malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int sqr(int x) { return x * x; }   int main() {     int n, m, x, y;     map<int, int> targets;     vector<int> ans, r;     scanf( %d , &n);     ans.assign(n, -1);     r.assign(n, 0);     for (int i = 0; i != n; ++i) {       scanf( %d%d , &x, &r[i]);       targets[x] = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       auto target = targets.lower_bound(x);       if (target != targets.end()) {         if (ans[target->second] == -1 &&             sqr(target->first - x) + sqr(y) <= sqr(r[target->second]))           ans[target->second] = i;       }       if (target != targets.begin()) {         --target;         if (ans[target->second] == -1 &&             sqr(target->first - x) + sqr(y) <= sqr(r[target->second]))           ans[target->second] = i;       }     }     printf( %d n , n - count(ans.begin(), ans.end(), -1));     for (auto itans = ans.begin(); itans != ans.end(); ++itans)       printf( %d  , *itans);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int x0, y0, x, y, n;     int i, j, r, a, b;     set<pair<int, int> > s;     queue<pair<int, pair<int, int> > > q;     cin >> x0 >> y0 >> x >> y >> n;     for (i = 0; i < n; i++) {       cin >> r >> a >> b;       for (j = a; j <= b; j++) s.insert(make_pair(r, j));     }     q.push(make_pair(0, make_pair(x0, y0)));     while (!q.empty()) {       int cr = q.front().first;       int cx = q.front().second.first;       int cy = q.front().second.second;       q.pop();       for (int i = -1; i <= 1; i++)         for (int j = -1; j <= 1; j++) {           if (cx + i == x && cy + j == y) {             cout << cr + 1 << endl;             return 0;           }           if (i == 0 && j == 0) continue;           if (s.count(make_pair(cx + i, cy + j)) > 0) {             q.push(make_pair(cr + 1, make_pair(cx + i, cy + j)));             s.erase(make_pair(cx + i, cy + j));           }         }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e6 + 10, inf = 1e9 + 10;   long long int t, n, ans, a[mx];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       cout << (n + 1) / 10 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[10000];   int n = 0;   void init() {     queue<string> q;     q.push( 4 );     q.push( 7 );     while (!q.empty()) {       string u = q.front();       q.pop();       arr[n++] = stoi(u);       if (u.length() < 9) {         q.push(u +  4 );         q.push(u +  7 );       }     }   }   int main() {     ios_base::sync_with_stdio(false);     init();     int t = 1;     while (t--) {       int k;       cin >> k;       cout << lower_bound(arr, arr + n, k) - arr + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void mod(string &s) {     for (int i = 0; i < (int)s.size(); i++) {       switch (s[i]) {         case  N :           s[i] =  S ;           break;         case  S :           s[i] =  N ;           break;         case  E :           s[i] =  W ;           break;         case  W :           s[i] =  E ;           break;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string a, b;     cin >> a >> b;     n = (int)a.size();     reverse(b.begin(), b.end());     mod(b);     b += a;     vector<int> pref(2 * n, 0);     int i = 1, j = 0;     while (i < 2 * n) {       if (b[j] == b[i]) {         pref[i++] = ++j;       } else {         while (j != 0 && b[j] != b[i]) j = pref[j - 1];         if (b[j] != b[i]) i++;       }     }     if (pref[2 * n - 1])       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct fastio {     char s[100000];     int it, len;     fastio() { it = len = 0; }     inline char get() {       if (it < len) return s[it++];       it = 0;       len = fread(s, 1, 100000, stdin);       if (len == 0)         return EOF;       else         return s[it++];     }     bool notend() {       char c = get();       while (c ==     || c ==   n ) c = get();       if (it > 0) it--;       return c != EOF;     }   } _buff;   inline long long getnum() {     long long r = 0;     bool ng = 0;     char c;     c = _buff.get();     while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get();     if (c ==  - ) ng = 1, c = _buff.get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get();     return ng ? -r : r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline char getreal() {     char c = _buff.get();     while (c <= 32) c = _buff.get();     return c;   }   long long qpow(long long x, long long k) {     return k == 0 ? 1                   : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;   }   const int maxn = 300111;   int n, q;   int a[maxn];   void makev(vector<pair<int, int> > &v) {     sort(v.begin(), v.end());     int c = 0;     vector<pair<int, int> > nv;     for (auto x : v) {       if ((c | x.second) > c) {         c = c | x.second;         nv.push_back(make_pair(x.first, c));       }     }     v = nv;   }   vector<pair<int, int> > v[maxn];   int lst[20];   int main() {     n = getnum(), q = getnum();     for (int i = 1; i <= n; i++) a[i] = getnum();     for (int i = n; i >= 1; i--) {       vector<pair<int, int> > &cur = v[i];       cur.push_back(make_pair(i, a[i]));       for (int j = 0; j < 20; j++) {         if ((a[i] >> j) & 1) {           if (lst[j]) {             for (auto x : v[lst[j]]) cur.push_back(x);           }           lst[j] = i;         }       }       makev(cur);     }     for (int i = 1; i <= q; i++) {       int x, y;       x = getnum(), y = getnum();       bool ok = false;       for (auto t : v[x]) {         ok |= t.first <= y && ((t.second & a[y]) > 0);       }       puts(ok ?  Shi  :  Fou );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> piles(n);     vector<pair<int, int>> cost(n);     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       piles[i] = tmp;       int closest = int(sqrt(tmp) + 0.5f);       cost[i] = pair<int, int>(abs(tmp - closest * closest), tmp);     }     sort(cost.begin(), cost.end());     unsigned long long result = 0;     for (int i = 0; i < n; i++) {       int _cost = cost[i].first;       int _number = cost[i].second;       if (i < n / 2) {         result += _cost;       } else {         if (_cost == 0) result++;         if (_number == 0) result++;       }     }     printf( %llu n , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(int a, int b) {     bool dig[10] = {0};     while (a > 0) {       dig[a % 10] = true;       a /= 10;     }     while (b > 0) {       if (dig[b % 10]) {         return true;       }       b /= 10;     }     return false;   }   int main() {     int a;     cin >> a;     int i, s = 0;     for (i = 1; i * i <= a; i++) {       if (a % i == 0) {         if (check(a, i)) {           s++;         }         if (i != a / i && check(a, a / i)) {           s++;         }       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       int c = 0;       std::vector<int> v;       string s[3];       getline(cin, s[0]);       getline(cin, s[1]);       getline(cin, s[2]);       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= s[i].length() - 1; j++) {           if (s[i][j] ==  a  || s[i][j] ==  e  || s[i][j] ==  i  ||               s[i][j] ==  o  || s[i][j] ==  u )             c++;         }         v.push_back(c);         c = 0;       }       if (v[0] == 5 && v[1] == 7 && v[2] == 5) {         cout <<  YES ;       } else {         cout <<  NO ;       }     }     cerr <<  Time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     string s =    ;     sort(b.rbegin(), b.rend());     if (a.size() > b.size())       s = b.substr(0, a.size());     else       s = b;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  9 )         continue;       else if ((a[i] +  0 ) < (s[0] +  0 )) {         a[i] = s[0];         s.erase(0, 1);       }     }     cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, ans =   ;     cin >> s;     int i = 0, j = s.size() - 1;     while (i < j) {       if (s[i] == s[j]) {         i++;         j--;         continue;       } else {         s.insert(s.begin() + j + 1, s[i]);         i++;       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, flag;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     if (n == 2)       cout << a[0] + 2 * (a[1] - a[0]);     else {       for (int i = 0; i < n - 2; i++) {         if ((a[i + 2] - a[i + 1]) != (a[1 + i] - a[i])) {           flag = 0;           break;         } else           flag = 1;       }       if (flag) {         cout << a[0] + (n) * (a[1] - a[0]);       } else         cout << a[n - 1];     }   }
#include <bits/stdc++.h>   using namespace std;   void Read(int &p) {     p = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ;   }   struct ma {     int x, y;     ma(int _x = 0, int _y = 0) : x(_x), y(_y) {}   };   bool operator<(ma a, ma b) { return a.x < b.x; }   priority_queue<ma> q[100005], Q, _q;   int n, m, x, y, z, rot, mi = 1e9, si[100005], nm = 0, be[100005];   int fir[100005], tar[200005], len[200005], nex[200005], cnt;   long long ans1;   void Add(int a, int b, int c) {     ++cnt;     tar[cnt] = b;     len[cnt] = c;     nex[cnt] = fir[a];     fir[a] = cnt;   }   int Dfs(int r, int fa) {     int sz = 1, mx = 0;     for (int i = fir[r]; i; i = nex[i]) {       int v = tar[i];       if (v != fa) {         int sum = Dfs(v, r);         mx = max(mx, sum);         sz += sum;         ans1 += (long long)len[i] * min(sum, n - sum);       }     }     mx = max(mx, n - sz);     if (mx < mi) rot = r, mi = mx;     return sz;   }   void DFS(int x, int fa, int d) {     q[d].push(ma{-x, d});     si[d]++;     be[x] = d;     for (int i = fir[x]; i; i = nex[i])       if (tar[i] != fa) DFS(tar[i], x, d);   }   int work(int u) {     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     ma o;     if (_q.top().y == u) o = _q.top(), _q.pop();     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     u = _q.top().y;     if (o.x) _q.push(o);     return u;   }   int main() {     Read(n);     if (n == 1) {       printf( 0 n1 n );       return 0;     }     for (int i = 1; i < n; i++) {       int u, v, w;       Read(u), Read(v), Read(w);       Add(u, v, w), Add(v, u, w);     }     Dfs(1, 0);     q[0].push(ma{-rot, 0});     _q.push(ma{-rot, 0});     si[0] = 1;     for (int i = fir[rot]; i; i = nex[i]) {       DFS(tar[i], rot, ++nm);       Q.push(ma{si[nm] << 1, nm});       _q.push(ma(q[nm].top().x, nm));     }     printf( %lld n , ans1 << 1);     for (int i = 1; i <= n; i++) {       while (Q.top().x != si[Q.top().y] + q[Q.top().y].size()) Q.pop();       if (be[i] == Q.top().y || Q.top().x < n - i + 1)         m = work(be[i]);       else         m = Q.top().y;       if (i == rot && -q[m].top().x > rot && !q[0].empty() &&           Q.top().x < n - i + 1)         m = 0;       printf( %d  , -q[m].top().x);       q[m].pop();       si[be[i]]--;       if (!q[m].empty()) _q.push(ma(q[m].top().x, m));       Q.push(ma(si[m] + q[m].size(), m));       Q.push(ma(si[be[i]] + q[be[i]].size(), be[i]));     }   }
#include <bits/stdc++.h>   using namespace std;   long long expo(long long base, long long exponent, long long mod) {     long long ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   const long long mod = 998244353;   const long long root = 565042129;   const long long root_1 = 950391366;   const long long root_pw = 1 << 20;   void fft(vector<long long> &a, bool invert) {     long long i, j, n = (long long)a.size();     for (i = 1, j = 0; i < n; ++i) {       long long bit = n >> 1;       for (; j >= bit; bit >>= 1) {         j -= bit;       }       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (long long len = 2; len <= n; len <<= 1) {       long long wlen = invert ? root_1 : root;       for (i = len; i < root_pw; i <<= 1) {         wlen = (wlen * wlen % 998244353);       }       for (i = 0; i < n; i += len) {         long long w = 1;         for (j = 0; j < len / 2; ++j) {           long long u = a[i + j],                     v = (long long)(a[i + j + len / 2] * w % 998244353);           a[i + j] = (u + v + 998244353) % 998244353;           a[i + j + len / 2] = (u - v + 998244353) % 998244353;           w = (w * wlen % 998244353);         }       }     }     if (invert) {       long long nrev = expo(n, 998244353 - 2, 998244353);       for (i = 0; i < n; ++i) {         a[i] = (a[i] * nrev % 998244353);       }     }   }   void multiply(const vector<long long> &a, const vector<long long> &b,                 vector<long long> &res) {     vector<long long> fa(a.begin(), a.end()), fb(b.begin(), b.end());     size_t n = 1;     while (n < max(a.size(), b.size())) n <<= 1;     n <<= 1;     fa.resize(n), fb.resize(n);     fft(fa, false), fft(fb, false);     for (size_t i = 0; i < n; ++i) {       fa[i] *= fb[i];     }     fft(fa, true);     res.resize(n);     for (size_t i = 0; i < n; ++i) {       res[i] = fa[i];     }   }   vector<long long> ans;   signed main() {     long long n, first, k;     vector<long long> pol(1001, 0);     vector<long long> ans(1, 1);     cin >> n >> k;     vector<long long> temp;     for (long long i = 0; i < (long long)n; i++) {       cin >> first;       pol[first] = 1;     }     while (k) {       if (k % 2) {         multiply(ans, pol, ans);         for (long long i = 0; i < (long long)ans.size(); i++) {           if (ans[i])             ans[i] = 1;           else             ans[i] = 0;         }       }       multiply(pol, pol, pol);       for (long long i = 0; i < (long long)pol.size(); i++) {         if (pol[i])           pol[i] = 1;         else           pol[i] = 0;       }       k /= 2;     }     for (long long i = 0; i < (long long)ans.size(); i++) {       if (ans[i]) cout << i <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0;     cin >> n;     int arr[n];     set<int> s;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     for (int i = 1; i < n; i++) {       if (arr[i] == arr[i - 1]) {         c++;         arr[i]++;       } else if (arr[i] < arr[i - 1]) {         while (arr[i] <= arr[i - 1]) {           arr[i]++;           c++;         }       }     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, s = 0;     cin >> a >> b;     while (b > 1) {       if (b > a) swap(a, b);       s += a / b;       a -= (b * (a / b));       if (a < 1) break;     }     s += a;     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod_Expo(long long int x, long long int n, long long int M) {     if (x == 0) return 0;     if (n == 0)       return 1;     else if (n % 2 == 0)       return mod_Expo((x * x) % M, n / 2, M);     else       return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;   }   long long int binaryExponentiation(long long int x, long long int n) {     if (x == 0) return 0;     if (n == 0)       return 1;     else if (n % 2 == 0)       return binaryExponentiation(x * x, n / 2);     else       return x * binaryExponentiation(x * x, (n - 1) / 2);   }   long long int GCD(long long int A, long long int B) {     if (B == 0)       return A;     else       return GCD(B, A % B);   }   bool prime_check(long long int x) {     bool prime = (x >= 2);     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         prime = false;         break;       }     }     return prime;   }   long long int min1(long long int a, long long int b, long long int c) {     vector<long long int> v1, v2, v3;     v1.push_back(b);     v1.push_back(c);     v1.push_back(a);     sort(v1.begin(), v1.end());     return v1[0];   }   long long int min(long long int a, long long int b) {     if (a <= b)       return a;     else       return b;   }   long long int bin_search(long long int x, long long int low, long long int high,                            vector<long long int> v1) {     while (high > low) {       long long int mid = low + (high - low) / 2;       if (v1[mid] > x)         high = mid;       else         low = mid + 1;     }     return high;   }   long long int digitsum(long long int n) {     long long int sum = 0;     while (n != 0) {       sum = sum + n % 10;       n = n / 10;     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, t, f = 0, g = 0, x, y, z, k, a = 0, b = 0, c = 0, q,                                  x1, x2, y1, y2, x3, max2, min1 = 1000000, x4,                                  sum, d, M = 998244353, r, p, sum1 = 0, sum2 = 0,                                  sum3 = 0, sum4, sum5, max1 = 0, sum6;     cin >> t;     while (t--) {       cin >> n;       long long int arr[n], arr1[n];       f = 0;       set<long long int> s;       for (i = 0; i < n; i++) {         cin >> arr[i];         s.insert(arr[i]);         arr1[i] = arr[i];       }       sort(arr1, arr1 + n);       for (i = n - 1; i >= 0; i--) {         if (arr1[i] == arr[n - 1 - i]) {           f++;         }       }       if (f == n) {         if (s.size() < n)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     int a[n][2], maxi = -100;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= 0; j++) {         sum = sum - a[i][j];         sum = sum + a[i][j + 1];         maxi = max(maxi, sum);       }     }     cout << maxi;   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxN = 2e5 + 100;   const long long int maxM = 1e3 + 100;   const long long int mod = 1e9 + 7;   const long long int hmod = 1e16 + 7;   const long double PI = 3.141592653;   const long double eps = 1e-8;   const long long int D = 1379;   const long long int INF = 1e18 + 20;   const long long int Inf = 1e9 + 140;   long long int dp1[maxN];   long long int dp2[maxN];   long long int n, a[maxN];   long long int sum[maxN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long int i = 1; i <= n; i++)       cin >> a[i], sum[i] = sum[i - 1] + a[i];     dp1[n] = sum[n];     dp2[n] = -dp1[n];     for (long long int i = n - 1; i >= 1; i--) {       dp1[i] = max(dp1[i + 1], dp2[i + 1] + sum[i]);       dp2[i] = -dp1[i];     }     cout << dp1[2] << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long heavy;   long long ukupno;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     cin >> s;     heavy = 0;     ukupno = 0;     for (int i = 4; i < s.size(); i++) {       if (s[i] ==  l  && s[i - 1] ==  a  && s[i - 2] ==  t  && s[i - 3] ==  e  &&           s[i - 4] ==  m )         ukupno += heavy;       else if (s[i] ==  y  && s[i - 1] ==  v  && s[i - 2] ==  a  &&                s[i - 3] ==  e  && s[i - 4] ==  h )         heavy++;     }     cout << ukupno;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[93], b[93];     scanf( %d , &n);     int ans = 0;     a[0] = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i - 1] = a[i] - a[i - 1];     }     b[n] = 90 - a[n];     for (int i = 0; i <= n; i++) {       if (b[i] > 15) {         ans = a[i] + 15;         break;       }     }     if (!ans) ans = 90;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x1fffffffffffffff;   const double INFD = 1e20;   const double EPS = 1e-9;   const double PI = atan(1) * 4;   const long long M = 998244353;   long long mod(long long x) { return ((x % M) + M) % M; }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long sub(long long a, long long b) { return mod(mod(a) - mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   long long power(long long b, long long e) {     long long ans = 1;     while (e > 0) {       if (e % 2) ans = mul(ans, b);       b = mul(b, b);       e /= 2;     }     return mod(ans);   }   long long gcd(long long a, long long b) {     for (; b > 0; swap(a, b)) a %= b;     return a;   }   long long extended_euclid(long long a, long long b, long long &x,                             long long &y) {     long long xx = y = 0;     long long yy = x = 1;     while (b) {       long long q = a / b;       long long t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   long long inv(long long a) {     long long x, y;     long long d = extended_euclid(a, M, x, y);     if (d > 1) return -1;     return mod(x);   }   long long scan() {     long long r;     scanf( %lld , &r);     return r;   }   void scanstr(char *buf) { scanf( %s , buf); }   int main() {     long long n = scan();     vector<long long> a(n);     for (long long i = 0; i < n; ++i) {       a[i] = scan();     }     sort(a.begin(), a.end());     vector<long long> pfs(n + 1, 0);     for (long long i = 0; i < n; ++i) pfs[i + 1] = add(pfs[i], a[i]);     long long q_inv = inv(n);     for (long long i = 1; i < n; ++i) {       long long segcount = (i <= n / 2) ? i : (n - i);       long long ballcount = n - i;       long long q = ballcount / segcount;       long long r = ballcount % segcount;       long long ans = mul(q + 1, pfs[r]);       for (long long j = 1; j < q + 1; ++j) {         long long cur = mul(             q + 1 - j, sub(pfs[r + segcount * j], pfs[r + segcount * (j - 1)]));         ans = add(ans, cur);       }       cout << mul(ans, q_inv) << endl;     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[200005];   long long siz = 0;   long long cc = 0;   long long t, n;   long long a[200005];   long long vis[200005];   long long size_dict[200005];   void dfs(long long u) {     vis[u] = cc;     siz += 1;     for (long long i = 0; i < adj[u].size(); i++) {       if (!vis[adj[u][i]]) {         dfs(adj[u][i]);       }     }   }   int main() {     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i <= 200004; i++) {         adj[i].clear();       }       for (long long i = 0; i <= 200004; i++) vis[i] = 0;       for (long long i = 0; i < n; i++) {         cin >> a[i];         adj[i + 1].push_back(a[i]);         adj[a[i]].push_back(i + 1);       }       cc = 0;       for (long long i = 0; i < n; i++) {         if (!vis[i + 1]) {           cc++;           dfs(i + 1);           size_dict[cc] = siz;           siz = 0;         }       }       for (long long i = 1; i <= n; i++) {         cout << size_dict[vis[i]] <<    ;       }       cout <<   n ;     }   }