malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     map<char, long long> mp;     for (long long i = 0; i < n; i++) {       char x;       cin >> x;       mp[x]++;     }     vector<pair<long long, char>> v;     for (auto it : mp) {       pair<long long, char> p;       p.first = it.second;       p.second = it.first;       v.push_back(p);     }     sort(v.begin(), v.end(), greater<pair<long long, char>>());     long long ans = 0;     for (long long i = 0; i < v.size() && k > 0; i++) {       long long x = min(k, v[i].first);       ans += (x * x);       k -= x;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[] =  GB ;   int main() {     int n, k, a, b;     scanf( %d%d%d%d , &n, &k, &a, &b);     if (a < b) {       swap(a, b);       swap(s[0], s[1]);     }     int num = (a - 1) / k + 1;     if (b < num - 1) {       puts( NO );       return 0;     }     while (num--) {       int cnt = min(a, k);       a -= cnt;       while (cnt--) {         putchar(s[0]);       }       cnt = 0;       while (cnt < k && b > 0 && b > num - 1) {         putchar(s[1]);         ++cnt;         --b;       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a, b;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &a, &b);       double output;       if (b == 0) {         printf( 1 n );         continue;       } else if (a == 0) {         printf( 0.5 n );         continue;       }       if (a < 4 * b)         output = (double)(a + 8 * b) / 16.0 / b;       else         output = (double)(a - b) / (double)a;       printf( %lf n , output);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, kol = 0;     vector<int> a, b;     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       a.push_back(j);       b.push_back(j);     }     sort(b.begin(), b.end());     for (i = 0; i < n; i++)       if (a[i] != b[i]) kol++;     if (kol == 0 || kol == 2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 200005;   int nn;   int x[MAXN];   long long tt;   long long a[MAXN];   long long mi[MAXN], mx[MAXN];   long long ans[MAXN];   int tag[MAXN];   int main() {     using namespace std;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> nn >> tt;     for (int i = 1; i <= nn; i++) {       cin >> a[i];       mi[i] = a[i] + tt;       mx[i] = (long long)6e18;     }     for (int i = 1; i <= nn; i++) {       cin >> x[i];       if (x[i] < i) {         cout <<  No n ;         return 0;       }       if (x[i] != nn) mx[x[i]] = a[x[i] + 1] + tt - 1;       tag[i]++;       tag[x[i]]--;     }     for (int i = 1; i <= nn; i++) {       tag[i] += tag[i - 1];       if (tag[i] > 0 && i != nn) mi[i] = a[i + 1] + tt;       if (mi[i] > mx[i] || ans[i - 1] + 1 > mx[i]) {         cout <<  No n ;         return 0;       }       ans[i] = max(mi[i], ans[i - 1] + 1);     }     cout <<  Yes n ;     for (int i = 1; i <= nn; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N;   vector<int> E[100000];   bool visit[100000] = {0};   long long component[100000] = {0};   int cN = 0;   stack<int> stk;   void DFS(int s) {     if (visit[s]) return;     visit[s] = true;     stk.push(s);     while (!stk.empty()) {       int v = stk.top();       stk.pop();       component[cN]++;       for (int i = (0); i < (E[v].size()); i++) {         if (visit[E[v][i]]) continue;         visit[E[v][i]] = true;         stk.push(E[v][i]);       }     }     cN++;   }   int main() {     cin >> N;     for (int i = (0); i < (N - 1); i++) {       int a, b;       char w[20];       scanf( %d%d%s , &a, &b, w);       bool islucky = 1;       int len = strlen(w);       for (int i = (0); i < (len); i++) {         if (w[i] ==  4  || w[i] ==  7 )           ;         else           islucky = 0;       }       if (islucky) continue;       E[a - 1].push_back(b - 1);       E[b - 1].push_back(a - 1);     }     for (int i = (0); i < (N); i++) DFS(i);     long long ret = 0;     for (int i = (0); i < (cN); i++) {       ret += component[i] * (N - component[i]) * (N - component[i] - 1);     }     cout << ret << endl;   }
#include<bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   int vis[MAXN*2][MAXN*2],T,n,m,ans;   /*   void dfs(int x,int y,int step,int now){    if(step==n){          if(!vis[x+MAXN][y+MAXN]) ans++,vis[x+MAXN][y+MAXN] = 1;     return;    }    if(now==1){     dfs(x+1,y,step+1,2);     dfs(x-1,y,step+1,2);    }    else if(now==2){     dfs(x,y+1,step+1,1);     dfs(x,y-1,step+1,1);    }    else{     dfs(x+1,y,step+1,2);     dfs(x-1,y,step+1,2);     dfs(x,y+1,step+1,1);     dfs(x,y-1,step+1,1);    }   }   */   int main(){    int aa = -1;     cin>>n;     long long a1 = 3*n*(n+4)+2,a2 = n%2==0?aa*(n*(n + 4)+2):-aa*(n*(n + 4)+2);     cout<<1 + (a1+a2)/8<<endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> q, s;   int n, k;   vector<int> apply(vector<int> &a, vector<int> q) {     vector<int> res(n);     for (int i = 0; i < n; i++) {       res[i] = a[q[i]];     }     return res;   }   vector<int> rev_apply(const vector<int> &a, vector<int> &q) {     vector<int> res(n);     for (int i = 0; i < n; i++) {       res[q[i]] = a[i];     }     return res;   }   int main() {     cin >> n >> k;     q = vector<int>(n);     s = vector<int>(n);     for (int i = 0; i < n; i++) {       cin >> q[i];       q[i]--;     }     for (int i = 0; i < n; i++) {       cin >> s[i];       s[i]--;     }     vector<int> a(n), b, c;     for (int i = 0; i < n; i++) {       a[i] = i;     }     if (a == s) {       cout <<  NO  << endl;       return 0;     }     b = apply(a, q);     c = rev_apply(a, q);     if (b == s && c == s) {       if (k == 1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }       return 0;     }     b = a;     c = a;     int min_b = -1, min_c = -1;     for (int i = 0; i < k; i++) {       b = apply(b, q);       c = rev_apply(c, q);       if (b == s && min_b == -1) {         min_b = i + 1;       }       if (c == s && min_c == -1) {         min_c = i + 1;       }     }     if (min_b >= 0 && min_b % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     if (min_c >= 0 && min_c % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long sz = 3e5 + 10;   long long ara[sz], pos[sz], other[sz], mn[sz];   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &ara[i]);       pos[ara[i]] = i;     }     for (long long i = 1; i <= n; ++i) other[i] = mn[i] = n + 1;     for (long long i = 1; i <= m; ++i) {       long long p1, p2;       scanf( %lld , &p1), scanf( %lld , &p2);       if (pos[p1] > pos[p2]) swap(p1, p2);       other[pos[p1]] = min(other[pos[p1]], pos[p2]);     }     mn[n + 1] = n + 1;     for (long long i = n; i >= 1; --i) mn[i] = min(mn[i + 1], other[i]);     long long ans = 0;     for (long long i = 1; i <= n; ++i) ans += (mn[i] - i);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       vector<char> v[2];       for (int i = 0; i < s.size(); i++) v[s[i] % 2].push_back(s[i]);       int p1, p2;       for (p1 = 0, p2 = 0; p1 < v[0].size() && p2 < v[1].size();) {         if (v[0][p1] < v[1][p2])           cout << v[0][p1++];         else           cout << v[1][p2++];       }       while (p1 < v[0].size()) cout << v[0][p1++];       while (p2 < v[1].size()) cout << v[1][p2++];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, temp;     cin >> n >> k;     int arr[n], sum[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       if (arr[i] == 0)         sum[i] = 0;       else         sum[i] = sum[arr[i] - 1];       temp = i > k ? k : i;       temp += i + k < n ? k : (n - i - 1);       temp++;       if (arr[i] + k > i - k && arr[i] != 0) {         if (arr[i] + k > n)           temp = 0;         else if (i - k < 0)           temp -= arr[i] + k;         else           temp -= arr[i] + k - i + k;       }       sum[i] += temp;       cout << sum[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   pair<long long, char> s[MAXN], t[MAXN];   int nxt[MAXN];   void kmp(pair<long long, char> str[], int len) {     memset(nxt, -1, sizeof(nxt));     for (int i = 0; i < len - 1; i++) {       int p = nxt[i];       while (p != -1 && str[i + 1] != str[p + 1]) p = nxt[p];       nxt[i + 1] = p + (str[i + 1] == str[p + 1]);     }   }   long long solve(pair<long long, char> s[], int lens, pair<long long, char> t[],                   int lent) {     long long res = 0;     kmp(t, lent);     int p = -1;     if (lent == 0 && s[0].second == t[0].second && s[0].first >= t[0].first &&         s[-1].second == t[-1].second && s[-1].first >= t[-1].first)       res++;     for (int i = 0; i < lens; i++) {       while (p != -1 && s[i] != t[p + 1]) p = nxt[p];       if (p + 1 < lent && s[i] == t[p + 1]) p++;       if (p == lent - 1) {         if (s[i + 1].second == t[p + 1].second &&             s[i + 1].first >= t[p + 1].first &&             s[i - p - 1].second == t[-1].second &&             s[i - p - 1].first >= t[-1].first)           res++;         p = nxt[p];       }     }     return res;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     long long l;     char c[5];     for (int i = 0; i < n; i++) {       scanf( %I64d-%s , &l, c);       s[i] = make_pair(l, *c);     }     for (int i = 0; i < m; i++) {       scanf( %I64d-%s , &l, c);       t[i] = make_pair(l, *c);     }     int now = 0;     for (int i = 0; i + 1 < n; i++) {       if (s[i + 1].second == s[now].second)         s[now].first += s[i + 1].first;       else         s[++now] = s[i + 1];     }     n = now + 1;     now = 0;     for (int i = 0; i + 1 < m; i++) {       if (t[i + 1].second == t[now].second)         t[now].first += t[i + 1].first;       else         t[++now] = t[i + 1];     }     m = now + 1;     if (m == 1) {       long long res = 0;       for (int i = 0; i < n; i++)         if (s[i].second == t[0].second)           res += max(0LL, s[i].first - t[0].first + 1);       return 0 * printf( %I64d , res);     }     printf( %I64d , solve(s + 1, n - 2, t + 1, m - 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const unsigned long long p = 31;   const unsigned long long m = 1e9 + 7;   bool compare(string a, string b) {     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int n = a.length();     unsigned long long hash_a = 0, hash_b = 0;     unsigned long long p_pow = 1;     for (int i = 0; i < n; i++) {       hash_a = (hash_a + (a[i] -  a  + 1) * p_pow) % m;       hash_b = (hash_b + (b[i] -  a  + 1) * p_pow) % m;       p_pow = (p_pow * p) % m;     }     if (hash_a == hash_b) return true;     return false;   }   bool check(string a, string b) {     int blen = b.length();     int alen = a.length();     for (int i = 0; i + blen - 1 < alen; i++) {       string aux = a.substr(i, blen);       if (compare(b, aux)) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string a, b;       cin >> a >> b;       if (a.length() > b.length())         cout <<  NO  <<   n ;       else if (check(b, a))         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100001, BAR = 500, MOD = 1000000007;   int fac[N], inv[N];   int powMod(int a, int n) {     int ret = 1;     while (n) {       if (n & 1) {         ret = (long long)ret * a % MOD;       }       a = (long long)a * a % MOD;       n >>= 1;     }     return ret;   }   int binom(int n, int m) {     return (long long)fac[n] * inv[m] % MOD * inv[n - m] % MOD;   }   int m;   char s[N];   int ans[N];   void prepare(int l) {     int base = 1;     for (int i = 0; i < N; ++i) {       ans[i] = i < l ? 0 : (long long)binom(i - 1, l - 1) * base % MOD;       if (i >= l) {         base = (long long)base * 25 % MOD;       }     }     for (int i = 0; i < N; ++i) {       if (ans[i] >= MOD) {         ans[i] -= MOD;       }       if (i + 1 < N) {         ans[i + 1] += (long long)ans[i] * 26 % MOD;       }     }   }   int main() {     fac[0] = 1;     for (int i = 1; i < N; ++i) {       fac[i] = (long long)fac[i - 1] * i % MOD;     }     inv[N - 1] = powMod(fac[N - 1], MOD - 2);     assert((long long)inv[N - 1] * fac[N - 1] % MOD == 1);     for (int i = N - 2; i >= 0; --i) {       inv[i] = (long long)inv[i + 1] * (i + 1) % MOD;     }     scanf( %d , &m);     scanf( %s , s);     int len = strlen(s);     if (len > BAR) {       prepare(len);     }     while (m--) {       int op;       scanf( %d , &op);       if (op == 1) {         scanf( %s , s);         len = strlen(s);         if (len > BAR) {           prepare(len);         }       } else {         int n;         scanf( %d , &n);         if (len > BAR) {           printf( %d n , ans[n]);         } else {           if (n < len) {             printf( 0 n );           } else {             int ans = powMod(26, n);             int base = powMod(25, n - len + 1);             for (int i = len - 1; i >= 0; --i) {               ans -= (long long)binom(n, i) * base % MOD;               if (ans < 0) {                 ans += MOD;               }               base = (long long)base * 25 % MOD;             }             printf( %d n , ans);           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)998244353ll;   const long long MAXN = (long long)3e5 + 10;   const long long INF = (long long)2242545357980376863;   const long double EPS = (long double)1e-8;   long long source[MAXN], d0[MAXN], dis[MAXN], done[MAXN], par[MAXN];   vector<long long> C[MAXN];   vector<pair<long long, long long> > G[MAXN];   vector<pair<long long, pair<long long, long long> > > E;   set<pair<long long, long long> > dj;   void change_key(long long node, long long last, long long now) {     dj.erase({last, node});     dis[node] = now;     dj.insert({now, node});     return;   }   long long A[MAXN], B[MAXN], ans[MAXN];   long long W;   long long get_par(long long u) {     if (par[u] == u) return u;     return par[u] = get_par(par[u]);   }   bool merge(long long u, long long v) {     long long U = u, V = v;     u = get_par(u);     v = get_par(v);     if (u == v) return false;     if (C[u].size() < C[v].size()) swap(u, v);     par[v] = u;     for (auto x : C[v]) {       C[u].push_back(x);       if (get_par(A[x]) == get_par(B[x])) ans[x] = min(ans[x], W);     }     C[v].clear();     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(ans, 31, sizeof ans);     for (int i = 0; i < MAXN; i++) par[i] = i;     memset(dis, 31, sizeof dis);     memset(d0, 31, sizeof d0);     long long n, m, k, q;     scanf( %lld%lld%lld%lld , &n, &m, &k, &q);     long long u, v, w;     for (int i = 0; i < m; i++) {       scanf( %lld%lld%lld , &u, &v, &w);       G[u].push_back({v, w});       G[v].push_back({u, w});     }     long long p, f;     for (int i = 1; i <= k; i++) {       p = i;       source[p] = p;       dj.insert({0, p});       dis[p] = 0;     }     long long fr, d, adj;     while (dj.size()) {       d = (*dj.begin()).first;       fr = (*dj.begin()).second;       dj.erase(dj.begin());       for (auto edge : G[fr]) {         adj = edge.first;         w = edge.second;         if (done[adj] == 1) {           E.push_back({dis[adj] + dis[fr] + w, {source[fr], source[adj]}});         }         if (dis[adj] > d + w) {           change_key(adj, dis[adj], d + w);           source[adj] = source[fr];         }       }       done[fr] = 1;     }     for (int i = 0; i < q; i++) {       scanf( %lld%lld , A + i, B + i);       C[A[i]].push_back(i);       C[B[i]].push_back(i);     }     sort(E.begin(), E.end());     for (auto edge : E) {       W = edge.first;       if (merge(edge.second.first, edge.second.second)) {       }     }     for (int i = 0; i < q; i++) printf( %lld n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > adj[200001];   int totalIn, totalOut;   int inEdges[200001];   int outEdges[200001];   void dfs(int u, int par, int in, int out) {     inEdges[u] = in;     outEdges[u] = out;     for (pair<int, int> &p : adj[u]) {       int v = p.first;       int type = p.second;       if (v != par) {         if (type == 1) {           dfs(v, u, in, out + 1);           totalOut++;         } else {           dfs(v, u, in + 1, out);           totalIn++;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int s, t;     for (int i = 0; i < n - 1; i++) {       cin >> s >> t;       adj[s].push_back({t, 1});       adj[t].push_back({s, -1});     }     dfs(1, -1, 0, 0);     int in;     vector<int> cities;     int minIn = totalIn;     cities.push_back(1);     for (int i = 2; i <= n; i++) {       in = totalIn - inEdges[i] + outEdges[i];       if (in < minIn) {         minIn = in;         cities.clear();         cities.push_back(i);       } else if (in == minIn) {         cities.push_back(i);       }     }     cout << minIn <<   n ;     for (int &i : cities) cout << i <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, arr[26], s, k, fuck[19], ans;   vector<pair<long long, long long> > v1;   map<pair<long long, long long>, long long> maph;   void rek(long long x, long long r, long long z, long long o, bool p) {     if (x >= r) {       if (!p)         v1.push_back({z, o});       else         maph[{z, o}]++;       return;     }     if (arr[x] + z <= s) rek(x + 1, r, z + arr[x], o, p);     if (o < k and arr[x] <= 18 and z + fuck[arr[x]] <= s)       rek(x + 1, r, z + fuck[arr[x]], o + 1, p);     rek(x + 1, r, z, o, p);   }   int main() {     cin >> n >> k >> s;     fuck[0] = 1;     for (int i = 1; i <= 18; i++) fuck[i] = fuck[i - 1] * i;     for (int i = 0; i < n; i++) cin >> arr[i];     rek(0, n / 2, 0, 0, 0), rek(n / 2, n, 0, 0, 1);     for (int i = 0; i < v1.size(); i++) {       for (int j = 0; j <= k - v1[i].second; j++) {         if (maph.find({s - v1[i].first, j}) != maph.end())           ans += maph[{s - v1[i].first, j}];       }     }     cout << ans;   }
#include <bits/stdc++.h>   int main() {     int n, t, i, j, k, xi, ai, s, y;     int x[1000], a[1000];     scanf( %d%d , &n, &t);     for (i = 0; i < n; i++) {       scanf( %d%d , &xi, &ai);       j = 0;       while ((j < i) && (x[j] < xi)) j++;       for (k = i; k > j; k--) {         x[k] = x[k - 1];         a[k] = a[k - 1];       }       x[j] = xi;       a[j] = ai;     }     s = 2;     for (i = 0; i < n - 1; i++) {       y = (2 * x[i + 1]) - (2 * x[i]) - a[i] - a[i + 1];       if (y == (2 * t))         s++;       else if ((2 * t) < y)         s = s + 2;     }     printf( %d , s);   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt, pos, sz, mx, last, start;   char s[2000005], ans[2000005];   int main() {     scanf( %d , &n);     memset(ans,   000 , sizeof(ans));     for (register int i = 1; i <= n; i++) {       scanf( %s , s);       scanf( %d , &cnt);       sz = strlen(s);       for (register int j = 1; j <= cnt; j++) {         scanf( %d , &pos);         if (j == 1) {           start = 0;         } else {           start = last + sz - pos;           if (start < 0) {             start = 0;           }         }         for (register int k = start; k < sz; k++) {           ans[k + pos] = s[k];         }         last = pos;         mx = max(mx, pos + sz - 1);       }     }     while (ans[mx] ==   000 ) {       mx--;     }     for (register int i = 1; i <= mx; i++) {       if (ans[i] ==   000 ) {         ans[i] =  a ;       }       printf( %c , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       double n;       cin >> n;       double r = 1 / (2 * tan((360 / (4 * n)) * (3.1415926535 / 180)));       cout << setprecision(15) << 2 * r << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0, m = 0, y = 0, w = 0, g = 0, b = 0, d, e;     cin >> d >> e;     char arr[d][e];     for (int i = 0; i < d; i++) {       for (int j = 0; j < e; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  M ) {           m++;         } else if (arr[i][j] ==  C ) {           c++;         } else if (arr[i][j] ==  Y ) {           y++;         } else if (arr[i][j] ==  W ) {           w++;         } else if (arr[i][j] ==  G ) {           g++;         } else if (arr[i][j] ==  B ) {           b++;         }       }     }     if (y == 0 && c == 0 && m == 0) {       cout <<  #Black&White ;     } else {       cout <<  #Color ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000006;   char s[maxn];   int ans[8] = {1869, 8196, 1986, 8691, 6198, 1689, 1968};   int main() {     while (scanf( %s , s) != EOF) {       int len = strlen(s);       int A[10] = {0};       for (int i = 0; i < len; i++) {         A[s[i] -  0 ]++;       }       int m = 0;       for (int i = 1; i < A[1]; i++) {         printf( 1 );         m = (m * 10 + 1) % 7;       }       for (int i = 1; i <= A[2]; i++) {         printf( 2 );         m = (m * 10 + 2) % 7;       }       for (int i = 1; i <= A[3]; i++) {         printf( 3 );         m = (m * 10 + 3) % 7;       }       for (int i = 1; i <= A[4]; i++) {         printf( 4 );         m = (m * 10 + 4) % 7;       }       for (int i = 1; i <= A[5]; i++) {         printf( 5 );         m = (m * 10 + 5) % 7;       }       for (int i = 1; i < A[6]; i++) {         printf( 6 );         m = (m * 10 + 6) % 7;       }       for (int i = 1; i <= A[7]; i++) {         printf( 7 );         m = (m * 10 + 7) % 7;       }       for (int i = 1; i < A[8]; i++) {         printf( 8 );         m = (m * 10 + 8) % 7;       }       for (int i = 1; i < A[9]; i++) {         printf( 9 );         m = (m * 10 + 9) % 7;       }       m = (m * 10000) % 7;       printf( %d , ans[m]);       for (int i = 1; i <= A[0]; i++) printf( 0 );       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long t;     cin >> t;     for (int ti = (int)(0); ti < (int)(t); ti++) {       unsigned long long n;       cin >> n;       if (n % 2) {         unsigned long long tmp = (n + 1u) * n;         unsigned long long res;         if (tmp % (4u * n) == 0) {           res = n;         } else if (tmp % (4u * n) == 2u * n) {           res = n * 2u;         } else {           res = n * 4u;         }         cout << res + 1u << endl;       } else {         cout << n * 4u + 1 << endl;       }     }     return 0;   }