func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mx1 = 20;   const int mx2 = 405;   const int mx3 = 2005;   const int mx4 = 30005;   const int mx5 = 100005;   const int mx6 = 1000005;   int _toggle(int N, int pos) { return N = N ^ (1 << pos); }   int _set(int N, int pos) { return N = N | (1 << pos); }   int _reset(int N, int pos) { return N = N & ~(1 << pos); }   bool _check(int N, int pos) { return (bool)(N & (1 << pos)); }   bool _upper(char a) { return a >=  A  && a <=  Z ; }   bool _lower(char a) { return a >=  a  && a <=  z ; }   bool _digit(char a) { return a >=  0  && a <=  9 ; }   int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};   int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};   const int inf = 1e9 + 7;   int n, a[mx5];   int fnd(int x, int y) {     int cnt = (x != 0) + (y != 0);     int A = a[1] + x, B = a[2] + y, d = B - A, pre = B;     for (int i = 3; i <= n; i++) {       bool f = 0;       for (int j = -1; j < 2; j++) {         int now = a[i] + j;         if (now - pre == d) {           f = 1;           pre = now;           cnt += (j != 0);           break;         }       }       if (!f) {         return inf;       }     }     return cnt;   }   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (n < 3) {       cout << 0 <<   n ;       return;     }     int ans = inf;     for (int i = -1; i < 2; i++) {       for (int j = -1; j < 2; j++) {         ans = min(ans, fnd(i, j));       }     }     if (ans == inf) {       cout << -1 <<   n ;     } else {       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc = 1;     while (tc--) {       solve();     }   }   