#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LLINF = 1e18;   const int MAXN = 1e5;   int v, q;   vector<int> G[MAXN];   int min_dist[MAXN];   bool is_centroid[MAXN];   int sz[MAXN];   int father[MAXN];   int dfs_sz(int x, int f = -1) {     sz[x] = 1;     for (auto y : G[x]) {       if (y == f || is_centroid[y]) continue;       sz[x] += dfs_sz(y, x);     }     return sz[x];   }   int dfs_cd(int x, int cent_sz, int f = -1) {     for (auto y : G[x]) {       if (y == f || is_centroid[y]) continue;       if (sz[y] > cent_sz / 2) return dfs_cd(y, cent_sz, x);     }     return x;   }   void cent_descomp(int x, int f = -1) {     int cent_sz = dfs_sz(x);     int centroid = dfs_cd(x, cent_sz);     is_centroid[centroid] = true;     father[centroid] = f;     for (auto y : G[centroid]) {       if (is_centroid[y]) continue;       cent_descomp(y, centroid);     }   }   int height[MAXN];   void dfs_h(int x, int f = -1) {     for (auto y : G[x]) {       if (f == y) continue;       height[y] = height[x] + 1;       dfs_h(y, x);     }   }   int l;   int timer;   int tin[MAXN], tout[MAXN];   int up[MAXN][25];   void dfs(int v, int p) {     tin[v] = ++timer;     up[v][0] = p;     for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];     for (int u : G[v]) {       if (u != p) dfs(u, v);     }     tout[v] = ++timer;   }   bool is_ancestor(int u, int v) {     return tin[u] <= tin[v] && tout[u] >= tout[v];   }   int lca(int u, int v) {     if (is_ancestor(u, v)) return u;     if (is_ancestor(v, u)) return v;     for (int i = l; i >= 0; --i) {       if (!is_ancestor(up[u][i], v)) u = up[u][i];     }     return up[u][0];   }   void preprocess(int root) {     timer = 0;     l = ceil(log2(v));     dfs(root, root);   }   int get_d(int x, int y) {     return abs(height[x] + height[y] - 2 * height[lca(x, y)]);   }   void upd(int x) {     int y = x;     while (true) {       min_dist[y] = min(min_dist[y], get_d(x, y));       if (-1 == father[y]) break;       y = father[y];     }   }   int query(int x) {     int y = x;     int ans = INF;     while (true) {       ans = min(ans, min_dist[y] + get_d(x, y));       if (-1 == father[y]) break;       y = father[y];     }     return ans;   }   int main() {     scanf( %d %d , &v, &q);     for (int i = 1; i < v; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--, y--;       G[x].push_back(y);       G[y].push_back(x);       min_dist[i - 1] = INF;     }     min_dist[v - 1] = INF;     cent_descomp(0);     for (int i = 0; i < v; i++) {       if (father[i] == -1) {         dfs_h(i);         preprocess(i);       }     }     upd(0);     for (int _ = 0; _ < q; _++) {       int t, x;       scanf( %d %d , &t, &x);       x--;       if (t == 1)         upd(x);       else         printf( %d n , query(x));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int RLEN = 1 << 18 | 1;   inline char nc() {     static char ibuf[RLEN], *ib, *ob;     (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));     return (ib == ob) ? -1 : *ib++;   }   inline int rd() {     char ch = nc();     int i = 0, f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = nc();     }     while (isdigit(ch)) {       i = (i << 1) + (i << 3) + ch -  0 ;       ch = nc();     }     return i * f;   }   const int N = 1e5 + 50;   char ch[N];   int n, a[N], pre[N][26], suf[N][26];   int f[N][26], g[N], mem[27];   inline int mex(int sta) { return __builtin_ctz(~sta); }   inline int calc(int l, int r, int c, int flag) {     if (l > r) return 0;     if (~mem[c]) return mem[c];     int sta = 0;     for (int j = 0; j < 26; ++j) {       int _l = suf[l][j], _r = pre[r][j];       if (_r >= l)         sta |=             1 << (g[_r] ^ g[_l] ^ (!flag ? f[_l - 1][c] : calc(l, _l - 1, j, 1)) ^                   (flag ? f[r][j] : calc(_r + 1, r, j, 0)));     }     return mem[c] = mex(sta);   }   int main() {     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (int i = 1; i <= n; i++) a[i] = ch[i] -  a ;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; ++j) pre[i][j] = pre[i - 1][j];       pre[i][a[i]] = i;     }     for (int j = 0; j < 26; ++j) suf[n + 1][j] = n + 1;     for (int i = n; i >= 1; i--) {       for (int j = 0; j < 26; ++j) suf[i][j] = suf[i + 1][j];       suf[i][a[i]] = i;     }     for (int i = 1; i <= n; i++) {       g[i] = f[i - 1][a[i]] ^ g[pre[i - 1][a[i]]];       memset(mem, -1, sizeof(mem));       for (int j = 0; j < 26; ++j) f[i][j] = calc(pre[i][j] + 1, i, j, 0);     }     int q = rd();     for (int i = 1; i <= q; i++) {       int l = rd(), r = rd();       memset(mem, -1, sizeof(mem));       if (calc(l, r, 26, 1))         puts( Alice );       else         puts( Bob );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       string x;       cin >> x;       long long c = 0;       long long arr[n + 5];       memset(arr, 0, sizeof(arr));       for (long long i = 0; i < n; i++) {         if (x[i] ==  < ) {           if ((i - 1) < 0 || arr[i - 1] == 1) arr[i] = 1;         } else if (x[i] ==  > ) {           long long lft = i;           while (i < n && x[i] ==  > ) i++;           if (i >= n) {             long long rgt = i;             c += (rgt - lft);           } else             i--;         }       }       for (long long i = 0; i < n; i++)         if (arr[i] == 1) c++;       cout << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int sum;   vector<int> x;   int main() {     int n;     cin >> n;     x.push_back(-2099999999);     for (int i = 0; i < n; i++) {       int a;       cin >> a;       x.push_back(a);     }     sort(x.begin(), x.end());     for (int i = 1; i <= n; i++) sum += abs(i - x[i]);     cout << sum << endl;   }


#include <bits/stdc++.h>   int b;   struct Matrix {     long long int x[110][110];   } A, B, C;   Matrix operator*(Matrix A, Matrix B) {     Matrix C;     for (int i = 1; i <= b; i++) {       for (int j = 1; j <= b; j++) {         C.x[i][j] = 0;         for (int k = 1; k <= b; k++) {           C.x[i][j] += A.x[i][k] * B.x[k][j];           C.x[i][j] %= 1000000007;         }       }     }     return C;   }   void func(long long int k) {     for (int i = 1; i <= b; i++)       for (int j = 1; j <= b; j++) B.x[i][j] = C.x[i][j] = 0;     for (int i = 1; i <= b; i++) B.x[i][i] = C.x[i][i] = 1;     C = A;     while (k) {       if (k % 2 == 1) B = B * C;       k /= 2;       C = C * C;     }   }   int main() {     long long int a;     scanf( %lld%d , &a, &b);     for (int i = 1; i <= b; i++)       for (int j = 1; j <= b; j++) A.x[i][j] = 0;     A.x[1][1] = 1, A.x[1][b] = 1;     for (int i = 2; i <= b; i++) A.x[i][i - 1] = 1;     if (a < b) {       printf( 1 );       return 0;     }     func(a - b);     long long int s = 0;     for (int i = 1; i <= b; i++) s += B.x[1][i], s %= 1000000007;     s += B.x[1][1], s %= 1000000007;     printf( %lld , s);   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     return y == 0 ? x : gcd(y, x % y);   }   int main() {     long long int a;     cin >> a;     if (a > 2) {       if (a * a % 2)         cout << (a * a - 1) / 2 <<     << (a * a + 1) / 2;       else         cout << (a * a / 2 - 2) / 2 <<     << (a * a / 2 + 2) / 2;     } else {       cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long holes[14];   int main() {     long long zeroes = 0;     for (long long i = 0; i < 14; i++) {       cin >> holes[i];       if (holes[i] == 0) zeroes++;     }     zeroes++;     long long mx = 0;     for (long long i = 0; i < 14; i++) {       long long cnt = 0;       if (holes[i] != 0) {         long long a = holes[i] / 14;         long long b = holes[i] % 14;         if (a % 2 == 0) {           cnt = zeroes * a;           while (b) {             if (holes[(i + b) % 14] == 0)               cnt -= a;             else               cnt += (a + holes[(i + b) % 14] + 1);             b--;           }         } else {           cnt = a * (14 - zeroes);           for (long long j = 0; j < 14; j++)             if (i != j) cnt += holes[j];           while (b) {             if (holes[(i + b) % 14] == 0)               cnt += a + 1;             else               cnt -= (a + holes[(i + b) % 14]);             b--;           }         }       }       mx = max(cnt, mx);     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <class A>   void read(vector<A>& v);   template <class A, size_t S>   void read(array<A, S>& a);   template <class T>   void read(T& x) {     cin >> x;   }   void read(double& d) {     string t;     read(t);     d = stod(t);   }   void read(long double& d) {     string t;     read(t);     d = stold(t);   }   template <class H, class... T>   void read(H& h, T&... t) {     read(h);     read(t...);   }   template <class A>   void read(vector<A>& x) {     for (auto& a : x) read(a);   }   template <class A, size_t S>   void read(array<A, S>& x) {     for (auto& a : x) read(a);   }   const int MAXN = 2e5 + 5;   long long mod = 1e9 + 7;   vector<long long> gr[200005];   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long val = (b * b) - (4 * a * c);     cout << setprecision(8);     if (a == 0) {       if ((b == 0)) {         if (c == 0) {           cout << -1 <<   n ;           return;         }         cout << 0 <<   n ;       } else {         cout << 1 <<   n ;         long double ans = -(c * 1.0) / (b * 1.0);         cout << ans <<   n ;       }       return;     }     if (val < 0) {       cout << 0 <<   n ;       return;     } else {       long double root1 = -b + sqrt(val);       root1 /= 2.0 * a;       long double root2 = -b - sqrt(val);       root2 /= 2.0 * a;       if (root1 == root2) {         cout << 1 <<   n ;         cout << root1 <<   n ;       } else {         cout << 2 <<   n ;         if (root1 < root2) {           cout << root1 <<   n  << root2 <<   n ;         } else {           cout << root2 <<   n  << root1 <<   n ;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     test = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e13;   const int MAGIC = 3500000;   long long add(long long x, long long y) { return (x + y) % MOD; }   long long mul(long long x, long long y) {     long long coef = (long double)(x)*y / MOD + 0.5;     long long ret = x * y - coef * MOD;     ret += ret < 0 ? MOD : 0;     return ret;   }   struct mat {     long long dat[2][2];     mat() { memset(dat, 0, sizeof(dat)); }   } I, J;   mat operator*(const mat& A, const mat& B) {     mat ret;     for (int i = 0; i < (int)(2); i++)       for (int j = 0; j < (int)(2); j++)         ret.dat[i][j] =             add(mul(A.dat[i][0], B.dat[0][j]), mul(A.dat[i][1], B.dat[1][j]));     return ret;   }   void init() {     I.dat[0][0] = I.dat[1][1] = 1;     J.dat[1][0] = J.dat[0][1] = J.dat[1][1] = 1;   }   long long calc(long long pos) {     mat ans = I, cur = J;     while (pos > 0) {       if (pos & 1) ans = ans * cur;       cur = cur * cur;       pos >>= 1;     }     return ans.dat[1][0];   }   long long pw[14], cyc[14];   long long X;   int main() {     init();     scanf( %lld , &X);     pw[0] = 1;     for (int i = 1; i <= (int)(13); i++) pw[i] = 10 * pw[i - 1];     cyc[0] = 1;     cyc[1] = 60;     cyc[2] = 300;     cyc[3] = 1500;     for (int i = 4; i <= 13; i++) cyc[i] = 10 * cyc[i - 1];     vector<long long> occ, nocc;     occ.push_back(0);     for (int i = 1; i <= (int)(13); i++) {       int wt = cyc[i] / cyc[i - 1];       nocc.clear();       for (int j = 0; j < (int)(occ.size()); j++)         for (int k = 0; k < (int)(wt); k++)           if (calc(occ[j] + k * cyc[i - 1]) % pw[i] == X % pw[i])             nocc.push_back(occ[j] + k * cyc[i - 1]);       occ = nocc;     }     sort(occ.begin(), occ.end());     printf( %lld n , occ.empty() ? -1 : occ[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600010;   const int Mod = 998244353;   inline int sub(int x, int y) { return (x - y < 0 ? x - y + Mod : x - y); }   inline int add(int x, int y) { return (x + y >= Mod ? x + y - Mod : x + y); }   int po(int x, int y) {     int r = 1;     for (; y; y >>= 1, x = (1ll * x * x % Mod))       if (y & 1) r = (1ll * r * x % Mod);     return r;   }   namespace poly {   int r[N], a[N], b[N], w[N], iw[N], m, l;   void init(int x) {     for (m = 1, l = 0; m <= x; m <<= 1, ++l)       ;     for (int i = 0; i < m; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));     int b = po(3, (Mod - 1) / m), ib = po(b, Mod - 2);     w[m / 2] = iw[m / 2] = 1;     for (int i = 1; i < m / 2; ++i)       w[m / 2 + i] = (1ll * w[m / 2 + i - 1] * b % Mod),                 iw[m / 2 + i] = (1ll * iw[m / 2 + i - 1] * ib % Mod);     for (int i = m / 2 - 1; i; --i) w[i] = w[i << 1], iw[i] = iw[i << 1];   }   void ntt(int* a, int f) {     for (int i = 0; i < m; ++i)       if (i < r[i]) swap(a[i], a[r[i]]);     for (int i = 1, id = 1; i < m; i <<= 1, ++id) {       for (int j = 0; j < m; j += i << 1)         for (int k = 0; k < i; ++k) {           int x = a[j + k],               y = (1ll * (f == 1 ? w[i + k] : iw[i + k]) * a[i + j + k] % Mod);           a[j + k] = add(x, y), a[i + j + k] = sub(x, y);         }     }     if (f == -1) {       int in = po(m, Mod - 2);       for (int i = 0; i < m; ++i) a[i] = (1ll * a[i] * in % Mod);     }   }   void prod(int* a, int* b, int len) {     init(len);     ntt(a, 1);     ntt(b, 1);     for (int i = 0; i < m; ++i) a[i] = (1ll * a[i] * b[i] % Mod);     ntt(a, -1);   }   }  // namespace poly   using poly::a;   using poly::b;   using poly::prod;   int fac[N], inv[N];   void init() {     const int m = 3e5;     fac[0] = 1;     for (int i = 1; i <= m; ++i) fac[i] = (1ll * fac[i - 1] * i % Mod);     inv[m] = po(fac[m], Mod - 2);     for (int i = m - 1; i >= 0; i--) inv[i] = (1ll * i + 1 * inv[i + 1] % Mod);   }   vector<int> ve[N];   priority_queue<pair<int, int> > Q;   int cq;   struct Edge {     int to, next;   } edge[N << 1];   int head[N], num;   void add_edge(int a, int b) {     edge[++num] = (Edge){b, head[a]};     head[a] = num;   }   void dfs(int x, int f) {     int cnt = 0;     for (int i = head[x]; i; i = edge[i].next)       if (edge[i].to != f) {         dfs(edge[i].to, x);         ++cnt;       }     if (cnt) {       ++cq;       ve[cq].push_back(1);       ve[cq].push_back(cnt);       Q.push(make_pair(-1, cq));     }   }   int main() {     init();     int n;     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       add_edge(x, y);       add_edge(y, x);     }     dfs(1, 0);     for (int i = 1; i < cq; ++i) {       int t1 = Q.top().second;       Q.pop();       int t2 = Q.top().second;       Q.pop();       int la = ve[t1].size() - 1, lb = ve[t2].size() - 1;       for (int j = 0; j <= la; j++) a[j] = ve[t1][j];       for (int j = 0; j <= lb; j++) b[j] = ve[t2][j];       prod(a, b, la + lb + 2);       ve[t1].clear();       for (int j = 0; j <= la + lb; j++) ve[t1].push_back(a[j]);       for (int i = 0; i <= poly ::m; i++) a[i] = b[i] = 0;       Q.push(make_pair(-la - lb, t1));     }     int rt = Q.top().second, len = -Q.top().first;     int ans = 0;     for (int i = 0; i <= len; ++i) {       int tmp = (1ll * ve[rt][i] * fac[n - i] % Mod);       ans = (i & 1) ? sub(ans, tmp) : add(ans, tmp);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, mod = 1e9 + 7;   const long long inf = 1e18;   int x[maxn], frs[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, z;     cin >> n >> z;     for (int i = 0; i < n; i++) {       cin >> x[i];     }     sort(x, x + n);     int pt = 0;     for (int i = 0; i < n; i++) {       pt = max(pt, i + 1);       while (pt < n && x[pt] - x[i] < z) pt++;       frs[i] = pt;     }     int l = 0, r = (n / 2) + 1;     while (r - l > 1) {       int mid = (l + r) >> 1;       int pt = mid - 1;       for (int i = 0; i < mid; i++) {         pt = max(pt + 1, frs[i]);       }       if (pt >= n)         r = mid;       else         l = mid;     }     return cout << l << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   vector<vector<int> > dp;   vector<int> res;   void recalc(char col) {     dp = vector<vector<int> >(n + 1, vector<int>(n + 1, 0));     res = vector<int>(n, 0);     for (int(i) = 0; (i) < (n + 1); ++(i)) dp[i][0] = 0;     for (int(ncur) = (1); (ncur) < (n + 1); ++(ncur)) {       for (int(mcur) = (0); (mcur) < (n + 1); ++(mcur)) {         if (s[ncur - 1] == col) {           dp[mcur][ncur] = dp[mcur][ncur - 1] + 1;           continue;         }         if (mcur == 0) {           dp[mcur][ncur] = 0;         } else {           dp[mcur][ncur] = dp[mcur - 1][ncur - 1] + 1;         }       }     }     for (int(i) = 0; (i) < (n); ++(i)) {       for (int(j) = (1); (j) < (n + 1); ++(j)) {         res[i] = max(res[i], dp[i + 1][j]);       }     }   }   void solve() {     cin >> n;     cin >> s;     int q;     cin >> q;     vector<pair<pair<char, int>, int> > qrs(q);     for (int(i) = 0; (i) < (q); ++(i)) {       cin >> qrs[i].first.second >> qrs[i].first.first;       qrs[i].second = i;     }     sort(qrs.begin(), qrs.end());     vector<pair<int, int> > ans(q);     char lastcol = -1;     for (int(i) = 0; (i) < (q); ++(i)) {       char col = qrs[i].first.first;       int m = qrs[i].first.second;       if (col != lastcol) {         lastcol = col;         recalc(col);       }       ans[i].first = qrs[i].second;       ans[i].second = res[m - 1];     }     sort(ans.begin(), ans.end());     for (int(i) = 0; (i) < (q); ++(i)) cout << ans[i].second << endl;   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1000010;   long long fact[N];   int main(int argc, char const *argv[]) {     long long n, m;     cin >> n >> m;     if (n == 1 && m == 1) {       cout <<  1 n ;       return 0;     }     double ans = 1.0 / (double)n +                  (((n - 1.0) / (double)n) * (m - 1.0) / (n * 1.0 * m - 1.0));     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>    using namespace std;      using ll = long long;   using ld = long double;   #define fi first   #define se second      void solve(){    ll n;    cin>>n;    vector<ll>d(n);    for(int i=0;i<n;i++)     cin>>d[i];    ll ans=0,curr=0;    sort(d.begin(),d.end());    for(int i=1;i<d.size()-1;i++){     ans+=(i*d[i])-curr;     curr+=d[i];    }    ll l = d.size();    if(l>=3)     ans+=((l-2)*d[l-1])-curr;    cout<<-1*ans<<  n ;   }      int main()    {     ios::sync_with_stdio(false);    cin.tie(0);       int t;    cin>>t;    while(t--){     solve();    }        return 0;    }


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


#include <bits/stdc++.h>   using namespace std;   bool check(vector<long long> a, long long m, long long n) {     vector<long long> v(n + 1, 0);     for (long long i = 0; i < n; i++) {       v[a[i]] += 1;     }     set<pair<long long, long long>, greater<pair<long long, long long>>> s;     for (long long i = 1; i < n + 1; i++) {       if (v[i]) {         s.insert({v[i], i});       }     }     vector<long long> b;     for (long long i = 0; i < n; i++) {       if (i >= m and v[b[i - m]]) {         s.insert({v[b[i - m]], b[i - m]});       }       if (s.empty()) return false;       pair<long long, long long> p = *(s.begin());       b.push_back(p.second);       s.erase(p);       v[p.second] -= 1;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < m; i++) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (a[n - 1] > b[0]) {       cout <<  -1 n ;       return 0;     }     long long ans = 0;     for (long long i = 0; i < n; i++) ans += a[i] * m;     long long g = n - 1, h = m - 1;     bool is = false;     for (long long i = m - 1; i >= 0; i--) {       while (g >= 0 && h == 0) {         g--;         h = m - 1;       }       if (b[i] == a[n - 1]) {         break;       }       if (g < 0) {         cout <<  -1 n ;         return 0;       }       ans += b[i] - a[g];       h--;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int t, n, a[200010], tot, cnt[200010];   int f[200010];   int find_f(int x) { return f[x] ^ x ? f[x] = find_f(f[x]) : x; }   int main() {     scanf( %d , &t);     for (int _ = 0; _ < t; ++_) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , a + i);       for (int i = 1; i <= n; ++i) f[i] = i, cnt[i] = 0;       for (int i = 1; i <= n; ++i)         if (find_f(i) != find_f(a[i])) f[find_f(i)] = find_f(a[i]);       for (int i = 1; i <= n; ++i) ++cnt[find_f(i)];       for (int i = 1; i <= n; ++i) printf( %d  , cnt[find_f(i)]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     vector<int> a(n, 0);     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     vector<int> b(m, 0);     for (int i = 0; i < m; i++) cin >> b[i];     int count = 0;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (abs(a[i] - b[j]) <= 1) {           count++;           b[j] = INT_MAX;           break;         }       }     }     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int add(int a, int b, int c) {     a += b;     if (a >= c)       a -= c;     else if (a < 0)       a += c;     return a;   }   inline int mul(int a, int b, int c) { return (long long)a * b % c; }   int pow(int a, long long b, int c) {     int res = 1;     for (; b; b /= 2) {       if (b % 2) res = mul(res, a, c);       a = mul(a, a, c);     }     return res;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int k, p;       long long l, r;       scanf( %d%I64d%I64d%d , &k, &l, &r, &p);       if (p == 2) {         printf( %d n , !(k % 2));         continue;       }       int prod = 1;       if (k % p) {         int e = pow(2, l, p - 1);         int t = pow(k, e, p);         if (t == 1)           prod = pow(2, r - l + 1, p);         else {           int inv = pow(add(t, -1, p), p - 2, p);           int num =               add(pow(t, add(pow(2, r - l + 1, p - 1), -1, p - 1), p), -1, p);           prod = add(mul(t, mul(num, inv, p), p), 1, p);         }       }       if (k % 2)         prod = mul(prod, pow(2, add(l % (p - 1), -(r % (p - 1)), p - 1), p), p);       printf( %d n , prod);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct milk {     int x, num;     bool operator<(const milk &mm) const { return x < mm.x; }   } b[1000010];   int a[1000010], n, m, k;   bool ok(int p2) {     int p1 = 1, now = 0;     while (p1 <= n || p2 <= m) {       if ((p1 <= n && a[p1] < now) || (p2 <= m && b[p2].x < now)) return 0;       for (int i = 1; i <= k; i++)         if (p1 <= n && (p2 > m || a[p1] < b[p2].x))           p1++;         else           p2++;       now++;     }     return 1;   }   int main() {     int l, r, mid;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i].x);       b[i].num = i;     }     sort(a + 1, a + n + 1);     sort(b + 1, b + m + 1);     if (!ok(m + 1)) {       printf( -1 n );       return 0;     }     l = 1;     r = m + 1;     while (l < r) {       mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , m - l + 1);     for (int i = l; i <= m; i++) printf( %d%c , b[i].num, i == m ?   n  :    );   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void O_o() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   bool prime(int n, int i) {     if (i == n) return true;     if (n % i == 0) return false;     prime(n, i + 1);   }   int arr[1000005], arr1[1000005];   unsigned long long sum = 0;   int main() {     O_o();     int n, s, m;     cin >> n;     for (int i = 1;; i *= 2) {       if (i < 1000005)         arr1[i] = 1;       else         break;     }     for (int i = 1;; i *= 2) {       if (i == n) {         s = ((i * 2) - 1);         break;       } else if (i > n) {         s = i - 1;         break;       }     }     m = n++;     for (int i = 0; i < int(n); i++) {       if (arr[s - m] == 0 && arr[m] == 0) arr[s - m] = m, arr[m] = s - m;       if (arr1[m] == 1) s = m - 1;       if (m == 0) break;       m--;     }     for (int i = 0; i < int(n); i++) sum += (arr[i] ^ i);     cout << sum <<   n ;     for (int i = 0; i < int(n); i++) cout << arr[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, const T& b) {     return a > b ? a = b, true : false;   }   template <class T>   bool umax(T& a, const T& b) {     return a < b ? a = b, true : false;   }   template <long long sz>   using tut = array<long long, sz>;   const long long N = 3e5 + 5;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   const long double Pi = acos(-1);   const long long MX = 2e16;   long long n, m, k, t, q, ans, res, a[N];   long long in[N][2], cc[N], cnt[N][2];   long long par[N], sz[N];   vector<long long> edges[N];   string s;   void dfs(long long u) {     cnt[u][cc[u]]++;     for (auto x : edges[u]) {       if (in[x][1] == -1) continue;       long long to = in[x][0] + in[x][1] - u;       if (~cc[to]) continue;       cc[to] = cc[u] ^ (s[x] ==  0 );       dfs(to);     }   }   long long f(long long x) { return (par[x] == x ? x : par[x] = f(par[x])); }   void add(long long a, long long s0, long long s1) {     a = f(a);     res -= min(cnt[a][0], cnt[a][1]);     cnt[a][0] += s0, cnt[a][1] += s1;     res += min(cnt[a][0], cnt[a][1]);   }   void merge(long long a, long long b) {     a = f(a), b = f(b);     if (a == b) return;     if (sz[b] > sz[a]) swap(a, b);     add(a, cnt[b][0], cnt[b][1]);     add(b, -cnt[b][0], -cnt[b][1]);     sz[a] += sz[b], par[b] = a;   }   void solve(long long t_case) {     cin >> n >> k >> s;     s =  $  + s;     memset(in, -1, sizeof in), memset(cc, -1, sizeof cc);     for (long long i = 0; i < k; i++) {       sz[i] = 1, par[i] = i;       long long c;       cin >> c;       for (long long j = 0; j < c; j++) {         long long x;         cin >> x, edges[i].push_back(x);         if (~in[x][0])           in[x][1] = i;         else           in[x][0] = i;       }     }     for (long long i = 0; i < k; i++) {       if (~cc[i]) continue;       cc[i] = 0, dfs(i);     }     for (long long i = 1; i <= n; i++) {       long long c0 = in[i][0], c1 = in[i][1];       if (~c0 && c1 == -1) {         if (s[i] ==  0 ) {           if (cc[c0])             add(c0, mod, 0);           else             add(c0, 0, mod);         } else {           if (cc[c0])             add(c0, 0, mod);           else             add(c0, mod, 0);         }       }       if (~c0 && ~c1) {         merge(c0, c1);       }       cout << res <<   n ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (0) {       long long t;       cin >> t;       for (long long t_case = 1; t_case <= t; t_case++) solve(t_case);     } else       solve(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lucky[1024 * 4];   long long fact[14];   int cnt;   void func(long long cur, int pos, int maxpos) {     if (pos == maxpos) {       lucky[++cnt] = cur * 10 + 4;       lucky[++cnt] = cur * 10 + 7;       return;     }     func(cur * 10 + 4, pos + 1, maxpos);     func(cur * 10 + 7, pos + 1, maxpos);   }   void pre() {     cnt = 0;     for (int d = 1; d <= 10; d++) {       func(0, 1, d);     }     sort(lucky, lucky + cnt);     fact[0] = 1;     for (int i = 1; i < 14; i++) fact[i] = i * fact[i - 1];   }   long long n, k;   void in() { cin >> n >> k; }   int arr[14] = {0};   int brr[14] = {0};   void rec(int p, long long k, int coun) {     if (coun == p) return;     int b = (k + fact[p - 1 - coun] - 1) / fact[p - 1 - coun];     int c = 0;     for (int i = 0; i < 14; i++) {       if (brr[i] == 0) c++;       if (b == c) {         brr[i] = 1;         arr[coun] = i;         rec(p, k - fact[p - 1 - coun] * (b - 1), coun + 1);         break;       }     }     return;   }   bool luck(long long q) {     for (int i = 0; i < cnt; i++) {       if (lucky[i] == q) return true;       if (lucky[i] > q) return false;     }     return false;   }   void solve() {     int p = 0;     while (fact[p] < k) p++;     if (n < 14 && k > fact[n]) {       cout << -1 << endl;       return;     }     rec(p, k, 0);     for (int i = 0; i < p; i++) {       arr[i] += n - p + 1;     }     int ans = 1;     while (lucky[ans] <= n - p) {       ans++;     }     ans--;     for (long long i = n - p + 1; i <= n; i++) {       if (luck(i) && luck(arr[i - n - 1 + p])) ans++;     }     cout << ans << endl;   }   int main() {     pre();     in();     solve();   }


#include <bits/stdc++.h>   const int MAXINT = 2147483640;   const long long MAXLL = 9223372036854775800LL;   const long long MAXN = 1e6;   const double eps = 1e-9;   const long long mod = 1e9 + 7;   using namespace std;   long long binpow(long long a, long long n) {     long long ans = 1;     while (n) {       if (n & 1) ans *= a;       a *= a;       n >>= 1;     }     return ans;   }   long long n;   char a[MAXN], b[MAXN];   int main() {     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     long long ans1 = 0, ans0 = 0;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i] ==  1 )         ans1++;       else         ans0++;     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] ==  0  && b[i] ==  0 ) {         ans += ans1;         ans0--;       }       if (a[i] ==  1  && b[i] ==  0 ) {         ans += ans0;         ans1--;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int count = 0;     for (int i = 1; i < n - 1; i++) {       if ((a[i - 1] - a[i]) * (a[i + 1] - a[i]) > 0) {         count++;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct item {     int id, savetime, destructiontime, value;   };   struct state {     int bestval, besttime;     vector<int> items;   };   int n;   item arr[101];   state dp[101][2001];   int itemidx[101][2001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       arr[i].id = i;       cin >> arr[i].savetime >> arr[i].destructiontime >> arr[i].value;     }     sort(arr + 1, arr + n + 1, [](const item& a, const item& b) {       return a.destructiontime < b.destructiontime;     });     for (int i = 0; i <= 2000; ++i) {       dp[0][i] = {0, 0, {}};     }     for (int idx = 1; idx <= n; ++idx) {       for (int t = 0; t <= 2000; ++t) {         if (t > 0)           dp[idx][t] = dp[idx][t - 1];         else           dp[idx][t] = {0, 0, {}};         if (dp[idx - 1][t].bestval > dp[idx][t].bestval) {           dp[idx][t] = dp[idx - 1][t];         }         if (t >= arr[idx].savetime && t < arr[idx].destructiontime &&             dp[idx - 1][t - arr[idx].savetime].bestval + arr[idx].value >                 dp[idx][t].bestval) {           dp[idx][t] = dp[idx - 1][t - arr[idx].savetime];           dp[idx][t].bestval += arr[idx].value;           dp[idx][t].besttime += arr[idx].savetime;           dp[idx][t].items.emplace_back(idx);         }       }     }     state beststate = dp[n][2000];     cout << accumulate(beststate.items.begin(), beststate.items.end(), 0,                        [](int prev, int idx) { return prev + arr[idx].value; })          << endl;     cout << beststate.items.size() << endl;     for (int idx : beststate.items) {       cout << arr[idx].id <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx )   using namespace std;   const long long maxn = 1e5 + 20;   const long long inf = (long long)2e9;   const long double pi = asin(1) * 2;   const long double eps = 1e-8;   const long long mod = (long long)1e9 + 7;   const long long ns = 97;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   long long dp[maxn], tin[maxn], up[maxn], was[maxn], used[maxn];   vector<long long> g[maxn], ans, order;   long long timer = 0, flag = 1;   void dfs(long long v) {     used[v] = 1;     tin[v] = timer++;     dp[v] = tin[up[v]];     for (auto& u : g[v]) {       if (!used[u]) dfs(u);       dp[v] = min(dp[v], dp[u]);       if (dp[u] < tin[v] && dp[u] != tin[up[v]]) flag = 0;     }     if (dp[v] < tin[up[v]]) flag = 0;     order.push_back(v);   }   void dfs2(long long v) {     used[v] = 1;     for (auto& u : g[v])       if (!used[u]) dfs2(u);     if (was[v]) ans.push_back(v);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long a, b;       cin >> a >> b;       --a, --b;       g[a].push_back(b);       used[b] = 1;     }     for (long long i = 0; i < n; ++i) {       cin >> up[i];       --up[i];       was[up[i]] = 1;     }     vector<long long> roots;     for (long long i = 0; i < n; ++i)       if (!used[i]) roots.push_back(i);     for (auto& x : used) x = 0;     for (auto& x : roots) dfs(x);     if (!flag) {       cout << -1;       exit(0);     }     for (auto& x : used) x = 0;     reverse(order.begin(), order.end());     for (long long i = 0; i < n; ++i)       if (!used[i]) dfs2(i);     cout << (long long)ans.size() <<   n ;     for (auto& x : ans) cout << x + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   long long int mp[10];   long long int x[20];   bool solve(long long int idx, bool isSmall) {     if (idx == b.size()) {       return true;     }     long long int start = b[idx] -  0 ;     if (isSmall) start = 9;     for (long long int j = start; j >= 0; j--) {       if (mp[j] > 0) {         mp[j]--;         x[idx] = j;         bool flag = false;         if (isSmall) flag = true;         if (j < start) flag = true;         bool temp = solve(idx + 1, flag);         if (temp) return true;         mp[j]++;       }     }     return false;   }   int main() {     cin >> a >> b;     if (b.size() > a.size()) {       sort(a.rbegin(), a.rend());       cout << a << endl;       return 0;     } else {       for (long long int i = 0; i < a.size(); i++) {         mp[a[i] -  0 ]++;       }       solve(0, false);       for (long long int i = 0; i < b.size(); i++) {         cout << x[i];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n, t = 1;     while (t--) {       cin >> n;       vector<long> v(n), b(n), ans(n, 0);       for (i = 0; i < n; i++) {         cin >> v[i];         b[i] = v[i];       }       for (i = n - 2; i >= 0; i--) {         if (b[i + 1] >= v[i]) ans[i] = 1 + b[i + 1] - v[i];         b[i] = max(b[i], b[i + 1]);       }       for (i = 0; i < n; i++) {         cout << ans[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 3e5 + 100;   string s;   int n;   int main() {     while (scanf( %d , &n) != EOF) {       cin >> s;       int len = s.length();       int flag = 0;       int i;       for (i = 1; i < len; i++) {         if (s[i] < s[i - 1]) {           flag = 1;           break;         }       }       if (flag == 0)         cout <<  NO  << endl;       else         cout <<  YES  << endl << i <<     << i + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e7 + 10;   int n;   vector<string> a;   vector<pair<pair<int, int>, int> > pos;   char s[N];   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); i++) {       int m;       string t;       cin >> t;       a.push_back(t);       scanf( %d , &m);       for (int j = (0); j < (m); j++) {         int at;         scanf( %d , &at);         at--;         pos.push_back(make_pair(make_pair(at, -(int)a[i].size()), i));       }     }     sort(pos.begin(), pos.end());     int p = 0;     for (int i = (0); i < ((int)pos.size()); i++) {       int at = pos[i].first.first, len = -pos[i].first.second, id = pos[i].second;       while (p < at) s[p++] =  a ;       if (p >= at && p < at + len) {         for (int j = (p - at); j < (len); j++) s[p++] = a[id][j];       }     }     printf( %s n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string second;     long long n, i, m, ans = 0, j, k, sum = 0;     cin >> m;     n = m;     vector<long long> b(m / 2), a(n);     for (i = 0; i < n / 2; i++) cin >> b[i];     a[0] = 0;     a[n - 1] = b[0];     for (i = 1; i < m / 2; i++) {       long long diff = 0;       if (b[i] > a[n - i]) diff = b[i] - a[n - i];       if (diff < a[i - 1]) diff = a[i - 1];       a[i] = diff;       a[n - i - 1] = b[i] - diff;     }     for (i = 0; i < a.size(); i++) cout << a[i] <<    ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long m;   long long ten[1005], f[1005][105][2];   int MAIN() {     scanf( %d%d%lld , &n, &k, &m);     ten[0] = 1;     for (int i = 1; i < 1005; ++i) {       ten[i] = ten[i - 1] * 10 % k;     }     f[0][0][0] = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < k; ++j) {         for (int s = 0; s < 2; ++s) {           for (int x = 0; x < 10; ++x) {             if (i == n - 1 && x == 0) {               continue;             }             int next_k = (ten[i] * x + j) % k;             int next_s = (s || (x != 0 && next_k == 0)) ? 1 : 0;             f[i + 1][next_k][next_s] =                 (f[i + 1][next_k][next_s] + f[i][j][s]) % m;           }         }       }     }     long long ans = 0;     for (int i = 0; i < k; ++i) {       ans = ans + f[n][i][1];     }     ans %= m;     printf( %lld n , ans);     return 0;   }   int main() {     ios ::sync_with_stdio(false);     cout << fixed << setprecision(16);     return MAIN();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   int ans = 0, n;   int a, b, c;   void cbh(int uuu, int len) {     if (len == n) return;     if (uuu == 1) {       if (a < b)         ans += a, cbh(2, len + 1);       else         ans += b, cbh(3, len + 1);     } else if (uuu == 2) {       if (a < c)         ans += a, cbh(1, len + 1);       else         ans += c, cbh(3, len + 1);     } else {       if (b < c)         ans += b, cbh(1, len + 1);       else         ans += c, cbh(2, len + 1);     }   }   int main() {     scanf( %d%d%d%d , &n, &a, &b, &c);     if (n <= 1) {       puts( 0 );       return 0;     }     cbh(1, 1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     std::cin >> n;     int max_x = 0;     std::vector<int> v(n, 0);     for (int i = 0; i < n; ++i) {       std::cin >> v[i];     }     for (const auto& elem : v) {       int tmp = elem + max_x;       if (tmp > max_x) max_x = tmp;       std::cout << tmp <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MIN(int a, int b) {     int x = (b > a) ? a : b;     return x;   }   int MAX(int a, int b) {     int x = (b < a) ? a : b;     return x;   }   const int size = 1000007;   const long long modulo = 1000000007;   const long long inf = 1e18;   const double eps = 1e-6;   long long t, n, p, m, b[4000], k, n25, n50, n100;   bool flg[1000][1000];   int a[100009];   int main() {     while (cin >> n >> m) {       long long ase = n * 100 + m * 10;       long long cnt = 0;       while (ase >= 220) {         if (cnt % 2 == 0) {           if (n >= 2) {             n--;             n--;             if (m >= 2) {               m -= 2;               cnt++;             }           } else {             int less = 220 - (n * 100);             int j = less / m;             n = 0;             m = m - j;             cnt++;           }           ase -= 220;         } else {           if (m >= 22) {             m -= 22;             cnt++;           } else {             if (m >= 12) {               m -= 12;               n--;               cnt++;             } else if (m >= 2) {               m -= 2;               n -= 2;               cnt++;             }           }           ase -= 220;         }       }       if (cnt % 2 == 0)         cout <<  Hanako n ;       else         cout <<  Ciel n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 998244353;   long long int dx[] = {0, 0, 1, -1};   long long int dy[] = {1, -1, 0, 0};   long long int m = 0, n, res, k, ans = 0, nbcycle = 0;   string s2 =  zero , ch =   , s, t, s1 =   ;   set<pair<long long int, long long int> > st;   vector<pair<string, long long int> > vm;   vector<pair<long long int, pair<long long int, long long int> > > vvv;   vector<pair<long long int, long long int> > vv, vv2;   vector<long long int> v[300005], v2;   long long int dp[505][505][2], a[5005];   long long int pal[505][505];   long long int solve(long long int i, long long int j, long long int flag) {     if (i == j) return 1;     if (i > j) return flag;     long long int &ret = dp[i][j][flag];     if (ret != -1) return ret;     long long int ans = min(1 + solve(i + 1, j, 0), 1 + solve(i, j - 1, 0));     for (long long int k = i + 1; k <= j; k++) {       if (a[i] == a[k])         ans = min(ans, solve(i + 1, k - 1, 1) + solve(k + 1, j, 0));     }     return ret = ans;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int i = 0, x, y, z, j = 0, q, mm = 0, mx = -1e9, idx = 0, ok = 0,                   l = 0, r = 0, negatif = 0, positif = 0, l1, r1, d;     set<pair<long long int, long long int> >::iterator it, it1;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       pal[i][i] = 1;     }     memset(dp, -1, sizeof(dp));     cout << solve(1, n, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Timer {     Timer() { beg = clock(); }     ~Timer() {}     clock_t beg;   };   int main() {     ios_base::sync_with_stdio(false);     int n, d, h;     cin >> n >> d >> h;     if (d < h) {       cout << -1 << endl;       return 0;     }     if (d == 1 && h == 1) {       if (n == 2) {         cout << 1 <<     << 2 << endl;       } else {         cout << -1 << endl;       }       return 0;     }     if (2 * h < d) {       cout << -1 << endl;       return 0;     }     if (n < d + 1) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < h; ++i) {       cout << i + 1 <<     << i + 2 << endl;     }     if (d - h > 0) {       cout << 1 <<     << h + 2 << endl;     }     for (int i = 0; i < d - h - 1; ++i) {       cout << i + h + 2 <<     << i + h + 3 << endl;     }     for (int i = 0; i < n - d - 1; ++i) {       cout << h <<     << i + d + 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       set<int> s;       for (int i = 0; i < n; i++) {         int temp;         cin >> temp;         s.insert(temp);       }       if (s.size() != n)         cout <<  YES n ;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (!y) return x;     return gcd(y, x % y);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sortbysecinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second > b.second);   }   bool sortbysize(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   bool sortcol(const vector<int> &v1, const vector<int> &v2) {     return v1[0] < v2[0];   }   long long proceed() {     long long l, r, m, i, mn = 1e15, a;     cin >> l >> r >> m;     for (i = l; i <= r; ++i) {       if (i <= m) {         long long x = m % i;         if (x < mn) mn = x, a = i;       }       long long y = i - m % i;       if (y < mn) mn = y, a = i;     }     (m + mn) % a == 0 ? cout << a <<     << l <<     << l + mn <<   n                        : cout << a <<     << l + mn <<     << l <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1, i = 0;     cin >> t;     while (t--) {       proceed();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   int biton(int N, int pos) { return N = N | (1 << pos); }   int bitoff(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int n, ar[1234567], k;   pair<int, int> p[323456];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i].first);       p[i].second = i + 1;       ar[i + 1] = p[i].first;     }     sort(p, p + n, greater<pair<int, int>>());     int start = k + 1;     long long int ans = 0;     map<int, int> block, ok;     for (int i = 0; i < n; i++) {       while (block[start] != 0) start++;       if (start < p[i].second) {         ok[p[i].second] = p[i].second;         block[p[i].second] = p[i].second;       } else {         ok[p[i].second] = start;         block[start] = start;         start++;       }     }     long long int sum = 0;     for (int i = 1; i <= n; i++) {       sum += 1LL * (ok[i] - i) * ar[i];     }     printf( %lli n , sum);     for (int i = 1; i <= n; i++) printf( %i  , ok[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     int d, n;     cin >> d >> n;     vector<int> days(n);     for (int i = 0; i < n; i++) cin >> days[i];     int count = 0;     for (int i = 1; i < n; i++) count += d - days[i - 1];     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int f(long long int a) {     long long int i, r = 0;     for (i = 1; i <= a; i++) {       r += i * (9 * (pow(10, i - 1)));     }     return r;   }   int main() {     long long int i, n, a;     cin >> n;     for (i = 1; n % (long long int)(pow(10, i)) != n; i++)       ;     a = f(i - 1);     n = n - (pow(10, i - 1));     a = a + ((n + 1) * (i));     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<string> s(n + 2);     for (int i = 1; i <= n; i++) {       cin >> s[i];       s[i] =  .  + s[i] +  . ;     }     s[0] = s[n + 1] = string(m + 2,  . );     vector<vector<int>> d(n + 2, vector<int>(m + 2, 1e9));     priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,                    greater<pair<int, pair<int, int>>>>         pq;     for (int i = 0; i < n + 2; i++) {       for (int j = 0; j < m + 2; j++) {         if (s[i][j] ==  . ) {           d[i][j] = 0;           pq.push({0, {i, j}});         }       }     }     while (!pq.empty()) {       int dis = pq.top().first;       int i, j;       tie(i, j) = pq.top().second;       pq.pop();       if (dis > d[i][j]) continue;       for (int di = -1; di <= 1; di++) {         if (i == 0 && di == -1) continue;         if (i == n + 1 && di == 1) continue;         for (int dj = -1; dj <= 1; dj++) {           if (j == 0 && dj == -1) continue;           if (j == m + 1 && dj == 1) continue;           if (d[i + di][j + dj] > d[i][j] + 1) {             d[i + di][j + dj] = d[i][j] + 1;             pq.push({d[i + di][j + dj], {i + di, j + dj}});           }         }       }     }     int mx = 0;     vector<vector<pair<int, int>>> x(2000);     for (int i = 0; i < n + 2; i++) {       for (int j = 0; j < m + 2; j++) {         mx = max(mx, d[i][j]);         if (d[i][j] > 0) {           x[d[i][j]].emplace_back(i, j);         }       }     }     vector<vector<int>> e;     int ans = mx;     int lo = 1, hi = mx + 1;     while (lo + 1 < hi) {       e = vector<vector<int>>(n + 2, vector<int>(m + 2));       for (int i = 0; i < n + 2; i++) e[i][0] = e[i][m + 1] = 1e9;       for (int i = 0; i < m + 2; i++) e[0][i] = e[n + 1][i] = 1e9;       int mid = (lo + hi) / 2;       queue<pair<int, int>> que;       for (auto p : x[mid]) {         if (d[p.first][p.second] == mid) {           que.push({p.first, p.second});           e[p.first][p.second] = mid;           ans = mid;         }       }       int tmp = mid - 1;       while (que.size() && tmp) {         for (int jj = que.size(); jj > 0; jj--) {           int i, j;           tie(i, j) = que.front();           que.pop();           for (int di = -1; di <= 1; di++) {             for (int dj = -1; dj <= 1; dj++) {               if (e[i + di][j + dj] != mid) {                 e[i + di][j + dj] = mid;                 que.push({i + di, j + dj});               }             }           }         }         tmp--;       }       bool ok = true;       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < m + 1; j++) {           if (d[i][j] != 0 && d[i][j] < mid && e[i][j] == 0) {             ok = false;             break;           }         }         if (!ok) break;       }       if (ok) {         lo = mid;       } else {         hi = mid;       }     }     ans = lo - 1;     vector<string> res(n, string(m,  . ));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  X ) {           if (d[i][j] > ans) {             res[i - 1][j - 1] =  X ;           }         }       }     }     cout << ans <<   n ;     for (int i = 0; i < n; i++) {       cout << res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int mn = a[n];     for (int i = 1; i <= n / 2; i++) mn = min(mn, a[i + n / 2] - a[i]);     printf( %d n , mn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[300005], r[300005];   int main() {     int n;     scanf( %d , &n);     int lm = -1, rm = 0x3f3f3f3f;     int ansl = 0, ansr = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       if (l[i] > lm) {         ansl = i;         lm = l[i];       }       if (r[i] < rm) {         ansr = i;         rm = r[i];       }     }     int lmm = 0x3f3f3f3f, rmm = -1;     for (int i = 1; i <= n; i++) {       if (l[i] == lm && lmm > r[i]) {         lmm = r[i];         ansl = i;       }       if (r[i] == rm && rmm < l[i]) {         rmm = l[i];         ansr = i;       }     }     if (ansl == ansr) {       int lll = -1, rrr = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansl) continue;         lll = max(lll, l[i]);         rrr = min(rrr, r[i]);       }       if (rrr <= lll) {         printf( 0 n );       } else         printf( %d n , rrr - lll);     } else {       int ll1 = -1, rr1 = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansl) continue;         ll1 = max(ll1, l[i]);         rr1 = min(rr1, r[i]);       }       int ll2 = -1, rr2 = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansr) continue;         ll2 = max(ll2, l[i]);         rr2 = min(rr2, r[i]);       }       if (ll2 >= rr2 && ll1 >= rr1)         printf( 0 n );       else {         int ans = max(rr2 - ll2, rr1 - ll1);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct camel {     int x, y;   };   int main() {     int n;     bool r = false;     cin >> n;     camel arr[n];     for (int i = 0; i < n; i++) cin >> arr[i].x >> arr[i].y;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++)         if (arr[i].x + arr[i].y == arr[j].x)           if (arr[j].x + arr[j].y == arr[i].x) r = true;     }     if (r)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using lld = long double;   using vi = vector<int>;   using vll = vector<long long>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int x[n];     for (int &u : x) {       cin >> u;     }     sort(x, x + n);     if ((x[n - 1] - x[0] == 0) || (x[n - 1] - x[0] == 1)) {       cout << n << endl;       for (int &u : x) {         cout << u <<    ;       }     } else {       int a = count(x, x + n, x[0]);       int b = count(x, x + n, x[0] + 1);       int c = count(x, x + n, x[0] + 2);       if (2 * min(a, c) > 2 * (b / 2)) {         cout << n - (2 * min(a, c)) << endl;         if (a <= c) {           b += 2 * a;           c -= a;           a = 0;         } else {           b += 2 * c;           a -= c;           c = 0;         }       } else {         cout << n - (2 * (b / 2)) << endl;         if (b % 2 == 0) {           a += b / 2;           c += b / 2;           b = 0;         } else {           a += b / 2;           c += b / 2;           b = 1;         }       }       while (a--) {         cout << x[0] <<    ;       }       while (b--) {         cout << x[0] + 1 <<    ;       }       while (c--) {         cout << x[0] + 2 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 200005;   int prime[1100000], primesize;   bool isprime[11000000];   long long f[N], invf[N];   long long inv[N];   void getlist(int listsize) {     memset(isprime, 1, sizeof(isprime));     isprime[1] = false;     for (int i = 2; i <= listsize; i++) {       if (isprime[i]) prime[++primesize] = i;       for (int j = 1; j <= primesize && i * prime[j] <= listsize; j++) {         isprime[i * prime[j]] = false;         if (i % prime[j] == 0) break;       }     }   }   void extend_gcd(long long a, long long b, long long& d, long long& x,                   long long& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       extend_gcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   void ni(int n) {     inv[0] = inv[1] = 1;     for (int i = 2; i <= n; i++) {       inv[i] = (mod - (mod / i)) * inv[mod % i] % mod;     }   }   long long fpow(long long a, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = (res * a) % mod;       k >>= 1;       a = a * a % mod;     }     return res;   }   void init(int n) {     f[0] = 1;     for (int i = 1; i <= n; ++i) {       f[i] = f[i - 1] * i % mod;     }     invf[n] = fpow(f[n], mod - 2);     for (int i = n - 1; i >= 0; --i) {       invf[i] = invf[i + 1] * (i + 1) % mod;     }   }   long long C(int n, int k) {     if (k < 0 || k > n) return 0;     return f[n] * invf[k] % mod * invf[n - k] % mod;   }   long long pos[27][200005];   long long num[27];   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       pos[s[i] -  a ][0]++;       pos[s[i] -  a ][pos[s[i] -  a ][0]] = i + 1;     }     long long m;     cin >> m;     for (int i = 1; i <= m; i++) {       memset(num, 0, sizeof(num));       string x;       cin >> x;       long long res = 0;       for (auto j : x) {         num[j -  a ]++;         res = max(res, pos[j -  a ][num[j -  a ]]);       }       cout << res << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n, ch = 0;     string s, g;     cin >> n >> k >> s;     for (int i = 1; i <= n && ch == 0; i++) {       string t = s.substr(0, i);       string temp =   0 ;       int count;       (n % i == 0) ? count = n / i : count = (n / i) + 1;       for (int j = 0; j < count; j++) temp += t;       if (temp.find(s) == 0) {         g = t;         ch++;       }     }     string l =   0 ;     for (int i = 0; i < k - 1; i++) l += g;     l += s;     cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a, b[1000002], c = 0, d, e, f, g, h, i, j;   int main() {     cin >> a;     for (i = 1; i <= a; i++) {       cin >> d;       b[d]++;       if (b[d] > c) {         c = b[d];         e = d;       }     }     cout << e;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char a[n][m];     bool vis[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         vis[i][j] = false;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i > 0 && i < n - 1 && j > 0 && j < m - 1) {           bool flag = true;           for (int k = -1; k <= 1; k++) {             for (int l = -1; l <= 1; l++) {               if (k == 0 && l == 0) continue;               if (a[i + k][j + l] ==  . ) {                 flag = false;               }             }           }           if (flag == true) {             for (int k = -1; k <= 1; k++) {               for (int l = -1; l <= 1; l++) {                 if (k == 0 && l == 0) continue;                 vis[i + k][j + l] = true;               }             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  #  && vis[i][j] == false) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   typedef long long int ll;   typedef unsigned long long int ull;   #define N 1010100   #define inf 1e9      #define loop(x, n, r) for(int i = x; i < n; i += r)      #define pb push_back   #define pp pair<int, int>      using namespace std;      int main(){       ios::sync_with_stdio(0); cin.tie(0);       int T = 1;       cin >> T;       while(T--){           int n;           cin >> n;           string b;           cin >> b;           cout <<  1 ;           char prev = b[0] ==  0  ?  1  :  2 ;           loop(1, n, 1){               if(prev ==  2 ){                   if(b[i] ==  1 )                       cout <<  0 ;                   else                       cout <<  1 ;                   prev =  1 ;               }               else if(prev ==  1 ){                   if(b[i] ==  1 ){                       cout <<  1 ;                       prev =  2 ;                   }                   else{                       cout <<  0 ;                       prev =  0 ;                   }               }               else{                   if(b[i] ==  1 ){                       cout <<  1 ;                       prev =  2 ;                   }                   else{                       cout <<  1 ;                       prev =  1 ;                   }               }           }           cout <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   const int INF = 1000000000, mod = 1000000007;   const long long LLINF = 1000000000000000000ll;   long long n, k, d1, d2;   bool try_solve(long long d1, long long d2) {     if (n % 3) return 0;     if ((k - d1 + d2) % 3) return 0;     long long x2 = (k - d1 + d2) / 3;     if (x2 >= 0 && x2 <= k) {       long long x1 = d1 + x2;       long long x3 = x2 - d2;       if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k && x1 <= n / 3 &&           x2 <= n / 3 && x3 <= n / 3) {         return 1;       }     }     return 0;   }   int main() {     int t;     scanf( %d , &t);     while (t-- > 0) {       scanf( %I64d %I64d %I64d %I64d , &n, &k, &d1, &d2);       bool can = 0;       for (int i = -1; i <= 1; ++i) {         for (int j = -1; j <= 1; ++j) {           if (i == 0 || j == 0) continue;           can |= try_solve(d1 * i, d2 * j);         }       }       puts(can ?  yes  :  no );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   void dprintln(const T &t) {     cout << t << endl;   }   template <typename T, typename... Args>   void dprintln(const T &t, const Args &...rest) {     cout << t <<    ;     dprintln(rest...);   }   template <typename T>   void println(const T &t) {     cout << t <<   n ;   }   template <typename T, typename... Args>   void println(const T &t, const Args &...rest) {     cout << t <<    ;     println(rest...);   }   template <typename T>   void print(const T &t) {     cout << t <<    ;   }   template <typename T, typename... Args>   void print(const T &t, const Args &...rest) {     cout << t;     print(rest...);   }   template <class T>   void scan(T &t) {     cin >> t;   }   template <class T, class... Args>   void scan(T &a, Args &...rest) {     cin >> a;     scan(rest...);   }   using ll = long long;   using vl = vector<ll>;   using vi = vector<int>;   using pii = pair<int, int>;   using vb = vector<bool>;   using vpii = vector<pii>;   template <typename T>   struct bit {     vector<T> a;     explicit bit(int n, int v = 0) {       a.resize(n + 1);       if (v != 0) {         for (int i = 1; i <= n; ++i) a[i] = v;       }     }     T sum(T x) {       T res = 0;       while (x) {         res += a[x];         x -= x & -x;       }       return res;     }     T sum(int l, int r) {       if (l > r) return 0;       return sum(r) - sum(l - 1);     }     void add(int x, T v) {       while (x < a.size()) {         a[x] += v;         x += x & -x;       }     }     void clear() { fill(a.begin(), a.end(), 0); }   };   vi get_prime(int n) {     vi minp(n + 1), p;     for (int i = 2; i <= n; i++) {       if (!minp[i]) {         minp[i] = i;         p.push_back(i);       }       for (auto &x : p) {         if (x <= minp[i] && x * i <= n)           minp[x * i] = x;         else           break;       }     }     return p;   }   const int mod = 1000000007;   inline void add_mod(ll &x, const ll &y) {     x += y;     if (x >= mod) x -= mod;   }   void sub_mod(ll &x, const ll &y) {     x -= y;     if (x < 0) x += mod;   }   template <typename T>   using vv = vector<vector<T>>;   template <typename T1, typename T2 = T1>   using vp = vector<pair<T1, T2>>;   template <typename T, int n>   using va = vector<array<T, n>>;   using vec = vector<ll>;   using mat = vector<vec>;   mat get_I(int n) {     mat res(n, vec(n));     for (int i = 0; i < n; i++) res[i][i] = 1;     return res;   }   mat operator*(const mat &a, const mat &b) {     mat c(a.size(), vec(b[0].size()));     for (size_t i = 0; i < a.size(); i++) {       for (size_t j = 0; j < a[0].size(); j++) {         if (a[i][j]) {           for (size_t k = 0; k < b[0].size(); k++) {             add_mod(c[i][k], a[i][j] * b[j][k] % mod);           }         }       }     }     return c;   }   vec operator*(const mat &a, const vec &b) {     vec c(a.size());     for (size_t i = 0; i < a.size(); i++) {       for (size_t j = 0; j < a[0].size(); j++) {         add_mod(c[i], a[i][j] * b[j] % mod);       }     }     return c;   }   mat pow(mat a, ll n) {     mat res(a.size(), vec(a[0].size()));     for (size_t i = 0; i < a.size(); i++) {       res[i][i] = 1;     }     while (n) {       if (n & 1) {         res = res * a;       }       a = a * a;       n >>= 1;     }     return res;   }   struct UF {     vi par;     explicit UF(int n) {       par.assign(n + 1, 0);       for (int i = (1); i < (n + 1); ++i) par[i] = i;     }     int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }     void unite(int x, int y) { par[find(x)] = find(y); }   };   vi get_popcnt(int n) {     vi res(n + 1);     for (int i = (0); i < (n); ++i) {       if (i * 2 <= n) res[i * 2] = res[i];       if ((i & 1) == 0) res[i + 1] = res[i] + 1;     }     return res;   }   template <class T>   struct SparseTable {     std::vector<std::vector<T>> f;     std::vector<int> lg;     SparseTable() {}     SparseTable(const std::vector<T> &a) { init(a); }     void init(const std::vector<T> &a) {       int n = a.size();       lg.assign(n + 1, 0);       for (int i = 1, j = 0; i <= n; i++) {         if (i == (1 << (j + 1))) j++;         lg[i] = j;       }       f.assign(lg.back() + 1, std::vector<T>(a.size()));       f[0] = a;       for (int j = 1; (1 << j) <= n; j++) {         for (int i = 0; i + (1 << j) - 1 < n; i++) {           f[j][i] = min(f[j - 1][i], f[j - 1][i + (1 << (j - 1))]);         }       }     }     T query(int l, int r) {       int j = lg[r - l + 1];       return min(f[j][l], f[j][r - (1 << j) + 1]);     }   };   struct LCA {     const std::vector<std::vector<int>> &g;     SparseTable<std::pair<int, int>> st;     std::vector<int> sp;     std::vector<int> dep, ST, ED;     LCA(const std::vector<std::vector<int>> &graph, int root = 1) : g(graph) {       int sz = graph.size();       dep = ST = ED = std::vector<int>(sz);       dfs(root, -1, 0);       std::vector<std::pair<int, int>> vec;       for (int i = 0; i < sp.size(); i++) {         vec.emplace_back(ST[sp[i]], sp[i]);       }       st.init(vec);     }     void dfs(int u, int fa, int d) {       dep[u] = d + 1;       ST[u] = sp.size();       sp.push_back(u);       for (auto v : g[u]) {         if (v != fa) {           dfs(v, u, d + 1);           sp.push_back(u);         }       }       ED[u] = (int)sp.size() - 1;     }     int query(int u, int v) {       int l = ST[u], r = ST[v];       if (l > r) std::swap(l, r);       return st.query(l, r).second;     }     bool on_path(int x, int y, int z) {       int anc = query(x, y);       if (dep[z] < dep[anc]) return false;       return query(x, z) == z || query(y, z) == z;     }   };   const int N = (int)2e5 + 5, M = 1005;   struct node {     bool ok;     int u, v;   } tree[N * 4];   int leaf[N];   int p[N];   int v[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vv<int> g(n + 1);     for (int i = (1); i < (n + 1); ++i) cin >> p[i], v[p[i]] = i;     for (int i = (2); i < (n + 1); ++i) {       int x;       cin >> x;       g[x].push_back(i);     }     LCA lca(g);     auto check = [&lca](int a, int b, int c, int d) -> vi {       if (a == 0) return {c, d};       int x[4] = {a, b, c, d};       for (int i = (0); i < (3); ++i)         for (int j = (i + 1); j < (4); ++j) {           int anc = lca.query(x[i], x[j]);           bool flag = true;           for (int k = (0); k < (4); ++k) {             if (k != i && k != j) {               int t = x[k];               if (!lca.on_path(x[i], x[j], t)) {                 flag = false;                 break;               }             }           }           if (flag) return {x[i], x[j]};         }       return {-1, -1};     };     auto push_up = [&check](int id) {       auto &f = tree[id], lson = tree[id * 2], rson = tree[id * 2 + 1];       if (lson.ok && rson.ok) {         auto res = check(lson.u, lson.v, rson.u, rson.v);         if (res[0] != -1) {           f.ok = true;           f.u = res[0];           f.v = res[1];         } else           f.ok = false;       } else {         f.ok = false;       }     };     function<void(int, int, int)> build;     build = [&build, &push_up](int id, int l, int r) {       if (l == r) {         leaf[l] = id;         tree[id].u = tree[id].v = v[l];         tree[id].ok = true;         return;       }       int mid = (l + r) / 2;       build(id * 2, l, mid);       build(id * 2 + 1, mid + 1, r);       push_up(id);     };     build(1, 0, n - 1);     auto work = [&push_up](int i) {       int id = leaf[p[i]];       tree[id].u = tree[id].v = i;       while (id != 1) {         id /= 2;         push_up(id);       }     };     auto upd = [&work](int i, int j) {       swap(p[i], p[j]);       work(i);       work(j);     };     function<int(int, int, int, int, int)> query;     query = [&check, &query](int id, int l, int r, int u, int v) {       if (tree[id].ok) {         auto t = check(u, v, tree[id].u, tree[id].v);         if (t[0] != -1) return r - l + 1;         if (l == r) return 0;       }       int mid = (l + r) / 2;       auto &lson = tree[id * 2];       if (lson.ok) {         auto t = check(u, v, lson.u, lson.v);         if (t[0] != -1) {           return mid - l + 1 + query(id * 2 + 1, mid + 1, r, t[0], t[1]);         }       }       return query(id * 2, l, mid, u, v);     };     int q;     cin >> q;     for (int _ = 0, __ = (int)q; _ < __; _++) {       int t, i, j;       scan(t);       if (t == 1) {         scan(i, j);         upd(i, j);       } else {         println(query(1, 0, n - 1, 0, 0));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int countBits(long long mask) {     int res = 0;     while (mask) mask &= (mask - 1), ++res;     return res;   }   string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   long long toNumber(string s) {     stringstream ss;     long long n;     ss << s;     ss >> n;     return n;   }   bool palindrome[2001][2001];   int Start[2001], End[2001], cumEnd[2001];   int main() {     string str;     while (cin >> str) {       memset(Start, 0, sizeof Start);       memset(End, 0, sizeof End);       memset(palindrome, 0, sizeof palindrome);       for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i) {         palindrome[i][i] = true;         if (i && str[i] == str[i - 1]) palindrome[i - 1][i] = true;       }       for (int len = (int)(3), _m = (int)(str.size()); len < _m; ++len)         for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i)           if (len + i - 1 >= str.size())             break;           else             palindrome[i][i + len - 1] =                 (str[i] == str[i + len - 1]) && palindrome[i + 1][i + len - 2];       for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i) {         for (int j = (int)(i), _m = (int)(str.size()); j < _m; ++j)           Start[i] += palindrome[i][j];         for (int j = (int)(0), _m = (int)(i + 1); j < _m; ++j)           End[i] += palindrome[j][i];         cumEnd[i] = End[i] + (!i ? 0 : cumEnd[i - 1]);       }       long long res = 0;       for (int i = (int)(1), _m = (int)(str.size()); i < _m; ++i)         res += (long long)Start[i] * cumEnd[i - 1];       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt_t = 0;   vector<pair<int, int>> ls_[2];   vector<int> upb, downb;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) {       return a.first < b.first;     }     return a.second < b.second;   }   long long proc(vector<pair<int, int>> &ls) {     long long sum = 0;     int sz = ls.size();     if (sz == 0) return 0;     sort(ls.begin(), ls.end(), cmp);     int ex_up = 0, ex_down = 0;     int bup = -200001;     int bdown = -bup;     int i, rup, rdown;     for (i = 0; i < sz; i++) {       if (ls[i].second > bup || ls[i].second == bup && ls[i].first > rup) {         bup = ls[i].second, rup = ls[i].first;       }       if (ls[i].second < bdown || ls[i].second == bdown && ls[i].first > rdown) {         bdown = ls[i].second, rdown = ls[i].first;       }     }     int j, k;     int bd;     bd = ls[0].second;     int bsz = (ls.back().first - ls[0].first) / 2;     upb.clear();     upb.resize(bsz);     downb.clear();     downb.resize(bsz);     for (i = 0, k = ls[0].first; k < rup; k += 2) {       for (j = i; ls[j].first == k; j++)         ;       if (j > i) {         if (ls[j - 1].second > bd) bd = ls[j - 1].second;         i = j;       }       upb[(k - ls[0].first) / 2] = bd;     }     bd = ls[0].second;     for (i = 0, k = ls[0].first; k < rdown; k += 2) {       for (j = i; ls[j].first == k; j++)         ;       if (j > i) {         if (ls[i].second < bd) bd = ls[i].second;         i = j;       }       downb[(k - ls[0].first) / 2] = bd;     }     bd = ls.back().second;     for (i = sz - 1, k = ls.back().first; k > rup; k -= 2) {       for (j = i; ls[j].first == k; j--)         ;       if (j < i) {         if (ls[i].second > bd) bd = ls[i].second;         i = j;       }       upb[bsz - 1 - (ls.back().first - k) / 2] = bd;     }     bd = ls.back().second;     for (i = sz - 1, k = ls.back().first; k > rdown; k -= 2) {       for (j = i; ls[j].first == k; j--)         ;       if (j < i) {         if (ls[j + 1].second < bd) bd = ls[j + 1].second;         i = j;       }       downb[bsz - 1 - (ls.back().first - k) / 2] = bd;     }     for (i = 0; i < bsz; i++) {       if (upb[i] >= downb[i]) {         sum += (upb[i] - downb[i]) / 2;       }     }     return sum;   }   int main() {     int n, i, u, v;     scanf( %d , &n);     ls_[0].clear();     ls_[1].clear();     for (i = 0; i < n; i++) {       scanf( %d%d , &u, &v);       ls_[((u + v) % 2 + 2) % 2].push_back(make_pair(u - v, u + v));     }     long long ans = proc(ls_[0]) + proc(ls_[1]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, n, m, k;     int i, j, a[55];     bool f = 0;     cin >> n >> m >> k;     for (i = 0; i < n; i++) cin >> a[i];     sort(a + 0, a + n);     if (k >= m) {       cout << 0 << endl;       f = 1;     } else       for (i = n - 1, x = 0; i >= 0 && k > 0; i--) {         if (i < (n - 1))           x += (a[i] - 1);         else           x += a[i];         if ((x + k - 1) >= m) {           cout << (n - i) << endl;           f = 1;           break;         }       }     if (f == 0) cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ch = getchar(), f = 0;     int x = 0;     while (ch <  0  || ch >  9 ) {       f |= ch ==  - ;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f ? -x : x;   }   struct eric {     int to, next, v;   } edge[10005 << 4];   int head[10005], size = 1;   int n, m;   int dis[10005], out[10005 << 4], vis[10005], used[10005], num[10005];   inline void add(int x, int y, int z) {     edge[++size].to = y;     edge[size].v = z;     edge[size].next = head[x];     head[x] = size;   }   queue<int> que;   int ined[10005];   void dfs1(int pos) {     vis[pos] = 1;     for (int i = head[pos]; i; i = edge[i].next) {       int v = edge[i].to;       if (edge[i].v < 0 || vis[v]) continue;       dfs1(v);     }   }   void dfs2(int pos) {     used[pos] = 1;     for (int i = head[pos]; i; i = edge[i].next) {       int v = edge[i].to;       if (edge[i].v > 0 || used[v]) continue;       dfs2(v);     }   }   inline bool ok(int x, int y) { return used[x] && used[y] && vis[x] && vis[y]; }   inline void SPFA(int s) {     for (int i = 1; i <= n; i++) dis[i] = -1000000007 / 10;     dis[s] = 0;     que.push(s);     ined[s] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       ined[u] = 0;       for (int i = head[u]; i; i = edge[i].next) {         int v = edge[i].to;         if (dis[v] < dis[u] + edge[i].v && ok(u, v)) {           dis[v] = dis[u] + edge[i].v;           if (!ined[v]) ined[v] = 1, que.push(v), num[v]++;         }       }       if (num[u] >= n) {         puts( No );         exit(0);       }     }   }   int main() {     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++)       x = read(), y = read(), add(x, y, 1), add(y, x, -2);     dfs1(1);     dfs2(n);     SPFA(1);     for (int u = 1; u <= n; u++) {       for (int i = head[u]; i; i = edge[i].next) {         int v = edge[i].to;         if (!ok(u, v)) {           out[i >> 1] = 1;           continue;         }         out[i >> 1] = abs(dis[v] - dis[u]);         if (out[i >> 1] > 2) {           puts( No );           return 0;         }       }     }     puts( Yes );     for (int i = 1; i <= m; i++) printf( %d n , out[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double sum = 0;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) sum += 1.0 / i;     printf( %.12f n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b, c, d;     cin >> a >> b >> c >> d;     if (a + b == c + d || a + c == b + d || a + d == b + c || a + b + c == d ||         a + c + d == b || b + c + d == a || a + b + d == c) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;   const int INF = 0x3f3f3f3f;   const ll LINF = 0x3f3f3f3f3f3f3f3fLL;   const double EPS = 1e-8;   const int MOD = 1000000007;   const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};   const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},             dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};   template <typename T, typename U>   inline bool chmax(T &a, U b) {     return a < b ? (a = b, true) : false;   }   template <typename T, typename U>   inline bool chmin(T &a, U b) {     return a > b ? (a = b, true) : false;   }   template <typename T>   void unique(vector<T> &a) {     a.erase(unique((a).begin(), (a).end()), a.end());   }   struct IOSetup {     IOSetup() {       cin.tie(nullptr);       ios_base::sync_with_stdio(false);       cout << fixed << setprecision(20);     }   } iosetup;   using CostType = ll;   struct Edge {     int src, dst;     CostType cost;     Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}     inline bool operator<(const Edge &rhs) const {       return cost != rhs.cost ? cost < rhs.cost              : dst != rhs.dst ? dst < rhs.dst                               : src < rhs.src;     }     inline bool operator<=(const Edge &rhs) const { return !(rhs < *this); }     inline bool operator>(const Edge &rhs) const { return rhs < *this; }     inline bool operator>=(const Edge &rhs) const { return !(*this < rhs); }   };   struct CentroidDecomposition {     int root;     vector<vector<int> > comp;     vector<int> par;     CentroidDecomposition(const vector<vector<Edge> > &graph) : graph(graph) {       int n = graph.size();       alive.assign(n, true);       subtree.resize(n);       comp.resize(n);       par.assign(n, -1);       root = build(0);     }       private:     const vector<vector<Edge> > graph;     vector<bool> alive;     vector<int> subtree;     int build(int s) {       int centroid = search_centroid(-1, s, calc_subtree(-1, s) / 2);       alive[centroid] = false;       for (const Edge &e : graph[centroid]) {         if (alive[e.dst]) {           comp[centroid].emplace_back(build(e.dst));           par[e.dst] = centroid;         }       }       alive[centroid] = true;       return centroid;     }     int calc_subtree(int par, int ver) {       subtree[ver] = 1;       for (const Edge &e : graph[ver]) {         if (e.dst != par && alive[e.dst])           subtree[ver] += calc_subtree(ver, e.dst);       }       return subtree[ver];     }     int search_centroid(int par, int ver, int half) {       for (const Edge &e : graph[ver]) {         if (e.dst != par && alive[e.dst]) {           if (subtree[e.dst] > half) return search_centroid(ver, e.dst, half);         }       }       return ver;     }   };   template <typename T>   struct LiChaoTree {     struct Line {       T a, b;       Line(T a, T b) : a(a), b(b) {}       T f(T x) { return a * x + b; }     };     LiChaoTree(const vector<T> &xs_, const T TINF, bool is_minimized = true)         : xs(xs_), TINF(TINF), is_minimized(is_minimized) {       sort((xs).begin(), (xs).end());       unique(xs);       int sz = xs.size();       while (n < sz) n <<= 1;       xs.resize(n, TINF);       Line unity(0, is_minimized ? TINF : -TINF);       dat.assign(n << 1, unity);     }     void add(T a, T b) {       Line line(a, b);       add(line, 1, 0, n);     }     void add(T a, T b, T left, T right) {       int l = lower_bound((xs).begin(), (xs).end(), left) - xs.begin(),           r = lower_bound((xs).begin(), (xs).end(), right) - xs.begin();       int len, node_l = l, node_r = r;       for (l += n, r += n, len = 1; l < r; l >>= 1, r >>= 1, len <<= 1) {         if (l & 1) {           Line line(a, b);           add(line, l++, node_l, node_l + len);           node_l += len;         }         if (r & 1) {           Line line(a, b);           node_r -= len;           add(line, --r, node_r, node_r + len);         }       }     }     T query(T x) {       int node = lower_bound((xs).begin(), (xs).end(), x) - xs.begin();       node += n;       T res = dat[node].f(x);       while (node >>= 1) {         if (is_minimized) {           chmin(res, dat[node].f(x));         } else {           chmax(res, dat[node].f(x));         }       }       return res;     }       private:     const T TINF;     bool is_minimized;     int n = 1;     vector<T> xs;     vector<Line> dat;     void add(Line &line, int node, int left, int right) {       bool l = dat[node].f(xs[left]) <= line.f(xs[left]),            r = dat[node].f(xs[right - 1]) <= line.f(xs[right - 1]);       if (l && r) {         if (!is_minimized) swap(dat[node], line);         return;       }       if (!l && !r) {         if (is_minimized) swap(dat[node], line);         return;       }       int mid = (left + right) >> 1;       bool m = line.f(xs[mid]) < dat[node].f(xs[mid]);       if (is_minimized) {         if (m) swap(dat[node], line);       } else {         if (!m) swap(dat[node], line);       }       if (line.f(xs[left]) <= dat[node].f(xs[left])) {         if (is_minimized) {           add(line, node << 1, left, mid);         } else {           add(line, (node << 1) + 1, mid, right);         }       } else {         if (is_minimized) {           add(line, (node << 1) + 1, mid, right);         } else {           add(line, node << 1, left, mid);         }       }     }   };   int main() {     int n;     cin >> n;     vector<vector<Edge> > graph(n);     for (int _ = (0); _ < (n - 1); ++_) {       int u, v;       cin >> u >> v;       --u;       --v;       graph[u].emplace_back(u, v);       graph[v].emplace_back(v, u);     }     vector<int> a(n);     for (int i = (0); i < (n); ++i) cin >> a[i];     CentroidDecomposition cent(graph);     vector<bool> visited(n, false);     ll ans = 0;     function<void(int)> dfs = [&](int root) {       visited[root] = true;       chmax(ans, a[root]);       vector<vector<ll> > sum_a, psum_a;       vector<vector<pair<ll, int> > > psum_b;       function<void(int, int, int, ll, ll, ll, int)> dfs2 =           [&](int par, int ver, int idx, ll sum, ll A, ll B, int len) {             sum += a[ver];             A += 1LL * a[ver] * len;             B += sum - a[root];             bool leaf = true;             for (const Edge &e : graph[ver]) {               if (e.dst == par || visited[e.dst]) continue;               dfs2(ver, e.dst, idx, sum, A, B, len + 1);               leaf = false;             }             if (leaf) {               sum_a[idx].emplace_back(sum);               psum_a[idx].emplace_back(A);               psum_b[idx].emplace_back(B, len - 1);             }           };       for (const Edge &e : graph[root]) {         if (visited[e.dst]) continue;         int sz = sum_a.size();         sum_a.emplace_back();         psum_a.emplace_back();         psum_b.emplace_back();         dfs2(-1, e.dst, sz, a[root], a[root], 0, 2);       }       int m = sum_a.size();       vector<ll> xs;       for (int i = (0); i < (m); ++i) {         for (ll e : sum_a[i]) xs.emplace_back(e);         for (ll e : psum_a[i]) chmax(ans, e);         for (auto pr : psum_b[i])           chmax(ans, pr.first + 1LL * a[root] * (pr.second + 1));       }       if (!xs.empty()) {         sort((xs).begin(), (xs).end());         unique(xs);         LiChaoTree<ll> lct1(xs, LINF, false);         for (int i = (0); i < (m); ++i) {           int sz = sum_a[i].size();           for (int j = (0); j < (sz); ++j)             chmax(ans, lct1.query(sum_a[i][j]) + psum_a[i][j]);           for (int j = (0); j < (sz); ++j)             lct1.add(psum_b[i][j].second, psum_b[i][j].first);         }         LiChaoTree<ll> lct2(xs, LINF, false);         for (int i = m - 1; i >= 0; --i) {           int sz = sum_a[i].size();           for (int j = (0); j < (sz); ++j)             chmax(ans, lct2.query(sum_a[i][j]) + psum_a[i][j]);           for (int j = (0); j < (sz); ++j)             lct2.add(psum_b[i][j].second, psum_b[i][j].first);         }       }       for (int e : cent.comp[root]) dfs(e);     };     dfs(cent.root);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> m1, m2;   void go(string s, map<string, int>& mp) {     if (mp.find(s) != mp.end()) {       return;     }     mp[s] = 1;     if (s[0] ==  X ) {       string s1 = s;       string s2 = s;       swap(s1[0], s1[1]);       swap(s2[0], s2[2]);       go(s1, mp);       go(s2, mp);     } else if (s[1] ==  X ) {       string s1 = s;       string s2 = s;       swap(s1[1], s1[0]);       swap(s2[1], s2[3]);       go(s1, mp);       go(s2, mp);     } else if (s[3] ==  X ) {       string s1 = s;       string s2 = s;       swap(s1[3], s1[1]);       swap(s2[3], s2[2]);       go(s1, mp);       go(s2, mp);     } else {       string s1 = s;       string s2 = s;       swap(s1[2], s1[0]);       swap(s2[2], s2[3]);       go(s1, mp);       go(s2, mp);     }   }   int main() {     string tmp;     string a;     cin >> a;     cin >> tmp;     a += tmp;     string b;     cin >> b;     cin >> tmp;     b += tmp;     go(a, m1);     go(b, m2);     int done = 0;     for (auto it : m1) {       if (m2[it.first]) {         done = 1;         cout <<  YES  << endl;         break;       }     }     if (!done) {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p[2001];   long long find_size(long long x) {     if (p[x] == -1) return 1;     return 1 + find_size(p[x]);   }   void solve() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       if (x > 0) x--;       p[i] = x;     }     long long ans = 1;     for (long long i = 0; i < n; i++) {       ans = max(ans, find_size(i));     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, maxn = 1e6, MAXN = 1 << 21;   int jc[2222222], injc[2222222], n, a, b, s[2222222], t[2222222], l, r,       pw[2222222], sz, rev[2222222], cnt;   int S[2222222], T[2222222], G[2222222], w[2][2222222], cur, gg[2222222];   long long c[2222222];   int binpow(int a, int t) {     int res = 1, p = a;     for (int i = t; i; i >>= 1) {       if (i & 1) res = (long long)res * p % mod;       p = (long long)p * p % mod;     }     return res;   }   int C(int n, int k) {     if (n < k) return 0;     return ((long long)jc[n] * injc[k] % mod) * injc[n - k] % mod;   }   void Init() {     jc[0] = injc[0] = 1;     for (int i = 1; i <= maxn; i++) {       jc[i] = (long long)jc[i - 1] * i % mod;     }     injc[maxn] = binpow(jc[maxn], mod - 2);     for (int i = maxn - 1; i >= 0; i--)       injc[i] = (long long)injc[i + 1] * (i + 1) % mod;     w[0][0] = 1;     cur = binpow(3, (mod - 1) / MAXN);     for (int i = 1; i <= MAXN; i++) w[0][i] = (long long)w[0][i - 1] * cur % mod;     w[1][0] = 1;     cur = binpow(3, mod - 1 - (mod - 1) / MAXN);     for (int i = 1; i <= MAXN; i++) w[1][i] = (long long)w[1][i - 1] * cur % mod;   }   void ntt(int d[], int flag) {     for (int i = 0; i < sz; i++) c[i] = (long long)d[i];     for (int i = 0; i < sz; i++) {       if (rev[i] > i) swap(c[i], c[rev[i]]);     }     for (int i = 2; i <= sz; i <<= 1) {       int p = i >> 1, fu = MAXN / i;       for (int j = 0; j < p; j++) {         gg[j] = w[flag][j * fu];       }       for (int j = 0; j < sz; j += i) {         for (int k = j; k < j + p; k++) {           long long tmp1 = c[k];           long long tmp2 = c[k + p] % mod * gg[k - j];           c[k] = tmp1 + tmp2;           c[k + p] = tmp1 - tmp2;         }       }     }     for (int j = 0; j < sz; j++) c[j] %= mod;     if (flag) {       int wn = binpow(sz, mod - 2);       for (int i = 0; i < sz; i++) {         c[i] = c[i] * wn % mod;       }     }     for (int i = 0; i < sz; i++) d[i] = c[i];   }   void doit() {     if (sz <= 64) {       for (int i = 0; i < sz; i++) G[i] = 0;       for (int i = 0; i < sz; i++) {         for (int j = 0; j < sz - i; j++) {           G[i + j] = ((long long)S[i] * T[j] + G[i + j]) % mod;         }       }       for (int i = 0; i < sz; i++) S[i] = G[i];       return;     }     rev[0] = 0;     for (int i = 1; i < sz; i++) {       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (cnt - 1));     }     ntt(S, 0);     ntt(T, 0);     for (int i = 0; i < sz; i++) S[i] = (long long)S[i] * T[i] % mod;     ntt(S, 1);   }   void solve(int n) {     if (n == 1) {       s[1] = 1;       return;     }     if (!n) {       s[0] = 1;       return;     }     if (n & 1) {       solve(n - 1);       t[0] = (long long)s[0] * (n - 1) % mod;       for (int i = 1; i <= n; i++)         t[i] = ((long long)s[i] * (n - 1) + s[i - 1]) % mod;       for (int i = 1; i <= n; i++) s[i] = t[i];     } else {       solve(n >> 1);       pw[0] = 1;       sz = 1;       cnt = 0;       while (sz <= n) {         sz *= 2;         cnt++;       }       int c = (n >> 1);       for (int i = 1; i <= c; i++) pw[i] = (long long)pw[i - 1] * c % mod;       for (int i = 0; i < sz; i++) S[i] = T[i] = 0;       for (int i = 0; i <= c; i++) S[i] = (long long)s[i] * jc[i] % mod;       for (int i = 0; i <= c; i++) T[i] = (long long)pw[i] * injc[i] % mod;       reverse(T, T + c + 1);       doit();       for (int j = 0; j < sz; j++) T[j] = 0;       for (int j = c; j <= n; j++) T[j - c] = (long long)S[j] * injc[j - c] % mod;       for (int j = 0; j < sz; j++) S[j] = s[j];       doit();       for (int j = 0; j <= n; j++) s[j] = S[j];     }   }   int main() {     cin >> n >> a >> b;     Init();     n--;     if (!n) {       if (!(a + b - 2))         cout << C(a + b - 2, a - 1) << endl;       else         cout << 0 << endl;       return 0;     }     solve(n);     cout << ((long long)s[a + b - 2] * C(a + b - 2, a - 1) % mod + mod) % mod          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int mod = 1e9 + 7;   int a[N];   long long fac[30];   long long sum[N];   long long Contor(int* a, int n) {     long long res = 0;     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = i + 1; j <= n; j++)         if (a[i] > a[j]) cnt++;       res += cnt * fac[n - i];     }     return res;   }   void ReContor(int* a, int n, long long k, int ed) {     int vis[30] = {0};     for (int i = 1; i <= n; i++) {       int cnt = k / fac[n - i], j;       for (j = 1; j <= n; j++)         if (!vis[j]) {           if (!cnt) break;           cnt--;         }       vis[j] = 1;       a[i] = ed + j;       k %= fac[n - i];     }   }   void init() {     fac[0] = 1;     for (int i = 1; i <= 20; i++) fac[i] = fac[i - 1] * i;   }   int main() {     init();     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + i;     int m = 15, ed = n - 15;     if (n < 15) m = n, ed = 0;     for (int i = 1; i <= m; i++) a[i] = ed + i;     long long cnt = 0;     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int l, r;         scanf( %d%d , &l, &r);         printf( %lld n , sum[r] - sum[l - 1]);       } else {         int x;         scanf( %d , &x);         cnt += x;         ReContor(a, m, cnt, ed);         for (int i = 1; i <= m; i++) sum[ed + i] = sum[ed + i - 1] + a[i];         for (int i = 1; i <= m; i++) a[i] = ed + i;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     scanf( %d , &a);     printf( %d , a % 2);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1111111111;   const long long MOD = 1e9 + 7;   int pref[5001][5001];   int nxt[5001][5001];   int dp(int i, int j) {     int x;     if (i > 0) {       x = pref[i][j] - pref[i - 1][j];     } else {       x = pref[0][j];     }     x %= MOD;     if (x < 0) {       x += MOD;     }     return x;   }   int digits[5001];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string x;     cin >> x;     for (int i = 1; i <= n; i++) {       digits[i] = x.at(i - 1) -  0 ;     }     for (int i = 0; i < 5001; i++) {       for (int j = 0; j < 5001; j++) {         if (j == 0) {           pref[j][i] = 0;         } else if (i == 0) {           pref[j][i] = 0;         } else {           pref[j][i] = 1;         }       }     }     for (int i = n; i >= 1; i--) {       for (int j = n; j >= i; j--) {         if (digits[i] == digits[j]) {           if (j == n) {             nxt[i][j] = INF;           } else {             nxt[i][j] = nxt[i + 1][j + 1] + 1;           }         } else {           nxt[i][j] = 0;         }       }     }     int a;     int next;     for (int b = 2; b <= n; b++) {       for (int c = b; c <= n; c++) {         if (digits[b] == 0) {           pref[b][c] = pref[b - 1][c];         } else {           a = max(1, 2 * b - c);           pref[b][c] = (pref[b - 1][c] % MOD + pref[b - 1][b - 1] % MOD -                         pref[a - 1][b - 1] % MOD) %                        MOD;           if (2 * b - c - 1 > 0) {             a = 2 * b - c - 1;             next = nxt[a][b];             if (next < INF) {               if (next + a < b && next + b <= c &&                   digits[next + a] < digits[next + b]) {                 pref[b][c] += dp(a, b - 1);                 pref[b][c] %= MOD;               }             }           }         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans += dp(i, n);       ans %= MOD;     }     if (ans < 0) {       ans += MOD;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int inf = 0x3f3f3f3f, N = 1e7;   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   char s[10];   int d(char c) { return c -  0 ; }   int main() {     while (~scanf( %s , s)) {       long long x = d(s[0]) * 10000 + d(s[2]) * 1000 + d(s[4]) * 100 +                     d(s[3]) * 10 + d(s[1]);       long long ans = x;       for (int i = 1; i < 5; i++) ans = ans * x % 100000;       printf( %05d , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[100005];   int vis[100005];   vector<vector<int> > r;   bool dfs(int x, int f) {     vis[x] = 1;     int k = -1;     for (int y : g[x]) {       if (y == f) continue;       if (vis[y] > 0 || !vis[y] && !dfs(y, x)) {         if (k < 0)           k = y;         else           r.push_back({k, x, y}), k = -1;       }     }     vis[x] = -1;     if (k >= 0) {       r.push_back({k, x, f});       return true;     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int _ = 0, ThxDem = m; _ < ThxDem; ++_) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0, ThxDem = n; i < ThxDem; ++i)       if (!vis[i] && dfs(i, -1)) {         puts( No solution );         return 0;       }     for (auto v : r) printf( %d %d %d n , v[0] + 1, v[1] + 1, v[2] + 1);     return 0;   }