#include <bits/stdc++.h>
using namespace std;
int x, y, a[1000001], b[1000001],
    ans = 10000000, c[1000001], d[1000001], e[1000001], f[1000001], g[1000001],
    h[1000001], j[1000001], k[1000001], B, C, D, E, F, G, H, J, K, B2, C2, D2,
    E2, F2, G2, H2, J2, K2, n, m;
vector<int> v;
vector<int>::iterator it;
string s;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  b[1] = a[1] + 1;
  c[1] = a[1] + 1;
  d[1] = a[1] + 1;
  e[1] = a[1];
  f[1] = a[1];
  g[1] = a[1];
  h[1] = a[1] - 1;
  j[1] = a[1] - 1;
  k[1] = a[1] - 1;
  for (int i = 2; i <= n; i++) b[i] = b[i - 1] + (a[2] - a[1] - 1);
  for (int i = 2; i <= n; i++) c[i] = c[i - 1] + (a[2] - a[1]);
  for (int i = 2; i <= n; i++) d[i] = d[i - 1] + (a[2] - a[1] - 2);
  for (int i = 2; i <= n; i++) e[i] = e[i - 1] + (a[2] - a[1]);
  for (int i = 2; i <= n; i++) f[i] = f[i - 1] + (a[2] - a[1] + 1);
  for (int i = 2; i <= n; i++) g[i] = g[i - 1] + (a[2] - a[1] - 1);
  for (int i = 2; i <= n; i++) h[i] = h[i - 1] + (a[2] - a[1] + 1);
  for (int i = 2; i <= n; i++) j[i] = j[i - 1] + (a[2] - a[1] + 2);
  for (int i = 2; i <= n; i++) k[i] = k[i - 1] + (a[2] - a[1]);
  for (int i = 1; i <= n; i++)
    if (abs(b[i] - a[i]) <= 1)
      B += abs(b[i] - a[i]);
    else
      B2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(c[i] - a[i]) <= 1)
      C += abs(c[i] - a[i]);
    else
      C2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(d[i] - a[i]) <= 1)
      D += abs(d[i] - a[i]);
    else
      D2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(e[i] - a[i]) <= 1)
      E += abs(e[i] - a[i]);
    else
      E2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(f[i] - a[i]) <= 1)
      F += abs(f[i] - a[i]);
    else
      F2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(g[i] - a[i]) <= 1)
      G += abs(g[i] - a[i]);
    else
      G2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(h[i] - a[i]) <= 1)
      H += abs(h[i] - a[i]);
    else
      H2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(j[i] - a[i]) <= 1)
      J += abs(j[i] - a[i]);
    else
      J2 = 1;
  for (int i = 1; i <= n; i++)
    if (abs(k[i] - a[i]) <= 1)
      K += abs(k[i] - a[i]);
    else
      K2 = 1;
  if (B2 != 1) ans = min(ans, B);
  if (C2 != 1) ans = min(ans, C);
  if (D2 != 1) ans = min(ans, D);
  if (E2 != 1) ans = min(ans, E);
  if (F2 != 1) ans = min(ans, F);
  if (G2 != 1) ans = min(ans, G);
  if (H2 != 1) ans = min(ans, H);
  if (J2 != 1) ans = min(ans, J);
  if (K2 != 1) ans = min(ans, K);
  if (ans == 10000000)
    cout << -1;
  else
    cout << ans;
  return 0;
}
