#include <bits/stdc++.h>   using namespace std;   int main() {     string arr[11] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM ,                        SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE };     int n;     cin >> n;     int counter = 0;     string str;     int num_convert;     for (int i = 0; i < n; i++) {       str =   ;       cin >> str;       if (isdigit(str.at(0))) {         num_convert = stoi(str, nullptr, 10);         if (num_convert < 18) {           counter++;         }       } else {         for (int i = 0; i < 11; i++) {           if (str == arr[i]) {             counter++;           }         }       }     }     cout << counter;   }


#include <bits/stdc++.h>   const int LIM = 1e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     if (n % 2) {       cout <<  NO ;       return 0;     } else {       int mid = n / 2;       for (int i = 0; i < mid - 1; i++) {         if (x[i] - x[i + 1] == x[i + mid + 1] - x[i + mid] &&             y[i] - y[i + 1] == y[i + mid + 1] - y[i + mid]) {           continue;         } else {           cout <<  NO ;           return 0;         }       }       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isp(const int x) {     if (x <= 1) return false;     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   int pow(int x, int e, const int MOD) {     int r = 1;     for (; e; e >>= 1, x = (long long)x * x % MOD)       if (e & 1) r = (long long)r * x % MOD;     return r;   }   bool isr(int n, int p) {     for (int i = 2, q = p - 1; i * i <= q; ++i)       if (q % i == 0) {         if (pow(n, i, p) == 1 || pow(n, q / i, p) == 1) return false;       }     return true;   }   int main() {     int n, x;     scanf( %d%d , &n, &x);     if (!isp(n + 1)) return puts( -1 ), 0;     for (--x; x > 1; --x)       if (isr(x, n + 1)) return printf( %d n , x), 0;     return puts( -1 ), 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   long long n, w, b, x, c[1005], cost[1005], f[1005][10005], C, a[10005], tot;   long long cmp(long long x, long long y) { return x > y; }   signed main() {     n = read();     w = read();     b = read();     x = read();     for (long long i = 1; i <= n; i++) c[i] = read(), C += c[i];     for (long long i = 1; i <= n; i++) cost[i] = read();     memset(f, -0x3f, sizeof(f));     f[0][0] = w;     for (long long i = 1; i <= n; i++) {       if (i != 1)         for (long long j = 0; j <= C; j++)           f[i][j] = min(f[i - 1][j] + x, w + b * j);       else         for (long long j = 0; j <= C; j++) f[i][j] = f[i - 1][j];       tot = 0;       for (long long k = 1; k <= c[i]; k *= 2) {         a[++tot] = k;         c[i] -= k;       }       if (c[i]) a[++tot] = c[i];       sort(a + 1, a + tot + 1, cmp);       for (long long k = 1; k <= tot; k++) {         for (long long j = C; j >= a[k]; j--) {           if (f[i][j - a[k]] >= cost[i] * a[k])             f[i][j] = max(f[i][j], f[i][j - a[k]] - cost[i] * a[k]);         }       }     }     long long ans = 0;     for (long long i = C; i >= 0; i--) {       if (f[n][i] >= 0) {         ans = i;         break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void no() { cout <<  NO  << endl; }   void yes() { cout <<  YES  << endl; }   int main() {     int q, n, wyn;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> n;       char a;       string s;       cin >> a;       cin >> s;       if (s.length() == 1 && a >= s[0])         no();       else {         yes();         cout << 2 << endl;         cout << a <<   n  << s << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000;   int degree[maxn + 5];   int Cn_i(int n, int i) {     int up = 1;     int down = 1;     for (int t = n; t >= n - i + 1; t--) {       up = up * t;     }     for (int t = i; t >= 1; t--) {       down = down * t;     }     return up / down;   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) degree[i] = 0;       for (int i = 0; i < n - 1; i++) {         int a, b;         scanf( %d%d , &a, &b);         degree[a]++;         degree[b]++;       }       int ans = 0;       for (int i = 0; i <= n; i++) {         if (degree[i] >= 2) {           ans += Cn_i(degree[i], 2);         }       }       printf( %d n , ans);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   char s[maxn];   int size[maxn], last[200];   bool isover[maxn];   string ans[maxn], now;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> s;     int len = strlen(s);     bool hasdel = false;     now =   ;     for (int no = len - 1; ~no; no--) {       now = s[no] + now;       if (now.size() > 1) {         if (now[0] != now[1]) last[now[0]] = now[1];       }       if (now.size() > 1 && !hasdel) {         if (now[0] == now[1] && now[1] > last[now[1]]) {           now = now.substr(2);           hasdel = true;         }       } else         hasdel = false;       size[no] = now.size();       if (now.size() > 10)         ans[no] = now.substr(0, 5) +  ...  + now.substr(now.size() - 2);       else         ans[no] = now;     }     for (int i = 0; i < len; i++) {       cout << size[i] <<     << ans[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> children[1000005];   int r_1[1000005], r_2[1000005], timer, n, k, p[1000005], mx[1000005 << 2],       inc[1000005 << 2];   stack<int> seq;   vector<int> ans;   void dfs(int node) {     timer++;     r_1[node] = timer;     for (int i = 0; i < children[node].size(); i++) {       int neb = children[node][i];       dfs(neb);     }     r_2[node] = timer;   }   int rt(int r1, int r2, int q1, int q2, int ind, int typ) {     if (q1 > q2) return 0;     if (q1 > r2 || q2 < r1) return 0;     if (q1 <= r1 && q2 >= r2) {       inc[ind] += typ;       return inc[ind] + mx[ind];     } else {       inc[ind * 2] += inc[ind];       inc[ind * 2 + 1] += inc[ind];       inc[ind] = 0;       int mid = (r1 + r2) / 2;       int left = 0, right = 0;       left = rt(r1, mid, q1, q2, ind * 2, typ);       right = rt(mid + 1, r2, q1, q2, ind * 2 + 1, typ);       mx[ind] =           max(mx[ind * 2] + inc[ind * 2], mx[ind * 2 + 1] + inc[ind * 2 + 1]);       return max(left, right);     }   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &p[i]);     p[n] = n + 1;     for (int i = 0; i <= n; i++) {       while (seq.size()) {         int top = seq.top();         if (p[top] >= p[i]) break;         children[i].push_back(top);         seq.pop();       }       seq.push(i);     }     dfs(n);     for (int i = n - 1; i >= 0; i--) {       if (i + k <= n) {         ans.push_back(rt(1, timer, r_1[i + k - 1], r_1[i], 1, 0) + 1);         rt(1, timer, r_1[i + k - 1] + 1, r_2[i + k - 1], 1, -1);       }       rt(1, timer, r_1[i] + 1, r_2[i], 1, 1);     }     reverse(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> gph[500005];   int n, par[500005], dep[500005], msk[500005];   int dp[500005], sz[500005];   int mx[1 << 22];   int l[23] = {};   void dfs2(int x, vector<pair<int, int> > &v) {     v.push_back(pair<int, int>(dep[x], msk[x]));     for (auto &i : gph[x]) dfs2(i, v);   }   void dfs(int x) {     if (gph[x].empty()) {       mx[msk[x]] = dep[x];       return;     }     for (int i = 1; i < gph[x].size(); i++) {       dfs(gph[x][i]);       vector<pair<int, int> > w;       dfs2(gph[x][i], w);       for (auto &j : w) mx[j.second] = -1;     }     dfs(gph[x][0]);     for (int i = 1; i < gph[x].size(); i++) {       vector<pair<int, int> > w;       dfs2(gph[x][i], w);       for (auto &j : w) {         for (int k = 0; k < 23; k++) {           int val = mx[j.second ^ l[k]];           if (~val) dp[x] = max(dp[x], j.first + val - 2 * dep[x]);         }       }       for (auto &j : w) mx[j.second] = max(mx[j.second], j.first);     }     for (int k = 0; k < 23; k++) {       if (mx[msk[x] ^ l[k]] != -1) {         dp[x] = max(dp[x], mx[msk[x] ^ l[k]] - dep[x]);       }     }     mx[msk[x]] = max(mx[msk[x]], dep[x]);   }   int main() {     scanf( %d , &n);     char ch[6];     for (int i = 0; i < 22; i++) l[i] = (1 << i);     for (int i = 2; i <= n; i++) {       scanf( %d %s , &par[i], ch);       gph[par[i]].push_back(i);       dep[i] = dep[par[i]] + 1;       msk[i] = msk[par[i]] ^ (1 << (*ch -  a ));     }     for (int i = n; i; i--) {       sz[i] = 1;       for (auto &j : gph[i]) sz[i] += sz[j];       sort(gph[i].begin(), gph[i].end(),            [&](const int &a, const int &b) { return sz[a] > sz[b]; });     }     memset(mx, -1, sizeof(mx));     dfs(1);     for (int i = n; i; i--) {       for (auto &j : gph[i]) dp[i] = max(dp[i], dp[j]);     }     for (int i = 1; i <= n; i++) printf( %d  , dp[i]);   }


#include <vector>   #include <array>   #include <stack>   #include <queue>   #include <list>   #include <bitset>   #include <set>   #include <map>   #include <unordered_set>   #include <unordered_map>   #include <algorithm>   #include <numeric>   #include <iostream>   #include <iomanip>   #include <string>   #include <chrono>   #include <random>   #include <cmath>   #include <cassert>   #include <climits>   #include <cstring>   #include <cstdlib>   #include <functional>   #include <sstream>      using namespace std;      const long long MOD = 998244353;      vector<vector<int>> matXmat(const vector<vector<int>>& A, const vector<vector<int>>& B, long long M = MOD) {       int n = A.size();       assert(n != 0);       assert(A[0].size() == B.size());       int l = B.size();       assert(l != 0);       int m = B[0].size();       assert(m != 0);          vector<vector<int>> res(n, vector<int>(m, 0));          long long MOD2 = M * 1LL * M;       for (int i = 0; i < n; ++i) {           for (int j = 0; j < l; ++j) {               for (int k = 0; k < m; ++k) {                   res[i][k] += A[i][j] * 1LL * B[j][k] % M;                   if (res[i][k] >= M) {                       res[i][k] -= M;                   }                   if (res[i][k] < 0) {                       res[i][k] += M;                   }               }           }       }       return res;   }         vector<long long> __tmpA(500, 0);   vector<vector<int>> matXmat2(const vector<vector<int>>& A, const vector<vector<int>>& B, long long M = MOD) {       int n = A.size();       assert(n != 0);       assert(A[0].size() == B.size());       int l = B.size();       assert(l != 0);       int m = B[0].size();       assert(m != 0);          vector<vector<int>> res(n, vector<int>(m, 0));          long long MOD2 = M * 1LL * M;       for (int i = 0; i < n; ++i) {           for (int k = 0; k < m; ++k) {               __tmpA[k] = 0;           }           for (int j = 0; j < l; ++j) {               for (int k = 0; k < m; ++k) {                   __tmpA[k] += A[i][j] * 1LL * B[j][k];                   if (__tmpA[k] >= MOD2) {                       __tmpA[k] -= MOD2;                   }               }           }           for (int k = 0; k < m; ++k) {               if (__tmpA[k] >= MOD) {                   res[i][k] = __tmpA[k] % MOD;               } else {                   res[i][k] = __tmpA[k];               }           }       }       return res;   }      vector<int> matXvec(const vector<vector<int>>& A, const vector<int>& B, long long M = MOD) {       int n = A.size();       assert(n != 0);       int m = A[0].size();       assert(m == B.size());          vector<int> res(n, 0);          long long MOD2 = M * 1LL * M;       for (int i = 0; i < n; ++i) {           long long ans = 0;           for (int j = 0; j < m; ++j) {               ans += A[i][j] * 1LL * B[j];               if (ans >= MOD2) {                   ans -= MOD2;               }               if (ans < 0) {                   ans += MOD2;               }           }           ans %= M;           if (ans < 0) {               ans += M;           }           res[i] = ans;       }       return res;   }      vector<vector<int>> matPow(vector<vector<int>> A, long long n, long long M = MOD) {       int m = A.size();       assert(m != 0 && A[0].size() == m);       vector<vector<int>> res(m, vector<int>(m, 0));       for (int i = 0; i < m; ++i) {           res[i][i] = 1;       }          while (n > 0) {           if (n & 1) {               res = matXmat2(res, A, M);           }           A = matXmat2(A, A, M);           n >>= 1;       }       return res;   }         class Trie{       public:           Trie(int n = 110000) : N(n), nodes(n), rt(-1), idx(-1) {               rt = newNode();           }              void reset() {               for (int i = 0; i <= idx; ++i) {                   nodes[i].reset();               }               idx = -1;               rt = newNode();           }                 int root() { return rt; }              int index(char ch) {               return ch -  a ;           }              void insert(string& s) {               int cur = rt;               for (auto c : s) {                   c = index(c);                   if (nodes[cur].nexts[c] == -1) {                       nodes[cur].nexts[c] = newNode();                   }                   cur = nodes[cur].nexts[c];                   nodes[cur].cnt += 1;               }               nodes[cur].isEnd = true;           }                 bool query(string& s) {               int cur = rt;               for (auto c : s) {                   c = index(c);                   if (nodes[cur].nexts[c] == -1) {                       return false;                   }                   cur = nodes[cur].nexts[c];               }               return nodes[cur].isEnd;           }              int next(int r, char ch) {               ch = index(ch);               return nodes[r].nexts[ch];           }              bool isEnd(int u) {               return nodes[u].isEnd;           }             private:           const static int A = 26;           struct Node {               Node() : cnt(0), isEnd(false) {                    fill(begin(nexts), end(nexts), -1);               }                  void reset() {                   cnt = 0;                   isEnd = false;                   fill(begin(nexts), end(nexts), -1);               }                  int nexts[A];               int cnt;               bool isEnd;           };              int N;           int rt;           int idx;           vector<Node> nodes;              int newNode() {               return ++idx;           }   };      class Solution {   public:       long long solve(vector<string>& S, int m) {           int n = S.size();              Trie tr(2000);           for (auto s : S) {               tr.insert(s);           }           const int N = 100;           vector<vector<vector<pair<int,int>>>> nexts(N, vector<vector<pair<int,int>>>(N));                      int rt = tr.root();           vector<pair<int,int>> que;           que.emplace_back(rt, rt);           vector<vector<bool>> ok(N, vector<bool>(N, false));           ok[rt][rt] = true;           vector<vector<bool>> visited(N, vector<bool>(N, false));           visited[rt][rt] = true;           for (int i = 0; i < que.size(); ++i) {               int u = que[i].first, v = que[i].second;                  for (int j =  a ; j <=  z ; ++j) {                   int nu = tr.next(u, j);                   int nv = tr.next(v, j);                   if (nu < 0 || nv < 0) {                       continue;                   }                   if (tr.isEnd(nu) && tr.isEnd(nv)) {                       nexts[u][v].emplace_back(rt, rt);                   }                   if (tr.isEnd(nu)) {                       nexts[u][v].emplace_back(rt, nv);                       if (!visited[rt][nv]) {                           visited[rt][nv] = true;                           que.emplace_back(rt, nv);                       }                   }                   if (tr.isEnd(nv)) {                       nexts[u][v].emplace_back(nu, rt);                       if (!visited[nu][rt]) {                           visited[nu][rt] = true;                           que.emplace_back(nu, rt);                       }                   }                   {                       nexts[u][v].emplace_back(nu, nv);                       if (!visited[nu][nv]) {                           visited[nu][nv] = true;                           que.emplace_back(nu, nv);                       }                   }               }           }                 while (true) {               int chg = 0;               for (auto& p : que) {                   int u = p.first, v = p.second;                   if (ok[u][v]) {                       continue;                   }                   for (auto& p2 : nexts[u][v]) {                       int nu = p2.first, nv = p2.second;                       if (ok[nu][nv]) {                           ok[u][v] = true;                           ++chg;                           break;                       }                                      }               }               if (chg == 0) {                   break;               }           }              map<pair<int,int>,int> indices;           for (auto& p : que) {               int u = p.first, v = p.second;               if (ok[u][v]) {                   int idx = indices.size();                   indices[p] = idx;               }           }               int sz = indices.size();           // cout <<  sz   << sz << endl;           vector<vector<int>> mat(sz, vector<int>(sz, 0));           for (auto& p : que) {               int u = p.first, v = p.second;               if (ok[u][v]) {                   for (auto& p2 : nexts[u][v]) {                       int nu = p2.first, nv = p2.second;                       if (ok[nu][nv]) {                           // cout << indices[p] <<     << indices[p2] <<     << u <<     << v <<  endl;                           mat[indices[p2]][indices[p]] += 1;                       }                   }               }           }              auto M = matPow(mat, m);              return M[0][0];       }   };      int main(int argc, char** argv) {       ios::sync_with_stdio(false);       cin.tie(0);          Solution sol;          int n, m;       cin >> n >> m;          vector<string> S(n);       for (int i = 0; i < n; ++i) {           cin >> S[i];       }          cout << sol.solve(S, m) <<   n ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f, maxn = 5e5 + 500;   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long ksm(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = (r * a) % mod;       a = a * a % mod;       b >>= 1;     }     return r;   }   int n, m, f[maxn][25] = {0};   int query(int l, int r) {     int sum = 0;     for (int i = 23; i >= 0; i--) {       if (f[l][i] < r && f[l][i] != 0) {         l = f[l][i];         sum += (1 << i);       }     }     if (f[l][0] < r) return -1;     return sum + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     int max1 = 0;     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       f[l][0] = max(f[l][0], r);       max1 = max(r, max1);     }     for (int l = 0; l <= max1; l++)       if (l != 0) f[l][0] = max(f[l][0], max(l, f[l - 1][0]));     for (int j = 1; j <= 23; j++)       for (int l = 0; l <= max1; l++) f[l][j] = f[f[l][j - 1]][j - 1];     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       int ans = query(l, r);       cout << ans << endl;     }   }


/**     *  Author: N.Nafi1211 || <nomaannafi99@gmail.com> #~#   **/       #include <bits/stdc++.h>   using namespace std;      clock_t startTime;   double getCurrentTime(){    return (double) (clock() - startTime) / CLOCKS_PER_SEC;   }      #define PB push_back      typedef long long ll;   typedef vector<char> vc;   typedef vector<int> vi;   typedef vector<long long> vll;   typedef vector<double> vd;      void solve()   {    string a, b;    cin >> a >> b;    int n = a.length(), m = b.length();       int res = 0;       for(int len=1; len<=min(n, m); ++len) {     for(int i=0; i+len<=n; ++i) {      for(int j=0; j+len<=m; ++j) {       if(a.substr(i, len) == b.substr(j, len)) {        res = max(res, len);       }      }     }    }    int ans = n-res + m-res;    cout << ans <<   n ;    return;      }      int main()   {    ios_base::sync_with_stdio(0);    cin.tie(0);    //startTime = clock();       int t;       cin >> t;       while(t--)     solve();       //printf( %.3lf n , getCurrentTime());    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cout << 8 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > adj;   vector<int> in;   vector<int> out;   vector<pair<int, int> > visit;   pair<int, int> cal(int son) {     if (visit[son].first > 0) return visit[son];     if (visit[son].first == -2) return {-1, -1};     visit[son] = {-2, 0};     pair<int, int> temp, ans = {0, 0};     for (int i = 0; i < adj[son].size(); ++i) {       temp = cal(adj[son][i].first);       if (temp.first == -1) return temp;       if (temp.first > ans.first) {         ans.first = temp.first;         ans.second = max(temp.second, adj[son][i].second);       }     }     ++ans.first;     visit[son] = ans;     return visit[son];   }   int main() {     int n, m;     cin >> n >> m;     adj.resize(n + 1);     out.resize(n + 1);     in.resize(n + 1);     visit.resize(n + 1, {-1, 0});     int num1, num2;     for (int i = 0; i < m; ++i) {       cin >> num1 >> num2;       out[num1]++;       in[num2]++;       adj[num1].push_back({num2, i});     }     int node = 0, cnt = 0;     for (int i = 1; i <= n; ++i) {       if (in[i] == 0) {         node = i;         ++cnt;       }     }     if (cnt != 1) {       cout << -1 << endl;       return 0;     }     pair<int, int> temp = cal(node);     if (temp.second == -1 || temp.first != n)       cout << -1 << endl;     else       cout << temp.second + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 5;   pair<long long, long long> a[maxn];   long long n;   long long cnt[maxn][2];   void solve() {     cin >> n;     for (long long i = 1; i <= n; i++)       cnt[i][0] = cnt[i][1] = 0, cin >> a[i].first >> a[i].second;     long long ans = n * (n - 1) * (n - 2) / 6;     for (long long i = 1; i <= n; i++) {       cnt[a[i].first][0]++;       cnt[a[i].second][1]++;     }     for (long long i = 1; i <= n; i++) {       ans -= (cnt[a[i].first][0] - 1) * (cnt[a[i].second][1] - 1);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long int mod = 1e9 + 7;   const long long int MAX = LLONG_MAX;   const long long int MIN = LLONG_MIN;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n, k;     cin >> n >> k;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     map<long long int, long long int> mp;     long long int c = 0;     deque<long long int> d;     for (long long int i = 0; i < n; i++) {       if (c < k) {         if (mp[a[i]] == 0) {           d.push_front(a[i]);           mp[a[i]]++;           c++;         } else {         }       } else {         long long int x = d.back();         if (mp[a[i]] != 0) {         } else {           mp[x] = mp[x] - 1;           d.pop_back();           d.push_front(a[i]);           mp[a[i]]++;         }       }     }     cout << d.size() <<   n ;     for (auto i = d.begin(); i != d.end(); i++) {       cout << *i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     long i;     for (i = 0; i <= n - 1; i++) cin >> a[i];     sort(a, a + n);     long long pc = 1, qc = 1, rc = 1;     long long b[3];     long long p = a[0], q = a[1], r = a[2];     if (p == q && q == r) {       long long c = 3;       for (i = 3; i <= n - 1; i++)         if (a[i] == p) c++;       cout << c * (c - 1) * (c - 2) / 6;     } else if (p == q) {       long long pc = 2, rc = 1;       for (i = 3; i <= n - 1; i++)         if (a[i] == p)           pc++;         else if (a[i] == r)           rc++;       cout << pc * (pc - 1) * rc / 2;     } else if (q == r) {       long long pc = 1, rc = 2;       for (i = 3; i <= n - 1; i++)         if (a[i] == p)           pc++;         else if (a[i] == r)           rc++;       cout << rc * (rc - 1) * pc / 2;     } else {       long long rc = 1;       for (i = 3; i <= n - 1; i++)         if (a[i] == r) rc++;       cout << rc;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   signed main() {     long long int t;     cin >> t;     vector<long long int> nums = {6, 10, 14, 15};     long long int minS = nums[0] + nums[1] + nums[2];     long long int maxS = nums[0] + nums[1] + nums[3];     while (t--) {       long long int n;       cin >> n;       if (n <= minS)         cout <<  NO n ;       else {         long long int d = n - minS;         if (d == nums[0] || d == nums[1] || d == nums[2]) {           if (n <= maxS)             cout <<  NO n ;           else             cout <<  YES n                   << 6 <<     << 10 <<     << 15 <<     << n - maxS <<   n ;         } else           cout <<  YES n  << 6 <<     << 10 <<     << 14 <<     << d <<   n ;       }     }     return 0;   }


#include<cstdio>   const int N=100005;   int n,a[100005];   inline int ask2(int x){       if(a[x]) return a[x];       printf( ? %d n ,x);       fflush(stdout);       scanf( %d ,a+x);       return a[x];   }   inline int ask(int x){       if(ask2(x)>ask2(x+1)) return 1;       else  return 0;   }   int main(){       scanf( %d ,&n);       a[0]=a[n+1]=1e9;       int l=1,r=n;       int mid=(l+r)/2;       while(r-l>20){           mid=(l+r)/2;           if(ask(mid)) l=mid+1;           else r=mid;       }       for(int i=l-1;i<=r+1;i++)           ask2(i);       for(int i=l;i<=r;i++){           if(a[i]<a[i+1]&&a[i]<a[i-1]){               printf( ! %d n ,i);               return 0;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3, MOD = (1e9) + 7;   int n, m, k, A[N + 9][N + 9], row[N + 9], col[N + 9], x, y;   char c;   void init() {     for (int i = 0; i < N + 5; ++i) row[i] = col[i] = i;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     init();     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) scanf( %d , &A[i][j]);     }     for (int i = 0; i < k; ++i) {       cin.ignore();       scanf( %c %d %d , &c, &x, &y);       switch (c) {         case  c :           swap(col[x], col[y]);           break;         case  r :           swap(row[x], row[y]);           break;         case  g :           printf( %d n , A[row[x]][col[y]]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void my_dbg() { cout << endl; }   template <typename Arg, typename... Args>   void my_dbg(Arg A, Args... B) {     cout <<     << A;     my_dbg(B...);   }   using ll = long long;   using vi = vector<int>;   using vl = vector<ll>;   using pii = pair<int, int>;   const int inf = INT_MAX;   const int ninf = INT_MIN;   const int mod = 1e9 + 7;   const int maxN = 2e5 + 2;   void solve() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     vector<pii> a(m);     for (int i = (int)(0); i < (int)(m); i++) {       scanf( %d , &a[i].first);       scanf( %d , &a[i].second);     }     sort(a.begin(), a.end(), [&](pii a, pii b) { return a.second < b.second; });     ll sum = 0, ans = 0;     multiset<int> ms;     for (int i = (int)(0); i < (int)(m); i++) {       while ((int)ms.size() and              (*ms.begin() < a[i].second or (int) ms.size() >= n)) {         sum -= *ms.begin();         ms.erase(ms.begin());       }       sum += a[i].first;       ll cur = sum;       ll rem = n - (int)ms.size() - 1;       cur += rem * a[i].second;       ans = max(ans, cur);       ms.insert(a[i].first);     }     printf( %lld n , ans);   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     long long int a = 0, b = 0, c = 0;     for (int i = 0; i < s.length(); i++) {       if (i > 0 && s[i - 1] ==  v  && s[i] ==  v ) {         a++;         c += b;       } else if (s[i] ==  o ) {         b += a;       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x, nr;   bool kgood(int N, int K) {     int i, ap[10] = {0};     while (N) {       ++ap[N % 10];       N /= 10;     }     for (i = 0; i <= K; ++i)       if (!ap[i]) return false;     return true;   }   int main() {     int i;     scanf( %d%d , &n, &k);     for (i = 0; i < n; ++i) {       scanf( %d , &x);       if (kgood(x, k)) ++nr;     }     printf( %d n , nr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) {       a -= 1000000007;     }     return a;   }   long long sub(long long a, long long b) {     a -= b;     if (a < 0) {       a += 1000000007;     }     return a;   }   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   void add_self(long long& a, long long b) { a = add(a, b); }   void sub_self(long long& a, long long b) { a = sub(a, b); }   void mul_self(long long& a, long long b) { a = mul(a, b); }   const long long MAXN = 200010;   long long get(long long val, long long tot) {     long long ans = 0;     long long L = val, R = val + 1 - (val % 2);     while (R <= tot) {       ans += R - L + 1;       L = 2 * L;       R = 2 * R + 1;     }     ans += max(0LL, tot - L + 1);     return ans;   }   int main() {     long long x, k;     cin >> x >> k;     long long lo = 0, hi = 1e18, ans = 0;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (get(2 * mid + 1, x) >= k) {         ans = 2 * mid + 1;         lo = mid + 1;       } else {         hi = mid - 1;       }     }     lo = 0;     hi = 1e18;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (get(2 * mid, x) >= k) {         ans = max(ans, 2 * mid);         lo = mid + 1;       } else {         hi = mid - 1;       }     }     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   long long d[61];   int ans;   int n, a[200005];   void insert() {     for (int i = 1; i <= n; i++) {       long long x = a[i];       for (int j = 60; j >= 0; j--)         if (x & (1LL << j)) {           if (d[j] == 0) {             d[j] = x;             ans++;             break;           } else             x ^= d[j];         }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] ^= a[i - 1];     if (a[n] == 0) {       printf( -1 n );       return 0;     }     insert();     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 100;   long long A[MX][MX];   long long acum[MX][MX];   long long n, m;   long long getAns(long long a, long long b) {     long long ans = n * m;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (i + a - 1 < n && j + b - 1 < m) {           long long cur = 0;           for (long long l = i; l <= i + a - 1; l++) {             cur += acum[l][j + b] - acum[l][j];           }           ans = min(ans, cur);         }       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> A[i][j];       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         acum[i][j + 1] = acum[i][j] + A[i][j];       }     }     long long a, b;     cin >> a >> b;     long long ans = min(getAns(a, b), getAns(b, a));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const nmax = 100;   int v[1 + nmax];   map<int, int> dp;   int mex(vector<int> v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 0; i < v.size(); i++)       if (v[i] != i) return i;     return v.size();   }   int computedp(int mask) {     map<int, int>::iterator it = dp.find(mask);     if (it != dp.end()) return it->second;     vector<int> v;     for (int i = 1; (1 << i) <= mask; i++) {       int newmask = ((mask & ((1 << i) - 1)) | (mask >> i));       v.push_back(computedp(newmask));     }     dp[mask] = mex(v);     return dp[mask];   }   map<int, int> frec;   void decompose(int number) {     for (int i = 2; i * i <= number; i++) {       if (number % i == 0) {         int p = 0;         while (number % i == 0) {           number /= i;           p++;         }         frec[i] |= (1 << p);       }     }     if (1 < number) frec[number] |= 2;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++) decompose(v[i]);     int result = 0;     for (map<int, int>::iterator it = frec.begin(); it != frec.end(); it++) {       result ^= computedp(it->second | 1);     }     if (result == 0)       cout <<  Arpa ;     else       cout <<  Mojtaba ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   long long cmp(pair<int, int> a, pair<int, int> b) {     return a.second < b.second;   }   int main() {     int n, m;     cin >> n >> m;     char a[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     long long ans = 0;     long long x[n + 1][m + 1];     long long y[n + 1][m + 1];     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         x[i][j] = 0;         y[i][j] = 0;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  0 ) {           x[i][j] = x[i][j - 1] + 1;           y[i][j] = y[i - 1][j] + 1;           long long ymin = y[i][j];           long long xmin = x[i][j];           for (int k = j - x[i][j] + 1; k <= j; k++) {             ymin = min(ymin, y[i][k]);           }           for (int k = i - y[i][j] + 1; k <= i; k++) {             xmin = min(xmin, x[k][j]);           }           long long p1 = ymin + x[i][j];           long long p2 = xmin + y[i][j];           long long p = (max(p1, p2)) * 2;           ans = max(p, ans);         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10101;   const int BIT = 30;   int N;   int arr[MAXN], brr[MAXN];   int real_arr[MAXN];   bool isb[MAXN], risb[MAXN];   vector<pair<int, int> > vans;   void action(int a, int b) {     arr[b] ^= arr[a];     vans.push_back(make_pair(b + 1, a + 1));   }   void aswap(int a, int b) {     if (a == b) return;     action(a, b);     action(b, a);     action(a, b);   }   void fail() {     cout << -1 << endl;     exit(0);   }   void calc() {     int basis[BIT];     memset((basis), -1, sizeof(basis));     memset((isb), 0, sizeof(isb));     for (int i = 0; i < BIT; i++) {       for (int j = 0; j < N; j++) {         if (isb[j]) continue;         if (arr[j] & (1 << i)) {           basis[i] = j;           isb[j] = true;           break;         }       }       if (basis[i] == -1) continue;       for (int j = 0; j < N; j++) {         if (j == basis[i]) continue;         if (arr[j] & (1 << i)) {           action(basis[i], j);         }       }     }     bool bused[BIT];     int rbasis[BIT];     memset((bused), 0, sizeof(bused));     memset((risb), 0, sizeof(risb));     for (int i = 0; i < N; i++) {       int x = brr[i];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           if (!bused[j]) {             bused[j] = true;             if (!risb[i]) {               rbasis[j] = i;               risb[i] = true;             }           }         }       }       if (x) fail();     }     for (int i = 0; i < N; i++) {       if (arr[i]) continue;       int x = brr[i];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           action(basis[j], i);         }       }     }     if (0) {       cout <<  B  ;       for (int i = 0; i < BIT; i++) cout << basis[i] <<    ;       cout << endl;       cout <<  -A  ;       for (int i = 0; i < N; i++) cout << arr[i] <<    ;       cout << endl;     }     int mat[BIT], mat2[BIT];     bool oked[BIT];     memset((mat), 0, sizeof(mat));     memset((mat2), 0, sizeof(mat2));     memset((oked), 0, sizeof(oked));     memset((rbasis), -1, sizeof(rbasis));     memset((bused), 0, sizeof(bused));     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       mat2[i] = 1 << i;       rbasis[i] = i;       int x = brr[basis[i]];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           mat[i] ^= 1 << j;         }       }     }     if (0)       for (int i = 0; i < BIT; i++) {         if (basis[i] == -1) continue;         for (int j = 0; j < BIT; j++) {           if (basis[j] == -1) continue;           cout << !!(mat[i] & (1 << j)) <<    ;         }         cout << endl;       }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       int pv = -1;       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (bused[j]) continue;         if (mat[j] & 1 << i) {           pv = j;           bused[j] = true;           break;         }       }       if (pv == -1) continue;       swap(bused[i], bused[pv]);       swap(mat[i], mat[pv]);       swap(mat2[i], mat2[pv]);       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == i) continue;         if (mat[j] & 1 << i) {           mat[j] ^= mat[i];           mat2[j] ^= mat2[i];         }       }     }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       if (!(mat[i] & 1 << i)) {         for (int j = 0; j < BIT; j++) {           if (basis[j] == -1) continue;           if (j == i) continue;           if (mat[j] & 1 << i) action(basis[i], basis[j]);         }         action(basis[i], basis[i]);       }     }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       int pv = -1;       for (int j = i; j < BIT; j++) {         if (basis[j] == -1) continue;         if (mat2[j] & 1 << i) {           pv = j;           break;         }       }       swap(mat2[i], mat2[pv]);       aswap(basis[i], basis[pv]);       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == i) continue;         if (mat2[j] & 1 << i) {           mat2[j] ^= mat2[i];           action(basis[i], basis[j]);         }       }     }     if (0)       for (int i = 0; i < BIT; i++) {         if (basis[i] == -1) continue;         for (int j = 0; j < BIT; j++) {           if (basis[j] == -1) continue;           cout << !!(mat[i] & (1 << j)) <<    ;         }         cout << endl;       }     return;     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       int pv = -1;       int ii = rbasis[i];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (oked[j]) continue;         if (mat[j] & (1 << i)) {           pv = j;           break;         }       }       if (pv == -1) {         continue;       }       if (0) cout <<  II   << ii <<   PV   << pv << endl;       oked[pv] = true;       swap(mat2[ii], mat2[pv]);       int lb = -1;       for (int j = 0; j < BIT; j++)         if (basis[j] != -1 && rbasis[j] == pv) lb = j;       swap(rbasis[i], rbasis[lb]);       if (0) cout <<  SWAP RB   << i <<     << lb << endl;       aswap(basis[ii], basis[pv]);       vector<pair<int, int> > vb;       int b = basis[pv];       int orig_arr = arr[b];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == i) continue;         if (1) {           int rj = rbasis[j];           if ((mat2[pv] ^ mat[pv]) & (1 << j)) {             mat2[pv] ^= mat2[rj];             arr[basis[pv]] ^= arr[basis[rj]];             vb.push_back(make_pair(basis[pv] + 1, basis[rj] + 1));           }         }       }       if (!(mat2[pv] & (1 << i))) {         mat2[pv] ^= 1 << i;         arr[b] ^= orig_arr;         vans.push_back(make_pair(b + 1, b + 1));       }       for (__typeof(vb.begin()) it = vb.begin(); it != vb.end(); it++)         vans.push_back(*it);     }     vector<pair<int, int> > vi;     for (int q = 0; q < BIT; q++) {       int i = rbasis[q];       if (i == -1 || basis[i] == -1) continue;       if (oked[i]) continue;       vi.push_back(make_pair(basis[q] + 1, basis[q] + 1));       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == q) continue;         if ((mat2[i] ^ mat[i]) & (1 << j)) {           mat2[i] ^= 1 << j;           vi.push_back(make_pair(basis[q] + 1, basis[j] + 1));           cout <<  VIPB   << q <<     << j << endl;           cout <<  NOW   << rbasis[q] << endl;         }       }     }     if (0)       for (int i = 0; i < BIT; i++) {         if (basis[i] == -1) continue;         for (int j = 0; j < BIT; j++) {           if (basis[j] == -1) continue;           cout << !!(mat2[i] & (1 << j)) <<    ;         }         cout << endl;       }     if (0) {       cout <<  A  ;       for (int i = 0; i < N; i++) cout << arr[i] <<    ;       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 0; i < N; i++) cin >> arr[i];     for (int i = 0; i < N; i++) cin >> brr[i];     for (int i = 0; i < N; i++) real_arr[i] = arr[i];     calc();     for (__typeof(vans.begin()) it = vans.begin(); it != vans.end(); it++) {       real_arr[it->first - 1] ^= real_arr[it->second - 1];     }     if (0) {       cout <<  R  ;       for (int i = 0; i < N; i++) cout << real_arr[i] <<    ;       cout << endl;     }     int A = vans.size();     cout << A <<   n ;     for (__typeof(vans.begin()) it = vans.begin(); it != vans.end(); it++) {       cout << it->first <<     << it->second <<   n ;     }     cout << flush;     for (int i = 0; i < N; i++) assert(real_arr[i] == brr[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, a, b, s1, s2;     cin >> n >> m >> a >> b;     if (n % m == 0)       cout <<  0  << endl;     else {       s1 = (n - ((n / m) * m)) * b;       s2 = (((n / m) + 1) * m - n) * a;       if (s1 > s2)         printf( %I64d , s2);       else         printf( %I64d , s1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long cnt = 0.5 * n / (k + 1);     cout << cnt <<     << cnt * k <<     << n - cnt - cnt * k << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solution() {     int n, m;     cin >> n >> m;     int rows[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> rows[i][j];       }     }     int cols[m][n];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> cols[i][j];       }     }     int el = cols[0][0];     for (int i = 0; i < n; i++) {       if (find(rows[i], rows[i] + m, el) != rows[i] + m) {         int l = find(rows[i], rows[i] + m, el) - rows[i];         int arrangement[n];         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             if (cols[0][j] == rows[k][l]) {               arrangement[j] = k;               break;             }           }         }         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             cout << rows[arrangement[i]][j] <<    ;           }           cout << endl;         }         return;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int count, counter = 0;     cin >> count;     while (counter++ < count) {       solution();     }     return 0;   }


#include<bits/stdc++.h>      using namespace std;      #define task  sol    #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #define pb push_back   #define mp make_pair   #define zs(v) ((int)(v).size())   #define BIT(x, i) (((x) >> (i)) & 1)   #define CNTBIT __builtin_popcountll   #define ALL(v) (v).begin(),(v).end()   #define endl   n       typedef long double ld;   typedef long long ll;   typedef pair<int, int> pii;      const ll base=331;   const int dx[8]={0,-1,0,1,1,-1,-1,1};   const int dy[8]={-1,0,1,0,-1,-1,1,1};      int c[55][55];   int mod;   ll dp[55][55*55];   ll fact[55];   int f[4005];   int n;         void gogo()   {       cin>>n>>mod;          dp[0][0]=1;       for (int i=1;i<=n;++i)       {           for (int num=0;num<=n*n;++num)           {               for (int k=1;k<=i;++k)                   if (num+i-k<=n*n) (dp[i][num+i-k]+=dp[i-1][num])%=mod;           }       }          for (int i=0;i<=n;++i)       {           c[i][0]=1;           for (int j=1;j<=i;++j)               c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;       }       fact[0]=1;       for (int i=1;i<=n;++i) fact[i]=fact[i-1]*i%mod;             int ans=0;       for (int i=0;i<n;++i)       {           ll val=c[n][i]*fact[i]%mod;           int len=n-i-1;           int m=len*(len-1)/2;              for (int i=0;i<=m;++i) f[i]=0;           for (int inv1=0;inv1<=m;++inv1)           {               for (int inv2=0;inv2<=inv1;++inv2)               {                   (f[inv1-inv2]+=dp[len][inv1]*dp[len][inv2]%mod)%=mod;               }           }           for (int i=1;i<=m;++i) (f[i]+=f[i-1])%=mod;           int value=0;           for (int x=1;x<=len+1;++x)           {               for (int y=x+1;y<=len+1;++y)               {                   assert(y-x>=0);                   if (m>y-x)                       (value+=(f[m]-f[y-x]+mod)%mod)%=mod;               }           }   //        cout<<value<<endl;           ans=(ans+val*value%mod)%mod;       }       cout<<ans;   }   int main()   {       ios_base::sync_with_stdio(0); cin.tie(0);       if (fopen(task .inp ,  r ))       {           freopen(task .inp ,  r , stdin);           freopen(task .out ,  w , stdout);       }       gogo();   }


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


#include <bits/stdc++.h>   using namespace std;   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int gcd(long long int a, long long int b) {     if (a < b)       return gcd(b, a);     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int isPrime(long long int n) {     long long int p = (long long int)sqrt(n);     for (int i = (2); i <= (p); i += (1))       if (n % i == 0) return 0;     return 1;   }   long long int pow(long long int b, long long int e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long int a = pow(b, e / 2);       return a * a;     } else {       long long int a = pow(b, e / 2);       return b * a * a;     }   }   long long int powm(long long int x, long long int y,                      long long int m = 1000000007) {     x = x % m;     long long int res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int modInverse(long long int a, long long int m) {     return powm(a, m - 2, m);   }   void solve() {     long long int n;     cin >> n;     vector<long long int> arr(n);     for (int i = (0); i <= (n - 1); i += (1)) cin >> arr[i];     if (n == 1) {       cout <<  1 1  <<   n             << (-arr[0]) <<   n             <<  1 1             <<   n0  <<   n             <<  1 1 n             <<  0  <<   n ;       return;     }     vector<vector<long long int>> ans;     ans.push_back({1, 1, -arr[0]});     arr[0] = 0;     vector<long long int> temp;     temp.push_back(2);     temp.push_back(n);     for (int i = (1); i <= (n - 1); i += (1)) {       long long int x = arr[i] % n;       arr[i] += x * (n - 1);       temp.push_back(x * (n - 1));     }     ans.push_back(temp);     temp.clear();     temp.push_back(1);     temp.push_back(n);     for (int i = (0); i <= (n - 1); i += (1)) {       temp.push_back(-arr[i]);     }     ans.push_back(temp);     for (int i = (0); i <= (2); i += (1)) {       cout << ans[i][0] <<     << ans[i][1] <<   n ;       for (int j = (2); j <= ((int)ans[i].size() - 1); j += (1))         cout << ans[i][j] <<    ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <iostream>   #include <cstdio>   #include <algorithm>   #include <bits/stdc++.h>   #define ALL(x) (x).begin(), (x).end()   #define sz(a) int(a.size())   #define rep(i,x,n) for(int i=x;i<n;i++)   #define repd(i,x,n) for(int i=x;i<=n;i++)   #define pii pair<int,int>   #define pll pair<long long ,long long>   #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)   #define MS0(X) memset((X), 0, sizeof((X)))   #define MSC0(X) memset((X),   0 , sizeof((X)))   #define pb push_back   #define mp make_pair   #define fi first   #define se second   #define eps 1e-6   #define chu(x)  if(DEBUG_Switch) cout<< [ <<#x<<   <<(x)<< ] <<endl   #define du3(a,b,c) scanf( %d %d %d ,&(a),&(b),&(c))   #define du2(a,b) scanf( %d %d ,&(a),&(b))   #define du1(a) scanf( %d ,&(a));   using namespace std;   typedef long long ll;   ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}   ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}   ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}   ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}   void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf( %d , V[i] ); if (i != Len - 1) {printf(   );} else {printf(  n );}}}   void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf( %lld , V[i] ); if (i != Len - 1) {printf(   );} else {printf(  n );}}}   inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c <  0  || c >  9 ) {if (c ==  - ) { fh = -1; } c = getchar();} while (c >=  0  && c <=  9 ) { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;}   inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c <  0  || c >  9 ) {if (c ==  - ) { fh = -1; } c = getchar();} while (c >=  0  && c <=  9 ) { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;}   void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf( %d%c , arr[i], i == n ?   n  :    );}}   void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf( %lld%c , arr[i], i == n ?   n  :    );}}   const int maxn = 1000010;   const int inf = 0x3f3f3f3f;   /*** TEMPLATE CODE * * STARTS HERE ***/   #define DEBUG_Switch 0   pll a[5];   int b[5];   int main()   {   #if DEBUG_Switch       freopen( D:  code  input.txt ,  r , stdin);   #endif       //freopen( D:  code  output.txt , w ,stdout);       int t;       t = readint();       while (t--) {           repd(i, 1, 4) {               a[i].fi = readint();               a[i].se = readint();               b[i] = i;           }           ll ans = 1e18;           do {               ll x1 = min(a[b[1]].fi, a[b[3]].fi), x2 = max(a[b[1]].fi, a[b[3]].fi), x3 = min(a[b[2]].fi, a[b[4]].fi), x4 = max(a[b[2]].fi, a[b[4]].fi);               ll y1 = min(a[b[1]].se, a[b[2]].se), y2 = max(a[b[1]].se, a[b[2]].se), y3 = min(a[b[3]].se, a[b[4]].se), y4 = max(a[b[3]].se, a[b[4]].se);               ll x_l, x_r, y_l, y_r;               ll cost_x, cost_y;               if (x4 < x1) {                   x_l = x_r = 0;                   cost_x = x2 - x3 + x1 - x4;               } else {                   x_l = max(x3 - x2, 0ll);                   x_r = x4 - x1;                   cost_x = x2 - x1 + x4 - x3;               }                  if (y4 < y1) {                   y_l = y_r = 0;                   cost_y = y2 - y3 + y1 - y4;               } else {                   y_l = max(y3 - y2, 0ll);                   y_r = y4 - y1;                   cost_y = y2 - y1 + y4 - y3;               }                  ll temp = cost_x + cost_y;               if (y_l > x_r) {                   temp += 2ll * (y_l - x_r);               } else if (x_l > y_r) {                   temp += 2ll * (x_l - y_r);               }               ans = min(ans, temp);           } while (next_permutation(b + 1, b + 1 + 4));           printf( %lld n , ans );       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, l, r;     cin >> T;     for (int i = 1; i <= T; i++) {       cin >> l >> r;       cout << l <<     << 2 * l << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     int l = -1;     for (int i = 0; i < n - 1 && k > 0; i++) {       if (s[i] ==  4  && s[i + 1] ==  7 ) {         if (i % 2 == 1) {           if (i - 1 >= 0 && s[i - 1] ==  4 ) {             l = i;             break;           }         }         --k;         if (i % 2 == 0)           s[i + 1] =  4 ;         else           s[i] =  7 ;       }     }     if (l != -1) {       if (k % 2 == 1) s[l] =  7 ;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       long long n, i, j = 0, x;       cin >> n;       string s =   ;       stack<long long> q;       deque<long long> d;       for (i = 0; i < (n); i++) {         cin >> x;         d.push_back(x);       }       q.push(0);       while (!d.empty()) {         if (d.front() >= q.top() &&             (d.front() < d.back() || d.back() < q.top())) {           q.push(d.front());           s +=  L ;           d.pop_front();         } else if (d.back() >= q.top() &&                    (d.front() >= d.back() || d.front() < q.top())) {           q.push(d.back());           s +=  R ;           d.pop_back();         } else           break;       }       cout << q.size() - 1 <<   n ;       cout << s;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int Max_W(1000050);   inline int Mult(const int &a, const int &b) { return (a * 1LL) * b % MOD; }   constexpr int Add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }   constexpr int Sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }   void exgcd(const int &a, const int &b, int &x, int &y) {     if (b == 0)       x = 1, y = 0;     else       exgcd(b, a % b, y, x), y -= x * (a / b);   }   inline int inverse(const int &a) {     int invx, invy;     exgcd(a, MOD, invx, invy);     return (invx % MOD + MOD) % MOD;   }   int power(int a, int n) {     int Ret(1);     while (n) {       if (n & 1) Ret = Mult(Ret, a);       a = Mult(a, a), n >>= 1;     }     return Ret;   }   int W, A[Max_W], Fac[Max_W], Inv[Max_W];   inline int P(const int &n, const int &m) {     return (0 <= m && m <= n) ? Mult(Fac[n], Inv[n - m]) : 0;   }   int work(const int &N) {     int Ans(0);     if (W == 1)       Ans = N;     else       Ans = Mult(Sub(power(W, N + 1), W), inverse(Sub(W, 1)));     for (int len = N + 1; len - N <= W; ++len)       if (len - N < N + 1)         Ans =             Add(Ans, Mult(Mult(A[len - N], A[len - N]), power(W, N - (len - N))));       else         Ans = Add(Ans, Mult(A[len - N], P(W - ((len - N) - (N + 1) + 1), N)));     return Ans;   }   int main() {     int N;     scanf( %d%d , &W, &N);     A[0] = 1;     for (int i = 1; i <= W; ++i) A[i] = Mult(A[i - 1], W - i + 1);     Fac[0] = 1;     for (int i = 1; i <= W; ++i) Fac[i] = Mult(Fac[i - 1], i);     Inv[W] = inverse(Fac[W]);     for (int i = W - 1; i >= 0; --i) Inv[i] = Mult(Inv[i + 1], i + 1);     printf( %d , Sub(work(N), work(N - 1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     set<char> st;     for (auto i : s) st.insert(i);     if (k > n) {       string p = s;       char ch = *st.begin();       for (int i = 0; i < k - n; i++) {         p += ch;       }       cout << p;     } else {       int p = k;       k--;       char ch = *st.rbegin();       if (s[k] == ch) {         for (; k >= 0; k--) {           if (s[k] != ch) break;         }         for (int i = 0; i < k; i++) cout << s[i];         cout << *(st.upper_bound(s[k]));         ch = *st.begin();         for (int i = 0; i < p - k - 1; i++) cout << ch;       } else {         for (int i = 0; i < k; i++) cout << s[i];         cout << *(st.upper_bound(s[k]));       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   int n;   long long X1, Y1, X2, Y2;   long long sign(long long a) {     if (a > 0) return 1;     if (a < 0) return -1;     return 0;   }   int main() {     cin >> X1 >> Y1 >> X2 >> Y2;     cin >> n;     int ans = 0;     for (int i = 0; i < n; ++i) {       cin >> a >> b >> c;       if (sign(a * X1 + b * Y1 + c) != sign(a * X2 + b * Y2 + c)) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> v(n);       set<long long> s;       for (long long x = 0; x < n; x++) {         cin >> v[x];       }       long long index = -1;       if (v[n - 1] > v[n - 2]) {         for (long long x = n - 1; x >= 1; x--) {           if (v[x] < v[x - 1]) {             index = x;             break;           }         }         cout << (index == -1 ? 0 : index) <<   n ;       } else {         long long count = 0;         long long index = -1;         for (long long x = n - 1; x > 0; x--) {           if (v[x] < v[x - 1] && count == 1) {             index = x;             break;           }           if (v[x] > v[x - 1]) {             count = 1;           }         }         cout << (index == -1 ? 0 : index) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 110000;   int n, m, h;   int head[maxn], num;   struct road {     int to, next;   } edge[maxn * 2];   void add(int u, int v) {     edge[num].to = v;     edge[num].next = head[u];     head[u] = num++;   }   int dfn[maxn], low[maxn], block[maxn];   int id, cnt, vis[maxn], numxx[maxn];   int out[maxn];   stack<int> q;   void dfs(int u, int fa) {     dfn[u] = low[u] = ++id;     q.push(u);     vis[u] = 1;     for (int i = head[u]; i != -1; i = edge[i].next) {       int v = edge[i].to;       if (!dfn[v]) {         dfs(v, u);         low[u] = min(low[v], low[u]);       } else if (vis[v])         low[u] = min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       cnt++;       int v;       do {         v = q.top();         vis[v] = 0;         q.pop();         block[v] = cnt;         numxx[cnt]++;       } while (v != u);     }   }   int tim[maxn];   void init() {     id = num = cnt = 0;     memset(dfn, 0, sizeof(dfn));     memset(low, 0, sizeof(low));     memset(edge, 0, sizeof(edge));     memset(numxx, 0, sizeof(numxx));     memset(block, 0, sizeof(block));     memset(vis, 0, sizeof(vis));     while (!q.empty()) q.pop();     memset(head, -1, sizeof(head));     memset(out, 0, sizeof(out));   }   int main() {     while (scanf( %d%d%d , &n, &m, &h) != EOF) {       init();       for (int i = 1; i <= n; i++) {         scanf( %d , &tim[i]);       }       for (int i = 1; i <= m; i++) {         int a, b;         scanf( %d%d , &a, &b);         if ((tim[a] + 1) % h == tim[b]) add(a, b);         if ((tim[b] + 1) % h == tim[a]) add(b, a);       }       for (int i = 1; i <= n; i++) {         if (!dfn[i]) dfs(i, -1);       }       for (int i = 1; i <= n; i++) {         for (int j = head[i]; j != -1; j = edge[j].next) {           int v = edge[j].to;           if (block[v] != block[i]) {             out[block[i]]++;           }         }       }       int ans = INF;       int flag = 0;       for (int i = 1; i <= cnt; i++) {         if (out[i] == 0) {           if (ans > numxx[i]) {             ans = numxx[i];             flag = i;           }         }       }       cout << ans << endl;       for (int i = 1; i <= n; i++) {         int putt = 0;         if (block[i] == flag) {           ans--;           putt = 1;         }         if (ans != 0 && putt == 1)           cout << i <<    ;         else if (ans == 0 && putt == 1)           cout << i << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 200001;   const long long int M = 21;   struct point {     long long int x, y, cur;     bool operator==(const point b) {       if (this->x == b.x && this->y == b.y) return 1;       return 0;     }     bool operator!=(const point b) { return !(*this == b); }     friend bool operator<(const point a, const point b) {       if (a.x != b.x) return a.x < b.x;       return a.y < b.y;     }   };   void debug(stringstream &s) {}   template <typename T, typename... Args>   void debug(stringstream &s, T a, Args... args) {     string word;     s >> word;     cout << word <<   =   << a << endl;     debug(s, args...);   }   bool overflow;   long long int fast_exp(long long int x, long long int n) {     if (n == 0) return 1;     long long int ans;     if (n % 2 == 0) {       ans = fast_exp(x, n / 2);       if (ans > ans * ans % 998244353) overflow = 1;       ans = ans * ans % 998244353;     } else {       ans = fast_exp(x, n - 1);       if (ans > ans * x % 998244353) overflow = 1;       ans = ans * x % 998244353;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int _ = 1;     while (_--) {       long long int n, m = 0, x = 0, y = 0, ans = 0, k;       string s, sol;       cin >> s;       n = s.size();       set<long long int, greater<long long int>> c[26];       s =  0  + s;       for (int i = 1; i <= n; i++) c[s[i] -  a ].insert(i);       long long int dp[n + 1][51];       memset(dp, -1, sizeof(dp));       for (int i = 0; i <= n; i++) dp[i][0] = n + 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j < 51; j++) {           dp[i][j] = dp[i - 1][j];           x = dp[i - 1][j - 1];           auto it = c[s[i] -  a ].upper_bound(x);           if (it != c[s[i] -  a ].end() && *it >= i) {             dp[i][j] = max(dp[i][j], *it);           }         }       }       x = -1;       for (int i = 50; i > 0; i--) {         bool flag = 0;         m = 0;         for (int j = 1; j <= n; j++) {           if (dp[j][i] != -1) {             if (dp[j][i] - j >= m) {               x = j;               y = i;               m = dp[j][i] - j;             }             flag = 1;           }         }         if (flag) break;       }       for (int i = x; i > 0; i--) {         if (dp[i - 1][y] != dp[i][y]) {           if (dp[i][y] > i)             sol = s[i] + sol + s[i];           else             sol = s[i];           y--;         }       }       cout << sol <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   vector<int> p, vg;   set<pair<int, int> > done;   bool cando(int i, int j) {     return done.find(make_pair(min(i, j), max(i, j))) == done.end();   }   int moves = 0;   void doswap(int i, int j) {     ++moves;     assert(i != j);     assert(min(i, j) >= 0 && max(i, j) < int((vg).size()));     assert(cando(i, j));     printf( %d %d n , min(i, j) + 1, max(i, j) + 1);     swap(p[i], p[j]);     swap(vg[i], vg[j]);     done.insert(make_pair(min(i, j), max(i, j)));   }   void brute_force(vector<int> pp) {     int N = int((pp).size());     vector<pair<int, int> > op;     vector<int> aim = pp;     sort((aim).begin(), (aim).end());     for (int i = (0); i < (N); i++)       for (int j = (0); j < (i); j++)         if (cando(i, j)) op.push_back(make_pair(i, j));     sort((op).begin(), (op).end());     do {       vector<int> tmp = pp;       for (auto it : op) {         swap(tmp[it.first], tmp[it.second]);       }       if (tmp == aim) {         for (auto it : op) doswap(it.first, it.second);         return;       }     } while (next_permutation((op).begin(), (op).end()));     cerr <<  EPIC FAIL n ;   }   int main() {     ios::sync_with_stdio(false);     int N;     cin >> N;     if (N == 1) {       cout <<  YES n ;       return 0;     }     if ((N * (N - 1)) % 4 != 0) {       cout <<  NO n ;       return 0;     }     printf( YES n );     p = vector<int>(N);     for (int i = (0); i < (N); i++) p[i] = i;     vg = p;     while (true) {       vector<int> ids;       for (int i = (0); i < (N); i++)         if (p[i] != -1) ids.push_back(i);       int S = int((ids).size());       if (S <= 1) break;       assert(ids[S - 1] == S - 1);       if (S <= 5) {         vector<int> tmp(S);         for (int i = (0); i < (S); i++) tmp[i] = p[i];         brute_force(tmp);         break;       }       vector<int> x(S - 1);       for (int i = (0); i < (S - 1); i++) x[i] = i;       random_shuffle((x).begin(), (x).end());       if (p[S - 1] == S - 1) {         bool ok = false;         while (!ok) {           int z1 = max((rand() % (S - 1)), rand() % (S - 1));           int z2 = max((rand() % (S - 1)), rand() % (S - 1));           if (z1 == z2) continue;           if (!cando(z1, S - 1) || !cando(z2, S - 1)) continue;           if (!cando(z1, z2)) continue;           ok = true;           doswap(z2, S - 1);           doswap(z2, z1);           for (auto i : x) {             if (i != z1 && i != z2 && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(z1, S - 1);         }       } else {         int id_largest = -1;         for (int i = (0); i < (S); i++)           if (p[i] == S - 1) id_largest = i;         assert(id_largest != -1);         if (cando(id_largest, S - 1)) {           for (auto i : x) {             if (i != id_largest && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(id_largest, S - 1);         } else {           int z = S - 2;           while (!cando(z, S - 1) || !cando(id_largest, z)) --z;           assert(z >= 0);           assert(z != id_largest);           doswap(id_largest, z);           for (auto i : x) {             if (i != z && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(z, S - 1);         }       }       assert(p[S - 1] == S - 1);       p[S - 1] = -1;     }     assert(moves == (N * (N - 1)) / 2);     for (int i = (0); i < (N); i++) assert(vg[i] == i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int Mod = 1e9 + 7;   const int Mod2 = 49157;   const int p = 10;   inline long long Read() {     long long Ans = 0;     char Ch = getchar(), Las =    ;     while (!isdigit(Ch)) {       Las = Ch;       Ch = getchar();     }     while (isdigit(Ch)) {       Ans = (Ans << 3) + (Ans << 1) + Ch -  0 ;       Ch = getchar();     }     if (Las ==  - ) Ans = -Ans;     return Ans;   }   inline void Write(long long x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x >= 10) Write(x / 10);     putchar(x % 10 +  0 );   }   unsigned long long Hash[1000010], Hash2[1000010], idx[1000010], Pow[1000010],       Pow2[1000010];   unsigned long long a, b, c;   unsigned long long a2, b2, c2;   int Left_a, Right_a, Left_b, Right_b, Left_c, Right_c, Len;   bool Flag;   string s;   inline void Get_Hash() {     Pow[0] = 1;     Pow2[0] = 1;     for (int i = 1; i <= 1000010 / 2; i++) {       Pow[i] = Pow[i - 1] * p % Mod;       Pow2[i] = Pow2[i - 1] * p % Mod2;     }     idx[0] = s[0] -  0 ;     Hash[0] = idx[0];     Hash2[0] = idx[0];     for (int i = 1; i < Len; i++) {       idx[i] = s[i] -  0 ;       Hash[i] = (Hash[i - 1] * p + idx[i]) % Mod;       Hash2[i] = (Hash2[i - 1] * p + idx[i]) % Mod2;     }   }   inline unsigned long long Cmp_Hash(int Left, int Right) {     if (Left == 0) return Hash[Right];     return (Hash[Right] + Mod - (Hash[Left - 1] * Pow[Right - Left + 1]) % Mod) %            Mod;   }   inline unsigned long long Cmp_Hash2(int Left, int Right) {     if (Left == 0) return Hash2[Right];     return (Hash2[Right] + Mod2 -             (Hash2[Left - 1] * Pow2[Right - Left + 1]) % Mod2) %            Mod2;   }   int main() {     cin >> s;     Len = s.size();     Get_Hash();     int j;     for (int i = 1; i <= Len / 2; i++) {       if (i > 1 and idx[0] == 0) break;       a = Cmp_Hash(0, i - 1);       a2 = Cmp_Hash2(0, i - 1);       if (i < Len / 3 + 1) {         j = (Len - i) / 2;         if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) {           b = Cmp_Hash(i, i + j - 1);           b2 = Cmp_Hash2(i, i + j - 1);           c = Cmp_Hash(i + j, Len - 1);           c2 = Cmp_Hash2(i + j, Len - 1);           if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) {             Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i;             Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1;             break;           }         }         j = (Len - i - 1) / 2;         if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) {           b = Cmp_Hash(i, i + j - 1);           b2 = Cmp_Hash2(i, i + j - 1);           c = Cmp_Hash(i + j, Len - 1);           c2 = Cmp_Hash2(i + j, Len - 1);           if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) {             Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i;             Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1;             break;           }         }       }       if (i > (Len - 1) / 3 - 1) {         j = Len - 2 * i;         if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) {           b = Cmp_Hash(i, i + j - 1);           b2 = Cmp_Hash2(i, i + j - 1);           c = Cmp_Hash(i + j, Len - 1);           c2 = Cmp_Hash2(i + j, Len - 1);           if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) {             Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i;             Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1;             break;           }         }         j = Len - 2 * i - 1;         if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) {           b = Cmp_Hash(i, i + j - 1);           b2 = Cmp_Hash2(i, i + j - 1);           c = Cmp_Hash(i + j, Len - 1);           c2 = Cmp_Hash2(i + j, Len - 1);           if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) {             Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i;             Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1;             break;           }         }       }       if (Flag == 1) break;     }     if (Flag == 1) {       for (int i = Left_a; i <= Right_a; i++) Write(idx[i]);       putchar( + );       for (int i = Left_b; i <= Right_b; i++) Write(idx[i]);       putchar( = );       for (int i = Left_c; i <= Right_c; i++) Write(idx[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double EPS = 1e-7;   const int inf = 1e8;   int main() {     int n, sum = 0;     cin >> n;     vector<int> in(n);     for (int i = 0; i < n; i++) cin >> in[i];     for (int i = 0; i < n; i++) sum += in[i];     vector<int> used(n);     for (int i = 0; i < n; i++)       if (!used[i]) {         for (int j = i + 1; j < n; j++)           if (!used[j] && in[i] + in[j] == sum * 2 / n) {             used[i] = used[j] = true;             cout << i + 1 <<     << j + 1 << endl;             break;           }       }   }


#include <bits/stdc++.h>   using namespace std;   long long n, p, q, r, e, ans;   vector<long long> fst, lst, mid, Ans;   int main() {     cin >> n >> p >> q >> r;     for (int i = 0; i < n; i++) {       cin >> e;       fst.push_back(p * e);       mid.push_back(q * e);       lst.push_back(r * e);     }     long long mxe;     mxe = fst[0];     for (int i = 1; i < n; i++) {       mxe = max(mxe, fst[i]);       fst[i] = mxe;     }     mxe = lst[n - 1];     for (int i = n - 2; i >= 0; i--) {       mxe = max(mxe, lst[i]);       lst[i] = mxe;     }     for (int i = 0; i < n; i++) {       ans = fst[i] + mid[i] + lst[i];       Ans.push_back(ans);     }     cout << *max_element(Ans.begin(), Ans.end());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m][n];     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     int ans[n];     memset(ans, 0, sizeof(ans));     int k = 0;     int x = 0, y = 0;     int ma = INT_MIN;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (a[i][j] > ma) {           x = j;           ma = a[i][j];         }       }       ans[x]++;       ma = INT_MIN;     }     ma = INT_MIN;     for (int i = 0; i < n; i++) {       if (ans[i] > ma) {         x = i;         ma = ans[i];       }     }     cout << x + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<string, set<string> > ma;   set<string> hostname;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       int i = s.find( / , 7);       if (i != -1) {         string path = s.substr(i, s.size());         string name = s.substr(0, i);         ma[name].insert(path);         hostname.insert(name);       } else {         ma[s].insert( lorem );         hostname.insert(s);       }     }     map<set<string>, vector<string> > ans;     for (string s : hostname) {       ans[ma[s]].emplace_back(s);     }     for (auto it = begin(ans); it != end(ans);) {       if ((it->second).size() == 1) {         ans.erase(it->first);         it = begin(ans);       } else         ++it;     }     cout << ans.size() <<   n ;     for (auto [key, val] : ans) {       for (string s : val) {         cout << s <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   T min(T x, T y) {     return x < y ? x : y;   }   template <typename T>   T max(T x, T y) {     return x > y ? x : y;   }   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T gcd(T x, T y) {     return x ? gcd(y % x, x) : y;   }   int main() {     int t, d, l, r, p;     scanf( %d , &t);     while (t--) {       scanf( %d %d %d %d , &d, &p, &l, &r);       printf( %d n , d / p - r / p + (l - 1) / p);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename num_t>   inline void addmod(num_t& a, const long long& b, const int& m) {     a = (a + b) % m;     if (a < 0) a += m;   }   template <typename num_t>   inline void update_max(num_t& a, const num_t& b) {     a = max(a, b);   }   template <typename num_t>   inline void update_min(num_t& a, const num_t& b) {     a = min(a, b);   }   template <typename num_t>   num_t gcd(num_t lhs, num_t rhs) {     return !lhs ? rhs : gcd(rhs % lhs, lhs);   }   template <typename num_t>   num_t pw(num_t n, num_t k, num_t mod) {     num_t res = 1;     for (; k > 0; k >>= 1) {       if (k & 1) res = 1ll * res * n % mod;       n = 1ll * n * n % mod;     }     return res;   }   const int inf = 1e9 + 7;   const int mod = inf;   const int MAX_N = 200000 + 7;   const long long ll_inf = 9ll * inf * inf;   int n, k;   array<int, 5> arr[MAX_N];   int pre_calc[32][MAX_N];   int calc(array<int, 5>& arr, int mask) {     int sum = 0;     for (int i = (0), _b = (k); i < _b; ++i)       if (mask & (1 << i))         sum += arr[i];       else         sum -= arr[i];     return sum;   }   void update(int i, array<int, 5>& temp) {     arr[i] = temp;     for (int mask = (0), _b = (1 << k); mask < _b; ++mask) {       pre_calc[mask][i] = calc(temp, mask);     }   }   template <typename num_t>   class SegmentTree {    public:     void init(int l, int r) {       tree.resize((r - l + 1) << 1);       node_index = 0;       build_tree(tree[node_index++], l, r);     }     void update(int left_index, int right_index) {       update_(tree[0], left_index, right_index);     }     num_t get(int left_index, int right_index) {       if (right_index < left_index) return 0;       return get(tree[0], left_index, right_index).best_value;     }       private:     struct node {       static const num_t nil = 0;       node *left_child, *right_child;       int left_index, right_index;       array<int, 32> min_value;       array<int, 32> max_value;       int best_value = 0;       bool inited = false;       void push_down() {         for (int i = (0), _b = (1 << k); i < _b; ++i) {           min_value[i] = max_value[i] = left_index;         }         best_value = 0;         inited = true;       }       inline int dist(array<int, 5>& lhs, array<int, 5>& rhs) {         int sum = 0;         for (int i = (0), _b = (k); i < _b; ++i) sum += abs(lhs[i] - rhs[i]);         return sum;       }       void merge_node() {         node &lhs = *left_child, &rhs = *right_child;         merge_node(lhs, rhs);       }       void merge_node(node& lhs, node& rhs) {         best_value = max(lhs.best_value, rhs.best_value);         inited = true;         if (lhs.inited && rhs.inited) {           for (int i = (0), _b = (1 << k); i < _b; ++i) {             update_max(best_value,                        dist(arr[lhs.max_value[i]], arr[rhs.min_value[i]]));             update_max(best_value,                        dist(arr[rhs.max_value[i]], arr[lhs.min_value[i]]));             if (pre_calc[i][lhs.max_value[i]] <= pre_calc[i][rhs.max_value[i]])               max_value[i] = rhs.max_value[i];             else               max_value[i] = lhs.max_value[i];             if (pre_calc[i][lhs.min_value[i]] <= pre_calc[i][rhs.min_value[i]])               min_value[i] = lhs.min_value[i];             else               min_value[i] = rhs.min_value[i];           }         } else if (lhs.inited) {           min_value = lhs.min_value;           max_value = lhs.max_value;         } else {           min_value = rhs.min_value;           max_value = rhs.max_value;         }       }       void lazy_update() {}       inline void init(int left, int right, node* left_child_,                        node* right_child_) {         left_index = left;         right_index = right;         left_child = left_child_;         right_child = right_child_;       }       int size() const { return right_index - left_index + 1; }     };     vector<node> tree;     int node_index = 0;     void build_tree(node& root, int left, int right) {       if (left == right) {         root.init(left, right, nullptr, nullptr);         root.push_down();         return;       }       int mid = (left + right) >> 1, lhs = node_index++, rhs = node_index++;       build_tree(tree[lhs], left, mid);       build_tree(tree[rhs], mid + 1, right);       root.init(left, right, &tree[lhs], &tree[rhs]);       root.merge_node();     }     void update_(node& root, int u, int v) {       if (u > root.right_index || v < root.left_index) return;       if (u <= root.left_index && root.right_index <= v) {         root.push_down();       } else {         root.lazy_update();         update_(*root.left_child, u, v);         update_(*root.right_child, u, v);         root.merge_node();       }     }     node get(node& root, int u, int v) {       if (u <= root.left_index && root.right_index <= v) return root;       if (u > root.right_index || v < root.left_index) return node();       root.lazy_update();       auto lhs = get(*root.left_child, u, v);       auto rhs = get(*root.right_child, u, v);       node ans;       ans.merge_node(lhs, rhs);       return ans;     }   };   SegmentTree<int> segment_tree;   void solve() {     cin >> n >> k;     for (int i = (0), _b = (n); i < _b; ++i) {       array<int, 5> cur;       for (int j = (0), _b = (k); j < _b; ++j) cin >> cur[j];       update(i, cur);     }     segment_tree.init(0, n - 1);     int q;     cin >> q;     while (q-- > 0) {       int op;       cin >> op;       if (op == 1) {         int u;         cin >> u;         --u;         array<int, 5> cur;         for (int j = (0), _b = (k); j < _b; ++j) cin >> cur[j];         update(u, cur);         segment_tree.update(u, u);       } else {         int u, v;         cin >> u >> v;         cout << segment_tree.get(u - 1, v - 1) <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     const bool multiple_test = false;     int test = 1;     if (multiple_test) cin >> test;     for (int i = 0; i < test; ++i) {       solve();     }   }


#include <bits/stdc++.h>   int next[1 + (1000 * (1000 - 1)) * 2], hh[1 + (1000 * (1000 - 1)) * 2], l_;   int link(int l, int h) {     next[l_] = l;     hh[l_] = h;     return l_++;   }   int ij[(1000 * (1000 - 1))], ww[(1000 * (1000 - 1))], ao[1000];   long long ww_[1000][1000];   int pq[1 + 1000], iq[1000], cnt;   long long *dd;   int less(int u, int v) { return dd[u] < dd[v]; }   int i2(int i) {     return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;   }   void pq_up(int u) {     int i, j, v;     for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j) pq[iq[v] = i] = v;     pq[iq[u] = i] = u;   }   void pq_dn(int u) {     int i, j, v;     for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j) pq[iq[v] = i] = v;     pq[iq[u] = i] = u;   }   void pq_add_last(int u) { iq[u] = ++cnt; }   int pq_remove_first() {     int u = pq[1], v = pq[cnt--];     iq[v] = 1;     pq_dn(v);     return u;   }   void dijkstra(int s, int n) {     int h, i, j, l, w;     memset(dd, 0x3f, n * sizeof *dd), dd[s] = 0;     pq_add_last(s), pq_up(s);     while (cnt) {       i = pq_remove_first();       for (l = ao[i]; l; l = next[l]) {         h = hh[l];         j = i ^ ij[h];         w = ww[h];         if (dd[j] > dd[i] + w) {           if (dd[j] == 0x3f3f3f3f3f3f3f3fLL) pq_add_last(j);           dd[j] = dd[i] + w;           pq_up(j);         }       }     }   }   int main() {     int n, m, s, t, h, i, j, w, d, c;     scanf( %d%d%d%d , &n, &m, &s, &t), s--, t--;     l_ = 1;     for (h = 0; h < m; h++) {       scanf( %d%d%d , &i, &j, &w), i--, j--;       ij[h] = i ^ j;       ww[h] = w;       ao[i] = link(ao[i], h);       ao[j] = link(ao[j], h);     }     for (i = 0; i < n; i++) {       dd = ww_[i];       dijkstra(i, n);     }     l_ = 1;     m = 0;     for (i = 0; i < n; i++) {       scanf( %d%d , &d, &c);       dd = ww_[i];       ao[i] = 0;       for (j = 0; j < n; j++)         if (j != i && dd[j] <= d) {           ij[m] = i ^ j;           ww[m] = c;           ao[i] = link(ao[i], m++);         }     }     dijkstra(s, n);     printf( %lld n , dd[t] == 0x3f3f3f3f3f3f3f3fLL ? -1 : dd[t]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     int x, y, nr;     bool t;   };   const int N = 2e4 + 7;   int n, m;   int ans[N];   Point tab[N];   bool cmp(Point a, Point b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   int xr, yr;   void change(Point &a) {     xr = a.x;     yr = a.y;   }   bool cmp2(Point a, Point b) {     return (a.x - xr) * (b.y - yr) < (b.x - xr) * (a.y - yr);   }   void wczytaj(int a) {     scanf( %d %d , &tab[a].x, &tab[a].y);     tab[a].nr = a;     if (a > n) {       tab[a].t = true;       tab[a].nr -= n;     }   }   void connect(int x, int y) {     if (tab[x].t)       ans[tab[y].nr] = tab[x].nr;     else       ans[tab[x].nr] = tab[y].nr;   }   void solve(int from, int to) {     if (from > to) return;     assert((to - from) % 2 == 1);     if (from + 1 == to) {       connect(from, to);       return;     }     int id = min_element(tab + from, tab + to + 1, cmp) - tab;     swap(tab[id], tab[from]);     change(tab[from]);     sort(tab + from + 1, tab + to + 1, cmp2);     int pref = 0, mid = 0;     for (int i = from + 1; i <= to; ++i) {       if (tab[i].t != tab[from].t && pref == 0) {         mid = i;         break;       }       pref += tab[i].t ? 1 : -1;     }     assert(mid != 0);     connect(from, mid);     solve(from + 1, mid - 1);     solve(mid + 1, to);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) wczytaj(i);     for (int i = 1; i <= n; ++i) wczytaj(n + i);     solve(1, 2 * n);     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);     return 0;   }


#include <iostream>   #include <vector>   #include <set>    #include <algorithm>   #include<map>   #include <math.h>   using namespace std;   void solve(){      int n,x,t;      cin>>n>>x>>t;      cout<<(long long)max(0,n-t/x)*(t/x) + (long long)min(n,t/x)*min(n-1,t/x-1)/2<<endl;          }      int main()   {   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int testCase;       cin>>testCase;       while (testCase--)       {           solve();       }          }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long power(long long B, long long P) {     if (P == 0) return 1;     long long X = power(B, P / 2);     if (P % 2 == 0)       return X * X;     else       return B * X * X;   }   long long fx4[] = {1, -1, 0, 0};   long long fy4[] = {0, 0, 1, -1};   long long D[300005], C[300005];   int main() {     long long T, N, M, X, Y, W, K, Q, R, P;     cin >> N;     for (int i = 1; i < N; i++) {       cin >> X >> Y;       D[X]++;       D[Y]++;     }     for (int i = 1; i <= N; i++) {       if (D[i] == 2) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     long long int n, k;     long long int right = (long long int)2e9;     long long int left = 0;     cin >> n >> k;     long long int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     while (right - left > 0) {       long long int mid = (right + left + 1) / 2;       long long int cnt = 0;       for (int i = 0; i < n; i++) {         cnt += max(0LL, mid * a[i] - b[i]);         if (cnt > k) break;       }       if (cnt <= k)         left = mid;       else         right = mid - 1;     }     cout << left;   }   int main() {     solve();     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct dat {     int x, rev, f, cap, cost;     dat(int x = 0, int rev = 0, int f = 0, int cap = 0, int cost = 0)         : x(x), rev(rev), f(f), cap(cap), cost(cost) {}   };   vector<dat> v[5100];   void add(int s, int t, int ca, int co) {     int n = v[s].size();     int m = v[t].size();     v[s].push_back(dat(t, m, 0, ca, co));     v[t].push_back(dat(s, n, 0, 0, -co));   }   priority_queue<pair<int, int> > q;   pair<int, int> pa[5100];   int pot[5100], vis[5100], A[5100 * 10], dist[5100], col[5100][5100], a[5100],       b[5100], deg[5100], deg1[5100], fl[5100];   int mx = 0;   int doit(int de) {     int mxx = 0;     for (int i = 0; i <= de; i++) pot[i] = 1e9;     pot[0] = 0;     int qt = 0;     A[qt++] = 0;     int nodes = de + 1;     for (int i = 0; i <= de; i++) vis[i] = 0;     for (int qh = 0; (qh - qt) % nodes != 0; qh++) {       int u = A[qh % nodes];       vis[u] = false;       for (int i = 0; i < (int)v[u].size(); i++) {         dat e = v[u][i];         if (e.cap == e.f) continue;         int vv = e.x;         int ndist = pot[u] + e.cost;         if (pot[vv] > ndist) {           pot[vv] = ndist;           if (!vis[vv]) {             vis[vv] = true;             A[qt++ % nodes] = vv;           }         }       }     }     while (1) {       for (int i = 0; i <= de; i++) fl[de] = 0;       for (int i = 0; i <= de; i++) dist[i] = 1e9;       dist[0] = 0;       while (!q.empty()) q.pop();       q.push(pair<int, int>(0, 0));       fl[0] = 1e9;       while (!q.empty()) {         pair<int, int> aa = q.top();         q.pop();         int x = aa.second;         if (-aa.first != dist[x]) continue;         for (int i = 0; i < v[x].size(); i++) {           dat bb = v[x][i];           if (bb.f == bb.cap) continue;           int y = bb.x;           int xx = dist[x] + bb.cost + pot[x] - pot[y];           if (dist[y] > xx) {             dist[y] = xx;             q.push(pair<int, int>(-dist[y], y));             pa[y] = pair<int, int>(x, i);             fl[y] = min(fl[x], bb.cap - bb.f);           }         }       }       if (!fl[de]) break;       mxx += fl[de];       for (int i = 0; i <= de; i++) pot[i] += dist[i];       int x = de;       while (1) {         pair<int, int> aa = pa[x];         int y = aa.first;         int id = aa.second;         v[y][id].f += fl[de];         v[x][v[y][id].rev].f -= fl[de];         if (!y) break;         x = y;       }     }     return mxx;   }   int main() {     int n, m, K, T;     scanf( %d%d%d%d , &n, &m, &K, &T);     for (int i = 1; i <= K; i++) {       scanf( %d%d , &a[i], &b[i]);       deg[a[i]]++;       deg1[b[i]]++;     }     int ans = 0;     for (int i = 1; i <= n; i++) ans += (deg[i] % T) > 0;     for (int i = 1; i <= m; i++) ans += (deg1[i] % T) > 0;     printf( %d n , ans);     int so = 0;     int de = m + n + 1;     mx = 0;     for (int i = T; i; i--) {       for (int j = 0; j <= de; j++) v[j].clear();       for (int j = 1; j <= K; j++)         if (!col[a[j]][b[j]]) {           add(a[j], b[j] + n, 1, 0);         }       int kt = 0;       for (int j = 1; j <= n; j++) {         add(so, j, deg[j] / i, 0);         kt += deg[j] / i;         if (deg[j] % i) add(so, j, 1, 1);       }       int kt1 = 0;       for (int j = 1; j <= m; j++) {         add(j + n, de, deg1[j] / i, 0);         if (deg1[j] % i) add(j + n, de, 1, 1);       }       int mm = doit(de);       mx += mm;       for (int j = 1; j <= n; j++) {         for (int k = 0; k < v[j].size(); k++) {           dat aa = v[j][k];           if (aa.x == so) continue;           if (aa.f == 1) {             int y = aa.x;             if (y > n && y <= n + m) {               col[j][y - n] = i;               deg[j]--, deg1[y - n]--;             }           }         }       }     }     for (int i = 1; i <= K; i++) printf( %d  , col[a[i]][b[i]]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> g[100010];   int vis[100010];   struct node {     int num;     long long inc;     long long dec;     int val;   } nodes[100010];   void dfs(node &u) {     vis[u.num] = 1;     for (int v : g[u.num]) {       if (!vis[v]) {         dfs(nodes[v]);         u.inc = max(u.inc, nodes[v].inc);         u.dec = max(u.dec, nodes[v].dec);       }     }     if (u.val + u.inc - u.dec < 0) {       u.inc += abs(u.val + u.inc - u.dec);     } else {       u.dec += abs(u.val + u.inc - u.dec);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       nodes[i].num = i;       nodes[i].inc = nodes[i].dec = 0;     }     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; ++i) {       int v;       cin >> v;       nodes[i].val = v;     }     dfs(nodes[1]);     cout << nodes[1].inc + nodes[1].dec;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Q;   long long int N;   int cheats[20] = {0, 0, 1, 2, 3, 4, 6, 7, 8, 10, 12};   int main() {     scanf( %d , &Q);     for (int qi = 0; qi < Q; qi++) {       scanf( %lld , &N);       if (N < 10) {         printf( %d n , cheats[(int)N]);         continue;       }       long long int low = 3, high = N / 2, med, v;       while (low != high) {         med = (high + low + 1) / 2;         v = med * (med - 1) / 2;         if (v <= (N - med))           low = med;         else           high = med - 1;       }       high = low * (low - 1) / 2;       if (N - low >= high + 3)         printf( %lld n , 2 * (N - low - 1));       else         printf( %lld n , high + N - low);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   void PLAY() {     cout << fixed << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int num_cost[100005];   int mp[205][100005];   int freq_cum[100005];   int freq[100005];   int main() {     PLAY();     int n;     cin >> n;     vector<int> v(n);     set<int> st;     for (int i = 0; i < n; i++) {       cin >> v[i];       freq_cum[v[i]]++;       freq[v[i]]++;       st.insert(v[i]);     }     for (int i = 0; i < n; i++) {       int d;       cin >> d;       num_cost[v[i]] += d;       mp[d][v[i]]++;     }     vector<int> srtd(st.begin(), st.end());     sort(srtd.rbegin(), srtd.rend());     for (int i = 1; i < 100005; i++) {       num_cost[i] += num_cost[i - 1];       freq_cum[i] += freq_cum[i - 1];     }     for (int i = 1; i <= 200; i++)       for (int j = 1; j < 100005; j++) mp[i][j] += mp[i][j - 1];     int res = INT_MAX;     for (int i = 0; i < (int)srtd.size(); i++) {       int num = srtd[i];       int cur_cost = num_cost[srtd[0]] - num_cost[srtd[i]];       int removed = freq_cum[srtd[0]] - freq_cum[num];       int rem = n - removed;       int remove = max(0, rem - (freq[num] * 2 - 1));       for (int cost = 1; cost <= 200 && remove; cost++) {         int avilable = mp[cost][num - 1] - mp[cost][0];         int cnt = min(remove, avilable);         cur_cost += cnt * cost;         remove -= cnt;       }       res = min(res, cur_cost);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[200005];   int sz[200005];   void init(int node) {     sz[node] = 1;     for (auto it : g[node]) {       init(it);       sz[node] = sz[node] + sz[it];     }   }   void dfs(int node) {     for (auto it : g[node]) {       if (!(sz[it] & 1)) dfs(it);     }     cout << node <<   n ;     for (auto it : g[node]) {       if (sz[it] & 1) dfs(it);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i, pi, r;     cin >> n;     if (!(n & 1)) {       cout <<  NO n ;       return 0;     }     for (i = 1; i <= n; i++) {       cin >> pi;       if (pi == 0)         r = i;       else         g[pi].push_back(i);     }     init(r);     cout <<  YES n ;     dfs(r);     return 0;   }