#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1e5 + 5, lg = 16;   struct updates {     int l, x, y, id;     bool operator<(const updates &other) const {       if (l != other.l) return l > other.l;       return id < other.id;     }   };   vector<updates> upd;   vector<int> v[Nmax];   struct Node {     int s, l, r;     bool full;     Node() { s = l = r = full = 0; }     Node(int S, int L, int R, bool Full) {       s = S;       l = L;       r = R;       full = Full;     }   };   int f[Nmax], x, y, w, i, answer[Nmax], n, q;   Node combina(Node a, Node b) {     if (a.full && b.full) return Node(0, a.l + b.l, a.r + b.r, 1);     if (a.full) return Node(b.s, a.l + b.l, b.r, 0);     if (b.full) return Node(a.s, a.l, a.r + b.r, 0);     return Node(a.s + b.s + f[a.r + b.l], a.l, b.r, 0);   }   class SegmentTree {     Node *a;       public:     void build(int sz) { a = new Node[4 * sz + 5]; }     void update(int node, int st, int dr, int pos) {       if (st == dr) {         a[node].s = 0;         a[node].l = a[node].r = a[node].full = 1;         return;       }       if (pos <= ((st + dr) / 2))         update((node << 1), st, ((st + dr) / 2), pos);       else         update(((node << 1) + 1), ((st + dr) / 2) + 1, dr, pos);       a[node] = combina(a[(node << 1)], a[((node << 1) + 1)]);     }     Node query(int node, int st, int dr, int Left, int Right) {       if (Left <= st && dr <= Right) return a[node];       if (Left <= ((st + dr) / 2) && ((st + dr) / 2) < Right)         return combina(             query((node << 1), st, ((st + dr) / 2), Left, Right),             query(((node << 1) + 1), ((st + dr) / 2) + 1, dr, Left, Right));       if (Left <= ((st + dr) / 2))         return query((node << 1), st, ((st + dr) / 2), Left, Right);       else         return query(((node << 1) + 1), ((st + dr) / 2) + 1, dr, Left, Right);     }   } aint[Nmax];   class HeavyPath {     int level[Nmax], dad[Nmax], to[Nmax], pos[Nmax], w[Nmax], sz[Nmax],         First[Nmax], t[Nmax][lg + 2], nrChains;     void dfs(int node) {       for (auto i = 1; i <= lg; ++i) t[node][i] = t[t[node][i - 1]][i - 1];       w[node] = 1;       for (auto it : v[node])         if (!level[it]) {           level[it] = level[node] + 1;           dad[it] = t[it][0] = node;           dfs(it);           w[node] += w[it];         }     }     void chains(int node) {       to[node] = nrChains;       pos[node] = ++sz[nrChains];       if (v[node].size() == 1 && node != 1) return;       int xson = 0;       for (auto it : v[node])         if (it != dad[node] && w[xson] < w[it]) xson = it;       chains(xson);       for (auto it : v[node])         if (it != dad[node] && it != xson) {           First[++nrChains] = it;           chains(it);         }     }     Node query(int x, int y) {       if (to[x] == to[y])         return aint[to[x]].query(1, 1, sz[to[x]], pos[x], pos[y]);       return combina(query(x, dad[First[to[y]]]),                      aint[to[y]].query(1, 1, sz[to[y]], 1, pos[y]));     }       public:     void prepare() {       memset(level, 0, sizeof(level));       level[1] = 1;       dad[1] = 0;       dfs(1);       nrChains = 1;       First[1] = 1;       memset(sz, 0, sizeof(sz));       chains(1);       int i;       for (i = 1; i <= nrChains; ++i) aint[i].build(sz[i]);     }     int get_answer(int x, int y) {       int X = x, Y = y;       if (level[x] < level[y]) swap(x, y), swap(X, Y);       int up = level[x] - level[y] - 1, i;       if (up != -1) {         for (i = 0; i <= lg; ++i)           if (up & (1 << i)) x = t[x][i];         if (dad[x] == y) {           auto ans = query(x, X);           if (ans.full) return f[ans.l];           return ans.s + f[ans.l] + f[ans.r];         }         x = dad[x];       }       for (i = lg; i >= 0; --i)         if (t[x][i] != t[y][i]) x = t[x][i], y = t[y][i];       auto ans1 = query(x, X), ans2 = query(y, Y);       swap(ans2.l, ans2.r);       ans1 = combina(ans2, ans1);       if (ans1.full) return f[ans1.l];       return ans1.s + f[ans1.l] + f[ans1.r];     }     void add_edge(int x, int y) {       if (y == dad[x]) swap(x, y);       aint[to[y]].update(1, 1, sz[to[y]], pos[y]);     }   } hp;   int main() {     cin.sync_with_stdio(false);     cin >> n >> q;     for (i = 1; i < n; ++i) cin >> f[i];     for (i = 1; i < n; ++i) {       cin >> x >> y >> w;       v[x].push_back(y);       v[y].push_back(x);       upd.push_back({w, x, y, 0});     }     for (i = 1; i <= q; ++i) {       cin >> x >> y >> w;       upd.push_back({w, x, y, i});     }     sort(upd.begin(), upd.end());     hp.prepare();     for (auto it : upd) {       if (!it.id)         hp.add_edge(it.x, it.y);       else         answer[it.id] = hp.get_answer(it.x, it.y);     }     for (i = 1; i <= q; ++i) cout << answer[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[100001];   int w[100001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> c[i];     }     for (int i = 0; i < n; i++) {       cin >> w[i];     }     int ch = m;     set<pair<long long, int> > s;     long long cnt = 0;     for (int i = 0; i < n; i++) {       if (ch < c[i] % 100) {         long long mn = (100 - c[i] % 100) * w[i];         if (s.begin() != s.end() && s.begin()->first < mn) {           cnt += s.begin()->first;           ch += 100;           ch -= c[i] % 100;           s.erase(s.begin());           s.insert(make_pair((100 - c[i] % 100) * w[i], i));         } else {           ch += 100 - c[i] % 100;           cnt += mn;         }       } else {         if (c[i] % 100 != 0) {           s.insert(make_pair((100 - c[i] % 100) * w[i], i));           ch -= c[i] % 100;         }       }     }     cout << cnt << endl;     vector<bool> p(n, 0);     for (set<pair<long long, int> >::iterator it = s.begin(); it != s.end();          it++) {       p[it->second] = 1;     }     for (int i = 0; i < n; i++) {       if (p[i]) {         cout << c[i] / 100 <<     << c[i] % 100 << endl;       } else {         cout << (c[i] + 99) / 100 <<   0  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> p[100];     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p[i].first;       p[i].second = i + 1;     }     sort(p, p + n);     for (int i = 0; i < n; i++) cout << p[i].second <<    ;   }


#include <bits/stdc++.h>   int main() {     int ans = 0;     int count;     scanf( %d , &count);     for (int i = 0; i < count; i++) {       int prize;       scanf( %d , &prize);       int minTimeToPrize = std::min(prize - 1, 1000000 - prize);       ans = std::max(ans, minTimeToPrize);     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct Point {     int x, y;     void read() {       int a, b;       scanf( %d%d , &a, &b);       x = a + b;       y = a - b;     }     bool operator<(const Point p) const { return x != p.x ? x < p.x : y < p.y; }   } p[N];   int n;   int pre_min[N], pre_max[N];   int suf_min[N], suf_max[N];   bool check(long long mid) {     for (int l = 1, r = 1; r <= n; r++) {       while (p[r].x - p[l].x > mid && l <= n) l++;       int mx = max(pre_max[l - 1], suf_max[r + 1]);       int mn = min(pre_min[l - 1], suf_min[r + 1]);       if (mx - mn <= mid) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) p[i].read();     sort(p + 1, p + 1 + n);     pre_min[0] = INT_MAX;     pre_max[0] = INT_MIN;     suf_min[n + 1] = INT_MAX;     suf_max[n + 1] = INT_MIN;     for (int i = 1; i <= n; i++) {       pre_max[i] = max(pre_max[i - 1], p[i].y);       pre_min[i] = min(pre_min[i - 1], p[i].y);     }     for (int i = n; i >= 1; i--) {       suf_max[i] = max(suf_max[i + 1], p[i].y);       suf_min[i] = min(suf_min[i + 1], p[i].y);     }     long long ans, low = 0, high = 1LL << 50, mid;     while (low <= high) {       mid = (low + high) >> 1;       if (check(mid))         high = mid - 1, ans = mid;       else         low = mid + 1;     }     printf( %.10f n , ans / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 40, MMax = 200;   int N, nn, A[NMax][NMax], B[NMax];   int get(int a, int b) { return (a ^ b); }   int P(int a, int b) {     if (b)       return a * -1;     else       return a;   }   int main() {     scanf( %d , &N);     nn = (N + 1) >> 1;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) scanf( %d , &A[i][j]);     int ret = -100000000;     for (int I = 0; I < (1 << nn); I++) {       int cnt = 0;       int k = I;       for (int i = 1; i <= nn; i++) {         B[i] = (I & 1);         cnt += P(A[i][nn], B[i]);         I >>= 1;       }       I = k;       for (int i = 1; i < nn; i++) cnt += P(A[i + nn][nn], get(B[i], B[nn]));       for (int i = 1; i < nn; i++) {         int tot0 = P(A[nn][i], 0) + P(A[nn][nn + i], get(0, B[nn])),             tot1 = P(A[nn][i], 1) + P(A[nn][nn + i], get(1, B[nn]));         for (int j = 1; j < nn; j++) {           int maxx = -100000000;           for (int first = 0; first < 2; first++) {             int second = 0;             int x1 = get(first, B[j]), x2 = get(second, B[nn]),                 x3 = get(B[j], B[nn]), x4 = get(first, second), x5 = get(x1, x2);             if (get(x3, x4) == x5)               maxx =                   max(maxx, P(A[j][i], first) + P(A[j][nn + i], x1) +                                 P(A[nn + j][i], x4) + P(A[nn + j][nn + i], x5));           }           if (maxx != -100000000)             tot0 += maxx;           else             tot0 = -100000000;         }         for (int j = 1; j < nn; j++) {           int maxx = -100000000;           for (int first = 0; first < 2; first++) {             int second = 1;             int x1 = get(first, B[j]), x2 = get(second, B[nn]),                 x3 = get(B[j], B[nn]), x4 = get(first, second), x5 = get(x1, x2);             if (get(x3, x4) == x5)               maxx =                   max(maxx, P(A[j][i], first) + P(A[j][nn + i], x1) +                                 P(A[nn + j][i], x4) + P(A[nn + j][nn + i], x5));           }           if (maxx != -100000000)             tot1 += maxx;           else             tot1 = -100000000;         }         cnt += max(tot0, tot1);       }       ret = max(ret, cnt);     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long s1 = a + b;       long long s2 = c + d;       if (s1 > s2)         cout << s1 << endl;       else         cout << s2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, flag = 0, j;     cin >> n;     while (n--) {       int x;       cin >> x;       flag = 0;       for (i = 0; i <= 33; i++) {         for (j = 0; j <= 14; j++) {           if (i * 3 + j * 7 == x) {             cout <<  YES  << endl;             flag = 1;             break;           }         }         if (flag == 1) break;       }       if (flag == 0) cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   bool valid(int P, int d, vector<int> guess) {     if (P >= N) {       return true;     }     if (P == 0) {       if (valid(P + 1, d, guess)) return true;       guess[P] -= d;       if (valid(P + 1, d, guess)) return true;       guess[P] += d;       guess[P] += d;       if (valid(P + 1, d, guess)) return true;       guess[P] -= d;     } else {       if (guess[P] == guess[P - 1]) {         if (valid(P + 1, d, guess)) return true;       } else if ((guess[P] - d) == guess[P - 1]) {         guess[P] -= d;         if (valid(P + 1, d, guess)) return true;         guess[P] += d;       } else if ((guess[P] + d) == guess[P - 1]) {         guess[P] += d;         if (valid(P + 1, d, guess)) return true;         guess[P] -= d;       }     }     return false;   }   int main() {     cin >> N;     vector<int> V(N);     for (int i = 0; i < N; i++) cin >> V[i];     for (int d = 0; d <= 100; d++) {       if (valid(0, d, V)) {         cout << d <<   n ;         return 0;       }     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     int64_t n;     cin >> n;     int64_t a[n];     for (int64_t i = 0; i < n; i++) cin >> a[i];     map<int64_t, int64_t> first;     map<int64_t, int64_t> second;     first[a[0]] = 1;     int64_t sum = 0;     for (int64_t i = 0; i < n; i++) sum += a[i];     for (int64_t i = 1; i < n; i++) second[a[i]]++;     int64_t cur = 0;     if (sum % 2) {       cout <<  NO n ;       return 0;     }     int64_t tar = sum / 2;     for (int64_t i = 0; i < n; i++) {       cur += a[i];       if (cur == tar) {         cout <<  YES n ;         return 0;       }       if (cur > tar) {         int64_t x = cur - tar;         if (first[x] > 0) {           cout <<  YES n ;           return 0;         }       }       if (cur < tar) {         int64_t x = tar - cur;         if (second[x] > 0) {           cout <<  YES n ;           return 0;         }       }       first[a[i + 1]]++;       second[a[i + 1]]--;     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int n, m, q;   int a[1110][810];   char s[1100];   int ni[5] = {0, 1, 3, 2, 4};   long long pow_mod(long long a, long long e) {     long long res = 1;     for (; e; a = a * a % mod, e >>= 1)       if (e & 1) res = res * a % mod;     return res;   }   int frnum;   const int BASE = 5;   int wr[1100];   void gauss() {     for (int i = 1; i <= n; i++) {       int flag = 0;       for (int j = i; j <= m; j++)         if (a[j][i]) {           for (int k = 1; k <= n + q; k++) swap(a[j][k], a[i][k]);           flag = 1;           break;         }       if (flag == 0) {         m++;         for (int j = 1; j <= n + q; j++) a[m][j] = a[i][j], a[i][j] = 0;         continue;       }       for (int j = i + 1; j <= n + q; j++)         a[i][j] = (a[i][j] * ni[a[i][i]]) % BASE;       a[i][i] = 1;       for (int j = 1; j <= m; j++)         if (a[j][i] && j != i) {           for (int k = 1; k <= n + q; k++)             if (k != i)               a[j][k] = (a[j][k] + 5 - (a[j][i] * a[i][k]) % BASE) % BASE;           a[j][i] = 0;         }     }     for (int i = 1; i <= n; i++)       if (a[i][i] == 0) frnum++;     for (int i = 1; i <= m; i++) {       int ff = 0;       for (int j = 1; j <= n; j++)         if (a[i][j]) ff = 1;       if (ff) continue;       for (int j = n + 1; j <= n + q; j++)         if (a[i][j]) wr[j - n] = 1;     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) a[j][i] = s[j] -  a ;     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) a[j][i + n] = s[j] -  a ;     }     gauss();     for (int i = 1; i <= q; i++) {       if (wr[i])         cout << 0 << endl;       else         cout << pow_mod(5, frnum) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, a;     cin >> n >> a;     map<int, int> my;     set<int> rem;     int ca = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == a) {         ++ca;       } else {         if (rem.find(x) != rem.end()) continue;         my[x]++;         if (my[x] <= ca) {           my.erase(x);           rem.insert(x);         }       }     }     if (my.empty()) {       cout <<  -1 n ;       return 0;     } else {       for (auto it : my) {         if (it.second >= ca) {           cout << it.first <<   n ;           return 0;         }       }     }     cout <<  -1 n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int64_t n, l, d;     cin >> n >> d >> l;     int a[25001];     for (int i = 1; i <= n; i++) {       if (d > 0) {         a[i] = l;       } else {         a[i] = 1;       }       d = a[i] - d;     }     a[n] = a[n] - d;     if (a[n] <= 0 || a[n] > l) {       cout << -1;     } else {       for (int i = 1; i <= n; i++) {         cout << a[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;   long long int getint() {     long long int ret = 0;     bool f = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f ^= 1;     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return f ? -ret : ret;   }   using namespace std;   int k, p;   long long int l, r;   int mypow(int a, long long int b, int mod) {     int ret = 1;     for (; b; b >>= 1, a = (long long int)a * a % mod)       if (b & 1) ret = (long long int)ret * a % mod;     return ret;   }   int work() {     k = getint();     l = getint(), r = getint();     p = getint();     if (p == 2) return (k & 1) ? 0 : 1;     if (k % p == 0) return k & 1 ? mypow(mypow(2, p - 2, p), r - l, p) : 1;     int t = mypow(2, l, p - 1), ans;     t = mypow(k, t, p);     if ((t - 1) % p == 0)       ans = mypow(2, r - l + 1, p);     else {       int c = mypow(2, r - l + 1, p - 1);       c = mypow(t, c, p);       ans = (long long int)(c + p - 1) * mypow(t + p - 1, p - 2, p) % p;     }     if (k & 1) ans = (long long int)ans * mypow(mypow(2, p - 2, p), r - l, p) % p;     return ans;   }   int main() {     int T = getint();     while (T--) printf( %d n , work());   }


#include <bits/stdc++.h>   using namespace std;   long long valor[100456], solapacion[100456][320], posheavy[100456],       resp[100456], arrupd[100456];   vector<long long> v[100456], colaheavy;   bool light[100456], existe[100456];   void init() {     for (int i = 0; i < 100456; ++i) {       existe[i] = false;     }   }   void solape(long long m) {     long long auxcontador = 0;     for (int i = 0; i < colaheavy.size(); ++i) {       for (int j = 0; j < v[colaheavy[i]].size(); j++) {         existe[v[colaheavy[i]][j]] = true;       }       for (int j = 0; j < m; j++) {         auxcontador = 0;         for (int k = 0; k < v[j].size(); k++) {           if (existe[v[j][k]] == true) {             auxcontador++;           }         }         if (colaheavy[i] == j) auxcontador = 0;         solapacion[j][i] = auxcontador;       }       for (int j = 0; j < v[colaheavy[i]].size(); j++) {         existe[v[colaheavy[i]][j]] = false;       }     }   }   void updatelight(long long pos, long long val) {     pos--;     for (int i = 0; i < v[pos].size(); ++i) {       valor[v[pos][i]] += val;     }     for (int i = 0; i < colaheavy.size(); ++i) {       resp[colaheavy[i]] += (solapacion[pos][i]) * val;     }   }   void updateheavy(long long pos, long long num) {     pos--;     resp[pos] += v[pos].size() * num;     arrupd[pos] += num;   }   void querylight(long long num) {     long long tot = 0;     for (int i = 0; i < v[num].size(); ++i) {       tot += valor[v[num][i]];     }     for (int i = 0; i < colaheavy.size(); ++i) {       tot += solapacion[num][i] * arrupd[colaheavy[i]];     }     cout << tot << endl;   }   void queryheavy(long long num) {     long long tot = resp[num];     for (int i = 0; i < colaheavy.size(); ++i) {       tot += solapacion[num][i] * arrupd[colaheavy[i]];     }     cout << tot << endl;   }   int main() {     long long n, m, queries, aux, aux2, val, num;     ios_base::sync_with_stdio(false);     cin.tie(0);     string txt;     cin >> n >> m >> queries;     init();     for (int i = 0; i < n; ++i) {       cin >> valor[i];     }     for (int i = 0; i < m; ++i) {       cin >> aux;       light[i] = true;       if (aux >= sqrt(100456)) {         posheavy[i] = colaheavy.size();         colaheavy.push_back(i);         light[i] = false;       }       resp[i] = 0;       for (int j = 0; j < aux; j++) {         cin >> aux2;         aux2--;         resp[i] += valor[aux2];         v[i].push_back(aux2);       }     }     solape(m);     for (int i = 0; i < queries; ++i) {       cin >> txt;       if (txt[0] ==  ? ) {         cin >> val;         val--;         if (light[val] == true) {           querylight(val);         } else {           queryheavy(val);         }       } else {         cin >> num >> val;         if (light[num - 1] == true) {           updatelight(num, val);         } else {           updateheavy(num, val);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 201;   int a[maxn], N, L, K;   double f[maxn][maxn][maxn * 2], p[maxn];   int main() {     scanf( %d%d%d , &N, &L, &K);     for (int i = 0; i < N; ++i) {       scanf( %lf , &p[i]);       p[i] /= 100;     }     for (int i = 0; i < N; ++i) scanf( %d , &a[i]);     f[0][0][N + min(N, K)] = 1;     for (int i = 0; i < N; ++i)       for (int j = 0; j <= N; ++j)         for (int k = -N; k <= N; ++k)           if (f[i][j][N + k] > 0) {             f[i + 1][j + 1][N + min(k + a[i], N)] += p[i] * f[i][j][N + k];             f[i + 1][j][N + k] += (1 - p[i]) * f[i][j][N + k];           }     double ans = 0;     for (int j = L; j <= N; ++j)       for (int k = N; k <= N + N; ++k) ans += f[N][j][k];     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s[100005];   int color[100005];   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       int i, j, tmp = 0;       int u, v, ans;       for (i = 1; i <= n; i++) scanf( %d , &color[i]);       for (j = 0; j < m; j++) {         scanf( %d%d , &u, &v);         if (color[u] != color[v]) {           s[color[v]].insert(color[u]);           s[color[u]].insert(color[v]);         }       }       ans = color[1];       for (i = 1; i <= n; i++) {         if (s[color[i]].size() > tmp ||             (s[color[i]].size() == tmp && color[i] < ans)) {           tmp = s[color[i]].size();           ans = color[i];         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 61);   const int inf = (1 << 30);   const int nmax = 4e5 + 50;   const int mod = 1e9 + 7;   using namespace std;   string s;   long long n, a[nmax], st[4 * nmax], i, lzy[4 * nmax], x, q, st1[4 * nmax],       ms[4 * nmax], msk[nmax], m, ans, j, inv[100], l, r, sv[500], x1;   long long pr[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,                     37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,                     83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,                     139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,                     197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,                     263, 269, 271, 277, 281, 283, 293};   long long pw(long long n, long long p) {     long long tmp = n, ans = 1, mx;     if (p == mod - 2)       mx = 31;     else       mx = 18;     for (int i = 0; i <= mx; i++) {       if (p & (1LL << i)) ans = (ans * tmp) % mod;       tmp = (tmp * tmp) % mod;     }     return ans;   }   void build(int x, int l, int r) {     if (l == r) {       st[x] = a[l];       st1[x] = msk[l];       return;     }     int mid = (l + r) / 2;     build(2 * x, l, mid);     build(2 * x + 1, mid + 1, r);     st[x] = st[2 * x] * st[2 * x + 1];     st[x] %= mod;     st1[x] = st1[2 * x] | st1[2 * x + 1];   }   void push(int nod, int l, int r) {     if (!lzy[nod]) return;     if (lzy[nod] != 1) st[nod] = (st[nod] * pw(lzy[nod], r - l + 1)) % mod;     st1[nod] |= ms[nod];     if (l != r) {       if (lzy[nod] != 1) {         lzy[nod * 2] *= lzy[nod];         lzy[nod * 2 + 1] *= lzy[nod];         lzy[nod * 2] %= mod;         lzy[nod * 2 + 1] %= mod;       }       ms[nod * 2] |= ms[nod];       ms[nod * 2 + 1] |= ms[nod];     }     lzy[nod] = 1;   }   void upd(int nod, int l, int r, int tl, int tr, long long v, long long m) {     push(nod, l, r);     if (tl <= l && r <= tr) {       lzy[nod] = (lzy[nod] * v) % mod;       ms[nod] |= m;       push(nod, l, r);       return;     }     int mid = (l + r) / 2;     if (tl <= mid) upd(nod * 2, l, mid, tl, tr, v, m);     if (mid < tr) upd(nod * 2 + 1, mid + 1, r, tl, tr, v, m);     push(nod * 2, l, mid);     push(nod * 2 + 1, mid + 1, r);     st[nod] = st[nod * 2] * st[nod * 2 + 1];     st[nod] %= mod;     st1[nod] = st1[nod * 2] | st1[nod * 2 + 1];   }   pair<long long, long long> qry(int nod, int l, int r, int tl, int tr) {     push(nod, l, r);     if (tl <= l && r <= tr) return {st[nod], st1[nod]};     int mid = (l + r) / 2;     pair<long long, long long> vl, x;     vl.first = 1, vl.second = 0;     if (tl <= mid) {       x = qry(nod * 2, l, mid, tl, tr);       vl.first = (vl.first * x.first) % mod;       vl.second |= x.second;     }     if (mid < tr) {       x = qry(nod * 2 + 1, mid + 1, r, tl, tr);       vl.first = (vl.first * x.first) % mod;       vl.second |= x.second;     }     return vl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> q;     for (j = 0; j < 62; j++) {       inv[j] = pw(pr[j], mod - 2);       sv[pr[j]] = j;     }     for (i = 1; i <= n; i++) {       cin >> a[i];       for (j = 0; j < 62; j++)         if (a[i] % pr[j] == 0) msk[i] |= (1LL << j);     }     for (i = 1; i <= 1600000; i++) lzy[i] = 1;     build(1, 1, n);     while (q--) {       cin >> s;       if (s[0] ==  M ) {         cin >> l >> r >> x;         x1 = x, m = 0;         for (j = 0; j < 62; j++)           if (x % pr[j] == 0) m |= (1LL << j);         upd(1, 1, n, l, r, x, m);       } else {         cin >> l >> r;         pair<long long, long long> p = qry(1, 1, n, l, r);         ans = p.first;         for (j = 0; j < 62; j++) {           if (p.second & (1LL << j)) {             ans = (ans * (1 - inv[j] + mod)) % mod;           }         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l;   long long dp[250005];   short big_arr[250005], small_arr[5001];   long long pre[51], sum[51], suf[51], mx[51], maxx = -1e5;   long long solve(int indx, long long curSum) {     if (indx == m + 1) return -2000;     short &i = big_arr[indx];     long long &res = dp[indx];     if (~res) return res;     res = pre[i];     if (curSum + sum[i] >= suf[i] && curSum + sum[i] > 0)       res = max(res, solve(indx + 1, curSum + sum[i]) + sum[i]);     else if (suf[i] > 0)       res = max(res, solve(indx + 1, suf[i]) + suf[i] - curSum);     else       res = max(res, solve(indx + 1, 0) - curSum);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     fill(pre, pre + 51, -1e5);     fill(suf, suf + 51, -1e5);     fill(mx, mx + 51, -1e5);     fill(dp, dp + 250005, -1);     for (int i = 0; i < n; i++) {       cin >> l;       long long tmp = 0;       for (int j = 0; j < l; j++) {         cin >> small_arr[j];         mx[i] = max((long long)small_arr[j], mx[i]);         if (tmp < 0) tmp = 0;         tmp += small_arr[j];         mx[i] = max(mx[i], tmp);         sum[i] += small_arr[j];         pre[i] = max(pre[i], sum[i]);       }       tmp = 0;       for (int j = l - 1; j >= 0; j--) {         tmp += small_arr[j];         suf[i] = max(suf[i], tmp);       }     }     for (int i = 1; i <= m; i++) {       cin >> big_arr[i];       big_arr[i]--;       maxx = max(mx[big_arr[i]], maxx);     }     cout << max(solve(1, 0), maxx) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 9901;   template <class T>   int countbit(T n) {     int t = 0;     while (n) n &= n - 1, ++t;     return t;   }   template <class T>   T lowbit(T n) {     return n & (-n);   }   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x7f7f7f7f;   const int maxn = 111111;   void File() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   long long c[66][66];   long long go(long long n, long long t) {     int cnt = 0;     long long tt = t;     while (tt) tt >>= 1, ++cnt;     int arr[65];     int i, size = 0;     while (n) arr[size++] = n & 1, n >>= 1;     reverse(arr, arr + size);     long long ans = 0;     bool flag;     int ct = count(arr, arr + size, 1);     for (i = 0; i < size; ++i) {       flag = true;       if (arr[i]) {         if (size - i == ct && ct == cnt && cnt)           ans++, flag = false;         else {           if (cnt >= 0) ans += c[size - i - 1][cnt], --cnt;         }         --ct;       }       if (i && !cnt) {         ans++;         break;       }       if (!flag) break;     }     if (t == 1) ans--;     return ans;   }   int main() {     ios::sync_with_stdio(false);     int i, j;     for (i = 0; i < 66; ++i) {       c[i][i] = c[i][0] = 1;     }     for (i = 1; i < 66; ++i) {       for (j = 1; j < i; ++j) {         c[i][j] = c[i - 1][j - 1] + c[i - 1][j];       }     }     long long n, t;     cin >> n >> t;     int k = countbit(t);     if (k == 1)       cout << go(n + 1, t) << endl;     else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   struct Point {     int x, y;     Point* next;     bool operator<(const Point& p) const { return 1ll * p.x * y < 1ll * x * p.y; }   } P[200010], *np = P;   std::map<long long, Point*> fir;   std::map<Point, int> M;   int main() {     int q, s = 0;     scanf( %d , &q);     while (q--) {       int t, x, y;       scanf( %d%d%d , &t, &x, &y);       long long d = 1ll * x * x + 1ll * y * y;       if (t == 1) {         M[(Point){x, y}]++;         for (Point* p = fir[d]; p; p = p->next)           M[(Point){x + p->x, y + p->y}] += 2;         *np = (Point){x, y, fir[d]};         fir[d] = np++;         s++;       }       if (t == 2) {         M[(Point){x, y}]--;         if (fir[d] && fir[d]->x == x && fir[d]->y == y) fir[d] = fir[d]->next;         ;         for (Point* p = fir[d]; p; p = p->next) {           if (p->next && p->next->x == x && p->next->y == y)             p->next = p->next->next;           ;           M[(Point){x + p->x, y + p->y}] -= 2;         }         s--;       }       if (t == 3) printf( %d n , s - M[(Point){x, y}]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long expo(long long x, long long n, long long m) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return expo((x * x) % m, n / 2, m);     else       return (x * expo((x * x) % m, (n - 1) / 2, m)) % m;   }   string DtoB(int j) {     string s =   ;     for (int i = 32; i >= 0; i--) {       int k = j >> i;       if (k & 1)         s +=  1 ;       else         s +=  0 ;     }     return s;   }   void solve() {     int n;     cin >> n;     int arr[n];     int s[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       s[i] = arr[i];     }     sort(s, s + n);     map<int, int> m;     for (int i = 0; i < n; i++) m[s[i]] = i;     vector<vector<int> > ans;     int visit[n];     memset(visit, 0, sizeof(visit));     ;     for (int i = 0; i < n; i++) {       if (visit[i] == 0) {         vector<int> p;         for (int j = i; visit[j] == 0; j = m[arr[j]]) {           p.push_back(j + 1);           visit[j] = 1;         }         ans.push_back(p);       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].size() <<    ;       for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] <<    ;       cout << endl;     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:320000000 )   using namespace std;   const double EPS = 1e-9;   const int INF = 0x7f7f7f7f;   const double PI = acos(-1.0);   template <class T>   inline T Abs(T n) {     return ((n) < 0 ? -(n) : (n));   }   template <class T>   inline T Max(T x, T y) {     return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;   }   template <class T>   inline T Min(T x, T y) {     return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;   }   template <class T>   inline T Swap(T &a, T &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   template <class T>   inline T gcd(T a, T b) {     return (b) == 0 ? (a) : gcd((b), ((a) % (b)));   }   template <class T>   inline T lcm(T a, T b) {     return ((a) / gcd((a), (b)) * (b));   }   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   struct an {     int a;     int d;     bool operator<(const an &t) const { return d < t.d; }   };   int main() {     int i, j, k, n, a[200];     int miniind, maxiind, maxi, mini;     while (scanf( %d , &n) != EOF) {       maxi = 0;       mini = 200;       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);         if (a[i] > maxi) {           maxi = a[i];           maxiind = i;         }         if (a[i] < mini) {           mini = a[i];           miniind = i;         }       }       printf( %d n ,              max(n - maxiind - 1, max(maxiind, max(n - miniind - 1, miniind))));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       long long n, g, b;       cin >> n >> g >> b;       if (g >= b) {         cout << n << endl;         continue;       }       long long good_need = n / 2;       if (n % 2 == 1) good_need += 1;       good_need -= g;       long long bad_poss = n / 2;       long long periods = bad_poss / b;       if (good_need - periods * g <= 0) {         cout << n << endl;         continue;       }       good_need -= periods * g;       long long restperiods = good_need / g;       long long rest = 0;       if (good_need % g != 0) {         rest = good_need % g + b;       }       cout << g + (periods + restperiods) * (g + b) + rest << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c, d;     while (scanf( %d , &n) != EOF) {       int j, x, y, flag = 0;       for (int i = 1; i <= 4; i++) {         scanf( %d%d%d%d , &a, &b, &c, &d);         a = min(a, b);         b = min(c, d);         if (a + b <= n) {           x = a;           y = n - x;           j = i;           flag = 1;         }       }       if (flag)         printf( %d %d %d n , j, x, y);       else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w[1501000], cnt[1501000];   int main() {     int N, i;     int po, ans;     scanf( %d , &N);     for (int i = (0); i < (N); i++) scanf( %d , w + i);     sort(w, w + N);     memset(cnt, 0, sizeof(cnt));     for (int i = (0); i < (N); i++) cnt[w[i]]++;     po = 0;     ans = 0;     for (int po = (0); po < (1501000); po++) {       if (cnt[po] == 0) continue;       cnt[po + 1] += cnt[po] / 2;       if (cnt[po] % 2) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h, m, n, vn;   map<int, pair<int, int> > M;   int group[222222], pos[222222], host[222222];   vector<int> v[222222], first[222222];   inline void add(int i, int x, int d) {     int m = first[i].size();     while (x < m) {       first[i][x] += d;       x = x | (x + 1);     }   }   inline int sum(int i, int x) {     int m = first[i].size(), res = 0;     while (x >= 0) {       res += first[i][x];       x = (x & (x + 1)) - 1;     }     return res;   }   int main() {     memset(host, -1, sizeof(host));     scanf( %d%d%d n , &h, &m, &n);     memset(group, -1, sizeof(group));     for (int i = 0; i < h; ++i)       if (group[i] == -1) {         for (int j = i; group[j] == -1; j = (j + m) % h) {           pos[j] = v[vn].size();           group[j] = vn;           v[vn].push_back(j);         }         ++vn;       }     for (int i = 0; i < vn; ++i) {       first[i].resize(int(v[i].size()));       for (int j = 0; j < v[i].size(); ++j) add(i, j, 1);     }     long long res = 0;     for (int i = 0; i < n; ++i) {       char ch;       int id, hash;       scanf( %c %d , &ch, &id);       if (ch ==  + ) {         scanf( %d , &hash);         int j = group[hash];         int k = pos[hash];         int l = k - 1, r = v[j].size();         int base = sum(j, k - 1);         while (r - l > 1) {           int mid = (l + r) / 2;           if (sum(j, mid) > base)             r = mid;           else             l = mid;         }         if (r < v[j].size()) {           M[id] = make_pair(j, r);           add(j, r, -1);           res += r - k;         } else {           l = -1, r = k;           while (r - l > 1) {             int mid = (l + r) / 2;             if (sum(j, mid) > 0)               r = mid;             else               l = mid;           }           M[id] = make_pair(j, r);           add(j, r, -1);           res += v[j].size() - k + r;         }       } else if (ch ==  - ) {         int j = M[id].first;         int k = M[id].second;         add(j, k, 1);       }       scanf(  n );     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, Max, reg;   int TIME = 0;   vector<int> T, W;   bool used[1010];   int p[1010], dmg[1010];   int main() {     int i, j, k, l, x, y;     cin >> n >> Max >> reg;     for (i = 0; i < n; ++i) cin >> p[i] >> dmg[i];     int ch = Max, cd = 0;     while (1) {       ch -= cd;       ch = min(Max, ch + reg);       if (ch <= 0) break;       j = -1;       for (i = 0; i < n; ++i) {         if (used[i] || p[i] * Max < 100 * ch) continue;         if (j == -1 || dmg[j] < dmg[i]) j = i;       }       if (j != -1 && dmg[j] >= 0) {         if (dmg[j] > cd || true) {           T.push_back(TIME);           W.push_back(j + 1);           used[j] = true;           cd += dmg[j];         }       }       ++TIME;       if (TIME >= 10000) break;     }     if (ch > 0)       cout <<  NO n ;     else {       cout <<  YES n ;       cout << TIME <<     << T.size() << endl;       for (i = 0; i < T.size(); ++i) cout << T[i] <<     << W[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 10;   const int N = 2e5;   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qmul(long long p, long long q, long long mo) {     long long f = 0;     while (q) {       if (q & 1) f = (f + p) % mo;       p = (p + p) % mo;       q >>= 1;     }     return f;   }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p % 19260817;       p = p * p % 19260817;       q >>= 1;     }     return f;   }   int n, m, k, t;   int main() {     int i, j;     scanf( %d , &n);     for (i = n;; i--) {       if (n % i) continue;       j = i;       int cnta = 0, cntb = 0;       while (j && j % 2 == 0) cnta++, j /= 2;       while (j && j % 2 == 1) cntb++, j /= 2;       if (!j && cntb == cnta + 1) return 0 * printf( %d n , i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1) {       cout << -1;       return 0;     }     if (n < 3) {       cout <<  bb nww n nbb nww ;       return 0;     }     string s1, s2;     for (int i = 0; i < 110; i++) s1 += (i % 4 < 2) ?  w  :  b ;     s2 = s1.substr(2);     s1 = s1.substr(0, n);     s2 = s2.substr(0, n);     for (int i = 0; i < n; i++) {       int x = i & 1;       for (int j = 0; j < n; j++) {         int y = (j % 4) < 2 ? 1 : 0;         if (x ^ y)           cout << s1 <<   n ;         else           cout << s2 <<   n ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[4], i, j, s;   int main() {     for (i = 0; i < 4; i++) {       scanf( %d , &a[i]);       s += a[i];     }     for (i = 0; i < 4; i++) {       if (a[i] == s - a[i]) {         puts( YES );         return 0;       }       for (j = i + 1; j < 4; j++)         if (a[i] + a[j] == s - a[i] - a[j]) {           puts( YES );           return 0;         }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static inline void amin(int &a, int b) {     if (a > b) a = b;   }   int main() {     int N, M;     scanf( %d%d , &N, &M);     int A[N];     for (int i = 0; i < N; ++i) {       scanf( %d , &A[i]);     }     pair<int, int> Q[M];     for (int i = 0; i < M; ++i) {       scanf( %d%d , &Q[i].first, &Q[i].second);       Q[i].first--;       Q[i].second--;     }     int res = *max_element(A, A + N) - *min_element(A, A + N);     list<int> res_q;     int changes[N];     for (int mx = 0; mx < N; ++mx) {       list<int> q;       memset(changes, 0, sizeof changes);       for (int i = 0; i < M; ++i)         if (mx < Q[i].first || Q[i].second < mx) {           q.push_back(i);           for (int j = Q[i].first; j < Q[i].second + 1; ++j) changes[j]--;         }       int mn = numeric_limits<int>::max();       for (int i = 0; i < N; ++i) amin(mn, A[i] + changes[i]);       if (res < A[mx] - mn) {         res = A[mx] - mn;         res_q = q;       }     }     printf( %d n%d n , res, (int)res_q.size());     for (auto it : res_q) printf( %d  , it + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   template <class T, class U>   istream &operator>>(istream &in, pair<T, U> &p) {     in >> p.first >> p.second;     return in;   }   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     out << p.first <<     << p.second;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &i : v) {       in >> i;     }     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (auto &i : v) {       out << i <<    ;     }     return out;   }   inline void io(int x = 15) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     srand(time(0));     cout << fixed << setprecision(x);   }   vector<int> prefix_function(string s) {     int n = s.length();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) {         j = pi[j - 1];       }       if (s[i] == s[j]) ++j;       pi[i] = j;     }     return pi;   }   bool prime_test(long long n) {     for (long long i = 2; i * i <= n; ++i)       if ((n >= 0 && n < 2) || n % i == 0) return false;     return true;   }   void prime_nums(int n, vector<char> &prime) {     prime[0] = prime[1] = false;     for (long long i = 2; i * i <= n; ++i) {       if (prime[i]) {         for (int j = i * i; j <= n; j += i) {           prime[j] = false;         }       }     }   }   long long bin_pow(long long a, long long b, long long m = 0) {     if (m == 0)       return b == 0 ? 1 : (b % 2 ? bin_pow(a, b - 1) * a : bin_pow(a * a, b / 2));     if (b == 0) return 1;     long long temp = bin_pow(a, b / 2, m);     if (b % 2 == 0)       return (temp * temp) % m;     else       return (a * temp * temp) % m;   }   bool nextperm(vector<char> &a) {     int n = a.size();     for (int i = n - 2; i >= 0; --i) {       if (a[i] < a[i + 1]) {         int mnv = a[i + 1], mni = i + 1;         for (int j = i + 2; j < n; ++j) {           if (a[j] < mnv && a[j] > a[i]) {             mni = j;             mnv = a[j];           }         }         swap(a[i], a[mni]);         reverse(a.begin() + i + 1, a.end());         return true;       }     }     return false;   }   int main() {     io();     int n, s;     cin >> n >> s;     vector<int> used(n);     for (int i = 0; i < n - 1; ++i) {       int l, r;       cin >> l >> r;       ++used[--l];       ++used[--r];     }     int x = 0;     for (int i = 0; i < n; ++i) {       if (used[i] == 1) {         ++x;       }     }     cout << (long double)s / x * 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n;   long long len[1000005];   long long pai[1000005];   string s;   long long find(long long x) {     if (pai[x] == x) return x;     return pai[x] = find(pai[x]);   }   void merge(long long a, long long b) {     long long paiA = find(a), paiB = find(b);     pai[paiB] = paiA;   }   int32_t main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(0);     cin >> n >> s;     long long p = 0, b = 0;     pai[0] = 0;     for (long long i = 1; i <= n; i++) {       pai[i] = i;       if (s[i - 1] ==  1 ) {         p++;         b = 0;       } else if (s[i - 1] ==  0 ) {         b++;         p = 0;       } else {         p++, b++;       }       len[i - 1] = max(p, b);     }     for (long long i = 1; i <= n; i++) {       long long res = 0, pos = 0;       while (pos < n) {         pos += i - 1;         while (pos < n and len[pos] < i) {           merge(pos + 1, pos);           pos = find(pos);         }         if (pos >= n) break;         pos++;         res++;       }       cout << res <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const bound = 2e6 + 2, N = 5e5 + 2;   long long OO = 1e18;   double eps = 1e-6;   int oo = 1e9, mod = oo + 7;   pair<int, int> can[101];   bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     if (a.first.first != b.first.first) return a.first.first > b.first.first;     return a.first.second < b.first.second;   }   int main() {     int n, m, k, a;     cin >> n >> k >> m >> a;     for (int(i) = 0; (i) < (a); (i)++) {       int g;       cin >> g;       g--;       can[g].first++;       can[g].second = i;     }     for (int(i) = 0; (i) < (n); (i)++) {       pair<pair<int, int>, int> tmp[101];       for (int(j) = 0; (j) < (n); (j)++) tmp[j] = {can[j], j};       int sv = tmp[i].first.second;       tmp[i].first.first += m - a;       if (m - a) tmp[i].first.second = m;       sort(tmp, tmp + n, cmp);       bool no = 1;       for (int(j) = 0; (j) < (k); (j)++) {         if (tmp[j].first.first && tmp[j].second == i) {           no = 0;           break;         }       }       if (no) {         cout << 3 <<    ;         continue;       }       int to = -1, rem = m - a;       for (int(j) = 0; (j) < (n); (j)++)         if (tmp[j].second == i) {           tmp[j].first.first -= m - a;           tmp[j].first.second = sv;         }       sort(tmp, tmp + n, cmp);       for (int(j) = 0; (j) < (n); (j)++) {         if (to != -1) {           if (rem < to - tmp[j].first.first + 1) break;           rem -= to - tmp[j].first.first + 1;           tmp[j].first.first += to - tmp[j].first.first + 1;           tmp[j].first.second = m;         }         if (tmp[j].second == i) to = tmp[j].first.first;       }       sort(tmp, tmp + n, cmp);       no = 1;       for (int(j) = 0; (j) < (k); (j)++)         if (tmp[j].first.first && tmp[j].second == i) no = 0;       if (no)         cout << 2 <<    ;       else         cout << 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int z[26][200001], w[26];   int main() {     int n, m, i, j, a, le;     char str[200001];     scanf( %d %d , &n, &m);     scanf( %s , str);     for (i = 0; str[i]; i++) {       z[str[i] -  a ][w[str[i] -  a ]] = i;       w[str[i] -  a ]++;     }     long long ans;     int mi;     while (n) {       n--;       ans = 0;       scanf( %s , str);       le = strlen(str);       for (i = 0; str[i]; i++) {         a = str[i] -  a ;         if (w[a] == 0)           ans += le;         else {           mi = abs(i - z[a][0]);           ;           for (j = 1; j < w[a]; j++) {             mi = min(mi, abs(i - z[a][j]));           }           ans += mi;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 100;   const long double eps = 1e-11;   const long double pi = acos(-1.0L);   int myrand() { return rand(); }   unsigned rdtsc() {     unsigned ans;     asm( rdtsc  :  =a (ans));     return ans;   }   int rnd(int x) { return myrand() % x; }   void precalc() {}   int n, k;   int a, b, c, d;   bool read() {     if (scanf( %d%d , &n, &k) < 2) {       return false;     }     scanf( %d%d%d%d , &a, &b, &c, &d);     return true;   }   void solve() {     if (n <= 4 || k < n + 1) {       printf( -1 n );       return;     }     vector<int> path;     for (int i = 1; i <= n; i++) {       if (i != a && i != b && i != c && i != d) {         path.push_back(i);       }     }     printf( %d %d  , a, c);     for (int i = 0; i < ((int)((path).size())); i++) {       printf( %d  , path[i]);     }     printf( %d %d n , d, b);     printf( %d %d  , c, a);     for (int i = 0; i < ((int)((path).size())); i++) {       printf( %d  , path[i]);     }     printf( %d %d n , b, d);   }   int main() {     srand(rdtsc());     precalc();     while (true) {       if (!read()) {         break;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     cout << a[0];     for (int e = 1; e < a.size(); e++)       if (a[e] < b[0])         cout << a[e];       else         break;     cout << b[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     map<int, int> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) {           ++m[a[i] + a[j]];         }       }     }     int Max = 0;     for (auto it = m.begin(); it != m.end(); it++) {       Max = max(it->second / 2, Max);     }     cout << Max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     string In;     vector<char> Que;     cin >> n >> t >> In;     for (char x : In) {       Que.push_back(x);     }     for (int i = 0; i < t; i++) {       for (int x = 0; x < n; x++) {         if (Que[x] ==  B  && Que[x + 1] ==  G ) {           Que[x] =  G ;           Que[x + 1] =  B ;           x++;         }       }     }     for (char x : Que) {       cout << x;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 100011;   const int MAX = 1e9;   int mi[SIZE << 2], a[SIZE];   void init(int L, int R, int id) {     mi[id] = MAX;     if (L == R) return;     int mm = (L + R) >> 1;     init(L, mm, id << 1);     init(mm + 1, R, (id << 1) + 1);   }   void ins(int L, int R, int id, int x, int v) {     if (L == R) {       mi[id] = v;       return;     }     int mm = (L + R) >> 1;     if (x <= mm)       ins(L, mm, id << 1, x, v);     else       ins(mm + 1, R, (id << 1) + 1, x, v);     mi[id] = min(mi[id << 1], mi[(id << 1) | 1]);   }   int qq(int L, int R, int id, int l1, int rr) {     if (L >= l1 && R <= rr) return mi[id];     if (R < l1 || L > rr) return MAX;     int mm = (L + R) >> 1;     return min(qq(L, mm, id << 1, l1, rr), qq(mm + 1, R, (id << 1) | 1, l1, rr));   }   int main() {     int n, s, l;     scanf( %d%d%d , &n, &s, &l);     init(0, n, 1);     ins(0, n, 1, 0, 0);     multiset<int> H;     int lt = 1, an;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[i] = x;       H.insert(x);       while (*H.rbegin() - *H.begin() > s) {         H.erase(H.find(a[lt++]));       }       if (i - lt + 1 >= l) {         ins(0, n, 1, i, an = qq(0, n, 1, lt - 1, i - l) + 1);       } else         an = MAX;     }     if (an >= MAX)       puts( -1 );     else       printf( %d n , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, start, x;   pair<int, int> ask(int v) {     printf( ? %d n , v);     fflush(stdout);     int value, nxt;     scanf( %d %d , &value, &nxt);     return pair<int, int>(value, nxt);   }   const int RANDOM_Q = 1000;   int main() {     srand(time(NULL));     scanf( %d %d %d , &n, &start, &x);     vector<int> v;     for (int i = int(1); i < int(n + 1); i++) {       v.push_back(i);     }     random_shuffle(v.begin(), v.end());     vector<int> randoms;     for (int i = int(0); i < int(min(RANDOM_Q, (int)v.size())); i++) {       randoms.push_back(v[i]);     }     int ans = (int)2e9;     int possible_start = start, start_val = -1;     for (auto &each : randoms) {       pair<int, int> p = ask(each);       if (p.first >= x && p.first < ans) {         ans = p.first;       } else if (p.first < x && p.first > start_val) {         possible_start = p.second;         start_val = p.first;       }     }     int cur = possible_start;     for (int i = 0; cur != -1 && i < 1999 - RANDOM_Q; i++) {       pair<int, int> p = ask(cur);       if (p.first >= x) {         ans = p.first;         break;       }       cur = p.second;     }     printf( ! %d n , ans == (int)2e9 ? -1 : ans);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   #define ll long long   using namespace std;      int main()   {       ios_base::sync_with_stdio(0) ;       cin.tie(0) ;       cout.tie(0) ;       int t;       cin>>t;       while(t--)       {           ll n,x,s=0,a=1;           cin>>n>>x;           ll arr[n];           for(int i=0; i<n; i++)           {               cin>>arr[i];           }              int mn=100000000,gg=mn,ind=-1;              for(int i=0; i<n; i++)           {               int y=arr[i],cnt=0;               while(!(y%x))               {                   y/=x;                   cnt++;               }               if(cnt<mn)               {                   mn=cnt;                   ind=i;               }           }              for(int i=0; i<n; i++)           {               if(i<ind)               gg=mn+1;               else                   gg=mn;               s+=arr[i];               a=1;               while(((arr[i]%x)==0)&&(gg--))               {                   a*=x;                   arr[i]/=x;                   s+=a*arr[i];               }           }              cout<<s<<  n ;          }      }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int c = 0;     for (int j = 0; j < str.length(); j++) {       if (str[j] ==  @ ) {         c = c + 1;       }     }     if (c == 0) {       cout <<  No solution  << endl;     } else if (c > 0) {       int c1 = 1;       int i = 0;       for (; i < str.length(); i++) {         char ch = str[i];         if (ch ==  @  and (i == 0 or i == (str.length() - 1))) {           break;         } else if (ch ==  @  and (i > 0 and i < (str.length() - 1))) {           char ch1 = str[i - 1];           char ch2 = str[i + 1];           if (ch1 ==  ,  or ch2 ==  , ) {             break;           }           if (ch1 !=  ,  and ch2 !=  ,  and c1 != c) {             string str1 = str.substr(0, i + 2);             string str2 = str.substr(i + 2);             str = str1 +  ,  + str2;             c1 = c1 + 1;           }           if (ch1 !=  ,  and ch2 !=  ,  and c1 == c) {             continue;           }         }       }       if (i < str.length()) {         cout <<  No solution  << endl;       }       if (i >= str.length()) {         cout << str << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> h(n);     for (int i = 0; i < n; i++) cin >> h[i];     vector<pair<int, int> > v(n);     for (int i = 0; i < n; i++) {       v[i] = make_pair(h[i], i);     }     sort(v.begin(), v.end());     sort(h.begin(), h.end());     h.erase(unique(h.begin(), h.end()), h.end());     if (n - h.size() < 2) {       cout <<  NO  << endl;       return 0;     } else {       cout <<  YES  << endl;     }     map<int, int> x;     for (int i = 0; i + 1 < n; i++) {       if (v[i].first == v[i + 1].first) {         x[v[i].first] += 1;       }     }     int type = x.size();     for (int i = 0; i < 3; i++) {       if (i == 0) {         for (int j = 0; j < n; j++) {           printf( %d  , v[j].second + 1);         }         printf(  n );       } else {         if (type == 1) {           vector<pair<int, int> >::iterator it =               lower_bound(v.begin(), v.end(), make_pair(x.begin()->first, -1));           swap(v[it - v.begin()], v[it - v.begin() + i]);           for (int j = 0; j < n; j++) {             printf( %d  , v[j].second + 1);           }           printf(  n );         } else {           vector<pair<int, int> >::iterator it =               lower_bound(v.begin(), v.end(), make_pair(x.begin()->first, -1));           x.erase(x.begin());           swap(v[it - v.begin()], v[it - v.begin() + 1]);           for (int j = 0; j < n; j++) {             printf( %d  , v[j].second + 1);           }           printf(  n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   int a[N];   int main() {     long long ans = 0, ones = 0, k;     string s;     cin >> k >> s;     a[0] = -1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) ones++, a[ones] = i;       if (ones >= k) {         if (k != 0)           ans += a[ones - k + 1] - a[ones - k];         else if (s[i] ==  0 )           ans += i - a[ones];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, p = 1e9 + 7;   int n, cnt[26], inv[N], fac[N], finv[N];   char a[N], b[N];   inline int solve(char *s) {     int ans = 0, noans = fac[n];     memset(cnt, 0, sizeof cnt);     for (int i = 1; i <= n; ++i) ++cnt[a[i] -  a ];     for (int i = 0; i < 26; ++i) noans = 1ll * noans * finv[cnt[i]] % p;     for (int i = 1; i <= n; ++i) {       int v = s[i] -  a ;       noans = 1ll * noans * inv[n - i + 1] % p;       for (int c = 0; c < v; ++c)         if (cnt[c]) {           noans = 1ll * noans * cnt[c] % p;           ans = (ans + noans) % p;           noans = 1ll * noans * inv[cnt[c]] % p;         }       if (!cnt[v]) return ans;       noans = 1ll * noans * cnt[v] % p;       --cnt[v];     }     return ans;   }   int main() {     scanf( %s%s , a + 1, b + 1);     n = strlen(a + 1);     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % p;     inv[0] = inv[1] = 1;     for (int i = 2; i <= n; ++i) inv[i] = 1ll * inv[p % i] * (p - p / i) % p;     finv[0] = 1;     for (int i = 1; i <= n; ++i) finv[i] = 1ll * inv[i] * finv[i - 1] % p;     printf( %d , (solve(b) - solve(a) - 1 + p) % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<long long> vis(n);       for (int i = 0, ggdem = m; i < ggdem; ++i) {         long long a, b, c;         cin >> a >> b >> c;         a--;         b--;         c--;         vis[b] = 1;       }       long long ve = -1;       for (int i = 0, ggdem = n; i < ggdem; ++i) {         if (vis[i] == 0) ve = i;       }       for (int i = 0, ggdem = n; i < ggdem; ++i) {         if (i != ve) {           cout << i + 1 <<     << ve + 1 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     unsigned long long int n, sum = 0, sum1 = 0, i, MAX = 0, temp;     scanf( %llu , &n);     int a[n];     for (i = 0; i < n; ++i) {       scanf( %llu , &a[i]);     }     for (i = 0; i < n; ++i) {       sum = sum + a[i];     }     for (i = 0; i < n; ++i) {       if (a[i] > MAX) {         MAX = a[i];       }     }     for (i = 0; i < n; ++i) {       if (a[i] == MAX) {         break;       }     }     temp = a[n - 1];     a[n - 1] = MAX;     a[i] = temp;     if (sum % 2 != 0) {       printf( NO );     } else {       for (i = 0; i < n - 1; ++i) {         sum1 = sum1 + a[i];       }       if (sum1 >= a[n - 1]) {         printf( YES );       } else {         printf( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, x, y;     cin >> n >> x >> y;     int a[n];     int c = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= x) c++;     }     if (x > y)       cout << n << endl;     else {       if (c % 2 == 0)         cout << c / 2 << endl;       else         cout << (c / 2) + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int block[101];   int nuclea[101];   int inst[101][101];   int main() {     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> inst[j][i];       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (nuclea[j] == 0) block[inst[i][j]]++;       }       block[0] = 0;       for (int j = 0; j < n; j++) {         if (block[inst[i][j]] > 1 && nuclea[j] == 0) {           nuclea[j] = i + 1;         }       }       for (int i = 1; i < 101; i++) {         if (block[i] < 2) block[i] = 0;       }     }     for (int i = 0; i < n; i++) cout << nuclea[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3 * 100 * 1000 + 1000;   const int N1 = 5100;   long long A[N], n, k;   unsigned long long dp[N1][N1];   void read() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     for (int i = 0; i < N1; i++)       for (int j = 0; j < N1; j++) dp[i][j] = (1 << 31);   }   int cal(int p, int q) { return p * ((n + k - 1) / k) + q * (n / k) - 1; }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     read();     int p = n % k, q = k - n % k;     dp[0][0] = 0;     for (int i = 0; i <= p; i++)       for (int j = 0; j <= q; j++) {         int last = cal(i, j);         if (i - 1 >= 0)           dp[i][j] = min(dp[i][j],                          dp[i - 1][j] + A[last] - A[last - (n + k - 1) / k + 1]);         if (j - 1 >= 0)           dp[i][j] =               min(dp[i][j], dp[i][j - 1] + A[last] - A[last - (n / k) + 1]);       }     cout << dp[p][q] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? n == 1 ? x : b_pow(x, n >> 1) * b_pow(x, (n >> 1) + (n & 1)) : 1;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   string table[119] = {        - ,   H ,   He ,  Li ,  Be ,  B ,    C ,    N ,    O ,    F ,    Ne ,  Na ,        Mg ,  Al ,  Si ,  P ,   S ,   Cl ,   Ar ,   K ,    Ca ,   Sc ,   Ti ,  V ,        Cr ,  Mn ,  Fe ,  Co ,  Ni ,  Cu ,   Zn ,   Ga ,   Ge ,   As ,   Se ,  Br ,        Kr ,  Rb ,  Sr ,  Y ,   Zr ,  Nb ,   Mo ,   Tc ,   Ru ,   Rh ,   Pd ,  Ag ,        Cd ,  In ,  Sn ,  Sb ,  Te ,  I ,    Xe ,   Cs ,   Ba ,   La ,   Ce ,  Pr ,        Nd ,  Pm ,  Sm ,  Eu ,  Gd ,  Tb ,   Dy ,   Ho ,   Er ,   Tm ,   Yb ,  Lu ,        Hf ,  Ta ,  W ,   Re ,  Os ,  Ir ,   Pt ,   Au ,   Hg ,   Tl ,   Pb ,  Bi ,        Po ,  At ,  Rn ,  Fr ,  Ra ,  Ac ,   Th ,   Pa ,   U ,    Np ,   Pu ,  Am ,        Cm ,  Bk ,  Cf ,  Es ,  Fm ,  Md ,   No ,   Lr ,   Rf ,   Db ,   Sg ,  Bh ,        Hs ,  Mt ,  Ds ,  Rg ,  Cn ,  Uut ,  Uuq ,  Uup ,  Uuh ,  Uus ,  Uuo };   vector<int> item, goal, able[17];   int n, m;   void output(int bit, int num) {     vector<string> ans;     for (int i = 0; i < n; i++)       if (bit & (1 << i)) ans.push_back(table[item[i]]);     for (int i = 0; i < ans.size(); i++) cout << (i ?  +  :   ) << ans[i];     cout <<  ->  << table[goal[num]] << endl;   }   vector<int> currentUsing;   bool done[1 << 17][17];   bool dfs(int pos, int bit) {     if (pos == m) {       cout <<  YES  << endl;       for (int i = 0; i < pos; i++) output(currentUsing[i], i);       return true;     }     if (done[bit][pos])       return false;     else       done[bit][pos] = 1;     for (int i = 0; i < able[pos].size(); i++) {       if (bit & able[pos][i]) continue;       currentUsing.push_back(able[pos][i]);       if (dfs(pos + 1, bit | able[pos][i])) return true;       currentUsing.pop_back();     }     return false;   }   int main() {     cin >> n >> m;     string tmp;     for (int i = 0; i < n; i++)       cin >> tmp, item.push_back(find(table, table + 119, tmp) - table);     for (int i = 0; i < m; i++)       cin >> tmp, goal.push_back(find(table, table + 119, tmp) - table);     for (int i = 0; i < m; i++) {       for (int bit = 0; bit < (1 << n); bit++) {         int sum = 0;         for (int j = 0; j < n; j++)           if (bit & (1 << j)) sum += item[j];         if (sum == goal[i]) able[i].push_back(bit);       }     }     if (!dfs(0, 0)) cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int mod = 998244353;   int a[N], s[N], f[N][105], b[N][105];   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;     return;   }   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   int main() {     int n, k, len;     read(n), read(k), read(len);     if (len == 1) {       printf( 0 n );       return 0;     }     s[0] = 1;     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= k; ++j)         if (a[i] == j || a[i] == -1) b[i][j] = 1;     for (int j = 1; j <= k; ++j)       for (int i = 1; i <= n; ++i) b[i][j] += b[i - 1][j];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= k; ++j) {         if (~a[i] && a[i] != j) continue;         f[i][j] = s[i - 1];         if (i >= len && b[i][j] - b[i - len][j] == len)           add(f[i][j], (f[i - len][j] - s[i - len] + mod) % mod);         add(s[i], f[i][j]);       }     }     printf( %d n , s[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int head[N], Next[N], ver[N], tot;   inline void add(int u, int v) {     ver[++tot] = v, Next[tot] = head[u], head[u] = tot;   }   int pa[N][25], top[N], son[N], dep[N], ans, n, L;   long long sum[N], w[N], S;   inline void init(int u) {     for (int i = 1; i <= 20; ++i) pa[u][i] = pa[pa[u][i - 1]][i - 1];     int dis = L, tmp = u;     for (int i = 20; i >= 0; --i) {       int fa = pa[tmp][i];       if (!fa || (1 << i) >= dis) continue;       if (sum[u] - sum[fa] + w[fa] > S) continue;       dis -= (1 << i), top[u] = fa, tmp = fa;     }   }   void dfs1(int u, int fa) {     sum[u] = sum[fa] + w[u], top[u] = u, dep[u] = dep[fa] + 1, init(u);     for (int i = head[u]; i; i = Next[i]) dfs1(ver[i], u);   }   void dfs2(int u) {     int mx = -1;     for (int i = head[u]; i; i = Next[i]) {       int v = ver[i];       dfs2(v);       if (son[v] == v) continue;       if (mx == -1 || dep[mx] > dep[son[v]]) mx = son[v];     }     if (mx == -1) ++ans, mx = top[u];     son[u] = mx;   }   int main() {     scanf( %d%d%lld , &n, &L, &S);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &w[i]);       if (w[i] > S) return puts( -1 ), 0;     }     for (int i = 2, f; i <= n; ++i) scanf( %d , &f), add(f, i), pa[i][0] = f;     dfs1(1, 0), dfs2(1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 9;   vector<pair<int, int> > barr[N];   int n, q, arr[N], a, b;   long long t[N], ans[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     scanf( %d , &q);     int kok = sqrt(n);     for (int i = 1; i <= q; i++) {       scanf( %d %d , &a, &b);       if (b > kok) {         for (int j = a; j <= n; j += b) ans[i] += arr[j];       } else         barr[b].push_back(make_pair(a, i));     }     for (int i = 1; i <= kok; i++) {       if (barr[i].size()) {         for (int j = n; j >= 1; j--) t[j] = arr[j] + t[(i + j) * (i + j <= n)];         for (int j = 0; j < barr[i].size(); j++)           ans[barr[i][j].second] = t[barr[i][j].first];       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxN = 5e5 + 5;   int m, k, n, s;   vector<int> a;   int c[maxN], h[maxN];   int main(int argc, char *argv[]) {     cin >> m >> k >> n >> s;     a.resize(m + 1);     for (int i = 1; i <= m; ++i) cin >> a[i];     int total = 0;     for (int i = 0; i < s; ++i) {       int x;       cin >> x;       c[x]++;       if (c[x] == 1) total++;     }     int cur_s = 0;     vector<int> ans;     bool found = false;     for (int l = 1, r = 1; l + k - 1 <= m; ++l) {       while ((cur_s < total && r <= m) || r - l + 1 <= k) {         h[a[r]]++;         if (h[a[r]] == c[a[r]]) cur_s++;         r++;       }       if (cur_s == total && (l - 1) / k + (m - r + 1) / k + 1 >= n) {         found = true;         int to_remove = r - l - k;         for (int i = l; to_remove > 0 && i < r; ++i) {           if (h[a[i]] > c[a[i]]) {             to_remove--;             ans.emplace_back(i);             h[a[i]]--;           }         }         break;       }       if (h[a[l]] == c[a[l]]) cur_s--;       h[a[l]]--;     }     if (found == false)       cout << -1 << endl;     else {       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); ++i) {         if (i > 0) cout <<    ;         cout << ans[i];       }       cout << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const char nl =   n ;   const long long mod = 1e9 + 7;   long long bigmod(long long a, long long b) {     if (b == 0) return 1;     long long ans = bigmod(a, b / 2);     ans = (ans * ans) % mod;     if (b & 1) ans *= a;     return ans % mod;   }   void solve() {     long long n;     cin >> n;     cout << (bigmod(4, pow(2, n) - 2) * 6) % mod << nl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   inline bool read(int &x) {     char ch;     bool flag = false;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) flag = true;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     x = flag ? -x : x;     if (ch ==   n ) return 0;     return 1;   }   inline void write(int x) {     static const int maxlen = 100;     static char s[maxlen];     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     int len = 0;     for (; x; x /= 10) s[len++] = x % 10 +  0 ;     for (int i = len - 1; i >= 0; --i) putchar(s[i]);   }   const int MAXN = 2500;   int n, lim;   int g[MAXN][MAXN];   char s[MAXN];   int f[MAXN][MAXN];   bool go_l[MAXN][MAXN], go_r[MAXN][MAXN];   bool go_up[MAXN][MAXN], go_down[MAXN][MAXN];   int add_l[MAXN][MAXN];   int add_h[MAXN][MAXN];   int sum_l[MAXN][MAXN];   int sum_h[MAXN][MAXN];   int main() {     read(n);     read(lim);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       for (int j = 1; j <= n; j++)         if (s[j - 1] ==  B )           g[i][j] = 1;         else           g[i][j] = 0;     }     for (int i = 1; i <= n; i++) {       go_l[i][0] = 1;       for (int j = 1; j <= n; j++)         if ((go_l[i][j - 1]) && (g[i][j] == 0))           go_l[i][j] = 1;         else           go_l[i][j] = 0;       go_r[i][n + 1] = 1;       for (int j = n; j >= 1; j--)         if ((go_r[i][j + 1]) && (g[i][j] == 0))           go_r[i][j] = 1;         else           go_r[i][j] = 0;       for (int j = 1; j <= n - lim + 1; j++)         if (go_l[i][j - 1] && go_r[i][j + lim] && (!go_r[i][1]))           add_h[i][j] = 1;         else           add_h[i][j] = 0;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum_h[i][j] = sum_h[i - 1][j] + add_h[i][j];     for (int j = 1; j <= n; j++) {       go_up[0][j] = 1;       for (int i = 1; i <= n; i++)         if ((go_up[i - 1][j]) && (g[i][j] == 0))           go_up[i][j] = 1;         else           go_up[i][j] = 0;       go_down[n + 1][j] = 1;       for (int i = n; i >= 1; i--)         if ((go_down[i + 1][j]) && (g[i][j] == 0))           go_down[i][j] = 1;         else           go_down[i][j] = 0;       for (int i = 1; i <= n - lim + 1; i++)         if (go_up[i - 1][j] && go_down[i + lim][j] && (!go_down[1][j]))           add_l[i][j] = 1;         else           add_l[i][j] = 0;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum_l[i][j] = sum_l[i][j - 1] + add_l[i][j];     int tot = 0;     for (int i = 1; i <= n; i++)       if (go_r[i][1]) tot++;     for (int i = 1; i <= n; i++)       if (go_down[1][i]) tot++;     int ans = 0;     for (int i = 1; i <= n - lim + 1; i++)       for (int j = 1; j <= n - lim + 1; j++)         ans = max(ans, (sum_l[i][j + lim - 1] - sum_l[i][j - 1]) +                            (sum_h[i + lim - 1][j] - sum_h[i - 1][j]));     cout << ans + tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   long long int n, k, mx, sum, a[N];   int main() {     cin >> n >> k;     sum++;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i) {         if (a[i] != a[i - 1]) {           sum++;           mx = max(mx, sum);         } else {           sum = 1;         }       }     }     mx = max(sum, mx);     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   void solve() {     int n, k;     cin >> n >> k;     string A[n];     map<string, int> m;     for (int i = (0); i < (n); i++) {       cin >> A[i];       m[A[i]]++;     }     long long ans = 0;     sort(A, A + n);     set<string> st;     for (int i = (0); i < (n - 2); i++) {       for (int j = (i + 1); j < (n - 1); j++) {         string s(k,  . );         for (int z = (0); z < (k); z++) {           if (A[i][z] == A[j][z]) {             s[z] = A[i][z];           } else {             int tmp = A[i][z] + A[j][z];             if (tmp == 152) {               s[z] =  T ;             } else if (tmp == 153) {               s[z] =  S ;             } else {               s[z] =  E ;             }           }         }         string tmp = A[i] + A[j] + s;         if (s.compare(A[i]) >= 0 && s.compare(A[j]) >= 0 &&             st.find(tmp) == st.end()) {           ans += m[s];           if (s.compare(A[i]) == 0) {             ans--;           }           if (s.compare(A[j]) == 0) {             ans--;           }           st.insert(tmp);         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int n, k, f, c, ans;   int main() {     cin >> n >> k;     for (int i = 2; i <= n; i++) {       f = 0;       for (int j = 2; j <= i / 2; j++) f += (i % j == 0);       if (f == 0) a.push_back(i);     }     for (int i = 2; i < a.size(); i++)       for (int j = 1; j < i && a[j - 1] + a[j] + 1 <= a[i]; j++)         if (a[j - 1] + a[j] + 1 == a[i]) ans++;     if (ans >= k)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, f[200009];   int judge(int len) {     if (len == 2) return 0;     if (len == 3) return k == (n - 1) ? 1 : 0;     if ((long long)(k - 2) * ((len - 1) / 2 - 1) < n - len - k + 2) return 0;     return 1;   }   int main() {     scanf( %d%d , &n, &k);     int l = 2, r = n - k + 2, len = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (judge(mid))         r = mid - 1, len = mid;       else         l = mid + 1;     }     printf( %d n , len - 1);     for (int i = 1; i < len; i++) printf( %d %d n , i, i + 1);     int lf = k - 2, ilf = n - len - k + 2, t = len + 1;     for (int i = 1; i <= lf; i++) {       printf( %d %d n , (len + 1) / 2, t);       f[i] = t, t++;     }     int x = 1;     while (ilf > 0) {       printf( %d %d n , f[x], t);       f[x] = t;       t++;       x = x % lf + 1;       ilf--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long N = 100001;   long long mod = 1000000007;   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long power(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long p, long long q) {     if (p % q == 0)       return q;     else {       return gcd(q, p % q);     }   }   long long mul(long long a, long long b) {     return ((a % mod) * (b % mod)) % mod;   }   long long sub(long long a, long long b) {     return (((a - b) % mod) + mod) % mod;   }   vector<long long> kmp(string s) {     long long n = s.size();     vector<long long> ans(n);     long long len = 0;     for (long long i = 1; i < n; i++) {       while (len > 0 && s[len] != s[i]) len = ans[len - 1];       len += (s[i] == s[len]);       ans[i] = len;     }     return ans;   }   void solve() {     string s;     cin >> s;     vector<long long> ans = kmp(s);     if (ans.back() == 0) {       cout <<  Just a legend  <<   n ;       return;     }     for (long long i = 1; i < s.size() - 1; i++) {       if (ans[i] == ans.back()) {         cout << s.substr(0, ans[i]);         cout <<   n ;         return;       }     }     if (ans[ans.back() - 1] == 0)       cout <<  Just a legend ;     else       cout << s.substr(0, ans[ans.back() - 1]);   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     int curr_len = 0;     int l = 0, r = a.size() - 1;     while (l <= r) {       if (a[l] - 1 < int(1e6) - a[r]) {         curr_len = a[l] - 1;         ++l;       } else {         curr_len = int(1e6) - a[r];         --r;       }     }     cout << curr_len;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 400;   struct hh {     double x, y;   } a[MAX];   double jisuan(hh a, hh b, hh c) {     double x1, y1, x2, y2;     x1 = b.x - a.x;     y1 = b.y - a.y;     x2 = c.x - a.x;     y2 = c.y - a.y;     return (x1 * y2 - x2 * y1) / 2;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].x >> a[i].y;     }     double area, l, r;     area = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         l = r = 0;         for (int k = 0; k < n; k++) {           double w = jisuan(a[i], a[j], a[k]);           if (w > 0 && w > l)             l = w;           else if (w < 0 && -w > r)             r = -w;         }         if (l + r > area && l > 0 && r > 0) area = l + r;       }     }     printf( %.6f n , area);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     cout << (n * 6 - 1) * k << endl;     for (int i = 0; i < n; i++)       cout << (i * 6 + 1) * k <<     << (i * 6 + 2) * k <<     << (i * 6 + 3) * k            <<     << (i * 6 + 5) * k << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   default_random_engine gen(42);   uniform_real_distribution<double> ran(0, 1);   void vin(std::vector<int> &a) {     for (auto &x : a) cin >> x;   }   void vout(std::vector<int> &a) {     for (auto x : a) cout << x <<    ;     cout << endl;   }   bool vm(array<pair<int, int>, 2> m) {     if (abs(m[0].first - m[1].first) + abs(m[0].second - m[1].second) != 3)       return 0;     if (m[0].first == m[1].first || m[0].second == m[1].second) return 0;     return 1;   }   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return {a.first + b.first, a.second + b.second};   }   std::vector<pair<int, int> > mo{{1, 2},   {2, 1},   {2, -1}, {1, -2},                                   {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}};   array<std::vector<std::vector<int> >, 2> dp;   int n, m;   void initdp() {     for (int qw = 0; qw < 2; qw++) {       dp[qw].resize(n, std::vector<int>(m, -1));       priority_queue<tuple<int, int, int>, std::vector<tuple<int, int, int> >,                      greater<tuple<int, int, int> > >           pq;       pq.emplace(make_tuple(0, n / 2 - 1 + qw, m / 2 - 1));       while (!pq.empty()) {         int x, y, d;         tie(d, x, y) = pq.top();         pq.pop();         if (dp[qw][x][y] != -1) continue;         dp[qw][x][y] = d;         for (auto move : mo) {           pair<int, int> t = move + make_pair(x, y);           if (t.first >= 0 && t.first < n && t.second >= 0 && t.second < m &&               dp[qw][t.first][t.second] == -1)             pq.emplace(make_tuple(d + 1, t.first, t.second));         }       }     }   }   int dist(pair<int, int> b, bool t) { return dp[t][b.first][b.second]; }   int end(array<pair<int, int>, 2> a, bool t) {     if (vm(a)) return t;     if (a[0].first == n / 2 - 1 && a[0].second == m / 2 - 1) return 0;     if (a[1] == make_pair(n / 2, m / 2 - 1)) return 1;     return -1;   }   pair<int, int> w;   double rek(array<pair<int, int>, 2> a, bool t, int rd = 6, double mx = INT_MAX,              double mn = INT_MIN) {     pair<int, int> mw = {0, 0};     if (end(a, t) != -1)       return ((end(a, t) ? 1000 : -1000) + ran(gen) * .001) * pow(1.01, rd);     if (rd == 0) {       double d[2][2];       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) d[i][j] = dist(a[i], j);       d[t][0] -= .5;       d[t][1] -= .5;       return (d[0][0] - d[1][1] + (d[0][1] - d[1][0]) * .1 + ran(gen) * .001) *              pow(1.01, rd);     }     double rt = t ? -100000 : 100000;     priority_queue<array<pair<int, int>, 2>,                    std::vector<array<pair<int, int>, 2> >,                    greater<array<pair<int, int>, 2> > >         pq;     for (auto x : mo) {       pair<int, int> c = a[t] + x;       if (c.first >= 0 && c.first < n && c.second >= 0 && c.second < m)         pq.emplace(array<pair<int, int>, 2>{             make_pair(dp[t][c.first][c.second], dp[!t][c.first][c.second]), c});     }     assert(!pq.empty());     while (!pq.empty()) {       array<pair<int, int>, 2> n = a;       n[t] = pq.top()[1];       pq.pop();       double r = rek(n, !t, rd - 1, mx, mn);       if ((t && r > rt) || (!t && r < rt)) {         rt = r;         mw = n[t];       }       if ((t && rt > mx) || (!t && rt < mn)) break;       if (t)         mn = max(mn, rt);       else         mx = min(mx, rt);     }     w = mw;     return rt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     initdp();     int xWI, yWI, xBL, yBL;     cin >> xWI >> yWI >> xBL >> yBL;     xWI--;     yWI--;     xBL--;     yBL--;     array<pair<int, int>, 2> a = {make_pair(xWI, yWI), make_pair(xBL, yBL)};     if (vm(a)) {       cout <<  WHITE n  << xBL + 1 <<     << yBL + 1 <<   n ;       return 0;     }     double r = rek(a, 0);     int me;     if (fabs(r) > 500)       me = r > 0;     else {       int fr = ((xWI + yWI + xBL + yBL) % 2);       int df = dp[fr][a[fr].first][a[fr].second],           da = dp[fr][a[!fr].first][a[!fr].second];       cerr << df <<     << da <<   n ;       if (df + 1 + fr <= da)         me = fr;       else         me = !fr;     }     cout << (me ?  BLACK  :  WHITE ) << endl;     int t = 0;     while (true) {       if (t == me) {         rek(a, t);         cout << w.first + 1 <<     << w.second + 1 << endl;         if (w == a[!t]) return 0;         if (!vm(a) && w == make_pair(n / 2 - 1 + t, m / 2 - 1)) return 0;       } else {         cin >> w.first >> w.second;         w.first--;         w.second--;       }       a[t] = w;       t = !t;     }   }


#include <bits/stdc++.h>   using namespace std;   class Node {    public:     vector<int> kids;     int pos[26];     int size;     int depth;     Node() {       this->size = 0;       memset(pos, 0, sizeof(pos));     }     void push(int kid, int next) {       this->kids.push_back(kid);       pos[next] = this->kids.size();     }   } N[300005];   int n, x, y;   char c;   int maxdepth;   int reduce[300005];   void init(int id) {     N[id].size = 1;     int l = N[id].kids.size();     for (int i = 0; i < l; i++) {       N[N[id].kids[i]].depth = N[id].depth + 1;       init(N[id].kids[i]);       maxdepth = max(maxdepth, N[N[id].kids[i]].depth);       N[id].size += N[N[id].kids[i]].size;     }   }   int dfsS(vector<int> &kids) {     if (kids.size() <= 1) return 0;     int ret = kids.size() - 1;     int l = kids.size();     int pos;     vector<int> tmp;     for (int i = 0; i < 26; i++) {       for (int j = 0; j < l; j++) {         pos = N[kids[j]].pos[i];         if (pos) {           tmp.push_back(N[kids[j]].kids[pos - 1]);         }       }       if (tmp.size() > 1) ret += dfsS(tmp);       tmp.clear();     }     return ret;   }   void dfsD(int id) {     int l = N[id].kids.size();     int ret = l ? 1 : 0;     ret += dfsS(N[id].kids);     reduce[N[id].depth + 1] += ret;     for (int i = 0; i < l; i++) {       dfsD(N[id].kids[i]);     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x >> y >> c;       N[x].push(y, c -  a );     }     N[1].depth = 0;     init(1);     dfsD(1);     int mm = 0;     int ans = 0;     for (int i = 1; i <= maxdepth; i++) {       if (reduce[i] > mm) {         ans = i;         mm = reduce[i];       }     }     cout << N[1].size - mm << endl;     cout << ans;     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   bitset<3> bs(int x) { return bitset<3>(x); }   const int MAXN = 1e5 + 10;   vector<int> vec[MAXN];   int mark[MAXN], tt;   int single(int x) { return (x & (x - 1)) == 0; }   void solve() {     ++tt;     int a[3];     vector<int> sec;     for (int i = 0; i < 3; i++) {       cin >> a[i];       for (int x : vec[a[i]]) {         if (mark[x] ^ tt) sec.push_back(x);         mark[x] = tt;       }     }     int cnt[8] = {};     for (int x : sec) {       int mask = 0;       for (int i = 0; i < 3; i++)         if (a[i] % x == 0) mask ^= 1 << i;       ++cnt[mask];     }     int ans = 0;     for (int i = 0; i < (1 << 3); i++) {       for (int j = i; j < (1 << 3); j++) {         for (int k = j; k < (1 << 3); k++) {           if ((i | j | k) != (1 << 3) - 1) continue;           if ((i == j && single(i)) || (j == k && single(j))) continue;           int cnt_single = single(i) + single(j) + single(k);           int memo_ans = ans;           if (cnt_single == 3) {             ans += cnt[i] * cnt[j] * cnt[k];           } else if (cnt_single == 2) {             ans += cnt[i] * cnt[j] * cnt[k];           } else if (cnt_single == 1) {             if (single(i)) {               if (j == k) {                 ans += cnt[i] * (cnt[j] + 1) * cnt[j] / 2;               } else {                 ans += cnt[i] * cnt[j] * cnt[k];               }             }             if (single(j)) {               if (i == k) {                 ans += cnt[j] * (cnt[i] + 1) * cnt[i] / 2;               } else {                 ans += cnt[i] * cnt[j] * cnt[k];               }             }             if (single(k)) {               if (i == j) {                 ans += cnt[k] * (cnt[i] + 1) * cnt[i] / 2;               } else {                 ans += cnt[i] * cnt[j] * cnt[k];               }             }           } else if (i == j && j == k) {             ans += (cnt[i] + 2) * (cnt[i] + 1) * cnt[i] / 6;           } else if (i == j) {             ans += cnt[k] * (cnt[i] + 1) * cnt[i] / 2;           } else if (j == k) {             ans += cnt[i] * (cnt[j] + 1) * cnt[j] / 2;           } else {             ans += cnt[i] * cnt[j] * cnt[k];           }           if (ans != memo_ans && 0) {             cerr << bs(i) <<     << bs(j) <<     << bs(k) <<   n ;             cerr <<  ans:   << memo_ans <<   n ;             cerr <<  now ans:   << ans <<   n n ;           }         }       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (int i = 1; i < MAXN; i++)       for (int j = i; j < MAXN; j += i) vec[j].push_back(i);     int te = 1;     cin >> te;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   const int MAXN = 1000002;   int n, l, t;   int a[MAXN << 1];   inline void init() {     scanf( %d%d%d , &n, &l, &t);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);   }   int main() {     init();     t <<= 1;     double res = 0.0;     int cycles = t / l;     t %= l;     res += (double)cycles * (double)n * (double)(n - 1) * 0.5;     for (int i = 0; i < n; ++i) a[i + n] = a[i] + l;     for (int i = 0; i < n; ++i) {       int ind = i + n;       int l = 1, r = n - 1;       int cur = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (a[ind] - a[ind - mid] <= t) {           cur = mid;           l = mid + 1;         } else {           r = mid - 1;         }       }       res += (double)cur * 0.25;       cur = 0;       l = 1, r = n - 1;       while (l <= r) {         int mid = (l + r) >> 1;         if (a[i + mid] - a[i] <= t) {           cur = mid;           l = mid + 1;         } else {           r = mid - 1;         }       }       res += (double)cur * 0.25;     }     res /= 2.0;     printf( %.15lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, a, b, c, n, t, f, d;     string s, v;     map<char, int> ma, sa;     vector<int> vv;     map<char, int>::iterator it, ki;     cin >> s;     f = 0;     c = 0;     for (j = 0; j < s.size(); j++) {       if ((s[j] >=  A  && s[j] <=  Z )) {         c++;       }     }     if (c == s.size()) {       for (j = 0; j < s.size(); j++) {         cout << char(s[j] + 32);       }       cout << endl;     } else if (s[0] >=  a  && s[0] <=  z  && c == s.size() - 1) {       cout << char(s[0] - 32);       for (j = 1; j < s.size(); j++) {         cout << char(s[j] + 32);       }       cout << endl;     } else {       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int alpha[26] = {0}, dig[105] = {0};   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return ((a * b) / gcd(a, b));   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void getArr(int a[], int n) {     for (int i = 0; i < n; i++) cin >> a[i];   }   void putArr(int a[], int n) {     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   void initAlpha(string s) {     int n = s.size();     for (int i = 0; i < n; i++) alpha[s[i] -  a ]++;   }   void initDigit(int a[], int n) {     for (int i = 0; i < n; i++) dig[a[i]]++;   }   bool isPalindrome(string input) {     if (input == string(input.rbegin(), input.rend())) return true;     return false;   }   int numLen(int n) {     int len = 0;     while (n != 0) {       n /= 10;       len++;     }     return len;   }   void robot() {     string s;     char n[50];     cin >> s;     int l = s.size(), k = 0;     bool flag = false;     for (int i = l - 1; i >= 0; i--) {       if (s[i] ==  0  && !flag)         continue;       else {         n[k++] = s[i];         flag = true;       }     }     n[k] =   0 ;     if (isPalindrome(n))       cout <<  YES n ;     else       cout <<  NO n ;   }   int main() { robot(); }


#include <bits/stdc++.h>   using namespace std;   int n, u, v, N;   vector<char> ans(1e5 + 5);   vector<int> sub(1e5 + 5);   vector<set<int> > adj(1e5 + 5);   void dfs(int u, int par) {     sub[u] = 1;     for (int v : adj[u]) {       if (v != par) {         dfs(v, u);         sub[u] += sub[v];       }     }   }   int centroid(int u, int par) {     for (int v : adj[u]) {       if (v != par && sub[v] > n / 2) {         return centroid(v, u);       }     }     return u;   }   void build(int u, int prev, int level) {     dfs(u, -1);     n = sub[u];     int cur = centroid(u, -1);     ans[cur] = char(level + 65);     for (int v : adj[cur]) {       adj[v].erase(cur);       build(v, cur, level + 1);     }   }   int main(void) {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n;     N = n;     for (int i = 1; i <= n - 1; ++i) {       cin >> u >> v;       adj[u].insert(v);       adj[v].insert(u);     }     build(1, -1, 0);     for (int i = 1; i <= N; ++i) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, mod = 1e9 + 7ll, cont, maxi = 1000000000000ll, cont2, val[400005],                ans, bestval = 1000000000000ll;   pair<long long, long long> dp[400005], num, ft[400005];   pair<int, int> v[400005];   map<int, int> ind;   vector<int> opz[400005], tmp;   void update(int pos, long long val, long long num) {     for (int i = pos; i < 400005; i += (i & (-i))) {       if (ft[i].first > val) {         ft[i] = {val, num};       } else {         if (ft[i].first == val) ft[i].second += num;         ft[i].second %= mod;       }     }   }   pair<long long, long long> query(int pos) {     long long sol = maxi, solnum = 0;     for (int i = pos; i > 0; i -= (i & (-i))) {       if (ft[i].first < sol) {         sol = ft[i].first;         solnum = ft[i].second;       } else {         if (ft[i].first == sol) {           solnum += ft[i].second;           solnum %= mod;         }       }     }     return {sol, solnum};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       tmp.push_back(v[i].first);       tmp.push_back(v[i].second);     }     sort(tmp.begin(), tmp.end());     cont = 1;     for (int i = 0; i < tmp.size(); i++) {       if (i == 0 || tmp[i] != tmp[i - 1]) {         ind[tmp[i]] = cont;         val[cont] = tmp[i];         cont++;       }     }     for (int i = 0; i < n; i++) {       opz[ind[v[i].first]].push_back(v[i].second);     }     for (int i = 0; i < 400005; i++) {       sort(opz[i].begin(), opz[i].end());       ft[i] = {maxi, 0};     }     update(1, maxi, 1);     for (int i = 1; i < cont; i++) {       cont2 = 0;       if (opz[i].size() == 0) continue;       dp[i].first = maxi;       dp[i].second = 1;       for (int j = 0; j < opz[i].size(); j++) {         cont2++;         if (j == opz[i].size() - 1 || opz[i][j] != opz[i][j + 1]) {           num = query(ind[opz[i][j]]);           num.first = num.first - (val[i] - opz[i][j]);           num.second *= cont2;           num.second %= mod;           if (dp[i].first > num.first) {             dp[i] = num;           } else {             if (dp[i].first == num.first) {               dp[i].second += num.second;               dp[i].second %= mod;             }           }           cont2 = 0;         }       }       update(i, dp[i].first, dp[i].second);     }     sort(v, v + n);     reverse(v, v + n);     for (int i = ind[v[0].first]; i > ind[v[0].second]; i--) {       if (bestval > (dp[i].first - (maxi - val[i]))) {         bestval = (dp[i].first - (maxi - val[i]));         ans = dp[i].second;       } else {         if (bestval == (dp[i].first - (maxi - val[i]))) ans += dp[i].second;         ans %= mod;       }     }     cout << max(ans, 1ll) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string arr[9];   int moves1[4] = {2, 2, -2, -2}, moves2[4] = {2, -2, 2, -2};   int grid[2][9][9];   bool visited[9][9];   int incrementer;   void canMeet(int row, int col, int nw) {     for (int i = 0; i < 4; ++i) {       if (row + moves1[i] >= 0 && row + moves1[i] < 8 && col + moves2[i] >= 0 &&           col + moves2[i] < 8 && !visited[row + moves1[i]][col + moves2[i]]) {         grid[incrementer][row + moves1[i]][col + moves2[i]] = nw + 1;         visited[row + moves1[i]][col + moves2[i]] = true;         canMeet(row + moves1[i], col + moves2[i], nw + 1);       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       memset(grid, 0, sizeof(grid));       for (int i = 0; i < 8; ++i) {         cin >> arr[i];       }       int x, y, x1, y1;       bool done = false;       for (int i = 0; i < 8; ++i) {         for (int j = 0; j < 8; ++j) {           if (arr[i][j] ==  K  && !done) {             x = i;             y = j;             done = true;           } else if (arr[i][j] ==  K  && done) {             x1 = i;             y1 = j;           }         }       }       incrementer = 1;       memset(visited, false, sizeof(visited));       visited[x][y] = true;       canMeet(x, y, 0);       incrementer = 1;       memset(visited, false, sizeof(visited));       visited[x1][y1] = true;       canMeet(x1, y1, 0);       grid[1][x1][y1] = 2;       grid[0][x][y] = 2;       done = false;       for (int i = 0; i < 8; ++i) {         for (int j = 0; j < 8; ++j) {           if ((arr[i][j] ==  .  || arr[i][j] ==  K ) && grid[0][i][j] != 0 &&               grid[1][i][j] != 0 && grid[0][i][j] % 2 == grid[1][i][j] % 2)             done = true;         }       }       if (done)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }