#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000000;   int xx[1111111], yy[1111111];   int pos[1111111], n, m, op[1111111], np[1111111], ff;   int owner[3333333], first[3333333];   int ans[1111111];   bool used[1111111];   void imp() {     puts( -1 );     exit(0);   }   inline int sum(int x) {     int r = 0;     while (x >= 0) {       r += first[x];       x = (x & (x + 1)) - 1;     }     return r;   }   inline void add(int x, int d) {     while (x <= maxn) {       first[x] += d;       x = (x | (x + 1));     }   }   inline int getFirst(int x) {     int l = -1, r = maxn;     while (r - l > 1) {       int mid = ((l + r) >> 1);       if (sum(mid) >= x) {         r = mid;       } else {         l = mid;       }     }     return r;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &xx[i], &yy[i]);       --xx[i];     }     memset(owner, -1, sizeof(owner));     memset(pos, -1, sizeof(pos));     int ff = m;     for (int i = 1; i <= n; ++i) {       add(ff + i, 1);     }     for (int i = 0; i < m; ++i) {       int &oldPlace = op[i];       int &newPlace = np[i];       int &x = xx[i];       int &y = yy[i];       oldPlace = getFirst(y);       if ((pos[x] != -1 && oldPlace != pos[x]) ||           (owner[oldPlace] != -1 && owner[oldPlace] != x)) {         imp();       }       newPlace = ff--;       owner[oldPlace] = -1;       add(oldPlace, -1);       add(newPlace, 1);       pos[x] = newPlace;       owner[newPlace] = x;     }     for (int i = m - 1; i >= 0; --i) {       int &oldPlace = op[i];       int &newPlace = np[i];       int &x = xx[i];       int &y = yy[i];       pos[x] = oldPlace;       owner[oldPlace] = x;       add(oldPlace, 1);       owner[newPlace] = -1;       add(newPlace, -1);     }     memset(ans, -1, sizeof(ans));     for (int i = 0; i < n; ++i)       if (pos[i] != -1) {         int p = sum(pos[i]);         ans[p - 1] = i;         used[i] = true;       }     int fx = 0;     for (int i = 0; i < n; ++i)       if (ans[i] == -1) {         while (used[fx]) {           ++fx;         }         ans[i] = fx;         used[fx] = true;       }     for (int i = 0; i < n; ++i) {       if (i > 0) {         putchar(   );       }       printf( %d , ans[i] + 1);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[100001];   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a);       a = (a * a);       b >>= 1;     }     return res;   }   long long modpow(long long a, long long b, long long x) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % x;       a = (a * a) % x;       b >>= 1;     }     return res;   }   void sieve() {     spf[1] = 1;     for (long long i = 2; i < 100001; i++) spf[i] = i;     for (long long i = 4; i < 100001; i += 2) spf[i] = 2;     for (long long i = 3; i * i < 100001; i++)       if (spf[i] == i)         for (long long j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;   }   vector<long long> getFactorization(long long x) {     vector<long long> ret;     while (x != 1) {       ret.push_back(spf[x]);       x = x / spf[x];     }     return ret;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> adj[n + 1];     for (int i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     vector<pair<long long, long long>> topic(n);     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       topic[i] = {a, i + 1};     }     sort(topic.begin(), topic.end());     vector<long long> res;     vector<set<long long>> around(n + 1);     for (int i = 0; i < topic.size(); i++) {       long long u = topic[i].second;       res.push_back(u);       if (around[u].find(topic[i].first) != around[u].end() ||           around[u].size() != topic[i].first - 1) {         cout << -1 <<   n ;         return;       }       for (auto j : adj[u]) {         around[j].insert(topic[i].first);       }     }     for (auto i : res) cout << i <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<long long> v[N];   long long vis[N];   long long col[N];   set<long long> che;   void dfs(long long x) {     vis[x] = 1;     che.insert(x);     for (auto it : v[x]) {       if (!vis[it]) {         dfs(it);       }     }   }   void solve() {     long long n;     cin >> n;     long long i, x, y;     vector<pair<long long, long long> > e, spe;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       x--, y--;       e.push_back(make_pair(x, y));     }     for (i = 0; i < n; i++) {       cin >> col[i];     }     for (auto it : e) {       if (col[it.first] != col[it.second]) {         spe.push_back(make_pair(it.first, it.second));       }     }     long long m = spe.size();     long long f = 0, ind = 0;     long long cnt[n];     memset(cnt, 0, sizeof(cnt));     if (m == 0) {       cout <<  YES n1 ;       return;     }     for (auto it : spe) {       cnt[it.first]++;       cnt[it.second]++;     }     for (i = 0; i < n; i++) {       if (cnt[i] == m) {         cout <<  YES n  << i + 1;         return;       }     }     cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     int zD = 1;     int zABC = 0;     for (int i = 1; i <= n; i++) {       int nzD = zABC * 3LL % 1000000007;       int nzABC = (zABC * 2LL + zD) % 1000000007;       zD = nzD;       zABC = nzABC;     }     cout << zD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       auto chk = [&](int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; };       vector<int> nxt(n * m, -1), deg(n * m), dp(n * m), dp2(n * m);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           char c;           cin >> c;           int x = i, y = j;           if (c ==  L ) --y;           if (c ==  R ) ++y;           if (c ==  U ) --x;           if (c ==  D ) ++x;           if (chk(x, y)) {             nxt[i * m + j] = x * m + y;             deg[x * m + y] += 1;           }         }       }       for (int i = 0; i < n * m; ++i) dp2[i] = i;       queue<int> q;       for (int i = 0; i < n * m; ++i)         if (deg[i] == 0) q.push(i);       while (!q.empty()) {         int u = q.front();         q.pop();         if (nxt[u] != -1) {           int v = nxt[u];           if (dp[v] < dp[u] + 1) {             dp[v] = dp[u] + 1;             dp2[v] = dp2[u];           }           if (--deg[v] == 0) q.push(v);         }       }       int ans = 0;       for (int i = 0; i < n * m; ++i) {         if (deg[i] == 0) continue;         int p = nxt[i];         vector<int> loop;         while (p != i) {           loop.push_back(p);           p = nxt[p];         }         loop.push_back(i);         for (int j : loop) dp[j] += loop.size() - 1, deg[j] = 0;       }       int mx = -1, x = -1, y = -1;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           if (dp[i * m + j] > mx) {             mx = dp[i * m + j];             x = dp2[i * m + j] / m;             y = dp2[i * m + j] % m;           }         }       }       cout << x + 1 <<     << y + 1 <<     << mx + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void addmod(int &a, long long b) {     a = (a + b);     if (a >= 1000000007) a -= 1000000007;   }   void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }   int gi() {     int a;     scanf( %d , &a);     return a;   }   long long gll() {     long long a;     scanf( %lld , &a);     return a;   }   class rangesum {     vector<long long> s;       public:     rangesum(const vector<int> &inp, const int &n) {       s.resize(n + 1);       for (int i = 0; i < n; i++) s[i + 1] = s[i] + inp[i];     }     long long get(int x, int y) { return s[y + 1] - s[x]; }   };   int main() {     int n = gi(), l, u;     vector<int> a(n);     for (auto i = 0; i < n; i++) {       a[i] = gi();     }     rangesum rs(a, n);     set<int> rm;     multiset<long long, greater<long long>> v;     rm.insert(-1);     rm.insert(n);     v.insert(rs.get(0, n - 1));     for (int i = 0; i < n; i++) {       int ix = gi() - 1;       auto it = rm.upper_bound(ix);       u = (*it) - 1;       it--;       l = (*it) + 1;       auto mit = v.find(rs.get(l, u));       assert(mit != v.end());       v.erase(mit);       if (ix > l) v.insert(rs.get(l, ix - 1));       if (ix < u) v.insert(rs.get(ix + 1, u));       rm.insert(ix);       printf( %lld n , (v.size() ? *v.begin() : 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long BIG = 1000000000000000000LL;   void solve();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }   long long nbBoxes;   long long reqSom = 0;   bool cycor[1 << 15];   pair<long long, pair<long long, long long> > cymem[1 << 15];   long long dpGo[1 << 15];   long long origSom[15];   vector<long long> yolo[15];   map<long long, long long> loc;   map<long long, long long> ds;   vector<long long> maskOk;   pair<long long, long long> finRes[15];   long long osef[15];   long long getMap(long long x) {     auto it = loc.find(x);     if (it == loc.end())       return -1;     else       return it->second;   }   void tester(long long dep, long long valEnvoi, long long suiv,               bool act = false) {     if (dep == suiv) {       if (origSom[dep] == reqSom) {         cycor[1LL << dep] = true;         cymem[1LL << dep] = {dep, {valEnvoi, suiv}};         if (act) finRes[dep] = {dep, osef[dep]};       }       return;     }     long long gauche = dep;     long long cg = reqSom - (origSom[dep] - valEnvoi);     long long mask = (1LL << gauche);     if (act) finRes[dep] = {suiv, valEnvoi};     while (true) {       long long prev = gauche;       gauche = getMap(cg);       if (gauche != -1 && act) finRes[gauche] = {prev, cg};       if (gauche == -1 || gauche == dep) break;       if (mask & (1LL << gauche)) break;       cg = reqSom - (origSom[gauche] - cg);       mask |= (1LL << gauche);     }     if (gauche == dep && cg == valEnvoi) {       cycor[mask] = true;       cymem[mask] = {dep, {valEnvoi, suiv}};     }   }   void solve() {     cin >> nbBoxes;     for (long long i = (0); i < (nbBoxes); ++i) {       long long ni;       cin >> ni;       for (long long i00 = (0); i00 < (ni); ++i00) {         long long x;         cin >> x;         yolo[i].push_back(x);         reqSom += x;         origSom[i] += x;         loc[x] = i;         osef[i] = x;       }     }     if (reqSom % nbBoxes != 0) {       cout <<  No n ;       return;     }     reqSom /= nbBoxes;     for (long long i = (0); i < (nbBoxes); ++i) {       for (long long x : yolo[i]) {         tester(i, x, -1);         tester(i, x, i);       }     }     for (long long i = (0); i < ((1 << 15)); ++i) {       dpGo[i] = -1;     }     dpGo[0] = 0;     for (long long mask = 1; mask < (1 << 15); ++mask) {       for (long long s = mask; s > 0; s = ((s - 1) & mask)) {         if (cycor[s] && dpGo[mask ^ s] != -1) {           dpGo[mask] = s;           break;         }       }     }     long long cur = (1LL << nbBoxes) - 1;     while (dpGo[cur] != 0) {       if (dpGo[cur] == -1) {         cout <<  No n ;         return;       }       long long ret = dpGo[cur];       long long dep = cymem[ret].first, valEnv = cymem[ret].second.first,                 suiv = cymem[ret].second.second;       tester(dep, valEnv, suiv, true);       cur ^= ret;     }     cout <<  Yes n ;     for (long long i = (0); i < (nbBoxes); ++i)       cout << finRes[i].second <<     << finRes[i].first + 1 <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using LD = long double;   using ULL = unsigned long long;   template <class T1, class T2>   using P = pair<T1, T2>;   using PII = P<int, int>;   using PLL = P<LL, LL>;   using PLD = P<LD, LD>;   template <class T>   using V = vector<T>;   using VI = V<int>;   using VLL = V<LL>;   using VLD = V<LD>;   using VB = V<bool>;   using VS = V<string>;   template <class T, class Comp = greater<T>>   using PQ = priority_queue<T, V<T>, Comp>;   template <class T>   int sz(const T& x) {     return (int)size(x);   }   template <class T>   bool amin(T& a, const T& b) {     if (b < a) {       a = b;       return true;     }     return false;   }   template <class T>   bool amax(T& a, const T& b) {     if (b > a) {       a = b;       return true;     }     return false;   }   const size_t rseed =       std::chrono::high_resolution_clock::now().time_since_epoch().count();   mt19937 rnd(rseed);   int randint(int lo, int hi) {     return uniform_int_distribution<int>{lo, hi}(rnd);   }   int main() {     int T;     scanf( %d , &T);     for (int t = (1); t <= (T); t++) {       int n;       scanf( %d , &n);       string s(n + 1,    );       scanf( %s , &s[0]);       string a(n,    ), b(n,    );       bool f = false;       for (int i = (0); i <= (n - 1); i++) {         if (f) {           a[i] =  0 ;           b[i] = s[i];         } else {           if (s[i] ==  1 ) {             f = true;             a[i] =  1 ;             b[i] =  0 ;           } else if (s[i] ==  2 )             a[i] = b[i] =  1 ;           else             a[i] = b[i] =  0 ;         }       }       printf( %s n%s n , a.c_str(), b.c_str());     }   }


#include <bits/stdc++.h>   using namespace std;   int seq[100];   int main() {     int n;     int acc, t, pen;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , seq + i);     }     sort(seq, seq + n);     acc = 10;     t = 0;     pen = 0;     for (int i = 0; i < n; i++) {       acc += seq[i];       if (acc > 720) {         break;       }       t++;       if (acc > 360) {         pen += ((acc - 360) < 0 ? -(acc - 360) : (acc - 360));       }     }     printf( %d %d n , t, pen);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e5 + 20, sqr = 150, mod = 1e9 + 7;   long long len, n, dp[maxx][sqr][2], q, pw25[maxx], pw26[maxx], pwmod[maxx],       fac[maxx], tmp[maxx];   string s;   long long pw(long long a, long long b) {     if (!b) return 1ll;     long long x = pw(a, b / 2);     x = (x * x) % mod;     if (b % 2) x = (x * a) % mod;     return x;   }   long long sel(long long a, long long b) {     long long x = 1ll;     x = (x * fac[a]) % mod;     x = (x * pwmod[b]) % mod;     x = (x * pwmod[a - b]) % mod;     return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pw25[0] = pw26[0] = 1;     for (long long i = 1; i < maxx; i++)       pw25[i] = (pw25[i - 1] * 25) % mod, pw26[i] = (pw26[i - 1] * 26) % mod;     fac[0] = 1;     for (long long i = 1; i < maxx; i++) fac[i] = (fac[i - 1] * i) % mod;     for (long long i = 0; i < maxx; i++) pwmod[i] = pw(fac[i], mod - 2);     for (long long j = 0; j < sqr; j++) {       dp[j][j][1] = dp[j][j][0] = 1;       for (long long i = j + 1; i < maxx; i++) {         dp[i][j][0] = (((dp[i - 1][j][0] * 26) % mod) +                        (j >= 1 ? dp[i - 1][j - 1][1] : 0)) %                       mod;         dp[i][j][1] = (((dp[i - 1][j][1] * 25) % mod) +                        (j >= 1 ? dp[i - 1][j - 1][1] : 0)) %                       mod;       }     }     long long c = 0;     cin >> n >> s;     len = s.length();     if (len >= sqr) {       fill(tmp, tmp + maxx, 0);       tmp[len - 1] = 1;       for (long long j = len; j < maxx; j++)         tmp[j] = (((tmp[j - 1] * 26ll) % mod) +                   (((long long)sel(j, len - 1) * pw25[j + 1 - len]) % mod)) %                  mod;     }     for (long long i = 0; i < n; i++) {       long long type;       cin >> type;       if (type == 1) {         cin >> s, len = s.length();         if (len >= sqr) {           fill(tmp, tmp + maxx, 0);           tmp[len - 1] = 1;           for (long long j = len; j < maxx; j++)             tmp[j] = (((tmp[j - 1] * 26ll) % mod) +                       (((long long)sel(j, len - 1) * pw25[j + 1 - len]) % mod)) %                      mod;         }       } else {         c++;         cin >> q;         if (len < sqr) {           if (len > q)             cout << 0 <<   n ;           else             cout << dp[q][len][0] <<   n ;           continue;         }         long long ans = 0ll;         cout << tmp[q - 1] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<array<int, 2>> tree(1);   int terminal[110];   unsigned long long inf = (1ull << 63) - 1;   int s;   struct Mat {     vector<unsigned long long> data;     Mat() { data.assign(s * s, inf); }   };   Mat operator*(const Mat& a, const Mat& b) {     Mat r;     for (int i = 0; i < s; i++) {       for (int k = 0; k < s; k++) {         for (int j = 0; j < s; j++) {           r.data[i * s + j] =               min(r.data[i * s + j], a.data[i * s + k] + b.data[k * s + j]);         }       }     }     return r;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int g, n, m;     cin >> g >> n >> m;     vector<pair<int, vector<int>>> mut;     vector<vector<vector<int>>> node(g);     for (int i = 0; i < n; i++) {       int a, k;       cin >> a >> k;       node[a].push_back(vector<int>(k));       mut.emplace_back(a, vector<int>());       for (int& v : node[a].back()) {         cin >> v;         mut.back().second.push_back(v);       }     }     for (int i = 0; i < m; i++) {       int k;       cin >> k;       int p = 0;       while (k--) {         int c;         cin >> c;         if (!tree[p][c]) {           tree[p][c] = tree.size();           tree.push_back({0, 0});         }         p = tree[p][c];       }       terminal[p] = 1;     }     {       vector<int> link(tree.size());       queue<int> q;       q.push(0);       while (q.size()) {         int p = q.front();         q.pop();         int par = link[p];         terminal[p] |= terminal[par];         for (int c : {0, 1}) {           if (!tree[p][c]) {             tree[p][c] = tree[par][c];           } else {             link[tree[p][c]] = p ? tree[par][c] : 0;             q.push(tree[p][c]);           }         }       }     }     s = tree.size();     for (int p = 0; p < s; p++)       if (terminal[p]) tree[p][0] = tree[p][1] = p;     vector<Mat> mat(g);     for (int c : {0, 1}) {       for (int i = 0; i < s; i++) {         mat[c].data[i * s + tree[i][c]] = 1;       }     }     vector<int> changed(g, 1);     while (1) {       int found = 0;       vector<int> nchanged(g);       for (auto& [a, v] : mut) {         int need = 0;         for (int b : v)           if (changed[b]) need = 1;         if (!need) continue;         Mat prod = mat[v[0]];         for (int i = 1; i < (int)v.size(); i++) {           prod = prod * mat[v[i]];         }         for (int i = 0; i < s * s; i++) {           if (prod.data[i] < mat[a].data[i]) {             mat[a].data[i] = prod.data[i];             nchanged[a] = 1;             found = 1;           }         }       }       changed = nchanged;       if (!found) break;     }     for (int a = 2; a < g; a++) {       unsigned long long mi = inf;       for (int i = 0; i < s; i++) {         if (!terminal[i]) mi = min(mi, mat[a].data[i]);       }       if (mi < inf)         cout <<  NO   << mi << endl;       else         cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize  -O3    using namespace std;   const int MAXN = 310000;   int n;   int a[MAXN];   vector<int> pr;   int bb[MAXN];   int go[MAXN];   int cc[MAXN];   int ans[MAXN];   vector<int> fc[MAXN];   int gcd(int a, int b) {     while (b) {       int q = a % b;       a = b;       b = q;     }     return a;   }   int dp[1 << 7];   int gg;   int gog[1 << 7];   void run(int x, int msk, int ml, int k) {     if (x == k) {       dp[msk] = cc[ml];       gog[msk] = ml;       return;     }     run(x + 1, msk, ml, k);     run(x + 1, msk + (1 << x), ml * fc[gg][x], k);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (int i = 0; i < MAXN; ++i) bb[i] = i;     for (int i = 2; i < MAXN; ++i) {       if (bb[i] == i) pr.push_back(i);       for (int j : pr) {         if (j * i >= MAXN || bb[i] < j) break;         bb[j * i] = j;       }     }     for (int i = 1; i < MAXN; ++i) {       int cur = 1;       int x = i;       while (x != 1) {         int d = bb[x];         while (x % d == 0) x /= d;         cur *= d;         fc[i].push_back(d);       }       go[i] = cur;     }     cin >> n;     int now = 0;     fill(ans, ans + MAXN, 1000);     for (int i = 0; i < n; ++i) {       cin >> a[i];       now = gcd(now, a[i]);       a[i] = go[a[i]];       ++cc[a[i]];       ans[a[i]] = 1;     }     if (now != 1) {       cout << -1 <<   n ;       return 0;     }     for (int i = 1; i < MAXN; ++i) {       for (int j = 2 * i; j < MAXN; j += i) cc[i] += cc[j];     }     for (int i = MAXN - 1; i > 1; --i) {       if (go[i] != i) continue;       int k = fc[i].size();       gg = i;       run(0, 0, 1, k);       for (int i = (1 << k) - 1; i > 0; --i) {         for (int j = (i - 1) & i; j > 0; j = (j - 1) & i) dp[j] -= dp[i];         dp[0] -= dp[i];       }       for (int j = 0; j < (1 << k); ++j)         if (dp[j]) ans[gog[j]] = min(ans[gog[j]], ans[i] + 1);     }     cout << ans[1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, m;   priority_queue<int> s;   int main() {     scanf( %d , &n);     m = n;     for (int i = 0; i < int(n); i++) {       scanf( %d , &x);       if (x < m) {         s.push(x);         cout <<    ;       } else if (x == m) {         cout << x <<    ;         m--;         while (!s.empty() && m == s.top()) {           cout << s.top() <<    ;           s.pop();           m--;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[12000];   int n, i, j;   vector<int> ans;   int cek(int v, int t, string e) {     if (v >= strlen(s) - 1) return v;     int i = v;     do {       string tmp =   ;       for (i = i;; i++) {         tmp.push_back(s[i]);         if (s[i] ==  > ) break;       }       i++;       if (e ==  <table>  && tmp ==  </table> ) break;       if (e ==  <tr>  && tmp ==  </tr> ) break;       if (e ==  <td>  && tmp ==  </td> ) {         ans[t]++;         break;       }       if (tmp ==  <table> ) {         ans.push_back(0);         i = cek(i, ans.size() - 1, tmp);       } else if (tmp ==  <tr> ) {         i = cek(i, t, tmp);       } else if (tmp ==  <td> ) {         i = cek(i, t, tmp);       }     } while (i < strlen(s));     return i;   }   int main() {     n = 0;     bool f = 1;     while (scanf( %c , &s[n]) != EOF) {       if (s[n] !=   n ) n++;     }     int k = cek(0, -1,    );     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++) {       if (f)         f = 0;       else         printf(   );       cout << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, k;   int a[333333];   long long ans;   map<int, int> mp, mpb;   int main() {     scanf( %d%d%d , &n, &p, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       mp[a[i]]++;     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       if (1ll * ((it->first) + (it->first)) *               (2ll * (it->first) * (it->first) % p) % p !=           k)         ans -= (1ll * (it->second) * ((it->second) - 1));     }     for (int i = 1; i <= n; i++) {       mpb[((1ll * a[i] * a[i] % p * a[i] % p * a[i] - 1ll * k * a[i]) % p + p) %           p]++;     }     for (map<int, int>::iterator it = mpb.begin(); it != mpb.end(); it++) {       ans += (1ll * (it->second) * ((it->second) - 1));     }     printf( %lld n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long fac[1000006];   inline long long exp(long long x, long long n) {     long long r = 1;     x = x;     while (n) {       if (n % 2) r = (r * x) % 10000000000000007;       x = (x * x) % 10000000000000007;       n = n / 2;     }     return r;   }   inline long long mmi(long long a) {     return exp(a, 10000000000000007 - 2) % 10000000000000007;   }   inline long long fact(long long n) {     long long res = 1;     for (long long i = 1; i < (n + 1); ++i) {       res = (res * i) % 10000000000000007;     }     return res;   }   inline void fact_a() {     fac[0] = 1;     fac[1] = 1;     for (long long i = 1; i < (105); ++i) {       fac[i] = (fac[i - 1] * i) % 10000000000000007;     }   }   inline long long inv_fact(long long n) {     long long par = fac[n];     long long res = mmi(par);     return res;   }   inline long long comb(long long n, long long r) {     if (n == r && r == 0) return 1;     if (n < r) return 0;     return ((fac[n] * inv_fact(r)) % 10000000000000007 * inv_fact(n - r)) %            10000000000000007;   }   struct triplet {     long long a, b, c;   };   bool operator<(const triplet &t1, const triplet &t2) {     if (t1.a < t2.a) return true;     if (t1.a == t2.a && t1.b < t2.b) return true;     if (t1.a == t2.a && t1.b == t2.b && t1.c < t2.c) return true;     return false;   }   pair<long long, pair<long long, long long> > ex_gcd(long long a, long long b) {     if (b == 0) {       return make_pair(a, make_pair(1, 0));     }     pair<long long, pair<long long, long long> > p = ex_gcd(b, a % b);     long long gcd = p.first;     long long x1 = p.second.first;     long long y1 = p.second.second;     long long x = y1;     long long y = x1 - (a / b) * y1;     return make_pair(gcd, make_pair(x, y));   }   long long prime[3000006];   long long spf_prime[3000006];   void sieve() {     prime[1] = 1;     for (long long i = 2; i * i <= 3000000; i++)       if (prime[i] == 0)         for (long long j = i * i; j <= 3000000; j += i) prime[j] = 1;   }   void spf() {     for (long long i = 2; i * i <= 3000000; i++)       if (!spf_prime[i])         for (long long j = i * i; j <= 3000000; j += i)           if (!spf_prime[j]) spf_prime[j] = i;     for (long long i = 2; i <= 3000000; i++)       if (!spf_prime[i]) spf_prime[i] = i;   }   long long getparent_BIT(long long idx) { return idx - (idx & -idx); }   long long getnext_BIT(long long idx) { return idx + (idx & -idx); }   long long getsum_BIT(long long idx, long long BIT[], long long n) {     long long sum = 0;     while (idx > 0) {       sum += BIT[idx];       idx = getparent_BIT(idx);     }     return sum;   }   void update_BIT(long long idx, long long BIT[], long long val, long long n) {     while (idx <= n) {       BIT[idx] += val;       idx = getnext_BIT(idx);     }   }   void build_BIT(long long BIT[], long long a[], long long n) {     for (long long i = 0; i < (n); ++i) {       update_BIT(i, BIT, a[i], n);     }   }   void comp_lps(string s, long long lps[], long long n) {     long long i = 1, j = 0;     while (i < n) {       if (s[i] == s[j]) {         lps[i++] = ++j;       } else {         if (j != 0)           j = lps[j - 1];         else           lps[i++] = 0;       }     }   }   void dfs_l(long long u, vector<vector<long long> > &adj, long long status[]) {     if (status[u] == 1) return;     status[u] = 1;     for (long long i = 0; i < (adj[u].size()); ++i) dfs_l(adj[u][i], adj, status);   }   long long dij(long long u, long long n,                 vector<vector<pair<long long, long long> > > &adj,                 long long status[]) {     long long dist[n];     for (long long i = 0; i < (n); ++i) dist[i] = 1000000000;     dist[0] = 0;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         q;     q.push(make_pair(0, 0));     while (!q.empty()) {       pair<long long, long long> p;       p = q.top();       q.pop();       long long x = p.second;       long long w = p.first;       if (status[x] == 1) continue;       status[x] = 1;       for (long long i = 0; i < (adj[x].size()); ++i) {         long long ww = adj[x][i].first;         long long y = adj[x][i].second;         if (dist[x] + ww < dist[y]) {           dist[y] = dist[x] + ww;           q.push(make_pair(dist[y], y));         }       }     }     if (dist[n - 1] >= 1000000000) return -1;     return dist[n - 1];   }   long long phi(long long n) {     vector<long long> v;     long long k = n;     ;     for (long long i = 2; i * i <= n; i++) {       if (k % i == 0) {         v.push_back(i);         while (k % i == 0) k /= i;       }     }     if (k > 1) v.push_back(k);     long long ans = n;     for (long long i = 0; i < (v.size()); ++i) ans -= (ans / v[i]);     return ans;   }   struct trie {     struct trie *left, *right;     bool isend;   };   trie *get_trie() {     trie *ptr = new trie;     ptr->left = NULL;     ptr->right = NULL;     ptr->isend = false;     return ptr;   }   bool isempty(trie *root) {     if (root->left == NULL && root->right == NULL) return true;     return false;   }   void insert_trie(trie *root, string key) {     trie *ptr = root;     for (long long i = 0; i < (key.size()); ++i) {       if (key[i] ==  0 ) {         if (ptr->left == NULL) {           ptr->left = get_trie();         }         ptr = ptr->left;       } else {         if (ptr->right == NULL) ptr->right = get_trie();         ptr = ptr->right;       }     }     ptr->isend = true;   }   trie *remove_trie(trie *root, string key, long long idx = 0) {     if (root == NULL) return NULL;     if (idx == key.size()) {       if (isempty(root)) {         delete (root);         root = NULL;       }       return root;     }     if (key[idx] ==  0 )       root->left = remove_trie(root->left, key, idx + 1);     else       root->right = remove_trie(root->right, key, idx + 1);     if (isempty(root)) {       delete (root);       root = NULL;     }     return root;   }   long long search_trie(trie *root, string key) {     trie *ptr = root;     string s =   ;     for (long long i = 0; i < (key.size()); ++i) {       if (key[i] ==  0 ) {         if (ptr->right != NULL) {           ptr = ptr->right;           s +=  1 ;         } else {           ptr = ptr->left;           s +=  0 ;         }       } else {         if (ptr->left != NULL) {           ptr = ptr->left;           s +=  1 ;         } else {           ptr = ptr->right;           s +=  0 ;         }       }     }     long long res = 0;     reverse(s.begin(), s.end());     for (long long i = s.length() - 1; i >= (0); --i)       res = res * 2 + (s[i] -  0 );     return res;   }   struct Comp {     bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {       if (a.first != b.first) {         return a.first < b.first;       }       return a.second > b.second;     }   };   void dearr() {     long long dar[1005];     dar[0] = 1;     dar[1] = 0;     dar[2] = 1;     for (long long i = 3; i < (1002); ++i) {       dar[i] = (i - 1) * (dar[i - 1] + dar[i - 2]);     }   }   int main() {     long long n;     cin >> n;     if (n % 2 == 0) {       cout <<  white             <<   n ;       cout << 1 <<     << 2 <<   n ;     } else       cout <<  black             <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i % 2 == 0) {           if (j % 2 == 0) {             cout <<  W ;           } else {             cout <<  B ;           }         } else {           if (j % 2 != 0) {             cout <<  W ;           } else {             cout <<  B ;           }         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int first, second;     cin >> second >> first;     if ((second == 1 && first == 0) || first == 0) {       cout <<  NO ;       return 0;     } else if (first == 1 && second == 0) {       cout <<  YES ;       return 0;     }     int tot = first;     int co = first - 1;     if (first == 1 && second >= 0) {       cout <<  NO ;       return 0;     }     if ((second - co) % 2 == 0 && (second - co) >= 0)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, k, lb, ub, ans = -1;   int main() {     long long l, r;     scanf( %lld%lld%lld%lld , &n, &l, &r, &k);     x = (r >= l ? r - l + 1 : r + n - l + 1) % n;     for (long long i = k, j, r; i; i = j) {       j = k / (k / i + 1);       r = k / i;       ub = min(2 * n, i);       lb = max(n, j + 1);       ub = min(ub, min((2 * n + k - 2 * x + 1) / (r + 1), (k - x) / r));       lb = max(lb, (k - 2 * x + r - 1) / r);       if (ub >= lb) ans = max(ans, ub);     }     if (x <= k && k <= x * 2) ans = max(ans, n + min(k - x, x - 1) + n - x + 1);     if (!x && k == n) ans = max(ans, n + 1);     printf( %lld n , ~ans ? ans - n : ans);   }


#include <bits/stdc++.h>   using namespace std;   char p[][20] = { vaporeon ,  jolteon ,  flareon ,  espeon ,                    umbreon ,   leafeon ,  glaceon ,  sylveon };   char s[20];   int main() {     int n, k, i;     scanf( %d , &n);     scanf( %s , s);     for (k = 0; k < 8; k++) {       int fl = 1;       for (i = 0; fl && i < n; i++) {         if (p[k][i] ==   0  || (p[k][i] != s[i] && s[i] !=  . )) fl = 0;       }       if (fl && p[k][i] ==   0 ) printf( %s n , p[k]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double epsilon = 1e-9;   int main() {     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     vector<pair<int, int> > moves;     for (int i = 0; i < n; i++) {       if (b[i] != a[i]) {         for (int j = i + 1; j < n; j++) {           if (b[j] == a[i]) {             for (int k = j; k > i; k--) {               moves.push_back(make_pair(k - 1, k));               swap(b[k], b[k - 1]);             }             break;           }         }       }     }     cout << moves.size() << endl;     for (int i = 0; i < moves.size(); i++)       cout << moves[i].first + 1 <<     << moves[i].second + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a, b, c, d, e, first;     cin >> a >> b >> c >> d >> e >> first;     b = min(c, b);     if (d < a && d < b)       cout << d * max(e, first);     else {       long long p = min(a, d) * e + min(d - min(d, a), b) * first;       long long q = min(b, d) * first + min(d - min(d, b), a) * e;       cout << max(p, q);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl;         cout << i + 1 <<     << i + 2 << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 21;   int a[1 << maxn], n;   long long ans[maxn][2];   void mergesort(int l, int r, int dep) {     if (r - l <= 1) return;     int m = (l + r) / 2;     mergesort(l, m, dep - 1);     mergesort(m, r, dep - 1);     for (int i = l; i < m; i++) {       ans[dep][0] += lower_bound(a + m, a + r, a[i]) - a - m;     }     for (int i = m; i < r; i++) {       ans[dep][1] += lower_bound(a + l, a + m, a[i]) - a - l;     }     inplace_merge(a + l, a + m, a + r);   }   long long solve(int q) {     long long res = 0;     while (q) swap(ans[q][0], ans[q][1]), q--;     for (int i = 1; i <= n; i++) {       res += ans[i][0];     }     return res;   }   int main() {     int m, q;     cin >> n;     for (int i = 0; i < 1 << n; i++) scanf( %d , &a[i]);     cin >> m;     mergesort(0, 1 << n, n);     for (int i = 0; i < m; i++) {       scanf( %d , &q);       cout << solve(q) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const long long inf = (((long long)1) << 61) + 5;   const int N = 100005;   int f[N];   int g[N];   int a[N];   int bit[N];   int ans[N];   int sum1(int x) {     int ans = 0;     for (int i = x; i > 0; i -= i & -i) ans = max(bit[i], ans);     return ans;   }   void add1(int x, int val) {     for (int i = x; i <= N; i += i & -i) bit[i] = max(bit[i], val);   }   int sum2(int x) {     int ans = 0;     for (int i = x; i <= N; i += i & -i) ans = max(bit[i], ans);     return ans;   }   void add2(int x, int val) {     for (int i = x; i > 0; i -= i & -i) bit[i] = max(bit[i], val);   }   int main() {     int n, res = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       int x = sum1(a[i] - 1);       f[i] = x + 1;       if (f[i] > res) res = f[i];       add1(a[i], f[i]);     }     memset(bit, 0, sizeof bit);     for (int i = n; i >= 1; i--) {       int x = sum2(a[i] + 1);       g[i] = x + 1;       add2(a[i], g[i]);     }     vector<int> q[N];     for (int i = 1; i <= n; i++) {       if (f[i] + g[i] - 1 < res)         ans[i] = 1;       else         q[f[i]].push_back(i);     }     for (int i = 1; i <= res; i++) {       int sz = q[i].size();       for (int j = 0; j < sz; j++) {         int v = q[i][j];         if (sz == 1)           ans[v] = 3;         else           ans[v] = 2;       }     }     for (int i = 1; i <= n; i++) printf( %d , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   template <typename T>   inline void read(T &x) {     x = 0;     T fl = 1;     char ch = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) fl = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + (ch ^ 48);     x *= fl;   }   template <typename T, typename... Args>   inline void read(T &x, Args &...args) {     read(x);     read(args...);   }   const int N = 1e5 + 5;   struct data {     int s, m, r, t;     data(int x = 0) { t = x; }     bool operator<(const data &b) const { return t < b.t; }     long long calc(long long tim) { return min(s + tim * r, m * 1ll); }   } a[18][N];   struct seg {     int trt[N << 2];     long long trm[18][N << 2], trr[18][N << 2];     void pushdown(int nod) {       if (trt[nod] >= 0) trt[(nod << 1)] = trt[(nod << 1 | 1)] = trt[nod];     }     void pushup(int nod) {       if (trt[(nod << 1)] != trt[(nod << 1 | 1)])         trt[nod] = -1;       else         trt[nod] = trt[(nod << 1)];     }     void build(int nod, int l, int r, int dep) {       trt[nod] = -2;       if (l == r) {         read(a[dep][l].s, a[dep][l].m, a[dep][l].r);         if (a[dep][l].r == 0)           a[dep][l].t = inf;         else           a[dep][l].t = a[dep][l].m % a[dep][l].r == 0                             ? a[dep][l].m / a[dep][l].r                             : a[dep][l].m / a[dep][l].r + 1;         trm[dep][l] = trm[dep][l - 1] + a[dep][l].m;         trr[dep][l] = trr[dep][l - 1] + a[dep][l].r;         return;       }       int mid = (l + r) >> 1;       build((nod << 1), l, mid, dep + 1);       build((nod << 1 | 1), mid + 1, r, dep + 1);       for (int i = (l); i <= (r); i++) a[dep][i] = a[dep + 1][i];       sort(a[dep] + l, a[dep] + r + 1);       for (int i = (l); i <= (r); i++) {         trm[dep][i] = trm[dep][i - 1] + a[dep][i].m;         trr[dep][i] = trr[dep][i - 1] + a[dep][i].r;       }     }     long long query(int tim, int nod, int l, int r, int ql, int qr, int dep) {       long long res = 0;       if (ql <= l && r <= qr && trt[nod] != -1) {         if (trt[nod] == -2)           for (int i = (l); i <= (r); i++) res += a[dep][i].calc(tim);         else {           int i = upper_bound(a[dep] + l, a[dep] + 1 + r, data(tim - trt[nod])) -                   a[dep] - 1;           res = (tim - trt[nod]) * (trr[dep][r] - trr[dep][i]) + trm[dep][i] -                 trm[dep][l - 1];         }         trt[nod] = tim;         return res;       }       pushdown(nod);       int mid = (l + r) >> 1;       if (ql <= mid) res += query(tim, (nod << 1), l, mid, ql, qr, dep + 1);       if (qr > mid)         res += query(tim, (nod << 1 | 1), mid + 1, r, ql, qr, dep + 1);       pushup(nod);       return res;     }   } sgt;   int n, m;   int main() {     read(n);     sgt.build(1, 1, n, 0);     read(m);     for (int _ = (1); _ <= (m); _++) {       int t, l, r;       read(t);       read(l);       read(r);       printf( %lld n , sgt.query(t, 1, 1, n, l, r, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, i, j, n, aux, cnt, ans, div1[10000010], v[10000010];   int main() {     cin >> a >> n;     v[1] = 1;     for (i = 3; i * i <= a + n - 1; i += 2)       if (!div1[i]) {         div1[i] = i;         for (j = i * i; j <= a + n - 1; j += 2 * i) div1[j] = i;       }     for (i = 2; i <= a + n - 1; i += 2) div1[i] = 2;     for (i = 2; i <= a + n - 1; i++) {       aux = i;       cnt = 0;       if (!div1[i]) div1[i] = i;       while (aux % div1[i] == 0) aux /= div1[i], cnt++;       v[i] = v[aux];       if (cnt & 1) v[i] *= div1[i];     }     for (i = a; i <= a + n - 1; i++) ans += v[i];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   vector<long long> v;   unordered_map<long long, long long> m;   long long falla(long long n) {     if (m.count(n)) {       return m[n];     }     long long ans;     long long k = 0;     for (int j = n - 1; j >= 1; j--) {       if (n % j == 0) {         ans = j;         break;       }       if (n % (n - j + 1) == 0) {         ans = n / (n - j + 1);         break;       }     }     m[ans] = ans;     return ans;   }   int main() {     long long casos;     cin >> casos;     long long num = pow(2, 25) - 1;     for (int i = 1; i < 30; i++) {       v.push_back((1 << i) - 1);     }     long long flag = 0;     while (casos--) {       long long num;       long long ans1;       cin >> num;       if (m.count(num)) {         cout << m[num] << endl;         flag = 1;       }       if (flag == 0) {         ans1 = lower_bound((v).begin(), (v).end(), num) - v.begin();         if (num == v[ans1]) {           ans1 = falla(num);           m[num] = ans1;           cout << ans1 << endl;         } else {           m[num] = v[ans1];           cout << v[ans1] << endl;         }       }       flag = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[200005][2];   bool vst[200005][2];   long long A[200005], n;   long long go(long long v, bool b) {     if (vst[v][b]) return dp[v][b];     vst[v][b] = true;     long long val = 0;     if (!b) {       if ((v - A[v]) > 1)         val = go(v - A[v], b ^ 1);       else if ((v - A[v]) == 1)         val = -1;     } else {       if ((v + A[v]) <= n) val = go(v + A[v], b ^ 1);     }     if (val != -1)       dp[v][b] = A[v] + val;     else       dp[v][b] = -1;     return dp[v][b];   }   int main() {     long long i;     cin >> n;     for (i = (2); i <= (n); i++) {       cin >> A[i];     }     memset((vst), (0), sizeof(vst));     long long j;     memset((dp), (-1), sizeof(dp));     for (i = (2); i <= (n); i++) {       go(i, 0);       if (dp[i][0] != -1)         cout << dp[i][0] + i - 1 << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const double Pi = 3.1415926535897932;   const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};   const int maxn = 1e4 + 5;   struct EDGE {     int a, b;     int A, B;   } edge[maxn];   int n, m;   int last[maxn];   vector<int> G[maxn], tree[maxn];   int d[maxn];   int A[maxn], B[maxn];   bool vis[maxn];   vector<int> ans;   int in[maxn];   void dfs_tree(int a, int fa) {     vis[a] = true;     for (int i = 0; i < G[a].size(); i++) {       int p = G[a][i];       if (p == last[a]) continue;       int b = edge[p].a ^ edge[p].b ^ a;       if (!vis[b]) {         tree[a].push_back(p);         in[p] = true;         d[b] = d[a] + 1;         last[b] = p;         dfs_tree(b, a);       } else if (d[a] > d[b]) {         if (d[a] - d[b] + 1 & 1) {           ans.push_back(p);           B[a]++;           B[b]--;         } else {           A[a]++;           A[b]--;         }       }     }   }   void dfs(int a) {     vis[a] = true;     for (int i = 0; i < tree[a].size(); i++) {       int p = tree[a][i];       int b = edge[p].a ^ edge[p].b ^ a;       if (!vis[b]) dfs(b);       A[a] += A[b];       B[a] += B[b];     }     edge[last[a]].A = A[a];     edge[last[a]].B = B[a];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[i] = EDGE{a, b};       G[a].push_back(i);       G[b].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) dfs_tree(i, -1);     }     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (!vis[i]) dfs(i);     }     if (ans.size() == 0) {       for (int i = 1; i <= m; i++) ans.push_back(i);     } else if (ans.size() == 1) {       for (int i = 1; i <= m; i++)         if (in[i]) {           if (edge[i].A == 0 && edge[i].B) ans.push_back(i);         }     } else {       int t = ans.size();       ans.clear();       for (int i = 1; i <= m; i++)         if (in[i]) {           if (edge[i].B) {             if (edge[i].B == t && edge[i].A == 0) ans.push_back(i);           }         }     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++)       printf( %d , ans[i]), putchar(i == ans.size() - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[200];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].second;       long long tmp = a[i].second;       while (tmp % 3 == 0) {         a[i].first--;         tmp /= 3;       }     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) cout << a[i].second <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[3];     scanf( %I64d%I64d%I64d , &arr[0], &arr[1], &arr[2]);     sort(arr, arr + 3);     if (arr[0] == arr[1] && arr[1] == arr[2])       printf( 0 n );     else if (arr[2] == arr[1] && arr[1] > arr[0]) {       printf( %I64d n , arr[2] - arr[0] - 1);     } else if (arr[2] > arr[1] && arr[1] == arr[0]) {       printf( %I64d n , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));     } else if (arr[2] > arr[1] && arr[1] > arr[0]) {       printf( %I64d n , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));     }   }


#include <bits/stdc++.h>   using namespace std;   long long const modul = 1;   long long mod_sum(long long x, long long y) { return (x + y) % modul; }   long long mod_sub(long long x, long long y) {     if (x > y) {       return (x - y) % modul;     } else {       return (modul + x - y) % modul;     }   }   long long mod_mpl(long long x, long long y) { return (x * y) % modul; }   void set_precise(int n) {     cout << fixed;     cout << setprecision(n);   }   int const N = 200000;   class Tree {    private:     long long tree[N * 4];     int start;     int size;     void rebuild(int id) {       if (id < 1) {         return;       }       tree[id] = tree[id * 2] + tree[id * 2 + 1];       rebuild(id / 2);     };     long long count_sum(int cur, int left, int right, int cur_l, int cur_r) {       int mid = (cur_l + cur_r) / 2;       if ((left == cur_l) && (right == cur_r)) {         return tree[cur];       }       if (right <= mid) {         return count_sum(cur * 2, left, right, cur_l, mid);       } else if (left >= mid + 1) {         return count_sum(cur * 2 + 1, left, right, mid + 1, cur_r);       } else {         return count_sum(cur * 2, left, mid, cur_l, mid) +                count_sum(cur * 2 + 1, mid + 1, right, mid + 1, cur_r);       }     };       public:     Tree() {       size = 0;       start = 0;     };     void initialize(int n) {       int cur = 1;       int sum = 0;       while (cur < n) {         sum += cur;         cur *= 2;       }       start = sum + 1;       size = cur;       for (int i = 1; i < start + cur; ++i) {         tree[i] = 0;       }     }     Tree(int n) {       int cur = 1;       int sum = 0;       while (cur < n) {         sum += cur;         cur *= 2;       }       start = sum + 1;       size = cur;       for (int i = 1; i < start + cur; ++i) {         tree[i] = 0;       }     };     void update(int pos, long long q, long long no_more) {       long long cur = tree[start + pos];       cur += q;       if (cur > no_more) {         cur = no_more;       }       tree[start + pos] = cur;       rebuild((start + pos) / 2);     };     long long get_sum(int left, int right) {       if (left > right) {         return 0;       }       return count_sum(1, left, right, 0, size - 1);     }   };   Tree max_a;   Tree max_b;   int main() {     int n, k;     long long a, b;     int q;     cin >> n >> k >> a >> b >> q;     max_a.initialize(n);     max_b.initialize(n);     for (int i = 0; i < q; ++i) {       int type;       cin >> type;       if (type == 1) {         int day;         long long x;         cin >> day >> x;         --day;         max_a.update(day, x, a);         max_b.update(day, x, b);       } else {         int p;         cin >> p;         --p;         long long ans = 0;         ans += max_b.get_sum(0, p - 1);         ans += max_a.get_sum(p + k, n - 1);         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void sove() {}   int main() {     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; ++i) {       cin >> nums[i];     }     for (int i = 0; i < n / 2; i += 2) {       int temp = nums[i];       nums[i] = nums[n - i - 1];       nums[n - i - 1] = temp;     }     for (int num : nums) {       cout << num <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   vector<int> e[maxn];   int dp[maxn], root[maxn], d[maxn], sz[maxn];   pair<int, int> dfs(int v, int st, int par) {     if (root[v] == -1) sz[st]++;     root[v] = st;     pair<int, int> p = make_pair(0, -1);     for (int i = 0; i < e[v].size(); i++)       if (e[v][i] != par) p = max(p, dfs(e[v][i], st, v));     if (par != -1) p.first++;     if (p.second == -1) p.second = v;     return p;   }   int get_root(int v) { return root[v] == v ? v : root[v] = get_root(root[v]); }   void merge(int v, int u) {     v = get_root(v);     u = get_root(u);     if (sz[v] > sz[u]) swap(v, u);     if (v == u) return;     root[v] = u;     sz[u] += sz[v];     d[u] = max((d[v] + 1) / 2 + (d[u] + 1) / 2 + 1, max(d[v], d[u]));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, q;     cin >> n >> m >> q;     memset(root, -1, sizeof root);     for (int i = 0; i < m; i++) {       int u, v;       cin >> v >> u;       v--;       u--;       e[v].push_back(u);       e[u].push_back(v);     }     for (int i = 0; i < n; i++)       if (root[i] == -1) d[i] = dfs(dfs(i, i, -1).second, i, -1).first;     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         x--;         cout << d[get_root(x)] <<   n ;       } else {         int x, y;         cin >> x >> y;         x--;         y--;         merge(x, y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     for (long long int _ = 0; _ < t; _++) {       long long int n, m, b, mod;       cin >> n >> m >> b >> mod;       vector<long long int> v(n + 1);       for (long long int i = 1; i <= n; i++) cin >> v[i];       long long int dp[2][m + 1][b + 1];       for (long long int i = 0; i <= 1; i++) {         for (long long int j = 0; j <= m; j++) {           for (long long int k = 0; k <= b; k++) dp[i][j][k] = 0;         }       }       dp[0][0][0] = 1;       for (long long int i = 1; i <= n; i++) {         for (long long int j = 0; j <= m; j++) {           for (long long int k = 0; k <= b; k++) {             if (k >= v[i] && j > 0)               dp[i % 2][j][k] =                   (dp[1 - (i % 2)][j][k] + dp[i % 2][j - 1][k - v[i]]) % mod;             else               dp[i % 2][j][k] = dp[1 - (i % 2)][j][k];           }         }       }       long long int ans = 0;       for (long long int k = 0; k <= b; k++) ans = (ans + dp[n % 2][m][k]) % mod;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   set<string> a, b, c;   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       a.insert(s);     }     for (int i = 1; i <= m; i++) {       string s;       cin >> s;       if (a.count(s)) c.insert(s);       b.insert(s);     }     while (1) {       if (a.empty()) {         cout <<  NO n ;         return;       }       if (!c.empty()) {         a.erase(*c.begin());         b.erase(*c.begin());         c.erase(c.begin());       } else {         if (b.count(*a.begin())) b.erase(*a.begin());         a.erase(a.begin());       }       if (b.empty()) {         cout <<  YES n ;         return;       }       if (!c.empty()) {         a.erase(*c.begin());         b.erase(*c.begin());         c.erase(c.begin());       } else {         if (a.count(*b.begin())) a.erase(*b.begin());         b.erase(b.begin());       }     }   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, res = 0, a = 0, b;     cin >> n >> d;     for (int i = 0; i < n; i++) {       cin >> b;       if (a >= b) {         res += ceil((a - b + 1) / (double)d);         b += ceil((a - b + 1) / (double)d) * d;       }       a = b;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100010];   int N, K, in[100010], dp[100010][2];   vector<pair<int, int> > num[100010];   void dfs(int u, int fa) {     for (pair<int, int>& e : g[u]) {       int v = e.first, cost = e.second;       if (v == fa) continue;       dfs(v, u);       num[u].push_back(pair<int, int>(dp[v][1] + cost, v));     }     sort(num[u].begin(), num[u].end(), greater<pair<int, int> >());     dp[u][1] = 0;     int sum = 0;     for (size_t i = 0; (int)i < K - 1 && i < num[u].size(); i++) {       dp[u][1] += num[u][i].first;       sum += num[u][i].first;     }     if ((int)num[u].size() <= K - 1) {       for (size_t i = 0; i < num[u].size(); i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum - dp[v][1] + dp[v][0]);       }     } else {       for (size_t i = 0; i < (int)K - 1; i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum + num[u][K - 1].first - dp[v][1] + dp[v][0]);       }       for (size_t i = K - 1; i < num[u].size(); i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum + num[u][i].first - dp[v][1] + dp[v][0]);       }     }   }   int main() {     int u, v, c;     scanf( %d%d , &N, &K);     for (int i = 1; i < N; i++) {       scanf( %d%d%d , &u, &v, &c);       g[u].push_back(pair<int, int>(v, c));       g[v].push_back(pair<int, int>(u, c));     }     dfs(0, -1);     printf( %d n , max(dp[0][0], dp[0][1]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); }   const double EPS = 10e-9;   const long long INF = (1LL << 30);   using namespace std;   template <typename T>   string toString(T t) {     stringstream ss;     ss << t;     return ss.str();   }   long long isSquare(long long N) {     long long lo = 1, hi = 2 * sqrt(N);     while (hi - lo > 1) {       long long mid = (hi + lo) >> 1;       long long res = mid * mid;       if (res < N) {         lo = mid;       } else if (res > N) {         hi = mid;       } else {         return mid;       }     }     return lo;   }   int main() {     long long N;     cin >> N;     if (N % 3 != 0) {       cout << 0 << endl;     } else {       N /= 3;       int options = 0;       for (long long i = 1; i * i * i <= N; i++) {         if (N % i == 0) {           long long left = N / i, to = i / 2;           for (long long a = 1; a <= to; a++) {             long long c = i - a;             long long d = (a - c) * (a - c);             long long sqr = isSquare(d + 4 * left);             if (sqr * sqr == d + 4 * left) {               long long b = (-(a + c) + sqr) >> 1;               if (c <= b) {                 if (a == c) {                   if (b == c) {                     options += 1;                   } else {                     options += 3;                   }                 } else {                   if (b == c) {                     options += 3;                   } else {                     options += 6;                   }                 }               }             }           }         }       }       cout << options << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 1e17;   const long long int N = 5005;   long long int n;   long long int a[N];   long long int dp[N][N];   long long int go(long long int idx, long long int flag) {     long long int &ans = dp[idx][flag];     if (ans != -1) return ans;     if (idx > n) {       return 0;     }     if (flag == 0 or flag == 2) {       ans = max(go(idx + 1, flag), go(idx + 1, flag + 1)) + a[idx];     } else {       ans = max(go(idx + 1, flag), go(idx + 1, flag + 1)) - a[idx];     }     return ans;   }   vector<long long int> res;   void backtrack(long long int idx, long long int flag) {     if (idx > n) {       return;     }     if (flag == 0 or flag == 2) {       long long int tmp1 = go(idx + 1, flag) + a[idx];       long long int tmp2 = go(idx + 1, flag + 1) + a[idx];       res.push_back(1);       if (tmp1 >= tmp2) {         backtrack(idx + 1, flag);       } else {         backtrack(idx + 1, flag + 1);       }     } else {       long long int tmp1 = go(idx + 1, flag) - a[idx];       long long int tmp2 = go(idx + 1, flag + 1) - a[idx];       res.push_back(0);       if (tmp1 >= tmp2) {         backtrack(idx + 1, flag);       } else {         backtrack(idx + 1, flag + 1);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof(dp));     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int ans = go(0, 0);     backtrack(0, 0);     res.erase(res.begin());     long long int cnt = 0, idx = 0;     while (res[idx] and idx < n) {       cnt++;       idx++;     }     vector<long long int> vec;     vec.push_back(cnt);     cnt = 0;     idx = vec.back();     while (idx < n and !res[idx]) {       cnt++;       idx++;     }     vec.push_back(cnt);     idx = vec[0] + vec[1];     cnt = 0;     while (idx < n and res[idx]) {       cnt++;       idx++;     }     vec.push_back(cnt);     idx = 0, cnt = 0;     for (auto to : vec) {       cnt = to;       if (cnt == 0LL) {         cout << idx <<    ;       } else {         cout << idx + cnt <<    ;         idx += cnt;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   bool chk(string s) {     int l = s.size();     for (int i = 0, j = l - 1; i <= j; i++, j--) {       if (s[i] != s[j]) return false;     }     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       string ans;       int mx = 0;       string res;       for (int i = 0; i < s.size(); i++) {         ans += s[i];         if (chk(ans)) {           int l = ans.size();           if (l > mx) {             mx = ans.size();             res = ans;           }         }       }       ans =   ;       for (int i = s.size() - 1; i >= 0; i--) {         ans += s[i];         if (chk(ans)) {           int l = ans.size();           if (l > mx) {             mx = ans.size();             res = ans;           }         }       }       int p1 = 0;       int p2 = 0;       for (int i = 0, j = s.size() - 1; i < j; i++, j--) {         if (s[i] != s[j]) {           p1 = i - 1;           p2 = j + 1;           break;         }       }       ans =   ;       string rev =   ;       for (int i = 0; i <= p1; i++) ans += s[i];       for (int i = p2; i < s.size(); i++) rev += s[i];       string ss =   ;       for (int i = p1 + 1; i < p2; i++) {         ss += s[i];         string tmp = ans + ss + rev;         int l = tmp.size();         if (l <= mx) continue;         if (chk(tmp)) {           if (l > mx) {             mx = l;             res = tmp;           }         }       }       ss =   ;       for (int j = p2 - 1; j > p1; j--) {         ss = s[j] + ss;         string tmp = ans + ss + rev;         int l = tmp.size();         if (chk(tmp)) {           if (l > mx) {             mx = l;             res = tmp;           }         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     int num = n + m;     int a = m / 2, aa = m % 2, aaa = a + aa;     if (n == m) {       for (int i = 0; i < n; i++) {         printf( 01 );       }     } else if (n < m) {       if (aaa <= n + 1) {         a = m - (n + 1);         m -= a;         for (int i = 0; n; i++) {           if (a) {             printf( 11 );             a--;           } else if (m) {             printf( 1 );             m--;           }           if (n) {             printf( 0 );             n--;           }         }         if (a)           printf( 11 );         else if (m)           printf( 1 );       } else         printf( -1 );     } else if (n > m) {       if (n <= m + 1) {         for (int i = 0; i < m; i++) {           printf( 01 );         }         printf( 0 );       } else         printf( -1 );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k, d, t;   int main() {     scanf( %lld%lld%lld , &k, &d, &t);     t *= 2;     long long round = ceil((double)k / d) * d;     long long num = k * 2 + (round - k);     long long cnt = t / num;     long long left = t - cnt * num;     double ans = 0.0;     if (left <= k * 2) {       ans = cnt * round + left / 2;       if (left % 2) ans += 0.5;     } else       ans = cnt * round + k + (left - k * 2);     printf( %.1lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 0, last = 0, current = 0;     while (n > 0) {       ans++;       current = last + ans;       last = current;       n -= current;       if (n < 0) {         ans--;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int head, tail, n, q[100100];   long long f[100100], a[100100], b[100010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);     f[1] = 0;     head = tail = 1;     q[head] = 1;     for (int i = 2; i <= n; i++) {       while (head < tail) {         if ((1.0 * f[q[head]] + 1.0 * a[i] * b[q[head]]) >             (1.0 * f[q[head + 1]] + 1.0 * a[i] * b[q[head + 1]]))           head++;         else           break;       }       f[i] = f[q[head]] + b[q[head]] * a[i];       while (head < tail) {         if (1.0 * (f[q[tail]] - f[q[tail - 1]]) * (b[q[tail]] - b[i]) >             1.0 * (f[i] - f[q[tail]]) * (b[q[tail - 1]] - b[q[tail]]))           tail--;         else           break;       }       q[++tail] = i;     }     printf( %I64d , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 5005;   void update(int &a, int b) {     a += b;     a %= MOD;   }   int add(int a, int b) { return (a + b) % MOD; }   int multiply(int a, int b) { return (a * 1LL * b) % MOD; }   int quick_power(int a, int n) {     int res = 1;     for (; n > 0; n >>= 1) {       if (n & 1) res = multiply(res, a);       a = multiply(a, a);     }     return res;   }   int get_inv(int a) { return quick_power(a, MOD - 2); }   int n, a;   int cnt[N], sum[N][N], dp[N][N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       cnt[a]++;     }     for (int i = 0; i <= n; i++) {       sum[0][i] = 1;     }     int answer = 0;     for (int i = 1; i <= n; i++) {       int inv = get_inv(n - i + 1);       for (int j = 1; j <= n; j++) {         if (cnt[j]) {           dp[i][j] = multiply(multiply(sum[i - 1][j - 1], cnt[j]), inv);           update(answer, multiply(multiply(dp[i - 1][j], cnt[j] - 1), inv));         }         sum[i][j] = add(sum[i][j - 1], dp[i][j]);       }     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long double n, h;     cin >> n >> h;     cout << setprecision(20);     for (long double i = 0; i < n - 1; i++) {       cout << h * sqrt((i + 1) / n) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const long long N = 1e5 + 5, M = 1e9 + 7;   char ulta[500];   set<char> ache;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ulta[ U ] =  D ;     ulta[ D ] =  U ;     ulta[ R ] =  L ;     ulta[ L ] =  R ;     string s;     long long n, i, j, k, ans = 2;     cin >> n >> s;     for (auto ch : s) {       auto x = ache.find(ulta[ch]);       if (x != ache.end()) {         ans++;         ache.clear();       }       ache.insert(ch);     }     cout << ans - 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct State {     int len, link;     map<char, int> nxtc;   } SA[2 * 2006];   bool vis[2 * 2006];   char str[2006], pref[2 * 2006], suf[2006];   class SuffixAutomata {     int sz, last;     void init(int idx) {       SA[idx].len = 0, SA[idx].link = -1;       SA[idx].nxtc.clear();     }     bool traverse(int cur, char *ch) {       if (*ch == 0) return true;       if (SA[cur].nxtc.count(*ch) == 0) return false;       int p = SA[cur].nxtc[*ch];       return traverse(p, ++ch);     }     int findState(int cur, char *ch) {       if (*ch == 0) return cur;       int p = SA[cur].nxtc[*ch];       return findState(p, ++ch);     }       public:     SuffixAutomata() {       sz = last = 0;       init(0);       ++sz;     }     int size() { return sz; }     void extend(char ch) {       int p, q, clone, cur = sz++;       init(cur);       SA[cur].len = SA[last].len + 1;       for (p = last; p != -1 && SA[p].nxtc.count(ch) == 0; p = SA[p].link)         SA[p].nxtc[ch] = cur;       if (p == -1)         SA[cur].link = 0;       else {         q = SA[p].nxtc[ch];         if (SA[p].len + 1 == SA[q].len)           SA[cur].link = q;         else {           clone = sz++;           init(clone);           SA[clone] = SA[q];           SA[clone].len = SA[p].len + 1;           for (; p != -1 && SA[p].nxtc[ch] == q; p = SA[p].link)             SA[p].nxtc[ch] = clone;           SA[cur].link = SA[q].link = clone;         }       }       last = cur;     }     bool traverse(char *str) { return traverse(0, str); }     int findState(char *str) { return findState(0, str); }   };   int lenp, lens, dp[2 * 2006][2006];   int rec(int cur, int idx) {     if (suf[idx] == 0) return 1;     if (dp[cur][idx] != -1) return dp[cur][idx];     int &ret = dp[cur][idx];     ret = 0;     char ch;     int p;     if (idx) {       ch = suf[idx];       if (SA[cur].nxtc.count(ch) == 0) return ret = 0;       p = SA[cur].nxtc[ch];       return ret = rec(p, idx + 1);     }     map<char, int> &M = SA[cur].nxtc;     map<char, int>::iterator im;     for (im = M.begin(); im != M.end(); ++im) {       ch = im->first;       p = im->second;       ret += rec(p, idx);       if (ch == suf[idx]) ret += rec(p, idx + 1);     }     return ret;   }   int main() {     int i, j, ans, n;     while (scanf( %s , str) != EOF) {       SuffixAutomata sa;       for (i = 0; str[i]; ++i) sa.extend(str[i]);       ans = 0;       scanf( %s %s , pref, suf);       lenp = strlen(pref), lens = strlen(suf);       if (!sa.traverse(pref)) {         puts( 0 );         continue;       }       for (i = 0; i < lenp; ++i) {         if (i + lens < lenp) continue;         for (j = 0; j < lens; ++j) {           if (pref[i + j] != suf[j]) break;         }         if (i + j == lenp) {           strcat(pref, &suf[lenp - i]);           ans += sa.traverse(pref);           pref[lenp] = 0;         }       }       n = sa.findState(pref);       memset(dp, -1, sizeof(dp));       ans += rec(n, 0);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   int main() {     int n, k, q, i, a, b, p[MAX] = {0}, c[MAX] = {0};     scanf( %d %d %d , &n, &k, &q);     while (n--) {       scanf( %d %d , &a, &b);       p[a]++;       p[b + 1]--;     }     for (i = 1; i < MAX; i++) {       p[i] += p[i - 1];       c[i] += c[i - 1] + (p[i] >= k);     }     while (q--) {       scanf( %d %d , &a, &b);       printf( %d n , c[b] - c[a - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class base {    public:     long double a, b;     base(void) {       a = 0;       b = 0;     }     base(long double _a, long double _b) {       a = _a;       b = _b;     }     base(long double _a) {       a = _a;       b = 0;     }     base operator*(const base& b2) {       base ret(a * b2.a - b * b2.b, b * b2.a + a * b2.b);       return ret;     }     base operator+(const base& b2) {       base ret(a + b2.a, b + b2.b);       return ret;     }     base operator-(const base& b2) {       base ret(a - b2.a, b - b2.b);       return ret;     }     base operator/(const base& b2) {       long double c = b2.a, d = b2.b;       base ret((a * c + b * d) / (c * c + d * d),                (b * c - a * d) / (c * c + d * d));       return ret;     }     void operator*=(const base& b2) {       long double tmp = a * b2.a - b * b2.b;       b = b * b2.a + a * b2.b;       a = tmp;     }     void operator/=(const base& b2) {       long double c = b2.a, d = b2.b;       long double tmp = (a * c + b * d) / (c * c + d * d);       b = (b * c - a * d) / (c * c + d * d);       a = tmp;     }     inline long double real(void) { return a; }   };   void fft(vector<base>& a, bool invert) {     int n = (int)a.size();     for (int i = 1, j = 0; i < n; ++i) {       int bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     base ww[n];     long double ang = 2 * 3.14159265358979323846l / n * (invert ? -1 : 1);     base wi(cos(ang), sin(ang));     ww[0] = 1;     for (int i = 1; i < n; i++) {       ww[i] = ww[i / 2] * ww[i / 2];       if (i % 2 == 1) ww[i] *= wi;     }     for (int len = 2; len <= n; len <<= 1) {       int k = n / len;       for (int i = 0; i < n; i += len) {         int wn = 0;         for (int j = 0; j < len / 2; ++j) {           base u = a[i + j], v = a[i + j + len / 2] * ww[wn];           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           wn += k;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   vector<int> multiply(const vector<int>& a, const vector<int>& b) {     vector<base> fa(a.begin(), a.end());     size_t n = 1;     while (n < (a.size() + b.size())) n <<= 1;     fa.resize(n);     vector<int> res;     fft(fa, false);     for (size_t i = 0; i < n; ++i) fa[i] *= fa[i];     fft(fa, true);     res.resize(n);     long long int carry = 0;     for (size_t i = 0; i < n; ++i) {       carry += (long long int)(fa[i].real() + 0.5);       res[i] = carry % 1000;       carry /= 1000;     }     int i;     for (i = n - 1; i > 0; i--) {       if (res[i] != 0) break;     }     res.resize(i + 1);     return res;   }   void small_mult(vector<int>& a, int b) {     int carry = 0;     for (int i = 0; i < (int)a.size() || carry; i++) {       if (i == (int)a.size()) a.push_back(0);       int cur = carry + a[i] * b;       a[i] = cur % 1000;       carry = cur / 1000;     }     while (a.size() > 1 && !a.back()) a.pop_back();   }   void fast_3_pow(long long int k, vector<int>& ans) {     ans = {1};     if (k <= 0) return;     long long int r = 0, kk = 0;     for (long long int t = k; t > 0; t /= 2) {       r = (2 * r + t % 2);       kk++;     }     for (long long int i = 0; i < kk; i++) {       ans = multiply(ans, ans);       if (r % 2) small_mult(ans, 3);       r /= 2;     }   }   bool first_is_BE(vector<int>& v1, vector<int>& v2) {     if (v1.size() > v2.size()) return 1;     if (v1.size() < v2.size()) return 0;     for (long long int i = ((long long int)v1.size()) - 1; i >= 0; i--) {       if (v1[i] > v2[i]) return 1;       if (v1[i] < v2[i]) return 0;     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     if (s ==  1 ) {       cout <<  1 ;       return 0;     }     if (s ==  2 ) {       cout <<  2 ;       return 0;     }     if (s ==  3 ) {       cout <<  3 ;       return 0;     }     if (s ==  4 ) {       cout <<  4 ;       return 0;     }     if (s ==  5 ) {       cout <<  5 ;       return 0;     }     if (s ==  6 ) {       cout <<  5 ;       return 0;     }     if (s ==  7 ) {       cout <<  6 ;       return 0;     }     if (s ==  8 ) {       cout <<  6 ;       return 0;     }     if (s ==  9 ) {       cout <<  6 ;       return 0;     }     vector<int> n;     int tmp = 0;     while (s.size() % 3 != 0) s =  0  + s;     for (int i = 0; i < (int)s.size(); i++) {       tmp *= 10;       tmp += s[i] -  0 ;       if ((i + 1) % 3 == 0) {         n.push_back(tmp);         tmp = 0;       }     }     reverse(n.begin(), n.end());     vector<int> v1, vt;     int k;     k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);     fast_3_pow(k, v1);     vt = v1;     small_mult(v1, 4);     while (1) {       if (first_is_BE(v1, n)) {         break;       }       k++;       small_mult(v1, 3);     }     int ans3 = 3 * k + 4;     k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);     v1 = vt;     while (1) {       if (first_is_BE(v1, n)) {         break;       }       k++;       small_mult(v1, 3);     }     int ans1 = 3 * k;     k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);     v1 = vt;     small_mult(v1, 2);     while (1) {       if (first_is_BE(v1, n)) {         break;       }       k++;       small_mult(v1, 3);     }     int ans2 = 3 * k + 2;     cout << min(min(ans1, ans2), ans3);     return 0;   }


#include <bits/stdc++.h>   #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define ll long long int   #define pb push_back   #define pob pop_back   #define ub upper_bound   #define lb lower_bound   #define mp make_pair   #define f0(i,n) for(i=0;i<n;i++)   #define rf0(i,n) for(i=n-1;i>=0;i--)   #define f2(i,n) for(i=1;i<n;i++)   #define f1(i,n) for(i=1;i<=n;i++)   #define fab(i,a,b) for(i=a;i<=b;i++)   #define shr  ll t;cin>>t; while(t--)   #define fi first   #define sc second   #define pll pair<ll,ll>   #define vll vector<ll>   #define vpll vector<pll>   #define all(v) v.begin(),v.end()   #define mod 1000000007   #define dev(a) for(auto it:a)cout<<it<<      #define prec(nm,prc) cout<<fixed << setprecision(nm)<<prc   #define print(a) cout<<a<<endl;   #define nl   n    using namespace std;   bool comp(pll &a,pll &b)   {       return (a.sc<b.sc);   }   ll power(ll n,ll p)   {    if(p==0)    return 1;    else    {     ll ans=power(n,p/2)%mod;     ans=(ans*ans)%mod;     if(p%2==0)     return ans;     else     return ans=(ans*n)%mod;    }   }   bool isPrime(ll n)    {        if (n <= 1)            return false;        if (n <= 3)            return true;             if (n % 2 == 0 || n % 3 == 0)            return false;             for (ll i = 5; i * i <= n; i = i + 6)            if (n % i == 0 || n % (i + 2) == 0)                return false;             return true;    }              /********************HAR HAR MAHADEV***********JAI BAJRANG BALI************************/     int main()    {      FAST;      /* ifstream cin;       cin.open( input.txt );       ofstream cout;       cout.open( output.txt );                         */      shr        {           ll i,j,n,a,b,c,c1,d,m,sum=0,temp,k,k2,k1,ans=0,cnt=0,r=0,e=0,f;         string str,stri,om,s;           map<ll,ll>mp,mp1;           set<ll>st; vector<vll> v;           cin>>n>>k; ll x[n][2];           f0(i,n)           {               cin>>x[i][0]>>x[i][1];           }          f0(i,n)          {             vll vk;              f0(j,n)             {                                  if(i!=j)                 {                     vk.pb(abs(x[i][0]-x[j][0])+abs(x[i][1]-x[j][1]));                 }                             }              v.pb(vk);             r++;         }         f0(i,v.size())         {         ll p=*max_element(all(v[i]));         if(p<=k){e=1;break;}         }         if(e==1)cout<<1;         else cout<<-1;         cout<<endl;        }               return 0;     }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 10000;   const double eps = 1e-9;   using namespace std;   int n, m, cur;   set<int> s;   void dfs(int x, int y) {     if (y == 0) {       int tmp = abs(abs(x) - n);       if (tmp < MAXN) {         if (s.size() < m) s.insert(cur * MAXN + tmp);         if (s.size() < m) s.insert(cur + MAXN * tmp);       }       return;     }     dfs(x + (y % 10), y / 10);     dfs(x - (y % 10), y / 10);     dfs(x * (y % 10), y / 10);   }   int main() {     scanf( %d , &(n)), scanf( %d , &(m));     for (int i = 0; i < MAXN; i++) {       cur = i;       dfs(i % 10, i / 10);     }     auto it = s.begin();     for (; it != s.end(); it++) printf( %08d n , *it);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int MAX = 400005;   const int MAX1 = 2007;   const int MAX2 = 4007;   const int LEN = 21;   const int BASE = 1000000000;   const double EPS = 1e-7;   const int MOD = 1234567891;   vector<pair<char, int> > vec;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ifstream in(  );     ofstream out(  );     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = (0); i < ((int)s.size()); ++i) {       vec.push_back(make_pair(s[i], i));     }     sort(vec.begin(), vec.end());     char ans[MAX];     memset(ans,   0 , sizeof(ans));     for (int i = (k); i < ((int)vec.size()); ++i) {       ans[vec[i].second] = vec[i].first;     }     for (int i = (0); i < (n); ++i) {       if (ans[i] !=   0 ) cout << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num;   int likes[7][7];   map<string, int> heroes;   int getNum(string s) {     if (!heroes.count(s)) heroes[s] = num++;     return heroes[s];   }   int getMaxSymp(int n1, int n2) {     vector<int> p, groups(7, 0);     for (int i = 0; i < 7; i++) {       p.push_back(i);       if (i >= n1) groups[i] = i < n1 + n2 ? 1 : 2;     }     int res = 0;     do {       int r = 0;       for (int i = 0; i < 7; i++)         for (int j = 0; j < 7; j++)           if (groups[i] == groups[j]) r += likes[p[i]][p[j]];       res = max(r, res);     } while (next_permutation(p.begin(), p.end()));     return res;   }   int main() {     int i, j, k, n, a, b, c, res = 2000000000, symp = 0;     cin >> n;     for (i = 0; i < n; i++) {       string s1, s2, s3;       cin >> s1 >> s3 >> s2;       likes[getNum(s1)][getNum(s2)] = 1;     }     cin >> a >> b >> c;     for (i = 1; i < 7; i++)       for (j = 1; j + i < 7; j++) {         k = 7 - i - j;         int d = max(a / i, max(b / j, c / k)) - min(a / i, min(b / j, c / k));         if (d < res)           res = d, symp = getMaxSymp(i, j);         else if (res == d)           symp = max(symp, getMaxSymp(i, j));       }     cout << res <<     << symp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long inv[5050 + 10], fac[5050 + 10], ifac[5050 + 10];   void setComb() {     inv[0] = 1;     inv[1] = 1;     fac[1] = 1;     ifac[1] = 1;     fac[0] = 1;     ifac[0] = 1;     for (int i = 2; i < 5050; i++) {       inv[i] = (-MOD / i) * inv[MOD % i] % MOD;       fac[i] = fac[i - 1] * i % MOD;       ifac[i] = ifac[i - 1] * inv[i] % MOD;       inv[i] = (inv[i] + MOD) % MOD;       fac[i] = (fac[i] + MOD) % MOD;       ifac[i] = (ifac[i] + MOD) % MOD;     }     return;   }   long long comb(long long n, long long k) {     if (n < k || n < 0 || k < 0)       return 0;     else       return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD);   }   long long hcomb(long long n, long long r) {     if (n == 0 && r == 0)       return 1;     else if (n < 0 || r < 0)       return 0;     else       return comb(n + r - 1, r - 1);   }   int N;   vector<int> A;   long long dp[5050][5050];   long long cnt[5050];   void add(long long &a, long long b) { a = (a + b) % MOD; }   void mul(long long &a, long long b) { a = a * b % MOD; }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> N;     A.resize(N);     for (int i = 0; i < (N); ++i) cin >> A[i];     sort(A.begin(), A.end());     for (int i = 0; i < (N); ++i) cnt[A[i]]++;     setComb();     dp[0][0] = 1;     for (int i = 0; i < N; i++) {       long long sum = 0;       for (int j = 0; j <= 5000; j++) {         long long res = sum;         mul(res, cnt[j]);         mul(res, inv[N - i]);         add(dp[i + 1][j], res);         sum += dp[i][j];       }     }     long long ans = 0;     for (int i = 1; i < N; i++) {       for (int j = 0; j <= 5000; j++) {         long long res = dp[i][j];         mul(res, cnt[j] - 1);         mul(res, inv[N - i]);         add(ans, res);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     vector<int>::iterator it;     int n, q, x, count1 = 0, x1;     cin >> q;     while (q--) {       cin >> n;       while (n--) {         cin >> x;         v.push_back(x);       }       it = v.end() - 1;       x1 = *it;       for (it = v.end() - 2; it >= v.begin(); it--) {         if (*it > x1)           count1++;         else           x1 = *it;       }       cout << count1 << endl;       count1 = 0;       v.clear();     }   }


#include <bits/stdc++.h>   long long ans;   int F[50000001], n, m, N;   char str[10001];   void dfs(int x, int bit, int key) {     if (x > 3) {       if (bit) F[bit] += key;       return;     }     dfs(x + 1, bit, key);     int v = str[x] -  a ;     dfs(x + 1, bit | (1 << v), -key);   }   int main() {     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %s , str + 1);       dfs(1, 0, -1);     }     n = 24;     N = 1 << n;     int res = 0;     for (int i = 0; i < N; i++) res += F[i];     for (int i = 1; i < N; i <<= 1)       for (int j = 0; j < N; j++)         if (i & j) {           F[j] += F[j - i];         }     for (int i = 0; i < N; i++) ans ^= (long long)F[i] * F[i];     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10, MAXM = 100;   int A[MAXN][MAXM], B[MAXN][MAXM], C[MAXN][MAXM];   int order[MAXM];   int ib, is;   bool cmp(int a, int b) { return B[is][a] - A[ib][a] > B[is][b] - A[ib][b]; }   int main() {     int n, m, k, ans = 0, tmp;     int cur_hold, nx, p;     int i, j, id;     scanf( %d%d%d , &n, &m, &k);     for (i = 0; i < n; ++i) {       scanf( %*s );       for (j = 0; j < m; ++j) scanf( %d%d%d , A[i] + j, B[i] + j, C[i] + j);     }     for (ib = 0; ib < n; ++ib)       for (is = 0; is < n; ++is)         if (ib != is) {           for (j = 0; j < m; ++j) order[j] = j;           sort(order, order + m, cmp);           for (tmp = cur_hold = j = 0; j < m; ++j) {             id = order[j];             if ((p = B[is][id] - A[ib][id]) > 0) {               nx = min(C[ib][id], k - cur_hold);               tmp += p * nx;               cur_hold += nx;             } else               break;           }           if (ans < tmp) ans = tmp;         }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init() {}   void _print(long long int t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long int t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long int round_up(long long int a, long long int b) {     return (a + b - 1) / b;   }   long long int gcd(long long int a, long long int b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long int expo(long long int a, long long int b, long long int mod) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   void extendgcd(long long int a, long long int b, long long int *v) {     if (b == 0) {       v[0] = 1;       v[1] = 0;       v[2] = a;       return;     }     extendgcd(b, a % b, v);     long long int x = v[1];     v[1] = v[0] - v[1] * (a / b);     v[0] = x;     return;   }   long long int mminv(long long int a, long long int b) {     long long int arr[3];     extendgcd(a, b, arr);     return arr[0];   }   long long int mminvprime(long long int a, long long int b) {     return expo(a, b - 2, b);   }   bool revsort(long long int a, long long int b) { return a > b; }   void swap(int &x, int &y) {     int temp = x;     x = y;     y = temp;   }   long long int combination(long long int n, long long int r, long long int m,                             long long int *fact, long long int *ifact) {     long long int val1 = fact[n];     long long int val2 = ifact[n - r];     long long int val3 = ifact[r];     return (((val1 * val2) % m) * val3) % m;   }   void google(int t) { cout <<  Case #  << t <<  :  ; }   vector<long long int> sieve(int n) {     int *arr = new int[n + 1]();     vector<long long int> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long int mod_add(long long int a, long long int b, long long int m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long int mod_mul(long long int a, long long int b, long long int m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long int mod_sub(long long int a, long long int b, long long int m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long int mod_div(long long int a, long long int b, long long int m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   void solve() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int sum = 0;       long long int ans = 0;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];         if (sum < 0) {           ans -= sum;           sum = 0;         }       }       cout << sum <<   n ;     }   }   int main() {     init();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long int b[100005], p[100005];   int n, m, a;   bool check(int x) {     int temp_a = a;     for (__typeof((x)) i = (0); i < (x); i += 1) {       int t = x - 1;       if (p[i] > b[t - i]) {         if (temp_a < p[i] - b[t - i]) {           return false;         } else {           temp_a -= p[i] - b[t - i];         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> a;     for (__typeof((n)) i = (0); i < (n); i += 1) {       cin >> b[i];     }     for (__typeof((m)) i = (0); i < (m); i += 1) {       cin >> p[i];     }     sort(b, b + n, greater<int>());     sort(p, p + m);     int l = 0, h = ((n) < (m) ? (n) : (m)), ans = 0;     while (l < h) {       int mid = (l + h + 1) / 2;       if (check(mid) == true) {         l = mid;       } else {         h = mid - 1;       }       ans = l;     }     int ans2 = 0;     for (__typeof((ans)) i = (0); i < (ans); i += 1) {       ans2 += p[i];     }     ans2 -= a;     if (ans2 < 0) {       ans2 = 0;     }     cout << ans <<     << ans2;   }


#include <bits/stdc++.h>   using namespace std;   long long a00, a01, a10, a11;   char *s;   bool isSquare(long long x, long long &res) {     long long t = sqrt(x);     for (long long i = max(t - 10, 1LL); i <= t + 10; i++) {       if (i * i == x) {         res = i;         return true;       }     }     return false;   }   bool getS(long long n0, long long n1, long long n) {     s = new char[n + 1];     long long A01 = a01, A10 = a10;     for (long long i = 0; i < n; i++) {       if (A01 - n1 >= 0) {         s[i] =  0 ;         n0 -= 1;         A01 -= n1;       } else if (A10 - n0 >= 0) {         s[i] =  1 ;         n1 -= 1;         A10 -= n0;       } else         return false;     }     s[n] =   0 ;     if (n0 != 0 || n1 != 0 || A01 != 0 || A10 != 0) return false;     return true;   }   bool solve() {     long long t;     if (!isSquare(1 + 8 * a00, t)) return false;     vector<long long> n0;     n0.push_back((1 + t) / 2);     n0.push_back((1 - t) / 2);     if (!isSquare(1 + 8 * a11, t)) return false;     vector<long long> n1;     n1.push_back((1 + t) / 2);     n1.push_back((1 - t) / 2);     for (auto i : n0)       for (auto j : n1) {         long long n = i + j;         if (i < 0 || j < 0 || n <= 0) continue;         if (!getS(i, j, n)) continue;         return true;       }     return false;   }   int main() {     while (cin >> a00 >> a01 >> a10 >> a11) {       bool can = solve();       printf( %s n , can ? s :  Impossible );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<long long>;   using pii = pair<long long, long long>;   const signed INF_ = 1001001001;   const long long INF = 1001001001001001001LL;   const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},                   DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto i = (begin(v)); i != (end(v)); ++i)       os << *i << (i == end(v) - 1 ?    :    );     return os;   }   template <class T>   istream &operator>>(istream &is, vector<T> &v) {     for (auto i = (begin(v)); i != (end(v)); ++i) is >> *i;     return is;   }   template <class T, class U>   istream &operator>>(istream &is, pair<T, U> &p) {     is >> p.first >> p.second;     return is;   }   template <class T, class U>   bool chmax(T &a, const U &b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   bool chmin(T &a, const U &b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   void PSUM(T &c) {     partial_sum(begin(c), end(c), begin(c));   }   template <class T>   using heap = priority_queue<T, vector<T>, greater<T>>;   struct before_main_function {     before_main_function() {       cin.tie(0);       ios::sync_with_stdio(0);       cout << setprecision(15) << fixed;     }   } before_main_function;   signed main() {     long long N, M;     cin >> N >> M;     vector<vector<long long>> g(N);     vector<long long> deg(N);     for (long long i = 0, ilen = (long long)(M); i < ilen; ++i) {       long long a, b;       cin >> a >> b;       a--, b--;       g[a].push_back(b);       g[b].push_back(a);       deg[a]++;       deg[b]++;     }     vector<pii> ans;     vector<bool> vis(N);     {       queue<long long> q;       long long st = max_element(begin(deg), end(deg)) - begin(deg);       q.push(st);       vis[st] = true;       while (q.size()) {         long long v = q.front();         q.pop();         for (auto &&w : g[v]) {           if (vis[w]) continue;           vis[w] = true;           ans.push_back({v + 1, w + 1});           q.push(w);         }       }     }     for (auto &&p : ans) {       cout << p.first <<     << p.second << endl;     }     return (0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   int rep[2000005];   int sz[2000005];   void dsu(int n) {     for (int i = 0; i < n; i++) rep[i] = i, sz[i] = 1;   }   int findSet(int a) { return ((rep[a] == a) ? a : rep[a] = findSet(rep[a])); }   int mergeSet(int a, int b) {     int y = findSet(b);     int x = findSet(a);     if (x != y) {       rep[x] = y;       sz[y] += sz[x];       sz[x] = 0;     }   }   long long int grid[1005][1005];   int vis[1005][1005] = {0};   vector<pair<long long int, pair<int, int> > > v;   int n, m;   long long int k;   int dx[] = {-1, 0, 0, 1};   int dy[] = {0, -1, 1, 0};   int solx = -1;   int soly = -1;   long long int sol;   int cnt;   void floodfill(int x, int y) {     if (cnt < 1) return;     vis[x][y] = 1;     grid[x][y] = sol;     cnt--;     for (int i = 0; i < 4; i++) {       int newx = x + dx[i];       int newy = y + dy[i];       if (newx >= 0 && newx < n && newy >= 0 && newy < m && !vis[newx][newy] &&           grid[newx][newy] >= sol) {         floodfill(newx, newy);       }     }   }   void solve() {     cin >> n >> m;     cin >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         v.push_back(make_pair(grid[i][j], make_pair(i, j)));       }     }     sort(v.begin(), v.end(), greater<pair<long long int, pair<int, int> > >());     dsu(n * m);     int i = 0, j = 0;     while (i < v.size()) {       j = i;       while (j < v.size()) {         if (v[i].first == v[j].first) {           int x = v[j].second.first;           int y = v[j].second.second;           for (int k = 0; k < 4; k++) {             int newx = x + dx[k];             int newy = y + dy[k];             if (newx >= 0 && newx < n && newy >= 0 && newy < m &&                 grid[newx][newy] >= v[j].first) {               mergeSet(newx * m + newy, x * m + y);             }           }         } else           break;         j++;       }       for (int l = i; l < j; l++) {         if (v[l].first && (k % v[l].first == 0) &&             sz[findSet(v[l].second.first * m + v[l].second.second)] >=                 k / v[l].first) {           solx = v[l].second.first;           soly = v[l].second.second;           sol = v[l].first;           cnt = k / v[l].first;           break;         }       }       i = j;     }     if (solx == -1 || soly == -1)       cout <<  NO n ;     else {       floodfill(solx, soly);       cout <<  YES n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m - 1; j++) {           if (vis[i][j])             cout << grid[i][j] <<    ;           else             cout <<  0  ;         }         if (vis[i][m - 1])           cout << grid[i][m - 1] <<   n ;         else           cout <<  0 n ;       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int k = 0;     while (1) {       k++;       if (k % m == 0) n++;       n--;       if (n == 0) break;     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   int edges[MAXN] = {0};   int main() {     int n, s;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       edges[a]++, edges[b]++;     }     int amt = 0;     for (int i = 0; i < n; i++) {       if (edges[i] == 1) amt++;     }     double ans = ((double)s) / ((double)amt);     cout << fixed << setprecision(10) << ans * 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int v[100];   bool cmp(int a, int b) { return a > b; }   int highest(int n) {     int i = 1, fact = 0;     while (2 * i <= n) {       i *= 2;       fact++;     }     return fact;   }   void permute(int left, int right, int pos, int last) {     if (!pos || (!last && pos == 1)) return;     int t = highest(pos);     pos -= (1 << t);     if (!last) {       left = right - t - 1;       swap(v[left + 1], v[right]);       sort(v + left + 2, v + right, cmp);       permute(left, right, pos, t);       return;     }     swap(v[left], v[right]);     --right;     if (last - t != 1) {       ++left;       sort(v + left, v + right + 1);       permute(left, right, pos + (1 << t), 0);       return;     }     permute(left, right, pos, t);   }   int main() {     int n, m, num = 1, piv = 0, pos, t;     cin >> n >> m;     for (int i = 0; i < n; ++i) v[i] = i + 1;     permute(0, n - 1, m, 0);     for (int i = 0; i < n; ++i) cout << v[i] <<    ;     return 0;   }