malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void chkmin(T &x, T y) {     x = x > y ? y : x;   }   const int INF = (1ll << 30) - 1;   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 0;     } while (ch >  9  || ch <  0 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     x = f ? x : -x;   }   template <typename T>   void write(T x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 3e4 + 5;   const int K = 200 + 5;   int n, m, a[N], f[N][K][4];   int main() {     read(n);     read(m);     memset(f, -0x3f, sizeof(f));     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 0; i <= n; i++)       for (int j = 0; j < 4; j++) f[i][0][j] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x = 1 + (j != 1 && j != m);         f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j - 1][3]) + x * a[i];         f[i][j][1] = max(f[i][j][0], f[i - 1][j][1]);         f[i][j][2] = max(f[i - 1][j][2], f[i - 1][j - 1][1]) - x * a[i];         f[i][j][3] = max(f[i][j][2], f[i - 1][j][3]);         if (x == 2) f[i][j][1] = max(f[i][j][1], f[i - 1][j - 1][1]);         if (x == 2) f[i][j][3] = max(f[i][j][3], f[i - 1][j - 1][3]);       }     }     int ans = 0;     for (int i = 0; i < 4; i++) chkmax(ans, f[n][m][i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int pos, h, ans, id, f;   } Do[100001];   int n;   int cmd(node a, node b) { return a.pos < b.pos; }   int cmd2(node a, node b) { return a.id < b.id; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &Do[i].pos, &Do[i].h);       Do[i].id = i;     }     sort(Do + 1, Do + n + 1, cmd);     Do[n].ans = 1;     Do[n].f = n;     for (int i = n - 1; i >= 1; i--) {       Do[i].ans = 1;       Do[i].f = i;       int next = i + 1;       if (Do[i].pos + Do[i].h - 1 < Do[i + 1].pos) continue;       while (next <= n) {         if (Do[Do[next].f + 1].pos > Do[i].pos + Do[i].h - 1) {           Do[i].ans += Do[next].ans;           Do[i].f = Do[next].f;           break;         } else {           Do[i].ans += Do[next].ans;           Do[i].f = Do[next].f;           next = Do[next].f + 1;         }       }     }     sort(Do + 1, Do + n + 1, cmd2);     for (int i = 1; i <= n; i++) printf( %d  , Do[i].ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double fact[51], all = 0.0;     fact[0] = 1;     for (int i = 1; i < 51; i++) fact[i] = fact[i - 1] * i;     int N, A[50], P;     double dp[51][51];     cin >> N;     for (int i = 0; i < N; i++) cin >> A[i];     cin >> P;     int sum = 0;     for (int i = 0; i < N; i++) sum += A[i];     if (sum <= P) {       cout << N << endl;       return (0);     }     for (int i = 0; i < N; i++) {       memset(dp, 0, sizeof(dp));       dp[0][0] = 1;       for (int j = 0; j < N; j++) {         if (i == j) continue;         for (int k = N - 1; k >= 0; k--) {           for (int l = P; l >= A[j]; l--) {             dp[k + 1][l] += dp[k][l - A[j]];           }         }       }       for (int j = 0; j < N; j++) {         for (int k = max(0, P - A[i] + 1); k <= P; k++) {           all += fact[j] * fact[N - 1 - j] * dp[j][k] * j;         }       }     }     cout << fixed << setprecision(10) << all / fact[N] << endl;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   void scan() {}   template <typename F, typename... R>   void scan(F& f, R&... r) {     cin >> f;     scan(r...);   }   int di_;   string dnms_, co_ =  , ;   void debug_() { cout << endl; }   template <typename F, typename... R>   void debug_(F& f, R&... r) {     while (dnms_[di_] !=  , ) cout << dnms_[di_++];     di_++;     cout <<  :   << f <<  , ;     debug_(r...);   }   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,  << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& a) {     out <<   ;     for (auto it = a.begin(); it != a.end(); it++) {       if (it != a.begin()) out <<    ;       out << *it;     }     out <<   ;     return out;   }   template <class A, class B>   istream& operator>>(istream& in, pair<A, B>& a) {     in >> a.first >> a.second;     return in;   }   template <class A>   istream& operator>>(istream& in, vector<A>& a) {     for (A& i : a) in >> i;     return in;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<long long int> v(m);     cin >> v;     vector<long long int> a(n + 2, 0);     for (int i = 0; i < m - 1; i++) {       long long int xi = v[i];       long long int xi1 = v[i + 1];       if (xi == xi1) continue;       if (xi1 < xi) swap(xi1, xi);       if (xi > 1) {         a[1] += xi1 - xi;         a[xi] -= xi1 - xi;       }       a[xi] += xi1 - 1;       a[xi + 1] -= xi1 - 1;       if (xi1 - xi - 1 > 0) {         a[xi + 1] += xi1 - xi - 1;         a[xi1] -= xi1 - xi - 1;       }       a[xi1] += xi;       a[xi1 + 1] -= xi;       if ((n - xi1) > 0) {         a[xi1 + 1] += xi1 - xi;         a[n + 1] -= xi1 - xi;       }     }     for (int i = 1; i < n + 2; ++i) {       a[i] += a[i - 1];     }     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     init_code();     long long t;     cin >> t;     while (t--) {       long long x1, y1, z1;       long long x2, y2, z2;       cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;       long long ans = 0;       if (z1 >= y2) {         z1 = z1 - y2;         ans = ans + 2 * (y2);         y2 = 0;         long long f = z1 + x1;         if (f <= z2) {           z2 = z2 - f;           ans = ans - 2 * z2;         }       } else {         ans = ans + 2 * (z1);         y2 = y2 - z1;         z1 = 0;         long long f = z1 + x1;         if (f <= z2) {           z2 = z2 - f;           ans = ans - 2 * z2;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   char c[600][600];   int check(int x, int y) {     if (c[x][y - 1] ==  *  && c[x][y + 1] ==  *  && c[x + 1][y] ==  *  &&         c[x - 1][y] ==  *  && c[x][y] ==  * )       return 1;     return 0;   }   int main() {     int m, n;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> c[i][j];     int x = -1, y = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (check(i, j) == 1) {           x = i;           y = j;         }       }     if (x == -1 || y == -1) {       cout <<  NO  << endl;       return 0;     }     for (int i = x - 1; i >= 0; i--) {       if (c[i][y] ==  * ) {         c[i][y] =  . ;       } else         break;     }     for (int i = x + 1; i < n; i++) {       if (c[i][y] ==  * ) {         c[i][y] =  . ;       } else         break;     }     for (int i = y - 1; i >= 0; i--) {       if (c[x][i] ==  * ) {         c[x][i] =  . ;       } else         break;     }     for (int i = y + 1; i < m; i++) {       if (c[x][i] ==  * ) {         c[x][i] =  . ;       } else         break;     }     c[x][y] =  . ;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (c[i][j] ==  * ) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int N;   int c[2][MAXN];   int idx[2];   pair<int, int> p[MAXN];   int pn;   long long solve() {     long long ret = 0;     int pre = -1;     for (int i = 0; i < N; ++i) idx[i] = 1;     while (1) {       int opt = 1000000007, x = -1;       for (int i = 0; i < N; ++i) {         if (idx[i] <= c[i][0]) {           if (c[i][idx[i]] < opt && c[i][idx[i]] >= pre) {             opt = c[i][idx[i]];             x = i;           }         }       }       if (x != -1) {         pre = opt;         p[pn++] = make_pair(opt, x + 1);         ++idx[x];         continue;       }       opt = 1000000007, x = -1;       for (int i = 0; i < N; ++i) {         if (idx[i] <= c[i][0]) {           if (c[i][idx[i]] < opt) {             opt = c[i][idx[i]];             x = i;           }         }       }       if (x == -1) return ret;       ret += opt < pre;       pre = opt;       p[pn++] = make_pair(opt, x + 1);       ++idx[x];     }   }   int main() {     cin >> N;     for (int i = 0; i < N; ++i) {       cin >> c[i][0] >> c[i][1];       int x, y, m;       cin >> x >> y >> m;       for (int j = 2; j <= c[i][0]; ++j) {         c[i][j] = (1LL * c[i][j - 1] * x + y) % m;       }     }     cout << solve() << endl;     for (int i = 0; i < pn; ++i) {       printf( %d %d n , p[i].first, p[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   const int MAXQ = 5000005;   int n, m, X1[MAXQ], X2[MAXQ], Y1[MAXQ], Y2[MAXQ];   bool ans[MAXQ];   bitset<MAXN> dp1[MAXN][MAXN], dp2[MAXN][MAXN], temp;   char board[MAXN][MAXN];   void dnc(int r1, int r2, vector<int> &que) {     if (que.empty() || r1 > r2) return;     int mid = (r1 + r2) / 2;     for (int i = r1; i <= r2; ++i) {       for (int j = 1; j <= m; ++j) {         dp1[i][j].reset();         dp2[i][j].reset();       }     }     for (int i = mid; i >= r1; --i) {       for (int j = m; j >= 1; --j) {         if (board[i][j] ==  # ) continue;         if (i == mid)           dp1[i][j].set(j);         else           dp1[i][j] |= dp1[i + 1][j];         if (j < m) dp1[i][j] |= dp1[i][j + 1];       }     }     for (int i = mid; i <= r2; ++i) {       for (int j = 1; j <= m; ++j) {         if (board[i][j] ==  # ) continue;         if (i == mid)           dp2[i][j].set(j);         else           dp2[i][j] |= dp2[i - 1][j];         if (j > 1) dp2[i][j] |= dp2[i][j - 1];       }     }     vector<int> q1, q2;     for (int i = 0; i < que.size(); ++i) {       int pos = que[i];       if (X1[pos] <= mid && X2[pos] >= mid) {         temp = (dp1[X1[pos]][Y1[pos]] & dp2[X2[pos]][Y2[pos]]);         ans[pos] = temp.any();       } else if (X2[pos] < mid)         q1.push_back(pos);       else         q2.push_back(pos);     }     dnc(r1, mid - 1, q1);     dnc(mid + 1, r2, q2);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , board[i] + 1);     int q;     vector<int> que;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       scanf( %d %d %d %d , &X1[i], &Y1[i], &X2[i], &Y2[i]);       que.push_back(i);     }     dnc(1, n, que);     for (int i = 0; i < q; ++i) {       if (ans[i])         printf( Yes n );       else         printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[3005];   vector<long long> sum[3005];   struct node {     int mon;     int who;     bool operator<(const node &a) const { return mon > a.mon; }   };   int main() {     int n, m;     int p, c;     int get;     int Max;     long long ans;     int pos[3005];     while (~scanf( %d%d , &n, &m)) {       Max = 0;       get = 0;       for (int i = 2; i <= m; i++) {         v[i].clear();         sum[i].clear();       }       for (int i = 0; i < n; i++) {         scanf( %d%d , &p, &c);         if (p == 1)           get++;         else {           v[p].push_back(c);         }       }       for (int i = 2; i <= m; i++) {         long long s = 0;         sort(v[i].begin(), v[i].end());         Max = max(Max, (int)v[i].size());         for (int j = 0; j < v[i].size(); j++) {           s += v[i][j];           sum[i].push_back(s);         }       }       if (get > Max) {         printf( 0 n );         continue;       } else {         int g;         ans = 999999999999999L;         for (int i = get; i <= Max; i++) {           g = get;           long long cost = 0;           memset(pos, 0, sizeof(pos));           for (int j = 2; j <= m; j++) {             if (i < v[j].size()) {               pos[j] = v[j].size() - i;               g += pos[j];               cost += sum[j][pos[j] - 1];             }           }           if (g > i) {             ans = min(ans, cost);             continue;           }           priority_queue<node> Q;           for (int j = 2; j <= m; j++) {             if (pos[j] < v[j].size()) Q.push((node){v[j][pos[j]], j});           }           int need = i + 1 - g;           while (need) {             if (Q.empty()) break;             node a = Q.top();             Q.pop();             cost += a.mon;             pos[a.who]++;             if (v[a.who].size() > pos[a.who])               Q.push((node){v[a.who][pos[a.who]], a.who});             need--;           }           if (need == 0) ans = min(ans, cost);         }         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long k2, k3, k5, k6;     long long sum = 0;     cin >> k2 >> k3 >> k5 >> k6;     long min = k2 < k5 ? k2 < k6 ? k2 : k6 : k5 < k6 ? k5 : k6;     sum += min * 256;     k2 -= min;     k5 -= min;     k6 -= min;     min = k2 < k3 ? k2 : k3;     sum += 32 * min;     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   using namespace std;   bool vis[maxn];   int a[maxn];   int main() {     string s;     cin >> s;     int k = s.size();     char y = s[0];     int ans = 1;     for (int i = 0; i < k; i++) {       if (i == 0) {         cout <<  Mike  << endl;         continue;       }       if (s[0] < s[i]) {         cout <<  Ann  << endl;         continue;       }       if (s[i] > y) {         cout <<  Ann  << endl;       } else {         y = s[i];         cout <<  Mike  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char s[10000010];   struct Trie {     struct nd {       int ch[2], fa, fail, pos;     } t[10000010];     int used;     Trie() : used(1) {}     int id[10000010];     int ins(int len, int I) {       int u = 1;       for (int i = 1; i <= len; i++) {         if (!t[u].ch[s[i] -  a ])           t[u].ch[s[i] -  a ] = ++used, t[t[u].ch[s[i] -  a ]].fa = u;         u = t[u].ch[s[i] -  a ];       }       id[u] = I;       return u;     }     void build() {       queue<int> q;       for (int j = 0; j < 2; j++)         if (t[1].ch[j]) {           t[t[1].ch[j]].fail = 1;           q.push(t[1].ch[j]);         }       while (!q.empty()) {         int i = q.front();         q.pop();         if (id[i])           t[i].pos = id[i];         else           t[i].pos = t[t[i].fail].pos;         for (int j = 0; j < 2; j++) {           if (t[i].ch[j])             t[t[i].ch[j]].fail = t[t[i].fail].ch[j], q.push(t[i].ch[j]);           else             t[i].ch[j] = t[t[i].fail].ch[j];         }       }     }   } T;   int r[1000];   bool e[1000][1000];   void add(int i) {     int p = r[i];     if (T.t[T.t[p].fail].pos) {       e[T.t[T.t[p].fail].pos][i] = 1;     }     p = T.t[p].fa;     while (p) {       if (T.t[p].pos) {         e[T.t[p].pos][i] = 1;       }       p = T.t[p].fa;     }   }   int cp[1000];   bool vis[1000];   vector<int> pth[1000];   int fnd(int x) {     for (int i = 1; i <= n; i++) {       if (!vis[i] && e[x][i]) {         vis[i] = 1;         if (!cp[i] || fnd(cp[i])) {           cp[i] = x;           return 1;         }       }     }     return 0;   }   int id[1000];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       int m = strlen(s + 1);       r[i] = T.ins(m, i);     }     T.build();     for (int i = 1; i <= n; i++) add(i);     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) e[i][j] |= (e[i][k] & e[k][j]);       }     }     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       fnd(i);     }     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++)       if (cp[i]) vis[cp[i]] = 1;     int c = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         c++;         int x = i;         pth[c].push_back(x);         while (cp[x]) {           x = cp[x];           pth[c].push_back(x);         }         reverse(pth[c].begin(), pth[c].end());       }     }     for (int i = 1; i <= c; i++) id[i] = pth[i].size() - 1;     while (1) {       memset(vis, 0, sizeof(vis));       for (int i = 1; i <= c; i++) {         int u = pth[i][id[i]];         for (int j = 1; j <= n; j++)           if (e[u][j]) vis[j] = 1;       }       bool fl = 1;       for (int i = 1; i <= c; i++)         if (vis[pth[i][id[i]]]) {           fl = 0;           break;         }       if (fl) break;       for (int i = 1; i <= c; i++) {         while (vis[pth[i][id[i]]]) id[i]--;       }     }     printf( %d n , c);     for (int i = 1; i <= c; i++) printf( %d  , pth[i][id[i]]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long tab[200001], min1, odl = -1, wynik, first;     cin >> n;     cin >> tab[0];     min1 = 0;     first = 0;     for (int i = 1; i < n; i++) {       cin >> tab[i];       if (tab[i] == tab[min1]) {         if (odl < i - min1) odl = i - min1;         min1 = i;       }       if (tab[i] < tab[min1]) {         min1 = i;         first = i;         odl = -1;       }     }     if (odl == -1)       cout << n * (tab[first] + 1) - 1;     else {       odl--;       int space = n - (min1 - first + 1);       if (odl > space)         cout << n * tab[first] + odl;       else         cout << n * tab[first] + space;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int M = 10005;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   int n, a, i, j, b[M + 1], s[100100], r = 200000000;   int main() {     scanf( %d , &n);     for (i = 1; i <= M; i++) b[i] = 10000;     for (i = 1; i <= n; i++) {       scanf( %d , &a);       s[i] = s[i - 1] + a;       for (j = 1; j <= M && i - j > 0; j++)         b[j] = min(b[j], abs(s[i] - s[i - j]));     }     for (j = 1; j <= M; j++) r = min(r, j * j + b[j] * b[j]);     printf( %d n , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[55], b[55];     int n, i, j, sum = 0, sum1 = 0, s = 0, s1 = 0, count = 0, count1 = 0, k = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     for (i = 0; i < n; i++) {       scanf( %d , &b[i]);       sum1 += b[i];     }     if (sum < sum1) {       printf( No n );     } else {       printf( Yes n );     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long MX = 4e6 + 5, MOD = 1e9 + 7, inf = 1e18, LG = 21;   int main() {     int t;     cin >> t;     while (t--) {       long long x0, n, ans = 0;       cin >> x0 >> n;       if (n == 0) {         cout << x0 <<   n ;         continue;       }       if (x0 % 2 == 0) {         long long k = (((n - 1) / 4) * 4 + 1);         ans = x0 - k;         for (long long i = k + 1; i <= n; i++) {           if (i % 4 < 2)             ans -= i;           else             ans += i;         }       } else {         long long k = (((n - 1) / 4) * 4 + 1);         ans = x0 + k;         for (long long i = k + 1; i <= n; i++) {           if (i % 4 < 2)             ans += i;           else             ans -= i;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxN = 1 << 18;   template <class T1, class T2>   inline void remax(T1& a, T2 b) {     a = max(a, (T1)b);   }   int deg[maxN], fat[maxN];   vector<int> G[maxN];   queue<int> Q;   long long w[maxN];   pair<long long, int> leg[2][maxN];   void solve() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (1); i < (int)(n + 1); i++) scanf( %lld , w + i);     bool tree = m == n - 1;     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);       deg[a]++, deg[b]++;     }     int s, prv = 0;     scanf( %d , &s);     if (tree) deg[s] = maxN;     for (int i = (1); i < (int)(n + 1); i++)       if (deg[i] == 1) Q.push(i);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       for (int u : G[v])         if (deg[u] > 1) {           pair<long long, int> prop = {leg[0][v].first + w[v], v};           fat[v] = u;           if (leg[0][u].first <= prop.first)             leg[1][u] = leg[0][u], leg[0][u] = prop;           else if (leg[1][u].first < prop.first)             leg[1][u] = prop;           if (--deg[u] == 1) Q.push(u);         }     }     long long res = 0, finish = 0;     while (deg[s] < 2) {       res += w[s];       remax(finish, leg[0][s].second == prv ? leg[1][s].first : leg[0][s].first);       prv = s;       s = fat[s];     }     remax(finish, leg[0][s].second == prv ? leg[1][s].first : leg[0][s].first);     for (int i = (1); i < (int)(n + 1); i++)       if (deg[i] > 1) {         res += w[i];         if (i != s) remax(finish, leg[0][i].first);       }     res += finish;     printf( %lld n , res);   }   int main() {     int t;     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, minx = 999999, ans, df1, df2;     char s[51];     scanf( %d , &n);     getchar();     scanf( %s , s);     for (int i = 0; i < n - 3; i++) {       int t = 0;       ans = 0;       while (t <= 3) {         int x = i + t;         if (t == 0) {           df1 = s[x] -  A ;           df2 =  Z  - s[x] + 1;           ans += min(df1, df2);         }         if (t == 1) {           df1 = abs(s[x] -  C );           df2 =  Z  - s[x] + 3;           ans += min(df1, df2);         }         if (t == 2) {           df1 = abs(s[x] -  T );           df2 = s[x] -  A  + 7;           ans += min(df1, df2);         }         if (t == 3) {           df1 = abs(s[x] -  G );           df2 =  Z  - s[x] + 7;           ans += min(df1, df2);         }         t++;       }       minx = min(minx, ans);     }     printf( %d n , minx);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m;   int a[N], q[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> m;     for (int i = 0; i < m; ++i) cin >> q[i];     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(q, q + m);     sort(a, a + n);     int r = n - 1, res = 0;     while (r >= 0) {       int t = q[0];       while (t-- > 0 && r >= 0) {         res += a[r--];       }       int k = 2;       while (k-- > 0 && r >= 0) r--;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2001;   const long long INF = 1e15;   int DELTA = 2500;   int n;   long long price[MAXN], Time[MAXN];   long long dp[MAXN][3 * MAXN];   long long rec(int idx, int remTime) {     if (remTime >= MAXN) remTime = MAXN - 1;     if (idx == n) return remTime >= 0 ? 0 : INF;     long long &ans = dp[idx][remTime + DELTA];     if (ans != -1) return ans;     ans = INF;     ans = min(ans, rec(idx + 1, remTime - 1));     ans = min(ans, price[idx] + rec(idx + 1, remTime + Time[idx]));     return ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> Time[i] >> price[i];     memset(dp, -1, sizeof(dp));     cout << rec(0, 0) << endl;     return 0;   }