malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, D = 50;   const int V = N * D;   vector<int> g[N];   int S[V], ssz;   int low[V], num[V], cnt, vis[V];   int scc[V], scc_cnt;   int all[V], sz;   int n, m, d;   long long val[N];   void push(int i, int j) {     if (val[i] >> j & 1) {       all[sz++] = i;       while (sz >= V) {         n++;       }     }   }   int dp[V];   void tarjanSCC(int u) {     low[u] = num[u] = ++cnt;     vis[u] = 1;     S[ssz++] = u;     for (int w : g[u / d]) {       int v = w * d + (u % d + 1) % d;       while (v >= V) v++;       if (!num[v]) tarjanSCC(v);       if (vis[v]) low[u] = min(low[u], low[v]);     }     if (low[u] == num[u]) {       scc[u] = ++scc_cnt;       int v;       sz = 0;       push(u / d, u % d);       do {         v = S[--ssz];         vis[v] = 0;         push(v / d, v % d);         scc[v] = scc_cnt;         for (int wver : g[v / d]) {           int ver = wver * d + (v % d + 1) % d;           if (scc[ver]) {             dp[scc_cnt] = max(dp[scc_cnt], dp[scc[ver]]);           }         }       } while (u != v);       sort(all, all + sz);       dp[scc_cnt] += int(unique(all, all + sz) - all);     }   }   int main() {     scanf( %d %d %d , &n, &m, &d);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--, v--;       g[u].push_back(v);     }     char str[100];     for (int i = 0; i < n; i++) {       scanf(  %s , str);       for (int j = 0; j < d; j++) {         if (str[j] ==  1 ) {           val[i] |= 1LL << j;         }       }     }     tarjanSCC(0);     printf( %d n , dp[scc[0]]);   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int cheak(int x) {     int sum = x;     while (x) {       sum += x / k;       x /= k;     }     if (sum >= n) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &k);     int head = 1, tail = n;     while (head <= tail) {       int mid = (head + tail) / 2;       if (cheak(mid))         tail = mid - 1;       else         head = mid + 1;     }     printf( %d n , head);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int inf = 1e18;   long long int b, d;   string a, c;   vector<pair<long long int, long long int>> arr(101);   int main(void) {     cin >> b >> d;     cin >> a;     cin >> c;     for (int i = 0; i < c.size(); i++) {       long long int k = i, val = 0;       for (int j = 0; j < a.size(); j++) {         if (a[j] == c[k]) {           k++;           if (k == c.size()) {             k = 0;             val++;           }         }       }       arr[i] = make_pair(val, k);     }     long long int ans = 0, curr = 0;     for (int i = 0; i < b; i++) {       ans += arr[curr].first;       curr = arr[curr].second;     }     cout << ans / d << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   template <class T>   void out(const vector<T> &a) {     cout <<  array:  ;     for (int i = 0; i < (int)a.size(); i++) cout << a[i] <<    ;     cout << endl;     cout.flush();   }   template <class T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   inline bool isPrime(T n) {     if (n <= 1) return false;     for (T i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   template <class T>   T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <typename T>   static T mod(T a, T b) {     a %= b;     if (a < 0) a += b;     return a;   }   template <class T>   string toString(T n) {     ostringstream oss;     oss << n;     oss.flush();     return oss.str();   }   template <typename T>   static void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long toLl(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   bool IsVowel(char ch) {     ch = tolower(ch);     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   int BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return (int)R;   }   long long mulmod(long long a, long long b, long long c) {     long long x = 0, y = a % c;     while (b > 0) {       if (b % 2 == 1) {         x = (x + y) % c;       }       y = (y * 2) % c;       b /= 2;     }     return x % c;   }   void binprint(int mask, int n) {     int i;     string s =   ;     do {       s += (mask % 2 +  0 );       mask /= 2;     } while (mask);     reverse(s.begin(), s.end());     s = string((n - (int)s.size() > 0 ? n - (int)s.size() : 0),  0 ) + s;     for (i = (int)s.size() - n; i < (int)s.size(); i++) printf( %c , s[i]);     printf(  n );   }   long long mpow(long long x, long long k) {     if (k == 0) return 1;     long long r = mpow(x, k / 2);     return k % 2 ? (r * r * x) : (r * r);   }   int main() {     long long n, k, x[500], cnt, i;     cin >> n >> k;     for (i = 0; i < n; i++) cin >> x[i];     cnt = 0;     while (x[0] != k) {       for (i = 0; i < n - 1; i++) {         if (x[i] != x[i + 1]) x[i]++;       }       x[n - 1]++;       cnt++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, b = 0, count = 0;     char ch, c;     cin >> n >> c;     if (c ==  U )       b++;     else       a++;     n--;     while (n--) {       cin >> ch;       if (a == b && ch != c) {         count++;         c = ch;       }       if (ch ==  U )         b++;       else         a++;     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   long long ksm(long long a, long long b) {     if (!b) return 1;     long long ns = ksm(a, b >> 1);     ns = ns * ns % 998244353;     if (b & 1) ns = ns * a % 998244353;     return ns;   }   int chk(int x1, int y1, int x2, int y2) {     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     fflush(stdout);     int r = 0;     cin >> r;     return r;   }   int a[55][55];   int main() {     int n;     cin >> n;     a[1][1] = 1;     for (int j = 3; j <= n; j++)       if (chk(1, j - 2, 1, j))         a[1][j] = a[1][j - 2];       else         a[1][j] = a[1][j - 2] ^ 1;     for (int i = 2; i <= n; i++)       for (int j = n; j >= 1; j--) {         if (i == n && j == n)           a[i][j] = 0;         else {           if (j >= 2)             if (chk(i - 1, j - 1, i, j))               a[i][j] = a[i - 1][j - 1];             else               a[i][j] = a[i - 1][j - 1] ^ 1;           else if (chk(i, j, i, j + 2))             a[i][j] = a[i][j + 2];           else             a[i][j] = a[i][j + 2] ^ 1;         }       }     int ed = 0;     for (int i = 1; i <= n; i += 2) {       if (a[i][i] == 1 && a[i + 2][i + 2] == 0) {         if (chk(i, i + 1, i + 2, i + 2))           ed = a[i][i + 1];         else if (chk(i, i, i + 1, i + 2))           ed = a[i + 1][i + 2] ^ 1;         else {           if (a[i][i + 1] == a[i + 1][i + 2])             ed = a[i][i + 1] ^ a[i][i + 2] ^ 1;           else if (a[i][i + 2] == 0)             ed = a[i + 1][i + 2];           else             ed = a[i][i + 1] ^ 1;         }         break;       }     }     cout <<  !  << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if ((i + j) & 1) a[i][j] ^= ed;         cout << a[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int x[100005];   int main() {     int n;     long long mn, mx, md, re, ans;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &x[i]);     sort(x, x + n);     mn = x[n - 1];     mx = x[0] + x[n - 1];     while (mn <= mx) {       re = 0;       md = (mx + mn) / 2;       for (int i = 0; i < n; i++) re += (md - x[i]);       if (re >= md) {         ans = md;         mx = md - 1;       } else         mn = md + 1;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     vector<vector<int>> sum_points(n + m), diff_points(n + m);     vector<int> x(k), y(k);     for (int i = 0; i < k; ++i) {       scanf( %d%d , &x[i], &y[i]);       sum_points[x[i] + y[i]].push_back(i);       diff_points[x[i] - y[i] + m].push_back(i);     }     vector<long long> ans(k, -1);     long long time = 0;     int px = 0, py = 0, nx = 0, ny = 0;     int dx = 1, dy = 1;     while (dx) {       int xdiff = (dx > 0) ? n - px : px;       int ydiff = (dy > 0) ? m - py : py;       int diff = min(xdiff, ydiff);       nx = px + diff * dx;       ny = py + diff * dy;       if (dx * dy > 0) {         for (int i : diff_points[nx - ny + m])           if (ans[i] == -1) ans[i] = time + abs(x[i] - px);       } else {         for (int i : sum_points[nx + ny])           if (ans[i] == -1) ans[i] = time + abs(x[i] - px);       }       if (xdiff < ydiff) dx *= -1;       if (xdiff > ydiff) dy *= -1;       if (xdiff == ydiff) dx = 0;       px = nx;       py = ny;       time += diff;     }     for (long long t : ans) printf( %lld n , t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, a, b;   inline bool valid(int x, int y, int &mx) {     if (!(x % a) && !(y % b)) {       int a1 = x / a;       int b1 = y / b;       if (!((a1 + b1) % 2)) {         if (!a1 && b1 && n <= a || !b1 && a1 && m <= b) return false;         int r = a1 > b1 ? a1 : b1;         if (mx == -1 || mx > r) {           mx = r;           return true;         }       }     }     return false;   }   int main() {     cin >> n >> m >> i >> j >> a >> b;     int x, y, d = -1;     x = i - 1;     y = m - j;     valid(x, y, d);     x = n - i;     y = j - 1;     valid(x, y, d);     x = n - i;     y = m - j;     valid(x, y, d);     x = i - 1;     y = j - 1;     valid(x, y, d);     if (d == -1)       cout <<  Poor Inna and pony!  << endl;     else       cout << d << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long ans, sum[300030], cnt[300030], tot[3];   int main() {     scanf( %d , &n);     tot[0] = 1;     for (int i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       while (x) {         cnt[i] += x % 2;         x >>= 1;       }       sum[i] = sum[i - 1] + cnt[i];       ans += tot[sum[i] % 2];       for (int j = i, k = i + 1, maxx = 0; j >= 1 && j >= i - 64; j--) {         while (k > j) maxx = max(1ll * maxx, cnt[k - 1]), k--;         if (maxx * 2 > sum[i] - sum[j - 1] && ((sum[i] % 2) == (sum[j - 1] % 2)))           ans--;       }       ++tot[sum[i] % 2];     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<long long int> G[N];     for (long long int i = 0; i < m; ++i) {       long long int a, b;       cin >> a >> b;       G[a].push_back(b);     }     long long int rnd[N];     for (long long int i = 1; i < n + 1; ++i) {       long long int z = G[i].size();       rnd[i] = z - 1;     }     long long int far[N];     for (long long int i = 1; i < n + 1; ++i) {       far[i] = N * N * N;       if (rnd[i] >= 0) {         for (long long int j = 0; j < G[i].size(); ++j) {           long long int x = G[i][j];           if (x > i)             far[i] = min(x - i, far[i]);           else             far[i] = min(n - i + x, far[i]);         }       }       if (G[i].size() == 0) far[i] = 0;     }     for (long long int i = 1; i < n + 1; ++i) {       long long int mx = 0;       for (long long int j = 1; j < n + 1; ++j) {         long long int s = 0;         if (rnd[j] > 0 || far[j] > 0) {           long long int z = j - i;           if (j < i) z = n - i + j;           s = z + rnd[j] * n + far[j];         }         mx = max(s, mx);       }       cout << mx <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int o = 4;   int main() {     char arr[o][o];     int a = 0;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) cin >> arr[i][j];     }     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         if (arr[i][j] ==  x ) {           if ((arr[i + 1][j] ==  x  || arr[i + 1][j] ==  . ) &&               (arr[i + 2][j] ==  x  || arr[i + 2][j] ==  . ) &&               (arr[i + 1][j] != arr[i + 2][j]) && i + 2 < 4)             a++;           if ((arr[i + 1][j] ==  x  || arr[i + 1][j] ==  . ) &&               (arr[i - 1][j] ==  x  || arr[i - 1][j] ==  . ) &&               (arr[i + 1][j] != arr[i - 1][j]) && i > 0 && i < 3)             a++;           if ((arr[i - 1][j] ==  x  || arr[i - 1][j] ==  . ) &&               (arr[i - 2][j] ==  x  || arr[i - 2][j] ==  . ) &&               (arr[i - 1][j] != arr[i - 2][j]) && i > 1)             a++;           if ((arr[i][j + 1] ==  x  || arr[i][j + 1] ==  . ) &&               (arr[i][j + 2] ==  x  || arr[i][j + 2] ==  . ) &&               (arr[i][j + 1] != arr[i][j + 2]) && j + 2 < 4)             a++;           if ((arr[i][j + 1] ==  x  || arr[i][j + 1] ==  . ) &&               (arr[i][j - 1] ==  x  || arr[i][j - 1] ==  . ) &&               (arr[i][j + 1] != arr[i][j - 1]) && j > 0 && j < 3)             a++;           if ((arr[i][j - 1] ==  x  || arr[i][j - 1] ==  . ) &&               (arr[i][j - 2] ==  x  || arr[i][j - 2] ==  . ) &&               (arr[i][j - 1] != arr[i][j - 2]) && j > 1)             a++;           if ((arr[i + 1][j + 1] ==  x  || arr[i + 1][j + 1] ==  . ) &&               (arr[i + 2][j + 2] ==  x  || arr[i + 2][j + 2] ==  . ) &&               (arr[i + 1][j + 1] != arr[i + 2][j + 2]) && i + 2 < 4 && j + 2 < 4)             a++;           if ((arr[i + 1][j + 1] ==  x  || arr[i + 1][j + 1] ==  . ) &&               (arr[i - 1][j - 1] ==  x  || arr[i - 1][j - 1] ==  . ) &&               (arr[i + 1][j + 1] != arr[i - 1][j - 1]) && i > 0 && j > 0 &&               i < 3 && j < 3)             a++;           if ((arr[i - 1][j - 1] ==  x  || arr[i - 1][j - 1] ==  . ) &&               (arr[i - 2][j - 2] ==  x  || arr[i - 2][j - 2] ==  . ) &&               (arr[i - 1][j - 1] != arr[i - 2][j - 2]) && i > 1 && j > 1)             a++;           if ((arr[i + 1][j - 1] ==  x  || arr[i + 1][j - 1] ==  . ) &&               (arr[i + 2][j - 2] ==  x  || arr[i + 2][j - 2] ==  . ) &&               (arr[i + 1][j - 1] != arr[i + 2][j - 2]) && i + 2 < 4 && j > 1)             a++;           if ((arr[i + 1][j - 1] ==  x  || arr[i + 1][j - 1] ==  . ) &&               (arr[i - 1][j + 1] ==  x  || arr[i - 1][j + 1] ==  . ) &&               (arr[i + 1][j - 1] != arr[i - 1][j + 1]) && i + 1 < 4 && i > 0 &&               j + 1 < 4 && j > 0)             a++;           if ((arr[i - 2][j + 2] ==  x  || arr[i - 2][j + 2] ==  . ) &&               (arr[i - 1][j + 1] ==  x  || arr[i - 1][j + 1] ==  . ) &&               (arr[i - 2][j + 2] != arr[i - 1][j + 1]) && i - 2 >= 0 && j + 2 < 4)             a++;         }       }     }     if (a > 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, i, j, k, l, r;     cin >> t;     while (t--) {       cin >> l >> r;       if (l == r) {         if (l % 2 == 0)           cout << l << endl;         else           cout <<  -  << l << endl;       } else if (l % 2 == 1 && r % 2 == 1) {         cout <<  -  << (l + r) / 2 << endl;       } else if (l % 2 == 0 && r % 2 == 0) {         cout << (l + r) / 2 << endl;       } else if (l % 2 == 0 && r % 2 == 1) {         cout <<  -  << (r - l + 1) / 2 << endl;       } else         cout << (r - l + 1) / 2 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long int n, m, i, j = 0, b;     cin >> n >> m;     unsigned long long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 1; i < n; i++) a[i] = a[i - 1] + a[i];     for (i = 0; i < m; i++) {       cin >> b;       while (b > a[j]) {         j++;       }       if (j == 0)         cout << j + 1 <<     << b << endl;       else if (j < n)         cout << j + 1 <<     << b - a[j - 1] << endl;       else if (j == n)         cout << j <<     << b - a[j - 2] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<long long, long long>, int> > island;   set<pair<long long, long long> > bridge;   int ans[200100];   int main() {     int n, m;     long long l, r, prevl, prevr, a;     cin >> n >> m;     cin >> prevl >> prevr;     for (int i = 1; i < n; i++) {       cin >> l >> r;       island.push_back(pair<pair<long long, long long>, int>(           pair<long long, long long>(r - prevl, l - prevr), i - 1));       prevl = l;       prevr = r;     }     sort(island.begin(), island.end());     for (int i = 0; i < m; i++) {       cin >> a;       bridge.insert(pair<long long, long long>(a, i + 1));     }     bridge.insert(pair<long long, long long>(1e19, -1));     set<pair<long long, long long> >::iterator point;     long long lastl, lastr;     int idx;     for (vector<pair<pair<long long, long long>, int> >::iterator it =              island.begin();          it != island.end(); ++it) {       lastr = it->first.first;       lastl = it->first.second;       idx = it->second;       point = bridge.lower_bound(pair<long long, long long>(lastl, -1));       if (point->first > lastr) {         cout <<  No ;         return 0;       } else {         ans[idx] = point->second;         bridge.erase(point);       }     }     cout <<  Yes n ;     for (int i = 0; i < n - 1; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5, inf = 1e9;   int n, kk, s, x, k[N][2];   char ch[N];   int fa[N << 1], val[N << 1];   int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; }   void uni(int a, int b) {     if (find(a) == find(b)) return;     val[find(b)] += val[find(a)];     fa[find(a)] = find(b);   }   int mix(int a) { return min(val[find(a)], val[find(a + kk)]); };   int main() {     scanf( %d%d%s , &n, &kk, ch + 1);     for (int i = 1; i <= kk; i++) {       scanf( %d , &s);       while (s--) {         scanf( %d , &x);         k[x][bool(k[x][0])] = i;       }     }     for (int i = 1; i <= kk; i++) val[i] = 1;     val[kk + kk + 1] = inf;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (k[i][0] == 0) goto qwq;       if (ch[i] ==  1 ) {         if (k[i][1]) {           if (find(k[i][0]) == find(k[i][1])) goto qwq;           ans -= mix(k[i][0]) + mix(k[i][1]);           uni(k[i][0], k[i][1]), uni(k[i][0] + kk, k[i][1] + kk);           ans += mix(k[i][1]);         } else {           ans -= mix(k[i][0]);           uni(k[i][0], kk + kk + 1);           ans += val[find(k[i][0] + kk)];         }       } else {         if (k[i][1]) {           if (find(k[i][0]) == find(k[i][1] + kk)) goto qwq;           ans -= mix(k[i][0]) + mix(k[i][1]);           uni(k[i][0], k[i][1] + kk), uni(k[i][0] + kk, k[i][1]);           ans += mix(k[i][0]);         } else {           ans -= mix(k[i][0]);           uni(k[i][0] + kk, kk + kk + 1);           ans += mix(k[i][0]);         }       }     qwq:       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, mod = 998244353;   long long jc[N] = {1}, ny[N];   void Add(long long &x, long long y) { x = (x + y + mod) % mod; }   long long q_pow(long long x, long long y) {     long long ans = 1;     for (; y; y >>= 1) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;     }     return ans;   }   long long C(int x, int y) { return jc[x] * ny[y] % mod * ny[x - y] % mod; }   int main() {     long long n;     scanf( %lld , &n);     ny[0] = 1;     for (int i = 1; i <= n; ++i)       jc[i] = jc[i - 1] * i % mod, ny[i] = q_pow(jc[i], mod - 2);     long long sum = 0;     long long kk = -1;     for (int i = 1; i <= n; ++i) {       kk = -kk;       Add(sum, kk * C(n, i) % mod * q_pow(3, n * n - i * n + i) % mod);     }     Add(sum, sum);     kk = 1;     for (int i = 1; i <= n; ++i) {       kk = -kk;       long long pos =           (q_pow(3, n * (n - i)) - q_pow(q_pow(3, n - i) - 1, n) + mod) % mod;       long long tmp = kk * C(n, i) % mod * 3LL % mod * pos % mod;       Add(sum, tmp);     }     printf( %lld n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   multiset<string> S;   long long n, a[3005];   long long f[3005][3005];   long long F[3005];   void update(int u, long long T) {     for (int i = u; i < 3005; i += i & -i) {       F[i] = max(F[i], T);     }   }   long long get(int u) {     long long res = (1ll << 60);     for (int i = u; i >= 0; i--) {       res = min(res, F[i]);       if (i == 0) break;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<long long> V;     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> a[i];       a[i] += n - i;     }     V.push_back(-1000000005);     for (int i = (1); i <= (n); ++i) V.push_back(a[i]);     sort((V).begin(), (V).end());     f[0][0] = 0;     for (int i = (1); i <= (n); ++i) {       long long T = (1ll << 60);       for (int j = (0); j <= (n); ++j) {         T = min(T, f[i - 1][j]);         f[i][j] = T + abs(a[i] - V[j]);       }     }     long long res = (1ll << 60);     for (int i = (1); i <= (n); ++i) res = min(res, f[n][i]);     cout << res << endl;     return 0;   }