#include <bits/stdc++.h>   using namespace std;   const long long N = 201;   const long long K = 201;   const long long X = 201;   long long dp[N][X];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, k, x;     cin >> n >> k >> x;     vector<long long> picBeauty;     picBeauty.push_back(-1);     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       picBeauty.push_back(x);     }     long long minimumPosts = n / k;     if (x < minimumPosts) {       cout << -1 << endl;       return 0;     }     for (long long i = 0; i <= n; i++) {       for (long long j = 0; j <= x; j++) {         dp[i][j] = 0;       }     }     for (long long i = 1; i <= k; i++) {       dp[i][1] = picBeauty[i];     }     long long flag = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = 2; j <= i && j <= x; j++) {         long long tempFlag = 0;         long long backAllowed = i - k;         for (long long y = i - 1; y >= 1 && y >= backAllowed; y--) {           if (dp[y][j - 1] > 0)             dp[i][j] = max(dp[i][j], dp[y][j - 1] + picBeauty[i]);         }       }     }     long long ans = 0;     for (long long i = n - k + 1; i <= n; i++) {       ans = max(ans, dp[i][x]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int l, r, id;     bool operator<(const Q a) const {       if (l == a.l) return r < a.r;       return l < a.l;     }   } q[400003];   int a[400003], b[400003];   int pos[400003];   int m, sum[400003];   int lb(int k) { return k & -k; }   void add(int k, int v) {     while (k <= m) {       sum[k] += v;       k += lb(k);     }   }   int s(int k) {     int re = 0;     while (k) {       re += sum[k];       k -= lb(k);     }     return re;   }   int L[400003];   int main() {     int i, j, n;     while (~scanf( %d , &n)) {       memset(sum, 0, sizeof(sum));       m = 0;       for (i = 0; i < n; i++) {         scanf( %d%d , &q[i].l, &q[i].r);         q[i].id = i;         b[m++] = q[i].l, b[m++] = q[i].r;       }       sort(b, b + m);       m = unique(b, b + m) - b;       for (i = 0; i < n; i++) {         int id = lower_bound(b, b + m, q[i].r) - b + 1;         add(id, 1);       }       sort(q, q + n);       int ans = 0;       for (i = 0; i < n; i++) {         int l = lower_bound(b, b + m, q[i].l) - b + 1;         int r = lower_bound(b, b + m, q[i].r) - b + 1;         add(r, -1);         ans = s(r) - s(l - 1);         L[q[i].id] = ans;       }       for (i = 0; i < n; i++) {         printf( %d n , L[i]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string w;       for (int i = 0; i <= 2 * n - 2; i = i + 2) {         w = w + s[i];       }       cout << w << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > p;   int main() {     int tc;     cin >> tc;     while (tc--) {       p.clear();       int n, a, b;       cin >> n;       bool value = true;       for (int i = 0; i < n; ++i) {         cin >> a >> b;         if (a < b) value = false;         if (p.empty())           p.push_back({a, b});         else {           if (a < p.back().first || b < p.back().second ||               a - p.back().first < b - p.back().second)             value = false;           p.push_back({a, b});         }       }       if (value)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 5;   const long long MOD = 1e9 + 7;   long long nCr[N][N];   void precompute() {     nCr[0][0] = 1;     for (long long i = 1; i < N; i++) {       nCr[i][0] = 1;       for (long long j = 1; j <= i; j++) {         nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];         nCr[i][j] %= MOD;       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     precompute();     long long n, m, k;     cin >> n >> m >> k;     long long ans = nCr[n - 1][2 * k] * nCr[m - 1][2 * k];     ans %= MOD;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[110][110], i, j, maxi, f, maxid[110], c = 0, poi;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) scanf( %d , &a[i][j]);     }     for (i = 0; i < m; i++) {       maxi = a[i][0];       maxid[i] = 0;       for (j = 0; j < n; j++) {         if (maxi < a[i][j]) {           maxi = a[i][j];           maxid[i] = j;         }       }     }     f = 0;     sort(maxid, maxid + m);     poi = maxid[0];     for (i = 1; i < m; i++) {       if (maxid[i] != maxid[i - 1]) {         if (f < c) {           f = c;           poi = maxid[i - 1];         }         c = 0;       } else         c++;     }     printf( %d n , poi + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   template <class T>   T sqr(const T &x) {     return x * x;   }   template <class T>   T lowbit(const T &x) {     return (x ^ (x - 1)) & x;   }   inline long long mlog2(long long n) {     long long c = 0;     c += 64 - __builtin_clzll(n);     return c - 1;   }   void fun(int a, int b) {     for (b = 0; b < 5; b++) a++;   }   bool arr[15][15] = {0};   int k;   bool check(int a, int b, int c, int d) {     int i, j, tp = 0;     for (i = a; i <= b; i++)       for (j = c; j <= d; j++) {         if (arr[i][j] == 1) tp++;         if (tp >= k) return 1;       }     return 0;   }   int main() {     int r, c, n, i, j, p, q, cou = 0, x, y;     cin >> r >> c >> n >> k;     for (i = 0; i < n; i++) {       cin >> x >> y;       x--;       y--;       arr[x][y] = 1;     }     for (i = 0; i < r; i++) {       for (j = i; j < r; j++) {         for (p = 0; p < c; p++) {           for (q = p; q < c; q++) {             if (check(i, j, p, q)) cou++;           }         }       }     }     cout << cou;   }


#include <bits/stdc++.h>   using namespace std;   string st;   long ans, tans, n, ttl, qpos;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     cin >> st;     for (int i = 0; i < st.size(); i++)       if (st[i] ==  H ) ++ttl;     ans = 1000000;     for (int stp = 0; stp < n; stp++) {       tans = 0;       qpos = stp;       for (int i = 1; i <= ttl; i++) {         if (st[qpos] ==  T ) ++tans;         ++qpos;         if (qpos == n) qpos = 0;       }       ans = min(ans, tans);     }     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   const int N = 60;   const int M = 11;   const int MOD = 1e9 + 7;   int binom[N + 1][N + 1], n, a[N], parent[N], inDegree[N], v0[N], v1[N], msk1[N],       dp[N + 1][1 << M];   int findRoot(int u) {     if (parent[u] != u) {       parent[u] = findRoot(parent[u]);     }     return parent[u];   }   void add(int &x, int a) {     x += a;     if (x >= MOD) {       x -= MOD;     }   }   int solve(int n0, int n1) {     assert(n0 <= M);     for (int j = 0; j < n1; ++j) {       msk1[j] = 0;     }     for (int i = 0; i < n0; ++i) {       for (int j = 0; j < n1; ++j) {         if (v1[j] % v0[i] == 0) {           msk1[j] |= 1 << i;         }       }     }     for (int i = 1; i <= n1; ++i) {       for (int msk = 0; msk < 1 << n0; ++msk) {         dp[i][msk] = 0;       }     }     for (int i = 0; i < n1; ++i) {       add(dp[1][msk1[i]], 1);     }     for (int i = 1; i < n1; ++i) {       for (int msk = 0; msk < 1 << n0; ++msk) {         if (dp[i][msk]) {           int cnt = 0;           for (int j = 0; j < n1; ++j) {             if ((msk1[j] & msk) == msk1[j]) {               cnt++;             } else if (msk1[j] & msk) {               add(dp[i + 1][msk | msk1[j]], dp[i][msk]);             }           }           if (i < cnt) {             add(dp[i + 1][msk], 1LL * (cnt - i) * dp[i][msk] % MOD);           }         }       }     }     return dp[n1][(1 << n0) - 1];   }   int main() {     for (int i = 0; i <= N; ++i) {       binom[i][0] = 1;       for (int j = 1; j <= i; ++j) {         binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;       }     }     while (scanf( %d , &n) == 1) {       for (int i = 0; i < n; ++i) {         scanf( %d , a + i);         parent[i] = i;         inDegree[i] = 0;       }       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           if (i != j && a[j] % a[i] == 0) {             if (findRoot(i) != findRoot(j)) {               parent[findRoot(i)] = findRoot(j);             }             inDegree[j]++;           }         }       }       int result = 1, size = 0;       for (int group = 0; group < n; ++group) {         if (parent[group] == group) {           int n0 = 0, n1 = 0;           for (int i = 0; i < n; ++i) {             if (findRoot(i) == group) {               if (inDegree[i]) {                 v1[n1++] = a[i];               } else {                 v0[n0++] = a[i];               }             }           }           if (n1) {             size += n1 - 1;             result =                 1LL * result * binom[size][n1 - 1] % MOD * solve(n0, n1) % MOD;           }         }       }       printf( %d n , result);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2010;   const long long mod = 998244353;   long long pw(long long a, long long b) {     if (b == 0) return 1;     long long k = pw(a, b / 2);     k = (k * k) % mod;     if (b & 1) k = (k * a) % mod;     return k;   }   long long n, m;   long long dp[maxn][maxn], cnt[maxn], f[maxn][maxn];   string s;   signed main() {     s +=  . ;     string ss;     cin >> ss;     n = ss.size();     s += ss;     for (long long i = 1; i <= n; i++) cnt[i] = cnt[i - 1] + (s[i] ==  ? );     for (long long t = 2; t <= n; t++)       for (long long l = 1; l + t - 1 <= n; l++) {         long long r = l + t - 1;         if (t == 2) f[l][r] = (s[l] !=  ) );         if (s[l] ==  ) ) {           dp[l][r] = dp[l + 1][r];           f[l][r] = f[l + 1][r];           continue;         }         if (s[r] ==  ( ) {           dp[l][r] = dp[l][r - 1];           continue;         }         if (t == 2) {           dp[l][r] = 1;           continue;         }         long long K = pw(2, cnt[r - 1] - cnt[l]);         f[l][r] = K + dp[l + 1][r - 1];         if (s[l] ==  ? ) f[l][r] += f[l + 1][r];         f[l][r] %= mod;         if (s[l] ==  (  && s[r] ==  ) ) dp[l][r] = (dp[l + 1][r - 1] + K) % mod;         if (s[l] ==  ?  && s[r] ==  ) )           dp[l][r] = (dp[l + 1][r] + dp[l + 1][r - 1] + K) % mod;         if (s[l] ==  (  && s[r] ==  ? )           dp[l][r] = (dp[l][r - 1] + dp[l + 1][r - 1] + K) % mod;         if (s[l] ==  ?  && s[r] ==  ? )           dp[l][r] = (dp[l][r - 1] + dp[l + 1][r] + K) % mod;       }     cout << dp[1][n];   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5 + 10;   const int MaxL = 18;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int up[MaxN][MaxL], ds[MaxN];   vector<int> graph[MaxN];   int n, m, sz[MaxN];   long long sum[MaxN], ups[MaxN];   void dfsLca(int v, int p) {     up[v][0] = p;     for (int i = 1; i < MaxL; ++i) {       up[v][i] = up[up[v][i - 1]][i - 1];     }     sz[v] = 1;     for (int i = 0; i < (int)graph[v].size(); ++i) {       int to = graph[v][i];       if (to == p) {         continue;       }       ds[to] = ds[v] + 1;       dfsLca(to, v);       sz[v] += sz[to];       sum[v] += sz[to] + sum[to];     }   }   void dfsUp(int v, int p) {     if (p != -1) {       ups[v] = (sum[p] - (sum[v] + sz[v]) + ups[p]) + (n - sz[v]);     }     for (int i = 0; i < (int)graph[v].size(); ++i) {       int to = graph[v][i];       if (to == p) {         continue;       }       dfsUp(to, v);     }   }   int getLca(int x, int y) {     if (ds[x] > ds[y]) {       swap(x, y);     }     for (int i = MaxL - 1; i >= 0; --i) {       if (ds[up[y][i]] >= ds[x]) {         y = up[y][i];       }     }     if (x == y) {       return x;     }     for (int i = MaxL - 1; i >= 0; --i) {       if (up[x][i] != up[y][i]) {         x = up[x][i];         y = up[y][i];       }     }     return up[x][0];   }   int getKth(int x, int k) {     for (int i = MaxL - 1; i >= 0; --i) {       if (k & (1 << i)) {         x = up[x][i];       }     }     return x;   }   double solve(int x, int y) {     int l = getLca(x, y);     int len = ds[x] + ds[y] - 2 * ds[l];     double ans = 0;     if (x != l && y != l) {       long long total = 1LL * sz[x] * sz[y];       long long cnt =           1LL * sz[x] * sum[y] + 1LL * sz[y] * sum[x] + 1LL * total * len + total;       ans = 1.0 * cnt / total;     } else {       if (ds[x] > ds[y]) {         swap(x, y);       }       int xy = getKth(y, len - 1);       long long total = 1LL * (n - sz[xy]) * sz[y];       long long cnt = 1LL * (n - sz[xy]) * sum[y] +                       1LL * (ups[xy] - (n - sz[xy])) * sz[y] + 1LL * total * len +                       total;       ans = 1.0 * cnt / total;     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n - 1; ++i) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       graph[x].push_back(y);       graph[y].push_back(x);     }     dfsLca(0, 0);     dfsUp(0, -1);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       printf( %.9lf n , solve(x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> len(n);     vector<string> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];       len[i] = s[i].length();     }     const int all = n - 1 + accumulate(len.begin(), len.end(), 0);     vector<vector<bool>> eq(n, vector<bool>(n, false));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (s[i] == s[j]) eq[i][j] = true;       }     }     vector<vector<int>> dp(n, vector<int>(n, 0));     for (int i = n - 1; i >= 0; i--) {       for (int j = n - 1; j >= 0; j--)         if (eq[i][j]) {           if (i + 1 < n and j + 1 < n)             dp[i][j] = dp[i + 1][j + 1] + 1;           else             dp[i][j] = 1;         }     }     int ans = all;     for (int i = 0; i < n; i++) {       int sum = 0;       for (int d = 0; i + d < n; d++) {         int cnt = 1;         sum += len[i + d];         for (int pos = i + d + 1; pos < n; pos++) {           if (dp[i][pos] > d) {             cnt++;             pos += d;           }         }         int res = all - sum * cnt + cnt;         if (cnt > 1 and ans > res) ans = res;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long sz(vector<long long> v) {     if (v.empty()) {       return 0;     } else {       return v.size();     }   }   long long sz(set<long long> v) {     if (v.empty()) {       return 0;     } else {       return v.size();     }   }   long long sz(vector<pair<long long, long long> > v) {     if (v.empty()) {       return 0;     } else {       return v.size();     }   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e % 2)       return ((b * power((b) * (b), (e - 1) / 2)));     else       return power((b) * (b), e / 2);   }   long long modpower(long long b, long long e, long long q) {     long long MOD = q;     if (e == 0) return 1;     if (e % 2)       return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;     else       return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;   }   void dpv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void dpv(vector<pair<long long, long long> > v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second <<   n ;     }   }   void dpv(set<long long> v) {     for (auto i : v) {       cout << i <<    ;     }     cout <<   n ;   }   void oblivious() {     long long n;     cin >> n;     string s[n];     char c[n][n];     for (long long i = 0; i < n; i++) {       cin >> s[i];       for (long long j = 0; j < s[i].length(); j++) {         c[i][j] = s[i][j];       }     }     long long r[n], co[n];     memset(r, 0, sizeof(r));     memset(co, 0, sizeof(co));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         if (c[i][j] ==  . ) {           r[i] = 1;           co[j] = 1;         }       }     }     long long f1 = 1;     long long f2 = 1;     for (long long i = 0; i < n; i++) {       if (r[i] == 0) {         f1 = 0;         break;       }     }     for (long long i = 0; i < n; i++) {       if (co[i] == 0) {         f2 = 0;         break;       }     }     if (f1 || f2) {       if (f1 && f2) {         for (long long i = 0; i < n; i++) {           for (long long j = 0; j < n; j++) {             if (c[i][j] ==  . ) {               cout << i + 1 <<     << j + 1 <<   n ;               break;             }           }         }       } else if (f1) {         for (long long i = 0; i < n; i++) {           for (long long j = 0; j < n; j++) {             if (c[i][j] ==  . ) {               cout << i + 1 <<     << j + 1 <<   n ;               break;             }           }         }       } else if (f2) {         for (long long i = 0; i < n; i++) {           for (long long j = 0; j < n; j++) {             if (c[j][i] ==  . ) {               cout << j + 1 <<     << i + 1 <<   n ;               break;             }           }         }       }     } else {       cout <<  -1  <<   n ;     }   }   signed main() {     long long t = 1;     while (t--) {       oblivious();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, N = 2000;   long long m, n, shroo, I[maxn], tmm, id[maxn], J[maxn], W[maxn], Su[maxn],       dp1[maxn], dp2[maxn];   vector<pair<long long, long long> > hel1;   vector<int> tmp, in[maxn], out[maxn];   bool amx(int i, int j) { return id[I[i]] > id[I[j]]; }   void dfs_1(int i) {     id[i] = 1;     for (auto A : out[i])       if (!id[A]) dfs_1(A);     tmp.push_back(i);   }   void dfs_2(int i) {     id[i] = tmm;     for (auto A : in[i])       if (!id[A]) dfs_2(A);   }   void scc() {     for (int y = 1; y <= n; y++)       if (!id[y]) dfs_1(y);     memset(id, 0, sizeof id);     reverse(tmp.begin(), tmp.end());     for (auto A : tmp)       if (!id[A]) tmm++, dfs_2(A);   }   long long gett(long long x) {     int st = 0, en = 2e4 + 5, md, i;     while (st <= en) {       md = st + ((en - st) >> 1);       if (2 * x >= md * (md + 1))         st = md + 1, i = md;       else         en = md - 1;     }     return (i + 1) * x - 1LL * i * (i + 1) * (i + 2) / 6;   }   int main() {     scanf( %d%d , &n, &m);     for (int y = 1; y <= m; y++) {       scanf( %d%d%d , &I[y], &J[y], &W[y]);       in[J[y]].push_back(I[y]);       out[I[y]].push_back(J[y]);       Su[y] = gett(W[y]);     }     scc();     tmp.clear();     cin >> shroo;     for (int y = 1; y <= m; y++)       if (id[I[y]] == id[J[y]]) dp2[id[I[y]]] += Su[y];     for (int y = 1; y <= m; y++)       if (id[I[y]] != id[J[y]]) tmp.push_back(y);     sort(tmp.begin(), tmp.end(), amx);     for (int y = 1; y <= n; y++) dp1[y] = dp2[y];     for (auto A : tmp)       dp1[id[I[A]]] = max(dp1[id[I[A]]], dp2[id[I[A]]] + W[A] + dp1[id[J[A]]]);     printf( %lld , dp1[id[shroo]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100500;   struct matrix {     long double a[3][3];     void clear() { memset(a, 0, sizeof(a)); }     matrix operator*(const matrix &y) {       matrix ans;       ans.clear();       for (int i = (0), iend = (2); i <= iend; i++)         for (int j = (0), jend = (2); j <= jend; j++)           for (int k = (0), kend = (2); k <= kend; k++)             ans.a[i][j] += a[i][k] * y.a[k][j];       return ans;     }   } basis;   struct segment_tree {     matrix sum[maxn << 2];     void push_up(int rt) { sum[rt] = sum[(rt << 1)] * sum[(rt << 1 | 1)]; }     void upd(int l, int r, int rt, int tar, long double val) {       if (l == r) {         sum[rt].clear();         sum[rt].a[1][0] = 1;         sum[rt].a[2][1] = 1;         sum[rt].a[1][2] = (val - 1) / val;         sum[rt].a[2][2] = 1 / val;         return;       }       int mid = (l + r) >> 1;       if (tar <= mid)         upd(l, mid, (rt << 1), tar, val);       else         upd(mid + 1, r, (rt << 1 | 1), tar, val);       push_up(rt);     }     matrix query(int l, int r, int rt, int tl, int tr) {       if (tl <= l && r <= tr) return sum[rt];       int mid = (l + r) >> 1;       matrix ans = basis;       if (tl <= mid) ans = ans * query(l, mid, (rt << 1), tl, tr);       if (tr >= mid + 1) ans = ans * query(mid + 1, r, (rt << 1 | 1), tl, tr);       return ans;     }   } t;   int main() {     basis.clear();     for (int i = (0), iend = (2); i <= iend; i++) basis.a[i][i] = 1;     int n, q;     scanf( %d%d , &n, &q);     for (int i = (1), iend = (n); i <= iend; i++) {       int a, b;       scanf( %d%d , &a, &b);       t.upd(1, n, 1, i, (long double)(a) / b);     }     for (int i = (1), iend = (q); i <= iend; i++) {       int ty;       scanf( %d , &ty);       if (ty == 1) {         int idx, a, b;         scanf( %d%d%d , &idx, &a, &b);         t.upd(1, n, 1, idx, (long double)(a) / b);       } else {         int l, r;         scanf( %d%d , &l, &r);         matrix ans;         ans.clear();         ans.a[0][2] = 1;         ans = ans * t.query(1, n, 1, l, r);         long double out = (long double)(1) / ans.a[0][2];         if (isnan(out)) out = 0;         printf( %.7lf n , (double)(out));       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 101000;   vector<int> e[mn];   int c[mn], s[mn], sc[mn], sv[mn];   int R[mn], vis[mn];   int n, m, i, j, k, nc, tt;   long long ans;   bool cmpc(int i, int j) { return c[i] > c[j]; }   bool cmps(int i, int j) { return s[i] < s[j]; }   void add(int i, int d, int l) {     s[0] = l;     int j = lower_bound(sv + 1, sv + 1 + n, 0, cmps) - sv;     if (j == n + 1) return;     j = sv[j];     if (s[j] != l || c[j] > d) return;     e[j].push_back(i);   }   inline bool dfs(int r) {     int p, i;     vis[r] = nc;     for (p = 0; p < e[r].size(); ++p) {       i = e[r][p];       if (R[i] == 0 || (vis[R[i]] != nc && dfs(R[i]))) {         R[i] = r;         return 1;       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (i = 1; i <= n; ++i) cin >> c[i] >> s[i];     for (i = 1; i <= n; ++i) sc[i] = sv[i] = i;     sort(sc + 1, sc + 1 + n, cmpc);     sort(sv + 1, sv + 1 + n, cmps);     cin >> m;     for (i = 1; i <= m; ++i) {       cin >> j >> k;       add(i, j, k);       add(i, j, k + 1);     }     for (i = 1; i <= n; ++i) {       ++nc;       if (dfs(sc[i])) ++tt, ans += c[sc[i]];     }     cout << ans << endl;     cout << tt << endl;     for (i = 1; i <= m; ++i)       if (R[i]) cout << i <<     << R[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 2e5 + 3;   long long n, k, arr[MX], sum;   multiset<long long> st;   string s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> arr[i];     cin >> s;     st.insert(-arr[0]);     for (long long i = 1; i < n; i++) {       if (s[i] == s[i - 1])         st.insert(-arr[i]);       else {         long long a = 0;         for (auto u : st) {           if (a == k) break;           sum -= u;           a++;         }         st.clear();         st.insert(-arr[i]);       }     }     long long a = 0;     for (auto u : st) {       if (a == k) break;       sum -= u;       a++;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, root;   vector<int> adj[N];   int dp[N][2], deg[N];   bool mark[N];   void dfs(int u, int pre) {     for (int v : adj[u]) {       if (v == pre) continue;       dfs(v, u);     }     for (int p = 0, _n = (2); p < _n; p++) {       int d = (deg[u] + ((p == 0 && pre != -1) ? -1 : 0));       vector<int> ban;       for (int v : adj[u])         if (v != pre) {           if (!dp[v][0]) ban.push_back(v);         }       bool flag = false;       for (int v : ban) {         if (!dp[v][1]) {           flag = true;           break;         }       }       if (flag) continue;       if ((d - ban.size()) % 2 == 1) {         flag = true;         for (int v : adj[u])           if (v != pre && dp[v][0]) {             if (dp[v][1]) flag = false;           }         if (flag) continue;       }       dp[u][p] = 1;     }   }   void print_ans(int u, int pre, int p) {     int d = (deg[u] + ((p == 0 && pre != -1) ? -1 : 0)), cnt = 0;     for (int v : adj[u])       if (v != pre) {         if (!dp[v][0]) {           cnt++;           print_ans(v, u, 1);           mark[v] = 1;         }       }     if ((d - cnt) % 2 == 1) {       for (int v : adj[u])         if (v != pre && dp[v][0] && dp[v][1]) {           print_ans(v, u, 1);           mark[v] = 1;           break;         }     }     cout << u <<   n ;     for (int v : adj[u])       if (v != pre && !mark[v]) print_ans(v, u, 0);   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     clock_t tStart = clock();     cin >> n;     for (int i = (1), _b = (n); i <= _b; i++) {       int j;       cin >> j;       if (j == 0)         root = i;       else {         adj[i].push_back(j);         adj[j].push_back(i);         deg[i]++;         deg[j]++;       }     }     dfs(root, -1);     if (!dp[root][0]) {       cout <<  NO  <<   n ;       return 0;     } else {       cout <<  YES  <<   n ;       print_ans(root, -1, 0);     }     fprintf(stderr,  Time taken: %.2fs n ,             (double)(clock() - tStart) / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double weight = 0;     long n, m;     cin >> n >> m;     long long a[n];     long long b[n];     bool flag = 0;     for (long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         flag = 1;       }     }     for (long i = 0; i < n; i++) {       cin >> b[i];       if (b[i] == 1) {         flag = 1;       }     }     if (flag == 1) {       cout << -1 << endl;       exit(0);     }     weight = m;     weight += double(weight) / double(b[0] - 1);     for (long i = n - 1; i > 0; i--) {       weight += double(weight) / double(a[i] - 1);       weight += double(weight) / double(b[i] - 1);     }     weight += double(weight) / double(a[0] - 1);     cout << setprecision(30) << weight - m << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10050;   const int inf = 0x7fffffff;   string str;   int buf[maxn];   vector<int> sans[10];   int save[300] = {};   string ansstr;   string bk;   int bK;   int main(void) {     int n, K;     cin >> n >> K >> str;     int ans = inf;     for (int k = ( 0 ); k <= ( 9 ); ++k) {       for (int i = 0; i < (n); ++i) buf[i] = abs(k - str[i]);       sort(buf, buf + n);       int res = accumulate(buf, buf + K, 0);       if (ans > res) ans = res;       save[k] = res;     }     cout << ans << endl;     for (int i = 0; i < (n); ++i) ansstr.push_back( 9 );     bk = str;     bK = K;     for (int no = ( 0 ); no <= ( 9 ); ++no)       if (save[no] == ans) {         K = bK;         str = bk;         for (int i = 0; i < (10); ++i) sans[i].clear();         for (int i = 0; i < (n); ++i) {           if (str[i] >= no)             sans[abs(no - str[i])].push_back(i);           else             sans[abs(no - str[i])].push_back(1000000 - i);         }         for (int i = 0; i < (10); ++i) sort(sans[i].begin(), sans[i].end());         for (int i = 0; i < (10); ++i)           for (int j = 0; j < (sans[i].size()); ++j) {             if (K <= 0) break;             K--;             int cnt = sans[i][j];             if (cnt > 500000) cnt -= 1000000;             str[abs(cnt)] = no;           }         if (str < ansstr) ansstr = str;       }     cout << ansstr << endl;   }


#include <bits/stdc++.h>   int n, m, a, b, mna = 101, mnb = 101, mxa, mxb;   void No() { printf( -1 ); }   void Yes(int n) { printf( %d , n); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n;          i++, scanf( %d , &a), mna = std::min(mna, a), mxa = std::max(mxa, a))       ;     for (int i = 0; i < m; i++, scanf( %d , &b), mnb = std::min(mnb, b))       ;     mxa = std::max(mxa, 2 * mna);     if (mxa >= mnb)       No();     else       Yes(mxa);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T bpow(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int ts, kk = 1;   int n, a[1000006];   bool bl[1000006];   char s[1000006];   int p[2][2][1000006];   int dp(bool st, bool c, int i) {     if (i == n) {       if (c && st) return -1;       return 0;     }     int &pr = p[st][c][i];     if (pr != -1) return pr;     pr = 0;     pr = max(pr, dp(st, 0, i + 1));     if (bl[i] == 0) {       if (c == 0) pr = max(dp((i == 0) || st, 1, i + 1) + 1, pr);       if (a[i] > 1) pr = max(dp(st, 1, i + 1) + 1, pr);     } else {       if (c == 0) pr = max(dp((i == 0) || st, 1, i + 1) + 1, pr);       if (a[i] > 1) pr = max(dp(st, 1, i + 1) + 1, pr);     }     return pr;   }   void prnt(bool st, bool c, int i) {     if (i == n) {       puts(  );       return;     }     int &pr = p[st][c][i];     if (dp(st, 0, i + 1) == pr) {       prnt(st, 0, i + 1);       return;     }     if (bl[i] == 0) {       if (c == 0 && dp((i == 0), 1, i + 1) + 1 == pr) {         printf( %d 0 0 n , i);         prnt((i == 0), 1, i + 1);         return;       }       if (a[i] > 1 && pr == dp(st, 1, i + 1) + 1) {         printf( %d 0 1 n , i);         prnt(st, 1, i + 1);         return;       }     } else {       if (c == 0 && dp((i == 0), 1, i + 1) + 1 == pr) {         printf( %d 1 0 n , i);         prnt((i == 0), 1, i + 1);         return;       }       if (a[i] > 1 && pr == dp(st, 1, i + 1) + 1) {         printf( %d 1 1 n , i);         prnt(st, 1, i + 1);         return;       }     }   }   int main() {     int t, i, j, k;     memset(p, -1, sizeof(p));     scanf(  %s , s);     k = strlen(s);     bl[0] = s[0] -  0 ;     n = 1;     for (i = 0; i < k; i++) {       if ((bool)(s[i] -  0 ) == bl[n - 1])         a[n - 1]++;       else {         bl[n] = (s[i] -  0 );         a[n++] = 1;       }     }     if (n > 1 && bl[n - 1] == bl[0]) {       a[0] += a[n - 1];       n--;     }     k = dp(0, 0, 0);     printf( %d n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, pair<int, int> > > l, u;   set<pair<int, pair<int, int> > >::iterator itu, itl;   const int INF = 1000 * 1000 * 1000LL + 10;   int main() {     int n, q, a, b, ll, lm, lt, uu, um, ut;     char c;     long long ans;     cin >> n >> q;     for (int i = 0; i < q; i++) {       scanf( %d %d %c , &a, &b, &c);       ans = 0;       if (c ==  U ) {         l.insert(make_pair(b, make_pair(INF, INF)));         u.insert(make_pair(a, make_pair(0, 0)));         itl = l.find(make_pair(b, make_pair(INF, INF)));         itu = u.find(make_pair(a, make_pair(0, 0)));         itu++;         if (itl == l.begin()) {           ll = 0;           lm = 0;           lt = q;         } else {           itl--;           ll = (*itl).first;           lm = (*itl).second.first;           lt = (*itl).second.second;           itl++;         }         if (itu == u.end()) {           uu = 0;           um = 0;           ut = q;         } else {           uu = n - (*itu).first + 1;           um = (*itu).second.first;           ut = (*itu).second.second;         }         itu--;         l.erase(itl);         u.erase(itu);         if (uu > ll || (ll == uu && ut < lt)) {           if (uu != b) ans += (um + b - uu);           u.insert(make_pair(a, make_pair(um + b - uu, i + 1)));         } else {           ans += (b - ll);           u.insert(make_pair(a, make_pair(b - ll, i + 1)));         }       } else {         l.insert(make_pair(b, make_pair(0, 0)));         u.insert(make_pair(a, make_pair(INF, INF)));         itl = l.find(make_pair(b, make_pair(0, 0)));         itu = u.find(make_pair(a, make_pair(INF, INF)));         itl++;         if (itl == l.end()) {           ll = n + 1;           lm = 0;           lt = q;         } else {           ll = (*itl).first;           lm = (*itl).second.first;           lt = (*itl).second.second;         }         if (itu == u.begin()) {           uu = n + 1;           um = 0;           ut = q;         } else {           itu--;           uu = n - (*itu).first + 1;           um = (*itu).second.first;           ut = (*itu).second.second;           itu++;         }         itl--;         l.erase(itl);         u.erase(itu);         if (uu > ll || (ll == uu && ut > lt)) {           if (ll != b) ans += (lm + ll - b);           l.insert(make_pair(b, make_pair(lm + ll - b, i + 1)));         } else {           ans += (uu - b);           l.insert(make_pair(b, make_pair(uu - b, i + 1)));         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 4040;   map<int, int> cnt1;   map<int, int> cnt2;   pair<int, int> a[200020];   int main() {     int ans = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       cnt1[a[i].first + a[i].second]++;       cnt2[a[i].first - a[i].second]++;     }     for (int i = 0; i < n; i++) {       int curx = a[i].first;       int cury = a[i].second;       ans += cnt2[curx - cury] - 1 + cnt1[curx + cury] - 1;     }     cout << ans / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[2000];   int n;   inline bool check() {     int c = 0;     for (int i = 0; i < n; ++i)       if (a[i] + 1 == a[i + 1]) ++c;     if (c == n)       return true;     else       return false;   }   inline void push() {     for (int i = 0; i <= n; ++i) {       if (i % 2 == 0) {         if (a[i] == n)           a[i] = 0;         else           a[i] = a[i] + 1;       } else {         if (a[i] == 0)           a[i] = n;         else           a[i] = a[i] - 1;       }     }   }   int main() {     scanf( %d , &n);     --n;     for (int i = 0; i <= n; ++i) {       scanf( %d , &a[i]);       if (i % 2 == 0) {         if (a[i] == n)           a[i] = 0;         else           a[i] = a[i] + 1;       } else {         if (a[i] == 0)           a[i] = n;         else           a[i] = a[i] - 1;       }     }     if (check()) {       puts( Yes );       return 0;     } else {       for (int i = 0; i < n; ++i) {         push();         if (check()) {           puts( Yes );           return 0;         }       }     }     puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int n, l;   int a[maxn], b[maxn];   bool check(int d, int x, int y) {     int i = x + 1, j = y + 1;     i %= n;     j %= n;     while (i != x && j != y) {       if ((a[i] - b[j] + l) % l == d) {         i++;         i %= n;         j++;         j %= n;       } else {         return false;       }     }     return true;   }   int main() {     cin >> n >> l;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     bool flag = false;     for (int i = 0; i < n && !flag; i++) {       for (int j = 0; j < n && !flag; j++) {         int d = (a[i] - b[j] + l) % l;         if (check(d, i, j)) {           flag = true;         }       }     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100000 + 10;   int main() {     long long n, a[maxN], c = 0, min = 1000000001, index;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < min) {         min = a[i];         c = 0;         index = i;       } else if (a[i] == min) {         c++;       }     }     if (c == 0)       cout << index + 1;     else       cout <<  Still Rozdil ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c = 0;     cin >> a >> b;     int x[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};     for (int i = a; i <= b; i++) {       int y = i;       while (y != 0) {         c += x[y % 10];         y = y / 10;       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using ld = long double;   const int MN = 2e5 + 3, MOD = 1e9 + 7;   void solve() {     int n, a, b;     scanf( %d %d %d , &n, &a, &b);     if (a > b) swap(a, b);     printf( %d %d n , min(n, max(1, a + b + 1 - n)), min(n, a + b - 1));   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   const int N = (int)2e5 + 7;   const int MOD = (int)1e9 + 7;   const int INF = (int)2e7;   const long long BIG = 1e18;   int a[N], b[N], c[N], d[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n, ans = 0;     cin >> n;     unordered_map<int, int> cnt;     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;     set<pair<int, int> > q;     for (auto x : cnt) q.insert(make_pair(x.second, x.first));     while (int(q.size()) >= 3) {       vector<pair<int, int> > del;       auto it = q.end();       --it;       b[ans] = it->second;       del.push_back(*it);       --it;       c[ans] = it->second;       del.push_back(*it);       --it;       d[ans] = it->second;       del.push_back(*it);       ++ans;       for (auto x : del) {         pair<int, int> w = x;         q.erase(w);         if (w.first != 1) q.insert(make_pair(w.first - 1, w.second));       }     }     cout << ans <<   n ;     for (int i = 0; i < ans; i++) {       vector<int> p = {b[i], c[i], d[i]};       sort(p.begin(), p.end());       cout << p[2] <<     << p[1] <<     << p[0] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 151;   int m, n;   char gd[N][N];   inline int fab(int x) { return x > 0 ? x : -x; }   int main() {     while (scanf( %d%d , &m, &n) != -1) {       for (int i = 0; i < m; i++) scanf( %s , gd[i]);       int ans = 0, x = 0, y = 0;       for (int i = 0; i < m; i++)         for (int j = (i & 1 ? n - 1 : 0); 0 <= j && j < n; j += (i & 1 ? -1 : 1))           if (gd[i][j] ==  W ) {             ans += fab(i - x) + fab(j - y);             x = i;             y = j;           }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long g, r;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     vector<int> d;     for (int i = 0; i < m; i++) {       long long dt;       cin >> dt;       d.push_back(dt);     }     sort(d.begin(), d.end());     cin >> g >> r;     vector<vector<bool>> vis(m, vector<bool>(g + 1));     vector<vector<int>> dis(m, vector<int>(g + 1, 0));     deque<tuple<int, int>> dq;     dq.push_back(make_tuple(0, 0));     long long ans = 1e9;     vis[0][0] = 1;     while (!dq.empty()) {       int i, t;       tie(i, t) = dq.front();       dq.pop_front();       if (t == 0) {         int ttn = n - d[i];         if (ttn <= g) {           ans = min(ans, dis[i][t] * (r + g) + ttn);         }       }       if (t == g) {         if (!vis[i][0]) {           dq.push_back(make_tuple(i, 0));           dis[i][0] = dis[i][t] + 1;           vis[i][0] = 1;         }         continue;       }       if (i) {         int rs = t + d[i] - d[i - 1];         if (rs <= g && !vis[i - 1][rs]) {           dis[i - 1][rs] = dis[i][t];           dq.push_front(make_tuple(i - 1, rs));           vis[i - 1][rs] = 1;         }       }       if (i < m - 1) {         int rs = t + d[i + 1] - d[i];         if (rs <= g && !vis[i + 1][rs]) {           dis[i + 1][rs] = dis[i][t];           dq.push_front(make_tuple(i + 1, rs));           vis[i + 1][rs] = 1;         }       }     }     if (ans == 1e9) {       cout << -1 <<   n ;     } else {       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void no(int ex = -1) { cout << ex <<   n ; }   void win(bool bl) {     if (bl)       cout <<  YES ;     else       cout <<  NO ;     cout <<   n ;   }   const int N = 2 * 100000;   const int mod = 998244353;   double T, n, m, k, p, res, pr;   bool bw;   string str;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> T;     while (T--) {       cin >> n;       cin >> pr;       bw = false;       for (int i = 1; i < n; i++) {         cin >> k;         if (abs(k - pr) >= 2) {           bw = true;           p = i;         }         pr = k;       }       if (bw)         cout <<  YES               <<   n               << p <<     << p + 1 <<   n ;       else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   struct fenwick {     vector<T> bit;     int n;     void build(int n_) {       n = n_;       bit.resize(n + 1);       for (int i = 1; i <= n; ++i) bit[i] = T(0);     }     void update(int pos, T val) {       for (; pos <= n; pos += pos & -pos) bit[pos] = (bit[pos] + val) % M;     }     T get(int r) {       T x{};       for (; r; r -= r & -r) x = (x + bit[r]) % M;       return x;     }     T query(int l, int r) { return (get(r) - get(l - 1) + M) % M; }   };   fenwick<long long> fenw1, fenw2;   const int N = 5e5 + 5;   int b[N];   long long a[N];   int _runtimeTerror_() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i], b[i] = i;     sort(b + 1, b + 1 + n, [&](int x, int y) { return a[x] < a[y]; });     long long ans = 0;     fenw1.build(n);     fenw2.build(n);     for (int i = 1; i <= n; ++i) {       fenw1.update(b[i], b[i]);       fenw2.update(b[i], n - b[i] + 1);       long long u = 1LL * (fenw1.get(b[i])) * (n - b[i] + 1) % M;       u += 1LL * b[i] * (fenw2.query(b[i] + 1, n)) % M;       u %= M;       ans += a[b[i]] * 1LL * u % M;       ans %= M;     }     cout << ans <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int M = 1e9 + 7;   const int INF = 2e9 + 5;   const int rx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};   const int ry[8] = {0, -1, 0, 1, 1, -1, 1, -1};   mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<long long, long long> > a(n);     long long sumx = 0;     long long sumy = 0;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       sumx += a[i].first;       sumy += a[i].second;     }     long long res = 0;     for (int i = 0; i < n; i++) {       res += (n - 1) * a[i].first * a[i].first - a[i].first * (sumx - a[i].first);       res += (n - 1) * a[i].second * a[i].second -              a[i].second * (sumy - a[i].second);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> g;   vector<int> a;   int n;   vector<map<int, int>> dp;   int ans = 0;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   void dfs(int v, int p = -1) {     for (auto to : g[v]) {       if (to != p) {         dfs(to, v);         if (gcd(a[v], a[to]) != 1) {           for (auto i : dp[to]) {             int y = gcd(a[v], i.first);             if (y != 1) {               for (auto c : dp[v])                 if (gcd(c.first, i.first) != 1)                   ans = max(ans, i.second + c.second);             }           }           for (auto i : dp[to]) {             int y = gcd(a[v], i.first);             if (y != 1) {               dp[v][y] = max(dp[v][y], i.second + 1);               ans = max(ans, i.second + 1);             }           }         }       }     }   }   signed main() {     std::ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     g.resize(n);     a.resize(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     dp.resize(n);     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < n; ++i) {       if (a[i] != 1) {         ans = 1;         dp[i][a[i]] = 1;       }     }     if (!ans) {       cout << 0;       return 0;     }     dfs(0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   const int md = 1e9 + 7;   int mul(int a, int b) { return (long long)a * b % md; }   char s[N];   int n, m, nn, x[N], z[N];   bool start[N];   int main() {     scanf( %d %d %s , &n, &m, s);     nn = strlen(s);     for (int i = 0; i < m; i++) {       scanf( %d , &x[i]);       x[i]--;       start[x[i]] = true;     }     for (int i = 1, l = -1, r = -1; i < nn; i++) {       int &k = z[i];       if (i < r) {         k = min(r - i, z[i - l]);       }       for (; i + k < nn && s[k] == s[i + k]; k++)         ;       if (i + k > r) {         l = i;         r = i + k;       }     }     for (int i = 0; i < m - 1; i++) {       int p = x[i + 1] - x[i];       if (p + z[p] < nn) {         puts( 0 );         return 0;       }     }     int ans = 1;     int r = -1;     for (int i = 0; i < n; i++) {       if (start[i]) {         r = i + nn;       }       if (i >= r) {         ans = mul(ans, 26);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int s;     cin >> s;     long long int tot = 0;     while (s >= 10) {       tot += s / 10 * 10;       s = s / 10 + s % 10;     }     cout << tot + s << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long EPS = 1e-9;   long long mpow(long long a, long long b, long long p = MOD) {     a = a % p;     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % p;       a = (a * a) % p;       b = b >> 1;     }     return res % p;   }   const long long N = 1e6 + 5;   long long dp[N];   long long fac[N];   long long ncm(long long n, long long m) {     if (m > n) return 0;     long long ans = fac[n];     ans = (ans * mpow(fac[m], MOD - 2)) % MOD;     ans = (ans * mpow(fac[n - m], MOD - 2)) % MOD;     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fac[0] = 1;     for (long long i = 1; i < N; i++) {       fac[i] = (i * fac[i - 1]) % MOD;     }     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     dp[n] = 1;     long long ans = 0;     for (long long i = n - 1; i >= 0; i--) {       dp[i] = dp[i + 1];       if (a[i] <= 0) continue;       for (long long j = i + 1; j < n; j++) {         if (j - i < a[i]) continue;         long long rem = a[i] - 1;         long long oo = j - i - 1;         long long c = ncm(oo, rem) * dp[j + 1];         ans += c;         ans %= MOD;         dp[i] += c;         dp[i] %= MOD;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const long long MOD = (long long)(1e9) + 7;   long long getVal(pair<pair<int, int>, long long> p) {     return (p.second * (p.first.second - p.first.first + 1)) % MOD;   }   void pr(stack<pair<pair<int, int>, long long>> st) {     cout << st.top().first.first <<     << st.top().first.second <<              << st.top().second <<   n ;     st.pop();     if (!st.empty()) pr(st);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string second;     cin >> second;     vector<int> v;     int cur = 0;     for (int i = 0; i < (int)second.size(); i++) {       if (second[i] ==  1 ) {         v.push_back(cur);         cur = 0;       } else {         cur++;       }     }     if ((int)v.size() == 0) {       return cout << (int)second.size() <<   n , 0;       ;     }     long long factor = ((long long)(v[0] + 1) * (cur + 1)) % MOD;     v.erase(v.begin());     stack<pair<pair<int, int>, long long>> st;     long long cursum = 0;     for (int i = 0; i < (int)v.size(); i++) {       long long ori = cursum;       while (!st.empty()) {         if (v[i] >= st.top().first.first) {           cursum -= getVal(st.top());           cursum %= MOD;           cursum += MOD;           cursum %= MOD;           if (v[i] < st.top().first.second) {             st.top().first.first = v[i] + 1;             cursum += getVal(st.top());             cursum %= MOD;             break;           } else {             st.pop();           }         } else {           break;         }       }       st.push(make_pair(make_pair(0, v[i]), (ori + 1) % MOD));       cursum += getVal(st.top());       cursum %= MOD;     }     cursum++;     cursum %= MOD;     long long res = (factor * cursum) % MOD;     return cout << res <<   n , 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e15 + 37;   const long long N = 1000 + 10;   const long long IM = 1e18;   const long long PI = 3.14159265;   void PV(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void PA(long long v[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cout << v[i] <<    ;     cout <<   n ;   }   void IN(long long a[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cin >> a[i];   }   inline void PTN(long long n = 1, long long a = 0, long long b = 0,                   long long c = 0) {     if (n--) cout << a <<    ;     if (n--) cout << b <<    ;     if (n--) cout << c <<    ;     cout <<   n ;   }   inline void op() {}   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     op();     long long i, j, x, y, u, l;     long long tt = 1;     {       i = j = x = y = u = l = 0;       string s;       cin >> s;       l = s.size();       for (i = 0; i < l; i++) {         char c;         if (i && s[i] == s[i - 1]) {           for (c =  a ; c <=  z ; c++) {             if (c != s[i]) {               if (i < l) {                 if (c != s[i + 1]) {                   s[i] = c;                   break;                 }               }             }           }         }       }       cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   static inline void amn(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amx(T &x, U y) {     if (x < y) x = y;   }   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long N = 5e5 + 5;   long long top(long long x, long long y) {     long long f = x / y;     if (x % y) f++;     return f;   }   bool cmp(pair<long long, long long> &a, pair<long long, long long> &b) {     return a.first < b.first;   }   void solve() {     long long n, m, x;     cin >> n >> m >> x;     vector<pair<long long, long long> > v;     for (long long i = 1; i <= n; i++) {       v.push_back({0, i});     }     long long sa = top(n, m), sb = n / m;     long long A = (n % m) * sa;     for (long long i = 1; i <= x; i++) {       for (long long j = 0; j < A; j++) {         v[j].first++;       }       for (long long j = 0; j < A; j += sa) {         cout << sa;         for (long long k = j; k < j + sa; k++) {           cout <<     << v[k].second;         }         cout << endl;       }       for (long long j = A; j < n; j += sb) {         cout << sb;         for (long long k = j; k < j + sb; k++) {           cout <<     << v[k].second;         }         cout << endl;       }       sort(v.begin(), v.end(), cmp);     }     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long test_case = 1;     cin >> test_case;     while (test_case--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int binarySearch(int a[], int l, int r, int x);   int main() {     int n, m, i, temp;     vector<int> v1;     vector<int> v2;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d , &temp);       v1.push_back(temp);     }     for (i = 0; i < m; i++) {       scanf( %d , &temp);       v2.push_back(temp);     }     for (i = 0; i < n; i++) {       if (find(v2.begin(), v2.end(), v1[i]) != v2.end()) {         printf( %d  , v1[i]);       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e4 + 3;   const long long MOD = 998244353;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     int s = 2 * n, mid = n, one = 0, left = 0;     for (int i = 1; i <= k; i++) {       cin >> a[i];       if (a[i] % 2) {         a[i]--;         left++;       }     }     for (int i = 1; i <= k; i++) {       if (a[i] >= 4) {         int need = a[i] / 4;         if (mid <= need) {           a[i] -= mid * 4;           mid = 0;         } else {           a[i] %= 4;           mid -= need;         }       }     }     if (mid == 0) {       for (int i = 1; i <= k; i++) s -= a[i] / 2;       s -= left;       if (s >= 0)         cout <<  YES ;       else         cout <<  NO ;       return 0;     }     for (int i = 1; i <= k; i++) {       if (a[i] == 2) {         if (s) {           s--;           continue;         }         if (mid) {           mid--;           left--;           continue;         }         left += 2;       }     }     if (s + mid * 2 >= left)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[200005];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int s, t, m = 0;     for (s = 0; s < n;) {       t = s + 1;       while (a[t] <= a[t - 1] * 2 && t < n) t++;       int res = t - s;       m = max(m, res);       s = t;     }     printf( %d , m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cmp(string s1, string s2) {     if (s1 ==  rock  && s2 ==  scissors ) return 1;     if (s1 ==  scissors  && s2 ==  paper ) return 1;     if (s1 ==  paper  && s2 ==  rock ) return 1;     return 0;   }   int main() {     string s1, s2, s3;     cin >> s1 >> s2 >> s3;     if (cmp(s1, s2) && cmp(s1, s3)) {       putchar( F );       return 0;     }     if (cmp(s2, s1) && cmp(s2, s3)) {       putchar( M );       return 0;     }     if (cmp(s3, s1) && cmp(s3, s2)) {       putchar( S );       return 0;     }     putchar( ? );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const long long mod = 1e9 + 7;   long long mpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) {         res = res * a;       }       b = b / 2;       a = a * a;     }     return res;   }   long long pow1(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) res = res * a % mod;       b = b / 2;       a = a * a % mod;     }     return res;   }   int main() {     long long k;     cin >> k;     long long b = 1;     b = mpow(2LL, k - 1) - 1 + mpow(2, k) - 1 - (mpow(2, k - 1));     long long ans = pow1(4, b);     ans = ans * 6 % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   long long ToInt(const T &x) {     stringstream s;     s << x;     long long r;     s >> r;     return r;   }   template <class T>   string ToString(const T &x) {     stringstream s;     s << x;     return s.str();   }   int main() {     string str, str2;     cin >> str;     if (str.length() == 1) return cout << 1 << endl, 0;     long long N = str[0] -  0 ;     N++;     for (int i = 1; i < str.length(); i++) str2 +=  0 ;     string temp = ToString(N);     str2 = temp + str2;     printf( %lld n , ToInt(str2) - ToInt(str));   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, f, g, h, i, j, k;   int father[100005][20];   vector<int> tree[100005];   int deep[100005];   int que[100005], num[100005];   int K;   int an;   void soso(int x) {     int ii, jj, kk;     que[++que[0]] = x;     deep[x] = deep[father[x][0]] + 1;     for (ii = 0; ii < tree[x].size(); ii++) {       jj = tree[x][ii];       if (jj == father[x][0]) continue;       father[jj][0] = x;       soso(jj);     }   }   void Build_LCA() {     int ii, jj, kk;     for (jj = 1; jj <= 19; jj++)       for (ii = 1; ii <= a; ii++)         father[ii][jj] = father[father[ii][jj - 1]][jj - 1];   }   int LCA(int x, int y) {     int ii, jj, kk;     if (deep[x] < deep[y]) swap(x, y);     for (ii = 18; ii >= 0; ii--)       if (deep[father[x][ii]] >= deep[y]) x = father[x][ii];     if (x == y) return x;     for (ii = 18; ii >= 0; ii--)       if (father[x][ii] != father[y][ii]) x = father[x][ii], y = father[y][ii];     return father[x][0];   }   int Dis(int x, int y) {     int u = LCA(x, y);     return deep[x] + deep[y] - 2 * deep[u];   }   int Add(set<pair<int, int> >& E, int x, int vv) {     int R = 0;     set<pair<int, int> >::iterator now;     if (vv == 1) E.insert(make_pair(num[x], x));     now = E.find(make_pair(num[x], x));     set<pair<int, int> >::iterator now1 = now;     set<pair<int, int> >::iterator pre, next;     if (now != E.begin()) {       pre = --now;       R += Dis((*pre).second, x);     }     now = now1;     next = ++now;     if (next != E.end()) {       R += Dis((*next).second, x);     }     now = now1;     if (now != E.begin() && next != E.end())       R -= Dis((*pre).second, (*next).second);     if (vv == -1) E.erase(now);     return R * vv;   }   bool Check(int x) {     int ii, jj, kk;     int now = 0;     set<pair<int, int> > GG;     for (ii = 1; ii <= x - 1; ii++) now += Add(GG, ii, 1);     for (ii = x; ii <= a; ii++) {       now += Add(GG, ii, 1);       set<pair<int, int> >::iterator in = GG.end();       in--;       int tmp = Dis((*GG.begin()).second, (*in).second);       if (now + tmp <= (K << 1)) return true;       now += Add(GG, ii - x + 1, -1);     }     return false;   }   int main() {     cin >> a >> K;     K--;     for (i = 1; i < a; i++) {       cin >> c >> d;       tree[c].push_back(d);       tree[d].push_back(c);     }     soso(1);     Build_LCA();     for (i = 1; i <= a; i++) num[que[i]] = i;     int low = 1, high = a, mid;     while (low <= high) {       mid = (low + high) >> 1;       if (Check(mid)) {         an = max(an, mid);         low = mid + 1;       } else         high = mid - 1;     }     cout << an << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[505], b[505];   void solve() {     long long int n;     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> a[i];     for (long long int i = 1; i <= n; i++) cin >> b[i];     long long int x = (n + 1) / 2;     if (n % 2 == 1 && a[x] != b[x]) {       cout <<  No n ;       return;     }     multiset<pair<long long int, long long int> > m;     if (n % 2) {       for (long long int i = 1; i < x; i++) m.insert({a[x + i], a[x - i]});       for (long long int i = 1; i < x; i++) {         pair<long long int, long long int> p = {b[x + i], b[x - i]};         if (m.find(p) != m.end()) {           m.erase(m.find(p));           continue;         }         swap(p.first, p.second);         if (m.find(p) != m.end()) {           m.erase(m.find(p));           continue;         }         cout <<  No n ;         return;       }     } else {       for (long long int i = 0; i < x; i++) m.insert({a[x - i], a[x + i + 1]});       for (long long int i = 0; i < x; i++) {         pair<long long int, long long int> p = {b[x - i], b[x + i + 1]};         if (m.find(p) != m.end()) {           m.erase(m.find(p));           continue;         }         swap(p.first, p.second);         if (m.find(p) != m.end()) {           m.erase(m.find(p));           continue;         }         cout <<  No n ;         return;       }     }     cout <<  Yes n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int qc;     cin >> qc;     for (long long int i = 1; i <= qc; i++) solve();   }


#include <bits/stdc++.h>   #define ll long long   #define f(n) for(ll i=0;i<n;i++)   #define mod 998244353   #define vl vector<ll>   #define pb push_back   #define mk make_pair   #define forn(i, n) for (int i = 0; i < int(n); i++)   #define nl   n    #define IOS ios_base::sync_with_stdio(false);       #include <iostream>   using namespace std;          void solve()   {           ll n;           cin>>n;           ll a[n];           for(ll i=0;i<n;i++)           {               cin>>a[i];           }           sort(a,a+n);           ll v=0,s=0;               for(int i=2;i<n;i++)           {               s+=a[i-2];               v-=(a[i]*(i-1));               v+=s;           }           cout<<v<<endl;   }          void init_code()   {       #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif    }           int main()   {       init_code();      IOS      cin.tie(NULL);      cout.tie(NULL);      ll t;      cin>>t;      //t=1;      while(t--)      {         solve();      }      return 0;   }


#include <bits/stdc++.h>   using namespace std;      using ll = long long int;   typedef vector<ll> vi;   typedef vector<vi> vvi;   typedef pair<ll,ll> ii;   typedef vector<ii> vii;   typedef vector<vii> vvii;   #define F first   #define S second      ll min(ll x, ll y){       return ((x < y) ? x : y);   }      ll max(ll x, ll y){       return ((x > y) ? x : y);   }   const ll INF = 1e18;      double findavg (ll x, ll itr){       ll sum = 0;       for (ll i = 0; itr > i; i++){           ll mvs = 0;           ll cur = 0;           while (x > cur){               ll rd = rand()%2;               if (rd){                   cur++;               }else cur = 0;               mvs++;           }           cout << mvs << endl;           sum += mvs;       }       double ans = (double)sum/(double)itr;       cout <<  x:   << x <<     <<  itr:   << itr << endl;       cout << ans << endl;       return ans;   }      int main(){       ll t; cin >> t;       while (t--){           ll k; cin >> k;           if (k%2 == 1){               cout <<  -1 n ;               continue;           }           vi v;           for (ll i = 1; 63 > i; i++){               ll bm = 1;               bm <<= i;               if (k & bm){                   v.push_back(1);                   for (ll j = 0; i > j+1; j++){                       if (j) v.push_back(0);                       else v.push_back(1);                   }               }              }           cout << v.size() << endl;           for (auto i: v) cout << i <<    ;           cout << endl;       }      }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, c;     cin >> n >> a >> b >> c;     long long x = n % 4;     long long y = 4 - x;     if (n % 4 == 0)       cout << 0 <<   n ;     else {       if (y == 1) {         cout << min(min(a, b + c), 3 * c) <<   n ;       } else if (y == 2) {         cout << min(min(2 * a, 2 * c), b) <<   n ;       } else if (y == 3) {         cout << min(min(c, 3 * a), b + a) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   inline long long gcd(long long a, long long b) {     a = ((a) < 0 ? -(a) : (a));     b = ((b) < 0 ? -(b) : (b));     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   long long ext_gcd(long long A, long long B, long long* X, long long* Y) {     long long x2, y2, x1, y1, x, y, r2, r1, q, r;     x2 = 1;     y2 = 0;     x1 = 0;     y1 = 1;     for (r2 = A, r1 = B; r1 != 0;          r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {       q = r2 / r1;       r = r2 % r1;       x = x2 - (q * x1);       y = y2 - (q * y1);     }     *X = x2;     *Y = y2;     return r2;   }   inline long long modInv(long long a, long long m) {     long long x, y;     ext_gcd(a, m, &x, &y);     x %= m;     if (x < 0) x += m;     return x;   }   inline long long bigmod(long long a, long long p, long long m) {     long long res = 1 % m, x = a % m;     while (p) {       if (p & 1) res = (res * x) % m;       x = (x * x) % m;       p >>= 1;     }     return res;   }   int dir4[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   const long long inf = 100000000000000LL;   const long long mod = 1000000007;   const double pi = 2 * acos(0.0);   const double eps = 1e-11;   const int Size = 300505;   int N;   int Map[105];   int A[105];   vector<int> POS[105];   vector<int> G1, GX, G2;   vector<int> mset1, mset2;   char res[105];   bool solve() {     int cnt1 = 0, cntx = 0;     for (long long s = (1); s <= (100); ++s) {       if (Map[s] == 1) {         cnt1++;         G1.push_back(s);       } else if (Map[s] == 2) {         G2.push_back(s);       } else if (Map[s] > 2) {         cntx++;         GX.push_back(s);       }     }     for (long long i = (0); i <= (cnt1 / 2 - 1); ++i) {       int v = G1.back();       mset1.push_back(POS[v][0]);       G1.pop_back();     }     for (long long i = (0); i <= (cnt1 / 2 - 1); ++i) {       int v = G1.back();       mset2.push_back(POS[v][0]);       G1.pop_back();     }     if (cnt1 % 2 == 1) {       int v = G1.back();       mset1.push_back(POS[v][0]);       G1.pop_back();       if (cntx == 0) return false;       int xx = GX.back();       GX.pop_back();       mset2.push_back(POS[xx][0]);       for (long long i = (1); i <= (((long long)(POS[xx]).size()) - 1); ++i) {         mset1.push_back(POS[xx][i]);       }     }     for (long long i = (0); i <= (((long long)(G2).size()) - 1); ++i) {       int v = G2[i];       for (long long j = (0); j <= (((long long)(POS[v]).size()) - 1); ++j) {         mset1.push_back(POS[v][j]);       }     }     for (long long i = (0); i <= (((long long)(GX).size()) - 1); ++i) {       int v = GX[i];       for (long long j = (0); j <= (((long long)(POS[v]).size()) - 1); ++j) {         mset1.push_back(POS[v][j]);       }     }     for (long long i = (0); i <= (((long long)(mset1).size()) - 1); ++i) {       int p = mset1[i];       res[p] =  A ;     }     for (long long i = (0); i <= (((long long)(mset2).size()) - 1); ++i) {       int p = mset2[i];       res[p] =  B ;     }     if (((long long)(mset1).size()) + ((long long)(mset2).size()) != N)       return false;     res[N] =   0 ;     printf( YES n );     printf( %s n , res);     return true;   }   int main() {     scanf( %d , &N);     for (long long i = (0); i <= (N - 1); ++i) {       scanf( %d , &A[i]);       Map[A[i]]++;       POS[A[i]].push_back(i);     }     if (!solve()) {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long fin(long long a, long long b) {     long long ans = 1;     a %= mod;     while (b) {       if (b % 2 == 1) {         ans = (ans * a) % mod;       }       a = (a * a) % mod;       b = b / 2;     }     return ans;   }   int main() {     long long x, k;     cin >> x >> k;     if (x == 0)       cout <<  0 n ;     else {       x %= mod;       cout << (((2 * x - 1) * fin(2, k) + mod) % mod + 1 + mod) % mod <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(){    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       //freopen( input.txt , r ,stdin);       //freopen( output.txt , w ,stdout);    int T;    cin>>T;    for(int t=0;t<T;t++){     int n,k;     cin>>n>>k;     if(n==1&&k==1){cout<<0<<endl;continue;}     if(k<=3){      if(k==2){       int m=n-1;       cout<<m<<endl;       cout<<1<<   ;       for(int i=3;i<=n;i++)        cout<<i<<   ;       cout<<endl;     }else{      if(k==1){       cout<<n-1<<endl;       for(int i=2;i<=n;i++)         cout<<i<<   ;        cout<<endl;      }      else{       cout<<n-2<<endl;       cout<<1<<   ;       for(int i=4;i<=n;i++)         cout<<i<<   ;        cout<<endl;             }     }     }else{      if(k%2==0){       int m=n-k/2;       cout<<m<<endl;       for(int i=k/2;i<=n;i++)        if(i!=k)cout<<i<<   ;       cout<<endl;      }else{       int m=n-k/2-1;       cout<<m<<endl;       for(int i=k/2+1;i<=n;i++)        if(i!=k)cout<<i<<   ;       cout<<endl;      }     }    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init_code() {}   long long int c[207];   bool adj[207][207];   long long int n;   void dfs(long long int u, long long int cu) {     if (~c[u]) {       if (c[u] ^ cu) {         cout <<  NO               <<   n ;         exit(0);       }       return;     }     c[u] = cu;     for (long long int v = 0; v < n; v++)       if (adj[u][v]) dfs(v, cu ^ 1);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     init_code();     cin >> n;     string str;     cin >> str;     for (long long int i = 0; i < n; i++) {       for (long long int j = i + 1; j < n; j++) {         if (str[j] < str[i]) adj[i][j] = adj[j][i] = 1;       }     }     memset(c, -1, sizeof(c));     for (long long int i = 0; i < n; i++) {       if (c[i] < 0) dfs(i, 0);     }     cout <<  YES           <<   n ;     for (long long int i = 0; i < n; i++) cout << c[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A>   using VE = vector<A>;   template <typename A>   using USET = unordered_set<A>;   template <typename A>   using HEAP = priority_queue<A>;   template <typename A, typename B>   using PA = pair<A, B>;   template <typename A, typename B>   using UMAP = unordered_map<A, B>;   template <typename A>   using RHEAP = priority_queue<A, vector<A>, greater<A> >;   template <typename A>   A MAX(const A &a) {     return a;   }   template <typename A>   A MIN(const A &a) {     return a;   }   template <typename A>   A MAX(const A *a, const A *b) {     return *max_element(a, b);   }   template <typename A>   A MIN(const A *a, const A *b) {     return *min_element(a, b);   }   template <typename A, typename... B>   A MAX(const A &a, const B &...b) {     return max(a, MAX(b...));   }   template <typename A, typename... B>   A MIN(const A &a, const B &...b) {     return min(a, MIN(b...));   }   template <typename A, typename B = typename std::iterator_traits<A>::value_type>   B MAX(A a, A b) {     return *max_element(a, b);   }   template <typename A, typename B = typename std::iterator_traits<A>::value_type>   B MIN(A a, A b) {     return *min_element(a, b);   }   mt19937 rng(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   const int N = 100010, M = 1010;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       int idx = 0;       map<int, int> mp;       vector<int> a(n);       for (auto &u : a) {         cin >> u;         if (!mp.count(u)) mp[u] = ++idx;         u = mp[u];       }       int p = -1;       for (int i = 0; i < n; i++)         if (a[i] == a[(i + 1) % n]) {           p = i;           break;         }       vector<int> c(n);       if (p == -1) {         for (int i = 0, j = 1; i + 1 < n; i += 2) {           c[i] = j;           j = 3 - j;           c[i + 1] = j;           j = 3 - j;         }         if (c.back() == 0) {           if (c[n - 2] != c[0])             c.back() = 3;           else             c.back() = 3 - c[0];         }       } else {         rotate(a.begin(), a.begin() + p + 1, a.end());         c[0] = 1;         for (int i = 1; i < n; i++)           if (a[i] != a[i - 1])             c[i] = 3 - c[i - 1];           else             c[i] = 1;       }       cout << MAX(c.begin(), c.end()) <<   n ;       int j;       if (p == -1)         j = 0;       else         j = n - p - 1;       for (int i = 0; i < n; i++, j++) cout << c[j % n] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[27], c[27], d[27];   int main() {     int count, i, n, max, co, t, index, k;     char str[1010], ch, b[1010];     ch = getchar();     while (ch !=   n ) {       a[ch -  a  + 1]++;       ch = getchar();     }     count = 0;     for (i = 1; i <= 26; i++)       if (a[i] != 0) count++;     scanf( %d , &n);     if (n < count)       printf( -1 n );     else if (n == count) {       max = 0;       for (i = 1; i <= 26; i++)         if (a[i] > max) max = a[i];       printf( %d n , max);       for (i = 1; i <= 26; i++)         if (a[i] != 0) printf( %c , i +  a  - 1);       printf(  n );     } else {       t = 0;       for (i = 1; i <= 26; i++) {         if (a[i] != 0) b[t++] = i +  a  - 1;         c[i] = 1;       }       copy(a, a + 27, d);       for (k = n - count; k > 0; k--) {         max = 0;         index = 0;         for (i = 1; i <= 26; i++)           if (d[i] > max) {             max = d[i];             index = i;           }         c[index]++;         b[t++] = index +  a  - 1;         if (a[index] % c[index] != 0)           d[index] = a[index] / c[index] + 1;         else           d[index] = a[index] / c[index];       }       max = 0;       for (i = 1; i <= 26; i++) {         if (d[i] > max) max = d[i];       }       printf( %d n , max);       b[t] = 0;       puts(b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 5, mod = 1e9 + 7, inf = 1e18;   long long n, m, ans[maxn], h[maxn], par[20][maxn], mx[20][maxn], pw2[20],       p[maxn], sz[maxn], ip[maxn];   vector<pair<long long, long long>> v1[maxn], v2[maxn];   vector<pair<long long, pair<long long, long long>>> adj[maxn], g[maxn];   vector<pair<pair<long long, long long>, pair<long long, long long>>> vec;   set<pair<long long, long long>> s[maxn];   long long get_par(long long u) {     if (p[u] == 0) return u;     p[u] = get_par(p[u]);     return p[u];   }   bool merge(long long u, long long v) {     u = get_par(u);     v = get_par(v);     if (u == v) return 0;     if (sz[u] < sz[v]) swap(u, v);     p[v] = u;     sz[u] += sz[v];     return 1;   }   void dfs(long long u) {     for (long long i = 1; i < 20; i++) {       long long v = par[i - 1][u];       if ((v == 0) || (par[i - 1][v] == 0)) break;       par[i][u] = par[i - 1][v];       mx[i][u] = max(mx[i - 1][u], mx[i - 1][v]);     }     for (auto j : g[u]) {       long long v = j.first, w = j.second.first;       if (j.first == par[0][u]) continue;       ip[v] = j.second.second;       mx[0][v] = w;       par[0][v] = u;       h[v] = h[u] + 1ll;       dfs(v);     }   }   void build_mst() {     sort(vec.begin(), vec.end());     for (auto i : vec) {       long long u = i.second.first, v = i.second.second, w = i.first.first;       if (merge(u, v)) {         g[u].push_back({v, {w, i.first.second}});         g[v].push_back({u, {w, i.first.second}});       }     }     dfs(1);   }   long long get_pr(long long v, long long d) {     for (long long i = 0; i < 20; i++) {       if ((pw2[i] & d) == 0) continue;       v = par[i][v];     }     return v;   }   long long get_mx(long long v, long long d) {     long long MX = 0;     for (long long i = 0; i < 20; i++) {       if ((pw2[i] & d) == 0) continue;       MX = max(MX, mx[i][v]);       v = par[i][v];     }     return MX;   }   long long get_lca(long long u, long long v) {     if (h[u] > h[v]) swap(u, v);     if (h[u] != h[v]) v = get_pr(v, h[v] - h[u]);     if (u == v) return u;     for (long long i = 19; i >= 0; i--) {       if (par[i][v] == par[i][u]) continue;       u = par[i][u];       v = par[i][v];     }     return par[0][u];   }   void DFS(long long u) {     for (pair<long long, long long> i : v1[u]) s[u].insert(i);     for (auto j : g[u]) {       if (j.first == par[0][u]) continue;       DFS(j.first);       if (s[j.first].size() == 0) continue;       if (s[j.first].size() > s[u].size()) s[u].swap(s[j.first]);       for (auto j2 : s[j.first]) s[u].insert(j2);       s[j.first].clear();     }     for (pair<long long, long long> i : v2[u]) s[u].erase(i);     if (u == 1) return;     if (s[u].size() == 0) {       ans[ip[u]] = -1;       return;     }     ans[ip[u]] = (*s[u].begin()).first - 1ll;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     pw2[0] = 1;     for (long long i = 1; i < 20; i++) pw2[i] = (pw2[i - 1] * 2ll);     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back({v, {w, i}});       adj[v].push_back({u, {w, i}});       vec.push_back({{w, i}, {u, v}});     }     build_mst();     for (auto j : vec) {       long long u = j.second.first, v = j.second.second, w = j.first.first,                 i = j.first.second;       if (h[u] > h[v]) swap(u, v);       if (par[0][v] == u) continue;       long long lca = get_lca(u, v);       v1[u].push_back({w, v});       v1[v].push_back({w, u});       v2[lca].push_back({w, v});       v2[lca].push_back({w, u});       ans[i] = max(get_mx(u, h[u] - h[lca]), get_mx(v, h[v] - h[lca])) - 1;     }     DFS(1);     for (long long i = 0; i < m; i++) cout << ans[i] <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() { cout <<  INTERCAL  << endl; }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<int> s;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       s.insert(x);     }     set<int>::iterator it, it1, it2;     it = s.begin();     it1 = it;     it1++;     it2 = s.end();     it2--;     if (s.size() == 1)       cout << 0 << endl;     else if (s.size() == 2) {       int e = *it1 - (*it);       if (e % 2 == 0) e /= 2;       cout << e;     } else if (s.size() == 3) {       int a = (*it);       int b = (*it1);       int c = (*it2);       if (b - a == c - b)         cout << b - a << endl;       else         cout << -1 << endl;     } else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   int n, ans, q[N], x[N], y[N];   struct node {     int a, b, m, id;   };   vector<node> a[N];   bool cmp(node x, node y) { return x.a < y.a; }   void Work() {     scanf( %d , &n);     for (int i = 1, x, y, z; i <= n; i++) {       scanf( %d%d%d , &x, &y, &z);       a[x + y - z].push_back((node){x, y, z, i});       q[i] = x + y - z;     }     ans = 0;     for (int i = 1; i <= n; i++)       if (a[q[i]].size()) {         sort(a[q[i]].begin(), a[q[i]].end(), cmp);         for (int j = 0, px = -1e9; j < (int)a[q[i]].size(); j++) {           node b = a[q[i]][j];           if (b.b < q[i] - px) px = min(b.a, q[i]), ans++;           x[b.id] = b.a - px;           y[b.id] = b.m - x[b.id];         }         a[q[i]].clear();       }     cout << ans <<   n ;     for (int i = 1; i <= n; i++) cout << x[i] <<     << y[i] <<   n ;   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d8x[8] = {1, -1, 0, 0, 1, 1, -1, -1};   int d8y[8] = {0, 0, 1, -1, 1, -1, 1, -1};   const int M = 1e9 + 7;   const int N = 1e3, Nx = 500;   int a[N + 1], c[N + 1];   bool isPrime[N + 1];   void sieve(int x) {     for (int i = 0; i <= x; i++) isPrime[i] = true;     isPrime[0] = false;     isPrime[1] = false;     for (int i = 2; i * i <= x; i++) {       if (isPrime[i]) {         for (int j = i * i; j <= x; j += i) isPrime[j] = false;       }     }   }   template <class type>   type gcd(type a, type b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class type>   type MODEXPO(type a, type b, int mod) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return MODEXPO((a * a) % mod, b / 2, mod);     else       return (a * MODEXPO((a * a) % mod, (b - 1) / 2, mod)) % mod;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     fast();     int n;     cin >> n;     int ans = 1;     for (int i = 0; i <= n - 1; i++) cin >> a[i], a[i]--;     for (int i = 0; i <= n - 1; i++) {       memset(c, 0, sizeof c);       int l = 0, x = i;       while (!c[x]) c[x] = 1, l++, x = a[x];       if (x != i) {         ans = -1;         break;       }       if (l % 2 == 0) l /= 2;       ans *= l / gcd(l, ans);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 1e9 + 7;   const ll longinf = 1LL << 60;   const ll mod = 1e9 + 7;   template <typename T, typename S>   struct LazySegmentTree {    private:     int n;     vector<T> node;     vector<S> lazy;     T E0;     S E1;     inline void updatef(S& lazy, S& value) { lazy += value; }     inline void calculatef(T& node, S& lazy, int len) { node += lazy; }     inline T queryf(T& x, T& y) { return max(x, y); }       public:     LazySegmentTree(int sz, T nodeE, S lazyE) : E0(nodeE), E1(lazyE) {       n = 1;       while (n < sz) n <<= 1;       node.resize(2 * n - 1, E0);       lazy.resize(2 * n - 1, E1);     }     LazySegmentTree(vector<T>& v, T E0, S E1) : E0(E0), E1(E1) {       n = 1;       int sz = v.size();       while (n < sz) n <<= 1;       node.resize(2 * n - 1, E0);       lazy.resize(2 * n - 1, E1);       for (int i = (int)(0); i < (int)(sz); ++i) node[i + n - 1] = v[i];       for (int i = n - 2; i >= 0; --i) {         node[i] = queryf(node[2 * i + 1], node[2 * i + 2]);       }     }     void eval(int k, int l, int r) {       if (lazy[k] == E1) return;       calculatef(node[k], lazy[k], r - l);       if (r - l > 1) {         updatef(lazy[2 * k + 1], lazy[k]);         updatef(lazy[2 * k + 2], lazy[k]);       }       lazy[k] = E1;     }     void update(int a, int b, S x, int k = 0, int l = 0, int r = -1) {       if (r < 0) r = n;       eval(k, l, r);       if (r <= a || b <= l) return;       if (a <= l && r <= b) {         updatef(lazy[k], x);         eval(k, l, r);       } else {         update(a, b, x, 2 * k + 1, l, (l + r) / 2);         update(a, b, x, 2 * k + 2, (l + r) / 2, r);         node[k] = queryf(node[2 * k + 1], node[2 * k + 2]);       }     }     T query(int a, int b, int k = 0, int l = 0, int r = -1) {       if (r < 0) r = n;       eval(k, l, r);       if (r <= a || b <= l) return E0;       if (a <= l && r <= b) return node[k];       T xl = query(a, b, 2 * k + 1, l, (l + r) / 2);       T xr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return queryf(xl, xr);     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n, m, p;     cin >> n >> m >> p;     vector<pair<int, pair<int, ll>>> v(n + p);     for (int i = (int)(0); i < (int)(n); ++i) {       int x, y;       cin >> x >> y;       v[i] = {x, {-inf, -y}};     }     vector<pair<int, int>> b(m);     for (int i = (int)(0); i < (int)(m); ++i) {       cin >> b[i].first >> b[i].second;     }     for (int i = (int)(0); i < (int)(p); ++i) {       int x, y, z;       cin >> x >> y >> z;       v[n + i] = {x, {y, z}};     }     sort(b.begin(), b.end());     vector<ll> c(m);     for (int i = (int)(0); i < (int)(m); ++i) c[i] = -b[i].second;     LazySegmentTree<ll, ll> sg(c, -longinf, 0);     sort(v.begin(), v.end());     ll ans = -longinf;     for (auto e : v) {       if (e.second.second < 0) {         ans = max(sg.query(0, m) + e.second.second, ans);       } else {         int idx =             lower_bound(b.begin(), b.end(), pair<int, int>{e.second.first, inf}) -             b.begin();         sg.update(idx, m, e.second.second);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<pair<int, int> > v(n);     for (int i = 0; i < n; i++) cin >> v[i].first;     bool is0 = false, is1 = false;     for (int i = 0; i < n; i++) {       cin >> v[i].second;       if (v[i].second)         is1 = true;       else         is0 = true;     }     if (is0 && is1) {       cout <<  Yes n ;       return;     }     for (int i = 1; i < n; i++)       if (v[i - 1] > v[i]) {         cout <<  No n ;         return;       }     cout <<  Yes n ;   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int mat[1000010];   int row(int r) {     int s = r * m, e = s + m;     bool eq = false, dif = false;     for (int i = s, idx = 0; i < e; i++, idx++) {       if (mat[i] == -1) continue;       int a = mat[i] / 2;       int b = idx & 1;       if (a == b) eq = true;       if (a != b) dif = true;     }     if (eq && dif) return 0;     if (eq || dif) return 1;     return 2;   }   int col(int c) {     int s = c, e = n * m + c;     bool eq = false, dif = false;     for (int i = s, idx = 0; i < e; i += m, idx++) {       if (mat[i] == -1) continue;       int a = min(mat[i], 3 - mat[i]);       int b = idx & 1;       if (a == b) eq = true;       if (a != b) dif = true;     }     if (eq && dif) return 0;     if (eq || dif) return 1;     return 2;   }   int main() {     while (cin >> n >> m) {       char ch;       for (int i = 0; i < n * m; i++) {         cin >> ch;         if (ch ==  . )           mat[i] = -1;         else           mat[i] = (int)(ch -  1 );       }       int res = 1;       for (int i = 0; i < n; i++) {         res *= row(i);         if (res >= 1000003) res -= 1000003;       }       for (int i = 0; i < m; i++) {         res *= col(i);         if (res >= 1000003) res -= 1000003;       }       cout << res % 1000003 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100;   int n, x, t;   long long ans, s[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       t = 0;       while (x) {         t += x % 2;         x /= 2;       }       ++s[t];     }     for (int i = 1; i <= N; ++i) ans += s[i] * (s[i] - 1) / 2;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j;   vector<string> koutsompolio;   int main() {     cin >> n;     string lol;     bool r, f;     for (i = 0; i <= n; i++) {       getline(cin, lol);       koutsompolio.push_back(lol);     }     for (i = 1; i <= n; i++) {       r = false;       f = false;       if ((koutsompolio[i][0] ==  m ) && (koutsompolio[i][1] ==  i ) &&           ((koutsompolio[i][2] ==  a )) && (koutsompolio[i][3] ==  o ) &&           (koutsompolio[i][4] ==  . )) {         r = true;       }       if ((koutsompolio[i][koutsompolio[i].size() - 1] ==  . ) &&           (koutsompolio[i][koutsompolio[i].size() - 2] ==  a ) &&           ((koutsompolio[i][koutsompolio[i].size() - 3] ==  l )) &&           (koutsompolio[i][koutsompolio[i].size() - 4] ==  a ) &&           (koutsompolio[i][koutsompolio[i].size() - 5] ==  l )) {         f = true;       }       if ((f == false) && (r == true)) {         cout <<  Rainbow s n ;       } else if ((f == true) && (r == false)) {         cout <<  Freda s n ;       } else {         cout <<  OMG>.< I don t know! n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x{};     cin >> x;     if (x % 3 == 0 || x % 7 == 0) {       cout <<  YES  << endl;       return;     }     int ms{x / 3};     int ml{x / 7};     for (int i{0}; i <= ms; ++i) {       for (int j{0}; j <= ml; ++j) {         int chunks{3 * i + 7 * j};         if (chunks == x) {           cout <<  YES  << endl;           return;         }       }     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t{};     cin >> t;     while (t > 0) {       solve();       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k;     cin >> k;     long long cnt = 0;     for (double a = 2 + 2. / 3; a < (2 * k) / sqrt(3); a += 2) {       double b =           1e-8 + (-a + sqrt((16 * k * k) / 3. - (3 * a * a))) / 2. - 2. / 3;       if (b > 0) cnt += ((int)b + 2) / 2;     }     cout << 1 + 6 * cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cmpint(const void *a, const void *b) {     if (((int *)a)[0] == ((int *)b)[0]) return ((int *)a)[1] - ((int *)b)[1];     return ((int *)a)[0] - ((int *)b)[0];   }   int prim[500005] = {0};   bool isprim[5000005] = {0};   int prim_len;   void count_prim() {     int i, j, l;     prim[0] = 2;     prim_len = 1;     for (i = 3; i < 5000000; i += 2)       if (isprim[i] == 0) {         prim[prim_len] = i;         prim_len++;         l = i * 2;         if (i < 10000)           for (j = i * i; j < 5000000; j += l) isprim[j] = 1;       }   }   int a[100005];   int main() {     int i, j, n, m, k, l, o, p;     scanf( %d , &n);     count_prim();     m = 0;     for (i = (0); i < (prim_len); i++) {       k = prim[i];       l = 0;       while (k > 0) {         l = l * 10 + k % 10;         k /= 10;       }       if (l != prim[i] && isprim[l] == 0 && l % 2 == 1) {         m++;         a[m] = prim[i];       }       if (m > n) break;     }     printf( %d n , a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     vector<long> A;     long N, L, R, M, T, Sum, Min = 2147483647;     cin >> N;     A.resize(N);     for (long i = 0; i < N; ++i) cin >> A[i];     for (long M = 1; M <= 100; ++M) {       Sum = 0;       for (long i = 0; i < N; ++i)         Sum += min(min(abs(A[i] - M + 1), abs(A[i] - M - 1)), abs(A[i] - M));       if (Sum < Min) {         Min = Sum;         T = M;       }     }     cout << T <<     << Min;     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e6 + 3;   int add(int a, int b) { return (a += b) >= mod ? a -= mod : a; }   int sub(int a, int b) { return add(a, mod - b); }   int mul(int a, int b) { return int(1LL * a * b % mod); }   int pow(int a, int64_t n) {     int res = 1;     while (n > 0) {       if (n & 1) {         res = mul(res, a);       }       a = mul(a, a);       n >>= 1;     }     return res;   }   int inv(int a) { return pow(a, mod - 2); }   int main() {     const int n = 11;     std::vector<int> f(n + 1);     for (int i = 1; i <= n; ++i) {       std::cout <<  ?   << i << std::endl;       std::cin >> f[i];       if (f[i] == 0) {         std::cout <<  !   << i << std::endl;         return 0;       }     }     std::vector<std::vector<int> > a(1 + n, std::vector<int>(1 + n));     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         a[i][j] = pow(i, j - 1);       }     }     for (int j = 1, i = 1; j <= n; ++j) {       bool was = false;       for (int k = i; k <= n; ++k) {         if (a[k][j] != 0) {           was = true;           std::swap(a[i], a[k]);           std::swap(f[i], f[k]);           break;         }       }       if (!was) {         continue;       }       for (int k = i + 1; k <= n; ++k) {         int coeff = mul(sub(0, inv(a[k][j])), a[i][j]);         for (int t = j; t <= n; ++t) {           a[k][t] = add(mul(coeff, a[k][t]), a[i][t]);         }         assert(a[k][j] == 0);         f[k] = add(f[i], mul(coeff, f[k]));       }       i++;     }     std::vector<int> x(1 + n);     for (int i = n; i >= 1; --i) {       assert(a[i][i] != 0);       int res = f[i];       for (int j = i + 1; j <= n; ++j) {         res = sub(res, mul(a[i][j], x[j]));       }       x[i] = mul(res, inv(a[i][i]));     }     for (int i = 0; i < mod; ++i) {       int p = 1, s = 0;       for (int j = 1; j <= n; ++j) {         s = add(s, mul(x[j], p));         p = mul(p, i);       }       if (s == 0) {         std::cout <<  ?   << i << std::endl;         int v;         std::cin >> v;         assert(v == 0);         std::cout <<  !   << i << std::endl;         return 0;       }     }     std::cout <<  !   << -1 << std::endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());   const string DIGITS =  0123456789 ;   const string ALPH =  abcdefghijklmnopqrstuvwxyz ;   template <class T0, class T1>   inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {     return out <<  {  << a.first <<  ,   << a.second <<  } ;   }   template <class T0, class T1, class T2>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  } ;   }   template <class T0, class T1, class T2, class T3>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  ,   << get<3>(a) <<  } ;   }   template <class T>   inline ostream &operator<<(ostream &out, vector<T> &a) {     out <<  [ ;     for (long long i = 0; i < (long long)(a.size()); ++i)       out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()];     return out;   }   void smain();   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(10) << fixed;     smain();     return 0;   }   void smain() {     long long t;     cin >> t;     while (t--) {       long long n, k;       string s;       cin >> n >> k >> s;       vector<long long> p(2);       map<long long, long long> mp;       for (long long i = 0; i < s.size(); i++) {         p[s[i] -  0 ]++;         long long u = p[0] - p[1];         mp[u]++;       }       long long v = p[0] - p[1];       if (v == 0) {         if (mp[k] != 0) {           cout << -1 <<   n ;         } else {           cout << mp[k] <<   n ;         }         continue;       }       long long sum = 0;       for (auto h : mp) {         if ((k - h.first) % abs(v) == 0 && (k - h.first) / v >= 0) {           sum += h.second;         }       }       if (k == 0) sum++;       cout << sum <<   n ;     }   }