malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     int y, ne;   } e[200010];   int f[100005], h[100005], np, vis[100005], s;   long long dp[100005], r[100005];   long long saya(int n) {     if (dp[n] != -1) return dp[n];     vis[n] = 1;     long long ans = 0, res = 0;     vector<long long> v;     for (int i = h[n]; i; i = e[i].ne) {       if (!vis[e[i].y]) {         v.push_back(saya(e[i].y));         res += r[e[i].y];       }     }     sort(v.begin(), v.end());     int j = f[n] - 1;     if (n == s) j++;     for (int i = v.size() - 1; i >= 0 && j > 0; i--, j--) {       ans += v[i];     }     if (j != 0) {       ans += 2 * min(res, 1ll * j);       r[n] = j - min(res, 1ll * j);     }     ans += f[n] - j;     return dp[n] = ans;   }   void add(int a, int b) {     e[np].y = b;     e[np].ne = h[a];     h[a] = np;     np++;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &f[i]);     np = 1;     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b);       add(b, a);     }     scanf( %d , &s);     memset(dp, -1, sizeof(dp));     printf( %I64d n , saya(s));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int val[N];   int dp[N][N];   vector<int> v[N];   int n, k;   void solve(int node, int par) {     dp[node][0] = val[node];     for (auto to : v[node]) {       if (to != par) solve(to, node);     }     for (int dep = 0; dep < N; ++dep) {       if (dep == 0) {         for (auto to : v[node]) {           if (to == par) continue;           dp[node][dep] += dp[to][max(0, k - dep - 1)];         }       } else {         for (auto to : v[node]) {           if (to == par) continue;           int cur = dp[to][dep - 1];           for (auto other : v[node]) {             if (other == par || other == to) continue;             cur += dp[other][max(dep - 1, k - dep - 1)];           }           dp[node][dep] = max(dp[node][dep], cur);         }       }     }     for (int dep = N - 1; dep > 0; --dep) {       dp[node][dep - 1] = max(dp[node][dep - 1], dp[node][dep]);     }   }   int main() {     cin >> n >> k;     k++;     for (int i = 1; i <= n; i++) cin >> val[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     solve(1, 1);     cout << dp[1][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int roundpow2(int x) {     int y = 1;     while (y < x) {       y *= 2;     }     return y;   }   class SegmentTree {    private:     vector<pair<int, int>> tree;     int sz;     void push(int i) {       if (tree[i] != make_pair(-1, -1)) {         tree[i * 2 + 1] = tree[i];         tree[i * 2 + 2] = tree[i];         tree[i] = make_pair(-1, -1);       }     }     pair<int, int> query(int i, int tl, int tr, int index) {       if (tl == tr - 1) {         return tree[i];       }       push(i);       int tm = (tl + tr) / 2;       if (index < tm) {         return query(2 * i + 1, tl, tm, index);       } else {         return query(2 * i + 2, tm, tr, index);       }     }     void update(int i, int tl, int tr, int l, int r, pair<int, int> val) {       if (l >= tr || r <= tl) {         return;       }       if (l <= tl && tr <= r) {         tree[i] = val;         return;       }       if (tl == tr - 1) {         return;       }       push(i);       int tm = (tl + tr) / 2;       update(i * 2 + 1, tl, tm, l, r, val);       update(i * 2 + 2, tm, tr, l, r, val);     }       public:     SegmentTree(int n) {       sz = roundpow2(n);       tree.resize(2 * sz, make_pair(-1, -1));       for (int i = n - 1; i < 2 * n - 1; i++) {         tree[i] = make_pair(0, n - 1);       }     }     pair<int, int> query(int index) { return query(0, 0, sz, index); }     void update(int l, int r, pair<int, int> val) {       update(0, 0, sz, l, r + 1, val);     }   };   int n, k, a;   int m;   int func(int l, int r) { return (r - l + 2) / (a + 1); }   int main() {     cin >> n >> k >> a >> m;     SegmentTree tree(n);     int p = func(0, n - 1);     int ans = -1;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       x--;       pair<int, int> v = tree.query(x);       int l = v.first;       int r = v.second;       p -= func(l, r);       p += func(l, x - 1);       p += func(x + 1, r);       tree.update(l, x - 1, make_pair(l, x - 1));       tree.update(x + 1, r, make_pair(x + 1, r));       if (p < k && ans == -1) {         ans = i + 1;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int a[1000010];   int d[1000010];   int lowbit(int x) { return x & -x; }   void update(int x, int v) {     while (x <= n) {       d[x] += v;       x += lowbit(x);     }   }   int query(int x) {     int res = 0;     while (x) {       res += d[x];       x -= lowbit(x);     }     return res;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       update(a[i], 1);     }     while (q--) {       int k;       scanf( %d , &k);       if (k > 0)         update(k, 1);       else {         k = -k;         int l = 1, r = n, pos = -1;         while (l <= r) {           int mid = (l + r) >> 1;           if (query(mid) < k) {             l = mid + 1;           } else {             r = mid - 1;             pos = mid;           }         }         if (pos != -1) update(pos, -1);       }     }     int ans = -1;     for (int i = 1; i <= n; i++) {       if (query(i) - query(i - 1)) {         ans = i;         break;       }     }     printf( %d , (ans == -1 ? 0 : ans));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double dp[105][105][105];   void solve(int r, int s, int p) {     double _r = 0, _s = 0, _p = 0;     for (int i = r; i >= 0; i--) {       for (int j = s; j >= 0; j--) {         for (int k = p; k >= 0; k--) {           double tot = i * j + j * k + k * i;           if ((i == 0) && (j == 0) && (k > 0)) _p += dp[i][j][k];           if ((k == 0) && (j == 0) && (i > 0)) _r += dp[i][j][k];           if ((i == 0) && (k == 0) && (s > 0)) _s += dp[i][j][k];           if (tot == 0) continue;           if (i > 0) {             double t = i * k;             dp[i - 1][j][k] += (dp[i][j][k] * t / tot);           }           if (j > 0) {             double t = j * i;             dp[i][j - 1][k] += (dp[i][j][k] * t / tot);           }           if (k > 0) {             double t = j * k;             dp[i][j][k - 1] += (dp[i][j][k] * t / tot);           }         }       }     }     printf( %0.9f %0.9f %0.9f n , _r, _s, _p);   }   int main() {     int r, s, p;     cin >> r >> s >> p;     dp[r][s][p] = 1;     solve(r, s, p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200005], b[30][200005], d[30][200005], c[200005], r[200005], l[200005];   long long ans = 0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < 30; i++) {       b[i][n] = n;       for (int j = n - 1; j >= 0; j--)         if (a[j] >> i & 1)           b[i][j] = j;         else           b[i][j] = b[i][j + 1];       if (a[0] >> i & 1)         d[i][0] = 0;       else         d[i][0] = -1;       for (int j = 1; j < n; j++)         if (a[j] >> i & 1)           d[i][j] = j;         else           d[i][j] = d[i][j - 1];     }     int t = 0;     for (int i = 0; i < n; i++) {       while (t && a[c[t - 1]] <= a[i]) t--;       if (t)         l[i] = c[t - 1] + 1;       else         l[i] = 0;       c[t++] = i;     }     t = 0;     for (int i = n - 1; i >= 0; i--) {       while (t && a[c[t - 1]] < a[i]) t--;       if (t)         r[i] = c[t - 1] - 1;       else         r[i] = n - 1;       c[t++] = i;     }     for (int i = 0; i < n; i++) {       int L = -1, R = n;       for (int j = 0; j < 30; j++)         if (!(a[i] >> j & 1)) L = max(L, d[j][i]), R = min(R, b[j][i]);       L++, R--;       L = max(L, l[i]), R = min(R, r[i]);       ans +=           1ll * (i - l[i] + 1) * (r[i] - i + 1) - 1ll * (i - L + 1) * (R - i + 1);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = static_cast<int>(1e9) + 7;   using namespace std::rel_ops;   inline long long bit(int x) { return 1LL << x; }   template <class T>   inline bool chmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   inline bool chmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {     return make_pair(v, c);   }   template <class T>   inline istream& operator>>(istream& is, vector<T>& v) {     for (auto& x : v) is >> x;     return is;   }   template <class T>   inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {     bool t = 0;     for (const T& x : v.first) {       if (t) os << v.second;       os << x;       t = 1;     }     return os;   }   template <class T>   inline ostream& operator<<(ostream& os, vector<T>& v) {     return os << v *    ;   }   struct before_main {     before_main() {       cin.tie(0);       ios::sync_with_stdio(0);       cout << fixed << setprecision(20);       ;     };   } __before_main;   long long solve(long long n, long long k) {     if (n == 1) return 0;     long long a = n;     long long ans = 0;     while (k--) {       a -= 2;       if (a < 0) return ans;       ans += 2 * a + 1;     }     return ans;   }   int main() {     long long n, k;     cin >> n >> k;     cout << solve(n, k) << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, p[202020], ki[202020], ka[202020], ta, tb, taa, tbb, nx[202020];   void gab(long long aa, long long bb) {     nx[ka[aa]] = ki[bb];     ka[aa] = ka[bb];     ki[bb] = ki[aa];     p[aa] = bb;   }   long long car(long long aa) {     if (p[aa] == aa)       return aa;     else       return p[aa] = car(p[aa]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (i = 1; i <= n; i++) p[i] = i;     for (i = 1; i <= n; i++) ki[i] = i;     for (i = 1; i <= n; i++) ka[i] = i;     for (i = 1; i < n; i++) {       cin >> ta >> tb;       taa = car(ta);       tbb = car(tb);       gab(taa, tbb);     }     long long tem = ki[car(1)];     for (i = 1; i <= n; i++) {       cout << tem;       tem = nx[tem];       if (i < n)         cout <<    ;       else         cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200001;   vector<char> now;   char t[maxn], p[maxn];   int lt, lp, l, r;   int a[maxn];   bool judge(int cur) {     now.clear();     bool tmp[maxn];     for (int i = 1; i <= lt; i++) tmp[i] = true;     for (int i = 1; i <= cur; i++) tmp[a[i]] = false;     for (int i = 1; i <= lt; i++)       if (tmp[i]) now.push_back(t[i]);     int pos = 0;     for (int i = 0; i < now.size(); i++) {       if (now[i] == p[pos + 1]) pos++;       if (pos == lp) break;     }     if (pos == lp)       return true;     else       return false;   }   int main() {     int temp;     lt = 0;     temp = getchar();     while (temp !=   n ) {       lt++;       t[lt] = temp;       temp = getchar();     }     lp = 0;     temp = getchar();     while (temp !=   n ) {       lp++;       p[lp] = temp;       temp = getchar();     }     for (int i = 1; i <= lt; i++) scanf( %d , &a[i]);     l = 0;     r = lt;     while (l + 1 < r) {       int mid = (l + r) >> 1;       if (judge(mid))         l = mid;       else         r = mid;     }     printf( %d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int tot = 0;   int ch[5000001][2];   int s[5000001];   void insert(int x) {     int Root = 0;     for (int i = 30; i >= 0; i--) {       int tmp = (x >> i) & 1;       if (!ch[Root][tmp]) {         ch[Root][tmp] = ++tot;         s[tot] = 0;       }       Root = ch[Root][tmp];       ++s[Root];     }   }   void del(int x) {     int Root = 0;     for (int i = 30; i >= 0; i--) {       int tmp = (x >> i) & 1;       Root = ch[Root][tmp];       --s[Root];     }   }   int query(int x) {     int Root = 0, ans = 0;     for (int i = 30; i >= 0; i--) {       int tmp = (x >> i) & 1;       if (s[ch[Root][tmp ^ 1]])         ans += (1 << i), Root = ch[Root][tmp ^ 1];       else         Root = ch[Root][tmp];     }     return ans;   }   int q, x;   char str[101];   int main() {     scanf( %d , &q);     insert(0);     while (q--) {       scanf( %s , str);       scanf( %d , &x);       if (str[0] ==  + )         insert(x);       else if (str[0] ==  - )         del(x);       else         printf( %d n , query(x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sapxep(int n, int b[]) {     for (int i = 0; i < n; i++) {       for (int i = 0; i < n - 1; i++) {         if (b[i] < b[i + 1]) {           int t = b[i];           b[i] = b[i + 1];           b[i + 1] = t;         }       }     }   }   int main() {     int n;     cin >> n;     int a[n][4], b[n];     for (int i = 0; i < n; i++) {       b[i] = 0;       for (int j = 0; j < 4; j++) {         cin >> a[i][j];         b[i] += a[i][j];       }     }     int c = b[0];     sapxep(n, b);     for (int i = 0; i < n; i++) {       if (c == b[i]) {         cout << i + 1;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, sum;   long long arr[105];   long long val[105];   void icchhipadey() {     long long n;     cin >> n;     long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     long long f, x;     cin >> f >> x;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (arr[i] > f) {         long long xx = arr[i] - f;         xx = (xx + f + x - 1) / (f + x);         ans += xx;       }     }     cout << ans * x << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     icchhipadey();   }
#include <bits/stdc++.h>   using namespace std;   bool push(vector<int> &c, vector<int> &d, int f, int t, int x = -1) {     if (x == -1) x = d[f];     x = min(x, d[f]);     if (c[t] <= x) {       d[f] -= c[t];       c[t] = 0;       return true;     }     c[t] -= x;     d[f] -= x;     return false;   }   void solve() {     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     vector<int> c = a, d = b;     push(c, d, 0, 1);     int i = 1;     for (; i < n; i++) {       if (!push(c, d, i, i)) break;       push(c, d, i, (i + 1 == n ? 0 : i + 1));     }     if (i < n) {       cout <<  NO n ;       return;     }     int p = c[0];     c = a, d = b;     push(c, d, 0, 0, p);     push(c, d, 0, 1);     i = 1;     for (; i < n; i++) {       if (!push(c, d, i, i)) break;       push(c, d, i, (i + 1 == n ? 0 : i + 1));     }     if (c[0] > 0 || i < n) {       cout <<  NO n ;       return;     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cout << setprecision(12);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[300];   int main() {     cin >> n;     for (int i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     if (a[n - 1] != a[n])       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int T = 1e3 + 5;   int g[T][T];   void add(int a, int b) { g[a][b] = g[b][a] = 1; }   int last, K, a, b, i, j, N;   int main() {     cin >> K;     add(0, 2);     add(0, 3);     for (i = 2; i <= 30; i++) {       add(2 * i, 2 * i - 1);       add(2 * i, 2 * i - 2);       add(2 * i + 1, 2 * i - 1);       add(2 * i + 1, 2 * i - 2);     }     N = 2 * 30 + 1;     for (i = 30; i >= 0; i--)       if (K & (1 << (i - 1))) {         last = 2 * i;         for (j = i; j < 30; j++) {           N++;           add(N, last);           last = N;         }         add(last, 1);       }     cout << N + 1 << endl;     for (i = 0; i <= N; i++) {       for (j = 0; j <= N; j++)         if (g[i][j])           printf( %c ,  Y );         else           printf( %c ,  N );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   int main() {     long long t;     cin >> t;     for (long long ind = 0; ind < t; ++ind) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       a.clear();       a.resize(26, 0);       long long num = n / k, ans = 0;       for (long long i = 0; i < k; ++i) {         if (i > k - i - 1) break;         for (long long j = i; j < n; j += k) {           a[s[j] -  a ]++;         }         bool p = false;         if (i != k - i - 1) {           p = true;           for (long long j = k - i - 1; j < n; j += k) {             a[s[j] -  a ]++;           }         }         long long m = a[0];         for (long long j = 1; j < 26; ++j) {           if (a[j] > m) m = a[j];         }         if (p)           ans += 2 * num - m;         else           ans += num - m;         a.clear();         a.resize(26, 0);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MAXN = 1e5 + 100;   long long F[MAXN];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     F[0] = 1;     F[1] = 1;     for (long long i = 2; i < MAXN; i++) F[i] = (F[i - 1] + F[i - 2]) % MOD;     long long N, M;     cin >> N >> M;     cout << 2 * (F[N] + F[M] + MOD - 1) % MOD <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 112345;   long long t[4 * N];   long long lzs[4 * N], lzm[4 * N];   int a[4 * N], b[4 * N];   void build(int i, int l, int r) {     if (l == r) {       a[i] = b[i] = l;     } else {       int m = (l + r) / 2;       build(2 * i, l, m);       build(2 * i + 1, m + 1, r);       a[i] = l;       b[i] = r;     }   }   void push(int i, int l, int r) {     if (lzs[i]) {       t[i] += 1ll * lzs[i] * (r - l + 1);       if (l != r) {         lzs[2 * i] += lzs[i];         lzs[2 * i + 1] += lzs[i];       }       lzs[i] = 0;     }     if (lzm[i]) {       a[i] = b[i] = lzm[i];       if (l != r) {         lzm[2 * i] = lzm[i];         lzm[2 * i + 1] = lzm[i];       }       lzm[i] = 0;     }   }   long long query(int i, int l, int r, int ql, int qr) {     push(i, l, r);     if (ql <= l && r <= qr) return t[i];     if (qr < l || r < ql) return 0;     int m = (l + r) / 2;     return query(2 * i, l, m, ql, qr) + query(2 * i + 1, m + 1, r, ql, qr);   }   void update(int i, int l, int r, int ql, int qr, int x) {     push(i, l, r);     if (qr < l || r < ql) return;     if (ql <= l && r <= qr && a[i] == b[i]) {       lzs[i] += abs(x - a[i]);       lzm[i] = x;       push(i, l, r);     } else {       int m = (l + r) / 2;       update(2 * i, l, m, ql, qr, x);       update(2 * i + 1, m + 1, r, ql, qr, x);       t[i] = t[2 * i] + t[2 * i + 1];       a[i] = min(a[2 * i], a[2 * i + 1]);       b[i] = max(b[2 * i], b[2 * i + 1]);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     build(1, 1, n);     while (m--) {       int op;       scanf( %d , &op);       if (op == 1) {         int l, r, x;         scanf( %d%d%d , &l, &r, &x);         update(1, 1, n, l, r, x);       } else {         int l, r;         scanf( %d%d , &l, &r);         printf( %lld n , query(1, 1, n, l, r));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Q = 86401;   int n, M, T;   int R, res[20000];   vector<int> in[Q];   vector<int> out[Q];   int outTime[20000];   int main() {     scanf( %d%d%d , &n, &M, &T);     int a, b, c;     for (int i = 0; i < n; ++i) {       scanf( %d:%d:%d , &a, &b, &c);       a = a * 60 * 60 + b * 60 + c;       in[a].push_back(i);       out[a + T - 1].push_back(i);     }     set<pair<int, int> > q;     bool maxF = false;     for (int i = 0; i < Q; ++i) {       maxF |= q.size() == M;       for (int j = 0; j < in[i].size(); ++j) {         int u = in[i][j];         if (q.size() < M) {           res[u] = ++R;         } else {           int v = (*--q.end()).second;           q.erase(--q.end());           res[u] = res[v];         }         outTime[u] = i + T - 1;         q.insert(make_pair(i + T - 1, u));       }       for (int j = 0; j < out[i].size(); ++j) {         int u = out[i][j];         q.erase(make_pair(outTime[u], u));       }     }     if (!maxF)       puts( No solution );     else {       map<int, int> mp;       R = 0;       for (int i = 0; i < n; ++i) {         if (mp.find(res[i]) == mp.end()) {           mp[res[i]] = ++R;         }         res[i] = mp[res[i]];       }       printf( %d n , R);       for (int i = 0; i < n; ++i) printf( %d n , res[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long B = uniform_int_distribution<int>(333, 999)(rng);   const long long MOD1 = 1792209677, MOD2 = 1211874137;   template <class T>   pair<T, T> operator+(const pair<T, T>& l, const pair<T, T>& r) {     return {(l.first + r.first) % MOD1, (l.second + r.second) % MOD2};   }   template <class T>   pair<T, T> operator-(const pair<T, T>& l, const pair<T, T>& r) {     return {(l.first - r.first + MOD1) % MOD1,             (l.second - r.second + MOD2) % MOD2};   }   template <class T>   pair<T, T> operator*(const pair<T, T>& l, const T& r) {     return {l.first * r % MOD1, l.second * r % MOD2};   }   template <class T>   pair<T, T> operator*(const pair<T, T>& l, const pair<T, T>& r) {     return {l.first * r.first % MOD1, l.second * r.second % MOD2};   }   struct HashInterval {     vector<pair<long long, long long> > hs, pw;     HashInterval(string& str)         : hs(str.length() + 1, pair<long long, long long>(0, 0)), pw(hs) {       pw[0] = pair<long long, long long>(1, 1);       for (int i = 0; i < (int)str.length(); i++) {         hs[i + 1] = hs[i] * B + pair<long long, long long>(str[i], str[i]);         pw[i + 1] = pw[i] * B;       }     }     pair<long long, long long> hashInterval(int a, int b) {       pair<long long, long long> ans = hs[b] - hs[a] * pw[b - a];       return ans;     }   };   long long A[N];   vector<long long> V1, V2;   pair<long long, long long> hs1[N], hs2[N], pw[N];   vector<long long> ANS;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     long long m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     for (int i = 1; i <= n; i++) {       A[n + i] = A[i] + m;     }     for (int i = 2; i <= 2 * n; i++) {       V1.push_back(A[i] - A[i - 1]);     }     V2 = V1;     reverse(V2.begin(), V2.end());     pw[0] = make_pair(1, 1);     for (int i = 1; i <= 2 * n; i++) {       pw[i] = pw[i - 1] * B;     }     for (int i = 0; i < (int)V1.size(); i++) {       hs1[i + 1] = hs1[i] * B + make_pair(V1[i], V1[i]);       hs2[i + 1] = hs2[i] * B + make_pair(V2[i], V2[i]);     }     for (int i = 1; i <= n; i++) {       if (hs1[n] - hs1[0] * pw[n] == hs2[n - i + n] - hs2[n - i] * pw[n]) {         ANS.push_back((A[1] + A[i]) % m);       }     }     cout << ANS.size() <<   n ;     if (ANS.size()) {       sort(ANS.begin(), ANS.end());       for (auto it : ANS) {         cout << it <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     cin >> n;     vector<int> t(3);     for (int &i : t) {       cin >> i;     }     sort(t.begin(), t.end());     c = t[0];     b = t[1];     a = t[2];     int x, y, z;     int max = 0;     for (z = n / c; z >= 0; z--) {       for (y = (n - z * c) / b; y >= 0; y--) {         x = (n - z * c - y * b) / a;         if (x * a + y * b + z * c == n && x + y + z > max) {           max = x + y + z;         }       }     }     cout << max;     return 0;   }