malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int rev(int ans) {     if (ans == 1)       return 0;     else       return 1;   }   int main() {     int arr[3][3], ans[3][3];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         cin >> arr[i][j];         ans[i][j] = 1;       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (arr[i][j] % 2 != 0) {           if (i - 1 >= 0) {             ans[i - 1][j] = rev(ans[i - 1][j]);           }           if (i + 1 < 3) {             ans[i + 1][j] = rev(ans[i + 1][j]);           }           if (j + 1 < 3) {             ans[i][j + 1] = rev(ans[i][j + 1]);           }           if (j - 1 >= 0) {             ans[i][j - 1] = rev(ans[i][j - 1]);           }           ans[i][j] = rev(ans[i][j]);         }       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         cout << ans[i][j];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   const int N = 1e5 + 4;   int n, a[N], c[40];   inline void solve() {     memset(c, 0, sizeof(c));     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       for (int j = 0; j < 30; j++)         if ((a[i] >> j) & 1) c[j]++;     }     for (int i = 29; i >= 0; i--)       if (c[i] & 1) {         if (c[i] % 4 == 1) {           puts( WIN );         } else {           puts((n & 1) ?  LOSE  :  WIN );         }         return;       }     puts( DRAW );   }   int main() {     for (int T = read(); T--;) solve();     return (0 - 0);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   const double EPS = 10e-9;   int const S = 1 << 19;   int n, a[S], leftlink[S], rightlink[S], decrease;   pair<int, int> tree[2 * S];   pair<int, int> Min() { return tree[1]; }   void Init() {     tree[S] = make_pair(INF, 0);     for (int i = 1; i <= (n); ++i) tree[i + S] = make_pair(a[i], i);     for (int i = n + 1; i <= (S - 1); ++i) tree[S + i] = make_pair(INF, i);     for (int i = S - 1; i >= (1); --i)       tree[i] = min(tree[2 * i], tree[2 * i + 1]);   }   void Delete(int p) {     for (tree[p + S] = make_pair(INF, p), p += S, p >>= 1; p; p >>= 1)       tree[p] = min(tree[p * 2], tree[p * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= (n); ++i) {       cin >> a[i];       leftlink[i] = i - 1;       rightlink[i] = i + 1;     }     rightlink[n] = 0;     Init();     pair<int, int> greedy;     long long ans = 0;     while (n) {       if (n <= 2) break;       greedy = Min();       Delete(greedy.second);       if (!leftlink[greedy.second]) {         ans += ((long long)(n - 2)) * (greedy.first - decrease);         leftlink[rightlink[greedy.second]] = 0;         decrease = greedy.first;         --n;         continue;       }       if (!rightlink[greedy.second]) {         ans += ((long long)(n - 2)) * (greedy.first - decrease);         decrease = greedy.first;         rightlink[leftlink[greedy.second]] = 0;         --n;         continue;       }       leftlink[rightlink[greedy.second]] = leftlink[greedy.second];       rightlink[leftlink[greedy.second]] = rightlink[greedy.second];       ans +=           min(a[leftlink[greedy.second]], a[rightlink[greedy.second]]) - decrease;       --n;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, m = 0, temp = 0;     cin >> n >> m;     int arr[n + 1];     fill(arr, arr + n + 1, -1);     for (int i = 1; i <= m; i++) {       cin >> temp;       int k = temp;       while (k <= n && arr[k] == -1) {         arr[k] = temp;         k++;       }     }     for (int j = 1; j <= n; j++) cout << arr[j] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cost;   int di[4] = {0, -1, 0, 1};   int dj[4] = {-1, 0, 1, 0};   char grid[51][51];   int vis[51][51];   pair<int, int> pi;   pair<int, int> pf;   vector<pair<int, int>> ili;   vector<pair<int, int>> ilf;   void dfs(int r, int c, vector<pair<int, int>>* island) {     vis[r][c] = 1;     (*island).push_back({r, c});     for (int v = 0; v < 4; v++) {       int i = r + di[v];       int j = c + dj[v];       if (i > 0 && i <= n && j > 0 && j <= n) {         if (grid[i][j] ==  0  && !vis[i][j]) {           dfs(i, j, island);         }       }     }   }   int main() {     cin >> n;     cin >> pi.first >> pi.second;     cin >> pf.first >> pf.second;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> grid[i][j];       }     }     dfs(pi.first, pi.second, &ili);     if (vis[pf.first][pf.second]) {       cout <<  0  << endl;     } else {       dfs(pf.first, pf.second, &ilf);       int less = (int)INFINITY;       for (int i = 0; i < (int)ili.size(); i++) {         for (int j = 0; j < (int)ilf.size(); j++) {           cost = pow((ili[i].first - ilf[j].first), 2) +                  pow((ili[i].second - ilf[j].second), 2);           if (cost < less && cost) {             less = cost;           }         }       }       cout << less << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long LLINF = 1000000000000000007LL;   const double EPS = 1e-9;   const int sz = 200100;   int ar[600][600];   int p[600][600];   int suf_sum_2d(int i1, int j1, int i2, int j2) {     return p[i2 + 1][j2 + 1] - p[i2 + 1][j1] - p[i1][j2 + 1] + p[i1][j1];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> ar[i][j];         p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] - p[i][j] + ar[i][j];       }     }     int mx = -INF;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         int r = min(min(i + 1, j + 1), min(n - i, m - j));         int res = ar[i][j];         for (int k = 1; k < r; ++k) {           res =               suf_sum_2d(i - k, j - k, i + k, j + k) - res - ar[i - k + 1][j - k];           mx = max(mx, res);         }       }     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> mp;   bool f(int mid) {     if (mp.size() < mid) return false;     int a = 0, b = 0;     bool fl = 0;     for (auto it = mp.begin(); it != mp.end(); it++) {       if (it->second > mid) {         a = mid;         if (fl == 0) {           b++;         } else {           b += 2;           fl = 0;         }       } else if (it->second == mid) {         if (a == 0) {           a = mid;           fl = 1;         } else           b++;       } else if (it->second < mid)         b++;     }     return a >= mid && b >= mid;   }   int main() {     int test;     cin >> test;     for (int t = 1; t <= test; t++) {       int n, ans = 0, imax = 0;       cin >> n;       mp.clear();       for (int i = 0; i < n; i++) {         int temp;         cin >> temp;         mp[temp]++;         imax = max(imax, mp[temp]);       }       int low = 1, high = imax;       while (low <= high) {         int mid = low + (high - low) / 2;         if (f(mid)) {           ans = mid;           low = mid + 1;         } else           high = mid - 1;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int INT_MAX_VAL = (int)0x3F3F3F3F;   int INT_MIN_VAL = (int)-0x3F3F3F3F;   long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F;   long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F;   vector<long long> G[5005];   long long n;   int W;   int cnt[5005];   int dp[2][5005][5005];   int dfs2(int v, int p) {     if (G[v].size() == 1) {       cnt[v] = 1;       return 1;     }     int res = 0;     for (auto &w : G[v])       if (w != p) res += dfs2(w, v);     cnt[v] = res;     return res;   }   void dfs(int v, int p) {     dp[1][v][0] = 0;     if (G[v].size() == 1) {       dp[0][v][1] = 0;       return;     }     dp[0][v][0] = 0;     dp[1][v][0] = 0;     for (auto &w : G[v]) {       if (w == p) continue;       dfs(w, v);       for (int i = W; i >= 0; --i) {         int d0 = INT_MAX_VAL;         int d1 = INT_MAX_VAL;         for (int j = min(i, cnt[w]); j >= 0; --j) {           d0 = min(d0, dp[0][w][j] + dp[0][v][i - j]);           d0 = min(d0, dp[1][w][j] + dp[0][v][i - j] + 1);           d1 = min(d1, dp[1][w][j] + dp[1][v][i - j]);           d1 = min(d1, dp[0][w][j] + dp[1][v][i - j] + 1);         }         dp[0][v][i] = d0;         dp[1][v][i] = d1;       }     }   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     memset(dp, 0x3F, 2 * 5005 * 5005 * sizeof(int));     cin >> n;     for (long long(i) = 0LL; (i) < (n - 1); (i)++) {       long long a, b;       cin >> a >> b;       --a, --b;       G[a].push_back(b);       G[b].push_back(a);     }     if (n == 2) {       cout << 1 <<   n ;       return 0;     }     int i = 0;     while (G[i].size() == 1) ++i;     W = dfs2(i, -1) / 2;     dfs(i, -1);     cout << dp[0][i][W] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct ban {     long long s, a, b;   };   bool operator<(const ban& a, const ban& b) { return (a.a - a.b) > (b.a - b.b); }   int n;   long long s;   ban a[N];   long long sum;   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> s;     for (int i = 0; i < n; ++i) {       cin >> a[i].s >> a[i].a >> a[i].b;       sum += a[i].s;     }     sort(a, a + n);     long long t = 0;     for (int i = 0; i < n; ++i) {       if (a[i].a - a[i].b > 0) t += a[i].s;     }     long long yans = 0;     for (int i = 0; i < n; ++i) {       if (a[i].a - a[i].b > 0) yans += (a[i].a * a[i].s);     }     long long tt = (((sum / s) + !!(sum % s)) - ((t / s) + !!(t % s))) * s;     for (int i = n - 1; i >= 0; --i) {       if (a[i].a - a[i].b <= 0) {         if (tt > a[i].s) {           tt -= a[i].s;           yans += (a[i].b * a[i].s);         } else {           yans += (a[i].b * tt);           yans += (a[i].a * (a[i].s - tt));           tt = 0;         }       }     }     ans = yans;     t = 0;     for (int i = n - 1; i >= 0; --i) {       if (a[i].b - a[i].a > 0) t += a[i].s;     }     yans = 0;     for (int i = n - 1; i >= 0; --i) {       if (a[i].b - a[i].a > 0) yans += (a[i].b * a[i].s);     }     tt = (((sum / s) + !!(sum % s)) - ((t / s) + !!(t % s))) * s;     for (int i = 0; i < n; ++i) {       if (a[i].b - a[i].a <= 0) {         if (tt > a[i].s) {           tt -= a[i].s;           yans += (a[i].a * a[i].s);         } else {           yans += (a[i].a * tt);           yans += (a[i].b * (a[i].s - tt));           tt = 0;         }       }     }     ans = max(ans, yans);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   int NEGINF = -1e9;   int main() {     ifstream fin( input.txt );     int n, l, r;     cin >> n >> l >> r;     vector<int> a(n), b(n), p(n), c(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> ppos(n);     for (int i = 0; i < n; i++) {       cin >> p[i];       ppos[p[i] - 1] = i;     }     int loc, csmall = NEGINF;     for (int i = 0; i < n; i++) {       loc = ppos[i];       if (csmall + 1 + a[loc] < l) {         b[loc] = l;         csmall = b[loc] - a[loc];       } else if (csmall + 1 + a[loc] > r) {         cout <<  -1 n ;         return 0;       } else {         csmall++;         b[loc] = a[loc] + csmall;       }     }     for (int i = 0; i < n; i++) {       cout << b[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   char a[2005][2005];   bool used[2005][2005];   queue<pair<int, int> > q;   int nu() {     puts( Not unique );     return 0;   }   bool impasse(int ic, int jc) {     int cnt = 0;     cnt += (a[ic][jc - 1] ==  . );     cnt += (a[ic][jc + 1] ==  . );     cnt += (a[ic - 1][jc] ==  . );     cnt += (a[ic + 1][jc] ==  . );     return (cnt < 2);   }   void add(int ic, int jc) {     if (impasse(ic - 1, jc) && !used[ic - 1][jc]) {       q.push(make_pair(ic - 1, jc));       used[ic - 1][jc] = true;     }     if (impasse(ic + 1, jc) && !used[ic + 1][jc]) {       q.push(make_pair(ic + 1, jc));       used[ic + 1][jc] = true;     }     if (impasse(ic, jc - 1) && !used[ic][jc - 1]) {       q.push(make_pair(ic, jc - 1));       used[ic][jc - 1] = true;     }     if (impasse(ic, jc + 1) && !used[ic][jc + 1]) {       q.push(make_pair(ic, jc + 1));       used[ic][jc + 1] = true;     }   }   int main() {     int n, m;     scanf( %d %d n , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %c , &a[i][j]);       }       scanf( %c , &a[0][0]);     }     for (int i = 0; i <= n + 1; i++) {       a[i][0] =  * ;       a[i][m + 1] =  * ;     }     for (int i = 0; i <= m + 1; i++) {       a[0][i] =  * ;       a[n + 1][i] =  * ;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  * ) continue;         int cnt = 0;         cnt += (a[i][j - 1] ==  . );         cnt += (a[i][j + 1] ==  . );         cnt += (a[i - 1][j] ==  . );         cnt += (a[i + 1][j] ==  . );         if (cnt == 0) return nu();         if (cnt == 1) {           used[i][j] = true;           q.push(make_pair(i, j));         }       }     while (!q.empty()) {       int ic = q.front().first;       int jc = q.front().second;       q.pop();       if (a[ic][jc] !=  . ) continue;       if (a[ic + 1][jc] ==  . ) {         a[ic][jc] =  ^ ;         a[ic + 1][jc] =  v ;         add(ic + 1, jc);       }       if (a[ic - 1][jc] ==  . ) {         a[ic][jc] =  v ;         a[ic - 1][jc] =  ^ ;         add(ic - 1, jc);       }       if (a[ic][jc + 1] ==  . ) {         a[ic][jc] =  < ;         a[ic][jc + 1] =  > ;         add(ic, jc + 1);       }       if (a[ic][jc - 1] ==  . ) {         a[ic][jc] =  > ;         a[ic][jc - 1] =  < ;         add(ic, jc - 1);       }       if (a[ic][jc] ==  . ) return nu();       add(ic, jc);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  . ) return nu();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         putchar(a[i][j]);       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long v[100100];   long long h[100100];   int main() {     long long n, m;     cin >> n >> m;     long long vidx = 0;     for (; vidx < n; ++vidx) {       long long x;       cin >> x;       v[vidx] = x;     }     long long hidx = 0;     for (long long loop = 0; loop < m; ++loop) {       long long x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 > 1) continue;       h[hidx] = x2;       ++hidx;     }     sort(v, v + vidx);     sort(h, h + hidx);     v[vidx] = 1e9;     ++vidx;     long long res = n + m;     for (long long idx = 0; idx < vidx; ++idx) {       long long lim = v[idx];       auto it = lower_bound(h, h + hidx, lim) - h;       res = min(res, hidx - it + idx);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long przodek(long long n, long long m) {     if (n == m) return n;     if (n > m) return przodek(n / 2, m);     return przodek(n, m / 2);   }   int main() {     long long q;     cin >> q;     set<pair<long long, long long> > path_fee;     for (int i = 0; i < q; i++) {       long long op, v, u, w;       cin >> op;       if (op == 1) {         cin >> u >> v >> w;         long long prz = przodek(u, v);         while (u != prz) {           pair<long long, long long> act_fee = *path_fee.lower_bound({u, 0});           if (act_fee.first == u)             path_fee.erase(act_fee);           else             act_fee.second = 0;           path_fee.insert({u, act_fee.second + w});           u /= 2;         }         while (v != prz) {           pair<long long, long long> act_fee = *path_fee.lower_bound({v, 0});           if (act_fee.first == v)             path_fee.erase(act_fee);           else             act_fee.second = 0;           path_fee.insert({v, act_fee.second + w});           v /= 2;         }         continue;       }       cin >> u >> v;       long long cost = 0;       long long prz = przodek(u, v);       while (u != prz) {         pair<long long, long long> act_fee = *path_fee.lower_bound({u, 0});         if (act_fee.first == u) {           cost += act_fee.second;         }         u /= 2;       }       while (v != prz) {         pair<long long, long long> act_fee = *path_fee.lower_bound({v, 0});         if (act_fee.first == v) {           cost += act_fee.second;         }         v /= 2;       }       cout << cost << endl;     }   }
#include <bits/stdc++.h>   int arr[1100000];   using namespace std;   int main() {     memset(arr, 0, sizeof arr);     int n;     cin >> n;     int x = 1, pre = 1;     for (int i = 1; i <= n; i++) {       int c;       cin >> c;       arr[x] = i;       x += c;     }     x = arr[1];     for (int i = 1; i <= 1000000; i++) {       if (!arr[i])         arr[i] = x;       else         x = arr[i];     }     int q;     cin >> q;     while (q--) {       cin >> x;       cout << arr[x] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x, l, r, m;   int main() {     cin >> n;     int endtime = 0;     while (n--) {       cin >> x;       endtime += x;     }     cin >> m;     while (m--) {       cin >> l >> r;       if (endtime <= l) {         cout << l << endl;         return 0;       } else if (endtime > r) {         continue;       } else {         cout << endtime << endl;         return 0;       }     }     cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int N6 = 1e6 + 6;   const int N9 = 1e9 + 7;   const long long INFLL = (long long)1e18 + 100;   const int INF = 1e9 + 100;   const long long mod = 1e9 + 9;   const long long P = 31;   int n, k, cur, ans;   std::vector<int> g[1111];   map<pair<int, int>, bool> cnt;   void solve() {     cin >> n >> k;     int cur;     for (int i = 1; i <= n; ++i) {       cur = 0;       for (int j = 1; j <= n; ++j) {         if (!cnt.count(make_pair(i, j)) && i != j) {           ++cur;           cnt[make_pair(i, j)];           cnt[make_pair(j, i)];           g[i].push_back(j);           ++ans;         }         if (cur == k) {           break;         }       }       if (cur != k) {         cout << -1;         exit(0);       }     }     cout << ans <<   n ;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < g[i].size(); ++j) {         cout << i <<     << g[i][j] <<   n ;       }     }   }   int main() {     int tt = 1;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int a = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       a = (a << 3) + (a << 1) + (c ^  0 );       c = getchar();     }     return f ? -a : a;   }   int point[51][3], N;   void solve(int l, int r, int dir) {     if (l == r)       printf( (%01d*abs(((1-abs((t-%d)))+abs((abs((t-%d))-1))))) ,              point[l][dir] / 2, l, l);     else {       putchar( ( );       solve(l, l + r >> 1, dir);       putchar( + );       solve((l + r >> 1) + 1, r, dir);       putchar( ) );     }   }   int main() {     N = read();     for (int i = 1; i <= N; ++i) {       point[i][0] = read();       point[i][1] = read();       point[i][2] = read();     }     solve(1, N, 0);     putchar(  n );     solve(1, N, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 100111, inf = 1000111222;   const int max_lev = 18;   int n, m, q, parent[max_lev][max_n], best_h[max_n], used[max_n], h[max_n];   int real_p[max_lev][max_n];   int tin[max_n], tout[max_n], cur;   vector<int> g[max_n];   void dfs(int v, int p) {     tin[v] = ++cur;     parent[0][v] = p;     real_p[0][v] = p;     for (int to : g[v]) {       if (to == p) {         continue;       }       if (tin[to]) {         if (tin[to] < tin[parent[0][v]]) {           parent[0][v] = to;         }       } else {         dfs(to, v);         if (tin[parent[0][to]] < tin[parent[0][v]]) {           parent[0][v] = parent[0][to];         }       }     }     tout[v] = cur;   }   void get_all_p(int parent[max_lev][max_n]) {     for (int lev = 1; lev < max_lev; ++lev) {       for (int i = 0; i < n; ++i) {         parent[lev][i] = parent[lev - 1][parent[lev - 1][i]];       }     }   }   bool is_ancestor(int v1, int v2) {     return tin[v1] <= tin[v2] && tout[v1] >= tout[v2];   }   int lca(int v1, int v2) {     if (is_ancestor(v1, v2)) {       return v1;     }     for (int i = max_lev - 1; i >= 0; --i) {       if (!is_ancestor(real_p[i][v1], v2)) {         v1 = real_p[i][v1];       }     }     return real_p[0][v1];   }   int get_d(int v, int up) {     if (v == up) {       return 0;     }     int res = 1;     for (int i = max_lev - 1; i >= 0; --i) {       if (!is_ancestor(parent[i][v], up)) {         res += 1 << i;         v = parent[i][v];       }     }     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(0, 0);     get_all_p(parent);     get_all_p(real_p);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       --u;       --v;       int lc = lca(u, v);       int ans = get_d(u, lc) + get_d(v, lc);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 6e5 + 8;   const int T = 2e5 + 2;   int n, b[N], t[N];   template <typename _Tp>   inline void IN(_Tp& x) {     char ch;     bool flag = 0;     x = 0;     while (ch = getchar(), !isdigit(ch))       if (ch ==  - ) flag = 1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     if (flag) x = -x;   }   struct Segment_Tree {     long long sum[N << 2];     void update(int x, int l, int r, int pos, int val) {       if (l == r) {         sum[x] += val;         return void();       }       (pos <= ((l + r) >> 1))           ? update(((x) << 1), l, ((l + r) >> 1), pos, val)           : update(((x) << 1 | 1), ((l + r) >> 1) + 1, r, pos, val);       sum[x] = max(sum[((x) << 1)], sum[((x) << 1 | 1)]);     }   } Tree;   int main() {     IN(n);     for (int i = 1; i <= n; ++i) IN(b[i]), t[i] = b[i] - i + T;     for (int i = 1; i <= n; ++i) Tree.update(1, 1, N - 1, t[i], b[i]);     printf( %lld n , Tree.sum[1]);     return 0;   }