malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2019, mod = 998244353;   int n, m, ans, f[N << 1][N], g[N << 1][N];   int qpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod, b >>= 1;     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &ans);     f[0][0] = 1;     for (int i = 1; i <= 2 * n; i++)       for (int j = 0; j <= min(i, n); j++) {         if (!j)           f[i][j] = f[i - 1][j + 1], g[i][j] = g[i - 1][j + 1];         else           f[i][j] = (f[i - 1][j - 1] + 1ll * (j + 1) * f[i - 1][j + 1]) % mod,           g[i][j] = (g[i - 1][j - 1] + 1ll * (j + 1) * g[i - 1][j + 1]) % mod;         if (j >= m) g[i][j] = (f[i][j] + g[i][j]) % mod;       }     ans = 1ll * ans * qpow(1ll * f[2 * n][0] * (2 * n + 1) % mod, mod - 2) % mod *           g[2 * n][0] % mod;     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4040;   int dp[N][N];   int n, m;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       int i, j;       memset(dp, 63, sizeof(dp));       memset(dp[0], 0, sizeof(dp[0]));       int ret = 0;       for (i = 1; i <= n; i++) {         int x, y;         scanf( %d%d , &x, &y);         for (j = 0; j <= m; j++) {           int w = dp[i - 1][j];           dp[i][j] = min(dp[i][j], max(w, x - 1) + y);           dp[i][j + 1] = min(dp[i][j + 1], w);           ret = max(ret, x - 1 - w);         }       }       for (i = 0; i <= m; i++) ret = max(ret, 86400 - dp[n][i]);       printf( %d n , ret);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long NLINF = 0xf7f7f7f7f7f7f7f7;   const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;   const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;   const int N = 2e5 + 10;   int n, freq[30], mark[30];   vector<char> odd, ch;   char s[N], r[N];   int main() {     scanf( %s , &s), n = strlen(s);     for (int i = 0; i < n; i++) {       freq[s[i] -  a ]++;     }     for (int i = 0; i < n; i++) {       if (freq[s[i] -  a ] % 2 == 0) ch.push_back(s[i]);       if (freq[s[i] -  a ] % 2 && !mark[s[i] -  a ])         odd.push_back(s[i]), mark[s[i] -  a ] = 1;     }     sort(odd.begin(), odd.end());     for (int i = 0; i < odd.size(); i++) {       if (odd.size() % 2 && i == odd.size() / 2)         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       else if (i >= odd.size() / 2) {         freq[odd[i] -  a ]--;         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       } else {         freq[odd[i] -  a ]++;         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       }     }     sort(ch.begin(), ch.end());     assert(ch.size() == n);     bool par = 1;     for (int i = 0, lo = 0, hi = n - 1; i < n; i++) {       if (i % 2 == par)         r[hi--] = ch[i];       else if (ch[i] == ch[i + 1])         r[lo++] = ch[i];       else         par = !par, r[n / 2] = ch[i];     }     printf( %s n , r);   }
#include <bits/stdc++.h>   const int N = 1e5 + 1;   const int INF = 1e9 + 9;   int n;   int d[N];   std::vector<int> a[N];   int dfs(int v) {     for (int u : a[v]) {       d[v] += dfs(u);     }     if (d[v] == 0) return d[v] = 1;     return d[v];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x;       scanf( %d , &x);       x--;       a[x].push_back(i);     }     dfs(0);     std::sort(d, d + n);     for (int i = 0; i < n; i++) printf( %d  , d[i]);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, n1, m1;   double dp[1002][1002], ans, c[1003][1003];   int main() {     scanf( %d %d , &n, &m);     scanf( %d%d , &n1, &m1);     if (n == n1)       ans = 0.000000;     else if (m == 1)       dp[n1][m1] = 2 * (n - n1);     else {       for (int i = n - 1; i >= n1; i--) {         for (int j = 2; j < m; j++) {           c[j][j] = 0.75, c[j][j - 1] = -0.25;           c[j][j + 1] = -0.25;           c[j][1002] = 1.0 + 0.25 * dp[i + 1][j];         }         c[1][1] = 2.0 / 3.0;         c[1][2] = -1.0 / 3.0;         c[1][1002] = 1.0 + 1.0 / 3 * dp[i + 1][1];         c[m][m] = 2.0 / 3.0;         c[m][m - 1] = -1.0 / 3.0;         c[m][1002] = 1.0 + 1.0 / 3 * dp[i + 1][m];         c[1][2] /= c[1][1];         c[1][1002] /= c[1][1];         c[1][1] = 1;         for (int j = 2; j <= m; j++) {           c[j][j] -= c[j][j - 1] * c[j - 1][j];           c[j][1002] -= c[j][j - 1] * c[j - 1][1002];           c[j][j + 1] /= c[j][j];           c[j][1002] /= c[j][j];           c[j][j] = 1;         }         for (int j = m; j >= 1; j--)           dp[i][j] = (c[j][1002] - dp[i][j + 1] * c[j][j + 1]);       }     }     printf( %.12lf n , dp[n1][m1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (x > y) swap(x, y);     if (x <= 0) return y;     if (y % x == 0) return x;     return gcd(y % x, x);   }   int main() {     vector<long long> a;     long long b[400000];     bool c[400000];     for (long long i = 0; i < (long long)(400000); i++) {       b[i] = 0;       c[i] = false;     }     int n, k;     long long g;     long long x, y, z, xx, yy, zz;     long long s, ans;     bool v = true;     ans = 0;     scanf( %I64d %I64d %I64d , &z, &x, &y);     g = gcd(x, y);     a.push_back(0);     c[0] = true;     xx = 0;     while (true) {       if (xx >= y)         xx -= y;       else         xx += x;       if (c[xx])         break;       else         c[xx] = true;       a.push_back(xx);     }     xx = 0;     yy = 0;     zz = 0;     while (true) {       if (xx < a[yy]) {         b[xx] = yy;         zz = max(zz, yy);         xx++;       } else         yy++;       if (yy >= a.size()) break;     }     ans = 0;     if (z < (x + y - g)) {       for (long long i = 0; i < (long long)(z + 1); i++) ans += b[i];       printf( %I64d n , ans);       return 0;     }     for (long long i = 0; i < (long long)(x + y - g); i++) {       ans += b[i];     }     xx = (x + y) / g;     yy = z / g;     zz = (xx + yy) * (yy - xx + 1) / 2;     zz *= g;     ans += zz;     zz = (z % g) + 1;     zz *= ((z / g) + 1);     ans += zz;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   struct outgoing {     long long wt = INF, to = -1;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     vector<long long> stations;     vector<pair<long long, long long>> connections;     long long n, i, j, k, t, temp;     cin >> n;     vector<outgoing> edge(n + 1);     pair<long long, long long> vertices[n + 1];     long long cost[n + 1];     long long mult[n + 1];     for (i = 1; i <= n; i++) {       cin >> vertices[i].first >> vertices[i].second;     }     for (i = 1; i <= n; i++) {       cin >> cost[i];       edge[i].wt = cost[i];       edge[i].to = i;     }     for (i = 1; i <= n; i++) {       cin >> mult[i];     }     long long total = 0;     vector<bool> selected(n + 1, false);     for (i = 1; i <= n; i++) {       long long v = -1;       for (j = 1; j <= n; j++) {         if (!selected[j] && (v == -1 || edge[j].wt < edge[v].wt)) {           v = j;         }       }       selected[v] = true;       long long x_now = vertices[v].first;       long long y_now = vertices[v].second;       if (edge[v].to == v) {         stations.push_back(v);       } else {         connections.push_back({v, edge[v].to});       }       total += edge[v].wt;       for (j = 1; j <= n; j++) {         long long x_diff = fabs(vertices[j].first - vertices[v].first);         long long y_diff = fabs(vertices[j].second - vertices[v].second);         if ((mult[v] + mult[j]) * (x_diff + y_diff) < edge[j].wt) {           edge[j].wt = (mult[v] + mult[j]) * (x_diff + y_diff);           edge[j].to = v;         }       }     }     cout << total << endl;     cout << stations.size() << endl;     for (auto x : stations) {       cout << x <<    ;     }     cout <<   n ;     cout << connections.size() << endl;     for (auto x : connections) {       cout << x.first <<     << x.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<char> v;   vector<char> vv;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     char s[3][3], ss[3][3];     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) cin >> s[i][j];     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) cin >> ss[i][j];     if (s[0][0] !=  X ) v.push_back(s[0][0]);     if (s[0][1] !=  X ) v.push_back(s[0][1]);     if (s[1][1] !=  X ) v.push_back(s[1][1]);     if (s[1][0] !=  X ) v.push_back(s[1][0]);     if (v[0] == ss[0][0]) {       if (ss[0][0] !=  X ) vv.push_back(ss[0][0]);       if (ss[0][1] !=  X ) vv.push_back(ss[0][1]);       if (ss[1][1] !=  X ) vv.push_back(ss[1][1]);       if (ss[1][0] !=  X ) vv.push_back(ss[1][0]);     } else if (ss[0][1] == v[0]) {       if (ss[0][1] !=  X ) vv.push_back(ss[0][1]);       if (ss[1][1] !=  X ) vv.push_back(ss[1][1]);       if (ss[1][0] !=  X ) vv.push_back(ss[1][0]);       if (ss[0][0] !=  X ) vv.push_back(ss[0][0]);     } else if (v[0] == ss[1][1]) {       vv.push_back(ss[1][1]);       if (ss[1][0] !=  X ) vv.push_back(ss[1][0]);       if (ss[0][0] !=  X ) vv.push_back(ss[0][0]);       if (ss[0][1] !=  X ) vv.push_back(ss[0][1]);     } else if (v[0] == ss[1][0]) {       if (ss[1][0] !=  X ) vv.push_back(ss[1][0]);       if (ss[0][0] !=  X ) vv.push_back(ss[0][0]);       if (ss[0][1] !=  X ) vv.push_back(ss[0][1]);       if (ss[1][1] !=  X ) vv.push_back(ss[1][1]);     }     for (int i = 0; i < 3; i++)       if (v[i] != vv[i]) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n / 2; i++) {       cin >> a[i];     }     sort(a, a + n / 2);     int bb = 0, cc = 0;     for (int i = 0; i < n / 2; i++) {       bb += abs(a[i] - (i * 2 + 1));       cc += abs(a[i] - (i * 2 + 2));     }     cout << min(bb, cc) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10;   const long long mod = 1e9 + 7;   const long long INF = 1e18 + 10;   int main() {     long long n, m, i;     string s;     cin >> n;     while (n--) {       cin >> m >> s;       if (s.size() < 11)         cout <<  NO n ;       else {         for (i = 0; i < s.size(); ++i) {           if (s[i] ==  8 ) break;         }         if (i == s.size())           cout <<  NO n ;         else {           if (s.size() - i >= 11)             cout <<  YES n ;           else             cout <<  NO n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 1000000007, INF = 1e9 + 7;   const int block = 316;   int n, k, type[N], a[N], m, cnt[N * 3], l[N][5];   long long ans, res[N], p[N][5];   set<long long> s;   map<long long, int> conv;   struct query {     int l, r, id, num;     query(){};     query(int a, int b, int c) : l(a), r(b), id(a / block), num(c){};   } q[N];   bool cmp(query q1, query q2) {     if (q1.id != q2.id) return q1.id < q2.id;     return q1.r < q2.r;   }   void add(int v, int cond) {     ans += cnt[l[v][cond]];     cnt[l[v][1]]++;   }   void remove(int v, int cond) {     cnt[l[v][1]]--;     ans -= cnt[l[v][cond]];   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> type[i];     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++) {       if (type[i] == 2) a[i] *= -1;       p[i][1] = p[i - 1][1] + a[i];       p[i][2] = p[i][1] - k;       p[i][3] = p[i][1] + k;       s.insert(p[i][1]);       s.insert(p[i][2]);       s.insert(p[i][3]);     }     int cnt = 0;     for (long long e : s) {       conv[e] = ++cnt;     }     for (int i = 0; i <= n; i++) {       l[i][1] = conv[p[i][1]];       l[i][2] = conv[p[i][2]];       l[i][3] = conv[p[i][3]];     }     cin >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       l--;       q[i] = query(l, r, i);     }     sort(q + 1, q + m + 1, &cmp);     int l = 0, r = -1;     for (int i = 1; i <= m; i++) {       int L = q[i].l, R = q[i].r;       while (r < R) add(++r, 2);       while (l < L) remove(l++, 3);       while (R < r) remove(r--, 2);       while (L < l) add(--l, 3);       res[q[i].num] = ans;     }     for (int i = 1; i <= m; i++) {       cout << res[i] << endl;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   const int MAXQ = 3e5 + 5;   const int inf = 0x3f3f3f3f;   struct Query {     int id, l, r;     Query(void) {}     Query(int _id, int _l, int _r) : id(_id), l(_l), r(_r) {}   };   long long res[MAXQ];   struct Solver {     vector<int> a, b;     vector<Query> qs;     void solve(void) {       int n = (int)a.size();       a.push_back(-inf);       b.push_back(-inf);       vector<vector<Query> > f(n), g(n);       for (Query x : qs) x.r = min(x.r, n - 1), f[x.l].push_back(x);       vector<int> sta(1, n), val(1, -inf);       for (int i = n - 1; i >= 0; --i) {         int pos = lower_bound(val.begin(), val.end(), b[i]) - val.begin();         pos = sta[pos - 1];         for (Query x : f[i]) {           int id = x.id, l = x.l, r = x.r;           if (pos > r) {             res[id] = (long long)(r - l + 1) * b[i];             continue;           }           res[id] = (long long)(pos - l) * b[i];           x.l = pos;           g[pos].push_back(x);         }         while (val.back() >= a[i]) val.pop_back(), sta.pop_back();         sta.push_back(i);         val.push_back(a[i]);       }       sta = vector<int>(1, n);       val = vector<int>(1, -inf);       vector<long long> sum(1, 0);       for (int i = n - 1; i >= 0; --i) {         while (val.back() >= a[i]) {           val.pop_back();           sta.pop_back();           sum.pop_back();         }         sum.push_back((long long)a[i] * (sta.back() - i) + sum.back());         sta.push_back(i);         val.push_back(a[i]);         for (Query x : g[i]) {           int id = x.id, r = x.r;           int pos = lower_bound(sta.begin(), sta.end(), r, greater<int>()) -                     sta.begin();           res[id] += sum.back() - sum[pos];           res[id] += (long long)(x.r - sta[pos] + 1) * val[pos];         }       }     }   } slv[MAXN];   int a[MAXN], f[MAXN];   int main(void) {     int n, Q, d;     scanf( %d%d%d , &n, &Q, &d);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     deque<int> q;     for (int i = 0; i < n; ++i) {       while (q.size() && q.front() <= i - d) q.pop_front();       while (q.size() && a[q.back()] >= a[i]) q.pop_back();       q.push_back(i);       f[i] = a[q.front()];     }     for (int i = 0; i < n; ++i) {       int t = i % d;       slv[t].a.push_back(f[i]);       slv[t].b.push_back(a[i]);     }     for (int i = 1; i <= Q; ++i) {       int l, r;       scanf( %d%d , &l, &r);       --l;       --r;       int t = l % d;       if (r % d < l % d) r -= d;       l /= d;       r /= d;       slv[t].qs.emplace_back(i, l, r);     }     for (int i = 0; i < d; ++i) slv[i].solve();     for (int i = 1; i <= Q; ++i) printf( %lld n , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[300010], B[300010];   int n, m;   struct node {     int negpos, negpos_pref, negpos_suf, neg, neg_pref, neg_suf, pos, pos_pref,         pos_suf, len;     node() {       negpos = negpos_pref = negpos_suf = neg = neg_pref = neg_suf = pos =           pos_pref = pos_suf = 0;     }   };   node ST[3000010];   void merge(node a, node b, node &x) {     x.negpos = x.negpos_pref = x.negpos_suf = -0x3f3f3f3f;     x.neg = x.neg_pref = x.neg_suf = -0x3f3f3f3f;     x.pos = x.pos_pref = x.pos_suf = -0x3f3f3f3f;     x.negpos = max(a.negpos, max(b.negpos, a.neg_suf + b.pos_pref));     x.negpos =         max(x.negpos, max(a.negpos_suf + b.pos_pref, a.neg_suf + b.negpos_pref));     x.negpos_pref = a.negpos_pref;     if (a.neg == a.len) x.negpos_pref = max(x.negpos_pref, a.neg + b.negpos_pref);     if (a.negpos == a.len)       x.negpos_pref = max(x.negpos_pref, a.negpos + b.pos_pref);     x.negpos_suf = b.negpos_suf;     if (b.pos == b.len) x.negpos_suf = max(x.negpos_suf, a.negpos_suf + b.pos);     if (b.negpos == b.len) x.negpos_suf = max(x.negpos_suf, a.neg_suf + b.negpos);     x.pos = a.pos + b.pos;     x.neg = a.neg + b.neg;     x.pos_pref = a.pos_pref;     if (a.pos_pref == a.len) x.pos_pref = a.len + b.pos_pref;     x.pos_suf = b.pos_suf;     if (b.pos_suf == b.len) x.pos_suf = a.pos_suf + b.len;     x.neg_pref = a.neg_pref;     if (a.neg_pref == a.len) x.neg_pref = a.len + b.neg_pref;     x.neg_suf = b.neg_suf;     if (b.neg_suf == b.len) x.neg_suf = a.neg_suf + b.len;   }   void init_node(node &x, long long v) {     x.negpos = x.negpos_pref = x.negpos_suf = 0;     x.pos = x.pos_pref = x.pos_suf = 0;     x.neg = x.neg_pref = x.neg_suf = 0;     if (v < 0) {       x.neg = x.neg_pref = x.neg_suf = 1;     } else if (v > 0) {       x.pos = x.pos_pref = x.pos_suf = 1;     }     if (v) {       x.negpos = x.negpos_pref = x.negpos_suf = 1;     }   }   void init(int N, int li, int ls) {     ST[N].len = (ls - li + 1);     if (li == ls) {       init_node(ST[N], B[li]);     } else {       int mid = (li + ls) / 2;       init(2 * N, li, mid);       init(2 * N + 1, mid + 1, ls);       merge(ST[2 * N], ST[2 * N + 1], ST[N]);     }   }   void upd(int N, int li, int ls, int p, long long v) {     if (p > ls || p < li) return;     if (li == p && ls == p) {       B[p] += v;       init_node(ST[N], B[p]);       return;     }     int mid = (li + ls) / 2;     upd(2 * N, li, mid, p, v);     upd(2 * N + 1, mid + 1, ls, p, v);     merge(ST[2 * N], ST[2 * N + 1], ST[N]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &A[i]);     scanf( %d , &m);     for (int i = 0; i < n - 1; i++) B[i] = A[i] - A[i + 1];     n--;     if (n == 0) {       while (m--) printf( 1 n );       return 0;     }     init(1, 0, n - 1);     for (int i = 0; i < m; i++) {       int l, r;       long long v;       scanf( %d %d %lld , &l, &r, &v);       l -= 2;       r--;       if (l >= 0 && l < n) upd(1, 0, n - 1, l, -v);       if (r >= 0 && r < n) upd(1, 0, n - 1, r, v);       printf( %d n , ST[1].negpos + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[110], b[110], cnt, n;   map<int, int> mp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int num;       scanf( %d , &num);       if (!mp[num]) {         mp[num]++;         b[cnt++] = num;       }     }     sort(b, b + cnt);     if (cnt == 1)       printf( 0 );     else if (cnt == 2) {       if (abs(b[1] - b[0]) % 2)         printf( %d , abs(b[1] - b[0]));       else         printf( %d , abs(b[1] - b[0]) / 2);     } else if (cnt == 3 && ((b[1] - b[0]) == (b[2] - b[1])))       printf( %d , b[1] - b[0]);     else       printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int ans = 15;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) ans &= 8;       if (s[i] ==  1  || s[i] ==  2  || s[i] ==  3 ) ans &= 7;       if (s[i] ==  1  || s[i] ==  4  || s[i] ==  7 ) ans &= 13;       if (s[i] ==  3  || s[i] ==  6  || s[i] ==  9 ) ans &= 14;       if (s[i] ==  7  || s[i] ==  9 ) ans &= 11;     }     if (ans)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<string> normal;   set<string> grumpy;   void build_normal() {     normal.insert( great! );     normal.insert( don t think so );     normal.insert( don t touch me );     normal.insert( not bad );     normal.insert( cool );   }   void build_grumpy() {     grumpy.insert( no way );     grumpy.insert( don t even );     grumpy.insert( are you serious? );     grumpy.insert( go die in a hole );     grumpy.insert( worse );     grumpy.insert( terrible );   }   int main() {     build_normal();     build_grumpy();     for (int i = 0; i < 10; i++) {       cout << i << endl;       string s;       getline(cin, s);       if (normal.count(s)) {         cout <<  normal  << endl;         return 0;       } else if (grumpy.count(s)) {         cout <<  grumpy  << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 100010;   int dp[550][550], A[550], B[550], path[550][550], n, m;   bool print(int x) {     if (!x) return false;     if (print(path[n][x]))       printf(  %d , B[x]);     else       printf( %d , B[x]);     return true;   }   int main() {     int i, j, tp, ans, pos;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) scanf( %d , &A[i]);       scanf( %d , &m);       for (i = 1; i <= m; i++) scanf( %d , &B[i]);       memset(dp, 0, sizeof dp);       for (i = 1; i <= n; i++) {         tp = pos = 0;         for (j = 1; j <= m; j++) {           dp[i][j] = dp[i - 1][j];           path[i][j] = path[i - 1][j];           if (A[i] == B[j] && tp + 1 > dp[i][j])             dp[i][j] = tp + 1, path[i][j] = pos;           if (B[j] < A[i] && dp[i - 1][j] > tp) tp = dp[i - 1][j], pos = j;         }       }       ans = 1;       for (i = 1; i <= m; i++)         if (dp[n][i] > dp[n][ans]) ans = i;       printf( %d n , dp[n][ans]);       if (dp[n][ans]) print(ans);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long &i : a) cin >> i;     unordered_map<long long, bool> m;     for (int i = 0; i < n; i++) {       long long sum = a[i];       for (int j = i + 1; j < n; j++) {         sum += a[j];         if (sum > n) break;         m[sum] = true;       }     }     long long count = 0;     for (long long i : a) {       count += m[i];     }     cout << count <<   n ;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, maxi = 0;     cin >> n;     std::stack<int> stk;     for (int i = 0; i < n; ++i) {       cin >> a;       a %= 2;       maxi = max(maxi, a);       if (!stk.empty()) {         if (stk.top() == a)           stk.pop();         else           stk.push(a);       } else         stk.push(a);     }     if (stk.size() < 2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a, b;     long long c, nr = 0;     for (a = 1; a <= n; ++a) {       for (b = a; b <= n; ++b) {         c = sqrt(a * a + b * b);         if (c * c == a * a + b * b && c >= b && c <= n) ++nr;       }     }     cout << nr;     return 0;   }