#include <bits/stdc++.h>   using namespace std;   using INT = long long;   using pii = pair<int, int>;   const int mod = 1e9 + 7;   int power(int a, int n, int mod, int ans = 1) {     for (; n; n >>= 1, a = (INT)a * a % mod)       if (n & 1) ans = (INT)ans * a % mod;     return ans;   }   int fac[3000111], rev[3000111];   int dp[3000111];   int C(int n, int k) {     if (k < 0 or k > n) return 0;     return (INT)fac[n] * rev[k] % mod * rev[n - k] % mod;   }   void pre() {     for (int i = fac[0] = rev[0] = 1; i < 3000111; i++) {       fac[i] = (INT)fac[i - 1] * i % mod;     }     rev[3000111 - 1] = power(fac[3000111 - 1], mod - 2, mod);     for (int i = 3000111 - 2; i >= 0; i--)       rev[i] = (INT)rev[i + 1] * (i + 1) % mod;   }   int main() {     pre();     int n, q;     cin >> n >> q;     dp[0] = n;     for (int i = 1; i <= n; i++) {       dp[1] = (dp[1] + 3 * i) % mod;       dp[2] = (C(i * 3, 2) + dp[2]) % mod;     }     int r3 = power(3, mod - 2, mod);     for (int i = 3; i <= 3 * n; i++) {       dp[i] = (C(3 * n, i - 2) + 3LL * C(3 * n, i - 1) + 3LL * C(3 * n, i) +                C(3 * n, i + 1) - 3LL * dp[i - 1] - dp[i - 2]) %               mod;       dp[i] = (INT)dp[i] * r3 % mod;       if (dp[i] < 0) dp[i] += mod;     }     while (q--) {       int x;       scanf( %d , &x);       printf( %d n , dp[x]);     }     return 0;   }


#include <bits/stdc++.h>   int a[(1 << 22) + 1];   int n, m;   bool vis[(1 << 22) + 1][2];   bool yes[(1 << 22) + 1];   int mask;   void dfs(int now, int p) {     if (vis[now][p]) return;     vis[now][p] = true;     if (p == 0)       dfs(now, 1);     else {       for (int j = 0; j < n; j++) {         int jj = 1 << j;         if (!(jj & now)) dfs(now | jj, 1);       }       if (yes[now ^ mask]) dfs(now ^ mask, 0);     }   }   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 0; i < (1 << n); i++) yes[i] = vis[i][0] = vis[i][1] = false;     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);       yes[a[i]] = true;     }     mask = (1 << n) - 1;     for (int i = 0; i < m; i++) {       if (!vis[a[i]][0]) {         ans++;         dfs(a[i], 0);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 3030;   int head[MAX_N], current, n, siz[MAX_N][MAX_N], fa[MAX_N][MAX_N];   long long f[MAX_N][MAX_N];   struct edge {     int to, nxt;   } edges[MAX_N << 1];   void addpath(int src, int dst) {     edges[current].to = dst, edges[current].nxt = head[src];     head[src] = current++;   }   void dfs(int u, int org) {     siz[org][u] = 1;     for (int i = head[u]; i != -1; i = edges[i].nxt)       if (edges[i].to != fa[org][u])         fa[org][edges[i].to] = u, dfs(edges[i].to, org),         siz[org][u] += siz[org][edges[i].to];   }   long long dp(int u, int v) {     if (u == v) return 0;     if (f[u][v]) return f[u][v];     return (f[u][v] = max(dp(u, fa[u][v]), dp(v, fa[v][u])) +                       1LL * siz[u][v] * siz[v][u]);   }   int main() {     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (int i = 1, u, v; i <= n - 1; i++)       scanf( %d%d , &u, &v), addpath(u, v), addpath(v, u);     for (int i = 1; i <= n; i++) dfs(i, i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) ans = max(ans, dp(i, j));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     register char c = getchar();     register bool f = 0;     while (!isdigit(c)) f ^= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   template <class T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void print(T x, char c) {     print(x), putchar(c);   }   template <class T>   inline T gcd(T n, T m) {     return m ? gcd(m, n % m) : n;   }   template <const int N>   struct Prime : std::vector<int> {     Prime() {       std::vector<bool> vis(N);       for (int i = 2; i < N; i++) {         if (!vis[i]) this->push_back(i);         for (int j : *this) {           if (i * j >= N) break;           vis[i * j] = true;           if (!(i % j)) break;         }       }     }   };   const int N = 1e5 + 10, M = 1e7 + 10;   int n, k, A, B, C, a[N], deg[N], v[N][8], l[N], f[M];   Prime<10000> prime;   std::vector<int> pos;   std::unordered_map<int, int> primeid;   void affect(int *v, int l, int x) {     std::function<void(int, int)> dfs = [&](int i, int s) {       if (i == l) {         if (s != 1) f[s] += x;         return;       }       dfs(i + 1, s);       dfs(i + 1, s * v[i]);     };     dfs(0, 1);   }   int query(int *v, int l) {     int res = 0;     std::function<void(int, int)> dfs = [&](int i, int s) {       if (i == l) {         res += s < 0 ? -f[-s] : f[s];         return;       }       dfs(i + 1, s);       dfs(i + 1, s * -v[i]);     };     dfs(0, -1);     return res;   }   int main() {     read(n), read(k);     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 0; i < prime.size(); i++) primeid[prime[i]] = i;     for (int x, i = 1; i <= n; i++) {       x = a[i];       for (int j = 0; prime[j] * prime[j] <= x; j++)         if (x % prime[j] == 0) {           v[i][l[i]++] = prime[j];           while (x % prime[j] == 0) x /= prime[j];         }       if (x != 1) v[i][l[i]++] = x;     }     for (int i = 1; i <= n; i++) affect(v[i], l[i], 1);     for (int i = 1; i <= n; i++) deg[i] = query(v[i], l[i]) - 1;     for (int i = 1; i <= n; i++) affect(v[i], l[i], -1);     int fulldeg = 0;     for (int i = 1; i <= n; i++) fulldeg += deg[i] == n - 1;     if (fulldeg >= k) {       for (int i = 1; i <= n; i++)         if (deg[i] == n - 1) pos.push_back(i);     } else {       for (int i = 1; i <= n; i++)         if (n - 1 - deg[i] >= 2) {           A = i;           for (int j = 1; j <= n; j++)             if (j != A && gcd(a[i], a[j]) == 1) {               if (!B) {                 B = j;                 continue;               }               if (!C) {                 C = j;                 continue;               }               break;             }           break;         }       if (A) {         if (!(B && C))           printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 120), exit(0);         auto getp = [&](int cur) {           std::vector<int> res;           for (int i = 1; i <= n && res.size() < cur; i++)             if (i != A && i != B && i != C) {               res.push_back(i);             }           return res;         };         auto solve = [&](int cur) {           int res = 0;           std::vector<int> p = getp(cur);           for (int i : p) affect(v[i], l[i], 1);           for (int i : p) deg[i] = query(v[i], l[i]) - 1;           for (int i : p) affect(v[i], l[i], -1);           for (int i : p) res += deg[i] != cur - 1;           return res;         };         int l = 1, r = n - 3, mid, res = -1;         while (l <= r) {           mid = (l + r) >> 1;           solve(mid) + 3 >= k ? (res = mid, r = mid - 1) : (l = mid + 1);         }         if (!(~res))           printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 144), exit(0);         int now = solve(res);         std::vector<int> p = getp(res);         for (int i : p)           if (deg[i] != res - 1) pos.push_back(i);         if (pos.size() < k) pos.push_back(A);         if (pos.size() < k) pos.push_back(B);         if (pos.size() < k) pos.push_back(C);       } else {         uint64_t all = 0;         std::vector<int> match(n + 1);         std::vector<uint64_t> hsh(n + 1);         std::map<uint64_t, int> map;         std::map<int, uint64_t> sta;         std::mt19937_64 rng(             20040725 ^             std::chrono::steady_clock::now().time_since_epoch().count());         for (int i = 1; i <= n; i++)           hsh[i] = rng(), all ^= hsh[i], map[hsh[i]] = i;         for (int i = 1; i <= n; i++)           for (int x = 1; x < (1 << l[i]); x++) {             int s = 1;             for (int j = 0; j < l[i]; j++)               if ((x >> j) & 1) s *= v[i][j];             sta[s] ^= hsh[i];           }         for (int i = 1; i <= n; i++)           if (deg[i] == n - 2) {             uint64_t tem = all;             for (int x = 1; x < (1 << l[i]); x++) {               int s = 1;               for (int j = 0; j < l[i]; j++)                 if ((x >> j) & 1) s *= v[i][j];               tem ^= sta[s];             }             match[i] = map[tem];           }         for (int i = 1; i <= n; i++)           if (!match[i] || i < match[i]) pos.push_back(i);       }     }     if (!(pos.size() >= k))       printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 186), exit(0);     for (int i = 0; i < k; i++) print(pos[i],    n [i + 1 == k]);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int toN = 58;   int pn, p[10000];   int n, a[10000], omask[10000];   int dp[110][1 << 18];   int ans[110][1 << 18];   bool isPrime(int n) {     if (n == 2) return true;     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   int main() {     pn = 0;     for (int i = 2; i <= toN; ++i)       if (isPrime(i)) p[pn++] = i;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i <= n; ++i) {       for (int m = 0; m < (1 << pn); ++m) dp[i][m] = inf;     }     dp[0][0] = 0;     for (int i = 1; i <= toN; ++i) {       omask[i] = 0;       for (int j = 0; j < pn; ++j)         if (i % p[j] == 0) omask[i] |= (1 << j);     }     for (int m = 0; m < (1 << pn); ++m) {       for (int j = 1; j <= toN; ++j)         if ((omask[j] & m) == 0) {           for (int i = 0; i < n; ++i)             if (dp[i][m] < inf) {               int nm = (m | omask[j]);               if (dp[i + 1][nm] > dp[i][m] + abs(j - a[i])) {                 dp[i + 1][nm] = dp[i][m] + abs(j - a[i]);                 ans[i + 1][nm] = j;               }             }         }     }     int v = 0;     for (int m = 0; m < (1 << pn); ++m)       if (dp[n][v] > dp[n][m]) v = m;     vector<int> ansv;     for (int i = n; i >= 1; --i) {       ansv.push_back(ans[i][v]);       v = v - omask[ans[i][v]];     }     reverse((ansv).begin(), (ansv).end());     for (__typeof(ansv.begin()) it = ansv.begin(); it != ansv.end(); ++it)       cout << *it <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int INF = 0x3f3f3f3f;   int dp[N];   struct node {     int v, id;   } a[N][2];   void up1(int sta, int cost, int i) {     if (a[sta][0].v > cost) {       a[sta][1] = a[sta][0];       a[sta][0] = {cost, i};     } else if (a[sta][1].v > cost) {       a[sta][1] = {cost, i};     }   }   int num = -1, now, cs;   pair<int, int> ans;   void up2(node x, node y, int sta) {     if (x.v == INF || y.v == INF) return;     now = x.v + y.v;     if (dp[sta] > num || (dp[sta] == num && cs > now)) {       num = dp[sta];       cs = now;       ans = {x.id, y.id};     }   }   int main() {     int k, n, m, sta, v, cost;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &k);       sta = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &v);         sta |= 1 << (v - 1);       }       dp[sta]++;     }     int mx = 0;     for (int i = 0; i < 9; i++) {       for (int j = (1 << 9) - 1; j >= 0; j--) {         if ((1 << i) & j) dp[j] = dp[j] + dp[j ^ (1 << i)];         mx = max(mx, dp[j]);       }     }     for (int j = 0; j < (1 << 9); j++) a[j][0].v = a[j][1].v = INF;     for (int i = 1; i <= m; i++) {       scanf( %d %d , &cost, &k);       sta = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &v);         sta |= 1 << (v - 1);       }       up1(sta, cost, i);     }     for (int i = 0; i < (1 << 9); i++) {       for (int j = 0; j < (1 << 9); j++) {         if (i == j)           up2(a[i][0], a[i][1], i);         else           up2(a[i][0], a[j][0], i | j);       }     }     printf( %d %d n , ans.first, ans.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double vb, vs;   double x[105];   double tagx, tagy;   double cal(int p) { return sqrt((x[p] - tagx) * (x[p] - tagx) + tagy * tagy); }   int cmp(double x) {     if (x < (-1e-6))       return -1;     else if (x > 1e-6)       return 1;     else       return 0;   }   int main() {     scanf( %d%lf%lf , &n, &vb, &vs);     for (int i = 0; i < n; i++) scanf( %lf , &x[i]);     scanf( %lf%lf , &tagx, &tagy);     double ans = (double)(0x3f3f3f3f);     int pos;     double min_cal;     for (int i = 1; i < n; i++) {       double time = (x[i] / vb) + (cal(i) / vs);       if (cmp(time - ans) == -1) {         ans = time;         pos = i;         min_cal = cal(i);       } else if (cmp(time - ans) == 0) {         if (cmp(cal(i) - min_cal) == -1) {           ans = time;           pos = i;           min_cal = cal(i);         }       }     }     printf( %d n , pos + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int add(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   int sub(int a, int b) {     a -= b;     return a < 0 ? a + mod : a;   }   int mul(int a, int b) { return (long long)a * b % mod; }   int qpow(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ret = mul(ret, a);     return ret;   }   const int inv2 = qpow(2, mod - 2);   const int N = 1e6 + 5;   int n;   int hed[N], cnt, to[N], nxt[N];   inline void adde(int u, int v) {     ++cnt;     to[cnt] = v, nxt[cnt] = hed[u];     hed[u] = cnt;   }   int f[N][2];   int ans = 0;   inline void dfs(int x, int pre) {     int way0 = 1;     for (int i = hed[x]; i; i = nxt[i]) {       int v = to[i];       if (v == pre) continue;       dfs(v, x);       way0 = mul(way0, add(mul(inv2, f[v][0]), f[v][1]));     }     int way1 = sub(1, way0);     f[x][0] = way0;     f[x][1] = way1;     ans = add(ans, way1);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adde(u, v), adde(v, u);     }     dfs(1, 0);     cout << mul(ans, qpow(2, n)) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int MAXN = 2000 + 5;   int dp[MAXN][MAXN] = {0};   int previous[MAXN] = {0};   void calculatePrevious(const string &s, const string &p) {     int sSize = s.length();     int pSize = p.length();     for (int i = 0; i < sSize; ++i) {       previous[i] = -2;       int currentP = pSize - 1;       int currentS = i;       while (currentP >= 0 && currentS >= 0) {         while (currentS >= 0 && s[currentS] != p[currentP]) {           currentS--;         }         if (currentS >= 0) {           currentP--;           currentS--;         }       }       if (currentP == -1) {         previous[i] = currentS;       }     }   }   int main() {     string s, p;     cin >> s >> p;     int sSize = s.length();     int pSize = p.length();     calculatePrevious(s, p);     for (int i = 1; i <= sSize; ++i) {       for (int j = 0; j < sSize; ++j) {         dp[i][j] = dp[i - 1][j];         if (j > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);         int prev = previous[i - 1];         if (prev != -2) {           int toDelete = (i - 1) - prev - pSize;           int newDelete = j - toDelete;           int newIndex = prev + 1;           if (newDelete >= 0 && newIndex >= newDelete) {             dp[i][j] = max(dp[i][j], 1 + dp[newIndex][newDelete]);           }         }       }     }     for (int i = 0; i < sSize; ++i) cout << dp[sSize][i] <<    ;     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, j, i = 0, count = 0, max = 100000000;     string s1, s2;     cin >> n >> m >> s1 >> s2;     vector<int> a, b;     while (i + n <= m) {       count = 0;       for (j = 0; j < n; j++) {         if (s1[j] != s2[i + j]) {           a.push_back(j + 1);           count++;         }       }       if (count < max) {         max = count;         b = a;       }       i++;       a.clear();     }     cout << max << endl;     for (i = 0; i < max; i++) cout << b[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void proc_status() {     ifstream t( /proc/self/status );     cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())          << endl;   }   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   inline T read() {     register T sum(0), fg(1);     register char ch(getchar());     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fg = -1;     for (; isdigit(ch); ch = getchar()) sum = sum * 10 -  0  + ch;     return sum * fg;   }   const int MOD = (int)1e9 + 7;   const int MAXN = (int)1e6;   int n;   char s0[MAXN + 5];   inline void input() { scanf( %s , s0 + 1), n = strlen(s0 + 1); }   namespace PAM {   const int MAX_NODE = MAXN * 2, alpha = 26;   int fail[MAX_NODE + 5], trans[MAX_NODE + 5][alpha], nxt[MAX_NODE + 5], cnt;   int len[MAX_NODE + 5], delta[MAX_NODE + 5];   int rt0, rt1, lst;   int S[MAX_NODE + 5], N = 0;   inline void init() {     S[0] = -1;     cnt = 1, lst = 0;     memset(trans[0], 0, sizeof trans[0]);     memset(trans[1], 0, sizeof trans[1]);     len[0] = 0, len[1] = -1;     fail[0] = 1;   }   inline int new_node(int l) {     len[++cnt] = l;     fail[cnt] = 0;     memset(trans[cnt], 0, sizeof trans[cnt]);     return cnt;   }   inline int extend(int ch) {     int p = lst;     S[++N] = ch;     while (S[N - len[p] - 1] != S[N]) p = fail[p];     int np = -1;     if (!trans[p][ch]) {       np = new_node(len[p] + 2);       int t = fail[p];       while (S[N - len[t] - 1] != S[N]) t = fail[t];       fail[np] = trans[t][ch];       delta[np] = len[np] - len[fail[np]];       nxt[np] = delta[np] == delta[fail[np]] ? nxt[fail[np]] : fail[np];       trans[p][ch] = np;     } else       np = trans[p][ch];     return lst = np;   }   }  // namespace PAM   inline void solve() {     static int s[MAXN + 5];     for (int i = 1; i <= n / 2; ++i) {       s[i * 2 - 1] = s0[i] -  a ;       s[i * 2] = s0[n - i + 1] -  a ;     }     static int nd[MAXN + 5];     PAM::init();     for (int i = 1; i <= n; ++i) nd[i] = PAM::extend(s[i]);     static int f[MAXN + 5], g[MAXN + 5];     f[0] = 1;     for (int i = 1; i <= n; ++i)       for (int p = nd[i]; p; p = PAM::nxt[p]) {         g[p] = f[i - PAM::len[PAM::nxt[p]] - PAM::delta[p]];         if (PAM::delta[p] == PAM::delta[PAM::fail[p]])           (g[p] += g[PAM::fail[p]]) %= MOD;         if (i % 2 == 0) (f[i] += g[p]) %= MOD;       }     printf( %d n , (f[n] + MOD) % MOD);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int INF = 0x3f3f3f3f, N = 2000005, M = 2000005, MOD = 1e9 + 7;   int sgn(double x) { return x < -eps ? -1 : (x < eps ? 0 : 1); }   int Rand(int x) { return rand() * rand() % x + 1; }   vector<int> G[N];   int dep[N];   double ans = 0;   void dfs(int x, int _fa, int _dep) {     dep[x] = _dep;     ans += 1. / dep[x];     for (auto v : G[x])       if (v != _fa) {         dfs(v, x, _dep + 1);       }   }   int Solve() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v), G[v].push_back(u);     }     dfs(1, 0, 1);     cout << fixed << setprecision(12) << ans << endl;     return 0;   }   void Pre() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     Pre();     while (Solve())       ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:50000000 )   using namespace std;   int tt[1000000], kix[1000000], num[1000000], degree[1000000], black[1000000],       fix[1000000];   vector<int> q, g[1000000];   int pirveli, p, i, j, n, m, k, a, b;   int par[100005][20];   long long ans[1000000];   void go(int x, int prev = -1) {     fix[x] = 1;     q.push_back(x);     for (int i = 0; i < g[x].size(); i++) {       int nxt = g[x][i];       if (nxt == prev) continue;       if (fix[nxt] == 0) {         go(nxt, x);         continue;       }       if (num[nxt] != -1) continue;       for (int j = q.size() - 1; j >= 0; j--) {         num[q[j]] = nxt;         if (q[j] == nxt) break;       }     }     q.pop_back();   }   void DFS(int v, int prev, int deg, int raod) {     kix[v] = 1;     degree[v] = deg;     if (tt[v] != 1) raod++;     black[v] = raod;     par[v][0] = num[prev];     for (int j = 1; j <= 19; j++)       if (par[v][j - 1] == -1)         par[v][j] = -1;       else         par[v][j] = par[par[v][j - 1]][j - 1];     for (int i = 0; i < g[v].size(); i++) {       int nxt = g[v][i];       if (nxt == prev) continue;       DFS(nxt, v, deg + 1, raod);     }   }   int LCA(int a, int b) {     for (int i = 18; i >= 0; i--) {       if (degree[a] - (1 << i) >= degree[b]) {         a = par[a][i];       }     }     if (a == b) return a;     for (int i = 18; i >= 0; i--) {       if (par[a][i] != par[b][i]) {         a = par[a][i];         b = par[b][i];       }     }     return par[a][0];   }   int main() {     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     for (i = 0; i < n; i++) num[i] = -1;     go(0);     for (i = 0; i <= n; i++)       for (j = 0; j <= 20; j++) par[i][j] = -1;     for (i = 0; i < n; i++) {       if (num[i] == -1 || num[i] == i) continue;       for (j = 0; j < g[i].size(); j++) g[num[i]].push_back(g[i][j]);     }     for (i = 0; i < n; i++)       if ((num[i] == -1 || num[i] == i)) {         for (j = 0; j < g[i].size(); j++) {           int nxt = g[i][j];           if (num[nxt] == i) {             g[i][j] = g[i].back();             g[i].pop_back();             j--;           } else if (num[nxt] == -1)             continue;           else             g[i][j] = num[nxt];         }       }     if (num[0] == -1)       pirveli = 0;     else       pirveli = num[0];     for (i = 0; i < n; i++)       if (num[i] == -1) {         num[i] = i;         tt[i] = 1;       }     DFS(pirveli, -1, 0, 0);     ans[0] = 1;     for (i = 1; i <= n; i++) ans[i] = ans[i - 1] * 2 % 1000000007;     cin >> k;     while (k--) {       cin >> a >> b;       a = num[a - 1];       b = num[b - 1];       if (degree[a] < degree[b]) swap(a, b);       p = LCA(a, b);       p = num[p];       cout << ans[black[a] + black[b] - 2 * black[p] + (tt[p] == 0)] << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long HASH = 1e16 + 7;   const long long INF = 1e9;   long long tavan(long long a, long long b) {     return b ? (tavan(a * a, b >> 1) * (b & 1 ? a : 1)) : 1;   }   long long gcd(long long a, long long b) {     return (a < b) ? gcd(b, a) : ((a % b == 0) ? b : gcd(b, a % b));   }   bool isprime(long long x) {     for (long long i = 2; i <= sqrt(x); i++)       if (!(x % i)) return false;     return true;   }   ifstream fin( input.txt );   ofstream fout( output.txt );   long long n, a[1100];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int t = 0; t < n + 1000; t++) {       bool ex = 1;       for (int i = 0; i < n; i++) {         if (i % 2 == 0)           a[i]++;         else           a[i]--;         if (a[i] == n) a[i] = 0;         if (a[i] == -1) a[i] = n - 1;         if (a[i] != i) ex = 0;       }       if (ex) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxl = 26;   const int Maxn = 30005;   const int Maxstr = 200005;   const int Inf = 2000000007;   char str[Maxstr];   int t;   int n, m, k;   int freq[Maxl];   bool dp[Maxn];   int res;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       scanf( %s , str);       fill(freq, freq + Maxl, 0);       for (int i = 0; i < k; i++) freq[str[i] -  A ]++;       res = Inf;       int mx = max(n, m);       for (int i = 0; i < Maxl; i++) {         int tot = 0;         for (int j = 0; j < Maxl; j++)           if (j != i) tot += freq[j];         int mn = tot;         fill(dp, dp + mx + 1, false);         dp[0] = true;         for (int j = 0; j < Maxl; j++)           if (j != i)             for (int l = mx; l >= 0; l--)               if (dp[l])                 if (l + freq[j] > mx)                   mn = min(mn, l + freq[j]);                 else                   dp[l + freq[j]] = true;         for (int l = 0; l <= mx; l++)           if (dp[l]) {             int a = l, b = tot - l;             int mya = max(0, n - a), myb = max(0, m - b);             if (mya + myb <= freq[i]) res = min(res, mya * myb);             mya = max(0, n - b), myb = max(0, m - a);             if (mya + myb <= freq[i]) res = min(res, mya * myb);           }         int a = mn, b = tot - mn;         int mya = max(0, n - a), myb = max(0, m - b);         if (mya + myb <= freq[i]) res = min(res, mya * myb);         mya = max(0, n - b), myb = max(0, m - a);         if (mya + myb <= freq[i]) res = min(res, mya * myb);       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace {   void Solve(int) {     const set<string> bins = { AND ,  OR ,  XOR };     int n;     cin >> n;     vector<string> type(n);     vector<int> lef(n, -1), rig(n, -1);     for (int i = 0, __i = n; i < __i; ++i) {       cin >> type[i] >> lef[i];       if (type[i] !=  IN ) --lef[i];       if (bins.count(type[i])) {         cin >> rig[i];         --rig[i];       }     }     auto eval = [](const string& t, bool a, bool b) {       if (t ==  AND )         return a and b;       else if (t ==  OR )         return a or b;       else         return (bool)(a ^ b);     };     vector<bool> val(n), flip(n);     function<void(int)> dfs1 = [&](int at) {       if (type[at] ==  IN ) {         val[at] = lef[at];       } else {         dfs1(lef[at]);         if (bins.count(type[at])) {           dfs1(rig[at]);           val[at] = eval(type[at], val[lef[at]], val[rig[at]]);         } else {           val[at] = !val[lef[at]];         }       }     };     dfs1(0);     function<void(int)> dfs2 = [&](int at) {       if (type[at] ==  IN )         flip[at] = true;       else if (type[at] ==  NOT ) {         flip[at] = true;         dfs2(lef[at]);       } else {         if (val[at] != eval(type[at], val[lef[at]] ^ 1, val[rig[at]])) {           flip[at] = true;           dfs2(lef[at]);         }         if (val[at] != eval(type[at], val[lef[at]], val[rig[at]] ^ 1)) {           flip[at] = true;           dfs2(rig[at]);         }       }     };     dfs2(0);     for (int i = 0, __i = n; i < __i; ++i)       if (type[i] ==  IN ) cout << (val[0] ^ flip[i]);     cout <<   n ;   }   void Init() {     ios::sync_with_stdio(false);     cin.tie(nullptr);   }   }  // namespace   int32_t main() {     Init();     int tests = 1;     for (int test = 1, __test = tests + 1; test < __test; ++test) Solve(test);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000 + 1;   const int INF = numeric_limits<int>::max() / 2;   pair<int, int> P[MAX_N];   pair<int, int> prefix[MAX_N], suffix[MAX_N];   int N;   long long square(int first) { return 1LL * first * first; }   bool valid(long long M) {     long long bestY, bestXY;     int i = 1, j = 1;     while (i <= N) {       while (square(P[i].first - P[j].first) > M) j++;       assert(j <= i);       assert(square(P[i].first - P[j].first) <= M);       int maxY = -INF;       int minY = INF;       bool changed = false;       if (j > 1) {         changed = true;         minY = min(minY, prefix[j - 1].first);         maxY = max(maxY, prefix[j - 1].second);       }       if (i < N) {         changed = true;         minY = min(minY, suffix[i + 1].first);         maxY = max(maxY, suffix[i + 1].second);       }       if (changed) {         bestY = square(maxY - minY);         bestXY = max(square(maxY), square(minY)) +                  max(square(P[i].first), square(P[j].first));       } else         bestY = 0, bestXY = 0;       if (bestY <= M && bestXY <= M) return true;       i++;     }     return false;   }   void makePrefixSuffix() {     pair<int, int> p = {INF, -INF};     for (int i = 1; i <= N; ++i) {       p.first = min(p.first, P[i].second);       p.second = max(p.second, P[i].second);       prefix[i] = p;     }     p = {INF, -INF};     for (int i = N; i >= 1; i--) {       p.first = min(p.first, P[i].second);       p.second = max(p.second, P[i].second);       suffix[i] = p;     }   }   long long binarySearch() {     long long l = 0;     long long r = 1LL * INF * INF >> 1;     long long sol = -1;     while (l <= r) {       long long m = (l + r) / 2;       if (valid(m)) {         sol = m;         r = m - 1;       } else         l = m + 1;     }     return sol;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N;     for (int i = 1; i <= N; ++i) cin >> P[i].first >> P[i].second;     sort(P + 1, P + N + 1);     makePrefixSuffix();     long long sol1 = binarySearch();     for (int i = 1; i <= N; ++i) swap(P[i].first, P[i].second);     sort(P + 1, P + N + 1);     makePrefixSuffix();     long long sol2 = binarySearch();     cout << min(sol1, sol2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[100010];   int y[100010], res[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int num;       scanf( %d%d , &num, &y[i]);       res[i] = 0;       for (int k = 1; k * k <= num; k++)         if (num % k == 0) {           a[k].push_back(i);           res[i]++;           if (k * k != num) {             a[num / k].push_back(i);             res[i]++;           }         }     }     for (int i = 1; i <= 100000; i++)       for (int j = 1; j < a[i].size(); j++)         if (a[i][j] - a[i][j - 1] <= y[a[i][j]]) res[a[i][j]]--;     for (int i = 0; i < n; i++) printf( %d n , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct P {     long long first, second, sum;     P(long long first = 0, long long second = 0, long long sum = 0)         : first(first), second(second), sum(sum) {}     bool operator<(const P &b) const { return first < b.first; }   };   const long long MAX_V = 500100;   const long long MAX_LOG_V = 25;   vector<long long> G[MAX_V];   long long root, V;   long long parent[MAX_LOG_V][MAX_V];   long long depth[MAX_V], ans[MAX_V];   struct vertex {     long long v, di;     vertex(long long v, long long di = 0) : v(v), di(di) {}     bool operator<(const vertex &b) const { return di < b.di; }   };   vector<vertex> depVec[MAX_V];   long long dfs_index = 0;   void dfs(long long v, long long p, long long d) {     parent[0][v] = p;     depth[v] = d;     depVec[d].push_back(vertex(v, ++dfs_index));     for (long long i = 0; i < G[v].size(); i++)       if (G[v][i] != p) dfs(G[v][i], v, d + 1);   }   void init() {     dfs(root, -1, 1);     for (long long k = 0; k + 1 < MAX_LOG_V; k++)       for (long long v = 1; v <= V; v++) {         if (parent[k][v] < 0)           parent[k + 1][v] = -1;         else           parent[k + 1][v] = parent[k][parent[k][v]];       }   }   long long lca(long long u, long long v) {     if (depth[u] > depth[v]) swap(u, v);     for (long long k = 0; k < MAX_LOG_V; k++) {       if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];       if (depth[v] == depth[u]) break;     }     if (u == v) return u;     for (long long k = MAX_LOG_V - 1; k >= 0; k--) {       if (parent[k][u] != parent[k][v]) {         u = parent[k][u];         v = parent[k][v];       }     }     return parent[0][u];   }   void solve(const vector<vertex> &vec) {     vector<P> stk(vec.size() + 1, P(0));     long long sn = 0;     long long d = depth[lca(vec[0].v, vec[1].v)];     stk[sn++] = P(d, 1, d);     ans[vec[1].v] += stk[0].sum;     for (long long i = 2; i < vec.size(); i++) {       long long d = depth[lca(vec[i - 1].v, vec[i].v)];       if (d < 0) {         cout <<  d =   << d << endl;       }       long long x =           lower_bound(stk.begin(), stk.begin() + sn, P(d, -1)) - stk.begin();       if (x == sn) {         stk[sn] = P(d, stk[sn - 1].second + 1, stk[sn - 1].sum + d);         sn++;       } else {         long long cnt = stk[sn - 1].second - (x > 0 ? stk[x - 1].second : 0) + 1;         if (cnt < 0) {           cout <<  stk[sn-1].second =   << stk[sn - 1].second << endl;           cout <<  x =   << x << endl;           cout <<  sn =   << sn << endl;           cout <<  ~ =   << (x > 0 ? stk[x - 1].second : 0) << endl;         }         stk[x] =             P(d, stk[sn - 1].second + 1, (x > 0 ? stk[x - 1].sum : 0) + d * cnt);         sn = x + 1;       }       ans[vec[i].v] += stk[sn - 1].sum;       if (stk[sn - 1].sum < 0) {         cout <<  vec[i].v =   << vec[i].v << endl;         for (long long j = 0; j < sn; j++)           cout <<  stk[  << j <<  ] =   << stk[sn - 1].first <<                    << stk[sn - 1].second <<     << stk[sn - 1].sum << endl;         exit(0);       }     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     cin >> V;     for (long long i = 1; i <= V; i++) {       long long p;       cin >> p;       if (p == 0)         root = i;       else         G[p].push_back(i);     }     init();     for (long long i = 2; i <= V; i++) {       if (depVec[i].empty()) break;       if (depVec[i].size() > 1) {         sort(depVec[i].begin(), depVec[i].end());         solve(depVec[i]);         reverse(depVec[i].begin(), depVec[i].end());         solve(depVec[i]);       }       for (auto j : depVec[i]) {         ans[j.v] += ans[parent[0][j.v]] + depth[j.v] - 1;       }     }     for (long long i = 1; i <= V; i++) {       cout << ans[i] << (i == V ?   n  :    );     }   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = 1e9 + 7;   int dp[107][107];   int par[107][107];   string t =  .,!?  ;   bool check(char c) { return t.find(c) == string::npos; }   void solve() {     int t;     cin >> t;     for (int k = 0; k < t; k++) {       int n;       cin >> n;       vector<string> users;       for (int i = 0; i < n; i++) {         string p;         cin >> p;         users.push_back(p);       }       sort(users.begin(), users.end());       map<string, int> id;       for (int i = 0; i < n; i++) id[users[i]] = i;       memset(dp, 0, sizeof(dp));       for (int i = 0; i < n; i++) dp[0][i] = 1;       memset(par, -1, sizeof(par));       int m;       cin >> m;       string buf;       getline(cin, buf);       vector<string> message;       for (int i = 0; i < m; i++) {         string buf;         getline(cin, buf);         int pos = buf.find( : );         string user = buf.substr(0, pos);         string msg = buf.substr(pos + 1);         message.push_back(msg);         vector<string> w;         int p = 0, l = msg.size();         while (p < l) {           while (p < l && !check(msg[p])) p++;           int q = p;           while (q < l && check(msg[q])) q++;           string word = msg.substr(p, q - p);           if (word !=   ) w.push_back(word);           p = q;         }         int uid = id.count(user) == 0 ? -1 : id[user];         if (uid == -1) {           for (int j = 0; j < n; j++) {             if (find(w.begin(), w.end(), users[j]) != w.end()) continue;             for (int jj = 0; jj < n; jj++) {               if (dp[i][jj] == 1 && (i == 0 || j != jj)) {                 dp[i + 1][j] = 1;                 par[i + 1][j] = jj;               }             }           }         } else {           for (int jj = 0; jj < n; jj++) {             if (dp[i][jj] == 1 && (i == 0 || uid != jj)) {               dp[i + 1][uid] = 1;               par[i + 1][uid] = jj;             }           }         }       }       vector<string> res;       for (int i = 0; i < n; i++)         if (dp[m][i] == 1) {           int p = i, q = m;           while (q > 0) {             res.push_back(users[p]);             p = par[q][p];             q--;           }         }       if (res.empty()) {         cout <<  Impossible  <<   n ;       } else {         reverse(message.begin(), message.end());         for (int i = m - 1; i >= 0; --i) {           ostringstream oss;           oss << res[i];           oss <<  : ;           oss << message[i];           cout << oss.str() <<   n ;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(9);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long f = 1;     for (long long i = 0; i < 100000; i++) {       n += (n % m);       if (n % m == 0) {         f = 0;         break;       }     }     if (!f)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 2e5;   const long long inf = 1e18;   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   template <typename... T>   void writeline(T&&... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   long long add(long long a, long long b) {     long long res = (a + b) % mod;     return (res < 0) ? res + mod : res;   }   long long mul(long long a, long long b) {     long long res = (a * 1LL * b) % mod;     return (res < 0) ? res + mod : res;   }   string binary(long long x) {     string res =   ;     for (long long i = 0; i < 32; i++) res += (1 << i & x) ?  1  :  0 ;     return res;   }   long long in(long long x, long long y, long long z) {     if (y > z) swap(y, z);     return (x >= y && x <= z);   }   long long valid(long long x, long long sum) {     long long s = 0;     while (x) {       s += x % 10;       x /= 10;     }     return s == sum;   }   void solve() {     long long n;     cin >> n;     if (n == 1) {       cout << -1;       return;     }     writeline(n, n + 1, n * (n + 1));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long data = 0, w = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + ch -  0 , ch = getchar();     return data * w;   }   long long n, c, p[1000005], a[1000005];   int main() {     n = read(), c = read();     for (long long i = 1; i <= n; i++) p[i] = read();     long long sum = 0, ans = 0;     for (long long i = 1; i <= n; i++) {       long long s = read();       a[i] = s - p[i] + c * (n - i);       sum += p[i];     }     ans = sum;     sort(a + 1, a + n + 1);     for (long long i = 1; i <= n; i++)       sum += a[i] - (i - 1) * c, ans = min(ans, sum);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, used[100003], m[100003];   string s, ans =  INFINITE ;   void DFS(int v) {     if (used[v] == 1) {       ans =  INFINITE ;       return;     }     used[v] = 1;     if (s[v] ==  < ) {       if (v - m[v] > 0)         DFS(v - m[v]);       else {         ans =  FINITE ;         return;       }     } else {       if (v + m[v] <= n)         DFS(v + m[v]);       else {         ans =  FINITE ;         return;       }     }   }   int main() {     cin >> n >> s;     s =     + s;     for (int k = 1; k <= n; k++) cin >> m[k];     DFS(1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ll t;     cin >> t;     while (t--) {       ll n, m, k;       cin >> n >> m >> k;       k--;       k--;       if (m > n * (n - 1) / 2 || m < n - 1) {         cout <<  nO  <<   n ;         continue;       }       if (k > 1) {         if (m > n - 2) {           cout <<  yEs  <<   n ;         } else           cout <<  nO  <<   n ;       } else if (k == 1) {         if (m == n * (n - 1) / 2) {           cout <<  yEs  <<   n ;         } else           cout <<  nO  <<   n ;       } else if (k == 0) {         if (n == 1)           cout <<  yEs  <<   n ;         else           cout <<  nO  <<   n ;       } else         cout <<  nO  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 10005;   vector<int> g[M];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         int v = g[i][j];         ans += ((int)g[v].size()) - 1;       }     }     cout << ans / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fac[1000001];   int main() {     long long n, ans = 0, c = 0, mx = 0, tmp, tmp2, lg;     cin >> n;     for (long long i = 2; i < n; i++) {       tmp = n / i;       tmp = tmp * (tmp + 1) / 2 - 1;       ans += (tmp * 4);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int Mod = 998244353;   int n, x, y;   int gr[200005];   long long sol;   int main() {     cin >> n;     sol = n;     for (int i = 1; i < n; ++i) {       cin >> x >> y;       gr[x]++;       gr[y]++;       sol = 1LL * sol * gr[x] % Mod * gr[y] % Mod;     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int n, x, trie[2][31 * maxn], cnt[31 * maxn], a[maxn], tot = 1;   inline void insert(int x) {     int p = 1, t;     for (int i = 31; i >= 0; i--) {       t = (1 << i) & x ? 1 : 0;       if (!trie[t][p]) trie[t][p] = ++tot;       p = trie[t][p];       cnt[p]++;     }   }   inline int get_max(int x) {     int p = 1, t, res = 0;     for (int i = 31; i >= 0; i--) {       t = (1 << i) & x ? 1 : 0;       if (trie[t][p] && cnt[trie[t][p]]) {         p = trie[t][p];       } else {         p = trie[t ^ 1][p];         res |= (1 << i);       }       cnt[p]--;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       insert(x);     }     for (int i = 1; i <= n; i++) {       printf( %d%c , get_max(a[i]), i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, s;     cin >> s;     vector<string> g;     for (long long i = 0; i < s.length(); i++) {       a += s[i];       if (s[i] !=  a ) {         b += s[i];       }       if (a.length() + b.length() == s.length()) {         break;       }     }     if (s == a + b) {       cout << a;     } else {       cout <<  :(  << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     return w ? -X : X;   }   int n, m;   int dx[4][5] = {       {2, 1, 0, 0, 0}, {1, 0, 0, 0, -1}, {0, 0, 0, -1, -2}, {1, 0, 0, 0, -1}};   int dy[4][5] = {       {0, 0, -1, 0, 1}, {0, 0, 1, 2, 0}, {-1, 0, 1, 0, 0}, {0, -2, -1, 0, 0}};   char maze[9][9];   int ans = -1;   char as[9][9];   bool check(int x, int y, int dir, char c) {     for (int i = 0; i < 5; i++) {       int nx = x + dx[dir][i];       int ny = y + dy[dir][i];       if (nx < 0 or nx >= n or ny < 0 or ny >= m) {         return 0;       }       if (!(c ==  .  or maze[nx][ny] ==  . )) {         return 0;       }     }     for (int i = 0; i < 5; i++) {       int nx = x + dx[dir][i];       int ny = y + dy[dir][i];       maze[nx][ny] = c;     }     return 1;   }   void dfs(int x, int y, char c) {     if (x == n) {       if (c -  A  > ans) {         ans = c -  A ;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             as[i][j] = maze[i][j];           }         }       }       return;     }     if ((n - x) * m / 5 + c -  A  <= ans) {       return;     }     if (y == m) {       dfs(x + 1, 0, c);       return;     }     for (int i = 0; i < 4; i++) {       if (check(x, y, i, c)) {         dfs(x, y + 1, c + 1);         check(x, y, i,  . );       }     }     dfs(x, y + 1, c);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         maze[i][j] =  . ;       }     }     dfs(0, 0,  A );     printf( %d n , ans);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         printf( %c , as[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const double EPS = 1e-4;   void solve() {     int n;     cin >> n;     vector<long long> a(n);     vector<pair<long long, long long>> diff(n);     for (long long i = 0; i < int(n); i++) cin >> a[i];     for (long long i = 0; i < int(n); i++) diff[i] = {a[i] - i, i};     sort(diff.begin(), diff.end());     long long curr_sum = 0, res = 0;     for (long long i = 1; i < n; ++i) {       if (curr_sum == 0LL && diff[i].first == diff[i - 1].first) {         curr_sum += (a[diff[i].second] + a[diff[i - 1].second]);       } else if (diff[i].first == diff[i - 1].first) {         curr_sum += a[diff[i].second];       } else {         curr_sum = 0;       }       res = max(res, curr_sum);     }     for (long long i = 0; i < int(n); i++) res = max(res, a[i]);     cout << res;     debug() <<   [              <<  diff                  :               << (diff) <<  ]  ;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265359;   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T sqr(T x) {     return x * x;   }   const long long mod = 1000000007;   struct matr {     int maxn;     int n;     long long a[1 << 7][1 << 7];     matr(int _n) {       maxn = 1 << _n;       n = _n;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) a[i][j] = 0;     }     matr operator*(const matr &other) const {       matr res(n);       long long mod2 = mod * mod;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) {           for (int h = 0; h < maxn; h++) {             res.a[i][j] += (a[i][h] * other.a[h][j]);             if (res.a[i][j] >= mod2) res.a[i][j] -= mod2;           }           res.a[i][j] %= mod;         }       return res;     }     vector<long long> operator*(const vector<long long> &row) {       vector<long long> res(maxn);       for (int i = 0; i < maxn; i++) {         for (int j = 0; j < maxn; j++) {           res[i] += (a[i][j] * row[j]) % mod;         }         res[i] %= mod;       }       return res;     }   };   matr gen(int n) {     if (n == 1) {       matr res(n);       res.a[0][1] = 1;       res.a[0][0] = 1;       res.a[1][0] = 1;       return res;     }     matr res(7);     for (int _left = 0; _left < (1 << n); _left++) {       for (int mid = 0; mid < (1 << (n - 1)); mid++) {         int cmid = (mid << 1) | 1 | (1 << n);         for (int _right = 0; _right < (1 << n); _right++) {           bool bad = false;           for (int j = 0; j < n && !bad; j++) {             bad |= bool(_left & (1 << j)) && bool(_right & (1 << j)) &&                    bool(cmid & (1 << j)) && bool(cmid & (1 << (j + 1)));           }           if (!bad) {             res.a[_right][_left]++;           }         }       }     }     return res;   }   int main() {     vector<long long> ans(1 << 7);     ans[1] = 1;     for (int i = 1; i <= 7; i++) {       int n;       cin >> n;       matr x(7), res(7);       x = gen(i);       for (int j = 0; j < (1 << i); j++)         for (int h = 0; h < (1 << i); h++) res.a[j][h] = j == h;       while (n) {         if (n & 1) res = res * x;         x = x * x;         n >>= 1;       }       ans = res * ans;       if (i == 7) break;       for (int j = 0; j < (1 << i); j++) {         ans[j | (1 << i)] = ans[j];         ans[j] = 0;       }     }     cout << ans[(1 << 7) - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Inf = 1000000000000000000ll;   const int inf = 1000000000;   vector<long long> pri, fac;   long long m, x, ans;   void getpri(long long t, vector<long long>& v) {     v.clear();     for (long long i = 2; i * i <= t; ++i) {       if (t % i) continue;       v.push_back(i);       while (t % i == 0) t /= i;     }     if (t != 1) v.push_back(t);     sort(v.begin(), v.end());   }   long long Euler(long long t) {     long long res = t;     for (int i = 0; i < pri.size(); ++i)       if (t % pri[i] == 0) res = res / pri[i] * (pri[i] - 1);     return res;   }   long long mul(long long x, long long y, long long mod) {     long long res = 0;     while (y) {       if (y & 1) (res += x) >= mod && (res -= mod);       (x <<= 1) >= mod && (x -= mod);       y >>= 1ll;     }     return res;   }   long long qpow(long long b, long long p, long long mod) {     long long res = 1ll;     b %= mod;     while (p) {       if (p & 1ll) res = mul(b, res, mod);       b = mul(b, b, mod);       p >>= 1ll;     }     return res;   }   void work(long long md) {     long long f_d = Euler(md);     long long l_d = f_d;     if (l_d > 1) {       for (int j = 0; j < fac.size(); ++j)         while (l_d % fac[j] == 0 && qpow(x, l_d / fac[j], md) == 1) l_d /= fac[j];     }     ans += f_d / l_d;   }   int main() {     scanf( %lld%lld , &m, &x);     getpri(m, pri);     long long eul = Euler(m);     if (eul > 1)       getpri(eul, fac);     else       fac.push_back(1);     for (long long i = 1; i * i <= m; ++i) {       if (m % i) continue;       work(i);       if (i * i != m) work(m / i);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     long long n, k;     cin >> n >> k;     long long altura = ceil((long double)k / n);     cout << altura;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class V>   ostream& operator<<(ostream& s, pair<T, V> a) {     s << a.first <<     << a.second;     return s;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     cin >> T;     for (long long int qq = 1; qq <= T; qq++) {       long long int n;       string a, b;       cin >> n >> a >> b;       vector<long long int> ans;       long long int f = 0, l = n - 1, r = 0;       for (int i = n - 1; i >= 0; i--) {         if (b[i] -  0  != ((a[l] -  0 ) ^ f)) {           if (a[l] != a[r]) a[r] = (a[r] -  0 ) ^ 1 +  0 , ans.push_back(1);           f ^= 1;           ans.push_back(i + 1);           swap(l, r);         }         if (l > r)           l--;         else           l++;       }       cout << ans.size();       for (auto x : ans) cout <<     << x;       cout << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   #define int      long long   #define f(i,n)         for(int i=0;i<(n);++i)   #define fa(i,a,n)      for(int i=a;i<=(n);++i)   #define fd(i,a,n)      for(int i=a;i>=(n);--i)   #define tc       int t;cin>>t;f(testcase,t)   #define ld    long double   #define pii             pair<int,int>   #define mem(a,i)  memset(a,i,sizeof(a))   #define all(x)    x.begin(),x.end()   #define tr(c,i)   for(auto i = c.begin(); i != c.end(); i++)   #define present(c,x)  (c.find(x) != c.end())   #define cpresent(c,x)  (find(allc,x) != c.end())   #define PI 3.1415926535897932   void c_p_c() {    ios_base::sync_with_stdio(false);    cin.tie(0); cout.tie(0);   }      void solve() {    int n;    cin >> n;    int a[n];       map<int, int> m;    f(i, n) {     cin >> a[i];     m[a[i]]++;       }    cout << n - m.begin()->second <<   n ;   }   int32_t main() {       c_p_c();    tc    solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c() {     int n;     cin >> n;     vector<long long> a(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i];     vector<long long> pf(n, a[0]);     for (int(i) = (1); (i) < (n); ++(i)) pf[i] = pf[i - 1] ^ a[i];     map<long long, vector<pair<long long, long long>>> mp;   }   void b() {     int n;     cin >> n;     vector<int> a(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i];     int sum = accumulate((a).begin(), (a).end(), 0);     int best = sum;     sort((a).begin(), (a).end());     for (int(r) = (1); (r) < (n); ++(r)) {       sum -= a[r];       sum -= a[0];       for (int d = 1; d * d <= a[r]; d++) {         if (a[r] % d == 0) {           best = min(best, sum + a[r] / d + a[0] * d);           best = min(best, sum + a[r] / (a[r] / d) + a[0] * (a[r] / d));         }       }       sum += a[r];       sum += a[0];     }     cout << best;   }   int main() {     b();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double mar[100000];   int main() {     double ml, rl;     cin >> ml >> rl;     double m = ml, r = rl;     double save = 0;     if (ml >= 3)       save += 2 * m * (m - 3) + 2 * (m - 2) + 6;     else if (ml == 2)       save += 2;     save *= (sqrt(2) - 2);     double ans = m * (m + 1) + m * (m + 1) * (2 * m + 1) / 3 - 2 * (m);     ans += save;     ans *= r;     ans /= (m * m);     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int n, x;     cin >> n;     vector<vector<int>> adj(n);     for (int i = 1; i < n; i++)       cin >> x, x--, adj[x].push_back(i), adj[i].push_back(x);     queue<int> q;     q.push(0);     map<int, int> depth, count;     depth[0] = 0;     count[0]++;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto nxt : adj[cur])         if (depth.find(nxt) == depth.end())           depth[nxt] = depth[cur] + 1, count[depth[nxt]]++, q.push(nxt);     }     int ret = 0;     for (auto it : count) ret += it.second % 2;     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, j, n, k;     while (scanf( %d %d , &n, &k) == 2) {       int f, t, max = -2000000000;       for (i = 0; i < n; i++) {         scanf( %d %d , &f, &t);         if (t > k) {           if ((f - t + k) > max) max = f - t + k;         } else {           if (f > max) max = f;         }       }       printf( %d n , max);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       int n, k, d;       cin >> n >> k >> d;       int mn = n;       int a[n + 10];       for (int j = 1; j <= n; j++) cin >> a[j];       for (int j = 1; j <= n - d + 1; j++) {         set<int> s;         for (int q = j; q <= j + d - 1; q++) s.insert(a[q]);         int z = s.size();         mn = min(mn, z);       }       cout << mn <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, numa, numb, ans;     bool f = 0;     cin >> n >> a >> b;     for (int i = 2, cnt = 1; i <= n; i *= 2) {       numa = a / i;       if (a % i != 0) numa++;       numb = b / i;       if (b % i != 0) numb++;       if (numa == numb) {         if (i == n) f = 1;         ans = cnt;         break;       }       cnt++;     }     if (f == 1)       cout <<  Final!  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x[100005], y[112345];   set<long long> stx, sty;   int main() {     long long n, m, a, b;     scanf( %lld %lld , &n, &m);     long long total = n * n;     while (m--) {       scanf( %lld %lld , &a, &b);       if (x[a] == 0 && y[b] == 0) {         total = total - 2 * n + stx.size() + sty.size() + 1;       } else if (x[a] && y[b] == 0) {         total = total - n + stx.size();       } else if (y[b] && x[a] == 0)         total = total - n + sty.size();       x[a] = y[b] = 1;       stx.insert(a);       sty.insert(b);       printf( %lld  , total);     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   double a[22][22], p[20][(1 << 18) + 10], pc[(1 << 18) + 10],       sm[20][(1 << 18) + 10];   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           scanf( %lf , &a[i][j]);         }       memset(sm, 0, sizeof(sm));       for (int mask = 0; mask < (1 << n); mask++) {         pc[mask] = 0.0;         for (int bit = 0; bit < n; bit++) {           if (mask & (1 << bit)) {             pc[mask]++;             for (int cara = 0; cara < n; cara++) {               sm[cara][mask] += a[bit][cara];             }           }         }       }       for (int niv = 0; niv < n; niv++) {         for (int mask = 0; mask < (1 << n); mask++) {           if (niv == 0) {             if (mask == ((1 << n) - 1)) {               p[niv][mask] = 1.0;             } else {               p[niv][mask] = 0.0;             }           } else {             double sum = 0.0;             for (int bit = 0; bit < n; bit++) {               if ((mask & (1 << bit)) == 0) {                 sum += p[niv - 1][mask | (1 << bit)] * sm[bit][mask];               }             }             p[niv][mask] = 2.0 * sum / (pc[mask] * (pc[mask] + 1));           }         }       }       for (int i = 0; i < n; i++) {         printf( %lf%c , p[n - 1][1 << i],    n [i == (n - 1)]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int main(void) {     int n;     scanf( %d , &n);     int d;     scanf( %d , &d);     int h;     scanf( %d , &h);     if (d > 2 * h || d < h || (n > 2 && (d <= 1)) || (h < 1)) {       cout <<  -1 n ;       return 0;     } else {       int it = 1;       int c = 0;       while (it <= h) {         cout << it <<     << it + 1 << endl;         it++;         c++;       }       if (d != h) {         if (c < n - 1) {           cout << 1 <<     << it + 1 << endl;           c++;           it += 1;           d = d - h - 1;           while (d > 0 && c < n - 1) {             cout << it <<     << it + 1 << endl;             it++;             d--;             c++;           }           while (c < n - 1) {             cout << 1 <<     << it + 1 << endl;             it++;             c++;           }         }       } else {         if (c < n - 1) {           cout << 2 <<     << it + 1 << endl;           c++;           it += 1;           d = d - h - 1;           while (d > 0 && c < n - 1) {             cout << it <<     << it + 1 << endl;             it++;             d--;             c++;           }           while (c < n - 1) {             cout << 2 <<     << it + 1 << endl;             it++;             c++;           }         }       }     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long INF = 1e18;   struct node {     int u, v, w;     node(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}   } a[2 * N];   int fst[N], nxt[2 * N], tot, n, size[N];   bool vis[N];   long long ans, sum[N], ans0, mn;   void build(int x, int y, int z) {     a[tot] = node(x, y, z);     nxt[tot] = fst[x];     fst[x] = tot++;   }   void calc(int x) {     int y;     size[x] = 1;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       calc(y);       size[x] += size[y];       ans += (long long)a[p].w * size[y] * (n - size[y]);     }   }   void dfs1(int x) {     int y;     sum[x] = 0;     size[x] = 1;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       dfs1(y);       sum[x] = (long long)sum[y] + (long long)size[y] * a[p].w;       size[x] += size[y];     }   }   void dfs2(int x, int all) {     int y;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       sum[y] = sum[x] - (long long)size[y] * a[p].w +                (long long)(all - size[y]) * a[p].w;       mn = min(mn, sum[y]);       dfs2(y, all);     }   }   long long work(int x, int i) {     for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;     dfs1(x);     for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;     mn = sum[x];     dfs2(x, size[x]);     return (long long)(mn - sum[x]) * (n - size[x]);   }   int main() {     int x, y, z;     scanf( %d , &n);     tot = 0;     memset(fst, -1, sizeof(fst));     for (int i = 0; i < n - 1; i++) {       scanf( %d%d%d , &x, &y, &z);       x--;       y--;       build(x, y, z);       build(y, x, z);     }     ans = 0;     calc(0);     ans0 = ans;     long long tmp;     for (int i = 0; i < n - 1; i++) {       tmp = ans0 + work(a[i * 2].u, i) + work(a[i * 2].v, i);       ans = min(ans, tmp);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class DSU {    public:     vector<long long> p;     DSU() {}     DSU(long long n) {       p.resize(n + 1);       for (long long i = 1; i <= n; i++) p[i] = i;     }     void join(long long a, long long b) { p[find(b)] = find(a); }     long long find(long long a) { return a == p[a] ? a : p[a] = find(p[a]); }     bool check(long long a, long long b) { return find(a) == find(b); }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     DSU d(n);     vector<DSU> D;     for (long long i = 0; i <= m; i++) D.push_back(d);     for (long long i = 0; i < m; i++) {       long long u, v, c;       cin >> u >> v >> c;       D[c].join(u, v);     }     long long q;     cin >> q;     while (q--) {       long long u, v;       cin >> u >> v;       long long ans = 0;       for (long long i = 1; i <= m; i++)         if (D[i].check(u, v)) ans++;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500004;   int a[N], m, k, s, t, n, sz = 0;   map<int, int> mp, mq;   void add(int n, int val) {     if (n == -1) return;     if (val == 1) {       ++mq[n];       if (mq[n] == mp[n]) ++sz;     } else {       if (mq[n] == mp[n]) --sz;       --mq[n];     }   }   int main() {     scanf( %d %d %d %d , &m, &k, &n, &s);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= s; i++) {       scanf( %d , &t);       ++mp[t];     }     for (int i = 1; i <= m; i++)       if (!mp.count(a[i])) a[i] = -1;     bool ok = 0;     vector<int> v;     for (int l = 1, r = 1; l <= m && !ok; l++) {       for (; r <= m && sz < mp.size(); r++) add(a[r], 1);       if (sz >= mp.size()) {         if ((l - 1) / k + (m - r + 1) / k >= n - 1) {           ok = 1;           for (int i = l; i < r; i++) {             if (a[i] != -1 && mp[a[i]] > 0) {               --mp[a[i]];               a[i] = -2;             }           }           for (int i = l; i < r; i++) {             if (a[i] != -2 && (int)v.size() < r - l - k) v.push_back(i);           }           int cnt = (l - 1) % k;           for (int i = 1; i <= cnt; i++) v.push_back(i);         }       }       add(a[l], -1);     }     if (!ok)       puts( -1 );     else {       printf( %d n , v.size());       for (int x : v) printf( %d  , x);     }   }


#include <bits/stdc++.h>   using namespace std;   string s[] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM ,                  SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE };   int main() {     int n;     scanf( %d , &n);     string ss;     int sol = 0;     for (int i = 0; i < n; i++) {       cin >> ss;       if (isalpha(ss[0])) {         for (int j = 0; j < 11; j++)           if (ss == s[j]) {             sol++;             break;           }       } else {         int age = 0;         for (int j = 0; j < ss.length(); j++) {           age *= 10;           age += (ss[j] -  0 );         }         if (age < 18) sol++;       }     }     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int N = 100005;   long long ans;   int n, a[N], pi;   vector<int> G[N];   int s[2], flag, cnt[2];   map<int, int> mp[2];   void upd(int u, int dep) {     if ((dep % 2) != (flag % 2)) {       s[flag ^ 1] ^= a[u];       mp[flag ^ 1][a[u]]++;       ++cnt[flag ^ 1];     } else {       s[flag] ^= a[u];       mp[flag][a[u]]++;       ++cnt[flag];     }   }   void dfs(int u, int fa, int dep) {     if (G[u].size() == 1 && u != 1) {       if ((dep & 1) && flag == 0) flag ^= 1;     }     for (auto to : G[u])       if (to != fa) dfs(to, u, dep + 1);     upd(u, dep);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 2; i <= n; ++i) {       scanf( %d , &pi);       G[pi].push_back(i);       G[i].push_back(pi);     }     dfs(1, 0, 0);     if (s[flag] == 0) {       if (cnt[flag] > 1) ans += 1LL * cnt[flag] * (cnt[flag] - 1) / 2;       if (cnt[flag ^ 1] > 1) ans += 1LL * cnt[flag ^ 1] * (cnt[flag ^ 1] - 1) / 2;       for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) {         int tmp1 = it->first, tmp2 = it->second, tmp3 = mp[flag ^ 1][tmp1];         ans += 1LL * tmp2 * tmp3;       }     } else {       for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) {         int tmp1 = it->first, tmp2 = it->second,             tmp3 = mp[flag ^ 1][s[flag] ^ tmp1];         ans += 1LL * tmp2 * tmp3;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class data {    public:     long long k, b;     bool operator<(const data a) const {       if (k * a.k < 0)         return (b * a.k < a.b * k);       else         return (b * a.k > a.b * k);     }     bool operator==(const data a) const { return b * a.k == a.b * k; }   } d[100010];   long long n, tot = 0;   int main() {     long long x, y, cnt = 0;     scanf( %I64d , &n);     for (long long i = 1; i <= n; ++i) {       ++tot;       scanf( %I64d%I64d , &d[tot].k, &d[tot].b);       if (d[tot].k == 0) {         --tot;         continue;       }     }     n = tot;     sort(d + 1, d + tot + 1);     long long nowk = 0;     for (long long i = 1; i <= n; ++i)       if ((d[i - 1] == d[i]) && (i > 1)) {         nowk += abs(d[i].k);       } else {         if (nowk > 0) cnt++;         nowk = abs(d[i].k);       }     if (nowk) cnt++;     printf( %I64d n , cnt);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T qmax(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline void getmin(T &a, const T &b) {     if (a > b) a = b;   }   template <typename T>   inline void getmax(T &a, const T &b) {     if (a < b) a = b;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = 1e9 + 7;   const int N = 51, M = 2953;   const int go[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   char g[N][N];   int tp[N][N];   map<int, int> id;   int mask[M], cnt;   int dis[N][N][M];   bool vis[N][N][M], can[N][N][M];   int ans[N][N][M];   vector<pair<pair<int, int>, int> > to[N][N][M];   int n, m, k, sti, stj, edi, edj;   inline void bfs() {     static queue<pair<pair<int, int>, int> > q;     static int st, ed;     dis[sti][stj][1] = 1;     q.push(make_pair(make_pair(sti, stj), 1));     while (!q.empty()) {       pair<pair<int, int>, int> p = q.front();       q.pop();       int i = p.first.first, j = p.first.second, comb = mask[p.second];       if (dis[i][j][p.second] == dis[edi][edj][1]) break;       comb |= (~tp[i][j] ? 1 << tp[i][j] : 0);       for (register int d = 0; d < (4); ++d) {         int ni = i + go[d][0], nj = j + go[d][1];         if (ni < 1 || ni > n || nj < 1 || nj > m || (ni == sti && nj == stj))           continue;         int ncomb = comb;         if (~tp[ni][nj]) {           ncomb &= ~(1 << tp[ni][nj]);           if (__builtin_popcount(ncomb) >= k) continue;         } else {           ncomb = 0;         }         int cid = id[ncomb];         if (dis[ni][nj][cid]) {           if (dis[ni][nj][cid] == dis[i][j][p.second] + 1)             to[i][j][p.second].push_back(make_pair(make_pair(ni, nj), cid));           continue;         }         dis[ni][nj][cid] = dis[i][j][p.second] + 1;         q.push(make_pair(make_pair(ni, nj), cid));         to[i][j][p.second].push_back(make_pair(make_pair(ni, nj), cid));       }     }   }   inline bool cmp(const pair<pair<int, int>, int> &a,                   const pair<pair<int, int>, int> &b) {     pair<int, int> p = a.first, q = b.first;     if (g[p.first][p.second] != g[q.first][q.second])       return g[p.first][p.second] < g[q.first][q.second];     if (p.first == edi && p.second == edj) return false;     return cmp(to[p.first][p.second][a.second][ans[p.first][p.second][a.second]],                to[q.first][q.second][b.second][ans[q.first][q.second][b.second]]);   }   inline void dfs(int i, int j, int k) {     if (vis[i][j][k]) return;     vis[i][j][k] = true;     if (i == edi && j == edj) {       can[i][j][k] = true;       return;     }     vector<pair<int, int> > nxt;     for (register int d = 0; d < (to[i][j][k].size()); ++d) {       pair<pair<int, int>, int> p = to[i][j][k][d];       int ni = p.first.first, nj = p.first.second, nk = p.second;       nxt.push_back(make_pair(tp[ni][nj], d));     }     sort(nxt.begin(), nxt.end());     for (int id1 = 0, id2; id1 < nxt.size(); id1 = id2) {       int bst = -1;       for (id2 = id1; id2 < nxt.size() && nxt[id2].first == nxt[id1].first;            ++id2) {         pair<pair<int, int>, int> p = to[i][j][k][nxt[id2].second];         dfs(p.first.first, p.first.second, p.second);         if (can[p.first.first][p.first.second][p.second]) {           if (bst == -1 || cmp(p, to[i][j][k][bst])) bst = nxt[id2].second;         }       }       if (~bst) {         can[i][j][k] = true;         ans[i][j][k] = bst;         return;       }     }   }   inline void getans(pair<pair<int, int>, int> a) {     pair<int, int> p = a.first;     if (p.first == edi && p.second == edj) return;     if (p.first != sti || p.second != stj) putchar(g[p.first][p.second]);     getans(to[p.first][p.second][a.second][ans[p.first][p.second][a.second]]);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (register int i = (1); i <= (n); ++i) {       scanf( %s , g[i] + 1);       for (register int j = (1); j <= (m); ++j) {         if (g[i][j] ==  S ) {           tp[i][j] = -1;           sti = i, stj = j;         } else if (g[i][j] ==  T ) {           tp[i][j] = -1;           edi = i, edj = j;         } else {           tp[i][j] = g[i][j] -  a ;         }       }     }     id[0] = ++cnt;     mask[cnt] = 0;     for (register int i = (1); i <= (k - 1); ++i) {       for (int comb = (1 << i) - 1, x, y; comb < (1 << 26);            x = comb & -comb, y = comb + x, comb = ((comb & ~y) / x >> 1) | y) {         id[comb] = ++cnt;         mask[cnt] = comb;       }     }     bfs();     if (!dis[edi][edj][1]) return puts( -1 ), 0;     dfs(sti, stj, 1);     getans(make_pair(make_pair(sti, stj), 1));     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 29);   const int maxn = 300005;   const int mod = 1000007;   vector<pair<int, int> > color[maxn];   int q1[maxn], q2[maxn], ans[maxn], qq;   int n, m, num[maxn], top = 0, q[maxn], tot = 0, stk[maxn];   vector<int> edge[maxn];   bool vis[maxn];   long long V[maxn];   int N[maxn], C[maxn];   int F[mod];   void ins(int a, int b) {     long long hsh = 1ll * a * (n + 2) + b;     int h = hsh % mod;     for (int p = F[h]; p > 0; p = N[p]) {       if (V[p] == hsh) {         return;       }     }     V[++tot] = hsh, C[tot] = 0, N[tot] = F[h], F[h] = tot;   }   void upd(int a, int b) {     long long hsh = 1ll * a * (n + 2) + b;     int h = hsh % mod;     for (int p = F[h]; p > 0; p = N[p]) {       if (V[p] == hsh) {         C[p]++;         return;       }     }   }   int calc(int a, int b) {     long long hsh = 1ll * a * (n + 2) + b;     int h = hsh % mod;     for (int p = F[h]; p > 0; p = N[p]) {       if (V[p] == hsh) {         return C[p];       }     }     return 0;   }   void DFS(int x) {     if (vis[x]) {       return;     }     vis[x] = 1;     stk[++top] = x;     for (int i = 0; i < edge[x].size(); ++i) {       DFS(edge[x][i]);     }   }   void solve1(int c) {     if (color[c].empty()) {       return;     }     int all = 0;     for (int i = 0; i < color[c].size(); ++i) {       num[++all] = color[c][i].first;       num[++all] = color[c][i].second;     }     sort(num + 1, num + 1 + all);     all = unique(num + 1, num + 1 + all) - num - 1;     for (int i = 1; i <= all; ++i) {       edge[num[i]].clear();       vis[num[i]] = 0;     }     for (int i = 0; i < color[c].size(); ++i) {       int a = color[c][i].first, b = color[c][i].second;       edge[a].push_back(b), edge[b].push_back(a);     }     for (int i = 1; i <= all; ++i) {       if (!vis[num[i]]) {         top = 0;         DFS(num[i]);         for (int j = 1; j <= top; ++j) {           for (int k = j + 1; k <= top; ++k) {             int a = stk[j], b = stk[k];             if (a > b) {               swap(a, b);             }             upd(a, b);           }         }       }     }   }   int fa[maxn];   int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }   void solve2(int c) {     for (int i = 1; i <= n; ++i) {       fa[i] = i;     }     for (int i = 0; i < color[c].size(); ++i) {       int a = color[c][i].first, b = color[c][i].second;       a = getf(a);       b = getf(b);       if (a != b) {         fa[a] = b;       }     }     for (int i = 1; i <= qq; ++i) {       if (getf(q1[i]) == getf(q2[i])) {         ans[i]++;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       color[i].clear();     }     for (int i = 1, a, b, c; i <= m; ++i) {       scanf( %d%d%d , &a, &b, &c);       color[c].push_back(make_pair(a, b));     }     tot = 0;     memset(F, 0, sizeof(F));     memset(N, 0, sizeof(N));     memset(C, 0, sizeof(C));     memset(V, 0, sizeof(V));     scanf( %d , &qq);     for (int i = 1; i <= qq; ++i) {       scanf( %d%d , q1 + i, q2 + i);       ans[i] = 0;       if (q1[i] > q2[i]) {         swap(q1[i], q2[i]);       }       ins(q1[i], q2[i]);     }     int L = (int)sqrt(m);     if (1ll * L * L < m) {       L++;     }     for (int i = 1; i <= m; ++i) {       if (color[i].size() <= L) {         solve1(i);       } else {         solve2(i);       }     }     for (int i = 1; i <= qq; ++i) {       ans[i] += calc(q1[i], q2[i]);     }     for (int i = 1; i <= qq; ++i) {       if (q1[i] == q2[i]) {         ans[i] = m;       }     }     for (int i = 1; i <= qq; ++i) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, k;     cin >> t;     while (t--) {       cin >> k >> n;       cout << n + (9 * (k - 1)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> name, name2;   const int maxn = 1e3 + 10;   string s[maxn];   int A[maxn];   int main() {     int n;     cin >> n;     int maxx = -999999999;     for (int i = 0; i < n; i++) {       cin >> s[i] >> A[i];       name[s[i]] += A[i];     }     for (int i = 0; i < n; i++) maxx = max(maxx, name[s[i]]);     for (int i = 0; i < n; i++) {       name2[s[i]] += A[i];       if (name2[s[i]] >= maxx && name[s[i]] == maxx) {         cout << s[i];         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-9;   const int INT_INF = 1 << 31 - 1;   const long long I64_INF = 1ll << 63 - 1ll;   const double PI = acos(-1.0);   using namespace std;   struct person {     int c, first;     person(int _c = 0, int _f = 0) {       c = _c;       first = _f;     }     friend bool operator<(const person& a, const person& b) {       return a.first < b.first;     }   };   int n, d, S;   vector<person> a;   vector<person> b;   vector<int> sumb;   int maxCNT = 0;   int minS = 0;   void upd(int a, int b) {     if (a > maxCNT || a == maxCNT && b < minS) {       maxCNT = a;       minS = b;     }   }   pair<int, int> go(int free, int second) {     if (free >= (int)b.size()) return make_pair((int)b.size(), 0);     if (b[0].first > second) return make_pair(free, 0);     int r = (int)b.size() - free;     int l = 0;     while (l != r - 1) {       int m = (l + r) >> 1;       if (sumb[m] <= second)         l = m;       else         r = m;     }     return make_pair(free + l + 1, sumb[l]);   }   int main() {     scanf( %d%d%d , &n, &d, &S);     for (int i = 0; i < (int)n; i++) {       int c, first, l;       scanf( %d%d%d , &c, &first, &l);       if (l < d) first = S + 1;       if (!c)         b.push_back(person(c, first));       else         a.push_back(person(c, first));     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (!b.empty()) sumb.push_back(b[0].first);     for (int i = 1; i < (int)b.size(); i++)       if (*sumb.rbegin() > S)         sumb.push_back(S + 1);       else         sumb.push_back(*sumb.rbegin() + b[i].first);     pair<int, int> r = go(0, S);     upd(r.first, r.second);     int k = 0;     int sum = 0;     int Sum = 0;     for (int i = 0; i < (int)a.size(); i++) {       Sum += a[i].c;       if (Sum > n + n) break;     }     for (int i = 0; i < (int)a.size(); i++) {       k++;       sum += a[i].first;       if (sum > S) break;       int x = Sum - (int)a.size() + k;       pair<int, int> r = go(x, S - sum);       upd((int)a.size() + r.first, sum + r.second);     }     printf( %d %d n , maxCNT, minS);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n), cum(n + 1);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       cum[i + 1] = a[i] + cum[i];     }     int bits = 32 - __builtin_clz(n);     vector<vector<int>> dp(bits + 1, vector<int>(n));     auto sum = [&](int l, int r) { return (cum[r] - cum[l]) % 10; };     for (int bit = 0; bit < bits; bit++) {       int len = 1 << bit;       for (int i = 0; i + 2 * len <= n; i++) {         dp[bit + 1][i] = dp[bit][i] + dp[bit][i + len] +                          (sum(i, i + len) + sum(i + len, i + 2 * len)) / 10;       }     }     int q;     scanf( %d , &q);     for (int qq = 0; qq < q; qq++) {       int l, r;       scanf( %d %d , &l, &r);       --l;       int bit = __builtin_ctz(r - l);       printf( %d n , dp[bit][l]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 5, MOD = 1e9 + 7;   long long n;   long long par[MAXN];   long long cnt1[MAXN];   long long cnt2[MAXN];   long long dp1[MAXN];   long long dp2[MAXN];   long long color[MAXN];   bool subtree[MAXN];   vector<long long> G[MAXN];   void dfs_up1(long long v = 0) {     for (long long i = 0; i < G[v].size(); i++) {       dfs_up1(G[v][i]);       subtree[v] |= subtree[G[v][i]];     }     subtree[v] |= color[v];   }   void dfs_up2(long long v = 0) {     for (long long i = 0; i < G[v].size(); i++) dfs_up2(G[v][i]);     if (!subtree[v]) {       dp1[v] = 0;       dp2[v] = 1;       return;     }     if (color[v]) {       dp1[v] = 1;       for (long long i = 0; i < G[v].size(); i++)         if (subtree[G[v][i]]) {           if (color[G[v][i]]) dp1[v] = (dp1[v] * dp1[G[v][i]]) % MOD;           if (!color[G[v][i]])             dp1[v] = (dp1[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;         }       dp2[v] = 0;       return;     }     long long bu = 1, num = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) {           num++;           bu = (bu * dp1[G[v][i]]) % MOD;         }         if (!color[G[v][i]]) bu = (bu * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;       }     dp1[v] = num * bu % MOD;     bu = 1;     num = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) bu = (bu * dp1[G[v][i]]) % MOD;         if (!color[G[v][i]]) {           cnt1[num] =               ((num ? cnt1[num - 1] : 1) * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;           num++;         }       }     long long ind = num - 1;     for (long long i = G[v].size() - 1; ~i; i--)       if (subtree[G[v][i]]) {         if (!color[G[v][i]]) {           cnt2[ind] = ((ind != num - 1 ? cnt2[ind + 1] : 1) *                        (dp1[G[v][i]] + dp2[G[v][i]])) %                       MOD;           ind--;         }       }     ind = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (!color[G[v][i]]) {           dp1[v] = (dp1[v] + bu * (ind ? cnt1[ind - 1] : 1) % MOD *                                  (ind + 1 != num ? cnt2[ind + 1] : 1) % MOD *                                  dp1[G[v][i]]) %                    MOD;           ind++;         }       }     dp2[v] = 1;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) dp2[v] = (dp2[v] * dp1[G[v][i]]) % MOD;         if (!color[G[v][i]])           dp2[v] = (dp2[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;       }   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i < n; i++) {       scanf( %lld , &par[i]);       G[par[i]].push_back(i);     }     for (long long i = 0; i < n; i++) scanf( %lld , &color[i]);     dfs_up1();     dfs_up2();     printf( %lld n , dp1[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s, x, a, ans = 1;   void setup() {     cin >> s >> x;     a = s - x;     if (a & 1) {       cout << 0;       exit(0);     }     a >>= 1;   }   void xuly() {     long long k = a;     while (x) {       if (x & 1) {         if (a & 1) {           cout << 0;           return;         }         ans <<= 1;       }       x >>= 1;       a >>= 1;     }     if (k == 0) ans -= 2;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     setup();     xuly();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int n = a.size();     int f = 0, s = 0;     for (int i = 0; i < n; ++i)       if (a[i] != b[i]) {         if (a[i] ==  4 )           f++;         else           s++;       }     int ans = min(f, s);     ans += (f - ans) + (s - ans);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 5;   int n, par[N], mx1[N], mx2[N], ans[N];   int main() {     scanf( %d , &n);     par[1] = mx1[1] = mx2[1] = ans[1] = 0;     for (int i = 2; i <= n + 1; i++) {       scanf( %d , &par[i]);       int v = i, val;       ans[i] = mx1[i] = mx2[i] = 0;       while (v > 0) {         val = max(mx1[v], mx2[v] + 1);         if (val <= ans[v]) break;         ans[v] = val;         if (mx1[par[v]] < val)           mx1[par[v]] = val;         else if (mx2[par[v]] < val)           mx2[par[v]] = val;         v = par[v];       }       printf( %d  , max(mx1[1], mx2[1]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, a, b, Q;   long long W[(500000)], S[(500000)], O[(500000)];   map<pair<int, int>, vector<pair<int, int> > > M;   void pro(int t, int b, long long* g, int& l) {     *g = 0, l = 1;     while (b < N) {       long long S = W[b] + g[l - 1];       g[l++] = S, b += t;     }   }   int main() {     scanf( %d , &N);     for (int i(0); i < N; i++) scanf( %lld , W + i);     scanf( %d , &Q);     for (int i(0); i < Q; i++)       scanf( %d%d , &a, &b), --a, M[{b, a % b}].push_back({a, i});     for (auto& h : M) {       pro(h.first.first, h.first.second, S, a);       for (auto& w : h.second)         O[w.second] = S[a - 1] - S[w.first / h.first.first];     }     for (int i(0); i < Q; i++) printf( %lld n , O[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 256;   const char nxt =   n ;   inline void in(string Q) {     Q +=  .in ;     freopen(Q.c_str(),  r , stdin);   }   inline void out(string Q) {     Q +=  .out ;     freopen(Q.c_str(),  w , stdout);   }   inline void open_file(string Q) {     in(Q);     out(Q);   }   inline bool Pal(const string& s) {     return equal(s.begin(), s.end(), s.rbegin());   }   vector<string> taxi, pizza, frienD;   string change(string& X) {     string ret =   ;     for (auto to : X)       if (to !=  - ) ret.push_back(to);     return ret;   }   int check(string x) {     x = change(x);     if (int(x.size()) != 6) return 2;     string cur =   ;     cur += x[0];     for (auto to : x) {       if (to != cur.back()) cur.push_back(to);     }     if (int(cur.size()) == 1) return 1;     cur = x;     sort(cur.begin(), cur.end());     reverse(cur.begin(), cur.end());     char last =  . ;     bool ok = 1;     for (auto to : cur) {       if (to == last) {         ok = 0;         break;       }       last = to;     }     if (cur == x && ok) return 0;     return 2;   }   map<string, int> M[10], tax, piz, fr;   vector<string> nm;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (0) open_file(  );     int n;     cin >> n;     while (n--) {       int kol;       string name, phone;       cin >> kol >> name;       nm.push_back(name);       M[0][name] = M[1][name] = M[2][name] = 0;       while (kol--) {         cin >> phone;         int D = check(phone);         M[D][name]++;       }     }     for (int i = 0; i < 3; ++i) {       int mx = 0;       for (auto to : M[i]) {         mx = max(mx, to.second);       }       if (!mx) {         for (auto it : nm) {           if (!tax[it] && i == 1) {             tax[it] = 1;             taxi.push_back(it);           }           if (!piz[it] && !i) {             pizza.push_back(it);             piz[it] = 1;           }           if (!fr[it] && i == 2) {             fr[it] = 1;             frienD.push_back(it);           }         }         continue;       }       if (i == 1) {         for (auto it : nm) {           for (auto to : M[i]) {             if (to.second == mx && it == to.first && !tax[it]) {               taxi.push_back(it);               tax[it] = 1;             }           }         }       }       if (i == 0) {         for (auto it : nm) {           for (auto to : M[i]) {             if (to.second == mx && it == to.first && !piz[it]) {               pizza.push_back(it);               piz[it] = 1;             }           }         }       }       if (i == 2) {         for (auto it : nm) {           for (auto to : M[i]) {             if (to.second == mx && it == to.first && !fr[it]) {               frienD.push_back(it);               fr[it] = 1;             }           }         }       }     }     cout <<  If you want to call a taxi, you should call: ;     string ans =   ;     for (auto to : taxi) ans +=     + to +  , ;     ans.pop_back();     ans +=  . ;     cout << ans;     ans =   ;     cout << nxt <<  If you want to order a pizza, you should call: ;     for (auto to : pizza) ans +=     + to +  , ;     ans.pop_back();     ans +=  . ;     cout << ans;     ans =   ;     cout << nxt          <<  If you want to go to a cafe with a wonderful girl, you should call: ;     for (auto to : frienD) ans +=     + to +  , ;     ans.pop_back();     ans +=  . ;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct rec {     int w, h;   };   vector<rec> v;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int w, h;       scanf( %d %d , &w, &h);       v.push_back({w, h});     }     int last = -0x3f3f3f3f;     for (int i = n; i > 0; i--) {       int prev = max(v[i - 1].w, v[i - 1].h);       int mini = min(v[i].h, v[i].w);       int maxi = max(v[i].h, v[i].w);       if (mini >= last && mini <= prev) {         last = mini;       } else if (maxi >= last && maxi <= prev) {         last = maxi;       } else {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100001], v[100001], posa[100001], posv[100001], x, y;   int inx[100001];   inline void kspxa(int s, int t) {     if (s < t) {       int i = s, j = t, k = (i + j) >> 1;       int l = a[i];       a[i] = a[k];       a[k] = l;       l = posa[i];       posa[i] = posa[k];       posa[k] = l;       k = a[i];       l = posa[i];       while (i != j) {         while (i < j && a[j] > k) --j;         if (i < j) a[i] = a[j], posa[i++] = posa[j];         while (i < j && a[i] < k) ++i;         if (i < j) a[j] = a[i], posa[j--] = posa[i];       }       a[i] = k;       posa[i] = l;       kspxa(s, i - 1);       kspxa(i + 1, t);     }   }   inline void kspxv(int s, int t) {     if (s < t) {       int i = s, j = t, k = (i + j) >> 1;       int l = v[i];       v[i] = v[k];       v[k] = l;       l = posv[i];       posv[i] = posv[k];       posv[k] = l;       k = v[i];       l = posv[i];       while (i != j) {         while (i < j && v[j] > k) --j;         if (i < j) v[i] = v[j], posv[i++] = posv[j];         while (i < j && v[i] < k) ++i;         if (i < j) v[j] = v[i], posv[j--] = posv[i];       }       v[i] = k;       posv[i] = l;       kspxv(s, i - 1);       kspxv(i + 1, t);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &x, &y);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), posa[i] = i;     for (int i = 1; i <= m; i++) scanf( %d , &v[i]), posv[i] = i;     kspxa(1, n);     kspxv(1, m);     int left = 1, ans = 0;     memset(inx, 0, sizeof(inx));     for (int i = 1; i <= n; i++) {       if (left > m) break;       while (left <= m && v[left] < a[i] - x) ++left;       if (left > m) break;       if (v[left] >= a[i] - x && v[left] <= a[i] + y)         inx[posa[i]] = posv[left], ++left, ++ans;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       if (inx[i]) printf( %d %d n , i, inx[i]);   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &a) {     return out <<  (  << a.first <<  ,  << a.second <<  ) ;   }   template <class A>   ostream &operator<<(ostream &out, const vector<A> &a) {     for (const A &it : a) out << it <<    ;     return out;   }   template <class A, class B>   istream &operator>>(istream &in, pair<A, B> &a) {     return in >> a.first >> a.second;   }   template <class A>   istream &operator>>(istream &in, vector<A> &a) {     for (A &i : a) in >> i;     return in;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, x, y;     cin >> n >> x >> y;     string s;     cin >> s;     reverse((s).begin(), (s).end());     long long cnt = 0;     for (long long i = 0; i < x; i++) {       if ((i == x || i == y)) {         cnt += s[i] ==  0 ;       } else         cnt += s[i] ==  1 ;     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   long long a[2005];   vector<long long> Z;   vector<long long> F;   int main() {     long long n, i, S = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       S += a[i];     }     sort(a, a + n);     reverse(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] % 2 == 0)         Z.push_back(a[i]);       else         F.push_back(a[i]);     }     i = 0;     long long j = 0, k = 1, sum1 = 0, sum2 = 0;     while (1) {       if (k == 0) {         if (i >= Z.size()) break;         sum1 += Z[i];         i++;         k = 1;       } else {         if (j >= F.size()) break;         sum1 += F[j];         j++;         k = 0;       }     }     i = 0, j = 0, k = 0;     while (1) {       if (k == 0) {         if (i >= Z.size()) break;         sum2 += Z[i];         i++;         k = 1;       } else {         if (j >= F.size()) break;         sum2 += F[j];         j++;         k = 0;       }     }     long long maxi = max(sum1, sum2);     cout << S - maxi;     return 0;   }


#include <bits/stdc++.h>   long long t[105], s[105];   long long a[105];   int getNumber(long long add) {     if (add == 0)       return 1;     else {       int res = -1;       for (int i = 2; i <= 101; i++) {         long long last = i * (i - 1) * (i - 2) / 6,                   next = i * (i - 1) * (i + 1) / 6;         if ((next - last) == add) {           res = i;           break;         }       }       return res;     }   }   int main() {     int n;     scanf( %d%lld%lld , &n, &t[0], &s[0]);     for (int i = 1; i <= n; i++) {       if (i <= n - 3)         printf( + %d n , n - i);       else {         if (i == n || i == n - 2)           printf( + 1 n );         else           printf( + 2 n );       }       fflush(stdout);       scanf( %lld%lld , &t[i], &s[i]);     }     long long add = t[n] - t[n - 1];     a[1] = getNumber(add) - 1;     long long add0 = s[n] - s[n - 1], add1 = s[n - 2] - s[n - 3];     a[3] = add0 - add1 - 1;     a[2] = add1 / (a[3] + 1);     add = s[n - 1] - s[n - 2];     a[4] = (add - (a[3] + 1) * (a[1] + 1)) / (a[3] + 1) - 1;     for (int i = 5; i <= n; i++) {       long long add = s[n - i + 2] - s[n - i + 1];       a[i] = (add - a[i - 3] * a[i - 4] - a[i - 3] * (a[i - 1] + 1)) /                  (a[i - 1] + 1) -              1;     }     a[n]++;     printf( !  );     for (int i = 1; i <= n; i++) printf( %lld  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long ans[100100 << 1];   long long ksm(long long p, long long q) {     long long res = 1;     while (q) {       if (q & 1) res = res * p % 1000000007;       p = p * p % 1000000007;       q >>= 1;     }     return res;   }   signed main() {     cin >> n;     ans[0] = 1;     for (long long i = 1; i <= (n << 1); i++) {       ans[i] = ans[i - 1] * i % 1000000007;     }     cout << (ans[n << 1] * ksm(ans[n] * ans[n] % 1000000007, 1000000007 - 2)) %                     1000000007 -                 n;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   string s1, s2;   bool eq(int a1, int b1, int a2, int b2) {     if ((b1 - a1) & 1) {       while (a1 < b1) {         if (s1[a1] != s2[a2]) return 0;         ++a1;         ++a2;       }       return 1;     }     int m1 = (a1 + b1) / 2;     int m2 = (a2 + b2) / 2;     return (eq(a1, m1, a2, m2) && eq(m1, b1, m2, b2)) ||            (eq(a1, m1, m2, b2) && eq(m1, b1, a2, m2));   }   bool func() {     if (s1.length() != s2.length()) return 0;     if (eq(0, s1.length(), 0, s2.length())) {       return 1;     }   }   int main() {     cin >> s1 >> s2;     if (func())       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, k;     cin >> n >> m >> k;     vector<int> dp1(m, 0);     vector<int> pref_max(m, 0);     vector<int> suf_max(m, 0);     vector<vector<int> > a(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         a[i].push_back(x);       }     }     for (int i = 0; i < n; i++) {       vector<vector<int> > sa1(m);       vector<vector<int> > sa2(m);       for (int j = 0; j < m; j++) {         sa1[j].push_back(0);         sa2[j].push_back(0);         for (int ii = 0; ii < k; ii++) {           if (j + ii < m) {             sa1[j].push_back(sa1[j][sa1[j].size() - 1] + a[i][j + ii]);             if (i < n - 1) {               sa2[j].push_back(sa2[j][sa2[j].size() - 1] + a[i + 1][j + ii]);             } else {               sa2[j].push_back(0);             }           } else {             sa1[j].push_back(sa1[j][sa1[j].size() - 1]);             sa2[j].push_back(sa2[j][sa2[j].size() - 1]);           }         }       }       vector<int> dp2(m, -1e9);       for (int j = 0; j < m; j++) {         if (j - k >= 0) {           dp2[j] = pref_max[j - k];         }         if (j + k < m) {           dp2[j] = max(dp2[j], suf_max[j + k]);         }         for (int ii = max(0, j - k + 1); ii < min(m, j + k); ii++) {           if (ii < j) {             dp2[j] = max(dp2[j], dp1[ii] - sa1[j][k - (j - ii)]);           } else {             dp2[j] = max(dp2[j], dp1[ii] - sa1[ii][k - (ii - j)]);           }         }         if (i == 0) {           dp2[j] = sa1[j][k] + sa2[j][k];         } else {           dp2[j] += sa1[j][k] + sa2[j][k];         }       }       dp1 = dp2;       pref_max[0] = dp1[0];       for (int j = 1; j < m; j++) {         pref_max[j] = max(pref_max[j - 1], dp1[j]);       }       suf_max[m - 1] = dp1[m - 1];       for (int j = m - 2; j >= 0; j--) {         suf_max[j] = max(suf_max[j + 1], dp1[j]);       }     }     cout << pref_max[m - 1];   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     solve();     cout << endl;     return 0;   }