malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct S {     int c[13], ma;   } a[2010];   int b[20][2020];   bool cmp(S a, S b) { return a.ma > b.ma; }   int dp[20][(1 << 12) + 10], sum[20][(1 << 12) + 10];   int main() {     int T, n, m, i, j, k, l;     scanf( %d , &T);     while (T--) {       memset(dp, 0, sizeof dp);       scanf( %d%d , &n, &m);       for (i = 1; i <= n; i++)         for (j = 1; j <= m; j++) scanf( %d , &b[i][j]);       for (i = 1; i <= m; i++) {         a[i].ma = 0;         for (j = 1; j <= n; j++) {           a[i].ma = max(a[i].ma, b[j][i]);           a[i].c[j] = b[j][i];         }       }       sort(a + 1, a + 1 + m, cmp);       m = min(n, m);       for (i = 1; i <= m; i++)         for (j = 0; j < (1 << n); j++) {           int cc = 0;           for (k = 1; k <= n; k++) {             int ans = 0;             for (l = 0; l < n; l++)               if (j >> ((l + k) % n) & 1) ans += a[i].c[l + 1];             cc = max(ans, cc);           }           sum[i][j] = cc;         }       for (i = 1; i <= m; i++)         for (j = 0; j < (1 << n); j++)           for (k = j;; k = (k - 1) & j) {             dp[i][j] = max(dp[i][j], dp[i - 1][k] + sum[i][j ^ k]);             if (!k) break;           }       printf( %d n , dp[m][(1 << n) - 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1234567;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, a, t;     cin >> s;     vector<string> v;     for (int i = 0; i < 10; i++) {       cin >> a;       v.push_back(a);     }     for (int i = 0; i < s.size(); i += 10) {       t = s.substr(i, 10);       for (int j = 0; j < 10; j++)         if (v[j].compare(t) == 0) {           cout << j;           break;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T gi() {     T f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;   int n, m, c[N];   long long tr[N << 2], dp[N], lz[N << 2];   struct Node {     int l, p;   };   vector<Node> a[N];   inline int ls(int p) { return p << 1; }   inline int rs(int p) { return p << 1 | 1; }   inline void pushup(int p) { tr[p] = max(tr[ls(p)], tr[rs(p)]); }   inline void pushdown(int p) {     if (lz[p]) {       tr[ls(p)] += lz[p], lz[ls(p)] += lz[p];       tr[rs(p)] += lz[p], lz[rs(p)] += lz[p];       lz[p] = 0;     }   }   void modify(int ql, int qr, long long val, int l, int r, int p) {     if (ql <= l && r <= qr) {       tr[p] += val, lz[p] += val;       return;     }     pushdown(p);     int mid = (l + r) >> 1;     if (ql <= mid) modify(ql, qr, val, l, mid, ls(p));     if (qr > mid) modify(ql, qr, val, mid + 1, r, rs(p));     pushup(p);   }   long long query(int ql, int qr, int l, int r, int p) {     if (ql <= l && r <= qr) return tr[p];     int mid = (l + r) >> 1;     long long ans = 0;     if (ql <= mid) ans = query(ql, qr, l, mid, ls(p));     if (qr > mid) ans = max(ans, query(ql, qr, mid + 1, r, rs(p)));     return ans;   }   int main() {     n = gi<int>(), m = gi<int>();     for (int i = 1; i <= n; i += 1) c[i] = gi<int>();     while (m--) {       int l = gi<int>(), r = gi<int>(), p = gi<int>();       a[r].push_back((Node){l, p});     }     long long sum = 0, res = 0;     for (int i = 1; i <= n + 1; i += 1) {       res += c[i];       dp[i] = max(dp[i - 1], query(1, max(1, i - 1), 1, n, 1));       modify(1, i, -c[i], 1, n, 1);       for (auto x : a[i]) modify(1, x.l, x.p, 1, n, 1), sum += x.p;       dp[i] = max(dp[i], sum - res);       modify(i, i, dp[i - 1], 1, n, 1);     }     printf( %lld n , dp[n + 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<string> s(n);     for (string &e : s) cin >> e;     vector<vector<int> > a(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     vector<int> dp(1 << n, (1 << 30));     vector<vector<int> > cost(n, vector<int>(m, 0)), masks(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int max_a = 0;         for (int k = 0; k < n; k++)           if (s[i][j] == s[k][j]) {             max_a = max(max_a, a[k][j]);             cost[i][j] += a[k][j];             masks[i][j] |= (1 << k);           }         cost[i][j] -= max_a;       }     dp[0] = 0;     for (int mask = 1; mask < (1 << n); mask++) {       int j = 0;       for (; j < n; j++)         if (mask & (1 << j)) break;       for (int i = 0; i < m; i++) {         dp[mask] = min(dp[mask], dp[mask & (mask ^ masks[j][i])] + cost[j][i]);         dp[mask] = min(dp[mask], dp[mask ^ (1 << j)] + a[j][i]);       }     }     printf( %d n , dp[(1 << n) - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2][2005];   int a[2005];   int cnt2[2005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 1; i--) {       cnt2[i] = cnt2[i + 1];       if (a[i] == 2) cnt2[i]++;     }     for (int i = 0; i <= 2; i++) dp[i][0] = 1;     for (int i = 1; i <= n; i++) {       dp[0][i] = dp[1][i] = 1;       for (int j = 1; j <= i - 1; j++) {         if (a[i] >= a[j]) dp[0][i] = max(dp[0][j] + 1, dp[0][i]);         if (a[i] <= a[j]) dp[1][i] = max(max(dp[0][j], dp[1][j]) + 1, dp[1][i]);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(dp[1][i] + cnt2[i + 1], ans);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using ulint = unsigned long long;   const int T = 10;   lint dp[T], nxt[T];   void relax(lint &x, lint y) { x = max(x, y); }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     fill(begin(dp), end(dp), -1);     fill(begin(nxt), end(nxt), -1);     int n;     cin >> n;     dp[0] = 0;     while (n--) {       int k;       cin >> k;       vector<lint> cards[4];       for (int i = 0; i < k; i++) {         int c, d;         cin >> c >> d;         cards[c].push_back(d);       }       for (auto &vec : cards) {         sort(vec.begin(), vec.end(), greater<lint>());       }       for (int i = 0; i < T; i++) {         if (dp[i] == -1) continue;         bool flag1 = i + 1 >= T;         bool flag2 = i + 2 >= T;         bool flag3 = i + 3 >= T;         relax(nxt[i], dp[i]);         if (cards[1].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[1][0] * (flag1 + 1));         if (cards[2].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[2][0] * (flag1 + 1));         if (cards[3].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[3][0] * (flag1 + 1));         if (cards[1].size() >= 2)           relax(nxt[(i + 2) % T],                 dp[i] + cards[1][0] * (flag2 + 1) + cards[1][1]);         if (cards[1].size() >= 1 && cards[2].size() >= 1)           relax(nxt[(i + 2) % T], dp[i] + cards[1][0] + cards[2][0] +                                       max(cards[1][0], cards[2][0]) * flag2);         if (cards[1].size() >= 3)           relax(nxt[(i + 3) % T],                 dp[i] + cards[1][0] * (flag3 + 1) + cards[1][1] + cards[1][2]);       }       copy(begin(nxt), end(nxt), begin(dp));     }     cout << *max_element(begin(dp), end(dp)) << endl;   }
#include <bits/stdc++.h>   int n, m, mo;   int sz[111111], ace[111111];   int ancestor(int x) { return x - ace[x] ? ace[x] = ancestor(ace[x]) : x; }   int mul(int x, int y) { return (int)((long long int)x * y % mo); }   int main() {     scanf( %d%d%d , &n, &m, &mo);     if (mo == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) ace[i] = i;     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       ace[ancestor(x)] = ancestor(y);     }     for (int i = 1; i <= n; i++) sz[ancestor(i)]++;     int res = 1, w = 0;     for (int i = 1; i <= n; i++)       if (sz[i]) {         res = mul(res, sz[i]);         w++;       }     if (w == 1)       puts( 1 );     else {       for (w -= 2; w; w--) res = mul(res, n);       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   const int mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;     } else {       exgcd(b, a % b, x, y);       long long temp = x;       x = y;       y = temp - a / b * y;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long x, y, a, b, c;     cin >> a >> b >> c;     c = -c;     long long d = gcd(a, b);     if (c % d != 0) {       cout << -1 <<   n ;       return 0;     }     exgcd(a, b, x, y);     cout << x * (c / d) <<     << y * (c / d) <<   n ;   }
#include <bits/stdc++.h>   const unsigned long long mod = 1e9 + 7;   using namespace std;   const int N = 1e3 + 5;   const double esp = 1e-5;   int n, x, pos, lsum = -1, rsum;   unsigned long long f[N], a[N];   unsigned long long qpow(unsigned long long a, unsigned long long b) {     unsigned long long ans = 1, base = a;     while (b) {       if (b & 1) ans = (ans * base % mod + mod) % mod;       base = (base * base % mod + mod) % mod;       b >>= 1;     }     return ans;   }   void init() {     f[0] = 1;     for (int i = 1; i <= 1000; i++) f[i] = f[i - 1] * i % mod, a[i - 1] = i - 1;   }   unsigned long long cal(unsigned long long n, unsigned long long m) {     return 1ll *            (f[n] * qpow(f[m], mod - 2) % mod * qpow(f[n - m], mod - 2) % mod);   }   void find() {     int l = 0;     int r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (mid <= pos) {         l = mid + 1;         lsum++;       } else {         r = mid;         rsum++;       }     }   }   int main() {     init();     scanf( %d%d%d , &n, &x, &pos);     find();     unsigned long long ans = f[rsum] * cal(n - x, rsum) % mod * f[lsum] % mod *                              cal(x - 1, lsum) % mod * f[n - lsum - rsum - 1] %                              mod;     printf( %lld , ans % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 1e5 + 5;   long long i, j, m, n, k, t, d;   long long ans;   long long x[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> d;     for (i = 1; i <= n; i++) {       cin >> x[i];     }     for (i = 1; i <= n; i++) {       long long low = i + 2, high = n, mid, ok = -1;       while (low <= high) {         mid = (low + high) / 2;         if (x[mid] - x[i] <= d) {           ok = mid;           low = mid + 1;         } else {           high = mid - 1;         }       }       if (ok == -1) continue;       ans += (ok - i) * (ok - i - 1) / 2;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int h[100010], res[100010];   int main() {     int n, i;     while (scanf( %d , &n) != EOF) {       memset(h, 0, sizeof(h));       memset(res, 0, sizeof(res));       for (i = 1; i <= n; i++) {         scanf( %d , &h[i]);       }       int temp = 0;       for (i = 1; i <= n; i++) {         temp = min(temp, h[i] - i);         res[i] = i + temp;       }       temp = n + 1;       for (i = n; i >= 1; i--) {         temp = min(temp, h[i] + i);         res[i] = min(res[i], temp - i);       }       int ans = 0;       for (i = 1; i <= n; i++) {         ans = max(ans, res[i]);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     while (k--) {       int n;       cin >> n;       vector<int> h(n);       for (int i = 0; i < n; i++) cin >> h[i];       sort(h.begin(), h.end());       reverse(h.begin(), h.end());       int ans = 0;       for (int i = 0; i < n; i++) {         int w1 = i + 1;         if (h[i] >= w1) {           ans = max(ans, w1);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[505];   int m, b[505];   int sumA[505];   int sumB[505];   int dp[505][505];   struct Answer {     int p;     char c;     Answer(void){};     Answer(int x, char y) {       p = x;       c = y;     }   } stk[505];   int tot = 0;   int tree[505];   int lowbit(int x) { return x & -x; }   int query(int p) {     int r = 0;     while (p) {       r += tree[p];       p -= lowbit(p);     }     return r;   }   void add(int p) {     while (p <= n) {       tree[p] += 1;       p += lowbit(p);     }   }   void dfs(int l, int r) {     if (l == r) return;     if (dp[l + 1][r] && sumA[r] - sumA[l] > a[l]) {       dfs(l + 1, r);       stk[++tot] = Answer(l,  L );     } else {       dfs(l, r - 1);       stk[++tot] = Answer(r,  R );     }   }   signed main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     scanf( %d , &m);     for (int i = 1; i <= m; ++i) scanf( %d , b + i);     memset(sumA, 0, sizeof(sumA));     memset(sumB, 0, sizeof(sumB));     for (int i = 1; i <= n; ++i) sumA[i] = sumA[i - 1] + a[i];     for (int i = 1; i <= m; ++i) sumB[i] = sumB[i - 1] + b[i];     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; ++i) dp[i][i] = 1;     for (int i = 1; i < n; ++i)       for (int j = 1; i + j <= n; ++j) {         if (sumA[i + j] - sumA[j] > a[j]) dp[j][i + j] |= dp[j + 1][i + j];         if (sumA[i + j - 1] - sumA[j - 1] > a[i + j])           dp[j][i + j] |= dp[j][i + j - 1];       }     bool flag = true;     for (int i = 1, j = 1, k; i <= m; ++i) {       for (k = j; k <= n && sumA[k] != sumB[i]; ++k)         ;       if (k > n) {         flag = false;         break;       }       if (i == m && k != n) {         flag = false;         break;       }       if (!dp[j][k]) {         flag = false;         break;       }       dfs(j, k);       j = k + 1;     }     if (!flag) return puts( NO ), 0;     puts( YES );     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= tot; ++i) {       int q = query(stk[i].p);       add(stk[i].p);       stk[i].p -= q;       if (stk[i].c ==  L )         ++stk[i].p;       else         --stk[i].p;     }     for (int i = 1; i <= tot; ++i) printf( %d %c n , stk[i].p, stk[i].c);   }
#include <bits/stdc++.h>   using namespace std;   int cmp(int a, int b) { return a > b; }   int main() {     int i, j, m, n, sm = 0, sn = 0, num[110], e[110];     string s;     map<string, int> mapp;     map<string, int>::iterator it;     scanf( %d%d , &m, &n);     for (i = 0; i < m; i++) {       scanf( %d , &num[i]);     }     sort(num, num + m, cmp);     for (i = 0; i < n; i++) {       cin >> s;       for (it = mapp.begin(); it != mapp.end(); it++) {         if (it->first == s) {           it->second++;           break;         }       }       if (it == mapp.end()) mapp.insert(pair<string, int>(s, 1));     }     for (it = mapp.begin(), i = 0; it != mapp.end(); ++it, i++) {       e[i] = it->second;     }     sort(e, e + i, cmp);     n = i;     for (i = 0; i < n; i++) {       sm += e[i] * num[i];       sn += e[i] * num[m - i - 1];     }     printf( %d %d , sn, sm);   }
#include <bits/stdc++.h>   int ans[1000006];   int dij[1000006];   int mmax;   void dfs(int now, int num) {     dij[num] = now;     for (int i = 2; i < now; i++) {       if (now % i == 0) {         dfs(now / i, num + 1);       }     }     dij[++num] = 1;     if (num > mmax) {       mmax = num;       for (int i = 0; i <= num; i++) ans[i] = dij[i];     }     return;   }   int main() {     int n;     scanf( %d , &n);     mmax = 0;     if (n == 1)       printf( 1 n );     else {       dfs(n, 0);       for (int i = 0; i <= mmax; i++) printf( %d  , ans[i]);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int num[maxn], ans;   void Solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , num + i);     sort(num + 1, num + 1 + n);     int nn = unique(num + 1, num + 1 + n) - (num + 1);     for (int i = 1; i <= nn; i++) {       int j = num[i] << 1;       int pos = lower_bound(num + 1, num + 1 + nn, j) - num;       while (num[pos - 1] < j && pos <= nn) {         ans = max(ans, num[pos - 1] % num[i]);         pos = lower_bound(num + pos + 1, num + 1 + nn, j) - num;         j += num[i];       }       ans = max(ans, num[pos - 1] % num[i]);     }     printf( %d , ans);   }   int main() {     Solve();     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     if (N == 1) {       cout <<  ! 1  << endl;       return 0;     }     vector<int> res(N);     for (;;) {       int x = 0, y = 0;       for (int i = 0; i < N; ++i) {         if (x == 0 && res[i] == 0) {           x = i + 1;         } else if (res[i] == 0) {           y = i + 1;           break;         }       }       if (y == 0) break;       int z, w;       cout <<  ?   << x <<     << y << endl;       cin >> z;       cout <<  ?   << y <<     << x << endl;       cin >> w;       if (z == 0) {         res[y - 1] = w;       } else if (w == 0) {         res[x - 1] = z;       } else if (z > w) {         res[x - 1] = z;       } else {         res[y - 1] = w;       }     }     set<int> a;     for (int i = 1; i <= N; ++i) a.insert(i);     for (auto x : res) a.erase(x);     for (auto& x : res)       if (x == 0) x = *a.begin();     cout <<  ! ;     for (auto x : res) cout <<     << x;     cout << endl;   }
#include <bits/stdc++.h>   const long long int mod = 1e9 + 7;   using namespace std;   long long int p, q, r, s;   long long int len(long long int x) {     long long int count = 0;     while (x > 0) {       x = x / 10;       count++;     }     return count;   }   long long int fx(long long int x) {     long long int count = 9;     if (x <= 9) return x;     p = len(x);     q = x % 10;     x /= 10;     r = x / pow(10, p - 2);     s = pow(10, p - 2);     x = x % s;     if (p == 2) {       count += r;       if (q < r) count--;       return count;     }     for (int i = (1); i <= (p - 2); i++) count += 9 * pow(10, i - 1);     count += (r - 1) * pow(10, p - 2);     count += x + 1;     if (q < r) count--;     return count;   }   int main() {     long long int y, z;     cin >> y >> z;     long long int temp = fx(z) - fx(y - 1);     cout << temp << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, t, a[200010], f[200010];   long long ans;   struct nood {     int x, id;   } b[200010];   int cmp(nood a, nood b) { return a.x > b.x; }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i].x = a[i];       b[i].id = i;     }     sort(b + 1, b + n + 1, cmp);     for (int i = 1; i <= m * k; i++) {       f[b[i].id] = 1;       ans = ans + b[i].x;     }     printf( %lld n , ans);     for (int i = 1; i <= n; i++) {       if (f[i] == 1) t++;       if (t == m + 1) {         printf( %d  , i - 1);         t = 1;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int tc, n, m, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     long long int k1, k2;     cin >> k1;     queue<long long int> q1;     for (__typeof(k1) i = (0) - ((0) > (k1)); i != (k1) - ((0) > (k1));          i += 1 - 2 * ((0) > (k1))) {       long long int a;       cin >> a;       q1.push(a);     }     cin >> k2;     queue<long long int> q2;     for (__typeof(k2) i = (0) - ((0) > (k2)); i != (k2) - ((0) > (k2));          i += 1 - 2 * ((0) > (k2))) {       long long int a;       cin >> a;       q2.push(a);     }     long long int af = q1.front();     long long int bf = q2.front();     long long int sa = ((int)(q1).size());     long long int sb = ((int)(q2).size());     long long int ans = 0;     while (((int)(q1).size()) && ((int)(q2).size())) {       long long int a = q1.front();       long long int b = q2.front();       if ((ans > 4e7)) {         cout << -1;         return 0;       }       if (a < b) {         q2.push(a);         q2.push(b);       } else {         q1.push(b);         q1.push(a);       }       q1.pop();       q2.pop();       ans++;     }     cout << ans <<    ;     if (((int)(q1).size()) == 0)       cout << 2;     else       cout << 1;     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, h, a, b, k, s[10001];   int main() {     scanf( %lld%lld%lld%lld%lld , &n, &h, &a, &b, &k);     for (int i = 1; i <= k; i++) {       long long u1, v1, u2, v2;       scanf( %lld%lld%lld%lld , &u1, &v1, &u2, &v2);       if (u1 == u2)         s[i] = abs(v1 - v2);       else if ((a < v1 && v1 < b) || (a < v2 && v2 < b))         s[i] = abs(u1 - u2) + abs(v1 - v2);       else         s[i] = min(abs(u1 - u2) + abs(v1 - a) + abs(v2 - a),                    abs(u1 - u2) + abs(v1 - b) + abs(v2 - b));     }     for (int i = 1; i <= k; i++) printf( %lld n , s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int h[N], e[2 * N], ne[2 * N], w[2 * N], idx;   int dist[N][N];   int n, m, k;   bool st[N];   pair<int, int> q[N];   void add(int a, int b, int c) {     e[idx] = b;     ne[idx] = h[a];     w[idx] = c;     h[a] = idx++;   }   priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>       heap;   void dijkstra(int start, int dist[]) {     memset(st, 0, sizeof st);     dist[start] = 0;     heap.push({0, start});     while (heap.size()) {       int t = heap.top().second;       heap.pop();       if (st[t]) continue;       st[t] = 1;       for (int i = h[t]; i != -1; i = ne[i]) {         int j = e[i];         if (dist[j] > dist[t] + w[i]) {           dist[j] = dist[t] + w[i];           heap.push({dist[j], j});         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie(0);     int T = 1;     while (T--) {       memset(dist, 0x3f, sizeof dist);       memset(h, -1, sizeof h);       cin >> n >> m >> k;       for (int i = 1; i <= m; i++) {         int a, b, c;         cin >> a >> b >> c;         add(a, b, c), add(b, a, c);       }       for (int i = 1; i <= k; i++) cin >> q[i].first >> q[i].second;       for (int i = 1; i <= n; i++) dijkstra(i, dist[i]);       long long ans = 1e18;       for (int i = 0; i < idx; i += 2) {         int a = e[i], b = e[i ^ 1];         long long now = 0;         for (int j = 1; j <= k; j++) {           int from = q[j].first, to = q[j].second;           now +=               min(min(dist[from][a] + dist[b][to], dist[from][b] + dist[a][to]),                   dist[from][to]);         }         ans = min(ans, now);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const int N = 1e5 + 5;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       long long nem = 0, ans = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > 0) {           nem += a[i];         } else {           if (nem < -a[i]) {             ans += -a[i] - nem;             nem = 0;           } else {             nem = nem + a[i];           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     cin >> n >> k;     int total = (n * (n - 1)) / 2;     if (total >= n * k) {       total = n * k;       cout << total <<   n ;       int nod1 = 1;       int nod2 = nod1 + 1;       int cate = 0;       while (total > 0) {         cate++;         if (nod2 > n) nod2 = 1;         cout << nod1 <<     << nod2 <<   n ;         if (cate == k) {           nod1++;           nod2 = nod1 + 1;           cate = 0;         } else           nod2++;         total--;       }     } else       cout << -1 <<   n ;   }