#include <bits/stdc++.h>   using namespace std;   vector<int> v[100005];   vector<pair<int, int> > asdf;   int n;   int m;   int cnt[100005];   vector<int> nxt[100005];   void build(int at, int num) {     if (cnt[at] > 2) return;     if (num == m) {       while ((int)asdf.size()) {         printf( %d %d n , 1 + asdf.back().first, 1 + asdf.back().second);         asdf.pop_back();       }       exit(0);     }     if (cnt[at] == 2) return;     int a, b;     if ((int)v[at].size() != 0) {       a = v[at].front();       b = v[at].back();     } else {       a = -1, b = -1;     }     int c, d;     if ((int)nxt[at].size()) {       c = nxt[at].back();       d = nxt[at].front();     } else {       c = d = -1;     }     for (auto(i) = (at + 1); (i) != (n); (i)++) {       if (i != d && i != c && i != a && i != b && cnt[i] < 2) {         asdf.push_back(make_pair(i, at));         cnt[at]++;         cnt[i]++;         nxt[at].push_back(i);         nxt[i].push_back(at);         build(i, num + 1);         nxt[at].pop_back();         nxt[i].pop_back();         cnt[at]--;         cnt[i]--;         asdf.pop_back();       }     }     if (cnt[at] > 0 && cnt[at] < 2) {       c = nxt[at].front();       d = nxt[at].back();       for (auto(i) = (0); (i) != (at); (i)++) {         if (cnt[i] < 2 && i != a && i != b && i != c && i != d) {           asdf.push_back(make_pair(i, at));           cnt[at]++;           cnt[i]++;           nxt[at].push_back(i);           nxt[i].push_back(at);           build(i, num + 1);           nxt[at].pop_back();           nxt[i].pop_back();           cnt[at]--;           cnt[i]--;           asdf.pop_back();         }       }     } else {       c = d = -1;       for (auto(i) = (0); (i) != (at); (i)++) {         if (i != c && i != d && i != a && i != b && cnt[i] < 2) {           asdf.push_back(make_pair(i, at));           cnt[at]++;           cnt[i]++;           nxt[at].push_back(i);           nxt[i].push_back(at);           build(i, num + 1);           nxt[at].pop_back();           nxt[i].pop_back();           cnt[at]--;           cnt[i]--;           asdf.pop_back();         }       }     }   }   int main() {     cin >> n >> m;     for (auto(i) = (0); (i) != (m); (i)++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].push_back(b), v[b].push_back(a);     }     int kek = 0;     for (auto(i) = (0); (i) != (n); (i)++)       kek += (min(2, (n - 1 - (int)v[i].size())));     kek /= 2;     if (kek < m) {       puts( -1 );       return 0;     }     for (auto(i) = (0); (i) != (n); (i)++) build(i, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4;   vector<int> adj[N];   int deg[N];   int lv[N];   int decr[N];   int vis[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     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);       deg[x]++;       deg[y]++;     }     queue<pair<int, int>> q;     bool yes = n > 3;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.push({i, 0}), lv[i] = 1, decr[i] = 3;     while (!q.empty()) {       auto tmp = q.front();       q.pop();       int u = tmp.first;       int p = tmp.second;       vis[u] = 1;       if (decr[u] < 3) yes = false;       for (auto v : adj[u]) {         if (vis[v]) continue;         if (lv[v] != 0 && lv[v] != lv[u] + 1) {           yes = false;         }         lv[v] = lv[u] + 1;         deg[v]--;         decr[v]++;         if (lv[v] == k + 1 && deg[v] == 0)           q.push({v, u});         else if (deg[v] == 1)           q.push({v, u});       }     }     int mx = 0;     for (int i = 1; i <= n; i++) mx = max(mx, lv[i]);     yes &= (mx == k + 1);     puts(yes ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5000000;   void solve1(char *S) {     int lenS = strlen(S);     for (int i = 0, j = lenS - 1; i < j; i++, j--)       if (S[i] < S[j])         break;       else if (S[i] > S[j]) {         for (i = 0, j = lenS - 1; i < j; i++, j--) swap(S[i], S[j]);         break;       }     puts(S);   }   void lyndon(char *S, int *f, int lenS) {     int cnt = 0;     for (int i = 0; i < lenS; i++) f[i] = 0;     for (int i = 0; i < lenS;) {       int j = i, k = i + 1;       while (k < lenS && S[j] <= S[k]) j = (S[j] == S[k] ? j + 1 : i), k++;       int t = k - j;       cnt++;       while (i + t - 1 < k) f[i + t - 1] = cnt, i += t;     }   }   void algorithmZ(char *S, int *f, int lenS) {     f[0] = lenS;     int mx = 0, ps = 0;     for (int i = 1; i < lenS; i++) {       f[i] = (i <= mx ? min(mx - i + 1, f[i - ps]) : 0);       while (S[f[i]] == S[i + f[i]]) f[i]++;       if (i + f[i] - 1 > mx) mx = i + f[i] - 1, ps = i;     }   }   char ans[MAXN + 5], T[2 * MAXN + 5];   int f[2 * MAXN + 5];   int cmp(int l, int r) {     int p = f[l];     if (p >= r - l + 1)       return 0;     else       return (T[l + p] < T[p] ? -1 : 1);   }   bool cmp2(char *S, char *T, int n) {     for (int i = 0; i < n; i++) {       if (S[i] < T[i])         return true;       else if (S[i] > T[i])         return false;     }     return true;   }   void update(char *T, int lenS) {     if (cmp2(T, ans, lenS))       for (int i = 0; i < lenS; i++) ans[i] = T[i];   }   int get(int x) {     int p;     for (p = x - 1; p >= 0 && f[p] == 0; p--)       ;     return p;   }   void update2(char *S, int x, int lenS) {     for (int i = 0; i < x; i++) T[i] = S[x - i - 1];     for (int i = x; i < lenS; i++) T[i] = S[i];     update(T, lenS);     for (int i = x, j = lenS - 1; i < j; i++, j--) swap(T[i], T[j]);     update(T, lenS);   }   void solve2(char *S) {     int lenS = strlen(S);     for (int i = 0; i < lenS; i++) ans[i] = S[i];     for (int i = 0; i < lenS; i++) T[lenS - i - 1] = S[i], T[lenS + i + 1] = S[i];     algorithmZ(T, f, 2 * lenS + 1);     int pos = 0;     for (int i = 1; i < lenS - 1; i++) {       int t = cmp(lenS + 1 + pos + 1, lenS + 1 + i);       if (t == 0) {         if (cmp(i - pos, lenS - pos - 2) == 1) pos = i;       } else if (t == -1)         pos = i;     }     for (int i = 0; i < lenS; i++) T[i] = S[i];     for (int i = pos + 1, j = lenS - 1; i < j; i++, j--) swap(T[i], T[j]);     update(T, lenS);     for (int i = 0; i < lenS; i++) T[lenS - i - 1] = S[i];     lyndon(T, f, lenS);     int tmp = get(lenS - 1);     while (tmp >= 0 && f[tmp] == f[lenS - 1]) tmp = get(tmp);     update2(S, lenS - tmp - 1, lenS);     if (tmp >= 0) {       int p = get(tmp);       while (p >= 0 && f[p] == f[tmp]) p = get(p);       update2(S, lenS - p - 1, lenS);     }     puts(ans);   }   void print(int l, int r) {     for (int i = l; i <= r; i++) putchar(T[i]);   }   char S[MAXN + 5];   int main() {     int k;     scanf( %s%d , S, &k);     if (k == 1)       solve1(S);     else {       int lenS = strlen(S);       for (int i = 0; i < lenS; i++) T[lenS - i - 1] = S[i];       lyndon(T, f, lenS);       int lst = lenS - 1, len = 0, tmp = 0;       while (k >= 2 && lst >= 0) {         int p = get(lst);         if (!(len == 1 && lst - p == 1) && !(f[lst] == tmp)) {           if (k == 2) break;           k--;         }         print(p + 1, lst);         len = lst - p, tmp = f[lst], lst = p;       }       if (lst >= 0) solve2(S + (lenS - lst - 1));     }   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 1e5 + 100;   const int INF = 1e9;   const double eps = 1e-7;   void solve() {     int n;     cin >> n;     vector<long long> a(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.begin() + n);     for (int i = n - 1; i > -1; i--) {       cout << a[i % 2 ? n - 1 - i / 2 : i / 2] <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long> hs, vs;   multiset<long long> hms, vms;   int main() {     long long h, w, t, n, i, j, k, l;     char c;     cin >> w >> h >> n;     hs.insert(0);     hs.insert(h);     vs.insert(0);     vs.insert(w);     hms.insert(h);     vms.insert(w);     for (i = 0; i < n; i++) {       cin >> c >> j;       if (c ==  H ) {         hs.insert(j);         auto q = hs.find(j);         auto p = q;         auto r = q;         p--;         r++;         hms.erase(hms.find(*r - *p));         hms.insert(*q - *p);         hms.insert(*r - *q);       } else {         vs.insert(j);         auto q = vs.find(j);         auto p = q;         auto r = q;         p--;         r++;         vms.erase(vms.find(*r - *p));         vms.insert(*q - *p);         vms.insert(*r - *q);       }       cout << (*hms.rbegin()) * (*vms.rbegin()) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, a[101], d = 0, x = 0, y = 0, m = 0, p = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       m = max(m, a[i]);       p = min(p, a[i]);       if (a[i] > 0)         x++;       else if (a[i] < 0)         y++;     }     float z = ceil(n / 2.0);     if (x >= z)       d = m;     else if (y >= z)       d = p;     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pr1(T a) {     cout << a;     cout <<   n ;   }   template <class T, class T2>   void pr2(T a, T2 b) {     cout << a <<     << b;     cout <<   n ;   }   template <class T, class T2, class T3>   void pr3(T a, T2 b, T3 c) {     cout << a <<     << b <<     << c;     cout <<   n ;   }   template <class T>   void PR(T a, int n) {     for (int i = (int)(0); i < (int)(n); i++) {       if (i) cout <<    ;       cout << a[i];     }     cout <<   n ;   }   bool check(int n, int m, int x, int y) {     return x >= 0 && x < n && y >= 0 && y < m;   }   const long long MAX = 1000000007, MAXL = 1LL << 60, dx[4] = {-1, 0, 1, 0},                   dy[4] = {0, 1, 0, -1};   void Main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double r = d / 2;     double t = v / (r * r * M_PI);     double ans = h / (t - e);     if (ans < 0)       pr1( NO );     else {       printf( YES n );       printf( %.10f n , ans);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int in(char &c) { return scanf( %c , &c); }   int in(char s[]) { return scanf( %s , s); }   int in(int &x) { return scanf( %d , &x); }   int in(long long &x) { return scanf( %lld , &x); }   int in(double &x) { return scanf( %lf , &x); }   int in(pair<int, int> &p) { return scanf( %d%d , &p.first, &p.second); }   int in(pair<long long, long long> &p) {     return scanf( %lld%lld , &p.first, &p.second);   }   int in(pair<double, double> &p) { return scanf( %lf%lf , &p.first, &p.second); }   int in(long double &a) { return scanf( %Lf , &a); }   int in(int &x, long long &y) { return scanf( %d%lld , &x, &y); }   int in(long long &x, int &y) { return scanf( %lld%d , &x, &y); }   int in(int &x, int &y) { return scanf( %d%d , &x, &y); }   int in(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int in(char s[], int &n) { return scanf( %s%d , s, &n); }   int in(int &n, char s[]) { return scanf( %d%s , &n, s); }   int in(char a[], char b[]) { return scanf( %s%s , a, b); }   int in(double &x, double &y) { return scanf( %lf%lf , &x, &y); }   int in(int &n, char s[], char t[]) { return scanf( %d%s%s , &n, s, t); }   int in(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int in(long long &x, long long &y, long long &z) {     return scanf( %lld%lld%lld , &x, &y, &z);   }   int in(double &x, double &y, double &z) {     return scanf( %lf%lf%lf , &x, &y, &z);   }   int in(int &x, int &y, int &z, int &k) {     return scanf( %d%d%d%d , &x, &y, &z, &k);   }   int in(long long &x, long long &y, long long &z, long long &k) {     return scanf( %lld%lld%lld%lld , &x, &y, &z, &k);   }   int in(double &x, double &y, double &z, double &k) {     return scanf( %lf%lf%lf%lf , &x, &y, &z, &k);   }   const int N = 3e5 + 10, M = 1e3 + 10, mod = 1e9 + 7;   const double eps = 1e-6, Pi = acos(-1.0);   vector<int> g[N];   int dep[N], vis[N], op[N], u[N], v[N], In[N], col[N], use[N], Out[N];   queue<int> que;   int topsort(int n) {     for (int i = 1; i <= n; i++) {       if (In[i] == 0) {         que.push(i);       }     }     int cnt = 0;     while (!que.empty()) {       int u = que.front();       que.pop();       dep[u] = ++cnt;       for (auto e : g[u]) {         In[e]--;         if (In[e] == 0) {           que.push(e);         }       }     }     return (n != cnt);   }   int main() {     int T, c = 0, t;     in(T);     t = T;     while (T--) {       c++;       int n, m;       in(n, m);       for (int i = 1; i <= n; i++) In[i] = dep[i] = vis[i] = 0, g[i].clear();       for (int i = 1; i <= m; i++) {         in(op[i], u[i], v[i]);         if (op[i] == 1) {           In[v[i]]++;           g[u[i]].push_back(v[i]);         }       }       if (topsort(n)) {         printf( NO n );         continue;       }       printf( YES n );       for (int i = 1; i <= m; i++) {         if (op[i] == 0) {           if (dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);         }         printf( %d %d n , u[i], v[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int par[4000];   long long int sub[4000];   long long int n;   vector<long long int> adj[4000];   long long int dp[4000][4000];   long long int conec[4000][4000];   void dfsc(long long int node, long long int cur, long long int dir,             long long int prev) {     conec[node][cur] = dir;     long long int ele = adj[cur].size();     for (long long int i = 0; i <= ele - 1; i++) {       if (adj[cur][i] != prev) {         dfsc(node, adj[cur][i], dir, cur);       }     }   }   void dfss(long long int node) {     sub[node] = 1;     long long int ele = adj[node].size();     for (long long int i = 0; i <= ele - 1; i++) {       if (par[node] != adj[node][i]) {         par[adj[node][i]] = node;         dfss(adj[node][i]);         sub[node] += sub[adj[node][i]];       }     }   }   long long int depth(long long int now, long long int pr) {     if (adj[now].size() == 1) return 0;     long long int ret = 0;     for (long long int i = 0; i <= adj[now].size() - 1; i++) {       if (adj[now][i] != pr) ret = max(ret, depth(adj[now][i], now));     }     return 1 + ret;   }   void dfs(long long int start, long long int fin) {     if (dp[start][fin] != -1) return;     if (par[start] == fin) {       dp[start][fin] = sub[start] * (n - sub[start]);       return;     }     if (par[fin] == start) {       dp[start][fin] = sub[fin] * (n - sub[fin]);       return;     }     dfs(conec[start][fin], fin);     dfs(start, conec[fin][start]);     long long int lef, rig;     if (par[start] == conec[start][fin])       lef = sub[start];     else       lef = n - sub[conec[start][fin]];     if (par[fin] == conec[fin][start])       rig = sub[fin];     else       rig = n - sub[conec[fin][start]];     dp[start][fin] =         lef * rig + max(dp[start][conec[fin][start]], dp[conec[start][fin]][fin]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int cur, TESTS, q, a, m, s, b, r, c, k, p, w, d, x, i, j, y, z, xs,         ys, t;     TESTS = 1;     memset(par, -1, sizeof(par));     memset(dp, -1, sizeof(dp));     while (TESTS--) {       cin >> n;       for (long long int i = 0; i <= n - 2; i++) {         cin >> a >> b;         a--;         b--;         adj[a].push_back(b);         adj[b].push_back(a);       }       dfss(0);       for (long long int i = 0; i <= n - 1; i++) {         long long int ele = adj[i].size();         for (long long int j = 0; j <= ele - 1; j++) {           dfsc(i, adj[i][j], adj[i][j], i);         }       }       for (long long int i = 0; i <= n - 1; i++) {         for (long long int j = 0; j <= n - 1; j++) {           if (i == j) continue;           dfs(i, j);         }       }       long long int ans = 0;       for (long long int i = 0; i <= n - 1; i++)         for (long long int j = 0; j <= n - 1; j++) ans = max(ans, dp[i][j]);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   struct intmod {     long long val;     intmod(long long _val = 1) {       val = _val % MOD;       if (val < 0) val += MOD;     }     bool operator!=(intmod rhs) const { return val != rhs.val; }     bool operator==(intmod rhs) const { return val == rhs.val; }     intmod operator+=(intmod rhs) {       val += rhs.val;       if (val >= MOD) val -= MOD;       return *this;     }     intmod operator-=(intmod rhs) {       val -= rhs.val;       if (val < 0) val += MOD;       return *this;     }     intmod operator*=(intmod rhs) {       val = val * rhs.val % MOD;       return *this;     }     friend intmod operator+(intmod lhs, intmod rhs) { return lhs += rhs; }     friend intmod operator-(intmod lhs, intmod rhs) { return lhs -= rhs; }     friend intmod operator*(intmod lhs, intmod rhs) { return lhs *= rhs; }     friend intmod sqr(intmod a) { return a * a; }     friend intmod bpow(intmod a, int p) {       intmod ans(1);       while (p) {         if (p & 1) ans *= a;         a = sqr(a);         p >>= 1;       }       return ans;     }     friend intmod inv(intmod a) { return bpow(a, MOD - 2); }     intmod operator/=(intmod rhs) { return (*this) *= inv(rhs); }     friend intmod operator/(intmod lhs, intmod rhs) { return lhs /= rhs; }     friend istream &operator>>(istream &is, intmod &im) { return is >> im.val; }     friend ostream &operator<<(ostream &os, intmod im) { return os << im.val; }   };   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     cout << bpow(intmod(2), n + m) << endl;     return 0;   }


#include <bits/stdc++.h>   long long int power(long long int x, long long int n) {     long long int result = 1;     while (n) {       if (n % 2 == 1) result = result * x;       n = n / 2;       x = x * x;     }     return result;   }   long long int gcd(long long int a, long long int b) {     if (!b) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int BS(long long int a[], long long int s, long long int n,                    long long int val) {     long long int mid, beg = s, end = n - 1;     while (beg <= end) {       mid = (beg + end) / 2;       if (val == a[mid]) {         break;       } else if (val > a[mid]) {         beg = mid + 1;       } else {         end = mid - 1;       }     }     return mid;   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int d, ans = 0;       d = (n / 2) + 1;       long long int a[n * k];       for (long long int i = 0; i < n * k; i++) cin >> a[i];       long long int count = k;       if (n != 2 && n != 1) {         for (long long int j = n * k - d; j >= 0; j -= d) {           ans += a[j];           count--;           if (count == 0) break;         }         cout << ans <<   n ;       } else if (n == 2) {         long long int x = k;         for (long long int i = 0; i < n * k; i++) {           ans += a[i];           x--;           i++;           if (x == 0) break;         }         cout << ans <<   n ;       } else if (n == 1) {         for (long long int i = 0; i < n * k; i++) ans += a[i];         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char with[1005], make[1005];     int count1[26], count2[26], ans = 0;     bool flag = false;     scanf( %s , with);     memset(count1, 0, sizeof(count1));     memset(count2, 0, sizeof(count2));     for (int i = 0; with[i]; i++) {       count1[with[i] -  a ]++;     }     int m;     scanf( %s , make);     for (int j = 0; make[j]; j++) {       count2[make[j] -  a ]++;     }     for (int i = 0; i <= 25; i++) {       if (count1[i] >= count2[i])         ans += count2[i];       else if (count1[i] < count2[i] && count1[i] > 0)         ans += count1[i];       else         flag = true;     }     if (flag) {       cout <<  -1  << endl;     } else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y;   string s;   bool v[505][505];   bool judge(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); }   int dirx(char x) {     if (x ==  L  || x ==  R ) return 0;     if (x ==  U ) return -1;     return 1;   }   int diry(char x) {     if (x ==  U  || x ==  D ) return 0;     if (x ==  L ) return -1;     return 1;   }   int main() {     cin >> n >> m >> x >> y;     cin >> s;     int len = (int)s.length();     int nx, ny;     v[x][y] = true;     printf( 1  );     for (int i = 0; i < len - 1; ++i) {       nx = x + dirx(s[i]);       ny = y + diry(s[i]);       if (!judge(nx, ny)) {         printf( 0  );         continue;       }       x = nx;       y = ny;       if (v[x][y])         printf( 0  );       else {         v[x][y] = true;         printf( 1  );       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (!v[i][j]) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int v[1 << 20], n, L = 1048575;   void R(int i) {     if (~i) {       int p;       for (; v[p = L ^ i] || p > n; L /= 2)         ;       v[p] = 1;       R(i - 1);       printf( %d  , p);     }   }   int main() {     scanf( %d , &n);     printf( %lld n , 1LL * n * (n + 1));     R(n);   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     unordered_map<char, int> v;     int cnt = 0;     int j = 0;     for (int i1 = 1; i1 <= n; ++i1) {       char ch;       string second;       cin >> ch >> second;       if (ch ==  ! ) {         if (cnt == 0) {           for (int i = 0; i < second.length(); ++i) {             if (v[second[i]] == 0) {               v[second[i]] = 1;             }           }           cnt++;         } else {           unordered_map<char, int> v1;           for (int i = 0; i < second.length(); ++i) {             if (v1[second[i]] == 0) {               v1[second[i]] = 1;             }           }           for (char ch1 =  a ; ch1 <=  z ; ++ch1) {             if (v[ch1] == 1 && v1[ch1] == 1) {               v[ch1] = 1;             } else {               v[ch1] = -1;             }           }         }       } else if (ch ==  . ) {         if (cnt == 0) {           for (int i = 0; i < second.length(); ++i) {             v[second[i]] = -1;           }         } else {           for (int i = 0; i < second.length(); ++i) {             v[second[i]] = -1;           }         }       } else {         if (i1 != n) {           v[second[0]] = -1;         }       }       int sum = 0, sum1 = 0;       for (char ch1 =  a ; ch1 <=  z ; ++ch1) {         if (v[ch1] == 1) {           sum += 1;         } else if (v[ch1] == -1) {           sum1--;         }       }       j++;       if (sum == 1 || sum1 == -25) {         break;       }     }     int totSum = 0;     for (int i = j + 1; i <= n; ++i) {       char ch;       string second;       cin >> ch >> second;       if (ch ==  ! ) {         totSum++;       } else if (ch ==  ?  && i != n) {         totSum++;       }     }     cout << totSum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   const int MAXM = 300000;   struct node {     int key, id, rev;     int siz1, siz2, s;     node *fa, *ch[2], *mx;   } tree[MAXN + MAXM + 5], *ad[MAXN + MAXM + 5];   struct edge {     int u, v, w, id;     edge(int _u = 0, int _v = 0, int _w = 0, int _i = 0)         : u(_u), v(_v), w(_w), id(_i) {}   } e[MAXM + 5];   bool operator<(edge a, edge b) {     if (a.w == b.w) return a.id < b.id;     return a.w < b.w;   }   set<edge> Set;   set<edge>::iterator it;   node *NIL, *ncnt;   void Init() {     NIL = ncnt = &tree[0];     NIL->fa = NIL->ch[0] = NIL->ch[1] = NIL->mx = NIL;     NIL->key = -1;   }   bool IsRoot(node *x) {     return (x->fa == NIL) || (x->fa->ch[0] != x && x->fa->ch[1] != x);   }   void SetChild(node *x, node *y, int d) {     x->ch[d] = y;     if (y != NIL) y->fa = x;   }   node *NewNode(int k, int id, int s) {     ncnt++;     ncnt->key = k, ncnt->id = id, ncnt->s = ncnt->siz1 = s;     ncnt->fa = ncnt->ch[0] = ncnt->ch[1] = NIL;     ncnt->mx = ncnt;     return ncnt;   }   void PushDown(node *x) {     if (x->rev) {       swap(x->ch[0], x->ch[1]);       if (x->ch[0] != NIL) x->ch[0]->rev ^= 1;       if (x->ch[1] != NIL) x->ch[1]->rev ^= 1;       x->rev = 0;     }   }   void PushUp(node *x) {     if (x->key > x->ch[0]->mx->key && x->key > x->ch[1]->mx->key)       x->mx = x;     else if (x->ch[0]->mx->key > x->ch[1]->mx->key)       x->mx = x->ch[0]->mx;     else       x->mx = x->ch[1]->mx;     x->siz1 = x->s + x->ch[0]->siz1 + x->ch[1]->siz1 + x->siz2;   }   void Rotate(node *x) {     node *y = x->fa;     PushDown(y), PushDown(x);     int d = (y->ch[1] == x);     if (IsRoot(y))       x->fa = y->fa;     else       SetChild(y->fa, x, y->fa->ch[1] == y);     SetChild(y, x->ch[!d], d);     SetChild(x, y, !d);     PushUp(y);   }   void Splay(node *x) {     PushDown(x);     while (!IsRoot(x)) {       node *y = x->fa;       if (IsRoot(y))         Rotate(x);       else {         if ((y->fa->ch[1] == y) == (y->ch[1] == x))           Rotate(y);         else           Rotate(x);         Rotate(x);       }     }     PushUp(x);   }   void Access(node *x) {     node *y = NIL;     while (x != NIL) {       Splay(x);       x->siz2 += x->ch[1]->siz1;       x->ch[1] = y;       x->siz2 -= x->ch[1]->siz1;       PushUp(x);       y = x, x = x->fa;     }   }   void MakeRoot(node *x) {     Access(x), Splay(x);     x->rev ^= 1;   }   void Link(node *x, node *y) {     MakeRoot(x);     MakeRoot(y);     x->fa = y;     y->siz2 += x->siz1;   }   void Cut(node *x, node *y) {     MakeRoot(x);     Access(y), Splay(y);     y->ch[0] = x->fa = NIL;     PushUp(y);   }   node *FindRoot(node *x) {     Access(x), Splay(x);     node *ret = x;     while (ret->ch[0] != NIL) ret = ret->ch[0];     PushUp(ret);     return ret;   }   node *LCA(node *x, node *y) {     Access(x), Splay(x);     Splay(y);     while (y->fa != NIL) {       y = y->fa;       Splay(y);     }     return y;   }   node *QueryMAX(node *x, node *y) {     node *z = LCA(x, y);     node *ret = z;     Access(x), Splay(z);     if (z->ch[1]->mx->key > ret->key) ret = z->ch[1]->mx;     Access(y), Splay(z);     if (z->ch[1]->mx->key > ret->key) ret = z->ch[1]->mx;     return ret;   }   int n, m, stot;   void Debug() {     for (it = Set.begin(); it != Set.end(); it++)       printf( (%d, %d, %d) n , it->u, it->v, it->w);   }   int main() {     Init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) ad[i] = NewNode(-1, -1, 1);     stot = n;     for (int i = 1; i <= m; i++) {       e[i].id = i;       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       if (e[i].u == e[i].v) continue;       ad[n + i] = NewNode(e[i].w, i, 0);       Set.insert(e[i]);       if (FindRoot(ad[e[i].u]) == FindRoot(ad[e[i].v])) {         node *p = QueryMAX(ad[e[i].u], ad[e[i].v]);         Splay(p);         if (p->key > e[i].w) {           Set.erase(e[p->id]);           Cut(p, ad[e[p->id].u]), Cut(p, ad[e[p->id].v]);           Link(ad[e[i].u], ad[n + i]), Link(ad[e[i].v], ad[n + i]);         } else           Set.erase(e[i]);       } else {         MakeRoot(ad[e[i].u]), MakeRoot(ad[e[i].v]);         if (ad[e[i].u]->siz1 % 2 == 1 && ad[e[i].v]->siz1 % 2 == 1) stot -= 2;         Link(ad[e[i].u], ad[n + i]), Link(ad[e[i].v], ad[n + i]);       }       if (stot == 0) {         it = Set.end();         it--;         while (true) {           node *p = ad[n + it->id], *q = ad[e[it->id].u], *r = ad[e[it->id].v];           MakeRoot(p);           Access(q);           Access(r);           if (q->siz1 & 1) break;           Access(q);           if (r->siz1 & 1) break;           Set.erase(it);           it = Set.end();           it--;         }         it = Set.end();         it--;         printf( %d n , it->w);       } else         printf( -1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long ar[1000010];   int main() {     long long n;     cin >> n;     long long ans = 0;     if (n % 2 == 1)       puts( 0 );     else {       n = n / 2;       n = (n - 1) / 2;       cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, m, k, par[maxn], ans[maxn];   bool arr[maxn];   pair<int, pair<int, int>> e[maxn];   int get_path(int v) { return par[v] < 0 ? v : (par[v] = get_path(par[v])); }   void merge(int v, int u) {     if ((v = get_path(v)) == (u = get_path(u))) return;     if (par[v] < par[u]) swap(v, u);     par[u] += par[v];     par[v] = u;     arr[u] = arr[u] || arr[v];   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       int x;       cin >> x;       arr[x] = 1;     }     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       e[i] = {w, {u, v}};     }     sort(e, e + m);     int ind;     memset(par, -1, sizeof(par));     for (int i = 0; i < m; i++) {       int u = e[i].second.first, v = e[i].second.second;       if ((u = get_path(u)) != (v = get_path(v)) && arr[u] && arr[v]) {         ind = i;       }       merge(u, v);     }     for (int i = 0; i < k; i++) {       cout << e[ind].first <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   int t;   int main() {     cin >> t;     while (t--) {       cin >> a >> b;       cout << a + b <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Yahia74() {}   const int N = 1e5 + 74, M = 1e5 + 74, OO = 0x3f3f3f3f;   int main() {     Yahia74();     int n, cnt[N] = {};     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (i < n / 2) {         if (x - i >= 0) cnt[x - i]++;       } else {         if (x - (n - i - 1) >= 0) cnt[x - (n - i - 1)]++;       }     }     int mx = 0;     for (int i = 1; i < 100001; i++) mx = max(mx, cnt[i]);     cout << n - mx << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename Sep, typename Head, typename... Tail>   void fold_print(Sep sep, Head&& h, Tail&&... args) {     ((std::cerr << h) << ... << (std::cerr << sep, args));   }   std::mt19937_64 myrand(       std::chrono::high_resolution_clock::now().time_since_epoch().count());   using namespace std;   using LL = long long int;   void init();   void process();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T = 1;     init();     for (int t = 1; t <= T; t++) {       process();     }     cout.flush();     return 0;   }   constexpr LL MOD = 998244353;   vector<LL> fac(5000 * 2 + 1), inv(5000 * 2 + 1);   LL fastpw(LL x, LL p) {     if (p == 0) return 1;     LL tmp = fastpw(x * x % MOD, p / 2);     if (p % 2 == 0)       return tmp;     else       return tmp * x % MOD;   }   LL modinv(LL x) { return fastpw(x, MOD - 2); }   void init() {     fac[0] = 1;     for (LL i = 1; i < fac.size(); i++) {       fac[i] = i * fac[i - 1] % MOD;     }     for (size_t i = 0; i < inv.size(); i++) {       inv[i] = modinv(fac[i]);     }   }   LL C(LL n, LL m) { return fac[n] * inv[m] % MOD * inv[n - m] % MOD; }   void process() {     int n, k;     cin >> n >> k;     vector<int> arr(n);     {       for (auto& x : arr) {         char ch;         cin >> ch;         x = ch -  0 ;       }     }     auto permute = [&](LL l, LL r, LL one) {       LL len = r - l + 1;       LL cnt[] = {len - one, one};       if (len == 1 || cnt[0] == len || cnt[1] == len) return 0ll;       cnt[1 - arr[l]] -= 1;       return C(len - 1, cnt[0]);     };     LL ans = 1, r = 0, cnt = arr[0];     for (LL i = 0; i < n; cnt -= arr[i], i += 1) {       while (r + 1 < n && cnt + arr[r + 1] <= k) {         cnt += arr[r + 1], r += 1;       }       if (cnt != k) break;       if (r == n - 1) {         for (int j = i; j < n; cnt -= arr[j], j += 1) {           ans = (ans + permute(j, r, cnt)) % MOD;         }         break;       } else {         ans = (ans + permute(i, r, cnt)) % MOD;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int fact[200005];   long long int n;   struct point {     long long int x, y;   };   bool cmp(struct point i1, struct point i2) {     if (i1.x != i2.x)       return i1.x < i2.x;     else {       return (i1.y < i2.y);     }   }   long long int fact_(long long int n) {     long long int ans = 1;     fact[0] = fact[1] = 1;     for (int i = 2; i <= n; i++) {       ans = (ans * i) % 1000000007;       fact[i] = ans % 1000000007;     }     return ans;   }   long long int mod_inv(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b % 2 == 1) ans = (ans * a) % 1000000007;       a = (a * a) % 1000000007;       b = b >> 1;     }     return ans;   }   long long int ncr(long long int n, long long int r) {     if (n < r) return 0;     if (r == 0) return n;     if (r == 1) return n;     if (n == r) return 1;     return ((((fact[n] % 1000000007) *               mod_inv(fact[r] % 1000000007, 1000000007 - 2)) %              1000000007) *             mod_inv(fact[n - r] % 1000000007, 1000000007 - 2)) %            1000000007;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<struct point> ar1(4), ar2(4);     for (int i = 0; i < 4; i++) {       long long int a, b;       cin >> a >> b;       ar1[i].x = a;       ar1[i].y = b;     }     for (int i = 0; i < 4; i++) {       long long int a, b;       cin >> a >> b;       ar2[i].x = a;       ar2[i].y = b;     }     sort(ar1.begin(), ar1.end(), cmp);     sort(ar2.begin(), ar2.end(), cmp);     bool f = 0;     for (int i = 0; i < 4; i++) {       if (ar2[i].x >= ar1[0].x && ar2[i].y >= ar1[0].y && ar2[i].x <= ar1[3].x &&           ar2[i].y <= ar1[3].y)         f = 1;     }     for (int i = 0; i < 4; i++) {       if ((ar1[i].x + ar1[i].y) >= (ar2[1].x + ar2[1].y) &&           (ar1[i].y - ar1[i].x) >= (ar2[1].y - ar2[1].x) &&           (ar1[i].x + ar1[i].y) <= (ar2[2].x + ar2[2].y) &&           (ar1[i].y - ar1[i].x) <= (ar2[2].y - ar2[2].x))         f = 1;     }     point c1, c2;     c1.x = (ar1[0].x + ar1[1].x) / 2;     c1.y = (ar1[0].y + ar1[3].y) / 2;     c2.x = (ar2[0].x + ar2[1].x) / 2;     c2.y = (ar2[0].y + ar2[3].y) / 2;     if (c2.x >= ar1[0].x && c2.y >= ar1[0].y && c2.x <= ar1[3].x &&         c2.y <= ar1[3].y)       f = 1;     if ((c1.x + c1.y) >= (ar2[1].x + ar2[1].y) &&         (c1.y - c1.x) >= (ar2[1].y - ar2[1].x) &&         (c1.x + c1.y) <= (ar2[2].x + ar2[2].y) &&         (c1.y - c1.x) <= (ar2[2].y - ar2[2].x))       f = 1;     if (!f)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int N, M;     cin >> N >> M;     using Interval = pair<int, int>;     vector<Interval> intervals(N);     for (int i = 0; i < N; i++) {       cin >> intervals[i].first >> intervals[i].second;     }     int i = 0;     int current_time = 1;     for (int m = 0; m < M; m++) {       int moment;       cin >> moment;       while (i < N && moment > current_time +                                    intervals[i].first * intervals[i].second - 1) {         current_time += intervals[i].first * intervals[i].second;         i++;       }       assert(i < N);       cout << i + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long p;     int d;   } store[200005];   bool cmp(node& a, node& b) { return a.d < b.d; }   bool check(int e, int full, int n) {     if (store[0].d > full) return 1;     for (int i = 0; i < (n - 1); ++i)       if (store[i + 1].d - store[i].d > full) return 1;     if (e - store[n - 1].d > full) return 1;     return 0;   }   int main(void) {     int e, full, n;     scanf( %d %d %d , &e, &full, &n);     for (int i = 0; i < (n); ++i) scanf( %d %lld , &store[i].d, &store[i].p);     sort(store, store + n, cmp);     if (check(e, full, n)) {       puts( -1 );       return 0;     }     long long ret = 0;     int cur = full - store[0].d;     for (int i = 0; i < (n); ++i) {       int d = store[i + 1].d - store[i].d;       int s = i + 1, minn = 1e7, indexx;       bool flag = 0;       while (d <= full && s < n) {         if (store[s].p <= store[i].p) {           if (d <= cur) {             cur -= d;           } else {             ret += (d - cur) * store[i].p;             cur = 0;           }           i = s - 1;           flag = 1;           break;         }         if (store[s].p <= minn) {           minn = store[i].p;           indexx = s;         }         s++;         d = store[s].d - store[i].d;       }       if (!flag) {         if (store[i].d + full >= e) {           ret += store[i].p * max(0, e - store[i].d - cur);           break;         }         ret += (full - cur) * store[i].p;         cur = full - (store[indexx].d - store[i].d);         i = indexx - 1;       }     }     printf( %lld , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int getint() {     static char c;     while ((c = getchar()) <  0  || c >  9 )       ;     int res = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ;     return res;   }   const int MaxN = 200000;   int n;   int col[MaxN + 1];   struct state {     int x, l;     state() {}     state(const int &_x, const int &_l) : x(_x), l(_l) {}     friend inline bool operator<(const state &lhs, const state &rhs) {       if (lhs.x != rhs.x) return lhs.x < rhs.x;       return lhs.l < rhs.l;     }   };   state lower[MaxN + 1], upper[MaxN + 1];   int used[MaxN + 1];   int main() {     n = getint();     for (int i = 1; i <= n; ++i) col[i] = getint();     if (col[1] > 1) {       printf( -1 n );       return 0;     }     lower[1] = state(1, 1);     upper[1] = state(1, 1);     for (int i = 2; i <= n; ++i) {       lower[i] = lower[i - 1];       if (++lower[i].l > 5) ++lower[i].x, lower[i].l = 1;       upper[i] = upper[i - 1];       if (++upper[i].l > 2) ++upper[i].x, upper[i].l = 1;       if (col[i] > 0) {         state l(col[i], 1);         state r(col[i], 5);         lower[i] = max(lower[i], l);         upper[i] = min(upper[i], r);         if (lower[i].x > col[i] || upper[i].x < col[i]) {           printf( -1 n );           return 0;         }       }     }     state res = upper[n];     if (res.l == 1) res.l = 5, --res.x;     if (res < lower[n]) {       printf( -1 n );       return 0;     }     used[col[n] = res.x] = 1;     for (int i = n - 1; i >= 1; --i) {       col[i] = min(col[i + 1], upper[i].x);       col[i] -= used[col[i]] == 5;       ++used[col[i]];     }     printf( %d n , res.x);     for (int i = 1; i <= n; ++i) printf( %d  , col[i]);     return 0;   }


#include <bits/stdc++.h>   #define N 410   #define ll long long   #define ull unsigned long long   //#define mo (ll)((ll)1e9+7)   #define squ(x) ((x)*(x))   #define db double   #define all(x) x.begin(),x.end()   #define cmax(a,b) a=max(a,b)   #define cmin(a,b) a=min(a,b)   #define rep(i,l,r) for(register int i=l;i<=r;++i)   #define drep(i,r,l)for(register int i=r;i>=l;--i)   #define pb push_back   #define inline inline __attribute__((always_inline))   using namespace std;      inline ll read() {    ll x = 0, f = 1; char ch = getchar();    while (ch <  0  || ch >  9 ) {if (ch ==  - )f = -1; ch = getchar();}    while (ch >=  0  && ch <=  9 ) {x = x * 10 + ch -  0 ; ch = getchar();}    return x * f;   }   ll mo;   ll dp[N][N];      int fac[N], inv[N], bit[N];   ll Pow(ll a, ll b) {    ll res = 1;    a %= mo;    for (; b; b >>= 1, a = a * a % mo)     if (b & 1) res = res * a % mo;    return res;   }   void init_inv(int n) {    fac[0] = 1;    rep(i, 1, n)fac[i] = (ll)fac[i - 1] * i % mo;    inv[n] = Pow(fac[n], mo - 2);    drep(i, n, 1) inv[i - 1] = (ll)inv[i] * i % mo;   }   ll C(int n, int m) {    if (n < m)return 0;    return 1ll * fac[n] * inv[m] % mo * inv[n - m] % mo;   }   int main() {    int n = read(); mo = read();    init_inv(n);    bit[0] = 1; rep(i, 1, 400)bit[i] = bit[i - 1] * 1ll * 2 % mo;    dp[0][0] = 1;    rep(i, 0, n)rep(j, 0, i)if (dp[i][j] > 0) {     rep(k, 1, n - i)(dp[i + k + 1][j + k] += dp[i][j] * 1ll * C(j + k, k) % mo                      * bit[k - 1] % mo) %= mo;    }    ll ans = 0;    rep(i, 1, n)(ans += dp[n + 1][i]) %= mo;    printf( %lld n , ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[20];   int main() {     int n, b[20];     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     int kol = 1;     for (int i = 0; i < n; i++) kol *= 2;     for (int i = 0; i < kol; i++) {       int sum = 0;       a[n - 1]++;       for (int j = n - 1; j > 0; j--) {         a[j - 1] = a[j] / 2 + a[j - 1];         a[j] %= 2;       }       for (int j = 0; j < n; j++) {         if (a[j] == 1)           sum += b[j];         else           sum -= b[j];       }       sum = abs(sum);       sum %= 360;       if (sum == 0) {         cout <<  yes ;         return 0;       }     }     cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)500;   const int linf = (int)1e9 + 7;   const int mod = (int)1e9 + 7;   const int sN = (int)27000;   inline void ioi2020() {}   using ll = long long;   using ld = long double;   using ull = unsigned long long;   ll n, m, k;   ll a[N];   ll dp[(1 << 20)][20];   map<ll, ll> mp[N];   int main() {     ioi2020();     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 1; i <= k; i++) {       int a, b, c;       cin >> a >> b >> c;       mp[a - 1][b - 1] = c;     }     for (int mask = 0; mask < (1 << n); mask++) {       for (int bit = 0; bit < n; bit++) {         if ((mask >> bit) & 1) {           for (int sbit = 0; sbit < n; sbit++) {             if ((mask >> sbit) & 1) dp[mask][bit] += a[sbit];           }         }       }     }     for (int mask = 0; mask < (1 << n); mask++) {       for (int bit = 0; bit < n; bit++) {         if (!((mask >> bit) & 1)) {           for (int sbit = 0; sbit < n; sbit++) {             if ((mask >> sbit) & 1)               dp[(mask ^ (1 << bit))][bit] =                   max(dp[(mask ^ (1 << bit))][bit],                       dp[mask][sbit] + mp[sbit][bit] + a[bit]);           }         }       }     }     ll res = 0;     for (int mask = 0; mask < (1 << n); mask++) {       if (__builtin_popcount(mask) == m) {         for (int bit = 0; bit < n; bit++) {           res = max(res, dp[mask][bit]);         }       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXP = 1e5;   long long int n, s, p, q, x, sell[MAXP + 5] = {0}, buy[MAXP + 5] = {0};   char d;   vector<pair<long long int, long long int> > ansell;   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> d >> p >> q;       if (d ==  S )         sell[p] += q;       else         buy[p] += q;     }     x = 0;     for (int i = 0; i <= MAXP; i++) {       if (x == s) break;       if (sell[i]) {         ansell.push_back(make_pair(i, sell[i]));         x++;       }     }     for (int i = ((int(ansell.size()))) - 1; i >= 0; i--)       cout <<  S   << ansell[i].first <<     << ansell[i].second << endl;     x = 0;     for (int i = MAXP; i >= 0; i--) {       if (x == s) break;       if (buy[i]) {         cout <<  B   << i <<     << buy[i] << endl;         x++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tm[100005];   int gcd(int a, int b) {     int r;     while (b > 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   int main() {     int n, i, j, tt, m;     scanf( %d , &n);     scanf( %d , &tm[1]);     for (i = 2; i <= n; i++) {       scanf( %d , &tm[i]);     }     int flag = 0;     while (tm[1] % 2 == 0) tm[1] /= 2;     while (tm[1] % 3 == 0) tm[1] /= 3;     int gd = tm[1];     for (i = 1; i <= n; i++) {       while (tm[i] % 2 == 0) tm[i] /= 2;       while (tm[i] % 3 == 0) tm[i] /= 3;       if (tm[i] == tm[1])         continue;       else {         flag = 1;         break;       }     }     if (flag)       printf( NO n );     else       printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string ans =  no ;     cin >> n;     vector<int> lineas(n);     for (int i = 0; i < n; i++) {       int a;       cin >> a;       lineas[i] = a;     }     int minimo;     int maximo;     for (int i = 0; i < n - 1; i++) {       minimo = min(lineas[i], lineas[i + 1]);       maximo = max(lineas[i], lineas[i + 1]);       for (int j = 0; j < n - 1; j++) {         if (j != i) {           int anterior = min(lineas[j], lineas[j + 1]);           int siguiente = max(lineas[j], lineas[j + 1]);           if (siguiente < maximo and minimo < siguiente and anterior < minimo) {             ans =  yes ;           }           if (minimo < anterior and maximo < siguiente and anterior < maximo) {             ans =  yes ;           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Pos[1 << (24)], dp[1 << (24)];   int a, b;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> Pos[1 << i];     }     int m;     cin >> m;     if (m) cin >> a, m--;     if (m) cin >> b, m--;     int upper = 1 << n;     dp[0] = 1;     for (int i = 1; i < upper; ++i) {       int GetLow = ((i) & (-(i))), tmp = i;       Pos[i] = Pos[GetLow] + Pos[GetLow ^ i];       if (Pos[i] == a || Pos[i] == b) continue;       while (tmp) {         int s = dp[i] + dp[GetLow ^ i];         dp[i] = s > (1000000007) ? s - (1000000007) : s;         tmp ^= ((tmp) & (-(tmp)));         GetLow = ((tmp) & (-(tmp)));       }     }     cout << dp[(1 << n) - 1] << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int ppr = 257;   const long long INF = 2e18;   const int inf = 2e9;   const int mod = 1e9 + 7;   const int N = 1e6 + 123;   const long double pi = 3.141592653589793238462643;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   int n, dp[55][55][55][55], a[55][55], p[55][55];   bool u[55][55][55][55];   inline int get(int x1, int aza_ibagaliev, int x2, int y2) {     return p[x2][y2] - p[x2][aza_ibagaliev - 1] - p[x1 - 1][y2] +            p[x1 - 1][aza_ibagaliev - 1];   }   int calc(int x1, int aza_ibagaliev, int x2, int y2) {     if (u[x1][aza_ibagaliev][x2][y2]) return dp[x1][aza_ibagaliev][x2][y2];     u[x1][aza_ibagaliev][x2][y2] = 1;     dp[x1][aza_ibagaliev][x2][y2] = max((x2 - x1 + 1), (y2 - aza_ibagaliev + 1)) *                                     (get(x1, aza_ibagaliev, x2, y2) > 0);     for (int i = x1; i < x2; i++) {       dp[x1][aza_ibagaliev][x2][y2] = min(           dp[x1][aza_ibagaliev][x2][y2],           calc(x1, aza_ibagaliev, i, y2) + calc(i + 1, aza_ibagaliev, x2, y2));     }     for (int i = aza_ibagaliev; i < y2; i++) {       dp[x1][aza_ibagaliev][x2][y2] =           min(dp[x1][aza_ibagaliev][x2][y2],               calc(x1, aza_ibagaliev, x2, i) + calc(x1, i + 1, x2, y2));     }     return dp[x1][aza_ibagaliev][x2][y2];   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         char c;         cin >> c;         a[i][j] = (c ==  # );         p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + a[i][j];       }     cout << calc(1, 1, n, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n;   int main() {     cin >> n;     long long int summ = n + (n - 1);     long long int wei = 0;     while (summ != 0) {       summ /= 10;       wei++;     }     long long int stdl = 9;     for (int i = 1; i < wei; i++) {       stdl = stdl * 10 + 9;     }     summ = n + (n - 1);     if (summ < stdl) wei--, stdl /= 10;     long long int ans, p = stdl / 2;     ans = min(p, n - p);     long long int qian = 1;     for (int i = 1; i <= wei; i++) qian *= 10;     while (stdl + qian <= summ) {       stdl += qian;       p = stdl / 2;       ans += min(p, n - p);     }     if (n < 5) {       if (n == 2) ans = 1;       if (n == 3) ans = 3;       if (n == 4) ans = 6;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const N = 100 * 1000 + 16;   int const M = 1000 * 1000 * 1000 + 7;   int n, k;   int a[N];   int c[N];   ll e, v[N];   vector<int> idx[N];   struct wavelet {     int L, R;     vector<int> b;     wavelet* l = 0;     wavelet* r = 0;     wavelet(int* pl, int* pr, int L, int R) {       this->L = L;       this->R = R;       if (L == R || pl >= pr) return;       int M = L + R >> 1;       auto f = [M](int x) { return x <= M; };       b.reserve(pr - pl + 1);       b.emplace_back(0);       for (auto p = pl; p != pr; ++p) b.emplace_back(b.back() + f(*p));       auto pm = stable_partition(pl, pr, f);       l = new wavelet(pl, pm, L, M);       r = new wavelet(pm, pr, M + 1, R);     }     ~wavelet() {       delete l;       delete r;     }     int query(int l, int r, int k) {       if (k < L || l >= r) return 0;       if (R <= k) return r - l;       int lf = b.size() > l ? b[l] : 0;       int rg = b.size() > r ? b[r] : 0;       return (this->l ? this->l->query(lf, rg, k) : 0) +              (this->r ? this->r->query(l - lf, r - rg, k) : 0);     }   };   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cin >> n >> k;     fill_n(a + 1, n, n + 1);     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       idx[x].emplace_back(i);       if (++c[x] > k) a[idx[x][c[x] - k - 1]] = i;     }     wavelet t(a + 1, a + 1 + n, 1, 1000 * 1000 * 1000);     int q;     cin >> q;     int last = 0;     while (q--) {       int xi, yi;       cin >> xi >> yi;       int l = (xi + last) % n + 1;       int r = (yi + last) % n + 1;       if (l > r) swap(l, r);       int z = t.query(l - 1, r, r);       last = r - l + 1 - z;       cout << last <<   n ;     }     cout << flush;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const double eps = 1e-8;   bool order(double a, double b, double c) { return a < b && b < c; }   int main() {     double h, m, s, t1, t2;     cin >> h >> m >> s >> t1 >> t2;     s /= 60;     m = m / 60 + s / 60;     h = h / 12 + m / 12;     if (m >= 1 - eps) m -= 1;     if (h >= 1 - eps) h -= 1;     t1 /= 12;     t2 /= 12;     if (t1 >= 1 - eps) t1 -= 1;     if (t2 >= 1 - eps) t2 -= 1;     if (t1 > t2) swap(t1, t2);     bool should = order(t1, h, t2);     if (should == order(t1, m, t2) && should == order(t1, s, t2))       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 7;   const int MOD = 1e9 + 7;   vector<int> Gimp[MAXN];   vector<int> Gcrew[MAXN];   vector<int> G[MAXN];   int comp[MAXN];   int compSize[MAXN];   bool vis[MAXN];   bool col[MAXN];   bool ans;   int res;   int allSize;   void DFScomp(int v, int nr) {     comp[v] = nr;     ++compSize[nr];     for (auto u : Gcrew[v]) {       if (comp[u] > 0) continue;       DFScomp(u, nr);     }   }   void DFScolor(int v, bool c) {     vis[v] = true;     col[v] = c;     if (c) res += compSize[v];     allSize += compSize[v];     for (auto u : G[v]) {       if (vis[u]) {         if (col[u] == c) ans = false;         continue;       }       DFScolor(u, !c);     }   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v;       string c;       cin >> u >> v >> c;       if (c ==  imposter ) {         Gimp[v].push_back(u);         Gimp[u].push_back(v);       } else {         Gcrew[v].push_back(u);         Gcrew[u].push_back(v);       }     }     int c = 1;     for (int i = 1; i <= n; ++i) {       if (comp[i] == 0) {         DFScomp(i, c);         ++c;       }     }     for (int v = 1; v <= n; ++v) {       for (auto u : Gimp[v]) {         G[comp[u]].push_back(comp[v]);         G[comp[v]].push_back(comp[u]);       }     }     int best = 0;     ans = true;     for (int i = 1; i < c; ++i) {       if (!vis[i]) {         res = 0;         allSize = 0;         DFScolor(i, 0);         best += max(res, allSize - res);       }     }     if (!ans) best = -1;     cout << best <<   n ;     for (int i = 1; i <= n; ++i) {       Gimp[i].clear();       Gcrew[i].clear();       G[i].clear();       col[i] = 0;       comp[i] = 0;       compSize[i] = 0;       vis[i] = false;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int T;     cin >> T;     while (T--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n, r;     cin >> n >> r;     double R = -r / (sin(acos(-1) / n) - 1);     double ans = R - r;     cout << fixed << setprecision(10) << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;   char ch;   string ss =   , str =   ;   map<pair<long long, long long>, long long> mp;   set<long long> st;   long long a[300003], b[300003];   vector<pair<long long, long long>> v;   bool ask(long long k) {     long long i;     for (i = 0; i < v.size(); i++)       if (v[i].first != k && v[i].second != k) break;     if (i == v.size()) return 1;     long long x = v[i].first;     long long g = k;     if (x > k) swap(x, k);     if (a[x] + a[k] - mp[{x, k}] == m) return 1;     x = v[i].second;     if (x > g) swap(x, g);     if (a[x] + a[g] - mp[{x, g}] == m) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> x >> y, a[x]++, a[y]++;       v.push_back({x, y});       if (x > y) swap(x, y);       mp[{x, y}]++;     }     x = v[0].first;     y = v[0].second;     bool ya = ask(x);     if (ya) {       cout <<  YES ;       return 0;     }     ya = ask(y);     if (ya) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string sub, inp =   ;     while (cin >> sub) {       inp += sub;     }     string s =   ;     for (int i = 0; i < (int)inp.size(); ++i) {       if (inp[i] ==  a ) {         inp[i - 2] ==  /  ? s +=  A  : s +=  a ;       } else if (inp[i] ==  r ) {         inp[i - 2] ==  /  ? s +=  R  : s +=  r ;       } else if (inp[i] ==  d ) {         inp[i - 2] ==  /  ? s +=  D  : s +=  d ;       }     }     vector<int> st, ans;     for (int i = 0; i < static_cast<int>((s).size()); ++i) {       if (s[i] ==  a ) {         st.push_back(0);       } else if (s[i] ==  A ) {         ans.push_back(st.back());         st.pop_back();       } else if (s[i] ==  d ) {         st[static_cast<int>((st).size()) - 1]++;       }     }     sort(ans.begin(), ans.end());     for (auto x : ans) cout << x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5, Mod = 1e9 + 7;   struct Edge {     int nxt, to;   } e[maxn << 1];   int hd[maxn], e_cnt = 1;   void add(int u, int v) {     e[++e_cnt] = (Edge){hd[u], v};     hd[u] = e_cnt;   }   int n, pre[maxn << 2], nxt[maxn << 2], p[maxn], dep[maxn], fac[maxn];   bool vis[maxn << 2];   void dfs(int u) {     for (int i = hd[u]; i; i = e[i].nxt)       if (i != p[u]) p[e[i].to] = i ^ 1, dep[e[i].to] = dep[u] + 1, dfs(e[i].to);   }   vector<int> getRoute(int u, int v) {     vector<int> v1, v2;     while (dep[u] != dep[v]) {       if (dep[u] > dep[v])         v1.push_back(p[u]), u = e[p[u]].to;       else         v2.push_back(p[v]), v = e[p[v]].to;     }     while (u != v)       v1.push_back(p[u]), v2.push_back(p[v]), u = e[p[u]].to, v = e[p[v]].to;     int siz = v2.size();     for (int i = siz - 1; i >= 0; i--) v1.push_back(v2[i] ^ 1);     return v1;   }   void link(int a, int b) {     if (nxt[a] || pre[b]) {       cout << 0;       exit(0);     }     nxt[a] = b;     pre[b] = a;   }   void cover(int u) {     vis[u] = true;     if (nxt[u]) cover(nxt[u]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fac[0] = 1;     for (int i = 1; i <= 5e5; i++) fac[i] = (long long)fac[i - 1] * i % Mod;     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int a, b;       cin >> a >> b;       add(a, b);       add(b, a);     }     dfs(1);     int sum = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (!a) continue;       if (i == a) {         cout << 0;         return 0;       }       vector<int> vec = getRoute(a, i);       int siz = vec.size();       sum += siz;       if (sum > n * 2 - 2) {         cout << 0;         return 0;       }       link(a, vec[0] + n * 2);       link((vec[siz - 1] ^ 1) + n * 2, i + n);       for (int j = 0; j + 1 < siz; j++)         link((vec[j] ^ 1) + n * 2, vec[j + 1] + n * 2);     }     int ans = 1;     for (int i = 1; i <= n; i++) {       cover(i);       if (vis[i + n]) {         for (int j = hd[i]; j; j = e[j].nxt)           if (!vis[j + n * 2]) {             cout << 0;             return 0;           }       } else {         int cnt = 0;         for (int j = hd[i]; j; j = e[j].nxt)           if (!pre[j + n * 2]) cover(j + n * 2), cnt++;         for (int j = hd[i]; j; j = e[j].nxt)           if (!vis[j + n * 2]) {             cout << 0;             return 0;           }         if (vis[i + n]) cnt--;         ans = (long long)ans * fac[cnt] % Mod;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     x = ch -  0 ;     while (1) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       x = x * 10 + ch -  0 ;     }     return x * f;   }   const int maxn = 510;   const int inf = 0x7fffffff;   int n, a[maxn], dp[maxn][maxn];   int main() {     n = read();     for (int i = 0; i < n; i++) a[i] = read();     for (int i = 1; i <= n; i++) {       for (int j = 0, k = i - 1; k < n; j++, k++) {         if (i == 1) {           dp[j][k] = 1;           continue;         }         dp[j][k] = dp[j + 1][k] + 1;         for (int p = j + 2; p <= k; p++)           if (a[p] == a[j])             dp[j][k] = min(dp[j][k], dp[j + 1][p - 1] + dp[p + 1][k]);         if (a[j] == a[j + 1]) dp[j][k] = min(dp[j][k], dp[j + 2][k] + 1);       }     }     printf( %d n , dp[0][n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   using namespace std;   long long fun(long long a[], long long b[], long long n) {     long long ans = 0;     long long pa[n];     for (long long i = 0; i < n; ++i) pa[a[i]] = i;     long long push_back[n];     for (long long i = 0; i < n; ++i) push_back[b[i]] = i;     vector<long long> freq(n);     for (long long i = 0; i < n; ++i) {       if (pa[i] < push_back[i]) {         long long k = n - 1 - push_back[i] + pa[i] + 1;         freq[k]++;       } else {         long long k = pa[i] - push_back[i];         freq[k]++;       }     }     return *max_element((freq).begin(), (freq).end());   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T = 1;     for (long long tp = 1; tp <= T; ++tp) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; ++i) {         cin >> a[i];         a[i]--;       }       long long b[n];       for (long long i = 0; i < n; ++i) {         cin >> b[i];         b[i]--;       }       cout << (fun(a, b, n));       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long i, j, k, l, n, m, a, b, u;     cin >> n;     vector<pair<string, pair<long long, long long>>> v(n);     for (i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second.first >> v[i].second.second;     }     long long ans = 0;     for (i = 1; i <= 366; i++) {       long long m = 0, f = 0;       for (j = 0; j < n; j++) {         if (v[j].second.first <= i && v[j].second.second >= i) {           if (v[j].first ==  M )             m++;           else             f++;         }       }       ans = max(ans, min(m, f));     }     cout << ans * 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     int i = 0;     while (i < n and s[i] ==  a ) i++;     int j = i + 1;     while (j < n and s[j] !=  a ) j++;     if (i == n)       s[n - 1] =  z ;     else       for (int k = i; k < j; k++) s[k] = (s[k] -  a  - 1 + 26) % 26 +  a ;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;     return;   }   void get_output(int arr[], int n) {     int flag = 1;     while (flag) {       flag = 0;       for (int i = 0; i < n - 1; i++) {         if (arr[i] > arr[i + 1]) {           swap(arr[i], arr[i + 1]);           cout << i + 1 <<     << i + 2 << endl;           flag = 1;         }       }     }     return;   }   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     get_output(arr, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = ~(1 << 31);   const int N = 200000;   int n;   char s[N + 1];   char t[N + 1];   int suffix_array[N + 1];   int *eq;   int lcp[N + 1];   vector<pair<int, int> > lcp_;   inline int add(int a, int b, int md) {     a += b;     if (a >= md) a -= md;     return a;   }   inline int sub(int a, int b, int md) {     a -= b;     if (a < 0) a += md;     return a;   }   int cnt[N + 2];   pair<int, int> res[N + 1];   void count_sort(pair<int, int> *a, int n) {     memset(cnt, 0, 4 * n);     for (int i = 0; i < n; ++i) ++cnt[a[i].first + 1];     for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];     for (int i = 0; i < n; ++i) {       res[cnt[a[i].first]] = a[i];       ++cnt[a[i].first];     }     for (int i = 0; i < n; ++i) a[i] = res[i];   }   pair<int, int> substr[N + 1];   int eq_c1[N + 1], eq_c2[N + 1];   int *suffix_array_build(char *s, int n, int *suffix_array) {     for (int i = 0; i < n; ++i) substr[i] = make_pair((int)s[i], i);     sort(substr, substr + n);     int *eq = eq_c1;     int *eqnw = eq_c2;     eq[substr[0].second] = 0;     for (int i = 1; i < n; ++i)       eq[substr[i].second] =           eq[substr[i - 1].second] + (substr[i].first != substr[i - 1].first);     for (int i = 1; i < n; i <<= 1) {       for (int j = 0; j < n; ++j)         substr[j] = make_pair(eq[sub(substr[j].second, i, n)],                               sub(substr[j].second, i, n));       count_sort(substr, n);       eqnw[substr[0].second] = 0;       for (int j = 1; j < n; ++j)         eqnw[substr[j].second] = eqnw[substr[j - 1].second] +                                  (substr[j].first != substr[j - 1].first ||                                   eq[add(substr[j].second, i, n)] !=                                       eq[add(substr[j - 1].second, i, n)]);       swap(eq, eqnw);     }     for (int i = 0; i < n; ++i) suffix_array[i] = substr[i].second;     return eq;   }   void lcp_build(char *s, int n, int *suffix_array, int *eq, int *lcp) {     for (int i = 0; i < n - 1; ++i) {       while (s[i + lcp[eq[i]]] == s[suffix_array[eq[i] - 1] + lcp[eq[i]]])         ++lcp[eq[i]];       lcp[eq[i + 1]] = max(lcp[eq[i]] - 1, 0);     }   }   void erase_forb() {     int mn = INF;     for (int i = 0; i < n; ++i) {       mn = min(mn, lcp[i]);       if (t[suffix_array[i]] ==  0 ) {         lcp_.push_back(make_pair(suffix_array[i], mn));         mn = INF;       }     }   }   long long calc() {     vector<pair<int, int> > st;     st.push_back(make_pair(0, 0));     long long ans = 0;     for (int i = 0; i < lcp_.size(); ++i) {       ans = max(ans, (long long)n - lcp_[i].first - 1);       while (!st.empty() && lcp_[i].second <= st.back().second) st.pop_back();       ans = max(ans, (long long)(lcp_[i].second * (i - st.back().first + 1)));       st.push_back(make_pair(i, lcp_[i].second));     }     for (int i = 0; i < st.size() - 1; ++i)       ans = max(ans, (long long)(lcp_.size() - st[i].first) * (st[i + 1].second));     return ans;   }   int main() {     scanf( %d%s%s , &n, s, t);     reverse(s, s + n);     reverse(t, t + n);     ++n;     eq = suffix_array_build(s, n, suffix_array);     lcp_build(s, n, suffix_array, eq, lcp);     erase_forb();     printf( %lld n , calc());     return 0;   }


#include <bits/stdc++.h>   const int N_MAX = 600007;   std::map<std::pair<int, int>, int> ext;   long long ans[N_MAX], now;   int fa[N_MAX], siz[N_MAX][2], top;   std::pair<int, int> stk[N_MAX];   int find(int x) {     while (fa[x] != x) x = fa[x];     return x;   }   void merge(std::pair<int, int> v) {     int x = find(v.first), y = find(v.second);     if (x != y) {       if (siz[x][0] + siz[x][1] < siz[y][0] + siz[y][1]) std::swap(x, y);       now -= 1ll * siz[x][0] * siz[x][1] + 1ll * siz[y][0] * siz[y][1];       siz[x][0] += siz[y][0], siz[x][1] += siz[y][1];       now += 1ll * siz[x][0] * siz[x][1];       fa[y] = x, stk[++top] = std::make_pair(x, y);     }   }   void undoMerge() {     int x = stk[top].first, y = stk[top].second;     now -= 1ll * siz[x][0] * siz[x][1];     siz[x][0] -= siz[y][0], siz[x][1] -= siz[y][1];     now += 1ll * siz[x][0] * siz[x][1] + 1ll * siz[y][0] * siz[y][1];     fa[y] = y, --top;   }   static const int T_MAX = 1200007;   std::vector<std::pair<int, int> > op[T_MAX];   void modify(int k, int l, int r, int x, int y, std::pair<int, int> v) {     if (x <= l && r <= y) {       op[k].push_back(v);       return;     }     if (x <= ((l + r) >> 1)) modify((k << 1), l, ((l + r) >> 1), x, y, v);     if (((l + r) >> 1) < y) modify((k << 1 | 1), ((l + r) >> 1) + 1, r, x, y, v);   }   void dfs(int k, int l, int r) {     int temp = top;     for (auto v : op[k]) merge(v);     if (l == r)       ans[l] = now;     else       dfs((k << 1), l, ((l + r) >> 1)), dfs((k << 1 | 1), ((l + r) >> 1) + 1, r);     while (top > temp) undoMerge();   }   int main() {     const int n = 3e5;     int Q;     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) {       std::pair<int, int> temp;       scanf( %d%d , &temp.first, &temp.second), temp.second += n;       if (ext.find(temp) == ext.end())         ext[temp] = i;       else         modify(1, 1, Q, ext[temp], i - 1, temp), ext.erase(temp);     }     for (auto i : ext) modify(1, 1, Q, i.second, Q, i.first);     for (int i = 1; i <= n; ++i) fa[i] = i, siz[i][0] = 1;     for (int i = n + 1; i <= n + n; ++i) fa[i] = i, siz[i][1] = 1;     dfs(1, 1, Q);     for (int i = 1; i <= Q; ++i) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int prv[100010], nxt[100010];   int main() {     int n, k;     string s;     cin >> n >> k;     cin >> s;     int closest = -1;     for (int i = 0; i < s.length(); ++i) {       if (s[i] ==  0 ) {         closest = i;       }       prv[i] = closest;     }     closest = n;     for (int i = s.length() - 1; i >= 0; --i) {       if (s[i] ==  0 ) {         closest = i;       }       nxt[i] = closest;     }     int p1 = 0, p2 = 0;     int sum = 0;     int ans = n;     for (p1 = 0; p1 < s.length(); ++p1) {       while (sum < k + 1 && p2 < s.length()) {         sum += (s[p2] ==  0  ? 1 : 0);         ++p2;       }       if (sum == k + 1) {         int pos = p1 + (p2 - p1) / 2;         if (nxt[pos] != n) {           ans = min(ans, max(nxt[pos] - p1, p2 - 1 - nxt[pos]));         }         if (prv[pos] != -1) {           ans = min(ans, max(prv[pos] - p1, p2 - 1 - prv[pos]));         }       }       sum -= (s[p1] ==  0  ? 1 : 0);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long arr[N];   int main() {     long long n, k;     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n);     --k;     int x = 0, y = 0;     for (int i = 0; i < n; ++i) {       if (arr[i] < arr[k / n]) x++;       if (arr[i] == arr[k / n]) y++;     }     cout << arr[k / n] <<     << arr[(k - n * x) / y] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     char c, res[2] = { W ,  B };     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  - )           cout << c;         else           cout << res[((i % 2) + (j % 2)) % 2];       }       cout << endl;     }     return 0;   }


#include <iostream>   #include <algorithm>   #include <string>   using namespace std;   int main()   {    int t, n;    string s, b =  trygub ;    cin >> t;    while (t--)    {     int k = 0;     cin >> n >> s;     sort(s.begin(), s.end());     cout << s << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, base = 2333, mod = 20030731;   int n, m, a[N], b[N], pw[N], h1[N], h2[N], ans[N];   void init() {     pw[0] = 1;     for (int i = (1); i <= (n - 1); i++)       pw[i] = (long long)base * pw[i - 1] % mod,       h1[i] = (((long long)h1[i - 1] * base + b[i]) % mod + mod) % mod;     for (int i = n - 1; i; i--)       h2[i] = (((long long)h2[i + 1] * base + b[i]) % mod + mod) % mod;   }   int get1(int x, int y) {     return (h1[y] + mod - (long long)h1[x - 1] * pw[y - x + 1] % mod) % mod;   }   int get2(int x, int y) {     return (h2[x] + mod - (long long)h2[y + 1] * pw[y - x + 1] % mod) % mod;   }   bool chk(int x, int y) { return get1(x, y) == get2(x, y); }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n - 1); i++) b[i] = a[i + 1] - a[i];     init();     for (int i = (1); i <= (n); i++) {       bool flag = 1;       if (i > 1) flag &= chk(1, i - 1);       if (i < n) {         flag &= a[1] + a[i] + m == a[i + 1] + a[n];         if (i < n - 1) flag &= chk(i + 1, n - 1);       }       if (flag) ans[++*ans] = (a[1] + a[i]) % m;     }     sort(ans + 1, ans + 1 + *ans);     printf( %d n , *ans);     for (int i = (1); i <= (*ans); i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   long long max3(long long x, long long y, long long z) {     return max(max(x, y), z);   }   long long min3(long long x, long long y, long long z) {     return min(min(x, y), z);   }   const long long N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7,                   inf = 1e17 + 10;   const long long INF = 1e9 + 7;   void add(long long& a, long long b) {     a += b;     if (a >= mod) {       a -= mod;     }   }   long long X[] = {0, 1, 0, -1};   long long Y[] = {-1, 0, 1, 0};   long long power(long long x, long long n) {     long long result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result * x) % mod;       x = ((x % mod) * (x % mod)) % mod;       n = n / 2;     }     return result;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<string> s(n);       long long f[26] = {0};       for (long long i = 0; i < n; i++) {         cin >> s[i];         for (long long j = 0; j < s[i].size(); j++) {           f[s[i][j] -  a ]++;         }       }       bool flag = true;       for (long long i = 0; i < 26; i++) {         if (f[i] % n != 0) flag = false;       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long front[1000001], back[1000001], vt[1000001];   int main() {     long long k, sz, ko = 0, j = 0, kq = 0;     string s;     cin >> k >> s;     sz = s.size();     s =     + s;     for (long long i = 1; i <= sz + 1; i++) {       front[i] = ko;       if (s[i] ==  0 )         ko++;       else         ko = 0;     }     ko = 0;     for (long long i = sz; i >= 1; i--) {       back[i] = ko;       if (s[i] ==  0 )         ko++;       else         ko = 0;     }     for (long long i = 1; i <= sz; i++)       if (s[i] ==  1 ) j++, vt[j] = i;     if (k == 0) {       vt[j + 1] = sz + 1;       front[sz + 1] = ((s[sz] ==  1 ) ? 0 : front[sz] + 1);       j++;       for (long long i = 1; i <= j; i++)         kq += front[vt[i]] * (front[vt[i]] + 1) / 2;       cout << kq;       return 0;     }     for (long long i = 1; i <= j - k + 1; i++)       kq += (front[vt[i]] + 1) * (back[vt[i + k - 1]] + 1);     cout << kq;   }


#include <bits/stdc++.h>   using namespace std;   vector<double> p;   double g;   int n;   int main() {     cin >> n;     p.resize(n + 1);     for (int i = 0; i <= n; i++) cin >> p[i];     g = p[n / 2];     for (int i = 0; i <= (n - 1) / 2; i++)       for (int j = n - (n - 1) / 2; j <= n; j++)         g = max(g, (p[i] * (2 * j - n) + p[j] * (n - 2 * i)) / (j - i) / 2);     cout << g;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   const long long MAX = 1e6 + 2047;   const long long mod = 1e9 + 7;   const long long MAX_2 = 1009;   void sout() { cout <<   n ; }   template <typename T, typename... Types>   void sout(T var1, Types... var2) {     cout << var1 <<    ;     sout(var2...);   }   template <typename T>   void sout(vector<T> arr) {     for (auto it : arr) {       cout << it <<    ;     }     sout();   }   template <typename T>   void sout(set<T> st) {     for (auto it : st) {       cout << it <<    ;     }     sout();   }   void test_case() {     long long n;     cin >> n;     queue<long long> q;     q.push(4);     q.push(7);     set<long long> st;     st.insert(4);     st.insert(7);     while (!q.empty()) {       long long curr = q.front();       q.pop();       st.insert(curr);       if (curr > n) {         continue;       }       q.push(curr * 10 + 4);       q.push(curr * 10 + 7);     }     vector<long long> arr(st.begin(), st.end());     long long ans = lower_bound(arr.begin(), arr.end(), n) - arr.begin() + 1;     cout << ans <<   n ;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     long long t = 1;     while (t--) {       test_case();     }   }


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


#include <bits/stdc++.h>   using namespace std;   char s[100100];   char s1[100100];   int res[5];   vector<int> zeros, ones;   int n;   int was[100100];   int model() {     memset(was, 0, sizeof(was));     for (int i = (0); i < (n); ++i)       if (s[i] ==  0 )         zeros.push_back(i);       else         ones.push_back(i);     int p1 = 0;     int p2 = 0;     for (int i = (0); i < (n - 2); ++i) {       if (i & 1)         was[zeros[p2++]] = 1;       else         was[ones[p1++]] = 1;     }     int c = 0, p = 2;     for (int i = (0); i < (n); ++i)       if (was[i] == 0) {         c += (s[i] -  0 ) * p;         p /= 2;       }     return c;   }   int main() {     scanf( %s , &s);     n = strlen(s);     int a = 0, b = 0, c = 0;     for (int i = (0); i < (n); ++i) s1[i] = s[i];     for (int i = (0); i < (n); ++i)       if (s[i] ==  0 )         a++;       else if (s[i] ==  1 )         b++;       else         c++;     if (a + c > b) res[0] = 1;     if (b + c > a + 1) res[3] = 1;     if ((a + c + 1 >= b) && (b + c >= a)) {       int v = n / 2;       if (n & 1) v++;       for (int i = (0); i < (n); ++i)         if (s[i] ==  1 ) v--;       int cnt = 0;       for (int i = (0); i < (n); ++i)         if (s[i] ==  ? ) {           if (cnt < v) {             s[i] =  1 ;             cnt++;           } else             s[i] =  0 ;         }       int q = model();       res[q] = 1;       cnt = 0;       for (int i = (0); i < (n); ++i) s[i] = s1[i];       for (int i = n - 1; i >= 0; --i)         if (s[i] ==  ? ) {           if (cnt < v) {             s[i] =  1 ;             cnt++;           } else             s[i] =  0 ;         }       zeros.clear();       ones.clear();       q = model();       res[q] = 1;     }     for (int i = (0); i < (4); ++i)       if (res[i]) {         int v1 = (i & 1);         int v2 = i / 2;         cout << v2 << v1 << endl;       }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, min = 0, k;     scanf( %d , &n);     for (int i = 1; i < 200; i++) {       k = (pow(2, i) - 1) * pow(2, i - 1);       if (k > n) {         printf( %d , min);         break;       } else if ((n % k) == 0) {         min = k;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int input(long long int n, vector<long long int> &ve);   long long int input(long long int n, vector<long long int> &ve) {     long long int val;     for (long long int i = 0; i < n; i++) {       cin >> val;       ve.push_back(val);     }     return 0;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, a, m, b;     vector<long long int> vis, v;     vector<vector<long long int>> adj;     cin >> n >> m;     vis.resize(n + 2, 0);     adj.resize(n + 2);     for (long long int i = 0; i < m; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (long long int i = 1; i < n + 1; i++) {       if (adj[i].size() != n - 1) {         v.push_back(i);       } else {         vis[i] = 1;       }     }     if (v.size() == 0) {       cout <<  YES  << endl;       for (long long int i = 0; i < n; i++) {         cout <<  b ;       }       cout << endl;     } else {       vis[v[0]] = 2;       for (long long int i = 0; i < adj[v[0]].size(); i++) {         if (vis[adj[v[0]][i]] == 0) {           vis[adj[v[0]][i]] = 2;         }       }       long long int in = -1;       for (long long int i = 0; i < v.size(); i++) {         if (vis[v[i]] == 0) {           vis[v[i]] = 3;           in = i;           break;         }       }       long long int flag = 0;       if (in != -1) {         for (long long int i = 0; i < adj[v[in]].size(); i++) {           if (vis[adj[v[in]][i]] == 0) {             vis[adj[v[in]][i]] = 3;           } else if (vis[adj[v[in]][i]] == 2) {             flag = 1;             break;           }         }       }       if (flag == 1) {         cout <<  NO  << endl;         return 0;       }       for (long long int i = 0; i < v.size(); i++) {         long long int x = vis[v[i]];         if (x == 0) {           flag = 1;           break;         }       }       long long int two = 0, three = 0;       for (long long int i = 1; i < n + 1; i++) {         if (vis[i] == 2) {           two++;         } else if (vis[i] == 3) {           three++;         } else {           two++;           three++;         }       }       for (long long int i = 0; i < v.size(); i++) {         long long int x = vis[v[i]];         if (x != 1) {           if (x == 2) {             if (adj[v[i]].size() != two - 1) {               flag = 1;               break;             }           } else {             if (adj[v[i]].size() != three - 1) {               flag = 1;               break;             }           }           for (long long int j = 0; j < adj[v[i]].size(); j++) {             if (vis[adj[v[i]][j]] != x && vis[adj[v[i]][j]] != 1) {               flag = 1;               break;             }           }         }         if (flag == 1) {           break;         }       }       if (flag == 1) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         for (long long int i = 1; i < n + 1; i++) {           if (vis[i] == 1) {             cout <<  b ;           } else if (vis[i] == 2) {             cout <<  a ;           } else {             cout <<  c ;           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string h, v;     cin >> h >> v;     bool flag = true;     if (h[0] ==  >  && v[0] ==  v ) flag = false;     if (h[0] ==  <  && v[m - 1] ==  v ) flag = false;     if (h[n - 1] ==  >  && v[0] ==  ^ ) flag = false;     if (h[n - 1] ==  <  && v[m - 1] ==  ^ ) flag = false;     if (flag)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:255000000 )   bool firstout = 1;   template <class T>   T &minn(T &a, T b) {     if (b < a) a = b;     return a;   }   template <class T>   T &maxx(T &a, T b) {     if (a < b) a = b;     return a;   }   int &madd(int &a, int b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   int &msub(int &a, int b) {     a -= b;     if (a < 0) a += 1000000007;     return a;   }   int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }   int mdiv(long long a, long long b, long long m) {     a = (a % m + m) % m;     b = (b % m + m) % m;     if (a % b == 0) return a / b;     return (a + m * mdiv(-a, m, b)) / b;   }   int n, m, q;   int t;   int P[1012];   char A[1012][12][12];   pair<int, pair<int, int> > E[1012 * 1012];   vector<pair<int, int> > R[1012];   int B[1012];   int root(int i) {     if (P[i] == i) return i;     return P[i] = root(P[i]);   }   void dfs(int i) {     B[i] = 1;     int j, k;     for (k = (0); k < (R[i].size()); ++k) {       j = R[i][k].first;       if (B[j]) continue;       printf((firstout) ?  %                             d                          :   %                             d ,              (j + 1)),           firstout = 0;       if (R[i][k].second == t)         printf((firstout) ?  %                               d                            :   %                               d ,                (0)),             firstout = 0;       else         printf((firstout) ?  %                               d                            :   %                               d ,                (i + 1)),             firstout = 0;       printf(  n ), firstout = 1;       dfs(j);     }   }   int main() {     int i, j, k;     char c;     int a, d;     int ts;     for (ts = 1; scanf( %                          d ,                        &(n)) > 0;          ++ts) {       int x;       scanf(            %             d ,           &(m));       scanf(            %             d ,           &(q));       scanf(            %             d ,           &(x));       for (k = (0); k < (q); ++k) {         for (i = (0); i < (n); ++i)           scanf(                %                 s ,               &(A[k][i]));       }       int qq = 0;       int kk;       for (k = (0); k < (q); ++k)         for (kk = (k + 1); kk < (q); ++kk) {           int r = 0;           for (i = (0); i < (n); ++i)             for (j = (0); j < (m); ++j) r += A[k][i][j] != A[kk][i][j];           E[qq++] = make_pair(min(r * x, n * m), make_pair(k, kk));         }       t = n * m;       n = q;       m = qq;       for (i = (0); i < (n); ++i) P[i] = i, R[i].clear();       sort(E, E + m);       int res = 0;       for (k = (0); k < (m); ++k) {         i = E[k].second.first;         j = E[k].second.second;         int ii = root(i);         int jj = root(j);         if (ii != jj) {           a = E[k].first;           res += a;           R[i].push_back(make_pair(j, a));           R[j].push_back(make_pair(i, a));           P[ii] = jj;         }       }       res += t;       printf(            %             d ,           (res));       printf(  n ), firstout = 1;       printf((firstout) ?  %                             d                          :   %                             d ,              (1)),           firstout = 0;       printf((firstout) ?  %                             d                          :   %                             d ,              (0)),           firstout = 0;       printf(  n ), firstout = 1;       for (i = (0); i < (n); ++i) B[i] = 0;       dfs(0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, bool> g;   struct node {     int x, y, z, num;   } ans[3000];   int a[60], sum[60], vis[60], flag, n, final, k;   int main() {     int i, t = 0, s, j, num = 0, tt;     flag = 0;     final = 0;     scanf( %d%d , &n, &k);     g.clear();     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     ans[++t].z = 0;     ans[t].x = 0;     ans[t].y = 0;     ans[t].num = 0;     for (i = 1; i <= n; i++) {       tt = t;       for (j = 1; j <= tt; j++) {         if (g[ans[j].z + a[i]] == false) {           g[ans[j].z + a[i]] = true;           ans[++t].z = ans[j].z + a[i];           ans[t].y = a[i];           ans[t].x = j;           ans[t].num = ans[j].num + 1;           num++;           printf( %d , ans[t].num);           s = t;           while (1) {             printf(  %d , ans[s].y);             s = ans[s].x;             if (s == 1) break;           }           printf(  n );           if (num == k) break;         }       }       if (num == k) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   int main() {     int n;     scanf( %d , &n);     while (n--) {       int a, b;       scanf( %d%d , &a, &b);       long long first = (long long)a * b, t = cbrt(first) + 0.5;       puts(t * t * t == first && a % t == 0 && b % t == 0 ?  Yes  :  No );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   class Interval {    public:     int s, e, i;   } interval[MAXN + 5];   bool cmp_input(const Interval &a, const Interval &b) { return a.i < b.i; }   bool cmp_interval(const Interval &a, const Interval &b) {     if (a.s != b.s) return a.s < b.s;     return a.e < b.e;   }   int arr[MAXN + 5];   int final[MAXN + 5];   int ptr[MAXN + 5];   vector<int> indx[MAXN + 5];   int answer[MAXN + 5];   int freq[MAXN + 5];   int tree[MAXN + 5];   int n, m;   void _update(int ind, int val) {     for (int i = ind; i <= n; i += i & -i) tree[i] += val;     return;   }   int _query(int ind) {     int ret = 0;     for (int i = ind; i > 0; i -= i & -i) ret += tree[i];     return ret;   }   void update(int s, int e, int val) {     _update(s + 1, val);     _update(e + 2, -val);     return;   }   int query(int ind) { return _query(ind + 1); }   void preCalculate() {     int c, c2;     for (c = 0; c < n; c++) {       if (c) answer[c] = answer[c - 1];       if (arr[c] > n) continue;       freq[arr[c]]++;       if (freq[arr[c]] == arr[c]) answer[c]++;       if (freq[arr[c]] == arr[c] + 1) answer[c]--;       indx[arr[c]].push_back(c);     }     for (c = 1; c <= n; c++) indx[c].push_back(n);     for (c = 0; c < n; c++) update(c, c, answer[c]);     return;   }   void add(int ind, int from, int val) {     int to = from + 1;     if (to >= indx[ind].size()) return;     update(indx[ind][from], indx[ind][to] - 1, val);     return;   }   void moveOne(int &start) {     if (arr[start] > n) {       start++;       return;     }     add(arr[start], ptr[arr[start]] + arr[start] - 1, -1);     add(arr[start], ptr[arr[start]] + arr[start], 1);     ptr[arr[start]]++;     start++;     return;   }   int main() {     FILE *in = stdin;     int c, c2;     fscanf(in,  %d%d , &n, &m);     for (c = 0; c < n; c++) fscanf(in,  %d , &arr[c]);     for (c = 0; c < m; c++) {       fscanf(in,  %d%d , &interval[c].s, &interval[c].e);       interval[c].s--;       interval[c].e--;       interval[c].i = c;     }     sort(interval, interval + m, cmp_interval);     preCalculate();     int start = 0;     for (c = 0; c < m; c++) {       while (interval[c].s > start) moveOne(start);       final[interval[c].i] = query(interval[c].e);     }     sort(interval, interval + m, cmp_input);     for (c = 0; c < m; c++) printf( %d n , final[c]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string s2;     cin >> s >> s2;     transform(s.begin(), s.end(), s.begin(), ::tolower);     transform(s2.begin(), s2.end(), s2.begin(), ::tolower);     if (s == s2) {       printf( 0 n );     } else if (s < s2) {       printf( -1 n );     } else if (s > s2) {       printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> a;     for (int i = 0; i < m; i++) {       int q, w;       cin >> q >> w;       a.push_back(make_pair(q, w));     }     sort(a.begin(), a.end(), comp);     int i = 0;     int ma = 0;     while (n > 0 && i <= m - 1) {       if (n >= a[i].first) {         n -= a[i].first;         ma += a[i].first * a[i].second;       } else {         ma += n * a[i].second;         n = 0;       }       i++;     }     cout << ma << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int N;     char in[120];     scanf( %d%s , &N, in);     int len = strlen(in);     int flag = 0;     for (int i = 0; i < len; i++) {       for (int d = 1; d < len; d++) {         if (i + 4 * d >= len) break;         if (in[i] ==  *  && in[i + d] ==  *  && in[i + 2 * d] ==  *  &&             in[i + 3 * d] ==  *  && in[i + 4 * d] ==  * )           flag = 1;       }     }     if (flag)       printf( yes n );     else       printf( no n );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     scanf( %d , &n);     if (n == 1) {       printf( 0 n0 n0 n );       return 0;     }     for (int t = 1; t <= n - 1; t++)       if (gcd(t, n) == 1 && gcd(t + 1, n) == 1) {         for (int i = 0; i < n; i++) printf( %d  , i);         printf(  n );         for (int i = 0; i < n; i++) printf( %d  , (int)(1ll * t * i % n));         printf(  n );         for (int i = 0; i < n; i++) printf( %d  , (int)(1ll * (t + 1) * i % n));         printf(  n );         return 0;       }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const double PI = 3.141592653589793;   const double eps = 1e-6;   int n, r, R;   double x;   int main() {     scanf( %d %d %d , &n, &R, &r);     if (n == 1) {       if (r <= R)         printf( YES n );       else         printf( NO n );       return 0;     }     if (r > R / 2) {       printf( NO n );       return 0;     }     x = asin(r * 1.0 / (R - r)) * 180.0 / PI;     if (2 * n * x > 360 + eps)       printf( NO n );     else       printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)5e3 + 10;   const int MOD = (int)1e9 + 7;   long long dp[1111][1111];   int num[1111], k;   int mark[1111];   long long dfs(int pos, int x, int flag) {     if (pos == 0) return mark[x] == k - 1 && (x != 0);     if (dp[pos][x] != -1 && !flag) {       return dp[pos][x];     }     long long ans = 0;     int ed = flag ? num[pos] : 1;     for (int i = 0; i <= ed; i++) {       ans += dfs(pos - 1, x + i, flag && i == ed);       ans %= MOD;     }     if (!flag) dp[pos][x] = ans;     return ans;   }   char str[1111];   long long solve() {     memset(dp, -1, sizeof(dp));     int len = 0, l = strlen(str + 1);     for (int i = l; i >= 1; i--) {       num[++len] = str[i] -  0 ;     }     if (k == 0) return 1;     if (k == 1) return len - 1;     return dfs(len, 0, 1);   }   int work(int x) {     int re = 0;     while (x) {       re++;       x -= x & (-x);     }     return re;   }   void init() {     mark[1] = 0;     for (int i = 2; i <= 1000; i++) mark[i] = mark[work(i)] + 1;   }   int main() {     init();     scanf( %s , str + 1);     scanf( %d , &k);     printf( %lld n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[(1 << 20) + 4], n;   long long store[21][2], INV = 0;   long long query(int l, int r, int no) {     return (A + r + 1 - upper_bound(A + l, A + r + 1, no));   }   void gen(int de, int l, int r) {     if (!de) return;     gen(de - 1, l, (l + r) / 2);     gen(de - 1, (l + r) / 2 + 1, r);     int a = l, b = (l + r) / 2, c = r;     for (int i = a; i <= b; i++) {       long long nos = query(b + 1, c, A[i]);       store[de][1] += nos;     }     for (int i = b + 1; i <= c; i++) {       long long nos = query(a, b, A[i]);       store[de][0] += nos;     }     sort(A + l, A + r + 1);   }   int main() {     cin >> n;     for (int i = 1; i <= (1 << n); i++) cin >> A[i];     gen(n, 1, (1 << n));     for (int de = n; de > 0; de--) INV += store[de][0];     int m;     cin >> m;     while (m--) {       int de;       cin >> de;       while (de != 0) {         INV -= store[de][0];         INV += store[de][1];         swap(store[de][0], store[de][1]);         de--;       }       printf( %lld n , INV);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, k;   int a[N];   int b[N];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n - 1; ++i) {       b[i] = a[i + 1] - a[i] - 1;     }     sort(b, b + n - 1);     int kk = n;     long long ans = n;     for (int i = 0; i < n - 1; ++i) {       if (kk == k) break;       ans += b[i];       kk--;       if (kk == k) break;     }     cout << ans << endl;     return 0;   }