Polycarp likes arithmetic progressions. A sequence [a_1, a_2, ..., a_n] is called an arithmetic progression if for each i (1 ≤ i < n) the value a_{i+1} - a_i is the same. For example, the sequences [42], [5, 5, 5], [2, 11, 20, 29] and [3, 2, 1, 0] are arithmetic progressions, but [1, 0, 1], [1, 3, 9] and [2, 3, 1] are not.

It follows from the definition that any sequence of length one or two is an arithmetic progression.

Polycarp found some sequence of positive integers [b_1, b_2, ..., b_n]. He agrees to change each element by at most one. In the other words, for each element there are exactly three options: an element can be decreased by 1, an element can be increased by 1, an element can be left unchanged.

Determine a minimum possible number of elements in b which can be changed (by exactly one), so that the sequence b becomes an arithmetic progression, or report that it is impossible.

It is possible that the resulting sequence contains element equals 0.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in b.

The second line contains a sequence b_1, b_2, ..., b_n (1 ≤ b_i ≤ 10^{9}).

Output

If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't use operation twice to the same position).

Examples

Input

4
24 21 14 10


Output

3


Input

2
500 500


Output

0


Input

3
14 5 1


Output

-1


Input

5
1 3 6 9 12


Output

1

Note

In the first example Polycarp should increase the first number on 1, decrease the second number on 1, increase the third number on 1, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to [25, 20, 15, 10], which is an arithmetic progression.

In the second example Polycarp should not change anything, because his sequence is an arithmetic progression.

In the third example it is impossible to make an arithmetic progression.

In the fourth example Polycarp should change only the first element, he should decrease it on one. After that his sequence will looks like [0, 3, 6, 9, 12], which is an arithmetic progression.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;

public class Div_3_481 {

	static Reader r = new Reader();
	static PrintWriter out = new PrintWriter(System.out);

	private static void solve1() throws IOException {

		StringBuilder res = new StringBuilder();

		int n = r.nextInt();

		int arr[] = r.nextIntArray(n);

		HashSet<Integer> set = new HashSet<Integer>();

		ArrayList<Integer> pal = new ArrayList<Integer>();

		for (int i = n - 1; i >= 0; i--) {
			if (set.contains(arr[i])) {
				continue;
			} else {
				pal.add(arr[i]);
				set.add(arr[i]);
			}
		}

		res.append(pal.size()).append("\n");
		for (int i = pal.size() - 1; i >= 0; i--) {
			res.append(pal.get(i) + " ");
		}

		out.print(res);
		out.close();
	}

	private static void solve2() throws IOException {

		int n = r.nextInt();
		char str[] = r.next().toCharArray();

		int cnt = 0;

		int len = 0;
		for (int i = 0; i < str.length; i++) {
			if (str[i] == 'x') {
				len++;
			} else {
				if (len >= 3) {
					cnt += (len - 2);
				}
				len = 0;
			}
		}
		if (len >= 3) {
			cnt += (len - 2);
		}

		out.print(cnt);
		out.close();

	}

	private static void solve3() throws IOException {

		StringBuilder res = new StringBuilder();

		int n = r.nextInt();
		int m = r.nextInt();

		long a[] = r.nextLongArray(n);
		long b[] = r.nextLongArray(m);

		int idx = 1;
		long prefix[] = new long[n + 1];
		for (int i = 1; i <= n; i++) {
			prefix[i] = prefix[i - 1] + a[i - 1];
		}

		for (int i = 0; i < m; i++) {
			while (prefix[idx] < b[i]) {
				idx++;
			}
			res.append((idx) + " " + (b[i] - prefix[idx - 1])).append("\n");
		}

		out.print(res);
		out.close();

	}

	private static void solve4() throws IOException {

		int n = r.nextInt();
		long arr[] = r.nextLongArray(n);

		long ans = 0;
		if (n > 2) {

			ans = Long.MAX_VALUE;
			boolean flag = false;

			long a = (arr[1] - arr[0]);
			long b = (arr[1] - (arr[0] + 1));
			long c = (arr[1] - (arr[0] - 1));
			long d = ((arr[1] + 1) - arr[0]);
			long e = ((arr[1] + 1) - (arr[0] - 1));
			long f = ((arr[1] + 1) - (arr[0] + 1));
			long g = ((arr[1] - 1) - arr[0]);
			long h = ((arr[1] - 1) - (arr[0] + 1));
			long l = ((arr[1] - 1) - (arr[0] - 1));

			long A[] = { arr[0], arr[0] + 1, arr[0] - 1, arr[0], arr[0] - 1, arr[0] + 1, arr[0], arr[0] + 1,
					arr[0] - 1 };
			long D[] = { a, b, c, d, e, f, g, h, l };

//			System.out.println(Arrays.toString(A));
//			System.out.println(Arrays.toString(D));

			for (int j = 0; j < 9; j++) {
				boolean fl = true;
				long temp = 0;
				for (int i = 0; i < n; i++) {
					long val = A[j] + (i * D[j]);
					if (Math.abs(val - arr[i]) <= 1) {
						if (val != arr[i])
							temp++;
					} else {
						fl = false;
						break;
					}
				}
				if (fl) {
					flag = true;
					ans = Math.min(ans, temp);
				}
			}

			if (!flag) {
				ans = -1;
			}

		}

		out.print(ans);
		out.close();

	}

	public static void main(String[] args) throws IOException {

//		solve1();

//		solve2();

//		solve3();

		solve4();

	}

	static class Reader {

		final private int BUFFER_SIZE = 1 << 12;
		boolean consume = false;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		private boolean reachedEnd = false;

		public Reader() {
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = 0;
			bytesRead = 0;
		}

		public boolean hasNext() {
			return !reachedEnd;
		}

		private void fillBuffer() throws IOException {
			bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1) {
				buffer[0] = -1;
				reachedEnd = true;
			}
		}

		private void consumeSpaces() throws IOException {
			while (read() <= ' ' && reachedEnd == false)
				;
			bufferPointer--;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

		public String next() throws IOException {
			StringBuilder sb = new StringBuilder();
			consumeSpaces();
			byte c = read();
			do {
				sb.append((char) c);
			} while ((c = read()) > ' ');
			if (consume) {
				consumeSpaces();
			}
			if (sb.length() == 0) {
				return null;
			}
			return sb.toString();
		}

		public String nextLine() throws IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			return str;
		}

		public int nextInt() throws IOException {
			consumeSpaces();
			int ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public long nextLong() throws IOException {
			consumeSpaces();
			long ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10L + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			consumeSpaces();
			double ret = 0;
			double div = 1;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public int[][] nextIntMatrix(int n, int m) throws IOException {
			int[][] grid = new int[n][m];
			for (int i = 0; i < n; i++) {
				grid[i] = nextIntArray(m);
			}
			return grid;
		}

		public char[][] nextCharacterMatrix(int n) throws IOException {
			char[][] a = new char[n][];
			for (int i = 0; i < n; i++) {
				a[i] = next().toCharArray();
			}
			return a;
		}

		public void close() throws IOException {
			if (System.in == null) {
				return;
			} else {
				System.in.close();
			}
		}
	}

}