malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXK = 3000;   struct Update {     int cost;     long long profit;   };   struct CommutativeUndoableDS {     vector<array<long long, MAXK + 1> > dp;     CommutativeUndoableDS() {       dp.emplace_back();       fill(dp.back().begin(), dp.back().end(), 0);     }     void addUpdate(Update u) {       int sz = dp.size();       dp.push_back(dp.back());       for (int i = MAXK; i >= u.cost; i--) {         dp[sz][i] = max(dp[sz][i], dp[sz - 1][i - u.cost] + u.profit);       }     }     void undoLastUpdate() {       dp.pop_back();       assert(!dp.empty());     }     long long operator[](int i) { return dp.back()[i]; }   };   struct QueueUndoDS {     vector<pair<Update, int> > qyu;     CommutativeUndoableDS ds;     int rem_a;     QueueUndoDS() { rem_a = 0; }     void pushBack(pair<Update, int> u) {       ds.addUpdate(u.first);       qyu.emplace_back(u);     }     void pushBack(Update u) { pushBack(pair<Update, int>(u, 1)); }     void popFront() {       assert(!qyu.empty());       if (rem_a == 0) {         rem_a = qyu.size();         for (int i = 0; i < rem_a; i++) ds.undoLastUpdate();         reverse(qyu.begin(), qyu.end());         for (pair<Update, int> &u : qyu) {           u.second = 0;           ds.addUpdate(u.first);         }       }       vector<pair<Update, int> > popped[2];       while (qyu.back().second == 1) {         popped[1].push_back(qyu.back());         qyu.pop_back();         ds.undoLastUpdate();       }       int sz = rem_a & (-rem_a);       for (int i = 0; i < sz; i++) {         assert(qyu.back().second == 0);         popped[0].push_back(qyu.back());         qyu.pop_back();         ds.undoLastUpdate();       }       for (int z : {1, 0}) {         reverse(popped[z].begin(), popped[z].end());         for (pair<Update, int> &u : popped[z]) pushBack(u);       }       assert(qyu.back().second == 0);       ds.undoLastUpdate();       qyu.pop_back();       rem_a--;     }   };   vector<long long> a[MAXK];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     QueueUndoDS qds;     for (int i = 1; i <= n; i++) {       int sz;       cin >> sz;       a[i].resize(sz + 1);       for (int j = 1; j <= sz; j++) {         cin >> a[i][j];         a[i][j] += a[i][j - 1];       }       if (sz > k) a[i].resize(k + 1);       qds.pushBack({(int)a[i].size() - 1, a[i].back()});     }     long long ans = -1;     for (int i = 1; i <= n; i++) {       qds.popFront();       for (int j = 0; j < a[i].size(); j++) {         ans = max(ans, a[i][j] + qds.ds[k - j]);       }       qds.pushBack({(int)a[i].size() - 1, a[i].back()});     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   constexpr int maxn = 1e6 + 7;   struct DSU {     vector<int> f;     void init(int n) {       f.resize(n + 1);       iota(f.begin(), f.end(), 0);     }     int seek(int x) { return x == f[x] ? x : (f[x] = seek(f[x])); }     bool same(int u, int v) { return seek(u) == seek(v); }     void Merge(int u, int v) { f[seek(u)] = seek(v); }   } dsu;   vector<int> prime[maxn];   set<pair<int, int> > onepath;   void solve() {     dsu.init(maxn);     int n, m, mx = 0;     scanf( %d %d , &n, &m);     vector<int> vec(n + 1, 0);     for (int i = 1; i <= n; ++i) {       scanf( %d , &vec[i]);       mx = max(mx, vec[i]);     }     for (int i = 2; i <= mx + 1; ++i) {       if (!prime[i].size()) {         for (int j = i; j <= mx + 1; j += i) {           prime[j].push_back(i);         }       }     }     for (int i = 1; i <= n; ++i) {       for (auto fac : prime[vec[i]]) {         dsu.Merge(vec[i], fac);       }     }     for (int i = 1; i <= n; ++i) {       vector<int> has = prime[vec[i] + 1];       has.push_back(vec[i]);       for (int i = 0; i < has.size(); ++i) {         for (int j = i + 1; j < has.size(); ++j) {           int u = has[i], v = has[j];           u = dsu.seek(u), v = dsu.seek(v);           if (!dsu.same(u, v)) {             if (u > v) swap(u, v);             onepath.insert({u, v});           }         }       }     }     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       u = vec[u], v = vec[v];       u = dsu.seek(u), v = dsu.seek(v);       if (u > v) swap(u, v);       if (u == v)         puts( 0 );       else if (onepath.count({u, v}))         puts( 1 );       else         puts( 2 );     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int maxx = -1;     set<int> s;     map<int, int> m;     vector<int> l(n);     for (int i = 0; i < n; i++) {       cin >> l[i];       m[l[i]]++;       if (m[l[i]] > maxx) maxx = m[l[i]];       s.insert(l[i]);     }     cout << maxx <<     << s.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     long long int n, m, k;     vector<long long int> a, b;     while (t--) {       cin >> n >> m;       cout << n <<     << n * 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int n, m;   char s[MAXN];   int g[22][22];   int dp[1 << 21];   int sol(int msk) {     if (1 << m == msk + 1) return 0;     if (dp[msk] != -1) return dp[msk];     int tk[20] = {0};     int ntk[20] = {0};     int tksz = 0;     int ntksz = 0;     for (int i = 0; i < m; i++) {       if (msk & (1 << i))         tk[tksz++] = i;       else         ntk[ntksz++] = i;     }     int all = 0;     int save = 0;     int best = 10000000;     for (int i = 0; i < ntksz; i++) {       save = 0;       int x = ntk[i];       for (int j = 0; j < tksz; j++) {         int y = tk[j];         save += g[x][y] + g[y][x];       }       best = min(best, -save + sol(msk | (1 << ntk[i])));       all += save;     }     return dp[msk] = best + all;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d %d , &n, &m);     scanf( %s , s);     for (int i = 1; i < n; i++) {       g[s[i - 1] -  a ][s[i] -  a ]++;     }     for (int i = 0; i < m; i++) g[i][i] = 0;     int ans = sol(0);     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) ans += g[i][j];     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct Student {     int number;     int cost;     int com;   };   bool comp1(Student a, Student b) {     if (a.cost < b.cost) return true;     return false;   }   bool comp2(Student a, Student b) {     if (a.number < b.number) return true;     return false;   }   int main() {     long n, t, k, res, q;     cin >> n;     Student* A = new Student[n];     int* K = new int[n];     for (int i = 0; i < n; i++) {       A[i].number = i;       A[i].com = 0;       cin >> A[i].cost;     }     sort(A, A + n, comp1);     int* D = new int[n];     int* C = new int[n];     D[2] = -1;     C[2] = A[2].cost - A[0].cost;     K[2] = 1;     for (int i = 3; i < n; i++) {       D[i] = -1;       C[i] = A[i].cost - A[0].cost;       K[i] = 1;       if (i >= 5) {         if (i - 3 >= 2 && (C[i - 3] + A[i].cost - A[i - 2].cost) < C[i]) {           C[i] = C[i - 3] + A[i].cost - A[i - 2].cost;           D[i] = i - 3;           K[i] = K[i - 3] + 1;         }         if (i - 4 >= 2 && (C[i - 4] + A[i].cost - A[i - 3].cost) < C[i]) {           C[i] = C[i - 4] + A[i].cost - A[i - 3].cost;           D[i] = i - 4;           K[i] = K[i - 4] + 1;         }         if (i - 5 >= 2 && (C[i - 5] + A[i].cost - A[i - 4].cost) < C[i]) {           C[i] = C[i - 5] + A[i].cost - A[i - 4].cost;           D[i] = i - 5;           K[i] = K[i - 5] + 1;         }       }     }     q = n - 1;     while (q != -1) {       A[q].com = K[q];       t = q - 1;       while (t != D[q]) {         A[t].com = K[q];         t--;       }       q = D[q];     }     res = C[n - 1];     cout << res <<     << K[n - 1] << endl;     sort(A, A + n, comp2);     for (int i = 0; i < n; i++) cout << A[i].com <<    ;     return 0;   }
#include <bits/stdc++.h>   int a[2005][2005], b[100005], c[8][10];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a < b ? a : b; }   int main() {     int n, m, k, s;     while (scanf( %d%d%d%d , &n, &m, &k, &s) != EOF) {       for (int i = 1; i <= 9; i++) {         c[0][i] = -1 << 15;         c[1][i] = 1 << 15;         c[2][i] = -1 << 15;         c[3][i] = 1 << 15;         c[4][i] = -1 << 15;         c[5][i] = 1 << 15;         c[6][i] = -1 << 15;         c[7][i] = 1 << 15;       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &a[i][j]);           c[0][a[i][j]] = max(c[0][a[i][j]], i + j);           c[1][a[i][j]] = min(c[1][a[i][j]], i + j);           c[2][a[i][j]] = max(c[2][a[i][j]], i - j);           c[3][a[i][j]] = min(c[3][a[i][j]], i - j);         }       }       for (int i = 0; i < s; i++) {         scanf( %d , &b[i]);       }       int Max = n + m - 2;       int ans = 0;       for (int i = 0; i < s - 1; i++) {         ans = max(ans, c[0][b[i]] - c[1][b[i + 1]]);         ans = max(ans, -c[1][b[i]] + c[0][b[i + 1]]);         ans = max(ans, c[2][b[i]] - c[3][b[i + 1]]);         ans = max(ans, -c[3][b[i]] + c[2][b[i + 1]]);         if (ans >= Max) {           break;         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   struct x {     int a, id, gp;     bool operator<(const x& xx) const { return a < xx.a; }   } s[100005];   bool cmp(x p, x q) { return p.id < q.id; }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i].a);       s[i].id = i;       s[i].gp = 1;     }     if (n == 2) {       printf( 0 n1 1 n );       return 0;     }     sort(s, s + n);     int a1 = s[n - 1].a + s[n - 2].a - s[0].a - s[1].a;     int a2 = max(s[n - 1].a + s[n - 2].a, s[n - 1].a + s[0].a + m) -              min(s[0].a + s[1].a + m, s[1].a + s[2].a);     if (a1 > a2) {       s[0].gp = 2;       sort(s, s + n, cmp);       printf( %d n , a2);       for (int i = 0; i < n; i++) printf( %d  , s[i].gp);     } else {       printf( %d n , a1);       for (int i = 0; i < n; i++) printf( 1  );     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000005;   int sp[maxN];   void seive() {     for (int i = 2; i <= 1000000; ++i) {       if (sp[i] != 0) continue;       for (int j = i; j <= 1000000; j += i) {         if (sp[j] == 0) sp[j] = i;       }     }   }   int nxtpow(int x) {     int p = 1;     while (p < x) p <<= 1;     return p;   }   int main() {     seive();     int n;     scanf( %d , &n);     int pow = 0;     int x = n;     int val = 1;     vector<int> pows;     while (x > 1) {       int p = sp[x];       int cnt = 1;       while (x > 1 && sp[x / p] == p) {         x /= p;         ++cnt;       }       x /= p;       pow = max(pow, nxtpow(cnt));       val *= p;       pows.push_back(cnt);     }     int ans = 0;     for (int x : pows) {       if (x != pow) {         ++ans;         break;       }     }     while (pow > 1) {       pow >>= 1;       ++ans;     }     printf( %d %d n , val, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     map<string, long long> m;     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x;       string y;       cin >> x >> y;       sort(y.begin(), y.end());       if (m[y] == 0)         m[y] = x;       else         m[y] = min(m[y], x);     }     long long ans = INT_MAX;     for (auto it = m.begin(); it != m.end(); it++) {       for (auto i = m.begin(); i != m.end(); i++) {         if (i == it) continue;         string s1 = it->first;         string s2 = i->first;         set<char> s;         for (long long p = 0; p < s1.size(); p++) s.insert(s1[p]);         for (long long q = 0; q < s2.size(); q++) s.insert(s2[q]);         if (s.size() == 3) ans = min(ans, m[s1] + m[s2]);       }     }     if (m[ ABC ] > 0) ans = min(ans, m[ ABC ]);     if (m[ A ] > 0 && m[ B ] > 0 && m[ C ] > 0)       ans = min(ans, m[ A ] + m[ B ] + m[ C ]);     if (ans != INT_MAX)       cout << ans << endl;     else       cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     int a[n + 1], b[n + 1], i;     a[0] = -1;     b[0] = -1;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       cin >> b[i];     }     if (a[1] == 0) {       cout <<  NO ;       return 0;     } else {       if (a[s] == 1) {         cout <<  YES ;         return 0;       } else {         if (b[s] == 0) {           cout <<  NO ;           return 0;         } else {           for (i = s; i <= n; i++) {             if (a[i] == 1 && b[i] == 1) {               cout <<  YES ;               return 0;             }           }         }       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ans = 0, i, j, dp[N], half, n, a[N];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     for (i = n - 1; i >= 0; --i) {       dp[a[i]] = 1;       for (j = 2 * a[i]; j < N; j += a[i]) {         dp[a[i]] = max(dp[a[i]], dp[j] + 1);       }       ans = max(ans, dp[a[i]]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using vc = vector<T>;   template <class T>   using vvc = vc<vc<T>>;   template <class T>   void mkuni(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   long long rand_int(long long l, long long r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<long long>(l, r)(gen);   }   template <class T>   void print(T x, int suc = 1) {     cout << x;     if (suc == 1)       cout <<   n ;     else       cout <<    ;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = 0; i < v.size(); i++)       print(v[i], i == (int)(v.size()) - 1 ? suc : 2);   }   const int INF = 0x3f3f3f;   const int maxn = 5e3 + 7;   const int mod = 998244353;   const int N = 1e7 + 7;   int n;   int dp[maxn][maxn];   int pre[maxn];   int sum[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     for (int i = 0; i < n; ++i) {       pre[i + 1] = upper_bound(a.begin(), a.end(), (a[i]) / 2) - a.begin();     }     dp[0][n + 1] = 1;     for (int i = 0; i < n; ++i) {       sum[n + 1] = dp[i][n + 1];       for (int k = n; k >= 1; --k) sum[k] = (sum[k + 1] + dp[i][k]) % mod;       for (int j = 1; j <= n; ++j) {         if (pre[n - j + 1] - i + 1 >= 0)           dp[i + 1][j] =               (dp[i + 1][j] + 1ll * dp[i][j] * (pre[n - j + 1] - i + 1) % mod) %               mod;         dp[i + 1][j] = (dp[i + 1][j] + sum[n - pre[n - j + 1] + 1]) % mod;       }     }     cout << dp[n][1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 998244353;   const int N = 200005, E = 524288;   int R[N * 4];   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % M;       a = a * a % M;       b >>= 1;     }     return ans;   }   long long wn[N * 4], iwn[N * 4];   void init() {     int i;     iwn[E / 2] = wn[E / 2] = 1;     long long s1 = qpow(3, (M - 1) / E);     long long s2 = qpow(s1, M - 2);     for (i = E / 2 + 1; i < E; ++i) {       wn[i] = wn[i - 1] * s1 % M;       iwn[i] = iwn[i - 1] * s2 % M;     }     for (i = E / 2 - 1; i; --i) {       wn[i] = wn[i << 1];       iwn[i] = iwn[i << 1];     }   }   void NTT(long long *f, int lim, int op) {     int i, j, k;     for (i = 0; i < lim; ++i) {       R[i] = (R[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0);       if (R[i] < i) swap(f[R[i]], f[i]);     }     for (i = 1; i < lim; i <<= 1)       for (j = 0; j < lim; j += (i << 1))         for (k = j; k < j + i; ++k) {           long long a = f[k], b = f[k + i];           long long w = (op == 1 ? wn[k - j + i] : iwn[k - j + i]);           f[k] = (a + b * w) % M;           f[k + i] = (a - b * w) % M;         }     if (op == -1) {       long long inv = qpow(lim, M - 2);       for (i = 0; i < lim; ++i) f[i] = f[i] * inv % M;     }   }   void mult(long long *a, int n, long long *b, int m) {     int lim = 1;     while (lim < n + m) lim <<= 1;     for (int i = n; i < lim; ++i) a[i] = 0;     for (int i = m; i < lim; ++i) b[i] = 0;     NTT(a, lim, 1);     NTT(b, lim, 1);     for (int i = 0; i < lim; ++i) a[i] = a[i] * b[i] % M;     NTT(a, lim, -1);   }   int p[66], k, i, n, m;   char s[N], t[N];   long long a[N * 4], b[N * 4], sum, vis[66], pre[N];   int main() {     init();     for (i = 0; i < 26; ++i) {       scanf( %d , &p[i]);       --p[i];     }     mt19937 rnd(time(0));     for (i = 0; i < 26; ++i)       for (int j = i; !vis[j]; j = p[j]) vis[j] = rnd() % M;     scanf( %s , s);     scanf( %s , t);     n = strlen(s);     m = strlen(t);     reverse(s, s + n);     for (i = 0; i < n; ++i) {       a[i] = (-vis[s[i] -  a ] - vis[p[s[i] -  a ]]) % M;       sum = (sum + vis[s[i] -  a ] * vis[p[s[i] -  a ]]) % M;     }     for (i = 0; i < m; ++i) {       b[i] = vis[t[i] -  a ];       pre[i] = vis[t[i] -  a ] * vis[t[i] -  a ] % M;     }     for (i = 1; i < m; ++i) pre[i] = (pre[i - 1] + pre[i]) % M;     mult(a, n, b, m);     for (i = n - 1; i < m; ++i)       if ((a[i] + pre[i] - (i - n >= 0 ? pre[i - n] : 0) + sum) % M == 0)         putchar( 1 );       else         putchar( 0 );   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int maxn = 2e5 + 5;   const double PI = 3.14159265358979323846;   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     set<long long> s1;     for (long long i = 0; i < n; i++) {       cin >> v[i];       if (s1.find(v[i]) != s1.end() && s1.size() > 1) {         cout << 0 <<   n ;         return;       }       s1.insert(v[i]);     }     if (n == 1) {       cout << -1 <<   n ;       return;     }     if (s1.size() == 1) {       cout << 1 <<   n ;       cout << v[0] <<   n ;       return;     }     sort(v.begin(), v.end());     set<long long> s2;     unordered_map<long long, long long> amp;     long long d = 0;     long long d2 = INT_MAX;     for (long long i = 1; i < n; i++) {       s2.insert(v[i] - v[i - 1]);       amp[v[i] - v[i - 1]]++;       ;       d = ((d) > (v[i] - v[i - 1]) ? (d) : (v[i] - v[i - 1]));       d2 = ((d2) < (v[i] - v[i - 1]) ? (d2) : (v[i] - v[i - 1]));     }     if (s2.size() > 2) {       cout << 0;       return;     }     if (s2.size() == 1) {       if (n == 2 && d / 2 == double(d) / 2) {         vector<long long> ans;         ans.push_back(v[0] - d);         ans.push_back(v[n - 1] + d);         ans.push_back(v[0] + d / 2);         sort(ans.begin(), ans.end());         cout << ans.size() <<   n ;         cout << ans[0] <<     << ans[1] <<     << ans[2];         return;       }       cout << 2 <<   n ;       cout << v[0] - d <<     << v[n - 1] + d;       return;     }     if (amp[d] > 1) {       cout << 0 <<   n ;       return;     }     for (long long i = 1; i < n; i++) {       if (v[i] - v[i - 1] == d && (double)d / 2 == d2) {         cout << 1 <<   n ;         cout << v[i - 1] + d2 <<   n ;         return;       }     }     cout << 0 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long l = 1;     while (l--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void speed() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const long long N = 1e5 + 5;   const long long NN = 105;   const long long MAX = 2e5 + 123;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   map<long long, long long> m;   long long ans = 1, cnt;   vector<pair<long long, pair<long long, long long> > > v;   void hajime() {     long long n, a[N * 2];     scanf( %I64d , &n);     for (long long i = 1; i <= n; i++) scanf( %I64d , &a[i]);     a[n + 1] = -INF;     long long l = 1;     long long mx = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < a[i + 1]) {         ans++;       } else {         mx = max(mx, ans);         v.push_back({ans, {l, i}});         ans = 1;         l = i + 1;       }     }     for (int i = 0; i < v.size(); i++) {       if (i) {         if (a[v[i].second.first + 1] > a[v[i - 1].second.second]) {           mx = max(mx, v[i].first + v[i - 1].first - 1);         }       }       if (i != v.size() - 1) {         if (a[v[i].second.second - 1] < a[v[i + 1].second.first]) {           mx = max(mx, v[i].first + v[i + 1].first - 1);         }       }     }     cout << mx;   }   int main() {     long long miyagi = 1;     while (miyagi--) hajime();   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n;   long long nim[N], prefnim[N];   vector<pair<long long, long long> > sum[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       long long cur = i;       for (long long j = i + 1; j <= n; j++) {         cur += j;         if (cur > n) break;         sum[cur].push_back({i, j});       }     }     for (long long i = 1; i <= n; i++) {       unordered_set<long long> s;       for (auto &it : sum[i])         s.insert(prefnim[it.second] ^ prefnim[it.first - 1]);       long long val = 0;       while (s.find(val) != s.end()) val++;       nim[i] = val;       prefnim[i] = prefnim[i - 1] ^ nim[i];     }     if (nim[n] == 0)       cout <<  -1 ;     else {       long long ans = 1e9;       for (auto &it : sum[n]) {         if ((prefnim[it.second] ^ prefnim[it.first - 1]) == 0)           ans = min(ans, it.second - it.first + 1);       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dem[100001];   long long f[100002];   int main() {     int n;     long long x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       dem[x]++;     }     f[1] = dem[1];     for (int i = 2; i < 100002; i++) f[i] = max(f[i - 2] + dem[i] * i, f[i - 1]);     cout << f[100001];   }