#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long INF = 1e14;   long long gcd(long long a, long long b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     if ((n * m * 2) % k != 0 || k == 1) {       cout <<  NO ;       return 0;     }     cout <<  YES           <<   n ;     if (k % 2 == 0) {       k = k / 2;       long long g = gcd(n, k);       n = n / g;       k = k / g;       g = gcd(m, k);       m = m / g;       k = k / g;       cout << 0 <<     << 0 <<   n ;       cout << n <<     << 0 <<   n ;       cout << 0 <<     << m <<   n ;       return 0;     }     long long g = gcd(n, k);     if (g > 1) {       n = (n / g) * 2;       k = k / g;       g = gcd(m, k);       m = m / g;       k = k / g;     } else {       n = (n / g);       k = k / g;       g = gcd(m, k);       m = (m / g) * 2;       k = k / g;     }     cout << 0 <<     << 0 <<   n ;     cout << n <<     << 0 <<   n ;     cout << 0 <<     << m <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_NUMBER = 105;   int flower[MAX_NUMBER], odd[MAX_NUMBER], even[MAX_NUMBER];   int number;   int main() {     scanf( %d , &number);     int sums = 0;     int odd_number = 0, even_number = 0;     for (int i = 1; i <= number; i++) {       scanf( %d , &flower[i]);       sums = sums + flower[i];       if (flower[i] % 2 == 1) {         odd[odd_number++] = flower[i];       } else {         even[even_number++] = flower[i];       }     }     if (odd_number == 0) {       printf( 0 n );     } else {       if (odd_number % 2 == 1) {         printf( %d n , sums);       } else {         sort(odd, odd + odd_number);         printf( %d n , sums - odd[0]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[2005], b[2005];   vector<pair<long long, pair<int, int> > > bb;   long long diff = 0L;   bool good(long long x, int place) {     if (place >= bb.size())       return false;     else       return diff + 2 * (bb[place].first - x) <= 0;   }   int find_(long long x) {     int place = -1, jump = bb.size();     while (jump > 0) {       if (good(x, place + jump)) place += jump;       jump /= 2;     }     while (good(x, place + 1)) place++;     return place;   }   bool sorter(pair<long long, pair<int, int> > a,               pair<long long, pair<int, int> > b) {     return a.first < b.first;   }   int main() {     int n;     scanf( %i , &n);     for (int e = 0; e < n; e++) scanf( %I64d , &a[e]);     int m;     scanf( %i , &m);     for (int e = 0; e < m; e++) scanf( %I64d , &b[e]);     for (int e = 0; e < n; e++) diff += a[e];     for (int e = 0; e < m; e++) diff -= b[e];     long long acc = diff;     vector<pair<int, int> > rr;     for (int e = 0; e < n; e++) {       for (int ee = 0; ee < m; ee++) {         if (abs(diff + 2 * (b[ee] - a[e])) < abs(acc)) {           acc = diff + 2 * (b[ee] - a[e]);           rr.clear();           rr.push_back(make_pair(e, ee));         }       }     }     for (int e = 0; e < m; e++) {       for (int ee = e + 1; ee < m; ee++) {         bb.push_back(make_pair(b[e] + b[ee], make_pair(e, ee)));       }     }     sort(bb.begin(), bb.end(), sorter);     for (int e = 0; e < n; e++) {       for (int ee = e + 1; ee < n; ee++) {         long long itm = a[e] + a[ee];         int pl = find_(itm);         if (pl < (int)bb.size() - 1) {           if (abs(diff + 2 * (bb[pl + 1].first - itm)) < abs(acc)) {             acc = diff + 2 * (bb[pl + 1].first - itm);             rr.clear();             rr.push_back(make_pair(e, bb[pl + 1].second.first));             rr.push_back(make_pair(ee, bb[pl + 1].second.second));           }         }         if (pl > -1) {           if (abs(diff + 2 * (bb[pl].first - itm)) < abs(acc)) {             acc = diff + 2 * (bb[pl].first - itm);             rr.clear();             rr.push_back(make_pair(e, bb[pl].second.first));             rr.push_back(make_pair(ee, bb[pl].second.second));           }         }       }     }     printf( %I64d n%i n , abs(acc), rr.size());     for (auto e : rr) printf( %i %i n , e.first + 1, e.second + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     cin >> l >> r;     for (int i = l; i <= r; ++i) {       int d[10] = {};       int c = i;       bool ok = true;       while (c) {         if (d[c % 10]) {           ok = false;           break;         }         d[c % 10] += 1;         c /= 10;       }       if (ok) {         cout << i <<   n ;         return 0;       }     }     cout <<  -1 n ;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, 1, 0, -1};   long long spf[1];   void sieve() {     long long i, j;     for (i = 0; i < 1; i++) spf[i] = i;     for (i = 4; i < 1; i += 2) spf[i] = 2;     for (i = 3; i * i < 1; i++) {       if (spf[i] == i) {         for (j = i * i; j < 1; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   bool isvowel(char c) {     switch (c) {       case  a :       case  e :       case  i :       case  o :       case  u :       case  y :         return true;       default:         return false;     }   }   bool isPrime(long long n) {     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long sum(long long n) {     long long ans = 0;     while (n > 0) {       long long d = n % 10;       ans += d;       n /= 10;     }     return ans;   }   vector<long long> adj[200005];   long long col[200005];   pair<long long, long long> e[200005];   long long bfs(long long node) {     col[node] = 1;     queue<long long> q;     q.push(node);     while (!q.empty()) {       long long curr = q.front();       q.pop();       for (auto child : adj[curr]) {         if (col[child] == -1) {           col[child] = 1 - col[curr];           q.push(child);         } else if (col[child] == col[curr]) {           return false;         }       }     }     return true;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       long long n, m;       cin >> n >> m;       for (long long i = 1; i <= m; i++) {         long long u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);         e[i] = {u, v};       }       memset(col, -1, sizeof(col));       for (long long i = 1; i <= n; i++) {         if (col[i] == -1) {           if (bfs(i) == false) {             cout <<  NO                   <<   n ;             return 0;           }         }       }       cout <<  YES             <<   n ;       vector<long long> v;       for (long long i = 1; i <= n; i++) {         if (col[i] == 1) {           v.push_back(i);         }       }       for (long long i = 1; i <= m; i++) {         if (col[e[i].first] == 0) {           cout <<  0 ;         } else {           cout <<  1 ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int inf = 1e9;   const long double eps = 1e-7;   const long double pi = acos(-1);   const int dx[8] = {0, 2, 1, 0, -2, -1, 1, 2};   const int dy[8] = {2, 0, 1, -2, 0, -1, 2, 1};   const int N = 23;   const int MAXN = 1e5;   const int mod = 1e9 + 7;   int g[N];   int dp[(1 << N)], p[(1 << N)];   int main() {     int n, m;     cin >> n >> m;     if (m == n * (n - 1) / 2) {       cout << 0;       return 0;     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       g[u] |= (1 << v);       g[v] |= (1 << u);     }     for (int i = 0; i < n; i++) {       g[i] |= (1 << i);     }     for (int i = 0; i < (1 << n); i++) {       dp[i] = inf;     }     dp[0] = 0;     for (int i = 0; i < n; i++) {       dp[g[i]] = 1;       p[g[i]] = 0;     }     for (int mask = 1; mask < (1 << n); mask++) {       if (dp[mask] == inf) continue;       for (int i = 0; i < n; i++) {         if ((mask >> i) & 1) {           int nmask = (mask | g[i]);           if (dp[nmask] > dp[mask] + 1) {             dp[nmask] = dp[mask] + 1;             p[nmask] = mask;           }         }       }     }     int mask = (1 << n) - 1;     vector<int> ans;     cout << dp[mask] <<   n ;     while (mask) {       int pmask = p[mask];       if (p[mask] == 0) {         for (int i = 0; i < n; i++) {           if (mask == g[i]) {             ans.push_back(i);             break;           }         }         break;       }       for (int i = 0; i < n; i++) {         if ((pmask >> i) & 1) {           int nmask = (pmask | g[i]);           if (nmask == mask) {             ans.push_back(i);             break;           }         }       }       mask = pmask;     }     reverse(ans.begin(), ans.end());     for (int i = 0; i < (int)ans.size(); i++) {       cout << ans[i] + 1 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   string slv(string s) {     int sz = s.size();     if (sz % 2 == 1)       return s;     else {       string a = slv(s.substr(0, sz / 2));       string b = slv(s.substr(sz / 2, sz));       return a < b ? a + b : b + a;     }   }   int main() {     string a, b;     cin >> a >> b;     cout << ((slv(a) == slv(b)) ?  YES  :  NO );   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, b;     cin >> n >> m;     vector<int> ct(0);     if (m == 1) {       for (int j = 0; j < n; j++) cout << 1 << endl;       return 0;     }     if (m == 2) {       ct.push_back(1);       ct.push_back(2);       for (int i = 0; i < n; i++) cout << ct[i % 2] << endl;       return 0;     }     if (m % 2 != 0) {       ct.push_back((m + 1) / 2);       int l, r;       l = (m + 1) / 2;       r = (m + 1) / 2;       while (l != 1) {         l--;         ct.push_back(l);         r++;         ct.push_back(r);       }       for (int i = 0; i < n; i++) cout << ct[i % m] << endl;     } else if (m % 2 == 0) {       ct.push_back((m + 1) / 2);       int l, r;       l = (m + 1) / 2;       r = (m + 1) / 2;       while (l != 1) {         r++;         ct.push_back(r);         l--;         ct.push_back(l);       }       ct.push_back(m);       for (int i = 0; i < n; i++) cout << ct[i % m] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[10003], v1[10003];   int cnt[10003];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, i, j;     cin >> m >> n;     for (i = 0; i < m; i++) {       int x, y;       cin >> x;       memset(cnt, 0, sizeof(cnt));       for (j = 0; j < x; j++) {         cin >> y;         v[i].push_back(y);         cnt[y]++;       }       for (j = 1; j <= n; j++) {         if (!cnt[j]) v1[i].push_back(j);       }       sort(v[i].begin(), v[i].end());       sort(v1[i].begin(), v1[i].end());     }     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) {         int fl = 1;         for (int k = 0; k < v[i].size(); k++) {           if (!binary_search(v1[j].begin(), v1[j].end(), v[i][k])) fl = 0;         }         if (fl) {           cout <<  impossible ;           return 0;         }       }     cout <<  possible ;   }


#include <bits/stdc++.h>   using namespace std;   int a[505];   int sorted_a[505];   void rot(int i) {     i--;     int temp = a[i + 2];     a[i + 2] = a[i + 1];     a[i + 1] = a[i];     a[i] = temp;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int cases;     cin >> cases;     while (cases--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];         sorted_a[i] = a[i];       }       sort(sorted_a, sorted_a + n);       vector<int> ans;       for (int i = n - 1; i > 1; i--) {         int j = i;         while (a[j] != sorted_a[i]) j--;         if (j == 0) {           ans.push_back(1);           rot(1);           j++;         }         for (; j < i; j++) {           ans.push_back(j);           rot(j);         }       }       if (a[0] != sorted_a[0]) {         if (a[0] == a[2]) {           ans.push_back(1);           ans.push_back(1);           rot(1);           rot(1);         } else {           for (int i = 2; i < n - 1; i++) {             if (a[i] == a[i + 1]) {               for (int j = i; j >= 1; j--) {                 ans.push_back(j);                 rot(j);               }               break;             }           }         }       }       if (a[0] == sorted_a[0]) {         cout << ans.size() <<   n ;         for (int i : ans) cout << i <<    ;         cout <<   n ;       } else         cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int maxim = 0, sum = 0, a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];         maxim = max(maxim, a[i]);         sum += a[i];       }       if (maxim > sum / 2) {         cout <<  T n ;         continue;       }       if (sum % 2 == 0)         cout <<  HL n ;       else         cout <<  T n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int odd(int arr[], int n) {     for (int i = 0; i < n; i++) {       if (arr[i] % 2 != 0) {         return i;       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int sum = 0;       for (int i = 0; i < n; i++) {         sum += arr[i];       }       int fodd = odd(arr, n);       if (isPrime(sum)) {         cout << n - 1 << endl;         for (int i = 0; i < n; i++) {           if (i == fodd) {             continue;           }           cout << (i + 1) <<    ;         }         cout << endl;       }       if (!(isPrime(sum))) {         cout << n << endl;         for (int i = 0; i < n; i++) {           cout << (i + 1) <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     string s1 =   ;     if (n % 2 == 0) {       for (int i = 0; i < n; i++) {         cout << s[i] << s[i + 1];         i++;         if (i < n - 2) {           cout <<  - ;         }       }     } else {       if (n == 3)         cout << s << endl;       else {         for (int i = 0; i < n; i++) {           if (i == 0) {             cout << s[i] << s[i + 1] << s[i + 2] <<  - ;             i += 2;             continue;           } else {             cout << s[i] << s[i + 1];           }           if (i < n - 2) {             cout <<  - ;           }           i++;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long int fastPow(long long int x, long long int y) {     long long int p = mod;     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int arr[200005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),         cout.precision(15);     long long int n, m, A, res = 1;     cin >> n >> m >> A;     for (long long int i = 1; i <= m; i++) {       cin >> arr[i];     }     res = fastPow(A, n - 2 * arr[m]);     for (long long int i = m - 1; i >= 0; i--) {       long long int tmp = fastPow(A, arr[i + 1] - arr[i]) % mod;       long long int tmp2 = (tmp * ((tmp - 1 + mod) % mod) / 2) % mod;       long long int tmp3 = (tmp + tmp2) % mod;       res = (res * tmp3) % mod;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p[10005];   long long s[10005];   long long dp[2][10005];   int n;   long long m;   int main() {     scanf( %d%I64d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &s[i]);     int now = 0, next = 1;     for (int i = 1; i <= n; i++) {       memset(dp[next], 0, sizeof(dp[next]));       for (int j = 0; j <= i; j++) {         if (j == 0) {           dp[next][j] = dp[now][j] + p[i];         } else if (j == i) {           dp[next][j] = dp[now][j - 1] + s[i];         } else {           dp[next][j] = min(dp[now][j] + p[i] + j * m, dp[now][j - 1] + s[i]);         }       }       swap(now, next);     }     long long ans = dp[now][0];     for (int i = 1; i <= n; i++) ans = min(ans, dp[now][i]);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, p;       cin >> a >> b >> p;       string s;       cin >> s;       int len = s.size();       int pos = 0;       char ss =  C ;       for (int i = len - 2; i >= 0; i--) {         if (ss != s[i]) {           p -= (s[i] ==  A  ? a : b);           ss = s[i];           if (p < 0) {             pos = i + 1;             break;           }         }       }       cout << pos + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int col[n + 2], k[m + 2];     for (int i = 1; i <= n; i++) cin >> col[i];     for (int i = 1; i <= m; i++) cin >> k[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         vector<int> v[105];         int cnt = 0;         for (int kk = i; kk <= j; kk++) v[col[kk]].push_back(1);         for (int kk = 1; kk <= m; kk++) {           if (v[kk].size() != k[kk]) goto damn;         }         cout <<  YES n ;         return 0;       damn:;       }     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   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;   }   int n, m;   vector<int> G[20], G2[20];   int low[20], dfn[20];   int cur;   bool tarjan(int u, int fa) {     bool flg = 0;     low[u] = dfn[u] = ++cur;     bool flg2 = 1;     for (auto v : G2[u]) {       if (!dfn[v]) {         if (!tarjan(v, u)) flg2 = 0;         low[u] = min(low[u], low[v]);         if (dfn[v] == low[v]) flg2 = 0;       } else if (v != fa || flg)         low[u] = min(low[u], dfn[v]);       else         flg = 1;     }     return flg2;   }   vector<pair<int, int> > del;   int curcnt;   int ans = 0x3f3f3f3f;   vector<int> Gans[20];   void delete_edge(int x) {     if (!x) return;     if (G2[x].empty()) return;     int rrrnd = (rand() % G2[x].size() + G2[x].size()) % G2[x].size();     int y = G2[x][rrrnd];     del.emplace_back(x, y);     G2[x].erase(find(G2[x].begin(), G2[x].end(), y));     G2[y].erase(find(G2[y].begin(), G2[y].end(), x));     memset(low, 0, sizeof low);     memset(dfn, 0, sizeof dfn);     cur = 0;     if (!tarjan(1, -1)) {     Ret:       G2[x].push_back(y);       G2[y].push_back(x);       del.pop_back();       return;     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) goto Ret;     curcnt--;     if (curcnt < ans) {       ans = curcnt;       for (int i = 1; i <= n; i++) Gans[i] = G2[i];     }   }   void add_edge(int x) {     if (del.empty()) return;     G2[del[x].first].push_back(del[x].second);     G2[del[x].second].push_back(del[x].first);     del.erase(del.begin() + x);     curcnt++;   }   int main() {     srand(19260817);     int stt = clock();     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++) {       x = read(), y = read();       G[x].push_back(y);       G[y].push_back(x);     }     curcnt = ans = m;     for (int i = 1; i <= n; i++) Gans[i] = G[i];     const int max_time = 1950;     for (int _ = 1; _ <= 1000; _++) {       for (int i = 1; i <= n; i++) G2[i] = G[i];       curcnt = m;       for (int __ = 1; __ <= 1000; __++) {         if (rand() % 4)           delete_edge((rand() % n + n) % n + 1);         else if (!del.empty()) {           add_edge(rand() % del.size());         }       }       if (clock() - stt > max_time) break;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       for (int j = 0; j < Gans[i].size(); j++)         if (Gans[i][j] > i) printf( %d %d n , i, Gans[i][j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   int main() {     int q;     read(q);     while (q--) {       long long l, r;       read(l);       read(r);       long long ans = (l + r) * (r - l + 1) / 2;       if (!(r & 1)) --r;       if (!(l & 1)) ++l;       if (l > r)         cout << ans <<   n ;       else         cout << ans - (l + r) * ((r - l) / 2 + 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   template <class T>   inline void gmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline void gmin(T &a, T b) {     if (b < a) a = b;   }   using namespace std;   const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,             ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,             ms127 = 2139062143;   const double PI = acos(-1.0), eps = 1e-8;   void fre() {     freopen( /Users/luras/Desktop/in.txt ,  r , stdin);     freopen( /Users/luras/Desktop/out.txt ,  w , stdout);   }   const int INF = 1e9;   int casenum, casei;   const int top = 1e5, top2 = top + top;   int g, n, m, b[N], c[N];   struct A {     int typ, p, t, o, v;     bool operator<(const A &b) const { return p < b.p; }   } a[N];   pair<int, int> ans[N];   vector<int> sot1[N + top], sot2[N + top];   int main() {     while (~scanf( %d%d%d , &g, &n, &m)) {       for (int i = 1; i <= g; i++) {         scanf( %d%d%d , &a[i].typ, &a[i].p, &a[i].t);         a[i].o = i;       }       sort(a + 1, a + g + 1);       for (int i = 1; i <= g; i++) {         a[i].v = a[i].t - a[i].p;         if (a[i].typ == 1)           ans[a[i].o] = {a[i].p, m};         else           ans[a[i].o] = {n, a[i].p};         if (a[i].typ == 2)           sot2[a[i].v + top].push_back(a[i].o);         else           sot1[a[i].v + top].push_back(a[i].o);       }       for (int i = 1; i <= top2; i++) {         int t1 = sot1[i].size(), t2 = sot2[i].size(), t3 = min(t1, t2);         for (int j = t1 - 1, k = 0; j >= t1 - t3; j--, k++) {           b[sot1[i][j]] = sot2[i][k];         }         for (int j = t2 - 1, k = 0; j >= t2 - t3; j--, k++) {           b[sot2[i][j]] = sot1[i][k];         }         if (t1 > t2) {           for (int j = 0, k = t3; j < t1 - t3; j++, k++) {             b[sot1[i][j]] = sot1[i][k];           }         } else if (t2 > t1) {           for (int j = 0, k = t3; j < t2 - t3; j++, k++) {             b[sot2[i][j]] = sot2[i][k];           }         }       }       for (int i = 1; i <= g; i++) {         printf( %d %d n , ans[b[i]].first, ans[b[i]].second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int c = 3002;   int w, n, m, dif[c], rf[c];   long long sok = 1e15;   pair<long long, long long> op[c][c], cl[c][c];   vector<int> sz[c];   bool v[c];   pair<long long, long long> add(pair<long long, long long> a,                                  pair<long long, long long> b) {     return {a.first + b.first, a.second + b.second};   }   void dfs(int a) {     v[a] = true;     rf[a] = 1;     for (int i = 0; i <= n; i++) {       op[a][i] = {-sok, -sok};     }     op[a][1] = {0, dif[a]};     for (int x : sz[a]) {       if (!v[x]) {         dfs(x);         rf[a] += rf[x];         for (int db = rf[a]; db >= 1; db--) {           op[a][db] = max(add(op[a][db], op[x][1]), add(op[a][db - 1], cl[x][1]));           for (int i = max(2, db - rf[a] + rf[x]); i <= min(rf[x], db); i++) {             op[a][db] = max({op[a][db], add(op[a][db - i], cl[x][i]),                              add(op[a][db - i + 1], op[x][i])});           }         }       }     }     for (int i = 1; i <= rf[a]; i++) {       cl[a][i] = {op[a][i].first + (op[a][i].second > 0), 0};     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> w;     while (w--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         dif[i] = -x;       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         dif[i] += x;       }       for (int i = 1; i < n; i++) {         int a, b;         cin >> a >> b;         sz[a].push_back(b), sz[b].push_back(a);       }       dfs(1);       cout << cl[1][m].first <<   n ;       for (int i = 1; i <= n; i++) {         v[i] = 0;         sz[i].clear();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, c;   vector<vector<long long> > a;   long long dp[200000 + 5][2][2];   long long fun(long long idx, bool state, bool prev) {     if (idx == 0) return 0;     if (dp[idx][state][prev]) return dp[idx][state][prev];     if (prev || !state)       return dp[idx][state][prev] = a[idx][state] + min(fun(idx - 1, 0, state),                                                         fun(idx - 1, 1, state));     return dp[idx][state][prev] =                c + a[idx][state] +                min(fun(idx - 1, 0, state), fun(idx - 1, 1, state));   }   void solve() {     cin >> n >> c;     a.resize(n + 1, vector<long long>(2));     for (long long i = 1; i <= n - 1; i++) cin >> a[i][0];     for (long long i = 1; i <= n - 1; i++) cin >> a[i][1];     dp[n][0][0] = dp[n][1][0] = min(fun(n - 1, 0, 0), fun(n - 1, 1, 0));     for (long long i = 0; i <= n - 1; i++)       cout << min(dp[i][0][0], dp[i][1][0]) <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int M = 6;   const int MSK = 1 << M;   const int N = 45;   int D[45][MSK][MSK];   int col(int x) {     int ans = 0;     while (x) ans += x % 2, x /= 2;     return ans;   }   int n, m;   bool BIT(int x, int i) {     if (i < 0) return 0;     return (x >> i) & 1;   }   bool bad(int a, int b, int c) {     for (int i = 0; i < m; i++)       if (!(BIT(a, i) || BIT(c, i) || BIT(b, i - 1) || BIT(b, i) ||             BIT(b, i + 1)))         return true;     return false;   }   int main() {     cin >> n >> m;     if (n < m) swap(n, m);     for (int i = 0; i < N; i++)       for (int j = 0; j < MSK; j++)         for (int k = 0; k < MSK; k++) D[i][j][k] = 1e9;     for (int i = 0; i < MSK; i++) {       D[0][0][i] = col(i);     }     for (int i = 1; i <= n; i++) {       for (int pmsk = 0; pmsk < MSK; pmsk++)         for (int msk = 0; msk < MSK; msk++) {           for (int tmsk = 0; tmsk < MSK; tmsk++) {             if (bad(tmsk, pmsk, msk)) continue;             D[i][pmsk][msk] =                 min(D[i][pmsk][msk], D[i - 1][tmsk][pmsk] + col(msk));           }         }     }     int ans = 1e9;     for (int msk = 0; msk < MSK; msk++) {       ans = min(ans, (D[n][msk][0]));     }     cout << n * m - ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     set<int> keyboards;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       keyboards.insert(a);     }     int prev = 0;     int result = 0;     for (auto keyboard : keyboards) {       if (prev != 0) result += (keyboard - prev - 1);       prev = keyboard;     }     printf( %d n , result);   }


#include <bits/stdc++.h>   using namespace std;   const int L = 1000000 + 10;   int main() {     int n;     scanf( %d , &n);     char s[n + 10];     scanf( %s , s);     int next[n + 10];     next[0] = -1;     int j = 0, k = -1;     int maxn = 1;     while (j < n) {       if (k == -1 || s[j] == s[k]) {         next[++j] = ++k;         int xun = j - next[j];         maxn = max(maxn, j / xun / 2 * xun);       } else         k = next[k];     }     printf( %d n , n - maxn + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string char_to_str(char c) {     string tem(1, c);     return tem;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class T>   T rand() {     return uniform_int_distribution<T>()(rng);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n, k;     cin >> n >> k;     vector<long long> v;     vector<long long> v2;     for (long long i = 1; i * i <= n; ++i) {       if (n % i == 0) {         v.push_back(i);         v2.push_back(n / i);       }     }     reverse(v2.begin(), v2.end());     for (auto r : v2) v.push_back(r);     long long f = 0;     for (long long i = v.size() - 1; i >= 0; --i) {       long long t = n / v[i];       if (k > 100000000 || (k * (k + 1)) / 2 > t) {         continue;       }       for (long long j = 1; j < k; ++j) {         t -= j;         cout << j * v[i] <<    ;       }       cout << t * v[i];       return 0;     }     cout <<  -1 ;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int n, fa[N], p[N], cnt, mk, la[N], size[N];   int getfa(int x) {     if (fa[x] == x) return x;     return fa[x] = getfa(fa[x]);   }   void merge(int x, int y) {     int fx = getfa(x), fy = getfa(y);     if (fx == fy) return;     fa[fx] = fy;     size[fy] += size[fx];   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       fa[i] = i;       size[i] = 1;       if (p[i] == i) {         if (!mk)           mk = i;         else           p[i] = mk, cnt++;       }     }     if (!mk) {       for (int i = 1; i <= n; i++) merge(i, p[i]);       int now = 0;       for (int i = 1; i <= n; i++) {         if (size[i] > now) {           now = size[i];           mk = i;         }       }       for (int i = 1; i <= n; i++) fa[i] = i;       p[mk] = mk;       cnt++;     }     for (int i = 1; i <= n; i++) {       if (p[i] == i) continue;       if (getfa(i) == getfa(p[i])) p[i] = mk, cnt++;       merge(i, p[i]);     }     cout << cnt << endl;     for (int i = 1; i <= n; i++) cout << p[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, mod, a[N], b[N], ans[N];   int main() {     cin >> n >> m >> mod;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= m; i++) {       cin >> b[i];     }     for (int i = 1; i <= m; i++) {       ans[i] += b[i];       ans[i + n - m + 1] -= b[i];     }     for (int i = 1; i <= n; i++) {       ans[i] += ans[i - 1];     }     for (int i = 1; i <= n; i++) {       ans[i] += a[i];       cout << ans[i] % mod <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double epsilon = 1e-9;   int main() {     long long n, m, v;     cin >> n >> m >> v;     long long p = ((n - 1) * (n - 2)) / 2LL + 1;     if (m > p || m < n - 1) {       cout << -1 << endl;       return 0;     }     int other = 1;     if (v == 1) other = 2;     for (int i = 1; i <= n; i++) {       if (i == v)         continue;       else         cout << v <<     << i << endl;     }     m -= n - 1;     for (int i = 1; i <= n && m > 0; i++) {       if (i == v || i == other) continue;       for (int j = i + 1; j <= n && m > 0; j++) {         if (j == v || j == other || j == i) continue;         printf( %d %d n , i, j);         m--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-7;   const double PI = acos(-1.0);   const double ZERO = 0;   const double DOUBLE_MAX = 1 / ZERO;   int main() {     long double t, s, q;     cin >> t >> s >> q;     long double speed = (q - 1) / q;     long double x = 0, d;     int res = 0;     while (t - s > 1e-9) {       x += s * speed;       while (t - s > 1e-9 && x > 1e-10) {         s += (x) + 1e-9;         x *= speed;       }       res++;     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     if (x < 0) return -x;     return x;   }   template <class T>   T sqr(T a) {     return a * a;   }   const double pi = acos(-1.0);   const double eps = 1e-8;   char str1[2000010];   char str2[2000010];   int main() {     int cross, cnt1, cnt2, sum1, sum2, n, f, i;     while (1 == scanf( %d , &n)) {       cnt1 = cnt2 = sum1 = sum2 = cross = 0;       scanf( %s%s , str1, str2);       for (i = 0; i < 2 * n; i++) {         if (str1[i] ==  1  && str2[i] ==  1 )           cross++;         else if (str1[i] ==  1 )           cnt1++;         else if (str2[i] ==  1 )           cnt2++;       }       f = 1;       while (cross) {         if (f)           sum1++, f = 0;         else           sum2++, f = 1;         cross--;       }       if ((cnt1 == 0 && cnt2 == 0 && cross == 0) || (cross == 2 * n) ||           (cross % 2 == 0 && cnt1 == 0 && cnt2 == 0))         printf( Draw n );       else if (cnt2 == 0 && sum1 + cnt1 - 1 == sum2 && cnt1 != 1)         printf( Draw n );       else if (sum2 + cnt2 - 1 == sum1 + cnt1 || sum2 + cnt2 == sum1 + cnt1)         printf( Draw n );       else if (sum1 + cnt1 > sum2 + cnt2)         printf( First n );       else         printf( Second n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ii = int;   int main() {     ii n, i;     cin >> n;     ii* ar = (ii*)malloc(sizeof(ii) * n);     for (i = 0; i < n; i++) {       cin >> ar[i];     }     ii max = *max_element(ar, ar + n);     if (n == 1)       cout << max - max << endl;     else {       ii count = 0;       for (i = 0; i < n; i++) {         count = count + max - ar[i];       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> balance(n, 0);     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       balance[a - 1] -= c;       balance[b - 1] += c;     }     int total = 0;     for (int i = 0; i < n; i++) {       total += balance[i] > 0 ? balance[i] : 0;     }     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) f = ch ==  -  ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   inline int sqr(int x) { return x * x; }   inline int dis(int x1, int y1, int x2, int y2) {     return sqr(x2 - x1) + sqr(y2 - y1);   }   const int N = 24, MAXN = N + 10;   int xo, yo;   int x[MAXN], y[MAXN];   int dp[1 << N], pre[1 << N], w[MAXN][MAXN];   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     cin.tie(0);     xo = read(), yo = read();     int n = read(), msk = (1 << n) - 1;     for (int i = (0); i <= (n - 1); i += (1)) x[i] = read(), y[i] = read();     x[n] = xo, y[n] = yo;     for (int i = (0); i <= (n); i += (1))       for (int j = (i + 1); j <= (n); j += (1))         w[i][j] = w[j][i] = dis(x[i], y[i], x[j], y[j]);     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int s = (0); s <= (msk); s += (1))       if (dp[s] != 0x3f3f3f3f)         for (int i = (0); i <= (n - 1); i += (1))           if (((s >> i) & 1) == 0) {             int k = s | (1 << i);             if (dp[s] + w[n][i] + w[i][n] < dp[k])               dp[k] = dp[s] + w[n][i] + w[i][n], pre[k] = s;             for (int j = (i + 1); j <= (n - 1); j += (1))               if (((k >> j) & 1) == 0) {                 int l = k | (1 << j);                 if (dp[s] + w[n][i] + w[i][j] + w[j][n] < dp[l])                   dp[l] = dp[s] + w[n][i] + w[i][j] + w[j][n], pre[l] = s;               }             break;           }     printf( %d n , dp[msk]);     printf( 0  );     for (int x = msk; x; x = pre[x]) {       for (int i = (0); i <= (n - 1); i += (1))         if (((x ^ pre[x]) >> i) & 1) printf( %d  , i + 1);       printf( 0  );     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const double eps = 1e-12;   const int maxn = 1e5 + 5;   const int INF = 1e9;   long long n, m;   long long ma = 0, mi = 0;   void pre() {     for (int i = 0; i < n; i++) ma += i;     if (n & 1) {       mi = n / 2 * (n / 2 + 1);     } else {       mi = n / 2 * n / 2;     }   }   int main() {     long long ans = 0, x, d;     scanf( %lld%lld , &n, &m);     pre();     for (int i = 0; i < m; i++) {       scanf( %lld %lld , &x, &d);       if (d < 0) {         ans += x * n + d * mi;       } else {         ans += x * n + d * ma;       }     }     printf( %lf n , (double)1.0 * ans / n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 30;   const int MOD = 1e9 + 7;   long long n, power[K + 1];   int k;   __inline void add(int &a, int b) {     if ((a += b) >= MOD) {       a -= MOD;     }   }   struct Matrix {     int trans[K][K];     int go[K];     Matrix() {       memset(trans, 0, sizeof(trans));       memset(go, 0, sizeof(go));     }     int all() {       int result = 0;       for (int i = 0; i < k; i++) {         add(result, go[i]);         for (int j = 0; j < k; j++) {           add(result, trans[i][j]);         }       }       return result;     }   };   map<long long, Matrix> mp;   Matrix search(long long n) {     if (mp.count(n)) {       return mp[n];     }     Matrix ret;     if (k >= n) {       for (int i = 0; i < n; i++) {         ret.go[i] = 0;         ret.trans[i][i] = 1;         for (int j = i + 1; j < n; j++) {           ret.trans[i][j] = power[j - i - 1];         }       }       return ret;     }     long long unit = 1;     int length = 1;     while (unit <= n / k && unit * k < n) {       unit *= k;       length++;     }     Matrix base = search(unit);     ret = base;     long long remaind = n % unit;     Matrix extra = search(remaind);     static int reach[K][K], _reach[K][K];     for (int i = 0; i < k; i++) {       ret.go[i] = base.go[i];       for (int j = 0; j < k; j++) {         reach[i][j] = base.trans[i][j];       }     }     for (int i = 1; i <= n / unit; i++) {       if (i == n / unit && remaind == 0) {         break;       }       Matrix &nxt = (i < n / unit) ? base : extra;       int lead = i;       for (int j = 0; j < k; j++) {         for (int l = 0; l < k; l++) {           _reach[j][l] = reach[j][l];           add(ret.go[j], reach[j][l]);           reach[j][l] = 0;         }       }       int t = ((k - 1) * (length - 2) + i - 1) % k;       for (int start = 0; start < k; start++) {         int sum = 0;         for (int prev = k - 1; prev >= 0; prev--) {           int pv = (prev + t) % k;           add(sum, _reach[start][pv]);           int succ = prev;           int sv = (succ + t) % k, temp = ((sv - i) % k + k) % k;           add(ret.go[start], 1LL * sum * nxt.go[temp] % MOD);           for (int end = 0; end < k; end++) {             add(reach[start][end],                 1LL * sum * nxt.trans[temp][((end - i) % k + k) % k] % MOD);           }         }       }       for (int i = 0; i < k; i++) {         for (int j = 0; j < k; j++) {           ret.trans[i][j] = reach[i][j];         }       }     }     return mp[n] = ret;   }   int main() {     power[0] = 1;     for (int i = 1; i <= K; i++) {       power[i] = power[i - 1] * 2;     }     cin >> n >> k;     Matrix answer = search(n);     cout << (answer.all() + 1) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n;   int a[N], sum[N], b[65][N], cnt[65];   long long ans;   int t[2];   long long find(int l, int r, int lim) {     int i, j;     long long ret = 0;     if (l > r) return 0;     j = l - 1;     t[0] = t[1] = 0;     for (i = l; i <= r; ++i) {       while (sum[i] - sum[j] >= lim) {         ++t[sum[j] & 1];         ++j;       }       ret += (long long)t[sum[i] & 1];     }     return ret;   }   void dfs(int l, int r, int mx) {     if (r - l - 1 < 1) return;     if (!mx) return;     int i, tmx = 0;     cnt[mx] = 1;     b[mx][cnt[mx]] = l;     for (i = l + 1; i <= r - 1; ++i)       if (a[i] == mx) b[mx][++cnt[mx]] = i;     b[mx][++cnt[mx]] = r;     if (cnt[mx] > 2) {       ans += find(l + 1, r - 1, mx + mx);       for (i = 1; i <= cnt[mx] - 1; ++i) {         ans -= find(b[mx][i] + 1, b[mx][i + 1] - 1, mx + mx);       }     }     for (i = 1; i <= cnt[mx] - 1; ++i) dfs(b[mx][i], b[mx][i + 1], mx - 1);   }   int main() {     int i, mx = 0;     long long x;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %lld , &x);       for (; x; x >>= 1)         if (x & 1ll) ++a[i];       mx = max(mx, a[i]);       sum[i] = sum[i - 1] + a[i];     }     dfs(0, n + 1, mx);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int T;     int n, x, i, j;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &x);       printf( %d n , 2 * x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int bun, beef, chicks, hp, cp, count1 = 0, count2 = 0;       cin >> bun >> beef >> chicks >> hp >> cp;       bun /= 2;       if (hp >= cp) {         count1 = min(bun, beef);         bun -= count1;         if (bun != 0) {           count2 = min(bun, chicks);         }       } else {         count2 = min(bun, chicks);         bun -= count2;         if (bun != 0) {           count1 = min(bun, beef);         }       }       cout << count1 * hp + count2 * cp << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long mod = 998244353;   long long p[N];   int main() {     int n;     long long ans;     scanf( %d , &n);     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = p[i - 1] * (n - i + 1) % mod;     ans = p[1];     for (int i = 2; i <= n; i++) {       ans += (p[i] - p[i - 1] + mod) % mod * i % mod;       ans %= mod;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, in, ans = 0, asum = 0, bsum = 0;     vector<int> a, b;     vector<int>::iterator minit, it2;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &in);       a.push_back(in);     }     b = a;     sort(b.begin(), b.end());     for (int i = 0; i < n; i++) {       asum += a[i];       bsum += b[i];       if (asum == bsum) {         ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct state {     state(int a, int b, int c, int d) : num(a), ind1(b), ind2(c), oper(d){};     int num;     int ind1, ind2;     int oper;   };   vector<state> ansState;   int n, ans = 100000;   map<set<int>, int> m;   vector<state> v;   void dfs() {     if (v[v.size() - 1].num == n) {       if (v.size() < ans) {         ans = v.size();         ansState = v;       }       return;     }     if (v.size() >= ans || v.size() > 5) return;     set<int> s;     for (int i = 0; i < v.size(); ++i) s.insert(v[i].num);     if (m[s]) return;     m.insert(make_pair(s, 1));     for (int i = 0; i < v.size(); ++i) {       for (int j = 1; j <= 3; ++j) {         int x = v[i].num * (1 << j);         if (x > n) break;         int flag = 1;         for (int k = 0; k < v.size(); ++k)           if (v[k].num == x) {             flag = 0;             break;           }         if (!flag) continue;         v.push_back(state(x, i, -1, j));         dfs();         v.pop_back();       }       for (int j = 0; j < v.size(); ++j)         for (int k = 0; k <= 3; ++k) {           int x = v[i].num + (1 << k) * v[j].num;           if (x > n) break;           int flag = 1;           for (int t = 0; t < v.size(); ++t)             if (v[t].num == x) {               flag = 0;               break;             }           if (flag) {             v.push_back(state(x, i, j, 4 + k));             dfs();             v.pop_back();           }         }     }   }   int Solution() {     cin >> n;     v.push_back(state(1, -1, -1, -1));     dfs();     cout << ans - 1 << endl;     for (int i = 1; i < ansState.size(); ++i) {       cout <<  lea e  << (char)( a  + i) <<  x, [ ;       if (ansState[i].oper < 4) {         cout << (1 << ansState[i].oper) <<  *e  << (char)( a  + ansState[i].ind1)              <<  x]  << endl;       }       if (ansState[i].oper == 4) {         cout <<  e  << (char)( a  + ansState[i].ind1) <<  x +                <<  e  << (char)( a  + ansState[i].ind2) <<  x]  << endl;       }       if (ansState[i].oper > 4) {         cout <<  e  << (char)( a  + ansState[i].ind1) <<  x +                << (1 << (ansState[i].oper - 4)) <<  *               <<  e  << (char)( a  + ansState[i].ind2) <<  x]  << endl;       }     }     return 0;   }   int main() {     Solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2 * 1e9;   const int mod = 1e9 + 7;   const int maxn = 200005;   int n, m;   int arr[maxn], ob[maxn], fact[maxn], obr[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> arr[1];     ob[1] = fact[1] = obr[1] = 1;     for (int i = 2; i <= n; ++i) {       cin >> arr[i];       ob[i] = (mod - 1LL * (mod / i) * ob[mod % i] % mod) % mod;       fact[i] = (1LL * i * fact[i - 1]) % mod;       obr[i] = (1LL * obr[i - 1] * ob[i]) % mod;     }     int ans = 0;     if (n % 4 == 0) {       for (int i = 1; i <= n; i += 2) {         int p1 = (n - 2) / 2, p2 = (i - 1) / 2;         int c =             (((1LL * fact[p1] * obr[p2]) % mod * obr[p1 - p2]) % mod + mod) % mod;         if (c == 0) c = 1;         ans = (1LL * ans + (1LL * c * (arr[i] - arr[i + 1])) % mod) % mod;       }     } else if (n % 4 == 1) {       for (int i = 1; i <= n; i += 2) {         int p1 = (n - 1) / 2, p2 = (i - 1) / 2;         int c = ((1LL * fact[p1] * obr[p2]) % mod * obr[p1 - p2]) % mod;         if (c == 0) c = 1;         ans = (1LL * ans + (1LL * c * arr[i]) % mod) % mod;       }     } else if (n % 4 == 2) {       for (int i = 1; i <= n; ++i) {         int p1 = (n - 2) / 2, p2 = (i - 1) / 2;         int c = ((1LL * fact[p1] * obr[p2]) % mod * obr[p1 - p2]) % mod;         if (c == 0) c = 1;         ans = (1LL * ans + (1LL * c * arr[i]) % mod) % mod;       }     } else {       ans = arr[1];       for (int i = 2; i <= n; i += 2) {         int p1 = (n - 3) / 2, p2 = (i - 2) / 2;         int c1 = ((1LL * fact[p1] * obr[p2]) % mod * obr[p1 - p2]) % mod;         p2 += 1;         int c2 = ((1LL * fact[p1] * obr[p2]) % mod * obr[p1 - p2]) % mod;         if (c1 == 0)           c1 = 1;         else if (c2 == 0)           c2 = 1;         ans = (1LL * ans + (1LL * arr[i] * 2 * c1) % mod +                (1LL * arr[i + 1] * (c2 - c1)) % mod) %               mod;       }     }     ans = (ans + mod) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     T f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int max(int x, int y) { return x > y ? x : y; }   int min(int x, int y) { return x < y ? x : y; }   char s[500010], t[500010];   int m, n, cnt0, cnt1;   int nxt[500010], ans[500010];   void Get_Next() {     nxt[0] = -1;     int j = 0, k = -1;     while (j <= n) {       if (k == -1 || t[j] == t[k])         nxt[++j] = ++k;       else         k = nxt[k];     }   }   bool fl;   int main() {     scanf( %s , s), scanf( %s , t), m = strlen(s), n = strlen(t);     t[n] =  $ ;     for (int i = 1; i <= m; ++i)       if (s[i - 1] ==  0 )         cnt0++;       else         cnt1++;     Get_Next();     for (int i = 0; i < n; ++i) {       if (t[i] ==  0  && cnt0 == 0) {         fl = 1;         break;       }       if (t[i] ==  1  && cnt1 == 0) {         fl = 1;         break;       }       ans[i] = t[i] -  0 ;       if (t[i] ==  0 )         cnt0--;       else         cnt1--;     }     if (fl) {       cout << s <<   n ;       return 0;     }     int now = n, kk = n;     while (1) {       if (now == n) now = nxt[n];       if (t[now] ==  0  && cnt0 == 0) {         for (int i = 1; i <= cnt1; ++i) ans[kk + i - 1] = 1;         break;       }       if (t[now] ==  1  && cnt1 == 0) {         for (int i = 1; i <= cnt0; ++i) ans[kk + i - 1] = 0;         break;       }       ans[kk++] = t[now] -  0 ;       if (t[now] ==  0 )         cnt0--;       else         cnt1--;       now++;       if (kk > m) break;     }     for (int i = 0; i < m; ++i) cout << ans[i];     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, ch;     while (!isdigit(ch = getchar()))       ;     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return x;   }   template <typename T>   inline T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   struct Node {     int len, pos, id;   };   struct prime {     int p, c;   };   const int MAXN = 100000;   vector<Node> a[MAXN + 1];   vector<prime> d[41];   int pri[45][10];   long long pw[45][10];   int main() {     int n = read(), m = read();     for (int i = 1; i <= n; i++) {       int len = read();       for (int j = 0; j < len; j++) {         int x = read();         a[x].push_back((Node){len, j, i});       }     }     for (int i = 2; i <= 40; i++) {       int tmp = i;       for (int j = 2; j <= i; j++) {         if (tmp % j) continue;         int c = 0;         while (tmp % j == 0) tmp /= j, ++c;         d[i].push_back((prime){j, c});       }       long long mul = 1;       for (int j = 0; j < 10; j++) pw[i][j] = mul, mul *= i;     }     for (int i = 1; i <= m; i++) {       int si = a[i].size(), res = 1, l = 0;       if (!si) {         puts( 0 );         continue;       }       long long lcm = a[i][0].len, pos = a[i][0].pos, las = a[i][0].id;       int s = d[lcm].size();       for (int j = 0; j < s; j++) {         prime z = d[lcm][j];         pri[z.p][z.c]++;       }       for (int r = 1; r < si; r++) {         Node x = a[i][r], y = a[i][l];         if (x.id != las + 1) {           l = r, lcm = x.len, pos = x.pos;           memset(pri, 0, sizeof(pri));         } else {           long long g = gcd(lcm, (long long)x.len);           while (l < r && abs(pos - x.pos) % g) {             s = d[y.len].size();             for (int j = 0; j < s; j++) {               prime z = d[y.len][j];               pri[z.p][z.c]--;               if (!pri[z.p][z.c]) {                 int flag = 0;                 for (int k = z.c + 1; k < 10; k++) flag |= pri[z.p][k];                 if (!flag) {                   lcm /= pw[z.p][z.c];                   for (int k = z.c; k >= 1; k--)                     if (pri[z.p][k]) {                       lcm *= pw[z.p][k];                       break;                     }                 }               }             }             g = gcd(lcm, (long long)x.len);             y = a[i][++l];             pos %= lcm;           }           long long tpos = x.pos;           while (pos != tpos) {             if (pos < tpos)               pos += (tpos - pos + lcm - 1) / lcm * lcm;             else               tpos += (pos - tpos + x.len - 1) / x.len * x.len;           }           lcm = lcm / g * x.len;         }         las = x.id;         s = d[x.len].size();         for (int j = 0; j < s; j++) {           prime z = d[x.len][j];           pri[z.p][z.c]++;         }         res = max(res, r - l + 1);       }       printf( %d n , res);       memset(pri, 0, sizeof(pri));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   void solve() {     long long int n, x;     cin >> n >> x;     vector<long long int> v(n);     for (auto &it : v) cin >> it;     ;     sort(v.begin(), v.end());     long long int ans = 0;     vector<long long int> a;     for (long long int i = 0; i < n; i++) {       if (v[i] >= x) {         ans++;       } else {         a.push_back(v[i]);       }     }     reverse(a.begin(), a.end());     for (long long int i = 0; i < a.size(); i++) {       long long int mini = a[i];       long long int count = 1;       while (mini * count < x) {         i++;         if (i >= a.size()) {           break;         }         mini = min(mini, a[i]);         count++;       }       if (mini * count >= x) {         ans++;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x;   char s[100005];   bool flag[500];   int cnt[500];   vector<char> f;   int main() {     scanf( %d , &x);     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; i++) cnt[s[i]]++;     for (int i =  a ; i <=  z ; i++) {       if (cnt[i] == 0) continue;       flag[i] = 1;       int pre = -1;       bool tag = 0;       f.push_back(char(i));       for (int j = 0; j < len; j++) {         if (flag[s[j]]) {           pre = j;           continue;         }         int y = j - pre;         if (y >= x) {           tag = 1;           break;         }       }       if (tag)         continue;       else {         cnt[i] = 0;         flag[i] = 0;         int pos = -1;         int pre = -1;         for (int j = 0; j < len; j++) {           if (s[j] == i) {             pos = max(pos, j);           }           if (flag[s[j]]) {             pre = j;             continue;           }           int y = j - pre;           if (y >= x) {             pre = pos;             cnt[i]++;           }         }         break;       }     }     string ans =   ;     int p = f.size();     for (int i = 0; i < p; i++) {       for (int j = 1; j <= cnt[f[i]]; j++) ans += f[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005], b[200005];   int x[200005];   int main() {     int n;     long long t;     scanf( %d%I64d , &n, &t);     for (int i = 1; i <= n; i++) scanf( %I64d , a + i);     for (int i = 1; i <= n; i++) {       scanf( %d , x + i);       if (x[i] < x[i - 1] || x[i] < i) {         puts( No );         return 0;       }     }     for (int i = 1; i <= n; i++) b[x[i]] = -1;     for (int i = 1; i <= n; i++) b[i] += b[i - 1];     for (int i = 1; i <= n; i++)       if (b[x[i] - 1] - b[i - 1]) {         puts( No );         return 0;       }     for (int i = n; i; i--) b[i] -= b[i - 1];     for (int i = 1; i < n; i++) b[i] += a[i + 1] + t;     b[n] = a[n] + t + 1;     for (int i = 1; i <= n; i++)       if (b[i] < a[i] + t || b[i] <= b[i - 1]) {         puts( No );         return 0;       }     puts( Yes );     for (int i = 1; i <= n; i++) printf( %I64d  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tests;     scanf( %d , &tests);     while (tests--) {       int item;       cin >> item;       vector<int> v;       set<int> s;       int temp;       for (int i = 0; i < item; i++) {         scanf( %d , &temp);         v.push_back(temp);         s.insert(temp);       }       int distinct = 0;       cout << s.size() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50005;   int n, m;   int p[N], a[N];   struct LCT {     int fa[N], ch[N][2], siz[N], sv[N];     long long sv2[N], sav[N], san[N], sa[N];     int nroot(int u) { return ch[fa[u]][0] == u || ch[fa[u]][1] == u; }     void pushup(int u) {       siz[u] = siz[ch[u][0]] + siz[ch[u][1]] + sv[u];       san[u] = san[ch[u][0]] + san[ch[u][1]] + 1ll * a[u] * sv[u];       sa[u] =           sa[ch[u][0]] + sa[ch[u][1]] + sav[u] +           (1ll * sv[u] * sv[u] - sv2[u] + 2ll * siz[ch[u][1]] * sv[u]) * a[u] +           2 * san[ch[u][0]] * (siz[ch[u][1]] + sv[u]);     }     void rot(int u) {       int v = fa[u], t = fa[v], d = (u == ch[v][1]);       if (nroot(v)) ch[t][v == ch[t][1]] = u;       fa[u] = t;       fa[ch[u][d ^ 1]] = v;       ch[v][d] = ch[u][d ^ 1];       fa[v] = u;       ch[u][d ^ 1] = v;       pushup(v);       pushup(u);     }     void splay(int u) {       while (nroot(u)) {         int v = fa[u];         if (nroot(v)) rot(u == ch[v][1] ^ v == ch[fa[v]][1] ? u : v);         rot(u);       }     }     int access(int u) {       int v = 0;       for (; u; v = u, u = fa[u]) {         splay(u);         sv[u] += siz[ch[u][1]] - siz[v];         sv2[u] += 1ll * siz[ch[u][1]] * siz[ch[u][1]] - 1ll * siz[v] * siz[v];         sav[u] += sa[ch[u][1]] - sa[v];         ch[u][1] = v;         pushup(u);       }       return v;     }     int lca(int u, int v) {       access(u);       return access(v);     }     void makeroot(int u) {       access(u);       splay(u);     }     void Link(int u, int v) {       makeroot(u);       makeroot(v);       fa[u] = v;       sv[v] += siz[u];       sv2[v] += 1ll * siz[u] * siz[u];       sav[v] += sa[u];       pushup(v);     }     void Cut(int u, int v) {       access(u);       splay(v);       ch[v][1] = fa[u] = 0;       pushup(v);     }   } lt;   void query() {     lt.splay(1);     printf( %.12lf n , 1.0 * lt.sa[1] / n / n);   }   int main() {     int x, y;     char ty;     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , p + i);     for (int i = 1; i <= n; i++)       scanf( %d , a + i), lt.siz[i] = lt.sv[i] = 1, lt.san[i] = lt.sa[i] = a[i];     for (int i = 2; i <= n; i++) lt.Link(i, p[i]);     scanf( %d , &m);     query();     while (m--) {       do ty = getchar();       while (ty !=  P  && ty !=  V );       scanf( %d%d , &x, &y);       if (ty ==  P ) {         if (lt.lca(x, y) == x) swap(x, y);         lt.Cut(x, p[x]);         lt.Link(x, p[x] = y);       } else         lt.makeroot(x), a[x] = y, lt.pushup(x);       query();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[6];   int sum = 0;   int x, y, z;   int x1, adjf, z1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     scanf( %d%d%d , &x, &y, &z);     scanf( %d%d%d , &x1, &adjf, &z1);     for (auto i = 0; i != 6; i++) scanf( %d , &a[i]);     if (y < 0) {       sum += a[0];     }     if (y > adjf) {       sum += a[1];     }     if (z < 0) {       sum += a[2];     }     if (z > z1) {       sum += a[3];     }     if (x < 0) {       sum += a[4];     }     if (x > x1) {       sum += a[5];     }     printf( %d , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long mx, p1, p2, val, sum, res, res1;   long long m[200007][27];   int main() {     ios_base::sync_with_stdio();     cin.tie();     cout.tie();     ;     cin >> n >> k;     res = 1000000007.0;     for (int i = 1; i <= n; i++) {       cin >> val;       mx = max(val, mx);       m[val][0]++;       if (m[val][0] >= k) res = 0;     }     mx /= 2;     for (long long i = mx; i >= 0; i--) {       if (i == 0) {         sum = m[0][0];         for (int j = 0; j <= 19; j++) {           m[0][j + 1] += m[1][j];           sum += m[i][j + 1];         }       } else {         p1 = 2 * i;         p2 = 2 * i + 1;         sum = m[i][0];         for (int j = 0; j <= 19; j++) {           m[i][j + 1] += m[p1][j] + m[p2][j];           sum += m[i][j + 1];         }       }       if (sum >= k) {         sum = 0;         res1 = 0;         for (long long j = 0; j <= 19; j++) {           res1 += m[i][j] * j;           sum += m[i][j];           if (sum >= k) {             res = min(res, (res1 - (sum - k) * j));             break;           }         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long a, b, c;       scanf( %lld %lld %lld , &a, &b, &c);       printf( %lld n , a + b + c - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100003;   int n, L, R, phi;   long long mod;   long long fac[N], inv[N];   int d[N][33];   int tot, p[N];   long long fpow(long long x, int y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   void init() {     fac[0] = inv[0] = 1;     for (int i = 1; i <= n; i++) {       int tmp = i;       for (int j = 1; j <= tot; j++) {         d[i][j] = d[i - 1][j];         while (tmp % p[j] == 0) tmp /= p[j], d[i][j]++;       }       fac[i] = fac[i - 1] * tmp % mod;       inv[i] = fpow(fac[i], phi - 1);     }   }   long long C(int n, int m) {     if (n < m) return 0;     long long res = fac[n] * inv[m] % mod * inv[n - m] % mod;     for (int i = 1; i <= tot; i++)       res = res * fpow(p[i], d[n][i] - d[m][i] - d[n - m][i]) % mod;     return res;   }   int main() {     scanf( %d%I64d%d%d , &n, &mod, &L, &R);     int tmp = mod;     phi = mod;     for (int i = 2; i * i <= tmp; i++)       if (tmp % i == 0) {         p[++tot] = i;         phi = phi / i * (i - 1);         while (tmp % i == 0) tmp /= i;       }     if (tmp != 1) p[++tot] = tmp, phi = phi / tmp * (tmp - 1);     init();     long long ans = 0;     for (int i = 0; i <= n; i++) {       long long res = (C(i, (i + L + 1) / 2) - C(i, (i + R) / 2 + 1) + mod) % mod;       ans = (ans + res * C(n, i) % mod) % mod;     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mapa[35];   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       for (int j = 30; j >= 0; j--)         if ((1 << j) & x) {           mapa[j]++;           break;         }     }     while (q--) {       int x;       scanf( %d , &x);       long long pos = 0, res = 0;       for (int i = 30; i >= 0; i--) {         long long b = (1 << i);         if (b > x) continue;         long long aux = min(mapa[i], (long long)x / b);         res += aux;         x -= b * aux;       }       if (x > 0)         printf( -1 n );       else         printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 2010;   long long a[mn], b[mn];   int main() {     int n, k;     long long p;     scanf( %d %d %lld , &n, &k, &p);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= k; i++) scanf( %lld , &b[i]);     sort(a + 1, a + n + 1);     sort(b + 1, b + k + 1);     long long ans = 4e18;     for (int st = 0; st + n <= k; st++) {       long long tans = 0;       for (int i = 1; i <= n; i++) {         long long temp = 0;         long long now = b[st + i];         if (a[i] <= p && now <= p) {           if (a[i] <= now)             temp += p - a[i];           else             temp += a[i] - now + p - now;         } else if (a[i] <= p && p < now)           temp += now - a[i] + now - p;         else if (now <= p && p < a[i])           temp += a[i] - now + p - now;         else if (p < a[i] && p < now) {           if (now <= a[i])             temp += a[i] - p;           else             temp += now - a[i] + now - p;         }         tans = max(tans, temp);       }       ans = min(ans, tans);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, b, r;     cin >> n >> m;     b = 3;     r = 1;     while (n > 0) {       if (n % 2 != 0) r = (r * b) % m;       b = (b * b) % m;       n = n / 2;     }     cout << (r - 1 + m) % m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   unordered_map<int, int> Par[N];   map<pair<int, int>, int> ans;   vector<int> G[N];   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   inline int find(int x, int c) {     if (Par[c].find(x) == Par[c].end()) return x;     return Par[c][x] = find(Par[c][x], c);   }   inline void merge(int x, int y, int c) {     x = find(x, c);     y = find(y, c);     if (x == y) return;     Par[c][x] = y;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       G[a].push_back(c);       G[b].push_back(c);       merge(a, b, c);     }     for (int i = 1; i <= n; i++) {       sort(G[i].begin(), G[i].end());       G[i].resize(unique(G[i].begin(), G[i].end()) - G[i].begin());     }     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (G[a].size() > G[b].size()) swap(a, b);       if (G[a].size() == G[b].size() and a > b) swap(a, b);       if (ans.count({a, b})) {         cout << ans[{a, b}] <<   n ;         continue;       }       int res = 0;       for (auto u : G[a])         if (find(b, u) == find(a, u)) res++;       ans[{a, b}] = res;       cout << res <<   n ;     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   long long maxi = LLONG_MAX;   long long mini = LLONG_MIN;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long a[] = {1, 1, 3};   void fn(long long n, long long x) {     if (n <= 1) {       for (long long i = 0; i < n; i++) {         cout << x <<    ;       }       return;     }     long long t = (n) / 2;     if (n == 3) {       for (long long i = 0; i < 3; i++) {         cout << x * a[i] <<    ;       }       return;     } else {       if (n % 2 == 1) cout << x <<    ;       for (long long i = 0; i < t; i++) {         cout << x <<    ;       }     }     x *= 2;     fn(t, x);   }   int main() {     fast();     long long n;     cin >> n;     fn(n, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t, class u>   void chmax(t& first, u second) {     if (first < second) first = second;   }   template <class t, class u>   void chmin(t& first, u second) {     if (second < first) first = second;   }   template <class t>   using vc = vector<t>;   template <class t>   using vvc = vc<vc<t>>;   using pi = pair<ll, ll>;   using vi = vc<ll>;   template <class t, class u>   ostream& operator<<(ostream& os, const pair<t, u>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <class t>   ostream& operator<<(ostream& os, const vc<t>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   using uint = unsigned;   using ull = unsigned long long;   template <ll i, class T>   void print_tuple(ostream&, const T&) {}   template <ll i, class T, class H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <class... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   void print(ll x, ll suc = 1) {     cout << x;     if (suc == 1) cout <<   n ;     if (suc == 2) cout <<    ;   }   ll read() {     ll i;     cin >> i;     return i;   }   vi readvi(ll n, ll off = 0) {     vi v(n);     for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;     return v;   }   template <class T>   void print(const vector<T>& v, ll suc = 1) {     for (ll i = ll(0); i < ll(v.size()); i++)       print(v[i], i == ll(v.size()) - 1 ? suc : 2);   }   string readString() {     string s;     cin >> s;     return s;   }   template <class T>   T sq(const T& t) {     return t * t;   }   void yes(bool ex = true) {     cout <<  Yes  << endl;     if (ex) exit(0);   }   void no(bool ex = true) {     cout <<  No  << endl;     if (ex) exit(0);   }   constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }   const ll infLL = LLONG_MAX / 3;   const ll inf = infLL;   ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }   ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }   ll popcount(signed t) { return __builtin_popcount(t); }   ll popcount(ll t) { return __builtin_popcountll(t); }   bool ispow2(ll i) { return i && (i & -i) == i; }   ll mask(ll i) { return (ll(1) << i) - 1; }   bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }   template <class t>   void mkuni(vc<t>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   ll rand_int(ll l, ll r) {     static random_device rd;     static mt19937_64 gen(rd());     return uniform_int_distribution<ll>(l, r)(gen);   }   ll gcd(ll first, ll second) {     return second ? gcd(second, first % second) : first;   }   ll lcm(ll first, ll second) { return first / gcd(first, second) * second; }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed << setprecision(20);     ll n;     cin >> n;     ll g = 0;     vc<pi> vs;     for (ll _ = ll(0); _ < ll(n); _++) {       ll first, second;       cin >> first >> second;       g = gcd(g, lcm(first, second));       vs.emplace_back(first, second);     }     if (g > 1) {       for (auto z : vs) {         ll first = gcd(g, z.first);         ll second = gcd(g, z.second);         if (first > 1)           g = first;         else if (second > 1)           g = second;         else           assert(false);       }       cout << g << endl;     } else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 105000;   int n;   int a[MAXN];   bool can(int x) {     if (x == 0) return true;     if (n - x < x) return false;     int r = n;     for (int i = x; i >= 1; i--) {       if (r <= x) return false;       while (a[r] < 2 * a[i]) {         r--;         if (r <= x) return false;       }       r--;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int l = 0, r = n;     while (l < r) {       int m = (l + r + 1) / 2;       if (can(m))         l = m;       else         r = m - 1;     }     printf( %d , n - l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100020;   const int logn = 18;   const int MOd = 1e9 + 7;   int a, b;   int ar[maxn];   int main() {     scanf( %d %d , &a, &b);     for (int i = 1; i <= a; i++) scanf( %d , &ar[i]);     double ans = 0.0;     for (int i = 1, j, k, t; i <= b; i++) {       scanf( %d %d %d , &j, &k, &t);       ans = max(ans, ((double)(ar[j] + ar[k]) / t));     }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   char mat[105][105];   void solve() {     int n, m, horizontal;     cin >> n >> m >> horizontal;     int vertical = n * m / 2 - horizontal;     int oxe = 0, nte = 0;     char cc =  e ;     if (n % 2 != m % 2) {       if (n % 2 == 0) {         for (int i = 0; i < n; i += 2) {           mat[i][m - 1] = mat[i + 1][m - 1] = cc++;           if (cc >  z ) cc =  e ;         }         vertical -= n / 2;         m--;         nte = 1;       } else {         for (int j = 0; j < m; j += 2) {           mat[n - 1][j] = mat[n - 1][j + 1] = cc++;           if (cc >  z ) cc =  e ;         }         horizontal -= m / 2;         n--;         oxe = 1;       }     }     assert(n % 2 == 0 && m % 2 == 0);     int puth = n * m / 2;     int putv = 0;     char mofio[] = { a ,  b };     int cur = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j += 2) {         mat[i][j] = mat[i][j + 1] = mofio[cur];         cur ^= 1;       }       if (m % 4 == 0) cur ^= 1;     }     mofio[0] =  c , mofio[1] =  d ;     cur = 0;     for (int i = 0; i < n; i += 2) {       for (int j = 0; j < m; j += 2) {         if (puth == horizontal && putv == vertical) {           cout <<  YES n ;           for (int ii = 0; ii < n + oxe; ii++) {             for (int jj = 0; jj < m + nte; jj++) {               cout << mat[ii][jj];             }             cout <<   n ;           }           return;         }         mat[i][j] = mat[i + 1][j] = mofio[cur];         mat[i][j + 1] = mat[i + 1][j + 1] = mofio[cur ^ 1];         puth -= 2;         putv += 2;       }       cur ^= 1;     }     if (puth == horizontal && putv == vertical) {       cout <<  YES n ;       for (int ii = 0; ii < n + oxe; ii++) {         for (int jj = 0; jj < m + nte; jj++) {           cout << mat[ii][jj];         }         cout <<   n ;       }       return;     }     cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   int main() {     int N, ele = -1;     cin >> N;     vector<int> A(N);     int i;     for (i = 0; i < N; ++i) cin >> A[i];     sort(A.begin(), A.end());     int ans = 0, ctr = 0, x;     for (i = 0; i < N; i += x) {       x = upper_bound(A.begin(), A.end(), A[i]) -           lower_bound(A.begin(), A.end(), A[i]);       ans = ans + min(ctr, x);       ctr = max(ctr, x);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, c;     cin >> a >> b >> c;     if (b >= a && c >= a)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   inline int clamp(int v) {     if (v > n)       return v - n;     else if (v < 1) {       if (v == 0)         return n;       else         return n + v;     } else       return v;   }   void validate() {     n = 6;     assert(clamp(0) == 6);     assert(clamp(1) == 1);     assert(clamp(-1) == 5);     assert(clamp(6) == 6);     assert(clamp(7) == 1);     assert(clamp(3 + 5 % n) == 2);     assert(clamp(3 + 6 % n) == 3);     assert(clamp(3 + 7 % n) == 4);     assert(clamp(3 + 8 % n) == 5);     assert(clamp(3 + 9 % n) == 6);     assert(clamp(3 + 10 % n) == 1);     assert(clamp(3 + 11 % n) == 2);   }   int main() {     validate();     cin >> n >> q;     int startOdd = 1;     int startEven = 2;     for (int i = 0; i < q; i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int count;         scanf( %d , &count);         startOdd = clamp(startOdd + (count % n));         startEven = clamp(startEven + (count % n));       } else {         startOdd = (startOdd % 2 == 0) ? startOdd - 1 : startOdd + 1;         startEven = (startEven % 2 == 0) ? startEven - 1 : startEven + 1;       }     }     int evenOffset = startEven - 2;     int oddOffset = startOdd - 1;     int positions[1000000 + 1];     for (int i = 1; i <= n; i++) {       int pos = (i % 2 == 1) ? clamp(i + oddOffset) : clamp(i + evenOffset);       positions[pos] = i;     }     for (int i = 1; i <= n; i++) {       cout << positions[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, l, mx;   int a[100001];   int p[100001], miu[100001], len;   vector<int> b[100001];   vector<int> c[100001];   bool bz[100001];   int f[100001];   long long ans, s;   bool cmp(int a, int b) { return a > b; }   int gcd(int x, int y) {     int r = x % y;     while (r) x = y, y = r, r = x % y;     return y;   }   void init() {     int i, j, k, l;     miu[1] = 1;     for (i = 2; i <= 100000; i++) {       if (!bz[i]) p[++len] = i, miu[i] = -1;       for (j = 1; j <= len; j++)         if (1ll * i * p[j] <= 100000) {           bz[i * p[j]] = 1;           if (!(i % p[j])) break;           miu[i * p[j]] = -miu[i];         } else           break;     }   }   void add(int t, int s) {     int i, l = b[t].size();     for (i = 0; i <= l - 1; i++) f[b[t][i]] += s;   }   int get(int t) {     int i, k, l = b[t].size(), ans = 0;     for (i = 0; i <= l - 1; i++) k = b[t][i], ans += miu[k] * f[k];     return ans;   }   void work(int S) {     static int d[100001];     int i, j, k, l, len = c[S].size(), t = 0, A;     if (!len) return;     for (i = 0; i <= len - 1; i++) {       A = c[S][i];       while (t && get(A)) {         while (gcd(d[t], A) > 1) add(d[t], -1), --t;         s = 1ll * d[t] * A * S;         ans = (ans > s ? ans : s);         add(d[t], -1), --t;       }       d[++t] = A, add(A, 1);     }     while (t) add(d[t], -1), --t;   }   int main() {     init();     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), mx = (mx > a[i] ? mx : a[i]);     sort(a + 1, a + n + 1, cmp);     l = 0;     for (i = 1; i <= n; i++)       if (a[i] != a[i - 1])         a[++l] = a[i];       else         ans = (ans > a[i] ? ans : a[i]);     n = l;     for (i = 1; i <= mx; i++) {       s = floor(sqrt(i));       for (j = 1; j <= s; j++)         if (!(i % j)) {           b[i].push_back(j);           if (j * j < i) b[i].push_back(i / j);         }     }     for (i = 1; i <= n; i++) {       l = b[a[i]].size();       for (j = 0; j <= l - 1; j++) k = b[a[i]][j], c[k].push_back(a[i] / k);     }     for (i = 1; i <= 100000; i++) work(i);     printf( %lld n , ans);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   using pr = pair<T, U>;   template <typename T>   using vt = vector<T>;   template <class T>   bool cmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   inline namespace CP {   inline namespace Output {   template <class T>   void outv(vector<T> v, int add = 0, bool standard = 1) {     for (T& i : v) (standard ? cout : cerr) << (i + add) <<    ;     cout <<   n ;   }   template <class T>   void put(T output) {     cout << output <<   n ;   }   }  // namespace Output   class IO {    public:     void setIn(string second) { (void)!freopen(second.c_str(),  r , stdin); }     void setOut(string second) { (void)!freopen(second.c_str(),  w , stdout); }     void Input(int __use_input = 0) {       if (!!__use_input && 0) {         setIn( in  + to_string(__use_input) +  .txt );       }     }     IO FastIO() {       cin.tie(nullptr)->sync_with_stdio(0);       return *this;     }     IO* SetIO(string __s =   , string __t =   ) {       cin.exceptions(cin.failbit);       if ((int)(__t).size())         setIn(__s), setOut(__t);       else if ((int)(__s).size())         setIn(__s +  .in ), setOut(__s +  .out );       return this;     }   };   }  // namespace CP   const int MX = (1e5 + 5);   int N, K, P;   int a[MX];   void test_case() {     cin >> N >> K >> P;     for (int i = (0); i < (N); ++i) cin >> a[i];     vt<vt<int>> sets(K, vt<int>());     vt<pr<int, int>> even_pairs, odd_pairs;     int ptr = 0, used = 0;     for (int i = (0); i < (N); ++i) {       if (a[i] & 1 && ptr < (K - P))         sets[ptr++].push_back(a[i]);       else if (a[i] & 1) {         if (used)           odd_pairs.back().second = a[i];         else           odd_pairs.push_back({a[i], -1});         used = !used;       } else         even_pairs.push_back({a[i], -1});     }     if (ptr != (K - P) || used ||         (int)(even_pairs).size() + (int)(odd_pairs).size() < P)       return void(put( NO ));     even_pairs.insert(even_pairs.end(), odd_pairs.begin(), odd_pairs.end());     if (P == 0) {       for (auto pr : even_pairs) {         if (pr.first & 1) sets[0].push_back(pr.second);         sets[0].push_back(pr.first);       }     } else {       int have = (int)(even_pairs).size();       for (int i = (0); i < (P); ++i) {         if (i == P - 1)           for (auto pair : even_pairs) {             sets[ptr].push_back(pair.first);             if (pair.first & 1) sets[ptr].push_back(pair.second);           }         else {           if (even_pairs.back().first & 1)             sets[ptr].push_back(even_pairs.back().second);           sets[ptr++].push_back(even_pairs.back().first);           even_pairs.pop_back();         }       }     }     put( YES );     for (int i = (0); i < (K); ++i) {       cout << (int)(sets[i]).size() <<    ;       for (int j = (0); j < ((int)(sets[i]).size()); ++j)         cout << sets[i][j] <<    n [j == (int)(sets[i]).size() - 1];     }   }   int main() {     CP::IO().SetIO()->FastIO().Input(0);     int Test_Cases = 1;     for (int tt = 1; tt <= Test_Cases; ++tt) {       ;       ;       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[1005];   int dp[1005][3 * 1005];   int n, k;   int func(int idx, int diff) {     if (idx == n) {       return (abs(diff) == k);     }     if (abs(diff) == k) {       return 0;     }     int &re = dp[idx][diff + 1005];     if (re != -1) return re;     re = 0;     if (ch[idx] ==  W )       re = func(idx + 1, diff + 1);     else if (ch[idx] ==  L )       re = func(idx + 1, diff - 1);     else if (ch[idx] ==  D )       re = func(idx + 1, diff);     else {       re =           func(idx + 1, diff - 1) | func(idx + 1, diff) | func(idx + 1, diff + 1);     }     return re;   }   void path(int idx, int diff) {     if (idx == n) return;     if (ch[idx] ==  W ) {       printf( W );       path(idx + 1, diff + 1);     } else if (ch[idx] ==  L ) {       printf( L );       path(idx + 1, diff - 1);     } else if (ch[idx] ==  D ) {       printf( D );       path(idx + 1, diff);     } else {       if (func(idx + 1, diff + 1)) {         printf( W );         path(idx + 1, diff + 1);       } else if (func(idx + 1, diff)) {         printf( D );         path(idx + 1, diff);       } else {         printf( L );         path(idx + 1, diff - 1);       }     }   }   int main() {     scanf( %d%d%s , &n, &k, ch);     memset(dp, -1, sizeof dp);     if (func(0, 0)) {       path(0, 0);     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int pos[4] = {0};       int n = s.size(), ans = s.size() + 1;       for (int i = 0; i < n; i++) {         pos[s[i] -  0 ] = i + 1;         int x = min(pos[1], min(pos[2], pos[3]));         if (x == 0) continue;         ans = min(ans, i - x + 2);       }       if (s.size() + 1 == ans)         cout <<  0  << endl;       else         cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 998244353;   const long long maxn = (1 << 16) + 5;   long long cnt[maxn];   vector<vector<long long> > dp;   long long k;   long long c;   long long c1[20][20];   long long maxbit(long long x) {     for (long long i = 16; i >= 0; i--) {       if (x & (1 << i)) {         return i;       }     }   }   long long po(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b % 2 == 0) {       long long u = po(a, b / 2);       return (u * u) % p;     } else {       long long u = po(a, b - 1);       return (a * u) % p;     }   }   long long inv(long long x) { return po(x, p - 2); }   vector<vector<long long> > build(       vector<pair<long long, pair<long long, long long> > > g) {     vector<vector<long long> > answ(k + 1);     for (long long i = 0; i <= k; ++i) {       answ[i].resize(1 << c);       for (long long j = 0; j < (1 << c); ++j) answ[i][j] = 0;     }     for (auto h : g) {       answ[h.second.first][h.second.second] = h.first;     }     return answ;   }   vector<pair<long long, pair<long long, long long> > > mul1(       vector<pair<long long, pair<long long, long long> > > a,       vector<pair<long long, pair<long long, long long> > > b) {     map<pair<long long, long long>, long long> m;     vector<pair<long long, long long> > keys;     vector<pair<long long, pair<long long, long long> > > ans;     for (auto h1 : a) {       for (auto h2 : b) {         if ((h1.second.first + h2.second.first) <= k) {           pair<long long, pair<long long, long long> > z = {               (h1.first * h2.first) % p *                   c1[h1.second.first + h2.second.first][h1.second.first],               {h1.second.first + h2.second.first,                h1.second.second ^ h2.second.second}};           if (m.count(z.second)) {             m[z.second] = (m[z.second] + z.first) % p;           } else {             m[z.second] = (z.first % p);             keys.push_back(z.second);           }         }       }     }     for (auto z : keys) {       ans.push_back({m[z], z});     }     return ans;   }   vector<vector<long long> > answ;   void mul(vector<vector<long long> > &a, vector<vector<long long> > b) {     vector<pair<long long, long long> > used1;     vector<pair<long long, long long> > used2;     for (long long i = 0; i <= k; ++i) {       for (long long j = 0; j < (1 << c); ++j) {         if (a[i][j]) used1.push_back({i, j});         if (b[i][j]) used2.push_back({i, j});       }     }     for (long long i = 0; i <= k; ++i)       for (long long j = 0; j < (1 << c); ++j) answ[i][j] = 0;     for (auto h1 : used1) {       for (auto h2 : used2) {         if ((h1.first + h2.first) <= k) {           answ[h1.first + h2.first][h1.second ^ h2.second] +=               ((a[h1.first][h1.second] * b[h2.first][h2.second]) % p) *               c1[h1.first + h2.first][h1.first];           answ[h1.first + h2.first][h1.second ^ h2.second] %= p;         }       }     }     a = answ;   }   vector<pair<long long, pair<long long, long long> > > degree(       vector<pair<long long, pair<long long, long long> > > h, long long x) {     if (x == 1) return h;     if (x % 2 == 0) {       vector<pair<long long, pair<long long, long long> > > ans1 =           degree(h, x / 2);       return mul1(ans1, ans1);     } else {       vector<pair<long long, pair<long long, long long> > > ans1 =           degree(h, x - 1);       return mul1(ans1, h);     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (long long i = 0; i < 20; ++i) {       for (long long j = 0; j < 20; ++j) {         if (i < j) {           c1[i][j] = 0;           continue;         }         if (i == j || j == 0) {           c1[i][j] = 1;           continue;         }         c1[i][j] = c1[i - 1][j - 1] + c1[i - 1][j];         c1[i][j] %= p;       }     }     long long n;     cin >> n >> k >> c;     answ.resize(k + 1);     for (long long i = 0; i <= k; ++i) answ[i].resize(1 << c);     long long a[n];     long long o1 = 0;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       o1 ^= a[i];     }     long long b[n];     for (long long i = 0; i < n; ++i) {       long long x = a[i];       while (true) {         long long u = maxbit(x);         if ((x - (1 << u)) >= k) {           x -= (1 << u);         } else {           break;         }       }       b[i] = x;     }     sort(b, b + n);     for (long long i = 0; i < n; ++i) {       cnt[b[i]]++;     }     dp.resize(k + 1);     for (long long i = 0; i <= k; ++i) {       dp[i].resize(1 << c);       for (long long j = 0; j < (1 << c); ++j) {         dp[i][j] = 0;       }     }     dp[0][0] = 1;     for (long long i = 0; i < (1 << c); ++i) {       if (!cnt[i]) continue;       vector<pair<long long, pair<long long, long long> > > h;       for (long long j = 0; j <= k; ++j) {         h.push_back({1, {j, i ^ (i - j)}});       }       vector<pair<long long, pair<long long, long long> > > g = degree(h, cnt[i]);       mul(dp, build(g));     }     vector<long long> ans(1 << c);     for (long long i = 0; i < (1 << c); ++i) {       ans[i ^ o1] = dp[k][i];     }     for (long long i = 0; i < (1 << c); ++i) {       ans[i] *= po(inv(n), k);       ans[i] %= p;     }     for (long long i = 0; i < (1 << c); ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 150;   int ej[M][M];   const int inf = 1e9;   int n;   int bfs(int src, int sink) {     vector<int> vis(n, 0);     vector<int> dis(n, 0);     queue<int> que;     vis[src] = 1;     que.push(src);     while (que.size() > 0) {       int u = que.front();       que.pop();       for (int v = 0; v < n; v++) {         if (vis[v] == 0 && ej[u][v] == 1) {           vis[v] = 1;           dis[v] = dis[u] + 1;           que.push(v);           if (v == sink) return dis[v];         }       }     }     return -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (x) v.push_back(x);     }     n = v.size();     for (long long k = 0; k < 62; k++) {       int cnt = 0;       for (int i = 0; i < n; i++) {         if (v[i] & (1LL << k)) {           cnt++;         }       }       if (cnt >= 3) {         cout << 3 << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if ((v[i] & v[j]) > 0) ej[i][j] = 1;       }     }     int ans = inf;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (ej[i][j] == 0) continue;         ej[i][j] = 0;         ej[j][i] = 0;         int cur = bfs(i, j);         if (cur != -1) {           ans = min(ans, cur + 1);         }         ej[i][j] = 1;         ej[j][i] = 1;       }     }     if (ans == inf) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long arr[n + 5];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     long long mn = arr[0];     long long mx = arr[n - 1];     long long cnt1 = 0, cnt2 = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == mn)         cnt1++;       else if (arr[i] == mx)         cnt2++;     }     cout << mx - mn <<    ;     if (mn == mx)       cout << n * 1LL * (n - 1) / 2;     else       cout << (long long)(cnt1 * cnt2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[50005];   long long int dp[50005][505];   int k;   vector<int> v[50005];   long long ans;   void dfs(int i) {     vis[i] = 1;     dp[i][0] = 1;     for (auto j : v[i]) {       if (!vis[j]) {         vis[j] = 1;         dfs(j);         for (int w = 0; w <= k; w++) ans += dp[i][w] * dp[j][k - w - 1];         for (int w = 0; w <= k; w++) dp[i][w + 1] += dp[j][w];       }     }   }   int main() {     int n, a, b;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int n, a[N], b[N], p[N];   int main() {     if (fopen( 180F.in ,  r )) freopen( 180F.in ,  r , stdin);     scanf( %d n , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; i++) {       scanf( %d , b + i);     }     for (int i = 1; i <= n; i++) {       p[a[i]] = b[i];     }     for (int i = 1; i <= n; i++) {       printf( %d  , p[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n, i, k, ans = -1, x, l, sum;     cin >> n;     long long int a[n + 2];     a[0] = 0;     long long int ca[n + 2];     ca[0] = 0;     l = (n + 1) / 2;     for (i = 1; i <= n; i++) {       if (i <= l) {         cin >> a[i];       } else {         a[i] = x;       }       ca[i] = ca[i - 1] + a[i];       if (i == l) cin >> x;     }     long long int mn[n + 2];     mn[0] = 0;     for (i = 1; i <= l; i++) {       sum = i * x - ca[i];       mn[i] = min(mn[i - 1], sum);     }     for (i = l; i <= n; i++) {       sum = ca[i];       k = n - i;       sum += mn[k];       if (sum > 0) {         ans = i;       }     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const double h = 1e-6;   const int MAX_ = 200005;   inline long long int mul(long long int a, long long int b) {     return (a * 1ll * b) % 1000000007;   }   inline long long int sub(long long int a, long long int b) {     long long int c = a - b;     if (c < 0) c += 1000000007;     return c;   }   inline long long int add(long long int a, long long int b) {     long long int c = a + b;     if (c > 1000000007) c -= 1000000007;     return c;   }   long long int sqr(long long int x) { return x * x; }   long long int ncr[3050][3050];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 0; i < 3050; i++) {       for (int j = 0; j <= i; j++) {         if (i == 0 || j == 0)           ncr[i][j] = 1;         else           ncr[i][j] = add(ncr[i - 1][j - 1], ncr[i - 1][j]);       }     }     int k;     cin >> k;     long long int val;     long long int ans = 1;     int count = 0;     for (long long int i = 0; i < k; i++) {       cin >> val;       ans = mul(ans, ncr[count + val - 1][val - 1]);       ans %= 1000000007;       count += val;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m, dx, dy, qx, qy, ps[1 << 20];   long t, ans[1 << 20];   long a, b;   long bst, bp;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> dx >> dy;     qx = qy = 0;     for (int i = 0; i < n; i++) {       ps[qx] = qy;       qy += dy;       qx += dx;       qx %= n;       qy %= n;     }     for (int i = 1; i <= m; i++) {       cin >> a >> b;       t = b - ps[a] + n;       t %= n;       ans[t]++;     }     bst = -1;     for (int i = 0; i < n; i++)       if (ans[i] > bst) bst = ans[i], bp = i;     cout << 0 <<     << bp << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p = 1000000007ll;   int main(void) {     long long n;     cin >> n;     vector<pair<long long, long long> > loops;     long long tmp = 0;     for (long long i = (0); i < (n); ++i) {       string com;       cin >> com;       if (com ==  for ) {         long long x;         cin >> x;         loops.emplace_back(x, tmp);         tmp = 0;       } else if (com ==  end ) {         tmp = tmp * loops.back().first + loops.back().second;         if (tmp >= (1ll << 32)) {           cout <<  OVERFLOW!!!  << endl;           return 0;         }         loops.pop_back();       } else {         ++tmp;       }     }     if (tmp >= (1ll << 32)) {       cout <<  OVERFLOW!!!  << endl;       return 0;     }     cout << tmp << endl;     return 0;   }