malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int sum[1111], cnt, po[1111], Sum[1111];   char s[1111][1111], ss[1111][1111];   int a[1111];   int find(char *s) {     if (mp[s]) return mp[s];     mp[s] = ++cnt;     strcpy(ss[cnt], s);     return cnt;   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       int mx = -1000000000;       for (int i = 1; i <= n; i++) {         scanf( %s%d , s[i], &a[i]);         int id = find(s[i]);         sum[id] += a[i];       }       for (int i = 1; i <= cnt; i++) mx = max(mx, sum[i]);       for (int i = 1; i <= n; i++) {         int id = find(s[i]);         Sum[id] += a[i];         if (Sum[id] >= mx && sum[id] >= mx) {           puts(s[i]);           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int limit = 320;   int v[100000];   int dp[limit][100000];   int n;   static int bruteforce(int p, int k) {     int cnt = 0;     while (p < n) {       cnt++;       p = p + v[p] + k;     }     return cnt;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> v[i];     for (int j = 1; j < limit; j++) {       for (int i = n - 1; i >= 0; i--) {         if (i + j + v[i] >= n)           dp[j][i] = 1;         else           dp[j][i] = 1 + dp[j][i + j + v[i]];       }     }     int q;     cin >> q;     for (int i = 0, p, k; i < q; ++i) {       cin >> p >> k;       --p;       if (k < limit)         cout << dp[k][p] <<   n ;       else         cout << bruteforce(p, k) <<   n ;     }   }
#include <bits/stdc++.h>   const int inf = 0x3f3f3f;   const long long INF = 1ll << 61;   using namespace std;   int n, x;   typedef struct Node {     int t, h, m;   };   Node aa[2000 + 55], bb[2000 + 55];   void init() {     memset(aa, 0, sizeof(aa));     memset(bb, 0, sizeof(bb));   }   int cnt1, cnt2;   bool input() {     while (cin >> n >> x) {       cnt1 = cnt2 = 0;       for (int i = 0; i < n; i++) {         int t;         scanf( %d , &aa[i].t);         scanf( %d %d , &aa[i].h, &aa[i].m);         bb[i].t = aa[i].t, bb[i].h = aa[i].h, bb[i].m = aa[i].m;       }       return false;     }     return true;   }   bool cmp1(Node x, Node y) { return x.m > y.m; }   void cal() {     sort(aa, aa + n, cmp1);     sort(bb, bb + n, cmp1);     int ans1 = 0;     int now = 0;     int tx = x;     for (int i = 0; i < n; i++) {       if (aa[i].t == now && tx >= aa[i].h) {         now = 1 - now;         tx += aa[i].m;         ans1++;         aa[i].t = -1;         i = -1;       }     }     int ans2 = 0;     now = 1;     for (int i = 0; i < n; i++) {       if (bb[i].t == now && x >= bb[i].h) {         now = 1 - now;         x += bb[i].m;         ans2++;         bb[i].t = -1;         i = -1;       }     }     int ans = max(ans1, ans2);     cout << ans << endl;   }   void output() {}   int main() {     while (true) {       init();       if (input()) return 0;       cal();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<long long int, long long int> m;     long long int a, x, n, o, i, j;     long long int sum = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a >> x;       m[a] = max(m[a], x);     }     cin >> o;     for (i = 0; i < o; i++) {       cin >> a >> x;       m[a] = max(m[a], x);     }     map<long long int, long long int>::iterator it = m.begin();     for (it; it != m.end(); it++) {       sum += it->second;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int PI = 3.141592653589793;   const int inf = 1000111222;   const int mod = 1000000007;   const int N = 200007;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     int len = a.second - a.first + 1;     int len2 = b.second - b.first + 1;     if (len == len2) return a.first < b.first;     return (len > len2);   }   void solve() {     int n;     cin >> n;     int ar[n + 7];     set<pair<int, int>, bool (*)(const pair<int, int> &, const pair<int, int> &)>         S(&comp);     S.insert({1, n});     int cnt = 0;     while (!S.empty()) {       auto it = S.begin();       int l = it->first, r = it->second;       S.erase(it);       int len = r - l + 1;       int mid = 0;       if (len & 1) {         mid = (l + r) / 2;       } else {         mid = (l + r - 1) / 2;       }       ++cnt;       ar[mid] = cnt;       if (len == 1) continue;       if (mid > l) S.insert({l, mid - 1});       if (mid < r) S.insert({mid + 1, r});     }     for (int i = 1; i <= n; i++) {       cout << ar[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int cnt = 1, T[N * 31][2], n;   long long t, a[N * 31];   void insert(long long x) {     int u = 0;     for (int i = 30; i >= 0; i--) {       int v = (x >> i) & 1;       if (!T[u][v]) {         memset(T[cnt], 0, sizeof(T[cnt]));         a[cnt] = 0;         T[u][v] = cnt++;       }       u = T[u][v];     }     a[u] = x;   }   long long dfs(int p, int k) {     if (!T[p][0] && !T[p][1]) return 0;     if (!T[p][0]) return dfs(T[p][1], k - 1);     if (!T[p][1]) return dfs(T[p][0], k - 1);     return (1LL << k) + min(dfs(T[p][0], k - 1), dfs(T[p][1], k - 1));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &t);       insert(t);     }     printf( %lld n , dfs(0, 30));     return 0;   }
#include <bits/stdc++.h>   long long gcdfun(long long x, long long y) {     if (y == 0)       return x;     else       return gcdfun(y, x % y);   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, k = 1, flag = 0, ans = 0;       cin >> n;       vector<int> a(n), b(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.begin(), a.end());       int p = *max_element(a.begin(), a.end());       while (k <= 1024) {         flag = 0;         for (int i = 0; i < n; i++) {           b[i] = (a[i] ^ k);         }         sort(b.begin(), b.end());         for (int i = 0; i < n; i++) {           if (a[i] != b[i]) {             flag = 1;             break;           }         }         if (flag == 1)           k++;         else {           cout << k <<   n ;           ans = 1;           break;         }       }       if (ans == 0) cout << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   double tick() {     static clock_t oldt, newt = clock();     double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;     oldt = newt;     return diff;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a[4][4] = {0};     long long k;     cin >> k;     char c;     std::map<long long, long long> mp;     for (long long i = 0LL; i < (4); i++)       for (long long j = 0LL; j < (4); j++) {         cin >> c;         if (c !=  . ) mp[c -  0 ]++;       }     bool flag = true;     for (auto a : mp)       if (a.second > (2 * k)) {         flag = false;         break;       }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     string d;     cin >> d;     bool f = true;     for (int i = 0; i < d.size(); i++) {       if (d[i] ==  0 ) {         d.erase(i, 1);         f = false;         break;       }     }     if (f) {       d.erase(0, 1);     }     cout << d << endl;     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } p[111];   int g[1111][1111];   int vis[1111];   int n;   void dfs(int u) {     vis[u] = 1;     int i;     for (i = 0; i < n; i++) {       if (g[u][i] && !vis[i]) {         dfs(i);       }     }   }   int main() {     cin >> n;     int i, j;     memset(g, 0, sizeof(g));     for (i = 0; i < n; i++) {       cin >> p[i].x >> p[i].y;     }     int ans = 0;     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         if (p[i].x == p[j].x || p[i].y == p[j].y) {           g[i][j] = g[j][i] = 1;         }       }     }     for (i = 0; i < n; i++) {       if (!vis[i]) {         dfs(i);         ans++;       }     }     cout << ans - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, R, RP[70];   int T, nm = 1, o;   int GCD(int a, int b) { return !a ? b : GCD(b % a, a); }   void BT(int a) {     if (a == 62) {       if (o == 0) return;       if (o % 2 == 0)         RP[nm]--;       else         RP[nm]++;       return;     }     BT(a + 1);     int ls = nm;     nm = (nm * a) / GCD(nm, a);     o++;     if (nm <= 62) BT(a + 1);     nm = ls;     o--;   }   long long powe(long long a, int b) {     long long res = 1;     for (; b; b /= 2) {       if (b % 2) res *= a;       a *= a;     }     return res;   }   long long gen(long long k) {     long long t = powl(n, 1. / k) - 0.5;     return t + (powl(t + 1, k) - 0.5 <= n);   }   int main() {     cin >> T;     BT(2);     for (int i = 0; i < T; i++) {       cin >> n;       R = 0;       for (int j = 2; j <= 62; j++) R += RP[j] * (gen(j) - 1LL);       cout << n - R - 1 << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( 03 )   using namespace std;   int n, m, q, x[200100], y[200100], dad[400100];   bool viz[400100];   int find(int p) {     if (dad[p] == p) return p;     return dad[p] = find(dad[p]);   }   void join(int a, int b) { dad[find(a)] = find(b); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m >> q;     for (int i = 1; i <= n + m; i++) dad[i] = i;     for (int i = 1; i <= q; i++) cin >> x[i] >> y[i];     for (int i = 1; i <= q; i++) join(x[i], y[i] + n);     int rs = 0;     for (int i = 1; i <= n + m; i++) {       int p = find(i);       if (!viz[p]) rs++;       viz[p]++;     }     cout << rs - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[110], n, sum = 0, i;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n - 1; i++) {       if (a[i] == a[i + 1]) {         sum++;         i++;       }     }     printf( %d n , sum / 2);     return 0;   }
#include <bits/stdc++.h>   const int N = 1e3 + 5;   int n, m, q, sum[N][N];   int opt(int x, int y) {     return (__builtin_popcount(x) + __builtin_popcount(y)) & 1;   }   int calc(int x, int y, int opt) {     return opt == 0 ? sum[x][y] : x * y - sum[x][y];   }   long long I(int x, int y, int r, int c) {     long long ans = 1LL * r * c / 2 * n * m;     if ((r & 1) && (c & 1)) ans += calc(n, m, opt(r - 1, c - 1));     return ans;   }   long long D(int x, int y, int r, int c) {     int xx = r * n;     long long ans = 1LL * c / 2 * (x - xx) * m;     if (c & 1) ans += calc(x - xx, m, opt(r, c - 1));     return ans;   }   long long R(int x, int y, int r, int c) {     int yy = c * m;     long long ans = 1LL * r / 2 * n * (y - yy);     if (r & 1) ans += calc(n, y - yy, opt(r - 1, c));     return ans;   }   long long O(int x, int y, int r, int c) {     int xx = r * n, yy = c * m;     return calc(x - xx, y - yy, opt(r, c));   }   long long query(int x, int y) {     if (x == 0 || y == 0) return 0;     int r = (x - 1) / n, c = (y - 1) / m;     if (r == 0 && c == 0) return O(x, y, r, c);     if (r == 0) return D(x, y, r, c) + O(x, y, r, c);     if (c == 0) return R(x, y, r, c) + O(x, y, r, c);     return I(x, y, r, c) + D(x, y, r, c) + R(x, y, r, c) + O(x, y, r, c);   }   long long query(int x1, int y1, int x2, int y2) {     return query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) +            query(x1 - 1, y1 - 1);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x;         scanf( %1d , &x);         sum[i][j] = x + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];       }     }     for (int i = 1; i <= q; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       printf( %lld n , query(x1, y1, x2, y2));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int c = 0, r, d, a, s;       a = n;       while (n) {         if (n >= 10) {           r = n / 10;           n -= r * 10;           n += r;           c += r * 10;         } else {           c += n;           n /= 10;         }       }       cout << c << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string tolower(string str) {     for (int i = 0; i < str.size(); i++) str[i] = tolower(str[i]);     return str;   }   int main() {     int n;     cin >> n;     vector<string> store;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       store.push_back(tolower(str));     }     string str, temp, ans =   ;     cin >> temp;     vector<int> color(temp.size());     str = tolower(temp);     char letter;     cin >> letter;     for (int i = 0; i < str.size(); i++) {       for (int j = 0; j < store.size(); j++) {         string& here = store[j];         if (i + here.size() <= str.size()) {           string substr = str.substr(i, here.size());           if (substr == here) {             for (int k = i; k < i + here.size(); k++) color[k] = 1;           }         }       }     }     char second = (letter ==  a ) ?  b  :  a ;     for (int i = 0; i < str.size(); i++) {       if (color[i])         ans += (str[i] == letter) ? second : letter;       else         ans += str[i];       if (isupper(temp[i])) ans[i] = toupper(ans[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   int x[200010], s1, s2, n;   bool check(int lim) {     int l = -2147483647;     int r = 2147483647;     for (int i = n; i >= 1; i--) {       if (x[i] >= l && x[i] <= r) {         l = x[i] - lim;         r = x[i] + lim;       } else {         l = std::max(l, x[i] - lim);         r = std::min(r, x[i] + lim);       }     }     return (l <= s1 && s1 <= r) || (l <= s2 && s2 <= r);   }   int main() {     n = inp();     s1 = inp();     s2 = inp();     int l = abs(s1 - s2);     int r = 1e9;     for (int i = 1; i <= n; i++) {       x[i] = inp();       if (x[i] == x[i - 1]) {         i--;         n--;       }     }     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , l);   }
#include <bits/stdc++.h>   using namespace std;   int dp[55][35555], n, m, a[35555], las[35555], pre[35555], now;   struct LT {     int mx, lazy;   } tr[517171];   void U(int x) { tr[x].mx = max(tr[x << 1].mx, tr[x << 1 | 1].mx); }   void D(int x) {     tr[x << 1].lazy += tr[x].lazy;     tr[x << 1].mx += tr[x].lazy;     tr[x << 1 | 1].lazy += tr[x].lazy;     tr[x << 1 | 1].mx += tr[x].lazy;     tr[x].lazy = 0;     U(x);   }   void rebuild(int x, int l, int r) {     tr[x].lazy = 0;     if (l == r) {       tr[x].mx = dp[now][l - 1];       return;     }     int mid = (l + r) >> 1;     rebuild(x << 1, l, mid);     rebuild(x << 1 | 1, mid + 1, r);     U(x);   }   void C(int x, int l, int r, int st, int en) {     if (l == st && r == en) {       tr[x].mx++;       tr[x].lazy++;       return;     }     D(x);     int mid = (l + r) >> 1;     if (st <= mid) C(x << 1, l, mid, st, min(en, mid));     if (en > mid) C(x << 1 | 1, mid + 1, r, max(st, mid + 1), en);     U(x);   }   int Q(int x, int l, int r, int st, int en) {     if (l == st && r == en) {       return tr[x].mx;     }     D(x);     int t = 0, mid = (l + r) >> 1;     if (st <= mid) t = max(t, Q(x << 1, l, mid, st, min(en, mid)));     if (en > mid) t = max(t, Q(x << 1 | 1, mid + 1, r, max(st, mid + 1), en));     return t;   }   int main() {     scanf( %d%d , &n, &m);     memset(las, 0, sizeof(las));     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       pre[i] = las[a[i]];       las[a[i]] = i;     }     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= m; i++) {       now = i - 1;       rebuild(1, 1, n);       for (int j = 1; j <= n; j++) {         C(1, 1, n, pre[j] + 1, j);         dp[i][j] = Q(1, 1, n, 1, j);       }     }     printf( %d , dp[m][n]);   }
#include <bits/stdc++.h>   using namespace std;   string s;   map<string, bool> vis;   void ReadCube(string cube) {     int _4D[4][6] = {{0, 1, 2, 3, 4, 5},                      {0, 3, 2, 1, 5, 4},                      {0, 5, 2, 4, 1, 3},                      {0, 4, 2, 5, 3, 1}};     for (int i = 0; i < 4; ++i) {       string x(6,    );       for (int j = 0; j < 6; ++j) {         x[j] = cube[_4D[i][j]];       }       vis[x] = true;     }   }   void rotate90() {     swap(s[0], s[1]);     swap(s[1], s[2]);     swap(s[2], s[3]);     ReadCube(s);   }   void Left(string c) {     int p[] = {5, 1, 4, 3, 0, 2};     string x(6,    );     for (int i = 0; i < 6; ++i) {       x[i] = c[p[i]];     }     ReadCube(x);   }   void Right(string c) {     int p[] = {4, 1, 5, 3, 2, 0};     string x(6,    );     for (int i = 0; i < 6; ++i) {       x[i] = c[p[i]];     }     ReadCube(x);   }   int main() {     cin >> s;     int ans = 0;     sort(s.begin(), s.end());     do {       if (vis[s]) continue;       for (int i = 0; i < 4; ++i) {         rotate90();       }       Left(s);       Right(s);       ans++;     } while (next_permutation(s.begin(), s.end()));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;       #define MAXN (int)(1e5 + 5)   #define MAXL 20   #define F first   #define S second   #define endl   n    #define MOD (lli)(1e9 + 9)   #define MOD2 (lli)(1e9 + 7)   #define lli long long int   #define sz(a) int(a.size())   #define DEBUG if (0) cout <<  aqui  << endl;   #define PI 2 * acos(0.0)   typedef pair<int, lli> ii;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};      int t;      int main(){     ios_base::sync_with_stdio(false);     cin.tie(NULL);        cin >> t;        while(t--) {       int k, n, m;       cin >> k >> n >> m;       vector<int> vec, vec2;          for(int i=0;i<n;i++) {         int a;         cin >> a;         vec.push_back(a);       }          for(int i=0;i<m;i++) {         int a;         cin >> a;         vec2.push_back(a);       }          vector<int> ans;       int a = 0, b = 0;       bool nono = false;       while(a < sz(vec) or b < sz(vec2)) {         bool at = false;            if(b < sz(vec2)) {           if(!vec2[b] or (a < sz(vec) && vec2[b] < vec[a])) at = true;         }            if(!at && a < sz(vec)) {           ans.push_back(vec[a]);           a++;         } else if(b < sz(vec2)) {           ans.push_back(vec2[b]);           b++;         }       }          int atual = k;       for(auto i : ans) {         if(!i) atual++;         else if(i > atual) nono = true;       }             if(nono) {         cout << -1 << endl;         continue;       }          for(auto i : ans) cout << i <<    ;       cout << endl;        }           return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   long long I[100][100], temp[100][100], M[100][100], store[100][100];   void copyM(long long M1[][100], long long M2[][100], int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         M2[i][j] = M1[i][j];       }     }   }   void matmul(long long M1[][100], long long M2[][100], int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         temp[i][j] = 0;         for (int k = 0; k < m; ++k)           temp[i][j] = (temp[i][j] + (M2[i][k] * M1[k][j]) % mod) % mod;       }     }   }   void setI(int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         if (i != j)           I[i][j] = 0;         else           I[i][j] = 1;       }     }   }   void powerM(long long M1[][100], int m, long long n) {     setI(m);     while (n > 0) {       if (n % 2 == 0) {         matmul(M1, M1, m);         copyM(temp, M1, m);         n /= 2;       } else {         matmul(M1, I, m);         copyM(temp, I, m);         n -= 1;       }     }   }   long long t[105];   int main() {     int n, b, k, x;     scanf( %d%d%d%d , &n, &b, &k, &x);     memset(M, 0, sizeof(M));     for (int i = 0; i < n; ++i) {       int p;       scanf( %d , &p);       p %= x;       t[p]++;     }     for (int i = 0; i < x; ++i)       for (int j = 0; j < x; ++j) {         M[i][(i * 10 + j) % x] += t[j];       }     powerM(M, x, b);     printf( %lld n , I[0][k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int n;     cin >> n;     vector<long long> l(n + 1), t(n + 1);     l[0] = 0;     t[0] = 0;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       l[i] = l[i - 1];       t[i] = t[i - 1];       if (c ==  L )         l[i]--;       else if (c ==  R )         l[i]++;       else if (c ==  U )         t[i]++;       else         t[i]--;     }     long long low = 0;     long long high = 1000000000LL * 1000000000LL * 4;     long long mid;     while (low < high) {       mid = (low + high) / 2;       long long tempx = (mid / n) * l[n] + l[mid % n];       long long tempy = (mid / n) * t[n] + t[mid % n];       if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid) {         high = mid;       } else {         low = mid + 1;       }     }     mid = low;     long long tempx = (mid / n) * l[n] + l[mid % n];     long long tempy = (mid / n) * t[n] + t[mid % n];     if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid)       cout << mid << endl;     else       cout << -1 << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1200031;   int n, ar[N], w[N];   int gcd(int a, int b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   vector<pair<int, int> > edges;   vector<int> entries[N];   int sz[N];   long long ANS[N];   vector<int> interesting;   long long cur_pairs;   void run_cleanup() {     for (int i = 0; i < interesting.size(); i++) {       int id = interesting[i];       sz[id] = 1;       w[id] = id;     }   }   int get(int x) {     interesting.push_back(x);     if (x == w[x]) return x;     return w[x] = get(w[x]);   }   long long F(int x) { return 1ll * x * (x - 1) / 2; }   void merge(int a, int b) {     a = get(a);     b = get(b);     if (a == b) return;     cur_pairs -= F(sz[a]);     cur_pairs -= F(sz[b]);     w[a] = b;     sz[b] += sz[a];     cur_pairs += F(sz[b]);   }   vector<int> divs[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i];     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       edges.push_back(make_pair(a, b));     }     for (int i = 0; i < edges.size(); i++) {       int here = gcd(ar[edges[i].first], ar[edges[i].second]);       entries[here].push_back(i);     }     for (int i = 1; i <= n; i++) {       w[i] = i;       sz[i] = 1;     }     for (int i = 1; i <= 200000; i++) {       interesting.clear();       cur_pairs = 0;       for (int j = i; j <= 200000; j += i) {         for (int q = 0; q < entries[j].size(); q++) {           int id = entries[j][q];           merge(edges[id].first, edges[id].second);         }       }       ANS[i] = cur_pairs;       run_cleanup();     }     for (int i = 1; i <= 200000; i++) {       for (int j = i * 2; j <= 200000; j += i) divs[j].push_back(i);     }     for (int i = 200000; i; --i) {       for (int j = 0; j < divs[i].size(); j++) {         int p = divs[i][j];         ANS[p] -= ANS[i];       }     }     for (int i = 1; i <= n; i++) {       ANS[ar[i]]++;     }     for (int i = 1; i <= 200000; i++) {       if (ANS[i]) cout << i <<     << ANS[i] << endl;     }     return 0;   }