#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int A[110]; rep(i, N) cin >> A[i]; int sum = 0; rep(i, N) sum += A[i]; int cnt = 1; while (true) { int tmp = 0; rep(i, cnt - 1) { tmp += (i + 1) * 2; } tmp += cnt; if (tmp > sum) break; cnt++; } int ans = 100000; rep(i, cnt - 1) { rep(k, N - (i * 2)) { int B[110] = {}; rep(j, i) { B[j + k] = j + 1; } B[i + k] = i + 1; rep(j, i) { B[j + i + 1 + k] = B[j + i + k] - 1; } int tmp1 = 0; int tmp2 = 0; rep(j, N) { //cout << B[j] << " "; if (A[j] < B[j]) tmp1 += B[j] - A[j]; else if (A[j] > B[j]) tmp2 += A[j] - B[j]; } //cout << endl; //cout << tmp1 << " " << tmp2 << endl; ans = min(ans, tmp2); } //rep(j, 10) cout << B[j] << " "; //cout << endl; } cout << ans << endl; return 0; }