#include <bits/stdc++.h>   using namespace std;   template <class T>   void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   static void redirect(int argc, const char **argv) {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (argc > 1) {       static filebuf f;       f.open(argv[1], ios::in);       cin.rdbuf(&f);       if (!cin) {         cerr <<  Failed to open    << argv[1] <<     << endl;         exit(1);       }     }     if (argc > 2) {       static filebuf f;       f.open(argv[2], ios::out | ios::trunc);       cout.rdbuf(&f);       if (!cout) {         cerr <<  Failed to open    << argv[2] <<     << endl;       }     }   }   class UnionFind {    private:     mutable std::vector<int> parent;       public:     explicit UnionFind(int size = 0) : parent(size, -1) {}     int size() const { return parent.size(); }     int find(int x) const {       assert(x >= 0 && x < size());       int y = x;       while (parent[y] >= 0) y = parent[y];       while (parent[x] >= 0) {         int nxt = parent[x];         parent[x] = y;         x = nxt;       }       return y;     }     bool merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return false;       if (-parent[x] > -parent[y]) std::swap(x, y);       parent[y] += parent[x];       parent[x] = y;       return true;     }     int component_size(int x) const { return -parent[find(x)]; }   };   template <typename T, typename C, T Modulus>   class MR {    private:     struct tag_plus {};     struct tag_minus {};     struct tag_good {};     T value;     static_assert(std::numeric_limits<C>::max() / Modulus / Modulus > 0,                    compute type is too small );     static_assert(Modulus < std::numeric_limits<T>::max() / 2,                    storage type is too small );     void reduce(tag_plus) {       if (value >= Modulus) value -= Modulus;     }     void reduce(tag_minus) {       if (value < 0) value += Modulus;     }     void reduce(tag_good) {}       public:     static const T modulus = Modulus;     MR() : value(0) {}     MR(C value) : value(value % Modulus) { reduce(tag_minus()); }     template <typename tag_t>     MR(T value, tag_t tag) : value(value) {       reduce(tag);     }     MR &operator=(C value) {       this->value = value % Modulus;       reduce(tag_minus());       return *this;     }     MR operator+(MR b) const { return MR(value + b.value, tag_plus()); }     MR operator-(MR b) const { return MR(value - b.value, tag_minus()); }     MR operator*(MR b) const {       return MR(C(value) * C(b.value) % Modulus, tag_good());     }     MR operator-() const { return MR(-value, tag_minus()); }     MR &operator+=(MR b) {       value += b.value;       reduce(tag_plus());       return *this;     }     MR &operator-=(MR b) {       value -= b.value;       reduce(tag_minus());       return *this;     }     MR &operator*=(MR b) {       value = C(value) * C(b.value) % Modulus;       return *this;     }     bool operator==(MR b) const { return value == b.value; }     bool operator!=(MR b) const { return value != b.value; }     T get() const { return value; }   };   static inline int bit(int x) { return 1 << x; }   static int min_colours(const vector<int> &edges) {     int N = ((long long)(edges).size());     int M = 1 << N;     vector<MR<int, long long, 1000000009> > a(M);     a[0] = 1;     for (int i = 1; i < M; i++) {       int v = __builtin_ctz(i);       a[i] = a[i & ~bit(v)] + a[i & ~bit(v) & ~edges[v]];     }     vector<MR<int, long long, 1000000009> > ak(M,                                                MR<int, long long, 1000000009>(1));     for (int k = 1;; k++) {       MR<int, long long, 1000000009> sum = 0;       for (int i = 0; i < M; i++) {         ak[i] *= a[i];         sum += __builtin_parity(i) ? ak[i] : -ak[i];       }       if (sum.get() != 0) return k;     }   }   int main(int argc, const char **argv) {     redirect(argc, argv);     int N;     cin >> N;     vector<string> matrix(N);     UnionFind scc(N);     for (int i = 0; i < N; i++) {       cin >> matrix[i];       for (int j = 0; j < i; j++)         if (matrix[i][j] ==  A ) scc.merge(i, j);     }     vector<pair<int, int> > comps;     for (int i = 0; i < N; i++)       if (i == scc.find(i)) comps.emplace_back(scc.component_size(i), i);     sort(begin(comps), end(comps));     reverse(begin(comps), end(comps));     vector<int> cmap(N);     int C = ((long long)(comps).size());     int C2 = 0;     while (C2 < C && comps[C2].first >= 2) C2++;     for (int i = 0; i < C; i++) cmap[comps[i].second] = i;     C = C2;     vector<int> edge(C);     for (int i = 0; i < N; i++)       for (int j = 0; j < i; j++)         if (matrix[i][j] ==  X ) {           int p = cmap[scc.find(i)];           int q = cmap[scc.find(j)];           if (p == q) {             cout <<  -1 n ;             return 0;           }           if (p < C && q < C) {             edge[p] |= bit(q);             edge[q] |= bit(p);           }         }     int mc = C2 ? min_colours(edge) : 0;     cout << N - 1 + mc <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000 + 10];   int ret[21][21];   int pool[410], two[100];   int main() {     ios::sync_with_stdio(false);     memset(a, 0, sizeof(a));     memset(ret, 0, sizeof(ret));     memset(pool, 0, sizeof(pool));     memset(two, 0, sizeof(two));     int n;     cin >> n;     int t, tag = 0, tt = 0;     for (int i = 0; i < n * n; i++) {       cin >> t;       a[t]++;     }     if (n == 1) {       cout <<  yes             <<   n ;       cout << t <<   n ;       return 0;     }     if (n % 2) {       int cnt = 0;       for (int i = 1; i <= 1000; i++) {         if (a[i] % 4) {           if (a[i] % 2) {             if (cnt == 0) {               ret[n / 2][n / 2] = i;               a[i]--;               cnt = 1;             } else {               cout <<  no                     <<   n ;               return 0;             }           }           if (a[i] % 4) {             two[tt++] = i;             a[i] -= 2;             if (tt > (n - 1)) {               cout <<  no                     <<   n ;               return 0;             }           }         }         while (a[i] > 0) {           pool[tag++] = i;           a[i] -= 4;         }       }       while (tt < (n - 1)) {         two[tt++] = pool[--tag];         two[tt++] = pool[tag];       }       int cnt2 = 0, cnt4 = 0;       for (int i = 0; i * 2 < n; i++) {         for (int j = 0; j * 2 < n; j++) {           if (i == n / 2 && j == n / 2) continue;           if (i == n / 2) {             ret[i][j] = two[cnt2++];             ret[i][n - j - 1] = ret[i][j];           } else if (j == n / 2) {             ret[i][j] = two[cnt2++];             ret[n - i - 1][j] = ret[i][j];           } else {             ret[i][j] = pool[cnt4++];             ret[n - i - 1][n - j - 1] = ret[i][j];             ret[i][n - j - 1] = ret[i][j];             ret[n - i - 1][j] = ret[i][j];           }         }       }     } else {       bool can = true;       for (int i = 1; i <= 1000; i++) {         if (a[i] % 4) {           cout <<  no                 <<   n ;           return 0;         }         while (a[i] > 0) {           pool[tag++] = i;           a[i] -= 4;         }       }       for (int i = 0; i * 2 < n; i++) {         for (int j = 0; j * 2 < n; j++) {           ret[i][j] = pool[i * n / 2 + j];           ret[n - i - 1][n - j - 1] = ret[i][j];           ret[i][n - j - 1] = ret[i][j];           ret[n - i - 1][j] = ret[i][j];         }       }     }     cout <<  yes           <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << ret[i][j];         if (j == n - 1)           cout <<   n ;         else           cout <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (a < b) swap(a, b);     cout << b <<     << (a - b) / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct player {     string name;     long long point;     player() {}     player(string n, long long p) { name = n, point = p; }     bool operator<(const player &p) const {       if (point == p.point) {         return name < p.name;       }       return point > p.point;     }   };   vector<player> vec, tmp;   vector<long long> prize;   long long n, m, x;   string str;   int index_of() {     for (int i = 0; i < vec.size(); i++) {       if (tmp[i].name == str) return i;     }   }   int find_first_pos(int in) {     int j = 0;     for (int i = in; i < tmp.size() && j < prize.size(); i++, j++) {       tmp[i].point += prize[j];     }     for (int i = in - 1; i >= 0 && j < prize.size(); i--, j++) {       tmp[i].point += prize[j];     }     sort(tmp.begin(), tmp.end());     return index_of() + 1;   }   int find_last_pos(int in) {     tmp = vec;     if (prize.size() >= tmp.size()) {       tmp[in].point += prize[tmp.size() - 1];     }     int j = 0;     for (int i = tmp.size() - 1; i >= 0 && j < prize.size(); i--) {       if (i != in) {         player p(tmp[i].name, tmp[i].point + prize[j]);         if (p < tmp[in]) {           tmp[i].point += prize[j];           j++;         }       }     }     sort(tmp.begin(), tmp.end());     return index_of() + 1;   }   bool func(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> str >> x;         vec.push_back(player(str, x));       }       sort(vec.begin(), vec.end());       cin >> m;       for (int i = 0; i < m; i++) {         cin >> x;         prize.push_back(x);       }       sort(prize.begin(), prize.end(), func);       cin >> str;       tmp = vec;       long long in = index_of();       long long fir, sec;       fir = find_first_pos(in);       sec = find_last_pos(in);       cout << fir <<     << sec << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct cub {     int c, h;   } nr[100100];   vector<int> axnorm;   vector<pair<int, int> > cul[100100];   struct cmp {     bool operator()(pair<int, int> a, pair<int, int> b) {       return (a.first > b.first);     }   };   priority_queue<pair<long long, int> > H[100100];   int N, C;   int culoare1, culoare2, nrcub1, nrcub2;   long long solutie;   int caut(int x) {     int p = -1, u = C, mij;     while (u - p > 1) {       mij = (p + u) / 2;       if (axnorm[mij] < x)         p = mij;       else         u = mij;     }     if (u == C || axnorm[u] != x) return -1;     return u;   }   void prec() {     long long sum;     for (int i = 1; i <= C; ++i) {       sum = 0;       sort(cul[i].begin(), cul[i].end(), cmp());       for (size_t j = 0; j < cul[i].size(); ++j) {         sum = (long long)(sum + cul[i][j].first);         H[(int)(j + 1)].push(pair<long long, int>(sum, i));       }     }   }   void solve() {     sort(axnorm.begin(), axnorm.end());     axnorm.erase(unique(axnorm.begin(), axnorm.end()), axnorm.end());     C = (int)axnorm.size();     int i, cc, cc1;     long long s, s1;     for (i = 1; i <= N; ++i)       cul[caut(nr[i].c) + 1].push_back(pair<int, int>(nr[i].h, i));     prec();     for (i = 1; i <= N; ++i) {       if (H[i].size() < 2) break;       s = H[i].top().first;       cc = H[i].top().second;       H[i].pop();       if (solutie < s + H[i].top().first) {         solutie = s + H[i].top().first;         culoare1 = cc;         culoare2 = H[i].top().second;         nrcub1 = nrcub2 = i;       }       H[i].push(pair<long long, int>(s, cc));     }     for (i = 2; i <= N; ++i) {       if (!H[i].size()) break;       s = H[i].top().first;       cc = H[i].top().second;       H[i].pop();       s1 = H[i - 1].top().first;       cc1 = H[i - 1].top().second;       H[i - 1].pop();       if (cc == cc1) {         if (H[i].size() > 0) {           if (solutie < s1 + H[i].top().first) {             solutie = s1 + H[i].top().first;             culoare1 = H[i].top().first;             culoare2 = cc1;             nrcub1 = i;             nrcub2 = i - 1;           }         }         if (H[i - 1].size() > 0) {           if (solutie < s + H[i - 1].top().first) {             solutie = s + H[i - 1].top().first;             culoare1 = cc1;             culoare2 = H[i - 1].top().second;             nrcub1 = i;             nrcub2 = i - 1;           }         }       } else {         if (solutie < s + s1) {           solutie = s + s1;           culoare1 = cc;           culoare2 = cc1;           nrcub1 = i;           nrcub2 = i - 1;         }       }       H[i].push(pair<long long, int>(s, cc));       H[i - 1].push(pair<long long, int>(s1, cc1));     }   }   void afis() {     size_t x, y;     x = y = 0;     cout << solutie <<   n ;     cout << nrcub1 + nrcub2 <<   n ;     while (nrcub1 || nrcub2) {       if (nrcub1 > nrcub2) {         cout << cul[culoare1][x].second <<    ;         ++x;         --nrcub1;       } else {         cout << cul[culoare2][y].second <<    ;         ++y;         --nrcub2;       }     }   }   int main() {     int i;     scanf( %d , &N);     for (i = 1; i <= N; ++i) {       scanf( %d%d , &nr[i].c, &nr[i].h);       axnorm.push_back(nr[i].c);     }     solve();     afis();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, net, i, flag, d;     string str;     cin >> n;     net = 0;     flag = 0;     for (i = 0; i < n; i++) {       cin >> d;       cin >> str;       if ((net == 0) && (str !=  South )) flag = 1;       if ((net == 20000) && (str !=  North )) flag = 1;       if (str ==  South )         net += d;       else if (str ==  North )         net -= d;       if (net > 20000 || net < 0) flag = 1;     }     if (net != 0) flag = 1;     if (flag == 1)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     puts( 1 );     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e6 + 5;   std::vector<int> G[MAXN];   int f[MAXN][26];   void dfs(int v) {     for (register int i = 1; i <= 20; ++i) {       f[v][i] = f[f[v][i - 1]][i - 1];     }     for (auto x : G[v]) {       if (x == f[v][0]) continue;       f[x][0] = v;       dfs(x);     }   }   int n, k;   bool vis[MAXN];   int main() {     scanf( %d%d , &n, &k);     for (register int i = 1; i <= n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     int res = n - k;     f[n][0] = n;     dfs(n);     vis[n] = true;     res--;     for (register int i = n - 1; i >= 1; --i) {       if (vis[i]) continue;       int len = 1, v = i;       for (register int j = 20; j >= 0; --j) {         if (vis[f[v][j]]) continue;         v = f[v][j];         len += (1 << j);       }       if (len <= res) {         res -= len;         int x = i;         while (true) {           if (vis[x]) break;           vis[x] = 1;           x = f[x][0];         }       }     }     for (register int i = 1; i <= n; ++i)       if (!vis[i]) printf( %d  , i);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, x;     cin >> n >> x;     long int sum = 0, zz;     for (int i = 0; i < n; i++) cin >> zz, sum += zz;     if (sum + n - 1 == x)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct qeury {     int a, b, c;   };   const int N = 5000 + 5;   int ans[N][N];   int r[N], cc[N];   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     vector<qeury> q;     int a, b, c;     for (int i = 0; i < k; i++) {       cin >> a >> b >> c;       q.push_back({a, b, c});     }     reverse(q.begin(), q.end());     for (int i = 0; i < q.size(); i++) {       a = q[i].a;       b = q[i].b - 1;       c = q[i].c;       if (a == 1) {         if (!r[b]) {           r[b] = 1;           for (int j = 0; j < m; j++) {             if (!ans[b][j]) {               ans[b][j] = c;             }           }         }       } else {         if (!cc[b]) {           cc[b] = 1;           for (int j = 0; j < n; j++) {             if (!ans[j][b]) {               ans[j][b] = c;             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j];         if (j < m - 1) cout <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e6 + 5;   const int MOD = 998244353;   long long lgput(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) {         r = 1LL * r * b % MOD;       }       p >>= 1;       b = b * b % MOD;     }     return r;   }   long long N;   vector<long long> lista[NMAX + 5];   long long good_kids[NMAX + 5];   long long cati[NMAX + 5];   long long total = 0, special = 0;   long long answer = 0;   void solve() {     cin >> N;     for (long long i = 1; i <= N; ++i) {       cin >> cati[i];       for (long long j = 1; j <= cati[i]; ++j) {         long long x;         cin >> x;         good_kids[x]++;         lista[i].push_back(x);       }       total = (total + 1LL * N * cati[i] % MOD) % MOD;     }     for (long long i = 1; i <= N; ++i) {       for (auto gift : lista[i]) {         long long expected =             1LL * lgput(N, MOD - 2) * lgput(cati[i], MOD - 2) % MOD;         expected =             1LL * expected * lgput(N, MOD - 2) % MOD * good_kids[gift] % MOD;         answer = (answer + expected) % MOD;       }     }     cout << answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (b < a * 2) {       cout <<  NO ;       return 0;     }     cout <<  YES  <<   n ;     for (int i = 0; i < a - 1; i++) cout << 2 <<    ;     cout << b - 2 * (a - 1) <<   n ;     cout << 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 4, Mod = 1e9 + 7;   struct Mint {     int res;     Mint() { res = 0; }     Mint(int a) : res(a) {}     friend Mint operator+(Mint A, Mint B) {       return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod)                                          : (A.res + B.res));     }     friend Mint& operator+=(Mint& A, Mint B) { return A = A + B; }     friend Mint operator-(Mint A, Mint B) {       B.res = Mod - B.res;       return A + B;     }     friend Mint operator-(Mint A) { return Mint(Mod - A.res); }     friend Mint operator+(Mint A) { return A; }     friend Mint& operator-=(Mint& A, Mint B) { return A = A - B; }     friend Mint operator*(Mint A, Mint B) { return 1ll * A.res * B.res % Mod; }     friend Mint& operator*=(Mint& A, Mint B) { return A = A * B; }     friend Mint operator~(Mint A) {       static Mint res;       res = Mint(1);       static int k;       k = Mod - 2;       for (; k; k >>= 1, A *= A) (k & 1) && (res = res * A, 0);       return res;     }     friend Mint operator/(Mint A, Mint B) { return A * (~B); }     friend Mint& operator/=(Mint& A, Mint B) { return A *= (~B); }     friend Mint operator>>(Mint A, Mint B) { return Mint(A.res / B.res); }     friend Mint& operator>>=(Mint& A, Mint B) { return A = A >> B; }   };   Mint fac[N], ifac[N];   inline Mint C(int n, int k) { return fac[n] * ifac[n - k] * ifac[k]; }   int n, k;   Mint dp[N], pre[N];   int main() {     scanf( %d%d , &n, &k);     fac[0] = Mint(1);     for (register int i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * Mint(i);     ifac[n] = ~fac[n];     for (register int i = (n - 1); i >= (0); --i)       ifac[i] = ifac[i + 1] * Mint(i + 1);     dp[0] = pre[0] = Mint(1);     for (register int i = (1); i <= (n - 1); ++i)       dp[i] =           (pre[i - 1] - ((i - k > 0) ? pre[i - k - 1] : Mint(0))) * fac[i - 1],       pre[i] = pre[i - 1] + dp[i] * ifac[i];     Mint res;     for (register int i = (1); i <= (n); ++i)       res += dp[i - 1] * fac[n - i] * C(n - 1, n - i);     printf( %d n , (fac[n] - res).res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     int n;     cin >> n;     vector<int> indeg(n);     queue<int> deg1;     vector<int> xorV(n);     for (int i = 0; i < n; i++) {       cin >> indeg[i] >> xorV[i];       if (indeg[i] == 1) deg1.push(i);     }     set<pair<int, int> > edges;     while (deg1.size() > 0) {       int v = deg1.front();       deg1.pop();       int u = xorV[v];       if (--indeg[u] == 1) deg1.push(u);       if (indeg[u] > 0) xorV[u] ^= v;       if (v > u) swap(u, v);       edges.insert({u, v});     }     cout << edges.size() << endl;     for (auto &edg : edges) {       cout << edg.first <<     << edg.second << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   unsigned int ip[100005];   unsigned int const one = -1;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       unsigned int a, b, c, d;       scanf( %u.%u.%u.%u , &a, &b, &c, &d);       ip[i] = (a << 24) + (b << 16) + (c << 8) + d;     }     unsigned int mask = 0;     set<unsigned int> S;     for (int i = 1; i < 32; i++) {       mask = one << (32 - i);       for (int j = 0; j < n; j++) {         S.insert(mask & ip[j]);       }       if (S.size() == k) {         unsigned int a, b, c, d;         a = mask >> 24;         b = (mask << 8) >> 24;         c = (mask << 16) >> 24;         d = (mask << 24) >> 24;         printf( %u.%u.%u.%u , a, b, c, d);         return 0;       }       S.clear();     }     cout << -1;     return 0;   }


// Murabito-B 21/04/13   #include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve() {       int a, b, c;       cin >> a >> b >> c;       for (int i = 0; i <= a - c; ++i) cout << 1;       for (int i = 1; i < c; ++i) cout << 0;       cout <<   1 ;       for (int i = 1; i < b; ++i) cout << 0;       cout <<   n ;   }   int main() {       ios_base::sync_with_stdio(false), cin.tie(0);       int _;       for (cin >> _; _--;) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long M = 1e9 + 7;   const long long N = 5e5;   const long long INF = 1e9 + 1;   long long n, a[N], x[N], res, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int j = 1; j <= n; ++j) {       for (int i = 1; i <= n; ++i) {         if (x[i] != 1 && ans >= a[i]) {           x[i] = 1;           ans++;         }       }       if (ans == n) {         break;       }       res++;       for (int i = n; i >= 1; --i) {         if (x[i] != 1 && ans >= a[i]) {           x[i] = 1;           ans++;         }       }       if (ans == n) {         break;       }       res++;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long logg(long long x, long long y) {     if (x == 0) return -1;     return logg(x / y, y) + 1;   }   long long poww(long long a, long long b, long long m) {     if (b == 0) return 1;     long long ans = 1;     ans = poww(a, b >> 1, m);     ans = (ans * ans) % m;     if (b & 1) ans = (ans * a) % m;     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     long long a[n], b[n];     for (long long i = 0; i < n; i++) cin >> a[i], b[i] = a[i];     sort(b, b + n, greater<long long>());     long long sum = 0;     map<long long, long long> mp;     for (long long i = 0; i < k; i++) sum += b[i], mp[b[i]]++;     long long count = 0;     vector<long long> ans;     for (long long i = 0; i < n; i++) {       if (k == 1) {         ans.push_back(n - i);         break;       }       if (mp.count(a[i]))         count++, ans.push_back(count), count = 0, mp[a[i]]--, k--;       else         count++;       if (mp[a[i]] == 0) mp.erase(a[i]);     }     cout << sum <<   n ;     for (auto i : ans) cout << i <<    ;   }


#include<bits/stdc++.h>   using namespace std;      #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define int long long   #define line cout<< [At  <<__LINE__<< ] <<endl;   #define size(x) ((int)x.size())      namespace Debug{     void __print(signed x){cout << x;}     void __print(long x){cout << x;}     void __print(long long x){cout << x;}     void __print(unsigned x){cout << x;}     void __print(unsigned long x){cout << x;}     void __print(unsigned long long x){cout << x;}     void __print(float x){cout << x;}     void __print(double x){cout << x;}     void __print(long double x){cout << x;}     void __print(char x){cout <<      << x <<     ;}     void __print(const char *x){cout <<     << x <<    ;}     void __print(const string &x){cout <<     << x <<    ;}     void __print(bool x){cout << (x ?  true  :  false );}     template<typename T, typename V> void __print(const pair<T, V> &x){cout <<  { ;__print(x.first);cout <<  , ;__print(x.second);cout <<  } ;}     template<typename T> void __print(const T &x){int f = 0;cout <<  { ;for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);cout <<  } ;}     void _print(){cout <<  ] <<endl;}     template <typename T, typename... V> void _print(T t, V... v){__print(t);if (sizeof...(v)) cout <<  ,  ;_print(v...);}          #define debug(x...) cout << Line: <<__LINE__<<   [  << #x <<  ] = [ ; _print(x);     #define deb(x...) cout << [  << #x <<  ] = [ ; _print(x);   }using namespace Debug;         const int mod = (int)1e9 + 7ll;      int dp[2000][2000][2], n;      int shoot(int plane, int k, int dir){    if(plane > n || plane < 1 || k == 1)     return 1l;        if(dp[plane][k][dir] != -1)      return dp[plane][k][dir];        int res = 0l;        if(dir == 0){      res = shoot(plane + 1, k, dir);      res += shoot(plane - 1, k - 1, 1 - dir);     }     else{      res = shoot(plane - 1, k, dir);      res += shoot(plane + 1, k - 1, 1 - dir);     }        res %= mod;     return dp[plane][k][dir] = res;   }      void process(){    int k;    cin >> n >> k;    cout << shoot(1, k, 0) <<   n ;   }      signed main() {    IOS;    int t = 1;    cin >> t;    while(t--){     memset(dp, -1, sizeof(dp));     process();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c, a, b;   int main() {     scanf( %d , &n);     while (n--) {       scanf( %d%d , &a, &b);       if (a != b)         if (a > b)           m++;         else           c++;     }     if (m != c)       if (m > c)         printf( Mishka );       else         printf( Chris );     else       printf( Friendship is magic!^^ );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     stringstream ss;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       switch (s[i]) {         case  > :           ss << 1000;           break;         case  < :           ss << 1001;           break;         case  + :           ss << 1010;           break;         case  - :           ss << 1011;           break;         case  . :           ss << 1100;           break;         case  , :           ss << 1101;           break;         case  [ :           ss << 1110;           break;         case  ] :           ss << 1111;           break;         default:           break;       }     }     string ans = ss.str();     int os = 1;     long long jawab = 0;     for (int i = ans.length() - 1; i >= 0; i--) {       if (ans[i] ==  1 ) jawab = (jawab + os) % 1000003;       os = (os * 2) % 1000003;     }     cout << jawab << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-9;   const int MOD = 1000000007;   const int INF = 1000000000;   const long long LINF = 1000000000000000000LL;   int main() {     int r, h, ret, m, x;     scanf( %d %d , &r, &h);     r *= 2, h *= 2, ret = h / r * 2, m = h % r, x = m + r / 2;     if (m >= r / 2) ret += 2, x -= r;     if ((0.5 * r * (sqrt(3.0) + 1.0) - 1.0 * x - 1.0 * r) < EPS) ret++;     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct ask {     int l, r, cur;   } tmp;   long long pre[maxn], suf[maxn], s[maxn], d[maxn], h[maxn], ans[maxn];   vector<ask> V, W;   int n, m, a, b;   long long solve(int l, int r, vector<ask> &V) {     if (l == r) return 0;     int mid = (l + r) >> 1;     long long best;     vector<ask> Vl, Vr, Vt;     pre[mid] = 0;     for (int i = (mid + 1); i <= int(r); i++)       pre[i] = max(pre[i - 1], s[i] - s[mid] + 2 * h[i]);     suf[mid + 1] = 0;     for (int i = (mid); i >= (l); i--)       suf[i] = max(suf[i + 1], s[mid] - s[i] + 2 * h[i]);     for (auto x : V)       if (x.r <= mid)         Vl.push_back(x);       else if (mid + 1 <= x.l)         Vr.push_back(x);       else if (l != x.l || r != x.r) {         ans[x.cur] = max(ans[x.cur], suf[x.l] + pre[x.r]);         Vl.push_back((ask){x.l, mid, x.cur});         Vr.push_back((ask){mid + 1, x.r, x.cur});       }     best = pre[r] + suf[l];     best = max(best, solve(l, mid, Vl));     best = max(best, solve(mid + 1, r, Vr));     for (auto x : V)       if (l == x.l && r == x.r) ans[x.cur] = max(ans[x.cur], best);     return best;   }   void solve2() {     pre[0] = 0;     for (int i = (1); i <= int(n); i++)       pre[i] = max(pre[i - 1], s[i] - s[1] + 2 * h[i]);     suf[n + 1] = 0;     for (int i = (n); i >= (1); i--)       suf[i] = max(suf[i + 1], s[n + 1] - s[i] + 2 * h[i]);     for (auto x : W) ans[x.cur] = max(ans[x.cur], pre[x.l] + suf[x.r]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= int(n); i++)       scanf( %I64d , &d[i]), s[i + 1] = s[i] + d[i];     for (int i = (1); i <= int(n); i++) scanf( %I64d , &h[i]);     for (int i = (1); i <= int(m); i++) {       scanf( %d%d , &a, &b);       if (a <= b) {         if (3 <= a) V.push_back((ask){1, a - 1, i});         if (b <= n - 2) V.push_back((ask){b + 1, n, i});         if (2 <= a && b <= n - 1) W.push_back((ask){a - 1, b + 1, i});       } else         V.push_back((ask){b + 1, a - 1, i});     }     solve(1, n, V);     solve2();     for (int i = (1); i <= int(m); i++) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   #define int long long   #define ld long double   #define vc vector   #define s second   #define f first         //#include  prettyprint.hpp       using namespace std;         typedef pair <int, int> pii;   int n, m;   int t(int a){       return a+n;   }   int mod=998244353;   vc< vc <int> > anz, suf, pref;      bool g (int a, int b){       if (a<0 || b<0) return false;       if (a >n || b >=m) return false;       return true;   }      int h (int a, int b){       if (a<0 || a>n) return 1;       return 0;   }      int an(int a ,int b){       return g(a, b)? anz[a][b] : h(a, b);   }      int su(int a ,int b){       return g(a, b)? suf[a][b] : h(a, b);   }      int pre(int a ,int b){       return g(a, b)? pref[a][b] : h(a, b);   }   int plu (int & a, int b){       return a =(a+b)%mod;   }      int mult (int a, int b){       return a*b % mod;   }      int calc_inst(int i, int j){       int s1 = mult(mult(an(i, j), an(n-i+1, j-1)), su(n-i, m-j));          int s2 = mult(mult(an(i, j), an(i+1, m-j-1)), pre(i, m-j+1));          return plu(s1, s2);      }   int do_calc(){       anz = suf = pref = vc <vc <int> > (n+1, vc <int > (m+1));          vc <vc <int > > b (n+1, vc <int> (m)), c (n+1, vc <int> (m));          anz[0][0] = 1;             for (int i=1; i<=n; i++){          anz[i][0] = anz[i-1][0];           for (int j=1; j<m; j++){               anz[i][j] = (anz[i][j-1]+anz[i-1][j])%mod;           }       }       for (int i=1; i<=n; i++){           for (int j=1; j<m; j++){               b[i][j] = anz[i][j]*anz[n-i+1][j-1] % mod;               suf[i][j] = (suf[i-1][j]+b[i][j])%mod;           }          }             for (int i=1; i<n; i++){           for (int k=m-1; k>=2; k--){               c[i][k] = anz[n-i][k]*anz[n-i+1][m-k-1]%mod;               pref[i][k]=(pref[i][k+1]+c[i][k])%mod;           }          }                int ret = 0;       for (int i=1; i<=n; i++){           for (int j=1; j<m; j++){               plu(ret, calc_inst(i, j));           }       }       return ret;      }      void do_test(){             cin >> n >> m;       int res= do_calc();       //a1 = very_balanced();      // cout << res <<   n ;       //swap(n, m);     //  a2 = very_balanced();      // res1=do_calc();       //assert(a1 == a2);   //a1 = (n-1)*(m-1);          res = 2*res%mod;         // cout <<  res1   << res1 <<     << res2 <<   a   << a1 <<      << a2 <<     << endl;          cout << res <<   n ;          //cout << a << endl;      }   signed main(){       ios_base::sync_with_stdio(false);             do_test();   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());   int a[105], vis[105];   vector<int> v[105];   int main() {     int n;     cin >> n;     for (int i = 1; i <= 2 * n; ++i) cin >> a[i];     int ans = 0;     for (int i = 1; i <= 2 * n; ++i) {       if (vis[a[i]]) continue;       vis[a[i]] = 1;       for (int j = i + 1; a[j] != a[i]; ++j)         if (!vis[a[j]]) ++ans;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   const int maxn = 1e6;   const int INF = 0x3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   using namespace std;   struct node {     int a, b, color;   } edge[maxn];   int n, m, ans;   int vis[maxn];   vector<int> v[maxn];   void dfs(int x, int fa) {     if (vis[x]) {       if (x == fa) ans = 2;       return;     }     vis[x] = 1;     for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], fa);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[i].a = a;       edge[i].b = b;       edge[i].color = 1;       v[a].push_back(b);     }     ans = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) vis[j] = 0;       dfs(i, i);     }     cout << ans << endl;     if (ans == 1) {       for (int i = 0; i < m; i++) cout << 1 <<    ;       cout << endl;     } else {       for (int i = 1; i <= m; i++) {         if (edge[i].a < edge[i].b) edge[i].color = 2;       }       for (int i = 1; i <= m; i++) cout << edge[i].color <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > q1, q2;   int x[200005];   int main() {     int n, z, ans = 0;     cin >> n >> z;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int l1 = n >> 1;     for (int i = 0; i < l1; i++) q1.push(x[i]);     for (int i = l1; i < n; i++) q2.push(x[i]);     while (!q2.empty()) {       if (!q1.empty() && q2.top() - q1.top() >= z) {         ans++;         q1.pop();         q2.pop();       } else {         q1.push(q2.top());         q2.pop();       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int a[100000];   int base = int(1e9 + 7);   int lucky[2000];   long long co[2000];   long long f[2000][2000];   long long unlucky;   long long frac[100001];   long long c[100001];   int size = 1100;   int r1, r2;   int getBit(int, int);   void create();   int find(int);   long long inpow(long long, long long);   void calCombination();   void dp();   int main() {     cin >> n >> k;     create();     for (int i = 0; i < n; i++) {       fscanf(stdin,  %d , &a[i]);       int pos = find(a[i]);       if (pos != -1) {         co[pos]++;       } else         unlucky++;     }     calCombination();     dp();     long long res = 0;     f[m - 1][0] = 1;     for (int j = 0; j <= k; j++) {       res = (res + f[m - 1][j] * c[k - j]) % base;     }     cout << res << endl;     return 0;   }   int getBit(int x, int i) { return ((x & (1 << i)) != 0); }   void create() {     m = 0;     for (int ndig = 1; ndig <= 9; ndig++)       for (int i = 0; i < (1 << ndig); i++) {         int cur = 0;         for (int j = ndig - 1; j >= 0; j--)           if (getBit(i, j) == 0)             cur = cur * 10 + 4;           else             cur = cur * 10 + 7;         lucky[m++] = cur;       }   }   int find(int x) {     int lo, hi;     lo = 0;     hi = m - 1;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (x == lucky[mid]) return mid;       if (x < lucky[mid])         hi = mid - 1;       else         lo = mid + 1;     }     return -1;   }   long long inpow(long long x, long long p) {     if (p == 1) return x % base;     if (p % 2 == 0) {       long long t = inpow(x, p / 2);       return (t * t) % base;     } else       return (x * inpow(x, p - 1)) % base;   }   void calCombination() {     frac[0] = 1;     for (int i = 1; i <= unlucky; i++) frac[i] = (frac[i - 1] * i) % base;     c[0] = 1;     c[1] = unlucky;     for (long long i = 2; i <= unlucky; i++) {       c[i] =           frac[unlucky] * inpow((frac[i] * frac[unlucky - i]) % base, base - 2);       c[i] = c[i] % base;     }   }   void dp() {     for (int i = 0; i < m; i++) f[i][0] = 1;     f[0][1] = co[0];     for (int i = 1; i < m; i++)       for (int j = 1; j <= (i + 1); j++)         f[i][j] = (f[i - 1][j - 1] * co[i] + f[i - 1][j]) % base;   }


#include <bits/stdc++.h>   using namespace std;   long long a[101];   long long vis[101];   long long judge(vector<long long> A) {     if (A.empty()) return 0;     for (long long i = 0; i < A.size(); i++) {       if (A[i] != i) return i;     }     return A.size();   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       memset(vis, 0, sizeof vis);       vector<long long> A, B;       vis[1] = 1;       A.push_back(a[1]);       for (long long i = 2; i <= n; i++) {         if (a[i] != a[i - 1]) {           vis[i] = 1;           A.push_back(a[i]);         }       }       for (long long i = 1; i <= n; i++) {         if (!vis[i]) {           B.push_back(a[i]);         }       }       B.erase(unique(B.begin(), B.end()), B.end());       cout << judge(A) + judge(B) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 10;   int n, m;   int px[] = {0, 1, -1, 0};   int py[] = {1, 0, 0, -1};   bool dig[10];   char a[N][N];   bool inside(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }   bool alone(int x, int y) {     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  . ) return false;     }     return true;   }   void go(int x, int y) {     a[x][y] =  * ;     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  X ) go(x2, y2);       if (isdigit(a[x2][y2])) dig[a[x2][y2] -  0 ] = 1;     }   }   char getColor(int x, int y) {     memset(dig, 0, sizeof(dig));     go(x, y);     int i;     for (i = 0; i < 10; i++)       if (dig[i] == 0) return  0  + i;     assert(false);   }   void fill(int x, int y, char c) {     a[x][y] = c;     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  * ) fill(x2, y2, c);     }   }   void print() {     int i;     for (i = 0; i < n; i++) printf( %s n , a[i]);     printf(  n n );   }   int main() {     scanf( %d%d , &n, &m);     int i, j, k, t;     for (i = 0; i < n; i++) scanf( %s , a[i]);     int x[3], y[3];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (a[i][j] !=  . ) continue;         x[0] = i;         y[0] = j;         for (k = 0; k < 2; k++) {           x[1] = x[0] + px[k];           y[1] = y[0] + py[k];           if (!inside(x[1], y[1])) continue;           if (a[x[1]][y[1]] ==  . ) break;         }         if (k == 2) {           printf( -1 n );           return 0;         }         a[x[0]][y[0]] =  X ;         a[x[1]][y[1]] =  X ;         for (t = 0; t < 2; t++) {           for (k = 0; k < 4; k++) {             x[2] = x[t] + px[k];             y[2] = y[t] + py[k];             if (!inside(x[2], y[2])) continue;             if (a[x[2]][y[2]] !=  . ) continue;             if (alone(x[2], y[2])) a[x[2]][y[2]] =  X ;           }         }         fill(x[0], y[0], getColor(x[0], y[0]));       }     for (i = 0; i < n; i++) printf( %s n , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000009];   int pre[10000009];   vector<long long> alr;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     long long ans = 0, ans1 = 0;     int taken = 0;     for (int i = 0; i < n; i++) {       pre[a[i]]++;     }     for (int i = 0; i < n; i++) {       if (pre[a[i]] % 2 == 1) {         if (pre[a[i] - 1] > 0)           pre[a[i]]--, pre[a[i] - 1]++;         else           pre[a[i]]--;       }     }     int x = 0, y = 0, l = 0, r = 2;     while (l < n && r < n) {       if (pre[a[l]] >= 2 && pre[a[r]] >= 2) {         if (a[l] == a[r] && pre[a[r]] < 4) {           r++;           continue;         }         pre[a[l]] -= 2;         pre[a[r]] -= 2;         ans += a[l] * a[r];       } else if (pre[a[r]] < 2 && pre[a[l]] >= 2)         r++;       else if (pre[a[r]] >= 2 && pre[a[l]] < 2)         l++;       else if (pre[a[r]] < 2 && pre[a[l]] < 2)         l++, r++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   template <class T>   inline void relaxMin(T &a, T b) {     a = min(a, b);   }   template <class T>   inline void relaxMax(T &a, T b) {     a = max(a, b);   }   string str(int i) {     char s[100];     sprintf(s,  %d , i);     return string(s);   }   inline int sign(int x) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }   inline int myAbs(int a) { return a > 0 ? a : -a; }   const int mlen = (int)2e5 + 10;   int n;   char s[mlen];   int main() {     gets(s);     n = strlen(s);     int i = 0;     while (i < n && s[i] <= 32) i++;     while (i < n) {       char ch = s[i];       int l;       if (ch ==  , )         l = 1;       else if (ch ==  . )         l = 3;       else         l = n;       while (l > 0 && i < n && isdigit(ch) == isdigit(s[i])) putchar(s[i++]), l--;       while (i < n && s[i] <= 32) i++;       if (i < n && (ch ==  ,  || s[i] ==  .  || (isdigit(ch) && isdigit(s[i]))))         putchar(   );     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ex[100];   int att[100];   int de[100];   int jo[100];   int n, m, n1, n2;   int ae() {     int ina = 0;     int inb = 0;     pair<int, bool> mi[200];     for (int i = 0; i < n1; i++) mi[i].first = att[i], mi[i].second = 0;     for (int i = n1; i < n1 + m; i++) {       mi[i].first = jo[i - n1], mi[i].second = 1;     }     sort(mi, mi + m + n1);     int v = 0;     int y = 0;     for (int i = 0; i < n1 + m; i++) {       if (mi[i].second == 0)         v++;       else if (v) {         v--;         y++;       }     }     int v1 = 0;     int vt = 0;     for (int i = 0; i < y; i++) {       vt = jo[m - i - 1] - att[i];       if (vt > 0) v1 += vt;     }     return v1;   }   bool di() {     int in1 = 0;     int in2 = 0;     while (true) {       if (in2 == n2) return true;       if (in1 == m) return false;       while (jo[in1++] <= de[in2]) {         if (in1 == m) return false;       }       in1--;       ex[in1] = 1;       in1++, in2++;     }   }   bool di2() {     int in1 = 0;     int in2 = 0;     while (true) {       if (in2 == n1) return true;       if (in1 == m) return false;       while (ex[in1++] == 1)         ;       in1--;       if (in1 == m) return 0;       while (jo[in1++] < att[in2]) {         if (in1 == m) return false;       }       in1--;       in1++, in2++;     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       int t;       cin >> s >> t;       if (s[0] ==  A ) {         att[n1++] = t;       } else {         de[n2++] = t;       }     }     for (int i = 0; i < m; i++) cin >> jo[i];     sort(jo, jo + m);     sort(de, de + n2);     sort(att, att + n1);     int m1 = 0;     if (di() && di2()) {       for (int i = 0; i < m; i++)         if (!(ex[i] == 1)) m1 += jo[i];       for (int i = 0; i < n1; i++) m1 -= att[i];     }     cout << max(m1, ae());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   template <typename T, bool MULTI = false, typename SIZE_T = int>   struct sms_mo {     static_assert(std::is_integral<T>::value,  Not an integral type );     static_assert(std::is_integral<SIZE_T>::value,  Not an integral type );     struct node {       node* ch[2];       SIZE_T cnt;       char d;       T v, mi;       node(int d_, T v_, SIZE_T cnt_) : cnt(cnt_), d(d_), v(v_), mi(v) {         ch[0] = ch[1] = NULL;       }       node(node* x, bool b = true) : cnt(x->cnt), d(x->d), v(x->v), mi(x->mi) {         if (b)           ch[0] = x->ch[0], ch[1] = x->ch[1];         else           ch[0] = ch[1] = NULL;       }       void update() {         if (!ch[0] ^ !ch[1]) {           for (int i = 0; i < 2; i++)             if (ch[i]) {               node* tmp = ch[i];               ch[0] = tmp->ch[0], ch[1] = tmp->ch[1];               d = tmp->d, v = tmp->v;               cnt = tmp->cnt, mi = tmp->mi;               delete tmp;               return;             }         }         cnt = 0;         mi = std::numeric_limits<T>::max();         for (int i = 0; i < 2; i++)           if (ch[i]) {             cnt += ch[i]->cnt;             mi = std::min(mi, ch[i]->mi);           }       }     };     node* root;     T N;     char n;     sms_mo() : root(NULL), N(0), n(0) {}     sms_mo(T v) : sms_mo() {       while (v >> n) n++, N = 2 * N + 1;     }     sms_mo(const sms_mo& t) : root(NULL), N(t.N), n(t.n) {       if (!t.root) return;       root = new node(t.root, false);       std::vector<std::pair<node*, node*>> q = {{root, t.root}};       while (q.size()) {         auto [x, y] = q.back();         q.pop_back();         for (int i = 0; i < 2; i++)           if (y->ch[i]) {             x->ch[i] = new node(y->ch[i], false);             q.emplace_back(x->ch[i], y->ch[i]);           }       }     }     sms_mo(std::initializer_list<T> v) : sms_mo() {       for (T i : v) insert(i);     }     ~sms_mo() {       std::vector<node*> q = {root};       while (q.size()) {         node* x = q.back();         q.pop_back();         if (!x) continue;         q.push_back(x->ch[0]), q.push_back(x->ch[1]);         delete x;       }     }     friend void swap(sms_mo& a, sms_mo& b) {       std::swap(a.root, b.root), std::swap(a.N, b.N), std::swap(a.n, b.n);     }     sms_mo& operator=(const sms_mo& v) {       sms_mo tmp = v;       swap(tmp, *this);       return *this;     }     SIZE_T size() const { return root ? root->cnt : 0; }     SIZE_T count(node* x) const { return x ? x->cnt : 0; }     void clear() {       sms_mo tmp;       swap(*this, tmp);     }     void expand(T v) {       while (v >> n) n++, N = 2 * N + 1;     }     char msb(T v, char l, char r) {       for (char i = r; i > l; i--)         if (v >> i & 1) return i;       return -1;     }     void cut(node* at, T v, char i, node* prev = NULL) {       char d = msb(v ^ at->v, prev ? std::max(at->d, prev->d) : at->d, i);       if (d == -1) {         if (!prev or prev->d <= at->d) return;         d = prev->d, v = ~at->v;       }       node* nxt = new node(at);       at->ch[v >> d & 1] = NULL;       at->ch[!(v >> d & 1)] = nxt;       at->d = d;     }     node* insert(node* at, T v, SIZE_T qt, char i) {       if (!at) return new node(-1, v, qt);       cut(at, v, i);       if (at->d == -1) {         at->cnt += qt;         at->mi = v;         if (!MULTI) at->cnt = 1;         return at;       }       bool dir = v >> at->d & 1;       at->ch[dir] = insert(at->ch[dir], v, qt, at->d - 1);       at->update();       return at;     }     void insert(T v, SIZE_T qt = 1) {       if (qt <= 0) return erase(v, -qt);       expand(v);       root = insert(root, v, qt, n - 1);     }     node* erase(node* at, T v, SIZE_T qt, char i) {       if (!at) return at;       if (at->d == -1)         at->cnt = at->cnt < qt ? 0 : at->cnt - qt;       else {         bool dir = v >> at->d & 1;         at->ch[dir] = erase(at->ch[dir], v, qt, i - 1);         at->update();       }       if (!at->cnt) delete at, at = NULL;       return at;     }     void erase(T v, SIZE_T qt = 1) {       if (v < 0 or v > N or !qt) return;       if (qt < 0) insert(v, -qt);       if (!count(v)) return;       root = erase(root, v, qt, n - 1);     }     void erase_all(T v) {       if (v < 0 or v > N or !count(v)) return;       root = erase(root, v, std::numeric_limits<SIZE_T>::max(), n - 1);     }     SIZE_T count(node* at, T a, T b, T l, T r, char i) const {       if (!at or b < l or r < a) return 0;       if (a <= l and r <= b) return at->cnt;       T m = l + (r - l) / 2;       if (at->d < i) {         if ((at->v >> i & 1) == 0)           return count(at, a, b, l, m, i - 1);         else           return count(at, a, b, m + 1, r, i - 1);       }       return count(at->ch[0], a, b, l, m, i - 1) +              count(at->ch[1], a, b, m + 1, r, i - 1);     }     SIZE_T count(T v) const { return count(root, v, v, 0, N, n - 1); }     SIZE_T order_of_key(T v) { return count(root, 0, v - 1, 0, N, n - 1); }     SIZE_T lower_bound(T v) { return order_of_key(v); }     const T operator[](SIZE_T k) const {       node* at = root;       T l = 0, r = N;       char i = n - 1;       while (l < r) {         T m = l + (r - l) / 2;         if (at->d < i) {           if ((at->v >> i & 1) == 0)             r = m;           else             l = m + 1;           i--;           continue;         }         if (count(at->ch[0]) > k)           at = at->ch[0], r = m;         else {           k -= count(at->ch[0]);           at = at->ch[1];           l = m + 1;         }         i--;       }       return l;     }     node* merge(node* l, node* r, char i) {       if (!l or !r) return l ? l : r;       cut(l, r->v, i, r), cut(r, l->v, i, l);       if (l->d == -1) {         if (MULTI) l->cnt += r->cnt;         delete r;         return l;       }       for (int j = 0; j < 2; j++) l->ch[j] = merge(l->ch[j], r->ch[j], l->d - 1);       l->update(), delete r;       return l;     }     void merge(sms_mo& s) {       if (N > s.N) swap(*this, s);       expand(s.N);       root = merge(root, s.root, n - 1);       s.root = NULL;     }     node* split(node*& x, SIZE_T k) {       if (k <= 0 or !x) return NULL;       node* ret = new node(x);       ret->ch[0] = ret->ch[1] = NULL;       ret->cnt = 0;       if (x->d == -1)         x->cnt -= k, ret->cnt += k, ret->mi = x->mi;       else {         if (k <= count(x->ch[0]))           ret->ch[0] = split(x->ch[0], k);         else {           ret->ch[1] = split(x->ch[1], k - count(x->ch[0]));           std::swap(x->ch[0], ret->ch[0]);         }         ret->update(), x->update();       }       if (!x->cnt) delete x, x = NULL;       return ret;     }     void split(SIZE_T k, sms_mo& s) {       s.clear();       s.root = split(root, std::min(k, size()));       s.N = N, s.n = n;     }     void split_val(T k, sms_mo& s) { split(order_of_key(k), s); }     T min() { return root->mi; };   };   std::mt19937 dyn_array_rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   template <typename T, typename SIZE_T = int,             typename SET = sms_mo<T, true, SIZE_T>>   struct dyn_array {     static_assert(std::is_integral<T>::value,  Not an integral type );     static_assert(std::is_integral<SIZE_T>::value,  Not an integral type );     struct node {       node *l, *r;       int p;       SIZE_T sz;       bool rev, rev_lazy;       SET val;       T mi;       node(SET& v)           : l(NULL), r(NULL), p(dyn_array_rng()), sz(1), rev(0), rev_lazy(0) {         swap(val, v);         mi = val.min();       }       node(node* x)           : l(NULL),             r(NULL),             p(x->p),             sz(x->sz),             rev(x->rev),             rev_lazy(x->rev_lazy),             val(x->val),             mi(x->mi) {}       void prop() {         if (rev_lazy) {           rev ^= 1;           std::swap(l, r);           if (l) l->rev_lazy ^= 1;           if (r) r->rev_lazy ^= 1;         }         rev_lazy = false;       }       void update() {         sz = val.size();         mi = val.min();         if (l) sz += l->sz, mi = std::min(mi, l->mi);         if (r) sz += r->sz, mi = std::min(mi, r->mi);       }     };     node* root;     dyn_array() { root = NULL; }     dyn_array(const dyn_array& v) : root(NULL) {       if (!v.root) return;       root = new node(v.root);       std::vector<std::pair<node*, node*>> q = {{root, v.root}};       while (q.size()) {         auto [x, y] = q.back();         q.pop_back();         if (y->l) {           x->l = new node(y->l);           q.emplace_back(x->l, y->l);         }         if (y->r) {           x->r = new node(y->r);           q.emplace_back(x->r, y->r);         }       }     }     dyn_array(std::initializer_list<T> v) : dyn_array() {       for (T i : v) push_back(i);     }     ~dyn_array() {       std::vector<node*> q = {root};       while (q.size()) {         node* x = q.back();         q.pop_back();         if (!x) continue;         q.push_back(x->l), q.push_back(x->r);         delete x;       }     }     friend void swap(dyn_array& a, dyn_array& b) { std::swap(a.root, b.root); }     dyn_array& operator=(const dyn_array& v) {       dyn_array tmp = v;       swap(tmp, *this);       return *this;     }     void clear() {       dyn_array tmp;       swap(tmp, *this);     }     SIZE_T size(node* x) const { return x ? x->sz : 0; }     SIZE_T size() const { return size(root); }     void join(node* l, node* r, node*& i) {       if (!l or !r) return void(i = l ? l : r);       l->prop(), r->prop();       if (l->p > r->p)         join(l->r, r, l->r), i = l;       else         join(l, r->l, r->l), i = r;       i->update();     }     void concat(dyn_array& v) {       join(root, v.root, root);       v.root = NULL;     }     void split(node* i, node*& l, node*& r, SIZE_T idx) {       if (!i) return void(r = l = NULL);       i->prop();       if (size(i->l) + i->val.size() <= idx) {         split(i->r, i->r, r, idx - size(i->l) - i->val.size());         l = i;       } else if (size(i->l) >= idx) {         split(i->l, l, i->l, idx);         r = i;       } else {         SET L;         if (!i->rev)           i->val.split(idx - size(i->l), L);         else {           i->val.split(i->val.size() - (idx - size(i->l)), L);           swap(L, i->val);         }         node* novo = new node(L);         novo->rev = i->rev;         novo->l = i->l;         i->l = NULL;         novo->update();         l = novo, r = i;       }       i->update();     }     void split(SIZE_T k, dyn_array& v) {       v.clear();       split(root, v.root, root, std::min(k, size()));     }     void push_back(T val, SIZE_T qt = 1) {       SET v;       v.insert(val, qt);       node* i = new node(v);       join(root, i, root);     }     T get(node* i, SIZE_T idx) const {       i->prop();       if (size(i->l) + i->val.size() <= idx)         return get(i->r, idx - size(i->l) - i->val.size());       if (size(i->l) > idx) return get(i->l, idx);       if (!i->rev) return i->val[idx - size(i->l)];       return i->val[i->val.size() - 1 - (idx - size(i->l))];     }     const T operator[](SIZE_T i) const { return get(root, i); }     void update(SIZE_T idx, T val) {       dyn_array L, M;       split(idx + 1, M);       M.split(idx, L);       L.push_back(val);       L.concat(*this);       swap(*this, L);     }     void merge(node*& i, SET& v) {       if (!i) return;       i->prop();       merge(i->l, v), merge(i->r, v);       v.merge(i->val);       delete i;       i = NULL;     }     void sort(bool reverse = false) {       if (!root) return;       root->prop();       merge(root->l, root->val);       merge(root->r, root->val);       root->rev = reverse;       root->update();     }     void sort(SIZE_T l, SIZE_T r, bool reverse = false) {       dyn_array L, M;       split(r + 1, M);       M.split(l, L);       M.sort(reverse);       L.concat(M);       L.concat(*this);       swap(*this, L);     }     void reverse() {       if (root) root->rev_lazy ^= 1;     }     void reverse(SIZE_T l, SIZE_T r) {       dyn_array L, M;       split(r + 1, M);       M.split(l, L);       M.reverse();       L.concat(M);       L.concat(*this);       swap(*this, L);     }     T min() { return root->mi; }     T rmq(SIZE_T l, SIZE_T r) {       dyn_array L, M;       split(r + 1, M);       M.split(l, L);       T ans = M.min();       L.concat(M);       L.concat(*this);       swap(*this, L);       return ans;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     map<int, int> ida, volta;     vector<int> w(n);     for (int& i : w) cin >> i;     auto w2 = w;     sort(w2.begin(), w2.end());     for (int i = 0; i < n; i++) ida[w2[i]] = i, volta[i] = w2[i];     dyn_array<int> v;     for (int i = 0; i < n; i++) v.push_back(ida[w[i]]);     while (q--) {       int t, r;       cin >> t >> r;       r--;       v.sort(0, r, t - 1);     }     for (int i = 0; i < n; i++) cout << volta[v[i]] <<    ;     cout <<   n ;     exit(0);   }


#include <bits/stdc++.h>   int a[100];   int main() {     int n;     scanf( %d%d%d , &a[0], &a[1], &n);     for (int i = 2; i <= n; i++) {       a[i] = a[i - 1] + a[i - 2];     }     printf( %d n , a[n]);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int chkmax(T &a, T b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   template <class T>   int chkmin(T &a, T b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   template <class iterator>   void output(iterator begin, iterator end, ostream &out = cerr) {     while (begin != end) {       out << (*begin) <<    ;       begin++;     }     out << endl;   }   template <class T>   void output(T x, ostream &out = cerr) {     output(x.begin(), x.end(), out);   }   void fast_io() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int MOD = 1e9 + 7;   const int _2 = (MOD + 1) / 2;   void add(int &a, int b) {     a += b;     if (a >= MOD) {       a -= MOD;     }   }   int mul(int a, int b) { return (1LL * a * b) % MOD; }   const int mx = 2e3 + 10;   int n, m, cs, used[mx];   vector<vector<int> > g;   vector<int> a;   void read() {     cin >> n >> m;     g.resize(n);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }   }   int dfs(int v) {     int res = 1;     used[v] = 1;     for (auto v1 : g[v]) {       if (used[v1] == 0) {         res += dfs(v1);       }     }     return res;   }   void find_cycles() {     used[0] = 1;     for (auto v : g[0]) {       if (used[v] == 0) {         int len = dfs(v);         a.push_back(len + 1);       }     }   }   int dp[mx][2 * mx], dpPref[mx][2 * mx], dpSuf[mx][2 * mx];   int dpPrefObl[mx][2 * mx], dpSufObl[mx][2 * mx];   void update_dp(int len, int idx, int stay) {     fill(dp[idx + 1], dp[idx + 1] + m + 1, 0);     for (int delta = 0; delta <= m; ++delta) {       if (dp[idx][delta]) {         add(dp[idx + 1][delta + len], dp[idx][delta]);         add(dp[idx + 1][abs(delta - len)], dp[idx][delta]);         if (stay) {           add(dp[idx + 1][delta], dp[idx][delta]);         }       }     }   }   void calc_dp(int stay) {     fill(dp[0], dp[0] + m + 1, 0);     dp[0][0] = 1;     for (int i = 0; i < cs; ++i) {       update_dp(a[i], i, stay);     }   }   void process() {     cs = a.size();     calc_dp(1);     for (int i = 0; i <= cs; ++i) {       copy(dp[i], dp[i] + m + 1, dpPref[i]);     }     calc_dp(0);     for (int i = 0; i <= cs; ++i) {       copy(dp[i], dp[i] + m + 1, dpPrefObl[i]);     }     reverse(a.begin(), a.end());     calc_dp(1);     for (int i = 0; i <= cs; ++i) {       copy(dp[i], dp[i] + m + 1, dpSuf[i]);     }     calc_dp(0);     for (int i = 0; i <= cs; ++i) {       copy(dp[i], dp[i] + m + 1, dpSufObl[i]);     }     reverse(a.begin(), a.end());   }   int ans;   int convert(int val, int pos) { return (pos == 0 ? val : mul(val, _2)); }   int merge(int pos, int sum) {     int res = 0;     for (int delta1 = -m; delta1 <= m; ++delta1) {       int delta2 = sum - delta1;       if (abs(delta2) <= m) {         add(res, mul(convert(dpPref[pos][abs(delta1)], delta1),                      convert(dpSuf[cs - 1 - pos][abs(delta2)], delta2)));       }     }     return res;   }   int merge_obl(int pos, int sum) {     int res = 0;     for (int delta1 = -m; delta1 <= m; ++delta1) {       int delta2 = sum - delta1;       if (abs(delta2) <= m) {         add(res, mul(convert(dpPrefObl[pos][abs(delta1)], delta1),                      convert(dpSufObl[cs - 1 - pos][abs(delta2)], delta2)));       }     }     return res;   }   void mergeAns() {     add(ans, dpPrefObl[cs][0]);     for (int i = 0; i < cs; ++i) {       add(ans, mul(merge_obl(i, a[i] - 1), 4));       for (int diff = 2 - a[i]; diff <= a[i] - 2; ++diff) {         add(ans, mul(merge(i, diff), 2));       }     }   }   signed main() {     fast_io();     read();     find_cycles();     process();     mergeAns();     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 100;   class Node {    public:     int l, r;     bool operator<(const Node &a) const { return r < a.r; }   };   Node n[maxn];   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d%d , &n[i].l, &n[i].r);     sort(n, n + N);     int ans = 1, ps = 0;     for (int i = 1; i < N; i++)       if (n[i].l > n[ps].r) {         ans++;         ps = i;       }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400005;   int N;   long long T;   long long A[MAXN];   long long pre[MAXN];   map<long long, int> mp;   int BIT[MAXN];   void add(int idx) {     for (; idx < MAXN; idx += idx & -idx) BIT[idx]++;   }   int get(int idx) {     int ret = 0;     for (; idx > 0; idx -= idx & -idx) ret += BIT[idx];     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin >> N >> T;     mp[-T] = 1;     mp[0] = 1;     for (int i = 1; i <= N; i++) {       cin >> A[i];       pre[i] = pre[i - 1] + A[i];       mp[pre[i] - T] = 1;       mp[pre[i]] = 1;     }     int ind = 0;     for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++)       it->second = ++ind;     long long ans = 0;     add(mp[0]);     for (int i = 1; i <= N; i++) {       ans += i - get(mp[pre[i] - T]);       add(mp[pre[i]]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, n, r;     cin >> t;     while (t--) {       cin >> n >> r;       vector<long long> v(n);       set<long long> s;       for (int i = 0; i < n; i++) {         cin >> v[i];         s.insert(v[i]);       }       vector<long long> a;       for (auto i : s) {         a.push_back(i);       }       int co = 0;       long long cur = 0;       for (int i = a.size() - 1; i >= 0; i--) {         if (a[i] - cur > 0) {           a[i] = 0;           co++;           cur += r;         } else           break;       }       cout << co << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod1 = 1e9 + 7;   const int mod2 = 998244353;   const long long int inf = 1e18;   const double pi = 3.1415926535897932384626;   long long int mpow(long long int a, long long int b, long long int m) {     long long int res = 1;     while (b) {       if (b % 2) res = res * a % m;       a = a * a % m;       b /= 2;     }     return res;   }   long long int inv(long long int a, long long int m) {     return mpow(a, m - 2, m);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int ncr(long long int n, long long int k) {     if (n < k) return 0;     long long int C[n + 1][k + 1];     long long int i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= min(i, k); j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);       }     }     return C[n][k];   }   void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n], b[m];     vector<long long int> x;     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < m; i++) {       cin >> b[i];       x.push_back(upper_bound(a, a + n, b[i]) - a);     }     for (auto i : x) cout << i <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     clock_t start, end;     start = clock();     solve();     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);     cerr <<   nExecution time :   << fixed << time_taken << setprecision(5)          <<   s  n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int b[maxn];   int c[maxn];   bool visit[maxn];   int n, k;   int main() {     int i, p;     while (scanf( %d%d , &n, &k) != EOF) {       for (i = 1; i <= n; i++) scanf( %d , &b[i]);       memset(c, 0, sizeof(c));       memset(visit, false, sizeof(visit));       for (p = 1; p <= n; p++) {         for (i = 1; i <= n; i++)           if (c[i] == b[i] && visit[i] == false) break;         printf( %d  , i);         int u = i;         visit[u] = true;         for (i = 1; i <= n; i++)           if (u >= i + k)             c[i]++;           else             break;       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n;     char prev =  a ;     int dur = 0;     vector<int> durs;     for (int i = 0; i < n; ++i) {       char c;       cin >> c;       if (c ==  W ) {         if (dur != 0) durs.push_back(dur);         dur = 0;       } else {         ++dur;       }     }     if (dur != 0) durs.push_back(dur);     cout << durs.size() <<   n ;     for (int i = 0; i < durs.size(); ++i) {       cout << durs[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e10;   const double pi = 3.14159265359;   const long long mod = 1743;   const long long MAXN = 2 * 1e5 + 6;   const long long MAXM = 2 * 1e5 + 6;   const long long zero = 0;   double v1, v2, e1, e2, h, d, r, area;   int main() {     ios::sync_with_stdio(false);     cin >> d >> h >> v1 >> e1;     r = d * 0.5;     area = r * r * pi;     v2 = area * e1;     cout.precision(10);     if (v2 >= v1)       cout <<  NO ;     else       cout <<  YES  << endl << (area * h) / (v1 - v2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e3 + 10;   vector<pair<int, int> > v[N];   int ps[N], mx[N], cnt, wr;   void dfs(int u, int par) {     for (auto y : v[u]) {       if (y.first == par) continue;       ps[y.first] = ps[u];       if (y.second == 1)         ps[y.first]++;       else {         wr++;         ps[y.first]--;       }       mx[y.first] = max(mx[u], ps[y.first]);       cnt = min(cnt, ps[y.first] - mx[y.first]);       dfs(y.first, u);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].push_back(make_pair(b, 1));       v[b].push_back(make_pair(a, 2));     }     int ans = n - 1;     for (int i = 0; i < n; i++) {       fill(mx, mx + N, 0);       fill(ps, ps + N, 0);       cnt = 0;       wr = 0;       dfs(i, -1);       ans = min(ans, wr + cnt);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int modl = 1e9 + 7;   string pattern;   int n;   vector<vector<int>> nums;   void init();   int main() {     cin >> n;     cin >> pattern;     init();     vector<vector<int>> dp(n + 1, vector<int>(1 << 20, 0));     for (int i = 0; i <= n; i++) {       dp[i][0] = 1;       for (int j = 0; j < (1 << 20); j++) {         if (dp[i][j]) {           for (int k = i; k < n; k++) {             if (nums[i][k])               dp[k + 1][j | (1 << (nums[i][k] - 1))] =                   (dp[k + 1][j | (1 << (nums[i][k] - 1))] + dp[i][j]) % modl;           }         }       }     }     int res = 0;     for (int i = 0; i <= n; i++) {       for (int j = 2; j <= (1 << 20); j <<= 1) {         res = (res + dp[i][j - 1]) % modl;       }     }     cout << res << endl;     return 0;   }   void init() {     nums = vector<vector<int>>(n, vector<int>(n, 0));     for (int i = 0; i < n; i++) {       for (int j = i, k = 0; j < n; j++) {         k = ((k << 1) + pattern[j] -  0 );         if (k > 20) break;         nums[i][j] = k;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9;   const long long LNF = 1e18;   void setIO(string s) {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   const int N = 1e5 + 7;   vector<int> adj[N], ans;   bool vis[N][2], cvis[N];   bool dfs(int u, int p) {     if (vis[u][p]) return false;     vis[u][p] = true;     if (adj[u].empty() && p) {       ans.emplace_back(u);       return true;     }     for (auto& v : adj[u]) {       if (dfs(v, p ^ 1)) {         ans.emplace_back(u);         return true;       }     }     return false;   }   bool cycle(int u) {     if (cvis[u]) return true;     cvis[u] = true;     for (auto& i : adj[u]) {       if (cycle(i)) return true;       cvis[i] = false;     }     return false;   }   int main() {     setIO( input );     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       int c;       cin >> c;       for (int j = 0; j < c; ++j) {         int v;         cin >> v;         adj[i].emplace_back(--v);       }     }     int s;     cin >> s;     --s;     if (dfs(s, 0)) {       cout <<  Win n ;       for (int i = (int)ans.size() - 1; i >= 0; --i) cout << ans[i] + 1 <<    ;     } else {       if (cycle(s))         cout <<  Draw ;       else         cout <<  Lose ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   struct circle {     double x, y, r;     circle() {}     circle(double x, double y, double r = 0) : x(x), y(y), r(r) {}     circle operator+(circle b) { return circle(x + b.x, y + b.y); }     circle operator-(circle b) { return circle(x - b.x, y - b.y); }     circle operator*(double d) { return circle(x * d, y * d); }     double squareLength() { return ((x) * (x)) + ((y) * (y)); }     double length() { return sqrt(squareLength()); }     void normalize() {       double d = length();       x /= d;       y /= d;     }   };   circle dot(circle a, circle b) { return circle(a.x * b.y, a.y * b.x); }   circle a, b, c;   double get_angle(circle a, circle b) { return asin(a.r / (a - b).length()); }   bool check(circle p) {     return fabs(get_angle(a, p) - get_angle(b, p)) < 1e-8 &&            fabs(get_angle(b, p) - get_angle(c, p)) < 1e-8 &&            fabs(get_angle(c, p) - get_angle(a, p)) < 1e-8;   }   circle get_circle(circle a, circle b) {     double br = ((b.r) * (b.r));     double ar = ((a.r) * (a.r));     double A = br - ar;     double x = (br * a.x - ar * b.x) / A;     double y = (br * a.y - ar * b.y) / A;     double aa = ((a.y - y) * (a.y - y));     double bb = ((b.y - y) * (b.y - y));     double B = -2 * (br * a.x - ar * b.x);     double C = br * (aa + ((a.x) * (a.x))) - ar * (bb + ((b.x) * (b.x)));     double D = sqrt(((B) * (B)) - 4 * A * C);     return circle(x, y, fabs(D / (2 * A)));   }   int main() {     cin >> a.x >> a.y >> a.r;     cin >> b.x >> b.y >> b.r;     cin >> c.x >> c.y >> c.r;     if (a.r == b.r && b.r == c.r) {       if (fabs(c.y - b.y) < 1e-10) swap(a, b);       double y = ((((c.x) * (c.x)) - ((a.x) * (a.x)) + ((c.y) * (c.y)) -                    ((a.y) * (a.y))) *                       (b.x - a.x) -                   (((b.x) * (b.x)) - ((a.x) * (a.x)) + ((b.y) * (b.y)) -                    ((a.y) * (a.y))) *                       (c.x - a.x)) /                  (2 * ((c.y - a.y) * (b.x - a.x) - (b.y - a.y) * (c.x - a.x)));       double x = (((b.x) * (b.x)) - ((a.x) * (a.x)) + ((b.y) * (b.y)) -                   ((a.y) * (a.y)) - 2 * y * (b.y - a.y)) /                  (2 * (b.x - a.x));       if (check(circle(x, y))) cout << setprecision(5) << fixed << x <<     << y;       return 0;     }     if (fabs(a.r - b.r) < 1e-10) swap(a, c);     if (fabs(a.r - c.r) < 1e-10) swap(a, b);     circle p1 = get_circle(a, b);     circle p2 = get_circle(a, c);     double length = (p2 - p1).length();     if (length < p1.r + p2.r + 1e-8)       if (p1.r < p2.r + length + 1e-8 && p2.r < p1.r + length + 1e-8 &&           length < p1.r + p2.r + 1e-8) {         double x =             (((p2.r) * (p2.r)) - ((p1.r) * (p1.r)) - ((length) * (length))) /             (-2 * length);         double h = sqrt(((p1.r) * (p1.r)) - ((x) * (x)));         circle vec = (p2 - p1);         vec.normalize();         vec = vec * x;         circle point = p1 + vec;         vec = dot(circle(-1, 1), vec);         vec.normalize();         vec = vec * h;         circle x1 = point + vec;         circle x2 = point - vec;         cout << setprecision(5) << fixed;         if (check(x1) && !check(x2))           cout << x1.x <<     << x1.y;         else if (!check(x1) && check(x2))           cout << x2.x <<     << x2.y;         else if (check(x1) && check(x2))           if (get_angle(a, x1) > get_angle(a, x2))             cout << x1.x <<     << x1.y;           else             cout << x2.x <<     << x2.y;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200010];   int T, N;   int Solve() {     N = strlen(s + 1);     int Ans = 0, Len = 1;     while ((1 << (Len)) <= N) ++Len;     for (register int i = 1; i <= N; ++i) {       if (s[i] ==  0 ) continue;       int p = i, num = 0;       while (p > 1 && s[p - 1] ==  0 ) --p;       for (register int j = i; j <= min(i + Len - 1, N); ++j) {         num = (num << 1) + s[j] -  0 ;         if (num > N) break;         int L = j - i + 1, R = j - p + 1;         if (L <= num && num <= R) ++Ans;       }     }     return Ans;   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %s , s + 1);       printf( %d n , Solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5555;   int t[N], l[N], r[N], x[N], a[N], dif[N];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d %d %d , t + i, l + i, r + i, x + i);       --l[i], --r[i];     }     for (int i = 0; i < n; ++i) a[i] = 1000000000;     for (int i = 0; i < m; ++i) {       if (t[i] == 1) {         for (int j = l[i]; j <= r[i]; ++j) {           dif[j] += x[i];         }       } else {         for (int j = l[i]; j <= r[i]; ++j) {           a[j] = min(a[j], x[i] - dif[j]);         }       }     }     for (int i = 0; i < m; ++i) {       if (t[i] == 1) {         for (int j = l[i]; j <= r[i]; ++j) {           a[j] += x[i];         }       } else {         int mx = -2e9;         for (int j = l[i]; j <= r[i]; ++j) {           mx = max(mx, a[j]);         }         if (mx != x[i]) {           puts( NO );           return 0;         }       }     }     puts( YES );     for (int i = 0; i < n; ++i) {       printf( %d  , a[i] - dif[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long rin() {     long long s = 0;     bool bj = false;     char c = getchar();     for (; (c >  9  || c <  0 ) && c !=  - ; c = getchar())       ;     if (c ==  - ) bj = true, c = getchar();     for (; c >=  0  && c <=  9 ; c = getchar())       s = (s << 1) + (s << 3) + (c ^  0 );     if (bj) return -s;     return s;   }   inline void pri(long long ans, long long x, long long y, int n, int m, int xt,                   int yt) {     xt = (xt == -1);     yt = (yt == -1);     xt ^= (((x - 1) / n) & 1);     yt ^= (((y - 1) / m) & 1);     printf( %d %d n , xt ? 0 : n, yt ? 0 : m);     return;   }   inline int Gcd(int a, int b) { return (!b) ? (a) : (Gcd(b, a % b)); }   inline void Ex_Gcd(int a, int b, long long &x, long long &y) {     (!b) ? (x = y = 1) : (Ex_Gcd(b, a % b, y, x), y -= x * (a / b));     return;   }   int n, m, x, y, xt, yt;   inline int work() {     if (!xt && !yt) {       puts( -1 );       return 0;     }     if (!xt) {       if (x == 0 || x == n)         printf( %d %d n , x, (yt == -1) ? 0 : m);       else         puts( -1 );     } else {       if (y == 0 || y == m)         printf( %d %d n , (xt == -1) ? (0) : n, y);       else         puts( -1 );     }     return 0;   }   int main() {     n = rin();     m = rin();     x = rin();     y = rin();     xt = rin();     yt = rin();     if (xt == 0 || yt == 0) return work();     if (xt == -1) x = n - x;     if (yt == -1) y = m - y;     long long ans = n - x;     int z = Gcd(n, m);     if ((-y - ans) % z) {       puts( -1 );       return 0;     }     long long X, Y;     Ex_Gcd(n / z, m / z, X, Y);     X *= ((-ans - y) / z);     X %= m;     long long M = 1LL * n / z * m;     ans += X * n;     ans = (ans % M + M) % M;     pri(ans, ans + x, ans + y, n, m, xt, yt);     return 0;   }


/*   --------------------       |       LOSER        |       |     ~NOOBOSS~      |        --------------------   */   #include <bits/stdc++.h>   using namespace std;   #define      mxx                 1e18   #define      mnn                 -1e18   #define      Y()                 cout<<  YES  <<endl   #define      N()                 cout <<  NO <<endl   #define      endl                  n    #define      Ceil(x,y)           ((x+y-1)/y)   #define      sz(s)               (int)s.size()   #define      angle(x)            double(x * acos(-1) / 180.0)   #define      max_3(a,b,c)        max(a, max(b,c))   #define      min_3(a,b,c)        min(a, min(b,c))   #define      gcd(a,b)            __gcd(a,b)   #define      lcm(a,b)           (a*b)/gcd(a,b)   #define      loser               return 0   #define      ll                  long long   #define      PI                  acos(-1)   #define      mem(a,v)            memset(a,v,sizeof(a))   #define      SORT(v)             sort(v.begin(),v.end())   #define      REV(v)              reverse(v.begin(),v.end())   #define      B                   begin()   #define      E                   end()   #define      V                   vector   #define      F                   first   #define      S                   second   #define      PSB                 push_back   #define      MP                  make_pair   #define      flash               cout.flush()   #define      InTheNameOfGod      ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);   constexpr ll MOD = 998244353;   constexpr ll mod = 1e9  + 7;   int dx[] = {0,0,1,-1};   int dy[] = {1,-1,0,0};   /*-----*/   #define bug1(a)  cerr<<a<<endl;   #define bug2(a,b)  cerr<<a<<   <<b<<endl;   #define bug3(a,b,c)  cerr<<a<<   <<b<<   <<c<<endl;   /*----*/   const ll N=3e6+5;   vector<ll> adj[N];   ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}   ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}   ll nsum(ll num){return (num*(num+1))/2;}   void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);}   /*------------------START---------------------*/      /*-----*/   void solve(){      ll n,k;      string s;      cin>>n>>k;      if(n<3){        if(k) cout<<-1<<endl;        else{           for(ll i=1;i<=n;i++) cout<<i<<   ;           cout<<endl;        }        return;      }         ll mx=1; ll bal=n-3;      mx+=bal/2;      if(k>mx){       cout<<-1<<endl;      }      else{         cout<<1<<   ;         ll ct=2;         for(ll i=2;i<=n;i++){           if(k){               cout<<i+1<<   <<i<<   ;               --k; i++;           }           else{               cout<<i<<   ;           }         }         cout<<endl;      }         //cout << fixed << setprecision(10);   }   /*-----*/   int main(){      InTheNameOfGod         ll Test=1;      cin>>Test;      while(Test--){        solve();       }     loser;   }   ///////   C O D I N G  I S  L I F E   ///////


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v(14 + 1);   int go[1001][14], fail[1001], weight[1001], nxt, maxLength;   pair<int, long long> a[1001];   long long dp[1001][(1 << 14)];   const long long negativeInfinity = LLONG_MIN / 2;   void AddStringToAhoCorasick(string s, int val) {     int i = 0;     for (auto c : s) {       int k = c -  a ;       if (go[i][k] == 0) {         go[i][k] = ++nxt;       }       i = go[i][k];     }     maxLength = max(maxLength, (int)s.size());     weight[i] += val;   }   void BuildAhoCorasick() {     queue<int> Q;     for (int x = 0; x < 14; ++x) {       if (go[0][x]) {         Q.push(go[0][x]);       }     }     while (!Q.empty()) {       const int i = Q.front();       Q.pop();       weight[i] += weight[fail[i]];       for (int x = 0; x < 14; ++x) {         const int j = go[i][x];         if (j) {           fail[j] = go[fail[i]][x];           Q.push(j);         } else {           go[i][x] = go[fail[i]][x];         }       }     }   }   void ResetTransitions() {     for (int i = 0; i <= nxt; ++i) {       a[i].first = -1;     }   }   inline pair<int, long long> GetTransitionedNode(int i, const string &s) {     int j = i;     long long val = 0;     for (auto c : s) {       j = go[j][c -  a ];       val += weight[j];     }     a[i] = make_pair(j, val);     return a[i];   }   void ApplyStringTransitions(const string &s, const int n, const int qCount) {     for (int i = 0; i <= n; ++i) {       int j;       long long val;       tie(j, val) = GetTransitionedNode(i, s);       for (int mask : v[qCount]) {         if (dp[i][mask] < negativeInfinity) {           continue;         }         val += dp[i][mask];         for (int x = 0; x < 14; ++x) {           if ((mask & (1 << x)) > 0) {             continue;           }           const int k = go[j][x], nmask = mask | (1 << x);           dp[k][nmask] = max(dp[k][nmask], val + weight[k]);         }         val -= dp[i][mask];       }     }   }   int Initialise() {     int n;     cin >> n;     while (n--) {       string s;       int val;       cin >> s >> val;       AddStringToAhoCorasick(s, val);     }     BuildAhoCorasick();     for (int mask = 0; mask < (1 << 14); ++mask) {       v[__builtin_popcount(mask)].push_back(mask);     }     return nxt;   }   int main() {     int n = Initialise();     string t;     cin >> t;     int cur = 0;     for (int i = 0; i <= n; ++i) {       for (int mask = 0; mask < (1 << 14); ++mask) {         dp[i][mask] = LLONG_MIN;       }     }     dp[0][0] = 0;     string s;     int qCount = 0;     for (auto c : t) {       if (c !=  ? ) {         s.push_back(c);         continue;       }       ApplyStringTransitions(s, n, qCount);       s.clear();       ++qCount;     }     long long ans = LLONG_MIN;     for (int i = 0; i <= n; ++i) {       int j;       long long val;       tie(j, val) = GetTransitionedNode(i, s);       for (int mask : v[qCount]) {         if (dp[i][mask] < negativeInfinity) {           continue;         }         ans = max(ans, val + dp[i][mask]);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100010][3];   vector<int> v;   int n;   int solve(int i, int op, int last) {     if (i == n) {       return 0;     }     if (dp[i][op] != -1) {       return dp[i][op];     }     int ans = 0x3f3f3f3f;     int aux = op;     if (aux == 2) {       aux = -1;     }     int aux2 = last;     if (aux2 == 2) {       aux2 = -1;     }     if ((v[i] - v[i - 1] + 1 - aux) == (v[i - 1] + aux - v[i - 2] - aux2)) {       ans = min(ans, 1 + solve(i + 1, 1, op));     }     if ((v[i] - v[i - 1] - aux) == (v[i - 1] + aux - v[i - 2] - aux2)) {       ans = min(ans, solve(i + 1, 0, op));     }     if ((v[i] - v[i - 1] - 1 - aux) == (v[i - 1] + aux - v[i - 2] - aux2)) {       ans = min(ans, 1 + solve(i + 1, 2, op));     }     return dp[i][op] = ans;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n;     v.resize(n, 0);     for (int i = 0; i < (n); i++) {       cin >> v[i];     }     memset(dp, -1, sizeof dp);     int ans = 0x3f3f3f3f;     for (int i = 0; i < (3); i++) {       for (int j = 0; j < (3); j++) {         memset(dp, -1, sizeof dp);         int aux = (i > 0) + (j > 0);         ans = min(ans, aux + solve(2, i, j));       }     }     if (n <= 2) {       cout << 0 <<   n ;       return 0;     }     if (ans > n + 1) {       cout << -1 <<   n ;     } else {       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, p;     cin >> s;     int sz = s.size();     for (char ch =  a ; ch <=  z ; ch++) {       for (int i = 0; i <= s.size(); i++) {         p = s.substr(0, i) + ch + s.substr(i, sz);         if (p == string(p.rbegin(), p.rend())) {           cout << p <<   n ;           return 0;         }       }     }     cout <<  NA n ;   }


#include <bits/stdc++.h>   using namespace std;   const int NM_MAX = 82;   const int U_MAX = 6404;   int U;   vector<int> edges[U_MAX];   short int C[U_MAX][U_MAX];   short int R[U_MAX][U_MAX];   short int F[U_MAX][U_MAX];   int dist[U_MAX];   int parent[U_MAX];   queue<int> q;   bool BellmanFord() {     for (int i = 1; i <= U; i++) {       dist[i] = INT_MAX;       parent[i] = -1;     }     parent[1] = 0;     dist[1] = 0;     q.push(1);     while (q.empty() == false) {       int u = q.front();       q.pop();       for (int v : edges[u])         if (R[u][v] > 0 && dist[u] + C[u][v] < dist[v]) {           dist[v] = dist[u] + C[u][v];           parent[v] = u;           q.push(v);         }     }     return (parent[U] != -1);   }   void pushFlow(int u, int v, int flow) {     R[u][v] -= flow;     R[v][u] += flow;     F[u][v] += flow;     F[v][u] -= flow;   }   int minCostMaxFlow() {     while (BellmanFord() == true) {       int u;       u = U;       int flow = INT_MAX;       while (u != 1) {         flow = min(flow, (int)R[parent[u]][u]);         u = parent[u];       }       u = U;       while (u != 1) {         pushFlow(parent[u], u, flow);         u = parent[u];       }     }     int ans = 0;     for (int i = 1; i <= U; i++)       for (int j = 1; j <= U; j++) ans += C[i][j] * F[i][j];     return ans;   }   int n, m;   int ma[NM_MAX][NM_MAX];   int da[] = {-1, 0, 1, 0}, db[] = {0, 1, 0, -1};   bool inside(int a, int b) { return (1 <= a && a <= n && 1 <= b && b <= m); }   int codif(int a, int b) { return (a - 1) * m + b + 1; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> ma[i][j];     U = 1 + n * m + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int d = 0; d < 4; d++) {           int i1 = i + da[d], j1 = j + db[d];           if (inside(i1, j1)) {             int u = codif(i, j), v = codif(i1, j1);             if ((i + j) & 1) swap(u, v);             edges[u].push_back(v);             edges[v].push_back(u);             C[u][v] = (ma[i][j] != ma[i1][j1]);             R[u][v] = 1;             F[u][v] = 0;             C[v][u] = -(ma[i][j] != ma[i1][j1]);             R[v][u] = 0;             F[v][u] = 0;           }         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if ((i + j) & 1) {           int u = codif(i, j);           edges[u].push_back(U);           edges[U].push_back(u);           C[u][U] = 0;           R[u][U] = 1;           F[u][U] = 0;           C[U][u] = 0;           R[U][u] = 0;           F[U][u] = 0;         } else {           int u = codif(i, j);           edges[1].push_back(u);           edges[u].push_back(1);           C[1][u] = 0;           R[1][u] = 1;           F[1][u] = 0;           C[u][1] = 0;           R[u][1] = 0;           F[u][1] = 0;         }     cout << minCostMaxFlow() / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(2 * n);       for (auto &it : a) cin >> it;       vector<int> kop(n);       vector<int> ARR;       for (int i = 0; i < 2 * n; ++i) {         if (!kop[a[i] - 1]) {           kop[a[i] - 1] = true;           ARR.push_back(a[i]);         }       }       for (auto it : ARR) cout << it <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (1LL << 60);   long long dp[1 << 22];   struct node {     int x, k, p;   } f[110];   int cmp(node x, node y) { return x.k < y.k; }   long long ans;   int main() {     int n, m, b;     scanf( %d%d%d , &n, &m, &b);     int l = 1 << m;     for (int i = 1; i <= l; i++) {       dp[i] = inf;     }     int cnt;     for (int i = 1; i <= n; i++) {       f[i].p = 0;       int x;       scanf( %d%d%d , &f[i].x, &f[i].k, &cnt);       for (int j = 0; j < cnt; j++) {         scanf( %d , &x);         f[i].p |= (1 << (x - 1));       }     }     ans = inf;     sort(f + 1, f + n + 1, cmp);     for (int i = 1; i <= n; i++) {       for (int j = 0; j < l; ++j) {         dp[j | f[i].p] = min(dp[j] + f[i].x, dp[j | f[i].p]);       }       ans = min(ans, dp[l - 1] + (long long)f[i].k * b);     }     if (ans >= inf) {       printf( -1 n );     } else {       printf( %lld , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long INF = 1000000000;   template <class T>   T read(T &x) {     char c;     int flag = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag *= -1;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= flag;     return x;   }   int dep[100005];   int fa[100005];   vector<int> adj[100005];   void dfs(int x, int f) {     for (int i : adj[x]) {       if (i == f) continue;       fa[i] = x;       dep[i] = dep[x] + 1;       dfs(i, x);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1);     int root = 1;     for (int i = 1; i <= n; ++i)       if (dep[root] < dep[i]) root = i;     memset(dep, 0, sizeof dep);     ;     dfs(root, -1);     int tar = root;     for (int i = 1; i <= n; ++i)       if (dep[tar] < dep[i]) tar = i;     vector<int> v;     while (tar != root) {       v.push_back(tar);       tar = fa[tar];     }     v.push_back(root);     if (v.size() != (k << 1) + 1) return cout <<  No  << endl, 0;     memset(dep, 0, sizeof dep);     ;     root = v[k];     dfs(root, -1);     for (int i = 1; i <= n; ++i) {       if (dep[i] == k) continue;       int sz = adj[i].size() - 1 + (root == i);       if (sz < 3) return cout <<  No  << endl, 0;     }     cout <<  Yes  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1003][1003], a[1003];   pair<pair<int, int>, int> from[1003][1003];   vector<pair<int, int> > sol;   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) cin >> a[i];     if (N % 2 == 0) {       N++;       a[N] = 0;     }     memset(dp, 0x3f3f3f3f, sizeof(dp));     dp[1][1] = 0;     for (int i = 3; i <= N; i += 2) {       for (int j = 1; j <= i - 2; j++) {         if (dp[i - 2][j] + max(a[j], a[i - 1]) < dp[i][i]) {           dp[i][i] = dp[i - 2][j] + max(a[j], a[i - 1]);           from[i][i] = make_pair(make_pair(j, i - 1), j);         }         if (dp[i - 2][j] + max(a[j], a[i]) < dp[i][i - 1]) {           dp[i][i - 1] = dp[i - 2][j] + max(a[j], a[i]);           from[i][i - 1] = make_pair(make_pair(j, i), j);         }         if (dp[i - 2][j] + max(a[i], a[i - 1]) < dp[i][j])           ;         {           dp[i][j] = dp[i - 2][j] + max(a[i], a[i - 1]);           from[i][j] = make_pair(make_pair(i, i - 1), j);         }       }     }     int best = 0x3f3f3f3f, missing;     for (int i = 1; i <= N; i++)       if (dp[N][i] + a[i] < best) {         best = dp[N][i] + a[i];         missing = i;       }     printf( %d n , best);     if (a[missing]) sol.push_back(make_pair(missing, 0));     int start = N;     while (start != 1) {       int x2 = from[start][missing].first.first;       int x3 = from[start][missing].first.second;       sol.push_back(make_pair(x2, x3));       missing = from[start][missing].second;       start -= 2;     }     for (int i = sol.size() - 1; i >= 0; i--) {       if (sol[i].second)         printf( %d %d n , sol[i].first, sol[i].second);       else         printf( %d n , sol[i].first);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int bit[MAXN + 100], ans[MAXN], _pos[MAXN];   vector<pair<int, int> > _query[MAXN];   vector<int> d[MAXN];   void upd(int id) {     for (; id <= MAXN; id += id & (-id)) bit[id]++;     return;   }   int get(int id) {     int now = 0;     for (; id > 0; id = id & (id - 1)) now += bit[id];     return now;   }   int main() {     ios::sync_with_stdio(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       _pos[x] = i + 1;     }     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       _query[y].push_back({i, x});     }     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j += i)         d[max(_pos[i], _pos[j])].push_back(min(_pos[i], _pos[j]));     for (int i = 1; i <= n; i++) {       for (auto j : d[i]) upd(j);       for (auto j : _query[i]) ans[j.first] = get(i) - get(j.second - 1);     }     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int q, n;     cin >> q;     while (q--) {       cin >> n;       vector<int> a(1 + n), answer(1 + n, 0);       map<int, unordered_set<int> > m;       vector<bool> vis(n + 1, false);       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       for (int i = 1; i <= n; ++i) {         if (!vis[i]) {           int j = i;           vis[i] = true;           while (a[j] != i) {             m[i].insert(j);             j = a[j];             vis[j] = true;           }           m[i].insert(j);         }       }       for (auto p : m) {         int temp = p.second.size();         answer[p.first] = temp;         for (auto r : p.second) {           answer[r] = temp;         }       }       for (int i = 1; i <= n; ++i) cout << answer[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #include<unordered_set>   using namespace std;   #define ll long long int   #define f1(i,n) for(i=0;i<n;i++)   #define f2(i,a,n) for(i=n-1;i>=a;i--)   #define f3(i,a,n) for(i=a;i<n;i++)   #define vl vector<long long int>   #define um unordered_map<ll,ll>   #define us unordered_set<ll>   #define pb push_back   #define mp make_pair   #define sv(v) sort(v.begin(),v.end())   #define rv(v) reverse(v.begin(),v.end())   #define sa(v,n) sort(v,v+n)   #define ra(v,n) sort(v,v+n,greater<int>())   #define mod 1000000007         void solution(){    ll k{},kg{},l{},h{},r{},u{},n=0,m{},p{},x=0,y{},o=0,sum=0,sum1{},pos{},ch=0,c1=0,c2=0,i=0,j=0,ans=0,a{},b=0,c=0,i1,i2,p1,q,d=0,w,result{},avg{};    string s,s1,s2;    cin>>n;    vl v,v1;    //map<ll,ll> mp;    f1(i,n){     cin>>x;     if(x%2==0) v.pb(x);     else v1.pb(x);         }    f1(i,v.size()) cout<<v[i]<<   ;    f1(i,v1.size()) cout<<v1[i]<<   ;    cout<<endl;       }   //nobody read comments!   int main() {    ios_base::sync_with_stdio(false);       cin.tie(NULL);    ll t=1;       cin>>t;       while(t--)       solution();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     long long n, m, k, l;     scanf( %lld%lld%lld%lld , &n, &m, &k, &l);     n /= m;     m = (m + k + l - 1) / m;     printf( %lld n , (n >= m) ? m : -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> even_bag, odd_bag;     int n, all, x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       all += x;       if (x & 1)         odd_bag.push_back(x);       else         even_bag.push_back(x);     }     cout << ((all & 1) ? odd_bag.size() : even_bag.size()) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e5 + 7;   long long n, a[NMAX], b[NMAX];   long long dp[NMAX];   struct linija {     long long a, b;   };   linija c[NMAX];   int sz, cur;   double prijesek_x(int i, int j) {     return (double)(c[i].b - c[j].b) / (c[j].a - c[i].a);   }   void dodaj(linija L) {     c[sz].a = L.a;     c[sz].b = L.b;     while (sz >= 2 && prijesek_x(sz, sz - 1) <= prijesek_x(sz - 1, sz - 2)) {       c[sz - 1].a = c[sz].a;       c[sz - 1].b = c[sz].b;       sz--;     }     sz++;   }   long long dobij(int ide) {     while (cur + 1 < sz && (double)ide > prijesek_x(cur, cur + 1)) cur++;     return 1LL * c[cur].a * ide + 1LL * c[cur].b;   }   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]);     linija L = {b[1], 0};     dodaj(L);     for (int i = 2; i <= n; i++) {       dp[i] = dobij(a[i]);       linija L = {b[i], dp[i]};       dodaj(L);     }     printf( %I64d n , dp[n]);     return 0;   }