#include<iostream> #include<cstdio> #include<algorithm> #define maxn 4010 #define ll long long #define INF 1000000000000ll usingnamespacestd;
int n, a[maxn];
ll b[maxn]; voidwork(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], a[i + n] = a[i]; ll ans = INF; for (int k = 1; k <= n; ++k) { ll sum = 0; for (int i = 1; i <= n; ++i) b[i] = a[i + k - 1] - i + 1; nth_element(b + 1, b + (n + 1 >> 1), b + n + 1); int v = b[n + 1 >> 1]; for (int i = 1; i <= n; ++i) sum += abs(b[i] - v); ans = min(ans, sum); } cout << ans << "\n"; }