#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long long int lli;   const int mod=1e9+7;   int main()   {           ll t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           if(n<=32)           {               ll m=n-3;               m+=5;               cout<<m<<endl;               for(ll i=3; i<n; i++)               {                   cout<<i<<   <<n<<endl;               }               for(ll i=0; i<5; i++)               {                   cout<<n<<   <<2<<endl;               }           }           else           {               ll m = n-4;               m+=9;               cout<<m<<endl;               for(ll i=3; i<n; i++)               {                   if(i==16)                       continue;                   cout<<i<<   <<n<<endl;               }                   for(ll i=0; i<5; i++)               {                   cout<<n<<   <<16<<endl;               }                   for(ll i=0; i<4; i++)               {                   cout<<16<<   <<2<<endl;               }               //cout<<m<<nn;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int a = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       a = a * 10 + c - 48;       c = getchar();     }     return a;   }   const int _ = 3e5 + 7, __ = _ * 19;   vector<int> nxt[_];   int N, M, dep[_];   void qdep(int x, int p) {     dep[x] = dep[p] + 1;     for (auto &t : nxt[x])       if (t != p) qdep(t, x);   }   long long mrk[__], mn[__];   int ch[__][2], cnode;   void mark(int x, long long v) {     if (x) {       mrk[x] = min(mrk[x] + v, mn[0]);       mn[x] = min(mn[x] + v, mn[0]);     }   }   void down(int x) {     if (x && mrk[x]) {       mark((ch[x][0]), mrk[x]);       mark((ch[x][1]), mrk[x]);       mrk[x] = 0;     }   }   void mdf(int &x, int l, int r, int t, long long v, bool type) {     if (!type && !x) {       x = ++cnode;     }     if (l == r) {       mn[x] = type ? v : min(mn[x], v);       return;     }     down(x);     ((l + r) >> 1) >= t ? mdf((ch[x][0]), l, ((l + r) >> 1), t, v, type)                         : mdf((ch[x][1]), ((l + r) >> 1) + 1, r, t, v, type);     mn[x] = min(mn[(ch[x][0])], mn[(ch[x][1])]);   }   int merge(int p, int q) {     if (!p || !q) {       return p + q;     }     mn[p] = min(mn[p], mn[q]);     down(p);     down(q);     ch[p][0] = merge(ch[p][0], ch[q][0]);     ch[p][1] = merge(ch[p][1], ch[q][1]);     return p;   }   vector<pair<int, int> > route[_];   int dfs(int x, int p) {     long long vlsum = 0;     int rt = 0;     for (auto t : nxt[x])       if (t != p) {         int R = dfs(t, x);         mdf(R, 1, N, dep[x] + 1, mn[0], 1);         long long v = mn[R];         mark(rt, v);         mark(R, vlsum);         vlsum = min(mn[0], vlsum + v);         rt = merge(rt, R);       }     for (auto t : route[x]) mdf(rt, 1, N, t.first, vlsum + t.second, 0);     if (x == 1) cout << (vlsum <= 1e16 ? vlsum : -1);     return rt;   }   int main() {     N = read();     M = read();     for (int i = 1; i < N; ++i) {       int x = read(), y = read();       nxt[x].push_back(y);       nxt[y].push_back(x);     }     qdep(1, 0);     for (int i = 1; i <= M; ++i) {       int x = read(), y = read(), w = read();       route[x].push_back(pair<int, int>(dep[y], w));     }     memset(mn, 0x3f, sizeof(mn));     dfs(1, 0);     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y, s;     scanf( %d %d %d , &x, &y, &s);     if (s >= 0) {       y = y + s;       if (y % x)         printf( %d , y % x);       else         printf( %d , x);     } else if (s < 0) {       double p = abs(s);       p = ceil(p / x);       y = y + s + (p * x);       if (y % x)         printf( %d , y % x);       else         printf( %d , x);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, a, b;     cin >> n >> a >> b;     set<long long> s;     while (a--) {       long long j;       cin >> j;       s.insert(j);     }     for (long long i = 1; i <= n; i++)       if (s.count(i))         cout <<  1  ;       else         cout <<  2  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MAXN = 4010;   int n;   inline int pack(int l, int r, int k) { return (l << 19) + (r << 7) + k; }   unordered_map<int, int> dp(MAXN* MAXN * 2);   vector<int> a, pref;   int calc(int l, int r, int k, int p) {     if (p) {       if (dp.count(pack(l, r, k))) return dp[pack(l, r, k)];       if (r - l + 1 < k) return dp[pack(l, r, k)] = 0;       if (r - l + 1 == k)         return dp[pack(l, r, k)] =                    (calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1]));       return dp[pack(l, r, k)] = max(                  calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1]),                  calc(l + k + 1, r, k + 1, p ^ 1) + (pref[l + k] - pref[l - 1]));     }     if (r - l + 1 < k) return 0;     if (r - l + 1 == k) return calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]);     return min(calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]),                calc(l, r - k - 1, k + 1, p ^ 1) - (pref[r] - pref[r - k - 1]));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     a.resize(n);     pref.resize(n + 1);     for (int i = 0; i < n; i++) {       cin >> a[i];       pref[i + 1] = pref[i] + a[i];     }     cout << calc(1, n, 1, 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   int n;   vector<int> d, a;   int get_longest(int l) {     vector<int> d;     while (l > a.size())       for (int i = 0; i < n; ++i) a.push_back(a[i]);     d.assign(l + 10, INF);     d[0] = -INF;     for (int i = 0; i < l; ++i) {       int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());       if (d[j - 1] <= a[i] && a[i] < d[j]) d[j] = a[i];     }     for (int i = 1; i <= l; ++i)       if (d[i] == INF) return i - 1;     return l;   }   int main() {     int t;     int longest_same = 1;     vector<int> b;     scanf( %d %d , &n, &t);     a.assign(n, 0);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     b.assign(a.begin(), a.end());     sort(b.begin(), b.end());     map<int, int> new_val;     int longest = 1;     for (int i = 0; i < n; ++i) {       if (i > 0 && b[i] == b[i - 1])         ++longest;       else {         if (longest > longest_same) longest_same = longest;         longest = 1;       }       if (i == 0 || b[i] != b[i - 1]) new_val[b[i]] = i;     }     if (longest > longest_same) longest_same = longest;     for (int i = 0; i < n; ++i) {     }     longest = get_longest(n);     int next_longest, prev_longest;     int d = INF;     int k = 1;     while (d > longest_same && k < t) {       ++k;       next_longest = get_longest(k * n);       d = next_longest - longest;       prev_longest = longest;       longest = next_longest;     }     if (d <= longest_same) {       longest = prev_longest + (t - k + 1) * longest_same;     }     printf( %d n , longest);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace DynamicTree {   unsigned int randxor() {     static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;     unsigned int t;     t = (x ^ (x << 11));     x = y;     y = z;     z = w;     return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));   }   struct D_NODE {     int lazy_for_dep;     int dep;     D_NODE *pr;     D_NODE *pair_of_end;     int __PRIORITY;     int size;     long long int lazy_for_dist;     long long int dist;     long long int have_dist;     D_NODE *lef;     D_NODE *rig;     int idx;     int MINT_DEP;     D_NODE *MINT;     int MAXT_DEP;     D_NODE *MAXT;     bool start_flag;     int NUMBER_OF_START_FLAG;     D_NODE() {       NUMBER_OF_START_FLAG;       start_flag = false;       lazy_for_dep = 0;       dep = 0;       lazy_for_dist = 0;       dist = 0;       lef = rig = NULL;       __PRIORITY = randxor();       pair_of_end = NULL;       MINT = NULL;       MINT_DEP = INT_MAX;       MAXT = NULL;       MAXT_DEP = INT_MIN;       pr = NULL;       size = 0;     }   };   const int MEMORY_SIZE = 2000000;   D_NODE dymmy[MEMORY_SIZE];   int ord = 0;   D_NODE *neww() {     if (ord < MEMORY_SIZE) {       ord++;       return &dymmy[ord - 1];     }     return new D_NODE();   }   const int VECTOR_SIZE = 1000000;   D_NODE *VEC[VECTOR_SIZE];   int VECTOR_CUR_INDEX = 0;   inline void see(D_NODE *f, bool B = false) {     if (f->lef) {       see(f->lef, true);     }     cout << f->idx <<    ;     if (f->rig) {       see(f->rig, true);     }     if (B == false) {       puts(  );     }   }   int get_size(D_NODE *b) {     if (b == NULL) {       return 0;     }     return b->size;   }   void update(D_NODE *B) {     if (B == NULL) {       return;     }     if (B->lazy_for_dep) {       B->dep += B->lazy_for_dep;       if (B->lef) {         B->lef->lazy_for_dep += B->lazy_for_dep;       }       if (B->rig) {         B->rig->lazy_for_dep += B->lazy_for_dep;       }       B->lazy_for_dep = 0;     }     if (B->lazy_for_dist) {       B->dist += B->lazy_for_dist;       if (B->lef) {         B->lef->lazy_for_dist += B->lazy_for_dist;       }       if (B->rig) {         B->rig->lazy_for_dist += B->lazy_for_dist;       }       B->lazy_for_dist = 0;     }     B->size = 1 + get_size(B->lef) + get_size(B->rig);     if (B->lef) {       B->lef->pr = B;     }     if (B->rig) {       B->rig->pr = B;     }     B->MINT = B;     B->MINT_DEP = B->dep;     if (B->lef && B->MINT_DEP > B->lef->MINT_DEP + B->lef->lazy_for_dep) {       B->MINT_DEP = B->lef->MINT_DEP + B->lef->lazy_for_dep;       B->MINT = B->lef->MINT;     }     if (B->rig && B->MINT_DEP > B->rig->MINT_DEP + B->rig->lazy_for_dep) {       B->MINT_DEP = B->rig->MINT_DEP + B->rig->lazy_for_dep;       B->MINT = B->rig->MINT;     }     B->MAXT = B;     B->MAXT_DEP = B->dep;     if (B->lef && B->MAXT_DEP < B->lef->MAXT_DEP + B->lef->lazy_for_dep) {       B->MAXT_DEP = B->lef->MAXT_DEP + B->lef->lazy_for_dep;       B->MAXT = B->lef->MAXT;     }     if (B->rig && B->MAXT_DEP < B->rig->MAXT_DEP + B->rig->lazy_for_dep) {       B->MAXT_DEP = B->rig->MAXT_DEP + B->rig->lazy_for_dep;       B->MAXT = B->rig->MAXT;     }     B->NUMBER_OF_START_FLAG = B->start_flag;     if (B->lef) {       B->NUMBER_OF_START_FLAG += B->lef->NUMBER_OF_START_FLAG;     }     if (B->rig) {       B->NUMBER_OF_START_FLAG += B->rig->NUMBER_OF_START_FLAG;     }   }   D_NODE *find_root(D_NODE *a) {     while (a->pr != NULL) {       update(a);       a = a->pr;     }     return a;   }   void path_update(D_NODE *a, bool dep_only = false) {     VECTOR_CUR_INDEX = 0;     while (a != NULL) {       VEC[VECTOR_CUR_INDEX] = a;       VECTOR_CUR_INDEX++;       a = a->pr;     }     int k = VECTOR_CUR_INDEX - 1;     if (dep_only == false) {       for (int i = k; i >= 0; i--) {         update(VEC[i]);       }     }     for (int i = 0; i <= k; i++) {       update(VEC[i]);     }   }   inline D_NODE *merge(D_NODE *a, D_NODE *b) {     if (a != NULL) update(a);     if (b != NULL) update(b);     if (a == NULL) {       path_update(b);       return b;     }     if (b == NULL) {       path_update(a);       return a;     }     if (a->__PRIORITY > b->__PRIORITY) {       a->rig = merge(a->rig, b);       update(a);       return a;     } else {       b->lef = merge(a, b->lef);       update(b);       return b;     }   }   int calc_left_size(D_NODE *a) {     if (a == NULL) {       return 0;     }     path_update(a);     int sum = 1 + get_size(a->lef);     D_NODE *pre = a;     a = a->pr;     while (a != NULL) {       if (a->rig == pre) {         sum++;         sum += get_size(a->lef);       }       pre = a;       a = a->pr;     }     return sum;   }   inline void split_base_cnt(D_NODE *b, D_NODE *&l, D_NODE *&r, int x) {     if (b == NULL) {       D_NODE *L = NULL;       if (l) L = l->pr;       D_NODE *R = NULL;       if (r) R = r->pr;       l = r = NULL;       path_update(L);       path_update(R);       return;     }     update(b);     int __get_size = get_size(b->lef);     if (__get_size >= x) {       r = b;       update(b->lef);       split_base_cnt(b->lef, l, b->lef, x);       return;     }     if (__get_size + 1 == x) {       l = b;       r = b->rig;       l->rig = NULL;       path_update(l);       return;     }     l = b;     update(b->rig);     split_base_cnt(b->rig, b->rig, r, x - 1 - __get_size);   }   D_NODE *cut(D_NODE *&tree, D_NODE *root_of_new_subtree) {     if (root_of_new_subtree == NULL) {       cout <<  error cut  << endl;       exit(0);       return NULL;     }     D_NODE *star = root_of_new_subtree;     D_NODE *en = root_of_new_subtree->pair_of_end;     int __LEFT_SIZE = calc_left_size(star);     int cur_dep = root_of_new_subtree->dep;     long long int cur_dist = root_of_new_subtree->dist;     D_NODE *l1 = NULL;     D_NODE *l2 = NULL;     D_NODE *l3 = NULL;     split_base_cnt(tree, l1, l2, __LEFT_SIZE - 1);     if (l1) {       l1->pr = NULL;     }     if (l2) {       l2->pr = NULL;     }     if (tree) {       tree->pr = NULL;     }     int __RIGHT_SIZE = calc_left_size(en);     split_base_cnt(l2, l2, l3, __RIGHT_SIZE);     if (l2) {       l2->pr = NULL;     }     if (l3) {       l3->pr = NULL;     }     tree = merge(l1, l3);     if (tree) tree->pr = NULL;     if (l2) l2->pr = NULL;     if (l2) l2->lazy_for_dep += -cur_dep;     if (l2) l2->lazy_for_dist += -cur_dist;     update(l2);     return l2;   }   void add_distance(D_NODE *&tree, D_NODE *ap, long long int add) {     path_update(ap);     ap->have_dist += add;     D_NODE *star = ap;     D_NODE *en = star->pair_of_end;     int __LEFT_SIZE = calc_left_size(star);     D_NODE *l1;     D_NODE *l2;     D_NODE *l3;     split_base_cnt(tree, l1, l2, __LEFT_SIZE - 1);     int __RIGHT_SIZE = calc_left_size(en);     split_base_cnt(tree, l2, l3, __RIGHT_SIZE);     l2->lazy_for_dist += add;     update(l2);     tree = merge(l1, l2);     tree = merge(tree, l3);     tree->pr = NULL;     return;   }   void link(D_NODE *&tree, D_NODE *nex_parent, D_NODE *linked,             long long int subtree_add_dist = 1) {     if (linked == NULL) {       return;     }     path_update(nex_parent);     path_update(nex_parent->pair_of_end);     D_NODE *ne = neww();     (*ne) = (*nex_parent->pair_of_end);     ne->pr = NULL;     ne->lef = ne->rig = NULL;     ne->size = 1;     ne->MINT_DEP = ne->MAXT_DEP = ne->dep;     ne->MINT = ne->MAXT = ne;     update(ne);     update(linked);     linked->lazy_for_dist += nex_parent->dist + subtree_add_dist;     linked->lazy_for_dep += nex_parent->dep + 1;     update(linked);     linked = merge(ne, linked);     linked->pr = NULL;     int LEFT_SIZE = calc_left_size(nex_parent->pair_of_end);     LEFT_SIZE--;     D_NODE *l1 = NULL;     D_NODE *l2 = NULL;     split_base_cnt(tree, l1, l2, LEFT_SIZE);     if (l1) l1->pr = NULL;     if (l2) l2->pr = NULL;     tree = merge(l1, linked);     if (tree) {       tree->pr = NULL;     }     D_NODE *cp_ = tree;     tree = merge(tree, l2);     tree->pr = NULL;   }   D_NODE *LCA(D_NODE *&tree, D_NODE *a, D_NODE *b) {     if (a == b) return a;     tree->pr = NULL;     int lef1 = calc_left_size(a);     int rig1 = calc_left_size(a->pair_of_end);     int lef2 = calc_left_size(b);     int rig2 = calc_left_size(b->pair_of_end);     if (lef1 <= lef2 && rig2 <= rig1) {       return a;     }     if (lef2 <= lef1 && lef1 <= rig2) {       return b;     }     int mint = lef1;     if (lef1 > lef2) {       mint = lef2;     }     int maxt = rig1;     if (rig1 < rig2) {       maxt = rig2;     }     D_NODE *L1;     D_NODE *L2;     D_NODE *L3;     D_NODE *ANS;     split_base_cnt(tree, L1, L2, mint - 1);     split_base_cnt(L2, L2, L3, maxt - mint + 1);     if (L1) {       L1->pr = NULL;     }     if (L2) {       L2->pr = NULL;     }     if (L3) {       L3->pr = NULL;     }     ANS = L2->MINT;     tree = merge(L1, L2);     tree = merge(tree, L3);     if (tree) tree->pr = NULL;     return ANS;   }   long long int distance(D_NODE *&tree, D_NODE *a, D_NODE *b) {     if (a == b) {       return 0;     }     tree->pr = NULL;     D_NODE *LC = LCA(tree, a, b);     path_update(LC);     long long int ans = a->dist + b->dist - 2LL * LC->dist;     return ans;   }   void push_back(D_NODE *&tree, D_NODE *a) {     tree = merge(tree, a);     tree->pr = NULL;   }   D_NODE *go_up(D_NODE *tree, D_NODE *from, int x) {     if (x == 0) {       return from;     }     path_update(from);     int want_dep = from->dep - x;     update(from);     update(from->lef);     if (from->lef && from->lef->MINT_DEP <= want_dep &&         want_dep <= from->lef->MAXT_DEP) {       from = from->lef;       while (1) {         update(from);         update(from->rig);         if (from->rig && from->rig->MINT_DEP <= want_dep &&             from->rig->MAXT_DEP >= want_dep) {           from = from->rig;           continue;         }         if (from->dep == want_dep) {           return from;         }         from = from->lef;         continue;       }     }     D_NODE *pre = from;     from = from->pr;     while (1) {       update(from);       update(from->lef);       if (from->lef == pre) {         pre = from;         from = from->pr;         continue;       }       if (from->dep == want_dep) {         return from;       }       if (from->lef && from->lef->MINT_DEP <= want_dep &&           want_dep <= from->lef->MAXT_DEP) {         from = from->lef;         while (1) {           update(from);           update(from->rig);           if (from->rig && from->rig->MINT_DEP <= want_dep &&               from->rig->MAXT_DEP >= want_dep) {             from = from->rig;             continue;           }           if (from->dep == want_dep) {             return from;           }           from = from->lef;           continue;         }       } else {         pre = from;         from = from->pr;       }     }   }   D_NODE *F(D_NODE *tree, int k) {     D_NODE *a = tree;     update(a);     while (1) {       update(a);       if (a->rig) {         update(a->rig);         if (a->rig->MAXT_DEP >= k && a->rig->MINT_DEP <= k) {           a = a->rig;           continue;         }       }       if (a->dep == k) {         return a;       }       a = a->lef;     }     return a;   }   inline void se(D_NODE *f, bool B = false) {     update(f);     int MX = f->MAXT_DEP;     int MN = f->MINT_DEP;     if (f->lef) {       se(f->lef, true);     }     if (f->rig) {       se(f->rig, true);     }     update(f);   }   }  // namespace DynamicTree   DynamicTree::D_NODE *root;   int n;   int m;   vector<int> v[100002];   DynamicTree::D_NODE *linkk[100002];   int dep[100002];   int star[100002];   int en[100002];   bool use[100002];   vector<int> vv;   int siz;   inline void dfs(int b, int h = 0) {     use[b] = true;     dep[b] = h;     star[b] = siz;     siz++;     vv.push_back(b);     for (int i = 0; i < v[b].size(); i++) {       if (use[v[b][i]]) {         continue;       }       dfs(v[b][i], h + 1);       en[b] = siz;       siz++;       vv.push_back(b);     }     if (siz - 1 == star[b]) {       vv.push_back(b);       en[b] = siz;       siz++;     }   }   void make() {     dfs(0);     for (int i = 0; i < vv.size(); i++) {       DynamicTree::D_NODE *add = DynamicTree::neww();       add->dep = dep[vv[i]];       add->idx = vv[i];       add->MINT = add;       add->MINT_DEP = dep[vv[i]];       add->MAXT_DEP = dep[vv[i]];       add->MAXT = add;       add->dist = dep[vv[i]];       add->have_dist = 1;       add->size = 1;       if (star[vv[i]] == i) {         add->start_flag = true;         add->NUMBER_OF_START_FLAG = 1;         linkk[vv[i]] = add;         DynamicTree::push_back(root, add);       } else {         linkk[vv[i]]->pair_of_end = add;         DynamicTree::push_back(root, add);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         int a;         scanf( %d , &a);         a--;         v[i].push_back(a);       }     }     make();     int cc = 0;     while (m--) {       int ty;       scanf( %d , &ty);       if (ty == 1) {         cc++;         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         printf( %lld n , DynamicTree::distance(root, linkk[a], linkk[b]));         continue;       }       if (ty == 2) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b = DynamicTree::go_up(root, linkk[a], b)->idx;         DynamicTree::D_NODE *nw = DynamicTree::cut(root, linkk[a]);         DynamicTree::link(root, linkk[b], nw);         continue;       }       int k;       scanf( %d , &k);       cc++;       DynamicTree::D_NODE *ans = DynamicTree::F(root, k);       printf( %d n , ans->idx + 1);     }     return 0;   }


/******************************************************************************                                    Online C++ Compiler.                  Code, Compile, Run and Debug C++ program online.   Write your code in this editor and press  Run  button to compile and execute it.      *******************************************************************************/      #include <bits/stdc++.h>   using namespace std;      #define ll long long      int main()   {       int t; cin >> t;              while (t--){           int n; cin >> n;           vector<int> a(n);           for (int i = 0; i < n; i++) cin >> a[i];           int check = 1;           for (int i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) check = 0;           if (check) cout << 0 << endl;           else if (a[0] == 1 || a[n - 1] == n) cout << 1 << endl;           else if (a[0] == n && a[n - 1] == 1) cout << 3 << endl;           else cout << 2 << endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, x1, y, y1;     char a, b;     cin >> a >> y >> b >> y1;     x1 = a - 96;     x = b - 96;     int counter = 0;     string s[100000];     while (true) {       if (x == x1 && y == y1) {         break;       }       if (x > x1) {         x1++;         s[counter] +=  R ;       }       if (x < x1) {         x1--;         s[counter] +=  L ;       }       if (y > y1) {         y1++;         s[counter] +=  D ;       }       if (y < y1) {         y1--;         s[counter] +=  U ;       }       counter++;     }     cout << counter << endl;     for (int i = 0; i < counter; i++) {       cout << s[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int INF = 1e8 + 7;   int n;   int Min[N][20], Max[N][20];   struct Node {     int x, y;     bool operator<(const Node& p) const { return x < p.x; }   } nod[N];   long long sqr(long long x) { return x * x; }   void rmq() {     for (int i = 0; i < n; ++i) {       Min[i][0] = nod[i].y;       Max[i][0] = nod[i].y;     }     for (int j = 1; (1 << j) <= n; ++j)       for (int i = 0; i + (1 << j) - 1 < n; ++i) {         Min[i][j] = min(Min[i][j - 1], Min[i + (1 << (j - 1))][j - 1]);         Max[i][j] = max(Max[i][j - 1], Max[i + (1 << (j - 1))][j - 1]);       }   }   int query(int t, int l, int r) {     if (l > r) return (1 - (t << 1)) * INF;     int k = (int)log2(r - l + 1.0);     switch (t) {       case 0:         return min(Min[l][k], Min[r - (1 << k) + 1][k]);       case 1:         return max(Max[l][k], Max[r - (1 << k) + 1][k]);     }     return 0;   }   bool isok(long long D, long long x, long long ymin, long long ymax) {     if (x > D) return false;     if (ymin != -INF && x + sqr(ymin) > D) return false;     if (ymax != INF && x + sqr(ymax) > D) return false;     if (ymin != -INF && ymax != INF && sqr(ymax - ymin) > D) return false;     return true;   }   bool check(long long D) {     if (sqr(nod[n - 1].x - nod[0].x) <= D) return true;     if (sqr(query(1, 0, n - 1) - query(0, 0, n - 1)) <= D) return true;     int l = 0, r = n - 1, ymin, ymax;     r = 0;     for (int i = 0; i < n; ++i) {       if (r < i) r = i;       while (r + 1 < n && abs(nod[r + 1].x) <= abs(nod[i].x) &&              sqr(nod[r + 1].x - nod[i].x) <= D)         ++r;       while (abs(nod[r].x) > abs(nod[i].x)) --r;       l = i;       ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1));       ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1));       long long x = sqr(nod[l].x);       if (isok(D, x, ymin, ymax)) return true;     }     l = 0, r = n - 1;     l = n - 1;     for (int i = n - 1; i >= 0; --i) {       if (l > i) l = i;       while (l - 1 >= 0 && abs(nod[l - 1].x) <= abs(nod[i].x) &&              sqr(nod[l - 1].x - nod[i].x) <= D)         --l;       while (abs(nod[l].x) > abs(nod[i].x)) ++l;       r = i;       ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1));       ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1));       long long x = max(sqr(nod[l].x), sqr(nod[r].x)),                 y = max(sqr(ymin), sqr(ymax));       if (isok(D, x, ymin, ymax)) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &nod[i].x, &nod[i].y);     }     sort(nod, nod + n);     rmq();     long long L = 0, R = sqr(nod[n - 1].x - nod[0].x);     while (L + 1 < R) {       long long M = (L + R) >> 1;       check(M) ? R = M : L = M;     }     long long ans = check(L) ? L : R;     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   int m, n, h;   int t[maxn];   int first[maxn * 2], nxt[maxn * 2], des[maxn * 2], tot;   int dfn[maxn], low[maxn], dft;   bool d[maxn];   int flag[maxn], cnt[maxn], scc;   stack<int> stk;   inline void add(int x, int y) {     tot++;     des[tot] = y;     nxt[tot] = first[x];     first[x] = tot;   }   void tar(int node) {     dfn[node] = low[node] = ++dft;     stk.push(node);     for (int t = first[node]; t; t = nxt[t]) {       int v = des[t];       if (!dfn[v]) tar(v);       low[node] = min(low[node], low[v]);     }     if (dfn[node] == low[node]) {       scc++;       while (true) {         int temp = stk.top();         flag[temp] = scc;         cnt[scc]++;         stk.pop();         if (temp == node) break;       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &h);     for (int i = 1; i <= n; i++) {       scanf( %d , t + i);     }     for (int i = 0; i < m; i++) {       int u1, u2;       scanf( %d%d , &u1, &u2);       if (t[u1] == (t[u2] + 1) % h) add(u2, u1);       if (t[u2] == (t[u1] + 1) % h) add(u1, u2);     }     for (int i = 1; i <= n; i++) {       if (!dfn[i]) tar(i);     }     for (int i = 1; i <= n; i++) {       for (int t = first[i]; t; t = nxt[t]) {         if (flag[i] == flag[des[t]])           continue;         else {           d[flag[i]]++;         }       }     }     cnt[0] = n + 1;     int ans = 0;     for (int i = 1; i <= scc; i++) {       if (d[i] == 0 && cnt[i] < cnt[ans]) {         ans = i;       }     }     cout << cnt[ans] << endl;     for (int i = 1; i <= n; i++) {       if (flag[i] == ans) {         cout << i <<    ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, n, i, l, r, mid, res;     scanf( %lld , &T);     while (T--) {       scanf( %lld , &n);       l = 2;       r = n - 1;       res = n - 1;       while (l <= r) {         mid = (l + r) >> 1;         if (mid * (mid - 1) / 2 + (n - mid) <= 2 * (n - mid))           l = mid + 1;         else           r = mid - 1;       }       res = max(res, min(l * (l - 1) / 2 + (n - l), 2 * (n - l)));       res = max(res, min((l - 1) * (l - 2) / 2 + (n - l + 1), 2 * (n - l + 1)));       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<  ,  ;     err(++it, args...);   }   void solve() {     int n, m;     cin >> n >> m;     vector<int> l(m), r(m);     for (int i = 0; i < m; ++i) {       cin >> l[i] >> r[i];     }     for (int i = 0; i < n; ++i) cout << (i & 1);     cout << endl;   }   int main(int argc, char* argv[]) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char c = getchar();     if (c <  0  && c >  9  && c !=  - ) c = getchar();     long long f = 1, cnt = 0;     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) {       cnt = cnt * 10 + int(c -  0 );       c = getchar();     }     return cnt * f;   }   const int MOD = 1e9 + 9;   struct Loc {     Loc(int a, int b) {       x = a;       y = b;     }     int x;     int y;     bool operator<(const Loc &a) const {       if (y == a.y) {         return x < a.x;       }       return y < a.y;     }   };   map<Loc, int> table;   bool vis[100005];   priority_queue<int> q1;   priority_queue<int, vector<int>, greater<int> > q2;   long long result = 0;   void add(int a, int m) { result = (result * m + a) % MOD; }   int xPos[100005];   int yPos[100005];   bool judge(int x, int y) {     if (table.find(Loc(x, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x + 1, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x - 1, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x - 2, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x + 1, y + 1)) != table.end()) {       if (table.find(Loc(x + 1, y)) == table.end() &&           table.find(Loc(x + 2, y)) == table.end()) {         return false;       }     }     return true;   }   int main() {     int m;     int x, y;     m = read();     for (int i = 0; i < m; i++) {       cin >> x >> y;       xPos[i] = x;       yPos[i] = y;       table[Loc(x, y)] = i;     }     for (int i = 0; i < m; i++) {       if (judge(xPos[i], yPos[i])) {         q1.push(i);         q2.push(i);       }     }     memset(vis, false, sizeof(vis));     int top = 0;     int count = 0;     while (count < m) {       if ((count & 1) == 0) {         top = q1.top();       } else {         top = q2.top();       }       x = xPos[top];       y = yPos[top];       bool found = false;       if (!vis[top] && judge(x, y)) {         add(top, m);         table.erase(Loc(x, y));         vis[top] = true;         found = true;       }       if ((count & 1) == 0) {         q1.pop();       } else {         q2.pop();       }       if (found) {         count++;         if (table.find(Loc(x, y - 1)) != table.end() && judge(x, y - 1)) {           q1.push(table[Loc(x, y - 1)]);           q2.push(table[Loc(x, y - 1)]);         }         if (table.find(Loc(x - 1, y - 1)) != table.end() && judge(x - 1, y - 1)) {           q1.push(table[Loc(x - 1, y - 1)]);           q2.push(table[Loc(x - 1, y - 1)]);         }         if (table.find(Loc(x + 1, y - 1)) != table.end() && judge(x + 1, y - 1)) {           q1.push(table[Loc(x + 1, y - 1)]);           q2.push(table[Loc(x + 1, y - 1)]);         }       }     }     printf( %d , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long q;     cin >> q;     while (q--) {       long long n, m;       cin >> n;       cin >> m;       if (m > n || m % 10 == 0) {         cout << 0 <<   n ;         continue;       }       long long p = (n / m) / 10;       long long q = (n / m) % 10;       long long sum = 0;       if (m % 2 == 0)         sum = p * (40LL);       else if (m % 5 == 0)         sum = p * (25LL);       else         sum = p * (45LL);       long long num = 0;       for (long long i = 1; i <= q; i++) {         num += m;         sum += (num % 10);       }       cout << sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:65777216 )   using namespace std;   long long n, l, r, ql, qr, sum, ans, w[100005];   long long koll, kolr, t;   using namespace std;   int main() {     cin >> n >> l >> r >> ql >> qr;     for (int i = 1; i <= n; i++) {       cin >> w[i];       sum += w[i] * r;     }     ans = sum + qr * (n - 1);     for (int i = 1; i <= n; i++) {       sum += w[i] * l - w[i] * r;       koll = i;       kolr = n - i;       if (koll > kolr) {         ans = min(sum + (koll - kolr - 1) * ql, ans);       } else if (koll < kolr) {         ans = min(sum + (kolr - koll - 1) * qr, ans);       } else if (koll == kolr) {         ans = min(sum, ans);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   template <typename T>   inline T sqr(T n) {     return n * n;   }   int C, Hr, Hb, Wr, Wb;   long long ans;   int main() {     scanf( %d%d%d%d%d , &C, &Hr, &Hb, &Wr, &Wb);     for (int x = 0; x < 10000000 && 1ll * x * Wr <= C; x++) {       int y = (C - x * Wr) / Wb;       ans = max(ans, 1ll * Hr * x + 1ll * Hb * y);     }     for (int y = 0; y < 10000000 && 1ll * y * Wb <= C; y++) {       int x = (C - y * Wb) / Wr;       ans = max(ans, 1ll * Hr * x + 1ll * Hb * y);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << (n <= 2  ? n              : n % 2 ? (long long)n * (n - 1) * (n - 2)              : n % 3 ? (long long)n * (n - 1) * (n - 3)                      : (long long)(n - 1) * (n - 2) * (n - 3))          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   const int maxn = 1e5 + 10, N = 3e6, SQ = 1000, base = 800287, mod = 1e9 + 7,             INF = 1e9 + 10, lg = 22;   const long double eps = 1e-4;   int n, m, q;   unordered_map<int, int> par[maxn], res[maxn];   inline int root(int v, int x) {     return (par[v][x] <= 0 ? v : par[v][x] = root(par[v][x], x));   }   void merge(int v, int u, int x) {     if ((v = root(v, x)) == (u = root(u, x))) {       return;     }     par[u][x] = v;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int x, y, z;       cin >> x >> y >> z;       merge(x, y, z);     }     cin >> q;     while (q--) {       int v, u;       cin >> v >> u;       int ans = 0;       if ((int)par[v].size() < (int)par[u].size()) {         swap(v, u);       }       if (res[v].find(u) != res[v].end()) {         cout << res[v][u] <<   n ;         continue;       }       for (auto i : par[u]) {         if (par[v].find(i.first) == par[v].end()) {           continue;         }         if (root(v, i.first) == root(u, i.first)) {           ans++;         }       }       res[v][u] = res[u][v] = ans;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     long long int c = power(a, b >> 1);     c = (c * c) % 1000000007;     if (b & 1) return (a * c) % 1000000007;     return c;   }   const int N = (int)1e5 + 5;   const int Q = 301;   int dp[N][10], num[N][10];   string query[N];   string s, temp;   void solve() {     cin >> s;     int q, p;     cin >> q;     for (int i = 0; i <= q - 1; i++) {       cin >> temp;       query[i] = temp;     }     for (int i = 0; i <= 9; i++) {       dp[q][i] = i;       num[q][i] = 1;     }     for (int i = q - 1; i >= 0; i--) {       for (int j = 0; j <= 9; j++) {         dp[i][j] = dp[i + 1][j];         num[i][j] = num[i + 1][j];       }       p = query[i][0] -  0 ;       temp = query[i].substr(3, query[i].size() - 3);       long long int pos = 0;       dp[i][p] = 0;       for (int k = temp.size() - 1; k >= 0; k--) {         dp[i][p] += (dp[i + 1][temp[k] -  0 ] * power(10, pos)) % 1000000007;         if (dp[i][p] >= 1000000007) dp[i][p] -= 1000000007;         pos += num[i][temp[k] -  0 ];         pos %= (1000000007 - 1);       }       num[i][p] = pos;     }     int ans = 0;     int pos = 0;     for (int i = s.size() - 1; i >= 0; i--) {       ans += (dp[0][s[i] -  0 ] * power(10, pos)) % 1000000007;       if (ans >= 1000000007) ans -= 1000000007;       pos += num[0][s[i] -  0 ];       pos %= (1000000007 - 1);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     for (int TC = 1; TC <= T; TC++) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int BITS = 60;   struct tree_node {     int child[2] = {-1, -1};     bool full = false;   };   struct tree {     vector<tree_node> nodes = {tree_node()};     int get_or_create_node(int &node) {       int answer = node;       if (node < 0) {         answer = node = nodes.size();         nodes.emplace_back();       }       return answer;     }     void recursive_add(int node, int bit, long long prefix, long long start,                        long long end) {       long long after = prefix + (1LL << bit);       if (start <= prefix && after <= end) {         nodes[node].full = true;         return;       }       if (bit <= 0) return;       long long mid = (prefix + after) / 2;       if (start < mid)         recursive_add(get_or_create_node(nodes[node].child[0]), bit - 1, prefix,                       start, end);       if (end > mid)         recursive_add(get_or_create_node(nodes[node].child[1]), bit - 1, mid,                       start, end);     }     void add_range(long long L, long long R) { recursive_add(0, BITS, 0, L, R); }   };   tree a_tree, b_tree;   vector<pair<int, int>> options[BITS + 1];   long long dfs_sum(int bit, long long prefix) {     for (pair<int, int> &p : options[bit])       if (a_tree.nodes[p.first].full || b_tree.nodes[p.second].full) {         long long count = 1LL << bit;         long long prefix_sum = (prefix % MOD) * (count % MOD);         long long bit_sum = (count / 2 % MOD) * ((count - 1) % MOD);         return (prefix_sum + bit_sum) % MOD;       }     if (bit <= 0) return 0;     long long sum = 0;     for (int next = 0; next < 2; next++) {       options[bit - 1].clear();       for (pair<int, int> &p : options[bit])         for (int left = 0; left < 2; left++) {           int right = left ^ next;           int a_child = a_tree.nodes[p.first].child[left];           int b_child = b_tree.nodes[p.second].child[right];           if (a_child >= 0 && b_child >= 0)             options[bit - 1].emplace_back(a_child, b_child);         }       if (!options[bit - 1].empty()) {         long long add = (long long)next << (bit - 1);         sum = (sum + dfs_sum(bit - 1, prefix + add)) % MOD;       }     }     return sum;   }   int main() {     int A, B;     cin >> A;     for (int i = 0; i < A; i++) {       long long L, R;       cin >> L >> R;       R++;       a_tree.add_range(L, R);     }     cin >> B;     for (int i = 0; i < B; i++) {       long long L, R;       cin >> L >> R;       R++;       b_tree.add_range(L, R);     }     options[BITS].emplace_back(0, 0);     cout << dfs_sum(BITS, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t, n, i, j, x;     int n1, n2;     int a, b, p, q;     cin >> t;     for (i = 0; i < t; i++) {       cin >> n;       n1 = 0, n2 = 0;       vector<int> v, v1, v2;       vector<int> even, odd;       for (j = 0; j < n; j++) {         cin >> x;         if (x % 2) {           n1++;           odd.push_back(j);         } else {           n2++;           even.push_back(j);         }         v.push_back(x);         v1.push_back(x);         v2.push_back(x);       }       long long max1 = 0, max2 = 0, max_total;       int k, temp;       a = 0, b = 0;       if (n % 2) {         if (abs(n1 - n2) != 1) {           cout <<  -1 n ;         } else {           if (n1 < n2) {             for (k = 0; k < n; k++) {               if (k % 2) {                 while (a < n && !(v1[a] % 2)) {                   a++;                 }                 max1 += abs(a - k);                 if (a != k) {                   temp = v1[a];                   v1[a] = v1[k];                   v1[k] = temp;                 }                 a++;               } else {                 while (b < n && v1[b] % 2) {                   b++;                 }                 max1 += abs(b - k);                 if (b != k) {                   temp = v1[b];                   v1[b] = v1[k];                   v1[k] = temp;                 }                 b++;               }             }             cout << max1 <<   n ;           } else {             for (k = 0; k < n; k++) {               if (!(k % 2)) {                 while (a < n && !(v2[a] % 2)) {                   a++;                 }                 max2 += abs(a - k);                 if (a != k) {                   temp = v2[a];                   v2[a] = v2[k];                   v2[k] = temp;                 }                 a++;               } else {                 while (b < n && v2[b] % 2) {                   b++;                 }                 max2 += abs(b - k);                 if (b != k) {                   temp = v2[b];                   v2[b] = v2[k];                   v2[k] = temp;                 }                 b++;               }             }             cout << max2 <<   n ;           }         }       } else {         if (n1 != n2) {           cout <<  -1 n ;         } else {           a = 0, b = 0;           for (k = 0; k < n; k++) {             if (k % 2) {               while (a < n && !(v1[a] % 2)) {                 a++;               }               max1 += abs(a - k);               if (a != k) {                 temp = v1[a];                 v1[a] = v1[k];                 v1[k] = temp;               }               a++;             } else {               while (b < n && v1[b] % 2) {                 b++;               }               max1 += abs(b - k);               if (b != k) {                 temp = v1[b];                 v1[b] = v1[k];                 v1[k] = temp;               }               b++;             }           }           a = 0, b = 0;           for (k = 0; k < n; k++) {             if (!(k % 2)) {               while (a < n && !(v2[a] % 2)) {                 a++;               }               max2 += abs(a - k);               if (a != k) {                 temp = v2[a];                 v2[a] = v2[k];                 v2[k] = temp;               }               a++;             } else {               while (b < n && v2[b] % 2) {                 b++;               }               max2 += abs(b - k);               if (b != k) {                 temp = v2[b];                 v2[b] = v2[k];                 v2[k] = temp;               }               b++;             }           }           cout << min(max1, max2) <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx4[] = {0, 0, -1, 1};   long long dy4[] = {-1, 1, 0, 0};   long long n, m;   long long V[5003];   long long cnt[5003];   long long dis(long long x, long long y) {     if (y > x)       return y - x;     else {       return y + n - x;     }   }   long long res[5003];   int main() {     long long i, j;     scanf( %lld%lld , &n, &m);     for (i = 1; i <= n; i++) V[i] = LLONG_MAX;     for (i = 1; i <= m; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       V[x] = min(dis(x, y), V[x]);       cnt[x]++;     }     long long Mx = 0;     for (i = 1; i <= n; i++) {       long long d = cnt[i];       Mx = max(Mx, d);     }     long long tot = (Mx - 1) * n;     long long extra = n, extra1 = n;     for (i = 1; i <= n; i++) {       if (i - 1) printf(   );       long long Mn = 0;       for (j = 1; j <= n; j++) {         if (cnt[j] == Mx) {           long long f = extra + j - 1;           f %= n;           long long ex1 = f + V[j];           Mn = max(Mn, ex1);         } else if (cnt[j] == Mx - 1 && Mx - 1 != 0) {           long long f = extra1 - j + 1;           f %= n;           if (f == 0) f = n;           long long ex1 = V[j] - f;           Mn = max(Mn, ex1);         }       }       extra--;       extra1++;       printf( %lld , tot + Mn);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using u32 = unsigned;   using u64 = unsigned long long;   int lg_ceil(u64 n) { return 63 - __builtin_clzll(2 * n - 1); }   int lg_floor(u32 n) { return 31 - __builtin_clz(n); }   template <class T>   struct sparse_table {     sparse_table() {}     sparse_table(std::vector<T>& V, std::function<T(T, T)> f)         : M(lg_ceil(V.size()), V), F(f) {       for (size_t i = 0; i + 1 < M.size(); i++) {         for (size_t j = 0; j + (1 << i) < M[i].size(); j++) {           M[i + 1][j] = F(M[i][j], M[i][j + (1 << i)]);         }       }     }     T query(int l, int r) {       int k = lg_floor(r - l);       return F(M[k][l], M[k][r - (1 << k)]);     }     std::vector<std::vector<T>> M;     std::function<T(T, T)> F;   };   template <class T>   struct mmax {     T operator()(const T& a, const T& b) { return std::max(a, b); }   };   template <class T>   struct mmin {     T operator()(const T& a, const T& b) { return std::min(a, b); }   };   template <class T>   std::vector<T> read(int n) {     std::vector<T> res(n);     for (auto& r : res) {       std::cin >> r;     }     return res;   }   int main() {     std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);     int n;     std::cin >> n;     auto r = read<int>(n);     for (int i = 0; i < 2 * n; i++) {       r.push_back(r[i]);     }     if (n == 1) {       std::cout << 0 <<   n ;       return 0;     }     int lg = lg_ceil(n);     std::vector<std::vector<int>> ll(lg + 1, std::vector<int>(3 * n));     std::vector<std::vector<int>> rr(lg + 1, std::vector<int>(3 * n));     for (int i = 0; i < 3 * n; i++) {       ll[0][i] = std::max(i - r[i], 0);       rr[0][i] = std::min(i + r[i] + 1, 3 * n);     }     for (int j = 1; j <= lg; j++) {       sparse_table<int> lo(ll[j - 1], mmin<int>());       sparse_table<int> hi(rr[j - 1], mmax<int>());       for (int i = 0; i < 3 * n; i++) {         ll[j][i] = lo.query(ll[j - 1][i], rr[j - 1][i]);         rr[j][i] = hi.query(ll[j - 1][i], rr[j - 1][i]);       }     }     std::vector<int> left(n), right(n), sum(n), ans(n);     std::iota(begin(left), end(left), n);     std::iota(begin(right), end(right), n + 1);     for (int j = lg; j >= 0; j--) {       sparse_table<int> lo(ll[j], mmin<int>());       sparse_table<int> hi(rr[j], mmax<int>());       for (int i = 0; i < n; i++) {         int nl = lo.query(left[i], right[i]);         int nr = hi.query(left[i], right[i]);         if (nr - nl < n) {           left[i] = nl, right[i] = nr;           sum[i] += 1 << j;         } else {           ans[i] = sum[i] + (1 << j);         }       }     }     for (int a : ans) {       std::cout << a <<    ;     }     std::cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], b[n];     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     int ans = 0;     for (int i = 0; i < n; ++i) {       int x = a[i], y = b[i];       ans = max(ans, x + y);       for (int j = i + 1; j < n; ++j) {         x |= a[j];         y |= b[j];         ans = max(ans, x + y);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010, P = 1000000007;   int n, q, a[maxn], b[maxn], w[maxn];   __int128 c1[maxn], c2[maxn];   void add(__int128 *c, int p, __int128 v) {     for (; p <= n; p += p & -p) c[p] += v;   }   __int128 sum(__int128 *c, int p) {     __int128 s = 0;     for (; p; p -= p & -p) s += c[p];     return s;   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]), b[i] = i - a[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);       add(c1, i, w[i]), add(c2, i, 1LL * b[i] * w[i]);     }     while (q--) {       int x, y;       scanf( %d %d , &x, &y);       if (x < 0) {         x *= -1, add(c1, x, -w[x]), add(c2, x, -1LL * b[x] * w[x]);         w[x] = y;         add(c1, x, w[x]), add(c2, x, 1LL * b[x] * w[x]);       } else {         auto chk = [&](int st) {           int l = x, r = y, p = x - 1;           while (l <= r) {             int mid = (l + r) >> 1;             if (a[mid] <= st + mid - x)               l = (p = mid) + 1;             else               r = mid - 1;           }           __int128 s = (st - x) * (sum(c1, p) - sum(c1, x - 1)) + sum(c2, p) -                        sum(c2, x - 1);           s -= (st - x) * (sum(c1, y) - sum(c1, p)) + sum(c2, y) - sum(c2, p);           return s;         };         int l0 = 1, r0 = 1000000000, ans;         while (l0 <= r0) {           int mid = (l0 + r0) >> 1;           auto t1 = chk(mid), t2 = chk(mid + 1);           if (t1 <= t2)             ans = t1 % P, r0 = mid - 1;           else             l0 = mid + 1;         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int len = 0, k = 0, a[100005], p, q;   void findlength(long long int n, long long int mul) {     if (n < 2) return;     if (n % 2 == 0) {       len += mul;     }     findlength(n / 2, 2 * mul);   }   void findans(long long int n, long long int l, long long int r) {     if (n < 2) return;     if (n % 2 == 0) {       a[k] = (l + r) / 2;       k++;     }     if (p > (l + r) / 2 - 1 || q < l) {     } else       findans(n / 2, l, (l + r) / 2 - 1);     if (p > r || q < (l + r) / 2 + 1) {     } else       findans(n / 2, (l + r) / 2 + 1, r);   }   int main() {     long long int n, l, r, i, left, right;     cin >> n >> l >> r;     l--;     r--;     p = l;     q = r;     findlength(n, 1);     len += n;     if (n == 0) len++;     findans(n, 0, len - 1);     sort(a, a + k);     left = 0;     while (left < k) {       if (l > a[left])         left++;       else         break;     }     if (left >= k) left--;     right = 0;     while (right < k) {       if (r > a[right])         right++;       else         break;     }     if (right >= k) right--;     if (a[right] > r) right--;     if (a[right] > r) right--;     if (len == n || r < l) {       cout << r - l + 1 << endl;     } else {       cout << (r - l + 1) - (right - left + 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   const int MAXN = 5 + 100000;   vector<int> g[MAXN], s;   bitset<MAXN> vis;   int k, pos[MAXN];   void dfs(int u) {     assert(int(g[u].size()) >= k);     vis[u] = true;     pos[u] = s.size();     s.push_back(u);     int minp = 1e6;     for (const int& v : g[u]) {       if (!vis[v]) {         dfs(v);         return;       }       minp = min(minp, pos[v]);     }     cout << int(s.size()) - minp <<   n ;     for (int i = minp; i < (int)s.size(); ++i) {       cout << 1 + s[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m >> k;     while (m--) {       int u, v;       cin >> u >> v;       g[--u].push_back(--v);       g[v].push_back(u);     }     vis.reset();     s.reserve(1 + k);     dfs(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const int N = 1e6 + 6;   struct segt {     vector<int> t;     int d;     segt(vector<int> &a) {       int n = a.size();       for (d = 2; d < n; d <<= 1)         ;       t.assign(d * 2, 0);       for (int i = 0; i < n; ++i) t[i + d] = a[i];       for (int i = d - 1; i; --i) t[i] = min(t[i * 2], t[i * 2 + 1]);     }     int rmq(int i, int j) {       int res = 1e9;       for (i += d, j += d; i <= j; ++i >>= 1, --j >>= 1) {         if (i & 1) res = min(res, t[i]);         if (~j & 1) res = min(res, t[j]);       }       return res;     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n;     vector<pair<int, int>> s;     set<int> u;     for (int i = 0; i < n; ++i) {       int l, r;       cin >> l >> r;       s.push_back({l, r});       u.insert(l);       u.insert(r);       u.insert(r + 1);     }     vector<int> t((u).begin(), (u).end());     vector<int> f(t.size());     for (auto p : s) {       int l = p.first;       int r = p.second;       f[lower_bound((t).begin(), (t).end(), l) - t.begin()]++;       f[lower_bound((t).begin(), (t).end(), r + 1) - t.begin()]--;     }     for (int i = 1; i < f.size(); ++i) f[i] += f[i - 1];     segt q(f);     for (int k = 0; k < n; ++k) {       int l = s[k].first;       int r = s[k].second;       int i = lower_bound((t).begin(), (t).end(), l) - t.begin();       int j = lower_bound((t).begin(), (t).end(), r) - t.begin();       if (q.rmq(i, j) != 1) {         cout << k + 1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     long long l;     cin >> a >> b >> c >> l;     long long ans = (l + 1) * (l + 3) * (l + 2) / 6;     for (long long k = 0; k <= l; k++) {       if (a + k >= b + c) {         long long j = min(k, (a - b - c + k) / 2);         ans = ans - (j + 1) * (j + 2) / 2;       }       if (b + k >= a + c) {         long long j = min(k, (b - a - c + k) / 2);         ans = ans - (j + 1) * (j + 2) / 2;       }       if (c + k >= b + a) {         long long j = min(k, (c - b - a + k) / 2);         ans = ans - (j + 1) * (j + 2) / 2;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int spf[100000 + 1];   long long int const MAXN = 100001;   long long int modex(long long int x, long long int y, long long int p);   void getZarr(string str, long long int Z[]);   void sieve();   vector<long long int> getFactorization(long long int x);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int a, b;     cin >> a >> b;     for (long long int x = 1; x < a; x++) {       long long int temp = sqrt(a * a - x * x);       if (temp * temp == a * a - x * x) {         if ((b * x) % a == 0 && (b * temp) % a == 0) {           if (x == -(b * temp) / a || temp == (b * x) / a) continue;           cout <<  YES  <<   n ;           cout << 0 <<     << 0 <<   n ;           cout << x <<     << temp <<   n ;           cout << -(b * temp) / a <<     << (b * x) / a <<   n ;           return 0;         }       }     }     cout <<  NO  <<   n ;   }   void getZarr(string str, long long int Z[]) {     Z[0] = 0;     long long int n = str.length();     long long int L, R, k;     L = R = 0;     for (long long int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && str[R - L] == str[R]) R++;         Z[i] = R - L;         R--;       } else {         k = i - L;         if (Z[k] < R - i + 1)           Z[i] = Z[k];         else {           L = i;           while (R < n && str[R - L] == str[R]) R++;           Z[i] = R - L;           R--;         }       }     }   }   long long int modex(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void sieve() {     spf[1] = 1;     for (int i = 2; i < MAXN; i++) spf[i] = i;     for (int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (int i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (int j = i * i; j < MAXN; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   vector<long long int> getFactorization(long long int x) {     vector<long long int> ret;     while (x != 1) {       ret.push_back(spf[x]);       x = x / spf[x];     }     return ret;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> starts(m), ends(m), results;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       starts[l - 1]++;       ends[r - 1]++;     }     int open = 0;     for (int i = 0; i < m; i++) {       open += starts[i];       if (open == 0) results.push_back(i + 1);       open -= ends[i];     }     std::cout << results.size() << std::endl;     for (auto p : results) cout << p <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a;   stack<int> q;   vector<int> d;   void insert(int x) {     if (q.empty()) {       q.push(x);       return;     }     if (q.top() != x) {       q.push(x);       return;     }     q.pop();     insert(x + 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a), insert(a);     while (!q.empty()) d.push_back(q.top()), q.pop();     int k = d.size();     printf( %d n , k);     for (int i = k - 1; i >= 0; i--) printf( %d%c , d[i], i ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _exit(string message) {     if (message !=   ) cout << message << endl;     exit(0);   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &V) {     if (!V.empty()) {       out <<  [ ;       for (auto v : V) out << v <<  ,  ;       out <<   b b] ;     } else       out <<  [] ;     return out;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k, q = 998244353;     cin >> n >> k;     long long m = min(n + 1, k);     vector<vector<int> > T(n + 1, vector<int>(m, 0));     vector<vector<int> > PT(n + 1, vector<int>(m, 0));     for (int j = 1; j < m; j++) PT[0][j] = T[0][j] = 2;     T[1][1] = 2;     for (int j = 1; j < m; j++) PT[1][j] = 2;     for (int i = 2; i <= n; i++) PT[i][1] = T[i][1] = 2;     for (int i = 2; i <= n; i++) {       for (int j = 2; j < m; j++) {         T[i][j] = (2 * T[i - 1][j]) % q;         if (i >= j + 1) T[i][j] -= PT[i - 1 - j][j];         if (i >= j) T[i][j] += PT[i - j][j - 1];         if (T[i][j] < 0) T[i][j] += q;         if (T[i][j] >= q) T[i][j] = T[i][j] % q;         PT[i][j] = PT[i][j - 1] + T[i][j];         if (PT[i][j] >= q) PT[i][j] = PT[i][j] % q;       }     }     for (int j = 0; j < m; j++) PT[0][j] = T[0][j] = 0;     long long ans = 0;     for (int i = 1; i < m; i++)       ans +=           ((1ll * T[n][i] * PT[n][min(m - 1, (k - 1) / i)]) % q * (q + 1) / 2) %           q;     cout << ans % q << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int dp[303030][30];   int u, v;   int in[303030];   vector<int> adj[303030];   char s[303030];   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       --u;       --v;       adj[u].push_back(v);       in[v]++;     }     queue<int> q;     for (int i = 0; i < n; ++i) {       if (in[i] == 0) {         q.push(i);       }     }     int cnt = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       ++cnt;       dp[u][s[u] -  a ]++;       for (int v : adj[u]) {         if (--in[v] == 0) {           q.push(v);         }         for (int i = 0; i < 26; ++i) {           dp[v][i] = max(dp[v][i], dp[u][i]);         }       }     }     if (cnt == n) {       int ans = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < 26; ++j) {           ans = max(ans, dp[i][j]);         }       }       printf( %d n , ans);     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int N = 3e6 + 5;   int a[55][55], b[55][55], aa[55][55], bb[55][55];   int row(int x, int y) {     for (int i = 1; i <= x; i++) {       int k = 1;       for (int j = 2; j <= y; j++) {         if (a[i][j] > a[i][k]) {           k = j;         } else           return 0;       }     }     for (int i = 1; i <= x; i++) {       int k = 1;       for (int j = 2; j <= y; j++) {         if (b[i][j] > b[i][k]) {           k = j;         } else           return 0;       }     }     return 1;   }   int col(int x, int y) {     for (int i = 1; i <= y; i++) {       int k = 1;       for (int j = 2; j <= x; j++) {         if (a[j][i] > a[k][i]) {           k = j;         } else           return 0;       }     }     for (int i = 1; i <= y; i++) {       int k = 1;       for (int j = 2; j <= x; j++) {         if (b[j][i] > b[k][i]) {           k = j;         } else           return 0;       }     }     return 1;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> aa[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> bb[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         a[i][j] = min(aa[i][j], bb[i][j]);         b[i][j] = max(aa[i][j], bb[i][j]);       }     }     if (row(n, m) && col(n, m))       cout <<  Possible ;     else       cout <<  Impossible ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<long long> dd;   long long su;   long long revsum[100001];   struct tab {     long long l;     long long d;   } arr[100001];   long long findsumoftop(long long k) {     long long ans = 0;     multiset<long long>::iterator it = dd.begin();     while (k--) {       if (it == dd.end()) {         break;       } else {         ans += *it;         it++;       }     }     return -ans;   }   bool compare(const tab& t1, const tab& t2) { return t1.l < t2.l; }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; ++i) cin >> arr[i].l;     for (long long i = 0; i < n; ++i) cin >> arr[i].d;     sort(arr, arr + n, compare);     for (long long i = n - 1; i >= 0; --i) revsum[i] = arr[i].d + revsum[i + 1];     long long st = 0;     long long en = 1;     long long ma = 300000000;     while (st < n) {       if (arr[st].l == arr[en].l)         en++;       else {         long long matmp = (su - findsumoftop(en - st - 1) + revsum[en]);         for (long long i = st; i < en; ++i) dd.insert(-arr[i].d), su += arr[i].d;         ma = min(ma, matmp);         st = en;         en++;       }     }     cout << ma << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 550005;   const long long mod = 998244353;   int n, u, v;   vector<int> g[N];   long long dp[N][2][2];   inline long long bin(long long x, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = res * x % mod;       x = x * x % mod;       k >>= 1;     }     return res;   }   vector<long long> pre, su;   inline void dfs(int v, int p = 0) {     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) {         swap(g[v][i], g[v].back());         g[v].pop_back();         break;       }     }     for (int to : g[v]) {       dfs(to, v);     }     int sz = g[v].size();     pre.resize(sz, 0);     su.resize(sz, 0);     for (int i = 0; i < sz; ++i) {       int to = g[v][i];       pre[i] = (dp[to][1][0] + dp[to][0][0]) % mod;       if (i) pre[i] = pre[i - 1] * pre[i] % mod;     }     for (int i = sz - 1; i >= 0; --i) {       int to = g[v][i];       su[i] = (dp[to][0][0] + dp[to][1][0]) % mod;       if (i + 1 < sz) su[i] = su[i] * su[i + 1] % mod;     }     long long s = 1;     for (int to : g[v]) {       s = s * dp[to][1][0] % mod;     }     dp[v][0][0] = 0;     dp[v][0][1] = 1;     dp[v][1][0] = s;     dp[v][1][1] = 0;     for (int i = 0; i < sz; ++i) {       int to = g[v][i];       long long add = dp[to][0][1];       if (i - 1 >= 0) add = add * pre[i - 1] % mod;       if (i + 1 < sz) add = add * su[i + 1] % mod;       dp[v][0][0] += add;       dp[v][0][0] %= mod;     }     (dp[v][1][0] += dp[v][0][0]) %= mod;     for (int to : g[v]) {       dp[v][0][1] = dp[v][0][1] * (dp[to][1][0] + dp[to][0][0]) % mod;     }   }   vector<int> e[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n - 1; ++i) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int x = min(n, 3);     dfs(x);     cout << dp[x][1][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       if (n < 6) {         cout << 15 << endl;       } else if (n % 2 == 0) {         cout << n / 2 * 5 << endl;       } else {         n++;         cout << n / 2 * 5 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     string a[n];     a[0] = s;     for (int i = 1; i < n; i++) {       a[i] = a[i - 1][n - 1] + a[i - 1].substr(0, n - 1);     }     int dem = 0;     for (int i = 0; i < n; i++) {       if (a[i] !=  . ) {         dem++;         for (int j = i + 1; j < n; j++) {           if (a[j] == a[i]) {             a[j] =  . ;           }         }       }     }     cout << dem;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 1e4 + 5;   int n, k;   int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn];   int main() {     scanf( %d%d , &n, &k);     memset(dp1, -0x3f, sizeof(dp1));     memset(dp2, -0x3f, sizeof(dp2));     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= n; i++) {       c[i] = b[i] * k - a[i];     }     dp1[0] = dp2[0] = 0;     for (int i = 1; i <= n; i++) {       if (c[i] >= 0) {         for (int v = 10000; v >= c[i]; v--)           dp1[v] = max(dp1[v], dp1[v - c[i]] + a[i]);       } else {         for (int v = 10000; v >= -c[i]; v--)           dp2[v] = max(dp2[v], dp2[v + c[i]] + a[i]);       }     }     int ans = 0;     for (int i = 0; i <= 10000; i++) ans = max(ans, dp1[i] + dp2[i]);     if (ans)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res % mod;   }   const int N = 5e3 + 10;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int k;     cin >> k;     cout <<  2000 n ;     for (int i = 1; i <= 1998; ++i) cout <<  0  ;     int d = 1999 - k % 1999;     int x = (k + d) / 1999;     cout << -d <<     << x + d << endl;     return 0;   }


#include <bits/stdc++.h>   int dis[1048576];   std::vector<int> node[1048576], rnode[1048576];   int main() {     int n, m, s, t;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       node[u].push_back(v);       rnode[v].push_back(u);     }     scanf( %d%d , &s, &t);     memset(dis + 1, (int)0x7f7f7f7f, sizeof(int) * n);     dis[t] = 0;     std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,                         std::greater<std::pair<int, int> > >         pq;     pq.push(std::pair<int, int>(0, t));     while (!pq.empty()) {       const int u = pq.top().second, cu = pq.top().first;       pq.pop();       if (cu != dis[u]) continue;       for (auto v : rnode[u]) {         if (dis[v] <= dis[u]) continue;         int max = 0, min = dis[v];         for (auto k : node[v]) {           max = std::max(max, dis[k]);           min = std::min(min, dis[k]);         }         const int cv = std::min(max, min + 1);         if (cv < dis[v]) pq.push(std::pair<int, int>(dis[v] = cv, v));       }     }     printf( %d n , dis[s] == (int)0x7f7f7f7f ? -1 : dis[s]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long p = 1e9 + 7;   long long dp[N], dp1[N];   long long modexp(long long a, long long b, long long p) {     long long ans = 1LL;     a %= p;     while (b) {       if (b & 1) ans = ans * a % p;       b >>= 1;       a = a * a % p;     }     return ans;   }   int main() {     memset(dp, 0, sizeof(dp));     int n, k;     scanf( %d%d , &n, &k);     dp[0] = 1LL;     for (int i = 1; i <= k; i++) {       for (int j = 0; j < N; j++) {         if (j) {           dp1[j] += j * 1LL * dp[j];           dp1[j] %= p;         }         if (dp[j]) {           dp1[j + 1] += (n - j) * 1LL * dp[j];           dp1[j + 1] %= p;         }       }       for (int j = 0; j < N; j++) dp[j] = dp1[j];       memset(dp1, 0, sizeof(dp1));     }     long long ans = 0;     for (int i = 0; i <= min(n, N - 1); i++)       ans = (ans + dp[i] * modexp(2, n - i, p) % p) % p;     printf( %lld n , ans);     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); }   struct KMP {     int n, at;     string s;     vector<int> nxt;     vector<int> nxtdiff;     void init(int _n) {       n = _n, at = 0, s = string(n,  ? ), nxt = nxtdiff = vector<int>(n + 1, 0);     }     void add(char c) {       s[at++] = c;       int x = nxt[at - 1];       while (x != 0 && s[x] != c) x = nxt[x];       if (at >= 2 && s[x] == c) ++x;       nxt[at] = x;       nxtdiff[at - 1] = s[nxt[at - 1]] != c ? nxt[at - 1] : nxtdiff[nxt[at - 1]];     }   };   struct RMQ {     int n;     vector<int> val;     void init(int _n) {       n = _n;       val = vector<int>(4 * n, 0);     }     void _set(int x, int l, int r, int IDX, int VAL) {       if (l == r) {         val[x] = VAL;       } else {         int m = l + (r - l) / 2;         if (IDX <= m)           _set(2 * x + 1, l, m, IDX, VAL);         else           _set(2 * x + 2, m + 1, r, IDX, VAL);         val[x] = min(val[2 * x + 1], val[2 * x + 2]);       }     }     void set(int idx, int v) { _set(0, 0, n - 1, idx, v); }     int _get(int x, int l, int r, int L, int R) {       if (L <= l && r <= R) {         return val[x];       } else {         int m = l + (r - l) / 2, ret = INT_MAX;         if (L <= m) ret = min(ret, _get(2 * x + 1, l, m, L, R));         if (m + 1 <= R) ret = min(ret, _get(2 * x + 2, m + 1, r, L, R));         return ret;       }     }     int get(int l, int r) { return _get(0, 0, n - 1, l, r); }   };   const int BASE = 1000000000;   const int BASEDIGITS = 9;   struct BigInt {     vector<int> val;     BigInt() {}   };   void print(const BigInt &a) {     if (((int)(a.val).size()) == 0) {       printf( 0 );       return;     }     for (int i = ((int)(a.val).size()) - 1; i >= 0; --i) {       if (i == ((int)(a.val).size()) - 1)         printf( %d , a.val[i]);       else         printf( %0*d , BASEDIGITS, a.val[i]);     }   }   BigInt operator+(const BigInt &a, unsigned long long b) {     BigInt c = a;     for (int i = 0; b > 0; ++i) {       if (i >= ((int)(c.val).size())) c.val.push_back(0);       b += c.val[i];       c.val[i] = b % BASE;       b /= BASE;     }     return c;   }   BigInt operator+(const BigInt &a, const BigInt &b) {     BigInt c;     int carry = 0;     for (int i = 0;          i < ((int)(a.val).size()) || i < ((int)(b.val).size()) || carry > 0;          ++i) {       if (i < ((int)(a.val).size())) carry += a.val[i];       if (i < ((int)(b.val).size())) carry += b.val[i];       c.val.push_back(carry % BASE);       carry /= BASE;     }     return c;   }   BigInt operator-(const BigInt &a, unsigned long long b) {     BigInt c = a;     for (int i = 0; b > 0; ++i) {       assert(i < ((int)(c.val).size()));       int cur = b % BASE;       b /= BASE;       if (cur <= c.val[i])         c.val[i] -= cur;       else         c.val[i] += BASE - cur, ++b;     }     while (((int)(c.val).size()) > 0 && c.val.back() == 0) c.val.pop_back();     return c;   }   int operator%(const BigInt &a, int b) {     int ret = 0;     for (int i = ((int)(a.val).size()) - 1; i >= 0; --i)       ret = ((unsigned long long)ret * BASE + a.val[i]) % b;     return ret;   }   int operator&(const BigInt &a, int b) { return (a % (1 << 30)) & b; }   struct RelaxableSet {     BigInt sum;     map<int, int> cnt;     void init() {       sum = BigInt();       cnt = map<int, int>();     }     void relax(int lim) {       int rem = 0;       while (((int)(cnt).size()) > 0) {         auto it = prev(cnt.end());         if (it->first <= lim) break;         sum = sum - (unsigned long long)it->first * it->second, rem += it->second,         cnt.erase(it);       }       if (rem > 0) cnt[lim] += rem, sum = sum + (unsigned long long)lim * rem;     }     void remove(int val) {       auto it = cnt.find(val);       assert(it != cnt.end());       if (it->second == 1)         cnt.erase(it);       else         --it->second;       sum = sum - val;     }     void add(int val) {       ++cnt[val];       sum = sum + val;     }     void print() {       for (auto it = cnt.begin(); it != cnt.end(); ++it)         printf(  %d=%d , it->first, it->second);       puts(  );     }   };   const int MAXN = 600000;   const int MASK = (1 << 30) - 1;   int n;   char c[MAXN];   int w[MAXN];   BigInt ans[MAXN];   KMP kmp;   RMQ rmq;   RelaxableSet have;   void solve() {     kmp.init(n);     rmq.init(n);     have.init();     BigInt prv;     for (int i = (0); i < (n); ++i) {       char cc = (prv + (unsigned long long)(c[i] -  a )) % 26 +  a ;       int ww = w[i] ^ (prv & MASK);       kmp.add(cc);       int len = i;       while (len >= 1) {         if (kmp.s[len] != cc) {           int val = rmq.get(i - len, i - 1);           have.remove(val);           len = kmp.nxt[len];         } else {           len = kmp.nxtdiff[len];         }       }       rmq.set(i, ww);       have.relax(ww);       if (cc == kmp.s[0]) have.add(ww);       ans[i] = prv + have.sum;       prv = ans[i];     }   }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf(  %c%d , &c[i], &w[i]);     solve();     for (int i = (0); i < (n); ++i) print(ans[i]), puts(  );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int C = 20, A = 40;   int n, liq;   int dp[1 << C];   long long k[A];   int main() {     scanf(  %d %d , &n, &liq);     for (int i = 0; i < n; i++)       for (int j = 0, first; j < n; j++)         cin >> first, k[i] |= (long long)(first || i == j) << j;     for (int i = 1; i < (1 << max(0, n - C)); i++) {       int first = i;       for (int j = 0; j < C; j++)         if ((i >> j) & 1) first &= k[j + C] >> C;       if (first == i) dp[i] = __builtin_popcount(i);     }     for (int i = 1; i < (1 << max(0, n - C)); i++)       for (int j = 0; j < C; j++)         if ((i >> j) & 1) dp[i] = max(dp[i], dp[i ^ (1 << j)]);     int ans = 0;     for (int i = 0; i < (1 << min(C, n)); i++) {       int first = i, second = (1 << max(0, n - C)) - 1;       for (int j = 0; j < min(C, n); j++)         if ((i >> j) & 1) first &= k[j] & ((1 << C) - 1), second &= k[j] >> C;       if (first != i) continue;       ans = max(ans, __builtin_popcount(i) + dp[second]);     }     long double l = liq, a = ans;     cout << fixed << setprecision(7) << (l * l * (a - 1)) / 2 / a << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int64_t> A(8, 8);     vector<int64_t> A_high(8, 0);     vector<int64_t> B(8, 8);     vector<int64_t> B_high(8, 8);     int64_t amax = 8;     int64_t bmax = 8;     char k;     for (int64_t i = 0; i < 8; i++) {       for (int64_t j = 0; j < 8; j++) {         cin >> k;         if (k ==  B ) {           if (B_high[j] > i) {             B_high[j] = i;           }           B[j] = 7 - i;         } else if (k ==  W ) {           A_high[j] = i;           if (A[j] > i) {             A[j] = i;           }         }       }     }     for (int64_t i = 0; i < 8; i++) {       if (amax > A[i] && (B_high[i] > A[i])) {         amax = A[i];       }       if (bmax > B[i] && (A_high[i] < 7 - B[i])) {         bmax = B[i];       }     }     if (amax <= bmax) {       cout <<  A  << endl;     } else {       cout <<  B  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, int> mp;     int n, m;     cin >> n >> m;     int same = 0;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       mp[s] = 1;     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       if (mp[s]) same++;     }     n = n - same;     m = m - same;     if (same % 2 == 1)       n >= m ? cout <<  YES  : cout <<  NO ;     else       n > m ? cout <<  YES  : cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long fpow(long long b, long long x) {     long long res = 1;     while (x) {       if (x & 1) res = (res * b) % MOD;       b = (b * b) % MOD;       x >>= 1;     }     return res;   }   long long c(long long k, long long r) {     if (r < 0) return 0;     if (r == 0) return 1;     return c(k, r - 1) * (k - r + 1) % MOD * fpow(r, MOD - 2) % MOD;   }   int main() {     long long n, m, g;     cin >> n >> m >> g;     if (m == 1) {       if (n & 1) {         if (g)           cout << (n - 1) / 2 << endl;         else           cout << (n - 1) / 2 + 2 << endl;       } else {         if (g)           cout << n / 2 + 1 << endl;         else           cout << n / 2 << endl;       }       return 0;     }     if (m == 0) {       if (g == !(n & 1))         printf( 1 n );       else         printf( 0 n );       return 0;     }     if (n == 0) {       if (g)         printf( 0 n );       else         printf( 1 n );       return 0;     }     long long k = 1 + g;     long long C = c(n + m - k, m - 1);     long long ans = C;     for (k = k + 2; k <= n + 1; k += 2) {       C = C * (n - k + 2) % MOD * (n - k + 3) % MOD *           fpow(n + m - k + 2, MOD - 2) % MOD * fpow(n + m - k + 1, MOD - 2) % MOD;       ans = (ans + C) % MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T& a, const T& b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T& a, const T& b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   template <typename T>   class Grid {     struct Pos {       int i, j;       Pos(int i, int j) : i(i), j(j) {}     };     int H, W;     vector<vector<T>> G;     vector<int> di8 = {1, 1, 0, -1, -1, -1, 0, 1},                 dj8 = {0, 1, 1, 1, 0, -1, -1, -1};     vector<int> di4 = {1, 0, -1, 0}, dj4 = {0, 1, 0, -1};     vector<Pos> neighbor(int i, int j, const vector<int>& dis,                          const vector<int>& djs) const {       vector<Pos> res;       for (int k = 0; k < dis.size(); ++k) {         if (in(i + dis[k], j + djs[k])) res.emplace_back(i + dis[k], j + djs[k]);       }       return res;     }       public:     static bool in(int H, int W, int i, int j) {       return 0 <= i && i < H && 0 <= j && j < W;     }     Grid(int H, int W) : H(H), W(W) { G.resize(H, vector<T>(W)); }     Grid(int H, int W, T zero) : H(H), W(W) { G.resize(H, vector<T>(W, zero)); }     vector<T>& operator[](int i) { return G[i]; }     bool in(int i, int j) const { return (0 <= i && i < H && 0 <= j && j < W); }     vector<Pos> neighbor8(int i, int j) const { return neighbor(i, j, di8, dj8); }     vector<Pos> neighbor4(int i, int j) const { return neighbor(i, j, di4, dj4); }     int to1DIndex(int i, int j) { return i * W + j; }     Pos to2DIndex(int i) { return Pos(i / W, i % W); }     void scanFrom(istream& strm) {       for (int i = 0; i < (int)(H); ++i)         for (int j = 0; j < (int)(W); ++j) strm >> G[i][j];     }     void outputTo(ostream& strm) {       for (int i = 0; i < (int)(H); ++i) {         for (int j = 0; j < (int)(W); ++j) cout << G[i][j];         strm << endl;       }     }   };   template <typename T>   inline istream& operator>>(istream& strm, Grid<T>& g) {     g.scanFrom(strm);     return strm;   }   template <typename T>   inline ostream& operator<<(ostream& strm, Grid<T>& g) {     g.outputTo(strm);     return strm;   }   int n;   int X[1010][1010], Y[1010][1010];   char ans[1010][1010];   bool in(int i, int j) { return 0 <= i && i < n && 0 <= j && j < n; }   int di[4] = {1, 0, -1, 0};   int dj[4] = {0, 1, 0, -1};   int main() {     cin >> n;     for (int i = 0; i < (int)(n); ++i)       for (int j = 0; j < (int)(n); ++j) {         ans[i][j] =  ? ;         scanf( %d %d , &X[i][j], &Y[i][j]);         if (X[i][j] != -1) --X[i][j];         if (Y[i][j] != -1) --Y[i][j];       }     unordered_map<int, unordered_map<int, char>> dir;     dir[1][0] =  D ;     dir[-1][0] =  U ;     dir[0][1] =  R ;     dir[0][-1] =  L ;     function<void(int, int, int, int)> sink = [&](int i, int j, int x, int y) {       for (int k = 0; k < (int)(4); ++k) {         int ni = i + di[k], nj = j + dj[k];         if (!in(ni, nj)) continue;         if (ans[ni][nj] !=  ? ) continue;         if (X[ni][nj] != x || Y[ni][nj] != y) continue;         ans[ni][nj] = dir[i - ni][j - nj];         sink(ni, nj, x, y);       }     };     for (int i = 0; i < (int)(n); ++i)       for (int j = 0; j < (int)(n); ++j) {         if (ans[i][j] !=  ? ) continue;         if (X[i][j] == -1) {           for (int k = 0; k < (int)(4); ++k) {             int ni = i + di[k], nj = j + dj[k];             if (!in(ni, nj)) continue;             if (X[ni][nj] != -1) continue;             ans[i][j] = dir[ni - i][nj - j];             ans[ni][nj] = dir[i - ni][j - nj];             sink(i, j, -1, -1);             sink(ni, nj, -1, -1);           }         } else {           if (ans[X[i][j]][Y[i][j]] !=  ? ) break;           if (X[X[i][j]][Y[i][j]] != X[i][j] || Y[X[i][j]][Y[i][j]] != Y[i][j])             break;           ans[X[i][j]][Y[i][j]] =  X ;           sink(X[i][j], Y[i][j], X[i][j], Y[i][j]);         }       }     for (int i = 0; i < (int)(n); ++i)       for (int j = 0; j < (int)(n); ++j) {         if (ans[i][j] ==  ? ) {           cout <<  INVALID  << endl;           return 0;         }       }     cout <<  VALID  << endl;     for (int i = 0; i < (int)(n); ++i) {       for (int j = 0; j < (int)(n); ++j) cout << ans[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> vec_splitter(string s) {     for (char& c : s) c = c ==  ,  ?     : c;     stringstream ss;     ss << s;     vector<string> res;     for (string z; ss >> z; res.push_back(z))       ;     return res;   }   void debug_out(vector<string> args, int idx) { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, Head H, Tail... T) {     if (idx > 0) cerr <<  ,  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, T...);   }   void localTest() {}   const long long N = 2e5 + 5, MOD = 998244353;   long long A[N], fac[N], ifac[N];   long long power(long long a, long long b, long long c) {     long long ret = 1;     while (b) {       if (b & 1) {         ret = (ret * a) % c;       }       b >>= 1;       a = (a * a) % c;     }     return ret;   }   long long C(long long n, long long r) {     if (n < r) {       return 0;     }     long long ret = fac[n];     ret = (ret * ifac[r]) % MOD;     ret = (ret * ifac[n - r]) % MOD;     return ret;   }   int main() {     localTest();     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fac[0] = ifac[0] = 1;     for (long long i = 1; i < N; ++i) {       fac[i] = (i * fac[i - 1]) % MOD;       ifac[i] = power(fac[i], MOD - 2, MOD);     }     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= n; ++i) {       cin >> A[i];     }     if (k == 1) {       cout <<  0 n ;       return 0;     }     long long ans = power(k, n, MOD), val = 0, fixed = 0, move = n, sum = 0;     for (long long i = 1; i <= n; ++i) {       if (A[i] == A[i % n + 1]) {         fixed++;         move--;       }     }     val = power(k, fixed, MOD);     for (long long i = 0; i <= move / 2; ++i) {       long long mul = C(move, i) * C(move - i, i) % MOD;       mul = (mul * power(k - 2, move - 2 * i, MOD)) % MOD;       sum += mul;       sum %= MOD;     }     val = (val * sum) % MOD;     ans = (ans - val + MOD) % MOD;     ans = (ans * power(2, MOD - 2, MOD)) % MOD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,unroll-loops )   const long long int MAXN = 4e3 + 20, md = 1e9 + 7, inf = 5e18;   int dp[MAXN][100][100], a[MAXN], ps[MAXN], sp[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -63, sizeof(dp));     long long int n, sq;     cin >> n >> a[0];     ps[0] = a[0];     sq = ceil(sqrt(2 * n));     for (int i = 1; i < n; i++) {       cin >> a[i];       ps[i] = ps[i - 1] + a[i];     }     sp[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       sp[i] = sp[i + 1] + a[i];     }     if (n == 1) {       cout << a[0] <<   n ;       return 0;     }     if (n == 2) {       cout << a[0] + abs(a[1]) <<   n ;       return 0;     }     if (n == 3) {       int h = a[0] + a[1], q;       q = -a[2] - abs(a[1]);       cout << max(h, q + a[0]) <<   n ;       return 0;     }     for (int i = n / 2 - 1; i >= 0; i--) {       for (int k = 1; k <= sq; k++) {         for (int j = 0; j <= k; j++) {           int l = i, r = n - l - j - 1, h1, h2;           if (r <= l) break;           l += k;           r -= k;           if (r <= l) {             r += k;             if (l < r) {               h1 = ps[l] - sp[r];             } else {               l -= k;               dp[i][k][j] = ps[l] - sp[r];               continue;             }           } else {             h1 = dp[l][k][j];             r--;             if (l < r) {               h1 = min(h1, dp[l][k + 1][j + 1]);             }           }           l = i;           r = n - l - j - 1;           l += k + 1;           r -= k + 1;           if (r <= l) {             r += k + 1;             if (l < r) {               h2 = ps[l] - sp[r];             } else {               dp[i][k][j] = h1;               continue;             }           } else {             h2 = dp[l][k + 1][j];             r--;             if (l < r) {               h2 = min(h2, dp[l][k + 2][j + 1]);             }           }           dp[i][k][j] = max(h1, h2);         }       }     }     int h1 = min(dp[1][2][0], (dp[1][3][1] < -1e6 ? 500000000 : dp[1][3][1])),         h2 = min(dp[0][1][0], dp[0][2][1]);     cout << max(h1, h2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   pair<int, int> c1, c2, r1, r2;   int ans = 0;   long double dst(pair<int, int> a, pair<int, int> b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   int main() {     cout << setiosflags(ios::fixed) << setprecision(10);     cin >> c1.first >> c1.second >> r1.first >> r1.second;     cin >> c2.first >> c2.second >> r2.first >> r2.second;     long double D = dst(c1, c2);     if (D > r1.first * r1.first) {       if ((sqrt(D) >= r1.first + r2.second) || (sqrt(D) + r1.first <= r2.first))         ans++;     } else {       if ((sqrt(D) + r2.second <= r1.first) || (sqrt(D) + r1.first <= r2.first))         ans++;     }     if (D > r2.first * r2.first) {       if ((sqrt(D) >= r2.first + r1.second) || (sqrt(D) + r2.first <= r1.first))         ans++;     } else {       if ((sqrt(D) + r1.second <= r2.first) || (sqrt(D) + r2.first <= r1.first))         ans++;     }     if (D > r1.second * r1.second) {       if ((sqrt(D) >= r1.second + r2.second) || (sqrt(D) + r1.second <= r2.first))         ans++;     } else {       if ((sqrt(D) + r2.second <= r1.second) || (sqrt(D) + r1.second <= r2.first))         ans++;     }     if (D > r2.second * r2.second) {       if ((sqrt(D) >= r2.second + r1.second) || (sqrt(D) + r2.second <= r1.first))         ans++;     } else {       if ((sqrt(D) + r1.second <= r2.second) || (sqrt(D) + r2.second <= r1.first))         ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mx = 0;   string a, b;   string ba, bb;   int sum[123] = {};   void solve(int last) {     int cursum1[123];     int cursum2[123];     memcpy(cursum1, sum, sizeof sum);     memcpy(cursum2, sum, sizeof sum);     if (cursum1[last] == 0 || cursum2[(10 - last) % 10] == 0) {       int mn = min(cursum1[0], cursum2[0]);       if (mn == 0) return;       if (mn > mx) {         mx = mn;         sort(ba.begin(), ba.end(), greater<char>());         sort(bb.begin(), bb.end(), greater<char>());       }       return;     }     string na, nb;     string zero;     cursum1[last]--;     cursum2[(10 - last) % 10]--;     na += last +  0 ;     nb += ((10 - last) % 10) +  0 ;     int now = 1;     for (;;) {       bool fnd = false;       for (int put = 0; put <= 9; put++) {         int need = (9 - put) % 10;         if (cursum1[put] > 0 && cursum2[need] > 0) {           na += put +  0 ;           nb += need +  0 ;           cursum1[put]--;           cursum2[need]--;           fnd = true;           break;         }       }       if (fnd)         ++now;       else {         int mn = min(cursum1[0], cursum2[0]);         cursum1[0] -= mn;         cursum2[0] -= mn;         for (int i = 0; i < mn; i++) {           zero +=  0 ;         }         now += mn;         for (int put = 0; put <= 9; put++) {           for (int u = 0; u < cursum1[put]; u++) na += put +  0 ;         }         for (int put = 0; put <= 9; put++) {           for (int u = 0; u < cursum2[put]; u++) nb += put +  0 ;         }         break;       }     }     if (now > mx) {       mx = now;       reverse(na.begin(), na.end());       reverse(nb.begin(), nb.end());       ba = na + zero;       bb = nb + zero;     }   }   void solveAll(string& str) {     a = str;     memset(sum, 0, sizeof sum);     mx = 0;     for (int i = 0; i < a.size(); i++) sum[a[i] -  0 ]++;     ba = bb = a;     for (int last = 1; last <= 9; last++) {       solve(last);     }   }   int parse(const string& str) {     int ret = 0;     for (int i = 0; i < str.size(); i++) {       ret = ret * 10 + str[i] -  0 ;     }     return ret;   }   int count(int num) {     int ret = 0;     while (num) {       if (num % 10 == 0)         ++ret;       else         break;       num /= 10;     }     return ret;   }   void test() {     for (int i = 0; i < 1231; i++) {       string ran;       ran += (rand() % 9) + 1 +  0 ;       int len = rand() % 6;       ++len;       for (int u = 1; u < len; u++) {         ran += (rand() % 10) +  0 ;       }       solveAll(ran);       int mx1 = 0;       sort(ran.begin(), ran.end());       do {         string ran2 = ran;         sort(ran2.begin(), ran2.end());         do {           int num1 = parse(ran);           int num2 = parse(ran2);           num1 += num2;           int howmany = count(num1);           mx1 = max(mx1, howmany);         } while (next_permutation(ran2.begin(), ran2.end()));       } while (next_permutation(ran.begin(), ran.end()));       if (mx != mx1) {         cout << ran <<    wrong  << endl;         exit(0);       }     }     cout <<  OK  << endl;   }   int main() {     cin >> a;     solveAll(a);     cout << ba << endl << bb << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int l, r, k;       cin >> l >> r >> k;       if (k < l) {         cout << k << endl;       } else {         cout << (r / k + 1) * k << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010;   int n, m;   char a[maxn], b[maxn];   char s[maxn * 2], c[maxn * 3];   int z[maxn * 3];   int lcp[maxn];   int lcs[maxn];   void z_init(int len) {     int l = 1, r = 1;     z[1] = len;     for (int i = 2; i <= len; i++) {       if (i > r) {         l = i;         r = i;         while (r <= len && c[r - i + 1] == c[r]) r++;         z[i] = r - l;         r--;       } else {         int k = i - l + 1;         if (z[k] < r - i + 1)           z[i] = z[k];         else {           l = i;           while (r <= len && c[r - i + 1] == c[r]) r++;           z[i] = r - l;           r--;         }       }     }   }   void init() {     for (int i = 1; i <= m; i++) c[i] = s[i];     c[m + 1] =  # ;     for (int i = 1; i <= n; i++) c[m + 1 + i] = a[i];     c[n + m + 2] =   0 ;     z_init(n + m + 1);     for (int i = 1; i <= n; i++) lcp[i] = z[m + 1 + i];     for (int i = 1; i <= m; i++) c[i] = s[m + 1 - i];     c[m + 1] =  # ;     for (int i = 1; i <= n; i++) c[m + 1 + i] = b[n + 1 - i];     c[n + m + 2] =   0 ;     z_init(n + m + 1);     for (int i = 1; i <= n; i++) lcs[i] = z[m + 1 + n + 1 - i];   }   long long cnt[maxn * 2], sum[maxn * 2];   int lowbit(int x) { return x & (-x); }   void add(int v) {     int x = v;     while (x <= n) sum[x] += v, cnt[x]++, x += lowbit(x);   }   void sub(int v) {     int x = v;     while (x <= n) sum[x] -= v, cnt[x]--, x += lowbit(x);   }   long long get_sum(int x) {     long long res = 0;     while (x) res += sum[x], x -= lowbit(x);     return res;   }   long long get_cnt(int x) {     long long res = 0;     while (x) res += cnt[x], x -= lowbit(x);     return res;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s%s%s , a + 1, b + 1, s + 1);     init();     long long ans = 0;     for (int i = 1; i <= min(n, m - 1); i++) add(max(1, m - lcs[i]));     for (int i = 1, r; i <= n; i++) {       r = min(m - 1, lcp[i]);       ans += 1LL * (r + 1) * get_cnt(r) - get_sum(r);       sub(max(1, m - lcs[i]));       if (i + m - 1 <= n) add(max(1, m - lcs[i + m - 1]));     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     int n, k;     string s;     while (t--) {       cin >> n >> k >> s;       vector<int> A(n + 1);       for (int i = 0; i < (int)(n); i++) {         if (s[i] ==  1 ) {           A[max(0, i - k)]++;           A[min(n - 1, i + k) + 1]--;         }       }       for (int i = 0; i < (int)(n + 1); i++) {         if (i > 0) A[i] += A[i - 1];       }       int cnt = 0;       int i = 0;       while (i < n) {         if (A[i] == 0) {           cnt++;           i += k + 1;         } else           i++;       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double PI = 3.141592653589793238462643383279;   const double EPS = 1e-9;   const long long MOD = 1000000007;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   int n;   int a[100];   vector<pair<vector<int>, int> > v1, v2;   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)n; i++) scanf( %d , a + i);     for (int i = 0; i < (int)(1 << 15); i++) {       {         int pre = __builtin_popcount((a[0] ^ i) & ((1 << 15) - 1));         vector<int> tmp;         for (int k = 1; k < n; k++) {           int now = __builtin_popcount((a[k] ^ i) & ((1 << 15) - 1));           tmp.push_back(pre - now);           pre = now;         }         v1.push_back(pair<vector<int>, int>(tmp, i));         if (i == 3) {         }       }       {         int pre = __builtin_popcount((a[0] >> 15) ^ i);         vector<int> tmp2;         for (int k = 1; k < n; k++) {           int now = __builtin_popcount((a[k] >> 15) ^ i);           tmp2.push_back(now - pre);           pre = now;         }         v2.push_back(pair<vector<int>, int>(tmp2, i * (1 << 15)));       }     }     sort(v1.begin(), v1.end(),          [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) {            for (int i = 0; i < (int)n - 1; i++) {              if (l.first[i] < r.first[i]) return true;              if (l.first[i] > r.first[i]) return false;            }            return l.second < r.second;          });     sort(v2.begin(), v2.end(),          [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) {            for (int i = 0; i < (int)n - 1; i++) {              if (l.first[i] < r.first[i]) return true;              if (l.first[i] > r.first[i]) return false;            }            return l.second < r.second;          });     int pos = 0;     for (pair<vector<int>, int>& p : v1) {       while (pos < (int)v2.size()) {         pair<vector<int>, int>& q = v2[pos];         bool ok = true;         bool con = false;         for (int i = 0; i < (int)n - 1; i++) {           if (q.first[i] < p.first[i]) {             pos++;             ok = false;             con = true;             break;           }           if (q.first[i] > p.first[i]) {             ok = false;             break;           }         }         if (ok) {           printf( %d n , p.second + q.second);           return 0;         }         if (!con) break;       }     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, l, m, n, d, x = 0;     cin >> k;     cin >> l;     cin >> m;     cin >> n;     cin >> d;     int arr[] = {k, l, m, n};     for (int i = 1; i <= d; i++) {       for (int j = 0; j < 4; j++) {         if (i % arr[j] == 0) {           x++;           break;         }       }     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, input;     int count = 1;     int s = 3;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &input);       if (input == 10) {         if (s == 1) {           count++;         }         s = 0;       } else if (input == 1) {         if (s == 0) {           count++;         }         s = 1;       }     }     printf( %d , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     T = 1;     while (T--) {       string t, s, s1, s2;       cin >> t;       s = t;       int i, j, x, l, a = 0;       for (i = 0; i < t.length(); i++) {         if (t[i] ==  a ) a = i;       }       for (i = 0; i < t.length(); i++) {         if (t[i] ==  a ) {           t.erase(i, 1);           i--;         }       }       l = t.length();       s1 = t.substr(0, l / 2);       s2 = t.substr(l / 2, l - l / 2);       if (s1 == s2) {         for (i = 0, j = 0; j < s1.length();) {           if (s[i] !=  a ) {             i++;             j++;           } else             i++;         }         while (s[i] ==  a ) {           i++;         }         if (i > a) {           s1 = s.substr(0, i);           cout << s1 << endl;         } else           cout <<  :( n ;       } else {         cout <<  :( n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i = 2, c = 0, v = 1;     cin >> n;     int x = 5;     while (n - x > 0) {       n = n - x;       x = x * 2;       v = v * 2;     }     while (n - v >= 1) {       n = n - v;       c++;     }     if (c + 1 == 1) {       cout <<  Sheldon ;     }     if (c + 1 == 2) {       cout <<  Leonard ;     }     if (c + 1 == 3) {       cout <<  Penny ;     }     if (c + 1 == 4) {       cout <<  Rajesh ;     }     if (c + 1 == 5) {       cout <<  Howard ;     }   }