#include <bits/stdc++.h>   using namespace std;   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   T POW(T B, T printf) {     if (printf == 0) return 1;     if (printf & 1)       return B * POW(B, printf - 1);     else       return (POW(B, printf / 2) * POW(B, printf / 2));   }   template <typename T>   T Bigmod(T b, T p, T m) {     if (p == 0)       return 1;     else if (!(p & 1))       return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;     else       return ((b % m) * Bigmod(b, p - 1, m)) % m;   }   template <typename T>   T Dis(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   T Angle(T x1, T y1, T x2, T y2) {     return atan(double(y1 - y2) / double(x1 - x2));   }   template <typename T>   T DIFF(T a, T b) {     T d = a - b;     if (d < 0)       return -d;     else       return d;   }   template <typename T>   T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <typename T>   T euclide(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclide(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclide(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclide(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <typename T>   void ia(T a[], int n) {     for (int i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void pa(T a[], int n) {     for (int i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }   template <class T, class first>   inline T togglebit(T a, first i) {     T t = 1;     return (a ^ (t << i));   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int cdigittoint(char ch) { return ch -  0 ; }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }   double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }   struct Node {     int cnt;     Node *l, *r;     Node() {       cnt = 0;       l = r = NULL;     }   };   vector<int> adj[100007];   vector<int> ppl[100007];   Node Tree[18 * 100007];   int avail;   Node *Roots[100007];   int L[100007], T[100007];   int PP[100007][20];   Node *Update(Node *idx, int l, int r, int pos) {     Node *u = &Tree[++avail];     if (idx != NULL) *u = *idx;     if (l == r) {       u->cnt++;       return u;     }     u->cnt++;     if (pos <= ((l + r) >> 1))       u->l = Update(u->l, l, ((l + r) >> 1), pos);     else       u->r = Update(u->r, ((l + r) >> 1) + 1, r, pos);     return u;   }   int Query(Node *u, Node *v, Node *p, Node *fp, int l, int r, int k) {     if (l == r) return l;     int sum = ((u ? u->l : NULL) ? (u ? u->l : NULL)->cnt : 0) +               ((v ? v->l : NULL) ? (v ? v->l : NULL)->cnt : 0) -               ((p ? p->l : NULL) ? (p ? p->l : NULL)->cnt : 0) -               ((fp ? fp->l : NULL) ? (fp ? fp->l : NULL)->cnt : 0);     if (sum >= k) {       return Query((u ? u->l : NULL), (v ? v->l : NULL), (p ? p->l : NULL),                    (fp ? fp->l : NULL), l, ((l + r) >> 1), k);     } else {       return Query((u ? u->r : NULL), (v ? v->r : NULL), (p ? p->r : NULL),                    (fp ? fp->r : NULL), ((l + r) >> 1) + 1, r, k - sum);     }   }   void Bfs(int n, int m) {     queue<int> q;     q.push(1);     q.push(0);     q.push(0);     Roots[0] = NULL;     while (!q.empty()) {       int u = q.front();       q.pop();       int p = q.front();       q.pop();       int l = q.front();       q.pop();       L[u] = l;       T[u] = p;       Roots[u] = Roots[p];       for (int i = 0; i < (int)ppl[u].size(); i++) {         int x = ppl[u][i];         Roots[u] = Update(Roots[u], 1, m, x);       }       for (int i = 0; i < (int)adj[u].size(); i++) {         int v = adj[u][i];         if (v != p) {           q.push(v);           q.push(u);           q.push(l + 1);         }       }     }   }   void Sparse(int n) {     for (int i = 1; i <= n; i++) PP[i][0] = T[i];     for (int j = 1; (1 << j) < n; j++) {       for (int i = 1; i <= n; i++) {         if (PP[i][j - 1]) PP[i][j] = PP[PP[i][j - 1]][j - 1];       }     }   }   int LCA(int p, int q) {     if (L[p] < L[q]) swap(p, q);     int b;     for (b = 1; (1 << b) <= L[p]; b++)       ;     b--;     for (int i = b; i >= 0; i--) {       if (L[p] - (1 << i) >= L[q]) p = PP[p][i];     }     if (p == q) return p;     for (int i = b; i >= 0; i--) {       if (PP[p][i] && PP[p][i] != PP[q][i]) {         p = PP[p][i];         q = PP[q][i];       }     }     return T[p];   }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= m; i++) {       int(x);       scanf( %d , &x);       ppl[x].push_back(i);     }     Roots[0] = NULL;     Bfs(n, m);     Sparse(n);     while (q--) {       int u, v, a;       scanf( %d%d%d , &u, &v, &a);       int lca = LCA(u, v);       int cnt = (Roots[u] ? Roots[u]->cnt : 0) + (Roots[v] ? Roots[v]->cnt : 0) -                 (Roots[lca] ? Roots[lca]->cnt : 0) -                 (Roots[T[lca]] ? Roots[T[lca]]->cnt : 0);       int k = min(cnt, a);       vector<int> xx;       for (int i = 1; i <= k; i++) {         int x = Query(Roots[u], Roots[v], Roots[lca], Roots[T[lca]], 1, m, i);         xx.push_back(x);       }       printf( %d , (int)xx.size());       for (int i = 0; i < (int)xx.size(); i++) printf(  %d , xx[i]);       printf(  n );       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     if (a == b) {       cout << a <<   n ;     } else       cout <<  1 n ;     return 0;   }


#include <bits/stdc++.h>   struct DSU {     long long M[400005];     DSU(long long n) {       for (long long i = 0; i < n; i++) {         M[i] = i;       }     }     long long find(long long x) {       while (M[x] != x) {         long long p = M[x];         M[x] = M[p];         x = p;       }       return x;     }     bool join(long long x, long long y) {       long long xr = find(x);       long long yr = find(y);       if (xr == yr) {         return false;       } else {         M[xr] = yr;         return true;       }     }   };   using namespace std;   int main() {     long long n, m, q;     cin >> n >> m >> q;     DSU dsu(n + m);     long long z = n + m - 1;     for (long long i = 0; i < q; i++) {       long long r, c;       cin >> r >> c;       r--;       c--;       if (dsu.join(r, c + n)) z--;     }     cout << z;   }


#include <bits/stdc++.h>   const int N = 2e5;   using namespace std;   const int SIZE = 26;   int tot = 0, sub = 0;   struct node {     node* next[SIZE];     int strings;     int tin, tout;     node() {       for (int i = 0; i < SIZE; i++) {         next[i] = nullptr;       }       tin = 0;       tout = 0;       strings = 0;     }   };   void add(struct node* root, string key) {     struct node* cur_v = root;     for (size_t i = 0; i < key.length(); i++) {       char c = key[i];       if (cur_v->next[c -  a ] == nullptr) {         cur_v->next[c -  a ] = new node();       }       cur_v = cur_v->next[c -  a ];     }     cur_v->strings++;   }   int t[4 * N + 1], mx_id[4 * N + 1];   void pull(int v) {     if (t[2 * v] > t[2 * v + 1]) {       t[v] = t[2 * v];       mx_id[v] = mx_id[2 * v];     } else {       t[v] = t[2 * v + 1];       mx_id[v] = mx_id[2 * v + 1];     }   }   void upd(int v, int tl, int tr, int id, int x) {     if (tl == tr) {       t[v] = x;       mx_id[v] = id;       return;     }     int tm = (tl + tr) >> 1;     if (id <= tm) {       upd(2 * v, tl, tm, id, x);     } else {       upd(2 * v + 1, tm + 1, tr, id, x);     }     pull(v);   }   int pos = -1;   int mx = 0;   void calc(int v, int tl, int tr, int L, int R) {     if (tl == L && tr == R) {       if (mx < t[v]) {         mx = t[v];         pos = mx_id[v];       }       return;     }     int tm = (tl + tr) >> 1;     if (R <= tm) {       calc(2 * v, tl, tm, L, R);     } else if (L > tm) {       calc(2 * v + 1, tm + 1, tr, L, R);     } else {       calc(2 * v, tl, tm, L, tm);       calc(2 * v + 1, tm + 1, tr, tm + 1, R);     }   }   int t1, t2;   void dfs(struct node* v, int d = 0) {     t1++;     v->tin = t1;     if (v->strings > 0) {       upd(1, 1, N, t1, d);     }     for (int i = 0; i < SIZE; i++) {       if (v->next[i] == nullptr) {         continue;       }       dfs(v->next[i], d + 1);     }     if (d < 1) {       return;     }     v->tout = t1;     if (v->strings == 0) {       mx = 0;       pos = 0;       calc(1, 1, N, v->tin, v->tout);       upd(1, 1, N, pos, 0);       upd(1, 1, N, v->tin, d);       sub += mx - d;     }   }   char buf[N];   int main() {     int n;     scanf( %d , &n);     string s;     node* t = new node();     for (int i = 1; i <= n; i++) {       scanf( %s , buf);       s = buf;       int sz = s.size();       tot += sz;       add(t, s);     }     dfs(t);     printf( %d n , tot - sub);   }


#include <bits/stdc++.h>   using namespace std;   inline void setmin(int &x, int y) {     if (y < x) x = y;   }   inline void setmax(int &x, int y) {     if (y > x) x = y;   }   inline void setmin(long long &x, long long y) {     if (y < x) x = y;   }   inline void setmax(long long &x, long long y) {     if (y > x) x = y;   }   const int N = 100000;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 239;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   const int ABC = 26;   vector<int> pos[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     cout << fixed;     int n, m, s, e;     cin >> n >> m >> s >> e;     int a[n], b[m];     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     for (int i = 0; i < m; i++) {       cin >> b[i];       b[i]--;       pos[b[i]].push_back(i);     }     int cnt = s / e;     int dp[n][cnt + 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < cnt + 1; j++) dp[i][j] = inf;     for (int i = 0; i < n; i++) {       int p = 0;       dp[i][0] = -1;       for (int j = 1; j < min(i + 1, cnt) + 1; j++) {         if (i > 0) setmin(dp[i][j], dp[i - 1][j]);         int last_pos = (i == 0 ? -1 : dp[i - 1][j - 1]);         while (p < (int)pos[a[i]].size() && pos[a[i]][p] <= last_pos) p++;         if (p < (int)pos[a[i]].size()) setmin(dp[i][j], pos[a[i]][p]);       }     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < cnt + 1; j++)         if ((i + 1) + (dp[i][j] + 1) + j * e <= s) setmax(ans, j);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modPow(long long a, long long b, long long m) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long x = a * a;       x %= m;       return modPow(x, b / 2, m);     }     return (a * modPow(a, b - 1, m)) % m;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, i, j;       cin >> n;       string s =   ;       for (i = 0; i < (53); i++) s +=  a ;       cout << s;       cout <<   n ;       for (i = 0; i < (n); i++) {         long long a;         cin >> a;         if (s[a] ==  a ) {           for (auto j = (a); j <= (52); j++) {             s[j] =  b ;           }         } else {           for (auto j = (a); j <= (52); j++) {             s[j] =  a ;           }         }         cout << s;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long g, t;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int n;     long long Max = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (i)         g = gcd(g, t);       else         g = t;       Max = max(Max, t);     }     long long cnt = Max / g - n;     if (cnt % 2 == 0)       printf( Bob n );     else       printf( Alice n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, T, a[200010], x, y, d[200010], q[200010], l, r;   vector<int> v[200010], Q;   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++)         scanf( %d , &a[i]), a[i] = 2 - a[i], v[i].clear();       for (int i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         v[x].push_back(y), v[y].push_back(x);       }       if (n == 1) {         puts( 1 );         continue;       }       int Ans = n;       for (int col = 0; col < 2; col++) {         int ans = 0;         for (int i = 1; i <= n; i++) d[i] = v[i].size();         l = 1, r = 0, Q.clear();         for (int i = 1; i <= n; i++)           if (d[i] == 1) {             if (a[i] != col)               q[++r] = i;             else               Q.push_back(i);           }         while (1) {           while (l <= r) {             x = q[l++];             for (int j = 0, sz = v[x].size(); j < sz; j++)               if ((--d[v[x][j]]) == 1) {                 if (a[v[x][j]] == (col ^ (ans & 1)))                   Q.push_back(v[x][j]);                 else                   q[++r] = v[x][j];               }           }           ans++;           if (r == n) {             Ans = min(Ans, ans);             break;           }           for (int j = 0, sz = Q.size(); j < sz; j++) q[++r] = Q[j];           Q.clear();         }       }       printf( %d n , Ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     int t, n;     string s, p;     cin >> t;     while (t--) {       cin >> n;       cin >> s;       for (int j = 0; j < (2 * n - 1); j += 2) {         cout << s[j];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   void solve() {     int n;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a[x] = i;     }     int l = 0, r = n - 1;     for (int i = n; i > 0; i--) {       if (a[i] == l) {         l++;         continue;       }       if (a[i] == r) {         r--;         continue;       }       cout <<  YES  << endl            << a[i] - 1 + 1 <<     << a[i] + 1 <<     << a[i] + 1 + 1 << endl;       return;     }     cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 2e5 + 10;   int n;   int a[MAXN], b[MAXN];   namespace bit {   int a[MAXN];   void init() { std::fill(a + 1, a + n + 1, 0); }   void add(int x, int y) {     for (; x <= n; x += x & (-x)) {       a[x] += y;     }   }   int query(int x) {     int ans = 0;     for (; x > 0; x -= x & (-x)) {       ans += a[x];     }     return ans;   }   }  // namespace bit   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       a[i]++;     }     for (int i = 1; i <= n; i++) {       scanf( %d , b + i);       b[i]++;     }     static int p[MAXN], q[MAXN];     for (int i = 1; i <= n; i++) {       p[i] = a[i] - bit::query(a[i]) - 1;       bit::add(a[i], 1);     }     bit::init();     for (int i = 1; i <= n; i++) {       q[i] = b[i] - bit::query(b[i]) - 1;       bit::add(b[i], 1);     }     static int sum[MAXN];     for (int i = n; i >= 1; i--) {       sum[i] += p[i] + q[i];       int k = n - i + 1;       sum[i - 1] = sum[i] / k;       sum[i] %= k;     }     bit::init();     for (int i = 1; i <= n; i++) {       int l = 1, r = n, ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (mid - bit::query(mid) - 1 >= sum[i]) {           ans = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       bit::add(ans, 1);       printf( %d  , ans - 1);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = int(1e4) + 4;   int a[MAXN], h[MAXN], c[MAXN];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       h[i] = a[i];       int j = i - 1;       while (h[j] > h[i] && j > 0) {         h[i] += a[j];         c[i]++;         j--;       }       c[i] += c[j];     }     cout << c[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   const int N = 2e5 + 3;   const int MOD = 998244353;   int max1 = 0, max2 = 0;   void solve() {     long long int a[3];     cin >> a[0] >> a[1] >> a[2];     sort(a, a + 3);     cout << (a[0] + a[1] + min(a[2], 2 * (a[1] + a[0]))) / 3 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> cc[100000];   int num[100000];   int main() {     int n, k, m;     cin >> n >> k >> m;     for (int j = 0; j < n; cin >> num[j++])       ;     sort(num, num + n);     for (int j = 0; j < m; cc[j++].clear())       ;     cc[0].push_back(0);     for (int j = 1; j < n; j++) cc[(num[j] - num[0]) % m].push_back(j);     for (int j = 0; j < m; j++) {       if (cc[j].size() >= k) {         cout <<  Yes  << endl;         for (int i = 0; i < k; i++) {           cout << num[cc[j][i]] <<    ;         }         return 0;       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 31;   const int mod = 1000000007;   struct ma {     long long a[maxn][maxn];     int n;     ma(int m = 0) {       n = m;       memset(a, 0, sizeof(a));       for (int i = 0; i < n; i++) a[i][i] = 1;     }     ma(const ma& nn) {       n = nn.n;       memcpy(a, nn.a, sizeof(a));     }     ma operator*(const ma& nn) {       ma ret(n);       memset(ret.a, 0, sizeof(ret.a));       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) ret.a[i][j] += a[i][k] * nn.a[k][j] % mod;           ret.a[i][j] %= mod;         }       return ret;     }   };   ma mypow(ma a, long long n) {     ma ret(a.n);     while (n) {       if (n & 1) ret = ret * a;       n >>= 1;       a = a * a;     }     return ret;   }   ma m1[100], m2[100];   int main() {     long long n;     int k, i, j;     cin >> n >> k;     n--;     m1[1].n = k + 1;     for (i = 0; i <= k; i++) m1[1].a[i][i] = 1;     for (i = 1; i < 99; i++) {       int tmp = ((-i - 1) % k + k) % k + 1;       tmp = k - tmp;       memcpy(m2[i].a[0], m1[i].a[k], sizeof(m1[i].a[k]));       for (j = 1; j <= k; j++) {         for (int c = 0; c <= k; c++)           m2[i].a[j][c] =               ((m2[i].a[j - 1][c] * 2 - m1[i].a[tmp][c]) % mod + mod) % mod;         tmp++;         if (tmp >= k) tmp = 0;       }       m2[i].n = k + 1;       m1[i + 1] = m1[i] * mypow(m2[i], k - 1);     }     ma ans(k + 1);     int ind = 1, sheng = n % k;     n /= k;     while (n) {       ans = ans * mypow(m2[ind], n % k);       ind++, n /= k;     }     long long ret = 0;     for (i = 0; i <= k; i++) ret = (ret + ans.a[sheng + 1][i] * (1ll << i)) % mod;     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9;   const long long inf = (long long)3e18;   const int base = 1000 * 1000 * 1000;   const int maxn = 20;   const long double pi = acosl(-1.0);   const long double eps = 1e-5;   void error() { exit(1); }   int n;   bool flag = true;   long long A, cf, cm, m;   vector<long long> d;   long long ans = 0, minans;   long long predmin, curmin, people;   unordered_map<long long, long long> st;   set<long long> val;   set<pair<long long, int> > powerans;   set<pair<long long, int> > power, nopower;   void solve() {     scanf( %d %I64d %I64d %I64d %I64d , &n, &A, &cf, &cm, &m);     d.resize(n);     for (int i = 0; i < n; i++) {       scanf( %I64d , &d[i]);       nopower.insert(make_pair((-1) * d[i], i));       st[d[i]]++;       val.insert(d[i]);     }     val.insert(A);     val.insert(A + 1);     while ((int)nopower.size() && (A + (*nopower.begin()).first) <= m) {       pair<long long, int> v = (*nopower.begin());       nopower.erase(nopower.begin());       st[(-1) * v.first]--;       st[A]++;       m -= (A + v.first);       power.insert(make_pair((-1) * v.first, v.second));       ans += cf;     }     predmin = (*val.begin());     val.erase(val.begin());     curmin = (*val.begin());     val.erase(*val.begin());     people = st[predmin];     ans += predmin * cm;     minans = predmin;     powerans = power;     while ((int)power.size() || flag) {       if (predmin == A || (int)power.size() == n) {         ans = A * cm + n * cf;         break;       }       if ((int)power.size() && (m <= 0 || !flag)) {         pair<long long, int> v = (*power.begin());         power.erase(power.begin());         if (predmin >= v.first)           m += (A - predmin);         else           m += (A - v.first);         if (v.first <= predmin)           people++;         else           st[v.first]++;       }       flag = false;       long long del = m / people;       if (m > 0 && del > 0) {         flag = true;         if (curmin <= predmin + del) {           m -= (curmin - predmin) * people;           people += st[curmin];           predmin = curmin;           curmin = (*val.begin());           val.erase(*val.begin());         } else {           predmin += del;           m -= del * people;         }         long long curans = predmin * cm + (int)power.size() * cf;         if (predmin == A) curans += (people - (int)power.size()) * cf;         if (ans < curans) {           ans = curans;           minans = predmin;           while ((int)powerans.size() != (int)power.size()) {             powerans.erase(*powerans.begin());           }         }       }     }     printf( %I64d n , ans);     while ((int)powerans.size()) {       pair<long long, int> v = (*powerans.begin());       powerans.erase(powerans.begin());       d[v.second] = A;     }     for (int i = 0; i < n; i++)       if (d[i] < minans) d[i] = minans;     for (int i = 0; i < n; i++) printf( %I64d  , d[i]);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1000001;   int n, m, a[MAXN], b[MAXN];   int box[MAXN], axi[MAXN];   int n1, n2;   int main() {     std::cin >> n >> m;     for (int i = 1; i <= n; i++) {       std::scanf( %d , a + i);       if (a[i] <= m) {         b[++n1] = a[i];         box[a[i]]++;       }     }     if (!n1) {       std::puts( 1 0 );       return 0;     }     std::sort(b + 1, b + 1 + n1);     int n2 = std::unique(b + 1, b + 1 + n1) - b - 1;     for (int i = 1; i <= n2; i++)       for (int j = 1; j <= m / b[i]; j++) axi[b[i] * j] += box[b[i]];     int sum = 0, lcm;     for (int i = 1; i <= m; i++) {       if (axi[i] > sum) sum = axi[i], lcm = i;     }     std::printf( %d %d n , lcm, sum);     for (int i = 1; i <= n; i++)       if (!(lcm % a[i])) std::printf( %d  , i);     std::putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int mod = 1e9 + 7;   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   int n, trie[maxn][26], en[maxn], nxt;   string s;   void ins(int cur, int i) {     if (i == (int)s.size())       en[cur] = 1;     else {       int le = (s[i] -  a );       if (!trie[cur][le]) trie[cur][le] = ++nxt;       ins(trie[cur][le], i + 1);     }   }   multiset<int> merge(multiset<int> a, multiset<int> b) {     if ((int)a.size() < (int)b.size()) swap(a, b);     for (auto aa : b) a.insert(aa);     return a;   }   multiset<int> dfs(int cur, int dep) {     multiset<int> ret;     for (int i = 0; i < 26; i++)       if (trie[cur][i]) ret = merge(ret, dfs(trie[cur][i], dep + 1));     if (en[cur])       ret.insert(dep);     else if (cur != 0) {       int a = *prev(ret.end());       ret.erase(prev(ret.end()));       ret.insert(dep);     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       ins(0, 0);     }     multiset<int> res = dfs(0, 0);     long long ans = 0;     for (auto a : res) ans += a;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 10;   long long arr[MAX], arr2[MAX];   int n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> arr[i];     for (int i = 0; i < n; ++i) cin >> arr2[i];     vector<pair<long long, long long> > vp;     for (int i = 0; i < n; ++i) vp.push_back({arr[i], arr2[i]});     sort(vp.begin(), vp.end());     for (int i = 0; i < n; ++i) arr[i] = vp[i].first, arr2[i] = vp[i].second;     int idx = 0;     int cur = arr[0];     long long ans = 0, sum = 0;     priority_queue<long long> q;     while (1) {       ans += sum;       while (idx < n && cur == arr[idx]) {         sum += arr2[idx];         q.push(arr2[idx]);         idx++;       }       if (q.size() == 0) {         if (idx == n) break;         cur = arr[idx];       } else {         long long x = q.top();         q.pop();         sum -= x;         cur++;       }     }     return cout << ans <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   using ld = long double;   ld sq(ld x) { return x * x; }   int main() {     size_t n;     cin >> n;     vector<ld> mn(n), mx(n), mnk(n), mxk(n);     for (size_t i = 0; i != n; ++i) {       cin >> mx[i];     }     for (size_t i = 0; i != n; ++i) {       cin >> mn[i];     }     mnk[0] = mn[0];     mxk[0] = mx[0];     for (size_t i = 1; i != n; ++i) {       mnk[i] = mnk[i - 1] + mn[i];       mxk[i] = mxk[i - 1] + mx[i];     }     vector<ld> a(n), b(n), ak(n), bk(n);     ak[n - 1] = 1;     bk[n - 1] = 1;     for (size_t i = 0; i < n - 1; ++i) {       ld u = mxk[i];       ld v = mnk[i];       ld D = sqrt(sq(u + v) - 4 * u);       ld x1 = (u + v + D) / 2;       ld x2 = (u + v - D) / 2;       ak[i] = x1;       bk[i] = x2;     }     a[0] = ak[0];     b[0] = bk[0];     for (size_t i = 1; i != n; ++i) {       a[i] = ak[i] - ak[i - 1];       b[i] = bk[i] - bk[i - 1];     }     for (size_t i = 0; i != n; ++i) cout << a[i] <<    ;     cout << endl;     for (size_t i = 0; i != n; ++i) cout << b[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <int M>   struct static_mint {     static_assert(0 < M,  Module must be positive );     int val;     static_mint() : val() {}     static_mint(long long x) : val(x % M) {       if (val < 0) val += M;     }     static_mint pow(long long n) const {       static_mint ans = 1, x(*this);       while (n) {         if (n & 1) ans *= x;         x *= x;         n /= 2;       }       return ans;     }     static_mint inv() const { return pow(M - 2); }     friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }     friend static_mint inv(const static_mint &m) { return m.inv(); }     static_mint operator+() const {       static_mint m;       m.val = val;       return m;     }     static_mint operator-() const {       static_mint m;       m.val = M - val;       return m;     }     static_mint &operator+=(const static_mint &m) {       if ((val += m.val) >= M) val -= M;       return *this;     }     static_mint &operator-=(const static_mint &m) {       if ((val -= m.val) < 0) val += M;       return *this;     }     static_mint &operator*=(const static_mint &m) {       val = (long long)val * m.val % M;       return *this;     }     static_mint &operator/=(const static_mint &m) {       val = (long long)val * m.inv().val % M;       return *this;     }     friend static_mint operator+(const static_mint &lhs, const static_mint &rhs) {       return static_mint(lhs) += rhs;     }     friend static_mint operator-(const static_mint &lhs, const static_mint &rhs) {       return static_mint(lhs) -= rhs;     }     friend static_mint operator*(const static_mint &lhs, const static_mint &rhs) {       return static_mint(lhs) *= rhs;     }     friend static_mint operator/(const static_mint &lhs, const static_mint &rhs) {       return static_mint(lhs) /= rhs;     }     friend bool operator==(const static_mint &lhs, const static_mint &rhs) {       return lhs.val == rhs.val;     }     friend bool operator!=(const static_mint &lhs, const static_mint &rhs) {       return lhs.val != rhs.val;     }     static_mint &operator++() { return *this += 1; }     static_mint &operator--() { return *this -= 1; }     static_mint operator++(int) {       static_mint result(*this);       *this += 1;       return result;     }     static_mint operator--(int) {       static_mint result(*this);       *this -= 1;       return result;     }     template <typename T>     explicit operator T() const {       return T(val);     }     friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {       return os << m.val;     }     friend std::istream &operator>>(std::istream &is, static_mint &m) {       long long x;       is >> x;       m = x;       return is;     }   };   template <typename>   struct is_mint : public std::false_type {};   template <int M>   struct is_mint<static_mint<M>> : public std::true_type {};   template <typename T>   struct matrix : std::vector<std::vector<T>> {     int n, m;     matrix() : n(), m() {}     matrix(int n, int m, const T val = T())         : n(n), m(m), std::vector<std::vector<T>>(n, std::vector<T>(m, val)) {}     matrix(std::initializer_list<std::vector<T>> l)         : std::vector<std::vector<T>>(l) {       n = l.size();       if (l.size()) {         m = l.begin()->size();       }     }     matrix &operator+=(const matrix &mat) {       assert(n == mat.n && m == mat.m);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           (*this)[i][j] += mat[i][j];         }       }       return *this;     }     matrix &operator-=(const matrix &mat) {       assert(n == mat.n && m == mat.m);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           (*this)[i][j] -= mat[i][j];         }       }       return *this;     }     matrix &operator*=(const matrix &mat) {       assert(m == mat.n);       matrix res(n, mat.m);       for (int i = 0; i < n; i++) {         for (int j = 0; j < mat.m; j++) {           for (int k = 0; k < m; k++) {             res[i][j] += (*this)[i][k] * mat[k][j];           }         }       }       this->swap(res);       return *this;     }     matrix &operator*=(const T &val) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           (*this)[i][j] *= val;         }       }       return *this;     }     friend matrix operator+(matrix a, const matrix &b) {       a += b;       return a;     }     friend matrix operator-(matrix a, const matrix &b) {       a -= b;       return a;     }     friend matrix operator*(matrix a, const matrix &b) {       a *= b;       return a;     }     friend matrix operator*(matrix a, const T &val) {       a *= val;       return a;     }     friend matrix operator*(const T &val, matrix a) {       a *= val;       return a;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     using mint = static_mint<1000000007>;     int n, x;     cin >> n >> x;     vector<int> cnt(101);     for (int i = 0, d; i < n; i++) {       cin >> d, cnt[d] += 1;     }     matrix<mint> m(101, 101);     m[0][0] = 1 + cnt[1];     for (int i = 1; i < 100; i++) {       m[i][0] = cnt[i + 1] - cnt[i];     }     m[100][0] = -cnt[100];     for (int j = 1; j < 101; j++) {       m[j - 1][j] = 1;     }     matrix<mint> ans(101, 101);     for (int i = 0; i < 101; i++) ans[0][0] = 1;     for (; x; x /= 2) {       if (x & 1) ans *= m;       m *= m;     }     cout << ans[0][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   T inverse(T a, T m) {     T u = 0, v = 1;     while (a != 0) {       T t = m / a;       m -= t * a;       swap(a, m);       u -= t * v;       swap(u, v);     }     assert(m == 1);     return u;   }   template <typename T>   class Modular {    public:     using Type = typename decay<decltype(T::value)>::type;     constexpr Modular() : value() {}     template <typename U>     Modular(const U& x) {       value = normalize(x);     }     template <typename U>     static Type normalize(const U& x) {       Type v;       if (-mod() <= x && x < mod())         v = static_cast<Type>(x);       else         v = static_cast<Type>(x % mod());       if (v < 0) v += mod();       return v;     }     const Type& operator()() const { return value; }     template <typename U>     explicit operator U() const {       return static_cast<U>(value);     }     constexpr static Type mod() { return T::value; }     Modular& operator+=(const Modular& other) {       if ((value += other.value) >= mod()) value -= mod();       return *this;     }     Modular& operator-=(const Modular& other) {       if ((value -= other.value) < 0) value += mod();       return *this;     }     template <typename U>     Modular& operator+=(const U& other) {       return *this += Modular(other);     }     template <typename U>     Modular& operator-=(const U& other) {       return *this -= Modular(other);     }     Modular& operator++() { return *this += 1; }     Modular& operator--() { return *this -= 1; }     Modular operator++(int) {       Modular result(*this);       *this += 1;       return result;     }     Modular operator--(int) {       Modular result(*this);       *this -= 1;       return result;     }     Modular operator-() const { return Modular(-value); }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(static_cast<int64_t>(value) *                         static_cast<int64_t>(rhs.value));       return *this;     }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       int64_t q = static_cast<int64_t>(static_cast<long double>(value) *                                        rhs.value / mod());       value = normalize(value * rhs.value - q * mod());       return *this;     }     template <typename U = T>     typename enable_if<!is_integral<typename Modular<U>::Type>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(value * rhs.value);       return *this;     }     Modular& operator/=(const Modular& other) {       return *this *= Modular(inverse(other.value, mod()));     }     template <typename U>     friend const Modular<U>& abs(const Modular<U>& v) {       return v;     }     template <typename U>     friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend std::istream& operator>>(std::istream& stream, Modular<U>& number);       private:     Type value;   };   template <typename T>   bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value == rhs.value;   }   template <typename T, typename U>   bool operator==(const Modular<T>& lhs, U rhs) {     return lhs == Modular<T>(rhs);   }   template <typename T, typename U>   bool operator==(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) == rhs;   }   template <typename T>   bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(const Modular<T>& lhs, U rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(U lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T>   bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value < rhs.value;   }   template <typename T>   Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T>   Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T>   Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T>   Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> power(const Modular<T>& a, const U& b) {     assert(b >= 0);     Modular<T> x = a, res = 1;     U p = b;     while (p > 0) {       if (p & 1) res *= x;       x *= x;       p >>= 1;     }     return res;   }   template <typename T>   bool IsZero(const Modular<T>& number) {     return number() == 0;   }   template <typename T>   string to_string(const Modular<T>& number) {     return to_string(number());   }   template <typename T>   std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {     return stream << number();   }   template <typename T>   std::istream& operator>>(std::istream& stream, Modular<T>& number) {     typename common_type<typename Modular<T>::Type, int64_t>::type x;     stream >> x;     number.value = Modular<T>::normalize(x);     return stream;   }   constexpr int md = (int)1e9 + 7;   using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;   template <typename T>   class graph {    public:     struct edge {       int from;       int to;       T cost;     };     vector<edge> edges;     vector<vector<int>> g;     int n;     graph(int _n) : n(_n) { g.resize(n); }     virtual int add(int from, int to, T cost) = 0;   };   template <typename T>   class forest : public graph<T> {    public:     using graph<T>::edges;     using graph<T>::g;     using graph<T>::n;     forest(int _n) : graph<T>(_n) {}     int add(int from, int to, T cost = 1) {       assert(0 <= from && from < n && 0 <= to && to < n);       int id = (int)edges.size();       assert(id < n - 1);       g[from].push_back(id);       g[to].push_back(id);       edges.push_back({from, to, cost});       return id;     }   };   template <typename T>   class dfs_forest : public forest<T> {    public:     using forest<T>::edges;     using forest<T>::g;     using forest<T>::n;     vector<int> pv;     vector<int> pe;     vector<int> order;     vector<int> pos;     vector<int> end;     vector<int> sz;     vector<int> root;     vector<int> depth;     vector<T> dist;     dfs_forest(int _n) : forest<T>(_n) {}     void init() {       pv = vector<int>(n, -1);       pe = vector<int>(n, -1);       order.clear();       pos = vector<int>(n, -1);       end = vector<int>(n, -1);       sz = vector<int>(n, 0);       root = vector<int>(n, -1);       depth = vector<int>(n, -1);       dist = vector<T>(n);     }     void clear() {       pv.clear();       pe.clear();       order.clear();       pos.clear();       end.clear();       sz.clear();       root.clear();       depth.clear();       dist.clear();     }       private:     void do_dfs(int v) {       pos[v] = (int)order.size();       order.push_back(v);       sz[v] = 1;       for (int id : g[v]) {         if (id == pe[v]) {           continue;         }         auto& e = edges[id];         int to = e.from ^ e.to ^ v;         depth[to] = depth[v] + 1;         dist[to] = dist[v] + e.cost;         pv[to] = v;         pe[to] = id;         root[to] = (root[v] != -1 ? root[v] : to);         do_dfs(to);         sz[v] += sz[to];       }       end[v] = (int)order.size() - 1;     }     void do_dfs_from(int v) {       depth[v] = 0;       dist[v] = T{};       root[v] = v;       pv[v] = pe[v] = -1;       do_dfs(v);     }       public:     void dfs(int v, bool clear_order = true) {       if (pv.empty()) {         init();       } else {         if (clear_order) {           order.clear();         }       }       do_dfs_from(v);     }     void dfs_all() {       init();       for (int v = 0; v < n; v++) {         if (depth[v] == -1) {           do_dfs_from(v);         }       }       assert((int)order.size() == n);     }   };   template <typename T>   class lca_forest : public dfs_forest<T> {    public:     using dfs_forest<T>::edges;     using dfs_forest<T>::g;     using dfs_forest<T>::n;     using dfs_forest<T>::pv;     using dfs_forest<T>::pos;     using dfs_forest<T>::end;     using dfs_forest<T>::depth;     int h;     vector<vector<int>> pr;     lca_forest(int _n) : dfs_forest<T>(_n) {}     inline void build_lca() {       assert(!pv.empty());       int max_depth = 0;       for (int i = 0; i < n; i++) {         max_depth = max(max_depth, depth[i]);       }       h = 1;       while ((1 << h) <= max_depth) {         h++;       }       pr.resize(n);       for (int i = 0; i < n; i++) {         pr[i].resize(h);         pr[i][0] = pv[i];       }       for (int j = 1; j < h; j++) {         for (int i = 0; i < n; i++) {           pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]);         }       }     }     inline bool anc(int x, int y) {       return (pos[x] <= pos[y] && end[y] <= end[x]);     }     inline int go_up(int x, int up) {       assert(!pr.empty());       up = min(up, (1 << h) - 1);       for (int j = h - 1; j >= 0; j--) {         if (up & (1 << j)) {           x = pr[x][j];           if (x == -1) {             break;           }         }       }       return x;     }     inline int lca(int x, int y) {       assert(!pr.empty());       if (anc(x, y)) {         return x;       }       if (anc(y, x)) {         return y;       }       for (int j = h - 1; j >= 0; j--) {         if (pr[x][j] != -1 && !anc(pr[x][j], y)) {           x = pr[x][j];         }       }       return pr[x][0];     }   };   template <typename T>   class fenwick {    public:     vector<T> fenw;     int n;     fenwick(int _n) : n(_n) { fenw.resize(n); }     void modify(int x, T v) {       while (x < n) {         fenw[x] += v;         x |= (x + 1);       }     }     T get(int x) {       T v{};       while (x >= 0) {         v += fenw[x];         x = (x & (x + 1)) - 1;       }       return v;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     dfs_forest<int> g(n);     vector<int> deg(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       g.add(x, y);       ++deg[x];       ++deg[y];     }     42;     g.dfs(0);     vector<vector<int>> children(n);     for (int i = 1; i < n; i++) {       children[g.pv[i]].push_back(i);     }     42;     vector<int> num(n, -1);     vector<int> low(n, -1);     for (int i : g.order) {       int sz = (int)children[i].size();       int from = (i == 0 ? -1 : max(0, num[i] - sz));       low[i] = from;       int x = from;       for (int j : children[i]) {         if (x == num[i]) {           ++x;         }         num[j] = x++;       }     }     42;     vector<vector<int>> go(n);     for (int i = 0; i < n; i++) {       go[i].resize(deg[i]);     }     42;     go[0].resize(deg[0] + 1);     42;     for (int i = 1; i < n; i++) {       int j = g.pv[i];       int t = num[i];       go[i][t - low[i]] = j;       go[j][t - low[j]] = i;     }     42;     vector<pair<int, int>> res;     res.emplace_back(0, 0);     42;     while (res.back().second >= 0) {       int i = res.back().first;       int t = res.back().second;       int pos = t - low[i];       if (pos >= (int)go[i].size()) {         res.emplace_back(i, low[i]);         continue;       }       res.emplace_back(go[i][pos], t + 1);     }     42;     res.pop_back();     42;     cout << res.size() <<   n ;     for (auto& p : res) {       cout << p.first + 1 <<     << p.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long binary_exp(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = (ans * a);       }       a = (a * a);       b = b >> 1;     }     return ans;   }   int fn(int low, vector<int> &a, int p) {     int k = low;     for (int i = 0; i < a.size(); i++) {       k = low + i;       int j = upper_bound(a.begin(), a.end(), k) - a.begin();       if ((j - i) % p == 0) {         return 0;       }     }     return 1;   }   map<long long, long long> mp;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long T;     T = 1;     while (T--) {       int n, p;       cin >> n >> p;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.begin(), a.end());       int low = max(a[0], a[n - 1] - n + 1);       for (int i = 0; i < n; i++) {         low = max(low, a[i] - i);       }       int high = a[n - 1];       if (!fn(low, a, p)) {         cout << 0 << endl;         cout << endl;         continue;       }       int z = low;       while (low < high) {         int mid = (low + high) / 2;         mid++;         if (fn(mid, a, p)) {           low = mid;         } else {           high = mid - 1;         }       }       cout << low - z + 1 << endl;       for (int i = z; i <= low; i++) {         cout << i <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long M = 1e9 + 9;   long long axm(long long a, long long x, long long m) {     a %= m;     long long r = 1;     while (x > 0) {       if (x & 1) r = r * a % m;       a = a * a % m;       x /= 2;     }     return r;   }   long long inv(long long a, long long m) { return axm(a, m - 2, m); }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   struct P {     long long x, y;   };   long long dist(P a, P b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   long long test(P p1, P p2, P p3, P p4) {     long long d2 = dist(p1, p2);     long long d3 = dist(p1, p3);     long long d4 = dist(p1, p4);     if (d2 == 0 || d3 == 0 || d4 == 0) return 0;     if (d2 == d3 && 2 * d2 == d4 && 2 * dist(p2, p4) == dist(p2, p3)) {       return 1;     }     if (d3 == d4 && 2 * d3 == d2 && 2 * dist(p3, p2) == dist(p3, p4)) {       return 1;     }     if (d2 == d4 && 2 * d2 == d3 && 2 * dist(p2, p3) == dist(p2, p4)) {       return 1;     }     return 0;   }   P p[4][4];   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long n;     cin >> n;     for (long long tt = 0; tt < n; tt++) {       for (long long i = 0; i < 4; i++) {         long long xx, yy, aa, bb;         cin >> xx >> yy >> aa >> bb;         p[i][0].x = xx;         p[i][0].y = yy;         for (long long j = 1; j < 4; j++) {           p[i][j].x = aa - (p[i][j - 1].y - bb);           p[i][j].y = bb + (p[i][j - 1].x - aa);         }       }       long long ans = inf;       for (long long i = 0; i < 4; i++) {         for (long long j = 0; j < 4; j++) {           for (long long k = 0; k < 4; k++) {             for (long long l = 0; l < 4; l++) {               long long s = i + j + k + l;               if (s < ans && test(p[0][i], p[1][j], p[2][k], p[3][l])) {                 ans = s;               }             }           }         }       }       if (ans == inf) ans = -1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = (int)1e9;   const long long int infll = (long long int)1e18;   const double inf1 = 1e-9;   const int ss = (int)1e6 + 3;   const int base = inf;   bool pred(const pair<int, int>& i, const pair<int, int>& j) {     if (i.first == j.first)       return i.second > j.second;     else       return i.first > j.first;   }   bool pred2(const int& i, const int& j) { return i > j; }   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     int k = 100001;     vector<vector<int> > b(k);     int mx = -1;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       b[a[i]].push_back(i);       mx = max(a[i], mx);     }     if (mx == 1) {       cout << b[1].size() << endl;       for (int i = 0; i < n; ++i) cout << i + 1 <<    ;       return 0;     }     bool t = true;     for (int j = 2; j <= mx; ++j) {       if (b[j].size() > b[j - 1].size()) {         t = false;         break;       }     }     if (!t) {       cout <<  -1 ;       return 0;     }     cout << b[1].size() << endl;     vector<int> c(n);     for (int i = 1; i <= mx; ++i) {       for (int j = 0; j < b[i].size(); ++j) c[b[i][j]] = j + 1;     }     for (int i = 0; i < n; ++i) cout << c[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a, b;     scanf( %d %d %d %d , &x, &y, &a, &b);     int minV = max(a, b + 1);     int maxP = min(y, x - 1);     vector<pair<int, int> > output;     int total = 0;     for (int v = minV; v <= x; v++) {       for (int p = b; p <= min(v - 1, maxP); p++) {         output.push_back(pair<int, int>(v, p));         ++total;       }     }     printf( %d n , total);     for (int k = 0; k < output.size(); k++) {       printf( %d %d n , output[k].first, output[k].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[1 << 20];   long long B[1 << 20];   long long getIP() {     int a[4];     scanf( %d.%d.%d.%d , &a[0], &a[1], &a[2], &a[3]);     int i;     long long res = 0;     for (i = (0); i < (4); ++i) res = (res << 8) | a[i];     return res;   }   void printIP(long long res) {     int a[4];     int i;     for (i = (0); i < (4); ++i) {       a[i] = int(res & 255);       res >>= 8;     }     printf( %d.%d.%d.%d n , a[3], a[2], a[1], a[0]);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     int i, j;     for (i = (0); i < (n); ++i) A[i] = getIP();     long long mask = 0;     for (i = (32) - 1; i >= (1); --i) {       if (i != 32) mask |= 1LL << i;       for (j = (0); j < (n); ++j) B[j] = A[j] & mask;       sort(B, B + n);       if (k == unique(B, B + n) - B) {         printIP(mask);         return 0;       }     }     printf( -1 n );     return 0;   };


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   const long double EPS = 1e-12;   int d, s;   bool vis[5105][515];   int pa[5105][515];   int parem[5105][515];   vector<int> ans;   vector<pair<int, vector<int> > > fin;   void go(int sum, int rem, int dig, int len) {     if (len == 0) {       reverse(ans.begin(), ans.end());       fin.push_back(make_pair(ans.size(), ans));       return;     }     ans.push_back(dig);     int dd = pa[sum][rem];     int remm = parem[sum][rem];     go(sum - dig, remm, dd, len - 1);   }   queue<vector<int> > qu;   void solve(int dii) {     while (not qu.empty()) qu.pop();     vis[dii][dii % d] = 1;     qu.push({dii, dii % d, dii, 0});     while (not qu.empty()) {       auto vec = qu.front();       qu.pop();       int sum = vec[0], rem = vec[1], dig = vec[2], len = vec[3];       if (sum > s) continue;       if (sum > 5001) continue;       if (len > 50001) continue;       for (int i = 0; i <= 9; i++) {         if (sum == 0 && i == 0) continue;         int sumi = sum + i;         int remi = (rem * 10 + i) % d;         if (not vis[sumi][remi]) {           pa[sumi][remi] = dig;           parem[sumi][remi] = rem;           vis[sumi][remi] = 1;           qu.push({sumi, remi, i, len + 1});         }         if (sumi == s && remi == 0) {           ans.clear();           go(sumi, remi, i, len + 1);           return;         }       }     }   }   int main() {     scanf( %d%d , &d, &s);     vis[0][0] = 1;     solve(0);     if (not fin.empty()) {       sort(fin.begin(), fin.end());       for (int i = 0; i < fin[0].first; i++) {         printf( %d , fin[0].second[i]);       }       printf(  n );       return 0;     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y, xlast, ylast, n, k, i;     double sum = 0.0f;     scanf( %d%d , &n, &k);     scanf( %d%d , &xlast, &ylast);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &x, &y);       sum += sqrt(pow((double)x - xlast, 2) + pow((double)y - ylast, 2));       xlast = x;       ylast = y;     }     printf( %0.9lf , sum / 50 * k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1000000007;   long long ans, f[2002][2002];   int n, m;   inline void solve() {     scanf( %d%d , &n, &m);     for (register int i = 1; i <= m; ++i) f[1][i] = 1;     for (register int i = 2; i <= n; ++i) {       int t = 0;       f[i][1] = 1;       for (register int j = 2; j <= m; ++j) {         (t += f[i - 1][j]) %= md;         f[i][j] = (f[i][j - 1] + t) % md;       }     }     for (register int i = 1; i <= n; ++i)       for (register int j = 2; j <= m; ++j)         (ans += (m - j + 1) * (f[i][j] - f[i - 1][j] + md) % md *                 f[n - i + 1][j] % md) %= md;     printf( %lld n , ans);   }   int main() {     ios_base::sync_with_stdio(false);     int T = 1;     for (; T--;) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     vector<int> vec(n);     vector<int> kactane(30, 0);     vector<int> harfmax(30, 0);     int res = 0;     for (int i = 0; i < n; i++) {       int cnt = 0;       kactane[s[i] -  a ]++;       for (int u = s[i] -  a  + 1; u <=  z  -  a ; u++) {         if (kactane[u]) {           cnt = max(cnt, harfmax[u]);         }       }       harfmax[s[i] -  a ] = max(harfmax[s[i] -  a ], cnt + 1);       vec[i] = cnt;       res = max(res, vec[i]);       if (res > 1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (auto& x : vec) cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     if (str.size() % 2 == 1) {       cout <<  No  << endl;       return 0;     }     stack<char> sta;     for (int i = 0; i < str.size(); i++) {       if (!sta.empty() && sta.top() == str[i])         sta.pop();       else         sta.push(str[i]);     }     puts(sta.empty() ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1.0e-11;   const double pi = acos(-1.0);   int main() {     string s;     cin >> s;     int n = s.size();     vector<int> points;     for (long long i = 0; i < (int)(s).size(); i++) {       if (s[i] ==  . ) {         points.push_back(i);       }     }     if (points.empty() || points.front() == 0 || points.front() > 8 ||         points.back() == n - 1 || n - 1 - points.back() > 3) {       cout <<  NO n ;       return 0;     }     vector<bool> sep((int)(s).size(), false);     for (long long i = 1; i <= (int)(points).size() - 1; i++) {       if (points[i] - points[i - 1] - 1 < 2 ||           points[i] - points[i - 1] - 1 > 11) {         cout <<  NO n ;         return 0;       }       int d = points[i] - points[i - 1] - 1;       if (d > 8) {         sep[points[i] - 8] = true;         continue;       }       sep[points[i - 1] + 2] = true;     }     cout <<  YES n ;     for (long long i = 0; i < (int)(s).size(); i++) {       if (sep[i]) {         cout << endl;       }       cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   template <typename T, typename S>   ostream& operator<<(ostream& os, pair<T, S> a) {     os <<  (  << a.first <<  ,  << a.second <<  ) ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> v) {     for (auto x : v) os << x <<    ;     return os;   }   void debug() { cerr <<   n ; }   template <typename H, typename... T>   void debug(H a, T... b) {     cerr << a;     if (sizeof...(b)) cerr <<  ,  ;     debug(b...);   }   vector<bool> get_prime(int n) {     vector<bool> prime(n + 1, true);     if (n >= 0) prime[0] = false;     if (n >= 1) prime[1] = false;     for (int i = 2; i * i <= n; i++) {       if (prime[i]) {         for (int j = i + i; j <= n; j += i) prime[j] = false;       }     }     return (prime);   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     auto p = get_prime(2000000);     vector<ll> d;     for (int i = 0; i < (int)(1000000); ++i)       if (p[i]) d.push_back(i);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       ll a = sqrt(n);       int ans2 = 1;       ans2 +=           upper_bound(d.begin(), d.end(), n) - lower_bound(d.begin(), d.end(), a);       if (p[a]) ans2--;       cout << ans2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1050;   const int MAX_M = 1050;   int n, m, q;   int matrix[MAX_N][MAX_M];   int l[MAX_M][MAX_N];   int r[MAX_M][MAX_N];   int u[MAX_N][MAX_M];   int d[MAX_N][MAX_M];   void modify(int x, int y) {     matrix[x][y] ^= 1;     for (int j = 1; j <= m; j++) {       if (matrix[x][j] == 1) {         l[j][x] = l[j - 1][x] + 1;       } else {         l[j][x] = 0;       }     }     for (int j = m; j >= 1; j--) {       if (matrix[x][j] == 1) {         r[j][x] = r[j + 1][x] + 1;       } else {         r[j][x] = 0;       }     }     for (int i = 1; i <= n; i++) {       if (matrix[i][y] == 1) {         u[i][y] = u[i - 1][y] + 1;       } else {         u[i][y] = 0;       }     }     for (int i = n; i >= 1; i--) {       if (matrix[i][y] == 1) {         d[i][y] = d[i + 1][y] + 1;       } else {         d[i][y] = 0;       }     }   }   int query(int f[], int pos, int bound) {     int l = pos;     int r = pos;     int ret = f[pos];     int min_height = f[pos];     while (l > 1 || r < bound) {       if (r == bound || f[l - 1] > f[r + 1]) {         l--;         min_height = min(min_height, f[l]);       } else {         r++;         min_height = min(min_height, f[r]);       }       ret = max(ret, (r - l + 1) * min_height);     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , matrix[i] + j);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (matrix[i][j] == 1) {           l[j][i] = l[j - 1][i] + 1;           u[i][j] = u[i - 1][j] + 1;         } else {           l[j][i] = u[i][j] = 0;         }       }     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--) {         if (matrix[i][j] == 1) {           r[j][i] = r[j + 1][i] + 1;           d[i][j] = d[i + 1][j] + 1;         } else {           d[i][j] = r[j][i] = 0;         }       }     while (q--) {       int a, x, y;       scanf( %d%d%d , &a, &x, &y);       if (a == 1) {         modify(x, y);         continue;       }       int ans = 0;       ans = max(ans, query(l[y], x, n));       ans = max(ans, query(r[y], x, n));       ans = max(ans, query(u[x], y, m));       ans = max(ans, query(d[x], y, m));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, N, minim, maxim;     long long M;     scanf( %d %I64d , &N, &M);     maxim = 0;     if (2 * M < N)       minim = N - 2 * M;     else       minim = 0;     if (M == 0)       maxim = N;     else       for (i = 1; i <= N; ++i)         if (1LL * i * (i - 1) / 2 >= M) {           maxim = N - i;           break;         }     printf( %d %d n , minim, maxim);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pred[300005];   long long suffc[300005];   long long ans[300005];   int main() {     int n, m;     scanf( %d %d , &n, &m);     pair<int, int> ara[n];     vector<pair<int, int> > vt(n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i].first, &ara[i].second);       vt[i] = {ara[i].second - ara[i].first, i};     }     sort(vt.begin(), vt.end());     pred[0] = ara[vt[0].second].second;     for (int i = 1; i < n; i++) {       pred[i] = pred[i - 1] + ara[vt[i].second].second;     }     suffc[n - 1] = ara[vt[n - 1].second].first;     for (int i = n - 2; i >= 0; i--) {       suffc[i] = suffc[i + 1] + ara[vt[i].second].first;     }     for (int i = 0; i < n; i++) {       int pos = upper_bound(vt.begin(), vt.end(),                             make_pair(ara[i].second - ara[i].first, n + 1)) -                 vt.begin();       ans[i] += 1ll * suffc[pos] + 1ll * (n - pos) * ara[i].second;       pos--;       if (pos >= 0)         ans[i] += 1ll * pred[pos] + 1ll * (pos + 1) * ara[i].first,             ans[i] -= ara[i].first + ara[i].second;       if (i == 0) {       }     }     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--, v--;       ans[u] -= min(ara[u].first + ara[v].second, ara[u].second + ara[v].first);       ans[v] -= min(ara[u].first + ara[v].second, ara[u].second + ara[v].first);     }     for (int i = 0; i < n; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   deque<int> d[100005];   int v[100005];   int p[100005];   pair<int, int> q[100005];   int ans = 0;   int prog = 0;   int as[100005];   unordered_map<int, int> possible[100005];   bool cmp(int a, int b) {     if (q[a].first / 300 != q[b].first / 300)       return q[a].first / 300 < q[b].first / 300;     return q[a].second < q[b].second;   }   void update(int val, int pos, int u, int c) {     if (c == -1) {       prog -= possible[val].size() <= 1;       if (u == 1) {         int cnt = d[val].front();         d[val].pop_front();         if (d[val].empty())           --ans;         else {           --possible[val][d[val].front() - cnt];           if (!possible[val][d[val].front() - cnt])             possible[val].erase(d[val].front() - cnt);         }       } else {         int cnt = d[val].back();         d[val].pop_back();         if (d[val].empty())           --ans;         else {           --possible[val][cnt - d[val].back()];           if (!possible[val][cnt - d[val].back()])             possible[val].erase(cnt - d[val].back());         }       }       if (!d[val].empty()) prog += possible[val].size() <= 1;     } else {       if (d[val].empty())         ++ans;       else         prog -= possible[val].size() <= 1;       if (u == 1) {         if (d[val].empty()) {           d[val].push_front(pos);         } else {           int cnt = d[val].front();           d[val].push_front(pos);           ++possible[val][cnt - pos];         }       } else {         if (d[val].empty()) {           d[val].push_back(pos);         } else {           int cnt = d[val].back();           d[val].push_back(pos);           ++possible[val][pos - cnt];         }       }       if (possible[val].size() <= 1) ++prog;     }   }   int main(void) {     int n, m;     ios_base ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> v[i];     cin >> m;     for (int i = 1; i <= m; ++i) cin >> q[i].first >> q[i].second, p[i] = i;     sort(p + 1, p + 1 + m, cmp);     for (int i = q[p[1]].first; i <= q[p[1]].second; ++i) update(v[i], i, 1, 1);     as[p[1]] = ans + !prog;     int l = q[p[1]].first, r = q[p[1]].second;     for (int i = 2; i <= m; ++i) {       while (l > q[p[i]].first) --l, update(v[l], l, -1, 1);       while (r < q[p[i]].second) ++r, update(v[r], r, 1, 1);       while (l < q[p[i]].first) update(v[l], l, -1, -1), ++l;       while (r > q[p[i]].second) update(v[r], r, 1, -1), --r;       as[p[i]] = ans + !prog;     }     for (int i = 1; i <= m; ++i) cout << as[i] <<   n ;     return cout <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   struct tc {     int cnt, count;     long long p[5001];   } q[5001];   struct sc {     int id;     long long num;   } anss[200010], s[200010];   void merge(int l, int mid, int r) {     int i = l, j = mid + 1;     int cc = l;     while (i <= mid && j <= r) {       if (anss[i].num <= anss[j].num) {         s[cc].id = anss[i].id;         s[cc++].num = anss[i++].num;       } else {         s[cc].id = anss[j].id;         s[cc++].num = anss[j++].num;       }     }     while (i <= mid) {       s[cc].id = anss[i].id;       s[cc++].num = anss[i++].num;     }     while (j <= r) {       s[cc].id = anss[j].id;       s[cc++].num = anss[j++].num;     }     for (i = l; i < cc; i++) {       anss[i].id = s[i].id;       anss[i].num = s[i].num;     }     return;   }   void mergesort(int x, int y) {     if (x < y) {       int mid = (x + y) / 2;       mergesort(x, mid);       mergesort(mid + 1, y);       merge(x, mid, y);     }     return;   }   int main() {     int i, j;     long long n, a, x, y, m;     int ans = -1, k, sum, l = 0;     cin >> n;     for (i = 0; i < n; i++) {       scanf( %d %I64d %I64d %I64d %I64d , &k, &a, &x, &y, &m);       sum = 0;       l += k;       q[i].cnt = 1;       q[i].count = k;       q[i].p[1] = a;       for (j = 2; j <= k; j++) {         q[i].p[j] = (x * q[i].p[j - 1] + y) % m;         if (q[i].p[j] < q[i].p[j - 1]) sum++;       }       ans = max(ans, sum);     }     printf( %d n , ans);     int st = 0, end = 0;     if (l <= 2e5) {       while (end < l) {         for (i = 0; i < n; i++) {           for (j = q[i].cnt; j <= q[i].count; j++) {             if (j != q[i].cnt && q[i].p[j] < q[i].p[j - 1]) {               q[i].cnt = j;               break;             }             anss[end].id = i;             anss[end++].num = q[i].p[j];           }           if (j > q[i].count) q[i].cnt = j;         }         mergesort(st, end - 1);         st = end;       }       for (i = 0; i < l; i++) printf( %I64d %d n , anss[i].num, anss[i].id + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> p(n), m(n);       vector<vector<long long>> v(n + 1);       for (long long i = 0; i < n; i++) {         cin >> m[i] >> p[i];         v[m[i]].push_back(i);       }       vector<long long> sum(n + 1);       sum[0] = v[0].size();       for (long long i = 1; i < n + 1; i++) {         sum[i] = sum[i - 1] + v[i].size();       }       long long kol = 0;       long long ans = 0;       multiset<long long> st;       for (long long i = n; i > 0; i--) {         for (long long j = 0; j < v[i].size(); j++) {           st.insert(p[v[i][j]]);         }         while (kol + sum[i - 1] < i) {           ans += *st.begin();           ++kol;           st.erase(st.begin());         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool check(int x, int n, vector<int>& a) {     vector<int> temp;     int i = 0, j = x;     int cnt = 0;     bool ok = false;     while (cnt < n) {       if (ok)         temp.push_back(a[i]), i++, ok = false;       else         temp.push_back(a[j]), j++, ok = true;       cnt++;     }     cnt = 0;     return cnt == x;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int cnt = 0;     vector<int> ans(n);     for (int i = 1; i < n; i += 2) {       ans[i] = a[cnt++];     }     for (int i = 0; i < n; i += 2) ans[i] = a[cnt++];     cnt = 0;     for (int i = 1; i < n - 1; i++) {       if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) cnt++;     }     cout << cnt <<   n ;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       int n, i, z = -1, o = -1, s = 0, max = -1;       scanf( %d , &n);       char ss[n + 5], at[2];       scanf( %s , ss);       int a[n], b[n], zero[n], one[n];       for (i = 0; i < n; i++) {         at[0] = ss[i];         at[1] =   0 ;         a[i] = atoi(at);       }       for (i = 0; i < n; i++) {         if (!a[i]) {           if (o >= 0) {             zero[++z] = one[o--];             b[i] = zero[z];           } else {             zero[++z] = ++s;             b[i] = zero[z];           }         }         if (a[i]) {           if (z >= 0) {             one[++o] = zero[z--];             b[i] = one[o];           } else {             one[++o] = ++s;             b[i] = one[o];           }         }         if (max < b[i]) max = b[i];       }       printf( %d n , max);       for (i = 0; i < n; i++) printf( %d  , b[i]);       printf(  n );     }   }


#include <algorithm>   #include <iostream>   #include <cstdlib>   #include <cassert>   #include <cstring>   #include <iomanip>   #include <cstdio>   #include <limits>   #include <string>   #include <vector>   #include <cmath>   #include <deque>   #include <queue>   #include <stack>   #include <map>   #include <set>   using namespace std;      typedef long long LL;   typedef long long ll;   typedef long double LD;   typedef vector<int> vi;   typedef pair<LL,LL> PLL;   typedef pair<LL,int> PLI;   typedef pair<int,int> PII;   typedef pair<int,int> pii;   typedef vector<vector<LL>> VVL;      #define rep(i, a, b) for(int i = a; i < (b); ++i)   #define trav(a, x) for(auto& a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   #define popf pop_front   #define pf push_front   #define popb pop_back   #define mp make_pair   #define pb push_back   #define remove erase   #define fi first   #define se second      #define endl   n       const int INF = 1061109567;   const LL LINF = 4557430888798830399LL;   const LL MOD = 1000000007;   const int dx[8] = {0,0,1,-1,1,-1,1,-1};   const int dy[8] = {1,-1,0,0,1,-1,-1,1};   const char dch[4] = { R , L , D , U };   // const string ds[8] = { E , W , S , N , SE , NW , SW , NE };   inline void fasterios(){       ios_base::sync_with_stdio(0);       cin.tie(0); cout.tie(0);   }         // Don t forget to read all the inputs before returning!!!   int solve(){     int n; cin >> n;     vector <PII> arr(n);     rep(i,0,n){       cin >> arr[i].fi;       arr[i].se = i;     }     sort(all(arr));     vector <int> tmp[2];     rep(i,0,n) if(abs(arr[i].se - i) % 2 == 1) tmp[i%2].pb(arr[i].fi);     sort(all(tmp[0]));     sort(all(tmp[1]));     if(sz(tmp[0]) != sz(tmp[1])){       cout <<  NO  << endl;       return 0;     }     for(int i = 0;i < sz(tmp[0]);i++){       if(tmp[0][i] != tmp[1][i]){         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }      int main(){     fasterios();     int testCases; cin >> testCases; int tc = 0;     while(++tc <= testCases){       // cout <<  Case #  << tc <<  :  ;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   long long a, b, n, dv[N], l, r, sz;   long long bs(long long l, long long r) {     long long bas = 0;     long long son = sz + 1;     while (bas + 1 < son) {       long long orta = bas + son >> 1;       if (dv[orta] < l)         bas = orta;       else if (dv[orta] > r)         son = orta;       else if (dv[orta] <= r and dv[orta] >= l)         bas = orta;     }     return (dv[bas] < l or dv[bas] > r) ? -1 : dv[bas];   }   int main() {     cin >> a >> b >> n;     for (long long i = 1; i * i <= max(a, b); i++) {       if (a % i == 0 and b % i == 0) {         dv[++sz] = i;         if (b % (a / i) == 0 and i * i != max(a, b)) dv[++sz] = a / i;         if (a % (b / i) == 0) dv[++sz] = b / i;       } else if (a % (b / i) == 0 and b % i == 0)         dv[++sz] = b / i;       else if (b % (a / i) == 0 and a % i == 0)         dv[++sz] = a / i;     }     sort(dv + 1, dv + sz + 1);     for (long long i = 1; i <= n; i++) {       cin >> l >> r;       cout << bs(l, r) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, ans, i, j, k;     cin >> t;     for (i = 0; i < t; i++) {       cin >> n;       int x[2 * n];       for (j = 0; j < 2 * n; j++) cin >> x[j];       sort(x, x + 2 * n);       ans = x[n] - x[n - 1];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 1e9 + 7;   int ds[100];   int hs[100];   int solve() {     int N, X;     scanf( %d %d , &N, &X);     for (int i = 0; i < N; i++) {       scanf( %d %d , &ds[i], &hs[i]);     }     int last = *std::max_element(ds, ds + N);     if (last >= X) return 1;     int dec = 0;     for (int i = 0; i < N; i++) {       dec = std::max(dec, ds[i] - hs[i]);     }     if (dec == 0) return -1;     return (X - last + dec - 1) / dec + 1;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       printf( %d n , solve());     }   }


#include <bits/stdc++.h>   using namespace std;   struct s_ix {     long long ix;     long long val;   };   bool operator<(s_ix aa, s_ix bb) { return aa.val - aa.ix < bb.val - bb.ix; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, k, nc[200200], sum, nbw, maxnbw;       s_ix nb[200200];       string s[200200];       cin >> n;       for (int j = 0; j < n; j++) cin >> s[j];       maxnbw = 0;       for (int l = 0; l < 26; l++) {         nbw = 0;         for (int j = 0; j < n; j++) {           nb[j].val = 0;           nb[j].ix = 0;           for (int jj = 0; jj < s[j].length(); jj++) {             if ((int)(s[j][jj] -  a ) == l)               nb[j].val++;             else               nb[j].ix++;           }         }         sort(nb, nb + n);         reverse(nb, nb + n);         long long nl = 0;         nl = nb[0].val - nb[0].ix;         int j = 0;         while (nl > 0 and j < n) {           j++;           nl += nb[j].val - nb[j].ix;           nbw++;         }         maxnbw = max(maxnbw, nbw);       }       cout << maxnbw << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s1 = 0, s2 = 0, s3 = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i % 3 == 0)         s1 += a[i];       else if (i % 3 == 1)         s2 += a[i];       else         s3 += a[i];     }     if (s1 >= s2 && s1 >= s3)       cout <<  chest n ;     else if (s2 >= s3 && s2 >= s1)       cout <<  biceps n ;     else       cout <<  back n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long strL[200005], patL[200005], n, m, pref[200005], ans, tempL[200005];   char strC[200005], tempC[200005];   vector<long long> endings;   string patC =   ;   long long lenP, lenS;   void calcPrefixFunction() {     for (long long i = 1, k = 0; i < m - 2; i++) {       while (k > 0 && (patC[k] != patC[i] || patL[k] != patL[i])) k = pref[k - 1];       if (patC[k] == patC[i] && patL[i] == patL[k])         pref[i] = ++k;       else         pref[i] = k;     }   }   void kmp() {     for (long long i = 0, k = 0; i < n; i++) {       while (k > 0 && (strL[i] != patL[k] || strC[i] != patC[k])) k = pref[k - 1];       if (strL[i] == patL[k] && strC[i] == patC[k]) k++;       if (k == m - 2) {         endings.push_back(i);         k = pref[k - 1];       }     }   }   long long tempSolve1() {     long long ret = 0;     for (long long i = 0; i < n; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         ret += strL[i] - tempL[0] + 1;     return ret;   }   long long tempSolve2() {     long long ret = 0;     for (long long i = 0; i < n - 1; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         if (tempL[1] <= strL[i + 1] && strC[i + 1] == tempC[1]) ret++;     return ret;   }   void solve() {     if (lenP > lenS) {       puts( 0 );       return;     }     if (m == 1) {       printf( %I64d , tempSolve1());       return;     }     if (m == 2) {       printf( %d , tempSolve2());       return;     }     calcPrefixFunction();     kmp();     for (long long i = 0; i < endings.size(); i++) {       long long start, end;       end = endings[i] + 1;       start = end - m + 1;       if (end >= n || start < 0) continue;       if (strC[start] == tempC[0] && strL[start] >= tempL[0])         if (strC[end] == tempC[m - 1] && strL[end] >= tempL[m - 1]) ans++;     }     printf( %d , ans);   }   void input() {     scanf( %d %d , &n, &m);     for (long long i = 0; i < n; i++) {       scanf( %d-%c , &strL[i], &strC[i]);       if (i && strC[i] == strC[i - 1]) {         strL[i - 1] += strL[i];         n--;         i--;       }       lenS += strL[i];     }     for (long long i = 0; i < m; i++) {       scanf( %d-%c , &tempL[i], &tempC[i]);       lenP += tempL[i];       if (i && tempC[i] == tempC[i - 1]) {         tempL[i - 1] += tempL[i];         if (i - 2 >= 0) patL[i - 2] = tempL[i - 1];         i--;         m--;       } else if (i && i < m - 1)         patC += tempC[i], patL[i - 1] = tempL[i];     }   }   int main() {     input();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, g;     cin >> n >> g;     g %= 4 * n;     long long xx, yy;     cin >> xx >> yy;     long long x[n], y[n];     for (int(i) = int(0); i < int(n); ++i) cin >> x[i] >> y[i];     for (int(i) = int(1); i < int(g + 1); ++i) {       long long dx = xx - x[(i - 1) % n];       long long dy = yy - y[(i - 1) % n];       xx -= 2 * dx;       yy -= 2 * dy;     }     cout << xx <<     << yy << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct dat {     long long a;     long long n;   };   bool comp(struct dat a, struct dat b) { return a.a < b.a; }   int main() {     ios::sync_with_stdio(false);     long long a, b, c, i, j, k, l, m, t, x, y, n, z;     vector<long long> a1;     string s;     cin >> n;     vector<vector<long long> > arr(n, vector<long long>(2));     struct dat arr1[n];     for (i = 0; i < n; i++) {       cin >> arr[i][0];       arr[i][1] = i;       arr1[i].a = arr[i][0];       arr1[i].n = i;     }     sort(arr1, arr1 + n, comp);     for (i = 0; i < n; i++) {       arr[arr1[i].n][1] = i;     }     vector<vector<long long> > ans;     int arr3[n];     for (i = 0; i < n; i++) {       arr3[i] = 0;     }     for (i = 0; i < n; i++) {       if (arr3[i] == 1)         continue;       else {         j = i;         vector<long long> q1;         while (arr3[j] == 0) {           arr3[j] = 1;           q1.push_back(j);           j = arr[j][1];         }         sort(q1.begin(), q1.end());         ans.push_back(q1);       }     }     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++) {       cout << ans[i].size() <<    ;       for (j = 0; j < ans[i].size(); j++) {         cout << ans[i][j] + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long N = 5e3 + 5;   long long a[N];   long long pre[N];   long long dp[N][N];   long long n, m, k;   long long check = 0;   long long go(long long pos, long long kk) {     if (kk == k) return 0;     if (pos == n + 1) return -1e15;     long long &ans = dp[pos][kk];     if (ans != -1) return ans;     ans = go(pos + 1, kk);     if (pos + m - 1 <= n) {       ans = max(ans, pre[pos + m - 1] - pre[pos - 1] + go(pos + m, kk + 1));     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       pre[i] = pre[i - 1] + a[i];     }     memset(dp, -1, sizeof(dp));     cout << go(1, 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string str;   int main() {     cin >> n >> str;     for (int i = 0; i < str.size(); i++) {       if (n % (i + 1) == 0) {         for (int j = 0; j <= i / 2; j++) {           swap(str[j], str[i - j]);         }       }     }     cout << str;   }


#include <bits/stdc++.h>   using namespace std;   bool deb = false;   int i, k, n;   const int N = 500011;   int a[N];   bool f1(long long int x) {     int i;     long long int inc = 0, dec = 0;     for (i = 0; i < n; ++i) {       if (a[i] > x)         dec += (a[i] - x);       else         inc += (x - a[i]);     }     if (dec <= inc && dec <= k) return 1;     return 0;   }   bool f2(long long int x) {     int i;     long long int inc = 0, dec = 0;     for (i = 0; i < n; ++i) {       if (a[i] > x)         dec += (a[i] - x);       else         inc += (x - a[i]);     }     if (dec >= inc && inc <= k) return 1;     return 0;   }   long long int min_max(long long int lo, long long int hi) {     while (lo < hi) {       long long int mid = lo + (hi - lo) / 2;       if (f1(mid)) {         hi = mid;       } else         lo = mid + 1;     }     return hi;   }   long long int max_min(long long int lo, long long int hi) {     while (lo < hi) {       long long int mid = lo + (hi - lo) / 2;       if (f2(mid)) {         lo = mid + 1;       } else         hi = mid;     }     return lo - 1;   }   int main() {     int i, j;     scanf( %d , &n), scanf( %d , &k);     for (i = 0; i < n; ++i) scanf( %d , &a[i]);     int mx = min_max(1, 1000000007);     int mn = max_min(1, 1000000007);     printf( %d n , mx - mn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     string s;     map<string, int> mp;     for (int i = 0; i < n; ++i) {       cin >> s;       mp[s]++;     }     int ans = 0;     for (auto ss : mp) {       ans = max(ans, ss.second);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int mx = 2002;   const int inf = 1000 * 1000 * 1000;   using namespace std;   vector<int> adj[mx];   vector<long long> w[mx];   set<pair<long long, int> > s;   long long dist[mx];   bool mrk[mx];   void dijkstra() {     while (s.size()) {       pair<long long, int> p = *s.begin();       s.erase(s.begin());       int v = p.second;       mrk[v] = 1;       for (int i = 0; i < adj[v].size(); i++) {         int u = adj[v][i];         if (!mrk[u]) {           pair<long long, int> p1 = make_pair(dist[u], u);           s.erase(p1);           dist[u] = min(dist[u], w[v][i] + dist[v]);           s.insert(make_pair(dist[u], u));         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, cnt = 0;     long long mn = inf;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         long long k;         cin >> k;         w[i].push_back(k);         w[j].push_back(k);         adj[i].push_back(j);         adj[j].push_back(i);         cnt++;         mn = min(mn, k);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < w[i].size(); j++) {         w[i][j] -= mn;       }     }     for (int i = 0; i < n; i++) {       long long ww = inf;       for (int j = 0; j < adj[i].size(); j++) {         ww = min(ww, w[i][j]);       }       dist[i] = 2 * ww;       s.insert(make_pair(dist[i], i));     }     dijkstra();     for (int i = 0; i < n; i++) {       cout << dist[i] + (n - 1) * mn << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void DBG() { cerr <<  ] n ; }   template <typename T, typename... Args>   void DBG(T first, Args... args) {     cerr << first;     if (sizeof...(args)) cerr <<  ,  ;     DBG(args...);   }   void solve() {     long long int x0, y0, ax, ay, bx, by, sx, sy, t;     cin >> x0 >> y0 >> ax >> ay >> bx >> by >> sx >> sy >> t;     vector<long long int> px, py;     px.push_back(x0);     py.push_back(y0);     while (true) {       long long bound = 0;       if (px.back() > sx) {         bound += px.back() - sx;       }       if (py.back() > sy) {         bound += py.back() - sy;       }       if (bound > t) {         px.pop_back();         py.pop_back();         break;       }       px.push_back(px.back() * ax + bx);       py.push_back(py.back() * ay + by);     }     long long int n = px.size();     long long int g = 0;     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         long long int from_i = abs(sx - px[i]) + abs(sy - py[i]);         long long int from_j = abs(sx - px[j]) + abs(sy - py[j]);         long long int cnt =             min(from_i, from_j) + abs(px[i] - px[j]) + abs(py[i] - py[j]);         if (cnt <= t) {           g = max(g, j - i + 1);         }       }     }     cout << g <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t = 1;     for (long long int tt = 1; tt <= t; tt++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 100;   int n, root, u, Sum;   int num[maxn], sum[maxn];   vector<int> G[maxn];   int ans1, ans2;   void dfs1(int x) {     sum[x] = num[x];     int len = G[x].size();     for (int i = 0; i < len; ++i) {       int pos = G[x][i];       dfs1(pos);       if (ans1 != 0) {         return;       }       sum[x] += sum[pos];     }     if (sum[x] == Sum / 3) {       ans1 = x;     }   }   void dfs2(int x) {     num[x] = 0;     int len = G[x].size();     for (int i = 0; i < len; ++i) {       int pos = G[x][i];       dfs2(pos);     }   }   void dfs3(int x) {     sum[x] = num[x];     int len = G[x].size();     for (int i = 0; i < len; ++i) {       int pos = G[x][i];       if (pos != ans1) {         dfs3(pos);         if (ans2 != 0) {           return;         }         sum[x] += sum[pos];       }     }     if (sum[x] == Sum / 3) {       ans2 = x;     }   }   int main() {     ios::sync_with_stdio(false);     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; ++i) {         G[i].clear();       }       Sum = 0;       ans1 = ans2 = 0;       for (int i = 1; i <= n; ++i) {         scanf( %d%d , &u, &num[i]);         Sum += num[i];         if (u != 0) {           G[u].push_back(i);         } else {           root = i;         }       }       if (Sum % 3 != 0) {         printf( -1 n );         continue;       }       dfs1(root);       if (ans1 == 0 || ans1 == root) {         printf( -1 n );         continue;       }       dfs2(ans1);       dfs3(root);       if (ans2 == 0 || ans2 == root) {         printf( -1 n );       } else {         printf( %d %d n , ans1, ans2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, n, m, mis, cri;   int main() {     cin >> a;     for (int i = 0; i < a; i++) {       cin >> n >> m;       if (n > m) {         mis++;       } else if (n < m) {         cri++;       }     }     if (mis > cri) {       cout <<  Mishka ;     } else if (cri > mis) {       cout <<  Chris ;     } else {       cout <<  Friendship is magic!^^ ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<int, int>;   using vi = vector<int>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   struct T {     ld mat[2][2];     ld dx = 0, dy = 0;     T() {       for (int i = 0; i < 2; ++i)         for (int j = 0; j < 2; ++j) mat[i][j] = i == j;     }     T(const T &o) {       for (int i = 0; i < 2; ++i)         for (int j = 0; j < 2; ++j) mat[i][j] = o.mat[i][j];       dx = o.dx;       dy = o.dy;     }   };   T op(T l, T r) {     T m;     m.mat[0][0] = l.mat[0][0] * r.mat[0][0] + l.mat[0][1] * r.mat[1][0];     m.mat[0][1] = l.mat[0][0] * r.mat[0][1] + l.mat[0][1] * r.mat[1][1];     m.mat[1][0] = l.mat[1][0] * r.mat[0][0] + l.mat[1][1] * r.mat[1][0];     m.mat[1][1] = l.mat[1][0] * r.mat[0][1] + l.mat[1][1] * r.mat[1][1];     m.dx = l.mat[0][0] * r.dx + l.mat[0][1] * r.dy + l.dx;     m.dy = l.mat[1][0] * r.dx + l.mat[1][1] * r.dy + l.dy;     return m;   }   T ident;   struct SegmentTree {     struct Node {       T val;       int l, r;       Node(T _val, int _l, int _r) : val(_val), l(_l), r(_r){};     };     int n;     vector<Node> tree;     SegmentTree(int p, vector<T> &init) : n(1 << p) {       tree.assign(2 * n, Node(ident, 0, n - 1));       for (int j = 1; j < n; ++j) {         int m = (tree[j].l + tree[j].r) / 2;         tree[2 * j].l = tree[j].l;         tree[2 * j].r = m;         tree[2 * j + 1].l = m + 1;         tree[2 * j + 1].r = tree[j].r;       }       for (int j = 2 * n - 1; j > 0; --j) {         if (j >= n)           tree[j].val = init[j - n];         else           tree[j].val = op(tree[2 * j].val, tree[2 * j + 1].val);       }     }     void update(int i, T val) {       for (tree[i + n].val = val, i = (i + n) / 2; i > 0; i /= 2)         tree[i].val = op(tree[2 * i].val, tree[2 * i + 1].val);     }     T query(int l, int r) {       T lhs, rhs;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) lhs = op(lhs, tree[l++].val);         if (!(r & 1)) rhs = op(tree[r--].val, rhs);       }       return op(l == r ? op(lhs, tree[l].val) : lhs, rhs);     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int p = 1;     while ((1 << p) < 2 * n) ++p;     vector<T> init(1 << p, T());     for (int i = 0; i < n; ++i) {       init[2 * i + 1].dx = 1;     }     SegmentTree st(p, init);     vector<ld> curdeg(n, 0.0);     while (m--) {       int x, y, z;       cin >> x >> y >> z;       --y;       if (x == 1) {         T cur = st.query(2 * y + 1, 2 * y + 1);         cur.dx += z;         st.update(2 * y + 1, cur);       } else {         curdeg[y] -= ld(z) / 180.0 * 3.14159265358979323846;         T m;         m.mat[0][0] = m.mat[1][1] = cos(curdeg[y]);         m.mat[1][0] = sin(curdeg[y]);         m.mat[0][1] = -m.mat[1][0];         st.update(2 * y, m);       }       T f = st.query(0, 2 * n - 1);       printf( %.7lf %.7lf n , double(f.dx), double(f.dy));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[166666][6];   multiset<long long> s[6];   signed main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= 4; j++) {         scanf( %lld , &arr[i][j]);         s[j].insert(arr[i][j]);       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= 4; j++) {         s[j].erase(s[j].find(arr[i][j]));       }       if (*s[1].rbegin() <= *s[3].begin() && *s[2].rbegin() <= *s[4].begin()) {         cout << *s[1].rbegin() <<     << *s[2].rbegin();         return 0;       }       for (long long j = 1; j <= 4; j++) {         s[j].insert(arr[i][j]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long int k, a[26], i, max = -1, l, sum = 0;     cin >> s;     cin >> k;     l = s.length();     for (i = 0; i < 26; i++) {       cin >> a[i];       if (max < a[i]) max = a[i];     }     for (i = 0; i < l; i++) {       sum = sum + (i + 1) * a[s[i] -  a ];     }     for (i = 0; i < k; i++) {       sum += (i + l + 1) * max;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Set(long long N, long long pos) { return N = N | (1 << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }   void CI(long long &_x) { scanf( %d , &_x); }   void CO(long long &_x) { cout << _x; }   template <typename T>   void getarray(T a[], long long n) {     for (long long i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void prLLIarray(T a[], long long n) {     for (long long i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   const double EPS = 1e-9;   const long long INF = 0x7f7f7f7f;   long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};   long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};   long long dr4[4] = {0, 0, 1, -1};   long long dc4[4] = {-1, 1, 0, 0};   long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};   long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};   int main() {     double a, b, m;     cin >> a >> b >> m;     double vx, vy, vz;     cin >> vx >> vy >> vz;     double tt = m / vy;     tt = fabs(tt);     double x = (a / 2.0) + (tt * vx);     double z = vz * tt;     while (x < 0) {       x += 2.0 * a;     }     while (x > (2 * a)) x -= (2.0 * a);     if (x > a) x = (2.0 * a) - x;     while (z < 0) z += (2.0 * b);     while (z > (2 * b)) z -= (2.0 * b);     if (z > b) z = (2.0 * b) - z;     cout << fixed << setprecision(9) << x <<     << z <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int len(const T &c) {     return (int)c.size();   }   template <class T>   void cmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void cmax(T &a, T b) {     if (b > a) a = b;   }   int n;   int main() {     cin >> n;     if (n == 3) {       cout << 5;       return 0;     }     int t;     for (int i = 1;; i += 2) {       t = i * i;       t++;       t /= 2;       if (t >= n) {         cout << i << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   vector<int> adj[N];   int sum[N];   void dfs1(int node) {     if (adj[node].size() == 0) sum[node] = 1;     for (int i = 0; i < adj[node].size(); i++) {       int a = adj[node][i];       dfs1(a);       sum[node] += sum[a];     }   }   int mx(int node);   int mn(int node);   int Mx(int node);   int Mn(int node);   int mx(int node) {     if (adj[node].size() == 0) return 1;     int ret = 1;     for (int i = 0; i < adj[node].size(); i++) {       int a = adj[node][i];       ret = max(ret, sum[node] - sum[a] + mn(a));     }     return ret;   }   int mn(int node) {     if (adj[node].size() == 0) return 1;     int ret = 0;     for (int i = 0; i < adj[node].size(); i++) {       int a = adj[node][i];       ret += mx(a) - 1;     }     return ret + 1;   }   int Mx(int node) {     if (adj[node].size() == 0) return 1;     int ret = 0;     for (int i = 0; i < adj[node].size(); i++) {       int a = adj[node][i];       ret += Mn(a);     }     return ret;   }   int Mn(int node) {     if (adj[node].size() == 0) return 1;     int ret = N;     for (int i = 0; i < adj[node].size(); i++) {       int a = adj[node][i];       ret = min(ret, Mx(a));     }     return ret;   }   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &a, &b);       adj[a].push_back(b);     }     dfs1(1);     cout << mx(1) <<     << Mx(1);     return 0;   }