#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > G[500005];   int sz[500005];   vector<int> *vec[500005];   int cnt[(1 << 23) + 5];   int lazy[500005];   int len[500005];   int res[500005];   void get_ready(int u, int par, int mask, int hh) {     sz[u] = 1;     len[u] = hh;     lazy[u] = mask;     for (auto v : G[u])       if (v.first != par)         get_ready(v.first, u, mask ^ v.second, hh + 1), sz[u] += sz[v.first];   }   void DFS(int u, int par, int keep, int mask) {     int node = -1, mx = 0, xr = 0;     for (auto x : G[u]) {       int v = x.first;       if (par != v and sz[v] > mx) {         mx = sz[v], node = v, xr = x.second;       }     }     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) DFS(v, u, 0, x.second);     }     if (node != -1) {       DFS(node, u, 1, xr);       vec[u] = vec[node];       res[u] = max(res[u], res[node]);     } else       vec[u] = new vector<int>;     for (int i = 1; i <= (1 << 22); i <<= 1) {       res[u] = max(res[u], cnt[lazy[u] ^ i] - len[u]);     }     res[u] = max(res[u], cnt[lazy[u]] - len[u]);     cnt[lazy[u]] = max(cnt[lazy[u]], len[u]);     vec[u]->push_back(u);     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) {         res[u] = max(res[u], res[v]);         for (auto vv : *vec[v]) {           for (int i = 1; i <= (1 << 22); i <<= 1) {             res[u] = max(res[u], len[vv] + cnt[lazy[vv] ^ i] - 2 * len[u]);           }           res[u] = max(res[u], len[vv] + cnt[lazy[vv]] - 2 * len[u]);         }         for (auto vv : *vec[v]) {           int temp = lazy[vv];           cnt[temp] = max(cnt[temp], len[vv]);           vec[u]->push_back(vv);         }         vec[v]->clear();       }     }     if (!keep) {       for (auto v : *vec[u]) cnt[lazy[v]] = -1000000000;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     for (int i = 0; i < (1 << 23) + 5; i++) cnt[i] = -1000000000;     int N;     cin >> N;     for (int i = 2; i <= N; i++) {       string ch;       int p;       cin >> p >> ch;       G[p].push_back({i, 1 << (ch[0] -  a )});       G[i].push_back({p, 1 << (ch[0] -  a )});     }     get_ready(1, -1, 0, 0);     DFS(1, -1, 1, 0);     for (int i = 1; i <= N; i++) cout << res[i] <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   long long sum[500000 + 10];   int data[500000 + 10];   int main() {     int n, l, r, ql, qr;     scanf( %d%d%d%d%d , &n, &l, &r, &ql, &qr);     for (int i = 1; i <= n; ++i) {       scanf( %d , &data[i]);       sum[i] += (sum[i - 1] + data[i] * r);     }     long long ans = 100000000000000;     long long tem = 0;     for (int i = 0; i <= n; ++i) {       tem += data[i] * l;       if (0 == i)         ans = min(ans, sum[n] + (n - 1) * qr);       else if (n == i)         ans = min(ans, tem + (n - 1) * ql);       else if (i == (n - i)) {         ans = min(ans, tem + sum[n] - sum[i]);       } else if (i < (n - i))         ans = min(ans, tem + sum[n] - sum[i] + (n - i - i - 1) * qr);       else         ans = min(ans, tem + sum[n] - sum[i] + (2 * i - n - 1) * ql);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, x;   char s[3];   int main() {     cin >> n;     while (n--) {       cin >> s;       if (s[0] ==  a ) {         cin >> x;         v.insert(lower_bound(v.begin(), v.end(), x), x);       }       if (s[0] ==  d ) {         cin >> x;         v.erase(lower_bound(v.begin(), v.end(), x));       }       if (s[0] ==  s ) {         long long ans = 0;         for (int i = 2; i < v.size(); i += 5) {           ans += v[i];         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long M = 1e5 + 1;   vector<int> len;   vector<int> dist[N];   vector<long long> pre[N];   long long n, m;   void mer(long long v, long long l, long long addl, long long r,            long long addr) {     dist[v].push_back(0);     long long sl = dist[l].size();     long long sr = dist[r].size();     long long pl = 0;     long long pr = 0;     while (pl < sl && pr < sr) {       if (dist[l][pl] + addl <= dist[r][pr] + addr) {         dist[v].push_back(dist[l][pl] + addl);         pl++;       } else {         dist[v].push_back(dist[r][pr] + addr);         pr++;       }     }     while (pl < sl) {       dist[v].push_back(dist[l][pl] + addl);       pl++;     }     while (pr < sr) {       dist[v].push_back(dist[r][pr] + addr);       pr++;     }     return;   }   void bfs(long long v) {     if (v > n) return;     long long l = 2 * v;     long long r = 2 * v + 1;     bool cl = false, cr = false;     if (l <= n) {       bfs(l);       cl = true;     }     if (r <= n) {       bfs(r);       cr = true;     }     if (cl && cr) {       long long addl = len[2 * v - 1];       long long addr = len[2 * v];       mer(v, l, addl, r, addr);     } else if (cl && !cr) {       long long addl = len[2 * v - 1];       dist[v].push_back(0);       for (long long x : dist[l]) dist[v].push_back(addl + x);     } else if (cr && !cl) {       long long addr = len[2 * v];       dist[v].push_back(0);       for (long long x : dist[r]) dist[v].push_back(addr + x);     } else {       dist[v].push_back(0);     }     long long sze = dist[v].size();     pre[v].resize(sze);     long long prev = 0ll;     for (long long i = 0; i < sze; i++) {       pre[v][i] = prev + dist[v][i];       prev = pre[v][i];     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     len.push_back(-1);     cin >> n >> m;     for (long long i = 0; i < n - 1; i++) {       long long x;       cin >> x;       len.push_back(x);     }     bfs(1);     for (long long i = 0; i < m; i++) {       long long ans = 0ll;       long long a, h;       cin >> a >> h;       long long opt = 3;       while (a >= 1) {         if (h < 0) break;         if (opt == 3) {           long long cnt =               (upper_bound(dist[a].begin(), dist[a].end(), h) - dist[a].begin());           if (cnt > 0) ans += (cnt)*h - pre[a][cnt - 1];         } else if (opt == 2) {           ans += h;           if (2 * a <= n) {             long long cnt = (upper_bound(dist[2 * a].begin(), dist[2 * a].end(),                                          h - len[2 * a - 1]) -                              dist[2 * a].begin());             if (cnt > 0)               ans += (cnt) * (h - len[2 * a - 1]) - pre[2 * a][cnt - 1];           }         } else {           if (h > 0) ans += h;           if (2 * a + 1 <= n) {             long long cnt = (upper_bound(dist[2 * a + 1].begin(),                                          dist[2 * a + 1].end(), h - len[2 * a]) -                              dist[2 * a + 1].begin());             if (cnt > 0)               ans += (cnt) * (h - len[2 * a]) - pre[2 * a + 1][cnt - 1];           }         }         if (a % 2) {           h -= len[2 * (a / 2)];           opt = 2;         } else {           h -= len[2 * (a / 2) - 1];           opt = 1;         }         a /= 2;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     int d;     for (int i = 0; i < n; i++) {       cin >> d;       sum += d;     }     int count = 5;     for (int i = 1; i <= 5; i++) {       if ((sum + i) % (n + 1) == 1) {         count--;       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long arr1[1000001];   template <typename T>   T myMax(T x, T y) {     return (x > y) ? x : y;   }   template <typename T>   T myMin(T x, T y) {     return (x < y) ? x : y;   }   template <typename T>   T sum(T x, T y) {     return (x + y);   }   template <typename T>   T Mean(T x, T y) {     return (x + ((y - x) / 2));   }   void seive() {     for (long long i = 0; i <= 1000000; i++) {       arr1[i] = 1;     }     for (long long i = 2; i * i <= 1000000; i++) {       if (arr1[i] == 1) {         arr1[i] = 1;         for (long long j = i * i; j <= 1000000; j = j + i) {           arr1[j] = 0;         }       }     }   }   long long find_occurances(string s) {     string s1 =   ;     long long c = 0;     for (long long i = 0; i < 3; i++) {       s1 = s1 + s[i];     }     if (s1 ==  abc ) {       c++;     }     long long n = s.size();     long long l = 0;     long long r = 2;     while (r < n - 1) {       s1.erase(s1.begin());       l++;       r++;       s1 += s[r];       if (s1 ==  abc ) {         c++;       }     }     return c;   }   bool check_power_of_2(long long x) {     if ((x & (x - 1)) == 0) {       return true;     }     return false;   }   bool cmp(pair<long long, pair<long long, long long>> x,            pair<long long, pair<long long, long long>> y) {     if (x.first == y.first) {       return x.second.second < y.second.second;     }     return x.first < y.first;   }   bool cmp1(pair<long long, long long> p, pair<long long, long long> q) {     return p.first < q.second;   }   bool check(vector<long long>& v) {     if (v[0] == 1) {       bool flag1 = true;       for (long long i = 1; i < v.size(); i++) {         if (v[i] != v[i - 1]) {           flag1 = false;           break;         }       }       return flag1;     } else {       return false;     }   }   bool check_prime(long long x) {     if (x == 2) {       return true;     }     if (x == 3) {       return true;     }     if ((x % 2) == 0) {       return false;     }     if ((x % 3) == 0) {       return false;     }     for (long long i = 5; i * i <= x; i = i + 6) {       if ((x % i) == 0) {         return false;       }       if ((x % (i + 2)) == 0) {         return false;       }     }     return true;   }   bool check_array(vector<long long>& v) {     for (long long i = 1; i < v.size(); i++) {       if (v[i] == v[i - 1]) return false;     }     return true;   }   bool is_vowel(char x) {     if ((x ==  a ) || (x ==  e ) || (x ==  o ) || (x ==  i ) || (x ==  u )) {       return true;     }     return false;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       long long sum = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];       }       if ((sum % n) == 0) {         cout << 0 <<   n ;       } else {         cout << 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ini;   struct TrieNode {     long long value;     TrieNode *arr[2];   };   TrieNode *newNode() {     TrieNode *temp = new TrieNode;     temp->value = 0;     temp->arr[0] = temp->arr[1] = NULL;     return temp;   }   void insert(TrieNode *root, long long pre_xor) {     TrieNode *temp = root;     for (int i = 41 - 1; i >= 0; i--) {       bool val = pre_xor & (1LL << i);       if (temp->arr[val] == NULL) temp->arr[val] = newNode();       temp = temp->arr[val];     }     temp->value = pre_xor;   }   long long query(TrieNode *root, long long pre_xor) {     TrieNode *temp = root;     for (int i = 41 - 1; i >= 0; i--) {       bool val = pre_xor & (1LL << i);       if (temp->arr[1 - val] != NULL)         temp = temp->arr[1 - val];       else if (temp->arr[val] != NULL)         temp = temp->arr[val];     }     return pre_xor ^ (temp->value);   }   long long maxSubarrayXOR(long long arr[], long long n) {     TrieNode *root = newNode();     insert(root, 0);     long long result = ini, pre_xor = 0;     for (int i = 0; i < n; i++) {       pre_xor = pre_xor ^ arr[i];       insert(root, pre_xor);       result = max(result, query(root, pre_xor ^ ini));     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long arr[100000], n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i], ini ^= arr[i];     cout << maxSubarrayXOR(arr, n);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, u[6], v[6], x;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) {       scanf( %d , &x);       u[x]++;     }     for (int i = (1); i <= (n); i++) {       scanf( %d , &x);       v[x]++;     }     int dif = 0;     for (int i = (1); i <= (5); i++)       if ((u[i] + v[i]) & 1) {         printf( -1 n );         return 0;       } else         dif += max(0, (u[i] - v[i]) / 2);     printf( %d n , dif);     return 0;   }


#include <bits/stdc++.h>   long long int min(long long int x, long long int y) { return (x < y) ? x : y; }   long long int max(long long int x, long long int y) { return (x > y) ? x : y; }   long long int fastexpo(long long int base, long long int power) {     long long int res = 1;     while (power) {       if (power % 2 == 0) {         base *= base;         power /= 2;       } else {         res *= base;         power--;       }     }     return res;   }   long long int modexpo(long long int base, long long int power,                         long long int mod) {     long long int res = 1;     while (power) {       if (power % 2 == 0) {         base = (base * base) % mod;         power /= 2;       } else {         res = (base * res) % mod;         power--;       }     }     return res;   }   const long long int SN = 1e7;   bool prime[SN + 1];   void SEIVE(int n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     prime[0] = false;     prime[1] = false;   }   using namespace std;   int x[26], par[200010];   int find(int n) {     if (par[n] == n)       return n;     else       return par[n] = find(par[n]);   }   void solve() {     int n;     cin >> n;     for (long long int i = 0; i < n + 1; i++) par[i] = i;     for (long long int i = 1; i < n + 1; i++) {       string s;       cin >> s;       for (long long int j = 0; j < s.size(); j++) {         if (!x[s[j] -  a ])           x[s[j] -  a ] = i;         else           par[find(i)] = par[x[s[j] -  a ]];       }     }     int ans = 0;     for (long long int i = 1; i < n + 1; i++) {       if (par[i] == i) ans++;     }     cout << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, x, y, c1 = 0, c2 = 0, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x > 0)         c1++;       else         c2++;     }     m = min(c1, c2);     if (m <= 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     { solve(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const long long UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   static char stdinBuffer[1024];   static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char *stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   int rint() {     readAhead(16);     int x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   char rch() {     readAhead(16);     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     char ans = *stdinPos;     ++stdinPos;     return ans;   }   long long rlong() {     readAhead(32);     long long x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   int nim(int x) { return x; }   map<int, map<int, int> > g[2];   map<int, vector<pair<int, int> > > z[2];   int lim[2];   map<int, pair<int, int> > h;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     lim[0] = rint(), lim[1] = rint();     int k = rint();     for (int i = 0; i < k; i++) {       int xb = rint(), yb = rint(), xe = rint(), ye = rint();       if (xb == xe) {         if (yb > ye) swap(yb, ye);         g[0][xb][yb]++;         g[0][xb][ye]--;       } else {         if (xb > xe) swap(xb, xe);         g[1][yb][xb]++;         g[1][yb][xe]--;       }     }     int nimber = 0;     for (int t = 0; t < 2; t++)       for (auto &o : g[t]) {         int cnt = 0;         int last = 0;         int sumlen = 0;         for (auto &w : o.second) {           int oldcnt = cnt;           int pos = w.first;           cnt += w.second;           if (oldcnt == 0 && cnt > 0) {             int len = pos - last;             if (len) {               z[t][o.first].push_back(make_pair(last, pos));               sumlen += len;             }           }           if (oldcnt > 0 && cnt == 0) {             last = pos;           }         }         {           int pos = lim[t ^ 1];           int len = pos - last;           if (len) {             z[t][o.first].push_back(make_pair(last, pos));             sumlen += len;           }         }         h[sumlen] = make_pair(t, o.first);         nimber ^= sumlen;       }     for (int t = 0; t < 2; t++) {       int unseen = lim[t] - 1 - g[t].size();       int num = lim[t ^ 1];       if (unseen & 1) nimber ^= num;       if (unseen > 0) {         int have = -1;         int want = 1;         for (auto &w : g[t]) {           if (want != w.first) {             have = want;             break;           }           want++;         }         if (have == -1) have = lim[t] - 1;         assert(g[t].count(have) == 0);         h[num] = make_pair(t, have);         z[t][have].push_back(make_pair(0, lim[t ^ 1]));       }     }     if (nimber == 0) {       printf( SECOND n );     } else {       printf( FIRST n );       for (auto w : h) {         int len = w.first;         int go = len ^ nimber;         if (go > len) continue;         int rm = len - go;         int t = w.second.first;         int o = w.second.second;         int solution = -1;         for (auto &q : z[t][o]) {           int start = q.first, end = q.second;           if (rm <= end - start) {             solution = start + rm;             break;           } else             rm -= end - start;         }         assert(solution != -1);         if (t == 0) {           printf( %d %d %d %d n , o, 0, o, solution);         } else {           printf( %d %d %d %d n , 0, o, solution, o);         }         return 0;       }     }   }


#include <bits/stdc++.h>   static const int MOD = 1000000007;   using ll = long long;   using u32 = unsigned;   using u64 = unsigned long long;   using namespace std;   template <class T>   constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;   char buf[200001];   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       int a = 1, b = 0;       for (int i = 0; i < n; ++i) {         if (s[i] <=  2  && t[i] <=  2 ) {         } else if (s[i] <=  2 )           b = 0;         else if (t[i] <=  2 )           a = 0;         else {           swap(a, b);         }       }       puts(b ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, r;     cin >> k >> r;     int count = 1;     int aux = k;     while (true) {       if ((k % 10 == 0) || (abs(k - r) % 10 == 0)) {         break;       } else {         k += aux;         count++;       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, d;     cin >> n >> d;     vector<long long> delta(n);     vector<long long> rs(n);     for (int i = 0; i < n; ++i) cin >> delta[i];     rs[0] = delta[0];     for (int i = 1; i < n; ++i) rs[i] = rs[i - 1] + delta[i];     vector<long long> maxTotDeposit(n);     long long mxSoFar = LLONG_MIN;     for (int i = n - 1; i >= 0; --i) {       mxSoFar = max(mxSoFar, rs[i]);       maxTotDeposit[i] = d - mxSoFar;       if (mxSoFar > d) {         cout << -1;         return 0;       }     }     long long dep = 0;     int ans = 0;     for (int i = 0; i < n; ++i) {       if (!delta[i] && rs[i] + maxTotDeposit[i] < 0) {         cout << -1;         return 0;       }       if (!delta[i] && rs[i] + dep < 0) {         ++ans;         dep = maxTotDeposit[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   const int N = 1e5 + 10;   int buc[N], L, R, a[N];   long long ans;   void update(int c, int d) { ans += d * buc[c] * (long long)(buc[c] - 1) / 2; }   long long cal(int l, int r) {     while (L < l) update(a[L], -1), buc[a[L]]--, update(a[L], 1), L++;     while (L > l) L--, update(a[L], -1), buc[a[L]]++, update(a[L], 1);     while (R < r) R++, update(a[R], -1), buc[a[R]]++, update(a[R], 1);     while (R > r) update(a[R], -1), buc[a[R]]--, update(a[R], 1), R--;     return ans;   }   long long dp[22][N];   int cur;   void solve(int lb, int rb, int l, int r) {     if (lb > rb || l > r) return;     int mid = l + r >> 1;     int d = 0;     long long res = 1e18;     for (int i = lb; i <= min(rb, mid - 1); ++i) {       long long tmp = cal(i + 1, mid);       if (res > dp[cur - 1][i] + tmp) res = dp[cur - 1][i] + tmp, d = i;     }     dp[cur][mid] = res;     solve(lb, d, l, mid - 1), solve(d, rb, mid + 1, r);   }   int main() {     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     int n, m;     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]);     buc[a[1]]++, L = R = 1;     for (cur = 1; cur <= m; ++cur) solve(0, n - 1, 1, n);     printf( %lld , dp[m][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int arr[t];     for (int i = 0; i < t; i++) {       int y;       cin >> y;       y = y + i;       arr[i] = y;     }     sort(arr, arr + t);     for (int i = 0; i < t; i++) {       arr[i] -= i;     }     int check = 1;     for (int i = 0; i < t - 1; i++) {       if (arr[i] > arr[i + 1]) {         check = 0;         break;       }     }     if (check == 0)       cout <<  :(  n ;     else {       for (int i = 0; i < t; i++) {         cout << arr[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int N = 1e5 + 15, M = 105, T = 1e7 + 5;   long long maxi[N], l[N], r[N];   pair<long long, long long> f[N];   pair<long long, int> bsd(pair<long long, int> a, pair<long long, int> b) {     if (a.first > b.first || a.first == b.first && a.second < b.second)       return a;     else       return b;   }   int get(long long n, long long target, long long j) {     while (j <= n && target > r[j]) ++j;     return j;   }   int main() {     long long j = 1, g = 1, n, i, p, t, L, t0, x;     cin >> L >> n >> p >> t;     for (i = 1; i <= n; i++) cin >> l[i] >> r[i];     for (i = 1; i <= n; i++) {       maxi[i] = max(maxi[i], maxi[i - 1]);       f[i] = bsd(f[i], make_pair(maxi[i] + (r[i] - l[i]) / p,                                  l[i] + ((r[i] - l[i]) / p) * p));       t0 = f[i].second + t;       j = get(n, t0, j);       if (j > n) continue;       if (l[j] >= t0) {         maxi[j] = max(maxi[j], f[i].first);         continue;       }       f[j] = bsd(f[j], make_pair(f[i].first + (r[j] - t0) / p,                                  t0 + ((r[j] - t0) / p) * p));       maxi[j + 1] = max(maxi[j + 1], f[i].first);     }     long long ret = 0;     for (i = 1; i <= n; ++i) ret = max(ret, f[i].first);     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005, T = 100000;   int n, m, a[N], l[N], r[N];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i];     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = m; i > 0; --i) {       l[a[i] + T + i] = l[a[i] + T + i + 1] + 1;       r[a[i] + T - i] = r[a[i] + T - i - 1] + 1;     }     long long ans = 0;     for (int i = 1; i <= n; i++)       ans += min(n, i + (m + 1) - r[i + T]) - max(1, i - (m + 1) + l[i + T]) + 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   int main() {     int n, a;     scanf( %d , &n);     for (int i = 1; i <= n / 2; i++) {       if (gcd(i, n - i) == 1) a = i;     }     printf( %d %d , a, n - a);   }


#include <bits/stdc++.h>   int main() {     char str[5010];     memset(str, 0, sizeof(str));     scanf( %s , str);     int n;     n = strlen(str);     int res = 0;     for (int i = 0; i < n; i++) {       int l = 0, sum = 0;       for (int j = i; j < n; j++) {         if (str[j] ==  ( )           l++;         else if (str[j] ==  ) )           l--;         else           l--, sum++;         if (!l) res++;         if (l < 0 && sum > 0) {           l += 2;           sum--;         } else if (l < 0 && sum <= 0) {           break;         }       }     }     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int r1, r2, c1, c2;     cin >> r1 >> c1 >> r2 >> c2;     if (r1 == r2 || c1 == c2) {       cout << 1 <<    ;     } else {       cout << 2 <<    ;     }     if ((r1 + c1) % 2 != (r2 + c2) % 2) {       cout << 0 <<    ;     } else {       if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) {         cout << 1 <<    ;       } else {         cout << 2 <<    ;       }     }     cout << max(abs(r1 - r2), abs(c1 - c2)) <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   unsigned long long bit[N][20], ans, s;   int main() {     int n, k, a;     cin >> n >> k;     for (int x = 1; x < N; x += x & (-x)) bit[x][0]++;     for (int i = 0; i < n; i++) {       cin >> a;       for (int j = k + 1; j > 0; j--) {         s = 0;         for (int x = a; x > 0; x -= x & (-x)) s += bit[x][j - 1];         for (int x = a; x < N; x += x & (-x)) bit[x][j] += s;       }     }     for (int x = n; x > 0; x -= x & (-x)) ans += bit[x][k + 1];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {-1, 0, 1, 0};   const int dc[] = {0, 1, 0, -1};   string FILE_NAME =  testcase.C ;   string NAME;   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   int main() {     int n, k;     cin >> n >> k;     if (k >= n * (n - 1) / 2) {       cout <<  no solution  << endl;     } else {       for (int i = 0; i < (n); i++) {         cout << 0 <<     << i << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4;   bitset<maxn * 25> f[50][25];   int n;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     vector<int> a(n * 2);     for (int i = 1; i <= n * 2; i++) cin >> a[i - 1];     sort(a.begin(), a.end());     vector<vector<int>> ans(2);     ans[0].push_back(a[0]), ans[1].push_back(a[1]);     int sum = 0;     for (int i = 2; i <= n * 2 - 1; i++) sum += a[i];     int lim = sum / 2;     f[1][0].set(0);     for (int i = 2; i <= n * 2 - 1; i++)       for (int j = 0; j <= min(i, n - 1); j++) {         f[i][j] |= f[i - 1][j];         if (j) f[i][j] |= f[i - 1][j - 1] << a[i];       }     int s1 = -1, cnt = n - 1, id = 2 * n - 1;     for (int i = lim; i >= 0; i--) {       if (f[id][cnt][i]) {         s1 = i;         break;       }     }     assert(s1 >= 0);     for (int i = id; i >= 2; i--) {       assert(f[i][cnt][s1]);       if (cnt >= 1 && s1 >= a[i] && f[i - 1][cnt - 1][s1 - a[i]]) {         ans[0].push_back(a[i]);         s1 -= a[i], cnt--;       } else         ans[1].push_back(a[i]);     }     sort(ans[0].begin(), ans[0].end());     sort(ans[1].begin(), ans[1].end(), greater<int>());     for (int i = 0; i <= 1; i++) {       for (auto x : ans[i]) cout << x <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100100], b[100100];   int n, x;   multiset<int> st;   multiset<int>::iterator it;   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 0; i < n; i++) {       int w;       scanf( %d , &w);       st.insert(w);     }     sort(a, a + n);     reverse(a, a + n);     int res = 1;     for (int i = 0; i < n; i++) {       int w = x - a[i];       it = st.lower_bound(w);       if (it != st.end()) {         st.erase(it);         res = i + 1;       }     }     printf( 1 %d , res);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   long long n, a, b, val[MAX], incc[MAX], decc[MAX];   vector<int> g[MAX];   void dfs(int v, int p) {     for (auto u : g[v])       if (u != p)         dfs(u, v), decc[v] = max(decc[v], decc[u]),                    incc[v] = max(incc[v], incc[u]);     long long meg = val[v] + incc[v] - decc[v];     if (meg < 0)       incc[v] += -meg;     else       decc[v] += meg;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++)       cin >> a >> b, a--, b--, g[a].push_back(b), g[b].push_back(a);     for (int i = 0; i < n; i++) cin >> val[i];     dfs(0, -1);     cout << incc[0] + decc[0];   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long ans, p;   int main() {     scanf( %d , &n);     p = 2;     for (int i = 1; i <= n; i++) {       cout << (long long)i * (i + 1) * (i + 1) - p / i << endl;       p = (long long)i * (i + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int x1, x2, y1, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2) {       int w = max(y1, y2) - min(y1, y2);       cout << x1 + w <<     << y1 <<     << x2 + w <<     << y2 << endl;     } else if (y1 == y2) {       int w = max(x1, x2) - min(x1, x2);       cout << x1 <<     << y1 + w <<     << x2 <<     << y2 + w << endl;     } else if (abs(x1 - x2) == abs(y1 - y2)) {       cout << x1 <<     << y2 <<     << x2 <<     << y1 << endl;     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t = 0;     string s;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s[0] >=  0  && s[0] <=  9 ) {         if (s.size() == 1 || (s.size() == 2 && s <  18 )) t++;       } else if (s ==  ABSINTH  || s ==  CHAMPAGNE  || s ==  TEQUILA  ||                  s ==  WINE  || s ==  WHISKEY  || s ==  VODKA  || s ==  SAKE  ||                  s ==  RUM  || s ==  GIN  || s ==  BRANDY  || s ==  BEER )         t++;     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double cooy1, cooy2, cooyw, cooxb, cooyb, r;   double s1, s2;   int main() {     ios_base::sync_with_stdio(false);     cin >> cooy1 >> cooy2 >> cooyw >> cooxb >> cooyb >> r;     cooy1 += r;     cooy2 -= r;     cooyw -= r;     s1 = 2 * cooyw - cooy1;     s2 = 2 * cooyw - cooy2;     double xx1 = cooxb * (cooyw - s1) / (cooyb - s1);     double xx2 = cooxb * (cooyw - s2) / (cooyb - s2);     double dd1 = sqrt(cooxb * cooxb + (s1 - cooyb) * (s1 - cooyb)) * r / cooxb;     double dd2 = sqrt(cooxb * cooxb + (s2 - cooyb) * (s2 - cooyb)) * r / cooxb;     if (s1 - dd1 < s2 - r) {       if (s2 - dd2 < s2 - r) {         cout << -1;         return 0;       }       cout.precision(30);       cout << xx2;       return 0;     } else {       cout.precision(30);       cout << xx1;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long a, long long b) {     a = a % mod;     long long ans = 1;     while (b > 0) {       if (b % 2 == 1) {         ans = (ans * a) % mod;       }       b = b / 2;       a = (a * a) % mod;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long loc[n + 1];       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         loc[a[i]] = i;       }       map<long long, long long> p;       long long m = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = loc[i]; j - 1 >= 0 && p[j - 1] == 0; j--) {           if (m > (n - 1)) {             break;           }           if (a[j - 1] > a[j]) {             swap(loc[a[j]], loc[a[j - 1]]);             swap(a[j], a[j - 1]);             p[j - 1]++;             m++;           } else {             break;           }         }       }       for (long long i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e5 + 10;   long long ans;   long long n, k;   long long s[maxn];   long long l[maxn];   long long r[maxn];   long long seg[4 * maxn];   long long lazy[4 * maxn];   vector<long long> bois[maxn];   void in();   void solve();   long long doaz(long long);   long long get(long long, long long, long long, long long, long long);   void upd(long long, long long, long long, long long, long long);   void push(long long, long long, long long);   void out();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     in();     solve();     out();   }   void in() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> s[i];     for (long long i = 0; i < k; i++) cin >> l[i] >> r[i];   }   void solve() {     sort(s, s + n);     for (long long i = 0; i < k; i++) {       l[i] = lower_bound(s, s + n, l[i]) - s;       r[i] = upper_bound(s, s + n, r[i]) - s;       bois[l[i]].push_back(i);       bois[r[i]].push_back(i);     }     for (long long i = 0; i < n; i++) {       l[k + i] = i;       r[k + i] = i + 1;       bois[i].push_back(k + i);     }     ans = n * (n - 1) * (n - 2) / 6;     for (long long i = 0; i < n; i++) {       for (auto j : bois[i]) upd(1, 0, n, l[j], r[j]);       ans -= doaz(get(1, 0, n, 0, n) - get(1, 0, n, i, i + 1));     }   }   long long get(long long id, long long l, long long r, long long L,                 long long R) {     if (r <= L || R <= l) return 0;     if (L <= l && r <= R) return seg[id];     if (lazy[id]) push(id, l, r);     long long mid = (l + r) >> 1;     return get(id << 1, l, mid, L, R) + get(id << 1 | 1, mid, r, L, R);   }   void upd(long long id, long long l, long long r, long long L, long long R) {     if (r <= L || R <= l) return;     if (L <= l && r <= R) {       seg[id] = r - l - seg[id];       lazy[id] = 1 - lazy[id];       return;     }     if (lazy[id]) push(id, l, r);     long long mid = (l + r) >> 1;     upd(id << 1, l, mid, L, R);     upd(id << 1 | 1, mid, r, L, R);     seg[id] = seg[id << 1] + seg[id << 1 | 1];   }   void push(long long id, long long l, long long r) {     long long mid = (l + r) >> 1;     lazy[id] = 0;     lazy[id << 1] = 1 - lazy[id << 1];     lazy[id << 1 | 1] = 1 - lazy[id << 1 | 1];     seg[id << 1] = mid - l - seg[id << 1];     seg[id << 1 | 1] = r - mid - seg[id << 1 | 1];   }   bool cmp(long long i, long long j) { return s[i] < s[j]; }   long long doaz(long long x) { return x * (x - 1) / 2; }   void out() { cout << ans; }


#include <bits/stdc++.h>   using namespace std;   void dbg() { std::cout <<    # n ; }   template <typename T, typename... Args>   void dbg(T a, Args... args) {     std::cout << a <<    ;     dbg(args...);   }   const long long maxn = 2e5 + 10;   const long long MAX = 1000;   const long long inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   long long n, d, m;   long long a[maxn];   long long b[maxn];   multiset<long long> small;   void solve() {     cin >> n >> d >> m;     for (long long i = (1); i <= (n); ++i) {       cin >> a[i];     }     sort(a + 1, a + 1 + n);     long long pos = upper_bound(a + 1, a + 1 + n, m) - a;     long long cans = 0;     long long ans = 0;     for (long long i = (1); i <= (pos - 1); ++i) small.insert(a[i]), cans += a[i];     long long forsmall = n - 1;     ans = max(cans, ans);     for (long long i = (1); i <= (n - pos + 1); ++i) {       if (forsmall < 0) break;       while (small.size() > forsmall) {         cans -= *small.begin();         small.erase(small.begin());       }       cans += a[n - i + 1];       ans = max(ans, cans);       forsmall -= (d + 1);     }     cout << (ans) << endl;   }   signed main() {     long long TestCase = 1;     while (TestCase--) {       solve();     }     char EndFile = getchar();     EndFile = getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[101], n, imin = 0, imax = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       if (arr[i] == 1)         imin = i;       else if (arr[i] == n)         imax = i;     }     int a;     if (imax < imin) swap(imax, imin);     int rsp = abs(imin - imax) + max(n - imax, imin - 1);     cout << rsp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cout << fixed;     setprecision(15);     double x, y;     cin >> n >> x >> y;     long long p1 = 0, p2 = 0, ans = 0;     set<double> s;     for (long long i = 0; i < n; i++) {       double a, b;       cin >> a >> b;       if (a == x) {         if (s.find((double)1e7) == s.end()) {           s.insert((double)1e7);         }         continue;       }       if (b == y) {         if (s.find((double)1e6) == s.end()) {           s.insert((double)1e6);         }         continue;       }       double slope = (double)(b - y) / (a - x);       if (s.find(slope) == s.end()) {         s.insert(slope);       }     }     cout << (long long)s.size() <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int par[200010];   bool isLeaf[200010];   vector<int> adj[200010];   long long f[200010], dp[200010], s[200010], ans = 0, n;   void duyet(int u) {     s[u] = 1;     f[u] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (par[u] != v) {         par[v] = u;         duyet(v);         s[u] += s[v];         f[u] += f[v];       }     }     f[u] += s[u];   }   void cal(int u) {     long long tong = 0;     dp[u] = dp[par[u]] - 2 * s[u] + n;     ans = max(ans, dp[u]);     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (par[u] != v) {         cal(v);       }     }   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       par[i] = 0;       adj[x].push_back(y);       adj[y].push_back(x);     }     par[n] = 0;     duyet(1);     dp[1] = f[1];     for (int i = 0; i < adj[1].size(); i++) {       int v = adj[1][i];       cal(v);     }     cout << ans << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long maxn = 2e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;   long long n, m, du[maxn], vis[maxn], f[maxn];   long long res, ans = 1;   vector<long long> e[maxn];   map<pair<long long, long long>, long long> mp;   inline long long ksm(long long a, long long b) {     long long k = 1;     while (b) {       if (b & 1) k = k * a % mod;       a = a * a % mod;       b >>= 1;     }     return k;   }   void topo() {     queue<long long> q;     for (long long i = 1; i <= n; i++) {       if (du[i] == 1) {         q.push(i);         vis[i] = i;       }     }     while (!q.empty()) {       long long u = q.front();       q.pop();       for (auto v : e[u]) {         du[v]--;         if (du[v] <= 1 && !vis[v]) {           vis[v] = v;           q.push(v);         }       }     }   }   void dfs(long long u, long long fa) {     vis[u] = fa;     f[fa]++;     for (auto v : e[u]) {       if (!vis[v] && du[v] > 1) {         dfs(v, fa);       }     }   }   signed main() {     cin >> n;     long long flag = 0;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       e[i].emplace_back(x);       e[x].emplace_back(i);       du[i]++;       du[x]++;     }     topo();     for (long long i = 1; i <= n; i++) {       if (!vis[i] && du[i] > 1) {         dfs(i, i);       }     }     for (long long i = 1; i <= n; i++) {       if (vis[i] == i && f[i] == 0) {         res++;       } else if (vis[i] == i && f[i] > 1) {         ans = ans * (ksm(2, f[i]) - 2) % mod;       }     }     cout << ans * ksm(2, res) % mod;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long int n, s, p, q;     char d;     map<long long int, long long int> p1, p2;     cin >> n >> s;     for (long long int i = 1; i <= n; i++) {       cin >> d >> p >> q;       if (d ==  B )         p1[p] += q;       else if (d ==  S )         p2[p] += q;     }     map<long long int, long long int>::reverse_iterator rit;     map<long long int, long long int>::iterator it;     vector<pair<long long int, long long int> > p3;     long long int cnt = 0;     for (it = p2.begin(); it != p2.end(); it++) {       if (cnt < s) {         p3.push_back(make_pair(it->first, it->second));         cnt++;       }     }     cnt = 0;     reverse(p3.begin(), p3.end());     vector<pair<long long int, long long int> >::iterator it2;     for (it2 = p3.begin(); it2 != p3.end(); ++it2) {       if (cnt < s) {         cout <<  S               <<     << it2->first <<     << it2->second << endl;         cnt++;       }     }     cnt = 0;     for (rit = p1.rbegin(); rit != p1.rend(); ++rit) {       if (cnt < s) {         cout <<  B               <<     << rit->first <<     << rit->second << endl;         cnt++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1005][1005];   int sum[1005][1005];   int mn = 1000000007, area = 0;   int X, Y, n, m;   int extend(int x, int y, int dx, int dy) {     int mx = 0;     if (x + dx <= n && y + dy - 1 <= m &&         sum[x + dx][y + dy - 1] - sum[x + dx][y - 1] - sum[x][y + dy - 1] +                 sum[x][y - 1] ==             dx * dy)       mx = dy + extend(x + 1, y, dx, dy);     else if (y + dy <= m && x + dx - 1 <= n &&              sum[x + dx - 1][y + dy] - sum[x + dx - 1][y] - sum[x - 1][y + dy] +                      sum[x - 1][y] ==                  dx * dy)       mx = dx + extend(x, y + 1, dx, dy);     return mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     int x, y;     for (x = 1; x <= n; x++) {       for (y = 1; y <= m; y++)         if (s[x][y] ==  X ) break;       if (y < m + 1) break;     }     X = x, Y = y;     int extX = 0, extY = 0;     for (int i = x; i <= n; i++)       if (s[i][y] ==  X ) extX++;     for (int i = y; i <= m; i++)       if (s[x][i] ==  X ) extY++;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +                      (s[i][j] ==  X )),         area += (s[i][j] ==  X );       }     for (int dx = 1; dx <= extX; dx++) {       if (dx * extY > mn) break;       if (sum[x + dx - 1][y + extY - 1] - sum[x + dx - 1][y - 1] -               sum[x - 1][y + extY - 1] + sum[x - 1][y - 1] ==           dx * extY) {         int dArea = dx * extY + extend(x, y, dx, extY);         if (dArea == area && dx * extY < mn) mn = dx * extY;       }     }     for (int dy = 1; dy <= extY; dy++) {       if (dy * extX > mn) break;       if (sum[x + extX - 1][y + dy - 1] - sum[x + extX - 1][y - 1] -               sum[x - 1][y + dy - 1] + sum[x - 1][y - 1] ==           extX * dy) {         int dArea = dy * extX + extend(x, y, extX, dy);         if (dArea == area && extX * dy < mn) mn = extX * dy;       }     }     if (mn == 1000000007)       cout <<  -1  << endl;     else       cout << mn << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     set<int> s;     multiset<int> m;     auto add = [&](int x) {       auto it = s.insert(x).first;       if (next(it) != s.end() && it != s.begin())         m.erase(m.find(*next(it) - *prev(it)));       if (next(it) != s.end()) m.insert(*next(it) - x);       if (it != s.begin()) m.insert(x - *prev(it));     };     auto rm = [&](int x) {       s.erase(x);       auto it = s.lower_bound(x);       if (it != s.end()) m.erase(m.find(*it - x));       if (it != s.begin()) m.erase(m.find(x - *prev(it)));       if (it != s.end() && it != s.begin()) m.insert(*it - *prev(it));     };     for (int i = 0; i < n; i++) {       int x;       cin >> x;       add(x);     }     auto solve = [&]() -> long long {       if (s.size() <= 1)         return 0;       else         return (*s.rbegin() - *s.begin() - *m.rbegin());     };     cout << solve() <<   n ;     while (q--) {       int t, x;       cin >> t >> x;       if (t == 0)         rm(x);       else         add(x);       cout << solve() <<   n ;     }     return 0;   }


// author: sharad12arse   #include<bits/stdc++.h>   using namespace std;      #define ll long long   #define ull unsigned long long   #define gcd __gcd   #define INF LONG_LONG_MAX      void solve(){    int n;    cin>>n;    ll a1=0,a2=0,x=0;    vector<ll> arr(n);    for(int i=0;i<n;i++){     cin>>arr[i];     x^=arr[i];    }    a2=x;    for(int i=0;i<n-1;i++){     a1^=arr[i];     a2^=arr[i];     if(a1==a2){      cout<< YES n ;      return;     }    }    a1=0,a2=0;    for(int i=0;i<n-1;i++){     a1^=arr[i];     a2=0;     for(int j=n-1;j>i;j--){      a2^=arr[j];      if(a1==a2&&((x^a1)^a2)==a1){       cout<< YES n ;       return;      }     }    }    cout<< NO n ;   }      int main(){    ios_base::sync_with_stdio(0);    cin.tie(0);    int t=1;    cin>>t;    while(t--){     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 200005;   const int MD = 998244353;   void add(int& a, int b) {     a += b;     if (a >= MD) a -= MD;   }   void sub(int& a, int b) {     a -= b;     if (a < 0) a += MD;   }   int mod_mult(long long a, long long b) { return (a * b) % MD; }   int h[MX];   int fact[MX];   int inv_fact[MX];   int exp(int a, int b) {     int res = 1;     while (b) {       if (b % 2 == 1) res = mod_mult(res, a);       a = mod_mult(a, a);       b /= 2;     }     return res;   }   int C(int n, int k) {     int tmp = fact[n];     tmp = mod_mult(tmp, inv_fact[k]);     tmp = mod_mult(tmp, inv_fact[n - k]);     return tmp;   }   int f(int x) {     int tmp = exp(2, x);     if (x % 2 == 0) {       sub(tmp, C(x, x / 2));     }     tmp = mod_mult(tmp, inv_fact[2]);     return tmp;   }   int main() {     fact[0] = 1;     for (int i = 1; i < MX; i++) {       fact[i] = mod_mult(fact[i - 1], i);     }     inv_fact[MX - 1] = exp(fact[MX - 1], MD - 2);     for (int i = MX - 2; i >= 0; i--) {       inv_fact[i] = mod_mult(inv_fact[i + 1], i + 1);     }     int n, k;     ignore = scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       ignore = scanf( %d , h + i);     }     int mult_at_end = 1;     int B = 0;     for (int i = 0; i < n; i++) {       if (h[i] == h[(i + 1) % n]) {         mult_at_end = mod_mult(mult_at_end, k);       } else {         B++;       }     }     int ans = 0;     for (int c = 0; c <= B; c++) {       int tmp = exp(k - 2, c);       tmp = mod_mult(tmp, C(B, c));       tmp = mod_mult(tmp, f(B - c));       add(ans, tmp);     }     ans = mod_mult(ans, mult_at_end);     printf( %d n , ans);   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int M = 2;   struct Node {     int parent, rela;     void set(int p, int r) {       parent = p;       rela = r;     }   } node[maxn];   int Find(int x) {     int tmp_p;     if (node[x].parent != x) {       tmp_p = node[x].parent;       node[x].parent = Find(node[x].parent);       node[x].rela = (node[x].rela + node[tmp_p].rela) % M;     }     return node[x].parent;   }   void Merge(int a, int b, int p, int q, int d) {     node[p].parent = q;     node[p].rela = (node[b].rela - node[a].rela - d + M) % M;   }   int n, m;   const long long mod = 1e9 + 7;   void init() {     for (int i = 0; i < maxn; ++i) {       node[i].parent = i, node[i].rela = 0;     }   }   long long powerMod(int x, int k) {     long long res = 1;     long long base = x;     while (k) {       if (k & 1) res = res * base % mod;       base = base * base % mod;       k >>= 1;     }     return res;   }   int main() {     init();     int num = 0;     cin >> n >> m;     int res = 1;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       int p = Find(a);       int q = Find(b);       if (p != q)         Merge(a, b, p, q, c ^ 1);       else {         if ((node[a].rela - node[b].rela + 2) % 2 != 1 - c) res = 0;       }     }     if (res == 0)       cout << res << endl;     else {       for (int i = 1; i <= n; ++i)         if (Find(i) == i) num++;       cout << powerMod(2, num - 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e6 + 6;   const long long MOD = 1e9 + 7;   bool comparator(long long i, long long j) { return (i < j); }   struct setCompare {     bool operator()(const int64_t& lhs, const int64_t& rhs) const {}   };   long long power(long long x, long long i) {     long long ans = 1;     while (i > 0) {       if (i & 1) ans = (ans * x) % MOD;       i >>= 1;       x = (x * x) % MOD;     }     return ans;   }   long long power(long long x, long long i, long long mod) {     long long ans = 1;     while (i > 0) {       if (i & 1) ans = (ans * x) % mod;       i >>= 1;       x = (x * x) % mod;     }     return ans;   }   long long modInverse(long long x, long long mod) {     return power(x, mod - 2, mod);   }   bool isPalindrome(string s) {     long long limit = s.length() / 2;     for (long long i = 0; i < limit; i++)       if (s[i] != s[s.length() - i - 1]) return false;     return true;   }   long long gcd(long long x, long long y) {     long long t;     while (y != 0) t = x % y, x = y, y = t;     return x;   }   bool isVowel(char ch) {     if (ch ==  a  || ch ==  i  || ch ==  e  || ch ==  u  || ch ==  o  ||         ch ==  y ) {       return true;     }     return false;   }   bool isPrime(long long n) {     long long root = sqrt(n);     for (long long i = 2; i <= root; i++)       if (n % i == 0) return 0;     return 1;   }   long double getDisSquare(long double asdfg, long double qwert,                            long double gfdsa, long double trewq) {     return ((asdfg - gfdsa) * (asdfg - gfdsa) +             (qwert - trewq) * (qwert - trewq));   }   bool isSquareHelper(long long asdfg, long long qwert, long long gfdsa,                       long long trewq, long long x3, long long y3, long long x4,                       long long y4) {     long double d1, d2, d3, d4, d5, d6;     d1 = getDisSquare(asdfg, qwert, gfdsa, trewq);     d2 = getDisSquare(gfdsa, trewq, x3, y3);     d3 = getDisSquare(x3, y3, x4, y4);     d4 = getDisSquare(x4, y4, asdfg, qwert);     if (d1 == d2 && d1 == d3 && d1 == d4) {       d5 = getDisSquare(asdfg, qwert, x3, y3);       d6 = getDisSquare(gfdsa, trewq, x4, y4);       if (d5 == d6) {         return 1;       }     }     return 0;   }   bool isSquare(long long asdfg, long long qwert, long long gfdsa,                 long long trewq, long long x3, long long y3, long long x4,                 long long y4) {     if (isSquareHelper(asdfg, qwert, gfdsa, trewq, x3, y3, x4, y4) ||         isSquareHelper(asdfg, qwert, gfdsa, trewq, x4, y4, x3, y3) ||         isSquareHelper(asdfg, qwert, x3, y3, gfdsa, trewq, x4, y4))       return 1;     else       return 0;   }   bool isEqualateralTriangle(long long asdfg, long long qwert, long long gfdsa,                              long long trewq, long long x3, long long y3) {     long long d1 = getDisSquare(asdfg, qwert, gfdsa, trewq);     long long d2 = getDisSquare(gfdsa, trewq, x3, y3);     long long d3 = getDisSquare(x3, y3, asdfg, qwert);     if (d1 == d2 && d1 == d3) {       return 1;     } else       return 0;   }   bool isRightAngleTriangleHelper(long long asdfg, long long qwert,                                   long long gfdsa, long long trewq, long long x3,                                   long long y3) {     long long d1 = getDisSquare(asdfg, qwert, gfdsa, trewq);     long long d2 = getDisSquare(gfdsa, trewq, x3, y3);     long long d3 = getDisSquare(x3, y3, asdfg, qwert);     if (d2 == (d1 + d3)) {       return 1;     }     return 0;   }   bool isRightAngleTriangle(long long asdfg, long long qwert, long long gfdsa,                             long long trewq, long long x3, long long y3) {     if (isRightAngleTriangleHelper(asdfg, qwert, gfdsa, trewq, x3, y3) ||         isRightAngleTriangleHelper(gfdsa, trewq, x3, y3, asdfg, qwert) ||         isRightAngleTriangleHelper(x3, y3, asdfg, qwert, gfdsa, trewq))       return 1;     return 0;   }   bool areCollinear(long long asdfg, long long qwert, long long gfdsa,                     long long trewq, long long x3, long long y3) {     return ((x3 - asdfg) * (trewq - qwert) == (y3 - qwert) * (gfdsa - asdfg));   }   long long n, a, b, c, t[maxn], k;   void getInput() {     cin >> n >> a >> b >> c >> k;     for (long long i = 0; i < n; i++) cin >> t[i];   }   void getAnswer() {}   void solve() {     sort(t, t + n);     long long ans = 0;     long long x, y;     x = a / b;     y = a % b;     for (long long i = 0; i < n; i++) {       if (b >= c) {         ans += a;       } else {         long long tt = k - t[i];         ans += (a - b * tt + c * tt);       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) getInput(), solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long MX = 1e9;   const long long INF = 1e9;   void solve() {     string s;     cin >> s;     int n = s.length(), mx[n + 1], c = 0;     for (int i = 0; i < s.length(); ++i) {       if (s[i] ==  1 )         ++c;       else if (c)         --c;       mx[i] = c;     }     mx[n + 1] = c;     for (int i = n - 1; i >= 0; --i) mx[i] = min(mx[i], mx[i + 1]);     int nz = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  1 ) {         if (nz < mx[i + 1]) {           s[i] =  0 ;           ++nz;         }       }     }     cout << s <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000 + 10;   int mod;   int n, m;   vector<int> E[MAX_N];   bool v[MAX_N];   int cnt;   void dfs(int u) {     if (v[u]) return;     v[u] = true;     ++cnt;     for (vector<int>::iterator e = E[u].begin(); e != E[u].end(); ++e) {       dfs(*e);     }   }   int main() {     cin >> n >> m >> mod;     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       E[a].push_back(b), E[b].push_back(a);     }     memset(v, 0, sizeof v);     vector<int> comp;     for (int i = 0; i < n; ++i) {       if (!v[i]) {         cnt = 0;         dfs(i);         comp.push_back(cnt);       }     }     if (comp.size() == 1) {       cout << 1 % mod << endl;       return 0;     }     long long ans = 1, sum = 0;     for (vector<int>::iterator e = comp.begin(); e != comp.end(); ++e) {       ans = ans * (*e) % mod;       sum += *e;       sum %= mod;     }     for (int i = 0; i < comp.size() - 2; ++i) {       ans = ans * sum % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int v;     int w;     Edge* next;     void add(int v, int w, Edge*& head) {       this->v = v;       this->w = w;       this->next = head;       head = this;     }   } edges[200100];   Edge* h[100100];   struct Q {     int v;     int t;     bool operator<(const Q& q) const { return v < q.v || v == q.v && t < q.t; }     void init(int v, int t) {       this->v = v;       this->t = t;     }   } q[100100], q0;   void addEdge(int v1, int v2, int w) {     static Edge* e = edges;     (e++)->add(v2, w, h[v1]);     (e++)->add(v1, w, h[v2]);   }   int d[100010];   struct CMP {     bool operator()(int a, int b) const {       return d[a] < d[b] || d[a] == d[b] && a < b;     }   };   set<int, CMP> heap;   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int v1, v2, w;       scanf( %d %d %d , &v1, &v2, &w);       v1--, v2--;       addEdge(v1, v2, w);     }     int u = 0;     for (int i = 0; i < n; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         int t;         scanf( %d , &t);         q[u++].init(i, t);       }     }     memset(d, 127, sizeof(d));     d[0] = 0;     heap.insert(0);     while (!heap.empty()) {       int v = *heap.begin();       heap.erase(heap.begin());       if (v == n - 1) {         printf( %d n , d[v]);         return 0;       }       int dist = d[v];       q0.init(v, dist);       Q* qi = lower_bound(q, q + u, q0);       while (qi < q + u && qi->v == v && qi->t == dist) {         dist++;         qi++;       }       for (Edge* e = h[v]; e; e = e->next) {         if (d[e->v] > dist + e->w) {           heap.erase(e->v);           d[e->v] = dist + e->w;           heap.insert(e->v);         }       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long nCrModp_2(long long n, long long r, long long p) {     if (r > n) {       return 0;     }     if (n < 0 || r < 0) {       return 0;     }     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;     return (fac[n] * power(fac[r], p - 2, p) % p * power(fac[n - r], p - 2, p) %             p) %            p;   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long ans = 0;     long long mod = 998244353;     ans = m;     ans = ans * power(m - 1, k, mod);     ans = ans % mod;     ans = ans * nCrModp_2(n - 1, k, mod);     ans = ans % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int t, n, c_0, c_1, h;     string s;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> c_0 >> c_1 >> h;       cin >> s;       int sum = 0;       for (int j = 0; j < n; j++) {         sum += s[j] -  0 ;       }       if (c_0 - c_1 > h) {         sum = c_1 * n + (n - sum) * h;       } else if (c_1 - c_0 > h) {         sum = c_0 * n + sum * h;       } else         sum = c_1 * sum + (n - sum) * c_0;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 100;   const int maxK = 5000 + 10;   const long long INF = 1e18;   int a[maxn], n, k;   long long f[maxK][maxK];   long long gao(int i, int j, int len) {     int s = i * (n / k) + j * (n / k + 1) + 1;     int t = s + len - 1;     return a[t] - a[s];   }   void solve() {     sort(a + 1, a + 1 + n);     int ni = k - n % k;     int nj = n % k;     f[0][0] = 0;     for (int i = 0; i <= ni; i++) {       for (int j = 0; j <= nj; j++) {         if (i == 0 && j == 0) continue;         f[i][j] = INF;         if (i >= 1) {           f[i][j] = min(f[i][j], f[i - 1][j] + gao(i - 1, j, n / k));         }         if (j >= 1) {           f[i][j] = min(f[i][j], f[i][j - 1] + gao(i, j - 1, n / k + 1));         }       }     }     printf( %I64d n , f[ni][nj]);   }   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long mx = 1e9 + 9, r = 0;     for (int i = n - 1; i >= 0; i--) {       a[i] = min(mx, a[i]);       r += a[i];       mx = min(mx, max(0ll, a[i] - 1));     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010, M = 100010, SIZE = 26, LEN = 1000010;   int n, m, dfk = 0;   namespace BIT {   int c[LEN];   void Add(int x, int k) {     for (; x <= dfk; x += x & -x) c[x] += k;     return;   }   int Sum(int x) {     int sum = 0;     for (; x; x -= x & -x) sum += c[x];     return sum;   }   }  // namespace BIT   struct Trie_Node;   struct Edge;   struct Trie_Node {     Trie_Node() {       dfn = size = 0;       head = NULL;       fail = NULL;       for (int i = 0; i < SIZE; ++i) link[i] = NULL;       return;     }     Trie_Node *fail, *link[SIZE];     Edge *head;     int dfn, size;   } * node[M];   struct Edge {     Edge() {       p = NULL;       nxt = NULL;       return;     }     Trie_Node *p;     Edge *nxt;   };   inline void Add_Edge(Trie_Node *u, Trie_Node *v) {     Edge *w = new Edge();     w->p = v;     w->nxt = u->head;     u->head = w;     return;   }   bool exist[M];   char buff[LEN];   queue<Trie_Node *> que;   void BFS(Trie_Node *root) {     root->fail = root;     for (int i = 0; i < SIZE; ++i)       if (root->link[i]) {         Add_Edge(root->link[i]->fail = root, root->link[i]);         que.push(root->link[i]);       } else         root->link[i] = root;     while (!que.empty()) {       Trie_Node *u = que.front();       que.pop();       for (int i = 0; i < SIZE; ++i)         if (u->link[i]) {           Add_Edge(u->link[i]->fail = u->fail->link[i], u->link[i]);           que.push(u->link[i]);         } else           u->link[i] = u->fail->link[i];     }     return;   }   void DFS(Trie_Node *u) {     u->dfn = ++dfk;     u->size = 1;     for (Edge *i = u->head; i; i = i->nxt) {       Trie_Node *v = i->p;       DFS(v);       u->size += v->size;     }     return;   }   long long Query(Trie_Node *root, char *s) {     long long res = 0;     int j = 1, m = strlen(s + 1);     for (Trie_Node *i = root; j <= m; ++j) {       i = i->link[s[j] - 97];       res += BIT::Sum(i->dfn);     }     return res;   }   int main() {     scanf( %d%d , &n, &m);     Trie_Node *root = new Trie_Node();     for (int i = 1; i <= m; ++i) {       scanf( %s , buff + 1);       int k = strlen(buff + 1);       node[i] = root;       for (int j = 1; j <= k; node[i] = node[i]->link[buff[j] - 97], ++j)         if (!node[i]->link[buff[j] - 97])           node[i]->link[buff[j] - 97] = new Trie_Node();     }     BFS(root);     DFS(root);     using namespace BIT;     for (int i = 1; i <= m; ++i) {       Add(node[i]->dfn, 1);       Add(node[i]->dfn + node[i]->size, -1);     }     memset(exist, 1, sizeof(exist));     for (int i = 1; i <= n; ++i) {       char t;       cin >> t;       if (t !=  ? ) {         int x;         scanf( %d , &x);         if (t !=  - ) {           if (!exist[x]) {             exist[x] = 1;             Add(node[x]->dfn, 1);             Add(node[x]->dfn + node[x]->size, -1);           }         } else if (exist[x]) {           exist[x] = 0;           Add(node[x]->dfn, -1);           Add(node[x]->dfn + node[x]->size, 1);         }       } else {         scanf( %s , buff + 1);         printf( %lld n , Query(root, buff));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 505, mod = 998244353;   int n, m;   vector<int> c, pos[MX];   long long mem[2 * MX][2 * MX];   bool isValid(int a, int b) {     if (a != pos[c[a]][0] && a != pos[c[a]].back()) return 0;     if (b != pos[c[b]][0] && b != pos[c[b]].back()) return 0;     for (int i = 1; i <= n; i++)       if ((a <= pos[i][0] && pos[i][0] <= b) !=           (a <= pos[i].back() && pos[i].back() <= b))         return 0;     return 1;   }   long long dp(int a, int b) {     if (a > b) return 1;     long long &res = mem[a][b];     if (res != -1) return res;     if (!isValid(a, b)) return res = 0;     int mn = c[a];     for (int i = a; i <= b; i++) mn = min(mn, c[i]);     int ind = pos[mn][0];     long long x = dp(a, ind - 1);     for (int i = a; i < ind; i++) x += dp(a, i) * dp(i + 1, ind - 1) % mod;     x %= mod;     ind = pos[mn].back();     long long y = dp(ind + 1, b);     for (int i = ind + 1; i <= b; i++) y += dp(ind + 1, i) * dp(i + 1, b) % mod;     y %= mod;     res = 1;     for (int i = 0; i + 1 < pos[mn].size(); i++)       (res *= dp(pos[mn][i] + 1, pos[mn][i + 1] - 1)) %= mod;     (res *= x) %= mod;     (res *= y) %= mod;     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     c.resize(m);     for (int i = 0; i < m; i++) cin >> c[i];     c.erase(unique(c.begin(), c.end()), c.end());     if (c.size() > 2 * n) {       cout << 0 <<   n ;       return 0;     }     m = c.size();     for (int i = 0; i < m; i++) pos[c[i]].emplace_back(i);     memset(mem, -1, sizeof(mem));     cout << dp(0, m - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;   vector<int> g[1000001];   int p[1000001], c[1000001], a[1000001], sz[1000001], root, n;   char sub(string a, string b) {     for (int i = 0; i < b.size(); i++) {       if (a[i] != b[i]) return a[i];     }     return a.back();   }   vector<string> query(int l, int r) {     vector<string> v;     cout <<  ?   << l <<     << r << endl;     fflush(stdout);     for (int i = 0; i < (r - l + 1) * (r - l + 2) / 2; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       v.push_back(s);     }     return v;   }   int main() {     int n;     cin >> n;     if (n == 1) {       auto a = query(1, n);       cout <<  !   << a[0] << endl;       fflush(stdout);       return 0;     }     auto a = query(1, n);     auto b = query(1, n - 1);     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<string> suf;     int l = 0, r = 0;     while (l < a.size() || r < b.size()) {       if (r == b.size() || a[l] != b[r]) {         suf.push_back(a[l]);         l++;       } else {         l++, r++;       }     }     sort(suf.begin(), suf.end(),          [&](string& a, string& b) { return a.size() < b.size(); });     string ans;     ans += suf[0];     for (int i = 1; i < suf.size(); i++) ans += sub(suf[i], suf[i - 1]);     reverse(ans.begin(), ans.end());     cout <<  !   << ans << endl;     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   const int siz = 1000000 + 10;   char a[siz];   int main() {     int t, n, m = 0, i, l, k;     scanf( %d , &t);     scanf( %s , a);     int len = strlen(a);     int z = 0, o = 0;     for (l = 0; l < len; l++) {       if (a[l] ==  1 )         o++;       else if (a[l] ==  0 )         z++;     }     m = min(o, z);     len -= (2 * m);     printf( %d , len);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, N, id[6100];   bool judge(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   void work() {     if (judge(N)) return;     if (N % 2 && !judge(N - 2)) N -= 3, id[3] = 3;     for (int i = 1; i <= n; i++) {       if (judge(i) && judge(N - i)) {         id[i] = 2;         break;       }     }   }   int main() {     cin >> n;     N = n * (n + 1) / 2;     for (int i = 1; i <= n; i++) id[i] = 1;     if (n == 1) puts( -1 );     work();     for (int i = 1; i <= n; i++) cout << id[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(), cout.tie();     bool w = false;     int cnt = 0;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       int zero = 0, one = 0;       if (w && s[i] ==  0 ) {         cout << 1 <<     << 1 << endl;         w = false;       } else if (s[i] ==  0 ) {         cout << 3 <<     << 1 << endl;         w = true;       } else {         cout << 4 - cnt <<     << 2 << endl;         cnt++;         if (cnt == 4) cnt = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double t[100001], v[100001], fin[100001];   int main() {     double n, a, d;     cin >> n >> a >> d;     for (int i = 0; i < n; ++i) {       cin >> t[i] >> v[i];     }     cout.precision(5);     for (int i = 0; i < n; ++i) {       fin[i] = 2 * d * a <= v[i] * v[i] ? sqrt(2.0 * d / a)                                         : (d / v[i] + v[i] / (2 * a));       fin[i] += t[i];       if (i) fin[i] = max(fin[i], fin[i - 1]);       cout << fixed << fin[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int a[N], p[N], d[N];   int main(int argc, char const *argv[]) {     int n, gain = 0;     scanf( %d n , &n);     for (int i = 2; i <= n; i++) scanf( %d , p + i);     for (int i = 1; i <= n; i++) d[i] = d[p[i]] + 1;     for (int i = 1; i <= n; i++) a[d[i]] += 1;     for (int i = 1; i <= n; i++) gain += (a[i] % 2);     printf( %d n , gain);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 503;   char thien[N][N];   int n, m, visit[N][N];   vector<pair<int, int> > adj[N][N];   int hang[4] = {-1, 0, 1, 0};   int cot[4] = {0, 1, 0, -1};   struct ds {     char type;     int u, v;   };   vector<ds> Ans;   void DFS(int u, int v) {     visit[u][v] = true;     Ans.push_back({ B , u, v});     for (int dir = 0; dir < 4; ++dir) {       int nu = u + hang[dir], nv = v + cot[dir];       if (nu < 1 || nu > n || nv < 1 || nv > m || thien[nu][nv] ==  #  ||           visit[nu][nv])         continue;       adj[u][v].push_back({nu, nv}), DFS(nu, nv);     }   }   void phudo(int u, int v) {     for (auto it : adj[u][v]) {       int x = it.first, y = it.second;       phudo(x, y);       Ans.push_back({ D , x, y}), Ans.push_back({ R , x, y});     }   }   int main() {     if (fopen( trash.inp ,  r ))       freopen( trash.inp ,  r , stdin), freopen( trash.out ,  w , stdout);     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) cin >> thien[i][j];     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (!visit[i][j] && thien[i][j] !=  # ) {           DFS(i, j);           phudo(i, j);         }     cout << Ans.size() <<   n ;     for (auto it : Ans) cout << it.type <<     << it.u <<     << it.v <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n + 10];     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]);     long long x, y;     cin >> x >> y;     long long h = x + y;     long long sum = 0;     for (int i = 1; i <= n; ++i) {       sum = sum + y * (a[i] / (h));       a[i] = a[i] % h;       if (a[i] > x) sum += y;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[100];   long long C[51][3000][2];   int Count[2000100];   double DP[2000100];   int l;   double get(int mask) {     int left = Count[mask];     if (left == 0) return 0;     if (DP[mask] >= 0) return DP[mask];     double res = 0;     int cnt = 0;     for (int i = 0; i < l; i++)       if ((mask & (1 << i)) == 0) {         res += left + Count[mask | (1 << i)] * get(mask | (1 << i));         cnt++;       }     return DP[mask] = res / cnt / left;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     l = s[0].size();     int h1 = l / 2;     int h2 = l - l / 2;     for (int j = 0; j < n; j++)       for (int i = 0; i < (1 << h1); i++) {         long long c = 0;         for (int k = 0; k < n; k++) {           if (k != j) {             int common = 0;             for (int m = 0; m < h1; m++)               if (s[j][m] == s[k][m]) common |= 1 << m;             if ((i & common) == i) c |= 1ll << k;           }         }         C[j][i][0] = c;       }     for (int j = 0; j < n; j++)       for (int i = 0; i < (1 << h2); i++) {         long long c = 0;         for (int k = 0; k < n; k++) {           if (j != k) {             int common = 0;             for (int m = 0; m < h2; m++)               if (s[j][m + h1] == s[k][m + h1]) common |= 1 << m;             if ((i & common) == i) c |= 1ll << k;           }         }         C[j][i][1] = c;       }     int mask = (1 << h1) - 1;     for (int i = 0; i < (1 << l); i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         long long common = C[j][mask & i][0] & C[j][i >> h1][1];         if (common != 0) cnt++;       }       Count[i] = cnt;     }     for (int i = 0; i < (1 << l); i++) DP[i] = -1.0;     printf( %.15llf n , get(0));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long m = 200, ans = 0;     while (n--) {       long long a, p;       cin >> a >> p;       m = min(m, p);       ans += m * a;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   typedef struct mk {     int v;     struct mk *next;   } roy;   roy *add(roy *head, int v) {     roy *t = (roy *)malloc(sizeof(roy));     t->v = v;     t->next = NULL;     if (head == NULL) return t;     t->next = head;     return t;   }   long long n, a[300010], s[300030], u, v, count;   roy *gp[300030];   void dfs(int x, int p) {     s[x] += a[x];     roy *t = gp[x];     while (t != NULL) {       int y = t->v;       if (y != p) {         dfs(y, x);         if (s[y] > 0) s[x] += s[y];       }       t = t->next;     }   }   void go(int x, int p, long long total) {     s[x] += a[x];     roy *t = gp[x];     while (t != NULL) {       int y = t->v;       if (y != p) {         go(y, x, total);         if (s[y] > 0) s[x] += s[y];       }       t = t->next;     }     if (s[x] == total) s[x] = 0, count++;   }   int main() {     for (int i = 0; i < 300030; i++) gp[i] = NULL;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i < n; i++) {       scanf( %lld%lld , &u, &v);       gp[u] = add(gp[u], v);       gp[v] = add(gp[v], u);     }     dfs(1, -1);     long long mx = -1e18;     for (int i = 1; i <= n; i++) {       mx = (mx < s[i]) ? s[i] : mx;       s[i] = 0;     }     go(1, -1, mx);     printf( %lld %lld n , mx * count, count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + ch -  0 , ch = getchar();     return s * f;   }   const int N = 1e5 + 5, M = 320;   int n, m, fa[N], top[N], t[N], sz[N], son[N];   struct Edge {     int to, next;   } e[N];   int head[N], ecnt, id[N], pos[N], L[M], R[M];   inline void adde(int u, int v) {     e[++ecnt].next = head[u];     e[ecnt].to = v;     head[u] = ecnt;   }   void dfs1(int u) {     sz[u] = 1;     for (int i = head[u], v; i; i = e[i].next) {       v = e[i].to;       dfs1(v);       sz[u] += sz[v];       if (sz[son[u]] < sz[v]) son[u] = v;     }   }   int inde, p[N], cnt[M][N], ans, tag[M], blk, blksz;   void dfs2(int u, int fr) {     id[u] = ++inde;     p[inde] = u;     top[u] = fr;     ++cnt[pos[inde]][t[u]];     if (son[u]) dfs2(son[u], fr);     for (int i = head[u], v; i; i = e[i].next) {       v = e[i].to;       if (v != son[u]) dfs2(v, v);     }   }   bool black[N];   inline void modify_blk(int x, int l, int r, int val) {     if (l <= L[x] && R[x] <= r) {       if (val > 0) {         ++tag[x];         ans += cnt[x][tag[x]];       } else {         ans -= cnt[x][tag[x]];         --tag[x];       }     } else {       for (int i = max(l, L[x]), u; i <= min(r, R[x]); ++i) {         u = p[i];         if (black[u]) {           if (val > 0)             --t[u];           else             ++t[u];           continue;         }         if (val > 0) {           --cnt[x][t[u]];           ++cnt[x][--t[u]];           if (t[u] == tag[x]) ++ans;         } else {           --cnt[x][t[u]];           if (t[u] == tag[x]) --ans;           ++cnt[x][++t[u]];         }       }     }   }   inline void modify_node(int u, int val) {     if (black[u] && !val) {       ++cnt[pos[id[u]]][t[u]];       if (t[u] <= tag[pos[id[u]]]) ++ans;     } else if (!black[u] && val) {       --cnt[pos[id[u]]][t[u]];       if (t[u] <= tag[pos[id[u]]]) --ans;     }     black[u] = val;   }   inline void modify(int x, int val) {     if (black[x] == val) return;     modify_node(x, val);     int u = fa[x], l, r;     while (u) {       l = id[top[u]];       r = id[u];       if (pos[l] == pos[r]) {         modify_blk(pos[l], l, r, black[x]);       } else {         modify_blk(pos[l], l, r, black[x]);         modify_blk(pos[r], l, r, black[x]);         for (int i = pos[l] + 1; i < pos[r]; ++i) modify_blk(i, l, r, black[x]);       }       u = fa[top[u]];     }   }   int main() {     n = read();     m = read();     for (int i = 2; i <= n; ++i) fa[i] = read(), adde(fa[i], i);     for (int i = 1; i <= n; ++i) t[i] = read() + 1;     blksz = min(N / (M - 2), int(sqrt(n)));     blk = (n - 1) / blksz + 1;     for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / blksz + 1;     for (int i = 1; i <= blk; ++i) L[i] = (i - 1) * blksz + 1, R[i] = i * blksz;     R[blk] = n;     dfs1(1);     dfs2(1, 0);     while (m--) {       int node = read(), val = 1;       if (node < 0) node = -node, val = 0;       modify(node, val);       printf( %d  , ans);     }     return 0;   }


#include <bits/stdc++.h>   const int inf = (int)1e9;   const int mod = 1e9 + 7;   using namespace std;   long long a[1011][1011];   int n, m;   int id[1000011];   long long k;   int d[1000011];   int c[1011][1011];   int now = 0;   vector<pair<long long, pair<int, int> > > b;   bool cmp(pair<long long, pair<int, int> > a,            pair<long long, pair<int, int> > b) {     return a.first > b.first;   }   int get(int x) {     if (d[x] == x) {       return x;     }     return get(d[x]);   }   void unite(int x, int y) {     x = get(x);     y = get(y);     if (x == y) {       return;     }     if (id[x] <= id[y]) {       d[x] = y;       id[y] += id[x];     } else {       d[y] = x;       id[x] += id[y];     }   }   void rec(int x, int y, int cnt, int mn) {     if (now >= cnt) {       return;     }     now++;     c[x][y] = mn;     if (a[x - 1][y] >= mn && c[x - 1][y] == 0) {       rec(x - 1, y, cnt, mn);     }     if (a[x + 1][y] >= mn && c[x + 1][y] == 0) {       rec(x + 1, y, cnt, mn);     }     if (a[x][y + 1] >= mn && c[x][y + 1] == 0) {       rec(x, y + 1, cnt, mn);     }     if (a[x][y - 1] >= mn && c[x][y - 1] == 0) {       rec(x, y - 1, cnt, mn);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         b.push_back(make_pair(a[i][j], make_pair(i, j)));         d[(i - 1) * m + j] = (i - 1) * m + j;         id[(i - 1) * m + j] = 1;       }     }     sort(b.begin(), b.end(), &cmp);     for (int x = 0; x < b.size(); x++) {       int i = b[x].second.first, j = b[x].second.second;       if (a[i - 1][j] >= a[i][j]) {         unite((i - 1) * m + j, (i - 2) * m + j);       }       if (a[i + 1][j] >= a[i][j]) {         unite((i - 1) * m + j, (i)*m + j);       }       if (a[i][j + 1] >= a[i][j]) {         unite((i - 1) * m + j, (i - 1) * m + j + 1);       }       if (a[i][j - 1] >= a[i][j]) {         unite((i - 1) * m + j, (i - 1) * m + j - 1);       }       if (k % a[i][j] == 0) {         if (id[get((i - 1) * m + j)] >= k / a[i][j]) {           cout <<  YES  << endl;           rec(i, j, k / a[i][j], a[i][j]);           for (int k = 1; k <= n; k++) {             for (int l = 1; l <= m; l++) {               cout << c[k][l] <<    ;             }             cout << endl;           }           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct number {     deque<int> q;     map<int, int> db;     int curr = 0;   };   struct pii {     int x, y, id;   };   const int S = 300;   bool sortFunc(pii a, pii b) {     if (a.x / S == b.x / S) return ((a.x / S) & 1 ? a.y > b.y : a.y < b.y);     return a.x < b.x;   }   vector<number> t(1e5 + 1);   void inc(map<int, int>& db, int num, int& curr) {     if (db.count(num) == 0) db[num] == 0;     if (++db[num] == 1) curr++;   }   void dec(map<int, int>& db, int num, int& curr) {     if (--db[num] == 0) curr--;   }   int curr = 0, nums = 0;   void add(int poz, int num) {     if (t[num].curr <= 1 && t[num].q.size() > 0) curr--;     if (t[num].q.empty())       t[num].q.push_front(poz);     else if (poz < t[num].q.front()) {       inc(t[num].db, t[num].q.front() - poz, t[num].curr);       t[num].q.push_front(poz);     } else {       inc(t[num].db, poz - t[num].q.back(), t[num].curr);       t[num].q.push_back(poz);     }     if (t[num].curr <= 1) curr++;     if (t[num].q.size() == 1) nums++;   }   void remove(int poz, int num) {     if (t[num].curr <= 1) curr--;     if (t[num].q.size() == 1)       t[num].q.pop_front();     else if (poz == t[num].q.front()) {       t[num].q.pop_front();       dec(t[num].db, t[num].q.front() - poz, t[num].curr);     } else {       t[num].q.pop_back();       dec(t[num].db, poz - t[num].q.back(), t[num].curr);     }     if (t[num].curr <= 1 && t[num].q.size() > 0) curr++;     if (t[num].q.size() == 0) nums--;   }   int main() {     int n;     cin >> n;     vector<int> sor(n);     for (int& a : sor) cin >> a;     int q;     cin >> q;     vector<pii> v(q);     for (int i = 0; i < q; i++)       cin >> v[i].x >> v[i].y, v[i].id = i, v[i].x--, v[i].y--;     sort(v.begin(), v.end(), sortFunc);     int l = 0, r = -1;     vector<int> ans(q);     for (pii& a : v) {       while (a.x < l) add(l - 1, sor[l - 1]), l--;       while (r < a.y) add(r + 1, sor[r + 1]), r++;       while (l < a.x) remove(l, sor[l]), l++;       while (a.y < r) remove(r, sor[r]), r--;       ans[a.id] = (curr > 0 ? nums : nums + 1);     }     for (int& a : ans) cout << a <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int MAX = 200005;   long long modexp(long long x, long long n) {     if (n == 0) return 1LL;     if (n % 2 == 0) {       long long y = modexp(x, n / 2) % mod;       return (y * y) % mod;     }     return (x * modexp(x, n - 1) % mod) % mod;   }   long long powr(long long x, long long n) {     long long ans = 1;     for (int i = 1; i <= n; i++) ans = ans * x;     return ans;   }   int main() {     int n;     scanf( %d , &n);     int a[n];     int dp[n];     pair<int, int> aux[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       dp[i] = mod;       aux[i] = make_pair(a[i], i);     }     sort(aux, aux + n);     sort(a, a + n);     dp[2] = a[2] - a[0];     dp[3] = a[3] - a[0];     dp[4] = a[4] - a[0];     int idx[n];     for (int i = 0; i < 5; i++) idx[i] = 0;     for (int i = 5; i < n; i++) {       vector<pair<int, int> > p;       if (i - 2 >= 3) p.push_back(make_pair(dp[i - 3] + a[i] - a[i - 2], i - 2));       if (i - 3 >= 3) p.push_back(make_pair(dp[i - 4] + a[i] - a[i - 3], i - 3));       if (i - 4 >= 3) p.push_back(make_pair(dp[i - 5] + a[i] - a[i - 4], i - 4));       sort(p.begin(), p.end());       dp[i] = p[0].first;       idx[i] = p[0].second;     }     int color[n];     int team = 0;     for (int i = n - 1; i > 0; i--) {       team++;       int x = idx[i];       for (int j = x; j <= i; j++) {         color[j] = team;       }       i = x;     }     printf( %d %d n , dp[n - 1], team);     int ans[n];     for (int i = 0; i < n; i++) {       ans[aux[i].second] = color[i];     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char dir[] = { R ,  L ,  D ,  U };   const int MOD = 1e9 + 7;   const long long INF = 1e9;   void setIO(string filename) {     if (fopen((filename +  .in ).c_str(),  r )) {       freopen((filename +  .in ).c_str(),  r , stdin);       freopen((filename +  .out ).c_str(),  w , stdout);     }   }   void solve() {     int n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (auto &i : a) cin >> i.first >> i.second;     sort((a).begin(), (a).end());     for (int i = 0; i < n - 1; i++) {       pair<long long, long long> curr = a[i];       if (a[i + 1].first - a[i].first >= 30)         continue;       else {         while (curr.first < a[i + 1].first) {           curr.second = (curr.second + 4 - 1) / 4;           curr.first++;         }         a[i + 1].second += max(0ll, curr.second - a[i + 1].second);       }     }     long long ans = a.back().first;     while (a.back().second > 1) {       ;       a.back().second = (a.back().second + 4 - 1) / 4;       ans++;     }     cout << max(1ll, ans + (a.back().first == ans)) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int flag = 0;     for (int i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) {         flag = 1;         cout <<  YES  << endl;         cout << i + 1 <<     << i + 2;         break;         return 0;       }     }     if (flag == 0) {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int n = s.length();     s[n - 1] = s[0];     cout << s <<   n ;     return;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pil = pair<int, ll>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   const int inf = (1 << 30) - 1;   const ll INF = (1LL << 60) - 1;   const double pi = acos(-1.0);   const double EPS = 1e-10;   template <typename T>   bool chmax(T &x, const T &y) {     if (x < y) {       x = y;       return true;     }     return false;   }   template <typename T>   bool chmin(T &x, const T &y) {     if (x > y) {       x = y;       return true;     }     return false;   }   template <typename T>   void in(T &x) {     cin >> x;   }   template <typename T>   void out(T x) {     cout << x <<   n ;   }   template <typename T>   void out2(T x) {     cout << x <<    ;   }   template <typename T, typename U>   void in(pair<T, U> &p) {     cin >> p.first >> p.second;   }   template <typename T, typename U>   void out(pair<T, U> p) {     cout << p.first <<     << p.second <<   n ;   }   using vi = vector<int>;   using vll = vector<ll>;   template <typename T>   void in(vector<T> &a) {     for (int i = 0; i < (int)a.size(); i++) cin >> a[i];   }   template <typename T>   void out(const vector<T> &a) {     for (auto &e : a) cout << e <<   n ;   }   template <typename T>   void out2(const vector<T> &a) {     for (auto &e : a) cout << e <<    ;     cout <<   n ;   }   template <typename T>   void unique(vector<T> &a) {     sort(a.begin(), a.end()), a.erase(unique(a.begin(), a.end()), a.end());   }   vector<int> iota(int n) {     vector<int> ret(n);     iota(ret.begin(), ret.end(), 0);     return ret;   }   template <typename T>   vector<int> iota(const vector<T> &a, bool greater = false) {     vector<int> ret = iota((int)a.size());     sort(ret.begin(), ret.end(),          [&](int i, int j) { return (a[i] < a[j]) ^ greater; });     return ret;   }   struct io_setup {     io_setup() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout << fixed << setprecision(15);     }   } io_setup;   const int MOD = 1000000007;   int main() {     int T;     in(T);     int ord[] = {0, 2, 3, 1};     while (T--) {       ll N;       in(N);       ll x = 1;       while (x * 4 <= N) x *= 4;       ll y = (N - x) / 3;       ll p, q, r;       p = x + y, q = x * 2;       while (y) {         x /= 4;         q += x * ord[y / x];         y %= x;       }       r = p ^ q;       if (N % 3 == 1) out(p);       if (N % 3 == 2) out(q);       if (N % 3 == 0) out(r);     }   }