#include <bits/stdc++.h>   using namespace std;   char ans[10][10];   long long dp[10][513][513];   pair<pair<long long, long long>, long long> recur[10][513][513];   long long insert[10][513][513];   long long curr, nexty, n, m;   long long setBit(long long num, long long i) { return num | (1 << i); }   long long unsetBit(long long num, long long i) {     num ^= 1 << i;     return num;   }   bool checkBit(long long num, long long i) {     if (num & 1 << i)       return true;     else       return false;   }   string binary(long long num, long long m) {     string ans;     for (long long i = 0; i < m; i++) {       if (checkBit(num, i))         ans =  1  + ans;       else         ans =  0  + ans;     }     return ans;   }   void backtrack(long long j, long long mask1, long long mask2, long long mask3,                  long long newT, long long ogmask1, long long ogmask2,                  long long ts) {     if (j == m) {       if (dp[curr][ogmask1][ogmask2] + newT > dp[nexty][mask2][mask3]) {         dp[nexty][mask2][mask3] = dp[curr][ogmask1][ogmask2] + newT;         recur[nexty][mask2][mask3] = pair<pair<long long, long long>, long long>(             pair<long long, long long>(ogmask1, ogmask2), mask1);         insert[nexty][mask2][mask3] = ts;       }       return;     }     if (j > 1) {       if (!checkBit(mask1, j) && !checkBit(mask1, j - 1) &&           !checkBit(mask1, j - 2) && !checkBit(mask2, j - 1) &&           !checkBit(mask3, j - 1)) {         long long tempmask1 = setBit(mask1, j);         tempmask1 = setBit(tempmask1, j - 1);         tempmask1 = setBit(tempmask1, j - 2);         backtrack(j + 1, tempmask1, setBit(mask2, j - 1), setBit(mask3, j - 1),                   newT + 1, ogmask1, ogmask2, ts);       }     }     if (j > 1) {       if (!checkBit(mask1, j - 1) && !checkBit(mask2, j - 1) &&           !checkBit(mask3, j - 1) && !checkBit(mask3, j) &&           !checkBit(mask3, j - 2)) {         long long newmask = setBit(mask3, j - 1);         newmask = setBit(newmask, j);         newmask = setBit(newmask, j - 2);         backtrack(j + 1, setBit(mask1, j - 1), setBit(mask2, j - 1), newmask,                   newT + 1, ogmask1, ogmask2, setBit(ts, 2 * (j - 1) + 1));       }     }     if (j > 1) {       if (!checkBit(mask1, j - 2) && !checkBit(mask3, j - 2) &&           !checkBit(mask2, j) && !checkBit(mask2, j - 1) &&           !checkBit(mask2, j - 2)) {         long long newmask = setBit(mask2, j);         newmask = setBit(newmask, j - 1);         newmask = setBit(newmask, j - 2);         backtrack(j + 1, setBit(mask1, j - 2), newmask, setBit(mask3, j - 2),                   newT + 1, ogmask1, ogmask2, setBit(ts, 2 * (j - 2)));       }     }     if (j > 1) {       if (!checkBit(mask1, j) && !checkBit(mask3, j) && !checkBit(mask2, j) &&           !checkBit(mask2, j - 1) && !checkBit(mask2, j - 2)) {         long long newmask = setBit(mask2, j);         newmask = setBit(newmask, j - 1);         newmask = setBit(newmask, j - 2);         ts = setBit(ts, 2 * j);         ts = setBit(ts, 2 * j + 1);         backtrack(j + 1, setBit(mask1, j), newmask, setBit(mask3, j), newT + 1,                   ogmask1, ogmask2, ts);         ts = unsetBit(ts, 2 * j);         ts = unsetBit(ts, 2 * j + 1);       }     }     backtrack(j + 1, mask1, mask2, mask3, newT, ogmask1, ogmask2, ts);   }   char currchar =  A ;   void recursion(long long i, long long mask1, long long mask2) {     if (i == 0) return;     recursion(i - 1, recur[i][mask1][mask2].first.first,               recur[i][mask1][mask2].first.second);     long long mask = insert[i][mask1][mask2];     for (long long j = 0; j < m; j++) {       if (!checkBit(recur[i][mask1][mask2].second, j)) {         ans[i][j] =  . ;         continue;       }       if (checkBit(mask, j * 2) && checkBit(mask, j * 2 + 1)) {         ans[i][j] = ans[i + 1][j] = ans[i + 2][j] = ans[i + 1][j - 1] =             ans[i + 1][j - 2] = currchar;         currchar++;       } else if (checkBit(mask, j * 2) && !checkBit(mask, j * 2 + 1)) {         ans[i][j] = ans[i + 1][j + 2] = ans[i + 2][j] = ans[i + 1][j + 1] =             ans[i + 1][j] = currchar;         currchar++;       } else if (!checkBit(mask, j * 2) && checkBit(mask, j * 2 + 1)) {         ans[i][j] = ans[i + 1][j] = ans[i + 2][j + 1] = ans[i + 2][j - 1] =             ans[i + 2][j] = currchar;         currchar++;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     memset(dp, -1, sizeof(dp));     memset(ans, 0, sizeof(ans));     dp[0][0][0] = 0;     for (long long i = 0; i < n; i++) {       curr = i;       nexty = i + 1;       for (long long mask1 = 0; mask1 < (1 << m); mask1++) {         for (long long mask2 = 0; mask2 < (1 << m); mask2++) {           if (dp[curr][mask1][mask2] != -1) {             backtrack(0, mask1, mask2, 0, 0, mask1, mask2, 0);           }         }       }     }     cout << dp[n][0][0] <<   n ;     recursion(n, 0, 0);     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j < m; j++) {         if (ans[i][j] == 0 && ans[i][j - 1] == 0 && ans[i][j + 1] == 0 &&             ans[i + 1][j] == 0 && ans[i + 2][j] == 0) {           ans[i][j] = ans[i][j - 1] = ans[i][j + 1] = ans[i + 1][j] =               ans[i + 2][j] = currchar;           currchar++;         }       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j < m; j++) cout << ans[i][j];       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     for (int i = 0; i < 2 * n + 1; i++) {       for (int j = 0; j < 2 * n + 1; j++) {         if (i < n + 1) {           if (j < n - i) {             printf(    );           } else if (j < n + i) {             if (j <= n) {               printf( %d  , j - n + i);             } else {               printf( %d  , abs(j - n - i));             }           } else if (j == n + i) {             printf( 0 );           }         } else {           int temp = i;           i = 2 * n - i;           if (j < n - i) {             printf(    );           } else if (j < n + i) {             if (j <= n) {               printf( %d  , j - n + i);             } else {               printf( %d  , abs(j - n - i));             }           } else if (j == n + i) {             printf( 0 );           }           i = temp;         }       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   inline void chmin(T &t, U f) {     if (t > f) t = f;   }   template <class T, class U>   inline void chmax(T &t, U f) {     if (t < f) t = f;   }   long long N;   char S[11111];   long long ex[27 * 26 * 26];   long long dp[11111][2];   long long get(long long l, long long r) {     if (r > N) return -1;     long long x = 0;     for (long long i = l; i < r; i++) {       x = x * 26 + (S[i] -  a );     }     if (r - l == 2) x += 26 * 26 * 26;     return x;   }   signed main() {     scanf( %s , S);     N = strlen(S);     if (N <= 6) {       puts( 0 );       return 0;     }     if (N == 7) {       puts( 1 );       printf( %s , S + 5);       return 0;     }     ex[get(N - 2, N)] = true;     ex[get(N - 3, N)] = true;     dp[N - 2][0] = true;     dp[N - 3][1] = true;     for (long long i = N - 4; i >= 5; i--) {       long long t2 = get(i, i + 2);       long long t3 = get(i, i + 3);       if (t2 == get(i + 2, i + 4))         dp[i][0] = dp[i + 2][1];       else         dp[i][0] = dp[i + 2][0] | dp[i + 2][1];       if (t3 == get(i + 3, i + 6))         dp[i][1] = dp[i + 3][0];       else         dp[i][1] = dp[i + 3][0] | dp[i + 3][1];       if (dp[i][0]) ex[t2] = true;       if (dp[i][1]) ex[t3] = true;     }     vector<string> vec;     for (long long i = 0; i < (26); i++)       for (long long j = 0; j < (26); j++)         if (ex[26 * 26 * 26 + i * 26 + j])           vec.push_back(string(1,  a  + i) + string(1,  a  + j));     for (long long i = 0; i < (26); i++)       for (long long j = 0; j < (26); j++)         for (long long k = 0; k < (26); k++)           if (ex[i * 26 * 26 + j * 26 + k])             vec.push_back(string(1,  a  + i) + string(1,  a  + j) +                           string(1,  a  + k));     sort((vec).begin(), (vec).end());     printf( %lld n , (long long)vec.size());     for (long long i = 0; i < (vec.size()); i++) printf( %s n , vec[i].c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   int main() {     map<int, int>::iterator ptr;     int n, i, x, a[3];     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       m[x]++;     }     if (m.size() > 3) {       cout <<  NO ;       return 0;     }     if (m.size() <= 2) {       cout <<  YES ;       return 0;     }     i = 0;     for (ptr = m.begin(); ptr != m.end(); ptr++) a[i++] = ptr->first;     if ((a[0] + a[2]) == (2 * a[1]))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int n;   int mt[256][256];   int xy[256], yx[256];   int lx[256], ly[256], slk[256], slkx[256], prv[256];   char S[256], T[256];   void updtree(int x) {     for (int y = 0; y < (int)(n); y++)       if (lx[x] + ly[y] - mt[x][y] < slk[y]) {         slk[y] = lx[x] + ly[y] - mt[x][y];         slkx[y] = x;       }   }   int hungar() {     for (int i = 0; i < (int)(n); i++) {       ly[i] = 0;       lx[i] = *max_element(mt[i], mt[i] + n);     }     memset(xy, -1, sizeof(xy));     memset(yx, -1, sizeof(yx));     for (int m = 0; m < (int)(n); m++) {       memset(S, 0, sizeof(S));       memset(T, 0, sizeof(T));       memset(prv, -1, sizeof(prv));       memset(slk, 0x7f, sizeof(slk));       queue<int> q;       for (int i = 0; i < (int)(n); i++)         if (xy[i] == -1) {           {             q.push(i);             prv[i] = -2;             S[i] = 1;             updtree(i);           };           break;         }       int x = 0, y = -1;       while (y == -1) {         while (!q.empty() && y == -1) {           x = q.front();           q.pop();           for (int j = 0; j < (int)(n); j++)             if (mt[x][j] == lx[x] + ly[j] && !T[j]) {               if (yx[j] == -1) {                 y = j;                 break;               }               T[j] = 1;               {                 q.push(yx[j]);                 prv[yx[j]] = x;                 S[yx[j]] = 1;                 updtree(yx[j]);               };             }         }         if (y != -1) break;         int dlt = 0x7f7f7f7f;         for (int j = 0; j < (int)(n); j++)           if (!T[j]) dlt = min(dlt, slk[j]);         for (int k = 0; k < (int)(n); k++) {           if (S[k]) lx[k] -= dlt;           if (T[k]) ly[k] += dlt;           if (!T[k]) slk[k] -= dlt;         }         for (int j = 0; j < (int)(n); j++)           if (!T[j] && !slk[j]) {             if (yx[j] == -1) {               x = slkx[j];               y = j;               break;             } else {               T[j] = 1;               if (!S[yx[j]]) {                 q.push(yx[j]);                 prv[yx[j]] = slkx[j];                 S[yx[j]] = 1;                 updtree(yx[j]);               };             }           }       }       if (y != -1) {         for (int p = x; p != -2; p = prv[p]) {           yx[y] = p;           int ty = xy[p];           xy[p] = y;           y = ty;         }       } else         break;     }     int res = 0;     for (int i = 0; i < (int)(n); i++) res += mt[i][xy[i]];     return res;   }   string s, t;   int f(char c) {     if ( A  <= c && c <=  Z )       return (int)(c -  A  + 26);     else       return (int)(c -  a );   }   char invf(int i) {     if (i < 26)       return (char)(i +  a );     else       return (char)(i - 26 +  A );   }   int main() {     int N;     cin >> N >> n;     cin >> s >> t;     memset(mt, 0, sizeof(mt));     for (int i = 0; i < (int)(N); i++) {       mt[f(s[i])][f(t[i])]++;     }     cout << hungar() << endl;     for (int i = 0; i < (int)(n); i++) {       cout << invf(xy[i]);     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 300;   int n, m;   struct cell {     int mask = 0;     bool operator[](int i) { return mask & (1 << i); }   };   cell arr[MAX][MAX];   vector<pair<int, int> > adj[MAX][MAX];   int inDegree[MAX][MAX], _Time, visTime[MAX][MAX], lowTime[MAX][MAX],       compIdx[MAX][MAX];   bool inStack[MAX][MAX];   void SCC(int x, int y, stack<pair<int, int> >& s) {     visTime[x][y] = lowTime[x][y] = ++_Time;     s.push({x, y});     inStack[x][y] = 1;     for (auto v : adj[x][y])       if (!visTime[v.first][v.second]) {         SCC(v.first, v.second, s);         lowTime[x][y] = min(lowTime[x][y], lowTime[v.first][v.second]);       } else if (inStack[x][y])         lowTime[x][y] = min(lowTime[x][y], lowTime[v.first][v.second]);     if (visTime[x][y] == lowTime[x][y]) {       vector<pair<int, int> > temp;       int cnt = 0;       int v, u;       compIdx[x][y] = lowTime[x][y];       do {         cnt++;         v = s.top().first, u = s.top().second;         s.pop();         inStack[v][u] = 0;         compIdx[v][u] = compIdx[x][y];         arr[x][y].mask |= arr[v][u].mask;         vector<pair<int, int> >& to = adj[v][u];         for (int i = 0; i < int(to.size()); i++)           if (!inStack[to[i].first][to[i].second] &&               compIdx[to[i].first][to[i].second] != compIdx[x][y])             temp.push_back(to[i]);       } while (v != x || u != y);       if (cnt > 1) inDegree[x][y] = 0;       adj[x][y] = temp;     }   }   void getDAG() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (!visTime[i][j]) {           stack<pair<int, int> > s;           SCC(i, j, s);         }   }   bool getPath(int x, int y, int idx, string& str) {     if (idx + arr[x][y][str[idx] -  0 ] == int(str.size())) return 1;     vector<pair<int, int> >& to = adj[x][y];     for (int i = 0; i < int(to.size()); i++)       if (getPath(to[i].first, to[i].second, idx + arr[x][y][str[idx] -  0 ],                   str))         return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> n >> m >> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         char ch;         cin >> ch;         arr[i][j].mask |= 1 << (ch -  0 );       }     for (int k = 0; k < 10; k++) {       int x, y;       cin >> x >> y;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (arr[i][j][k] && i + x >= 0 && i + x < n && j + y >= 0 && j + y < m)             adj[i + x][j + y].push_back({i, j}), inDegree[i][j]++;     }     getDAG();     while (q--) {       string str;       cin >> str;       reverse(str.begin(), str.end());       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (!inDegree[i][j]) {             int idx = 0;             while (arr[i][j][str[idx] -  0 ]) idx++;             if (getPath(i, j, idx, str)) {               cout <<  YES n ;               goto ESHTA;             }           }       cout <<  NO n ;     ESHTA:;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T a) {     return a < 0 ? -a : a;   }   template <typename T>   T sqr(T a) {     return a * a;   }   const int INF = (int)1e9;   const long double EPS = 1e-9;   const long double PI = 3.1415926535897932384626433832795;   const int N = 4;   struct pt {     int first, second;     pt() { first = second = 0; }     pt(int cX, int cY) : first(cX), second(cY) {}   };   int n, m;   int used[N * N];   pt a[N * N];   int s;   int sum[3 * N];   int szst[N][N];   int st[N][N][3 * N];   int szfn[N][N];   int fn[N][N][3 * N];   int mn[N][N];   inline void put(int i, int j, int v) {     mn[i][j] = v;     for (int k = 0; k < int(szst[i][j]); ++k) sum[st[i][j][k]] += v;   }   inline void take(int i, int j) {     for (int k = 0; k < int(szst[i][j]); ++k) sum[st[i][j][k]] -= mn[i][j];   }   void solve(int x, int y) {     if (y == n) {       x++;       y = 0;     }     if (x == n) {       printf( %d n , s);       for (int i = 0; i < int(n); ++i) {         for (int j = 0; j < int(n); ++j) {           printf( %d , mn[i][j]);           if (j + 1 != n) printf(   );         }         puts(  );       }       exit(0);     }     for (int i = 0; i < int(m); ++i) {       if (used[i] < a[i].second) {         put(x, y, a[i].first);         used[i]++;         bool good = true;         for (int j = 0; j < int(szfn[x][y]); ++j)           if (sum[fn[x][y][j]] != s) {             good = false;             break;           }         if (good) solve(x, y + 1);         used[i]--;         take(x, y);       }     }   }   void pickRow(int idx) {     if (idx == n) {       s = sum[0];       solve(1, 0);       s = INF;       return;     }     for (int i = 0; i < int(m); ++i)       if (used[i] < a[i].second) {         used[i]++;         put(0, idx, a[i].first);         pickRow(idx + 1);         used[i]--;         take(0, idx);       }   }   int main() {     cin >> n;     vector<int> c;     c.resize(n * n);     for (int i = 0; i < int(n * n); ++i) {       scanf( %d , &c[i]);     }     sort((c).begin(), (c).end());     m = 0;     int cnt = 1;     for (int i = 1; i < n * n; ++i) {       if (c[i] != c[i - 1]) {         a[m++] = pt(c[i - 1], cnt);         cnt = 1;       } else         cnt++;     }     a[m++] = pt(c[n * n - 1], cnt);     for (int i = 0; i < int(n); ++i)       for (int j = 0; j < int(n); ++j) {         st[i][j][szst[i][j]++] = i;         st[i][j][szst[i][j]++] = n + j;         if (i == j) st[i][j][szst[i][j]++] = 2 * n;         if (i == n - j - 1) st[i][j][szst[i][j]++] = 2 * n + 1;         if (j == n - 1) fn[i][j][szfn[i][j]++] = i;         if (i == n - 1) fn[i][j][szfn[i][j]++] = n + j;         if (i == n - 1 && j == n - 1) fn[i][j][szfn[i][j]++] = 2 * n;         if (i == n - 1 && j == 0) fn[i][j][szfn[i][j]++] = 2 * n + 1;       }     random_shuffle(a, a + m);     s = INF;     pickRow(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p) {     if (p == 0) return 1;     long long my = bigmod(b, p / 2);     my *= my;     my %= 1000000009;     if (p & 1) my *= b, my %= 1000000009;     return my;   }   int setb(int n, int pos) { return n = n | (1 << pos); }   int resb(int n, int pos) { return n = n & ~(1 << pos); }   bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }   double p[100];   int n, k;   double pr[(1 << 20) + 5][21];   double prob(int mask, int pos) {     double tot = 0.0;     int i;     for (i = 0; i < n; i++) {       if (checkb(mask, i) == 0) tot += p[i];     }     return p[pos] / tot;   }   void prework() {     for (int mask = 0; mask < (1 << n); mask++) {       for (int i = 0; i < n; i++) {         if (checkb(mask, i) == 0) {           pr[mask][i] = prob(mask, i);         }       }     }   }   double dp[(1 << 20) + 5];   double motherfuckerareyoukiddingme(int x) {     for (int mask = (1 << n) - 1; mask >= 0; mask--) {       int bt = __builtin_popcount(mask);       if (bt >= k) {         if (bt == k && checkb(mask, x))           dp[mask] = 1.0;         else           dp[mask] = 0.0;       } else {         double ret = 0.0;         for (int i = 0; i < n; i++) {           if (checkb(mask, i) == 0) {             ret += pr[mask][i] * dp[setb(mask, i)];           }         }         dp[mask] = ret;       }     }     return dp[0];   }   int main() {     int i, d = 0;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %lf , &p[i]);     for (i = 0; i < n; i++)       if (p[i] > 0.0) d++;     k = min(d, k);     prework();     for (i = 0; i < n; i++) {       if (i) printf(   );       printf( %.10f , motherfuckerareyoukiddingme(i));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, q = 0;     cin >> n >> m;     int k = n * m;     char a[k];     for (int j = 0; j < k; j++) {       cin >> a[k];       if (a[k] ==  M  || a[k] ==  Y  || a[k] ==  C ) {         q = 1;       }     }     if (q == 1) {       cout <<  #Color  << endl;     } else {       cout <<  #Black&White  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500000;   int n, m;   vector<int> nei[N + 1];   bool vis[N + 1];   int fa[N + 1], dep[N + 1];   void dfs(int x = 1) {     vis[x] = true;     for (int i = 0; i < nei[x].size(); i++) {       int y = nei[x][i];       if (vis[y]) continue;       fa[y] = x;       dep[y] = dep[x] + 1;       dfs(y);     }   }   vector<int> buc[N + 1];   void mian() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       nei[i].clear(), buc[i].clear(), vis[i] = fa[i] = dep[i] = 0;     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       nei[x].push_back(y);       nei[y].push_back(x);     }     dep[1] = 1;     dfs();     for (int i = 1; i <= n; i++)       if (dep[i] >= n + 1 >> 1) {         puts( PATH );         printf( %d n , dep[i]);         while (i) printf( %d  , i), i = fa[i];         puts(  );         return;       } else         buc[dep[i]].push_back(i);     puts( PAIRING );     int cnt = 0;     for (int i = 1; i <= n; i++) cnt += buc[i].size() >> 1;     printf( %d n , cnt);     for (int i = 1; i <= n; i++) {       for (int j = 0; j + 1 < buc[i].size(); j += 2)         printf( %d %d n , buc[i][j], buc[i][j + 1]);     }   }   int main() {     int testnum;     cin >> testnum;     while (testnum--) mian();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int in[100005];   int in2[100005];   int remlocate[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> in[i];     }     for (int i = 0; i < n; ++i) {       cin >> in2[i];       remlocate[in2[i]] = i;     }     int go1 = n - 1;     int go2 = n - 1;     int cnt = 0;     for (int i = 0; i < n; ++i) {       while (in2[go2] == 0) {         go2--;       }       if (in[go1] != in2[go2]) {         cnt++;         in2[remlocate[in[go1]]] = 0;         go1--;       } else {         go1--;         go2--;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int MAXN = 1000005;   int dp[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int x;     int maxn = 0;     for (int i = 0; i < n; i++) {       cin >> x;       dp[x]++;       maxn = max(maxn, dp[x]);       for (int j = x * 2; j < MAXN; j += x) {         dp[j] = max(dp[j], dp[x]);       }     }     cout << maxn << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   using ll = long long;   using ld = long double;   const ll MOD = 1000000007;   const ll root = 62;   ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   ll binpow(ll a, ll b) {     ll res = 1;     while (b) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return res;   }   ll modInv(ll a) { return binpow(a, MOD - 2); }   const double PI = acos(-1);   const double eps = 1e-10;   const int INF = 0x3f3f3f3f;   const int NINF = 0xc0c0c0c0;   const ll INFLL = 0x3f3f3f3f3f3f3f3f;   const ll NINFLL = 0xc0c0c0c0c0c0c0c0;   struct Dinic {     struct Edge {       int to, rev;       ll flo, cap;     };     int N;     vector<vector<Edge>> adj;     void init(int _N) {       N = _N;       adj.resize(N);     }     void add(int a, int b, ll cap, ll rcap = 0) {       adj[a].push_back({b, (int)adj[b].size(), 0, cap});       adj[b].push_back({a, (int)adj[a].size() - 1, 0, rcap});     }     vector<int> lev, ptr;     bool bfs(int s, int t) {       lev = ptr = vector<int>(N);       queue<int> Q({s});       lev[s] = 1;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         for (auto e : adj[u]) {           if (!lev[e.to] && e.cap - e.flo) Q.push(e.to), lev[e.to] = lev[u] + 1;         }       }       return lev[t];     }     ll dfs(int v, int t, ll flo) {       if (v == t) return flo;       for (int& i = ptr[v]; i < (adj[v].size()); i++) {         Edge& e = adj[v][i];         ll dif = e.cap - e.flo;         if (lev[e.to] != lev[v] + 1 || !dif) continue;         if (ll df = dfs(e.to, t, min(flo, dif))) {           e.flo += df;           adj[e.to][e.rev].flo -= df;           return df;         }       }       return 0;     }     ll Flow(int s, int t) {       ll tot = 0;       while (bfs(s, t))         while (ll df = dfs(s, t, numeric_limits<ll>::max())) tot += df;       return tot;     }   };   vector<vector<int>> arr;   vector<vector<char>> res;   vector<vector<int>> ans;   int n, m;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   bool inside(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   pair<int, int> pos(int a) { return {a / m, a % m}; }   char getdir(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first && a.second == b.second - 1) {       return  R ;     } else if (a.first == b.first && a.second == b.second + 1) {       return  L ;     } else if (a.first == b.first - 1 && a.second == b.second) {       return  D ;     } else if (a.first == b.first + 1 && a.second == b.second) {       return  U ;     } else {       cout <<  GFYAHFGAIJOTGIOWGEOG n ;     }     return  ? ;   }   void solve() {     cin >> n >> m;     Dinic G;     G.init(n * m + 4);     arr.resize(n);     res.resize(n);     ans.resize(n);     for (auto i = (0); i < (n); ++i) {       arr[i].resize(m);       res[i].resize(m);       ans[i].resize(m);     }     for (auto i = (0); i < (n); ++i) {       for (auto j = (0); j < (m); ++j) {         cin >> arr[i][j];         ans[i][j] = -1;       }     }     G.add(n * m + 1, n * m, INF);     int req = 0;     for (auto i = (0); i < (n); ++i) {       for (auto j = (0); j < (m); ++j) {         bool go = false;         for (auto d = (0); d < (4); ++d) {           if (inside(i + dx[d], j + dy[d])) {             go |= (arr[i + dx[d]][j + dy[d]] < arr[i][j]);             if (arr[i + dx[d]][j + dy[d]] == arr[i][j] && ((i + j) & 1) == 0) {               G.add(i * m + j, (i + dx[d]) * m + j + dy[d], 1);             }           }         }         if (((i + j) & 1) == 0) {           if (go) {             G.add(n * m, i * m + j, 1);           } else {             G.add(n * m + 2, i * m + j, 1);             G.add(n * m, n * m + 3, 1);             req++;           }         } else {           if (go) {             G.add(i * m + j, n * m + 1, 1);           } else {             G.add(i * m + j, n * m + 3, 1);             G.add(n * m + 2, n * m + 1, 1);             req++;           }         }       }     }     if (G.Flow(n * m + 2, n * m + 3) != req) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     for (auto i = (0); i < (n * m); ++i) {       for (auto e : G.adj[i]) {         if (e.flo > 0 && e.to < n * m) {           auto [x, y] = pos(i);           auto [dx, dy] = pos(e.to);           res[x][y] = getdir({x, y}, {dx, dy});           res[dx][dy] = getdir({dx, dy}, {x, y});           ans[x][y] = 1;           ans[dx][dy] = arr[x][y] - 1;         }       }     }     for (auto i = (0); i < (n); ++i) {       for (auto j = (0); j < (m); ++j) {         if (ans[i][j] != -1) continue;         for (auto d = (0); d < (4); ++d) {           if (inside(i + dx[d], j + dy[d])) {             if (arr[i + dx[d]][j + dy[d]] < arr[i][j]) {               res[i][j] = getdir({i, j}, {i + dx[d], j + dy[d]});               ans[i][j] = arr[i][j] - arr[i + dx[d]][j + dy[d]];             }           }         }       }     }     for (auto i = (0); i < (n); ++i) {       for (auto j = (0); j < (m); ++j) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     for (auto i = (0); i < (n); ++i) {       for (auto j = (0); j < (m); ++j) {         cout << res[i][j] <<    ;       }       cout <<   n ;     }     return;   }   int T;   int main() {     mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());     cin.tie(0)->sync_with_stdio(0);     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long b[100005];   long long x;   long long n, m;   long long c[100005];   long long d[100005];   void solve() {     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i) a[i] += a[i - 1];       c[i + 1] = 1e9;     }     for (long long i = 0; i < m; i++) {       cin >> b[i];       if (i) b[i] += b[i - 1];       d[i + 1] = 1e10;     }     cin >> x;     long long fans = 0;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         long long l = j - i + 1;         if (i)           c[l] = min(c[l], a[j] - a[i - 1]);         else           c[l] = min(c[l], a[j]);       }     }     for (long long i = 0; i < m; i++) {       for (long long j = i; j < m; j++) {         long long l = j - i + 1;         if (i)           d[l] = min(d[l], b[j] - b[i - 1]);         else           d[l] = min(d[l], b[j]);       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         if (c[i] * d[j] <= x) {           fans = max(fans, i * j);         }       }     }     cout << fans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long T;     T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   vector<int> g[N], used, g1[N];   int gl[N];   bool ok = 1;   void dfs(int v, int glb) {     used[v] = 1;     gl[v] = glb;     for (int to : g[v])       if (!used[to]) dfs(to, glb + 1);   }   void dfs1(int v, int root) {     used[v] = 1;     for (int to : g1[v])       if (to == root)         ok = 0;       else if (!used[to])         dfs1(to, root);   }   int32_t main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     map<pair<int, int>, int> q;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       q[make_pair(a, b)] = i;       g[a].push_back(b);       g[b].push_back(a);       g1[a].push_back(b);     }     for (int i = 0; i < n; ++i) {       used.assign(n, 0);       dfs1(i, i);     }     used.assign(n, 0);     for (int i = 0; i < n; ++i)       if (!used[i]) dfs(i, 0);     if (ok) {       cout <<  1 n ;       for (int i = 0; i < m; ++i) cout <<  1  ;       return 0;     }     vector<int> res(m);     for (auto x : q) {       int a = x.first.first;       int b = x.first.second;       if (gl[a] > gl[b])         res[x.second] = 1;       else         res[x.second] = 2;     }     cout <<  2 n ;     for (int i = 0; i < m; ++i) cout << res[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y;   bool f[1000010];   vector<int> v, b[1000010];   int ans = 0, res = 0;   int main(int argc, char **argv) {     scanf( %d , &n);     if (n == 1) {       puts( 1 );       return 0;     }     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       b[x].push_back(i);       if (!f[x]) {         f[x] = 1;         v.push_back(x);       }     }     for (int i = 0; i < (int)v.size(); ++i) {       for (int j = i; j < (int)v.size(); ++j) {         x = v[i];         y = v[j];         if (i == j) {           res = max(res, (int)b[x].size());           continue;         }         bool ok = 0;         int idx = -1;         ans = 0;         if (b[x][0] < b[y][0]) {           while (idx <= (int)b[x].back() || idx <= (int)b[y].back()) {             if (ok == 0) {               if (idx == -1) {                 ++ans;                 idx = b[x][0];               } else {                 int ii =                     lower_bound(b[x].begin(), b[x].end(), idx) - b[x].begin();                 if (ii < (int)b[x].size()) {                   ++ans;                   idx = b[x][ii];                 } else                   idx = 1e9;               }             } else {               if (idx == -1) {                 ++ans;                 idx = b[y][0];               } else {                 int ii =                     lower_bound(b[y].begin(), b[y].end(), idx) - b[y].begin();                 if (ii < (int)b[y].size()) {                   ++ans;                   idx = b[y][ii];                 } else                   idx = 1e9;               }             }             ok ^= 1;           }         } else {           swap(x, y);           while (idx <= (int)b[x].back() || idx <= (int)b[y].back()) {             if (ok == 0) {               if (idx == -1) {                 ++ans;                 idx = b[x][0];               } else {                 int ii =                     lower_bound(b[x].begin(), b[x].end(), idx) - b[x].begin();                 if (ii < (int)b[x].size()) {                   ++ans;                   idx = b[x][ii];                 } else                   idx = 1e9;               }             } else {               if (idx == -1) {                 ++ans;                 idx = b[y][0];               } else {                 int ii =                     lower_bound(b[y].begin(), b[y].end(), idx) - b[y].begin();                 if (ii < (int)b[y].size()) {                   ++ans;                   idx = b[y][ii];                 } else                   idx = 1e9;               }             }             ok ^= 1;           }         }         res = max(res, ans);       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   pair<long long, long long> d[1000009];   long long f[1000009];   deque<pair<long long, long long> > dq;   long long dsum = 0;   int main() {     long long l, m;     scanf( %I64d %I64d , &l, &m);     int(n);     scanf( %d , &n);     d[0].first = 0;     d[0].second = 999999999;     for (int i = (1); i < (n + 1); ++i) {       scanf( %I64d %I64d , &d[i].first, &d[i].second);     }     sort(d, d + n + 1);     d[n + 1].first = l;     d[n + 1].second = 0;     n += 2;     long long ans = 0;     f[0] = m;     for (int i = (1); i < (n); ++i) {       f[i] = f[i - 1] - (d[i].first - d[i - 1].first);       while (f[i] < 0) {         if (((int)(dq).size()) == 0) {           ans = -1;           break;         }         long long buy = min(-f[i], dq[0].second);         dq[0].second -= buy;         ans += buy * dq[0].first;         dsum -= buy;         f[i] += buy;         if (dq[0].second == 0) dq.pop_front();       }       while (((int)(dq).size())) {         if (dq.back().first > d[i].second) {           dsum -= dq.back().second;           dq.pop_back();         } else           break;       }       if ((m - f[i] - dsum) > 0) {         dq.push_back(make_pair(d[i].second, m - f[i] - dsum));         dsum += m - f[i] - dsum;       }       if (ans == -1) break;     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   bool judge(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   int main() {     int n;     scanf( %d , &n);     if (judge(n)) {       printf( 1 n );       return 0;     }     if (n % 2) {       if (judge(n - 2)) {         printf( 2 n );       } else {         printf( 3 n );       }       return 0;     } else {       printf( 2 n );       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[424242];   int main() {     long long n;     cin >> n;     int ans = 0;     if (n % 3 == 0) {       n /= 3;       int kp = 0;       for (int d = 1; d <= 50000; d++)         if ((4 * n) % d == 0) p[kp++] = d;       for (int a = 1; 8LL * a * a * a <= n; a++)         for (int id = 0; id < kp; id++) {           int b = p[id] - a;           if (b < a) continue;           if (2LL * b * (a + b) * (a + b) > n) continue;           long long d = (long long)(a + b) * (a + b) * (a - b) * (a - b) +                         4LL * (a + b) * n;           long long dd = sqrt(1.0 * d);           while (dd * dd < d) dd++;           while (dd * dd > d) dd--;           if (dd * dd == d) {             long long c = -a - b + dd / (a + b);             if (c < 2 * b || (c & 1)) continue;             c >>= 1;             if (a < b && b < c)               ans += 6;             else if (a == b && b == c)               ans += 1;             else               ans += 3;           }         }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int M = 11;   const int MOD = 1e9 + 7;   int n, m;   int dp[M][N][N];   int solve(int idx, int a, int b) {     if (idx >= m) return 1;     int& r = dp[idx][a][b];     if (r != -1) return r;     r = solve(idx + 1, a, b);     if (a < b) {       r = (r + solve(idx, a + 1, b)) % MOD;       r = (r + solve(idx, a, b - 1)) % MOD;     }     if (a + 1 < b) r = ((r - solve(idx, a + 1, b - 1)) % MOD + MOD) % MOD;     return r;   }   int main() {     cin >> n >> m;     memset(dp, -1, sizeof dp);     cout << solve(0, 1, n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846264338;   const long long INF = 1000000000000000000;   const long long INF1 = 1000000000;   const long long MOD = 1000000007;   long long mpow(long long a, long long b) {     a %= MOD;     if (!b) return 1;     long long temp = mpow(a, b / 2);     temp = (temp * temp) % MOD;     if (b % 2) return (a * temp) % MOD;     return temp;   }   long long _pow(long long a, long long b) {     if (!b) return 1;     long long temp = _pow(a, b / 2);     temp = (temp * temp);     if (b % 2) return (a * temp);     return temp;   }   long long mod_in(long long n) { return mpow(n, MOD - 2); }   long long cl(long long a, long long b) {     if (a % b) return 1 + a / b;     return a / b;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     T = 1;     while (T--) {       long long n, k;       cin >> n >> k;       set<long long> s1, s2;       cout <<  ?  ;       for (int i = 1; i <= k; i++) cout << i <<    ;       cout <<   n ;       cout.flush();       long long pos, apos;       cin >> pos >> apos;       s1.insert(k + 1);       for (int i = 1; i <= k; i++) {         if (pos == i) continue;         cout <<  ?  ;         for (int j = 1; j <= k + 1; j++) {           if (i == j) continue;           cout << j <<    ;         }         cout <<   n ;         cout.flush();         long long x, y;         cin >> x >> y;         if (y == apos)           s1.insert(i);         else           s2.insert(i);       }       cout <<  ?  ;       for (long long x : s1) cout << x <<    ;       for (long long y : s2) cout << y <<    ;       cout <<   n ;       cout.flush();       long long u, v;       cin >> u >> v;       long long p1 = -1, p2 = -1, c[2] = {};       if (s1.count(u)) {         if (v > apos) {           p1 = 1;           p2 = 0;         } else {           p1 = 0;           p2 = 1;         }       } else {         if (v > apos) {           p1 = 0;           p2 = 1;         } else {           p1 = 1;           p2 = 0;         }       }       for (int i = 1; i <= k; i++) {         if (i == pos) continue;         if (s1.count(i))           c[p1]++;         else           c[p2]++;       }       cout <<  !   << c[0] + 1 <<   n ;       cout.flush();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   const int inf = 0x3f3f3f3f;   int to[N * 2], nxt[N * 2], pre[N * 2], cnt, n, tot[N], dp[N][N][2];   void makeedge(int x, int y) {     to[cnt] = x;     nxt[cnt] = pre[y];     pre[y] = cnt++;     to[cnt] = y;     nxt[cnt] = pre[x];     pre[x] = cnt++;   }   int dfs(int x, int fa) {     int son = 0;     if (tot[x] == 1) {       son = 1;       dp[x][0][1] = 0;       dp[x][1][0] = 0;     } else {       dp[x][0][1] = 0;       dp[x][0][0] = 0;     }     for (int p = pre[x]; p != -1; p = nxt[p]) {       int y = to[p];       if (y == fa) continue;       int tmp = dfs(y, x);       for (int j = son; j >= 0; j--) {         for (int k = tmp; k >= 1; k--) {           dp[x][j + k][0] =               min(dp[x][j + k][0],                   min(dp[x][j][0] + dp[y][k][1] + 1, dp[x][j][0] + dp[y][k][0]));           dp[x][j + k][1] =               min(dp[x][j + k][1],                   min(dp[x][j][1] + dp[y][k][0] + 1, dp[x][j][1] + dp[y][k][1]));         }         dp[x][j][0] = min(inf, dp[x][j][0] + min(dp[y][0][1] + 1, dp[y][0][0]));         dp[x][j][1] = min(inf, dp[x][j][1] + min(dp[y][0][0] + 1, dp[y][0][1]));       }       son += tmp;     }     return son;   }   int main() {     scanf( %d , &n);     memset(pre, -1, sizeof(pre));     memset(dp, inf, sizeof(dp));     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       tot[x]++;       tot[y]++;       makeedge(x, y);     }     if (n == 2) {       printf( 1 n );       return 0;     }     int son = 0, S;     for (int i = 1; i <= n; i++) {       if (tot[i] != 1)         S = i;       else         son++;     }     dfs(S, 0);     printf( %d n , min(dp[S][son / 2][0], dp[S][son / 2][1]));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, s, q, nr = 0;     scanf( %d%d%d , &t, &s, &q);     while (s < t) {       nr++;       s += s * (q - 1);     }     printf( %d , nr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[105];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, x, y, t, l, m, k = 0, r = 0, a, b, c, d, p = 0, q = 0, s, i,                                     j, ans = 0, ans1 = 0;     string s1;     char ch;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       q = a + b;       p = a - b;       s = c + d;       r = c - d;       x = p * n;       y = q * n;       if (x > s || y < r)         cout <<  No               <<   n ;       else         cout <<  Yes               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sci[200005], bn[200005];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int m, ple = 0, sat = 0, fi = 1, cn;       map<int, int> mp;       for (int i = 0; i < n; i++) {         scanf( %d , &sci[i]);         mp[sci[i]]++;       }       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         scanf( %d , &bn[i]);       }       for (int i = 1; i <= m; i++) {         scanf( %d , &cn);         if (mp[bn[i]] > ple) {           ple = mp[bn[i]];           sat = mp[cn];           fi = i;         } else if (mp[bn[i]] == ple && mp[cn] > sat) {           sat = mp[cn];           fi = i;         }       }       printf( %d n , fi);     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e5 + 5;   int n;   int a[M];   int q, ans[M];   vector<pair<int, int> > ps[M];   int pas[M], las[M], llas[M], mfr[M];   struct SEGMENT1 {     int val[M * 4];     void update(int L, int R, int p, int l, int r, int v) {       if (L == l && R == r) {         val[p] += v;         return;       }       int mid = (L + R) >> 1;       if (mid >= r)         update(L, mid, p << 1, l, r, v);       else if (mid < l)         update(mid + 1, R, p << 1 | 1, l, r, v);       else         update(L, mid, p << 1, l, mid, v),             update(mid + 1, R, p << 1 | 1, mid + 1, r, v);     }     int query(int L, int R, int p, int x) {       if (L == R) return val[p];       int mid = (L + R) >> 1;       if (mid >= x)         return val[p] + query(L, mid, p << 1, x);       else         return val[p] + query(mid + 1, R, p << 1 | 1, x);     }   } T1;   struct SEGMENT2 {     int val[M * 4];     void update(int L, int R, int p, int x, int v) {       val[p] += v;       if (L == R) return;       int mid = (L + R) >> 1;       if (mid >= x)         update(L, mid, p << 1, x, v);       else         update(mid + 1, R, p << 1 | 1, x, v);     }     int query(int L, int R, int p, int l, int r) {       if (L == l && R == r) return val[p];       int mid = (L + R) >> 1;       if (mid >= r)         return query(L, mid, p << 1, l, r);       else if (mid < l)         return query(mid + 1, R, p << 1 | 1, l, r);       else         return query(L, mid, p << 1, l, mid) +                query(mid + 1, R, p << 1 | 1, mid + 1, r);     }   } T2;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &q);     for (int i = 1, l, r; i <= q; i++)       scanf( %d %d , &l, &r), ps[r].push_back(pair<int, int>(l, i));     for (int i = 1, x, len; i <= n; i++) {       x = a[i];       len = i - las[x];       if (len != pas[x] && pas[x] != las[x]) {         if (mfr[x] < llas[x]) T1.update(1, n, 1, mfr[x] + 1, llas[x], 1);         mfr[x] = llas[x];       }       pas[x] = len;       if (las[x] != 0) T2.update(1, n, 1, las[x], -1);       T2.update(1, n, 1, i, 1);       llas[x] = las[x];       las[x] = i;       for (int j = 0, up = ps[i].size(), c1, c2, l, id; j < up; j++) {         l = ps[i][j].first;         id = ps[i][j].second;         c1 = T2.query(1, n, 1, l, i);         c2 = T1.query(1, n, 1, l);         if (c1 != c2)           ans[id] = c1;         else           ans[id] = c1 + 1;       }     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 10, K = 256, B = 16;   int a[N], parent[N], depth[N], up[N], ans[N][K];   vector<int> g[N];   bitset<(1 << (B + 1)) + 10> trie;   void make_tries(int i, int par);   void trie_insert(int val);   void trie_clear(int val);   int trie_max(int val);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     make_tries(1, 0);     while (q--) {       int u, v;       cin >> u >> v;       int dist = 0, res = 0;       while (depth[v] - depth[u] >= K - 1) {         res = max(res, ans[v][dist]);         v = up[v];         ++dist;       }       dist <<= 8;       while (depth[v] >= depth[u]) {         res = max(res, dist xor a[v]);         v = parent[v];         ++dist;       }       cout << res << endl;     }   }   void make_tries(int i, int par) {     parent[i] = par;     depth[i] = 1 + depth[par];     if (depth[i] >= K) {       int u = i;       int dist = 0;       while (depth[i] - depth[u] <= K - 1) {         trie_insert(dist xor a[u]);         u = parent[u];         ++dist;       }       for (int d = 0; d < K; ++d) {         ans[i][d] = trie_max(d << 8);       }       up[i] = u;       dist = 0;       u = i;       while (depth[i] - depth[u] <= K - 1) {         trie_clear(dist xor a[u]);         u = parent[u];         ++dist;       }     }     for (auto &j : g[i]) {       if (j != par) {         make_tries(j, i);       }     }   }   void trie_insert(int val) {     int pos = 1;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | ((val & (1 << b)) >> b);       trie[pos] = 1;     }   }   void trie_clear(int val) {     int pos = 1;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | ((val & (1 << b)) >> b);       trie[pos] = 0;     }   }   int trie_max(int val) {     int pos = 1, res = 0;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | (((val & (1 << b)) >> b) ^ 1);       if (trie[pos]) {         res |= (1 << b);       } else {         pos ^= 1;       }     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t, n;     cin >> t;     string s;     for (int k = 0; k < t; k++) {       cin >> n;       cin >> s;       if (s.size() == 2) {         if (s[0] < s[1]) {           cout <<  YES                 <<   n ;           cout << 2 <<   n ;           cout << s[0] <<     << s[1] << endl;         } else           cout <<  NO                 <<   n ;       } else {         cout <<  YES               <<   n ;         cout << 2 <<   n ;         cout << s[0] <<    ;         for (int i = 1; i < s.size(); i++) cout << s[i];         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int powmod(long long int a, int b, int n) {     long long int rm = 1;     while (b) {       if (b % 2) {         rm = (rm * a) % n;       }       a = (a * a) % n;       b /= 2;     }     return rm;   }   int main() {     int n;     long long int a[110];     cin >> n;     for (int i = (int)1; i <= (int)n; i++) cin >> a[i];     long long int cost = 0;     for (long long int i = 1; i <= n; ++i) {       cost = cost + (a[i] - 1) * i + 1;     }     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   int arr1[2222], arr2[2222];   char ans[999999];   long long int i, j, lo, hi, mid, cnt, sum, nd;   queue<int> q;   int main() {     cin >> s >> t;     for (i = 0; i < t.size(); i++) {       arr2[(int)(t[i] -  a )]++;     }     cnt = 0;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         cnt++;         q.push(i);       } else         arr1[(int)(s[i] -  a )]++;     }     lo = 0;     hi = 10000000;     while (lo <= hi) {       mid = (lo + hi) / 2;       sum = 0;       for (i = 0; i < 26; i++) {         nd = arr2[i] * mid;         nd -= arr1[i];         if (nd < 0) nd = 0;         sum = sum + nd;       }       if (sum >= cnt)         hi = mid - 1;       else         lo = mid + 1;     }     mid++;     sum = 0;     for (i = 0; i < 26; i++) {       nd = arr2[i] * mid;       nd -= arr1[i];       if (nd < 0) nd = 0;       sum = sum + nd;     }     if (sum > cnt) {       mid--;       sum = 0;       for (i = 0; i < 26; i++) {         nd = arr2[i] * mid;         nd -= arr1[i];         if (nd < 0) nd = 0;         sum = sum + nd;       }       if (sum > cnt) mid--;     }     for (i = 0; i < 26; i++) {       arr2[i] = arr2[i] * mid;       if (arr2[i]) {         while (arr2[i]--) {           if (arr1[i])             arr1[i]--;           else {             int u = q.front();             q.pop();             s[u] = (char)i +  a ;             cnt--;           }         }       }     }     while (cnt--) {       int u = q.front();       q.pop();       s[u] =  z ;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b);   long long mpower(long long x, long long y, long long c);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     map<long long, long long> M;     vector<long long> aa;     set<long long> st;     set<long long>::iterator itr;     long long n, i, j, k;     cin >> n;     string s;     cin >> s;     long long cnt = 0;     for (i = n - 1; i >= 0; i--) {       long long flag = -1;       if (2 * (i + 1) <= n) {         for (j = i + 1; j < (2 * (i + 1)); j++) {           if (s[j] == s[j - 1 - i]) {             flag = 1;           } else {             flag = -1;             break;           }         }       }       if (flag == 1) {         i = -1;       }       cnt++;     }     cout << cnt;     return 0;   }   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   long long mpower(long long x, long long y, long long c) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % c;       y = y >> 1;       x = (x * x) % c;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   double shortestDisSq(double x1, double y1, double x2, double y2, double x,                        double y) {     double magSq = pow(abs(x2 - x1), 2) + pow(abs(y2 - y1), 2);     double proj = ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)) / magSq;     if (proj > 1) proj = 1;     if (proj < 0) proj = 0;     return pow(abs((x1 + proj * (x2 - x1)) - x), 2) +            pow(abs((y1 + proj * (y2 - y1)) - y), 2);   }   int main() {     int n;     double x, y;     cin >> n >> x >> y;     double p, q;     double op, oq, ip, iq;     const double PI = 3.141592653589793238463;     double dis;     double R2 = 0;     double r2 = 100000000000000;     for (int i = 0; i < n; i++) {       cin >> p >> q;       if (i == 0) {         ip = p;         iq = q;       }       if (i > 0) r2 = min(r2, shortestDisSq(p, q, op, oq, x, y));       if (i == n - 1) r2 = min(r2, shortestDisSq(ip, iq, p, q, x, y));       op = p;       oq = q;       dis = pow(abs(x - p), 2) + pow(abs(y - q), 2);       R2 = max(R2, dis);     }     double res = PI * (R2 - r2);     printf( %.8lf n , res);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const long double pi = acos(-1.0);   const long double eps = 1e-6;   const int INF = 1E9;   const int MAXN = 5111;   struct node {     pair<int, int> key;     int pr, cnt;     node *l, *r;     node(pair<int, int> _key) {       key = _key;       pr = rand();       cnt = 1;       l = r = NULL;     }   };   int cnt(node *p) { return p ? p->cnt : 0; }   void upd_cnt(node *&p) {     if (p) p->cnt = 1 + cnt(p->l) + cnt(p->r);   }   void split(node *p, pair<int, int> key, node *&l, node *&r) {     if (p == NULL) {       l = r = NULL;       return;     }     if (key < p->key) {       split(p->l, key, l, p->l);       r = p;     } else {       split(p->r, key, p->r, r);       l = p;     }     upd_cnt(p);   }   void merge(node *&p, node *l, node *r) {     if (l == NULL)       p = r;     else if (r == NULL)       p = l;     else if (l->pr < r->pr) {       p = l;       merge(l->r, l->r, r);     } else {       p = r;       merge(r->l, l, r->l);     }     upd_cnt(p);   }   void insert(pair<int, int> key, int pr, node *&p) {     if (p == NULL) {       p = new node(key);       p->pr = pr;       return;     }     if (pr > p->pr) {       if (key > p->key)         insert(key, pr, p->r);       else         insert(key, pr, p->l);     } else {       node *t = new node(key);       t->pr = pr;       split(p, key, t->l, t->r);       p = t;     }     upd_cnt(p);   }   void erase(pair<int, int> key, node *&p) {     if (p == NULL) return;     if (p->key == key)       merge(p, p->l, p->r);     else {       if (key < p->key)         erase(key, p->l);       else         erase(key, p->r);     }     upd_cnt(p);   }   int n, m;   vector<int> color, used;   vector<vector<int> > g, queries;   vector<pair<int, int> > q;   vector<node *> root;   vector<map<int, int> > lib;   vector<int> ans, link;   void init() {     color.resize(n);     used.resize(n, 0);     root.resize(n, NULL);     g.resize(n);     queries.resize(n);     q.resize(m);     ans.resize(m);     link.resize(n);     lib.resize(n);   }   void intersect(int vid, int wid, node *&w) {     if (!w) return;     if (w->l) intersect(vid, wid, w->l);     if (w->r) intersect(vid, wid, w->r);     int ckey = w->key.second;     if (lib[link[vid]].find(ckey) == lib[link[vid]].end()) {       lib[link[vid]][ckey] = w->key.first;       insert(w->key, rand(), root[vid]);     } else {       erase(make_pair(lib[link[vid]][ckey], ckey), root[vid]);       w->key.first += lib[link[vid]][ckey];       insert(w->key, rand(), root[vid]);       lib[link[vid]][ckey] = w->key.first;     }     lib[link[wid]].erase(ckey);     delete w;   }   void dfs(int v, int par) {     used[v] = 1;     for (int i = 0; i < (int)(g[v].size()); i++) {       int w = g[v][i];       if (!used[w]) {         dfs(w, v);       }     }     if (v == 0) {       v = v;     }     int maxid = -1;     for (int i = 0; i < (int)(g[v].size()); i++) {       int w = g[v][i];       if (w != par) {         if (maxid == -1 || cnt(root[w]) > cnt(root[maxid])) maxid = w;       }     }     if (maxid != -1) {       link[v] = link[maxid];       root[v] = root[maxid];       for (int i = 0; i < (int)(g[v].size()); i++) {         int w = g[v][i];         if (w != par && w != maxid) {           intersect(v, w, root[w]);         }       }       if (lib[link[v]].find(color[v]) == lib[link[v]].end()) {         lib[link[v]][color[v]] = 1;         insert(make_pair(1, color[v]), rand(), root[v]);       } else {         erase(make_pair(lib[link[v]][color[v]], color[v]), root[v]);         lib[link[v]][color[v]]++;         insert(make_pair(lib[link[v]][color[v]], color[v]), rand(), root[v]);       }     } else {       root[v] = new node(make_pair(1, color[v]));       link[v] = v;       lib[link[v]][color[v]] = 1;     }     node *t1 = NULL, *t2 = NULL;     for (int i = 0; i < queries[v].size(); i++) {       int qid = queries[v][i];       split(root[v], make_pair(q[qid].second, 0), t1, t2);       ans[qid] = cnt(t2);       merge(root[v], t1, t2);     }   }   int main() {     cin >> n >> m;     init();     for (int i = 0; i < (int)(n); i++) cin >> color[i];     for (int i = 0; i < (int)(n - 1); i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < (int)(m); i++) {       cin >> q[i].first >> q[i].second;       q[i].first--;       queries[q[i].first].push_back(i);     }     dfs(0, 0);     for (int i = 0; i < (int)(m); i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1100000;   char s[MAXN];   int n;   bool check(int o) {     int p = 0;     int mx = 0;     bool uni = true;     for (int i = 0; i < n; i++) {       if (s[i] ==  L )         p--;       else {         if (p < o - 1) p++;       }       if (p < mx) {         mx = p;         uni = true;       } else {         uni = false;       }     }     return uni;   }   int main() {     scanf( %s , s);     n = strlen(s);     if (s[n - 1] ==  R ) {       for (int i = 0; i < n; i++) {         s[i] = (s[i] ==  L ) ?  R  :  L ;       }     }     if (check(n + 1)) {       printf( 1 );       return 0;     }     int a = 1, b = n;     while (a <= b) {       int m = (a + b) / 2;       if (check(m)) {         a = m + 1;       } else {         b = m - 1;       }     }     printf( %d , a - 1);   }


#include <bits/stdc++.h>   using namespace std;   bool primecheck(long long int a) {     bool check = true;     for (long long int i = 2; i <= sqrt(a); i++) {       if (a % i == 0) {         check = false;         break;       }     }     return (check);   }   vector<long long int> printDivisors(long long int n) {     vector<long long int> sol;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i) {           sol.push_back(i);         } else {           sol.push_back(i);           sol.push_back(n / i);         }       }     }     return (sol);   }   long long int digits(long long int a) { return (floor(log10(a)) + 1); }   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   bool check(string a, string b) {     long long int freq1[26] = {0};     long long int i;     for (i = 0; i < a.size(); i++) {       freq1[a[i] -  a ]++;     }     for (i = 0; i < b.size(); i++) {       freq1[b[i] -  a ]--;     }     bool sol = true;     for (i = 0; i < 26; i++)       if (freq1[i] != 0) sol = false;     return (sol);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b, c, i, j, k, l, m, n, t;     cin >> t;     while (t--) {       string num1, num2;       cin >> num1 >> num2;       bool sol;       long long int size1 = num1.size();       long long int size2 = num2.size();       if (size2 < size1) {         cout <<  NO               <<   n ;       } else {         sol = false;         for (i = 0; i <= size2 - size1; i++) {           string fresh = num1;           for (j = 0; j < size1; j++) {             fresh[j] = num2[i + j];           }           if (check(num1, fresh)) {             cout <<  YES                   <<   n ;             sol = true;             break;           }         }         if (!sol)           cout <<  NO                 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int INF = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   template <class T>   inline void read(T &x) {     int c;     for (c = getchar(); c < 32 && ~c; c = getchar())       ;     for (x = 0; c > 32; x = x * 10 + c -  0 , c = getchar())       ;   }   int n, m;   int chu[maxn];   vector<int> g[maxn];   priority_queue<int> q;   int ind;   int lab[maxn];   int main() {     read(n), read(m);     int u, v;     for (int i = 0; i < m; i++) {       read(v), read(u);       g[u].emplace_back(v);       chu[v]++;     }     ind = n;     for (int i = 1; i <= n; i++) {       if (chu[i] == 0) {         q.emplace(i);       }     }     while (!q.empty()) {       int x = q.top();       q.pop();       lab[x] = ind--;       for (auto &i : g[x]) {         chu[i]--;         if (chu[i] == 0) q.emplace(i);       }     }     for (int i = 1; i <= n; i++) {       cout << lab[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   namespace input {   template <class T>   void re(complex<T>& x);   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   void re(long double& x) {     string t;     re(t);     x = stold(t);   }   template <class T, class... Ts>   void re(T& t, Ts&... ts) {     re(t);     re(ts...);   }   template <class T>   void re(complex<T>& x) {     T a, b;     re(a, b);     x = cd(a, b);   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.first, p.second);   }   template <class T>   void re(vector<T>& a) {     for (int i = (0); i < ((int)a.size()); ++i) re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = (0); i < (SZ); ++i) re(a[i]);   }   }  // namespace input   using namespace input;   namespace output {   void pr(int x) { cout << x; }   void pr(long x) { cout << x; }   void pr(long long x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(unsigned long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(float x) { cout << x; }   void pr(double x) { cout << x; }   void pr(long double x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { pr(x ?  true  :  false ); }   template <class T>   void pr(const complex<T>& x) {     cout << x;   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T>   void pr(const T& x);   template <class T, class... Ts>   void pr(const T& t, const Ts&... ts) {     pr(t);     pr(ts...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.first,  ,  , x.second,  } );   }   template <class T>   void pr(const T& x) {     pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0;     pr( } );   }   void ps() { pr(  n ); }   template <class T, class... Ts>   void ps(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr(   );     ps(ts...);   }   void pc() { pr( ] n ); }   template <class T, class... Ts>   void pc(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr( ,  );     pc(ts...);   }   }  // namespace output   using namespace output;   namespace io {   void setIn(string second) { freopen(second.c_str(),  r , stdin); }   void setOut(string second) { freopen(second.c_str(),  w , stdout); }   void setIO(string second =   ) {     cin.sync_with_stdio(0);     cin.tie(0);     if ((int)second.size()) {       setIn(second +  .in ), setOut(second +  .out );     }   }   }  // namespace io   using namespace io;   typedef decay<decltype(MOD)>::type T;   struct mi {     T val;     explicit operator T() const { return val; }     mi() { val = 0; }     mi(const long long& v) {       val = (-MOD <= v && v <= MOD) ? v : v % MOD;       if (val < 0) val += MOD;     }     friend void pr(const mi& a) { pr(a.val); }     friend void re(mi& a) {       long long x;       re(x);       a = mi(x);     }     friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }     friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }     friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }     mi operator-() const { return mi(-val); }     mi& operator+=(const mi& m) {       if ((val += m.val) >= MOD) val -= MOD;       return *this;     }     mi& operator-=(const mi& m) {       if ((val -= m.val) < 0) val += MOD;       return *this;     }     mi& operator*=(const mi& m) {       val = (long long)val * m.val % MOD;       return *this;     }     friend mi pow(mi a, long long p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi& a) {       assert(a != 0);       return pow(a, MOD - 2);     }     mi& operator/=(const mi& m) { return (*this) *= inv(m); }     friend mi operator+(mi a, const mi& b) { return a += b; }     friend mi operator-(mi a, const mi& b) { return a -= b; }     friend mi operator*(mi a, const mi& b) { return a *= b; }     friend mi operator/(mi a, const mi& b) { return a /= b; }   };   int n, ways;   string g[2000];   pair<int, int> ans = {MOD, MOD};   bool check(vector<int> deg) {     vector<int> v;     for (int i = (0); i < (n); ++i) v.push_back(deg[i]);     sort(begin(v), end(v));     int sum = 0;     for (int i = (0); i < ((int)v.size() - 1); ++i) {       sum += v[i];       if (sum == i * (i + 1) / 2) return 0;     }     return 1;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     re(n);     vector<int> deg(n);     for (int i = (0); i < (n); ++i) {       re(g[i]);       for (int j = (0); j < (n); ++j)         if (g[i][j] ==  1 ) deg[i]++;     }     if (check(deg)) {       ps(0, 1);       exit(0);     }     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (n); ++j)         if (i != j) {           if (g[i][j] ==  0 ) {             deg[j]--;             deg[i]++;           } else {             deg[j]++;             deg[i]--;           }         }       ways += check(deg);       for (int j = (0); j < (n); ++j)         if (i != j) {           if (g[i][j] ==  0 ) {             deg[j]++;             deg[i]--;           } else {             deg[j]--;             deg[i]++;           }         }     }     if (ways)       ps(1, ways);     else {       assert(n <= 6);       pair<int, long long> ans = {MOD, MOD};       for (int i = (0); i < (1 << n); ++i) {         vector<int> deg(n);         for (int j = (0); j < (n); ++j)           for (int k = (0); k < (n); ++k)             if (j != k) {               int ori = g[j][k] -  0 ;               if (i & (1 << j)) ori ^= 1;               if (i & (1 << k)) ori ^= 1;               deg[j] += ori;             }         int p = __builtin_popcount(i);         if (check(deg)) {           if (p < ans.first) ans = {p, 0};           if (p == ans.first) ans.second++;         }       }       if (ans.first == MOD) {         ps(-1);         exit(0);       }       for (int i = (1); i < (ans.first + 1); ++i) ans.second *= i;       ps(ans.first, ans.second);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   long long dp[64];   long long solve(long long k) {     if (dp[k] != -1) return dp[k];     if (k == 0) return 1LL;     return ((16LL * solve(k - 1) % mod) * (solve(k - 1) % mod) % mod + mod) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long k;     cin >> k;     for (int i = (0); i < (64); i++) dp[i] = -1;     cout << ((6LL * solve(k - 1)) % mod + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, A[100], B[100], t, r, x;   string s =   ;   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       r = 0;       for (int j = 0; j <= n; j++) {         if ((t + r) == n) {           x = 1;           break;         }         r = r + 7;       }       if (x == 1) break;       t = t + 4;     }     if (x == 1) {       for (int i = 0; i < t / 4; i++) s +=  4 ;       for (int i = 0; i < r / 7; i++) s +=  7 ;     } else {       s =  -1 ;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265;   void fastInOut();   const int N = 5003;   const long long OO = (long long)1e18;   int n, m, k;   long long cum[N], memo[N][N];   long long go(int i, int c) {     if (i == n + 1) return c == k ? 0 : -OO;     long long &ret = memo[i][c];     if (ret != -1) return ret;     ret = go(i + 1, c);     if (i + m <= n + 1)       ret = max(ret, cum[i + m - 1] - cum[i - 1] + go(i + m, c + 1));     return ret;   }   int main() {     fastInOut();     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> cum[i];       cum[i] += cum[i - 1];     }     memset(memo, -1, sizeof(memo));     cout << go(1, 0);     return 0;   }   void fastInOut() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long int sum = 0;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       sum = sum + arr[i];     }     if (sum & 1) {       cout <<  NO  << endl;       return 0;     }     sum = sum / 2;     multiset<long long int> m1, m2;     for (int i = 0; i < n; ++i) {       m2.insert(arr[i]);     }     for (int i = 0; i < n; ++i) {       m1.insert(arr[i]);       m2.erase(m2.find(arr[i]));       sum = sum - arr[i];       if (sum == 0 || m1.find(-sum) != m1.end() || m2.find(sum) != m2.end()) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int powmod(int a, int p, int m) {     int64_t ans = 1, cp = a;     for (int i = 0; (1ll << i) <= p; ++i, cp = cp * cp % m)       if ((1ll << i) & p) ans = ans * cp % m;     return ans;   }   int divmod(int64_t a, int b, int m) { return a * powmod(b, m - 2, m) % m; }   const int N = 200000;   int a[N], t[N], b[N], n, m;   unordered_set<int> pres;   vector<int> s;   double et;   pair<int, int> solve() {     {       if (n > 2)         if (rand() & 1)           swap(a[0], a[rand() % (n - 2) + 2]),               swap(a[1], a[rand() % (n - 2) + 2]);         else           swap(a[1], a[rand() % (n - 2) + 2]),               swap(a[0], a[rand() % (n - 2) + 2]);       s.clear();       for (int i = 0; i < n; ++i) s.push_back((a[i] - a[0] + m) % m);       sort(begin(s), end(s));       int dst = 0;       for (int i = 0; i < n; ++i) {         auto t = lower_bound(begin(s), end(s), (a[i] - a[1] + m) % m);         if (t == s.end() || *t != (a[i] - a[1] + m) % m) dst++;       }       int d = divmod((a[1] - a[0] + m) % m, dst, m), heads = 0;       for (int i = 0; i < n; ++i) heads += !pres.count((a[i] + d) % m);       if (!~-heads)         for (int i = 0; i < n; ++i)           if (!pres.count((a[i] + d) % m)) return {a[i], (m - d) % m};     }     return {-1, -1};   }   int main() {     srand(101);     cin.tie(0), ios::sync_with_stdio(0);     int comp = 0;     cin >> m >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     if (n == 1 || n == m) return cout << a[0] <<     << 1, 0;     if (n > m - n) {       sort(a, a + n);       for (int i = 0; i < m; ++i) t[i] = i;       memcpy(a, b, (set_difference(t, t + m, a, a + n, b) - b) * sizeof *b);       comp = 1;       n = m - n;     }     for (int i = 0; i < n; ++i) pres.insert(a[i]);     random_shuffle(a, a + n);     auto ans = solve();     if (!~ans.first)       cout <<  -1 ;     else if (!comp)       cout << ans.first <<     << ans.second <<   n ;     else       cout << (ans.first - ans.second + m) % m <<     << (m - ans.second) % m            <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> p(n);       int id = -1;       for (int i = 0; i < n; ++i) {         cin >> p[i];         if (p[i] == 1) id = i;       }       bool f1 = 0, f2 = 0;       int val = 0;       for (int i = id, j = 0; j < n; ++i, ++j) {         ++val;         if (p[i % n] != val) f1 = 1;       }       val = 0;       for (int i = id, j = 0; j < n; --i, ++j) {         ++val;         if (i < 0) i += n;         if (p[i % n] != val) f2 = 1;       }       if (f1 == 0 || f2 == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int f[11][11][4][maxn];   int n;   char s[maxn];   char c[maxn];   int lowbit(int x) { return x & (-x); }   int ch(char s) {     if (s ==  A )       return 1;     else if (s ==  T )       return 2;     else if (s ==  G )       return 3;     else if (s ==  C )       return 4;     return -1;   }   void Add(int *tr, int x, int d) {     for (; x <= n; x += lowbit(x)) {       tr[x] += d;     }   }   int Sum(int *tr, int x) {     if (x == 0) return 0;     int s = 0;     while (x) {       s += tr[x];       x -= lowbit(x);     }     return s;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 10; j++) Add(f[j][i % j][ch(s[i])], i, 1);     int q, x, d, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       if (x == 1) {         scanf( %d%s , &d, c);         for (int i = 1; i <= 10; i++) {           Add(f[i][d % i][ch(s[d])], d, -1);         }         s[d] = c[0];         for (int i = 1; i <= 10; i++) Add(f[i][d % i][ch(s[d])], d, 1);       } else {         scanf( %d %d %s , &l, &r, c);         int len = strlen(c);         int ans = 0;         for (int i = 0; i < len; i++) {           ans += Sum(f[len][(l + i) % len][ch(c[i])], r) -                  Sum(f[len][(l + i) % len][ch(c[i])], l - 1);         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[55][55];   double comb[55];   int a[55];   int main(int argc, char **argv) {     int n, p;     int tot = 0;     double res = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       tot += a[i];     }     cin >> p;     if (tot <= p) {       cout << n << endl;       return 0;     }     comb[0] = 1;     for (int i = 1; i <= n; i++) comb[i] = comb[i - 1] * i;     for (int block = 0; block < n; block++) {       memset(dp, 0, sizeof(dp));       dp[0][0] = 1;       for (int i = 0; i < n; i++) {         if (i == block) continue;         for (int j = p - a[i]; j >= 0; j--) {           for (int k = 0; k < n - 1; k++) {             dp[j + a[i]][k + 1] += dp[j][k];           }         }       }       for (int i = 0; i <= p; i++) {         if (a[block] + i > p) {           for (int j = 1; j <= n - 1; j++) {             res += j * dp[i][j] * comb[j] * comb[n - 1 - j] / comb[n];           }         }       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int x1, y1, x2, y2;     int sum = 0;     for (int i = 0; i < n; ++i) {       cin >> x1 >> y1 >> x2 >> y2;       sum += (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     bool good[n];     for (int i = 0; i < n; i++) good[i] = 1;     for (int i = 0; i < n; i++) {       int isGood = 1;       for (int j = 0; j < n; j++) {         int dum;         cin >> dum;         if (dum == 1 || dum == 3)           good[i] = 0;         else if (dum == 2)           good[j] = 0;       }     }     int ans = 0;     for (int i = 0; i < n; i++)       if (good[i]) ans++;     cout << ans << endl;     for (int i = 0; i < n; i++) {       if (good[i]) cout << i + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, i, v = 0, a[1010];     cin >> n >> s;     for (i = 1; i <= n; i++) {       cin >> a[i];       v = v + a[i];     }     for (i = 1; i <= n; i++)       if ((v - a[i]) <= s) {         cout <<  YES ;         return 0;       }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, m, in[N], out[N], id[N], dep[N];   vector<int> v[N];   int idx;   void dfs(int pos, int dd) {     in[pos] = ++idx;     id[idx] = pos;     dep[idx] = dd;     for (auto &i : v[pos]) dfs(i, dd + 1);     out[pos] = ++idx;     id[idx] = pos;     dep[idx] = dd;   }   int fa[N], ch[N][2], mn[N], mx[N], val[N], sz[N];   inline void pushup(int x) {     sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1;     mn[x] = mx[x] = dep[x];     mn[x] = min({mn[x], mn[ch[x][0]], mn[ch[x][1]]});     mx[x] = max({mx[x], mx[ch[x][0]], mx[ch[x][1]]});   }   int build(int l, int r) {     int mid = (l + r) >> 1, x = mid;     if (l < mid) ch[x][0] = build(l, mid - 1), fa[ch[x][0]] = x;     if (mid < r) ch[x][1] = build(mid + 1, r), fa[ch[x][1]] = x;     pushup(x);     return x;   }   inline void push(int x, int v) {     val[x] += v;     dep[x] += v;     mn[x] += v;     mx[x] += v;   }   inline void pushdown(int x) {     if (val[x]) {       if (ch[x][0]) push(ch[x][0], val[x]);       if (ch[x][1]) push(ch[x][1], val[x]);       val[x] = 0;     }   }   inline bool sd(int x) { return ch[fa[x]][1] == x; }   void rotate(int x) {     int y = fa[x], z = fa[y], k = sd(x);     if (z) ch[z][sd(y)] = x;     fa[x] = z;     fa[y] = x;     if (ch[x][!k]) fa[ch[x][!k]] = y;     ch[y][k] = ch[x][!k];     ch[x][!k] = y;     pushup(y);     pushup(x);   }   void splay(int x, int target = 0) {     static int stk[N], ptr;     stk[ptr = 1] = x;     int tmp = x;     while (fa[tmp] != target) stk[++ptr] = tmp = fa[tmp];     while (ptr) pushdown(stk[ptr--]);     while (fa[x] != target) {       int y = fa[x];       if (fa[y] != target) rotate(sd(x) == sd(y) ? y : x);       rotate(x);     }     pushup(x);   }   int kth(int x, int kk) {     pushdown(x);     if (mn[ch[x][1]] <= kk && mx[ch[x][1]] >= kk) return kth(ch[x][1], kk);     if (dep[x] == kk) {       splay(x);       return id[x];     }     return kth(ch[x][0], kk);   }   inline int split(int l, int r) {     splay(l);     splay(r, l);     return ch[r][0];   }   int pre(int x) {     splay(x);     x = ch[x][0];     while (ch[x][1]) x = ch[x][1];     splay(x);     return x;   }   int suf(int x) {     splay(x);     x = ch[x][1];     while (ch[x][0]) x = ch[x][0];     splay(x);     return x;   }   int erase(int l, int r) {     int lp = pre(l), rp = suf(r), p = split(lp, rp), v = fa[p];     ch[v][0] = fa[p] = 0;     return p;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int kk;       cin >> kk;       v[i].resize(kk);       for (int j = 0; j < kk; j++) cin >> v[i][j];     }     mn[0] = INT_MAX >> 1;     dfs(1, 0);     build(1, idx);     while (m--) {       int op;       cin >> op;       if (op == 1) {         int t1, t2;         cin >> t1 >> t2;         splay(in[t1]);         int rk1 = sz[ch[in[t1]][0]] + 1, ans = dep[in[t1]];         splay(in[t2]);         int rk2 = sz[ch[in[t2]][0]] + 1;         ans += dep[in[t2]];         if (rk1 > rk2) swap(t1, t2);         t1 = split(in[t1], out[t2]);         ans -= (mn[t1] - 1) * 2;         cout << ans << endl;       } else if (op == 2) {         int t1, t2;         cin >> t1 >> t2;         int val = t2 - 1;         splay(in[t1]);         t2 = kth(ch[in[t1]][0], dep[in[t1]] - t2);         t1 = erase(in[t1], out[t1]);         push(t1, -val);         int xx = pre(out[t2]);         splay(xx);         splay(out[t2], xx);         ch[out[t2]][0] = t1;         fa[t1] = out[t2];         pushup(out[t2]);         pushup(xx);       } else {         int k;         cin >> k;         splay(1);         cout << kth(1, k) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<int> adj[(int)1e5 + 7];   int vis[(int)1e5 + 7];   int deg[(int)1e5 + 7];   int cnt[(int)1e5 + 7];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       deg[v]++;       deg[u]++;     }     int lvl = 0;     queue<int> q;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.push(i);     while (q.size()) {       set<int> kroots;       int sz = q.size();       while (sz--) {         int root = q.front();         q.pop();         vis[root] = 1;         for (auto neighbour : adj[root]) {           if (vis[neighbour]) {             continue;           }           deg[neighbour]--;           cnt[neighbour]++;           kroots.insert(neighbour);         }       }       for (auto val : kroots) {         if (vis[val] || deg[val] > 1 || cnt[val] < 3) {           puts( No );           return 0;         }         q.push(val);       }       if (kroots.size())         lvl++;       else         break;     }     if (lvl == k)       puts( Yes );     else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, m, a, b, c, q, k, d, x;     cin >> n >> m;     vector<vector<int>> mat(n + 1, vector<int>(m + 1)),         ans(n + 1, vector<int>(m + 1));     char ch;     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) {         cin >> ch;         mat[i][j] = ch -  0 ;         ans[i][j] = ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1] + mat[i][j];       }     }     a = 0;     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) {         for (int i_ = i; i_ < n + 1; i_++) {           for (int j_ = j; j_ < m + 1; j_++) {             if (ans[i_][j_] - ans[i - 1][j_] - ans[i_][j - 1] +                     ans[i - 1][j - 1] ==                 0) {               a = max(a, 2 * (i_ - i + 1 + j_ - j + 1));             }           }         }       }     }     cout << a <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   long long INF = 1000000000000000005ll;   double PI = acos(-1);   inline string IntToString(long long int a) {     char x[100];     sprintf(x,  %lld , a);     string s = x;     return s;   }   inline long long int StringToInt(string a) {     char x[100];     long long int res;     strcpy(x, a.c_str());     sscanf(x,  %lld , &res);     return res;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (long long int i = 0; i < n; i++)       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (long long int i = 0; i < n; i++)       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) {     return v1[0] > v2[0];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int c[n];     string r[n];     string s[n];     for (long long int i = 0; i < n; i++) cin >> c[i];     for (long long int i = 0; i < n; i++) {       cin >> r[i];       s[i] = r[i];       reverse(r[i].begin(), r[i].end());     }     long long int dp[n + 1][2];     memset(dp, 0, sizeof(dp));     dp[0][1] = c[0];     for (long long int i = 1; i < n; i++) {       dp[i][0] = INF;       dp[i][1] = INF;       if (s[i] >= s[i - 1]) {         dp[i][0] = min(dp[i - 1][0], dp[i][0]);       }       if (s[i] >= r[i - 1]) {         dp[i][0] = min(dp[i - 1][1], dp[i][0]);       }       if (r[i] >= s[i - 1]) {         dp[i][1] = min(dp[i - 1][0] + c[i], dp[i][1]);       }       if (r[i] >= r[i - 1]) {         dp[i][1] = min(dp[i - 1][1] + c[i], dp[i][1]);       }     }     long long int mi = min(dp[n - 1][0], dp[n - 1][1]);     if (mi != INF)       cout << min(dp[n - 1][0], dp[n - 1][1]) <<   n ;     else       cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T Min(T x, T y) {     return x < y ? x : y;   }   template <class T>   inline T Max(T x, T y) {     return x > y ? x : y;   }   bool MOP1;   long long T, n, res;   long long head[(105)], nxt[(105)], to[(105)], line;   void add(long long x, long long y) {     nxt[++line] = head[x], to[line] = y, head[x] = line;   }   struct node {     string name;     long long lei, X, Y;     long long tot, mx;     long long sz, bo, sp;     long long x() {       if (lei == 2) return sz ? tot + bo * 2 + (sz - 1) * sp : 0;       if (lei == 3) return sz ? mx + bo * 2 : 0;     }     long long y() {       if (lei == 2) return sz ? mx + bo * 2 : 0;       if (lei == 3) return sz ? tot + bo * 2 + (sz - 1) * sp : 0;     }     void add(node now) {       sz++;       if (lei == 2) {         tot += now.X;         mx = Max(mx, now.Y);       } else if (lei == 3) {         tot += now.Y;         mx = Max(mx, now.X);       }     }     bool operator<(const node &a) const { return name < a.name; }   } A[(105)];   long long read(string k) {     long long res = 0;     for (long long i = 0; i < k.size(); i++)       res = (res << 1) + (res << 3) + (k[i] ^ 48);     return res;   }   map<string, long long> mp;   string str;   long long a, b;   bool mark[(105)];   void dfs(long long x) {     mark[x] = 1;     for (long long i = head[x]; i; i = nxt[i]) {       long long y = to[i];       if (!mark[y]) dfs(y), mark[y] = 1;       A[x].add(A[y]);     }     if (A[x].lei != 1) {       A[x].X = A[x].x();       A[x].Y = A[x].y();     }     return;   }   bool MOP2;   signed main() {     scanf( %d , &T);     while (T--) {       cin >> str;       if (str[0] ==  W ) {         getchar();         getline(cin, str,  ( );         mp[str] = ++n;         A[n].lei = 1;         A[n].name = str;         scanf( %d,%d) , &A[n].X, &A[n].Y);       } else if (str[0] ==  H ) {         cin >> str;         mp[str] = ++n;         A[n].name = str;         A[n].lei = 2;       } else if (str[0] ==  V ) {         cin >> str;         mp[str] = ++n;         A[n].name = str;         A[n].lei = 3;       } else {         res = str.find( . );         a = mp[str.substr(0, res)];         if (str[res + 1] ==  s ) {           long long now = str.find( ( ) + 1;           long long tmp = read(str.substr(now, str.size() - now - 1));           if (str[res + 5] ==  b ) {             A[a].bo = tmp;           } else if (str[res + 5] ==  s ) {             A[a].sp = tmp;           }         } else {           b = mp[str.substr(res + 6, str.size() - res - 7)];           add(a, b);         }       }     }     for (long long i = 1; i <= n; i++)       if (!mark[i]) dfs(i);     sort(A + 1, A + 1 + n);     for (long long i = 1; i <= n; i++)       cout << A[i].name <<     << A[i].X <<     << A[i].Y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-9;   inline int cmp(double x, double y = 0, double tol = EPS) {     return ((x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1);   }   struct point {     long long x, y;     point(long long x = 0, long long y = 0) : x(x), y(y) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; };     bool operator!=(point q) const { return cmp(q) != 0; };     bool operator<(point q) const { return cmp(q) < 0; };   };   ostream &operator<<(ostream &os, const point &p) {     os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   long long dot(point a, point b) { return a.x * b.x + a.y * b.y; }   long long cross(point a, point b) { return a.x * b.y - a.y * b.x; }   long long abs2(point a) { return dot(a, a); }   bool collinear(point a, point b, point c) {     return cmp(cross((b - a), (c - a))) == 0;   }   int ccw(point a, point b, point p) { return cmp(cross((b - a), (p - a))); }   point pivot;   bool radial_lt(point a, point b) {     int R = ccw(pivot, a, b);     if (R == 0)       return dot(pivot - a, pivot - a) < dot(pivot - b, pivot - b);     else       return (R == 1);   }   vector<point> convexhull(vector<point> T) {     sort(T.begin(), T.end());     T.resize(unique(T.begin(), T.end()) - T.begin());     int tam = 0, n = T.size();     vector<point> U;     int idx = min_element(T.begin(), T.end()) - T.begin();     pivot = T[idx];     swap(T[0], T[idx]);     sort(++T.begin(), T.end(), radial_lt);     for (int i = 0; i < T.size(); i++) {       while (tam > 1 && ccw(U[tam - 2], U[tam - 1], T[i]) <= 0)         U.pop_back(), tam--;       U.push_back(T[i]);       tam++;     }     return U;   }   void show(pair<pair<long long, long long>, pair<long long, long long> > s) {     cout << s.first.first <<     << s.first.second <<     << s.second.first <<              << s.second.second << endl;   }   int least_rot(       vector<pair<pair<long long, long long>, pair<long long, long long> > >           second) {     int n = second.size();     for (int i = (0); i < (n); i++) second.push_back(second[i]);     vector<int> f(second.size(), -1);     int k = 0;     for (int j = 1; j < second.size(); j++) {       pair<pair<long long, long long>, pair<long long, long long> > sj =           second[j];       int i = f[j - k - 1];       while (i != -1 && sj != second[k + i + 1]) {         if (sj < second[k + i + 1]) k = j - i - 1;         i = f[i];       }       if (sj != second[k + i + 1]) {         if (sj < second[k]) k = j;         f[j - k] = -1;       } else         f[j - k] = i + 1;     }     return k;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<point> A(n), B(m);     point p;     for (int i = (0); i < (n); i++) {       scanf( %lld %lld , &p.x, &p.y);       A[i] = p;     }     for (int i = (0); i < (m); i++) {       scanf( %lld %lld , &p.x, &p.y);       B[i] = p;     }     A = convexhull(A);     B = convexhull(B);     n = A.size();     m = B.size();     if (n != m) {       cout <<  NO n ;       return 0;     }     vector<pair<pair<long long, long long>, pair<long long, long long> > > AA, BB;     point esq, dir;     int ee, dd;     for (int i = (0); i < (n); i++) {       ee = i - 1;       if (ee < 0) ee += n;       dd = i + 1;       if (dd >= n) dd %= n;       esq = A[ee] - A[i], dir = A[dd] - A[i];       AA.push_back(make_pair(make_pair(cross(esq, dir), dot(esq, dir)),                              make_pair(abs2(esq), abs2(dir))));     }     for (int i = (0); i < (n); i++) {       ee = i - 1;       if (ee < 0) ee += n;       dd = i + 1;       if (dd >= n) dd %= n;       esq = B[ee] - B[i], dir = B[dd] - B[i];       BB.push_back(make_pair(make_pair(cross(esq, dir), dot(esq, dir)),                              make_pair(abs2(esq), abs2(dir))));     }     int u = least_rot(AA);     int v = least_rot(BB);     bool ok = true;     for (int i = (0); i < (n); i++) {       if (AA[u] != BB[v]) {         ok = false;         break;       }       u = (u + 1) % n;       v = (v + 1) % n;     }     if (ok)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   const int mx = 110;   int a[mx];   bool ok(char ch) {     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u  ||         ch ==  y )       return true;     return false;   }   int main() {     int n;     bool flag = 1;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     getchar();     for (int i = 0; i < n; i++) {       int num = 0;       char c;       while ((c = getchar()) !=   n )         if (ok(c)) num++;       if (num != a[i]) flag = 0;     }     printf(flag ?  YES n  :  NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 2, maxm = 1e7 + 5;   struct node {     int bg, ed, id;   } a[maxn];   int n, ans[maxn];   bool vis[maxm];   bool cmp(node a, node b) { return a.ed < b.ed; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i].bg, &a[i].ed);       a[i].id = i;     }     sort(a, a + n, cmp);     for (int i = 0; i < n; i++) {       int y = a[i].bg;       while (vis[y]) y++;       vis[y] = true;       ans[a[i].id] = y;     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   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...);   }   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   int root;   vector<vector<int> > g;   vector<int> ans;   int sub[N], t[N];   void dfs0(int v, int p) {     sub[v] = t[v];     for (auto u : g[v]) {       if (u != p) {         dfs0(u, v);         sub[v] += sub[u];       }     }     return;   }   int dfs1(int v, int p) {     int ret = -1, temp;     if ((v != root) && 3 * sub[v] == sub[root]) {       ret = v;     }     vector<int> ans;     for (auto u : g[v]) {       if (u != p) {         temp = dfs1(u, v);         if (temp != -1) {           if (ret == -1) ret = temp;           if (sub[v] == 2 * sub[temp] && (sub[root] - sub[v] == sub[temp]) &&               (v != root)) {             cout << min(v, temp) <<     << max(v, temp) <<   n ;             exit(0);           }           ans.push_back(temp);           if (ans.size() >= 2) {             cout << min(ans[0], ans[1]) <<     << max(ans[0], ans[1]) <<   n ;             exit(0);           }         }       }     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     g.resize(n + 2);     int p;     for (int i = 1; i <= n; i++) {       cin >> p >> t[i];       if (p != 0) {         g[i].push_back(p);         g[p].push_back(i);       } else {         root = i;       }     }     dfs0(root, -1);     dfs1(root, -1);     if ((int)ans.size() < 2) {       cout << -1 <<   n ;     } else {       cout << min(ans[0], ans[1]) <<     << max(ans[0], ans[1]) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       if (n <= 2) {         cout << 0 << endl;         continue;       } else {         int x;         x = n / 2;         if (n % 2 == 0) x--;         cout << x << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int ans = 0;     for (int i = 1; i <= k; i++) ans += a[i];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[60][20010];   int S[60][20010];   int n, m, k;   int sum(int i, int l, int r) {     if (l > r) return 0;     return S[i][r] - S[i][l - 1];   }   int L[20010], R[20010];   int pre[20010], suf[20010];   int ST[2][200010];   void init(int tree[], int A[], int node, int li, int ls) {     if (li == ls) {       tree[node] = A[li];     } else {       int mid = (li + ls) / 2;       init(tree, A, 2 * node, li, mid);       init(tree, A, 2 * node + 1, mid + 1, ls);       tree[node] = max(tree[2 * node], tree[2 * node + 1]);     }   }   int query(int tree[], int node, int li, int ls, int i, int j) {     if (i > ls || j < li) return -0x3f3f3f3f;     if (li >= i && ls <= j) return tree[node];     int mid = (li + ls) / 2;     int left = query(tree, 2 * node, li, mid, i, j);     int right = query(tree, 2 * node + 1, mid + 1, ls, i, j);     return max(left, right);   }   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &S[i][j]);         S[i][j] += S[i][j - 1];       }     }     int ans = 0;     for (int i = n; i > 0; i--) {       for (int j = 1; j <= m; j++) {         dp[i][j] = 0;         int l = max(1, j - k + 1), r = min(m, j + k - 1);         if (l > 1) {           dp[i][j] = pre[l - 1] + sum(i + 1, j, r);         }         if (r < m) {           dp[i][j] = max(dp[i][j], suf[r + 1] + sum(i + 1, j, r));         }         dp[i][j] = max(dp[i][j], query(ST[0], 1, 1, m, l, j) + S[i + 1][r]);         dp[i][j] =             max(dp[i][j], query(ST[1], 1, 1, m, j + 1, r) - S[i + 1][j - 1]);         dp[i][j] += sum(i, j, r);         ans = max(ans, dp[i][j]);       }       for (int j = 1; j <= m; j++) {         pre[j] = dp[i][j];         suf[j] = dp[i][j];       }       for (int j = 2; j <= m; j++) {         pre[j] = max(pre[j], pre[j - 1]);         suf[m - j + 1] = max(suf[m - j + 1], suf[m - j + 2]);       }       for (int j = 1; j <= m; j++) {         L[j] = dp[i][j] - S[i][min(m, j + k - 1)];         R[j] = dp[i][j] + S[i][j - 1];       }       init(ST[0], L, 1, 1, m);       init(ST[1], R, 1, 1, m);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   void solve(long long n) {     long long step = 0;     while (n != 1) {       if (n % 2 == 0) {         if (n % 6 != 0) {           ans.push_back(-1);           return;         }         n /= 6;         if (n == 0) {           ans.push_back(-1);           return;         }       } else {         n *= 2;         if (n % 6 != 0) {           ans.push_back(-1);           return;         }       }       ++step;     }     ans.push_back(step);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       solve(n);     }     for (int i = (0); i < (ans.size()); ++i) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, nums[2201], ans = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     sort(nums, nums + n);     for (int i = 0; i < k; i++) {       ans += nums[i];     }     cout << ans;     return 0;   }