#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MAX = 1e6;   int len1, len2, pre[MAX], suf[MAX];   bool can_skip(int skip) {     for (int i = 1; i + skip - 1 < len1; i++)       if (pre[i - 1] + suf[i + skip] >= len2) return 1;     return 0;   }   int main() {     string x, y, z =  1 ;     cin >> x >> y;     z += x;     x = z;     len1 = x.length();     len2 = y.length();     for (int i = 1, j = 0, it = 0; i < len1; i++) {       if (j < len2 && x[i] == y[j]) it++, j++;       pre[i] = it;     }     for (int i = len1 - 1, j = len2 - 1, it = 0; i >= 1; i--) {       if (j >= 0 && x[i] == y[j]) it++, j--;       suf[i] = it;     }     int l = 0, r = len1, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (can_skip(mid)) {         l = mid + 1, ans = mid;       } else         r = mid - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       string x;       cin >> x;       string a(n,  0 );       string b(n,  0 );       for (int j = 0; j < n; j++) {         if (x[j] ==  0 ) {           a[j] =  0 ;           b[j] =  0 ;         } else if (x[j] ==  2 ) {           a[j] =  1 ;           b[j] =  1 ;         } else {           a[j] =  1 ;           b[j] =  0 ;           for (int k = j + 1; k < n; k++) {             a[k] =  0 ;             b[k] = x[k];           }           break;         }       }       cout << a << endl;       cout << b << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   struct node {     int u, v, w, f, nxt;     node() {}     node(int u, int v, int w, int f, int nxt)         : u(u), v(v), w(w), f(f), nxt(nxt) {}   } e[N << 2];   int h[N], idx = 1;   void link(int x, int y, int w) {     e[++idx] = node(x, y, w, 1, h[x]);     h[x] = idx;     e[++idx] = node(y, x, -w, 0, h[y]);     h[y] = idx;   }   int dis[N], pre[N];   bool vis[N];   int n, m;   int Mincost = 0;   int spfa() {     memset(dis, 0x3f, sizeof dis);     memset(vis, 0, sizeof vis);     memset(pre, 0, sizeof pre);     queue<int> q;     while (q.size()) q.pop();     q.push(1);     dis[1] = 0;     while (q.size()) {       int t = q.front();       q.pop();       vis[t] = 0;       for (int i = h[t]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (e[i].f && dis[v] > dis[t] + w) {           dis[v] = dis[t] + w;           pre[v] = i;           if (vis[v] == 0) {             vis[v] = 1;             q.push(v);           }         }       }     }     if (dis[n] == 0x3f3f3f3f) return 0;     Mincost += dis[n];     for (int i = pre[n]; i; i = pre[e[i].u]) e[i].f--, e[i ^ 1].f++;     return 1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y, z;       cin >> x >> y >> z;       link(x, y, z);     }     vector<int> v;     v.clear();     while (spfa()) {       v.push_back(Mincost);     }     int m;     cin >> m;     while (m--) {       int x;       cin >> x;       double ans = 1e18;       for (int i = 0; i < v.size(); i++)         ans = min(ans, 1.0 * (v[i] + x) / (i + 1));       printf( %.10f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n, i, j, tmp, tmp2;     cin >> n >> tmp;     for (i = 1; i < n; i++) {       cin >> tmp2;       if (tmp == tmp2) {         for (i = i + 1; i < n; i++) {           cin >> tmp2;           if (tmp > tmp2) {             tmp = tmp2;             for (i = i + 1; i < n; i++) {               cin >> tmp2;               if (tmp <= tmp2) {                 cout <<  NO  << endl;                 return 0;               }               tmp = tmp2;             }           } else if (tmp < tmp2) {             cout <<  NO  << endl;             return 0;           }         }       } else if (tmp > tmp2) {         tmp = tmp2;         for (i = i + 1; i < n; i++) {           cin >> tmp2;           if (tmp <= tmp2) {             cout <<  NO  << endl;             return 0;           }           tmp = tmp2;         }       }       tmp = tmp2;     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5;   const int LOG = 16;   struct trie {     int go[N][2], NFI = 1;     trie() { memset(go, -1, sizeof(go)); }     void reset() {       for (int i = 0; i <= NFI; i++) go[i][0] = go[i][1] = -1;       NFI = 1;     }     void add(int x) {       for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {         int t = x >> bit & 1;         if (go[at][t] == -1) go[at][t] = ++NFI;         at = go[at][t];       }     }     int ask(int x) {       int res = 0;       for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {         int t = x >> bit & 1;         if (go[at][!t] != -1) {           res |= (1 << bit);           at = go[at][!t];         } else           at = go[at][t];       }       return res;     }   } t;   int n, q, a[N];   vector<int> nb[N];   int par[N], dep[N], jump_256[N];   void DFS_prep(int v) {     for (int u : nb[v]) {       if (u != par[v]) {         par[u] = v;         dep[u] = dep[v] + 1;         DFS_prep(u);       }     }   }   int res[N][256];   void precalc(int v) {     t.reset();     int temp = v;     for (int i = 0; temp && i <= 255; i++) {       t.add(a[temp] ^ i);       temp = par[temp];     }     jump_256[v] = temp;     for (int i = 0; i < 256; i++) res[v][i] = t.ask(i * 256);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       nb[u].push_back(v);       nb[v].push_back(u);     }     DFS_prep(1);     for (int i = 1; i <= n; i++) precalc(i);     while (q--) {       int u, v;       cin >> u >> v;       int ans = 0;       int jumps = 0;       while (v && dep[jump_256[v]] > dep[u]) {         ans = max(ans, res[v][jumps]);         jumps++;         v = jump_256[v];       }       jumps *= 256;       while (v && dep[v] >= dep[u]) {         ans = max(ans, a[v] ^ jumps);         v = par[v];         jumps++;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 100005;   long long f[N];   long long inverse(long long x) {     if (x >= mod) return inverse(x % mod);     assert(x != 0);     if (x == 1) return 1;     return inverse(mod % x) * (mod - mod / x) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<long long> a(n);     long long sum = 0;     for (auto &x : a) {       cin >> x;       sum += x;     }     f[0] = 0;     f[1] = ((sum - 1) * (sum - 1) % mod) * inverse(sum) % mod;     for (int m = 2; m < N && m < sum; m++) {       f[m] = 2 * f[m - 1] - f[m - 2] - ((sum - 1) * inverse(sum - m + 1) % mod);       f[m] %= mod;       if (f[m] < 0) f[m] += mod;     }     long long ans = 0;     for (auto x : a) {       ans += f[x];     }     ans %= mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }   int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }   const long long int MAXN = 1e6 + 10;   long long int n, ans = 1;   long long int a[MAXN], dp[MAXN];   void solve() {     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> a[i];       dp[a[i]]++;     }     for (int i = (MAXN - 1); i >= (1); --i) {       if (!dp[i]) continue;       for (long long int j = 2 * i; j <= MAXN - 1; j += i) {         dp[i] = max(dp[i], 1 + dp[j]);         ans = max(ans, dp[i]);       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     for (int i = (1); i <= (t); ++i) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int h, w, q;   char buf[505][505];   int ans[1000005];   struct query_ {     int y1, x1, y2, x2;     int id;   };   bitset<505> able[2][505][505];   void rec(int l, int r, vector<query_>& query) {     vector<query_> left, right;     int md = (l + r) >> 1;     for (int i = 0; i < h; ++i)       for (int j = l; j < r; ++j) able[0][i][j].reset(), able[1][i][j].reset();     for (int i = 0; i < h; ++i)       if (buf[i][md] ==  . ) able[0][i][md].set(i), able[1][i][md].set(i);     for (int i = h - 1; i >= 0; --i)       for (int j = md; j >= l; --j)         if (buf[i][j] ==  . ) {           able[0][i][j] |= able[0][i + 1][j];           if (j < md) able[0][i][j] |= able[0][i][j + 1];         }     for (int i = 0; i < h; ++i)       for (int j = md; j < r; ++j)         if (buf[i][j] ==  . ) {           if (buf[i][j + 1] ==  . ) able[1][i][j + 1] |= able[1][i][j];           if (buf[i + 1][j] ==  . ) able[1][i + 1][j] |= able[1][i][j];         }     for (int i = 0; i < query.size(); ++i) {       if (query[i].x1 <= md && md <= query[i].x2) {         if ((able[0][query[i].y1][query[i].x1] &              able[1][query[i].y2][query[i].x2])                 .any()) {           ans[query[i].id] = 1;         }       } else if (query[i].x2 < md)         left.push_back(query[i]);       else         right.push_back(query[i]);     }     if (!left.empty()) rec(l, md, left);     if (!right.empty()) rec(md, r, right);     query.clear();   }   int main() {     for (int i = 0; i < h; ++i)       for (int j = 0; j < w; ++j) buf[i][j] =  # ;     scanf( %d%d , &h, &w);     for (int i = 0; i < h; ++i) scanf( %s , buf[i]);     scanf( %d , &q);     vector<query_> query;     for (int i = 0; i < q; ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       --a;       --b;       --c;       --d;       if (a > c || b > d) continue;       query.push_back((query_){a, b, c, d, i});     }     rec(0, w, query);     for (int i = 0; i < q; ++i) {       if (ans[i])         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       vector<int> ans(n);       for (int i = 0; i < n / 2; i++) {         ans[i] = v[n - 1 - i];         ans[n - 1 - i] = -1 * v[i];       }       for (int ele : ans) cout << ele <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const int Inf = 1000000007;   const long long mod = 1000000007;   const double Pi = acos(-1);   void Fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int n, t, ans = 0;   long long res = 0;   int Co[4], Color[100005], a[100005];   vector<int> Adj[100005];   map<int, long long> C;   int main() {     Fastio();     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int j = 2; j <= n; j++) {       int temp;       cin >> temp;       Adj[temp].emplace_back(j);       Adj[j].emplace_back(temp);     }     queue<int> BFS;     BFS.push(1);     Co[1] = 1;     Color[1] = 1;     while (BFS.empty() == false) {       int node = BFS.front();       for (auto x : Adj[node]) {         if (!Color[x]) {           Color[x] = 3 - Color[node];           Co[Color[x]]++;           BFS.push(x);         }       }       BFS.pop();     }     for (int i = 1; i <= n; i++) {       if (Adj[i].size() == 1 and i != 1) {         t = Color[i];         break;       }     }     t = 3 - t;     for (int i = 1; i <= n; i++) {       if (Color[i] == 3 - t) {         ans ^= a[i];         C[a[i]]++;       }     }     if (ans == 0) {       res += 1ll * Co[3 - t] * (Co[3 - t] - 1) / 2;       res += 1ll * Co[t] * (Co[t] - 1) / 2;     }     for (int i = 1; i <= n; i++) {       if (Color[i] == t) {         res += C[a[i] ^ ans];       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5, inf = 1e9 + 5;   char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;   int ny;   inline char gc() {     return pp1 == pp2 &&                    (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)                ? EOF                : *pp1++;   }   inline int read() {     int x = 0;     for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)       if (nc == 45) ny = -1;     if (nc < 0) return nc;     for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;          x = (x << 3) + (x << 1) + (nc ^ 48))       ;     return x * ny;   }   int n, p[MAXN], tot;   struct Node {     int x, y, c;   } a[MAXN];   vector<int> s[MAXN];   pair<long long, int> Mn[MAXN << 2];   long long t[MAXN << 2];   inline void pushup(int x) { Mn[x] = min(Mn[x << 1], Mn[x << 1 | 1]); }   inline void pushr(int x, long long v) { Mn[x].first += v, t[x] += v; }   inline void pushdown(int x) {     if (t[x]) pushr(x << 1, t[x]), pushr(x << 1 | 1, t[x]), t[x] = 0;   }   inline void insert(int x, int l, int r, int p, long long v) {     if (l == r) {       Mn[x].first += v;       return;     }     int mid = l + r >> 1;     pushdown(x);     (p <= mid ? insert(x << 1, l, mid, p, v)               : insert(x << 1 | 1, mid + 1, r, p, v)),         pushup(x);   }   inline void add(int x, int l, int r, int ql, int qr, int v) {     if (ql > qr) return;     if (ql <= l && r <= qr) return pushr(x, v);     int mid = l + r >> 1;     pushdown(x);     if (ql <= mid) add(x << 1, l, mid, ql, qr, v);     if (qr > mid) add(x << 1 | 1, mid + 1, r, ql, qr, v);     pushup(x);   }   inline pair<long long, int> ask(int x, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return Mn[x];     int mid = l + r >> 1;     pair<long long, int> res = make_pair((long long)1e18, 0);     pushdown(x);     if (ql <= mid) res = min(res, ask(x << 1, l, mid, ql, qr));     if (qr > mid) res = min(res, ask(x << 1 | 1, mid + 1, r, ql, qr));     return res;   }   inline void build(int x, int l, int r) {     if (l == r) {       Mn[x] = make_pair(-p[l], l);       return;     }     int mid = l + r >> 1;     build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r), pushup(x);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       int x = read(), y = read(), w = read();       p[++tot] = x, p[++tot] = y, a[i] = (Node){x, y, w};     }     sort(p + 1, p + tot + 1), tot = unique(p + 1, p + tot + 1) - p - 1,                               build(1, 1, tot);     for (int i = 1; i <= n; i++)       a[i].x = lower_bound(p + 1, p + tot + 1, a[i].x) - p,       a[i].y = lower_bound(p + 1, p + tot + 1, a[i].y) - p;     for (int i = 1; i <= n; i++) s[max(a[i].x, a[i].y)].push_back(i);     long long sum = 0, ans = 0, px, py;     int flg = 0;     for (int i = 1; i <= tot; i++) {       insert(1, 1, tot, i, sum);       for (auto o : s[i])         sum += a[o].c, add(1, 1, tot, min(a[o].x, a[o].y) + 1, i, a[o].c);       pair<long long, int> t = ask(1, 1, tot, 1, i);       if (sum - p[i] - t.first > ans)         ans = sum - p[i] - t.first, px = p[i], py = p[t.second], flg = 1;     }     if (flg)       cout << ans <<   n  << py <<     << py <<     << px <<     << px <<   n ;     else       cout << 0 <<   n  << inf <<     << inf <<     << inf <<     << inf <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void no(int ex = -1) { cout << ex <<   n ; }   void bl(bool win) {     if (win)       cout <<  YES ;     else       cout <<  NO ;     cout <<   n ;   }   const int N = 2 * 10e5;   const int mod = 998244353;   vector<bool> pr;   void prime() {     int EDGE = 1000;     pr = vector<bool>(EDGE);     for (int i = 0; i < EDGE; i++) pr[i] = true;     pr[0] = false;     pr[1] = false;     for (int i = 2; i < EDGE; i++) {       if (pr[i]) {         if (i * i < EDGE) {           for (int j = i * i; j < EDGE; j += i) pr[j] = false;         }       }     }   }   long long nod(long long a1, long long b1) {     if (b1 == 0)       return a1;     else       return nod(b1, a1 % b1);   }   long long T;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     vector<int> mn(n);     for (int i = 0; i < int(n); i++) {       cin >> mn[i];     }     vector<int> res(k);     for (int i = 0; i < int(k); i++) {       cin >> res[i];     }     vector<int> ab = {0, 0, 0, 1};     vector<int>::iterator hig;     hig = lower_bound(ab.begin(), ab.end(), 1);     vector<vector<int>> ans(n, {0});     sort(mn.begin(), mn.end());     vector<int> us(n, 0);     int cnt = 0;     for (int z = n - 1; z >= 0; z--) {       vector<int>::iterator low;       low = lower_bound(us.begin(), us.end(), res[mn[z] - 1]);       int y = low - us.begin();       y = min(n - 1, y);       if (us[y] == res[mn[z] - 1]) y--;       ans[n - y - 1][0]++;       us[y]++;       ans[n - y - 1].push_back(mn[z]);     }     int cur = 0;     while (cur < n && ans[cur][0] != 0) {       cur++;     }     cout << cur <<   n ;     for (int i = 0; i < cur; i++) {       for (int j = 0; j <= ans[i][0]; j++) cout << ans[i][j] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, ans = 1e5, freq[125];   bool exst[125];   string s;   int main() {     scanf( %d , &n);     cin >> s;     for (int i = 0; i < n; i++) {       exst[s[i]] = true;     }     freq[s[0]] = 1;     for (int i = 0, j = 0; j < n;) {       bool valid = 1;       for (int k = 0; k <=  z ; k++) {         if (exst[k] && !freq[k]) {           j++;           freq[s[j]]++;           valid = 0;           break;         }       }       if (valid) {         ans = min(ans, j - i + 1);         freq[s[i]]--;         i++;       }     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, x, y, i, j;     long double sum1 = 0, sum2 = 0, mini, maxi, p, z;     cin >> n >> x >> y;     long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     mini = min(x, y);     maxi = max(x, y);     p = mini;     j = 0;     while (mini--) {       sum1 = sum1 + a[n - 1 - j];       j++;     }     z = maxi;     while (maxi--) {       sum2 = sum2 + a[n - 1 - j];       j++;     }     cout << fixed << setprecision(12) << sum1 / p + sum2 / z;   }


#include <bits/stdc++.h>   long long int oddsum[100020], evensum[100020];   int main() {     memset(oddsum, 0, sizeof(oddsum));     memset(evensum, 0, sizeof(evensum));     int n, i;     long long int x, ans = 0, sum;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       if (i & 1)         oddsum[(i >> 1) + 1] = oddsum[i >> 1] + x;       else         evensum[(i >> 1) + 1] = evensum[i >> 1] + x;     }     for (i = 0; i < n; i++) {       if (i & 1)         sum =             oddsum[(i >> 1) + 1] + evensum[(n >> 1) + 1] - evensum[(i >> 1) + 1];       else         sum = evensum[(i >> 1) + 1] + oddsum[n >> 1] - oddsum[i >> 1];       if (ans < sum) ans = sum;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[222], str;   int res[1000000] = {0};   bool hh(int n, int x) {     for (int i = 0; i < (1 << x); i++) {       str =   ;       for (int k = 0; k < x; k++) (i & (1 << k)) ? str +=  1  : str +=  0 ;       if (s[n].find(str) == -1) return false;     }     return true;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int ii = 0, jj = 10;       while (ii < jj && hh(i, ii + 1)) ii++;       res[i] = ii;     }     int t, m;     cin >> t;     while (t--) {       int i, j, mid, ii, jj;       cin >> i >> j;       ii = i;       jj = j;       n++;       s[n] = s[i] + s[j];       if (s[n].size() > 1000)         s[n] = s[n].substr(0, 500) + s[n].substr(s[n].size() - 500, 500);       i = 0;       j = 10;       while (i < j && hh(n, i + 1)) i++;       res[n] = max(i, max(res[ii], res[jj]));       cout << res[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     static int f[10000];     int n, ok = false;     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) scanf( %d , f + i);     for (int i = 1; i <= n; ++i)       if (f[f[f[i]]] == i) ok = true;     puts(ok ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long mod = 1e9 + 7;   inline long long gcd(long long a, long long b) {     return !b ? a : gcd(b, a % b);   }   inline long long q_pow(long long a, long long x) {     long long ans = 1, tmp = a;     while (x) {       if (x & 1) (ans *= tmp) %= mod;       (tmp *= tmp) %= mod;       x >>= 1;     }     return ans;   }   template <typename T>   inline void re(T &N) {     int f = 1;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f = -1;     N = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) N = N * 10 + c -  0 ;     N *= f;   }   int m, n, t = 1, st, en;   struct Trie {     struct node {       int a[2];       int ans, len;       int ma, mi;       node() {         a[0] = a[1] = 0;         ans = 1e9;         len = 1;         ma = -1e9;         mi = 1e9;       }       node(int x) {         a[0] = a[1] = 0;         ans = 1e9;         len = 1;         ma = mi = 0;       }     } nul;     vector<node> v;     Trie() { v.assign(1, nul); }     inline void push_up(int p) {       v[p].mi = min(v[(v[p].a[0])].mi, v[(v[p].a[1])].mi + v[(v[p].a[0])].len);       v[p].ma = max(v[(v[p].a[0])].ma, v[(v[p].a[1])].ma + v[(v[p].a[0])].len);       v[p].ans =           min({v[(v[p].a[0])].ans, v[(v[p].a[1])].ans,                v[(v[p].a[1])].mi - v[(v[p].a[0])].ma + v[(v[p].a[0])].len});       v[p].len = v[(v[p].a[0])].len + v[(v[p].a[1])].len;     }     int build(int p, int l, int r) {       if (!p) v.push_back(nul), p = (int)v.size() - 1;       if (l == r) return p;       int mid = (l + r) >> 1;       (v[p].a[0]) = build((v[p].a[0]), l, mid);       (v[p].a[1]) = build((v[p].a[1]), mid + 1, r);       push_up(p);       return p;     }     void insert(int p, int dep, int val) {       if (!(~dep)) return v[p] = node(1), void();       insert(v[p].a[val >> dep & 1], dep - 1, val);       push_up(p);     }     void rotate(int p, int dep, int lim) {       if (dep == lim) {         swap((v[p].a[0]), (v[p].a[1]));         push_up(p);         return;       }       rotate((v[p].a[0]), dep - 1, lim);       rotate((v[p].a[1]), dep - 1, lim);       push_up(p);     }   } tr;   int main() {     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     tr.build(0, 0, (1 << k) - 1);     for (int i = 0; i < n; i++) tr.insert(1, k - 1, a[i]);     vector<int> ans(1 << k), gray(1 << k);     for (int i = 0; i < 1 << k; i++) {       gray[i] = (i >> 1) ^ i;       vector<int> tmp;       for (int j = 0; j < k; j++, gray[i] >>= 1) tmp.push_back(gray[i] & 1);       for (int j = 0; j < k; j++) gray[i] = gray[i] << 1 | tmp[j];     }     for (int i = 0; i < 1 << k; i++) {       ans[gray[i]] = tr.v[1].ans;       if ((i + 1) < 1 << k) {         int pos = 31 - __builtin_clz(gray[i] ^ gray[i + 1]);         tr.rotate(1, k - 1, pos);       }     }     for (int i = 0; i < 1 << k; i++) cout << ans[i] <<    n [i + 1 == 1 << k];   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   template <typename T, typename U>   static void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static void amax(T &x, U y) {     if (x < y) x = y;   }   struct MaximumFlow {     static const int InfCapacity = INF;     struct Edge {       int to;       int capacity;       int rev;     };     vector<vector<Edge>> g;     void init(int n) { g.assign(n, vector<Edge>()); }     void add(int i, int j, int capacity) {       Edge e, f;       e.to = j, f.to = i;       e.capacity = capacity, f.capacity = 0;       g[i].push_back(e);       g[j].push_back(f);       g[i].back().rev = (int)g[j].size() - 1;       g[j].back().rev = (int)g[i].size() - 1;     }     void addB(int i, int j, int capacity) {       Edge e, f;       e.to = j, f.to = i;       e.capacity = capacity, f.capacity = capacity;       g[i].push_back(e);       g[j].push_back(f);       g[i].back().rev = (int)g[j].size() - 1;       g[j].back().rev = (int)g[i].size() - 1;     }     int maximumFlow(int s, int t) {       int n = g.size();       vector<int> level(n);       int total = 0;       bool update;       do {         update = false;         fill(level.begin(), level.end(), -1);         level[s] = 0;         queue<int> q;         q.push(s);         for (int d = n; !q.empty() && level[q.front()] < d;) {           int u = q.front();           q.pop();           if (u == t) d = level[u];           for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e)             if (e->capacity > 0 && level[e->to] == -1)               q.push(e->to), level[e->to] = level[u] + 1;         }         vector<int> iter(n);         for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;         while (1) {           int f = augment(level, iter, s, t, InfCapacity);           if (f == 0) break;           total += f;           update = true;         }       } while (update);       return total;     }     int augment(vector<int> &level, vector<int> &iter, int u, int t, int f) {       if (u == t || f == 0) return f;       int lv = level[u];       if (lv == -1) return 0;       level[u] = -1;       for (; iter[u] >= 0; --iter[u]) {         Edge &e = g[u][iter[u]];         if (level[e.to] <= lv) continue;         int l = augment(level, iter, e.to, t, min(f, e.capacity));         if (l == 0) continue;         e.capacity -= l;         g[e.to][e.rev].capacity += l;         level[u] = lv;         return l;       }       return 0;     }   };   int main() {     int n;     int m;     while (~scanf( %d%d , &n, &m)) {       vector<array<int, 2>> edges(m);       for (int(i) = 0; (i) < (int)(m); ++(i)) {         int x;         int y;         scanf( %d%d , &x, &y), --x, --y;         edges[i] = {x, y};       }       vector<pair<int, int>> ans(m);       int lo = 0, up = m + 1;       while (up - lo > 0) {         int mid = (lo + up) / 2;         MaximumFlow mf;         int src = m + n, dst = src + 1;         mf.init(dst + 1);         for (int(i) = 0; (i) < (int)(m); ++(i)) mf.add(src, i, 1);         for (int(i) = 0; (i) < (int)(m); ++(i))           for (int j : edges[i]) mf.add(i, m + j, 1);         for (int(j) = 0; (j) < (int)(n); ++(j)) mf.add(m + j, dst, mid);         int f = mf.maximumFlow(src, dst);         if (f == m) {           up = mid;           for (int(i) = 0; (i) < (int)(m); ++(i)) {             for (auto e : mf.g[i])               if (e.capacity == 0 && m <= e.to && e.to < m + n) {                 int x = e.to - m;                 auto p = make_pair(edges[i][0], edges[i][1]);                 if (p.first != x) swap(p.first, p.second);                 ans[i] = p;               }           }         } else {           lo = mid + 1;         }       }       printf( %d n , up);       for (int i = 0; i < (int)ans.size(); ++i)         printf( %d %d n , ans[i].first + 1, ans[i].second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100010], ans;   bool vis[100010];   bool c[100010];   void find(int v) {     vis[v] = true;     bool del = true;     for (int u : adj[v]) {       del &= c[u];       if (!vis[u]) find(u);     }     if (c[v] && del) ans.push_back(v);   }   int main() {     int n;     cin >> n;     int root;     for (int i = 1; i <= n; i++) {       int p;       cin >> p >> c[i];       if (p != -1)         adj[p].push_back(i);       else         root = i;     }     find(root);     sort(ans.begin(), ans.end());     if (ans.empty()) cout <<  -1 ;     for (int v : ans) cout << v <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 111;   int N;   long long A[maxn];   map<long long, long long> f;   void rl(long long &x) {     char ch = (getchar());     x = 0;     while ((ch <  0  || ch >  9 )) ch = (getchar());     while (!(ch <  0  || ch >  9 )) x = x * 10 + ch -  0 , ch = (getchar());   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) rl(A[i]);     f[A[1] - 1] = 0;     for (int i = 2; i <= N; ++i)       for (map<long long, long long>::iterator j = f.lower_bound(A[i]);            j != f.end(); f.erase(j++)) {         long long x = j->first, y = j->second;         f[x % A[i]] = max(f[x % A[i]], y + 1ll * (i - 1) * (x - x % A[i]));         f[A[i] - 1] =             max(f[A[i] - 1], y + 1ll * (i - 1) * A[i] * ((x - A[i] + 1) / A[i]));       }     long long ans = 0;     for (map<long long, long long>::iterator i = f.begin(); i != f.end(); ++i)       ans = max(ans, i->first * N + i->second);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int MN = 1e5 + 4, INF = 0x3f3f3f3f;   int N, R, M, ans, D, A[MN], depth[MN], ord[MN], ecnt, ein[MN], eout[MN], st[MN];   std::vector<int> adj[MN];   struct nd {     int l, r, val;     nd *ch[2];     nd() : l(0), r(0), val(INF), ch{0} {}   } * sgt[MN];   void dfs(int src, int p, int d) {     depth[src] = d;     ein[src] = ++ecnt;     for (int i : adj[src]) {       if (i == p) continue;       dfs(i, src, d + 1);     }     eout[src] = ecnt;   }   inline void upd(nd *n) { n->val = std::min(n->ch[0]->val, n->ch[1]->val); }   void build(nd *&n, int l, int r) {     n = new nd();     n->l = l, n->r = r;     if (l == r) return;     int mid = l + r >> 1;     build(n->ch[0], l, mid);     build(n->ch[1], mid + 1, r);   }   void mod(nd *&n, nd *o, int p, int v) {     n = new nd();     n->l = o->l, n->r = o->r;     if (n->l == n->r) {       n->val = v;       return;     }     int mid = n->l + n->r >> 1;     bool b = p > mid;     n->ch[!b] = o->ch[!b];     mod(n->ch[b], o->ch[b], p, v);     upd(n);   }   int qry(nd *n, int l, int r) {     if (l > n->r || r < n->l) return INF;     if (l <= n->l && n->r <= r) return n->val;     return std::min(qry(n->ch[0], l, r), qry(n->ch[1], l, r));   }   int main() {     scanf( %d%d , &N, &R);     for (int i = 1; i <= N; scanf( %d , A + i++))       ;     for (int i = 1, a, b; i < N; ++i) {       scanf( %d%d , &a, &b);       adj[a].emplace_back(b);       adj[b].emplace_back(a);     }     dfs(R, -1, 1);     for (int i = 0; i < N; ++i) ord[i] = i + 1;     std::stable_sort(ord, ord + N, [=](const int &a, const int &b) {       return depth[a] < depth[b];     });     build(sgt[0], 1, N);     for (int i = 0; i < N; ++i) {       if (depth[ord[i]] != D) st[D++] = i;       mod(sgt[i + 1], sgt[i], ein[ord[i]], A[ord[i]]);     }     st[D] = N;     scanf( %d , &M);     for (int i = 0, a, b; i < M; ++i) {       scanf( %d%d , &a, &b);       a = ((a + ans) % N) + 1, b = (b + ans) % N;       printf( %d n ,              ans = qry(sgt[st[std::min(depth[a] + b, D)]], ein[a], eout[a]));     }   }


#include <bits/stdc++.h>   using namespace std;   const int L = 0, R = 1, U = 2, D = 3;   const int maxn = 5005;   class Node {    public:     int dir, l, r, u, d;   } a[maxn], b[maxn];   int n, m;   char s[maxn];   inline int id(int x, int y) { return x * m + y; }   inline void build(int x, int y) {     Node &u = a[id(x, y)];     int nx, ny;     for (nx = x, ny = y - 1; ny >= 0 && s[id(nx, ny)] ==  . ; --ny)       ;     if (ny < 0)       u.l = -1;     else       u.l = id(nx, ny);     for (nx = x, ny = y + 1; ny < m && s[id(nx, ny)] ==  . ; ++ny)       ;     if (ny >= m)       u.r = -1;     else       u.r = id(nx, ny);     for (nx = x - 1, ny = y; nx >= 0 && s[id(nx, ny)] ==  . ; --nx)       ;     if (nx < 0)       u.u = -1;     else       u.u = id(nx, ny);     for (nx = x + 1, ny = y; nx < n && s[id(nx, ny)] ==  . ; ++nx)       ;     if (nx >= n)       u.d = -1;     else       u.d = id(nx, ny);     return;   }   inline void connectX(int u, int v) {     if (~u) b[u].r = v;     if (~v) b[v].l = u;   }   inline void connectY(int u, int v) {     if (~u) b[u].d = v;     if (~v) b[v].u = u;     return;   }   inline void erase(int u) {     connectX(b[u].l, b[u].r);     connectY(b[u].u, b[u].d);     return;   }   inline void dfs(int x, int &res) {     Node &u = b[x];     ++res;     if (u.dir == L) {       if (!~u.l) return;       erase(x);       dfs(u.l, res);     } else if (u.dir == R) {       if (!~u.r) return;       erase(x);       dfs(u.r, res);     } else if (u.dir == U) {       if (!~u.u) return;       erase(x);       dfs(u.u, res);     } else {       if (!~u.d) return;       erase(x);       dfs(u.d, res);     }     return;   }   int main() {     cin >> n >> m;     for (int i = (0); i < (n); ++i) {       string buf;       cin >> buf;       for (int j = (0); j < (m); ++j) {         s[id(i, j)] = buf[j];         if (buf[j] ==  L )           a[id(i, j)].dir = L;         else if (buf[j] ==  R )           a[id(i, j)].dir = R;         else if (buf[j] ==  U )           a[id(i, j)].dir = U;         else if (buf[j] ==  D )           a[id(i, j)].dir = D;       }     }     for (int x = (0); x < (n); ++x)       for (int y = (0); y < (m); ++y)         a[id(x, y)].l = a[id(x, y)].r = a[id(x, y)].u = a[id(x, y)].d = -1;     for (int x = (0); x < (n); ++x)       for (int y = (0); y < (m); ++y) build(x, y);     int ans = 0, cnt = 0;     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (m); ++j)         if (s[id(i, j)] !=  . ) {           for (int x = (0); x < (n); ++x)             for (int y = (0); y < (m); ++y) b[id(x, y)] = a[id(x, y)];           int res = 0;           dfs(id(i, j), res);           if (res > ans)             ans = res, cnt = 1;           else if (res == ans)             ++cnt;         }     printf( %d %d n , ans, cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[500010];   int num[500010];   int cnt;   long long t, mid;   int n;   int skip[500010];   long long minn(long long a, long long b) { return a < b ? a : b; }   stack<int> sta;   int ok(long long k) {     int i, j, end = -1, last, type = -1, cnt = 0;     long long time = 0, min;     for (i = 0; i < n; ++i) {       ++time;       if (s[i] ==  H ) {         if (k) {           --k;           last = i;           type = 0;           continue;         }         type = 1;         if (skip[i] == -1) {           return 0;         }         time += (skip[i] - i) * 3;         if (end != -1) {           num[cnt++] = i - end;         }         num[cnt++] = skip[i] - i;         end = skip[i];         last = skip[i];         i = skip[i];       } else if (s[i] ==  S ) {         ++k;       }     }     if (type == 0 && end != -1) {       num[cnt++] = last - end;     }     time -= (n - 1 - last);     min = time;     for (i = cnt - 1; i >= 0; --i) {       if (i & 1) {         time += num[i];       } else {         time -= num[i];         min = minn(min, time);       }     }     return min <= t;   }   int main() {     long long left, right;     int i;     cin >> n >> t >> s;     memset(skip, -1, sizeof(skip));     for (i = 0; i < n; ++i) {       if (s[i] ==  H ) {         sta.push(i);       } else if (s[i] ==  S ) {         if (!sta.empty()) {           skip[sta.top()] = i;           sta.pop();         }       }     }     left = 0;     right = n + 1;     while (left < right) {       mid = (left + right) >> 1;       if (ok(mid))         right = mid;       else {         left = mid + 1;       }     }     if (right == n + 1)       printf( -1 n );     else       cout << left << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, maxn = 200007;   const long long MOD = 998244353;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const long long P = 19260817;   char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int 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 << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   }   inline long long readll() {     long long 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 << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   }   void write(int x) {     if (!x) putchar( 0 );     if (x < 0) x = -x, putchar( - );     static int sta[20];     register int tot = 0;     while (x) sta[tot++] = x % 10, x /= 10;     while (tot) putchar(sta[--tot] + 48);   }   int mod1(int x) {     if (x >= MOD) x -= MOD;     return x;   }   int n, k;   int a[maxn], c[maxn];   int lst[maxn];   struct mcmf {     struct edge {       int to, nxt, c, val;     } e[maxn << 1];     int tot = 1, head[maxn];     void addedge(int u, int v, int val, int cost) {       e[++tot] = (edge){v, head[u], cost, val};       head[u] = tot;       e[++tot] = (edge){u, head[v], -cost, 0};       head[v] = tot;     }     int s, t;     int dis[maxn], pre[maxn], vis[maxn];     bool spfa() {       queue<int> q;       while (!q.empty()) q.pop();       memset(dis, 0x3f, sizeof(dis));       memset(vis, 0, sizeof(vis));       memset(pre, 0, sizeof(pre));       q.push(s);       dis[s] = 0;       vis[s] = 1;       while (!q.empty()) {         int u = q.front();         q.pop();         vis[u] = 0;         for (int i = head[u]; i; i = e[i].nxt) {           int v = e[i].to;           if (e[i].val && dis[v] > dis[u] + e[i].c) {             dis[v] = dis[u] + e[i].c, pre[v] = i;             if (!vis[v]) {               vis[v] = true;               q.push(v);             }           }         }       }       return (pre[t] != 0);     }     int query() {       int mc = 0, mf = 0;       while (spfa()) {         int flow = INF;         for (int i = pre[t]; i; i = pre[e[i ^ 1].to]) flow = min(flow, e[i].val);         mf += flow;         for (int i = pre[t]; i; i = pre[e[i ^ 1].to]) {           e[i].val -= flow, e[i ^ 1].val += flow, mc += flow * e[i].c;         }       }       return mc;     }   } F;   vector<int> v;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , c + i);     int sum = 0;     v.push_back(0);     for (int i = 1; i <= n; i++)       if (a[i] != a[i - 1]) v.push_back(a[i]);     n = v.size() - 1;     for (int i = 1; i <= n; i++) {       sum += c[v[i]];       if (lst[v[i]]) F.addedge(lst[v[i]] + 1, i, 1, -c[v[i]]);       lst[v[i]] = i;       if (i != n) F.addedge(i, i + 1, k - 1, 0);     }     F.s = n + 1, F.t = n + 2;     F.addedge(F.s, 1, k - 1, 0);     F.addedge(n, F.t, k - 1, 0);     printf( %d , sum + F.query());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, flag = 1, num = 0;     cin >> n;     string st;     cin >> st;     for (int i = 0; i < n && flag; i++) {       if (i < n - 1) {         if (st[i] == st[i + 1]) {           if (st[i] !=  ? ) {             flag = 0;           } else {             num = 1;           }         }       }       if (st[i] ==  ? ) {         if (i == 0 || i == n - 1)           num += 1;         else {           if (st[i - 1] == st[i + 1]) num += 1;         }       }     }     if (flag == 0)       cout <<  No ;     else {       if (num >= 1)         cout <<  Yes ;       else         cout <<  No ;     }   }


#include <bits/stdc++.h>   using namespace std;   int k, t;   char n1[10005];   char n2[10005];   int swapindex[2];   bool same(char x[], char y[], int n) {     for (int i = 0; i < n; i++) {       if (x[i] != y[i]) {         return false;       }     }     return true;   }   int ham(char x[], char y[], int n) {     int temp = 0;     for (int i = 0; i < n; i++) {       if (x[i] != y[i]) {         temp++;       }     }     return temp;   }   int main() {     cin >> k;     for (int i = 0; i < k; i++) {       cin >> t;       for (int l = 0; l < t; l++) {         cin >> n1[l];       }       for (int l = 0; l < t; l++) {         cin >> n2[l];       }       if (ham(n1, n2, t) == 2) {         int temp = 0;         for (int i = 0; i < t; i++) {           if (n1[i] != n2[i]) {             swapindex[temp] = i;             temp++;           }         }         swap(n1[swapindex[0]], n2[swapindex[1]]);         if (same(n1, n2, t)) {           cout <<  Yes  << endl;         } else {           cout <<  No  << endl;         }       } else {         cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005];   long long k;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     long long sum = accumulate(a, a + n, 0LL);     if (sum < k)       cout << -1 << endl;     else {       long long L = 0, R = 1 << 30;       while (L < R) {         long long mid = (L + R + 1) / 2, cur = 0;         for (int i = 0; i < n; i++) cur += min(mid, (long long)a[i]);         if (cur > k)           R = mid - 1;         else           L = mid;       }       long long cur = k;       for (int i = 0; i < n; i++) cur -= min((long long)a[i], L);       queue<pair<int, int> > q;       for (int i = 0; i < n; i++)         if (a[i] - L > 0) q.push(make_pair(i, a[i] - L));       while (cur--) {         pair<int, int> p = q.front();         q.pop();         if (p.second - 1 > 0) q.push(make_pair(p.first, p.second - 1));       }       while (!q.empty()) {         pair<int, int> p = q.front();         q.pop();         cout << p.first + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long sum = 0, sum_mas;     cin >> n;     vector<int> mas;     for (int i = 0, temp = 0; i < n; i++) {       cin >> temp;       sum += temp;       mas.push_back(temp);     }     sum_mas = sum;     sort(mas.begin(), mas.end());     for (int i = 0; i < n; i++) {       sum += sum_mas;       sum_mas -= mas[i];     }     cout << sum - mas[mas.size() - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class A, class B>   ostream& operator<<(ostream& os, const pair<A, B>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream& os, T&& x) -> decltype(x.begin(), os) {     os <<  { ;     for (auto it = x.begin(); it != x.end(); ++it)       os << *it << (it == prev(x.end()) ?    :  ,  );     return os <<  } ;   }   void dump() {}   template <class T, class... Args>   void dump(T&& x, Args... args) {     cerr << x <<  ;   ;     dump(args...);   }   int t, n, m;   void solve() {     cin >> n >> m;     bool ans = false;     for (int i = 0; i < n; ++i) {       int x, y, z, w;       cin >> x >> y >> z >> w;       if (y == z) ans = true;     }     if (m % 2 == 0 && ans)       cout <<  YES n ;     else       cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(false);     for (cin >> t; t--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, yu, one, sum, cnt = 3;   long long ans[4];   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   int main() {     scanf( %I64d , &n);     if (!(n % 3))       printf( 1 1 %I64d , n - 2);     else       printf( 1 2 %I64d , n - 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct tree {     int lf;     int rt;     int we;   } a[2000010];   int v[2000010];   int main() {     int n;     scanf( %d , &n);     for (int j = 0; j < n - 1; j++) {       scanf( %d%d , &a[j].lf, &a[j].rt);       a[j].we = -1;       v[a[j].lf]++;       v[a[j].rt]++;     }     int maxi = 0, ans = -1, p = 0;     for (int j = 0; j < 2000010; j++) {       if (maxi < v[j]) {         maxi = v[j];         ans = j;       }     }     for (int j = 0; j < n - 1; j++)       if ((a[j].lf == ans || a[j].rt == ans) && a[j].we == -1) a[j].we = p++;     for (int j = 0; j < n - 1; j++)       if (a[j].we == -1) a[j].we = p++;     for (int j = 0; j < n - 1; j++) printf( %d n , a[j].we);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     n = (s[n - 2] - 48) * 10 + (s[n - 1] - 48);     if (n % 4)       cout <<  0 ;     else       cout <<  4 ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 121;   int a[N], b[N], last[N], kol, ans, v, u, i, n;   inline void add(int v, int u) {     a[++kol] = u;     b[kol] = last[v];     last[v] = kol;   }   void dfs(int v, int p, int len) {     if (len == 2) {       ++ans;       return;     }     int x = last[v];     while (x) {       if (a[x] != p) dfs(a[x], v, len + 1);       x = b[x];     }   }   int main() {     cin >> n;     for (i = 1; i < n; ++i) {       cin >> v >> u;       add(v, u);       add(u, v);     }     for (i = 1; i <= n; ++i) dfs(i, 0, 0);     cout << ans / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       int v[1000];       cin >> n;       for (int i = 0; i < n; i++) {         cin >> v[i];         v[i] = abs(v[i]);       }       int signo = 1;       for (int i = 0; i < n - 1; i++) {         cout << v[i] * signo <<    ;         signo *= -1;       }       cout << v[n - 1] * signo << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   const long long maxn = 200 + 10;   const long long inf = 1e18 + 1;   long long a[maxn][maxn], mini[maxn], res[maxn], dp[maxn][maxn], id[maxn],       what[maxn];   long long N;   inline void calcDp() {     memset(dp, 0, sizeof dp);     dp[N][0] = 1;     for (long long i = N - 1; i >= 0; i--) {       for (long long j = 0; j <= i; j++) {         dp[i][j] = min(dp[i + 1][j + 1] * bool(what[i] != 1) +                            (j && what[i] != 0 ? dp[i + 1][j - 1] : 0),                        inf);       }     }   }   int32_t main() {     long long n = in(), m = in(), k = lin();     N = n + m - 1;     memset(mini, 63, sizeof mini);     memset(res, -1, sizeof res);     memset(what, -1, sizeof what);     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) a[i][j] = in();     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) mini[i + j] = min(mini[i + j], a[i][j]);     }     iota(id, id + n + m - 1, 0);     sort(id, id + n + m - 1, [](const long long &a, const long long &b) {       return mini[a] < mini[b];     });     for (long long _ = 0; _ < n + m - 1; _++) {       long long i = id[_];       what[i] = 0;       calcDp();       if (dp[0][0] >= k) continue;       k -= dp[0][0];       what[i] = 1;     }     for (long long i = 0; i < n; i++, cout <<   n ) {       for (long long j = 0; j < m; j++) {         cout << (what[i + j] == 0 ?  (  :  ) );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> cnt(n);     for (int i = 0; i < n; ++i) cin >> cnt[i];     sort(cnt.begin(), cnt.end(), greater<int>());     long long ans = 0;     int prev = 1000000001;     for (int i = 0; i < n; ++i) {       if (cnt[i] >= prev) cnt[i] = prev - 1;       prev = max(cnt[i], 0);       ans += prev;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void parseArray(long long* A, long long n) {     for (long long K = 0; K < n; K++) {       cin >> A[K];     }   }   long long modInverse(long long a, long long b) {     return 1 < a ? b - modInverse(b % a, a) * b / a : 1;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long double dist(long long x, long long y, long long a, long long b) {     return sqrt((x - a) * (x - a) + (y - b) * (y - b));   }   void debug(long long* a, long long n) {     for (int k = 0; k < n; k++) {       cout << a[k] <<    ;     }     cerr <<   n ;   }   long long mod = 1000000007;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n;     cin >> n;     long long ans[n + 1];     memset(ans, 0, sizeof ans);     long long id = 1;     for (int k = 2; k <= n; k++) {       if (ans[k] == 0) {         for (int j = k; j <= n; j += k) {           ans[j] = id;         }         id++;       }     }     for (int k = 2; k <= n; k++) {       cout << ans[k] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     int sum, c = 0;     cin >> n;     int arr[3];     for (int i = 0; i < n; i++) {       for (int i = 0; i < 3; i++) {         cin >> arr[i];       }       sum = arr[0] + arr[1] + arr[2];       if (sum > 1) c++;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();     if (flag) x = -x;   }   using namespace std;   const int P = 1e9 + 7;   const int inv2 = (P + 1) / 2;   inline long long quickpow(long long x, long long k) {     long long res = 1;     x %= P;     while (k) {       if (k & 1) res = res * x % P;       x = x * x % P;       k >>= 1;     }     return res;   }   int k;   long long s[230][230], tri[230][230], jie[230], jieni[230];   inline void init() {     s[0][0] = 1;     for (int i = 1; i <= k; ++i)       for (int j = 1; j <= i; ++j)         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (i - 1)) % P;     tri[1][1] = 1;     for (int i = 2; i <= k + 1; ++i)       for (int j = 1; j <= i; ++j)         tri[i][j] = (tri[i - 1][j - 1] + tri[i - 1][j]) % P;     jie[0] = jieni[0] = 1;     for (int i = 1; i <= k; ++i) jie[i] = jie[i - 1] * i % P;     jieni[k] = quickpow(jie[k], P - 2);     for (int i = k - 1; i; --i) jieni[i] = jieni[i + 1] * (i + 1) % P;   }   inline long long get_c(int n, int m) {     if (n < 0 || m < 0 || n - m < 0) return 0;     return tri[n + 1][m + 1];   }   struct Complex {     long long a, b;     Complex() { a = 0, b = 0; }     Complex(long long jzp, long long zzz) { a = jzp, b = zzz; }   } phi, phihat;   inline Complex operator+(const Complex &a, const Complex &b) {     return Complex((a.a + b.a) % P, (a.b + b.b) % P);   }   inline Complex operator-(const Complex &a, const Complex &b) {     return Complex((a.a - b.a) % P, (a.b - b.b) % P);   }   inline Complex operator*(const Complex &a, const Complex &b) {     return Complex((a.a * b.a + 5 * a.b * b.b) % P, (a.a * b.b + a.b * b.a) % P);   }   inline Complex get_inv(Complex x) {     long long a = x.a, b = x.b;     if (!b) return Complex(quickpow(a, P - 2), 0);     long long d = b * quickpow((5ll * b * b - a * a) % P, P - 2) % P;     long long c = -a * quickpow(b, P - 2) % P * d % P;     Complex res = Complex(c, d);     return res;   }   inline Complex Pow(Complex x, long long k) {     Complex res(1, 0);     while (k) {       if (k & 1) res = res * x;       x = x * x;       k >>= 1;     }     return res;   }   inline long long work(long long n) {     Complex ans;     for (int j = 0; j <= k; ++j) {       Complex res;       for (int d = 0; d <= j; ++d) {         Complex A = Pow(phi, d) * Pow(phihat, j - d);         if (A.a == 1 && A.b == 0) {           if ((j - d) & 1)             res = res - Complex(n % P * get_c(j, d) % P, 0);           else             res = res + Complex(n % P * get_c(j, d) % P, 0);         }         A = A * (Complex(1, 0) - Pow(A, n)) * get_inv(Complex(1, 0) - A);         if ((j - d) & 1)           res = res - Complex(get_c(j, d), 0) * A;         else           res = res + Complex(get_c(j, d), 0) * A;       }       if ((k - j) & 1)         ans = ans - Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res;       else         ans = ans + Complex(s[k][j], 0) * Pow(get_inv(Complex(0, 1)), j) * res;     }     ans = ans * Complex(jieni[k], 0);     if (ans.b) puts( wawa );     return ans.a;   }   int main() {     phi = Complex(inv2, inv2);     phihat = Complex(inv2, P - inv2);     read(k);     init();     long long l, r;     read(l), read(r);     l += 2;     r += 2;     long long ans = work(r) - work(l - 1);     printf( %lld n , (ans % P + P) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t0, t1, t2, x1, x2;   long long count(long long y1, long long y2) {     return t1 * y1 + t2 * y2 - t0 * (y1 + y2);   }   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2) {       cout << x1 <<     << x2;       return 0;     }     long long by1 = 0, by2 = x2;     for (long long y1 = 0; y1 <= x1; y1++) {       long long l = (y1 == 0 ? 1 : 0), r = x2;       while (l <= r) {         long long m = (l + r) / 2;         long long c = count(y1, m);         if (c < 0)           l = m + 1;         else {           if ((t1 * y1 + t2 * m) * (by1 + by2) <                   (t1 * by1 + t2 * by2) * (y1 + m) ||               ((t1 * y1 + t2 * m) * (by1 + by2) ==                    (t1 * by1 + t2 * by2) * (y1 + m) &&                (by1 + by2) < (y1 + m))) {             by1 = y1;             by2 = m;           }           r = m - (r == m ? 1 : 0);         }       }     }     cout << by1 <<     << by2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     cout <<  0  <<     <<  0  <<     << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, a[22222], mx = 0;     cin >> n >> b;     mx = b;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int k = b / a[i];       int s = b % a[i];       for (int j = i + 1; j < n; j++) {         int p = a[j] * k + s;         mx = max(mx, p);       }     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, j, n, max = -1, count, a;     char c1, c2;     scanf( %d , &n);     char s[n];     scanf( %s , s);     for (i = 0; i < n - 1; i++) {       count = 0;       for (j = i + 1; j < n - 1; j++) {         if (s[j] == s[i]) {           if (s[j + 1] == s[i + 1]) count++;         }       }       if (count > max) {         max = count;         c1 = s[i];         c2 = s[i + 1];       }     }     printf( %c%c n , c1, c2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     set<long long> a = {1, n};     for (long long d = 2; d <= min((long long)sqrt(n) + 10, n - 1); d++) {       if (n % d == 0) {         a.insert(d);         a.insert(n / d);       }     }     long long ans = -1;     if (a.size() >= k) {       auto it = next(a.begin(), k - 1);       ans = *it;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 405;   int x, y, n, d, a[25][2], memo[N][N];   bool check(int i, int j) { return i * i + j * j <= d * d; }   int solve(int i, int j) {     int &ans = memo[i + 200][j + 200];     if (~ans) return ans;     set<int> st;     for (int k = 0; k < n; k++)       if (check(i + a[k][0], j + a[k][1]))         st.insert(solve(i + a[k][0], j + a[k][1]));     int mex = 0;     while (st.count(mex)) mex++;     return ans = mex;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x >> y >> n >> d;     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];     memset(memo, -1, sizeof memo);     cout << (solve(x, y) ?  Anton  :  Dasha );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v, vv, vv2;   int main() {     long long t, n, a[1000], k, f = 0;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < s.size() && cnt >= -1; i++) {       if (s[i] ==  ( )         cnt++;       else         cnt--;     }     if (!cnt)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > a(n);     for (int i = (0); i < ((n)); ++i) cin >> a[i].first >> a[i].second;     sort(a.begin(), a.end());     long long best = -1;     vector<long long> dp(n, 0);     for (int i = n - 1; i >= 0; --i) {       dp[i] = -1;       long long prev = 0;       for (int j = i; j < n; ++j) {         prev += a[j].first - a[i].first;         long long cost = a[i].second + prev + (j == n - 1 ? 0 : dp[j + 1]);         if (dp[i] == -1 || dp[i] > cost) {           dp[i] = cost;         }       }       if (dp[i] == -1) dp[i] = a[i].second;     }     cout << dp[0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long re = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) re = (re << 1) + (re << 3) + ch -  0 , ch = getchar();     return re * flag;   }   long long n, mx, m, ans;   namespace seg {   long long seg[1000010];   inline void update(long long num) {     seg[num] = seg[num << 1] + seg[num << 1 | 1];   }   inline void add(long long l, long long r, long long num, long long pos) {     if (l == r) {       seg[num] = 1;       return;     }     long long mid = (l + r) >> 1;     if (mid >= pos)       add(l, mid, num << 1, pos);     else       add(mid + 1, r, num << 1 | 1, pos);     update(num);   }   inline long long query(long long l, long long r, long long ql, long long qr,                          long long num) {     if (l >= ql && r <= qr) return seg[num];     long long mid = (l + r) >> 1, re = 0;     if (mid >= ql) re += query(l, mid, ql, qr, num << 1);     if (mid < qr) re += query(mid + 1, r, ql, qr, num << 1 | 1);     return re;   }   }  // namespace seg   struct node {     long long x, y;   } a[200010];   inline bool cmp1(const node &a, const node &b) { return a.x < b.x; }   inline bool cmp2(const node &a, const node &b) {     if (a.y != b.y) return a.y < b.y;     return a.x > b.x;   }   int main() {     n = read();     long long i, j, k;     for (i = 1; i <= n; i++) a[i].x = read(), a[i].y = read();     sort(a + 1, a + n + 1, cmp1);     for (i = 1; i <= n; i = j + 1) {       m++;       j = i;       while (j < n && a[j + 1].x == a[i].x) a[++j].x = m;       a[i].x = m;     }     sort(a + 1, a + n + 1, cmp2);     for (i = 1; i <= n; i = j + 1) {       mx++;       j = i;       while (j < n && a[j + 1].y == a[i].y) a[++j].y = mx;       a[i].y = mx;     }     reverse(a + 1, a + n + 1);     for (i = 1; i <= n; i = j + 1) {       j = i;       while (j < n && a[j + 1].y == a[i].y) j++;       for (k = i; k <= j; k++) {         seg::add(1, m, 1, a[k].x);       }       for (k = i; k <= j; k++) {         ans += seg::query(1, m, ((k == i) ? 1 : a[k - 1].x + 1), a[k].x, 1) *                seg::query(1, m, a[k].x, m, 1);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   void solve() {     cin >> n >> k;     if (n < k) {       cout << k - n <<   n ;       return;     }     if ((n % 2 == 0 and k % 2 == 0) or (n % 2 == 1 and k % 2 == 1))       cout << 0 <<   n ;     else       cout << 1 <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     for (long long i = 1; i <= t; i++) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     int rs = 1;     int temp_rs = 1;     cin >> n >> k;     int mang[n];     for (i = 0; i < n; i++) {       cin >> mang[i];       if (i > 0) {         if (mang[i] != mang[i - 1]) {           rs += 1;         } else {           rs = 1;         }         if (rs > temp_rs) {           temp_rs = rs;         }       }     }     cout << temp_rs;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   int l[200005], r[200005], last[200005];   int main() {     cin >> s >> t;     memset(last, -1, sizeof(last));     int j = 0, slen = s.size(), tlen = t.size();     for (int i = 0; i < slen; i++) {       l[i] = last[s[i] -  a ];       if (j < tlen && s[i] == t[j]) {         l[i] = j;         j++;       }       last[s[i] -  a ] = l[i];     }     memset(last, -1, sizeof(last));     j = tlen - 1;     for (int i = slen - 1; i >= 0; i--) {       r[i] = last[s[i] -  a ];       if (j >= 0 && s[i] == t[j]) {         r[i] = j;         j--;       }       last[s[i] -  a ] = r[i];     }     bool ok = true;     for (int i = 0; i < slen; i++) {       if (l[i] == -1 || r[i] == -1 || l[i] < r[i]) {         ok = false;         break;       }     }     if (ok)       cout <<  yes  << endl;     else       cout <<  no  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   const double pie = 3.1415926535;   long long power(long long x, long long y) {     if (y == 0)       return 1;     else {       if (y % 2 == 0)         return power(x * x, y / 2);       else         return x * power(x * x, (y - 1) / 2);     }   }   long long mod_power(long long x, long long y, long long m) {     long long r = 1;     x = x % m;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) r = (r * x) % m;       y = y / 2;       x = (x * x) % m;     }     return r;   }   unsigned long long gcd(unsigned long long x, unsigned long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   vector<long long> extended_Euclid(long long a, long long b) {     vector<long long> v(3);     if (b == 0) {       v[0] = a;       v[1] = 1;       v[2] = 0;       return v;     } else {       vector<long long> v1 = extended_Euclid(b, a % b);       v[0] = v1[0];       v[1] = v1[2];       v[2] = v1[1] - (a / b) * v1[2];       return v;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int TESTS = 1;     while (TESTS--) {       int n, k;       cin >> n >> k;       vector<vector<int> > adj;       long long t = 0;       int flag = 0;       for (int i = 0; i < k; i++) {         int m;         cin >> m;         vector<int> v(m);         for (int i = 0; i < m; i++) cin >> v[i];         if (v[0] == 1) {           for (int i = 1; i < m; i++) {             if (v[i] == (v[i - 1] + 1))               flag++;             else               break;           }           t += m - 1 - flag;         } else           t += m - 1;       }       long long ans = t + n - flag - 1;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-5;   const long double PI = acos(-1);   const int INF = (int)1e9;   const long long INFF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MXN = (int)3e5 + 7;   int main(void) {     int n;     cin >> n;     puts(n == 2 ?  2  :  1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[5];     int dp[350][350];     int n;     int i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     if (n == 1) {       if (a[0] != 0)         printf( BitLGM n );       else         printf( BitAryo n );     }     if (n == 2) {       int mx = max(a[0], a[1]);       for (i = 1; i <= mx; i++) {         dp[i][0] = 1;         dp[0][i] = 1;       }       for (i = 1; i <= a[0]; i++) {         for (j = 1; j <= a[1]; j++) {           for (k = 1; k < i; k++) {             if (dp[i - k][j] == 0) {               dp[i][j] = 1;               break;             }           }           for (k = 1; k < j; k++) {             if (dp[i][j - k] == 0) {               dp[i][j] = 1;               break;             }           }           for (k = 1; k <= min(i, j); k++) {             if (dp[i - k][j - k] == 0) {               dp[i][j] = 1;               break;             }           }         }       }       if (dp[a[0]][a[1]] == 1)         printf( BitLGM n );       else         printf( BitAryo n );     }     if (n == 3) {       int g = 0;       g = g ^ a[0];       g = g ^ a[1];       g = g ^ a[2];       if (g != 0)         printf( BitLGM n );       else         printf( BitAryo n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, r1, r2, t1, t2, f1 = 1, f2 = 1, col[100010];   vector<vector<int>> graph;   bool dfs(const int &v, const int &from, const int &color) {     if (col[v] != color) return 0;     for (auto &i : graph[v])       if (i != from)         if (!dfs(i, v, color)) return 0;     return 1;   }   int main() {     scanf( %d , &n);     graph.resize(n + 1);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &r1, &r2);       graph[r1].push_back(r2);       graph[r2].push_back(r1);     }     for (int i = 1; i <= n; ++i) scanf( %d , &col[i]);     for (int i = 1; i <= n; ++i)       for (auto &j : graph[i])         if (col[i] != col[j]) {           t1 = i;           t2 = j;           break;         }     if (!t1) {       printf( YES n1 );       return 0;     }     for (auto &i : graph[t1]) f1 &= dfs(i, t1, col[i]);     for (auto &i : graph[t2]) f2 &= dfs(i, t2, col[i]);     if (f1)       printf( YES n%d , t1);     else if (f2)       printf( YES n%d , t2);     else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   int convexP = 0;   const int SQ = 1075;   const long long mini = -8e18;   bool isErased[300001];   long long type[300001], a[300001], b[300001];   long long out[300001];   long long la[300001], lb[300001];   int convexSz, p;   double cross(int x, int y) { return (double)(lb[y] - lb[x]) / (la[x] - la[y]); }   void insert(long long m, long long b) {     if (convexSz > 0) {       if (la[convexSz - 1] == m) {         lb[convexSz - 1] = min(lb[convexSz - 1], b);       } else {         la[convexSz] = m;         lb[convexSz++] = b;       }     } else {       la[convexSz] = m;       lb[convexSz++] = b;     }     while (convexSz >= 3 && cross(convexSz - 3, convexSz - 2) >                                 cross(convexSz - 2, convexSz - 1)) {       swap(la[convexSz - 2], la[convexSz - 1]);       swap(lb[convexSz - 2], lb[convexSz - 1]);       --convexSz;     }   }   long long query(long long x) {     if (convexSz == 0) {       return mini;     }     while (p + 1 < convexSz && cross(p, p + 1) <= x) p++;     return -(lb[p] + la[p] * x);   }   pair<pair<long long, long long>, int> ret[300001];   pair<pair<long long, long long>, int> v[300001];   pair<pair<long long, long long>, int> u[300001];   pair<pair<long long, long long>, int> g[300001];   void merge(int &arSize, int st, int ed) {     int usz = 0;     for (int i = st; i <= ed; ++i) {       if (!isErased[i] && type[i] == 1) {         u[usz++] = {{-a[i], -b[i]}, i};       }     }     sort(u, u + usz, greater<pair<pair<int, int>, int> >());     int sz0 = 0, sz1 = 0, rpos = 0;     while (sz0 < arSize && sz1 < usz) {       if (v[sz0].first.first > u[sz1].first.first) {         ret[rpos++] = (v[sz0++]);       } else {         ret[rpos++] = (u[sz1++]);       }     }     while (sz0 < arSize) {       ret[rpos++] = (v[sz0++]);     }     while (sz1 < usz) {       ret[rpos++] = (u[sz1++]);     }     arSize = rpos;     for (int i = 0; i < arSize; ++i) {       v[i] = ret[i];     }   }   pair<long long, long long> q[300001];   int ttt[300001];   void solve() {     int n;     scanf( %d  , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld %lld , &type[i], &a[i]);       if (type[i] == 1) {         scanf( %lld  , &b[i]);       }       out[i] = mini;     }     int pos = 0;     int vsz = 0;     for (int i = 1; i <= n; i += SQ) {       int ed = min(n, i + SQ - 1);       int sz = 0;       int gsz = 0;       for (int j = i; j <= ed; ++j) {         if (type[j] == 2 && a[j] < i) {           isErased[a[j]] = true;           int id = a[j];           g[gsz++] = {{a[id], b[id]}, j};         }       }       int tsz = 0;       for (int j = 0; j < vsz; ++j) {         if (!isErased[v[j].second]) {           v[sz++] = v[j];         }       }       vsz = sz;       convexSz = 0;       p = 0;       for (int j = 0; j < vsz; ++j) {         insert(v[j].first.first, v[j].first.second);       }       int qsz = 0;       for (int j = i; j <= ed; ++j) {         q[qsz++] = {a[j], j};       }       sort(q, q + qsz);       if (convexSz > 0)         for (int j = 0; j < qsz; ++j) {           out[q[j].second] = query(q[j].first);         }       int tttsz = 0;       for (int j = i; j <= ed; ++j) {         if (type[j] == 3) {           for (int k = 0; k < tttsz; ++k) {             int tid = ttt[k];             if (!isErased[tid]) out[j] = max(out[j], a[tid] * a[j] + b[tid]);           }           for (int k = gsz - 1; k >= 0; --k) {             if (g[k].second < j) {               break;             }             out[j] = max(out[j], g[k].first.first * a[j] + g[k].first.second);           }         } else if (type[j] == 2) {           isErased[a[j]] = true;         } else {           ttt[tttsz++] = j;         }       }       merge(vsz, i, ed);     }     for (int i = 1; i <= n; ++i) {       if (type[i] == 3) {         if (out[i] != mini)           printf( %lld n , out[i]);         else           printf( EMPTY SET n );       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXK = 3000;   struct Update {     int cost;     long long profit;   };   struct CommutativeUndoableDS {     vector<array<long long, MAXK + 1> > dp;     CommutativeUndoableDS() {       dp.emplace_back();       fill(dp.back().begin(), dp.back().end(), 0);     }     void addUpdate(Update u) {       int sz = dp.size();       dp.push_back(dp.back());       for (int i = MAXK; i >= u.cost; i--) {         dp[sz][i] = max(dp[sz][i], dp[sz - 1][i - u.cost] + u.profit);       }     }     void undoLastUpdate() {       dp.pop_back();       assert(!dp.empty());     }     long long operator[](int i) { return dp.back()[i]; }   };   struct QueueUndoDS {     vector<pair<Update, int> > qyu;     CommutativeUndoableDS ds;     int rem_a;     QueueUndoDS() { rem_a = 0; }     void pushBack(pair<Update, int> u) {       ds.addUpdate(u.first);       qyu.emplace_back(u);     }     void pushBack(Update u) { pushBack(pair<Update, int>(u, 1)); }     void popFront() {       assert(!qyu.empty());       if (rem_a == 0) {         rem_a = qyu.size();         for (int i = 0; i < rem_a; i++) ds.undoLastUpdate();         reverse(qyu.begin(), qyu.end());         for (pair<Update, int> &u : qyu) {           u.second = 0;           ds.addUpdate(u.first);         }       }       vector<pair<Update, int> > popped[2];       while (qyu.back().second == 1) {         popped[1].push_back(qyu.back());         qyu.pop_back();         ds.undoLastUpdate();       }       int sz = rem_a & (-rem_a);       for (int i = 0; i < sz; i++) {         assert(qyu.back().second == 0);         popped[0].push_back(qyu.back());         qyu.pop_back();         ds.undoLastUpdate();       }       for (int z : {1, 0}) {         reverse(popped[z].begin(), popped[z].end());         for (pair<Update, int> &u : popped[z]) pushBack(u);       }       assert(qyu.back().second == 0);       ds.undoLastUpdate();       qyu.pop_back();       rem_a--;     }   };   vector<long long> a[MAXK];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     QueueUndoDS qds;     for (int i = 1; i <= n; i++) {       int sz;       cin >> sz;       a[i].resize(sz + 1);       for (int j = 1; j <= sz; j++) {         cin >> a[i][j];         a[i][j] += a[i][j - 1];       }       if (sz > k) a[i].resize(k + 1);       qds.pushBack({(int)a[i].size() - 1, a[i].back()});     }     long long ans = -1;     for (int i = 1; i <= n; i++) {       qds.popFront();       for (int j = 0; j < a[i].size(); j++) {         ans = max(ans, a[i][j] + qds.ds[k - j]);       }       qds.pushBack({(int)a[i].size() - 1, a[i].back()});     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   constexpr int maxn = 1e6 + 7;   struct DSU {     vector<int> f;     void init(int n) {       f.resize(n + 1);       iota(f.begin(), f.end(), 0);     }     int seek(int x) { return x == f[x] ? x : (f[x] = seek(f[x])); }     bool same(int u, int v) { return seek(u) == seek(v); }     void Merge(int u, int v) { f[seek(u)] = seek(v); }   } dsu;   vector<int> prime[maxn];   set<pair<int, int> > onepath;   void solve() {     dsu.init(maxn);     int n, m, mx = 0;     scanf( %d %d , &n, &m);     vector<int> vec(n + 1, 0);     for (int i = 1; i <= n; ++i) {       scanf( %d , &vec[i]);       mx = max(mx, vec[i]);     }     for (int i = 2; i <= mx + 1; ++i) {       if (!prime[i].size()) {         for (int j = i; j <= mx + 1; j += i) {           prime[j].push_back(i);         }       }     }     for (int i = 1; i <= n; ++i) {       for (auto fac : prime[vec[i]]) {         dsu.Merge(vec[i], fac);       }     }     for (int i = 1; i <= n; ++i) {       vector<int> has = prime[vec[i] + 1];       has.push_back(vec[i]);       for (int i = 0; i < has.size(); ++i) {         for (int j = i + 1; j < has.size(); ++j) {           int u = has[i], v = has[j];           u = dsu.seek(u), v = dsu.seek(v);           if (!dsu.same(u, v)) {             if (u > v) swap(u, v);             onepath.insert({u, v});           }         }       }     }     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       u = vec[u], v = vec[v];       u = dsu.seek(u), v = dsu.seek(v);       if (u > v) swap(u, v);       if (u == v)         puts( 0 );       else if (onepath.count({u, v}))         puts( 1 );       else         puts( 2 );     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int maxx = -1;     set<int> s;     map<int, int> m;     vector<int> l(n);     for (int i = 0; i < n; i++) {       cin >> l[i];       m[l[i]]++;       if (m[l[i]] > maxx) maxx = m[l[i]];       s.insert(l[i]);     }     cout << maxx <<     << s.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     long long int n, m, k;     vector<long long int> a, b;     while (t--) {       cin >> n >> m;       cout << n <<     << n * 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int n, m;   char s[MAXN];   int g[22][22];   int dp[1 << 21];   int sol(int msk) {     if (1 << m == msk + 1) return 0;     if (dp[msk] != -1) return dp[msk];     int tk[20] = {0};     int ntk[20] = {0};     int tksz = 0;     int ntksz = 0;     for (int i = 0; i < m; i++) {       if (msk & (1 << i))         tk[tksz++] = i;       else         ntk[ntksz++] = i;     }     int all = 0;     int save = 0;     int best = 10000000;     for (int i = 0; i < ntksz; i++) {       save = 0;       int x = ntk[i];       for (int j = 0; j < tksz; j++) {         int y = tk[j];         save += g[x][y] + g[y][x];       }       best = min(best, -save + sol(msk | (1 << ntk[i])));       all += save;     }     return dp[msk] = best + all;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d %d , &n, &m);     scanf( %s , s);     for (int i = 1; i < n; i++) {       g[s[i - 1] -  a ][s[i] -  a ]++;     }     for (int i = 0; i < m; i++) g[i][i] = 0;     int ans = sol(0);     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) ans += g[i][j];     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct Student {     int number;     int cost;     int com;   };   bool comp1(Student a, Student b) {     if (a.cost < b.cost) return true;     return false;   }   bool comp2(Student a, Student b) {     if (a.number < b.number) return true;     return false;   }   int main() {     long n, t, k, res, q;     cin >> n;     Student* A = new Student[n];     int* K = new int[n];     for (int i = 0; i < n; i++) {       A[i].number = i;       A[i].com = 0;       cin >> A[i].cost;     }     sort(A, A + n, comp1);     int* D = new int[n];     int* C = new int[n];     D[2] = -1;     C[2] = A[2].cost - A[0].cost;     K[2] = 1;     for (int i = 3; i < n; i++) {       D[i] = -1;       C[i] = A[i].cost - A[0].cost;       K[i] = 1;       if (i >= 5) {         if (i - 3 >= 2 && (C[i - 3] + A[i].cost - A[i - 2].cost) < C[i]) {           C[i] = C[i - 3] + A[i].cost - A[i - 2].cost;           D[i] = i - 3;           K[i] = K[i - 3] + 1;         }         if (i - 4 >= 2 && (C[i - 4] + A[i].cost - A[i - 3].cost) < C[i]) {           C[i] = C[i - 4] + A[i].cost - A[i - 3].cost;           D[i] = i - 4;           K[i] = K[i - 4] + 1;         }         if (i - 5 >= 2 && (C[i - 5] + A[i].cost - A[i - 4].cost) < C[i]) {           C[i] = C[i - 5] + A[i].cost - A[i - 4].cost;           D[i] = i - 5;           K[i] = K[i - 5] + 1;         }       }     }     q = n - 1;     while (q != -1) {       A[q].com = K[q];       t = q - 1;       while (t != D[q]) {         A[t].com = K[q];         t--;       }       q = D[q];     }     res = C[n - 1];     cout << res <<     << K[n - 1] << endl;     sort(A, A + n, comp2);     for (int i = 0; i < n; i++) cout << A[i].com <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct x {     int a, id, gp;     bool operator<(const x& xx) const { return a < xx.a; }   } s[100005];   bool cmp(x p, x q) { return p.id < q.id; }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i].a);       s[i].id = i;       s[i].gp = 1;     }     if (n == 2) {       printf( 0 n1 1 n );       return 0;     }     sort(s, s + n);     int a1 = s[n - 1].a + s[n - 2].a - s[0].a - s[1].a;     int a2 = max(s[n - 1].a + s[n - 2].a, s[n - 1].a + s[0].a + m) -              min(s[0].a + s[1].a + m, s[1].a + s[2].a);     if (a1 > a2) {       s[0].gp = 2;       sort(s, s + n, cmp);       printf( %d n , a2);       for (int i = 0; i < n; i++) printf( %d  , s[i].gp);     } else {       printf( %d n , a1);       for (int i = 0; i < n; i++) printf( 1  );     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000005;   int sp[maxN];   void seive() {     for (int i = 2; i <= 1000000; ++i) {       if (sp[i] != 0) continue;       for (int j = i; j <= 1000000; j += i) {         if (sp[j] == 0) sp[j] = i;       }     }   }   int nxtpow(int x) {     int p = 1;     while (p < x) p <<= 1;     return p;   }   int main() {     seive();     int n;     scanf( %d , &n);     int pow = 0;     int x = n;     int val = 1;     vector<int> pows;     while (x > 1) {       int p = sp[x];       int cnt = 1;       while (x > 1 && sp[x / p] == p) {         x /= p;         ++cnt;       }       x /= p;       pow = max(pow, nxtpow(cnt));       val *= p;       pows.push_back(cnt);     }     int ans = 0;     for (int x : pows) {       if (x != pow) {         ++ans;         break;       }     }     while (pow > 1) {       pow >>= 1;       ++ans;     }     printf( %d %d n , val, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     map<string, long long> m;     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x;       string y;       cin >> x >> y;       sort(y.begin(), y.end());       if (m[y] == 0)         m[y] = x;       else         m[y] = min(m[y], x);     }     long long ans = INT_MAX;     for (auto it = m.begin(); it != m.end(); it++) {       for (auto i = m.begin(); i != m.end(); i++) {         if (i == it) continue;         string s1 = it->first;         string s2 = i->first;         set<char> s;         for (long long p = 0; p < s1.size(); p++) s.insert(s1[p]);         for (long long q = 0; q < s2.size(); q++) s.insert(s2[q]);         if (s.size() == 3) ans = min(ans, m[s1] + m[s2]);       }     }     if (m[ ABC ] > 0) ans = min(ans, m[ ABC ]);     if (m[ A ] > 0 && m[ B ] > 0 && m[ C ] > 0)       ans = min(ans, m[ A ] + m[ B ] + m[ C ]);     if (ans != INT_MAX)       cout << ans << endl;     else       cout << -1 << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ans = 0, i, j, dp[N], half, n, a[N];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     for (i = n - 1; i >= 0; --i) {       dp[a[i]] = 1;       for (j = 2 * a[i]; j < N; j += a[i]) {         dp[a[i]] = max(dp[a[i]], dp[j] + 1);       }       ans = max(ans, dp[a[i]]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vc = vector<T>;   template <class T>   using vvc = vc<vc<T>>;   template <class T>   void mkuni(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   long long rand_int(long long l, long long r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<long long>(l, r)(gen);   }   template <class T>   void print(T x, int suc = 1) {     cout << x;     if (suc == 1)       cout <<   n ;     else       cout <<    ;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = 0; i < v.size(); i++)       print(v[i], i == (int)(v.size()) - 1 ? suc : 2);   }   const int INF = 0x3f3f3f;   const int maxn = 5e3 + 7;   const int mod = 998244353;   const int N = 1e7 + 7;   int n;   int dp[maxn][maxn];   int pre[maxn];   int sum[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     for (int i = 0; i < n; ++i) {       pre[i + 1] = upper_bound(a.begin(), a.end(), (a[i]) / 2) - a.begin();     }     dp[0][n + 1] = 1;     for (int i = 0; i < n; ++i) {       sum[n + 1] = dp[i][n + 1];       for (int k = n; k >= 1; --k) sum[k] = (sum[k + 1] + dp[i][k]) % mod;       for (int j = 1; j <= n; ++j) {         if (pre[n - j + 1] - i + 1 >= 0)           dp[i + 1][j] =               (dp[i + 1][j] + 1ll * dp[i][j] * (pre[n - j + 1] - i + 1) % mod) %               mod;         dp[i + 1][j] = (dp[i + 1][j] + sum[n - pre[n - j + 1] + 1]) % mod;       }     }     cout << dp[n][1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 998244353;   const int N = 200005, E = 524288;   int R[N * 4];   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % M;       a = a * a % M;       b >>= 1;     }     return ans;   }   long long wn[N * 4], iwn[N * 4];   void init() {     int i;     iwn[E / 2] = wn[E / 2] = 1;     long long s1 = qpow(3, (M - 1) / E);     long long s2 = qpow(s1, M - 2);     for (i = E / 2 + 1; i < E; ++i) {       wn[i] = wn[i - 1] * s1 % M;       iwn[i] = iwn[i - 1] * s2 % M;     }     for (i = E / 2 - 1; i; --i) {       wn[i] = wn[i << 1];       iwn[i] = iwn[i << 1];     }   }   void NTT(long long *f, int lim, int op) {     int i, j, k;     for (i = 0; i < lim; ++i) {       R[i] = (R[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0);       if (R[i] < i) swap(f[R[i]], f[i]);     }     for (i = 1; i < lim; i <<= 1)       for (j = 0; j < lim; j += (i << 1))         for (k = j; k < j + i; ++k) {           long long a = f[k], b = f[k + i];           long long w = (op == 1 ? wn[k - j + i] : iwn[k - j + i]);           f[k] = (a + b * w) % M;           f[k + i] = (a - b * w) % M;         }     if (op == -1) {       long long inv = qpow(lim, M - 2);       for (i = 0; i < lim; ++i) f[i] = f[i] * inv % M;     }   }   void mult(long long *a, int n, long long *b, int m) {     int lim = 1;     while (lim < n + m) lim <<= 1;     for (int i = n; i < lim; ++i) a[i] = 0;     for (int i = m; i < lim; ++i) b[i] = 0;     NTT(a, lim, 1);     NTT(b, lim, 1);     for (int i = 0; i < lim; ++i) a[i] = a[i] * b[i] % M;     NTT(a, lim, -1);   }   int p[66], k, i, n, m;   char s[N], t[N];   long long a[N * 4], b[N * 4], sum, vis[66], pre[N];   int main() {     init();     for (i = 0; i < 26; ++i) {       scanf( %d , &p[i]);       --p[i];     }     mt19937 rnd(time(0));     for (i = 0; i < 26; ++i)       for (int j = i; !vis[j]; j = p[j]) vis[j] = rnd() % M;     scanf( %s , s);     scanf( %s , t);     n = strlen(s);     m = strlen(t);     reverse(s, s + n);     for (i = 0; i < n; ++i) {       a[i] = (-vis[s[i] -  a ] - vis[p[s[i] -  a ]]) % M;       sum = (sum + vis[s[i] -  a ] * vis[p[s[i] -  a ]]) % M;     }     for (i = 0; i < m; ++i) {       b[i] = vis[t[i] -  a ];       pre[i] = vis[t[i] -  a ] * vis[t[i] -  a ] % M;     }     for (i = 1; i < m; ++i) pre[i] = (pre[i - 1] + pre[i]) % M;     mult(a, n, b, m);     for (i = n - 1; i < m; ++i)       if ((a[i] + pre[i] - (i - n >= 0 ? pre[i - n] : 0) + sum) % M == 0)         putchar( 1 );       else         putchar( 0 );   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int maxn = 2e5 + 5;   const double PI = 3.14159265358979323846;   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     set<long long> s1;     for (long long i = 0; i < n; i++) {       cin >> v[i];       if (s1.find(v[i]) != s1.end() && s1.size() > 1) {         cout << 0 <<   n ;         return;       }       s1.insert(v[i]);     }     if (n == 1) {       cout << -1 <<   n ;       return;     }     if (s1.size() == 1) {       cout << 1 <<   n ;       cout << v[0] <<   n ;       return;     }     sort(v.begin(), v.end());     set<long long> s2;     unordered_map<long long, long long> amp;     long long d = 0;     long long d2 = INT_MAX;     for (long long i = 1; i < n; i++) {       s2.insert(v[i] - v[i - 1]);       amp[v[i] - v[i - 1]]++;       ;       d = ((d) > (v[i] - v[i - 1]) ? (d) : (v[i] - v[i - 1]));       d2 = ((d2) < (v[i] - v[i - 1]) ? (d2) : (v[i] - v[i - 1]));     }     if (s2.size() > 2) {       cout << 0;       return;     }     if (s2.size() == 1) {       if (n == 2 && d / 2 == double(d) / 2) {         vector<long long> ans;         ans.push_back(v[0] - d);         ans.push_back(v[n - 1] + d);         ans.push_back(v[0] + d / 2);         sort(ans.begin(), ans.end());         cout << ans.size() <<   n ;         cout << ans[0] <<     << ans[1] <<     << ans[2];         return;       }       cout << 2 <<   n ;       cout << v[0] - d <<     << v[n - 1] + d;       return;     }     if (amp[d] > 1) {       cout << 0 <<   n ;       return;     }     for (long long i = 1; i < n; i++) {       if (v[i] - v[i - 1] == d && (double)d / 2 == d2) {         cout << 1 <<   n ;         cout << v[i - 1] + d2 <<   n ;         return;       }     }     cout << 0 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long l = 1;     while (l--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void speed() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const long long N = 1e5 + 5;   const long long NN = 105;   const long long MAX = 2e5 + 123;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   map<long long, long long> m;   long long ans = 1, cnt;   vector<pair<long long, pair<long long, long long> > > v;   void hajime() {     long long n, a[N * 2];     scanf( %I64d , &n);     for (long long i = 1; i <= n; i++) scanf( %I64d , &a[i]);     a[n + 1] = -INF;     long long l = 1;     long long mx = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < a[i + 1]) {         ans++;       } else {         mx = max(mx, ans);         v.push_back({ans, {l, i}});         ans = 1;         l = i + 1;       }     }     for (int i = 0; i < v.size(); i++) {       if (i) {         if (a[v[i].second.first + 1] > a[v[i - 1].second.second]) {           mx = max(mx, v[i].first + v[i - 1].first - 1);         }       }       if (i != v.size() - 1) {         if (a[v[i].second.second - 1] < a[v[i + 1].second.first]) {           mx = max(mx, v[i].first + v[i + 1].first - 1);         }       }     }     cout << mx;   }   int main() {     long long miyagi = 1;     while (miyagi--) hajime();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n;   long long nim[N], prefnim[N];   vector<pair<long long, long long> > sum[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       long long cur = i;       for (long long j = i + 1; j <= n; j++) {         cur += j;         if (cur > n) break;         sum[cur].push_back({i, j});       }     }     for (long long i = 1; i <= n; i++) {       unordered_set<long long> s;       for (auto &it : sum[i])         s.insert(prefnim[it.second] ^ prefnim[it.first - 1]);       long long val = 0;       while (s.find(val) != s.end()) val++;       nim[i] = val;       prefnim[i] = prefnim[i - 1] ^ nim[i];     }     if (nim[n] == 0)       cout <<  -1 ;     else {       long long ans = 1e9;       for (auto &it : sum[n]) {         if ((prefnim[it.second] ^ prefnim[it.first - 1]) == 0)           ans = min(ans, it.second - it.first + 1);       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dem[100001];   long long f[100002];   int main() {     int n;     long long x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       dem[x]++;     }     f[1] = dem[1];     for (int i = 2; i < 100002; i++) f[i] = max(f[i - 2] + dem[i] * i, f[i - 1]);     cout << f[100001];   }


#include <bits/stdc++.h>   using namespace std;   long long dpf[110][100][60];   long long dpg[110][100][60];   int diff;   int likes_init = 0;   const long long mod = 998244353;   long long fast_exp(long long b, int e) {     b = b % mod;     if (e == 0) return 1;     if (e == 1) return b;     if (e % 2 == 1) return (b * fast_exp(b, e - 1)) % mod;     return fast_exp((b * b) % mod, e / 2);   }   long long modinv(long long x) {     assert(x % mod != 0);     return fast_exp(x, mod - 2);   }   long long f(int curr, int likes, int runs) {     if (dpf[curr][likes - likes_init][runs] == 1LL << 40) {       int dislike = likes + runs - diff;       if (curr == 0) return 0;       if (runs == 0) {         return curr;       }       if (dislike < 0) return 0;       long long tmp1, tmp2, tmp3;       tmp1 = (curr == 0 ? 0 : curr * f(curr + 1, likes + 1, runs - 1));       tmp2 =           (likes - curr == 0 ? 0 : (likes - curr) * f(curr, likes + 1, runs - 1));       tmp3 = (dislike == 0 ? 0 : dislike * f(curr, likes, runs - 1));       long long tmp = (tmp1 + tmp2 + tmp3) % mod;       long long ans = (tmp * modinv(likes + dislike)) % mod;       return dpf[curr][likes - likes_init][runs] = ans;     } else {       return dpf[curr][likes - likes_init][runs];     }   }   long long g(int curr, int likes, int runs) {     if (dpg[curr][likes - likes_init][runs] == 1LL << 40) {       int dislike = likes + runs - diff;       if (curr == 0) return 0;       if (runs == 0) {         return curr;       }       if (dislike < 0) return 0;       long long tmp1 = (curr == 0 ? 0 : curr * g(curr - 1, likes, runs - 1));       long long tmp2 = (likes == 0 ? 0 : likes * g(curr, likes + 1, runs - 1));       long long tmp3 =           (dislike - curr == 0 ? 0 : (dislike - curr) * g(curr, likes, runs - 1));       long long tmp = (tmp1 + tmp2 + tmp3) % mod;       long long ans = (tmp * modinv(likes + dislike)) % mod;       return dpg[curr][likes - likes_init][runs] = ans;     } else {       return dpg[curr][likes - likes_init][runs];     }   }   int main() {     int n, m;     cin >> n >> m;     diff = m;     int a[n];     for (int i = 0; i < 110; i++) {       for (int j = 0; j < 100; j++) {         for (int k = 0; k < 60; k++) {           dpf[i][j][k] = 1LL << 40;           dpg[i][j][k] = 1LL << 40;         }       }     }     bool good[n];     int tl = 0;     for (int i = 0; i < n; i++) {       cin >> good[i];     }     for (int i = 0; i < n; i++) {       cin >> a[i];       if (good[i]) {         diff += a[i];         tl += a[i];       } else         diff -= a[i];     }     likes_init = tl;     for (int i = 0; i < n; i++) {       if (good[i]) {         cout << (f(a[i], tl, m) % mod + mod) % mod <<   n ;       } else {         cout << (g(a[i], tl, m) % mod + mod) % mod <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, m = 0, n, cnt = 0, x = 0, ans = 0, y, sum = 0, l = 0,                            r = 0;     cin >> n >> m;     string a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           for (k = j; k < m; k++) {             if (a[i][k] ==  B ) {               cnt++;             } else {               break;             }           }           cnt = cnt / 2;           i += cnt;           j += cnt;           i++;           j++;           cout << i <<     << j;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   int n, m, a[MAXN];   int main() {     cin.tie(0);     int T;     cin >> T;     while (T--) {       int ans = 0;       cin >> n >> m;       for (register int i = 1; i <= n; ++i) cin >> a[i];       if (n > m || n == 2) {         puts( -1 );         continue;       }       for (register int i = 1; i <= n; ++i) ans += a[i] + a[i];       m -= n;       int minn1 = 0x3f3f3f3f, minn2 = 0x3f3f3f3f, p1, p2;       for (register int i = 1; i <= n; ++i) {         if (a[i] < minn1)           p2 = p1, p1 = i, minn2 = minn1, minn1 = a[i];         else if (a[i] < minn2)           minn2 = a[i], p2 = i;       }       ans += m * (minn1 + minn2);       printf( %d n , ans);       for (register int i = 1; i <= m; ++i) printf( %d %d n , p1, p2);       for (register int i = 2; i <= n; ++i) printf( %d %d n , i, i - 1);       printf( 1 %d n , n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct Data {     int u, v, w;     Data() {}     Data(int x, int y, int z) : u(x), v(y), w(z) {}   };   int n;   vector<Data> edge, ans;   vector<int> neighbor[N];   void dfs(int u, int par, vector<int> &leaf) {     if (neighbor[u].size() == 1) {       leaf.push_back(u);       return;     }     for (auto v : neighbor[u])       if (v != par) dfs(v, u, leaf);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y, w;       cin >> x >> y >> w;       edge.push_back(Data(x, y, w));       neighbor[x].push_back(y);       neighbor[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (neighbor[i].size() == 2) return cout <<  NO , 0;     cout <<  YES n ;     for (auto Q : edge) {       int u = Q.u, v = Q.v, w = Q.w;       vector<int> Uleaf, Vleaf;       dfs(u, v, Uleaf);       dfs(v, u, Vleaf);       int u1 = Uleaf.front(), u2 = Uleaf.back();       int v1 = Vleaf.front(), v2 = Vleaf.back();       ans.push_back(Data(u1, v1, w / 2));       ans.push_back(Data(u2, v2, w / 2));       if (u1 != u2) ans.push_back(Data(u1, u2, -w / 2));       if (v1 != v2) ans.push_back(Data(v1, v2, -w / 2));     }     cout << ans.size() <<   n ;     for (auto Q : ans) {       int u = Q.u, v = Q.v, w = Q.w;       cout << u <<     << v <<     << w <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[200003], b[200003], ch[200003];   void Do() {     int n, f = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n - 1; i++) {       if (a[i] == 0) f = 1;       if (f) a[i] = a[i + 1];     }     f = 0;     for (int i = 0; i < n - 1; i++) {       if (b[i] == 0) f = 1;       if (f) b[i] = b[i + 1];     }     int beg = a[0], desire;     ch[0] = a[0];     for (int i = 0; i < n - 1; i++)       if (b[i] == beg) desire = i;     int ind = 1;     for (int i = desire + 1; i < n - 1; i++) {       ch[ind++] = b[i];       if (ind == n - 1) break;     }     if (ind != n - 1) {       for (int i = 0;; i++) {         ch[ind++] = b[i];         if (ind == n - 1) break;       }     }     bool flag = true;     for (int i = 0; i < n - 1; i++)       if (a[i] != ch[i]) flag = false;     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     Do();     return 0;   }