#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   long long arr[100003];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     if (n == 1 || n == 2)       printf( 0 n );     else {       long long res = INF;       for (int i = -1; i <= 1; i++) {         for (int j = -1; j <= 1; j++) {           long long a = arr[0] + i;           long long b = (arr[1] + j) - (arr[0] + i);           long long cnt = abs(i) + abs(j);           for (int k = 2; k < n; k++) {             if (abs(a + (k * b) - arr[k]) > 1)               cnt = INF;             else               cnt += abs(a + (k * b) - arr[k]);           }           res = min(res, cnt);         }       }       if (res <= 1e9)         printf( %lld n , res);       else         printf( -1 n );     }   }   