#include <bits/stdc++.h>   using namespace std;   int n, a[500 + 5];   long long ans = 1LL << 60;   void cal(int x) {     if (!x) return;     long long sum = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] % x == 0 || (a[i] / x >= x - 1 - a[i] % x))         sum += a[i] / x + bool(a[i] % x);       else         return;     }     ans = min(ans, sum);   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i * i <= a[1]; ++i)       cal(i), cal(a[1] / i), cal(a[1] / i - 1), cal(a[1] / i + 1);     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int cap = int(1e5) + 1;   vector<int> graph[cap];   vector<int> cnt(cap);   void dfs(int i, int h) {     cnt[h] ^= 1;     for (int j : graph[i]) dfs(j, h + 1);   }   int main() {     int n;     cin >> n;     int p;     for (int i = 2; i <= n; ++i) {       cin >> p;       graph[p].push_back(i);     }     dfs(1, 0);     int ans = 0;     for (int i = 0; i < n; ++i) ans += cnt[i];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int days;     int index;   };   bool compare(node lhs, node rhs) { return (lhs.days < rhs.days); }   int main() {     int n, k;     int sum = 0;     scanf( %d%d , &n, &k);     node a[n + 1];     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].days);       a[i].index = i;     }     sort(a + 1, a + n + 1, compare);     int i = 1;     sum = a[i].days;     while (sum <= k) {       i++;       if (i <= n)         sum += (a[i].days);       else         break;     }     printf( %d n , i - 1);     if (i != 1) {       for (int j = 1; j < i; j++) printf( %d  , a[j].index);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<set<int> > g;   vector<int> ans;   vector<bool> used;   void dfs(int v, int p) {     used[v] = true;     ans.push_back(v);     for (set<int>::iterator i = g[v].begin(); i != g[v].end(); i++) {       if (!used[*i] && g[*i].count(p)) dfs(*i, v);     }   }   int main() {     int n;     scanf( %d , &n);     g.resize(n);     used.resize(n, false);     for (int i = 0; i < 2 * n; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       g[a].insert(b);       g[b].insert(a);       if (g[a].size() > 4 || g[b].size() > 4) {         puts( -1 );         return 0;       }     }     ans.push_back(0);     used[0] = true;     int st, p = -1;     for (set<int>::iterator i = g[0].begin(); i != g[0].end(); i++) {       int temp = 0, mp;       for (set<int>::iterator j = g[0].begin(); j != g[0].end(); j++) {         if (g[*i].count(*j)) {           temp++;           mp = *j;         }       }       if (temp == 1 && n > 6 || temp && n < 7) {         st = *i;         p = mp;         break;       }     }     if (p == -1) {       puts( -1 );       return 0;     }     ans.push_back(p);     used[p] = true;     dfs(st, p);     if (ans.size() != n) {       puts( -1 );       return 0;     }     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double t, n, i, x, mx, mn, f, j, s, r, y, c, m,         k = 0, W, H, x1, y1, w, h, w1, h1, l, u, d, sw, sh, X, Y, X1, X2, R;     cin >> t;     while (t--) {       cin >> W >> H;       cin >> x >> y >> x1 >> y1;       cin >> w >> h;       w1 = abs(x - x1);       h1 = abs(y - y1);       sw = W - w1;       sh = H - h1;       if (sw < w && sh < h)         cout << -1 << endl;       else {         r = W - x1;         l = x;         u = H - y1;         d = y;         if (max(r, l) >= w || max(u, d) >= h)           printf( %0.7lf n , k);         else {           X = max(r, l);           Y = max(u, d);           X = w - X;           Y = h - Y;           if (X > min(r, l))             R = Y;           else if (Y > min(u, d))             R = X;           else             R = min(X, Y);           printf( %0.7lf n , R);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int maxm = 2e1 + 7;   int n, m;   int ar[maxn];   char ch[maxn];   int main() {     int k;     scanf( %d%d , &n, &k);     int d = (n - k) / 2;     for (int i = 0; i < n; i++) {       ch[i] =  0  + (i % (d + 1) == d);     }     printf( %s n , ch);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC diagnostic ignored  -Wunused-result    #pragma GCC diagnostic ignored  -Wunused-function    using namespace std;   namespace {   namespace shik {   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(int64_t &x) { scanf( %  SCNd64, &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const int64_t &x) { printf( %  PRId64, x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   template <class T, class F = less<T>>   void sort_uniq(vector<T> &v, F f = F()) {     sort(begin(v), end(v), f);     v.resize(unique(begin(v), end(v)) - begin(v));   }   template <class T>   inline T bit(T x, int i) {     return (x >> i) & 1;   }   template <class T>   inline bool chkmax(T &a, const T &b) {     return b > a ? a = b, true : false;   }   template <class T>   inline bool chkmin(T &a, const T &b) {     return b < a ? a = b, true : false;   }   template <class T>   using MaxHeap = priority_queue<T>;   template <class T>   using MinHeap = priority_queue<T, vector<T>, greater<T>>;   const int N = 1e5 + 10;   int n, k;   vector<int> e[N];   void make_tree(int p) {     for (int i : e[p]) {       e[i].erase(find(begin(e[i]), end(e[i]), p));       make_tree(i);     }   }   pair<int, int> go(int p) {     int s = 0, r = 0, a1 = 0, a2 = 0;     for (int i : e[p]) {       auto t = go(i);       s += t.first;       int x = t.second;       if (x >= a1) {         a2 = a1;         a1 = x;       } else if (x >= a2) {         a2 = x;       }     }     if (a1 + a2 + 1 >= k) {       s++;     } else {       r = a1 + 1;     }     return {s, r};   }   int shik(int _k) {     k = _k;     return go(1).first;   }   int ans[N];   void solve(int l, int r, int al, int ar) {     if (r - l <= 1) return;     if (al == ar) {       for (int i = (l); i <= int(r); i++) ans[i] = al;       return;     }     int m = (l + r) / 2;     int am = shik(m);     ans[m] = am;     solve(l, m, al, am);     solve(m, r, am, ar);   }   void main() {     R(n);     for (int i = 0; i < int(n - 1); i++) {       int a, b;       R(a, b);       e[a].push_back(b);       e[b].push_back(a);     }     make_tree(1);     ans[1] = n;     solve(1, n + 1, n, 0);     for (int i = (1); i <= int(n); i++) W(ans[i]);   }   }  // namespace shik   }  // namespace   int main() {     shik::main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool adj[110][110];   short color[110];   bool ok = true;   int n, m;   void dfs(int node, int ccolor) {     color[node] = ccolor;     for (int i = 0; i < m; i++) {       if (adj[node][i]) {         if (color[i] == 0) {           dfs(i, ccolor * (-1));         } else if (color[i] == ccolor) {           ok = false;         }       }     }   }   int main() {     cin >> n >> m;     int ai[110], bi[110], a, b, i, j;     for (i = 0; i < m; i++) {       cin >> ai[i] >> bi[i];       if (bi[i] < ai[i]) swap(ai[i], bi[i]);     }     int x1, x2, y1, y2;     for (i = 0; i < m; i++) {       for (j = i + 1; j < m; j++) {         if (ai[i] > ai[j] && ai[i] < bi[j] && bi[i] > bi[j])           adj[i][j] = adj[j][i] = 1;         if (ai[j] > ai[i] && ai[j] < bi[i] && bi[j] > bi[i])           adj[i][j] = adj[j][i] = 1;       }     }     for (i = 0; i < m; i++) {       if (color[i] == 0) dfs(i, 1);     }     if (ok) {       for (i = 0; i < m; i++) {         if (color[i] == 1)           cout <<  i ;         else if (color[i] == -1)           cout <<  o ;       }     } else {       cout <<  Impossible  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ld = long double;   template <typename Arg1>   void debug_out(const char* name, Arg1&& arg1) {     cerr << name <<   =   << arg1 <<   ]           <<   n ;   }   template <typename Arg1, typename... Args>   void debug_out(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   =   << arg1 <<  , ;     debug_out(comma + 1, args...);   }   const long long mod = 1e9 + 7;   const long long N = 5e3 + 5, M = 2e5 + 5;   long long n;   long long v[N];   long long solve(long long l, long long r) {     if (r < l) return 0;     long long res = r - l + 1;     long long mn = *min_element(v + l, v + r + 1);     for (long long i = (l); i <= (r); ++i) v[i] -= mn;     long long ans = mn;     for (long long i = (l); i <= (r); ++i) {       if (v[i] == 0) {         ans += solve(l, i - 1);         l = i + 1;       }     }     ans += solve(l, r);     res = min(res, ans);     return res;   }   void Solve_main() {     cin >> n;     for (long long i = (1); i <= (n); ++i) cin >> v[i];     cout << solve(1, n) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     long long tc = 1;     for (long long i = 1; i <= tc; i++) {       Solve_main();     }     cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v;   vector<long long> q;   int main() {     long long n, d, a, b, xx, x, y, sum = 0;     cin >> n >> d >> a >> b;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       xx = x * a + y * b;       v.push_back(make_pair(xx, i));     }     sort(v.begin(), v.end());     for (long long i = 0; i < n; i++) {       if (v[i].first + sum <= d) {         q.push_back(v[i].second);         sum += v[i].first;       } else         break;     }     n = q.size();     cout << n << endl;     for (long long i = 0; i < n; i++) {       cout << q[i] + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   const int MAXN = 1e5 + 5;   vector<int> graph[MAXN], graph2[MAXN];   int res[MAXN];   bool used[MAXN];   int dfs(int v, vector<int>* g, int c) {     used[v] = true;     if (res[v] == 1 - c) {       cout <<  No n ;       exit(0);     }     res[v] = c;     for (int to : g[v]) {       if (!used[to]) {         dfs(to, g, c);       }     }     return 0;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     int n, m;     scanf( %d%d , &n, &m);     vector<vector<int>> inp;     for (int i = 0; i < n; ++i) {       int l;       scanf( %d , &l);       inp.push_back({});       for (int j = 0; j < l; ++j) {         int num;         scanf( %d , &num);         --num;         inp.back().push_back(num);       }     }     for (int i = 0; i < m; ++i) {       res[i] = 2;     }     for (int i = 0; i < n - 1; ++i) {       bool flag = false;       for (int j = 0; j < min(((int)(inp[i]).size()), ((int)(inp[i + 1]).size()));            ++j) {         if (inp[i][j] != inp[i + 1][j]) {           flag = true;           if (inp[i][j] > inp[i + 1][j]) {             if (res[inp[i][j]] == 1 || res[inp[i + 1][j]] == 0) {               cout <<  No n ;               return 0;             }             res[inp[i][j]] = 0;             res[inp[i + 1][j]] = 1;           } else {             graph[inp[i + 1][j]].push_back(inp[i][j]);             graph2[inp[i][j]].push_back(inp[i + 1][j]);           }           break;         }       }       if (!flag && ((int)(inp[i]).size()) > ((int)(inp[i + 1]).size())) {         cout <<  No n ;         return 0;       }     }     for (int i = 0; i < m; ++i) {       if (res[i] == 0 && !used[i]) {         dfs(i, graph, res[i]);       }       if (res[i] == 1 && !used[i]) {         dfs(i, graph2, res[i]);       }     }     cout <<  Yes n ;     vector<int> ans;     for (int i = 0; i < m; ++i) {       if (res[i] == 0) {         ans.push_back(i);       }     }     cout << ((int)(ans).size()) <<   n ;     for (int num : ans) {       cout << num + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int row = -n; row <= n; ++row) {       int top = n - abs(row);       for (int i = 0; i < abs(row); i++) {         cout <<     ;       }       for (int i = 0; i < top; i++) {         cout << i <<    ;       }       for (int i = top; i > 0; i--) {         cout << i <<    ;       }       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > adj[100005];   int m, n, a, b, w;   long long D[100005];   int Tr[100005];   void dijk(int x) {     Tr[x] = 0;     D[x] = 0;     set<pair<long long, int> > s;     s.insert({0, x});     while (s.size() > 0) {       long long d = (*s.begin()).first;       int u = (*s.begin()).second;       s.erase(s.begin());       for (int i = 0; i < adj[u].size(); ++i) {         int v = adj[u][i].second;         int w = adj[u][i].first;         if (D[v] > D[u] + w) {           D[v] = D[u] + w;           s.insert({D[v], v});           Tr[v] = u;         }       }     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> a >> b >> w;       adj[a].push_back({w, b});       adj[b].push_back({w, a});     }     memset(D, 63, sizeof(D));     dijk(1);     if (D[n] > 1e12) {       cout << -1;       return 0;     }     vector<int> p;     int t = n;     while (t > 0) {       p.push_back(t);       t = Tr[t];     }     reverse(p.begin(), p.end());     for (int i = 0; i < p.size(); ++i) cout << p[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void out(int a) { printf( %d n , a); }   inline void out(int a, int b) { printf( %d %d n , a, b); }   inline void outf(double a) { printf( %3.lf n , a); }   inline void outf(double a, double b) { printf( %3.lf %3.lf n , a, b); }   inline void base() {     ios_base::sync_with_stdio(false);     cin.tie(0);   }   int tour(vector<int> ls) {     while (ls.size() != 1) {       vector<int> nx;       for (int i = 0; i < ls.size(); i += 2) {         if (i + 1 == ls.size()) {           nx.push_back(ls[i]);           break;         }         cout <<  ?   << ls[i] <<     << ls[i + 1] << endl;         char c;         cin >> c;         if (c ==  > ) {           nx.push_back(ls[i]);         } else if (c ==  < ) {           nx.push_back(ls[i + 1]);         } else if (c ==  = ) {           nx.push_back(ls[i]);         }       }       ls = nx;     }     return ls[0];   }   int tour1(vector<int> ls) {     while (ls.size() != 1) {       vector<int> nx;       for (int i = 0; i < ls.size(); i += 2) {         if (i + 1 == ls.size()) {           nx.push_back(ls[i]);           break;         }         cout <<  ?   << ls[i] <<     << ls[i + 1] << endl;         char c;         cin >> c;         if (c ==  > ) {           nx.push_back(ls[i + 1]);         } else if (c ==  < ) {           nx.push_back(ls[i]);         } else if (c ==  = ) {           nx.push_back(ls[i]);         }       }       ls = nx;     }     return ls[0];   }   int main() {     base();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n == 1) {         cout <<  ! 1 1  << endl;         continue;       }       vector<int> lose;       vector<int> win;       for (int i = 1; i <= n; i += 2) {         if (i + 1 <= n) {           cout <<  ?   << i <<     << i + 1 << endl;           char c;           cin >> c;           if (c ==  > ) {             win.push_back(i);             lose.push_back(i + 1);           } else if (c ==  < ) {             win.push_back(i + 1);             lose.push_back(i);           } else {             win.push_back(i);             lose.push_back(i);           }         } else {           win.push_back(i);           lose.push_back(i);         }       }       int mx = tour(win), mn = tour1(lose);       cout <<  !   << mn <<     << mx << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 173, MAX2 = 400;   const int foo = INT_MIN;   char s[MAX];   int slen, l, an[MAX];   int B[MAX][MAX], F[MAX][MAX], R[MAX][MAX][MAX];   bool hh[MAX][MAX];   inline bool good(int i, int j) { return i <= j; }   int full(int i, int j);   int best(int i, int j) {     auto &ele = B[i][j];     if (ele != -1)       return ele;     else {       if (i == j) {         if (an[1] != -1)           return ele = an[1];         else           return ele = 0;       } else {         ele = full(i, j);         for (int r = (i); r <= (j); ++r) {           ele = max(ele, (good(i, r - 1) ? best(i, r - 1) : 0) +                              (good(r + 1, j) ? best(r + 1, j) : 0));         }         return ele;       }     }   }   int resi(int i, int j, int re);   int full(int i, int j) {     auto &ele = F[i][j];     if (ele != -1)       return ele;     else {       if (i == j) {         if (an[1] == -1)           return ele = foo;         else           return ele = an[1];       } else {         int len = j - i + 1;         ele = foo;         for (int re = (1); re <= (len); ++re) {           if (resi(i, j, re) != foo && an[re] != -1) {             ele = max(resi(i, j, re) + an[re], ele);           }         }         return ele;       }     }   }   int resi(int i, int j, int re) {     auto &ele = R[i][j][re];     if (ele != -1)       return ele;     else {       if (i == j) {         return ele = 0;       } else {         int len = j - i + 1;         if (len == re) {           if (hh[i][j])             return ele = 0;           else             return ele = foo;         } else {           if (re == 1) {             ele = foo;             for (int pos = (i); pos <= (j); ++pos) {               int l = pos == i ? 0 : full(i, pos - 1);               if (l != foo) {                 int r = pos == j ? 0 : full(pos + 1, j);                 if (r != foo) {                   ele = max(ele, l + r);                 }               }             }             return ele;           } else {             ele = foo;             for (int bl = (i + 1); bl <= (j + 1 - re); ++bl) {               int tmp = full(i, bl - 1);               if (tmp != foo) {                 int tmp2 = resi(bl, j, re);                 if (tmp2 != foo) {                   ele = max(ele, tmp + tmp2);                 }               }             }             for (int bl = (j - 1); bl >= (re + i - 1); --bl) {               int tmp = full(bl + 1, j);               if (tmp != foo) {                 int tmp2 = resi(i, bl, re);                 if (tmp2 != foo) {                   ele = max(ele, tmp + tmp2);                 }               }             }             if (s[i] == s[j])               ele = max(ele, re - 2 == 0 ? full(i + 1, j - 1)                                          : resi(i + 1, j - 1, re - 2));             return ele;           }         }       }     }   }   int main() {     scanf( %d , &l);     for (int i = (1); i <= (l); ++i) scanf( %d , &an[i]);     scanf( %s , s);     slen = strlen(s);     memset(B, -1, sizeof(B)), memset(F, -1, sizeof(F)), memset(R, -1, sizeof(R));     for (int i = (0); i <= (slen - 1); ++i) {       for (int j = (i); j <= (slen - 1); ++j) {         if (i == j)           hh[i][j] = 1;         else {           int mid = (i + j) / 2;           hh[i][j] = 1;           for (int k = (i); k <= (mid); ++k) {             int rk = j - k + i;             if (s[k] != s[rk]) {               hh[i][j] = 0;               break;             }           }         }       }     }     printf( %d n , best(0, slen - 1));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   struct IO {     char buf[(1 << 20)], *p1, *p2;     char pbuf[(1 << 20)], *pp;     IO() : p1(buf), p2(buf), pp(pbuf) {}     ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }     inline char gc() {       if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);       return p1 == p2 ?     : *p1++;     }     inline bool blank(char ch) {       return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;     }     template <class T>     inline void read(T &x) {       double tmp = 1;       bool sign = 0;       x = 0;       char ch = gc();       for (; !(ch >=  0  && ch <=  9 ); ch = gc())         if (ch ==  - ) sign = 1;       for (; (ch >=  0  && ch <=  9 ); ch = gc()) x = x * 10 + (ch -  0 );       if (ch ==  . )         for (ch = gc(); (ch >=  0  && ch <=  9 ); ch = gc())           tmp /= 10.0, x += tmp * (ch -  0 );       if (sign) x = -x;     }     inline void read(char *s) {       char ch = gc();       for (; blank(ch); ch = gc())         ;       for (; !blank(ch); ch = gc()) *s++ = ch;       *s = 0;     }     inline void read(char &c) {       for (c = gc(); blank(c); c = gc())         ;     }     inline void push(const char &c) {       if (pp - pbuf == (1 << 20)) fwrite(pbuf, 1, (1 << 20), stdout), pp = pbuf;       *pp++ = c;     }     template <class T>     inline void write(T x) {       if (x < 0) x = -x, push( - );       static T sta[35];       T top = 0;       do {         sta[top++] = x % 10, x /= 10;       } while (x);       while (top) push(sta[--top] +  0 );     }     template <class T>     inline void write(T x, char lastChar) {       write(x), push(lastChar);     }   } io;   constexpr long long N = 1e5 + 5;   constexpr double eps = 1e-6;   long long n, k, m, d;   long long id[64];   long long v[64];   long long Q;   long long level(long long x) {     long long ans = 0;     while (x) {       ans++;       x >>= 1LL;     }     return ans;   }   signed main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     ;     cin >> Q;     while (Q--) {       long long T;       cin >> T;       if (T == 1LL) {         long long X, K;         cin >> X >> K;         long long l = level(X);         long long M = (1LL << (l - 1LL));         v[l] += K % M;         v[l] %= M;         if (v[l] < 0) v[l] += M;       } else if (T == 2) {         long long X, K;         cin >> X >> K;         long long l = level(X);         while (l < 64) {           long long M = (1LL << (l - 1LL));           K %= M;           v[l] += K % M;           v[l] %= M;           if (v[l] < 0) v[l] += M;           id[l] += K % M;           id[l] %= M;           if (id[l] < 0) id[l] += M;           l++;           K *= 2;         }       } else {         long long X;         cin >> X;         cout << X <<    ;         long long l = level(X);         long long M = 1LL << (l - 1LL);         X -= M;         long long rawid = (X + v[l] + M) % M;         long long nowid = (rawid + id[l] + M) % M;         while (M + rawid != 1LL) {           rawid = (M + rawid) >> 1LL;           M >>= 1LL;           l--;           rawid -= M;           cout << M + (rawid - v[l] + M) % M <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 5e5 + 500;   long long seg[4 * maxn];   long long dp[maxn];   long long q[maxn];   long long houp[maxn];   long long a[maxn];   map<long long, long long> last;   map<long long, vector<long long> > las;   void bild() { fill(seg, seg + 4 * maxn, -1); }   void update(long long L, long long R, long long node, long long l, long long r,               long long v) {     if (l <= L && R <= r) {       seg[node] = max(seg[node], v);       return;     }     if (r <= L || R <= l) {       return;     }     seg[2 * node] = max(seg[2 * node], seg[node]);     seg[2 * node + 1] = max(seg[2 * node + 1], seg[node]);     long long mid = (L + R) / 2;     update(L, mid, 2 * node, l, r, v);     update(mid, R, 2 * node + 1, l, r, v);   }   long long findd(long long L, long long R, long long node, long long x) {     long long mid = (L + R) / 2;     if (L + 1 == R) {       return seg[node];     }     if (x < mid) {       return max(seg[node], findd(L, mid, 2 * node, x));     } else {       return max(seg[node], findd(mid, R, 2 * node + 1, x));     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     bild();     for (long long i = 0; i < n; i++) {       long long v = a[i];       if (last.count(v) > 0) {         q[i] = findd(0, n, 1, last[v]);         update(0, n, 1, last[v] + 1, i, last[v]);       } else {         q[i] = -1;       }       last[v] = i;     }     for (long long i = 0; i < n; i++) {       long long v = a[i];       las[v].push_back(i);       if (las[v].size() >= 4) {         q[i] = max(q[i], las[v][las[v].size() - 4]);       }     }     dp[0] = 0;     houp[0] = -1;     for (long long i = 1; i < n; i++) {       if (q[i] == -1) {         houp[i] = -1;         dp[i] = dp[i - 1];       } else {         if (q[i] == 0) {           dp[i] = max(dp[i - 1], 1LL);         } else {           dp[i] = max(dp[i - 1], 1 + dp[q[i] - 1]);         }         if (dp[i] == dp[i - 1]) {           houp[i] = -1;         } else {           houp[i] = q[i];         }       }     }     cout << 4 * dp[n - 1] << endl;     vector<long long> stk;     long long p = n - 1;     while (p >= 0) {       if (houp[p] == -1) {         p--;       } else {         stk.push_back(a[p]);         stk.push_back(a[houp[p]]);         stk.push_back(a[p]);         stk.push_back(a[houp[p]]);         p = houp[p] - 1;       }     }     reverse(stk.begin(), stk.end());     for (long long i = 0; i < stk.size(); i++) {       cout << stk[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int m, n, nword, R[MAXN], len[MAXN];   map<string, int> M;   string s[MAXN];   vector<int> adj[MAXN], adj2[MAXN];   int super[MAXN], nsuper, number[MAXN], low[MAXN], cnt;   int best[MAXN], rep[MAXN];   bool inStack[MAXN];   int st[MAXN], nst;   int f[MAXN];   long long resR, resLen;   void toLower(string& s) {     for (int i = 0; i < s.size(); i++) {       s[i] = tolower(s[i]);     }   }   int countR(string s) {     int ret = 0;     for (int i = 0; i < s.size(); i++) {       ret += s[i] ==  r ;     }     return ret;   }   void add(string& s) {     toLower(s);     if (M[s] == 0) M[s] = ++nword;     int x = M[s];     len[x] = s.length();     R[x] = countR(s);   }   void input() {     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       cin >> s[i];       add(s[i]);     }     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       string tmp;       int u, v;       cin >> tmp;       add(tmp);       u = M[tmp];       cin >> tmp;       add(tmp);       v = M[tmp];       adj[u].push_back(v);     }   }   void tarjan(int u) {     number[u] = ++cnt;     low[u] = number[u];     inStack[u] = true;     st[++nst] = u;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (number[v] == 0) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (inStack[v])         low[u] = min(low[u], number[v]);     }     if (low[u] == number[u]) {       nsuper++;       best[nsuper] = u;       super[u] = nsuper;       inStack[u] = false;       while (st[nst] != u) {         int v = st[nst--];         super[v] = nsuper;         inStack[v] = false;         if (R[v] < R[best[nsuper]] ||             (R[v] == R[best[nsuper]] && len[v] < len[best[nsuper]]))           best[nsuper] = v;       }       nst--;     }   }   void dfs(int u) {     f[u] = best[u];     for (int i = 0; i < adj2[u].size(); i++) {       int v = adj2[u][i];       if (f[v] == 0) dfs(v);       if (R[f[v]] < R[f[u]] || (R[f[v]] == R[f[u]] && len[f[v]] < len[f[u]]))         f[u] = f[v];     }   }   void solve() {     for (int i = 1; i <= nword; i++) {       if (number[i] == 0) tarjan(i);     }     for (int i = 1; i <= nword; i++) {       for (int j = 0; j < adj[i].size(); j++) {         int v = adj[i][j];         if (super[i] != super[v]) adj2[super[i]].push_back(super[v]);       }     }     for (int i = 1; i <= nword; i++) {       if (f[i] == 0) dfs(i);     }     for (int i = 1; i <= m; i++) {       int id = M[s[i]];       resR += R[f[super[id]]];       resLen += len[f[super[id]]];     }   }   void output() { printf( %I64d %I64d , resR, resLen); }   int main() {     input();     solve();     output();   }


#include <bits/stdc++.h>   using namespace std;   map<int, bool> mp;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       mp[a] = 1;     }     for (int i = 0; i < 1010; i++) {       if (mp[i] && mp[i + 1] && mp[i + 2]) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   char s[1010];   int a[1010], num[1010], b[30];   int prime[1010], notprime[1010];   priority_queue<pair<int, char> > pq;   set<pair<int, int> > st;   pair<int, int> c[1010];   int ans[1010];   int cnt;   void init() {     for (int i = 2; i <= 1000; i++) {       if (!notprime[i]) prime[cnt++] = i;       for (int j = 0; j < cnt && i * prime[j] <= 1000; j++) {         notprime[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }     for (int i = 0; i <= 1000; i++) a[i] = i, num[i] = 1;   }   int get(int x) { return a[x] == x ? x : a[x] = get(a[x]); }   void merge(int x, int y) {     int t1 = get(x);     int t2 = get(y);     if (t1 != t2) {       a[max(t1, t2)] = min(t1, t2);       num[min(t1, t2)] += num[max(t1, t2)];     }   }   bool cmp(pair<int, int> x, pair<int, int> y) { return x.first > y.first; }   int main() {     init();     scanf( %s , s);     int l = strlen(s);     for (int i = 0; i < l; i++) b[s[i] -  a ]++;     for (int i = 0; i < 30; i++)       if (b[i]) pq.push({b[i], i +  a });     for (int i = 0; i < cnt && prime[i] <= l; i++)       for (int j = 2; j <= l / prime[i]; j++) merge(prime[i], j * prime[i]);     st.insert({1, 1});     for (int i = 0; i < cnt && prime[i] <= l; i++) {       int r = get(prime[i]);       st.insert({num[r], r});     }     int num = 0, j = 0;     for (auto i : st) c[num++] = i;     sort(c, c + num, cmp);     int flag = 0;     while (pq.size() && j < num) {       pair<int, char> t = pq.top();       pq.pop();       if (t.first >= c[j].first)         ans[c[j].second] = t.second -  a ;       else {         flag = 1;         break;       }       if (t.first - c[j].first > 0) pq.push({t.first - c[j].first, t.second});       j++;     }     if (flag)       printf( NO n );     else {       printf( YES n );       for (int i = 1; i <= l; i++) printf( %c , ans[get(i)] +  a );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <typename T>   T gcd(T a, T b) {     T c;     while (b) {       c = b;       b = a % b;       a = c;     }     return a;   }   template <typename T>   T powmod(T a, T b) {     T res = 1;     a %= mod;     while (b) {       if (b & 1) res = res * (a % mod);       a = a * (a % mod);       b >>= 1;     }     return res;   }   void Solve() {     int n, m;     cin >> n >> m;     char grid[120][120];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> grid[i][j];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (grid[i][j] ==  B ) {           if (j + 1 == m) {             cout << i + 1 <<     << j + 1 <<   n ;             return;           } else {             int k;             for (k = j + 1; k < m; ++k) {               if (grid[i][k] !=  B ) break;             }             int a = k - j + 1;             cout << i + (a / 2) <<     << j + (a / 2) <<   n ;             return;           }         }       }     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     Solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<long long, long long> res;   long long a[N];   void dfs(long long cur, long long cnt, long long sum) {     if (!cur) {       res = max(res, {cnt, sum});       return;     } else {       int p = upper_bound(a + 1, a + N, cur) - a;       --p;       dfs(cur - a[p], cnt + 1, sum + a[p]);       if (p > 1) dfs(a[p] - 1 - a[p - 1], cnt + 1, sum + a[p - 1]);     }   }   int main() {     for (int i = 1; i <= N - 1; ++i) a[i] = 1ll * i * i * i;     long long m;     scanf( %lld , &m);     dfs(m, 0, 0);     printf( %lld %lld n , res.first, res.second);     return 0;   }


#include <bits/stdc++.h>   int cmpfnc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int i, n;     scanf( %d , &n);     int arr[300005];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     qsort(arr, n, sizeof(int), cmpfnc);     long long int sum = arr[0];     long long int count = 1;     long long int t2 = 0;     for (i = 1; i < n; i++) {       long long int t3 =           ((count % 1000000007) * (arr[i] % 1000000007)) % 1000000007;       t2 = (t2 + (t3 - sum + 1000000007) % 1000000007) % 1000000007;       sum = (sum * 2 + arr[i]) % 1000000007;       count = (count * 2 + 1) % 1000000007;     }     printf( %lld n , t2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str, s1, s2 =  < ;     stack<char> delm;     vector<string> re;     getline(cin, str);     for (int i = 0; i < str.size(); i++) {       if (str[i] ==     && delm.empty()) {         s1 =  < ;         delm.push(str[i]);       } else if (!delm.empty()) {         char ch = delm.top();         if (ch == str[i]) {           s1 +=  *> ;           re.push_back(s1);           delm.pop();         } else           s1 += str[i];       } else if (delm.empty()) {         if (str[i] ==     && s2.size() > 1) {           s2 +=  *> ;           re.push_back(s2);           s2 =  < ;         } else if (str[i] !=    ) {           s2 += str[i];         }         if (i == str.size() - 1 && str[str.size() - 1] !=    ) {           s2 +=  *> ;           re.push_back(s2);           s2 =  < ;           continue;         }       }     }     for (int i = 0; i < re.size(); i++) {       bool flag = false;       for (int j = 1; j < re[i].size() - 1; j++)         if (re[i][j] !=     || re[i][re[i].size() - 1] ==  * ) {           flag = true;           re[i] =               re[i].substr(0, re[i].size() - 2) + re[i].substr(re[i].size() - 1);           break;         }       if (flag) cout << re[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   inline void read(int &x) { scanf( %d , &x); }   inline void read(long long &x) { scanf( %I64d , &x); }   inline void read(double &x) { scanf( %lf , &x); }   inline void read(long double &x) {     double tmp;     read(tmp);     x = tmp;   }   template <class T>   inline void read(T *a, int n) {     for (int i = (0); i < (n); ++i) read(a[i]);   }   inline void write(int x) { printf( %d , x); }   inline void write(long long x) { printf( %I64d , x); }   inline void write(double x) { printf( %.10lf , x); }   inline void write(long double x) { printf( %.10lf , (double)x); }   template <class T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   template <class T>   inline void writeln(T *a, int n) {     for (int i = (0); i < (n); ++i) {       write(a[i]);       putchar(   );     }     putchar(  n );   }   template <class T>   inline void writelnln(T *a, int n) {     for (int i = (0); i < (n); ++i) writeln(a[i]);   }   int A[5];   std::set<int> res[5][5];   inline void calc(int l, int r) {     std::set<int> &S = res[l][r];     S.clear();     if (l == r) {       S.insert(A[l]);       S.insert(-A[l]);     } else {       for (int m = (l); m < (r); ++m) {         std::set<int> &a = res[l][m], &b = res[m + 1][r];         for (__typeof(a.begin()) aa = a.begin(); aa != a.end(); ++aa)           for (__typeof(b.begin()) bb = b.begin(); bb != b.end(); ++bb) {             S.insert(*aa + *bb);             S.insert(*aa - *bb);             S.insert(*aa * *bb);             S.insert(-*aa + *bb);             S.insert(-*aa - *bb);             S.insert(-*aa * *bb);           }       }     }   }   std::set<int> ANS;   char buf[3000007], *cb = buf;   int main() {     int k, m;     read(k);     read(m);     for (int ls = (0); ls < (10000); ++ls) {       A[0] = ls / 1000;       A[1] = ls / 100 % 10;       A[2] = ls / 10 % 10;       A[3] = ls % 10;       calc(0, 0);       calc(1, 1);       calc(2, 2);       calc(3, 3);       calc(0, 1);       calc(1, 2);       calc(2, 3);       calc(0, 2);       calc(1, 3);       calc(0, 3);       std::set<int> &ans = res[0][3];       for (__typeof(ans.begin()) x = ans.begin(); x != ans.end(); ++x) {         int ttt = abs(k - *x);         if (ttt < 10000) {           ANS.insert(ls * 10000 + ttt);           if (ANS.size() == m) {             for (__typeof(ANS.begin()) it = ANS.begin(); it != ANS.end(); ++it) {               int x = *it;               *(cb++) = x / 10000000 +  0 ;               *(cb++) = x / 1000000 % 10 +  0 ;               *(cb++) = x / 100000 % 10 +  0 ;               *(cb++) = x / 10000 % 10 +  0 ;               *(cb++) = x / 1000 % 10 +  0 ;               *(cb++) = x / 100 % 10 +  0 ;               *(cb++) = x / 10 % 10 +  0 ;               *(cb++) = x % 10 +  0 ;               *(cb++) =   n ;             }             fwrite(buf, 1, cb - buf, stdout);             return 0;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   signed long long W[303030];   vector<pair<int, int>> E[303030];   signed long long best[303030];   signed long long ma;   void dfs(int cur, int pre) {     vector<signed long long> C;     for (auto& e : E[cur])       if (e.first != pre) {         dfs(e.first, cur);         if (best[e.first] - e.second > 0) C.push_back(best[e.first] - e.second);       }     C.push_back(0);     C.push_back(0);     sort((C.begin()), (C.end()));     reverse((C.begin()), (C.end()));     ma = max(ma, W[cur] + C[0] + C[1]);     best[cur] = W[cur] + C[0];   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 0; i < (N); i++) cin >> W[i];     for (i = 0; i < (N - 1); i++) {       cin >> x >> y >> r;       E[x - 1].push_back({y - 1, r});       E[y - 1].push_back({x - 1, r});     }     dfs(0, -1);     cout << ma << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = numeric_limits<long long>::max() / 4;   struct Edge {     long long from, to, cap, flow, index;     Edge(long long from, long long to, long long cap, long long flow,          long long index)         : from(from), to(to), cap(cap), flow(flow), index(index) {}     long long rcap() { return cap - flow; }   };   struct Dinic {     long long N;     vector<vector<Edge> > G;     vector<vector<Edge *> > Lf;     vector<long long> layer;     vector<long long> Q;     Dinic(long long N) : N(N), G(N), Q(N) {}     void AddEdge(long long from, long long to, long long cap) {       if (from == to) return;       G[from].push_back(Edge(from, to, cap, 0, G[to].size()));       G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));     }     long long BlockingFlow(long long s, long long t) {       layer.clear();       layer.resize(N, -1);       layer[s] = 0;       Lf.clear();       Lf.resize(N);       long long head = 0, tail = 0;       Q[tail++] = s;       while (head < tail) {         long long first = Q[head++];         for (long long i = 0; i < G[first].size(); i++) {           Edge &e = G[first][i];           if (e.rcap() <= 0) continue;           if (layer[e.to] == -1) {             layer[e.to] = layer[e.from] + 1;             Q[tail++] = e.to;           }           if (layer[e.to] > layer[e.from]) {             Lf[e.from].push_back(&e);           }         }       }       if (layer[t] == -1) return 0;       long long totflow = 0;       vector<Edge *> P;       while (!Lf[s].empty()) {         long long curr = P.empty() ? s : P.back()->to;         if (curr == t) {           long long amt = P.front()->rcap();           for (long long i = 0; i < P.size(); ++i) {             amt = min(amt, P[i]->rcap());           }           totflow += amt;           for (long long i = P.size() - 1; i >= 0; --i) {             P[i]->flow += amt;             G[P[i]->to][P[i]->index].flow -= amt;             if (P[i]->rcap() <= 0) {               Lf[P[i]->from].pop_back();               P.resize(i);             }           }         } else if (Lf[curr].empty()) {           P.pop_back();           for (long long i = 0; i < N; ++i)             for (long long j = 0; j < Lf[i].size(); ++j)               if (Lf[i][j]->to == curr) Lf[i].erase(Lf[i].begin() + j);         } else {           P.push_back(Lf[curr].back());         }       }       return totflow;     }     long long GetMaxFlow(long long s, long long t) {       long long totflow = 0;       while (long long flow = BlockingFlow(s, t)) totflow += flow;       return totflow;     }   };   long long N, M;   set<long long> pr;   set<long long>::iterator it;   long long a[157], b[157];   pair<long long, long long> E[157];   long long get(long long p, long long N) {     memset(b, 0, sizeof(b));     for (long long i = (1); i < (N + 1); i++) {       while (a[i] % p == 0) {         b[i]++;         a[i] /= p;       }     }     Dinic F(N + 7);     for (long long i = 1; i <= N; i += 2) {       F.AddEdge(0, i, b[i]);     }     for (long long i = 2; i <= N; i += 2) {       F.AddEdge(i, N + 1, b[i]);     }     for (long long i = (0); i < (M); i++) {       F.AddEdge(E[i].first, E[i].second, min(b[E[i].first], b[E[i].second]));     }     return F.GetMaxFlow(0, N + 1);   }   int main() {     scanf( %lld %lld , &N, &M);     for (long long i = (1); i < (N + 1); i++) {       scanf( %lld , &a[i]);     }     for (long long i = (0); i < (M); i++) {       scanf( %lld %lld , &E[i].first, &E[i].second);       if (E[i].first % 2 == 0) swap(E[i].first, E[i].second);     }     for (long long i = (1); i < (N + 1); i++) {       long long tmp = a[i];       if (tmp % 2 == 0) {         pr.insert(2);         while (tmp % 2 == 0) {           tmp /= 2;         }       }       for (long long j = 3; j * j <= tmp; j += 2) {         if (tmp % j == 0) {           pr.insert(j);           while (tmp % j == 0) {             tmp /= j;           }         }       }       if (tmp > 1) pr.insert(tmp);     }     long long ans = 0;     for (it = pr.begin(); it != pr.end(); it++) {       ans += get(*it, N);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int sum[maxn], t, n, q, l, r;   char s[maxn];   set<int> v[4 * maxn + 10];   int main() {     scanf( %d , &t);     while (t--) {       sum[0] = 0;       scanf( %d%d%s , &n, &q, (s + 1));       for (int i = 1; i <= n; i++) {         sum[i] = sum[i - 1] + (s[i] ==  +  ? 1 : -1) * (i & 1 ? 1 : -1);         v[sum[i - 1] + sum[i] + 2 * maxn].clear();       }       for (int i = 1; i <= n; i++) v[sum[i - 1] + sum[i] + 2 * maxn].insert(i);       while (q--) {         scanf( %d%d , &l, &r);         if (sum[r] == sum[l - 1])           printf( 0 n );         else {           int k = r - l + 1;           if (k % 2 == 0)             printf( 2 n%d  , l), l++;           else             printf( 1 n );           printf( %d n , *v[sum[r] + sum[l - 1] + 2 * maxn].lower_bound(l));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int base = 1e9;   const int maxn = 1e3;   const int logn = 20;   const int inf = 2e9;   const int alpha = 26;   const int my_hash = 29;   const long long l_inf = 4e18;   const long long mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-9;   int n;   long long x, sum = 0;   vector<long long> a, b;   long long binpow(long long a, long long b) {     if (!b) return 1;     if (b % 2) return (binpow(a, b - 1) * a) % mod;     long long k = binpow(a, b / 2);     return (k * k) % mod;   }   int main() {     ios_base::sync_with_stdio();     cin >> n >> x;     a = vector<long long>(n);     for (int i = int(0); i < int(n); i++) {       cin >> a[i];       sum += a[i];     }     for (int i = int(0); i < int(n); i++) b.push_back(sum - a[i]);     sort(b.rbegin(), b.rend());     while (true) {       long long cnt = 0, v = b.back();       while (!b.empty() && b.back() == v) {         cnt++;         b.pop_back();       }       if (cnt % x) {         cout << binpow(x, min(v, sum));         exit(0);       } else {         cnt /= x;         for (int i = int(0); i < int(cnt); i++) b.push_back(v + 1);       }     }   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   void fil() {}   long long int ipow(long long int base, long long int k, long long int M) {     base %= M;     k = k % (M - 1);     long long int total = 1;     while (k) {       if (k & 1) {         total = (total * base) % M;       }       base = (base * base) % M;       k >>= 1;     }     return total;   }   void solve();   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     fil();     long long int t = 1;     cin >> t;     for (int i = 1; i < t + 1; i++) {       solve();     }   }   void solve() {     int n, m, ix, iy, fx, fy;     cin >> n >> m >> ix >> iy >> fx >> fy;     int dx = 1, dy = 1;     int cnt = 0;     while (1) {       if (ix == fx || iy == fy) {         cout << cnt <<   n ;         return;       }       if (!(ix + dx <= n && ix + dx >= 1)) {         dx *= -1;       }       if (!(iy + dy <= m && iy + dy >= 1)) {         dy *= -1;       }       ix += dx;       iy += dy;       cnt++;     }   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     LL sum = 0;     for (int i = 0; i < n; ++i) {       LL a;       cin >> a;       sum += a;     }     LL base = 1LL * (1 + n) * n / 2;     LL add = (sum - base) / n;     sum -= base + add * n;     for (int i = 0; i < sum; ++i) cout << i + 1 + add + 1 <<    ;     for (int i = sum; i < n; ++i) cout << i + 1 + add <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T;   int N, X, Y, Ord[100005];   bool print;   int A[100005], Freq[100005], Freq2[100005], F[100005];   vector<int> V;   vector<int> Ap[100005];   set<pair<int, int> > S1, S2;   int Res[100005];   void Read() {     scanf( %d%d%d , &N, &X, &Y);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       F[A[i]]++;       Ord[i] = i;     }   }   int missing() {     for (int i = 1; i <= N + 1; i++)       if (F[i] == 0) return i;     return -1;   }   bool cmp(int a, int b) { return F[A[a]] < F[A[b]]; }   void Solve() {     sort(Ord + 1, Ord + N + 1, cmp);     int miss = missing();     Freq[miss] = N - Y;     int cnt = 0, pos = 0, cnt2 = 0;     for (int i = 1; i <= N && cnt < Y - X; i++) {       pos = i;       if ((Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 2) > N - X) {         if (cnt2 == N - Y || (Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 1) > N - X)           continue;         Freq2[A[Ord[i]]]++;         cnt2++;         continue;       }       Freq[A[Ord[i]]]++;       Freq2[A[Ord[i]]]++;       cnt++;     }     if (cnt < Y - X) {       printf( NO n );       return;     }     for (int i = pos + 1; i <= N && cnt2 < N - Y; i++) {       if (Freq2[A[Ord[i]]] + 1 + Freq[A[Ord[i]]] > N - X) {         continue;       }       Freq2[A[Ord[i]]]++;       cnt2++;     }     if (cnt2 < N - Y) {       if (print) printf( NO n );       return;     }     if (print) printf( YES n );     for (int i = 1; i <= N + 1; i++) {       if (Freq[i] > 0) {         S1.insert(make_pair(Freq[i], i));       }       if (Freq2[i] > 0) S2.insert(make_pair(Freq2[i], i));     }     int total = N - X;     while (S1.size() > 0) {       set<pair<int, int> >::iterator it = S1.end();       --it;       set<pair<int, int> >::iterator it2 = S2.end();       --it2;       if ((it->first) * 2 == (it2->first) * 2 && (it->first) * 2 == total) {         --it;         --it2;         if (((it->second) != (it2->second)) ||             ((it->first) * 2 != total || (it2->first) * 2 != total)) {           ++it;           ++it2;         } else           ++it;       }       if ((it2->second) == (it->second)) --it2;       Ap[it2->second].push_back(it->second);       pair<int, int> a = *it;       pair<int, int> b = *it2;       --a.first;       --b.first;       S1.erase(it);       S2.erase(it2);       if (a.first > 0) S1.insert(a);       if (b.first > 0) S2.insert(b);       --total;     }     for (int i = 1; i <= N; i++) {       if (Ap[A[i]].size() > 0) {         int val = Ap[A[i]].back();         Res[i] = val;         Ap[A[i]].pop_back();       }     }     cnt = 0;     for (int i = 1; i <= N; i++) {       if (Res[i] == 0) {         Res[i] = A[i];       }       if (print) printf( %d  , Res[i]);     }     if (print) printf(  n );   }   int main() {     int T;     int ind = 0;     scanf( %d , &T);     print = true;     while (T--) {       ++ind;       Read();       Solve();       for (int i = 1; i <= N + 1; i++) {         Ap[i].clear();         Freq[i] = 0;         F[i] = 0;         Freq2[i] = 0;         Res[i] = 0;       }       S1.clear();       S2.clear();       V.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, t;   long long l, r = 1e14, md, res = 1e18, a[200500], b[200500];   struct sb {     long long x, y;     double t;     bool operator<(const sb a) const { return t > a.t; }   } s;   bool chk(long long sb) {     priority_queue<struct sb> q;     int i, j, k;     long long tmp;     for (i = 1; i <= n; i++) {       s.x = a[i];       s.y = b[i];       s.t = s.x * 1.0 / s.y;       q.push(s);     }     for (i = 0; i < m; i++) {       s = q.top();       q.pop();       tmp = s.x / s.y;       if (tmp < i) {         return 0;       }       s.x += sb;       s.t = s.x * 1.0 / s.y;       q.push(s);     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (i = 1; i <= n; i++) {       scanf( %lld , &b[i]);     }     while (l <= r) {       md = (l + r) / 2;       if (chk(md)) {         res = min(res, md);         r = md - 1;       } else {         l = md + 1;       }     }     if (res == 1e18) {       puts( -1 );       return 0;     }     printf( %lld , res);   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     if ((n % 2) == 0)       cout << n / 2;     else       cout << n / 2 + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long a = 0;   long long b = 0;   void dfs(vector<vector<int>> &g, vector<bool> was, int v, int lvl) {     was[v] = true;     if (lvl % 2 == 0)       a++;     else       b++;     for (int x : g[v]) {       if (!was[x]) dfs(g, was, x, lvl + 1);     }   }   int main() {     int n;     cin >> n;     unordered_set<string> names;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (names.find(s) == names.end())         cout <<  NO  << endl;       else         cout <<  YES  << endl;       names.insert(s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char t[100][100];   int main(int argc, char* argv[]) {     unsigned int n;     cin >> n;     for (unsigned int i = 0; i < n; ++i)       for (unsigned int j = 0; j < n; ++j) cin >> t[i][j];     unsigned int r = 0;     for (unsigned int i = 0; i < n; ++i) {       for (unsigned int j = 0; j < n; ++j) {         if (t[i][j] ==  . ) {           ++r;           break;         }       }     }     if (r < n) {       unsigned int c = 0;       for (unsigned int i = 0; i < n; ++i) {         for (unsigned int j = 0; j < n; ++j) {           if (t[j][i] ==  . ) {             ++c;             break;           }         }       }       if (c < n)         cout << -1 << endl;       else {         for (unsigned int i = 0; i < n; ++i) {           for (unsigned int j = 0; j < n; ++j) {             if (t[j][i] ==  . ) {               cout << j + 1 <<     << i + 1 << endl;               break;             }           }         }       }     } else {       for (unsigned int i = 0; i < n; ++i) {         for (unsigned int j = 0; j < n; ++j) {           if (t[i][j] ==  . ) {             cout << i + 1 <<     << j + 1 << endl;             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct V {     int x, y;   };   bool conf(V left, V right) {     if (left.x != right.x) return left.x < right.x;     return left.y < right.y;   }   int main() {     V arr[9];     for (int i = 0; i <= 7; i++) scanf( %d %d , &arr[i].x, &arr[i].y);     sort(arr, arr + 8, conf);     if ((arr[0].x != arr[1].x) || (arr[0].x != arr[2].x) ||         (arr[0].x == arr[3].x) || (arr[3].x != arr[4].x) ||         (arr[0].x == arr[5].x) || (arr[3].x == arr[5].x) ||         (arr[5].x != arr[6].x) || (arr[5].x != arr[7].x)) {       printf( ugly );       return 0;     }     if ((arr[0].y == arr[1].y) || (arr[0].y == arr[2].y) ||         (arr[1].y == arr[2].y) || (arr[0].y != arr[3].y) ||         (arr[0].y != arr[5].y) || (arr[1].y != arr[6].y) ||         (arr[2].y != arr[4].y) || (arr[2].y != arr[7].y)) {       printf( ugly );       return 0;     }     printf( respectable );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)2e9;   const long long mod = 1000000007;   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   long long powmod(long long a, long long p) {     long long ans = 1;     a %= mod;     while (p) {       if (p & 1) ans *= a;       p /= 2;       a *= a;       ans %= mod;       a %= mod;     }     return ans;   }   long long mdinv(long long a) { return powmod(a, mod - 2); }   const int N = 5e5 + 10;   vector<int> adj[N];   vector<int> pre[N];   vector<int> suf[N];   int d[N];   vector<pair<int, int> > nb[N];   int f[2 * N];   void dfs1(int i, int p) {     d[i] = 0;     for (int v : adj[i]) {       if (v != p) {         dfs1(v, i), d[i] = max(d[i], 1 + d[v]);       }     }   }   void evaluate(vector<pair<int, int> >& v);   void go(vector<pair<int, int> >& v, vector<pair<int, int> >& v2);   void dfs2(int i, int p, int parDep) {     vector<int>& pr = pre[i];     for (int v : adj[i]) {       if (v != p) {         pr.push_back(d[v] + 1);       } else         pr.push_back(parDep + 1);     }     vector<int> lst(pr);     vector<int>& sf = suf[i];     sf = pr;     for (int i = 1; i < (int)(pr.size()); i++) pr[i] = max(pr[i - 1], pr[i]);     for (int i = (int)(pr.size()) - 2; i >= 0; i--) sf[i] = max(sf[i], sf[i + 1]);     for (int first = 0; first < (int)(adj[i].size()); first++) {       int v = adj[i][first];       if (v == p) continue;       int mx = 0;       if (first) mx = max(mx, pr[first - 1]);       if (first + 1 < (int)(pr.size())) mx = max(mx, sf[first + 1]);       dfs2(v, i, mx);     }     for (int first : lst) nb[i].push_back({first, 1});     vector<pair<int, int> >& v = nb[i];     sort((v).begin(), (v).end());     int ind = 0;     for (int i = 1; i < (int)(v.size()); i++) {       if (v[ind].first == v[i].first) {         v[ind].second += v[i].second;       } else {         ind++;         v[ind] = v[i];       }     }     v.resize(ind + 1);     evaluate(nb[i]);     for (int v : adj[i]) {       if (v != p) {         go(nb[i], nb[v]);       }     }   }   vector<pair<int, int> > tmp;   void evaluate(vector<pair<int, int> >& v) {     tmp = v;     for (int i = (int)(tmp.size()) - 1; i >= 0; i--) {       if (i != (int)(tmp.size()) - 1)         tmp[i].second = tmp[i].second + tmp[i + 1].second;       int dep = tmp[i].first;       f[2 * dep] = max(f[2 * dep], tmp[i].second);       int greater = tmp[i].second - v[i].second;       f[2 * dep + 1] = max(f[2 * dep + 1], greater + 1);       f[2 * dep - 1] = max(f[2 * dep - 1], tmp[i].second);     }   }   void go(vector<pair<int, int> >& v1, vector<pair<int, int> >& v2) {     tmp.clear();     for (auto i : v1) tmp.push_back(i);     for (auto i : v2) tmp.push_back(i);     sort((tmp).begin(), (tmp).end());     int ind = 0;     for (int i = 1; i < (int)(tmp.size()); i++) {       if (tmp[ind].first == tmp[i].first) {         tmp[ind].second += tmp[i].second;       } else {         ind++;         tmp[ind] = tmp[i];       }     }     tmp.resize(ind + 1);     for (int i = (int)(tmp.size()) - 1; i >= 0; i--) {       if (i != (int)(tmp.size()) - 1)         tmp[i].second = tmp[i].second + tmp[i + 1].second;       int dep = tmp[i].first;       f[2 * dep] = max(f[2 * dep], tmp[i].second - 2);     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < (int)2 * N; i++) f[i] = 1;     int n;     cin >> n;     int a, b;     int mxd = 0;     for (int i = 0; i < (int)n - 1; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; i++) mxd = max(mxd, (int)(adj[i].size()));     dfs1(1, 0);     dfs2(1, 0, -1);     for (int i = N - 3; i >= 0; i -= 2) f[i] = max(f[i], f[i + 2]);     for (int i = N - 4; i >= 0; i -= 2) f[i] = max(f[i], f[i + 2]);     f[1] = mxd + 1;     for (int i = 1; i <= n; i++) cout << f[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   void transform(int input) {     if (input) {       transform((input - 1) / 26);       putchar(65 + (input - 1) % 26);     }   }   int main() {     int n, x, y;     string input;     for (scanf( %d  , &n); n--;) {       cin >> input;       if (sscanf(input.c_str(),  %*c%d%*c%d , &x, &y) == 2) {         transform(y);         printf( %d n , x);       } else {         x = 0;         for (int j = 0; j < input.size() && input[j] > 64 && input[j] < 91; j++) {           x = x * 26 + input[j] - 64;         }         string digits = input.c_str();         digits.erase(remove_if((digits).begin(), (digits).end(),                                [](char c) { return isalpha(c); }),                      digits.end());         printf( R%sC%d n , digits.c_str(), x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 105;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int x;     cin >> x;     for (int i = 0; i < n; i++) {       x = 7 - x;       int a, b;       cin >> a >> b;       if (a == x || b == x || 7 - a == x || 7 - b == x) {         cout <<  NO n ;         return 0;       }       for (int j = 1; j <= 6; j++)         if (a != j && b != j && 7 - a != j && 7 - b != j) x = j;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     char x =  a ;     int y;     set<int> arr[26];     for (int i = 0; i < s.length(); i++) {       y = s[i] - x;       arr[y].insert(i);     }     int q;     cin >> q;     int n, ans = 0;     for (int i = 0; i < q; i++) {       cin >> n;       if (n == 1) {         int pos;         char c;         cin >> pos >> c;         y = s[pos - 1] - x;         arr[y].erase(pos - 1);         s[pos - 1] = c;         y = c - x;         arr[y].insert(pos - 1);       }       if (n == 2) {         int l, r;         cin >> l >> r;         l--;         r--;         for (int i = 0; i < 26; i++) {           auto it = arr[i].lower_bound(l);           if (it == arr[i].end())             continue;           else if (*it <= r)             ans++;         }         cout << ans << endl;         ans = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       if (n == 1) {         printf( YES n%d n , m);       } else if (n == 2) {         if (m == 0) {           printf( NO n );         } else {           printf( YES n0 %d n , m);         }       } else {         int x = 1 << 18, y = 1 << 19, z = 0;         printf( YES n );         for (int i = 1; i <= n - 3; i++) {           printf( %d  , i);           z = z ^ i;         }         printf( %d %d %d n , x, y, (x ^ y ^ z ^ m));       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int expo(long long int base, long long int exponent,                      long long int mod) {     long long int ans = 1;     while (exponent > 0) {       if (exponent % 2 == 1) {         ans *= base;         ans %= mod;       }       base *= base;       base %= mod;       exponent /= 2;     }     return ans;   }   const long long int M = 3000006;   long long int f[M], inv[M];   void compute() {     f[0] = 1;     for (long long int i = 1; i <= M - 1; i++) {       f[i] = (1LL * i * f[i - 1]) % mod;     }     inv[M - 1] = expo(f[M - 1], mod - 2, mod);     for (long long int i = M - 2; i >= 0; i--) {       inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod;     }   }   long long int C(long long int n, long long int r) {     return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod;   }   long long int h[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1;     while (tests--) {       long long int i, j, n;       cin >> n;       for (long long int i = 1; i <= n; i++) cin >> h[i];       long long int tmp = 0;       vector<long long int> res(n + 1);       for (long long int i = 1; i <= n; i++) {         tmp = min(tmp, h[i] - i);         res[i] = tmp + i;       }       tmp = 0;       for (i = n; i >= 1; i--) {         tmp = min(tmp, h[i] - (n + 1 - i));         res[i] = min(res[i], tmp + (n + 1 - i));       }       long long int ans = 0;       for (long long int i = 1; i <= n; i++) ans = max(ans, res[i]);       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fRand(double fMin, double fMax) {     double f = (double)rand() / RAND_MAX;     return fMin + f * (fMax - fMin);   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   int n, a[100005], cnt[100005];   vector<int> d[100005];   int power(int x, int n) {     if (n == 0) return 1;     if (n & 1) return ((long long)x * power(x, n - 1)) % 1000000007;     int p = power(x, n / 2);     return ((long long)p * p) % 1000000007;   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       scanf( %d , &a[i]);       ++cnt[a[i]];     }     int m = *max_element(a + 1, a + n + 1);     for (int x = (1); x <= (m); ++x) cnt[x] += cnt[x - 1];     for (int x = (1); x <= (m); ++x)       for (int i = (x); i <= (m); i += x) d[i].push_back(x);     int ans = 0;     for (int x = (1); x <= (m); ++x) {       int k = (int)d[x].size(), q[k];       for (int i = (0); i <= (k - 2); ++i)         q[i] = cnt[d[x][i + 1] - 1] - cnt[d[x][i] - 1];       q[k - 1] = cnt[m] - cnt[d[x][k - 1] - 1];       int prod = 1;       for (int i = (0); i <= (k - 2); ++i)         prod = ((long long)prod * power(i + 1, q[i])) % 1000000007;       prod = ((long long)prod *               (power(k, q[k - 1]) - power(k - 1, q[k - 1]) + 1000000007)) %              1000000007;       ans = (ans + prod) % 1000000007;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1001000;   int f[maxn], rx[maxn], ry[maxn], ans[maxn], pre_rx[maxn], pre_ry[maxn];   struct node {     int num, x, y;   } mp[maxn];   int find(int x) {     while (x != f[x]) x = f[x] = f[f[x]];     return f[x];   }   void merge(int x, int y) {     int xx = find(x), yy = find(y);     if (xx != yy) f[yy] = xx;   }   bool cmp(node x, node y) { return x.num < y.num; }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int cnt = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %d , &mp[(i - 1) * m + j]);         mp[cnt].x = i, mp[cnt++].y = j;         f[(i - 1) * m + j] = (i - 1) * m + j;       }     sort(mp + 1, mp + n * m + 1, cmp);     int k;     for (int i = 1; i <= n * m; i = k) {       for (k = i + 1; k <= n * m && mp[k].num == mp[i].num; k++)         ;       for (int j = i; j < k; j++) {         int x = mp[j].x, y = mp[j].y;         if (!rx[x])           rx[x] = (x - 1) * m + y;         else           merge(rx[x], (x - 1) * m + y);         if (!ry[y])           ry[y] = (x - 1) * m + y;         else           merge(ry[y], (x - 1) * m + y);       }       for (int j = i; j < k; j++) {         int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y);         ans[r] = max(ans[r], max(pre_rx[x], pre_ry[y]) + 1);       }       for (int j = i; j < k; j++) {         int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y);         ans[(x - 1) * m + y] = ans[r];         pre_rx[x] = pre_ry[y] = ans[r];         rx[x] = 0, ry[y] = 0;       }     }     for (int i = 1; i <= n * m; i++) {       if (i % m == 0)         printf( %d n , ans[i]);       else         printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct vec {     long double x, y;     bool operator==(const vec &a) const { return x == a.x && y == a.y; }     bool operator<(const vec &a) const {       if (a.x != x) return x < a.x;       return y < a.y;     }     vec operator+(const vec &a) const { return {x + a.x, y + a.y}; }     vec operator*(const long double &a) const { return {x * a, y * a}; }     vec operator-(const vec &a) const { return {x - a.x, y - a.y}; }     vec operator/(const long double &a) const { return {x / a, y / a}; }     long double len() const { return sqrt(x * x + y * y); }     long double dot(const vec &a) const { return x * a.x + y * a.y; }     long double crs(const vec &a) const { return x * a.y - y * a.x; }     vec proj(const vec &a) const {       return (a / a.len()) * (*this).dot(a) / a.len();     }   };   struct P {     int x, y;     bool operator<(const P &a) const {       if (x != a.x) return x > a.x;       return y < a.y;     }   };   bool as(P a, P b) { return a.x < b.x; }   long long x, y, z, mod = 1000000007;   vector<int> v1, v, v2;   int i, n, m, k, a, d, b, c, dx[10] = {1, 0, -1, 0}, dy[10] = {0, 1, 0, -1};   int e[511112];   int l[511155];   int o[511110];   int j[511112];   stack<int> s;   queue<int> q, q1;   P u[533111];   string r, r1;   map<int, int> p, p1;   int main() {     scanf( %d %d , &a, &b);     for (int t = 1; t <= a; t++) scanf( %d , &j[t]);     for (int t = 1; t <= b; t++) {       v.clear();       scanf( %d , &n);       d = n;       e[d] = 1 - e[d];       n = j[n];       if (n == 1) {         c -= o[n];         if (e[d])           o[n]++;         else           o[n]--;         c += o[n];         goto qwe;       }       m = n;       for (int i = 2; i * i <= n; i++) {         if (n % i == 0) {           v.push_back(i);           for (; n % i == 0; n /= i)             ;         }       }       if (n > 1) v.push_back(n);       n = m;       c -= o[n];       if (e[d])         o[n]++;       else         o[n]--;       c += o[n];       for (int i = 1; i < (1 << v.size()); i++) {         int k = 0, p = 1;         for (int t = i, j = 0; t; j++, k += t % 2, k %= 2, t /= 2)           if (t % 2) p *= v[j];         if (e[d]) {           if (k)             x += l[p];           else             x -= l[p];           l[p]++;         } else {           l[p]--;           if (k)             x -= l[p];           else             x += l[p];         }       }     qwe:;       printf( %lld n , (long long)c * (c - 1) / 2 - x);     }   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   char p[102][102];   int main() {     int n;     scanf( %d n , &n);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) p[i][j] = getchar();       getchar();     }     bool foo = true;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         int cnt = 0;         if (p[i - 1][j] ==  o ) ++cnt;         if (p[i][j - 1] ==  o ) ++cnt;         if (p[i][j + 1] ==  o ) ++cnt;         if (p[i + 1][j] ==  o ) ++cnt;         if (cnt % 2) {           foo = false;           break;         }       }     }     if (foo)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1 >> s2;     int n = s1.length(), p = 0, a = 0, p2 = 0;     for (int i = 0; i < n; i++)       if (s1[i] ==  + ) p++;     int m = n - p;     for (int i = 0; i < n; i++) {       if (s2[i] ==  ? )         a++;       else if (s2[i] ==  + )         p2++;     }     int m2 = n - a - p2;     if (abs(p2 - p) <= a && abs(m2 - m) <= a) {       float y = abs(p2 - p), ans = 1;       y = min(y, a - y);       for (int i = a; i > a - y; i--) ans *= i;       for (int i = 2; i <= y; i++) ans /= i;       float s = pow(2, a);       printf( %.9f , ans / s);     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void printopt(int p) {     for (int i = p / 2; i; i--) printf( 4 );     for (int i = p / 2; i; i--) printf( 7 );   }   char s[100000 + 2];   char s47[100000 + 2];   int n;   bool fopt(int i, int ddif47) {     if (abs(ddif47) > n - i) return 0;     int j = i;     for (; j < i + (n - i - ddif47) / 2; j++) s47[j] =  4 ;     for (; j < n; j++) s47[j] =  7 ;     return 1;   }   bool f(int i, int dif47) {     if (i == n) return dif47 == 0;     switch (s[i] -  0 ) {       case 0:       case 1:       case 2:       case 3:         if (fopt(i, dif47)) return 1;         break;       case 4:         s47[i] =  4 ;         if (f(i + 1, dif47 + 1)) return 1;         s47[i] =  7 ;         if (fopt(i + 1, dif47 - 1)) return 1;         break;       case 5:       case 6:         s47[i] =  7 ;         if (fopt(i + 1, dif47 - 1)) return 1;         break;       case 7:         s47[i] =  7 ;         if (f(i + 1, dif47 - 1)) return 1;         break;       case 8:       case 9:         break;     }     return 0;   }   int main() {     scanf( %s , s);     n = strlen(s);     if (n % 2)       printopt(n + 1);     else if (f(0, 0))       printf( %s , s47);     else       printopt(n + 2);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vector<int>>;   using pii = pair<int, int>;   constexpr int N = 300001;   struct Ed {     int u, v;     bool s;   };   vector<pii> g[N], t[N];   int d[N], low[N], biconn[N];   bool scored[N], vis[N];   int tim = 1, compno = 1;   pii p[N];   void dfs(int u, int p) {     low[u] = d[u] = tim++;     for (const auto& pr : g[u]) {       if (pr.first == p) continue;       if (d[pr.first] != 0) {         low[u] = min(low[u], d[pr.first]);       } else {         dfs(pr.first, u);         low[u] = min(low[u], low[pr.first]);       }     }   }   void comp(int u, int p, int c) {     if (biconn[u] != 0) return;     if (low[u] == d[u]) c = ++compno;     biconn[u] = c;     for (const auto& pr : g[u]) {       if (pr.second && biconn[pr.first] == c) scored[c] = true;       if (pr.first == p && biconn[p] != c) {         t[c].push_back({biconn[p], pr.second});         t[biconn[p]].push_back({c, pr.second});       } else if (biconn[pr.first] == 0)         comp(pr.first, u, c);     }   }   void solve() {     int n, m, x, y, z, a, b;     cin >> n >> m;     while (m--) {       cin >> x >> y >> z;       g[x].push_back({y, z});       g[y].push_back({x, z});     }     cin >> a >> b;     dfs(a, -1);     comp(a, -1, 1);     a = biconn[a];     b = biconn[b];     queue<int> q;     q.push(a);     vis[a] = true;     while (!q.empty()) {       int u = q.front();       q.pop();       for (const auto& v : t[u])         if (!vis[v.first]) {           p[v.first] = {u, v.second};           q.push(v.first);           vis[v.first] = true;         }     }     bool ok = scored[a];     while (!ok && b != a) {       if (scored[b] || p[b].second) ok = true;       b = p[b].first;     }     cout << (ok ?  YES n  :  NO n );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int search(long long int *array, int start_idx, int end_idx,              long long int search_val) {     if (start_idx == end_idx)       return array[start_idx] <= search_val ? start_idx : -1;     int mid_idx = start_idx + (end_idx - start_idx) / 2;     if (search_val < array[mid_idx])       return search(array, start_idx, mid_idx, search_val);     int ret = search(array, mid_idx + 1, end_idx, search_val);     return ret == -1 ? mid_idx : ret;   }   long long int C(long long int k) { return (k * (k - 1)) / 2; }   int main() {     ios_base::sync_with_stdio;     cin.tie(NULL);     long long int n, d;     cin >> n >> d;     long long int arr[n];     for (long long int i = 0; i < n; i++) cin >> arr[i];     long long int ways = 0, current, maxallowed, index2, previndex2;     for (long long int i = 0; i < n; i++) {       current = arr[i];       maxallowed = current + d;       index2 = search(arr, 0, n - 1, maxallowed);       if (index2 - i + 1 >= 3) {         ways += C(index2 - i);       }     }     cout << ways;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 10;   const int mod = 998244353;   const int N = 2e5 + 6;   int pk = 30;   int a[N];   struct Trie {     static const int N = 15101000, M = 2;     int ne[N][M], rt, L, sum[N], ans[N];     void ini() {       fill_n(sum, N, 0);       L = 0, rt = newnode();     }     int newnode() {       fill_n(ne[L], M, 0);       return L++;     }     void add(int k, int x, int v) {       int p = rt;       for (int i = pk; i >= 0; i--) {         int c = (x >> i) & 1;         if (!ne[p][c]) ne[p][c] = newnode();         p = ne[p][c];       }       sum[p] += v;     }     int qry(int x) {       int p = rt;       for (int i = pk; i >= 0; i--) {         int c = (x >> i) & 1;         if (ne[p][c] && sum[ne[p][c]])           p = ne[p][c];         else           p = ne[p][!c];       }       return ans[p];     }     int solve() {       int res = 0;       for (int i = L - 1; i >= 0; i--) {         if (sum[i] > 0) continue;         if (!ne[i][0] || !ne[i][1])           sum[i] = sum[ne[i][0]] + sum[ne[i][1]];         else {           int c0 = ne[i][0], c1 = ne[i][1];           if (sum[c0] <= 1 || sum[c1] <= 1)             sum[i] = sum[c0] + sum[c1];           else {             if (sum[c0] < sum[c1])               res += sum[c0] - 1, sum[i] = sum[c1] + 1;             else               res += sum[c1] - 1, sum[i] = sum[c0] + 1;           }         }       }       return res;     }   } T;   int s[N], f[N];   int find(int x) {     if (f[x] == x) return x;     return f[x] = find(f[x]);   }   int main() {     int n, m;     T.ini();     scanf( %d , &n);     for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]), T.add(i, a[i], 1);     int ans = T.solve();     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool fs(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c <  0  || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   double fun(int h, double c, int n) {     double ans;     if (h % n == 0)       ans = h / n;     else       ans = h / n + 1;     return ans * c;   }   int main() {     int h, n;     double a, b, d, c;     double res = 20 / 100, x, y;     cin >> a >> b;     cin >> h >> d >> c >> n;     a = a * 60 + b;     b = 20 * 60 - a;     if (a >= 1200)       cout << fun(h, c - c * 20 / 100, n) << endl;     else       cout << min(fun(h + b * d, c - c * 20 / 100, n), fun(h, c, n)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool mark[100];   vector<pair<int, int> > coors;   void DFS(int ver) {     mark[ver] = true;     for (int i = 0; i < coors.size(); i++)       if ((coors[ver].first == coors[i].first ||            coors[ver].second == coors[i].second) &&           !mark[i])         DFS(i);   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     coors.resize(n);     for (int i = 0; i < n; i++) {       pair<int, int> tmp;       cin >> tmp.first >> tmp.second;       coors[i] = tmp;     }     int ans = -1;     for (int i = 0; i < n; i++) {       if (!mark[i]) {         ans++;         DFS(i);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int PMAX = 61;   long long shift[PMAX];   inline int logbin(long long x) { return 63 - __builtin_clzll(x); }   inline void modif(int p, long long k) {     shift[p] += k;     shift[p] %= (1ll << p);   }   int main() {     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int t;       scanf( %d , &t);       if (t == 1) {         long long x, k;         scanf( %I64d%I64d , &x, &k);         int p = logbin(x);         k = ((k % (1ll << p)) + (1ll << p)) % (1ll << p);         modif(p, k);       } else if (t == 2) {         long long x, k;         scanf( %I64d%I64d , &x, &k);         int p = logbin(x);         k = ((k % (1ll << p)) + (1ll << p)) % (1ll << p);         for (int i = p; i < PMAX; i++, k *= 2) modif(i, k);       } else {         long long x;         scanf( %I64d , &x);         for (int p = logbin(x); p >= 0; p--) {           printf( %lld  , x);           x = (1ll << p) + (x + shift[p] + (1ll << p)) % (1ll << p);           x /= 2;           if (p > 0)             x = (1ll << (p - 1)) +                 (x - shift[p - 1] + (1ll << (p - 1))) % (1ll << (p - 1));         }         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   int prime(long long n) {     if (n < 2) return 0;     if (n == 2 || n == 3) return 1;     if (n % 6 != 1 && n % 6 != 5) return 0;     for (long long i = 5; i <= sqrt(n); i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return 0;     }     return 1;   }   int t, r, g, b;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> r >> g >> b;       int mx = max(b, max(r, g));       int ans = min((r + g + b) / 2, r + g + b - mx);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class myistream {     static const int maxsize = 1000007, tmpsize = 50;     char *s, *tmp;     char *cur, *upperbound;     FILE *fp;     bool last_read;     bool end_of_file;     bool to_return;     void upd() {       int num = fread(s, sizeof(char), maxsize, fp);       if (num < maxsize) last_read = true, upperbound = s + num;       if (!num) end_of_file = true;       cur = s;     }     char scan() {       if (cur >= upperbound) {         if (last_read)           end_of_file = true;         else           upd();       }       return *cur++;     }     bool isspace(char c) {       return c ==     || c ==   n  || c ==   r  || c ==   t ;     }       public:     myistream(FILE *_fp)         : last_read(false), end_of_file(false), to_return(false), fp(_fp) {       s = new char[maxsize + 2];       tmp = new char[tmpsize + 2];       upperbound = s + maxsize;       cur = s + maxsize;     }     ~myistream() {       delete[] s;       delete[] tmp;       fclose(fp);     }     operator void *() const { return to_return ? 0 : (void *)this; }     bool operator!() const { return to_return; }     myistream &operator>>(int &a) {       if (!end_of_file) {         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         if (end_of_file) {           to_return = true;           return *this;         }         a = 0;         bool nega = false;         if (c ==  - ) nega = true, c = scan();         while (!isspace(c) && !end_of_file) {           a = a * 10 + (((int)c) & 15);           c = scan();         }         if (nega) a = -a;       } else         to_return = true;       return *this;     }     myistream &operator>>(long long &a) {       if (!end_of_file) {         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         if (end_of_file) {           to_return = true;           return *this;         }         a = 0;         bool nega = false;         if (c ==  - ) nega = true, c = scan();         while (!isspace(c) && !end_of_file) {           a = a * 10 + (((long long)c) & 15);           c = scan();         }         if (nega) a = -a;       } else         to_return = true;       return *this;     }     myistream &operator>>(char &c) {       if (!end_of_file) {         c = scan();         while (isspace(c) && !end_of_file) c = scan();       }       if (end_of_file) to_return = true;       return *this;     }     myistream &operator>>(bool &b) {       if (!end_of_file) {         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         b = (c ==  1 );       }       if (end_of_file) to_return = true;       return *this;     }     myistream &operator>>(char *s) {       if (!end_of_file) {         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         if (end_of_file) {           to_return = true;           return *this;         }         while (!isspace(c) && !end_of_file) *s++ = c, c = scan();         *s =   0 ;       } else         to_return = true;       return *this;     }     myistream &operator>>(string &s) {       s.clear();       if (!end_of_file) {         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         if (end_of_file) {           to_return = true;           return *this;         }         while (!isspace(c) && !end_of_file) s.push_back(c), c = scan();       } else         to_return = true;       return *this;     }     myistream &operator>>(double &d) {       if (!end_of_file) {         char *tp = tmp;         char c = scan();         while (isspace(c) && !end_of_file) c = scan();         if (end_of_file) {           to_return = true;           return *this;         }         while (!isspace(c) && !end_of_file) *tp++ = c, c = scan();         *tp =   0 ;         sscanf(tmp,  %lf , &d);       } else         to_return = true;       return *this;     }   };   class myostreamEndlType {};   class myostreamSetPrecisionType {    public:     int precision;     myostreamSetPrecisionType(int _precision) : precision(_precision) {}   };   class myostream {     static const int maxsize = 1000007, tmpsize = 50;     char *s, *upperbound, *cur, *tmp;     FILE *fp;     int numberAfterPoint;     char doubleFormat[20];     void write(char c) {       if (cur >= upperbound) {         fwrite(s, sizeof(char), maxsize, fp);         cur = s;       }       *cur++ = c;     }       public:     myostream(FILE *_fp) : fp(_fp) {       s = new char[maxsize];       tmp = new char[tmpsize + 2];       upperbound = s + maxsize;       cur = s;       precision(6);     }     ~myostream() {       fwrite(s, sizeof(char), cur - s, fp);       fclose(fp);       delete[] s;     }     void precision(int x) {       numberAfterPoint = x;       sprintf(doubleFormat,  %%.%dlf , x);     }     int precision(void) { return numberAfterPoint; }     myostream &operator<<(const myostreamSetPrecisionType &p) {       precision(p.precision);       return *this;     }     myostream &operator<<(const char &c) {       write(c);       return *this;     }     myostream &operator<<(const myostreamEndlType &e) {       write(  n );       return *this;     }     myostream &operator<<(const bool &b) {       write(b ?  1  :  0 );       return *this;     }     myostream &operator<<(const char *c) {       for (const char *p = c; *p; p++) write(*p);       return *this;     }     myostream &operator<<(const string &c) { return *this << c.c_str(); }     myostream &operator<<(const int &a) {       if (a == 0) {         write( 0 );         return *this;       }       int s = a;       if (s < 0) write( - ), s = -s;       char *tp = tmp;       while (s > 0) {         *tp++ = char((s % 10) | 48);         s /= 10;       }       for (--tp; tp >= tmp; --tp) write(*tp);       return *this;     }     myostream &operator<<(const long long &a) {       if (a == 0) {         write( 0 );         return *this;       }       long long s = a;       if (s < 0) write( - ), s = -s;       char *tp = tmp;       while (s > 0) {         *tp++ = char((s % 10) | 48);         s /= 10;       }       for (--tp; tp >= tmp; --tp) write(*tp);       return *this;     }     myostream &operator<<(const double &d) {       sprintf(tmp, doubleFormat, d);       *this << tmp;       return *this;     }   };   const int maxn = 100050, inf = 0x3fffffff;   int n, m, k;   bool hasv[maxn] = {};   int s, t;   vector<int> buf[maxn];   bool judge(int maxV) {     static bool inq[maxn];     static int dis[maxn];     memset(inq, false, sizeof inq);     fill(dis, dis + n, inf);     queue<int> q;     dis[s] = 0;     q.push(s);     inq[s] = true;     while (!q.empty()) {       int x = q.front();       q.pop();       inq[x] = false;       if (dis[x] < maxV)         for (auto it = (buf[x]).begin(); it != (buf[x]).end(); ++it) {           int tmp = dis[x] + 1;           if (hasv[*it]) tmp = 0;           if (dis[*it] > tmp) {             dis[*it] = tmp;             if (!inq[*it]) {               inq[*it] = true;               q.push(*it);             }           }         }     }     return dis[t] < inf;   }   int main(void) {     cin >> n >> m >> k;     while (k--) {       int a;       cin >> a;       --a;       hasv[a] = true;     }     while (m--) {       int a, b;       cin >> a >> b;       --a;       --b;       buf[a].push_back(b);       buf[b].push_back(a);     }     cin >> s >> t;     --s;     --t;     int left = 1, right = n + 1;     while (left < right) {       int mid = (left + right) >> 1;       if (judge(mid))         right = mid;       else         left = mid + 1;     }     if (left > n)       cout << -1 << endl;     else       cout << left << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int R = 0;     int d = 0;     int n = 0;     cin >> R;     cin >> d;     cin >> n;     int x;     int y;     int r;     int counter = 0;     double low = 0;     double high = 0;     for (int i = 0; i < n; i++) {       cin >> x;       cin >> y;       cin >> r;       if (((sqrt(x * x + y * y) - r) >= (R - d)) &&           ((sqrt(x * x + y * y) + r) <= R))         counter++;     }     cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;          bool checktwo(long long int n){if(n==0){return false;}else{return (ceil(log2(n)) == floor(log2(n)));}}   long long int powerof2lte(long long int n){int p = (long long int)log2(n);return (long long int)pow(2, p);}    long long int numdigits(long long int n){return floor(log10(n)) + 1; }      int main()   {       long long int n;       cin>>n;       cout<<2 - (n*n)<<  n ;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[131072], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 131072, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int& x) {     x = 0;     char c = gc();     while (c <  0  || c >  9 ) c = gc();     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = gc();     }   }   int fa[100003], son[100003][2], st[100003], a[100003], sum[100003],       size[100003], tag[100003];   bool rev[100003];   int n, q;   inline void pushup(int u) {     sum[u] = sum[son[u][0]] + sum[son[u][1]] + a[u];     size[u] = size[son[u][0]] + size[son[u][1]] + 1;   }   inline bool notrt(const int& u) {     return son[fa[u]][0] == u || son[fa[u]][1] == u;   }   inline void pushr(const int& u) {     swap(son[u][0], son[u][1]);     rev[u] ^= 1;   }   inline void pushc(const int& u, const int& k) {     a[u] = tag[u] = k;     sum[u] = k == 0 ? 0 : size[u];   }   inline void pushdown(const int& u) {     if (tag[u] != -1) {       if (son[u][0]) pushc(son[u][0], tag[u]);       if (son[u][1]) pushc(son[u][1], tag[u]);       tag[u] = -1;     }     if (!rev[u]) return;     if (son[u][0]) pushr(son[u][0]);     if (son[u][1]) pushr(son[u][1]);     rev[u] = 0;   }   inline void rotate(const int& x) {     int y = fa[x], z = fa[y];     int k = son[y][1] == x, w = son[x][k ^ 1];     if (notrt(y)) son[z][son[z][1] == y] = x;     son[x][k ^ 1] = y;     son[y][k] = w;     if (w) fa[w] = y;     fa[y] = x, fa[x] = z;     pushup(y);   }   inline void splay(const int& x) {     register int y = x, z = 0;     st[++z] = y;     while (notrt(y)) st[++z] = y = fa[y];     while (z) pushdown(st[z--]);     while (notrt(x)) {       y = fa[x], z = fa[y];       if (notrt(y)) rotate((son[z][1] == y) == (son[y][1] == x) ? y : x);       rotate(x);     }     pushup(x);   }   inline void access(int u) {     for (register int v = 0; u; u = fa[u]) {       splay(u), son[u][1] = v;       pushup(u), v = u;     }   }   inline void makeroot(int u) {     access(u), splay(u);     pushr(u);   }   inline void link(int u, int v) {     makeroot(u);     fa[u] = v;   }   inline void split(int u, int v) {     makeroot(u);     access(v), splay(v);   }   inline int check(int u1, int v1, int u2, int v2) {     split(u1, v1), pushc(v1, 1);     split(u2, v2);     int res = sum[v2];     split(u1, v1), pushc(v1, 0);     return res;   }   int main() {     int x, y, z, ans;     read(n), read(q);     for (register int i = 1; i <= n; ++i) tag[i] = -1;     for (register int i = 2; i <= n; ++i) {       read(x);       link(x, i);     }     while (q--) {       read(x), read(y), read(z);       ans = check(x, y, x, z);       ans = max(ans, check(x, y, y, z));       ans = max(ans, check(x, z, y, z));       printf( %d n , ans);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int maxn=1e4+10;   int vis[maxn];   int a[maxn];   int main()   {       int T;       scanf( %d ,&T);       while(T--){           int n,d;           scanf( %d%d ,&n,&d);           for(int i=1;i<=n;i++){               scanf( %d ,&a[i]);           }           for(int k=1;k<=n;k++){               int tmp=a[k];               int x=tmp/d;               int y=tmp%d;               if(!y) printf( YES n );               else{                   int flag=10000;                   for(int i=2;i<=9;i++){                       if(i*d%10==d-y){                           flag=i;                           break;                       }                   }                   if(flag==10000) flag=10;                   if(flag<=x) printf( YES n );                   else printf( NO n );               }           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   char to_da(char c) {     if (c >=  A  && c <=  Z )       return c;     else       return c - 32;   }   char to_xiao(char c) {     if (c >=  A  && c <=  Z )       return c + 32;     else       return c;   }   int main() {     string s;     int a;     while (cin >> s >> a) {       int len = s.length();       for (int i = 0; i < len; i++) {         s[i] = to_xiao(s[i]);         if (s[i] < a + 97)           s[i] = to_da(s[i]);         else           s[i] = to_xiao(s[i]);       }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<string> S;     long n;     string a;     cin >> n;     for (long i = 0; i < n; i++) {       cin >> a;       string s =   ;       long j = 0;       while (j < a.size()) {         if (a[j] ==  k ) {           long k = j;           while (a[k] ==  k ) k++;           if (a[k] ==  h ) {             j = k;             s = s +  kh ;           } else {             s.push_back(a[j]);           }         } else if (a[j] ==  u ) {           s = s +  oo ;         } else if (a[j] ==  h ) {           s = s +  kh ;         } else {           s.push_back(a[j]);         }         j++;       }       S.insert(s);     }     cout << S.size();   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int nm = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) nm = nm * 10 + c -  0 ;     return nm * f;   }   long long n, x, y;   char s[300010];   int main() {     n = read(), x = read(), y = read();     scanf( %s , s + 1);     int len = strlen(s + 1);     s[0] =  ? ;     long long tot = 0;     for (int i = 1; i <= len; i++)       if (s[i] != s[i - 1] && s[i] ==  0 ) tot++;     if (tot == 0) return puts( 0 );     cout << min(tot * y, tot * x - x + y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int pre[N];   int find(int x) {     if (!pre[x]) return x;     return pre[x] = find(pre[x]);   }   int d[510][510];   struct point {     int x, y, z;     void read() { scanf( %d%d%d , &x, &y, &z); }   } a[N];   int type[N];   int main() {     int n, m, r, x, y;     scanf( %d%d%d , &n, &m, &r);     int t = 0;     for (int i = 1; i <= r; i++) {       scanf( %d , &x);       while (x--) type[++t] = i;     }     for (int i = 1; i <= m; i++) {       a[i].read();       if (a[i].z == 0) {         x = find(a[i].x);         y = find(a[i].y);         if (x != y) pre[x] = y;       }     }     for (int i = 2; i <= n; i++)       if (type[i] == type[i - 1] && find(i) != find(i - 1)) {         cout <<  No  << endl;         return 0;       }     memset(d, -1, sizeof(d));     for (int i = 1; i <= m; i++) {       x = type[a[i].x], y = type[a[i].y];       if (d[x][y] == -1)         d[y][x] = d[x][y] = a[i].z;       else         d[y][x] = d[x][y] = min(d[x][y], a[i].z);     }     for (int i = 1; i <= r; i++) d[i][i] = 0;     for (int k = 1; k <= r; k++)       for (int i = 1; i <= r; i++)         for (int j = 1; j <= r; j++)           if (d[i][k] != -1 && d[k][j] != -1)             if (d[i][j] == -1)               d[i][j] = d[i][k] + d[k][j];             else               d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     cout <<  Yes  << endl;     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= r; j++) {         printf( %d  , d[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, n, x, y;     cin >> a >> b >> c >> d >> n;     if (c < d) swap(a, b), swap(c, d);     cout << max(0, n - (c - 1) * a - (d - 1) * b) <<    ;     if (b * d >= n) {       cout << n / d;       return 0;     }     cout << b + (n - b * d) / c;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int lim = sqrt(n) + 1;     if (!(n & 1)) {       cout << n / 2 << endl;       return 0;     }     for (long long int i = 3; i <= lim + 1; i++) {       if (n % i == 0) {         cout << (n - i) / 2 + 1 << endl;         return 0;       }     }     puts( 1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   bool conn[8][8];   int a, b;   int v[8];   int cur;   bool used[8][8];   int best, cur2, cur3, cur4, ans;   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) {       cin >> a >> b;       conn[a][b] = conn[b][a] = true;     }     for (int i = 0; i < 279936; i++) {       cur = i;       for (int j = 0; j < 6; j++) {         for (int k = 0; k < 6; k++) {           used[j][k] = false;         }       }       for (int j = 0; j < 7; j++) {         v[j] = cur % 6;         cur /= 6;       }       cur2 = 0;       for (int j = 1; j <= N; j++) {         for (int k = j + 1; k <= N; k++) {           if (conn[j][k]) {             cur3 = v[j];             cur4 = v[k];             if (cur3 > cur4) {               swap(cur3, cur4);             }             if (!used[cur3][cur4]) {               ++cur2;               used[cur3][cur4] = true;             }           }         }       }       ans = max(ans, cur2);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int lar(long long int a, long long int b) {     return ((a >= b) ? a : b);   }   long long int les(long long int a, long long int b) {     return ((a <= b) ? a : b);   }   int main() {     string s;     cin >> s;     vector<string> v;     long long int a = 0, b = 0;     for (long long int i = 0; i < s.size(); i++) {       if (s[i] ==  4 )         a++;       else if (s[i] ==  7 )         b++;     }     if (a == 0 && b == 0) {       cout << -1 << endl;       return 0;     }     if (a >= b)       cout <<  4  << endl;     else       cout <<  7  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[200005];   bool can(long long val, long long n, long long k) {     int m = (n + 1) / 2;     long long sum = 0;     for (int i = m; i <= n; i++) {       if (val > arr[i])         sum += val - arr[i];       else         break;     }     if (sum <= k)       return true;     else       return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     sort(arr + 1, arr + n + 1);     long long l = arr[(n + 1) / 2];     long long h = 3000000001;     while (l < h - 1) {       long long m = (l + h) / 2;       if (can(m, n, k)) {         l = m;       } else {         h = m;       }     }     if (can(h, n, k)) l = h;     cout << l <<   n ;   }