#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int64_t n, m;     cin >> n >> m;     if (n <= m) {       cout << n << endl;     } else {       n -= m;       int64_t l = 0, r = 2e9;       while (l < r) {         int64_t m = (l + r) / 2;         int64_t val = m * (m + 1) / 2;         if (val >= n) {           r = m;         } else {           l = m + 1;         }       }       cout << l + m << endl;     }     return 0;   }


#define _USE_MATH_DEFINES   #include<iostream>   #include<fstream>   #include<string>   #include<vector>   #include<utility>   #include<algorithm>   #include<climits>   #include<set>   #include<map>   #include<cmath>   #include<iomanip>   #include<iterator>   #include<queue>   #include<stack>   #include<cctype>   #include<deque>   #include<time.h>   #include<bitset>   #include<random>   #include <functional>   #include<unordered_set>   #include<unordered_map>   #include<random>   #include<numeric>   #include<chrono>   #include<sstream>   #include <valarray>    #include<list>   #include<complex>   #include<cassert>         typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;      #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:16777216 )   #define pb push_back   #define en   n    #define forn(i,n) for(int i = 0;i<n;i++)   #define for0(i,n) for(int i = 0;i<n;i++)   #define all(x) (x).begin(),(x).end()   #define rall(x) (x).rbegin(),(x).rend()   #define vec vector   #define pii pair<int,int>   #define pll pair<ll,ll>   #define szof(x) int(x.size())   #define sqr(x) ((x)*(x))   #define debug(x) cerr<<#x<<  =  <<x<<  n        using namespace std;      const int INF = 1000000000 + 1e8;   const ll LINF = 2000000000000000000;         const int N = 1e5 + 10;   const int MOD = 1e9 + 7;      ll l[N];   ll r[N];      void inc(int i1, int change, ll* t) {    for (int i = i1; i < N; i = i | (i + 1)) {     t[i] += change;    }   }      ll prefix(int i1, ll* t) {    ll res = 0;    for (int i = i1; i >= 0; i = (i & (i + 1)) - 1) {     res += t[i];    }    return res;   }      //возвращает prefix [i1, i2]   ll prefix(int i1, int i2, ll* t) {    return prefix(i2, t) - (i1 == 0 ? 0 : prefix(i1 - 1, t));   }         const int SEGTREE_SIZE = 2e5 + 10;   const ll NO_OPERATION = 1e18 + 5;      struct segtree {       struct node {     ll set;     ll min;     ll max;    };       vector<node> t;    int size;       const node NEUTRAL_ELEM = { NO_OPERATION, LINF, -LINF };    const node ZERO = { NO_OPERATION , 0, 0 };          void modify_op(ll& a, ll b, ll len) {     if (b == NO_OPERATION)      return;     if (a == NO_OPERATION) {      a = b * len;     }     else {      a += b * len;     }    }          node sum_op(node &a, node &b) {     node res;     res.min = min(a.min, b.min);     res.max = max(a.max, b.max);     res.set = NO_OPERATION;        return res;    }          void push(int v, int tl, int tr) {     if (t[v].set == NO_OPERATION || tr - tl == 1) {      return;     }     int tm = (tr + tl) / 2;     modify_op(t[v * 2 + 1].set, t[v].set, 1);     modify_op(t[v * 2 + 1].min, t[v].set, 1);     modify_op(t[v * 2 + 1].max, t[v].set, 1);        modify_op(t[v * 2 + 2].set, t[v].set, 1);     modify_op(t[v * 2 + 2].min, t[v].set, 1);     modify_op(t[v * 2 + 2].max, t[v].set, 1);        t[v].set = NO_OPERATION;    }          void init(int n) {     size = 1;     while (size < n) {      size *= 2;     }     t.assign(2 * size, ZERO);    }       segtree(int n = SEGTREE_SIZE) {     init(n);    }       segtree(vector<pii>& a) {     init(a.size());     build(a);    }          void build(vector<pii>& a, int v, int tl, int tr) {     if (tr - tl == 1) {      if (tl < a.size())       t[v] = { NO_OPERATION, a[tl].second, a[tl].first };      return;     }     int tm = (tr + tl) / 2;     build(a, v * 2 + 1, tl, tm);     build(a, v * 2 + 2, tm, tr);     t[v] = sum_op(t[v * 2 + 1], t[v * 2 + 2]);    }       void build(vector<pii>& a) {     build(a, 0, 0, size);    }       void modify(int v, int tl, int tr, int l, int r, ll val) {     push(v, tl, tr);     if (tr <= l || tl >= r) {      return;     }        if (l <= tl && tr <= r) {      modify_op(t[v].set, val, 1);      modify_op(t[v].min, val, 1);      modify_op(t[v].max, val, 1);      return;     }        int tm = (tl + tr) / 2;        modify(v * 2 + 1, tl, tm, l, r, val);     modify(v * 2 + 2, tm, tr, l, r, val);        t[v] = sum_op(t[v * 2 + 1], t[v * 2 + 2]);    }       void modify(int l, int r, ll val) {     modify(0, 0, size, l, r, val);    }       node get(int v, int tl, int tr, int l, int r) {     push(v, tl, tr);     if (tr <= l || tl >= r) {      return NEUTRAL_ELEM;     }        if (l <= tl && tr <= r) {      return t[v];     }        int tm = (tl + tr) / 2;        auto g1 = get(v * 2 + 1, tl, tm, l, r);     auto g2 = get(v * 2 + 2, tm, tr, l, r);        return sum_op(g1, g2);    }       node get(int l, int r) {     if (l >= r) {      return ZERO;     }        return get(0, 0, size, l, r);    }   };               void solve() {    int n, m;    cin >> n >> m;       vector<int> k(n + 1);    vector<pii> left(n + 1);    vector<pii> right(n + 1);       for(int i = 1; i <= n; i++){     cin >> k[i];     cin >> left[i].first >> left[i].second;     cin >> right[i].first >> right[i].second;    }       for (int i = 0; i <= n; i++) {     if (left[i].first <= k[i] && k[i] <= left[i].second) {      inc(i, 1, l);     }     if (right[i].first <= k[i] && k[i] <= right[i].second) {      inc(i, 1, r);     }    }       vector<int> dpl(n + 1), dpr(n + 1);    vector<int> pl(n + 1), pr(n + 1);       int last_l = INF, last_r = INF;       if (left[n].first <= k[n] && k[n] <= left[n].second) {     dpl[n] = 1;     last_l = n;     pl[n] = n + 1;    }    if (right[n].first <= k[n] && k[n] <= right[n].second) {     dpr[n] = 1;     last_r = n;     pr[n] = n + 1;    }        auto st_left = segtree(left);    auto st_right = segtree(right);       for (int i = n - 1; i >= 0; i--) {     int temp_l = last_l, temp_r = last_r;          if (last_r != INF)     {      bool ok = (prefix(i + 1, last_r, r) == last_r - (i + 1) + 1);            auto res = st_left.get(i, last_r + 1);            ok &= res.max <= k[i];      ok &= res.min >= k[i];            if (ok) {       dpl[i] = 1;       pl[i] = last_r;       temp_l = i;      }     }        if (last_l != INF)     {      bool ok = (prefix(i + 1, last_l, l) == last_l - (i + 1) + 1);         auto res = st_right.get(i, last_l + 1);         ok &= res.max <= k[i];      ok &= res.min >= k[i];         if (ok) {       dpr[i] = 1;       pr[i] = last_l;       temp_r = i;      }     }     last_l = temp_l, last_r = temp_r;    }       if (dpl[0]) {     cout <<  YES  << en;        bool first = true;        int cur = 0;     bool is_left = true;     while (cur != n + 1) {      if (!first) {       cout << (is_left == 0) <<    ;      }         first = 0;         int nt;      if (is_left) {       nt = pl[cur];      }      else {       nt = pr[cur];      }         is_left ^= 1;         for (int i = cur + 1; i < nt; i++) {       cout << (is_left == 0) <<    ;      }      cur = nt;     }           return;    }       if (dpr[0]) {     cout <<  YES  << en;        bool first = 1;     int cur = 0;     bool is_left = false;     while (cur != n + 1) {      if (!first) {       cout << (is_left == 0) <<    ;      }         first = 0;         int nt;      if (is_left) {       nt = pl[cur];      }      else {       nt = pr[cur];      }         is_left ^= 1;         for (int i = cur + 1; i < nt; i++) {       cout << (is_left == 0) <<    ;      }      cur = nt;     }        return;    }       cout <<  NO  << en;   }         int main() {    srand(time(0));    ios::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);         #ifdef _DEBUG     freopen( input.txt ,  r , stdin);    //freopen( output.txt ,  w , stdout);   #endif          int tst = 1;    //cin >> tst;       while (tst--)     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 3;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int n;   int a[MAXN];   long long seg[12][4 * MAXN];   void add(int j, int l, int r, long long val, int b = 0, int e = n, int k = 0) {     if (l <= b && e <= r) {       seg[j][k] += val;       return;     }     if (r <= b || e <= l) return;     int mid = (b + e) / 2;     add(j, l, r, val, b, mid, k * 2 + 1);     add(j, l, r, val, mid, e, k * 2 + 2);   }   long long get(int j, int i, int b = 0, int e = n, int k = 0) {     if (i < b || i >= e) return 0;     if (b + 1 == e) return seg[j][k];     int mid = (b + e) / 2;     return seg[j][k] + get(j, i, b, mid, k * 2 + 1) +            get(j, i, mid, e, k * 2 + 2);   }   int main() {     cin >> n;     int k;     cin >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       x--;       a[x] = i;     }     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         add(1, a[i], n, 1);       } else {         for (int j = 2; j <= k + 1; j++) {           long long x = get(j - 1, a[i] - 1);           add(j, a[i], n, x);         }         add(1, a[i], n, 1);       }     }     cout << get(k + 1, n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1LL << 60;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * b / gcd(a, b); }   const int N = 2e5 + 5;   int v[N], in[N];   vector<int> e[N];   bool cmp(int a, int b) { return in[a] < in[b]; }   void solve() {     int n;     cin >> n;     for (auto &li : e) li.clear();     for (int i = (0); i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       x--, y--;       e[x].push_back(y);       e[y].push_back(x);     }     vector<int> ch, gen;     for (int i = (0); i < (n); ++i) {       v[i] = 0;       int z;       cin >> z;       in[--z] = i;       ch.push_back(z);     }     for (int i = (0); i < (n); ++i) sort((e[i]).begin(), (e[i]).end(), cmp);     queue<int> q;     q.push(0);     v[0] = 1;     while (!q.empty()) {       int t = q.front();       q.pop();       gen.push_back(t);       for (auto to : e[t]) {         if (v[to]) continue;         v[to] = 1;         q.push(to);       }     }     for (int i = (0); i < (n); ++i)       if (gen[i] != ch[i]) {         puts( No );         return;       }     puts( Yes );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   int cnt[111], ans, b, d, pr[111], v[111];   int main() {     scanf( %d%d , &b, &d);     int k = b;     for (int i = 2; k > 1; i++) {       if (k % i) continue;       while (k % i == 0) cnt[i]++, k /= i;     }     bool flag = true;     k = d;     for (int i = 2; k > 1; i++) {       if (k % i) continue;       int x = 1;       while (k % i == 0) pr[i]++, k /= i, x *= i;       v[x] = -i;       if (cnt[i] == 0) {         flag = false;         continue;       }       int p = (pr[i] - 1) / cnt[i] + 1;       if (p > ans) ans = p;     }     if (flag)       printf( 2-type n%d n , ans);     else {       if (b % d == 1)         printf( 3-type n );       else if ((b + 1) % d == 0)         printf( 11-type n );       else {         flag = true;         for (int i = 2; i <= d; i++) {           if (v[i] >= 0 || cnt[-v[i]] || b % i == 1 || (b + 1) % i == 0) continue;           flag = false;           break;         }         if (flag)           printf( 6-type n );         else           printf( 7-type n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool res = false;     for (int i = 0; i < s.size() - 1; ++i) {       if (s[i] ==  A  && s[i + 1] ==  B ) {         for (int j = i + 2; j < s.size() - 1; ++j) {           if (s[j] ==  B  && s[j + 1] ==  A ) {             cout <<  YES n ;             return 0;           }         }         break;       }     }     for (int i = 0; i < s.size() - 1; ++i) {       if (s[i] ==  B  && s[i + 1] ==  A ) {         for (int j = i + 2; j < s.size() - 1; ++j) {           if (s[j] ==  A  && s[j + 1] ==  B ) {             cout <<  YES n ;             return 0;           }         }         break;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   string grid[1000];   vector<vector<pair<int, char>>> startAdj;   vector<bool> visited;   vector<int> merged;   vector<vector<pair<int, char>>> adj;   vector<int> value;   vector<int> greaterCount;   void flood(int start, int pos) {     if (visited[pos]) return;     visited[pos] = true;     merged[pos] = start;     for (int i = 0; i < startAdj[pos].size(); i++) {       if (startAdj[pos][i].second !=  = ) {         adj[start].push_back(startAdj[pos][i]);       }     }     for (int i = 0; i < startAdj[pos].size(); i++) {       if (startAdj[pos][i].second ==  = ) {         flood(start, startAdj[pos][i].first);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> grid[i];     startAdj.assign(N + M + 1, vector<pair<int, char>>());     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++)         startAdj[i + 1].push_back({j + 1 + N, grid[i][j]});     for (int j = 0; j < M; j++) {       for (int i = 0; i < N; i++) {         char c = grid[i][j];         if (c ==  > )           c =  < ;         else if (c ==  < )           c =  > ;         startAdj[j + 1 + N].push_back({i + 1, c});       }     }     visited.assign(N + M + 1, false);     merged.assign(N + M + 1, 0);     adj.assign(N + M + 1, vector<pair<int, char>>());     value.assign(N + M + 1, 0);     greaterCount.assign(N + M + 1, 0);     for (int i = 1; i <= N + M; i++) {       if (!visited[i]) {         flood(i, i);       }     }     bool works = true;     for (int i = 1; i <= N + M; i++) {       for (int j = 0; j < adj[i].size(); j++) {         if (adj[i][j].second ==  > ) greaterCount[i]++;         if (merged[adj[i][j].first] == i) works = false;       }     }     if (works) {       vector<int> curr;       for (int i = 1; i <= N + M; i++)         if (merged[i] == i && greaterCount[i] == 0) curr.push_back(i);       vector<int> next;       int v = 1;       while (curr.size() != 0) {         for (int i = 0; i < curr.size(); i++) {           value[curr[i]] = v;           for (int j = 0; j < adj[curr[i]].size(); j++) {             if (adj[curr[i]][j].second ==  < ) {               greaterCount[merged[adj[curr[i]][j].first]]--;               if (greaterCount[merged[adj[curr[i]][j].first]] == 0) {                 next.push_back(merged[adj[curr[i]][j].first]);               }             }           }         }         curr = next;         next.clear();         v++;       }       for (int i = 1; i <= N + M; i++) {         if (!value[i] && merged[i] == i) works = false;       }     }     if (works) {       cout <<  Yes n ;       for (int i = 0; i < N; i++) {         if (i) cout <<    ;         cout << value[merged[i + 1]];       }       cout <<   n ;       for (int i = 0; i < M; i++) {         if (i) cout <<    ;         cout << value[merged[i + 1 + N]];       }       cout <<   n ;     } else {       cout <<  No 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 n, k;     cin >> n >> k;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) cin >> arr[i];     long long c = 0;     for (long long i = 1; i < n; i++) {       if (arr[i] + arr[i - 1] < k) {         c += k - arr[i] - arr[i - 1];         arr[i] = k - arr[i - 1];       }     }     cout << c <<   n ;     for (auto i : arr) cout << i <<    ;     ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MAXN = 1000000005;   long long meta;   bool ok = 0;   map<long long, long long> visite;   void bfs(long long padre) {     queue<long long> cola;     cola.push(padre);     while (!cola.empty()) {       long long hijo = cola.front();       cola.pop();       long long hijo1 = hijo * 2;       long long hijo2 = hijo * 10 + 1;       if (hijo1 == meta) {         ok = 1;         visite[hijo1] = hijo;         break;       }       if (hijo2 == meta) {         ok = 1;         visite[hijo2] = hijo;         break;       }       if (hijo1 < MAXN) {         visite[hijo1] = hijo;         cola.push(hijo1);       }       if (hijo2 < MAXN) {         visite[hijo2] = hijo;         cola.push(hijo2);       }     }   }   int main() {     ios::sync_with_stdio(false);     long long padre;     cin >> padre >> meta;     bfs(padre);     if (ok == false) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     vector<long long> ans;     long long hijo = visite[meta];     ans.push_back(meta);     while (hijo != padre) {       ans.push_back(hijo);       hijo = visite[hijo];     }     ans.push_back(padre);     cout << ans.size() << endl;     for (int i = ans.size() - 1; i >= 0; i--) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   int CH, NEG;   template <typename TP>   inline void read(TP& ret) {     ret = NEG = 0;     while (CH = getchar(), CH <  ! )       ;     if (CH ==  - ) NEG = true, CH = getchar();     while (ret = ret * 10 + CH -  0 , CH = getchar(), CH >  ! )       ;     if (NEG) ret = -ret;   }   using namespace std;   int n, K;   struct node {     int sz;     int L[11LL], R[11LL];     bool operator<(const node& B) const {       int i;       for (i = (1); i <= (K); i++)         if (R[i] > B.L[i]) break;       return i > K;     }     bool operator>(const node& B) const {       int i;       for (i = (1); i <= (K); i++)         if (L[i] < B.R[i]) break;       return i > K;     }   } tmp;   int tot = 0;   set<node> S;   set<node>::iterator it1, it2;   void merge(node& A, const node& B) {     A.sz += B.sz;     int i;     for (i = (1); i <= (K); i++)       A.L[i] = std::min(A.L[i], B.L[i]), A.R[i] = std::max(A.R[i], B.R[i]);   }   int Add() {     int i;     tmp.sz = 1;     for (i = (1); i <= (K); i++) read(tmp.L[i]), tmp.R[i] = tmp.L[i];     if (S.empty()) {       S.insert(tmp);       return 1;     }     it1 = S.lower_bound(tmp);     while (true) {       if (it1 == S.end()) break;       if (*it1 > tmp) break;       it2 = it1;       it1++;       merge(tmp, *it2);       S.erase(it2);     }     S.insert(tmp);     it1 = S.end();     it1--;     return it1->sz;   }   int main() {     S.clear();     int i;     read(n), read(K);     for (i = (1); i <= (n); i++) {       printf( %d n , Add());     }   END:     getchar(), getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int N = 5e5 + 10;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7, G = 3;   const int base = 30000;   int t;   int n, m, k;   int dp[35][35][55];   int dfs(int n, int m, int k) {     if (k == 0 || n * m == k) return 0;     if (dp[n][m][k] != -1) return dp[n][m][k];     int ret = INF;     for (int i = 1; i < n; ++i)       for (int j = 0; j <= k; ++j)         ret = min(ret, dfs(i, m, j) + dfs(n - i, m, k - j) + m * m);     for (int i = 1; i < m; ++i)       for (int j = 0; j <= k; ++j)         ret = min(ret, dfs(n, i, j) + dfs(n, m - i, k - j) + n * n);     if (dp[n][m][k] == -1) dp[n][m][k] = ret;     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> t;     memset(dp, -1, sizeof(dp));     while (t--) {       cin >> n >> m >> k;       cout << dfs(n, m, k) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, int> mapdown, mapup, mapleft, mapright;     char keys[10] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };     int n, count1 = 0, count2 = 0, count3 = 0, count4 = 0;     char str[15];     mapdown.clear();     mapup.clear();     mapleft.clear();     mapright.clear();     scanf( %d , &n);     scanf( %s , str);     for (int i = 0; i < 10; i++) {       char c = keys[i];       if (keys[i] ==  7  || keys[i] ==  0  || keys[i] ==  9 ) {         mapdown.insert(make_pair(c, 0));       } else {         mapdown.insert(make_pair(c, 1));       }     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  1  || keys[i] ==  2  || keys[i] ==  3 )         mapup.insert(make_pair(keys[i], 0));       else         mapup.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  3  || keys[i] ==  6  || keys[i] ==  9  || keys[i] ==  0 )         mapright.insert(make_pair(keys[i], 0));       else         mapright.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < 10; i++) {       if (keys[i] ==  1  || keys[i] ==  4  || keys[i] ==  7  || keys[i] ==  0 )         mapleft.insert(make_pair(keys[i], 0));       else         mapleft.insert(make_pair(keys[i], 1));     }     for (int i = 0; i < n; i++) {       if (mapdown[str[i]] != 0) count1++;     }     for (int i = 0; i < n; i++) {       if (mapup[str[i]] != 0) count2++;     }     for (int i = 0; i < n; i++) {       if (mapleft[str[i]] != 0) count3++;     }     for (int i = 0; i < n; i++) {       if (mapright[str[i]] != 0) count4++;     }     if (count1 == n || count2 == n || count3 == n || count4 == n)       printf( NO );     else       printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isSolveabe(int *a, int n, int m) {     int i = m;     int j = n - 1;     int min = INT_MIN;     while (i < j) {       if (a[i] < a[j]) {         if (a[i] < min) {           return false;         }         min = a[i];         ++i;       } else {         if (a[j] < min) {           return false;         }         min = a[j];         --j;       }     }     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int *a = new int[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int s = 0;       int e = n - 1;       int ans = 0;       while (s <= e) {         int m = (s + e) / 2;         if (isSolveabe(a, n, m)) {           ans = m;           e = m - 1;         } else {           s = m + 1;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }   const long long N = 2e5 + 7;   const long long inf = 1e6 + 1;   const long long mod = 998244353;   int t, n, m, a[N];   struct node {     int def, s;     bool operator<(const node& a) const { return def < a.def; }   } b[N];   bool cmp(const node& a, int x) { return a.def < x; }   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       cin >> m;       for (int i = 1; i <= m; i++) cin >> b[i].def >> b[i].s;       sort(b + 1, b + 1 + m);       for (int i = m - 1; i >= 1; i--) {         b[i].s = max(b[i].s, b[i + 1].s);       }       bool ok = true;       int minn = 2 * n, ans = 0, last = 0;       for (int i = 1; i <= n; i++) {         int q = lower_bound(b + 1, b + 1 + m, a[i], cmp) - b;         if (q > m) {           ok = false;           break;         }         minn = min(minn, b[q].s);         if (last + minn < i) {           ans++;           last = i - 1;           minn = b[q].s;         }       }       if (ok == false)         cout <<  -1 n ;       else         cout << ans + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long int;   using pint = pair<int, int>;   using plint = pair<lint, lint>;   struct fast_ios {     fast_ios() {       cin.tie(0);       ios::sync_with_stdio(false);       cout << fixed << setprecision(20);     };   } fast_ios_;   template <typename T>   void ndarray(vector<T> &vec, int len) {     vec.resize(len);   }   template <typename T, typename... Args>   void ndarray(vector<T> &vec, int len, Args... args) {     vec.resize(len);     for (auto &v : vec) ndarray(v, args...);   }   template <typename T>   bool mmax(T &m, const T q) {     if (m < q) {       m = q;       return true;     } else       return false;   }   template <typename T>   bool mmin(T &m, const T q) {     if (m > q) {       m = q;       return true;     } else       return false;   }   template <typename T1, typename T2>   pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {     return make_pair(l.first + r.first, l.second + r.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {     return make_pair(l.first - r.first, l.second - r.second);   }   template <typename T>   istream &operator>>(istream &is, vector<T> &vec) {     for (auto &v : vec) is >> v;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &vec) {     os <<  [ ;     for (auto v : vec) os << v <<  , ;     os <<  ] ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const deque<T> &vec) {     os <<  deq[ ;     for (auto v : vec) os << v <<  , ;     os <<  ] ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const unordered_set<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {     os <<  (  << pa.first <<  ,  << pa.second <<  ) ;     return os;   }   template <typename TK, typename TV>   ostream &operator<<(ostream &os, const map<TK, TV> &mp) {     os <<  { ;     for (auto v : mp) os << v.first <<  =>  << v.second <<  , ;     os <<  } ;     return os;   }   template <typename TK, typename TV>   ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {     os <<  { ;     for (auto v : mp) os << v.first <<  =>  << v.second <<  , ;     os <<  } ;     return os;   }   lint extgcd(lint a, lint b, lint &x, lint &y) {     lint d = a;     if (b != 0)       d = extgcd(b, a % b, y, x), y -= (a / b) * x;     else       x = 1, y = 0;     return d;   }   lint mod_inverse(lint a, lint m) {     lint x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   struct UndirectedTree {     int V;     int root;     int dfs_cnt;     vector<vector<int>> edge;     UndirectedTree(int N = 0) : V(N), dfs_cnt(0), edge(N) {}     void add_edge(int u, int v) {       edge[u].emplace_back(v);       edge[v].emplace_back(u);     }     vector<int> par;     vector<int> subtree_size;     vector<int> dfs_id;     void _tree_dfs(int now, int prv) {       par[now] = prv;       subtree_size[now] = 1;       dfs_id[now] = dfs_cnt++;       for (auto nxt : edge[now])         if (nxt != prv) {           _tree_dfs(nxt, now);           subtree_size[now] += subtree_size[nxt];         }     }     void tree_dfs(int r) {       root = r;       par.resize(V, -1);       subtree_size.resize(V, -1);       dfs_id.resize(V, 0);       dfs_cnt = 0;       _tree_dfs(root, -1);     }     vector<int> prev_heavy;     int DT;     void _tree_dfs_th(int now, int prv, int ph) {       prev_heavy[now] = ph;       if ((int)edge[now].size() >= DT) ph = now;       for (auto nxt : edge[now])         if (nxt != prv) {           _tree_dfs_th(nxt, now, ph);         }     }     void tree_dfs_th(int B) {       DT = B;       prev_heavy.assign(V, -1);       _tree_dfs_th(root, -1, -1);     }     vector<vector<int>> parinfo;     void _hp_dfs(int now, int prv, int c, int r) {       parinfo[r][now] = c;       for (auto nxt : edge[now])         if (nxt != prv) _hp_dfs(nxt, now, c, r);     }     void heavy_prepare() {       parinfo.resize(V);       for (int now = (0), now_end_ = (V); now < now_end_; now++)         if ((int)edge[now].size() >= DT) {           parinfo[now].resize(V);           for (auto nxt : edge[now])             if (nxt != par[now]) _hp_dfs(nxt, now, nxt, now);         }     }   };   constexpr lint MOD = 998244353;   struct BIT {     using T = lint;     int len;     vector<T> val;     BIT(int num) : len(num), val(num + 1) {}     BIT() : BIT(0) {}     void reset() { fill(val.begin(), val.end(), 0); }     void _add(int pos, T v) {       while (pos > 0 and pos <= len) {         val[pos] += v;         if (val[pos] >= MOD) val[pos] -= MOD;         pos += pos & -pos;       }     }     T _sum(int pos) const {       T res = 0;       while (pos > 0) res += val[pos], pos -= pos & -pos;       return res % MOD;     }     void range_add(int l, int r, T v) {       _add(l + 1, v);       _add(r + 1, MOD - v);     }     T get(int x) { return _sum(x + 1); }   };   vector<lint> cache;   constexpr int B = 200;   int main() {     int N, Q;     cin >> N >> Q;     UndirectedTree tree(N);     for (int _ = (0), __end_ = (N - 1); _ < __end_; _++) {       int u, v;       cin >> u >> v;       tree.add_edge(u - 1, v - 1);     }     tree.tree_dfs(0);     tree.tree_dfs_th(B);     tree.heavy_prepare();     lint Ninv = mod_inverse(N, MOD);     BIT bit(N);     cache.resize(N);     for (int _ = (0), __end_ = (Q); _ < __end_; _++) {       int q, v;       cin >> q >> v;       v--;       int bid = tree.dfs_id[v];       if (q == 1) {         lint d;         cin >> d;         lint stsz = tree.subtree_size[v];         lint A = N - stsz;         bit.range_add(0, N, d * stsz % MOD * Ninv % MOD);         bit.range_add(bid, bid + stsz, d * A % MOD * Ninv % MOD);         if ((int)tree.edge[v].size() >= B) {           (cache[v] += d) %= MOD;         } else {           for (auto nxt : tree.edge[v])             if (nxt != tree.par[v]) {               lint cid = tree.dfs_id[nxt], cstsz = tree.subtree_size[nxt];               bit.range_add(cid, cid + cstsz, MOD - d * cstsz % MOD * Ninv % MOD);             }         }       } else {         lint ret = bit.get(bid);         while (tree.prev_heavy[v] >= 0) {           int p = tree.prev_heavy[v];           int c = tree.parinfo[p][v];           ret = ret + MOD - cache[p] * tree.subtree_size[c] % MOD * Ninv % MOD;           v = p;         }         ret %= MOD;         printf( %lld n , ret);       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Elem>   int quick_power(int a, Elem b, int Mod) {     int ans = 1;     while (b) {       if (b & 1) {         ans = 1ll * ans * a % Mod;       }       b >>= 1;       a = 1ll * a * a % Mod;     }     return ans;   }   const int Maxn = 100000;   const int Mod = 998244353;   const int G = 3;   int p[Maxn + 5];   int n;   long long m;   int frac[Maxn + 5], inv_f[Maxn + 5], inv[Maxn + 5];   void init() {     frac[0] = 1;     for (int i = 1; i <= Maxn + 1; i++) {       frac[i] = 1ll * frac[i - 1] * i % Mod;     }     inv_f[Maxn + 1] = quick_power(frac[Maxn + 1], Mod - 2, Mod);     for (int i = Maxn; i >= 0; i--) {       inv_f[i] = 1ll * inv_f[i + 1] * (i + 1) % Mod;     }     inv[1] = 1;     for (int i = 2; i <= Maxn + 1; i++) {       inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;     }   }   void NTT(int *a, int flag, int n) {     static int R[Maxn << 2 | 5], last_len;     int len = 1, L = 0;     while (len < n) {       len <<= 1;       L++;     }     if (len != last_len) {       for (int i = 0; i < len; i++) {         R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));       }       last_len = len;     }     for (int i = 0; i < len; i++) {       if (i < R[i]) {         swap(a[i], a[R[i]]);       }     }     for (int j = 1; j < len; j <<= 1) {       int T = quick_power(G, (Mod - 1) / (j << 1), Mod);       for (int k = 0; k < len; k += (j << 1)) {         for (int l = 0, t = 1; l < j; l++, t = 1ll * t * T % Mod) {           int Nx = a[k + l], Ny = 1ll * t * a[j + k + l] % Mod;           a[k + l] = (Nx + Ny) % Mod;           a[j + k + l] = (Nx - Ny + Mod) % Mod;         }       }     }     if (flag == -1) {       reverse(a + 1, a + len);       for (int i = 0, t = quick_power(len, Mod - 2, Mod); i < len; i++) {         a[i] = 1ll * a[i] * t % Mod;       }     }   }   int a[Maxn << 2 | 5], b[Maxn << 2 | 5], f[Maxn << 2 | 5], g[Maxn << 2 | 5];   int main() {     init();     scanf( %d%lld , &n, &m);     for (int i = 0; i <= n; i++) {       scanf( %d , &p[i]);     }     for (int i = 0; i <= n; i++) {       a[i] = inv_f[i];       b[i] = 1ll * frac[n - i] * p[n - i] % Mod;     }     int len = 1;     while (len <= (n << 1)) {       len <<= 1;     }     NTT(a, 1, len);     NTT(b, 1, len);     for (int i = 0; i < len; i++) {       a[i] = 1ll * a[i] * b[i] % Mod;     }     NTT(a, -1, len);     for (int i = 0; i <= n; i++) {       g[i] = 1ll * a[n - i] * inv_f[i] % Mod;       g[i] = 1ll * g[i] * quick_power(inv[i + 1], m, Mod) % Mod;     }     for (int i = 0; i < len; i++) {       a[i] = b[i] = 0;     }     for (int i = 0; i <= n; i++) {       if (i & 1) {         a[i] = Mod - inv_f[i];       } else {         a[i] = inv_f[i];       }       b[i] = 1ll * frac[n - i] * g[n - i] % Mod;     }     NTT(a, 1, len);     NTT(b, 1, len);     for (int i = 0; i < len; i++) {       a[i] = 1ll * a[i] * b[i] % Mod;     }     NTT(a, -1, len);     for (int i = 0; i <= n; i++) {       f[i] = 1ll * a[n - i] * inv_f[i] % Mod;     }     for (int i = 0; i <= n; i++) {       printf( %d  , f[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     bool p1 = (n >= 5);     bool p2 = 0, p3 = 0, p4 = 0;     for (int i = 0; i < n; i++) {       p2 |= (s[i] >=  a  && s[i] <=  z );       p3 |= (s[i] >=  A  && s[i] <=  Z );       p4 |= (s[i] >=  0  && s[i] <=  9 );     }     if (p1 && p2 && p3 && p4)       printf( Correct );     else       printf( Too weak );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int n;   map<string, int> was;   void read() {     cin >> n;     while (n--) {       int c;       string s;       cin >> c >> s;       sort(s.begin(), s.end());       if (was.count(s) == 0) {         was[s] = c;       } else {         was[s] = min(was[s], c);       }     }   }   int getC(string a, string b) {     if (!was.count(a) || !was.count(b)) {       return INF;     }     return was[a] + was[b];   }   void solve() {     int ans = INF;     if (was.count( A ) && was.count( B ) && was.count( C )) {       ans = was[ A ] + was[ B ] + was[ C ];     }     if (was.count( ABC )) {       ans = min(ans, was[ ABC ]);     }     ans = min(ans, getC( A ,  BC ));     ans = min(ans, getC( AB ,  C ));     ans = min(ans, getC( AC ,  B ));     ans = min(ans, getC( AB ,  BC ));     ans = min(ans, getC( AC ,  BC ));     ans = min(ans, getC( AB ,  AC ));     if (ans == INF) {       ans = -1;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;      typedef long long ll;         int main(){    ios_base::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);        int t;    cin >> t;    while (t--){     string s;     cin >> s;     stack<char> a, b;     int ans = 0;     for (auto c: s){      if (c ==  (  || c ==  ) ){       if (c ==  ( )        a.push(c);       else {        if (!a.empty()){         ans++;         a.pop();        }       }      }      if (c ==  [  || c ==  ] ){       if (c ==  [ )        b.push(c);       else {        if (!b.empty()){         ans++;         b.pop();        }       }      }     }      cout << ans <<   n ;    }   }


#include <bits/stdc++.h>   using namespace std;   int q[123456];   vector<int> sq;   int main() {     int n, k;     int a, b;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a, &b);       sq.push_back(min(2 * a, b) - min(a, b));       q[i] = min(a, b);       1;     }     sort(sq.begin(), sq.end(), greater<int>());     long long sum = 0;     int flag = 1;     for (int i = 0; i < k; i++) sum += sq[i], sq[i] < 0 ? flag = 0 : 0;     for (int i = 1; i <= n; i++) sum += q[i];     printf( %lld , flag * sum);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s[n];     int a[n];     for (int x = 0; x < n; x++) {       cin >> s[x];       a[x] = s[x].length();     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < n - 1; y++) {         if (a[y] > a[y + 1]) {           int t = a[y];           a[y] = a[y + 1];           a[y + 1] = t;           string temp = s[y];           s[y] = s[y + 1];           s[y + 1] = temp;         }       }     }     int f = 0;     for (int x = 0; x < n; x++) {       int i;       for (int y = x + 1; y < n; y++) {         i = s[y].find(s[x], 0);         if (i == -1) {           f = 1;           break;         }       }       if (f == 1) {         break;       }     }     if (f == 1) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       for (int x = 0; x < n; x++) {         cout << s[x] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, k, m, c1 = 0, count2 = 0, m3 = 0;     cin >> n;     long long int a[n];     map<long long int, long long int> m1;     for (i = 0; i < n; i++) {       cin >> a[i];       m1[i] = -1;     }     cin >> m;     vector<long long int> v;     for (i = 0; i < m; i++) {       long long int p, q, r;       cin >> p;       if (p == 1) {         cin >> q >> r;         a[q - 1] = r;         m1[q - 1] = i;         v.push_back(0);       } else {         cin >> q;         m3 = max(m3, q);         v.push_back(q);       }     }     long long int max1[v.size() - 1];     memset(max1, 0, sizeof(max1));     long long int m_1 = 0;     for (i = (m - 1); i >= 0; i--) {       if (v[i] > m_1) {         max1[i] = max(m_1, v[i]);         m_1 = max(m_1, v[i]);       } else {         max1[i] = m_1;         m_1 = max(m_1, v[i]);       }     }     for (i = 0; i < n; i++) {       if (m1[i] >= m) {         cout << a[i] <<    ;       } else if (m1[i] != -1) {         cout << max(a[i], max1[m1[i]]) <<    ;       } else {         cout << max(a[i], m3) <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double PI = 3.14159265358979323846;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long get(long long x, long long n) {     long long l, r;     if (x > n) return 0;     long long acc = 0;     if (x % 2 == 0) {       l = x;       r = x + 1;     } else {       l = 2 * x;       r = 2 * x + 1;       acc += 1;     }     while (r <= n) {       acc += r - l + 1;       l *= 2;       r = 2 * r + 1;     }     if (l <= n) acc += (n - l + 1);     return acc;   }   int dfs(int x, vector<bool> &chk, vector<int> &val, int step,           vector<map<int, int> > &e) {     chk[x] = true;     int maxval = -1e9 - 1;     for (auto &k : e[x]) {       if (chk[k.first]) continue;       maxval = max(maxval, dfs(k.first, chk, val, step + 1, e));     }     if (step == 0)       maxval = max(maxval, val[x]);     else if (step == 1)       maxval = max(maxval, val[x] + 1);     else       maxval = max(maxval, val[x] + 2);     return maxval;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n + 1);     int mmm = -1e9 - 1;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];       mmm = max(mmm, a[i + 1]);     }     set<int> s;     for (int i = 1; i <= n; i++) {       if (a[i] == mmm) s.insert(i);     }     vector<map<int, int> > v(n + 1);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       v[x][y] = 1;       v[y][x] = 1;     }     vector<bool> chk(n + 1);     if (s.size() == 1) {       int ans = dfs(*(s.begin()), chk, a, 0, v);       cout << ans << endl;     } else {       bool isok = false;       for (int i = 1; i <= n; i++) {         if (v[i].size() + 1 < s.size()) continue;         bool isok2 = true;         for (auto k : s) {           if (v[i][k] != 1 && k != i) {             isok2 = false;             break;           }         }         if (isok2) {           isok = true;           break;         }       }       if (isok) {         cout << mmm + 1 << endl;       } else {         cout << mmm + 2 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     x *= f;   }   int n;   double g[N][N];   double E[N], prod[N];   bool vis[N];   int main() {     read(n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         int x;         read(x);         g[i][j] = 1. * x / 100;       }     if (n == 1) return puts( 0 );     vis[n] = true;     for (int i = 1; i < n; i++) {       E[i] = 1;       prod[i] = 1 - g[i][n];     }     for (int i = 1; i <= n; i++) {       double low = 1e18;       int pos = 0;       for (int j = 1; j <= n; j++)         if (!vis[j] && E[j] / (1 - prod[j]) < low)           low = E[j] / (1 - prod[j]), pos = j;       if (pos == 1) return printf( %.10lf n , E[1] / (1 - prod[1])), 0;       vis[pos] = true;       for (int j = 1; j <= n; j++)         E[j] += E[pos] / (1 - prod[pos]) * g[j][pos] * prod[j],             prod[j] *= (1 - g[j][pos]);     }     return 0;   }


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


#include<bits/stdc++.h>   using namespace std;   void solve();   int main()   {    ios_base::sync_with_stdio(false); cin.tie(NULL);      #ifndef ONLINE_JUDGE    freopen( input1.txt ,  r , stdin);    freopen( error1.txt ,  w , stderr);    freopen( output1.txt ,  w , stdout);   #endif       int t ; cin >> t;    while (t--)    {     solve();     cout <<   n ;    }       cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;    return 0;   }   void solve()   {    long long n, x ;    cin >> n >> x ;    long long a[n], b[n], s = 0, s1 = 0, j = 0;    for (long long i = 0; i < n; i++)     cin >> a[i];    for (long long i = 0; i < n; i++)     s += a[i];    for (long long i = 0; i < n; i++)     b[i] = a[i];    while (1) {     if (j >= n)      j = 0;     if (b[j] % x != 0)      break;     s += a[j];     b[j] /= x;     j++;    }    cout << s;   }


#include <bits/stdc++.h>   using namespace std;   char s[2005];   int n, c[2005][2005], ans = 0x3f3f3f3f, was, ot[2005];   bool chk() {     static int ar[2005];     int sum = 0;     for (int i = (1), LIM = (n); i <= LIM; i++) ar[i] = ot[i], sum += ot[i];     sort(ar + 1, ar + 1 + n);     int sm = 0;     for (int i = (1), LIM = (n - 1); i <= LIM; i++) {       sm += ar[i];       if (sm == i * (i - 1) / 2) return 0;     }     return 1;   }   void dfs(int u, int s) {     if (u == n + 1) {       if (chk()) {         if (ans > s) ans = s, was = 0;         if (ans == s) was++;       }       return;     }     dfs(u + 1, s);     for (int i = (1), LIM = (n); i <= LIM; i++)       if (c[u][i])         ot[u]--, ot[i]++;       else         ot[u]++, ot[i]--;     for (int i = (1), LIM = (n); i <= LIM; i++) swap(c[i][u], c[u][i]);     dfs(u + 1, s + 1);     for (int i = (1), LIM = (n); i <= LIM; i++)       if (c[u][i])         ot[u]--, ot[i]++;       else         ot[u]++, ot[i]--;     for (int i = (1), LIM = (n); i <= LIM; i++) swap(c[i][u], c[u][i]);   }   int main() {     scanf( %d , &n);     for (int i = (1), LIM = (n); i <= LIM; i++) {       scanf( %s , s + 1);       for (int j = (1), LIM = (n); j <= LIM; j++)         c[i][j] = (s[j] ==  1 ), ot[i] += c[i][j];     }     if (n <= 6) {       dfs(1, 0);       if (ans == 0x3f3f3f3f)         puts( -1 );       else {         for (int i = (1), LIM = (ans); i <= LIM; i++)           was = 1ll * was * i % 998244353;         printf( %d %d n , ans, was);       }       return 0;     } else {       if (chk()) {         puts( 0 1 );         return 0;       }       for (int u = (1), LIM = (n); u <= LIM; u++) {         for (int i = (1), LIM = (n); i <= LIM; i++)           if (c[u][i])             ot[u]--, ot[i]++;           else             ot[u]++, ot[i]--;         for (int i = (1), LIM = (n); i <= LIM; i++) swap(c[i][u], c[u][i]);         if (chk()) was++;         for (int i = (1), LIM = (n); i <= LIM; i++)           if (c[u][i])             ot[u]--, ot[i]++;           else             ot[u]++, ot[i]--;         for (int i = (1), LIM = (n); i <= LIM; i++) swap(c[i][u], c[u][i]);       }       printf( %d %d n , 1, was);     }   }


#include <bits/stdc++.h>   using namespace std;   int ans, a, b, c;   int main() {     cin >> a >> b >> c;     ans = a;     while (!(b >= ans + 1 && c >= ans + 2)) ans--;     cout << 3 * ans + 3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 10, M = 20, mo = 1e9 + 7;   vector<vector<long long> > f, sum;   vector<long long> g;   long long a[maxn], c[maxn];   long long n, l, k, K, B, ans, i, j, z, x, y, N, r;   int main() {     scanf( %lld%lld%lld , &n, &l, &k);     g.push_back(0);     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);       c[i] = a[i];       g.push_back(0);     }     if (l <= n) {       printf( %lld n , l);       return 0;     }     sort(c, c + n);     K = min(l / n, k);     N = (l / n) % mo;     r = l % n;     f.push_back(g);     sum.push_back(g);     for (i = 1; i <= k; i++) {       f.push_back(g);       sum.push_back(g);     }     for (i = 0; i < n; i++) {       f[1][i] = 1;       sum[0][i] = 1;     }     sum[1][0] = 1;     for (i = 1; i < n; i++) sum[1][i] = (f[1][i] + sum[1][i - 1]) % mo;     for (i = 2; i <= K; i++) {       for (j = 0; j < n; j++) {         z = upper_bound(c, c + n, c[j]) - c - 1;         f[i][j] = sum[i - 1][z];       }       sum[i][0] = f[i][0];       for (j = 1; j < n; j++) sum[i][j] = (f[i][j] + sum[i][j - 1]) % mo;     }     for (i = 1; i <= K; i++) {       ans = (ans + (N - i + 1) * sum[i][n - 1]) % mo;       for (j = 0; j < r; j++) {         z = upper_bound(c, c + n, a[j]) - c - 1;         ans = (ans + sum[i - 1][z]) % mo;       }     }     if (r && K + 1 <= k) {       i = K + 1;       for (j = 0; j < r; j++) {         z = upper_bound(c, c + n, a[j]) - c - 1;         ans = (ans + sum[i - 1][z]) % mo;       }     }     ans = (ans + mo) % mo;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, flag, c, k, x, z, n, m, a[300007];   int main() {     cin >> n;     long long lst0 = 0, lst1 = 1;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 0)         lst0 = i + 1;       else         lst1 = i + 1;     }     cout << min(lst0, lst1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int MOD = 1000000007;   const int INF = 1000000001;   const ll LINF = 1000000001000000001LL;   void solve();   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(numeric_limits<double>::max_digits10);     solve();     return 0;   }   void solve() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> a(n);       for (int i = (0); i < ((n)); i++) cin >> a[i];       vector<int> b(n, false);       int p;       for (int i = (0); i < ((m)); i++) {         cin >> p;         p--;         b[p] = true;       }       bool ok = true;       for (int i = (0); i < ((n)); i++) {         for (int j = (i); j < (n); j++) {           if (!b[j]) {             for (int k = (j + 1); k < (n); k++) {               if (a[i] > a[k]) {                 ok = false;                 break;               }             }             if (!ok) break;           }         }         if (!ok) break;         for (int j = (i - 1); j < (0); j++) {           if (!b[j]) {             for (int k = (0); k < ((j + 1)); k++) {               if (a[i] < a[k]) {                 ok = false;                 break;               }             }             if (!ok) break;           }         }         if (!ok) break;       }       cout << (ok ?  YES  :  NO ) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400000 + 5;   vector<int> G[maxn];   int n;   int down[maxn], up[maxn], sz[maxn], par[maxn];   void dfs(int u, int fa) {     int len = G[u].size();     par[u] = fa;     sz[u] = 1;     for (int i = 0; i < len; i++) {       int v = G[u][i];       if (v == fa) continue;       dfs(v, u);       sz[u] += sz[v];     }   }   void dfs_down(int u, int fa) {     int len = G[u].size();     down[u] = (sz[u] <= n / 2) ? sz[u] : 0;     for (int i = 0; i < len; i++) {       int v = G[u][i];       if (v == fa) continue;       dfs_down(v, u);       down[u] = max(down[u], down[v]);     }   }   void dfs_up(int u, int val = 0, int fa = -1) {     if (val <= n / 2) {       up[u] = max(val, up[u]);     }     if (n - sz[u] <= n / 2) {       up[u] = max(n - sz[u], up[u]);     }     int len = G[u].size();     int m0 = 0, m1 = 0;     for (int i = 0; i < len; i++) {       int v = G[u][i];       if (v == fa) continue;       if (down[v] >= m0) {         m1 = m0;         m0 = down[v];       } else if (down[v] >= m1) {         m1 = down[v];       }     }     for (int i = 0; i < len; i++) {       int v = G[u][i];       if (v == fa) continue;       dfs_up(v, max(up[u], down[v] == m0 ? m1 : m0), u);     }   }   int ans[maxn];   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, -1);     dfs_down(1, -1);     dfs_up(1, 0, -1);     for (int u = 1; u <= n; u++) {       ans[u] = 1;       int len = G[u].size();       for (int j = 0; j < len; j++) {         int v = G[u][j];         if (v == par[u]) {           if (n - sz[u] - up[u] > n / 2) ans[u] = 0;         } else {           if (sz[v] - down[v] > n / 2) ans[u] = 0;         }       }     }     printf(  n );     for (int i = 1; i <= n; i++) {       printf( %d%c , ans[i], i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10, C = 30;   int nex[N][C], p, n, par[N], dfa[N][C];   string s, t;   vector<pair<int, char> > adj_matrix[N];   long long ans;   void dfs(int v, int p, int state) {     if (state == (int)t.size()) ans++;     for (auto pa : adj_matrix[v]) {       int u = pa.first;       char c = pa.second;       if (u == p) continue;       dfs(u, v, nex[state][c -  a ]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     int cur = n + 1;     for (int i = 1; i < n; i++) {       cin >> p;       p--;       cin >> s;       int j = 0, lp = p;       while (j + 1 < s.size()) {         adj_matrix[lp].push_back({cur, s[j]});         lp = cur;         j++;         cur++;       }       adj_matrix[lp].push_back({i, s[j]});     }     cin >> t;     nex[0][t[0] -  a ] = 1;     int l = 0;     for (int i = 1; i <= (int)t.size(); i++) {       for (int j = 0; j < 28; j++) {         if (i < (int)t.size()) {           if (j == (t[i] -  a ))             nex[i][j] = i + 1;           else             nex[i][j] = nex[l][j];         } else           nex[i][j] = nex[l][j];       }       if (i < (int)t.size()) l = nex[l][t[i] -  a ];     }     dfs(0, 0, 0);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int bef[100050];   int main() {     string s, s1;     cin >> s;     int len = s.size();     int last_a = -1;     int now = 0;     for (int i = 0; i < len; i++) {       if (s[i] !=  a ) {         s1 += s[i];         bef[now] = i;         now++;       } else {         last_a = i;       }     }     if (now % 2 == 1)       cout <<  :(  << endl;     else {       for (int i = 0; i < now / 2; i++) {         if (s1[i] != s1[i + now / 2]) {           cout <<  :(  << endl;           return 0;         }       }       if (last_a == -1 || bef[now / 2] > last_a || now == 0) {         for (int i = 0; i < (now != 0 ? bef[now / 2] : len); i++) {           cout << s[i];         }         cout << endl;       } else {         cout <<  :(  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 3e5 + 10, oo = 1e9, M = 64;   long long const OO = 1e18;   int mod = oo + 7;   double const eps = 1e-4, PI = acos(-1);   int n, k, in[N];   int cc = 0, m = 0, cnt = 0;   vector<int> dv[N];   bool brute(int i, int h) {     if (h > k) return 0;     if (i == m + 1) return h == k;     if (h == k) return 1;     int y = 0;     for (auto v : dv[i])       if (in[v]) y++;     in[i] = 1;     cnt++;     if (brute(i + 1, h + y)) return 1;     cnt--;     in[i] = 0;     if (brute(i + 1, h)) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &k);     int all = 0;     for (int i = 1; i <= n; i++)       for (int j = i + i; j <= n; j += i) all++, dv[j].push_back(i);     if (all < k) {       puts( No );       return 0;     }     for (int i = 1; i <= n && cc < k; i++) {       cc += dv[i].size();       in[i] = 1;       cnt++;       m++;     }     if (m < 10000) {       cnt = 0;       memset(in, 0, sizeof in);       brute(1, 0);     } else       for (int i = m; cc != k; i--)         if ((int)dv[i].size() == 1) cc--, in[i] = 0, cnt--;     puts( Yes );     printf( %d n , cnt);     for (int i = 1; i <= m; i++)       if (in[i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   long long a[20][10][10], b[20][10][10], c[20];   int read_int() {     int a = 0;     int b = 1, c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;     return a;   }   int findmax(long long n) {     long long temp = n;     int m = 0;     while (temp > 0) {       if (temp % 10 > m) m = temp % 10;       temp = temp / 10;     }     return m;   }   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     long long n;     cin >> n;     long long m, total;     for (int l = 0; l < 19; l++)       for (int x = 9; x >= 0; x--)         for (int y = 0; y <= 9; y++) {           total = 0;           if (!l)             if (!x)               if (y) {                 b[l][x][y] = 1;                 a[l][x][y] = 0;               } else {                 b[l][x][y] = 0;                 a[l][x][y] = 0;               }             else if (x > y) {               a[l][x][y] = y + 10 - x;               b[l][x][y] = 1;             } else {               a[l][x][y] = 10 - x;               b[l][x][y] = 2;             }           else {             total = 0;             m = y;             for (int j = 9; j >= 0; j--) {               total += b[l - 1][x > j ? x : j][m];               m = a[l - 1][x > j ? x : j][m];             }             a[l][x][y] = m;             b[l][x][y] = total;           }         }     m = n % 10;     long long K = n / 10, res = 0;     int len = 0;     while (1) {       while (K % 10 != 9 && K) {         res += b[len][findmax(K)][m];         m = a[len][findmax(K)][m];         K--;       }       if (!K) {         res += b[len][0][m];         break;       }       K /= 10;       len++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, ar[10];     cin >> a >> b >> c;     ar[0] = a + b + c;     ar[1] = a * b * c;     ar[2] = a + b * c;     ar[3] = a * b + c;     ar[4] = (a + b) * c;     ar[5] = a * (b + c);     sort(ar, ar + 6);     cout << ar[6 - 1];   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n;   int a[maxn];   int nivel[maxn], in[maxn], out[maxn], tt;   vector<int> grafo[maxn];   struct BinaryLifting {     int tab[maxn][20];     void dfs(int u, int p) {       in[u] = ++tt;       for (auto v : grafo[u]) {         if (v == p) continue;         nivel[v] = nivel[u] + 1, tab[v][0] = u;         dfs(v, u);       }       out[u] = tt;     }     void build(void) {       for (int j = 1; j < 20; j++)         for (int i = 1; i <= n; i++) tab[i][j] = tab[tab[i][j - 1]][j - 1];     }     int intersect(int u, int v, int w_u, int w_v) {       if (nivel[u] < nivel[v]) swap(u, v), swap(w_u, w_v);       for (int i = 19; i >= 0; i--)         if (nivel[u] - (1 << i) >= nivel[v] && w_u >= (1 << i))           u = tab[u][i], w_u -= (1 << i);       if (nivel[u] != nivel[v]) return -1;       if (u == v) return u;       for (int i = 19; i >= 0; i--)         if (tab[u][i] && tab[v][i] && tab[u][i] != tab[v][i] &&             min(w_u, w_v) >= (1 << i))           u = tab[u][i], v = tab[v][i], w_u -= (1 << i), w_v -= (1 << i);       if (tab[u][0] != tab[v][0] || min(w_u, w_v) == 0) return -1;       return tab[u][0];     }     int dist(int u, int v) {       return nivel[u] + nivel[v] - 2 * nivel[intersect(u, v, nivel[u], nivel[v])];     }     int get_intersection(int u, int v, int root) {       int k = -1;       int lca_u = intersect(u, root, nivel[u], nivel[root]);       int lca_v = intersect(v, root, nivel[v], nivel[root]);       int aux = intersect(u, v, nivel[u] - nivel[lca_u], nivel[v] - nivel[lca_v]);       if (k == -1 || (aux != -1 && dist(aux, root) > dist(k, root))) k = aux;       aux =           intersect(u, root, nivel[u] - nivel[lca_u], nivel[root] - nivel[lca_v]);       if (k == -1 || (aux != -1 && dist(aux, root) > dist(k, root))) k = aux;       aux =           intersect(root, v, nivel[root] - nivel[lca_u], nivel[v] - nivel[lca_v]);       if (k == -1 || (aux != -1 && dist(aux, root) > dist(k, root))) k = aux;       aux = intersect(root, root, nivel[root] - nivel[lca_u],                       nivel[root] - nivel[lca_v]);       if (k == -1 || (aux != -1 && dist(aux, root) > dist(k, root))) k = aux;       return k;     }     int kth(int u, int k) {       for (int i = 19; i >= 0; i--)         if (tab[u][i] && k >= (1 << i)) u = tab[u][i], k -= (1 << i);       return u;     }   } LCA;   struct SegmentTree {     long long tree[3 * maxn], lazy[3 * maxn];     void flush(int node, int l, int r) {       if (!lazy[node]) return;       if (l != r) {         lazy[2 * node] += lazy[node];         lazy[2 * node + 1] += lazy[node];       }       tree[node] += 1ll * (r - l + 1) * lazy[node];       lazy[node] = 0;     }     void upd(int node, int l, int r, int a, int b, int v) {       flush(node, l, r);       if (l > b || r < a) return;       if (l >= a && r <= b) {         lazy[node] = 1ll * v;         flush(node, l, r);         return;       }       int mid = (l + r) >> 1;       upd(2 * node, l, mid, a, b, v);       upd(2 * node + 1, mid + 1, r, a, b, v);       tree[node] = tree[2 * node] + tree[2 * node + 1];     }     long long query(int node, int l, int r, int a, int b) {       flush(node, l, r);       if (l > b || r < a) return 0;       if (l >= a && r <= b) return tree[node];       int mid = (l + r) >> 1;       return query(2 * node, l, mid, a, b) +              query(2 * node + 1, mid + 1, r, a, b);     }   } seg;   bool is_ancestor(int u, int v) { return (in[v] >= in[u] && out[v] <= out[u]); }   int main(void) {     int q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       grafo[u].push_back(v);       grafo[v].push_back(u);     }     LCA.dfs(1, 0);     LCA.build();     for (int i = 1; i <= n; i++) seg.upd(1, 1, n, in[i], in[i], a[i]);     int root = 1;     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int v;         scanf( %d , &v);         root = v;       } else if (op == 2) {         int u, v, x;         scanf( %d %d %d , &u, &v, &x);         int k = LCA.get_intersection(u, v, root);         if (!is_ancestor(k, root))           seg.upd(1, 1, n, in[k], out[k], x);         else {           seg.upd(1, 1, n, 1, n, x);           if (k != root) {             int w = LCA.kth(root, nivel[root] - nivel[k] - 1);             seg.upd(1, 1, n, in[w], out[w], -x);           }         }       } else {         int u;         scanf( %d , &u);         if (!is_ancestor(u, root))           printf( %lld n , seg.query(1, 1, n, in[u], out[u]));         else {           if (u == root)             printf( %lld n , seg.query(1, 1, n, 1, n));           else {             int w = LCA.kth(root, nivel[root] - nivel[u] - 1);             printf( %lld n ,                    seg.query(1, 1, n, 1, n) - seg.query(1, 1, n, in[w], out[w]));           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   #define nl   n    void solve()   {       int n;       cin >> n;       int arr[n][n];       int x = 1;       for(int i=0;i<n;i++){           for(int j=0;j<n;j++){               if(i==j){                   arr[i][j]=x;                   x++;               }           }       }       for (int k = 1; k <= 2 * n - 2; k++)       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   if(i!=j){                       if (i + j == k)                   {                       arr[i][j] = x;                       x++;                   }                   }               }           }       }       if (n == 1)       {           cout << 1 <<   n ;           return;       }       else if (n == 2)       {           cout << -1 <<   n ;       }       else       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   cout << arr[i][j] <<    ;               }               cout <<   n ;           }       }   }   int main()   {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       srand(chrono::high_resolution_clock::now().time_since_epoch().count());       int t;       cin >> t;       while (t--)       {           solve();       }       return 0;   }


#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   int primes[100000];   using namespace std;   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long sum = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       long long p = sum / k;       cout << abs(p - ans) <<    ;       ans = p;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int num) {     for (int i = 2; i <= sqrt(num) + 1; ++i) {       if (num % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (n < 9) {       cout << 1 << endl;       cout << n << endl;     } else if (n == 9) {       cout << 3 << endl;       cout << 3 <<     << 3 <<     << 3 << endl;     } else if (n == 11) {       cout << 3 << endl;       cout << 3 <<     << 3 <<     << 5 << endl;     } else {       cout << 3 << endl;       n -= 3;       for (int i = 3; i <= n / 2; ++i) {         if (isPrime(i) && isPrime(n - i)) {           cout << 3 <<     << i <<     << n - i << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool yes(int x1, int x2, int x3, int x4) {     int num1 = (x1 + x2 + x3 + x4) / 4, num2 = (x2 + x3) / 2, num3 = x4 - x1;     if (((x1 + x2 + x3 + x4) % 4 != 0) || ((x2 + x3) % 2 != 0) || num1 != num2 ||         num1 != num3 || x1 == -1 || x2 == -1 || x3 == -1 || x4 == -1)       return false;     if (x1 <= x2 && x2 <= x3 && x3 <= x4) return true;     return false;   }   bool fun(int x1, int x2, int x3, int x4, vector<int> sol) {     for (int i = 1; i <= 2000; i++) {       vector<int> Sol = sol;       int X1 = x1, X2 = x2, X3 = x3, X4 = x4;       x1 = i;       x4 = i * 3;       if (x2 == -1 && x3 != -1)         x2 = x4 + x1 - x3, sol.push_back(x2);       else if (x2 != -1 && x3 == -1)         x3 = x4 + x1 - x2, sol.push_back(x3);       else if (x2 != -1 && x3 != -1 && x2 + x3 != x1 + x4)         continue;       if (yes(x1, x2, x3, x4)) {         cout <<  YES n ;         for (int i = 0; i < (int)sol.size(); i++) cout << sol[i] <<   n ;         return true;       }       x1 = X1, x2 = X2, x3 = X3, x4 = X4, sol = Sol;     }     return false;   }   bool Fun(int x1, int x2, int x3, int x4, vector<int> sol) {     for (int i = 1; i <= 2000; i++) {       x2 = i;       x3 = x4 + x1 - x2;       vector<int> Sol = sol;       sol.push_back(x2);       sol.push_back(x3);       if (yes(x1, x2, x3, x4)) {         cout <<  YES n ;         for (int I = 0; I < (int)sol.size(); I++) cout << sol[I] << endl;         return true;       }       sol = Sol;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int ar[4];     memset(ar, -1, sizeof(ar));     for (int i = 0; i < n; i++) cin >> ar[i];     if (n == 0) {       cout <<  YES n1 n1 n3 n3 ;       goto ss;     }     for (int i = 0; i < 4; i++)       for (int i1 = 0; i1 < 4; i1++)         for (int i2 = 0; i2 < 4; i2++)           for (int i3 = 0; i3 < 4; i3++) {             if (i == i1 || i == i2 || i == i3 || i1 == i2 || i1 == i3 || i2 == i3)               continue;             vector<int> sol;             int x1 = ar[i], x2 = ar[i1], x3 = ar[i2], x4 = ar[i3];             if (x1 != -1 && x4 != -1) {               if (x1 * 3 != x4) continue;             } else if (x1 == -1 && x4 != -1) {               x1 = x4 / 3;               if (x4 % 3 != 0) continue;               sol.push_back(x1);             } else if (x1 != -1 && x4 == -1) {               x4 = x1 * 3;               sol.push_back(x4);             } else if (x1 == -1 && x4 == -1)               if (fun(x1, x2, x3, x4, sol)) goto ss;             if (x2 == -1 && x3 == -1) {               if (Fun(x1, x2, x3, x4, sol)) goto ss;             } else if (x2 == -1) {               x2 = x4 + x1 - x3;               sol.push_back(x2);             } else if (x3 == -1) {               x3 = x4 + x1 - x2;               sol.push_back(x3);             }             if (yes(x1, x2, x3, x4)) {               cout <<  YES n ;               for (int I = 0; I < (int)sol.size(); I++) cout << sol[I] <<   n ;               goto ss;             }           }     cout <<  NO ;   ss:     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[120000];   int main() {     cin >> n >> k;     for (int i = 0; i < n * 2; i++) a[i] = i;     for (int i = 0; i < k; i++) {       int now = i * 2;       swap(a[now], a[now + 1]);     }     k = n - k;     for (int i = 0; i < n * 2; i++) {       printf( %d  , a[i] + 1);     }     puts(  );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _dbg(const char* _s, T _h) {     cerr << _s <<   =   << _h <<   n ;   }   template <typename T, typename... Ts>   void _dbg(const char* _s, T _h, Ts... _t) {     int _b = 0;     while (((_b += *_s ==  ( ) -= *_s ==  ) ) != 0 || *_s !=  , ) cerr << *_s++;     cerr <<   =   << _h <<  , ;     _dbg(_s + 1, _t...);   }   const int64_t INF = static_cast<int64_t>(1e9) + 7;   const int64_t LINF = INF * INF;   const int MAXN = static_cast<int>(1e6) + 17;   void solve() {     int n;     int64_t second;     cin >> n >> second;     vector<int> v(n);     int64_t sum = 0;     int right = INF;     for (auto& el : (v)) {       cin >> el;       sum += el;       right = min(right, el);     }     if (sum < second) {       cout <<  -1 n ;       return;     }     ++right;     int left = 0;     while (right - left > 1) {       int mid = (left + right) / 2;       int64_t amount = 0;       for (int i = 0; i < n; ++i) {         amount += v[i] - mid;       }       if (amount >= second) {         left = mid;       } else {         right = mid;       }     }     cout << left;   }   int main() {     cin.tie(nullptr);     cout.tie(nullptr);     ios_base::sync_with_stdio(false);     int q = 1;     for (int i = 0; i < q; ++i) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005], top, s[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     top = -1;     for (int i = n - 1; i >= 0; --i) {       s[++top] = a[i];       while (top > 0 && s[top] == s[top - 1]) ++s[--top];     }     cout << s[0] - top;     return 0;   }


#include <bits/stdc++.h>   const int MaxN = 100111;   const int mod = 1000000009;   int f[MaxN];   int getFather(int x) {     if (f[x] == x) return f[x];     return f[x] = getFather(f[x]);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i;     int ans = 0;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (getFather(x) == getFather(y))         ans = ((ans * 2) % mod + 1) % mod;       else         f[getFather(y)] = getFather(x);       printf( %d n , ans % mod);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-12;   const int INF = (1 << 31) - 1;   const long long LLINF = ((long long)1 << 62) - 1;   const int maxn = 1000 * 100 + 10;   int a[maxn], sum[maxn], sum2[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (i)         sum[i] = sum[i - 1] + a[i];       else         sum[i] = a[i];     }     string s;     getline(cin, s);     getline(cin, s);     for (int i = (int)s.size() - 1; i >= 0; i--) {       if (i != (int)s.size() - 1) {         sum2[i] = sum2[i + 1] + (s[i] -  0 ) * a[i];       } else {         sum2[i] = (s[i] -  0 ) * a[i];       }     }     long long maxx = 0LL;     for (int i = (int)s.size() - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         long long cur = 0LL;         cur = sum[i - 1];         cur += sum2[i + 1];         maxx = max(maxx, cur);       }     }     printf( %lld , max(maxx, (long long)sum2[0]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   inline void inp(T &...args) {     ((cin >> args), ...);   }   template <typename T>   inline istream &operator>>(istream &in, vector<T> &a) {     for (auto &x : a) in >> x;     return in;   }   template <typename T, typename U>   inline istream &operator>>(istream &in, pair<T, U> &a) {     in >> a.first >> a.second;     return in;   }   void solve(int &T) {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     cin >> a;     map<long long int, long long int> m;     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       m[a[i]]++;     }     set<long long int> s;     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       if (a[i] <= k) {         long long int x = a[i];         long long int y = k - a[i];         if (m.count(y) and !s.count(min(x, y))) {           if (x == y and m[y] >= 2) {             s.insert(min(x, y));           } else             s.insert(min(x, y));         }       }     }     11;     int ok = 1;     vector<long long int> ans(n, 0);     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       if (s.count(a[i])) {         ans[i] = 1;         if (k % 2 == 0 and a[i] == k / 2) {           ans[i] = ok;           ok ^= 1;         }       }     }     for (auto &X : ans) {       cout << X <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       if (0) cerr <<  Case #  << i <<   n ;       solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   long long ln, lk, lm;   int a[10];   bool v[9], vv[9];   bool walk(int x) {     v[x] = 1;     if (a[x] == 1 || vv[a[x]]) return vv[x] = 1;     if (v[a[x]]) return 0;     return vv[x] = walk(a[x]);   }   bool ck() {     for (int i = 2; i <= k; i++) {       v[i] = 0;       vv[i] = 0;     }     for (int i = 2; i <= k; i++)       if (!v[i]) {         if (!walk(i)) {           return 0;         }       }     return 1;   }   long long tmp;   void dfs(int x) {     if (x == k + 1) {       if (ck()) tmp++;       return;     }     for (int(i) = 1; (i) <= (int)(k); (i)++)       if (i != x) {         a[x] = i;         dfs(x + 1);       }   }   int main() {     scanf( %d%d , &n, &k);     long long ans = k;     dfs(2);     (ans *= tmp) %= 1000000007;     m = n - k;     for (int i = k + 1; i <= n; i++) {       (ans *= m) %= 1000000007;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   long long ans[MAXN], b[MAXN];   int n, first[65], cnt_ans;   bool selected[MAXN];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &b[i]);     std::sort(b, b + n);     memset(first, 0xff, sizeof(first));     for (int i = 0; i < n; i++) {       for (int j = 60; j >= 0; j--) {         if (b[i] >> j & 1) {           if (first[j] == -1) first[j] = i;           break;         }       }     }     long long cur = 0;     bool flag = true;     for (int i = 0; i < n; i++) {       int j;       for (j = 0; j <= 60; j++)         if (!(cur >> j & 1)) {           if (first[j] != -1 && !selected[first[j]]) {             selected[first[j]] = true;             cur ^= b[first[j]];             ans[cnt_ans++] = b[first[j]++];             if (!(b[first[j]] >> j)) first[j] = -1;             break;           }         }       if (j == 61) {         flag = false;         break;       }     }     if (flag) {       printf( Yes n );       for (int i = 0; i < n; i++) printf( %lld  , ans[i]);       printf(  n );     } else {       printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   char c[10];   int vl(int x, int y) {     printf( 1 %d %d n , x, y), fflush(stdout);     return scanf( %s , c), c[0] ==  T ;   }   int ef(int L, int R) {     for (; L < R;)       vl((L + R >> 1), (L + R >> 1) + 1) ? R = (L + R >> 1)                                          : L = (L + R >> 1) + 1;     return L;   }   int main() {     scanf( %d%d , &N, &K);     int Ans1 = ef(1, N), Ans2 = ef(1, Ans1 - 1);     if (Ans1 == Ans2 || !vl(Ans2, Ans1)) Ans2 = ef(Ans1 + 1, N);     printf( 2 %d %d n , Ans1, Ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int b, f, p, h, c, money = 0;       scanf( %d %d %d %d %d , &b, &p, &f, &h, &c);       b /= 2;       if (h > c) {         money = min(b, p) * h;         b -= min(b, p);         money += min(b, f) * c;       } else {         money = min(b, f) * c;         b -= min(b, f);         money += min(b, p) * h;       }       printf( %d n , money);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       int n, m;       cin >> n >> m;       vector<int> a(n + 2);       for (int i = 1; i <= n; i++) cin >> a[i];       a[0] = 0, a[n + 1] = m;       vector<int> light(n + 2, 0), dark(n + 2, 0);       for (int i = 1; i <= n + 1; i++) {         light[i] = light[i - 1], dark[i] = dark[i - 1];         if (i % 2)           light[i] += a[i] - a[i - 1];         else           dark[i] += a[i] - a[i - 1];       }       int ans = light[n + 1];       for (int i = 1; i <= n + 1; i++) {         ans =             max(ans, light[i - 1] + dark[n + 1] - dark[i] + a[i] - a[i - 1] - 1);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 23;   bool a[maxn];   bool vis[maxn];   int n, m, x;   void dfs(int x) {     if (vis[x]) return;     vis[x] = true;     for (int i = 0; i <= n; i++)       if (x & (1 << i)) dfs(x ^ (1 << i));     if (a[x]) dfs((1 << n) - 1 - x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) scanf( %d , &x), a[x] = true;     int ans = 0;     for (int i = 0; i < (1 << n); i++)       if (!vis[i] && a[i]) dfs(i), ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, pos, lpos;     int q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       cin >> pos;       while (pos % 2 == 0) {         lpos = pos / 2 + 1;         pos += n - lpos + 1;       }       cout << pos / 2 + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long N = 1e5 + 10;   const long long bits = 30;   const long long mod = 1e9 + 7;   const long double pi = 3.14159265358979323846;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     std::cout << std::fixed << std::setprecision(20);     ;     long double n;     cin >> n;     long double ans = 0;     for (long double i = 1; i <= n; i++) {       ans += (long double)1.0 / i;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int nx[10000][26], al[26], l1, l2;   string s1, s2;   int main() {     cin >> s1 >> s2;     l1 = s1.size();     l2 = s2.size();     for (int i = 0; i < l1; i++) fill(nx[i], nx[i] + 26, -1);     fill(al, al + 26, -1);     for (int i = l1 - 1; i >= 0; i--) al[s1[i] -  a ] = i;     for (int i = l1 - 1; i >= 0; i--) {       for (int j = 0; j < 26; j++) nx[i][j] = al[j];       al[s1[i] -  a ] = i;     }     int cur = l1 - 1, ans = 0;     for (int i = 0; i < l2; i++) {       if (nx[cur][s2[i] -  a ] == -1) {         cout << -1 << endl;         return 0;       }       if (nx[cur][s2[i] -  a ] <= cur) ans++;       cur = nx[cur][s2[i] -  a ];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline long long Getint() {     char ch = getchar();     long long x = 0, fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       (x *= 10) += ch ^ 48;       ch = getchar();     }     return fh * x;   }   const int N = 200005;   int n, h;   long long mod, fc[N], fiv[N], inv[N], sm[N];   int su[N];   struct nod {     int a, l;     nod(int x = 0, int y = 0) {       a = x;       l = y;     }   };   vector<nod> a;   inline long long Solve(int l1, int l2) {     long long Ans = 1ll * l1 * l2 % mod * inv[2] % mod;     for (int i = 1; i <= l1; i++) (Ans += sm[i] - sm[i + l2] + mod) %= mod;     return (Ans % mod + mod) % mod;   }   void Build(int l, int r, int h) {     if (h == 1) {       su[r - l + 1]++;       return;     }     if (l == r) {       su[1]++;       return;     }     int mid = l + r >> 1;     Build(l, mid, h - 1);     Build(mid + 1, r, h - 1);   }   int main() {     n = Getint();     h = Getint();     mod = Getint();     fc[0] = fc[1] = fiv[0] = fiv[1] = inv[0] = inv[1] = 1;     for (int i = 2; i <= N - 1; i++) {       fc[i] = fc[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       fiv[i] = fiv[i - 1] * inv[i] % mod;     }     for (int i = 1; i <= N - 1; i++) {       sm[i] = (sm[i - 1] + inv[i]) % mod;     }     Build(1, n, h);     long long Ans = 0;     for (int i = 1; i <= n; i++) {       if (!su[i]) continue;       a.push_back(nod(su[i], i));       (Ans += 1ll * su[i] * i % mod * (i - 1) % mod * inv[4]) %= mod;     }     for (int i = 0; i <= int(a.size()) - 1; i++) {       (Ans += 1ll * a[i].a * (a[i].a - 1) % mod * inv[2] % mod *               Solve(a[i].l, a[i].l)) %= mod;       for (int j = i + 1; j <= int(a.size()) - 1; j++) {         (Ans += 1ll * a[i].a * a[j].a % mod * Solve(a[i].l, a[j].l)) %= mod;       }     }     cout << Ans % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int G = 2520;   const int B = 41;   const int MAXN = B * G;   unsigned char S[G][B], ps[B + 1][G][4], mp[256];   string e;   void Pre() {     mp[ A ] = 0;     mp[ G ] = 1;     mp[ T ] = 2;     mp[ C ] = 3;   }   void build(int g) {     for (int i = 0; i < 4; i++) {       ps[0][g][i] = 0;       for (int j = 0; j < B; j++) ps[j + 1][g][i] = ps[j][g][i] + (S[g][j] == i);     }   }   void chng(int p, char c) {     S[p % G][p / G] = c;     build(p % G);   }   inline int nxt(int x, int y) {     if (x % G <= y)       return (x + (y - x % G)) / G;     else       return (x + (G + y - x % G)) / G;   }   inline int get(int g, int l, int r, int x) { return ps[r][g][x] - ps[l][g][x]; }   int t(int i) { return e[i % e.size()]; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     Pre();     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) S[i % G][i / G] = mp[s[i]];     for (int i = 0; i < G; i++) build(i);     int q;     cin >> q;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int x;         char c;         cin >> x >> c;         x--;         chng(x, mp[c]);       } else {         int l, r;         cin >> l >> r >> e;         l--;         int ans = 0;         for (int i = 0; i < G; i++) {           ans += get(i, nxt(l, i), nxt(r, i), mp[t((i - l % G + G) % G)]);         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 9e4;   const int INF = 1 << 30;   const long long mod = 1e9 + 7;   const double eps = 1e-8;   int main() {     long long a[100] = {0,   4,   10,  20,  35,  56,  83, 116,                         155, 198, 244, 292, 341, 390, 439};     long long n;     while (cin >> n)       if (n <= 14)         cout << a[n] << endl;       else         cout << a[14] + (long long)49 * (n - 14) << endl;   }


#include <bits/stdc++.h>   int main() {     int tab[2000], i, max = 0, posmax = 0, index = -1, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &tab[i]);       if (tab[i] > max) {         max = tab[i];         posmax = i + 1;       }     }     while (max-- && index == -1)       for (i = 0; i < n; i++)         if (tab[i] == max) {           index = i;           break;         }     printf( %d %d , posmax, tab[index]);     return 0;   }


#include <bits/stdc++.h>   char bar[1000002];   int main() {     scanf( %s , bar);     int n = strlen(bar);     long long int left = 0, mid = 0, right = 0;     for (int i = 0; bar[i] !=  ^ ; i++) mid = i + 1;     for (int i = 0; bar[i] !=  ^ ; i++)       if (bar[i] !=  = ) left += (mid - i) * (bar[i] -  0 );     for (int i = n - 1; bar[i] !=  ^ ; i--)       if (bar[i] !=  = ) right += (i - mid) * (bar[i] -  0 );     if (left < right) puts( right );     if (right < left) puts( left );     if (right == left) puts( balance );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, char> > > adj(201);   int dp[101][101][26][2];   bool solve(int i, int j, char round, bool turn) {     if (dp[i][j][(int)(round -  a )][turn] != -1)       return dp[i][j][(int)(round -  a )][turn];     int ret = 0;     if (!turn) {       for (int k = 0; k < adj[i].size(); k++) {         if (adj[i][k].second >= round)           if (!solve(adj[i][k].first, j, adj[i][k].second, !turn)) ret = 1;       }     } else {       for (int k = 0; k < adj[j].size(); k++) {         if (adj[j][k].second >= round)           if (!solve(i, adj[j][k].first, adj[j][k].second, !turn)) ret = 1;       }     }     return dp[i][j][(int)(round -  a )][turn] = ret;   }   int main() {     memset(dp, -1, sizeof dp);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       char z;       cin >> x >> y >> z;       adj[x].push_back({y, z});     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int h = solve(i, j,  a , 0);         if (h == 1)           cout <<  A ;         else           cout <<  B ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     unsigned long long dp[1000000];     unsigned long long ans = 0;     for (long long i = 1; i <= 500000; i += 2) {       long long val = (i * i - (i - 2) * (i - 2)) * (i / 2);       ans = ans + val;       dp[i] = ans;     }     while (t--) {       long n;       cin >> n;       cout << dp[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> w[200000 + 20];   int a[200000 + 20][3];   vector<pair<int, pair<int, int> > > to_compress;   int n;   void maximize(int &a, int b) {     if (a < b) a = b;   }   struct Fenwick_tree {     int bit[1000000 + 50];     void update(int x, int v) {       for (; x <= 1000000; x += x & (-x)) maximize(bit[x], v);     }     int get(int x) {       int res = 0;       for (; x > 0; x -= x & (-x)) maximize(res, bit[x]);       return res;     }   };   Fenwick_tree LIS;   int ans = 0;   void compress() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &w[i].first, &w[i].second);     sort(w + 1, w + 1 + n);     for (int i = 1; i <= n; i++) {       to_compress.push_back(pair<int, pair<int, int> >(w[i].first + w[i].second,                                                        pair<int, int>(i, 1)));       to_compress.push_back(pair<int, pair<int, int> >(w[i].first - w[i].second,                                                        pair<int, int>(i, 2)));     }     sort(to_compress.begin(), to_compress.end());     int curr = 0;     for (int i = 0; i < to_compress.size(); i++) {       if (i == 0 || to_compress[i].first > to_compress[i - 1].first) curr++;       a[to_compress[i].second.first][to_compress[i].second.second] = curr;     }   }   void solve() {     for (int i = 1; i <= n; i++) {       int x = LIS.get(a[i][2]) + 1;       maximize(ans, x);       LIS.update(a[i][1], x);     }     printf( %d , ans);   }   int main() {     compress();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a, b, q, d, ai, p, t, zb[200001], suma[800005], sumb[800005],       za[200001], res;   void build1(int a[], int v, int tl, int tr) {     if (tl == tr)       suma[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build1(a, v * 2, tl, tm);       build1(a, v * 2 + 1, tm + 1, tr);       suma[v] = suma[v * 2] + suma[v * 2 + 1];     }   }   void build2(int a[], int v, int tl, int tr) {     if (tl == tr)       sumb[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build2(a, v * 2, tl, tm);       build2(a, v * 2 + 1, tm + 1, tr);       sumb[v] = sumb[v * 2] + sumb[v * 2 + 1];     }   }   int sum1(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (l == tl && r == tr) return suma[v];     int tm = (tl + tr) / 2;     return sum1(v * 2, tl, tm, l, min(r, tm)) +            sum1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);   }   int sum2(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (l == tl && r == tr) return sumb[v];     int tm = (tl + tr) / 2;     return sum2(v * 2, tl, tm, l, min(r, tm)) +            sum2(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);   }   void update1(int v, int tl, int tr, int pos, long long new_val) {     if (tl == tr)       suma[v] = new_val;     else {       int tm = (tl + tr) / 2;       if (pos <= tm)         update1(v * 2, tl, tm, pos, new_val);       else         update1(v * 2 + 1, tm + 1, tr, pos, new_val);       suma[v] = suma[v * 2] + suma[v * 2 + 1];     }   }   void update2(int v, int tl, int tr, int pos, long long new_val) {     if (tl == tr)       sumb[v] = new_val;     else {       int tm = (tl + tr) / 2;       if (pos <= tm)         update2(v * 2, tl, tm, pos, new_val);       else         update2(v * 2 + 1, tm + 1, tr, pos, new_val);       sumb[v] = sumb[v * 2] + sumb[v * 2 + 1];     }   }   int main() {     scanf( %d %d %d %d %d , &n, &k, &b, &a, &q);     for (int i = 0; i < n; i++) zb[i] = b;     for (int i = 0; i < n; i++) za[i] = a;     build1(za, 1, 0, n - 1);     build2(zb, 1, 0, n - 1);     for (int i = 0; i < q; i++) {       scanf( %d , &t);       if (t == 1) {         scanf( %d %d , &d, &ai);         d--;         za[d] -= ai;         zb[d] -= ai;         if (za[d] < 0) za[d] = 0;         if (zb[d] < 0) zb[d] = 0;         update1(1, 0, n - 1, d, za[d]);         update2(1, 0, n - 1, d, zb[d]);       } else {         scanf( %d , &p);         p--;         int size1 = p;         int size2 = n - k - p;         res = 0;         int resa = 0, resb = 0;         resa -= sum1(1, 0, n - 1, 0, size1 - 1);         resa += size1 * a;         resb -= sum2(1, 0, n - 1, n - size2, n - 1);         resb += size2 * b;         printf( %d n , resa + resb);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long t;   long long n;   int x;   int main() {     ios::sync_with_stdio(0);     cin.tie(), cout.tie();     cin >> t;     while (t--) {       cin >> n;       set<int> s;       int count = 0;       for (int i = 0; i < n; i++) {         cin >> x;         if (s.find(x) == s.end()) {           count++;           s.insert(x);         }       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   long long n, k, fd, gcd, sum = 0;   int main() {     cin >> n >> k;     if (k > sqrt(2 * n)) {       cout <<  -1 n ;     } else {       if ((k * (k + 1)) / 2 > n) {         cout << -1;       } else {         fd = -1;         for (long long i = (k * (k + 1)) / 2; i <= N; i++) {           if (n % i == 0) {             fd = i;             break;           }         }         if (fd == -1) {           for (long long i = N; i >= 1; i--) {             if (n % i == 0 && ((n / i) >= (k * (k + 1)) / 2)) {               gcd = i;               break;             }           }         } else           gcd = n / fd;         for (long long i = 1; i < k; i++) {           sum += gcd * i;           cout << gcd * i <<    ;         }         cout << (n - sum);       }     }   }


#include <bits/stdc++.h>   using namespace std;   string rotate(string s) {     for (int i = 1; i <= 3; i++) {       swap(s[i - 1], s[i]);     }     return s;   }   string rotate2(string s) {     swap(s[0], s[4]);     swap(s[2], s[4]);     swap(s[2], s[5]);     return s;   }   string solve(string s) {     string ans = s;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           s = rotate(s);           ans = min(ans, s);         }         s = rotate2(s);       }       s = rotate(s);     }     return ans;   }   int main() {     string s;     cin >> s;     set<string> st;     sort(s.begin(), s.end());     do {       st.insert(solve(s));     } while (next_permutation(s.begin(), s.end()));     cout << st.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   void In() { cin >> n >> k; }   void Solve() {     k--;     while (k--) {       int largest = INT_MIN, smallest = INT_MAX;       for (long long copy = n; copy; copy /= 10) {         int r = copy % 10;         largest = max(r, largest);         smallest = min(r, smallest);       }       if (largest == 0 || smallest == 0) return;       n += largest * smallest;     }   }   void Out() { cout << n <<   n ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       In();       Solve();       Out();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m1 = 0, m2 = 0, mn1 = INT_MAX, mn2 = INT_MAX, s1 = 0, s2 = 0;     cin >> n;     vector<pair<int, int> > vt;     long long tmp1, tmp2;     for (int i = 0; i < n; i++) {       cin >> tmp1 >> tmp2;       vt.push_back(make_pair(tmp1, tmp2));     }     string ans =   ;     tmp1 = 0, tmp2 = 0;     for (int i = 0; i < n; i++) {       if (tmp2 + vt[i].second <= tmp1 + 500) {         tmp2 += vt[i].second;         ans +=  G ;       } else {         tmp1 += vt[i].first;         ans +=  A ;       }     }     if (!(abs(tmp1 - tmp2) <= 500)) {       cout << -1;       return 0;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long func(long long x, long long y, long long z) {     return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);   }   void solve() {     long long na, nb, nc;     cin >> na >> nb >> nc;     vector<long long> a(na), b(nb), c(nc);     long long i, j, k;     for (i = 0; i < na; i++) cin >> a[i];     for (j = 0; j < nb; j++) cin >> b[j];     for (k = 0; k < nc; k++) cin >> c[k];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     i = j = k = 0;     long long ans, d1, d2, d3;     ans = LLONG_MAX;     while (i < na - 1 || j < nb - 1 || k < nc - 1) {       ans = min(ans, func(a[i], b[j], c[k]));       d1 = d2 = d3 = LLONG_MAX;       if (i < na - 1) d1 = func(a[i + 1], b[j], c[k]);       if (j < nb - 1) d2 = func(a[i], b[j + 1], c[k]);       if (k < nc - 1) d3 = func(a[i], b[j], c[k + 1]);       if (d1 <= d2 && d1 <= d3)         i++;       else if (d2 <= d1 && d2 <= d3)         j++;       else         k++;     }     ans = min(ans, func(a[i], b[j], c[k]));     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 1e6 + 10;   const int AA = 1000;   int dp[2001];   int main() {     long long target_W;     R(target_W);     long long sum = 0;     long long cnt[9], cnt2[9] = {};     for (int i = (1); i <= (8); ++i) {       R(cnt[i]);       sum += cnt[i] * i;     }     if (sum <= target_W)       W(sum);     else {       long long now = 0;       for (int i = (1); i <= (8); ++i) {         if (now + i * cnt[i] <= target_W) {           now += i * cnt[i];           cnt2[i] = cnt[i];           cnt[i] = 0;         } else {           long long v = (target_W - now) / i;           now += i * v;           cnt[i] -= v;           cnt2[i] += v;         }       }       dp[(0) + AA] = 1;       for (int v = (1); v <= (8); ++v) {         for (int j = 0; j < (min(100LL, cnt[v])); ++j) {           for (int k = 900; k >= -900; k--) {             if (dp[(k) + AA]) dp[(k + v) + AA] = 1;           }         }         for (int j = 0; j < (min(100LL, cnt2[v])); ++j) {           for (int k = -900; k <= 900; k++) {             if (dp[(k) + AA]) dp[(k - v) + AA] = 1;           }         }       }       long long an = 0;       for (int i = (0); i <= (target_W - now); ++i) {         if (dp[(i) + AA]) an = now + i;       }       W(an);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int const mod = 1e9 + 7;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int MIN(long long int a, long long int b) {     if (a < b) return a;     return b;   }   long long int MAX(long long int a, long long int b) {     if (a > b) return a;     return b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     bool p[1000001];     memset(p, true, sizeof p);     p[0] = p[1] = false;     p[2] = true;     for (int i = 2; i * i <= 1000001; i++) {       if (p[i]) {         for (int j = i * i; j <= 1000001; j += i) {           p[j] = false;         }       }     }     vector<int> pp;     for (int i = 2; i <= 1000001; i++) {       if (p[i]) pp.push_back(i);     }     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n + 1];       for (int i = 0; i < n; i++) cin >> a[i + 1];       int dp[n + 1], ans = 1;       dp[1] = 1;       for (int i = 2; i <= n; i++) {         dp[i] = 1;         for (int j = 1; j * j <= i; j++) {           if (i % j == 0) {             if (a[i] > a[j]) dp[i] = MAX(dp[i], dp[j] + 1);             if (a[i] > a[i / j]) dp[i] = MAX(dp[i], dp[i / j] + 1);           }         }         ans = MAX(dp[i], ans);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int check_matrix(int** arr, int n, int m) {     int itN = 0, itJ = n - 1;     if (n % 2) return n;     while (itN < itJ) {       for (int i = 0; i < m; ++i)         if (arr[itN][i] != arr[itJ][i]) return n;       itN++;       itJ--;     }     return check_matrix(arr, n / 2, m);   }   int main() {     int n, m, **arr;     std::cin >> n >> m;     arr = new int*[n];     for (int i = 0; i < n; ++i) *(arr + i) = new int[m];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) std::cin >> arr[i][j];     std::cout << check_matrix(arr, n, m);     for (int i = 0; i < n; ++i) delete[] * (arr + i);     delete[] arr;   }