malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100010][400];   vector<int> nima[100010];   int a[100010], b[100010];   int n, m, s, e;   int solve(int all = s, int c = e) {     unsigned int INF = -1;     vector<int> vt[100010];     int cur = 0;     memset(dp, -1, sizeof(dp));     int cnt = (all + c - 1) / c;     for (int i = 0; i < m; ++i) {       vt[b[i]].push_back(i + 1);     }     int ans = 0;     for (int i = 0; i < n; ++i) {       dp[cur][0] = 0;       cur ^= 1;       memset(dp[cur], -1, sizeof(dp[cur]));       for (int j = 1; j < cnt + 1; ++j) {         unsigned int pre = dp[cur ^ 1][j - 1];         unsigned int p =             upper_bound(vt[a[i]].begin(), vt[a[i]].end(), pre) - vt[a[i]].begin();         if (p == vt[a[i]].size())           p = INF;         else           p = vt[a[i]][p];         dp[cur][j] = min(dp[cur ^ 1][j], p);         if (dp[cur ^ 1][j] > p && p + i + j * c <= all) ans = max(ans, j);       }     }     return ans;   }   int main() {     while (cin >> n >> m >> s >> e) {       memset(dp, -1, sizeof(dp));       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i < m; ++i) {         scanf( %d , &b[i]);         nima[b[i]].push_back(i + 1);       }       int ans = 0;       int cnt = s / e;       for (int i = 0; i < n; ++i) {         dp[i][0] = 0;         if (nima[a[i]].size())           dp[i][1] = nima[a[i]][0];         else           dp[i][1] = -1;         if (i == 0) continue;         for (int j = 1; j <= cnt; ++j) {           unsigned int now = -1;           int w = a[i];           int last = dp[i - 1][j - 1];           now =               upper_bound(nima[w].begin(), nima[w].end(), last) - nima[w].begin();           if (now == nima[w].size() || dp[i - 1][j - 1] == -1) {             now = -1;           } else {             now = nima[w][now];           }           dp[i][j] = min(dp[i - 1][j], now);         }       }       for (int i = 0; i < n; ++i)         for (int j = 0; j < cnt + 1; ++j) {           if (dp[i][j] != -1) {             if (i + dp[i][j] + 1 + j * e <= s) ans = max(ans, j);           }         }       cout << ans << endl;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[11][5];   bool ok(int l, int j, int k) {     int i, an = 0;     for (i = 0; i < 5; i++) {       an = an + (a[j][i] - a[l][i]) * (a[k][i] - a[l][i]);     }     if (an > 0) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     int i, j, k, n;     cin >> n;     if (n > 11) {       n *= 5;       while (n--) cin >> i;       cout << 0;     } else {       for (i = 0; i < n; i++)         cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];       vector<int> v;       k = n;       j = n;       for (i = 0; i < n; i++) {         k = n;         for (j = 0; j < n && k == n; j++)           for (k = j + 1; k < n; k++) {             if (!ok(i, j, k)) {               break;             }           }         if (j == n && k == n) v.push_back(i + 1);       }       cout << v.size() << endl;       for (i = 0; i < v.size(); i++) cout << v[i] <<     << endl;       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2505;   int n, m, K, a[2][N][N], L[N][8], R[N][8], Lc[N][8], Rc[N][8];   char s[N];   long long ans;   void work(int x1, int x2, int y1, int y2, int d) {     if (y2 - y1 > x2 - x1) {       swap(x1, y1), swap(x2, y2), d ^= 1;     }     if (x1 + 1 == x2) {       ans += a[d][y1][x2] - a[d][y1][x1] == K;       return;     }     int mid = x1 + x2 >> 1;     work(x1, mid, y1, y2, d), work(mid, x2, y1, y2, d);     for (int i = y1; i < y2; ++i) {       for (int k = 0; k < K + 1; ++k)         L[i][k] = x1, Lc[i][k] = 0, R[i][k] = x2, Rc[i][k] = 0;       for (int j = y1; j < i + 1; ++j) {         for (int k = 0; k < K + 1; ++k) {           Lc[j][k] += a[d][i][mid] - a[d][i][L[j][k]];           while (Lc[j][k] > k)             Lc[j][k] -= a[d ^ 1][L[j][k]][i + 1] - a[d ^ 1][L[j][k]][j],                 ++L[j][k];           Rc[j][k] += a[d][i][R[j][k]] - a[d][i][mid];           while (Rc[j][k] > k)             --R[j][k],                 Rc[j][k] -= a[d ^ 1][R[j][k]][i + 1] - a[d ^ 1][R[j][k]][j];         }         for (int k = 0; k < K + 1; ++k)           ans += ((k ? L[j][k - 1] : mid) - L[j][k]) *                  (R[j][K - k] - (K - k ? R[j][K - k - 1] : mid));       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       for (int j = 0; j < m; ++j) a[0][i][j + 1] = a[1][j][i + 1] = s[j] - 48;     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) a[0][i][j + 1] += a[0][i][j];     for (int j = 0; j < m; ++j)       for (int i = 0; i < n; ++i) a[1][j][i + 1] += a[1][j][i];     work(0, n, 0, m, 1);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mx = 70, Mod = 1e9 + 7, mxx = 350000;   int n;   int get(int x, int y, int z) {     if (x > y) swap(x, y);     if (x > z) swap(x, z);     if (y > z) swap(y, z);     return x * mx * mx + y * mx + z;   }   bool mark[mxx];   vector<int> e[mxx];   int dp[mxx];   int par[mxx];   short d[mx][mx];   vector<pair<int, int> > res;   void connect(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   void bfs(int v) {     mark[v] = 1;     vector<int> vc;     vc.clear();     vc.push_back(v);     for (int i = 0; i < vc.size(); i++)       for (int u : e[v = vc[i]])         if (!mark[u]) mark[u] = 1, vc.push_back(u), par[u] = v;   }   void move(int u, int v) {     short a[3], b[3];     bool ma[3], mb[3];     for (int i = 0; i < 3; i++) {       a[i] = u % mx;       b[i] = v % mx;       u /= mx;       v /= mx;       ma[i] = 0;       mb[i] = 0;     }     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++)         if (a[i] == b[j]) ma[i] = 1, mb[j] = 1;     for (int i = 0; i < 3; i++) {       if (!ma[i]) u = a[i];       if (!mb[i]) v = b[i];     }     res.push_back(make_pair(u + 1, v + 1));   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int x, y, z, u;     cin >> n >> x >> y >> z;     x--, y--, z--;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < n; j++) d[i][j] = s[j] -  a  + 1;     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         for (int k = j + 1; k < n; k++) {           u = get(i, j, k);           for (int v = min(min(i, j), k) + 1; v < n; v++)             if (v != i && v != j && v != k) {               if (d[v][i] == d[j][k] && v > i) connect(u, get(v, j, k));               if (d[v][j] == d[i][k] && v > j) connect(u, get(v, i, k));               if (d[v][k] == d[i][j] && v > k) connect(u, get(v, i, j));             }         }       }     }     u = get(x, y, z);     if (u == get(0, 1, 2)) return cout <<  0 n , 0;     bfs(get(0, 1, 2));     if (!par[u]) return cout <<  -1 , 0;     while (par[u]) {       move(u, par[u]);       u = par[u];     }     cout << res.size() <<   n ;     for (pair<int, int> p : res) cout << p.first <<     << p.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   long long a[maxn];   long long fac[maxn], inv[maxn];   const int mod = 1e9 + 7;   long long Pow(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   long long C(int n, int m) {     if (n < m) return 0;     return fac[n] * inv[n - m] % mod * inv[m] % mod;   }   int main() {     fac[0] = inv[0] = 1;     for (int i = 1; i < maxn; i++) {       fac[i] = 1ll * fac[i - 1] * i % mod;       inv[i] = Pow(fac[i], mod - 2);     }     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), a[i] %= mod;     if (n <= 2) {       cout << (a[1] + a[2]) % mod << endl, exit(0);     }     if (n % 2 != 0) {       for (int i = 1; i < n; i++) {         if (i % 2 != 0)           a[i] = (a[i] + a[i + 1]) % mod;         else           a[i] = (a[i] - a[i + 1]) % mod;       }       n -= 1;     }     long long ans1 = 0, ans2 = 0;     for (int i = 1; i <= n; i += 2) {       ans1 = (ans1 + C(n / 2 - 1, (i - 1) / 2) * a[i] % mod) % mod;       ans2 = (ans2 + C(n / 2 - 1, (i - 1) / 2) * a[i + 1] % mod) % mod;     }     if ((1ll * n * (n - 1) / 2) % 2 == 0)       cout << (ans1 - ans2 + mod) % mod << endl;     else       cout << (ans1 + ans2 + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> &vec) {     os <<  { ;     for (int i = (0), __i = (((int)(vec).size())); i < __i; i++) {       os << vec[i];       if (i + 1 != ((int)(vec).size())) os <<  , ;     }     os <<  } ;     return os;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, pair<T1, T2> &par) {     os <<  (  << par.first <<  ,  << par.second <<  ) ;     return os;   }   const int dim = 110000;   char s[dim];   char s1[dim];   int p[dim];   int a[dim];   int a1[dim];   long long r1[dim];   long long r2[dim];   long long r3[dim];   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = (0), __i = (n); i < __i; i++) s1[i] = s[n - 1 - i];     s1[n] = 0;     p[0] = -1;     int g = -1;     for (int i = (1), __i = (n); i < __i; i++) {       while (g != -1 && s1[g + 1] != s1[i]) {         g = p[g];       }       if (s1[g + 1] == s1[i]) ++g;       p[i] = g;     }     g = -1;     a[0] = 0;     a1[0] = 0;     for (int i = (0), __i = (n); i < __i; i++) {       while (g != -1 && s1[g + 1] != s[i]) {         g = p[g];       }       if (s1[g + 1] == s[i]) ++g;       if (a[i] > g + 1) {         a1[i + 1] = a1[i];       } else {         a1[i + 1] = i - g;       }       a[i + 1] = max(a[i], g + 1);     }     r1[0] = 0;     r2[0] = 0;     r3[0] = 1;     long long cc = 52152551;     for (int i = (0), __i = (n); i < __i; i++) {       r1[i + 1] = r1[i] + s[i] * r3[i];       r2[i + 1] = r2[i] + s1[i] * r3[i];       r3[i + 1] = r3[i] * cc;     }     int ans = 0;     int i1, j1;     int i2, j2;     for (int i = (0), __i = (n); i < __i; i++) {       int l = 0, r = n;       while (r - l > 1) {         int mid = (l + r) / 2;         if (i - mid >= 0 && i + mid < n &&             (r1[i + 1] - r1[i - mid]) * r3[n - i - mid - 1] ==                 (r2[n - i] - r2[n - i - mid - 1]) * r3[i - mid]) {           l = mid;         } else {           r = mid;         }       }       int t = min(a[i - l], n - i - l - 1);       int ans1 = t * 2 + l * 2 + 1;       if (ans < ans1) {         ans = ans1;         i1 = a1[i - l];         j1 = t;         i2 = i - l;         j2 = l * 2 + 1;       }     }     if (j1 == 0) {       printf( 1 n );       printf( %d %d n , i2 + 1, j2);     } else {       printf( 3 n );       printf( %d %d n , i1 + 1, j1);       printf( %d %d n , i2 + 1, j2);       printf( %d %d n , n - j1 + 1, j1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int df[26];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     int mini = s.length();     for (int i = 0; i < s.length(); i++) {       df[s[i] -  A ]++;     }     for (int i = 0; i < k; i++) mini = min(mini, df[i]);     cout << k * mini <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, i;     cin >> n;     int a[n], b[n + 1];     for (i = 0; i < n; i++) {       cin >> a[i];       b[a[i]] = i;     }     int l, r, ans[n + 1];     l = b[1];     r = b[1];     for (i = 2; i <= n; i++) {       l = min(l, b[i]);       r = max(r, b[i]);       if ((r - l + 1) != i)         ans[i] = 0;       else         ans[i] = 1;     }     cout << 1;     for (i = 2; i <= n; i++) cout << ans[i];     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n, m;   const int N = 2e6 + 5;   const int mo = 1e9 + 7;   char s[N];   long long a[N], pw[N], cnt[N];   long long ans;   void FWTxor(long long *y, int op) {     for (int i = 1; i <= n; i++)       for (int j = 0; j < (1 << n); j += (1 << i))         for (int k = 0; k < (1 << (i - 1)); k++) {           long long c = (y[j | k] + y[j | k | (1 << (i - 1))]) % mo,                     d = (y[j | k] - y[j | k | (1 << (i - 1))] + mo) % mo;           y[j | k] = c * op % mo, y[j | k | (1 << (i - 1))] = d * op % mo;         }   }   void work() {     scanf( %d , &n);     scanf( %s , s);     pw[0] = 1;     for (int i = 0; i < (1 << n); i++) a[i] = s[i] -  0 ;     for (int i = 1; i <= n; i++) pw[i] = 2LL * pw[i - 1] % mo;     for (int i = 1; i < (1 << n); i++) cnt[i] = cnt[i >> 1] + (i & 1);     FWTxor(a, 1);     for (int i = 0; i < (1 << n); i++) a[i] = a[i] * a[i] % mo;     FWTxor(a, (mo + 1) / 2);     for (int i = 0; i < (1 << n); i++)       ans = (ans + 1LL * a[i] * pw[n - cnt[i]]) % mo;     printf( %lld , ans * 3 % mo);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e4 + 5;   int sum[55][N], a[55][N];   int lazy[N << 2], tree[N << 2];   int dp[55][N];   void pushdown(int root) {     if (lazy[root]) {       tree[root << 1] += lazy[root];       tree[root << 1 | 1] += lazy[root];       lazy[root << 1] += lazy[root];       lazy[root << 1 | 1] += lazy[root];       lazy[root] = 0;     }   }   void update(int root, int l, int r, int L, int R, int val) {     if (L <= l && r <= R) {       tree[root] += val;       lazy[root] += val;       return;     }     pushdown(root);     int mid = (l + r) >> 1;     if (L <= mid) update(root << 1, l, mid, L, R, val);     if (R > mid) update(root << 1 | 1, mid + 1, r, L, R, val);     tree[root] = max(tree[root << 1], tree[root << 1 | 1]);   }   int getsum(int x1, int y1, int x2, int y2) {     return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];       }     }     for (int i = 1; i <= m; i++) {       dp[1][i] = getsum(1, i, min(2, n), min(m, i + k - 1));     }     for (int i = 2; i <= n; i++) {       memset(lazy, 0, sizeof lazy);       memset(tree, 0, sizeof tree);       for (int j = 1; j <= m; j++) {         update(1, 1, m, j, j, dp[i - 1][j]);       }       for (int j = 1; j <= k; j++) {         update(1, 1, m, 1, j, -a[i][j]);       }       for (int j = 1; j <= m; j++) {         dp[i][j] = tree[1] + getsum(i, j, min(n, i + 1), min(m, j + k - 1));         update(1, 1, m, max(j - k + 1, 1), j, a[i][j]);         if (j + k <= m) {           update(1, 1, m, j + 1, j + k, -a[i][j + k]);         }       }     }     int ans = 0;     for (int i = 1; i <= m; i++) {       ans = max(ans, dp[n][i]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 707406378;   const int maxn = 1.5e7 + 10;   void read(long long &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   int main() {     long long n, x, y;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> x >> y;       ans = max(ans, x + y);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     if (y > x) {       return gcd(y, x);     }     if (y == 0) {       return x;     }     return gcd(y, x % y);   }   bool prime(long long int x) {     for (long long int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) {         return 0;       }     }     return 1;   }   long long int fact(long long int n) {     if (n == 0) {       return 1;     }     return n * fact(n - 1);   }   void solve() {     long long int r, c;     cin >> r >> c;     long long int b = 1;     for (long long int i = 0; i < r; i++) {       if (i % 2 == 0) {         for (long long int j = 0; j < c; j++) cout <<  # ;         cout << endl;       } else {         if (b == 1) {           for (long long int j = 0; j < c - 1; j++) cout <<  . ;           cout <<  # ;           cout << endl;           b = 0;         } else {           cout <<  # ;           for (long long int j = 0; j < c - 1; j++) cout <<  . ;           cout << endl;           b = 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int dp[10][310];   int nex[1010][10][1010];   int ai[1010];   int up;   void init(void) {     memset(dp, -1, sizeof(dp));     int i, j;     int cnt[10];     for (i = 1; i <= n; i++) {       memset(cnt, 0, sizeof(cnt));       for (j = 1; j <= 8; j++)         for (int k = 1; k <= n; k++) nex[i][j][k] = 1e9;       for (j = i; j <= n; j++) {         cnt[ai[j]]++;         nex[i][ai[j]][cnt[ai[j]]] = j;       }     }   }   int main() {     int i, j, k;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ai[i];     }     init();     up = (1 << 8) - 1;     int ans = 0;     for (int num = 0; num * 8 <= n; num++) {       for (int i = 0; i < 256; i++)         for (int k = 0; k <= 8; k++) dp[k][i] = 1e9;       dp[0][0] = 1;       for (i = 0; i <= up; i++) {         for (j = 0; j <= 8; j++) {           for (k = 1; k <= 8; k++) {             if (i & (1 << (k - 1))) continue;             if (dp[j][i] > n) continue;             dp[j][i ^ (1 << (k - 1))] =                 min(dp[j][i ^ (1 << (k - 1))], nex[dp[j][i]][k][num] + 1);             dp[j + 1][i ^ (1 << (k - 1))] =                 min(dp[j + 1][i ^ (1 << (k - 1))], nex[dp[j][i]][k][num + 1] + 1);           }         }       }       for (i = 0; i <= 8; i++)         if (dp[i][up] <= n + 1) {           ans = max(ans, num * 8 + i);         }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int num[105];   int a[105][105], sum[105][105], mx[105][105];   int f[105][10005];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> num[i];       for (int j = 1; j <= num[i]; j++) {         cin >> a[i][j];         sum[i][j] = sum[i][j - 1] + a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= num[i]; j++) {         for (int k = 0; k <= j; k++) {           mx[i][j] = max(mx[i][j],                          sum[i][k] + (sum[i][num[i]] - sum[i][num[i] - (j - k)]));         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= m; j++) {         int maxi = 0;         for (int k = 0; k <= num[i] && k <= j; k++) {           maxi = max(maxi, f[i - 1][j - k] + mx[i][k]);         }         f[i][j] = maxi;       }     }     cout << f[n][m] << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long a, b, c, flag = 0;     scanf( %lld , &a);     if (a == 1 || a == 2) {       printf( -1 );       return 0;     }     if (a % 2 == 0) {       flag = 1;     }     if (flag != 1) {       b = (a * a + 1) / 2;       c = (a * a - 1) / 2;       printf( %lld %lld , c, b);     } else {       b = (a * a + 4) / 4;       c = (a * a - 4) / 4;       printf( %lld %lld , c, b);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     vector<int> w(n, 0);     w[0] = v[0];     for (int i = 1; i < n; i++) w[i] = w[i - 1] + v[i];     int score = 0, penalty = 0;     for (int i = 0; i < n; i++) {       if (w[i] <= 60 * 12 - 10)         score++;       else         break;       if (w[i] > 60 * 6 - 10) penalty += w[i] - 60 * 6 + 10;     }     cout << score <<     << penalty << endl;   }
#include <bits/stdc++.h>   using namespace std;   int freq[200005];   int arr[1005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) freq[arr[i] + arr[j]]++;     int ans = 0;     for (int i = 0; i < 2e5 + 5; i++) ans = max(ans, freq[i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   struct change {     int s, t, u;   };   vector<long long> solve(vector<int> a, vector<change> b) {     long long sum = 0;     for (auto x : a) sum += x;     vector<long long> ans;     int n = a.size();     vector<int> cntr(n);     auto change_counter = [&](int i, int delta) {       sum -= max(0, a[i] - cntr[i]);       cntr[i] += delta;       sum += max(0, a[i] - cntr[i]);     };     map<pair<int, int>, int> mp;     for (auto c : b) {       auto it = mp.find({c.s, c.t});       if (it != mp.end()) {         change_counter(it->second, -1);         mp.erase(it);       }       if (c.u != -1) {         mp[{c.s, c.t}] = c.u;         change_counter(c.u, +1);       }       ans.push_back(sum);     }     return ans;   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       vector<int> a(n);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       int q;       scanf( %d , &q);       vector<change> b(q);       for (int i = 0; i < q; i++) {         scanf( %d%d%d , &b[i].s, &b[i].t, &b[i].u);         b[i].s--;         b[i].u--;       }       auto ans = solve(a, b);       for (auto x : ans) printf( %lld n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, t[100001], ans;   double w;   long long lowbit(long long x) { return x & (-x); }   struct rua {     double x, v;     long long id;   } _[100001];   void change(long long x) {     while (x <= n) t[x]++, x += lowbit(x);   }   int sum(long long k) {     long long res = 0;     while (k > 0) res += t[k], k -= lowbit(k);     return res;   }   bool cmp(rua a, rua b) { return fabs(a.x * b.v) < fabs(a.v * b.x); }   int main() {     scanf( %I64d%lf , &n, &w), w += 1e-6;     for (long long i = 1; i <= n; i++)       scanf( %lf%lf , &_[i].x, &_[i].v), _[i].v -= w;     sort(_ + 1, _ + n + 1, cmp);     for (long long i = 1; i <= n; i++) _[i].id = i, _[i].v += 2 * w;     sort(_ + 1, _ + n + 1, cmp);     for (long long i = 1; i <= n; i++)       ans += i - 1 - sum(_[i].id), change(_[i].id);     return printf( %I64d n , ans), 0;   }
#include<cstdio>   #include<cstring>   #include<algorithm>   using namespace std;   char ch;   int t,n,k,h[110],pos;   void read(int &x)   {    x=0;    ch=getchar();    while(ch< 0 ||ch> 9 ) ch=getchar();    while(ch>= 0 &&ch<= 9 )    {      x=x*10+ch- 0 ;     ch=getchar();    }   }   int main()   {    read(t);    while(t--)    {     read(n);read(k);     for (int i=1;i<=n;i++) read(h[i]);     while(k--)     {      pos=0;      for (int j=1;j<=n;j++)       if (j==n) pos=-1;       else if (h[j]<h[j+1]) {h[j]++;pos=j;break;}      if (pos==-1) break;     }      printf( %d n ,pos);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<long long> X(n + 1), Y(n + 1);     for (int i = (1); i <= (n); ++i) scanf( %lld%lld , &X[i], &Y[i]);     long long S = 0;     for (int k = (1); k <= (n); ++k) {       vector<double> V;       for (int i = (1); i <= (n); ++i)         if (i != k) V.push_back(atan2(Y[i] - Y[k], X[i] - X[k]));       sort(V.begin(), V.end());       V.insert(V.end(), V.begin(), V.end());       for (int i = 0, j = 0; i + 1 < n; i++) {         while (V[j] + (j >= n - 1 ? 2 * acos(-1) : 0.0) - V[i] < acos(-1)) j++;         long long x = j - 1 - i, y = n - 2 - x;         S += x * (x - 1) / 2 * y * (y - 1) / 2;       }     }     printf( %lld n , S / 2);     return 0;   }