malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   const int M = 300000;   int n, m, a[N], b[N];   vector<bool> g[M];   pair<int, int> p[N];   priority_queue<pair<int, int> > q;   bool solve(int x) {     if (x == 0) return true;     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     int sum = 0;     for (int i = 1; i <= n; i++) sum += b[i];     sort(b + 1, b + n + 1);     reverse(b + 1, b + n + 1);     if (sum & 1) {       b[1]--;       b[2]--;       b[3]--;     }     sort(b + 1, b + n + 1);     reverse(b + 1, b + n + 1);     if (b[n] < 0) return false;     for (int i = 1; i <= n; i++)       if (b[i] > 0) q.push(make_pair(b[i], i));     while (!q.empty()) {       pair<int, int> v = q.top();       q.pop();       if (q.empty()) return false;       pair<int, int> u = q.top();       q.pop();       v.first--;       u.first--;       if (v.first > 0) q.push(v);       if (u.first > 0) q.push(u);     }     return true;   }   void getSolution(int x) {     if (x == 0) {       m = 0;       for (int i = 1; i < n; i++) {         for (int j = 1; j <= 100; j++) {           m++;           for (int k = 1; k <= n; k++)             if (k == i || k == i + 1)               g[m][k - 1] = true;             else               g[m][k - 1] = false;         }       }       return;     }     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     for (int i = 1; i <= n; i++)       if (b[i] > 0) q.push(make_pair(b[i], i));     int sum = 0;     for (int i = 1; i <= n; i++) sum += b[i];     int game = 0;     while (!q.empty()) {       game++;       if (sum & 1) {         pair<int, int> a = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> b = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> c = q.top();         q.pop();         for (int j = 1; j <= n; j++)           if (j == a.second || j == b.second || j == c.second)             g[game][j - 1] = true;           else             g[game][j - 1] = false;         a.first--;         b.first--;         c.first--;         if (a.first > 0) q.push(a);         if (b.first > 0) q.push(b);         if (c.first > 0) q.push(c);         sum -= 3;       } else {         pair<int, int> a = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> b = q.top();         q.pop();         for (int j = 1; j <= n; j++)           if (j == a.second || j == b.second)             g[game][j - 1] = true;           else             g[game][j - 1] = false;         a.first--;         b.first--;         if (a.first > 0) q.push(a);         if (b.first > 0) q.push(b);       }     }     m = game;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int minval = a[1];     for (int i = 2; i <= n; i++) minval = min(minval, a[i]);     for (int i = 1; i <= 10000; i++) g[i].resize(n);     int ans = 0;     for (int i = minval; i >= 0; i--)       if (solve(i)) {         ans = i;         break;       }     cout << ans << endl;     getSolution(ans);     cout << m << endl;     for (int i = 1; i <= m; i++) {       for (int j = 0; j < g[i].size(); j++) cout << g[i][j];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 5e3 + 10;   int dp[maxn][maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i - 1] == b[j - 1]) {           dp[i][j] = dp[i - 1][j - 1] + 2;         } else           dp[i][j] = max({0, dp[i - 1][j] - 1, dp[i][j - 1] - 1});         ans = max(ans, dp[i][j]);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   char a[N], b[N];   int lcp[N][N];   int f[N][N][12];   int main() {     int l1, l2, n;     scanf( %d%d%d , &l1, &l2, &n);     scanf( %s%s , a + 1, b + 1);     for (int i = (1); i <= (l1); i++) {       for (int j = (1); j <= (l2); j++) {         if (a[i] == b[j])           lcp[i][j] = lcp[i - 1][j - 1] + 1;         else           lcp[i][j] = 0;       }     }     int ans = n;     for (int i = (1); i <= (l1); i++) {       for (int j = (1); j <= (l2); j++) {         for (int k = (1); k <= (n); k++) {           int A = lcp[i][j];           f[i][j][k] = max(f[i][j][k], f[i - A][j - A][k - 1] + A);           if (f[i][j][k] > f[i + 1][j][k]) f[i + 1][j][k] = f[i][j][k];           if (f[i][j][k] > f[i][j + 1][k]) f[i][j + 1][k] = f[i][j][k];           ans = max(ans, f[i][j][k]);         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 10;   vector<int> vec[MAXN];   int c[MAXN];   long long dp[2][MAXN];   void dfs(int v) {     vector<int> temp;     long long all = 1;     for (int i = 0; i < (int)vec[v].size(); i++) {       int u = vec[v][i];       dfs(u);       temp.push_back(all);       all = (all * (dp[0][u] + dp[1][u])) % (1000 * 1000 * 1000 + 7);     }     if (c[v]) {       dp[1][v] = all;       dp[0][v] = 0;     } else {       dp[0][v] = all;       all = 1;       for (int i = (int)vec[v].size() - 1; i >= 0; i--) {         int u = vec[v][i];         dp[1][v] = (dp[1][v] +                     (((temp[i] * all) % (1000 * 1000 * 1000 + 7)) * dp[1][u]) %                         (1000 * 1000 * 1000 + 7)) %                    (1000 * 1000 * 1000 + 7);         all = (all * (dp[0][u] + dp[1][u])) % (1000 * 1000 * 1000 + 7);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a;       cin >> a;       vec[a].push_back(i);     }     for (int i = 0; i < n; i++) cin >> c[i];     dfs(0);     cout << dp[1][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace Base {   const int inf = 0x3f3f3f3f, INF = 0x7fffffff;   const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;   template <typename T>   void read(T &x) {     x = 0;     int fh = 1;     double num = 1.0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     if (ch ==  . ) {       ch = getchar();       while (isdigit(ch)) {         num /= 10;         x = x + num * (ch -  0 );         ch = getchar();       }     }     x = x * fh;   }   template <typename T>   void chmax(T &x, T y) {     x = x < y ? y : x;   }   template <typename T>   void chmin(T &x, T y) {     x = x > y ? y : x;   }   }  // namespace Base   using namespace Base;   const int N = 100010;   int n, a[N], q[N], use[N], pre[N], prel[N], prem[N], prer[N], num, l[N], m[N],       r[N];   void force(int *a, int n, int id) {     int tmp = 0;     for (int i = 1; i <= n; i++) tmp = tmp + (a[i] << (i - 1));     int pl = 1, pr = 1;     q[1] = 0;     use[0] = true;     while (pl <= pr) {       int x = q[pl++];       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           int k = j + (j - i);           if (k > n) continue;           int nxt = x ^ (1 << (i - 1)) ^ (1 << (j - 1)) ^ (1 << (k - 1));           if (use[nxt] == false) {             q[++pr] = nxt;             use[nxt] = true;             pre[nxt] = x;             prel[nxt] = i;             prem[nxt] = j, prer[nxt] = k;           }         }     }     if (use[tmp] == false) {       printf( NO n );       exit(0);     }     printf( YES n );     while (tmp != 0) {       num++;       l[num] = prel[tmp] + id, m[num] = prem[tmp] + id, r[num] = prer[tmp] + id;       tmp = pre[tmp];     }     printf( %d n , num);     for (int i = 1; i <= num; i++) printf( %d %d %d n , l[i], m[i], r[i]);   }   void doit(int nl, int nm, int nr) {     num++;     l[num] = nl, m[num] = nm, r[num] = nr;     a[nl] ^= 1, a[nm] ^= 1, a[nr] ^= 1;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     int pl = 1, pr = n;     while (pr - pl + 1 > 12) {       if (a[pl] == 0) {         pl++;         continue;       }       if (a[pr] == 0) {         pr--;         continue;       }       if (a[pl] + a[pl + 1] + a[pl + 2] == 3) {         doit(pl, pl + 1, pl + 2);         continue;       }       if (a[pr] + a[pr - 1] + a[pr - 2] == 3) {         doit(pr - 2, pr - 1, pr);         continue;       }       if ((pr - pl) % 2 == 0) {         doit(pl, (pl + pr) / 2, pr);         continue;       }       if (a[pl] != a[pl + 1] && a[pl] == a[pl + 2]) {         doit(pl, pl + 2, pl + 4);         continue;       }       if (a[pr] != a[pr - 1] && a[pr] == a[pr - 2]) {         doit(pr - 4, pr - 2, pr);         continue;       }       doit(pl, (pl + pr - 1) / 2, pr - 1);     }     if (n <= 12)       force(a, n, 0);     else       force(a + pl - 1, 12, pl - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000;   int sum[maxn];   int a[maxn];   int sum2[maxn];   int main() {     int n;     char s[maxn];     while (cin >> n) {       memset(sum, 0, sizeof(sum));       for (int i = 1; i <= n; ++i) {         scanf( %d , a + i);         sum[i] = sum[i - 1] + a[i];       }       scanf( %s , s + 1);       int c = 0, ans = 0;       for (int i = n; i >= 1; --i) {         if (s[i] ==  1 ) {           ans = max(ans, c + sum[i - 1]);           c += a[i];         }       }       cout << max(c, ans) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[5005];   vector<int> primes;   int ans[5005];   int u[5005];   int n;   void pre() {     vector<char> bad(10005);     for (int i = 2; i <= 10000; ++i) {       if (!bad[i]) {         primes.push_back(i);         for (int j = i * i; j <= 10000; j += i) {           bad[j] = 1;         }       }     }   }   int f(int x) {     static vector<int> di;     di.clear();     if (x == 0) {       return 0;     }     bool neg = 0;     if (x < 0) {       neg = 1;       x *= -1;     }     int y = 1;     for (int i = 0; i < primes.size(); ++i) {       int cnt = 0;       while (x % primes[i] == 0) {         x /= primes[i];         ++cnt;       }       if (cnt & 1) {         y *= primes[i];       }     }     x *= y;     if (neg) {       x *= -1;     }     return x;   }   void compress() {     vector<int> vv;     for (int i = 1; i <= n; ++i) {       vv.push_back(arr[i].first);     }     sort((vv).begin(), (vv).end());     vv.resize(unique((vv).begin(), (vv).end()) - vv.begin());     for (int i = 1; i <= n; ++i) {       arr[i].second =           upper_bound((vv).begin(), (vv).end(), arr[i].first) - vv.begin();     }   }   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &arr[i].first);       arr[i].first = f(arr[i].first);     }     compress();     int ptr = 0;     for (int l = 1; l <= n; ++l) {       int cur = 0;       ++ptr;       for (int r = l; r <= n; ++r) {         if (arr[r].first != 0) {           if (u[arr[r].second] != ptr) {             u[arr[r].second] = ptr;             ++cur;           }         }         ++ans[max(1, cur)];       }     }     for (int i = 1; i <= n; ++i) {       printf( %d  , ans[i]);     }   }   int main() {     int tt = 1;     pre();     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tri = 0;     scanf( %d , &n);     long long trilist[n + 5];     for (int i = 0; i < n; i++) {       scanf( %ld , &trilist[i]);     }     sort(trilist, trilist + n);     for (int i = 0; i < n - 2; i++) {       if (trilist[i] + trilist[i + 1] > trilist[i + 2]) {         tri = 1;         break;       }     }     if (tri == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int visited1[200005], visited2[200005], step1[200005], step2[200005],       ar[200005];   long long int n;   void fill_array(long long int ar[], long long int value, long long int size) {     for (long long int i = 0; i < size; i++) ar[i] = value;   }   long long int dfs(long long int node, long long int step,                     long long int parent) {     if (step == 1) {       visited1[node] = 1;       if (node + ar[node] > n)         step1[node] = ar[node];       else {         if (visited2[node + ar[node]]) {           if (step2[node + ar[node]] < 0)             step1[node] = -1;           else if (step2[node + ar[node]] == 0)             step1[node] = -1;           else             step1[node] = step2[node + ar[node]] + ar[node];         } else {           long long int temp = dfs(node + ar[node], 2, node);           if (temp < 0)             step1[node] = -1;           else             step1[node] = temp + ar[node];         }       }       return step1[node];     } else {       visited2[node] = 1;       if (node - ar[node] < 1)         step2[node] = ar[node];       else if (node - ar[node] == 1)         step2[node] = -1;       else {         if (visited1[node - ar[node]]) {           if (step1[node - ar[node]] < 0)             step2[node] = -1;           else if (step1[node - ar[node]] == 0)             step2[node] = -1;           else             step2[node] = step1[node - ar[node]] + ar[node];         } else {           long long int temp = dfs(node - ar[node], 1, node);           if (temp < 0)             step2[node] = -1;           else             step2[node] = temp + ar[node];         }       }       return step2[node];     }   }   int main() {     cin >> n;     for (long long int i = 2; i <= n; i++) cin >> ar[i];     fill_array(visited1, 0, n + 1);     fill_array(visited2, 0, n + 1);     fill_array(step1, 0, n + 1);     fill_array(step2, 0, n + 1);     for (long long int i = 2; i <= n; i++) {       if (!visited1[i]) dfs(i, 1, -1);       if (!visited2[i]) dfs(i, 2, -1);     }     for (long long int i = 2; i <= n; i++) {       if (step2[i] == -1)         cout <<  -1 n ;       else         cout << step2[i] + i - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct pos {     long long int x;     long long int h;     int indx;     int sum;   } p[100005];   bool cmp(pos a, pos b) { return a.x < b.x; }   bool cmp2(pos a, pos b) { return a.indx < b.indx; }   int bs(long long int key) {     int l = 0;     int r = n;     int mid;     while (l <= r) {       mid = (l + r) / 2;       if (p[mid].x == key) {         return mid;       } else if (p[mid].x < key) {         l = mid + 1;       } else {         r = mid - 1;       }     }   }   int main() {     scanf( %d , &n);     long long int ar[n + 5];     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &p[i].x, &p[i].h);       p[i].indx = i;       p[i].sum = 1;     }     sort(p, p + n, cmp);     p[n - 1].sum = 1;     for (int i = n - 2; i >= 0; i--) {       long long int val = p[i].h + p[i].x;       int poscnt = 1;       while (val > p[i + poscnt].x && poscnt + i < n) {         p[i].sum += p[poscnt + i].sum;         poscnt += p[poscnt + i].sum;       }     }     sort(p, p + n, cmp2);     for (int i = 0; i < n; i++) {       printf( %d  , p[i].sum);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, p, prt[100005], num[100005], ans = 1, cnt, u, v;   inline int getfather(int u) {     if (u == prt[u]) return prt[u];     prt[u] = getfather(prt[u]);     return prt[u];   }   int main() {     scanf( %lld%lld%lld , &n, &m, &p);     for (register int i = 1; i <= n; i++) prt[i] = i;     for (register int i = 1; i <= m; i++) {       scanf( %lld%lld , &u, &v);       register int f1 = getfather(u), f2 = getfather(v);       if (f1 != f2) prt[f1] = f2;     }     for (register int i = 1; i <= n; i++) num[getfather(i)]++;     for (register int i = 1; i <= n; i++)       if (num[i]) cnt++, ans = ans * num[i] % p;     for (register int i = 1; i <= cnt - 2; i++) ans = ans * n % p;     if (cnt == 1) ans = 1;     printf( %lld , ans % p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ss[100002];   int main() {     int N, K, k = 0;     scanf( %d %d , &N, &K);     scanf( %s , ss);     string S = ss;     for (int i = 0; i < N - 1 && k < K; i++) {       if (S[i] ==  4  && S[i + 1] ==  7 ) {         int x = i + 1;         if (x % 2) {           if (x + 1 < N && S[x + 1] ==  7 ) {             if ((K - k) % 2) {               S[x] =  4 ;             }             printf( %s , S.c_str());             return 0;           }           S[x] =  4 ;         } else {           S[x - 1] =  7 ;           i -= 2;         }         k++;       }     }     printf( %s n , S.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ns, k, n, m;   char s[1000010], t[1000010], p[1000010];   vector<int> vet;   int fail[1000010];   void buildFail(char *p) {     int j = fail[0] = -1;     for (int i = 1; i <= m; i++) {       while (j >= 0 && p[j] != p[i - 1]) j = fail[j];       fail[i] = ++j;     }   }   int kmp(char *p, char *t) {     buildFail(p);     for (int i = 0, k = 0; i < n; i++) {       while (k >= 0 && p[k] != t[i]) k = fail[k];       if (++k >= m) {         return 1;         k = fail[k];       }     }     return 0;   }   int test(int k) {     int i, j;     m = 0;     for (i = 0, j = ns - k; i < k; i++, j++) {       if (s[i] != s[j]) break;       p[m++] = s[i];     }     if (i < k) return 0;     p[m] =   0 ;     return kmp(p, t);   }   int main() {     int lo, hi, mid;     scanf(  %s , s);     ns = strlen(s);     vet.clear();     m = ns;     buildFail(s);     k = ns;     while (fail[k] > 0) {       vet.push_back(fail[k]);       k = fail[k];     }     sort(vet.begin(), vet.end());     for (int i = 1; i < ns - 1; i++) t[i - 1] = s[i];     t[n - 2] =   0 ;     n = ns - 2;     lo = 0;     hi = vet.size() - 1;     k = 0;     while (lo <= hi) {       mid = (lo + hi) / 2;       if (test(vet[mid])) {         k = vet[mid];         lo = mid + 1;       } else         hi = mid - 1;     }     if (!k)       printf( Just a legend n );     else {       for (int i = 0; i < k; i++) printf( %c , s[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 400010;   struct ST {     int st[4 * MX], p[MX];     ST() { build(1, MX - 1, 1); }     void build(int i, int j, int pos) {       st[pos] = 0;       if (i == j) {         p[i] = pos;         return;       }       int m = (i + j) / 2;       build(i, m, pos * 2);       build(m + 1, j, pos * 2 + 1);     }     void update(int x, int k) {       int pos = p[x];       st[pos] = k;       pos /= 2;       while (pos) {         st[pos] = max(st[pos * 2], st[pos * 2 + 1]);         pos /= 2;       }     }     int leq(int i, int j, int pos, int x) {       if (i > x) return 0;       if (j <= x) return st[pos];       int m = (i + j) / 2;       return max(leq(i, m, pos * 2, x), leq(m + 1, j, pos * 2 + 1, x));     }     int geq(int i, int j, int pos, int x) {       if (i >= x) return st[pos];       if (j < x) return 0;       int m = (i + j) / 2;       return max(geq(i, m, pos * 2, x), geq(m + 1, j, pos * 2 + 1, x));     }   } st;   int n, a[MX], res[MX];   vector<int> c;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] -= i;       c.push_back(a[i]);       c.push_back(a[i] + 1);     }     sort(c.begin(), c.end());     c.erase(unique(c.begin(), c.end()), c.end());     for (int i = 0; i < n; i++)       a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin() + 1;     for (int i = 1; i < n; i++) {       st.update(a[i - 1], 1 + st.leq(1, MX - 1, 1, a[i - 1]));       res[i] = st.leq(1, MX - 1, 1, a[i - 1]);     }     st.build(1, MX - 1, 1);     for (int i = n - 2; i >= 0; i--) {       st.update(a[i + 1] + 1, 1 + st.geq(1, MX - 1, 1, a[i + 1] + 1));       if (i - 1 > 0) res[i] += st.geq(1, MX - 1, 1, a[i - 1]);     }     cout << n - 1 - max(*max_element(res, res + n), st.geq(1, MX - 1, 1, 1))          <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   int n, m, t;   long long dp[61][31][31];   int arr[61];   long long solve(int ind, int x, int y) {     if (x > 3 && y > 0 && x + y == t) return 1;     if (ind == n + m + 1) return 0;     long long &ret = dp[ind][x][y];     if (ret != -1) return ret;     ret = solve(ind + 1, x, y);     if (x < n && arr[ind] == 1) ret += solve(ind + 1, x + 1, y);     if (y < m && arr[ind] == 2) ret += solve(ind + 1, x, y + 1);     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &t);     int i = 0;     for (; i < n; i++) arr[i] = 1;     for (; i < n + m; i++) arr[i] = 2;     memset(dp, -1, sizeof dp);     printf( %lld n , solve(0, 0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int f[105][105][105], len[105], n, m;   char s[105];   int qpow(int x, int y) {     int res = 1;     while (y) {       if (y % 2) res = 1ll * res * x % mod;       x = 1ll * x * x % mod;       y /= 2;     }     return res;   }   int dfs(int x, int l, int r) {     if (f[x][l][r] != -1) return f[x][l][r];     if (x <= 1) return (l == r) && (s[l] == (x +  0 ));     int cnt = 0;     cnt = (cnt +            1ll * dfs(x - 1, l, r) * ((r == n) ? qpow(2, len[x - 2]) : 1) % mod) %           mod;     cnt = (cnt +            1ll * dfs(x - 2, l, r) * ((l == 1) ? qpow(2, len[x - 1]) : 1) % mod) %           mod;     for (int k = l; k < r; k++)       cnt = (cnt + 1ll * dfs(x - 1, l, k) * dfs(x - 2, k + 1, r) % mod) % mod;     return f[x][l][r] = cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     memset(f, -1, sizeof(f));     len[1] = 1;     len[0] = 1;     for (int i = 2; i <= m; i++) len[i] = (len[i - 1] + len[i - 2]) % (mod - 1);     cin >> s + 1;     printf( %d n , dfs(m, 1, n));   }
#include <bits/stdc++.h>   using namespace std;   typedef long long LL;   #define FOR(i, a, b) for(int i = (a); i < (b); i++)      const int N = 1 << 10;   int p[N][N];   int main()   {    int m, n;    cin >> m >> n;    FOR(i, 0, n)    FOR(j, 0, m)     cin >> p[i][j];    int sum = 0;    FOR(j, 0, m)     sum += p[n - 1][j] - p[0][j];    assert(sum%(n - 1) == 0);    sum /= (n - 1);    int sum0 = 0;    FOR(j, 0, m)     sum0 += p[0][j];    int row = 0;    FOR(i, 1, n - 1){     int S = 0;     FOR(j, 0, m)      S += p[i][j];     if(S == sum0 + i * sum) continue;     row = i;    }    int st = (row > 2 ? 0 : (row + 1));    LL sum2 = 0;    FOR(j, 0, m){     sum2 += p[st][j] * (LL) p[st][j];     sum2 += p[st + 2][j] * (LL) p[st + 2][j];     sum2 -= 2 * p[st + 1][j] * (LL) p[st + 1][j];    }    sum2 /= 2;    LL real = 0, real2 = 0, have = 0, have2 = 0;    FOR(j, 0, m){     have += p[row][j];     have2 += p[row][j] * (LL) p[row][j];     real += p[row - 1][j];     real2 += p[row - 1][j] * (LL) p[row - 1][j];     real2 += p[row + 1][j] * (LL) p[row + 1][j];    }    real += sum;    real2 = real2/2 - sum2;    LL a2_x2 = have2 - real2;    LL a_x = have - real;    LL a_plus_x = a2_x2 / a_x;    cout << row <<     << (a_plus_x - a_x) / 2 << endl;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f2f1f0f;   const long long LINF = 1ll * INF * INF;   const int MAX_N = 2e5 + 100;   int N;   long long C;   int Nr[MAX_N * 2];   long long SumNr[MAX_N * 2];   long long Ans[MAX_N];   long long SumAns[MAX_N];   long long getSum(long long val[], int a, int b) { return val[b] - val[a - 1]; }   long long getVal(int a, int b) {     return getSum(SumNr, a * 2 - 1, b * 2 - 1) - getSum(SumAns, a, b - 1);   }   int main() {     cin >> N >> C;     for (int i = 1; i <= N * 2 - 1; i++)       scanf( %d , &Nr[i]), SumNr[i] = SumNr[i - 1] + Nr[i];     deque<int> dQ;     int cl = 0;     for (int r = 1; r <= N; r++) {       while (!dQ.empty() && getVal(dQ.back(), r) < Nr[r * 2 - 1]) dQ.pop_back();       dQ.push_back(r);       while (!dQ.empty() && getSum(SumNr, dQ.front() * 2 - 1, r * 2 - 1) >= C)         dQ.pop_front();       while (cl + 1 <= N && getSum(SumNr, (cl + 1) * 2 - 1, r * 2 - 1) >= C) cl++;       if (cl != 0) Ans[r] = max(Ans[r], C - getSum(SumAns, cl, r - 1));       if (!dQ.empty()) Ans[r] = max(Ans[r], getVal(dQ.front(), r));       SumAns[r] = SumAns[r - 1] + Ans[r];     }     printf( %lld n , SumAns[N]);     return 0;   }