malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   string s;   int main() {     cin >> s;     int len = s.size();     int index7[20], index2[20], index5[20], index0[20];     int sum7 = 0, sum0 = 0, sum5 = 0, sum2 = 0;     for (int i = 0; i < len; i++) {       if (s[i] ==  5 ) {         index5[sum5] = i;         sum5++;       }       if (s[i] ==  0 ) {         index0[sum0] = i;         sum0++;       }       if (s[i] ==  7 ) {         index7[sum7] = i;         sum7++;       }       if (s[i] ==  2 ) {         index2[sum2] = i;         sum2++;       }     }     int res = 1000;     bool flag = false;     if (sum0 >= 2) {       flag = true;       int temp = (len - 1 - index0[sum0 - 1]) + (len - 2 - index0[sum0 - 2]);       res = min(res, temp);     }     if (sum0 > 0 && sum5 > 0) {       flag = true;       int temp = 0;       if (index0[sum0 - 1] < index5[sum5 - 1]) {         temp = ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0) +                ((index0[sum0 - 1] <= len - 2) ? len - 2 - index0[sum0 - 1] : 0);         temp++;       } else {         temp = ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0) +                ((index0[sum0 - 1] <= len - 1) ? len - 1 - index0[sum0 - 1] : 0);       }       if (index5[sum5 - 1] == 0) {         int i = 1;         while (s[i] ==  0  && i < index0[sum0 - 1]) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (sum5 > 0 && sum2 > 0) {       flag = true;       int temp = 0;       if (index5[sum5 - 1] < index2[sum2 - 1]) {         temp = ((index2[sum2 - 1] <= len - 1) ? len - 1 - index2[sum2 - 1] : 0) +                ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0);         temp++;       } else {         temp = ((index2[sum2 - 1] <= len - 2) ? len - 2 - index2[sum2 - 1] : 0) +                ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0);       }       if (index5[sum5 - 1] == 0 || index2[sum2 - 1] == 0) {         int i = 1;         while (s[i] ==  0 ) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (sum7 > 0 && sum5 > 0) {       flag = true;       int temp = 0;       if (index5[sum5 - 1] < index7[sum7 - 1]) {         temp = ((index7[sum7 - 1] <= len - 1) ? len - 1 - index7[sum7 - 1] : 0) +                ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0);         temp++;       } else {         temp = ((index7[sum7 - 1] <= len - 2) ? len - 2 - index7[sum7 - 1] : 0) +                ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0);       }       if (index5[sum5 - 1] == 0 || index7[sum7 - 1] == 0) {         int i = 1;         while (s[i] ==  0 ) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (!flag)       cout << -1 << endl;     else       cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, ans, tot;   unordered_map<long long, int> id;   int op[400010], d[400010], fa[400010], rk[400010], lg[400010], hs[400010];   struct node {     int u, v;     long long h;     void bb() {       if (u > v) swap(u, v);       h = (long long)u << 30 | v;     }   } e[400010], g[400010];   int getfa(int x) { return fa[x] == x ? x : getfa(fa[x]); }   void uni(int x, int y, int z) {     x = getfa(x), y = getfa(y);     if (rk[x] <= rk[y]) {       fa[x] = y;       lg[++tot] = x;       hs[tot] = z;       if (rk[x] == rk[y]) rk[y]++;     } else {       fa[y] = x;       lg[++tot] = y;       hs[tot] = z;     }   }   void del(int x) {     int i;     for (i = tot; hs[i] != x; i--) {       fa[lg[i]] = lg[i];     }     fa[lg[i]] = lg[i];     int u = tot;     tot = i - 1;     for (i++; i <= u; i++) uni(g[hs[i]].u, g[hs[i]].v, hs[i]);   }   void solve(int be, int en) {     for (int i = 1; i <= n; i++) fa[i] = i, rk[i] = 0;     tot = 0;     vector<int> v(cnt + 3), vv(cnt + 3);     for (int i = 1; i < be; i++)       if (op[i] == 1) v[d[i]] ^= 1;     for (int i = be; i <= en; i++)       if (op[i] == 1) vv[d[i]] = vv[d[i + m]] = 1;     for (int i = 1; i <= cnt; i++)       if (v[i] && !vv[i]) uni(g[i].u, g[i].v, i);     for (int i = 1; i <= cnt; i++)       if (v[i] && vv[i]) uni(g[i].u, g[i].v, i);     for (int i = be; i <= en; i++) {       if (ans) e[i] = e[i + m], d[i] = d[i + m];       if (op[i] == 1) {         v[d[i]] ^= 1;         if (v[d[i]])           uni(e[i].u, e[i].v, d[i]);         else           del(d[i]);       } else {         int x = getfa(e[i].u), y = getfa(e[i].v);         if (x != y)           putchar( 0 ), ans = 0;         else           putchar( 1 ), ans = 1;       }     }   }   int main(int argc, char const *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &op[i]);       scanf( %d%d , &e[i].u, &e[i].v);       e[i].bb();       op[i + m] = op[i];       e[i + m] = {e[i].u % n + 1, e[i].v % n + 1};       e[i + m].bb();     }     for (int i = 1, tot = m * 2; i <= tot; i++) {       long long t = e[i].h;       if (!id[t]) id[t] = ++cnt, g[cnt] = e[i];       d[i] = id[t];     }     int B = sqrt(m);     for (int i = 1; i <= m; i += B) solve(i, min(i + B - 1, m));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int x;   int dfs(int xx, int yy, int cc) {     if (cc == 0) {       if (xx == 1 || yy == 1) {         int tt = xx * yy;         if (tt % 2 == 0)           return tt / 2;         else           return tt / 2 + 1;       } else         return ((xx + yy) * 2 - 4) / 2;     }     if (xx <= 2 || yy <= 2) {       if (cc >= 1) return 0;       int k = xx * yy;       if (k % 2 == 0) return k / 2;       return k / 2 + 1;     }     int g = dfs(xx - 2, yy - 2, cc - 1);     return g;   }   int main() {     while (cin >> n >> m >> x) {       int t = dfs(n, m, x - 1);       cout << t << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   const long long mod = 1e9 + 7;   long long kissme(long long x, long long t) {     long long ans = 1;     while (t > 0) {       if (t & 1) ans = ans * x % mod;       x = x * x % mod;       t >>= 1;     }     return ans;   }   struct number {     int x, y;     number(int _x = 0, int _y = 0) {       x = _x;       y = _y;     }     number operator+(number t) {       return number((x + t.x) % mod, (y + t.y) % mod);     }     number operator-(number t) {       return number((x - t.x + mod) % mod, (y - t.y + mod) % mod);     }     number operator*(number t) {       return number((1ll * x * t.x + 1ll * y * t.y * 5) % mod,                     (1ll * x * t.y + 1ll * y * t.x) % mod);     }     number operator*(int t) {       return number((1ll * x * t) % mod, (1ll * y * t) % mod);     }     bool operator!=(number t) { return x != t.x || y != t.y; }     number inv() {       long long t = (1ll * x * x % mod - 5ll * y * y % mod + mod) % mod;       t = kissme(t, mod - 2);       return number(x * t % mod, (-y * t % mod + mod) % mod);     }     void operator=(int t) {       x = t;       y = 0;     }     number operator^(long long t) {       number ret(1, 0), b = (*this);       while (t > 0) {         if (t & 1) ret = ret * b;         b = b * b;         t >>= 1;       }       return ret;     }     void out() { cout << x <<  ,  << y << endl; }   };   number sigma(number x, long long l, long long r) {     if (x.x == 1 && x.y == 0)       return (r - l + 1) % mod;     else       return ((x ^ l) - (x ^ (r + 1))) * (number(1, 0) - x).inv();   }   long long k, l, r;   long long dp[211];   long long f[211], revf[211];   long long C(long long x, long long y) {     if (x < y)       return 0;     else       return f[x] * revf[y] % mod * revf[x - y] % mod;   }   number A, B, pa[211], pb[211];   int sign(long long n) { return n & 1 ? mod - 1 : 1; }   long long solve(long long l, long long r) {     number c = 1, bs = number(0, kissme(5, mod - 2));     number sum;     for (int i = 1; i <= k; i++) {       c = c * bs;       number tsum;       for (int j = 0; j <= i; j++) {         tsum = tsum + sigma(pa[j] * pb[i - j], l, r) * C(i, j) * sign(i - j);       }       tsum = tsum * c;       sum = sum + tsum * dp[i];     }     return sum.x;   }   int main() {     f[0] = 1;     for (int i = 1; i <= 205; i++) f[i] = f[i - 1] * i % mod;     revf[205] = kissme(f[205], mod - 2);     for (int i = 204; i >= 0; i--) revf[i] = revf[i + 1] * (i + 1) % mod;     number A = number(1, 1) * kissme(2, mod - 2), B = number(1, 0) - A;     pa[0] = 1;     pb[0] = 1;     for (int i = 1; i <= 205; i++) pa[i] = pa[i - 1] * A, pb[i] = pb[i - 1] * B;     cin >> k >> l >> r;     l += 2;     r += 2;     dp[1] = 1;     long long fac = 1;     for (int i = 1; i < k; i++) {       fac = fac * (i + 1) % mod;       for (int j = i; j >= 0; j--) {         dp[j + 1] = (dp[j + 1] + dp[j]) % mod;         dp[j] = dp[j] * (-i + mod) % mod;       }     }     cout << solve(l, r) % mod * kissme(fac, mod - 2) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> cnt(200002, 0);     for (int i = 0; i < n; i++) {       cnt[a[i]]++;     }     int mx = 0;     int res = 0;     for (int i = 0; i < 200002; i++) {       if (cnt[i] > mx) {         mx = cnt[i];         res = i;       }     }     int ind = 0;     for (int i = 0; i < n; i++) {       if (a[i] == res) {         ind = i;         break;       }     }     cout << n - mx <<   n ;     int ind1 = ind;     while (ind1 > 0) {       if (a[ind1 - 1] < res) {         cout <<  1   << ind1 <<     << ind1 + 1 <<   n ;       }       if (a[ind1 - 1] > res) {         cout <<  2   << ind1 <<     << ind1 + 1 <<   n ;       }       ind1--;     }     ind1 = ind;     while (ind1 < n - 1) {       if (a[ind1 + 1] < res) {         cout <<  1   << ind1 + 2 <<     << ind1 + 1 <<   n ;       }       if (a[ind1 + 1] > res) {         cout <<  2   << ind1 + 2 <<     << ind1 + 1 <<   n ;       }       ind1++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     istream& in = cin;     int n;     in >> n;     vector<string> v;     for (int i = 0; i < n; i++) {       string str;       in >> str;       v.push_back(str);     }     set<char> use;     map<char, set<char> > use2;     for (int i = 0; i < n; i++) {       char p, c;       for (int j = 0; j < v[i].length(); j++) {         c = v[i][j];         use.insert(c);         if (j != 0) {           use2[p].insert(c);         }         p = c;       }     }     if (use.size() != 26) {       for (char ch =  a ; ch <=  z ; ch++) {         if (use.find(ch) == use.end()) {           cout << ch << endl;           break;         }       }     } else {       bool find = false;       for (char c1 =  a ; c1 <=  z  && !find; c1++) {         set<char> s = use2[c1];         for (char c2 =  a ; c2 <=  z  && !find; c2++) {           if (s.find(c2) == s.end()) {             cout << c1 << c2 << endl;             find = true;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f = (ch ==  - ) ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 500 + 5;   const int P = 1e9 + 7;   int n, m, len;   inline int add(int a, int b) {     a += b;     return a >= P ? a - P : a;   }   inline int mul(int a, int b) { return (unsigned long long)a * b % P; }   char s[N][N];   int dp[2][N][N];   int dx1[] = {0, 1}, dy1[] = {1, 0};   int dx2[] = {0, -1}, dy2[] = {-1, 0};   bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void solve_odd() {     int u = 0, v = 1;     dp[u][0][n - 1] = 1;     len = (len + 1) >> 1;     for (int i = (0); i < (len - 1); ++i) {       u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u]));       for (int j = (0); j < (n); ++j)         for (int k = (0); k < (n); ++k) {           int x1 = j, y1 = i - j;           int x2 = k, y2 = m - 1 - (i - (n - 1 - x2));           if (ok(x1, y1) && ok(x2, y2)) {             for (int p = (0); p < (2); ++p)               for (int q = (0); q < (2); ++q) {                 int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p];                 int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q];                 if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) {                   dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]);                 }               }           }         }     }     int ans = 0;     for (int i = (0); i < (n); ++i) ans = add(ans, dp[u][i][i]);     cout << ans << endl;   }   void solve_even() {     int u = 0, v = 1;     dp[u][0][n - 1] = 1;     len = (len) >> 1;     for (int i = (0); i < (len - 1); ++i) {       u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u]));       for (int j = (0); j < (n); ++j)         for (int k = (0); k < (n); ++k) {           int x1 = j, y1 = i - j;           int x2 = k, y2 = m - 1 - (i - (n - 1 - x2));           if (ok(x1, y1) && ok(x2, y2)) {             for (int p = (0); p < (2); ++p)               for (int q = (0); q < (2); ++q) {                 int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p];                 int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q];                 if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) {                   dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]);                 }               }           }         }     }     int ans = 0;     for (int i = (0); i < (n); ++i)       ans = add(ans, add(dp[u][i][i], dp[u][i][i + 1]));     cout << ans << endl;   }   int main() {     n = read(), m = read();     for (int i = (0); i < (n); ++i) scanf( %s , s[i]);     if (s[0][0] != s[n - 1][m - 1]) {       puts( 0 );       return 0;     }     len = n + m - 1;     if (len & 1)       solve_odd();     else       solve_even();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int gotcha() {     int a = 0, b = 1, c = getchar();     while (!isdigit(c)) b ^= c ==  - , c = getchar();     while (isdigit(c)) a = a * 10 + c - 48, c = getchar();     return b ? a : -a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     map<int, int> mp;     int n;     scanf( %d , &n);     int b, i, index = 0, j;     for (i = 1; i <= n; i++) {       scanf( %d , &b);       mp[b] = i;     }     for (i = 0; i < n; i++) {       b = gotcha();       if (mp[b] - index > 0) {         printf( %d  , mp[b] - index);         index = mp[b];       } else         printf( 0  );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, u = 0, ans1 = 0, ans2 = 0;     cin >> n >> m >> k;     bool a[n][m];     long long sum[n + 2][m];     memset(sum, 0, sizeof(sum));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];         sum[i][j] = (i ? sum[i - 1][j] : 0) + a[i][j];         if (i >= k) sum[i][j] -= a[u][j];         if (sum[i][j] > sum[n][j]) {           sum[n][j] = sum[i][j];           sum[n + 1][j] = i - k + 1;         }       }       u += (i >= k);     }     for (long long j = 0; j < m; j++) {       ans1 += sum[n][j];       for (long long i = 0; i < sum[n + 1][j]; i++) ans2 += a[i][j];     }     cout << ans1 <<     << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ii {     string zl;     int x, id;   } zl[1000005];   bool cmp1(ii a, ii b) {     if (a.x < b.x) return 1;     if (a.x > b.x) return 0;     return a.zl < b.zl;   }   bool cmp2(ii a, ii b) { return a.id < b.id; }   int n, cnt, zhi[1000005], sz[1000005], i;   long long sum[1000005][5], ans;   map<int, int> mp;   void update(int id, int le, int ri, int pos) {     sz[id]++;     if (le == pos && ri == pos) {       sum[id][1] += zhi[pos];       return;     }     if (pos > (le + ri) / 2)       update(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);     else       update(id * 2, le, (le + ri) / 2, pos);     int i;     for (i = 0; i < 5; i++) {       sum[id][i] =           sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];     }   }   void erase(int id, int le, int ri, int pos) {     sz[id]--;     if (le == pos && ri == pos) {       sum[id][1] -= zhi[pos];       return;     }     if (pos > (le + ri) / 2)       erase(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);     else       erase(id * 2, le, (le + ri) / 2, pos);     int i;     for (i = 0; i < 5; i++) {       sum[id][i] =           sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (i = 1; i <= n; i++) {       cin >> zl[i].zl;       if (zl[i].zl[0] ==  s )         zl[i].x = 0;       else         cin >> zl[i].x;       zl[i].id = i;     }     sort(zl + 1, zl + n + 1, cmp1);     cnt = 1;     for (i = 1; i <= n; i++) {       if (zl[i].zl[0] ==  a ) {         if (!mp[zl[i].x]) mp[zl[i].x] = cnt++;         zhi[mp[zl[i].x]] = zl[i].x;         zl[i].x = mp[zl[i].x];       } else if (zl[i].zl[0] ==  d ) {         zl[i].x = mp[zl[i].x];       }     }     sort(zl + 1, zl + n + 1, cmp2);     for (i = 1; i <= n; i++) {       if (zl[i].zl ==  add ) update(1, 1, cnt, zl[i].x);       if (zl[i].zl ==  del ) erase(1, 1, cnt, zl[i].x);       if (zl[i].zl ==  sum ) cout << sum[1][3] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int primes[10001];   int p[10001];   int numbers[10001];   int cnt;   void sieve() {     for (int a = 2; a <= 10000; ++a)       if (primes[a] == 0)         for (int b = 2; b * a <= 10000; b++) primes[a * b] = 1;     int c = 0;     for (int a = 2; a <= 10001; ++a)       if (primes[a] == 0) {         p[c] = a;         c++;       }     cnt = 0;     for (int a = 1; a < c; ++a) {       if (primes[p[a] + p[a - 1] + 1] == 0) {         numbers[cnt] = p[a] + p[a - 1] + 1;         cnt++;       }     }   }   int main() {     sieve();     int n, k;     cin >> n >> k;     if (lower_bound(numbers, numbers + cnt, n) - numbers >= k - 1)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m;     int i = 0, tmp;     int P, Q;     cin >> n >> m;     i = n;     cin >> P;     while (i--) {       cin >> tmp;     }     cin >> Q;     i = m;     while (i--) {       cin >> tmp;     }     int sm = 1, sn = 1;     if (P < 0) sn = -1;     if (Q < 0) sm = -1;     if (m == n) {       if (sm * sn < 0) cout <<  - ;       P = (P < 0) ? -P : P;       Q = (Q < 0) ? -Q : Q;       int a = P, b = Q;       while (b) {         if (a > b)           a -= b;         else           b -= a;       }       P /= a;       Q /= a;       if (m >= 0) cout << P <<  /  << Q << endl;     } else {       if (n < m)         cout <<  0/1  << endl;       else {         if (sm * sn < 0) cout <<  - ;         cout <<  Infinity  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int A = 1e7 + 10;   const int B = 1e6 + 10;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     return x * f;   }   struct node {     int v, nxt, w, kkk;   } e[B];   int cnt, in[B], id[B], cg[B], k = 0, n, m, head[B];   void modify(int u, int v, int w, int kkk) {     e[++cnt].nxt = head[u];     e[cnt].w = w;     e[cnt].v = v;     e[cnt].kkk = kkk;     head[u] = cnt;   }   queue<int> q;   bool check(int mid) {     int kc = 0;     memset(in, 0, sizeof(in));     memset(id, 0, sizeof(id));     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = e[j].nxt) {         int v = e[j].v, w = e[j].w;         if (w <= mid) continue;         ++in[v];       }     }     for (int i = 1; i <= n; i++) {       if (!in[i]) {         q.push(i);       }     }     int js = 0;     while (!q.empty()) {       int now = q.front();       id[now] = ++kc;       js++;       q.pop();       for (int i = head[now]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (w <= mid) continue;         --in[v];         if (!in[v]) q.push(v);       }     }     if (js != n) return 0;     k = 0;     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = e[j].nxt) {         if (e[j].w > mid) continue;         int v = e[j].v;         if (id[v] < id[i]) {           cg[++k] = e[j].kkk;         }       }     }     return 1;   }   int main() {     n = read(), m = read();     int r = 0;     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w = read();       modify(u, v, w, i);       r = max(r, w);     }     int l = 0, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     sort(cg + 1, cg + k + 1);     printf( %d %d n , ans, k);     for (int i = 1; i <= k; i++) printf( %d  , cg[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long large = 2000000000000000000LL;   bitset<20011> vis;   vector<int> primes;   void sieve(long long n) {     vis.set();     vis[0] = 0;     vis[1] = 0;     for (long long i = 2; i <= n; i++) {       if (vis[i]) primes.push_back((int)i);       for (int j = 0; j < (int)primes.size() && i * primes[j] <= n; j++) {         vis[i * primes[j]] = 0;         if (i % primes[j] == 0) break;       }     }   }   int main() {     int n;     unsigned int a, b, c, d;     cin >> n >> a >> b >> c >> d;     sieve(20010);     unsigned int ans = 0;     int sq = 20000;     int p = 2;     while (p < n + 1) {       int l = p;       int r = min(l + sq, n + 1);       int sz = r - l;       vector<bool> vis(sz, true);       for (int i = 0; i < (int)primes.size(); i++) {         int x = primes[i];         int y = l;         y = max(y, 2 * x);         y = ((y - 1) / x + 1) * x;         while (y < r) {           vis[y - l] = false;           y += x;         }       }       for (int i = 0; i < sz; i++) {         if (vis[i]) {           unsigned int x = i + l;           if (x < 2) continue;           unsigned int temp = a * x * x * x + b * x * x + c * x + d;           unsigned int d = x;           while (n / d) {             ans += temp * (n / d);             if (n / x < d) break;             d *= x;           }         }       }       p += sq;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   int a[N];   int f[N];   int sumf[N];   long long sum;   long long best;   vector<int> freq;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       f[a[i]]++;       sum += a[i];     }     if (f[1]) {       printf( %lld n , sum);       return 0;     }     for (int i = 2; i < N; i++) {       if (f[i]) freq.push_back(i);       sumf[i] = f[i] + sumf[i - 1];     }     for (int i = 0; i < freq.size(); i++) {       int leading = freq[i];       long long total = 0;       for (int j = leading; j < N; j += leading) {         total += 1ll * (sumf[min(j + leading - 1, N - 1)] - sumf[j - 1]) * j;       }       best = max(best, total);     }     printf( %lld n , best);     return 0;   }