#include <bits/stdc++.h>   using namespace std;   int main() {     ifstream in( input.txt );     string s;     bool e = false;     int i, c = 0;     getline(cin, s);     for (i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) e = true;       if (e == true)         if (s[i] ==  0 ) c++;     }     if ((c >= 6) && (e == true))       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int a[122], b[122];   int main() {     int n, k, t, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> k >> t;       a[k]++;       b[t]++;     }     for (int i = 1; i <= 100; i++)       if (a[i] > 0) ans += a[i] * b[i];     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   using LL = long long;   using PII = pair<int, int>;   using PLL = pair<LL, LL>;   using VI = vector<int>;   using VVI = vector<VI>;   const int INF = 1e9;   const int MXN = 55;   const int MXM = 2e4 + 5;   int n, m, k;   VVI init(MXN, VI(MXM, 0));   VVI a, rev_a, sum, rev_sum, Lmax, Rmax, dp, dpL, dpR;   int getSum(VVI &sum, int x, int L, int R) {     if (L < 1) {       return sum[x][R];     }     return sum[x][R] - sum[x][L - 1];   }   void calc_overlapped(VVI &sum, VVI &dp, int i) {     deque<PII> dq;     for (int j = 1; j < (int)m - k + 2; ++j) {       int num = dp[i - 1][j] - getSum(sum, i, j, j + k - 1);       while (!dq.empty() && dq.front().second <= j - k) {         dq.pop_front();       }       while (!dq.empty() &&              dq.back().first + getSum(sum, i, dq.back().second, j - 1) <= num) {         dq.pop_back();       }       dq.push_back({num, j});       dp[i][j] = dq.front().first + getSum(sum, i, dq.front().second, j - 1) +                  getSum(sum, i, j, j + k - 1) + getSum(sum, i + 1, j, j + k - 1);     }   }   int main() {     cin.tie(nullptr);     cout.tie(nullptr);     ios_base::sync_with_stdio(false);     ;     cin >> n >> m >> k;     a = rev_a = sum = rev_sum = Lmax = Rmax = dp = dpL = dpR = init;     for (int i = 1; i < (int)n + 1; ++i) {       for (int j = 1; j < (int)m + 1; ++j) {         cin >> a[i][j];         sum[i][j] = sum[i][j - 1] + a[i][j];       }       for (int j = 1; j < (int)m + 1; ++j) {         rev_a[i][j] = a[i][m - j + 1];         rev_sum[i][j] = rev_sum[i][j - 1] + rev_a[i][j];       }     }     for (int i = 1; i < (int)n + 1; ++i) {       for (int j = 1; j < (int)m - k + 2; ++j) {         int ksum =             getSum(sum, i, j, j + k - 1) + getSum(sum, i + 1, j, j + k - 1);         dp[i][j] = ksum;         if (j - k > 0) {           dp[i][j] = max(dp[i][j], ksum + Lmax[i - 1][j - k]);         }         if (j + k <= m - k + 1) {           dp[i][j] = max(dp[i][j], ksum + Rmax[i - 1][j + k]);         }       }       calc_overlapped(sum, dpL, i);       calc_overlapped(rev_sum, dpR, i);       for (int j = 1; j < (int)m - k + 2; ++j) {         dp[i][j] = max({dp[i][j], dpL[i][j], dpR[i][m - k - j + 2]});         dpL[i][j] = dpR[i][m - k - j + 2] = dp[i][j];       }       for (int j = 1; j < (int)m - k + 2; ++j) {         Lmax[i][j] = max(Lmax[i][j - 1], dp[i][j]);       }       for (int j = m - k + 1; j > (int)0; --j) {         Rmax[i][j] = max(Rmax[i][j + 1], dp[i][j]);       }     }     int ans = 0;     for (int i = 1; i < (int)m - k + 2; ++i) {       ans = max(ans, dp[n][i]);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   bool inside(T a, T b, T c) {     return (b >= a && b <= c);   }   const long long INF64 = (long long)1E16;   int distsq2d(int x1, int y1, int x2, int y2) {     return sqr(x1 - x2) + sqr(y1 - y2);   }   double dist2d(double x1, double y1, double x2, double y2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2));   }   double dist3d(double x1, double y1, double z1, double x2, double y2,                 double z2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2) + sqr(z1 - z2));   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   int fx[] = {0, 0, 1, -1};   int fy[] = {1, -1, 0, 0};   bool status[30000002];   vector<int> v;   void siv() {     int N = 20000002;     int sq = sqrt(N);     for (int i = 3; i <= sq; i += 2) {       if (status[i] == 0) {         for (int j = i * i; j <= N; j += i) status[j] = 1;       }     }     int c = 1;     for (int i = 3; i <= 1100000; i += 2) {       if (status[i] == 0) {         char s[20];         sprintf(s,  %d , i);         reverse(s, s + strlen(s));         int r = atoi(s);         if (i != r) {           if (r == 2 or (r % 2 == 1 and status[r] == 0)) {             ++c;             v.push_back(i);           }         }       }     }   }   int main() {     siv();     int n;     cin >> n;     cout << v[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T second(T a) {     return a * a;   }   template <class T>   inline string tostring(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long tolong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T gcd(T a, T b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   template <typename T>   inline T bigmod(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return second(bigmod(a, b / 2, m)) % m;     else       return (a % m * bigmod(a, b - 1, m)) % m;   }   const int inf = (int)1e9 + 5;   const long long linf = (long long)1e16 + 5;   const long long modd = (long long)1e9 + 7;   const int mod = 10000007;   void pr(int f) {     if (f == 1)       cout <<  YES n ;     else       cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     char ch;     int js = 0;     int ans = 0;     int flag = 0;     for (int i = 1; i <= n; i++) {       cin >> ch;       if (ch ==  R ) {         ans += js;         flag = 1;         js = 0;         continue;       }       if (ch ==  L ) {         if ((flag == 1) && ((js % 2) == 1)) ans++;         flag = 0;         js = 0;         continue;       }       js++;     }     if (flag == 0) ans += js;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     do {       ios::sync_with_stdio(false);       cin.tie(nullptr);       cout.tie(nullptr);     } while (false);     string L, R;     cin >> L >> R;     reverse(L.begin(), L.end());     L.resize(R.size(),  0 );     reverse(L.begin(), L.end());     int n, m = 0;     cin >> n;     const int sigma = 10, M = 3 * R.size() * sigma + 100;     vector<vector<int> > son(M, vector<int>(sigma)),         sum(M, vector<int>(R.size()));     function<void(int, int, bool, bool, bool)> gen = [&](int idx, int u, bool big,                                                          bool small, bool start) {       if (idx >= R.size() || (big && small)) {         sum[u][R.size() - idx]++;       } else {         for (int i = (big ? 0 : L[idx] -  0 ); i <= (small ? 9 : R[idx] -  0 );              i++) {           int v = u;           if (start || i) {             if (!son[u][i]) {               son[u][i] = m++;             }             v = son[u][i];           }           gen(idx + 1, v, big || L[idx] -  0  < i, small || R[idx] -  0  > i,               start || i);         }       }     };     gen(0, m++, false, false, false);     vector<int> fail(m);     auto build = [&]() {       queue<int> que;       que.push(0);       while (!que.empty()) {         int u = que.front();         que.pop();         for (int i = 0; i < sigma; i++) {           if (!son[u][i]) {             son[u][i] = son[fail[u]][i];           } else {             int v = fail[u];             while (v && !son[v][i]) {               v = fail[v];             }             if (son[v][i] && son[v][i] != son[u][i]) {               fail[son[u][i]] = son[v][i];               for (int j = 0; j < R.size(); j++) {                 sum[son[u][i]][j] += sum[son[v][i]][j];               }             }             que.push(son[u][i]);           }         }       }     };     build();     vector<vector<int> > trans(m, vector<int>(sigma));     for (int u = 0; u < m; u++) {       for (int i = 1; i < R.size(); i++) {         sum[u][i] += sum[u][i - 1];       }       for (int i = 0; i < sigma; i++) {         int v = u;         while (v && !son[v][i]) {           v = fail[v];         }         trans[u][i] = son[v][i];       }     }     vector<vector<int> > dp(n + 1, vector<int>(m, -1e9));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int u = 0; u < m; u++) {         if (dp[i][u] >= 0) {           for (int j = 0; j < sigma; j++) {             int v = trans[u][j];             dp[i + 1][v] = max(dp[i + 1][v],                                dp[i][u] + sum[v][min((int)R.size(), n - i) - 1]);           }         }       }     }     int goal = *max_element(dp[n].begin(), dp[n].end());     cout << goal << endl;     vector<vector<bool> > on(n + 1, vector<bool>(m));     for (int i = 0; i < m; i++) {       on[n][i] = dp[n][i] == goal;     }     for (int i = n - 1; i >= 0; i--) {       for (int u = 0; u < m; u++) {         if (dp[i][u] >= 0) {           bool ok = false;           for (int j = 0; j < sigma; j++) {             int v = trans[u][j];             ok |=                 on[i + 1][v] &&                 dp[i][u] + sum[v][min((int)R.size(), n - i) - 1] == dp[i + 1][v];           }           on[i][u] = ok;         }       }     }     int u = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < sigma; j++) {         int v = trans[u][j];         if (on[i + 1][v] &&             dp[i][u] + sum[v][min((int)R.size(), n - i) - 1] == dp[i + 1][v]) {           cout << j;           u = v;           break;         }       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   struct edge {     int to, next, w;   } e[200010];   int head[N], ecnt, n, vis[N], val[N], mark[N][N];   long long dp[2][N][N], cover[N][N], sum;   inline void adde(int from, int to, int w) {     e[++ecnt] = (edge){to, head[from], w}, head[from] = ecnt;     e[++ecnt] = (edge){from, head[to], w}, head[to] = ecnt;   }   inline void Dijkstra(long long d[], int s) {     for (int i = 1; i <= n; i++) d[i] = 1e18;     memset(vis, 0, sizeof(vis));     priority_queue<pair<long long, int> > q;     q.push(pair<long long, int>(0, s)), d[s] = 0;     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (int i = head[u]; i; i = e[i].next)         if (!vis[e[i].to] && d[u] + e[i].w < d[e[i].to])           d[e[i].to] = d[u] + e[i].w,           q.push(pair<long long, int>(-d[e[i].to], e[i].to));     }   }   inline void work(int s, int t) {     static long long S[N], T[N], tmp[N];     Dijkstra(S, s), Dijkstra(T, t);     int top = 0;     for (int i = 1; i <= n; i++) tmp[++top] = S[i];     sort(tmp + 1, tmp + top + 1), top = unique(tmp + 1, tmp + top + 1) - tmp - 1;     for (int i = 1; i <= n; i++)       S[i] = lower_bound(tmp + 1, tmp + top + 1, S[i]) - tmp;     top = sum = 0;     for (int i = 1; i <= n; i++) tmp[++top] = T[i];     sort(tmp + 1, tmp + top + 1), top = unique(tmp + 1, tmp + top + 1) - tmp - 1;     for (int i = 1; i <= n; i++) sum += val[i];     for (int i = 1; i <= n; i++)       T[i] = lower_bound(tmp + 1, tmp + top + 1, T[i]) - tmp;     for (int i = 1; i <= n; i++)       cover[S[i] - 1][T[i] - 1] -= val[i], mark[S[i] - 1][T[i] - 1] = -1;     for (int i = n; i >= 0; i--)       for (int j = n; j >= 0; j--) {         cover[i][j] += cover[i + 1][j] + cover[i][j + 1] - cover[i + 1][j + 1];         mark[i][j] += mark[i + 1][j] + mark[i][j + 1] - mark[i + 1][j + 1];       }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) cover[i][j] += sum, mark[i][j] += n;   }   int nxt[2][N][N];   long long f[N][N], g[N][N];   int main() {     int m, s, t;     scanf( %d%d%d%d , &n, &m, &s, &t);     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     for (int i = 1, a, b, c; i <= m; i++)       scanf( %d%d%d , &a, &b, &c), adde(a, b, c);     work(s, t);     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= n + 1; j++) f[i][j] = g[i][j] = -1e18;     for (int i = n; i >= 0; i--)       for (int j = n; j >= 0; j--) {         if (mark[i][j] != mark[i + 1][j])           nxt[1][i][j] = i + 1;         else           nxt[1][i][j] = nxt[1][i + 1][j];         if (mark[i][j] != mark[i][j + 1])           nxt[0][i][j] = j + 1;         else           nxt[0][i][j] = nxt[0][i][j + 1];       }     for (int i = n; i >= 0; i--)       for (int j = n; j >= 0; j--) {         f[i][j] = f[i + 1][j], g[i][j] = g[i][j + 1];         if (cover[i][j] == sum)           dp[0][i][j] = dp[1][i][j] = 0;         else           dp[1][i][j] = f[nxt[1][i][j]][j] - cover[i][j],           dp[0][i][j] = g[i][nxt[0][i][j]] - cover[i][j];         f[i][j] = max(f[i][j], cover[i][j] - dp[0][i][j]),         g[i][j] = max(g[i][j], cover[i][j] - dp[1][i][j]);       }     long long w = dp[1][0][0];     if (w == 0)       puts( Flowers );     else       puts(w > 0 ?  Break a heart  :  Cry );     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-9;   double a, b, c, nx, mx, ny, my, ans;   long long ax, ay, bx, by;   int main() {     std::cin >> a >> b >> c >> ax >> ay >> bx >> by;     ans = std::abs(ax - bx) + std::abs(ay - by);     if ((a < eps && a > -eps) || (b < eps && b > -eps)) {       printf( %.7lf n , ans);       return 0;     }     nx = -b / a, mx = -c / a, ny = -a / b, my = -c / b;     ans = std::min(         ans,         std::abs(ay - (ny * ax + my)) + std::abs(by - (ny * bx + my)) +             sqrt((ax - bx) * (ax - bx) + ((ny * ax + my) - (ny * bx + my)) *                                              ((ny * ax + my) - (ny * bx + my))));     ans = std::min(         ans,         std::abs(ax - (nx * ay + mx)) + std::abs(bx - (nx * by + mx)) +             sqrt((ay - by) * (ay - by) + ((nx * ay + mx) - (nx * by + mx)) *                                              ((nx * ay + mx) - (nx * by + mx))));     ans = std::min(ans, std::abs(ay - (ny * ax + my)) +                             std::abs(bx - (nx * by + mx)) +                             sqrt((ax - (nx * by + mx)) * (ax - (nx * by + mx)) +                                  ((ny * ax + my) - by) * ((ny * ax + my) - by)));     ans = std::min(ans, std::abs(ax - (nx * ay + mx)) +                             std::abs(by - (ny * bx + my)) +                             sqrt((ay - (ny * bx + my)) * (ay - (ny * bx + my)) +                                  ((nx * ay + mx) - bx) * ((nx * ay + mx) - bx)));     printf( %.7lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const char opname[4][5] = { and ,  nand ,  or ,  nor };   const int inputmapping[3][4] = {{0, 1, 0, 1}, {0, 1, 0, 2}, {0, 1, 2, 3}};   int parseop(char *s) {     for (int i = (0); i < (4); ++i)       if (strcmp(opname[i], s) == 0) return i;     assert(false);     return -1;   }   int op(int id, int x, int y) {     if (id == 0) return x == 1 && y == 1 ? 1 : 0;     if (id == 1) return x == 1 && y == 1 ? 0 : 1;     if (id == 2) return x == 1 || y == 1 ? 1 : 0;     if (id == 3) return x == 1 || y == 1 ? 0 : 1;     assert(false);     return -1;   }   void gen() {     for (int x = (0); x < (4); ++x)       for (int y = (0); y < (4); ++y)         for (int z = (y); z < (4); ++z) {           for (int i = (0); i < (3); ++i) {             int masklen = i + 2;             vector<int> res(1 << masklen, 0);             for (int mask = (0); mask < (1 << masklen); ++mask) {               for (int love = (0); love < (2); ++love) {                 int w1 = (mask >> inputmapping[i][0]) & 1,                     w2 = (mask >> inputmapping[i][1]) & 1,                     w3 = (mask >> inputmapping[i][2]) & 1,                     w4 = (mask >> inputmapping[i][3]) & 1;                 int resy = op(y ^ love, w1, w2), resz = op(z ^ love, w3, w4),                     resx = op(x ^ love, resy, resz);                 res[mask] |= resx << love;               }             }             bool ok = true;             for (int j = (0); j < (((int)(res).size())); ++j)               if (res[j] == 3) ok = false;             if (!ok) continue;             printf( %s(%s(%c,%c),%s(%c,%c)):  , opname[x], opname[y],                     a  + inputmapping[i][0],  a  + inputmapping[i][1], opname[z],                     a  + inputmapping[i][2],  a  + inputmapping[i][3]);             for (int j = (0); j < (((int)(res).size())); ++j)               printf( %d , res[j]);             puts(  );           }         }   }   const int MAXA = 50;   const int MAXB = 50;   const int MAXC = 50;   struct Z {     int kind;     vector<pair<int, int> > condzero;   };   int na, nb, nc;   int bkind[MAXB], b[MAXB][2];   int ckind[MAXC], c[MAXC][2];   char opbuff[5], inbuff[(MAXB >= MAXC ? MAXB : MAXC) + 1];   Z classify(int id) {     int x = ckind[id], y = bkind[c[id][0]], z = bkind[c[id][1]],         w1 = b[c[id][0]][0], w2 = b[c[id][0]][1], w3 = b[c[id][1]][0],         w4 = b[c[id][1]][1];     map<int, int> mp;     vector<int> in(4);     vector<int> a;     int nin = 0;     if (mp.count(w1))       in[0] = mp[w1];     else       mp[w1] = in[0] = nin++, a.push_back(w1);     if (mp.count(w2))       in[1] = mp[w2];     else       mp[w2] = in[1] = nin++, a.push_back(w2);     if (mp.count(w3))       in[2] = mp[w3];     else       mp[w3] = in[2] = nin++, a.push_back(w3);     if (mp.count(w4))       in[3] = mp[w4];     else       mp[w4] = in[3] = nin++, a.push_back(w4);     int orgmask = 0, lovemask = 0, allmask = 0;     for (int mask = (0); mask < (1 << nin); ++mask) {       for (int love = (0); love < (2); ++love) {         int v1 = (mask >> in[0]) & 1, v2 = (mask >> in[1]) & 1,             v3 = (mask >> in[2]) & 1, v4 = (mask >> in[3]) & 1;         int vy = op(y ^ love, v1, v2), vz = op(z ^ love, v3, v4),             vx = op(x ^ love, vy, vz);         allmask |= vx << mask;         if (love == 0)           orgmask |= vx << mask;         else           lovemask |= vx << mask;       }     }     Z ret;     if ((orgmask & lovemask) != 0) {       ret.kind = -1;       return ret;     }     assert(orgmask == 0 || lovemask == 0 && allmask != 0);     ret.kind = orgmask == 0 ? 0 : 1;     int donemask = 0;     for (int i = (0); i < (nin); ++i)       for (int ii = (0); ii < (2); ++ii)         for (int j = (i + 1); j < (nin); ++j)           for (int jj = (0); jj < (2); ++jj) {             bool ok = true;             for (int k = (0); k < (1 << nin); ++k)               if (!(((k >> i) & 1) == ii || ((k >> j) & 1) == jj) &&                   ((allmask >> k) & 1) == 0)                 ok = false;             if (!ok) continue;             ret.condzero.push_back(make_pair((ii == 0 ? -1 : +1) * (a[i] + 1),                                              (jj == 0 ? -1 : +1) * (a[j] + 1)));             for (int k = (0); k < (1 << nin); ++k)               if (!(((k >> i) & 1) == ii || ((k >> j) & 1) == jj) &&                   ((allmask >> k) & 1) == 1)                 donemask |= 1 << k;           }     assert(donemask == allmask);     return ret;   }   struct G {     int n;     vector<int> adj[2 * MAXA];     int comp[2 * MAXA], ncomp;     int stck[2 * MAXA], nstck;     int id[2 * MAXA], lid[2 * MAXA], nid;     void init(int _n) {       n = _n;       for (int i = (0); i < (n); ++i) adj[i].clear();     }     void tarjan(int at) {       id[at] = lid[at] = nid++;       stck[nstck++] = at;       for (int i = (0); i < (((int)(adj[at]).size())); ++i) {         int to = adj[at][i];         if (id[to] == -1) {           tarjan(to);           lid[at] = min(lid[at], lid[to]);         } else if (comp[to] == -1) {           lid[at] = min(lid[at], id[to]);         }       }       if (lid[at] >= id[at]) {         while (comp[at] == -1) comp[stck[--nstck]] = ncomp;         ++ncomp;       }     }     void calccomp() {       nid = ncomp = nstck = 0;       for (int i = (0); i < (n); ++i) comp[i] = id[i] = -1;       for (int i = (0); i < (n); ++i)         if (id[i] == -1) tarjan(i);     }   };   G g;   bool satisfiable(vector<pair<int, int> > cond) {     g.init(2 * na);     for (int i = (0); i < (((int)(cond).size())); ++i) {       int x = cond[i].first, y = cond[i].second;       int xid = 2 * (abs(x) - 1) + (x > 0 ? 1 : 0),           yid = 2 * (abs(y) - 1) + (y > 0 ? 1 : 0);       g.adj[xid ^ 1].push_back(yid);       g.adj[yid ^ 1].push_back(xid);     }     g.calccomp();     for (int i = (0); i < (na); ++i)       if (g.comp[2 * i + 0] == g.comp[2 * i + 1]) return false;     return true;   }   void run() {     scanf( %d%d%d , &na, &nb, &nc);     for (int i = (0); i < (nb); ++i) {       scanf( %s , opbuff);       bkind[i] = parseop(opbuff);       scanf( %s , inbuff);       assert(strlen(inbuff) == na);       int cnt = 0;       for (int j = (0); j < (na); ++j)         if (inbuff[j] ==  x ) b[i][cnt++] = j;       assert(cnt == 2);     }     for (int i = (0); i < (nc); ++i) {       scanf( %s , opbuff);       ckind[i] = parseop(opbuff);       scanf( %s , inbuff);       assert(strlen(inbuff) == nb);       int cnt = 0;       for (int j = (0); j < (nb); ++j)         if (inbuff[j] ==  x ) c[i][cnt++] = j;       assert(cnt == 2);     }     vector<pair<int, int> > cond0, cond1;     int cnt0 = 0, cnt1 = 0;     for (int i = (0); i < (nc); ++i) {       Z res = classify(i);       if (res.kind == 0) {         ++cnt0;         for (int j = (0); j < (((int)(res.condzero).size())); ++j)           cond0.push_back(res.condzero[j]);       }       if (res.kind == 1) {         ++cnt1;         for (int j = (0); j < (((int)(res.condzero).size())); ++j)           cond1.push_back(res.condzero[j]);       }     }     bool ok0 = !satisfiable(cond0), ok1 = !satisfiable(cond1);     if (!ok0 && !ok1) {       printf( -1 n );       return;     }     int keep = max(ok0 ? cnt0 : 0, ok1 ? cnt1 : 0), ret = nc - keep;     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   int n, m;   vector<vector<int>> adj;   int Set[N];   bool vis[N];   bool isBipartite(int node) {     for (int& x : adj[node]) {       if (!vis[x]) {         vis[x] = 1;         Set[x] = 3 - Set[node];         if (!isBipartite(x)) return false;       } else if (Set[x] == Set[node])         return false;     }     return true;   }   int solve() {     scanf( %d%d , &n, &m);     adj = vector<vector<int>>(n + 1);     int V = -1;     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         vis[i] = 1;         Set[i] = 1;         bool res = isBipartite(i);         if (!res) return puts( -1 ), 0;       }     }     int A = 0, P = 0;     for (int i = 1; i <= n; i++) {       A += Set[i] == 1;       P += Set[i] == 2;     }     printf( %d n , A);     for (int i = 1; i <= n; i++)       if (Set[i] == 1) printf( %d  , i);     printf(  n );     printf( %d n , P);     for (int i = 1; i <= n; i++)       if (Set[i] == 2) printf( %d  , i);     return 0;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long n, dvyg, a[3000000];   long long pointer;   int main() {     cin >> n;     dvyg = 1;     for (int i = 1; i <= n; ++i) a[i] = i;     for (int i = 2; i <= n; ++i) {       pointer = n / i * i + dvyg;       for (int j = pointer; j >= dvyg; j -= i) {         if (j == pointer)           a[dvyg + n] = a[j];         else           a[j + i] = a[j];       }       ++dvyg;     }     for (int i = dvyg; i < dvyg + n; ++i) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void getint(int &v) {     char ch, fu = 0;     for (ch =  * ; (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) fu = 1, ch = getchar();     for (v = 0; ch >=  0  && ch <=  9 ; ch = getchar()) v = v * 10 + ch -  0 ;     if (fu) v = -v;   }   int n, a[500010], t, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) getint(a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n - 1; ++i)       if (a[i] == a[i + 1]) {         if (t) return puts( cslnb ), 0;         t = i;       }     if (t) {       if (t == 1) {         if (a[t] == 0) return puts( cslnb ), 0;         --a[t];       } else {         if (a[t] == a[t - 1] + 1) return puts( cslnb ), 0;         --a[t];       }       for (int i = 1; i <= n; ++i) (ans += a[i] - (i - 1)) %= 2;       if (ans & 1)         puts( cslnb );       else         puts( sjfnb );       return 0;     }     for (int i = 1; i <= n; ++i) (ans += a[i] - (i - 1)) %= 2;     if (ans % 2 == 0)       puts( cslnb );     else       puts( sjfnb );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout <<  [  << *it <<  :   << a <<  ] t ;     err(++it, args...);   }   const long long nax = 1e3 + 5;   long long n;   long long a[nax], dp[nax][nax];   long long fw(long long i, long long j) {     if (i == n) return 0;     if (j == n) return a[i];     if (j == n - 1) return max(a[i], a[j]);     if (dp[i][j] != -1) return dp[i][j];     long long& first = dp[i][j];     first = (long long)(1e18);     first = min(first, fw(j + 1, j + 2) + max(a[i], a[j]));     first = min(first, fw(i, j + 2) + max(a[j], a[j + 1]));     first = min(first, fw(j, j + 2) + max(a[i], a[j + 1]));     return first;   }   void bw(long long i, long long j) {     if (i == n) return;     if (j == n) {       cout << i + 1;       return;     }     if (j == n - 1) {       cout << i + 1 <<     << j + 1 <<   n ;       return;     }     long long first = dp[i][j];     if (first == max(a[i], a[j]) + fw(j + 1, j + 2)) {       cout << i + 1 <<     << j + 1 <<   n ;       bw(j + 1, j + 2);       return;     }     if (first == max(a[j], a[j + 1]) + fw(i, j + 2)) {       cout << j + 1 <<     << j + 2 <<   n ;       bw(i, j + 2);       return;     }     if (first == max(a[i], a[j + 1]) + fw(j, j + 2)) {       cout << i + 1 <<     << j + 2 <<   n ;       bw(j, j + 2);       return;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     memset(dp, -1, sizeof(dp));     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     cout << fw(0, 1) <<   n ;     bw(0, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 77;   long long a[N], f[N], l, r;   int n, k;   bool check(int mid) {     for (int i = 1; i <= n; i++) f[i] = 0;     f[0] = 1;     int pl = 1, pr;     for (int i = 1; i <= n; i++) {       while (a[i] - a[pl] > mid) pl++;       pr = i - k + 1;       for (int j = pl; j <= pr; j++) {         if (f[j - 1]) {           f[i] = 1;           break;         } else           pl++;       }     }     return f[n];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       r = max(a[i], r);     }     for (int i = 1; i <= n; i++) f[i] = 0x3f3f3f3f;     sort(a + 1, a + 1 + n);     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     printf( %lld , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   long long a[N], b[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     long long n;     cin >> n;     long long s = 0;     for (int i = 0; i < n; i++) cin >> a[i], s += a[i];     for (int j = 0; j < n; j++) cin >> b[j];     sort(b, b + n);     if (s <= b[n - 1] + b[n - 2])       cout <<  YES ;     else       cout <<  NO ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int cases(1), t;   template <typename T>   void binary(T n) {     stack<int> st;     while (n > 0) {       st.push(n % 2);       n /= 2;     }     while (!st.empty()) {       cout << st.top();       st.pop();     }     cout <<   n ;   }   vector<long long> factorize(long long x) {     vector<long long> res;     if (x % 2 == 0) {       res.push_back(2);     }     while (x % 2 == 0) {       x /= 2;     }     for (long long i = 3; i * i <= x; i += 2) {       if (x % i == 0) {         res.push_back(i);         while (x % i == 0) {           x /= i;         }       }     }     if (x > 2) res.push_back(x);     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     for (cin >> t; cases <= t; ++cases) {       long long first, second;       cin >> first >> second;       long long ans = 0;       if (first % second) {         cout << first <<   n ;         continue;       }       vector<long long> fac = factorize(second);       for (long long i = 0; i < fac.size(); i++) {         long long res = first;         while (res % second == 0) {           res /= fac[i];         }         ans = max(res, ans);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e+9 + 9;   const long double EPS = 1e-9;   const long double PI = 3.1415926535897932384626433832795;   const int N = 1000500;   int n, k, ans[N];   int main() {     scanf( %d%d , &n, &k);     if (k * 3 > n) {       printf( -1 );       return 0;     }     if (((k)&1)) {       int d = 2;       for (int i = 1; i <= k - 1; i += 2) {         ans[d] = ans[d + 1] = ans[d + 3] = i;         d += 2;         ans[d] = ans[d + 2] = ans[d + 3] = i + 1;         d += 4;       }       ans[1] = k;       for (int i = d; i <= n; ++i) ans[i] = k;     } else {       int d = 1;       for (int i = 1; i <= k; i += 2) {         ans[d] = ans[d + 1] = ans[d + 3] = i;         d += 2;         ans[d] = ans[d + 2] = ans[d + 3] = i + 1;         d += 4;       }       for (int i = d; i <= n; ++i) ans[i] = k;     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200050;   int len;   char a[maxn];   int main() {     while (scanf( %d , &len) != EOF) {       scanf( %s , a);       int ans = 0;       for (int i = 0; i < len; i++)         if (a[i] ==  < )           ans++;         else           break;       for (int i = len - 1; i >= 0; i--)         if (a[i] ==  > )           ans++;         else           break;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma optimizitaion_level 3   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   using namespace std;   int n, h;   vector<int> b;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> h;     b.resize(n);     for (auto &i : b) cin >> i;     for (int i = 0; i < n; i++) {       vector<int> now(i + 1);       for (int j = 0; j <= i; j++) {         now[j] = b[j];       }       sort(now.rbegin(), now.rend());       int free = h;       for (int j = 0; j <= i; j += 2) {         if (free >= now[j]) {           free -= now[j];         } else           return cout << i <<   n , 0;       }     }     cout << n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool GetMin(T &a, T b) {     return ((a <= b) ? false : (a = b, true));   }   template <typename T>   bool GetMax(T &a, T b) {     return ((a >= b) ? false : (a = b, true));   }   const int N = 2333;   const long double eps = 1e-8;   int n, m;   long double px[N], py[N], tx, ty, ki[N * N];   bool del[N];   bool Wow(long double x) { return x < -eps || x > eps; }   bool Judge(long double *_p) {     static long double p[N];     memcpy(p + 1, _p + 1, sizeof(long double) * n);     sort(p + 1, p + n + 1);     long double v = p[1] + p[n];     for (int i = 1; i <= n; ++i)       if (Wow(p[i] + p[n - i + 1] - v)) return false;     return true;   }   bool Check(long double ki) {     static long double p[N];     for (int i = 1; i <= n; ++i) p[i] = ki * px[i] + py[i];     return Judge(p);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %Lf%Lf , px + i, py + i);       tx += px[i];       ty += py[i];     }     tx /= n;     ty /= n;     for (int i = 1; i <= n; ++i)       if (!del[i])         for (int j = i + 1; j <= n; ++j)           if (!Wow(2 * tx - px[i] - px[j]) && !Wow(2 * ty - py[i] - py[j])) {             del[i] = true;             del[j] = true;             break;           }     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (!del[i]) {         px[++cnt] = px[i];         py[cnt] = py[i];       }     n = cnt;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         long double x = py[i] + py[j] - 2 * ty, y = 2 * tx - px[i] - px[j];         if (Wow(x) && Wow(y)) ki[++m] = x / y;       }     if (n <= 2) {       puts( -1 );       return 0;     }     sort(ki + 1, ki + m + 1);     int ans = Judge(px) + Judge(py);     ki[m + 1] = 1e100;     for (int i = 2, cnt = 1; i <= m + 1; ++i) {       if (Wow(ki[i] - ki[i - 1])) {         if (cnt >= (n >> 1)) ans += Check(ki[i - 1]);         cnt = 1;       } else         ++cnt;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 2e6 + 99;   const long long INF = 1e12;   const long long mod = 1e9 + 7;   set<pair<long long, long long>> dif;   set<pair<long long, long long>>::iterator it;   long long N, M, row[1000], col[1000], mark[500][500], imp[500][500],       arr[500][500];   void dfs() {     row[1] = 0;     for (long long A = 1; A <= M; A++) {       if (mark[1][A])         col[A] = 1 - row[1];       else         col[A] = row[1];     }     for (long long A = 2; A <= N; A++) {       if (mark[A][1])         row[A] = 1 - col[1];       else         row[A] = col[1];     }     dif.clear();     for (long long A = 2; A <= N; A++)       for (long long B = 2; B <= M; B++)         if (abs(col[B] - row[A]) != mark[A][B]) dif.insert(make_pair(A, B));     return;   }   void out_() {     cout <<  YES n ;     for (long long A = 1; A <= N; A++) cout << row[A];     cout <<   n ;     for (long long A = 1; A <= M; A++) cout << col[A];     exit(0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (long long A = 1; A <= N; A++)       for (long long B = 1; B <= M; B++) cin >> arr[A][B];     for (long long A = 1; A <= N; A++) {       for (long long B = 1; B <= M; B++) {         if (!arr[A][B])           mark[A][B] = 1;         else           mark[A][B] = 0;       }     }     for (long long A = 1; A <= M; A++) imp[1][A] = 1;     for (long long A = 1; A <= N; A++) imp[A][1] = 1;     dfs();     if (dif.empty()) out_();     for (long long A = 1; A <= N; A++) {       for (long long B = 1; B <= M; B++) {         mark[A][B] = 1 - mark[A][B];         if (imp[A][B]) {           dfs();           if (dif.empty())             out_();           else {             it = dif.end();             it--;             if (dif.begin()->first == A and it->first == A) {               for (auto A : dif) mark[A.first][A.second] ^= 1;               out_();             }           }         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005];   set<int> b;   set<int>::iterator it;   int main() {     long long n, i, s, x, y, z, d, st;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       b.insert(x);     }     n = 0;     for (it = b.begin(); it != b.end(); it++) a[n++] = *it;     scanf( %lld%lld , &x, &y);     s = 0;     st = 0;     while (y < x) {       z = x - 1;       for (i = n - 1; i >= st; i--) {         d = x - x % a[i];         if (z > d && d >= y) z = d;       }       x = z;       while (n > st && x - x % a[st] < y) st++;       while (n > 0 && x - x % a[n - 1] < y) n--;       s++;     }     printf( %lld n , s);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC_OPTIMIZE( ofast )   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     string need;     for (long long i = 0; i < k - 1; i++) {       need.push_back( ( );       need.push_back( ) );     }     for (long long i = 0; i < n / 2 - (k - 1); i++) {       need.push_back( ( );     }     for (long long i = 0; i < n / 2 - (k - 1); i++) {       need.push_back( ) );     }     vector<pair<long long, long long>> ans;     for (long long i = 0; i < n; i++) {       if (s[i] != need[i]) {         for (long long j = i + 1; j < n; j++) {           if (s[j] == need[i]) {             ans.push_back(make_pair(i + 1, j + 1));             reverse(s.begin() + i, s.begin() + j + 1);             break;           }         }       }     }     cout << ans.size() <<   n ;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     for (long long i = 0; i < q; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int index;     int disc, exit;     int val;     int depth;   };   int n, m;   edge e[200010];   vector<int> V[200010];   int disc = 1;   void calc_disc(int curr, int par, int depth) {     e[curr].disc = disc++;     e[curr].depth = depth;     for (int i = 0; i < V[curr].size(); i++) {       int next = V[curr][i];       if (next == par) continue;       calc_disc(next, curr, depth + 1);     }     e[curr].exit = disc++;   }   bool pro(const edge &e1, const edge &e2) { return e1.disc < e2.disc; }   int loga1[200010 * 2], loga2[200010 * 2];   int index_inv[200010];   void update(int x, int val, int log[]) {     for (; x < 200010 * 2; x += x & -x) log[x] += val;   }   int read(int x, int log[]) {     int rez = 0;     for (; x > 0; x -= x & -x) {       rez += log[x];     }     return rez;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &e[i].val);       e[i].index = i;     }     for (int i = 0; i < n - 1; i++) {       int p1, p2;       scanf( %d%d , &p1, &p2);       V[p1].push_back(p2);       V[p2].push_back(p1);     }     calc_disc(1, -1, 1);     sort(e + 1, e + n + 1, pro);     for (int i = 1; i <= n; i++) {       index_inv[e[i].index] = i;     }     for (int i = 0; i < m; i++) {       int p;       scanf( %d , &p);       if (p == 1) {         int x, val;         scanf( %d%d , &x, &val);         edge tmp = e[index_inv[x]];         if (tmp.depth % 2 == 1) val *= -1;         update(tmp.disc, val, loga1);         update(tmp.disc, -val, loga2);         update(tmp.exit, -val, loga1);         update(tmp.exit, val, loga2);       }       if (p == 2) {         int x;         scanf( %d , &x);         edge tmp = e[index_inv[x]];         if (tmp.depth % 2 == 0)           printf( %d n , read(tmp.disc, loga1) + tmp.val);         else           printf( %d n , read(tmp.disc, loga2) + tmp.val);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tab[100][100];   int seed = 1304104130;   int abs(int x) {     if (x < 0)       return -x;     else       return x;   }   int rand() { return seed = abs(seed * 12493LL + 142412 % 1000000009); }   int best(int a) {     int last = -1;     for (int i = 1; i * i < a; ++i) {       if (a % i == 0 && (a / i - i) % 2 == 0) last = (a / i - i) / 2;     }     return last;   }   bool issq(int x) {     int min = 0, max = x;     while (min <= max) {       long long int med = (min + max) / 2;       if (med * med == x)         return true;       else if (med * med > x)         max = med - 1;       else         min = med + 1;     }     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (n == 1 && m == 1) {       printf( 1 n );       return 0;     } else if (n == 1) {       for (int i = 0; i < m - 1; ++i) printf( 3  );       printf( %d n , best(9 * (m - 1)));       return 0;     } else if (m == 1) {       for (int i = 0; i < n - 1; ++i) printf( 3 n );       printf( %d n , best(9 * (n - 1)));       return 0;     }     while (true) {       for (int i = 0; i < n - 1; ++i)         for (int k = 0; k < m - 1; ++k) tab[i][k] = rand() % 3 * 8 + 8;       for (int i = 0; i < n - 1; ++i) {         int sum = 0;         for (int k = 0; k < m - 1; ++k) sum += tab[i][k] * tab[i][k];         tab[i][m - 1] = 2 * best(sum / 4);       }       for (int k = 0; k < m - 1; ++k) {         int sum = 0;         for (int i = 0; i < n - 1; ++i) sum += tab[i][k] * tab[i][k];         tab[n - 1][k] = 2 * best(sum / 4);       }       int sum1 = 0, sum2 = 0;       for (int i = 0; i < n - 1; ++i) sum1 += tab[i][m - 1] * tab[i][m - 1];       for (int k = 0; k < m - 1; ++k) sum2 += tab[n - 1][k] * tab[n - 1][k];       for (int div = 1; div * div < sum1; ++div)         if (sum1 % div == 0 && (div + sum1 / div) % 2 == 0) {           int r = (sum1 / div - div) / 2;           if (issq(r * r + sum2)) {             tab[n - 1][m - 1] = r;             for (int i = 0; i < n; ++i) {               for (int k = 0; k < m; ++k) printf( %d  , tab[i][k]);               putchar(10);             }             return 0;           }         }     }   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> mp;   int a[100001], b[100001];   int main() {     int n, i;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     if (a[1] != b[1] || a[n] != b[n]) {       cout <<  No ;       return 0;     }     for (i = 1; i < n; i++) mp[b[i + 1] - b[i]]++;     for (i = 1; i < n; i++)       if (!mp[a[i + 1] - a[i]]--) {         cout <<  No ;         return 0;       }     cout <<  Yes ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string t, s;     cin >> n >> s;     t = s;     sort(s.begin(), s.end());     int ret = (1 << 21);     for (int i = 0; i < s.length() + 1; i++) {       int dif = 0;       for (int i = 0; i < s.length(); i++) {         if (t[i] != s[i]) dif++;       }       ret = min(ret, dif);       rotate(s.begin(), s.begin() + 1, s.end());     }     cout << ret / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     vector<string> s1;     for (int i = 0; i < int((s).size()); i++) {       string s2(int((s).size()) - i,  0 );       if (s[i] !=  0 ) {         s2[0] = s[i];         s1.push_back(s2);       }     }     cout << s1.size() <<   n ;     for (auto i : s1) {       cout << i <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int dis(int x, int y) { return (x * x + y * y); }   int main() {     int d, n, i, x, y, r, cnt = 0, R1, R2;     cin >> r >> d;     R1 = r;     R2 = r - d;     cin >> n;     while (n--) {       cin >> x >> y >> r;       d = dis(x, y);       if (d <= ((R1 - r) * (R1 - r)) && d >= ((R2 + r) * (R2 + r))) {         cnt++;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Position {     int r, c, t;     Position(int r, int c, int t) {       this->r = r;       this->c = c;       this->t = t;     }   };   int main() {     vector<string> board;     vector<pair<int, int> > s;     for (int r = 0; r < 8; r++) {       string line;       cin >> line;       board.push_back(line);       for (int c = 0; c < 8; c++)         if (line[c] ==  S ) s.push_back(make_pair(r, c));     }     queue<Position> que;     que.push(Position(7, 0, 0));     int dr[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};     int dc[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};     while (!que.empty()) {       Position pos = que.front();       que.pop();       if (pos.t > 7) break;       for (int i = 0; i < 9; i++) {         int nr = pos.r + dr[i];         int nc = pos.c + dc[i];         if (0 <= nr && nr < 8 && 0 <= nc && nc < 8) {           bool isCollision = false;           for (int j = 0; j < (int)s.size(); j++) {             if ((nr == s[j].first + pos.t && nc == s[j].second) ||                 (nr == s[j].first + pos.t + 1 && nc == s[j].second)) {               isCollision = true;               break;             }           }           if (!isCollision) {             que.push(Position(nr, nc, pos.t + 1));           }         }       }     }     cout << (que.empty() ?  LOSE  :  WIN ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int sz, ans = 0, cnt = 0;     cin >> s;     sz = s.size();     ans = sz;     for (int i = 0; i < sz; i++)       if (s[i] ==  a ) cnt++;     while (cnt < ((ans / 2) + 1)) ans--;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, q;     cin >> n >> m >> q;     vector<long long> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> weights(m, 0);     vector<int> heavyListsIds;     vector<vector<int> > lists(m, vector<int>());     int heavyBorder = ceil(sqrt(0.0 + n));     int heavyCount = 0;     for (int i = 0; i < m; ++i) {       int length;       cin >> length;       if (length > heavyBorder) {         weights[i] = 42;         ++heavyCount;         heavyListsIds.push_back(i);       } else         weights[i] = 1;       lists[i].resize(length);       for (int j = 0; j < length; ++j) cin >> lists[i][j], --lists[i][j];       sort((lists[i]).begin(), (lists[i]).end());     }     vector<vector<int> > intersectionSize(m, vector<int>(heavyCount, 0));     for (int i = 0; i < (lists).size(); ++i)       for (int j = 0; j < (heavyListsIds).size(); ++j) {         int first = i, second = heavyListsIds[j];         if (first == second) continue;         if ((lists[first]).size() > (lists[second]).size()) {           int temp = first;           first = second;           second = temp;         }         for (int k = 0; k < (lists[first]).size(); ++k)           if (binary_search(lists[second].begin(), lists[second].end(),                             lists[first][k]))             ++intersectionSize[first][j];       }     vector<long long> cachedResults(heavyCount, 0), cachedUpdates(heavyCount, 0);     for (int i = 0; i < heavyCount; ++i) {       int listId = heavyListsIds[i];       for (int j = 0; j < (lists[listId]).size(); ++j)         cachedResults[i] += a[lists[listId][j]];     }     for (int i = 0; i < q; ++i) {       char c;       cin >> c;       if (c ==  + ) {         long long k, x;         cin >> k >> x;         --k;         if (weights[k] == 42) {           int heavy_k = 0;           for (int j = 0; j < heavyCount; ++j)             if (heavyListsIds[j] == k) {               heavy_k = j;               break;             }           cachedUpdates[heavy_k] += x;         } else {           for (int j = 0; j < (lists[k]).size(); ++j) a[lists[k][j]] += x;           for (int j = 0; j < heavyCount; ++j)             cachedResults[j] += intersectionSize[k][j] * x;         }       } else {         int k;         cin >> k;         --k;         if (weights[k] == 1) {           long long result = 0;           for (int j = 0; j < (lists[k]).size(); ++j) result += a[lists[k][j]];           for (int j = 0; j < heavyCount; ++j)             result += intersectionSize[k][j] * cachedUpdates[j];           cout << result << endl;         } else {           int heavy_k = 0;           for (int j = 0; j < heavyCount; ++j)             if (heavyListsIds[j] == k) {               heavy_k = j;               break;             }           long long result =               cachedResults[heavy_k] + cachedUpdates[heavy_k] * (lists[k]).size();           for (int j = 0; j < heavyCount; ++j)             result += intersectionSize[k][j] * cachedUpdates[j];           cout << result << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T expo(T e, T n) {     T x = 1, p = e;     while (n) {       if (n & 1) x = x * p;       p = p * p;       n >>= 1;     }     return x;   }   template <typename T>   T power(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = (x * p) % m;       p = (p * p) % m;       n >>= 1;     }     return x;   }   template <typename T>   T InverseEuler(T a, T m) {     return (a == 1 ? 1 : power(a, m - 2, m));   }   template <typename T>   T gcd(T a, T b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   template <typename T>   T lcm(T a, T b) {     return (a * (b / gcd(a, b)));   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   map<string, long long> M;   map<long long, string> invM;   long long n = 1;   vector<long long> g[5000], temp;   bool vis[5000];   long long in[5000], out[5000];   vector<pair<string, string> > ans;   void dfs(long long node) {     vis[node] = true;     temp.push_back(node);     for (auto it : g[node]) {       if (!vis[it]) {         dfs(it);       }     }     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     for (__typeof(q) i = 1; i <= q; ++i) {       string s, second;       cin >> s >> second;       if (M.find(s) == M.end()) {         M[s] = n;         invM[n] = s;         n++;       }       if (M.find(second) == M.end()) {         M[second] = n;         invM[n] = second;         n++;       }       g[M[s]].push_back(M[second]);       in[M[second]] += 1;       out[M[s]] += 1;     }     long long components = 0;     for (__typeof(n - 1) i = 1; i <= n - 1; ++i) {       if (!vis[i]) {         components++;         temp.clear();         dfs(i);         string A, B;         for (auto it : temp) {           if (in[it] == 0) A = invM[it];           if (out[it] == 0) B = invM[it];         }         ans.push_back({A, B});       }     }     cout << components <<   n ;     for (auto it : ans) {       cout << it.first <<     << it.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int n, i;   char s[100005];   long long a[270], r;   int main() {     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) a[s[i]]++;     for (i = 0; i < 270; i++) r += a[i] * a[i];     printf( %I64d n , r);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T mceil(T a, T b) {     if (a % b == 0)       return a / b;     else       return a / b + 1;   }   const long long int M = 1e9 + 7;   const long long int N = 2e5 + 5;   const long long int inf = 9e18;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<long long int> a(n), b(m);     map<long long int, long long int> mp;     vector<pair<long long int, long long int> > v;     long long int am = -1;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       am = max(a[i], am);       ans += a[i] * m;       v.push_back({a[i], m - 1});     }     for (long long int i = 0; i < m; i++) cin >> b[i];     sort((v).rbegin(), (v).rend());     vector<long long int> g;     for (long long int i = 0; i < m; i++) {       if (b[i] < am) {         cout << -1 <<   n ;         return 0;       } else if (b[i] == am)         continue;       else {         g.push_back(b[i]);       }     }     sort((g).rbegin(), (g).rend());     long long int ind = 0;     for (long long int i = 0; i < (int)((g).size()); i++) {       if (ind < n and v[ind].second) {         ans += g[i] - v[ind].first;         v[ind].second--;         if (v[ind].second == 0) ind++;       } else {         cout << -1;         return 0;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   int a[2010];   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     int n, count = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] == 1) ++count;     }     if (count) {       printf( %d , n - count);     } else {       int t = INF;       int i, j;       for (i = 1; i <= n; ++i) {         int x = a[i];         for (j = i + 1; j <= n; ++j) {           x = gcd(x, a[j]);           if (x == 1) {             t = min(t, j - i + 1);             break;           }         }       }       if (t == INF) {         puts( -1 );       } else {         printf( %d n , t - 1 + n - 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n;   pair<int, int> a[N];   void rec(int l, int r) {     if (l >= r) {       return;     }     int mid = (r + l) >> 1;     rec(l, mid);     rec(mid + 1, r);     for (int i = l; i <= r; i++) {       n++;       a[n] = make_pair(a[mid].first, a[i].second);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a + 1, a + n + 1);     rec(1, n);     sort(a + 1, a + n + 1);     n = unique(a + 1, a + n + 1) - a - 1;     cout << n <<   n ;     for (int i = 1; i <= n; i++) {       cout << a[i].first <<     << a[i].second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int higherR(int candies[], int index, int n, int c) {     int counter = 0;     for (int i = index + 1; i < n; i++) {       if (candies[i] > candies[index] && candies[i] != c) {         counter++;       }     }     return counter;   }   int higherL(int candies[], int index, int n, int c) {     int counter = 0;     for (int i = index - 1; i >= 0; i--) {       if (candies[i] > candies[index] && candies[i] != c) {         counter++;       }     }     return counter;   }   int main() {     int n;     cin >> n;     int l[n], r[n];     for (int i = 0; i < n; i++) {       cin >> l[i];     }     for (int i = 0; i < n; i++) {       cin >> r[i];     }     int candies[n];     for (int i = 0; i < n; i++) {       candies[i] = -1;     }     int currentNumberOfCandies = n - 1;     int childrenFed = 0;     bool contradiction = true;     for (int i = 0; i < n; i++) {       if (l[i] == 0 && r[i] == 0) {         candies[i] = n;         ++childrenFed;         contradiction = false;       }     }     if (contradiction) {       cout <<  NO ;       return 0;     }     while (childrenFed < n) {       if (currentNumberOfCandies < 1) {         cout <<  NO ;         return 0;       }       for (int i = 0; i < n; i++) {         if (candies[i] != -1) {           continue;         }         if (higherL(candies, i, n, currentNumberOfCandies) > l[i] ||             higherR(candies, i, n, currentNumberOfCandies) > r[i]) {           cout <<  NO ;           return 0;         }         if (higherL(candies, i, n, currentNumberOfCandies) == l[i] &&             higherR(candies, i, n, currentNumberOfCandies) == r[i]) {           candies[i] = currentNumberOfCandies;           ++childrenFed;         }       }       --currentNumberOfCandies;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << candies[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T;   double n;   int main() {     cin >> T;     while (T-- > 0) {       cin >> n;       printf( %.9lf n , (1.0 / (2.0 * sin(acos(-1.0) / (2.0 * n)))) *                             cos(acos(-1.0) / 2 / n) * 2);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t, n, i, j;     string second;     cin >> t;     while (t--) {       cin >> second;       vector<int> v1, v2;       n = second.length();       for (i = 0; i < n; i++) {         if ((second[i] -  0 ) % 2)           v1.push_back(second[i] -  0 );         else           v2.push_back(second[i] -  0 );       }       string ans =   ;       i = j = 0;       while (i < v1.size() && j < v2.size()) {         if (v1[i] < v2[j])           ans += char(v1[i++] +  0 );         else           ans += char(v2[j++] +  0 );       }       while (i < v1.size()) ans += char(v1[i++] +  0 );       while (j < v2.size()) ans += char(v2[j++] +  0 );       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   char question[4][100];   int len[4];   int main() {     for (int i = 0; i < 4; i++) {       cin >> question[i];       string s = question[i];       len[i] = s.size() - 2;     }     int count_ = 0;     int index = -1;     for (int i = 0; i < 4; i++) {       int n;       n = len[0];       len[0] = len[i];       len[i] = n;       if (((len[0] <= (len[1] / 2)) && (len[0] <= (len[2] / 2)) &&            (len[0] <= (len[3] / 2))) ||           ((len[0] >= (2 * len[1])) && (len[0] >= (2 * len[2])) &&            (len[0] >= (2 * len[3])))) {         index = i;         count_++;       }     }     if (count_ == 1) {       cout << (char)(index + 65);     } else {       cout <<  C ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[1005], y[1005], r[1005], level[1005];   long long sum[1005];   vector<pair<int, int> > X[1005];   void dfs(int node, int l) {     level[node] = l;     int i;     for (i = 0; i < X[node].size(); i++) {       if (level[X[node][i].second] <= level[node]) dfs(X[node][i].second, l + 1);     }   }   bool check(int ind1, int ind2) {     if (r[ind1] < r[ind2]) return false;     long double dist = (long long)(x[ind1] - x[ind2]) * (x[ind1] - x[ind2]) +                        (long long)(y[ind1] - y[ind2]) * (y[ind1] - y[ind2]);     dist = sqrtl(dist);     if (dist + r[ind2] > (long double)r[ind1]) return false;     return true;   }   int main() {     int n;     scanf( %d , &n);     int i;     for (i = 1; i <= n; i++) {       scanf( %d%d%d , x + i, y + i, r + i);     }     for (i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (check(i, j)) X[i].push_back(make_pair(r[j], j));         if (check(j, i)) X[j].push_back(make_pair(r[i], i));       }     }     for (i = 1; i <= n; i++) {       sort(X[i].begin(), X[i].end());       reverse(X[i].begin(), X[i].end());     }     for (i = 1; i <= n; i++) {       if (!level[i]) dfs(i, 1);     }     for (i = 1; i <= n; i++) {       sum[level[i]] += (long long)r[i] * r[i];     }     int cnt = 0;     long long ans = 0;     for (i = 1; i <= 1000; i++) {       if (i <= 2) {         ans += sum[i];         continue;       }       if (i % 2)         ans -= sum[i];       else         ans += sum[i];     }     long double p = (long double)(3.14159265359) * ans;     cout.precision(9);     cout << fixed << p;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(const int a, const int b) { return a > b; }   long long binpow(long long a, long long n, int mod) {     long long res = 1;     while (n)       if (n & 1) {         res *= a;         res %= mod;         --n;       } else {         a *= a;         a %= mod;         n >>= 1;       }     if (res == 0) res = mod;     return res;   }   vector<int> prefix_function(string s) {     int n = (int)s.length();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }     return pi;   }   string ss1, ss2;   int main() {     vector<int> a = prefix_function( a#aa );     int n;     cin >> n;     string s, str;     vector<string> v;     for (int i = 0; i < n; i++) {       cin >> str;       v.push_back(str);     }     for (int i =  a ; i <=  z ; i++) {       bool bb = true;       ss1 = i;       string f = ss1;       for (int ii = 0; ii < n && bb == true; ii++) {         vector<int> a = prefix_function(f +  #  + v[ii]);         for (int jj = f.length() + 1; jj < a.size() && bb == true; jj++) {           if (a[jj] == f.size()) {             bb = false;             break;           }         }       }       if (bb == true) {         cout << f;         return 0;       }     }     for (int i =  a ; i <=  z ; i++) {       for (int j =  a ; j <=  z ; j++) {         bool bb = true;         ss1 = i;         ss2 = j;         string f = ss1.append(ss2);         for (int ii = 0; ii < n && bb == true; ii++) {           vector<int> a = prefix_function(f +  #  + v[ii]);           for (int jj = f.length() + 1; jj < a.size() && bb == true; jj++) {             if (a[jj] == f.size()) {               bb = false;               break;             }           }         }         if (bb == true) {           cout << f;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct l {     int index;     int depth;     int color;   };   int a[100001];   struct BFSearch {     vector<pair<l, vector<int> > > adj;     queue<l> k;     void clear1() {       for (int i = 0; i < adj.size(); i++) {         adj[i].first.color = 0;         adj[i].first.depth = -1;       }     }     void bfs(int i) {       if (i > adj.size() - 1) return;       l o;       int p;       adj[i].first.color = 0;       adj[i].first.depth = 0;       k.push(adj[i].first);       while (k.size() != 0) {         o = k.front();         k.pop();         for (int i = 0; i < adj[o.index].second.size(); i++) {           p = adj[o.index].second[i];           if (adj[p].first.color == 0) {             adj[p].first.color = 1;             adj[p].first.depth = o.depth + 1;             k.push(adj[p].first);           }         }         adj[o.index].first.color = 2;       }     }   };   int main() {     pair<l, vector<int> > op;     BFSearch k;     int n, temp;     l p;     p.depth = -1;     p.color = 0;     cin >> n;     vector<int> x;     for (int i = 0; i < n; i++) {       op.second = x;       p.index = i;       op.first = p;       k.adj.push_back(op);     }     for (int i = 1; i < n; i++) {       cin >> temp;       k.adj[i].second.push_back(temp - 1);       k.adj[temp - 1].second.push_back(i);     }     k.bfs(0);     for (int i = 0; i < k.adj.size(); i++) {       a[k.adj[i].first.depth]++;     }     long sum = 0;     for (int i = 0; i < k.adj.size(); i++) {       if (a[i] % 2 == 1) sum += 1;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   char s[N];   int main(void) {     int n;     while (cin >> n) {       int cntl = 0;       int cntr = 0;       int cntq = 0;       getchar();       n = abs(n);       scanf( %s , s);       if (s[0] ==  )  || s[n - 1] ==  ( ) {         puts( :( );         continue;       }       if (n == 0) {         puts( :( );         continue;       }       if (n & 1) {         puts( :( );         continue;       }       for (int i = 0; i < n; i++) {         if (s[i] ==  ) )           cntr++;         else if (s[i] ==  ( )           cntl++;         else           cntq++;       }       if (abs(cntl - cntr) > cntq) {         puts( :( );         continue;       }       int needl = n / 2 - cntl;       for (int i = 0; i < n; i++) {         if (needl) {           if (s[i] ==  ? ) {             s[i] =  ( ;             needl--;           }         } else {           if (s[i] ==  ? ) s[i] =  ) ;         }       }       bool flg = false;       cntl = 0;       cntr = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  ) )           cntr++;         else           cntl++;         if ((i + 1) % 2 == 0) {           if (cntr == cntl && i + 1 != n) {             flg = true;             break;           }         }       }       if (flg == false) {         printf( %s n , s);       } else         puts( :( );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE* in = stdin;   FILE* out = stdout;   const int MAX = 100001;   int n, k;   int a[MAX];   int color[256];   void solve() {     memset(color, -1, sizeof(color));     color[0] = 0;     for (int i = 0; i < n; i++) {       if (color[a[i]] != -1) continue;       int left = -1;       for (int c = 0;; c++) {         if (color[a[i] - c] != -1) {           left = a[i] - c;           break;         }       }       if (color[left] + k - 1 >= a[i]) {         for (int c = left + 1; c <= a[i]; c++) color[c] = color[left];         continue;       }       int at = a[i];       if (at - k + 1 > left) {         for (int c = at - k + 1; c <= at; c++) color[c] = at - k + 1;         continue;       }       for (int c = left + 1; c <= a[i]; c++) color[c] = left + 1;     }     for (int i = 0; i < n; i++)       fprintf(out,  %d%c , color[a[i]], i + 1 == n ?   n  :    );   }   int main(void) {     fscanf(in,  %d %d , &n, &k);     for (int i = 0; i < n; i++) fscanf(in,  %d , &a[i]);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<char> s;     char ch;     int rep = 0;     for (int i = 0; i < n; i++) {       cin >> ch;       if (s.find(ch) != s.end()) rep++;       s.insert(ch);     }     if (26 - s.size() >= rep)       cout << rep;     else       cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> p;     vector<int> n;     vector<int> z;     int t;     cin >> t;     int x;     for (int i = 0; i < t; i++) {       cin >> x;       if (x > 0)         p.push_back(x);       else if (x < 0)         n.push_back(x);       else         z.push_back(x);     }     if (t == 1)       cout << x;     else if (z.size() == t) {       for (int i = 0; i < z.size(); i++) cout << z[i] <<    ;     } else if (z.size() + n.size() == t) {       if (n.size() == 1)         cout << 0;       else {         if (n.size() % 2 != 0) {           sort(n.rbegin(), n.rend());           for (int i = 1; i < n.size(); i++) cout << n[i] <<    ;         } else {           for (int i = 0; i < n.size(); i++) cout << n[i] <<    ;         }       }     } else if ((p.size() > 0 || p.size() == 0) &&                (n.size() > 0 || n.size() == 0)) {       for (int i = 0; i < p.size(); i++) cout << p[i] <<    ;       if (n.size() % 2 == 0) {         for (int i = 0; i < n.size(); i++) cout << n[i] <<    ;       } else {         sort(n.rbegin(), n.rend());         for (int i = 1; i < n.size(); i++) cout << n[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int t;   void solve() {     while (t--) {       long long int n, k, res = 0;       cin >> n >> k;       if (n < k)         res = k - n;       else if ((n - k) % 2 == 0 && n >= k) {         res = 0;       } else         res = 1;       cout << res <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], n, k;   bool cmp(int x, int y) { return x % 10 > y % 10; }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n, cmp);     for (int i = 0; i < n; i++) {       if (a[i] % 10 == 0 || k < 10 - a[i] % 10) break;       k -= 10 - a[i] % 10;       a[i] += 10 - a[i] % 10;     }     for (int i = 0; i < n; i++) {       if (k < 10) break;       int cpy = a[i];       a[i] = min(100, a[i] + k - k % 10);       k -= (a[i] - cpy);     }     int ans = 0;     for (int i = 0; i < n; i++) ans += a[i] / 10;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int N = 1e5 + 5;   int a[N];   int b[N];   int main() {     ios_base::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       vector<int> ve1, ve2;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       for (int i = 0; i < n; i++) ve1.push_back(a[i]);       for (int i = 0; i < n; i++) ve2.push_back(b[i]);       sort(ve1.begin(), ve1.end());       sort(ve2.begin(), ve2.end());       multiset<pair<int, long long> > mse;       bool res = true;       for (int i = 0; i < (n + 1) / 2; i++) {         int mn = min(a[i], a[n - i - 1]);         int mx = max(a[i], a[n - i - 1]);         mse.insert({mn, mx});       }       for (int i = 0; i < (n + 1) / 2; i++) {         int mn = min(b[i], b[n - i - 1]);         int mx = max(b[i], b[n - i - 1]);         pair<int, long long> x = {mn, mx};         if (mse.find(x) != mse.end()) {           mse.erase(mse.find(x));         } else {           res = false;         }       }       if (res)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modexp(long long int a, long long int b) {     long long int ret = 1;     while (b) {       if ((b & 1)) {         ret *= a;         ret %= 1000000007;       }       a *= a;       a %= 1000000007;       b >>= 1;     }     return ret;   }   long long int fact[200000];   int main() {     int n, k;     long long int ret = 1;     fact[0] = 1;     int i;     for (i = 1; i <= 1000; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= 1000000007;     }     scanf( %d %d , &n, &k);     ret *= modexp(k, k - 1);     ret %= 1000000007;     ret *= modexp(n - k, n - k);     ret %= 1000000007;     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   long long m;   long long from, to;   long long x, y;   int visit[2][1000010];   int main() {     std::cin >> m;     int i, time;     int cs[2], ci[2], targ[2];     for (i = 0; i < 2; ++i) {       std::cin >> from >> to >> x >> y;       time = 1;       int cur = from;       while (true) {         if (visit[i][cur]) {           cs[i] = time - visit[i][cur];           ci[i] = visit[i][cur];           break;         }         visit[i][cur] = time;         cur = (cur * x + y) % m;         ++time;       }       targ[i] = visit[i][to];     }     if (targ[0] == 0 || targ[1] == 0) {       std::cout << -1;     } else {       bool oncyc[2];       for (i = 0; i < 2; ++i) oncyc[i] = (targ[i] >= ci[i]);       if (!oncyc[0] && !oncyc[1]) {         if (targ[0] != targ[1])           std::cout << -1;         else           std::cout << targ[0] - 1;       } else if (!oncyc[0]) {         if (targ[0] >= targ[1] && !((targ[0] - targ[1]) % cs[1]))           std::cout << targ[0] - 1;         else           std::cout << -1;       } else if (!oncyc[1]) {         if (targ[1] >= targ[0] && !((targ[1] - targ[0]) % cs[0]))           std::cout << targ[1] - 1;         else           std::cout << -1;       } else {         long long cur = targ[0];         for (i = 0; i <= m + 1; ++i) {           if (cur >= targ[1] && (cur - targ[1]) % cs[1] == 0) break;           cur += cs[0];         }         if (i <= m + 1)           std::cout << cur - 1;         else           std::cout << -1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150001;   int a[N], vis[N];   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       memset(vis, 0, sizeof(vis));       int ans = 0;       for (int i = 1; i <= n; i++) {         if (vis[a[i] - 1] == 0 && a[i] != 1)           vis[a[i] - 1] = 1, ans++;         else if (vis[a[i]] == 0)           vis[a[i]] = 1, ans++;         else if (vis[a[i] + 1] == 0)           vis[a[i] + 1] = 1, ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string kStart =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   const string kPrefix =  What are you doing while sending   ;   const string kCenter =   ? Are you busy? Will you send   ;   const string kTail =   ? ;   const int64_t kMaxK = 1.0E18;   const int64_t kInf = numeric_limits<int64_t>::max();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int Q;     cin >> Q;     vector<int64_t> L;     L.push_back(75);     for (;;) {       int64_t cand = 68 + 2 * L.back();       if (cand > kMaxK) {         break;       }       L.push_back(cand);     }     string R;     for (int q = 0; q < Q; ++q) {       int N;       int64_t K;       cin >> N >> K;       if (N < L.size()) {         if (K > L[N]) {           R +=  . ;           continue;         }       }       for (;;) {         if (N == 0) {           R += kStart[K - 1];           break;         }         if (K <= kPrefix.size()) {           R += kPrefix[K - 1];           break;         }         int64_t prev_len = N - 1 < L.size() ? L[N - 1] : kInf;         if (prev_len == kInf || K <= kPrefix.size() + prev_len) {           --N;           K -= kPrefix.size();           continue;         }         if (K <= kPrefix.size() + prev_len + kCenter.size()) {           R += kCenter[K - kPrefix.size() - prev_len - 1];           break;         }         if (K <= kPrefix.size() + 2 * prev_len + kCenter.size()) {           --N;           K -= kPrefix.size() + kCenter.size() + prev_len;           continue;         }         R += kTail[K - 2 * prev_len - kPrefix.size() - kCenter.size() - 1];         break;       }     }     cout << R <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000,1000000000 )   using namespace std;   const long long inf = 1e18 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   const double PI = 2 * acos(0.0);   const double E = 2.71828;   int f[1 << 24], sum[1 << 24], n, k, a[24], b[2];   int main(void) {     scanf( %d , &n);     for (long long(i) = 0; (i) < (long long)(n); (i)++) scanf( %d , &a[i]);     scanf( %d , &k);     b[0] = b[1] = -1;     for (long long(i) = 0; (i) < (long long)(k); (i)++) scanf( %d , &b[i]);     f[0] = 1;     for (long long(i) = 0; (i) < (long long)(1 << n); (i)++) {       if (i) sum[i] = sum[i & (i - 1)] + a[__builtin_ctz(i)];       if (sum[i] == b[0] || sum[i] == b[1]) continue;       for (long long j = i; j; j &= j - 1) {         f[i] += f[i ^ (j & -j)];         if (f[i] >= mod) f[i] -= mod;       }     }     printf( %d n , f[(1 << n) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   struct node {     int u, v, w, t;   } e[1000005], E[1000005];   int cmp(node a, node b) { return a.w < b.w; }   struct Union_Find_Set {     int top, stk[1000005], siz[1000005], tot, fa[1000005];     void init(int x) {       tot = x;       for (int i = 1; i <= x; i++) fa[i] = i, siz[i] = 1;       return;     }     int find(int x) {       while (x != fa[x]) x = fa[x];       return x;     }     void link(int x, int y) {       int u = find(x), v = find(y);       if (u == v) return;       if (siz[u] < siz[v]) swap(u, v);       tot -= (siz[u] & 1);       tot -= (siz[v] & 1);       siz[u] += siz[v];       fa[v] = u;       tot += (siz[u] & 1);       stk[++top] = v;       return;     }     void cut() {       int x = stk[top], u = find(x);       --top;       tot -= (siz[u] & 1);       siz[u] -= siz[x];       fa[x] = x;       tot += (siz[u] & 1);       tot += (siz[x] & 1);     }   } S;   int n, m, ans[1000005], id[1000005];   void solve(int l, int r, int x, int y) {     if (l > r) return;     int mid = (l + r) >> 1, pre = S.top;     for (int i = l; i <= mid; i++)       if (id[i] < x) S.link(E[i].u, E[i].v);     for (int i = x; i <= y; i++) {       if (e[i].t <= mid) S.link(e[i].u, e[i].v);       if (!S.tot) {         ans[mid] = i;         break;       }     }     while (S.top > pre) S.cut();     if (!ans[mid]) {       for (int i = l; i <= mid; i++)         if (id[i] < x) S.link(E[i].u, E[i].v);       solve(mid + 1, r, x, y);       while (S.top > pre) S.cut();       return;     }     for (int i = l; i <= mid; i++)       if (id[i] < x) S.link(E[i].u, E[i].v);     solve(mid + 1, r, x, ans[mid]);     while (S.top > pre) S.cut();     for (int i = x; i < ans[mid]; i++)       if (e[i].t < l) S.link(e[i].u, e[i].v);     solve(l, mid - 1, ans[mid], y);     while (S.top > pre) S.cut();   }   int main() {     n = read();     m = read();     S.init(n);     for (int i = 1; i <= m; i++) {       e[i].u = read();       e[i].v = read();       e[i].w = read();       e[i].t = i;     }     for (int i = 1; i <= m; i++) E[i] = e[i];     sort(e + 1, e + 1 + m, cmp);     for (int i = 1; i <= m; i++) id[e[i].t] = i;     solve(1, m, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i] ? e[ans[i]].w : -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[30001];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> arr[i];       }       int dp1 = arr[1];       int dp2 = 0;       bool fail = 0;       for (int i = 2; i < n; i++) {         arr[i] = arr[i] - dp2;         if (arr[i] < 0) {           fail = 1;           break;         }         if (arr[i] > dp1) {           arr[i] = arr[i] - dp1;           dp2 = dp2 + arr[i];         } else {           dp1 = arr[i];         }       }       if (dp2 > arr[n]) {         fail = 1;       }       if (fail) {         cout <<  NO               <<   n ;       } else {         cout <<  YES               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int k;   long long s[16], sum;   map<long long, int> id;   vector<long long> v;   bool vis[16];   bool dp[1 << 15];   vector<pair<int, int> > way[1 << 15];   int pre[1 << 15];   pair<int, int> ans[16];   int main() {     scanf( %d , &k);     for (int i = 0; i < k; i++) {       int n;       scanf( %d , &n);       while (n--) {         int x;         scanf( %d , &x);         s[i] += x, sum += x;         id[x] = i;         v.push_back(x);       }     }     if (sum % k)       printf( No n );     else {       sum /= k;       for (auto x : v) {         for (int i = 0; i < k; i++) vis[i] = false;         long long now = x;         int mask = 0;         vector<pair<int, int> > opt;         bool f = true;         while (!vis[id[now]]) {           vis[id[now]] = true;           long long pre = now;           now = sum - s[id[now]] + now;           if (id.count(now) == 0) {             f = false;             break;           }           if (vis[id[now]] && now != x) {             f = false;             break;           }           mask |= 1 << id[pre];           opt.push_back(pair<int, int>(now, pre));         }         if (f == true) way[mask] = opt;       }       dp[0] = 1;       for (int i = 1; i < (1 << k); i++) {         for (int j = i - 1; j != i; j = (j - 1) & i) {           if (dp[j] && !way[i ^ j].empty()) {             dp[i] = 1;             pre[i] = j;             break;           }         }       }       if (!dp[(1 << k) - 1])         printf( No n );       else {         printf( Yes n );         int now = (1 << k) - 1;         while (now) {           int x = now ^ (pre[now]);           for (auto p : way[x])             ans[id[p.first]] = pair<int, int>(p.first, id[p.second]);           now = pre[now];         }         for (int i = 0; i < k; i++)           printf( %d %d n , ans[i].first, ans[i].second + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool mark[100007] = {0};   vector<pair<long long int, long long int> > adj[100007];   vector<long long int> ans;   long long int d[100007];   long long int par[100007];   void dijkstra(long long int v) {     d[v] = 0;     long long int u;     priority_queue<pair<long long int, long long int>,                    vector<pair<long long int, long long int> >,                    greater<pair<long long int, long long int> > >         pq;     pq.push(make_pair(d[v], v));     while (!pq.empty()) {       u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = true;       for (auto p : adj[u])         if (d[p.first] > d[u] + p.second) {           par[p.first] = u;           d[p.first] = d[u] + p.second;           pq.push({d[p.first], p.first});         }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m;     cin >> n >> m;     for (long long int i = 1; i <= m; i++) {       long long int a, b, w;       cin >> a >> b >> w;       adj[a].push_back(make_pair(b, w));       adj[b].push_back(make_pair(a, w));     }     for (long long int i = 1; i <= n; i++) {       d[i] = 100000000000000;       par[i] = -1;     }     dijkstra(1);     if (d[n] == 100000000000000)       cout <<  -1  << endl;     else {       long long int x = n;       while (x != 1) {         ans.push_back(x);         x = par[x];       }       ans.push_back(1);       reverse(ans.begin(), ans.end());       for (auto it : ans) cout << it <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 1e5 + 5;   const int inf = 1e9;   vector<int> adj[mxn];   bool f1[mxn], f2[mxn];   bool done;   int ask(char x, int y) {     cout << x <<     << y << endl;     int r;     cin >> r;     return r;   }   int dfs(int cur, int prev) {     if (done) return -1;     if (f1[cur]) {       done = true;       int x = ask( A , cur);       if (f2[x]) return cur;       return -1;     }     for (int u : adj[cur]) {       if (u == prev) continue;       int x = dfs(u, cur);       if (done) return x;     }     return -1;   }   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       adj[i].clear();       f1[i] = false;       f2[i] = false;     }     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     int k1;     cin >> k1;     int x[k1];     for (int i = 0; i < k1; i++) {       cin >> x[i];       f1[x[i]] = true;     }     int k2;     cin >> k2;     int y[k2];     for (int i = 0; i < k2; i++) {       cin >> y[i];       f2[y[i]] = true;     }     done = false;     int r = ask( B , y[0]);     cout <<  C   << dfs(r, -1) << endl;   }   int main() {     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[3];     cin >> s;     int a;     char b;     b = s[0];     a = s[1];     if ((b ==  a  || b ==  h ) && (a ==  1  || a ==  8 ))       cout << 3;     else if ((b ==  a  || b ==  h ) && (a >  1  && a <  8 ))       cout << 5;     else if ((a ==  1  || a ==  8 ) || (a >  a  && a <  h ))       cout << 5;     else       cout << 8;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int maxn = 1e5 + 5;   pair<int, int> node[maxn];   vector<int> V[maxn];   int n;   set<pair<int, int> > Snode;   int xx[maxn], xcnt;   bool find(int x, int y) {     if (x < maxn)       return binary_search(V[x].begin(), V[x].end(), y);     else       return false;   }   int main() {     scanf( %d , &n);     int x, y;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       node[i] = {x, y};       xx[++xcnt] = x;     }     sort(node + 1, node + 1 + n);     for (int i = 1; i <= n; i++) {       V[node[i].first].push_back(node[i].second);     }     sort(xx + 1, xx + 1 + xcnt);     xcnt = unique(xx + 1, xx + 1 + xcnt) - xx - 1;     42;     int sz = sqrt(maxn);     int res = 0;     for (int i = 1; i <= xcnt; i++) {       x = xx[i];       if (V[x].size() <= sz) {         for (int j = 0; j < V[x].size(); j++) {           for (int k = j + 1; k < V[x].size(); k++) {             int tmp = V[x][k] - V[x][j];             if (find(x + tmp, V[x][j]) && find(x + tmp, V[x][k])) res++;           }         }       } else {         for (int j = i + 1; j <= xcnt; j++) {           int x2 = xx[j];           if (V[x2].size() <= 1) continue;           for (int k = 0; k < V[x2].size(); k++) {             int tmp = x2 - x;             if (find(x, V[x2][k]) && find(x, V[x2][k] + tmp) &&                 find(x2, V[x2][k] + tmp))               res++;           }         }       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[1 << 18];   long long sum[1 << 18];   int p[1 << 18];   int n, T, m;   double c;   void Calc() {     double mean = 0.0;     for (int i = 0, j = 0; i < n && j < m; i++) {       mean = (mean + (a[i] + .0) / T) / c;       if (i == p[j] - 1) {         double real = (.0 + sum[i + 1] - sum[i - T + 1]) / T;         printf( %.9lf  , real);         printf( %.9lf  , mean);         printf( %.9lf n , fabs(real - mean) / real);         j++;       }     }   }   int main() {     scanf( %d%d%lf , &n, &T, &c);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum[i + 1] = sum[i] + a[i];     }     scanf( %d , &m);     for (int i = 0; i < m; i++) scanf( %d , &p[i]);     Calc();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, res = -1000000000;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (floor(sqrt(x)) != ceil(sqrt(x))) {         res = max(res, x);       }     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pay = 0, kd;     int U = 0, R = 0;     char c;     cin >> n;     cin >> c;     if (c ==  U ) {       kd = 1;       U++;     } else {       kd = 0;       R++;     }     for (int i = 1; i < n; i++) {       cin >> c;       if (c ==  U )         U++;       else if (c ==  R )         R++;       if (kd == 0 && R < U) {         pay++;         kd = 1;       } else if (kd && R > U) {         pay++;         kd = 0;       }     }     cout << pay;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20500;   int A[N];   int n;   int B[N];   int get(int k) {     if (n / k < 3) return -1e9;     for (int i = 0; i < k; i++) B[i] = 0;     for (int i = 0; i < n; i++) B[i % k] += A[i];     int ans = -1e9;     for (int i = 0; i < k; i++) ans = max(ans, B[i]);     return ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     int ans = -1e9;     for (int k = 1; k * k <= n; k++)       if (n % k == 0) ans = max(ans, max(get(k), get(n / k)));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a = 0, b = 0, c = 0;       string line;       cin >> line;       for (char d : line) {         if (d ==  B ) b++;         if (d ==  A ) a++;         if (d ==  C ) c++;       }       if (b == a + c) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1000000007;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int t;     t = 1;     while (t--) {       long long int n, m, k;       cin >> n >> m >> k;       vector<long long int> xs, ys;       for (long long int i = 0; i < n * m; i++) {         ys.push_back(i / n + 1);         if ((i / n) % 2 == 0) {           xs.push_back(i % n + 1);         } else {           xs.push_back(n - i % n);         }       }       for (long long int i = 0; i < k - 1; i++) {         cout << 2 <<     << xs[2 * i] <<     << ys[2 * i] <<     << xs[2 * i + 1]              <<     << ys[2 * i + 1] << endl;       }       cout << n * m - 2 * (k - 1) <<    ;       for (long long int i = 2 * (k - 1); i < n * m; i++) {         cout << xs[i] <<     << ys[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long solve(int N, const vector<int>& A) {     long long res = 0;     vector<int> freq(32);     for (int x : A) {       int hsb = (sizeof(int) * 8 - 1 - __builtin_clz((x)));       res += freq[hsb];       ++freq[hsb];     }     return res;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int TC;     cin >> TC;     for (int tc = (1), _b = (TC); tc <= _b; ++tc) {       int N;       cin >> N;       vector<int> A(N);       for (int i = 0, _n = (N); i < _n; ++i) cin >> A[i];       long long res = solve(N, A);       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T>& a) {     for (auto& e : a) {       cin >> e;     }   }   template <class T>   void print(vector<T>& a) {     for (auto& e : a) {       cout << e <<    ;     }     cout <<   n ;   }   void solve() {     long long n, h;     cin >> n >> h;     vector<long long> a(n);     read(a);     if (n == 1) {       cout << h <<   n ;       return;     }     vector<long long> b;     for (long long i = 1; i < n; ++i) {       b.push_back(a[i] - a[i - 1]);     }     long long l = 0, r = 1e18;     while (l + 1 != r) {       long long m = (l + r) / 2;       long long res = m;       for (long long i = 0; i < n - 1; ++i) {         res += min(m, b[i]);       }       if (res >= h) {         r = m;       } else {         l = m;       }     }     cout << r <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 505, M = 25005000, inf = 0x3f3f3f3f;   int n, m, num, dfn[N][N], dis[N];   bool mtr[2505][2505], v[2505];   char s[N][N];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int q[2505], head[2505], nxt[M], to[M], edgenum;   void addedge(int u, int v) {     to[++edgenum] = v;     nxt[edgenum] = head[u];     head[u] = edgenum;   }   inline void dfs(int x, int y) {     dfn[x][y] = num;     for (register int i = 0; i <= 3; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (nx >= 1 && nx <= n && ny >= 1 && ny <= m) {         if (s[nx][ny] == s[x][y] && !dfn[nx][ny]) dfs(nx, ny);         if (s[nx][ny] != s[x][y] && dfn[nx][ny])           mtr[num][dfn[nx][ny]] = mtr[dfn[nx][ny]][num] = 1;       }     }   }   inline int getdis(int s) {     memset(dis, inf, sizeof(dis));     int res = 0, f = 0, r = 1;     q[f] = s;     dis[s] = 0;     while (f != r) {       int u = q[f++];       res = max(res, dis[u]);       for (int i = head[u]; i != 0; i = nxt[i])         if (dis[to[i]] > dis[u] + 1) {           dis[to[i]] = dis[u] + 1;           q[r++] = to[i];         }     }     return res;   }   int main() {     read(n);     read(m);     for (register int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= m; j++)         if (!dfn[i][j]) {           ++num;           v[num] = s[i][j] ==  B ;           dfs(i, j);         }     for (register int i = 1; i <= num; i++)       for (register int j = 1; j <= num; j++)         if (mtr[i][j]) addedge(i, j);     int ans = 1e9;     for (register int i = 1; i <= num; i++) {       int d = getdis(i);       ans = min(ans, d + (((d + v[i]) & 1) ? 1 : 0));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);   int main()   {       fast;       int t;       cin >> t;       while (t--)       {           int n;           cin >> n;           vector<int> a(n + 1);           a[0] = 0;           for (int i = 1; i <= n; i++)               a[i] = i;           if (n % 2 == 0)           {               for (int i = 1; i < n; i += 2)                   swap(a[i], a[i + 1]);           }           else           {               for (int i = 1; i < n - 2; i+= 2)                   swap(a[i], a[i + 1]);               int temp = a[n];               a[n] = a[n - 1];               a[n - 1] = a[n - 2];               a[n - 2] = temp;           }           for (int i = 1; i <= n; i++)               cout << a[i] <<    ;           cout << endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3, Mod = 1e9 + 7;   const int maxN = 1e5 + 3;   void solve() {     long long n;     cin >> n;     long long ans = 6;     long long bin = 4;     for (int i = 1; i < n; i++) {       bin *= bin;       bin %= Mod;       ans *= bin;       ans %= Mod;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t = 1;     for (int i = 0; i < t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int x[102], pile[102];   int MN(int a, int b) { return (a < b) ? a : b; }   int main() {     int n, i, sz, j, flag;     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %d , &x[i]);       }       sort(x + 1, x + n + 1);       sz = 1;       pile[sz] = 1;       for (i = 2; i <= n; i++) {         flag = 0;         for (j = 1; j <= sz; j++) {           if (pile[j] <= x[i]) {             flag = 1;             pile[j]++;             break;           }         }         if (flag == 0) pile[++sz] = 1;       }       printf( %d n , sz);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int n;   int inDegree[MAXN];   long long A[MAXN], _A[MAXN], B[MAXN];   vector<int> adj[MAXN];   void build() {     for (int i = 0; i < n; i++) {       if (B[i] == -1) continue;       adj[i].push_back(B[i]);       inDegree[B[i]]++;     }   }   vector<int> solve() {     vector<int> pos, neg;     queue<int> q;     for (int i = 0; i < n; i++) {       if (inDegree[i] == 0) {         q.push(i);       }     }     while (!q.empty()) {       int i = q.front();       q.pop();       if (A[i] > 0) {         pos.push_back(i);         if (B[i] != -1) A[B[i]] += A[i];       } else {         neg.push_back(i);       }       for (auto v : adj[i]) {         inDegree[v]--;         if (inDegree[v] == 0) q.push(v);       }     }     reverse(neg.begin(), neg.end());     pos.insert(pos.end(), neg.begin(), neg.end());     return pos;   }   int main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       _A[i] = A[i];     }     for (int i = 0; i < n; i++) {       cin >> B[i];       if (B[i] != -1) B[i]--;     }     build();     long long ans = 0;     vector<int> v = solve();     for (auto i : v) {       ans += _A[i];       if (B[i] != -1) _A[B[i]] += _A[i];     }     cout << ans <<   n ;     for (auto i : v) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }