#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 500;   const long long INF = 1e9;   const long long BITS = 64;   const long double EPS = 1e-9;   void bye() {     cout <<   n ;     exit(0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long all = 0;     vector<string> g(n);     vector<int> pref(n);     for (int i = 0; i < n; i++) {       cin >> g[i];       all += (long long)(g[i]).size();       pref[i] = (i) ? pref[i - 1] + (long long)(g[i]).size() + 1                     : (long long)(g[i]).size();     }     all += n - 1;     vector<vector<bool> > eq(n, vector<bool>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         eq[i][j] = g[i] == g[j];       }     }     vector<vector<int> > dp(n, vector<int>(n));     for (int i = n - 1; i >= 0; i--) {       for (int j = n - 1; j >= 0; j--) {         if (eq[i][j]) {           if (i + 1 < n && j + 1 < n) {             dp[i][j] = dp[i + 1][j + 1] + 1;           } else {             dp[i][j] = 1;           }         }       }     }     long long ans = all;     for (int i = 0; i < n; i++) {       for (int k = 0; i + k < n; k++) {         long long now = (pref[i + k] - ((i) ? pref[i - 1] + 1 : 0));         long long cnt = 1;         for (int j = i + k + 1; j + k < n; j++) {           if (dp[i][j] > k) {             cnt++;             j += k;           }         }         if (cnt > 1) {           ans = min(ans, all + cnt * (k + 1) - now * cnt);         }       }     }     cout << ans;     bye();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 50;   const int MOD = 1e9 + 9;   int n, k, a, b, c, d, m, L, R, tot = 1;   pair<int, int> cities[MAXN];   struct TreeNode {     int x, l, r, lson, rson;     pair<int, int> v;   } tree[MAXN];   int newNode(int &x) { return x = ++tot; }   pair<int, int> calc(pair<int, int> l, pair<int, int> r) {     return {l.second + r.second, max(l.first + r.second, l.second + r.first) + 1};   }   void build(int o, int l, int r) {     int max_y = -1, max_id = l;     for (int i = l; i <= r; i++) {       if (cities[i].second > max_y) {         max_y = cities[i].second;         max_id = i;       }     }     tree[o].l = cities[l].first;     tree[o].r = cities[r].first;     tree[o].x = cities[max_id].first;     if (l < max_id) build(newNode(tree[o].lson), l, max_id - 1);     if (max_id < r) build(newNode(tree[o].rson), max_id + 1, r);     tree[o].v = calc(tree[tree[o].lson].v, tree[tree[o].rson].v);   }   pair<int, int> query(int o, int l, int r) {     if (o == 0 || l > tree[o].r || r < tree[o].l) return {-1, 0};     if (l <= tree[o].l && tree[o].r <= r) return tree[o].v;     if (r < tree[o].x) return query(tree[o].lson, l, r);     if (l > tree[o].x) return query(tree[o].rson, l, r);     return calc(query(tree[o].lson, l, r), query(tree[o].rson, l, r));   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < k; i++) {       scanf( %d%d , &cities[i].first, &cities[i].second);     }     scanf( %d%d%d%d , &a, &b, &c, &d);     for (int i = k; i < n; i++) {       cities[i].first = (1LL * a * cities[i - 1].first + b) % MOD;       cities[i].second = (1LL * c * cities[i - 1].second + d) % MOD;     }     sort(cities, cities + n);     tree[0].v = {-1, 0};     build(1, 0, n - 1);     scanf( %d , &m);     while (m--) {       scanf( %d%d , &L, &R);       printf( %d n , query(1, L, R).second);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     cin >> n;     vector<pair<int, int>> v;     for (i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       v.push_back(make_pair(x, y));     }     int ans = 0;     int total = 0;     bool u, d, l, r;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (v[i].first > v[j].first && v[i].second == v[j].second) d = true;         if (v[i].first < v[j].first && v[i].second == v[j].second) u = true;         if (v[i].second > v[j].second && v[i].first == v[j].first) l = true;         if (v[i].second < v[j].second && v[i].first == v[j].first) r = true;       }       if (d && u && l && r) total++;       d = false;       u = false;       l = false;       r = false;     }     cout << total;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500 + 7;   long long mod = 1e9 + 7;   bool solve(long long l, long long r, long long mx, long long& ans) {     if (r - l + 1 > mx) {       return false;     }     ans = -l + 1;     return true;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       string s;       cin >> s;       int x = 0, y = 0, mnx = 0, mxx = 0, mny = 0, mxy = 0;       long long ansX = 1, ansY = 1;       for (auto i : s) {         x += i ==  D ;         x -= i ==  U ;         y += i ==  R ;         y -= i ==  L ;         mnx = min(x, mnx);         mxx = max(x, mxx);         mny = min(y, mny);         mxy = max(y, mxy);         long long tmpX, tmpY;         if (solve(mnx, mxx, n, tmpX) && solve(mny, mxy, m, tmpY)) {           ansX = tmpX, ansY = tmpY;           continue;         }         break;       }       cout << ansX <<     << ansY <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   long long ar[1000001] = {};   long long n, a, b;   void shift(long long l, long long r) {     for (long long f = (long long)(l); f <= (long long)(r - 1); ++f) {       swap(ar[f], ar[f + 1]);     }   }   void Do(long long x, long long y) {     long i = 0;     for (long long f = (long long)(1); f <= (long long)(x); ++f) {       shift(i, i + a - 1);       i += a;     }     for (long long f = (long long)(1); f <= (long long)(y); ++f) {       shift(i, i + b - 1);       i += b;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(15);     cin >> n >> a >> b;     for (long long f = (long long)(0); f <= (long long)(n - 1); ++f) {       ar[f] = f + 1;     }     for (long long f = (long long)(0); f <= (long long)(1000000); ++f) {       long long tmp = round((n - a * f) / b);       if (tmp * b + f * a == n && tmp >= 0) {         Do(f, tmp);         for (long long f = (long long)(0); f <= (long long)(n - 1); ++f) {           cout << ar[f] <<    ;         }         return 0;       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   template <class T1, class T2, class T3, class T4>   inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {     printsp(x1), printsp(x2), printsp(x3), println(x4);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     int n, first;     cin >> n >> first;     if (n == 5 and first == 5) {       puts( >...v );       puts( v.<.. );       puts( ..^.. );       puts( >.... );       puts( ..^.< );       puts( 1 1 );       return 0;     }     if (n == 3 and first == 2) {       puts( >vv );       puts( ^<. );       puts( ^.< );       puts( 1 3 );       return 0;     }     for (int i = 1; i <= n; i += 2) {       putchar( v );       for (int j = 2; j <= n / 2; j++) {         if (j & 1)           putchar( . );         else           putchar( < );       }       for (int j = n / 2 + 1; j <= n; j++) {         putchar( < );       }       puts(  );       for (int j = 1; j <= n / 2; j++) putchar( > );       for (int j = n / 2 + 1; j < n; j++) {         if (j & 1)           putchar( . );         else           putchar( > );       }       puts( ^ );     }     print(1, 1);     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void rc(char &a) {     a = 0;     register int x = getchar_unlocked();     while (x <  a  || x >  z ) {       if (x ==   n ) {         a =  0 ;         return;       }       x = getchar_unlocked();     }     a = x;   }   const int maxn = 100100;   int key;   int main() {     ios_base::sync_with_stdio(0);     string ans =   ;     char cur;     while (true) {       rc(cur);       if (cur ==  0 ) break;       if (cur ==  a ) {         if (key == 0)           ans +=  a ;         else if (key == 1) {           ans +=  a ;           key = 2;         } else {           ans +=  a ;         }       } else {         if (key == 1)           ans += (cur - 1);         else if (key == 0) {           ans += (cur - 1);           key = 1;         } else {           ans += cur;         }       }     }     if (key == 0) {       ans = ans.substr(0, ans.size() - 1) +  z ;       cout << ans <<   n ;       return 0;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string tostring(const T &x) {     ostringstream os;     os << x;     return os.str();   }   inline int toint(const string &s) {     istringstream is(s);     int x;     is >> x;     return x;   }   inline int todecimal(string s) {     int a = 0;     for (int i = 0; i < s.size(); i++) a = 2 * a + (s[i] -  0 );     return a;   }   inline string tobinary(int a) {     string s;     while (a != 0) {       s = (char)(a % 2 +  0 ) + s;       a >>= 1;     }     return s;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   inline int isvowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 1;     return 0;   }   inline int isprime(int a) {     for (int i = 2; i * i <= a; i++)       if (!(a % i)) return 0;     return 1;   }   inline void inp(int &n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     n = n * sign;   }   const int dx4[4] = {0, 0, 1, -1};   const int dy4[4] = {1, -1, 0, 0};   const int dx8[8] = {0, 0, 1, 1, 1, -1, -1, -1};   const int dy8[8] = {1, -1, 0, 1, -1, 1, 0, -1};   class node {    public:     int x, y, z;     node(int a, int b, int c) {       x = a;       y = b;       z = c;     }   };   bool operator<(const node &a, const node &b) { return a.x > b.x; }   bool compare(const node &a, const node &b) { return a.x < b.x; }   int n, m;   void solve() {     cout << n + m - 1 << endl;     for (int i = 0; i < m; i++) {       cout << 1 <<     << i + 1 << endl;     }     for (int i = 0; i < n - 1; i++) {       cout << i + 2 <<     << 1 << endl;     }   }   void input() { cin >> n >> m; }   int main() {     int testcase = 1;     for (int i = 0; i < testcase; i++) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> v;   int res;   int countOne(vector<vector<int>> &a, int i, int j) {     int res = 0;     if (a[i][j] == 1) res++;     if (a[i + 1][j] == 1) res++;     if (a[i][j + 1] == 1) res++;     if (a[i + 1][j + 1] == 1) res++;     return res;   }   void switchZeroOne(vector<vector<int>> &a, int i, int j) {     int cnt = countOne(a, i, j);     while (cnt != 0) {       if (cnt == 4) {         v[res].push_back(i);         v[res].push_back(j);         v[res].push_back(i);         v[res].push_back(j + 1);         v[res].push_back(i + 1);         v[res].push_back(j);         res++;         a[i][j] = 0;         a[i][j + 1] = 0;         a[i + 1][j] = 0;         cnt = 1;       } else if (cnt == 1) {         int switchZero = 0;         for (int x = i; x < i + 2; x++) {           for (int y = j; y < j + 2; y++) {             if (a[x][y] == 1) {               a[x][y] = 0;               v[res].push_back(x);               v[res].push_back(y);             } else if (switchZero < 2) {               a[x][y] = 1;               v[res].push_back(x);               v[res].push_back(y);               switchZero++;             }           }         }         res++;         cnt = 2;       } else if (cnt == 2) {         int switchOne = 0;         for (int x = i; x < i + 2; x++) {           for (int y = j; y < j + 2; y++) {             if (a[x][y] == 0) {               a[x][y] = 1;               v[res].push_back(x);               v[res].push_back(y);             } else if (switchOne < 1) {               a[x][y] = 0;               v[res].push_back(x);               v[res].push_back(y);               switchOne++;             }           }         }         res++;         cnt = 3;       } else if (cnt == 3) {         for (int x = i; x < i + 2; x++) {           for (int y = j; y < j + 2; y++) {             if (a[x][y] == 1) {               a[x][y] = 0;               v[res].push_back(x);               v[res].push_back(y);             }           }         }         res++;         cnt = 0;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, m;     string s;     cin >> t;     while (t--) {       cin >> n >> m;       vector<vector<int>> a(n + 1, vector<int>(m + 1));       for (int i = 1; i <= n; i++) {         cin >> s;         for (int j = 1; j <= m; j++) {           a[i][j] = s[j - 1] -  0 ;         }       }       v = vector<vector<int>>(50000);       res = 0;       if (n > 2) {         for (int i = 1; i <= n - 2; i++) {           for (int j = 1; j <= m - 1; j++) {             if (a[i][j] == 1 && a[i][j + 1] == 1) {               v[res].push_back(i);               v[res].push_back(j);               v[res].push_back(i);               v[res].push_back(j + 1);               v[res].push_back(i + 1);               v[res].push_back(j);               res++;               a[i][j] = 0;               a[i][j + 1] = 0;               a[i + 1][j] ^= 1;             } else if (a[i][j] == 1) {               v[res].push_back(i);               v[res].push_back(j);               v[res].push_back(i + 1);               v[res].push_back(j);               v[res].push_back(i + 1);               v[res].push_back(j + 1);               res++;               a[i][j] = 0;               a[i + 1][j] ^= 1;               a[i + 1][j + 1] ^= 1;             } else if (a[i][j + 1] == 1) {               v[res].push_back(i);               v[res].push_back(j + 1);               v[res].push_back(i + 1);               v[res].push_back(j);               v[res].push_back(i + 1);               v[res].push_back(j + 1);               res++;               a[i][j + 1] = 0;               a[i + 1][j] ^= 1;               a[i + 1][j + 1] ^= 1;             }           }         }         for (int j = 1; j <= m - 1; j += 2) {           switchZeroOne(a, n - 1, j);         }         if (m % 2 == 1) switchZeroOne(a, n - 1, m - 1);       } else {         for (int j = 1; j <= m - 2; j++) {           for (int i = 1; i <= n - 1; i++) {             if (a[i][j] == 1 && a[i + 1][j] == 1) {               v[res].push_back(i);               v[res].push_back(j);               v[res].push_back(i);               v[res].push_back(j + 1);               v[res].push_back(i + 1);               v[res].push_back(j);               res++;               a[i][j] = 0;               a[i][j + 1] ^= 1;               a[i + 1][j] = 0;             } else if (a[i][j] == 1) {               v[res].push_back(i);               v[res].push_back(j);               v[res].push_back(i);               v[res].push_back(j + 1);               v[res].push_back(i + 1);               v[res].push_back(j + 1);               res++;               a[i][j] = 0;               a[i][j + 1] ^= 1;               a[i + 1][j + 1] ^= 1;             } else if (a[i + 1][j] == 1) {               v[res].push_back(i);               v[res].push_back(j + 1);               v[res].push_back(i + 1);               v[res].push_back(j);               v[res].push_back(i + 1);               v[res].push_back(j + 1);               res++;               a[i][j + 1] ^= 1;               a[i + 1][j] = 0;               a[i + 1][j + 1] ^= 1;             }           }         }         for (int i = 1; i <= n - 1; i += 2) {           switchZeroOne(a, i, m - 1);         }         if (n % 2 == 1) switchZeroOne(a, n - 1, m - 1);       }       cout << res <<   n ;       for (int i = 0; i < res; i++) {         for (int j = 0; j < v[i].size(); j++) {           cout << v[i][j] <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, d, v;   vector<long long> res;   void solve() {     cin >> x >> d;     res.clear();     v = 1;     for (int j = 0; j <= 30; j++) {       if ((1 << j) & x) {         for (int k = 1; k <= j; k++) res.push_back(v);         v += d + 1;         res.push_back(v);         v += d + 1;       }     }     cout << res.size() <<   n ;     for (int i = 0; i < res.size(); i++) cout << res[i] <<    ;     cout <<   n ;   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, big, small, counter = 0, y, b = 0;     cin >> x;     int a[x];     for (int i = 0; i < x; i++) {       cin >> y;       a[i] = y;     }     big = max_element(a, a + x) - a;     for (int i = 0; i < big; i++) {       swap(a[big - i], a[big - 1 - i]);       counter++;     }     small = min_element(a, a + x) - a;     for (int i = 0; i < x; i++) {       if (a[i] == a[small]) small = i;     }     for (int i = x - 1; i > small; i--, b++) {       swap(a[small + b], a[small + 1 + b]);       counter++;     }     cout << counter;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   int main() {     long long m, n, i;     while (cin >> n >> m) {       long long a[n + 1], b;       a[0] = 0;       for (i = 0; i < n; i++) {         cin >> a[i + 1];         a[i + 1] += a[i];       }       for (i = 0; i < m; i++) {         cin >> b;         auto j = lower_bound(a, a + n, b) - a;         cout << j <<     << b - a[j - 1] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long n, m, p;   int a[200003], b[200003];   int main() {     multiset<int> st;     scanf( %I64d%I64d%I64d , &n, &m, &p);     int k = 0;     for (int i = (1); i <= (n); i++) {       scanf( %d , &a[i]);     }     for (int i = (1); i <= (m); i++) {       scanf( %d , &b[i]);     }     int ans[200001], anscnt = 0;     for (int i = (1); i <= (p); i++) {       int q = i;       st.clear();       multiset<int>::iterator it;       if (q + (m - 1) * p <= n) {         for (int j = (1); j <= (m); j++) st.insert(b[j]);         for (int j = (0); j <= (m - 2); j++) {           it = st.find(a[j * p + q]);           if (it != st.end()) {             st.erase(it);           } else {             st.insert(-1 * a[j * p + q]);           }         }       }       while (q + (m - 1) * p <= n) {         it = st.find(a[(m - 1) * p + q]);         if (it != st.end()) {           st.erase(it);         } else {           st.insert(-1 * a[(m - 1) * p + q]);         }         if (st.empty()) ans[++anscnt] = q;         it = st.find(a[q] * -1);         if (it != st.end()) {           st.erase(it);         } else {           st.insert(a[q]);         }         q += p;       }     }     sort(ans + 1, ans + anscnt + 1);     printf( %d n , anscnt);     for (int i = (1); i <= (anscnt); i++) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n], ans = 0;     for (int i = (0); i < (n); ++i) cin >> a[i];     for (int l = (0); l < (n); ++l) {       long long k = 2LL << (int)log2(a[l]), sum = 0;       for (int r = (l + 2); r < (n); ++r) {         sum += a[r - 1];         if (sum >= k) break;         if ((a[l] >= a[r]) and (a[l] ^ a[r]) == sum) ++ans;       }     }     for (int r = (n)-1; r >= (0); --r) {       long long k = 2LL << (int)log2(a[r]), sum = 0;       for (int l = (r - 1) - 1; l >= (0); --l) {         sum += a[l + 1];         if (sum >= k) break;         if ((a[l] < a[r]) and (a[r] ^ a[l]) == sum) ++ans;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 1;     cin >> n;     for (int i = 0; i < n; i++) {       if (a <= 2) {         cout <<  a ;         a++;       } else if (a > 2 && a <= 4) {         cout <<  b ;         a++;       } else {         cout <<  a ;         a = 2;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename T>   bool mycomp(T x, T y) {     return (x == y);   }   bool paircomp(const pair<long long int, long long int> &x,                 const pair<long long int, long long int> &y) {     return x.second < y.second;   }   void solve() {     long long int n, m;     cin >> n >> m;     string s[n];     for (long long int i = 0; i < n; i++) cin >> s[i];     long long int labx, laby;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         if (s[i][j] ==  L ) labx = i, laby = j;       }     }     bool vis[n][m];     memset(vis, false, sizeof(vis));     queue<pair<long long int, long long int> > qe;     qe.push({labx, laby});     vis[labx][laby] = true;     while (!qe.empty()) {       long long int x = qe.front().first, y = qe.front().second;       qe.pop();       if (s[x][y] !=  L ) {         long long int no = 0;         if (x && s[x - 1][y] ==  . ) no++;         if (x < n - 1 && s[x + 1][y] ==  . ) no++;         if (y && s[x][y - 1] ==  . ) no++;         if (y < m - 1 && s[x][y + 1] ==  . ) no++;         if (no <= 1)           s[x][y] =  + , vis[x][y] = true;         else           continue;       }       if (x && !vis[x - 1][y] && s[x - 1][y] !=  # ) qe.push({x - 1, y});       if (x < n - 1 && !vis[x + 1][y] && s[x + 1][y] !=  # ) qe.push({x + 1, y});       if (y && !vis[x][y - 1] && s[x][y - 1] !=  # ) qe.push({x, y - 1});       if (y < m - 1 && !vis[x][y + 1] && s[x][y + 1] !=  # ) qe.push({x, y + 1});     }     for (long long int i = 0; i < n; i++) {       cout << s[i] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 301;   string s[N][N];   vector<pair<pair<int, int>, pair<int, int> > > f(int n, int k) {     vector<pair<pair<int, int>, pair<int, int> > > ans;     pair<int, int> f0 = {1, 0}, f1 = {0, 1};     int i, j, l;     for (i = 0; i < s[0][0].size(); ++i)       if (s[0][0][i] ==  0 )         ans.push_back({{0, 0}, f0});       else         ans.push_back({{0, 0}, f1});     for (i = 1; i < k; ++i)       for (l = 0; l < s[0][i].size(); ++l) {         ans.push_back({{0, i}, {0, 0}});         if (s[0][i][l] ==  0 )           ans.push_back({{0, 0}, f0});         else           ans.push_back({{0, 0}, f1});       }     for (i = 1; i < n; ++i)       for (l = 0; l < s[i][0].size(); ++l) {         ans.push_back({{i, 0}, {0, 0}});         if (s[i][0][l] ==  0 )           ans.push_back({{0, 0}, f0});         else           ans.push_back({{0, 0}, f1});       }     for (i = 1; i < n; ++i)       for (j = 1; j < k; ++j)         for (l = 0; l < s[i][j].size(); ++l)           if (s[i][j][l] ==  0 ) {             ans.push_back({{i, j}, {i, 0}});             if (i != 1) ans.push_back({{i, 0}, f0});           } else {             ans.push_back({{i, j}, {0, j}});             if (j != 1) ans.push_back({{0, j}, f1});           }     return ans;   }   int main() {     int i, j, k, n, p, l;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (i = 0; i < n; ++i)       for (j = 0; j < k; ++j) {         cin >> s[i][j];         for (l = 0; l < s[i][j].size() / 2; ++l)           swap(s[i][j][l], s[i][j][s[i][j].size() - l - 1]);       }     vector<pair<pair<int, int>, pair<int, int> > > ans1, ans2;     ans1 = f(n, k);     for (i = 0; i < n; ++i)       for (j = 0; j < k; ++j) cin >> s[i][j];     ans2 = f(n, k);     cout << ans1.size() + ans2.size() << endl;     for (i = 0; i < ans1.size(); ++i)       cout << ans1[i].first.first + 1 <<     << ans1[i].first.second + 1 <<                << ans1[i].second.first + 1 <<     << ans1[i].second.second + 1            <<   n ;     for (i = ans2.size() - 1; i >= 0; --i)       cout << ans2[i].second.first + 1 <<     << ans2[i].second.second + 1 <<                << ans2[i].first.first + 1 <<     << ans2[i].first.second + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long mod = 1e9 + 7;   unsigned long long ncr(long long int n, long long int k) {     unsigned long long res = 1;     if (k > n - k) k = n - k;     for (int i = 0; i < k; ++i) {       res *= (n - i);       res /= (i + 1);       res = res;     }     return res;   }   bool prime(unsigned long long num) {     bool flag = true;     for (unsigned long long i = 2; i * i <= num; i++) {       if (num % i == 0) {         flag = false;         break;       }     }     return flag;   }   long long ipow(long long base, long long exp) {     long long result = 1;     for (;;) {       if (exp & 1) {         result *= base;         result = result % mod;       }       exp >>= 1;       if (!exp) break;       base *= base;       base = base % mod;     }     return result % mod;   }   long long abs(long long a, long long b) {     if ((a - b) > 0)       return (a - b);     else       return (b - a);   }   long long MOD = 998244353;   long long add(long long a, long long b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;     return a;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long der(int k) {     long long res = 0;     long long fact = 1;     for (int i = 2; i <= k; i++) fact *= i;     int s = 1;     long long j = 1;     for (int i = 2; i <= k; i++) {       j = j * i;       long long first = (fact / j) * s;       res += first;       s = s * -1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     set<int> one, z;     int len = s.length();     for (int i = 0; i < len; i++) {       if (s[i] ==  0 )         z.insert(i + 1);       else         one.insert(i + 1);     }     vector<vector<int>> subs;     vector<int> sub;     while (true) {       if (z.empty()) break;       auto it = z.begin();       sub.push_back(*it);       int val = *it;       z.erase(it);       while (!z.empty()) {         auto it1 = one.lower_bound(val);         if (it1 == one.end()) break;         it = z.lower_bound(*it1);         if (it == z.end()) break;         int val1 = *it1;         val = *it;         sub.push_back(val1);         one.erase(it1);         sub.push_back(val);         z.erase(it);       }       subs.push_back(sub);       sub.clear();     }     if (!one.empty()) {       cout <<  -1 ;       return 0;     } else {       cout << subs.size() << endl;       for (int i = 0; i < subs.size(); i++) {         cout << subs[i].size() <<    ;         for (int j = 0; j < subs[i].size(); j++) {           cout << subs[i][j] <<    ;         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int h;   const int mx = 2e5 + 5;   vector<int> a(mx);   void eval1() {     cout << 0;     int x = 1, y = 1;     for (int i = 1; i <= h; i++) {       for (int j = 0; j < a[i]; j++) {         cout <<     << x;         y++;       }       x = y;     }     cout << endl;   }   void eval2() {     cout << 0;     int x = 1, y = 1, z = 1;     for (int i = 1; i <= h; i++) {       int p = a[i] / 2, q = a[i] - p;       vector<int> cand;       if (p) {         for (int j = 0; j < p; j++) {           cout <<     << x;           z++;           cand.push_back(z);         }         x = cand[0];       }       if (q) {         cand.clear();         for (int j = 0; j < q; j++) {           cout <<     << y;           z++;           cand.push_back(z);         }         if (p == 0) x = cand[0];         y = cand[0];       }     }     cout << endl;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> h;     for (int i = 0; i <= h; i++) cin >> a[i];     int vio = -1;     for (int i = 0; i < h; i++)       if (a[i] > 1 && a[i + 1] > 1) {         vio = i;         break;       }     if (vio == -1) {       cout <<  perfect  << endl;       return 0;     }     cout <<  ambiguous  << endl;     eval1();     eval2();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 10;   set<int> s[M];   int n, p[M];   bool check(int x) {     vector<int> b;     while (x) {       b.push_back(x % 10);       x /= 10;     }     if (b.size() > n) return false;     for (int i = 0; i < b.size(); i++)       if (s[p[i]].find(b[i]) == s[p[i]].end()) return false;     return true;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       p[i] = i;       for (int j = 0; j < 6; j++) {         int x;         cin >> x;         s[i].insert(x);       }     }     for (int x = 1;; x++) {       int fnd = false;       for (int i = 0; i < n; i++) p[i] = i;       do {         if (check(x)) fnd = true;       } while (next_permutation(p, p + n));       if (!fnd) return cout << x - 1 << endl, 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[220000];   int s[220000];   int g[220000];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , s + i, g + i);       a[i] = s[i] + g[i];     }     for (int i = 0; i < n - 1; ++i) a[i + 1] = min(a[i + 1], a[i] + 1);     for (int i = n - 1; i > 0; --i) a[i - 1] = min(a[i - 1], a[i] + 1);     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (a[i] < s[i]) {         printf( -1 n );         return 0;       }       ans += a[i] - s[i];     }     printf( %lld n , ans);     for (int i = 0; i < n; ++i) printf( %d  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];     int maxCap = b[0], curCap = b[0];     for (int i = 1; i < n; ++i) {       curCap = curCap - a[i] + b[i];       maxCap = max(maxCap, curCap);     }     cout << maxCap <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void read(Tp &x) {     static char c;     static bool neg;     x = 0, c = getchar(), neg = false;     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = true;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (neg) {       x = -x;     }   }   const int N = 100 + 5;   int k, n = 0;   int mp[N][N];   inline int C(int n, int m) {     if (m == 2) {       return n * (n - 1) / 2;     } else if (m == 3) {       return n * (n - 1) * (n - 2) / 6;     } else {       return -1;     }   }   int main() {     read(k);     for (; C(n, 3) <= k; ++n)       ;     --n;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         mp[i][j] = mp[j][i] = 1;       }     }     k -= C(n, 3);     while (k > 0) {       int t = 0;       for (; C(t, 2) <= k; ++t)         ;       --t;       ++n;       for (int i = 1; i <= t; ++i) {         mp[n][i] = mp[i][n] = 1;       }       k -= C(t, 2);     }     printf( %d n , n);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         putchar( 0  + mp[i][j]);       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 3;   long long n, ans, sz[N], up[N], down[N];   vector<long long> q[N];   void dfs1(long long v, long long p) {     sz[v] = 1;     for (auto i : q[v]) {       if (i != p) {         dfs1(i, v);         sz[v] += sz[i];         down[v] += down[i] + sz[i];       }     }   }   void dfs2(long long v, long long p) {     if (p != -1) {       up[v] = down[p] + up[p] - (down[v] + sz[v]) + (sz[1] - sz[v]);     }     ans = max(ans, down[v] + up[v] + n);     for (auto i : q[v]) {       if (i != p) {         dfs2(i, v);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       q[x].push_back(y);       q[y].push_back(x);     }     dfs1(1, -1);     dfs2(1, -1);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   struct T {     int l, r, i;     bool operator<(T const& other) {       return (l == other.l ? r < other.r : l < other.l);     }   };   int con[MAX][2];   pair<int, int> num[2 * MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k, l, r;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> l >> r;       num[i * 2] = {l, 1};       num[i * 2 + 1] = {r, 2};     }     sort(num, num + 2 * n);     int c = 0, a = 0;     for (int i = 0; i < 2 * n; i++) {       bool go = true;       if (num[i].second == 1)         a++;       else         go = false, a--;       if (a == k && go) con[c][0] = num[i].first;       if (a == k - 1 && !go) con[c][1] = num[i].first, c++;     }     cout << c << endl;     for (int i = 0; i < c; i++) cout << con[i][0] <<     << con[i][1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   char BUF_I[1048576], *S_I = BUF_I, *T_I = BUF_I;   struct Input {     Input() {}     inline Input &operator>>(char &c) {       return (c = ((S_I == T_I) &&                            (T_I = (S_I = BUF_I) + fread(BUF_I, 1, 1048576, stdin),                             S_I == T_I)                        ? EOF                        : *S_I++),               *this);     }     template <class T>     inline Input &operator>>(T &S_I) {       S_I = 0;       char c;       while (*this >> c, c < 48 || c > 57)         ;       while (S_I = S_I * 10 + c - 48, *this >> c, c > 47 && c < 58)         ;       return *this;     }     inline int Getint() {       char c;       register int S_I = 0;       register bool w = false;       while (*this >> c, c == 45 && (w = true), c < 48 || c > 57)         ;       while (S_I = S_I * 10 + c - 48, *this >> c, c > 47 && c < 58)         ;       return w ? -S_I : S_I;     }   } tin;   char BUF_O[262144], *S_O = BUF_O, *Limit_O = BUF_O + 262144;   struct Output {     ~Output() { Flush(); }     inline int Flush() {       fwrite(BUF_O, 1, S_O - BUF_O, stdout);       S_O = BUF_O;       return 0;     }     inline Output &operator<<(const char &c) {       if (S_O == Limit_O) Flush();       return (*S_O++ = c, *this);     }     template <class T>     inline Output &operator<<(T x) {       static char Stack[25];       static int Top;       if (x < (Top = 0)) *this <<  - , x = -x;       do {         Stack[++Top] = x % 10 + 48;       } while (x /= 10);       while (Top) (*this) << Stack[Top--];       return *this;     }   } tout;   int n, a[1005][1005];   int main() {     tin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) a[i][j] = (i + j - 2) % (n - 1) + 1;     for (int i = 1; i <= n; i++) {       a[i][n] = a[n][i] = a[i][i];       a[i][i] = 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) tout << a[i][j] <<    ;       tout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c1, c2, c3, c4, n, m, i, kol1, kol, ans, ans1;   int main() {     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     long long a[n + 1], b[m + 1];     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= m; i++) cin >> b[i];     for (i = 1; i <= n; i++) {       long long ans = 0;       if (a[i] * c1 <= c2)         ans += a[i] * c1;       else         ans += c2;       kol += ans;     }     kol = min(c3, kol);     for (i = 1; i <= m; i++) {       long long ans1 = 0;       if (b[i] * c1 <= c2)         ans1 += b[i] * c1;       else         ans1 += c2;       kol1 += ans1;     }     kol1 = min(c3, kol1) + kol;     cout << min(kol1, c4);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   const long long maxn = (long long)4e5 + 5;   const long long mod = 1000000007;   const long long inf = 0x3f3f3f3f;   long long a[maxn], b[maxn], n, ans;   bool cal(long long L, long long R) {     long long sum = 0;     for (long long i = n, l = 1, r = 1; i >= 1; --i) {       while (l <= n && b[i] + b[l] < L) ++l;       while (r <= n && b[i] + b[r] <= R) ++r;       sum += r - l - (l <= i && i < r);     }     return (sum >> 1) & 1;   }   bool solve(long long k) {     for (long long i = 1; i <= n; ++i) b[i] = a[i] & ((1 << (k + 1)) - 1);     sort(b + 1, b + n + 1);     return cal(1 << k, (1 << (k + 1)) - 1) ^ cal(3 << k, (1 << (k + 2)) - 2);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; ++i) cin >> a[i];     for (long long i = 0; i <= 30; ++i) ans |= solve(i) << i;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int l, b;     std::cin >> l >> b;     if (l * b % 2 == 0) {       std::cout << (l * b) / 2;       return 0;     }     std::cout << ((l * b) - 1) / 2;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int sz2 = 5e5 + 1;   int fact[sz2];   int inv_fact[sz2];   int mul(int a, int b) { return (long long)a * b % mod; }   int add(int a, int b) {     int res = (long long)a + b;     if (res < 0)       res += mod;     else if (res > mod)       res -= mod;     return res;   }   int bpow(int x, int p) {     int res = 1;     while (p) {       if (p & 1) res = mul(res, x);       p >>= 1;       if (p) x = mul(x, x);     }     return res;   }   int inv(int x) { return bpow(x, mod - 2); }   void calc_fact() {     fact[0] = inv_fact[0] = 1;     for (int i = 1; i < sz2; i++) {       fact[i] = mul(fact[i - 1], i);       inv_fact[i] = inv(fact[i]);     }   }   int cnk(int n, int k) {     if (k > n) return 0;     return mul(fact[n], mul(inv_fact[k], inv_fact[n - k]));   }   const int sz = 55;   int dp[sz * sz][sz][sz];   int dp1[sz * sz][sz];   int dp2[sz][sz][sz][sz][3];   void solve() {     int n, t;     cin >> n >> t;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       a[i].second--;     }     dp[0][0][0] = 1;     dp1[0][0] = 1;     for (int i = 0; i < n; i++) {       if (a[i].second <= 1) {         for (int j = t; j >= 0; j--) {           for (int k = 0; k < n; k++) {             for (int l = 0; l < n; l++) {               if (j + a[i].first <= t)                 dp[j + a[i].first][k + (a[i].second == 0)]                   [l + (a[i].second == 1)] =                       add(dp[j + a[i].first][k + (a[i].second == 0)]                             [l + (a[i].second == 1)],                           dp[j][k][l]);             }           }         }       } else {         for (int j = t; j >= 0; j--) {           for (int k = 0; k < n; k++) {             if (j + a[i].first <= t)               dp1[j + a[i].first][k + 1] =                   add(dp1[j + a[i].first][k + 1], dp1[j][k]);           }         }       }     }     dp2[1][1][0][0][0] = 1;     dp2[1][0][1][0][1] = 1;     dp2[1][0][0][1][2] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           for (int l = 0; l <= n; l++) {             for (int h = 0; h < 3; h++) {               for (int g = 0; g < 3; g++) {                 if (g != h)                   dp2[i + 1][j + (g == 0)][k + (g == 1)][l + (g == 2)][g] =                       add(dp2[i + 1][j + (g == 0)][k + (g == 1)][l + (g == 2)][g],                           dp2[i][j][k][l][h]);               }             }           }         }       }     }     int ans = 0;     for (int i = 0; i <= t; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           for (int l = 0; l <= n; l++) {             if (j + k + l > n) continue;             int p = mul(                 mul(dp[i][j][k], dp1[t - i][l]),                 add(dp2[j + k + l][j][k][l][0],                     add(dp2[j + k + l][j][k][l][1], dp2[j + k + l][j][k][l][2])));             int r = mul(fact[j], mul(fact[k], fact[l]));             ans = add(ans, mul(p, r));           }         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     calc_fact();     int q = 1;     for (; q > 0; q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2;     cin >> n1 >> n2 >> k1 >> k2;     if (n1 > n2)       cout <<  First  << endl;     else if (n1 == n2)       cout <<  Second  << endl;     else       cout <<  Second  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, k;     while (scanf( %d%d , &n, &m) != EOF) {       int ans = n / m;       k = n % m;       for (int i = 1; i <= m; i++) {         if (i <= m - k) {           printf( %d , ans);         } else {           printf( %d , ans + 1);         }         if (i != m) {           printf(   );         } else {           printf(  n );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int N = 710;   string s;   int n, t[N];   stack<int> st;   struct node {     long long f[3][3];     void init() {       for (int i = 1; i <= 2; i++) f[i][0] = f[0][i] = 1;     }     node() { memset(f, 0, sizeof(f)); }     void mergein(node t) {       for (int i = 0; i <= 2; i++)         for (int j = 0; j <= 2; j++)           if ((i == 0 || j == 0) && i != j)             for (int i1 = 0; i1 <= 2; i1++)               for (int j1 = 0; j1 <= 2; j1++)                 if ((i1 != i || i1 + i == 0) && (j1 != j || j1 + j == 0))                   f[i][j] = (f[i][j] + t.f[i1][j1]) % MOD;     }     void mergenear(node x, node y) {       for (int i = 0; i <= 2; i++)         for (int j = 0; j <= 2; j++)           for (int i1 = 0; i1 <= 2; i1++)             for (int j1 = 0; j1 <= 2; j1++)               if (i1 != j1 || i1 + j1 == 0)                 f[i][j] = (f[i][j] + (x.f[i][i1] * y.f[j1][j]) % MOD) % MOD;     }   };   node DAC(int l, int r) {     node tmp;     if (t[l] == r) {       if (l == r - 1)         tmp.init();       else         tmp.mergein(DAC(l + 1, r - 1));     } else       tmp.mergenear(DAC(l, t[l]), DAC(t[l] + 1, r));     return tmp;   }   void prepare() {     cin >> s;     n = s.length();   }   void solve() {     for (int i = 1; i <= n; i++)       if (s[i - 1] ==  ( )         st.push(i);       else         t[i] = st.top(), st.pop(), t[t[i]] = i;     node ans = DAC(1, n);     long long way = 0;     for (int i = 0; i <= 2; i++)       for (int j = 0; j <= 2; j++) way = (way + ans.f[i][j]) % MOD;     cout << way;   }   int main() {     prepare();     solve();   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   using namespace std;   const long long N = 1e6 + 5;   const long long mod = 1e9 + 7;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   long long test = 1, n, m, a[N], sz = 0, tot, ch[N];   string second =  0 ;   long long tree[N] = {};   void update(int idx, int val) {     idx++;     while (idx <= N - 1) {       tree[idx] += val;       idx += idx & (-idx);     }   }   long long query(int idx) {     idx++;     long long sum = 0;     while (idx > 0) {       sum += tree[idx];       idx -= idx & (-idx);     }     return sum;   }   int bs(int x) {     int l = 1, r = N - 1, ans = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (query(mid) >= x) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     return ans;   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == -1) {         vector<long long> v;         for (int i = 1; i <= m; i++) {           if (a[i] > sz) break;           v.push_back(bs(a[i]));         }         sz -= v.size();         for (auto it : v) ch[it] = 0, update(it, -1);       } else {         second += x +  0 ;         sz++, tot++;         update(tot, 1);         ch[tot] = 1;       }     }     if (sz == 0)       cout <<  Poor stack!             <<   n ;     else {       for (int i = 1; i <= tot; i++) {         if (ch[i] == 1) cout << second[i];       }       cout <<   n ;       ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(15);     ;     for (int i = 1; i <= test; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > g;   vector<vector<pair<long long, long long> > > updates;   vector<long long> tree;   vector<long long> ans;   long long n;   void update(long long v, long long l, long long r, long long al, long long ar,               long long val) {     if (al <= l && ar >= r) {       tree[v] += val;       return;     }     if (al <= r && ar >= l) {       update(v * 2, l, (r + l) / 2, al, ar, val);       update(v * 2 + 1, (r + l) / 2 + 1, r, al, ar, val);     }   }   long long answer(long long v, long long l, long long r, long long ind) {     if (l == r) {       return tree[v];     }     if (ind <= (r + l) / 2) {       return tree[v] + answer(v * 2, l, (r + l) / 2, ind);     } else {       return tree[v] + answer(v * 2 + 1, (r + l) / 2 + 1, r, ind);     }   }   void dfs(long long v, long long pred = -1, long long h = 0) {     for (long long i = 0; i < updates[v].size(); i++) {       update(1, 0, n - 1, h, min(updates[v][i].second + h, n),              updates[v][i].first);     }     ans[v] = answer(1, 0, n - 1, h);     for (long long i = 0; i < g[v].size(); i++) {       if (g[v][i] != pred) {         dfs(g[v][i], v, h + 1);       }     }     for (long long i = 0; i < updates[v].size(); i++) {       update(1, 0, n - 1, h, min(updates[v][i].second + h, n),              -updates[v][i].first);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     tree.resize(n * 4);     g.resize(n);     ans.resize(n);     updates.resize(n);     for (long long i = 0; i < n - 1; i++) {       long long x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     long long m;     cin >> m;     for (long long i = 0; i < m; i++) {       long long v, x, d;       cin >> v >> d >> x;       v--;       updates[v].push_back({x, d});     }     dfs(0);     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int flag[3000500];   int dp[200050];   int maxx[200050];   int ans[200050];   stack<int> st;   int main() {     string s;     cin >> s;     int n = s.size();     for (int i = 0; i < n; i++) {       ans[i] = 0;       if (s[i] ==  1 ) st.push(i);       if (s[i - 1] ==  1  && s[i] ==  0 ) {         int j = i;         while (!st.empty() && s[j] ==  0  && j < n) {           int temp = st.top();           st.pop();           ans[temp] = 1;           j++;           i = j - 1;         }       }     }     for (int i = 0; i < n; i++) cout << ans[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long calc(long long x, long long k) {     if (x < 0) return 0LL;     return x / k + 1LL;   }   int main() {     long long k, a, b;     scanf( %lld%lld%lld , &k, &a, &b);     if (a <= 0 && b <= 0) {       a = abs(a), b = abs(b);       printf( %lld n , calc(a, k) - calc(b - 1LL, k));     } else if (a >= 0 && b >= 0) {       printf( %lld n , calc(b, k) - calc(a - 1LL, k));     } else {       a = abs(a);       printf( %lld n , calc(b, k) + calc(a, k) - 1LL);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w, csets;   int weights[1001];   int beauties[1001];   int ranksz[1001];   int parents[1001];   bool superprnt[1001];   vector<vector<int>> setlist;   vector<int> beautysum;   vector<int> wtsum;   map<int, int> setidmap;   vector<vector<int>> dpmap;   int find_parent(int i) {     if (parents[i] == i) return i;     return parents[i] = find_parent(parents[i]);   }   void union_nodes(int a, int b) {     int prta{find_parent(a)};     int prtb{find_parent(b)};     if (prta == prtb) return;     if (ranksz[prta] > ranksz[prtb]) {       parents[prtb] = prta;       ranksz[prta] += ranksz[prtb];       superprnt[prtb] = 0;     } else {       parents[prta] = prtb;       ranksz[prtb] += ranksz[prta];       superprnt[prta] = 0;     }   }   int solvedp(int i, int wts) {     if (i == csets || wts == 0) return 0;     if (dpmap[i][wts] != -1) return dpmap[i][wts];     int ans1{-500}, ans2{-500}, ans3{-500};     if (wtsum[i] <= wts) ans1 = beautysum[i] + solvedp(i + 1, wts - wtsum[i]);     for (int j : setlist[i]) {       if (weights[j] <= wts) {         ans2 = max(ans2, beauties[j] + solvedp(i + 1, wts - weights[j]));       }     }     ans3 = solvedp(i + 1, wts);     return dpmap[i][wts] = max(max(ans1, ans2), ans3);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m, a, b;     cin >> n >> m >> w;     for (int i = 1; i <= n; ++i) {       cin >> weights[i];       parents[i] = i;       ranksz[i] = 1;       superprnt[i] = 1;     }     for (int i = 1; i <= n; ++i) {       cin >> beauties[i];     }     for (int i = 0; i < m; ++i) {       cin >> a >> b;       union_nodes(a, b);     }     int setid{0};     csets = 0;     for (int i = 1; i <= n; ++i) {       if (superprnt[i]) {         csets++;         setidmap[i] = setid++;       }     }     setlist = vector<vector<int>>(csets);     beautysum = vector<int>(csets, 0);     wtsum = vector<int>(csets, 0);     for (int i = 1; i <= n; ++i) {       int prt{find_parent(i)};       int id{setidmap[prt]};       setlist[id].push_back(i);       beautysum[id] += beauties[i];       wtsum[id] += weights[i];     }     dpmap = vector<vector<int>>(csets, vector<int>(w + 1, -1));     int ans{solvedp(0, w)};     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     long long int a[n];     for (auto i = 0; i <= n - 1; i++) cin >> a[i];     sort(a, a + n);     for (auto i = n - 1; i >= 0; i--) {       if (a[i] <= i + 1) {         cout << i + 2 <<   n ;         return;       }     }     cout <<  1 n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char E =   n ;   int main() {     set<string> a;     string s;     cin >> s;     a.insert(s);     int n = s.length();     for (int i = 1; i <= n + 1; i++) {       char z = s[n - 1];       for (int j = n; j >= 1; j--) {         s[j] = s[j - 1];       }       s[0] = z;       a.insert(s);     }     cout << a.size() << E;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool query(int x, int y) {     cout <<  ?   << x <<     << y << endl;     char resp;     cin >> resp;     if (resp ==  e ) exit(0);     return resp ==  x ;   }   void answer(int v) {     cout <<  !   << v << endl;     return;   }   void solve() {     int k = -1;     ;     for (int i = 0; i < 30; i++) {       int x = (1 << (i + 1)), y = (1 << i);       if (!query(x, y)) {         k = i;         break;       }     }     if (k == -1) {       answer(1);       return;     }     int l = (1 << k);     int u = (1 << (k + 1));     while (u - l > 2) {       int mid = (u + l) / 2;       if (!query(mid, mid / 2))         u = mid;       else         l = mid;     }     if (!query(u, 1))       answer(u);     else       answer(u - 1);     return;   }   int main() {     string msg;     while (cin >> msg, msg !=  end ) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, t, i, c = 0, s, x, y, u;     cin >> n >> t;     if (t < 10) {       for (i = 0; i < n; i++) cout << t;     } else {       s = t / 10;       c++;       while (1) {         s = s / 10;         c++;         if (s == 0) break;       }       if (c == n)         cout << t;       else if (c > n)         cout <<  -1 ;       else if (c < n) {         u = n - c;         cout << t;         for (i = 1; i <= u; i++) cout << 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int flag[13], change[13];   bool is_leap(int y) {     if (y % 100 == 0)       return y % 400 == 0;     else       return y % 4 == 0;   }   int main() {     memset(flag, 0, sizeof(flag));     memset(change, 0, sizeof(change));     int y;     cin >> y;     while (1) {       bool last = is_leap(y);       y++;       bool now = is_leap(y);       if (last && (!now))         for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1 + (i <= 2)) % 7;       else if ((!last) && now)         for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1 + (i >= 3)) % 7;       else         for (int i = 1; i <= 12; i++) change[i] = (change[i] + 1) % 7;       bool ok = true;       for (int i = 1; i <= 12; i++)         if (flag[i] != change[i]) {           ok = false;           break;         }       if (ok) break;     }     cout << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   int m;   const int mod = 1000000007;   struct matr {     int a[60][60];     matr() { memset(a, 0, sizeof(a)); }   };   matr mul(matr m1, matr m2) {     matr res;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j)         for (int k = 0; k < m; ++k)           res.a[i][j] = (res.a[i][j] + (long long)m1.a[i][k] * m2.a[k][j]) % mod;     return res;   }   matr pow(matr x, long long p) {     if (p == 0) {       matr res;       for (int i = 0; i < m; ++i) res.a[i][i] = 1;       return res;     } else if (p & 1)       return mul(x, pow(x, p - 1));     else {       matr t = pow(x, p >> 1);       return mul(t, t);     }   }   int g(char c) {     if (c >=  a  && c <=  z )       return c -  a ;     else       return c -  A  + 26;   }   int main() {     long long n;     int k;     cin >> n >> m >> k;     n--;     matr p;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) p.a[i][j] = 1;     for (int i = 0; i < k; ++i) {       string s;       cin >> s;       int v1 = g(s[0]);       int v2 = g(s[1]);       p.a[v2][v1] = 0;     }     p = pow(p, n);     int ans = 0;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) ans = (ans + p.a[i][j]) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long A, B, x, y, z;     cin >> A >> B >> x >> y >> z;     for (int i = 0; i < x; i++) A = A - 2;     for (int i = 0; i < y; i++) {       A--;       B--;     }     for (int i = 0; i < z; i++) B = B - 3;     long long a = 0, b = 0;     if (A < 0) a = -A;     if (B < 0) b = -B;     cout << (a + b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   struct point {     int first, second;     point(int first = 0, int second = 0) : first(first), second(second) {}     point operator-(point a) { return point(first - a.first, second - a.second); }     long long operator^(point a) {       return (long long)first * a.second - (long long)second * a.first;     }     long long operator*(point a) {       return (long long)first * a.first + (long long)second * a.second;     }     void input() { scanf( %d%d , &first, &second); }   };   int sgn(long long a) { return (a > 0) - (a < 0); }   int is_on(point a, point b, point c) {     if (sgn((a - b) ^ (a - c))) return 0;     return sgn((a - c) * (c - b)) > 0;   }   point ston[10], mons[1111];   int flag[1111], id[10], n, k, runs, used;   vector<int> adj[10][1111];   bool judge(int u) {     if (used >= k) return false;     flag[u] = runs;     int shoot = id[used++];     for (int i = 0; i < adj[shoot][u].size(); i++) {       int v = adj[shoot][u][i];       if (flag[v] != runs) {         if (!judge(v)) return false;       }     }     return true;   }   int main() {     scanf( %d%d , &k, &n);     for (int i = 0; i < k; i++) ston[i].input();     for (int i = 0; i < n; i++) mons[i].input();     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         for (int p = 0; p < n; p++)           if (p != j) {             if (is_on(ston[i], mons[j], mons[p])) adj[i][j].push_back(p);             if (adj[i][j].size() >= k) break;           }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) id[j] = j;       do {         ++runs;         used = 0;         if (judge(i)) {           ans++;           break;         }       } while (next_permutation(id, id + k));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005, mod = 1000000007;   int ar[N];   inline int lowbit(int x) { return x & (-x); }   void add(int i, int v) {     for (; i < N; i += lowbit(i)) {       ar[i] += v;       if (ar[i] >= mod) {         ar[i] %= mod;       }     }   }   int sum(int i) {     int res = 0;     for (; i > 0; i -= lowbit(i)) {       res += ar[i];       if (res >= mod) res %= mod;     }     return res;   }   int main() {     int n;     scanf( %d , &n);     memset(ar, 0, sizeof(ar));     for (int tp, i = 1; i <= n; i++) {       scanf( %d , &tp);       int s = sum(tp), v = ((long long)s * tp + tp) % mod, t = sum(tp - 1);       t = v - s + t;       if (t < 0) t += mod;       if (t >= mod) t %= mod;       add(tp, t);     }     printf( %d n , sum(N - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000010];   int main() {     int n;     scanf( %d , &n);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       sum += a[i];     }     if (sum <= 1) {       printf( -1 n );       return 0;     }     long long ans = 9999999999999999;     for (int i = 2; i * i <= sum; ++i) {       if (sum % i) continue;       long long cnt = 0, pre = 0;       while (sum % i == 0) sum /= i;       for (int j = 1; j <= n; ++j) {         pre = (pre + a[j]) % i;         cnt += min(pre, i - pre);       }       ans = min(ans, cnt);     }     if (sum > 1) {       long long pre = 0, cnt = 0;       for (int j = 1; j <= n; ++j) {         pre = (pre + a[j]) % sum;         cnt += min(pre, sum - pre);       }       ans = min(ans, cnt);     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000009;   map<string, int> mapa;   int n, m, k, a, parent[maxN], used[maxN], rozmiar[maxN], centr[maxN], q;   vector<int> graf[maxN];   string s, s1;   void DFS(int start) {     used[start] = 1;     for (int i = 0; i < graf[start].size(); i++) {       if (!used[graf[start][i]]) {         DFS(graf[start][i]);         rozmiar[start] += rozmiar[graf[start][i]];       }     }     rozmiar[start]++;     for (int i = 0; i < graf[start].size(); i++) {       if (graf[start][i] != parent[start]) {         if (rozmiar[graf[start][i]] > rozmiar[start] / 2) {           if (rozmiar[start] - rozmiar[centr[graf[start][i]]] <=               rozmiar[start] / 2)             centr[start] = centr[graf[start][i]];           else {             int x = parent[centr[graf[start][i]]];             while (1) {               if (rozmiar[start] - rozmiar[x] <= rozmiar[start] / 2) {                 centr[start] = x;                 break;               }               x = parent[x];             }           }         }       }     }     if (centr[start] == 0) centr[start] = start;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++) {       scanf( %d , &a);       parent[i] = a;       graf[i].push_back(a);       graf[a].push_back(i);     }     DFS(1);     for (int i = 0; i < q; i++) {       scanf( %d , &a);       printf( %d n , centr[a]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int a;     cin >> a;     string s;     cin >> s;     map<long long, long long> mp;     long long ans = 0;     for (int i = 0; i < s.size(); i++) {       long long c = 0;       for (int j = i; j < s.size(); j++) {         c += (s[j] -  0 );         mp[c]++;       }     }     for (auto i : mp) {       if (!i.first) {         if (!a) ans += (i.second * i.second);       } else if (a % i.first == 0) {         if (a == 0)           ans += (mp[0] * i.second * 2);         else           ans += (mp[a / i.first] * i.second);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fastio();     long long int T = 1;     cin >> T;     for (long long int test = 1; test <= T; test++) {       long long int n, m, k, ans, cnt, sum;       ans = 0;       cnt = 100;       sum = 0;       cin >> n >> k;       if (k < n)         ans = k;       else {         while (k && cnt--) {           if (k < n) {             ans += k;             break;           }           long long int z = k / n;           long long int a = z * n;           z *= (n - 1);           long long int q = k - z;           ans += a;           k = q;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, b, c, d;     cin >> n >> k >> a >> b >> c >> d;     if (n == 4 || k < n + 1)       cout << -1 << endl;     else {       int cur = 1;       vector<int> ret;       ret.push_back(a);       ret.push_back(c);       while (cur == a || cur == b || cur == c || cur == d) cur++;       ret.push_back(cur);       cur++;       ret.push_back(d);       for (int x = 4; x < n - 1; x++) {         while (cur == a || cur == b || cur == c || cur == d) cur++;         ret.push_back(cur);         cur++;       }       ret.push_back(b);       for (int i = 0; i < n; i++) cout << ret[i] <<    ;       cout << endl;       cout << ret[1] <<     << ret[0] <<     << ret[2] <<     << ret[n - 1]            <<    ;       for (int i = n - 2; i > 2; i--) cout << ret[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k;     cin >> k;     int sz = s.size();     string land;     bool equal;     int begin, lenth, idx, res = 0, end;     for (int i = 0; i < sz; i++) {       begin = i;       land =   ;       for (int j = i; j < sz; j++) {         land += s[j];         end = min(j + 1 + j - begin + 1 - 1, sz - 1);         idx = 0;         equal = 1;         for (int l = j + 1; l <= end; l++, idx++) {           if (land[idx] != s[l]) {             equal = 0;             break;           }         }         lenth = end - (j + 1) + 1;         if (equal && lenth != j - begin + 1 && (j - begin + 1) - lenth <= k) {           if (j == sz - 1)             res = max(res, (((j - begin + 1) + lenth + k) / 2) * 2);           else             res = max(res, 2 * (j - begin + 1));         }         if (equal && lenth == j - begin + 1) res = max(res, 2 * (j - begin + 1));       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int cnt = 0;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n - 1; i++) {       if (a[i] == 0) {         if (a[i + 1] == 1 && a[i - 1] == 1) {           if (i + 2 < n) {             if (a[i + 2] == 0) {               cnt++;               a[i + 1] = 0;             } else               cnt++;           } else             cnt++;         }       }     }     cout << cnt;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 5;   char C[MAXN][20][20];   long long aans[MAXN];   struct node {     long long u, v, val, way;     node() {}     node(long long a, long long b, long long c) {       u = a;       v = b;       val = c;     }   };   vector<node> v;   vector<int> vv[MAXN];   long long fa[MAXN * 10];   bool cmp(node a, node b) { return a.val < b.val; }   long long getf(long long x) {     if (x == fa[x])       return x;     else       return fa[x] = getf(fa[x]);   }   void add(long long a, long long b) { fa[getf(a)] = getf(fa[b]); }   void dfs(long long x, long long fa) {     long long len = vv[x].size();     for (long long i = 0; i < len; i++) {       long long to = vv[x][i];       if (to != fa) {         cout << to <<     << x << endl;         dfs(to, x);       }     }   }   int main() {     long long n, m, k, w;     cin >> n >> m >> k >> w;     for (long long k1 = 1; k1 <= k; k1++) {       for (long long i = 1; i <= n; i++) {         cin >> C[k1][i] + 1;       }     }     for (long long k1 = 1; k1 <= k; k1++) {       for (long long k2 = k1 + 1; k2 <= k; k2++) {         long long num = 0;         for (long long i = 1; i <= n; i++) {           for (long long j = 1; j <= m; j++) {             if (C[k1][i][j] != C[k2][i][j]) num++;           }         }         v.push_back(node(k1, k2, num * w));       }     }     for (long long i = 1; i <= k; i++) {       v.push_back(node(0, i, n * m));     }     long long ans = 0;     for (long long i = 1; i <= k; i++) {       fa[i] = i;     }     sort(v.begin(), v.end(), cmp);     for (long long i = 0; i < v.size(); i++) {       long long aa = v[i].u, cc = v[i].val;       long long bb = v[i].v;       if (getf(aa) != getf(bb)) {         add(aa, bb);         ans += cc;         vv[aa].push_back(bb);         vv[bb].push_back(aa);       }     }     cout << ans << endl;     dfs(0, 0);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000 )   using namespace std;   struct N {     int x, y;   };   queue<N> q;   char Map[2010][2010];   int jx[] = {-1, 0, 1, 0};   int jy[] = {0, 1, 0, -1};   char CalChar(int dir) {     if (dir == 0) return  v ;     if (dir == 1) return  < ;     if (dir == 2) return  ^ ;     return  > ;   }   int Check(int x, int y, int n, int m) {     bool hav = false;     int dir;     for (int i = 0; i < 4; ++i) {       if (1 <= x + jx[i] && x + jx[i] <= n && 1 <= y + jy[i] && y + jy[i] <= m &&           Map[x + jx[i]][y + jy[i]] ==  . ) {         if (hav) return -1;         hav = true;         dir = i;       }     }     if (hav == false) return -2;     return dir;   }   void Output(int n, int m) {     for (int i = 1; i <= n; ++i) puts(Map[i] + 1);     puts(  );   }   int main() {     int n, m, i, j, tmp;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , Map[i] + 1);     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j) {         if (Map[i][j] ==  . ) {           tmp = Check(i, j, n, m);           if (0 <= tmp) {             q.push((N){i + jx[tmp], j + jy[tmp]});             Map[i][j] = CalChar(tmp);             Map[i + jx[tmp]][j + jy[tmp]] = CalChar((tmp + 2) % 4);           }         }       }     }     N f, t;     while (q.empty() == false) {       f = q.front();       q.pop();       for (i = 0; i < 4; ++i) {         t.x = f.x + jx[i];         t.y = f.y + jy[i];         if (1 <= t.x && t.x <= n && 1 <= t.y && t.y <= m &&             Map[t.x][t.y] ==  . ) {           tmp = Check(t.x, t.y, n, m);           if (tmp == -2) return puts( Not unique ), 0;           if (0 <= tmp) {             Map[t.x][t.y] = CalChar(tmp);             Map[t.x + jx[tmp]][t.y + jy[tmp]] = CalChar((tmp + 2) % 4);             q.push((N){t.x + jx[tmp], t.y + jy[tmp]});           }         }       }     }     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j)         if (Map[i][j] ==  . ) return puts( Not unique ), 0;     }     for (i = 1; i <= n; ++i) puts(Map[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = s.length();       if (n <= 10) {         cout << s << endl;       } else {         cout << s.at(0);         cout << n - 2;         cout << s.at(n - 1) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[1007];   long long cnt[1007];   long long ncr[1007][1007];   long long MOD = 998244353;   int main() {     long long n, res = 0, x;     scanf( %I64d , &n);     ;     for (long long i = 1; i <= n; ++i) scanf( %I64d , &a[i]);     ;     for (int i = 0; i < 1000; ++i) {       for (int j = 0; j <= i; ++j) {         if (i == 0 || j == 0)           ncr[i][j] = 1;         else           ncr[i][j] = (ncr[i - 1][j] + ncr[i - 1][j - 1]) % MOD;       }     }     for (long long i = n; i > 0; --i) {       if ((a[i] > 0) && ((i + a[i]) <= n)) {         x = ncr[n - i][a[i]];         cnt[i] = x;         for (long long j = i + a[i] + 1; j < n; ++j) {           x = ncr[j - i - 1][a[i]];           x = (x * cnt[j]) % MOD;           cnt[i] = (cnt[i] + x) % MOD;         }       }       res = (res + cnt[i]) % MOD;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   template <typename T>   using V = vector<T>;   template <typename T, typename S>   using P = pair<T, S>;   template <class T>   using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;   using LD = long double;   template <typename T, typename S>   void check(T& a, S& b) {     if (a >= b) {       a %= b;     }   }   template <typename T>   T gcd(T u, T v) {     if (u == v) return u;     if (u == 0) return v;     if (v == 0) return u;     if (~u & 1) {       if (v & 1)         return gcd(u >> 1, v);       else         return gcd(u >> 1, v >> 1) << 1;     }     if (~v & 1) return gcd(u, v >> 1);     if (u > v) return gcd((u - v) >> 1, v);     return gcd((v - u) >> 1, u);   }   const int N = 35001;   int n, k;   int dp[N][51];   class SegmentTree {    public:     int n;     V<int> arr, lazy;     SegmentTree() {}     SegmentTree(int n) {       this->n = n;       this->arr = V<int>(n << 2, 0);       this->lazy = V<int>(n << 2, 0);     }     void propogate(int node, int s, int e) {       if (lazy[node]) {         arr[node] += lazy[node];         if (s != e) {           lazy[node << 1] += lazy[node];           lazy[node << 1 | 1] += lazy[node];         }       }       lazy[node] = 0;     }     void update(int node, int s, int e, int l, int r, int val) {       propogate(node, s, e);       if (l > r || s > r || e < l) return;       if (s >= l && e <= r) {         lazy[node] += val;         propogate(node, s, e);         return;       }       int mid = (s + e) >> 1;       update(node << 1, s, mid, l, r, val);       update(node << 1 | 1, mid + 1, e, l, r, val);       arr[node] = max(arr[node << 1], arr[node << 1 | 1]);     }     void upd(int node, int s, int e, int l, int val) {       propogate(node, s, e);       if (s == e) {         arr[node] = max(arr[node], val);         return;       }       int mid = (s + e) >> 1;       if (l <= mid)         upd(node << 1, s, mid, l, val);       else         upd(node << 1 | 1, mid + 1, e, l, val);       propogate(node << 1, s, mid);       propogate(node << 1 | 1, mid + 1, e);       arr[node] = max(arr[node << 1], arr[node << 1 | 1]);       return;     }     int get(int node, int s, int e, int l, int r) {       propogate(node, s, e);       if (l > r || s > r || e < l) return 0;       if (s >= l && e <= r) {         return arr[node];       }       int mid = (s + e) >> 1;       return max(get(node << 1, s, mid, l, r),                  get(node << 1 | 1, mid + 1, e, l, r));     }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cerr.tie(NULL);     ;     cin >> n >> k;     V<int> a, f(n + 1, n);     a.resize(n);     for (int i = 0; i < (int)n; i++) cin >> a[i], a[i]--;     SegmentTree seg[51];     for (int i = 0; i < k; i++) seg[i] = SegmentTree(n);     for (int i = n - 1; i >= 0; i--) {       dp[i][0] = dp[i + 1][0];       if (f[a[i]] == n) dp[i][0]++;       seg[0].upd(1, 0, n - 1, i, dp[i][0]);       for (int j = 1; j < min(n - i, k); j++) {         seg[j - 1].update(1, 0, n - 1, i + 1, min(f[a[i]], n - 1), 1);         dp[i][j] = seg[j - 1].get(1, 0, n - 1, i + 1, n - 1);         seg[j].upd(1, 0, n - 1, i, dp[i][j]);       }       f[a[i]] = i;     }     cout << dp[0][k - 1] <<   n ;     cerr <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       if (n == 1) {         printf( a na nb nb n );         continue;       }       if (n % 2 == 0) {         for (int i = 0; i < 4; i++) {           for (int j = 0; j < n; j++) {             if (i % 4 < 2) {               printf( %c ,  a  + (i % 2 + (j % 4) / 2) % 2);             } else {               if (j == 0) {                 printf( %c ,  c );               } else if (j == n - 1) {                 printf( %c ,  f );               } else {                 printf( %c ,  d  + (i % 2 + (j - 1) % 4 / 2) % 2);               }             }           }           printf(  n );         }       } else {         for (int i = 0; i < 4; i++) {           for (int j = 0; j < n; j++) {             if (i < 2) {               if (j == n - 1) {                 printf( %c ,  c );               } else {                 printf( %c ,  a  + (i % 2 + (j % 4) / 2) % 2);               }             } else {               if (j < 1) {                 printf( %c ,  d );               } else {                 printf( %c ,  f  + (i % 2 + (j - 1) % 4 / 2) % 2);               }             }           }           printf(  n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const int N = (int)3e5 + 4;   const int M = 1001;   int n, k;   int a[6];   double ans;   void f(int s) {     if (s == k) {       for (int i = 0; i < n; ++i) {         for (int j = i + 1; j < n; ++j) {           if (a[i] > a[j]) {             ++ans;           }         }       }       return;     }     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         reverse(a + i, a + j + 1);         f(s + 1);         reverse(a + i, a + j + 1);       }     }   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     f(0);     for (int i = 0; i < k; ++i) {       ans /= n;       ans /= (n + 1);       ans *= 2.0;     }     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test, i, j, xy, flag = 0, n, u, count, d, o1 = 0, o2 = 0, s, e, l,                               r, x, y, m, z, max1, x1, y1, k, x2, y2, z1, sum, f,                               min1;     cin >> test;     while (test--) {       x1 = y1 = 0;       string a;       cin >> n >> x >> y >> z >> a;       for (i = 0; i < n; i++) {         if (a[i] ==  0 ) {           x1++;         } else {           y1++;         }       }       x2 = (x1 * z) + (x1 * y) + (y1 * y);       y2 = (y1 * z) + (y1 * x) + (x1 * x);       z1 = x1 * x + y1 * y;       cout << min(min(x2, y2), z1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long s, x;     cin >> s >> x;     s -= x;     if (s % 2 || s < 0) {       cout << 0 <<   n ;       return 0;     }     s >>= 1;     bool ok = true;     for (int i = 50; i >= 0; --i)       if (s & (1LL << i)) ok &= (~x & (1LL << i)) != 0;     if (!ok) {       cout << 0 <<   n ;       return 0;     }     long long ans = 1LL << __builtin_popcountll(x);     cout << (s == 0 ? ans - 2 : ans) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using u64 = uint64_t;   using u32 = uint32_t;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vvi = vector<vi>;   using vpi = vector<pi>;   static constexpr int INF = (int)1e9;   static constexpr ll INFL = (ll)1e18;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<string> s(n), t(m);     for (auto& si : s) cin >> si;     for (auto& ti : t) cin >> ti;     int q, y;     cin >> q;     while (q--) cin >> y, --y, cout << s[y % n] << t[y % m] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     if (n > 2) {       for (long long int i = 0; i < n - 1; i++) cout << 2 <<    ;       cout << 1 << endl;     } else       cout << -1 << endl;   }   void testcase() {     int t;     cin >> t;     while (t--) {       solve();     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN();   int main() {     long long k, b, t;     int n;     cin >> k >> b >> n >> t;     long long z = 1;     int num = 0;     while (z <= t) {       z = z * k + b;       num++;     }     printf( %d , max(0, n - num + 1));   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using uint = unsigned int;   const int NMax = 1e2 + 5;   const ll inf_ll = 1e18 + 5;   const int inf_int = 1e9 + 5;   const int mod = 100003;   using zint = int;   void getABC(char* sir, int& a, int& b, int& c) {     ++sir;     a = 0;     while (isdigit(*sir)) {       a = a * 10 + *sir -  0 ;       ++sir;     }     ++sir;     b = 0;     while (isdigit(*sir)) {       b = b * 10 + *sir -  0 ;       ++sir;     }     ++sir;     ++sir;     c = 0;     while (*sir != 0 && isdigit(*sir)) {       c = c * 10 + *sir -  0 ;       ++sir;     }   }   int euclid(int a, int b) { return b ? euclid(b, a % b) : a; }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int N;     cin >> N;     char sir[100];     map<pair<int, int>, int> make_pair;     vector<pair<int, int>> v(N + 1);     for (int i = 1; i <= N; ++i) {       cin >> sir;       int a, b, c;       getABC(sir, a, b, c);       int top = a + b;       int gcd = euclid(top, c);       top /= gcd;       c /= gcd;       make_pair[{top, c}]++;       v[i] = {top, c};     }     for (int i = 1; i <= N; ++i) {       cout << make_pair[v[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int judge(int n) {     if (n == 2 || n == 3) return 1;     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   int main() {     int i, j, m;     scanf( %d , &n);     if (judge(n))       printf( 1 n%d n , n);     else if (judge(n - 2))       printf( 2 n2 %d n , n - 2);     else if (judge(n - 4))       printf( 3 n2 2 %d n , n - 4);     else {       for (i = n - 2; i >= n - 300 && i >= 1; i--)         if (judge(i)) {           k = i;           m = n - i;           break;         }       for (j = 2; j <= m; j++) {         if (judge(j) && judge(m - j)) {           printf( 3 n%d %d %d n , k, j, n - i - j);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int MOD = 1e9 + 7;   int n, revfact[N << 1], fact[N << 1];   int mul(int, int);   int sum(int, int);   int pow(int, int);   int choose(int, int);   int32_t main() {     cin >> n;     fact[0] = 1;     for (int i = 1; i < 2 * n + 3; i++) fact[i] = mul(fact[i - 1], i);     for (int i = 0; i < 2 * n + 3; i++) revfact[i] = pow(fact[i], MOD - 2);     int res = choose((2 * n) + 2, n + 1) - 1;     if (res < 0) res += MOD;     cout << res << endl;   }   int mul(int a, int b) { return 1LL * a * b % MOD; }   int sum(int a, int b) {     int c = a + b;     if (c >= MOD) c -= MOD;     return c;   }   int pow(int n, int md) {     int res = 1;     for (; md; md /= 2) {       if (md % 2 == 1) res = mul(res, n);       n = mul(n, n);     }     return res;   }   int choose(int m, int k) {     return mul(fact[m], mul(revfact[k], revfact[m - k]));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, x, t = 1, y;     cin >> a >> b;     x = abs(a - b);     if (x % 2 != 0) t = 0;     x = (x / 2);     y = (x * (x + 1)) / 2;     y *= 2;     if (!t) x++, y += x;     cout << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   using ll = long long;   using ld = long double;   const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1;   const ll INF = 1e18;   ld tic, tac;   void solve() {     int n, count = 0;     cin >> n;     int i, a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) count++;     }     cout << count <<   n ;     for (i = 1; i < n; i++) {       if (a[i] == 1) {         cout << a[i - 1] <<     ;       }     }     cout << a[n - 1] <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000100;   const int off = 1 << 19;   const int inf = 1e9;   int a[MAX], s[MAX], c[MAX];   pair<int, int> T[2 * off];   int n, k;   pair<int, int> getmax(int i, int lo, int hi, int a, int b) {     if (lo >= b || hi <= a) return {-inf, -1};     if (lo >= a && hi <= b) return T[i];     return max(getmax(i * 2, lo, (lo + hi) / 2, a, b),                getmax(i * 2 + 1, (lo + hi) / 2, hi, a, b));   }   long long solve(int lo, int hi) {     if (lo >= hi) {       for (int i = lo; i <= hi; ++i) c[s[i]]--;       return 0;     }     int m = getmax(1, 0, off, lo, hi).second;     assert(m != -1);     long long ans = 0;     if (hi - m < m - lo) {       for (int i = m + 1; i <= hi; ++i) c[s[i]]--;       for (int i = m + 1; i <= hi; ++i) ans += c[(s[i] - (a[m] % k) + k) % k];       ans--;       ans += solve(lo, m);       for (int i = m + 1; i <= hi; ++i) c[s[i]]++;       ans += solve(m + 1, hi);     } else {       for (int i = lo; i <= m; ++i) c[s[i]]--;       for (int i = lo; i <= m; ++i) ans += c[(s[i] + a[m]) % k];       ans--;       ans += solve(m + 1, hi);       for (int i = lo; i <= m; ++i) c[s[i]]++;       ans += solve(lo, m);     }     return ans;   }   int main(void) {     scanf( %d %d , &n, &k);     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     s[0] = 0;     for (int i = (0); i < (n); ++i) s[i + 1] = (s[i] + a[i]) % k;     for (int i = (0); i < (n + 1); ++i) c[s[i]]++;     for (int i = (0); i < (n); ++i) T[off + i] = {a[i], i};     for (int i = off - 1; i > 0; --i) T[i] = max(T[i * 2], T[i * 2 + 1]);     long long ans = solve(0, n);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500005;   const int inf = 100000000;   struct elem {     long long val;     int l, r;   };   struct V {     long long val;     int ind;   };   bool compare(V x, V y) {     if (x.val < y.val) return true;     if (x.val == y.val && x.ind < y.ind) return true;     return false;   }   V a[MAXN];   elem L[MAXN];   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> a[i].val;       a[i].ind = i;       L[i].val = a[i].val;       L[i].l = i - 1;       L[i].r = i + 1;     }     int GlobalLeft = 1;     int GlobalRight = N;     sort(a + 1, a + N + 1, compare);     long long ans = 0;     a[N + 1].val = inf;     int pntL = 1, pntR = 1;     int Left = N;     while (pntL <= N && Left > 2) {       pntR = pntL;       while (a[pntR].val == a[pntL].val) pntR++;       int NextL = pntR;       pntR--;       while (pntL <= pntR && a[pntL].ind == GlobalLeft && Left > 2) {         ans += L[GlobalLeft].val;         GlobalLeft = L[GlobalLeft].r;         pntL++;         Left--;       }       while (pntL <= pntR && a[pntR].ind == GlobalRight && Left > 2) {         ans += L[GlobalRight].val;         GlobalRight = L[GlobalRight].l;         pntR--;         Left--;       }       while (pntL <= pntR && Left > 2) {         ans += min(L[L[a[pntL].ind].l].val, L[L[a[pntL].ind].r].val);         L[L[a[pntL].ind].l].r = L[a[pntL].ind].r;         L[L[a[pntL].ind].r].l = L[a[pntL].ind].l;         pntL++;         Left--;       }       pntL = NextL;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v;     int c;     int w;     int id;     bool use;   };   bool operator<(const Edge& l, const Edge& r) { return l.w < r.w; }   class Node {     int depth;     pair<int, int> w;     Node* parent;       public:     Node() : depth(0), w(0, -1), parent(nullptr) {}     static pair<int, int> merge(Node* a, Node* b, int W, int id) {       pair<int, int> mx = {-1, -1};       while ((a->parent || b->parent) && a != b) {         if (!b->parent || a->parent && a->depth <= b->depth) {           mx = max(mx, a->w);           a = a->parent;         } else {           mx = max(mx, b->w);           b = b->parent;         }       }       if (a == b) return {W - mx.first, mx.second};       if (a->depth < b->depth) swap(a, b);       b->parent = a;       b->w.first = W;       b->w.second = id;       a->depth = max(a->depth, b->depth + 1);       return {0, -id};     }   };   int main(int argc, const char* argv[]) {     int N, M;     std::vector<int> W, C;     int S;     scanf( %d%d , &N, &M);     W.resize(M);     C.resize(M);     for (auto&& x : W) scanf( %d , &x);     for (auto&& x : C) scanf( %d , &x);     vector<Edge> edges(M);     for (int i = 0; i < M; i++) {       Edge& e = edges[i];       scanf( %d %d , &e.u, &e.v);       e.u--;       e.v--;       e.c = C[i];       e.w = W[i];       e.id = i + 1;     }     scanf( %d , &S);     sort((edges).begin(), (edges).end());     vector<Node> nodes(N);     int best = 1 << 30;     int exc = -1;     const Edge* useE = nullptr;     long long sumw = 0;     for (auto&& e : edges) {       pair<int, int> r = Node::merge(&nodes[e.u], &nodes[e.v], e.w, e.id);       if (r.second < 0) {         e.use = true;         sumw += e.w;         r.second = -r.second;       } else {         e.use = false;       }       int bonus = r.first - S / e.c;       if (bonus < best) {         best = bonus;         exc = r.second;         useE = &e;       }     }     printf(          %I64d            n ,         sumw + best);     for (auto&& e : edges)       if (e.use && e.id != exc) printf( %d %d n , e.id, e.w);     printf( %d %d n , useE->id, useE->w - S / useE->c);     return 0;   }


#include <bits/stdc++.h>   int star[100005];   int scnt;   int pack[100005];   int pcnt;   int unit(int x) {     if (x > 0) return x;     return 0;   }   int check(int time) {     int i;     int sat = 0;     for (i = 1; i <= pcnt; i++) {       if (sat >= star[scnt]) return 1;       int l = 1, r = scnt, mid, idx;       while (l <= r) {         mid = (l + r) / 2;         if (star[mid] > sat) {           idx = mid;           r = mid - 1;         } else           l = mid + 1;       }       if (star[idx] < pack[i]) {         if (pack[i] - star[idx] > time) return 0;         int t = pack[i] - star[idx];         sat = pack[i] + unit(time - 2 * t);         if (sat < pack[i] + (time - t) / 2) sat = pack[i] + (time - t) / 2;       } else         sat = pack[i] + time;     }     if (sat >= star[scnt]) return 1;     return 0;   }   int main(void) {     int n;     char tmp[100005];     scanf( %d , &n);     scanf( %s , &tmp[1]);     int i;     for (i = 1; i <= n; i++) {       if (tmp[i] ==  * ) star[++scnt] = i;       if (tmp[i] ==  P ) pack[++pcnt] = i;     }     int l = 1, r = 2 * n - 1, mid, ans;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 2e5;   int n, a[mxN], k;   void solve() {     long long n;     cin >> n;     if (n == 0) {       cout << 1 << endl;       return;     }     if (n % 4 == 1) {       cout << 8 << endl;     } else if (n % 4 == 2) {       cout << 4 << endl;     } else if (n % 4 == 3) {       cout << 2 << endl;     } else if (n % 4 == 0) {       cout << 6 << endl;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   long long x, a[N], b[N];   long long n, k;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + 1 + n);     b[1] = a[1];     int j = 2;     for (int i = 2; i <= n; i++) {       if (a[i] != a[i - 1]) {         b[j] = a[i] - a[i - 1];         j++;       }     }     for (int i = 1; i <= k; i++) {       cout << b[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 100;   int a[maxn];   long long dp[maxn][2];   int get1(long long n) {     int sum = 0;     while (n != 0) {       if ((n & 1) == 1) sum += 1;       n >>= 1;     }     return sum;   }   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) {       long long x;       cin >> x;       a[i] = get1(x);     }     dp[0][0] = 0;     dp[0][1] = 0;     dp[1][0] = 0;     dp[1][1] = 0;     for (int i = 2; i <= N; i++) {       if (a[i] & 1) {         dp[i][0] = dp[i - 1][1] + (a[i - 1] & 1);         dp[i][1] = dp[i - 1][0] + !(a[i - 1] & 1);       } else {         dp[i][0] = dp[i - 1][0] + !(a[i - 1] & 1);         dp[i][1] = dp[i - 1][1] + (a[i - 1] & 1);       }     }     long long ans = 0;     for (int i = 2; i <= N; i++) {       int L = max(1, i - 120);       int sum = a[i];       int pmax = a[i];       int res = 0;       for (int j = i - 1; j >= L; j--) {         pmax = max(pmax, a[j]);         sum += a[j];         if (sum & 1) continue;         if (pmax > sum / 2) res += 1;       }       ans += dp[i][0] - res;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 810000;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n;   struct segg {     long long son[N][2], siz[N], cnt = 0, val[N], rd[N], root, x, y, z, sum[N];     inline long long New_Node(long long x) {       cnt++;       val[cnt] = sum[cnt] = x;       siz[cnt] = 1;       rd[cnt] = rand();       return cnt;     }     inline void UpDate(long long x) {       siz[x] = siz[son[x][0]] + siz[son[x][1]] + 1;       sum[x] = sum[son[x][0]] + sum[son[x][1]] + val[x];     }     void Split(long long root, long long k, long long &x, long long &y) {       if (!root)         x = y = 0;       else {         if (val[root] > k) {           y = root;           Split(son[root][0], k, x, son[root][0]);         } else {           x = root;           Split(son[root][1], k, son[root][1], y);         }         UpDate(root);       }     }     long long Merge(long long x, long long y) {       if (!x || !y) return x + y;       if (rd[x] < rd[y]) {         son[x][1] = Merge(son[x][1], y);         UpDate(x);         return x;       } else {         son[y][0] = Merge(x, son[y][0]);         UpDate(y);         return y;       }     }     void Insert(long long s) {       Split(root, s, x, y);       root = Merge(Merge(x, New_Node(s)), y);     }     void Delete(long long s) {       Split(root, s, x, z);       Split(x, s - 1, x, y);       y = Merge(son[y][0], son[y][1]);       root = Merge(Merge(x, y), z);     }     void Rankdx(long long s) {       Split(root, s - 1, x, y);       printf( %lld n , siz[x] + 1);       root = Merge(x, y);     }     long long dk(long long root, long long k) {       while (1) {         if (siz[son[root][0]] >= k)           root = son[root][0];         else if (siz[son[root][0]] == k - 1)           return val[root];         else           k -= siz[son[root][0]] + 1, root = son[root][1];       }     }     void Findkx(long long s) { printf( %lld n , val[dk(root, s)]); }     void Findqq(long long s) {       Split(root, s - 1, x, y);       printf( %lld n , val[dk(x, siz[x])]);       root = Merge(x, y);     }     void Findhz(long long s) {       Split(root, s, x, y);       printf( %lld n , val[dk(y, 1)]);       root = Merge(x, y);     }     long long FindS(long long x, long long p) {       if (!p) return 0;       long long qwq = 0;       while (1) {         if (p == siz[son[x][0]] + 1) return qwq + sum[son[x][0]] + val[x];         if (p <= siz[son[x][0]])           x = son[x][0];         else           qwq += sum[son[x][0]] + val[x], p = p - siz[son[x][0]] - 1,                                           x = son[x][1];       }     }   } A, B;   signed main() {     srand((unsigned)time(NULL));     n = read();     for (register long long i = 1; i <= n; i++) {       long long opt = read(), x = read();       if (!opt) {         if (x > 0)           A.Insert(-x);         else           A.Delete(x);       }       if (x > 0)         B.Insert(-x);       else         B.Delete(x);       long long qwq = B.sum[B.root];       long long res = B.siz[B.root] - A.siz[A.root];       if (!res) {         printf( %lld n , -qwq);         continue;       }       if (B.dk(B.root, res) < A.dk(A.root, 1))         printf( %lld n , -qwq - A.dk(A.root, 1) - B.FindS(B.root, res - 1));       else         printf( %lld n , -qwq - B.FindS(B.root, res));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace chu_xuan {   void swap(int &a, int &b) {     register int tmp = a;     a = b, b = tmp;   }   void read(long long &a) {     a = 0;     int b = 1, c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) b = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) a = (a << 3) + (a << 1) + c - 48, c = getchar();     a *= b;   }   int In() {     int a = 0, b = 1, c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) b = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) a = (a << 3) + (a << 1) + c - 48, c = getchar();     return a * b;   }   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a > b ? b : a; }   }  // namespace chu_xuan   using namespace chu_xuan;   const int N = 3e5;   long long n, a[N];   long long ans;   int main() {     read(n);     for (int i = 0; i < n; i++) read(a[i]);     sort(a, a + n);     for (int i = 0; i < n / 2; i++) {       ans += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long fastpow(int b, int e) {     if (!e) return 1;     if (e & 1) return b * fastpow(b, e - 1);     long long temp = fastpow(b, e / 2);     return temp * temp;   }   int notwork(char a, char b) {     set<char> s;     s.insert(a);     s.insert(b);     if (a == b && a ==  o ) return 0;     if (a == b && a ==  A ) return 0;     if (a == b && a ==  v ) return 0;     if (a == b && a ==  V ) return 0;     if (a == b && a ==  I ) return 0;     if (a == b && a ==  H ) return 0;     if (a == b && a ==  O ) return 0;     if (a == b && a ==  M ) return 0;     if (a == b && a ==  x ) return 0;     if (a == b && a ==  X ) return 0;     if (a == b && a ==  Y ) return 0;     if (a == b && a ==  w ) return 0;     if (a == b && a ==  W ) return 0;     if (a == b && a ==  U ) return 0;     if (a == b && a ==  T ) return 0;     if (s.count( b ) && s.count( d )) return 0;     if (s.count( p ) && s.count( q )) return 0;     return 1;   }   int midwork(char a) {     char arr[] = { U ,  T ,  W ,  w ,  Y ,  x ,  X ,  M ,                    o ,  O ,  H ,  I ,  v ,  V ,  A };     for (int i = 0; i < 15; i++)       if (arr[i] == a) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     int len = s.length();     int mid = len / 2;     if (s.length() & 1 == 0) mid++;     if (len & 1) {       if (!midwork(s[mid])) return cout <<  NIE , 0;     }     for (int i = 0, j = len - 1; i < mid; i++, j--) {       if (notwork(s[i], s[j])) return cout <<  NIE , 0;     }     cout <<  TAK ;     return 0;   }