#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, x, y, i;     cin >> n >> m >> x >> y;     cout << x <<     << y << endl;     int k = x + 1;     int p = x - 1;     for (i = 1; i < m + 1; i++) {       if (i != y) cout << x <<     << i << endl;     }     int jj = 1;     while (k <= n) {       if (jj == 0) {         for (i = 1; i < m + 1; i++) {           cout << k <<     << i << endl;         }         jj = 1;       } else {         for (i = m; i >= 1; i--) {           cout << k <<     << i << endl;         }         jj = 0;       }       k++;     }     while (p >= 1) {       if (jj == 0) {         for (i = 1; i < m + 1; i++) {           cout << p <<     << i << endl;         }         jj = 1;       } else {         for (i = m; i >= 1; i--) {           cout << p <<     << i << endl;         }         jj = 0;       }       p--;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int wall[110][110] = {0};     int r, c;     scanf( %d %d%*c , &r, &c);     char a[110];     for (int i = 1; i < r; i++) gets(a);     int flag = 0;     int seg = 0;     for (int i = 0; i < c; i++) {       char x;       scanf( %c , &x);       if (flag == 0) {         if (x ==  B ) {           flag++;           seg++;         } else           continue;       } else {         if (x ==  B )           continue;         else           flag = 0;       }     }     printf( %d n , seg);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2012;   int f[N][N][2];   int n, m, k, flag;   int ex, ey;   inline int find(int x, int y, int p) {     if (y < 0) return y;     return f[x][y][p] == y ? y : f[x][y][p] = find(x, f[x][y][p], p);   }   int dis(int x, int y) { return abs(ex - x) + abs(ey - y); }   inline void chk(int &ans, int nx, int ny, int &x, int &y) {     int d = dis(nx, ny);     if (d < ans) {       ans = d, x = nx, y = ny;     } else if (ans == d) {       if (!flag) {         if (nx < x) {           x = nx, y = ny;         } else if (nx == x && ny < y)           y = ny;       } else {         if (ny < y) {           x = nx, y = ny;         } else if (ny == y && nx < x)           x = nx;       }     }   }   void update(int r, int &ans, int &x, int &y) {     int nx = r, ny = find(r, ey, 0);     if (ny > 0) chk(ans, nx, ny, x, y);     ny = find(r, ey, 1);     if (ny <= m) chk(ans, nx, ny, x, y);   }   int main() {     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) f[i][j][0] = f[i][j][1] = j;     int x, y;     scanf( %d%d%d , &n, &m, &k);     if (n > m) swap(n, m), flag = 1;     while (k--) {       scanf( %d%d , &x, &y);       if (flag) swap(x, y);       ex = x, ey = y;       int d = 0, ans = ~0u >> 2, nx, ny;       while (d <= ans) {         int pre = ans;         int r = x - d;         if (r > 0 && r <= n) update(r, ans, nx, ny);         r = x + d;         if (r > 0 && r <= n) update(r, ans, nx, ny);         d++;       }       f[nx][ny][0] = ny - 1;       f[nx][ny][1] = ny + 1;       if (flag) swap(nx, ny);       printf( %d %d n , nx, ny);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int INF = 1e9 + 10;   int n, current;   pair<int, int> best;   int ans[N], block[N], sz[N];   vector<int> tree[N], tree_c[N];   int dfs1(int i, int parent) {     sz[i] = 1;     for (int k = 0; k < tree[i].size(); ++k) {       int j = tree[i][k];       if (j != parent and !block[j]) sz[i] += dfs1(j, i);     }     return sz[i];   }   void dfs2(int i, int parent) {     int highest = current - sz[i];     for (int k = 0; k < tree[i].size(); ++k) {       int j = tree[i][k];       if (j == parent or block[j]) continue;       dfs2(j, i);       highest = max(highest, sz[j]);     }     if (highest < best.first) best = make_pair(highest, i);   }   int find_centroid(int i) {     current = dfs1(i, 0);     best = make_pair(INF, 0);     dfs2(i, 0);     return best.second;   }   int build(int i, int deep) {     int centroid = find_centroid(i);     block[centroid] = 1;     for (int k = 0; k < tree[centroid].size(); ++k) {       int j = tree[centroid][k];       if (block[j]) continue;       j = build(j, deep + 1);       tree_c[centroid].push_back(j);       tree_c[j].push_back(centroid);     }     return centroid;   }   bool solve(int root) {     ans[root] = 0;     queue<pair<int, int> > q;     q.push(make_pair(root, -1));     while (!q.empty()) {       int i = q.front().first;       int parent = q.front().second;       q.pop();       for (int k = 0; k < tree_c[i].size(); ++k) {         int j = tree_c[i][k];         if (j == parent) continue;         if (ans[i] + 1 > 25) return false;         ans[j] = ans[i] + 1;         q.push(make_pair(j, i));       }     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       --x, --y;       tree[x].push_back(y);       tree[y].push_back(x);     }     int root = build(0, 0);     if (!solve(root))       printf( Impossible! n );     else {       for (int i = 0; i < n; ++i) {         if (i) printf(   );         printf( %c , ans[i] +  A );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline long long read() {     bool sign = 0;     char ch = nc();     long long x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return 0;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return x;   }   };  // namespace fastIO   using namespace fastIO;   long long qpow(long long n, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans *= n, ans %= 998244353;       n *= n, n %= 998244353;       k >>= 1;     }     return ans;   }   char s[3000010];   long long fac[3000010], ifac[3000010], l[3000010], r[3000010], x[3000010],       y[3000010];   long long c(long long x, long long y) {     return fac[x] * ifac[x - y] % 998244353 * ifac[y] % 998244353;   }   signed main() {     cin >> s + 1;     long long n = strlen(s + 1);     fac[0] = 1;     for (long long i = 1; i <= n; i++) {       fac[i] = fac[i - 1] * i % 998244353;     }     ifac[n] = qpow(fac[n], 998244353 - 2);     for (long long i = n - 1; i >= 0; i--)       ifac[i] = ifac[i + 1] * (i + 1) % 998244353;     for (long long i = 1; i <= n; i++) {       l[i] = l[i - 1] + (s[i] ==  ( );       x[i] = x[i - 1] + (s[i] ==  ? );     }     for (long long i = n; i >= 1; i--) {       r[i] = r[i + 1] + (s[i] ==  ) );       y[i] = y[i + 1] + (s[i] ==  ? );     }     long long ans = 0;     for (long long i = 1; i <= n - 1; i++) {       ans += l[i] * c(x[i] + y[i + 1], y[i + 1] - l[i] + r[i + 1]) +              x[i] * c(x[i] + y[i + 1] - 1, y[i + 1] - l[i] + r[i + 1] - 1),           ans %= 998244353;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long ar[], long long n) {     bool flag = true;     for (long long i = 1; i < n; i++) {       if (ar[i] >= (ar[i - 1] + ar[(i + 1) % n])) {         flag = false;         break;       }     }     return flag;   }   int32_t main() {     long long n;     cin >> n;     long long temp[n];     for (long long i = 0; i < n; i++) {       cin >> temp[i];     }     sort(temp, temp + n);     long long ar[n];     long long k = 0;     for (long long i = n - 3; i >= 0; i--, k++) ar[k] = temp[i];     ar[k++] = temp[n - 2];     ar[k++] = temp[n - 1];     if (check(ar, n)) {       cout <<  YES n ;       for (auto k : ar) cout << k <<    ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   void sort(int *a, int n) {     int isSorted = 0;     int i;     int tmp;     while (isSorted == 0) {       isSorted = 1;       for (i = 0; i < n - 1; i++) {         if (a[i] > a[i + 1]) {           tmp = a[i];           a[i] = a[i + 1];           a[i + 1] = tmp;           isSorted = 0;         }       }     }   }   int main() {     int n, m;     int p[101];     int i;     int numeven, numodd;     scanf( %d , &n);     m = n / 2;     for (i = 0; i < m; i++) scanf( %d , p + i);     sort(p, m);     numeven = 0;     numodd = 0;     for (i = 0; i < m; i++) {       numeven += ((n - i * 2) - p[m - 1 - i]) > 0 ? ((n - i * 2) - p[m - 1 - i])                                                   : -((n - i * 2) - p[m - 1 - i]);     }     for (i = 0; i < m; i++) {       numodd += (((i * 2 + 1) - p[i])) > 0 ? (((i * 2 + 1) - p[i]))                                            : -(((i * 2 + 1) - p[i]));     }     if (numeven > numodd)       printf( %d n , numodd);     else       printf( %d n , numeven);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int sum = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();     return sum * ff;   }   int Q, n, a[10005], cnt;   int main() {     Q = read();     for (; Q--;) {       n = read();       cnt = 0;       if (n == 4) {         puts( 3 1 4 2 );         continue;       }       if (n <= 3)         printf( -1 );       else {         if (n & 1) {           for (int j = n; j >= 1; j--)             if (j & 1) a[++cnt] = j;           a[++cnt] = 4, a[++cnt] = 2;           if (n >= 6)             for (int j = 6; j <= n; j++)               if (j % 2 == 0) a[++cnt] = j;         } else {           for (int j = n; j >= 1; j--)             if (j % 2 == 0) a[++cnt] = j;           a[++cnt] = 5, a[++cnt] = 1, a[++cnt] = 3;           if (n >= 7)             for (int j = 7; j <= n; j++)               if (j & 1) a[++cnt] = j;         }         for (int i = 1; i <= cnt; i++) printf( %d  , a[i]);       }       puts(  );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using std::cerr;   using std::cin;   using std::cos;   using std::cout;   using std::endl;   using std::make_pair;   using std::max;   using std::min;   using std::next_permutation;   using std::pair;   using std::priority_queue;   using std::queue;   using std::random_shuffle;   using std::set;   using std::sin;   using std::sort;   using std::sqrt;   using std::stack;   using std::string;   using std::stringstream;   using std::swap;   using std::vector;   const long double PI = 3.14159265358979323846;   int main() {     vector<string> taxi, pizza, girls;     int mtaxi, mpizza, mgirls;     mtaxi = mpizza = mgirls = 0;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int s;       string name;       cin >> s >> name;       int ntaxi, npizza, ngirls;       ntaxi = npizza = ngirls = 0;       for (int j = 0; j < s; ++j) {         string number;         cin >> number;         string nomer = number.substr(0, 2);         nomer += number.substr(3, 2);         nomer += number.substr(6, 2);         bool t = true;         for (int k = 1; k < 6; ++k) t = t && (nomer[k] == nomer[0]);         if (t) {           ++ntaxi;           continue;         }         bool p = true;         for (int k = 1; k < 6; ++k) p = p && (nomer[k] < nomer[k - 1]);         if (p)           ++npizza;         else           ++ngirls;       }       if (ntaxi == mtaxi) {         taxi.push_back(name);       }       if (ntaxi > mtaxi) {         mtaxi = ntaxi;         taxi.resize(0);         taxi.push_back(name);       }       if (npizza == mpizza) {         pizza.push_back(name);       }       if (npizza > mpizza) {         mpizza = npizza;         pizza.resize(0);         pizza.push_back(name);       }       if (ngirls == mgirls) {         girls.push_back(name);       }       if (ngirls > mgirls) {         mgirls = ngirls;         girls.resize(0);         girls.push_back(name);       }     }     cout <<  If you want to call a taxi, you should call: ;     for (int i = 0; i < taxi.size() - 1; ++i) cout <<     << taxi[i] <<  , ;     cout <<     << taxi.back() <<  .  << endl;     cout <<  If you want to order a pizza, you should call: ;     for (int i = 0; i < pizza.size() - 1; ++i) cout <<     << pizza[i] <<  , ;     cout <<     << pizza.back() <<  .  << endl;     cout <<  If you want to go to a cafe with a wonderful girl, you should call: ;     for (int i = 0; i < girls.size() - 1; ++i) cout <<     << girls[i] <<  , ;     cout <<     << girls.back() <<  .  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, l, w[200005], h[200005], a, b, m, m1;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &w[i], &h[i]);       if (h[m] <= h[i]) {         m1 = m;         m = i;       } else if (h[m1] <= h[i]) {         m1 = i;       }       a += w[i];     }     for (i = 1; i <= n; i++) {       if (i == m) {         printf( %d  , (a - w[i]) * h[m1]);       } else         printf( %d  , (a - w[i]) * h[m]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string rl;     cin >> rl;     vector<int> A(n, 0);     for (int i = 0; i < n; i++) cin >> A[i];     int diff = 2147483647;     int t;     for (int i = 0; i < n - 1; i++)       if (rl[i] ==  R  && rl[i + 1] ==  L ) {         t = (A[i + 1] - A[i]) / 2;         diff = min(diff, t);       }     if (diff == 2147483647) diff = -1;     cout << diff <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(int n) { cout << n << endl; }   int main() {     int n, l, sum = 0;     cin >> n;     string s;     s = to_string(n);     l = s.size();     for (int i = l; i > 0; i--) sum += pow(2, i - 1);     reverse(s.begin(), s.begin() + l);     for (int i = 0; i < l; i++)       if (s[i] ==  7 ) sum += pow(2, i);     print(sum);   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 5;   const int mod = (int)1e9 + 7;   const int logN = 17;   const int inf = 1e9;   const int N = 2e5 + 5;   int s, n, m, h1[N], h, t, x, y, z;   vector<int> v[N];   pair<int, int> e[N];   void print(int x, int y) {     cout <<  YES n ;     vector<int> com, h, t;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++)       h1[*it]++;     for (__typeof(v[y].begin()) it = v[y].begin(); it != v[y].end(); it++)       h1[*it]++;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++) {       if (*it == y) continue;       if (h1[*it] == 1 && h.size() < ::h) h.push_back(*it);       if (h1[*it] == 2) com.push_back(*it);     }     for (__typeof(v[y].begin()) it = v[y].begin(); it != v[y].end(); it++) {       if (*it == x) continue;       if (h1[*it] == 1 && t.size() < ::t) t.push_back(*it);     }     while (h.size() < ::h) {       h.push_back(com.back());       com.pop_back();     }     while (t.size() < ::t) {       t.push_back(com.back());       com.pop_back();     }     cout << x <<     << y <<   n ;     for (__typeof(h.begin()) it = h.begin(); it != h.end(); it++)       cout << *it <<    ;     cout <<   n ;     for (__typeof(t.begin()) it = t.begin(); it != t.end(); it++)       cout << *it <<    ;     cout <<   n ;   }   int main() {     scanf( %d %d %d %d , &n, &m, &h, &t);     int s = 0;     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       e[++s] = make_pair(x, y);       e[++s] = make_pair(y, x);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       sort(v[i].begin(), v[i].end());     }     for (int i = 1; i <= s; i++) {       x = e[i].first;       y = e[i].second;       if (v[x].size() >= h + 1 && v[y].size() >= h + t + 1) {         print(x, y);         return 0;       }       if (v[x].size() >= h + t + 1 && v[y].size() >= t + 1) {         print(x, y);         return 0;       }       if (v[x].size() <= h || v[y].size() <= t) continue;       int j = 0;       int s1 = v[x].size() - 1, s2 = v[y].size() - 1, com = 0;       for (int tt = 0; tt <= s1; tt++) {         while (j < v[y].size() && v[y][j] < v[x][tt]) j++;         if (j < v[y].size() && v[y][j] == v[x][tt]) com++;       }       if (s1 + s2 - com >= h + t) {         print(x, y);         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 2e3 + 505;   struct node {     double x, y;   } a[mx];   double pw(double x) { return x * x; }   double dist(node a, node b) { return sqrt(pw(a.x - b.x) + pw(a.y - b.y)); }   double f[2][mx], g[2][mx];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf%lf , &a[i].x, &a[i].y);     for (int i = 1; i < n; i++)       for (int j = 0; j < n; j++) {         g[i % 2][j] =             max(g[(i + 1) % 2][(j - 1 + n) % n] + dist(a[j], a[(j - 1 + n) % n]),                 f[(i + 1) % 2][(j - i + n) % n] + dist(a[j], a[(j - i + n) % n]));         f[i % 2][j] =             max(f[(i + 1) % 2][(j + 1) % n] + dist(a[j], a[(j + 1) % n]),                 g[(i + 1) % 2][(i + j) % n] + dist(a[j], a[(i + j) % n]));       }     double ans = 0;     for (int i = 0; i < n; i++)       ans = max(ans, max(f[(n - 1) % 2][i], g[(n - 1) % 2][i]));     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000 + 10;   int n;   const int nn = 65536 * 4;   long long sha[maxn];   long long tree[nn * 2 + 10], tag[nn * 2 + 10];   long long fix;   long long og[maxn];   void _down(int id) {     tree[id * 2] += tag[id], tag[id * 2] += tag[id];     tree[id * 2 + 1] += tag[id], tag[id * 2 + 1] += tag[id];     tag[id] = 0;   }   void _update(int a, int b, int l, int r, int id) {     if (l >= a and r <= b) {       tree[id] += fix;       tag[id] += fix;       return;     }     _down(id);     int mid = (l + r) / 2;     if (a <= mid) _update(a, b, l, mid, id << 1);     if (b > mid) _update(a, b, mid + 1, r, id << 1 | 1);     tree[id] = max(tree[id << 1], tree[id << 1 | 1]);   }   long long _query(int a, int b, int l, int r, int id) {     if (l >= a and r <= b) return tree[id];     _down(id);     int mid = (l + r) / 2;     if (a <= mid)       return _query(a, b, l, (l + r) / 2, id << 1);     else       return _query(a, b, (l + r) / 2 + 1, r, id << 1 | 1);   }   int _nxt(int l, int r, int id) {     if (l == r) return l;     _down(id);     if (tree[id << 1] >= fix)       return _nxt(l, (l + r) / 2, id << 1);     else       return _nxt((l + r) / 2 + 1, r, id << 1 | 1);   }   int main() {     int Q;     scanf( %d%d , &n, &Q);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &sha[i]);       og[i] = sha[i];       sha[i] += sha[i - 1];       fix = sha[i];       _update(i, i, 1, nn, 1);     }     while (Q--) {       int x;       long long y;       scanf( %d%I64d , &x, &y);       fix = y - og[x];       og[x] = y;       _update(x, n, 1, nn, 1);       int now = 1;       long long op;       int ui = 0;       while (1) {         op = _query(now, now, 1, nn, 1);         if (op == (now != 1 ? _query(now - 1, now - 1, 1, nn, 1) * 2 : 0)) {           ui = 1;           printf( %d n , now);           break;         }         fix = op * 2;         if (fix > tree[1]) break;         now = _nxt(1, nn, 1);       }       if (!ui) puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   template <typename A, typename B>   inline char smax(A &a, const B &b) {     return a < b ? a = b, 1 : 0;   }   template <typename A, typename B>   inline char smin(A &a, const B &b) {     return b < a ? a = b, 1 : 0;   }   template <typename I>   inline void read(I &x) {     int f = 0, c;     while (!isdigit(c = getchar())) c ==  -  ? f = 1 : 0;     x = c & 15;     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);     f ? x = -x : 0;   }   const int N = 1e5 + 7;   int n;   int b[N], s[N], id[N << 1], pre[N << 1];   struct wph {     int d, id;   } a[N];   inline void add(int x, int fa, int tag = 1) {     if (tag) s[x] = s[fa] + 1, b[s[x]] = x;     printf( %d %d n , x, fa);   }   inline void work() {     std::sort(a + 1, a + n + 1,               [](const wph &a, const wph &b) { return a.d > b.d; });     for (int i = 1; i < n; ++i)       printf( %d %d n , a[i].id * 2 - 1, a[i + 1].id * 2 - 1);     for (int i = 1; i <= n; ++i) id[i] = a[i].id * 2 - 1;     int nn = n;     for (int i = 1; i <= n; ++i)       if (i + a[i].d - 1 < nn)         printf( %d %d n , id[i] + 1, id[i + a[i].d - 1]);       else         id[++nn] = id[i] + 1, printf( %d %d n , id[nn], id[nn - 1]);   }   inline void init() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i].d), a[i].id = i;   }   int main() {     init();     work();     fclose(stdin), fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   void print_mat(vector<vector<long long> > mat) {     for (long long y = 0; y < (long long)((long long)((mat).size())); ++y) {       for (long long x = 0; x < (long long)((long long)((mat[y]).size())); ++x)         printf( %lld  , mat[y][x]);       puts(  );     }   }   vector<vector<long long> > I;   vector<vector<long long> > add(vector<vector<long long> > mat1,                                  vector<vector<long long> > mat2) {     int h = (long long)((mat1).size()), w = (long long)((mat1[0]).size());     assert((long long)((mat2).size()) == h && (long long)((mat2[0]).size()) == w);     vector<vector<long long> > ret(h, vector<long long>(w, 0));     for (long long y = 0; y < (long long)(h); ++y)       for (long long x = 0; x < (long long)(w); ++x)         ret[y][x] = mat1[y][x] + mat2[y][x];     return ret;   }   vector<long long> mul(vector<vector<long long> > mat, vector<long long> vec) {     int h = (long long)((mat).size()), w = (long long)((mat[0]).size());     assert((long long)((vec).size()) == w);     vector<long long> ret(h, 0);     for (long long y = 0; y < (long long)(h); ++y)       for (long long x = 0; x < (long long)(w); ++x)         ret[y] = (ret[y] + mat[y][x] * vec[x] % MOD) % MOD;     return ret;   }   vector<vector<long long> > mul(vector<vector<long long> > mat1,                                  vector<vector<long long> > mat2) {     int h = (long long)((mat1).size()), in = (long long)((mat1[0]).size()),         w = (long long)((mat2[0]).size());     assert((long long)((mat2).size()) == in);     vector<vector<long long> > ret(h, vector<long long>(w, 0));     for (long long y = 0; y < (long long)(h); ++y)       for (long long x = 0; x < (long long)(w); ++x)         for (long long i = 0; i < (long long)(in); ++i) {           ret[y][x] = (ret[y][x] + mat1[y][i] * mat2[i][x] % MOD) % MOD;         }     return ret;   }   vector<vector<long long> > pow(vector<vector<long long> > mat,                                  long long power) {     int n = (long long)((mat).size());     vector<vector<long long> > ret(n, vector<long long>(n, 0));     for (long long i = 0; i < (long long)(n); ++i) ret[i][i] = 1;     while (power > 0) {       if (power & 1) ret = mul(ret, mat);       mat = mul(mat, mat);       power >>= 1;     }     return ret;   }   vector<vector<long long> > powadd(vector<vector<long long> > mat,                                     long long power) {     int n = (long long)((mat).size());     vector<vector<long long> > ret(n, vector<long long>(n, 0));     for (long long i = 0; i < (long long)(n); ++i) ret[i][i] = 1;     if (power == 0) return ret;     if (power % 2 == 1) {       ret = powadd(mat, power / 2);       ret = mul(ret, add(I, pow(mat, power / 2 + 1)));     } else {       ret = add(pow(mat, power), powadd(mat, power - 1));     }     return ret;   }   long long solve(long long L) {     if (L == 0) return 0LL;     if (L == 1) return 4;     vector<vector<long long> > mat =         vector<vector<long long> >(5, vector<long long>(5, 0));     for (long long i = 0; i < (long long)(5); ++i)       for (long long j = 0; j < (long long)(5); ++j)         if (abs(i - j) == 1) mat[i][j] = 1;     vector<long long> vec = vector<long long>(5, 0);     vec[0] = vec[4] = 1;     vec[1] = vec[2] = vec[3] = 2;     vector<long long> piyo = mul(powadd(mat, L - 2), vec);     long long res = 4;     for (long long i = 0; i < (long long)(5); ++i) res = (res + piyo[i]) % MOD;     return res;   }   long long solve2(long long L) {     return (solve(L) + solve((L + 1) / 2)) * ((MOD + 1) / 2) % MOD;   }   int main() {     I = vector<vector<long long> >(5, vector<long long>(5, 0));     for (long long i = 0; i < (long long)(5); ++i) I[i][i] = 1;     long long L, R;     while (cin >> L >> R) {       cout << (solve2(R) - solve2(L - 1) + MOD) % MOD << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int pc;   void PrintCase() { printf( Case %lli:  , ++pc); }   long long int GCD(long long int a, long long int b) {     if (a < b) swap(a, b);     if (b == 1) return 1;     if (!b) return a;     if (!(a % b))       return b;     else       return (a, a % b);   }   long long int LCM(long long int a, long long int b) {     return (a * b) / GCD(a, b);   }   long long int bigmod(long long int n, long long int p) {     if (p == 0) return 1;     if (p == 1) return (n + 1000000007) % 1000000007;     if (p % 2)       return (bigmod(n, p - 1) * n + 1000000007) % 1000000007;     else {       long long int x = bigmod(n, p / 2);       return (x * x + 1000000007) % 1000000007;     }   }   long long int modinverse(long long int n) {     return bigmod(n, 1000000007 - 2) % 1000000007;   }   bool sc[100007];   vector<long long int> pr;   void seieve() {     for (long long int i = 2; i <= 100007; i++) {       if (!sc[i]) {         pr.push_back(i);         for (long long int j = i * i; j <= 100007; j += i) sc[j] = 1;       }     }   }   pair<long long int, long long int> pf[100007];   void pri_fact(long long int n) {     for (long long int i = 0; i < pr.size() && n != 1; i++) {       pf[i].first = pr[i];       long long int c = 0;       while (!(n % pr[i])) {         n /= pr[i];         c++;       }       pf[i].second = c;     }   }   vector<long long int> de;   void devisors(long long int n) {     long long int i;     for (i = 1; i <= sqrt(n); i++) {       if (!(n % i) && i != sqrt(n)) {         de.push_back(i);         de.push_back(n % i);       }     }     if ((i - 1) * (i - 1) == n) de.push_back(i - 1);     sort(de.begin(), de.end());   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, h, a, b, k, i, p, q, u, v;     cin >> n >> h >> a >> b >> k;     for (i = 0; i < k; i++) {       cin >> p >> q >> u >> v;       long long int x = abs(p - u);       if (!x) {         cout << abs(q - v) << endl;       } else if (q < a && v < a) {         cout << x + (a - q) + (a - v) << endl;       } else if (q > b && v > b) {         cout << x + (q - b) + (v - b) << endl;       } else {         cout << x + abs(q - v) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   vector<int> pos[10];   int main() {     ios_base::sync_with_stdio(false);     string s;     int n, m;     cin >> n >> m;     cin >> s;     int e[10] = {0};     for (int i = 0; (int)i < (int)s.size(); i++) {       e[s[i] -  0 ]++;       pos[s[i] -  0 ].push_back(i);     }     string ans;     vector<int> can;     int mi = INT_MAX;     pair<int, string> W = make_pair(INT_MAX,  ~ );     for (int X = 0; X < 10; X++) {       if (e[X] < m) {         string mur = s;         int sum = 0;         int t = m - e[X];         for (int i = 1; i <= 9; i++) {           int x = X - i;           int y = X + i;           if (y <= 9) {             int j = 0;             while (j < pos[y].size() && t) {               mur[pos[y][j]] = X +  0 ;               sum += i;               t--;               j++;             }           }           if (x >= 0) {             int j = pos[x].size() - 1;             while (j >= 0 && t) {               mur[pos[x][j]] = X +  0 ;               sum += i;               t--;               j--;             }           }         }         W = min(W, make_pair(sum, mur));       } else if (e[X] >= m) {         cout << 0 << endl;         cout << s << endl;         return 0;       }     }     cout << W.first << endl;     cout << W.second << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long mod = 1000000007;   const long long INF18 = 1000000000000000000;   long long n;   long long a[1010];   bool ok = false;   void rec(long long depth, long long cnt, long long sum) {     if (ok) return;     if (depth >= n) {       if (cnt < 1) return;       if (sum == 0) ok = true;       return;     }     rec(depth + 1, cnt, sum);     rec(depth + 1, cnt + 1, sum + a[depth]);     rec(depth + 1, cnt + 1, sum - a[depth]);   }   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) {       if (a[i] == 0) {         cout <<  YES n ;         return;       }       for (long long j = 0; j < n; j++) {         if (i == j) continue;         if (a[i] == a[j]) {           cout <<  YES n ;           return;         }       }     }     ok = false;     rec(0, 0, 0);     if (ok)       cout <<  YES n ;     else       cout <<  NO n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int FuN(long long n) {     string s;     while (n != 0) {       int ch = (n % 2);       s += ch +  0 ;       n /= 2;     }     int x = -1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) x = i + 1;     }     return x;   }   int main() {     int t, n, i, j;     t = 1;     cin >> t;     while (t--) {       long long ans = 0, fg = 1, a[200005], cnt = 0, x;       cin >> n;       map<long long, long long> m;       for (i = 1; i <= n; i++) {         cin >> a[i];         x = FuN(a[i]);         m[x]++;       }       for (auto it : m) {         ans += (it.second * (it.second - 1)) / 2;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const double EPS = 1e-9;   const double PI = acos(-1.);   const int INF = 1e9;   const int MAXN = 2e5 + 5;   const long long MOD = 1e9 + 7;   void output_path(int n, int a, int b, int c, int d) {     cout << a <<     << c <<    ;     for (int i = (1); i <= (int)(n); i++) {       if (i != a && i != b && i != c && i != d) {         cout << i <<    ;       }     }     cout << d <<     << b << endl;   }   void solve() {     int n, k, a, b, c, d;     cin >> n >> k >> a >> b >> c >> d;     if (n == 4 || k <= n) {       cout << -1 << endl;       return;     }     output_path(n, a, b, c, d);     output_path(n, c, d, a, b);   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   bool is_valid_streak(map<ll, ll>& unique_counts) {     if (unique_counts.size() == 2 && unique_counts.begin()->first == 1 &&         unique_counts.begin()->second == 1) {       return true;     } else if (unique_counts.size() == 2 &&                unique_counts.begin()->first + 1 ==                    unique_counts.rbegin()->first &&                unique_counts.rbegin()->second == 1) {       return true;     }     return false;   }   int main() {     ll n;     cin >> n;     vector<ll> a(n);     map<ll, ll> counts;     map<ll, ll> unique_counts;     set<ll> unique_values;     for (ll i = 0; i < n; i++) {       cin >> a[i];     }     ll ans = 0;     for (ll i = 0; i < n; i++) {       if (counts[a[i]] != 0) {         unique_counts[counts[a[i]]]--;         if (unique_counts[counts[a[i]]] == 0) {           unique_counts.erase(counts[a[i]]);         }       }       counts[a[i]]++;       unique_counts[counts[a[i]]]++;       unique_values.insert(a[i]);       if (unique_values.size() == 1) {         ans = i + 1;       } else if (unique_values.size() == i + 1) {         ans = i + 1;       } else if (is_valid_streak(unique_counts)) {         ans = i + 1;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int num = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch ^ 48);       ch = getchar();     }     return w ? -num : num;   }   int n, m;   vector<int> c[1005], r[1005];   char ch[1005][1005];   bool vis[1005], vis2[1005];   int main() {     n = read(), m = read();     int numj = 0, numi = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch[i][j];         if (ch[i][j] ==  # ) {           c[i].push_back(j);           r[j].push_back(i);           if (!vis[j]) {             numj++;             vis[j] = true;           }           if (!vis2[i]) {             vis2[i] = true;             numi++;           }         }       }     }     int tag;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (ch[i][j] ==  . ) {           if (c[i].size()) {             int len = c[i].size();             if (j > c[i][len - 1] || j < c[i][0])               tag = 1;             else {               cout << -1;               return 0;             }           }           if (r[j].size()) {             int len = r[j].size();             if (i > r[j][len - 1] || i < r[j][0])               tag = 1;             else {               cout << -1;               return 0;             }           }         }       }     }     int pre, aft, minl = 1005, maxl = 0, ans = 0, rest = 0;     for (int i = 1; i <= n; i++) {       pre = 0;       for (int j = 1; j <= m; j++) {         if (ch[i][j] ==  # ) {           if (!pre) pre = j;           if (j == m || ch[i][j + 1] ==  . ) aft = j;         }       }       if (!pre) {         rest++;         continue;       }       if (minl == 0) {         minl = pre;         maxl = aft;         ans++;       } else if (pre > maxl) {         ans++;         minl = pre;         maxl = aft;       } else if (aft < minl) {         minl = pre;         maxl = aft;         ans++;       } else {         maxl = max(maxl, aft);         minl = min(minl, pre);       }     }     if (numj == m && rest) {       cout << -1;       return 0;     }     rest = 0;     for (int i = 1; i <= m; i++) {       int flag = 0;       for (int j = 1; j <= n; j++) {         if (ch[j][i] ==  # ) {           flag = 1;           break;         }       }       if (!flag && numi == n) {         cout << -1;         return 0;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, max = 0, count1 = 0;       cin >> n;       vector<int> v;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         v.push_back(x);         if (max < x) {           max = x;         }       }       int c = v[0];       for (int i = 0; i < v.size(); i++) {         if (v[i] == c) {           count1++;         }         c = v[i];       }       if (count1 == n) {         cout <<  0  << endl;       } else {         vector<int> v1(10000);         map<int, int> mp;         long long int sum;         for (int i = 0; i < n; i++) {           sum = v[i];           for (int j = i + 1; j < n; j++) {             sum = sum + v[j];             if (sum <= 8000) {               v1[sum] = 1;             }           }         }         int count = 0;         for (int i = 0; i < n; i++) {           if (v1[v[i]]) {             count++;           }         }         cout << count << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   namespace jumpmelon {   long long divfloor(long long a, long long b) {     long long k = a / b;     if (k * b > a) k--;     return k;   }   long long divceil(long long a, long long b) {     long long k = a / b;     if (k * b < a) k++;     return k;   }   void work() {     long long n, i_l, i_r, i_k;     scanf( %lld%lld%lld%lld , &n, &i_l, &i_r, &i_k);     long long d = i_l <= i_r ? i_r - i_l + 1 : i_r + n - i_l + 1;     long long s = i_k - d, v = n - d + 1, ans = -1;     if (n <= 1000000) {       for (long long r = 0; r <= n; r++) {         long long a = max(0LL, r - v), b = min(d, r);         long long mink = max(0LL, divceil(s - b, n + r));         long long maxk = divfloor(s - a, n + r);         if (mink <= maxk) ans = max(ans, r);       }     } else {       for (long long k = 0; k * n <= s; k++) {         long long t = s - k * n;         long long minr = 0, maxr = n;         if (k) maxr = min(maxr, divfloor(t, k));         maxr = min(maxr, divfloor(t + v, k + 1));         if (k)           minr = max(minr, divceil(t - d, k));         else if (t > d)           continue;         minr = max(minr, divceil(t, k + 1));         if (minr <= maxr) ans = max(ans, maxr);       }     }     printf( %lld n , ans);   }   }  // namespace jumpmelon   int main() {     jumpmelon::work();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e5 + 10;   multiset<int> ms;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       ms.insert(x);     }     int cur = 1;     while (!ms.empty()) {       if (cur <= *ms.begin()) {         ms.erase(ms.find(*ms.begin()));         cur++;       } else {         ms.erase(ms.find(*ms.begin()));       }     }     cout << cur << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100][100];   struct point {    public:     int f, t;     point() {}     point(int a, int b) { f = a, t = b; }   };   int main() {     int X, k;     cin >> X >> k;     int val, sum = 0;     vector<pair<int, int>> a, b;     for (int i = 0; i < (X); i++) {       cin >> val;       sum += val;       a.push_back(make_pair(val, i + 1));     }     sort((a).begin(), (a).end());     int cnt = 0;     while (k--) {       int di = a[X - 1].first - a[0].first;       if (di > 1) {         a[X - 1].first--;         a[0].first++;         b.push_back(make_pair(a[X - 1].second, a[0].second));         sort((a).begin(), (a).end());         cnt++;       } else         break;     }     cout << a[X - 1].first - a[0].first <<     << cnt << endl;     for (int j = 0; j < (cnt); j++)       cout << b[j].first <<     << b[j].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   const int maxm = 5005;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n;     scanf( %d , &n);     int a[maxn];     bool exist[maxm];     for (int i = 0; i < maxm; ++i) exist[i] = true;     int i = 2;     while (i < maxm) {       int j = i + i;       if (exist[i]) {         while (j < maxm) {           exist[j] = false;           j += i;         }       }       i += 1;     }     vector<int> primes;     for (int i = 2; i < maxm; ++i)       if (exist[i]) {         primes.push_back(i);       }     for (int i = 0; i < n; ++i) scanf( %d , a + i);     int cur_gcd = gcd(a[0], a[1]);     for (int i = 2; i < n; ++i)       if (cur_gcd != 1) cur_gcd = gcd(cur_gcd, a[i]);     for (int i = 0; i < n; ++i) a[i] = a[i] / cur_gcd;     vector<int> nums;     for (int i = 0; i < n; ++i) {       int cur = a[i];       for (int j = 0; j < primes.size(); ++j)         if (primes[j] > cur)           break;         else if (cur % primes[j] == 0) {           nums.push_back(primes[j]);           while (cur % primes[j] == 0) {             cur = cur / primes[j];           }         }       if (cur > 1) nums.push_back(cur);     }     sort(nums.begin(), nums.end());     int ans = 0;     int left = 0, right = 0;     while (right < nums.size()) {       while (right < nums.size() && nums[right] == nums[left]) right++;       if (right - left > ans) {         ans = right - left;       }       left = right;     }     if (ans == 0 || ans == n)       cout << -1 << endl;     else       cout << n - ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[300010];   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       int prvi = -1, br_jednakih = 1, maxi = -1;       for (int i = 0; i < n; i++) {         cin >> a[i];         maxi = max(maxi, a[i]);         if (i == 0) {           prvi = a[i];           continue;         }         if (a[i] == prvi) {           br_jednakih++;         }       }       if (br_jednakih == n) {         cout << -1 << endl;         continue;       }       if (a[0] == maxi && a[1] != a[0]) {         cout << 1 << endl;         continue;       }       bool da = false;       for (int i = 1; i < n - 1; i++) {         if (a[i] == maxi && (a[i + 1] != maxi || a[i - 1] != maxi) && !da) {           cout << i + 1 << endl;           da = true;           break;         }       }       if (da) continue;       if (a[n - 1] == maxi && a[n - 2] != maxi) {         cout << n << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   void parse(int size, std::string& input, int& pos, int depth, int& max_depth,              std::vector<std::vector<std::string> >& comments) {     if (size <= pos) {       return;     }     if (depth > max_depth) {       max_depth = depth;       comments.push_back(std::vector<std::string>());     }     int end = pos;     while (input[end++] !=  , ) {     }     comments[depth].push_back(input.substr(pos, end - pos - 1));     pos = end;     while (end < size && input[end++] !=  , ) {     }     if (end == size) {       ++end;     }     int children = std::stoi(input.substr(pos, end - pos - 1));     pos = end;     for (int i = 0; i < children; ++i) {       parse(size, input, pos, depth + 1, max_depth, comments);     }   }   int main() {     std::string input;     std::cin >> input;     std::vector<std::vector<std::string> > comments;     int max_depth = -1, pos = 0, size = input.size();     while (pos < size) {       parse(size, input, pos, 0, max_depth, comments);     }     std::cout << max_depth + 1 << std::endl;     bool not_first;     for (std::vector<std::string>& level : comments) {       not_first = false;       for (std::string& comment : level) {         if (not_first) {           std::cout <<    ;         } else {           not_first = true;         }         std::cout << comment;       }       std::cout << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, CA, CB;   struct point {     int x, y;     bool operator<(const point &p) const { return x != p.x ? x < p.x : y < p.y; }   } st[201000];   int BX[201000], EX[201000], BY[201000], EY[201000];   long long res;   void Pro(vector<point> &w, int *B, int *E) {     int i;     int top = 0;     for (auto &tp : w) {       while (top && st[top].x + st[top].y >= tp.x + tp.y) top--;       if (top && st[top].y - st[top].x <= tp.y - tp.x) continue;       st[++top] = tp;     }     int pv = 1;     for (i = 1; i <= 200020; i++) {       while (pv < top &&              st[pv].y + abs(i - st[pv].x) >= st[pv + 1].y + abs(i - st[pv + 1].x))         pv++;       B[i] = st[pv].y + abs(i - st[pv].x);     }     top = 0;     for (auto &tp : w) {       while (top && st[top].y - st[top].x <= tp.y - tp.x) top--;       if (top && st[top].y + st[top].x >= tp.y + tp.x) continue;       st[++top] = tp;     }     pv = 1;     for (i = 1; i <= 200020; i++) {       while (pv < top &&              st[pv].y - abs(i - st[pv].x) <= st[pv + 1].y - abs(i - st[pv + 1].x))         pv++;       E[i] = st[pv].y - abs(i - st[pv].x);       if (B[i] > E[i]) B[i] = 1, E[i] = 0;     }   }   struct AA {     int t, y, ck;     bool operator<(const AA &p) const { return t < p.t; }   } T[401000];   int BIT[201000][2];   void Add(int a, int ck, int b) {     while (a <= 200020) {       BIT[a][ck] += b;       a += (a & -a);     }   }   int Sum(int a, int ck) {     if (a < 0) return 0;     int r = 0;     while (a) {       r += BIT[a][ck];       a -= (a & -a);     }     return r;   }   void Do(vector<point> w, int ck) {     if (w.empty()) return;     int i;     sort(w.begin(), w.end());     Pro(w, BX, EX);     for (i = 0; i < w.size(); i++) swap(w[i].x, w[i].y);     sort(w.begin(), w.end());     Pro(w, BY, EY);     int cnt = 0;     for (i = 1; i <= 200020; i++) {       BIT[i][0] = BIT[i][1] = 0;       T[cnt++] = {BY[i], i, 1};       T[cnt++] = {EY[i] + 1, i, -1};     }     sort(T, T + cnt);     int pv = 0;     for (i = 1; i <= 200020; i++) {       while (pv < cnt && T[pv].t <= i) {         Add(T[pv].y, T[pv].y % 2, T[pv].ck);         pv++;       }       if (BX[i] > EX[i]) continue;       res += Sum(EX[i], (ck + i) % 2) - Sum(BX[i] - 1, (ck + i) % 2);     }   }   int main() {     int i, x, y;     scanf( %d , &n);     vector<point> A, B;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       x += 1e5 + 10;       y += 1e5 + 10;       if ((x + y) % 2) {         A.push_back({x, y});       } else {         B.push_back({x, y});       }     }     Do(A, 0);     Do(B, 1);     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   long long n, h;   long long r(long long l, long long s, long long e, long long d) {     if (s + 1 == e) return 0;     long long m = 1 + (s + e) >> 1;     long long k =         (n < m ? (d ? (1ll << (h - l)) : 1) : (d ? 1 : (1ll << (h - l))));     if (n < m) return r(l + 1, s, m, 1) + k;     return r(l + 1, m, e, 0) + k;   }   int main() {     cin >> h >> n;     --n;     cout << r(0, 0, 1ll << h, 0);   }


#include <bits/stdc++.h>   using namespace std;   int ar[200010];   vector<int> ans;   void solve() {     int n, a, b, k, cnt = 0;     cin >> n >> a >> b >> k;     string s;     cin >> s;     int nxt = n + 1;     for (int i = n; i > 0; i--) {       if (s[i - 1] ==  1 ) {         cnt += (nxt - i - 1) / b;         nxt = i;       }       ar[i] = nxt;     }     cnt += (nxt - 1) / b;     int last = 0;     if (cnt < a) {       printf( 0 n );       return;     }     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  1 ) {         last = i;         continue;       }       if (i - last == b) {         cnt--;         ans.push_back(i);         last = i;         if (cnt < a) break;       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     printf(  n );   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     int n, d, h;     cin >> n >> d >> h;     if (d > 2 * h || (d == 1 && (n - 1 > d))) {       cout << -1 << endl;     } else {       for (int i = 1; i <= h; i++) {         cout << i <<     << i + 1 << endl;       }       if (d > h) {         cout << 1 <<     << h + 2 << endl;         for (int i = h + 2; i <= d; i++) {           cout << i <<     << i + 1 << endl;         }       }       if (n - 1 > d) {         if (h > 1) {           for (int i = d + 2; i <= n; i++) {             cout << 2 <<     << i << endl;           }         } else {           for (int i = d + 2; i <= n; i++) {             cout << 1 <<     << i << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a[105];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int c = 0;     for (int i = 0; i < n;) {       if (a[i] == 1) {         while (a[i] == 1 || a[i + 1] == 1) {           c++;           i++;           if (i == n) break;         }       }       i++;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};   using namespace std;   template <class T>   T sq(T n) {     return n * n;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   bool inside(T a, T b, T c) {     return a <= b && b <= c;   }   template <class T>   void setmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void setmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   pair<int, int> in[110];   int main() {     int n, T, t = 1, m, i, j, k;     while (scanf( %d , &n) == 1) {       scanf( %d , &k);       double ans = 0;       for (i = 0; i < n; i++) {         scanf( %d , &in[i].first);         scanf( %d , &in[i].second);       }       for (i = 1; i < n; i++) {         ans += sqrt((double)((             ((in[i].first - in[i - 1].first) * (in[i].first - in[i - 1].first)) +             ((in[i].second - in[i - 1].second) *              (in[i].second - in[i - 1].second)))));       }       ans /= (double)50.0;       printf( %.15lf n , ans * (double)k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double m1 = 200.0, m2 = 0.0, DV;   int card, n, k, Q, getcard;   int a[110], vs[110], b[110], len = 0;   int sum = 0, tmp;   int main() {     memset(vs, 0, sizeof(vs));     scanf( %d%d , &n, &k);     card = (int)(n / k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) {       sum = 0;       for (int j = 1; j <= card; ++j) {         scanf( %d , &tmp);         sum += a[tmp];         vs[tmp] = 1;       }       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;     }     for (int i = 1; i <= n; ++i)       if (!vs[i]) b[++len] = a[i];     getcard = (n - len) / card;     if (len >= card && getcard < k) {       sort(b + 1, b + len + 1);       sum = 0;       for (int i = 1; i <= card; ++i) sum += b[i];       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;       sum = 0;       for (int i = len - card + 1; i <= len; ++i) sum += b[i];       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;     }     printf( %.10lf %.10lf n , m1, m2);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a = 0, b = 0, r = 0;     while (true) {       a = (int)n / 36;       r = n % 36;       b = (int)r / 3;       if (r % 3 == 2) b += 1;       if (b >= 12)         n = b * 3 + a * 36;       else         break;     }     cout << a <<     << b << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum Type { Normal, HBox, VBox };   struct Widget {     char name[11];     long long width, height;     int border, spacing;     vector<int> sons;     Type type;   };   int wCnt;   Widget widgets[101];   map<string, int> name2id;   int str2int(char* start, char* end) {     int res = 0;     for (char* p = start; p != end; ++p) {       res = res * 10 + (*p -  0 );     }     return res;   }   void addWidget(char name[11], int width, int height, Type type) {     strcpy(widgets[wCnt].name, name);     widgets[wCnt].width = width;     widgets[wCnt].height = height;     widgets[wCnt].border = 0;     widgets[wCnt].spacing = 0;     widgets[wCnt].type = type;     name2id[name] = wCnt;     wCnt++;   }   bool isWidget(char buf[50]) {     if (strncmp(buf,  Widget , 6) == 0) {       char name[11];       int width, height;       int p1, p2, p3;       for (int i = 7; buf[i] !=   0 ; ++i) {         if (buf[i] ==  ( ) {           p1 = i;         } else if (buf[i] ==  , ) {           p2 = i;         } else if (buf[i] ==  ) ) {           p3 = i;         }       }       strncpy(name, buf + 7, p1 - 7);       name[p1 - 7] =   0 ;       width = str2int(buf + p1 + 1, buf + p2);       height = str2int(buf + p2 + 1, buf + p3);       addWidget(name, width, height, Normal);       return true;     } else {       return false;     }   }   bool isBox(char buf[50]) {     char name[11];     if (strncmp(buf,  HBox , 4) == 0) {       strcpy(name, buf + 5);       addWidget(name, 0, 0, HBox);       return true;     } else if (strncmp(buf,  VBox , 4) == 0) {       strcpy(name, buf + 5);       addWidget(name, 0, 0, VBox);       return true;     } else {       return false;     }   }   void operate(char buf[50]) {     char name[11];     int p1, p2, p3;     for (int i = 0; buf[i] !=   0 ; ++i) {       if (buf[i] ==  . ) {         p1 = i;       } else if (buf[i] ==  ( ) {         p2 = i;       } else if (buf[i] ==  ) ) {         p3 = i;       }     }     strncpy(name, buf, p1);     name[p1] =   0 ;     int idx = name2id[name];     if (strncmp(buf + p1 + 1,  pack , p2 - p1 - 1) == 0) {       char packName[11];       strncpy(packName, buf + p2 + 1, p3 - p2 - 1);       packName[p3 - p2 - 1] =   0 ;       int packIdx = name2id[packName];       widgets[idx].sons.push_back(packIdx);     } else if (strncmp(buf + p1 + 1,  set_border , p2 - p1 - 1) == 0) {       int border = str2int(buf + p2 + 1, buf + p3);       widgets[idx].border = border;     } else if (strncmp(buf + p1 + 1,  set_spacing , p2 - p1 - 1) == 0) {       int spacing = str2int(buf + p2 + 1, buf + p3);       widgets[idx].spacing = spacing;     }   }   void compBox(int idx) {     if (widgets[idx].sons.size() == 0 || widgets[idx].width != 0) {       return;     }     int sonSize = widgets[idx].sons.size();     for (int i = 0; i < sonSize; ++i) {       int sonIdx = widgets[idx].sons[i];       compBox(sonIdx);       if (widgets[idx].type == HBox) {         widgets[idx].width += widgets[sonIdx].width;         widgets[idx].height = max(widgets[idx].height, widgets[sonIdx].height);       } else if (widgets[idx].type == VBox) {         widgets[idx].width = max(widgets[idx].width, widgets[sonIdx].width);         widgets[idx].height += widgets[sonIdx].height;       }     }     widgets[idx].width += 2 * widgets[idx].border;     widgets[idx].height += 2 * widgets[idx].border;     if (widgets[idx].type == HBox) {       widgets[idx].width += (sonSize - 1) * widgets[idx].spacing;     } else if (widgets[idx].type == VBox) {       widgets[idx].height += (sonSize - 1) * widgets[idx].spacing;     }   }   void compSize() {     for (int i = 0; i < wCnt; ++i) {       if (widgets[i].type != Normal && widgets[i].width == 0 &&           widgets[i].sons.size() != 0) {         compBox(i);       }     }   }   bool cmp(Widget a, Widget b) {     return (strcmp(a.name, b.name) <= 0) ? true : false;   }   void clear() {     name2id.clear();     for (int i = 0; i < wCnt; ++i) {       widgets[i].sons.clear();     }   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       getchar();       wCnt = 0;       while (n--) {         char buf[50];         fgets(buf, 50, stdin);         int bufLen = strlen(buf);         buf[bufLen - 1] =   0 ;         if (isWidget(buf)) {           continue;         }         if (isBox(buf)) {           continue;         }         operate(buf);       }       compSize();       sort(widgets, widgets + wCnt, cmp);       for (int i = 0; i < wCnt; ++i) {         printf( %s %I64d %I64d n , widgets[i].name, widgets[i].width,                widgets[i].height);       }       clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = (int)1e9;   const double inf1 = 1e-9;   const int ss = (int)1e6 + 3;   int main() {     string s;     getline(cin, s);     int sz = s.find( . );     int z1 = 0;     if (sz == -1) {       sz = s.size();       z1 = -1;     }     string res;     int z = 0;     if (s[0] ==  - ) {       res =  ( ;       z = 1;     }     res +=  $ ;     for (int i = z; i < (sz - z) % 3 + z; ++i) res += s[i];     if ((sz - z) % 3 != 0) res +=  , ;     string tmp;     for (int i = (sz - z) % 3 + z; i < sz; i += 3) {       res += s[i];       res += s[i + 1];       res += s[i + 2];       res +=  , ;     }     res.erase(res.size() - 1, 1);     res +=  . ;     s +=  00 ;     res += s[sz + 1 + z1];     res += s[sz + 2 + z1];     if (s[0] ==  - ) {       res +=  ) ;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long ans1, ans2;       long long n, m;       cin >> n >> m;       ans1 = n * m / 2;       ans2 = ans1;       if (n * m % 2) ans1++;       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long white1 = (x2 - x1 + 1) * (y2 - y1 + 1) / 2;       long long black1 = white1;       if ((x2 - x1 + 1) * (y2 - y1 + 1) % 2) {         if (abs(x2 - y2) % 2)           black1++;         else           white1++;       }       long long x3, y3, x4, y4;       cin >> x3 >> y3 >> x4 >> y4;       long long white2 = (x4 - x3 + 1) * (y4 - y3 + 1) / 2;       long long black2 = white2;       if ((x4 - x3 + 1) * (y4 - y3 + 1) % 2) {         if (abs(x4 - y3) % 2)           black2++;         else           white2++;       }       long long x5 = max(x1, x3), y5 = max(y1, y3), x6 = min(x2, x4),                 y6 = min(y2, y4);       long long white = 0, black = 0;       if (x5 <= x6 && y5 <= y6) {         long long gapx = x6 - x5 + 1;         long long gapy = y6 - y5 + 1;         white = gapx * gapy / 2;         black = white;         if (gapx * gapy % 2) {           if (abs(x5 - y5) % 2)             black++;           else             white++;         }       }       ans1 -= white;       ans2 -= black;       white1 -= white;       black1 -= black;       white2 -= white;       black2 -= black;       ans1 += black1;       ans2 -= black1;       ans2 += white2;       ans1 -= white2;       ans2 += white + black;       cout << ans1 <<     << ans2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int inf = numeric_limits<int>::max() >> 1;   constexpr int N = 100001;   constexpr int mod = 1000000007;   int h[N], tin[N], tout[N], ap[N], n, root, a[N], T;   int mx[N * 4], mn[N * 4], ml[N * 4];   vector<int> g[N];   void dfs(int u, int p) {     tin[u] = ++T;     ap[T] = u;     h[u] = h[p] + 1;     for (int v : g[u])       if (v != p) dfs(v, u);     tout[u] = T;   }   void build(int id, int l, int r) {     if (l == r) {       mx[id] = h[ap[l]];       mn[id] = a[ap[l]];       ml[id] = h[ap[l]];       return;     }     build((id << 1), l, (l + r) / 2);     build(((id << 1) + 1), (l + r) / 2 + 1, r);     mx[id] = max(mx[(id << 1)], mx[((id << 1) + 1)]);     mn[id] = min(mn[(id << 1)], mn[((id << 1) + 1)]);     ml[id] = min(ml[(id << 1)], ml[((id << 1) + 1)]);     return;   }   int query(int id, int l, int r, int L, int R, int dep) {     if (R < l || r < L) return inf;     if (ml[id] > dep) return inf;     if (L <= l && r <= R && mx[id] <= dep) return mn[id];     return min(query((id << 1), l, (l + r) / 2, L, R, dep),                query(((id << 1) + 1), (l + r) / 2 + 1, r, L, R, dep));   }   void solution() {     cin >> n >> root;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(root, 0);     build(1, 1, n);     int m;     cin >> m;     int last = 0;     while (m--) {       int p, q;       cin >> p >> q;       p = 1 + ((p + last) % n);       q = (q + last) % n;       last = query(1, 1, n, tin[p], tout[p], h[p] + q);       cout << last <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc = 1;     while (tc--) {       solution();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 1;   int vis[M], vis2[M];   int main() {     string t, s;     cin >> s >> t;     int a = 0, b = 0;     for (char c : t) vis[c]++;     int i = 0;     for (char c : s) {       if (vis[c]) {         vis[c]--;         a++;         vis2[i] = 1;       }       i++;     }     for (i = 0; i < s.size(); i++) {       if (vis2[i]) continue;       char c = s[i];       if (islower(c))         c = toupper(c);       else         c = tolower(c);       if (vis[c]) b++, vis[c]--;     }     cout << a <<     << b;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const long long MOD = 998244353;   vector<vector<pair<long long, long long> > > adj;   int c[2];   int colour[700005];   bool ok;   int n;   void dfs(int idx) {     c[colour[idx]] += (idx <= n);     for (auto x : adj[idx]) {       if (colour[x.first] == -1) {         colour[x.first] = colour[idx] ^ x.second;         dfs(x.first);       } else if (colour[x.first] != (colour[idx] ^ x.second)) {         ok = false;       }     }   }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int m;       cin >> n >> m;       adj.assign(n + m + 5, vector<pair<long long, long long> >());       for (int i = 0; i < n + m + 5; i++) {         colour[i] = -1;       }       int fake = n + 1;       for (int i = 0; i < m; i++) {         int a, b;         string c;         cin >> a >> b >> c;         if (c ==  crewmate ) {           adj[a].push_back(pair<long long, long long>(fake, 1));           adj[fake].push_back(pair<long long, long long>(a, 1));           adj[fake].push_back(pair<long long, long long>(b, 1));           adj[b].push_back(pair<long long, long long>(fake, 1));           fake++;         } else {           adj[a].push_back(pair<long long, long long>(b, 1));           adj[b].push_back(pair<long long, long long>(a, 1));         }       }       int ans = 0;       ok = true;       for (int i = 1; i < n + 1; i++) {         if (colour[i] == -1) {           colour[i] = 0;           c[0] = c[1] = 0;           dfs(i);           ans += max(c[0], c[1]);         }       }       if (!ok) {         ans = -1;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b[100], c, xd = 0, lol;     cin >> a;     for (int i = 0; i < a; i++) {       cin >> b[i];     }     sort(b, b + a);     for (int i = 0; i < a; i++) {       if (i == a - 1) {         c = b[i];       }     }     for (int i = 0; i < a; i++) {       if (b[i] <= c) {         xd = xd + (c - b[i]);       }     }     cout << xd;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   const long double pi = 3.1415926535897932384626433832795;   const long double eps = 1e-8;   const int MAXN = 1000500;   string s;   int n;   int fin[3];   struct node {     int l, r, par, link;     map<char, int> next;     node(int l = 0, int r = 0, int par = -1) : l(l), r(r), par(par), link(-1) {}     int len() { return r - l; }     int &get(char c) {       if (!next.count(c)) next[c] = -1;       return next[c];     }   };   node t[MAXN];   int sz;   struct state {     int v, pos;     state(int v, int pos) : v(v), pos(pos) {}   };   state ptr(0, 0);   state go(state st, int l, int r) {     while (l < r)       if (st.pos == t[st.v].len()) {         st = state(t[st.v].get(s[l]), 0);         if (st.v == -1) return st;       } else {         if (s[t[st.v].l + st.pos] != s[l]) return state(-1, -1);         if (r - l < t[st.v].len() - st.pos) return state(st.v, st.pos + r - l);         l += t[st.v].len() - st.pos;         st.pos = t[st.v].len();       }     return st;   }   int split(state st) {     if (st.pos == t[st.v].len()) return st.v;     if (st.pos == 0) return t[st.v].par;     node v = t[st.v];     int id = sz++;     t[id] = node(v.l, v.l + st.pos, v.par);     t[v.par].get(s[v.l]) = id;     t[id].get(s[v.l + st.pos]) = st.v;     t[st.v].par = id;     t[st.v].l += st.pos;     return id;   }   int get_link(int v) {     if (t[v].link != -1) return t[v].link;     if (t[v].par == -1) return 0;     int to = get_link(t[v].par);     return t[v].link = split(                go(state(to, t[to].len()), t[v].l + (t[v].par == 0), t[v].r));   }   void tree_extend(int pos) {     for (;;) {       state nptr = go(ptr, pos, pos + 1);       if (nptr.v != -1) {         ptr = nptr;         return;       }       int mid = split(ptr);       int leaf = sz++;       t[leaf] = node(pos, n, mid);       t[mid].get(s[pos]) = leaf;       ptr.v = get_link(mid);       ptr.pos = t[ptr.v].len();       if (!mid) break;     }   }   void build_tree() {     sz = 1;     for (int i = 0; i < n; ++i) tree_extend(i);   }   long long d[MAXN][3];   long long ans[MAXN];   const int MOD = 1e9 + 7;   long long bal[MAXN];   void add(int l, int r, int val) {     bal[l] += val;     bal[r + 1] -= val;   }   void dfs(int v, int len) {     for (auto w : ::t[v].next) {       int nlen = len + ::t[w.second].len();       dfs(w.second, nlen);     }     int tt = -1;     for (int i = 0; i < (int)(3); ++i)       if (fin[i] >= t[v].l && fin[i] < t[v].r) {         tt = i;         break;       }     if (tt != -1)       d[v][tt] = 1;     else {       for (auto w : ::t[v].next) {         for (int i = 0; i < (int)(3); ++i) d[v][i] += d[w.second][i];       }       long long c = 1;       for (int i = 0; i < (int)(3); ++i) c = (c * d[v][i]) % MOD;       add(len - t[v].len() + 1, len, c);     }   }   int main() {     vector<string> in(3);     for (int i = 0; i < (int)(3); ++i) {       cin >> in[i];       s += in[i];       fin[i] = s.length();       s += char( 0  + i);     }     n = s.length();     build_tree();     dfs(0, 0);     int l = 1e9;     for (int i = 0; i < (int)(3); ++i) l = min(l, (int)in[i].length());     long long z = 0;     for (int i = 0; i < (int)(MAXN); ++i) {       z += bal[i];       z %= MOD;       z = (z + MOD) % MOD;       ans[i] = z;     }     for (int i = 1; i <= (int)(l); ++i) printf( %d  , (int)ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using UL = unsigned long int;   using UI = unsigned int;   using ULL = unsigned long long int;   using LI = long int;   using LL = long long;   using LF = double;   using LLF = long double;   const int mod1 = 1000000007;   const int mod2 = 998244353;   const double PI = acos(-1);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int ntc = 1, tc, i, j;     int n, k;     for (tc = 1; tc <= ntc; tc++) {       cin >> n >> k;       string s;       cin >> s;       int cnt1[26] = {0}, cnt2[26] = {0};       string ans =   ;       for (auto ch : s) {         cnt1[ch -  a ]++;       }       for (i = 0; i < 26 && k > 0; i++) {         cnt2[i] += min(k, cnt1[i]);         k -= min(k, cnt1[i]);       }       for (auto ch : s) {         if (cnt2[ch -  a ] > 0) {           cnt2[ch -  a ]--;           continue;         }         cout << ch;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1004;   int n, p, q, f[N][54][54], vc = 1000000000, ns[N][30], nt[N][30];   char c[N], s[N], t[N];   bool check1(int i, char x, int j) {     if (i + 1 < j) return false;     for (int k = 1; k < j; k++) {       if (s[i + k - j + 1] != s[k]) return false;     }     if (x != s[j]) return false;     return true;   }   bool check2(int i, char x, int j) {     if (i + 1 < j) return false;     for (int k = 1; k < j; k++) {       if (t[i + k - j + 1] != t[k]) return false;     }     if (x != t[j]) return false;     return true;   }   void build() {     for (int i = 0; i <= p; i++) {       for (char x =  a ; x <=  z ; x++) {         for (int j = p; j >= 1; j--) {           if (check1(i, x, j)) {             ns[i][x -  a  + 1] = j;             break;           }         }       }     }     for (int i = 0; i <= q; i++) {       for (char x =  a ; x <=  z ; x++) {         for (int j = q; j >= 1; j--) {           if (check2(i, x, j)) {             nt[i][x -  a  + 1] = j;             break;           }         }       }     }   }   int cal(int i, int x, int y) {     if (i == n) return 0;     if (f[i][x][y] != -vc) return f[i][x][y];     f[i][x][y] = -vc + 1;     if (c[i + 1] ==  * ) {       for (char b =  a ; b <=  z ; b++) {         int cost = 0;         int nx1 = ns[x][b -  a  + 1];         if (nx1 == p) cost++;         int nx2 = nt[y][b -  a  + 1];         if (nx2 == q) cost--;         f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);       }     } else {       int cost = 0;       char b = c[i + 1];       int nx1 = ns[x][b -  a  + 1];       if (nx1 == p) cost++;       int nx2 = nt[y][b -  a  + 1];       if (nx2 == q) cost--;       f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);     }     return f[i][x][y];   }   int main() {     scanf( %s%s%s , c + 1, s + 1, t + 1);     p = strlen(s + 1);     q = strlen(t + 1);     n = strlen(c + 1);     build();     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= p; j++) {         for (int z = 0; z <= q; z++) f[i][j][z] = -vc;       }     }     cout << cal(0, 0, 0);   }


#include <bits/stdc++.h>   using namespace std;   string S;   set<string> answer;   void izomorphism1(string &s) {     swap(s[0], s[3]);     swap(s[1], s[3]);     swap(s[2], s[3]);   }   void izomorphism2(string &s) {     swap(s[1], s[4]);     swap(s[3], s[5]);     swap(s[4], s[5]);   }   void izomorphism3(string &s) {     swap(s[4], s[2]);     swap(s[0], s[5]);     swap(s[4], s[5]);   }   int main() {     cin >> S;     sort(S.begin(), S.end());     do {       string cur_S, min_string;       cur_S = S;       min_string = S;       for (int i = 1; i <= 4; i++, izomorphism1(cur_S))         for (int j = 1; j <= 4; j++, izomorphism2(cur_S))           for (int z = 1; z <= 4; z++, izomorphism3(cur_S)) {             min_string = min(min_string, cur_S);           }       answer.insert(min_string);     } while (next_permutation(S.begin(), S.end()));     cout << answer.size() << endl;     return 0;   }


#include <bits/stdc++.h>   const unsigned long long maxn = 70;   unsigned long long n, flg, KKK, ans;   unsigned long long f[maxn], mul10[maxn], cycle[maxn], a[maxn];   struct matrix {     unsigned long long len, wid;     unsigned long long mt[3][3];   } pre[14][45];   inline unsigned long long min(unsigned long long a, unsigned long long b) {     return a < b ? a : b;   }   unsigned long long modmul(unsigned long long a, unsigned long long b,                             unsigned long long mod) {     unsigned long long res = 0;     while (b) {       if (b & 1) {         res += a;         if (res > mod) res -= mod;       }       a += a;       if (a > mod) a -= mod;       b >>= 1;     }     return res;   }   matrix mul(matrix a, matrix b, unsigned long long mod) {     matrix res;     res.len = a.len, res.wid = b.wid;     for (unsigned long long u = 1; u <= a.len; u++)       for (unsigned long long v = 1; v <= b.wid; v++) res.mt[u][v] = 0;     for (unsigned long long u = 1; u <= a.len; u++)       for (unsigned long long v = 1; v <= b.wid; v++)         for (unsigned long long w = 1; w <= a.wid; w++)           res.mt[u][v] =               (res.mt[u][v] + modmul(a.mt[u][w], b.mt[w][v], mod)) % mod;     return res;   }   unsigned long long calc(unsigned long long b, unsigned long long kk,                           unsigned long long mod) {     matrix a, res;     res.len = 1, res.wid = 2, res.mt[1][1] = 0, res.mt[1][2] = 1;     for (unsigned long long i = 0; i <= 44; i++)       if ((b >> i) & 1) res = mul(res, pre[kk][i], mod);     return res.mt[1][1];   }   void dfs(unsigned long long len, unsigned long long now) {     if (now > ans) return;     if (len == n + 1) {       flg = 1, ans = min(ans, now);       return;     }     for (unsigned long long i = 0; i < 10; i++) {       unsigned long long k =           (modmul(i, cycle[len], cycle[len + 1]) + now) % cycle[len + 1];       if (calc(k, len, mul10[len]) == a[len]) dfs(len + 1, k);     }   }   signed main() {     f[0] = 0, f[1] = 1;     for (unsigned long long i = 2; i <= 60; i++) f[i] = f[i - 1] + f[i - 2];     cycle[0] = 6, mul10[0] = 1;     for (unsigned long long i = 1; i <= 19; i++)       cycle[i] = 10ll * cycle[i - 1], mul10[i] = 10ll * mul10[i - 1];     for (unsigned long long i = 1; i <= 13; i++) {       pre[i][0].len = pre[i][0].wid = 2, pre[i][0].mt[1][1] = 0,       pre[i][0].mt[1][2] = pre[i][0].mt[2][1] = pre[i][0].mt[2][2] = 1;       for (unsigned long long j = 1; j <= 44; j++)         pre[i][j] = mul(pre[i][j - 1], pre[i][j - 1], mul10[i]);     }     scanf( %llu , &KKK);     n = 13, ans = 10000000000000000;     for (unsigned long long i = 1; i <= n; i++)       a[i] = a[i - 1] + KKK % 10 * mul10[i - 1], KKK /= 10;     for (unsigned long long i = 0; i < 60; i++)       if (f[i] % 10 == a[1]) dfs(1, i);     if (flg == 0)       puts( -1 );     else       printf( %llu n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     int n, m;     cin >> n >> m;     int now1 = 0;     for (int i = 0; i < n; i++) {       int c, t;       cin >> c >> t;       now1 += c * t;       mp[now1] = 1;     }     map<int, int>::iterator it = mp.begin();     int now = 0;     for (int i = 0; i < m; i++) {       int v;       cin >> v;       while (v > it->first) {         it++;         now++;       }       cout << now + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T, class U>   inline void print(T first, U second) {     printsp(first);     println(second);   }   template <class T, class U, class V>   inline void print(T first, U second, V z) {     printsp(first);     printsp(second);     println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int ch[300010], re[300010], a[300010];   int C(int n, int m) {     return ((long long)ch[n] * re[m] % 1000000007) * (long long)re[n - m] %            1000000007;   }   void pre() {     ch[0] = 1;     for (int i = 1; i < 300010; i++)       ch[i] = (long long)ch[i - 1] * i % 1000000007;     re[300010 - 1] = power(ch[300010 - 1], 1000000007 - 2, 1000000007);     for (int i = 300010 - 1; i > 0; i--)       re[i - 1] = (long long)re[i] * i % 1000000007;     return;   }   int main() {     pre();     int n;     gn(n);     for (int i = 1; i <= n; i++) gn(a[i]);     if (n == 1) {       printf( %d n , a[1]);       return 0;     }     if (n == 2) {       printf( %d n , ((a[1] + a[2]) % 1000000007 + 1000000007) % 1000000007);       return 0;     }     if (n & 1) {       for (int i = 1; i < n; i++) {         if (i & 1)           a[i] = ((a[i] + a[i + 1]) % 1000000007 + 1000000007) % 1000000007;         else           a[i] = ((a[i] - a[i + 1]) % 1000000007 + 1000000007) % 1000000007;       }       n--;     }     if (n == 2) {       printf( %d n , (a[1] + a[2]) % 1000000007);       return 0;     }     long long ans1 = 0, ans2 = 0;     int m = n / 2;     for (int i = 1; i <= n; i++) {       if (i & 1) {         ans1 =             (ans1 + (long long)C(m - 1, i / 2) * a[i] % 1000000007) % 1000000007;       } else {         ans2 = (ans2 + (long long)C(m - 1, i / 2 - 1) * a[i] % 1000000007) %                1000000007;       }     }     if (m & 1 == 1)       printf( %I64d n , (ans1 + ans2) % 1000000007);     else       printf( %I64d n , ((ans1 - ans2) % 1000000007 + 1000000007) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   struct node {     int x, y;     int dir, len;   } arr[1100 * 1100], st[1100];   int n, m, tot, vis[1100][1100], cnt;   int srow[1100][1100], scol[1100][1100];   int dir[4] = {1, -1, -1, 1};   char mmap[1100][1100];   void Initial() {     int i, j, k;     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) srow[i][j] = srow[i][j - 1] + vis[i][j];     for (j = 1; j <= m; ++j)       for (i = 1; i <= n; ++i) scol[i][j] = scol[i - 1][j] + vis[i][j];   }   int GetDir(char c) {     if (c ==  N ) return 0;     if (c ==  S ) return 1;     if (c ==  W ) return 2;     if (c ==  E ) return 3;   }   int Isok(int in) {     int i, j, k, x, y;     x = st[in].x, y = st[in].y;     for (i = 1; i <= tot; ++i) {       int td = arr[i].dir, tl = arr[i].len;       if (td == 0) {         if (x - tl <= 0) return 0;         if (scol[x][y] - scol[x - tl - 1][y] > 0) return 0;         x -= tl;       } else if (td == 1) {         if (x + tl >= n + 1) return 0;         if (scol[x + tl][y] - scol[x - 1][y] > 0) return 0;         x += tl;       } else if (td == 2) {         if (y - tl <= 0) return 0;         if (srow[x][y] - srow[x][y - tl - 1] > 0) return 0;         y -= tl;       } else {         if (y + tl >= m + 1) return 0;         if (srow[x][y + tl] - srow[x][y - 1] > 0) return 0;         y += tl;       }     }     cnt++;     return 1;   }   int main() {     int i, j, k;     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 0; i < 26; ++i) st[i].x = -1;       for (i = 1; i <= n; ++i) {         scanf( %s , mmap[i] + 1);         for (j = 1; j <= m; ++j) {           if (mmap[i][j] >=  A  && mmap[i][j] <=  Z )             st[mmap[i][j] -  A ].x = i, st[mmap[i][j] -  A ].y = j;           vis[i][j] = mmap[i][j] ==  #  ? 1 : 0;         }       }       Initial();       scanf( %d , &tot);       for (i = 1; i <= tot; ++i) {         char str[20];         scanf( %s %d , str, &arr[i].len);         arr[i].dir = GetDir(str[0]);       }       cnt = 0;       for (i = 0; i < 26; ++i)         if (st[i].x != -1 && Isok(i)) printf( %c , i +  A );       if (cnt == 0) printf( no solution n );       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 5;   int a[N], b[N];   bool mark[N];   vector<int> ch;   int main() {     int n, m, mn, ans = 0;     cin >> n >> m;     mn = n / m;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= m && !mark[a[i]]) {         b[a[i]]++;         if (b[a[i]] == mn) mark[a[i]] = true;       } else         ch.push_back(i);     }     for (int i = 1; i <= m; i++)       while (!mark[i]) {         ans++;         a[ch.back()] = i;         ch.pop_back();         b[i]++;         if (b[i] == mn) mark[i] = true;       }     cout << mn <<     << ans <<   n ;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   const unsigned long long inf = 1LL << 61;   const double eps = 1e-5;   using namespace std;   bool cmp(int a, int b) { return a > b; }   string itoa(long long a) {     string t =   ;     while (a > 0) {       t += (char)(a % 10 +  0 );       a /= 10;     }     string s =   ;     for (int i = t.size() - 1; i >= 0; i--) s += t[i];     return s;   }   long long atoi(string s) {     long long t = 1;     long long ans = 0;     for (int i = s.size() - 1; i >= 0; i--) {       long long b = (long long)(s[i] -  0 );       ans += b * t;       t *= 10;     }     return ans;   }   int main() {     int n, m;     while (cin >> n >> m) {       long long c = m + n;       string c1 = itoa(c);       string c2 =   ;       for (int i = 0; i < c1.size(); i++) {         if (c1[i] !=  0 ) c2 += c1[i];       }       long long cc = atoi(c2);       string a = itoa(n);       string b = itoa(m);       string a1 =   ;       string b1 =   ;       for (int i = 0; i < a.size(); i++) {         if (a[i] !=  0 ) a1 += a[i];       }       for (int j = 0; j < b.size(); j++) {         if (b[j] !=  0 ) b1 += b[j];       }       long long aa = atoi(a1);       long long bb = atoi(b1);       if (aa + bb == cc)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int ans[100005];   string s[100005];   map<string, int> h;   vector<pair<int, int> > v;   string res[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   int main() {     memset(ans, -1, sizeof(ans));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     h[ S ] = 0;     h[ M ] = 1;     h[ L ] = 2;     h[ XL ] = 3;     h[ XXL ] = 4;     h[ XXXL ] = 5;     for (int i = 0; i < 6; i++) cin >> a[i];     int n;     cin >> n;     bool ok = 1;     for (int i = 1; i <= n; i++) {       cin >> s[i];       string t[2];       t[0] =   ;       t[1] =   ;       int k = 0;       int m = s[i].length();       for (int j = 0; j < m; j++) {         if (s[i][j] ==  , )           k++;         else           t[k] += s[i][j];       }       if (t[1] ==   ) {         ans[i] = h[t[0]];         a[h[t[0]]]--;         if (a[h[t[0]]] < 0) ok = 0;       } else         v.push_back(pair<int, int>(h[t[0]], i));     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       int j = v[i].second, x = v[i].first;       if (a[x] > 0)         ans[j] = x, a[x]--;       else         ans[j] = x + 1, a[x + 1]--;     }     for (int i = 0; i < 6; i++)       if (a[i] < 0) ok = 0;     if (!ok)       printf( NO n );     else {       cout <<  YES             <<   n ;       for (int i = 1; i <= n; i++) cout << res[ans[i]] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[103], n, x, y, m, ans;   int main() {     cin >> x >> y >> n;     m = x * y;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int x, j;       cin >> x;       for (j = 0; j < n; j++) {         if (a[j] == x) break;       }       ans = ans + j + 1;       for (int k = j - 1; k >= 0; k--) a[k + 1] = a[k];       a[0] = x;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void runcase() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int changes = 0;     k--;     for (int i = 1; i < n; i++)       if (a[i] != a[i - 1]) changes++;     int ans = 0;     if (k == 0) {       if (changes == 0)         ans = 1;       else         ans = -1;     } else {       ans = max(1, (changes + k - 1) / k);     }     cout << ans << endl;   }   int main() {     int t;     cin >> t;     while (t--) runcase();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<long long int> a(n);     vector<long long int> mp(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     vector<long long int> ans(n + 1);     priority_queue<pair<long long, long long>> pq;     long long cost = 0;     for (int i = 0; i < n + 1; i++) {       ans[i] = mp[i] + cost;       if (mp[i] == 0) {         if (pq.empty()) {           for (int j = i + 1; j < n + 1; j++) ans[j] = -1;           break;         }         auto tp = pq.top();         pq.pop();         cost += (long long)(i - tp.first);         tp.second--;         if (tp.second > 1) pq.push({tp.first, tp.second});       }       if (mp[i] > 1) pq.push({i, mp[i]});     }     for (int i = 0; i < n + 1; i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> in[101000];   int n, m, k, curt;   int up[101000], t[101000], tout[101000], ans[101000];   int jmp[101000][20];   char used[101000];   void dfs(int v, int p) {     if (used[v]) return;     used[v] = 1;     t[v] = curt++;     up[v] = t[v];     for (unsigned int i = 0; i < in[v].size(); i++)       if (used[in[v][i]]) {         if (p != in[v][i]) up[v] = min(up[v], t[in[v][i]]);       } else {         dfs(in[v][i], v);         up[v] = min(up[v], up[in[v][i]]);       }   }   void dfs2(int v, int cur) {     if (used[v]) return;     used[v] = 1;     ans[v] = cur;     for (unsigned int i = 0; i < in[v].size(); i++)       if (!used[in[v][i]] && !((t[v] < t[in[v][i]] && up[in[v][i]] > t[v]) ||                                (t[v] > t[in[v][i]] && up[v] > t[in[v][i]])))         dfs2(in[v][i], cur);     for (unsigned int i = 0; i < in[v].size(); i++)       if (!used[in[v][i]] && ((t[v] < t[in[v][i]] && up[in[v][i]] > t[v]) ||                               (t[v] > t[in[v][i]] && up[v] > t[in[v][i]])))         dfs2(in[v][i], cur + 1);   }   void getLCA(int v, int p) {     if (used[v]) return;     used[v] = 1;     t[v] = curt++;     jmp[v][0] = p;     for (int i = 1; i <= 18; ++i) jmp[v][i] = jmp[jmp[v][i - 1]][i - 1];     for (unsigned int i = 0; i < in[v].size(); i++)       if (in[v][i] != p) getLCA(in[v][i], v);     tout[v] = curt++;   }   char upp(int a, int b) { return t[a] <= t[b] && tout[a] >= tout[b]; }   int lca(int a, int b) {     if (upp(a, b)) return a;     if (upp(b, a)) return b;     for (int i = 18; i >= 0; --i)       if (!upp(jmp[a][i], b)) a = jmp[a][i];     return jmp[a][0];   }   int main(void) {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int q, w;       cin >> q >> w;       in[q].push_back(w);       in[w].push_back(q);     }     dfs(1, -1);     memset(used, 0, sizeof(used));     curt = 0;     dfs2(1, 0);     curt = 0;     memset(used, 0, sizeof(used));     getLCA(1, 1);     cin >> k;     for (int i = 0; i < k; i++) {       int q, w;       cin >> q >> w;       int l = lca(q, w);       cout << ans[q] + ans[w] - 2 * ans[l] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y, r, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double diam = 2 * r;     double dist = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));     int q = 0;     if (dist == 0) {       cout << 0 << endl;     } else {       while (dist >= diam) {         dist -= diam;         q++;       }       if (dist == 0) {         cout << q << endl;       } else {         cout << q + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int MAX = 1e5 + 7;   using namespace std;   string st =  fedabc ;   void solve(unsigned long long n, char c) {     n--;     unsigned long long res = 16LL * (n / 4LL);     if (n % 2) res += 7;     res += st.find(c) + 1;     cout << res;   }   void mysolve(unsigned long long n, char c) {     unsigned long long l = 0, r = n / 2;     unsigned long long res = 0;     while (l <= r) {       unsigned long long mid = (l + r) / 2;       if ((1 + (mid + (mid * 3LL))) <= n) {         res = mid;         l = mid + 1;       } else {         r = mid - 1;       }     }     unsigned long long currF = (1 + (res + (res * 3)));     unsigned long long served = 2LL * res;     unsigned long long sec = 6;     if ((currF == n) || (currF + 2 == n)) {       sec += ((served - 1) * 6) + (currF - 1);     } else if (currF + 1 == n || currF + 3 == n) {       sec += (served * 6) + (currF);     } else if (currF + 4 == n || currF + 6 == n) {       sec += ((served + 1) * 6) + (currF + 1);     }     for (auto i : st) {       sec++;       if (i == c) break;     }     cout << sec;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     unsigned long long n = stoll(s.substr(0, s.size() - 1));     char seat = s[s.size() - 1];     solve(n, seat);   }


#include <bits/stdc++.h>   using namespace std;   int ar[1002][1002];   char buf[20];   int main() {     int n, m, k, w;     int res = 0;     vector<pair<int, int> > r;     scanf( %d %d %d %d n , &n, &m, &k, &w);     vector<vector<string> > f(k);     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         fgets(buf, 20, stdin);         string s = buf;         s = s.substr(0, s.size() - 1);         f[i].push_back(s);       }     }     for (int i = 0; i < f.size(); i++) {       for (int j = i + 1; j < f.size(); j++) {         int d = 0;         for (int e = 0; e < n; e++) {           for (int l = 0; l < m; l++) {             if (f[i][e][l] != f[j][e][l]) d++;           }         }         if (d * w < n * m) {           ar[i + 1][j + 1] = d * w;           ar[j + 1][i + 1] = d * w;         } else {           ar[i + 1][j + 1] = 1000;           ar[j + 1][i + 1] = 1000;         }       }     }     for (int i = 0; i < k + 1; i++) {       ar[0][i] = n * m;       ar[i][0] = n * m;     }     vector<char> used(k + 1, false);     vector<int> min_edge(k + 1, 1000), end_edge(k + 1, -1);     min_edge[0] = 0;     for (int i = 0; i < k + 1; i++) {       int v = -1;       for (int j = 0; j < k + 1; j++) {         if (!used[j] && (v == -1 || min_edge[j] < min_edge[v])) v = j;       }       used[v] = true;       if (end_edge[v] != -1) {         res += ar[v][end_edge[v]];         r.push_back(pair<int, int>(v, end_edge[v]));       }       for (int j = 0; j < k + 1; j++) {         if (ar[v][j] < min_edge[j]) {           min_edge[j] = ar[v][j];           end_edge[j] = v;         }       }     }     printf( %d n , res);     for (int i = 0; i < r.size(); i++) {       printf( %d %d n , r[i].first, r[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   size_t ham_dist(const string &a, const string &b) {     size_t ct = 0;     for (size_t i = 0; i < a.size(); ++i)       if (a[i] != b[i]) ++ct;     return ct;   }   string opp(const string &a) {     string r =   ;     for (size_t i = 0; i < a.size(); ++i) r += (a[i] ==  0  ?  1  :  0 );     return r;   }   string read_line(size_t m) {     string r;     for (size_t j = 0; j < m; ++j) {       char c[2];       cin >> c;       r += string(c);     }     return r;   }   string string_from_int(size_t len, size_t z) {     string o;     for (size_t i = 0; i < len; ++i) {       if (z & (1 << i))         o +=  1 ;       else         o +=  0 ;     }     return o;   }   int main() {     size_t n, m, k;     cin >> n >> m >> k;     map<string, size_t> counts;     vector<string> mat;     mat.reserve(n);     for (size_t i = 0; i < n; ++i) {       string l = read_line(m);       mat.push_back(l);     }     if (n < m) {       vector<string> newmat = mat;       swap(n, m);       mat.clear();       mat.reserve(n);       for (size_t i = 0; i < n; ++i) {         string p;         for (size_t j = 0; j < m; ++j) {           p += newmat[j][i];         }         mat.push_back(p);       }     }     for (size_t i = 0; i < n; ++i) {       string &l = mat[i];       if (counts.find(l) == counts.end()) counts[l] = 0;       ++counts[l];     }     bool feasible = false;     if (counts.size() <= k + 2) {       if (n <= k) {         for (size_t z = 0; z < ((size_t)1 << m); ++z) {           string l = string_from_int(m, z);           if (counts.find(l) == counts.end()) counts[l] = 0;         }       }       for (map<string, size_t>::iterator it = counts.begin(); it != counts.end();            ++it) {         size_t cost = 0;         for (map<string, size_t>::iterator jt = counts.begin();              jt != counts.end(); ++jt) {           if (jt->second == 0) continue;           size_t cost_per = ham_dist(it->first, jt->first);           cost_per = min(cost_per, ham_dist(opp(it->first), jt->first));           cost += cost_per * jt->second;         }         if (cost <= k) {           feasible = true;           k = cost;         }       }     }     if (!feasible) {       cout <<  -1  << endl;     } else {       cout << k << endl;     }     return 0;   }


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


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


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 0, k = 0, s = 0;     cin >> n >> k >> s;     int sz = min(n * (n - 1), k * (k - 1) / 2 + s);     vector<vector<int> > dp(k + 1, vector<int>(sz + 1, 1e9 + 42));     dp[0][0] = 0;     for (int pos = 0; pos < n; pos++) {       int q;       cin >> q;       for (int i = k - 1; i >= 0; i--)         for (int j = sz - pos; j >= 0; j--)           dp[i + 1][j + pos] = min(dp[i + 1][j + pos], dp[i][j] + q);     }     int ans = 1e9 + 42;     for (int i = k * (k - 1) / 2; i <= sz; i++) ans = min(ans, dp[k][i]);     cout << ans;     return 0;   }


//  “Alhamdulillah for Everything”   #include<bits/stdc++.h>   using namespace std;      #define      pai              acos(-1)   #define      ff               first   #define      ss               second   #define      ll               long long   #define      pb               push_back   #define      mp               make_pair   #define      pll              pair<ll,ll>   #define      sz(a)            (ll)a.size()   #define      endl               n    #define      gcd(a, b)        __gcd(a, b)   #define      lcm(a, b)        ((a*b)/gcd(a,b))   #define      all(vec)         vec.begin(),vec.end()   #define      ms(a, b)         memset(a,b,sizeof(a))   #define      rep(i,n)         for(int i= 0; i < int(n); i++)   #define      rep1(i,n)        for(int i= 1; i <= n; i++)   #define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)   #define      PRINT_CASE       printf( Case %d:  ,zz)   #define      fii              freopen( input.txt , r ,stdin);   #define      foo              freopen( output.txt , w ,stdout);   #define      boom             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);      const ll M   = 1e9+7;   const ll mxn = 1e5+7;   const ll inf = 1e18;      int  main()   {       //boom;       ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;       cin>>t;       TEST_CASE(t)       {           cin>>n>>k;           vector<ll>vec(n);           for(i=0;i<n;i++)           {               cin>>vec[i];           }           ll ans=0,sum=vec[0];           for(i=1;i<n;i++)           {               a=vec[i]*100;               b=sum*k;               if(a<b)               {                   sum+=vec[i];               }               else               {                   ll tem=a-b+k-1;                   tem/=k;                   sum+=(vec[i]+tem);                   ans+=tem;               }               //cout<<i<< === <<sum<< ==== <<ans<<endl;           }           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return SQR(POW(B, P / 2));   }   template <typename T>   inline T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T BMOD(T p, T e, T m) {     T ret = 1;     while (e) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;       e >>= 1;     }     return (T)ret;   }   int n, T;   int wt[200005], bit[200005];   set<pair<int, int> > st;   void update(int pos) {     while (pos < 200001) {       bit[pos] += 1;       pos += (pos & -pos);     }     return;   }   int query(int pos) {     int sum = 0;     while (pos > 0) {       sum += bit[pos];       pos -= (pos & -pos);     }     return sum;   }   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) {       scanf( %d , &wt[i]);       st.insert(make_pair(wt[i] - i, i));     }     int ans = 0;     for (auto &i : st) {       int xx = i.first;       int yy = i.second;       update(yy);       int rng = T - 1 - xx;       rng = min(n, rng);       rng = min(rng, T - 1);       if (rng <= 0) continue;       int id = query(rng);       ans = max(ans, id);     }     printf( %d , ans), puts(  );     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1025;   const int maxm = 10;   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     int ans1 = 0, ans2 = 0;     int cnt1 = 0;     int f = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         f = 1;         ans1 = max(ans1, cnt1);         cnt1 = 0;         continue;       }       if (s[i] ==  ) ) {         f = 0;         continue;       }       if (!f) {         if (s[i] !=  _ ) {           cnt1++;         } else {           ans1 = max(ans1, cnt1);           cnt1 = 0;         }       }       if (f) {         if ((s[i - 1] ==  (  || s[i - 1] ==  _ ) && s[i] !=  _ ) {           ans2++;         }       }     }     ans1 = max(ans1, cnt1);     cnt1 = 0;     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (abs(n - k) == 1 || ((n - k) == 0 && n > 0 && k > 0)) {       cout <<  YES ;     } else       cout <<  NO ;   }