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.*;
import java.math.BigInteger;
import java.util.*;

import javax.swing.plaf.synth.SynthSeparatorUI;
public class Problem3 {
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args) throws IOException, InterruptedException {
		int n=sc.nextInt();
		int a[]=new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
		}
		if(n==2||n==1) {
			System.out.println(0);
			return;
		}
		int dx[]={a[0],a[0]-1,a[0]+1};
		int dy[]={a[1],a[1]+1,a[1]-1};
		int ans=INF;
		
		for (int i = 0; i < dx.length; i++) {
			label:for (int j = 0; j < dy.length; j++) {
				int diff=dy[j]-dx[i];
				long prev=dy[j];
				int count=0;
				if(i==1||i==2) {
					count++;
					
				}
				 if(j==1 ||j==2) {
					
					count++;
				}
				for (int k = 2; k < a.length; k++) {
					if(Math.abs(prev+diff-a[k])>1) {
						continue label;
					}
					if(Math.abs(prev+diff)!=a[k]) {
					count++;
					}
					prev+=diff;
					
				}
				
				ans=Math.min(count, ans);
			}
		
		}
		if(ans==INF) {
			System.out.println(-1);
		}
		else
	System.out.println(ans);
		}
	
	
	private static boolean check(int k, int mid, int a, int b,int n) {
		long normal=n-mid;
		long cost1=1l*normal*1l*b*1l;
		long cost2=1l*mid*1l*a*1l;
		if(cost1+cost2>=k)
		return false;
		else
			return true;
	}
	static long pow(long a, int n,int mod)
	{
		long res = 1;
		while(n != 0)
		{
			if((n & 1) == 1)
				res = (res*(a));
			a *= (a);
			a=a;
			n >>= 1;			
		}
		return res;
	}
	static TreeSet<Integer> primes;
	static int[] isComposite;

	static void sieve(int N)	// O(N log log N) 
	{
		isComposite = new int[N+1];					
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new TreeSet<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) 
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}   
	}
	static int INF=(int) 1E9;
	static class Pair{
		int x;
		int y;
		public Pair(int x,int y) {
			this.x=x;
			this.y=y;
		}
		
	}
	public static int[] schuffle(int a[]) {
		for (int i = 0; i < a.length; i++) {
			int x=(int)(Math.random()*a.length);
		int temp=a[x];
		a[x]=a[i];
		a[i]=temp;
		}
		return a;
	}
	static long gcd(long min,long a) {
		if(a==0) {
			return min;
		}
		return gcd(a,min%a);
	}
static int 	factprime(int n,int p) {
	int pow=0;
	for(int i=p ; i<=n ; i=i*p) {
		pow+=n/i;
	}
	return pow;
}
static long power(long x, long y) 
{ 
    long temp; 
    if( y == 0) 
        return 1; 
       
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%10)*(temp)%10)%10; 
    else
        return ((x%10)*(temp%10)*(temp%10))%10;
}  
	static ArrayList<Integer> adj[];
static Stack<Integer> st=new Stack<>();
static  boolean visited[];
static void dfs(int i){
	visited[i]=true;
	st.add(i);
	for(int x:adj[i]) {
		if(!visited[x])
			dfs(x);
	}
}


	static  class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

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

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

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public boolean ready() throws IOException {
		return br.ready();
	}
	public void waitForInput() throws InterruptedException {Thread.sleep(2300);}
}



static class SegmentTree {
	int N; // number of elements in my array after the padding
	int [] array, sTree, lazy; 
	SegmentTree(int []inp){
		N = inp.length - 1;
		array = inp;
		sTree =  new int[N<<1];
		lazy =  new int[N<<1];
		build(1, 1, N);
	}
	void build(int node, int b, int e) {
		if(b == e) {
			//node = b + N - 1
			// update(idx , value)
			// sTree[idx + N - 1] += value
			sTree[node] = array[b];
		}
		else {
			int nodeLeft = node << 1;
			int nodeRight = (node << 1)+1;
			int mid = (b + e) >> 1;
			build(nodeLeft, b , mid);
			build(nodeRight, mid + 1, e);
			sTree[node] = sTree[nodeLeft] + sTree[nodeRight];
		}
	}
	void propagate(int node, int b, int e) {
		int leftChild = node << 1;
		int rightChild = node<<1|1;
		lazy[leftChild] += lazy[node];
		lazy[rightChild] += lazy[node];
		int mid = (b + e)>>1;
		if(lazy[node]%2!=0) {
		sTree[leftChild] = (mid - b + 1)-sTree[leftChild];
		sTree[rightChild] =(e - mid)-sTree[rightChild];
		}
		lazy[node] = 0;
	}
	// add value v for element in position idx in my input array
	//O(log(N))
	void update_point(int idx, int v) {
		int node = idx + N - 1;
		sTree[node] += v;
		while(node > 1) {
			node >>= 1;
			sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
		}
	}
	// O(log(N))
	int query(int i, int j) {
		return query(1, 1, N, i, j); 
	}
	int query(int node, int b, int e, int i, int j) {
		
		
		if(i > e || j < b)
			return 0;
		if(b >= i && e <= j)
			return sTree[node];
		int mid = (b + e) >> 1;
		propagate(node, b, e);
        int q1 = query(node << 1, b, mid, i , j);
		int q2 = query(node<<1|1, mid + 1, e, i, j);
		return q1 + q2;
		
		
	}
	void update_range(int i, int j) { //O(log(N))
		update_range(1, 1, N, i, j); 
	}
	void update_range(int node, int b, int e, int i, int j) {
		if(i > e || j < b)
			return;
		if(b >= i && e <= j) {
			sTree[node] = (e - b + 1)-sTree[node];
			lazy[node]+=1;
		}
		else {
			int mid = (b + e) >> 1;
			propagate(node, b, e);
			update_range(node<<1, b , mid, i, j);
			update_range(node<<1|1, mid+1, e, i, j);
			sTree[node] = sTree[node<<1] + sTree[node<<1|1];
		}
	}
}
}

	

