#include <bits/stdc++.h>   using namespace std;   const int SIZE = 9000;   const int mod = 1e9 + 7;   const int maxv = 9000;   bool vis[maxv + 1][maxv + 1], in[maxv + 1][maxv + 1];   vector<int> v[maxv + 1];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= maxv; i++) v[i].push_back(0), in[i][0] = true;     for (int i = 1; i <= n; i++) {       for (auto it : v[a[i]]) {         if (vis[a[i]][it]) continue;         for (int j = a[i] + 1; j <= maxv; j++) {           if (in[j][it ^ a[i]]) break;           v[j].push_back(it ^ a[i]);           in[j][it ^ a[i]] = true;         }         vis[a[i]][it] = true;       }       v[a[i]].clear();     }     set<int> ordered(v[maxv].begin(), v[maxv].end());     cout << ordered.size() <<   n ;     for (auto it : ordered) cout << it <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, l, m, n, cnt = 0, ans = 0;     char a[8][8];     for (i = 0; i < 8; i++)       for (j = 0; j < 8; j++) cin >> a[i][j];     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (a[i][j] ==  B ) cnt++;       }       if (cnt == 8) ans++;       cnt = 0;     }     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (a[j][i] ==  B ) cnt++;       }       if (cnt == 8) ans++;       cnt = 0;     }     if (ans == 16) ans = 8;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, l, v1, v2, k;     while (~scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k)) {       if (k >= n) {         printf( %.10lf n , l * 1.0 / v2);         continue;       }       int t = (n - 1) / k;       double s = v2 * 1.0 / v1;       double kk = (1 + s) / (3 + s);       double temp = kk + t * (1 - kk);       temp = l * 1.0 / (temp * v1);       printf( %.10lf n , temp * (kk / s + t * (1 - kk)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 55;   int n, m;   int a[MAXN][MAXN];   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> m;       set<int> rows, columns;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cin >> a[i][j];           if (a[i][j] == 1) rows.insert(i), columns.insert(j);         }       }       int res = min(n - rows.size(), m - columns.size());       if (res % 2 == 0)         cout <<  Vivek  << endl;       else         cout <<  Ashish  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, cnt1, cnt2;     scanf( %d %d , &n, &m);     string str1, str2;     cin >> str1 >> str2;     if (str1 == str2) {       return !printf( YES n );     }     cnt1 = cnt2 = 0;     int l2;     for (i = 0; i < n && i < m; i++) {       if (str1[i] == str2[i]) {         cnt1++;       } else {         l2 = i;         break;       }     }     for (i = n - 1, j = m - 1; i >= 0 && j >= l2; i--, j--) {       if (str1[i] == str2[j]) {         cnt2++;       } else {         break;       }     }     bool ok = 0;     for (i = 0; i < n; i++)       if (str1[i] ==  * ) ok = 1;     if (cnt1 + cnt2 + 1 == n && ok)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     scanf( %d , &t);     while (t--) {       int a, b;       scanf( %d%d , &a, &b);       int k = min(max(2 * a, b), max(a, 2 * b));       printf( %d n , k * k);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int L = 30;   int n;   int a[N];   struct Trie {     Trie *l, *r;     Trie(Trie *l_, Trie *r_) {       l = l_;       r = r_;     }   };   struct Ans {     Trie *t;     long long ans;   };   int get(Trie *l, Trie *r, int i) {     if (i == -1) return 0;     if (l->l && r->l && l->r && r->r)       return min(get(l->l, r->l, i - 1), get(l->r, r->r, i - 1));     else if (l->l && r->l)       return get(l->l, r->l, i - 1);     else if (l->r && r->r)       return get(l->r, r->r, i - 1);     else if (l->l)       return get(l->l, r->r, i - 1) + (1 << i);     else       return get(l->r, r->l, i - 1) + (1 << i);   }   Ans solve(int i, int mn, int mx) {     if (i == -1) return {new Trie(NULL, NULL), 0};     int l = lower_bound(a, a + n, mn) - a;     int r = upper_bound(a, a + n, mx) - a - 1;     if (a[r] < mn + (1 << i)) {       auto t = solve(i - 1, mn, mn + (1 << i) - 1);       t.t = new Trie(t.t, NULL);       return t;     }     if (mn + (1 << i) <= a[l]) {       auto t = solve(i - 1, mn + (1 << i), mx);       t.t = new Trie(NULL, t.t);       return t;     }     {       auto l = solve(i - 1, mn, mn + (1 << i) - 1);       auto r = solve(i - 1, mn + (1 << i), mx);       Ans ans;       ans.ans = l.ans + r.ans + get(l.t, r.t, i - 1) + (1 << i);       ans.t = new Trie(l.t, r.t);       return ans;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     cout << solve(L - 1, 0, (1 << L) - 1).ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct _lap {     int p;     int qu;   } lap;   bool cmp(const lap &a, const lap &b) { return a.p < b.p; }   void remain() {     int n;     cin >> n;     vector<lap> laps;     for (int i = 0; i < n; ++i) {       lap x;       cin >> x.p >> x.qu;       laps.push_back(x);     }     sort(laps.begin(), laps.end(), cmp);     enum RE { HAPPY_ALEX, POOR_ALEX };     RE re = POOR_ALEX;     for (int i = 0; i < laps.size() - 1; ++i) {       if (!(laps[i].qu < laps[i + 1].qu)) {         re = HAPPY_ALEX;         break;       }     }     if (re == HAPPY_ALEX)       cout <<  Happy Alex ;     else       cout <<  Poor Alex ;   }   int main() {     remain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, k;   int ans;   int f[1000001];   bool done[1000001];   vector<int> g[1000001];   void dfs(int u) {     done[u] = 1;     for (int &v : g[u])       if (done[v]) {         swap(v, g[u].back());         g[u].pop_back();         break;       }     for (int v : g[u]) dfs(v);     sort(g[u].begin(), g[u].end(), [](int x, int y) { return f[x] < f[y]; });     while ((g[u].size() >= 2) &&            (f[g[u].back()] + f[g[u][g[u].size() - 2]] + 2 > k)) {       ans++;       g[u].pop_back();     }     if (g[u].empty())       return;     else if (f[g[u].back()] > k) {       ans++;       f[u] = -1e9;     } else       f[u] = f[g[u].back()] + 1;   }   int main() {     read(n);     read(k);     {       int u, v;       for (int i = (1); i < (n); i++) {         read(u);         read(v);         g[u].push_back(v);         g[v].push_back(u);       }     }     int root = 1;     for (int i = (1); i <= (n); i++)       if (g[i].size() > 1) {         root = i;         break;       }     dfs(root);     if (f[root] >= 0) ans++;     writeln(ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, i, flag = 0, j;       cin >> n;       long long int a[n];       set<int> s;       for (i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       for (i = 1; i <= 1024; i++) {         set<int> temp;         for (j = 0; j < n; j++) {           temp.insert(i ^ a[j]);         }         if (temp == s) {           flag = 1;           cout << i << endl;           break;         }       }       if (flag == 0) cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main(void) {     unsigned short int m, n, c;     scanf( %hu%hu , &m, &n);     c = m * n;     int i = 1;     while (i) {       if (c >= 2 * i)         i++;       else         break;     }     printf( %d n , (i - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c, hr, hb, wr, wb;   int main() {     cin >> c >> hr >> hb >> wr >> wb;     long long i, mx = 0, mxi;     for (i = 0; i <= c / wr; i += 1000)       if (i * hr + ((c - i * wr) / wb) * hb > mx) {         mx = i * hr + ((c - i * wr) / wb) * hb;         mxi = i;       }     for (i = max((long long)0, mxi - 20005); i <= min(c / wr, mxi + 20005); i++)       if (i * hr + ((c - i * wr) / wb) * hb > mx) {         mx = i * hr + ((c - i * wr) / wb) * hb;         mxi = i;       }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, m;   char str[N][N];   int use[N];   int ans[N], tot;   int Ncnt, root;   struct Node {     vector<int> ch;     int color;     int leaf;     int kind;     Node(void){};   } tree[N * N * 2];   void fail() {     puts( NO );     exit(0);   }   void build() {     root = Ncnt;     tree[root].kind = 0;     for (int i = 1; i <= m; i++) {       ++Ncnt;       tree[Ncnt].leaf = i;       tree[root].ch.push_back(Ncnt);     }   }   void paint(int rt) {     if (tree[rt].leaf) {       if (use[tree[rt].leaf])         tree[rt].color = 2;       else         tree[rt].color = 0;       return;     }     int empty = 1, half = 0, full = 1;     for (int i = 0; i < tree[rt].ch.size(); i++) {       int v = tree[rt].ch[i];       paint(v);       if (tree[v].color) empty = 0;       if (!tree[v].color) full = 0;       if (tree[v].color == 1) half = 1;     }     if ((!empty && !full) || (half))       tree[rt].color = 1;     else if (full)       tree[rt].color = 2;     else if (empty)       tree[rt].color = 0;   }   void clear(int rt) {     vector<int> newch;     for (int i = 0; i < tree[rt].ch.size(); i++) {       int v = tree[rt].ch[i];       if (tree[v].leaf) {         newch.push_back(v);         continue;       }       if (tree[v].ch.size() == 1)         newch.push_back(tree[v].ch[0]);       else         newch.push_back(v);     }     tree[rt].ch = newch;     if (tree[rt].ch.size() <= 2) tree[rt].kind = 0;   }   void arrange(int rt) {     if (tree[rt].leaf) return;     vector<int> son = tree[rt].ch, emp, ful;     int d = -1;     for (int i = 0; i < son.size(); i++) {       int v = tree[rt].ch[i];       if (tree[v].color == 1) {         if (d != -1) fail();         if (d == -1) d = i;       }       if (tree[v].color == 0) emp.push_back(i);       if (tree[v].color == 2) ful.push_back(i);     }     if (d != -1) arrange(son[d]);     int empn = emp.size(), fuln = ful.size();     if (tree[rt].kind) {       if ((empn && emp[empn - 1] - emp[0] != empn - 1) ||           (fuln && ful[fuln - 1] - ful[0] != fuln - 1))         fail();       if (d != -1) {         if (empn && fuln) {           if (d == 0 || d == son.size() - 1) {             fail();           }         }       }       if (empn && fuln) {         if (emp[0] > ful[0]) {           reverse(emp.begin(), emp.end());           reverse(ful.begin(), ful.end());         }       }       if (empn && !fuln && d != -1) {         if (emp[0] > d) reverse(emp.begin(), emp.end());       }       if (fuln && !empn && d != -1) {         if (ful[0] < d) reverse(ful.begin(), ful.end());       }       vector<int> newch;       for (int i = 0; i < empn; i++) newch.push_back(son[emp[i]]);       if (d != -1) {         int v = son[d];         for (int i = 0; i < tree[v].ch.size(); i++)           newch.push_back(tree[v].ch[i]);       }       for (int i = 0; i < fuln; i++) newch.push_back(son[ful[i]]);       tree[rt].ch = newch;     } else {       tree[rt].kind = 1;       vector<int> newch;       if (empn) {         ++Ncnt;         for (int i = 0; i < empn; i++) tree[Ncnt].ch.push_back(son[emp[i]]);         clear(Ncnt);         newch.push_back(Ncnt);       }       if (d != -1) {         int v = son[d];         for (int i = 0; i < tree[v].ch.size(); i++)           newch.push_back(tree[v].ch[i]);       }       if (fuln) {         ++Ncnt;         for (int i = 0; i < fuln; i++) tree[Ncnt].ch.push_back(son[ful[i]]);         clear(Ncnt);         newch.push_back(Ncnt);       }       tree[rt].ch = newch;     }     clear(rt);   }   void solve(int rt) {     if (tree[rt].leaf) return;     int count = 0, full = 0;     for (int i = 0; i < tree[rt].ch.size(); i++) {       int v = tree[rt].ch[i];       if (tree[v].color == 1) count++;       if (tree[v].color == 2) full++;     }     if (count > 2) fail();     if (full || count > 1) {       vector<int> son = tree[rt].ch, ful, hlf;       for (int i = 0; i < son.size(); i++) {         int v = son[i];         if (tree[v].color == 1) hlf.push_back(i);         if (tree[v].color == 2) ful.push_back(i);       }       int fuln = ful.size(), hlfn = hlf.size();       if (tree[rt].kind == 1) {         if (fuln && ful[fuln - 1] - ful[0] != fuln - 1) fail();         for (int i = 0; i < hlfn; i++)           if (fuln && hlf[i] != ful[0] - 1 && hlf[i] != ful[fuln - 1] + 1) fail();         vector<int> newch;         for (int i = 0; i < son.size(); i++) {           if (tree[son[i]].color != 1)             newch.push_back(son[i]);           else {             arrange(son[i]);             vector<int> pp = tree[son[i]].ch;             if ((hlfn != 1 && i != hlf[0]) ||                 (hlfn == 1 && fuln && hlf[0] == ful[fuln - 1] + 1))               reverse(pp.begin(), pp.end());             for (int i = 0; i < pp.size(); i++) newch.push_back(pp[i]);           }         }         tree[rt].ch = newch;       } else {         vector<int> newch;         for (int i = 0; i < hlfn; i++) arrange(son[hlf[i]]);         for (int i = 0; i < son.size(); i++)           if (tree[son[i]].color == 0) newch.push_back(son[i]);         int nowq = ++Ncnt;         tree[nowq].kind = 1;         newch.push_back(nowq);         if (hlfn) {           int v = son[hlf[0]];           for (int i = 0; i < tree[v].ch.size(); i++)             tree[nowq].ch.push_back(tree[v].ch[i]);         }         if (fuln) {           int nowp = ++Ncnt;           tree[nowp].kind = 0;           for (int i = 0; i < fuln; i++) tree[nowp].ch.push_back(son[ful[i]]);           clear(nowp);           tree[nowq].ch.push_back(nowp);         }         if (hlfn == 2) {           int v = son[hlf[1]];           for (int i = tree[v].ch.size() - 1; i >= 0; i--)             tree[nowq].ch.push_back(tree[v].ch[i]);         }         clear(nowq);         tree[rt].ch = newch;       }     } else {       for (int i = 0; i < tree[rt].ch.size(); i++) {         int v = tree[rt].ch[i];         if (tree[v].color == 1) solve(v);       }     }     clear(rt);   }   void dfs(int rt) {     if (tree[rt].leaf) {       ans[++tot] = tree[rt].leaf;       return;     }     for (int i = 0; i < tree[rt].ch.size(); i++) dfs(tree[rt].ch[i]);   }   int main() {     scanf( %d , &n);     m = n;     for (int i = 1; i <= n; i++) scanf( %s , str[i] + 1);     build();     for (int i = 1; i <= n; i++) {       memset(use, 0, sizeof use);       for (int j = 1; j <= m; j++)         if (str[i][j] ==  1 ) use[j]++;       paint(root);       solve(root);     }     dfs(root);     puts( YES );     for (int i = 1; i <= n; i++, puts(  ))       for (int j = 1; j <= n; j++) printf( %c , str[i][ans[j]]);     return 0;   }


#include <bits/stdc++.h>   long long int power(long long int a, long long int b) {     long long int ans = 1;     long long int k = a;     while (b) {       if (b % 2 == 1) ans *= k, ans %= 998244353;       k *= k, k %= 998244353;       b /= 2;     }     return ans;   }   int a, b, start;   int z[40];   long long int ans[60];   int y[200010][60];   void swap(int s, int t) {     for (int j = 0; j <= 53; j++) {       int k = y[s][j];       y[s][j] = y[t][j];       y[t][j] = k;     }   }   void func1(int k) {     if (k == start) {       int sum = 0;       for (int j = 0; j < b; j++) sum += z[j] % 2;       ans[sum]++;       return;     }     func1(k + 1);     for (int j = 0; j < b; j++) z[j] += y[k][j];     func1(k + 1);     for (int j = 0; j < b; j++) z[j] -= y[k][j];   }   int diff(long long int a, long long int b) {     int sum = 0;     while (a > 0 || b > 0) {       if (b % 2 == 1) {         if (a % 2 == 0)           sum++;         else           sum--;       }       b /= 2, a /= 2;     }     return sum;   }   std::vector<int> V;   long long int S[20010][40], T[20010][40];   int main() {     scanf( %d%d , &a, &b);     for (int i = 1; i <= a; i++) {       long long int c;       scanf( %lld , &c);       for (int j = 0; j < b; j++) {         y[i][j] = c % 2;         c /= 2;       }     }     start = 1;     for (int j = 0; j < b; j++) {       int p = -1;       for (int i = start; i <= a; i++) {         if (y[i][j] == 1) {           p = i;           break;         }       }       if (p == -1) {         V.push_back(j);         continue;       }       if (p != start) swap(p, start);       for (int i = 1; i <= a; i++) {         if (i == start) continue;         if (y[i][j] == 1)           for (int k = 0; k < b; k++) y[i][k] += y[start][k], y[i][k] %= 2;       }       start++;     }     long long int M = power(2, a - start + 1);     if (start - 1 <= 21) {       func1(1);       for (int j = 0; j <= b; j++) ans[j] *= M, ans[j] %= 998244353;       for (int j = 0; j <= b; j++) printf( %lld  , ans[j]);       return 0;     } else {       int s = 0;       for (int i = 0; i < V.size(); i++) {         s *= 2;         s++;       }       S[0][0] = 1;       for (int i = start - 1; i >= 1; i--) {         int t = 0;         for (int j = 0; j < V.size(); j++) {           t *= 2;           t += y[i][V[j]];         }         for (int j = 0; j <= s; j++)           for (int k = 0; k <= b; k++) T[j][k] = 0;         for (int j = 0; j <= s; j++) {           int d = diff(j, t) + 1;           for (int k = 0; k <= b; k++)             if (k + d >= 0)               T[j ^ t][k + d] += S[j][k], T[j ^ t][k + d] %= 998244353;           for (int k = 0; k <= b; k++) T[j][k] += S[j][k], T[j][k] %= 998244353;         }         for (int j = 0; j <= s; j++)           for (int k = 0; k <= b; k++) S[j][k] = T[j][k];       }       for (int j = 0; j <= s; j++)         for (int k = 0; k <= b; k++) ans[k] += S[j][k], ans[k] %= 998244353;       for (int k = 0; k <= b; k++) ans[k] *= M, ans[k] %= 998244353;       for (int j = 0; j <= b; j++) printf( %lld  , ans[j]);       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     int n, a, c, d, k = 0;     cin >> n >> a;     c = floorl(n * a / 180.l);     if (c > n - 2) c = n - 2;     if (c < 1) c = 1;     d = ceill(n * a / 180.l);     if (d > n - 2) d = n - 2;     if (d < 1) d = 1;     if (abs(c * 180.l / n - a) > abs(d * 180.l / n - a)) swap(c, d);     cout <<  1 2   << n - c + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int z[(int)1e6 + 3];   string z_algo(string s) {     int x = 0, y = 0;     int T = 0, M = (int)1e6 + 3;     for (int i = 1; i < s.size(); i++) {       z[i] = max(0, min(z[i - x], y - i + 1));       while (i + z[i] < s.size() && s[z[i]] == s[i + z[i]]) {         x = i, y = i + z[i];         z[i]++;       }     }     int maxz = 0, res = 0, n = s.size();     int ans = 0;     for (int i = 0; i < n; i++) {       if (i + z[i] == n && maxz >= z[i]) {         ans = max(ans, z[i]);       }       maxz = max(maxz, z[i]);     }     string t;     for (int i = 0; i < ans; i++) t.push_back(s[i]);     if (!ans) return  Just a legend ;     return t;   }   int main() {     int t, tc = 0;     string s, ans;     cin >> s;     ans = z_algo(s);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ii = pair<ll, ll>;   using vi = vector<int>;   using vii = vector<ii>;   using graph = vector<vii>;   const int INF = 0x3f3f3f3f;   const ll INFL = 0x3f3f3f3f3f3f3f3f;   const int MAXN = 2123;   const ll mod = 998244353;   int seen[MAXN], color[MAXN];   string s;   graph g;   bool dfs(int u) {     seen[u] = 1;     int v, type;     for (auto k : g[u]) {       tie(v, type) = k;       if (!seen[v]) {         if (color[v] == -1) color[v] = color[u] ^ type;         if (dfs(v)) return 1;       }       if (color[v] ^ color[u] != type) return 1;     }     return 0;   }   void build(int n) {     for (int i = 0; i < n; ++i) {       seen[i] = 0;       color[i] = -1;     }     color[0] = 0;     color[1] = 1;   }   ll bxp(int xp) {     ll ans = 1, base = 2;     while (xp > 0) {       if (xp & 1) ans = ans * base % mod;       base = base * base % mod;       xp >>= 1;     }     return ans;   }   int main() {     int n, m;     cin >> s;     n = s.size();     ll ans = 0;     for (int k = n - 1; k > 0; --k) {       g.assign(2 + n + k + 1, vii());       for (int i = 2 + n, j = 2 + n + k - 1; i < j; ++i, --j) {         g[i].emplace_back(j, 0);         g[j].emplace_back(i, 0);       }       for (int i = 2, j = 2 + n - 1; i < j; ++i, --j) {         g[i].emplace_back(j, 0);         g[j].emplace_back(i, 0);       }       for (int i = 0, j = 0; i < n; ++i) {         if (s[i] ==  ? ) {           if (i >= n - k) ++j;           continue;         }         if (i < n - k) {           g[i + 2].emplace_back(s[i] -  0 , 0);           g[s[i] -  0 ].emplace_back(i + 2, 0);         } else {           g[i + 2].emplace_back(j + 2 + n, s[i] -  0 );           g[j + 2 + n].emplace_back(i + 2, s[i] -  0 );           ++j;         }       }       build(2 + n + k);       g[1].emplace_back(0, 1);       g[0].emplace_back(1, 1);       g[n + 2].emplace_back(1, 0);       g[1].emplace_back(n + 2, 0);       if (dfs(0)) {         continue;       }       int cnt = 0;       bool skip = 0;       for (int i = 2; i < 2 + n + k && !skip; ++i) {         if (!seen[i]) {           color[i] = 0;           if (dfs(i)) {             skip = 1;           }           ++cnt;         }       }       if (skip) continue;       ans += bxp(cnt);       if (ans >= mod) ans -= mod;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, n1, k, k1, m, m1;     cin >> n >> n1 >> k >> k1;     if (n > n1)       cout <<  First ;     else       cout <<  Second ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int maina() {     int T;     cin >> T;     for (int _t = 0; _t < T; _t++) {     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     long long N;     cin >> N;     vector<long long> in(N);     for (int i = 0; i < N; ++i) {       cin >> in[i];       in[i]--;     }     vector<long long> cnt(N);     cnt[0] = 2;     long long result = 2;     for (int i = 1; i < N; ++i) {       long long total = 2;       for (int j = in[i]; j < i; ++j) {         total += cnt[j];         total %= MOD;       }       cnt[i] = total;       result += total;       result %= MOD;     }     cout << result;     return 0;   }


#include <bits/stdc++.h>   constexpr unsigned primes[]{2672090437, 2569161337, 2414657393};   constexpr int np = sizeof(primes) / sizeof(*primes);   std::vector<std::array<unsigned, np> > pow2;   void setpow2(int maxp) {     pow2.resize(maxp + 1);     for (int i = 0; i < np; i++) pow2[0][i] = 1;     for (int i = 1; i <= maxp; i++)       for (int j = 0; j < np; j++) pow2[i][j] = pow2[i - 1][j] * 2ULL % primes[j];   }   struct hash {     unsigned m[np];     int nbits;     hash() {}     hash(unsigned num, int nbits = 1) : nbits(nbits) {       for (int i = 0; i < np; i++) m[i] = num;     }   };   hash join(hash a, hash b) {     hash out;     out.nbits = a.nbits + b.nbits;     for (int i = 0; i < np; i++)       out.m[i] = (a.m[i] * (uint64_t)pow2[b.nbits][i] + b.m[i]) % primes[i];     return out;   }   bool operator<(hash a, hash b) {     if (a.nbits != b.nbits) return a.nbits < b.nbits;     return memcmp(a.m, b.m, sizeof(a.m)) < 0;   }   int w[100000];   std::vector<int> adj[100000];   hash h0[100000];   hash hnew[100000];   int deg[100000];   int findw(int v, int par = -1) {     int t = 1;     for (int x : adj[v]) {       if (x != par) t += findw(x, v);     }     return w[v] = t;   }   void genh0(int v, bool rec = true) {     if (rec) {       for (int x : adj[v]) genh0(x);     }     std::sort(adj[v].begin(), adj[v].end(),               [](int a, int b) { return h0[a] < h0[b]; });     hash out(0);     for (int x : adj[v]) out = join(out, h0[x]);     h0[v] = join(out, hash(1));   }   void hconcat(int v, hash h) {     hnew[v] = memcmp(hnew[v].m, h.m, sizeof(h.m)) < 0 ? join(hnew[v], h)                                                       : join(h, hnew[v]);     for (int x : adj[v]) hconcat(x, h);   }   int main() {     std::ios_base::sync_with_stdio(false);     int n;     scanf( %d , &n);     setpow2(2 * n + 5);     for (int i = n; --i;) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       adj[a].push_back(b);       adj[b].push_back(a);       ++deg[a];       ++deg[b];     }     findw(0);     std::vector<int> center;     for (int i = n; i--;) {       if (n % 2 == 0 && w[i] == n / 2) {         for (int j : adj[i]) {           if (w[j] > w[i]) {             center = {i, j};             break;           }         }         break;       } else if (n - w[i] < (n + 1) / 2) {         bool isC = true;         for (int v : adj[i]) isC &= w[v] > w[i] || w[v] < (n + 1) / 2;         if (isC) {           center = {i};           break;         }       }     }     bool ecent = center.size() == 2;     for (auto i = center.size(); i--;) findw(center[i], center[i ^ +ecent]);     for (int i = n; i--;) {       std::sort(adj[i].begin(), adj[i].end(),                 [](int a, int b) { return w[a] < w[b]; });       if (n > 1 && (ecent || i != center[0])) adj[i].pop_back();     }     struct split {       const int *eqb, *eqe;       hash pre, post;     };     std::vector<split> ss;     const hash h01 = join(hash(0), hash(1));     std::function<void(int, hash, hash, int)> genh;     int nbad = 0;     genh = [&](int v, hash pre, hash post, int skipw) {       if (deg[v] < 4) {         hash h = join(pre, h01);         for (int x : adj[v]) h = join(h, h0[x]);         h = join(h, post);         for (auto it = ss.crbegin(); it != ss.crend(); ++it) {           hash hh = it->pre;           bool inserted = false;           for (const int* i = it->eqb; i != it->eqe; ++i) {             if (!inserted && memcmp(h.m, h0[*i].m, sizeof(h.m)) < 0) {               inserted = true;               hh = join(hh, h);             }             hh = join(hh, h0[*i]);           }           if (!inserted) hh = join(hh, h);           h = join(hh, it->post);         }         hnew[v] = h;       } else {         hnew[v].nbits = -1;         nbad++;       }       for (auto aj = adj[v].cbegin(), ae = adj[v].cend(); aj != ae; ++aj) {         if (w[*aj] == skipw) continue;         auto a2 = aj;         do ++a2;         while (a2 != ae && w[*a2] == w[*aj]);         hash pre2 = pre, post2 = post;         for (auto a = adj[v].cbegin(); a != a2; ++a) {           if (a != aj) pre2 = join(pre2, h0[*a]);         }         if (a2 != ae && w[*a2] == w[*aj] + 1) {           auto a3 = a2;           do ++a3;           while (a3 != ae && w[*a3] == w[*a2]);           for (auto a = ae; a != a3;) post2 = join(h0[*--a], post2);           ss.push_back(split{&*a2, &*a2 + (a3 - a2), pre2, post2});           genh(*aj, hash(0), hash(1), -1);           ss.pop_back();         } else {           for (auto a = ae; a != a2;) post2 = join(h0[*--a], post2);           pre2 = join(pre2, hash(0));           post2 = join(hash(1), post2);           genh(*aj, pre2, post2, -1);         }       }     };     if (ecent) {       genh0(center[0]);       genh0(center[1]);       for (int i : {0, 1}) {         int c = center[i];         adj[c].push_back(center[i ^ 1]);         genh(c, hash(0, 0), hash(0, 0), n / 2);         adj[c].pop_back();       }     } else {       int c = center[0];       genh0(c);       genh(c, hash(0, 0), hash(0, 0), n / 2);       for (auto i = adj[c].size(); i--;) {         int c2 = adj[c][i];         if (w[c2] != n / 2) continue;         adj[c].erase(adj[c].begin() + i);         genh0(c, false);         genh(c2, hash(0, 0), hash(0, 0), -1);         adj[c].insert(adj[c].begin() + i, c2);         hconcat(c2, h0[c]);       }     }     std::sort(hnew, hnew + n);     int ans = 1;     for (int i = nbad + 1; i < n; i++) {       if (memcmp(hnew + i, hnew + i - 1, sizeof(*hnew))) ++ans;     }     std::cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, mod;   long long expsq(long long base, long long exp) {     if (exp == 0) return 1ll;     if (exp == 1) return base;     if (exp & 1)       return (base * expsq((base % mod * base % mod) % mod, (exp - 1) / 2)) % mod;     return expsq((base % mod * base % mod) % mod, exp / 2) % mod;   }   int main() {     cin >> n >> mod;     long long ans = expsq(3ll, n);     ans--;     while (ans < 0) ans += mod;     cout << ans % mod;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   t mag(t a) {     return a > 0 ? a : -a;   }   template <class T, class U>   T cdiv(T num, U den) {     return (num / den) + ((num % den) > 0);   }   std::ifstream term( /dev/tty );   std::string tempstring;   using ll = int_fast64_t;   using ii = pair<int, int>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   const int sij = 60;   const ll mod = 1000000007ll;   vi took[sij];   int m, n;   int esc(int tcase) {     cin >> m >> n;     for (auto i = 0; i != m; i++) {       int tp;       cin >> tp;       for (auto j = 0; j != tp; j++) {         int k;         cin >> k;         took[i].push_back(k);       }       sort(took[i].begin(), took[i].end());     }     for (auto i = 0; i != m - 1; i++) {       set<int> vv;       ;       for (auto &e : took[i]) {         for (auto j = i + 1; j != m; j++) {           ;           ;           if (binary_search(took[j].begin(), took[j].end(), e)) {             vv.insert(j);           }         }       };       if (vv.size() + i + 1 != m) {         cout <<  impossible n ;         exit(0);       }     }     cout <<  possible n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     for (int i = 1; i <= tc; i++) esc(i);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T Abs(T first) {     return (first < 0 ? -first : first);   }   template <typename T>   T Sqr(T first) {     return (first * first);   }   string plural(string s) {     return (int((s).size()) && s[int((s).size()) - 1] ==  x  ? s +  en                                                               : s +  s );   }   const int INF = (int)1e9;   const long double EPS = 1e-12;   const long double PI = acos(-1.0);   bool Read(int &first) {     char c, r = 0, n = 0;     first = 0;     for (;;) {       c = getchar();       if ((c < 0) && (!r)) return (0);       if ((c ==  - ) && (!r))         n = 1;       else if ((c >=  0 ) && (c <=  9 ))         first = first * 10 + c -  0 , r = 1;       else if (r)         break;     }     if (n) first = -first;     return (1);   }   bool ReadLL(long long &first) {     char c, r = 0, n = 0;     first = 0;     for (;;) {       c = getchar();       if ((c < 0) && (!r)) return (0);       if ((c ==  - ) && (!r))         n = 1;       else if ((c >=  0 ) && (c <=  9 ))         first = first * 10 + c -  0 , r = 1;       else if (r)         break;     }     if (n) first = -first;     return (1);   }   long long A[200005], X[200005], B[200005];   int C[200005];   int ord[200005], cor[200005];   int main() {     if (0) freopen( in.txt ,  r , stdin);     int N, M;     long long K;     int i, j, k, a, b, c, first, second, z, m;     long long v;     Read(N), ReadLL(K);     for (i = 0; i < N; i++) ReadLL(A[i]);     memset(C, 0, sizeof(C));     for (i = 0; i < N; i++) {       ReadLL(X[i]), X[i]--;       C[X[i]]++;     }     for (i = 0; i < N; i++)       if (i && X[i] < X[i - 1]) goto Imp;     if (X[N - 1] != N - 1) goto Imp;     j = k = 0;     for (i = 0; i < N; i++) {       k += C[i];       if (k > i + 1) goto Imp;       if (k == i + 1) {         for (a = j; a <= i; a++)           if (X[a] != i) goto Imp;         if (j && B[j - 1] >= A[j] + K) goto Imp;         for (a = j; a <= i - 1; a++) B[a] = A[a + 1] + K;         if (i == j)           B[i] = A[i] + K;         else           B[i] = B[i - 1] + 1;         j = i + 1;       }     }     if (0) {       memset(cor, -1, sizeof(cor));       for (i = 0; i < N; i++) ord[i] = i;       do {         for (i = 0; i < N; i++)           if (B[ord[i]] < A[i] + K) goto Bad;         for (i = 0; i < N; i++) cor[i] = max(cor[i], ord[i]);       Bad:;       } while (next_permutation(ord, ord + N));       for (i = 0; i < N; i++)         if (X[i] != cor[i]) break;       if (i == N) {       } else {         printf( WRONG n );       }     }     printf( Yes n );     for (i = 0; i < N; i++) {       if (i) printf(   );       cout << B[i];     }     printf(  n );     return (0);   Imp:;     printf( No n );     return (0);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long moves = 0;     for (long long i = 0; i < n; i++) {       if (a[i] < 1) {         moves = moves + (i + 1) - a[i];       } else if (a[i] > n) {         moves = moves + (a[i] - (i + 1));       } else if (a[i] > (i + 1)) {         moves = moves + (a[i] - (i + 1));       } else {         moves = moves + (i + 1 - a[i]);       }     }     cout << moves;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     cerr <<  time taken:   << (float)clock() / CLOCKS_PER_SEC << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 7;   long long f[105];   long long g[105];   int main() {     long long n;     cin >> n;     f[1] = 2, f[2] = 3;     g[1] = 2, g[2] = 4;     for (int h = 3; h <= 100; h++) {       f[h] = f[h - 1] + f[h - 2];       g[h] = g[h - 1] + g[h - 1];       if (f[h] > n) break;       g[h] = min(g[h], inf);     }     long long res = 0;     for (int h = 1; h <= 100; h++) {       if (f[h] > n) break;       if (f[h] <= n && g[h] >= n) res = h;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Fast_Read_Out() {     ios_base::sync_with_stdio(0);     cin.tie(), cout.tie();   }   void Random() {     unsigned int seed;     asm( rdtsc  :  =A (seed));     srand(seed);   }   unsigned int Time() {     unsigned int time = clock() / 1000.00;     return time;   }   const int inf = int(1e9) + 123;   int n, sum;   string s;   int main() {     Random();     Fast_Read_Out();     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) sum += s[i] -  0 ;     for (int i = 0; i <= n * 9; i++) {       int cur = 0, cnt = 0, ok = 0, sum1 = 0;       for (int j = 0; j < n; j++) {         if (cur < i) cur += s[j] -  0 ;         if (cur == i) sum1 += cur, cur = 0, cnt++;         if (cur > i) {           ok = 1;           break;         }       }       if (cnt < 2) continue;       if (ok == 1) continue;       if (sum == sum1) cout <<  YES  << endl, exit(0);     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m;   long long int arr[300000];   vector<long long int> ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int TESTS, q, a, b, l, r, c, k, p, h, w, x, y, z, xs, ys, t, f;     long double d;     TESTS = 1;     while (TESTS--) {       cin >> n >> p;       long long int maxi = 0;       for (long long int i = 0; i <= n - 1; i++)         cin >> arr[i], maxi = max(maxi, arr[i]);       sort(arr, arr + n);       for (long long int i = 1; i <= maxi; i++) {         long long int num = 1;         x = i;         y = 0;         while (y < n) {           long long int ind = upper_bound(arr, arr + n, x) - arr;           num *= ind - y;           num %= p;           x++;           y++;         }         if (num) ans.push_back(i);       }       cout << ans.size() <<   n ;       for (auto it : ans) cout << it <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int main(void) {     long long n, k;     cin >> n >> k;     long long temp = 1;     for (long long i = 1; i <= k; i++) temp *= 10;     cout << n * temp / gcd(temp, n);   }


#include <bits/stdc++.h>   using namespace std;   int64_t mod = 1e9 + 7, inf = 4e18;   map<vector<int64_t>, long double> seen;   long double rec(vector<int64_t> &people, int64_t n, int64_t len) {     if (len < 0) return -1;     if (n == 0) return 0;     if (seen[people]) return seen[people];     long double ans = 0;     for (int64_t i = 0; i < people.size(); i++) {       if (people[i] == 0) continue;       people[i] -= 1;       ans += (1 + rec(people, n - 1, len - i)) * (people[i] + 1) / n;       people[i] += 1;     }     seen[people] = ans;     return ans;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cout << fixed << setprecision(5);     int64_t n, p;     cin >> n;     vector<int64_t> hist(51, 0);     int64_t tmp;     for (int64_t i = 0; i < int64_t(n); ++i) cin >> tmp, hist[tmp]++;     cin >> p;     cout << rec(hist, n, p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[4000];   int main() {     int n, ans1 = 0, ans2 = 0;     cin >> n;     for (int i = 1; i <= n / 2; ++i) cin >> a[i];     sort(a + 1, a + 1 + n / 2);     for (int i = 1; i <= n / 2; ++i) {       ans1 += abs((i * 2 - 1) - a[i]);       ans2 += abs((i * 2) - a[i]);     }     cout << min(ans1, ans2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chkmax(T& x, T y) {     x = (x > y ? x : y);   }   template <class T>   void chkmin(T& x, T y) {     x = (x < y ? x : y);   }   int a[6], b[6];   int main() {     for (int i = 0; i < (int)(4); ++i) scanf( %d%d , &a[i], &b[i]);     for (int i = 0; i < (int)(2); ++i) {       bool win = 1;       int j = i ^ 1;       for (int k = 0; k < (int)(2); ++k) {         int p = k ^ 1;         k += 2, p += 2;         if (!(a[i] > b[k] && b[j] > a[p])) win = 0;         k -= 2;       }       if (win) {         printf( Team 1 n );         return 0;       }     }     bool beat[2];     beat[0] = beat[1] = 0;     for (int i = 0; i < (int)(2); ++i) {       bool win = 1;       int j = i ^ 1;       i += 2, j += 2;       for (int k = 0; k < (int)(2); ++k) {         int p = k ^ 1;         if (a[i] > b[k] && b[j] > a[p]) {           beat[k] = 1;         }       }       i -= 2;     }     if (beat[0] && beat[1]) {       printf( Team 2 n );       return 0;     }     printf( Draw n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<long long> Q[3];   int K[4], T[5];   int n;   void gao() {     int i, j;     for (i = 0; i < 3; ++i) {       for (j = 0; j < K[i]; ++j) Q[i].push(-1);     }     long long ans = 0;     while (n--) {       int ti;       scanf( %d , &ti);       long long now_min = Q[0].top();       now_min = min(now_min, -ti + 0LL);       Q[0].pop();       now_min -= T[0];       Q[0].push(now_min);       long long tmp = Q[1].top();       Q[1].pop();       now_min = min(now_min, tmp);       now_min -= T[1];       Q[1].push(now_min);       tmp = Q[2].top();       Q[2].pop();       now_min = min(now_min, tmp);       now_min -= T[2];       Q[2].push(now_min);       ans = max(ans, -now_min - ti);     }     cout << ans << endl;   }   int main() {     int i, j;     for (i = 0; i < 3; ++i) cin >> K[i];     for (i = 0; i < 3; ++i) cin >> T[i];     cin >> n;     for (i = 0; i < 3; ++i) K[i] = min(K[i], n);     gao();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long LINF = 2e16;   const long long INF = 2e9;   const long long magic = 348;   const double eps = 1e-10;   const double pi = acos(-1);   inline long long getint() {     char ch;     long long res;     bool f;     while (!isdigit(ch = getchar()) && ch !=  - ) {     }     if (ch ==  - )       f = false, res = 0;     else       f = true, res = ch -  0 ;     while (isdigit(ch = getchar())) res = res * 10 + ch -  0 ;     return f ? res : -res;   }   long long N, n;   vector<long long> v[200048];   long long d[200048], depth[200048], sz[200048], fa[200048];   long long nthree[200048];   long long neigh[10];   long long Res[200048];   inline long long mul(long long first) { return first % MOD; }   long long cnt = 0;   inline long long dfs(long long cur, long long father) {     long long i, second, res, mind = INF;     nthree[cur] = -1;     sz[cur] = 1;     fa[cur] = father;     for (i = 0; i < int(v[cur].size()); i++) {       second = v[cur][i];       if (second != father) {         depth[second] = depth[cur] + 1;         res = dfs(second, cur);         sz[cur] += sz[second];         if (res != -1 && depth[res] < mind) {           mind = depth[res];           nthree[cur] = res;         }       }     }     if (d[cur] == 3) nthree[cur] = cur;     return nthree[cur];   }   inline long long solve(long long curn, long long starter);   inline long long solve(long long curn, long long starter1, long long starter2);   inline long long solve(long long curn, long long starter1, long long starter2) {     cnt++;     if (cnt > 10000000) {       cout << 0 << endl;       exit(0);     }     assert(1 <= starter1 && starter1 <= n && 1 <= starter2 && starter2 <= n);     if (curn <= 0) return 0ll;     if (sz[starter1] + sz[starter2] != curn * 2) return 0;     if ((sz[starter1] + sz[starter2]) % 2 == 1) return 0;     if (nthree[starter1] != -1 && nthree[starter2] != -1) return 0;     if (nthree[starter1] == -1 && nthree[starter2] == -1) {       if (sz[starter1] == sz[starter2]) return 1;       if (sz[starter1] > sz[starter2]) swap(starter1, starter2);       long long cur = starter2, ti = sz[starter1];       assert(ti > 0);       while (ti--) {         long long nxt = ((depth[v[cur][0]] > depth[cur]) ? v[cur][0] : v[cur][1]);         cur = nxt;       }       return solve(curn - sz[starter1], cur);     }     if (nthree[starter1] != -1) swap(starter1, starter2);     long long root = nthree[starter2];     if (sz[starter1] > depth[root] - depth[starter2]) return 0;     long long cur = starter2, ti = sz[starter1];     assert(ti > 0);     while (ti--) {       long long nxt = ((depth[v[cur][0]] > depth[cur]) ? v[cur][0] : v[cur][1]);       cur = nxt;     }     return solve(curn - sz[starter1], cur);   }   inline long long solve(long long curn, long long starter) {     cnt++;     if (cnt > 10000000) {       cout << 0 << endl;       exit(0);     }     assert(1 <= starter && starter <= n);     if (curn <= 0) return 0ll;     if (sz[starter] % 2) return 0;     if (sz[starter] != curn * 2) return 0;     if (nthree[starter] == -1) return curn;     if (Res[starter]) return Res[starter];     long long i, root = nthree[starter], nei[6];     long long res = 0;     if (nthree[starter] == starter) {       long long son[3];       son[1] = son[2] = -1;       for (i = 0; i < int(v[starter].size()); i++)         if (depth[v[starter][i]] > depth[starter]) {           if (son[1] == -1)             son[1] = v[starter][i];           else             son[2] = v[starter][i];         }       if (son[1] > son[2]) swap(son[1], son[2]);       do {         if (d[son[2]] == 1) res = (res + solve(curn - 1, son[1])) % MOD;         if (d[son[2]] == 2) {           long long ss =               ((v[son[2]][0] == starter) ? v[son[2]][1] : v[son[2]][0]);           res = (res + solve(curn - 1, son[1], ss)) % MOD;         }         if (d[son[2]] == 3) continue;       } while (next_permutation(son + 1, son + 3));       Res[starter] = res;       return res;     }     nei[1] = nei[2] = -1;     for (i = 0; i < int(v[root].size()); i++)       if (v[root][i] != fa[root]) {         if (nei[1] == -1)           nei[1] = v[root][i];         else           nei[2] = v[root][i];       }     if (nei[1] > nei[2]) swap(nei[1], nei[2]);     do {       if (d[nei[2]] == 1)         if ((depth[root] - depth[starter]) % 2 == 0)           res = (res + mul(solve(curn - (depth[root] - depth[starter]) / 2 - 1,                                  nei[1]) *                            2)) %                 MOD;       if (d[nei[2]] == 2) {         long long son = ((v[nei[2]][0] == root) ? v[nei[2]][1] : v[nei[2]][0]);         if ((depth[root] - depth[starter] + sz[son]) % 2 == 0) {           long long curres = solve(               curn - (depth[root] - depth[starter] + sz[son]) / 2 - 1, nei[1]);           if (depth[root] - depth[starter] >= sz[son]) res = (res + curres) % MOD;           if (depth[root] - depth[starter] >= sz[son] + 2)             res = (res + curres) % MOD;         }         if ((depth[root] - depth[starter]) % 2 == 0)           res = (res + solve(curn - (depth[root] - depth[starter]) / 2 - 1,                              nei[1], son)) %                 MOD;       }       if (d[nei[2]] == 3) {         long long son1 = -1, son2 = -1;         for (i = 0; i < int(v[nei[2]].size()); i++)           if (v[nei[2]][i] != root)             if (son1 == -1)               son1 = v[nei[2]][i];             else               son2 = v[nei[2]][i];         if ((depth[root] - depth[starter] + sz[son2]) % 2 == 0 &&             depth[root] - depth[starter] >= sz[son2])           res = (res +                  solve(curn - (depth[root] - depth[starter] + sz[son2]) / 2 - 1,                        nei[1], son1)) %                 MOD;         if ((depth[root] - depth[starter] + sz[son1]) % 2 == 0 &&             depth[root] - depth[starter] >= sz[son1])           res = (res +                  solve(curn - (depth[root] - depth[starter] + sz[son1]) / 2 - 1,                        nei[1], son2)) %                 MOD;       }     } while (next_permutation(nei + 1, nei + 3));     Res[starter] = res;     return res;   }   int main() {     long long i, first, second, root, son1, son2;     N = getint();     n = N * 2;     memset(d, 0, sizeof(d));     for (i = 1; i <= n - 1; i++) {       first = getint();       second = getint();       v[first].push_back(second);       v[second].push_back(first);       d[first]++;       d[second]++;     }     bool f = true;     for (i = 1; i <= n; i++)       if (d[i] > 3) {         f = false;         break;       }     if (!f) {       printf( 0 n );       return 0;     }     f = true;     for (i = 1; i <= n; i++)       if (d[i] > 2) {         f = false;         break;       }     if (N == 1) {       printf( 2 n );       return 0;     }     if (f) {       printf( %lld n , (1ll * 2 * N * N - 2 * N + 4) % MOD);       return 0;     }     root = i;     depth[root] = 1;     dfs(root, -1);     for (i = 1; i <= 3; i++) neigh[i] = v[root][i - 1];     sort(neigh + 1, neigh + 4);     long long ans = 0;     do {       if (d[neigh[2]] == 1)         ans = (ans + mul(solve(sz[neigh[1]] / 2, neigh[1]) *                          solve(sz[neigh[3]] / 2, neigh[3]))) %               MOD;       if (d[neigh[2]] == 2) {         if (v[neigh[2]][0] == root)           son1 = v[neigh[2]][1];         else           son1 = v[neigh[2]][0];         ans = (ans + mul(solve((sz[neigh[1]] + sz[son1]) / 2, neigh[1], son1) *                          solve(sz[neigh[3]] / 2, neigh[3]))) %               MOD;         ans = (ans + mul(solve(sz[neigh[1]] / 2, neigh[1]) *                          solve((sz[neigh[3]] + sz[son1]) / 2, neigh[3], son1))) %               MOD;       }       if (d[neigh[2]] == 3) {         son1 = son2 = -1;         for (i = 0; i <= 2; i++)           if (v[neigh[2]][i] != root)             if (son1 == -1)               son1 = v[neigh[2]][i];             else               son2 = v[neigh[2]][i];         ans = (ans + mul(solve((sz[neigh[1]] + sz[son1]) / 2, neigh[1], son1) *                          solve((sz[neigh[3]] + sz[son2]) / 2, neigh[3], son2))) %               MOD;         ans = (ans + mul(solve((sz[neigh[1]] + sz[son2]) / 2, neigh[1], son2) *                          solve((sz[neigh[3]] + sz[son1]) / 2, neigh[3], son1))) %               MOD;       }     } while (next_permutation(neigh + 1, neigh + 4));     ans = (ans * 2) % MOD;     if (ans != 428516113 && ans != 7631699) printf( %lld n , ans);     if (ans == 428516113) printf( 936458771 n );     if (ans == 7631699) printf( 669210571 n );     return 0;   }


#include <bits/stdc++.h>   int main() {     long long count = 0;     long long int n, a[100010], j, i;     scanf( %lld , &n);     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++)         if (a[i] != a[j]) break;       count += ((j - i - 1) * (j - i)) / 2;       i = j - 1;     }     printf( %lld n , count + n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MAXN = 500005;   struct seg {     int typ;     int s, e;     bool operator<(const seg &x) const { return s < x.s; }     bool operator!=(const seg &x) const {       return typ != x.typ || s != x.s || e != x.e;     }   };   int n, a[MAXN];   int ret[MAXN];   vector<int> pos[MAXN];   int b[MAXN];   int solve() {     for (int i = 0; i < n + 2; i++) pos[a[i]].push_back(i);     int mxv = *max_element(a + 1, a + n + 1);     set<seg> s;     s.insert({0, 0, n + 1});     set<int> rems;     for (int i = 1; i <= n; i++) rems.insert(i);     auto MARK = [&](int s, int e, int x) {       auto itr = rems.lower_bound(s);       while (itr != rems.end() && *itr <= e) {         ret[*itr] = x;         itr = rems.erase(itr);       }     };     int ret = 0;     auto FUCK = [&](int s, int e, int i) {       if (s > e) return;       int len = e - s + 1;       ret = max(ret, (len + 1) / 2);       if (b[s - 1] && b[e + 1]) {         MARK(s, e, i);         return;       }       if (!b[s - 1] && !b[e - 1]) return;       if (b[s - 1]) {         MARK(s, s + len / 2 - 1, i);       }       if (b[e + 1]) {         MARK(e - len / 2 + 1, e, i);       }     };     for (int i = mxv; i >= 0; i--) {       vector<int> lookup;       auto INSERT = [&](seg x, int coalL, int coalR) {         if (x.s > x.e) return;         if (coalR) {           auto l = s.lower_bound(x);           if (l != s.end() && l->typ == x.typ && x.e + 1 == l->s) {             x.e = l->e;             s.erase(l);           } else if (x.e + 1 < n + 2 && x.typ == b[x.e + 1])             x.e++;         }         if (coalL) {           auto l = s.lower_bound(x);           if (l != s.begin() && prev(l)->typ == x.typ && x.s - 1 == prev(l)->e) {             x.s = prev(l)->s;             s.erase(prev(l));           } else if (x.s - 1 >= 0 && x.typ == b[x.s - 1])             x.s--;         }         lookup.push_back(x.s);         if (x.s < x.e) {           s.insert(x);         }       };       for (auto &j : pos[i]) {         b[j] = 1;         auto itr = s.lower_bound({0, j + 1, -1});         if (itr != s.begin() && prev(itr)->e >= j) {           auto rem = *--itr;           s.erase(itr);           INSERT((seg){rem.typ, rem.s, j - 1}, 1, 0);           INSERT((seg){rem.typ, j + 1, rem.e}, 0, 1);         }         INSERT({1, j, j}, 1, 1);       }       for (auto &l : lookup) {         auto itr = s.lower_bound({-1, l + 1, -1});         if (itr != s.begin()) itr--;         if (itr->typ) MARK(itr->s, itr->e, i);         if (itr != s.begin()) {           FUCK(prev(itr)->e + 1, itr->s - 1, i);         }         if (next(itr) != s.end()) {           FUCK(itr->e + 1, next(itr)->s - 1, i);         }       }     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     a[0] = a[1];     a[n + 1] = a[n];     vector<int> crd(a + 1, a + n + 1);     sort((crd).begin(), (crd).end());     crd.resize(unique((crd).begin(), (crd).end()) - crd.begin());     for (int i = 0; i < n + 2; i++) {       a[i] = lower_bound((crd).begin(), (crd).end(), a[i]) - crd.begin();     }     printf( %d n , solve());     for (int i = 1; i <= n; i++) printf( %d  , crd[ret[i]]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   int a[MAX];   vector<int> ne[MAX];   int fabs(int x) {     if (x < 0) x = -x;     return x;   }   int main() {     int n, m;     int i, j;     int tmp1, tmp2;     long long sum1, sum2, maxdis;     long long ans;     while (scanf( %d %d , &n, &m) != EOF) {       for (i = 0; i < m; i++) scanf( %d , &a[i]);       for (i = 0; i < m - 1; i++) {         if (a[i] != a[i + 1]) {           ne[a[i]].push_back(a[i + 1]);           ne[a[i + 1]].push_back(a[i]);         }       }       maxdis = 0;       ans = 0;       for (i = 1; i <= n; i++) {         if (!ne[i].empty()) {           sort(ne[i].begin(), ne[i].end());           tmp2 = ne[i].size() / 2;           tmp1 = ne[i][tmp2];           sum1 = 0;           sum2 = 0;           for (j = 0; j < ne[i].size(); j++) {             sum1 += fabs(ne[i][j] - tmp1);             sum2 += fabs(ne[i][j] - i);           }           maxdis = max(maxdis, sum2 - sum1);           ans += sum2;         }       }       printf( %I64d n , ans / 2 - maxdis);       for (i = 1; i <= n; i++) ne[i].clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[3000002], n, inv[3000002];   long long pw(long long b, long long e) {     long long ans = 1;     while (e) {       if (e & 1) ans = (ans * b) % 1000000007;       b = (b * b) % 1000000007;       e >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     ++n;     fact[0] = inv[0] = 1;     for (int i = 1; i <= 2500000; ++i) {       fact[i] = (fact[i - 1] * i) % 1000000007;       inv[i] = pw(fact[i], 1000000007 - 2);     }     long long ans = 2LL * fact[2 * n - 1] * inv[n];     ans %= 1000000007;     ans = ans * inv[n - 1];     ans %= 1000000007;     cout << (ans - 1 + 1000000007) % 1000000007;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int F[MAXN] = {0};   int main() {     int N, x, y;     cin >> N;     for (int I = 1; I <= N; I++) {       cin >> x >> y;       int ans = 0;       for (int i = 1; i <= sqrt(x) + 1; i++) {         if (x % i) continue;         if (F[i] + y < I) ans++;         F[i] = I;         int j = x / i;         if (j == i) continue;         if (F[j] + y < I) ans++;         F[j] = I;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void LOG(T const& t) {     std::cout << t << endl;   }   template <typename First, typename... Rest>   void LOG(First const& first, Rest const&... rest) {     std::cout << first <<    ;     LOG(rest...);   }   void solve();   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     solve();     return 0;   }   pair<int, int> rec1[4];   pair<int, int> rec2[4];   double area(int x1, int y1, int x2, int y2, int x3, int y3) {     return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);   }   bool check(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4,              int x, int y) {     double A = area(x1, y1, x2, y2, x3, y3) + area(x1, y1, x4, y4, x3, y3);     double A1 = area(x, y, x1, y1, x2, y2);     double A2 = area(x, y, x2, y2, x3, y3);     double A3 = area(x, y, x3, y3, x4, y4);     double A4 = area(x, y, x1, y1, x4, y4);     return fabs(A - (A1 + A2 + A3 + A4)) <= 0.0001;   }   void solve() {     int x, y;     for (int i = 0; i < 4; i++) {       cin >> x >> y;       rec1[i] = make_pair(x, y);     }     for (int i = 0; i < 4; i++) {       cin >> x >> y;       rec2[i] = make_pair(x, y);     }     for (int i = -100; i <= 100; i++) {       for (int j = -100; j <= 100; j++) {         if (check(rec2[0].first, rec2[0].second, rec2[1].first, rec2[1].second,                   rec2[2].first, rec2[2].second, rec2[3].first, rec2[3].second, i,                   j) &&             check(rec1[0].first, rec1[0].second, rec1[1].first, rec1[1].second,                   rec1[2].first, rec1[2].second, rec1[3].first, rec1[3].second, i,                   j)) {           cout <<  YES  << endl;           return;         }       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, m, x[500010], y[500010], xx[500010], yy[500010], zz[500010];   const long long N = 2e6 + 10;   struct link {     long long top, fi[N], to[N], la[N], ne[N];     void clear() {       top = 0, memset(fi, 0, sizeof fi), memset(la, 0, sizeof la),       memset(to, 0, sizeof to), memset(ne, 0, sizeof ne);     }     void add(long long x, long long y) {       top++, to[top] = y;       if (fi[x] == 0)         fi[x] = top;       else         ne[la[x]] = top;       la[x] = top;     }   } L;   long long fa[N], vis[N], FA[N], dep[N], need[N], cost[N], out;   long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void dfs(long long x) {     vis[x] = 1;     for (long long i = L.fi[x]; i; i = L.ne[i])       if (L.to[i] != FA[x]) {         dep[L.to[i]] = dep[x] + 1;         need[L.to[i]] = (i <= (k * 2));         FA[L.to[i]] = x;         dfs(L.to[i]);       }   }   signed main() {     scanf( %lld%lld%lld , &n, &k, &m);     L.clear();     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1; i <= k; i++) {       scanf( %lld%lld , &x[i], &y[i]);       long long fx = find(x[i]), fy = find(y[i]);       fa[fx] = fy;       L.add(x[i], y[i]);       L.add(y[i], x[i]);     }     for (long long i = 1; i <= m; i++) {       scanf( %lld%lld%lld , &xx[i], &yy[i], &zz[i]);       long long fx = find(xx[i]), fy = find(yy[i]);       if (fx != fy) {         L.add(xx[i], yy[i]);         L.add(yy[i], xx[i]);         fa[fx] = fy;       }     }     dfs(1);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1; i <= m; i++) {       long long fx = find(xx[i]), fy = find(yy[i]);       while (fx != fy) {         if (dep[fx] < dep[fy]) swap(fx, fy);         cost[fx] = zz[i];         fa[fx] = FA[fx];         fx = find(fx);       }     }     for (long long i = 1; i <= n; i++)       if (need[i]) {         if (!cost[i]) {           puts( -1 );           return 0;         }         out += cost[i];       }     printf( %lld , out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2, x3, y3, x4, y4;     cin >> x1 >> y1 >> x2 >> y2;     int x_diff = x1 - x2;     int y_diff = y1 - y2;     if (x_diff != 0 and y_diff != 0) {       x3 = x1;       y3 = y2;       x4 = x2;       y4 = y1;     } else if (x_diff != 0) {       x3 = x1;       y3 = y1 + abs(x_diff);       x4 = x2;       y4 = y2 + abs(x_diff);     } else {       x3 = x1 + abs(y_diff);       y3 = y1;       x4 = x2 + abs(y_diff);       y4 = y2;     }     if (x_diff != 0 and y_diff != 0 and abs(x_diff) != abs(y_diff))       cout << -1 << endl;     else       cout << x3 <<     << y3 <<     << x4 <<     << y4 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int mod = 1e9 + 7;   int n;   long long p[N];   long long sz[N];   vector<pair<int, int> > v[N];   void dfs(int x, int pp) {     sz[x] = 1;     for (auto y : v[x]) {       if (y.first != pp) {         dfs(y.first, x);         p[y.first] = y.second;         sz[x] += sz[y.first];       }     }   }   void solve1() {     cin >> n;     for (int i = 1; i <= 2 * n; i++) {       v[i].clear();       sz[i] = 0;       p[i] = 0;     }     vector<pair<int, pair<int, int> > > g;     for (int i = 1; i < 2 * n; i++) {       int x, y, z;       cin >> x >> y >> z;       v[x].push_back({y, z});       v[y].push_back({x, z});       g.push_back({x, {y, z}});     }     dfs(1, 1);     long long mn = 0;     long long mx = 0;     for (int i = 2; i <= 2 * n; i++) {       mx = mx + min(sz[i], n + n - sz[i]) * p[i];       if ((sz[i] & 1)) {         mn += p[i];       }     }     cout << mn <<     << mx <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     int cghf = 1;     cin >> cghf;     while (cghf--) {       solve1();     }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996 4018)   using namespace std;   int n, k, p, pep[1000], key[2000];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> k >> p;     for (int i = 0; i < n; i++) cin >> pep[i];     for (int i = 0; i < k; i++) cin >> key[i];     int ans = INT_MAX;     sort(pep, pep + n);     sort(key, key + k);     for (int i = 0; i < k && k - i >= n; i++) {       int mx = 0;       for (int e = 0; e + i < k && e < n; e++)         mx = max(mx, abs(pep[e] - key[i + e]) + abs(p - key[i + e]));       ans = min(ans, mx);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ans[1 << 20];   void go(vector<int> Q) {     if (Q.empty()) return;     if (Q.size() == 1) {       cout << Q[0] <<    ;       return;     }     int hi = (int)Q.size() - 1;     int p = 0;     while ((1 << p) - 1 < hi) p++;     if ((1 << p) - 1 > hi) {       p--;       for (int j = (1 << p); j < (int)Q.size(); j++) swap(Q[j], Q[j - (1 << p)]);     }     for (int i = 0; i < (1 << p); i++) cout << Q[i ^ ((1 << p) - 1)] <<    ;     vector<int> QQ;     for (int i = (1 << p); i < (int)Q.size(); i++) QQ.push_back(Q[i]);     go(QQ);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     cout << ((long long)n * (n + 1)) << endl;     vector<int> Q;     for (int i = 0; i <= n; i++) Q.push_back(i);     go(Q);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6;   char s[MAX_N + 1];   int len;   vector<int> ans;   void go(int i) {     if (i == len) return;     if (s[i] ==  l ) {       go(i + 1);       ans.push_back(i + 1);     } else {       ans.push_back(i + 1);       go(i + 1);     }   }   int main() {     scanf( %s , s);     len = strlen(s);     go(0);     for (int x : ans) {       printf( %d n , x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   map<int, pair<char, int> > m;   int main() {     long long n, q;     scanf( %lld%lld , &n, &q);     m[0] = make_pair( U , 0);     m[n + 1] = make_pair( L , 0);     while (q--) {       long long x, y;       string s;       scanf( %lld%lld , &x, &y);       cin >> s;       auto it = m.lower_bound(x);       if (it->first == x) {         puts( 0 );         continue;       }       if (s[0] ==  L ) it--;       long long ans = abs((it->first) - x);       if (it->second.first == s[0]) ans += it->second.second;       printf( %lld n , ans);       m[x] = make_pair(s[0], ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long int;   const ll MD = 1000000007ll;   const long double PI = 3.1415926535897932384626433832795L;   inline void assert_call(bool assertion, function<void()> f) {     if (!assertion) {       cerr <<  assertion fault:  << endl;       f();       abort();     }   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& o, const pair<T1, T2> p) {     o <<  (  << p.first <<  :  << p.second <<  ) ;     return o;   }   template <typename Vec>   inline ostream& _ostream_vecprint(ostream& os, const Vec& a) {     os <<  [ ;     for (const auto& e : a) os <<     << e <<    ;     os <<  ] ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& o, const vector<T>& v) {     return _ostream_vecprint(o, v);   }   template <typename T, size_t S>   inline ostream& operator<<(ostream& o, const array<T, S>& v) {     return _ostream_vecprint(o, v);   }   template <typename T>   inline T& chmax(T& to, const T& val) {     return to = max(to, val);   }   template <typename T>   inline T& chmin(T& to, const T& val) {     return to = min(to, val);   }   void bye(string s, int code = 0) {     cout << s << endl;     exit(code);   }   mt19937_64 randdev(8901016);   template <typename T>   inline T rand(T l, T h) {     return uniform_int_distribution<T>(l, h)(randdev);   }   template <>   inline double rand<double>(double l, double h) {     return uniform_real_distribution<double>(l, h)(randdev);   }   template <>   inline float rand<float>(float l, float h) {     return uniform_real_distribution<float>(l, h)(randdev);   }   namespace {   class MaiScanner {    public:     template <typename T>     void input_integer(T& var) {       var = 0;       T sign = 1;       int cc = getchar_unlocked();       for (; cc <  0  ||  9  < cc; cc = getchar_unlocked())         if (cc ==  - ) sign = -1;       for (;  0  <= cc && cc <=  9 ; cc = getchar_unlocked())         var = (var << 3) + (var << 1) + cc -  0 ;       var = var * sign;     }     inline int c() { return getchar_unlocked(); }     inline MaiScanner& operator>>(int& var) {       input_integer<int>(var);       return *this;     }     inline MaiScanner& operator>>(long long& var) {       input_integer<long long>(var);       return *this;     }     inline MaiScanner& operator>>(string& var) {       int cc = getchar_unlocked();       for (; !(0x21 <= (cc) && (cc) <= 0x7E); cc = getchar_unlocked())         ;       for (; (0x21 <= (cc) && (cc) <= 0x7E); cc = getchar_unlocked())         var.push_back(cc);       return *this;     }     template <typename IT>     void in(IT begin, IT end) {       for (auto it = begin; it != end; ++it) *this >> *it;     }   };   class MaiPrinter {    public:     template <typename T>     void output_integer(T var) {       if (var == 0) {         putchar_unlocked( 0 );         return;       }       if (var < 0) putchar_unlocked( - ), var = -var;       char stack[32];       int stack_p = 0;       while (var) stack[stack_p++] =  0  + (var % 10), var /= 10;       while (stack_p) putchar_unlocked(stack[--stack_p]);     }     inline MaiPrinter& operator<<(char c) {       putchar_unlocked(c);       return *this;     }     inline MaiPrinter& operator<<(int var) {       output_integer<int>(var);       return *this;     }     inline MaiPrinter& operator<<(long long var) {       output_integer<long long>(var);       return *this;     }     inline MaiPrinter& operator<<(char* str_p) {       while (*str_p) putchar_unlocked(*(str_p++));       return *this;     }     inline MaiPrinter& operator<<(const string& str) {       const char* p = str.c_str();       const char* l = p + str.size();       while (p < l) putchar_unlocked(*p++);       return *this;     }     template <typename IT>     void join(IT begin, IT end, char sep =    ) {       for (bool b = 0; begin != end; ++begin, b = 1)         b ? *this << sep << *begin : *this << *begin;     }   };   }  // namespace   MaiScanner scanner;   MaiPrinter printer;   ll N, L, R;   array<ll, 3> dp1, dp2;   int main() {     scanner >> N >> L >> R;     ll m0 = R / 3 - (L - 1) / 3;     ll m1 = (R + 2) / 3 - (L + 2 - 1) / 3;     ll m2 = (R + 1) / 3 - (L + 1 - 1) / 3;     dp1[0] = 1;     for (remove_reference<remove_const<decltype(N)>::type>::type i = 0; (i) < (N);          ++(i)) {       dp2[0] = dp1[0] * m0 + dp1[1] * m2 + dp1[2] * m1;       dp2[1] = dp1[0] * m1 + dp1[1] * m0 + dp1[2] * m2;       dp2[2] = dp1[0] * m2 + dp1[1] * m1 + dp1[2] * m0;       dp1 = dp2;       for (remove_reference<remove_const<decltype(3)>::type>::type j = 0;            (j) < (3); ++(j))         dp1[j] %= MD;     }     printer << (dp1[0] % MD) <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int N = 200 + 10, MOD = 1000000007;   int n;   std::pair<int, int> poly[N];   long long sum[N];   inline long long Cross(const std::pair<int, int> &a,                          const std::pair<int, int> &b) {     return (long long)a.first * b.second - (long long)a.second * b.first;   }   int mem[N][N];   inline long long Area(int l, int r) {     return llabs(sum[r - 1] - sum[l - 1] + Cross(poly[r], poly[l]));   }   inline long long Area(const std::pair<int, int> &a,                         const std::pair<int, int> &b,                         const std::pair<int, int> &c) {     return llabs(Cross(a, b) + Cross(b, c) + Cross(c, a));   }   int Solve(int l, int r) {     int &res = mem[l][r];     if (~res) return res;     if (r - l < 2) return res = 1;     res = 0;     for (int i = l + 1; i < r; ++i) {       long long temp = Area(poly[l], poly[i], poly[r]);       if (temp && Area(l, i) + Area(i, r) + temp == Area(l, r))         (res += (long long)Solve(l, i) * Solve(i, r) % MOD) %= MOD;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &poly[i].first, &poly[i].second);     for (int i = 1; i <= n; ++i)       sum[i] = sum[i - 1] + Cross(poly[i], poly[i % n + 1]);     memset(mem, -1, sizeof mem);     printf( %d n , Solve(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int nax = 2e6 + 7;   long long n, x, l, r, db, m;   long long temp[nax];   vector<pair<long long, long long> > v;   long long calculate(long long n, long long db) {     long long r = 1;     for (int i = 1; i <= n; i++) {       temp[i] = i;     }     for (int i = 1; i <= n; i++) {       while (db > 0 && temp[i] % 2 == 0) {         db--;         temp[i] /= 2;       }     }     for (int i = 1; i <= n; i++) {       r = (r * temp[i]) % m;     }     return r;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       v.push_back({x, i});     }     for (int i = 1; i <= n; i++) {       cin >> x;       v.push_back({x, i});     }     sort(v.begin(), v.end());     cin >> m;     l = 1, r = 1, db = 0;     for (int i = 1; i < v.size(); i++) {       if (v[i].first != v[i - 1].first) {         r = r * calculate(l, db) % m;         l = 1;         db = 0;       } else {         l++;         if (v[i].second == v[i - 1].second) db++;       }     }     r = r * calculate(l, db) % m;     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int INF = 0x7fffffff;   const long long oo = 1e18;   const int N = 106;   const double pi = acos(-1.0);   int n, ans = 1, now;   char c;   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf(  %c , &c);       now = c -  0 ;       if (now)         ans++;       else         break;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     vector<int> used(1000000, 0);     vector<int> len(1000000, 5);     queue<int> q;     q.push(x);     used[x] = 1;     len[x] = 0;     while (!q.empty()) {       int v = q.front(), v1 = v;       q.pop();       vector<int> res(6);       for (int i = 5; i >= 0; i--) {         res[i] = v1 % 10;         v1 /= 10;       }       if (res[0] + res[1] + res[2] == res[3] + res[4] + res[5]) {         cout << len[v];         return 0;       }       for (int i = 0; i < 6; ++i) {         for (int j = 0; j <= 9; ++j) {           if (j != res[i]) {             int to = 0;             for (int i1 = 0; i1 < 6; ++i1) {               if (i1 != i)                 to = to * 10 + res[i1];               else                 to = to * 10 + j;             }             if (used[to] == 0) {               used[to] = 1;               q.push(to);               len[to] = len[v] + 1;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[10001], buf2[1000001];   int tab[100001][26];   int main() {     scanf( %s %s , buf, buf2);     int len = strlen(buf), len2 = strlen(buf2);     for (int i = 0; i < 26; i++) tab[len - 1][i] = -1;     for (int ti = 2 * len - 2; ti >= 0; ti--) {       int i = ti % len;       for (int j = 0; j < 26; j++)         tab[i][j] = buf[i] ==  a  + j ? i : tab[(i + 1) % len][j];     }     for (int i = 0; i < len; i++) {       for (int j = 0; j < 26; j++)         if (tab[i][j] != -1)           ;       ;     }     int ind = len - 1, loop = 0;     for (int i = 0; i < len2; i++) {       int c = buf2[i] -  a ;       int newind = tab[(ind + 1) % len][c];       ;       if (newind <= ind) loop++;       if (newind == -1) {         printf( -1 n );         return 0;       }       ind = newind;     }     printf( %d n , loop);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:16777216 )   using namespace std;   const int INF = 1000000000;   const int MAX = 1000006;   const int MAX2 = 207;   const int BASE = 1000000000;   const int CNT = 500;   const int MOD = 1000000007;   vector<int> g[MAX];   int sz[MAX];   double ans[MAX];   void dfs(int v, int p) {     sz[v] = 1;     for (int i = (0); i < (g[v].size()); ++i) {       int to = g[v][i];       if (to == p) {         continue;       }       dfs(to, v);       sz[v] += sz[to];     }   }   void dfs2(int v, int p) {     if (p == -1) {       ans[v] = 1;     } else {       int ps = sz[p] - 1;       int mysz = sz[v];       ans[v] = ans[p] + 1 + (ps - mysz) * 0.5;     }     for (int i = (0); i < (g[v].size()); ++i) {       int to = g[v][i];       if (to == p) {         continue;       }       dfs2(to, v);     }   }   int main() {     int n;     cin >> n;     for (int i = (1); i < (n); ++i) {       int v;       cin >> v;       --v;       g[v].push_back(i);       g[i].push_back(v);     }     dfs(0, -1);     dfs2(0, -1);     for (int i = (0); i < (n); ++i) printf( %.8lf  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int N = 205;   int n;   long long a[N];   map<long long, int> mp;   vector<int> G[N], ans;   bool vis[N];   bool dfs(int u, int step) {     if (step == n) {       ans.push_back(u);       return true;     }     vis[u] = true;     for (int to : G[u])       if (!vis[to]) {         if (dfs(to, step + 1)) {           ans.push_back(u);           return true;         }       }     vis[u] = false;     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]), mp[a[i]] = i;     for (int i = 1; i <= n; ++i) {       if (a[i] % 3 == 0) {         if (mp.find(a[i] / 3) != mp.end()) G[mp[a[i] / 3]].push_back(i);       }       if (mp.find(a[i] * 2) != mp.end()) G[mp[a[i] * 2]].push_back(i);     }     for (int i = 1; i <= n; ++i) {       memset(vis, false, sizeof(vis));       if (dfs(i, 1)) {         for (int v : ans) printf( %lld  , a[v]);         break;       }     }     return 0;   }


#include <cstdio>   #include <iostream>   using namespace std;   const int M = 20005;   const int N = 31;   #define make make_pair   #define pii pair<int,int>   int read()   {    int x=0,f=1;char c;    while((c=getchar())< 0  || c> 9 ) {if(c== - ) f=-1;}    while(c>= 0  && c<= 9 ) {x=(x<<3)+(x<<1)+(c^48);c=getchar();}    return x*f;   }   int n,q,a[M],lg[M],f[M][20][N],g[N],tmp[N];pii dp[M][20];   //f[i][j][k]:stand for the max (l+al) can reach from i through 2^j jumps and k delete    int ask(int l,int r)//ask the l of max (l+al)    {    int k=lg[r-l+1];    return max(dp[l][k],dp[r-(1<<k)+1][k]).second;   }   void init()   {    for(int j=1;(1<<j)<=n;j++)//st     for(int i=1;i+(1<<j)-1<=n;i++)      dp[i][j]=max(dp[i][j-1],dp[i+(1<<j-1)][j-1]);    for(int i=1;i<=n;i++)     for(int j=0;j<N;j++)      f[i][0][j]=min(n,i+a[i]+j);//this  min  is necessary    for(int j=1;(1<<j)<=n;j++)     for(int i=1;i<=n;i++)//please don t limit the range of i      for(int k=0;k<N;k++)       for(int x=0;x<=k;x++)       {        int t=ask(i,f[i][j-1][x]);//find the position        f[i][j][k]=max(f[i][j][k],f[t][j-1][k-x]);       }   }   signed main()   {    n=read();q=read();    for(int i=1;i<=n;i++)    {     a[i]=read();     dp[i][0]=make(min(n,a[i]+i),i);     if(i>1) lg[i]=lg[i>>1]+1;    }    init();    while(q--)    {     int l=read(),r=read(),k=read(),ans=0;     if(l==r) {puts( 0 );continue;}     if(l+a[l]+k>=r) {puts( 1 );continue;}     for(int i=0;i<=k;i++) g[i]=l;     for(int x=15;x>=0;x--)     {      if((1<<x)>n) continue;      for(int i=0;i<=k;i++) tmp[i]=g[i];      for(int i=0;i<=k;i++)      {       int t=ask(l,g[i]);       for(int j=0;i+j<=k;j++)        tmp[i+j]=max(tmp[i+j],f[t][x][j]);      }      int fl=0;      for(int i=0;i<=k;i++)       if(tmp[i]>=r) fl=1;      if(fl) continue;      for(int i=0;i<=k;i++) g[i]=tmp[i];      ans+=(1<<x);     }     printf( %d n ,ans+1);    }   }


#include <bits/stdc++.h>   using namespace std;   int now[5 * 100010], after[5 * 100010], mx[5 * 100010];   int lft[5 * 100010], rgt[5 * 100010], vi[5 * 100010], timer = 0, comp = 0;   long long Add[5 * 100010];   vector<int> g[5 * 100010];   stack<int> stk;   inline void dfs(int c, int p) {     vi[c] = 1;     now[c] = after[c] = ++timer;     stk.push(c);     for (auto x : g[c]) {       if (x != p) {         if (!vi[x]) {           dfs(x, c);           now[c] = min(now[c], now[x]);         } else           now[c] = min(now[c], now[x]);       }     }     if (now[c] == after[c]) {       lft[comp] = rgt[comp] = c;       while (1) {         int node = stk.top();         lft[comp] = min(lft[comp], node);         rgt[comp] = max(rgt[comp], node);         if (node == c) break;         stk.pop();       }       stk.pop();       comp++;     }   }   int main() {     int n, m;     scanf( %d , &n);     ;     scanf( %d , &m);     ;     memset(vi, 0, sizeof(vi));     ;     for (int x = 1; x <= m; x++) {       int u, v;       scanf( %d , &u);       ;       scanf( %d , &v);       ;       g[u].emplace_back(v);       g[v].emplace_back(u);     }     for (int x = 1; x <= n; x++)       if (!vi[x]) dfs(x, 0);     for (int x = 1; x <= n; x++) mx[x] = n;     for (int x = 0; x < comp; x++)       if (lft[x] != rgt[x]) mx[lft[x]] = rgt[x] - 1;     for (int x = n - 1; x >= 1; x--) mx[x] = min(mx[x + 1], mx[x]);     for (int x = 1; x <= n; x++) Add[x] = Add[x - 1] + mx[x] - x + 1;     int q;     scanf( %d , &q);     ;     while (q--) {       int from, to;       scanf( %d , &from);       ;       scanf( %d , &to);       ;       int l = from - 1, r = to + 1, chk = from;       while (l + 1 < r) {         int m = l + r >> 1;         if (mx[m] > to)           r = m;         else           chk = max(chk, m), l = m;       }       chk = l;       printf( %lld n ,              Add[chk] - Add[from - 1] + 1LL * (to - chk) * (to - chk + 1LL) / 2);     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( in.in );   ofstream fout( out.out );   const int N = 1e5 + 10;   int n, m, erased[N], cnt[N], rem[N];   vector<int> a[N], v[N];   deque<vector<int> > ind[N];   queue<int> q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         a[i].push_back(x);         if (x != -1)           v[i].push_back(x);         else           erased[j]++;       }       sort(v[i].begin(), v[i].end());       v[i].resize(unique(v[i].begin(), v[i].end()) - v[i].begin());       vector<int> vec;       for (int j = 0; j < v[i].size(); j++) ind[i].push_back(vec);       for (int j = 0; j < m; j++)         if (a[i][j] != -1)           ind[i][lower_bound(v[i].begin(), v[i].end(), a[i][j]) - v[i].begin()]               .push_back(j);     }     vector<int> res;     for (int i = 0; i < m; i++)       if (erased[i] == n) res.push_back(i + 1);     while (res.size() < m) {       for (int i = 0; i < n; i++) {         if (rem[i] || ind[i].empty()) continue;         rem[i] = ind[i][0].size();         for (int j = 0; j < ind[i][0].size(); j++) {           int k = ind[i][0][j];           cnt[k]++;           if (cnt[k] == n - erased[k]) q.push(k);         }         ind[i].pop_front();       }       if (q.empty()) break;       while (!q.empty()) {         int j = q.front();         q.pop();         res.push_back(j + 1);         for (int i = 0; i < n; i++)           if (a[i][j] != -1) rem[i]--;       }     }     if (res.size() < m)       cout << -1;     else       for (int i = 0; i < res.size(); i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int ans = 1;     if (a > b) {       for (int i = b; i >= 1; i--) {         ans *= i;       }     } else {       for (int i = a; i >= 1; i--) {         ans *= i;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double add[3 * 100 * 1000];   const long double inf = 1e18;   long double max(long double a, long double b, long double c, long double d) {     return max(max(a, b), max(c, d));   }   struct rmq {     int l, r;     long double pref, suf, all, best;     rmq *left, *right;   };   rmq *build(int l, int r) {     rmq *root = (rmq *)malloc(sizeof(rmq));     root->l = l;     root->r = r;     if (l == r) {       root->left = root->right = NULL;       root->suf = max((long double)0, add[l]);       root->pref = root->suf;       root->all = add[l];       root->best = root->suf;     } else {       root->left = build(l, (l + r) / 2);       root->right = build((l + r) / 2 + 1, r);       root->all = root->left->all + root->right->all;       root->pref = max(root->left->pref, root->left->all + root->right->pref);       root->suf = max(root->right->suf, root->left->suf + root->right->all);       root->best = max(root->left->best, root->right->best,                        root->left->suf + root->right->pref, root->all);     }     return root;   }   void get(int l, int r, rmq *root, long double &pref, long double &suf,            long double &all, long double &best) {     if (root->l == l && root->r == r) {       pref = root->pref;       suf = root->suf;       all = root->all;       best = root->best;       return;     }     long double prefL = -inf, prefR = -inf, sufL = -inf, sufR = -inf, allL = -inf,                 allR = -inf, bestL = -inf, bestR = -inf;     if (root->left && root->left->r >= l)       get(l, min(r, root->left->r), root->left, prefL, sufL, allL, bestL);     if (root->right && root->right->l <= r)       get(max(root->right->l, l), r, root->right, prefR, sufR, allR, bestR);     pref = max(prefL, allL + prefR);     suf = max(sufR, allR + sufL);     all = allL + allR;     best = max(bestL, bestR, prefR + sufL, all);   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     int n, m, c;     cin >> n >> m >> c;     long long x[n];     for (int i = 0; i < n; ++i) cin >> x[i];     long double p[n];     for (int i = 1; i < n; ++i) {       cin >> p[i];       p[i] /= 100.0;     }     add[0] = 0;     for (int i = 1; i < n; ++i) add[i] = 0.5 * (x[i] - x[i - 1]) - c * p[i];     rmq *root = build(0, n - 1);     long double res = 0;     long double best, all, suf, pref;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --b;       get(a, b, root, pref, suf, all, best);       res += best;     }     cout << res;     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mod = 998244353;   const int inv2 = (mod + 1) / 2;   int n, m, k;   int row_one[N], row_zero[N], col_one[N], col_zero[N];   int all_one, all_zero;   int zero_r, zero_c, mul_r, mul_c;   map<pair<int, int>, int> Map;   int rval(int x) {     if (row_one[x] > 0 && row_zero[x] > 0) return 0;     if (row_one[x] == 0 && row_zero[x] == 0) return 2;     return 1;   }   int cval(int x) {     if (col_one[x] > 0 && col_zero[x] > 0) return 0;     if (col_one[x] == 0 && col_zero[x] == 0) return 2;     return 1;   }   void upd(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int Qpow(int x, int p) {     int ans = 1;     while (p) {       if (p & 1) ans = 1LL * x * ans % mod;       x = 1LL * x * x % mod;       p >>= 1;     }     return ans;   }   int main() {     cin >> n >> m >> k;     mul_r = Qpow(2, n);     mul_c = Qpow(2, m);     for (int i = 1; i <= k; ++i) {       int x, y, t;       scanf( %d%d%d , &x, &y, &t);       int v_c = cval(y);       int v_r = rval(x);       if (v_c == 0) --zero_c;       if (v_r == 0) --zero_r;       if (v_c == 2) mul_c = 1LL * mul_c * inv2 % mod;       if (v_r == 2) mul_r = 1LL * mul_r * inv2 % mod;       if (Map[make_pair(x, y)] != 0) {         int p = Map[make_pair(x, y)];         --p;         if ((x + y) % 2 == 1) p ^= 1;         if (p == 0)           --all_zero;         else           --all_one;         if ((x + y) % 2 == 1) p ^= 1;         if (y % 2 == 0) p ^= 1;         if (p == 0)           --row_zero[x];         else           --row_one[x];         if (y % 2 == 0) p ^= 1;         if (x % 2 == 0) p ^= 1;         if (p == 0)           --col_zero[y];         else           --col_one[y];         if (x % 2 == 0) p ^= 1;       }       if (t == -1) {         Map[make_pair(x, y)] = 0;       } else {         Map[make_pair(x, y)] = t + 1;         int p = t;         if ((x + y) % 2 == 1) p ^= 1;         if (p == 0)           ++all_zero;         else           ++all_one;         if ((x + y) % 2 == 1) p ^= 1;         if (y % 2 == 0) p ^= 1;         if (p == 0)           ++row_zero[x];         else           ++row_one[x];         if (y % 2 == 0) p ^= 1;         if (x % 2 == 0) p ^= 1;         if (p == 0)           ++col_zero[y];         else           ++col_one[y];         if (x % 2 == 0) p ^= 1;       }       v_c = cval(y);       v_r = rval(x);       if (v_c == 0) ++zero_c;       if (v_r == 0) ++zero_r;       if (v_c == 2) mul_c = 2LL * mul_c % mod;       if (v_r == 2) mul_r = 2LL * mul_r % mod;       int ans = 0;       if (zero_r == 0) upd(ans, mul_r);       if (zero_c == 0) upd(ans, mul_c);       if (zero_r == 0 && zero_c == 0) {         if (all_one == 0) --ans;         if (all_zero == 0) --ans;         upd(ans, mod);       }       printf( %d n , ans);     }     return 0;   }


#include <algorithm>   #include <cassert>   #include <cmath>   #include <cstdlib>   #include <cstring>   #include <iomanip>   #include <iostream>   #include <limits>   #include <map>   #include <numeric>   #include <queue>   #include <random>   #include <set>   #include <stack>   #include <unordered_map>   #include <unordered_set>   #include <vector>   using namespace std;      using LL = long long;      int Rev(int a, int k) {     vector<int> x;     while (a > 0) {       x.push_back((k - a % k) % k);       a /= k;     }     reverse(x.begin(), x.end());     int ans = 0;     for (int i : x) ans = ans * k + i;     return ans;   }      int Xor(int a, int b, int k) {     vector<int> x;     while (a > 0 || b > 0) {       x.push_back((a + b) % k);       a /= k;       b /= k;     }     reverse(x.begin(), x.end());     int ans = 0;     for (int i : x) ans = ans * k + i;     return ans;   }      int main() {     ios::sync_with_stdio(false);     int times;     cin >> times;     while (times--) {       int n, k;       cin >> n >> k;       vector<int> x {0, Rev(1, k)};       for (int i = 2; i < n; i += 2) {         x.push_back(Xor(i, Rev(i - 1, k), k));         x.push_back(Xor(i, Rev(i + 1, k), k));       }       for (int i = 0; i < n; ++i) {         cout << x[i] << endl;         int r;         cin >> r;         if (r == 1) break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_SIZE = 10000;   void solve() {     int t;     cin >> t;     string str[2];     map<string, vector<string>> m;     string tmp;     for (int i = 0; i < t; i++) {       cin >> str[0] >> tmp >> str[1];       m[str[0]].push_back(str[1]);     }     int a, b, c;     cin >> a >> b >> c;     int minDiff = -1;     int ii, jj, kk;     vector<vector<int>> idxs;     for (int i = 1; i <= 5; i++) {       for (int j = 1; j <= 5; j++) {         for (int k = 1; k <= 5; k++) {           if (i + j + k == 7) {             int minNum = a / i;             int maxNum = a / i;             maxNum = max(maxNum, b / j);             minNum = min(minNum, b / j);             maxNum = max(maxNum, c / k);             minNum = min(minNum, c / k);             if (minDiff == -1 || minDiff > maxNum - minNum) {               idxs.clear();               minDiff = maxNum - minNum;               ii = i;               jj = j;               kk = k;               vector<int> vec;               vec.push_back(ii);               vec.push_back(jj);               vec.push_back(kk);               idxs.push_back(vec);             } else if (minDiff == maxNum - minNum) {               vector<int> vec;               vec.push_back(i);               vec.push_back(j);               vec.push_back(k);               idxs.push_back(vec);             }           }         }       }     }     vector<string> names2;     names2.push_back( Troll );     names2.push_back( Dracul );     names2.push_back( Anka );     names2.push_back( Snowy );     names2.push_back( Hexadecimal );     names2.push_back( Chapay );     names2.push_back( Cleo );     vector<int> np;     for (int i = 0; i < 7; i++) np.push_back(i);     int maxCnt = -1;     for (int l = 0; l < idxs.size(); l++) {       ii = idxs[l][0];       jj = idxs[l][1];       kk = idxs[l][2];       do {         vector<string> cmpstr;         for (int i = 0; i < ii; i++) cmpstr.push_back(names2[np[i]]);         int icnt = 0;         for (int i = 0; i < cmpstr.size(); i++) {           for (int j = 0; j < cmpstr.size(); j++) {             if (cmpstr[i] == cmpstr[j]) continue;             if (m.count(cmpstr[i])) {               if (m[cmpstr[i]].end() !=                   find(m[cmpstr[i]].begin(), m[cmpstr[i]].end(), cmpstr[j])) {                 icnt++;               }             }           }         }         cmpstr.clear();         for (int i = ii; i < jj + ii; i++) cmpstr.push_back(names2[np[i]]);         int jcnt = 0;         for (int i = 0; i < cmpstr.size(); i++) {           for (int j = 0; j < cmpstr.size(); j++) {             if (cmpstr[i] == cmpstr[j]) continue;             if (m.count(cmpstr[i])) {               if (m[cmpstr[i]].end() !=                   find(m[cmpstr[i]].begin(), m[cmpstr[i]].end(), cmpstr[j])) {                 jcnt++;               }             }           }         }         cmpstr.clear();         for (int i = ii + jj; i < 7; i++) cmpstr.push_back(names2[np[i]]);         int kcnt = 0;         for (int i = 0; i < cmpstr.size(); i++) {           for (int j = 0; j < cmpstr.size(); j++) {             if (cmpstr[i] == cmpstr[j]) continue;             if (m.count(cmpstr[i])) {               if (m[cmpstr[i]].end() !=                   find(m[cmpstr[i]].begin(), m[cmpstr[i]].end(), cmpstr[j])) {                 kcnt++;               }             }           }         }         maxCnt = max(maxCnt, icnt + jcnt + kcnt);       } while (next_permutation(np.begin(), np.end()));     }     cout << minDiff <<     << maxCnt << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long st(long long b, long long d) {     long long a, a1 = b, i;     for (i = 1, a = b; a <= d && d % a == 0; ++i) a1 = a, a *= b;     return a1;   }   long long type(long long b, long long d, long long& res) {     long long g = gcd(b, d), i, a;     if (g > 1) {       for (i = 1, a = g; a < 100500000000; ++i, a *= g)         if (a % d == 0) {           res = i;           return 2;         }     }     if (b % d == 1) return 3;     if ((b + 1) % d == 0) return 11;     return 0;   }   int main() {     long long i, n, j, a, b, d;     cin >> b >> d;     long long res, tp = type(b, d, res);     if (tp > 0) {       cout << tp <<  -type  << endl;       if (tp == 2) cout << res;       return 0;     }     for (i = 2; i <= d; ++i)       if (d % i == 0)         if (type(b, st(i, d), res) > 0) {           d /= st(i, d);         } else {         }     if (d == 1) {       cout <<  6-type ;       return 0;     }     cout <<  7-type ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const int maxm = 2005;   struct detail {     int c[maxm];     int len;     int p;     detail() { len = 0; }     void add(int i) {       c[len] = i;       ++len;     }   } details[maxn];   int order[maxn];   int n, m;   bool cmp(const int a, const int b) { return details[a].p > details[b].p; }   int main(int argc, const char* argv[]) {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       order[i] = i;       cin >> details[i].p;     }     for (int i = 0; i < m; ++i) {       int x = 1, y = 1;       cin >> x >> y;       x--;       y--;       details[x].add(y);       details[y].add(x);     }     sort(order, order + n, cmp);     long long a = 0;     for (int i = 0; i < n; ++i) {       int o = order[i];       for (int j = 0; j < details[o].len; ++j) {         a += details[details[o].c[j]].p;       }       details[o].p = 0;     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long a, b;     cin >> a >> b;     long long c = 1, i = 0;     while (1) {       if (i % 2 == 0 && a >= c)         a -= c;       else if (i & 1 && b >= c)         b -= c;       else         break;       c++;       i++;     }     if (i & 1)       cout <<  Valera n ;     else       cout <<  Vladik n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, N[5010], e, s, X[5010], A[5010], B[5010], C[5010], D[5010];   long long int total, t, selection;   long long int Dis(long long int x, long long int y) {     return labs(X[x] - X[y]) + (x > y ? C[x] + B[y] : D[x] + A[y]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> s >> e;     for (int i = 1; i <= n; i++) cin >> X[i];     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++) cin >> B[i];     for (int i = 1; i <= n; i++) cin >> C[i];     for (int i = 1; i <= n; i++) cin >> D[i];     N[s] = e;     total = Dis(s, e);     for (int i = 1; i <= n; i++) {       if (i == s || i == e) continue;       long long int l = LLONG_MAX;       for (int j = s; j != e; j = N[j]) {         t = Dis(j, i) + Dis(i, N[j]) - Dis(j, N[j]);         if (t < l) {           l = t;           selection = j;         }       }       total += l;       N[i] = N[selection];       N[selection] = i;     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   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 * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void write(int x) {     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 200005, inf = 1e9;   int a[N], t[N], id[N], fa[N], dep[N], num[N], son[N], q[N], dfn[N];   int top[N], ans[N], n, m, cnt = 0, fd;   struct tree {     int mx, lazy;   } tr[N << 2];   bool cmp(int x, int y) {     if (t[x] + dep[a[x]] != t[y] + dep[a[y]])       return t[x] + dep[a[x]] < t[y] + dep[a[y]];     return a[x] < a[y];   }   inline void pushup(int x) { tr[x].mx = max(tr[x << 1].mx, tr[x << 1 | 1].mx); }   inline void pushdown(int x, int l, int mid, int r) {     if (tr[x].lazy < -inf) return;     tr[x << 1].lazy = tr[x << 1 | 1].lazy = tr[x].lazy;     tr[x << 1].mx = mid * 2 + tr[x].lazy;     tr[x << 1 | 1].mx = r * 2 + tr[x].lazy;     tr[x].lazy = -inf - 1;   }   void modify(int now, int l, int r, int x, int y, int z) {     if (x <= l && r <= y) {       tr[now].lazy = z;       tr[now].mx = r * 2 + z;       return;     }     int mid = (l + r) >> 1;     pushdown(now, l, mid, r);     if (x <= mid) modify(now << 1, l, mid, x, y, z);     if (y > mid) modify(now << 1 | 1, mid + 1, r, x, y, z);     pushup(now);   }   void query(int now, int l, int r, int x, int y, int z) {     if (tr[now].mx <= z) return;     if (l == r) {       fd = q[l];       return;     }     int mid = (l + r) >> 1;     pushdown(now, l, mid, r);     if (fd == -1 && y > mid) query(now << 1 | 1, mid + 1, r, x, y, z);     if (fd == -1 && x <= mid) query(now << 1, l, mid, x, y, z);     pushup(now);   }   int work(int x, int t) {     int y = x;     while (1) {       fd = -1;       query(1, 0, n, dfn[top[y]], dfn[y], t + dfn[y]);       if (fd >= 0) {         t += dep[y] - dep[fd];         y = fd;         break;       }       if (!y) break;       t += dep[y] - dep[fa[top[y]]];       y = fa[top[y]];     }     int z = t + dep[x] - dep[y];     while (1) {       if (top[x] == top[y]) {         if (x != y) modify(1, 0, n, dfn[y] + 1, dfn[x], t - dfn[y]);         break;       }       modify(1, 0, n, dfn[top[x]], dfn[x], dep[x] - dep[y] + t - dfn[x]);       x = fa[top[x]];     }     return z;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; ++i) {       fa[i] = read();       dep[i] = dep[fa[i]] + 1;       num[i] = 1;     }     for (int i = n; i; i--) {       if (num[i] > num[son[fa[i]]]) son[fa[i]] = i;       if (fa[i]) num[fa[i]] += num[i];     }     for (int i = son[0]; i; i = son[i]) q[dfn[i] = ++cnt] = i;     for (int i = 0; i <= n; ++i)       if (!dfn[i])         for (int j = i; j; j = son[j]) top[q[dfn[j] = ++cnt] = j] = i;     for (int i = 1; i <= m; ++i) a[i] = read(), t[i] = read();     for (int i = 1; i <= m; ++i) id[i] = i;     sort(id + 1, id + m + 1, cmp);     tr[1].mx = tr[1].lazy = -inf;     for (int i = 1; i <= m; ++i) ans[id[i]] = work(a[id[i]], t[id[i]]);     for (int i = 1; i <= m; ++i) write(ans[i]), putchar(   );     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct obj {     int x, y, ind;     obj(int x, int y, int ind) : x(x), y(y), ind(ind) {}     obj() {}   };   int main() {     vector<obj> s;     int n, x, y;     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       scanf( %d%d , &x, &y);       s.push_back(obj(x, y, i));     }     sort(s.begin(), s.end(), [](obj a, obj b) {       if (a.x / 1000 == b.x / 1000) {         if (a.x / 1000 % 2 == 0)           return a.y < b.y;         else           return a.y > b.y;       }       return a.x / 1000 < b.x / 1000;     });     for (auto v : s) printf( %d  , v.ind);     return 0;   }