#include <bits/stdc++.h>   using namespace std;   int dpo[2010][15], dpe[2010][15], a[2010], b[2010];   long long combe[15], combo[15];   long long f[2010], c[2010];   long long nck(long long n, long long k) {     if (n < k) return 0;     long long ret = (f[n] * c[k]) % 998244353;     return (ret * c[n - k]) % 998244353;   }   long long pwr(long long b, long long e) {     b %= 998244353;     if (e == 0) return 1;     if (e == 1) return b;     return (pwr(b * b, e / 2) * pwr(b, e % 2)) % 998244353;   }   int conv(string str) {     int dir = 1, ret = 0;     for (auto x : str) ret += dir * (x - 48), dir *= -1;     ret %= 11;     if (ret < 0) ret += 11;     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     f[0] = c[0] = 1;     for (int i = 1; i < 2010; i++) (f[i] = f[i - 1] * i) %= 998244353;     c[2010 - 1] = pwr(f[2010 - 1], 998244353 - 2);     for (int i = 2010 - 2; i; i--) (c[i] = c[i + 1] * (i + 1)) %= 998244353;     int T;     cin >> T;     while (T--) {       int n;       string str;       int otot = 0, etot = 0, ocnt = 0, ecnt = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> str;         if (str.length() % 2)           a[ocnt++] = conv(str);         else           b[ecnt++] = conv(str);       }       etot = accumulate(b, b + ecnt, 0) % 11;       if (ocnt == 0) {         cout << (etot ? 0 : f[n]) << endl;         continue;       }       for (int i = 0; i <= ecnt; i++) fill(dpe[i], dpe[i] + 15, 0);       dpe[0][0] = 1;       for (int i = 0; i < ecnt; i++)         for (int j = i; j >= 0; j--)           for (int rem = 0; rem < 11; rem++)             (dpe[j + 1][(rem + b[i]) % 11] += dpe[j][rem]) %= 998244353;       fill(combe, combe + 11, 0);       for (int i = 0; i <= ecnt; i++) {         long long r = f[i] * f[ecnt - i] % 998244353 *                       nck(ocnt / 2 + i, ocnt / 2) % 998244353 *                       nck((ocnt + 1) / 2 - 1 + ecnt - i, (ocnt + 1) / 2 - 1) %                       998244353;         for (int rpos = 0; rpos < 11; rpos++) {           int rneg = (rpos - etot) % 11;           if (rneg < 0) rneg += 11;           (combe[(rpos + rneg) % 11] += r * dpe[i][rpos]) %= 998244353;         }       }       otot = accumulate(a, a + ocnt, 0) % 11;       for (int i = 0; i <= ocnt; i++) fill(dpo[i], dpo[i] + 15, 0);       dpo[0][0] = 1;       for (int i = 0; i < ocnt; i++)         for (int j = i; j >= 0; j--)           for (int rem = 0; rem < 11; rem++)             (dpo[j + 1][(rem + a[i]) % 11] += dpo[j][rem]) %= 998244353;       fill(combo, combo + 11, 0);       {         int i = (ocnt + 1) / 2;         long long r = f[i] * f[ocnt - i] % 998244353;         for (int rpos = 0; rpos < 11; rpos++) {           int rneg = (rpos - otot) % 11;           if (rneg < 0) rneg += 11;           (combo[(rpos + rneg) % 11] += r * dpo[i][rpos]) %= 998244353;         }       }       long long res = 0;       for (int i = 0; i < 11; i++)         (res += combo[i] * combe[(11 - i) % 11]) %= 998244353;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   int res = 0;   int r[10];   int v[10];   int main() {     int t;     cin >> t;     while (t--) {       long long x = 1;       int n;       cin >> n;       for (int i = 3; i <= n * 2; i++) {         x = x * i % mod;       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[105];   map<int, bool> q;   int main() {     while (~scanf( %d %d , &n, &k)) {       q.clear();       for (int i = 0; i < k; i++) scanf( %d , &a[i]);       int t = 1;       int t2 = n;       for (int i = 0; i < k; i++) {         int t3 = (a[i] %= t2);         while (t3--) {           t++;           if (t > n) t = 1;           if (q[t]) t3++;         }         printf( %d%c , t, i == k - 1 ?   n  :    );         q[t] = 1;         t++;         if (t > n) t = 1;         while (q[t]) {           t++;           if (t > n) t = 1;         }         t2--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     int t = 1;     cin >> t;     int n;     while (t--) {       cin >> n;       if (n == 1 || n == 2) {         cout << 1 <<   n ;         continue;       }       if (n & 1)         cout << n / 2 + 1 <<   n ;       else         cout << n / 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     cin >> num;     for (int i = 1; i <= 2 * sqrt(num); i++) {       int x = (i * (i + 1)) / 2;       int tmp = num - x;       int st = 1, en = 2 * sqrt(num);       while (st <= en) {         int mid = st + (en - st) / 2;         int y = (mid * (mid + 1)) / 2;         if (y == tmp) {           cout <<  YES  << endl;           return 0;         } else if (y < tmp) {           st = mid + 1;         } else {           en = mid - 1;         }       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma GCC optimize(3)   template <typename T>   T min(T x, T y) {     return x < y ? x : y;   }   template <typename T>   T max(T x, T y) {     return x > y ? x : y;   };   const int INF = 1000000000;   const int MAXN = 100005;   const int B = 500;   int N, M, Q;   int low[MAXN];   std::vector<int> V[MAXN], ID[MAXN], up[MAXN];   int ans[MAXN];   int f[MAXN];   void solve() {     static int mx[MAXN][25];     for (int l = 1, r; l <= N; l = r + 1) {       r = min(l + B - 1, N);       for (int i = l; i <= r; i++) {         f[i] = i;         for (int j = l; j <= i; j++)           if (f[j] >= low[i] && low[i] >= j) f[j] = i;         for (int j = 0; j < V[i].size(); j++) {           if (V[i][j] >= l) {             ans[ID[i][j]] = f[V[i][j]];             continue;           }           ans[ID[i][j]] = f[V[i][j]];           for (int k = l; k <= i; k++)             if (low[k] >= V[i][j] && low[k] <= ans[ID[i][j]]) ans[ID[i][j]] = k;         }       }       memset(mx, 0, sizeof(mx));       memset(f, 0, sizeof(f));       for (int i = r; i >= 1; i--) {         f[i] = i;         for (int j = 0; j < up[i].size(); j++) {           if (up[i][j] > r) continue;           int t = 0;           while (1 << t <= up[i][j] - i) t++;           t--;           f[i] = max(f[i], max(mx[i + 1][t], mx[up[i][j] - (1 << t) + 1][t]));         }         mx[i][0] = f[i];         for (int j = 1; j < 25; j++)           mx[i][j] = max(mx[i][j - 1], mx[min(r, i + (1 << (j - 1)))][j - 1]);       }     }     for (int i = 1; i <= Q; i++) printf( %d n , ans[i]);   }   void init() {     int l, r;     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; i++) {       scanf( %d %d , &l, &r);       if (l == r) continue;       low[r] = l;       up[l].push_back(r);     }     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       scanf( %d %d , &l, &r);       V[r].push_back(l);       ID[r].push_back(i);     }   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string a;     cin >> a;     if (n & 1) {       cout <<  :( ;       return 0;     }     int cnt1 = 1;     int cnt2 = 1;     if (a[0] ==  ) ) {       cout <<  :( ;       return 0;     }     a[0] =  ( ;     if (a.back() ==  ( ) {       cout <<  :( ;       return 0;     }     a[a.size() - 1] =  ) ;     for (int i = 1; i < a.size(); ++i)       if (a[i] ==  ( ) ++cnt1;     if (cnt1 > n / 2) {       cout <<  :( ;       return 0;     }     for (int i = 0; i < a.size(); ++i) {       if (a[i] ==  ? ) {         ++cnt1;         a[i] =  ( ;       }       if (cnt1 == n / 2) break;     }     if (cnt1 < n / 2) {       cout <<  :( ;       return 0;     }     for (int i = 0; i < a.size(); ++i)       if (a[i] ==  ? ) a[i] =  ) ;     stack<int> s;     for (int i = 0; i < a.size(); ++i) {       if (a[i] ==  ( )         s.push(a[i]);       else {         if (s.empty()) {           cout <<  :( ;           return 0;         } else {           s.pop();           if (s.empty() && i != a.size() - 1) {             cout <<  :( ;             return 0;           }         }       }     }     if (!s.empty()) {       cout <<  :( ;       return 0;     }     for (int i = 0; i < a.size(); ++i) cout << a[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, cnt;   int fans = 1, r2;   string b, c, d, n;   struct Node {     string s1;     string s2;     int jyh1 = -1;   } nd[107];   int find(string x) {     int ress = -1;     for (int i = 0; i < cnt; i++) {       if (nd[i].s1 == x) ress = i;     }     return ress;   }   int getans(int x, int re, int xx, int yy) {     int ccnt = 0;     int lev = 3;     if (nd[x].jyh1 == -1) {       for (int i = 0; i < nd[x].s2.length();) {         if (nd[x].s2[i] ==  ( ) {           ccnt++;           i += 2;           continue;         } else if (nd[x].s2[i] ==  ) ) {           ccnt--;           i += 2;           continue;         } else if (isdigit(nd[x].s2[i])) {           while (isdigit(nd[x].s2[i]) && i < nd[x].s2.length()) i++;           i++;           continue;         } else if ((nd[x].s2[i] ==  +  || nd[x].s2[i] ==  - ) && ccnt == 0) {           lev = min(1, lev);           i += 2;           continue;         } else if ((nd[x].s2[i] ==  *  || nd[x].s2[i] ==  / ) && ccnt == 0) {           lev = min(2, lev);           i += 2;           continue;         } else {           string got =   ;           int l = i - 2;           while (nd[x].s2[i] !=     && i < nd[x].s2.length()) {             got += nd[x].s2[i];             i++;           }           if (find(got) == -1) {             i++;             continue;           } else {             int tg = getans(find(got), x, l, i + 1);             if (ccnt == 0) lev = min(r2, lev);             fans = min(fans, tg);             i++;             continue;           }         }       }       nd[x].jyh1 = lev;     }     lev = nd[x].jyh1;     r2 = lev;     if (lev == 3) return 1;     if (lev == 1 &&         (nd[re].s2[xx] ==  -  || nd[re].s2[xx] ==  *  || nd[re].s2[xx] ==  /  ||          nd[re].s2[yy] ==  *  || nd[re].s2[yy] ==  / ))       return 0;     else if (lev == 1)       return 1;     if (lev == 2 && nd[re].s2[xx] ==  / )       return 0;     else if (lev == 2)       return 1;   }   int main() {     cin >> a;     getline(cin, b);     for (int i = 0; i <= a; i++) {       c =   ;       d =   ;       n =   ;       getline(cin, b);       for (int j = 1; j < b.length(); j++) {         if (b[j] ==  e  && b[j - 1] ==  n ) {           j++;           while (b[j] ==    ) j++;           while (b[j] !=    ) {             n += b[j];             j++;           }           b.erase(0, j);           break;         }       }       for (int j = 0; j < b.length(); j++) {         if (b[j] !=    ) d += b[j];       }       b = d;       b =     + b;       for (int j = 1; j < b.length(); j++) {         if (((b[j - 1] ==  +  || b[j - 1] ==  -  || b[j - 1] ==  *  ||               b[j - 1] ==  /  || b[j - 1] ==  (  || b[j - 1] ==  ) ) &&              b[j] !=    ) ||             ((b[j] ==  +  || b[j] ==  -  || b[j] ==  *  || b[j] ==  /  ||               b[j] ==  (  || b[j] ==  ) ) &&              b[j - 1] !=    ))           c +=    , c += b[j];         else           c += b[j];       }       if (i == a) n =  MaIN ;       nd[cnt].s1 = n;       nd[cnt].s2 = c;       cnt++;     }     nd[cnt].s1 =   ;     nd[cnt].s2 =  ( MaIN ) ;     cnt++;     getans(cnt - 2, cnt - 1, 0, 7);     if (fans == 1)       cout <<  OK  << endl;     else       cout <<  Suspicious  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, x, a[3000], b[3000], qmi[3000], ymi[3000];   string s;   int main() {     iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];       a[i + 1] += a[i];     }     for (int j = 0; j < m; j++) {       cin >> b[j + 1];       b[j + 1] += b[j];     }     cin >> x;     for (int l = 1; l <= n; l++) {       qmi[l] = x + 1;       for (int j = 0; j + l <= n; j++) {         qmi[l] = min(qmi[l], a[j + l] - a[j]);       }     }     for (int l = 1; l <= m; l++) {       ymi[l] = x + 1;       for (int j = 0; j + l <= m; j++) {         ymi[l] = min(ymi[l], b[j + l] - b[j]);       }     }     int ans = 0;     for (int l = 1; l <= n; l++) {       for (int xl = 1; xl <= m; xl++) {         if (qmi[l] <= x / ymi[xl]) {           ans = max(ans, l * xl);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, k, sum = 0;     bool flag = false;     set<long long> S;     scanf( %I64d%I64d , &n, &k);     for (i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         S.insert(i);         S.insert(n / i);       }     }     if (S.size() >= k) flag = true;     if (flag) {       set<long long>::iterator it;       it = S.begin();       while (k--) {         it++;       }       it--;       cout << *it;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   int n, m, seg[300005], lazy[300005], d[200005], l[200005], r[200005], q[200005];   bool b = 1;   void update(int root, int lo, int hi, int l, int r, int val) {     if (lazy[root]) {       seg[root] |= lazy[root];       if (lo ^ hi) {         lazy[root * 2 + 1] |= lazy[root];         lazy[root * 2 + 2] |= lazy[root];       }       lazy[root] = 0;     }     if (lo >= l && hi <= r) {       seg[root] |= val;       if (lo ^ hi) {         lazy[root * 2 + 1] |= val;         lazy[root * 2 + 2] |= val;       }     } else if (lo > r || hi < l)       return;     else {       update(root * 2 + 1, lo, (lo + hi) / 2, l, r, val);       update(root * 2 + 2, (lo + hi) / 2 + 1, hi, l, r, val);     }   }   int query(int root, int lo, int hi, int l, int r) {     if (lazy[root]) {       seg[root] |= lazy[root];       if (lo ^ hi) {         lazy[root * 2 + 1] |= lazy[root];         lazy[root * 2 + 2] |= lazy[root];       }       lazy[root] = 0;     }     if (lo >= l && hi <= r) {       if (lo == hi) d[lo] = seg[root];       return seg[root];     } else if (lo > r || l > hi)       return -1;     else       return query(root * 2 + 1, lo, (lo + hi) / 2, l, r) &              query(root * 2 + 2, (lo + hi) / 2 + 1, hi, l, r);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , l + i, r + i, q + i);       update(0, 0, n - 1, l[i] - 1, r[i] - 1, q[i]);     }     for (int i = 0; i < m && b; i++)       b = query(0, 0, n - 1, l[i] - 1, r[i] - 1) == q[i];     if (b) {       printf( YES n );       for (int i = 0; i < n; i++)         printf( %d%c , d[i] ? d[i] : query(0, 0, n - 1, i, i),                i + 1 < n ? 32 : 10);     } else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     vector<long long int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     long long int s, t;     cin >> s >> t;     long long int sum1 = 0;     for (int i = min(s, t) - 1; i < max(s, t) - 1; i++) {       sum1 += v[i];     }     long long int sum2 = 0;     for (int i = max(s, t) - 1;; i = (i + 1) % n) {       if (i == min(s, t) - 1) break;       sum2 += v[i];     }     cout << min(sum1, sum2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1000000007;   const double PI = acos(-1.0);   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   int n, m;   long long ans;   int a[100005];   int b[2000];   int c[2000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k, x;     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       int num;       cin >> num;       b[num]++;     }     for (int i = 0; i < k; i++) {       int cnt = 1;       memset(c, 0, sizeof(c));       for (int j = 0; j <= 1111; j++) {         if (b[j]) {           if ((cnt & 1)) {             c[j ^ x] += (b[j] + 1) / 2;             c[j] += b[j] / 2;           } else {             c[j ^ x] += b[j] / 2;             c[j] += (b[j] + 1) / 2;           }           cnt += b[j];         }       }       for (int j = 0; j <= 1111; j++) b[j] = c[j];     }     int ans1 = 0, ans2 = 0x3f3f3f3f;     for (int j = 0; j <= 1111; j++)       if (b[j]) {         ans1 = max(ans1, j);         ans2 = min(ans2, j);       }     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int ind = 0;     vector<int> v;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       v.push_back(temp);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       if (v[i] - ind == 1) {         ind++;       } else {         break;       }     }     printf( %d , ind + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int maxm = 500 * 500 + 10;   const int inf = 1e9;   const long long mod = 1e9 + 7;   int getint() {     char c;     while ((c = getchar()) && !(c >=  0  && c <=  9 ) && c !=  - )       ;     int ret = c -  0 , sgn = 0;     if (c ==  - ) sgn = 1, ret = 0;     while ((c = getchar()) && c >=  0  && c <=  9 ) ret = ret * 10 + c -  0 ;     if (sgn) ret = -ret;     return ret;   }   vector<int> g[maxn], h[maxn];   int cnt;   int vis[maxn];   void dfs(int u) {     vis[u] = 1;     h[cnt].push_back(u);     int sz = g[u].size();     for (int i = 0; i < sz; i++) {       int v = g[u][i];       if (vis[v]) continue;       dfs(v);     }   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       int i;       for (i = 1; i <= n; i++) g[i].clear(), h[i].clear();       for (i = 1; i <= n; i++) {         int x = getint();         g[i].push_back(x), g[x].push_back(i);       }       memset(vis, 0, sizeof(vis));       cnt = 0;       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           cnt++;           dfs(i);         }       }       int flag = 0, ff = 1;       int center1 = -1, center2 = -1;       for (int i = 1; i <= cnt; i++) {         int sz = h[i].size();         if (sz == 1) center1 = i, flag = 1;         if (sz == 2) center2 = i, flag = 1;         if (sz >= 3 && sz & 1) {           ff = 0;         }       }       if (center1 == -1 && center2 == -1) {         puts( NO );         continue;       } else if (center1 == -1 && !ff) {         puts( NO );         continue;       }       puts( YES );       if (center1 != -1) {         int u = h[center1][0];         for (int i = 1; i <= cnt; i++)           if (i != center1) {             int sz = h[i].size();             for (int j = 0; j < sz; j++) {               printf( %d %d n , u, h[i][j]);             }           }       } else {         int u = h[center2][0], v = h[center2][1];         printf( %d %d n , u, v);         for (int i = 1; i <= cnt; i++)           if (i != center2) {             int sz = h[i].size();             for (int j = 0; j < sz; j++) {               if (j & 1) {                 printf( %d %d n , u, h[i][j]);               } else                 printf( %d %d n , v, h[i][j]);             }           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 1e5 + 10;   long long power(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       if (ret >= MOD) ret %= MOD;       if (a >= MOD) a %= MOD;       b >>= 1;     }     return ret;   }   long long invmod(long long x) { return power(x, MOD - 2); }   long long dp[55][2];   long long a[55];   long long n;   long long go(long long pos, long long check) {     if (pos == n + 1) return 0;     if (dp[pos][check] != -1) return dp[pos][check];     long long ans = 0;     if (check == 0) {       ans += max(a[pos] + go(pos + 1, check ^ 1), go(pos + 1, check));     } else {       ans += min(go(pos + 1, check ^ 1), a[pos] + go(pos + 1, check));     }     dp[pos][check] = ans;     return ans;   }   long long go1(long long pos, long long check) {     if (pos == n + 1) return 0;     if (dp[pos][check] != -1) return dp[pos][check];     long long ans = 0;     if (check == 0) {       ans += min(go1(pos + 1, check ^ 1), a[pos] + go1(pos + 1, check));     } else {       ans += max(a[pos] + go1(pos + 1, check ^ 1), go1(pos + 1, check));     }     dp[pos][check] = ans;     return ans;   }   int32_t main() {     cin >> n;     long long sum = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     memset(dp, -1, sizeof(dp));     long long k = go1(1, 0);     cout << k <<     << sum - k << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool G[100005];   bool use[100005];   int top[100005];   int Top[100005];   char R[100005];   int num[100005];   int main() {     int m, n, Len = 0, useLen = 0;     char str[10];     memset(G, true, sizeof(G));     memset(use, false, sizeof(use));     scanf( %d%d , &n, &m);     int number = 0, last = 0;     for (int i = 0; i < m; i++) {       scanf( %s %d , str, &num[i]);       R[i] = str[0];     }     for (int i = 0; i < m; i++) {       int a;       str[0] = R[i];       a = num[i];       if (str[0] ==  + ) {         if (number != 0 || (Len != 0 && use[a] == false)) G[a] = false;         last = a;         number++;       }       if (str[0] ==  - ) {         if (use[a] == false) {           for (int i = Len - 1; i >= useLen; i--) {             G[Top[i]] = false;           }           useLen = Len;           if (number != 0 || (i != m - 1 && a != num[i + 1])) G[a] = false;         } else {           if (number > 1 || (number == 1 && i != m - 1 && num[i + 1] != a))             G[a] = false;           number--;         }       }       if (use[a] == false) {         Top[Len++] = a;         use[a] = true;       }     }     int sum = 0;     for (int i = 1; i <= n; i++)       if (G[i]) {         top[sum++] = i;       }     printf( %d n , sum);     if (sum > 0) {       for (int i = 0; i < sum - 1; i++) printf( %d  , top[i]);       printf( %d n , top[sum - 1]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:32000000 )   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   const int maxn = 300100;   struct state {     int len, link;     map<char, int> next;     int cnt[3];     state() { memset(cnt, 0, sizeof(cnt)); }   };   const int MAXLEN = 300100;   state st[MAXLEN * 2];   int sz, last;   void sa_init() {     sz = last = 0;     st[0].len = 0;     st[0].link = -1;     ++sz;   }   int KK;   vector<int> states[maxn];   void sa_extend(char c) {     int cur = sz++;     st[cur].len = st[last].len + 1;     if (c >=  a  && c <=  z ) st[cur].cnt[KK] = 1;     int p;     for (p = last; p != -1 && !st[p].next.count(c); p = st[p].link)       st[p].next[c] = cur;     if (p == -1)       st[cur].link = 0;     else {       int q = st[p].next[c];       if (st[p].len + 1 == st[q].len)         st[cur].link = q;       else {         int clone = sz++;         st[clone].len = st[p].len + 1;         st[clone].next = st[q].next;         st[clone].link = st[q].link;         for (; p != -1 && st[p].next[c] == q; p = st[p].link)           st[p].next[c] = clone;         st[q].link = st[cur].link = clone;       }     }     last = cur;   }   const int mod = 1000000007;   struct num {     int x;     num() : x(0) {}     num(int x) : x(x) {}     num operator+(const num& o) const {       num res(x + o.x);       if (res.x >= mod) res.x -= mod;       return res;     }     num operator-(const num& o) const {       num res(x - o.x);       if (res.x < 0) res.x += mod;       return res;     }     num operator*(const num& o) const { return num(x * (long long)o.x % mod); }   };   num add[maxn];   num ans[maxn];   int main() {     string s1, s2, s3;     cin >> s1 >> s2 >> s3;     sa_init();     KK = 0;     for (int i = 0; i < int((s1).size()); ++i) sa_extend(s1[i]);     sa_extend( A );     KK = 1;     for (int i = 0; i < int((s2).size()); ++i) sa_extend(s2[i]);     sa_extend( B );     KK = 2;     for (int i = 0; i < int((s3).size()); ++i) sa_extend(s3[i]);     sa_extend( C );     for (int i = 0; i < sz; ++i) states[st[i].len].push_back(i);     for (int ii = maxn - 1; ii >= 1; --ii) {       for (int i = 0; i < int((states[ii]).size()); ++i) {         int curst = states[ii][i];         for (int iter = 0; iter < 3; ++iter)           st[st[curst].link].cnt[iter] += st[curst].cnt[iter];       }     }     for (int i = 1; i < sz; ++i) {       num curres = num(st[i].cnt[0]) * num(st[i].cnt[1]) * num(st[i].cnt[2]);       add[st[i].len] = add[st[i].len] + curres;       int lf = st[st[i].link].len;       add[lf] = add[lf] - curres;     }     num cr(0);     for (int i = maxn - 1; i >= 0; --i) {       cr = cr + add[i];       ans[i] = cr;     }     int to = min(int((s1).size()), min(int((s2).size()), int((s3).size())));     for (int i = 0; i < to; ++i) printf( %d  , ans[i + 1].x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modmulti(long long int a, long long int b, long long int m) {     return ((a % m) * (b % m)) % m;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int power(long long int x, long long int y, long long int m) {     if (y == 0) return 1;     long long int p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long int power2(long long int x, long long int y) {     if (y == 0) return 1;     long long int p = power2(x, y / 2);     p = (p * p);     return (y % 2 == 0) ? p : (x * p);   }   bool cmp(pair<long long int, long long int>& a,            pair<long long int, long long int>& b) {     if (a.first == b.first)       return (a.second < b.second);     else       return (a.first > b.first);   }   long long int bin(vector<long long int> a, long long int left,                     long long int right, long long int x) {     long long int mid = left + (right - left) / 2;     if (a[mid] == x) return mid;     if (left <= right) {       if (a[mid] < x)         return bin(a, mid + 1, right, x);       else if (a[mid] > x)         return bin(a, left, mid - 1, x);     }     return -1;   }   long long int findclosest(long long int n) {     long long int i;     for (i = 0; i <= 64; i++) {       if (power2(2, i) <= n)         continue;       else         break;     }     return power2(2, i - 1);   }   long long int get_signi(long long int n) {     while (n >= 10) {       n = n / 10;     }     return n;   }   long long int get_digits(long long int n) {     long long int i = 0;     while (n >= 10) {       n = n / 10;       i++;     }     return i;   }   bool is_palindrome(string t) {     for (int i = 0; i < t.size() / 2; i++) {       if (t[i] != t[t.size() - i - 1]) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     string second;     cin >> second;     string t =   ;     long long int last_index = 0, i, j;     for (i = 0; i < 26; i++) {       for (j = last_index; j < second.size(); j++) {         if (second[j] ==  a  + 25 - i) {           t += second[j];           last_index = j;         }       }     }     cout << t <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 2500000000;   const int inf = 123456789;   const double EPS = 1e-9;   const double PI = 2 * asin(1.0);   const long long mod = 1e9 + 7;   int double_cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   const int N = 3e5;   int n;   int t[2 * N][2];   void modify(int p, int value, int q) {     for (t[p += n][q] += value; p > 1; p >>= 1)       t[p >> 1][q] = t[p][q] + t[p ^ 1][q];   }   int query(int l, int r, int q) {     int res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res += t[l++][q];       if (r & 1) res += t[--r][q];     }     return res;   }   int main() {     scanf( %d , &n);     int k;     scanf( %d , &k);     int a, b;     scanf( %d%d , &a, &b);     int q;     scanf( %d , &q);     a -= b;     for (int i = 0; i < q; ++i) {       int s;       scanf( %d , &s);       if (s == 1) {         int x, y;         scanf( %d%d , &x, &y);         int aux = min(b - t[x + n][0], y);         int aux2 = max(0, min(a - t[x + n][1], y - aux));         modify(x, aux, 0);         modify(x, aux2, 1);       } else {         int x;         scanf( %d , &x);         long long saida =             query(1, x, 0) + query(x + k, n + 1, 1) + query(x + k, n + 1, 0);         cout << saida << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool benar;   string ans, st;   int main() {     scanf( %d , &n);     vector<string> data;     while (cin >> st) data.push_back(st);     if (data[0] ==  int ) {       if (data.size() == 1)         printf( %s n , data[0].c_str());       else         printf( Error occurred n );     } else {       vector<int> q;       q.push_back(0);       benar = true;       ans =  pair< ;       for (int i = 1; i < data.size(); i++) {         if (data[i] ==  pair ) {           if (q.size() == 0) {             benar = false;             break;           }           ans +=  pair< ;           q[q.size() - 1]++;           q.push_back(0);         } else {           if (q.size() == 0) {             benar = false;             break;           }           ans +=  int ;           q[q.size() - 1]++;           while (q.size()) {             if (q[q.size() - 1] == 2) {               ans +=  > ;               q.pop_back();             } else               break;           }           if (q.size())             if (q[q.size() - 1] == 1) ans +=  , ;         }       }       if (q.size()) benar = false;       if (benar)         printf( %s n , ans.c_str());       else         printf( Error occurred n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long int bexp(long long int a, long long int b, long long int mod) {     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   const long long int N = 1000010;   const long long int mod = 1e9 + 7;   struct comp {     bool operator()(const pair<long long int, long long int> a,                     const pair<long long int, long long int> b) const {       return a.second > b.second;     }   };   long long int dp[N] = {}, prime[N] = {};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     long long int t;     cin >> t;     dp[1] = 1;     prime[1] = 1;     long long int cnt = 1;     for (long long int i = 2; i < N; ++i) {       if (prime[i] == 0) {         cnt++;         for (long long int j = i * i; j < N; j += i) {           prime[j] = 1;         }       }       long long int k = sqrt(i);       if (k * k == i && prime[k] == 0) {         cnt--;       }       dp[i] = cnt;     }     for (long long int i = 0; i < t; ++i) {       long long int n;       cin >> n;       cout << dp[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   float r, p, m;   float a[100 * 1000];   int main() {     cin >> m >> r;     p = r * sqrt(2);     a[0] = 2 * r;     a[1] = 2 * r + p;     for (int i = (2), _end = (m); i < _end; ++i) {       a[i] = 2 * p;       a[i] += 2 * r * (i - 1);     }     float sum = 0;     sum += a[0] * m;     for (int i = (1), _end = (m); i < _end; ++i) {       sum += 2 * (m - i) * a[i];     }     sum = sum / (m * m);     printf( %.9f n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long;   using ld = long double;   mt19937 rnd(time(nullptr));   lli GCD(lli a, lli b) {     if (b == 0) return a;     return GCD(b, a % b);   }   lli LCM(lli a, lli b) { return a / GCD(a, b) * b; }   inline void Solve() {     lli n = 0;     cin >> n;     vector<lli> data(n);     for (auto &it : data) {       cin >> it;       while (it % 2 == 0) it /= 2;       while (it % 3 == 0) it /= 3;     }     for (lli i = 1; i < n; i++) {       if (data[i] != data[i - 1]) {         cout <<  No ;         return;       }     }     cout <<  Yes ;   }   signed main() {     cout << fixed << setprecision(20);     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k;     cin >> n >> m >> k;     long long int b[n];     memset(b, 0, sizeof(b));     vector<pair<long long int, long long int> > a;     for (int i = 0; i < n; i++) {       long long int x;       cin >> x;       a.push_back(make_pair(x, i));     }     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     long long int sum = 0;     for (int i = 0; i < k * m; i++) {       b[a[i].second] = 1;       sum += a[i].first;     }     long long int l = 0, p = 0;     cout << sum << endl;     for (int i = 0; i < n; i++) {       l = l + b[i];       if (l == m) {         p++;         cout << i + 1 <<    ;         l = 0;       }       if (p == k - 1) break;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<vector<pair<int, string> > > rg(m, vector<pair<int, string> >(1));     for (int i = 0; i < n; i++) {       string sn;       int r, s;       cin >> sn;       scanf( %d %d , &r, &s);       rg[r - 1].push_back(make_pair(s, sn));     }     for (int i = 0; i < m; i++) {       rg[i][0] = make_pair(-10,  xD );       sort(rg[i].begin(), rg[i].end());       reverse(rg[i].begin(), rg[i].end());       cout << (rg[i][1].first == rg[i][2].first                    ?  ?                     : string(rg[i][0].second +     + rg[i][1].second))            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   long long POW(long long a, long long b, long long MMM = MOD) {     long long ret = 1;     for (; b; b >>= 1, a = (a * a) % MMM)       if (b & 1) ret = (ret * a) % MMM;     return ret;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) {     if (a == 0 || b == 0) return a + b;     return a * (b / gcd(a, b));   }   int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};   vector<int> v[2];   vector<pair<int, int> > ans;   int main() {     v[0].push_back(0);     v[1].push_back(0);     int n;     scanf( %d , &n);     for (int(i) = (1); (i) <= (n); (i) += (1)) {       int x;       scanf( %d , &x);       v[x - 1].push_back(i);     }     for (int(t) = (1); (t) <= (n); (t) += (1)) {       int cnt[2] = {0};       int now = 0, last = -1;       while (1) {         int p1 = upper_bound(v[0].begin(), v[0].end(), now) - v[0].begin() - 1;         int p2 = upper_bound(v[1].begin(), v[1].end(), now) - v[1].begin() - 1;         if (p1 + t >= v[0].size() && p2 + t >= v[1].size()) break;         int t1 = 987654321, t2 = 987654321;         if (p1 + t < v[0].size()) t1 = v[0][p1 + t];         if (p2 + t < v[1].size()) t2 = v[1][p2 + t];         if (t1 < t2) {           cnt[0]++;           last = 0;           now = t1;         } else {           cnt[1]++;           last = 1;           now = t2;         }       }       if (now == n) {         if (cnt[0] > cnt[1] && last == 0) ans.push_back(make_pair(cnt[0], t));         if (cnt[0] < cnt[1] && last == 1) ans.push_back(make_pair(cnt[1], t));       }     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (auto a : ans) printf( %d %d n , a.first, a.second);   }


#include <bits/stdc++.h>   using namespace std;   int options[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};   int main(void) {     string s;     cin >> s;     int total = 1;     for (int i = 0; i < 2; ++i) {       total *= options[s[i] -  0 ];     }     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[512];   int main() {     int n, t;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       vector<int> ans;       for (int i = 1; i <= n; i++) {         for (int j = 1; j < n - 1; j++) {           if (a[j] > a[j + 1]) {             swap(a[j], a[j + 2]);             swap(a[j], a[j + 1]);             ans.emplace_back(j);             ans.emplace_back(j);           } else if (a[j + 1] > a[j + 2]) {             swap(a[j], a[j + 1]);             swap(a[j], a[j + 2]);             ans.emplace_back(j);           }         }       }       int i;       for (i = 2; i <= n; i++)         if (a[i] < a[i - 1]) break;       if (i <= n)         printf( -1 n );       else {         printf( %d n , ans.size());         for (int x : ans) printf( %d  , x);         ;         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   long long dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const long double pi = 3.141592653589;   const long long mod = 1000000007;   const long long maxn = 1e5 + 5;   template <typename T>   void printv(const vector<T>& v) {     for (auto i : v) cout << i <<    ;     cout <<   n ;   }   template <typename T>   void printv(const vector<pair<T, T>>& v) {     for (auto p : v) cout <<  (  << p.first <<  ,  << p.second <<  ), ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long n;     string s;     cin >> n >> s;     long long open = 0, closed = 0;     for (auto i : s) {       if (i ==  ( )         open++;       else         closed++;     }     if ((n & 1) || (open != closed))       cout << -1 <<   n ;     else {       long long ans = 0;       long long ck = 0;       for (auto i : s) {         if (i ==  ( )           ck++;         else {           ck--;           if (ck < 0) {             ans += 2;           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n;   struct Data {     int s, id;     bool operator<(const Data &a) const { return s < a.s; }   } da[N];   int a[N], b[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int s;       scanf( %d , &s);       da[i] = Data{s, i};     }     sort(da, da + n);     for (int i = 0; i < (n + 2) / 3; i++) {       a[da[i].id] = i;       b[da[i].id] = da[i].s - i;     }     int x = (n + 2) / 3;     for (int i = x; i < min(x + x, n); i++) {       a[da[i].id] = 0;       b[da[i].id] = da[i].s;     }     for (int i = x + x; i < n; i++) {       a[da[i].id] = da[i].s - (n - i - 1);       b[da[i].id] = n - i - 1;     }     puts( YES );     for (int i = 0; i < n; i++) {       printf( %d%c , a[i],    n [i == n - 1]);     }     for (int i = 0; i < n; i++) {       printf( %d%c , b[i],    n [i == n - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     vector<pair<long long, long long> > arr;     long long n = s.length();     for (int i = 0; i < n; i++) {       for (int j = 1; i + (2 * j) < n; j++) {         if (s[i] == s[i + j] && s[i] == s[i + (2 * j)]) {           arr.push_back(make_pair(i + (2 * j), i));           break;         }       }     }     sort(arr.begin(), arr.end());     long long cnt = 0;     for (int i = 0, j = 0; i < n; i++) {       while (j < arr.size() && arr[j].second < i) j++;       if (j == arr.size()) break;       cnt += (n - arr[j].first);     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     int n, maxf;     cin >> n;     int h[n];     for (int i = 0; i < n; i++) cin >> h[i];     maxf = h[n - 1];     h[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       if (h[i] > maxf) {         maxf = h[i];         h[i] = 0;       } else         h[i] = maxf - h[i] + 1;     }     for (int i = 0; i < n; i++) cout << h[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, mod = 998244353;   int n, m, x, y;   vector<int> e[2][N];   inline void adde(int x, int y, int o) { e[o][x].push_back(y); }   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) -  0  + ch;       ch = getchar();     }     return x * f;   }   void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   int dis[19][N];   bool vis[19][N];   queue<pair<int, int> > q;   int spfa() {     memset(dis, 63, sizeof(dis));     q.push(pair<int, int>(0, 1));     dis[0][1] = 0;     while (!q.empty()) {       int u = q.front().second, k = q.front().first;       q.pop();       vis[k][u] = 0;       for (int v : e[k & 1][u]) {         if (dis[k][v] > dis[k][u] + 1) {           dis[k][v] = dis[k][u] + 1;           if (!vis[k][v]) vis[k][v] = 1, q.push(pair<int, int>(k, v));         }       }       if (k < 18) {         if (dis[k + 1][u] > dis[k][u] + (1 << k)) {           dis[k + 1][u] = dis[k][u] + (1 << k);           if (!vis[k + 1][u]) vis[k + 1][u] = 1, q.push(pair<int, int>(k + 1, u));         }       }     }     int res = 1e9 + 7;     for (int i = 0; i <= 18; ++i) res = min(res, dis[i][n]);     return res;   }   queue<int> Q, tmp;   int diss[N];   inline int qbit(int x) {     int res = 1, t = 2;     for (; x; x >>= 1)       x & 1 ? (res = 1ll * res * t % mod) : 1, t = 1ll * t * t % mod;     return res;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; ++i) {       x = read(), y = read();       adde(x, y, 0), adde(y, x, 1);     }     int ans = spfa();     if (ans < 1e9) return write(ans), 0;     memset(diss, 63, sizeof(diss));     diss[1] = 0, Q.push(1), tmp.push(1);     for (int k = 0;; ++k) {       while (!Q.empty()) {         int u = Q.front();         Q.pop();         if (u == n) return write((qbit(k) - 1 + diss[u]) % mod), 0;         for (int v : e[k & 1][u])           if (diss[v] > diss[u] + 1)             diss[v] = diss[u] + 1, Q.push(v), tmp.push(v);       }       while (!tmp.empty()) Q.push(tmp.front()), tmp.pop();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       int c = 0;       string ans =  -1 , temp;       for (int i = 0; i < m; i++) {         temp = v[0];         for (char j =  a ; j <=  z ; j++) {           temp[i] = j;           for (int k = 0; k < n; k++) {             c = 0;             for (int l = 0; l < m; l++)               if (v[k][l] != temp[l]) c++;             if (c > 1) break;           }           if (c <= 1) {             ans = temp;             break;           }         }         if (ans !=  -1 ) break;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const double INF = DBL_MAX;   bool iszero(const double a) { return fabs(a) <= eps; }   double sqr(const double a) { return a * a; }   int sgn(const double a) {     if (a < -eps) return -1;     return (a > eps);   }   int cmp(const double a, const double b) { return sgn(a - b); }   int inint() {     int t;     scanf( %d , &t);     return t;   }   const int N = 4010;   const long long p = 1e9 + 7;   struct ll {     long long l;     ll(long long a = 0) : l(a % p) {}     ll operator+(ll a) { return (l + a.l) % p; }     ll operator+=(ll a) {       l = (l + a.l) % p;       return *this;     }     ll operator+(long long a) { return ll((l + a) % p); }     ll operator+=(long long a) {       l = (l + a) % p;       return *this;     }     ll operator*(ll a) { return ll((l * a.l) % p); }     ll operator*(long long a) { return ll((l * a) % p); }     ll operator=(long long a) {       l = a % p;       return *this;     }     ll operator=(ll a) {       l = a.l % p;       return *this;     }     long long operator*() { return l; }   };   ll C[N][N];   void init() {     for (int i = 0; i < N; i++) C[i][0] = 1;     for (int i = 1; i < N; i++)       for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];   }   ll a[N][N], bell[N], cnt[N];   void init2() {     a[0][0] = bell[0] = 1;     a[1][1] = bell[1] = 1;     for (int i = 2; i < N; i++) {       a[i][1] = a[i - 1][i - 1];       for (int j = 2; j <= i; j++) a[i][j] = a[i][j - 1] + a[i - 1][j - 1];       bell[i] = a[i][i];     }   }   void solve() {     int n = inint();     ll ans;     for (int i = 0; i < n; i++) ans += bell[i] * C[n][i];     cout << (*ans) << endl;   }   int main() {     init();     init2();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int g, t, n;   int main() {     cin >> n >> n;     cin >> s;     int l = s.size();     for (int i = 0; i < l; i++) {       if (s[i] ==  T )         t = i;       else if (s[i] ==  G )         g = i;     }     if (g < t) swap(g, t);     int i;     if ((g - t) % n != 0) {       cout <<  NO ;       return 0;     }     for (i = t; i <= g; i += n) {       if (s[i] ==  # ) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> me;   long long sum(long long x) { return (x * (x + 1)) / 2; }   int main() {     int k;     string s;     cin >> k >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         me.push_back(i);       }     }     long long ans = 0, cnt = 0, idx = -1;     if (k == 0) {       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  1 ) {           ans += sum(cnt);           cnt = 0;         } else {           cnt++;         }       }       ans += sum(cnt);     } else {       long long fst = -1;       for (int i = 0; i < me.size(); i++) {         long long idx = me[i];         cnt = 0;         if ((i + k - 1) == me.size() - 1) {           ans += ((idx - fst) * (s.size() - me[i + k - 1]));         } else if (i + k - 1 < me.size() - 1) {           ans += ((idx - fst) * (me[i + k] - me[i + k - 1]));         }         fst = me[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void test_case() {     const int N = 55;     int n, x, y, m = 0;     cin >> n;     int arr[N][N] = {0};     map<int, pair<int, int>> pos;     deque<int> ci, sally;     vector<pair<pair<int, int>, pair<int, int>>> ans;     for (int k = 0; k < n; ++k) {       cin >> x;       ci.push_back(x);     }     int k = 0;     for (auto z : ci) {       for (int j = 0; j < z; ++j) {         cin >> arr[k][j];         sally.push_back(arr[k][j]);         pos[arr[k][j]] = {k, j};       }       k++;     }     sort(sally.begin(), sally.end());     for (int i = 0; i < n; ++i) {       for (int j = 0; j < ci.front(); ++j) {         if (pos[sally.front()].first == i && pos[sally.front()].second == j)           sally.pop_front();         else {           m++;           ans.push_back(               {{pos[sally.front()].first, pos[sally.front()].second}, {i, j}});           pos[arr[i][j]] = {pos[sally.front()].first, pos[sally.front()].second};           arr[pos[sally.front()].first][pos[sally.front()].second] = arr[i][j];           sally.pop_front();         }       }       ci.pop_front();     }     cout << m << endl;     for (auto x : ans) {       cout << x.first.first + 1 <<     << x.first.second + 1 <<                << x.second.first + 1 <<     << x.second.second + 1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1;     while (t--) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[210], in[10];   int cnt[10], r[10];   int main() {     scanf( %s %s , in, str);     int l = strlen(in);     for (int i = 0; i < l; i++) {       if (in[i] ==  9 )         cnt[6]++;       else if (in[i] ==  5 )         cnt[2]++;       else         cnt[in[i] -  0 ]++;     }     l = strlen(str);     for (int i = 0; i < l; i++) {       if (str[i] ==  9 )         r[6]++;       else if (str[i] ==  5 )         r[2]++;       else         r[str[i] -  0 ]++;     }     int ans = 0x7fffffff;     for (int i = 0; i <= 9; i++) {       if (cnt[i] == 0) continue;       ans = min(ans, r[i] / cnt[i]);     }     cout << ans << endl;   }


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


#include<bits/stdc++.h>   #include<iostream>   #include<string>   #include<cmath>   #include<cstdio>   #include<cctype>   #include<cstring>   #include<iomanip>   #include<cstdlib>   #include<ctime>   #include<set>   #include<map>   #include<utility>   #include<queue>   #include<vector>   #include<stack>   #include<sstream>   #include<algorithm>   #define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)   #define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)   #define rep(i,n)for(int i=0,_n=n;i<n;i++)   #define ll long long   #define pii pair<int,int>   #define vi vector<int>   #define vpii vector<pii>   #define p_q priority_queue   #define m_p make_pair   #define pb push_back   #define ld long double   #define F first   #define S second   #define ull unsigned long long   #define mod 1000000007   #define md 998244353   #define x1 XZVJDFADSPFOE   #define y1 GASDIJSLDAEJF   #define x2 DFDAJKVOHKWIW   #define y2 PSFSAODSXVNMQ   #define LLINF 0x3f3f3f3f3f3f3f3fLL   #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)   using namespace std;   inline void read(int &x)   {    short negative=1;       x=0;       char c=getchar();       while(c< 0  || c> 9 )       {     if(c== - )      negative=-1;     c=getchar();    }       while(c>= 0  && c<= 9 )           x=(x<<3)+(x<<1)+(c^48),c=getchar();       x*=negative;   }   ll qpow(ll n,ll k){    ll ans=1;    while(k){     if(k%2){      ans*=n;      ans%=mod;     }     n*=n;     n%=mod;     k/=2;    }    return ans;   }   string iots(int n)   {    string s=  ;    while(n)    {     int now=n%10;     s+=now+ 0 ;     n/=10;    }    reverse(s.begin(),s.end());    return s;   }   int stoi(string s)   {    int n=0;    rep(i,s.size())    {     n*=10;     n+=s[i]- 0 ;    }    return n;   }   int n;   int p[100100];   int pr[100100];   int suf[100100];   //pr[i]->i山峰左边能到的最远的地方 suf[i]右边    int main()   {    ios::sync_with_stdio(0);    cin>>n;    rep(i,n)cin>>p[i];     pr[0]=0;    forn(i,1,n-1)    {     if(p[i]>p[i-1])     {      pr[i]=pr[i-1];      }      else      {      pr[i]=i;     }    }    suf[n-1]=n-1;    fore(i,n-2,0)    {     if(p[i]>p[i+1])     {      suf[i]=suf[i+1];     }     else     {      suf[i]=i;     }    }    int mx=0;    rep(i,n)    {     if(pr[i]==i||suf[i]==i)continue;     if(i-pr[i]==suf[i]-i)     {      mx=max(mx,i-pr[i]);     }    }    int ans=0;    rep(i,n)    {     if(pr[i]==i||suf[i]==i)continue;     if(i-pr[i]==suf[i]-i&&i-pr[i]==mx)     {      ans++;     }    }    int cnt=0;    rep(i,n)    {     if(i-pr[i]==mx)cnt++;     if(suf[i]-i==mx)cnt++;     }     if(mx==0||mx%2==1||cnt>=3)    {     cout<<0<<endl;     return 0;    }    if(ans==1) cout<<1<<endl;    else cout<<0<<endl;    return 0;   }   //特判判全   //循环边界   //精度足够   //注意初值


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a) b %= a, swap(a, b);     return b;   }   char x[1000005], y[1000005];   int aux[1000005][26];   int main() {     long long n, m;     cin >> n >> m;     scanf( %s %s , x, y);     int lenx = strlen(x), leny = strlen(y);     long long mdc = gcd(lenx, leny);     long long mmc = lenx / mdc * leny;     long long diff = mmc;     for (int i = (0); i < (leny); ++i) ++aux[i % mdc][y[i] -  a ];     for (int i = (0); i < (lenx); ++i) diff -= aux[i % mdc][x[i] -  a ];     cout << diff * (n * lenx / mmc) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   const int maxn = (int)3e5 + 10, mod = 998244353;   int add(int x, int y) {     x += y;     if (x >= mod) {       x -= mod;     }     return x;   }   int sub(int x, int y) {     x -= y;     if (x < 0) {       x += mod;     }     return x;   }   int mul(int x, int y) { return (long long)x * y % mod; }   int my_pow(int x, int y) {     int ans = 1;     for (; y; y >>= 1, x = mul(x, x)) {       if (y & 1) {         ans = mul(ans, x);       }     }     return ans;   }   pair<int, int> dp[maxn];   int v[maxn];   int res[maxn];   int main() {     int m;     cin >> m;     int n = 0;     int ps = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &v[i]);       n += v[i];       if (v[i] > v[ps]) {         ps = i;       }     }     dp[1] = make_pair(1, 0);     dp[0] = make_pair(1, 0);     int rn = my_pow(n, mod - 2);     int rm = my_pow(m - 1, mod - 2);     for (int i = 1; i < n; i++) {       int p1 = mul(i, rn);       int p2 = sub(1, p1);       int p3 = mul(p2, rm);       int p4 = mul(p2, mul(m - 2, rm));       pair<int, int> cur = make_pair(0, sub(0, mul(i, rn)));       cur.first = add(cur.first, add(sub(0, mul(dp[i - 1].first, p1)),                                      mul(dp[i].first, sub(1, p4))));       cur.second = add(cur.second, add(sub(0, mul(dp[i - 1].second, p1)),                                        mul(dp[i].second, sub(1, p4))));       cur.first = mul(cur.first, my_pow(p3, mod - 2));       cur.second = mul(cur.second, my_pow(p3, mod - 2));       dp[i + 1] = cur;     }     pair<int, int> cur = dp[n];     cur.first += mul(m - 1, dp[0].first);     cur.second += mul(m - 1, dp[0].second);     int x = mul(sub(0, cur.second), my_pow(cur.first, mod - 2));     for (int i = 0; i <= n; i++) {       res[i] = add(mul(dp[i].first, x), dp[i].second);     }     int tot = 0;     for (int i = 0; i < m; i++) {       tot = add(tot, res[v[i]]);     }     cout << tot << endl;   }


#include <bits/stdc++.h>   using namespace std;   void init() {}   const int N = 1e6 + 34;   const int INF = 1e9 + 34;   vector<int> ans[2];   vector<int> es[N];   int n, m, v1, v2;   int c[N];   void dfs(int v, int q) {     if (c[v] && c[v] != q + 1) {       cout <<  -1 ;       exit(0);     }     if (c[v]) return;     c[v] = q + 1;     ans[q].push_back(v + 1);     for (int w : es[v]) {       dfs(w, 1 - q);     }   }   int main() {     init();     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> v1 >> v2;       v1--;       v2--;       es[v1].push_back(v2);       es[v2].push_back(v1);     }     for (int i = 0; i < n; i++)       if (!c[i]) dfs(i, 0);     for (int i = 0; i < 2; i++) {       cout << ans[i].size() <<   n ;       for (int w : ans[i]) cout << w <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       int n;       cin >> n;       long long int a[n + 1];       int o = 0, idx, z = 0;       long long int maxo = -1000000007;       vector<int> v, v0;       for (long long int i = 1; i < n + 1; i++) {         cin >> a[i];         if (a[i] < 0) {           o++;           if (maxo < a[i]) {             maxo = a[i];             idx = i;           }         }         if (a[i] != 0)           v.push_back(i);         else           v0.push_back(i);       }       if (o % 2 == 1) {         v.erase(find(v.begin(), v.end(), idx));         v0.push_back(idx);         sort(v0.begin(), v0.end());       }       bool ch = 0;       if (v.size() > 0) {         for (long long int i = 0; i < v.size() - 1; i++) {           ch = 1;           cout <<  1   << v[i] <<     << v[i + 1] <<   n ;         }         if (v0.size() > 0) {           for (long long int i = 0; i < v0.size() - 1; i++) {             cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ;           }           cout <<  2   << v0[v0.size() - 1] <<   n ;         }       } else {         if (idx == n) {           cout <<  2   << idx <<   n ;           for (long long int i = 1; i < v0.size() - 1; i++)             cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ;         } else {           for (long long int i = 0; i < v0.size() - 1; i++)             cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     int min = a;     if (b < a) {       min = b;     }     return min;   }   int main() {     int a, b, c, ans, min;     cin >> a;     cin >> b;     cin >> c;     if (a == 1 && b != 1 && c != 1) {       ans = (a + b) * c;     } else if (a != 1 && b != 1 && c == 1) {       ans = a * (b + c);     } else if (a != 1 && b == 1 && c != 1) {       if (a < c) {         ans = (a + b) * c;       } else {         ans = a * (b + c);       }     } else if (a == 1 && b == 1 && c != 1) {       ans = (a + b) * c;     } else if (a != 1 && b == 1 && c == 1) {       ans = a * (b + c);     } else if (a == 1 && c == 1) {       ans = a + b + c;     } else {       ans = a * b * c;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os << p.first <<     << p.second;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& vec) {     for (int i = 0; i < vec.size(); i++) {       os << vec[i] << (i + 1 == vec.size() ?    :    );     }     return os;   }   void solve() {     int h, w;     cin >> h >> w;     vector<vector<int>> ans;     vector<vector<int>> s(h, vector<int>(w));     for (int i = 0; (i) < (int)(h); (i)++) {       string t;       cin >> t;       for (int j = 0; (j) < (int)(w); (j)++) {         s[i][j] = t[j] -  0 ;       }     }     auto exc = [&](int y0, int x0, int y1, int x1, int y2, int x2) {       s[y0][x0] = s[y0][x0] ^ 1;       s[y1][x1] = s[y1][x1] ^ 1;       s[y2][x2] = s[y2][x2] ^ 1;       vector<int> r = {y0 + 1, x0 + 1, y1 + 1, x1 + 1, y2 + 1, x2 + 1};       ans.push_back(r);     };     auto exc2 = [&](int topy, int leftx, int no_use_y, int no_use_x) {       vector<int> r;       for (int i = topy; i < topy + 2; i++) {         for (int j = leftx; j < leftx + 2; j++) {           if (i != no_use_y || j != no_use_x) {             r.push_back(i + 1);             r.push_back(j + 1);           }         }       }       s[r[0] - 1][r[1] - 1] ^= 1;       s[r[2] - 1][r[3] - 1] ^= 1;       s[r[4] - 1][r[5] - 1] ^= 1;       ans.push_back(r);     };     if ((h & 1) && (w & 1)) {       if (s[h - 1][w - 1] == 1) {         exc(h - 1, w - 1, h - 2, w - 1, h - 1, w - 2);       }       for (int i = 0; i < h - 1; i += 2) {         if (s[i][w - 1] == 1) {           if (s[i + 1][w - 1] == 1) {             exc(i, w - 1, i + 1, w - 1, i, w - 2);           } else {             exc(i, w - 1, i, w - 2, i + 1, w - 2);           }         } else {           if (s[i + 1][w - 1] == 1) {             exc(i + 1, w - 1, i, w - 2, i + 1, w - 2);           }         }       }       for (int i = 0; i < w - 1; i += 2) {         if (s[h - 1][i] == 1) {           if (s[h - 1][i + 1] == 1) {             exc(h - 1, i, h - 1, i + 1, h - 2, i);           } else {             exc(h - 1, i, h - 2, i, h - 2, i + 1);           }         } else {           if (s[h - 1][i + 1] == 1) {             exc(h - 1, i + 1, h - 2, i, h - 2, i + 1);           }         }       }     } else if (h & 1) {       for (int i = 0; i < w - 1; i += 2) {         if (s[h - 1][i] == 1) {           if (s[h - 1][i + 1] == 1) {             exc(h - 1, i, h - 1, i + 1, h - 2, i);           } else {             exc(h - 1, i, h - 2, i, h - 2, i + 1);           }         } else {           if (s[h - 1][i + 1] == 1) {             exc(h - 1, i + 1, h - 2, i, h - 2, i + 1);           }         }       }     } else if (w & 1) {       for (int i = 0; i < h - 1; i += 2) {         if (s[i][w - 1] == 1) {           if (s[i + 1][w - 1] == 1) {             exc(i, w - 1, i + 1, w - 1, i, w - 2);           } else {             exc(i, w - 1, i, w - 2, i + 1, w - 2);           }         } else {           if (s[i + 1][w - 1] == 1) {             exc(i + 1, w - 1, i, w - 2, i + 1, w - 2);           }         }       }     }     if (h & 1) h--;     if (w & 1) w--;     for (int i = 0; i < h; i += 2) {       for (int j = 0; j < w; j += 2) {         while (true) {           int c = 0;           for (int ii = i; ii < i + 2; ii++) {             for (int jj = j; jj < j + 2; jj++) {               c += (s[ii][jj] == 1);             }           }           if (c == 0) {             break;           } else if (c == 1 || c == 3) {             [&]() {               for (int ii = i; ii < i + 2; ii++) {                 for (int jj = j; jj < j + 2; jj++) {                   if (s[ii][jj] == 0) {                     exc2(i, j, ii, jj);                     return;                   }                 }               }             }();           } else if (c == 2 || c == 4) {             [&]() {               for (int ii = i; ii < i + 2; ii++) {                 for (int jj = j; jj < j + 2; jj++) {                   if (s[ii][jj] == 1) {                     exc2(i, j, ii, jj);                     return;                   }                 }               }             }();           }         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; (i) < (int)(ans.size()); (i)++) {       cout << ans[i] <<   n ;     }   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long read1() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int ans;   long long w[20], ansa, ansb, ansc;   void dfs(long long a, long long b, long long c, long long nowa, long long nowb,            long long jin, int nowl, int wei) {     if (nowl >= ans) return;     if (!a && !b && !c && !jin) {       ans = nowl;       ansa = nowa;       ansb = nowb;       return;     }     if (!c) {       int tot = 0;       long long nw = jin + a + b;       while (nw) {         tot++;         nw /= 10;       }       dfs(0, 0, 0, nowa + a * w[wei], nowb + b * w[wei], 0, nowl + tot, wei);       return;     }     if ((a + b + jin) % 10 == c % 10)       dfs(a / 10, b / 10, c / 10, nowa + a % 10 * w[wei], nowb + b % 10 * w[wei],           (a % 10 + b % 10 + jin) / 10, nowl, wei + 1);     else {       dfs(a * 10 + (c + 10 - b % 10 - jin) % 10, b, c, nowa, nowb, jin, nowl + 1,           wei);       dfs(a, b * 10 + (c + 10 - a % 10 - jin) % 10, c, nowa, nowb, jin, nowl + 1,           wei);       dfs(a, b, c * 10 + (a + b + jin) % 10, nowa, nowb, jin, nowl + 1, wei);     }   }   int a, b, c;   int main() {     scanf( %d+%d=%d , &a, &b, &c);     w[0] = 1;     ans = 12;     for (int i = 1; i <= 18; i++) w[i] = w[i - 1] * 10;     dfs(a, b, c, 0, 0, 0, 0, 0);     printf( %I64d+%I64d=%I64d , ansa, ansb, ansa + ansb);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int n, dp[MAXN], ans[MAXN], mx[4 * MAXN], lz[4 * MAXN];   vector<pair<int, int> > v, id;   void refresh(int pos, int bg, int ed) {     if (lz[pos] == 0) return;     int LZ = lz[pos];     lz[pos] = 0;     mx[pos] += LZ;     if (bg == ed) return;     lz[2 * pos] += LZ;     lz[2 * pos + 1] += LZ;   }   void upd(int pos, int bg, int ed, int p, int q, int val) {     refresh(pos, bg, ed);     if (q < bg || ed < p) return;     if (p <= bg && ed <= q) {       lz[pos] += val;       refresh(pos, bg, ed);       return;     }     int mid = (bg + ed) >> 1, l = 2 * pos, r = 2 * pos + 1;     upd(l, bg, mid, p, q, val);     upd(r, mid + 1, ed, p, q, val);     mx[pos] = max(mx[l], mx[r]);   }   int qry(int pos, int bg, int ed, int p, int q) {     refresh(pos, bg, ed);     if (q < bg || ed < p) return 0;     if (p <= bg && ed <= q) return mx[pos];     int mid = (bg + ed) >> 1, l = 2 * pos, r = 2 * pos + 1;     return max(qry(l, bg, mid, p, q), qry(r, mid + 1, ed, p, q));   }   int main() {     scanf( %d , &n);     for (int i = 0, x, h; i < n; i++) {       scanf( %d %d , &x, &h);       v.push_back(make_pair(x, x + h - 1));       id.push_back(make_pair(x, i));     }     sort(v.begin(), v.end());     sort(id.begin(), id.end());     dp[n - 1] = 1;     ans[id[n - 1].second] = 1;     upd(1, 0, n - 1, n - 1, n - 1, 1);     for (int i = n - 2; i >= 0; i--) {       int a = v[i].first;       int b = v[i].second;       int t = lower_bound(v.begin(), v.end(), make_pair(b + 1, (int)-1e9)) -               v.begin();       t--;       if (t == i)         dp[i] = 1;       else         dp[i] = qry(1, 0, n - 1, i + 1, t) + 1;       upd(1, 0, n - 1, i, i, dp[i]);       upd(1, 0, n - 1, i + 1, n - 1, 1);       ans[id[i].second] = dp[i];     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 20;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1.0);   const double RATE = 0.995;   const double eps = 1e-4;   int arr[MAXN][MAXN];   signed main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         scanf( %d , &arr[i][j]);       }     }     int a1a2 = arr[1][2];     int a2 = sqrt(1ll * a1a2 * arr[2][3] / arr[1][3]);     printf( %d  , arr[1][2] / a2);     printf( %d , a2);     for (int i = 3; i <= n; ++i) printf(  %d , arr[2][i] / a2);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<pair<long long, long long>> ans;     long long i = 0;     long long j = 0;     ans.push_back({0, -1});     ans.push_back({-1, 0});     ans.push_back({-1, -1});     for (long long k = 0; k < n; k++) {       ans.push_back({i, j});       ans.push_back({i, j + 1});       ans.push_back({i + 1, j});       i++;       j++;     }     ans.push_back({i, j});     cout << ans.size() << endl;     for (long long i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second << endl;   }   signed main() {     long long t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     long long int prices[n];     for (long long int i = 0; i < n; i++) {       cin >> prices[i];     }     long long int minimum = prices[0];     long long int ans = 0;     for (long long int i = 1; i < n; i++) {       if (prices[i] < minimum) {         minimum = prices[i];       }     }     for (long long int i = 0; i < n; i++) {       prices[i] -= minimum;     }     for (long long int i = 0; i < n; i++) {       if (prices[i] % k != 0) {         cout << -1 << endl;         return 0;       }     }     for (long long int i = 0; i < n; i++) {       ans += prices[i] / k;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   char a[N], b[N];   int n, T;   int ans[N * 2], ct, rev;   int rt, ch[N][2], fa[N], tg[N], col[N], sz[N];   int get(int x) { return ch[fa[x]][1] == x; }   void pushdown(int x) {     swap(ch[x][0], ch[x][1]), col[ch[x][0]] ^= 1, col[ch[x][1]] ^= 1,         tg[ch[x][0]] ^= 1, tg[ch[x][1]] ^= 1;     tg[x] = 0;   }   int s(int x, int k) {     if (tg[x]) pushdown(x);     if (sz[ch[x][0]] >= k) return s(ch[x][0], k);     if (sz[ch[x][0]] + 1 == k) return x;     return s(ch[x][1], k - sz[ch[x][0]] - 1);   }   char sc(int k) { return col[s(rt, k)] +  0 ; }   void updata(int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; }   void rotate(int x) {     int k = get(x), y = fa[x];     ch[y][k] = ch[x][k ^ 1];     fa[ch[y][k]] = y;     if (fa[y]) ch[fa[y]][ch[fa[y]][1] == y] = x;     fa[x] = fa[y];     fa[y] = x;     ch[x][k ^ 1] = y;     updata(y);     updata(x);   }   int q[N], cnt;   void splay(int x) {     int y;     q[cnt = 1] = x;     for (int i = x; fa[i]; i = fa[i]) q[++cnt] = fa[i];     for (int i = cnt; i >= 1; i--)       if (tg[q[i]]) pushdown(q[i]);     while (fa[x]) {       y = fa[x];       if (fa[y]) rotate(get(x) == get(y) ? y : x);       rotate(x);     }   }   void work(int k) {     if (k == n) {       col[rt] ^= 1;       tg[rt] ^= 1;       return;     }     int y = s(rt, k + 1);     splay(y);     rt = y;     col[ch[y][0]] ^= 1, tg[ch[y][0]] ^= 1;   }   void clr() {     for (int i = 1; i <= n; i++) fa[i] = tg[i] = sz[i] = ch[i][0] = ch[i][1] = 0;   }   int ins(int l, int r) {     if (l > r) return 0;     int mid = l + r >> 1;     col[mid] = a[mid] -  0 ;     ch[mid][0] = ins(l, mid - 1);     fa[ch[mid][0]] = mid;     ch[mid][1] = ins(mid + 1, r);     fa[ch[mid][1]] = mid;     sz[mid] = sz[ch[mid][0]] + sz[ch[mid][1]] + 1;     return mid;   }   int main() {     scanf( %d , &T);     while (T--) {       ct = rev = 0;       clr();       char c;       int aaa = 1;       scanf( %d%s%s , &n, a + 1, b + 1);       rt = ins(1, n);       for (int i = n; i; i--)         if ((c = sc(i)) != b[i]) {           if (sc(1) != c) ans[++ct] = 1, work(1);           ans[++ct] = i;           work(i);         }       sc(1);       printf( %d , ct);       for (int i = 1; i <= ct; i++) printf(  %d , ans[i]);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 2e5 + 10;   int x, y;   string cc;   vector<string> s[10][10];   bool can(int a, int b) {     for (auto i : s[a][b]) {       for (auto j : i)         if (j ==  . ) return true;     }     return false;   }   void color(int a, int b) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (s[a][b][i][j] ==  . ) s[a][b][i][j] =  ! ;       }     }   }   void call() {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           for (int l = 0; l < 3; l++) {             if (s[i][j][k][l] ==  . ) s[i][j][k][l] =  ! ;           }         }       }     }   }   void print() {     for (int k = 0; k < 3; k++) {       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           cout << s[k][j][i] <<    ;         }         cout <<   n ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < 9; i++) {       for (int j = 0; j < 3; j++) {         cin >> cc;         s[i / 3][j].push_back(cc);       }     }     cin >> x >> y;     x--;     y--;     x %= 3;     y %= 3;     if (can(x, y)) {       color(x, y);       print();     } else {       call();       print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ifree() { freopen( in ,  r , stdin); }   void ofree() { freopen( out ,  w , stdout); }   double min(double a, double b) { return a < b ? a : b; }   int main() {     int n, w;     while (cin >> n >> w) {       int arr[2 * n];       for (int i = 0; i < 2 * n; i++) cin >> arr[i];       sort(arr, arr + 2 * n);       double ans;       if (2 * arr[0] < arr[n])         ans = 3 * n * arr[0];       else         ans = 3 * n * ((double)arr[n]) / 2;       printf( %lf n , min((double)w, ans));     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[102], b[102];   long long cn[103];   int main() {     long long n, m;     cin >> n >> m;     long long k;     memset(a, -1, sizeof(a));     for (long long i = 1; i <= m; i++)       for (long long j = 1; j <= n; j++) {         cin >> k;         if (k > a[i]) {           a[i] = k;           b[i] = j;         }       }     for (long long i = 1; i <= m; i++) {       cn[b[i]]++;     }     long long mx = 0, win = 1;     for (long long i = 1; i <= n; i++) {       if (cn[i] > mx) {         mx = cn[i];         win = i;       }     }     cout << win << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string input;   int main() {     cin >> input;     int last = -1;     for (char i =  z ; i >=  a ; i--)       for (int j = last + 1; j < input.length(); j++)         if (input[j] == i) {           cout << input[j];           last = j;         }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int l[1 << 12];   int in[1 << 12];   int sm[1 << 12];   void go(int now) {     if (now * 2 > ((1 << n) - 1)) return;     int a = now * 2;     int b = now * 2 + 1;     go(a);     go(b);     int al = l[a] + in[a];     int bl = l[b] + in[b];     l[now] = max(al, bl);     sm[now] = sm[a] + sm[b] + abs(al - bl);   };   int main() {     cin >> n;     n++;     for (int i = 2; i <= (1 << n) - 1; i++) {       cin >> in[i];     }     go(1);     cout << sm[1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t, sum;     cin >> s >> t;     string n = to_string(stoi(s) + stoi(t));     s.erase(remove(s.begin(), s.end(),  0 ), s.end());     t.erase(remove(t.begin(), t.end(),  0 ), t.end());     n.erase(remove(n.begin(), n.end(),  0 ), n.end());     if (stoi(s) + stoi(t) == stoi(n))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const long long oo = 1e18;   long long a[N], w[N], k, n, t, l[N], r[N], res;   string s;   vector<long long> b;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       t += a[i];     }     cin >> k;     for (int i = 1; i <= k; ++i) cin >> l[i] >> r[i];     sort(l + 1, l + 1 + k);     sort(r + 1, r + 1 + k);     int i = 0;     for (i = k; i >= 1; --i) {       if (l[i] <= t && t <= r[i])         res = t;       else if (r[i] < t)         break;     }     if (res == 0 && i != k && k != 0)       res = l[i + 1];     else if (res == 0)       res = -1;     if (res == 0) res = -1;     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void test() {     string s;     cin >> s;     const int len = s.size();     stack<char> a;     for (int i = 0; i < len; ++i) {       if (a.empty()) {         a.push(s[i]);       } else if (s[i] ==  B ) {         a.pop();       } else {         a.push(s[i]);       }     }     cout << a.size() <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       test();     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int     #define vi vector<int>    #define vll vector<ll>   /*int gcd(int a,int b){       if(b==0)           return a;       else           return gcd(b,a%b);   }   */   void solve(){       int n;       cin>>n;       int a[n];       for(int i=0;i<n;i++){           cin>>a[i];       }       int cnt=0;       for(int i=0;i<n;i++){           if(a[i]!=i+1)               cnt=1;       }       if(a[0]==n && a[n-1]==1){           cout<< 3 <<endl;           return;       }       if(cnt==0){           cout<< 0 <<endl;       }       else if(a[0]==1 || a[n-1]==n){           cout<< 1 <<endl;           return;       }       else           cout<< 2 <<endl;                   }   int main(){       cin.tie(NULL);       #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif           int n;       cin>>n;       while(n--){           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x[100002] = {0}, j, t;     cin >> n;     t = n;     for (int i = 0; i < n; i++) {       cin >> j;       x[j] = 1;       while (t >= 1 && x[t] == 1) {         cout << t <<    ;         t--;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 5;   long long n, m, c, cur, loc;   long long a[N];   void work() {     long long lim = c / 2 + c % 2;     if (cur > lim) {       for (long long i = n; i >= 1; i--) {         if (cur > a[i] || !a[i]) {           loc = i;           return;         }       }       loc = 1;       return;     } else {       for (long long i = 1; i <= n; i++) {         if (cur < a[i] || !a[i]) {           loc = i;           return;         }       }       loc = n;       return;     }   }   bool check() {     for (long long i = 1; i <= n; i++) {       if (!a[i]) return 0;     }     for (long long i = 2; i <= n; i++) {       if (a[i] < a[i - 1]) return 0;     }     return 1;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m >> c;     for (long long i = 1; i <= m; i++) {       cin >> cur;       work();       a[loc] = cur;       cout << loc << endl;       if (check()) {         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-13;   int ROUND(double x) { return (int)(x + 0.5); }   bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }   bool ISEQUAL(double x, double y) {     return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));   }   double SQSUM(double x, double y) { return x * x + y * y; }   template <class T>   bool INRANGE(T x, T a, T b) {     return a <= x && x <= b;   }   int main() {     long long n, l, t;     scanf( %lld %lld %lld n , &n, &l, &t);     vector<long long> a(n);     for (int i = 0; i < n; i++) {       scanf( %lld  n , &a[i]);     }     long long count = 0;     long long base = 2 * t / l;     long long boundary = (2 * t) % l;     {       int x = 1;       for (int y = 0; y < n - 1; y++) {         x = max(x, y + 1);         while (x < n) {           if (a[x] - a[y] > boundary) {             break;           }           x++;         }         count += (x - (y + 1));       }     }     {       int x = 1;       for (int y = 0; y < n - 1; y++) {         x = max(x, y + 1);         while (x < n) {           if (l - (a[x] - a[y]) <= boundary) {             break;           }           x++;         }         count += (n - x);       }     }     double ans = 0.0;     double masu = n * (n - 1) * 0.5;     ans += (double)base * masu * 2;     ans += 1.0 * count;     ans /= 4;     printf( %.16f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5];   int kiemtra(int x, int y, int z) {     if (x < y + z && y < z + x && z < x + y) return 1;     if (x == y + z || y == x + z || z == x + y) return 2;     return 0;   }   void solve() {     int i, j, k, x, gan;     gan = 0;     for (i = 0; i < 4; i++)       for (j = 0; j < 4; j++)         for (k = 0; k < 4; k++)           if (i != j && j != k && i != k) {             x = kiemtra(a[i], a[j], a[k]);             if (x == 1) {               cout <<  TRIANGLE n ;               return;             }             if (x == 2) gan = 1;           }     if (gan == 1) {       cout <<  SEGMENT n ;       return;     }     cout <<  IMPOSSIBLE n ;   }   void input() {     int i;     while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {       solve();     }   }   int main() {     input();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MAX(long long int a, long long int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int MIN(long long int a, long long int b) {     if (a < b) {       return a;     } else {       return b;     }   }   int gcd(long long int a, long long int b) {     long long int c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   int main() {     int n;     cin >> n;     cout << (6 * n * (n - 1)) + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int node_max = 3000;   struct network {     struct node {       int v, c, w, b;       node(int _v = 0, int _c = 0, int _w = 0, int _b = 0)           : v(_v), c(_c), w(_w), b(_b) {}     };     int n, pre[node_max];     vector<node> nd[node_max];     void clear() {       for (int i = 0; i < n; ++i) nd[i].clear();       n = 0;     }     void insert(int u, int v, int c, int w, bool d = false) {       n = max(n, max(u, v) + 1);       nd[u].push_back(node(v, c, w, nd[v].size()));       nd[v].push_back(node(u, 0, -w, nd[u].size() - 1));       if (d) {         nd[v].push_back(node(u, c, w, nd[u].size()));         nd[u].push_back(node(v, 0, -w, nd[v].size() - 1));       }     }     pair<int, int> get_max_flow_min_cost(int src, int dst) {       pair<int, int> res;       int flow;       while ((flow = get_min_path(src, dst)) != 0) {         res.first += flow;         for (int i = dst; i != src; i = nd[i][pre[i]].v) {           res.second += nd[nd[i][pre[i]].v][nd[i][pre[i]].b].w * flow;           nd[nd[i][pre[i]].v][nd[i][pre[i]].b].c -= flow;           nd[i][pre[i]].c += flow;         }       }       return res;     }     int get_min_path(int src, int dst) {       int dis[node_max], bfs[node_max];       bool visited[node_max] = {};       fill(dis, dis + n, INT_MAX);       visited[src] = true;       dis[src] = 0;       bfs[0] = src;       for (int s = 0, t = 1; s != t; visited[bfs[s]] = 0, s = (s + 1) % n) {         int v = bfs[s];         for (vector<node>::iterator i = nd[v].begin(); i != nd[v].end(); ++i) {           if (i->c <= 0 || dis[v] + i->w >= dis[i->v]) continue;           dis[i->v] = dis[v] + i->w;           pre[i->v] = i->b;           if (!visited[i->v]) {             visited[i->v] = true;             bfs[t] = i->v;             t = (t + 1) % n;           }         }       }       if (dis[dst] == INT_MAX) return 0;       int res = INT_MAX;       for (int i = dst; i != src; i = nd[i][pre[i]].v)         res = min(res, nd[nd[i][pre[i]].v][nd[i][pre[i]].b].c);       return res;     }   };   int n, m, s[1024], t[1024], c[1024], ans[1024];   network g;   bool solve() {     if (scanf( %d%d , &n, &m) == EOF) return false;     for (int i = 0; i < n; ++i) scanf( %d%d%d , &s[i], &t[i], &c[i]);     g.clear();     int S = n * 2, T = n * 2 + 2;     g.insert(S, S + 1, m, 0);     for (int i = 0; i < n; ++i) {       g.insert(S + 1, i, 1, 0);       g.insert(i + n, T, 1, 0);       g.insert(i, i + n, 1, -c[i]);       for (int j = 0; j < n; ++j) {         if (i != j && s[i] + t[i] <= s[j]) {           g.insert(i + n, j, 1, 0);         }       }     }     g.get_max_flow_min_cost(S, T);     for (int i = 0; i < n; ++i) {       ans[i] = 0;       for (vector<network::node>::iterator j = g.nd[i].begin();            j != g.nd[i].end(); ++j) {         if (j->v == i + n && j->c == 0) {           ans[i] = 1;         }       }       printf(i == n - 1 ?  %d n  :  %d  , ans[i]);     }     return true;   }   int main() {     while (solve())       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int c = 2 * min(a, b);       int d = max(a, b);       if (c > max(a, b)) {         cout << c * c << endl;       } else {         cout << d * d << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   const int N = 100111;   struct Bridge {     struct edge {       int to, rv;       edge() {}       edge(int to, int rv) : to(to), rv(rv) {}     };     int nv, cnt;     vector<edge> graph[N];     int dis[N], low[N], par[N];     void init(int v = N) {       nv = v;       for (v = 0; v < nv; v++) graph[v].clear();     }     void add_edge(int u, int v) {       if (u == v) return;       int tu = graph[u].size(), tv = graph[v].size();       graph[u].push_back(edge(v, tv)), graph[v].push_back(edge(u, tu));     }     void proc() {       cnt = 0;       fill(dis, dis + nv, ~0);       for (int u = 0; u < nv; u++)         if (!~dis[u]) dfs(u, -1, -1);     }     void dfs(int u, int p, int pe) {       dis[u] = low[u] = cnt++, par[u] = p;       for (int i = 0; i < graph[u].size(); i++) {         int v = graph[u][i].to;         if (i == pe) continue;         if (~dis[v]) {           low[u] = min(low[u], dis[v]);         } else {           dfs(v, u, graph[u][i].rv);           low[u] = min(low[u], low[v]);         }       }     }     bool is_bridge(int u, int v) {       if (dis[u] > dis[v]) swap(u, v);       return (u == par[v] and dis[v] <= low[v]);     }   };   struct UnionFind {     vector<int> par;     void init(int n) { par.assign(n, ~0); }     int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }     bool connect(int x, int y) {       x = root(x), y = root(y);       if (x == y) return 0;       if (par[y] < par[x]) swap(x, y);       par[x] += par[y], par[y] = x;       return 1;     }     bool same(int x, int y) { return root(x) == root(y); }     int size(int x) { return -par[root(x)]; }   };   int n, m, k;   int us[N], vs[N];   int as[N], bs[N];   Bridge brg;   UnionFind uf;   struct LowestCommonAncestor {     static const int LOGV = 20;     static const int V = 100111;     vector<int> graph[V];     int par[LOGV][V], dep[V], nv;     void init(int v) {       nv = v, memset(par, ~0, sizeof(par));       for (v = 0; v < nv; v++) graph[v].clear();     }     void add_edge(int u, int v) {       graph[u].push_back(v);       graph[v].push_back(u);     }     void dfs(int u, int p, int d) {       par[0][u] = p, dep[u] = d;       for (int i = 0; i < graph[u].size(); i++)         if (p != graph[u][i]) dfs(graph[u][i], u, d + 1);     }     void prepare(int root) {       dfs(root, ~0, 0);       for (int k = 0; k + 1 < LOGV; k++)         for (int v = 0; v < nv; v++) {           if (!~par[k][v])             par[k + 1][v] = ~0;           else             par[k + 1][v] = par[k][par[k][v]];         }     }     int get(int u, int v) {       if (dep[u] > dep[v]) swap(u, v);       for (int k = 0; k < LOGV; k++)         if (dep[v] - dep[u] >> k & 1) v = par[k][v];       if (u == v) return u;       for (int k = LOGV - 1; ~k; --k)         if (par[k][u] != par[k][v]) u = par[k][u], v = par[k][v];       return par[0][u];     }   };   LowestCommonAncestor lca;   int name[N];   int main() {     int i, j, tcc, tc = 1 << 28;     for (tcc = 0; tcc < tc; tcc++) {       n = getint(), m = getint();       brg.init(n);       for (i = 0; i < m; i++) {         us[i] = getint() - 1;         vs[i] = getint() - 1;         brg.add_edge(us[i], vs[i]);       }       brg.proc();       k = getint();       for (i = 0; i < k; i++) {         as[i] = getint() - 1;         bs[i] = getint() - 1;       }       uf.init(n);       for (i = 0; i < m; i++)         if (!brg.is_bridge(us[i], vs[i])) {           uf.connect(us[i], vs[i]);         }       int M = 0;       for (i = 0; i < n; i++)         if (uf.root(i) == i) {           name[i] = M++;         }       lca.init(M);       for (i = 0; i < m; i++)         if (brg.is_bridge(us[i], vs[i])) {           int uu = name[uf.root(us[i])];           int vv = name[uf.root(vs[i])];           lca.add_edge(uu, vv);         }       lca.prepare(0);       for (i = 0; i < k; i++) {         int uu = name[uf.root(as[i])];         int vv = name[uf.root(bs[i])];         int a = lca.dep[uu];         int b = lca.dep[vv];         int c = lca.dep[lca.get(uu, vv)];         printf( %d n , a + b - 2 * c);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2007;   int n, m, a[maxn][maxn];   long long sr[maxn][maxn], sc[maxn][maxn], sumr[maxn], sumc[maxn], allsumr[maxn],       allsumc[maxn];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         sumr[i] += a[i][j];         sumc[j] += a[i][j];       }     }     for (int r = 1; r <= n + 1; r++) {       for (int nr = 1; nr <= n; nr++) {         int dis;         if (nr < r)           dis = abs(r - nr - 1) * 4 + 2;         else           dis = abs(r - nr) * 4 + 2;         sr[r][nr] = dis * dis * sumr[nr];         allsumr[r] += sr[r][nr];       }     }     for (int c = 1; c <= m + 1; c++) {       for (int nc = 1; nc <= m; nc++) {         int dis;         if (nc < c)           dis = abs(c - nc - 1) * 4 + 2;         else           dis = abs(c - nc) * 4 + 2;         sc[c][nc] = dis * dis * sumc[nc];         allsumc[c] += sc[c][nc];       }     }     long long ans = 1e18 + 10;     int x, y;     for (int r = 1; r <= n + 1; r++) {       for (int c = 1; c <= m + 1; c++) {         if (allsumr[r] + allsumc[c] < ans) {           ans = allsumr[r] + allsumc[c];           x = r, y = c;         }       }     }     printf( %lld n%d %d n , ans, x - 1, y - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[100001];   int acum[100001];   long long cnt = 0, ans[100001];   struct Q {     int i, j, p;     Q(int a, int b, int c) : i(a), j(b), p(c){};     Q() {}     bool operator<(const Q &other) const {       if (i / 300 == other.i / 300) return j < other.j;       return i / 300 < other.i / 300;     }   };   vector<Q> queries;   int freq[2097151];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , v + i);       acum[i] = v[i] ^ acum[i - 1];     }     for (int k = 0; k < m; k++) {       int i, j;       scanf( %d %d , &i, &j);       queries.push_back(Q(i - 1, j, k));     }     sort(queries.begin(), queries.end());     int l = 0, r = 0;     freq[0] = 1;     for (int q = 0; q < m; q++) {       int i = queries[q].i, j = queries[q].j, p = queries[q].p;       while (l > i) {         --l;         cnt += freq[acum[l] ^ k];         freq[acum[l]]++;       }       while (r < j) {         r++;         cnt += freq[acum[r] ^ k];         freq[acum[r]]++;       }       while (l < i) {         freq[acum[l]]--;         cnt -= freq[acum[l] ^ k];         l++;       }       while (r > j) {         freq[acum[r]]--;         cnt -= freq[acum[r] ^ k];         r--;       }       ans[p] = cnt;     }     for (int i = 0; i < m; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int people[105];   int main() {     int a, b, c;     memset(people, 0, sizeof(people));     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &a, &b, &c);       people[a] -= c;       people[b] += c;     }     long long sum = 0;     for (int i = 1; i <= n; i++)       if (people[i] > 0) sum += people[i];     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(vector<int>& v, int k, int val, int start) {     vector<int> dp(v.size());     if (v[0] <= val && start == 0) {       dp[0] = dp[1] = 1;     }     if (v[1] <= val) {       dp[1] = 1;     }     for (int i = 2; i < v.size(); ++i) {       dp[i] = dp[i - 1];       if (v[i] <= val) {         dp[i] = max(dp[i], 1 + dp[i - 2]);       }     }     int endpos = v.size() - 1;     if ((start == 1 && k % 2) || (start == 0 && k % 2 == 0)) {       endpos--;     }     if (dp[endpos] >= (k + 1 - start) / 2) {       return true;     }     return false;   }   bool checkall(vector<int>& v, int k, int val) {     return check(v, k, val, 0) || check(v, k, val, 1);   }   void solve(std::istream& in, std::ostream& out) {     int n, k;     in >> n >> k;     vector<int> v(n);     for (auto& x : v) {       in >> x;     }     int l = 1, r = 1e9 + 1;     while (r - l > 1) {       int m = (r + l) / 2;       if (checkall(v, k, m)) {         r = m;       } else {         l = m;       }     }     if (checkall(v, k, l)) {       r = l;     }     out << r << endl;   }   int main() { solve(cin, cout); }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int MOD = 1e9 + 7;   inline int read() {     int s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = (s << 1) + (s << 3) + ch -  0 ;       ch = getchar();     }     return s * f;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   int a[maxn];   int main() {     int T = read(), n, m, k;     while (T--) {       n = read(), k = read();       for (int i = 1; i <= n; i++) a[i] = read();       sort(a + 1, a + n + 1);       int ans = 0;       for (int i = 2; i <= n; i++) {         if (a[1] + a[i] > k) continue;         ans += (k - a[i]) / a[1];       }       write(ans);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const int N = 1e5 + 5, inf = 1e9 + 5;   long long add(long long x, long long y) {     x += y;     if (x >= MOD) return x - MOD;     return x;   }   long long sub(long long x, long long y) {     x -= y;     if (x < 0) return x + MOD;     return x;   }   long long mult(long long x, long long y) { return (x * y) % MOD; }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       int n, m;       cin >> n >> m;       vector<int> row_sum(n), col_sum(m);       vector<vector<bool>> a(n, vector<bool>(m));       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           char c;           cin >> c;           row_sum[i] += c ==  * ;           col_sum[j] += c ==  * ;           a[i][j] = c ==  * ;         }       }       int ans = inf;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           ans = min(ans, n - row_sum[i] + m - col_sum[j] - (!a[i][j]));         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int IINF = 1e9;   const long long LINF = 1e18;   const int K = 1e5 + 5;   const int KL = 1e6 + 5;   int n;   int a[505];   int mem[505][505];   bool tok[505];   int dp(int l, int r) {     if (l == r) return 1;     if (l > r) return 0;     if (mem[l][r] != -1) return mem[l][r];     int k;     int ans = 505, ans2 = 505, ans3 = 505;     if (a[l] == a[l + 1]) ans2 = min(ans2, 1 + dp(l + 2, r));     for (int k = l + 2; k <= r; k++)       if (a[l] == a[k]) {         ans = min(ans, dp(l + 1, k - 1) + dp(k + 1, r));       }     ans3 = 1 + dp(l + 1, r);     return mem[l][r] = min({ans, ans2, ans3});   }   int main() {     memset(mem, -1, sizeof mem);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     printf( %d n , dp(1, n));     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, mod = 1e9 + 7;   int n, m, q, top, col, cnt, st[N], len[N], size[N], dfn[N], bl[N], son[N], S[N],       w[N], T[N], low[N], bin[N], dep[N], f[N];   char sc[N][10];   vector<int> e[N], v[N];   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return f * x;   }   void Tarjan(int x) {     dfn[x] = low[x] = ++cnt;     st[++top] = x;     for (int i = 0; i < e[x].size(); i++) {       int y = e[x][i];       if (!dfn[y]) {         Tarjan(y);         low[x] = min(low[x], low[y]);         if (low[y] == dfn[x]) {           if (st[top] == y) {             top--;             v[x].push_back(y);             v[y].push_back(x);             continue;           }           size[++col] = 1;           while (1) {             int z = st[top--];             size[col]++;             bl[z] = col;             v[z].push_back(col);             v[col].push_back(z);             if (z == y) break;           }           bl[x] = col;           v[x].push_back(col);           v[col].push_back(x);         }       } else         low[x] = min(low[x], dfn[y]);     }   }   void dfs(int x, int fa) {     S[x] = 1;     f[x] = fa;     dep[x] = dep[fa] + 1;     w[x] = w[fa];     if (size[x] > 2)       w[x]--;     else if (size[bl[x]] > 2)       w[x]++;     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (y == fa) continue;       dfs(y, x);       S[x] += S[y];       if (S[y] > S[son[x]]) son[x] = y;     }   }   void dfs2(int x, int fa) {     T[x] = fa;     if (!son[x]) return;     dfs2(son[x], fa);     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (T[y]) continue;       dfs2(y, y);     }   }   int lca(int x, int y) {     while (T[x] ^ T[y]) {       if (dep[T[x]] > dep[T[y]])         x = f[T[x]];       else         y = f[T[y]];     }     return dep[x] > dep[y] ? y : x;   }   int main() {     n = read(), m = read();     col = n;     for (int i = 1, x, y; i <= m; i++) {       x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     Tarjan(1);     bin[0] = 1;     sc[0][len[0]++] =  1 ;     for (int i = 1; i <= col; i++) {       bin[i] = bin[i - 1] * 2 % mod;       int x = bin[i];       while (x) {         sc[i][len[i]++] =  0  + x % 10;         x /= 10;       }     }     dfs(1, 0);     dfs2(1, 1);     q = read();     for (int i = 1, x, y, z; i <= q; i++) {       x = read(), y = read();       z = lca(x, y);       z = w[x] + w[y] - w[z] - w[f[z]];       for (int j = len[z] - 1; j > -1; j--) putchar(sc[z][j]);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     vector<long long> div;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i != i) {           div.push_back(n / i);         }         div.push_back(i);       }     }     sort(div.begin(), div.end());     if (k > div.size()) {       cout << -1 << endl;     } else {       cout << div[k - 1] << endl;     }     return 0;   }