#include <bits/stdc++.h>   using namespace std;   const int maxn = 65;   const int inf = 1e9;   int n, m, r;   int dp[maxn][maxn][maxn];   int a[maxn][maxn][maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> r;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) cin >> a[i][j][k];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) dp[i][j][k] = inf;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++)           for (int z = 0; z < n; z++) {             a[i][k][z] = min(a[i][j][z] + a[i][k][j], a[i][k][z]);             dp[0][k][z] = min(dp[0][k][z], a[i][k][z]);           }     for (int i = 1; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < n; k++) {           for (int z = 0; z < n; z++)             dp[i][k][z] = min(dp[i][k][z], dp[i - 1][k][j] + dp[0][j][z]);         }       }     }     for (int i = 0; i < r; i++) {       int s, t, k;       cin >> s >> t >> k;       s--, t--;       k = min(k, n - 2);       cout << dp[k][s][t] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )   using namespace std;   const double eps = 0.000001;   const long double pi = acos(-1);   const int maxn = 1e7 + 9;   const int mod = 1e9 + 7;   const long long MOD = 1e18 + 9;   const long long INF = 1e18 + 123;   const int inf = 2e9 + 11;   const int mxn = 1e6 + 9;   const int N = 3e5 + 123;   const int PRI = 555557;   const int pri = 997;   int tests = 1;   int n, m, k;   int a[N];   int now[N];   string s;   long long cnt[N];   long long cur, res;   inline void Solve() {     cin >> n >> k;     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + i; j <= n; j += i) {         cnt[j]++;         ans++;       }     }     for (int i = n; i > 0; i--) {       now[i] = 1;     }     for (int i = 1; i <= n; i++) {       long long cur = cnt[i];       for (int j = i + i; j <= n; j += i)         if (now[j]) cur++;       if (ans - cur >= k && cnt[i]) {         now[i] = 0;         ans -= cur;         for (int j = i + i; j <= n; j += i) cnt[j]--;       }     }     if (ans != k) {       cout <<  No ;       exit(0);     }     for (int i = 1; i <= n; i++) {       if (now[i]) {         res++;       }     }     cout <<  Yes n  << res <<   n ;     for (int i = 1; i <= n; i++)       if (now[i]) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     while (tests--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:64000000 )   using namespace std;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   template <class T>   T jog(T a, T b) {     return a + b;   }   template <class T>   T bog(T a, T b) {     return a - b;   }   template <class T>   T gon(T a, T b) {     return a * b;   }   template <class T>   T sq(T x) {     return x * x;   }   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   template <class T>   T power(T a, T p) {     T res = 1, x = a;     while (p) {       if (p & 1) res = res * x;       x = x * x;       p >>= 1;     }     return res;   }   template <class T>   T cordinatlenth(T a, T b, T c, T d) {     return sqrt(sq(a - c) + sq(b - d));   }   template <class T>   string toString(T n) {     ostringstream oss;     oss << n;     oss.flush();     return oss.str();   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long bigmod(long long a, long long p, long long mod) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = (res * x) % mod;       x = (x * x) % mod;       p >>= 1;     }     return res;   }   int diraction1[] = {-1, 0, 0, 1, 1, -1, -1, 1};   int diraction2[] = {0, -1, 1, 0, 1, -1, 1, -1};   int horsed1[] = {-2, -2, -1, 1, 2, 2, 1, -1};   int horsed2[] = {1, -1, -2, -2, -1, 1, 2, 2};   void Input();   const int INF = 2147483647;   const long long LINF = 9223372036854775807ll;   bool isok(long long x);   int n, in[100010], tmp[100010];   int main() {     Input();     return 0;   }   void Input() {     cin >> n;     long long sum = 0;     for (int i = 0; i < n; i++) cin >> in[i], sum += in[i];     long long ans = sum / (n - 1);     ans += (bool)(sum % (n - 1));     for (int i = 0; i < n; i++) ans = ans < in[i] ? in[i] : ans;     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma warning(disable : 4996)   using namespace std;   const long long INF = 2147483647;   const double PI = acos(-1);   const int mod = 1e9 + 7;   bool vis[3][120000];   int main() {     long long n, q;     cin >> n >> q;     long long obstacles = 0;     for (int j = 1; j <= q; j++) {       long long x, y;       cin >> x >> y;       long long increment = vis[x][y] == 1 ? -1 : 1;       vis[x][y] = 1 - vis[x][y];       long long dx = x == 2 ? 1 : 2;       for (int i = -1; i <= 1; i++) {         if (vis[dx][y + i]) obstacles += increment;       }       if (obstacles)         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000000;   struct UnionFind {     int par[MAX_N], ra[MAX_N];     void init(int n) {       for (int(i) = 0; (i) < (n); (i)++) par[i] = i, ra[i] = 0;     }     int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }     bool same(int x, int y) { return find(x) == find(y); }     void unite(int x, int y) {       if ((x = find(x)) != (y = find(y))) {         if (ra[x] < ra[y]) swap(x, y);         par[y] = x, ra[x] += (ra[x] == ra[y]);       }     }   };   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long A, B;   string a, b;   int pp[1000000][26];   int sz[1000000];   UnionFind uf;   int main() {     scanf( %I64d%I64d , &A, &B);     cin >> a >> b;     long long al = a.size(), bl = b.size();     long long st = al * bl;     st /= gcd(al, bl);     uf.init(al);     for (int(i) = 0; (i) < (al); (i)++) uf.unite(i, (i + bl) % al);     for (int(i) = 0; (i) < (al); (i)++) {       int ns = uf.find(i);       pp[ns][a[i] -  a ]++;       sz[ns]++;     }     long long ans = 0;     for (int(i) = 0; (i) < (bl); (i)++) {       int ns = uf.find(i % al);       for (int(j) = 0; (j) < (26); (j)++)         if (j != b[i] -  a ) ans += pp[ns][j];     }     long long kkd = A * al / st;     cout << ans * kkd << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10010;   vector<int> v[MAXN];   int childcnt[MAXN] = {0};   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     int root = 0;     for (int i = 1; i <= n; i++) {       if (v[i].size() == 1) {         root = i;         break;       }     }     bool vis[MAXN];     memset(vis, false, sizeof(vis));     queue<int> q;     q.push(root);     vis[root] = true;     int deep = 0;     long long ans = 0;     while (!q.empty()) {       childcnt[deep++] = q.size();       queue<int> p;       while (!q.empty()) {         int cur = q.front();         q.pop();         int len = v[cur].size();         int cnt = 0;         for (int i = 0; i < len; i++) {           if (!vis[v[cur][i]]) {             vis[v[cur][i]] = true;             p.push(v[cur][i]);             cnt++;           }         }         ans += (cnt - 1) * cnt / 2;       }       q = p;     }     for (int i = 2; i < deep; i++) {       ans += childcnt[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   template <class T>   void dbv(T a) {     for (auto x : a) {       cout << x <<   **  ;     }     cout << endl;   }   long long calc(long long in, vector<long long> &a) {     priority_queue<long long> pq;     long long cum = in;     long long cnt = 0;     long long n = a.size();     for (int i = (0); i < (n); ++i) {       pq.push(-a[i]);       cum += a[i];       if (cum < 0) {         cum += pq.top();         pq.pop();         cnt++;       }     }     return cnt;   }   void output() {     long long n, q;     cin >> n >> q;     vector<long long> a(n);     for (int i = (0); i < (n); ++i) {       cin >> a[i];     }     long long st = calc(0, a);     vector<long long> lims;     lims.push_back(0);     for (int val = (st - 1); val >= (0); --val) {       long long low = lims[st - val - 1] + 1;       long long high = LINF;       while (low < high) {         long long mid = (low + high) / 2;         if (calc(mid, a) <= val)           high = mid;         else           low = mid + 1;       }       lims.push_back(low);     }     lims.push_back(1e18);     for (int i = (0); i < (q); ++i) {       long long qu;       cin >> qu;       long long low = 0;       long long high = st + 1;       while (low < high) {         long long mid = (low + high) / 2;         if (qu < lims[mid])           high = mid;         else           low = mid + 1;       }       cout << (st - (low - 1)) << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (int i = (0); i < (t); ++i) {       output();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long n, k, ans, pw[11], a[200005];   map<int, int> w[11];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.precision(30);     cerr.precision(7);     ;     cin >> n >> k;     pw[0] = 1LL;     for (int i = 1; i <= 10; i++) pw[i] = (pw[i - 1] * 10LL) % k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int j = 1; j <= 10; j++) w[j][(a[i] * pw[j]) % k]++;     }     for (int i = 1; i <= n; i++) {       int l = (int)to_string(a[i]).size();       ans += w[l][(k - (a[i] % k)) % k];       ans -= !(((pw[l] * a[i]) % k + a[i]) % k);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long m, n, f[22], inv[22];   inline long long read() {     long long s = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         f = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = (s << 1) + (s << 3) + c -  0 ;       c = getchar();     }     return s * f;   }   inline void write(long long x) {     if (x < 0) {       x = ~(x - 1);       putchar( - );     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   long long power(long long a, long long p) {     long long res = 1;     while (p) {       if (p & 1) res *= a, res %= mod;       p >>= 1;       a *= a;       a %= mod;     }     return res;   }   long long c(long long n, long long m) {     if (n < m || n < 0 || m < 0) {       return 0;     }     n %= mod;     if (n == 0 || m == 0) {       return 1;     }     long long res = 1;     for (long long i = 0; i < m; i++) {       res *= n - i, res %= mod;     }     for (long long i = 1; i <= m; i++) {       res *= inv[i], res %= mod;     }     return res;   }   signed main() {     n = read(), m = read();     for (long long i = 1; i <= n; i++) {       f[i] = read();     }     for (long long i = 1; i <= 20; i++) {       inv[i] = power(i, mod - 2);     }     long long ans = 0;     for (long long i = 1; i < (1 << n); i++) {       long long t = n + m - 1, bit = 0;       for (long long j = 0; j < n; j++) {         if (i & (1 << j)) {           t -= f[j + 1] + 1;           bit++;         }       }       if (bit % 2 == 1) {         ans = (ans + c(t, n - 1)) % mod;       } else {         ans = (ans - c(t, n - 1)) % mod;       }     }     cout << (c(n + m - 1, n - 1) - ans + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long inf = 1000000000;   long n, nn;   long d[40000][100];   long dem[40000];   long tong[40000];   long lon[40000];   long canh[40000][30][2];   long res[40000], kq, mot, hai, ans[40000], cans[40000];   string x, s[40], y;   vector<string> chuoi;   long max(long a, long b) {     if (a > b) return a;     return b;   }   long nap(long u, char v) {     if (d[u][v -  a ]) return d[u][v -  a ];     d[u][v -  a ] = ++nn;     tong[nn] = tong[u] + v -  a  + 1;     lon[nn] = max(v -  a  + 1, lon[u]);     return d[u][v -  a ];   }   void push(string &s) {     long u = 0;     for (long i = 0; i <= s.length() - 1; i++) u = nap(u, s[i]);     dem[u]++;   }   long get(string &s) {     long u = 0;     for (long i = 0; i <= s.length() - 1; i++) {       u = d[u][s[i] -  a ];       if (!u) return u;     }     return u;   }   long dp(long u) {     if (res[u] != -inf) return res[u];     res[u] = -1;     for (long t = 0; t <= 1; t++)       for (long i = 0; i <= 25; i++)         if (canh[u][i][t]) {           long v = canh[u][i][t];           res[u] = max(dp(v), res[u]);         }     res[u] *= -1;     return res[u];   }   void qhd(long u) {     if (ans[u] != -inf) return;     long cost = tong[u] * lon[u] + dem[u];     ans[u] = -1;     cans[u] = -1;     for (long t = 0; t <= 1; t++)       for (long i = 0; i <= 25; i++)         if (canh[u][i][t]) {           long v = canh[u][i][t];           if (res[u] == res[v]) continue;           qhd(v);           if (ans[v] > cans[u]) {             cans[u] = ans[v];             ans[u] = cans[v];           } else if (cans[u] == ans[v] && ans[u] > cans[v])             ans[u] = cans[v];         }     if (ans[u] == -1) ans[u] = 0;     if (cans[u] == -1) cans[u] = 0;     ans[u] += cost;   }   int main() {     cin >> n;     for (long i = 1; i <= n; i++) {       cin >> s[i];       chuoi.clear();       for (long d = s[i].length(); d >= 1; d--) {         for (long u = 0; u <= s[i].length() - d; u++) {           x = s[i].substr(u, d);           chuoi.push_back(x);         }       }       sort(chuoi.begin(), chuoi.end());       push(chuoi[0]);       for (long i = 1; i <= chuoi.size() - 1; i++)         if (chuoi[i] != chuoi[i - 1]) push(chuoi[i]);     }     for (long i = 1; i <= n; i++) {       string ss = s[i];       for (long d = ss.length() - 1; d >= 1; d--) {         for (long u = 0; u <= ss.length() - d; u++) {           long v = u + d - 1;           x = ss.substr(u, d);           long t = get(x);           if (v + 1 < ss.length() && !canh[t][ss[v + 1] -  a ][0]) {             y = ss.substr(u, d + 1);             long tt = get(y);             canh[t][ss[v + 1] -  a ][0] = tt;           }           if (u > 0 && !canh[t][ss[u - 1] -  a ][1]) {             y = ss.substr(u - 1, d + 1);             long tt = get(y);             canh[t][ss[u - 1] -  a ][1] = tt;           }         }       }     }     for (long i = 1; i <= nn; i++) res[i] = -inf;     kq = -1;     for (char c =  a ; c <=  z ; c++) {       x = c;       long u = get(x);       if (!u) continue;       kq = max(dp(u), kq);     }     if (kq == 1)       cout <<  First  << endl;     else       cout <<  Second  << endl;     for (long i = 1; i <= nn; i++) ans[i] = -inf;     long tl = -inf;     long tll;     for (char c =  a ; c <=  z ; c++) {       x = c;       long u = get(x);       if (!u) continue;       if (res[u] != kq) continue;       qhd(u);       long t = ans[u];       if (t > tl) {         tl = t;         tll = cans[u];       } else if (t == tl && cans[u] < tll)         tll = cans[u];     }     cout << tl <<     << tll << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   double fail[310][3100], p[310][3100], val[310], nf[3100];   int main() {     int N, M, i, j, u;     double res;     scanf( %d%d , &N, &M);     for (i = 1; i <= N; i++)       for (j = 1; j <= M; j++) {         scanf( %lf , &p[j][i]);         p[j][i] /= 1000;       }     for (i = 1; i <= M; i++) {       fail[i][0] = 1;       for (j = 1; j <= N; j++) {         fail[i][j] = fail[i][j - 1] * (1 - p[i][j]);       }       val[i] = 1 - fail[i][N];     }     res = 0;     for (i = 1; i <= N; i++) {       u = max_element(val, val + M + 1) - val;       res += val[u];       for (j = 1; j <= N; j++)         nf[j] = nf[j - 1] * (1 - p[u][j]) + fail[u][j - 1] * p[u][j];       memcpy(fail[u], nf, sizeof(nf));       val[u] -= nf[N];     }     printf( %.15lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[1001000];   int g[1001000];   int ans[1001000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i] >> g[i];       ans[i] = 1001000;     }     ans[0] = s[0] + g[0];     for (int i = 0; i < n - 1; i++) {       ans[i + 1] = min(g[i + 1] + s[i + 1], ans[i] + 1);     }     for (int i = n - 1; i > 0; i--) {       ans[i - 1] = min(ans[i] + 1, ans[i - 1]);     }     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += ans[i] - s[i];       if (ans[i] < s[i]) {         cout << -1;         return 0;       }     }     cout << sum << endl;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   const long long int N = 2e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int x, y, a, b;     cin >> x >> y >> a >> b;     vector<pair<long long int, long long int>> mp;     for (int i = a; i <= x; i++) {       for (int j = b; j <= y; j++) {         if (i <= j)           continue;         else {           mp.push_back({i, j});         }       }     }     cout << mp.size() << endl;     for (int i = 0; i < mp.size(); i++) {       cout << mp[i].first <<     << mp[i].second << endl;     }   }


#include <bits/stdc++.h>   char s[100001];   int main() {     int n;     int i, j;     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++)       if (s[i] ==  0 ) break;     if (i == n) {       for (j = 0; j < n - 1; j++) printf( %c , s[j]);       printf(  n );     } else {       for (j = 0; j < i; j++) printf( %c , s[j]);       for (j = i + 1; j < n; j++) printf( %c , s[j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105555;   int a[N];   int main() {     int n;     scanf( %d , &n);     int mn = 1e7, mi, mx = -1e7, xi;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       if (i > 1 && xi < i - 1 && mx > a[i - 1] && a[i - 1] < a[i]) {         printf( 3 n%d %d %d n , xi + 1, i, i + 1);         return 0;       }       if (i > 1 && mi < i - 1 && mn < a[i - 1] && a[i - 1] > a[i]) {         printf( 3 n%d %d %d n , mi + 1, i, i + 1);         return 0;       }       if (a[i] > mx) {         mx = a[i];         xi = i;       }       if (a[i] < mn) {         mn = a[i];         mi = i;       }     }     puts( 0 );   }


#include <bits/stdc++.h>   using namespace std;   set<long long int> blacklist;   long long int par(long long int* parent, long long int f, long long int n) {     if (parent[f] < 0) return parent[f];     if (parent[f] == f)       return f;     else {       parent[f] = par(parent, parent[f], n);       return parent[f];     }   }   void unio(long long int* parent, long long int f, long long int s,             long long int pf, long long int ps) {     if (pf < ps)       parent[ps] = pf;     else       parent[pf] = ps;   }   void utilfun(long long int* parent, vector<long long int>* adj,                pair<long long int, long long int>* edge, long long int n,                long long int m, long long int a, long long int b) {     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if (f == a || f == b || s == a || s == b) {         continue;       } else {         long long int pf = par(parent, f, n);         long long int ps = par(parent, s, n);         unio(parent, f, s, pf, ps);       }     }     long long int ind = -2;     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if ((f == a || s == a) && (s != b && f != b)) {         long long int ot = f + s - a;         long long int pot = par(parent, ot, n);         if (pot >= 0) {           parent[pot] = ind;           ind--;         }       }     }     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if ((f == b || s == b) && (s != a && f != a)) {         long long int ot = f + s - b;         long long int pot = par(parent, ot, n);         if (pot == -1) {           continue;         } else if (pot < -1) {           blacklist.insert(pot);         } else           parent[pot] = b;       }     }   }   int main() {     long long int t;     cin >> t;     while (t--) {       blacklist.clear();       long long int n, m, a, b;       cin >> n >> m >> a >> b;       a--;       b--;       vector<long long int> adj[n];       pair<long long int, long long int> edge[m];       long long int parent[n];       for (long long int i = 0; i < n; i++) parent[i] = i;       for (long long int i = 0; i < m; i++) {         long long int x, y;         cin >> x >> y;         x--;         y--;         adj[x].push_back(y);         adj[y].push_back(x);         edge[i] = {x, y};       }       utilfun(parent, adj, edge, n, m, a, b);       long long int ac = 0;       long long int bc = -1;       set<long long int>::iterator itr;       for (long long int i = 0; i < n; i++) {         long long int pot = par(parent, i, n);         if (blacklist.find(pot) != blacklist.end()) continue;         if (pot < -1)           ac++;         else if (pot == b)           bc++;       }       cout << ac * bc <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long int n;       scanf( %lld , &n);       printf( %lld n , n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class TaskC {    public:     void solve(std::istream& in, std::ostream& out);   };   void TaskC::solve(std::istream& in, std::ostream& out) {     int n;     in >> n;     int a[310][310];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; ++j) {         in >> a[i][j];       }     }     int k;     in >> k;     while (k--) {       int x, y, c;       in >> x >> y >> c;       --x, --y;       a[x][y] = min(a[x][y], c);       a[y][x] = min(a[y][x], c);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           a[i][j] = min(a[i][j], min(a[i][x] + a[x][y] + a[y][j],                                      a[i][y] + a[y][x] + a[x][j]));         }       }       long long ans = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < i; ++j) ans += (long long)a[i][j];       }       out << ans <<    ;     }   };   int main() {     TaskC solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int ans = -1e18;     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         vector<long long int> in, out;         long long int sum = 0;         for (long long int k = 0; k < n; k++) {           if (k < i || k > j)             out.push_back(a[k]);           else             in.push_back(a[k]), sum += a[k];         }         sort((in).begin(), (in).end());         sort((out).rbegin(), (out).rend());         long long int l = 0, r = 0, s = k;         while (l < (long long int)in.size() && r < (long long int)out.size() &&                s-- > 0) {           if (in[l] < out[r]) sum += out[r] - in[l];           l++, r++;         }         ans = max(ans, sum);       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int test_cases = 1;     while (test_cases--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int SIZ = 500;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) {         f = -1;       }       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   struct note {     int t;     int next;   };   int cnt;   int head[N];   note e[N << 1];   inline void add(int x, int y) {     e[++cnt].t = y;     e[cnt].next = head[x];     head[x] = cnt;   }   int n, m;   namespace tl {   int cnt;   int id[N], iid[N];   int fa[N];   int top[N], son[N], siz[N];   void dfs1(int p, int f) {     fa[p] = f;     siz[p] = 1;     for (int i = head[p]; i + 1; i = e[i].next) {       int t = e[i].t;       if (t == f) {         continue;       }       dfs1(t, p);       siz[p] += siz[t];       if (siz[t] > siz[son[p]]) {         son[p] = t;       }     }   }   void dfs2(int p, int top_p) {     id[p] = ++cnt;     iid[cnt] = p;     top[p] = top_p;     if (son[p]) {       dfs2(son[p], top_p);     }     for (int i = head[p]; i + 1; i = e[i].next) {       int t = e[i].t;       if (t == fa[p] || t == son[p]) {         continue;       }       dfs2(t, t);     }   }   int bol;   int idb[N];   int tag[N / SIZ + 10];   int l[N / SIZ + 10], r[N / SIZ + 10];   int col[N];   int sum[N / SIZ + 10][N << 1];   int t[N];   int a[N];   inline void input() {     for (int i = 1; i <= n; i++) {       read(t[i]);       t[i]++;     }   }   inline void init() {     dfs1(1, -1);     dfs2(1, 1);     for (int i = 1; i <= n; i++) {       idb[i] = (i - 1) / SIZ + 1;       if (idb[i] != idb[i - 1]) {         r[idb[i - 1]] = i - 1;         l[idb[i]] = i;       }     }     r[idb[n]] = n;     for (int i = 1; i <= n; i++) {       a[id[i]] = n - t[i];     }     for (int i = 1; i <= n; i++) {       sum[idb[i]][a[i]]++;     }   }   int ans;   inline void update(int l, int r, int val) {     for (int i = l; i <= r; i++) {       int o = idb[i];       if (!col[i] && a[i] >= n - tag[o]) {         ans--;       }       if (!col[i]) {         sum[o][a[i]]--;       }       a[i] += val;       if (!col[i]) {         sum[o][a[i]]++;       }       if (!col[i] && a[i] >= n - tag[o]) {         ans++;       }     }   }   inline void modify(int L, int R, int val) {     int x = idb[L], y = idb[R];     if (x == y) {       update(L, R, val);       return;     }     update(L, r[x], val);     update(l[y], R, val);     for (int i = x + 1; i <= y - 1; i++) {       if (val == 1) {         tag[i]++;         ans += sum[i][n - tag[i]];       } else {         ans -= sum[i][n - tag[i]];         tag[i]--;       }     }   }   inline void query(int x) {     int val = (x > 0) ? 1 : -1;     x = abs(x);     col[id[x]] ^= 1;     if (a[id[x]] >= n - tag[idb[id[x]]]) {       ans -= val;     }     sum[idb[id[x]]][a[id[x]]] -= val;     while (x + 1) {       modify(id[top[x]], id[x], val);       x = fa[top[x]];     }     printf( %d  , ans);   }   }  // namespace tl   int main() {     memset(head, -1, sizeof(head));     read(n), read(m);     for (int i = 2; i <= n; i++) {       int x;       read(x);       add(x, i);       add(i, x);     }     tl::input();     tl::init();     for (int i = 1; i <= m; i++) {       int x;       read(x);       tl::query(x);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[1111111];   int B[1111111];   int main(void) {     int alen = 0;     int blen = 0;     scanf( %d %d , &alen, &blen);     for (int i = 0; i < alen; i++) scanf( %d , &A[i]);     memset(B, -1, sizeof(B));     for (int i = 0; i < blen; i++) {       int x = 0;       scanf( %d , &x);       B[x] = i;     }     deque<int> Queue;     int ans = 0;     for (int i = 0; i < 2 * alen; i++) {       int where = B[A[i % alen]];       if (where != -1) {         while (Queue.size() >= 2 &&                !((Queue.front() < Queue.back() &&                   (Queue.back() < where || where < Queue.front())) ||                  (Queue.front() > Queue.back() && Queue.back() < where &&                   where < Queue.front())))           Queue.pop_front();         Queue.push_back(where);       } else         Queue.clear();       ans = max<int>(ans, Queue.size());     }     ans = min(ans, alen);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   const int N = 3e4 + 10;   long long ri() {     char c = getchar();     long long x = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) -  0  + c;     return x * f;   }   long long len[66];   int n, d, m, tot, gen[25], b[N];   std::bitset<N> all;   struct info {     long long ans, len;     std::bitset<N> pre, suf;     info operator+(const info &b) {       info c;       c.ans = ans + b.ans;       c.len = len + b.len;       c.pre = pre;       c.suf = b.suf;       if (len < n - 1) c.pre &= (b.pre << len) | (all >> n - 1 - len);       if (b.len < n - 1) c.suf &= (suf >> b.len) | (all << n - 1 - b.len);       if (len + b.len >= n) {         std::bitset<N> res = suf & b.pre;         if (len < n - 1) res &= (all << n - 1 - len);         if (b.len < n - 1) res &= (all >> n - 1 - b.len);         c.ans += res.count();       }       return c;     }     void operator+=(const info &b) { *this = !len ? b : *this + b; }   } f[66][66];   long long Query(long long x) {     info res;     res.ans = res.len = 0;     int add = 0;     for (int i = tot; ~i; --i)       for (int j = 1; j <= d; ++j) {         if (x >= len[i]) {           x -= len[i];           res += f[i][(add + gen[j]) % m];         } else {           (add += gen[j]) %= m;           break;         }       }     return res.ans;   }   int main() {     d = ri();     m = ri();     for (int i = 1; i <= d; ++i) gen[i] = ri();     n = ri();     for (int i = 1; i <= n; ++i) b[i] = ri();     for (int i = 1; i < n; ++i) all.set(i);     len[tot = 0] = 1;     for (int i = 0; i < m; ++i) {       f[0][i].len = 1;       if (n == 1)         f[0][i].ans = i <= b[1];       else {         for (int j = 1; j <= n - 1; ++j) {           f[0][i].pre[j] = i <= b[n - j + 1];           f[0][i].suf[j] = i <= b[n - j];         }       }     }     long long L = ri(), R = ri();     for (; len[tot] <= R / d;) {       ++tot;       len[tot] = len[tot - 1] * d;       for (int i = 0; i < m; ++i)         for (int j = 1; j <= d; ++j) f[tot][i] += f[tot - 1][(i + gen[j]) % m];     }     printf( %lld n , Query(R) - Query(L + n - 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     int n, m;     std::vector<int> r;     std::vector<std::vector<int>> d;     std::vector<std::vector<std::array<int, 2>>> v;     std::vector<bool> visited;     std::vector<int> val;     void dfs(int cur, int col) {       visited[cur] = true;       val[cur] = col;       for (auto next : v[cur]) {         if (visited[next[0]]) continue;         dfs(next[0], col ^ next[1]);       }     }     void solve(std::istream& in, std::ostream& out) {       in >> n >> m;       r.resize(n);       d.resize(n);       for (auto& el : r) in >> el;       for (int i = 0; i < m; ++i) {         int x;         in >> x;         for (int j = 0; j < x; ++j) {           int a;           in >> a;           --a;           d[a].push_back(i);         }       }       v.resize(m);       val.resize(m);       for (int i = 0; i < n; ++i) {         v[d[i][0]].push_back({d[i][1], !r[i]});         v[d[i][1]].push_back({d[i][0], !r[i]});       }       visited.resize(m);       for (int i = 0; i < m; ++i) {         if (!visited[i]) {           dfs(i, 0);         }       }       for (int i = 0; i < n; ++i)         if ((val[d[i][0]] ^ val[d[i][1]]) != (!r[i])) return void(out <<  NO n );       out <<  YES n ;     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long pref1[N + 5];   long long pref2[N + 5];   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, type, l, r;     cin >> n;     n++;     int arr[n];     for (int i = 1; i < n; i++) {       cin >> arr[i];       pref1[i] = pref1[i - 1] + arr[i];     }     sort(arr + 1, arr + n);     for (int i = 1; i < n; i++) pref2[i] = pref2[i - 1] + arr[i];     cin >> m;     while (m--) {       cin >> type >> l >> r;       if (type == 1)         ans = pref1[r] - pref1[l - 1];       else         ans = pref2[r] - pref2[l - 1];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     vector<int> b(n);     for (i = 0; i < n - 1; i++) {       b[i] = a[i] + a[i + 1];     }     b[n - 1] = a[n - 1];     for (i = 0; i < n; i++) {       printf( %d  , b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(string a, string b) { return (a.length() > b.length()); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.setf(ios::fixed);     cout.setf(ios::showpoint);     {       long long int n, x, y;       cin >> n >> x >> y;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       for (long long int i = 0; i < n; i++) {         long long int c = 0;         for (long long int j = max(0LL, i - x); j < i; j++)           if (a[j] < a[i]) c++;         for (long long int j = i + 1; j < min(n, i + y + 1); j++)           if (a[j] < a[i]) c++;         if (!c) {           cout << i + 1;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> re;   int main() {     cin >> n;     int least[n];     for (int i = 0; i < n; i++) cin >> least[i];     sort(least, least + n);     int cont = 0;     for (int i = 1; i < n; i++) {       if (least[i] == least[i - 1]) {         re.push_back(least[i]);         least[i - 1] = -1;         cont++;       } else {         cont = 0;       }       if (cont >= 2) {         cout <<  NO  << endl;         return 0;       }     }     sort(re.begin(), re.end());     cout <<  YES  << endl;     cout << n - re.size() << endl;     for (int i = 0; i < n; i++) {       if (least[i] == -1) continue;       cout << least[i] <<    ;     }     cout << endl;     cout << re.size() << endl;     for (int i = re.size() - 1; i >= 0; i--) cout << re[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void optimise() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int mod = 1e6 + 3;   void normalize(long long int &a) { a = (a + mod) % mod; }   long long int modmul(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a * b) % mod;   }   long long int modadd(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a + b) % mod;   }   long long int modsub(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a - b + mod) % mod;   }   long long int me(long long int x, long long int n) {     x %= mod;     if (n == 0) return 1;     long long int u = me(x, n / 2) % mod;     u = (u * u) % mod;     if (n % 2) u = (u * x) % mod;     return u;   }   long long int me1(long long int x, long long int n) {     if (n == 0) return 1;     long long int u = me1(x, n / 2);     u = u * u;     if (n % 2) u = u * x;     return u;   }   inline long long int modInv(long long int a) { return me(a, mod - 2); }   inline long long int modDiv(long long int a, long long int b) {     return modmul(a, modInv(b));   }   float power(float x, long long int y) {     float temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       if (y > 0)         return x * temp * temp;       else         return (temp * temp) / x;     }   }   long long int __gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return __gcd(b, a % b);   }   const long long int N = 1e9 + 1;   bool compare(pair<long long int, pair<long long int, long long int>> a,                pair<long long int, pair<long long int, long long int>> b) {     if (a.first > b.first) return true;     if (a.first == b.first) {       if (a.second.first > b.second.first)         return true;       else if (a.second.first == b.second.first) {         return a.second.second > b.second.second;       }       return false;     }     return false;   }   struct FenwickTree {     map<long long int, long long int> f;     void insert(long long int k, long long int x) {       while (k < N) {         f[k] = max(x, f[k]);         k += (k & (-k));       }     }     long long int sum(long long int r) {       long long int ans = 0;       while (r > 0) {         ans = max(f[r], ans);         r -= ((r) & (-r));       }       return ans;     }   } ft;   void solve() {     long long int n;     cin >> n;     vector<pair<long long int, pair<long long int, long long int>>> v(n);     for (long long int i = 0; i < n; i++) {       cin >> v[i].second.first >> v[i].first >> v[i].second.second;     }     sort(v.begin(), v.end(), compare);     queue<pair<long long int, pair<long long int, long long int>>> q;     long long int max1 = 0;     for (long long int i = 0; i < n; i++) {       auto k1 = v[i];       long long int k2 = ft.sum(k1.first - 1);       max1 = max(max1, k2 + k1.second.second);       ft.insert(k1.second.first, k2 + k1.second.second);     }     cout << max1;   }   signed main() {     optimise();     long long int t;     t = 1;     cout << fixed << setprecision(5);     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5, P = 1e9 + 7;   struct Trie {     int ch[2], siz, mn, mx;   } t[N * 32];   int n, a[N], cntnode = 1, s[N][33], rt[N], ans;   long long kth, m;   void Insert(int x) {     int now = 1;     t[now].siz++;     for (int i = 31; ~i; --i) {       int& nxt = t[now].ch[a[x] >> i & 1];       if (!nxt) nxt = ++cntnode, t[nxt].mn = x;       now = nxt;       ++t[now].siz;       t[now].mx = x;     }   }   int calc(int v, int l, int r) {     if (!l) return 0;     int res = 0;     for (int i = 31; ~i; --i) {       int p = v >> i & 1;       if (!p)         (res += (1LL << i) * (s[r][i] - s[l - 1][i]) % P) %= P;       else         (res += (1LL << i) * (r - l + 1 - s[r][i] + s[l - 1][i]) % P) %= P;     }     return res;   }   int main() {     scanf( %d%lld , &n, &m);     m *= 2;     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       Insert(i);       for (int j = 31; ~j; --j) s[i][j] = s[i - 1][j] + (a[i] >> j & 1);     }     for (int i = 1; i <= n; ++i) rt[i] = 1;     for (int i = 31; ~i; --i) {       long long tot = 0;       int z;       for (int j = 1; j <= n; ++j) {         int p = (a[j] >> i & 1) ^ 1;         tot += t[t[rt[j]].ch[p]].siz;       }       if (tot >= m)         z = 1, kth |= 1LL << i;       else         z = 0, m -= tot;       for (int j = 1; j <= n; ++j) rt[j] = t[rt[j]].ch[(a[j] >> i & 1) ^ z];     }     for (int i = 1; i <= n; ++i) {       int now = 1;       for (int j = 31; ~j; --j) {         int p = (a[i] ^ kth) >> j & 1;         if (!(kth >> j & 1) && t[now].ch[p ^ 1])           (ans += calc(a[i], t[t[now].ch[p ^ 1]].mn, t[t[now].ch[p ^ 1]].mx)) %=               P;         now = t[now].ch[p];       }     }     printf( %lld , 1LL * (kth * m % P + ans) % P * (P + 1 >> 1) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   vector<pair<int, int> > g[maxn];   set<pair<int, int> > s;   int c[maxn], dis[maxn];   void dijekstra(int u) {     dis[u] = 0;     s.insert(make_pair(u, dis[u]));     while (s.size()) {       pair<int, int> a = *s.begin();       s.erase(a);       for (int i = 0; i < g[a.first].size(); i++) {         if (a.second + g[a.first][i].second < dis[g[a.first][i].first]) {           s.erase(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));           dis[g[a.first][i].first] = a.second + g[a.first][i].second;           s.insert(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));         }       }     }     s.clear();   }   int main() {     ios_base::sync_with_stdio(false);     memset(dis, 63, sizeof(dis));     int n, x, y;     cin >> n;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 0; i < n - 1; i++) {       cin >> x >> y;       if (c[x] == c[y]) {         g[x].push_back(make_pair(y, 0));         g[y].push_back(make_pair(x, 0));       } else {         g[x].push_back(make_pair(y, 1));         g[y].push_back(make_pair(x, 1));       }     }     dijekstra(1);     int mx = -1, j;     for (int i = 1; i <= n; i++)       if (dis[i] > mx) mx = dis[i], j = i;     memset(dis, 63, sizeof(dis));     dijekstra(j);     mx = -1;     for (int i = 1; i <= n; i++)       if (dis[i] > mx) mx = dis[i], j = i;     cout << (dis[j] + 1) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[100003][3], ara[100003], mod = 1000000007, n, m;   long long solve(long long idx, long long sta) {     if (idx == n) {       if (sta == 0 || sta == 2)         return 1;       else {         return 0;       }     } else if (dp[idx][sta] != -1)       return dp[idx][sta];     else {       long long p = 0, q = 0, r = 0, t, x, y, z;       if (sta == 0) {         p = solve(idx + 1, 0);         x = 1;         z = idx + 1;         if (ara[idx] == 1) {           x = 2;           z = idx + m;         }         q = solve(z, x);       } else if (sta == 1) {         x = 1;         z = idx + 1;         if (ara[idx] == 1) {           x = 2;           z = idx + m;         }         q = solve(z, x);       } else {         p = solve(idx, 0);         q = solve(idx + 1, sta);       }       t = (p + q) % mod;       dp[idx][sta] = t;       return dp[idx][sta];     }   }   int main() {     long long i, k, ans = 1, sc = 1;     string str, ttr, ntr;     cin >> str;     cin >> ttr;     n = str.size();     m = ttr.size();     if (n >= m) {       for (i = 0; i <= n - m; i++) {         if (str[i] == ttr[0]) {           ntr = str.substr(i, m);           if (ntr == ttr) {             ara[i] = 1;           }         }         dp[i][0] = -1;         dp[i][1] = -1;         dp[i][2] = -1;       }     }     if (n >= m) {       for (i = n - m; i <= n; i++) {         dp[i][0] = -1;         dp[i][1] = -1;         dp[i][2] = -1;       }       ans = solve(0, 0);     }     if (ans >= sc)       k = ans - sc;     else {       k = (mod - sc) + ans;     }     printf( %lld n , k);     return 0;   }


#include <bits/stdc++.h>   void read(int& x) {     x = 0;     char c;     do {       c = getchar();     } while (c <  0  || c >  9 );     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }   }   using namespace std;   int n, m, f[1000 + 5][1000 + 5], ans, sum[1000 + 5];   int s[100000 + 5][3], as[100000 + 5];   vector<int> v[100000 + 5];   void place(int x, int y) {     f[x][y] = !f[x][y];     ans++;     sum[x]++;   }   void remove(int x, int y) {     f[x][y] = !f[x][y];     ans--;     sum[x]--;   }   void invert(int x) {     f[x][0] = !f[x][0];     ans -= sum[x];     sum[x] = m - sum[x];     ans += sum[x];   }   void dfs(int k) {     int o = 0, t, x, y, i;     t = s[k][0];     x = s[k][1];     y = s[k][2];     if (t == 1)       if (f[x][y] ^ f[x][0] ^ 1)         place(x, y);       else         o = 1;     if (t == 2)       if (f[x][y] ^ f[x][0])         remove(x, y);       else         o = 1;     if (t == 3) invert(x);     as[k] = ans;     for (i = 0; i < v[k].size(); i++) dfs(v[k][i]);     if (o) return;     if (t == 1) remove(x, y);     if (t == 2) place(x, y);     if (t == 3) invert(x);   }   int main() {     int q, x, y, i;     read(n);     read(m);     read(q);     for (i = 1; i <= q; i++) {       read(s[i][0]);       read(s[i][1]);       if (s[i][0] < 3) read(s[i][2]);       if (s[i][0] < 4)         v[i - 1].push_back(i);       else         v[s[i][1]].push_back(i);     }     dfs(0);     for (i = 1; i <= q; i++) printf( %d n , as[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int64_t n;     cin >> n;     multiset<int64_t> S;     if (n & 1) {       n--;       cout << n / 2 << endl;       while (n) {         S.insert(2);         n = n - 2;       }       auto itr = S.end();       itr--;       S.erase(itr);       S.insert(3);     } else {       cout << n / 2 << endl;       while (n) {         S.insert(2);         n = n - 2;       }     }     for (auto itr = S.begin(); itr != S.end(); itr++) {       cout << (*itr) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     while (cin >> n) {       string s;       getline(cin, s);       getline(cin, s);       stringstream ss(s);       string token;       string res =   ;       vector<int> numelements;       bool error = 0;       if (s ==  int ) {         cout <<  int  << endl;         continue;       }       while (ss >> token) {         int cur = numelements.size() - 1;         if (cur >= 0 && numelements[cur] == 1) res +=  , ;         if (token ==  pair ) {           if (cur >= 0) {             numelements[cur]++;             if (numelements[cur] >= 3) {               error = 1;               break;             }           }           res +=  pair< ;           numelements.push_back(0);         } else if (token ==  int ) {           if (cur < 0) {             error = 1;             break;           }           numelements[cur]++;           res +=  int ;           if (numelements[cur] >= 3) {             error = 1;             break;           }           while (numelements.size() > 0 &&                  numelements[numelements.size() - 1] == 2) {             numelements.erase(numelements.end() - 1);             res +=  > ;           }         }       }       if (numelements.size() > 0) error = 1;       if (error)         cout <<  Error occurred  << endl;       else         cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, l, m, n, x, y, z;     cin >> n >> x >> y;     string s;     cin >> s;     for (i = 0; i < n; i++) {       if (s[i] ==  0 ) break;     }     if (i == n) return cout << 0 << endl, 0;     for (j = s.size() - 1; j >= 0; j--)       if (s[j] ==  0 ) break;     s = s.substr(i, j - i + 1);     long long int cnt = 0;     for (i = 1; i < s.size(); i++) {       if (s[i] ==  0  && s[i - 1] ==  1 ) cnt++;     }     cnt++;     cout << (cnt - 1) * min(x, y) + y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int N = 2e5 + 5;   int gcd(int a, int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   bool compare(long long i, long long j) { return i > j; }   long long power(long long x, long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return (power(x, y / 2) % mod * power(x, y / 2) % mod) % mod;     else       return (x % mod * power(x, y / 2) % mod * power(x, y / 2) % mod) % mod;   }   class sortByVal {    public:     bool operator()(const pair<long long, pair<long long, long long>> &a,                     const pair<long long, pair<long long, long long>> &b) {       if (a.first != b.first) {         return a.first < b.first;       }       return a.second.first > b.second.first;     }   };   bool prime[100005];   void SieveOfEratosthenes(long long n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, n, m;       cin >> a >> b >> n >> m;       if (n + m > a + b) {         cout <<  NO  << endl;         ;       } else {         if (m > min(a, b)) {           cout <<  NO  << endl;           ;         } else           cout <<  YES  << endl;         ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( A.in );   ofstream fout( A.out );   long long r, h;   int main() {     cin >> r >> h;     if (h % r == 0) {       cout << (h / r) * 2 + 1;       return 0;     }     double d = double(h) / double(r);     int z = h / r;     double dd = z + 0.5;     if (d >= dd) {       if ((r / 2) * (r / 2) + ((d - dd) * r + r / 2) * ((d - dd) * r + r / 2) >=           r * r)         cout << 2 * z + 3;       else         cout << 2 * z + 2;     } else {       cout << 2 * z + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   void CP() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     return;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int a[n + 1];     a[1] = 1;     for (int i = 2; i <= n; i++) {       a[i] = a[i - 1] + i;     }     for (int i = 1; i <= n; i++) {       cerr << a[i] <<    ;     }     cerr << endl;     if (m == 1) {       m -= 1;     } else {       if (m > a[n]) {         m %= a[n];         cerr << m << endl;       }       int i;       for (i = n - 1; i > 1; i--) {         if (m >= a[i]) {           m %= a[i];           break;         }       }       if (i == 1 && m != 0) {         m -= 1;       }     }     cout << m << endl;     return 0;   }


#include<bits/stdc++.h>   #define fast  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define arin(x,n) for(int i=0;i<n;i++)cin>>x[i]   #define debug(x,n) for(int i=0;i<n;i++)cout<<x[i]<<      #define pb push_back   #define all(c) begin(c), end(c)   #define isAll(c) (int)(c).size()   typedef long long int ll;       using namespace std;      int solve(vector <pair<int, int>> &arr)   {       int num = isAll(arr);       vector <int> lc(num);        vector <int> rc(num);          for (int i = 0; i < num; i++)           lc[i] = arr[i].first, rc[i] = arr[i].second;          sort(all(lc)), sort(all(rc));          int result = 1e9 + 7;       for (auto [l, r] : arr)       {           int result_l = distance(begin(rc), lower_bound(all(rc), l)),               result_r = distance(upper_bound(all(lc), r), end(lc));                 result = min(result, result_l + result_r);       }       return result;   }       int main()   {    fast;    ll T=1;    cin>>T;    while(T--)    {     int num;     cin >> num;        vector <pair<int, int>> arr(num);     for(auto &[x, y] : arr)       cin >> x >> y;             cout << solve(arr) << endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, a, b;       string s =   , s1;       cin >> n >> a >> b;       for (int i = 0; i < b; i++) s += ( a  + i);       for (int i = b; i < a; i++) s +=  a ;       s1 = s;       int x = n / a, y = n % a;       x--;       while (x--) {         s += s1;       }       for (int i = 0; i < y; i++) s += s1[i];       cout << s << endl;     }   }


#include <bits/stdc++.h>   inline long long read() {     long long x = 0;     char ch = getchar(), w = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * w;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   using namespace std;   const int N = 5e5 + 656666;   long long n, m, c, c0;   struct TT {     long long t, a, b;   } a[N];   bool cmp(TT x, TT y) { return x.t < y.t; }   map<long long, long long> q;   long long cal() {     q.clear();     long long ans = 0;     q[0] = c0;     long long now = c0, cap = c;     for (int i = 1; i <= n; ++i) {       long long rest = a[i].t - a[i - 1].t;       long long val = 0;       now -= rest;       while (!q.empty() && rest) {         val = min(rest, q.begin()->second);         rest -= val;         q.begin()->second -= val;         ans += val * q.begin()->first;         if (!q.begin()->second) q.erase(q.begin());       }       if (rest) return -1;       long long ned = min(cap - now, a[i].a);       now += ned;       while (!q.empty() && a[i].b < q.rbegin()->first && ned < a[i].a) {         val = min(q.rbegin()->second, a[i].a - ned);         q.rbegin()->second -= val;         ned += val;         if (!q.rbegin()->second) q.erase(--q.end());       }       q[a[i].b] += ned;     }     return ans;   }   int main() {     int T = read();     while (T--) {       n = read(), m = read(), c = read(), c0 = read();       for (int i = 1; i <= n; ++i) {         a[i].t = read();         a[i].a = read();         a[i].b = read();       }       a[++n] = (TT){m, 0, 0};       sort(a + 1, a + 1 + n, cmp);       writeln(cal());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void task() {     int s, t, q, r = 1;     long long tm, cs;     cin >> t >> s >> q;     cs = s;     while (cs < t) {       tm = cs;       cs = (q - 1) * tm + cs;       if (cs < t) r++;     }     cout << r;   }   int main() {     ios_base::sync_with_stdio(false);     task();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr <<   n ; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << setw(2) << *it <<   =   << setw(2) << a <<    ;     err(++it, args...);   }   void solve() {     int n;     cin >> n;     int a[n], status[n], res[n];     memset(res, 0, sizeof res);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> status[i];     for (int i = 0; i < n; i++)       if (status[i]) res[i] = a[i];     vector<int> v;     for (int i = 0; i < n; i++) {       if (status[i] == 0) v.push_back(a[i]);     }     sort(v.rbegin(), v.rend());     int idx = 0;     for (int i = 0; i < n; i++)       if (status[i] == 0) res[i] = v[idx++];     for (int i = 0; i < n; i++) cout << res[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int test;     cin >> test;     while (test--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[1000000];   vector<pair<int, int> > ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= k; i++) {       int high = 1, low = 1;       for (int j = 2; j <= n; j++) {         if (a[j] > a[high]) high = j;         if (a[j] < a[low]) low = j;       }       if (high != low) {         ans.push_back(make_pair(high, low));         a[high]--;         a[low]++;       }     }     int high = 1, low = 1;     for (int j = 2; j <= n; j++) {       if (a[j] > a[high]) high = j;       if (a[j] < a[low]) low = j;     }     int s = ans.size();     cout << a[high] - a[low] <<     << s << endl;     ;     for (int i = 0; i <= s - 1; i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 44, MS = (1 << 21) + 2;   int n, K;   long long adj[MN];   int dp[MS], clique;   bool is[MS];   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> K;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         bool t;         cin >> t;         adj[i] |= (1ll << j) * t;       }     if (n == 1) return cout <<  0 n , 0;     int b = n / 2;     for (int msk = 1; msk < (1 << b); ++msk) {       int v = __builtin_ctz(msk);       dp[msk] = dp[msk ^ (1 << v)];       dp[msk] = max(dp[msk], dp[(msk ^ (1 << v)) & adj[v]] + 1);       clique = max(clique, dp[msk]);     }     is[0] = true;     for (int msk = 1; msk < (1 << (n - b)); ++msk) {       int v = __builtin_ctz(msk);       is[msk] = is[msk ^ (1 << v)];       v += b;       for (int i = b; i < n; ++i)         if (i != v) {           if ((msk & (1 << (i - b))) && !(adj[v] & (1ll << i))) is[msk] = false;         }       if (is[msk]) {         long long M = (1 << b) - 1;         for (int i = b; i < n; ++i)           if (msk & 1 << (i - b)) M &= adj[i];         clique = max(clique, dp[M] + __builtin_popcount(msk));       }     }     cout << setprecision(12) << fixed          << 1ll * clique * (clique - 1) * ((long double)K / clique) *                 ((long double)K / clique) / 2          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, int> > v;   int n;   long long A[100005];   long long B[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d %d , &a, &b);       A[i] = (long long)a;       B[i] = (long long)b;       v.push_back(make_pair((long long)(b - a), i));     }     sort(v.begin(), v.end());     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long a = A[v[i - 1].second];       long long b = B[v[i - 1].second];       ans += a * ((long long)(i - 1)) + b * ((long long)(n - i));     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, string> mapa;   int main() {     mapa[0] =  zero ;     mapa[1] =  one ;     mapa[2] =  two ;     mapa[3] =  three ;     mapa[4] =  four ;     mapa[5] =  five ;     mapa[6] =  six ;     mapa[7] =  seven ;     mapa[8] =  eight ;     mapa[9] =  nine ;     mapa[10] =  ten ;     mapa[11] =  eleven ;     mapa[12] =  twelve ;     mapa[13] =  thirteen ;     mapa[14] =  fourteen ;     mapa[15] =  fifteen ;     mapa[16] =  sixteen ;     mapa[17] =  seventeen ;     mapa[18] =  eighteen ;     mapa[19] =  nineteen ;     mapa[20] =  twenty ;     mapa[30] =  thirty ;     mapa[40] =  forty ;     mapa[50] =  fifty ;     mapa[60] =  sixty ;     mapa[70] =  seventy ;     mapa[80] =  eighty ;     mapa[90] =  ninety ;     int num;     cin >> num;     if (num <= 19) {       cout << mapa[num] << endl;     } else if (num % 10 == 0) {       cout << mapa[num] << endl;     } else {       int aux = (num / 10) * 10;       int rest = num % 10;       cout << mapa[aux] <<  -  << mapa[rest] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a = 0;     cin >> x >> y;     for (int i = 1; i <= x; i++) {       if (i % 2 == 0) {         if (a == 0) {           for (int k = 0; k < y - 1; k++) {             cout <<  . ;           }           cout <<  #  << endl;           a++;         } else {           a = 0;           cout <<  # ;           for (int k = 0; k < y - 1; k++) {             if (k == y - 2) {               cout <<  .  << endl;             } else {               cout <<  . ;             }           }         }       } else {         for (int j = 0; j < y; j++) {           if (j == y - 1) {             cout <<  #  << endl;           } else {             cout <<  # ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int A, B, i;     long long int sum = 0;     int a[100001] = {0};     cin >> A;     cin >> B;     for (i = 0; i < A; i++) {       cin >> a[i];     }     qsort(a, A, sizeof(int), cmpfunc);     for (i = 1; i < A; i++) {       if ((a[i] - a[0]) % B == 0)         sum = sum + (a[i] - a[0]) / B;       else {         sum = -1;         break;       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   bool vis[26];   int main() {     cin >> s;     long long ans = 1;     int cnt1 = 0;     int cnt2 = 0;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ? )         cnt2++;       else if (s[i] >=  A  && s[i] <=  Z ) {         if (vis[s[i] -  A ] == 1)           continue;         else           vis[s[i] -  A ] = 1, cnt1++;       }     }     if (cnt1)       if (s[0] >=  A  && s[0] <=  Z )         ans = 9;       else         ans = 10;     for (int i = 9; i > 9 - cnt1 + 1; i--) ans *= i;     if (cnt2)       if (s[0] ==  ? )         ans *= 9;       else         ans *= 10;     for (int i = 1; i < cnt2; i++) ans *= 10;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const long long INF = 1e9 + 19;   const int LOG = 11;   int n, m;   int a[N][N];   int b[N][N];   int pref[N][N];   short table[LOG][LOG][N][N];   int deg[N];   void read() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);   }   int getSum(int x1, int y1, int x2, int y2) {     return pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];   }   bool isSquare(int x1, int y1, int x2, int y2) {     return (x2 - x1) * (y2 - y1) == getSum(x1, y1, x2, y2);   }   int getMax(int x1, int y1, int x2, int y2) {     int szX = x2 - x1;     int szY = y2 - y1;     int dx = deg[szX];     int dy = deg[szY];     int tmp = max(max(table[dx][dy][x1][y1], table[dx][dy][x2 - (1 << dx)][y1]),                   max(table[dx][dy][x1][y2 - (1 << dy)],                       table[dx][dy][x2 - (1 << dx)][y2 - (1 << dy)]));     return tmp;   }   void solve() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         pref[i + 1][j + 1] =             pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int l = 0;         int r = min(n - i, m - j) + 1;         while (r - l > 1) {           int mid = (l + r) / 2;           if (isSquare(i, j, i + mid, j + mid))             l = mid;           else             r = mid;         }         b[i][j] = l;       }     for (int i = 2; i <= max(n, m); i++) deg[i] = deg[i / 2] + 1;     for (int dx = 0; dx <= 10; dx++)       for (int dy = 0; dy <= 10; dy++)         for (int i = 0; i + (1 << dx) <= n; i++)           for (int j = 0; j + (1 << dy) <= m; j++) {             if (dx == 0 && dy == 0) {               table[0][0][i][j] = b[i][j];             } else if (dx != 0) {               table[dx][dy][i][j] =                   max(table[dx - 1][dy][i][j],                       table[dx - 1][dy][i + (1 << (dx - 1))][j]);             } else               table[dx][dy][i][j] =                   max(table[dx][dy - 1][i][j],                       table[dx][dy - 1][i][j + (1 << (dy - 1))]);           }     int t;     scanf( %d , &t);     for (int it = 0; it < t; it++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       x1--;       y1--;       int l = 0;       int r = min(x2 - x1, y2 - y1) + 1;       while (r - l > 1) {         int mid = (l + r) / 2;         if (getMax(x1, y1, x2 - mid + 1, y2 - mid + 1) >= mid)           l = mid;         else           r = mid;       }       printf( %d n , l);     }   }   void stress() {}   int main() {     if (1) {       int k = 1;       for (int tt = 0; tt < k; tt++) {         read();         solve();       }     } else {       stress();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Computational_Geometry {    public:     void init();     void solve();     Computational_Geometry() {       EPS = 1e-10;       Pi = acos(-1.0);     }       private:     struct node {       long long x, y;     } point[100010], line[100010];     struct inter {       double x, y;     } q[100010], p[100010];     int n, m;     double EPS, Pi;     friend bool operator==(const node &, const node &);     friend node operator-(const node &, const node &);     friend long long operator*(const node &, const node &);   };   bool operator==(const Computational_Geometry::node &a,                   const Computational_Geometry::node &b) {     return (a.x == b.x && a.y == b.y);   }   Computational_Geometry::node operator-(const Computational_Geometry::node &a,                                          const Computational_Geometry::node &b) {     Computational_Geometry::node d;     d.x = a.x - b.x;     d.y = a.y - b.y;     return d;   }   long long operator*(const Computational_Geometry::node &a,                       const Computational_Geometry::node &b) {     return a.x * b.y - a.y * b.x;   }   void Computational_Geometry::init() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> point[i].x >> point[i].y;     for (int i = 2; i <= n; i++) line[i] = point[i] - point[1];   }   void Computational_Geometry::solve() {     bool flag = true;     cin >> m;     for (int i = 1; i <= m; i++) {       if (!flag) continue;       node p, now;       cin >> p.x >> p.y;       now = p - point[1];       if (now * line[2] <= 0 || now * line[n] >= 0) flag = false;       int l = 2, r = n - 1;       while (l <= r) {         int mid = (l + r) / 2;         if (now * line[mid + 1] <= 0)           r = mid - 1;         else           l = mid + 1;       }       if ((p - point[l]) * (point[l + 1] - point[l]) <= 0) flag = false;     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(false);     Computational_Geometry ans;     ans.init();     ans.solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int N = 1000090, M = 1000000007;   int B[N];   void up(int i, int v) {     for (; i < N; i += (i & (-i))) B[i] += v;   }   int sm(int i) {     int s = 0;     for (; i > 0; i -= (i & (-i))) s += B[i];     return s;   }   int main() {     int q, x, n;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &x), up(x, 1);     for (int Q = 0; Q < q; ++Q) {       scanf( %d , &x);       if (x > 0)         up(x, 1), n++;       else {         int b = 0, e = N;         x = -1 * x;         while (b < e) {           int bw = (b + e) / 2;           int z = sm(bw);           if (z >= x)             e = bw;           else             b = bw + 1;         }         up(b, -1);         n--;       }     }     int ans = sm(N);     if (!ans)       printf( 0 );     else {       for (int i = 1; i < N; ++i)         if (sm(i) > 0) return cout << i, 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<vector<int>> v(200001, vector<int>(32));     for (int i = 0; i < 2e5 + 1; i++) {       for (int j = 0; j < 32; j++) {         if (i & (1 << j)) v[i][j] = 1;       }     }     for (int i = 1; i < 2e5 + 1; i++) {       for (int j = 0; j < 32; j++) {         v[i][j] += v[i - 1][j];       }     }     while (t--) {       int l, r;       cin >> l >> r;       int ans = 1e9;       for (int i = 0; i < 32; i++) {         if ((1 << i) <= r) {           ans = min(ans, r - v[r][i] - l + 1 + v[l - 1][i]);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> mm;   long long Abs(long long a) {     if (a < 0) a = -a;     return a;   }   int main() {     int q, l, m, a;     long long b;     scanf( %lld%d%d%d , &b, &q, &l, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &a);       mm[a] = 1;     }     int cur = b, cnt = 0;     if (Abs(b) > l) {       printf( 0 n );       return 0;     }     if (q == 1) {       if (mm[b] == 0)         printf( inf n );       else         printf( 0 n );       return 0;     }     if (q == -1) {       if (mm[b] && mm[-b])         printf( 0 n );       else         printf( inf n );       return 0;     }     if (q == 0 && b != 0) {       if (mm[b] && mm[0])         printf( 0 n );       else if (mm[0] == 0)         printf( inf n );       else if (mm[b] == 0)         printf( 1 n );       return 0;     }     if (b == 0) {       if (mm[0] == 1)         printf( 0 n );       else         printf( inf n );       return 0;     }     while (Abs(b) <= l) {       if (mm[b] == 0) cnt++;       b = b * q;     }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 200100;   map<int, long long> m1;   map<int, long long> m2;   int a[maxn];   int main() {     m1.clear();     m2.clear();     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long sum = 0;     for (int i = n; i >= 1; i--) {       if ((long long)a[i] * k <= 1e9 && (long long)a[i] * k >= -1e9) {         sum += m2[a[i] * k];         m2[a[i]] += m1[a[i] * k];       }       m1[a[i]]++;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (1 << 29);   const int N = 1024;   int indeg[N], outdeg[N];   int dis[N][N];   int net[N][N];   bool vis[N];   int n, m;   int tmp;   void dfs(int sta, int u) {     vis[u] = true;     for (int i = 1; i <= n; i++) {       if (!vis[i] && net[u][i]) {         tmp = min(tmp, net[u][i]);         dfs(sta, i);       }     }     dis[sta][u] = tmp;   }   int main() {     while (scanf( %d %d , &n, &m) == 2) {       if (n == 1) {         printf( 0 n );         continue;       }       memset(indeg, 0, sizeof(indeg));       memset(outdeg, 0, sizeof(outdeg));       memset(vis, false, sizeof(vis));       memset(net, 0, sizeof(net));       fill(dis[0], dis[0] + N * N, oo);       for (int i = 1; i <= m; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         net[u][v] = w;         outdeg[u]++;         indeg[v]++;       }       for (int i = 1; i <= n; i++) {         if (!vis[i] && !indeg[i]) {           tmp = oo;           dfs(i, i);         }       }       int ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (indeg[i] == 0 && outdeg[j] == 0) {             if (dis[i][j] != oo) {               ans++;             }           }         }       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (indeg[i] == 0 && outdeg[j] == 0) {             if (dis[i][j] != oo) {               printf( %d %d %d n , i, j, dis[i][j]);             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double ans = 5, a;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> a;       ans += a * 1.0 / n;     }     cout << ans;   }


#include <bits/stdc++.h>   int main() {     int t, s, q;     scanf( %d %d %d , &t, &s, &q);     int j = 0;     while (s < t) {       s *= q;       j++;     }     printf( %d n , j);     return 0;   }


#include <bits/stdc++.h>      using namespace std;   typedef long long ll;      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cin >> a[i][j];     }     vector<vector<int>> b(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cin >> b[i][j];     }     vector<vector<int>> bb;     for (int i = 0; i < n; ++i) bb.push_back(b[i]);     sort(bb.begin(), bb.end());     bb.erase(unique(bb.begin(), bb.end()), bb.end());     vector<vector<int>> who_a(bb.size());     vector<vector<int>> who_b(bb.size());     for (int i = 0; i < n; ++i) {       int ind = lower_bound(bb.begin(), bb.end(), a[i]) - bb.begin();       if (ind == (int)bb.size() || bb[ind] != a[i]) {         cout << -1 << endl;         return 0;       }       who_a[ind].push_back(i);       ind = lower_bound(bb.begin(), bb.end(), b[i]) - bb.begin();       who_b[ind].push_back(i);     }     vector<int> p(n);     for (int i = 0; i < (int)bb.size(); ++i) {       if (who_a[i].size() != who_b[i].size()) {         cout << -1 << endl;         return 0;       }       for (int j = 0; j < (int)who_a[i].size(); ++j) {         p[who_a[i][j]] = who_b[i][j];       }     }     vector<int> q(n);     for (int i = 0; i < n; ++i) q[p[i]] = i;     vector<bool> good(n, 0);     vector<int> cnt_bad(m, 0), cnt_kek(m, 0);     for (int j = 0; j < m; ++j) {       for (int i = 0; i < n - 1; ++i) {         if (a[q[i]][j] < a[q[i + 1]][j]) ++cnt_kek[j];         if (a[q[i]][j] > a[q[i + 1]][j]) ++cnt_bad[j];       }     }     vector<int> ans;     while (true) {       bool ok = true;       for (int i = 0; i < n - 1; ++i) ok &= good[i] || q[i] < q[i + 1];       if (ok) break;       int col = -1;       for (int j = 0; j < m; ++j) {         if (cnt_bad[j] == 0 && cnt_kek[j] > 0) {           col = j;           break;         }       }       if (col == -1) break;       ans.push_back(col);       for (int i = 0; i < n - 1; ++i) {         if (!good[i] && a[q[i]][col] < a[q[i + 1]][col]) {           good[i] = true;           for (int j = 0; j < m; ++j) {               if (a[q[i]][j] < a[q[i + 1]][j]) --cnt_kek[j];               if (a[q[i]][j] > a[q[i + 1]][j]) --cnt_bad[j];           }         }       }     }     bool ok = true;     for (int i = 0; i < n - 1; ++i) ok &= good[i] || q[i] < q[i + 1];     if (ok) {       cout << (int)ans.size() << endl;       reverse(ans.begin(), ans.end());       for (int i : ans) cout << i + 1 <<    ;       cout << endl;     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     int a, b = 0;     cin >> n;     cin >> s;     int ans = 2000000000;     for (int i = 0; i < n; i++) {       a = b;       cin >> b;       if (i) {         if (s[i] ==  L  && s[i - 1] ==  R ) ans = min(ans, (b - a) / 2);       }     }     if (ans == 2000000000) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int cost[2005];   bool have[2005][3];   int dp[2003][10];   int solve(int i, int vits) {     if (i >= n) {       if (vits == 7) return 0;       return 1e9;     }     int &ret = dp[i][vits];     if (ret + 1) return ret;     int sol1 = 0, sol2 = 0;     sol1 = solve(i + 1, vits);     sol2 = cost[i] + solve(i + 1, vits | (have[i][0] | (2 * have[i][1]) |                                           (4 * have[i][2])));     return ret = min(sol1, sol2);   }   int main() {     ios_base::sync_with_stdio(false);     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 0; i < n; i++) {       cin >> cost[i];       string s;       cin >> s;       for (auto x : s) {         if (x ==  A ) have[i][0] = true;         if (x ==  B ) have[i][1] = true;         if (x ==  C ) have[i][2] = true;       }     }     int res = solve(0, 0);     if (res > 7e8) res = -1;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using namespace std;   int n;   void solve() {     cin >> n;     if (n % 2 == 0) {       cout <<  NO ;       return;     }     cout <<  YES n ;     vector<int> v(2 * n + 1);     for (int i = 1; i <= n; i++) {       if (i % 2) {         v[i] = 2 * i - 1;         v[i + n] = 2 * i;       } else {         v[i] = 2 * i;         v[i + n] = 2 * i - 1;       }     }     for (int i = 1; i <= 2 * n; i++) cout << v[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int b, h, a;     long long int count = 0;     cin >> b >> h;     for (int i = h - 1; i >= 0; i = i - 2) {       for (int j = b - 1; j >= 0; j = j - 2) {         a = j * i;         count += a;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     long long n, p, d, w;     cin >> n >> p >> w >> d;     for (register int y = (0); y <= (w); ++y) {       long long x = (p - y * d) / w;       if (x < 0) continue;       if (x * w + y * d != p) continue;       if (x + y <= n) {         cout << x <<     << y <<     << n - x - y <<   n ;         return 0;       }     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[2005];   int sum[2005];   bool cmp(int a, int b) { return a > b; }   int main() {     int n, i, j, t;     int temp;     while (cin >> n) {       memset(num, 0, sizeof(num));       for (i = 0; i < n; i++) {         cin >> temp;         num[temp]++;       }       cin >> t;       memset(sum, 0, sizeof(sum));       for (i = 0; i <= t; i++) {         sum[0] += num[i];       }       for (i = 1; i < 1001; i++) {         sum[i] = sum[i - 1] - num[i - 1] + num[i + t];       }       sort(sum, sum + 1001, cmp);       cout << sum[0] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     int val = n - a;     if (val > (b + 1)) {       cout << b + 1 << endl;     } else {       cout << val << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int ABS(long long int a) {     if (a < 0) return (-a);     return a;   }   void input() {}   int main() {     long long int n, t;     int f = 0;     scanf( %llu , &n);     scanf( %llu , &t);     long long int x[n];     for (int i = (1); i < (n); ++i) {       scanf( %llu , &x[i]);     }     long long int i = 1;     while (i <= t) {       if (i == t) f = 1;       i += x[i];       if (i == t) f = 1;       if (f) break;     }     if (f)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   vector<T> &operator+=(vector<T> &v, T x) {     v.push_back(x);     return v;   }   void solve() {     int n;     cin >> n;     int a[n], b[n];     int cash = 1, t = 0;     for (int i = (0), _b_ = (n); i < _b_; i++) {       cin >> a[i] >> b[i];       if (i > 0) {         if (a[i] == a[i - 1] && b[i] == b[i - 1]) {           t++;         } else {           cash = max(cash, t + 1);           t = 0;         }       }     }     cout << max(cash, t + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500005;   int tot, head[maxn << 1], n, m, a[maxn << 1], b, maxdep, xzynb, son[maxn << 1],       size, ans[maxn << 1];   template <typename Tp>   inline void read(Tp& o) {     o = 0;     register int f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       o = (o << 1) + (o << 3) + (c ^ 48);       c = getchar();     }     o *= f;   }   inline void print(int x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) {       print(x / 10);     }     putchar(x % 10 + 48);   }   struct qwq {     int to;     int next;   } s[maxn << 1];   inline void add(int x, int y) {     tot++;     s[tot].to = y;     s[tot].next = head[x];     head[x] = tot;   }   inline void dfs(int x, int fa) {     son[x] = 1;     ans[x] = x;     int res = 0;     for (register int i = head[x]; i; i = s[i].next) {       if (s[i].to != fa) {         dfs(s[i].to, x);         son[x] += son[s[i].to];         if (son[s[i].to] > son[res]) res = s[i].to;       }     }     if ((son[res] << 1) > son[x]) {       int temp = ans[res];       while (((son[x] - son[temp]) << 1) > son[x]) {         temp = a[temp];       }       ans[x] = temp;     }   }   int main() {     read(n), read(m);     for (register int i = 2; i <= n; ++i) {       read(a[i]);       add(i, a[i]), add(a[i], i);     }     dfs(1, 0);     for (register int i = 1; i <= m; ++i) {       read(b);       print(ans[b]), puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct atom {     int x, y;   } x[110000];   int A[800], f[2][800], n, m;   int compare(atom k1, atom k2) { return k1.y < k2.y; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &x[i].x, &x[i].y);     sort(x + 1, x + m + 1, compare);     memset(f, 0x00, sizeof f);     int now = 0, lim = 780;     for (int i = 1; i <= n; i++) {       memset(A, 0x00, sizeof A);       memset(f[now ^ 1], 0x3f, sizeof f[now ^ 1]);       while (m && x[m].y == n - i + 1) {         A[min(n - x[m].x + 1, lim + 1)]++;         m--;       }       for (int j = lim; j; j--) A[j] += A[j + 1];       for (int j = min(lim, i); j >= 0; j--)         f[now ^ 1][j] = f[now][max(j - 1, 0)] + A[j + 1] * 3;       for (int j = 0; j <= min(i, lim); j++)         f[now ^ 1][0] =             min(f[now ^ 1][0],                 f[now][max(j - 1, 0)] + j * (j + 1) / 2 + 2 + A[j + 1] * 3);       for (int j = 1; j <= min(i, lim); j++)         f[now ^ 1][j] = min(f[now ^ 1][j], f[now ^ 1][j - 1]);       now ^= 1;     }     cout << f[now][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MX = 1e6 + 5;   long long MD = 1e9 + 7;   const int MDL = 99824453;   auto time0 = chrono::high_resolution_clock::now();   long long a[MX], LPF[MX];   long long bin_power(long long a, long long b, long long md) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % md;       a = (a * a) % md;       b >>= 1;     }     return res;   }   long long lcm(long long n) {     map<long long, long long> mp;     for (long long i = 1; i <= n; i++) {       long long cur = a[i], curf = LPF[cur], cnt = 0;       while (cur > 1) {         cur /= LPF[cur];         cnt++;         if (LPF[cur] != curf) {           mp[curf] = max(mp[curf], cnt);           curf = LPF[cur];           cnt = 0;         }       }     }     long long ans = 1;     for (auto x : mp) ans = (ans * bin_power(x.first, x.second, MD)) % MD;     return ans;   }   void solve() {     long long n, k;     cin >> n >> k;     if (k == 1) {       cout <<  Yes ;       return;     }     bool flag = false;     for (long long i = 1; i <= n; i++) cin >> a[i];     MD = k;     long long L = lcm(n);     if (L != 0)       cout <<  No ;     else       cout <<  Yes ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     srand(time(0));     time0 = chrono::high_resolution_clock::now();     for (long long i = 1; i <= MX - 1; i++) LPF[i] = i;     for (long long i = 2; i <= MX - 1; i++) {       if (LPF[i] == i) {         for (int j = 2 * i; j < MX; j += i)           if (LPF[j] == j) LPF[j] = i;       }     }     solve();     cerr <<  Execution Time:            << chrono::duration_cast<chrono::nanoseconds>(                 chrono::high_resolution_clock::now() - time0)                     .count() *                 1e-9          <<   sec n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char no[20];     cin >> no;     int len = strlen(no);     int ans = (1 << len) - 2;     for (int i = (len - 1), pos = 0; i >= 0; i--, pos++) {       if (no[i] ==  7 ) ans += (1 << pos);     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void Read(int &x) {     int f = 1;     char c = getchar();     x = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x *= f;   }   const int p = 1000000007;   int n, m;   inline int Pow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1ll * a * res % p;       a = 1ll * a * a % p, b >>= 1;     }     return res;   }   int main() {     Read(n), Read(m);     cout << 1ll * Pow(2, m) * Pow(n + 1, m - 1) % p * (n - m + 1) % p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int minu = 1, temp = 0, n, ans = 0;       cin >> n;       ans = ((n) * (n + 1)) / 2;       while (minu <= n) {         temp += minu;         minu *= 2;       }       ans -= (2 * temp);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void dbg(T t) {     cerr << t << endl;   }   template <typename T, typename... Args>   void dbg(T t, Args... args) {     cerr << t <<    ;     dbg(args...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, a, spec = 3;     int t[2] = {1, 2};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       if (spec == a) {         cout <<  NO  << endl;         return 0;       }       for (int j = 0; j < 2; j++)         if (t[j] != a) swap(t[j], spec);     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     string str;     cin >> str;     int n = str.size();     vector<int> arr(26, 1e8);     for (int i = 0; i < n; i++) {       arr[str[i] -  0  - 49] = min(arr[str[i] -  0  - 49], i);     }     cout <<  Mike n ;     bool ch = true;     for (int i = 1; i < n; i++) {       for (int j = 0; j < str[i] -  0  - 49; j++) {         ch = false;         if (arr[j] < i) {           cout <<  Ann n ;           break;         }         if (j == str[i] -  0  - 50) {           cout <<  Mike n ;         }       }       if (ch) {         cout <<  Mike n ;       }       ch = true;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long b, long long e) {     long long p = 1;     while (e > 0) {       if (e & 1) {         p = (p * b) % 1000000007;       }       e = e >> 1;       b = (b * b) % 1000000007;     }     return p;   }   vector<string> num;   string s, s1;   int main() {     long long n, i, t, x = 0, j, m, c, q, ans = 0, l;     scanf( %lld , &n);     cin >> s;     for (i = 0; i < 10; i++) {       for (j = 0; j < n; j++) {         s1 = s;         for (l = 0; l < n; l++) {           s1[l] = (char)((s[(l + j) % n] - 48 + i) % 10 + 48);         }         num.push_back(s1);       }     }     sort((num).begin(), (num).end());     cout << num[0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ydidicreate;   int dontknowy[100000];   int main() {     int tt;     cin >> tt;     while (tt--) {       int n, k;       cin >> n >> k;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       ;       sort(a, a + n);       int f[k];       for (int i = 0; i < k; i++) cin >> f[i];       ;       sort(f, f + k);       long long ans = 0;       int l = n - 1, m = 0;       int pos;       for (int i = 0; i < k; i++) {         if (f[i] == 1) {           ans += (2 * a[l]);           l--;         } else {           pos = i;           break;         }       }       for (int i = k - 1; i >= 0; i--) {         if (f[i] == 1) break;         ans += a[l];         l--;         ans += a[m];         m++;         f[i] -= 2;         while (f[i]--) {           m++;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const long long mm = 1e9 + 7;   int ch[maxn][27], fail[maxn];   long long cnt[maxn];   long long s[maxn], len[maxn];   int slink[maxn];   int dif[maxn];   char sp[maxn];   long long g[maxn];   int last, sz, n;   int newnode(int x) {     for (int i = 0; i < 26; ++i) {       ch[sz][i] = 0;     }     cnt[sz] = 0;     len[sz] = x;     return sz++;   }   void init() {     sz = 0;     newnode(0);     newnode(-1);     last = 0, n = 0;     fail[0] = 1;     fail[1] = 0;     s[0] = -1;   }   int getfail(int u) {     while (s[n - len[u] - 1] != s[n]) u = fail[u];     return u;   }   int pos[maxn];   void add(int c) {     s[++n] = c;     int u = getfail(last);     if (!ch[u][c]) {       int np = newnode(len[u] + 2);       fail[np] = ch[getfail(fail[u])][c];       ch[u][c] = np;       dif[np] = len[np] - len[fail[np]];       if (dif[np] == dif[fail[np]]) {         slink[np] = slink[fail[np]];       } else         slink[np] = fail[np];     }     last = ch[u][c];     pos[last] = n;     cnt[last]++;   }   void count() {     for (int i = sz - 1; i >= 0; --i) {       cnt[fail[i]] += cnt[i];     }   }   long long dp[maxn];   char dsp[maxn];   int main() {     init();     dsp[0] =  a ;     scanf( %s , dsp + 1);     int le = strlen(dsp + 1);     int j = 0;     for (int i = 1; i <= le; ++i) {       sp[++j] = dsp[i];       sp[++j] = dsp[le - i + 1];     }     dp[0] = 1;     for (int i = 1; i <= le; ++i) {       add(sp[i] -  a );       for (int j = last; j >= 2; j = slink[j]) {         g[j] = dp[i - len[slink[j]] - dif[j]];         if (dif[j] == dif[fail[j]]) g[j] = (g[j] % mm + g[fail[j]] % mm) % mm;         if (i % 2 == 0) dp[i] = (dp[i] % mm + g[j] % mm) % mm;       }     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<long long>> a;     bool tr = true;     for (long long l, r, i = 0; i < n; i++) {       cin >> l >> r;       a.push_back({l, r});     }     sort(a.begin(), a.end(),          [](const vector<long long>& a, const vector<long long>& b) -> bool {            if (a[0] == b[0]) {              return a[1] < b[1];            } else {              return a[0] < b[0];            }          });     long long f = -1, s = -1;     for (long long i = 0; i < n; i++) {       if (tr && a[i][0] > f) {         f = a[i][1];       } else if (tr && a[i][0] > s) {         s = a[i][1];       } else {         tr = false;       }     }     if (tr) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cdiv(long long a, long long b) {     return a / b + ((a ^ b) > 0 && a % b);   }   long long fdiv(long long a, long long b) {     return a / b - ((a ^ b) < 0 && a % b);   }   void solve() {     long long int n;     cin >> n;     vector<long long int> v(n);     map<long long int, long long int> mp;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       v[i] = x % 3;       mp[v[i]]++;     }     long long int ans = mp[0];     long long int c = min(mp[1], mp[2]);     ans = ans + c;     mp[1] = mp[1] - c;     mp[2] = mp[2] - c;     ans = ans + mp[1] / 3 + mp[2] / 3;     cout << ans;     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N];   int main() {     int n;     long long sum = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i] - 1;       if (sum % 2 == 1)         printf( 1 n );       else         printf( 2 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e8 + 10;   const int MOD = 1e9 + 7;   const int MAX = 2e5 + 1;   const double EPS = (1e-9);   map<int, bool> mp;   int main() {     int n, x, y, l, last, ans;     bool f1 = 0, f2 = 0, f3 = 0;     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       mp[a] = 1;     }     for (auto it = mp.begin(); it != mp.end(); it++) {       if (mp.count(it->first + (x - y)) && it->first + x <= l)         f3 = 1, ans = it->first + x;       if (mp.count(it->first - (x - y)) && it->first - x >= 0)         f3 = 1, ans = it->first - x;       if (mp.count(it->first + x + y)) f3 = 1, ans = it->first + x;       if (mp.count(it->first + x)) f1 = 1;       if (mp.count(it->first + y)) f2 = 1;     }     if (f1 && f2) return cout <<  0 n , 0;     if (f3) return cout <<  1 n  << ans <<   n , 0;     if (f1) return cout <<  1 n  << y <<   n , 0;     if (f2) return cout <<  1 n  << x <<   n , 0;     return cout <<  2 n  << x <<     << y <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   int vis[N];   int p[N];   int sum[N];   int main() {     int t = 0;     for (int i = 2; i <= 1000010; i++) {       if (vis[i] == 0) p[++t] = i;       for (int j = 1; j <= t && (i * p[j] <= 1000010); j++) {         vis[i * p[j]] = 1;         if (i % p[j] == 0) {           break;         }       }     }     for (int i = 1; i <= 1000010; i++) {       if (vis[i] == 0) {         sum[i] = 1 + sum[i - 1];       } else {         sum[i] = sum[i - 1];       }     }     int k;     scanf( %d , &k);     while (k--) {       double n;       scanf( %lf , &n);       int q = (int)n;       int w = (int)sqrt(n);       printf( %d n , sum[q] - sum[w] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110000], b[110000];   struct Node {     int a, b;   } node[110000];   int main() {     int i, j, h;     int n, m, T;     int cas = 1;     int x, y;     while (scanf( %d%d%d%d , &n, &m, &x, &y) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       for (j = 1; j <= m; j++) {         scanf( %d , &b[j]);       }       int k = 0;       for (i = 1, j = 1; i <= n && j <= m; i++) {         if (b[j] - y > a[i]) continue;         while (b[j] + x < a[i] && j <= m) {           j++;         }         if (j > m) break;         if (b[j] - y <= a[i]) {           k++;           node[k].a = i;           node[k].b = j;           j++;         }       }       printf( %d n , k);       for (i = 1; i <= k; i++) {         printf( %d %d n , node[i].a, node[i].b);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 5;   const long long INF = (1LL << 62);   const long double pi = 3.14159265359;   void SRAND() {     auto duration = std::chrono::system_clock::now().time_since_epoch();     auto millis =         std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();     srand(millis);   }   long long n, k, u[N], p[N], ans, x, y;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 1; i <= n; i++) cin >> u[i];     for (long long i = n; i >= 1; i--) {       p[i] = (u[i] == 1 ? p[i + 1] + 1 : 0);     }     for (long long i = 1; i <= n; i++) {       x = u[i];       y = u[i];       if (x == y * k) ans++;       for (long long j = i + 1; j <= n; j++) {         if (u[j] == 1) {           if (x % k == 0 && (x - k * y) / k >= 1 && (x - k * y) / k <= p[j])             ans++;           y += p[j];           j += p[j] - 1;           continue;         }         if (x >= INF / u[j]) break;         x *= u[j];         y += u[j];         if (x == y * k) ans++;       }     }     cout << ans <<   n ;     return 0;   }