malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<long long int> v;     unordered_map<long long int, long long int> mapy;     v.push_back(0);     v.push_back(2);     mapy[2] = 1;     for (long long int i = 2; i <= 100000; i++) {       v.push_back(((3 * (i * (i + 1))) / 2) - i);       mapy[(((3 * (i * (i + 1))) / 2) - i)] = 1;     }     while (t--) {       long long int n;       cin >> n;       ;       long long int c = 0;       while (n > 1) {         auto f = lower_bound(v.begin(), v.end(), n);         if (mapy[n] == 1) {           c++;           break;         }         long long int hj = f - v.begin();         hj--;         n -= v[hj];         c++;       }       cout << c << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n == 1) {       cout <<  1 n0 1 n0 n1 ;       return 0;     }     vector<long long> p1, p2;     p1.push_back(1);     p1.push_back(0);     p2.push_back(1);     for (long long i = 1; i < n; i++) {       vector<long long> temp = p1;       p1.push_back(0);       for (long long j = 0; j < p2.size(); j++) {         p1[j + 2] += p2[j];         p1[j + 2] %= 2LL;       }       p2 = temp;     }     reverse(p1.begin(), p1.end());     reverse(p2.begin(), p2.end());     cout << p1.size() - 1 <<   n ;     for (long long i = 0; i < p1.size(); i++) cout << p1[i] <<    ;     cout <<   n ;     cout << p2.size() - 1 <<   n ;     for (long long i = 0; i < p2.size(); i++) cout << p2[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, d, a[100000], diff;     long sum = 0;     cin >> n >> d;     for (long i = 0; i < n; i++) cin >> a[i];     for (long i = 1; i < n; i++) {       if (a[i - 1] >= a[i]) {         diff = a[i - 1] - a[i];         a[i] = a[i] + (diff / d + 1) * d;         sum = sum + diff / d + 1;       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 55, p = 1e9 + 7;   int n, m;   long long inv[Maxn], f[Maxn][Maxn], g[Maxn][Maxn], sum[Maxn][Maxn];   long long get_inv(int x) {     return x <= 1 ? 1 : (p - p / x) * get_inv(p % x) % p;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) inv[i] = get_inv(i);     f[0][1] = sum[0][1] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i + 1; j++)         for (int k = 1; k <= i; k++)           (g[i][j] += sum[k - 1][j] * sum[i - k][j]) %= p;       for (int j = 1; j <= i + 1; j++) {         (g[i][j] += p - g[i][j + 1]) %= p;         for (int a = n; a >= 0; a--)           for (int b = n + 1; b >= 0; b--) {             long long now = 1;             for (int d = 1; i * d <= a && j * d <= b; d++) {               (now *= inv[d] * (g[i][j] + d - 1 + p) % p) %= p;               (f[a][b] += now * f[a - i * d][b - j * d]) %= p;             }           }       }       for (int j = i + 1; j >= 1; j--) sum[i][j] = (sum[i][j + 1] + f[i][j]) % p;     }     printf( %lld , f[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n;   long long mas[300007];   long long ex[300007];   vector<long long> s;   int main() {     scanf( %d %d , &m, &n);     for (int i = 0; i < m; i++) {       scanf( %I64d , &mas[i]);     }     for (int i = 0; i < n; i++) {       scanf( %I64d , &ex[i]);     }     n--;     m--;     for (int i = 0; i < n; i++) {       ex[i] = ex[i + 1] - ex[i];       s.push_back(ex[i]);     }     s.push_back((long long)1000000000000);     for (int i = 0; i < m; i++) {       mas[i] = mas[i + 1] - mas[i];       s.push_back(mas[i]);     }     m = n + m + 1;     vector<int> z(m);     for (int i = 1, l = 0, r = 0; i < m; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < m && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     int c = 0;     for (int i = n; i < m; i++)       if (z[i] >= n) c++;     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1500 + 10;   int n, x, y;   struct node {     int xx, yy, id;     bool operator<(const node &a) const {       if (xx - x >= 0 && a.xx - x <= 0) return 1;       if (xx - x <= 0 && a.xx - x >= 0) return 0;       return (yy - y) * (long long)(a.xx - x) < (a.yy - y) * (long long)(xx - x);     }   } p[M];   vector<int> g[M];   int sz[M];   int ans[M];   void dfs(int o, int u) {     sz[u] = 1;     for (int &v : g[u])       if (v != o) {         dfs(u, v);         sz[u] += sz[v];       }   }   void dfs2(int o, int u, int l, int r) {     if (sz[u] == 1) {       ans[p[l].id] = u;       return;     }     int id = l;     for (int i = l + 1; i < r; ++i) {       if (p[i].xx < p[id].xx) {         id = i;       }     }     swap(p[id], p[l]);     ans[p[l].id] = u;     x = p[l].xx, y = p[l].yy;     sort(p + l + 1, p + r);     int sum = l + 1;     for (int &v : g[u])       if (v != o) {         dfs2(u, v, sum, sum + sz[v]);         sum += sz[v];       }   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       g[u].emplace_back(v);       g[v].emplace_back(u);     }     for (int i = 0; i < n; ++i) {       scanf( %d%d , &p[i].xx, &p[i].yy);       p[i].id = i;     }     dfs(1, 1);     dfs2(1, 1, 0, n);     for (int i = 0; i < n; ++i) {       printf( %d%c , ans[i],    n [i == n - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   pair<long long, long long> a[3005];   long long v[3005];   vector<long long> vec[3005];   priority_queue<long long, vector<long long>, greater<long long> > mc;   bool compare(pair<long long, long long> a, pair<long long, long long> b) {     return a > b;   }   int main() {     cin >> n >> m;     if (m == 1) {       cout << 0 << endl;       exit(0);     };     long long x, y;     for (long long i = 0; i < n; i++) {       scanf( %I64d%I64d , &x, &y);       x--;       v[x]++;       vec[x].push_back(y);       if (x) mc.push(y);     }     for (long long i = 0; i < m; i++) {       a[i].first = v[i];       a[i].second = i;       sort(vec[i].begin(), vec[i].end());     }     sort(a, a + m, compare);     if (a[0].second == 0 && a[0].first > a[1].first) {       cout << 0 << endl;       exit(0);     };     long long need = a[0].first - v[0] + 1;     long long tneed;     priority_queue<long long, vector<long long>, greater<long long> > tmc;     long long res = 541885418851154LL;     long long cost;     for (long long i = 0; i <= a[0].first; i++) {       cost = 0;       while (tmc.size()) {         tmc.pop();       }       tneed = need;       if (tneed <= 0) {         res = 0;         break;       }       long long debug = (i == 2);       for (long long j = 0; j < m; j++) {         long long tj = a[j].second;         for (long long k = max(v[tj] - i, 0LL); k < v[tj]; k++) {           if (tj != 0) tmc.push(vec[tj][k]);         }         if (v[tj] <= i) continue;         for (long long k = 0; k < v[tj] - i; k++) {           cost += vec[tj][k];           tneed--;           if (tneed == 0) break;         }         if (tneed == 0) break;       }       tneed -= a[0].first - i;       if (tneed <= 0) {         res = min(res, cost);         continue;       }       for (long long j = 0; j < tneed; j++) {         cost += tmc.top();         tmc.pop();       }       res = min(res, cost);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int res[100005];   int main() {     long long int n;     scanf( %lld , &n);     if (n % 4 == 2 || n % 4 == 3) {       printf( -1 );       exit(0);     }     long long int c = 2;     for (long long int i = 0; i < n / 2; i += 2) {       res[i] = c;       res[i + 1] = n - i;       c += 2;     }     c = 1;     for (long long int i = n - 2; i >= n / 2; i -= 2) {       res[i] = c;       res[i + 1] = n - c;       c += 2;     }     if (n % 2) res[n / 2] = n / 2 + 1;     for (long long int i = 0; i < n; i++) printf( %lld  , res[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5000;   int p[MAXN], size[MAXN], n, m;   int find_set(int v) { return v == p[v] ? v : p[v] = find_set(p[v]); }   void union_set(int x, int y) {     x = find_set(x);     y = find_set(y);     if (x != y) {       if (size[x] < size[y]) swap(x, y);       p[x] = y;       size[y] += size[x];     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) size[i] = 1, p[i] = i;     while (m--) {       int x, y;       cin >> x >> y;       union_set(x, y);     }     int mx = 0;     cin >> m;     while (m--) {       int x, y;       cin >> x >> y;       if (find_set(x) == find_set(y)) size[find_set(x)] = 0;     }     for (int i = 1; i <= n; i++) {       mx = max(mx, size[find_set(i)]);     }     cout << mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MOD = 1000000009;   int parent[N];   int Rank[N];   int Find(int x) {     if (parent[x] != x) {       parent[x] = Find(parent[x]);     }     return parent[x];   }   bool Union(int x, int y) {     x = Find(x);     y = Find(y);     if (x == y) return false;     if (Rank[x] < Rank[y]) {       parent[x] = y;     } else if (Rank[x] > Rank[y]) {       parent[y] = x;     } else {       parent[x] = y;       Rank[y]++;     }     return true;   }   int main() {     int n, m, a, b;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       parent[i] = i;     }     int ans = 1;     while (m--) {       scanf( %d %d , &a, &b);       if (!Union(a, b)) {         ans = (ans * 2) % MOD;       }       printf( %d n , ans ? ans - 1 : MOD - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[2005], d[100005], z[100005], L[100005];   inline void upd(int &a, int b) {     if (a < b) a = b;   }   int main(void) {     while (cin >> n >> m) {       for (int i = int(1); i <= int(n); i++) cin >> a[i];       for (int i = int(1); i <= int(m); i++) cin >> b[i];       sort(a + 1, a + n + 1);       sort(b + 1, b + m + 1);       memset(d, 0, sizeof d), memset(z, 0, sizeof z), memset(L, 0, sizeof L);       for (int i = int(1); i <= int(n); i++) {         if (i > 1 && a[i] - 1 == a[i - 1])           L[i] = L[i - 1];         else           L[i] = i;         int x = upper_bound(b + 1, b + m + 1, a[i]) - b;         upd(d[i], z[L[i] - 1]);         for (int j = int(x - 1); j >= int(1); j--) {           if (i <= a[i] - b[j]) break;           upd(d[i], z[L[i - a[i] + b[j]] - 1] + x - j);         }         upd(z[i], max(z[i - 1], d[i]));         for (int j = int(x); j <= int(m); j++) {           if (i + b[j] - a[i] > n) break;           upd(z[i + b[j] - a[i]], d[i] + j - x + 1);         }       }       cout << z[n] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, r[200005], cnt = 0;     bool valid[200005];     pair<int, int> p;     pair<int, pair<int, int> > u;     vector<int> v;     vector<pair<int, pair<int, int> > > event;     priority_queue<pair<int, int> > pq;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &l, &r[i]);       event.push_back(make_pair(l, make_pair(0, i)));       event.push_back(make_pair(r[i] + 1, make_pair(1, i)));     }     sort(event.begin(), event.end());     memset(valid, true, sizeof valid);     for (int i = 0; i < (int)event.size(); i++) {       u = event[i];       l = u.first;       while (u.first == l) {         if (u.second.first == 0) {           pq.push(make_pair(r[u.second.second], u.second.second));           cnt++;         } else if (valid[u.second.second]) {           valid[u.second.second] = false;           cnt--;         }         i++;         if (i == (int)event.size()) break;         u = event[i];       }       i--;       while (cnt > k) {         p = pq.top();         pq.pop();         while (!valid[p.second]) {           p = pq.top();           pq.pop();         }         valid[p.second] = false;         v.push_back(p.second);         cnt--;       }     }     printf( %d n , (int)v.size());     for (int i = 0; i < (int)v.size(); i++) {       if (i) putchar(   );       printf( %d , v[i]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 23, MAXM = 2e4 + 10, LIM = (1 << MAXN), mod = 998244353;   int n, f[1 << MAXN], g[1 << MAXN], F[1 << MAXN];   long long ans;   int pcnt[1 << MAXN], psum[1 << MAXN], tag[1 << MAXN];   char s[MAXN][MAXM];   int cnt[MAXN][26];   int main() {     for (int i = (0); i <= (22); i++) tag[1 << i] = i;     for (int i = (1); i <= ((1 << 23) - 1); i++) {       pcnt[i] = pcnt[i - (i & -i)] + 1;       psum[i] = psum[i - (i & -i)] + tag[(i & -i)] + 1;     }     scanf( %d , &n);     for (int i = (0); i <= (n - 1); i++) {       scanf( %s , s[i] + 1);       int len = strlen(s[i] + 1);       for (int j = (1); j <= (len); j++) {         cnt[i][s[i][j] -  a ]++;       }     }     for (int i = (1); i <= ((1 << n) - 1); i++) f[i] = 1;     for (int i = (0); i <= (25); i++) {       g[0] = 1e9;       for (int j = (1); j <= ((1 << n) - 1); j++) {         g[j] = min(g[j ^ (j & -j)], cnt[tag[(j & -j)]][i]);         f[j] = 1LL * f[j] * (g[j] + 1) % mod;       }     }     for (int i = (1); i <= ((1 << n) - 1); i++) {       if ((pcnt[i] & 1))         F[i] = f[i];       else         F[i] = mod - f[i];     }     for (int i = (0); i <= (22); i++) {       for (int j = (1); j <= ((1 << n) - 1); j++) {         if (j >> i & 1) {           F[j] = (F[j] + F[j ^ (1 << i)]) % mod;         }       }     }     for (int j = (1); j <= ((1 << n) - 1); j++) {       ans ^= (1LL * F[j] * pcnt[j] * psum[j]);     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       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];       sort(a.begin(), a.end());       sort(b.rbegin(), b.rend());       int f = 0;       for (int i = 0; i < n; i++) {         if (a[i] + b[i] > x) {           f = 1;           break;         }       }       if (f)         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int tc = 1;   const int M = 1e9 + 7;   const long long Inf = (long long)2e18 + 5;   const int N = 2e5 + 5;   std::vector<long long> a[N];   int solve() {     int a;     cin >> a;     int z = 0;     int bg = 0;     int xx = 0;     int mx = 0;     long long ans = 0LL;     for (z = 0; z < a; z++) {       int n;       cin >> n;       mx = 0;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         mx = max(mx, x);       }       if (z > 0) {         if (xx > mx) {           ans += (long long)(xx - mx) * n;           bg += n;         } else {           ans += (long long)(mx - xx) * bg;           xx = mx;           bg += n;         }       } else {         xx = mx;         bg += n;       }     }     cout << ans << endl;     return 0;   }   int main() {     int test = 1;     while (test--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x1, x2, y1, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     int dx = abs(x2 - x1);     int dy = abs(y2 - y1);     if (dx <= 4 && dy <= 2 || dy <= 4 && dx <= 2 || dx == 3 && dy == 3) {       cout <<  First ;     } else {       cout <<  Second ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, c;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> a >> b >> c;     if (n == 1)       cout << 0 << endl;     else if (c >= min(a, b))       cout << (n - 1) * min(a, b) << endl;     else       cout << min(a, b) + (n - 2) * c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long s = 0;       for (long long i = 0; i < n; i++) {         long long a;         cin >> a;         s += 2 * a;       }       if (n == m && n > 2) {         cout << s << endl;         for (long long i = 1; i < n; i++) cout << i <<     << i + 1 << endl;         cout << n <<     << 1 << endl;       } else         cout <<  -1 n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.length();     if ((s[l - 1] - 48) % 2 == 0) {       int temp = s[l - 2] * 10 + s[l - 1];       if (temp % 4 == 0) {         cout << 4 << endl;       } else {         cout << 0 << endl;       }     } else {       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (n == 1 && m == 2) {       cout << 0 << endl;       cout << 1 <<     << 1 << endl;       cout << 1 <<     << 2 << endl;       cout << 1 <<     << 1 << endl;       return 0;     }     if (n == 2 && m == 1) {       cout << 0 << endl;       cout << 1 <<     << 1 << endl;       cout << 2 <<     << 1 << endl;       cout << 1 <<     << 1 << endl;       return 0;     }     if ((n % 2 && m % 2) || n == 1 || m == 1) {       cout << 1 << endl;       if (n == 1) {         cout << 1 <<     << m;         cout <<     << 1 <<     << 1 << endl;       } else if (m == 1) {         cout << 1 <<     << 1 <<     << n <<     << 1 << endl;       } else if (n % 2 == 1 && m % 2 == 1) {         cout << n <<     << m <<    ;         cout << n <<     << 1 << endl;       } else {         cout << n <<     << 1;         cout <<     << 1 <<     << 1 << endl;       }     } else       cout << 0 << endl;     if (m % 2 == 0) {       for (int i = 1; i <= m; i++) cout << 1 <<     << i << endl;       for (int j = m; j >= 1; j -= 2) {         for (int i = 2; i <= n; i++) cout << i <<     << j << endl;         for (int i = n; i > 1; i--) cout << i <<     << j - 1 << endl;       }       cout << 1 <<     << 1 << endl;     } else {       cout << 1 <<     << 1 << endl;       for (int i = 1; i <= n; i += 2) {         for (int j = 2; j <= m; j++) cout << i <<     << j << endl;         if (i != n)           for (int j = m; j >= 2; j--) cout << i + 1 <<     << j << endl;       }       if (n % 2 == 1 && m % 2 == 0) {         for (int i = 2; i <= n; i++) cout << i <<     << 1 << endl;         cout << 1 <<     << 1 << endl;       } else         for (int i = n; i >= 1; i--) cout << i <<     << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int c[100010];   int x[100010], y[100010];   vector<int> t[100010];   int f[100010];   int find(int x) { return (f[x] == -1 ? x : f[x] = find(f[x])); }   int fa[100010], dep[100010];   int dfn[100010], rnk[100010], totn = 0;   int siz[100010], son[100010], top[100010];   void dfs1(int k) {     dep[k] = dep[fa[k]] + 1;     siz[k] = 1;     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k]) continue;       fa[*it] = k;       dfs1(*it);       siz[k] += siz[*it];       if (son[k] == 0 || siz[*it] > siz[son[k]]) son[k] = *it;     }     return;   }   void dfs2(int k, int tp) {     dfn[k] = ++totn;     rnk[totn] = k;     top[k] = tp;     if (son[k]) dfs2(son[k], tp);     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k] || *it == son[k]) continue;       dfs2(*it, *it);     }     return;   }   int LCA(int a, int b) {     while (top[a] != top[b]) {       if (dep[top[a]] < dep[top[b]]) swap(a, b);       a = fa[top[a]];     }     return (dep[a] < dep[b] ? a : b);   }   long long v[100010];   void dfs3(int k) {     v[k] = c[k];     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k]) continue;       dfs3(*it);       v[k] -= v[*it];     }     return;   }   long long ve[100010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &y[i]);     memset(f, -1, sizeof(f));     for (int i = 1; i <= m; ++i) {       int p = find(x[i]), q = find(y[i]);       if (p == q) continue;       f[p] = q;       t[x[i]].push_back(y[i]);       t[y[i]].push_back(x[i]);     }     dfs1(1);     dfs2(1, 1);     dfs3(1);     for (int i = 1; i <= m; ++i) {       if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) continue;       if ((dep[x[i]] + dep[y[i]] - 2 * dep[LCA(x[i], y[i])]) % 2 == 0) {         int val = v[1] / 2;         val = val * (dep[x[i]] % 2 == 0 ? -1 : 1);         ve[i] = val;         c[x[i]] -= val;         c[y[i]] -= val;         break;       }     }     dfs3(1);     if (v[1] != 0) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= m; ++i) {       if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) {         if (dep[x[i]] < dep[y[i]]) swap(x[i], y[i]);         ve[i] = v[x[i]];       }       printf( %lld n , ve[i]);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 )   #pragma GCC optimize( fast-math )   using namespace std;   const int INF = 1e9;   const long long INFll = 2e18;   const int BASE1 = 179;   const int BASE2 = 653;   const long long MOD = 1e9 + 7;   const int MAXN = 2e5;   const long double PI = 3.1415926535;   const long double EPS = 1e-10;   void solve() {     int n;     cin >> n;     vector<vector<char>> dop(n, vector<char>(n,  * ));     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (n); j++) {         if (abs(i - n / 2) + abs(j - n / 2) <= n / 2) dop[i][j] =  D ;       }     }     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (n); j++) {         cout << dop[i][j];       }       cout <<   n ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(15);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 10;   long long n, m;   long long res[N], sum[N], a[N];   long long len;   struct Node {     int x, p, id;   } Q[N];   inline long long read() {     long long x = 0, f = 0;     char ch;     while (((ch = getchar()) <  0  || ch >  9 ) && (ch !=  - ))       ;     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   inline bool cmp(Node a, Node b) { return a.p != b.p ? a.p < b.p : a.x > b.x; }   signed main() {     n = read();     len = sqrt(n);     for (long long i = 1; i <= n; i++) a[i] = read();     m = read();     for (int i = 1; i <= m; i++) {       long long x, p;       x = read(), p = read();       Q[i].x = x, Q[i].p = p;       Q[i].id = i;     }     sort(Q + 1, Q + m + 1, cmp);     int last = n;     for (int i = 1; i <= m; i++) {       long long ans = 0;       if (Q[i].p >= len) {         for (int j = Q[i].x; j <= n; j += Q[i].p) {           ans += a[j];         }       } else {         int p = Q[i].p, x = Q[i].x;         if (Q[i].p != Q[i - 1].p) last = n;         for (int j = last; j >= x; j--) {           sum[j] = a[j];           if (j + p <= n) sum[j] += sum[j + p];         }         last = x - 1;         ans = sum[x];       }       res[Q[i].id] = ans;     }     for (int i = 1; i <= m; i++) printf( %lld n , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 200010;   char str[MAXN + 1], S[MAXN + 1];   int main() {     scanf( %s , str + 1);     int N = strlen(str + 1);     for (int i = 0; i <= N; i++)       for (char c =  a ; c <=  z ; c++) {         int top = 0;         for (int j = 1; j <= i; j++) S[++top] = str[j];         S[++top] = c;         for (int j = i + 1; j <= N; j++) S[++top] = str[j];         bool flag = 1;         for (int j = 1; j <= top; j++)           if (S[j] != S[top - j + 1]) {             flag = 0;             break;           }         if (flag) {           for (int j = 1; j <= top; j++) printf( %c , S[j]);           printf(  n );           return 0;         }       }     printf( NA n );     return 0;   }