#include <bits/stdc++.h>   int pos = 1 << 17;   char buf[1 << 17];   inline char nextch() {     if (pos == 1 << 17) fread(buf, 1 << 17, 1, stdin), pos = 0;     return buf[pos++];   }   inline int read() {     char ch;     while (!isdigit(ch = nextch()))       ;     int x = ch -  0 ;     while (isdigit(ch = nextch())) x = 10 * x + ch -  0 ;     return x;   }   const int N = 1 << 17;   int ab[132000], de[132000], fr[132000], fib[132000];   inline int lgput(int a, int n) {     int r = 1;     while (n) {       if (n % 2) r = 1LL * r * a % 1000000007;       n /= 2;       a = 1LL * a * a % 1000000007;     }     return r;   }   void fwht(int *data, int dim) {     for (int len = 1; 2 * len <= dim; len <<= 1) {       for (int i = 0; i < dim; i += 2 * len) {         for (int j = 0; j < len; j++) {           int a = data[i + j];           int b = data[i + j + len];           data[i + j] = a + b;           if (data[i + j] >= 1000000007) data[i + j] -= 1000000007;           data[i + j + len] = a - b;           if (data[i + j + len] < 0) data[i + j + len] += 1000000007;         }       }     }   }   void to_transform(int dim, int *data) {     int len, i, j, u, v;     for (len = 1; 2 * len <= dim; len <<= 1) {       for (i = 0; i < dim; i += 2 * len) {         for (j = 0; j < len; j++) {           u = data[i + j];           v = data[i + len + j];           data[i + j] = v;           data[i + len + j] = u + v;           if (data[i + len + j] >= 1000000007) data[i + len + j] -= 1000000007;         }       }     }   }   void inv_transform(int dim, int *data) {     int len, i, j, u, v;     for (len = 1; 2 * len <= dim; len <<= 1) {       for (i = 0; i < dim; i += 2 * len) {         for (j = 0; j < len; j++) {           u = data[i + j];           v = data[i + len + j];           data[i + j] = v - u;           data[i + len + j] = u;           if (data[i + j] < 0) data[i + j] += 1000000007;         }       }     }   }   int main() {     int n = read();     for (int i = 0; i < n; i++) fr[read()]++;     for (int i = 0; i < N; i++) {       for (int j = i; j; j = (j - 1) & i)         ab[i] = (ab[i] + 1LL * fr[j] * fr[i ^ j]) % 1000000007;       ab[i] = (ab[i] + 1LL * fr[0] * fr[i]) % 1000000007;     }     for (int i = 0; i < N; i++) de[i] = fr[i];     fwht(de, N);     for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * de[i] % 1000000007;     fwht(de, N);     int inv = lgput(N, 1000000007 - 2);     for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * inv % 1000000007;     fib[1] = 1;     for (int i = 2; i < N; i++) {       fib[i] = fib[i - 1] + fib[i - 2];       if (fib[i] >= 1000000007) fib[i] -= 1000000007;     }     for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * fib[i] % 1000000007;     to_transform(N, ab);     for (int i = 0; i < N; i++) fr[i] = 1LL * fr[i] * fib[i] % 1000000007;     to_transform(N, fr);     for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * fr[i] % 1000000007;     inv_transform(N, ab);     to_transform(N, ab);     for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * fib[i] % 1000000007;     to_transform(N, de);     for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * de[i] % 1000000007;     inv_transform(N, ab);     int ans = 0;     for (int i = 1; i < N; i++)       if (i - (i & (-i)) == 0) ans = (ans + ab[i]) % 1000000007;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   inline int read() {     int f = 1, x = 0;     char ch = getchar();     while (!(ch >=  0  && ch <=  9 )) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2};   int dy[8] = {2, -2, 2, -2, 1, -1, 1, -1};   struct Point {     int x, y, c, fa;     friend bool operator==(Point a, Point b) {       return (a.x == b.x && a.y == b.y);     }   } w[2], b[2], other, list[4][1000 * 1000 + 1];   void readother() { std::cin >> other.x >> other.y; }   bool check(Point a, Point b) {     int x = abs(a.x - b.x), y = abs(a.y - b.y);     if (x <= 2 && y <= 2 && x + y == 3) {       printf( %d %d n , b.x, b.y);       return true;     }     return false;   }   int otherx, othery;   bool bk = false;   void printlist(int k, Point a) {     if (a.fa == -1 || bk == true) return;     if (a.fa != 1) printlist(k, list[k][a.fa]);     if (check(a, other) == true) bk = true;     if (bk == true) return;     printf( %d %d n , a.x, a.y);     readother();   }   int n, m, head, tail, v[4][1000 + 1][1000 + 1];   void closer(int k, Point st, Point ed) {     Point a, b;     head = tail = 1;     memset(v[k], 0, sizeof(v[k]));     v[k][st.x][st.y] = head;     list[k][head] = st, list[k][head].c = 0, list[k][head].fa = -1;     if (st == ed) return;     while (head <= tail) {       a = list[k][head];       for (int i = 0; i < 8; i++) {         b = a, b.x += dx[i], b.y += dy[i], b.c++;         if (b.x < 1 || b.y < 1 || b.x > n || b.y > m || v[k][b.x][b.y] != 0)           continue;         tail++;         v[k][b.x][b.y] = tail;         b.fa = head;         list[k][tail] = b;         if (b == ed) return;       }       head++;     }   }   void printlast(int k) {     Point a;     if (k == 0) {       a = b[0];       if (check(a, other) == false) {         a = b[0], a.x -= 1, a.y += 2;         printf( %d %d n , a.x, a.y), readother();       } else         return;       if (check(a, other) == false) {         a = b[0], a.x -= 3, a.y += 1;         printf( %d %d n , a.x, a.y), readother();       } else         return;       if (check(a, other) == false) {         a = b[0], a.x -= 1;         printf( %d %d n , a.x, a.y), readother();       } else         return;     } else {       a = w[0];       if (check(a, other) == false) {         a = w[0], a.x += 1, a.y += 2;         printf( %d %d n , a.x, a.y), readother();       } else         return;       if (check(a, other) == false) {         a = w[0], a.x += 3, a.y += 1;         printf( %d %d n , a.x, a.y), readother();       } else         return;       if (check(a, other) == false) {         a = w[0], a.x += 1;         printf( %d %d n , a.x, a.y), readother();       } else         return;     }   }   bool choose;   int main() {     n = read(), m = read(), w[1].x = read(), w[1].y = read(), b[1].x = read(),     b[1].y = read();     w[0].x = n / 2, w[0].y = m / 2, b[0].x = n / 2 + 1, b[0].y = m / 2;     closer(0, w[1], w[0]), closer(1, b[1], b[0]);     closer(2, w[1], b[0]);     closer(3, b[1], w[0]);     if ((w[1].x + w[1].y) % 2 != (b[1].x + b[1].y) % 2) {       if (list[0][v[0][w[0].x][w[0].y]].c <= list[1][v[1][b[0].x][b[0].y]].c)         printf( WHITE n ), other = b[1],                            printlist(0, list[0][v[0][w[0].x][w[0].y]]);       else if (list[2][v[2][b[0].x][b[0].y]].c >=                list[1][v[1][b[0].x][b[0].y]].c + 2)         printf( BLACK n ), readother(),             printlist(1, list[1][v[1][b[0].x][b[0].y]]);       else         printf( WHITE n ), other = b[1],                            printlist(2, list[2][v[2][b[0].x][b[0].y]]),                            printlast(0);     } else {       if (list[1][v[1][b[0].x][b[0].y]].c < list[0][v[0][w[0].x][w[0].y]].c)         printf( BLACK n ), readother(),             printlist(1, list[1][v[1][b[0].x][b[0].y]]);       else if (list[3][v[3][w[0].x][w[0].y]].c > list[0][v[0][w[0].x][w[0].y]].c)         printf( WHITE n ), other = b[1],                            printlist(0, list[0][v[0][w[0].x][w[0].y]]);       else         printf( BLACK n ), readother(),             printlist(3, list[3][v[3][w[0].x][w[0].y]]), printlast(1);     }   }


#include <bits/stdc++.h>   using namespace std;   int modi = 1e9 + 7;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     return !b ? a : gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       string str =   ;       if (x % 2 == 1) {         str +=  7 ;         x -= 3;       }       while (x > 1) {         str +=  1 ;         x -= 2;       }       cout << str << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 800010;   int t, n, m, k, b, u;   int ans = 0, total = 0, cnt = 0;   int a[maxx], sum[maxx];   struct no {     int num, l, r;     bool operator<(const no &X) const { return r < X.r; }   };   priority_queue<no> q;   struct node {     int num;     int l;     int r;   } s[maxx];   bool cmp(node a, node b) { return a.l < b.l; }   int main() {     scanf( %d%d , &n, &k);     for (register int i = 1; i <= n; i++) {       scanf( %d%d , &s[i].l, &s[i].r);       sum[s[i].l]++;       sum[s[i].r + 1]--;       s[i].num = i;     }     sort(s + 1, s + n + 1, cmp);     cnt = 1;     for (register int i = 1; i <= 200000; i++) {       while (cnt <= n && s[cnt].l <= i) {         q.push(no{s[cnt].num, s[cnt].l, s[cnt].r});         cnt++;       }       sum[i] += sum[i - 1];       while (sum[i] > k) {         a[++total] = q.top().num;         sum[i]--;         sum[q.top().r + 1]++;         q.pop();       }     }     sort(a + 1, a + total + 1);     printf( %d n , total);     for (register int i = 1; i <= total; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long a, long long b) { return (a < b) ? a : b; }   long long max(long long a, long long b) { return (a > b) ? a : b; }   int main() {     long long t, n, m, i, j, k = 0, p = 0;     cin >> n;     string s, q, r;     cin >> s;     p = s.size();     if (p % n != 0) {       for (i = 0; i < p / n + 1; i++) {         r +=  1 ;         for (j = 1; j < n; j++) r +=  0 ;       }       cout << r << endl;       return 0;     }     for (i = 0; i < p; i++)       if (s[i] !=  9 ) break;     if (i == p) {       for (i = 0; i < p + n; i++) {         if (i % n == 0)           r +=  1 ;         else           r +=  0 ;       }       cout << r << endl;       return 0;     }     for (i = n; i < p; i++) {       if (s[i] > s[i % n]) break;       if (s[i] < s[i % n]) break;     }     if (i == p || s[i] > s[i % n]) {       k = 1;       for (i = n - 1; i >= 0; i--) {         m = (s[i] - 48 + k);         k = m / 10;         s[i] = m % 10 + 48;         if (k == 0) break;       }       for (i = n; i < p; i++) s[i] = s[i % n];       cout << s << endl;       return 0;     }     for (i = n; i < p; i++) s[i] = s[i % n];     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   void Solve() {     long long T;     cin >> T;     while (T--) {       long long b, w;       cin >> b >> w;       if (b > w * 3 + 1 || w > b * 3 + 1) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       long long x = 2, y = 2;       while (b && w) {         cout << x <<     << y++ <<   n ;         cout << x <<     << y++ <<   n ;         b--, w--;       }       if (b) {         cout <<  2 1 n ;         b--;         x = 1, y = 2;         while (b) {           cout << x <<     << y <<   n ;           b--;           if (b) {             cout << x + 2 <<     << y <<   n ;             b--;           }           y += 2;         }       }       if (w) {         cout << x <<     << y <<   n ;         w--;         x = 1, y = 3;         while (w) {           cout << x <<     << y <<   n ;           w--;           if (w) {             cout << x + 2 <<     << y <<   n ;             w--;           }           y += 2;         }       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<string, string>> taken;   int main() {     int n;     scanf( %d , &n);     int ans = 0;     for (int i = 1; i <= n; ++i) {       string s, t;       cin >> s >> t;       bool flag = 1;       for (auto [x, y] : taken) {         if (x == s && y == t) {           flag = 0;           break;         }       }       if (flag) {         ans++;         taken.push_back({s, t});       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, s = -1, l = 1, r = 1e18;     cin >> m;     while (l <= r) {       long long as = 0, i;       long long mid = (l + r) / 2;       for (i = 2; i * i * i <= mid; i++) as += mid / (i * i * i);       if (as == m) s = mid;       if (as >= m)         r = mid - 1;       else         l = mid + 1;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;   };   point p[345678];   vector<point> important, ugly;   vector<int> ilist;   int n;   long long ans[345678];   long long distance(int i, int j) {     return llabs(important[i].x - important[j].x) +            llabs(important[i].y - important[j].y);   }   long long distance(point p, point q) {     return llabs(p.x - q.x) + llabs(p.y - q.y);   }   long long dp[15][15][15][15];   long long lovetourist(int i, int f, int l, int k) {     if (k == 0) return distance(f, l);     if (i == important.size()) return -1e17;     if (dp[i + 1][f + 1][l + 1][k + 1] != -1)       return dp[i + 1][f + 1][l + 1][k + 1];     long long ret = lovetourist(i + 1, f, l, k);     if (f == -1)       ret = max(ret, lovetourist(i + 1, i, i, k - 1));     else       ret = max(ret, distance(l, i) + lovetourist(i + 1, f, i, k - 1));     return dp[i + 1][f + 1][l + 1][k + 1] = ret;   }   long long respecttourist() {     long long res = -1e17;     for (int i = 0; i < ilist.size(); i++) {       for (int j = i + 1; j < ilist.size(); j++) {         for (int k = 1; k <= n; k++) {           if (k == ilist[i] || k == ilist[j]) continue;           res = max(res, distance(p[ilist[i]], p[ilist[j]]) +                              distance(p[ilist[i]], p[k]) +                              distance(p[ilist[j]], p[k]));         }       }     }     return res;   }   int main() {     cin >> n;     long long minx, maxx, miny, maxy, sum = 0;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;       if (i == 1) {         minx = p[i].x;         maxx = p[i].x;         miny = p[i].y;         maxy = p[i].y;       }       minx = min(minx, p[i].x);       maxx = max(maxx, p[i].x);       miny = min(miny, p[i].y);       maxy = max(maxy, p[i].y);     }     p[n + 1] = p[1];     for (int i = 1; i <= n; i++) {       sum += llabs(p[i].x - p[i + 1].x) + llabs(p[i].y - p[i + 1].y);       ilist.push_back(i);       if (p[i].x == minx)         important.push_back(p[i]);       else if (p[i].x == maxx)         important.push_back(p[i]);       else if (p[i].y == miny)         important.push_back(p[i]);       else if (p[i].y == maxy)         important.push_back(p[i]);       else {         ugly.push_back(p[i]);         ilist.pop_back();       }     }     memset(dp, -1, sizeof(dp));     long long res = lovetourist(0, -1, -1, important.size());     assert(2 <= important.size() && important.size() <= 8);     int k = n;     while (!ugly.empty()) {       ans[k--] = res;       ugly.pop_back();     }     for (int i = important.size(); i >= 3; i--)       ans[k--] = lovetourist(0, -1, -1, i);     ans[3] = max(ans[3], respecttourist());     for (int i = 3; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   struct str {     char s[110];   } p[110];   int n;   int ans[26], connect[26][26], v, e;   int toposort(int n, int mat[][26], int* ret) {     int d[26], i, j, k;     for (i = 0; i < n; i++)       for (d[i] = j = 0; j < n; d[i] += mat[j++][i])         ;     for (k = 0; k < n; ret[k++] = i) {       for (i = 0; d[i] && i < n; i++)         ;       if (i == n) return 0;       for (d[i] = -1, j = 0; j < n; j++) d[j] -= mat[i][j];     }     return 1;   }   int main() {     int i, j;     bool ok = true;     scanf( %d , &n);     memset(connect, 0, sizeof(connect));     for (i = 0; i < n; ++i) {       scanf( %s , p[i].s);       if (i > 0 && ok) {         for (j = 0; p[i].s[j] && p[i - 1].s[j]; ++j) {           if (p[i].s[j] != p[i - 1].s[j]) {             connect[p[i - 1].s[j] -  a ][p[i].s[j] -  a ] = 1;             break;           }         }         if (strlen(p[i].s) < strlen(p[i - 1].s) && j == strlen(p[i].s))           ok = false;       }     }     if (ok && toposort(26, connect, ans)) {       for (i = 0; i < 25; ++i) {         printf( %c , ans[i] +  a );       }       printf( %c n , ans[i] +  a );     } else {       puts( Impossible );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, k, a[110000], cnt, tmp[110000];   int edgenum = 1, vet[610000], val[610000], Next[610000], Head[110000];   double ang[610000];   bool vis[110000];   map<pair<int, int>, int> rnk;   vector<long long> sum[110000];   struct node {     int x, y;     node() {}     node(int _x, int _y) : x(_x), y(_y) {}   } p[110000];   node operator-(const node &a, const node &b) {     return node(a.x - b.x, a.y - b.y);   }   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   void addedge(int u, int v) {     vet[++edgenum] = v;     Next[edgenum] = Head[u];     Head[u] = edgenum;   }   int dfs(int u) {     vis[u] = true;     int flow = 1, tmp;     for (int e = Head[u]; e; e = Next[e])       if (!vis[vet[e]]) {         tmp = dfs(vet[e]);         val[e] += tmp;         val[e ^ 1] -= tmp;         flow += tmp;       }     return flow;   }   inline bool cmp(int a, int b) { return ang[a] < ang[b]; }   inline long long cross(node x, node y) {     return 1ll * x.x * y.y - 1ll * x.y * y.x;   }   int main() {     n = read();     m = read();     int u, v;     for (int i = 1; i <= m; i++) {       u = read();       v = read();       addedge(u, v);       addedge(v, u);     }     for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read();     int rt = 1;     for (int i = 2; i <= n; i++)       if (p[i].x < p[rt].x) rt = i;     dfs(rt);     for (int u = 1; u <= n; u++) {       cnt = 0;       for (int e = Head[u]; e; e = Next[e]) {         tmp[++cnt] = e;         v = vet[e];         ang[e] = atan2(p[v].y - p[u].y, p[v].x - p[u].x);       }       sort(tmp + 1, tmp + cnt + 1, cmp);       sum[u].push_back(0);       for (int i = 1; i <= cnt; i++) {         rnk[pair<int, int>(u, vet[tmp[i]])] = i;         sum[u].push_back(sum[u].back() + val[tmp[i]]);       }     }     q = read();     int l, r;     while (q--) {       k = read();       for (int i = 1; i <= k; i++) a[i] = read();       long long s = 0, ans = k;       for (int i = 2; i < k; i++)         s += cross(p[a[i]] - p[a[1]], p[a[i + 1]] - p[a[1]]);       if (s < 0) reverse(a + 1, a + k + 1);       a[0] = a[k];       a[k + 1] = a[1];       for (int i = 1; i <= k; i++) {         l = rnk[pair<int, int>(a[i], a[i + 1])];         r = rnk[pair<int, int>(a[i], a[i - 1])];         ans += sum[a[i]][r] - sum[a[i]][l - 1];         if (l > r) ans += sum[a[i]][(int)sum[a[i]].size() - 1];       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, memo[100001];   vector<long long> a;   long long x;   long long rek(int pos) {     long long &ret = memo[pos];     if (ret != -1) return ret;     ret = rek(pos - 1) + 20;     x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 50);     else       ret = min(ret, 50LL);     x = upper_bound(a.begin(), a.end(), a[pos] - 1440) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 120);     else       ret = min(ret, 120LL);     return ret;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     memset(memo, -1, sizeof(memo));     memo[0] = 20;     rek(n - 1);     for (int i = 0; i < n; i++)       if (!i)         cout << memo[i] << endl;       else         cout << memo[i] - memo[i - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> mp;     int n, k;     cin >> n >> k;     int c;     cin >> c;     for (int i = 1; i <= c; i++) {       int x;       cin >> x;       mp[x] = 1;     }     int ans = 0;     int t = 0;     for (int i = 1; i <= n; i++) {       t++;       if (mp[i] == 1) {         ans++;         t = 0;       } else if (t == k) {         ans++;         t = 0;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T, typename TT>   inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {     return os << t.first <<     << t.second;   }   template <typename T>   inline ostream &operator<<(ostream &os, const vector<T> &t) {     for (auto i : t) os << i <<    ;     return os;   }   template <typename T>   inline istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T1, typename T2>   inline istream &operator>>(istream &is, pair<T1, T2> &t) {     is >> t.first >> t.second;     return is;   }   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> v(n);     cin >> v;     int mn = *min_element(v.begin(), v.end()),         c = n - count(v.begin(), v.end(), mn);     if (c >= n / 2)       cout <<  Alice  <<   n ;     else       cout <<  Bob  <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool mat[3001][3001];   vector<int> v[3010];   int main() {     int n, m, a, b, result = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) mat[i][j] = false;     for (int i = 0; i < m; i++) {       cin >> a >> b;       v[a].push_back(b);       mat[a][b] = true;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) {           int r = 0;           for (int k = 0; k < v[i].size(); k++) {             if (mat[v[i][k]][j] == true) r++;           }           result += (r * (r - 1)) / 2;         }       }     }     cout << result;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double P[1000];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lf , P + i);     }     sort(P, P + n);     reverse(P, P + n);     double x1 = 0;     double x2 = 1;     double res = 0;     for (int i = 0; i < n; i++) {       double s = (1 - P[i]);       if (s == 0) s = 1;       if (res == 1) break;       x1 += P[i] / s;       x2 *= s;       res = max(res, x1 * x2);     }     printf( %.12lf n , res);     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int size = 0;     scanf( %ld , &size);     char fmt[size + 1];     fmt[size] =   0 ;     scanf( %s , fmt);     int width = 0;     int maxHeight = 1;     int ithX[size];     int depth[size];     int currentDepth = 0;     char ch =   0 ;     for (size_t ith = 0; ith < size; ith += 1) {       char thisCh = fmt[ith];       width += 1;       if (thisCh ==  [ ) {         currentDepth += 1;         depth[ith] = currentDepth;       } else {         depth[ith] = currentDepth;         currentDepth -= 1;         if (ch ==  [ ) width += 3;       }       ithX[ith] = width;       size_t thisHeight = (currentDepth << 1) + 1;       if (maxHeight < thisHeight) maxHeight = thisHeight;       ch = thisCh;     }     size_t outLen = width * maxHeight;     char buffer[outLen + 1];     buffer[outLen] =   0 ;     memset(buffer,    , outLen);     for (size_t ith = 0; ith < size; ith += 1) {       size_t x = ithX[ith] - 1;       size_t d = depth[ith];       int lineEnd = maxHeight - d;       int lineStart = maxHeight - (lineEnd + 1);       int indexStart = x + lineStart * width;       int indexEnd = x + lineEnd * width;       if (fmt[ith] ==  [ )         buffer[indexStart + 1] = buffer[indexEnd + 1] =  - ;       else         buffer[indexEnd - 1] = buffer[indexStart - 1] =  - ;       buffer[indexStart] = buffer[indexEnd] =  + ;       for (size_t y = lineStart + 1; y < lineEnd; y += 1)         buffer[x + y * width] =  | ;     }     for (size_t line = 0; line < maxHeight; line += 1) {       fwrite(buffer + line * width, sizeof(char), width, stdout);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len;   bool flag;   int p, a[25][105], b[25][105], c[25][105];   char s[1000];   int dp[1005];   int main() {     scanf( %d%d%d , &n, &m, &p);     for (i = 1; i <= n; i++) {       scanf( %s , s);       for (j = 1; j <= m; j++) {         scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]);       }     }     int v;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         memset(dp, 0, sizeof(dp));         for (x = 1; x <= m; x++) {           for (v = p; v >= 0; v--) {             for (num = 0; num <= c[i][x]; num++) {               int pro = b[j][x] - a[i][x];               if (v - num >= 0 && dp[v] < dp[v - num] + pro * num) {                 dp[v] = dp[v - num] + pro * num;                 ans = max(ans, dp[v]);               } else if (v - num < 0)                 break;             }           }         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long LLMAX = 9223372036854775807LL;   const int MOD = 1000000007;   const int maxn = 500001;   int n;   int a[maxn];   pair<int, int> p[maxn];   int pr[maxn], ne[maxn];   int main() {     scanf( %d , &(n));     for (int(i) = 0; (i) < (int)(n); ++(i)) scanf( %d , &(a[i]));     for (int i = 0; i < n; ++i) {       p[i] = make_pair((a[i]), (i));       pr[i] = i - 1;       ne[i] = i + 1;     }     sort(p, p + n);     long long ans = 0, l = 0, r = n - 1;     for (int i = 0; i < n - 2; ++i) {       int j = p[i].second;       if (j == l) {         ans += p[i].first;         l = ne[j];       } else if (j == r) {         ans += p[i].first;         r = pr[r];       } else {         ans += min(a[pr[j]], a[ne[j]]);         pr[ne[j]] = pr[j];         ne[pr[j]] = ne[j];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     string a, b, c;     vector<vector<long long> > arr(3, vector<long long>((26 * 2) + 1, 0));     cin >> n;     cin >> a >> b >> c;     long long len = a.length();     for (long long i = 0; i < len; i++) {       char cur = a[i];       if (cur >=  a ) {         arr[0][cur - 97]++;       } else {         arr[0][cur - 65 + 26]++;       }     }     for (long long i = 0; i < len; i++) {       char cur = b[i];       if (cur >=  a ) {         arr[1][cur - 97]++;       } else {         arr[1][cur - 65 + 26]++;       }     }     for (long long i = 0; i < len; i++) {       char cur = c[i];       if (cur >=  a ) {         arr[2][cur - 97]++;       } else {         arr[2][cur - 65 + 26]++;       }     }     for (long long i = 0; i < 52; i++) {       if (arr[0][i] > arr[0][52]) {         arr[0][52] = arr[0][i];       }       if (arr[1][i] > arr[1][52]) {         arr[1][52] = arr[1][i];       }       if (arr[2][i] > arr[2][52]) {         arr[2][52] = arr[2][i];       }     }     long long x = arr[0][52], y = arr[1][52], z = arr[2][52];     if (n == 1 && x == len) {       x = len - 1;     } else if (x + n >= len) {       x = len;     } else {       x += n;     }     if (n == 1 && y == len) {       y = len - 1;     } else if (y + n >= len) {       y = len;     } else {       y += n;     }     if (n == 1 && z == len) {       z = len - 1;     } else if (z + n >= len) {       z = len;     } else {       z += n;     }     if (x > y && x > z) {       cout <<  Kuro n ;     } else if (y > x && y > z) {       cout <<  Shiro n ;     } else if (z > x && z > y) {       cout <<  Katie n ;     } else {       cout <<  Draw n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   const int inf = ~0U >> 1;   template <class U, class V>   struct MCMF {     static const int N = 8000, M = 7001010;     int h[N], ing[N], pre[N], to[M], ne[M], e, s, t, n;     U cap[M];     V dis[N], cost[M];     void ini(int _n = N) {       fill(h, h + (n = _n), -1);       e = 0;     }     void liu(int u, int v, U c, V w) {       to[e] = v;       ne[e] = h[u];       cap[e] = c;       cost[e] = w;       h[u] = e++;     }     void link(int u, int v, U c, V w) {       liu(u, v, c, w);       liu(v, u, 0, -w);     }     bool spfa() {       queue<int> Q;       fill(dis, dis + n, -inf);       Q.push(s), ing[s] = 1, dis[s] = 0;       while (!Q.empty()) {         int c = Q.front();         Q.pop();         ing[c] = 0;         for (int k = h[c]; ~k; k = ne[k])           if (cap[k] > 0) {             int v = to[k];             if (dis[c] + cost[k] > dis[v]) {               dis[v] = dis[c] + cost[k];               pre[v] = k;               if (!ing[v]) Q.push(v), ing[v] = 1;             }           }       }       return dis[t] != -inf;     }     U flow;     V mincost;     pair<U, V> run(int _s, int _t) {       s = _s, t = _t;       flow = mincost = 0;       while (spfa()) {         U pl = inf;         int p, k;         for (p = t; p != s; p = to[k ^ 1]) pl = min(pl, cap[k = pre[p]]);         for (p = t; p != s; p = to[k ^ 1])           cap[k = pre[p]] -= pl, cap[k ^ 1] += pl;         mincost += pl * dis[t];         flow += pl;       }       return make_pair(flow, mincost);     }   };   MCMF<int, int> flow;   int n, a[N];   int can[3005][3005];   int main() {     scanf( %d , &n);     for (int i = (1); i < (n + 1); i++) {       scanf( %d , &a[i]);     }     flow.ini(n * 2 + 100);     int t = flow.n - 1, s = t - 1, ss = s - 1;     ;     for (int i = (1); i < (n + 1); i++) {       flow.link(i, i + n, 1, 1);       flow.link(i, i + n, inf, 0);       int f1 = 1, f2 = 1, f3 = 1;       for (int j = (i + 1); j < (n + 1); j++) {         if (a[j] - a[i] == 1 && f1) {           f1 = 0;           flow.link(i + n, j, 1, 0);         }         if (a[i] - a[j] == 1 && f2) {           f2 = 0;           flow.link(i + n, j, 1, 0);         }         if (a[i] - a[j] == 0 && f3) {           f3 = 0;           flow.link(i + n, j, 1, 0);         }       }     }     for (int j = (0); j < (7); j++) {       int pre = 0;       for (int i = (1); i < (n + 1); i++) {         if (a[i] % 7 == j) {           if (pre) flow.link(pre + n, i, 1, 0);           pre = i;         }       }     }     for (int i = (1); i < (n + 1); i++)       flow.link(ss, i, 1, 0), flow.link(i + n, t, 1, 0);     flow.link(s, ss, 4, 0);     int ans = flow.run(s, t).second;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << setprecision(12);     int l;     cin >> l;     string s;     cin >> s;     size_t t = 0;     for (auto c : s) t += (c ==  1 );     if (t * 2 == s.length()) {       cout << 2 << endl;       cout << s[0] <<     << s.substr(1) << endl;     } else {       cout << 1 << endl;       cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline void cmin(int &x, int y) {     if (y < x) x = y;   }   inline void cmax(int &x, int y) {     if (y > x) x = y;   }   const int N = 1000006;   int a[12][N], sum[N], tmp[N], bcj[N], f[N][22], id[N], n, m, T, i, j, l, r;   int inline read() {     char ch = getchar();     int z = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       z = z * 10 + ch -  0 ;       ch = getchar();     }     return z * f;   }   int find(int x) {     if (bcj[x] == x) return x;     return bcj[x] = find(bcj[x]);   }   int calc(int f[], int g[], int j, int k) {     int i, ans = 0;     for ((i) = (1); (i) <= (n + n); ++i) bcj[i] = f[i];     for ((i) = (1); (i) <= (n + n); ++i) bcj[n + n + i] = n + n + g[i];     for ((i) = (1); (i) <= (n); ++i)       if (a[i][j] == a[i][k] && find(n + i) != find(n + n + i)) {         ++ans;         bcj[find(n + n + i)] = find(n + i);       }     return ans;   }   void build(int l, int r, int x) {     int mid = l + r >> 1, i;     if (l == r) {       int ans = 1;       for ((i) = (2); (i) <= (n); ++i)         if (a[i][l] != a[i - 1][l]) ++ans;       sum[x] = ans;       for ((i) = (1); (i) <= (n); ++i)         if (i == 1 || a[i][l] != a[i - 1][l])           f[x][i] = i;         else           f[x][i] = f[x][i - 1];       for ((i) = (1); (i) <= (n); ++i) f[x][n + i] = f[x][i];     } else {       build(l, mid, x * 2);       build(mid + 1, r, x * 2 + 1);       sum[x] = sum[x * 2] + sum[x * 2 + 1];       sum[x] -= calc(f[x * 2], f[x * 2 + 1], mid, mid + 1);       for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;       for ((i) = (1); (i) <= (n); ++i) {         int z = bcj[i];         if (!id[z]) id[z] = i;         f[x][i] = id[z];       }       for ((i) = (n + 1); (i) <= (n + n); ++i) {         int z = bcj[n * 2 + i];         if (!id[z]) id[z] = i;         f[x][i] = id[z];       }     }   }   int query(int l, int r, int x, int s, int t, int g[]) {     int i;     if (s <= l && r <= t) {       for ((i) = (1); (i) <= (n + n); ++i) g[i] = f[x][i];       return sum[x];     }     int mid = l + r >> 1;     if (t <= mid) return query(l, mid, x * 2, s, t, g);     if (s > mid) return query(mid + 1, r, x * 2 + 1, s, t, g);     int h1[22], h2[22];     int ans =         query(l, mid, x * 2, s, t, h1) + query(mid + 1, r, x * 2 + 1, s, t, h2);     ans -= calc(h1, h2, mid, mid + 1);     for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;     for ((i) = (1); (i) <= (n); ++i) {       int z = bcj[i];       if (!id[z]) id[z] = i;       g[i] = id[z];     }     for ((i) = (n + 1); (i) <= (n + n); ++i) {       int z = bcj[n * 2 + i];       if (!id[z]) id[z] = i;       g[i] = id[z];     }     return ans;   }   int main() {     n = read();     m = read();     T = read();     for ((i) = (1); (i) <= (n); ++i)       for ((j) = (1); (j) <= (m); ++j) a[i][j] = read();     build(1, m, 1);     while (T--) {       l = read();       r = read();       printf( %d n , query(1, m, 1, l, r, tmp));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int j, n, m, po, a, b, no, flag, cnt = 0, t, cnt2, ar[200001], x, y,                                                i, co[200001], sum = 0, k,                                                ans = INT_MIN, sum1 = 0;     string str[1000], ptr, tr, rtr, rt;     vector<long long int> v1, v2;     set<string> s;     set<long long int> si;     queue<long long int> qui;     queue<string> qus;     set<string>::iterator it;     cin >> t;     while (t--) {       cin >> n >> a >> b;       string sr;       for (i = 0; i < a; i++) {         sr[i] = char( a  + i % b);       }       for (i = 0; i < n; i++) {         cout << sr[i % a];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long cnt[5], ans1, ans2;   int main() {     int n, a[200010];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         cnt[1]++;       else         cnt[0]++;     }     for (int i = 0; i < n; i++) {       if (a[i] == 0)         cnt[0]--;       else {         ans1 += cnt[0];       }     }     cout << ans1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[200], t[200];   int cnt[200], cnt2[200];   int check(int p, char t[]) {     int i;     for (i = 0; i < 26; i++) {       cnt2[i] = 0;     }     for (i = p; i < p + n; i++) {       cnt2[t[i] -  a ]++;     }     for (i = 0; i < 26; i++) {       if (cnt[i] != cnt2[i]) return 0;     }     return 1;   }   int main() {     int T, flag, i;     scanf( %d , &T);     while (T--) {       flag = 0;       scanf( %s%s , s, t);       n = strlen(s);       m = strlen(t);       for (i = 0; i < 26; i++) {         cnt[i] = 0;       }       for (i = 0; i < n; i++) {         cnt[s[i] -  a ]++;       }       for (i = 0; i <= m - n; i++) {         if (check(i, t)) {           flag = 1;           break;         }       }       if (flag) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct node {     long long k[51][51];   } a, ans;   long long t, n, m, q, op, x, y, z, s = 1, mp[26][26];   inline long long read() {     long long sum = 0, x = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       sum = sum * 10 + ch -  0 ;       ch = getchar();     }     return sum * x;   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   inline node mul(node a, node b) {     node c;     memset(c.k, 0, sizeof(c.k));     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j)         for (register long long p = 1; p <= t; p++)           c.k[i][j] = (c.k[i][j] + a.k[i][p] * b.k[p][j]) % mod;     return c;   }   inline void power(long long b) {     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ans = mul(a, ans);   }   inline void build() {     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j) {         long long aa = ((i - 1) / m) + 1, bb = (i - 1) % m + 1,                   A = ((j - 1) / m) + 1, B = (j - 1) % m + 1;         if (mp[aa][bb] == 0 && mp[A][B] == 0 && abs(A - aa) + abs(B - bb) <= 1)           a.k[i][j] = 1;         else           a.k[i][j] = 0;       }   }   signed main() {     n = read();     m = read();     q = read();     t = n * m;     ans.k[1][1] = 1;     while (q--) {       build();       op = read();       x = read();       y = read();       z = read();       power(z - s);       s = z;       if (op == 2 || op == 3) ans.k[(x - 1) * m + y][1] = 0;       if (op == 2) mp[x][y] = 1;       if (op == 3) mp[x][y] = 0;       if (op == 1) {         write(ans.k[(x - 1) * m + y][1]);         putchar(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long exp) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base);       base = (base * base);       exp /= 2;     }     return res;   }   long long mod(long long a, long long b) { return (a % b + b) % b; }   long long powerm(long long base, long long exp, long long mod) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return ans;   }   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     t = 1;     while (t--) {       string s;       cin >> s;       cout << s;       for (long long i = s.size() - 1; i >= 0; i--) cout << s[i];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x != 0) s.insert(x);     }     cout << s.size();   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 1024 * 1024;   int n;   int k;   int v[MXN];   int c[MXN];   int p[MXN];   pair<int, int> vstk[MXN];   pair<int, int> cstk[MXN];   int vn, cn;   static pair<int, int> getxy(int iv) {     int p1 = vstk[iv].first;     auto cx =         lower_bound(cstk, cstk + cn, p1,                     [](const pair<int, int>& a, int b) { return a.first > b; });     return {vstk[iv].second, cx->second};   }   static void calcP() {     vn = 0;     cn = 0;     for (int i = n - 1; i >= 0; i--) {       while (vn > 0 && vstk[vn - 1].second <= v[i]) vn--;       vstk[vn++] = pair<int, int>(i, v[i]);       while (cn > 0 && cstk[cn - 1].second >= c[i]) cn--;       cstk[cn++] = pair<int, int>(i, c[i]);       int l = 0, r = vn - 1;       while (l < r) {         int m = (l + r) / 2;         pair<int, int> xy = getxy(m);         if (xy.first < xy.second)           r = m;         else           l = m + 1;       }       pair<int, int> a1 = getxy(l);       int tans = min(a1.first, a1.second);       if (l > 0) {         a1 = getxy(l - 1);         tans = max(tans, min(a1.first, a1.second));       }       p[i] = tans;     }   }   static double solve() {     for (int i = 0; i < n; i++) v[i] *= 100;     calcP();     sort(p, p + n);     double prb = double(k) / n;     double ans = p[0] * prb;     for (int i = 1; i < n && n - k - i + 1 >= 0; i++) {       prb *= n - k - i + 1;       prb /= (n - i);       ans += p[i] * prb;     }     return ans;   }   int main() {     while (scanf( %d %d , &n, &k) == 2) {       for (int i = 0; i < n; i++) scanf( %d , v + i);       for (int i = 0; i < n; i++) scanf( %d , c + i);       double ans = solve();       printf( %.7f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int *input = new int[n];     for (int i = 0; i < n; i++) cin >> input[i];     sort(input, input + n);     int over = input[n - 1] + 1;     int ans = 1;     for (int i = n - 2; i >= 0; i--) {       if (input[i] + 1 < over) {         over = input[i] + 1;         ans++;       } else if (input[i] < over) {         over = input[i];         ans++;       } else if (input[i] - 1 > 0 && input[i] - 1 < over) {         over = input[i] - 1;         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<string, string>, int> m, m1;   vector<pair<string, string> > ans;   int main() {     string s1, s2;     int n, t, i, d, j;     scanf( %d%d , &n, &d);     for (i = 1; i <= n; i++) {       cin >> s1 >> s2 >> t;       for (j = 0; j < ans.size(); j++)         if ((ans[j].first == s1 && ans[j].second == s2) ||             (ans[j].first == s2 && ans[j].second == s1))           break;       if (j != int(ans.size())) continue;       t++;       if ((m[make_pair(s2, s1)] != 0 && t - m[make_pair(s2, s1)] <= d &&            t - m[make_pair(s2, s1)] > 0) ||           (m1[make_pair(s2, s1)] != 0 && t - m1[make_pair(s2, s1)] <= d &&            t - m1[make_pair(s2, s1)] > 0))         ans.push_back(make_pair(s1, s2));       if (m[make_pair(s1, s2)] != t) m1[make_pair(s1, s2)] = m[make_pair(s1, s2)];       m[make_pair(s1, s2)] = t;     }     printf( %d , int(ans.size()));     for (i = 0; i < ans.size(); i++)       cout << endl << ans[i].first <<     << ans[i].second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   void bugp(const pair<T, V> &x) {     cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl;   }   template <typename T, typename U, typename V>   void bugpp(const pair<T, pair<U, V> > &x) {     cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second          <<  }}  << endl;   }   template <typename T>   bool maximize(T &x, const T &y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   template <typename T>   bool minimize(T &x, const T &y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   const int N = 2002;   int n, C[N], A[N], subsz[N];   bool chk[N], answer = 1;   vector<int> child[N];   int getNext(int idx) {     int ans = -1;     for (int i = 1, _n = (n); i <= _n; ++i) {       if (!chk[i]) --idx;       if (!idx) {         ans = i;         break;       }     }     return ans;   }   void DFS(int u) {     subsz[u] = 1;     A[u] = getNext(C[u] + 1);     if (A[u] == -1)       answer = 0;     else       chk[A[u]] = 1;     for (int &v : child[u]) {       DFS(v);       subsz[u] += subsz[v];     }     if (C[u] >= subsz[u]) answer = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int root;     for (int i = 1, _n = (n); i <= _n; ++i) {       int p;       cin >> p >> C[i];       if (p)         child[p].push_back(i);       else         root = i;     }     DFS(root);     if (!answer)       cout <<  NO ;     else {       cout <<  YES n ;       for (int i = 1, _n = (n); i <= _n; ++i) cout << A[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <class I>   inline void fr(I &num) {     num = 0;     register char c = nc();     register int p = 1;     while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = nc() : c = nc();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = nc();     num *= p;   }   template <class I>   inline I Max(I p, I q) {     return p > q ? p : q;   }   template <class I>   inline I Min(I p, I q) {     return p < q ? p : q;   }   template <class I>   inline I A(I x) {     return x < 0 ? -x : x;   }   template <class I>   inline void sp(I &p, I &q) {     I x = p;     p = q, q = x;   }   template <class I>   inline void ckMax(I &p, I q) {     p = (p > q ? p : q);   }   template <class I>   inline void ckMin(I &p, I q) {     p = (p < q ? p : q);   }   };  // namespace io   using io ::A;   using io ::ckMax;   using io ::ckMin;   using io ::fr;   using io ::Max;   using io ::Min;   using io ::nc;   using io ::sp;   const int N = 1000005;   map<pair<int, int>, int> mp;   int n, k, cn, d;   inline void gcd(const int a, const int b) {     return !b ? d = a, void() : gcd(b, a % b);   }   inline double dis(const int x, const int y) {     return sqrt(1.0 * x * x + 1.0 * y * y);   }   struct ky {     int x, y;     double ds;     bool operator<(const ky &p) const { return ds < p.ds; }   };   vector<ky> vec[N];   vector<double> o;   int main() {     scanf( %d%d , &n, &k);     const int kk = k >> 1;     register double ans = 0;     for (register int i = 1, x, y; i <= n; ++i) {       scanf( %d%d , &x, &y);       if ((!x) && (!y)) {         vec[++cn].push_back((ky){x, y, 0});         continue;       }       gcd(A(x), A(y));       pair<int, int> p = make_pair(x / d, y / d);       if (!mp[p]) mp[p] = ++cn;       vec[mp[p]].push_back((ky){x, y, dis(x, y)});     }     for (register int j = 1, i; j <= cn; ++j) {       const int sz = vec[j].size();       register int mn = Min(kk, sz);       std::sort(vec[j].begin(), vec[j].end());       for (i = 1; i <= mn; ++i)         o.push_back(vec[j][sz - i].ds * ((k - i) - (i - 1)));       double s = 0;       mn = Min(k, sz);       for (i = kk + 1; i <= mn; ++i)         o.push_back(vec[j][i - kk - 1].ds * ((k - kk - 1) - kk) - 2.0 * s),             s += vec[j][i - kk - 1].ds;     }     std::sort(o.begin(), o.end());     for (register int i = o.size() - 1; (~i) && k; --i) ans += o[i], --k;     printf( %.9lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<int> val[100010];   int x[100010];   int td[100010 * 4], ti[100010 * 4];   int queryd(int node, int lo, int hi, int l, int r) {     if (l > hi or r < lo) return 0;     if (lo >= l and hi <= r) return td[node];     int md = (lo + hi) >> 1;     int p1 = queryd(node << 1, lo, md, l, r);     int p2 = queryd(node << 1 | 1, md + 1, hi, l, r);     return max(p1, p2);   }   void updated(int node, int lo, int hi, int idx, int val) {     if (lo == hi) {       td[node] = max(td[node], val);       return;     }     int md = (lo + hi) >> 1;     if (idx <= md)       updated(node << 1, lo, md, idx, val);     else       updated(node << 1 | 1, md + 1, hi, idx, val);     td[node] = max(td[node << 1], td[node << 1 | 1]);   }   int queryi(int node, int lo, int hi, int l, int r) {     if (l > hi or r < lo) return 0;     if (lo >= l and hi <= r) return ti[node];     int md = (lo + hi) >> 1;     int p1 = queryi(node << 1, lo, md, l, r);     int p2 = queryi(node << 1 | 1, md + 1, hi, l, r);     return max(p1, p2);   }   void updatei(int node, int lo, int hi, int idx, int val) {     if (lo == hi) {       ti[node] = max(ti[node], val);       return;     }     int md = (lo + hi) >> 1;     if (idx <= md)       updatei(node << 1, lo, md, idx, val);     else       updatei(node << 1 | 1, md + 1, hi, idx, val);     ti[node] = max(ti[node << 1], ti[node << 1 | 1]);   }   int ai[100010], ad[100010], md[100010];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0, l, r; i < n; ++i) {       cin >> l >> r;       x[l]++;       x[r + 1]--;     }     for (int i = 1; i <= m; ++i) {       x[i] += x[i - 1];     }     for (int i = 1; i <= m; ++i) {       auto xz = queryi(1, 0, n, 0, x[i]);       ai[i] = xz + 1;       updatei(1, 0, n, x[i], xz + 1);     }     for (int i = m; i > 0; --i) {       auto xz = queryd(1, 0, n, 0, x[i]);       ad[i] = xz + 1;       updated(1, 0, n, x[i], xz + 1);     }     md[m] = ad[m];     int ans = 0;     for (int i = m - 1; i > 0; --i) {       md[i] = max(ad[i], md[i + 1]);     }     for (int i = 1; i < m; ++i) {       ans = max(ans, ai[i] + md[i + 1]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long Inf = 1e18;   const int N = 1010;   const int mod = 0;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   template <typename T>   bool chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   };   template <typename T>   bool chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   };   int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }   void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }   void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ;   }   template <typename T>   string to_string(T v) {     int fst = 1;     string ret =  { ;     for (auto x : v) {       if (!fst) ret +=  , ;       fst = 0, ret += to_string(x);     }     ret +=  } ;     return ret;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << to_string(H);     dbg_out(T...);   }   int n, m, c, a[N], h, t;   void print(int x) {     cout << x <<   n ;     fflush(stdout);   }   int place(int x) {     if (x <= c / 2) {       if (x >= a[h])         return ++h;       else {         int p = 1;         while (a[p] <= x) ++p;         return p;       }     } else {       if (x <= a[t])         return --t;       else {         int p = n;         while (a[p] >= x) --p;         return p;       }     }   }   int main() {     n = gi(), m = gi(), c = gi();     h = 0, t = n + 1;     a[t] = c + 1;     for (int i = 1; i <= m; i++) {       int x = gi(), pos = place(x);       print(pos);       a[pos] = x;       if (h + 1 == t) return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[60];   int n;   long long f[60][10];   int main() {     gets(s + 1);     n = strlen(s + 1);     for (int j = 0; j < 10; ++j) f[1][j] = 1;     for (int i = 1; i < n; ++i)       for (int j = 0; j < 10; ++j) {         int sum = j + s[i + 1] - 48;         if (sum & 1) {           f[i + 1][sum - 1 >> 1] += f[i][j];           f[i + 1][sum + 1 >> 1] += f[i][j];         } else           f[i + 1][sum >> 1] += f[i][j];       }     long long ans = 0;     for (int j = 0; j < 10; ++j) ans += f[n][j];     bool flag = true;     for (int i = 2; i <= n; ++i) {       int sum = s[i - 1] + s[i] - 48 * 2;       if (sum & 1) {         if ((sum - 1 >> 1) != s[i] - 48 && (sum + 1 >> 1) != s[i] - 48)           flag = false;       } else if ((sum >> 1) != s[i] - 48)         flag = false;     }     if (flag) --ans;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a[n];     long long m = 1e9;     long long sum = 0;     for (long long i = 0; i < n; ++i) cin >> a[i], m = min(m, a[i]), sum += a[i];     for (long long i = 0; i < n; ++i) {       if ((a[i] - m) % k != 0) {         cout << -1;         return 0;       }     }     long long l = sum - m * n;     cout << l / k;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   int ansa, ansb, ansc;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int main() {     a = read();     b = read();     c = read();     d = read();     if (c * 2 < d || d * 2 < c || a <= d || b <= d) {       printf( -1 );       return 0;     }     printf( %d n%d n%d , a * 2, b * 2, min(c * 2, d * 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<int> a;     int n, t;     cin >> n;     while (n--) {       cin >> t;       a.insert(t);     }     cout << ((a.count(0) == 1) ? a.size() - 1 : a.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct myhash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long modpow(long long base, long long exp, long long modulus) {     base %= modulus;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % modulus;       base = (base * base) % modulus;       exp >>= 1;     }     return result;   }   long long modinv(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   int main() {     long long n;     cin >> n;     vector<string> s(n);     for (long long(i) = (0); i < (n); ++(i)) cin >> s[i];     map<long long, unordered_map<char, vector<string>>> m;     vector<pair<string, string>> secondwords(0);     vector<vector<string>> firstwords(0);     unordered_map<long long, long long> fq;     vector<long long> poss(0);     for (long long(i) = (0); i < (n); ++(i)) {       char lastvowel;       long long numvowels = 0;       for (long long(j) = (0); j < (s[i].length()); ++(j)) {         switch (s[i][j]) {           case  a :           case  e :           case  i :           case  o :           case  u :             numvowels++;             lastvowel = s[i][j];             break;         }       }       if (!fq[numvowels]) {         fq[numvowels] = 1;         poss.push_back(numvowels);       }       m[numvowels][lastvowel].push_back(s[i]);     }     vector<char> st{ a ,  e ,  i ,  o ,  u };     for (long long(i) = (0); i < (poss.size()); ++(i)) {       vector<string> ones(0);       for (long long(j) = (0); j < (st.size()); ++(j)) {         for (long long(k) = (0); k < (m[poss[i]][st[j]].size() / 2); ++(k)) {           secondwords.push_back(               {m[poss[i]][st[j]][k * 2], m[poss[i]][st[j]][k * 2 + 1]});         }         if (m[poss[i]][st[j]].size() % 2 == 1) {           ones.push_back(m[poss[i]][st[j]][m[poss[i]][st[j]].size() - 1]);         }       }       firstwords.push_back(ones);     }     long long np = secondwords.size();     vector<pair<string, string>> fans(0);     for (long long(i) = (0); i < (firstwords.size()); ++(i)) {       for (long long(j) = (0); j < (firstwords[i].size() / 2); ++(j)) {         fans.push_back({firstwords[i][j * 2], firstwords[i][j * 2 + 1]});       }     }     if (fans.size() >= secondwords.size()) {       cout << secondwords.size() <<   n ;       for (long long(i) = (0); i < (secondwords.size()); ++(i)) {         cout << fans[i].first <<     << secondwords[i].first <<   n ;         cout << fans[i].second <<     << secondwords[i].second <<   n ;       }     } else {       long long sc = secondwords.size(), fw = fans.size();       while (sc > fw) {         sc--;         fw++;         fans.push_back(secondwords[sc]);       }       cout << sc <<   n ;       for (long long(i) = (0); i < (sc); ++(i)) {         cout << fans[i].first <<     << secondwords[i].first <<   n ;         cout << fans[i].second <<     << secondwords[i].second <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = long double;   using pl = pair<ll, ll>;   using pi = pair<int, int>;   vector<pi> viz[100010];   pi p[100010];   double num[100010];   bool no;   set<int> val;   vector<int> in;   void dfs(int u) {     in.push_back(u);     for (auto x : viz[u]) {       int v = x.first, c = x.second;       if (p[v].first != 0) {         if (p[v].first != p[u].first) {           if ((p[v].second == c - p[u].second))             continue;           else             no = true;         }         if (p[v].first == p[u].first) {           val.insert((c - p[v].second - p[u].second) * p[v].first);         }       } else {         p[v].first = -p[u].first;         p[v].second = c - p[u].second;         dfs(v);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b, c;       cin >> a >> b >> c;       viz[a].push_back({b, c});       viz[b].push_back({a, c});     }     no = false;     for (int i = 1; i <= n; i++) {       if (p[i].first == 0) {         val.clear();         in.clear();         p[i] = {1, 0};         dfs(i);         if (val.size() > 1) no = true;         if (val.size() == 0) {           vector<int> fd;           for (auto x : in) fd.push_back(p[x].first * p[x].second);           sort(begin(fd), end(fd));           int c = -fd[fd.size() / 2];           for (auto x : in) num[x] = (double)p[x].first * c + p[x].second;         } else {           double c = (double)*val.begin() / 2;           for (auto x : in) num[x] = (double)p[x].first * c + p[x].second;         }       }     }     if (no)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << num[i] <<    ;       cout << endl;     }   }


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


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


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007, n, m, siz[100010], s[210][210], dp[100010][210],             f[210], sum[210];   vector<long long> g[100010];   void jia(long long &x, long long y) {     x += y;     if (x >= mod) x -= mod;   }   void dfs(long long x, long long fa) {     dp[x][0] = 2;     siz[x] = 1;     for (long long i = 0, v; i < g[x].size(); i++) {       v = g[x][i];       if (v == fa) continue;       dfs(v, x);       for (long long j = 0; j <= m; j++) f[j] = 0;       for (long long j = 0; j <= min(m, siz[x]); j++)         for (long long k = 0; k <= min(m - j, siz[v]); k++)           jia(f[j + k], dp[x][j] * dp[v][k] % mod);       for (long long j = 0; j <= m; j++) dp[x][j] = f[j];       for (long long j = 0; j <= m; j++) jia(sum[j], mod - dp[v][j]);       siz[x] += siz[v];     }     for (long long j = 0; j <= m; j++) jia(sum[j], dp[x][j]);     for (long long j = m; j >= 1; j--) jia(dp[x][j], dp[x][j - 1]);     jia(dp[x][1], mod - 1);   }   int main() {     scanf( %lld%lld , &n, &m);     for (long long u, v, i = 1; i < n; i++) {       scanf( %lld%lld , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     s[1][1] = 1;     for (long long i = 2; i <= m; i++)       for (long long j = 1; j <= i; j++)         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod;     dfs(1, 0);     long long ans = 0;     for (long long fac = 1, i = 1; i <= m; i++) {       fac = fac * i % mod;       jia(ans, fac * s[m][i] % mod * sum[i] % mod);     }     printf( %lld , ans);     return 0;   }


#include <algorithm>   #include <cmath>   #include <cstdio>   #include <cstring>   #include <fstream>   #include <iomanip>   #include <iostream>   #include <map>   #include <queue>   #include <random>   #include <set>   #include <stack>   #include <string>   #include <vector>      #ifndef ONLINE_JUDGE   //freopen( code.in ,  r , stdin);   //freopen( code.out , w ,stdout);   #endif      #define tplcf template <class c>   #define tplcfd template <class c, class b>   #define deout(X) operator<<(X)   #define recog(X) typename std::enable_if<sizeof dud<c>(0) X 1, debug &>::type      template <class c, class S = std::greater<c>, int L = 100000>   class sarr   {   public:       c *a;       int sa[L];       sarr(c *a, int sl, int sr)       {           for (int i = sl; i <= sr; ++i)               sa[i] = i;           sort(sa + sl, sa + sr + 1, S());       }       c &operator[](const int &index) { return a[sa[index]]; }   };   tplcf sarr<c>   sortarr(c *arr, int sl, int sr)   {       return sarr<c>(arr, sl, sr);   }      tplcf class suba   {   public:       suba(c *a, int l, int r) : a(a), l(l), r(r) {}       int l, r;       c *a;       c &operator[](const int &index) { return a[l + index]; }       inline uint32_t len() { return r - l + 1; }   };   tplcf suba<c>   subarr(c *a, int l, int r)   {       return suba<c>(a, l, r);   }      tplcf struct rge   {       c b, e;   };   tplcf rge<c>   range(c i, c j) { return rge<c>{i, j}; }   tplcf auto dud(c *x) -> decltype(std::cerr << *x, 0);   tplcf char dud(...);   struct debug   {   #ifndef ONLINE_JUDGE       ~debug()       {           std::cerr << std::endl;       }       tplcf recog(!=) deout(c i)       {           std::cerr << std::boolalpha << i;           return *this;       }       tplcf recog(==) deout(c i)       {           return *this << range(begin(i), end(i));       }       tplcfd debug &operator<<(std::pair<b, c> d)       {           return *this <<  (  << d.first <<  ,   << d.second <<  ) ;       }       tplcf debug &deout(rge<c> d)       {           *this <<  [ ;           for (auto it = d.b; it != d.e; ++it)               *this << (char *) ,   + 2 * (it == d.b) << *it;           return *this <<  ] ;       }       tplcf debug &deout(suba<c> sa)       {           *this <<  {  << sa.l <<  ,   << sa.r <<  }:  << range(sa.a + sa.l, sa.a + sa.r + 1);           return *this;       }   #else       tplcf debug &deout(const c &)       {           return *this;       }   #endif   };   #include <chrono>   class Timer   {   public:       Timer() : t1(clock::now()) {}       void tic()       {           t1 = clock::now();       }       void toc(const char *str)       {           t2 = clock::now();           std::cerr << str <<   time:   << std::chrono::duration_cast<res>(t2 - t1).count() / 1e3 <<  ms.  << std::endl;       }      private:       typedef std::chrono::high_resolution_clock clock;       typedef std::chrono::microseconds res;       clock::time_point t1, t2;   };      typedef long long ll;   #define FILE(X, Y)          ifstream fin(X);        ofstream fout(Y)   #define FASTIO()                       cin.sync_with_stdio(false);        cin.tie(0);                        cout.tie(0)   #define MP(X, Y) make_pair(X, Y)   #define imie(X)   [  << #X  :   << (X) <<  ]     #ifndef ONLINE_JUDGE   #define PAUSE()             system( pause );        return 0   #else   #define PAUSE() return 0   #endif      #define INF 0x3f3f3f3f   #define INFM 0x3f      using namespace std;      int n, m;   double p[10005];   char s[10004];   int las = 1;      mt19937 mtrand(time(0));      int main(void)   {       FASTIO();       cin >> n >> m;       for (int i = 1; i <= n; ++i)       {           p[i] = 1;       }       char t[3];       for (int i = 1; i <= m; ++i)       {           cin >> s + 1;           double c[2] = {0, 0};           for (int j = 1; j <= n; ++j)           {               c[s[j] -  0 ] += p[j];           }           cout << ((double(mtrand() % RAND_MAX) / double(RAND_MAX)) > (c[0] / (c[0] + c[1])) ?  1  :  0 ) << endl;           cin >> t;           for (int j = 1; j <= n; ++j)           {               if (s[j] != t[0])                   p[j] *= 0.8;           }       }       PAUSE();   }


#include <bits/stdc++.h>   using namespace std;    #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define int long long int   #define ld long double   #define endl   n    #define rep(i,a,b) for(int i=a;i<b;i++)   #define reprev(i,a,b) for(int i=b-1;i>=a;i--)   #define all(c) c.begin(),c.end()   #define sz(c) (int)c.size()   #define ff first   #define ss second   #define pii pair<int,int>   #define vi vector<int>   #define vii vector<pii>   #define vin(a,n) vi a(n); rep(k_,0,n) {cin>>a[k_];}   #define vout(a) rep(k_,0,sz(a)) {cout<<a[k_]<<   ;} cout<<endl;   #define pb push_back   #define mp  make_pair   #define mod 1000000007   #define mod2 998244353   #define inf 1e18   #define pi 3.1415926535897932384626   #define tr(container, it)    for(auto it = container.begin(); it != container.end(); it++)      int power(int x, unsigned int y, int p)     {         int res = 1;     // Initialize result              x = x % p; // Update x if it is more than or                     // equal to p              if (x == 0) return 0; // In case x is divisible by p;             while (y > 0)         {             // If y is odd, multiply x with result             if (y & 1)                 res = (res*x) % p;                  // y must be even now             y = y>>1; // y = y/2             x = (x*x) % p;         }         return res;     }      int ceill(int a,int b)   {       return (a+b-1)/b;   }      #define MAXN   100001        // stores smallest prime factor for every number   int spf[MAXN];        // Calculating SPF (Smallest Prime Factor) for every   // number till MAXN.   // Time Complexity : O(nloglogn)   void sieve()   {       spf[1] = 1;       for (int i=2; i<MAXN; i++)                // marking smallest prime factor for every           // number to be itself.           spf[i] = i;            // separately marking spf for every even       // number as 2       for (int i=4; i<MAXN; i+=2)           spf[i] = 2;            for (int i=3; i*i<MAXN; i++)       {           // checking if i is prime           if (spf[i] == i)           {               // marking SPF for all numbers divisible by i               for (int j=i*i; j<MAXN; j+=i)                        // marking spf[j] if it is not                    // previously marked                   if (spf[j]==j)                       spf[j] = i;           }       }   }        // A O(log n) function returning primefactorization   // by dividing by smallest prime factor at every step   vector<int> getFactorization(int x)   {       vector<int> ret;       while (x != 1)       {           ret.push_back(spf[x]);           x = x / spf[x];       }       return ret;   }      int modInverse(int n, int p)    {        return power(n, p-2, p);    }    const int N=1000000;   int fac[N+1];    void precomp(int p)   {       fac[0] = 1;        for (int i=1 ; i<=N; i++)            fac[i] = fac[i-1]*i%p;   }   // Returns nCr % p using Fermat s little    // theorem.    int nCrModPFermat(int n, int r, int p)    {       // Base case       if (r==0)          return 1;             // Fill factorial array so that we        // can find all factorial of r, n        // and n-r         return (fac[n]* modInverse(fac[r], p) % p *                modInverse(fac[n-r], p) % p) % p;    }   signed main()   {       #ifndef ONLINE_JUDGE           freopen( ./input.txt ,  r , stdin);           freopen( ./output.txt ,  w , stdout);       #endif       IOS       int T; cin>>T;       precomp(mod);       rep(t,1,T+1)       {           int n; cin>>n;           vin(a,n);           int and_val=a[0];           rep(i,1,n) and_val = and_val&a[i];              int freq=0;              rep(i,0,n)           {               if(a[i]==and_val) freq++;           }              int ans = freq*(freq-1);           ans%=mod;           ans*=fac[n-2]; ans%=mod;           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edges[500000];   bool vis[500000];   int order[1000000];   int first[500000], second[500000];   int C;   void dfs(int i) {     vis[i] = 1;     first[i] = C;     order[C++] = i;     for (int j = 0; j < edges[i].size(); j++)       if (!vis[edges[i][j]]) dfs(edges[i][j]);     second[i] = C;     order[C++] = i;   }   int segFill[2 * (1 << 20)], up[2 * (1 << 20)];   int segEmpty[2 * (1 << 20)];   int l[2 * (1 << 20)], r[2 * (1 << 20)];   void init() {     for (int i = (1 << 20); i < 2 * (1 << 20); i++) {       segFill[i] = -1;       up[i] = 0;       segEmpty[i] = 0;       l[i] = r[i] = i - (1 << 20);     }     for (int i = (1 << 20) - 1; i > 0; i--) {       segFill[i] = -1;       up[i] = 0;       segEmpty[i] = 0;       l[i] = l[2 * i];       r[i] = r[2 * i + 1];     }   }   void push(int i) {     if (up[i] > 0) {       if (i < (1 << 20)) {         up[(i << 1)] = up[i];         up[(i << 1) + 1] = up[i];       }       segFill[i] = up[i];       up[i] = 0;     }   }   int getFill(int i, int loc) {     push(i);     if (i >= (1 << 20))       return segFill[i];     else if (r[(i << 1)] >= loc)       return getFill((i << 1), loc);     else       return getFill((i << 1) + 1, loc);   }   int low, high;   void setFill(int i, int v) {     push(i);     if ((l[i] > high) || (r[i] < low)) return;     if ((l[i] >= low) && (r[i] <= high)) {       up[i] = v;       push(i);       return;     }     setFill((i << 1), v);     setFill((i << 1) + 1, v);     segFill[i] = max(segFill[(i << 1)], segFill[(i << 1) + 1]);   }   void setEmpty(int loc, int v) {     loc += (1 << 20);     segEmpty[loc] = v;     for (loc /= 2; loc > 0; loc /= 2)       segEmpty[loc] = max(segEmpty[2 * loc], segEmpty[2 * loc + 1]);   }   int getEmpty(int i) {     if ((l[i] > high) || (r[i] < low)) return 0;     if ((l[i] >= low) && (r[i] <= high)) return segEmpty[i];     return max(getEmpty((i << 1)), getEmpty((i << 1) + 1));   }   int main() {     int N, a, b;     scanf( %d , &N);     for (int i = 1; i < N; i++) {       scanf( %d %d , &a, &b);       a--, b--;       edges[a].push_back(b);       edges[b].push_back(a);     }     C = 0;     dfs(0);     init();     int Q, tp, v;     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       scanf( %d %d , &tp, &v);       v--;       if (tp == 1) {         low = first[v];         high = second[v];         setFill(1, i + 1);       }       if (tp == 2) setEmpty(first[v], i + 1);       if (tp == 3) {         low = first[v];         high = second[v];         a = getFill(1, first[v]);         b = getEmpty(1);         printf( %d n , a >= b);       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class C>   void mini(C& a, C b) {     a = min(a, b);   }   template <class C>   void maxi(C& a, C b) {     a = max(a, b);   }   void a() {     int n;     cin >> n;     vector<int> a(n), b(n), c(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> c[i];     vector<int> p(n);     p[0] = a[0];     for (int(i) = 1; i <= n - 2; i++) {       if (a[i] == p[i - 1])         p[i] = b[i];       else         p[i] = a[i];     }     if (a.back() != p[0] and a.back() != p[n - 2])       p[n - 1] = a.back();     else if (b.back() != p[0] and b.back() != p[n - 2])       p[n - 1] = b.back();     else       p[n - 1] = c.back();     for (int i = 0; i < n; i++) cout << p[i] <<    ;     cout <<   n ;   }   void b() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int diferentes = 1;     for (int(i) = 1; i <= n - 1; i++)       if (a[i] != a[i - 1]) diferentes++;     if (k == 1 and diferentes != 1) {       cout <<  -1 n ;       return;     }     int res = 1;     diferentes -= k;     while (diferentes > 0) {       res++;       diferentes -= k - 1;     }     cout << res <<   n ;   }   void c() {     int n;     long long l;     cin >> n >> l;     vector<long long> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     double izq = 0;     double izqVel = 1;     double der = l;     double derVel = 1;     int i = 0;     int j = n - 1;     double time = 0.0;     while (i <= j) {       double ti = (double)(a[i] - izq) / (double)izqVel;       double tj = (double)(der - a[j]) / (double)derVel;       if (ti < tj) {         izq = a[i];         i++;         izqVel++;         der -= ti * derVel;         time += ti;       } else {         der = a[j];         j--;         derVel++;         izq += tj * izqVel;         time += tj;       }     }     time += (der - izq) / (izqVel + derVel);     cout << setprecision(9) << fixed << time <<   n ;   }   void d() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(n), c(m), d(m);     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     for (int i = 0; i < m; i++) cin >> c[i] >> d[i];     vector<pair<int, int> > delta;     int dx, dy;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         dx = c[j] - a[i];         dy = d[j] - b[i];         if (dx >= 0 and dy >= 0) delta.push_back({dx, dy});       }     sort(delta.begin(), delta.end());     if (delta.empty()) {       cout << 0 <<   n ;       return;     }     int x = delta.back().first + 1;     int maxy = -1;     int res = x;     for (int(i) = delta.size() - 1; i >= 1; i--) {       x = delta[i - 1].first + 1;       maxi(maxy, delta[i].second);       mini(res, x + maxy + 1);     }     maxi(maxy, delta[0].second);     mini(res, maxy + 1);     cout << res <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     d();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, o = 0, z = 0;     cin >> n;     string s;     cin >> s;     for (i = 0; i < n; i++) {       if (s[i] ==  1 )         o++;       else         z++;     }     if (z != o) {       cout << 1 << endl << s;     } else {       cout << 2 << endl;       for (i = 0; i < n - 1; i++) cout << s[i];       cout <<     << s[n - 1];     }   }


#include <bits/stdc++.h>   using namespace std;   void Solves();   void In(int **a, int n);   int main() {     Solves();     return 0;   }   void Solves() {     long long n, k;     cin >> n >> k;     if (k > n * n) {       cout << -1;       return;     }     int **a = new int *[n + 1];     for (int i = 0; i <= n; i++) {       a[i] = new int[n + 1];     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         a[i][j] = 0;       }     }     if (k == 0) {       In(a, n);       return;     }     if (n == 1 && k == 1) {       cout << 1 << endl;       return;     }     for (int i = 1; i <= n - 1; i++) {       a[i][i] = 1;       k--;       for (int j = i + 1; j <= n; j++) {         if (k >= 2) {           a[i][j] = 1;           a[j][i] = 1;           k -= 2;         }         if (k == 1) {           a[i + 1][i + 1] = 1;           k--;         }         if (k == 0) {           In(a, n);           return;         }       }     }   }   void In(int **a, int n) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000], l[1000000], r[1000000];   int main() {     int n;     cin >> n;     int minn = 10000000;     int kol = 0;     int ans = 0;     int m = 2 * n - 1;     for (int i = 0; i < m; i++) {       cin >> a[i];       if (a[i] < 0) {         kol++;         a[i] = -a[i];       }       ans += a[i];       if (a[i] < minn) minn = a[i];     }     if (n % 2 == 1)       cout << ans << endl;     else {       if (kol % 2 == 0)         cout << ans << endl;       else         cout << ans - 2 * minn << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000001;   void run_case() {     long long n;     cin >> n;     vector<pair<long long, long long>> v;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back({x, i});     }     sort(v.begin(), v.end());     vector<long long> curr_max(n), maxi(n), ans(n);     curr_max[0] = v[0].second;     maxi[0] = v[0].second;     ans[v[0].second] = -1;     for (long long i = 1; i < n; i++) {       curr_max[i] = max(curr_max[i - 1], v[i].second);       if (v[i].first == v[i - 1].first)         maxi[i] = maxi[i - 1];       else         maxi[i] = curr_max[i];       ans[v[i].second] = maxi[i] - v[i].second - 1;     }     for (long long i = 0; i < n; i++) {       cout << max(ans[i], -1ll) <<    ;     }     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc = 1;     while (tc--) run_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int A, B;   signed long long from[505];   signed long long to[505];   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> K;     for (x = 0; x < (505); x++)       for (y = 0; y < (505); y++) from[x] = -1LL << 60;     from[0] = 0;     int sum = 0;     for (i = 0; i < (N); i++) {       cin >> A >> B;       for (x = 0; x < (505); x++) to[x] = -1LL << 60;       for (x = 0; x < (K); x++) {         y = (sum - x) % K;         if (y < 0) y += K;         for (j = 0; j < (K); j++) {           if (j > A) continue;           k = (A + B - j) % K;           if (k > B) continue;           int add = (A + B - j - k) / K;           to[(x + j) % K] = max(to[(x + j) % K],                                 from[x] + add + ((x + j) >= K) + ((y + k) >= K));         }       }       (sum += A + B) %= K;       swap(from, to);     }     signed long long ma = 0;     for (i = 0; i < (K); i++) ma = max(ma, from[i]);     cout << ma << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     multiset<long long> x, y;     long long n, closing = 0, count = 0, i, j, pair = 0;     cin >> n;     string ss;     for (i = 0; i < n; i++) {       stack<char> s;       closing = 0;       cin >> ss;       for (j = 0; j < ss.length(); j++) {         if (ss[j] ==  )  && s.size() == 0) closing++;         if (ss[j] ==  ( ) s.push(ss[j]);         if (ss[j] ==  )  && s.size() != 0) s.pop();       }       if (closing == 0 && s.size() > 0) x.insert(s.size());       if (closing > 0 && s.size() == 0) y.insert(closing);       if (closing == 0 && s.size() == 0) count++;     }     for (auto i : x) {       if (y.find(i) != y.end()) {         pair++;         y.erase(y.find(i));       }     }     cout << pair + count / 2;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n, m, i, j, a, b;   long long check(long long x, long long y) {     if (x == i && y == j) return 0;     if (abs(x - i) % a != 0 || abs(y - j) % b != 0) return inf;     if (abs(abs(x - i) / a - abs(y - j) / b) & 1) return inf;     if ((i - a < 1 && i + a > n) || (j - b < 1 && j + b > m))       return inf;     else       return max(abs(x - i) / a, abs(y - j) / b);   }   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &i, &j, &a, &b);     long long ret = inf;     ret = min(check(1, m), check(n, 1));     ret = min(ret, check(n, m));     ret = min(ret, check(1, 1));     if (ret == inf)       printf( Poor Inna and pony! n );     else       printf( %d n , ret);   }


#include <bits/stdc++.h>   using namespace std;   long long C[20][20];   long long dp[20];   int cnt[16];   int k, t;   long long solve(int l) {     memset(dp, 0, sizeof(dp));     dp[0] = 1;     for (int j = 0; j < 16; j++) {       for (int i = l; i >= 0; i--) {         for (int k = 1; k <= min(l - i, t - cnt[j]); k++) {           dp[i + k] = (dp[i + k] + C[l - i][k] * dp[i]);         }       }     }     return dp[l];   }   int main() {     C[0][0] = 1;     for (int i = 1; i < 20; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     scanf( %d%d , &k, &t);     for (int i = 1; i < 20; i++) {       long long ways = 0;       for (int j = 1; j < 16; j++) {         cnt[j]++;         ways += solve(i - 1);         cnt[j]--;       }       if (ways < k) {         k -= ways;       } else {         int l = i;         for (int i = 1; i <= l; i++) {           if (i == 1) {             for (int j = 1; j < 16; j++) {               cnt[j]++;               long long ways = solve(l - i);               if (ways < k) {                 k -= ways;                 cnt[j]--;               } else {                 if (j < 10)                   printf( %d , j);                 else                   printf( %c ,  a  + (j - 10));                 break;               }             }           } else {             for (int j = 0; j < 16; j++) {               if (cnt[j] == t) continue;               cnt[j]++;               long long ways = solve(l - i);               if (ways < k) {                 k -= ways;                 cnt[j]--;               } else {                 if (j < 10)                   printf( %d , j);                 else                   printf( %c ,  a  + (j - 10));                 break;               }             }           }         }         break;       }     }   }


/*              Note        :           helluva implementation.           Link        :                  Boka hoye gelum...   */            #include  bits/stdc++.h        #define sp <<      #define el <<  n    #define S second   #define F first   #define pb push_back   #define all(ar) ar.begin(),ar.end()    #define pii pair<ll,ll>           using namespace std;   using ll = long long;   using ld = long double;       const ll mod = 1000000007;   const ll oo = 3372036000000000;   const ll si = 300005;      vector<pair<pii,char>> vec;    ll ans[si],in[si],n,m;   char dir[si];     bool don[si];       void sm_dir(char q){    stack<pii> od,ev;     for(ll i = q ==  L  ? 0 : n - 1; i < n && i >=  0; q ==  L ? i++ : i--){     if(don[vec[i].F.S] || vec[i].S != q) continue;      pii da,cur = vec[i].F;      if(cur.F & 1){      if(od.empty()){       od.push(cur);        continue;       }      da = od.top(); od.pop();      }else{      if(ev.empty()){       ev.push(cur); continue;       }      da = ev.top(); ev.pop();      }     ll tim = abs(da.F - cur.F)/2;      if(q ==  R ) tim += m - da.F;      else tim += da.F;      don[da.S] = don[cur.S] = 1;      ans[da.S] = ans[cur.S] = tim;     }   }         void baki(){    stack<pii> od,ev;     for(ll i = 0; i < n; i++){     if(don[vec[i].F.S]) continue;      if(vec[i].S ==  L ){      if(vec[i].F.F&1) od.push(vec[i].F);       else ev.push(vec[i].F);      }    }    for(ll i = n-1; i >= 0; i--){     if(don[vec[i].F.S]) continue;      if(vec[i].S ==  R ){      pii cur = vec[i].F,da;       if(cur.F & 1){       if(od.empty()) continue;        da = od.top(); od.pop();       }else{       if(ev.empty()) continue;        da = ev.top(); ev.pop();       }      ll tim = 0;        if(m - cur.F > da.F){       ll wae = m - cur.F,nda = (wae - da.F); // sure?         ll dis = (m - nda)/2;        tim += wae;        tim += dis;       }else{       ll wae = da.F, nda = ((2 * m) - (cur.F + wae))/2;        tim += (wae + nda);       }      ans[cur.S] = ans[da.S] = tim;     }    }   }         signed main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);   //*   #ifndef ONLINE_JUDGE       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);   #endif   //*/       ll t; cin>>t;        while(t--){        vec.clear();        memset(ans,-1,sizeof(ans));        memset(don,0,sizeof(don));           cin>>n>>m;        for(ll i = 0; i < n; i++) cin>>in[i];         for(ll i = 0; i < n; i++) cin>>dir[i];         for(ll i = 0; i < n; i++){         ll x = in[i]; char d = dir[i];          vec.pb({{x,i},d});         }         sort(all(vec));         stack<pii> ev,od;          for(ll i = 0; i < n; i++){         if(vec[i].S ==  R ){          if(vec[i].F.F & 1) od.push(vec[i].F);           else ev.push(vec[i].F);          }else{          pii da,cur = vec[i].F;           if(vec[i].F.F & 1){           if(od.empty()) continue;            da = od.top(); od.pop();           }else{           if(ev.empty()) continue;            da = ev.top(); ev.pop();           }          ll tim = (cur.F - da.F)/2;           don[cur.S] = don[da.S] = 1;           ans[cur.S] = ans[da.S] = tim;          }        }        sm_dir( L );         sm_dir( R );        baki();         for(ll i = 0; i < n; i++) cout<<ans[i] sp; cout el;        }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000010];   int solution[1000010] = {0};   int main() {     ios::sync_with_stdio(0);     int n;     long long int sum = 0;     long long int part;     long long partSum = 0;     long long int result = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     if (sum % 3)       cout <<  0 ;     else {       part = sum / 3;       for (int i = 0; i < n; ++i) {         partSum += a[i];         if (partSum == part) solution[i] = 1;       }       for (int i = 0; i < n - 2; i++) solution[i + 1] += solution[i];       partSum = 0;       for (int i = n - 1; i - 2 >= 0; --i) {         partSum += a[i];         if (partSum == part) result += solution[i - 2];       }       cout << result;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int N = 1e5 + 2;   vector<pair<int, int> > seg[3 * N][2];   long long int sig[3 * N];   int a[N];   vector<pair<int, int> > m[2];   int n, x;   inline long long int mrg(vector<pair<int, int> > z[2],                            vector<pair<int, int> > y[2]) {     if (z[0].size() == 0) {       m[0] = y[0];       m[1] = y[1];       return 0;     }     if (y[0].size() == 0) {       m[0] = z[0];       m[1] = z[1];       return 0;     }     long long int t = 0;     for (auto i : z[1]) {       for (auto j : y[0]) {         if ((i.first | j.first) >= x) {           t += 1LL * i.second * j.second;         }       }     }     m[1].clear();     m[0].clear();     m[1] = y[1];     int r = 0;     r = y[1].back().first;     for (auto i : z[1]) {       long long int e = (i.first | r);       if (m[1].size() == 0) {         m[1].push_back({e, i.second});       } else if (e != m[1].back().first)         m[1].push_back({e, i.second});       else {         m[1].back().second += i.second;       }     }     m[0] = z[0];     r = z[0].back().first;     for (auto i : y[0]) {       long long int e = (i.first | r);       if (m[0].size() == 0) {         m[0].push_back({e, i.second});       } else if (e != m[0].back().first)         m[0].push_back({e, i.second});       else         m[0].back().second += i.second;     }     return t;   }   void upd(int nod, int l, int r, int id, int val) {     if (r - l == 1) {       seg[nod][0].clear();       seg[nod][0].push_back({val, 1});       seg[nod][1].clear();       seg[nod][1].push_back({val, 1});       if (val >= x)         sig[nod] = 1;       else         sig[nod] = 0;       return;     }     int mid = (r + l) >> 1;     if (mid > id)       upd(nod << 1, l, mid, id, val);     else       upd(nod << 1 | 1, mid, r, id, val);     sig[nod] = sig[nod << 1] + sig[nod << 1 | 1];     sig[nod] += mrg(seg[nod << 1], seg[nod << 1 | 1]);     seg[nod][0] = m[0];     seg[nod][1] = m[1];   }   void build(int nod, int l, int r) {     if (r - l == 1) {       seg[nod][0].clear();       seg[nod][0].push_back({a[l], 1});       seg[nod][1].clear();       seg[nod][1].push_back({a[l], 1});       if (a[l] >= x)         sig[nod] = 1;       else         sig[nod] = 0;       return;     }     int mid = (r + l) >> 1;     build(nod << 1, l, mid);     build(nod << 1 | 1, mid, r);     sig[nod] = sig[nod << 1] + sig[nod << 1 | 1];     sig[nod] += mrg(seg[nod << 1], seg[nod << 1 | 1]);     seg[nod][0] = m[0];     seg[nod][1] = m[1];   }   vector<pair<int, int> > g[2];   long long int ans = 0;   void get(int nod, int l, int r, int L, int R) {     if (l >= R || L >= r) return;     if (l >= L && r <= R) {       ans += mrg(g, seg[nod]) + sig[nod];       g[0] = m[0];       g[1] = m[1];       return;     }     int mid = (r + l) >> 1;     get(nod << 1, l, mid, L, R);     get(nod << 1 | 1, mid, r, L, R);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     scanf( %d %d %d , &n, &q, &x);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     build(1, 1, N);     for (int i = 0; i < q; i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int id, val;         scanf( %d %d , &id, &val);         upd(1, 1, N, id, val);       } else {         int l, r;         scanf( %d %d , &l, &r);         ans = 0;         get(1, 1, N, l, r + 1);         printf( %lld  n , ans);         g[0].clear();         g[1].clear();       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1500 + 5, INF = 2000 * 1000 * 1000;   vector<pair<int, int> > li[N];   vector<int> adj[N];   pair<pair<int, int>, int> po[N];   pair<int, int> J;   int d[N], out[N];   void dfs(const int &v, const int &pa) {     d[v] = 1;     for (int i = 0; i < (int)(adj[v]).size(); ++i) {       if (adj[v][i] != pa) {         dfs(adj[v][i], v);         d[v] += d[adj[v][i]];         li[v].push_back(make_pair(d[adj[v][i]], adj[v][i]));       }     }   }   bool cmp(const pair<pair<int, int>, int> &R,            const pair<pair<int, int>, int> &T) {     long long a1 = J.first - R.first.first, a2 = J.first - T.first.first;     long long b1 = J.second - R.first.second, b2 = J.second - T.first.second;     return a1 * b2 > a2 * b1;   }   void ass(int f, int s, int x) {     pair<int, int> ans = make_pair(-INF, -INF);     int no;     for (int i = f; i <= s; ++i) {       if (po[i].first.second > ans.second)         ans = make_pair(po[i].first.first, po[i].first.second), no = i;       else if (po[i].first.second == ans.second && po[i].first.first < ans.first)         ans = make_pair(po[i].first.first, po[i].first.second), no = i;     }     J = ans;     out[po[no].second] = x;     swap(po[no], po[s]);     sort(po + f, po + s, cmp);     for (int i = 0; i < (int)(li[x]).size(); ++i) {       ass(f, f + li[x][i].first - 1, li[x][i].second);       f += li[x][i].first;     }   }   int main() {     ios::sync_with_stdio(false);     srand(time(0));     int n, a, b, root;     int zero = 0;     scanf( %d , &n);     if (n >= 1300)       root = 750;     else       root = rand() % n + 1;     for (int i = 0; i < n - 1; ++i) {       adj[i].reserve(N);       li[i].reserve(N);       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(root, zero);     for (int i = 1; i <= n; ++i)       scanf( %d%d , &po[i].first.first, &po[i].first.second), po[i].second = i;     ass(1, n, root);     for (int i = 1; i <= n; ++i) printf( %d  , out[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long int a[n + 2];     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     long long int mx = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) {           mx = max(mx, a[i] | a[j]);         }         for (int k = 1; k <= n; k++) {           if (i != j && i != k && j != k) {             mx = max(mx, a[i] | a[j] | a[k]);           }         }       }     }     printf( %lld , mx);     return 0;   }


#include<bits/stdc++.h>   #define pb push_back   #define F first   #define S second   using namespace std;   typedef long long ll;   typedef pair<int,int>pi;   typedef vector<int>vi;   const int maxn=1e6+10;   const int M=998244353;   ll t[1<<14][105];   ll d[105][105],d2[105][14],d22[14][14];   ll mind[1<<14][105],mind2[1<<14][14];   ll xa[105],ya[105],xb[105],yb[105],T[105],ans;   struct node{       ll x,y,t;   }A[205];   bool cmp(node u,node v){return u.t<v.t;}   void Min(ll &x,ll y){if (y<x)x=y;}   int n,m,f[1<<14][105];   const ll inf=1e14;   int main(){       cin >> m >> n;       for (int i=0;i<m;i++) cin >> xb[i] >> yb[i];       for (int i=0;i<n;i++) cin >> A[i].x >> A[i].y >> A[i].t;       sort(A,A+n,cmp);       for (int i=0;i<n;i++) xa[i]=A[i].x,ya[i]=A[i].y,T[i]=A[i].t;       for (int i=0;i<n;i++)           for (int j=0;j<n;j++)               d[i][j]=abs(xa[i]-xa[j])+abs(ya[i]-ya[j]);       for (int i=0;i<n;i++)           for (int j=0;j<m;j++)               d2[i][j]=abs(xa[i]-xb[j])+abs(ya[i]-yb[j]);       for (int i=0;i<m;i++)           for (int j=0;j<m;j++)               d22[i][j]=abs(xb[i]-xb[j])+abs(yb[i]-yb[j]);       for (int i=0;i<n;i++)       for (int j=0;j<(1<<m);j++){           mind[j][i]=inf;           for (int k=0;k<m;k++) if ((j>>k)&1) Min(mind[j][i],d2[i][k]);       }       for (int i=0;i<m;i++)       for (int j=0;j<(1<<m);j++){           mind2[j][i]=inf;           for (int k=0;k<m;k++) if ((j>>k)&1) Min(mind2[j][i],d22[i][k]);       }       memset(f,-1,sizeof(f));       for (int i=0;i<n;i++) f[0][i]=1;       for (int i=0;i<=n;i++)           for (int j=0;j<(1<<m);j++)               t[j][i]=inf;       for (int i=0;i<m;i++) t[1<<i][0]=0;       int ans=0;       for (int mask=0;mask<(1<<m);mask++){           for (int j=0;j<=n;j++) if (t[mask][j]<inf){               for (int i=0;i<m;i++) if (!((mask>>i)&1)){                   Min(t[mask|1<<i][j],t[mask][j]+mind2[mask][i]);               }               for (int i=0;i<n;i++) if (t[mask][j]+mind[mask][i]<=T[i]){                   f[mask][i]=max(f[mask][i],j+1);               }           }           for (int i=0;i<n;i++) if (f[mask][i]!=-1){               int k=f[mask][i];               ans=max(ans,k);               for (int j=0;j<m;j++) if (!((mask>>j)&1)){                   Min(t[mask|1<<j][k],T[i]+min(d2[i][j],mind2[mask][j]));               }               for (int j=i+1;j<n;j++) if (min(d[i][j],mind[mask][j])+T[i]<=T[j]){                   f[mask][j]=max(f[mask][j],k+1);               }           }       }       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[200005];   long long k;   int main() {     scanf( %d%I64d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     int p;     for (p = 1; p <= n && a[p] == 0; p++)       ;     p = n - p + 1;     long long mx = 0;     for (int i = 1; i <= n; i++) mx = max(mx, a[i]);     if (p == 2)       printf( %I64d n , (k - a[n] - 1) / a[n - 1] + 1);     else if (p == 3) {       long long l = 0, r = 1.5e9;       while (l < r) {         long long md = (l + r) / 2;         long long res = md * (md + 1) / 2;         if (res < 0 || res >= k)           r = md;         else {           res *= a[n - 2];           if (res < 0 || res >= k)             r = md;           else {             res += md * a[n - 1];             if (res < 0 || res >= k)               r = md;             else if (res + a[n] >= k)               r = md;             else               l = md + 1;           }         }       }       printf( %I64d n , r);     } else {       p = n - p + 2;       int ans = 0, i;       while (mx < k) {         for (i = p; i <= n; i++) a[i] += a[i - 1], mx = max(mx, a[i]);         ans++;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1 >> s2;     int h1 = stoi(s1.substr(0, 2));     int m1 = stoi(s1.substr(3, 2));     int h2 = stoi(s2.substr(0, 2));     int m2 = stoi(s2.substr(3, 2));     int m3 = (m1 + m2) / 2;     int h3 = h1 + h2;     if (h3 % 2 != 0) m3 += 30;     h3 = h3 / 2;     if (m3 >= 60) {       h3++;       m3 -= 60;     }     if (h3 < 10) cout <<  0 ;     cout << h3 <<  : ;     if (m3 < 10) cout <<  0 ;     cout << m3;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0, sch = 0, nm = -100000, pnm = 10000;     vector<int> v;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       if ((t % 2 == 1) && (t > 0)) {         pnm = ((pnm) < (t)) ? (pnm) : (t);         ans += t;       } else if (t % 2 == -1) {         nm = ((nm) > (t)) ? (nm) : (t);       } else if (t > 0) {         sch += t;       }     }     if (ans == 0) ans += nm;     ans += sch;     if (ans % 2 == 0) ans = ((ans - pnm) > (ans + nm)) ? (ans - pnm) : (ans + nm);     printf( %d , ans);     return 0;   }