#include <bits/stdc++.h>   using namespace std;   int tree[2000004];   int A[500002];   long long modular_pow(long long base, long long exponent, long long modulus) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   void build(int node, int start, int end) {     if (start == end) {       tree[node] = A[start];     } else {       int mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       tree[node] = tree[2 * node] + tree[2 * node + 1];     }   }   int query(int node, int start, int end, int l, int r) {     if (r < start or end < l) {       return 0;     }     if (l <= start and end <= r) {       return tree[node];     }     int mid = (start + end) / 2;     int p1 = query(2 * node, start, mid, l, r);     int p2 = query(2 * node + 1, mid + 1, end, l, r);     return (p1 + p2);   }   int main() {     int n, d;     scanf( %d %d , &n, &d);     int ar[n];     for (int i = 0; i < n; i++) scanf( %d , &ar[i]);     sort(ar, ar + n);     long long int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (ar[i + 1] - ar[i] > 2 * d) {         ans += 2;         continue;       }       if (ar[i + 1] - ar[i] == 2 * d) {         ans++;         continue;       }     }     ans += 2;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     long n(0);     scanf( %ld , &n);     std::map<long, long> solutions;     bool possible(1);     for (int k = 0; k < n; k++) {       long number(0), participant(0);       scanf( %ld %ld , &number, &participant);       if (solutions.find(participant) != solutions.end()) {         if (number > 1 + solutions[participant]) {           possible = 0;           break;         }         if (number > solutions[participant]) {           solutions[participant] = number;         }       } else {         if (number > 0) {           possible = 0;           break;         } else {           solutions.insert(std::pair<long, long>(participant, 0));         }       }     }     puts(possible ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct node {     int x, p;   } a[N];   int d, n, m, top, xx, nexttttt[N], last, q[N];   long long ans;   bool cmp(node a, node b) { return a.x < b.x; }   int main() {     scanf( %d%d%d , &d, &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i].x, &a[i].p);     sort(a + 1, a + m + 1, cmp);     a[m + 1].x = d;     a[m + 1].p = 0;     for (int i = m + 1; i >= 0; i--) {       if (a[i].x - a[i - 1].x > n) {         puts( -1 );         return 0;       }       while (top && a[i].p < a[q[top]].p) top--;       nexttttt[i] = q[top];       q[++top] = i;     }     for (int i = 0; i <= m; i++) {       xx = max(0, min(a[nexttttt[i]].x - a[i].x, n) - last);       ans += 1ll * xx * a[i].p;       last -= a[i + 1].x - a[i].x - xx;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, a[3][30], half;   long long ans, ans1, ans2;   struct node {     long long x, y, z;     bool operator<(const node& T) const {       if (x != T.x)         return x < T.x;       else if (y != T.y)         return y < T.y;       else         return z < T.z;     }   };   map<node, long long> b;   void pt(long long s, long long s1) {     long long val = 0;     long long temp = s;     long long temp1 = s1;     for (int w = 0; w < half; w++) {       if (s % 3 == 1 || s % 3 == 2) val += a[0][w];       s /= 3;     }     for (int w = half; w < n; w++) {       if (s1 % 3 == 1 || s1 % 3 == 2) val += a[0][w];       s1 /= 3;     }     if (val > ans) {       ans = val;       ans1 = temp;       ans2 = temp1;     }   }   void solve(int ind, long long s, long long r, long long w, long long mask) {     if (ind == -1) {       long long g = min(s, min(r, w));       s -= g;       r -= g;       w -= g;       b[{s, r, w}] = mask;     } else {       solve(ind - 1, s, r + a[1][ind], w + a[2][ind], mask * 3);       solve(ind - 1, s + a[0][ind], r, w + a[2][ind], mask * 3 + 1);       solve(ind - 1, s + a[0][ind], r + a[1][ind], w, mask * 3 + 2);     }   }   void solve1(int ind, long long s, long long r, long long w, long long mask) {     if (ind == half - 1) {       long long g = min(s, min(r, w));       node temp = {s, r, w};       s -= g;       r -= g;       w -= g;       if (s >= r && s >= w) {         if (b[{0, s - r, s - w}]) {           pt(b[{0, s - r, s - w}], mask);         }       }       if (r >= s && r >= w) {         if (b[{r - s, 0, r - w}]) {           pt(b[{r - s, 0, r - w}], mask);         }       }       if (w >= s && w >= r) {         if (b[{w - s, w - r, 0}]) {           pt(b[{w - s, w - r, 0}], mask);         }       }     } else {       solve1(ind - 1, s, r + a[1][ind], w + a[2][ind], mask * 3);       solve1(ind - 1, s + a[0][ind], r, w + a[2][ind], mask * 3 + 1);       solve1(ind - 1, s + a[0][ind], r + a[1][ind], w, mask * 3 + 2);     }   }   int main() {     scanf( %d , &n);     b.clear();     for (i = 0; i < n; i++) scanf( %d%d%d , &a[0][i], &a[1][i], &a[2][i]);     if (n == 1) {       if (a[0][0] == 0 && a[1][0] == 0)         printf( LM n );       else if (a[0][0] == 0 && a[2][0] == 0)         printf( LW n );       else if (a[1][0] == 0 && a[2][0] == 0)         printf( MW n );       else         printf( Impossible n );       return 0;     }     half = (n + 1) / 2;     ans = -1000000000;     solve(half - 1, 0, 0, 0, 0);     solve1(n - 1, 0, 0, 0, 0);     if (ans == -1000000000)       return 0 * printf( Impossible n );     else {       for (i = 0; i < half; i++) {         if (ans1 % 3 == 0)           printf( MW n );         else if (ans1 % 3 == 1)           printf( LW n );         else           printf( LM n );         ans1 /= 3;       }       for (i = half; i < n; i++) {         if (ans2 % 3 == 0)           printf( MW n );         else if (ans2 % 3 == 1)           printf( LW n );         else           printf( LM n );         ans2 /= 3;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   stack<int> s1;   char a[200005];   int flag[200005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     memset(flag, 0, sizeof(flag));     scanf( %s , a);     int l = 0;     for (int i = 0; i < n; i++) {       if (l == k) break;       if (a[i] ==  ( ) {         s1.push(i);       }       if (a[i] ==  )  && !s1.empty()) {         l += 2;         flag[i] = 1;         flag[s1.top()] = 1;         s1.pop();       }     }     for (int i = 0; i < n; i++) {       if (flag[i]) printf( %c , a[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b) {     long long res = ((long long)a * b) % 1000000007;     return res;   }   int binaryPow(int n, int p) {     int acc = 1;     while (p) {       if (p & 1) acc = mult(acc, n);       n = mult(n, n);       p /= 2;     }     return acc;   }   int modularInv(int n) { return binaryPow(n, 1000000007 - 2); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k, pa, pb;     cin >> k >> pa >> pb;     int pd = modularInv(pa + pb);     int dp[k + 1][k + 1];     for (int i = k; i >= 1; i--) {       for (int j = k; j >= 0; j--) {         if (i + j < k) {           dp[i][j] = mult(               (mult(pa, dp[i + 1][j]) + mult(pb, dp[i][i + j])) % 1000000007, pd);         } else {           dp[i][j] = (i + j + mult(pa, modularInv(pb))) % 1000000007;         }       }     }     cout << dp[1][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     int s = 0, o = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) o = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) s *= 10, s += c -  0 ;     return s * o;   }   const int mod = (int)1e9 + 7;   struct Mat {     int n;     long long x;     int a[31][31];     void operator*=(const Mat &p) {       int c[31][31];       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           long long r = 0;           for (int k = 0; k < n; k++) r += (1ll * a[i][k] * p.a[k][j]) % mod;           c[i][j] = r % mod;           if (c[i][j] < 0) c[i][j] += mod;         }       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) a[i][j] = c[i][j];     }     void write() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) printf( %d  , a[i][j]);         printf(  n );       }     }   } A[70][30], B[70][30];   long long n;   int k;   Mat I;   Mat calc(int i, int j, long long n) {     Mat r = I;     if (n == 0) return r;     for (int timer = 0; timer < k; timer++) {       if (n >= A[i][j].x)         r *= A[i][j];       else         r *= calc(i - 1, j, n);       n -= A[i][j].x;       if (n <= 0) break;       j = (j + 1) % k;     }     return r;   }   int main(int argc, char const *argv[]) {     scanf( %I64d%d , &n, &k);     I.n = k + 1;     for (int i = 0; i < I.n; i++)       for (int j = 0; j < I.n; j++) I.a[i][j] = i == j;     for (int i = 0; i < k; i++) {       Mat &M = A[0][i];       M.n = k + 1, M.x = 1;       for (int t = 0; t < k + 1; t++)         for (int s = 0; s < k + 1; s++) M.a[t][s] = (t == s || t == i);       Mat &N = B[0][i];       N.n = k + 1, N.x = 1;       for (int t = 0; t < k + 1; t++)         for (int s = 0; s < k + 1; s++) {           if (t == i) N.a[t][s] = -1;           if (t == s) N.a[t][s] = 1;         }     }     int i;     for (i = 0;; i++) {       long long _x = A[i][0].x * k;       if (_x > n || _x < 0) break;       Mat &M = A[i + 1][0];       M = A[i][0];       M.x = _x;       for (int p = 1; p < k; ++p) M *= A[i][p];       for (int j = 1; j < k; ++j) {         Mat &M = A[i + 1][j];         M = B[i][j - 1];         M *= A[i + 1][j - 1];         M *= A[i][j - 1];         M.x = _x;       }       Mat &N = B[i + 1][0];       N = B[i][k - 1];       N.x = _x;       for (int p = k - 2; p >= 0; --p) N *= B[i][p];       for (int j = 1; j < k; ++j) {         Mat &N = B[i + 1][j];         N = B[i][j - 1];         N *= B[i + 1][j - 1];         N *= A[i][j - 1];         N.x = _x;       }     }     Mat res = calc(i, 0, n);     long long r = 0;     for (int i = 0; i < k + 1; i++) r += res.a[i][k];     printf( %I64d n , r % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> values;   map<int, bool> reverseVisited;   map<int, vector<int> > rev;   stack<int> lastVisited;   map<int, bool> visited;   map<int, vector<int> > cities;   void dfs(int init) {     visited[init] = true;     for (int i = 0; i < cities[init].size(); i++) {       if (!visited[cities[init][i]]) {         dfs(cities[init][i]);       }     }     lastVisited.push(init);   }   void dfs2(int init, long long int &mini, long long int &ww) {     reverseVisited[init] = true;     if (mini > values[init])       mini = values[init], ww = 1;     else if (mini == values[init])       ww++;     for (int i = 0; i < rev[init].size(); i++) {       if (!reverseVisited[rev[init][i]]) dfs2(rev[init][i], mini, ww);     }   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int w;       cin >> w;       values[i] = w;     }     int m;     cin >> m;     while (m--) {       int u, v;       cin >> u >> v;       cities[u].push_back(v);       rev[v].push_back(u);       visited[u] = false;       reverseVisited[v] = false;     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         dfs(i);       }     }     long long int minMoney = 0, numWays = 1;     while (!lastVisited.empty()) {       long long int po = 1000000007;       int q = lastVisited.top();       lastVisited.pop();       if (!reverseVisited[q]) {         long long int ww = 0;         dfs2(q, po, ww);         minMoney += po;         if (ww > 0) numWays *= ww;         numWays %= 1000000007;       }     }     cout << minMoney <<     << numWays << endl;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 100000 + 10;   int ans[N], sum, a[N], c[N];   int n, m, block, root, id[N], size[N];   int ne[N << 1], to[N << 1], first[N], tot;   int num[N], tim[N];   void add(int u, int v) {     ne[tot] = first[u];     to[tot] = v;     first[u] = tot++;   }   struct Node {     int l, r, id, k;     bool operator<(const Node& e) const {       return l / block < e.l / block || l / block == e.l / block && r < e.r;     }   } q[N];   int dfs(int u, int f) {     id[u] = ++tot;     size[u] = 1;     for (int i = first[u]; ~i; i = ne[i]) {       int v = to[i];       if (v == f) continue;       size[u] += dfs(v, u);     }     return size[u];   }   void Init() {     root = 1;     memset(first, -1, sizeof(first));     scanf( %d%d , &n, &m);     block = (int)ceil(pow(n, 0.5));     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     tot = 0;     dfs(root, -1);     for (int i = 1; i <= n; i++) a[id[i]] = c[i];     for (int i = 1; i <= m; i++) {       int v;       scanf( %d%d , &v, &q[i].k);       q[i].l = id[v];       q[i].r = id[v] + size[v] - 1;       q[i].id = i;     }     sort(q + 1, q + 1 + m);   }   void add(int pos) {     num[a[pos]]++;     tim[num[a[pos]]]++;   }   void del(int pos) {     tim[num[a[pos]]]--;     num[a[pos]]--;   }   int main() {     Init();     int L = 1, R = 0;     for (int i = 1; i <= m; i++) {       while (L < q[i].l) del(L++);       while (L > q[i].l) add(--L);       while (R < q[i].r) add(++R);       while (R > q[i].r) del(R--);       ans[q[i].id] = tim[q[i].k];     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int l, r, a, count;     scanf( %d%d%d , &l, &r, &a);     count = 0;     while (count < a) {       if (l > (r + a)) {         r = r + a;         goto x;       }       if (r > (l + a)) {         l = l + a;         goto x;       }       if (l < r) {         l++;         count++;       }       if (l == r) {         if ((a - count) % 2 == 0) {           l = l + (a - count) / 2;           r = r + (a - count) / 2;           goto x;         } else {           l = l + (a - count - 1) / 2;           r = r + (a - count - 1) / 2;           goto x;         }       }       if (r < l) {         r++;         count++;       }     }   x:     if (l <= r)       printf( %d , 2 * l);     else       printf( %d , 2 * r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, M = 35;   int n, m, x;   int g[M][M], tot, v[1000][2];   int main() {     int T;     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &g[i][j]);         }       }       int ans = 0;       memset(v, 0, sizeof(v));       tot = (n + m - 1) / 2;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           int k = i + j - 1;           if (k <= tot) {             v[k][g[i][j]]++;           } else if ((m + n - k) <= tot) {             v[(m + n - k)][g[i][j]]++;           }         }       }       for (int i = 1; i <= tot; i++) {         ans += min(v[i][0], v[i][1]);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, h, g;     vector<int> home, guest;     cin >> n;     while (n--) {       cin >> h >> g;       home.push_back(h);       guest.push_back(g);     }     n = home.size();     h = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (home[i] == guest[j]) h++;       }     }     cout << h <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> bit(n);     for (int i = 0; i < n; i++) {       cin >> bit[i];     }     bit.push_back(bit[n - 1]);     int bit_before = bit[0];     int bit_start = bit[0];     int start = 0;     int cur_max = 0;     for (int i = 1; i < n + 1; i++) {       if (bit_before == bit[i]) {         int end = i - 1;         cur_max = max(cur_max, (end - start) / 2);         if (bit_start != bit[end]) {           for (int j = start + 1; j <= (end + start) / 2; j++) bit[j] = bit_start;           for (int j = (end + start) / 2 + 1; j < end; j++) bit[j] = bit[end];         } else {           for (int j = start; j <= end; j++) bit[j] = bit[end];         }         start = i;         bit_start = bit[i];       }       bit_before = bit[i];     }     cout << cur_max << endl;     for (int i = 0; i < n - 1; i++) cout << bit[i] <<    ;     cout << bit[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   int n, m, c[2005][2005];   char s[2005][2005];   bool vis[2005][2005];   bool judge(int x, int y) {     return x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ;   }   queue<pair<int, int> > q;   void bfs(int x, int y) {     vis[x][y] = 1;     q.push(make_pair(x, y));     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       for (int k = 0; k < 4; k++) {         int tx = p.first + d[k][0];         int ty = p.second + d[k][1];         if (judge(tx, ty) && !vis[tx][ty]) {           vis[tx][ty] = 1;           if (k == 0) {             s[p.first][p.second] =  < ;             s[tx][ty] =  > ;           } else if (k == 1) {             s[p.first][p.second] =  > ;             s[tx][ty] =  < ;           }           if (k == 2) {             s[p.first][p.second] =  ^ ;             s[tx][ty] =  v ;           }           if (k == 3) {             s[p.first][p.second] =  v ;             s[tx][ty] =  ^ ;           }           for (int i = 0; i < 4; i++) {             int ttx = tx + d[i][0];             int tty = ty + d[i][1];             if (judge(ttx, tty) && !vis[ttx][tty]) {               c[ttx][tty]--;               if (c[ttx][tty] == 1) {                 q.push(make_pair(ttx, tty));                 vis[ttx][tty] = 1;               }             }           }           break;         }       }     }   }   bool has_ans() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (s[i][j] ==  . ) return 0;     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (s[i][j] ==  * ) continue;         for (int k = 0; k < 4; k++)           if (judge(i + d[k][0], j + d[k][1])) c[i][j]++;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (c[i][j] == 1 && !vis[i][j]) bfs(i, j);     if (has_ans())       for (int i = 0; i < n; i++) printf( %s n , s[i]);     else       printf( Not unique n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool isPrime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   int main() {     cin >> n;     for (int i = (1); i <= (1000); i++)       if (!isPrime(n * i + 1)) {         cout << i;         return 0;       }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     string str, ch[103];     int n;     cin >> str >> n;     for (int i = 1; i <= n; i++) cin >> ch[i];     sort(ch + 1, ch + 1 + n);     for (int i = 1; i <= n; i++) {       int len = str.length();       string t = ch[i].substr(0, len);       if (t == str) {         cout << ch[i] << endl;         return 0;       }     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXV = 210;   const int MAXE = 40010;   const int inf = 1e9;   struct Edge {     int u, v, cap, flow, next;   } grana[MAXE];   int n, m, E;   vector<int> odd, even, sol[MAXV], g[MAXV];   int head[MAXV], dist[MAXV];   int src, snk, k;   bool mark[MAXV];   int val[MAXV], a[MAXV];   bool is_prime(int x) {     int rt = sqrt(x);     for (int i = 2; i <= rt; i++)       if (x % i == 0) return false;     return true;   }   void add_edge(int u, int v, int c1, int c2) {     grana[E++] = (Edge){u, v, c1, 0, head[u]};     head[u] = E - 1;     grana[E++] = (Edge){v, u, c2, 0, head[v]};     head[v] = E - 1;   }   bool bfs() {     fill(dist, dist + MAXV, -1);     queue<int> q;     dist[src] = 0;     for (q.push(src); !q.empty(); q.pop()) {       int u = q.front();       for (int e = head[u]; e != -1; e = grana[e].next) {         int v = grana[e].v;         if (grana[e].cap > grana[e].flow && dist[v] == -1) {           dist[v] = dist[u] + 1;           q.push(v);         }       }     }     return (dist[snk] != -1);   }   int dfs(int u, int minCap) {     if (minCap == 0) return 0;     if (u == snk) return minCap;     for (int e = head[u]; e != -1; e = grana[e].next) {       int v = grana[e].v;       if (dist[v] != dist[u] + 1) continue;       int augment = dfs(v, min(minCap, grana[e].cap - grana[e].flow));       if (augment) {         grana[e].flow += augment;         grana[e ^ 1].flow -= augment;         return augment;       }     }     return 0;   }   int Dinic() {     int flow = 0, bf = 0;     while (bfs()) {       do {         bf = dfs(src, inf);         flow += bf;       } while (bf);     }     return flow;   }   void fail() {     printf( Impossible );     exit(0);   }   void traversal(int u, int num) {     mark[u] = true;     sol[num].push_back(val[u]);     for (int i = 0; i < 2; i++) {       int v = g[u][i];       if (!mark[v]) {         traversal(v, num);         return;       }     }   }   int main() {     fill(head, head + MAXV, -1);     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a[i] = x;       if (x & 1)         odd.push_back(x);       else         even.push_back(x);     }     if (odd.size() != even.size()) fail();     src = n, snk = n + 1;     for (int i = 0; i < even.size(); i++) {       for (int j = 0; j < odd.size(); j++) {         if (is_prime(even[i] + odd[j])) {           add_edge(i, even.size() + j, 1, 0);         }       }     }     for (int i = 0; i < even.size(); i++) add_edge(src, i, 2, 0);     for (int i = 0; i < odd.size(); i++) add_edge(even.size() + i, snk, 2, 0);     int maxFlow = Dinic();     if (maxFlow < n) fail();     for (int i = 0; i < even.size(); i++) {       for (int e = head[i]; e != -1; e = grana[e].next) {         if (grana[e].flow == 1) {           g[i].push_back(grana[e].v);           g[grana[e].v].push_back(i);         }       }     }     int p = 0;     for (int i = 0; i < even.size(); i++) {       while (a[p] != even[i]) p++;       val[i] = p + 1;       p++;     }     p = 0;     for (int i = 0; i < odd.size(); i++) {       while (a[p] != odd[i]) p++;       val[(int)(even.size()) + i] = p + 1;       p++;     }     for (int i = 0; i < n; i++)       if (!mark[i]) traversal(i, k++);     printf( %d n , k);     for (int i = 0; i < k; i++) {       printf( %d  , sol[i].size());       for (auto xt : sol[i]) printf( %d  , xt);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long c, f, l;   };   bool operator<(node a, node b) { return a.f < b.f; }   long long n, dx, fx, bn, tot, i, tf, fn, first, xn, sum, xx;   node a[100004], b[100004];   bool can;   int main() {     cin >> n >> dx >> fx;     bn = -1;     tot = 0;     for (i = 0; i < n; i++) {       cin >> a[i].c >> a[i].f >> a[i].l;       tot += a[i].c;       if (a[i].l >= dx) {         bn++;         b[bn] = a[i];       }     }     bn++;     sort(b, b + bn);     can = false;     tf = 0;     fn = 0;     first = -1;     for (i = 0; i < bn; i++) {       if (tf + b[i].f <= fx) {         tf += b[i].f;         if (b[i].c != 0 && first == -1) {           first = i;           can = true;         }         fn++;       }     }     if (can == false) {       first = -1;       for (i = 0; i < bn; i++) {         if (b[i].c != 0) {           first = i;           break;         }       }       if (first != -1) {         if (b[first].f <= fx) {           tf = b[first].f;           xx = 0;           for (i = 0; i < bn; i++) {             if (tf + b[i].f > fx) break;             tf += b[i].f;             xx++;           }           if (tot + xx + 1 > fn) {             can = true;             fn = xx + 1;           }         }       }     }     if (can == true) {       if (tot + fn > n) {         cout << n <<    ;         xn = n - tot;         if (xn - 1 < first) {           sum = 0;           for (i = 0; i <= xn - 2; i++) sum += b[i].f;           sum += b[first].f;         } else {           sum = 0;           for (i = 0; i < xn; i++) sum += b[i].f;         }         cout << sum << endl;       } else {         cout << tot + fn <<    ;         if (fn - 1 < first) {           sum = 0;           for (i = 0; i < fn - 1; i++) sum += b[i].f;           sum += b[first].f;         } else {           sum = 0;           for (i = 0; i < fn; i++) sum += b[i].f;         }         cout << sum << endl;       }     } else {       cout << fn <<    ;       sum = 0;       for (i = 0; i < fn; i++) sum += b[i].f;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const long long MODSQ = 1LL * MOD * MOD;   int W[8];   int dp[1 << 7][1 << 7][8][2];   struct matrix {     int sz;     int data[1 << 7][1 << 7];   };   matrix multiply(matrix& a, matrix& b) {     matrix c;     c.sz = a.sz;     for (int i = 0; i < c.sz; i++)       for (int j = 0; j < c.sz; j++) {         long long sum = 0;         for (int k = 0; k < c.sz; k++) {           sum += 1LL * a.data[i][k] * b.data[k][j];           if (sum >= MODSQ) sum -= MODSQ;         }         c.data[i][j] = sum % MOD;       }     return c;   }   matrix pow(matrix b, int e) {     if (e == 1) return b;     matrix ret = pow(multiply(b, b), e / 2);     if (e & 1) return multiply(ret, b);     return ret;   }   matrix transition_matrix(int sz) {     matrix ret;     ret.sz = 1 << sz;     for (int i = 0; i < (1 << sz); i++)       for (int j = 0; j < (1 << sz); j++) ret.data[i][j] = dp[i][j][sz][1];     return ret;   }   int main() {     for (int i = 0; i < (1 << 7); i++)       for (int j = 0; j < (1 << 7); j++) {         dp[i][j][0][0] = 0;         dp[i][j][0][1] = 1;         for (int k = 0; k < 7; k++) {           dp[i][j][k + 1][0] = dp[i][j][k][0] + dp[i][j][k][1];           dp[i][j][k + 1][1] = dp[i][j][k][0];           if (!(((i >> k) & 1) && ((j >> k) & 1)))             dp[i][j][k + 1][1] += dp[i][j][k][1];         }       }     int last = 0;     for (int i = 1; i <= 7; i++) {       scanf( %d , W + i);       if (W[i]) last = i;     }     matrix pre, base, tmp;     int psz = -1;     for (int i = 1; i <= last; i++)       if (W[i]) {         base.sz = 1 << i;         if (psz == -1) {           for (int j = 0; j < (1 << i); j++) base.data[j][0] = 0;           base.data[(1 << i) - 1][0] = 1;         } else {           for (int j = 0; j < (1 << i); j++) {             if ((j >> psz) == (1 << (i - psz)) - 1)               base.data[j][0] = pre.data[j & ((1 << psz) - 1)][0];             else               base.data[j][0] = 0;           }         }         tmp = pow(transition_matrix(i), W[i]);         pre = multiply(tmp, base);         psz = i;       }     printf( %d n , pre.data[(1 << last) - 1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 303;   const int MOD = 1e9 + 7;   long long ncr[MAX][MAX];   map<int, int> cnt;   int tot[MAX];   long long dp[MAX][MAX];   vector<int> fin;   int get(int a) {     int ans = 1;     for (int i = 2; (i * i) <= a; i++) {       int k = 0;       while ((a % i) == 0) {         a /= i;         k ^= 1;       }       if (k) {         ans *= i;       }     }     ans *= a;     return ans;   }   int main() {     for (int i = 0; i < MAX; i++) {       ncr[i][0] = 1;       for (int j = 1; j <= i; j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % MOD;       }     }     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       cnt[get(a)]++;     }     for (auto x : cnt) {       fin.push_back(x.second);     }     sort(fin.begin(), fin.end());     reverse(fin.begin(), fin.end());     int m = fin.size();     for (int i = 1; i <= m; i++) {       tot[i] = tot[i - 1] + fin[i - 1];     }     dp[1][fin[0] - 1] = 1;     for (int i = 2; i <= m; i++) {       int slots = tot[i - 1] + 1;       for (int j = 0; j <= n; j++) {         if (!dp[i - 1][j]) {           continue;         }         for (int k = 1; k <= min(slots, fin[i - 1]); k++) {           for (int l = 0; l <= min(j, k); l++) {             dp[i][fin[i - 1] - k + j - l] +=                 (((((dp[i - 1][j] * ncr[j][l]) % MOD) *                    ncr[fin[i - 1] - 1][k - 1]) %                   MOD) *                  ncr[slots - j][k - l]) %                 MOD;             dp[i][fin[i - 1] - k + j - l] %= MOD;           }         }       }     }     long long ans = dp[m][0];     for (int i = 0; i < m; i++) {       for (int j = 1; j <= fin[i]; j++) {         ans = (ans * j) % MOD;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, MAX = 1e5 + 5;   long long powN(long long a, long long p) {     if (p == 0) return 1;     long long z = powN(a, p / 2);     z = (z * z) % MOD;     if (p % 2) z = (z * a) % MOD;     return z;   }   vector<bool> is_prime(MAX + 1, true);   void Sieve() {     is_prime[0] = is_prime[1] = false;     int i, j;     for (i = 2; i * i <= MAX; i++) {       if (is_prime[i]) {         for (j = i * i; j <= MAX; j += i) is_prime[j] = false;       }     }   }   int main() {     string s, t;     cin >> s >> t;     int n = s.length();     string s1 = s;     if (s == t)       cout <<  No such string  << endl;     else {       bool ans = false;       bool dec = false;       for (int i = 0; i < n; i++) {         if (dec) {           if (t[i] ==  a ) {             s[i] = t[i];             continue;           }           s[i] = (t[i] - 1);           ans = true;           cout << s << endl;           break;         } else if (t[i] - s[i] > 1) {           ans = true;           s[i] = t[i] - 1;           cout << s << endl;           break;         } else if (t[i] - s[i] == 1) {           s[i]++;           dec = true;         } else           continue;       }       if (!ans) {         dec = false;         for (int i = 0; i < n; i++) {           if (dec) {             if (s1[i] ==  z ) continue;             s1[i]++;             ans = true;             cout << s1 << endl;             break;           } else if (t[i] - s1[i] > 1) {             ans = true;             s1[i] = t[i] - 1;             cout << s1 << endl;             break;           } else if (t[i] - s1[i] == 1) {             dec = true;           } else             continue;         }       }       if (!ans) cout <<  No such string  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFLL = 1e18 + 7;   const long double EPS = 1e-9;   const int MAXN = 1e5 + 17;   mt19937 myRand(1337);   mt19937_64 myRand64(1337);   signed main(void) {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int k;     cin >> k;     int len = k / (int)1e6 + (k % (int)1e6 != 0) + 2;     int r = k + len;     vector<int> ans = {-1};     int m = r / (int)1e6;     r = r - (r / (int)1e6) * 1e6;     ans.push_back(r);     for (int i = 0; i < m; ++i) {       ans.push_back((int)1e6);     }     for (int i = 0; i < len - (int)ans.size(); ++i) ans.push_back(0);     cout << (int)ans.size() << endl;     for (int i : ans) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, cnt, r[1010];   pair<int, int> c[1010];   bool check[1010];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c[i].second >> c[i].first;       if (c[i].second > c[i].first) swap(c[i].second, c[i].first);     }     sort(c, c + n);     while (1) {       int i = 0;       for (i = 0; i < n; i++)         if (!check[i]) break;       if (i == n) break;       r[cnt] = c[i].first;       for (i = 0; i < n; i++)         if (c[i].first >= r[cnt] && c[i].second <= r[cnt]) check[i] = true;       cnt++;     }     cout << cnt << endl;     for (int i = 0; i < cnt; i++) cout << r[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, u, v, vk = 0, vv = 0;   long long res = 0, se = 0;   int visited[1000000], selfE[1000000];   vector<vector<int> > G(1000000, vector<int>());   void dfs(int i) {     if (visited[i]) return;     visited[i] = 1;     vk++;     for (int u : G[i]) {       dfs(u);     }   }   void solve() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &u, &v);       if (u == v) {         selfE[v - 1] += 1;         se++;       } else {         G[u - 1].push_back(v - 1);         G[v - 1].push_back(u - 1);       }     }     for (int i = 0; i < n; i++) {       long long l = G[i].size();       res += l * (l - 1) / 2;     }     res += se * (se - 1) / 2;     res += se * (m - se);     memset(visited, 0, sizeof visited);     for (int i = 0; i < n; i++) {       if (G[i].size()) {         dfs(i);         break;       }     }     for (int i = 0; i < n; i++)       if (G[i].size() || selfE[i]) vv++;     if (vk == vv)       cout << res << endl;     else       cout << 0 << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double p[1001];   double getp(unsigned long long a, unsigned long long b) {     unsigned long long st = 1, ed = 1;     double ret;     while (st < a) st = st * 10;     while (ed < b) ed = ed * 10;     if (ed > b) ed = ed / 10;     if (st > a) st = st / 10;     if (ed + ed - 1 < a) return 0;     if ((ed + ed - 1) <= b) {       ret = st * (pow(10, log10(ed / st) + 1) - 1) / 9;     } else       ret = st * (pow(10, log10(ed / st)) - 1) / 9 + (b - ed + 1);     if (st + st - 1 >= a) ret = ret - (a - st);     if (st + st - 1 < a) ret = ret - (st);     return (double)ret / (b - a + 1);   }   double memo[1001][1001];   double dp(int i, int j) {     if (j < 0 || i < 0) return 0;     if (memo[i][j] != -1) return memo[i][j];     if (i == 0 && j == 0) {       memo[i][j] = 1;       return 1;     }     double ret = p[i - 1] * dp(i - 1, j - 1) + (1 - p[i - 1]) * dp(i - 1, j);     memo[i][j] = ret;     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         memo[i][j] = -1;       }     }     unsigned long long a, b;     int i = 0;     int t = n;     while (t--) {       cin >> a >> b;       p[i++] = getp(a, b);     }     for (int j = 0; j <= n; j++) {       if (memo[n][j] == -1) dp(n, j);     }     double k;     cin >> k;     k = ceil(k * n / 100);     double sum = 0;     for (int j = 0; j <= n; j++) {       if (j >= k) sum = sum + memo[n][j];     }     printf( %.15f , sum);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline void init() {     ios::sync_with_stdio(false);     cin.tie(0);   }   const int N = 100005;   vector<int> adj[N];   bool reach[N][2];   int prv[N][2];   void dfs(int u, int k) {     reach[u][k] = true;     for (int v : adj[u]) {       if (!reach[v][k ^ 1]) {         prv[v][k ^ 1] = u;         dfs(v, k ^ 1);       }     }   }   int vis[N];   bool detectCycle(int u) {     vis[u] = 1;     for (int v : adj[u]) {       if (vis[v] == 1) return true;       if (vis[v] == 0 && detectCycle(v)) return true;     }     vis[u] = 2;     return false;   }   int main() {     init();     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       while (x--) {         int j;         cin >> j;         adj[i].push_back(j);       }     }     int s;     cin >> s;     dfs(s, 0);     bool win = false;     for (int i = 1; i <= n; i++) {       if (reach[i][1] && (int)adj[i].size() == 0) {         win = true;         cout <<  Win n ;         int p = 1;         vector<int> res;         while (prv[i][p] != 0) {           res.push_back(i);           i = prv[i][p];           p ^= 1;         }         res.push_back(s);         reverse(res.begin(), res.end());         for (int r : res) cout << r <<    ;         cout <<   n ;         break;       }     }     if (!win) {       if (detectCycle(s)) {         cout <<  Draw n ;       } else {         cout <<  Lose n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   vector<long long int> v[2];   const long long int N = 3e5 + 5;   long long int x[N];   char ch[N];   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int n;     cin >> n;     long long int idx = 0;     long long int ans = 0;     long long int min1 = 1e12, max1 = 0, min2 = 1e12, max2 = 0;     for (long long int i = 1; i <= n; i++) {       cin >> x[i] >> ch[i];       if (ch[i] ==  G ) {         idx = i;       }       if (ch[i] ==  R ) {         min1 = min(min1, x[i]);         max1 = max(max1, x[i]);       }       if (ch[i] ==  B ) {         min2 = min(min2, x[i]);         max2 = max(max2, x[i]);       }     }     if (!idx) {       long long int ans = 0;       if (max2 >= min2) ans += max2 - min2;       if (max1 >= min1) ans += max1 - min1;       cout << ans;       return 0;     }     idx = 0;     for (long long int i = 1; i <= n; i++) {       if (ch[i] ==  G ) {         if (idx) {           v[0].clear();           v[1].clear();           long long int tot = x[i] - x[idx];           for (long long int j = idx; j <= i; j++) {             if (ch[j] ==  R  || ch[j] ==  G ) v[0].push_back(x[j]);             if (ch[j] ==  B  || ch[j] ==  G ) v[1].push_back(x[j]);           }           long long int sz = v[0].size();           long long int max1 = 0, max2 = 0;           for (long long int j = 0; j <= sz - 2; j++) {             max1 = max(max1, v[0][j + 1] - v[0][j]);           }           sz = v[1].size();           for (long long int j = 0; j <= sz - 2; j++) {             max2 = max(max2, v[1][j + 1] - v[1][j]);           }           tot += 2 * (x[i] - x[idx]) - max1 - max2;           tot = min(tot, 2 * (x[i] - x[idx]));           ans += tot;         } else {           for (long long int j = 1; j <= i - 1; j++) {             if (ch[j] ==  B ) {               ans += x[i] - x[j];               break;             }           }           for (long long int j = 1; j <= i - 1; j++) {             if (ch[j] ==  R ) {               ans += x[i] - x[j];               break;             }           }         }         idx = i;       }     }     for (long long int j = n; j > idx; j--) {       if (ch[j] ==  R ) {         ans += x[j] - x[idx];         break;       }     }     for (long long int j = n; j > idx; j--) {       if (ch[j] ==  B ) {         ans += x[j] - x[idx];         break;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   namespace FASTIO {   char buf[1 << 21];   char *p1, *p2;   template <typename T>   inline void wt(T x, char c =   n ) {     if (x < 0) {       x = -x;       putchar( - );     }     static char sta[sizeof(T) * 8];     T top = 0;     do {       sta[top++] = x % 10;       x /= 10;     } while (x);     while (top) putchar(sta[--top] +  0 );     putchar(c);   }   template <typename T>   inline T rd() {     T sum = 0, fl = 1;     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     for (; ch <  0  || ch >  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       if (ch ==  - )         fl = -1;       else if (ch == EOF)         exit(0);     for (;  0  <= ch && ch <=  9 ;          ch = (p1 == p2 &&                        (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                    ? EOF                    : *p1++))       sum = sum * 10 + ch -  0 ;     return sum * fl;   }   }  // namespace FASTIO   using namespace FASTIO;   int n, m;   int k;   int len;   std::vector<int> a;   struct node {     node *son[2];     int cnt;     node() {       son[0] = NULL;       son[1] = NULL;       cnt = 0;     }     ~node() {       delete son[0];       delete son[1];     }   } root;   inline void insert(int x) {     node *p = &root;     for (int i = len; i >= 0; i--) {       p->cnt++;       const bool $ = (x & 1 << i) != 0;       if (!p->son[$]) p->son[$] = new node();       p = p->son[$];     }     p->cnt++;     return;   }   inline int query() {     const node *p = &root;     int ans = 0;     for (int i = len; p && i >= 0; i--) {       const bool $ = (k & 1 << i) != 0;       if (!p->son[$] || p->son[$]->cnt < 1 << i)         p = p->son[$];       else {         p = p->son[!$];         ans |= 1 << i;       }     }     return ans;   }   int main() {     n = rd<int>();     m = rd<int>();     a.resize(n);     for (int &ele : a) ele = rd<int>();     std::sort(a.begin(), a.end());     a.erase(std::unique(a.begin(), a.end()), a.end());     len = a.back();     len = len ? log2(len) + 2 : 2;     for (const int &A : a) insert(A);     while (m--) {       k ^= rd<int>();       wt(query());     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int N, A, B, C;     char Error = 0;     scanf( %d , &N);     while (N) {       A = N % 10;       B = N % 100;       C = N % 1000;       if (A == 1) {         N /= 10;       } else if (B == 14) {         N /= 100;       } else if (C == 144) {         N /= 1000;       } else {         Error = 1;         break;       }     }     puts(Error ?  NO  :  YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   const int M = 1e9 + 7;   int n;   vector<int> d;   vector<pair<int, int> > construct(int cur, vector<int> d) {     if (((int)d.size()) == 0) return vector<pair<int, int> >();     vector<pair<int, int> > tmp;     for (int i = 0; i < (d[0]); i++) {       for (int j = cur + i + 1; j <= cur + d.back(); j++)         tmp.push_back(make_pair(cur + i, j));     }     cur += d[0];     for (int i = 1; i < ((int)d.size()); i++) d[i] -= d[0];     d.erase(d.begin());     if (((int)d.size())) d.pop_back();     auto t = construct(cur, d);     for (auto x : t) tmp.push_back(x);     return tmp;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     d.resize(n);     for (int i = 0; i < (n); i++) cin >> d[i];     auto ans = construct(0, d);     cout << ((int)ans.size()) << endl;     for (auto x : ans) cout << x.first + 1 <<     << x.second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[110], s[110][110];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 1; j <= a[i]; j++) s[i][j % m + 1]++;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= m; k++)           if (abs(s[i][k] - s[j][k]) > 1) {             printf( NO n );             return 0;           }     printf( YES n );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= a[i]; j++) printf( %d  , j % m + 1);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   char s[maxn];   int un[maxn], ln[maxn];   int main() {     int i, j, k;     int ans = INT_MAX, tmp;     scanf( %s , s + 1);     un[0] = ln[0] = 0;     for (i = 1; s[i]; ++i) {       if (islower(s[i])) {         ln[i] = ln[i - 1] + 1;         un[i] = un[i - 1];       } else {         ln[i] = ln[i - 1];         un[i] = un[i - 1] + 1;       }     }     int len = i - 1;     for (i = 1; i <= len; ++i) {       tmp = ln[i - 1] + un[len] - un[i];       ans = min(ans, tmp);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int sg[100010], f[100010], pre[100010];   int used[100010];   int n;   int cal(int n) {     for (int m = 2;; m++) {       int tot = m * (m - 1) / 2;       if (tot > n) break;       tot = n - tot;       if (tot % m) continue;       int s = tot / m;       int t = s + m - 1;       int v = sg[t] ^ sg[s - 1];       used[v] = n;       if (v == 0 && pre[n] == 0) pre[n] = m;     }     int ret = 0;     for (; used[ret] == n; ret++)       ;     return ret;   }   int main() {     int i, j, k;     scanf( %d , &n);     for (i = 3; i <= n; i++) {       f[i] = cal(i);       sg[i] = sg[i - 1] ^ f[i];     }     if (f[n])       printf( %d n , pre[n]);     else       puts( -1 );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     if (v.size() == 0) {       os <<  empty vector n ;       return os;     }     for (auto element : v) os << element <<    ;     return os;   }   template <typename T, typename second>   ostream& operator<<(ostream& os, pair<T, second>& p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, set<T>& v) {     if (v.size() == 0) {       os <<  empty set n ;       return os;     }     auto endit = v.end();     endit--;     os <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       os << *it;       if (it != endit) os <<  ,  ;     }     os <<  ] ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, multiset<T>& v) {     if (v.size() == 0) {       os <<  empty multiset n ;       return os;     }     auto endit = v.end();     endit--;     os <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       os << *it;       if (it != endit) os <<  ,  ;     }     os <<  ] ;     return os;   }   template <typename T, typename second>   ostream& operator<<(ostream& os, map<T, second>& v) {     if (v.size() == 0) {       os <<  empty map n ;       return os;     }     auto endit = v.end();     endit--;     os <<  { ;     for (auto it = v.begin(); it != v.end(); it++) {       os <<  (  << (*it).first <<   :   << (*it).second <<  ) ;       if (it != endit) os <<  ,  ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<vector<T>>& v) {     for (auto& subv : v) {       for (auto& e : subv) os << e <<    ;       os <<   n ;     }     return os;   }   bool do_debug = false;   void Runtime_Terror() {     long long n, k, tem;     cin >> n >> k >> tem;     long long x = tem;     vector<string> v;     string s;     cin >> s;     vector<long long> pos, maxi;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  * ) {         long long cnt = 0;         pos.push_back(i);         while (i < s.size() && s[i] ==  * ) {           cnt++;           i++;         }         maxi.push_back(cnt * k + 1);       }     }     if (maxi.size() == 0) {       cout << s <<   n ;       return;     };     ;     vector<long long> ans(pos.size());     vector<long long> pro(maxi.size());     pro[pro.size() - 1] = maxi.back();     long long sz = maxi.size();     for (long long i = sz - 2; i >= 0; i--) {       if (pro[i + 1] == -1) {         pro[i] = -1;         continue;       }       long double cal = (LLONG_MAX - 1e8) / (maxi[i] * 1.0);       if (pro[i + 1] > (long long)(cal)) {         pro[i] = -1;         continue;       }       pro[i] = pro[i + 1] * maxi[i];     }     for (long long i = 0; i < maxi.size() - 1; i++) {       if (pro[i + 1] == -1) {         ans[i] = 1;         continue;       }       long long small = pro[i + 1];       for (long long j = 0; j < maxi[i] + 1; j++) {         if (small >= x) {           ans[i] = j + 1;           break;         }         small += pro[i + 1];       }       x -= (ans[i] - 1) * (pro[i + 1]);     }     ans[ans.size() - 1] = x;     ;     long long in = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] !=  * )         cout << s[i];       else {         for (long long j = 0; j < ans[in] - 1; j++) cout <<  b ;         in++;         while (i < s.size() && s[i] ==  * ) i++;         i--;       }     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     for (long long i = 0; i < t; i++) Runtime_Terror();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long exetended_euclid(long long a, long long b, long long &x,                              long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long m = exetended_euclid(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return m;   }   void solve() {     long long n, m;     cin >> n >> m;     if (n > 1 && m == 0) {       cout <<  No solution n ;     } else {       string s =   ;       s += to_string(m);       n--;       while (n--) {         s +=  0 ;       }       cout << s <<   n ;     }   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     long n(0);     scanf( %ld , &n);     long currentDiv = 2, total = 1;     while (n > 1) {       if (currentDiv * currentDiv > n) {         total += n;         break;       } else if (n % currentDiv == 0) {         total += n;         n /= currentDiv;       } else {         ++currentDiv;       }     }     printf( %ld n , total);     return 0;   }


#include<iostream>   #include<iomanip>   #include<queue>   #include<stack>   #include<numeric>   #include<cstring>   #include<vector>   #include<algorithm>   #include<set>   #include<map>   #include<unordered_map>   #include<unordered_set>   #include<climits>   #include<cmath>      using namespace std;   #define int long long   #define pp pair<int,int>   #define ppl pair<ll,ll>    #define mod 1000000007      int32_t main()   {    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);        int t;    cin>>t;       while(t--)    {     int num;     cin >> num;        if ((num % 111) == 0)      cout <<  YES n ;        else     {      while (num > 0)      {       if ((num % 11) == 0)        break;          num -= 111;      }         if (num >= 0)       cout <<  YES n ;         else       cout <<  NO n ;     }    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e4 + 5;   map<int, int> mp[N];   int arr[N];   int main() {     int n, m, a, b;     cin >> n >> m;     while (m--) {       cin >> a >> b;       mp[a][b]++;     }     arr[1] = 1;     for (int i = 2; i <= n; i++) {       int j = i;       arr[j] = j;       while (j > 1 && mp[arr[j - 1]][arr[j]] == 1) {         swap(arr[j], arr[j - 1]);         j--;       }     }     for (int i = 1; i <= n; i++) {       cout << arr[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   struct node {     int i, j, bal;     char scoba;     node() {}     node(long long _i, long long _j, long long _k, char _scoba)         : i(_i), j(_j), bal(_k), scoba(_scoba) {}   };   node p[210][210][410];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s >> t;     long long n = s.size(), m = t.size();     vector<vector<vector<long long> > > dp(         n + 1, vector<vector<long long> >(m + 1, vector<long long>(410, inf)));     dp[0][0][0] = 0;     for (long long i = 0; i <= n; ++i) {       for (long long j = 0; j <= m; ++j) {         for (long long k = 0; k <= 410; ++k) {           if (dp[i][j][k] == inf) continue;           long long nxti = i + (i < n && s[i] ==  ( ),                     nxtj = j + (j < m && t[j] ==  ( );           if (k + 1 < 410 && dp[nxti][nxtj][k + 1] > dp[i][j][k] + 1) {             dp[nxti][nxtj][k + 1] = dp[i][j][k] + 1;             p[nxti][nxtj][k + 1] = node(i, j, k,  ( );           }           nxti = i + (i < n && s[i] ==  ) ), nxtj = j + (j < m && t[j] ==  ) );           if (k > 0 && dp[nxti][nxtj][k - 1] > dp[i][j][k] + 1) {             dp[nxti][nxtj][k - 1] = dp[i][j][k] + 1;             p[nxti][nxtj][k - 1] = node(i, j, k,  ) );           }         }       }     }     long long curi = n, curj = m, cur_balance = 0;     for (long long i = 0; i < 410; ++i) {       if (dp[n][m][cur_balance] + cur_balance > dp[n][m][i] + i &&           dp[n][m][i] != inf) {         cur_balance = i;       }     }     string ans =   ;     long long temp = cur_balance;     while (curi > 0 || curj > 0 || cur_balance) {       node a = p[curi][curj][cur_balance];       long long ni = a.i;       long long nj = a.j;       long long nbal = a.bal;       ans += a.scoba;       curi = a.i;       curj = a.j;       cur_balance = a.bal;     }     while (temp--) ans =  )  + ans;     reverse(ans.begin(), ans.end());     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, z, f[1000000], k, ans = 0, a, b, c, t;   vector<long long> v;   map<long long, long long> m;   int main() {     cin >> n >> a >> b >> c >> t;     for (int i = 0; i < n; i++) cin >> f[i];     sort(f, f + n);     for (int i = 0; i < n; i++) {       x = a;       k = (t - f[i]) * c;       k -= (t - f[i]) * b;       k += a;       x = max(x, k);       ans += x;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int size = 60;   const int ssize = 20;   const int lsize = 20 * 1000;   char field[size][size];   int n, m;   int cnt[1 << ssize];   double ans[1 << ssize];   int clr[size][size];   int hmas[lsize];   int bc(int msk) {     int c = 0;     while (msk > 0) {       c += msk & 1;       msk /= 2;     }     return c;   }   int h[size];   int ch[size];   void rec(int ps, int msk) {     if (ps == m) {       cnt[msk] = 0;       for (int i = 0; i < n; i++) ch[i] = 0;       for (int i = 0; i < n; i++) {         if (ch[clr[ps][i]] > 0) {           cnt[msk]++;         }         ch[clr[ps][i]]++;         if (ch[clr[ps][i]] == 2) cnt[msk]++;       }       return;     }     for (int i = 0; i < n; i++) clr[ps + 1][i] = clr[ps][i];     rec(ps + 1, msk);     for (int i = 0; i < n; i++) {       clr[ps + 1][i] = clr[ps][i] * 200 + (int)field[i][ps];       hmas[clr[ps + 1][i]] = -1;     }     int cc = 0;     for (int i = 0; i < n; i++) {       if (hmas[clr[ps + 1][i]] == -1) {         hmas[clr[ps + 1][i]] = cc++;       }       clr[ps + 1][i] = hmas[clr[ps + 1][i]];     }     rec(ps + 1, msk | (1 << ps));   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , field[i]);     }     m = strlen(field[0]);     for (int i = 0; i < n; i++) clr[0][i] = 0;     rec(0, 0);     for (int i = (1 << m) - 1; i >= 0; i--) {       if (cnt[i] == 0)         ans[i] = 0.0;       else {         ans[i] = 0.0;         double p = 1.0 / (m - bc(i));         for (int j = 0; j < m; j++)           if (!((i >> j) & 1)) {             int tg = i | (1 << j);             double g = (cnt[i] - cnt[tg] + 0.0) / cnt[i];             ans[i] += p * (g + (1 - g) * (ans[tg] + 1));           }       }     }     cout.precision(20);     cout << ans[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long conv(char c) { return c -  a ; }   vector<long long> get_sa(const char *s, long long n) {     vector<long long> sa(n);     long long m = 26;     vector<long long> cnt(max(n, m)), x(n), y(n);     for (long long i = 0; i < (long long)(n); ++i) cnt[x[i] = conv(s[i])]++;     for (long long i = 0; i < (long long)(m - 1); ++i) cnt[i + 1] += cnt[i];     for (long long i = n - 1; i >= 0; --i) sa[--cnt[x[i]]] = i;     for (long long len = 1, p = 0; p + 1 < n; len <<= 1, m = p + 1) {       p = 0;       for (long long i = n - len; i < n; ++i) y[p++] = i;       for (long long i = 0; i < (long long)(n); ++i)         if (sa[i] >= len) y[p++] = sa[i] - len;       for (long long i = 0; i < (long long)(m); ++i) cnt[i] = 0;       for (long long i = 0; i < (long long)(n); ++i) cnt[x[i]]++;       for (long long i = 0; i < (long long)(m - 1); ++i) cnt[i + 1] += cnt[i];       for (long long i = n - 1; i >= 0; --i) sa[--cnt[x[y[i]]]] = y[i];       y = x;       p = 0;       x[sa[0]] = 0;       for (long long i = 0; i < (long long)(n - 1); ++i)         x[sa[i + 1]] = sa[i] + len < n && sa[i + 1] + len < n &&                                y[sa[i]] == y[sa[i + 1]] &&                                y[sa[i] + len] == y[sa[i + 1] + len]                            ? p                            : ++p;     }     return sa;   }   vector<long long> get_lcp(const char *s, long long n, vector<long long> &sa) {     vector<long long> lcp(n), rank(n);     for (long long i = 0; i < (long long)(n); ++i) rank[sa[i]] = i;     long long k = 0, j;     for (long long i = 0; i < n; lcp[rank[i++]] = k) {       if (rank[i] - 1 >= 0)         for (k ? k-- : 0, j = sa[rank[i] - 1]; s[i + k] == s[j + k]; ++k)           ;     }     return lcp;   }   char S[5050];   long long dp[5050];   void solve() {     memset(dp, 0, sizeof dp);     long long n;     cin >> n;     cin >> S;     vector<long long> sa = get_sa(S, n);     vector<long long> lcp = get_lcp(S, n, sa);     for (long long i = 0; i < n; ++i) {       dp[i] = n - sa[i];       long long commonbaby = 1e9;       for (long long j = i - 1; j >= 0; --j) {         commonbaby = min(commonbaby, lcp[j + 1]);         if (sa[j] < sa[i]) {           dp[i] = max(dp[i], dp[j] + n - sa[i] - commonbaby);         }       }     }     cout << *max_element(dp, dp + n) <<   n ;   }   signed main(void) {     cin.tie(0)->sync_with_stdio(false);     long long T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 69;   const int MOD = 1000000007;   void solve() {     int r, c;     cin >> r >> c;     char grid[MAX][MAX];     int rows[r], cols[c], aCount = 0;     for (int i = 0; i < r; i++) {       rows[i] = 0;     }     for (int i = 0; i < c; i++) {       cols[i] = 0;     }     char q;     bool two = false;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         cin >> q;         if (q ==  A ) {           rows[i]++;           cols[j]++;           aCount++;         }         if (((i == 0 || i == r - 1) && (j == 0 || j == c - 1)) && q ==  A ) {           two = true;         }         grid[i][j] = q;       }     }     int rMax = -1, cMax = -1;     for (int i = 0; i < r; i++) {       rMax = max(rMax, rows[i]);     }     for (int i = 0; i < c; i++) {       cMax = max(cMax, cols[i]);     }     if (aCount == 0) {       cout <<  MORTAL ;     } else if (aCount == r * c) {       cout << 0;     } else if (rows[0] == c || cols[0] == r || rows[r - 1] == c ||                cols[c - 1] == r) {       cout << 1;     } else if (two || rMax == c || cMax == r) {       cout << 2;     } else if (rows[0] || cols[0] || rows[r - 1] || cols[c - 1]) {       cout << 3;     } else {       cout << 4;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tt;     cin >> tt;     for (int i = 1; i <= tt; i++) {       solve();       cout << endl;     }   }


#include <bits/stdc++.h>   const int maxn = 60;   int mtx[maxn][maxn];   int n, m;   bool col_ok(int a, int b) {     for (int i = 0; i < n; i++) {       if (mtx[i][a] != mtx[i][b]) return 0;     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf(  %c , &mtx[i][j]);     for (int i = 0; i < n; i++) {       int cmp = -1;       for (int j = 0; j < m; j++) {         if (mtx[i][j] ==  # ) {           if (cmp == -1) {             cmp = j;           } else {             if (!col_ok(cmp, j)) {               printf( No n );               return 0;             }           }         }       }     }     printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     string x;     cin >> x;     string y = x;     for (int i = 0; i < x.length(); i++) {       if (x[i] ==  a ) continue;       for (int j = i; j < x.length(); j++) {         if (x[j] ==  a ) break;         x[j] = char(int(x[j]) - 1);       }       break;     }     if (y == x) {       x[x.length() - 1] =  z ;     }     cout << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], ans = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int j;       for (j = 0;; j++)         if (i + (1 << j) > n) break;       j--;       ans += a[i];       a[i + (1 << j)] += a[i];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long a[maxn], dp[maxn], sum[maxn];   int main() {     int n, c;     scanf( %d%d , &n, &c);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     multiset<long long> st;     for (int i = 1; i <= n; i++) dp[i] = 1e16;     for (int i = 1; i <= n; i++) {       st.insert(a[i]);       dp[i] = min(dp[i], dp[i - 1] + a[i]);       if (i >= c) {         dp[i] = min(dp[i], dp[i - c] + sum[i] - sum[i - c] - *(st.begin()));         st.erase(st.find(a[i - c + 1]));       }     }     printf( %lld n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const double PI = acos(-1);   vector<double> vec;   double getAngle(double x, double y) {     if (x == 0) {       if (y > 0) return 90;       return 270;     }     if (y == 0) {       if (x > 0) return 0;       return 180;     }     double angle = 0;     if (x > 0) {       if (y > 0)         angle = atan(y / x);       else         angle = 2 * PI - atan((-1.0 * y) / x);     } else {       if (y > 0)         angle = PI - atan(y / (-1.0 * x));       else         angle = PI + atan((-1.0 * y) / (-1.0 * x));     }     return (angle * 180.0) / PI;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       double x, y;       cin >> x >> y;       vec.push_back(getAngle(x, y));     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     sort(vec.begin(), vec.end());     double gap = 0;     for (int i = 0; i < n - 1; i++) {       gap = max(gap, vec[i + 1] - vec[i]);     }     gap = max(gap, 360.0 - vec[n - 1] + vec[0]);     double ans = 360.0 - gap;     printf( %0.9f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a = 0, b = 0;     bool gr = 0;     cout <<  ?   << 0 <<     << 0 << endl;     fflush(stdout);     int g;     cin >> g;     if (g == 1)       gr = 1;     else       gr = 0;     for (int i = 29; i >= 0; i--) {       cout <<  ?   << (a + (1 << i)) <<     << b << endl;       fflush(stdout);       int a1, a2;       cin >> a1;       cout <<  ?   << a <<     << (b + (1 << i)) << endl;       fflush(stdout);       cin >> a2;       if (a1 == a2) {         if (gr) {           a += (1 << i);           if (a1 == 1)             gr = 1;           else             gr = 0;         } else {           b += (1 << i);           if (a1 == 1)             gr = 1;           else             gr = 0;         }       }       if (a1 != a2) {         if (a1 == -1) {           a += (1 << i);           b += (1 << i);         }       }     }     cout <<  !   << a <<     << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cout << 1 <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout << setprecision(32);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, a[1005], b[1005], Id[1005];   int ans, ans1, ans2;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];       Id[b[i]] = i;     }     sort(a + 1, a + n + 1);     i = 1;     while (i <= n) {       if (a[i] != b[i]) {         m = Id[a[i]];         for (int j = i + 1; j <= m; j++)           if (b[j] != b[j - 1] - 1) {             printf( 0 0 n );             return 0;           }         ans++;         ans1 = i;         ans2 = m;         i = m;       }       i++;     }     if (ans != 1)       printf( 0 0 n );     else       printf( %d %d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A, B, N;   long long l, t, m;   int main() {     cin >> A >> B >> N;     for (int i = 0; i < N; i++) {       cin >> l >> t >> m;       if (t < A + (l - 1) * B) {         cout << -1 << endl;       } else {         long long left = l, right = (t - A) / B + 1;         while (left <= right) {           long long mid = (left + right) / 2;           long long sum = (mid - l + 1) * (2 * A + B * (mid + l) - 2 * B) / 2;           if (sum <= m * t) {             left = mid + 1;           } else {             right = mid - 1;           }         }         cout << right << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int n;   long long a[200010];   int ans_check[200010];   int main() {     int i, j, k;     scanf( %d , &t);     while (t--) {       int check = 0;       int cnt = 1;       memset(ans_check, 0, sizeof(ans_check));       scanf( %d , &n);       for (i = 1; i <= n; i++) {         scanf( %64d , &a[i]);       }       sort(a + 1, a + n + 1);       long long ans_uncheck = a[1] * a[n];       for (i = 1; i <= n; i++)         if (a[i] * a[n - i + 1] != ans_uncheck || a[i] == ans_uncheck ||             a[n - i + 1] == ans_uncheck) {           printf( -1 n );           check = 1;           break;         }       if (check == 1) continue;       long long che = 2;       int ch = 0;       long long tmpp = ans_uncheck;       while (ans_uncheck > 1) {         if (ans_uncheck % che == 0) {           if (ch == 1) cnt++;           ans_uncheck /= che;           ch = 0;           ans_check[cnt]++;         } else {           che++;           ch = 1;         }       }       long long check2 = 1;       for (i = 1; i <= cnt; i++) check2 *= (ans_check[i] + 1);       if (cnt == 1) {         if (n != ans_check[1] - 1) {           printf( -1 n );           check = 1;         }       } else if (check2 != n + 2) {         printf( -1 n );         check = 1;       }       if (check == 1) continue;       cout << tmpp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int main() {     long long n, i, j, t;     vector<long long> a;     vector<long long> b;     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       a.push_back(j);       b.push_back(j);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     i = 0;     j = 1;     long long counter = 0;     while (j < n) {       if (b[i] < a[j]) {         t = a[i];         a[i] = a[j];         a[j] = t;         i++;         counter++;       }       j++;     }     cout << counter << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1000000007;   long long b(long long a, long long n, long long mod) {     if (n == 0) {       return 1;     }     if (n == 1) {       return a % mod;     }     long long t = b(a, n / 2, mod);     t *= t;     t %= mod;     if (n % 2) {       t *= a;     }     t %= mod;     return t;   }   int main() {     long long n, m;     cin >> n >> m;     cout << (b(3, n, m) - 1 + m) % m;     return 0;   }


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


#include <bits/stdc++.h>   int a[200001];   int renew[200001];   int payoff[200001];   int maxpay[200001];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int mode;       scanf( %d , &mode);       if (mode == 1) {         int t1, t2;         scanf( %d %d , &t1, &t2);         a[t1 - 1] = t2;         renew[t1 - 1] = i;       } else {         int t1;         scanf( %d , &t1);         payoff[i] = t1;       }     }     maxpay[q - 1] = payoff[q - 1];     for (int i = q - 2; i >= 0; i--) {       if (payoff[i] > maxpay[i + 1]) {         maxpay[i] = payoff[i];       } else         maxpay[i] = maxpay[i + 1];     }     for (int i = 0; i < n; i++) {       if (maxpay[renew[i]] > a[i]) a[i] = maxpay[renew[i]];     }     for (int i = 0; i < n; i++) {       printf( %d  , a[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.rbegin(), a.rend());     queue<int> x;     for (int i = 0; i < n; ++i) {       x.push(a[i].second);     }     set<int> s;     for (int i = 0; i < n; ++i) s.insert(i);     int r = 0;     vector<int> ans(n, -1);     int t[2 * k + 1];     int ind = 0;     while (!s.empty()) {       while (s.count(x.front()) == 0) x.pop();       ind = 0;       t[ind] = x.front();       ind++;       auto it = s.find(x.front());       if (it != s.begin()) {         it--;         for (int i = 0; i < k; ++i) {           t[ind] = *it;           ind++;           if (it == s.begin()) break;           it--;         }       }       it = s.find(x.front());       if (it != s.end()) {         it++;         for (int i = 0; i < k; ++i) {           if (it == s.end()) break;           t[ind] = *it;           ind++;           it++;         }       }       for (int i = 0; i < ind; ++i) {         s.erase(t[i]);         ans[t[i]] = r;       }       r ^= 1;     }     for (int i : ans) cout << i + 1;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void err(istringstream *iss) {}   template <typename T, typename... Args>   void err(istringstream *iss, const T &$val, const Args &...args) {     string $name;     *iss >> $name;     if ($name.back() ==  , ) $name.pop_back();     cout << $name <<   =   << $val <<  ;  , err(iss, args...);   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   int n, m, K, T, Q, cn;   struct Trie {     static const int maxNode = (1 << 19) * 20, CHARSET = 2;     int end, wordCnt, nxt[maxNode][CHARSET];     char ch[maxNode];     void init() {       memset(nxt, -1, sizeof(nxt));       end = 1, wordCnt = 0;     }     void add(const bool *s, int len) {       int p = 0;       for (int i = 0; i < len; i++) {         int &nxtp = nxt[p][*s];         if (nxtp == -1) {           nxtp = end++;           ch[nxtp] = *s;         }         p = nxtp, s++;       }     }     int lower_bound_lexi_sameLen(const bool *s, int len) {       int ret = 0;       for (int i = 0, p = 0; i < len; i++, s++) {         bool os = nxt[p][*s] == -1 ? !*s : *s;         p = nxt[p][os];         if (os) ret |= 1 << (len - 1 - i);       }       return ret;     }   };   bool s[22];   Trie t;   int a[300005], os, x;   bitset<1 << 20 | 3> vstd;   int main() {     cin.tie(NULL);     t.init();     scanf( %d%d , &n, &Q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]), vstd[a[i]] = 1;     }     for (int i = 0; i < 1 << 19; i++) {       if (vstd[i]) continue;       for (int j = 0; j < 19; j++) {         s[18 - j] = ((i >> j) & 1);       }       t.add(s, 19);     }     while (Q--) {       scanf( %d , &x);       os ^= x;       for (int j = 0; j < 19; j++) {         s[18 - j] = ((os >> j) & 1);       }       printf( %d n , os ^ t.lower_bound_lexi_sameLen(s, 19));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int dx2[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dy2[] = {0, 0, 1, -1, 1, -1, -1, 1};   int read() {     int x;     scanf( %d , &x);     return x;   }   int a[505][505];   int main() {     int x, y;     x = read();     y = read();     int sx = read();     int sy = read();     string s;     cin >> s;     a[sx][sy] = 1;     cout << 1 <<    ;     for (int i = 0; i < s.size() - 1; i++) {       if (s[i] ==  U ) {         int nx = sx - 1 == 0 ? 1 : sx - 1;         int ny = sy;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  D ) {         int nx = sx + 1 == x + 1 ? x : sx + 1;         int ny = sy;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  R ) {         int nx = sx;         int ny = sy + 1 == y + 1 ? y : sy + 1;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  L ) {         int nx = sx;         int ny = sy - 1 == 0 ? 1 : sy - 1;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       }     }     int ans = 0;     for (int i = 1; i <= x; i++) {       for (int j = 1; j <= y; j++) {         if (a[i][j] == 0) ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct hashed_str {     long long n;     vector<long long> hs;     vector<long long> pows;     long long p = 61;     long long mod = 1e9 + 7;     hashed_str(string &s) {       n = s.size();       long long n1 = (int)s.size();       pows = {1};       for (int i = 1; i < n; i++) {         pows.push_back((pows.back() * p) % mod);       }       hs.resize(n1);       hs[0] = (long long)((s[0] -  a ) + 1);       for (int i = 1; i < n1; i++) {         hs[i] =             (hs[i - 1] % mod + (pows[i] * (long long)(s[i] -  a  + 1ll)) % mod) %             mod;       }     }     long long get(long long l, long long r) {       if (l > r) {         return 0;       }       long long a = (l ? hs[l - 1] : 0);       long long b = hs[r];       long long s = (b - a + mod) % mod;       return (s * pows[n - l - 1]) % mod;     }   };   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     string t;     string s;     cin >> s >> t;     long long n = t.size();     hashed_str hs(t);     long long cnt_0 = 0, cnt_1 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         cnt_0++;       } else {         cnt_1++;       }     }     char aa =  0 ;     char bb =  1 ;     long long a = cnt_0;     long long b = cnt_1;     if (s[0] ==  1 ) {       swap(a, b);       swap(aa, bb);     }     if (b == 0) {       if (n % a != 0) {         cout << 0;         return 0;       }       long long len_a = n / a;       long long hash_a = hs.get(0, len_a - 1);       long long hash_b = -1;       long long ptr = len_a;       bool ok = 1;       for (int i = 1; i < s.size(); i++) {         long long cur_h = hs.get(ptr, ptr + len_a - 1);         if (cur_h != hash_a) {           ok = 0;           break;         }         ptr += len_a;       }       cout << ok;       return 0;     }     long long answ = 0;     for (int i = 0; i < t.size(); i++) {       long long len_a = i + 1;       if ((n - len_a * a) % b != 0 || n - len_a * a <= 0) {         continue;       }       long long len_b = (n - len_a * a) / b;       long long hash_a = hs.get(0, len_a - 1);       long long hash_b = -1;       long long ptr = len_a;       bool ok = 1;       for (int j = 1; j < s.size(); j++) {         if (s[j] == aa) {           long long cur_h = hs.get(ptr, ptr + len_a - 1);           if (cur_h != hash_a) {             ok = 0;             break;           }           ptr += len_a;         } else {           long long cur_h = hs.get(ptr, ptr + len_b - 1);           if (hash_b == -1) {             hash_b = cur_h;           }           if (cur_h != hash_b) {             ok = 0;             break;           }           ptr += len_b;         }       }       if (hash_a == hash_b) {         ok = 0;       }       answ += ok;     }     cout << answ;   }


#include <bits/stdc++.h>   using namespace std;   int max(long long int arr[], long long int n) {     int m = INT_MIN;     for (int i = 0; i < n; i++) {       if (arr[i] > m) {         m = arr[i];       }     }     return (m);   }   void display(long long int arr[], long long int n) {     for (int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }   }   int main() {     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int m = max(arr, n);       for (int i = 0; i < n; i++) {         long long int a = m - arr[i];         arr[i] = a;       }       if (k % 2 == 0) {         m = max(arr, n);         for (int i = 0; i < n; i++) {           long long int a = m - arr[i];           arr[i] = a;         }         display(arr, n);       } else {         display(arr, n);       }       cout << endl;     }     return (0);   }


#include <bits/stdc++.h>   typedef struct {     int num;     int val;     int rank;   } data;   int cnum(const void* a, const void* b) {     return ((data*)a)->num - ((data*)b)->num;   }   int cval(const void* a, const void* b) {     return ((data*)b)->val - ((data*)a)->val;   }   int main(void) {     int i, n;     data a[2000];     scanf( %d , &n);     for (i = 0; i < n; i++) {       a[i].num = i;       scanf( %d , &(a[i].val));     }     qsort(a, n, sizeof(data), cval);     a[0].rank = 1;     for (i = 1; i < n; i++) {       if (a[i].val == a[i - 1].val) {         a[i].rank = a[i - 1].rank;       } else {         a[i].rank = i + 1;       }     }     qsort(a, n, sizeof(data), cnum);     for (i = 0; i < n; i++) {       printf( %d  , a[i].rank);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[2 * 110];   int main() {     int n, m, ans = -0x3f3f3f3f;     cin >> n;     m = n;     n *= 2;     n -= 1;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v, v + n);     if (m % 2 == 0) {       for (int x = 0; x <= n - 1; x += 2) {         int k = x, sum = 0;         for (int i = 0; i < n; i++) {           if (k) {             sum += -1 * v[i];             k--;           } else {             sum += v[i];           }         }         ans = max(ans, sum);       }     } else {       for (int x = 0; x <= n; x += 1) {         int k = x, sum = 0;         for (int i = 0; i < n; i++) {           if (k) {             sum += -1 * v[i];             k--;           } else {             sum += v[i];           }         }         ans = max(ans, sum);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > arr;   long long solve1(vector<pair<int, int> > tab) {     multiset<int> S;     int W = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       S.insert(tab[i].second);     }     for (int j = 0; j < n / 2; j++) {       int id = -1;       long long best = 0;       for (int i = 0; i < n; i++) {         multiset<int>::iterator it = S.end();         it--;         long long cur = W * 1LL * (*it);         S.erase(S.find(tab[i].second));         it = S.end();         it--;         long long tmp =             max((*it), tab[i].first) * 1LL * (W - tab[i].first + tab[i].second);         if (cur - tmp > best) {           best = cur - tmp;           id = i;         }         S.insert(tab[i].second);       }       if (id == -1) break;       S.erase(S.find(tab[id].second));       S.insert(tab[id].first);       W = W - tab[id].first + tab[id].second;       swap(tab[id].first, tab[id].second);     }     multiset<int>::iterator it = S.end();     it--;     long long result = W * 1LL * (*it);     return result;   }   long long solve2(vector<pair<int, int> > tab) {     sort(tab.begin(), tab.end(), [](pair<int, int> A, pair<int, int> B) {       return A.first - A.second > B.first - B.second;     });     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     int W = 0;     int H = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       H = max(H, tab[i].second);     }     long long res1 = W * 1LL * H;     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     sort(tab.begin(), tab.end(), [](pair<int, int> A, pair<int, int> B) {       if (A.second == B.second) {         return A.first < B.first;       } else {         return A.second > B.second;       }     });     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     W = 0;     H = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       H = max(H, tab[i].second);     }     long long res2 = W * 1LL * H;     return min(res1, res2);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     arr.resize(n);     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     long long res1 = solve1(arr);     long long res2 = solve2(arr);     cout << min(res1, res2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long a, b, c;     cin >> a >> b >> c;     long long flag = 1;     if (a == b) flag = 0;     cout << c * 2 + min(a, b) * 2 + flag << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, M, K, L;     cin >> N >> M >> K >> L;     long long max = N / M;     long long ans = 1;     bool f1 = true, f2 = true, f3 = true;     if (max < 1) f1 = !f1;     if (max * M - K < L) f3 = !f3;     if (f1 && f2 && f3) {       ans = (L + K) / M + (bool)((L + K) % M);     }     if (f1 && f2 && f3)       cout << ans << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   const int MAXN = 2e6 + 5;   using namespace std;   pair<int, int> arr[MAXN];   bool cmp(const pair<int, int> a, const pair<int, int> b) {     return a.second > b.second;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int q, w;       scanf( %d %d , &q, &w);       arr[i] = {q, w};     }     sort(arr, arr + m, cmp);     int N = (int(sqrt(8 * n - 7)) + 1) >> 1;     long long ans = 0ll;     int tmp = (N * (N - 1)) >> 1;     if ((N & 1) == 0 && tmp + ((N - 1) >> 1) > n - 1) N--;     for (int i = 0; i < min(N, m); i++) ans += (long long)arr[i].second;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m, a, b;       cin >> n >> m >> a >> b;       int total_ones = n * a;       if (total_ones != m * b) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         string str =   ;         for (int i = 0; i < m; i++) {           if (i < a)             str +=  1 ;           else             str +=  0 ;         }         for (int i = 0; i < n; i++) {           cout << str << endl;           for (int j = 0; j < a; j++) {             char c = str[0];             str = str.substr(1);             str = str + c;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   void ASS(bool bb) {     if (!bb) {       ++*(int*)0;     }   }   #pragma comment(linker,  /STACK:106777216 )   int read() {     int x;     scanf( %d , &x);     return x;   }   int main() {     int k, b, n;     k = read();     b = read();     n = read();     map<int, int> mp;     int s = 0;     int zer = 0;     long long res = 0;     for (int i = 0; i < (int)(n); i++) {       ++mp[s];       int x = read();       s = (s + x) % (k - 1);       if (x == 0)         zer++;       else         zer = 0;       if (b == 0)         res += zer;       else {         res += mp[(s + k - 1 - b) % (k - 1)];         if (b == k - 1) res -= zer;       }     }     cout << res << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long OO = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double pi = 3.14159265359;   void skrrrt() { ios_base::sync_with_stdio(0), cin.tie(0); }   const int N = 2009;   int n, d;   long long mem[N][N][2][2];   string a, b;   long long solve(int ind, int sum, int bgra, int smlrb) {     if (ind == a.size()) return (sum == 0);     long long &ret = mem[ind][sum][bgra][smlrb];     if (~ret) return ret;     ret = 0;     for (int i =  0 ; i <=  9 ; i++) {       if ((ind % 2) ^ ((i -  0 ) == d)) continue;       if (!bgra && i < a[ind]) continue;       if (!smlrb && i > b[ind]) continue;       ret = (ret + solve(ind + 1, (sum * 10 + (i -  0 )) % n,                          bgra || (i > a[ind]), smlrb || (i < b[ind]))) %             mod;     }     return ret;   }   int main() {     skrrrt();     cin >> n >> d;     cin >> a >> b;     memset(mem, -1, sizeof mem);     cout << solve(0, 0, 0, 0);   }


#include <bits/stdc++.h>   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   constexpr long long MAX = 5100000;   constexpr long long INF = 1LL << 60;   constexpr int inf = 1 << 28;   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<long long> a(n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     vector<pair<long long, long long>> vp;     for (int i = 0; i < n; i++) {       vp.emplace_back(a[i], 1);       while (vp.size() >= 2) {         auto s = vp.back();         vp.pop_back();         auto f = vp.back();         vp.pop_back();         if (f.second * (f.first + s.first) < f.first * (f.second + s.second)) {           vp.emplace_back(f.first + s.first, f.second + s.second);         } else {           vp.emplace_back(f);           vp.emplace_back(s);           break;         }       }     }     for (int i = 0; i < vp.size(); i++) {       auto p = vp[i];       for (int j = 0; j < p.second; j++) {         printf( %.12f n , (double)p.first / p.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2001], b[2001], n, k, len = 0, ans = 0, res = 0;   void solve() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (a[i] + k <= 5) {         len++;       }     }     ans = (len / 3);     printf( %d , ans);   }   int main() { solve(); }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   map<string, int> mp1[maxn], mp2[maxn];   vector<int> ans;   char getA(string a, string b) {     int c[30];     for (int i = 0; i < 26; i++) c[i] = 0;     for (int i = 0; i < a.size(); i++) c[a[i] -  a ]++;     for (int i = 0; i < b.size(); i++) c[b[i] -  a ]--;     for (int i = 0; i < 26; i++)       if (c[i] > 0) return i +  a ;   }   string solve(int n) {     cout <<  ? 1   << n << endl;     for (int i = 0; i < n * (n + 1) / 2; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       mp1[s.size()][s]++;     }     cout <<  ? 2   << n << endl;     for (int i = 0; i < n * (n - 1) / 2; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       mp2[s.size()][s]++;     }     for (int i = 1; i <= n; i++) {       for (auto p : mp2[i]) mp1[i][p.first] -= mp2[i][p.first];       for (auto p : mp1[i]) {         if (p.second > 0) {           string new1 =   ;           for (int j = 0; j < ans.size(); j++) new1 += ans[j];           ans.push_back(getA(p.first, new1));         }       }     }     string new1 =   ;     for (int j = 0; j < ans.size(); j++) new1 += ans[j];     return new1;   }   int ori[26][105];   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  ? 1 1  << endl;       string s;       cin >> s;       cout <<  !   << s << endl;     } else if (n == 2) {       cout <<  ? 1 1  << endl;       string s1, s2;       cin >> s1;       cout <<  ? 2 2  << endl;       cin >> s2;       cout <<  !   << s1 << s2 << endl;     } else {       string ramjas = solve((n + 1) / 2);       cout <<  ? 1   << n << endl;       for (int i = 0; i < n * (n + 1) / 2; i++) {         string s;         cin >> s;         for (int j = 0; j < s.size(); j++) ori[s[j] -  a ][s.size()]++;       }       string ramjas2 =   ;       for (int i = 1; i <= n / 2; i++) {         for (int j = 0; j < 26; j++) {           int num = ori[j][1] - (ori[j][i + 1] - ori[j][i]);           for (int k = 0; k < i; k++) {             if (ramjas[k] -  a  == j) num--;           }           for (int k = 0; k < ramjas2.size(); k++) {             if (ramjas2[k] -  a  == j) num--;           }           if (num > 0) {             ramjas2 += ( a  + j);             break;           }         }       }       for (int i = 0; i < ramjas2.size(); i++)         ramjas += ramjas2[ramjas2.size() - 1 - i];       cout <<  !   << ramjas << endl;     }   }


#include <bits/stdc++.h>   int main() {     int t;     std::cin >> t;     while (t--) {       std::set<int> all;       int n;       std::cin >> n;       while (n--) {         int tmp;         std::cin >> tmp;         while ((tmp & 1) == 0) {           all.insert(tmp);           tmp >>= 1;         }       }       printf( %d n , (int)all.size());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, q, inc[101];   double a[101], mi = 1000000007LL, ma;   set<vector<int> > S;   set<vector<int> >::iterator it;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> q;     int m = n / k;     for (int i = 0; i < q; i++) {       vector<int> v;       for (int j = 0; j < m; j++) {         int x;         cin >> x;         v.push_back(x);         inc[v[j] - 1] = 1;       }       sort(v.begin(), v.end());       S.insert(v);     }     for (it = S.begin(); it != S.end(); it++) {       vector<int> v = *it;       double s = 0;       for (int i = 0; i < v.size(); i++) s += a[v[i] - 1];       s /= v.size();       mi = min(mi, s);       ma = max(ma, s);     }     vector<double> v;     for (int i = 0; i < n; i++)       if (!inc[i]) v.push_back(a[i]);     if (v.size() >= m && k > S.size()) {       sort(v.begin(), v.end());       double s = 0;       for (int i = 0; i < m; i++) s += v[i];       mi = min(mi, s / m);       s = 0;       for (int i = 0; i < m; i++) s += v[v.size() - 1 - i];       ma = max(ma, s / m);     }     cout << setprecision(9) << mi <<     << ma;   }


#include <bits/stdc++.h>   using namespace std;   int ans, a, b, n, x;   int main() {     scanf( %d , &n);     while (n--) {       scanf( %d , &x);       if (n == 0) a = x;       b = max(b, x);     }     printf( %d n , a ^ b);     return 0;   }


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


#include <bits/stdc++.h>   void merging(long long arr[], long long start, long long mid, long long end);   void sort(long long arr[], long long start, long long end) {     long long mid;     if (end - start + 1 > 1) {       mid = (start + end) / 2;       sort(arr, start, mid);       sort(arr, mid + 1, end);       merging(arr, start, mid, end);     }   }   void merging(long long arr[], long long start, long long mid, long long end) {     long long len1, len2, i, j, k;     len1 = mid - start + 1;     len2 = end - mid - 1 + 1;     long long right[len2], left[len1];     for (i = 0; i < len1; i++) {       left[i] = arr[i + start];     }     for (i = 0; i < len2; i++) {       right[i] = arr[i + mid + 1];     }     i = 0;     j = 0;     k = start;     while ((i < len1) && (j < len2)) {       if (left[i] > right[j]) {         arr[k] = right[j];         j++;         k++;       } else {         arr[k] = left[i];         i++;         k++;       }     }     if (i == len1) {       while (j < len2) {         arr[k] = right[j];         j++;         k++;       }     } else {       while (i < len1) {         arr[k] = left[i];         i++;         k++;       }     }   }   long long gcd(long long a, long long b) {     if (a == b)       return a;     else if (a == 0)       return b;     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     long long n;     scanf( %I64lld , &n);     long long a[200005];     for (int i = 0; i < n; i++) {       scanf( %I64lld , &a[i]);     }     sort(a, 0, n - 1);     long long cor[200005], l = 0;     for (long long int i = 0; i < n - 1; i++) {       if (a[i] != a[i + 1]) {         cor[l] = a[i];         l++;       }     }     {       cor[l] = a[n - 1];       l++;     }     long long min[200005];     for (long long int i = 0; i < l - 1; i++) {       min[i] = cor[i + 1] - cor[i];     }     long long mini = cor[1] - cor[0];     for (int i = 0; i < l - 1; i++) {       mini = gcd(min[i], mini);     }     long long nop = 0;     for (long long int i = 0; i < n; i++) {       nop = nop + (a[n - 1] - a[i]) / mini;     }     printf( %I64lld %I64lld n , nop, mini);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   int n, k;   int in[222];   int main() {     int i, j, tcc, tc = 1 << 28;     for (tcc = 0; tcc < tc; tcc++) {       n = getint(), k = getint();       for (i = 0; i < n; i++) in[i] = getint();       int s, t;       int res = in[0];       for (s = 0; s < n; s++)         for (t = s; t < n; t++) {           int sum = 0;           vector<int> with;           for (i = s; i <= t; i++) sum += in[i], with.push_back(in[i]);           vector<int> other;           for (i = 0; i < s; i++) other.push_back(in[i]);           for (i = t + 1; i < n; i++) other.push_back(in[i]);           sort(other.begin(), other.end(), greater<int>());           sort(with.begin(), with.end());           res = max(res, sum);           int lm = min(other.size(), with.size());           lm = min(lm, k);           for (i = 0; i < lm; i++) {             sum += other[i];             sum -= with[i];             res = max(res, sum);           }         }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long al;     cin >> al;     while (al--) {       long long b, c;       cin >> b >> c;       if ((abs(b - c)) % 10 == 0)         cout << abs(b - c) / 10 <<   n ;       else {         b = abs(b - c);         cout << b / 10 + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int pos[100010];   int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   bool check(int i, int j) {     int x = (i - 1) / m + 1, y = (i - 1) % m + 1;     int x2 = (j - 1) / m + 1, y2 = (j - 1) % m + 1;     for (int k = 0; k < 4; k++)       if (x + dx[k] == x2 && y + dy[k] == y2) return true;     return false;   }   bool dfs(int i) {     if (i == n * m + 1) return true;     int x = (i - 1) / m + 1, y = (i - 1) % m + 1;     for (int j = i; j <= n * m; j++) {       swap(pos[i], pos[j]);       if (x != 1 && check(pos[i], pos[(x - 2) * m + y])) continue;       if (y != 1 && check(pos[i], pos[(x - 1) * m + y - 1])) continue;       if (dfs(i + 1)) return true;       swap(pos[i], pos[j]);     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) pos[(i - 1) * m + j] = (i - 1) * m + j;     if (!dfs(1)) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %d  , pos[(i - 1) * m + j]);       putchar(  n );     }     return 0;   }