#include <bits/stdc++.h>   using namespace std;   const int N = 500000;   mt19937 Rand(time(0));   int mod[3];   struct hasher {     int a[3];     hasher(int x = 0) { a[0] = a[1] = a[2] = x; }     friend hasher operator+(const hasher &a, const hasher &b) {       hasher res;       for (int i = 0; i < 3; ++i) {         res.a[i] = a.a[i] + b.a[i];         if (res.a[i] >= mod[i]) res.a[i] -= mod[i];       }       return res;     }     friend hasher operator-(const hasher &a, const hasher &b) {       hasher res;       for (int i = 0; i < 3; ++i) {         res.a[i] = a.a[i] - b.a[i];         if (res.a[i] < 0) res.a[i] += mod[i];       }       return res;     }     friend hasher operator*(const hasher &a, const hasher &b) {       hasher res;       for (int i = 0; i < 3; ++i) res.a[i] = 1LL * a.a[i] * b.a[i] % mod[i];       return res;     }     friend bool operator==(const hasher &a, const hasher &b) {       for (int i = 0; i < 3; ++i)         if (a.a[i] != b.a[i]) return 0;       return 1;     }     hasher inv() {       hasher res = 1;       for (int i = 0; i < 3; ++i) {         int k = mod[i] - 2, x = a[i];         for (; k; k >>= 1, x = 1LL * x * x % mod[i])           if (k & 1) res.a[i] = 1LL * res.a[i] * x % mod[i];       }       return res;     }   } pw[N + 9];   void Get_pw() {     pw[0] = 1;     pw[1] = 10;     for (int i = 2; i <= N; ++i) pw[i] = pw[i - 1] * pw[1];   }   hasher Get_hash(hasher *h, int l, int r) {     return h[r] - h[l - 1] * pw[r - l + 1];   }   hasher Get_hash(vector<hasher> &h, int l, int r) {     return h[r] - h[l - 1] * pw[r - l + 1];   }   char s[N + 9], t[N + 9];   int n, m;   void into() {     scanf( %s%s , s + 1, t + 1);     n = strlen(s + 1);     m = strlen(t + 1);   }   int Get_mod0() { return 19260817; }   bool Check_prime(int n) {     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   int Get_prime(int n) {     for (; !Check_prime(n); ++n)       ;     return n;   }   int Get_mod1() {     int sum = 0;     for (int i = 1; i <= n; ++i) sum += s[i];     for (int i = 1; i <= m; ++i) sum += t[i];     int n = Rand() % 200000000 + 300000000 + sum;     return Get_prime(n);   }   int Get_mod2() {     int x = Rand() % 200000000 + 300000000;     double y = 1.0 * (Rand() % 10), z = 1.0 * (Rand() & (1 << 28) - 1);     return Get_prime((int)(x + exp(y) + cos(z) * z));   }   void Get_mod() {     mod[0] = Get_mod0();     mod[1] = Get_mod1();     mod[2] = Get_mod2();   }   hasher hs[N + 9], ht[N + 9];   void Get_hash() {     for (int i = 1; i <= n; ++i) hs[i] = hs[i - 1] * pw[1] + (s[i] -  0 );     for (int i = 1; i <= m; ++i) ht[i] = ht[i - 1] * pw[1] + (t[i] -  0 );   }   int Get_lcp(int p) {     int l = 1, r = m, res = 0;     for (int mid; l <= r;) {       mid = l + r >> 1;       Get_hash(hs, p, p + mid - 1) == Get_hash(ht, 1, mid)           ? (res = mid, l = mid + 1)           : r = mid - 1;     }     return res;   }   void Get_ans() {     for (int i = 1; i <= n; ++i) {       if (i - (m - 1) >= 0 || i + (m - 1) <= n) {         if (Get_hash(hs, i - (m - 1) + 1, i) + Get_hash(hs, i + 1, i + (m - 1)) ==             ht[m]) {           printf( %d %d n%d %d n , i - (m - 1) + 1, i, i + 1, i + (m - 1));           return;         }       }       if (i + m <= n) {         int t = m - Get_lcp(i + 1);         if (t >= 1 && i >= t &&             Get_hash(hs, i + 1, i + m) + Get_hash(hs, i - t + 1, i) == ht[m]) {           printf( %d %d n%d %d n , i - t + 1, i, i + 1, i + m);           return;         }         if (t >= 2 && i >= t - 1 &&             Get_hash(hs, i + 1, i + m) + Get_hash(hs, i - t + 2, i) == ht[m]) {           printf( %d %d n%d %d n , i - t + 2, i, i + 1, i + m);           return;         }       }       if (i - m >= 0) {         int t = m - Get_lcp(i - m + 1);         if (t >= 1 && i + t <= n &&             Get_hash(hs, i - m + 1, i) + Get_hash(hs, i + 1, i + t) == ht[m]) {           printf( %d %d n%d %d n , i - m + 1, i, i + 1, i + t);           return;         }         if (t >= 2 && i + t - 1 <= n &&             Get_hash(hs, i - m + 1, i) + Get_hash(hs, i + 1, i + t - 1) ==                 ht[m]) {           printf( %d %d n%d %d n , i - m + 1, i, i + 1, i + t - 1);           return;         }       }     }   }   void work() {     Get_mod();     Get_pw();     Get_hash();     Get_ans();   }   void outo() {}   int main() {     int T = 1;     for (; T--;) {       into();       work();       outo();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using nagai = long long;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int c = 0;     int t = 1;     while (t <= n) {       n -= t, ++c, t *= 2;     }     if (n) ++c;     cout << c <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 200000 + 5;   const int MMAX = 2000 + 5;   const int INF = 1000000000;   const int BS = 1000000000 + 7;   const long long INFLL = 1000000000ll * 1000000000ll;   const long double eps = 1e-6;   int a[NMAX];   bool is_inverted[4 * NMAX];   bool shouldSetTrue[4 * NMAX];   bool shouldSetFalse[4 * NMAX];   bool shouldInvert[4 * NMAX];   void merge_flags(int parent, int child) {     if (shouldSetFalse[parent]) {       shouldSetFalse[child] = true;       shouldSetTrue[child] = false;       shouldInvert[child] = false;       return;     }     if (shouldSetTrue[parent]) {       shouldSetFalse[child] = false;       shouldSetTrue[child] = true;       shouldInvert[child] = false;       return;     }     if (shouldInvert[parent]) {       if (shouldSetFalse[child]) {         shouldSetFalse[child] = false;         shouldSetTrue[child] = true;         shouldInvert[child] = false;       } else if (shouldSetTrue[child]) {         shouldSetFalse[child] = true;         shouldSetTrue[child] = false;         shouldInvert[child] = false;       } else {         shouldInvert[child] = !shouldInvert[child];       }     }   }   void pass_down(int v, int tl, int tr) {     if (tl == tr) {       bool current = is_inverted[v];       if (shouldSetFalse[v]) {         current = false;       }       if (shouldSetTrue[v]) {         current = true;       }       if (shouldInvert[v]) {         current = !current;       }       is_inverted[v] = current;       shouldSetFalse[v] = false;       shouldSetTrue[v] = false;       shouldInvert[v] = false;       return;     }     merge_flags(v, v + v);     merge_flags(v, v + v + 1);     shouldSetFalse[v] = false;     shouldSetTrue[v] = false;     shouldInvert[v] = false;   }   bool get(int v, int tl, int tr, int pos) {     pass_down(v, tl, tr);     if (tl == tr) {       return is_inverted[v];     }     int tm = (tl + tr) / 2;     if (pos <= tm) {       return get(v + v, tl, tm, pos);     } else {       return get(v + v + 1, tm + 1, tr, pos);     }   }   void set_inverted(int v, int tl, int tr, int l, int r, bool shouldBeTrue,                     bool shouldBeFalse, bool shouldBeInverted) {     if (r < l) return;     pass_down(v, tl, tr);     if (l == tl && r == tr) {       if (shouldBeFalse) {         shouldSetFalse[v] = true;       }       if (shouldBeTrue) {         shouldSetTrue[v] = true;       }       if (shouldBeInverted) {         shouldInvert[v] = true;       }       return;     }     int tm = (tl + tr) / 2;     if (r <= tm) {       set_inverted(v + v, tl, tm, l, r, shouldBeTrue, shouldBeFalse,                    shouldBeInverted);     } else if (l >= tm + 1) {       set_inverted(v + v + 1, tm + 1, tr, l, r, shouldBeTrue, shouldBeFalse,                    shouldBeInverted);     } else {       set_inverted(v + v, tl, tm, l, tm, shouldBeTrue, shouldBeFalse,                    shouldBeInverted);       set_inverted(v + v + 1, tm + 1, tr, tm + 1, r, shouldBeTrue, shouldBeFalse,                    shouldBeInverted);     }   }   int main(int argc, char** argv) {     if (argc > 1 && strcmp(argv[1],  seland ) == 0) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int n, q;     scanf( %d %d n , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     scanf(  n );     int bias = 100000;     for (int i = 0; i < q; i++) {       char c;       int x;       scanf( %c %d n , &c, &x);       if (c ==  <  && x <= 0) {         x--;         set_inverted(1, 0, NMAX - 1, 0, bias + x, true, false, false);         set_inverted(1, 0, NMAX - 1, bias - x, 2 * bias, false, true, false);       } else if (c ==  >  && x >= 0) {         x++;         set_inverted(1, 0, NMAX - 1, bias + x, 2 * bias, true, false, false);         set_inverted(1, 0, NMAX - 1, 0, bias - x, false, true, false);       } else if (c ==  <  && x > 0) {         x--;         set_inverted(1, 0, NMAX - 1, 0, bias - x - 1, true, false, false);         set_inverted(1, 0, NMAX - 1, bias + x + 1, 2 * bias, false, true, false);         set_inverted(1, 0, NMAX - 1, bias - x, bias + x, false, false, true);       } else if (c ==  >  && x < 0) {         x++;         set_inverted(1, 0, NMAX - 1, bias - x + 1, 2 * bias, true, false, false);         set_inverted(1, 0, NMAX - 1, 0, bias + x - 1, false, true, false);         set_inverted(1, 0, NMAX - 1, bias + x, bias - x, false, false, true);       }     }     for (int i = 0; i < n; i++) {       bool inverted = get(1, 0, NMAX - 1, a[i] + bias);       if (inverted) {         printf( %d  , -a[i]);       } else {         printf( %d  , a[i]);       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0,                              x, y, z, cnt = 0;     string s;     set<long long> zero, one;     set<long long>::iterator it, it1;     vector<long long> v[200005];     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         zero.insert(i);       } else {         one.insert(i);       }     }     while (one.size()) {       i = -1;       if (zero.size() == 0) {         cout << -1;         return 0;       }       it = zero.lower_bound(i);       i = *it;       zero.erase(i);       v[ans].push_back(i);       while (one.size()) {         it = one.lower_bound(i);         if (it == one.end()) {           break;         }         i = *it;         one.erase(i);         v[ans].push_back(i);         it = zero.lower_bound(i);         if (it == zero.end()) {           cout << -1;           return 0;         }         i = *it;         zero.erase(i);         v[ans].push_back(i);       }       ans++;     }     k = ans + zero.size();     cout << k << endl;     for (i = 0; i < ans; i++) {       for (j = 0; j < v[i].size(); j++) {         if (j == 0) {           cout << v[i].size() <<    ;         }         cout << v[i][j] + 1 <<    ;       }       cout << endl;     }     while (zero.size()) {       it = zero.begin();       cout << 1 <<     << *it + 1 << endl;       zero.erase(it);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long int a[101];   long long int dp[101][101][101];   long long int f(int start, int end, int l) {     if (start > end) {       return 0;     }     if (start == end) {       return a[l];     }     if (dp[start][end][l] != 0) {       return dp[start][end][l];     }     long long int ans = a[l] + f(start + 1, end, 1);     for (int i = start + 1; i <= end; i++) {       if (s[i] == s[start]) {         ans = max(ans, f(start + 1, i - 1, 1) + f(i, end, l + 1));       }     }     dp[start][end][l] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     a[0] = 0;     cout << f(0, n - 1, 1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 103, maxm = 1003;   int m, n, ar[maxn];   double dp[maxn * maxm], pre[maxn * maxm];   int main() {     scanf( %d%d , &n, &m);     if (m == 1) {       printf( 1 );       return 0;     }     int sum = 0;     for (int i = 1; i <= n; i++) scanf( %d , &ar[i]), sum += ar[i];     dp[0] = 1;     for (int i = 1; i <= n; i++) {       pre[0] = dp[0];       for (int j = 1; j <= i * m; j++) pre[j] = pre[j - 1] + dp[j];       for (int j = i * m; j; j--) {         dp[j] = pre[j - 1];         if (j - m - 1 >= 0) dp[j] -= pre[j - m - 1];         if (j - ar[i] >= 0) dp[j] -= dp[j - ar[i]];         dp[j] /= m - 1;       }       dp[0] = 0;     }     double ans = 0;     for (int i = 0; i < sum; i++) ans += dp[i];     printf( %.10lf n , 1 + ans * (m - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n, 0);       vector<long long> pos(32, 0);       for (long long i = 0; i < n; i++) {         cin >> a[i];         long long ind = 0;         long long num = a[i];         while (num != 0) {           if (num % 2 == 1) pos[ind] += 1;           ind++;           num /= 2;         }       }       long long f = 0;       for (long long i = pos.size() - 1; i >= 0; i--) {         if (pos[i] % 2 == 1) {           f = 1;           if (pos[i] == 1)             cout <<  WIN n ;           else {             if ((pos[i] / 2) % 2 == 0)               cout <<  WIN n ;             else {               if (n % 2 == 0)                 cout <<  WIN n ;               else                 cout <<  LOSE n ;             }           }           break;         }       }       if (f == 0) cout <<  DRAW n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, t, piles = 1;     bool flag = true;     cin >> n;     vector<int> s1, s2;     vector<int>::iterator it;     for (i = 0; i < n; i++) {       cin >> t;       s1.push_back(t);     }     sort(s1.begin(), s1.end());     while (flag) {       flag = false;       for (it = s1.begin(), i = 0; it != s1.end();) {         if ((*it) < i) {           flag = true;           s2.push_back(*it);           s1.erase(it);         } else {           it++;           i++;         }       }       if (flag) {         piles += 1;         s1.clear();         s1 = s2;         s2.clear();       }     }     cout << piles;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int M = 1 << 16;   bitset<N> mp[M];   int a[N], sum, rk[N], k, n;   priority_queue<pair<int, int> > que;   void dfs(int s, int t) {     if (s == 0) return;     int r = 0;     for (; t * k < N && mp[s][t * k]; r++, t *= k) {     }     for (int i = 0; i < n; i++) {       if (s & (1 << i)) rk[i] += r;     }     for (int i = 0; i < n; i++) {       if (s & (1 << i) && t >= a[i] && mp[s - (1 << i)][t - a[i]]) {         dfs(s - (1 << i), t - a[i]);         return;       }     }   }   int main() {     sum = 0;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       sum += a[i];     }     mp[0][0] = 1;     for (int s = 1; s < (1 << n); s++) {       for (int i = 0; i < n; i++) {         if (s & (1 << i)) mp[s] |= mp[s - (1 << i)] << a[i];       }       for (int i = sum / k; i >= 1; i--) {         if (mp[s][i * k]) mp[s][i] = 1;       }     }     if (!mp[(1 << n) - 1][1]) {       puts( NO );       return 0;     }     puts( YES );     dfs((1 << n) - 1, 1);     for (int i = 0; i < n; i++) {       que.push({rk[i], a[i]});     }     while (que.size() != 1) {       pair<int, int> u = que.top();       que.pop();       pair<int, int> v = que.top();       que.pop();       printf( %d %d n , u.second, v.second);       u.second += v.second;       while (u.second % k == 0) {         u.second /= k;         u.first--;       }       que.push(u);     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int u;     int v;     int c;   };   bool compare(edge e, edge u) { return e.c < u.c; }   int findparent(int parent[], int u) {     int p = parent[u];     if (p == u) {       return p;     }     int fp = findparent(parent, p);     if (p == fp) {       return fp;     }     parent[u] = fp;     return parent[u];   }   int mc = -1;   void uni(int special[], int parent[], int u, int v, int c) {     int up = findparent(parent, u);     int vp = findparent(parent, v);     if (vp == up) {       return;     }     parent[up] = vp;     if (special[up] != 0 && special[vp] != 0) {       special[vp] = c;       special[up] = c;       mc = c;     } else {       int max = special[up] > special[vp] ? special[up] : special[vp];       special[up] = special[vp] = max;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     vector<edge> edges;     int special[n];     for (int i = 0; i < n; i++) {       special[i] = 0;     }     for (int i = 0; i < k; i++) {       int tmp;       cin >> tmp;       tmp--;       special[tmp] = 1;     }     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--;       v--;       edges.push_back({u, v, w});     }     sort(edges.begin(), edges.end(), compare);     int parent[n];     for (int i = 0; i < n; i++) {       parent[i] = i;     }     for (int i = 0; i < m; i++) {       int u = edges[i].u;       int v = edges[i].v;       int c = edges[i].c;       uni(special, parent, u, v, c);     }     for (int i = 0; i < k; i++) {       cout << mc <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double f[400][3100], p[400][3100], ans;   int n, m, up[400];   void dp(int i) {     int j;     long double pre, nw;     pre = f[i][0];     f[i][0] = 0;     for (j = 1; j <= n; j++) {       nw = f[i][j];       f[i][j] = pre * p[i][j] + f[i][j - 1] * (1 - p[i][j]);       pre = nw;     }     up[i]++;   }   int main() {     int i, j, k, x, to;     long double mx;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &x);         p[j][i] = (long double)x / (long double)1000;       }     for (i = 1; i <= m; i++)       for (j = 0; j <= n; j++) f[i][j] = 1;     for (i = 1; i <= m; i++) up[i] = 0;     for (i = 1; i <= m; i++) dp(i);     ans = 0;     for (i = 1; i <= n; i++) {       mx = -1;       for (j = 1; j <= m; j++)         if (f[j][n] > mx) mx = f[j][n], to = j;       ans += mx;       dp(to);     }     double out = ans;     printf( %.11f n , out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1010], seq[1010], id;   int qtes, u[1000010], v[1000010];   inline void add(int x, int y) {     a[y] -= a[x], a[x] *= 2, u[++qtes] = x, v[qtes] = y;   }   inline void Solve(int x, int y, int z) {     int q[3] = {x, y, z};     register int i, j;     for (i = 0; i < 3; ++i)       for (j = i + 1; j < 3; ++j)         if (a[q[i]] > a[q[j]]) swap(q[i], q[j]);     x = q[0], y = q[1], z = q[2];     if (x == y) {       add(x, y);       return;     }     if (y == z) {       add(y, z);       return;     }     int w = a[y] / a[x];     int tmp = w, up;     for (i = 0; tmp; ++i)       if ((tmp >> i) & 1) up = i, tmp ^= (1 << i);     for (i = 0; i <= up; ++i) {       if ((w >> i) & 1)         add(x, y);       else         add(x, z);     }     if (a[x] == 0 || a[y] == 0 || a[z] == 0)       return;     else       Solve(x, y, z);   }   int main() {     int n;     scanf( %d , &n);     register int i, j;     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     int last = 0;     for (i = 1; i <= n; ++i)       if (a[i]) ++last;     if (last < 2) {       puts( -1 );       return 0;     } else if (last == 2) {       puts( 0 );       return 0;     }     for (last -= 2; last--;) {       for (id = 0, i = 1; i <= n; ++i)         if (a[i]) seq[++id] = i;       Solve(seq[1], seq[2], seq[3]);     }     printf( %d n , qtes);     for (i = 1; i <= qtes; ++i) printf( %d %d n , u[i], v[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MAXN = 1e5 + 10;   const int MAXK = 5 + 1;   long long sumv[MAXK][MAXN << 2], setv[MAXN << 2];   long long prefix[MAXK][MAXN], C[MAXK][MAXK];   void Pushdown(int o, int lft, int rht) {     if (setv[o] != -1) {       setv[(o << 1)] = setv[(o << 1 | 1)] = setv[o];       int mid = lft + rht >> 1;       for (int k = 0; k < MAXK; ++k) {         sumv[k][(o << 1)] =             setv[(o << 1)] * (prefix[k][mid] - prefix[k][lft - 1] + mod) % mod;         sumv[k][(o << 1 | 1)] =             setv[(o << 1 | 1)] * (prefix[k][rht] - prefix[k][mid] + mod) % mod;       }       setv[o] = -1;     }   }   void Pushup(int o) {     for (int k = 0; k < MAXK; ++k)       sumv[k][o] = sumv[k][(o << 1)] + sumv[k][(o << 1 | 1)];   }   void Build(int o, int lft, int rht) {     if (lft == rht) {       scanf( %lld , setv + o);       sumv[0][o] = setv[o] % mod;       for (int k = 1; k < MAXK; ++k) sumv[k][o] = sumv[k - 1][o] * lft % mod;     } else {       int mid = lft + rht >> 1;       Build((o << 1), lft, mid);       Build((o << 1 | 1), mid + 1, rht);       Pushup(o);     }   }   int ul, ur, uv;   void Update(int o, int lft, int rht) {     if (ul <= lft and rht <= ur) {       setv[o] = uv;       for (int k = 0; k < MAXK; ++k)         sumv[k][o] = setv[o] * (prefix[k][rht] - prefix[k][lft - 1] + mod) % mod;     } else {       Pushdown(o, lft, rht);       int mid = lft + rht >> 1;       if (ul <= mid) Update((o << 1), lft, mid);       if (ur > mid) Update((o << 1 | 1), mid + 1, rht);       Pushup(o);     }   }   int ql, qr, qk;   long long Query(int o, int lft, int rht) {     if (ql <= lft and rht <= qr) return sumv[qk][o];     Pushdown(o, lft, rht);     int mid = lft + rht >> 1;     long long ans = 0;     if (ql <= mid) ans += Query((o << 1), lft, mid);     if (qr > mid) ans += Query((o << 1 | 1), mid + 1, rht);     return ans % mod;   }   void work() {     for (int i = 0; i < MAXK; ++i) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;     }     for (int i = 1; i < MAXN; ++i) {       long long u = 1;       for (int k = 0; k < MAXK; ++k) {         prefix[k][i] = (prefix[k][i - 1] + u) % mod;         u = u * i % mod;       }     }     int N, Q, K;     char cmd[20];     long long ans, ret;     scanf( %d%d , &N, &Q);     memset(setv, -1, sizeof setv);     Build(1, 1, N);     while (Q--) {       scanf( %s , cmd);       switch (cmd[0]) {         case  ? :           scanf( %d%d%d , &ql, &qr, &K);           ans = 0;           ret = 1;           for (qk = K; qk >= 0; --qk, ret = ret * (1 - ql) % mod)             ans += Query(1, 1, N) * (ret) % mod * C[K][qk] % mod;           printf( %lld n , (ans % mod + mod) % mod);           break;         case  = :           scanf( %d%d%d , &ul, &ur, &uv);           Update(1, 1, N);           break;       }     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   const int D = 510;   const int S = 5010;   bool dp[S][D];   pair<pii, int> prv[S][D];   queue<pii> q;   string reconstruct(int s, int r) {     if (prv[s][r].second == -1) return   ;     return reconstruct(prv[s][r].first.first, prv[s][r].first.second) +            char(prv[s][r].second +  0 );   }   int main() {     ios_base::sync_with_stdio(false);     int d, s;     cin >> d >> s;     memset(dp, 0, sizeof dp);     memset(prv, -1, sizeof prv);     q.push({0, 0});     dp[0][0] = true;     while (!q.empty()) {       int sd = q.front().first;       int r = q.front().second;       q.pop();       for (int dig = 0; dig < 10; ++dig) {         int newr = (r * 10 + dig) % d;         if (sd + dig > s) continue;         if (!dp[sd + dig][newr]) {           dp[sd + dig][newr] = true;           prv[sd + dig][newr] = {{sd, r}, dig};           q.push({sd + dig, newr});         }       }     }     if (!dp[s][0])       cout << -1 <<   n ;     else       cout << reconstruct(s, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, dst, cur;   int main() {     cin >> m >> n >> k;     dst = n + m + 34;     for (int i = 0; i < k; i++) {       cin >> x >> y;       cur = min(min(x - 1, y - 1), min(m - x, n - y));       dst = min(dst, cur);     }     if (dst < 5)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ceil(long long a, long long b) {     if (a % b == 0) return a / b;     return a / b + 1;   }   int main() {     long long n;     int q;     scanf( %lld %d , &n, &q);     for (int j = 0; (j) < int(q); (j)++) {       int x, y;       scanf( %d %d , &y, &x);       long long ans = 0;       int l = y - 1;       int m = l / 2;       if ((x + y) % 2 == 0) {         ans += ceil(n, 2) * (l - m) + (n / 2) * m;         ans += (y % 2 == 0 ? x : x + 1) / 2;       } else {         ans += ceil(n, 2) * m + (n / 2) * (l - m);         ans += (y % 2 == 0 ? x + 1 : x) / 2;         ans += ceil(n * n, 2);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, xian = (long long)1500000 * 1500000;   long long q[N], ans[N], n;   pair<long long, long long> a[N];   inline long long cal(pair<long long, long long> x) {     return x.first * x.first + x.second * x.second;   }   pair<long long, long long> solve(long long l, long long r) {     if (l == r) return a[q[l]];     long long mid = (l + r) >> 1;     while (1) {       random_shuffle(&q[l], &q[r + 1]);       pair<long long, long long> t1 = solve(l, mid), t2 = solve(mid + 1, r);       pair<long long, long long> t3 = make_pair(t1.first + t2.first,                                                 t1.second + t2.second),                                  t4 = make_pair(t1.first - t2.first,                                                 t1.second - t2.second);       pair<long long, long long> t = cal(t3) < cal(t4) ? t3 : t4;       if (cal(t) <= xian) return t;     }   }   pair<long long, long long> sol(long long l, long long r) {     if (l == r) return a[q[l]];     long long mid = (l + r) >> 1;     while (1) {       pair<long long, long long> t1 = sol(l, mid), t2 = sol(mid + 1, r);       pair<long long, long long> t3 = make_pair(t1.first + t2.first,                                                 t1.second + t2.second),                                  t4 = make_pair(t1.first - t2.first,                                                 t1.second - t2.second),                                  t;       if (cal(t3) < cal(t4))         t = t3;       else {         t = t4;         ans[mid + 1] *= -1;         ans[r + 1] *= -1;       }       if (cal(t) <= xian) return t;     }   }   long long an[N];   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i].first, &a[i].second);       q[i] = i;       ans[i] = 1;     }     solve(1, n);     sol(1, n);     ans[0] = 1;     for (long long i = 1; i <= n; i++) ans[i] *= ans[i - 1];     for (long long i = 1; i <= n; i++) an[q[i]] = ans[i];     for (long long i = 1; i <= n; i++)       if (an[i] == 1) {         putchar( 1 );         putchar(   );       } else {         putchar( - );         putchar( 1 );         putchar(   );       }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void gg(T &res) {     res = 0;     T fh = 1;     char ch = getchar();     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     res *= fh;   }   inline int gi() {     int x;     gg(x);     return x;   }   inline long long gl() {     long long x;     gg(x);     return x;   }   const int MAXN = 610;   const int MAXM = 200010;   const int INF = 1e9;   const int BIG = 1e7;   int bt = 1, b[MAXN], NEXT[MAXM], to[MAXM], val[MAXM];   inline void add(int x, int y, int z) {     NEXT[++bt] = b[x];     b[x] = bt;     to[bt] = y;     val[bt] = z;     NEXT[++bt] = b[y];     b[y] = bt;     to[bt] = x;     val[bt] = 0;   }   int T, dis[MAXN], q[MAXN];   bool fc() {     for (int i = 1; i <= T; i++) dis[i] = 0;     dis[0] = 1;     int l = 1, r = 0;     q[++r] = 0;     while (l <= r) {       int x = q[l++];       for (int i = b[x]; i; i = NEXT[i]) {         if (!val[i] || dis[to[i]]) continue;         dis[to[i]] = dis[x] + 1;         if (to[i] == T) return 1;         q[++r] = to[i];       }     }     return 0;   }   int dfs(int x, int M) {     if (x == T) return M;     int ans = 0;     for (int i = b[x]; i; i = NEXT[i]) {       if (!val[i] || dis[x] + 1 != dis[to[i]]) continue;       int r = dfs(to[i], min(val[i], M - ans));       val[i] -= r;       val[i ^ 1] += r;       if ((ans += r) == M) return ans;     }     dis[x] = -1;     return ans;   }   int main() {     int n = gi();     T = n + n + 1;     for (int i = 1; i <= n; i++)       for (int t = gi(); t--;) add(i, n + gi(), INF);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int x = BIG - gi();       ans -= x;       add(0, i, x);       add(n + i, T, BIG);     }     while (fc()) ans += dfs(0, INF);     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long INF = 1e12;   vector<long long> ans[200010];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) ans[i].push_back(-1);     ans[0][0] = a[0];     long long sz = 1;     for (long long i = 1; i < n; i++) {       long long l = -1, r = sz;       while (r - l > 1) {         long long mid = (l + r) / 2;         long long tmp = ans[mid][ans[mid].size() - 1];         if (tmp > a[i]) {           l = mid;         } else {           r = mid;         }       }       if (r == sz) {         ans[r][0] = a[i];         sz++;       } else {         ans[r].push_back(a[i]);       }     }     for (long long i = 0; i < sz; i++) {       for (long long ii = 0; ii < ans[i].size(); ii++) {         if (ii) cout <<    ;         cout << ans[i][ii];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   const int INF = 0x7ffffff;   const int MOD = 1e9 + 7;   int a[MAXN + 17], b[MAXN + 17], id[MAXN + 17];   bool cmp(int c, int d) { return a[c - 1] > a[d - 1]; }   int main() {     int n;     cin >> 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) id[i] = i + 1;     sort(id, id + n, cmp);     cout << n / 2 + 1 << endl;     cout << id[0] << endl;     if (!(n & 1)) cout << id[1] << endl;     int t = (n & 1) ? n / 2 : n / 2 - 1, j;     for (j = n - 1; t > 0; t--, j -= 2)       cout << (b[id[j] - 1] > b[id[j - 1] - 1] ? id[j] : id[j - 1]) <<    ;     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   const int N = 5e5 + 5;   using namespace std;   int n, m, k;   vector<int> build_kmp(string s, string t, bool check = false) {     vector<int> t_match(((int)t.size()) + 1, 0);     for (int i = (2); i <= (((int)t.size())); ++i) {       int c = t_match[i - 1];       while (c > 0 && t[c] != t[i - 1]) c = t_match[c];       if (t[c] == t[i - 1]) ++c;       t_match[i] = c;     }     vector<int> s_match(((int)s.size()) + 1, 0);     for (int i = (1); i <= (((int)s.size())); ++i) {       int c = s_match[i - 1];       while (c > 0 && t[c] != s[i - 1]) c = t_match[c];       if (t[c] == s[i - 1]) ++c;       if (c == m && check) {         int t = max(i, k);         if (n - t >= k && t - k + 1 <= i - m + 1) {           cout <<  Yes  << endl;           cout << t - k + 1 <<     << t + 1 << endl;           exit(0);         }         t = min(n - k, i - m);         if (t >= k && i <= t + k) {           cout <<  Yes  << endl;           cout << t - k + 1 <<     << t + 1 << endl;           exit(0);         }       }       s_match[i] = c;     }     vector<int> best(((int)t.size()) + 1, -1);     for (int i = (k); i <= (((int)s.size())); ++i) {       int c = s_match[i];       for (; best[c] == -1; c = t_match[c]) best[c] = i;     }     return best;   }   int main() {     string s, t;     cin >> n >> m >> k >> s >> t;     auto L = build_kmp(s, t, true);     reverse((s).begin(), (s).end());     reverse((t).begin(), (t).end());     auto R = build_kmp(s, t);     for (int i = (0); i <= (m); ++i)       if (R[i] != -1) R[i] = n - R[i] + 1;     for (int i = (0); i <= (m); ++i)       if (i <= k && m - i <= k && L[i] != -1 && R[m - i] != -1 &&           L[i] < R[m - i]) {         cout <<  Yes  << endl;         cout << L[i] - k + 1 <<     << R[m - i] << endl;         return 0;       }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   long long int INF = 1e18;   long long int power(long long int base, long long int exp) {     long long int res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base);       base = (base * base);       exp /= 2;     }     return res;   }   long long int bitc(long long int n, long long int x) { return ((n >> x) & 1); }   long long int __gcd(long long int a, long long int b) {     return b == 0 ? a : __gcd(b, a % b);   }   long long int fsub(long long int a, long long int b, long long int p = MOD) {     return ((a % p) - (b % p) + p) % p;   }   long long int fmult(long long int a, long long int b, long long int p = MOD) {     return ((a % p) * (b % p)) % p;   }   long long int fadd(long long int a, long long int b, long long int p = MOD) {     return (a % p + b % p) % p;   }   long long int fpow(long long int n, long long int k, long long int p = MOD) {     long long int r = 1;     while (k > 0) {       if (k & 1) r = r * n % p;       n = n * n % p;       k = k >> 1;     }     return r;   }   long long int inv(long long int a, long long int p = MOD) {     return fpow(a, p - 2, p);   }   long long int fdiv(long long int a, long long int b, long long int p = MOD) {     long long int yinv = inv(b);     long long int ans = (a * yinv) % p;     return ans;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &a) {     for (auto &item : a) {       in >> item;     }     return in;   }   template <typename T, typename U>   ostream &operator<<(ostream &out, pair<T, U> &a) {     cout << a.first <<     << a.second;     return out;   }   template <typename T, typename U>   istream &operator>>(istream &out, pair<T, U> &a) {     cin >> a.first >> a.second;     return out;   }   template <typename T, typename U>   ostream &operator<<(ostream &out, map<T, U> &a) {     for (auto &item : a) {       out << item <<   n ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> &a) {     for (auto &item : a) {       out << item <<    ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, vector<vector<T>> &a) {     for (auto &item : a) {       out << item <<   n ;     }     return out;   }   template <int D, typename T>   struct Vec : public vector<Vec<D - 1, T>> {     static_assert(D >= 1,  Vector dimension must be greater than zero! );     template <typename... Args>     Vec(int n = 0, Args... args)         : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}   };   template <typename T>   struct Vec<1, T> : public vector<T> {     Vec(int n = 0, T val = T()) : vector<T>(n, val) {}   };   std::vector<bool> is_prime;   std::vector<long long int> primes;   void sieve(long long int n) {     is_prime.resize(n + 2, true);     primes.clear();     long long int p;     for (p = 2; p * p <= n; p++) {       if (is_prime[p]) {         long long int i;         for (i = p * p; i <= n; i += p) {           is_prime[i] = false;         }       }     }     is_prime[0] = is_prime[1] = false;     long long int i;     for (i = 2; i <= n; i++) {       if (is_prime[i]) {         primes.emplace_back(i);       }     }   }   map<long long int, long long int> prime_factors(long long int n) {     map<long long int, long long int> s;     long long int i;     long long int tc = 0;     while (n % 2 == 0) {       tc++;       n /= 2;     }     if (tc > 0) {       s[2] = tc;     }     for (i = 3; i <= sqrt(n); i += 2) {       tc = 0;       while (n % i == 0) {         tc++;         n /= i;       }       if (tc > 0) {         s[i] = tc;       }     }     if (n > 2) {       s[n] += 1;     }     return s;   }   std::vector<long long int> fact_vec;   void fact_fun(long long int n) {     fact_vec.resize(n + 10);     long long int i;     fact_vec[0] = 1;     for (i = 1; i <= n + 2; i++) {       fact_vec[i] = (fact_vec[i - 1] * i) % MOD;     }   }   std::vector<long long int> p2;   void power_2(long long int n, long long int m = MOD) {     long long int i;     MOD = m;     p2.emplace_back(1);     for (i = 0; i < n; i++) {       p2.emplace_back(fmult(p2.back(), 2));     }   }   long long int ncr(long long int n, long long int r) {     if (r > n) return 0;     return fdiv(fact_vec[n], fmult(fact_vec[r], fact_vec[n - r]));   }   std::vector<long long int> spf;   void sieve2(long long int MAXN) {     MAXN += 10;     spf.resize(MAXN, 0);     spf[1] = 1;     for (long long int i = 2; i < MAXN; i++) spf[i] = i;     for (long long int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (long long int i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (long long int j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   std::vector<long long int> getFactorization(long long int x) {     std::vector<long long int> ret;     while (x != 1) {       ret.emplace_back(spf[x]);       x = x / spf[x];     }     return ret;   }   int main() {     long long int i, j;     ios::sync_with_stdio(false);     cin.tie(0);     long long int ti;     ti = 1;     while (ti--) {       long long int n, m;       cin >> n >> m;       Vec<2, long long int> mat(n + 2, m + 2), left, right, up, down, uvis, lvis,           vis;       uvis = lvis = vis = left = right = up = down = mat;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           char c;           cin >> c;           if (c ==  * ) {             mat[i][j] = 1;           }         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (mat[i][j] && mat[i][j - 1]) {             left[i][j] = left[i][j - 1] + 1;           }         }         for (j = m; j >= 1; j--) {           if (mat[i][j] && mat[i][j + 1]) {             right[i][j] = right[i][j + 1] + 1;           }         }       }       for (j = 1; j <= m; j++) {         for (i = 1; i <= n; i++) {           if (mat[i][j] && mat[i - 1][j]) {             up[i][j] = up[i - 1][j] + 1;           }         }         for (i = n; i >= 1; i--) {           if (mat[i][j] && mat[i + 1][j]) {             down[i][j] = down[i + 1][j] + 1;           }         }       }       vector<pair<pair<long long int, long long int>, long long int>> ans;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           std::vector<long long int> tv = {up[i][j], down[i][j], left[i][j],                                            right[i][j]};           long long int mn = *min_element((tv).begin(), (tv).end());           if (mn != 0) {             ans.emplace_back(make_pair(make_pair(i, j), mn));             long long int lr = j - mn;             long long int rr = j + mn + 1;             lvis[i][lr]++;             lvis[i][rr]--;             uvis[i - mn][j]++;             uvis[i + mn + 1][j]--;           }         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           vis[i][j] = lvis[i][j] + vis[i][j - 1];           if (mat[i][j] && vis[i][j] > 0) {             mat[i][j] = 0;           }         }       }       vis.clear();       vis.resize(n + 2, m + 2);       for (j = 1; j <= m; j++) {         for (i = 1; i <= n; i++) {           vis[i][j] = uvis[i][j] + vis[i - 1][j];           if (mat[i][j] && vis[i][j] > 0) {             mat[i][j] = 0;           }         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (mat[i][j]) {             cout << -1 <<   n ;             return 0;           }         }       }       cout << ans.size() <<   n ;       for (auto p : ans) {         cout << p.first.first <<     << p.first.second <<     << p.second <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(m);     int cnt = 0, ma = 0;     for (int i = 0; i < m; ++i) {       cin >> a[i];       cnt += a[i];       ma = max(ma, a[i]);     }     if (cnt < n || 2 * (cnt - ma) < n || (n % 2) && m <= 2) {       cout << -1 << endl;       return 0;     }     set<pair<int, int> > q;     vector<int> res;     for (int i = 0; i < n; ++i) {       int ma = 0, best = 0;       if (i && res[0] != res.back() && a[res[0]] && i + 1 < n) {         best = res[0];       } else {         for (int j = 0; j < m; ++j)           if (res.empty() || j != res.back())             if (i + 1 < n || res[0] != j) {               if (ma < a[j]) {                 ma = a[j];                 best = j;               }             }       }       res.push_back(best);       --a[best];     }     for (int i = 0; i < res.size(); ++i) printf( %d  , res[i] + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TC;     cin >> TC;     while (TC--) {       map<char, int> mp;       string s;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (mp[s[i]] <= 1) mp[s[i]]++;       }       int x1 = 0, x2 = 0;       for (auto i : mp) {         if (i.second == 2) x2++;         if (i.second == 1) x1++;       }       long long ans = (x1 / 2) + x2;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     setlocale(LC_ALL,  RUS );     double r;     cin >> r;     for (double x = 1; x <= 9; x++) {       double y = ((r - 1) / (2 * x)) - ((x + 1) / 2);       if (y == (long long)y && y > 0) {         cout << x <<     << fixed << setprecision(0) << y;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const long long MAXN = 600010;   const long long INF = 2147483600;   long long N, K;   struct data {     long long l, r, id;     bool operator<(const data &a) const {       if (a.l != l) return l < a.l;       return r < a.r;     }   } q[MAXN + 1];   vector<pair<long long, long long> > vec[MAXN + 1];   set<data>::iterator Ers[MAXN + 1];   set<data> S;   long long sum[MAXN + 1], kans, pans;   inline data mdata(long long l, long long r, long long id) {     data n;     n.l = l;     n.r = r;     n.id = id;     return n;   }   inline void check(long long x) {     long long nw = 1, sm = 0;     kans = 0;     pans = 0;     long long sumv = 0;     for (long long i = 1; i <= N; i++) sum[i] = 0;     for (long long i = 1; i <= N; i++) {       long long sumt = 0;       for (long long j = 0, sz = vec[i].size(); j < sz; j++) {         pair<long long, long long> k = vec[i][j];         sum[k.first] += k.second;         sumt += k.second;         if (k.first < nw) sm += k.second, sumv += k.second * (nw - k.first);       }       sum[i + 1] -= sumt;       pans += sumv;       while (nw <= i && sum[nw] + sm >= x)         sm += sum[nw], pans += sm, sumv += sm, ++nw;       kans += nw - 1;     }   }   long long top;   int main() {     N = read();     K = read();     for (long long i = 1; i <= N; i++) {       q[i].l = read(), q[i].r = read() - 1;       q[i].id = i;     }     for (long long i = 1; i <= N; i++) {       set<data>::iterator it = S.upper_bound(q[i]);       data l;       top = 0;       if (S.begin() != it) --it;       if (it == S.end())         l.l = INF;       else         l = (*it);       while (it != S.end()) {         if ((*it).r < q[i].l) {           ++it;           continue;         }         if ((*it).l > q[i].r) break;         Ers[++top] = it;         if ((*it).r >= q[i].r) break;         ++it;       }       data r;       r.r = -1;       if (it != S.end()) r = (*it);       long long last = q[i].l - 1;       for (long long j = 1; j <= top; j++) {         data x = (*Ers[j]);         long long lt = max(x.l, q[i].l), rt = min(x.r, q[i].r);         if (lt > rt) continue;         if (last + 1 != lt) vec[i].push_back(make_pair(1, lt - last - 1));         vec[i].push_back(make_pair(x.id + 1, rt - lt + 1));         last = rt;       }       if (last != q[i].r) vec[i].push_back(make_pair(1, q[i].r - last));       for (long long j = 1; j <= top; j++) S.erase(Ers[j]);       if (l.l < q[i].l && l.r >= q[i].l) S.insert(mdata(l.l, q[i].l - 1, l.id));       if (r.r > q[i].r && r.l <= q[i].r) S.insert(mdata(q[i].r + 1, r.r, r.id));       S.insert(q[i]);     }     long long l = 0, r = 1000000000;     long long ans = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       kans = 0;       check(mid);       if (kans < K)         ans = pans + (mid - 1) * (K - kans), r = mid - 1;       else         l = mid + 1;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int indexp = INT_MAX, indexr = INT_MAX;       int arr[n], brr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] == -1 and indexp == INT_MAX) indexp = i;         if (arr[i] == 1 and indexr == INT_MAX) indexr = i;       }       for (int i = 0; i < n; i++) {         cin >> brr[i];       }       int flag = 0;       for (int i = n - 1; i >= 0; i--) {         if (brr[i] == arr[i])           continue;         else {           if (brr[i] > arr[i]) {             if (i > indexr)               continue;             else {               flag = 1;               break;             }           } else {             if (i > indexp)               continue;             else {               flag = 1;               break;             }           }         }       }       if (flag == 1)         cout <<  NO               <<   n ;       else         cout <<  YES               <<   n ;     }     return (0);   }


#include <bits/stdc++.h>   long long num_div(long long x, long long limit) {     long long ans(0);     for (long long i = 1; i <= sqrt(x); ++i) {       if (!(x % i)) {         if (i > limit && i * i == x)           ans++;         else {           if (i > limit) ans++;           if (x / i > limit) ans++;         }       }     }     return ans;   }   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     if (n == m)       printf( infinity );     else       printf( %lld , n < m ? 0 : num_div(n - m, m));   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   int N;   vector<pair<int, int> > ans;   vector<int> E[maxn];   void go(int i, int t) { ans.push_back({i, t}); }   void dfs(int i, int p, int t) {     go(i, t);     int d = (t < E[i].size());     if (!d) t -= E[i].size(), go(i, t);     for (auto &j : E[i])       if (j != p) {         t++;         dfs(j, i, t);         go(i, t);         if (d && t == E[i].size()) t -= E[i].size(), go(i, t);       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> N;     int u, v;     for (int i = 1; i < N; i++) {       cin >> u >> v;       E[u].push_back(v);       E[v].push_back(u);     }     go(1, 0);     int t = 0;     for (auto &i : E[1]) t++, dfs(i, 1, t), go(1, t);     cout << ans.size() <<   n ;     for (auto &i : ans) cout << i.first <<     << i.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200000 + 5], b[200000 + 5], vis[200000 + 5];   int main() {     long long i, j, k;     long long n, m;     long long o = 0, minx = 10005, s = 0;     scanf( %I64d , &n);     for (i = 0; i < n; i++) {       scanf( %I64d , &m);       if (m % 2 == 0)         s += m;       else {         minx = min(minx, m);         s += m;         o++;       }     }     if (minx == 10005) {       cout << 0 << endl;       return 0;     }     if (o % 2)       cout << s << endl;     else       cout << s - minx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, k, i;       cin >> n >> k;       long long a[n], s = INT_MAX, l = INT_MIN;       for (i = 0; i < n; i++) {         cin >> a[i];         s = min(s, a[i]);         l = max(l, a[i]);       }       if (s + k >= l - k)         cout << s + k << endl;       else         cout <<  -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     list<unsigned long long int> blind;     list<unsigned long long int>::iterator bite, tempite;     unsigned long long int total, l, maxarea = 0, sum, i;     cin >> total >> l;     for (i = 0; i < total; ++i) {       cin >> sum;       if (sum >= l) blind.push_back(sum);     }     sum = 1;     while (sum != 0) {       sum = 0;       for (bite = blind.begin(); bite != blind.end();) {         if (*bite < l) {           tempite = bite;           ++bite;           blind.erase(tempite);         } else {           sum += *bite / l;           ++bite;         }       }       if (maxarea < l * sum) maxarea = l * sum;       ++l;     }     cout << maxarea;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100006];   vector<int> located[100006];   int parent[100006], level[100006], visited[100006];   int ancestor[100006][18];   vector<int> st[100006][18];   void dfs(int u) {     visited[u] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (visited[v] == 0) {         parent[v] = u;         level[v] = level[u] + 1;         dfs(v);       }     }   }   void merge(vector<int>& a, vector<int>& b) {     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<int> tmp;     int cnt = 0;     int l1 = a.size(), l2 = b.size();     int i = 0, j = 0;     while (i < l1 && j < l2 && cnt < 10) {       if (a[i] < b[j])         tmp.push_back(a[i++]);       else         tmp.push_back(b[j++]);       cnt++;     }     while (i < l1 && cnt < 10) {       tmp.push_back(a[i++]);       cnt++;     }     while (j < l2 && cnt < 10) {       tmp.push_back(b[j++]);       cnt++;     }     a.clear();     for (i = 0; i < cnt; i++) a.push_back(tmp[i]);   }   int main() {     int tc = 1;     for (int t = 1; t <= tc; t++) {       int n, m, q;       scanf( %d , &(n));       scanf( %d , &(m));       scanf( %d , &(q));       for (int j = 1; j < 18; j++) {         for (int i = 1; i <= n; i++) {           ancestor[i][j] = -1;         }       }       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d , &(u));         scanf( %d , &(v));         g[u].push_back(v);         g[v].push_back(u);       }       for (int i = 1; i <= m; i++) {         int tmp;         scanf( %d , &(tmp));         located[tmp].push_back(i);       }       parent[1] = -1;       level[1] = 1;       dfs(1);       for (int i = 1; i <= n; i++) ancestor[i][0] = parent[i];       for (int j = 1; j < 18; j++) {         for (int i = 1; i <= n; i++) {           if (ancestor[i][j - 1] != -1)             ancestor[i][j] = ancestor[ancestor[i][j - 1]][j - 1];         }       }       for (int i = 1; i <= n; i++) {         st[i][0] = located[i];         vector<int> vi;         merge(st[i][0], vi);       }       for (int j = 1; j < 18; j++) {         for (int i = 1; i <= n; i++) {           st[i][j] = st[i][j - 1];           if (ancestor[i][j - 1] == -1) continue;           merge(st[i][j], st[ancestor[i][j - 1]][j - 1]);         }       }       while (q--) {         int u, v, a;         scanf( %d , &(u));         scanf( %d , &(v));         scanf( %d , &(a));         if (level[u] < level[v]) {           int tmp = u;           u = v;           v = tmp;         }         vector<int> tmp;         for (int j = 17; j >= 0; j--) {           if (ancestor[u][j] != -1 && level[ancestor[u][j]] >= level[v]) {             merge(tmp, st[u][j]);             u = ancestor[u][j];           }         }         if (u != v) {           for (int j = 17; j >= 0; j--) {             if (ancestor[u][j] != -1 && ancestor[u][j] != ancestor[v][j]) {               merge(tmp, st[u][j]);               merge(tmp, st[v][j]);               u = ancestor[u][j];               v = ancestor[v][j];             }           }           merge(tmp, st[u][0]);           merge(tmp, st[v][0]);           u = parent[u];           v = parent[v];         }         merge(tmp, st[u][0]);         int cnt = 0;         int len = tmp.size();         cout << min(a, len);         for (int it = 0; it < tmp.size() && cnt < a; it++, cnt++) {           printf(   );           printf( %d , (tmp[it]));         }         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double i, j, h, l, num;     cin >> h >> l;     num = (l * l - h * h) / (2 * h);     cout << (fixed) << setprecision(12) << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long b, q, l, m, a[N];   map<long long, int> vis;   int main() {     scanf( %lld%lld%lld%lld , &b, &q, &l, &m);     while (m--) {       long long x;       scanf( %lld , &x);       vis[x] = 1;     }     if (max(-b, b) > l) {       printf( 0 n );     } else if (b == 0) {       if (vis.count(b) == 0)         printf( inf n );       else         printf( 0 n );     } else {       if (q == 0) {         if (vis.count(0) == 0) {           printf( inf n );         } else {           printf( %d n , !vis.count(b));         }       } else if (q == 1) {         if (vis.count(b) == 0)           printf( inf n );         else           printf( 0 n );       } else if (q == -1) {         if (vis.count(b) == 0 || vis.count(-b) == 0)           printf( inf n );         else           printf( 0 n );       } else {         int ans = 0;         while (max(-b, b) <= l) {           if (vis.count(b) == 0) ans++;           b *= q;         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100001];   int res[100001];   vector<vector<pair<int, int> > > g(1e5 + 2);   int check(int v) {     if (dp[v]) {       return dp[v];     }     dp[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       int nxt = g[v][i].first;       if (check(nxt) + 1 > dp[v]) {         dp[v] = dp[nxt] + 1;         res[v] = max(res[nxt], g[v][i].second);       }     }     return dp[v];   }   int main() {     int n, m, v, v1;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> v >> v1;       g[--v].push_back({--v1, i + 1});     }     for (int i = 0; i < n; i++) {       if (check(i) == n) {         cout << res[i];         return 0;       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   int a[N];   int vis[N];   int sum[4 * N];   void up(int id, int l, int r, int pos, int val) {     if (l == r) {       sum[id] = val;       return;     }     int mid = l + r >> 1;     if (pos <= mid)       up(id << 1, l, mid, pos, val);     else       up(id << 1 | 1, mid + 1, r, pos, val);     sum[id] = max(sum[id << 1], sum[id << 1 | 1]);   }   int qu(int id, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return sum[id];     int mx = 0;     int mid = l + r >> 1;     if (ql <= mid) mx = max(mx, qu(id << 1, l, mid, ql, qr));     if (qr > mid) mx = max(mx, qu(id << 1 | 1, mid + 1, r, ql, qr));     return mx;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= (n); ++i) cin >> a[i];     int q;     cin >> q;     int h;     int le = 0;     int pre = 0;     for (int i = 1; i <= q; ++i) {       int ty;       cin >> ty;       if (ty == 1) {         int pos, val;         cin >> pos >> val;         vis[pos] = i;         a[pos] = val;       } else {         cin >> h;         up(1, 1, q, i, h);       }     }     for (int i = 1; i <= (n); ++i) {       int le = qu(1, 1, q, vis[i], q);       if (le > a[i])         printf( %d  , le);       else         printf( %d  , a[i]);     }   }


#include <bits/stdc++.h>   int main() {     long long count, number;     long long Totalnumber = 200001;     std::vector<long long> Calresult(Totalnumber);     Calresult[2] = 1;     for (long long i = 3; i <= Totalnumber; i++) {       Calresult[i] = Calresult[i - 1] % 1000000007 * i % 1000000007;     }     std::cin >> count;     while (count--) {       std::cin >> number;       std::cout << Calresult[number * 2] << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2500 + 5;   int n, a[maxn][maxn];   int tot;   struct Data {     int x, y, z;     bool operator<(const Data &a) const { return z < a.z; }   } b[maxn * maxn];   bitset<2505> bt[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         scanf( %d , &a[i][j]), b[++tot] = (Data){i, j, a[i][j]};     for (int i = 1; i <= n; ++i)       if (a[i][i]) puts( NOT MAGIC ), exit(0);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j)         if (a[i][j] != a[j][i]) puts( NOT MAGIC ), exit(0);     sort(b + 1, b + 1 + tot);     for (int i = 1, p = 1; i <= tot; i = p) {       while (b[p].z == b[i].z && p <= tot) {         int x = b[p].x, y = b[p].y;         if ((bt[x] & bt[y]).count()) puts( NOT MAGIC ), exit(0);         p++;       }       for (int j = i; j < p; ++j) bt[b[j].x][b[j].y] = 1;     }     puts( MAGIC );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isValid(string& x, string& y) {     int found = y.find(x);     if (found == string::npos) return false;     for (int i = 0; i < found; ++i) {       if (y[i] ==  0 ) return false;     }     for (int i = found + x.length(); i < y.length(); ++i) {       if (y[i] ==  0 ) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     unsigned long long x, y;     cin >> x >> y;     bitset<64> b1(x);     bitset<64> b2(y);     string xString = b1.to_string();     string yString = b2.to_string();     int index = 0;     while (xString[index] ==  0 ) {       index++;     }     xString = xString.substr(index);     index = 0;     while (yString[index] ==  0 ) {       index++;     }     yString = yString.substr(index);     if (isValid(xString, yString)) {       int temp = yString.find(xString);       if (temp != 0 && xString.back() ==  0  &&           temp + xString.length() == yString.length()) {       } else {         cout <<  YES n ;         return 0;       }     }     index = -1;     for (int i = 0; i < xString.length(); ++i)       if (xString[i] ==  1 ) index = i;     string xNoTrailing = xString.substr(0, index + 1);     if (isValid(xNoTrailing, yString)) {       cout <<  YES n ;       return 0;     }     reverse(xNoTrailing.begin(), xNoTrailing.end());     if (isValid(xNoTrailing, yString)) {       cout <<  YES n ;       return 0;     }     xString.push_back( 1 );     reverse(xString.begin(), xString.end());     if (isValid(xString, yString)) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int y[3], m[3], p[3];   int result;   bool solve(int);   bool if_win(int, int, int);   int main() {     double lb = 0, ub = 0xffffff;     result = 0xfffffff;     scanf( %d%d%d , &y[0], &y[1], &y[2]);     scanf( %d%d%d , &m[0], &m[1], &m[2]);     scanf( %d%d%d , &p[0], &p[1], &p[2]);     if (if_win(0, 0, 0)) {       printf( %d n , 0);       return 0;     }     for (int i = 0; i < 100; i++) {       int mid = (int)((lb + ub) / 2 + 0.5);       if (solve(mid))         ub = mid;       else         lb = mid;       if (lb == ub || ub - lb == 1) break;     }     printf( %d n , result);     return 0;   }   bool solve(int x) {     int i;     int j;     int z;     for (i = x / p[0]; i >= 0; i--) {       for (j = (x - i * p[0]) / p[1]; j >= 0; j--) {         if (y[1] + j < m[2]) break;         for (z = (x - i * p[0] - j * p[1]) / p[2]; z >= 0; z--) {           int prise = p[0] * i + p[1] * j + p[2] * z;           if (if_win(i, j, z)) {             result = min(result, prise);             return true;           }         }       }     }     return false;   }   bool if_win(int i, int j, int z) {     if (y[1] + j <= m[2]) return false;     int time = m[0] / (y[1] + j - m[2]);     if (m[0] % (y[1] + j - m[2]) != 0) time++;     if (y[0] + i - time * (m[1] - y[2] - z) > 0)       return true;     else       return false;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, l;   const int mo = 1e9 + 7;   const int inv3 = 333333336;   int a[202020];   int b[202020];   int c[202020];   int sum[202020];   int sum2[202020];   long long gcd_ex(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return 1ll * a;     }     long long d = gcd_ex(b, a % b, y, x);     y = y - a / b * x;     return d;   }   long long solve(long long a, long long b, long long m) {     long long x, y;     long long d = gcd_ex(a, m, x, y);     if (b % d == 0) {       x %= m;       while (x < 0) x += m;       x %= m;       return x * (b / d) % (m / d);     } else {       return m;     }   }   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     cin >> n >> m;     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       sum[i] = (sum[i - 1] + a[i]) % mo;       sum2[i] = (sum2[i - 1] + (1ll * (a[i]) * (a[i]) % mo)) % mo;       b[i] = a[i];       c[i] = i;     }     sort(b + 1, b + n + 1);     sort(c + 1, c + n + 1, cmp);     int r, d, x;     long long aa, ab, ba, bb, mm, ssr, sp, sr;     for (register int i = 1; i <= m; ++i) {       scanf( %d %d %d , &l, &r, &d);       s = r - l + 1;       aa = 1ll * s;       ab = (0ll + mo + sum[r] - sum[l - 1]) % mo;       ba = (1ll * ((1ll * s * (s - 1) / 2) % mo) * d) % mo;       bb = (ab + mo - ba) % mo;       mm = 1ll * mo;       x = solve(aa, bb, mm);       if (b[lower_bound(b + 1, b + n + 1, x) - b] != x) {         printf( No n );         continue;       }       x = c[lower_bound(b + 1, b + n + 1, x) - b];       if (x < l && r < x) {         printf( No n );         continue;       }       x = a[x];       ssr = (0ll + mo + sum2[r] - sum2[l - 1]) % mo;       sr = ((2ll * ba) % mo * x) % mo;       sp = (1ll * ((1ll * (1ll * ba * (2ll * s - 1) % mo) * inv3) % mo) * d) % mo;       sp = (0ll + 1ll * s * (1ll * (x) * (x) % mo) % mo + sp + sr) % mo;       if (ssr != sp) {         printf( No n );         continue;       }       printf( Yes n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int maxn = 10000;   bool is_prime(int x) {     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) return 0;     }     if (x < 2) return 0;     return 1;   }   int main() {     int cc, n;     cin >> cc >> n;     vector<int> a(n);     for (int i = 0; i < cc; i++) {       int x;       cin >> x;       x--;       a[x]++;     }     vector<std::vector<int> > dp(3, std::vector<int>(3, 0));     for (int i = 0; i < n; i++) {       int c = a[i];       vector<std::vector<int> > new_dp(3, std::vector<int>(3, 0));       for (int x = 0; x < 3; x++) {         for (int y = 0; y < 3; y++) {           for (int z = 0; z < 3; z++) {             if (x + y + z <= c) {               new_dp[y][z] =                   max(new_dp[y][z], dp[x][y] + z + (c - x - y - z) / 3);             }           }         }       }       swap(dp, new_dp);     }     cout << dp[0][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (auto &i : a) cin >> i;     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     int ans = INT_MAX, base;     for (int i = 1; i <= 1000; i++) {       int first = i, curr = 0;       for (int j = 0; j < n; j++)         if (a[j] != first + j * k) curr++;       if (curr < ans) base = i, ans = curr;     }     cout << ans <<   n ;     for (int j = 0; j < n; j++) {       int now = base + j * k;       if (a[j] < now)         cout <<  +   << j + 1 <<     << now - a[j] <<   n ;       else if (a[j] > now)         cout <<  -   << j + 1 <<     << a[j] - now <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> a(4 * n);       for (int i = 0; i < 4 * n; i++) cin >> a[i];       sort(a.begin(), a.end());       int area = a[0] * a[4 * n - 1];       int temp = 0;       for (int i = 1; i <= n; i++) {         if ((a[2 * i - 2] != a[2 * i - 1]) ||             (a[4 * n - 2 * i] != a[4 * n - 2 * i + 1]) ||             (a[2 * i - 1 - 1] * a[4 * n - 2 * i + 1] != area)) {           temp = 1;           break;         }       }       if (temp == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using ll = long long;   void solve() {     string s;     cin >> s;     int m = ((int)(s).size());     vi a(m);     a[0] = ((s[0] ==  - ) ? -1 : 1);     for (__typeof(m) i = (1) - ((1) > (m)); i != (m) - ((1) > (m));          i += 1 - 2 * ((1) > (m))) {       if (s[i] ==  - ) {         a[i] = a[i - 1] - 1;       } else {         a[i] = a[i - 1] + 1;       }     }     ll res = m;     int i = 0, t = -1;     while (i < m) {       if (a[i] != t) {         i++;       } else {         t--;         res += (i + 1);       }     }     cout << res <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 100010;   int N;   int A[MAXN];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> N;     for (int i = 0; i < N; i++) {       cin >> A[i];     }     ll ans = 0;     for (int i = 0; i < N; i++) {       ans += ll(A[i]) * (N + 1 - A[i]);     }     for (int i = 0; i < N - 1; i++) {       ans -= ll(min(A[i], A[i + 1])) * (N + 1 - max(A[i], A[i + 1]));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[101];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, cnt = 0;       scanf( %d , &n);       for (int i = 1; i <= n; i *= 2) {         ans[++cnt] = i;         n -= i;       }       if (n > 0) {         ans[++cnt] = n;         sort(ans + 1, ans + cnt + 1);       }       printf( %d n , cnt - 1);       for (int i = 2; i <= cnt; i++) printf( %d  , ans[i] - ans[i - 1]);       printf(  n );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ans = 0, fh = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + ch -  0 , ch = getchar();     return ans * fh;   }   const int maxn = 2e5 + 100;   const long long inf = 1e18;   int n, m, head[maxn], nex[maxn], v[maxn], num = 1;   long long p[maxn << 2], la[maxn << 2];   long long a[maxn], b[maxn], w[maxn];   inline void updata(int o) { p[o] = min(p[o << 1], p[o << 1 | 1]); }   inline void pushdown(int o) {     if (!la[o]) return;     p[o << 1] += la[o], p[o << 1 | 1] += la[o];     la[o << 1] += la[o], la[o << 1 | 1] += la[o];     la[o] = 0;   }   void revise(int o, int l, int r, int ql, int qr, long long qz) {     if (ql == l && qr == r) {       p[o] += qz, la[o] += qz;       return;     }     int mid = l + r >> 1;     pushdown(o);     if (ql <= mid) revise(o << 1, l, mid, ql, min(qr, mid), qz);     if (qr > mid) revise(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr, qz);     updata(o);   }   long long query(int o, int l, int r, int ql, int qr) {     if (ql == l && qr == r) return p[o];     int mid = l + r >> 1;     pushdown(o);     long long ans = inf;     if (ql <= mid) ans = query(o << 1, l, mid, ql, min(qr, mid));     if (qr > mid)       ans = min(ans, query(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr));     return ans;   }   void build(int o, int l, int r) {     la[o] = 0;     if (l == r) {       p[o] = b[l];       return;     }     int mid = l + r >> 1;     build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);     updata(o);   }   inline void add(int x, int y, long long z) {     v[++num] = y;     w[num] = z;     nex[num] = head[x];     head[x] = num;   }   int main() {     n = read(), m = read();     int T = read();     for (int i = 1; i < n; i++) a[i] = read(), b[i] = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       add(x, y, read());     }     build(1, 0, n - 1);     for (int x = 1; x <= n; x++) {       for (int i = head[x]; i; i = nex[i]) revise(1, 0, n - 1, 0, v[i] - 1, w[i]);       b[x] = a[x] + p[1];     }     build(1, 1, n);     printf( %I64d n , p[1]);     while (T--) {       int x = read(), y = read();       revise(1, 1, n, x, x, y - a[x]), a[x] = y;       printf( %I64d n , p[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ReadInt() {     int t;     cin >> t;     return t;   }   long long ReadLong() {     long long t;     cin >> t;     return t;   }   int Vis[101][101];   vector<pair<int, int> > Road;   int main() {     int n, m;     cin >> n >> m;     if (m % 2 == 0 || n % 2 == 0) {       if ((n % 2 == 0 && m % 2 != 0 && m != 1) || (n == 2 && m == 1)) {         cout << 0 <<   n ;         int x = 1, y = 1;         Road.push_back({x, y});         Vis[x][y] = 1;         while (1) {           if (x + 1 <= n && !Vis[x + 1][y]) {             x++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y + 1 <= m && !Vis[x][y + 1]) {             y++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y - 1 > 0 && !Vis[x][y - 1]) {             y--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (x - 1 > 0 && !Vis[x - 1][y]) {             x--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else {             Road.push_back({1, 1});             break;           }         }         for (int i = 0; i < Road.size(); i++)           cout << Road[i].first <<     << Road[i].second <<   n ;       } else if ((m % 2 == 0 && n != 1) || (n == 1 && m == 2)) {         cout << 0 <<   n ;         int x = 1, y = 1;         Road.push_back({x, y});         Vis[x][y] = 1;         while (1) {           if (x + 1 <= n && !Vis[x + 1][y]) {             x++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y + 1 <= m && !Vis[x][y + 1]) {             y++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (x - 1 > 0 && !Vis[x - 1][y]) {             x--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y - 1 > 0 && !Vis[x][y - 1]) {             y--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else {             Road.push_back({1, 1});             break;           }         }         for (int i = 0; i < Road.size(); i++)           cout << Road[i].first <<     << Road[i].second <<   n ;       } else {         cout << 1 <<   n ;         int x = 1, y = 1;         Road.push_back({x, y});         Vis[x][y] = 1;         while (1) {           if (x + 1 <= n && !Vis[x + 1][y]) {             x++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y + 1 <= m && !Vis[x][y + 1]) {             y++;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (x - 1 > 0 && !Vis[x - 1][y]) {             x--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else if (y - 1 > 0 && !Vis[x][y - 1]) {             y--;             Road.push_back({x, y});             Vis[x][y] = 1;           } else {             cout << x <<     << y <<     << 1 <<     << 1 <<   n ;             break;           }         }         for (int i = 0; i < Road.size(); i++)           cout << Road[i].first <<     << Road[i].second <<   n ;         cout << 1 <<     << 1 <<   n ;       }     } else {       cout << 1 <<   n ;       int x = 1, y = 1;       Road.push_back({x, y});       Vis[x][y] = 1;       while (1) {         if (x + 1 <= n && !Vis[x + 1][y]) {           x++;           Road.push_back({x, y});           Vis[x][y] = 1;         } else if (y + 1 <= m && !Vis[x][y + 1]) {           y++;           Road.push_back({x, y});           Vis[x][y] = 1;         } else if (x - 1 > 0 && !Vis[x - 1][y]) {           x--;           Road.push_back({x, y});           Vis[x][y] = 1;         } else if (y - 1 > 0 && !Vis[x][y - 1]) {           y--;           Road.push_back({x, y});           Vis[x][y] = 1;         } else {           cout << x <<     << y <<     << 1 <<     << 1 <<   n ;           break;         }       }       for (int i = 0; i < Road.size(); i++)         cout << Road[i].first <<     << Road[i].second <<   n ;       cout << 1 <<     << 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int num = pow(10, 9) + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int c[n];     for (int i = 0; i < n; ++i) {       cin >> c[i];     }     long long int max_diff = -1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; j++) {         if (abs(c[i] - c[j]) > max_diff) max_diff = abs(c[i] - c[j]);       }     }     if (max_diff > k) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       for (int i = 0; i < n; ++i) {         for (int j = 1; j <= c[i]; j++) {           if (j % k == 0)             cout << k <<    ;           else             cout << j % k <<    ;         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 100;   vector<int> g[N];   vector<pair<int, int> > G[N];   map<int, long long> vToMinCost[N];   multiset<long long> costs[N];   long long addToAll[N];   int ansAt[N];   void upd(int id, int v, long long x) {     x -= addToAll[id];     if (vToMinCost[id].count(v) == 0 || vToMinCost[id][v] > x) {       if (vToMinCost[id].count(v) != 0)         costs[id].erase(costs[id].find(vToMinCost[id][v]));       vToMinCost[id][v] = x;       costs[id].insert(x);     }   }   void del(int id, int v) {     if (vToMinCost[id].count(v)) {       costs[id].erase(costs[id].find(vToMinCost[id][v]));       vToMinCost[id].erase(v);     }   }   void solve(int v, int par) {     ansAt[v] = v;     for (auto p : G[v]) upd(v, p.first, p.second);     for (int to : g[v]) {       if (to == par) continue;       solve(to, v);       int a = ansAt[v], b = ansAt[to];       if (vToMinCost[a].size() < vToMinCost[b].size()) swap(a, b);       del(a, to);       del(b, to);       if (vToMinCost[a].empty() || vToMinCost[b].empty()) {         printf( -1 n );         exit(0);       }       long long mn = *costs[b].begin() + addToAll[b];       long long mna = *costs[a].begin() + addToAll[a];       addToAll[a] += mn;       addToAll[b] += mna;       for (auto p : vToMinCost[b]) upd(a, p.first, p.second + addToAll[b]);       ansAt[v] = a;     }   }   int main(int, char **) {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++) G[i].push_back(make_pair(i, 0));     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       G[a].push_back(make_pair(b, c));     }     solve(0, -1);     int id = ansAt[0];     long long ans = *costs[id].begin() + addToAll[id];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, qu, f[100005], v[100005 + 100005], o[100005 + 100005], p, s[100005],       r, fr[100005], to[100005], si[100005], curm, grp[100005], gr, rt[100005];   bool u[100005], vis[100005];   vector<int> b[100005], c[100005], q[100005], ans[100005];   void bd(int a, int b) {     v[++p] = b;     o[p] = f[a];     f[a] = p;   }   void merge(vector<int> &a, vector<int> b) {     vector<int> c;     int l = 0, r = 0;     while (l < a.size() || r < b.size()) {       if (l == a.size())         c.push_back(b[r++]);       else if (r == b.size())         c.push_back(a[l++]);       else if (a[l] < b[r])         c.push_back(a[l++]);       else         c.push_back(b[r++]);     }     a = c;     if (a.size() > 11) a.resize(11);   }   void size(int x, int y) {     s[x] = vis[x] = 1;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) {         size(v[i], x);         s[x] += s[v[i]];       }   }   void pick(int x, int y, int z) {     int m = s[z] - s[x];     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) {         pick(v[i], x, z);         m = max(m, s[v[i]]);       }     if (m < curm) {       curm = m;       r = x;     }   }   void group(int x, int y, int z) {     grp[x] = z;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) group(v[i], x, z);   }   void dfs(int x, int y) {     c[x] = c[y];     merge(c[x], b[x]);     for (int i = (0); i < (q[x].size()); i++) {       int d = q[x][i];       if (vis[fr[d]] && vis[to[d]] && grp[fr[d]] != grp[to[d]]) {         merge(ans[d], c[x]);         rt[d] = r;       }     }     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) dfs(v[i], x);   }   void reset(int x, int y) {     vis[x] = 0;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) reset(v[i], x);   }   void root(int x) {     size(x, 0);     curm = 100005;     pick(x, 0, x);     grp[r] = 0;     gr = 1;     u[r] = 1;     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) group(v[i], r, gr++);     for (int i = (0); i < (q[r].size()); i++) {       int d = q[r][i];       if (vis[fr[d]] && vis[to[d]]) rt[d] = r;     }     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) dfs(v[i], 0);     reset(r, 0);     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) root(v[i]);   }   int main() {     scanf( %d %d %d , &n, &m, &qu);     for (int i = (1); i < (n); i++) {       int a, b;       scanf( %d %d , &a, &b);       bd(a, b);       bd(b, a);     }     for (int i = (1); i <= (m); i++) {       int t;       scanf( %d , &t);       b[t].push_back(i);     }     for (int i = (1); i <= (n); i++)       if (b[i].size() > 11) b[i].resize(11);     for (int i = (1); i <= (qu); i++) {       scanf( %d %d %d , &fr[i], &to[i], &si[i]);       q[fr[i]].push_back(i);       q[to[i]].push_back(i);     }     root(1);     for (int i = (1); i <= (qu); i++) {       merge(ans[i], b[rt[i]]);       if (ans[i].size() > si[i]) ans[i].resize(si[i]);       printf( %d , ans[i].size());       for (int j = (0); j < (ans[i].size()); j++) printf(  %d , ans[i][j]);       puts(  );     }     scanf(  n );   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, l, r, s, t;   long long modpow(long long x, long long y) {     if (y == 0) return 1 % 1000000009;     long long u = modpow(x, y / 2);     u = u * u % 1000000009;     if (y % 2) u = u * x % 1000000009;     return u;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     l = (n / k) * (k - 1) + n % k;     r = m - l;     if (r <= 0) {       cout << m << endl;       return 0;     }     s = m - r * (k);     if (s <= 0) s = 0;     t = modpow(2, r + 1);     t = (t + 1000000009 - 2) % 1000000009;     t = t * k % 1000000009;     s = s + t;     cout << s % 1000000009 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool is_prime(long long n) {     if (n == 2) return true;     if (n < 2) return false;     for (long long i = 3; i * i <= n; ++i)       if (!(n % i)) return false;     return true;   }   vector<long long> divison(long long n) {     vector<long long> v;     for (long long i = 1; i * i <= n; ++i)       if (!(n % i)) v.push_back(i), v.push_back(n / i);     return v;   }   void printnumberinbinary(unsigned long long t) {     if (!t) return;     printnumberinbinary(t >> 1);     cout << (t & 1);   }   int numberofdiv(int t) {     int ans = 0, x;     for (x = 1; x * x < t; x++) {       if (!(t % x)) ans += 2;     }     if (x * x == t) ans++;     return ans;   }   vector<set<int>> adj(1e5 + 1);   vector<bool> vis(1e5 + 1);   void dfs(int t) {     cout << t <<    ;     vis[t] = true;     for (auto f : adj[t])       if (!vis[f]) dfs(f);   }   int main() {     int t;     cin >> t;     while (t--) {       int a, y = 0;       cin >> a;       vector<int> v(a + 1, 0);       for (int x = 0; x < a; x++) {         int s;         cin >> s;         int flag = 0;         while (s--) {           int y;           cin >> y;           if (!v[y] && !flag) {             v[y]++;             flag++;           }         }         if (!flag) y = x + 1;       }       if (!y)         cout <<  OPTIMAL ;       else {         cout <<  IMPROVE n ;         for (int x = 1; x < v.size(); x++) {           if (!v[x]) {             cout << y <<     << x;             break;           }         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   bool w, w1;   int main() {     srand(time(NULL));     int n, m, mn, mx;     cin >> n >> m >> mn >> mx;     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       if (mn > x || mx < x) cout <<  Incorrect , exit(0);       if (x == mn) w = true;       if (x == mx) w1 = true;     }     if (w && w1) cout <<  Correct , exit(0);     if (w || w1)       if (n - m > 0)         cout <<  Correct , exit(0);       else         cout <<  Incorrect , exit(0);     if (n - m > 1)       cout <<  Correct , exit(0);     else       cout <<  Incorrect , exit(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   int n, a[N][N];   char s[N];   bool vis[N];   void dfs(int x, int fa) {     vis[x] = 1;     for (int i = 1; i <= n; i++) {       if (!a[x][i] || i == fa || i == x) continue;       if (a[i][fa]) printf( %d %d %d n , x, i, fa), exit(0);       if (!vis[i]) dfs(i, x);     }   }   signed main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n; j++) a[i][j] = s[j] -  0 ;     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     if (arr[n - 1] < arr[n - 2] + arr[n - 3]) {       cout <<  YES  << endl;       for (int i = 0; i < n - 2; i++) {         cout << arr[i] <<    ;       }       cout << arr[n - 1] <<     << arr[n - 2];     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   int main() {     int n, m;     int r = 0, a = 0, v = 0;     double es = 0.0;     scanf( %d%d , &n, &m);     r = 2 * n;     v = 5 * n;     a = 8 * n;     es = (double)r / m;     r = r / m;     if (es - r != 0.00) {       r++;     }     es = (double)v / m;     v = v / m;     if (es - v != 0.00) {       v++;     }     es = (double)a / m;     a = a / m;     if (es - a != 0.00) {       a++;     }     printf( %d , a + v + r);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9;   int n, a[N6], ans;   bool ok;   int main() {     ios_base ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       if (!a[i]) {         int cnt = 0;         while (!a[i] && i <= n) {           ++i;           ++cnt;         }         if ((cnt == 1 && !ok) || (cnt > 1) || (i > n && cnt == 1)) ans += cnt;       }       if (a[i]) ok = 1;     }     cout << abs(n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       int k;       cin >> n >> k;       int octr = 0;       int a[n];       int sum = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] % 2 != 0) octr++;         sum = sum + a[i];       }       if (octr >= k) {         if ((sum % 2 != 0 && k % 2 != 0) || (sum % 2 == 0 && k % 2 == 0)) {           cout <<  YES  << endl;           int f = 0;           while (k > 1) {             if (a[f] % 2 != 0) {               cout << f + 1 <<    ;               k--;             }             f++;           }           cout << n <<    ;           cout << endl;         } else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int llINF = (long long)(1e18) + 100;   const long long int MAXN = 1e6 + 10;   int lp[MAXN];   vector<int> pr;   void crivo() {     for (long long int i = 2; i < MAXN; i++) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (long long int j = 0;            j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN; ++j)         lp[i * pr[j]] = pr[j];     }   }   int n, dist[MAXN];   vector<int> adj[MAXN], dcp[MAXN];   vector<pair<int, int> > edge;   int other(int idx, int u) {     return edge[idx].first == u ? edge[idx].second : edge[idx].first;   }   int bfs(int p) {     memset(dist, 0, sizeof(dist));     queue<pair<int, int> > fila;     for (int x : adj[p]) {       fila.push({x, other(x, p)});       dist[other(x, p)] = 1;     }     int u, v, ans = INF;     pair<int, int> aux;     while (!fila.empty()) {       aux = fila.front();       fila.pop();       u = aux.second;       for (int w : adj[u]) {         if (w != aux.first) {           v = other(w, u);           if (dist[v] == 0 and v != p) {             fila.push({w, v});             dist[v] = dist[u] + 1;           } else             ans = min(ans, dist[u] + dist[v] + 1);         }       }     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     crivo();     lp[1] = 1;     cin >> n;     for (int i = 2; i < MAXN; i++) {       dcp[i] = dcp[i / lp[i]];       auto it = find(dcp[i].begin(), dcp[i].end(), lp[i]);       if (it != dcp[i].end())         dcp[i].erase(it);       else         dcp[i].push_back(lp[i]);     }     int a;     for (int i = 0; i < n; i++) {       cin >> a;       if (dcp[a].empty()) {         cout << 1 <<   n ;         return 0;       }       if (dcp[a].size() == 1) dcp[a].push_back(1);       edge.push_back({dcp[a][0], dcp[a][1]});       adj[dcp[a][0]].push_back(i);       adj[dcp[a][1]].push_back(i);     }     int ans = INF;     pr.insert(pr.begin(), 1);     for (int p : pr) {       if (p * p > MAXN) break;       ans = min(ans, bfs(p));     }     cout << (ans == INF ? -1 : ans) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct obj {     int id;     int f, t;     obj(int a, int b, int c) {       id = a;       f = b;       t = c;     }   };   bool cmpup(obj a, obj b) {     if (a.f == b.f) {       return a.id > b.id;     }     return a.f < b.f;   }   bool cmpdown(obj a, obj b) {     if (a.f == b.f) {       return a.id < b.id;     }     return a.f > b.f;   }   int n;   vector<obj> up;   vector<obj> down;   int a[105], d[105];   int now[105];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i], &d[i]);       now[i] = a[i];       if (d[i] > 0)         up.push_back(obj(i, a[i], a[i] + d[i]));       else if (d[i] < 0)         down.push_back(obj(i, a[i], a[i] + d[i]));     }     sort(up.begin(), up.end(), cmpup);     sort(down.begin(), down.end(), cmpdown);     int ans = 0;     for (int i = 0; i < up.size(); i++) {       for (int j = 0; j < n; j++) {         if (j == up[i].id) continue;         if (now[j] < up[i].f || now[j] > up[i].t) continue;         if (now[j] == up[i].f) {           if (j < up[i].id) ans++;         } else if (now[j] == up[i].t) {           if (j > up[i].id) ans++;         } else {           ans++;         }       }       now[up[i].id] = up[i].t;     }     for (int i = 0; i < down.size(); i++) {       for (int j = 0; j < n; j++) {         if (j == down[i].id) continue;         if (now[j] < down[i].t || now[j] > down[i].f) continue;         if (now[j] == down[i].f) {           if (j > down[i].id) ans++;         } else if (now[j] == down[i].t) {           if (j < down[i].id) ans++;         } else {           ans++;         }       }       now[down[i].id] = down[i].t;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   struct Input {     int n, k;     bool read() {       if (!(cin >> n >> k)) {         return false;       }       return true;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     long long ans;     void write() { cout << ans <<   n ; }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     void solve() {       ans = 0;       while (n > 1 && k > 0) {         ans += 2 * (n - 1) - 1;         n -= 2;         --k;       }     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     sol.read();     sol.solve();     sol.write();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int find(vector<long long int> &p, long long int i) {     if (p[i] == -1) return i;     return find(p, p[i]);   }   void solve() {     string st;     cin >> st;     long long int c = 0;     for (long long int i = 0; i < st.size(); i++) {       if (st[i] ==  >  or st[i] ==  < ) {         continue;       }       if (st[i] ==  / ) {         c--;         for (long long int j = 0; j < 2 * c; j++) {           cout <<    ;         }         cout <<  </  << st[i + 1] <<  >  << endl;       } else if (st[i - 1] !=  / ) {         for (long long int j = 0; j < 2 * c; j++) {           cout <<    ;         }         cout <<  <  << st[i] <<  >  << endl;         c++;       }     }   }   int main() {     { solve(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int xx[] = {0, 0, -1, 1}, yy[] = {-1, 1, 0, 0};   using ll = long long;   using ppi = pair<int, int>;   using ppl = pair<ll, ll>;   ll d[3001][3001];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       vector<int> v(N);       for (long long i = (0); i < (N); ++i) {         cin >> v[i];       }       memset(d, 0, sizeof(d));       for (int i = N - 1; 0 <= i; --i) {         d[i][v[i]] = 1;         if (i + 1 < N) {           for (long long x = (1); x <= (N); ++x) {             d[i][x] += d[i + 1][x];           }         }       }       ll ans = 0;       for (long long j = (1); j < (N - 2); ++j) {         for (long long k = (j + 1); k < (N - 1); ++k) {           ans += (d[0][v[k]] - d[j][v[k]]) * (d[k + 1][v[j]]);         }       }       cout << ans << ((char)10);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long a[300100], sum[300100];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i];     long long ans = sum[0];     sort(sum + 1, sum + n);     for (int i = 0; i < k - 1; i++) ans += sum[n - 1 - i];     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char alphz[27] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                      j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                      s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };   float Euclidean(long long x1, long long x2, long long y1, long long y2) {     return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));   }   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long LCM(long long a, long long b) { return (a * b) / gcd(a, b); }   void PrimeFactor(long long n) {     while (n % 2 == 0) {       n /= 2;     }     for (int i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         n /= i;       }     }     if (n > 2) {     };   }   bool is_square(long long x) {     long long l = 0, r = x;     while (l <= r) {       long long mid = l + (r - l) / 2;       if (mid * mid == x) return true;       if (mid * mid > x)         r = mid - 1;       else         l = mid + 1;     }     return false;   }   long long power(long long x, long long y) {     long long temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   bool is_Prime(int x) {     if (x == 2)       return 1;     else if (x % 2 == 0 || x < 2)       return 0;     for (int i = 3; i * i <= x; i += 2)       if (x % i == 0) return 0;     return 1;   }   const int N = 1e+5;   int aseg[4], seg[4];   void SEGBuild(int pos, int low, int hig) {     if (low == hig)       seg[pos] = aseg[low];     else {       int mid = low + (hig - low) / 2;       SEGBuild(2 * pos, low, mid);       SEGBuild(2 * pos + 1, mid + 1, hig);       if (seg[2 * pos] < seg[2 * pos + 1])         seg[pos] = seg[2 * pos];       else         seg[pos] = seg[2 * pos + 1];     }   }   void SEGUpdate(int pos, int idx, int low, int hig, int val) {     if (low == hig) {       aseg[idx] = val;       seg[pos] = val;     } else {       int mid = low + (hig - low) / 2;       if (idx >= low && idx <= mid)         SEGUpdate(2 * pos, idx, low, mid, val);       else         SEGUpdate(2 * pos + 1, idx, mid + 1, hig, val);       seg[pos] = min(seg[2 * pos + 1], seg[2 * pos]);     }   }   int ANSQuery(int pos, int low, int hig, int l, int r) {     if (l > hig || low > r) return 1e+5;     if (l <= low && r >= hig)       return seg[pos];     else {       int p1, p2;       int mid = low + (hig - low) / 2;       p1 = ANSQuery(2 * pos, low, mid, l, r);       p2 = ANSQuery(2 * pos + 1, mid + 1, hig, l, r);       return min(p1, p2);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int k;     string s;     cin >> k >> s;     vector<int> a(k, 0);     int len = (int)s.size();     if (len == 1) {       if (k > 1) return cout <<  IMPOSSIBLE n , 0;       return cout <<  a  <<   n , 0;     }     int i = 0, j = len - 1;     while (i < j) {       if (s[i] !=  ?  && s[j] !=  ?  && s[i] != s[j])         return cout <<  IMPOSSIBLE n , 0;       if (s[i] !=  ? ) a[s[i] -  a ]++;       if (s[j] !=  ? ) a[s[j] -  a ]++;       i++, j--;     }     int mid = len / 2;     if (len % 2 == 0)       i = mid - 1, j = mid;     else       i = mid, j = mid;     while (i >= 0) {       if (s[i] !=  ?  && s[j] !=  ? )         a[s[i] -  a ] += 2;       else if (s[i] ==  ?  && s[j] !=  ? )         s[i] = s[j], a[s[j] -  a ] += 2;       else if (s[i] !=  ?  && s[j] ==  ? )         s[j] = s[i], a[s[i] -  a ] += 2;       else {         int idx = 0;         for (int i = k - 1; i >= 0; i--) {           if (a[i] == 0) {             idx = i;             break;           }         }         s[i] = s[j] = idx +  a ;         a[idx] += 2;       }       i--, j++;     }     for (int i = 0; i < k; i++)       if (!a[i]) return cout <<  IMPOSSIBLE n , 0;     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   const int N = 1e5 + 4;   int n, a[N], c[40];   inline void solve() {     memset(c, 0, sizeof(c));     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       for (int j = 0; j < 30; j++)         if ((a[i] >> j) & 1) c[j]++;     }     for (int i = 29; i >= 0; i--)       if (c[i] & 1) {         if (c[i] % 4 == 1) {           puts( WIN );         } else {           puts((n & 1) ?  LOSE  :  WIN );         }         return;       }     puts( DRAW );   }   int main() {     for (int T = read(); T--;) solve();     return (0 - 0);   }