#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200010];   long long int ans = 0LL;   int odd = 0, sz[200010] = {};   void dfs(int cur, int par = -1, int ht = 0) {     sz[cur]++;     for (int u : adj[cur]) {       if (u == par) continue;       dfs(u, cur, ht ^ 1);       sz[cur] += sz[u];     }     if (ht) odd++;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1);     for (int i = 1; i <= n; i++) ans += (1LL) * sz[i] * (n - sz[i]);     ans += (1LL) * odd * (n - odd);     printf( %lld n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[300003];   vector<int> adje[300003];   int d[300003];   int pickd[300003];   bool vis[300003];   int n, m;   int x;   int dfs1(int u) {     int ans = 0;     if (d[u] == -1)       x = u;     else if (d[u] == 1)       ++ans;     vis[u] = true;     for (int v : adj[u]) {       if (!vis[v]) {         ans += dfs1(v);       }     }     return ans;   }   int dfs2(int u) {     int ans = 0;     if (d[u] == 1) ++ans;     vis[u] = true;     for (int i = 0; i < ((int)(adj[u].size())); ++i) {       int v = adj[u][i];       if (!vis[v]) {         int c = dfs2(v);         if (c % 2) pickd[adje[u][i]] = 1;         ans += c;       }     }     return ans;   }   bool solve() {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         x = -1;         int c = dfs1(i);         if (c % 2) {           if (x == -1)             return false;           else {             d[x] = 1;           }         }       }     }     memset(vis, 0, sizeof(vis));     memset(pickd, 0, sizeof(pickd));     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         dfs2(i);       }     }     int k = accumulate(pickd + 1, pickd + m + 1, 0);     cout << k <<   n ;     for (int i = 1; i <= m; ++i) {       if (pickd[i]) {         cout << i <<    n [(--k) == 0];       }     }     return true;   }   int main() {     ios ::sync_with_stdio(0);     while (cin >> n >> m) {       for (int i = 1; i <= n; ++i) {         cin >> d[i];       }       for (int i = 1; i <= m; ++i) {         int u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);         adje[u].push_back(i);         adje[v].push_back(i);       }       if (!solve()) cout <<  -1 n ;       for (int i = 1; i <= n; ++i) {         adj[i].clear();         adje[i].clear();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   int n, m, mx, now, a[5200];   signed main() {     read(n), read(m);     int tmp = 0;     for (int i = 3; i <= n; ++i) {       if (i & 1) ++tmp;       mx += tmp;     }     if (m > mx) return puts( -1 ), 0;     a[1] = 1, a[2] = 2;     int p = n + 1;     tmp = 0;     for (int i = 3; i <= n; ++i) {       if (i & 1) ++tmp;       if (now + tmp > m) {         p = i - 1;         break;       }       now += tmp, a[i] = i;     }     m -= now;     if (m)       a[p + 1] = p - m * 2 + 1 + p, p += 2;     else       ++p;     for (int i = p; i <= n; ++i) a[i] = 200000000 + i * n;     for (int i = 1; i <= n; ++i) printf( %d  , a[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 5e3 + 10;   vector<double> vd;   int flag = 0;   vector<int> check(double x, int sz) {     vector<int> v;     int cur = 0;     double tot = x;     while (v.size() < sz) {       int o = tot / 10;       cur += o;       v.push_back(cur);       tot -= o * 10;       if (v.size() == sz) break;       tot += x;     }     if (flag) vd.push_back(tot);     return v;   }   double solve(vector<int>& v1, int o = 0) {     double l = 10 + 1e-10;     double r = INF;     int cnt = 200;     while (cnt--) {       double mid = (l + r) / 2;       auto v2 = check(mid, v1.size());       for (int i = 0; i < v1.size(); i++) {         if (v1[i] < v2[i]) {           r = mid;           break;         }         if (v1[i] > v2[i]) {           l = mid;           break;         }       }       if (v1 != v2) continue;       if (o == 0)         l = mid;       else         r = mid;     }     return l;   }   int main() {     int n;     cin >> n;     vector<int> v(n);     for (auto& x : v) cin >> x;     double key1 = solve(v, 0);     double key2 = solve(v, 1);     flag = 1;     if (key1 > key2) swap(key1, key2);     int ans1 = check(key1, n + 1).back();     int ans2 = check(key2, n + 1).back();     if (abs(vd[0] - 10) <= 1e-8) ans1++;     if (ans1 == ans2)       puts( unique ), printf( %d n , ans1), exit(0);     else       puts( not unique );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p[11];   int main() {     string s;     cin >> s;     int n = s.size();     p[0] = 1;     for (int i = 1; i < n; i++) p[i] = p[i - 1] * 9ll;     long long ans = 1ll;     for (char c : s) ans *= (long long)(c -  0 );     ans = max(ans, p[n - 1]);     long long pre = 1;     for (int i = 1; i <= n; i++) {       for (long long j = 1; j < s[i - 1] -  0 ; j++) {         ans = max(ans, pre * j * p[n - i]);       }       pre *= (long long)(s[i - 1] -  0 );     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     int sum = 0;     char b[3] = { R ,  G ,  B };     for (int i = 1; i < n; i++) {       if (a[i - 1] == a[i] && a[i] == a[i + 1]) {         for (int j = 0; j < 3; j++) {           if (b[j] != a[i]) {             a[i] = b[j];             break;           }         }         sum++;       } else if (a[i - 1] == a[i]) {         for (int j = 0; j < 3; j++) {           if (b[j] != a[i] && b[j] != a[i + 1]) {             a[i] = b[j];             break;           }         }         sum++;       }     }     printf( %d n , sum);     for (int i = 0; i < n; i++) {       printf( %c , a[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long r, i;     int flag = 1;     cin >> r;     for (i = 1; i <= 1000000; i++) {       if ((r - i * i - i - 1) > 0 && (r - i * i - i - 1) % (2 * i) == 0) {         flag = 0;         break;       }     }     if (flag == 0)       printf( %lld %lld n , i, (r - i * i - i - 1) / 2 * i);     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int distance(int x1, int y1, int x2, int y2) {     return (int)ceil(sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, x, q, cnt = 0;     string t;     char ch;     map<char, vector<pair<int, int>>> keys;     int freq[26] = {0};     cin >> n >> m >> x;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch;         if (!freq[ch -  a ]) freq[ch -  a ]++;         keys[ch].push_back(make_pair(i, j));       }     }     if (keys.count( S )) {       vector<pair<int, int>> shiftCords = keys[ S ];       vector<pair<int, int>> chCords;       for (int i =  a ; i <=  z ; i++) {         if (keys.count(i)) {           chCords = keys[i];           bool validDistance = 0;           for (int j = 0; j < (int)chCords.size(); j++) {             for (int k = 0; k < (int)shiftCords.size(); k++) {               if (distance(chCords[j].first, chCords[j].second,                            shiftCords[k].first, shiftCords[k].second) <= x) {                 freq[i -  a ]++;                 validDistance = 1;                 break;               }             }             if (validDistance) break;           }         }       }     }     cin >> q;     cin >> t;     for (int i = 0; i < q; i++) {       char c = t[i];       if (islower(c)) {         if (!freq[c -  a ]) {           cout << -1 << endl;           return 0;         }       } else {         c = tolower(c);         if (!keys.count( S ) || !freq[c -  a ]) {           cout << -1 << endl;           return 0;         } else {           if (freq[c -  a ] == 1) cnt++;         }       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     int maxP = 0;     int maxQ = 0;     for (int i = 0; i < k; i++) {       int p = 0;       int q = 0;       cin >> p;       cin >> q;       if (p < q) {         cout <<  Happy Alex  << endl;         return 0;       }     }     cout <<  Poor Alex  << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 4e5 + 10;   const int maxm = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double eps = 1e-7;   using namespace std;   long long cnt[25][25], dp[1 << 21];   int n;   vector<int> col[25];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       col[x].push_back(i);     }     for (int i = 1; i <= 20; ++i)       for (int j = 1; j <= 20; ++j)         if (i != j) {           if (!col[i].size() || !col[j].size()) continue;           int l = 0;           for (int k = 0; k < col[i].size(); ++k) {             while (true) {               if (l == col[j].size() - 1 || col[j][l + 1] > col[i][k]) break;               l++;             }             if (col[j][l] < col[i][k]) cnt[i][j] += l + 1;           }         }     memset(dp, 0x3f, sizeof dp);     dp[0] = 0;     for (int S = 0; S < 1 << 20; ++S) {       for (int i = 0; i < 20; ++i)         if (!(S >> i & 1)) {           long long sum(0);           for (int j = 0; j < 20; ++j)             if (S >> j & 1) sum += cnt[j + 1][i + 1];           dp[S | (1 << i)] = min(dp[S | (1 << i)], dp[S] + sum);         }     }     cout << dp[(1 << 20) - 1] << endl;     return ~~(0 - 0);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long v;     cin >> v;     for (long long i = 0; i < v; i++) {       vector<long double> arr(250);       for (long long j = 0; j < 250; j++) cin >> arr[j];       long double avg1 = 0;       for (long long j = 0; j < 250; j++) avg1 += arr[j];       avg1 /= 250.0;       sort(arr.begin(), arr.end());       long double v1 = ((arr[249] - arr[0]) * (arr[249] - arr[0])) / 12.0;       long double v2 = 0;       for (long long j = 0; j < 250; j++)         v2 += ((avg1 - arr[j]) * (avg1 - arr[j]));       v2 /= 250.0;       long double avg2 = 0;       if (abs(v2 - avg1) > abs(v1 - v2))         cout <<  uniform n ;       else         cout <<  poisson n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string new_l, string old_l) {     int len_1;     int col_izm;     col_izm = 0;     len_1 = new_l.length();     if (len_1 == old_l.length()) {       for (int i = 0; i < len_1; i++) {         if (new_l[i] == old_l[i]) {           col_izm++;         } else if (((new_l[i] ==  1 ) || (new_l[i] ==  i ) || (new_l[i] ==  l ) ||                     (new_l[i] ==  I ) || (new_l[i] ==  L )) &&                    ((old_l[i] ==  1 ) || (old_l[i] ==  i ) || (old_l[i] ==  l ) ||                     (old_l[i] ==  I ) || (old_l[i] ==  L ))) {           col_izm++;         } else if (((new_l[i] ==  0 ) || (new_l[i] ==  o ) ||                     (new_l[i] ==  O )) &&                    ((old_l[i] ==  0 ) || (old_l[i] ==  o ) ||                     (old_l[i] ==  O ))) {           col_izm++;         } else if (((new_l[i] - old_l[i]) == 32) ||                    ((new_l[i] - old_l[i]) == -32)) {           col_izm++;         } else           return true;       }       if (col_izm == len_1)         return false;       else         return true;     } else       return true;   }   int main() {     string n_login, login;     int col;     cin >> n_login;     cin >> col;     for (int i = 0; i < col; i++) {       cin >> login;       if (!check(n_login, login)) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); }   int maximum(int a, int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int minimum(int a, int b) {     if (a < b) {       return a;     } else {       return b;     }   }   int main() {     int a[2000];     int p = 0, q = 1, x = 1, i, j;     int pl, pr, vl, vr, k;     long long c = 0, d;     a[0] = 0;     for (i = 0; i < 9; i++) {       for (j = p; j < q; j++) {         a[x++] = a[j] * 10 + 4;         a[x++] = a[j] * 10 + 7;       }       p = q;       q = x;     }     qsort(a, x, sizeof(int), cmp);     a[x] = 1000000001;     scanf( %d %d %d %d %d , &pl, &pr, &vl, &vr, &k);     d = (long long)(pr - pl + 1) * (vr - vl + 1);     for (i = 1; i <= x - k; i++) {       if (pl <= a[i] && vr >= a[i + k - 1]) {         int s1 = minimum(a[i], pr);         int s2 = maximum(a[i - 1] + 1, pl);         int t1 = maximum(a[i + k - 1], vl);         int t2 = minimum(a[i + k] - 1, vr);         if (s1 - s2 >= 0 && t2 - t1 >= 0) {           c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);         }       }       if (vl <= a[i] && pr >= a[i + k - 1]) {         int s1 = minimum(a[i], vr);         int s2 = maximum(a[i - 1] + 1, vl);         int t1 = maximum(a[i + k - 1], pl);         int t2 = minimum(a[i + k] - 1, pr);         if (s1 - s2 >= 0 && t2 - t1 >= 0) {           c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);         }       }     }     if (k == 1) {       for (i = 1; i < x; i++) {         if (pl <= a[i] && pr >= a[i] && vl <= a[i] && vr >= a[i]) c--;       }     }     printf( %.20lf n , (double)c / d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5100;   char Map[N][N];   int dp[N][N];   int main() {     int i, j;     int line, row;     scanf( %d%d , &line, &row);     for (i = 0; i < line; i++) scanf( %s , Map[i]);     for (i = 0; i < line; i++) {       for (j = row - 1; j >= 0; j--) {         if (Map[i][j] ==  1 )           dp[j][i] = dp[j + 1][i] + 1;         else           dp[j][i] = 0;       }     }     int ret = 0;     for (i = 0; i < row; i++) {       sort(dp[i], dp[i] + line);       for (j = 0; j < line; j++) {         ret = max(ret, (line - j) * dp[i][j]);       }     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s[1000005];   int main(void) {     int n, d, ans = 0;     cin >> n >> d >> s[1];     for (int i = 2; i <= n; ++i) {       cin >> s[i];       int cnt = 0;       if (s[i] <= s[i - 1]) cnt = (s[i - 1] - s[i] + d) / d;       s[i] += cnt * d;       ans += cnt;     }     return cout << ans <<   n , 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )   using namespace std;   const double eps = 0.000001;   const long double pi = acos(-1);   const int maxn = 1e7 + 9;   const int mod = 1e9 + 7;   const long long MOD = 1e18 + 9;   const long long INF = 1e18 + 123;   const int inf = 2e9 + 11;   const int mxn = 1e6 + 9;   const int N = 3e5 + 123;   const int PRI = 555557;   const int pri = 997;   int tests = 1;   int n, m, q;   int sz[N], pr[N], ans[N];   bool u[N];   vector<int> g[N];   void dfs(int v, int p = 1) {     sz[v] = 1;     pr[v] = p;     for (int to : g[v]) {       if (to == p) continue;       dfs(to, v);       sz[v] += sz[to];     }   }   void dfs_center(int v) {     u[v] = 1;     if (sz[v] == 1) {       ans[v] = v;       return;     }     int mx = g[v].back();     for (int to : g[v]) {       if (u[to]) continue;       dfs_center(to);       if (sz[mx] < sz[to]) {         mx = to;       }     }     int c = ans[mx];     while (sz[v] > sz[c] * 2) {       c = pr[c];     }     ans[v] = c;   }   inline void Solve() {     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int x;       cin >> x;       g[x].push_back(i);     }     dfs(1);     dfs_center(1);     while (q--) {       int x;       cin >> x;       cout << ans[x] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     while (tests--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     regex w( WUB );     cout << regex_replace(s, w,    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = int(1e9) + 7;   int debug = 0;   const int N = int(2e3) + 5;   using namespace std;   int a[N], b[N], p[N];   int main() {     int i, j, n, t;     ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     int ans = 0;     vector<pair<int, int> > moves;     for (i = 0; i < n; i++) p[a[i]] = i;     for (i = 0; i < n; i++) {       int pos = -1;       for (j = 0; j < n; j++)         if (debug)           cerr <<  j                 <<  :   << j <<   |                  <<  b[j]                 <<  :   << b[j] << endl;       ;       for (j = 0; j < n; j++)         if (p[b[j]] == i) pos = j;       if (j == i) continue;       if (debug)         cerr <<  pos               <<  :   << pos <<   |                <<  i               <<  :   << i << endl;       ;       int cur = pos;       for (j = pos - 1; j >= i; j--) {         if (p[b[j]] >= cur) {           ans += cur - j;           moves.push_back(make_pair(j, cur));           b[cur] = b[j];           b[j] = i;           cur = j;         }       }     }     cout << ans <<   n ;     reverse(moves.begin(), moves.end());     cout << moves.size() <<   n ;     for (i = 0; i < moves.size(); i++)       cout << moves[i].second + 1 <<     << moves[i].first + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3079;   int r, c, n, k;   vector<int> nx(maxn, -1), pv(maxn, -1), kth(maxn, -1);   vector<vector<int> > my(maxn);   class point {    public:     int x, y;   };   bool cmp(point& a, point& b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); }   vector<point> v(maxn);   long long sum(int i) { return (v[i].y - v[pv[i]].y) * (c + 1 - v[kth[i]].y); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> r >> c >> n >> k;     long long ans = 0;     int m = n + k + 1;     for (int i = 1; i <= n; i++) cin >> v[i].x >> v[i].y;     v[0] = {r + 1, 0};     for (int i = n + 1; i < m; i++) v[i] = {r + 1, c + 1};     sort(v.begin(), v.begin() + m, cmp);     for (int i = n + 1; i < m; i++)       kth[i] = m - 1, pv[i] = i - 1, nx[i] = min(m - 1, i + 1);     for (int i = m - 1; i >= 0; i--) my[v[i].x].push_back(i);     for (int x1 = 1; x1 <= r; x1++) {       int p = 0;       for (int i = 1; i <= n; i++) {         if (v[i].x < x1) continue;         nx[p] = i, pv[i] = p;         p = i;       }       nx[p] = n + 1, pv[n + 1] = p;       kth[p] = (k == 1 ? p : pv[m - 1]);       for (int i = p; i >= 0; i = pv[i]) kth[i] = pv[kth[nx[i]]];       long long cur = 0;       for (int i = nx[0]; i <= n; i = nx[i]) cur += sum(i);       for (int x2 = r; x2 >= x1; x2--) {         ans += cur;         for (int i : my[x2]) {           cur -= sum(i);           for (int j = pv[i], cnt = 0; cnt < k - 1 && j; cnt++, j = pv[j]) {             cur -= sum(j);             if (j < i) kth[j] = nx[kth[j]];             cur += sum(j);           }           cur -= sum(nx[i]);           nx[pv[i]] = nx[i], pv[nx[i]] = pv[i];           cur += sum(nx[i]);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 233;   const int INF = numeric_limits<int>::max();   void read(int &x) {     x = 0;     char ch = getchar();     int f = 1;     while (!isdigit(ch)) (ch ==  -  ? f = -1 : 0), ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   int f[N][105], g[105];   int n, K, p, a[N], nw, s[N];   int x, sum, st[N], tp;   signed main() {     memset(g, 0x7f, sizeof(g));     memset(f, 0x7f, sizeof(f));     read(n);     read(K);     read(p);     if (p * K > n) {       for (int i = 1; i <= n; ++i) {         read(x);         x %= p;         a[i] = x;         sum = (sum + a[i]) % p;         f[i][1] = sum;         g[1] = sum;         for (int j = min(K, i); j >= 2; --j)           if (i == j) {             f[i][j] = f[i - 1][j - 1] + x;             g[j] = x;           } else {             int l = f[i - 1][j - 1] + x;             int r = f[i - 1][j] + x;             if (g[j] + x >= p) r -= p;             if (l < r)               f[i][j] = l, g[j] = x;             else if (l > r)               f[i][j] = r, g[j] = (g[j] + x) % p;             else               f[i][j] = l, g[j] = max(x, (g[j] + x) % p);           }       }       return printf( %d , f[n][K]), 0;     }     for (int i = 1; i <= n; ++i)       read(a[i]), a[i] %= p, sum += a[i], s[i] = (s[i - 1] + a[i]) % p;     for (int i = 1; i <= n - 1; ++i) {       int pos = upper_bound(st + 1, st + 1 + tp, s[i]) - st;       if (pos > tp) ++tp;       st[pos] = s[i];     }     int pos = upper_bound(st + 1, st + 1 + tp, s[n]) - st;     if (pos >= K)       printf( %d , s[n]);     else       printf( %d , s[n] + p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int y;   vector<pair<int, int> > p[3];   int dp[111][111][3];   bool check(int x, int t, int y) {     for (int i = 0; i < p[y].size(); i++) {       if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t) return false;     }     return true;   }   int go(int x, int t, int y) {     if (x == n - 1) return true;     int& res = dp[x][t][y];     if (res != -1) return res;     res = 0;     for (int i = 0; i < p[y].size(); i++) {       if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t ||           x + 1 >= p[y][i].first - 2 * t && x + 1 <= p[y][i].second - 2 * t)         return res = false;     }     if (check(x + 1, t, y)) res |= go(x + 1, t + 1, y);     if (check(x + 1, t, min(2, y + 1))) res |= go(x + 1, t + 1, min(2, y + 1));     if (check(x + 1, t, max(y - 1, 0))) res |= go(x + 1, t + 1, max(y - 1, 0));     return res;   }   void R(string s, int v) {     int i = 0;     if (s[0] ==  s ) {       y = v;       s[0] =  . ;     }     while (i < s.size()) {       if (s[i] !=  . ) {         int l = i;         int r = l;         while (i < s.size() && s[i] == s[l]) i++;         r = i - 1;         i--;         p[v].push_back(make_pair(l, r));         if (i == s.size() - 1) return;       }       i++;     }   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       p[0].clear();       p[1].clear();       p[2].clear();       memset(dp, -1, sizeof(dp));       cin >> n >> k;       string s1, s2, s3;       cin >> s1 >> s2 >> s3;       R(s1, 0);       R(s2, 1);       R(s3, 2);       if (go(0, 0, y))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   const int sz = 1 << 15;   char inbuf[sz], outbuf[sz];   char *pinbuf = inbuf + sz;   char *poutbuf = outbuf;   inline char _getchar() {     if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;     return *(pinbuf++);   }   inline void _putchar(char x) {     if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;     *(poutbuf++) = x;   }   inline void flush() {     if (poutbuf != outbuf)       fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;   }   }  // namespace IO   inline int read() {     int x = 0, p = 1;     char c = IO::_getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) p = -1;       c = IO::_getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = IO::_getchar();     return x * p;   }   namespace Mymath {   long long qp(long long x, long long p, long long mod) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * x % mod;       x = x * x % mod;       p >>= 1;     }     return ans;   }   long long inv(long long x, long long mod) { return qp(x, mod - 2, mod); }   long long C(long long N, long long K, long long fact[], long long mod) {     return fact[N] * inv(fact[K], mod) % mod * inv(fact[N - K], mod) % mod;   }   template <typename Tp>   Tp gcd(Tp A, Tp B) {     if (B == 0) return A;     return gcd(B, A % B);   }   template <typename Tp>   Tp lcm(Tp A, Tp B) {     return A * B / gcd(A, B);   }   };  // namespace Mymath   const int Maxn = 705;   const long long mod = 1e9 + 7;   int dp[Maxn][3][Maxn][11];   int tot[11][Maxn];   char c[Maxn];   int n;   void Add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int main() {     scanf( %s , c);     n = strlen(c);     for (int i = 0; i <= 9; i++) dp[0][1][0][i] = 1;     for (int i = 0; i < n; i++) {       int curv = c[i] -  0 ;       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= 9; k++) {           if (i)             for (int l = 0; l < 3; l++) Add(tot[k][j], dp[i][l][j][k]);           Add(dp[i + 1][1][j + (curv >= k)][k], dp[i][1][j][k]);           for (int l = 0; l <= 9; l++) {             if (!i && !l) continue;             if (l == curv) continue;             Add(dp[i + 1][(l < curv) ? 0 : 2][j + (l >= k)][k], dp[i][1][j][k]);           }           for (int l = 0; l <= 9; l++) {             if (!i && !l) continue;             Add(dp[i + 1][0][j + (l >= k)][k], dp[i][0][j][k]);             Add(dp[i + 1][2][j + (l >= k)][k], dp[i][2][j][k]);           }         }       }     }     for (int j = 0; j <= n; j++) {       for (int k = 0; k <= 9; k++) {         for (int l = 0; l < 2; l++) Add(tot[k][j], dp[n][l][j][k]);       }     }     for (int i = 0; i <= 9; i++) {       for (int j = n; j >= 0; j--) {         Add(tot[i][j], tot[i][j + 1]);       }     }     long long ans = 0;     int w = 1;     for (int i = 0; i < n; i++) {       for (int j = 1; j <= 9; j++) {         int cnt = tot[j][i + 1] - tot[j + 1][i + 1];         if (cnt < 0) cnt += mod;         ans += 1ll * cnt * w % mod * j;         ans %= mod;       }       w = 1ll * w * 10 % mod;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<T> &v) {     for (typename vector<T>::size_type i = 0; i < v.size(); ++i)       out << v[i] <<    ;     out <<   n ;     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {     for (size_t i = 0; i < v.size(); ++i) {       for (size_t j = 0; j < v[i].size(); ++j) {         out << v[i][j] <<    ;       }       out <<   n ;     }     return out;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> divisors;     for (long long i = 1; i * i <= n; ++i) {       if (n % i == 0) {         divisors.push_back(i);         if (n / i != i) {           divisors.push_back(n / i);         }       }     }     if (k > divisors.size()) {       cout <<  -1 n ;       return 0;     }     sort(divisors.begin(), divisors.end());     cout << divisors[k - 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000;   struct node {     int n;     int i;     node(int n, int i) : n(n), i(i) {}     node() {}     bool operator<(const node& n1) const { return n < n1.n; }     bool is_happy() const {       int a = n;       while (a) {         if (a % 10 != 7 && a % 10 != 4) return false;         a /= 10;       }       return true;     }   };   node nodes[maxn];   int rev[maxn];   inline void sw(int i, int j, vector<pair<int, int> >& ans) {     ans.push_back(pair<int, int>(nodes[i].i, nodes[j].i));     swap(nodes[i].i, nodes[j].i);     rev[nodes[i].i] = i;     rev[nodes[j].i] = j;   }   int main() {     int n;     scanf( %d , &n);     bool sorted = true;     int x = -1, prev;     for (int i = 0; i < n; i++) {       prev = x;       scanf( %d , &x);       if (prev > x) sorted = false;       nodes[i] = node(x, i);     }     if (sorted) {       printf( 0 n );       return 0;     }     sort(nodes, nodes + n);     for (int i = 0; i < n; i++) {       rev[nodes[i].i] = i;     }     int happy = -1;     for (int i = 0; i < n; i++) {       if (nodes[i].is_happy()) {         happy = i;         break;       }     }     if (happy == -1) {       printf( -1 n );       return 0;     }     vector<pair<int, int> > ans;     for (int i = 0; i < n; i++)       if (i != happy && nodes[i].i != i) {         if (rev[i] != happy) sw(rev[i], happy, ans);         sw(happy, i, ans);       }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first + 1, ans[i].second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   int qpow(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % Mod;       if (b >>= 1) a = a * a % Mod;     }     return c;   }   int n;   long long a;   int p, q;   int main() {     scanf( %d , &n);     bool minus = 1;     q = 2;     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a);       if (!(a & 1)) minus = 0;       q = qpow(q, a);     }     q = q * 500000004ll % Mod;     if (minus) {       p = q - 1;       if (p < 0) p += Mod;     } else       p = q + 1;     p = p * 333333336ll % Mod;     printf( %d/%d n , p, q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dx[4] = {-1, 0, 0, +1};   long long int dy[4] = {0, -1, +1, 0};   const long long int LINF = 1e18;   const long long int INF = 1e9;   const long long int mod = 1e9 + 7;   long long int power(long long int a, long long int b, long long int m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long int t = power(a, b / 2, m);     t = (t * t) % m;     if (b & 1) t = (t * a) % m;     return t;   }   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, ans = 0, i, j;       string ip;       cin >> ip;       long long int sz = ip.size();       if (ip[0] ==  ? ) {         if (sz >= 2 && ip[1] ==  a )           ip[0] =  b ;         else           ip[0] =  a ;       }       for (long long int i = 1; i <= -1 + ip.size(); i++) {         if (ip[i] ==  ? ) {           if (ip[i - 1] ==  a ) {             if ((i + 1) < sz && ip[i + 1] ==  b )               ip[i] =  c ;             else               ip[i] =  b ;           } else if (ip[i - 1] ==  b ) {             if ((i + 1) < sz && ip[i + 1] ==  a )               ip[i] =  c ;             else               ip[i] =  a ;           } else if (ip[i - 1] ==  c ) {             if ((i + 1) < sz && ip[i + 1] ==  a )               ip[i] =  b ;             else               ip[i] =  a ;           } else             ip[i] =  a ;         }       }       bool poss = true;       for (long long int i = 1; i <= sz - 1; i++) {         if (ip[i] == ip[i - 1]) {           cout << -1 << endl;           poss = false;           break;         }       }       if (poss) cout << ip << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[105], b[105], c[105], tot, ans;   char s[105];   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       c[i] = s[i] -  0 ;       if (c[i] == 1) tot++;     }     ans = tot;     for (int i = 1; i <= 125; i++) {       for (int j = 1; j <= n; j++) {         if (i < b[j]) continue;         int k = i - b[j];         if (k % a[j] != 0) continue;         tot -= c[j];         c[j] ^= 1;         tot += c[j];       }       ans = max(ans, tot);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   const int oo = 0x3f3f3f3f;   template <typename T>   inline void rd(T &x) {     x = 0;     int f = 1;     char CH = getchar();     while (!isdigit(CH)) {       if (CH ==  - ) f = 0;       CH = getchar();     }     while (isdigit(CH)) {       x = ((x + (x << 2)) << 1) + (CH - 48);       CH = getchar();     }     x = (f == 1) ? x : -x;     return;   }   const int MXN = 2e6;   int a[MXN], n;   inline void solve() {     long long fuck;     rd(fuck);     if (fuck > 36) {       cout << -1;       return;     }     if (fuck == 1)       cout << 6;     else if (fuck == 2)       cout << 8;     else if (fuck > 2) {       while (fuck > 2) fuck -= 2, cout << 8;       if (fuck == 1) cout << 0;       if (fuck == 2) cout << 8;     }   }   int main() { solve(); }


#include <bits/stdc++.h>   const int MAXN = 100;   char s[MAXN + 5];   int main() {     int n, p, q;     scanf( %d%d%d , &n, &p, &q);     scanf( %s , s);     for (int i = 0; p * i <= n; i++) {       if ((n - p * i) % q == 0) {         int j = (n - p * i) / q;         printf( %d n , i + j);         int pos = 0;         for (int k = 1; k <= i; k++) {           for (int l = 1; l <= p; l++) {             printf( %c , s[pos]);             pos++;           }           puts(  );         }         for (int k = 1; k <= j; k++) {           for (int l = 1; l <= q; l++) {             printf( %c , s[pos]);             pos++;           }           puts(  );         }         return 0;       }     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   long long T, n, m, k;   int main() {     read(T);     while (T--) {       read(n), read(k);       k = k * k;       if ((n & 1) != (k & 1) || k > n)         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn(3e5 + 10), mxm(4e5 + 10);   const long long modl(998244353);   int nm, n, m, p, t, k;   int ans;   int a[mxn], b[mxn], c[mxn];   int main() {     ios_base::sync_with_stdio(false);     cin >> nm;     while (cin >> n >> m) {       ans = max(0, n + m - 3) / m + 1;       cout << ans;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 27;   vector<vector<int>> g;   int t, tin[N], tout[N], up[N][20], sz[N], d[N];   void dfs(int v, int p = 0, int dp = 0) {     tin[v] = t++;     d[v] = dp;     sz[v] = 1;     up[v][0] = p;     for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i - 1];     for (int u : g[v]) {       if (u != p) {         dfs(u, v, dp + 1);         sz[v] += sz[u];       }     }     tout[v] = t++;   }   bool is(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }   int get_up(int a, int b) {     for (int i = 18; i >= 0; i--) {       if (!is(up[a][i], b)) a = up[a][i];     }     return a;   }   int lca(int a, int b) {     if (is(a, b)) return a;     if (is(b, a)) return b;     return up[get_up(a, b)][0];   }   int main() {     int n;     cin >> n;     g.resize(n + 1);     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     tin[0] = -1;     tout[0] = 3 * N;     dfs(1);     int q;     cin >> q;     for (int o = 0; o < q; o++) {       int a, b;       cin >> a >> b;       int l = lca(a, b);       if (a == b)         cout << n <<   n ;       else if (d[b] - d[l] == d[a] - d[l]) {         a = get_up(a, l);         b = get_up(b, l);         cout << n - sz[a] - sz[b] <<   n ;       } else {         if (d[a] < d[b]) swap(a, b);         int dist = d[a] + d[b] - 2 * d[l];         if (dist % 2) {           puts( 0 );           continue;         }         dist /= 2;         int u = a;         for (int i = 18; i >= 0; i--) {           if (d[a] - d[up[u][i]] < dist) u = up[u][i];         }         int m = up[u][0];         cout << sz[m] - sz[u] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int l, t, c, a;   bool vis[26];   bool ok = false;   int main() {     cin >> s;     l = s.size();     if (l < 26) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < l; ++i) {       memset(vis, 0, sizeof vis);       t = c = 0;       for (int j = i; j < i + 26 && j < l; ++j) {         if (vis[s[j] -  A ]) break;         if (s[j] ==  ? ) {           c++;           continue;         }         vis[s[j] -  A ]++;         t++;       }       if (c + t == 26) {         a = i;         ok = true;         break;       }     }     if (!ok) {       cout << -1 << endl;       return 0;     }     queue<char> q;     for (int j = 0; j < 26; ++j) {       if (!vis[j]) q.push((char)j +  A );     }     for (int i = 0; i < a; ++i)       if (s[i] !=  ? )         cout << s[i];       else         cout <<  A ;     for (int i = a; i < 26 + a; ++i)       if (s[i] !=  ? )         cout << s[i];       else {         cout << q.front();         q.pop();       }     for (int i = 26 + a; i < l; ++i)       if (s[i] !=  ? )         cout << s[i];       else         cout <<  A ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long k;     cin >> k;     long long second = 2000 + k;     long long ar[2000];     ar[0] = -1;     for (long long int i = 1; i < 2000; i++) {       if (second <= 1000000) {         ar[i] = second;         second = 0;       } else {         ar[i] = 1000000;         second -= 1000000;       }     }     cout << 2000 <<   n ;     for (long long int i = 0; i < 2000; i++)       cout << ar[i] << ((i == (2000 - 1)) ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> blame(1002, 0);   vector<bool> visited(1002, false);   long long dfs(long long u) {     if (visited[u]) return u;     visited[u] = true;     return dfs(blame[u]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> blame[i];     }     for (long long i = 1; i <= n; i++) {       cout << dfs(i) <<    ;       fill(visited.begin(), visited.end(), false);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long g;   void ex_gcd(long long a, long long b, long long& x, long long& y) {     if (!b) {       g = a;       x = 1, y = 0;     } else {       ex_gcd(b, a % b, y, x);       y = y - a / b * x;     }   }   int main() {     long long a, b, c;     scanf( %lld%lld%lld , &a, &b, &c);     long long x, y;     ex_gcd(a, b, x, y);     if (c % g != 0) return 0 * printf( -1 n );     return 0 * printf( %lld %lld n , x * (-c / g), y * (-c / g));   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x[300300], y[300300];   vector<int> graph[300300];   int counter, dfs_num[300300], dfs_low[300300], dfs_parent[300300];   vector<pair<int, int> > bs;   void bridges(int u) {     dfs_low[u] = dfs_num[u] = counter++;     for (int v : graph[u]) {       if (!dfs_num[v]) {         dfs_parent[v] = u;         bridges(v);         if (dfs_low[v] > dfs_num[u]) bs.push_back(pair<int, int>(u, v));         dfs_low[u] = min(dfs_low[u], dfs_low[v]);       } else if (v != dfs_parent[u]) {         dfs_low[u] = min(dfs_low[u], dfs_num[v]);       }     }   }   vector<pair<int, int> > ng[300300];   struct subset {     int parent, _rank;   } subsets[300300];   int Find(int i) {     if (subsets[i].parent != i) subsets[i].parent = Find(subsets[i].parent);     return subsets[i].parent;   }   void Union(int x, int y) {     int xroot = Find(x), yroot = Find(y);     if (subsets[xroot]._rank < subsets[yroot]._rank)       subsets[xroot].parent = yroot;     else if (subsets[xroot]._rank > subsets[yroot]._rank)       subsets[yroot].parent = xroot;     else {       subsets[yroot].parent = xroot;       subsets[xroot]._rank++;     }   }   int maxi = 1, dist[300300];   void dfs(int u, int p, int d) {     if (d > dist[maxi]) maxi = u;     dist[u] = d;     for (pair<int, int> v : ng[u]) {       if (v.first != p) {         dfs(v.first, u, d + v.second);       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &x[i], &y[i]);       graph[x[i]].push_back(y[i]);       graph[y[i]].push_back(x[i]);     }     counter = 1;     for (int i = 1; i <= n; i++)       if (!dfs_num[i]) bridges(i);     for (int i = 1; i <= n; i++) {       subsets[i].parent = i;       subsets[i]._rank = 1;     }     for (int i = 0; i < bs.size(); i++) {       Union(bs[i].first, bs[i].second);       ng[bs[i].first].push_back(pair<int, int>(bs[i].second, 1));       ng[bs[i].second].push_back(pair<int, int>(bs[i].first, 1));     }     for (int i = 0; i < m; i++) {       if (Find(x[i]) == Find(y[i])) continue;       Union(x[i], y[i]);       ng[x[i]].push_back(pair<int, int>(y[i], 0));       ng[y[i]].push_back(pair<int, int>(x[i], 0));     }     dfs(1, 0, 0);     memset(dist, 0, sizeof dist);     dfs(maxi, 0, 0);     printf( %d n , dist[maxi]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100005], D[100005], n, m, w, L[100005];   bool go(int h) {     fill(L, L + n, 0);     for (int i = 0; i < n; ++i) D[i] = max(h - A[i], 0);     int pow = 0, cap = m, d;     for (int i = 0; i < n; ++i) {       pow -= L[i];       d = max(D[i] - pow, 0);       if (d > cap) return false;       pow += d;       cap -= d;       if (i + w < n) L[i + w] += d;     }     return true;   }   int main() {     std::ios::sync_with_stdio(false);     int mini = 2e9;     cin >> n >> m >> w;     for (int i = 0; i < n; ++i) {       cin >> A[i];       mini = min(mini, A[i]);     }     int lo = mini, hi = mini + m + 1, mid;     while (hi - lo > 1) {       mid = (hi + lo) >> 1;       if (go(mid))         lo = mid;       else         hi = mid;     }     cout << lo << endl;   }


#include <bits/stdc++.h>   int main(void) {     int t, n, d;     scanf( %d , &t);     while (t--) {       scanf( %d %d , &n, &d);       int i = 0;       int flag = 1;       while (i < n) {         int te = d / (i + 1);         te = te * (i + 1) == d ? te : te + 1;         if (i + te <= n) {           printf( YES n );           flag = 0;           break;         }         i++;       }       if (flag) printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m1 = 0, m2 = 0;     cin >> n;     vector<vector<long long> > m(n, vector<long long>(n));     vector<int> a(n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> m[i][j];     for (int i = 1; i < n - 1; i++)       a[i] = sqrt(m[i][i + 1] * m[i - 1][i] / m[i - 1][i + 1]);     a[0] = m[0][1] / a[1];     a[n - 1] = m[0][n - 1] / a[0];     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   const long long maxm = 1e5 + 100;   long long n, m;   struct node {     long long col[maxm * 4], tag[maxm * 4], sum[maxm * 4], siz[maxm * 4];     inline void pushup(long long o) {       sum[o] = sum[(o << 1)] + sum[(o << 1) | 1];       col[o] = col[(o << 1)] == col[(o << 1) | 1] ? col[(o << 1)] : 0;     }     inline void pushdown(long long o) {       if (tag[o]) {         tag[(o << 1)] += tag[o];         tag[(o << 1) | 1] += tag[o];         sum[(o << 1)] += siz[(o << 1)] * tag[o];         sum[(o << 1) | 1] += siz[(o << 1) | 1] * tag[o];         col[(o << 1)] = col[(o << 1) | 1] = col[o];         tag[o] = 0;       }     }     void build(long long o, long long l, long long r) {       siz[o] = (r - l + 1);       if (l >= r) {         col[o] = l;         return;       }       long long mid = (l + r) >> 1;       build((o << 1), l, mid), build((o << 1) | 1, mid + 1, r);       pushup(o);     }     void cover(long long o, long long l, long long r, long long ql, long long qr,                long long c) {       if (ql > r || qr < l) return;       if ((ql <= l) && (r <= qr) && col[o]) {         tag[o] += abs(col[o] - c);         sum[o] += abs(col[o] - c) * siz[o];         col[o] = c;         return;       }       pushdown(o);       long long mid = (l + r) >> 1;       cover((o << 1), l, mid, ql, qr, c),           cover((o << 1) | 1, mid + 1, r, ql, qr, c);       pushup(o);     }     long long ask(long long o, long long l, long long r, long long ql,                   long long qr) {       if (ql > r || qr < l) return 0;       if ((ql <= l) && (r <= qr)) return sum[o];       pushdown(o);       long long mid = (l + r) >> 1;       return ask((o << 1), l, mid, ql, qr) +              ask((o << 1) | 1, mid + 1, r, ql, qr);     }   } st;   signed main() {     scanf( %I64d%I64d , &n, &m);     st.build(1, 1, n);     for (long long i = 1; i <= m; i++) {       long long opt, l, r, x;       scanf( %I64d%I64d%I64d , &opt, &l, &r);       if (opt == 1)         scanf( %I64d , &x), st.cover(1, 1, n, l, r, x);       else         printf( %I64d n , st.ask(1, 1, n, l, r));     }     return 0;   }


#include <bits/stdc++.h>   template <typename Arg1>   void ZZ(const char* name, Arg1&& arg1) {     std::cout << name <<   =   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void ZZ(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cout.write(names, comma - names) <<   =   << arg1;     ZZ(comma, args...);   }   using namespace std;   long long int to_ll(string& s) {     long long int i, ret = 0, p = 1;     for (i = (long long int)s.length() - 1; i >= 0; i--)       ret += (s[i] -  0 ) * p, p *= 10LL;     return ret;   }   long long int gcd(long long int x, long long int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long int pwr(long long int base, long long int expo, long long int m) {     if (base == 0) return 0LL;     if (expo == 0) return (1LL % m);     if ((expo & 1) == 0) {       long long int temp = pwr(base, expo >> 1, m);       return (temp * temp) % m;     }     return ((base % m) * pwr(base, expo - 1, m)) % 1000000007;   }   vector<long long int> adj[200009];   long long int dp_down[200009][5], dp_up[200009][5], sz_down[200009][5],       sz_up[200009][5], p[200009], dp[200009][5], dp_sz[200009][5];   bool v_dp_down[200009][5], v_dp_up[200009][5], v_sz_down[200009][5],       v_sz_up[200009][5];   long long int n, k;   void dfs(long long int node, long long int parent) {     long long int i;     p[node] = parent;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       if (nxt == parent) continue;       dfs(nxt, node);     }   }   void dfs_sz_down(long long int node, long long int parent, long long int m) {     long long int i;     if (v_sz_down[node][m] == 1) return;     v_sz_down[node][m] = 1;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       long long int nxt_m = ((m - 1) % k + k) % k;       if (nxt == parent) continue;       dfs_sz_down(nxt, node, nxt_m);       sz_down[node][m] += sz_down[nxt][nxt_m];       dp_sz[node][nxt_m] += sz_down[nxt][nxt_m];     }     if (m == 0) sz_down[node][m]++;   }   void dfs_sz_up(long long int node, long long int parent, long long int m) {     if (v_sz_up[node][m] == 1) return;     v_sz_up[node][m] = 1;     if (m == 0) sz_up[node][m]++;     if (parent == -1) return;     long long int nxt_m = ((m - 1) % k + k) % k, i;     dfs_sz_up(parent, p[parent], nxt_m);     sz_up[node][m] += sz_up[parent][nxt_m];     sz_up[node][m] += dp_sz[parent][((m - 2) % k + k) % k];     sz_up[node][m] -= sz_down[node][((m - 2) % k + k) % k];   }   void dfs_up(long long int node, long long int parent, long long int m) {     if (v_dp_up[node][m] == 1) return;     v_dp_up[node][m] = 1;     if (parent == -1) return;     long long int nxt_m = ((m - 1) % k + k) % k, i;     dfs_up(parent, p[parent], nxt_m);     dp_up[node][m] += sz_up[parent][nxt_m] + dp_up[parent][nxt_m];     dp_up[node][m] += dp[parent][((m - 2) % k + k) % k];     dp_up[node][m] -= (2 * sz_down[node][((m - 2) % k + k) % k] +                        dp_down[node][((m - 2) % k + k) % k]);   }   void dfs_down(long long int node, long long int parent, long long int m) {     if (v_dp_down[node][m] == 1) return;     v_dp_down[node][m] = 1;     long long int i;     for (i = 0; i < adj[node].size(); i++) {       long long int nxt = adj[node][i];       long long int nxt_m = ((m - 1) % k + k) % k;       if (nxt == parent) continue;       dfs_down(nxt, node, nxt_m);       dp_down[node][m] += sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m];       dp[node][nxt_m] += (2 * sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int i, j, x, y, ans = 0;     cin >> n >> k;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, -1);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_sz_down(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_sz_up(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_down(i, p[i], j);     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) dfs_up(i, p[i], j);     for (j = 0; j < k; j++) {       for (i = 1; i <= n; i++) {         long long int total = dp_up[i][j] + dp_down[i][j];         long long int total_sz = sz_down[i][j] + sz_up[i][j];         if (j == 0) total_sz--;         long long int val = ((total - total_sz * j) / k);         if (j != 0) val += total_sz;         ans += val;       }     }     cout << ans / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 4;   int n, m, a, b, ay[N], by[N], l[N], linkY[N << 1];   void read() {     cin >> n >> m >> a >> b;     for (int i = 1; i <= n; ++i) {       cin >> ay[i];     }     for (int i = 1; i <= m; ++i) {       cin >> by[i];     }     for (int i = 1; i <= m; ++i) {       cin >> l[i];     }   }   long double dist = 1e18;   int ida, idb, idTmp;   long double sqr(long double x) { return x * x; }   long double euc(long double xa, long double ya, long double xb,                   long double yb) {     return sqrt(sqr(xa - xb) + sqr(ya - yb));   }   long double f(int ni, int mi) {     return euc(0, 0, a, ay[ni]) + euc(a, ay[ni], b, by[mi]);   }   long double ternarySearch(int num) {     int l = 1, r = n;     while (l + 2 < r) {       int dm = (r - l) / 3;       int m1 = l + dm;       int m2 = r - dm;       long double d1 = f(m1, num);       long double d2 = f(m2, num);       if (fabs(d1 - d2) < 1e-9) {         l = m1;         r = m2;       } else if (d1 < d2) {         r = m2;       } else {         l = m1;       }     }     idTmp = l;     for (int i = l + 1; i <= r; ++i) {       if (f(i, num) < f(idTmp, num)) {         idTmp = i;       }     }     return f(idTmp, num);   }   void calc() {     for (int i = 1; i <= m; ++i) {       long double distTmp = ternarySearch(i) + l[i];       if (distTmp < dist) {         dist = distTmp;         ida = idTmp;         idb = i;       }     }   }   void sovle() {     read();     calc();     cout << ida <<     << idb;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     sovle();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2 )   using namespace std;   using vi = vector<long long>;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   long long powmod(long long a, long long b, long long mod) {     if (b == 0 || a == 1) {       if (mod == 1)         return 0;       else         return 1;     }     if (b % 2 == 0) {       long long k = powmod(a, b / 2, mod);       return (k * k) % mod;     } else {       long long k = powmod(a, b / 2, mod);       return ((k * k) % mod * a) % mod;     }   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b)       return gcd(a % b, b);     else       return gcd(b % a, a);   }   long long prime(long long p) {     if (p == 1) return 0;     for (long long i = 2; i * i <= p; i++) {       if (p % i == 0 && i < p) return i;     }     return 1;   }   long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); }   long long random_modul() {     uniform_int_distribution<long long> u1(1e9, 2e9);     long long pepega = u1(rnd);     while (prime(pepega) != 1) pepega = u1(rnd);     return pepega;   }   template <typename T1>   void ifmax(T1& max, T1 kek) {     if (kek > max) max = kek;     return;   }   template <typename T1>   void ifmin(T1& min, T1 kek) {     if (kek < min) min = kek;     return;   }   template <typename T1>   istream& operator>>(std::istream& in, pair<T1, T1>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1>   istream& operator>>(std::istream& in, vector<T1>& a) {     for (long long i = 0; i < a.size(); i++) in >> a[i];     return in;   }   template <typename T1>   ostream& operator<<(std::ostream& out, vector<T1>& b) {     for (long long i = 0; i < b.size(); i++) out << b[i];     return out;   }   template <typename T1>   void sort(vector<T1>& m) {     sort(m.begin(), m.end());   }   template <typename T1>   void reverse(vector<T1>& m) {     reverse(m.begin(), m.end());   }   long long mod = 1000000007;   long long fac[200005];   long long inv_fac[200005];   long long co(long long a, long long b) {     long long ans = 1;     ans *= fac[b];     ans *= inv_fac[b - a];     ans %= mod;     ans *= inv_fac[a];     return ans % mod;   }   void solve() {     string a, b;     cin >> a >> b;     long long s1 = a.size();     long long s2 = b.size();     string ans;     for (long long i = 1; i <= s1; i++) {       for (long long j = 1; j <= s2; j++) {         string cur =   ;         for (long long k = 0; k < i; k++) cur += a[k];         for (long long k = 0; k < j; k++) cur += b[k];         if (i == 1 && i == j)           ans = cur;         else           ans = min(ans, cur);       }     }     cout << ans;     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     long long multitest = 0;     long long tututu;     tututu = 1;     long long combinatorics = 0;     if (combinatorics) {       fac[1] = 1;       fac[0] = 1;       for (long long i = 2; i < 200005; i++) {         fac[i] = fac[i - 1] * i;         fac[i] %= mod;       }       for (long long i = 0; i < 200005; i++) {         inv_fac[i] = inv(fac[i], mod);       }     }     if (multitest) cin >> tututu;     for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double n;     cin >> n;     long long m = sqrt(n);     if (m * m == n) {       cout << 2 * m;     } else if ((long long)m * (long long)(m + 1) >= n) {       cout << (long long)m + (long long)(m + 1);     } else       cout << (long long)2 * (long long)(m + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, i, oo = 0, oz = 0, zo = 0, zz = 0;     char s1[2000005], s2[2000005];     cin >> t;     cin >> s1;     cin >> s2;     t = 2 * t;     for (i = 0; i < t; i++) {       if (s1[i] ==  1  && s2[i] ==  1 )         oo++;       else if (s1[i] ==  1  && s2[i] ==  0 )         oz++;       else if (s1[i] ==  0  && s2[i] ==  1 )         zo++;       else         zz++;     }     if (oo % 2 == 0) {       if (oz > zo)         cout <<  First ;       else if (oz + 1 == zo || oz == zo)         cout <<  Draw ;       else         cout <<  Second ;     } else {       if (oz >= zo)         cout <<  First ;       else if (oz + 1 == zo || oz + 2 == zo)         cout <<  Draw ;       else         cout <<  Second ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, q;   map<pair<int, int>, int> vi;   int V[100005 << 2], ly[100005 << 2];   void push_down(int o) {     if (ly[o]) {       ly[o << 1] |= ly[o];       ly[o << 1 | 1] |= ly[o];       V[o << 1] |= ly[o];       V[o << 1 | 1] |= ly[o];       ly[o] = 0;     }   }   void push_up(int o) { V[o] = V[o << 1] & V[o << 1 | 1]; }   void ud(int o, int l, int r, int L, int R, int x) {     int mid = (l + r) / 2;     if (L <= l && r <= R) {       V[o] |= x;       ly[o] |= x;       return;     }     push_down(o);     if (L <= mid) ud(o << 1, l, mid, L, R, x);     if (R > mid) ud(o << 1 | 1, mid + 1, r, L, R, x);     push_up(o);   }   int qy(int o, int l, int r, int L, int R) {     int mid = (l + r) / 2;     if (L <= l && r <= R) return V[o];     push_down(o);     int ans = (1 << 30) - 1;     if (L <= mid) ans &= qy(o << 1, l, mid, L, R);     if (R > mid) ans &= qy(o << 1 | 1, mid + 1, r, L, R);     push_up(o);     return ans;   }   int main() {     cin >> n >> m;     int ok = 1;     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &l, &r, &q);       int tp = qy(1, 1, n, l, r);       if (vi[make_pair(l, r)]) {         if (tp != q) {           ok = 0;         }       }       if (!ok) continue;       vi[make_pair(l, r)] = 1;       if ((tp & q) == tp)         ud(1, 1, n, l, r, q);       else         ok = 0;     }     if (!ok) {       puts( NO );       return 0;     }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , qy(1, 1, n, i, i));   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int main() {     list<int> a;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a.push_back(x);     }     for (auto t = a.begin(); t != a.end(); t++) {       auto s = t;       s--;       if (t == a.begin()) continue;       while (true) {         if (*t == *s) {           *t = *t + 1;           t = a.erase(s);           if (t == a.begin()) break;           s = t, s--;         } else           break;       }     }     printf( %d n , a.size());     for (auto t : a) printf( %d  , t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   void chmax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   void add(T &a, T b) {     a += b;     if (a < 0) a += MOD;     if (a >= MOD) a -= MOD;   }   void FastIn(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int in() {     int x;     scanf( %d , &x);     return x;   }   long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   double din() {     double x;     scanf( %lf , &x);     return x;   }   long long p2[63];   void initP2() {     p2[0] = 1;     for (int i = (1); i <= (62); ++i) {       p2[i] = p2[i - 1] * 2;     }   }   int countBitsBaseB(long long n, long long b) {     if (n == 0) return 1;     int ret = 0;     while (n) {       ret++;       n /= b;     }     return ret;   }   int count1(long long n) {     int ret = 0;     while (n) {       ret += n & 1;       n >>= 1;     }     return ret;   }   long long c[1024][1024] = {0};   void initC() {     for (int i = 0; i < (1024); ++i) {       for (int j = 0; j < (i + 1); ++j) {         if (j == 0 || j == i) {           c[i][j] = 1;         } else {           c[i][j] = c[i - 1][j - 1];           add(c[i][j], c[i - 1][j]);         }       }     }   }   bool IsPrime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   void init() {     initP2();     initC();   }   const unsigned INVALID = 2000000001;   struct CMD {     int cmd, x, y;   } q[(int)(2e5 + 10)];   struct DSU {     int f[(int)(2e5 + 10)];     int h[(int)(2e5 + 10)];     int *addr[(int)(2e5 + 10) << 2];     int val[(int)(2e5 + 10) << 2];     int stkSize = 0;     void init(int n) {       for (int i = (1); i <= (n); ++i) {         f[i] = i;         h[i] = 1;       }       stkSize = 0;     }     int find(int x) { return x == f[x] ? x : find(f[x]); }     void merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) {         return;       }       if (h[x] > h[y]) swap(x, y);       addr[stkSize] = &f[x];       val[stkSize++] = f[x];       f[x] = y;       if (h[x] == h[y]) {         addr[stkSize] = &h[y];         val[stkSize++] = h[y];         h[y]++;       }     }     void mergeFast(int x, int y) {       x = find(x);       y = find(y);       if (x == y) {         return;       }       if (h[x] > h[y]) swap(x, y);       f[x] = y;       if (h[x] == h[y]) {         h[y]++;       }     }     void undo(int size) {       while (stkSize > size) {         stkSize--;         *addr[stkSize] = val[stkSize];       }     }       private:   } dsu;   const int BLOCK = 5000;   int last[(int)(2e5 + 10)];   pair<int, int> GetEdge(int x, int y, int der, int n) {     x += der - 1;     if (x >= n) x -= n;     y += der - 1;     if (y >= n) y -= n;     if (x > y) swap(x, y);     return make_pair(x + 1, y + 1);   }   void Switch(const pair<int, int> &edge, set<pair<int, int>> &edges) {     if (edges.find(edge) != edges.end()) {       edges.erase(edge);     } else {       edges.insert(edge);     }   }   int main() {     init();     int n = in(), m = in();     for (int i = (1); i <= (m); ++i) {       q[i].cmd = in();       q[i].x = in();       q[i].y = in();     }     last[0] = 0;     for (int start = 1; start <= m; start += BLOCK) {       int end = start + BLOCK - 1;       if (end > m) {         end = m;       }       set<pair<int, int>> nowEdges;       nowEdges.clear();       for (int i0 = (start); i0 <= (end); ++i0) {         nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 0, n));         nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 1, n));       }       set<pair<int, int>> possible;       possible.clear();       set<pair<int, int>> impossible;       impossible.clear();       for (int i1 = (1); i1 <= (start - 1); ++i1) {         if (q[i1].cmd == 2) {           continue;         }         auto edge0 = GetEdge(q[i1].x, q[i1].y, last[i1 - 1], n);         if (nowEdges.find(edge0) == nowEdges.end()) {           Switch(edge0, impossible);         } else {           Switch(edge0, possible);         }       }       dsu.init(n);       for (auto edge1 : impossible) {         dsu.mergeFast(edge1.first, edge1.second);       }       for (int i2 = (start); i2 <= (end); ++i2) {         if (q[i2].cmd == 1) {           last[i2] = last[i2 - 1];           Switch(GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n), possible);           continue;         } else {           const int top = dsu.stkSize;           for (auto edge1 : possible) {             dsu.merge(edge1.first, edge1.second);           }           auto queryEdge = GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n);           last[i2] = dsu.find(queryEdge.first) == dsu.find(queryEdge.second);           putchar( 0  + last[i2]);           dsu.undo(top);         }       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const bool debug = false;   int triple[1 << 12][3];   int use[1 << 12];   int cost[1 << 12];   std::vector<int> gen_masks(int L) {     std::vector<int> masks;     masks.push_back(0);     for (int i = 0; i < L; i++) {       for (int j = 1; j < L; j++) {         if (i + j * 2 >= L) continue;         masks.push_back((1 << i) | (1 << (i + j)) | (1 << (i + 2 * j)));       }     }     return masks;   }   int as[100005];   int main() {     std::vector<int> masks = gen_masks(12);     for (int u : masks) {       for (int v : masks) {         for (int w : masks) {           int res = (u ^ v ^ w) & ((1 << 9) - 1);           triple[res][0] = u;           triple[res][1] = v;           triple[res][2] = w;         }       }     }     std::vector<std::array<int, 3> > moves;     int NN;     scanf( %d , &NN);     int N = NN;     for (int i = 1; i <= N; i++) {       scanf( %d , &as[i]);     }     while (N >= 12) {       int M = 0;       for (int i = 0; i < 9; i++) {         M |= (as[N - i] << i);       }       for (int t = 0; t < 3; t++) {         std::array<int, 3> move;         int index = 0;         for (int i = 0; i < 12; i++) {           if (triple[M][t] & (1 << i)) {             as[N - i] ^= 1;             move[index++] = N - i;           }         }         if (index) {           assert(index == 3);           moves.push_back(move);         }       }       N -= 9;     }     N = std::min(NN, 12);     masks = gen_masks(N);     for (int i = 1; i < (1 << N); i++) {       cost[i] = 1e9;     }     for (int mask : masks) {       for (int i = 0; i < (1 << N); i++) {         if (cost[i ^ mask] > cost[i] + 1) {           cost[i ^ mask] = cost[i] + 1;           use[i ^ mask] = mask;         }       }     }     if (debug) {       int worst = 0;       for (int i = 0; i < (1 << N); i++) {         if (cost[i] < 1e9) worst = std::max(worst, cost[i]);         printf( %d:  , i);         for (int k = 0; k < N; k++) {           printf( %d , (use[i] >> k) & 1);         }         printf(  n );       }       printf( WORST: %d n , worst);     }     while (true) {       int M = 0;       for (int i = 0; i < N; i++) {         M |= (as[N - i] << i);       }       if (M == 0) break;       std::array<int, 3> move;       int index = 0;       for (int i = 0; i < 12; i++) {         if (use[M] & (1 << i)) {           as[N - i] ^= 1;           move[index++] = N - i;         }       }       if (index == 0) {         printf( NO n );         return 0;       }       assert(index == 3);       moves.push_back(move);     }     for (int i = 0; i < N; i++) {       assert(as[i] == 0);     }     printf( YES n );     printf( %d n , (int)moves.size());     for (auto move : moves) {       printf( %d %d %d n , move[0], move[1], move[2]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[100010], b[100010], c[100010];   void nhap() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     int dem = 1;     a[1] = c[1];     for (int i = 2; i <= n; i++)       if (c[i] != a[dem]) {         dem++;         a[dem] = c[i];       }     n = dem;   }   void xuli() {     a[0] = 0;     a[n + 1] = 0;     memset(b, 0, sizeof b);     for (int i = 1; i <= n; i++)       if (a[i - 1] == a[i + 1])         b[a[i]] += 2;       else         b[a[i]]++;     int dem = 0, kq;     for (int i = 1; i <= k; i++)       if (dem < b[i]) dem = b[i], kq = i;     cout << kq;   }   int main() {     if (0) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     };     nhap();     xuli();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long n, m, l, r;     vector<long> a(100005);     map<long, vector<long> >::iterator mi;     vector<long>::iterator vi1, vi2;     map<long, vector<long> > hash;     scanf( %ld %ld , &n, &m);     for (long i = 0; i < n; i++) {       scanf( %ld , &a[i]);       if (hash.find(a[i]) != hash.end())         hash[a[i]].push_back(i);       else {         vector<long> v;         v.push_back(i);         hash[a[i]] = v;       }     }     mi = hash.begin();     while (mi != hash.end()) {       if (mi->first > mi->second.size()) {         long temp = mi->first;         mi++;         hash.erase(hash.find(temp));       } else         mi++;     }     long diff = r - l + 1, count = 0;     long first, last;     for (long i = 0; i < m; i++) {       scanf( %ld %ld , &l, &r);       diff = r - l + 1, count = 0;       mi = hash.begin();       while (mi->first <= diff && mi != hash.end()) {         vi1 = upper_bound(mi->second.begin(), mi->second.end(), r - 1);         vi2 = lower_bound(             mi->second.begin(),             mi->second.end() - ((mi->first - 3 > 0) ? (mi->first - 3) : 0),             l - 1);         last = vi1 - mi->second.begin(), first = vi2 - mi->second.begin();         if (last - first == mi->first) count++;         mi++;       }       printf( %ld n , count);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int __SIZE = 1 << 18;   char ibuf[__SIZE], *iS, *iT;   template <typename T>   inline void read(T &x) {     char ch, t = 0;     x = 0;     while (!isdigit(ch = (iS == iT                               ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                                  (iS == iT ? EOF : *iS++))                               : *iS++)))       t |= ch ==  - ;     while (isdigit(ch))       x = x * 10 + (ch ^ 48),       ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                         (iS == iT ? EOF : *iS++))                      : *iS++);     x = t ? -x : x;   }   inline int read_int() {     int x;     return read(x), x;   }   inline long long read_ll() {     long long x;     return read(x), x;   }   template <typename T>   inline void chkmin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   inline void chkmax(T &a, T b) {     a = a > b ? a : b;   }   const int MAXN = 150010;   const int mod = 998244353;   inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }   inline int Mod(int x) { return x >= mod ? x - mod : x; }   inline int fsp(int x, int k = mod - 2) {     int s = 1;     while (k) {       if (k & 1) s = 1LL * s * x % mod;       x = 1LL * x * x % mod, k >>= 1;     }     return s;   }   inline long long S(long long x, long long k) { return (x + x + k - 1) * k / 2; }   inline long long find(long long x, long long k) {     if (!x) return k * (k + 1) >> 1;     long long p = find(x / k, k), rest = x % k;     long long st = (x / k) * (k * k + 1) + rest * k + 1;     if (st + k <= p)       return S(st, k);     else       return S(st, k) + min(k, st + k - p);   }   inline void Solve() {     long long n = read_ll(), k = read_int(), bel = (n - 1) / (k * k + 1);     long long p = find(bel, k);     if (p == n)       cout << (bel + 1) * (k + 1) << endl;     else {       long long pos = n - bel - 1 + (n < p);       long long t = (n - 1) % (k * k + 1) + 1;       long long cnt = bel * k + (t - 1 - (n >= p)) / k;       cout << pos + cnt << endl;     }   }   int main() {     int Case = read_int();     while (Case--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n;     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> x >> y;       mx = max(mx, (x + y));     }     cout << mx << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n];     int unos = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (arr[i]) unos++;     }     int fin = 0;     for (int i = 0; i < n; i++) {       int total = unos;       for (int j = i; j < n; j++) {         if (arr[j])           total--;         else           total++;         fin = max(fin, total);       }     }     printf( %d , fin);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int n, i, f, p, s, rez;   int main() {     cin >> n;     f = 1;     for (i = 1; i <= n; i++) f = ((unsigned long long)f * i) % 998244353;     f = ((unsigned long long)f * n) % 998244353;     p = 1;     s = 0;     for (i = n; i >= 2; i--) {       p = ((unsigned long long)p * i) % 998244353;       s = (s + p) % 998244353;     }     rez = (f - s + 998244353) % 998244353;     cout << rez;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long calc_2(int s) {     if (s < 0) return 0;     return 1LL * (s + 1) * (s + 2) / 2;   }   long long calc_3(int s) {     if (s < 0) return 0;     long long ans = 0;     for (int i = 0; i <= s; i++) ans += calc_2(s - i);     return ans;   }   int val[5];   int main() {     int a, b, c, L;     scanf( %d%d%d%d , &a, &b, &c, &L);     val[1] = a - b - c, val[2] = b - a - c, val[3] = c - a - b;     long long ans = calc_3(L);     for (int i = 1; i <= 3; i++) {       for (int z = 0; z <= L; z++) {         int ed = min(L - z, val[i] + z);         ans -= calc_2(ed);       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 26;   int cost[nmax][3];   const int l = 0, m = 1, w = 2;   map<pair<int, int>, pair<string, int> > myMap;   pair<string, long long> global;   bool ok = 0;   void firstHalf(int a, int b, int c, string s) {     if (myMap.count({a - b, b - c}) == 0 || myMap[{a - b, b - c}].second < a) {       myMap[{a - b, b - c}] = {s, a};     }   }   void findMatch(int a, int b, int c, string s) {     if (myMap.count({b - a, c - b}) != 0) {       int ans = myMap[{b - a, c - b}].second + a;       string fin = myMap[{b - a, c - b}].first + s;       if (ans > global.second) {         ok = 1;         global = {fin, ans};       }     }   }   void solve(int i, const int stop, void (*op)(int, int, int, string), int a,              int b, int c, string s) {     if (i == stop + 1) {       op(a, b, c, s);       return;     }     solve(i + 1, stop, op, a + cost[i][l], b + cost[i][m], c, s +  LM n );     solve(i + 1, stop, op, a + cost[i][l], b, c + cost[i][w], s +  LW n );     solve(i + 1, stop, op, a, b + cost[i][m], c + cost[i][w], s +  MW n );   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> cost[i][l] >> cost[i][m] >> cost[i][w];     global.second = -26 * 10e7;     string pl;     solve(1, n / 2, &firstHalf, 0, 0, 0, pl);     solve(n / 2 + 1, n, &findMatch, 0, 0, 0, pl);     if (ok)       cout << global.first;     else       cout <<  Impossible ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       long long mn = 1e9, mx = -1e9;       long long a[n];       for (int j = 0; j < n; j++) {         cin >> a[j];         mn = min(a[j], mn);         mx = max(a[j], mx);       }       long long x = mn * mx;       int ans = 1;       set<long long> s;       for (int j = 2; j <= sqrt(x); j++) {         if (x % j == 0) {           s.insert(j);           s.insert(x / j);         }       }       int cnt = 0;       for (int j = 0; j < n; j++) {         if (x % a[j] == 0) {           cnt++;         } else {           cnt = -1;           break;         }       }       if (cnt != s.size()) {         cout << -1 << endl;       } else         cout << x << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   class IntTree {    public:     IntTree(int size) : nodes_(4 * size + 10, 0), size_(size) {}     void Set(int pos, char ch) { Set(0, 1, size_, pos, ch); }     int Count(int left, int right) {       int mask = Mask(0, 1, size_, left, right);       return CountBits(mask);     }       private:     static int Left(int node) { return 2 * node + 1; }     static int Right(int node) { return 2 * node + 2; }     static int CountBits(int num);     void Set(int node, int left, int right, int pos, char ch);     int Mask(int node, int left, int right, int x, int y);     vector<int> nodes_;     int size_;   };   int IntTree::CountBits(int num) {     int count = 0;     while (num > 0) {       count += 1;       num -= (num & -num);     }     return count;   }   void IntTree::Set(int node, int left, int right, int pos, char ch) {     if (left == right) {       nodes_[node] = (1 << (ch -  a ));       return;     }     int mid = left + (right - left) / 2;     if (pos <= mid) {       Set(Left(node), left, mid, pos, ch);     } else {       Set(Right(node), mid + 1, right, pos, ch);     }     nodes_[node] = (nodes_[Left(node)] | nodes_[Right(node)]);   }   int IntTree::Mask(int node, int left, int right, int x, int y) {     if (x <= left && right <= y) {       return nodes_[node];     }     int mask = 0;     int mid = left + (right - left) / 2;     if (x <= mid) {       mask |= Mask(Left(node), left, mid, x, y);     }     if (mid < y) {       mask |= Mask(Right(node), mid + 1, right, x, y);     }     return mask;   }   int main() {     string str;     getline(cin, str);     IntTree tree(str.size());     for (size_t i = 0; i < str.size(); i += 1) {       tree.Set(i + 1, str[i]);     }     int queries;     cin >> queries;     for (int i = 0; i < queries; i += 1) {       int type, x, y;       char ch;       cin >> type;       if (type == 1) {         cin >> x >> ch;         tree.Set(x, ch);       } else {         cin >> x >> y;         cout << tree.Count(x, y) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 155;   int in[N][N];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> in[i][j];       }     }     vector<int> ans(N);     for (int v = 1; v < n; v++) {       for (int i = 1; i <= n; i++) {         bool f1 = false;         bool f2 = true;         for (int j = 1; j <= n; j++) {           if (in[i][j] == v)             f1 = true;           else {             if (in[i][j] != -1 and in[i][j] != 0) f2 = false;           }         }         if (f1 && f2) {           ans[i] = v;           for (int j = 1; j <= n; j++) in[i][j] = in[j][i] = -1;           break;         }       }     }     for (int i = 1; i <= n; i++) cout << (ans[i] == 0 ? n : ans[i]) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 9;   int n;   int mp[9];   bool done[109];   vector<pair<long long, pair<long long, long long> > > v[109];   void dfs(int node) {     done[node] = 1;     for (int i = 0; i < v[node].size(); i++) {       int u = v[node][i].first;       int e = v[node][i].second.first;       int f = v[node][i].second.second;       if (done[u]) continue;       mp[f] += e, dfs(u);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       v[a].push_back({b, {c, 1}});       v[b].push_back({a, {c, 0}});     }     dfs(0);     mp[1 - v[0][1].second.second] += v[0][1].second.first;     cout << min(mp[1], mp[0]) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 10;   const long long INF = 1e18;   int n, q;   struct Edge {     int u, v;     long long w;     Edge(int _u = 0, int _v = 0, long long _w = 0) : u(_u), v(_v), w(_w) {}   };   vector<Edge> E;   int E_size;   vector<int> G[N];   int ptr[2 * N];   void adjListInit(int l, int r) {     E.clear();     E_size = 0;     for (int i = l; i <= r; i++) G[i].clear();   }   void addEdge(int u, int v, long long w, int i) {     E.push_back(Edge(u, v, w));     E_size++;     ptr[i] = E_size - 1;     G[u].push_back(E_size - 1);   }   vector<Edge> Eback;   int Gback[N];   int Eback_size;   long long dist[N];   int in[N], out[N];   int peg[N];   int dfs_clock;   inline void dfsInit() {     dist[1] = 0;     dfs_clock = 0;   }   void dfs(int u, int pre) {     in[u] = ++dfs_clock;     peg[in[u]] = u;     for (int i = 0; i < G[u].size(); i++) {       Edge e = E[G[u][i]];       int v = e.v;       if (v == pre) continue;       dist[v] = dist[u] + e.w;       dfs(v, u);     }     out[u] = dfs_clock;   }   struct Node {     int l, r;     long long val, lazy;     void update(long long x) { val += x, lazy += x; }   } node[N << 2];   inline void pushdown(int rt) {     if (node[rt].lazy) {       node[rt << 1].update(node[rt].lazy);       node[rt << 1 | 1].update(node[rt].lazy);       node[rt].lazy = 0;     }   }   inline void pushup(int rt) {     node[rt].val = min(node[rt << 1].val, node[rt << 1 | 1].val);   }   void build(int root, int l, int r) {     node[root].l = l;     node[root].r = r;     node[root].val = 0;     node[root].lazy = 0;     if (l == r) {       int p = peg[l];       node[root].val = dist[p] + Eback[Gback[p]].w;     } else {       int mid = l + (r - l) / 2;       build(root * 2, l, mid);       build(root * 2 + 1, mid + 1, r);       pushup(root);     }   }   void update(int root, int st, int ed, int val) {     if (st > node[root].r || ed < node[root].l) return;     if (st <= node[root].l && node[root].r <= ed)       node[root].update(val);     else {       pushdown(root);       update(root * 2, st, ed, val);       update(root * 2 + 1, st, ed, val);       pushup(root);     }   }   long long query(int root, int st, int ed) {     if (ed < node[root].l || node[root].r < st) return INF;     if (st <= node[root].l && node[root].r <= ed)       return node[root].val;     else {       pushdown(root);       long long lson = query(root * 2, st, ed);       long long rson = query(root * 2 + 1, st, ed);       pushup(root);       return min(lson, rson);     }   }   int main() {     cin >> n >> q;     adjListInit(1, n);     for (int i = 1; i <= n - 1; i++) {       int a, b;       long long c;       scanf( %d%d%I64d , &a, &b, &c);       addEdge(a, b, c, i);     }     dfsInit();     dfs(1, -1);     Eback.clear();     Eback_size = 0;     for (int i = n, a, b, c; i <= 2 * n - 2; i++) {       scanf( %d%d%d , &a, &b, &c);       Eback.push_back(Edge(a, b, c));       Eback_size++;       ptr[i] = Eback_size - 1;       Gback[a] = Eback_size - 1;     }     Eback.push_back(Edge(1, 1, 0));     Eback_size++;     Gback[1] = Eback_size - 1;     build(1, 1, n);     for (int i = 1, type; i <= q; i++) {       scanf( %d , &type);       if (type == 1) {         int id;         long long w;         scanf( %d%I64d , &id, &w);         if (id < n) {           Edge &e = E[ptr[id]];           update(1, in[e.v], out[e.v], w - e.w);           e.w = w;         } else {           Edge &e = Eback[ptr[id]];           update(1, in[e.u], in[e.u], w - e.w);           e.w = w;         }       }       if (type == 2) {         int u, v;         scanf( %d%d , &u, &v);         if (in[u] <= in[v] && in[v] <= out[u]) {           long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w;           long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w;           printf( %I64d n , dv - du);         } else {           long long ans = query(1, in[u], out[u]);           long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w;           long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w;           ans -= du;           ans += dv;           printf( %I64d n , ans);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> a[100004];   int p[100004];   int v[100004];   long long int c[100004];   struct sajal {     long long int add, sub, d;   };   sajal d[100004];   int main() {     long n;     cin >> n;     long x, y;     for (long i = 1; i < n; i++) {       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     queue<long> q;     q.push(1);     p[1] = 1;     while (!q.empty()) {       long f = q.front();       q.pop();       v[f] = 1;       for (long i = 0; i < a[f].size(); i++) {         if (v[a[f][i]] == 0) {           v[a[f][i]] = 1;           q.push(a[f][i]);           p[a[f][i]] = f;         }       }     }     for (long i = 1; i <= n; i++) {       cin >> c[i];       d[i].add = 0;       d[i].sub = 0;       d[i].d = a[i].size();       if (a[i].size() == 1 && i != 1) {         q.push(i);       }     }     long long int add = 0;     long long int sub = 0;     long cur = 1;     while (!q.empty()) {       long f = q.front();       q.pop();       long long int e = d[f].add - d[f].sub;       long long int h = -c[f] - e;       long long int w = p[f];       if (h >= 0) {         d[f].add = d[f].add + h;       } else {         h = -h;         d[f].sub = h + d[f].sub;       }       if (d[f].sub > sub) sub = d[f].sub;       if (d[f].add > add) add = d[f].add;       if (d[w].sub < d[f].sub) d[w].sub = d[f].sub;       if (d[w].add < d[f].add) d[w].add = d[f].add;       d[w].d--;       if (d[w].d == 1 && w != 1) {         q.push(w);       }     }     c[1] = c[1] + d[1].add - d[1].sub;     c[1] = -c[1];     if (c[1] >= 0) {       d[1].add = d[1].add + c[1];     } else {       c[1] = -c[1];       d[1].sub = d[1].sub + c[1];     }     if (add < d[1].add) add = d[1].add;     if (sub < d[1].sub) sub = d[1].sub;     cout << add + sub << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, x;   string s;   int main() {     cin >> n >> m;     r = 0;     l = n + 1;     for (int i = 0; i < m; ++i) {       cin >> s;       cin >> s;       cin >> s;       if (s ==  left ) {         cin >> s >> x;         l = min(l, x);       } else {         cin >> s >> x;         r = max(r, x);       }     }     if (l - r - 1 <= 0)       cout << -1 << endl;     else       cout << l - r - 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string intial, code;     cin >> intial >> code;     int res = 0;     for (int i = 0; i < n; i++) {       int a = (((intial[i] -  0 ) - (code[i] -  0 )) + 10) % 10;       int b = (((code[i] -  0 ) - (intial[i] -  0 )) + 10) % 10;       res += min(a, b);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int e[100010];   int main() {     int n, u, i, j = 3;     double ans = 0;     scanf( %d%d , &n, &u);     for (i = 1; i <= n; i++) scanf( %d , &e[i]);     for (i = 1; i <= n; i++) {       while (j <= n && e[j] - e[i] <= u) j++;       j--;       if (j > i + 1) ans = max(ans, (e[j] - e[i + 1] + 0.0) / (e[j] - e[i]));     }     if (ans == 0)       cout << -1 << endl;     else {       cout.precision(19);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int temperature;       long long int a12, b11;       long long int solution;       cin >> a12 >> b11;       if (b11 == a12) {         solution = 0;       } else if (b11 > a12) {         temperature = b11 - a12;         if (temperature & 1) {           solution = 1;         } else {           solution = 2;         }       } else {         temperature = a12 - b11;         if (temperature & 1) {           solution = 2;         } else {           solution = 1;         }       }       cout << solution <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int a[26];   int w[256];   int n;   int LIMIT = 1;   int su[26], sv[26], sk[26];   int go(int lev) {     if (a[lev] == n) {       printf( %d n , lev);       for (int i = 0; i < lev; i++)         if (su[i] == -1) {           printf( lea e%cx, [%d*e%cx] n ,  a  + i + 1, 1 << sk[i],  a  + sv[i]);         } else if (sk[i] == 0)           printf( lea e%cx, [e%cx + e%cx] n ,  a  + i + 1,  a  + su[i],                   a  + sv[i]);         else           printf( lea e%cx, [e%cx + %d*e%cx] n ,  a  + i + 1,  a  + su[i],                  1 << sk[i],  a  + sv[i]);       return 1;     }     if (lev >= LIMIT) return 0;     int &i = su[lev], &j = sv[lev], &k = sk[lev];     i = -1;     for (j = 0; j <= lev; j++)       for (k = 0; k <= 3; k++) {         int v = (a[j] << k);         if (v > a[lev] && v <= n) {           a[lev + 1] = v;           if (go(lev + 1)) return 1;           a[lev + 1] = 0;         }       }     for (i = 0; i <= lev; i++)       for (j = 0; j <= lev; j++) {         for (k = 0; k <= 3; k++) {           int v = a[i] + (a[j] << k);           if (v > a[lev] && v <= n) {             a[lev + 1] = v;             if (go(lev + 1)) return 1;             a[lev + 1] = 0;           }         }       }     return 0;   }   int main(void) {     scanf( %d , &n);     if (n == 1) {       printf( 0 n );       return 0;     }     a[0] = 1;     w[1] = 1;     for (LIMIT = 1;; LIMIT++) {       if (go(0)) {         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     long long ans = 0;     for (int i = 2; i <= n; i++)       for (int j = i + i; j <= n; j += i) ans += j / i;     cout << ans * 4 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t INF = INT64_MAX / 4;   const int64_t NINF = -INF;   map<pair<int64_t, uint32_t>, int64_t> dp;   int64_t grundy(int64_t pile, uint32_t pattern) {     if (pile == 0) {       return 0;     }     pair<int64_t, uint32_t> key = {pile, pattern};     auto fd = dp.find(key);     if (fd != dp.end()) {       return fd->second;     }     bitset<32> bs(pattern);     set<int64_t> res;     for (int64_t i = 0; i < pile; i++) {       if (!bs[i]) {         bs[i] = true;         res.insert(grundy(pile - (i + 1), bs.to_ulong()));         bs[i] = false;       }     }     int64_t ans = 0;     while (res.find(ans) != res.end()) {       ans++;     }     dp.insert({key, ans});     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int64_t n;     cin >> n;     int64_t ans = 0;     for (int64_t i = 0; i < n; i++) {       int64_t pile;       cin >> pile;       ans ^= grundy(pile, 0);     };     if (ans == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p, q, b, t, g;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b != 0) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> p >> q >> b;       g = gcd(p, q);       q /= g;       while (true) {         g = gcd(b, q);         if (g == 1) break;         while (q % g == 0) q /= g;       }       if (q == 1)         cout <<  Finite ;       else         cout <<  Infinite ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int main() {     long long A, B, C, D, E, F, N, K, M, Z, sum = 0, num = 0, flag = 0;     string S, T;     cin >> Z;     queue<long long> que;     while (Z--) {       cin >> S;       vector<long long> P(0, 0);       num = 0;       S +=  0 ;       for (long long int i = 0; i < S.size(); i++) {         if (S[i] ==  1 )           num++;         else {           P.push_back(num);           num = 0;         }       }       sort(P.begin(), P.end());       reverse(P.begin(), P.end());       sum = 0;       for (long long int i = 0; i < P.size(); i++) {         sum += P[i];         i++;       }       que.push(sum);     }     while (!que.empty()) {       cout << que.front() << endl;       que.pop();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int k, n;     cin >> n >> k;     int x[n];     for (int i = 0; i < n; i++) {       cin >> x[i];     }     double m = -1, sum = 0;     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         c++;         sum += x[j];         if (c >= k && (sum / c) > m) {           m = sum / c;         }       }       c = 0;       sum = 0;     }     cout << setprecision(15) << fixed << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long powm(long long base, long long exp, long long mod = 1000000009) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return ans;   }   long long ctl(char x, char an =  a ) { return (long long)(x - an); }   char ltc(long long x, char an =  a ) { return (char)(x + an); }   long long first[300005], pref[300005], pref_fib[300005], a[300005];   long long get_fibo_sum(long long l, long long r) {     return (pref_fib[r] - (l ? pref_fib[l - 1] : 0) + 1000000009) % 1000000009;   }   long long get_fibo(long long st1, long long st2, long long i) {     if (i == 0)       return st1;     else if (i == 1)       return st2;     else {       long long ret = ((first[i - 1] * st2) % 1000000009 +                        (first[i - 2] * st1) % 1000000009) %                       1000000009;       return ret;     }   }   long long get_fibo_sum(long long st1, long long st2, long long i) {     if (i == 0)       return st1;     else if (i == 1)       return (st1 + st2) % 1000000009;     else {       long long ans = (st2 * get_fibo_sum(1, i - 1)) % 1000000009;       ans = (ans + (st1 * get_fibo_sum(0, i - 2)) % 1000000009) % 1000000009;       ans = (ans + st1) % 1000000009;       ans = (ans + st2) % 1000000009;       return ans;     }   }   const pair<long long, long long> khali = make_pair(0LL, 0LL);   struct lazySegTree {     long long tree[4 * 300005], x, y, val;     pair<long long, long long> lazy[4 * 300005];     void push(long long low, long long high, long long pos) {       if (lazy[pos] != khali) {         tree[pos] +=             get_fibo_sum(lazy[pos].first, lazy[pos].second, (high - low));         if (low != high) {           pair<long long, long long> tmp;           tmp = lazy[pos];           lazy[2 * pos + 1].first =               (lazy[2 * pos + 1].first + tmp.first) % 1000000009;           lazy[2 * pos + 1].second =               (lazy[2 * pos + 1].second + tmp.second) % 1000000009;           tmp.first = get_fibo(lazy[pos].first, lazy[pos].second,                                (low + high) / 2 - low + 1);           tmp.second = get_fibo(lazy[pos].first, lazy[pos].second,                                 (low + high) / 2 - low + 2);           lazy[2 * pos + 2].first =               (lazy[2 * pos + 2].first + tmp.first) % 1000000009;           lazy[2 * pos + 2].second =               (lazy[2 * pos + 2].second + tmp.second) % 1000000009;         }         lazy[pos] = khali;       }     }     long long query(long long low, long long high, long long pos) {       push(low, high, pos);       if (x <= low and y >= high) return tree[pos];       if (x > high || y < low) return 0;       long long mid = (high + low) / 2;       return (query(low, mid, 2 * pos + 1) + query(mid + 1, high, 2 * pos + 2)) %              1000000009;     }     void update(long long low, long long high, long long pos) {       push(low, high, pos);       if (x > high || y < low) return;       if (x <= low and y >= high) {         lazy[pos].first = first[low - x];         lazy[pos].second = first[low - x + 1];         push(low, high, pos);         return;       }       long long mid = (low + high) / 2;       update(low, mid, 2 * pos + 1), update(mid + 1, high, 2 * pos + 2);       tree[pos] = (tree[2 * pos + 1] + tree[2 * pos + 2]) % 1000000009;     }   } lst;   int main() {     first[0] = 1, first[1] = 1;     for (long long i = 2; i < 300005; i++)       first[i] = (first[i - 1] + first[i - 2]) % 1000000009;     for (long long i = 0; i < 4 * 300005; i++) lst.lazy[i] = khali;     long long type, l, r, n, q;     cin >> n >> q;     for (long long i = 1; i < n + 1; i++) cin >> a[i];     pref_fib[0] = 1;     for (long long i = 1; i < 300005; i++)       pref_fib[i] = (pref_fib[i - 1] + first[i]) % 1000000009;     pref[1] = a[1];     for (long long i = 1; i < 300005; i++)       pref[i] = (pref[i - 1] + a[i]) % 1000000009;     while (q--) {       cin >> type >> l >> r;       lst.x = l, lst.y = r;       if (type == 1) {         lst.update(1, n, 0);       } else {         long long ans = lst.query(1, n, 0);         ans = (ans + pref[r]) % 1000000009;         ans = (ans - pref[l - 1] + 1000000009) % 1000000009;         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   void solve() {     int n;     std::cin >> n;     std::stack<int> q;     int a = 0;     int cur = 1;     n += n;     while (n--) {       std::string s;       std::cin >> s;       if (s[0] ==  r ) {         if (!q.empty() && q.top() != cur) {           while (!q.empty()) q.pop();           ++a;         }         if (!q.empty()) q.pop();         ++cur;       } else {         int x;         std::cin >> x;         q.push(x);       }     }     std::cout << a;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool smin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool smax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 1e5 + 100, lg = 22;   long long n, k, add[N], h[N];   vector<pair<long long, long long> > adj[N];   long long par[N][lg];   void dfs(long long v = 1, long long p = -1, long long dep = 0) {     if (v != 1) {       par[v][0] = p;       for (long long i = 1; i < lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];     } else {       for (long long i = 0; i < lg; i++) par[v][i] = v;     }     h[v] = dep;     for (auto u : adj[v])       if (u.first != p) dfs(u.first, v, dep + 1);   }   long long getPar(long long v, long long k) {     for (long long i = lg - 1; i >= 0; i--)       if (k >> i & 1) v = par[v][i];     return v;   }   long long lca(long long u, long long v) {     if (h[u] > h[v]) swap(u, v);     v = getPar(v, h[v] - h[u]);     if (u == v) return v;     for (long long i = lg - 1; i >= 0; i--) {       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     }     return par[v][0];   }   long long ans[N];   long long calc(long long v = 1, long long p = -1, long long want = -1) {     long long res = add[v];     for (auto u : adj[v]) {       if (u.first == p) continue;       res += calc(u.first, v, u.second);     }     if (want != -1) ans[want] = res;     return res;   }   int32_t main() {     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       adj[v].push_back({u, i}), adj[u].push_back({v, i});     }     dfs();     cin >> k;     while (k--) {       long long u, v;       cin >> u >> v;       long long l = lca(u, v);       add[u]++, add[v]++, add[l] -= 2;     };     calc();     for (long long i = 0; i < n - 1; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int arr[n][4];     multiset<int> s[4];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 4; j++) {         cin >> arr[i][j];         s[j].insert(arr[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < 4; j++) {         auto temp = s[j].find(arr[i][j]);         s[j].erase(temp);       }       if (*s[0].rbegin() <= *s[2].begin() && *s[1].rbegin() <= *s[3].begin()) {         cout << *s[0].rbegin() <<     << *s[1].rbegin() << endl;         break;       }       for (int j = 0; j < 4; j++) s[j].insert(arr[i][j]);     }     return 0;   }