#include <bits/stdc++.h>   using namespace std;   int ask(int c, int d) {     cout <<  ?   << c <<     << d << endl;     fflush(stdout);     int x;     cin >> x;     return x;   }   void go(int a, int b) {     cout <<  !   << a <<     << b << endl;     fflush(stdout);     exit(0);   }   bool same[50];   signed main() {     int type = ask(0, 0);     if (type == 0) {       int ans = 0;       for (int i = 29; i >= 0; i--) {         int q = ask((1 << i), 0);         if (q == 0) {           continue;         }         if (q == 1) {           ans += 0;         } else {           ans += (1 << i);         }       }       go(ans, ans);     }     bool A, B;     if (type == 1) {       A = 1;       B = 0;     } else {       A = 0;       B = 1;     }     int ansA = 0, ansB = 0;     for (int i = 29; i >= 0; i--) {       int q = ask(ansA + (1 << i), ansB + (1 << i));       if (q == 0) {         for (int pos = i; pos >= 0; pos--) {           same[pos] = 1;         }         break;       }       if (A == 1) {         if (q == 1) {           same[i] = 1;         } else {           ansA += (1 << i);           ansB += 0;           int qq = ask(ansA, ansB);           if (qq == 1) A = 1, B = 0;           if (qq == -1) A = 0, B = 1;         }       } else {         if (q == -1) {           same[i] = 1;         } else {           ansA += 0;           ansB += (1 << i);           int qq = ask(ansA, ansB);           if (qq == 1) A = 1, B = 0;           if (qq == -1) A = 0, B = 1;         }       }     }     for (int i = 29; i >= 0; i--) {       if (same[i]) {         int q = ask(ansA + (1 << i), ansB);         if (q == 0) {           continue;         }         if (q == 1) {           ansA += 0;           ansB += 0;         } else {           ansA += (1 << i);           ansB += (1 << i);         }       }     }     go(ansA, ansB);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   bool z[MAXN] = {0};   void prework() {     for (int i = 2; i <= 1000; i++) {       if (z[i]) continue;       for (int k = i + i; k <= 1000; k += i) z[k] = true;     }   }   struct node {     char c;     int n;     bool operator<(node b) const { return n > b.n; }   };   vector<int> v;   int num[50] = {0};   string s;   node a[27];   char ans[1010] = {0};   int main() {     prework();     string s;     cin >> s;     int L = s.size();     int all = 0;     for (int i = 2; i <= L; i++) {       if (z[i]) continue;       if (i * 2 <= L) continue;       v.push_back(i);       all++;     }     v.push_back(1);     all++;     for (string::iterator k = s.begin(); k != s.end(); k++) num[*k -  a  + 1]++;     for (int i = 1; i <= 26; i++) {       a[i].c =  a  + i - 1;       a[i].n = num[i];     }     sort(a + 1, a + 27);     all = L - all;     if (a[1].n < all) {       cout <<  NO  << endl;       return 0;     }     a[1].n -= all;     int now = 1;     for (vector<int>::iterator k = v.begin(); k != v.end(); k++) {       while (!a[now].n) now++;       ans[*k] = a[now].c;       a[now].n--;     }     for (int i = 1; i <= L; i++)       if (!ans[i]) ans[i] = a[1].c;     cout <<  YES  << endl;     string sss(ans + 1);     cout << sss << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n == 1)       cout << 2;     else if (n == 2)       cout << 3;     else if (n == 3)       cout << 1;     else if (n == 4)       cout << 2;     else       cout << 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mo = (int)1e9 + 7;   int i, j, m, n, p, k, sum, id, x, y, a[1000005], flag, ans;   int power(int x, int y) {     int sum = 1;     for (; y; y >>= 1) {       if (y & 1) sum = 1ll * x * sum % Mo;       x = 1ll * x * x % Mo;     }     return sum;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     id = 1;     for (i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (y - x != 1 && y - x != k + 1) {         printf( 0 n );         return 0;       } else if (y - x != 1)         a[x]++, ++sum, id = x;     }     for (i = 1; i <= n; ++i) a[i] += a[i - 1];     for (i = id; i <= n && i + k + 1 <= n; ++i)       if (a[max(0, i - k - 1)] == 0)         ans = (ans + power(2, (i - 1 - max(0, i - k - 1) -                                (a[i - 1] - a[max(0, i - k - 1)])))) %               Mo;     if (!a[n]) ans = (ans + 1) % Mo;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = int(1e9) + 7;   const long long int MOD64 = (long long int)(1e18) + 7;   const int INF = 0x7fffffff;   const long long int INF64 = 0x7fffffffffffffff;   const int N = 5000 + 10;   int a[N], lnum[N], rnum[N];   int n, m;   vector<int> H[N];   long long int cal(int x, int val) {     int l = 0, r = H[x].size() - 1, ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (H[x][mid] <= val) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     return ans + 1;   }   pair<int, long long int> solve() {     int ans = 0;     long long int num = 1;     for (int i = int(1); i < int(n + 1); i++) {       long long int tmp = 0;       tmp = cal(i, lnum[i]) * cal(i, rnum[i]) - cal(i, min(lnum[i], rnum[i]));       if (tmp > 0) {         ans += 2;         num = (num * tmp) % MOD;         continue;       }       tmp = cal(i, lnum[i]) + cal(i, rnum[i]);       if (tmp != 0) {         ans += 1;         num = (num * tmp) % MOD;       }     }     return {ans, num};   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = int(1); i < int(n + 1); i++) {       cin >> a[i];       rnum[a[i]]++;     }     for (int i = int(0); i < int(m); i++) {       int f, h;       cin >> f >> h;       H[f].push_back(h);     }     for (int i = int(1); i < int(n + 1); i++) sort((H[i]).begin(), (H[i]).end());     int ans = 0;     long long int num = 0;     for (int i = int(0); i < int(n + 1); i++) {       rnum[a[i]]--;       lnum[a[i]]++;       pair<int, long long int> tmp = solve();       if (ans < tmp.first) {         ans = tmp.first;         num = tmp.second;       } else if (ans == tmp.first) {         num = (num + tmp.second) % MOD;       }     }     memset(lnum, 0, sizeof(lnum));     memset(rnum, 0, sizeof(rnum));     for (int i = int(1); i < int(n + 1); i++) rnum[a[i]]++;     for (int i = int(0); i < int(n); i++) {       rnum[a[i + 1]]--;       lnum[a[i]]++;       pair<int, long long int> tmp = solve();       if (tmp.first == ans) num = (num - tmp.second + MOD) % MOD;     }     cout << ans <<     << num << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     double ans = 0;     for (int i = 1; i <= m; ++i) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       ans = max(ans, ((double)a[x] + a[y]) / z);     }     printf( %.15f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int num;     int num_num;   } num[105];   int main() {     int N, M;     scanf( %d%d , &N, &M);     num[0].num = 0;     num[0].num_num = 0;     for (int i = 1; i <= N; i++) {       int flag;       scanf( %d , &flag);       num[i].num = num[i - 1].num + flag;       num[i].num_num = 0;     }     while (M--) {       int left, right;       scanf( %d%d , &left, &right);       if (left == right && num[left].num - num[left - 1].num > 0)         num[left].num_num++;       else if (left < right && num[right].num - num[left - 1].num >= 0) {         for (int i = left; i <= right; i++) num[i].num_num++;       }     }     long long int sum = 0;     for (int i = 1; i <= N; i++) {       sum += (num[i].num - num[i - 1].num) * num[i].num_num;     }     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long ar[maxn];   int main() {     long long n, m;     cin >> n >> m;     long long a, b, c;     cin >> a >> b >> c;     ar[a] = 1, ar[b] = 2, ar[c] = 3;     for (int i = 1; i < m; ++i) {       cin >> a >> b >> c;       if (!ar[a] and !ar[b] and !ar[c])         ar[a] = 1, ar[b] = 2, ar[c] = 3;       else {         if (ar[a]) {           if (ar[a] == 1)             ar[b] = 2, ar[c] = 3;           else if (ar[a] == 2)             ar[b] = 1, ar[c] = 3;           else             ar[b] = 1, ar[c] = 2;         } else if (ar[b]) {           if (ar[b] == 1)             ar[a] = 2, ar[c] = 3;           else if (ar[b] == 2)             ar[a] = 1, ar[c] = 3;           else             ar[a] = 1, ar[c] = 2;         } else if (ar[c]) {           if (ar[c] == 1)             ar[a] = 2, ar[b] = 3;           else if (ar[c] == 2)             ar[a] = 1, ar[b] = 3;           else             ar[a] = 1, ar[b] = 2;         }       }     }     for (int i = 1; i < n + 1; ++i) cout << ar[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double fs = 6e-2, Pi = acos(-1.0);   struct point {     double x, y;   } p[4];   double a, b, c, r, S, C, P, C1, A1, B1, R1, Ans;   double s(point a, point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   double gcd(double a, double b) {     return (fabs(b) > fs) ? gcd(b, fmod(a, b)) : a;   }   int main() {     for (int i = 1; i <= 3; ++i) scanf( %lf%lf , &p[i].x, &p[i].y);     a = s(p[1], p[2]), b = s(p[2], p[3]), c = s(p[1], p[3]), P = (a + b + c) / 2;     S = sqrt(P * (P - a) * (P - b) * (P - c)), r = a * b * c / (4 * S);     C1 = acos(1 - c * c / (2 * r * r)), A1 = acos(1 - a * a / (2 * r * r)),     B1 = 2 * Pi - A1 - C1;     R1 = gcd(A1, gcd(B1, C1));     return printf( %.6lf , (Pi * r * r * sin(R1)) / R1), 0;   }


#include <bits/stdc++.h>   using namespace std;   string eq(string c) {     string s =   ;     for (int i = 0; i < c.size(); i++) {       if (c[i] ==  2 )         s +=  2 ;       else if (c[i] ==  3 )         s +=  3 ;       else if (c[i] ==  4 )         s +=  223 ;       else if (c[i] ==  5 )         s +=  5 ;       else if (c[i] ==  6 )         s +=  53 ;       else if (c[i] ==  7 )         s +=  7 ;       else if (c[i] ==  8 )         s +=  7222 ;       else if (c[i] ==  9 )         s +=  7332 ;     }     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     return s;   }   int main() {     int n;     string s;     cin >> n >> s;     cout << eq(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[4], num, sum;   string s[4], str;   bool check(char ch) {     return ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u ;   }   int work() {     sum = 0;     for (int i = str.length() - 1; i >= 0; i--) {       sum += check(str[i]);       if (sum == m) return i;     }     return -1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 4; j++) {         cin >> str;         num = work();         if (!~num) {           puts( NO );           return 0;         }         s[j] = str.substr(num);       }       if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3])         a[0] = 1;       else if (s[0] == s[1] && s[2] == s[3])         a[1] = 1;       else if (s[0] == s[2] && s[1] == s[3])         a[2] = 1;       else if (s[0] == s[3] && s[1] == s[2])         a[3] = 1;       else {         puts( NO );         return 0;       }     }     if (a[0] && !(a[1] || a[2] || a[3]))       puts( aaaa );     else if (a[1] && !(a[2] || a[3]))       puts( aabb );     else if (a[2] && !(a[1] || a[3]))       puts( abab );     else if (a[3] && !(a[1] || a[2]))       puts( abba );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   int main() {     long int n, a[100001], i, flag;     char c[100001], c1;     while (scanf( %ld , &n) == 1) {       flag = 0;       long int a1[100001] = {0};       c1 = getchar();       gets(c);       for (i = 0; i < n; i++) {         scanf( %ld , &a[i]);       }       i = 0;       while (1) {         if (c[i] ==  >  && a1[i] == 0) {           a1[i] = 1;           i += a[i];           if (i >= n) {             flag = 1;             break;           }         } else if (c[i] ==  <  && a1[i] == 0) {           a1[i] = 1;           i -= a[i];           if (i < 0) {             flag = 1;             break;           }         } else {           flag = 0;           break;         }       }       if (flag == 1) {         printf( FINITE n );       } else {         printf( INFINITE n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   const int N = 5000 + 10;   const int mod = 1e9 + 7;   int n, dp[N][30], len, a[N], C[N][N], ans;   signed main() {     n = read();     for (int i = 1; i <= n; i++) {       int ch;       ch = getchar() -  a  + 1;       if (ch != a[len]) a[++len] = ch;     }     C[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     dp[0][0] = 1;     for (int i = 1; i <= len; i++)       for (int j = i; j; j--) {         int cur = a[i];         dp[j][cur] = 0;         for (int k = 0; k <= 26; k++)           if (k != cur) dp[j][cur] = (dp[j][cur] + dp[j - 1][k]) % mod;       }     for (int i = 1; i <= len; i++) {       int tmp = 0;       for (int j = 1; j <= 26; j++) tmp = (tmp + dp[i][j]) % mod;       (ans += 1LL * tmp * C[n][i] % mod) %= mod;     }     cout << ans;     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int x = 2 * n, y = 3 * m;     int k = 1;     while (6 * k <= x && 6 * k <= y) {       if (x + 2 <= y + 3)         x += 2;       else         y += 3;       k += 1;     }     cout << max(x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 )       ch ==  -  ? w = -1, ch = getchar() : ch = getchar();     while (ch >=  0  && ch <=  9 ) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return w * res;   }   int n, a, b, c, d, e, f;   int main() {     a = read();     b = read();     c = read();     d = read();     e = read();     f = read();     int flag = 0;     flag |= (b * d * f) > (a * c * e);     flag |= (!c && d);     flag |= (!a && b && c && d);     flag |= (!e && f && a && b && c && d);     flag ? printf( Ron n ) : printf( Hermione n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }   int main() {     fast();     int n, k;     cin >> n >> k;     vector<int> v(n), vc(k + 1);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     auto it = unique(v.begin(), v.end());     v.resize(distance(v.begin(), it));     for (int i = 0; i < v.size(); i++) {       vc[v[i]]++;       if (i > 0 && i < v.size() - 1) {         vc[v[i]] += (v[i - 1] == v[i + 1]);       }     }     int pos = 1;     for (int i = 1; i <= k; i++) {       if (vc[i] > vc[pos]) {         pos = i;       }     }     cout << pos;     return 0;   }


#include <bits/stdc++.h>   long long p[16];   void F() {     p[1] = 10;     for (int i = 2; i <= 14; i++) p[i] = p[i - 1] * 10;   }   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     F();     long long n, ans = 0;     cin >> n;     if (n < 10) {       cout << n;       return 0;     }     for (int i = 1; i <= 14; i++) {       if (n / p[i] == 0) {         long long a = p[i - 1] - 1;         long long b = n - a;         ostringstream str1, str2;         str1 << a;         str2 << b;         string sa = str1.str();         string sb = str2.str();         for (auto x : sa) ans += x -  0 ;         for (auto x : sb) ans += x -  0 ;         cout << ans;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   array<long long, 2> parent[1000][1000];   long long sze[1000][1000];   array<long long, 2> p(array<long long, 2> x) {     if (x == parent[x[0]][x[1]]) {       return x;     } else {       return parent[x[0]][x[1]] = p(parent[x[0]][x[1]]);     }   }   void unite(array<long long, 2> x, array<long long, 2> y) {     array<long long, 2> a = p(x);     array<long long, 2> b = p(y);     if (a != b) {       if (sze[a[0]][a[1]] < sze[b[0]][b[1]]) {         swap(a, b);       }       parent[b[0]][b[1]] = a;       sze[a[0]][a[1]] += sze[b[0]][b[1]];     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n;     cin >> n;     unordered_map<long long, vector<array<long long, 2>>> m1;     unordered_map<long long, vector<array<long long, 2>>> m2;     vector<array<long long, 2>> a(n);     for (long long i = 0; i < n; ++i) {       long long x, y;       cin >> x >> y;       x--;       y--;       a[i] = {x, y};       m1[x].push_back({x, y});       m2[y].push_back({x, y});     }     for (long long i = 0; i < 1000; ++i) {       for (long long j = 0; j < 1000; ++j) {         parent[i][j] = {i, j};         sze[i][j] = 1;       }     }     for (auto i : a) {       for (auto j : m1[i[0]]) {         if (j == i) {           continue;         }         unite(i, j);       }       for (auto j : m2[i[1]]) {         if (j == i) {           continue;         }         unite(i, j);       }     }     long long ans = 0;     for (auto i : a) {       if (i == parent[i[0]][i[1]]) {         ans++;       }     }     cout << ans - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int r, c, n, k;     cin >> r >> c >> n >> k;     int tab[r][c];     for (int i = 0; i < r; i++)       for (int j = 0; j < c; j++) tab[i][j] = 0;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       tab[x][y] = 1;     }     int wyn = 0;     for (int x1 = 0; x1 < r; x1++)       for (int y1 = 0; y1 < c; y1++)         for (int x2 = x1; x2 < r; x2++)           for (int y2 = y1; y2 < c; y2++) {             int v = 0;             for (int i = x1; i <= x2; i++)               for (int j = y1; j <= y2; j++) v += tab[i][j];             if (v >= k) wyn++;           }     cout << wyn;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int mod = 998244353;   int T;   int a[N], b[N], p[N];   bool vis[N];   int main() {     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         p[a[i]] = i;         vis[i] = 0;       }       for (int i = 1; i <= k; ++i) {         scanf( %d , &b[i]);       }       int ans = 1;       for (int i = k; i >= 1; --i) {         int t = p[b[i]];         int kk = 0;         if (t > 1 && !vis[t - 1]) kk++;         if (t < n && !vis[t + 1]) kk++;         vis[t] = 1;         ans = (ans * kk) % mod;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     scanf( %d , &tc);     for (int i = 0; i < tc; i++) {       int N, K;       scanf( %d %d , &N, &K);       if (N < K) {         printf( NO n );         continue;       }       if (N % 2 == 0) {         if (2 * K <= N) {           printf( YES n );           for (int j = 0; j < K - 1; j++) {             if (j != 0) printf(   );             printf( %d , 2);           }           printf(  %d n , N - (2 * (K - 1)));         } else if (N == K) {           printf( YES n );           for (int j = 0; j < K; j++) {             if (j != 0) printf(   );             printf( %d , 1);           }           printf(  n );         } else if (K % 2 != 0) {           printf( NO n );         } else {           bool flag = false;           int count = 0;           while (N > K) {             count++;             N -= 3;             K -= 1;             if (N == K) {               flag = true;               printf( YES n );               for (int l = 0; l < count; l++) {                 if (l != 0) printf(   );                 printf( %d , 3);               }               for (int l = 0; l < N; l++) {                 printf(  %d , 1);               }               printf(  n );               break;             }           }           if (!flag) {             printf( NO n );           }         }       } else {         if (K % 2 != 1) {           printf( NO n );         } else {           printf( YES n );           for (int j = 0; j < K - 1; j++) {             if (j != 0) printf(   );             printf( %d , 1);           }           printf(  %d n , N - ((K - 1)));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, q;   long long ans, in[N], out[N];   vector<int> f[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       f[x].push_back(y);       in[y]++, out[x]++;     }     for (int i = 1; i <= n; ++i) ans += in[i] * out[i];     printf( %lld n , ans);     scanf( %d , &q);     while (q--) {       int x;       scanf( %d , &x);       ans -= in[x] * out[x];       in[x] += out[x], out[x] = 0;       for (int i = 0; i < f[x].size(); ++i) {         int y = f[x][i];         ans -= in[y] * out[y];         out[y]++, in[y]--;         ans += in[y] * out[y];         f[y].push_back(x);       }       f[x].clear();       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ai, nb = 0;     map<int, int> dict;     map<int, int>::iterator it;     cin >> n;     int i = 0;     while (i < n) {       cin >> ai;       dict[ai]++;       i++;     }     for (it = dict.begin(); it != dict.end(); it++) {       while ((it->second) > 1) {         it->second = (it->second) - 2;         nb++;       }     }     cout << (nb / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int a[N];   int b[N];   int main() {     int n;     cin >> n;     a[1] = 0;     for (int i = 2; i <= n; ++i) {       int k;       cin >> k;       a[i] = a[i - 1] + k;     }     int x = 1e6;     for (int j = 1; j <= n; ++j) {       x = min(x, a[j]);     }     for (int i = 1; i <= n; ++i) {       if (a[i] - x + 1 >= 1 && a[i] - x + 1 <= n) {         b[a[i] - x + 1] = 1;       }     }     for (int i = 1; i <= n; ++i) {       if (b[i] == 0) {         cout << -1 << endl;         return 0;       }     }     for (int i = 1; i <= n; ++i) {       cout << a[i] - x + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<pair<int, int> > q;   int c[2048][2048];   int dr[4] = {-1, 0, 1, 0};   int dc[4] = {0, 1, 0, -1}, nr, nc;   int main() {     int n, t, x, y;     scanf( %d%d , &n, &t);     c[1023][1023] = n;     q.push(make_pair(1023, 1023));     pair<int, int> s;     int mxr = 1023, mxc = 1023;     while (!q.empty()) {       s = q.front();       q.pop();       if (c[s.first][s.second] < 4) continue;       for (int k = 0; k < 4; ++k) {         nr = s.first + dr[k];         nc = s.second + dc[k];         c[nr][nc] += c[s.first][s.second] / 4;         if (c[nr][nc] >= 4) q.push(make_pair(nr, nc));       }       c[s.first][s.second] %= 4;     }     ++t;     while (--t) {       scanf( %d%d , &x, &y);       x += 1023;       y += 1023;       if (x < 0 || x > 2047 || y < 0 || y > 2047)         printf( 0 n );       else         printf( %d n , c[y][x]);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   pair<int, int> p[maxn];   int a[maxn];   int b[maxn];   int n, k, cnt;   bool F(int a, int b) { return a > b; }   void solve() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     sort(a + 1, a + n + 1);     sort(b + 1, b + n + 1, F);     int i = 1, t = 1;     while (true) {       if (b[t] + a[i++] >= k) cnt++, t++;       if (t > n || i > n) break;     }     printf( 1 %d , cnt);   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   using VVI = vector<VI>;   using VB = vector<bool>;   using VVB = vector<VB>;   using VD = vector<double>;   using VVD = vector<VD>;   using VS = vector<string>;   using PII = pair<int, int>;   using VPII = vector<PII>;   using VL = vector<long long>;   using VVL = vector<VL>;   int n;   const int MOD = (int)1e9 + 7;   const int MAXN = 300010;   VI A;   int add(int a, int b) {     a = ((a % MOD) + (b % MOD));     return (a >= MOD) ? (a - MOD) : a;   }   int sub(int a, int b) {     a -= b;     return (a < 0) ? (a + MOD) : a;   }   int mul(int a, int b) { return ((long long)a * b) % MOD; }   int powTable[MAXN];   long long sumMaxDistSubsets() {     sort(A.begin(), A.end());     powTable[0] = 1;     for (int i = 1; i <= n; ++i) powTable[i] = (powTable[i - 1] * 2ll) % MOD;     int ret = 0;     for (int i = 1; i <= n; ++i) {       int times = powTable[i - 1] - powTable[n - i];       ret = add(ret, mul(A[i], times));     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     A.assign(n + 1, 0);     for (int i = 1; i < (int)n + 1; ++i) cin >> A[i];     cout << sumMaxDistSubsets() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, k, r;     cin >> n >> k >> r;     long long ar[n], arr[k];     for (i = 0; i < n; i++) {       cin >> ar[i];     }     for (i = 0; i < k; i++) {       cin >> arr[i];     }     sort(ar, ar + n);     sort(arr, arr + k);     long long a = ar[0], d, p;     long long b = arr[k - 1];     d = r / a;     p = r % a;     long long sum = b * d + p;     cout << max(sum, r) << endl;     return 0;   }


#include <bits/stdc++.h>   int getmin(int a, int b) {     if (a == -1)       return b;     else if (b == -1)       return a;     else       return a < b ? a : b;   }   int solve(int a, int b) {     int tot = 0;     while (a != 1 || b != 1) {       tot++;       if (!a || !b) return -1;       if (a > b)         a -= b;       else         b -= a;     }     return tot;   }   int main() {     int n, ans = -1;     scanf( %d , &n);     for (int a = 1; a < n; a++) ans = getmin(ans, solve(a, n));     if (ans == -1) ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int n, q;   struct X {     int id, val;   } s[maxn];   struct XX {     int a, b;     XX() {}     XX(int A, int B) {       a = A;       b = B;     }     bool operator<(const XX &aa) const { return b > aa.b; }   };   XX fir, sec;   vector<int> v[maxn];   set<XX> h;   int tmp[maxn], mn[maxn], mx[maxn];   bool check(int x) {     int tt = v[fir.a][x];     if (s[tt].val < sec.b) return 0;     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= 200000; i++) mx[i] = 0, mn[i] = 2000000000;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &s[i].id, &s[i].val);       v[s[i].id].push_back(i);       mx[s[i].id] = max(mx[s[i].id], s[i].val);       mn[s[i].id] = min(mn[s[i].id], s[i].val);     }     for (int i = 1; i <= 200000; i++) {       if (mx[i] == 0) continue;       h.insert(XX(i, mx[i]));     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int k;       scanf( %d , &k);       for (int j = 1; j <= k; j++) scanf( %d , &tmp[j]);       for (int j = 1; j <= k; j++) {         if (mx[tmp[j]] == 0) continue;         h.erase(XX(tmp[j], mx[tmp[j]]));       }       if (h.size() == 0) {         printf( 0 0 n );       } else if (h.size() == 1) {         XX ans = *h.begin();         printf( %d %d n , ans.a, mn[ans.a]);       } else {         set<XX>::iterator iter;         int cnt = 0;         for (iter = h.begin(); iter != h.end(); iter++) {           cnt++;           if (cnt == 1)             fir = *iter;           else if (cnt == 2) {             sec = *iter;             break;           }         }         int L = 0, R = v[fir.a].size() - 1;         int ans;         while (L <= R) {           int mid = (L + R) / 2;           if (check(mid))             ans = mid, R = mid - 1;           else             L = mid + 1;         }         int tt = v[fir.a][ans];         printf( %d %d n , s[tt].id, s[tt].val);       }       for (int j = 1; j <= k; j++) {         if (mx[tmp[j]] == 0) continue;         h.insert(XX(tmp[j], mx[tmp[j]]));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     vector<long long> a;     for (long long i = 0; i < n; ++i) {       long long x;       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     long long c = 0;     for (long long i = 0; i < a.size() - 1; ++i) {       c += a[a.size() - 1] - a[i];     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[110];   int main() {     int n, i, x, y, j;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       for (j = 0; j < x; j++) {         cin >> y;         c[y]++;         if (c[y] == n) {           cout << y <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   const int N = 3e5 + 7, M = 2e6;   const long long mod = 1e9 + 7;   inline int read() {     int ret = 0;     char ch = getchar();     bool f = 1;     for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^  - );     for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48;     return f ? ret : -ret;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void TelmaZzzz() {}   struct node {     int l, r, val;   } que[N];   int a[N];   int arr[N];   int k, t, m, n;   bool check(int x) {     int minn = m + 1, maxn = -1;     for (int i = 1; i <= m + 1; i++) arr[i] = 0;     for (int i = 1; i <= k; i++) {       if (que[i].val <= a[n - x + 1]) continue;       arr[que[i].l]++;       arr[que[i].r + 1]--;     }     int ans = m + 1;     for (int i = 1; i <= m + 1; i++) {       arr[i] += arr[i - 1];       if (arr[i]) ans += 2;     }     if (ans <= t) return true;     return false;   }   int main() {     TelmaZzzz();     R(n, m, k, t);     for (int i = 1; i <= n; i++) R(a[i]);     for (int i = 1; i <= k; i++) R(que[i].l, que[i].r, que[i].val);     sort(a + 1, a + 1 + n);     int l = 1, r = n;     while (l <= r) {       int mi = (l + r) / 2;       if (check(mi))         l = mi + 1;       else         r = mi - 1;     }     W(r);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   const int N = (int)2e5 + 5;   const int maxN = (int)1e6 + 6;   const long long Mod = (long long)1e9 + 7;   vector<int> box;   int len, k, a, b;   bool vis[201][201];   string s;   void call(int cur, int last) {     if (cur > k) return;     if (last == (int)s.size()) {       if (cur != k) return;       int cnt = 0;       for (int i : box) {         for (int j = cnt; j < i + cnt; ++j) cout << s[j];         cout <<   n ;         cnt += i;       }       exit(0);     }     if (vis[cur][last]) return;     vis[cur][last] = 1;     for (int i = a; i <= b; ++i) {       if (last + i <= (int)s.size()) {         box.push_back(i);         call(cur + 1, i + last);         box.pop_back();       }     }   }   int main() {     int test = 1, tc = 0;     while (test--) {       cin >> k >> a >> b;       cin >> s;       for (int i = a; i <= b; ++i) {         if (i <= (int)s.size()) {           box.push_back(i);           call(1, i);           box.pop_back();         }       }       puts( No solution );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double vp, vd, t, f, c;   int main() {     cin >> vp >> vd >> t >> f >> c;     if (vp >= vd) {       cout <<  0 ;       return 0;     }     int numberOfBojous = 0;     double timeToHaveTheDragonBack = 0, overtakePosition = 0;     double princessPosition = vp * t;     while (princessPosition < c) {       overtakePosition = vd * princessPosition / (vd - vp);       if (overtakePosition < c) numberOfBojous++;       timeToHaveTheDragonBack = (overtakePosition / vd) + f;       princessPosition = (vp * timeToHaveTheDragonBack) + overtakePosition;     }     cout << numberOfBojous;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-10;   const int MOD = 1000000007;   const int MAXN = 110000;   const double PI = acos(-1.0);   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   int num, kase;   int flag[22][MAXN];   long long fun() {     long long ret = 0;     for (int index = 0; index < (21); ++index) {       long long cnt = 0, t = 0;       for (int i = (1); i <= (num + 1); ++i) {         if (flag[index][i] == 1)           cnt++;         else {           t += ((cnt * cnt + cnt) >> 1);           cnt = 0;         }       }       ret += (1 << index) * t;     }     return ret;   }   void findlr(int* f, int n, int& l, int& r) {     int i = n - 1;     while (f[i] == 1) i--;     l = i + 1;     i = n + 1;     while (f[i] == 1) i++;     r = i - 1;   }   int main() {     int t, p;     while (~scanf( %d%d , &num, &kase)) {       memset(flag, 0, sizeof(flag));       for (int i = (1); i <= (num); ++i) {         scanf( %d , &t);         p = 1;         for (int ind = 0; ind < (21); ++ind) {           flag[ind][i] = ((t & p) > 0);           p <<= 1;         }       }       long long ans = fun();       int a, b, l, r;       for (int tt = 0; tt < (kase); ++tt) {         scanf( %d%d , &a, &b);         for (int ind = 0; ind < (21); ++ind) {           p = 1 << ind;           if (((b & p) > 0) != flag[ind][a]) {             findlr(flag[ind], a, l, r);             long long lenl = a - l, lenr = r - a;             ans += (1 - flag[ind][a] * 2) * (1 << ind) *                    (lenl * lenr + lenl + lenr + 1);             flag[ind][a] = !flag[ind][a];           }         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > vt;   bool cmp(pair<int, int> x, pair<int, int> y) {     return (x.first < y.first || (x.first == y.first && x.second < y.second));   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int u;       cin >> u;       vt.push_back(make_pair(u, i));     }     sort(vt.begin(), vt.end(), cmp);     for (int i = 0; i < (int)vt.size() - 2; i++)       for (int j = i + 1; j < (int)vt.size() - 1; j++) {         int k = upper_bound(                     vt.begin(), vt.end(),                     pair<int, int>(vt[i].first + vt[j].first - 1, 1000000000)) -                 vt.begin();         if (vt[k].first == (vt[i].first + vt[j].first)) {           cout << vt[k].second <<     << vt[i].second <<     << vt[j].second;           return 0;         }       }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2500 + 10, MAXK = 7;   int k, sum[MAXN][MAXN], l[MAXK], r[MAXK];   long long Tohka;   vector<string> Rotate(vector<string>& a) {     vector<string> Houki;     for (int i = 0; i < (int)a[0].size(); ++i) {       string str;       for (int j = 0; j < (int)a.size(); ++j) str += a[j][i];       Houki.push_back(str);     }     return Houki;   }   int Gets(int xl, int yl, int xr, int yr) {     return sum[xr][yr] - sum[xl - 1][yr] - sum[xr][yl - 1] + sum[xl - 1][yl - 1];   }   void solve(vector<string> a) {     if (a.size() == 0 || a[0].size() == 0) return;     if (a.size() > a[0].size()) a = Rotate(a);     int n = (int)a.size(), m = (int)a[0].size();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +                     (a[i - 1][j - 1] ==  1 );     int mid = (m + 1) / 2;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= k; ++j) l[j] = 1, r[j] = m;       for (int j = i; j <= n; ++j) {         for (int p = 0; p <= k; ++p) {           for (; l[p] <= mid && Gets(i, l[p], j, mid) > p; ++l[p])             ;           for (; r[p] > mid && Gets(i, mid + 1, j, r[p]) > p; --r[p])             ;         }         for (int lp = 0, rp = k; lp <= k; ++lp, --rp) {           int ls = (lp ? l[lp - 1] : (mid + 1)) - l[lp],               rs = r[rp] - (rp ? r[rp - 1] : mid - 1);           Tohka += (long long)ls * rs;         }       }     }     vector<string> lstr, rstr;     for (int i = 0; i < n; ++i) {       string ls, rs;       for (int j = 0; j < m; ++j) {         if (j + 1 < mid) ls += a[i][j];         if (j + 1 > mid) rs += a[i][j];       }       lstr.push_back(ls), rstr.push_back(rs);     }     solve(lstr), solve(rstr);   }   int main() {     int n, m;     vector<string> a;     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) {       string str;       cin >> str;       a.push_back(str);     }     solve(a);     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int INF = 1e9;   int main() {     string s;     cin >> s;     long long n = s.length();     vector<long long> v;     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (int(s[i]) < 97) {         v.push_back(1);       } else {         v.push_back(0);       }     }     vector<long long> p = vector<long long>(n, 0);     p[0] = (v[0] == 0) ? 1 : 0;     for (long long i = 1; i < n; i++) {       p[i] = p[i - 1] + ((v[i] == 0) ? 1 : 0);     }     long long mn = n - p[n - 1];     for (long long i = 0; i < n; i++) {       mn = min(mn, p[i] + (n - 1 - i - p[n - 1] + p[i]));     }     cout << mn << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, vector<long long>> v;   map<long long, long long> visited, dist, pt;   long long mx = 0, nd = 0, mxd = 0, mxn = 0;   void bfs(long long u) {     visited[u] = 1;     queue<long long> q;     q.push(u);     dist[u] = 0;     while (!q.empty()) {       u = q.front();       visited[u] = 1;       q.pop();       visited[u] = 1;       for (long long i = 0; i < (long long)v[u].size(); i++) {         long long p = v[u][i];         if (!visited[p]) {           visited[p] = 1;           dist[p] = dist[u] + 1;           if (dist[p] > mxd) {             mxd = dist[p];             mxn = p;           }           pt[p] = u;           q.push(p);         }       }     }   }   int main() {     long long a, b, x, c, i, j, n, t, k, z = 0, node, edge;     scanf( %lld , &n);     for (i = 1; i <= n; i++) {       scanf( %lld %lld , &a, &b);       v[a].push_back(b);       v[b].push_back(a);       c = a;     }     bfs(c);     x = mxn;     visited.clear();     dist.clear();     pt.clear();     mxd = 0;     bfs(mxn);     vector<long long> path;     path.push_back(mxn);     long long now = mxn;     while (now != x) {       now = pt[now];       path.push_back(now);     }     for (i = 0; i < (long long)path.size(); i++) cout << path[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   static int comp[maxn];   static int pr[maxn];   static int n;   void make_set() {     for (int i = 0; i < n; ++i) {       pr[i] = i;       comp[i] = 1;     }   }   int find_set(int a) {     if (pr[a] == a) return a;     return pr[a] = find_set(pr[a]);   }   void union_set(int a, int b) {     a = find_set(a);     b = find_set(b);     pr[a] = b;     comp[b] += comp[a];     comp[a] = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     int m;     cin >> m;     make_set();     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       a--;       b--;       if (find_set(a) != find_set(b)) union_set(a, b);     }     int k;     cin >> k;     for (int j = 0; j < k; ++j) {       int a, b;       cin >> a >> b;       a--;       b--;       if (find_set(a) == find_set(b)) {         comp[find_set(a)] = 0;       }     }     int mx = 0;     for (int l = 0; l < n; ++l) {       mx = max(mx, comp[l]);     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > G[100005];   int dp[100005], Xor[100005];   int rec(int n) {     int answer = 1e9;     for (int i = 0; i < G[n].size(); i++) {       int st = G[n][i].first;       int ed = G[n][i].second + st - 1;       int x = Xor[ed] ^ Xor[st - 1];       if (x == 0) answer = min(answer, G[n][i].second);     }     return answer;   }   int main() {     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= 100000; i++) {       for (int j = i, sum = i; sum <= 100000; j++, sum += j) {         if (j - i + 1 >= 2) G[sum].push_back(make_pair(i, j - i + 1));       }     }     for (int n = 1; n <= 100000; n++) {       set<int> ST;       for (int i = 0; i < G[n].size(); i++) {         int st = G[n][i].first;         int ed = G[n][i].second + st - 1;         int x = Xor[ed] ^ Xor[st - 1];         ST.insert(x);       }       for (int i = 0;; i++) {         if (ST.find(i) == ST.end()) {           dp[n] = i;           break;         }       }       Xor[n] = Xor[n - 1] ^ dp[n];     }     int n;     cin >> n;     if (dp[n] == 0) {       cout << -1 << endl;       return 0;     }     cout << rec(n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool is_possible(int m, long long k, long long p[], int n, int x, int a, int y,                    int b) {     if (a != b) {       int first = 0;       int second = 0;       int third = 0;       for (int i = 1; i <= m; i++) {         if (i % a == 0 && i % b == 0)           third++;         else if (i % a == 0)           first++;         else if (i % b == 0)           second++;       }       long long ans1 = 0;       for (int i = 0; i < third; i++) {         ans1 += ((p[i] * (x + y)) / 100);       }       for (int i = third; i <= third + first - 1; i++) {         ans1 += ((p[i] * x) / 100);       }       for (int i = third + first; i <= third + first + second - 1; i++) {         ans1 += ((p[i] * y) / 100);       }       long long ans2 = 0;       for (int i = 0; i < third; i++) {         ans2 += ((p[i] * (x + y)) / 100);       }       for (int i = third; i <= third + second - 1; i++) {         ans2 += ((p[i] * y) / 100);       }       for (int i = third + second; i <= third + second + first - 1; i++) {         ans2 += ((p[i] * x) / 100);       }       if (ans1 >= k || ans2 >= k) return true;       return false;     } else {       long long ans1 = 0;       int first = 0;       for (int i = 1; i <= m; i++) {         if (i % a == 0) first++;       }       for (int i = 0; i < first; i++) {         ans1 += ((p[i] * (x + y)) / 100);       }       if (ans1 < k) return false;       return true;     }   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long aa[n];       long long p[n];       for (int i = 0; i < n; i++) {         cin >> aa[i];         p[i] = aa[i];       }       int x, a, y, b;       cin >> x >> a >> y >> b;       long long k;       cin >> k;       sort(p, p + n, greater<long long>());       int l = 1;       int h = n;       int ans = -1;       while (l <= h) {         int m = l + (h - l) / 2;         if (is_possible(m, k, p, n, x, a, y, b)) {           ans = m;           h = m - 1;         } else {           l = m + 1;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void dbg_out() { cerr <<   b b] n ; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr << H <<  ,  ;     dbg_out(T...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     int n = (int)s.size();     int curr = 0, last = -1;     vector<int> ans;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) )         curr--;       else if (s[i] ==  ( )         curr++;       else {         if (curr <= 0) {           cout << -1;           return 0;         }         last = i;         curr--;         ans.push_back(curr);       }       if (curr < 0) {         cout << -1;         return 0;       }     }     if (last > -1) {       int x = 0, neg = 0;       for (int i = n - 1; i > last; --i) {         if (s[i] ==  ) )           x--;         else if (s[i] ==  ( )           x++;         if (x > 0) {           cout << -1;           return 0;         }       }       x = 0;       for (int i = last + 1; i < n; ++i) {         if (s[i] ==  ) )           x--;         else if (s[i] ==  ( )           x++;         neg = min(neg, x);       }       neg = ans.back() + neg;       if (x > 0 or neg < 0) {         cout << -1;         return 0;       }       ans.pop_back();       ans.push_back(neg + 1);     }     for (int i = 0; i < (int)ans.size(); ++i) {       if (i + 1 == (int)ans.size()) {         cout << ans[i] <<   n ;       } else         cout << 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ball {     float coord;     int mass;     float vel;     short num;   };   bool sort_num(ball a, ball b) { return a.num < b.num; }   bool sort_coord(ball a, ball b) { return a.coord < b.coord; }   void collide(ball &a, ball &b) {     float temp = a.vel;     a.vel = ((a.mass - b.mass) * a.vel + 2 * b.vel * b.mass) / (b.mass + a.mass);     b.vel = ((b.mass - a.mass) * b.vel + 2 * temp * a.mass) / (b.mass + a.mass);   }   void iter(vector<ball> &balls, int size, float &cur_time, int time) {     float col_t = 9999.9;     int col_c = -1;     float temp;     for (int i = 0; i < size - 1; i++) {       temp = (balls[i + 1].coord - balls[i].coord) /              (balls[i].vel - balls[i + 1].vel);       if (temp > 0.0000001 && temp < col_t) {         col_t = temp;         col_c = i;       }     }     if (cur_time + col_t > time || col_c == -1) {       col_t = time - cur_time;       for (int i = 0; i < size; i++) balls[i].coord += balls[i].vel * col_t;       cur_time += col_t;       return;     }     for (int i = 0; i < size; i++) {       balls[i].coord += balls[i].vel * col_t;     }     for (int i = 0; i < size - 1; i++) {       if (fabs(balls[i].coord - balls[i + 1].coord) < 0.0000001) {         collide(balls[i], balls[i + 1]);         i++;       }     }     cur_time += col_t;   }   int main() {     int n, t;     float cur_t = 0.0;     cin >> n >> t;     vector<ball> balls(n);     for (int i = 0; i < n; i++) {       cin >> balls[i].coord >> balls[i].vel >> balls[i].mass;       balls[i].num = i;     }     sort(balls.begin(), balls.end(), sort_coord);     while (cur_t < t) {       iter(balls, n, cur_t, t);     }     sort(balls.begin(), balls.end(), sort_num);     for (int i = 0; i < n; i++) cout << balls[i].coord << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v[10005];   int color[10005];   int flag[10005];   void dfs(int src, int p, int ctr) {     if (src == p) {       return;     }     flag[src] = ctr;     int i;     for (i = 0; i < v[src].size(); i++) {       if (color[v[src][i]] == color[src]) {         if (v[src][i] != p) dfs(v[src][i], src, ctr);       }     }   }   int main(void) {     scanf( %d , &n);     int i;     int x;     for (i = 2; i <= n; i++) {       scanf( %d , &x);       v[i].push_back(x);       v[x].push_back(i);     }     for (i = 1; i <= n; i++) {       scanf( %d , &x);       color[i] = x;     }     int ctr = 0;     for (i = 1; i <= n; i++) {       if (flag[i] == 0) {         ctr++;         dfs(i, -1, -ctr);       }     }     cout << ctr << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int maxar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long maxar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long minar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   int minar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   void inpar(int arr[], int n) {     for (int i = 0; i < n; i++) {       cin >> arr[i];     }   }   void inpar(long long arr[], long long n) {     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }   }   template <typename T>   inline T readInt() {     T n = 0, s = 1;     char p = getchar();     if (p ==  - ) s = -1;     while ((p <  0  || p >  9 ) && p != EOF && p !=  - ) p = getchar();     if (p ==  - ) s = -1, p = getchar();     while (p >=  0  && p <=  9 ) {       n = (n << 3) + (n << 1) + (p -  0 );       p = getchar();     }     return n * s;   }   void solve() {     int n = readInt<int>();     int a[n];     inpar(a, n);     int res = 0;     priority_queue<int> q;     for (int i = 1; i < n; i++) {       q.push(a[i]);     }     while (q.top() >= a[0]) {       res++;       a[0]++;       int temp = q.top();       temp--;       q.pop();       q.push(temp);     }     cout << res;   }   int32_t main() {     int tc;     tc = 1;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000 + 10;   int a[MAXN];   int sum[MAXN];   int cnt[100 + 10];   vector<int> vc;   unordered_map<int, int> mp;   int exist[MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     int D = -1;     bool flag = false;     for (int i = 1; i <= 100; ++i) {       if (cnt[i]) {         vc.push_back(i);         if (D == -1 || cnt[D] < cnt[i]) {           D = i;           flag = false;         } else if (D != -1 && cnt[i] == cnt[D] && i != D) {           flag = true;         }       }     }     if (flag) {       printf( %d n , n);       return 0;     }     sum[0] = 0;     int ans = 0;     for (int x : vc) {       if (x == D) continue;       mp.clear();       exist[0] = 0;       mp[0] = 0;       for (int i = 1; i <= n; ++i) {         if (a[i] == D)           sum[i] = sum[i - 1] + 1;         else if (a[i] == x)           sum[i] = sum[i - 1] - 1;         else           sum[i] = sum[i - 1] + 0;         if (mp.count(sum[i]) == 0) mp[sum[i]] = i;         if (a[i] == D) {           exist[i] = exist[i - 1] + 1;         } else {           exist[i] = exist[i - 1];         }       }       int L = 0;       for (int r = 1; r <= n; ++r) {         if (mp.count(sum[r])) {           int l = mp[sum[r]] + 1;           if (l <= r && exist[r] - exist[l - 1] >= 1) {             L = max(L, r - l + 1);           }         }       }       ans = max(ans, L);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int pc[1 << 10];     for (size_t i = 0; i < (1 << 10); i++) {       int buf = 0;       for (int j = 0; j < 10; j++) {         if ((1 << j) & i) buf++;       }       pc[i] = buf;     }     int n, m;     cin >> n >> m;     map<int, pair<unsigned long long, unsigned long long>> ans;     vector<int> v1(n);     vector<int> v2(m);     for (size_t i = 0; i < n; i++) {       cin >> v1[i];       v1[i] *= 2;     }     for (size_t i = 0; i < m; i++) {       cin >> v2[i];       v2[i] *= 2;     }     for (size_t i = 0; i < n; i++) {       for (size_t j = 0; j < m; j++) {         int buf = (v1[i] + v2[j]) / 2;         ans[buf].first |= (1ULL << i);         ans[buf].second |= (1ULL << j);       }     }     int ansv = 0;     for (auto i = ans.begin(); i != ans.end(); i++) {       for (auto j = i; j != ans.end(); j++) {         long long a1 = i->second.first;         long long a2 = j->second.first;         long long b1 = i->second.second;         long long b2 = j->second.second;         long long buf1 = a1 | a2;         long long buf2 = b1 | b2;         int buf = 0;         while (buf1) {           int buff = buf1 & 1023;           buf1 >>= 10;           buf += pc[buff];         }         while (buf2) {           int buff = buf2 & 1023;           buf2 >>= 10;           buf += pc[buff];         }         ansv = max(ansv, buf);       }     }     cout << ansv;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[105];   int main() {     int s = 0, t = 0;     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (s >= m)         break;       else {         s += a[n - i - 1];         t++;       }     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300 * 1000 + 13;   int n;   long long a[N], b[N];   void solve() {     scanf( %d , &n);     for (int i = 0; i < int(n); ++i) scanf( %lld%lld , &a[i], &b[i]);     long long ans = 0, mn = 1e18;     for (int i = 0; i < int(n); ++i) {       int ni = (i + 1) % n;       long long val = min(a[ni], b[i]);       ans += a[ni] - val;       mn = min(mn, val);     }     ans += mn;     printf( %lld n , ans);   }   int main() {     int T;     scanf( %d , &T);     for (int i = 0; i < int(T); ++i) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     unsigned long long c = 0;     short p;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p;       c += p;     }     cout << setprecision(14) << ((double)c / n);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, m, n, k, a[1100], b[1100][10], count = 0;     cin >> n >> m >> k;     for (i = 0; i <= m; i++) a[i] = 10000000;     for (i = 1; i <= n; i++) {       for (j = 0; j < 2; j++) cin >> b[i][j];       if (a[b[i][0]] > b[i][1]) a[b[i][0]] = b[i][1];     }     for (i = 1; i <= m; i++) count += a[i];     if (count > k)       cout << k << endl;     else       cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T, class U>   using Pa = pair<T, U>;   template <class T>   using vec = vector<T>;   template <class T>   using vvec = vector<vec<T>>;   bool chmax(int &a, int b) {     if (a < b) {       a = b;       return true;     }     return false;   }   vec<string> A = { 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                     1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   int dp[2010][2010] = {};   int pre[2010][2010] = {};   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N, K;     cin >> N >> K;     vec<string> S(N);     for (int i = 0; i < N; i++) cin >> S[i];     int M = 7;     auto calc = [&](string T, int num) {       string B = A[num];       bool ok = true;       int c = 0;       for (int i = 0; i < M; i++) {         if (T[i] ==  1  && B[i] ==  0 ) ok = false;         if (T[i] ==  0  && B[i] ==  1 ) c++;       }       if (!ok)         return -1;       else         return c;     };     for (int i = 0; i <= N; i++)       for (int k = 0; k <= K; k++) dp[i][k] = -1;     dp[0][0] = 0;     for (int i = 0; i < N; i++)       for (int j = 0; j <= K; j++)         if (dp[i][j] != -1) {           for (int n = 0; n < 10; n++) {             int c = calc(S[N - 1 - i], n);             if (c == -1) continue;             if (j + c <= K) {               if (chmax(dp[i + 1][j + c], n)) {                 pre[i + 1][j + c] = j;               }             }           }         }     if (dp[N][K] == -1) {       cout << -1 <<   n ;       return 0;     }     string ans =   ;     int now = K;     for (int i = N - 1; i >= 0; i--) {       char c =  0  + dp[i + 1][now];       ans += c;       now = pre[i + 1][now];     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline unsigned long long rnd() {     return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;   }   const int N = 300005, mod = 998244353;   pair<long long, long long> f[N];   long long dp[N];   int a[N], n, sum;   long long ksm(long long a, int b) {     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;     }     return ans;   }   pair<long long, long long> operator*(long long k,                                        pair<long long, long long> a) {     return make_pair(a.first * k % mod, a.second * k % mod);   }   pair<long long, long long> operator+(pair<long long, long long> a,                                        pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   void ycl() {     f[sum - 1] = make_pair(1, 0);     long long a = ksm(sum, mod - 2), b = ksm(n - 1, mod - 2);     for (int i = (int)(sum - 1); i >= (int)(1); i--) {       f[i - 1] =           -ksm(i, mod - 2) * sum % mod *           ((sum - i) * a % mod * b % mod * f[i + 1] +            ((sum - i) * a % mod * (1 - b) % mod - 1) * f[i] + make_pair(0, 1));     }     pair<long long, long long> c =         b * f[1] + (n - 2) * b % mod * f[0] + make_pair(0, 1);     long long X = (c.second - f[0].second) % mod *                   ksm((f[0].first - c.first) % mod, mod - 2) % mod;     for (int i = (int)(0); i <= (int)(sum); i++)       dp[i] = (f[i].first * X + f[i].second) % mod;   }   int main() {     n = read();     for (int i = (int)(1); i <= (int)(n); i++) sum += (a[i] = read());     ycl();     long long ans = 0;     for (int i = (int)(1); i <= (int)(n); i++) ans += dp[a[i]];     ans = ((ans - (n - 1) * dp[0]) % mod + mod) % mod;     cout << ans * ksm(n, mod - 2) % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> vis(n + 1, 0);       vector<long long> res(n);       vector<long long> v;       int b;       cin >> b;       v.push_back(b);       int cur = 1;       int ok = 1;       vis[v[0]] = 1;       res[0] = v[0];       for (int i = 1, a; i < n; i++) {         cin >> a;         v.push_back(a);         if (!ok) continue;         if (v[i] > v[i - 1]) {           vis[v[i]] = 1;           vis[v[i - 1]] = 1;           res[i] = v[i];           continue;         } else {           for (int j = cur; j < v[i]; j++) {             if (vis[j] == 0) {               vis[j] = 1;               res[i] = j;               cur = j + 1;               break;             }           }           if (res[i] == 0) {             ok = 0;           }         }       }       if (!ok)         cout << -1 << endl;       else {         for (int i = 0; i < res.size(); i++)           if (res[i] == 0)             cout << v[i] <<    ;           else             cout << res[i] <<    ;         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [ ;     int i = 0;     for (typename vector<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [ ;     int i = 0;     for (typename set<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class K, class V>   ostream& operator<<(ostream& os, const map<K, V>& p) {     os <<  [ ;     int i = 0;     for (typename map<K, V>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   string toString(const T& o) {     stringstream ss;     ss << o;     string ret;     getline(ss, ret);     return ret;   }   template <class T>   vector<T> subv(const vector<T>& v, int from, int to) {     return vector<T>(v.begin() + min(max(0, from), (int)v.size()),                      v.begin() + min(max(0, to), (int)v.size()));   }   pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator*(const int& a, const pair<int, int>& b) {     return make_pair(a * b.first, a * b.second);   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  a na nb nb n ;     } else if (n == 2) {       cout <<  aa nbb ncc ndd n ;     } else {       if (n % 2 == 0) {         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  aa  :  bb );         cout << endl;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  aa  :  bb );         cout << endl;         cout <<  e ;         for (int i = 0; i < n / 2 - 1; ++i) cout << (i % 2 == 0 ?  cc  :  dd );         cout <<  e  << endl;         cout <<  e ;         for (int i = 0; i < n / 2 - 1; ++i) cout << (i % 2 != 0 ?  cc  :  dd );         cout <<  e  << endl;       } else {         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  aa  :  bb );         cout <<  e  << endl;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  aa  :  bb );         cout <<  e  << endl;         cout <<  e ;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  cc  :  dd );         cout << endl;         cout <<  e ;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  cc  :  dd );         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n);       int itr = 1;       for (int& x : v) {         cin >> x;       }       set<int> bag{0}, tmp;       map<int, vector<int>> pep;       for (int i = 0; i < n && bag.size() <= k; i++) {         tmp = bag;         for (auto x : tmp) {           if (bag.find(x + v[i]) == bag.end()) {             bag.insert(x + v[i]);             pep[x + v[i]] = pep[x];             pep[x + v[i]].push_back(v[i]);           }           if (bag.size() > k) break;         }       }       pep.erase(pep.begin());       for (auto& it : pep) {         cout << it.second.size() <<    ;         for (auto& x : it.second) {           cout << x <<    ;         }         cout <<   n ;       }     }     cerr <<  processor time:   << clock() / (double)CLOCKS_PER_SEC <<  s     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[1000005];   int ar[1000005];   void solve() {     int n = (int)strlen(str + 1), i, j, ans = 0;     memset(ar, 0, sizeof(ar));     str[0] =  0 ;     for (i = n; i >= 0; i--) {       if (str[i] ==  1 ) {         j = i;         while (str[j] ==  1 ) --j;         if (i - j > 1)           ar[i] = -1, ar[j] = 1, str[j] =  1 ;         else {           int k;           for (k = -~j; k <= i; k++) ar[k] = 1;         }         i = -~j;       }     }     for (i = 0; i <= n; i++)       if (ar[i]) ans++;     printf( %d n , ans);     for (i = 0; i <= n && ans; i++) {       if (ar[i]) {         putchar(~ar[i] ?  +  :  - ), printf( 2^%d n , n - i);         --ans;       }     }   }   int main(void) {     while (~scanf( %s , str + 1)) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     reverse(t.begin(), t.end());     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


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


#include <bits/stdc++.h>   using namespace std;   int A[26];   int main() {     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; i++) s[i] = tolower(s[i]);     for (int i = 0; i < n; i++) {       if (!A[s[i] -  a ]) {         A[s[i] -  a ] = 1;         ++cnt;       }     }     if (cnt == 26)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, gn1 = 0, gj1 = 0, gn2 = 0, gj2 = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x % 2 == 0)         gn1++;       else         gj1++;     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       if (x % 2 == 0)         gn2++;       else         gj2++;     }     cout << min(gj1, gn2) + min(gj2, gn1) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( universal.in );   ofstream fout(  );   int n, m;   set<int> on;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int aux;       cin >> aux;       for (int j = 1, bb; j <= aux; ++j) {         cin >> bb;         on.insert(bb);       }       if (on.size() == m) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int p, i, j;     scanf( %d , &p);     int n = 1 << (p + 1);     vector<int> a(n);     for (i = 2; i < n; i++) scanf( %d , &a[i]);     vector<int> up(n), mx(n);     for (i = 1; i < n; i++) {       int sum = 0;       for (j = i; j > 1; j /= 2) sum += a[j];       up[i] = sum;     }     int maxVal = *max_element(up.begin(), up.end());     for (i = n / 2; i < n; i++) {       mx[i] += maxVal - up[i];     }     for (i = n - 1; i > 1; i--) {       int c = min(mx[i], mx[i ^ 1]);       mx[i] -= c;       mx[i ^ 1] -= c;       mx[i / 2] += c;     }     printf( %d n , accumulate(mx.begin(), mx.end(), 0));   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long n, k;   long long POW(long long a, long long n) {     if (!n) return 1;     long long ans = 1;     while (n) {       if (n & 1) ans = ans * a % mod;       n >>= 1;       a = a * a % mod;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     if (!n) return cout << 0, 0;     n %= mod;     cout << (POW(2, k + 1) * n % mod - POW(2, k) % mod + 1 + mod * mod) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long check, tn, tm, maxn;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long d = exgcd(b, a % b, x, y);     long long z = x;     x = y;     y = z - y * (a / b);     return d;   }   long long solve(long long x, long long y) {     long long c = x + y, dx, dy;     long long d = exgcd(tn, tm, dx, dy);     if (c % d) return maxn + 1;     long long mod = tm / d;     dx *= c / d;     if (mod < 0) mod = -mod;     dx = (dx % mod + mod) % mod;     long long ans = tn * dx - x;     if (ans < 0 || ans > maxn) return maxn + 1;     return ans;   }   int main() {     long long n, m, k, x, y;     cin >> n >> m >> k;     maxn = n * m / gcd(n, m);     tn = n << 1, tm = -(m << 1);     for (int i = 1; i <= k; ++i) {       cin >> x >> y;       long long ans = maxn + 1;       ans = min(ans, solve(x, y));       ans = min(ans, solve(x, -y));       ans = min(ans, solve(-x, y));       ans = min(ans, solve(-x, -y));       if (ans == maxn + 1)         cout << -1 << endl;       else         cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5 + 10;   inline long long po(long long a, long long p, long long mod) {     long long r = 1;     for (; p; p >>= 1, a = a * a % mod)       if (p & 1) r = r * a % mod;     return r;   }   const long long mod1 = 1e9 + 7;   const long long mod2 = 1e9 + 9;   const long long bas = 1e9 + 3;   int n;   int m;   long long a[N];   long long b[N];   long long pa1;   long long pa2;   long long sa1;   long long sa2;   long long pb1;   long long pb2;   long long sb1;   long long sb2;   long long mi1[N];   long long mi2[N];   long long imi1[N];   long long imi2[N];   long long ans[N];   int tp;   long long inv1;   long long inv2;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + n + 1);     for (int i = 1, j = n; i <= n; i++, j--) b[j] = a[i];     mi1[0] = 1;     for (int i = 1; i <= n; i++) (mi1[i] = mi1[i - 1] * bas) %= mod1;     mi2[0] = 1;     for (int i = 1; i <= n; i++) (mi2[i] = mi2[i - 1] * bas) %= mod2;     for (int i = n; i >= 1; i--)       pa1 = (pa1 * bas + a[i]) % mod1, pa2 = (pa2 * bas + a[i]) % mod2,       pb1 = (pb1 * bas + b[i]) % mod1, pb2 = (pb2 * bas + b[i]) % mod2;     inv1 = po(po(bas, n, mod1) + mod1 - 1, mod1 - 2, mod1);     inv2 = po(po(bas, n, mod2) + mod2 - 1, mod2 - 2, mod2);     for (int i = n; i >= 0; i--) {       long long t1 = ((pa1 + pb1) + (sa1 + mod1 - sb1)) % mod1;       long long x1 = (bas - 1) * t1 % mod1 * inv1 % mod1;       long long t2 = ((pa2 + pb2) + (sa2 + mod2 - sb2)) % mod2;       long long x2 = (bas - 1) * t2 % mod2 * inv2 % mod2;       if (x1 == x2 && x1 < m) ans[++tp] = x1;       pa1 = (pa1 + mod1 - a[i] * mi1[i - 1] % mod1) % mod1;       pa2 = (pa2 + mod2 - a[i] * mi2[i - 1] % mod2) % mod2;       sa1 = (sa1 + a[i] * mi1[i - 1]) % mod1;       sa2 = (sa2 + a[i] * mi2[i - 1]) % mod2;       pb1 = (pb1 + mod1 - a[i]) * 750000005 % mod1;       pb2 = (pb2 + mod2 - a[i]) * 166666668 % mod2;       sb1 = (sb1 * 750000005 + mi1[n - 1] * (m - a[i])) % mod1;       sb2 = (sb2 * 166666668 + mi2[n - 1] * (m - a[i])) % mod2;     }     printf( %d n , tp);     sort(ans + 1, ans + tp + 1);     for (int i = 1; i <= tp; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   long long dx[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long dy[] = {1, 1, 0, -1, -1, -1, 0, 1};   struct BipartiteMatcher {     vector<vector<long long>> G;     vector<long long> L, R, Viz;     BipartiteMatcher(long long n, long long m)         : G(n), L(n, -1), R(m, -1), Viz(n) {}     void AddEdge(long long a, long long b) { G[a].push_back(b); }     bool Match(long long node) {       if (Viz[node]) return false;       Viz[node] = true;       for (auto vec : G[node]) {         if (R[vec] == -1) {           L[node] = vec;           R[vec] = node;           return true;         }       }       for (auto vec : G[node]) {         if (Match(R[vec])) {           L[node] = vec;           R[vec] = node;           return true;         }       }       return false;     }     long long Solve() {       long long ok = true;       while (ok--) {         fill(Viz.begin(), Viz.end(), 0);         for (long long i = 0; i < (long long)L.size(); ++i)           if (L[i] == -1) ok |= Match(i);       }       long long ret = 0;       for (long long i = 0; i < L.size(); ++i) ret += (L[i] != -1);       return ret;     }   };   bool comp(const pair<long long, pair<long long, long long>> &a,             const pair<long long, pair<long long, long long>> &b) {     return a.second.second < b.second.second;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) {       long long n, m;       cin >> n >> m;       vector<pair<long long, pair<long long, long long>>> roads;       for (long long i = 0; i < m; ++i) {         long long u, v, w;         cin >> u >> v >> w;         --u;         --v;         roads.push_back({u, {v, w}});       }       sort(roads.begin(), roads.end(), comp);       long long lo = 0, hi = 1e9 + 1;       while (lo < hi) {         long long md = (lo + hi) >> 1;         BipartiteMatcher graph(n, n);         for (auto it : roads) {           if (it.second.second <= md)             graph.AddEdge(it.first, it.second.first);           else             break;         }         long long cnt = graph.Solve();         if (cnt < n) {           lo = md + 1;         } else           hi = md;       }       if (hi == (1e9 + 1))         cout << -1;       else         cout << hi;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define fi first   #define se second   #define fill0(a) memset(a,0,sizeof(a))   #define fill1(a) memset(a,-1,sizeof(a))   #define fillbig(a) memset(a,63,sizeof(a))   #define pb push_back   #define ppb pop_back   #define mp make_pair   #define mt make_tuple   #define eprintf(...) fprintf(stderr,__VA_ARGS__)   template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;}   template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;}   typedef pair<int,int> pii;   typedef long long ll;   typedef unsigned int u32;   typedef unsigned long long u64;   typedef long double ld;   namespace fastio{    #define FILE_SIZE 1<<23    char rbuf[FILE_SIZE],*p1=rbuf,*p2=rbuf,wbuf[FILE_SIZE],*p3=wbuf;    inline char getc(){return p1==p2&&(p2=(p1=rbuf)+fread(rbuf,1,FILE_SIZE,stdin),p1==p2)?-1:*p1++;}    inline void putc(char x){(*p3++=x);}    template<typename T> void read(T &x){     x=0;char c=getchar();T neg=0;     while(!isdigit(c)) neg|=!(c^ - ),c=getchar();     while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();     if(neg) x=(~x)+1;    }    template<typename T> void recursive_print(T x){return (!x)?void():(recursive_print(x/10),putc(x%10^48),void());}    template<typename T> void print(T x){(!x)&&(putc( 0 ),0);(x<0)&&(putc( - ),x=~x+1);recursive_print(x);}    template<typename T> void print(T x,char c){print(x);putc(c);}    void print_final(){fwrite(wbuf,1,p3-wbuf,stdout);}   }   const int MAXN=2e5;   const int MAXV=1e6;   int n,qu,s,d,a[MAXN+5],f[MAXN+5],pos[MAXV+5];   set<int> cmp[MAXN+5];int cmp_cnt=0;   int find(int x){return (!f[x])?x:f[x]=find(f[x]);}   bool merge(int x,int y){    x=find(x);y=find(y);if(x==y) return 0;    if(cmp[x].size()<cmp[y].size()) swap(x,y);    for(int v:cmp[y]) cmp[x].insert(v);    cmp[y].clear();f[y]=x;cmp_cnt--;return 1;   }   set<int> st;   int hd[MAXN+5],to[MAXN*2+5],nxt[MAXN*2+5],val[MAXN*2+5],ec=0;   void adde(int u,int v,int w){/*printf( %d %d %d n ,u,v,w);*/to[++ec]=v;val[ec]=w;nxt[ec]=hd[u];hd[u]=ec;}   int mx[MAXN+5];   void dfs(int x,int f){    for(int e=hd[x];e;e=nxt[e]){     int y=to[e],z=val[e];if(y==f) continue;     mx[y]=max(mx[x],z);dfs(y,x);    }   }   int main(){    scanf( %d%d%d%d ,&n,&qu,&s,&d);cmp_cnt=n;    for(int i=1;i<=n;i++){     scanf( %d ,&a[i]);st.insert(a[i]);     pos[a[i]]=i;cmp[i].insert(i);    }    while(cmp_cnt>1){     vector<pair<int,pii> > ed;     for(int i=1;i<=n;i++) if(!cmp[i].empty()){      for(int x:cmp[i]) st.erase(st.find(a[x]));      for(int x:cmp[i]){       for(int j=-1,v=-d;j<=1;j++,v=j*d) if(j!=0){        auto it=st.lower_bound(a[x]+v);        if(it!=st.end()) ed.pb(mp(abs(abs(a[x]-(*it))-d),mp(x,pos[*it])));        if(it!=st.begin()){--it;ed.pb(mp(abs(abs(a[x]-(*it))-d),mp(x,pos[*it])));}       }      }      for(int x:cmp[i]) st.insert(a[x]);     } sort(ed.begin(),ed.end());     for(int i=0;i<ed.size();i++){      int w=ed[i].fi,x=ed[i].se.fi,y=ed[i].se.se;      if(merge(x,y)) adde(x,y,w),adde(y,x,w);     }    } dfs(s,0);    while(qu--){     int x,k;scanf( %d%d ,&x,&k);     printf( %s n ,(mx[x]<=k)? Yes : No );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct fenwick_tree {     int tree_n = 0;     T tree_sum = 0;     vector<T> tree;     fenwick_tree(int n = -1) {       if (n >= 0) init(n);     }     void init(int n) {       tree_n = n;       tree_sum = 0;       tree.assign(tree_n + 1, 0);     }     template <typename T_array>     void build(const T_array &initial) {       assert((int)initial.size() == tree_n);       tree_sum = 0;       for (int i = 1; i <= tree_n; i++) {         tree[i] = initial[i - 1];         tree_sum += initial[i - 1];         for (int k = (i & -i) >> 1; k > 0; k >>= 1) tree[i] += tree[i - k];       }     }     void update(int index, const T &change) {       assert(0 <= index && index < tree_n);       tree_sum += change;       for (int i = index + 1; i <= tree_n; i += i & -i) tree[i] += change;     }     T query(int count) const {       assert(count <= tree_n);       T sum = 0;       for (int i = count; i > 0; i -= i & -i) sum += tree[i];       return sum;     }     T query_suffix(int start) const { return tree_sum - query(start); }     T query(int a, int b) const { return query(b) - query(a); }     T get(int a) const {       assert(0 <= a && a < tree_n);       int above = a + 1;       T sum = tree[above];       above -= above & -above;       while (a != above) {         sum -= tree[a];         a -= a & -a;       }       return sum;     }     int find_last_prefix(T sum) const {       if (sum < 0) return -1;       int prefix = 0;       for (int k = 31 - __builtin_clz(tree_n); k >= 0; k--)         if (prefix + (1 << k) <= tree_n && tree[prefix + (1 << k)] <= sum) {           prefix += 1 << k;           sum -= tree[prefix];         }       return prefix;     }   };   const int MASK = (1 << 30) - 1;   string S;   vector<pair<int, int>> W_stack;   fenwick_tree<int> suffixes;   long long current = 0;   vector<int> fail = {0};   int kmp_len = 0;   vector<int> link;   int query_stack_value(int index) {     assert(!W_stack.empty());     int low = 0, high = W_stack.size() - 1;     while (low < high) {       int mid = (low + high + 1) / 2;       if (W_stack[mid].second <= index)         low = mid;       else         high = mid - 1;     }     return W_stack[low].first;   }   void add_to_stack(int index, int w) {     while (!W_stack.empty() && w <= W_stack.back().first) {       int value = W_stack.back().first;       int prev_index = W_stack.back().second;       current -= (long long)suffixes.query(prev_index, index) * (value - w);       index = prev_index;       W_stack.pop_back();     }     W_stack.emplace_back(w, index);   }   void add_char(char c) {     S += c;     if (S.size() > 1) {       while (kmp_len > 0 && S[kmp_len] != S.back()) kmp_len = fail[kmp_len];       if (S[kmp_len] == S.back()) kmp_len++;     }     fail.push_back(kmp_len);     int index = S.size() - 1;     if (index > 0 && S[index] == S[fail[index]])       link.push_back(link[fail[index]]);     else       link.push_back(fail[index]);   }   void remove_suffixes(int len, char c) {     while (len > 0) {       if (len < (int)S.size() && S[len] != c) {         int remove = S.size() - len;         current -= query_stack_value(remove);         suffixes.update(remove, -1);       }       if (len < (int)S.size() && S[len] == c)         len = link[len];       else         len = fail[len];     }   }   int main() {     int N;     scanf( %d , &N);     suffixes.init(N);     const long long LOW_BASE = 1e12;     long long ans_high = 0, ans_low = 0;     long long ans_mask = 0, ans26 = 0;     for (int i = 0; i < N; i++) {       char c;       int w;       scanf(  %c %d , &c, &w);       c =  a  + (c -  a  + ans26) % 26;       w ^= ans_mask;       remove_suffixes(i, c);       add_char(c);       add_to_stack(i, w);       if (c == S[0]) {         suffixes.update(i, +1);         current += w;       }       ans_low += current % LOW_BASE;       ans_high += current / LOW_BASE + ans_low / LOW_BASE;       ans_low %= LOW_BASE;       ans_mask = (ans_mask + current) & MASK;       ans26 = (ans26 + current) % 26;       if (ans_high != 0)         printf( %lld%012lld n , ans_high, ans_low);       else         printf( %lld n , ans_low);     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[105][2005];   int main() {     memset(dp, -1, sizeof(dp));     int v1, v2, t, d;     cin >> v1 >> v2 >> t >> d;     dp[1][v1] = v1;     for (int i = 1; i < t; i++)       for (int j = 0; j < 2005; j++)         if (dp[i][j] != -1)           for (int k = -d; k <= d; k++)             if (j + k >= 0)               dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + j + k);     if (dp[t][v2] == -1)       cout <<  0 n ;     else       cout << dp[t][v2] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807ll;   const long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647,                   nmax = 300005;   struct trip {     long long a, b, c;   };   long long n, m, s[nmax];   vector<pair<long long, long long> > neg, poz;   vector<trip> sol;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (long long i = 1; i <= m; ++i) {       long long x, y, w;       cin >> x >> y >> w;       s[x] -= w;       s[y] += w;     }     for (long long i = 1; i <= n; ++i) {       if (s[i] > 0) poz.push_back({i, s[i]});       if (s[i] < 0) neg.push_back({i, -s[i]});     }     while (poz.size() && neg.size()) {       long long x = min(poz.back().second, neg.back().second);       long long a = neg.back().first, b = poz.back().first;       sol.push_back({a, b, x});       poz.back().second -= x;       neg.back().second -= x;       if (poz.back().second == 0) poz.pop_back();       if (neg.back().second == 0) neg.pop_back();     }     cout << sol.size() <<   n ;     for (auto x : sol) cout << x.a <<     << x.b <<     << x.c <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vll = vector<ll>;   using vii = vector<int>;   using pii = pair<int, int>;   template <typename T = vii>   using vec = vector<T>;   const ll INF = 1e18, MOD = 998244353;   const int MAX = 1e6;   ll ft[MAX + 1];   void cf() {     ft[0] = 1;     for (int i = 1; i <= MAX; i++) {       ft[i] = (i * ft[i - 1]) % MOD;     }   }   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     cf();     int n;     cin >> n;     unordered_map<int, int> cnt;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       u--, v--;       cnt[u]++;       cnt[v]++;     }     ll res = 1;     for (auto p : cnt) {       (res *= ft[p.second]) %= MOD;     }     cout << (n * res) % MOD <<   n ;   }


#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (n % 2 == 0)       printf( %d n , n / 2 * m);     else       printf( %d n , n / 2 * m + m / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long T, n, tempur;   int t[105], l[105], h[105];   int main() {     cin >> T;     while (T--) {       memset(t, 0, sizeof t);       memset(h, 0, sizeof h);       memset(l, 0, sizeof l);       cin >> n >> tempur;       int maxn = tempur, minn = tempur;       for (int i = 1; i <= n; i++) {         cin >> t[i] >> l[i] >> h[i];       }       int f = 0;       for (int i = 1; i <= n; i++) {         maxn += t[i] - t[i - 1];         minn -= t[i] - t[i - 1];         if ((h[i] >= minn && l[i] <= maxn) || (h[i] <= maxn && l[i] >= minn)) {           maxn = min(maxn, h[i]);           minn = max(minn, l[i]);         } else {           f = 1;           break;         }       }       if (!f)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long N, B;     cin >> N >> B;     vector<long long> res(N, -1);     queue<pair<long long, long long> > Q;     long long endTime = -1;     for (long long i = 0; i < N; i++) {       long long t, d;       cin >> t >> d;       while (endTime <= t) {         if (Q.size()) {           res[Q.front().second] = endTime = endTime + Q.front().first;           Q.pop();         } else {           endTime = t;           break;         }       }       if (Q.size() < B) {         Q.push({d, i});       }     }     while (Q.size()) {       res[Q.front().second] = endTime = endTime + Q.front().first;       Q.pop();     }     for (long long i = 0; i < N; i++) cout << res[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using namespace std;   const int N = 2002, NN = 502, mod = 1e9 + 7, mod1 = 1e9 + 9, Base = 317,             Base1 = 371;   int n, K, pw[NN], pw1[NN], lcp[N], mn[N][11], id[N];   string s[N];   struct Hash {     vector<pair<int, int> > hs;     Hash() {}     Hash(const string &s) : hs(((int)(s).size()) + 1, {0, 0}) {       for (int i = (1); i <= (((int)(s).size())); ++i)         hs[i] = {(hs[i - 1].first * 1LL * Base + s[i - 1]) % mod,                  (hs[i - 1].second * 1LL * Base1 + s[i - 1]) % mod1};     }     pair<int, int> query(int l, int r) {       pair<int, int> h = {           hs[r].first - hs[l - 1].first * 1LL * pw[r - l + 1] % mod,           hs[r].second - hs[l - 1].second * 1LL * pw1[r - l + 1] % mod1};       if (h.first < 0) h.first += mod;       if (h.second < 0) h.second += mod;       return h;     }   } hs[N];   int getLcp(const int &A, const int &B) {     int l = 1, r = min(((int)(s[A]).size()), ((int)(s[B]).size()));     while (l <= r) {       int m = (l + r) >> 1;       if (hs[A].query(1, m) == hs[B].query(1, m))         l = m + 1;       else         r = m - 1;     }     return r;   }   bool cmp(const int &A, const int &B) {     int r = getLcp(A, B);     if (r == ((int)(s[B]).size())) return 0;     if (r == ((int)(s[A]).size())) return 1;     return s[A][r] < s[B][r];   }   int queryLcp(int l, int r) {     int k = 31 - __builtin_clz(r - l + 1);     return min(mn[l][k], mn[r - (1 << k) + 1][k]);   }   vector<int> solve(int l, int r) {     if (l == r) return vector<int>(2, 0);     vector<int> dp(r - l + 2, 0);     int mid = l + 1;     for (int i = (l + 2); i <= (r); ++i)       if (lcp[i] < lcp[mid]) mid = i;     vector<int> dpLeft = solve(l, mid - 1), dpRight = solve(mid, r);     for (int i = (0); i <= (mid - l); ++i)       for (int j = (0); j <= (r - mid + 1); ++j)         dp[i + j] = max(dp[i + j], dpLeft[i] + dpRight[j] + i * j * lcp[mid]);     return dp;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> K;     for (int i = (1); i <= (n); ++i) cin >> s[i], id[i] = i, hs[i] = Hash(s[i]);     sort(id + 1, id + 1 + n, cmp);     for (int i = (2); i <= (n); ++i) lcp[i] = getLcp(id[i - 1], id[i]);     cout << solve(1, n)[K];     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 5, mod = 1e9 + 7, inf = 1e18;   long long n, q, a[maxn], mx[2ll][maxn];   pair<long long, long long> dp[2ll][maxn];   void cal_mx0(long long x) {     long long l = n - 1ll, sum = a[n];     for (long long i = n; i > 0; i--) {       if (l == 0) {         mx[0][i] = 1;         sum -= a[i];         continue;       }       while ((l > 0) && (sum + a[l] <= x)) {         sum += a[l];         l--;       }       mx[0][i] = l + 1ll;       sum -= a[i];     }   }   void cal_mx1(long long x) {     long long r = 2ll, sum = a[1];     for (long long i = 1; i <= n; i++) {       if (r == n + 1ll) {         mx[1][i] = n;         sum -= a[i];         continue;       }       while ((r <= n) && (sum + a[r] <= x)) {         sum += a[r];         r++;       }       mx[1][i] = r - 1ll;       sum -= a[i];     }   }   void cal_dp0() {     long long sum = 0;     for (long long i = 1; i <= n; i++) {       sum += a[i];       if (mx[0][i] == 1) {         dp[0][i] = {1, sum};         continue;       }       dp[0][i].first = dp[0][mx[0][i] - 1ll].first + 1ll;       dp[0][i].second = dp[0][mx[0][i] - 1ll].second;     }   }   void cal_dp1() {     long long sum = 0;     for (long long i = n; i > 0; i--) {       sum += a[i];       if (mx[1][i] == n) {         dp[1][i] = {1, sum};         continue;       }       dp[1][i].first = dp[1][mx[1][i] + 1ll].first + 1ll;       dp[1][i].second = dp[1][mx[1][i] + 1ll].second;     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> q;     long long second = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       second += a[i];     }     a[n + 1ll] = inf;     a[0] = inf;     while (q--) {       long long x;       cin >> x;       if (x >= second) {         cout << 1 <<   n ;         continue;       }       cal_mx0(x);       cal_mx1(x);       cal_dp0();       cal_dp1();       long long ans = min(dp[0][n].first, dp[1][1].first);       for (long long i = 1; i < n; i++) {         long long z = 0;         if ((dp[0][i].second + dp[1][i + 1ll].second) <= x) z = 1ll;         ans = min(ans, dp[0][i].first + dp[1ll][i + 1ll].first - z);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char a[2 * n - 1][2 * n - 1];     int v = 0, k = n;     for (int i = 0; i < n; i++, k--, v++) {       for (int j = 0; j < k; j++) printf(    );       for (int j = 0; j < v; j++) printf( %d  , j);       printf( %d , v);       for (int j = v - 1; j >= 0; j--) printf(  %d , j);       printf(  n );     }     for (int i = 0; i < n; i++) printf( %d  , i);     printf( %d , n);     for (int i = n - 1; i >= 0; i--) printf(  %d , i);     for (int i = 0, k = 1, v = n - 1; i < n; i++, k++, v--) {       printf(  n );       for (int j = 0; j < k; j++) printf(    );       for (int j = 0; j < v; j++) printf( %d  , j);       printf( %d , v);       for (int j = v - 1; j >= 0; j--) printf(  %d , j);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, m, k, ans = 0;     cin >> n >> m >> k;     vector<int> a(n + 1), b(n + 1), c(k + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= k; i++) cin >> c[i];     for (int i = 1; i <= k; i++) {       int curp = a[c[i]], curid = b[c[i]];       for (int j = 1; j <= n; j++) {         if (b[j] == curid && curp < a[j]) {           ans++;           a[c[i]] = 0;           b[c[i]] = 0;           break;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 205;   const int infint = 1e9;   const long long inf = 1e18;   const int K = 26;   long long n, l, a[MAXN], nxt[MAXN][K], used[MAXN];   string s[MAXN];   struct Vertex {     int next[K];     bool leaf = false;     long long val = 0;     int p = -1;     char pch;     int f = -1;     int go[K];     Vertex(int p = -1, char ch =  $ ) : p(p), pch(ch) {       memset(next, -1, sizeof next);       memset(go, -1, sizeof go);     }   };   vector<Vertex> t(1);   void add_string(string const &s, int value) {     int v = 0;     for (int i = 0; i < s.size(); i++) {       int c = s[i] -  a ;       if (t[v].next[c] == -1) {         t[v].next[c] = t.size();         Vertex child = Vertex(v, s[i]);         t.push_back(child);       }       v = t[v].next[c];     }     t[v].leaf = 1;     t[v].val += value;   }   int go(int v, char ch);   int get_link(int v) {     if (t[v].f == -1) {       if (v == 0 || t[v].p == 0)         t[v].f = 0;       else         t[v].f = go(get_link(t[v].p), t[v].pch);     }     return t[v].f;   }   int go(int v, char ch) {     int c = ch -  a ;     if (t[v].go[c] == -1) {       if (t[v].next[c] != -1)         t[v].go[c] = t[v].next[c];       else         t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);     }     return t[v].go[c];   }   void upd(int c) {     if (used[c]) return;     used[c] = 1;     if (c == 0) return;     upd(t[c].f);     t[c].val += t[t[c].f].val;   }   struct matrix {     long long a[MAXN][MAXN], n, m;     matrix(long long Cn, long long Cm) {       n = Cn, m = Cm;       for (long long i = 0; i < n; i++)         for (long long j = 0; j < m; j++) a[i][j] = -infint;     }     long long *operator[](const long long &i) { return a[i]; }     matrix Identity(const long long &n) {       matrix c(n, m);       return c;     }     inline matrix operator*(matrix &b) {       matrix c(n, b.m);       for (int i = 0; i < n; i++)         for (int j = 0; j < b.m; j++)           for (int k = 0; k < m; k++)             if (a[i][k] >= 0 && b[k][j] >= 0)               c[i][j] = max(c[i][j], (long long)a[i][k] + (long long)b[k][j]);       return c;     }     inline matrix operator+(matrix b) {       matrix c(n, m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) c[i][j] = (a[i][j] + b[i][j]) % MOD;       return c;     }     matrix operator^(const long long &c) {       if (c == 0) return Identity(n);       if (c == 1) return *this;       matrix tmp = *this ^ (c >> 1);       tmp = tmp * tmp;       if (c & 1) tmp = tmp * *this;       return tmp;     }     void inline print() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cout << a[i][j] <<    ;         cout <<   n ;       }     }   };   matrix cost(MAXN, MAXN);   matrix base(1, MAXN);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> l;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) add_string(s[i], a[i]);     for (int i = 0; i < t.size(); i++)       for (int j = 0; j < K; j++) nxt[i][j] = go(i, (char)(j +  a ));     for (int i = 1; i < t.size(); i++) upd(i);     cost.n = cost.m = t.size();     for (int i = 0; i < t.size(); i++)       for (int j = 0; j < t.size(); j++) cost[i][j] = -inf;     for (int i = 0; i < t.size(); i++)       for (int j = 0; j < K; j++) cost[i][nxt[i][j]] = t[nxt[i][j]].val;     cost = cost ^ l;     base.n = 1;     base.m = t.size();     base[0][0] = 0;     for (int i = 1; i < t.size(); i++) base[0][i] = -inf;     base = base * cost;     long long ans = 0;     for (int i = 0; i < t.size(); i++) ans = max(ans, base[0][i]);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int low(int a) {     if (a == 1) {       return 0;     }     return 1;   }   int main() {     int t;     cin >> t;     string s;     cin >> s;     stack<char> st;     st.push(s[0]);     int c = 0;     for (int i = 1; i < t; i++) {       if (st.top() == s[i]) {         c++;       } else {         st.push(s[i]);       }     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int from[N], to[N];   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<pair<int, int> > mst;     set<pair<int, int> > freeEdges;     for (int i = 0; i < (int)(m); ++i) {       int w, isMST;       cin >> w >> isMST;       if (isMST) {         mst.push_back(make_pair(w, i));       } else {         freeEdges.insert(make_pair(w, i));       }     }     sort(mst.begin(), mst.end());     for (int i = 0; i < (int)(n - 1); ++i) {       int id = mst[i].second;       from[id] = i;       to[id] = i + 1;     }     int u = 0, v = 2;     for (int i = 0; i < (int)(m - n + 1); ++i) {       int cur = mst[v - 1].first;       auto it = freeEdges.lower_bound(make_pair(cur, -1));       if (freeEdges.empty() || it == freeEdges.end()) {         cout << -1;         return 0;       }       int id = it->second;       from[id] = u;       to[id] = v;       --u;       if (u == -1) {         u = v - 1;         ++v;       }       freeEdges.erase(it);     }     for (int i = 0; i < (int)(m); ++i) {       cout << 1 + from[i] <<     << 1 + to[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, k;     scanf( %d , &t);     while (t-- && scanf( %d %d , &n, &k)) {       if ((k & 1) == (n & 1) && (long long)(k)*k <= n && n >= k)         printf( YES n );       else         printf( NO n );     }     return 0;   }