#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     cout << min(n, m) + 1 << endl;     for (int i = 0; i < min(n, m) + 1; i++) {       cout << i <<     << min(n, m) - i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[100];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int m = a[0];     for (int i = 1; i < n; i++) {       if (a[i] > m) {         m = a[i];       }     }     int o = 0;     for (int i = 0; i < n; i++) {       o = o + (m - a[i]);     }     cout << o;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500005, maxd = 20;   int jump[maxd][maxn], range[maxd][maxn];   int a[maxn], L[maxn], lmin[maxd][maxn];   int n;   int getminL(int a, int b) { return L[a] < L[b] ? a : b; }   int getmin(int a, int b) {     int k = b - a + 1 ? 31 - __builtin_clz(b - a + 1) : 0;     return getminL(lmin[k][a], lmin[k][b - (1 << k) + 1]);   }   int main() {     int i, x, d, ld;     scanf( %d , &n);     for (ld = 0; (1 << ld) <= n; ++ld)       ;     for (i = 1; i <= n; ++i) scanf( %d , a + i), a[i + n] = a[i];     for (i = 1; i <= n + n; ++i) L[i] = max(i - a[i], 0), lmin[0][i] = i;     for (d = 1; d < ld; ++d)       for (i = 1; i <= n + n - (1 << d) + 1; ++i)         lmin[d][i] = getminL(lmin[d - 1][i], lmin[d - 1][i + (1 << (d - 1))]);     for (i = 1; i <= n + n; ++i) {       jump[0][i] = getmin(L[i], i);       range[0][i] = L[i];       for (d = 1; range[d - 1][i]; ++d)         jump[d][i] = jump[d - 1][jump[d - 1][i]],         range[d][i] = range[d - 1][jump[d - 1][i]];     }     long long ans = 0;     for (i = n; i < n + n; ++i)       for (d = ld - 1, x = i, ++ans; d >= 0; --d)         if (range[d][x] > i - n + 1) ans += 1 << d, x = jump[d][x];     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const long long INF = 1e18;   const int irand(int lo, int hi) {     return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;   }   const long long lrand(long long lo, long long hi) {     return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;   }   template <typename T>   T getnum() {     int sign = 1;     T ret = 0;     char c;     do {       c = getchar();     } while (c ==     || c ==   n );     if (c ==  - )       sign = -1;     else       ret = c -  0 ;     while (1) {       c = getchar();       if (c <  0  || c >  9 ) break;       ret = 10 * ret + c -  0 ;     }     return sign * ret;   }   inline void ini(int& x) { x = getnum<int>(); }   inline void scani(int& x) { scanf( %d , &x); }   int n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (n * m > 2 && (n == 1 || m == 1)) {       cout << 1 << endl;       cout << n <<     << m <<   1 1  << endl;       if (n == 1) {         for (int j = 1; j <= m; j += 1) cout << 1 <<     << j << endl;       } else {         for (int i = 1; i <= n; i += 1) cout << i <<     << 1 << endl;       }       cout <<  1 1  << endl;     } else if ((n * m) & 1) {       cout << 1 << endl;       cout << n <<     << m <<   1 1  << endl;       for (int i = 1; i <= n; i += 1) {         if (i & 1) {           for (int j = 1; j <= m; j += 1) {             cout << i <<     << j << endl;           }         } else {           for (int j = m; j >= 1; j -= 1) {             cout << i <<     << j << endl;           }         }       }       cout <<  1 1  << endl;     } else {       cout << 0 << endl;       cout <<  1 1  << endl;       if (m & 1) {         for (int i = 1; i <= n; i += 1) {           if (i & 1) {             for (int j = 2; j <= m; j += 1) cout << i <<     << j << endl;           } else {             for (int j = m; j >= 2; j -= 1) cout << i <<     << j << endl;           }         }         for (int i = n; i >= 1; i -= 1) cout << i <<     << 1 << endl;       } else {         for (int j = 1; j <= m; j += 1) {           if (j & 1) {             for (int i = 2; i <= n; i += 1) cout << i <<     << j << endl;           } else {             for (int i = n; i >= 2; i -= 1) cout << i <<     << j << endl;           }         }         for (int j = m; j >= 1; j -= 1) cout << 1 <<     << j << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long Inf = 1e18;   const int N = 2e5 + 10;   const int mod = 0;   long long gi() {     long long x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   template <typename T>   bool chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   };   template <typename T>   bool chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   };   int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }   void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }   void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }   int n, x[N], sum[N];   long long a[N], t, b[N];   int main() {     cin >> n >> t;     for (int i = 1; i <= n; i++) a[i] = gi();     for (int i = 1; i <= n; i++) x[i] = gi();     for (int i = 1; i <= n; i++) {       if (x[i] < i) return puts( No ), 0;       sum[i]++;       sum[x[i]]--;     }     for (int i = 1; i <= n; i++) {       sum[i] += sum[i - 1];       b[i] = a[i] + t;       if (sum[i]) b[i] = a[i + 1] + t;       chkmax(b[i], b[i - 1] + 1);     }     for (int i = 1; i <= n; i++)       if (x[i] != n && b[x[i]] >= a[x[i] + 1] + t) return puts( No ), 0;     puts( Yes );     for (int i = 1; i <= n; i++) printf( %lld  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6, mod = 1e9 + 7, inf = 1e10;   long long int a[N], dp[N];   int main() {     long long int n, mn = 0, mx = -1, ans_1 = 0, ans_2 = 0, cnt, clk, clr;     cin >> n;     for (long long int i = 1; i * i * i <= n; i++) {       if (n % i == 0) {         for (long long int j = 1; j * j <= (n / i); j++) {           long long int k = n / (i * j);           if (i * j * k == n) {             cnt = (i + 1) * (j + 2) * (k + 2);             if (mn == 0) mn = cnt;             mn = min(mn, cnt);             mx = max(mx, cnt);             clk = (i + 2) * (j + 1) * (k + 2);             mn = min(mn, clk);             mx = max(mx, clk);             clr = (i + 2) * (j + 2) * (k + 1);             mn = min(mn, clr);             mx = max(mx, clr);           }         }       }     }     ans_1 = mn - n;     ans_2 = mx - n;     cout << ans_1 <<    ;     return cout << (ans_2), 0;   }


#include <bits/stdc++.h>   int arr[150];   int temp[150];   int main() {     int n, m;     std::cin >> n >> m;     for (int i = 0; i < n; ++i) {       int a, b;       std::cin >> a >> b;       for (int j = a; j <= b; ++j) arr[j]++;     }     int cnt = 0;     for (int i = 1; i <= m; ++i) {       if (!arr[i]) temp[cnt++] = i;     }     std::cout << cnt << std::endl;     for (int i = 0; i < cnt; ++i) {       if (!i)         std::cout << temp[i];       else         std::cout <<     << temp[i];     }     if (cnt) std::cout << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6000;   int dp[N][N], len[N], dep[N], sz[N], n, k, val[N];   char S[N * 300];   char *s[N];   struct Edge {     int L, len;     int to;     Edge(int L = 0, int len = 0, int to = 0) : L(L), len(len), to(to) {}   } d[N][26];   inline int idx(int c) { return c -  a ; }   void dfs(int x) {     sz[x] = val[x];     for (int i = 0; i <= sz[x]; i++) dp[x][i] = dep[x] * i * (i - 1) / 2;     for (int i = 0; i < 26; i++)       if (d[x][i].to) {         int u = d[x][i].to;         dep[u] = dep[x] + d[x][i].len;         dfs(u);         sz[x] += sz[u];         for (int i = sz[x]; i >= 0; i--) {           int xx = 0;           for (int j = 0; j <= sz[u] && j <= i; j++)             xx = max(xx, dp[x][i - j] + dp[u][j] + j * (i - j) * dep[x]);           dp[x][i] = xx;         }       }   }   int xb;   int main() {     scanf( %d%d , &n, &k);     s[0] = S;     xb = 1;     for (int i = 1; i <= n; i++) {       s[i] = s[i - 1] + len[i - 1];       scanf( %s , s[i]);       len[i] = strlen(s[i]);       int q = 1;       for (int j = 0; j < len[i];) {         int c = idx(s[i][j]);         if (d[q][c].to) {           for (int k = 0; k < d[q][c].len && j + k <= len[i]; k++)             if (s[i][j + k] != S[d[q][c].L + k]) {               int p = d[q][c].to;               d[q][c].to = ++xb;               int nq = xb;               if (j + k < len[i]) d[nq][idx(s[i][j + k])].to = ++xb;               d[nq][idx(S[d[q][c].L + k])].to = p;               if (j + k < len[i]) {                 d[nq][idx(s[i][j + k])].L = (&s[i][j + k]) - S;                 d[nq][idx(s[i][j + k])].len = len[i] - j - k;               }               d[nq][idx(S[d[q][c].L + k])].L = d[q][c].L + k;               d[nq][idx(S[d[q][c].L + k])].len = d[q][c].len - k;               d[q][c].len = k;               break;             }         } else {           d[q][c].L = (&s[i][j]) - S;           d[q][c].len = len[i] - j;           d[q][c].to = ++xb;         }         j += d[q][c].len;         q = d[q][c].to;       }       val[q]++;     }     dfs(1);     printf( %d n , dp[1][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j = 0, k = 0, l = 0, m = 0, n, t = 0, sum = 0, r = 0, q = 0, p = 0,                z = 0;   int a[2000005];   vector<int> v;   int main() {     ios_base::sync_with_stdio(false);     string s, f, g;     cin >> m >> f >> g;     n = g.size();     if (g[n - 1] ==  k )       t = 0;     else       t = 1;     if (t == 1) {       if (m < 30)         cout <<  12 ;       else if (m == 31)         cout <<  7 ;       else         cout <<  11 ;     } else {       if (m == 5 || m == 6)         cout <<  53 ;       else         cout <<  52 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n;   short ans = 0;   int main() {     cin >> a >> b;     while (b > 0) {       if (b == 1) {         ans = 0;         break;       }       if (b % a != 0) {         ans = 1;         break;       }       ++n;       b = b / a;     }     if (ans == 0) {       cout <<  YES  << endl;       cout << n - 1;     } else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2e5 + 17;   inline int sqr(int x) { return x * x; }   int main(void) {     int a[6];     for (int i = 0; i < 6; i++) cin >> a[i];     cout << sqr(a[0] + a[1] + a[2]) - sqr(a[0]) - sqr(a[2]) - sqr(a[4]);   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::ios;   using std::sort;   const int MAX = 1e3 + 2;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int n = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     cout << a[(n + 1) / 2] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int hardcode[11] = {0, 1, 0, 1, 2, 0, 2, 0, 1, 0, 1};   int get_sprague_1(int val) {     int tmp = val;     while (tmp % 4 == 0) {       tmp /= 4;     }     if (val <= 10) {       return hardcode[val];     } else if (tmp == 6 || (val % 4 == 0 && tmp % 2 == 1 && tmp != 3)) {       return 2;     } else {       return (val + 1) % 2;     }   }   int get_sprague_2(int val) {     if (val == 1) {       return 1;     } else if (val == 2) {       return 2;     } else {       return (val + 1) % 2;     }   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cin >> N >> K;     int xorv = 0;     if (K % 2 == 1) {       for (int a = 1; a <= N; a++) {         int x;         cin >> x;         xorv ^= get_sprague_1(x);       }     } else {       for (int a = 1; a <= N; a++) {         int x;         cin >> x;         xorv ^= get_sprague_2(x);       }     }     if (xorv == 0) {       cout <<  Nicky ;     } else {       cout <<  Kevin ;     }   }


#include <bits/stdc++.h>   using namespace std;   namespace zzc {   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   const int maxn = 2e5 + 5;   int ans = 0x3f3f3f3f;   char s[3][maxn];   int nxt[3][maxn], len[3], overlap[3][3];   void init(int id) {     for (int i = 2, j = 0; i <= len[id]; i++) {       while (j && s[id][i] != s[id][j + 1]) j = nxt[id][j];       if (s[id][i] == s[id][j + 1]) j++;       nxt[id][i] = j;     }   }   int kmp(int x, int y) {     int j = 0;     for (int i = 1; i <= len[x]; i++) {       while (j && s[x][i] != s[y][j + 1]) j = nxt[y][j];       if (s[x][i] == s[y][j + 1]) j++;       if (j == len[y]) return len[y];     }     return j;   }   int calc(int x, int y, int z) {     if (overlap[x][y] == len[y] && overlap[y][z] == len[z])       return len[x];     else if (overlap[x][y] == len[y])       return len[x] + len[z] - overlap[x][z];     else if (overlap[y][z] == len[z])       return len[x] + len[y] - overlap[x][y];     else       return len[x] + len[y] + len[z] - overlap[x][y] - overlap[y][z];   }   void work() {     for (int i = 0; i <= 2; i++)       scanf( %s , s[i] + 1), len[i] = strlen(s[i] + 1), init(i);     for (int i = 0; i <= 2; i++)       for (int j = 0; j <= 2; j++)         if (i != j) overlap[i][j] = kmp(i, j);     ans = min(ans, calc(0, 1, 2));     ans = min(ans, calc(0, 2, 1));     ans = min(ans, calc(1, 0, 2));     ans = min(ans, calc(1, 2, 0));     ans = min(ans, calc(2, 0, 1));     ans = min(ans, calc(2, 1, 0));     printf( %d n , ans);   }   }  // namespace zzc   int main() {     zzc::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int ct = 0, i, j;     map<char, int> mp1;     int len = s.length();     int bc, rc, gc;     gc = rc = bc = 0;     for (i = 0; i < len; i++) {       if (s[i] ==  R ) rc++;       if (s[i] ==  G ) gc++;       if (s[i] ==  B ) bc++;     }     if (gc > 0 && bc > 0 && rc > 0)       printf( BGR n );     else if (gc == 0) {       if (rc == 0)         printf( B );       else if (bc == 0)         printf( R );       else if (rc == 1 && bc == 1)         printf( G );       else if (rc > 1 && bc == 1)         printf( BG );       else if (bc > 1 && rc == 1)         printf( GR );       else         printf( BGR );     } else if (bc == 0) {       if (gc == 0)         printf( R );       else if (rc == 0)         printf( G );       else if (gc == 1 && rc == 1)         printf( B );       else if (rc > 1 && gc == 1)         printf( BG );       else if (gc > 1 && rc == 1)         printf( BR );       else         printf( BGR );     } else if (rc == 0) {       if (gc == 0)         printf( B );       else if (bc == 0)         printf( G );       else if (gc == 1 && bc == 1)         printf( R );       else if (bc > 1 && gc == 1)         printf( GR );       else if (gc > 1 && bc == 1)         printf( BR );       else         printf( BGR );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 1000000007;   int n, i, a, b, n1, n2;   struct str {     int a, b, t;   } s1[300005], s2[300005];   bool cmp1(str a, str b) { return a.a > b.a; }   bool cmp2(str a, str b) { return a.a < b.a; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d %d , &a, &b);       if (a < b)         s1[++n1] = (str){a, b, i};       else         s2[++n2] = (str){a, b, i};     }     if (n1 > n2) {       sort(s1 + 1, s1 + 1 + n1, cmp1);       printf( %d n , n1);       for (i = 1; i <= n1; i++) printf( %d  , s1[i].t);     } else {       sort(s2 + 1, s2 + 1 + n2, cmp2);       printf( %d n , n2);       for (i = 1; i <= n2; i++) printf( %d  , s2[i].t);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   void solve(int n) {     int m = 1;     while (n > 0) {       if (n & 1) v.push_back(m);       n >>= 1;       m++;     }     reverse(v.begin(), v.end());   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     solve(n);     for (auto it : v) {       cout << it <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MAXN = 100;   struct mtx {     int d[MAXN][MAXN];     int r, c;   };   mtx operator*(const mtx l, const mtx r) {     mtx res;     res.r = l.r;     res.c = r.c;     assert(l.c == r.r);     for (int i = 0; i < res.r; i++)       for (int j = 0; j < res.c; j++) {         int sm = 0;         for (int k = 0; k < l.c; k++) {           sm += 1ll * l.d[i][k] * r.d[k][j] % mod;           sm %= mod;         }         res.d[i][j] = sm;       }     return res;   }   void idmtx(mtx &m) {     assert(m.r == m.c);     for (int i = 0; i < m.r; i++) {       for (int j = 0; j < m.c; j++) {         m.d[i][j] = i == j;       }     }   }   mtx mtxpow(const mtx m, long long p) {     mtx r;     r.r = r.c = m.r;     idmtx(r);     mtx c = m;     for (; p; p >>= 1) {       if (p & 1) r = r * c;       c = c * c;     }     return r;   }   void printmtx(const mtx m) {     cout <<  MTX ----   << endl;     for (int i = 0; i < m.r; i++) {       for (int j = 0; j < m.c; j++) {         cout << m.d[i][j] <<    ;       }       cout << endl;     }   }   int main() {     long long n;     int m;     cin >> n >> m;     mtx rm;     rm.r = rm.c = m;     for (int i = 0; i < m; i++) {       for (int j = 0; j < m; j++) {         rm.d[i][j] = 0;         if (i == j) rm.d[i][j] += 1;         if (j == 0) {           rm.d[i][j] += i == m - 1 ? 1 : 0;         } else {           rm.d[i][j] += rm.d[i][j - 1];         }         rm.d[i][j] %= mod;       }     }     long long off = (n - 1) % m, k = (n - 1) / m;     mtx res = mtxpow(rm, k + 1);     cout << res.d[m - 1][off] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     long double s;     cin >> n >> s;     vector<long long> cnt(n);     for (long long i = 0; i < n - 1; ++i) {       long long u, v;       cin >> u >> v;       --u;       --v;       ++cnt[u];       ++cnt[v];     }     long long ans = 0;     for (long long i = 0; i < n; ++i) ans += (cnt[i] == 1);     cout << setprecision(20) << 2.0 * s / ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<int> s) {     for (int i = 0; i < s.size(); i++) cout << s[i] <<    ;     cout << endl;   }   const int INF = 1e9 + 7;   char next(char v) {     if (v ==  R ) return  L ;     if (v ==  L ) return  R ;     if (v ==  U ) return  D ;     if (v ==  D ) return  U ;   }   int now(char v) {     if (v ==  R ) return 1;     if (v ==  L ) return 3;     if (v ==  U ) return 0;     if (v ==  D ) return 2;   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<int> dp(n, INF);     dp[0] = 1;     vector<int> last(4, -1);     last[now(s[0])] = 0;     for (int i = 1; i < n; i++) {       int a = last[now(next(s[i]))];       int b = last[(now(s[i]) + 1) % 4];       int c = last[(now(s[i]) + 3) % 4];       int d = min(b, c);       last[now(s[i])] = i;       if (a == -1 && d == -1) {         dp[i] = 1;         continue;       }       if (a == -1) {         dp[i] = min(dp[i], dp[d] + 1);         continue;       }       if (d == -1) {         dp[i] = min(dp[i], dp[a] + 1);         continue;       }       dp[i] = min(dp[i], dp[max(a, d)] + 1);     }     cout << dp[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, n;   const int MOD = 1e9 + 7;   long long fac[1111111];   bool ok(int x) {     while (x) {       if (x % 10 == a || x % 10 == b) {         x /= 10;       } else         return 0;     }     return 1;   }   void init() {     fac[0] = fac[1] = 1;     for (int i = 2; i <= 1000000; i++) {       fac[i] = (fac[i - 1] * i) % MOD;     }   }   void gcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       gcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   long long inv(long long a, long long n) {     long long d, x, y;     gcd(a, n, d, x, y);     return d == 1 ? (x + n) % n : -1;   }   long long C(int n, int m) {     return fac[n] * inv(fac[m] * fac[n - m] % MOD, MOD) % MOD;   }   int main() {     init();     long long ans;     int len;     while (scanf( %d%d%d , &a, &b, &n) != EOF) {       ans = 0;       for (len = 0; len <= n; len++) {         if (ok(a * len + b * (n - len))) ans = (ans + C(n, len)) % MOD;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   bool vis[10005][10005], rev[10005];   struct E {     int nxt, to;   } e[MAXN];   int tot, head[MAXN];   inline void add(int x, int y) {     e[++tot] = (E){head[x], y};     head[x] = tot;   }   int opt[MAXN], X[MAXN], Y[MAXN], s[MAXN], m, n, q;   long long ans[MAXN];   void dfs(int x, int sum) {     int tmp = 0, i = x;     if (opt[i] == 1) {       if (vis[X[i]][Y[i]] == rev[X[i]])         tmp = 1, ++sum, ++s[X[i]], vis[X[i]][Y[i]] = !rev[X[i]];     }     if (opt[i] == 2) {       if (vis[X[i]][Y[i]] != rev[X[i]])         tmp = 1, --sum, --s[X[i]], vis[X[i]][Y[i]] = rev[X[i]];     }     if (opt[i] == 3) {       sum += m - s[X[i]] - s[X[i]];       rev[X[i]] ^= 1;       s[X[i]] = m - s[X[i]];     }     ans[i] = sum;     for (int i = head[x]; i; i = e[i].nxt) dfs(e[i].to, sum);     if (opt[x] == 1 && tmp) --sum, --s[X[i]], vis[X[i]][Y[i]] = rev[X[i]];     if (opt[x] == 2 && tmp) ++sum, ++s[X[i]], vis[X[i]][Y[i]] = !rev[X[i]];     if (opt[x] == 3)       sum -= m - s[X[i]] - s[X[i]], rev[X[i]] ^= 1, s[X[i]] = m - s[X[i]];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= q; ++i) {       scanf( %d%d , &opt[i], &X[i]);       if (opt[i] < 3) scanf( %d , &Y[i]);       if (opt[i] == 4)         add(X[i], i);       else         add(i - 1, i);     }     dfs(0, 0);     for (int i = 1; i <= q; ++i) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       int u = 1e9;       for (int a = 0; a <= 2; a++) {         for (int b = 0; b <= 2; b++) {           bool g = true;           int r = 0;           for (int i = 0; i < n; i++) {             bool f = false;             int m = 1e9;             for (int x = 0; x <= a; x++) {               for (int y = 0; y <= b; y++) {                 int s = v[i] - x - 2 * y;                 if (s >= 0 && s % 3 == 0) {                   f = true;                   m = min(m, s / 3);                 }               }             }             if (f)               r = max(r, a + b + m);             else               g = false;           }           if (g) u = min(u, r);         }       }       cout << u <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 5;   const long long INF64 = 1e18;   template <typename T>   string to_string(const vector<T>& v) {     string ret =  < ;     for (auto it : v) {       ret += to_string(it) +  ,  ;     }     ret.pop_back();     ret.pop_back();     ret +=  > ;     return ret;   }   void debug_print() { cerr << endl; }   template <typename T, typename... U>   void debug_print(T t, U... u) {     cerr <<     << to_string(t);     debug_print(u...);   }   const int N = 1e5 + 5;   void normalize(string& s, int m) {     reverse(s.begin(), s.end());     while (s.size() < m) s.push_back( 0 );     reverse(s.begin(), s.end());   }   string a, b;   int solve() {     if (a.size() == 1) {       return a[0] == b[0] ? 0 : a[0] > b[0] ? 1 : -1;     }     for (int i = 0; i < a.size() - 2; i++) {       if (a[i] == b[i]) continue;       int mx = min(a[i], b[i]);       a[i] -= mx;       b[i] -= mx;       if (a[i] >= 2) return 1;       if (b[i] >= 2) return -1;       if (a[i] > 0) {         a[i + 1]++;         a[i + 2]++;       }       if (b[i] > 0) {         b[i + 1]++;         b[i + 2]++;       }     }     if (a[a.size() - 2] != b[a.size() - 2]) {       return a[a.size() - 2] == b[a.size() - 2]  ? 0              : a[a.size() - 2] > b[a.size() - 2] ? 1                                                  : -1;     }     if (a.back() != b.back()) {       return a.back() == b.back() ? 0 : a.back() > b.back() ? 1 : -1;     }     return 0;   }   int main() {     cin >> a >> b;     if (a.size() > b.size())       normalize(b, a.size());     else       normalize(a, b.size());     int ans = solve();     if (ans == 0)       cout <<  =  << endl;     else if (ans == 1)       cout <<  >  << endl;     else       cout <<  <  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > v(n);     multiset<int> l, r;     for (int i = 0; i < n; i++) {       scanf( %d%d , &v[i].first, &v[i].second);       l.insert(v[i].first);       r.insert(v[i].second);     }     int ans = 0;     for (int i = 0; i < n; i++) {       l.erase(l.find(v[i].first));       r.erase(r.find(v[i].second));       ans = max(ans, *r.begin() - *--l.end());       l.insert(v[i].first);       r.insert(v[i].second);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r[305];   int main() {     int p, n;     cin >> p >> n;     int a[n + 5];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int sum = 0, c = 0, f = -1;     for (int i = 1; i <= n; i++) {       c = a[i] % p;       if (r[c] == 0) {         f = -1;         r[c]++;       } else {         f = i;         break;       }     }     cout << f << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 123;   const long long INF = (long long)1e18 + 123;   const int inf = (int)1e9 + 123;   const int MOD = (int)1e9 + 7;   void megaRandom() {     unsigned int FOR;     asm( rdtsc  :  =A (FOR));     srand(FOR);   }   int n;   vector<int> g[N];   long double res;   void dfs(int x, int pr = 0, int h = 1) {     if (h > 0) res += (1.0 / h);     for (auto to : g[x]) {       if (to == pr) continue;       dfs(to, x, h + 1);     }   }   int main() {     megaRandom();     cin >> n;     for (int i = 1, x, y; i < n; i++) {       cin >> x >> y;       g[x].push_back(y), g[y].push_back(x);     }     dfs(1);     cout << fixed << setprecision(6) << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000;   const int MOD = int(1E9) + 7;   int pow_mod(int b, int p) {     int ret = 1;     while (p) {       if (p & 1) ret = 1LL * ret * b % MOD;       b = 1LL * b * b % MOD;       p >>= 1;     }     return ret;   }   int P[MAXN + 5], S[MAXN + 5];   int l[MAXN + 5], r[MAXN + 5], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &l[i]);     for (int i = 1; i <= n; i++) scanf( %d , &r[i]);     for (int i = 1; i < n; i++) {       int len = max(0, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1);       int tmp = 1LL * pow_mod(r[i] - l[i] + 1, MOD - 2) *                 pow_mod(r[i + 1] - l[i + 1] + 1, MOD - 2) % MOD;       P[i] = (1 + MOD - 1LL * tmp * len % MOD) % MOD;     }     for (int i = 1; i < n; i++) S[i] = (P[i] + S[i - 1]) % MOD;     int ans = (3LL * S[n - 1] % MOD + 1) % MOD;     for (int i = 1; i + 2 < n; i++)       ans = (ans + 2LL * (S[n - 1] + MOD - S[i + 1]) % MOD * P[i] % MOD) % MOD;     for (int i = 1; i + 1 < n; i++) {       int len = max(0, min(r[i], min(r[i + 1], r[i + 2])) -                            max(l[i], max(l[i + 1], l[i + 2])) + 1);       int tmp = 1LL * pow_mod(r[i] - l[i] + 1, MOD - 2) % MOD *                 pow_mod(r[i + 1] - l[i + 1] + 1, MOD - 2) % MOD *                 pow_mod(r[i + 2] - l[i + 2] + 1, MOD - 2) % MOD;       int del = 1;       del = ((del + P[i]) % MOD + MOD - 1) % MOD;       del = ((del + P[i + 1]) % MOD + MOD - 1) % MOD;       del = (del + 1LL * tmp * len % MOD) % MOD;       ans = (ans + 2LL * del % MOD) % MOD;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int n, m, x[N], y[N], xx[N], yy[N], num[N][N], vis[N * N], cur, pre[N * N];   vector<int> v[N * N];   using pii = pair<int, int>;   vector<pair<int, pii>> process(vector<pair<int, pii>> q) {     sort(q.begin(), q.end());     vector<pair<int, pii>> ret;     for (int i = 0; i < int(q.size()); i++) {       int l = q[i].second.first, r = q[i].second.second, j = i + 1;       while (j < int(q.size()) && q[i].first == q[j].first) {         if (q[j].second.first > r) {           ret.push_back({q[i].first, {l, r}});           l = q[j].second.first;           r = q[j].second.second;         } else           r = max(r, q[j].second.second);         ++j;       }       ret.push_back({q[i].first, {l, r}});       i = j - 1;     }     return ret;   }   bool in(int a, pii y) { return a >= y.first && a <= y.second; }   bool check(int mid) {     mid *= 2;     vector<pair<int, pii>> a, b;     for (int i = 1; i <= n; i++) b.push_back({x[i], {y[i] - mid, y[i] + mid}});     for (int i = 1; i <= m; i++) a.push_back({yy[i], {xx[i] - mid, xx[i] + mid}});     a = process(a);     b = process(b);     for (int i = 0; i < int(a.size()); i++)       for (int j = 0; j < int(b.size()); j++) num[i][j] = -1;     int idx = 0;     for (int i = 0; i < n * m; i++) v[i].clear();     for (int i = 0; i < int(a.size()); i++) {       int lst = -1;       for (int j = 0; j < int(b.size()); j++)         if (in(a[i].first, b[j].second) && in(b[j].first, a[i].second)) {           num[i][j] = idx++;           if (lst != -1) v[lst].push_back(idx - 1), v[idx - 1].push_back(lst);           lst = idx - 1;         }     }     for (int i = 0; i < int(b.size()); i++) {       int lst = -1;       for (int j = 0; j < int(a.size()); j++)         if (in(a[j].first, b[i].second) && in(b[i].first, a[j].second)) {           if (lst != -1) v[lst].push_back(num[j][i]), v[num[j][i]].push_back(lst);           lst = num[j][i];         }     }     ++cur;     for (int i = 0; i < idx; i++)       if (vis[i] != cur) {         queue<int> q;         q.push(i);         pre[i] = -1;         vis[i] = cur;         while (!q.empty()) {           int nd = q.front();           q.pop();           for (auto &i : v[nd]) {             if (vis[i] != cur)               q.push(i), vis[i] = cur, pre[i] = nd;             else if (pre[nd] != i)               return 1;           }         }       }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int t1, t2;     for (int i = 1; i <= n; i++) cin >> t1 >> t2, x[i] = t1 + t2, y[i] = t1 - t2;     for (int i = 1; i <= m; i++)       cin >> t1 >> t2, xx[i] = t1 + t2, yy[i] = t1 - t2;     int l = 1, r = 1000000000, ans = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     if (ans == -1)       cout <<  Poor Sereja!  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace placeholders;   template <class T>   void mini(T &l, T r) {     l = min(l, r);   }   template <class T>   void maxi(T &l, T r) {     l = max(l, r);   }   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   const int N = 2E2 + 10;   int a[N][N];   void output(int n) {     printf( %d n , n);     for (int i = 0; i <= n; ++i) printf( %d%c , a[n][i],   n  [i < n]);   }   int main() {     int n;     scanf( %d , &n);     a[0][0] = 1;     a[1][0] = 0, a[1][1] = 1;     for (int i = 2; i <= n; ++i) {       for (int j = 0; j < n; ++j) a[i][j + 1] = a[i - 1][j];       for (int j = 0; j < n - 1; ++j) a[i][j] = a[i][j] + a[i - 2][j] & 1;     }     output(n);     output(n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct temp {     unordered_map<long long, int> mp;   };   int main() {     ios_base::sync_with_stdio(false);     long long sum = 0, ans = 0;     vector<int> val(26);     string str;     temp mpc[26];     for (int i = 0; i < 26; i++) cin >> val[i];     cin >> str;     for (int i = 0; i < str.size(); i++) {       int ch = str[i] -  a ;       if (mpc[ch].mp[sum] != 0) ans += mpc[ch].mp[sum];       sum += val[ch];       mpc[ch].mp[sum]++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string tos(int a) {     ostringstream os(  );     os << a;     return os.str();   }   const int MAXN = 1000000;   bool isp[MAXN + 100];   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i <= MAXN; ++i) isp[i] = 1;     isp[0] = isp[1] = 1;     for (int i = 2; i <= MAXN; ++i)       if (isp[i])         for (int j = i + i; j <= MAXN; j += i) isp[j] = 0;     int n;     while (cin >> n) {       int x, y;       for (int i = 2; i < MAXN; ++i) {         x = i, y = n - x;         if (!isp[x] && !isp[y]) break;       }       cout << x <<     << y <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<int> a(n + 1);     vector<int> primes = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29,                           31, 37, 41, 43, 47, 53, 59, 61, 67};     const int MAX = 70;     vector<int> cnt(MAX + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];       ++cnt[a[i]];     }     const int NS = 1 << primes.size();     vector<vector<int>> nw(MAX + 1, vector<int>(NS));     nw[0][0] = 1;     for (int i = 1; i <= MAX; ++i) {       int t = i;       int mask = 0;       for (int j = 0; j < primes.size(); ++j) {         mask <<= 1;         while (t % primes[j] == 0) {           mask ^= 1;           t /= primes[j];         }       }       long long E = 1;       for (int j = 1; j < cnt[i]; ++j) {         E = E * 2 % MOD;       }       long long O = 0;       if (cnt[i]) O = E;       for (int j = 0; j < NS; ++j) {         nw[i][j] = nw[i - 1][j] * E % MOD;         int pv = j ^ mask;         nw[i][j] = (nw[i][j] + nw[i - 1][pv] * O) % MOD;       }     }     long long ans = nw[MAX][0] - 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int x, y;     while (cin >> x >> y) {       while (true) {         bool ok = false;         if (x >= 2 && y >= 2) {           x -= 2;           y -= 2;           ok = true;         } else if (x >= 1 && y >= 12) {           x--;           y -= 12;           ok = true;         } else if (y >= 22) {           y -= 22;           ok = true;         }         if (!ok) {           cout <<  Hanako  << endl;           break;         }         ok = false;         if (y >= 22) {           y -= 22;           ok = true;         } else if (x >= 1 && y >= 12) {           x--;           y -= 12;           ok = true;         } else if (x >= 2 && y >= 2) {           x -= 2;           y -= 2;           ok = true;         }         if (!ok) {           cout <<  Ciel  << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void next_int(T &x) {     x = 0;     char c;     bool neg = false;     while (!isdigit(c = getchar()))       if (c ==  - ) neg = true;     do x = x * 10 + c - 48;     while (isdigit(c = getchar()));     if (neg) x = -x;   }   template <typename T>   inline void write_int(T x, char last = 0) {     if (x < 0) putchar( - ), x = abs(x);     char tmp[20];     int cnt = 0;     while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;     tmp[cnt] = x + 48;     for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);     if (last) putchar(last);   }   struct Line {     long long a, b;     Line(long long _a, long long _b) : a(_a), b(_b) {}   };   const int N = (int)2e5 + 5;   vector<Line> hull;   int n;   long long a[N], sum[N], sum2[N];   bool bad(Line l1, Line l2, Line l3) {     return (l1.b - l3.b) * (l2.a - l1.a) <= (l3.a - l1.a) * (l1.b - l2.b);   }   void add(Line x) {     while (((int)hull.size()) >= 2 &&            bad(hull[((int)hull.size()) - 2], hull[((int)hull.size()) - 1], x))       hull.pop_back();     hull.push_back(x);   }   long long getval(int pos, long long x) {     if (pos >= ((int)hull.size())) return (long long)1e18 + 7;     return hull[pos].a * x + hull[pos].b;   }   long long read(long long x) {     int lo = 0, hi = ((int)hull.size()) - 1, mid;     while (lo != hi) {       mid = (lo + hi) >> 1;       if (getval(mid, x) <= getval(mid + 1, x))         hi = mid;       else         lo = mid + 1;     }     return getval(lo, x);   }   int main() {     next_int(n);     for (int i = (1); i <= (n); ++i) {       next_int(a[i]);       sum[i] = sum[i - 1] + a[i];       sum2[i] = sum2[i - 1] + (long long)i * a[i];     }     add(Line(0, 0));     long long res = 0;     for (int i = (1); i <= (n); ++i) {       res = max(res, -read(-sum[i]) + sum2[i]);       add(Line(-i, sum2[i] - (long long)i * sum[i]));     }     write_int(res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T load() {     T r;     cin >> r;     return r;   }   template <typename T>   vector<T> loadMany(int n) {     vector<T> rs(n);     generate(rs.begin(), rs.end(), &load<T>);     return rs;   }   struct StrInt {     StrInt(const string& ref) : ref(ref) {}     int operator[](int i) const { return ref[i] -  a ; }     int size() const { return (int)ref.size(); }     const string& ref;   };   struct Trans {     explicit Trans(int k) : k(k), tab(k, -1), rev(k, -1) {}     Trans() : tab() {}     void add(int from, int to) {       tab[from] = to;       rev[to] = from;     }     int get(int i) { return tab[i]; }     bool loose(int i) { return tab[i] == -1; }     bool free(int j) { return rev[j] == -1; }     bool anyRangeFree(int j1, int j2) {       for (auto j = j1; j <= j2; ++j)         if (free(j)) return true;       return false;     }     int findRangeFree(int j1, int j2) {       for (auto j = j1; j <= j2; ++j)         if (free(j)) return j;       return -1;     }     bool defined() { return not tab.empty(); }     void fillWithAny() {       auto j = 0;       for (auto i = 0; i < k; ++i)         if (loose(i)) {           while (not free(j)) ++j;           add(i, j);         }     }     void print() {       for (auto i = 0; i < k; ++i) cout << (char)( a  + tab[i]);     }     int k;     vector<int> tab;     vector<int> rev;   };   Trans solveA(int i, int k, StrInt s, StrInt a, Trans&& trans) {     auto n = (int)s.size();     if (trans.loose(s[i]) and trans.free(a[i]))       trans.add(s[i], a[i]);     else if (trans.loose(s[i]))       return {};     ++i;     for (; i < n; ++i)       if (trans.loose(s[i]) and trans.anyRangeFree(a[i] + 1, k - 1))         return trans.add(s[i], trans.findRangeFree(a[i] + 1, k - 1)), move(trans);       else if (trans.loose(s[i]) and trans.free(a[i]))         trans.add(s[i], a[i]);       else if (trans.loose(s[i]))         return {};       else if (trans.get(s[i]) > a[i])         return move(trans);       else if (trans.get(s[i]) < a[i])         return {};     return move(trans);   }   Trans solveB(int i, int, StrInt s, StrInt b, Trans&& trans) {     auto n = (int)s.size();     if (trans.loose(s[i]) and trans.free(b[i]))       trans.add(s[i], b[i]);     else if (trans.loose(s[i]))       return {};     ++i;     for (; i < n; ++i)       if (trans.loose(s[i]) and trans.anyRangeFree(0, b[i] - 1))         return trans.add(s[i], trans.findRangeFree(0, b[i] - 1)), move(trans);       else if (trans.loose(s[i]) and trans.free(b[i]))         trans.add(s[i], b[i]);       else if (trans.loose(s[i]))         return {};       else if (trans.get(s[i]) < b[i])         return move(trans);       else if (trans.get(s[i]) > b[i])         return {};     return move(trans);   }   Trans solve(int k, StrInt s, StrInt a, StrInt b) {     auto n = s.size();     auto trans = Trans(k);     auto i = 0;     for (; i < n; ++i)       if (a[i] != b[i] and trans.loose(s[i]))         break;       else if (a[i] != b[i] and                (a[i] < trans.get(s[i]) and trans.get(s[i]) < b[i]))         return trans;       else if (a[i] != b[i] and a[i] == trans.get(s[i]))         return solveA(i, k, s, a, move(trans));       else if (a[i] != b[i] and b[i] == trans.get(s[i]))         return solveB(i, k, s, b, move(trans));       else if (trans.loose(s[i]) and trans.free(a[i]))         trans.add(s[i], a[i]);       else if (trans.loose(s[i]))         return {};       else if (not(a[i] <= trans.get(s[i]) and trans.get(s[i]) <= b[i]))         return {};     if (i == n) return trans;     if (trans.anyRangeFree(a[i] + 1, b[i] - 1))       return trans.add(s[i], trans.findRangeFree(a[i] + 1, b[i] - 1)),              move(trans);     auto ans1 = solveA(i, k, s, a, Trans(trans));     if (ans1.defined()) return ans1;     auto ans2 = solveB(i, k, s, b, move(trans));     return ans2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     auto t = load<int>();     while (t-- > 0) {       auto k = load<int>();       auto s = load<string>();       auto a = load<string>();       auto b = load<string>();       auto ans = solve(k, s, a, b);       if (ans.defined()) {         ans.fillWithAny();         cout <<  YES n ;         ans.print();         cout <<   n ;       } else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     string s;     cin >> s;     vector<int> freq(27, 0);     for (i = 0; i < s.length(); ++i) {       if (s[i] ==  B )         freq[26]++;       else if (s[i] >=  a  && s[i] <=  z )         freq[s[i] -  a ]++;     }     cout << (min(freq[26],                  min(freq[ u  -  a ],                      min(freq[ l  -  a ],                          min(freq[1],                              min(freq[ s  -  a ],                                  min(freq[0] >> 1, min(freq[ u  -  a ] >> 1,                                                        freq[ r  -  a ]))))))))          << endl;     return 0;   }


#include <bits/stdc++.h>   int edge[110][110];   int main() {     memset(edge, 0, sizeof(edge));     int n, u, v, w;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &w);       edge[i % n][(i + 1) % n] = edge[(i + 1) % n][i % n] = w;     }     scanf( %d%d , &u, &v);     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         if (i == j)           edge[i][j] = 0;         else if (edge[i][j] == 0)           edge[i][j] = 1000000;       }     for (int k = 0; k < n; ++k)       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j) {           if (i == k || j == k) continue;           if (edge[i][j] > edge[i][k] + edge[k][j])             edge[i][j] = edge[i][k] + edge[k][j];         }     printf( %d n , edge[u - 1][v - 1]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int m, n;       scanf( %d %d , &n, &m);       char s[n][m];       for (int i = 0; i < n; i++) {         scanf( %s , s[i]);       }       int ans = 0;       for (int i = 0; i < n; i++)         if (s[i][m - 1] ==  R ) ans++;       for (int i = 0; i < m; i++)         if (s[n - 1][i] ==  D ) ans++;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 105;   const long long mx1 = 1000001;   const long long mod = 1000000007;   vector<vector<long long> > edges;   void adds(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   long long mul(long long a, long long b) { return (long long)a * b % mod; }   void max_self(long long &a, long long b) { a = max(a, b); }   int main() {     int n, i, res = 0, inc1 = -1, lp = 0, rp = 0;     cin >> n;     string s;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ( ) {         lp++;       } else {         rp++;       }       if (rp > lp && inc1 == -1) {         inc1 = i;       } else if (lp == rp && inc1 != -1) {         res += i - inc1 + 1;         inc1 = -1;       }     }     if (lp != rp)       cout <<  -1 n ;     else {       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   double f(double z, double first) {     int k = 0;     double w;     while (first > 2 * z) {       w = z;       while (2 * w < first) w *= 2, k += 2;       first -= w;     }     if (first <= z)       return first;     else       return 2 * z - first;   }   int main() {     int b, c;     double a, lo, hi, mid, w;     int k;     while (scanf( %d %d , &c, &b) == 2) {       a = c;       if (c < b) {         printf( -1 n );       } else if (c == b) {         printf( %d n , b);       } else {         k = ((int)(floor(a / b + 1e-9) + 1e-9 - 1)) / 2;         hi = a / (2 * k + 1);         lo = a / (2 * k + 2);         k = 60;         while (k--) {           mid = (lo + hi) / 2.0;           w = f(mid, a);           if (w <= b)             lo = mid;           else             hi = mid;         }         printf( %.10lf n , mid);       }     }     return 0;   }


#include<bits/stdc++.h>   //#include<ext/pb_ds/assoc_container.hpp>   //#include<ext/pb_ds/tree_policy.hpp>   //#include <ext/pb_ds/trie_policy.hpp>   //using namespace __gnu_pbds;   using namespace std;   #define ll     long long int   #define ld    long double   #define mod             1000000007   #define inf             1e18   #define endl     n    #define pb     push_back   #define vi              vector<ll>   #define vs    vector<string>   #define pii             pair<ll,ll>   #define ump    unordered_map   #define mp     make_pair   #define pq_max          priority_queue<ll>   #define pq_min          priority_queue<ll,vi,greater<ll> >   #define all(n)    n.begin(),n.end()   #define ff     first   #define ss     second   #define mid(l,r)        (l+(r-l)/2)   #define bitc(n)   __builtin_popcount(n)   #define loop(i,a,b)  for(int i=(a);i<=(b);i++)   #define looprev(i,a,b)  for(int i=(a);i>=(b);i--)   #define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)   #define log(args...)  { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<   ;cout<<endl;    template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;}   template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}   vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}   void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {       cout << *it <<   =   << a << endl;       err(++it, args...);   }   //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;   //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;   void file_i_o()   {       ios_base::sync_with_stdio(0);        cin.tie(0);        cout.tie(0);       #ifndef ONLINE_JUDGE           freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);       #endif   }   int main(int argc, char const *argv[]) {       clock_t begin = clock();       file_i_o();       // Write your code here....       int t;       cin>>t;       while(t--){           int n;           cin>>n;           set<char> ts;           string s;           cin>>s;           int fl=0;           ts.insert(s[0]);           for(int i=1;i<n;i++){               if(s[i]==s[i-1]){                   continue;               }else{                   if(ts.find(s[i])==ts.end()){                       ts.insert(s[i]);                   }else{                       cout<< NO n ;                       fl=1;                       break;                   }               }           }           if(fl!=1){               cout<< YES n ;           }       }                          #ifndef ONLINE_JUDGE                  clock_t end = clock();         cout<<  n nExecuted In:  <<double(end - begin) / CLOCKS_PER_SEC*1000<<  ms ;       #endif        return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long double pii = 3.14159265359;   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 200001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T-- != 0) {       int N;       cin >> N;       vector<int> v(2);       for (int x = 0; x < (N); x++) {         int nb;         cin >> nb;         v[nb]++;       }       if (v[0] >= v[1]) {         cout << v[0] << nl;         for (int x = 0; x < (v[0]); x++) cout << 0 <<    ;       } else {         cout << v[1] - v[1] % 2 << nl;         for (int x = 0; x < (v[1] - v[1] % 2); x++) {           cout << 1 <<    ;         }       }       cout << nl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y, z;   };   double len[10000];   double sum[10000];   int n;   Point point[10001], potter;   double vp, vs;   double getDist(Point &a, Point &b) {     double x = a.x - b.x;     double y = a.y - b.y;     double z = a.z - b.z;     return sqrt(x * x + y * y + z * z);   }   double getGapConst(Point &tar, Point &vec) {     if (!(abs(vec.x - 0.0) < 1e-10)) return tar.x / vec.x;     if (!(abs(vec.y - 0.0) < 1e-10)) return tar.y / vec.y;     return tar.z / vec.z;   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i <= n; i++)       scanf( %lf %lf %lf , &point[i].x, &point[i].y, &point[i].z);     scanf( %lf %lf , &vp, &vs);     scanf( %lf %lf %lf , &potter.x, &potter.y, &potter.z);     if ((abs(point[0].x - potter.x) < 1e-10) &&         (abs(point[0].y - potter.y) < 1e-10) &&         (abs(point[0].z - potter.z) < 1e-10)) {       printf( YES n );       printf( 0 n );       printf( %lf %lf %lf n , potter.x, potter.y, potter.z);       return 0;     }     for (int i = 0; i < n; i++) {       len[i] = getDist(point[i], point[i + 1]);       if (i == 0)         sum[i] = 0;       else         sum[i] = sum[i - 1] + len[i - 1];     }     bool isFound = false;     for (int i = 0; i < n; i++) {       Point vec;       vec.x = point[i + 1].x - point[i].x;       vec.y = point[i + 1].y - point[i].y;       vec.z = point[i + 1].z - point[i].z;       double startRatio = sum[i] / len[i];       Point start;       start.x = point[i].x - startRatio * vec.x;       start.y = point[i].y - startRatio * vec.y;       start.z = point[i].z - startRatio * vec.z;       Point unit;       unit.x = vec.x / len[i];       unit.y = vec.y / len[i];       unit.z = vec.z / len[i];       double s = 0, e = 1, mid;       for (int q = 0; q < 40; q++) {         mid = (s + e) / 2;         Point tar;         tar.x = point[i].x + vec.x * mid;         tar.y = point[i].y + vec.y * mid;         tar.z = point[i].z + vec.z * mid;         double dist = getDist(tar, potter);         double reqTime = dist / vp;         Point snitch;         snitch.x = start.x + unit.x * vs * reqTime;         snitch.y = start.y + unit.y * vs * reqTime;         snitch.z = start.z + unit.z * vs * reqTime;         Point gap;         gap.x = snitch.x - point[i].x;         gap.y = snitch.y - point[i].y;         gap.z = snitch.z - point[i].z;         double gapConst = getGapConst(gap, vec);         if ((abs(mid - gapConst) < 1e-10)) {           isFound = true;           printf( YES n );           printf( %.10lf n , reqTime);           printf( %.10lf %.10lf %.10lf n , tar.x, tar.y, tar.z);           break;         } else if (mid > gapConst)           e = mid;         else           s = mid;       }       if (isFound) break;     }     if (!isFound) printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     unsigned long long ans = 0;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       if (x % 4 == 0) ans++;       if (i > 0) {         x += 10 * (s[i - 1] -  0 );         if (x % 4 == 0) ans += i;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     string s, s1;     cin >> s;     if (k == 0) {       cout << s;     } else if (n == 1) {       cout << 0 <<   n ;     } else {       if (s[0] !=  1 ) {         k--;       }       s1.push_back( 1 );       int i = 1;       while (k && i < n) {         if (s[i] !=  0 ) k--;         s1.push_back( 0 );         i++;       }       for (; i < n; i++) {         s1.push_back(s[i]);       }       cout << s1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define f(i,n) for(int i=0;i<n;i++)   #define endl (  n )   #define pb push_back   #define mp make_pair   #define pl pair<ll, ll>   #define vl vector<ll>   #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);      #define M 1000000007    const int N=2e5+2;    ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}   ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}   ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}   vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}   ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}   ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}   ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}   ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m      int fact[N];              void precalc(){               fact[0]=1;               for(int i=1;i<N;i++){                   fact[i]=mod_mul(fact[i-1],i,M);               }           }    long long mod(long long x){               return ((x%M + M)%M);           }           ll inv(ll x){               return expo(x,M-2,M);           }              ll divide(ll a, ll b){               return mod_mul(a,inv(b),M);           }              ll nCr(ll n, ll r){               return divide(fact[n],mod_mul(fact[r],fact[n-r],M));           }          int main()   {       fastIO     ll t;     cin>>t;     while(t--){    ll n; cin >> n;           ll arr[n], sum = 0;           for(auto &i : arr) cin >> i, sum += i;               ll cnt = sum - (sum / n * n);           cout << cnt * (n - cnt) << endl;                   }               }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 3;   const double EPS = (1e-7);   int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, v;     cin >> n >> m >> v;     int maxcon = ((n - 1) * (n - 2)) / 2 + 1;     if (m > maxcon or m < n - 1) {       cout << -1 << endl;     } else {       for (int i = 1; i <= n; i++) {         if (i != v) {           cout << i <<     << v <<    n ;           m--;         }       }       int pr = 1;       if (pr == v) {         pr++;       }       for (int i = 1; i <= n and m; i++) {         if (i != v and i != pr) {           for (int j = i + 1; j <= n and m; j++) {             if (j != v and j != pr) {               cout << i <<     << j << endl;               m--;             }           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 3e5;   int n;   int a[maxN];   int diff[maxN];   int ans[maxN];   vector<int> pos[maxN];   int main() {     int t;     while (scanf( %d , &t) != EOF)       for (int tt = 1; tt <= t; tt++) {         scanf( %d , &n);         for (int i = 0; i < n; i++) pos[i].clear();         for (int i = 0; i < n; i++) {           scanf( %d , &a[i]);           a[i]--;           pos[a[i]].push_back(i);         }         for (int i = 0; i < n; i++) diff[i] = -1;         for (int i = 0; i < n; i++)           if (!pos[i].empty()) {             diff[i] = max(*pos[i].begin(), n - 1 - *pos[i].rbegin());             for (int j = 0; j < pos[i].size() - 1; j++)               diff[i] = max(diff[i], pos[i][j + 1] - pos[i][j] - 1);           }         for (int i = 0; i < n; i++) ans[i] = -1;         for (int i = n - 1; i >= 0; i--)           if (diff[i] != -1) ans[diff[i]] = i + 1;         for (int i = 0; i < n; i++)           if (ans[i] != -1) {             int j = i;             while (j + 1 < n && (ans[j + 1] >= ans[i] || ans[j + 1] == -1))               ans[++j] = ans[i];             i = j;           }         for (int i = 0; i < n; i++)           printf( %d%c , ans[i], i < n - 1 ?     :   n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[2000];     memset(arr, 0, sizeof(arr));     string s;     cin >> s;     for (int i = 0; i < n; i++) arr[s[i]]++;     int m = 10000000;     for (int i = 65; i < 65 + k; i++) m = min(arr[i], m);     cout << m * k;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e1 + 5;   map<int, int> mp;   long long n, arr[MAXN], brr[MAXN], crr[MAXN];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       brr[i] = arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       crr[i] = arr[(i + 1) % n];     }     for (int i = 0; i < n; i++) {       mp[arr[i]] = crr[i];     }     for (int i = 0; i < n; i++) {       cout << mp[brr[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 1, B = 128;   int i, j, n, m, r, a[N], f[N][B];   int main() {     for (scanf( %d , &n); ++i <= n; scanf( %d , a + i))       ;     for (j = 1; j < B; ++j)       for (i = n; i; --i) f[i][j] = i + j + a[i] > n ? 1 : f[i + j + a[i]][j] + 1;     for (scanf( %d , &m); m--;) {       scanf( %d%d , &i, &j);       if (j < B)         printf( %d n , f[i][j]);       else {         for (r = 0; i <= n; i += j + a[i]) ++r;         printf( %d n , r);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (auto &ai : a) cin >> ai;     vector<pair<int, int>> v;     vector<bool> b(n);     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         sort(begin(v), end(v));         for (int k = 0; k < 3; k++)           if (!v.empty()) {             b[v.back().second] = true, v.pop_back();           }         v.clear();       } else {         v.emplace_back(a[i], i);       }     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         cout << cnt;         if (1 <= cnt) cout <<   popStack ;         if (2 <= cnt) cout <<   popQueue ;         if (3 <= cnt) cout <<   popFront ;         cout << endl;         cnt = 0;       } else {         if (b[i]) {           cnt++;           if (cnt == 1) cout <<  pushStack  << endl;           if (cnt == 2) cout <<  pushQueue  << endl;           if (cnt == 3) cout <<  pushFront  << endl;         } else {           cout <<  pushBack  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, kezd[200002], veg[200002], pos[200002], inv[200002], x, csa, csb;   vector<pair<pair<int, int>, int> > sz;   vector<int> v;   priority_queue<pair<int, int> > q;   void p() {     for (int i = 1; i <= n; i++) inv[pos[i]] = i;     for (int i = 1; i <= n; i++) cout << inv[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b, kezd[i] = a, veg[i] = b;       sz.push_back({{a, b}, i});     }     sort(sz.begin(), sz.end());     for (int i = 1; i <= n; i++) {       while (x < n && sz[x].first.first == i)         q.push({-sz[x].first.second, sz[x].second}), x++;       pos[i] = q.top().second, q.pop();     }     for (int i = 1; i <= n; i++) {       while (v.size() > 0 && veg[pos[v.back()]] < i) {         v.pop_back();       }       int a = kezd[pos[i]], b = veg[pos[i]];       if (v.size() > 0 && a <= v.back()) {         csa = i, csb = v.back();       }       while (v.size() > 0 && b >= veg[pos[v.back()]]) v.pop_back();       v.push_back(i);     }     if (!csa) {       cout <<  YES             <<   n ;       p();     } else {       cout <<  NO             <<   n ;       p();       swap(pos[csa], pos[csb]);       p();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     bool ok = 0;     int res = 0;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     if (c ==  - )       ok = 1;     else       res = c - 48;     while ((c = getchar()) >=  0  && c <=  9 )       res = (res << 3) + (res << 1) + (c - 48);     return ok ? ~res + 1 : res;   }   const int N = 4e5, M = 4e5;   int h[N], net[M], go[M], val[M], dep[N], ecnt = 1, cap[M];   void add(int u, int v, int w) {     go[++ecnt] = v;     cap[ecnt] = w;     net[ecnt] = h[u];     h[u] = ecnt;     swap(u, v);     go[++ecnt] = v;     cap[ecnt] = 0;     net[ecnt] = h[u];     h[u] = ecnt;   }   int s, t, n, m;   int bfs() {     memset(dep, 0, sizeof(dep));     queue<int> q;     q.push(s);     dep[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int e = h[u]; e; e = net[e]) {         int v = go[e];         if (!dep[v] && cap[e]) {           dep[v] = dep[u] + 1;           q.push(v);         }       }     }     return dep[t];   }   int dfs(int u, int flow) {     if (u == t) return flow;     int res = 0, tot = 0;     for (int e = h[u]; e; e = net[e]) {       int v = go[e];       if (dep[v] == dep[u] + 1 && cap[e]) {         res = dfs(v, min(flow, cap[e]));         tot += res;         cap[e] -= res;         cap[e ^ 1] += res;         flow -= res;       }     }     if (tot == 0) dep[u] = 0;     return tot;   }   int a[100000], v[100000];   int g;   int main() {     int cntg = 0;     int sum = 0;     int sum1 = 0;     s = N - 2;     t = N - 1;     n = read();     m = read();     g = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) {       v[i] = read();       if (a[i] == 0)         sum -= v[i], add(s, i, v[i]), sum1 += v[i];       else         add(i, t, v[i]);     }     for (int i = 1, w, k, u, op; i <= m; i++) {       op = read();       w = read();       k = read();       while (k--) {         u = read();         if (op)           add(u, i + n, 1e9);         else           add(i + n, u, 1e9);       }       int newop = read();       if (op == 0 && newop == 1) sum -= g;       if (op == 0)         add(s, i + n, w + (newop ? g : 0)), sum1 += w + (newop ? g : 0);       else         add(i + n, t, w + (newop ? g : 0));       if (op == 1) sum += w;     }     int ans = 0;     int res = 0;     while (bfs()) {       ans += dfs(s, 1e9);     }     printf( %d n , sum + sum1 - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   auto SEED = chrono::steady_clock::now().time_since_epoch().count();   mt19937 rng(SEED);   int main() {     int n, k;     cin >> n >> k;     int dist[n][n];     for (int i = (0); i < (n); i++) {       for (int j = (0); j < (n); j++) {         cin >> dist[i][j];       }     }     int t = 0;     int color[n];     long long int ans = 1ll << 60;     while (t < 5000) {       for (int i = (0); i < (n); i++) {         int tt = uniform_int_distribution<int>(1, n)(rng);         color[i] = tt & 1;       }       long long int dp[n][k];       for (int j = (0); j < (k + 1); j++) {         for (int i = (0); i < (n); i++) {           if (j) {             dp[i][j] = 1ll << 60;             for (int l = (0); l < (n); l++) {               if (color[i] + color[l] == 1) {                 dp[i][j] = min(dp[i][j], dp[l][j - 1] + dist[l][i]);               }             }           } else {             if (i)               dp[i][j] = 1ll << 60;             else               dp[i][j] = 0;           }         }       }       ans = min(ans, dp[0][k]);       t++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> q1;   vector<long long> q2;   long long n, x, y, a, b, k;   long long l = 1, r = n;   long long ans = 0;   long long mid;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool cmp(long long a, long long b) { return a > b; }   int main() {     int T;     scanf( %d , &T);     while (T--) {       q1.clear();       scanf( %lld , &n);       for (int i = 1; i <= n; i++) {         long long t;         scanf( %lld , &t);         q1.push_back(t);       }       scanf( %lld %lld %lld %lld %lld , &x, &a, &y, &b, &k);       long long gc = gcd(a, b);       long long lcm = a * b / gc;       sort(q1.begin(), q1.end(), cmp);       l = 1, r = n;       ans = 0;       while (l <= r) {         q2.clear();         mid = (l + r) / 2;         for (int j = 1; j <= mid; j++) {           if (j % lcm == 0) {             q2.push_back(x + y);           } else if (j % a == 0) {             q2.push_back(x);           } else if (j % b == 0) {             q2.push_back(y);           }         }         long long res = 0;         sort(q2.begin(), q2.end(), cmp);         for (int i = 0; i < q2.size(); i++) {           res += q1[i] * q2[i];         }         if (res >= k * 100) {           r = mid - 1;           ans = mid;         } else {           l = mid + 1;         }       }       if (!ans)         printf( -1 n );       else         printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string tmp;     map<string, vector<vector<string> > > m;     for (int i = 0; i < n; i++) {       cin >> tmp;       getline(cin, tmp);       bool f = false;       string name;       vector<string> v;       for (int j = 0; j < tmp.length(); j++) {         string s;         while (j < tmp.length() &&                ((tmp[j] >=  a  && tmp[j] <=  z ) ||                 (tmp[j] >=  0  && tmp[j] <=  9 ) || tmp[j] ==  T ))           s += tmp[j++];         if (!s.empty()) {           if (f)             v.push_back(s);           else {             name = s;             f = true;           }         }       }       m[name].push_back(v);     }     int V;     cin >> V;     map<string, string> v;     for (int i = 0; i < V; i++) {       string type, name;       cin >> type >> name;       v[name] = type;     }     int k;     scanf( %i n , &k);     for (int i = 0; i < k; i++) {       getline(cin, tmp);       string name;       int j = 0;       while (tmp[j] !=  ( ) {         if (tmp[j] !=    ) name += tmp[j];         j++;       }       vector<string> a;       while (j < tmp.length()) {         string s;         while (j < tmp.length() &&                ((tmp[j] >=  a  && tmp[j] <=  z ) ||                 (tmp[j] >=  0  && tmp[j] <=  9 ) || tmp[j] ==  T ))           s += tmp[j++];         if (!s.empty()) {           a.push_back(v[s]);         }         j++;       }       int ans = 0;       for (int k = 0; k < m[name].size(); k++) {         bool eq = true;         if (a.size() != m[name][k].size()) continue;         for (int j = 0; j < a.size(); j++)           if (a[j] != m[name][k][j] && m[name][k][j] !=  T ) {             eq = false;             break;           }         if (eq) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2 || y1 == y2)         cout << abs(x1 - x2) + abs(y1 - y2) << endl;       else         cout << abs(x1 - x2) + abs(y1 - y2) + 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char c = getchar();     x = 0;     while (!isdigit(c) && !isalpha(c)) c = getchar();     if (isalpha(c)) return void(x = c -  a );     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();   }   const int N = 5e5 + 5, SZ = 22;   int n, vv, ww;   int e, head[N], to[N << 1], val[N << 1], nxt[N << 1];   inline void add(int u, int v, int w) {     to[++e] = v;     val[e] = w;     nxt[e] = head[u];     head[u] = e;   }   inline void add_edge(int u, int v, int w) {     add(u, v, w);     add(v, u, w);   }   int sz[N], son[N], f[1 << 22 | 5], dep[N], Son, Max, ans[N], cur[N], s[N];   inline void dfs1(int u, int fa) {     sz[u] = 1;     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) {         int v = to[i], w = val[i];         s[v] = s[u] ^ (1 << w);         dep[v] = dep[u] + 1;         dfs1(v, u);         sz[u] += sz[v];         if (sz[v] > sz[son[u]]) son[u] = v;       }   }   inline void calc(int u, int fa) {     if (f[s[u]]) Max = max(Max, f[s[u]] + dep[u]);     for (int i = 1; i <= (1 << 21); i <<= 1)       if (f[i ^ s[u]]) Max = max(Max, f[i ^ s[u]] + dep[u]);     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) calc(to[i], u);   }   inline void update(int u, int fa) {     f[s[u]] = max(f[s[u]], dep[u]);     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) update(to[i], u);   }   inline void get_Max(int u, int fa) {     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa && to[i] != Son) {         calc(to[i], u);         update(to[i], u);       }   }   inline void clear(int u, int fa) {     f[s[u]] = 0;     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) clear(to[i], u);   }   inline void dfs2(int u, int fa, bool keep) {     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa && to[i] != son[u]) dfs2(to[i], u, false);     if (son[u]) dfs2(son[u], u, true);     Son = son[u];     f[s[u]] = max(f[s[u]], dep[u]);     get_Max(u, fa);     ans[u] = max(f[s[u]] - dep[u], Max - 2 * dep[u]);     for (int i = 1; i <= (1 << 21); i <<= 1)       ans[u] = max(ans[u], f[i ^ s[u]] - dep[u]);     for (int i = head[u]; i; i = nxt[i])       if (to[i] != fa) ans[u] = max(ans[u], ans[to[i]]);     Son = Max = 0;     if (!keep) clear(u, fa);   }   int main() {     read(n);     for (int uu = 2; uu <= n; uu++) {       read(vv);       read(ww);       add_edge(uu, vv, ww);     }     dfs1(1, 0);     dfs2(1, 0, 0);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, t, i, j, ii, a;     while (scanf( %d%d%d , &n, &k, &t) != EOF) {       for (i = 1; i <= n; i++) {         if ((i * k + 1) * 100 > t * n * k) break;       }       for (j = 0; j <= k; j++) {         a = (i - 1) * k + j;         if (n * k * t >= 100 * a && (a + 1) * 100 > t * n * k) {           for (ii = 1; ii <= i - 1; ii++) printf( %d  , k);           printf( %d , j);           for (ii = i + 1; ii <= n; ii++) printf(  %d , 0);           printf(  n );           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fat[200005];   void gerafat() {     fat[0] = 1;     for (long long i = 1; i < 200005; i++) {       fat[i] = (fat[i - 1] * i) % 1000000007;     }   }   long long modInv(long long a) {     long long v = 1;     long long e = 1000000007 - 2;     while (e) {       if (e % 2) {         v *= a;         v %= 1000000007;       }       e /= 2;       a *= a;       a %= 1000000007;     }     return v;   }   long long comb(int a, int b) {     if (a < b) return 0;     long long res =         ((fat[a] * modInv(fat[b])) % 1000000007 * modInv(fat[a - b])) %         1000000007;     return res;   }   int main() {     long long n, k;     cin >> n >> k;     gerafat();     vector<long long> num(0);     set<long long> sete;     vector<pair<long long, long long> > v(n, {0, 0});     for (long long i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v[i] = {a, b};       if (!sete.count(a)) {         num.push_back(a);         sete.insert(a);       }       if (!sete.count(b)) {         num.push_back(b);         sete.insert(b);       }       if (!sete.count(b + 1)) {         num.push_back(b + 1);         sete.insert(b + 1);       }     }     sort(num.begin(), num.end());     long long tam = num.size();     map<long long, long long> mapa;     for (long long i = 0; i < tam; i++) mapa[num[i]] = i;     vector<long long> pref(tam, 0);     for (int i = 0; i < n; i++) {       pref[mapa[v[i].first]]++;       pref[mapa[v[i].second + 1]]--;     }     for (int i = 1; i < tam; i++) pref[i] += pref[i - 1];     long long res = comb(pref[0], k) % 1000000007;     for (long long i = 1; i < tam; i++) {       res = (res + comb(pref[i], k)) % 1000000007;       res = (res + ((long long)(num[i] - num[i - 1] - 1) *                     comb(min(pref[i], pref[i - 1]), k)) %                        1000000007) %             1000000007;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r;     long long a;     map<int, long long> d;     int ans[300010];     int k = 0;     ans[0] = 1;     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a);       if (d[a] > r) {         ans[++k] = i;         r = i;       } else         d[a] = i;     }     if (k) {       printf( %i n%i , k, ans[0]);       for (int i = 1; i < k; ++i) printf(  %i n%i , ans[i], ans[i] + 1);       printf(  %i , n);     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed long long n, m, answer;   signed long long calc(signed long long n, signed long long m) {     signed long long answer;     if (m - n >= 1) {       answer = n;     } else {       answer =           m + (signed long long)ceil((sqrt(1.0L + 8.0L * (n - m)) - 1.0L) / 2.0L);     }     return answer;   }   int main() {     cin >> n >> m;     cout << calc(n, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, vis[4001], children, ans[4001];   long long v[4001], abcdefghijklmnopqrstuvwxyz[4001], d[4001];   int main() {     while (~scanf( %d , &n)) {       memset(vis, 0, sizeof(vis));       children = 0;       for (register int i = 1; i <= n; i++) {         scanf( %lld%lld%lld , &v[i], &d[i], &abcdefghijklmnopqrstuvwxyz[i]);       }       for (register int i = 1; i <= n; i++) {         if (vis[i]) {           continue;         }         ans[children++] = i;         register long long temp1 = v[i], temp2 = 0;         for (register int j = i + 1; j <= n; j++)           if (!vis[j]) {             abcdefghijklmnopqrstuvwxyz[j] -= temp1;             temp1--;             if (temp1 < 0) {               break;             }           }         for (register int j = i + 1; j <= n; j++) {           if (!vis[j]) {             abcdefghijklmnopqrstuvwxyz[j] -= temp2;           }           if (abcdefghijklmnopqrstuvwxyz[j] < 0 && !vis[j]) {             temp2 += d[j];             vis[j] = 1;           }         }       }       printf( %d n , children);       for (register int i = 0; i < children; i++) {         printf( %d%c , ans[i], i == children - 1 ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   const ll INF = 100000000000ll;   const int N = 200005;   const int prime = 31;   const ll mod = 1000000007;   const ld eps = 1e-5;   mt19937_64 strong_random(       chrono::system_clock::now().time_since_epoch().count());   ll n;   void input() { scanf( %lld , &n); }   void solve() {     vector<ll> divisors;     ll nval = n;     ll dv = 2;     while (dv * dv <= n) {       if (n % dv == 0) {         int cc = 0;         divisors.push_back(1);         while (n % dv == 0) {           n /= dv;           divisors.back() *= dv;         }       } else {         dv++;       }     }     if (n != 1) {       divisors.push_back(n);     }     int bitcnt = (int)(divisors).size();     pll ans = {nval, 1};     for (int i = 0; i < (1 << bitcnt); i++) {       ll a = 1, b = 1;       for (int j = 0; j < bitcnt; j++) {         if ((1 << j) & i) {           a *= divisors[j];         } else {           b *= divisors[j];         }       }       if (a < b) swap(a, b);       ans = min(ans, {a, b});     }     cout << ans.second <<     << ans.first << endl;   }   void precalc() {}   int main() {     precalc();     int testcases = 1;     for (int testId = 1; testId <= testcases; testId++) {       input();       solve();     }     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...);   }   vector<int> f, g;   void fdo(int k) {     if (k == 0) return;     vector<int> temp = f;     f.clear();     f.push_back(0);     for (auto it : temp) f.push_back(it);     bool flag = true;     int ch = 0;     for (int i = 0; i < g.size(); i++) {       if (abs(f[i] + g[i]) > 1) flag = false;     }     for (int i = 0; i < g.size(); i++) {       if (flag) {         f[i] = f[i] + g[i];       } else {         f[i] = f[i] - g[i];       }     }     g = temp;     for (int i = 0; i < f.size(); i++) {       assert(abs(f[i]) < 2);     }     assert(f[f.size() - 1] == 1);     assert(g[g.size() - 1] == 1);     fdo(k - 1);   }   int main() {     int n;     scanf( %d , &n);     f.push_back(0);     f.push_back(1);     if (n != 1)       g.push_back(-1);     else       g.push_back(1);     fdo(n - 1);     cout << f.size() - 1 << endl;     for (auto it : f) cout << it <<    ;     cout << endl;     cout << g.size() - 1 << endl;     for (auto it : g) cout << it <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int ans = 0;   bool ok = true;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void solve(int a) {     while (a % 2 == 0) {       a /= 2;       ans++;     }     while (a % 3 == 0) {       a /= 3;       ans++;     }     while (a % 5 == 0) {       a /= 5;       ans++;     }     if (a != 1) ok = false;   }   int main() {     scanf( %d%d , &a, &b);     int x = gcd(a, b);     a = a / x;     b = b / x;     solve(a);     solve(b);     if (ok)       printf( %d n , ans);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g;   int n;   int a = 0;   int b = 0;   int ans = 0;   bool used[200][200];   void dfs(int a, int b) {     used[a][b] = 1;     for (int i = max(0, n - a); i <= min(n, b); i++) {       if (!used[a + i - (n - i)][b - i + (n - i)]) {         dfs(a + i - n + i, b - i - i + n);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < 2 * n - 1; i++) {       int x;       scanf( %d , &x);       if (x <= 0)         b++;       else         a++;       g.push_back(abs(x));     }     sort(g.begin(), g.end());     for (int i = 0; i < 200; i++) {       for (int j = 0; j < 200; j++) {         used[i][j] = 0;       }     }     dfs(a, b);     for (int i = 0; i <= 2 * n - 1; i++) {       if (used[2 * n - 1 - i][i]) {         for (int j = 0; j < i; j++) {           ans -= g[j];         }         for (int j = i; j < g.size(); j++) {           ans += g[j];         }         printf( %d , ans);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   inline bool Min(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool Max(T &a, T b) {     return a < b ? (a = b, true) : false;   }   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline ll nl() {     ll a;     scanf( %lld , &a);     return a;   }   inline double nd() {     double a;     scanf( %lf , &a);     return a;   }   inline void pi(int a) { printf( %d  , a); }   inline void pl(ll a) { printf( %lld  , a); }   inline void pd(double a) { printf( %.12lf  , a); }   void solve() {     int n = ni();     vector<int> xs(n);     for (int i = 0; i < (int)(n); ++i) xs[i] = ni();     vector<int> cnt(n + 1);     vector<int> ans(n + 1);     for (int i = 0; i < n; i++) {       fill((cnt).begin(), (cnt).end(), 0);       int maxCnt = -1, maxNum = n;       for (int j = i; j < n; j++) {         cnt[xs[j]]++;         if (maxCnt <= cnt[xs[j]]) {           if (maxCnt < cnt[xs[j]] or (maxCnt == cnt[xs[j]] and xs[j] < maxNum))             maxNum = xs[j];           maxCnt = cnt[xs[j]];         }         ans[maxNum]++;       }     }     for (int i = 1; i <= n; i++) pi(ans[i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand((int)clock());     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   const int oo = 1000000007;   int n, k, m, a[10], lik[10], head[10], adj[10];   long long res;   bool fre[10], ok;   void make(int u, int v) {     m++;     adj[m] = v;     lik[m] = head[u];     head[u] = m;   }   void dfs(int u) {     fre[u] = false;     int i = head[u];     while (i != 0) {       int v = adj[i];       if (fre[v]) dfs(v);       i = lik[i];     }   }   bool check() {     m = 0;     memset(lik, 0, sizeof(lik));     memset(head, 0, sizeof(head));     memset(fre, 1, sizeof(fre));     for (long long i = 1; i <= k; i++) make(a[i], i);     dfs(1);     for (long long i = 1; i <= k; i++)       if (fre[i]) return false;     return true;   }   void att(int i) {     if (i > k) {       if (!ok) return;       if (check()) res++;       return;     }     for (long long x = 1; x <= k; x++)       if ((x != i) || (i == 1)) {         bool z = ok;         if (x == 1) ok = true;         a[i] = x;         att(i + 1);         ok = z;       };   }   int main() {     cin >> n >> k;     long long sum = 1;     for (long long i = 1; i <= n - k; i++) sum = (sum * (n - k)) % oo;     att(1);     cout << (res * sum) % oo;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r = 0, c = 0;     string str;     cin >> str;     if (str.length() > 2) {       for (int i = 0; i < str.length() - 2; i++) {         if (str[i] ==  Q ) {           for (int j = i + 1; j < str.length() - 1; j++) {             if (str[j] ==  A ) r++;             if (r > 0) {               for (int k = j + 1; k < str.length(); k++) {                 if (str[k] ==  Q ) {                   c++;                 }                 r = 0;               }             }           }         }       }     }     printf( %d , c);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   static constexpr ll oo = numeric_limits<ll>::max() / 2;   struct Node {     ll sm, mx;     Node() : sm{0}, mx{-oo} {}     Node(ll sm_, ll mx_) : sm{sm_}, mx{mx_} {}   };   struct LazySegmentTree {     vector<Node> tree;     vector<ll> mark;     int n;     LazySegmentTree(vector<ll> a) : n(a.size()) {       tree.resize(4 * n);       mark.resize(4 * n, oo);       build(1, 0, n - 1, a);     }     Node merge(Node lhs, Node rhs) {       Node node;       node.sm = lhs.sm + rhs.sm;       node.mx = max(lhs.mx, rhs.mx);       return node;     }     void build(int v, int tl, int tr, const vector<ll>& a) {       if (tl == tr) {         tree[v] = {a[tl], a[tl]};         return;       }       int tm = (tl + tr) / 2;       build(2 * v, tl, tm, a);       build(2 * v + 1, tm + 1, tr, a);       tree[v] = merge(tree[2 * v], tree[2 * v + 1]);     }     void push(int v, int l, int r) {       if (mark[v] == oo) {         return;       }       int m = (l + r) / 2;       mark[2 * v] = mark[v];       tree[2 * v].mx = mark[v];       tree[2 * v].sm = (m - l + 1) * mark[v];       mark[2 * v + 1] = mark[v];       tree[2 * v + 1].mx = mark[v];       tree[2 * v + 1].sm = (r - m) * mark[v];       mark[v] = oo;     }     Node query(int l, int r) { return query(1, 0, n - 1, l, r); }     Node query(int v, int tl, int tr, int l, int r) {       if (l > r) return Node();       if (tl == l && tr == r) {         return tree[v];       }       push(v, tl, tr);       int tm = (tl + tr) / 2;       Node sl = query(2 * v, tl, tm, l, min(tm, r));       Node sr = query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);       return merge(sl, sr);     }     void assign(int lo, int hi, ll x) { return update(1, 0, n - 1, lo, hi, x); }     void update(int v, int tl, int tr, int l, int r, ll x) {       if (l > r) return;       if (tl == l && tr == r) {         mark[v] = x;         tree[v].mx = x;         tree[v].sm = (r - l + 1) * x;         return;       }       push(v, tl, tr);       int tm = (tl + tr) / 2;       update(2 * v, tl, tm, l, min(tm, r), x);       update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x);       tree[v] = merge(tree[2 * v], tree[2 * v + 1]);     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<ll> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<ll> b(n - 1);     for (int i = 0; i < n - 1; ++i) cin >> b[i];     vector<ll> t(n, 0);     for (int i = 1; i < n; ++i) {       t[i] = t[i - 1] + b[i - 1];     }     vector<ll> s(n);     s[0] = t[0];     for (int i = 1; i < n; ++i) s[i] = s[i - 1] + t[i];     auto sum = [&](const int lo, const int hi) -> ll {       if (lo > hi) return 0;       ll ret = s[hi];       if (lo > 0) {         ret -= s[lo - 1];       }       return ret;     };     vector<ll> c(n);     for (int i = 0; i < n; ++i) c[i] = a[i] - t[i];     LazySegmentTree tree(move(c));     int q;     cin >> q;     while (q-- > 0) {       char op;       cin >> op;       if (op ==  + ) {         int pos, x;         cin >> pos >> x;         if (x == 0) continue;         --pos;         auto node = tree.query(pos, pos);         ll d = node.mx + x;         int lo = pos, hi = n;         while (hi - lo > 1) {           int m = lo + (hi - lo) / 2;           node = tree.query(lo, m);           if (node.mx >= d) {             hi = m;           } else {             lo = m;           }         }         tree.assign(pos, lo, d);       } else {         int lo, hi;         cin >> lo >> hi;         --lo;         --hi;         auto node = tree.query(lo, hi);         cout << node.sm + sum(lo, hi) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long ca;     cin >> ca;     while (ca--) {       long long n, i, j, k, l, r, m;       cin >> l >> r >> m;       for (i = l; i <= r; i++) {         long long x1, x2;         x1 = m / i;         if (m % i != 0)           x2 = m / i + 1;         else           x2 = m / i;         long long y1 = m - (x1 * i);         long long y2 = (x2 * i) - m;         long long lim = r - l;         if (y1 <= lim && x1 > 0) {           cout << i <<     << l + y1 <<     << l << endl;           break;         }         if (y2 <= lim && x2 > 0) {           cout << i <<     << l <<     << l + y2 << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   bool ck(int k) {     double ss = (double)k * m, cnt = 1;     double C = 1, A = k, B = 1;     for (long long lp = 1; cnt < n && ss > 0 && A >= 0; lp++) {       C = C * A / B;       A--;       B++;       double y = min(C, ss / lp);       cnt += y;       ss -= y * lp;     }     return cnt >= n;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       int l = 0, r = n;       while (l + 1 < r) {         int mid = (l + r) / 2;         if (ck(mid))           r = mid;         else           l = mid + 1;       }       if (ck(l))         printf( %d n , l);       else         printf( %d n , r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, sz[1005], lab[1005], cur = 1, cur2, f = 1;   vector<int> v[1005];   int getsz(int node, int p) {     sz[node] = 1;     for (int u : v[node]) {       if (u != p) sz[node] += getsz(u, node);     }     return sz[node];   }   int find(int node, int p) {     for (int u : v[node]) {       if (u != p && sz[u] > n / 2) return find(u, node);     }     return node;   }   void assign(int node, int p) {     if (f)       lab[node] = cur++;     else       lab[node] = (++cur2) * cur;     printf( %d %d %d n , node, p, lab[node] - lab[p]);     for (int u : v[node]) {       if (u != p) assign(u, node);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     getsz(1, 0);     int c = find(1, 0);     getsz(c, 0);     vector<pair<int, int> > ch;     for (int u : v[c]) ch.push_back({sz[u], u});     sort(ch.begin(), ch.end());     reverse(ch.begin(), ch.end());     for (auto p : ch) {       assign(p.second, c);       if (f && n <= 3 * cur && 3 * cur <= 2 * n) f = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   struct CHT {     vector<long long> m, c;     bool decSlope, askMin;     CHT(bool slopeType, bool queryType) {       decSlope = slopeType;       askMin = queryType;     }     bool throwLine(long long l1, long long l2, long long l3) {       if (decSlope) {         if (askMin)           return (double)(c[l2] - c[l1]) * (m[l1] - m[l3]) >=                  (double)(c[l3] - c[l1]) * (m[l1] - m[l2]);         else           return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);       } else {         if (!askMin)           return (c[l2] - c[l1]) * (m[l1] - m[l3]) >=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);         else           return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=                  (c[l3] - c[l1]) * (m[l1] - m[l2]);       }     }     void add(long long M, long long C) {       m.push_back(M);       c.push_back(C);       while (((long long)m.size()) >= 3 &&              throwLine(((long long)m.size()) - 3, ((long long)m.size()) - 2,                        ((long long)m.size()) - 1)) {         m.erase(m.end() - 2);         c.erase(c.end() - 2);       }     }     long long f(long long i, long long x) { return m[i] * x + c[i]; }     long long query(long long x) {       long long l = 0, r = ((long long)m.size()) - 1, ret;       if (askMin)         ret = inf;       else         ret = -inf;       while (l <= r) {         long long m1 = l + (r - l) / 3;         long long m2 = r - (r - l) / 3;         if (f(m1, x) == f(m2, x)) {           ret = f(m1, x);           r = m2 - 1;           l = m1 + 1;         } else if (f(m1, x) < f(m2, x)) {           if (askMin) {             ret = f(m1, x);             r = m2 - 1;           } else {             ret = f(m2, x);             l = m1 + 1;           }         } else {           if (askMin) {             ret = f(m2, x);             l = m1 + 1;           } else {             ret = f(m1, x);             r = m2 - 1;           }         }       }       return ret;     }   };   const long long lim = 2e5 + 10;   long long a[lim];   long long s[lim];   long long p[lim];   int main() {     CHT machine(true, false);     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       p[i] = p[i - 1] + a[i];       s[i] = s[i - 1] + i * a[i];     }     long long ans = s[n], ans2 = s[n];     for (long long i = n; i; i--) {       machine.add(i, -p[i]);       long long tmp = machine.query(a[i]) + p[i] - i * a[i] + s[n];       ans = max(ans, tmp);     }     CHT machine2(false, false);     for (long long i = 1; i <= n; i++) {       machine2.add(i, -p[i - 1]);       long long tmp = machine2.query(a[i]) + p[i - 1] - i * a[i] + s[n];       ans2 = max(ans2, tmp);     }     cout << max(ans, ans2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long mod = 998244353;   inline long long add(long long v1, long long v2) {     v1 += v2;     if (v1 >= mod) v1 -= mod;     if (v1 < 0) v1 += mod;     return v1;   }   inline long long mul(long long v1, long long v2) { return v1 * v2 % mod; }   inline long long mypow(long long v, long long t) {     long long res = 1;     while (t) {       if (t & 1) res = res * v % mod;       v = v * v % mod;       t >>= 1;     }     return res;   }   inline void bye() {     puts(  );     exit(0);   }   const int N = 303030;   int a[N];   long long cnt[N];   long long dp[8][N];   long long fac[N], ifac[N];   long long C(int v1, int v2) {     if (v1 < v2) return 0;     return mul(fac[v1], mul(ifac[v2], ifac[v1 - v2]));   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       cnt[a[i]]++;     }     fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = fac[i - 1] * i % mod;     }     ifac[N - 1] = mypow(fac[N - 1], mod - 2);     for (int i = N - 2; i >= 0; i--) {       ifac[i] = ifac[i + 1] * (i + 1) % mod;     }     for (int i = 1; i < N; i++) {       for (int j = i * 2; j < N; j += i) {         cnt[i] += cnt[j];       }     }     for (int i = 1; i < 8; i++) {       for (int j = N - 1; j >= 1; j--) {         dp[i][j] = C(cnt[j], i);         for (int k = j * 2; k < N; k += j) {           dp[i][j] = add(dp[i][j], -dp[i][k]);         }       }       if (dp[i][1]) {         printf( %d n , i);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200000], t[200000];   int equi(int a, int b, int c, int d) {     bool x = 1;     for (int i = 0; i <= b - a; i++) {       x &= (s[i + a] == t[i + c]);     }     if (x) return 1;     if (b <= a) return 0;     int n = b - a + 1;     if (n % 2 == 1) return 0;     if (equi(a, a + n / 2 - 1, c, c + n / 2 - 1)) {       if (equi(a + n / 2, b, c + n / 2, d)) return 1;     }     if (equi(a, a + n / 2 - 1, c + n / 2, d)) {       if (equi(a + n / 2, b, c, c + n / 2 - 1)) return 1;     }     return 0;   }   int main() {     int n = 0;     scanf( %s , s);     scanf( %s , t);     while (s[n++] !=   0 )       ;     n--;     if (equi(0, n - 1, 0, n - 1))       printf( YES );     else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> all;   vector<int> zu;   vector<int> de;   int main() {     string x;     cin >> x;     int y = x.size() / 2;     cout << x;     for (size_t i = 0; i < y; i++) {       swap(x[i], x[x.size() - i - 1]);     }     cout << x << endl;     return 0;   }


/*           ----@sagittarius_k2-----       Created by Ritesh Ranjan       ->       */       #define fio                                ios_base::sync_with_stdio(false);       cin.tie(NULL);                          cout.tie(NULL);       #include <bits/stdc++.h>   #include <iostream>   #include <set>   #include <algorithm>   #include <iterator>           using namespace std;       #define int long long int       #define M 1000000007       using namespace std;       signed main()   {       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           int a[n+1], b[n+1];           for(int i=1; i<=n; i++)           {               cin>>a[i];               b[i]=a[i];           }           sort(a+1, a+n+1);              int ans=-1, min_no=-1;           for(int i=1; i<=n; i++)           {               int c=0;               while(i<n && a[i]==a[i+1])               {                   i++;                   c++;               }               if(c==0)               {                   min_no=a[i];                   break;               }           }           for(int i=1; i<=n; i++)           {               if(b[i]==min_no)               {                   ans=i;                   break;               }           }           cout<<ans<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 100010, INF = 0x3f3f3f3f;   int n, m, deg, s[MAXN], p[MAXN];   int main() {     scanf( %d , &n);     for (int a = 0; a < n; a++) {       scanf( %d , &s[a]);       p[s[a]] = a;     }     int ult = -1, cnt = 0, res = 0;     for (int a = 1; a <= n; a++) {       if (p[a] > ult) {         cnt++;         ult = p[a];         res = max(cnt, res);       } else {         cnt = 1;         ult = p[a];       }     }     printf( %d n , n - res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[4111];   int f[4111], v[4111][4111];   int main() {     int n, m;     cin >> n >> m;     while (m--) {       int a, b;       cin >> a >> b;       if (a > b) swap(a, b);       g[a].push_back(b);       f[a]++;       f[b]++;       v[a][b] = v[b][a] = 1;     }     int ans = -1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         for (int k = j + 1; k < g[i].size(); k++) {           int a = g[i][j], b = g[i][k];           int w = f[a] + f[b] + f[i] - 6;           if (v[a][b]) {             if (ans == -1)               ans = w;             else               ans = min(ans, w);           }         }       }     }     cout << ans;   }