#include <bits/stdc++.h>   #define debug(a) cout << #a <<  :   << a <<   n    #define debugLine() cout <<  ============== n    #define tick() cout <<  Tick n ;   #define testCases() int t; cin >> t; while(t--)   #define all(a) a.begin(), a.end()   #define fillWith(a, b) memset(a, b, sizeof(a))   #define INF_32 1e9   #define INF_64 1e18   #define Mod 1000000007   #define PI 3.14159265358979323846   #define endl   n    #define goFast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)   typedef long long ll;   using namespace std;      int main()   {       goFast();       testCases()       {           ll n;           cin >> n;           ll arr[n + 3];           ll sum = 0;           for(int i = 0; i < n; i++)           {               cin >> arr[i];               sum += arr[i];           }           cout << (n - sum % n) * (sum % n) << endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int INF = 0x3f3f3f3f;   struct node {     int to, next;   } edge[maxn * 3];   struct Node {     int id;     long long val;     bool operator<(const Node& a) const { return val < a.val; }   };   int head[maxn], cnt, d[maxn], depth[maxn], ans[maxn];   int s[maxn];   void add(int u, int v) {     edge[cnt].to = v;     edge[cnt].next = head[u];     head[u] = cnt++;   }   void dfs(int k, int fa) {     for (int i = head[k]; i != -1; i = edge[i].next) {       int to = edge[i].to;       if (to == fa) continue;       depth[to] = depth[k] + 1;       dfs(to, k);       s[k] += s[to] + 1;     }   }   int main() {     int n, k;     cnt = 0;     memset(head, -1, sizeof(head));     memset(depth, -1, sizeof(depth));     memset(s, 0, sizeof(s));     scanf( %d%d , &n, &k);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);       d[u]++;       d[v]++;     }     depth[1] = 0;     dfs(1, 1);     priority_queue<Node> q;     for (int i = 1; i <= n; i++)       if (d[i] == 1 && i != 1) q.push({i, depth[i]});     long long sum = 0;     while (k && !q.empty()) {       Node top = q.top();       sum += top.val;       q.pop();       k--;       for (int i = head[top.id]; i != -1; i = edge[i].next) {         int to = edge[i].to;         if (depth[to] < depth[top.id]) {           d[to]--;           if (d[to] == 1) q.push({to, depth[to] - s[to]});           break;         }       }     }     printf( %lld n , sum);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void in(T &x) {     x = 0;     bool f = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     if (f) x = -x;   }   long long n, m;   void print(long long x) {     printf( %lld , x);     exit(0);   }   signed main() {     in(n), in(m);     if (n > m) swap(n, m);     if (n == 1) print(m - m % 6 + max(0ll, (m % 6 - 3) * 2));     if ((n & 1) == 0 && (m & 1) == 0) {       if (n == 2 && m == 2)         print(0);       else         print(n * m);     }     if ((n + m) & 1) {       if (m & 1) swap(n, m);       if (m == 2) {         if (n == 3) print(4);         if (n == 7) print(12);       }       print(n * m);     } else       print(n * m - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n, k, d;     cin >> n >> k >> d;     vector<int> dist(n, -1);     vector<vector<pair<int, int>>> za(n);     vector<int> keep(n - 1), par(n);     queue<int> q;     for (int i = (0); i < (k); ++i) {       int p;       cin >> p;       --p;       dist[p] = 0;       q.push(p);       par[p] = -1;     }     for (int i = (0); i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       za[x].emplace_back(y, i);       za[y].emplace_back(x, i);     }     int res = 0;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto edge : za[cur]) {         int u = edge.first;         int edge_no = edge.second;         if (dist[u] == -1) {           ++res;           dist[u] = dist[cur] + 1;           keep[edge_no] = 1;           q.push(u);         }       }     }     vector<int> shut;     for (int i = (0); i < (n - 1); ++i) {       if (keep[i] == 0) {         shut.push_back(i + 1);       }     }     cout << ((int)((shut).size())) << endl;     for (auto s : shut) {       cout << s <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int qq, n, m, k, l, r;   string s, s1, s2, s3;   int INF = (int)2e9 + 7;   struct st {     int x, y;   };   bool operator<(st& a, st& b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   vector<vector<char>> v;   int x[4] = {0, 0, -1, 1}, y[4] = {-1, 1, 0, 0};   void dfs(int i, int j) {     v[i][j] =  . ;     for (int ii = 0; ii < 4; ii++) {       if (v[i + x[ii]][j + y[ii]] ==  B ) dfs(i + x[ii], j + y[ii]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int k1, k2, c;     char e;     cin >> n >> m;     int ans = 0;     v.assign(n + 2, vector<char>(m + 2));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> e;         v[i][j] = e;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (v[i][j] ==  B ) {           dfs(i, j);           ans++;         }       }     }     cout << ans <<    ;     cin >> k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   int n, Z;   long long mul[N];   long long inv[N];   vector<pair<int, int> > a[N];   int sz[N];   int mxp[N];   bool done[N];   int root;   int treesz;   map<int, int> mop;   int getsz(int x, int fa) {     sz[x] = 1;     for (int i = a[x].size() - 1; ~i; --i) {       int y = a[x][i].first;       if (y == fa || done[y]) continue;       sz[x] += getsz(y, x);     }     return sz[x];   }   void getroot(int x, int fa) {     mxp[x] = treesz - sz[x];     for (auto &it : a[x]) {       int y = it.first;       if (y == fa || done[y]) continue;       getroot(y, x);       gmax(mxp[x], sz[y]);     }     if (mxp[x] < mxp[root]) root = x;   }   long long ans, sig;   void dfs1(int x, int fa, int val, int dep) {     sig += (val == 0);     ans += mop[(Z - val) * inv[dep] % Z];     for (auto &it : a[x]) {       if (it.first == fa || done[it.first]) continue;       dfs1(it.first, x, (val * 10ll + it.second) % Z, dep + 1);     }   }   void dfs2(int x, int fa, int val, int dep) {     sig += (val == 0);     ++mop[val];     for (auto &it : a[x]) {       if (it.first == fa || done[it.first]) continue;       dfs2(it.first, x, (val + it.second * mul[dep]) % Z, dep + 1);     }   }   void cal(int x) {     mop.clear();     for (auto &it : a[x]) {       int y = it.first;       if (done[y]) continue;       int z = it.second;       dfs1(y, x, z, 1);       dfs2(y, x, z, 1);     }     reverse(a[x].begin(), a[x].end());     mop.clear();     for (auto &it : a[x]) {       int y = it.first;       if (done[y]) continue;       int z = it.second;       dfs1(y, x, z, 1);       dfs2(y, x, z, 1);     }   }   void dfz(int x) {     treesz = getsz(x, 0);     getroot(x, root = 0);     cal(root);     done[root] = 1;     for (auto &it : a[root])       if (!done[it.first]) dfz(it.first);   }   void exgcd(long long a, long long b, long long &d, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       d = a;     } else {       exgcd(b, a % b, d, y, x);       y -= a / b * x;     }   }   long long INV(long long a, long long Z) {     long long x, y, d;     exgcd(a, Z, d, x, y);     if (d == 1)       return (x % Z + Z) % Z;     else       return -1;   }   int main() {     mxp[0] = inf;     while (~scanf( %d%d , &n, &Z)) {       mul[0] = 1;       mul[1] = 10 % Z;       inv[0] = 1;       inv[1] = INV(10, Z);       for (int i = 2; i <= n; ++i) {         mul[i] = mul[i - 1] * 10 % Z;         inv[i] = inv[i - 1] * inv[1] % Z;       }       for (int i = 1; i <= n; ++i) {         a[i].clear();         done[i] = 0;       }       for (int i = 1; i < n; ++i) {         int x, y, z;         scanf( %d%d%d , &x, &y, &z);         ++x;         ++y;         z %= Z;         a[x].push_back({y, z});         a[y].push_back({x, z});       }       ans = sig = 0;       treesz = n;       dfz(1);       printf( %lld n , ans + sig / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> adj[100001];   vector<int> cost[3];   long long matrix[3][3] = {0};   int tree[100000];   int output[100000] = {0};   void makeTree(int a, int pos) {     tree[pos] = a;     for (auto &i : adj[a]) {       if (pos == 0 || tree[pos - 1] != i) makeTree(i, pos + 1);     }   }   long long calc(int a, int b, int i) {     if (i == n) return 0;     int c = 0 ^ 1 ^ 2 ^ a ^ b;     return cost[c][tree[i] - 1] + calc(b, c, i + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < int(3); i++)       for (int j = 0; j < int(n); j++) {         int x;         cin >> x;         cost[i].push_back(x);       }     for (int i = 0; i < int(n - 1); i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     int counter = 0;     int lf;     for (int i = 0; i < int(n); i++) {       if (adj[i + 1].size() == 1) {         lf = i + 1;         counter++;       }       if (counter > 2) {         cout <<  -1 ;         return 0;       }     }     makeTree(lf, 0);     long long sml = pow(10, 15);     int x, y;     for (int i = 0; i < int(3); i++) {       for (int j = 0; j < int(3); j++) {         if (i == j) continue;         matrix[i][j] =             cost[i][tree[0] - 1] + cost[j][tree[1] - 1] + calc(i, j, 2);         sml = min(sml, matrix[i][j]);         if (sml == matrix[i][j]) {           x = i;           y = j;         }       }     }     cout << sml <<   n ;     output[tree[0] - 1] = x;     output[tree[1] - 1] = y;     for (int i = 2; i < n; i++) {       int c = 0 ^ 1 ^ 2 ^ x ^ y;       output[tree[i] - 1] = c;       x = y;       y = c;     }     for (int i = 0; i < int(n); i++) cout << output[i] + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   long long shu[200010];   int main() {     while (scanf( %d , &N) != EOF) {       for (int i = 1; i <= N * 2; i++) {         scanf( %I64d , &shu[i]);       }       sort(shu + 1, shu + 1 + 2 * N);       long long ans = (shu[N] - shu[1]) * (shu[2 * N] - shu[N + 1]);       for (int i = 2; i <= N; i++) {         ans = min(ans, (shu[i + N - 1] - shu[i]) * (shu[2 * N] - shu[1]));       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h;     cin >> w >> h;     char char1[100][100], char2[100][100];     string char3[200];     for (int i(0); i < h; ++i) cin >> char1[i];     for (int i(0); i < w; ++i) {       for (int j(0); j < h; ++j) {         char2[i][j] = char1[abs(j - h + 1)][i];       }     }     for (int i(0); i < w; ++i) {       for (int j(0); j < h / 2; ++j) {         char tmp = char2[i][j];         char2[i][j] = char2[i][abs(j - h + 1)];         char2[i][abs(j - h + 1)] = tmp;       }     }     for (int i(0); i < 2 * w; i += 2) {       for (int j(0); j < h; ++j) {         char3[i].insert(char3[i].end(), char2[i / 2][j]);         char3[i].insert(char3[i].end(), char2[i / 2][j]);       }       char3[i + 1] = char3[i];     }     for (int i(0); i < 2 * w; ++i) cout << char3[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     bool val = false;     cin >> n;     char array[n][5];     for (int i = 0; i < n; i++) {       cin >> array[i];     }     for (int i = 0; i < n; i++) {       if (array[i][0] ==  O  & array[i][1] ==  O ) {         val = true;         array[i][0] =  + ;         array[i][1] =  + ;         break;       }       if (array[i][3] ==  O  & array[i][4] ==  O ) {         val = true;         array[i][3] =  + ;         array[i][4] =  + ;         break;       }     }     if (val == true) {       cout <<  YES  <<   n ;     } else if (val == false)       cout <<  NO ;     if (val == true) {       for (int i = 0; i < n; i++) {         cout << array[i][0];         cout << array[i][1];         cout << array[i][2];         cout << array[i][3];         cout << array[i][4] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[110];   long long ans;   int main() {     ans = 0LL;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       ans += (long long)a[i];       ans += (long long)(i - 1) * (long long)(a[i] - 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long niz[200005];   int main() {     ios_base::sync_with_stdio(false);     cout.precision(10);     cout << fixed;     int n;     cin >> n;     long long k, m;     cin >> m >> k;     for (int i = 1; i <= n; i++) cin >> niz[i];     sort(niz + 1, niz + 1 + n);     long long b = niz[n];     long long a = niz[n - 1];     long long br = m / (k + 1);     long long ost = m % (k + 1);     long long res = 0;     res += ost * b;     res += br * a;     res += br * k * b;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;               void solve(){    int n;cin>>n;        if(n <= 45){     int point = 9;     string ans =   ;     int x = n;        while(x > point){      ans += to_string(point);      x -= point;      point--;     }     if(x) ans += to_string(x);     reverse(ans.begin(),ans.end());     cout<<ans<<endl;     return;    }       cout<< -1 <<endl;   }         int main(){    ios::sync_with_stdio(false); cin.tie(0);    #ifndef ONLINE_JUDGE     freopen( input.txt ,  r , stdin);    freopen( result.txt ,  w , stdout);    #endif    int t;cin>>t;    while(t--)     solve();                     return 0;   }//main


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};   int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};   int n, m;   bool dfs(pair<int, int> start, vector<string>& G, vector<vector<bool> >& odw,            set<pair<int, int> >& jed) {     stack<pair<int, int> > S;     S.push(start);     odw[start.first][start.second] = true;     bool brzeg = false;     while (!S.empty()) {       pair<int, int> akt = S.top();       S.pop();       if (akt.first == 0 || akt.first == n - 1 || akt.second == 0 ||           akt.second == m - 1)         brzeg = true;       for (int i = 0; i < 8; ++i) {         pair<int, int> nast = make_pair(akt.first + dx[i], akt.second + dy[i]);         if (nast.first >= 0 && nast.first < n && nast.second >= 0 &&             nast.second < m) {           if (G[nast.first][nast.second] ==  0  &&               !odw[nast.first][nast.second]) {             S.push(nast);             odw[nast.first][nast.second] = true;           }           if (G[nast.first][nast.second] ==  1 ) jed.insert(nast);         }       }     }     return brzeg;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     vector<string> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     int odp = 0;     for (int i = 0; i + 1 < n; ++i)       for (int j = 0; j + 1 < m; ++j)         if (a[i][j] ==  1  && a[i][j + 1] ==  1  && a[i + 1][j] ==  1  &&             a[i + 1][j + 1] ==  1 )           odp = 4;     vector<vector<bool> > odw(n, vector<bool>(m, false));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  1  || odw[i][j]) continue;         set<pair<int, int> > S;         if (dfs(make_pair(i, j), a, odw, S)) continue;         int wlk = S.size();         pair<int, int> start = *S.begin();         pair<int, int> nast;         int ilSa = 0;         for (int k = 0; k < 4; ++k) {           pair<int, int> t = make_pair(start.first + dx[k], start.second + dy[k]);           if (S.find(t) != S.end()) {             nast = t;             ++ilSa;           }         }         if (ilSa != 2) continue;         S.erase(start);         pair<int, int> akt = nast;         bool ok = true;         while (true) {           ilSa = 0;           for (int k = 0; k < 4; ++k) {             pair<int, int> t = make_pair(akt.first + dx[k], akt.second + dy[k]);             if (S.find(t) != S.end()) {               nast = t;               ++ilSa;             }           }           if (ilSa > 1) {             ok = false;             break;           }           if (ilSa < 1) {             if (S.size() > 1) ok = false;             break;           }           S.erase(akt);           akt = nast;         }         if (ok) odp = max(odp, wlk);       }     }     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, r, avg, m, k, t, x, y, i, j, b, d, MOD = 1073741824,                                                         count = 0, ans = 0;     string s;     cin >> s;     long long int a[36] = {0};     for (i = 0; i < s.size(); i++) {       if (s[i] -  a  >= 0) {         a[s[i] -  a  + 10]++;       } else {         x = s[i] - 48;         a[x]++;       }     }     for (i = 0; i < 36; i++) {       count += pow(a[i], 2);     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long int   const int N=1000005;   //vector<int>prime;   bool prime[N];   void sieve()   {       int k=sqrt(N-2);       for(int i=1;i<=N-2;++i)           prime[i]=true;       for(int i=2;i<=k;++i)       {           if(prime[i])           {               for(int k=i*i;k<=N-2;k+=i)               {                   prime[k]=false;                   //pf[k]=i;               }           }       }   }      void solve()   {           int d;        cin>>d;        int x;        int y;        for(int i=d+1;;i++)        {            if(prime[i])            {                 x=i;                break;            }        }        for(int i=x+d;;i++)        {            if(prime[i])            {                 y=i;                break;            }        }        cout<<x*y<<  n ;   }      int main() {    // your code goes here    ios_base::sync_with_stdio(false);       cin.tie(NULL);    sieve();    int t;    cin>>t;        while(t--)    {        solve();    }            return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt;     cin >> tt;     while (tt--) {       int n, l;       cin >> n >> l;       vector<double> flags(n);       for (auto& i : flags) cin >> i;       double a_s = 0, b_s = l;       double a_v = 1, b_v = 1;       int a_i = 0, b_i = n - 1;       double t = 0;       for (;;) {         double a_d = a_i < n ? flags[a_i] - a_s : 1e300,                b_d = b_i >= 0 ? b_s - flags[b_i] : 1e300;         double a_t = a_d / a_v, b_t = b_d / b_v;         double sep = b_s - a_s;         double sep_t = sep / (a_v + b_v);         double mn = min({a_t, b_t, sep_t});         t += mn;         a_s += a_v * mn;         b_s -= b_v * mn;         if (a_t == mn) {           a_v++;           a_i++;         } else if (b_t == mn) {           b_v++;           b_i--;         } else           break;       }       cout << fixed << t << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5.2e3 + 5;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   char s[MAXN];   bool a[MAXN][MAXN];   int main(void) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %s , s + 1);       for (int j = 1; s[j]; ++j) {         if (s[j] >=  0  && s[j] <=  9 )           s[j] -=  0 ;         else           s[j] = s[j] -  A  + 10;         for (int k = 0; k < 4; ++k) a[i][(j << 2) - k] = (s[j] >> k) & 1;       }     }     int x = 0;     for (int i = 1; i <= n && x != 1; ++i)       for (int l = 1, r = 1; l <= n && x != 1; l = r) {         while (r <= n && a[i][r] == a[i][l]) ++r;         x = gcd(x, r - l);       }     for (int j = 1; j <= n && x != 1; ++j)       for (int l = 1, r = 1; l <= n && x != 1; l = r) {         while (r <= n && a[r][j] == a[l][j]) ++r;         x = gcd(x, r - l);       }     printf( %d , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double sum[2][30][200010];   char A[2][200010];   int main() {     int N;     cin >> N;     cin >> A[0] >> A[1];     for (int i = 0; i < (N); i++)       for (int k = 0; k < (2); k++) A[k][i] -=  A ;     double cont = 0;     double val = 0;     for (int i = (1); i <= (N); i++) val = N - i + 1, val *= val, cont += val;     memset(sum, 0, sizeof(sum));     for (int i = 0; i < (N); i++) {       for (int k = 0; k < (2); k++) {         sum[k][A[k][i]][i] = ((i == 0) ? 0 : sum[k][A[k][i]][i - 1]) + (i + 1);         if (i > 0) {           for (char c = 0; c <= 25; c++) {             sum[k][c][i] = max(sum[k][c][i], sum[k][c][i - 1]);           }         }       }     }     double ans = 0;     for (int i = 0; i < (N); i++) {       for (int k = 0; k < (2); k++) {         double* lst = sum[1 - k][A[k][i]];         double val = lst[i - 1];         ans += ((double)(N - i)) * val / cont;       }       if (A[0][i] == A[1][i]) {         ans += ((double)(N - i)) * (i + 1) / cont;       }     }     double vv = ans;     cout << fixed << setprecision(12) << vv << endl;   }


#include <bits/stdc++.h>   bool u[1000001];   int pr[500001];   int l;   int n;   long long a[8];   int f[7000];   int thr[10];   int b[8];   int inf = 10000;   int g[8];   int cal(long long x) {     int i;     int ret = 0;     for (i = 1; i <= l && pr[i] <= x / pr[i]; i++) {       while (x % pr[i] == 0) {         x = x / pr[i];         ret++;       }     }     if (x > 1) ret++;     return ret;   }   void dfs(int x, int y, long long z, int r, int cur) {     int i;     if (r == n) {       if (f[x] > f[y] + cur + 1) f[x] = f[y] + cur + 1;     } else {       if (z % a[r] == 0 && b[r] == 2)         dfs(x, y - thr[r], z / a[r], r + 1, cur - g[r]);       dfs(x, y, z, r + 1, cur);     }   }   int main() {     int i, j;     memset(u, true, sizeof(u));     l = 0;     for (i = 2; i <= 1000000; i++) {       if (u[i]) {         l++;         pr[l] = i;       }       for (j = 1; j <= l && i <= 1000000 / pr[j]; j++) {         u[i * pr[j]] = false;         if (i % pr[j] == 0) break;       }     }     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     for (i = 0; i < n; i++) g[i] = cal(a[i]);     thr[0] = 1;     for (i = 1; i <= n; i++) thr[i] = thr[i - 1] * 3;     int mm = inf;     f[0] = 0;     for (i = 1; i < thr[n] - 1; i++) {       int cur = i;       bool flag = true;       for (j = n - 1; j >= 0; j--) {         b[j] = cur / thr[j];         cur = cur % thr[j];         if (b[j] == 0) flag = false;       }       f[i] = inf;       for (j = 0; j < n; j++)         if (b[j] == 1) {           if (g[j] == 1) {             if (f[i] > f[i - thr[j]] + 1) f[i] = f[i - thr[j]] + 1;           } else {             if (f[i] > g[j] + f[i - thr[j]] + 1) f[i] = g[j] + f[i - thr[j]] + 1;           }           dfs(i, i - thr[j], a[j], 0, g[j]);         }       if (flag) {         for (j = 0; j < n; j++)           if (b[j] == 1) break;         if (i + thr[j] == thr[n] - 1) {           if (f[i] < mm) mm = f[i];         } else {           if (f[i] + 1 < mm) mm = f[i] + 1;         }       }     }     printf( %d n , mm);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     priority_queue<pair<int, int> > neg;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pos;     cin >> n;     int x, a;     pair<int, int> temp;     for (int i = 0; i < n; i++) {       cin >> x >> a;       temp = make_pair(x, a);       if (x < 0) {         neg.push(temp);       } else {         pos.push(temp);       }     }     int ans = 0;     if (pos.size() >= neg.size()) {       while (1) {         if (pos.empty())           break;         else {           ans += pos.top().second;           pos.pop();         }         if (neg.empty())           break;         else {           ans += neg.top().second;           neg.pop();         }       }     } else {       while (1) {         if (neg.empty())           break;         else {           ans += neg.top().second;           neg.pop();         }         if (pos.empty())           break;         else {           ans += pos.top().second;           pos.pop();         }       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, nxt;   } e[200005 << 1];   int top = 1;   int head[200005];   void Add_Edge(int u, int v) {     e[++top] = edge{v, head[u]};     head[u] = top;   }   int n;   int a[200005], par[200005][21], dep[200005], size[200005];   void dfs(int u, int fa) {     size[u] = 1;     par[u][0] = fa;     dep[u] = dep[fa] + 1;     for (register int i = head[u]; i; i = e[i].nxt) {       int v = e[i].v;       dfs(v, u);       size[u] += size[v];     }   }   void Init() {     for (register int j = 1; j <= 20; ++j)       for (register int i = 1; i <= n; ++i) par[i][j] = par[par[i][j - 1]][j - 1];   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     int dis = dep[u] - dep[v];     for (register int i = 20; i >= 0; --i)       if (dis & (1 << i)) u = par[u][i];     if (u == v) return u;     for (register int i = 20; i >= 0; --i)       if (par[u][i] ^ par[v][i]) u = par[u][i], v = par[v][i];     return par[u][0];   }   int dist(int a, int b) {     int lca = LCA(a, b);     return dep[a] + dep[b] - dep[lca] * 2;   }   struct Node {     int x, y;   };   Node tree[200005 << 2];   Node merge(Node a, int b) {     if (a.x < 0 || b < 0) return Node{-1, -1};     int aa = a.x, bb = a.y;     int d1 = dist(aa, b);     int d2 = dist(bb, b);     int d3 = dist(bb, aa);     if (d1 + d2 == d3) return a;     if (d1 + d3 == d2) return Node{b, bb};     if (d2 + d3 == d1) return Node{aa, b};     return Node{-1, -1};   }   Node Merge(Node a, Node b) {     if (a.x < 0 || b.x < 0) return Node{-1, -1};     Node up1 = merge(a, b.x);     if (up1.x < 0)       return Node{-1, -1};     else       return merge(up1, b.y);   }   void Pushup(int i) { tree[i] = Merge(tree[i << 1], tree[i << 1 | 1]); }   int Index[200005];   void build(int i, int l, int r) {     if (l == r) return tree[i] = Node{Index[l], Index[l]}, void();     int mid = (l + r) >> 1;     build(i << 1, l, mid);     build(i << 1 | 1, mid + 1, r);     Pushup(i);   }   void update(int i, int l, int r, int res) {     if (l == r) return tree[i] = Node{Index[l], Index[l]}, void();     int mid = (l + r) >> 1;     if (res <= mid)       update(i << 1, l, mid, res);     else       update(i << 1 | 1, mid + 1, r, res);     Pushup(i);   }   int query(Node &mq, int i, int l, int r) {     if (tree[i].x >= 0) {       if (mq.x < 0) return mq = tree[i], r + 1;       Node up1 = Merge(mq, tree[i]);       if (up1.x >= 0) return mq = up1, r + 1;     }     if (l == r) return l;     int mid = (l + r) >> 1;     int res = query(mq, i << 1, l, mid);     if (res <= mid)       return res;     else       return query(mq, i << 1 | 1, mid + 1, r);   }   int read() {     int x = 0;     char c = getchar();     int f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * f;   }   void write(int x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   signed main() {     n = read();     for (register int i = 1; i <= n; ++i) {       a[i] = read() + 1;       Index[a[i]] = i;     }     for (register int i = 2; i <= n; ++i) {       int fa = read();       Add_Edge(fa, i);     }     dfs(1, 1);     Init();     build(1, 1, n);     int q = read();     for (register int i = 1; i <= q; ++i) {       int type = read();       if (type == 1) {         int x = read(), y = read();         swap(Index[a[x]], Index[a[y]]);         swap(a[x], a[y]);         update(1, 1, n, a[x]);         update(1, 1, n, a[y]);       } else {         Node mq = Node{-1, -1};         int Ans = query(mq, 1, 1, n);         write(Ans - 1), putchar(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     int n;     std::cin >> n;     std::vector<bool> col(6 * n);     for (int i = 0; i < 3 * n; ++i) {       int x;       std::cin >> x;       --x;       col[x] = true;     }     std::vector<int> sta;     std::vector<std::vector<int>> tmp(6 * n);     std::vector<std::tuple<int, int, int>> tp;     std::vector<bool> bel;     std::vector<std::vector<int>> E(2 * n);     for (int i = 0; i < 6 * n; ++i) {       sta.push_back(i);       if ((int)sta.size() >= 3) {         auto c = std::prev(sta.end()), b = std::prev(c), a = std::prev(b);         if (col[*a] == col[*b] && col[*b] == col[*c]) {           int u = tp.size();           tp.emplace_back(*a, *b, *c);           bel.push_back(col[*a]);           if (a != sta.begin()) {             tmp[*std::prev(a)].push_back(u);           }           E[u].insert(E[u].end(), tmp[*a].begin(), tmp[*a].end());           E[u].insert(E[u].end(), tmp[*b].begin(), tmp[*b].end());           sta.pop_back(), sta.pop_back(), sta.pop_back();         }       }     }     std::vector<int> fa(2 * n, -1), deg(2 * n, 0);     for (int u = 0; u < 2 * n; ++u) {       for (int v : E[u]) {         fa[v] = u;       }       deg[u] = E[u].size();     }     int cnt = 0;     for (int u = 0; u < 2 * n; ++u) {       if (fa[u] == -1 && !bel[u]) {         ++cnt;       }     }     int p = -1;     std::array<std::queue<int>, 2> Q;     for (int u = 0; u < 2 * n; ++u) {       if (!deg[u]) {         Q[bel[u]].push(u);       }     }     std::vector<std::tuple<int, int, int>> ans;     int c = 0;     for (int i = 0; i < 2 * n - 1; ++i) {       c ^= 1;       while (1) {         int u = Q[c].front();         Q[c].pop();         if (fa[u] == -1 && !bel[u]) {           if (cnt == 1) {             p = u;             continue;           }           --cnt;         }         ans.emplace_back(tp[u]);         if (fa[u] != -1) {           --deg[fa[u]];           if (!deg[fa[u]]) {             Q[bel[fa[u]]].push(fa[u]);           }         }         break;       }     }     if (p == -1) {       c ^= 1;       p = Q[c].front();     }     ans.emplace_back(tp[p]);     for (auto [x, y, z] : ans) {       std::cout << x + 1 <<     << y + 1 <<     << z + 1 <<   n ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 300 + 10, maxm = 4e4 + 10;   const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};   const int INF = 0x3f3f3f3f;   struct Graph {     int ndn, edn, last[maxn];     int u[maxm], v[maxm], flw[maxm], cap[maxm], nxt[maxm];     void init(int _n) {       ndn = _n;       edn = 0;       memset(last, -1, sizeof(last));       memset(flw, 0, sizeof(flw));       memset(cap, 0, sizeof(cap));     }     void adde(int _u, int _v, int _c) {       u[edn] = _u;       v[edn] = _v;       cap[edn] = _c;       nxt[edn] = last[_u];       last[_u] = edn++;     }   };   struct Dinic {     Graph *G;     int S, T, dist[maxn], cur[maxn];     int BFS();     int DFS(int, int);     int solve(Graph *, int, int);   };   int N, T;   char sci[15][15], cap[15][15];   int death[15][15], idsci[15][15], idcap[15][15];   int dist[15][15];   Graph G;   Dinic dinic;   bool judge(int x, int y) {     return x < 0 || x >= N || y < 0 || y >= N || !isdigit(sci[x][y]);   }   int main() {     int zx, zy;     G.init(1);     scanf( %d%d , &N, &T);     for (int i = 0; i < N; i++) {       scanf(  %s , sci[i]);       for (int j = 0; j < N; j++) {         if (isdigit(sci[i][j]) && sci[i][j] >=  1 ) {           idsci[i][j] = ++G.ndn;           G.adde(0, G.ndn, sci[i][j] -  0 );           G.adde(G.ndn, 0, 0);         }         if (sci[i][j] ==  Z ) {           zx = i;           zy = j;         }       }     }     for (int i = 0; i < N; i++) {       scanf(  %s , cap[i]);       for (int j = 0; j < N; j++) {         if (isdigit(cap[i][j]) && cap[i][j] >=  1 ) {           idcap[i][j] = ++G.ndn;           G.adde(G.ndn, 1, cap[i][j] -  0 );           G.adde(1, G.ndn, 0);         }       }     }     queue<pair<int, int> > que;     memset(death, 0x3f, sizeof(death));     death[zx][zy] = 0;     que.push({zx, zy});     while (que.size()) {       pair<int, int> u = que.front();       que.pop();       int d = death[u.first][u.second] + 1;       for (int k = 0; k < 4; k++) {         int x = u.first + dir[k][0];         int y = u.second + dir[k][1];         if (judge(x, y) || death[x][y] < INF) continue;         death[x][y] = d;         que.push({x, y});       }     }     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         if (isdigit(sci[i][j]) && sci[i][j] >=  1 ) {           while (que.size()) que.pop();           memset(dist, 0x3f, sizeof(dist));           dist[i][j] = 0;           que.push({i, j});           while (que.size()) {             pair<int, int> u = que.front();             que.pop();             if (idcap[u.first][u.second]) {               G.adde(idsci[i][j], idcap[u.first][u.second], sci[i][j] -  0 );               G.adde(idcap[u.first][u.second], idsci[i][j], 0);             }             int d = dist[u.first][u.second] + 1;             if (d > T || dist[u.first][u.second] >= death[u.first][u.second])               continue;             for (int k = 0; k < 4; k++) {               int x = u.first + dir[k][0];               int y = u.second + dir[k][1];               if (judge(x, y) || dist[x][y] < INF || death[x][y] < d) continue;               dist[x][y] = d;               que.push({x, y});             }           }         }     printf( %d n , dinic.solve(&G, 0, 1));     return 0;   }   int Dinic::solve(Graph *g, int ts, int tt) {     G = g;     S = ts;     T = tt;     int res = 0;     while (BFS()) {       for (int i = 0; i <= G->ndn; i++) cur[i] = G->last[i];       res += DFS(S, 1e9);     }     return res;   }   int Dinic::BFS() {     memset(dist, -1, sizeof(dist));     dist[S] = 0;     queue<int> que;     que.push(S);     while (que.size()) {       int u = que.front();       que.pop();       for (int e = G->last[u]; ~e; e = G->nxt[e]) {         int v = G->v[e];         if (dist[v] == -1 && G->cap[e] > G->flw[e]) {           dist[v] = dist[u] + 1;           que.push(v);         }       }     }     return ~dist[T];   }   int Dinic::DFS(int u, int tmin) {     if (u == T || tmin == 0) return tmin;     int nflw = 0, f;     for (int &e = cur[u]; ~e; e = G->nxt[e]) {       int v = G->v[e];       if (dist[u] + 1 == dist[v] &&           (f = DFS(v, min(tmin, G->cap[e] - G->flw[e]))) > 0) {         G->flw[e] += f;         G->flw[e ^ 1] -= f;         nflw += f;         tmin -= f;         if (tmin == 0) break;       }     }     return nflw;   }


#include <bits/stdc++.h>   using namespace std;   int a[52][52] = {0};   int b[52];   bool c[52] = {0};   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %d , &a[i][j]);         if (c[a[i][j]] == 0)           c[a[i][j]] = 1;         else           b[i] = a[i][j];       }       memset(c, 0, sizeof(c));     }     for (int i = 1; i <= n; i++) c[b[i]] = 1;     for (int i = 1; i <= n; i++) {       if (b[i])         cout << b[i];       else {         for (int j = 1; j <= n; j++)           if (c[j] == 0) {             cout << j;             c[j] = 1;             break;           }       }       cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ok;   vector<long long> nok;   void doit() {     long long n, d, m;     cin >> n >> d >> m;     vector<long long> v;     long long x;     while (n--) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     long long mleg = 0;     long long ans = 0;     long long cur = 0;     while ((mleg < v.size()) && (v[mleg] <= m)) {       cur += v[mleg];       mleg++;     }     long long sum[mleg];     sum[0] = v[0];     for (int i = 1; i < mleg; i++) {       sum[i] = v[i] + sum[i - 1];     }     ans = cur;     x = 1;     long long comp = 0;     while (v.size() - x >= mleg) {       long long ci = v.size() - x;       comp += v[ci];       long long nesesito = max(((x - 1) * d) - (ci - mleg), (long long)(0));       if (nesesito <= mleg) {         long long mres = 0;         if (nesesito)           mres = comp + (cur - sum[nesesito - 1]);         else           mres = comp + cur;         ans = max(mres, ans);       }       x++;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       doit();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005, M = N * N;   int n, m;   string s[N];   bool isvalid(int x, int y) {     return 0 <= x && x < n && 0 <= y && y < m && s[x][y] ==  . ;   }   int id(int x, int y) { return x * N + y; }   int par[M];   void init() {     for (int i = 0; i < M; i++) par[i] = i;   }   int find(int u) {     if (par[u] == u) return u;     return par[u] = find(par[u]);   }   void merge(int u, int v) { par[find(u)] = find(v); }   vector<int> adj[M];   bool vis[M];   int dis[M];   void bfs(int s) {     dis[s] = 0;     vis[s] = 1;     queue<int> q;     q.push(s);     while (q.size()) {       int u = q.front();       q.pop();       for (int v : adj[u])         if (!vis[v]) {           vis[v] = 1;           dis[v] = 1 + dis[u];           q.push(v);         }     }   }   int main() {     init();     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int sx, sy, l, r;     cin >> sx >> sy >> l >> r;     sx--;     sy--;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (s[i][j] !=  . ) continue;         if (isvalid(i + 1, j)) merge(id(i, j), id(i + 1, j));       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (s[i][j] !=  . ) continue;         int u = find(id(i, j));         int l = find(id(i, j - 1));         int r = find(id(i, j + 1));         if (isvalid(i, j - 1)) adj[u].push_back(l);         if (isvalid(i, j + 1)) adj[u].push_back(r);       }     bfs(find(id(sx, sy)));     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int k = find(id(i, j));         if (s[i][j] !=  .  || !vis[k]) continue;         int dif = j - sy;         int sum = dis[k];         assert(sum % 2 == abs(dif) % 2);         int rr = (sum + dif) / 2;         int ll = (sum - dif) / 2;         if (rr <= r && ll <= l) ans++;       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int solve(int n, int a[]) {     int count = 0;     for (int i = 0; i < n; ++i) {       if (a[i] == i) {         ++count;       }     }     for (int i = 0; i < n; ++i) {       if (a[i] != i && a[a[i]] == i) {         return count + 2;       }     }     return min(count + 1, n);   }   int main() {     int n;     int a[100000];     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     cout << solve(n, a) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 52;   const int MAX = 1e9 + 5;   int n, a[N];   long double dp[N][N][N][N];   int p;   long double all, P[N];   long double f(int wh, int ret, int left, int whd) {     if (left == 0 && ret) return 0;     if (left == 0 && ret == 0) return 1;     if (ret < 0) return 0;     if (wh > n) return 0;     long double &r = dp[wh][ret][left][whd];     if (r != -1) return r;     if (wh == whd) return r = f(wh + 1, ret, left, whd);     return r = f(wh + 1, ret - a[wh], left - 1, whd) + f(wh + 1, ret, left, whd);   }   int main() {     scanf( %d , &n);     P[0] = 1;     for (int i = 1; i <= n; i++) P[i] = P[i - 1] * i;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &p);     for (int A = 0; A <= N - 1; A++)       for (int B = 0; B <= N - 1; B++)         for (int C = 0; C <= N - 1; C++)           for (int D = 0; D <= N - 1; D++) dp[A][B][C][D] = -1;     for (int i = 1; i <= n; i++) {       int begin = p - a[i] + 1;       int end = p;       for (int j = begin; j <= end; j++) {         for (int k = 0; k <= n; k++) {           long double temp = f(1, j, k, i);           all += temp * P[k] / P[n] * P[n - k - 1] * k;         }       }     }     for (int i = 0; i <= p; i++) all += f(1, i, n, 0) * n;     cout << setprecision(12) << fixed << all <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     unsigned long long int t;     cin >> t;     while (t--) {       unsigned long long int n;       cin >> n;       unsigned long long int x;       cin >> x;       vector<unsigned long long int> ind;       vector<pair<unsigned long long int, unsigned long long int>> store;       unsigned long long int count = 0, ind1;       for (unsigned long long int i = 1; i <= n - 1; i++) {         unsigned long long int y;         cin >> y;         if (y != x) {           ind1 = i + 1;           count++;           store.push_back({1, i + 1});         } else {           ind.push_back(i);         }       }       if (count == 0)         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;         for (auto pr : store) {           cout << pr.first <<     << pr.second <<   n ;         }         if (ind.size() != 0) {           for (auto x : ind) {             cout << ind1 <<     << x + 1 <<   n ;           }         }       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T2>   T2 fac(T n) {     return n < 2 ? 1 : fac<T, T2>(n - 1) * n;   }   template <typename T, typename T2, typename T3>   T2 fac(T n, T3 mod) {     return n < 2 ? 1 : (fac<T, T2, T3>(n - 1, mod) * n) % mod;   }   template <typename T>   T nb_combinaisons(T k, T n) {     if (n < k) return nb_combinaisons<T>(n, k);     return fac<T, long long int>(n) /            (fac<T, long long int>(n - k) * fac<T, long long int>(k));   }   template <typename T, typename T2>   T nb_permutations(vector<T2> v) {     T total = fac<T, T>(v.size());     map<T2, T> m;     bool distinct = true;     for (long long unsigned c = 0; c < v.size(); c++) {       m[v[c]]++;       if (m[v[c]] - 1) distinct = false;     }     for (typename map<T2, T>::iterator it = m.begin(); it != m.end(); it++)       total /= fac<T, T>(it->second);     return total;   }   template <typename T, typename T2, typename T3>   T nb_permutations(vector<T2> v, T3 mod) {     T total = fac<T, T, T3>(v.size(), mod);     map<T2, T> m;     bool distinct = true;     for (long long unsigned c = 0; c < v.size(); c++) {       m[v[c]]++;       if (m[v[c]] - 1) distinct = false;     }     for (typename map<T2, T>::iterator it = m.begin(); it != m.end(); it++)       total /= fac<T, T>(it->second);     return total % mod;   }   string itoa_2(long long int n) {     string s;     stringstream ss;     ss << n;     ss >> s;     while (s.size() != 9) s =  0  + s;     return s;   }   int pgcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     return pgcd(b, a % b);   }   string conversion(int n, int base) {     string res =   ;     while (n != 0) {       res = ((char)( 0  + n % base)) + res;       n /= base;     }     return res;   }   int main() {     int n, m;     cin >> n >> m;     int i = 0;     vector<int> v;     if (m % 2 == 0) {       int gauche = (m - 1) / 2 + 1;       int droite = (m - 1) / 2 + 2;       bool g = true;       for (int c = 0; c < n; c++) {         if (g) {           cout << gauche << endl;           if (gauche - 1 <= 0) {             gauche = (m - 1) / 2 + 1;           } else             gauche--;         } else {           cout << droite << endl;           if (droite + 1 > m)             droite = (m - 1) / 2 + 2;           else             droite++;         }         g = !g;       }     } else {       int gauche = (m) / 2;       int droite = (m) / 2 + 2;       bool g = true;       for (int c = 0; c < n; c++) {         if (c % m == 0)           cout << (m / 2) + 1 << endl;         else if (g) {           cout << gauche << endl;           if (gauche - 1 <= 0) {             gauche = (m) / 2;           } else             gauche--;         } else {           cout << droite << endl;           if (droite + 1 > m)             droite = (m) / 2 + 2;           else             droite++;         }         if (c % m != 0) g = !g;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     long long int a, b, c, r;     while (t--) {       long long int ans = 0, mx = 0, mn = 0;       cin >> a >> b >> c >> r;       if (a >= b) {         mx = a;         mn = b;       } else {         mx = b;         mn = a;       }       if (c == mx || c == mn) {         ans = mx - mn - r;         if (ans < 0) ans = 0;         cout << ans << endl;       } else if (c > mn && c < mx) {         if (abs(c - mn) < r)           ans = mx - mn - (r + abs(c - mn));         else if (abs(mx - c) < r)           ans = mx - mn - (r + abs(mx - c));         else           ans = mx - mn - 2 * r;         if (ans < 0) ans = 0;         cout << ans << endl;       } else {         if (mn > c && abs(mn - c) < r)           ans = mx - mn - (r - abs(mn - c));         else if (c > mx && abs(c - mx) < r)           ans = mx - mn - (r - abs(c - mx));         else           ans = mx - mn;         if (ans < 0) ans = 0;         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t[45];   int n, i, k, m, kol, ans, ans2, j, l, ans3, ans1, sum;   void summ(int x) {     for (j = 0; j < k; j++) {       l = n - x;       while (ans2 <= m - t[j] and l > 0) {         l--;         ans2 += t[j];         kol++;       }     }   }   int main() {     cin >> n >> k >> m;     for (i = 0; i < k; i++) {       cin >> t[i];       sum += t[i];     }     i = 0;     sort(t, t + k);     for (i = 0; i <= n; i++) {       ans2 = 0;       kol = 0;       ans3 = 0;       if (sum * i > m) {         break;       }       if (sum * i == m) {         ans = max(ans, i * (k + 1));       }       ans2 = sum * i;       ans3 = (k + 1) * i;       summ(i);       ans3 += kol;       ans = max(ans, ans3);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     long long int temp;     while (b > 0) {       temp = b;       b = a % b;       a = temp;     }     return a;   }   int main() {     long long int N, m;     cin >> N >> m;     long long int a[N], B[m];     for (long long int i = 0; i < N; i++) {       cin >> a[i];     }     long long int n = N - 1;     long long int A[n];     for (long long int i = 1; i < N; i++) {       A[i - 1] = a[i] - a[i - 1];     }     for (long long int i = 0; i < m; i++) {       cin >> B[i];     }     long long int result = A[0];     for (long long int i = 1; i < n; i++) {       result = gcd(result, A[i]);     }     long long int j = 0;     while (j < m && result % B[j] != 0) {       j++;     }     if (j < m) {       cout <<  YES  << endl;       cout << a[0] <<     << j + 1 << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   vector<int> G[maxn + 5];   int dp[maxn + 5], d[maxn + 5];   int main() {     int n, x, ans = 0;     scanf( %d , &n);     for (int i = 2; i <= maxn; i++)       for (int j = i; j <= maxn; j += i) G[j].push_back(i);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       for (int j = 0; j < G[x].size(); j++) dp[x] = max(dp[x], d[G[x][j]] + 1);       for (int j = 0; j < G[x].size(); j++) d[G[x][j]] = dp[x];       ans = max(ans, dp[x]);     }     if (x == 1)       printf( 1 n );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1111;   int n;   string a[N], b[N];   int t[N];   int d;   std::set<pair<string, string> > res;   int main() {     cin >> n >> d;     for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> t[i];     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         if (!(a[i] == b[j] && a[j] == b[i])) continue;         int m = min(t[i], t[j]);         int M = max(t[i], t[j]);         if (M - m <= 0 || M - m > d) continue;         res.insert(make_pair(a[i], b[i]));         res.insert(make_pair(b[i], a[i]));       }     cout << res.size() / 2 << endl;     for (set<pair<string, string> >::iterator it = res.begin(); it != res.end();          ++it) {       string s1 = it->first, s2 = it->second;       if (s1 < s2) cout << s1 <<     << s2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 500;   long long dp[N];   long long n;   void init() {     dp[0] = 1ll;     dp[1] = 2ll;     for (int i = 2; i < N; i++) {       dp[i] = dp[i - 2] + dp[i - 1];     }   }   int main() {     init();     while (cin >> n) {       int cur = 0;       while (dp[cur] <= n) cur++;       cout << cur - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[100005];     cin >> str;     int flag = 0, i;     char checkString[100005];     for (i = 0; str[i] !=   0 ; i++) {       checkString[i] =  a ;     }     checkString[i] =   0 ;     if (strcmp(str, checkString) == 0) {       checkString[strlen(checkString) - 1] =  z ;       cout << checkString;     } else {       for (i = 0; str[i] !=   0 ; i++) {         if (!flag && str[i] ==  a ) continue;         if (flag && str[i] ==  a )           break;         else {           flag = 1;           str[i]--;         }       }       cout << str;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e7 + 50;   const double eps = 1e-7;   const int inf = 0x3f3f3f3f;   const long long lnf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 1e9 + 7;   const double pi = 3.141592653589;   int vis[maxn], cnt = 0, h[maxn];   int sum1[maxn], sum2[maxn];   int spr[maxn];   void ol() {     memset(vis, 1, sizeof(vis));     vis[0] = vis[1] = 0;     for (long long i = 2; i < maxn; i++) {       if (vis[i]) spr[cnt++] = i;       for (long long j = 0; i * spr[j] < maxn && j < cnt; j++) {         vis[i * spr[j]] = 0;         if (i % spr[j] == 0) break;       }     }   }   int f(int x) {     int ans = 0;     for (int i = 1; i <= cnt; i++) {       if (spr[i] <= x) {         ans = i;         break;       }     }     return ans;   }   vector<int> v(12);   bool g(int x) {     v.clear();     while (x) {       v.push_back(x % 10);       x /= 10;     }     bool flage = true;     int len = v.size();     for (int i = 0; i < len / 2; i++) {       if (v[i] != v[len - i - 1]) {         flage = false;         break;       }     }     return flage;   }   bool is(int x) {     int xx = x, s = 0;     while (x) {       s = s * 10 + (x % 10);       x /= 10;     }     return s == xx;   }   int main() {     long long p, q;     scanf( %lld%lld , &p, &q);     ol();     for (int i = 1; i < maxn - 20; i++) {       if (vis[i])         sum1[i] = sum1[i - 1] + 1;       else         sum1[i] = sum1[i - 1];     }     for (int i = 1; i < 10000000; i++) {       if (g(i)) {         sum2[i] = sum2[i - 1] + 1;       } else {         sum2[i] = sum2[i - 1];       }     }     int ans = 0;     for (int i = 1; i < 1e7; i++) {       if ((long long)sum1[i] * q <= (long long)sum2[i] * p) {         ans = i;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll MOD = 1000000007;   ll INF = 1LL << 60;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> tree[n + 1];     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       tree[u].push_back(v);       tree[v].push_back(u);     }     bool ans = true;     for (int i = 1; i <= n; i++) {       if (tree[i].size() == 2) {         ans = false;         break;       }     }     cout << (ans ?  YES  :  NO ) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     long long int n, a, b, t, ans, g;     cin >> t >> a >> b;     if (a > b) swap(a, b);     n = (b / gcd(a, b));     if (n > LLONG_MAX / a) {       ans = min(a - 1, t);     } else {       n *= a;       ans = (t / n) * a + min(t % n, a - 1);     }     g = gcd(ans, t);     cout << (ans / g) <<  /  << (t / g) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500500;   bool Ans[N];   int Weight[N];   pair<int, int> Edges1[N];   vector<int> Edges2[N];   vector<pair<int, vector<int> > > Query[N];   int P[N];   stack<pair<int, int> > Was;   void Clear() {     while (!Was.empty()) Was.pop();   }   void Restore() {     while (!Was.empty()) {       int x = Was.top().first;       int p = Was.top().second;       P[x] = p;       Was.pop();     }   }   int F(int x) {     if (x == P[x]) return x;     Was.push(make_pair(x, P[x]));     return P[x] = F(P[x]);   }   bool Un(int x, int y) {     if ((x = F(x)) == (y = F(y))) return false;     if (rand() & 1) swap(x, y);     Was.push(make_pair(x, P[x]));     P[x] = y;     return true;   }   int main() {     srand(time(0));     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       Weight[i] = w;       Edges1[i] = pair<int, int>(x, y);       Edges2[w].push_back(i);     }     int q;     cin >> q;     for (int i = 1; i <= q; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         int Idx;         scanf( %d , &Idx);         int w = Weight[Idx];         if (Query[w].empty() || Query[w].back().first != i)           Query[w].push_back(make_pair(i, vector<int>()));         Query[w].back().second.push_back(Idx);       }     }     for (int i = 1; i <= q; i++) Ans[i] = true;     for (int i = 1; i <= n; i++) P[i] = i;     for (int w = 1; w < N; w++) {       for (int i = 0; i < Query[w].size(); i++) {         int Idx = Query[w][i].first;         vector<int>& v = Query[w][i].second;         for (int j : v) {           int x = Edges1[j].first;           int y = Edges1[j].second;           Ans[Idx] &= Un(x, y);         }         Restore();       }       for (int i : Edges2[w]) {         int x = Edges1[i].first;         int y = Edges1[i].second;         Un(x, y);       }       Clear();     }     for (int i = 1; i <= q; i++) puts(Ans[i] ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   using pii = pair<int, int>;   using pi3 = pair<int, pii>;   int n, m;   int nxt[100010];   int a[100010], b[100010];   set<pii> A, B;   set<pi3> ans;   int calc_max(int u, set<pair<int, int> > &st) {     auto it = st.upper_bound({m - 1 - u, n + 100});     if (it == st.begin()) return 0;     return (*--it).second;   }   int update_A(int u) {     int id2 = calc_max(a[u], B);     if (id2 == 0) return 0;     int id1 = calc_max(b[id2], A);     if (id1 == 0) return 0;     ans.insert(pi3(a[id1] + b[id2], pii(id1, id2)));   }   int update_B(int u) {     int id2 = calc_max(b[u], A);     if (id2 == 0) return 0;     int id1 = calc_max(a[id2], B);     if (id1 == 0) return 0;     ans.insert(pi3(a[id2] + b[id1], pii(id2, id1)));   }   int del_A(int u) {     int id = calc_max(a[u], B);     if (id == 0) return 0;     if (calc_max(b[id], A) == u) {       auto p = pi3(a[u] + b[id], pii(u, id));       if (ans.find(p) != ans.end()) ans.erase(p);     }   }   int del_B(int u) {     int id = calc_max(b[u], A);     if (id == 0) return 0;     if (calc_max(b[id], B) == u) {       auto p = pi3(b[u] + a[id], pii(id, u));       if (ans.find(p) != ans.end()) ans.erase(p);     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int u;       scanf( %d , &u);       a[i] = u;       A.insert({u, i});     }     for (int i = 1; i <= n; i++) {       int u;       scanf( %d , &u);       b[i] = u;       B.insert({u, i});     }     for (int i = 1; i <= n; i++) {       update_A(i);       update_B(i);     }     while (!A.empty()) {       int u = 0, v = 0;       pi3 p;       if (!ans.empty()) p = *--ans.end();       if (ans.empty() ||           p.first < ((*--A.end()).first + (*--B.end()).first) % m) {         u = (*--A.end()).second, v = (*--B.end()).second;       } else         u = p.second.first, v = p.second.second;       printf( %d  , (a[u] + b[v]) % m);       del_A(u);       del_B(v);       A.erase({a[u], u});       B.erase({b[v], v});       auto it = A.lower_bound({a[u], u});       if (it != A.begin()) update_A((*--it).second);       it = B.lower_bound({b[v], v});       if (it != B.begin()) update_B((*--it).second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int dp[200001][18];   void solve() {     long long int n, m, rc, cc, rb, cb, tim = 0;     cin >> n >> m >> rc >> cc >> rb >> cb;     long long int dx = 1, dy = 1;     while ((rc != rb) && (cc != cb)) {       if ((rc == n) || (rc == 0)) dx = -dx;       if ((cc == m) || (cc == 0)) dy = -dy;       rc = rc + dx;       cc = cc + dy;       tim++;     }     cout << tim <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int t = 1;     for (long long int i = 1; i <= 200000; i++) {       for (long long int j = 0; j < 18; j++) {         dp[i][j] = dp[i - 1][j] + (((1 << j) & i) == 0);       }     }     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[2005];   long long sum[10005], D[5005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) D[abs(a[i] - a[j])]++;     sum[5000] = 0;     double ans = 0;     for (int i = 4999; i >= 0; i--) sum[i] = sum[i + 1] + D[i];     for (int i = 1; i <= 5000; i++)       for (int j = 1; i + j <= 5000; j++) ans += D[i] * D[j] * sum[i + j + 1];     double match = n * (n - 1) / 2.0;     printf( %.10lf n , ans / match / match / match);   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, x, y;     cin >> n >> x >> y;     long long l = y - (n - 1);     if ((n - 1) + l * l >= x && l > 0) {       for (long long i = 0; i < n - 1; i++) cout <<  1  ;       cout << l << endl;     } else {       cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <typename T>   void chmin(T &t, const T &f) {     if (t > f) t = f;   }   template <typename T>   void chmax(T &t, const T &f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   int M, N, V, W;   char A[1010][20][20];   int D[1010][1010];   int ds[1010];   int prv[1010];   bool used[1010];   int ansLen;   pair<int, int> ans[1010];   int main() {     for (; ~scanf( %d%d%d%d , &M, &N, &V, &W);) {       for (int u = 0; u < V; ++u) {         for (int x = 0; x < M; ++x) {           scanf( %s , A[u][x]);         }       }       for (int u = 0; u < V; ++u)         for (int v = u + 1; v < V; ++v) {           int cnt = 0;           for (int x = 0; x < M; ++x)             for (int y = 0; y < N; ++y) {               if (A[u][x][y] != A[v][x][y]) {                 ++cnt;               }             }           D[u][v] = D[v][u] = cnt * W;         }       fill_n(ds, V, M * N);       fill_n(used, V, false);       fill_n(prv, V, -1);       int total = 0;       ansLen = 0;       for (;;) {         int um = -1;         for (int u = 0; u < V; ++u)           if (!used[u]) {             if (!~um || ds[um] > ds[u]) {               um = u;             }           }         if (!~um) {           break;         }         used[um] = true;         total += ds[um];         ans[ansLen++] = make_pair(um, prv[um]);         for (int v = 0; v < V; ++v) {           if (ds[v] > D[um][v]) {             ds[v] = D[um][v];             prv[v] = um;           }         }       }       printf( %d n , total);       for (int i = 0; i < ansLen; ++i) {         printf( %d %d n , ans[i].first + 1, ans[i].second + 1);       }     }     return 0;   }


#include <iostream>   #include<cmath>>   #include<algorithm>   #include <string>   using namespace std;   int arr[101];   int arrstr[200];   bool prime(int n)   {       if(n<=1)           return false;       if(n<=3)           return true;       for(int i=2;i<=sqrt(n);i++)       {           if(n%i==0)               return false;          }       return true;   }   bool have(int n,int d)   {          if(n<d)           return false;       int x=n;       while(x)       {           if(x%10==d)           {               return true;           }           x=x/10;       }       return false;   }   bool check(int n,int d)   {       bool a=false;       int c=n%d;       int v=n/d;       for(int i=1;i<=v;i++)       {           if(have(d*i+c,d))           {               return true;           }             }           return false;   }   void solve()   {   long long  n,k,x;   cin>>n>>k;   x=k;   if(n>k)   {       if(n%k==0)        cout<<1<<  n ;   else    cout<<2<<  n ;   return;   }   cout<<k/n+(k%n!=0)<<  n ;   }      string sp(int n)   {       string str=  ;       while(n>0)       {           str+=   ;           n--;       }       return str;   }   string st(int n)   {       string str=  ;       while(n>0)       {           str+= * ;           n--;       }       return str;   }   int main()   {       ios::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);         int t;      cin>>t;      while(t--)       solve();             return 0;      }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 12;   int rows, cols, k, n;   char mat[MAXN][MAXN];   int sol = 0;   int Calc(int a, int b, int c, int d) {     int ret = 0;     for (int i = a; i <= c; i++) {       for (int j = b; j <= d; j++) ret += (mat[i][j] ==  # );     }     return ret;   }   int main() {     scanf( %d %d %d %d , &rows, &cols, &n, &k);     for (int i = 0; i <= rows; i++)       for (int j = 0; j <= cols; j++) mat[i][j] =  . ;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       mat[x][y] =  # ;     }     for (int i = 1; i <= rows; i++) {       for (int j = 1; j <= cols; j++) {         for (int ii = i; ii <= rows; ii++) {           for (int jj = j; jj <= cols; jj++) {             int sum = Calc(i, j, ii, jj);             sol += (sum >= k);           }         }       }     }     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using db = double;   using str = string;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pd = pair<db, db>;   using vi = vector<int>;   using vb = vector<bool>;   using vl = vector<ll>;   using vd = vector<db>;   using vs = vector<str>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpd = vector<pd>;   template <class T>   using V = vector<T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   const int MOD = 1e9 + 7;   const ll INF = 1e18;   const ll infl = 1e18 + 5;   const int infi = 1e9 + 5;   const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   constexpr int pct(int x) { return __builtin_popcount(x); }   constexpr int bits(int x) { return 31 - __builtin_clz(x); }   ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }   ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U f) {     hi++;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       f(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T, class U>   T lstTrue(T lo, T hi, U f) {     lo--;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo + 1) / 2;       f(mid) ? lo = mid : hi = mid - 1;     }     return lo;   }   template <class T>   void remDup(vector<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   template <class T, class U>   void erase(T& t, const U& u) {     auto it = t.find(u);     assert(it != end(t));     t.erase(u);   }   template <class T>   void re(T& x) {     cin >> x;   }   void re(db& d) {     str t;     re(t);     d = stod(t);   }   void re(ld& d) {     str t;     re(t);     d = stold(t);   }   template <class T, class... U>   void re(T& t, U&... u) {     re(t);     re(u...);   }   template <class T>   void re(complex<T>& c) {     T a, b;     re(a, b);     c = {a, b};   }   template <class T, class U>   void re(pair<T, U>& p) {     re(p.f, p.s);   }   template <class T>   void re(vector<T>& x) {     for (auto& a : x) re(a);   }   template <class T, size_t SZ>   void re(AR<T, SZ>& x) {     for (auto& a : x) re(a);   }   str to_string(char c) { return str(1, c); }   str to_string(const char* s) { return (str)s; }   str to_string(str s) { return s; }   str to_string(bool b) { return to_string((int)b); }   template <class T>   str to_string(complex<T> c) {     stringstream ss;     ss << c;     return ss.str();   }   str to_string(vector<bool> v) {     str res =  { ;     for (int i = (0); i < ((int)(v).size()); ++i) res += char( 0  + v[i]);     res +=  } ;     return res;   }   template <size_t SZ>   str to_string(bitset<SZ> b) {     str res =   ;     for (int i = (0); i < (SZ); ++i) res += char( 0  + b[i]);     return res;   }   template <class T>   str to_string(T v) {     bool fst = 1;     str res =   ;     for (const auto& x : v) {       if (!fst) res +=    ;       fst = 0;       res += to_string(x);     }     return res;   }   template <class T, class U>   str to_string(pair<T, U> p) {     return to_string(p.f) +     + to_string(p.s);   }   template <class T>   void pr(T x) {     cout << to_string(x);   }   template <class T, class... U>   void pr(const T& t, const U&... u) {     pr(t);     pr(u...);   }   void ps() { pr(  n ); }   template <class T, class... U>   void ps(const T& t, const U&... u) {     pr(t);     if (sizeof...(u)) pr(   );     ps(u...);   }   void pdbg(ll t) { cerr << t; }   void pdbg(int t) { cerr << t; }   void pdbg(str t) { cerr << t; }   void pdbg(char t) { cerr << t; }   void pdbg(ld t) { cerr << t; }   void pdbg(db t) { cerr << t; }   void pdbg(ull t) { cerr << t; }   template <class T, class V>   void pdbg(pair<T, V> p) {     cerr <<  { ;     pdbg(p.ff);     cerr <<  , ;     pdbg(p.ss);     cerr <<  } ;   }   template <class T>   void pdbg(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       pdbg(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void pdbg(set<T> v) {     cerr <<  [  ;     for (T i : v) {       pdbg(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void pdbg(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       pdbg(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void pdbg(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       pdbg(i);       cerr <<    ;     }     cerr <<  ] ;   }   void solve() {     ll n;     re(n);     str s;     re(s);     str t;     re(t);     ll a1 = 0, b1 = 0;     ll a2 = 0, b2 = 0;     for (int i = (0); i < (n); ++i) {       if (s[i] ==  a ) {         a1 += 1;       } else {         b1 += 1;       }       if (t[i] ==  a ) {         a2 += 1;       } else {         b2 += 1;       }     }     if ((a1 + a2) % 2 == 0 && (b1 + b2) % 2 == 0) {       ll ans = 0;       ll ab = 0, ba = 0;       vl aa1;       vl aa2;       vl bb1;       vl bb2;       for (int i = (0); i < (n); ++i) {         if (s[i] ==  a  && t[i] ==  b ) {           ab += 1;           aa1.push_back(i + 1);           bb2.push_back(i + 1);         } else if (s[i] ==  b  && t[i] ==  a ) {           ba += 1;           bb1.push_back(i + 1);           aa2.push_back(i + 1);         }       }       ans += ab / 2;       ans += ba / 2;       if (ab % 2 == 1) {         ans += 2;       }       ps(ans);       if (aa1.size() != 0 || aa2.size() != 0) {         while (aa1.size() > 1) {           cout << aa1[aa1.size() - 1] <<     << bb2[aa1.size() - 2] << endl;           aa1.pop_back();           bb2.pop_back();           aa1.pop_back();           bb2.pop_back();         }         while (aa2.size() > 1) {           cout << aa2[aa2.size() - 1] <<     << bb1[aa2.size() - 2] << endl;           aa2.pop_back();           bb1.pop_back();           aa2.pop_back();           bb1.pop_back();         }         if (aa1.size() == 1) {           cout << aa1[0] <<     << bb2[0] << endl;           cout << aa1[0] <<     << bb1[0] << endl;           aa1.pop_back();           bb1.pop_back();           aa2.pop_back();           bb2.pop_back();         }       }     } else {       cout << -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll T = 1;     for (int i = (0); i < (T); ++i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   const int INF = 1e9 + 9;   const int B = 1e9 + 7;   int n, p[N];   set<pair<int, int> > s[N];   int d[N];   int main() {     scanf( %d , &n);     ++n;     for (int i = int(2); i <= int(n); ++i) {       scanf( %d , &p[i]);       d[i] = -1;       for (int x = i; x > 1; x = p[x]) {         int old = d[x];         s[p[x]].erase(pair<int, int>(d[x], x));         if (s[x].size() == 0)           d[x] = 0;         else {           d[x] = s[x].rbegin()->first;           if (s[x].size() > 1) {             auto it = s[x].rbegin();             ++it;             d[x] = max(d[x], it->first + 1);           }         }         s[p[x]].insert(pair<int, int>(d[x], x));         while (s[p[x]].size() > 2) s[p[x]].erase(s[p[x]].begin());         if (d[x] == old) break;       }       printf( %d  , s[1].rbegin()->first + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100000];   int main() {     int m, n, j, k, l, t, ll;     bool is = false;     cin >> t;     cin >> s;     if (t < 5) {       cout <<  no  << endl;       return 0;     }     l = t / 5;     ll = t % 5;     for (j = 0; j < t && !is; j++)       for (k = 1; k < t && !is; k++)         if (j + 4 * k < t && s[j] ==  *  && s[j + 2 * k] ==  *  &&             s[j + k] ==  *  && s[j + 3 * k] ==  *  && s[j + 4 * k] ==  * ) {           is = true;         }     if (is)       cout <<  yes  << endl;     else       cout <<  no  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, g[2010], a[100003], f[2010], ansn, sum1, sum2;   bool make[200];   int main() {     cin >> n >> m;     bool see = false;     for (int i = m; i > n; i--) {       for (int j = 2; j <= min((long long)100000, n) and !see; j++)         if (i % j == 0) {           see = true;         }       if (!see) return cout << i, 0;       see = false;     }     cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   const int NN = 202020;   int a[NN], b[NN];   map<int, int> mp;   int main() {     int n, y;     cin >> n >> y;     for (int i = 1; i <= n; i++) cin >> a[i];     int m, yy;     cin >> m >> yy;     for (int i = 1; i <= m; i++) cin >> b[i];     int ans = 2;     for (int bt = 0; bt < 30; bt++) {       int d = (1 << bt);       mp.clear();       for (int i = 1; i <= n; i++) {         int ha = a[i] % (2 * d);         mp[ha]++;         ans = max(ans, mp[ha]);       }       for (int i = 1; i <= m; i++) {         int ha = (b[i] + d) % (2 * d);         mp[ha]++;         ans = max(ans, mp[ha]);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1);   const long long MOD = 1e9 + 7;   const long long INF = LLONG_MAX;   const long long SIZE = 100000;   void solve() {     long long n, s;     cin >> n >> s;     long long sum = 0, dig = 0, fir;     long long k = n;     vector<long long> v;     while (k != 0) {       long long rem = k % 10;       sum += rem;       fir = rem;       v.push_back(rem);       k /= 10;       dig++;     }     if (sum <= s) {       cout << 0 << endl;     } else {       reverse(v.begin(), v.end());       long long sum2 = 0, fin;       long long pos = -1;       for (long long i = 0; i < (long long)v.size(); i++) {         sum2 += v[i];         if (sum2 > s) {           pos = i;           break;         }       }       sum2 -= v[pos];       long long yup = -1;       for (long long i = pos - 1; i >= 0; i--) {         v[i] += 1;         sum2 += 1;         if (sum2 <= s) {           yup = i;           break;         }         sum2 -= v[i];       }       if (yup == -1) {         long long fin = pow(10, dig);         cout << fin - n << endl;       } else {         for (long long i = yup + 1; i < (long long)v.size(); i++) {           v[i] = 0;         }         long long fin = 0;         long long len = v.size() - 1;         for (long long i = 0; i < (long long)v.size(); i++) {           fin += v[i] * pow(10, len);           len--;         }         cout << fin - n << endl;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e5 + 5;   int n, a[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     for (int i = 0, eq = 0; i < n - 1; ++i) {       if (a[i] == a[i + 1]) {         if ((++eq) > 1 || (i > 0 && a[i] - 1 == a[i - 1]) || a[i] == 0) {           puts( cslnb );           return 0;         }       }     }     ll sum = 0;     for (int i = 0; i < n; ++i) sum += a[i] - i;     if ((sum & 1) == 0)       puts( cslnb );     else       puts( sjfnb );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int M, N, s, x, l, c;     vector<pair<int, int>> val;     vector<int> seq;     cin >> M;     for (int i = 0; i < M; i++) {       cin >> s;       if (s == 1) {         cin >> x;         val.push_back(make_pair(0, x));         if (seq.size() < 1e6) {           seq.push_back(x);         }       } else {         cin >> l >> c;         val.push_back(make_pair(l, c));         for (int j = 0; j < c; j++) {           if (seq.size() < 1e6) {             seq.insert(seq.end(), seq.begin(), seq.begin() + l);           } else {             break;           }         }       }     }     vector<long long> q;     long long v;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> v;       q.push_back(--v);     }     vector<int> res(N, 0);     int i = 0;     long long cc = 0;     for (int j = 0; j < val.size() && i < N; j++) {       if (val[j].first == 0) {         if (cc++ == q[i]) {           res[i++] = val[j].second;         }       } else {         long long next = cc + ((long long)val[j].second) * val[j].first;         while (i < N && q[i] < next) {           v = (q[i] - cc) % val[j].first;           res[i] = seq[v];           i++;         }         cc += ((long long)val[j].second) * val[j].first;       }     }     cout << res[0];     for (int i = 1; i < N; i++) {       cout <<     << res[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     vector<vector<int> > v(26);     for (int i = 0; i < n; i++) {       char a = s[i];       char k = a;       k++;       for (char j = k; j <=  z ; j++) {         int x = j -  a ;         if (v[x].size() > 0) {           cout <<  YES  << endl;           cout << v[x].back() + 1 <<     << i + 1 << endl;           return;         }       }       v[a -  a ].push_back(i);     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tests = 1;     while (tests--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[200005];   pair<long long int, long long int> even[200005];   pair<long long int, long long int> odd[200005];   int main() {     long long int n;     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> arr[i];     even[2] = make_pair(0, 2);     odd[2] = make_pair(abs(arr[2] - arr[1]), 1);     for (long long int i = 3; i <= n; i++) {       long long int preve = even[i - 1].first;       long long int prevel = even[i - 1].second;       long long int prevo = odd[i - 1].first;       long long int prevol = odd[i - 1].second;       if (i % 2 == 0) {         odd[i] = make_pair(prevo + abs(arr[i] - arr[i - 1]), prevol);         if (preve - abs(arr[i] - arr[i - 1]) <= 0)           even[i] = make_pair(0, i);         else           even[i] = make_pair(preve - abs(arr[i] - arr[i - 1]), prevel);       } else {         even[i] = make_pair(preve + abs(arr[i] - arr[i - 1]), prevel);         if (prevo - abs(arr[i] - arr[i - 1]) <= 0)           odd[i] = make_pair(0, i);         else           odd[i] = make_pair(prevo - abs(arr[i] - arr[i - 1]), prevol);       }     }     long long int m = 0;     for (long long int i = 1; i <= n; i++) {       m = max(m, max(even[i].first, odd[i].first));     }     cout << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   inline int sj(int n) {     unsigned long long x = rnd();     x = x << 32 | rnd();     return x % n + 1;   }   const int p = 998244353;   inline void inc(int &x, const int y) {     if ((x += y) >= p) x -= p;   }   inline void dec(int &x, const int y) {     if ((x -= y) < 0) x += p;   }   inline int ksm(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = (long long)r * x % p;       x = (long long)x * x % p;       y >>= 1;     }     return r;   }   priority_queue<int> ONLYYFORRCOPYY;   priority_queue<int, vector<int>, greater<int>> ONLYYFORRCOPYY__;   const int N = 1e6 + 2, M = 4e6 + 2;   struct Q {     int a, s;     bool operator<(const Q &o) const {       return max(a, s) < max(o.a, o.s) ||              max(a, s) == max(o.a, o.s) && (s < o.s || s == o.s && a < o.a);     }   };   Q a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << setiosflags(ios::fixed) << setprecision(15);     int n, d, i, ans = 0;     cin >> n >> d;     for (i = 1; i <= n; i++) cin >> a[i].s >> a[i].a;     sort(a + 1, a + n + 1);     for (i = 1; i <= n; i++)       if (d <= a[i].s) d = max(d, a[i].a), ++ans;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> g[100005];   vector<pair<pair<int, int>, int> > coord;   int visited[100005];   long long ans = 1;   const long long pmod = 1000000007;   long long expsize;   set<int> x, y;   bool cycle;   int mapback[100005];   long long qpmod(long long b, long long e) {     long long cur = b;     long long res = 1;     while (e) {       if (e % 2 == 1) {         res = res * cur % pmod;       }       e /= 2;       cur = cur * cur % pmod;     }     return res;   }   pair<pair<int, int>, int> m3(int a, int b, int c) {     pair<pair<int, int>, int> res;     res.first.first = a;     res.first.second = b;     res.second = c;     return res;   }   bool cmpx(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {     if (x.first.first < y.first.first) return true;     if ((x.first.first == y.first.first) && (x.first.second < y.first.second))       return true;     return false;   }   bool cmpy(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {     if (x.first.second < y.first.second) return true;     if ((x.first.second == y.first.second) && (x.first.first < y.first.first))       return true;     return false;   }   void dfs(int last, int cur) {     expsize++;     visited[cur] = 1;     x.insert(coord[mapback[cur]].first.first);     y.insert(coord[mapback[cur]].first.second);     int i;     for (i = 0; i < g[cur].size(); i++) {       if (g[cur][i] == last) continue;       if (visited[g[cur][i]]) {         cycle = true;         continue;       }       dfs(cur, g[cur][i]);     }   }   int main() {     scanf( %d , &n);     int i, j, k;     for (i = 0; i < n; i++) {       scanf( %d %d , &j, &k);       coord.push_back(m3(j, k, i));     }     sort(coord.begin(), coord.end(), cmpx);     for (i = 1; i < n; i++) {       if (coord[i].first.first == coord[i - 1].first.first) {         g[coord[i].second].push_back(coord[i - 1].second);         g[coord[i - 1].second].push_back(coord[i].second);       }     }     sort(coord.begin(), coord.end(), cmpy);     for (i = 1; i < n; i++) {       if (coord[i].first.second == coord[i - 1].first.second) {         g[coord[i].second].push_back(coord[i - 1].second);         g[coord[i - 1].second].push_back(coord[i].second);       }     }     for (i = 0; i < n; i++) {       mapback[coord[i].second] = i;     }     for (i = 0; i < n; i++) {       if (visited[i] == 0) {         x.clear();         y.clear();         cycle = false;         dfs(i, i);         expsize = x.size() + y.size();         if (cycle) {           ans = ans * qpmod(2, expsize) % pmod;         } else {           ans = ans * ((qpmod(2, expsize) + pmod - 1) % pmod) % pmod;         }       }     }     printf( %d n , (int)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int incoming[110];   int outgoing[110];   int main(int argc, const char* argv[]) {     int n, m;     cin >> n >> m;     int a, b, c;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c;       incoming[b] += c;       outgoing[a] += c;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (outgoing[i] - incoming[i] > 0) ans += outgoing[i] - incoming[i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, m, z, c;     string s;     cin >> s;     c = 0, z = 0;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  4 )         c++;       else if (s[i] ==  7 )         z++;     }     if (c == z && z == 0)       cout << -1 << endl;     else if (c >= z)       cout << 4 << endl;     else       cout << 7 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, INF = 1e9;   vector<int> g[N], r[N], out;   int cnt[N], ans = INF, sum = 0;   int dfs(int v, int par) {     for (int i = 0; i < g[v].size(); i++)       if (g[v][i] != par) cnt[v] += dfs(g[v][i], v);     for (int i = 0; i < r[v].size(); i++)       if (r[v][i] != par) cnt[v] += 1 + dfs(r[v][i], v);     return cnt[v];   }   void dfs2(int v, int par, int a, int b) {     for (int i = 0; i < g[v].size(); i++)       if (g[v][i] != par) dfs2(g[v][i], v, a + 1, b);     for (int i = 0; i < r[v].size(); i++)       if (r[v][i] != par) dfs2(r[v][i], v, a, b + 1);     int cur = sum - b + a;     if (cur < ans) {       ans = cur;       out.clear();       out.push_back(v + 1);     } else if (cur == ans)       out.push_back(v + 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       r[b].push_back(a);     }     dfs(0, -1);     sum = cnt[0];     dfs2(0, -1, 0, 0);     cout << ans <<   n ;     sort(out.begin(), out.end());     for (int i = 0; i < out.size(); i++)       cout << out[i] <<    n [i == out.size() - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> E[1010000];   int n, m, T[1010000];   bool v[1010000];   void DFS(int a) {     v[a] = true;     int i;     for (i = 0; i < E[a].size(); i++) {       if (!v[E[a][i]]) DFS(E[a][i]);     }   }   long long Res;   int main() {     int i, a, b, ck = 0, cc = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       if (a == b) {         cc++;         T[a]++;       }       E[a].push_back(b);       E[b].push_back(a);     }     Res = 1ll * cc * (m - cc) + 1ll * cc * (cc - 1) / 2;     for (i = 1; i <= n; i++) {       if (!E[i].empty()) {         if (!v[i] && ck) {           printf( 0 n );           return 0;         }         ck = 1;         DFS(i);       }     }     for (i = 1; i <= n; i++) {       int t = E[i].size() - T[i] * 2;       Res += 1ll * t * (t - 1) / 2;     }     printf( %lld n , Res);   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   const int maxn = 3e3+5;   const int mod = 0x3f3f3f3f;   int n,d,q;      void solve(int n){    if(n>=10*d){     cout<< YES <<endl;     return;    }    for(int i=1;i<=9;i++){     if(n>=d*i&&(n-i*d)%10==0){      cout<< YES <<endl;      return;     }    }    cout<< NO <<endl;   }      int main(){    int t;    cin>>t;    while(t--){          cin>>q>>d;     for(int i=0;i<q;i++){      cin>>n;      solve(n);     }    }         return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110, mod = 1e9 + 7;   const long long inf = 1e18;   long long a[maxn];   int b[maxn];   long long ans1, ans2, ans3;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int tot = 2; tot <= 2 * m; tot++) {       int pos = max(1, tot - m), pos2 = 0, pos3 = 0, mxp = -1,           lim = (tot + 1) / 2, cnt = 0;       for (int j = 0; j < n; j++) {         b[j] = a[j] % tot;       }       for (int j = 0; j < n; j++) {         cnt += (b[j] >= lim);         if (b[j] >= lim)           pos = max(pos, tot - b[j]);         else           pos = max(pos, b[j] + 1);         if (mxp == -1 || b[mxp] < b[j]) mxp = j;       }       for (int j = 0; j < n; j++) {         if (j != mxp) pos2 = max(pos2, (b[j] / 2) + 1);         pos3 = max(pos3, (b[j] / 2) + 1);       }       if (cnt & 1)         ans2 += max(0, tot - 2 * max(pos, pos2) + 1);       else         ans3 += max(0, tot - 2 * max(pos, pos3) + 1);     }     ans1 = (1ll * m * m - ans2 - ans3) >> 1;     return cout << ans1 <<     << ans1 <<     << ans2 <<     << ans3 << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const int N = 200005;   const int MAX = 250;   int cnt[N * (MAX + 5)];   int pref[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     string s;     cin >> s;     int n = s.size();     lint ans = 0;     for (int i = 0; i < n; i++) {       pref[i + 1] = s[i] -  0 ;       pref[i + 1] += pref[i];     }     for (int k = 1; k <= MAX; k++) {       for (int i = 0; i <= n; i++) {         ans += cnt[k * pref[i] - i + n]++;       }       for (int i = 0; i <= n; i++) {         cnt[k * pref[i] - i + n]--;       }     }     vector<int> ones;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         ones.emplace_back(i + 1);       }     }     ones.emplace_back(n + 1);     int i = 0;     int num = (int)ones.size() - 1;     for (int l = 1; l <= n; l++) {       while (i < num && ones[i] < l) {         i++;       }       for (int j = i; j < num; j++) {         if ((j - i + 1) * MAX > n) {           break;         }         int high = (ones[j + 1] - l) / (j - i + 1);         int low = max(MAX, (ones[j] - l) / (j - i + 1));         ans += max(high - low, 0);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100007];   int main() {     int n, kq;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     kq = 2;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n - 2; ++i) {       int j = 0;       for (j = i + 2; j <= n; ++j)         if (a[j] != a[j - 1] + a[j - 2]) break;       kq = max(kq, j - i);       i = j - 2;     }     cout << kq;     return 0;   }


//   // Created by Abhishek Bansal on 3/18/2021   //   //#pragma GCC optimize ( O3 )   //#pragma GCC optimize( Ofast,no-stack-protector )   //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native )   #include <bits/stdc++.h>   #define ll long long   #define ld long double   using namespace std;   clock_t startTime;   double getCurrentTime() {       return (double)(clock() - startTime) / CLOCKS_PER_SEC;   }   /*------------------------------------------------IO_OPERATORS---------------------------------------------*/   template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first <<     << _p.second; return _out; }   template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }   template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out <<     << *_it; return _out; }   template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; }   template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; return _out; }   template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; return _out; }   template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; return _out; }   template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; return _out; }   template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out <<  {   << _m.begin()->first <<   ,    << _m.begin()->second <<   } ; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out <<  , {    << _it->first <<   ,    << _it->second <<   } ; return _out; }   template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; return _out; }   //For 1 based indexing   template<typename T>   void out(const vector<T> &a, int n) {       for (int i = 1; i <= n; ++i) {cout << a[i] <<    ;} cout <<   n ;   }   template<typename T>   void out(const vector<vector<T>> &a, int n, int m) {       for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << a[i][j] <<    ;}cout <<   n ;}   }      const int N = 20000005;   int lp[N+1];   vector<int> pr;      void Precompute() {       for (int i=2; i<=N; ++i) {           if (lp[i] == 0) {               lp[i] = i;               pr.push_back (i);           }           for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)               lp[i * pr[j]] = pr[j];       }   }      void solve() {       int c, d, x;cin >> c >> d >> x;       ll ans = 0;       auto calc = [&](int i) {           if ((d + x / i) % c) return;           int prod = (d + x / i) / c;           int cnt = 0;           while (prod != 1) {               int  u= lp[prod];               cnt++;               while (prod % u == 0) prod /= u;           }           ans += (1 << cnt);       };          for (int i = 1; i * i <= x; ++i) {           if (x % i != 0) continue;           calc(i);           if (i * i != x) calc(x / i);       }       cout << ans <<   n ;   }      int main() {       ios_base::sync_with_stdio(false);cin.tie(nullptr);          startTime = clock();   // freopen( input.txt ,  r , stdin);   // freopen( output.txt ,  w , stdout);   //    cout << fixed << setprecision(20);       int T = 1;       Precompute();       cin >> T;       while (T--) {           solve();       }       return 0;   }


#include <bits/stdc++.h>   const long long maxn = 1e3 + 5;   const long long w = 1e8;   using namespace std;   int m, n, p, kq;   char a[maxn][maxn];   string s;   char dir[4] = { D ,  L ,  U ,  R };   int tdx, tdy;   int x, y;   inline void init() {     cin >> n >> m;     cin.ignore();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] ==  S ) {           x = j;           y = i;         }       }     cin >> s;     p = s.length();   }   inline void solve() {     sort(dir, dir + 4);     do {       tdx = x;       tdy = y;       for (int i = 0; i < p; i++) {         if (dir[s[i] - 48] ==  D ) tdy++;         if (dir[s[i] - 48] ==  U ) tdy--;         if (dir[s[i] - 48] ==  L ) tdx--;         if (dir[s[i] - 48] ==  R ) tdx++;         if (a[tdy][tdx] ==  #  || tdx < 1 || tdy < 1 || tdx > m || tdy > n) break;         if (a[tdy][tdx] ==  E ) {           kq++;           break;         }       }     } while (next_permutation(dir, dir + 4));     cout << kq;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     int N[2005], A[2005];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       N[i] = a;     }     for (int i = 0; i < n; i++) {       int cont = 0;       for (int j = 0; j < n; j++) {         if (i != j && N[i] < N[j]) cont++;       }       A[i] = 1 + cont;     }     for (int i = 0; i < n; i++) {       if (i != n - 1)         cout << A[i] <<    ;       else         cout << A[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, a, P, len, rev[N];   int Lim;   int f[2][N], g[2][N];   const long double PI = acos(-1.0);   struct Complex {     long double x, y;     Complex() {}     Complex(long double _x, long double _y) {       x = _x;       y = _y;     }     Complex conj() { return Complex(x, -y); }     Complex operator+(const Complex rhs) const {       return Complex(x + rhs.x, y + rhs.y);     }     Complex operator-(const Complex rhs) const {       return Complex(x - rhs.x, y - rhs.y);     }     Complex operator*(const Complex rhs) const {       return Complex(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);     }   } w[N], w2[N];   inline void FFT(Complex *F, int len, int type) {     for (int i = 0; i < len; i++)       if (i < rev[i]) swap(F[i], F[rev[i]]);     for (int k = 2; k <= len; k <<= 1)       for (int j = 0; j < len; j += k) {         for (int i = j; i < j + (k / 2); i++) {           Complex cur = type == 1 ? w[(k / 2) + (i - j)] : w2[(k / 2) + (i - j)];           Complex u = F[i], v = cur * F[i + (k / 2)];           F[i] = u + v;           F[i + (k / 2)] = u - v;         }       }     if (type == -1)       for (int i = 0; i < len; i++) F[i].x /= len, F[i].y /= len;   }   Complex A[N], B[N], C[N], D[N];   inline void MTT(int *F, int *G, int k) {     for (int i = 0; i < len; i++) A[i] = B[i] = C[i] = D[i] = Complex(0, 0);     Lim = int(sqrt(P) + 1);     for (int i = 0; i < k; i++) {       A[i] = Complex(F[i] / Lim, F[i] % Lim);       C[i] = Complex(G[i] / Lim, G[i] % Lim);     }     FFT(A, len, 1);     FFT(C, len, 1);     for (int i = 1; i < len; i++) B[len - i] = A[i].conj();     B[0] = A[0].conj();     for (int i = 1; i < len; i++) D[len - i] = C[i].conj();     D[0] = C[0].conj();     for (int i = 0; i < len; i++) {       Complex aa = (A[i] + B[i]) * Complex(0.5, 0),               bb = (A[i] - B[i]) * Complex(0, -0.5),               cc = (C[i] + D[i]) * Complex(0.5, 0),               dd = (C[i] - D[i]) * Complex(0, -0.5);       A[i] = (aa * cc) + Complex(0, 1) * (aa * dd + bb * cc), B[i] = bb * dd;     }     FFT(A, len, -1);     FFT(B, len, -1);     for (int i = 0; i < k; i++) {       long long aa = (long long)(A[i].x + 0.5) % P,                 bb = (long long)(A[i].y + 0.5) % P,                 cc = (long long)(B[i].x + 0.5) % P;       F[i] = (1ll * aa * Lim * Lim % P + 1ll * bb * Lim % P + cc % P) % P;       F[i] = (F[i] + P) % P;     }   }   int ans = 0;   inline void solve(int a, int k) {     if (a == 1) {       f[1][1] = ans = 1;       return;     }     solve(a >> 1, k);     memset(g, 0, sizeof g);     g[0][0] = g[1][0] = 1;     for (int i = 1; i < k; i++) g[0][i] = g[1][i] = (f[0][i] + f[1][i]) % P;     MTT(g[0], f[(a >> 1) & 1], k);     MTT(g[1], f[((a >> 1) & 1) ^ 1], k);     for (int i = 0; i < k; i++)       f[0][i] = (f[0][i] + g[0][i]) % P, f[1][i] = (f[1][i] + g[1][i]) % P;     if (a & 1) {       for (int i = k - 1; i; i--)         f[1][i] = (f[1][i] + f[0][i - 1] + f[1][i - 1]) % P;       f[1][1] = (f[1][1] + 1) % P;     }     for (int i = 1; i < k; i += 2) ans = (ans + f[1][i]) % P;   }   int main() {     scanf( %d%d%d , &n, &a, &P);     if (a == 1) return puts( 0 ), 0;     len = 1;     while (len <= n * 2) len <<= 1;     for (int i = 0; i < len; i++) {       rev[i] = rev[i >> 1] >> 1;       if (i & 1) rev[i] |= len >> 1;     }     for (int i = 1; i < len; i <<= 1) {       w[i] = Complex(1, 0);       for (int j = 1; j < i; j++)         w[i + j] = (((j & 31) == 1) ? Complex(cos(PI * j / i), sin(PI * j / i))                                     : w[i + j - 1] * w[i + 1]);     }     for (int i = 0; i < len; i++) w2[i] = w[i].conj();     solve(a >> 1, n + 1);     printf( %d n , ans);   }