#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long sl = s.length();     long long one = 0;     long long two = 0;     long long three = 0;     long long i;     for (i = 0; i < sl; i = i + 2) {       if (s[i] -  0  == 1) {         one++;       } else if (s[i] -  0  == 2) {         two++;       } else {         three++;       }     }     vector<char> v;     for (i = 0; i < one; i++) {       v.push_back( 1 );       v.push_back( + );     }     for (i = 0; i < two; i++) {       v.push_back( 2 );       v.push_back( + );     }     for (i = 0; i < three; i++) {       v.push_back( 3 );       v.push_back( + );     }     if (v[v.size() - 1] ==  + ) {       for (i = 0; i < v.size() - 1; i++) {         cout << v[i];       }     } else {       for (i = 0; i < v.size(); i++) {         cout << v[i];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   int h[N], ne[N], e[N], idx;   int n;   long long sz[N], dp[N], ans;   void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }   void dfs(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       dfs(j, u);       sz[u] += sz[j];     }   }   void dfs2(int u, int fa) {     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       dp[j] = dp[u] + n - 2 * sz[j];       dfs2(j, u);     }   }   void init(int u, int fa) {     ans += sz[u];     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       init(j, u);     }   }   int main() {     cin >> n;     memset(h, -1, sizeof h);     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b), add(b, a);     }     dfs(1, 1);     init(1, 1);     dp[1] = ans;     dfs2(1, 1);     long long maxx = 0;     for (int i = 1; i <= n; ++i) maxx = max(maxx, dp[i]);     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b, long long& x, long long& y) {     cerr <<  a ==   << a <<   b ==   << b << endl;     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     cerr <<  x1 ==   << x1 <<   y1 ==   << y1 << endl;     x = y1 - (b / a) * x1;     y = x1;     cerr <<  x ==   << x <<   y ==   << y << endl;     return d;   }   long long fact(long long a) {     long long ans = 1;     for (int i = 2; i <= a; ++i) ans = (ans * i) % 1000000007;     return ans;   }   int main() {     int n;     cin >> n;     long long ans = fact(2 * n - 1) % 1000000007;     long long tmp = (fact(n) * fact((2 * n - 1) - n)) % 1000000007;     long long x, y;     cerr << tmp <<     << ans << endl;     gcd(tmp, 1000000007, x, y);     cerr << x << endl;     while (x < 0) x += 1000000007;     ans = (ans * (x % 1000000007)) % 1000000007;     if (n == 2)       cout << 4 << endl;     else       cout << (ans * 2 - n) % 1000000007;     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void checkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void checkmin(T &x, T y) {     if (x > y) x = y;   }   template <class T>   inline T Min(T x, T y) {     return (x > y ? y : x);   }   template <class T>   inline T Max(T x, T y) {     return (x < y ? y : x);   }   using namespace std;   vector<int> a[111111], ans;   int n, m, b[111111], c[111111];   int main() {     while (scanf( %d%d , &n, &m) == 2) {       for (int i = 1; i <= n; ++i) a[i].clear();       ans.clear();       memset(c, 0, sizeof(c));       for (int i = 1; i <= m; ++i) {         int u, v;         scanf( %d%d , &u, &v);         a[u].push_back(v);         a[v].push_back(u);       }       for (int i = 1; i <= n; ++i) scanf( %d , b + i);       queue<int> q;       for (int i = 1; i <= n; ++i)         if (!b[i]) q.push(i);       while (!q.empty()) {         int v = q.front();         q.pop();         if (b[v] == c[v])           ans.push_back(v);         else           continue;         c[v]++;         for (int i = 0; i < a[v].size(); ++i) {           c[a[v][i]]++;           if (b[a[v][i]] == c[a[v][i]]) q.push(a[v][i]);         }       }       printf( %d n , ans.size());       for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);       if (ans.size()) puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double Fib(double x, double z);   string BinDec(unsigned long long x);   string StringInt(long long x);   unsigned long long StringInt(string x);   unsigned long long BinDec(string x);   unsigned long long POWMOD(unsigned long long x, unsigned long long y,                             unsigned long long mod);   unsigned long long POWE(long long, long long);   long long fast_pow(long long a, long long b, long long mod) {     if (b == 0) return 1ll;     long long ans = 1;     if (b % 2) return ans = (fast_pow(a, b - 1, mod) * a) % mod;     ans = (fast_pow(a, b / 2, mod) % mod);     return ((ans * ans) % mod);   }   int tree[100000 * 4] = {}, arr[100200] = {}, x;   void build(int in, int s, int e) {     if (s == e) {       tree[in] = s;       return;     }     int m = (s + e) / 2;     build(in * 2, s, m);     build(in * 2 + 1, m + 1, e);     if (arr[tree[in * 2]] > arr[tree[in * 2 + 1]])       tree[in] = tree[in * 2 + 1];     else       tree[in] = tree[in * 2];   }   void up(int in, int s, int e, int ind, int v) {     if (s > ind || ind > e) return;     if (s == e && s == ind) {       arr[s] = v;       tree[in] = s;       return;     }     int m = (s + e) / 2;     up(in * 2, s, m, ind, v);     up(in * 2 + 1, m + 1, e, ind, v);     if (arr[tree[in * 2]] > arr[tree[in * 2 + 1]])       tree[in] = tree[in * 2 + 1];     else       tree[in] = tree[in * 2];   }   long long qur(int in, int s, int e, int f, int l) {     if (s > e || s > l || f > e) return 100001;     if (f <= s && l >= e) return tree[in];     int m = (s + e) / 2;     long long v, i = qur(in * 2, s, m, f, l), j = qur(in * 2 + 1, m + 1, e, f, l);     if (arr[i] > arr[j])       v = j;     else       v = i;     return v;   }   bool p[100210] = {};   int S = 0, SS = 0;   vector<int> v;   vector<pair<int, int> > ans;   pair<int, int> vv[100010] = {};   void sort() {     int t;     for (int i = 0; i < x; i++) {       int j = qur(1, 0, x - 1, i, x - 1);       if (i == j) continue;       int k = j - i + 1;       if (!p[k]) {         ans.push_back({i, j});         t = arr[i];         up(1, 0, x - 1, i, arr[j]);         up(1, 0, x - 1, j, t);       } else if (k % 2 == 0) {         if (p[j - i - vv[k].second + 1]) S++;         ans.push_back({i + vv[k].second, j});         t = arr[i + vv[k].second];         up(1, 0, x - 1, i + vv[k].second, arr[j]);         up(1, 0, x - 1, j, t);         if (p[i + vv[k].second + -i - 1 + 1]) S++;         ans.push_back({i + 1, i + vv[k].second});         t = arr[i + 1];         up(1, 0, x - 1, i + 1, arr[i + vv[k].second]);         up(1, 0, x - 1, i + vv[k].second, t);         if (p[i + 1 - i + 1]) S++;         ans.push_back({i, i + 1});         t = arr[i + 1];         up(1, 0, x - 1, i + 1, arr[i]);         up(1, 0, x - 1, i, t);       } else {         k++;         i--;         if (p[j - i - vv[k].second + 1]) S++;         ans.push_back({i + vv[k].second, j});         t = arr[i + vv[k].second];         up(1, 0, x - 1, i + vv[k].second, arr[j]);         up(1, 0, x - 1, j, t);         if (p[i + vv[k].second + -i - 1 + 1]) SS++;         ans.push_back({i + 1, i + vv[k].second});         t = arr[i + 1];         up(1, 0, x - 1, i + 1, arr[i + vv[k].second]);         up(1, 0, x - 1, i + vv[k].second, t);         i++;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (long long i = 2; i <= 100000; i++) {       if (!p[i]) {         v.push_back(i);         for (long long j = i * i; j <= 100000; j += i) p[j] = 1;       }     }     for (int i = 4; i <= 100000; i += 2) {       for (int j = 0; j < v.size(); j++) {         if (!p[i - v[j]]) {           vv[i] = {i - v[j], v[j]};           break;         }       }     }     arr[100001] = 1e10;     cin >> x;     for (int i = 0; i < x; i++) cin >> arr[i];     build(1, 0, x - 1);     int j = 0;     sort();     if (S != 0 || SS != 0) cout << S <<     << SS << endl;     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   using vv = vector<vector<T>>;   template <class T>   inline bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   const ll MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(0);     int n;     cin >> n;     string opes(n,  . );     vector<pii> clds(n);     for (int(i) = 0; (i) < (n); ++(i)) {       string s;       cin >> s >> clds[i].first;       if (s ==  IN ) {         opes[i] =  > ;         continue;       }       --clds[i].first;       if (s ==  NOT ) {         opes[i] =  ~ ;         continue;       }       cin >> clds[i].second;       --clds[i].second;       if (s ==  AND ) {         opes[i] =  & ;       } else if (s ==  OR ) {         opes[i] =  | ;       } else if (s ==  XOR ) {         opes[i] =  ^ ;       } else         return 1;     };     vector<int> vals(n);     {       function<int(int)> dfs = [&](int v) {         if (opes[v] ==  & ) {           vals[v] = dfs(clds[v].first) & dfs(clds[v].second);         } else if (opes[v] ==  | ) {           vals[v] = dfs(clds[v].first) | dfs(clds[v].second);         } else if (opes[v] ==  ^ ) {           vals[v] = dfs(clds[v].first) ^ dfs(clds[v].second);         } else if (opes[v] ==  ~ ) {           vals[v] = 1 - dfs(clds[v].first);         } else           vals[v] = clds[v].first;         return vals[v];       };       dfs(0);     };     string re(n, vals[0] +  0 );     ;     {       function<void(int)> dfs = [&](int v) {         if (opes[v] ==  & ) {           if (vals[clds[v].first]) dfs(clds[v].second);           if (vals[clds[v].second]) dfs(clds[v].first);         } else if (opes[v] ==  | ) {           if (!vals[clds[v].first]) dfs(clds[v].second);           if (!vals[clds[v].second]) dfs(clds[v].first);         } else if (opes[v] ==  ^ ) {           dfs(clds[v].first);           dfs(clds[v].second);         } else if (opes[v] ==  ~ ) {           dfs(clds[v].first);         } else           re[v] ^= 1;       };       dfs(0);     }     for (int(i) = 0; (i) < (n); ++(i))       if (opes[i] ==  > ) cout << re[i];     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1000000009;   const double eps = 1e-9;   const int mod = 1000000007;   int nos[100001], n, pos = 0;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) scanf( %d , &nos[i]);     sort(nos, nos + n);     for (int i = 0; i < n; ++i)       if (pos + 1 <= nos[i]) ++pos;     printf( %d n , pos + 1);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, qu;   int a[100011];   int st[100011], en[100011];   int pos[100011];   int rt[100011], nxt[100011];   int step[100011];   bool vis[100011];   vector<int> v[100011], vv;   queue<int> q;   void bunhae_interval() {     int r = n % m, mm = n / m;     st[0] = 1;     for (int i = 0; i < m; i++) {       if (i) st[i] = en[i - 1] + 1;       en[i] = st[i] + mm - 1;       if (i < r) en[i]++;       for (int j = st[i]; j <= en[i]; j++) pos[j] = i;     }   }   void update(int x) {     int p = pos[x];     for (int i = st[p]; i <= x; i++) vis[i] = 0;     vis[x] = 1;     q.push(x);     while (!q.empty()) {       int y = q.front();       q.pop();       for (int i = 0; i < v[y].size(); i++) {         int z = v[y][i];         if (vis[z]) continue;         vis[z] = 1;         step[z] = step[y] + 1;         rt[z] = rt[x];         q.push(z);       }     }   }   int main() {     scanf( %d %d , &n, &qu);     m = sqrt(n);     bunhae_interval();     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = n; i >= 1; i--) {       int j = i + a[i];       if (j > n || pos[j] != pos[i])         nxt[i] = j, rt[i] = i, step[i] = 0;       else         rt[i] = rt[j], step[i] = step[j] + 1, v[j].push_back(i);     }     while (qu--) {       int tp, x, y;       scanf( %d %d , &tp, &x);       if (tp == 1) {         int cnt = 1, en = x;         while (1) {           if (rt[en] == en) {             if (nxt[en] > n)               break;             else               cnt++, en = nxt[en];           } else {             cnt += step[en], en = rt[en];           }         }         printf( %d %d n , en, cnt);       } else {         int xx = x + a[x];         if (xx > n) goto la;         vv.clear();         for (int i = 0; i < v[xx].size(); i++)           if (v[xx][i] != x) vv.push_back(v[xx][i]);         v[xx].clear();         for (int i = 0; i < vv.size(); i++) v[xx].push_back(vv[i]);       la:;         scanf( %d , &y);         int z = x + y;         if (z > n || pos[z] != pos[x])           nxt[x] = z, rt[x] = x, step[x] = 0;         else           rt[x] = rt[z], step[x] = step[z] + 1, v[z].push_back(x);         a[x] = y;         update(x);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int powers[1000100];   vector<pair<int, int> > edges;   unsigned long long hashes[1000100] = {0};   unsigned long long ts[1000100] = {0};   int main(void) {     powers[0] = 1;     for (int i = 1; i <= 1000000; i++)       powers[i] = (powers[i - 1] * (unsigned long long)41) % 291598227841757;     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       hashes[u] = (hashes[u] + powers[v]) % 291598227841757;       hashes[v] = (hashes[v] + powers[u]) % 291598227841757;       ts[u - 1] = hashes[u];       ts[v - 1] = hashes[v];       edges.push_back(make_pair(u, v));     }     sort(ts, ts + n);     int cur = 0;     long long int ans = 0;     for (int i = 1; i < n; i++) {       if (ts[i] != ts[cur]) {         long long int n = i - cur;         ans += n * (n - 1) / 2;         cur = i;       }     }     long long int a = n - cur;     ans += a * (a - 1) / 2;     for (int i = 0; i < m; i++) {       int u = edges[i].first, v = edges[i].second;       unsigned long long hu = (hashes[u] + powers[u]) % 291598227841757;       unsigned long long hv = (hashes[v] + powers[v]) % 291598227841757;       if (hu == hv) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e5 + 1;   int n, m;   vector<int> adj[N];   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int rand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }   int d[N];   bool inq[N];   bool vis3[N];   bool ok = true;   void dfs3(int id) {     inq[id] = true;     vis3[id] = true;     for (auto x : adj[id]) {       if (!vis3[x]) {         dfs3(x);       } else if (!inq[x])         ok = false;     }     inq[id] = false;   }   bool arin(int x) {     for (int i = 1; i <= n; i++) vis3[i] = inq[i] = false;     ok = true;     dfs3(x);     return ok;   }   bool vis[N];   vector<int> ch[N];   int par[N];   int dx[N], dy[N];   int cs[N];   int up[N];   void dfs(int id) {     vis[id] = true;     up[id] = id;     for (auto x : adj[id]) {       if (!vis[x]) {         d[x] = d[id] + 1;         par[x] = id;         ch[id].push_back(x);         cs[id] = x;         dfs(x);       } else {         dx[x]--;         dx[id]++;         if (d[up[id]] > d[x]) up[id] = x;       }     }     for (auto x : ch[id]) {       if (d[up[x]] < d[up[id]]) up[id] = up[x];     }   }   int dfs4(int id) {     int duh = dx[id];     for (auto x : ch[id]) duh += dfs4(x);     dy[id] = duh;     return duh;   }   bool good[N];   int rt;   void dfs2(int id) {     if (dy[id] <= 1) good[id] = good[up[id]];     if (id == rt) good[id] = true;     for (auto x : ch[id]) {       dfs2(x);     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       adj[i].clear();       ch[i].clear();       dx[i] = dy[i] = 0;       good[i] = false;     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);     }     int x = 0;     for (int i = 1; i <= 100; i++) {       x = rand(n) + 1;       if (arin(x)) break;       x = 0;     }     if (x == 0) {       cout <<  -1 n ;       return;     }     for (int i = 1; i <= n; i++) vis[i] = false;     d[x] = 0;     dfs(x);     rt = x;     dfs4(x);     dfs2(x);     int cnt = 0;     for (int i = 1; i <= n; i++)       if (good[i]) cnt++;     if (cnt * 5 < n) {       cout <<  -1 n ;       return;     }     for (int i = 1; i <= n; i++)       if (good[i]) cout << i <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   const int maxN = 3e5 + 5;   int main() {     if (fopen( iput.txt ,  r )) {       freopen( iput.txt ,  r , stdin);       freopen( oput.txt ,  w , stdout);     }     int n;     scanf( %d , &n);     printf( %d n , n / 2 * 2 + n - n / 2);     printf( 2  );     for (int i = 4; i <= n; i += 2) printf( %d  , i);     for (int i = 1; i <= n; i += 2) printf( %d  , i);     for (int i = 2; i <= n; i += 2) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> st[200000 + 7];   set<int>::iterator it;   vector<int> graph[200000 + 7], edge[200000 + 7];   pair<int, int> edges[200000 + 7], path[200000 + 7];   int sid[200000 + 7], prio[200000 + 7], pr_id, can[200000 + 7], neg[200000 + 7],       rev[200000 + 7];   long long weg[200000 + 7], uwg[200000 + 7];   void dfs(int u, int edg) {     int v, ed;     long long wg = 0;     neg[u] = edg;     for (int i = 0; i < graph[u].size(); i++) {       v = graph[u][i];       ed = edge[u][i];       dfs(v, ed);       wg += weg[v];     }     if (u == 1) return;     prio[u] = ++pr_id;     rev[pr_id] = edg;     sid[u] = u;     st[u].insert(pr_id);     can[edg] = min(1LL * edges[edg].first - 1, edges[edg].second - wg);     if (can[edg] < 0) {       puts( -1 );       exit(0);     }     weg[u] = wg + edges[edg].first - can[edg];   }   void solve(int u) {     int v, id1, id2;     for (int i = 0; i < graph[u].size(); i++) {       v = graph[u][i];       solve(v);       uwg[u] += uwg[v];       id1 = sid[u];       id2 = sid[v];       if (st[id2].size() > st[id1].size()) swap(id1, id2);       for (it = st[id2].begin(); it != st[id2].end(); it++)         st[id1].insert(int(*it));       sid[u] = id1;     }     if (u == 1) return;     int temp;     while (uwg[u] > edges[neg[u]].second) {       temp = *st[sid[u]].begin();       temp = rev[temp];       if (uwg[u] - can[temp] >= edges[neg[u]].second) {         edges[temp].first -= can[temp];         edges[temp].second -= can[temp];         uwg[u] -= can[temp];         can[temp] = 0;         st[sid[u]].erase(st[sid[u]].begin());       } else {         int tpv = uwg[u] - edges[neg[u]].second;         edges[temp].first -= tpv;         edges[temp].second -= tpv;         uwg[u] -= tpv;         can[temp] -= tpv;       }     }     uwg[u] += edges[neg[u]].first;   }   int main() {     int n, u, v, w, p;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       scanf( %d %d , &edges[i].first, &edges[i].second);       edge[u].push_back(i);       graph[u].push_back(v);       path[i] = make_pair(u, v);     }     dfs(1, 0);     solve(1);     printf( %d n , n);     for (int i = 1; i < n; i++)       printf( %d %d %d %d n , path[i].first, path[i].second, edges[i].first,              edges[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }   const long long mod = 1e9 + 7;   inline signed rd() {     signed ans = 0;     char last =    , ch = getchar();     while (!(ch >=  0  && ch <=  9 )) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar();     if (last ==  - ) ans = -ans;     return ans;   }   inline long long QPow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline long long QPow(long long a, long long b, const long long &mod) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     long long d = a;     if (b == 0)       x = 1, y = 0;     else {       d = exgcd(b, a % b, y, x), y -= a / b * x;     }     return d;   }   const long double PI = 3.141592653589793115997963468544185161590576171875;   const long long maxn = 100005;   struct Req {     long long s, a, b;     bool friend operator<(const Req &a, const Req &b) {       return (a.b - a.a) > (b.b - b.a);     }   } reqs[maxn];   long long arr[maxn];   long long rarr[maxn];   long long cnt[maxn];   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t, m, n, R, s;     long long k;     cin >> n >> s;     for (long long i = 1; i <= n; i++) cin >> reqs[i].s >> reqs[i].a >> reqs[i].b;     long long ans = 0;     long long sum = 0;     for (long long i = 1; i <= n; i++)       ans += reqs[i].a * reqs[i].s, sum += reqs[i].s;     sort(reqs + 1, reqs + 1 + n);     for (long long i = 1; i <= n; i++)       arr[i] = reqs[i].b - reqs[i].a, cnt[i] = reqs[i].s;     for (long long i = 1; i <= n; i++) rarr[i] = arr[n - i + 1];     signed id = 1;     while (arr[id] > 0) id++;     id--;     long long tot = 0;     long long tmp = ans;     for (long long i = 1; i <= id; i++) {       tot += cnt[i];       tmp += arr[i] * cnt[i];     }     long long num = (tot + s - 1) / s;     num *= s;     long long tmp3 = tmp;     long long re = sum % s;     num -= tot;     num -= (s - re) % s;     for (long long i = id + 1; i <= n; i++) {       if (num <= 0) break;       long long tmp1 = min(num, cnt[i]);       num -= tmp1;       tmp3 += tmp1 * arr[i];       if (num <= 0) break;     }     num = (tot + s - 1) / s;     num *= s;     num -= s;     long long tmp4 = ans;     for (long long i = 1; i <= n; i++) {       if (num <= 0) break;       long long tmp2 = min(cnt[i], num);       num -= tmp2;       tmp4 += tmp2 * arr[i];       if (num == 0) break;     }     ans = max(ans, max(tmp4, tmp3));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a, b, ii;   int ans;   char ch[1500][1500];   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   int dp[1500][1500];   int p[100007];   void dfs(int x, int y) {     if (x > n || x < 1 || y > m || y < 1) return;     if (ch[x][y] ==  * ) {       ans++;       return;     }     if (dp[x][y] != 0) return;     dp[x][y] = ii;     for (int i = 0; i < 4; i++) {       int temp_x = x + dx[i];       int temp_y = y + dy[i];       dfs(temp_x, temp_y);     }     return;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch[i][j];       }     }     for (ii = 1; ii <= k; ii++) {       cin >> a >> b;       ans = 0;       if (!dp[a][b])         dfs(a, b);       else         ans = p[dp[a][b]];       p[ii] = ans;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     cin >> n >> m;     double mn = 101.00, x = 0.00;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       x = a / (b * 1.00);       if (mn > x) mn = x;     }     cout << fixed << setprecision(8);     cout << mn * m << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int B) { return (unsigned long long)rng() % B; }   inline double time() {     return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(                                    chrono::steady_clock::now().time_since_epoch())                                    .count()) *            1e-9;   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<string> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     vector<int> sum(m + 1);     for (int i = 0; i + 1 < m; i++) {       int u = 0;       for (int j = 1; j < n; j++) {         if (s[j][i] ==  X  and s[j - 1][i + 1] ==  X ) u = 1;       }       sum[i + 1] = sum[i] + u;     }     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       if (x == y) {         printf( YES n );         continue;       }       if (sum[y - 1] - sum[x - 1] > 0) {         printf( NO n );         continue;       } else {         printf( YES n );         continue;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, S, s, up, down, mid, mx, mn, a, b, k, l, r, ans, raod;   pair<long long, long long> p[300005];   int main() {     cin >> t;     while (t--) {       cin >> n >> S;       mn = 1e10;       mx = 0;       for (k = 1; k <= n; k++) {         cin >> a >> b;         p[k].first = a;         mn = min(mn, a);         p[k].second = b;         mx = max(mx, b);       }       ans = 0;       sort(p + 1, p + n + 1);       l = mn;       r = mx;       while (l <= r) {         long long mid = (l + r + 1) / 2;         up = 0;         down = 0;         s = 0;         for (k = 1; k <= n; k++)           if (p[k].first > mid)             up++;           else if (p[k].second < mid)             down++;         if (up >= n / 2 + 1) {           l = mid + 1;         } else if (down >= n / 2 + 1)           r = mid - 1;         else {           raod = 0;           for (k = n; k >= 1; k--) {             if (raod <= n / 2 & p[k].second >= mid) {               raod++;               s += max(mid, p[k].first);             } else               s += p[k].first;           }           if (s <= S) {             ans = mid;             l = mid + 1;           } else             r = mid - 1;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = 100 * 1000 + 5;   int a[maxn];   int b[maxn];   int main() {     int t;     cin >> t;     int n, f1, fm1;     for (int i = 0; i < t; i++) {       f1 = maxn;       fm1 = maxn;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> a[j];         if (a[j] == 1 && f1 == maxn) f1 = j;         if (a[j] == -1 && fm1 == maxn) fm1 = j;       }       bool check = true;       for (int j = 0; j < n; j++) {         cin >> b[j];       }       for (int j = n - 1; j >= 0; j--) {         if (j > 0) {           if (a[j] < b[j] && f1 >= j) check = false;           if (a[j] > b[j] && fm1 >= j) check = false;         } else {           if (a[j] != b[j]) check = false;         }         if (!check) break;       }       if (check)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long k, i, j, b = 1;     string s =  codeforces ;     vector<int> a(10, 1);     cin >> k;     for (; b < k;)       for (i = 0; i < 10; i++) {         b /= a[i];         ++a[i];         b = b * a[i];         if (b > k - 1) break;       }     for (i = 0; i < 10; i++)       for (j = 0; j < a[i]; j++) cout << s[i];     cout <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int dp[502][502][2], n, m;   char str[502][502];   int dis;   int check(int x, int y) {     if (x < 0 or x >= n and y < 0 or y >= m)       return 0;     else       return 1;   }   int call(int x, int y, int a, int idx) {     int ham = x + y;     int paisi = n - 1 - a;     int baki = ham - paisi;     int b = m - 1 - baki;     if (check(x, y) == 0 or check(a, b) == 0) return dp[x][y][a & 1] = 0;     if (str[x][y] != str[a][b]) return dp[x][y][a & 1] = 0;     if (idx == 0) return dp[x][y][a & 1];     int dx = ((x - a) < 0 ? -(x - a) : (x - a));     int dy = ((y - b) < 0 ? -(y - b) : (y - b));     if (dis % 2 == 0) {       if (ham + 1 > dis / 2) return dp[x][y][a & 1] = 0;       if (ham + 1 == dis / 2) return dp[x][y][a & 1] = (dx + dy <= 1);     } else {       if (ham > dis / 2) return dp[x][y][a & 1] = 0;       if (ham == dis / 2) return dp[x][y][a & 1] = (x == a and y == b);     }     long long ret = 0;     ret += call(x + 1, y, a, 1 - idx);     ret += call(x + 1, y, a - 1, 1 - idx);     ret += call(x, y + 1, a, 1 - idx);     ret += call(x, y + 1, a - 1, 1 - idx);     return dp[x][y][a & 1] = ret % MOD;   }   int main() {     scanf( %d %d , &n, &m);     dis = n + m - 1;     for (int i = 0; i < n; i++) scanf( %s , str[i]);     for (int a = 0; a < n; a++) {       for (int y = m - 1; y >= 0; y--) {         int tempx = n - 1;         int tempy = y;         while (tempx >= 0 and tempy < m) {           call(tempx, tempy, a, 1);           tempy++;           tempx--;         }       }       for (int x = n - 2; x >= 0; x--) {         int tempx = x;         int tempy = 0;         while (tempx >= 0 and tempy < m) {           call(tempx, tempy, a, 1);           tempy++;           tempx--;         }       }     }     printf( %d n , dp[0][0][(n - 1) & 1]);   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 500500;   int n, k;   vector<pair<int, int> > g[N];   long long dp[N], W[N];   void dfs(int v, int pr = -1) {     dp[v] = 0;     vector<long long> u;     for (auto to : g[v]) {       if (to.first == pr) continue;       dfs(to.first, v);       dp[v] += dp[to.first] + W[to.first];       if (-W[to.first] + to.second > 0) u.push_back(-W[to.first] + to.second);     }     sort(u.begin(), u.end());     reverse(u.begin(), u.end());     for (int i = 0; i < min(k - 1, (int)u.size()); ++i) dp[v] += u[i];     if (k <= (int)u.size())       W[v] = u[k - 1];     else       W[v] = 0;   }   void solve() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) g[i].clear();     for (int i = 1; i < n; ++i) {       int x, y, w;       cin >> x >> y >> w;       g[x].push_back(make_pair(y, w));       g[y].push_back(make_pair(x, w));     }     dfs(1);     cout << dp[1] + W[1] << endl;   }   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     int count = 0;     for (int a = 1; a <= n; a++) {       for (int b = a; b <= n; b++) {         int k = a * a + b * b;         int c = sqrt(k);         if (c * c == k && c <= n) count++;       }     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 500031;   int tests, n, k;   vector<pair<int, int> > g[N];   int used[N];   long long dp[N][2];   void dfs(int v) {     used[v] = 1;     long long guaranteed = 0;     vector<long long> benefits;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i].first;       int cost = g[v][i].second;       if (used[to] == 1) continue;       dfs(to);       long long without_edge = max(dp[to][0], dp[to][1]);       long long with_edge = dp[to][0] + cost;       guaranteed += without_edge;       long long benefit_here = with_edge - without_edge;       if (benefit_here < 0) benefit_here = 0;       benefits.push_back(benefit_here);     }     sort(benefits.begin(), benefits.end());     reverse(benefits.begin(), benefits.end());     long long S = 0;     for (int i = 0; i < k - 1 && i < benefits.size(); i++) {       S += benefits[i];     }     dp[v][0] = guaranteed + S;     S = 0;     for (int i = 0; i < k && i < benefits.size(); i++) {       S += benefits[i];     }     dp[v][1] = guaranteed + S;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> tests;     for (; tests; --tests) {       cin >> n >> k;       for (int i = 1; i <= n; i++) {         g[i].clear();         used[i] = 0;       }       for (int i = 1; i < n; i++) {         int a, b, c;         cin >> a >> b >> c;         g[a].push_back(make_pair(b, c));         g[b].push_back(make_pair(a, c));       }       dfs(1);       cout << max(dp[1][0], dp[1][1]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   int map[525][525];   int note[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};   int main() {     int time = 0, size = 1, i, j, head, tail;     map[1][1] = 1;     while (time != 9) {       time++;       head = size + 1;       tail = 2 * size;       for (i = 1; i <= size; i++)         for (j = head; j <= tail; j++) map[i][j] = map[i][j - size];       for (i = head; i <= tail; i++)         for (j = 1; j <= size; j++) map[i][j] = map[i - size][j];       for (i = head; i <= tail; i++)         for (j = head; j <= tail; j++) map[i][j] = -map[i - size][j - size];       size *= 2;     }     int k;     scanf( %d , &k);     for (i = 1; i <= note[k]; i++) {       for (j = 1; j <= note[k]; j++)         if (map[i][j] == 1)           printf( + );         else           printf( * );       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tichnas;     cin >> tichnas;     while (tichnas--) {       long long n, c, m, maxs = 1e9, temp, ans;       map<long long, long long> type;       bool possible;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> c;         type[c]++;       }       for (auto it = type.begin(); it != type.end(); it++)         maxs = min(maxs, it->second + 1);       ans = n;       for (int i = 2; i <= maxs; i++) {         possible = true;         m = 0;         for (auto it = type.begin(); it != type.end() && possible; it++) {           temp = it->second;           if (temp % i == 0)             m += temp / i;           else if (i - 1 - temp % i <= temp / i)             m += temp / i + 1;           else             possible = false;         }         if (possible) ans = m;       }       cout << ans <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define imin INT_MIN   #define imax INT_MAX   #define br   n    #define sp       #define pie 3.141592653589793238462643383279   #define lower(sl) transform(sl.begin(), sl.end(), sl.begin(), ::tolower);   #define upper(sl) transform(sl.begin(), sl.end(), sl.begin(), ::toupper);   #define fo(i, n) for(int (i)=0;(i)<n;(i)++)   #define rfo(i, n) for(int (i)=n-1;(i)>=0;(i)--)   #define forl(i,a,n) for(int (i)=a;(i)<n;(i)++)   #define forr(i,a,n) for(int (i)=n-1;(i)>=a;(i)--)   #define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)   #define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it++)   #define popcount(x) __builtin_popcount(x)  // count the number of one’s(set bits) in an integer.   #define popcountll(x) __builtin_popcountll(x)   #define clz(x) __builtin_clz(x)   // count the leading zeros(binary representation) of the integer   #define clzll(x) __builtin_clzll(x)   #define ctz(x) __builtin_ctz(x)   // count the trailing zeros(binary representation) of the integer   #define ctzll(x) __builtin_ctzll(x)   #define pb push_back   #define mp make_pair   #define F first   #define S second   #define gcd __gcd   #define lcm(a,b) ((a)*(b))/gcd(a,b)   #define deci(n) fixed << setprecision(n)   #define all(x) x.begin(),x.end()   #define max3(a,b,c) max(max(a,b),c)   #define min3(a,b,c) min(min(a,b),c)   #define max4(a,b,c,d) max(a,max3(b,c,d))   #define min4(a,b,c,d) min(a,min3(b,c,d))   #define max5(a,b,c,d,e) max(max4(a,b,c,d),e)   #define min5(a,b,c,d,e) min(min4(a,b,c,d),e)   typedef pair<int, int> pii;   typedef pair<ll, ll> pl;   typedef pair<double, double> pd;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<pii> vpii;   typedef vector<pl> vpl;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef priority_queue<int, vector<int>, greater<int>> minpq;   typedef priority_queue<int> pq;   typedef unordered_map<int,int> umii;   typedef map<int,int> mii;   typedef set<int> si;   typedef deque<int> di;   typedef queue<int> qi;   const int max_n = 1e6 + 1;   const int mod = 1e9 + 7;   const int inf = 1e9;   const ll linf = 1e18;   const int wmod = 998244353;      int midofthree(int a,int b,int c){       if((a<=b and a>=c) or (a<=c and a>=b))           return a;       else if((b>=a and b<=c) or (b<=a and b>=c))           return b;       return c;   }      bool isPowerTwo(int x){     return (x && !(x & (x-1)));    }      bool ispalindrome(string s){       ll len=s.length();        fo(i, len){            if(s[i]!=s[len-i-1])           return false;        }        return true;    }       bool isSubstring(string s1, string s2){       if(s1.find(s2) != string::npos) return true;           return false;   }      int sum_of_digits(int x){       int sum = 0;       while (x > 0)       {           sum += x % 10;           x /= 10;       }       return sum;   }      int num_of_digits(int x){       return floor(log10(x) + 1);   }          int binaryToDecimal(int n){       int num = n;       int dec_value = 0;       int base = 1;       int temp = num;       while (temp){           int last_digit = temp % 10;           temp = temp / 10;           dec_value += last_digit * base;           base = base * 2;       }       return dec_value;   }      int isvowel(char x){       if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u )           return 1;       return 0;   }      int isconsonant(char x){       if (x !=  a  && x !=  e  && x !=  i  && x !=  o  && x !=  u )           return 1;       return 0;   }      // Check if n is a prime in O(sqrt(n/6))   bool isPrime(int n){    if(n<=1)return 0;    if(n<=3)return 1;    if(n%2==0 or n%3==0)return 0;    for(int i=5;i*i<=n;i+=6){     if(n%i==0 or n%(i+2)==0)return 0;    }    return 1;   }      // Generate the all primes <= n in O(nlog(logn))   vi sieve(int n){       vi primes, isprime(n + 1, 1);       for (int i = 2; i * i <= n; i++)           if (isprime[i])               for (int j = i + i; j <= n; j += i)                   isprime[j] = 0;       for (int i = 2; i <= n; i++)           if (isprime[i])               primes.push_back(i);       return primes;   }      vi factorize(int n){       vi res;       for (int i = 2; i * i <= n; ++i){           while (n % i == 0){               res.push_back(i);               n /= i;           }       }       if (n != 1){           res.push_back(n);       }       return res;   }      // Iteratively finding (x^n)(mod M) (slightly faster)   int modularExponentiation(int x,int n,int M){       int result=1;       while(n>0){           if(n % 2 ==1){               result=(result * x)%M;}           x=(x*x)%M;           n = n>>1;       }       return result;   }      //  calculationg exponential in logn    int binaryExponentiation(int x,int n){       int result=1;       while(n>0){           if(n % 2 ==1){               result=result * x;}           x=x*x;           n=n/2;       }       return result;   }      int modInverse(int a, int m){       int m0 = m,y = 0, x = 1;        if (m == 1)            return 0;        while (a > 1) {            int q = a / m;            int t = m;            m = a % m, a = t;            t = y;            y = x - q * y;            x = t;}       if (x < 0)            x += m0;        return x;    }       ll factorial(int n){       if(n==1 || n==0){           return 1;       }       else{           return n*factorial(n-1);       }   }      #define MAX 1000   // Function to find the factorial of large number    // and return them in string format    string longfactorial(int n){       long long counter;        long double sum = 0;        if (n == 0)            return  1 ;        for (counter = 1; counter <= n;            counter++) {            sum = sum + log(counter);        }        string result = to_string(round(exp(sum)));        return result;    }      ll NcR(int n,int m){       ll z=1;       for(int i=0;i<m;i++)           z=z*(n-i)/(i+1);       return z;   }      void fillPrefixSum(int arr[], int n, int prefixSum[]){        prefixSum[0] = arr[0];       for (int i = 1; i < n; i++)            prefixSum[i] = prefixSum[i - 1] + arr[i];    }      /* ========== YOUR CODE HERE ========= */   void solution(){         // 0xAAAAAAAA=even bits set to 1 ; 0x55555555 = odd bits set to 1       // int prefixSuma[n];       // fillPrefixSum(a, n, prefixSuma);          // int n;         // cin>>n;       // int a[n];       // fo(i,n){       //     cin>>a[i];       // }       int w,h,n;       cin>>w>>h>>n;       if(n==1){           cout<< YES <<br;       }       else{           int c=1,a=0;           int t1=1, t2=1;           while(w%2==0){               c = 2*c;               w/=2;           }           while(h%2==0){               c*=2;               h/=2;           }           if(c>=n){               cout<< YES <<br;           }           else{               cout<< NO <<br;           }       }      }   /* ========== YOUR CODE HERE ========= */      int main(){       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       srand(chrono::high_resolution_clock::now().time_since_epoch().count());          int testcase = 1;       cin>>testcase;       while(testcase--) {           solution();       }       return 0;   }   // By Ashwani Kumar, Indian Institute Of Technology(IIT), Guwahati.


#include <bits/stdc++.h>   using namespace std;   int pgcd(int a, int b) {     if (a == 0) return b;     return pgcd(b % a, a);   }   int nbNombres;   int vals[300 * 1000];   int minRange[20][300 * 1000];   int pgcdRange[20][300 * 1000];   vector<int> possibles(int taille) {     vector<int> sol;     int etage = __builtin_log2(taille);     int pseudo = (1 << etage);     for (int iDebut = 0; iDebut + taille <= nbNombres; iDebut++) {       int mini =           min(minRange[etage][iDebut], minRange[etage][iDebut + taille - pseudo]);       int pg = pgcd(pgcdRange[etage][iDebut],                     pgcdRange[etage][iDebut + taille - pseudo]);       if (mini == pg) sol.push_back(iDebut);     }     return sol;   }   int main() {     cin >> nbNombres;     for (int iNombre = 0; iNombre < nbNombres; iNombre++) {       cin >> vals[iNombre];       minRange[0][iNombre] = vals[iNombre];       pgcdRange[0][iNombre] = vals[iNombre];     }     for (int iPuis = 1; iPuis < 20; iPuis++) {       int curPuis = (1 << iPuis), derPuis = (1 << (iPuis - 1));       for (int iPos = 0; iPos + curPuis <= nbNombres; iPos++) {         minRange[iPuis][iPos] =             min(minRange[iPuis - 1][iPos], minRange[iPuis - 1][iPos + derPuis]);         pgcdRange[iPuis][iPos] = pgcd(pgcdRange[iPuis - 1][iPos],                                       pgcdRange[iPuis - 1][iPos + derPuis]);       }     }     int debut = 0, fin = nbNombres + 1;     while (debut + 1 < fin) {       int mil = (debut + fin) / 2;       if (!possibles(mil).empty()) {         debut = mil;       } else {         fin = mil;       }     }     vector<int> sol = possibles(debut);     cout << sol.size() <<     << debut - 1 << endl;     for (int val : sol) {       cout << val + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, g = 0, h = 0, i = 0, j, k, l, p = 0;     cin >> a >> b >> c >> d >> e >> f;     g = a - d;     h = b - e;     i = c - f;     if (g > 0) {       j = g / 2;     } else {       j = 0;     }     if (h > 0) {       k = h / 2;     } else {       k = 0;     }     if (i > 0) {       l = i / 2;     } else {       l = 0;     }     if (g >= 0) {       p = p + j;     } else {       p = p + g;     };     if (h >= 0) {       p = p + k;     } else {       p = p + h;     }     if (i >= 0) {       p = p + l;     } else {       p = p + i;     }     if (p >= 0) {       cout <<  Yes ;     } else {       cout <<  No ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, sum = 0;     scanf( %d , &n);     if (n == 1) sum = 1;     if (n == 2) sum = 5;     if (n == 3) sum = 13;     if (n >= 4) {       for (i = 4; i <= n; i++) {         sum = sum + i * i - (i - 2) * (i - 2);       }       sum = sum + 13;     }     printf( %d , sum);   }


#include <bits/stdc++.h>      typedef long long int ll;   typedef long double ld;   typedef unsigned long long ull;      #define RESET(a, b) memset(a, b, sizeof(a))   int INF = 1000000005;   long long INFF = 1000000000000000005LL;      using namespace std;         struct monster {       ll health, attack_power;   };      int main() {                ll t;       cin>>t;       while(t--)       {           ll a,b;           cin>>a>>b;           ll ans=INFF;           if(a==1)           {               if(b!=1)               {                   cout<<1<<endl;               }               else               {                   cout<< 2 n ;               }               continue;           }           if(b>a)           {               cout<< 1 n ;               continue;           }                    for(int i=0;i<=100000;i++)           {               ll x=b+i;               ll y=a;               ll cnt=i;               bool ok=0;               while(y and x!=1)               {                   ok=1;                   y=y/x;                   cnt++;               }                  //cout<<x<<endl;               if(ok)ans=min(ans,cnt);           }           cout<<ans<<endl;             }                //ctime;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int upd[400000][10];   long long val[400000][10];   bool dirty[400000];   void clean(int n, int l, int r) {     long long buf[10];     memset(buf, 0, sizeof buf);     for (int i = 0; i < 10; i++) {       buf[upd[n][i]] += val[n][i];     }     dirty[n] = false;     for (int i = 0; i < 10; i++) {       val[n][i] = buf[i];     }     if (l < r) {       dirty[n * 2] = dirty[n * 2 + 1] = true;       for (int i = 0; i < 10; i++) {         upd[n * 2][i] = upd[n][upd[n * 2][i]];         upd[n * 2 + 1][i] = upd[n][upd[n * 2 + 1][i]];       }     }     for (int i = 0; i < 10; i++) {       upd[n][i] = i;     }   }   long long get(int rl, int rr, int n = 1, int l = 0, int r = 100000) {     if (l > rr || r < rl) return 0;     if (dirty[n]) clean(n, l, r);     if (l >= rl && r <= rr) {       long long ans = 0;       for (int i = 0; i < 10; i++) {         ans += val[n][i] * i;       }       return ans;     }     long long ans = get(rl, rr, n * 2, l, (l + r) / 2);     ans += get(rl, rr, n * 2 + 1, (l + r) / 2 + 1, r);     return ans;   }   void update(int rl, int rr, int from, int to, int n = 1, int l = 0,               int r = 100000) {     if (l > rr || r < rl) {       clean(n, l, r);       return;     }     if (dirty[n]) clean(n, l, r);     if (l >= rl && r <= rr) {       for (int i = 0; i < 10; i++) {         if (upd[n][i] == from) upd[n][i] = to;       }       dirty[n] = true;       clean(n, l, r);       return;     }     update(rl, rr, from, to, n * 2, l, (l + r) / 2);     update(rl, rr, from, to, n * 2 + 1, (l + r) / 2 + 1, r);     for (int i = 0; i < 10; i++) {       val[n][i] = val[n * 2][i] + val[n * 2 + 1][i];     }   }   int n, q;   int arr[100000];   void build(int n = 1, int l = 0, int r = 100000) {     for (int i = 0; i < 10; i++) upd[n][i] = i;     if (l == r) {       if (l < n) {         int mul = 1;         int c = arr[l];         while (c) {           val[n][c % 10] += mul;           c /= 10;           mul *= 10;         }       }       return;     }     build(n * 2, l, (l + r) / 2);     build(n * 2 + 1, (l + r) / 2 + 1, r);     for (int i = 0; i < 10; i++) {       val[n][i] = val[n * 2][i] + val[n * 2 + 1][i];     }   }   void printtree() {     for (int i = 0; i < n; i++) {       cout << get(i, i) <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     build();     for (int i = 0; i < q; i++) {       int t, l, r, x, y;       cin >> t;       if (t == 1) {         cin >> l >> r >> x >> y;         update(l - 1, r - 1, x, y);       } else {         cin >> l >> r;         cout << get(l - 1, r - 1) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string ans;     string t;     for (int i = 0; i < n; i++) {       cin >> t;       if (i == 0) {         ans = t;         continue;       }       for (int j = 0; j < t.size(); j++)         if (ans[j] ==  ? )           ans[j] = t[j];         else if (ans[j] == t[j] || t[j] ==  ? )           ans[j] = ans[j];         else           ans[j] =  . ;     }     for (int i = 0; i < ans.size(); i++)       if (ans[i] ==  . )         ans[i] =  ? ;       else if (ans[i] ==  ? )         ans[i] =  a ;     ios_base::sync_with_stdio(false);     printf( %s , ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};   const int N = 212345;   int n, m, q, p[N], a[N];   int f[N], g[N], last[N];   vector<int> loc[N];   int maxm[N];   int my_find(int id, int val) {     int l = 0, r = loc[id].size();     while (l < r) {       int mid = l + (r - l) / 2;       int x = loc[id][mid];       if (f[x] > val)         r = mid;       else         l = mid + 1;     }     if (l == loc[id].size())       return m + 1;     else       return loc[id][l];   }   int tmin[N * 4];   void build(int o, int l, int r) {     if (l == r)       tmin[o] = maxm[l];     else {       int mid = l + (r - l) / 2;       build(o * 2, l, mid);       build(o * 2 + 1, mid + 1, r);       tmin[o] = min(tmin[o * 2], tmin[o * 2 + 1]);     }   }   const int INF = int(1e9);   int query(int o, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       return tmin[o];     } else {       int mid = l + (r - l) / 2;       int lmax = INF, rmax = INF;       if (ql <= mid) lmax = query(o * 2, l, mid, ql, qr);       if (qr > mid) rmax = query(o * 2 + 1, mid + 1, r, ql, qr);       return min(lmax, rmax);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       p[x] = i;     }     for (int i = 1; i <= m; i++) {       cin >> a[i];       a[i] = p[a[i]];       loc[a[i]].push_back(i);     }     for (int i = 1; i <= n; i++) sort((loc[i]).begin(), (loc[i]).end());     for (int i = 1; i <= m; i++) {       last[a[i]] = i;       if (a[i] == 1)         f[i] = i;       else         f[i] = f[last[a[i] - 1]];     }     for (int i = 1; i <= n; i++) last[i] = m + 1;     g[m + 1] = m + 1;     for (int i = m; i >= 1; i--) {       last[a[i]] = i;       if (a[i] == n)         g[i] = i;       else         g[i] = g[last[a[i] + 1]];     }     for (int i = 1; i <= m; i++) {       if (a[i] == 1)         maxm[i] = g[i];       else         maxm[i] = my_find(a[i] - 1, g[i]);     }     build(1, 1, m);     string ans;     while (q--) {       int l, r;       cin >> l >> r;       if (query(1, 1, m, l, r) <= r)         ans.push_back( 1 );       else         ans.push_back( 0 );     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2050;   int p[N], id[N], rmd[N], P[N], n;   int qry(vector<int> vec) {     cout <<  ?   << vec.size() <<    ;     for (auto t : vec) cout << t <<    ;     cout << endl, fflush(stdout);     int ok;     cin >> ok;     return ok;   }   int query(int x) {     vector<int> vec;     for (int i = 1; i <= n; ++i)       if (!p[i] && x != i) vec.push_back(i);     return qry(vec);   }   void query(int x, int y, int xx, int yy) {     for (int i = 1; i <= n; ++i)       if (!id[x] && !p[i] && rmd[i] == y) {         if (query(i)) id[x] = i;       } else if (!id[xx] && !p[i] && rmd[i] == yy)         if (query(i)) id[xx] = i;     p[id[x]] = x, p[id[xx]] = xx;   }   int main() {     cin >> n;     query(1, 0, n, 0);     for (int t = 2, l = 2, r = n - 1; l <= r; t <<= 1) {       for (int i = 1; i <= n; ++i)         if (!p[i]) {           vector<int> vec;           for (int j = 1; j <= t; ++j)             if (j % t != rmd[i]) vec.push_back(id[j]);           vec.push_back(i);           if (qry(vec)) rmd[i] += t >> 1;         }       while (l <= 2 * t && l <= r) query(l, l % t, r, r % t), ++l, --r;     }     if (p[1] * 2 > n)       for (int i = 1; i <= n; ++i) p[i] = n - p[i] + 1;     cout <<  !  ;     for (int i = 1; i <= n; ++i) cout << p[i] <<    ;     cout << endl, fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   const bool TEST = 0;   const int inf = 0x7fffffff;   using namespace std;   template <typename T>   void pA(T *begin, int n) {     for (int i = 0; i < n; i++) {       cout << *(begin++);     }     printf(  n );   }   const char cho[4] = { R ,  B ,  Y ,  G };   vector<unsigned int> fAns;   bool flag = 0;   bool check(string s, vector<unsigned int> ans) {     if (flag) return 0;     if (TEST) cout << s << endl;     ;     for (int c = 0; c < 4; c++) {       int pre = -4;       for (unsigned int i = 0; i < s.size(); i++) {         if (s[i] ==  ! ) {           if (c == 3)             return 1;           else             continue;         }         if (s[i] == cho[c]) {           if (i - pre >= 4) {             pre = i;           } else             return false;         }       }     }     fAns = ans;     flag = 1;     return 0;   }   int cor(char x) {     switch (x) {       case  R :         return 0;       case  B :         return 1;       case  Y :         return 2;       case  G :         return 3;     }     return 30;   }   void count(string s, vector<unsigned int> ans) {     if (TEST) cout <<  int count  << s << endl;     int sum = 0;     for (unsigned int i = 0; i < 4; i++) {       sum += cor(s[i]);     }     if (sum != 6) return;     for (unsigned int i = 4; i < s.size(); i++) {       if (s[i] ==  ! ) {         ans[cor(s[i - 4])]++;       }     }     fAns = ans;   }   void dfs(unsigned int st, unsigned int curTol, const string s,            vector<unsigned int> ans) {     bool val = 0;     val = check(s, ans);     if (!val) return;     if (st == 4) {       count(s, ans);     }     if (TEST) cout << val << endl;     for (unsigned int i = st; i < 4; i++) {       if (s[i] ==  ! ) {         for (int c = 0; c < 4; c++) {           string s2 = s;           s2[i] = cho[c];           ans[c]++;           dfs(i + 1, curTol + 1, s2, ans);           ans[c]--;         }         return;       }     }     count(s, ans);   }   void sol() {     string s;     cin >> s;     for (int i = 0; i < 4; i++) {       fAns.push_back(0);     }     dfs(0, 0, s, fAns);     for (int i = 0; i < 4; i++) {       if (0 != i) cout <<    ;       cout << fAns[i];     }     cout << endl;   }   void sol2() {     string s;     cin >> s;     for (int i = 0; i < 4; i++) {       fAns.push_back(0);     }     for (int c = 0; c < 4; c++) {       char x = cho[c];       unsigned int pos = s.find_first_of(x);       pos %= 4;       for (unsigned int i = pos; i < s.size(); i += 4) {         if ( !  == s[i]) fAns[cor(x)]++;       }     }     for (int i = 0; i < 4; i++) {       if (0 != i) cout <<    ;       cout << fAns[i];     }     cout << endl;   }   int main() {     sol2();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 1e5 + 10;   long long n, m, a[mx], cnt[mx], r[mx], l[mx], p[mx], ans[mx];   int main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < mx) cnt[a[i]]++;     }     for (long long i = 0; i < m; i++) cin >> l[i] >> r[i];     for (long long in = 1; in < mx; in++) {       if (cnt[in] >= in) {         p[0] = 0;         for (long long i = 1; i <= n; i++) p[i] = p[i - 1] + (a[i] == in);         for (long long i = 0; i < m; i++)           ans[i] += ((p[r[i]] - p[l[i] - 1]) == in);       }     }     for (long long i = 0; i < m; i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[1000010];   char b[1000010];   int main() {     cin >> a;     int ind = 0;     int ans = 0;     int n = strlen(a);     for (int i = 0; i < n; i++) {       if (a[i] ==  [  || a[i] ==  <  || a[i] ==  (  || a[i] ==  { ) {         b[ind] = a[i];         ind++;       } else {         ind--;         if (ind < 0) {           cout <<  Impossible ;           return 0;         }         if (b[ind] ==  [  && a[i] !=  ] ) {           ans++;         } else if (b[ind] ==  <  && a[i] !=  > )           ans++;         else if (b[ind] ==  {  && a[i] !=  } )           ans++;         else if (b[ind] ==  (  && a[i] !=  ) )           ans++;       }     }     if (ind > 0)       cout <<  Impossible ;     else       cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);     x *= f;   }   inline void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar((x % 10) ^ 48);   }   inline void write(int x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   int n, ans[5], head[1000050], tot, mx[1000050], mx1[1000050], p, dep[1000050],       d, vis[1000050], f[1000050];   struct edge {     int to, nxt;   } e[1000050 << 1];   void ins(int u, int v) { e[++tot] = (edge){v, head[u]}, head[u] = tot; }   void dfs(int x, int fa) {     dep[x] = dep[fa] + 1;     int cnt = 0;     f[x] = fa;     for (int i = head[x]; i; i = e[i].nxt)       if (e[i].to != fa && !vis[e[i].to]) {         dfs(e[i].to, x), cnt++;         if (!mx[x] || dep[mx[x]] < dep[mx[e[i].to]])           mx1[x] = mx[x], mx[x] = mx[e[i].to];         else if (dep[mx[e[i].to]] > dep[mx1[x]])           mx1[x] = mx[e[i].to];       }     if (!cnt) mx[x] = x;     if (cnt >= 2) {       if (dep[x] > d)         d = dep[x], p = x;       else if (dep[x] == d && dep[mx1[x]] + dep[mx[x]] > dep[mx1[p]] + dep[mx[p]])         p = x;     }   }   int main() {     read(n);     for (int i = 1, x, y; i < n; i++) read(x), read(y), ins(x, y), ins(y, x);     dfs(1, 0), ans[1] = mx[p], ans[3] = mx1[p];     for (int i = head[p]; i; i = e[i].nxt)       if (e[i].to != f[p] && (mx[e[i].to] == mx[p] || mx[e[i].to] == mx1[p]))         vis[e[i].to] = 1;     memset(mx, 0, sizeof mx), memset(mx1, 0, sizeof mx1);     d = 0;     dfs(p, 0), ans[2] = mx[p], ans[4] = mx1[p];     printf( %d %d n%d %d n , ans[1], ans[2], ans[3], ans[4]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string st[n];     int a[m];     for (int i = 0; i < n; i++) {       cin >> st[i];     }     for (int i = 0; i < m; i++) {       cin >> a[i];     }     int maxa = 0;     int ca, cb, cc, cd, ce;     for (int i = 0; i < m; i++) {       ca = 0;       cb = 0;       cc = 0;       cd = 0;       ce = 0;       for (int j = 0; j < n; j++) {         if (st[j][i] ==  A ) ca++;         if (st[j][i] ==  B ) cb++;         if (st[j][i] ==  C ) cc++;         if (st[j][i] ==  D ) cd++;         if (st[j][i] ==  E ) ce++;       }       int x1 = max(ca, cb);       int x2 = max(cc, cd);       int x3 = max(max(x1, x2), ce);       maxa += x3 * a[i];     }     cout << maxa << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   inline int getInt() {     int x;     scanf( %d , &x);     return x;   }   inline long long getLL() {     long long x;     scanf( %lld , &x);     return x;   };   inline int NUM(char c) { return (int)c - 48; }   inline char CHR(int n) { return (char)(n + 48); }   template <class T>   inline T MAX(T a, T b) {     if (a > b) return a;     return b;   }   template <class T>   inline T MIN(T a, T b) {     if (a < b) return a;     return b;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int N;   int A[100000 + 5];   int sorted[100000 + 5];   map<int, stack<int> > MAP;   int pos[100000 + 5];   int idx = -1;   inline bool islucky(int x) {     if (x == 0) return false;     while (x) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   vector<pair<int, int> > sol;   stack<int> tumpuk;   bool found[100000 + 5];   inline int jelajah(int i) {     found[i] = true;     int root = i;     while (pos[i] != root) {       sol.push_back(make_pair(i, pos[i]));       i = pos[i];       found[i] = true;     }     return i;   }   int main() {     scanf( %d , &N);     for (int i = 0, _n = (N); i < _n; i++) {       scanf( %d , &A[i]);       if (islucky(A[i])) idx = i;       sorted[i] = A[i];     }     sort(sorted, sorted + N);     bool so = true;     for (int i = 0, _n = (N); i < _n; i++) {       if (A[i] != sorted[i]) {         so = false;       }     }     if (idx == -1 && !so) {       puts( -1 );       return 0;     } else if (idx == -1) {       puts( 0 );       return 0;     }     for (int i = (N)-1; i >= 0; i--) {       MAP[sorted[i]].push(i);     }     for (int i = 0, _n = (N); i < _n; i++) {       int x = A[i];       A[i] = MAP[x].top();       MAP[x].pop();       pos[A[i]] = i;     }     idx = jelajah(idx);     for (int i = 0, _n = (N); i < _n; i++) {       if (!found[i]) {         tumpuk.push(idx);         sol.push_back(make_pair(idx, i));         idx = jelajah(i);       }     }     while ((tumpuk).size() > 0) {       sol.push_back(make_pair(idx, tumpuk.top()));       idx = tumpuk.top();       tumpuk.pop();     }     printf( %d n , (sol).size());     for (int i = 0, _n = ((sol).size()); i < _n; i++) {       printf( %d %d n , sol[i].first + 1, sol[i].second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int TAILLE_MAX = 1000;   int main() {     int n, l, r;     cin >> n >> l;     int p[TAILLE_MAX];     for (int i = 0; i < n; i++) cin >> p[i];     sort(p, p + n);     r = max(p[0], l - p[n - 1]) * 2;     for (int i = 0; i < n - 1; i++) r = max(r, p[i + 1] - p[i]);     cout.precision(20);     cout << fixed << r / 2.0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)2E5 + 5;   const long long mdls = (long long)1E9 + 7;   vector<int> Adj[maxN];   vector<long long> suff[maxN], pref[maxN];   long long f[maxN], g[maxN], h[maxN];   int n;   void DFS(int u) {     f[u] = 1;     for (int i = 0, sz = Adj[u].size(); i < sz; ++i) {       int v = Adj[u][i];       DFS(v);       f[u] = (f[u] * (f[v] + 1)) % mdls;     }     int sz = Adj[u].size();     suff[u].resize(sz);     pref[u].resize(sz);     long long temp = 1;     for (int i = 0; i < sz; ++i) {       temp = (temp * (f[Adj[u][i]] + 1)) % mdls;       pref[u][i] = temp;     }     temp = 1;     for (int i = sz - 1; i >= 0; --i) {       temp = (temp * (f[Adj[u][i]] + 1)) % mdls;       suff[u][i] = temp;     }   }   void DFS2(int u) {     for (int i = 0, sz = Adj[u].size(); i < sz; ++i) {       int v = Adj[u][i];       h[v] = h[u];       if (i > 0) h[v] = (h[v] * pref[u][i - 1]) % mdls;       if (i < sz - 1) h[v] = (h[v] * suff[u][i + 1]) % mdls;       h[v] = (h[v] + 1) % mdls;       g[v] = (f[v] * h[v]) % mdls;       DFS2(v);     }   }   int main() {     scanf( %d , &n);     for (int u = 1; u <= n; ++u) Adj[u].clear();     for (int v = 2; v <= n; ++v) {       int u;       scanf( %d , &u);       Adj[u].push_back(v);     }     DFS(1);     h[1] = 1;     g[1] = f[1];     DFS2(1);     for (int u = 1; u <= n; ++u) printf( %I64d  , g[u]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   template <class T>   int size(T &&x) {     return int(x.size());   }   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {     out <<  { ;     for (auto it = x.begin(); it != x.end(); ++it)       out << *it << (it == prev(x.end()) ?    :  ,  );     return out <<  } ;   }   void dump() {}   template <class T, class... Args>   void dump(T &&x, Args... args) {     cerr << x <<  ;   ;     dump(args...);   }   mt19937_64 rng(0);   int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int _degsize;     cin >> _degsize;     vector<int> d(_degsize);     for (int &di : d) cin >> di;     vector<pair<int, int>> edges;     auto add_edge = [&](int v, int u) {       assert(v != u);       edges.emplace_back(v, u);     };     while (size(d)) {       0 && cerr;       int n = d.back() + 1;       if (size(d) == 1) {         for (int v = (0); v <= ((n)-1); ++v)           for (int u = (0); u <= ((v)-1); ++u) add_edge(v, u);         d.clear();         break;       }       int max_cnt = d.front();       for (int &di : d) di -= max_cnt;       for (int v = (n - max_cnt); v <= (n - 1); ++v)         for (int u = (0); u <= ((v)-1); ++u) add_edge(v, u);       d.erase(d.begin());       d.erase(prev(d.end()));     }     cout << size(edges) <<   n ;     for (auto [v, u] : edges) cout << v + 1 <<     << u + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 5e5 + 10;   const double eps = 1e-9;   const int inf = 1e9;   char a[mx];   multiset<char> ms;   int main() {     scanf( %s , a);     int n = strlen(a);     int mn = a[0] -  a ;     printf( Mike n );     for (int i = 1; i < n; i++) {       if (a[i] -  a  > mn) {         printf( Ann n );       } else         printf( Mike n );       mn = min(mn, a[i] -  a );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int dem = 0;     int n;     int tong = 0;     int s;     cin >> n;     for (int i = 9; i >= 1; i--) {       if (n % i == 0) {         s = i;         break;       }     }     int z;     z = n / s;     cout << z << endl;     while (z) {       cout << s <<    ;       z--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string removeZero(string s) {     int i = 0, m = 0, j = s.size() - 1;     if (s[i] ==  0 ) {       while (s[i] ==  0 ) {         i++;       }     }     s.erase(0, i);     if (s[j] ==  0 ) {       while (s[j] ==  0 ) {         m++;         j--;       }     }     s.erase(j + 1, s.size() - j);     return s;   }   int main() {     string s;     cin >> s;     s = removeZero(s);     int x = 0, o = s.size() - 1, flag = 0;     while (x <= s.size() - 1) {       if (s[x] != s[o]) {         flag = 1;         cout <<  NO ;         break;       }       x++;       o--;     }     if (flag == 0) cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int maxm = 1e5 + 5;   const long double eps = 1e-14;   const long double eps2 = 1e-9;   const long double INF = 1 << 30;   inline int dcmp(const long double& x) {     return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);   }   template <typename T>   inline bool getmin(T& a, const T& b) {     return dcmp(b - a) < 0 ? (a = b, true) : false;   }   template <typename T>   inline bool getmax(T& a, const T& b) {     return dcmp(b - a) > 0 ? (a = b, true) : false;   }   pair<long double, long double> operator+(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return {a.first + b.first, a.second + b.second};   }   pair<long double, long double> operator-(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return {a.first - b.first, a.second - b.second};   }   pair<long double, long double> operator*(       const pair<long double, long double>& a, const long double& b) {     return {a.first * b, a.second * b};   }   long double dot(const pair<long double, long double>& a,                   const pair<long double, long double>& b) {     return a.first * b.first + a.second * b.second;   }   long double cross(const pair<long double, long double>& a,                     const pair<long double, long double>& b) {     return a.first * b.second - a.second * b.first;   }   long double abs(const pair<long double, long double>& a) {     return sqrt(dot(a, a));   }   struct Iron {     int show, speed, st, ed;     inline void read() {       scanf( %d%d%d%d , &show, &speed, &st, &ed);       st--, ed--;     }   } iron[maxm];   struct Iron2 {     long double from, fromt, to, tot;   };   struct Path {     int id, from, to;   };   struct Event {     long double t;     int segid;     bool operator<(const Event& rhs) const { return dcmp(t - rhs.t) < 0; }   };   int n, m;   vector<int> G[maxn], chain[maxn];   int fa[maxn], dep[maxn], chainid[maxn], size[maxn];   int pre[maxn], dfs_clock;   void dfs(int now) {     vector<int>& vec = chain[chainid[now]];     for (int i = ((int)(vec.size())) - 1; i >= 0; i--) pre[vec[i]] = dfs_clock++;     for (int i = 0; i < ((int)(vec.size())); i++) {       int now = vec[i];       for (const int& to : G[now])         if ((!i || to != vec[i - 1]) && to != fa[now]) dfs(to);     }   }   inline void make_HLD() {     int first = 0, last = 0;     int* q = new int[n];     q[last++] = 0;     fa[0] = -1;     dep[0] = 0;     while (last - first > 0) {       int now = q[first++];       for (const int& to : G[now])         if (to != fa[now]) {           fa[to] = now;           dep[to] = dep[now] + 1;           q[last++] = to;         }     }     for (int i = last - 1; i >= 0; i--) {       int now = q[i], hs = -1;       size[now] = 1;       for (const int& to : G[now])         if (to != fa[now]) {           size[now] += size[to];           if (hs < 0 || size[to] > size[hs]) hs = to;         }       if (hs < 0)         chainid[now] = now;       else         chainid[now] = chainid[hs];       chain[chainid[now]].push_back(now);     }     dfs_clock = 0;     delete[] q;     dfs(0);   }   inline bool inrange(const long double& x, const long double& L,                       const long double& R) {     return dcmp(x - L) >= 0 && dcmp(x - R) <= 0;   }   long double interPnt(pair<long double, long double> p1,                        pair<long double, long double> p2,                        pair<long double, long double> q1,                        pair<long double, long double> q2) {     pair<long double, long double> d = p2 - p1, e = q2 - q1;     long double crs = cross(d, e);     if (abs(crs) < eps) {       long double c2 = cross(d, q1 - p1);       if (abs(c2) > eps) return INF;       long double da2 = dot(d, d);       long double f1 = dot(d, q1 - p1) / da2;       long double f2 = dot(d, q2 - p1) / da2;       if (f1 < -eps and f2 < -eps) return INF;       if (f1 > 1 + eps and f2 > 1 + eps) return INF;       long double f = max(0.l, min(f1, f2));       return (p1 + d * f).first;     }     long double f1 = cross(d, q1 - p1);     long double f2 = cross(d, p1 - q2);     long double f = f1 + f2;     pair<long double, long double> x = q1 * (f2 / f) + q2 * (f1 / f);     long double fp = f1 / f;     long double gp = dot(x - p1, d) / dot(d, d);     if (fp < -eps or fp > 1 + eps) return INF;     if (gp < -eps or gp > 1 + eps) return INF;     return x.first;   }   inline long double getIntersectime(const Iron2& A, const Iron2& B) {     return interPnt(make_pair(A.fromt, A.from), make_pair(A.tot, A.to),                     make_pair(B.fromt, B.from), make_pair(B.tot, B.to));     const long double &x1 = A.from, &t1 = A.fromt, &x2 = A.to, &t2 = A.tot,                       &x3 = B.from, &t3 = B.fromt, &x4 = B.to, &t4 = B.tot;     long double deno = (x2 - x1) * (t4 - t3) - (t2 - t1) * (x4 - x3);     long double nume = (x3 - x1) * (t2 - t1) * (t4 - t3) -                        t3 * (t2 - t1) * (x4 - x3) + t1 * (t4 - t3) * (x2 - x1);     long double ans;     if (dcmp(deno) == 0) {       if (dcmp((x4 - x3) / (t4 - t3) * (t1 - t3) + x3 - x1) == 0)         ans = max(t1, t3);       else         ans = INF;     } else       ans = nume / deno;     if (inrange(ans, max(t1, t3), min(t2, t4)))       return ans;     else       return INF;   }   long double curtime;   vector<Iron2> vec;   struct cmp {     inline long double getpos(const Iron2& I, const long double& t) const {       return I.from + ((I.to - I.from) / (I.tot - I.fromt)) * (t - I.fromt);     }     bool operator()(const int& a, const int& b) const {       long double d1 = dcmp(getpos(vec[a], curtime) - getpos(vec[b], curtime)),                   d2 = dcmp(getpos(vec[a], curtime + 1) -                             getpos(vec[b], curtime + 1));       return d1 < 0 || (d1 == 0 && d2 < 0) || (d1 == 0 && d2 == 0 && a < b);     }   };   vector<Iron2> Seg[maxn];   inline long double solve_path(const int& nowSeg) {     vec = Seg[nowSeg];     set<int, cmp> second;     vector<Event> eve;     for (int i = 0; i < ((int)(vec.size())); i++)       eve.push_back((Event){vec[i].fromt, i << 1}),           eve.push_back((Event){vec[i].tot, i << 1 | 1});     sort(eve.begin(), eve.end());     long double ans = INF;     for (const Event& e : eve) {       curtime = e.t;       if (dcmp(curtime - ans) >= 0) break;       int id = e.segid;       if (!(id & 1)) {         id /= 2;         set<int>::iterator it = second.lower_bound(id);         assert(second.find(id) == second.end());         if (it != second.end()) getmin(ans, getIntersectime(vec[id], vec[*it]));         if (it != second.begin())           it--, getmin(ans, getIntersectime(vec[id], vec[*it]));         second.insert(id);       } else {         id /= 2;         set<int>::iterator it = second.lower_bound(id), itL = it, itR = it;         assert((*it) == id);         itR++;         if (itL != second.begin() && itR != second.end()) {           itL--;           getmin(ans, getIntersectime(vec[*itL], vec[*itR]));         }         second.erase(it);       }     }     return ans;   }   vector<Path> path, L, R;   inline void getPath(int a, int b) {     L.clear();     R.clear();     while (chainid[a] != chainid[b]) {       int atop = chain[chainid[a]].back(), btop = chain[chainid[b]].back();       if (dep[atop] > dep[btop])         L.push_back((Path){chainid[a], a, fa[atop]}), a = fa[atop];       else         R.push_back((Path){chainid[b], fa[btop], b}), b = fa[btop];     }     L.push_back((Path){chainid[a], a, b});     path.clear();     for (int i = 0; i < ((int)(L.size())); i++) path.push_back(L[i]);     for (int i = ((int)(R.size())) - 1; i >= 0; i--) path.push_back(R[i]);   }   inline int PosOnPath(int id, int now) {     if (chainid[now] != id) return 0;     return pre[now] - pre[chain[id].back()] + 1;   }   inline long double solve_tree() {     make_HLD();     for (int i = 0; i < m; i++) {       getPath(iron[i].st, iron[i].ed);       long double curt = iron[i].show, v = iron[i].speed;       for (const Path& p : path) {         int from = PosOnPath(p.id, p.from), to = PosOnPath(p.id, p.to);         long double arrt = curt + abs(to - from) / v;         long double cc = dcmp(arrt - curt) == 0 ? 0 : (to - from) / (arrt - curt);         Seg[p.id].push_back(             (Iron2){from - eps2 * cc, curt - eps2, to + eps2 * cc, arrt + eps2});         curt = arrt;       }     }     long double res = INF;     for (int i = 0; i < n; i++) getmin(res, solve_path(i));     return res;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, a, b; i < n - 1; i++) {       scanf( %d%d , &a, &b);       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < m; i++) iron[i].read();     long double ans = solve_tree();     if (dcmp(ans - INF) >= 0)       printf( -1 n );     else       printf( %.13f n , (double)ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e14;   long long ab(long long x) { return x > 0 ? x : -x; }   long long a[100005];   long long kn[66];   long long sum[100005];   map<long long, int> mp;   int nxt[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     kn[0] = 1;     int cnt = 0;     for (int i = 1;; i++) {       kn[i] = kn[i - 1] * k;       if (kn[i] == 1) break;       cnt++;       if (ab(kn[i]) >= oo) break;     }     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= cnt; j++) {         mp[sum[n] - sum[i] - kn[j]]++;       }     }     long long ans = 0, step = 0;     for (int i = n; i >= 1; i--) {       ans += mp[step];       for (int j = 0; j <= cnt; j++) {         mp[sum[n] - sum[i - 1] - kn[j]]--;       }       step += a[i];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e16;   const long long int maxn = 1 << 20;   double pie = 3.1415926535;   string str[101];   bool done[101];   int main() {     long long int n, i, j, cnt, offset;     string s, s1, ans;     cin >> n >> s;     ans =   ;     for (i = 0; i < n; i++) ans +=  9 ;     for (i = 0; i < n; i++) {       offset = 10 - (s[i] -  0 );       s1.clear();       for (j = i, cnt = 0; cnt < n; cnt++, j++) {         long long int x = (s[j] -  0  + offset) % 10;         s1 += (x +  0 );         if (j == n - 1) j = -1;       }       ans = min(ans, s1);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using std::max;   using std::min;   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3f;   std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   inline _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   inline void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   inline void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   inline void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     f && (x = -x);   }   template <typename _Tp, typename... Args>   inline void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   inline int read_str(char *s) {     char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 3005;   const int S = 12;   const int mod = 998244353;   template <typename _Tp1, typename _Tp2>   inline void add(_Tp1 &a, _Tp2 b) {     (a += b) >= mod && (a -= mod);   }   template <typename _Tp1, typename _Tp2>   inline void sub(_Tp1 &a, _Tp2 b) {     (a -= b) < 0 && (a += mod);   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   int n, c;   int a[N];   int A[N], B[N];   namespace sub1 {   int dp[N][N / S + 5];   int f[N][N], cnt[N], ans[N];   void MAIN() {     int maxx = n / c;     for (int j = 1; j <= n; ++j) {       memset(cnt, 0, sizeof(cnt));       int qwq = c - 1, coef = 1;       if (!qwq) f[j][j] = 1;       for (int i = j - 1; i >= 1; --i) {         if (a[i] != a[j]) {           if (!cnt[a[i]])             --qwq;           else             coef = 1ll * coef * B[cnt[a[i]]] % mod * A[cnt[a[i]] + 1] % mod;           ++cnt[a[i]];         }         if (!qwq) f[i][j] = coef;       }     }     dp[0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1, LIM = i / c; j <= LIM; ++j)         for (int k = 1; k <= i; ++k)           add(dp[i][j], 1ll * f[k][i] * dp[k - 1][j - 1] % mod);     memset(cnt, 0, sizeof(cnt));     int qwq = c, coef = 1, qaq = 1;     for (int i = n; i >= 0; --i) {       for (int j = 0; j <= maxx; ++j)         add(ans[j], 1ll * (qaq - (qwq ? 0 : coef) + mod) * dp[i][j] % mod);       if (!cnt[a[i]])         --qwq;       else         coef = 1ll * coef * B[cnt[a[i]]] % mod * A[cnt[a[i]] + 1] % mod;       ++cnt[a[i]];       add(qaq, qaq);     }     sub(ans[0], 1);     for (int j = 0; j <= n; ++j) printf( %d%c , ans[j],    n [j == n]);   }   }  // namespace sub1   namespace sub2 {   int dp[N][1 << S];   void MAIN() {     int maxx = n / c;     dp[0][0] = 1;     for (int i = 0; i < n; ++i) {       for (int j = i / c; j >= 0; --j) {         for (int st = (1 << c) - 2; st >= 0; --st) {           int to = st | 1 << (a[i + 1] - 1);           if (to + 1 == (1 << c))             add(dp[j + 1][0], dp[j][st]);           else             add(dp[j][to], dp[j][st]);         }       }     }     for (int i = 0; i <= n; ++i) {       int ans = 0;       if (i <= maxx)         for (int st = 0; st < 1 << c; ++st) add(ans, dp[i][st]);       if (!i) sub(ans, 1);       printf( %d%c , ans,    n [i == n]);     }   }   }  // namespace sub2   int main() {     for (int i = 1; i < N; ++i)       A[i] = (A[i - 1] + A[i - 1] + 1) % mod, B[i] = ksm(A[i]);     read(n, c);     for (int i = 1; i <= n; ++i) read(a[i]);     if (c > S)       sub1::MAIN();     else       sub2::MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inff = 0x3f3f3f3f3f3f3f3f;   int main() {     cin.tie(0);     long long k, d, t, qw, e;     scanf( %I64d , &k), scanf( %I64d , &d), scanf( %I64d , &t);     qw = (k / d + 1) * d;     if (k % d == 0) {       cout << t << endl;       return 0;     }     double s = 0.0, zz, po;     po = (qw - k) * 0.5 + k;     e = 2ll * t / (qw + k);     e *= qw;     s += e;     e /= qw;     zz = t - e * po;     if (zz <= k) {       s += zz;     } else {       s += k;       zz -= k;       s += zz * 2.0;     }     printf( %.10f n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fff() {     freopen( dravde.in ,  r , stdin);     freopen( dravde.out ,  w , stdout);   }   const int MAXN = 100001;   int n;   map<int, int> m[MAXN];   int f[MAXN], s[MAXN], p[MAXN], cnt = 0, z;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int v, c, l, r;       scanf( %d%d%d%d , &v, &c, &l, &r);       if (r + c < MAXN && (!l || m[l].find(r + c) != m[l].end())) {         int u = m[l][r + c];         f[i] = f[u] + v, p[i] = u;         if (!r && f[i] > f[z]) {           z = i;         }         if (f[i] > f[m[l + c][r]]) {           m[l + c][r] = i;         }       }     }     while (z) {       s[cnt++] = z;       z = p[z];     }     printf( %d n , cnt);     while (cnt--) {       printf( %d  , s[cnt]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, v;   pair<int, int> p[10];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf(  n );       for (int j = 1; j <= m; ++j) {         char ch = getchar();         if (ch ==  * ) p[++v] = make_pair(i, j);       }     }     if (p[1].first == p[2].first && p[1].second == p[3].second)       printf( %d %d , p[3].first, p[2].second);     else if (p[1].first == p[3].first && p[1].second == p[2].second)       printf( %d %d , p[2].first, p[3].second);     else if (p[2].first == p[1].first && p[2].second == p[3].second)       printf( %d %d , p[3].first, p[1].second);     else if (p[2].first == p[3].first && p[2].second == p[1].second)       printf( %d %d , p[1].first, p[3].second);     else if (p[3].first == p[1].first && p[3].second == p[2].second)       printf( %d %d , p[2].first, p[1].second);     else if (p[3].first == p[2].first && p[3].second == p[1].second)       printf( %d %d , p[1].first, p[2].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tests, t, qq, q, i, j, bb[200000], s1, ans[2100][2100];   long long a, b;   long solve(long long a, long long b) {     if (a < b) swap(a, b);     if (a == 0 || b == 0) return 0;     if (solve(a % b, b) == 0) return 1;     t = a / b;     if (b % 2 == 1) return 1 - t % 2;     t %= (b + 1);     if (t % 2 == 1) return 0;     return 1;   }   int main() {     long s = 0;     cin >> tests;     for (; tests; --tests) {       cin >> a >> b;       if (solve(a, b))         cout <<  First  << endl;       else         cout <<  Second  << endl;     }     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   using ll = long long;   using point = pair<ll, ll>;   ll& x(point& p) { return p.first; }   ll& y(point& p) { return p.second; }   int n;   point p[N], p2[N];   set<point> s;   point centerN, center2, invP;   int no() {     cout <<  NO  << endl;     return 0;   }   int main() {     cin >> n;     x(centerN) = 0;     y(centerN) = 0;     for (int i = 0; i < n; ++i) {       cin >> x(p[i]) >> y(p[i]);       x(p2[i]) = 2 * x(p[i]);       y(p2[i]) = 2 * y(p[i]);       x(centerN) += x(p[i]);       y(centerN) += y(p[i]);     }     if ((2 * x(centerN)) % n != 0 || (2 * y(centerN)) % n != 0) {       return no();     }     x(center2) = 2 * x(centerN) / n;     y(center2) = 2 * y(centerN) / n;     for (int i = 0; i < n; ++i) {       x(p2[i]) -= x(center2);       y(p2[i]) -= y(center2);       s.insert(p2[i]);     }     for (int i = 0; i < n; ++i) {       x(invP) = -x(p2[i]);       y(invP) = -y(p2[i]);       auto it = s.find(invP);       if (it == s.end()) {         return no();       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int kek[20];   long long a[696969];   void upd(int x, int v, int s = 0, int e = (1 << n) - 1, int d = n - 1,            int p = 1) {     if (s == e) {       a[p] = v;       return;     }     int m = (s + e) / 2;     if (x <= m) {       upd(x, v, s, m, d - 1, 2 * p + kek[d]);     } else {       upd(x, v, m + 1, e, d - 1, 2 * p + 1 - kek[d]);     }     a[p] = a[2 * p] + a[2 * p + 1];   }   long long query(int s, int e, int ps = 0, int pe = (1 << n) - 1, int d = n - 1,                   int p = 1) {     if (e < ps || pe < s) return 0;     if (s <= ps && pe <= e) return a[p];     int pm = (ps + pe) / 2;     return query(s, e, ps, pm, d - 1, 2 * p + kek[d]) +            query(s, e, pm + 1, pe, d - 1, 2 * p + 1 - kek[d]);   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 0; i < (1 << n); i++) {       int x;       scanf( %d , &x);       upd(i, x);     }     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int x, v;         scanf( %d %d , &x, &v);         x--;         upd(x, v);       }       if (t == 4) {         int s, e;         scanf( %d %d , &s, &e);         printf( %lld n , query(s - 1, e - 1));       }       if (t == 2) {         int x;         scanf( %d , &x);         for (int i = 0; i < x; i++) kek[i] ^= 1;       }       if (t == 3) {         int x;         scanf( %d , &x);         kek[x] ^= 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct event {     long long int peakval;     long long int pos;     long long int time1;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, d;     cin >> n >> m >> d;     struct event e1[m + 1];     e1[0].time1 = 0;     for (long long int i = 1; i <= m; i++) {       cin >> e1[i].pos >> e1[i].peakval >> e1[i].time1;     }     long long int dp[2][n + 1];     for (long long int i = 1; i <= n; i++) {       dp[0][i] = 0;     }     deque<pair<long long int, long long int> > dq1;     long long int delta, store;     for (long long int i = 1; i <= m; i++) {       delta = e1[i].time1 - (e1[i - 1].time1);       delta *= d;       for (long long int j = 1; j <= min(delta + 1, n); j++) {         while (!dq1.empty() && dp[0][j] >= dq1.back().first) {           dq1.pop_back();           if (dq1.empty()) {             break;           }         }         dq1.push_back({dp[0][j], j});       }       for (long long int j = 1; j <= n; j++) {         while (dq1.front().second < (j - delta)) {           dq1.pop_front();         }         store = e1[i].peakval - fabs(e1[i].pos - j);         dp[1][j] = dq1.front().first + store;         if ((j + delta + 1) <= n) {           while (dp[0][j + delta + 1] >= dq1.back().first) {             dq1.pop_back();             if (dq1.empty()) {               break;             }           }           dq1.push_back({dp[0][j + delta + 1], j + delta + 1});         }       }       for (long long int i = 1; i <= n; i++) {         dp[0][i] = dp[1][i];       }       dq1.clear();     }     long long int ans = -1000000000000000007;     for (long long int i = 1; i <= n; i++) {       ans = max(ans, dp[1][i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   class {    public:     int n, m;     vector<pair<int, int> > V[5555];     bool vis[5555], in[5555];     int ans[5555];     void solve() {       cin >> n >> m;       for (int i = 0; i < m; ++i) {         int u, v;         cin >> u >> v;         V[u].push_back({v, i});       }       for (int i = 1; i <= n; ++i) {         if (!vis[i]) dfs(i);       }       if (two)         cout << 2 <<   n ;       else         cout << 1 <<   n ;       for (int i = 0; i < m; ++i) {         cout << ans[i] + 1 <<    ;       }     }     bool two = 0;     void dfs(int u) {       in[u] = 1;       vis[u] = 1;       for (auto v : V[u]) {         if (!vis[v.first]) {           dfs(v.first);         } else if (in[v.first]) {           ans[v.second] = 1;           two = 1;         }       }       in[u] = 0;     }   } NSPACE;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 7;   void solve() {     long long n, curr, val, ans = 0;     cin >> n >> curr;     vector<long long> a(n), cost(n);     for (long long i = 0; i < n; i++) cin >> a[i];     cin >> val;     for (long long i = 0; i < n; i++) cin >> cost[i];     multiset<long long> s;     for (long long i = 0; i < n; i++) {       s.insert(cost[i]);       if (curr < a[i]) {         long long x = (a[i] - curr + val - 1) / val;         if (x > s.size()) {           ans = -1;           break;         }         while (x--) {           ans += *s.begin();           curr += val;           s.erase(s.begin());         }       }     }     cout << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n;   string s;   vector<long long int> ss;   inline bool check(long long int lim) {     long long int sum = 0, cnt = 0;     for (long long int i = 0; i < ss.size(); i++) {       if (sum + ss[i] <= lim) {         sum += ss[i];       } else {         cnt++;         sum = ss[i];       }     }     cnt++;     if (cnt <= n) return true;     return false;   }   int main() {     cin >> n;     cin.ignore();     getline(cin, s);     long long int pos = 0;     for (long long int i = 0; i < s.length(); i++) {       if (s[i] ==  -  || s[i] ==    ) {         ss.push_back(i - pos + 1);         pos = i + 1;       }     }     ss.push_back(s.length() - pos);     long long int low, high, mid;     high = s.length();     low = -1;     for (long long int i = 0; i < ss.size(); i++) low = max(low, ss[i]);     long long int ans = high;     while (low <= high) {       mid = (low + high) / 2;       if (check(mid)) {         high = mid - 1;         ans = min(ans, mid);       } else         low = mid + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int podch[1100];   int newp[1100];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, x;     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       podch[tmp]++;     }     for (int i = 0; i < k; i++) {       int countwas = 0;       for (int j = 0; j < 1100; j++) {         newp[j] = 0;       }       for (int j = 0; j < 1100; j++) {         int tmp = podch[j];         if (podch[j] % 2 != 0) {           if (countwas % 2 == 0) {             newp[(j ^ x)] += (podch[j] / 2 + 1);             newp[j] -= (podch[j] / 2 + 1);           } else {             newp[(j ^ x)] += (podch[j] / 2);             newp[j] -= (podch[j] / 2);           }         } else {           newp[(j ^ x)] += (podch[j] / 2);           newp[j] -= (podch[j] / 2);         }         countwas += tmp;       }       for (int j = 0; j < 1100; j++) {         podch[j] += newp[j];       }     }     int kek = 0;     for (int i = 0; i < 1100; i++) {       if (podch[i]) {         kek = i;         break;       }     }     int kek2 = 0;     for (int i = 0; i < 1100; i++) {       if (podch[i]) {         kek2 = i;       }     }     cout << kek2 <<     << kek << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long add(long long x, long long y, long long CMOD = MOD) {     return (x + y + CMOD + CMOD) % CMOD;   }   long long mult(long long x, long long y, long long CMOD = MOD) {     return add(x, 0) * add(y, 0) % CMOD;   }   long long fast_expo(long long x, long long y, long long CMOD = MOD) {     if (x == 0) return 0;     if (y == 0) return 1;     long long ans = fast_expo(x, y / 2, CMOD);     ans = mult(ans, ans, CMOD);     if (y & 1) ans = mult(ans, x, CMOD);     return ans;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long gen(long long x, long long y) {     if (x == y) return x;     return x + rng() % (y - x + 1);   }   const int TAM = 1e5 + 100;   const long long INF = LLONG_MAX / 4;   int n;   int main() {     priority_queue<long long, vector<long long>, greater<long long> > pq;     scanf( %d , &n);     if (n % 2 == 0) pq.push(0);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       pq.push(x);     }     long long ans = 0;     while (pq.size() > 1) {       long long x = 0;       for (int i = 0; i < 3; i++) {         x += pq.top();         pq.pop();       }       ans += x;       pq.push(x);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       int b[n];       vector<int> c;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       for (int i = 0; i < n; i++) {         if (!b[i]) c.push_back(a[i]);       }       sort(c.rbegin(), c.rend());       int j = 0;       for (int i = 0; i < n; i++) {         if (b[i])           cout << a[i] <<    ;         else           cout << c[j++] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char q[15][15], p[15][15], max_s[15], min_s[15], tmp[15], ans[15];   int np[15];   int main() {     int i, j, k, n, carry, t, flag;     while (scanf( %d %d , &n, &k) != EOF) {       for (i = 0; i < n; ++i) scanf( %s , q + i);       for (i = 0; i < k; ++i) {         np[i] = i;         ans[i] =  9 ;       }       ans[i] =   0 ;       do {         for (i = 0; i < k; ++i) {           min_s[i] =  9 ;           max_s[i] =  0 ;         }         min_s[i] =   0 ;         max_s[i] =   0 ;         for (i = 0; i < n; ++i) {           for (j = 0; j < k; ++j) {             p[i][j] = q[i][np[j]];           }           p[i][j] =   0 ;           if (strcmp(p[i], min_s) < 0) strcpy(min_s, p[i]);           if (strcmp(p[i], max_s) > 0) strcpy(max_s, p[i]);         }         carry = 0;         for (i = k - 1; i >= 0; --i) {           t = max_s[i] - min_s[i] - carry;           if (t < 0) {             carry = 1;             t += 10;           } else             carry = 0;           tmp[i] = t +  0 ;         }         tmp[k] =   0 ;         if (strcmp(tmp, ans) < 0) strcpy(ans, tmp);       } while (next_permutation(np, np + k));       flag = 0;       for (i = 0; i < k; ++i) {         if (ans[i] ==  0 ) {           if (flag != 0) printf( %c , ans[i]);         } else {           if (flag == 0) flag = 1;           printf( %c , ans[i]);         }       }       if (flag == 0)         printf( 0 n );       else         printf(  n );     }     return 0;   }