#include <bits/stdc++.h>   using namespace std;   string s;   string rev(string s) {     string p;     for (auto i : s) p.insert(0, 1, i);     return p;   }   int main() {     cin >> s;     int n = s.size();     for (int i = 0; i <= s.size(); i++)       for (int j = 0; j < 26; j++) {         string p = s;         p.insert(i, 1, j +  a );         if (p == rev(p)) return cout << p, 0;       }     cout <<  NA ;   }


#include <bits/stdc++.h>   struct PP {     int l, r, sum, lv, rv, cover;     int mid() { return (l + r) >> 1; }     void doit() { sum = lv = rv = cover ? 0 : dis(); }     int dis() { return r - l; }   } q[100005 * 3];   int max(int a, int b) { return a > b ? a : b; }   void Build(int l, int r, int x) {     q[x].l = l;     q[x].r = r;     q[x].sum = q[x].lv = q[x].rv = q[x].dis();     q[x].cover = -1;     if (l == r - 1) return;     int mid = q[x].mid();     Build(l, mid, (x << 1));     Build(mid, r, ((x << 1) | 1));   }   void pushdown(int x) {     q[(x << 1)].cover = q[((x << 1) | 1)].cover = q[x].cover;     q[(x << 1)].doit();     q[((x << 1) | 1)].doit();     q[x].cover = -1;   }   void Pushup(int x) {     q[x].sum = max(q[(x << 1)].rv + q[((x << 1) | 1)].lv,                    max(q[(x << 1)].sum, q[((x << 1) | 1)].sum));     q[x].lv = q[(x << 1)].lv;     q[x].rv = q[((x << 1) | 1)].rv;     if (q[(x << 1)].sum == q[(x << 1)].dis()) q[x].lv += q[((x << 1) | 1)].lv;     if (q[((x << 1) | 1)].sum == q[((x << 1) | 1)].dis())       q[x].rv += q[(x << 1)].rv;   }   void update(int l, int r, int c, int x) {     if (l <= q[x].l && q[x].r <= r) {       q[x].cover = c;       q[x].doit();       return;     }     if (q[x].cover != -1) pushdown(x);     int mid = q[x].mid();     if (l < mid) update(l, r, c, (x << 1));     if (mid < r) update(l, r, c, ((x << 1) | 1));     Pushup(x);   }   int query(int w, int x) {     if (q[x].sum >= w && q[x].cover == 0) return q[x].l;     if (q[x].cover != -1) pushdown(x);     if (q[(x << 1)].sum >= w)       return query(w, (x << 1));     else if (q[(x << 1)].rv + q[((x << 1) | 1)].lv >= w)       return q[(x << 1)].r - q[(x << 1)].rv;     else if (q[((x << 1) | 1)].sum >= w)       return query(w, ((x << 1) | 1));     else       return -1;   }   struct SS {     int l, r;   } cnt[100005];   int main() {     int i, m, op, a;     int L, B, F;     while (scanf( %d%d%d , &L, &B, &F) != EOF) {       scanf( %d , &m);       Build(0, B + L + F, 1);       for (i = 1; i <= m; i++) {         scanf( %d%d , &op, &a);         if (op == 1) {           int pos = query(B + a + F, 1);           if (pos == -1) {             printf( -1 n );             continue;           }           printf( %d n , pos);           update(pos + B, pos + B + a, 1, 1);           cnt[i].l = pos + B;           cnt[i].r = pos + B + a;         } else           update(cnt[a].l, cnt[a].r, 0, 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 200000;   int n, m, t, tin[mxN];   vector<int> adj[mxN], e[mxN];   vector<array<int, 3>> ans;   void dfs(int u, int p = -1) {     tin[u] = ++t;     if (p ^ -1) e[u].push_back(p);     for (int v : adj[u]) {       if (v == p) continue;       if (!tin[v]) {         dfs(v, u);       } else if (tin[v] < tin[u]) {         e[u].push_back(v);       }     }     while (e[u].size() >= 2) {       int v = e[u].back();       e[u].pop_back();       int w = e[u].back();       e[u].pop_back();       ans.push_back({v, u, w});     }     if (e[u].size() == 1 && p ^ -1) e[p].push_back(u);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v, --u, --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < n; ++i)       if (!tin[i]) dfs(i);     cout << ans.size() <<   n ;     for (array<int, 3> x : ans)       cout << x[0] + 1 <<     << x[1] + 1 <<     << x[2] + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int N = int(2e5) + 10;   const int M = int(1e5) + 5;   const int INF = int(1e9);   int U[N], V[N], W[N], vis[N], D[N], comp[N], val[N], ans[N], parent;   vector<int> g[N], rg[N], G[N], nodes;   int n, m;   int adj(int u, int e) { return U[e] ^ V[e] ^ u; }   void get(int u) {     nodes.push_back(u);     nodes.push_back(u + M);     vis[u] = 1;     for (auto e : G[u]) {       int w = adj(u, e);       if (vis[w]) continue;       get(w);     }   }   int NOT(int u) {     if (u < M)       return u + M;     else       return u - M;   }   void addEdge(int u, int v) {     u = NOT(u);     g[u].push_back(v);     rg[v].push_back(u);     u = NOT(u);     v = NOT(v);     swap(u, v);     g[u].push_back(v);     rg[v].push_back(u);   }   void clear(int u) {     g[u].clear(), rg[u].clear(), vis[u] = 0, val[u] = 0, comp[u] = 0;     for (auto e : G[u]) D[e] = 0;   }   vector<int> order, component;   void dfs1(int u) {     vis[u] = 1;     for (auto w : g[u])       if (!vis[w]) dfs1(w);     order.push_back(u);   }   void dfs2(int u) {     vis[u] = 1;     comp[u] = parent;     for (auto w : rg[u])       if (!vis[w]) dfs2(w);   }   int go(int t) {     for (auto u : nodes) clear(u);     for (auto u : nodes)       for (auto e : G[u])         if (!D[e]) {           D[e] = 1;           if (W[e] == t)             addEdge(U[e], V[e]), addEdge(NOT(U[e]), NOT(V[e]));           else             addEdge(U[e], NOT(V[e])), addEdge(NOT(U[e]), V[e]);         }     order.clear();     for (auto i : nodes)       if (!vis[i]) dfs1(i);     for (auto u : nodes) vis[u] = 0;     reverse(order.begin(), order.end());     vector<int> Cmp;     for (auto i : order) {       if (!vis[i]) parent = i, Cmp.push_back(i), dfs2(i);     }     for (auto u : nodes) {       if (comp[u] == comp[NOT(u)]) return INF;     }     reverse(Cmp.begin(), Cmp.end());     int a = 0, b = 0;     for (auto u : Cmp) {       if (!val[u]) {         val[u] = 1;         val[comp[NOT(u)]] = -1;       }     }     for (auto u : nodes)       if (u < M) (val[comp[u]] == 1) ? a++ : b++;     int V = (a > b ? 0 : 1);     for (auto u : nodes)       if (u < M && val[comp[u]] == 1)         ans[u] = V;       else if (u < M)         ans[u] = 1 - V;     return min(a, b);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       char x;       scanf( %d %d %c , U + i, V + i, &x);       G[U[i]].push_back(i);       G[V[i]].push_back(i);       W[i] = (x ==  R  ? 1 : 0);     }     long long int Ans1 = 0, Ans2 = 0;     for (int i = 1; i <= n; i++)       if (!vis[i]) {         nodes.clear();         get(i);         Ans1 += go(0);         Ans2 += go(1);       }     long long int Ans = min(Ans1, Ans2);     if (Ans >= INF)       puts( -1 );     else {       printf( %lld n , Ans);       int t = (Ans == Ans1 ? 0 : 1);       memset(vis, 0, sizeof(vis));       for (int i = 1; i <= n; i++)         if (!vis[i]) {           nodes.clear();           get(i);           go(t);         }       for (int i = 1; i <= n; i++)         if (ans[i]) printf( %d  , i);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     if (n == 47 || n == 74 || n == 477 || n == 477)       cout <<  YES ;     else if (n % 4 == 0 || n % 7 == 0 || n % 47 == 0)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, arr[105];     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int ans = arr[0];     for (int i = 1; i < n; i++) {       ans = gcd(ans, arr[i]);     }     cout << ans * n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, r;     cin >> n >> m >> r;     vector<int> v(n);     vector<int> v1(m);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       cin >> v1[i];     }     sort(v.begin(), v.end());     sort(v1.rbegin(), v1.rend());     if (v[0] > v1[0]) {       cout << r << endl;       return 0;     }     int cnt = 0;     cnt += r % v[0];     cnt += (r / v[0]) * v1[0];     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int ured() {     int re = 0, ch;     do {       ch = getchar();     } while ( 9  < ch || ch <  0 );     do {       re = re * 10 + (ch ^  0 );     } while ( 0  <= (ch = getchar()) && ch <=  9 );     return re;   }   void uwit(int da) {     int cn = 0, ch[21];     do {       ch[++cn] = da - da / 10 * 10;     } while (da /= 10);     do {       putchar( 0  ^ ch[cn]);     } while (--cn);   }   inline void dmax(int& fr, int to) {     if (fr < to) {       fr = to;     }   }   inline void dmin(int& fr, int to) {     if (fr > to) {       fr = to;     }   }   inline int mabs(int da) { return da >= 0 ? da : -da; }   const int _maxn = 200011, _mods = 1000000007;   int t, n, m, pdif;   char s[_maxn];   int main() {     t = ured();     while (t--) {       n = ured();       m = ured();       if (m >= 2 * n) {         uwit((m + 1) / 2 - 1);       } else {         uwit(m - n);       }       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const long long _ = 1e18;   signed main() {     long long a = read(), q = (_ % a * 9 % a * 9 % a + 1) % a;     printf( %lld %lld n , a - q + 1, a - q + _);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first < b.first;     else       return (a.second > b.second);   }   bool cmp(pair<string, int> x, pair<string, int> y) {     return (x.second < y.second);   }   long long int bigmod(long long int a, long long int b, long long int m) {     if (b == 0) return 1 % m;     long long int x = bigmod(a, b / 2, m);     x = (x * x) % m;     if (b % 2 == 1) x = (x * a) % m;     return x;   }   void NA() {     printf( NO n );     exit(0);   }   void YA() {     printf( YES n );     exit(0);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long int mx = 0LL, mn = 0LL;     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       mx = (mx + bigmod(2, i, 1000000007) * a[i]) % 1000000007;       mn = (mn + bigmod(2, n - i - 1, 1000000007) * a[i]) % 1000000007;     }     cout << (mx - mn + 1000000007) % 1000000007 << endl;   }


#include <bits/stdc++.h>   using namespace std;   void abc() { cout << endl; }   template <typename T, typename... U>   void abc(T a, U... b) {     cout << a <<    , abc(b...);   }   template <typename T>   void printv(T l, T r) {     while (l != r) cout << *l <<    n [++l == r];   }   template <typename A, typename B>   istream& operator>>(istream& o, pair<A, B>& a) {     return o >> a.first >> a.second;   }   template <typename A, typename B>   ostream& operator<<(ostream& o, pair<A, B> a) {     return o <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& o, vector<T> a) {     bool is = false;     for (T i : a) {       o << (is ?     :  { ), is = true, o << i;     }     return o <<  } ;   }   template <typename T>   struct vv : vector<vector<T>> {     vv(int n, int m, T v) : vector<vector<T>>(n, vector<T>(m, v)) {}     vv() {}   };   template <typename T>   struct vvv : vector<vv<T>> {     vvv(int n, int m, int k, T v) : vector<vv<T>>(n, vv<T>(m, k, v)) {}     vvv() {}   };   const int mod = 1e9 + 7, N = 200001, logN = 20, K = 80000;   long long int modpow(long long int a, int b) {     long long int ans = 1;     for (; b; b >>= 1, a = a * a % mod) {       if (b & 1) ans = ans * a % mod;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     vv<long long int> inv(n, n, 0);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         inv[i][j] = modpow((a[i] + a[j]) % mod, mod - 2);       }     vv<long long int> pre(1 << n, n, 1);     vv<long long int> pw(n, n + 1, 1);     for (int i = 0; i < n; ++i) {       for (int j = 1; j <= n; ++j) {         pw[i][j] = pw[i][j - 1] * a[i] % mod;       }     }     for (int i = 0; i < n; ++i) {       for (int s = 0; s < 1 << n; ++s) {         for (int j = 0; j < n; ++j)           if (s >> j & 1) {             pre[s][i] = pre[s][i] * inv[i][j] % mod;           }       }     }     vector<long long int> dp(1 << n, 1);     for (int s = 0; s < 1 << n; ++s) {       for (int t = s ^ (s & (-s)); t > 0; t = (t - 1) & s) {         long long int res = dp[t];         for (int j = 0; j < n; ++j)           if (t >> j & 1) {             res = res * pre[t ^ s][j] % mod * pw[j][__builtin_popcount(t ^ s)] %                   mod;           }         dp[s] -= res;         if (dp[s] < 0) dp[s] += mod;       }     }     long long int ans = 0;     for (int s = 0; s < 1 << n; ++s) {       int k = __builtin_popcount(s);       long long int res = dp[s];       for (int i = 0; i < n; ++i)         if (s >> i & 1) {           for (int j = 0; j < n; ++j)             if (~s >> j & 1) {               res = res * a[i] % mod * inv[i][j] % mod;             }         }       ans += res * k % mod;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   int main() {     int t, res = 0;     long x, y, n;     std::cin >> t;     for (int i = 0; i < t; i++) {       std::cin >> x >> y >> n;       if (n > 0) {         res = (n - y) % x;         std::cout << n - res <<   n ;       } else {         std::cout << 0 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int N, i, j;   string S, R;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> S;     for (i = N - 2; i >= 0; i -= 2) {       R = R + S[i];     }     if (N % 2 == 0)       i = 1;     else       i = 0;     for (i = i; i < N; i += 2) {       R = R + S[i];     }     cout << R << endl;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();     if (flag) x = -x;   }   using namespace std;   int n, q, nn;   bitset<2011> bt[1011][2], h[2011];   int htot;   int ans[2011], pos[2011];   inline void Gauss() {     int nw = 1;     for (int i = 1; i < nn; ++i) {       int id = -1;       for (int hang = nw; hang <= htot; ++hang)         if (h[hang][i]) {           id = hang;           break;         }       if (id == -1) continue;       swap(h[id], h[nw]);       pos[i] = nw;       for (int hang = 1; hang <= htot; ++hang)         if (hang != nw && h[hang][i]) {           h[hang] = h[hang] ^ h[nw];         }       ++nw;       if (nw > htot) break;     }     for (int i = 1; i <= htot; ++i)       if (h[i][nn]) {         bool flag = false;         for (int j = 1; j < nn; ++j)           if (h[i][j]) {             flag = true;             break;           }         if (!flag) {           puts( NO );           exit(0);         }       }     for (int i = 1; i < nn; ++i) {       ans[i] = h[pos[i]][nn];     }     puts( YES );     for (int i = 1; i <= n; ++i) {       if (ans[i] == 0 && ans[i + n] == 0)         putchar( . );       else if (ans[i] == 1 && ans[i + n] == 0)         putchar( R );       else if (ans[i] == 0 && ans[i + n] == 1)         putchar( B );       else         putchar( Y );     }     putchar(  n );   }   int main() {     read(n), read(q);     nn = n + n + 1;     for (int i = 1; i <= n; ++i) bt[i][0][i] = bt[i][1][i + n] = 1;     for (int i = 1; i <= q; ++i) {       char opt[6];       scanf( %s , opt);       if (opt[0] ==  m ) {         int k;         read(k);         htot += 2;         for (int j = 1; j <= k; ++j) {           int p;           read(p);           h[htot - 1] ^= bt[p][0];           h[htot] ^= bt[p][1];         }         char res[3];         scanf( %s , res);         if (res[0] ==  W )           h[htot - 1][nn] = 0, h[htot][nn] = 0;         else if (res[0] ==  R )           h[htot - 1][nn] = 1, h[htot][nn] = 0;         else if (res[0] ==  B )           h[htot - 1][nn] = 0, h[htot][nn] = 1;         else           h[htot - 1][nn] = 1, h[htot][nn] = 1;       } else if (opt[0] ==  R  && opt[1] ==  Y ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           bt[p][1] = bt[p][1] ^ bt[p][0];         }       } else if (opt[0] ==  R  && opt[1] ==  B ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           swap(bt[p][0], bt[p][1]);         }       } else if (opt[0] ==  Y  && opt[1] ==  B ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           bt[p][0] = bt[p][0] ^ bt[p][1];         }       }     }     Gauss();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, t, n, k, a, b;   double v;   string line;   char s[4];   int main() {     while (cin >> n >> a >> b) {       if (b < 0) b = n + b;       a = a + b;       a = a % n;       if (a == 0)         a = n;       else if (a < 0)         a = n + a;       cout << a;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   pair<int, int> p[N];   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int i = 0, j = 0;     while (j < n) {       if (a[i] < a[j]) i++;       j++;     }     cout << i << endl;     return 0;   }


#include <bits/stdc++.h>   const int INF = (int)1e9;   using namespace std;   const int MAX = 1e3 + 5;   int n, xa, ya, xb, yb;   pair<pair<int, int>, int> arr[MAX];   vector<pair<int, int> > vec;   bool covered(int x1, int y1, int x2, int y2, int R) {     double dist = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));     return dist <= (double)R;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> xa >> ya >> xb >> yb >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second;     }     if (xa > xb) swap(xa, xb);     if (ya > yb) swap(ya, yb);     for (int i = ya; i <= yb; i++) {       vec.push_back(make_pair(xa, i));       vec.push_back(make_pair(xb, i));     }     for (int i = xa + 1; i < xb; i++) {       vec.push_back(make_pair(i, ya));       vec.push_back(make_pair(i, yb));     }     int res = 0;     for (int i = 0; i < vec.size(); i++) {       bool flag = false;       for (int j = 0; j < n; j++) {         if (covered(vec[i].first, vec[i].second, arr[j].first.first,                     arr[j].first.second, arr[j].second)) {           flag = true;           break;         }       }       if (!flag) res++;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, m, fa[N], f[N], d[N], head[N], xx, yy, ww, fr[N];   int ans;   bool in[N], c[N];   struct nd {     int x, y, w, id;   } a[N];   bool operator<(nd a, nd b) { return a.w < b.w || (a.w == b.w && a.id < b.id); }   struct ndd {     int ne, to, w;   } e[N];   void ins(int x, int y, int w) {     static int cnt;     e[++cnt].to = y;     e[cnt].ne = head[x];     head[x] = cnt;     e[cnt].w = w;   }   int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }   void dfs(int x) {     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != f[x]) {         int y = e[i].to;         f[y] = x;         d[y] = d[x] + 1;         fr[y] = e[i].w;         dfs(y);       }   }   void col(int x, int b) {     c[x] = 1;     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != b) {         int y = e[i].to;         col(y, x);       }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].w);       a[i].id = i;     }     xx = a[1].x, yy = a[1].y, ww = a[1].w;     sort(a + 1, a + m + 1);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       int fx = gf(a[i].x), fy = gf(a[i].y);       if (fx != fy) {         fa[fx] = fy;         in[a[i].id] = 1;         ins(a[i].x, a[i].y, a[i].w);         ins(a[i].y, a[i].x, a[i].w);       }     }     d[1] = 1;     dfs(1);     if (!in[1]) {       while (xx != yy) {         if (d[xx] < d[yy]) swap(xx, yy);         ans = max(ans, fr[xx]);         xx = f[xx];       }     } else {       ans = 1e9;       col(yy, xx);       for (int i = 1; i <= m; ++i)         if (!in[a[i].id]) {           if (c[a[i].x] ^ c[a[i].y]) ans = min(ans, a[i].w);         }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y, z;     point() {}     point(long long a, long long b, long long c) : x(a), y(b), z(c) {}     double operator()(point y) {       return sqrt((this->x - y.x) * (this->x - y.x) +                   (this->y - y.y) * (this->y - y.y) +                   (this->z - y.z) * (this->z - y.z));     }   };   vector<pair<int, int>> ans;   int taken[10005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long a, b, c;     point arr[n];     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       point p(a, b, c);       arr[i] = p;     }     for (int i = 0; i < n; i++) {       double minimum = 1e11;       int correct;       if (taken[i]) continue;       for (int j = 0; j < n; j++) {         if (i == j || taken[j]) continue;         double x = arr[i](arr[j]);         if (x < minimum) {           minimum = x;           correct = j;         }       }       taken[correct] = 1;       taken[i] = 1;       ans.push_back({i, correct});     }     for (int i = 0; i < n / 2; i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int d[300010];   int h[300010];   pair<long long, int> L[8 * 300010];   pair<long long, int> R[8 * 300010];   void aggL(int nodo, int left, int right, int pos, long long val) {     if (left == right) {       L[nodo] = pair<long long, int>(val, pos);       return;     }     int mid = (left + right) / 2;     if (pos <= mid)       aggL(nodo * 2, left, mid, pos, val);     else       aggL(nodo * 2 + 1, mid + 1, right, pos, val);     L[nodo] = max(L[nodo * 2], L[nodo * 2 + 1]);   }   void aggR(int nodo, int left, int right, int pos, long long val) {     if (left == right) {       R[nodo] = pair<long long, int>(val, pos);       return;     }     int mid = (left + right) / 2;     if (pos <= mid)       aggR(nodo * 2, left, mid, pos, val);     else       aggR(nodo * 2 + 1, mid + 1, right, pos, val);     R[nodo] = max(R[nodo * 2], R[nodo * 2 + 1]);   }   pair<long long, int> qL(int nodo, int left, int right, int l, int r) {     if (left == l && right == r) return L[nodo];     int mid = (left + right) / 2;     if (r <= mid) return qL(nodo * 2, left, mid, l, r);     if (l >= mid + 1) return qL(nodo * 2 + 1, mid + 1, right, l, r);     if (l <= mid && r >= mid + 1)       return max(qL(nodo * 2, left, mid, l, mid),                  qL(nodo * 2 + 1, mid + 1, right, mid + 1, r));   }   pair<long long, int> qR(int nodo, int left, int right, int l, int r) {     if (left == l && right == r) return R[nodo];     int mid = (left + right) / 2;     if (r <= mid) return qR(nodo * 2, left, mid, l, r);     if (l >= mid + 1) return qR(nodo * 2 + 1, mid + 1, right, l, r);     if (l <= mid && r >= mid + 1)       return max(qR(nodo * 2, left, mid, l, mid),                  qR(nodo * 2 + 1, mid + 1, right, mid + 1, r));   }   int main() {     ifstream in( input.txt );     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> d[i];     for (int i = 0; i < N; i++) cin >> h[i];     for (int i = 0; i < 8 * 300010; i++) L[i].first = R[i].first = LLONG_MIN;     long long temp = 0;     for (int i = 0; i < N; i++) {       aggR(1, 0, 2 * 300010 - 1, i, temp + h[i] * 2);       aggL(1, 0, 2 * 300010 - 1, i, h[i] * 2 - temp);       temp += d[i];     }     for (int i = 0; i < N; i++) {       aggR(1, 0, 2 * 300010 - 1, i + N, temp + h[i] * 2);       aggL(1, 0, 2 * 300010 - 1, i + N, h[i] * 2 - temp);       temp += d[i];     }     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       if (a <= b) {         temp = qR(1, 0, 2 * 300010 - 1, b + 2, N + a - 1).first;         int pos = qR(1, 0, 2 * 300010 - 1, b + 2, N + a - 1).second;         temp += qL(1, 0, 2 * 300010 - 1, b + 1, pos - 1).first;         long long res = temp;         temp = qL(1, 0, 2 * 300010 - 1, b + 1, N + a - 2).first;         pos = qL(1, 0, 2 * 300010 - 1, b + 1, N + a - 2).second;         temp += qR(1, 0, 2 * 300010 - 1, pos + 1, N + a - 1).first;         res = max(res, temp);         cout << res << endl;       } else {         temp = qR(1, 0, 2 * 300010 - 1, b + 2, a - 1).first;         int pos = qR(1, 0, 2 * 300010 - 1, b + 2, a - 1).second;         temp += qL(1, 0, 2 * 300010 - 1, b + 1, pos - 1).first;         long long res = temp;         temp = qL(1, 0, 2 * 300010 - 1, b + 1, a - 2).first;         pos = qL(1, 0, 2 * 300010 - 1, b + 1, a - 2).second;         temp += qR(1, 0, 2 * 300010 - 1, pos + 1, a - 1).first;         res = max(res, temp);         cout << res << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200005, INF = 2000000000000000000;   long double pi = 3.1415926535897932;   long long powere(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   void copy(long long a[2][2], long long b[2][2]) {     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 2; j++) b[i][j] = a[i][j];     }   }   void matmult(long long m1[2][2], long long m2[2][2], long long m3[2][2]) {     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 2; j++) {         m3[i][j] = 0;         for (long long k = 0; k < 2; k++) {           m3[i][j] +=               (m1[i][k] % 1000000007 * m2[k][j] % 1000000007) % 1000000007;           m3[i][j] %= 1000000007;         }       }     }   }   void power(long long mat[2][2], long long b, long long p,              long long finres[2][2]) {     long long res[2][2] = {{0}}, cc[2][2];     res[0][0] = res[1][1] = 1;     while (b > 0) {       copy(res, cc);       if (b & 1) matmult(mat, cc, res);       copy(mat, cc);       b >>= 1;       matmult(cc, cc, mat);     }     copy(res, finres);   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(std::numeric_limits<double>::max_digits10);     ;     long long t;     cin >> t;     while (t--) {       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long x = abs(x1 - x2), y = abs(y1 - y2);       if (y < x) swap(x, y);       long long ans = (x * (x + 1));       ans += ((y - x - 1) * x);       cout << ans + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void fun(long long int a, long long int b, long long int u,            vector<long long int> &t) {     long long int i, j, k, n;     for (i = 1; i < b; i++) {       if (u) t[i]++;     }     u = 1 - u;     i = b;     while (i < 1000) {       for (j = 0; j < a; j++) {         if (i >= 1000) return;         if (u) t[i]++;         i++;       }       u = 1 - u;     }   }   void solve() {     long long int i, j, k, n;     cin >> n;     string s;     cin >> s;     vector<pair<long long int, long long int> > v(n);     vector<long long int> t(1000, 0);     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) t[0]++;     }     for (i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;     }     for (i = 0; i < n; i++) {       fun(v[i].first, v[i].second, s[i] -  0 , t);     }     long long int mx = t[0];     for (i = 1; i < (int)t.size(); i++) mx = max(mx, t[i]);     cout << mx;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, x, y;   char type;   map<int, pair<char, int> > Data;   int solve() {     auto fi = Data.lower_bound(x);     if (fi->first == x) return 0;     if (type ==  L ) fi--;     int ans = abs(x - fi->first);     if (fi->second.first == type) ans += fi->second.second;     Data[x] = make_pair(type, ans);     return ans;   }   int main() {     scanf( %d %d , &n, &q);     Data[0] = make_pair( U , 0);     Data[n + 1] = make_pair( L , 0);     while (q--) {       cin >> x >> y >> type;       printf( %d n , solve());     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 15, N = 15;   int m, n;   pair<int, int> a[M], b[N];   vector<int> tot, cur;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> m >> n;     for (int i = 1; i <= m; i++) {       cin >> a[i].first >> a[i].second;     }     for (int i = 1; i <= n; i++) {       cin >> b[i].first >> b[i].second;     }     for (int i = 1; i <= m; i++) {       cur.clear();       for (int j = 1; j <= n; j++) {         int cnt = 0;         if (a[i].first == b[j].first || a[i].first == b[j].second) {           cnt++;         }         if (a[i].second == b[j].first || a[i].second == b[j].second) {           cnt++;         }         if (cnt == 1) {           if (a[i].first == b[j].first || a[i].first == b[j].second) {             cur.push_back(a[i].first);           } else {             cur.push_back(a[i].second);           }         }       }       sort(cur.begin(), cur.end());       cur.erase(unique(cur.begin(), cur.end()), cur.end());       if (cur.size() >= 2) {         return cout << -1, 0;       } else if (cur.size() == 1) {         tot.push_back(cur[0]);       }     }     for (int i = 1; i <= n; i++) {       cur.clear();       for (int j = 1; j <= m; j++) {         int cnt = 0;         if (b[i].first == a[j].first || b[i].first == a[j].second) {           cnt++;         }         if (b[i].second == a[j].first || b[i].second == a[j].second) {           cnt++;         }         if (cnt == 1) {           if (b[i].first == a[j].first || b[i].first == a[j].second) {             cur.push_back(b[i].first);           } else {             cur.push_back(b[i].second);           }         }       }       sort(cur.begin(), cur.end());       cur.erase(unique(cur.begin(), cur.end()), cur.end());       if (cur.size() >= 2) {         return cout << -1, 0;       } else if (cur.size() == 1) {         tot.push_back(cur[0]);       }     }     sort(tot.begin(), tot.end());     tot.erase(unique(tot.begin(), tot.end()), tot.end());     if (tot.size() >= 2) {       cout << 0;     } else {       cout << tot[0];     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, t, i;     cin >> t;     for (i = 0; i < t; i++) {       cin >> a >> b;       cout << a + b;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k, b, n, t, ans, cur;   int main() {     ios_base::sync_with_stdio(0);     cin >> k >> b >> n >> t;     ans = n;     cur = k + b;     while (cur <= t) {       cur = cur * k + b;       --ans;     }     if (ans < 0) ans = 0;     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n, q, L[maxn << 2], R[maxn << 2];   double sum[maxn << 2], add[maxn << 2], mul[maxn << 2];   void pushup(int o) { sum[o] = sum[o * 2] + sum[o * 2 + 1]; }   void pushdown(int o) {     sum[o * 2] = sum[o * 2] * mul[o] + add[o] * (R[o * 2] - L[o * 2] + 1);     sum[o * 2 + 1] =         sum[o * 2 + 1] * mul[o] + add[o] * (R[o * 2 + 1] - L[o * 2 + 1] + 1);     add[o * 2] = add[o * 2] * mul[o] + add[o];     add[o * 2 + 1] = add[o * 2 + 1] * mul[o] + add[o];     mul[o * 2] = mul[o * 2] * mul[o];     mul[o * 2 + 1] = mul[o * 2 + 1] * mul[o];     mul[o] = 1;     add[o] = 0;   }   void build(int o, int l, int r) {     L[o] = l;     R[o] = r;     add[o] = 0;     mul[o] = 1;     if (l == r) {       cin >> sum[o];       return;     }     int mid = (l + r) >> 1;     build(o * 2, l, mid);     build(o * 2 + 1, mid + 1, r);     pushup(o);   }   double query(int o, int l, int r, int x, int y) {     if (x <= l && r <= y) {       return sum[o];     }     pushdown(o);     int mid = (l + r) >> 1;     double res = 0.0;     if (x <= mid) res += query(o * 2, l, mid, x, y);     if (y > mid) res += query(o * 2 + 1, mid + 1, r, x, y);     return res;   }   void update1(int o, int l, int r, int x, int y, double v) {     if (x <= l && r <= y) {       sum[o] += v * (r - l + 1);       add[o] += v;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (x <= mid) update1(o * 2, l, mid, x, y, v);     if (y > mid) update1(o * 2 + 1, mid + 1, r, x, y, v);     pushup(o);   }   void update2(int o, int l, int r, int x, int y, double v) {     if (x <= l && r <= y) {       add[o] *= v;       sum[o] *= v;       mul[o] *= v;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (x <= mid) update2(o * 2, l, mid, x, y, v);     if (y > mid) update2(o * 2 + 1, mid + 1, r, x, y, v);     pushup(o);   }   int main() {     scanf( %d%d , &n, &q);     build(1, 1, n);     while (q--) {       int l1, r1, l2, r2;       int id;       scanf( %d , &id);       if (id == 1) {         scanf( %d%d%d%d , &l1, &r1, &l2, &r2);         double sum1 = query(1, 1, n, l1, r1), sum2 = query(1, 1, n, l2, r2);         double len1 = r1 - l1 + 1, len2 = r2 - l2 + 1;         update2(1, 1, n, l1, r1, (len1 - 1) / len1);         update2(1, 1, n, l2, r2, (len2 - 1) / len2);         update1(1, 1, n, l1, r1, 1.0 / len1 * (sum2 / len2));         update1(1, 1, n, l2, r2, 1.0 / len2 * (sum1 / len1));       } else {         scanf( %d%d , &l1, &r1);         printf( %.7lf n , query(1, 1, n, l1, r1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void connected(vector<vector<bool> > chu, vector<bool>& v, int s) {     v[s] = 1;     for (int i = 0; i < chu.size(); i++) {       if (chu[s][i] && !v[i]) {         connected(chu, v, i);       }     }   }   int main() {     int n, m;     while (cin >> n >> m) {       if (n != m) {         cout <<  NO  << endl;         break;       }       vector<vector<bool> > chu(n, vector<bool>(n, 0));       for (int i = 0; i < m; i++) {         int e1, e2;         cin >> e1 >> e2;         chu[e1 - 1][e2 - 1] = 1;         chu[e2 - 1][e1 - 1] = 1;       }       vector<bool> visisted(n, 0);       connected(chu, visisted, 0);       bool allseen = true;       for (int i = 0; i < visisted.size(); i++) {         if (!visisted[i]) allseen = false;       }       if (allseen) {         cout <<  FHTAGN!  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 Rand(time(0));   const int maxn = 1e5 + 5;   const long long maxc = 1e9 + 7;   int n, m, d, a[maxn];   long long sum[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d >> m;     for (int i = (1); i <= (n); ++i) cin >> a[i];     sort(a + 1, a + n + 1);     for (int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] + a[i];     if (a[n] <= m) return cout << sum[n], 0;     int id = upper_bound(a + 1, a + n + 1, m) - a;     long long res = a[n] + sum[id - 1];     long long ans = res;     for (int i = (n - 1); i >= (id); --i) {       if (1LL * (n - i) * d > n) continue;       int r = (n - i) * d;       if (r - (i - id) < id) {         ans = max(ans, res + sum[n - 1] - sum[i - 1] - sum[max(0, r - (i - id))]);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const long long llinf = 1e18;   const long long nax = 0;   int n, m, batas;   vector<pair<int, int>> shift;   set<char> simpen;   map<char, bool> sabi;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> m >> batas;     char arr[n + 5][m + 5];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> arr[i][j];         if (arr[i][j] ==  S ) {           shift.push_back({i, j});         } else {           simpen.insert(arr[i][j]);         }       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         for (auto x : shift) {           int x1 = i, x2 = x.first, y1 = j, y2 = x.second;           int hitung = ceil(sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));           if (hitung <= batas) {             sabi[arr[i][j]] = 1;           }         }       }     }     int q, ans = 0;     cin >> q;     string s;     cin >> s;     for (int k = 0; k < q; ++k) {       if (s[k] >= 97) {         if (!simpen.count(s[k])) {           cout <<  -1  <<   n ;           return 0;         } else           continue;       } else {         if (shift.empty()) {           cout <<  -1  <<   n ;           return 0;         }         bool ok = 0, ada = 0;         if (!simpen.count(s[k] + 32)) {           cout <<  -1  <<   n ;           return 0;         } else {           if (sabi[s[k] + 32])             continue;           else             ans++;         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55, mod = 1LL * 1000 * 1000 * 1000 + 7;   int dp[N][N][2], ans[N][N][2], n, cnt50, cnt100, W, c[N][N], seen[N][N];   bool vis[N][N][2], vis2[N][N][2];   int C(int r, int n) {     if (r == 0 || r == n) return 1;     if (r > n) return 0;     if (seen[r][n]) return c[r][n];     seen[r][n] = true;     return c[r][n] = (C(r - 1, n - 1) + C(r, n - 1)) % mod;   }   int dfs(int x, int y, int tp) {     if (vis2[x][y][tp]) return ans[x][y][tp];     vis2[x][y][tp] = true;     if (tp) {       for (int i = 0; i <= cnt50 - x; i++)         for (int j = 0; j <= cnt100 - y; j++)           if (i * 50 + j * 100 <= W && (i || j) &&               dp[x][y][tp] == dp[x + i][y + j][!tp] + 1)             (ans[x][y][tp] += 1LL * dfs(x + i, y + j, !tp) * C(i, cnt50 - x) %                               mod * C(j, cnt100 - y) % mod) %= mod;     } else {       for (int i = 0; i <= x; i++)         for (int j = 0; j <= y; j++)           if ((i || j) && i * 50 + j * 100 <= W &&               dp[x][y][tp] == dp[x - i][y - j][!tp] + 1)             (ans[x][y][tp] +=              1LL * dfs(x - i, y - j, !tp) * C(i, x) % mod * C(j, y) % mod) %= mod;     }     return ans[x][y][tp];   }   struct Node {     int x = 0, y = 0, tp = 0;     Node(int a = 0, int b = 0, int c = 0) { x = a, y = b, tp = c; }   };   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < 2; k++) dp[i][j][k] = 1 << 29;     cin >> n >> W;     for (int i = 0, a; i < n; i++) {       cin >> a;       cnt50 += (a == 50);       cnt100 += (a == 100);     }     dp[0][0][0] = dp[0][0][1] = 0;     vis[0][0][0] = vis[0][0][1] = true;     ans[0][0][0] = ans[0][0][1] = 1;     queue<Node> q;     q.push(Node(0, 0, 0)), q.push(Node(0, 0, 1));     while (q.size()) {       Node tmp = q.front();       q.pop();       int x = tmp.x, y = tmp.y, tp = tmp.tp;       if (tp) {         for (int i = 0; i <= cnt50 - x; i++)           for (int j = 0; j <= cnt100 - y; j++)             if (i * 50 + j * 100 <= W && (i || j) && !vis[x + i][y + j][!tp]) {               q.push(Node(x + i, y + j, !tp));               dp[x + i][y + j][!tp] = dp[x][y][tp] + 1;               vis[x + i][y + j][!tp] = true;             }       } else {         for (int i = 0; i <= x; i++)           for (int j = 0; j <= y; j++)             if ((i || j) && i * 50 + 100 * j <= W && !vis[x - i][y - j][!tp]) {               q.push(Node(x - i, y - j, !tp));               dp[x - i][y - j][!tp] = dp[x][y][tp] + 1;               vis[x - i][y - j][!tp] = true;             }       }     }     dfs(cnt50, cnt100, 0);     if (dp[cnt50][cnt100][0] >= (1 << 29)) dp[cnt50][cnt100][0] = -1;     cout << dp[cnt50][cnt100][0] <<   n  << ans[cnt50][cnt100][0] <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int N, M, dbg[100005];   pair<int, int> A[100005];   map<int, int> mp;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a;       scanf( %d , &a);       mp[a]++;     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)       A[M++] = *it;     for (int i = 1; i < M; i++)       if (A[i].first != A[i - 1].first + 1) {         puts( NO );         return 0;       }     int p = 0;     for (int i = 0; i < M; i++) {       A[i].second--;       dbg[p++] = A[i].first;     }     for (int i = M - 1; i > 1; i--) {       while (A[i].second) {         if (!A[i - 1].second) {           puts( NO );           return 0;         }         A[i - 1].second--;         A[i].second--;         dbg[p++] = A[i - 1].first;         dbg[p++] = A[i].first;       }       if (!A[i - 1].second) {         puts( NO );         return 0;       }       A[i - 1].second--;       dbg[p++] = A[i - 1].first;     }     while (A[1].second) {       if (!A[0].second) {         puts( NO );         return 0;       }       A[0].second--;       A[1].second--;       dbg[p++] = A[0].first;       dbg[p++] = A[1].first;     }     if (A[0].second) {       puts( NO );       return 0;     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010];   int n;   bool check(int len) {     int now = 0, lft = 0;     bool flag = 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  R ) {         flag = 0;         if (now + 1 != len) now++;       } else         now--;       if (now < lft) {         lft = now;         flag = 1;       }     }     return flag;   }   int main() {     scanf( %s , s);     n = strlen(s);     if (s[n - 1] ==  R ) {       for (int i = 0; i < n; i++) {         if (s[i] ==  R )           s[i] =  L ;         else           s[i] =  R ;       }     }     if (check(n + 5)) {       puts( 1 );       return 0;     }     int l = 0, r = n + 5, ret = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ret = mid, l = mid + 1;       else         r = mid - 1;     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, flag;   vector<int> graph[100005];   bool vis[100005];   void dfs(int node, int parent) {     vis[node] = 1;     int x, u, v, i;     cnt++;     for (i = 0; i < graph[node].size(); i++) {       v = graph[node][i];       if (v == parent) continue;       if (vis[v] == 1)         flag = 1;       else         dfs(v, node);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int i, j, k, u, v, x, sum = 0;     for (i = 0; i < m; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     for (i = 1; i <= n; i++) {       if (vis[i] == 0) {         cnt = 0;         flag = 0;         dfs(i, 0);         if (flag == 1)           sum += cnt;         else           sum += (cnt - 1);       }     }     cout << n - sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> g(n);     int mm = 99999;     for (int i = 0; i < n; i++) {       cin >> g[i];       mm = min(mm, abs(g[i]));     }     sort(g.begin(), g.end());     int rest = k;     for (int i = 0; i < k; i++) {       if (i < g.size() && g[i] < 0) {         g[i] = -g[i];         rest--;       }     }     int ans = 0;     for (int i = 0; i < g.size(); i++) {       ans += g[i];     }     if (rest % 2) {       ans -= 2 * mm;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> g[500010];   int rad[2][500010], tata[500010], niv[500010];   char in[500010], vaz[500010], tip[500010];   struct edge {     int x, y, c;   };   edge v[500010];   int radacina(int x, int t) {     int y = x;     while (y != rad[t][y]) y = rad[t][y];     while (rad[t][x] != y) {       int aux = rad[t][x];       rad[t][x] = y;       x = aux;     }     return y;   }   void unite(int x, int y) {     x = radacina(x, 0);     y = radacina(y, 0);     rad[0][x] = y;   }   void dfs(int nod) {     vaz[nod] = 1;     for (int i = 0; i < g[nod].size(); i++) {       int vec = g[nod][i].first;       if (vaz[vec] == 1) continue;       niv[vec] = niv[nod] + 1;       tata[vec] = nod;       tip[vec] = g[nod][i].second;       dfs(vec);     }   }   int main() {     int n, k, m, x, y;     long long sol = 0;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= n; i++) rad[0][i] = rad[1][i] = i;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       unite(x, y);       g[x].push_back({y, 1});       g[y].push_back({x, 1});     }     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &v[i].x, &v[i].y, &v[i].c);       if (radacina(v[i].x, 0) != radacina(v[i].y, 0)) {         unite(v[i].x, v[i].y);         in[i] = 1;         g[v[i].x].push_back({v[i].y, 0});         g[v[i].y].push_back({v[i].x, 0});       }     }     dfs(1);     tata[1] = 1;     int nr = 0;     for (int i = 1; i <= m; i++) {       if (in[i] == 1) continue;       x = v[i].x;       y = v[i].y;       x = radacina(x, 1);       y = radacina(y, 1);       while (x != y) {         if (niv[x] < niv[y]) swap(x, y);         sol += tip[x] * v[i].c;         nr += tip[x];         rad[1][x] = tata[x];         x = radacina(x, 1);       }     }     if (nr < k)       printf( -1 );     else       printf( %I64d , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long rot = 0;     long long last = 0;     long long ans;     for (int i = 0; i < m; i++) {       long long t;       cin >> t;       if (last > t) {         rot++;       }       last = t;     }     ans = rot * n + last - 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(int y) {     return y % 400 == 0 ? 2 : y % 100 == 0 ? 1 : y % 4 == 0 ? 2 : 1;   }   int main() {     int n, r = 0, t;     scanf( %d , &n);     t = f(n);     while (r % 7 != 0 || r == 0 || t != f(n)) {       r += f(n);       n++;     }     printf( %d n , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long binSearch(long long n, long long pow2) {     long long L = 0, R = (n / pow2) + 10, M;     while (R - L > 1) {       M = (L + R) / 2;       double dM = M + 0.0;       if ((2.0 * dM + 1.0) * (pow2 + dM - 1.0) < n + 0.0)         L = M;       else         R = M;     }     if ((2 * L + 1) * (pow2 + L - 1) == n)       return L;     else if ((2 * R + 1) * (pow2 + R - 1) == n)       return R;     else       return -1;   }   int main() {     long long n;     cin >> n;     vector<long long> result;     for (long long pow2 = 1; pow2 - 1 <= n; pow2 *= 2) {       long long v = binSearch(n, pow2);       if (v != -1) result.push_back((2 * v + 1) * pow2);     }     sort(result.begin(), result.end());     if (result.size() == 0)       cout << -1;     else {       for (int i = 0; i < result.size(); i++) cout << result[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) { return a > b ? a : b; }   pair<int, int> a[100], ans[1000], p;   vector<pair<int, int>> v;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     int i = 0;     while (i < k) {       if (a[0].first - a[n - 1].first >= -1) break;       a[0].first++;       a[n - 1].first--;       p.first = a[0].second;       p.second = a[n - 1].second;       v.push_back(p);       sort(a, a + n);       i++;     }     cout << a[n - 1].first - a[0].first <<     << i << endl;     for (int k = 0; k < i; k++) {       cout << v[k].second <<     << v[k].first << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<double> E[100010];   int color[100010];   int seen[100010];   set<int> sets[100010];   void dfs(int u) {     for (int i = 0; i < E[u].size(); ++i) {       int v = E[u][i];       if (color[u] != color[v]) sets[color[u]].insert(color[v]);       if (!seen[v]) {         seen[v] = true;         dfs(v);       }     }   }   int main() {     int n, m, u, v;     cin >> n >> m;     set<int> colorids;     for (int i = 0; i < n; ++i) {       cin >> color[i];       colorids.insert(color[i]);     }     for (int i = 0; i < m; ++i) {       cin >> u >> v;       --u;       --v;       E[u].push_back(v);       E[v].push_back(u);     }     memset(seen, 0, sizeof(seen));     for (int i = 0; i < n; ++i)       if (!seen[i]) {         seen[i] = true;         dfs(i);       }     int maxcolor = -1;     int maxn = -(1 << 30);     for (typeof(colorids.begin()) it = colorids.begin(); it != colorids.end();          ++it) {       int color = *it;       int ncolors = sets[*it].size();       if (maxn < ncolors) {         maxn = ncolors;         maxcolor = *it;       }     }     cout << maxcolor << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     cout << (a + b + c) * (a + b + c) - (a * a + c * c + e * e);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 1e6 + 100;   ll n;   ll m;   ll **arr() {     ll **res = new ll *[n + 2];     for (ll i = 0; i < n + 2; ++i) {       res[i] = new ll[m + 2];       fill_n(res[i], m + 2, 0);     }     return res;   }   ll **inp;   ll **ans;   void pref(ll **a) {     for (ll i = 1; i <= n + 1; ++i) {       for (ll j = 1; j <= m + 1; ++j) {         a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];       }     }   }   ll sum(ll **a, ll il, ll ir, ll jl, ll jr) {     il = max(il, 1ll);     ir = min(ir, n);     jl = max(jl, 1ll);     jr = min(jr, m);     --il;     --jl;     return a[ir][jr] - a[ir][jl] - a[il][jr] + a[il][jl];   }   ll sq(ll first) { return first * first; }   bool check(ll t) {     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         ans[i][j] = sum(inp, i - t, i + t, j - t, j + t) == sq(2 * t + 1);       }     }     pref(ans);     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         if (sum(inp, i, i, j, j) && sum(ans, i - t, i + t, j - t, j + t) == 0) {           return false;         }       }     }     return true;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     inp = arr();     ans = arr();     for (ll i = 1; i <= n; ++i) {       string s;       cin >> s;       for (ll j = 1; j <= m; ++j) {         inp[i][j] = s[j - 1] ==  X ;       }     }     pref(inp);     ll lef = 0, rig = N;     while (rig - lef > 1) {       ll mid = (lef + rig) / 2;       if (check(mid)) {         lef = mid;       } else {         rig = mid;       }     }     assert(check(lef));     cout << lef <<   n ;     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         cout <<  .X [sum(ans, i, i, j, j)];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const int N = 1e3 + 5;   int f[N][N];   struct node {     long long x, y;   } a[N], b[N];   bool cmp(node x, node y) { return x.y < y.y; }   long long area(node a, node b, node c) {     return a.x * b.y - a.y * b.x + b.x * c.y - b.y * c.x + c.x * a.y - c.y * a.x;   }   bool toleft(node a, node b, node c) {     if (c.y <= a.y || c.y > b.y) return 0;     return area(a, b, c) > 0;   }   int n, m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) scanf( %lld%lld , &a[i].x, &a[i].y);     for (int i = 1; i <= m; ++i) scanf( %lld%lld , &b[i].x, &b[i].y);     sort(a + 1, a + n + 1, cmp);     int ans = 0;     for (int i = 1; i < n; ++i)       for (int j = i + 1; j <= n; ++j)         for (int k = 1; k <= m; ++k)           if (toleft(a[i], a[j], b[k])) f[i][j]++;     for (int i = 1; i < n; ++i)       for (int j = i + 1; j < n; ++j)         for (int k = j + 1; k <= n; ++k)           if (f[i][j] + f[j][k] == f[i][k]) ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int INF = 2000000000;   const long long BIG = 1446803456761533460LL;   const int maxn = 5010;   int n, m, k, dp[maxn][maxn];   int poww(int a, int b) {     int r = 1;     while (b) {       if (b & 1) r = (1LL * (r) * (a)) % MOD;       a = (1LL * (a) * (a)) % MOD;       b >>= 1;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     int mi = poww(m, MOD - 2);     dp[0][0] = 1;     for (int i = 0; i < k; ++i) {       for (int j = 0; j < k + 1; ++j) {         dp[i + 1][j] = ((dp[i + 1][j]) + (1LL * dp[i][j] * j % MOD)) % MOD;         dp[i + 1][j + 1] =             ((dp[i + 1][j + 1]) + (1LL * dp[i][j] * (n - j) % MOD * mi % MOD)) %             MOD;       }     }     int ans = 0;     for (int i = 0; i < k + 1; ++i) ans = ((ans) + (dp[k][i])) % MOD;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400000;   int a[N], t[N], type[N], us[N];   int main() {     ios::sync_with_stdio(0);     int n, w, k;     cin >> n >> w >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> t[i];     }     int r = -1;     int curr_time = 0;     int earn = 0;     set<pair<int, int> > half, full;     int ans = 0;     for (int i = 0; i < n; i++) {       r = max(r, i - 1);       while (r < n - 1) {         r++;         int temp = curr_time;         vector<pair<int, int> > pers_full, pers_half, pers_type;         half.insert(make_pair(t[r], r));         pers_half.push_back(make_pair(+1, r));         pers_type.push_back(make_pair(r, type[r]));         type[r] = 0;         curr_time += (t[r] + 1) / 2;         if (half.size() > w) {           auto p = *half.begin();           curr_time -= (p.first + 1) / 2;           half.erase(half.find(p));           pers_half.push_back(make_pair(-1, p.second));           curr_time += p.first;           full.insert(p);           pers_full.push_back(make_pair(+1, p.second));           pers_type.push_back(make_pair(p.second, type[p.second]));           type[p.second] = 1;         }         if (curr_time > k) {           while (pers_full.size()) {             auto p = pers_full.back();             pers_full.pop_back();             if (p.first == -1)               full.insert(make_pair(t[p.second], p.second));             else               full.erase(make_pair(t[p.second], p.second));           }           while (pers_half.size()) {             auto p = pers_half.back();             pers_half.pop_back();             if (p.first == -1)               half.insert(make_pair(t[p.second], p.second));             else               half.erase(make_pair(t[p.second], p.second));           }           while (pers_type.size()) {             auto p = pers_type.back();             pers_type.pop_back();             type[p.first] = p.second;           }           curr_time = temp;           r--;           break;         } else {           earn += a[r];           us[r] = 1;         }       }       ans = max(earn, ans);       if (us[i] == 1) {         if (type[i] == 0) {           half.erase(make_pair(t[i], i));           curr_time -= (t[i] + 1) / 2;         } else {           full.erase(make_pair(t[i], i));           curr_time -= t[i];         }         earn -= a[i];         us[i] = 0;         while (full.size() && half.size() < w) {           auto p = *full.rbegin();           full.erase(full.find(p));           half.insert(p);           curr_time -= p.first;           curr_time += (p.first + 1) / 2;           type[p.second] = 0;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using pii = pair<ll, int>;   const int INF = 1e9 + 1e2;   void fin() {}   const bool flag = 0;   const int N = 1e5 + 10;   int MOD;   int mult(ll a, ll b) { return a * 1ll * b % MOD; }   ll binpow(ll a, int b) {     ll res = 1;     while (b) {       if (b & 1) {         res = mult(res, a);       }       a = mult(a, a);       b >>= 1;     }     return res;   }   vector<pii> adj[N];   int sz[N], po[N];   bool cent[N];   void calc_sz(int first, int p = -1) {     sz[first] = 1;     for (pii to : adj[first]) {       if (to.first != p && !cent[to.first]) {         calc_sz(to.first, first);         sz[first] += sz[to.first];       }     }   }   int c_sz;   int fnd(int first, int p = -1) {     for (pii to : adj[first]) {       if (to.first != p && !cent[to.first] && sz[to.first] > c_sz / 2) {         return fnd(to.first, first);       }     }     return first;   }   ll ans;   int add(ll a, int b) { return (a + b + MOD) % MOD; }   map<int, ll> cnt;   void dfsadd(int first, int d, int r, int p = -1) {     cnt[r]++;     for (pii to : adj[first]) {       if (to.first != p && !cent[to.first]) {         dfsadd(to.first, d + 1, add(r, mult(po[d], to.second)), first);       }     }   }   void dfscalc(int first, int d, int r1, int r2, int p = -1) {     ans += (r1 == 0) + (r2 == 0);     for (pii to : adj[first]) {       if (to.first != p && !cent[to.first]) {         dfscalc(to.first, d + 1, add(mult(r1, 10), to.second),                 add(r2, mult(po[d], to.second)), first);       }     }   }   int phi;   void dfsget(int first, int d, int r, int p = -1) {     int inv = mult(MOD - r, binpow(po[d], phi - 1));     ans += cnt[inv];     for (pii to : adj[first]) {       if (to.first != p && !cent[to.first]) {         dfsget(to.first, d + 1, add(mult(r, 10), to.second), first);       }     }   }   void solve(int first = 0) {     calc_sz(first);     c_sz = sz[first];     first = fnd(first);     cent[first] = 1;     for (pii to : adj[first]) {       if (!cent[to.first]) {         dfsget(to.first, 1, to.second);         dfsadd(to.first, 1, to.second);         dfscalc(to.first, 1, to.second, to.second);       }     }     cnt.clear();     reverse((adj[first]).begin(), (adj[first]).end());     for (pii to : adj[first]) {       if (!cent[to.first]) {         dfsget(to.first, 1, to.second);         dfsadd(to.first, 1, to.second);       }     }     cnt.clear();     for (pii to : adj[first]) {       if (!cent[to.first]) {         solve(to.first);       }     }   }   void ma1n() {     int n;     cin >> n >> MOD;     for (int i = 1; i < n; ++i) {       int u, v, w;       cin >> u >> v >> w;       w %= MOD;       adj[u].push_back({v, w});       adj[v].push_back({u, w});     }     int first = MOD;     phi = MOD;     for (int i = 2; i <= sqrt(first); ++i) {       if (first % i == 0) {         while (first % i == 0) {           first /= i;         }         phi -= phi / i;       }     }     if (first > 1) {       phi -= phi / first;     }     po[0] = 1;     for (int i = 1; i < N; ++i) {       po[i] = mult(po[i - 1], 10);     }     solve();     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr), fin();     int ts = 1;     if (flag) {       cin >> ts;     }     while (ts--) {       ma1n();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sePuede(int rango[], int x) {     if (x % 2 == 1 && rango[0] == 1 && rango[x - 1] == 1) return true;     return false;   }   int main() {     int x = 0;     int impar = 0;     cin >> x;     int rango[x];     for (int y = 0; y < x; y++) {       cin >> rango[y];       rango[y] = rango[y] % 2;     }     if (sePuede(rango, x))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   void go(int parent, int node, int depth, int& odd_count, int& even_count,           vector<vector<int>>& tree) {     int count = 0;     for (int i = 0; i < tree[node].size(); i++) {       if (tree[node][i] != parent) {         count++;         go(node, tree[node][i], depth + 1, odd_count, even_count, tree);       }     }     if (count == 0) {       odd_count += depth % 2;       even_count += !(depth % 2);     }   }   int main() {     int n;     scanf( %d , &n);     vector<vector<int>> tree(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       tree[u - 1].push_back(v - 1);       tree[v - 1].push_back(u - 1);     }     int root = -1;     for (int i = 0; i < tree.size(); i++) {       if (tree[i].size() > 1) {         root = i;         break;       }     }     int odd_count = 0, even_count = 0;     go(-1, root, 0, odd_count, even_count, tree);     int min_ans = 0, max_ans = n - 1;     if (!odd_count || !even_count) {       min_ans = 1;     } else {       min_ans = 3;     }     vector<int> parent_leaf_count(n, 0);     for (int i = 0; i < n; i++) {       if (tree[i].size() == 1) {         parent_leaf_count[tree[i][0]]++;       }     }     for (int i = 0; i < n; i++) {       if (parent_leaf_count[i]) {         max_ans -= (parent_leaf_count[i] - 1);       }     }     printf( %d %d n , min_ans, max_ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     bool ms = false;     string a;     string b;     if (s[0] ==  - ) ms = true;     bool flag = false;     bool p = ms;     for (int i = 0; i < s.size(); i++) {       if (p) {         p = false;         continue;       }       if (s[i] ==  . ) {         flag = true;         continue;       }       if (!flag)         a.push_back(s[i]);       else         b.push_back(s[i]);     }     int l = a.size();     if (ms) cout <<  ( ;     cout <<  $ ;     for (int i = 0; i < l; i++) {       if ((l - i) % 3 == 0 && i != 0) cout <<  , ;       cout << a[i];     }     cout <<  . ;     if (b.size() >= 2)       cout << b[0] << b[1];     else if (b.size() == 1)       cout << b[0] <<  0 ;     else       cout <<  00 ;     if (ms) cout <<  ) ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       int a[n], b[n];       for (int i = 0; i < n; i++) cin >> a[i];       string s;       cin >> s;       vector<pair<long long, pair<long long, long long>>> c(n);       for (int i = 0; i < n; i++) {         c[i].second.first = a[i];         c[i].second.second = i;         c[i].first = (s[i] -  0 );       }       sort(c.begin(), c.end());       long long cnt = 1;       for (int i = 0; i < n; i++) {         b[c[i].second.second] = cnt;         cnt++;       }       for (int i = 0; i < n; i++) {         cout << b[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp_cata[3021][5021];   int main() {     dp_cata[0][0] = 1;     for (long long j = 0; j <= 5001; j++)       for (long long i = 0; i <= 3001; i++) {         if (i == 0) {           if (j != 0) dp_cata[i][j] = dp_cata[i + 1][j - 1];         } else           dp_cata[i][j] =               (dp_cata[i + 1][j - 1] + dp_cata[i - 1][j - 1]) % 1000000007;       }     long long n, m;     string s;     cin >> n >> m >> s;     if (n % 2 != 0) {       cout << 0;       exit(0);     }     long long x = 0, y = 0;     long long lientiep = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  ( )         x++;       else         y++;       lientiep = max(lientiep, y - x);     }     if (x > n / 2 || y > n / 2) {       cout << 0;       exit(0);     }     long long X = n / 2 - x;     long long Y = n / 2 - y;     long long ans = 0;     for (int i = 0; i <= n - m; i++) {       for (int j = 0; j <= i; j++)         if (j + x >= i - j + y && j - (i - j) >= lientiep) {           if (j < i - j) continue;           ans =               (ans +                dp_cata[j - (i - j)][i] *                    dp_cata[2 * (n / 2 - (i - j + y)) - (n - m - i)][n - m - i]) %               1000000007;         }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   int G[10][10];   int p[10];   bool vis[10][10];   void dfs(int cur) {     if (cur > n) {       memset(vis, 0, sizeof(vis));       int cnt = 0;       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           if (!G[i][j]) continue;           int u = p[i];           int v = p[j];           if (!vis[u][v]) {             vis[u][v] = vis[v][u] = true;             cnt++;           }         }       }       ans = max(ans, cnt);       return;     }     for (int i = 1; i <= 6; i++) {       p[cur] = i;       dfs(cur + 1);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u][v] = G[v][u] = 1;     }     dfs(1);     printf( %d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define ld long double   #define ff first   #define ss second   #define eb emplace_back   #define pb push_back   #define mp make_pair   #define all(x) begin(x), end(x)   #define endl   n    int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, -1, 1};   // ll dp[100005];   ll mod = 1e9 + 7;   bool vis[100000];   using namespace std;   bool isPrime(ll n) {     ll j;     for ( j = 2; j <= sqrt(n); j++) {       if (n % j == 0) {         break;       }     }     if (j > sqrt(n)) {       return 1;     }     else {       return 0;     }   }   ll modexpo(ll a, ll b) {     ll ans = 1;     a = a % mod;     while (b > 0) {       if ((b & 1) == 1) {         ans = ((ans % mod) * (a % mod)) % mod;       }       b = b >> 1;       a = ((a % mod) * (a % mod)) % mod;     }     return ans;   }   ll invmod(ll n) {     return modexpo(n, mod - 2);   }      ll comb(ll n, ll r) {     if (r == 0) {       return 1;     }     ll fact[n + 1];     fact[0] = 1;     for (ll i = 1; i <= n; i++) {       fact[i] = (fact[i - 1] * i) % mod;     }     return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) % mod;   }   ll gcd(ll a, ll b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   ll lcm(ll a, ll b) {     return (a * b) / gcd(a, b);   }   void dfs(ll i, vector<ll>adj[], bool visited[]) {     visited[i] = 1;     for (auto j : adj[i]) {       if (visited[j] == 0) {         dfs(j, adj, visited);       }     }   }   bool sortbysecdesc(const pair<ll, ll> &a, const pair<ll, ll> &b)   {     return a.second > b.second;   }   void solve(ll k) {     ll n;     cin >> n;     ll w[n + 1], ans = 0;     w[0] = 0;     vector<pair<ll, ll>>p;     for (ll i = 0; i < n; i++) {       cin >> w[i + 1];       p.pb(mp(i + 1, w[i + 1]));       ans += w[i + 1];     }     ll in[n + 1];   // memset(in, -1, sizeof(in));     for (ll i = 0; i <= n; i++) {       in[i] = -1;     }     for (ll i = 0; i < n - 1; i++) {       ll u, v;       cin >> u >> v;       in[u]++, in[v]++;     }     cout << ans <<    ;     sort(p.begin(), p.end(), sortbysecdesc);     for (ll i = 0; i < p.size(); i++) {       while (in[p[i].first] > 0) {         ans += p[i].second;         cout << ans <<    ;         in[p[i].first]--;       }     }     cout << endl;   }         int main() {   #ifndef ONLINE_JUDGE     // for getting input from input.txt     freopen( input.txt ,  r , stdin);     // for writing output to output.txt     freopen( output.txt ,  w , stdout);   #endif        ios_base::sync_with_stdio(false);     cin.tie(NULL);     ll t = 1;     cin >> t;     ll k = 1;     while (k <= t) {       solve(k);       k++;     }     return 0;   }   // f3=f2-f1,f4=-f1,f5=-f2,f6=f1-f2,f7=f1,f8=f2,f9=f2-f1,


#include <bits/stdc++.h>   using namespace std;   int main() {     map<pair<int, int>, int> dat;     vector<pair<int, int> > p;     int np;     cin >> np;     int res = 0;     while (np--) {       int x, y;       cin >> x >> y;       p.push_back(make_pair(x, y));       dat[make_pair(x, y)] = 1;     }     int sz = p.size();     for (int i = 0; i < sz; i++)       for (int j = i + 1; j < sz; j++) {         double x = p[i].first + p[j].first;         double y = p[i].second + p[j].second;         x /= 2.0;         y /= 2.0;         pair<int, int> tmp;         if (fabs(x - int(x)) < 1e-9 && fabs(y - int(y)) < 1e-9) {           tmp = make_pair(int(x), int(y));           if (dat.find(tmp) != dat.end()) res++;         }       }     cout << res << endl;   }


#include <iostream>   #include <cstdio>   #define mod 998244353   #define int long long   using namespace std;   int n,k,sa[200005],rk[200005];   int num;   inline int Qpow(register int a,register int p){    if (p==0)return 1;    register int t=Qpow(a,p/2);    t=t*t%mod;    if (p%2==1)t=t*a%mod;    return t;   }   inline int inv(register int x){    return Qpow(x,mod-2);   }   inline int C(register int n,register int m){    if (n<m||m<0)return 0;    register int ans=1;    for (register int i=1;i<=n;i++)ans=ans*i%mod;    for (register int i=1;i<=m;i++)ans=ans*inv(i)%mod;    for (register int i=1;i<=n-m;i++)ans=ans*inv(i)%mod;    return ans;   }   signed main(){    cin>>n>>k;    for (register int i=1;i<=n;i++){     scanf( %d ,&sa[i]);     sa[i]++;     rk[sa[i]]=i;    }    for (register int i=1;i<n;i++)     if (rk[sa[i]+1]>rk[sa[i+1]+1])k--;    cout<<C(n+k-1,k-1)<<endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[7];   int main() {     int n, len;     string str;     scanf( %d n , &n);     for (int i = 0; i < n; i++) {       getline(cin, str);       for (int j = 0; j < 7; j++) {         arr[j] += (str[j] -  0 );       }     }     int mx = 0;     for (int i = 0; i < 7; i++) mx = max(arr[i], mx);     printf( %d n , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct P {     double x, y;   } a[259];   long long f[259][259];   int n;   int read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   double cross(P a, P b, P c) {     P x = (P){b.x - a.x, b.y - a.y};     P y = (P){c.x - a.x, c.y - a.y};     return x.x * y.y - x.y * y.x;   }   bool jud() {     double ans = 0;     for (int i = 2; i <= n; i++) ans += cross(a[1], a[i - 1], a[i]);     if (ans > 0) return 1;     return 0;   }   void rever() {     for (int i = 1; i <= n / 2; i++) swap(a[i], a[n - i + 1]);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) scanf( %lf%lf , &a[i].x, &a[i].y);     if (jud()) rever();     for (int i = 1; i <= n; i++) f[i][i + 1] = 1;     for (int l = 1; l <= n - 1; l++)       for (int i = 1; i + l <= n; i++)         for (int j = i + 1; j < i + l; j++)           f[i][i + l] =               (f[i][i + l] + f[i][j] % 1000000007 * f[j][i + l] % 1000000007 *                                  (cross(a[i], a[j], a[i + l]) < 0 ? 1 : 0)) %               1000000007;     printf( %lld n , f[1][n] % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, f, a, b;   vector<long long> V;   long long ans;   int main() {     scanf( %lld %lld , &n, &f);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a, &b);       if (a >= b) {         V.push_back(0);         ans += b;       } else {         if (a * 2 <= b) {           V.push_back(a);         } else {           V.push_back(b - a);         }         ans += a;       }     }     sort(V.begin(), V.end());     reverse(V.begin(), V.end());     for (int i = 0; i < f; i++) {       ans += V[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int customer[1000][1000];   int main() {     int n, m, k;     cin >> n >> m >> k;     deque<int> dq;     for (int i = 0; i < k; i++) {       int x;       cin >> x;       dq.push_back(x);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> customer[i][j];     }     int t = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int cnt = 0;         for (deque<int>::iterator l = dq.begin(); l != dq.end(); l++) {           cnt++;           if (*l == customer[i][j]) {             int x = *l;             dq.erase(l);             dq.push_front(x);             t += cnt;             break;           }         }       }     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       string s;       cin >> n >> s;       string an =   ;       for (int i = 0; i < s.length(); i += 2) {         cout << s[i];       }       cout << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s = bitset<32>(n).to_string();     vector<int> v;     for (int i = 31; i >= 0; i--) {       if (s[i] ==  1 ) {         v.push_back(32 - i);       }     }     reverse(v.begin(), v.end());     for (int& a : v) {       cout << a <<    ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1, i = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 42;   long long dp[N][N];   int f[N], n;   string s;   long long Solve(int x) {     memset(dp, 0, sizeof dp);     dp[0][x] = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < s.size(); j++) {         int m = j;         while (m && s[m] !=  0 ) m = f[m];         if (s[m] ==  0 ) m++;         dp[i + 1][m] += dp[i][j];         m = j;         while (m && s[m] !=  1 ) m = f[m];         if (s[m] ==  1 ) m++;         dp[i + 1][m] += dp[i][j];       }     }     return dp[n][x];   }   int main() {     cin >> n >> s;     for (int i = 2; i <= s.size(); i++) {       f[i] = f[i - 1];       while (f[i] && s[f[i]] != s[i - 1]) f[i] = f[f[i]];       if (s[f[i]] == s[i - 1]) f[i]++;     }     long long ans = 0;     for (int i = 0; i < s.size(); i++) ans += Solve(i);     cout << (1ll << n) - ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   const int hashnum = 3;   long long base[] = {233, 23, 97};   long long mod[] = {122420729, 1000000007, 1000000009};   int sum[maxn];   char s[maxn];   long long power[hashnum][maxn];   int n;   struct node {     long long hv[hashnum];     int pref, suf, len;   };   node zer;   inline void init() {     zer.pref = zer.suf = zer.len = 0;     for (int i = (0); i < (hashnum); ++i) zer.hv[i] = 0;     for (int i = (0); i < (hashnum); ++i) {       power[i][0] = 1;       for (int j = (1); j < (maxn); ++j)         power[i][j] = power[i][j - 1] * base[i] % mod[i];     }   }   node merge(node& a, node& b) {     node c = zer;     if (a.len == 0 && b.len == 0)       c.suf = c.pref = a.pref + b.pref;     else if (a.len == 0)       c = b, c.pref += a.pref;     else if (b.len == 0)       c = a, c.suf += b.pref;     else {       c.len = a.len + b.len + (a.suf + b.pref) % 2;       c.pref = a.pref;       c.suf = b.suf;       for (int i = (0); i < (hashnum); ++i) {         if ((a.suf + b.pref) % 2 == 1) {           c.hv[i] = a.hv[i] * power[i][b.len + 1] % mod[i];           (c.hv[i] += 2 * power[i][b.len] % mod[i]) %= mod[i];           (c.hv[i] += b.hv[i]) %= mod[i];         } else {           c.hv[i] = a.hv[i] * power[i][b.len] % mod[i];           (c.hv[i] += b.hv[i]) %= mod[i];         }       }     }     return c;   }   struct segtree {     node t[maxn << 2];     int n, ql, qr;     node ans;     void init(int n) { this->n = n; }     void maintain(int o) { t[o] = merge(t[o << 1], t[o << 1 | 1]); }     void build(int l, int r, int o) {       t[o] = zer;       if (l == r) {         if (s[l] ==  0 ) {           t[o].len++;           for (int i = (0); i < (hashnum); ++i) t[o].hv[i] = 1;         } else           t[o].suf = t[o].pref = 1;         return;       }       int mid = l + r >> 1;       build(l, mid, o << 1), build(mid + 1, r, o << 1 | 1);       maintain(o);     }     void query(int l, int r, int o) {       if (ql <= l && qr >= r)         ans = merge(ans, t[o]);       else {         int mid = l + r >> 1;         if (ql <= mid) query(l, mid, o << 1);         if (qr > mid) query(mid + 1, r, o << 1 | 1);       }     }     node Query(int l, int r) {       ans = zer;       ql = l, qr = r;       query(1, n, 1);       return ans;     }   };   segtree tree;   bool judge(node& a, node& b) {     if (a.suf % 2 != b.suf % 2 || a.pref % 2 != b.pref % 2 || a.len != b.len)       return false;     for (int i = (0); i < (hashnum); ++i)       if (a.hv[i] != b.hv[i]) return false;     return true;   }   int main(void) {     scanf( %d%s , &n, s + 1);     init();     tree.init(n);     tree.build(1, n, 1);     for (int i = (1); i <= (n); ++i) {       sum[i] = sum[i - 1];       if (s[i] ==  1 ) sum[i]++;     }     int q;     scanf( %d , &(q));     for (; q--;) {       int l1, l2, r1, r2, len;       scanf( %d%d%d , &l1, &l2, &len);       r1 = l1 + len - 1;       r2 = l2 + len - 1;       if (sum[r2] - sum[l2 - 1] != sum[r1] - sum[l1 - 1]) {         puts( No );         continue;       }       node x = tree.Query(l1, r1);       node y = tree.Query(l2, r2);       if (judge(x, y))         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   const double Pi = 3.14159265;   const int N = 1e6 + 50;   const int M = 1e5 + 15;   const unsigned long long base = 163;   const int INF = 0x3f3f3f3f;   using namespace std;   int a[N];   int main() {     int n;     scanf( %d , &n);     int l = 0, r = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int pre = 1;     int now = -1;     int flag = 0;     for (int i = 1; i <= n - 1; i++) {       if (a[i] == a[i + 1]) {         pre++;       } else {         flag = 1;         if (now == -1)           now = pre;         else {           if (pre != now) {             cout <<  NO  << endl;             return 0;           }         }         pre = 1;       }     }     if (pre != now && flag) return cout <<  NO n , 0;     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 3;   struct Rcompare {     bool operator()(pair<int, int> lhs, pair<int, int> rhs) {       return lhs.first > rhs.first;     }   };   struct compare {     bool operator()(pair<int, int> lhs, pair<int, int> rhs) {       return lhs.first < rhs.first;     }   };   int solve(int x) {     if (x < 4 || x == 5 || x == 7 || x == 11) {       return -1;     }     if (x % 4 == 0) {       return x / 4;     }     if (x % 4 == 2) {       return x / 4;     }     if (x % 4 == 1) {       return x / 4 - 1;     }     return x / 4 - 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < (n); ++i) {       int x;       cin >> x;       cout << solve(x) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int bin[31];   int cnt;   int ch[6000010][2];   void insert(int x) {     for (int i = 30; i >= 0; --i) {       bin[i] = x & 1;       x >>= 1;     }     int now = 0;     for (int i = 0; i <= 30; ++i) {       if (!ch[now][bin[i]]) {         ch[now][bin[i]] = ++cnt;       }       now = ch[now][bin[i]];     }   }   int getans(int l, int r, int k) {     if (k == 32) return 0;     int firmin = 1 << 30;     if (ch[l][0] && ch[r][0])       firmin = min(firmin, getans(ch[l][0], ch[r][0], k + 1));     if (ch[l][1] && ch[r][1])       firmin = min(firmin, getans(ch[l][1], ch[r][1], k + 1));     if (firmin != 1 << 30) return firmin;     int secmin = 1 << 30;     if (ch[l][1] && ch[r][0])       secmin = min(secmin, getans(ch[l][1], ch[r][0], k + 1)) + (1 << (31 - k));     if (ch[l][0] && ch[r][1])       secmin = min(secmin, getans(ch[l][0], ch[r][1], k + 1)) + (1 << (31 - k));     return secmin;   }   long long ans;   void dfs(int x, int k) {     if (ch[x][0] && ch[x][1]) {       ans += 1ll * (getans(ch[x][0], ch[x][1], k + 1) + (1 << (31 - k)));     }     if (ch[x][0]) dfs(ch[x][0], k + 1);     if (ch[x][1]) dfs(ch[x][1], k + 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       insert(x);     }     dfs(0, 1);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int arr[4], sum;   string s;   int main() {     cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> s;     for (int i = 0; i < s.size(); i++) {       sum += arr[s[i] - 49];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   const long double eps = 1e-8;   const int MAXN = 100000 + 5;   pair<long double, long double> X[MAXN << 2];   inline pair<long double, long double> calc(const int& a, const int& b) {     long double x = (long double)(b - a) / (long double)a;     return make_pair(x, x);   }   inline void pushUp(const int& rt) {     X[rt].first = X[rt << 1].first * X[rt << 1 | 1].first;     X[rt].second = X[rt << 1].second + X[rt << 1 | 1].second * X[rt << 1].first;   }   void build(int l, int r, int rt) {     static int ax, bx;     if (l == r) {       scanf( %d %d , &ax, &bx);       X[rt] = calc(ax, bx);       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushUp(rt);   }   void update(const int& p, const pair<long double, long double>& v, int l, int r,               int rt) {     if (l == r) {       X[rt] = v;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(p, v, l, mid, rt << 1);     else       update(p, v, mid + 1, r, rt << 1 | 1);     pushUp(rt);   }   pair<long double, long double> query(const int& L, const int& R, int l, int r,                                        int rt) {     static pair<long double, long double> z =         make_pair((long double)1.0, (long double)0.0);     if (L <= l && r <= R) return X[rt];     int mid = (l + r) >> 1;     pair<long double, long double> x = z, y = z, ret;     if (L <= mid) x = query(L, R, l, mid, rt << 1);     if (R > mid) y = query(L, R, mid + 1, r, rt << 1 | 1);     ret.first = x.first * y.first;     ret.second = x.second + y.second * x.first;     return ret;   }   int main() {     static int n, q, op, x, ax, bx, lx, rx;     while (~scanf( %d %d , &n, &q)) {       build(1, n, 1);       while (q--) {         scanf( %d , &op);         if (op == 1) {           scanf( %d %d %d , &x, &ax, &bx);           update(x, calc(ax, bx), 1, n, 1);         } else {           scanf( %d %d , &lx, &rx);           long double ans = query(lx, rx, 1, n, 1).second;           if (ans != ans || ans >= 1e20)             ans = 0.0;           else             ans = 1 / (1 + ans);           cout << fixed << setprecision(8) << ans <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T x = 0, f = 0;     char c = getchar();     while (!isdigit(c)) f = c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return f ? -x : x;   }   namespace run {   const long long N = 2e5 + 9;   map<long long, long long> mp;   long long n, a[N], ans;   long long main() {     n = read<long long>();     for (long long i = 1; i <= n; i++) a[i] = read<long long>();     mp[0] = 1;     for (long long i = 1, sum = 0, las = 0; i <= n; i++) {       sum += a[i];       las = max(las, mp[sum]);       ans += i - las;       mp[sum] = i + 1;     }     printf( %lld n , ans);     return 0;   }   }  // namespace run   int main() { return run::main(); }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int id, a, b;   } node[111111], zhan[111111];   bool cmp1(Node a, Node b) { return a.a > b.a || (a.a == b.a && a.b > b.b); }   bool cmp2(Node a, Node b) { return a.b > b.b || (a.b == b.b && a.a < b.a); }   int main() {     int n, p, k;     scanf( %d%d%d , &n, &p, &k);     for (int i = 0; i < n; i++)       scanf( %d%d , &node[i].a, &node[i].b), node[i].id = i + 1;     sort(node, node + n, cmp2);     sort(node, node + n - p + k, cmp1);     int flag = 1 << 30, flag1 = -1;     for (int i = 0; i < k; i++) {       zhan[i] = node[i];       if (flag >= zhan[i].b) {         if (flag == zhan[i].b)           flag1 = max(zhan[i].a, flag1);         else           flag1 = zhan[i].a;         flag = zhan[i].b;       }     }     sort(node + k, node + n, cmp2);     int cnt = k;     for (int i = k; cnt < p; i++) {       if (node[i].b < flag || (node[i].b == flag && node[i].a >= flag1))         zhan[cnt++] = node[i];     }     for (int i = 0; i < p; i++) printf( %d  , zhan[i].id);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   struct ent {     int val, pos;     inline bool operator<(const ent &cpr) const { return val < cpr.val; }   };   set<ent> pq;   int n;   int val[300005];   long long sum[300005];   long long ret;   int a, b;   int del[300005];   int dcnt;   int main() {     ret = -1000000000000ll;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + max(val[i], 0);       ent nw;       nw.pos = i;       nw.val = val[i];       set<ent>::iterator it;       it = pq.find(nw);       if (it == pq.end())         pq.insert(nw);       else {         if (ret < 2 * val[i] + sum[i - 1] - sum[(*it).pos]) {           ret = 2 * val[i] + sum[i - 1] - sum[(*it).pos];           a = (*it).pos;           b = i;         }       }     }     cout << ret;     for (int i = 1; i < a; i++) del[++dcnt] = i;     for (int i = a + 1; i < b; i++)       if (val[i] < 0) del[++dcnt] = i;     for (int i = b + 1; i <= n; i++) del[++dcnt] = i;     printf(  %d n , dcnt);     for (int i = 1; i <= dcnt; i++) printf( %d  , del[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   const int LVL = 18;   int n, m;   int a[N];   int b[N];   int c[N];   int h[N];   int inplace[N], parent[N];   int inmst[N];   int dp[N][LVL], mini[N][LVL], maxi[N][LVL];   int ans[N];   vector<int> tree[N];   int find(int node) {     if (parent[node] == node) {       return node;     }     return parent[node] = find(parent[node]);   }   void addEdge(int edgeNo) {     if (find(a[edgeNo]) != find(b[edgeNo])) {       inmst[edgeNo] = true;       parent[find(a[edgeNo])] = find(b[edgeNo]);       tree[a[edgeNo]].push_back(edgeNo);       tree[b[edgeNo]].push_back(edgeNo);     } else {       inmst[edgeNo] = false;     }   }   pair<int, int> lca(int a, int b) {     if (h[a] > h[b]) {       int temp = a;       a = b;       b = temp;     }     int diff = abs(h[a] - h[b]);     int max_weight_edge = 0;     for (int i = 0; i <= 17; i++) {       if ((diff >> i) & 1) {         max_weight_edge = max(maxi[b][i], max_weight_edge);         b = dp[b][i];       }     }     if (b == a) {       return make_pair(a, max_weight_edge);     }     for (int i = 17; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         max_weight_edge = max(max_weight_edge, maxi[a][i]);         max_weight_edge = max(max_weight_edge, maxi[b][i]);         a = dp[a][i];         b = dp[b][i];       }     }     return make_pair(dp[a][0], max(max_weight_edge, max(maxi[a][0], maxi[b][0])));   }   void dfs(int node, int par) {     dp[node][0] = par;     for (int edgeNo : tree[node]) {       int child = a[edgeNo] ^ b[edgeNo] ^ node;       if (child != par) {         maxi[child][0] = c[edgeNo];         h[child] = h[node] + 1;         dfs(child, node);       }     }   }   void dfs2(int node, int par) {     for (int edgeNo : tree[node]) {       int next = a[edgeNo] ^ b[edgeNo] ^ node;       if (next != par) {         ans[edgeNo] = mini[next][0];         dfs2(next, node);       }     }   }   void update(int node, int lca, int val) {     int diff = abs(h[node] - h[lca]);     for (int i = LVL - 1; i >= 0; i--) {       if (diff & (1 << i)) {         mini[node][i] = min(mini[node][i], val);         node = dp[node][i];       }     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> c[i];       inplace[i] = i;     }     for (int i = 1; i <= n; i++) {       parent[i] = i;     }     sort(inplace + 1, inplace + 1 + m, [](int x, int y) {       return make_pair(c[x], make_pair(a[x], b[x])) <              make_pair(c[y], make_pair(a[y], b[y]));     });     for (int i = 1; i <= m; i++) {       addEdge(inplace[i]);     }     h[1] = 0;     dfs(1, 0);     for (int l = 1; l < LVL; l++) {       for (int i = 1; i <= n; i++) {         dp[i][l] = dp[dp[i][l - 1]][l - 1];         maxi[i][l] = max(maxi[i][l - 1], maxi[dp[i][l - 1]][l - 1]);       }     }     for (int j = 0; j < LVL; j++) {       for (int i = 1; i <= n; i++) {         mini[i][j] = 1e9 + 7;       }     }     for (int i = 1; i <= m; i++) {       if (inmst[i]) {         ans[i] = 1e9 + 7;       } else {         pair<int, int> result = lca(a[i], b[i]);         ans[i] = result.second;         update(a[i], result.first, c[i]);         update(b[i], result.first, c[i]);       }     }     for (int l = LVL - 1; l > 0; l--) {       for (int i = 1; i <= n; i++) {         mini[i][l - 1] = min(mini[i][l - 1], mini[i][l]);         mini[dp[i][l - 1]][l - 1] = min(mini[i][l], mini[dp[i][l - 1]][l - 1]);       }     }     dfs2(1, 0);     for (int i = 1; i <= m; i++) {       if (ans[i] == 1e9 + 7) {         ans[i] = 0;       }     }     for (int i = 1; i <= m; i++) {       cout << ans[i] - 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <typename T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int E, head[5050], to[5050], nxt[5050];   void init(int n) {     E = 0;     for (int i = 1; i <= n; i++) head[i] = -1;   }   void add_edge(int u, int v) {     nxt[E] = head[u];     to[E] = v;     head[u] = E++;   }   int dp[2][5050][5050], c[5050], d[5050];   int sz[5050];   void dfs(int u) {     dp[1][u][0] = 0;     dp[0][u][0] = 0;     dp[1][u][1] = c[u] - d[u];     dp[0][u][1] = c[u];     sz[u] = 1;     for (int e = head[u]; ~e; e = nxt[e]) {       int v = to[e];       dfs(v);       for (int i = sz[u] + sz[v]; i >= 1; i--) {         for (int j = min(i, sz[v]); j >= 0 && i - j <= sz[u]; j--) {           smin(dp[0][u][i], dp[0][u][i - j] + dp[0][v][j]);           if (i && j < i) smin(dp[1][u][i], dp[1][u][i - j] + dp[1][v][j]);         }       }       sz[u] += sz[v];     }     for (int i = 1; i <= sz[u]; i++) smin(dp[1][u][i], dp[0][u][i]);   }   int main() {     int n, b;     gn(n, b);     init(n);     memset(dp, 0x3f, sizeof(dp));     for (int i = 1, first; i <= n; i++) {       gn(c[i], d[i]);       if (i > 1) {         gn(first);         add_edge(first, i);       }     }     dfs(1);     int ans = 0;     for (int i = 1; i <= n; i++)       if (dp[1][1][i] <= b) ans = i;     println(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<string> s1, s2, s3;     s3.clear();     s1.clear();     s2.clear();     int n, m;     cin >> n >> m;     string str =   ;     for (int i = 0; i < n; i++) {       cin >> str;       s1.insert(str);     }     for (int i = 0; i < m; i++) {       cin >> str;       s2.insert(str);     }     set<string>::iterator it;     for (it = s1.begin(); it != s1.end(); it++) {       if (s2.find(*it) != s2.end()) {         s3.insert(*it);       }     }     int z = s3.size();     int x = s1.size() - z;     int y = s2.size() - z;     if (z % 2 != 0) {       if (x >= y) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     } else {       if (x - y >= 1)         cout <<  YES n ;       else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int card[10010];   int main() {     int n, r, s = 0, d = 0, l = 1, num = 0;     cin >> n;     r = n;     for (int i = 1; i <= n; i++) {       cin >> card[i];     }     while (l <= r) {       num++;       if (num & 1) {         if (card[l] > card[r]) {           s += card[l];           l++;         } else {           s += card[r];           r--;         }       } else {         if (card[l] > card[r]) {           d += card[l];           l++;         } else {           d += card[r];           r--;         }       }     }     cout << s <<     << d << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dp[200010][33];   void generate() {     for (long long i = 1; i <= (200000); i++) {       for (long long j = 0; j < (32); j++) {         dp[i][j] = dp[i - 1][j] + !((1 << j) & i);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     generate();     int t;     cin >> t;     while (t--) {       int l, r, mn = 0x3F3F3F3F;       cin >> l >> r;       for (long long j = 0; j < (32); j++) {         mn = min(mn, dp[r][j] - dp[l - 1][j]);       }       cout << mn <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long inf = 9e18;   struct NODE {     long long v, id;     bool operator<(const NODE& other) const {       return v > other.v || (v == other.v && id > other.id);     }   } node[N];   long long a[N], b[N];   long long n;   long long f(long long x, long long y) { return x - 3LL * y * y + 3LL * y - 1; }   long long find(long long v, long long x) {     long long l, r, mid;     l = 0;     r = x + 1;     while (r - l > 1) {       mid = (l + r) >> 1;       if (f(x, mid) >= v)         l = mid;       else         r = mid;     }     return l;   }   long long solve(long long x) {     long long tot = 0;     int i;     for (i = 1; i <= n; i++) {       tot += (b[i] = find(x, a[i]));     }     return tot;   }   int main() {     long long k;     int i, cnt = 0;     long long l = inf, r = -inf, mid, tot;     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> a[i];       l = min(l, f(a[i], a[i]));       r = max(r, f(a[i], 1));     }     while (r - l > 1) {       mid = (l + r) >> 1;       if (solve(mid) <= k)         r = mid;       else         l = mid;     }     tot = solve(r);     for (i = 1; i <= n; i++)       if (b[i] < a[i]) node[++cnt].v = f(a[i], b[i] + 1), node[cnt].id = i;     sort(node + 1, node + cnt + 1);     for (i = 1; i <= cnt; i++) {       if (tot == k) break;       b[node[i].id]++;       tot++;     }     for (i = 1; i <= n; i++) cout << b[i] <<    ;     return 0;   }