#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j;     cin >> n;     map<long long, long long> mp, cp;     vector<long long> v(n);     for (i = 0; i < n; i++) {       cin >> v[i];       mp[v[i]]++;     }     map<long long, long long>::iterator it;     for (it = mp.begin(); it != mp.end(); it++) {       cp[it->second]++;     }     if (cp.find(1) == cp.end() || cp[1] % 2 == 0) {       long long cnt = 0;       cout <<  YES  << endl;       for (i = 0; i < n; i++) {         if (mp[v[i]] == 1) {           if (cnt < cp[1] / 2) {             cout <<  A ;           } else             cout <<  B ;           cnt++;         } else           cout <<  A ;       }     } else {       if (cp[1] + 2 * cp[2] == n) {         cout <<  NO ;       } else {         cout <<  YES  << endl;         long long cnt = 0, t = 1;         for (i = 0; i < n; i++) {           if (mp[v[i]] == 1) {             if (cnt < (cp[1] + 1) / 2) {               cout <<  A ;             } else {               cout <<  B ;             }             cnt++;           } else if (mp[v[i]] == 2) {             cout <<  A ;           } else {             if (t == 1) {               cout <<  B ;               t++;             } else {               cout <<  A ;             }           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1E9 + 9;   int n, m, ans, cntNode(1),       root(1), f[200], dp[1005][105][13], vis[1005][105][13];   string s;   struct Trie {     int son[4], fail, len;     Trie() {       for (int i = 0; i < 4; i++) son[i] = 0;       fail = len = 0;     }   } tr[105];   void add(int& a, int b) { a = (a + b) % MOD; }   void insert(string& s) {     int cur = root;     for (int i = 0; i < s.size(); i++) {       if (!tr[cur].son[f[s[i]]]) tr[cur].son[f[s[i]]] = ++cntNode;       cur = tr[cur].son[f[s[i]]];     }     tr[cur].len = s.size();   }   void getFail() {     queue<int> Q;     Q.push(root);     tr[root].fail = root;     while (!Q.empty()) {       int now = Q.front();       Q.pop();       tr[now].len = max(tr[now].len, tr[tr[now].fail].len);       for (int i = 0; i < 4; i++) {         if (tr[now].son[i]) {           tr[tr[now].son[i]].fail = now != root ? tr[tr[now].fail].son[i] : root;           Q.push(tr[now].son[i]);         } else           tr[now].son[i] =               tr[tr[now].fail].son[i] ? tr[tr[now].fail].son[i] : root;       }     }   }   void DP() {     queue<tuple<int, int, int> > Q;     dp[0][1][0] = 1;     Q.push(make_tuple(0, 1, 0));     while (!Q.empty()) {       int len = get<0>(Q.front());       int node = get<1>(Q.front());       int last = get<2>(Q.front());       Q.pop();       if (len == n) {         if (!last) add(ans, dp[len][node][last]);         continue;       }       vis[len][node][last] = 0;       for (int i = 0; i < 4; i++) {         int to = tr[node].son[i];         int tmp = tr[to].len > last ? 0 : last + 1;         if (tmp > 10) continue;         add(dp[len + 1][to][tmp], dp[len][node][last]);         if (!vis[len + 1][to][tmp]) {           vis[len + 1][to][tmp] = 1;           Q.push(make_tuple(len + 1, to, tmp));         }       }     }     return;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> m;     f[ A ] = 0, f[ T ] = 1, f[ C ] = 2, f[ G ] = 3;     for (int i = 1; i <= m; i++) cin >> s, insert(s);     getFail();     DP();     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   T pow_mod(T a, U b, int mod) {     T r = 1;     for (; b > 0; b >>= 1) {       if (b & 1) r = (long long)r * a % mod;       a = (long long)a * a % mod;     }     return r;   }   namespace combinatorics {   const int mod = 1e9 + 7, N = 2e3 + 5;   int fac[N], ifac[N];   void init() {     fac[0] = ifac[0] = 1;     for (int i = 1; i < N; ++i) {       fac[i] = (long long)fac[i - 1] * i % mod;       ifac[i] = pow_mod(fac[i], mod - 2, mod);     }   }   int comb(int n, int k) {     return (long long)fac[n] * ifac[n - k] % mod * ifac[k] % mod;   }   }  // namespace combinatorics   using namespace combinatorics;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     init();     int t = 1;     while (t--) {       int n, x, p;       cin >> n >> x >> p;       vector<int> a(n), c(2);       a[p] = 1;       auto f = [&]() {         int l = 0, r = n;         while (l < r) {           int m = (l + r) >> 1;           if (m <= p) {             c[0] += a[m] == 0;             a[m] = -1;             l = m + 1;           } else {             c[1] += a[m] == 0;             a[m] = +1;             r = m;           }         }       };       f();       int ans = 0;       if (n - x >= c[1] && x - 1 >= c[0])         ans = (long long)comb(n - x, c[1]) * comb(x - 1, c[0]) % mod *               fac[n - 1 - c[0] - c[1]] % mod * fac[c[0]] % mod * fac[c[1]] % mod;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char opt;   long long a, b, c, ansa, ansb, ansc, anslen = 15;   void dfs(long long a, long long b, long long c, long long nowa, long long nowb,            int pre, long long len, long long step) {     if (len >= anslen) return;     if (!a && !b && !c && !pre) {       ansa = nowa, ansb = nowb, anslen = len;       return;     }     if (!c) {       long long tmp = a + b + pre;       int cnt = 0;       while (tmp) cnt++, tmp /= 10;       dfs(0, 0, 0, nowa + step * a, nowb + step * b, 0, len + cnt, step);       return;     }     if ((a + b + pre) % 10 == c % 10) {       dfs(a / 10, b / 10, c / 10, nowa + step * (a % 10), nowb + step * (b % 10),           (a % 10 + b % 10 + pre) / 10, len, step * 10);       return;     }     dfs(a * 10 + (c + 10 - b % 10 - pre) % 10, b, c, nowa, nowb, pre, len + 1,         step);     dfs(a, b * 10 + (c + 10 - a % 10 - pre) % 10, c, nowa, nowb, pre, len + 1,         step);     dfs(a, b, c * 10 + (a + b + pre) % 10, nowa, nowb, pre, len + 1, step);   }   int main() {     cin >> a >> opt >> b >> opt >> c;     dfs(a, b, c, 0, 0, 0, 0, 1);     cout << ansa <<  +  << ansb <<  =  << ansa + ansb << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int mod = 998244353;   int x[5], y[5];   int px[32], nx[32], py[32], ny[32];   int dp[32][20][20][20][20][2][2];   void add(int& x, const int& y) {     x += y;     if (x >= mod) x -= mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i += 1) cin >> x[i] >> y[i];     for (int mask = 0; mask < (1 << n); mask += 1)       for (int i = 0; i < n; i += 1)         if ((mask >> i) & 1) {           (x[i] > 0 ? px : nx)[mask] += abs(x[i]);           (y[i] > 0 ? py : ny)[mask] += abs(y[i]);         }     dp[0][0][0][0][0][0][0] = 1;     for (int i = 0; i < (30); i += 1)       for (int cpx = 0; cpx < (20); cpx += 1)         for (int cnx = 0; cnx < (20); cnx += 1)           for (int cpy = 0; cpy < (20); cpy += 1)             for (int cny = 0; cny < (20); cny += 1)               for (int bx = 0; bx < (2); bx += 1)                 for (int by = 0; by < (2); by += 1)                   for (int mask = 0; mask < (1 << n); mask += 1)                     if (dp[i][cpx][cnx][cpy][cny][bx][by]) {                       if (0)                         cout << i <<     << cpx <<     << cny <<     << cpy <<                                  << cny <<     << bx <<     << by <<                                  << dp[i][cpx][cnx][cpy][cny][bx][by] << endl;                       int npx = cpx + px[mask], nnx = cnx + nx[mask],                           npy = cpy + py[mask], nny = cny + ny[mask];                       if ((npx ^ nnx) & 1) continue;                       if ((npy ^ nny) & 1) continue;                       int cx = npx & 1, mx = (m >> i) & 1;                       int cy = npy & 1, my = (m >> i) & 1;                       add(dp[i + 1][npx >> 1][nnx >> 1][npy >> 1][nny >> 1]                             [cx != mx ? (cx > mx) : bx]                             [cy != my ? (cy > my) : by],                           dp[i][cpx][cnx][cpy][cny][bx][by]);                     }     cout << (dp[30][0][0][0][0][0][0] + mod - 1) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool qo(bool x) { return (x ? 0 : qo(!x)); }   const int mnx = 1e5 + 9;   const int mod = 1e9 + 7;   long long n, sum;   long long a[mnx];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int m = 0; m < (1 << n); m++) {       for (int j = 0; j < n; j++) {         if (m & (1 << j))           sum += a[j];         else           sum -= a[j];       }       if (sum % 360 == 0) {         cout <<  YES n ;         exit(0);         ;       }       sum = 0;     }     cout <<  NO n ;     exit(0);     ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = 1000001000;   const int mod = 1000 * 1000 * 1000 + 7;   const int mod9 = 1000 * 1000 * 1000 + 9;   const double PI = 3.1415926535897932;   double sqr(double first) { return first * first; };   long double sqr(long double first) { return first * first; };   long long sqr(long long first) { return first * first; };   long long sqr(int first) { return first * 1LL * first; };   long long gcd(long long a, long long b) {     while (b) a %= b, swap(a, b);     return a;   }   long long bpm(long long a, long long n = -2, long long m = mod) {     n = n >= 0 ? n : m + n;     long long r = 1;     while (n) {       if (n & 1) r = (r * a) % m;       a = (a * a) % m;       n >>= 1;     }     return r;   }   long long dist(long long x1, long long y1, long long x2, long long y2) {     return sqr(x1 - x2) + sqr(y1 - y2);   }   std::ostream& operator<<(std::ostream& os, pair<int, int> p) {     return os <<  {  << p.first <<     << p.second <<  } ;   }   const int N = 200005;   long long a[N];   pair<long long, long long> b[N];   int main() {     ios::sync_with_stdio(false);     long long n, m, s, d;     cin >> n >> m >> s >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int nwn = -1;     for (int i = 0; i < n; i++) {       b[i] = {a[i], a[i]};       if (i && a[i] - a[i - 1] < s + 2) {         b[nwn].second = b[i].first;       } else {         b[++nwn] = b[i];       }     }     n = nwn + 1;     vector<pair<long long, long long> > res;     long long pos = 0;     for (int i = 0; i < n; i++) {       long long next = b[i].first;       long long runD = next - 1 - pos;       bool err = false;       if (runD < s) {         err = true;       }       res.push_back({1, runD});       pos += runD;       long long fin = b[i].second + 1;       if (fin > m || fin - pos > d) {         err = true;       }       res.push_back({0, fin - pos});       pos = fin;       if (err) {         pos = m;         res.clear();         res.push_back({-1, 0});         break;       }     }     if (pos != m) {       res.push_back({1, m - pos});     }     for (pair<int, int> d : res) {       switch (d.first) {         case -1:           cout <<  IMPOSSIBLE n ;           break;         case 0:           cout <<  JUMP   << d.second <<   n ;           break;         case 1:           cout <<  RUN   << d.second <<   n ;           break;       }     }     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-10;   const double PI = acos(-1.0);   using namespace std;   int main(void) {     int n;     cin >> n;     vector<pair<int, int> > e;     for (int i = (0); i < (n); ++i) {       int a, b;       cin >> a >> b;       e.push_back(make_pair(a, b));     }     sort((e).begin(), (e).end());     int answer = 0;     for (int i = (0); i < (n); ++i) {       if (answer <= e[i].second)         answer = e[i].second;       else         answer = e[i].first;     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char field[50][50];   bool used[50][50];   int n, m, k;   int counts[26];   int cur_set;   set<string> min_ways;   int min_len = INT_MAX;   int start_x, start_y, end_x, end_y;   vector<char> alpha(0);   bool comp(pair<int, int> a, pair<int, int> b) {     if (field[a.first][a.second] ==  T ) return true;     if (field[b.first][b.second] ==  T ) return false;     return field[a.first][a.second] < field[b.first][b.second];   }   vector<pair<int, int>> find_near(int from_y, int from_x,                                    const set<char> &from_set) {     vector<pair<int, int>> near(0);     if (from_y > 0 && !used[from_y - 1][from_x] &&         from_set.find(field[from_y - 1][from_x]) != from_set.end())       near.push_back(make_pair(from_y - 1, from_x));     if (from_y < n - 1 && !used[from_y + 1][from_x] &&         from_set.find(field[from_y + 1][from_x]) != from_set.end())       near.push_back(make_pair(from_y + 1, from_x));     if (from_x > 0 && !used[from_y][from_x - 1] &&         from_set.find(field[from_y][from_x - 1]) != from_set.end())       near.push_back(make_pair(from_y, from_x - 1));     if (from_x < m - 1 && !used[from_y][from_x + 1] &&         from_set.find(field[from_y][from_x + 1]) != from_set.end())       near.push_back(make_pair(from_y, from_x + 1));     sort(near.begin(), near.end(), comp);     return near;   }   set<char> find_set_near(int from_y, int from_x) {     set<char> near = set<char>();     if (from_y > 0 && !used[from_y - 1][from_x])       near.insert(field[from_y - 1][from_x]);     if (from_y < n - 1 && !used[from_y + 1][from_x])       near.insert(field[from_y + 1][from_x]);     if (from_x > 0 && !used[from_y][from_x - 1])       near.insert(field[from_y][from_x - 1]);     if (from_x < m - 1 && !used[from_y][from_x + 1])       near.insert(field[from_y][from_x + 1]);     near.erase( T );     near.erase( S );     return near;   }   set<char> find_second_near_set(int from_y, int from_x, set<char> &not_from) {     bool l2, l1, r1, r2, u1, u2, d1, d2;     l2 = from_x - 2 >= 0;     l1 = from_x > 0;     r1 = from_x + 2 < m;     r2 = from_x + 1 < m;     u2 = from_y - 2 >= 0;     u1 = from_y > 0;     d1 = from_y + 1 < n;     d2 = from_y + 2 < n;     int yu2 = from_y - 2;     int yu1 = from_y - 1;     int yd1 = from_y + 1;     int yd2 = from_y + 2;     int xl2 = from_x - 2;     int xl1 = from_x - 1;     int xr1 = from_x + 1;     int xr2 = from_x + 2;     set<char> ret = set<char>();     if (l1 && u2) ret.insert(field[yu2][xl1]);     if (u2) ret.insert(field[yu2][from_x]);     if (u2 && r1) ret.insert(field[yu2][xr1]);     if (r2) {       if (u1) ret.insert(field[yu1][xr2]);       ret.insert(field[from_y][xr2]);       if (d1) ret.insert(field[yd1][xr2]);     }     if (d2) {       if (r1) ret.insert(field[yd2][xr1]);       ret.insert(field[yd2][from_x]);       if (l1) ret.insert(field[yd2][xl1]);     }     if (l2) {       if (d1) ret.insert(field[yd1][xl2]);       ret.insert(field[from_y][xl2]);       if (u1) ret.insert(field[yu1][xl2]);     }     for (set<char>::iterator i = not_from.begin(); i != not_from.end(); i++)       ret.erase(*i);     return ret;   }   void read() {     set<char> set_alpha = set<char>();     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> field[i][j];         if (field[i][j] ==  S ) {           start_y = i;           start_x = j;         } else if (field[i][j] ==  T ) {           end_y = i;           end_x = j;         } else           set_alpha.insert(field[i][j]);       }     for (set<char>::iterator i = set_alpha.begin(); i != set_alpha.end(); i++)       alpha.push_back(*i);   }   struct cell {     pair<int, int> pos;     string s;   };   struct comp2 {     bool operator()(const cell &a, const cell &b) {       if (a.s.size() != b.s.size())         return a.s.size() < b.s.size();       else         return a.s < b.s;     }   };   set<set<char>> last_sets;   bool wave(set<char> &cur_set) {     if (last_sets.find(cur_set) != last_sets.end())       return false;     else       last_sets.insert(cur_set);     memset(used, false, 2500);     used[start_y][start_x] = true;     cur_set.insert( T );     multiset<cell, comp2> myque;     cell tmp;     tmp.pos = make_pair(start_y, start_x);     tmp.s = string(  );     myque.insert(tmp);     while (!myque.empty()) {       cell cur_cell = *myque.begin();       myque.erase(myque.begin());       if (cur_cell.s.length() > min_len) break;       vector<pair<int, int>> near =           find_near(cur_cell.pos.first, cur_cell.pos.second, cur_set);       for (vector<pair<int, int>>::iterator i = near.begin(); i != near.end();            i++) {         if (field[i->first][i->second] ==  T ) {           if (cur_cell.s.length() < min_len) {             min_ways.clear();             min_len = cur_cell.s.length();           }           min_ways.insert(cur_cell.s);           break;         }         used[i->first][i->second] = true;         cell tmp = cur_cell;         tmp.pos = *i;         tmp.s.push_back(field[i->first][i->second]);         myque.insert(tmp);       }     }     cur_set.erase( T );     return false;   }   int main() {     read();     string s(  );     set<char> start_set = find_set_near(start_y, start_x);     set<char> end_set = find_set_near(end_y, end_x);     int l = alpha.size();     set<char> cur_set = set<char>();     if (!l)       wave(cur_set);     else {       for (set<char>::iterator a = start_set.begin(); a != start_set.end(); a++) {         cur_set.insert(*a);         if (cur_set.size() == k || l < k && cur_set.size() == l)           wave(cur_set);         else {           for (set<char>::iterator b = end_set.begin(); b != end_set.end(); b++) {             cur_set.insert(*b);             if (cur_set.size() == k || l < k && cur_set.size() == l)               wave(cur_set);             else {               for (int i = 0; i < l; i++) {                 if (cur_set.end() != cur_set.find(alpha[i])) continue;                 cur_set.insert(alpha[i]);                 if (cur_set.size() == k || l < k && cur_set.size() == l)                   wave(cur_set);                 else {                   for (int j = i + 1; j < l; j++) {                     if (cur_set.end() != cur_set.find(alpha[j])) continue;                     cur_set.insert(alpha[j]);                     if ((*a) == (*b) && cur_set.size() < k) {                       set<char> second_set =                           find_second_near_set(start_y, start_x, cur_set);                       if (!second_set.size())                         wave(cur_set);                       else {                         for (set<char>::iterator p = second_set.begin();                              p != second_set.end(); p++) {                           cur_set.insert(*p);                           wave(cur_set);                           cur_set.erase(*p);                         }                       }                     } else                       wave(cur_set);                     cur_set.erase(alpha[j]);                   }                 }                 cur_set.erase(alpha[i]);               }             }             cur_set.erase(*b);           }         }         cur_set.erase(*a);       }     }   label_end:     if (min_len == INT_MAX)       cout <<  -1 ;     else       cout << (*min_ways.begin());   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> AE[1000005];   long long par[1000005];   enum LG { AND = 1, OR = 2, XOR = 3, NOT = 4, IN = 5 };   long long type[1000005], inp[1000005];   inline void nedge(long long a, long long b) { AE[a].push_back(b), par[b] = a; }   bool oans[1000005];   bool dfs(long long p) {     if (AE[p].size()) {       volatile bool A = dfs(AE[p][0]), B = AE[p].size() > 1 ? dfs(AE[p][1]) : 0;       if (type[p] == AND)         oans[p] = (A and B);       else if (type[p] == OR)         oans[p] = (A or B);       else if (type[p] == XOR)         oans[p] = (A xor B);       else if (type[p] == NOT)         oans[p] = (not A);     } else       oans[p] = inp[p];     return oans[p];   }   bool ans[1000005];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       string x;       cin >> x;       long long a, b;       if (x ==  AND ) cin >> a >> b, nedge(i, a), nedge(i, b), type[i] = AND;       if (x ==  OR ) cin >> a >> b, nedge(i, a), nedge(i, b), type[i] = OR;       if (x ==  XOR ) cin >> a >> b, nedge(i, a), nedge(i, b), type[i] = XOR;       if (x ==  NOT ) cin >> a, nedge(i, a), type[i] = NOT;       if (x ==  IN ) cin >> a, inp[i] = a, type[i] = IN;     }     dfs(1);     queue<long long> q;     q.push(1);     while (!q.empty()) {       long long p = q.front(), pa = par[p];       q.pop();       bool nans = 0;       if (p == 1)         ans[p] = !oans[p];       else {         long long a = AE[pa][0], b = AE[pa].size() > 1 ? AE[pa][1] : -1;         if (type[pa] == AND)           nans = ((oans[a] ^ (p == a)) and (oans[b] ^ (p == b)));         else if (type[pa] == OR)           nans = ((oans[a] ^ (p == a)) or (oans[b] ^ (p == b)));         else if (type[pa] == XOR)           nans = ((oans[a] ^ (p == a)) xor (oans[b] ^ (p == b)));         else if (type[pa] == NOT)           nans = (not(oans[a] ^ (p == a)));         ans[p] = (nans != oans[pa]) ? ans[pa] : oans[1];       }       for (long long x : AE[p]) q.push(x);     }     for (long long i = 1; i <= n; i++)       if (type[i] == IN) cout << ans[i];     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct osoba {     string ime, prezime;   };   int main() {     int n;     cin >> n;     vector<osoba> osobe(n);     vector<int> redoslijed(n);     vector<string> minori(n);     bool trigger = true;     for (int i = 0; i < n; i++) cin >> osobe[i].ime >> osobe[i].prezime;     for (int i = 0; i < n; i++) cin >> redoslijed[i];     if (strcmp(osobe[redoslijed[0] - 1].ime.c_str(),                osobe[redoslijed[0] - 1].prezime.c_str()) < 0)       minori[0] = osobe[redoslijed[0] - 1].ime;     else       minori[0] = osobe[redoslijed[0] - 1].prezime;     for (int i = 1; i < n; i++) {       if (strcmp(minori[i - 1].c_str(), osobe[redoslijed[i] - 1].ime.c_str()) >               0 &&           strcmp(minori[i - 1].c_str(),                  osobe[redoslijed[i] - 1].prezime.c_str()) <= 0)         minori[i] = osobe[redoslijed[i] - 1].prezime;       else if (strcmp(minori[i - 1].c_str(),                       osobe[redoslijed[i] - 1].ime.c_str()) <= 0 &&                strcmp(minori[i - 1].c_str(),                       osobe[redoslijed[i] - 1].prezime.c_str()) > 0)         minori[i] = osobe[redoslijed[i] - 1].ime;       else if (strcmp(minori[i - 1].c_str(),                       osobe[redoslijed[i] - 1].ime.c_str()) <= 0 &&                strcmp(minori[i - 1].c_str(),                       osobe[redoslijed[i] - 1].prezime.c_str()) <= 0) {         if (strcmp(osobe[redoslijed[i] - 1].ime.c_str(),                    osobe[redoslijed[i] - 1].prezime.c_str()) < 0)           minori[i] = osobe[redoslijed[i] - 1].ime;         else           minori[i] = osobe[redoslijed[i] - 1].prezime;       } else {         cout <<  NO  << endl;         trigger = false;         break;       }     }     if (trigger) cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void CyBerForCe() {     long long n, k, x;     cin >> n >> k >> x;     vector<long long> v, u1, u2;     long long f[1024] = {0}, temp[1024];     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);       f[a]++;     }     for (long long i = 0; i < k; i++) {       for (long long j = 0; j < 1024; j++) temp[j] = 0;       long long c = 0;       for (long long j = 0; j < 1024; j++) {         temp[j] += ((f[j] + c) / 2);         temp[j ^ x] += ((f[j] + 1 - c) / 2);         c = (c + f[j]) & 1;       }       for (long long j = 0; j < 1024; j++) f[j] = temp[j];     }     long long mi = 1026, ma = -1;     for (long long i = 0; i < 1024; i++) {       if (f[i] > 0) {         mi = min(mi, i);         ma = max(ma, i);       }     }     cout << ma <<     << mi <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     CyBerForCe();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 2;   bitset<N> equa[N], value[N];   int ans[N], hehe[N];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, i, j, k, l, num = 0;     cin >> n >> m;     for (i = 0; i < n; i++) {       value[2 * i][2 * i] = 1;       value[2 * i + 1][2 * i + 1] = 1;     }     for (i = 0; i < m; i++) {       string s;       char x;       cin >> s;       if (s ==  mix ) {         cin >> j;         for (k = 0; k < j; k++) {           cin >> l;           l--;           equa[num] ^= value[2 * l];           equa[num + 1] ^= value[2 * l + 1];         }         cin >> x;         if (x ==  R ) {           ans[num + 1] = 1;         }         if (x ==  Y ) {           ans[num] = 1;         }         if (x ==  B ) {           ans[num] = ans[num + 1] = 1;         }         num += 2;       }       if (s ==  RB ) {         cin >> j;         for (k = 0; k < j; k++) {           cin >> l;           l--;           value[2 * l] ^= value[2 * l + 1];         }       }       if (s ==  RY ) {         cin >> j;         for (k = 0; k < j; k++) {           cin >> l;           l--;           swap(value[2 * n], value[2 * l]);           swap(value[2 * l], value[2 * l + 1]);           swap(value[2 * l + 1], value[2 * n]);         }       }       if (s ==  YB ) {         cin >> j;         for (k = 0; k < j; k++) {           cin >> l;           l--;           value[2 * l + 1] ^= value[2 * l];         }       }     }     int now = -1;     for (i = 0; i < 2 * n; i++) {       for (j = now + 1; j < num; j++) {         if (equa[j][i]) {           now++;           swap(equa[j], equa[now]);           swap(ans[j], ans[now]);           for (k = 0; k < num; k++) {             if (equa[k][i] && k != now) {               equa[k] ^= equa[now];               ans[k] ^= ans[now];             }           }           break;         }       }     }     for (i = now + 1; i < num; i++) {       assert(!equa[i].count());       if (ans[i] == 1) {         cout <<  NO ;         return 0;       }     }     for (i = now; i > -1; i--) {       for (j = 2 * n - 1; j > -1; j--) {         if (equa[i][j]) {           if (equa[i].count() == 1) {             equa[i][j] = 0;             hehe[j] = ans[i];           } else {             equa[i][j] = 0;             for (k = j; k > -1; k--) {               if (equa[i][k]) {                 break;               }             }             for (l = 0; l < i; l++) {               if (equa[l][k]) {                 equa[l] ^= equa[i];                 ans[l] ^= ans[i];               }             }           }         }       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) {       if (hehe[2 * i] && hehe[2 * i + 1]) {         cout <<  B ;       }       if (hehe[2 * i] && !hehe[2 * i + 1]) {         cout <<  Y ;       }       if (!hehe[2 * i] && hehe[2 * i + 1]) {         cout <<  R ;       }       if (!hehe[2 * i] && !hehe[2 * i + 1]) {         cout <<  . ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const double EPS = 1e-8;   const int MOD = 998244353;   const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};   struct IOSetup {     IOSetup() {       cin.tie(nullptr);       ios_base::sync_with_stdio(false);       cout << fixed << setprecision(20);       cerr << fixed << setprecision(10);     }   } iosetup;   int mod = MOD;   struct ModInt {     unsigned val;     ModInt() : val(0) {}     ModInt(long long x) : val(x >= 0 ? x % mod : x % mod + mod) {}     ModInt pow(long long exponent) {       ModInt tmp = *this, res = 1;       while (exponent > 0) {         if (exponent & 1) res *= tmp;         tmp *= tmp;         exponent >>= 1;       }       return res;     }     ModInt &operator+=(const ModInt &rhs) {       if ((val += rhs.val) >= mod) val -= mod;       return *this;     }     ModInt &operator-=(const ModInt &rhs) {       if ((val += mod - rhs.val) >= mod) val -= mod;       return *this;     }     ModInt &operator*=(const ModInt &rhs) {       val = static_cast<unsigned long long>(val) * rhs.val % mod;       return *this;     }     ModInt &operator/=(const ModInt &rhs) { return *this *= rhs.inv(); }     bool operator==(const ModInt &rhs) const { return val == rhs.val; }     bool operator!=(const ModInt &rhs) const { return val != rhs.val; }     bool operator<(const ModInt &rhs) const { return val < rhs.val; }     bool operator<=(const ModInt &rhs) const { return val <= rhs.val; }     bool operator>(const ModInt &rhs) const { return val > rhs.val; }     bool operator>=(const ModInt &rhs) const { return val >= rhs.val; }     ModInt &operator++() {       if (++val == mod) val = 0;       return *this;     }     ModInt operator++(int) {       ModInt res = *this;       ++*this;       return res;     }     ModInt &operator--() {       val = (val == 0 ? mod : val) - 1;       return *this;     }     ModInt operator--(int) {       ModInt res = *this;       --*this;       return res;     }     ModInt operator+() const { return *this; }     ModInt operator-() const { return ModInt(val ? mod - val : 0); }     ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }     ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }     ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }     ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }     friend ostream &operator<<(ostream &os, const ModInt &rhs) {       return os << rhs.val;     }     friend istream &operator>>(istream &is, ModInt &rhs) {       long long x;       is >> x;       rhs = ModInt(x);       return is;     }       private:     ModInt inv() const {       unsigned a = val, b = mod;       int x = 1, y = 0;       while (b) {         unsigned tmp = a / b;         swap(a -= tmp * b, b);         swap(x -= tmp * y, y);       }       return ModInt(x);     }   };   ModInt abs(const ModInt &x) { return x; }   struct Combinatorics {     int val;     vector<ModInt> fact, fact_inv, inv;     Combinatorics(int val = 10000000)         : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {       fact[0] = 1;       for (int i = (1); i < (val + 1); ++i) fact[i] = fact[i - 1] * i;       fact_inv[val] = ModInt(1) / fact[val];       for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;       for (int i = (1); i < (val + 1); ++i) inv[i] = fact[i - 1] * fact_inv[i];     }     ModInt nCk(int n, int k) {       if (n < 0 || n < k || k < 0) return ModInt(0);       return fact[n] * fact_inv[k] * fact_inv[n - k];     }     ModInt nPk(int n, int k) {       if (n < 0 || n < k || k < 0) return ModInt(0);       return fact[n] * fact_inv[n - k];     }     ModInt nHk(int n, int k) {       if (n < 0 || k < 0) return ModInt(0);       return (k == 0 ? ModInt(1) : nCk(n + k - 1, k));     }   };   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<vector<ModInt> > dp(k + 1, vector<ModInt>(k + 1, 0));     dp[0][0] = 1;     for (int i = (0); i < (k); ++i)       for (int j = (0); j < (i + 1); ++j) {         dp[i + 1][j] += dp[i][j] * j;         dp[i + 1][j + 1] += dp[i][j] * (n - j);       }     ModInt ans = 0;     for (int j = (0); j < (k + 1); ++j) ans += dp[k][j] / ModInt(m).pow(j);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans, t, p, q, i, j, n, m, k, l, r, br1, br0;   bool b[36][36];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       cin >> n >> m;       ans = 0;       vector<pair<int, int> > v;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           cin >> b[i][j];         }       }       for (i = 1; i <= m; i++) {         p = 1;         q = i;         br1 = br0 = 0;         while (p <= n && q > 0) {           if (b[p][q] == 1)             br1++;           else             br0++;           p++;           q--;         }         v.push_back({br0, br1});       }       for (i = 2; i <= n; i++) {         p = i;         q = m;         br1 = br0 = 0;         while (p <= n && q > 0) {           if (b[p][q] == 1)             br1++;           else             br0++;           p++;           q--;         }         v.push_back({br0, br1});       }       for (i = 0; i < v.size() / 2; i++) {         pair<int, int> pr = v[i];         pair<int, int> pr1 = v[v.size() - i - 1];         ans += min(pr.first + pr1.first, pr.second + pr1.second);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n), t(n);     vector<pair<long long, long long> > vp;     for (int i = 0; i < n; i++) {       cin >> a[i];       vp.push_back({a[i], i});     }     for (int i = 0; i < n; i++) cin >> t[i];     long long ans = 0;     sort(vp.begin(), vp.end());     long long sum = 0;     priority_queue<long long> pq;     int i = 0;     while (i < n) {       int j;       for (j = i; j < n; j++) {         if (vp[i].first == vp[j].first) {           sum += t[vp[j].second];           pq.push(t[vp[j].second]);         } else           break;       }       long long num = vp[i].first;       while (j < n && pq.empty() == 0 && num < vp[j].first) {         sum -= pq.top();         pq.pop();         ans += sum;         num++;       }       i = j;     }     while (pq.empty() == 0) {       sum -= pq.top();       pq.pop();       ans += sum;     }     cout << ans <<   n ;   }   int main(void) {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, int> m;   bool judge(string str) {     int count = 0;     for (int i = 0; i < 3; i++) {       if (str[i] ==  . ) break;       if (str[i] ==  A  && m[ A ] == 0) {         m[ A ] = 1;         count++;       } else if (str[i] ==  B  && m[ B ] == 0) {         m[ B ] = 1;         count++;       } else if (str[i] ==  C  && m[ C ] == 0) {         m[ C ] = 1;         count++;       }       if (count >= 3) return true;     }     return false;   }   int main() {     string str;     cin >> str;     int siz = str.size();     int count = 0;     for (int i = 0; i <= siz - 3; i++) {       m[ A ] = 0;       m[ B ] = 0;       m[ C ] = 0;       string sstr = str.substr(i, 3);       if (judge(sstr)) {         cout <<  Yes  << endl;         return 0;       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   const int MaxN = 1e6 + 255;   const long long INF = 1e18 + 7;   const int Mod = 1e9 + 7;   using namespace std;   long long n, a, f[MaxN], ans;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a);       ++f[a];     }     for (int i = 0; i < MaxN; ++i) {       if (f[i]) {         f[i + 1] += f[i] / 2;         f[i] %= 2;       }     }     for (int i = 0; i < MaxN; ++i)       if (f[i]) ++ans;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200 * 1000 + 5;   pair<long long int, long long int> b[MAXN];   long long int dp[MAXN];   long long int rem[MAXN];   inline pair<long long int, long long int> cst(int x, int y) {     long long int tt = ((b[x].first - rem[y] + b[y].second - 1) / b[y].second);     return make_pair(tt + dp[y], rem[y] + tt * b[y].second - b[x].first);   }   bool cmp(const pair<long long int, long long int>& x,            const pair<long long int, long long int>& y) {     if (x.first != y.first) return x.first < y.first;     return x.second > y.second;   }   inline bool isBet(int i, int j, int k) { return !cmp(cst(i, k), cst(i, j)); }   int main() {     ios::sync_with_stdio(false);     int n;     long long int s;     cin >> n >> s;     for (int i = 0; i < n; i++) cin >> b[i].second >> b[i].first;     b[n].first = s;     sort(b, b + n, cmp);     assert(!b[0].first);     deque<pair<int, int> > cands;     cands.push_back(make_pair(0, 1));     long long int ans = cst(n, 0).first;     long long int lst = b[0].second;     for (int i = 1; i < n; i++) {       if (b[i].second <= lst) continue;       while (cands.size() > 1 && isBet(i, cands[1].first, cands[0].first))         cands.pop_front();       pair<long long int, long long int> tmp = cst(i, cands[0].first);       dp[i] = tmp.first;       rem[i] = tmp.second;       ans = min(ans, cst(n, i).first);       while (cands.size() && isBet(cands.back().second, i, cands.back().first))         cands.pop_back();       if (cands.size()) {         int d = cands.back().second, u = n - 1;         while (d < u - 1) {           int mid = (d + u) / 2;           if (isBet(mid, i, cands.back().first))             u = mid;           else             d = mid;         }         if (isBet(u, i, cands.back().first)) cands.push_back(make_pair(i, u));       }       lst = b[i].second;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[1001], y[1001], a[1001], b[1001];   map<pair<int, int>, int> freq;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];     }     for (int j = 1; j <= n; j++) {       cin >> a[j] >> b[j];     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         freq[{x[i] + a[j], y[i] + b[j]}]++;       }     }     for (auto p : freq) {       if (p.second == n) {         cout << p.first.first <<     << p.first.second << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, m, k, a, b;     long long x[3], y[3];     for (i = 0; i < 3; i++) cin >> x[i] >> y[i];     cout << 3 << endl;     for (i = 0; i < 3; i++)       cout << (x[i] + x[(i + 1) % 3]) - x[(i + 2) % 3] <<                << (y[i] + y[(i + 1) % 3]) - y[(i + 2) % 3] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using pii = pair<int, int>;   constexpr auto MOD = 1000000007LL;   constexpr auto LINF = (1LL << 60);   constexpr auto INF = 2147483647LL;   constexpr auto PI = 3.1415926535897932384626433;   constexpr auto EPS = 1E-9;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> p) {     out << p.first <<     << p.second;     return out;   }   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &x : v) in >> x;     return in;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> v) {     for (int i = 0; i < v.size(); i++)       out << v[i] << (i + 1 == v.size() ?   n  :    );     out.flush();     return out;   }   int n, k, a[2][300010];   int tail[2], nxttail[2];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[0][i];     for (int i = 0; i < n; i++) cin >> a[1][i];     if (k == 1) {       int tail = 3;       for (int i = 0; i < n; i++) {         if (abs(a[0][i] - a[1][i]) > 1) {           cout <<  NO  << endl;           return 0;         }         if (a[0][i] > a[1][i]) {           if ((tail & 2) == 0) {             cout <<  NO  << endl;             return 0;           }           tail = 1;         } else if (a[1][i] > a[0][i]) {           if ((tail & 1) == 0) {             cout <<  NO  << endl;             return 0;           }           tail = 2;         } else           ;       }       cout <<  YES  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       nxttail[0] = nxttail[1] = INF;       for (int t = 0; t < 2; t++) {         if (tail[t] > k) continue;         if (a[t][i] >= a[t ^ 1][i]) {           int groups = 1 + (a[t][i] - (k - tail[t]) + k - 1) / k;           if (a[t ^ 1][i] < groups - 1)             continue;           else if (a[t ^ 1][i] == groups - 1) {             nxttail[t] = min(nxttail[t], (a[t][i] - (k - tail[t]) - 1) % k + 1);           } else if (a[t ^ 1][i] > groups - 1) {             nxttail[t ^ 1] = nxttail[t] = 1;           }         } else {           int groups = (a[t ^ 1][i] + k - 1) / k;           if (a[t][i] < groups - 1)             continue;           else if (a[t][i] == groups - 1) {             nxttail[t ^ 1] = min(nxttail[t ^ 1], (a[t ^ 1][i] - 1) % k + 1);           } else if (a[t][i] > groups - 1) {             nxttail[t] = nxttail[t ^ 1] = 1;           }         }       }       tail[0] = nxttail[0];       tail[1] = nxttail[1];     }     cout << (min(tail[0], tail[1]) <= k ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef int int2;   #define int long long      #define pi pair<int, int>   #define mp make_pair   #define pb push_back   #define eb emplace_back   #define f first   #define s second   #define INF 1e18      string printed(int mask) {       string res;       for (int i = 0; i < 26; i++) {           if (mask & (1 << i)) {               res +=  1 ;           } else {               res +=  0 ;           }       }       return res;   }      int2 main() {       ios::sync_with_stdio(0);       cin.tie(0);          int n, a, b;       cin >> n >> a >> b;       string st;       cin >> st;          vector<int> elts_prev(n);       vector<int> mapping(26);       vector<int> backmap(26);       vector<int> elts(n);       fill(mapping.begin(), mapping.end(), -1);       int curmap = 0;       for (int i = 0; i < n; i++) {           elts_prev[i] = st[i] -  a ;           // cout <<  mapping:   << mapping[elts_prev[i]] <<   n ;           if (mapping[elts_prev[i]] == -1) {               mapping[elts_prev[i]] = curmap;               backmap[curmap] = elts_prev[i];               curmap++;               // cout <<  i:   << i <<   , curmap:   << curmap <<  , elts_prev:   << elts_prev[i] <<   n ;           }       }       for (int i = 0; i < n; i++) {           elts[i] = mapping[elts_prev[i]];       }       vector<int> l(curmap), r(curmap), freq(curmap);       fill(l.begin(), l.end(), INF);       fill(r.begin(), r.end(), -INF);       for (int i = 0; i < n; i++) {           l[elts[i]] = min(l[elts[i]], i);           r[elts[i]] = max(r[elts[i]], i);           freq[elts[i]]++;       }          int maxn = 1 << curmap;          vector<bool> satisfy(maxn);       vector<int> dp(maxn);       fill(dp.begin(), dp.end(), -1);          dp[0] = 1;          // cout <<  curmap:   << curmap <<   n ;       // if (n == 5000 and a == 1 and b == 1 and st[0] ==  o ) {       //     cout <<  curmap:   << curmap <<   n ;       // }       function<int(int)> solve = [&](int i) {           if (~dp[i]) return dp[i];           dp[i] = 0;           int ll = INF, rr = -INF;           int amt = 0;           vector<int> elts;           for (int j = 0; j < curmap; j++) {               if (i & (1 << j)) {                   rr = max(rr, r[j]);                   ll = min(ll, l[j]);                   amt += freq[j];                   elts.pb(j);               }           }              // want amt >= (a / b) * (rr - ll + 1), i.e. amt >= ceil((a / b) * (rr - ll + 1)), i.e. amt >= (a * (rr - ll + 1) + (b - 1)) / b           bool can_change = (amt >= ((a * (rr - ll + 1) + (b - 1)) / b));              // Case 1: change all elements to color j           if (can_change) {               for (int j: elts) {                   dp[i] |= solve(i ^ (1 << j));               }           }              // Case 2: multiple subtrees           int cur_mask = 0;           for (int j: elts) {               cur_mask |= (1 << j);               if (cur_mask == i) break;               dp[i] |= (solve(cur_mask) & solve(i ^ cur_mask));           }           // cout <<  mask:   << printed(i) <<  , ll:   << ll <<  , rr:   << rr <<  , amt:   << amt <<  , dp:   << dp[i] <<   n ;           return dp[i];       };          vector<int> ans;       for (int i = 0; i < curmap; i++) {           if (solve((maxn - 1) ^ (1 << i)) == 1) {               ans.pb(backmap[i]);           }       }       sort(ans.begin(), ans.end());       cout << ans.size() <<    ;       for (int i = 0; i < (int)ans.size(); i++) {           cout << (char)( a  + ans[i]) <<    ;       }       cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int d[1000005];   bool vis[1000005];   vector<pair<int, int> > G[1000005];   void dfs(int u) {     for (pair<int, int> x : G[u])       if (!vis[x.first]) {         vis[x.first] = 1;         dfs(x.second);       }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     long long ans = 0;     int tmp;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       tmp = x;       if (x == y)         ans++;       else         d[x]++, d[y]++;       G[x].push_back(make_pair(i, y));       G[y].push_back(make_pair(i, x));     }     dfs(tmp);     bool test = 1;     for (int i = 0; i < m; i++)       if (!vis[i]) {         test = 0;         break;       }     if (test) {       ans = ans * (m - 1) - ans * (ans - 1) / 2;       for (int i = 1; i <= n; i++) ans += (long long)d[i] * (d[i] - 1) / 2;       printf( %I64d n , ans);     } else       puts( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, t, count;     long long x, N;     scanf( %d n , &t);     while (t--) {       scanf( %lld n , &N);       count = 0;       for (i = 1; i < 10; i++) {         x = i;         while (x <= N) {           count++;           x *= 10;           x += i;         }       }       printf( %d n , count);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 20;   const int Maxmask = (1 << 16);   int out[Maxn][Maxn];   bool making[Maxn][Maxmask];   int n;   int s;   int a[Maxn * Maxn];   int mod;   void input() {     cin >> n;     for (int i = 0; i < n * n; i++) {       cin >> a[i];       s += a[i];     }     s /= n;   }   void place() {     for (int i = 0; i < n * n; i++) out[i / n][i % n] = a[i];   }   bool is_true() {     int t;     for (int i = 0; i < n; i++) {       t = 0;       for (int j = 0; j < n; j++) t += out[i][j];       if (t != s) return false;       t = 0;       for (int j = 0; j < n; j++) t += out[j][i];       if (t != s) return false;     }     t = 0;     for (int i = 0; i < n; i++) t += out[i][i];     if (t != s) return false;     t = 0;     for (int i = 0; i < n; i++) t += out[i][n - i - 1];     if (t != s) return false;     return true;   }   bool found() {     int b[] = {2, 7, 6, 9, 5, 1, 4, 3, 8};     for (int i = 0; i < n * n; i++)       if (a[i] != b[i]) return false;     return true;   }   void calc_3() {     sort(a, a + n * n);     while (1) {       place();       if (is_true()) break;       next_permutation(a, a + (n * n));     }   }   void output() {     cout << s <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << out[i][j] <<    ;       cout <<   n ;     }   }   int main() {     input();     calc_3();     output();     return 0;   }


#include <bits/stdc++.h>   const int maxn = 200001, maxf = 19;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   int n, q, tot, lnk[maxn], dep[maxn], fa[maxn][maxf];   struct Edge {     int v, nxt;   } e[maxn << 1];   template <class T>   void swap(T& x, T& y) {     const T t = x;     x = y;     y = t;   }   template <class T>   const T& min(const T& x, const T& y) {     return x < y ? x : y;   }   void dfs(int u) {     for (int it = lnk[u]; it; it = e[it].nxt) {       int& v = e[it].v;       if (v == fa[u][0]) continue;       dep[v] = dep[u] + 1;       fa[v][0] = u;       for (int i = 1; fa[v][i - 1]; ++i) fa[v][i] = fa[fa[v][i - 1]][i - 1];       dfs(v);     }   }   int deeper(int u, int v) { return dep[u] < dep[v] ? v : u; }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     for (int i = 0, j = dep[v] - dep[u]; j; ++i, j >>= 1)       if (j & 1) v = fa[v][i];     if (u == v) return u;     for (int i = maxf - 1; i >= 0; --i)       if (fa[u][i] != fa[v][i]) {         u = fa[u][i];         v = fa[v][i];       }     return fa[u][0];   }   int dist(int u, int v) { return dep[u] + dep[v] - (dep[lca(u, v)] << 1); }   int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   void exgcd(int a, int b, int& x, int& y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= x * (a / b);   }   long long Case1(int t1, int d1, int t2, int d2) {     int g = gcd(t1, t2), r = (d2 - d1) % t2;     if (r < 0) r += t2;     if (r % g != 0) return INF;     int x, y;     t1 /= g;     t2 /= g;     r /= g;     exgcd(t1, t2, x, y);     if (x < 0) x += t2;     x = (long long)x * r % t2;     return (long long)x * t1 * g + d1;   }   long long AMAC(int m, int d, int l, int r) {     if (l % d == 0) return l / d;     if (l / d != r / d) return l / d + 1;     int g = gcd(m, d);     if (l % g != 0 && l / g == r / g) return -1;     long long res = AMAC(d, m % d, -r % d + d, -l % d + d);     if (res == -1) return -1;     return (res * m + l - 1) / d + 1;   }   long long Case2(int t1, int d1, int t2, int d2, int dd) {     int m = t2, d = t1, l = (d2 - d1 - dd) % t2, r = (d2 - d1 + dd) % t2;     if (l < 0) l += t2;     if (r < 0) r += t2;     if (l & 1) return INF;     if (t2 == dd * 2 || l > r || l == 0) return d1 + r / 2;     if (!(d %= m)) return INF;     long long res = AMAC(m, d, l, r);     if (res == -1) return INF;     return t1 * res + d1 + dd - (t1 * res % t2 - l) / 2;     return t1 * res + d1 + (((-t1 * res + d2 + dd - d1) / 2) % t2 + t2) % t2;   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       e[++tot] = (Edge){v, lnk[u]};       lnk[u] = tot;       e[++tot] = (Edge){u, lnk[v]};       lnk[v] = tot;     }     dfs(1);     scanf( %d , &q);     while (q--) {       int u, v, x, y;       scanf( %d%d%d%d , &u, &v, &x, &y);       int px = deeper(lca(u, x), lca(v, x));       int py = deeper(lca(u, y), lca(v, y));       int pp = deeper(lca(u, v), lca(x, y));       if (dep[px] < dep[pp] && dep[py] < dep[pp]) {         puts( -1 );         continue;       }       if (dep[px] < dep[pp])         px = pp;       else if (dep[py] < dep[pp])         py = pp;       int f1 = dist(u, v) << 1, f2 = dist(x, y) << 1, d = dist(px, py);       int t1 = dist(u, px), t2 = dist(u, py), t3 = dist(x, px), t4 = dist(x, py);       if (t1 <= t2)         t2 = f1 - t2;       else         t1 = f1 - t1;       if (t3 <= t4)         t4 = f2 - t4;       else         t3 = f2 - t3;       long long ans = min(min(Case1(f1, t1, f2, t3), Case2(f1, t1, f2, t4, d)),                           min(Case1(f1, t2, f2, t4), Case2(f1, t2, f2, t3, d)));       if (ans == INF)         puts( -1 );       else         printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int aa(int n) {     int a = 0;     for (int i = 2; i <= n - 1; i++)       if (n % i == 0) {         a = 1;         break;       } else         a = 0;     return a;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       if (aa(i) == 1 && aa(n - i) == 1) {         cout << i <<     << n - i << endl;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void blowback() {     long long i, j, l, k, n, m, x, y, r, ans = 0, sum = 10e17;     string s;     long long a, b, c, d;     cin >> a >> b >> c >> d;     if (a > (b * c)) {       cout <<  -1 n ;       return;     }     k = (2 * a - b * d) / (2 * b * d);     l = k + 1;     k = min(k, c / d);     l = min(l, c / d);     ans = (a * (k + 1)) - ((k * (k + 1)) * b * d) / 2;     k = l;     sum = (a * (k + 1)) - ((k * (k + 1)) * b * d) / 2;     cout << max({ans, sum, a}) <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) {       blowback();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   const long long LLINF = numeric_limits<long long>::max();   const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();   long long f[1010][1010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       x--, y--;       f[y][x]++;     }     long long ans = 0;     for (int i = 0; i < 1000; i++) {       long long cur = 0;       for (int j = 0; j + i < 1000; j++) {         cur += f[j][i + j];       }       ans += (cur - 1) * cur / 2ll;       cur = 0;       if (i > 0) {         for (int j = 0; j + i < 1000; j++) {           cur += f[i + j][j];         }         ans += (cur - 1) * cur / 2ll;       }     }     for (int i = 0; i < 1000; i++) {       long long cur = 0;       for (int j = 0; j <= i; j++) {         cur += f[j][i - j];       }       ans += (cur - 1) * cur / 2ll;       cur = 0;       if (i > 0) {         for (int j = 0; j + i < 1000; j++) {           cur += f[i + j][1000 - j - 1];         }         ans += (cur - 1) * cur / 2ll;       }     }     cout << ans;     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 first, long long second) {     return !second ? first : gcd(second, first % second);   }   long long lcm(long long first, long long second) {     return (first / gcd(first, second)) * second;   }   void PLAY() {     cout << fixed << setprecision(15);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int MAX = 6e5;   long long n, r, k;   long long archers[MAX], dist[MAX];   bool valid(long long val) {     memset(dist, 0, sizeof dist);     long long tmp = 0, cursum = k;     for (int i = 1; i <= n; ++i) {       long long cur = val - archers[i] - tmp;       if (cur < 0) {         tmp += dist[i];         continue;       }       if (cur > cursum) return false;       cursum -= cur;       tmp += cur;       long long idx = min(i + 2 * r, n);       dist[idx] -= cur;       tmp += dist[i];     }     return true;   }   int main() {     PLAY();     cin >> n >> r >> k;     for (int i = 1; i <= n; i++) {       cin >> archers[i];       long long x = max(i - r, 1LL);       long long y = min(i + r, n) + 1;       dist[x] += archers[i];       dist[y] -= archers[i];     }     for (int i = 1; i <= n; i++) archers[i] = archers[i - 1] + dist[i];     long long lo = *min_element(archers + 1, archers + n + 1);     long long hi = lo + k + 1, res = lo;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (valid(mid)) {         res = mid;         lo = mid + 1;       } else         hi = mid - 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MODV = 1e9 + 7;   int b[1001];   int ans[1005];   vector<pair<int, int> > sorted;   vector<pair<int, int> > unsorted;   void make_ans(int n) {     for (auto it : sorted) {       int x = it.first;       int y = it.second;       for (int i = x; i < y; i++) b[i] = 0;     }     ans[1] = 100000;     for (int i = 2; i <= n; i++) ans[i] = ans[i - 1] + b[i - 1];   }   int non_decreasing(int x, int y) {     for (int i = x + 1; i <= y; i++) {       if (ans[i - 1] > ans[i]) return 0;     }     return 1;   }   int check() {     for (auto it : unsorted) {       if (non_decreasing(it.first, it.second)) return 0;     }     return 1;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     while (m--) {       int t, x, y;       scanf( %d %d %d , &t, &x, &y);       if (t)         sorted.push_back({x, y});       else         unsorted.push_back({x, y});     }     sort(sorted.begin(), sorted.end());     memset(b, -1, sizeof(b));     make_ans(n);     if (check()) {       printf( YES n );       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);       printf(  n );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n, rec = 0;       long long int k;       cin >> n >> k;       char str[1000005];       cin >> str;       for (int h = 0; h < n; h++, rec++) {         int pos = h;         for (int i = h; i < n; i++) {           if (str[i] ==  0 ) {             pos = i;             break;           }         }         h = pos;         if (k - pos - rec >= 0) {           char temp = str[pos];           str[pos] = str[rec];           str[rec] = temp;           k -= (pos - rec);         } else if (k > 0) {           while (pos > 0 && str[pos - 1] ==  1  && k > 0) {             char temp = str[pos];             str[pos] = str[pos - 1];             str[pos - 1] = temp;             pos--;             k--;           }         }       }       cout << str << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200005;   set<int> nex[M];   int path[M];   int sh[M];   vector<int> edge[M];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int from, to;       scanf( %d%d , &from, &to);       edge[to].push_back(from);     }     for (int i = 1; i <= n; i++) {       sh[i] = -1;     }     int k;     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       int p;       scanf( %d , &p);       path[i] = p;     }     queue<int> q;     q.push(path[k]);     sh[path[k]] = 0;     int count = 1;     while (!q.empty()) {       int len = q.size();       for (int i = 0; i < len; i++) {         int x = q.front();         q.pop();         for (int v : edge[x]) {           if (sh[v] == -1) {             q.push(v);             sh[v] = count;             nex[v].insert(x);           } else if (sh[v] == count) {             nex[v].insert(x);           }         }       }       count++;     }     int mi = 0, ma = 0;     for (int i = 1; i < k; i++) {       if (nex[path[i]].find(path[i + 1]) == nex[path[i]].end()) {         mi++;         ma++;       } else if (nex[path[i]].size() > 1) {         ma++;       }     }     printf( %d %d n , mi, ma);   }


#include <bits/stdc++.h>   using namespace std;   int bit[210000], n;   void upd(int i) {     while (i <= n) bit[i] += 1, i += i & (-i);   }   void dec(int i) {     while (i <= n) bit[i] -= 1, i += i & (-i);   }   int cal(int i) {     int ret = 0;     while (i > 0) ret += bit[i], i -= i & (-i);     return ret;   }   int solve(int x) {     int l = 1, r = n + 1;     while (l < r) {       int mid = (l + r) >> 1, tx = cal(mid);       if (tx < x)         l = mid + 1;       else         r = mid;     }     return l;   }   int a[210000], b[210000], c[210000], va[210000], vb[210000], vc[210000];   int main() {     while (cin >> n) {       for (int i = 0; i < n; ++i) {         scanf( %d , a + i);         a[i]++;       }       for (int i = 0; i < n; ++i) {         scanf( %d , b + i);         b[i]++;       }       memset(bit, 0, sizeof(bit));       for (int i = n - 1; i >= 0; --i) {         va[i] = cal(a[i]);         upd(a[i]);       }       memset(bit, 0, sizeof(bit));       for (int i = n - 1; i >= 0; --i) {         vb[i] = cal(b[i]);         upd(b[i]);       }       reverse(va, va + n);       reverse(vb, vb + n);       memset(vc, 0, sizeof(vc));       int carry = 0;       for (int i = 1; i < n; ++i) {         vc[i] = (carry + va[i] + vb[i]) % (i + 1);         carry = (carry + va[i] + vb[i]) / (i + 1);       }       reverse(vc, vc + n);       memset(bit, 0, sizeof(bit));       for (int i = 1; i <= n; ++i) {         upd(i);       }       for (int i = 0; i < n; ++i) {         c[i] = solve(vc[i] + 1);         dec(c[i]);       }       for (int i = 0; i < n; ++i) {         if (i) printf(   );         printf( %d , c[i] - 1);       }       puts(  );       return 0;     }   }


#pragma GCC optimize( O2 )      #include<bits/stdc++.h>   #define ll long long   //#define int long long   #define fi first   #define se second   #define mpa make_pair   #define eb emplace_back   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   using namespace std;   mt19937 gen(time(0));      signed main() {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);          int n, q;       cin >> n >> q;       vector<int> a(n);       vector<int> c(n + 1);       int k = 800;       int K = (n + k - 1) / k * 2;       for (int i = 0; i < n; ++i) {           cin >> a[i];           ++c[a[i]];       }       vector<int> d;       for (int i = 0; i <= n; ++i) if (c[i] >= K) d.eb(i);       vector<vector<int>> psum(d.size(), vector<int>(n + 1, 0));       for (int i = 0; i < (int)(d.size()); ++i) {           for (int j = 1; j <= n; ++j) {               psum[i][j] = psum[i][j - 1] + (a[j - 1] == d[i]);           }       }       vector<int> temp(n + 1);       for (int z = 0; z < q; ++z) {           int l, r;           cin >> l >> r;           int mx = 0;           if (r - l + 1 < k) {               for (int j = l - 1; j < r; ++j) {                   ++temp[a[j]];                   mx = max(mx, temp[a[j]]);               }               for (int j = l - 1; j < r; ++j) --temp[a[j]];           } else {               for (int j = 0; j < (int)(d.size()); ++j) {                   int cnt = psum[j][r] - psum[j][l - 1];                   mx = max(mx, cnt);               }           }           int len = (r - l + 1);           int L = 0, R = mx;           while (L != R) {               int M = (L + R) / 2;               if ((len - M + 1) / 2 >= mx - M) {                   R = M;               } else {                   L = M + 1;               }           }           cout << R + 1 <<   n ;       }   }   /*      */


#include <bits/stdc++.h>   const double EPS = 1e-8;   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename A, size_t N, typename T>   void Fill(A (&array)[N], const T &val) {     std::fill((T *)array, (T *)(array + N), val);   }   class Graph {    public:     int vn;     int sumcost = 0;     vector<vector<pair<int, int>>> g;     Graph(int n) {       vn = n;       g.resize(n);     }     virtual void con(int a, int b, int w) = 0;     int getWeight(int f, int t) {       auto itr = lower_bound((g[f]).begin(), (g[f]).end(), make_pair(t, INT_MIN));       if (itr != g[f].end()) return itr->second;       return INT_MIN;     }     int Costsum() { return sumcost; }     void scan(int edcount, bool oindexed, bool w) {       for (int i = (0); (edcount) > i; i++) {         int a, b, c = 1;         scanf( %d %d , &a, &b);         if (w) scanf( %d , &c);         con(a - oindexed, b - oindexed, c);       }     }   };   class BiDGraph : public Graph {    public:     BiDGraph(int n) : Graph(n) {}     void con(int a, int b, int w = 1) {       g[a].push_back({b, w});       g[b].push_back({a, w});       sumcost++;     }   };   struct RSQ {     int n;     vector<int> dat;     RSQ() {}     RSQ(int n_) {       n = 1;       while (n < n_) n *= 2;       dat.resize(2 * n - 1, 0);     }     void add(int k, int a) {       k += n - 1;       dat[k] += a;       while (k > 0) {         k = (k - 1) / 2;         dat[k] = dat[2 * k + 1] + dat[2 * k + 2];       }     }     int query(int a, int b) { return query(a, b, 0, 0, n); }     int query(int a, int b, int k, int l, int r) {       if (r <= a || b <= l) return 0;       if (a <= l && r <= b) return dat[k];       int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);       int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return vl + vr;     }   };   class Heavy_Light_Decomposition {    public:     BiDGraph g, compg;     vector<int> sz, depth, chain, par;     int bn = 0;     vector<int> bvn, inbn;     vector<vector<int>> bv;     Heavy_Light_Decomposition(BiDGraph graph, vector<int> root)         : g(graph),           compg(graph.vn),           sz(graph.vn, 1),           depth(graph.vn),           chain(graph.vn),           par(graph.vn),           bvn(graph.vn, -1),           inbn(graph.vn) {       for (auto itr : root) getsz(itr, itr);       bv.push_back(vector<int>());       for (auto itr : root) {         if (bv[bv.size() - 1].size()) bv.push_back(vector<int>()), bn++;         HLD(itr, -1, itr, bn);       }     }     int getsz(int cur, int p) {       par[cur] = p;       for (auto itr : g.g[cur])         if (p != itr.first)           depth[itr.first] = depth[cur] + 1, sz[cur] += getsz(itr.first, cur);       return sz[cur];     }     void HLD(int cur, int p, int head, int num) {       chain[cur] = head, bvn[cur] = num;       inbn[cur] = bv[num].size(), bv[num].push_back(cur);       pair<int, int> Maxc = {-1, -1};       for (auto itr : g.g[cur])         if (itr.first != p) Maxc = max(Maxc, {sz[itr.first], itr.first});       for (auto itr : g.g[cur])         if (itr.first != p) {           int nb = num;           if (itr.first != Maxc.second) {             bv.push_back(vector<int>());             nb = ++bn;           }           HLD(itr.first, cur, itr.first == Maxc.second ? head : itr.first, nb);         }     }     int lca(int a, int b) {       if (chain[a] == chain[b]) return depth[a] < depth[b] ? a : b;       if (depth[chain[a]] > depth[chain[b]]) return lca(par[chain[a]], b);       return lca(a, par[chain[b]]);     }     void for_each_edge(int a, int b, function<void(int, int)> func) {       if (chain[a] == chain[b])         return func(inbn[a] < inbn[b] ? a : b, inbn[a] < inbn[b] ? b : a);       if (depth[chain[a]] < depth[chain[b]]) swap(a, b);       for_each_edge(a, chain[a], func), for_each_edge(par[chain[a]], b, func);     }   };   struct UnionFind {     vector<int> data;     UnionFind(int size) : data(size, -1) {}     bool unionSet(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       return x != y;     }     bool findSet(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     bool isroot(int x) { return data[x] < 0; }     int size(int x) { return -data[root(x)]; }   };   int main() {     int n;     cin >> n;     BiDGraph g(n);     vector<int> t(n);     vector<int> root;     UnionFind uf(n);     for (int i = (0); (n) > i; i++) {       int p;       scanf( %d %d , &p, &t[i]);       if (p == -1) root.push_back(i);       if (p > 0) uf.unionSet(i, p - 1), g.con(i, p - 1);     }     Heavy_Light_Decomposition hld(g, root);     vector<RSQ> seg;     for (int i = (0); (hld.bv.size()) > i; i++) {       seg.push_back(RSQ(hld.bv[i].size()));       for (int j = (0); (hld.bv[i].size()) > j; j++)         seg[i].add(j, t[hld.bv[i][j]]);     }     int q;     cin >> q;     for (int i = (0); (q) > i; i++) {       int mode, p, c;       scanf( %d %d %d , &mode, &p, &c);       c--, p--;       if (c == p || !uf.findSet(p, c)) {         printf( NO n );         continue;       }       int lca = hld.lca(p, c);       if (mode == 1) {         bool f = 0;         if (lca == p) {           int sum = 0;           hld.for_each_edge(p, c, [&](int u, int v) {             sum += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1);             if (u == lca) {               sum -= t[lca];             } else if (v == lca) {               sum -= t[lca];             }           });           if (sum == 0) f = 1;         }         printf(f ?  YES n  :  NO n );       } else {         if (lca == c) {           printf( NO n );           continue;         }         int sum = 0, sum2 = 0;         hld.for_each_edge(p, lca, [&](int u, int v) {           sum += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1);           if (u == lca) {             sum -= t[lca];           } else if (v == lca) {             sum -= t[lca];           }         });         hld.for_each_edge(c, lca, [&](int u, int v) {           sum2 += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1);           if (u == lca) {             sum2 -= t[lca];           } else if (v == lca) {             sum2 -= t[lca];           }         });         if (sum == 0 && sum2 == (hld.depth[c] - hld.depth[lca]))           printf( YES n );         else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     for (auto v : V) os << v <<    ;     return cout <<   ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> S) {     for (auto s : S) os << s <<    ;     return cout <<   ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os << P.first <<     << P.second;   }   const long long mod = 1;   long long inv(long long i) {     if (i == 1) return 1;     return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b, b % a);   }   int main() {     int r, h;     cin >> r >> h;     int ans = 2 * (h / r);     if ((double)(h - (ans / 2) * r) / (double)r >= sqrt(3) / 2) {       ans += 3;     } else if (2 * (h - (ans / 2) * r) >= r) {       ans += 2;     } else       ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int t;   double pi = acos(-1.0);   double d, h, v, e;   int main() {     scanf( %lf%lf%lf%lf , &d, &h, &v, &e);     double r = d / 2;     if (pi * r * r * e > v)       cout <<  NO  << endl;     else {       double s = (pi * r * r * h) / (v - pi * r * r * e);       cout <<  YES  << endl;       printf( %.12f n , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[5001][5001];   int main() {     memset((ans), 0, sizeof(ans));     int n, m, l, r;     char s[5001];     cin >> n >> m;     for (int i = 1; i <= n; i++) {       l = r = 0;       scanf( %s , s);       for (int j = 0; j < m; j++) {         if (s[j] ==  0 ) {           l = j + 1;         } else           ans[l][j]++;       }     }     int maxi = -1, x, y;     for (int i = 2; i < m; i++) {       for (int j = 1; j <= i; j++) {         ans[j][i] += ans[j - 1][i];       }     }     for (int i = 0; i <= m; i++)       for (int j = i; j < m; j++) maxi = max((j - i + 1) * ans[i][j], maxi);     cout << maxi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, fre[11], fre1[11];   string tot, no, cm =   , cm1 =   ;   bool belongs(int x) {     int tmp = x, len = 0, i;     int tmf[11] = {};     while (tmp > 0) {       tmf[(tmp % 10)]++;       tmp /= 10;       len++;     }     if (n - len == x) {       for (i = 0; i < 10; i++) {         if (fre1[i] < tmf[i]) return false;       }       return true;     }     return false;   }   int main() {     int i, j;     cin >> tot;     cin >> no;     if (tot ==  01  || tot ==  10 ) {       cout <<  0 n ;       return 0;     }     n = tot.length();     m = no.length();     for (i = 0; i < n; i++) {       fre[tot[i] - 48]++;       fre1[tot[i] - 48]++;     }     for (i = 0; i < m; i++) {       fre1[no[i] - 48]--;     }     for (i = 1; i <= n; i++) {       if (belongs(i)) {         int tmp = i;         while (tmp > 0) {           fre1[(tmp % 10)]--;           tmp /= 10;         }         break;       }     }     int tm;     for (i = 0; i < 10; i++) {       tm = fre1[i];       while (tm > 0) {         cm1 += (i + 48);         tm--;       }     }     for (i = 1; i < 10; i++) {       if (fre1[i] > 0) {         cm += (i + 48);         fre1[i]--;         break;       }     }     for (i = 0; i < 10; i++) {       tm = fre1[i];       while (tm > 0) {         cm += (i + 48);         tm--;       }     }     if (no[0] ==  0 ) {       i = 1;       n = cm.size();       while (i < n && cm[i] < no[0]) {         i++;       }       string ans1 =   , ans2 =   ;       for (j = 0; j < min(i, n); j++) ans1 += cm[j];       ans1 += no;       for (j = i; j < n; j++) ans1 += cm[j];       i = 1;       while (i < n && cm[i] <= no[0]) {         i++;       }       for (j = 0; j < min(i, n); j++) ans2 += cm[j];       ans2 += no;       for (j = i; j < n; j++) ans2 += cm[j];       string ans;       if (ans1[0] !=  0 ) {         ans = ans1;       } else if (ans2[0] !=  0 ) {         ans = ans2;       }       if (ans1[0] !=  0 ) {         ans = min(ans, ans1);       }       if (ans2[0] !=  0 ) {         ans = min(ans, ans2);       }       cout << ans << endl;     } else {       string ans3 = no + cm1;       i = 1;       n = cm.size();       while (i < n && cm[i] < no[0]) {         i++;       }       string ans1 =   , ans2 =   ;       for (j = 0; j < min(i, n); j++) ans1 += cm[j];       ans1 += no;       for (j = i; j < n; j++) ans1 += cm[j];       i = 1;       while (i < n && cm[i] <= no[0]) {         i++;       }       for (j = 0; j < min(i, n); j++) ans2 += cm[j];       ans2 += no;       for (j = i; j < n; j++) ans2 += cm[j];       string ans;       if (ans1[0] !=  0 ) {         ans = ans1;       } else if (ans2[0] !=  0 ) {         ans = ans2;       } else if (ans3[0] !=  0 ) {         ans = ans3;       }       if (ans1[0] !=  0 ) {         ans = min(ans, ans1);       }       if (ans2[0] !=  0 ) {         ans = min(ans, ans2);       }       if (ans3[0] !=  0 ) {         ans = min(ans, ans3);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long l;   typedef pair<int, int> pint;   typedef vector<pint> vpint;   typedef vector<int> vint;   typedef vector<vint> vvint;   int n, m, x[123457], cum[1234567];   int ans;   map<int, int> mp;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> x[i];       cum[i] = x[i];     }     sort(cum, cum + n);     for (int i = 0; i < n; ++i) {       if (x[i] != cum[i]) ans++;     }     if (ans < 3)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct ma {     int x, vt;   } a[105];   bool cmp(ma p, ma y) { return p.x < y.x; }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].x;       a[i].vt = i;     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n / 2; i++)       cout << a[i].vt <<     << a[n - i + 1].vt << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long global = 0;   void test_case(long long);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     int yes = 1;     if (yes)       cin >> t;     else       t = 1;     for (long long T = 0; T < t; T++) {       test_case(T);     }     return 0;   }   void test_case(long long T) {     long long n, m;     cin >> n >> m;     vector<string> vec(n);     for (long long(i) = 0; (i) < n; (i)++) {       cin >> vec[i];     }     vector<long long> x = {0, 1, 0, -1}, y = {1, 0, -1, 0};     long long g = 0;     for (long long(i) = 0; (i) < n; (i)++) {       for (long long(j) = 0; (j) < m; (j)++) {         if (vec[i][j] ==  G ) g++;         if (vec[i][j] ==  B ) {           for (long long k = 0; k < 4; k++) {             long long idx = i + x[k];             long long jdx = j + y[k];             if (idx >= 0 && idx < n && jdx >= 0 && jdx < m) {               if (vec[idx][jdx] ==  G ) {                 cout <<  no  << endl;                 return;               } else if (vec[idx][jdx] ==  . ) {                 vec[idx][jdx] =  # ;               }             }           }         }       }     }     queue<pair<long long, long long>> q;     q.push(pair<long long, long long>(n - 1, m - 1));     map<pair<long long, long long>, long long> v;     v[pair<long long, long long>(n - 1, m - 1)]++;     long long vg = 0;     while (!q.empty()) {       auto f = q.front();       q.pop();       if (vec[f.first][f.second] ==  G )         vg++;       else if (vec[f.first][f.second] ==  # )         break;       for (long long k = 0; k < 4; k++) {         long long idx = f.first + x[k];         long long jdx = f.second + y[k];         if (idx >= 0 && idx < n && jdx >= 0 && jdx < m) {           if (vec[idx][jdx] ==  #  || vec[idx][jdx] ==  B ) continue;           if (!v[pair<long long, long long>(idx, jdx)]) {             v[pair<long long, long long>(idx, jdx)]++;             q.push(pair<long long, long long>(idx, jdx));           }         }       }     }     if (vg == g)       cout <<  yes  << endl;     else       cout <<  no  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1004;   int cnk[N][N] = {0};   int mod = 1000000007;   void init_cnk() {     for (int i = 0; i < N; ++i) {       cnk[i][0] = 1;       cnk[i][i] = 1;     }     for (int i = 1; i < N; ++i) {       for (int j = 1; j < N; ++j) {         cnk[i][j] = (cnk[i - 1][j - 1] + cnk[i - 1][j]) % mod;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.precision(10);     cout << fixed;     int k;     cin >> k;     vector<int> c(k, 0);     for (int i = 0; i < k; ++i) cin >> c[i];     init_cnk();     int n = c.size();     vector<int> res(n, 0);     res[0] = 1;     int acc = c[0];     for (int i = 1; i < n; ++i) {       int cur = c[i];       for (int j = 0; j < cur; ++j) {         res[i] += (1LL * cnk[acc - 1 + j][j] * res[i - 1]) % (1LL * mod);         res[i] %= mod;       }       acc += cur;     }     cout << res[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 300 * 1000 + 7;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long long INF = 1000000000000000 + 7;   const double PI = 2 * acos(0.0);   long long a, b, c;   int main(void) {     cin >> a >> b >> c;     if (a > b || a > c)       cout <<  No  << endl;     else       cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int arr[15];     for (int i = 1; i <= 14; i++) cin >> arr[i];     long long int brr[15];     long long int ans = -1;     for (int i = 1; i <= 14; i++) {       if (arr[i] == 0) continue;       for (int j = 1; j <= 14; j++) brr[j] = arr[j];       long long int st = brr[i];       brr[i] = 0;       for (int j = 1; j <= 14; j++) brr[j] += st / 14;       st = st % 14;       int k = i + 1;       if (k > 14) k = 1;       while (st > 0) {         brr[k] += 1;         k = k + 1;         if (k > 14) k = 1;         st--;       }       long long int temp = 0;       for (int j = 1; j <= 14; j++)         if (brr[j] % 2 == 0) temp += brr[j];       ans = (ans > temp) ? ans : temp;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   void search(int cur) {     int tot, c[10];     int ok;     if (cur == n)       tot++;     else       for (int i = 0; i < n; i++) {         ok = 1;         c[cur] = i;       }     for (int j = 0; j < cur; j++) {       if (c[cur] == c[j] || cur - c[cur] == j - c[j] ||           cur + c[cur] == j + c[j]) {         ok = 0;         break;       }     }     if (ok) search(cur + 1);   }   const long long MAXN = 55;   long long num[MAXN];   void xswl() {     scanf( %lld%lld , &n, &k);     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &num[i]);     }     num[0] = 1;     sort(num + 1, num + 1 + n);     long long res = 999999999999999;     for (long long i = 2e5; i >= 0; --i) {       long long cnt = 0;       long long nowr = 0;       int t = lower_bound(num + 1, num + 1 + n, i) - num;       for (int j = t; j <= n; ++j) {         long long now = 0;         long long u = num[j];         while (u > i) {           ++now;           u >>= 1;         }         if (u == i) {           ++cnt;           nowr += now;         }         if (cnt == k) break;       }       if (cnt == k) {         if (res > nowr) {           res = nowr;         }       }     }     printf( %lld , res);   }   int main() { xswl(); }


#include <bits/stdc++.h>   using namespace std;   int maxn = 1000000000;   int main(int argc, char const *argv[]) {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a > b) a = a + b, b = a - b, a = a - b;       int side = max(2 * a, b);       cout << side * side << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int q;     cin >> q;     while (q--) {       int a, b, n, S;       cin >> a >> b >> n >> S;       int x = min(a, S / n);       cout << (S - x * n <= b ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[400000], t[400000], n, m, x[400000];   int main() {     scanf( %d%d , &n, &m);     int s = 0;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &c[i], &t[i]);       s += c[i] * t[i];       x[i] = s;     }     while (m--) {       int a;       scanf( %d , &a);       printf( %d n , lower_bound(x, x + n, a) - x + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1000000000000;   const double eps = (double)1e-8;   const int mod = (int)1000000007;   const int maxn = (int)1e6 + 5;   int n, res, cnt, z[maxn];   pair<pair<int, int>, pair<int, int> > a[maxn];   vector<int> t[maxn];   vector<pair<int, int> > vc[maxn];   map<int, int> m;   int sum(int z, int r) {     res = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) res += t[z][r];     return res;   }   void upd(int z, int i, int delta) {     for (; i < (int)t[z].size(); i = (i | (i + 1))) t[z][i] += delta;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     cnt = 0;     for (int i = (1); i <= (n); i++) {       cin >> a[i].second.first >> a[i].first.first >> a[i].first.second;       a[i].second.second = i;       if (!m.count(a[i].first.second)) m[a[i].first.second] = ++cnt;       vc[m[a[i].first.second]].push_back(make_pair(a[i].first.first, i));     }     for (int i = (1); i <= (cnt); i++) {       sort(vc[i].begin(), vc[i].end());       for (int j = (0); j < (vc[i].size()); j++) {         z[vc[i][j].second] = j;         t[i].push_back(0);       }     }     for (int i = (1); i <= (n); i++) {       if (a[i].second.first == 1) {         upd(m[a[i].first.second], z[i], 1);       } else if (a[i].second.first == 2) {         upd(m[a[i].first.second], z[i], -1);       } else {         cout << sum(m[a[i].first.second], z[i]) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   const int Mod = 1001943197;   const int Base = 34300;   const int MN = 100005, MQ = 100005, S = 500, MS = S + 5;   char s[MN], t[MN];   int N, lt, Lim, per[MN];   int pBase[MN];   int Hs[MN], Ht[MN];   inline int Hmerge(int h1, int h2, int l2) {     return (int)(((long long)h1 * pBase[l2] + h2) % Mod);   }   inline int gHash(int *H, int lb, int rb) {     return (int)(((long long)H[lb - 1] * (Mod - pBase[rb - lb + 1]) + H[rb]) %                  Mod);   }   inline bool smallerThan(int pos1, int pos2) {     if (pos1 == pos2) return false;     bool rev = false;     if (pos1 > pos2) std::swap(pos1, pos2), rev = true;     int lb = 0, rb = lt + (pos2 - pos1), ans = -1;     while (lb <= rb) {       int mid = (lb + rb) / 2;       int hs1 = mid <= lt ? gHash(Ht, 1, mid)                           : Hmerge(Ht[lt], gHash(Hs, pos1 + 1, pos1 + (mid - lt)),                                    mid - lt);       int hs2 = mid <= pos2 - pos1 ? gHash(Hs, pos1 + 1, pos1 + mid)                                    : Hmerge(gHash(Hs, pos1 + 1, pos2),                                             gHash(Ht, 1, mid - (pos2 - pos1)),                                             mid - (pos2 - pos1));       if (hs1 == hs2)         ans = mid, lb = mid + 1;       else         rb = mid - 1;     }     if (ans == lt + (pos2 - pos1)) return rev ? pos2 < pos1 : pos1 < pos2;     char ch1 = ans < lt ? t[ans + 1] : s[pos1 + ans - lt + 1];     char ch2 = ans < pos2 - pos1 ? s[pos1 + ans + 1] : t[ans - (pos2 - pos1) + 1];     if (rev) std::swap(ch1, ch2);     return ch1 < ch2;   }   int iper[MN], id[MN];   int ST[17][MN];   inline int gMin(int x, int y) { return iper[x] < iper[y] ? x : y; }   inline int RMQ(int l, int r) {     int j = 31 - __builtin_clz(r - l + 1);     return gMin(ST[j][l + (1 << j) - 1], ST[j][r]);   }   int Q, ql[MQ], qr[MQ], qk[MQ], qx[MQ], qy[MQ], Ans[MQ];   std::vector<int> V[MS];   int main() {     scanf( %s%s%d , s + 1, t + 1, &Q);     N = (int)(strlen(s + 1)), lt = (int)(strlen(t + 1));     for (int i = 1; i <= N; ++i)       Hs[i] = (int)(((long long)Hs[i - 1] * Base + (s[i] -  a  + 1)) % Mod);     for (int i = 1; i <= lt; ++i)       Ht[i] = (int)(((long long)Ht[i - 1] * Base + (t[i] -  a  + 1)) % Mod);     Lim = std::max(N, lt), pBase[0] = 1;     for (int i = 1; i <= Lim; ++i)       pBase[i] = (int)((long long)pBase[i - 1] * Base % Mod);     for (int i = 1; i <= N + 1; ++i) per[i] = i - 1;     std::sort(per + 1, per + N + 2, smallerThan);     for (int i = 1; i <= N + 1; ++i) iper[per[i]] = i;     for (int i = 0; i <= N; ++i) ST[0][i] = i;     for (int j = 0; 2 << j <= N + 1; ++j)       for (int i = (2 << j) - 1; i <= N; ++i)         ST[j + 1][i] = gMin(ST[j][i - (1 << j)], ST[j][i]);     for (int i = 1; i <= Q; ++i) {       scanf( %d%d%d%d%d , &ql[i], &qr[i], &qk[i], &qx[i], &qy[i]);       if (qk[i] > S) {         int lim = N / qk[i], ans = -1;         for (int j = 0; j <= lim; ++j) {           int l = j * qk[i] + qx[i];           int r = j * qk[i] + qy[i];           l = std::max(l, ql[i]);           r = std::min(r, qr[i]);           if (l <= r) {             int res = RMQ(l, r);             if (ans == -1)               ans = res;             else               ans = gMin(ans, res);           }         }         Ans[i] = ans;       } else         V[qk[i]].push_back(i);     }     for (int k = 1; k <= S; ++k) {       int tot = 0, mxlen = N / k + 1;       for (int j = 0; j < k; ++j)         for (int i = j; i <= N; i += k) ST[0][++tot] = i, id[i] = tot;       for (int j = 0; 2 << j <= mxlen; ++j)         for (int i = 2 << j; i <= tot; ++i)           ST[j + 1][i] = gMin(ST[j][i - (1 << j)], ST[j][i]);       for (int i : V[k]) {         int ans = -1;         for (int j = qx[i]; j <= qy[i]; ++j) {           int l = id[j] + (ql[i] - j + k - 1) / k;           int r = id[j] + (qr[i] - j + k) / k - 1;           if (l <= r) {             int res = RMQ(l, r);             if (ans == -1)               ans = res;             else               ans = gMin(ans, res);           }         }         Ans[i] = ans;       }     }     for (int i = 1; i <= Q; ++i) printf( %d%c , Ans[i],    n [i == Q]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100004];   long long k, mod = 1000000007;   long long qpow(long long n, long long m) {     long long ans = 1;     for (; m; m >>= 1) {       if (m & 1) ans = ans * n % mod;       n = n * n % mod;     }     return ans;   }   int main() {     scanf( %s %lld , s, &k);     int l = strlen(s);     long long p = 0, q = 0;     for (int i = 0; i < l; i++)       if (s[i] ==  0  || s[i] ==  5 ) p = (p + qpow(2, i)) % mod;     q = (qpow(2, k * l) - 1) * qpow(qpow(2, l) - 1, mod - 2) % mod;     printf( %lld n , p * q % mod);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v(6);     for (int i = 0; i < 6; ++i) cin >> v[i];     int n;     cin >> n;     vector<pair<int, int>> a;     int num;     for (int i = 0; i < n; ++i) {       cin >> num;       for (int j = 0; j < 6; ++j) {         a.push_back({num - v[j], i});       }     }     sort(a.begin(), a.end());     int ans = 1e9 + 7;     map<int, int> mp;     int t = 0;     int l = 0;     for (int i = 0; i < a.size(); ++i) {       int k = a[i].second;       if (mp[k] == 0) {         t++;       }       mp[k]++;       while (mp[a[l].second] > 1) {         mp[a[l].second]--;         l++;       }       if (t == n) {         ans = min(ans, a[i].first - a[l].first);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     char c;     unsigned int mask;     int u;     vector<unsigned int> ip;     set<unsigned int> net;     cin >> n >> k;     scanf( %c , &c);     unsigned int x, x1;     for (int i = 0; i < n; i++) {       c = 0;       x = 0;       x1 = 0;       while (c !=   n ) {         scanf( %c , &c);         if ((c !=  . ) && (c !=   n )) {           x *= 10;           x += (c -  0 );         } else {           x1 = x1 << 8;           x1 += x;           x = 0;         }       }       ip.push_back(x1);     }     for (int len = 1; len < 32; len++) {       mask = 1;       for (int y = 1; y < len; y++) {         mask = mask << 1;         mask++;       }       mask = mask << (32 - len);       unsigned int v = 0;       for (int i = 0; i < n; i++) {         v = ip[i];         v &= mask;         net.insert(v);       }       u = net.size();       if (u == k) {         unsigned int xx[4];         xx[3] = mask % 256;         mask /= 256;         xx[2] = mask % 256;         mask /= 256;         xx[1] = mask % 256;         mask /= 256;         xx[0] = mask;         cout << xx[0] <<  .  << xx[1] <<  .  << xx[2] <<  .  << xx[3] << endl;         return 0;       }       if (u > k) {         cout <<  -1  << endl;         return 0;       }       net.clear();     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int t;   long long sufa[100010];   long long a[100010];   pair<long long, long long> ab[100010];   long long n, m;   int main() {     cin >> t;     while (t--) {       scanf( %lld %lld , &n, &m);       for (long long i = 0; i < m; i++) {         scanf( %lld %lld , &ab[i].first, &ab[i].second);       }       sort(ab, ab + m);       sufa[m] = 0;       sufa[m - 1] = a[m - 1] = ab[m - 1].first;       for (int i = m - 1 - 1; i >= 0; i--) {         a[i] = ab[i].first;         sufa[i] = sufa[i + 1] + a[i];       }       long long ans = 0;       if (n <= m) {         ans = sufa[m - n];       }       for (long long i = 0; i < m; i++) {         long long idx = lower_bound(a, a + m, ab[i].second) - a;         idx = max(idx, m - n);         long long costn = m - idx;         long long costa = 0;         if (idx > i && costn < n) {           costa = ab[i].first;           costn += 1;         }         ans = max(ans, sufa[idx] + costa + (n - costn) * ab[i].second);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   long long mpow(long long a, long long n, long long mod) {     long long ret = 1;     long long b = a;     while (n) {       if (n & 1) ret = (ret * b) % mod;       b = (b * b) % mod;       n >>= 1;     }     return (long long)ret;   }   using namespace std;   int a[100000 + 5];   map<int, int> ind;   long long cnt[1500];   long long dp[1400][1400];   long long fact[100000 + 5];   long long inv[100000 + 5];   void computefact() {     fact[0] = 1;     inv[0] = 1;     long long i, j;     for (j = 1; j < 100000 + 5; j++) {       fact[j] = (fact[j - 1] * j) % 1000000007;       inv[j] = mpow(fact[j], 1000000007 - 2, 1000000007);     }   }   long long ncr(long long n, long long r) {     long long den = (inv[r] * inv[n - r]) % 1000000007;     long long num = (fact[n] * den) % 1000000007;     return num;   }   bool chk(int x) {     while (x != 0) {       int p = x % 10;       if (!(p == 4 || p == 7)) {         return 0;       }       x /= 10;     }     return 1;   }   int main() {     int i, j;     vector<int> luck;     long long n, len;     cin >> n >> len;     long long unl = 0;     int c = 1;     computefact();     for (j = 0; j < n; j++) {       cin >> a[j];       if (chk(a[j])) {         if (!ind[a[j]]) {           luck.push_back(a[j]);           ind[a[j]] = c;           cnt[c]++;           c++;         } else {           cnt[ind[a[j]]]++;         }       } else         unl++;     }     dp[0][0] = 1;     int sz = luck.size();     for (i = 1; i <= sz; i++) {       for (j = 0; j <= sz; j++) {         dp[i][j] = (dp[i - 1][j] + (dp[i - 1][j - 1] * cnt[i]) % 1000000007) %                    1000000007;       }     }     long long ans = 0;     for (long long k = 0; k <= min(len, unl); k++) {       long long q = len - k;       if (q > sz) continue;       ans = (ans + (ncr(unl, k) * dp[sz][q]) % 1000000007) % 1000000007;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   using namespace std;   mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());   const int N = 1e5 + 3;   int ok[N], tsz[N], dep[N];   vector<int> adj[N], g[N];   multiset<int> mset[N];   int vis[N];   bool flag;   void dfs2(int u) {     vis[u] = 1;     for (auto v : adj[u]) {       if (vis[v] == 2) flag = false;       if (!vis[v]) dfs2(v);     }     vis[u] = 2;   }   void dfs(int u, int keep) {     vis[u] = 1;     int bigchild = -1, high = -1;     for (auto v : adj[u]) {       if (!vis[v] and tsz[v] > high) {         high = tsz[v];         bigchild = v;       }     }     multiset<int> backEdge;     for (auto v : adj[u]) {       if (!vis[v] and v != bigchild)         dfs(v, 0);       else if (vis[v] == 1)         backEdge.insert(v);     }     if (bigchild != -1) {       dfs(bigchild, 1);       swap(mset[u], mset[bigchild]);     }     for (auto x : backEdge) mset[u].insert(x);     for (auto v : adj[u]) {       if (v != bigchild) {         for (auto x : mset[v]) {           mset[u].insert(x);         }       }     }     mset[u].erase(u);     if (int(mset[u].size()) == 1) {       g[*mset[u].begin()].push_back(u);     }     vis[u] = 2;   }   bool interesting(int u) {     flag = true;     dfs2(u);     return flag;   }   void dfs4(int u) {     vis[u] = 1;     ok[u] = 1;     for (int v : g[u]) {       if (!vis[v]) dfs4(v);     }     vis[u] = 2;   }   int dfs3(int u, int d = 0) {     vis[u] = 1;     dep[u] = d;     for (auto v : adj[u]) {       if (!vis[v]) tsz[u] += dfs3(v, d + 1);     }     vis[u] = 2;     return tsz[u] + 1;   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i)       adj[i].clear(), tsz[i] = 0, mset[i].clear(), ok[i] = 0, g[i].clear();     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);     }     int root = -1;     for (int t = 0; t < 100; ++t) {       int u = rng() % n + 1;       if (interesting(u)) {         root = u;       }       for (int i = 1; i <= n; ++i) vis[i] = 0;       if (root != -1) break;     }     if (root == -1) {       cout << -1 << endl;       return;     }     dfs3(root);     for (int i = 1; i <= n; ++i) vis[i] = 0;     dfs(root, 0);     for (int i = 1; i <= n; ++i) vis[i] = 0;     dfs4(root);     vector<int> ans;     for (int i = 1; i <= n; ++i)       if (ok[i]) ans.push_back(i);     if (5 * int(ans.size()) < n)       cout << -1 << endl;     else {       for (auto x : ans) cout << x <<    ;       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int vp, vd, t, f, c;     cin >> vp >> vd >> t >> f >> c;     int vs = vd - vp;     if (vp > vd) {       cout << 0;       return 0;     }     if (vp == vd) {       cout << 0;       return 0;     }     double d = vp * t;     d += d / (1.0 * vs) * vp;     cerr << d << endl;     if (int(d) >= c) {       cout << 0;       return 0;     }     int ans = 1;     while ((int)d < c) {       d += (d / vd + f) * vp;       d += (d / vs) * vp;       if (d - c > -1e-12) {         cout << ans;         return 0;       }       ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, k1, k2, m;   int main() {     cin >> n >> k;     m = n;     while (m % 2 == 0) {       k1++;       m /= 2;     }     while (m % 5 == 0) {       k2++;       m /= 5;     }     for (int i = 1; i <= max(0ll, k - k1); ++i) {       n *= 2;     }     for (int i = 1; i <= max(0ll, k - k2); ++i) {       n *= 5;     }     cout << n;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, maxi, mini;     cin >> n;     int z[n], o = 0;     for (i = 0; i < n; i++) {       cin >> z[i];       if (i == 0) {         maxi = z[i];         mini = z[i];       }       if (i > 0) {         if (z[i] > maxi) {           o++;           maxi = z[i];         }         if (z[i] < mini) {           o++;           mini = z[i];         }       }     }     cout << o;   }