#include <bits/stdc++.h>   using namespace std;   int n, c[3010];   struct info {     int x, y;   };   struct as {     int a, b, c;   } ans;   struct node {     int x, id;   } a[3010];   inline bool cmp(node a, node b) { return a.x > b.x; }   inline info max(info a, info b) {     if (a.x < b.x) return b;     return a;   }   struct seg {     int lt[12010], rt[12010];     info mx[12010];     inline void build(int i, int l, int r) {       lt[i] = l;       rt[i] = r;       if (l == r) {         mx[i] = (info){a[l].x - a[l + 1].x, l};         return;       }       int mid = l + r >> 1;       build(i * 2, l, mid);       build(i * 2 + 1, mid + 1, r);       mx[i] = max(mx[i * 2], mx[i * 2 + 1]);     }     inline info query(int i, int l, int r) {       if (l <= lt[i] && r >= rt[i]) return mx[i];       int mid = lt[i] + rt[i] >> 1;       info ans = {-1, 0};       if (l <= mid) ans = query(i * 2, l, r);       if (r > mid) ans = max(ans, query(i * 2 + 1, l, r));       return ans;     }   } A;   inline as max(as t1, as t2) {     if (t1.a == 0) return t2;     if (a[t1.a].x - a[t1.a + 1].x != a[t2.a].x - a[t2.a + 1].x)       return a[t1.a].x - a[t1.a + 1].x > a[t2.a].x - a[t2.a + 1].x ? t1 : t2;     if (a[t1.b].x - a[t1.b + 1].x != a[t2.b].x - a[t2.b + 1].x)       return a[t1.b].x - a[t1.b + 1].x > a[t2.b].x - a[t2.b + 1].x ? t1 : t2;     if (a[t1.c].x - a[t1.c + 1].x != a[t2.c].x - a[t2.c + 1].x)       return a[t1.c].x - a[t1.c + 1].x > a[t2.c].x - a[t2.c + 1].x ? t1 : t2;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].x), a[i].id = i;     sort(a + 1, a + n + 1, cmp);     A.build(1, 1, n);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j < n; j++)         if (2 * (j - i) >= i && i * 2 >= j - i) {           int lk = max(j + (max(i, j - i) + 1) / 2, j + 1),               rk = min(j + 2 * min(i, j - i), n);           if (lk <= rk) ans = max(ans, (as){i, j, A.query(1, lk, rk).y});         }     for (int i = 1; i <= ans.a; i++) c[a[i].id] = 1;     for (int i = ans.a + 1; i <= ans.b; i++) c[a[i].id] = 2;     for (int i = ans.b + 1; i <= ans.c; i++) c[a[i].id] = 3;     for (int i = ans.c + 1; i <= n; i++) c[a[i].id] = -1;     for (int i = 1; i <= n; i++) printf( %d  , c[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A, B;   char a[5555];   char b[5555];   int dp[5555][5555];   int main() {     scanf( %d%d , &A, &B);     scanf( %s%s , a + 1, b + 1);     int ans = 0;     int i, j;     for (i = 1; i <= A; i++) {       for (j = 1; j <= B; j++) {         if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);         dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);         ans = max(ans, dp[i][j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x, l;     int cnt = 0;     for (int i = 0; i < n; i++) {       cnt = 0;       cin >> x;       if (x % 7 != 0) {         cnt++;       }       x /= 7;       cout << x + cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:36777216 )   using namespace std;   long long pow_mod(long long x, long long y, long long z) {     long long res = 1;     while (y) {       if (y & 1) res *= x, res %= z;       x *= x, x %= z, y >>= 1;     }     return res % z;   }   void ext_gcd(long long a, long long b, long long &d, long long &x,                long long &y) {     if (!b) {       d = a, x = 1, y = 0;     } else {       ext_gcd(b, a % b, d, y, x), y -= x * (a / b);     }   }   long long inv(long long a, long long c) {     long long d, x, y;     ext_gcd(a, c, d, x, y);     return (x + c) % c;   }   long long fac[111111];   long long C(int x, int y) {     if (x < y) return 0;     return fac[x] * inv(fac[y], 1000000007) % 1000000007 *            inv(fac[x - y], 1000000007) % 1000000007;   }   int n, v;   vector<pair<int, int> > vec;   long long gao(int l, int r, int pre) {     if (l < 1) return 0;     if (r > n) return 0;     long long res;     if (pre == 1)       res = 1;     else       res = pow_mod(2, pre - 2, 1000000007);     for (int i = 1; i < vec.size(); i++) {       if (vec[i].second > r) {         res *= C(vec[i].first - pre - 1, vec[i].second - r - 1);         res %= 1000000007;         if (res == 0) return 0;         l = l - (vec[i].first - pre - 1 - (vec[i].second - r - 1));         r = vec[i].second;       } else if (vec[i].second < l) {         res *= C(vec[i].first - pre - 1, l - vec[i].second - 1);         res %= 1000000007;         if (res == 0) return 0;         r = r + (vec[i].first - pre - 1 - (l - vec[i].second - 1));         l = vec[i].second;       } else         return 0;       if (i == vec.size() - 1) return res;       if (r > n || l < 1) return 0;       pre = vec[i].first;     }     return res;   }   int main() {     fac[0] = 1;     for (int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % 1000000007;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v);       if (v) vec.push_back(make_pair(v, i));     }     if (vec.size() == 0) {       printf( %I64d n , pow_mod(2, n - 1, 1000000007));       return 0;     }     vec.push_back(make_pair(n + 1, n + 1));     sort(vec.begin(), vec.end());     long long ans;     if (vec[0].first == 1)       ans = gao(vec[0].second, vec[0].second, 1);     else       ans = gao(vec[0].second - vec[0].first + 1, vec[0].second, vec[0].first) +             gao(vec[0].second, vec[0].second + vec[0].first - 1, vec[0].first) %                 1000000007;     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     long long T[1000100];     long long ALL;     BIT() { ALL = 0; }     void add(int pos, long long w) {       ++pos;       ALL += w;       for (; pos < 1000100; pos += (pos & (-pos))) T[pos] += w;     }     long long all_from(int pos) {       long long ret = ALL;       for (; pos > 0; pos -= pos & (-pos)) ret -= T[pos];       return ret;     }   };   int N, M, H[1000100], FL[1000100], FR[1000100];   stack<int> pos;   vector<int> ib, ie, spl, spr, val;   vector<int> ids;   inline bool icompare(const int& f, const int& s) {     return ie[f] - ib[f] > ie[s] - ib[s];   }   vector<double> ans;   vector<int> Q, qid;   inline bool qcompare(const int& f, const int& s) { return Q[f] > Q[s]; }   BIT rem_val, rem_sum;   int main() {     scanf( %d , &N);     H[0] = H[N + 1] = -1100000000;     for (int i = 0; i < N; ++i) scanf( %d , &H[i + 1]);     pos.push(0);     for (int i = 1; i <= N; ++i) {       while (H[pos.top()] > H[i]) pos.pop();       FL[i] = pos.top();       pos.push(i);     }     while (!pos.empty()) pos.pop();     pos.push(N + 1);     for (int i = N; i > 0; --i) {       while (H[pos.top()] >= H[i]) pos.pop();       FR[i] = pos.top();       pos.push(i);     }     for (int i = 1; i <= N; ++i) {       ib.push_back(FL[i] + 1);       ie.push_back(FR[i] - 1);       val.push_back(H[i]);       spl.push_back(i - FL[i] - 1);       spr.push_back(FR[i] - i - 1);     }     for (int i = 0; i < ((int)(ib).size()); ++i) ids.push_back(i);     sort(ids.begin(), ids.end(), icompare);     scanf( %d , &M);     ans.resize(M);     Q.resize(M);     for (int i = 0; i < M; ++i) qid.push_back(i);     for (int i = 0; i < M; ++i) scanf( %d , &Q[i]);     sort(qid.begin(), qid.end(), qcompare);     long long val_all = 0, sum_all = 0;     int cur = 0;     for (int i = 0; i < ((int)(qid).size()); ++i) {       int V = Q[qid[i]];       while (cur < ((int)(ids).size()) && ie[ids[cur]] - ib[ids[cur]] + 1 >= V) {         int T = ids[cur++];         val_all += val[T] * 1LL * (ie[T] - ib[T] + 1);         sum_all += val[T];         if (spl[T] > 0)           rem_val.add(spl[T], spl[T] * 1LL * val[T]), rem_sum.add(spl[T], val[T]);         if (spr[T] > 0)           rem_val.add(spr[T], spr[T] * 1LL * val[T]), rem_sum.add(spr[T], val[T]);       }       long long out = val_all - (V - 1) * sum_all;       out -= rem_val.all_from(V) - (V - 1) * rem_sum.all_from(V);       ans[qid[i]] = ((double)out) / (N - V + 1);     }     for (int i = 0; i < M; ++i) printf( %.12lf n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   char a[2000010], b[2000010];   int main() {     int n;     int i;     int x, y, z;     int p, q;     while (~scanf( %d %s %s , &n, a, b)) {       x = y = z = 0;       for (i = 0; i < 2 * n; i++) {         if (a[i] ==  1  && b[i] ==  1 ) {           z++;         } else if (a[i] ==  1 ) {           x++;         } else if (b[i] ==  1 ) {           y++;         }       }       p = x + (z + 1) / 2;       q = y + z - (z + 1) / 2;       if (p == q || p + 1 == q) {         puts( Draw );       } else if (p > q) {         puts( First );       } else {         puts( Second );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T;   string hxt[16];   int main() {     cin >> T;     while (T--) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) cin >> hxt[i];       bool iif = false;       for (int i = 0; i < m; i++) {         char x = hxt[1][i];         for (char j =  a ; j <=  z ; j++) {           hxt[1][i] = j;           bool flag = true;           for (int k = 2; k <= n; k++) {             int js = 0;             for (int l = 0; l < m; l++) {               if (hxt[k][l] != hxt[1][l]) js++;               if (js > 1) break;             }             if (js > 1) {               flag = false;               break;             }           }           if (flag) {             cout << hxt[1] << endl;             iif = true;             break;           }           hxt[1][i] = x;         }         if (iif) break;       }       if (!iif) cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 2;   int n;   int a[N];   map<int, int> m;   map<pair<int, int>, bool> checked;   int main() {     cin >> n;     int zero = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       if (!a[i]) zero++;       ;       m[a[i]]++;     }     sort(a, a + n);     int ans = -1;     int help1, help2, help3;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         if (i != j) {           if (!a[i] and (!a[j])) continue;           if (checked[make_pair(a[i], a[j])]) continue;           checked[make_pair(a[i], a[j])] = true;           map<int, int> m1;           help3 = 2;           m1[a[i]]++, m1[a[j]]++;           help1 = a[i];           help2 = a[j];           while (m1[help1 + help2] < m[help1 + help2]) {             m1[help1 + help2]++;             help3++;             help2 += help1;             help1 = help2 - help1;           }           ans = max(ans, help3);         }     ans = max(ans, zero);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4005;   vector<int> v[maxn];   int vis[maxn][maxn];   int main(void) {     int n, m, ans = maxn;     memset(vis, 0, sizeof(vis));     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);       vis[x][y] = vis[y][x] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (!vis[i][j]) continue;         for (int k = j + 1; k <= n; k++) {           if (!vis[i][k] || !vis[k][j]) continue;           int cur = 0;           int len = v[i].size();           for (int d = 0; d < len; d++) {             if (v[i][d] != j && v[i][d] != k) cur++;           }           len = v[j].size();           for (int d = 0; d < len; d++) {             if (v[j][d] != i && v[j][d] != k) cur++;           }           len = v[k].size();           for (int d = 0; d < len; d++) {             if (v[k][d] != i && v[k][d] != j) cur++;           }           ans = min(ans, cur);         }       }     }     if (ans == maxn)       printf( -1 n );     else       printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int T, N;   int arr[500005];   stack<int> stk;   vector<pair<int, int>> v;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> T;     while (T--) {       cin >> N;       bool pos = 1;       while (stk.size()) {         stk.pop();       }       v.clear();       for (int i = 1; i <= N; i++) {         while (stk.size() && stk.top() == i) {           stk.pop();         }         cin >> arr[i];         if (arr[i] == -1) {           if (stk.empty()) {             arr[i] = N + 1;           } else {             arr[i] = stk.top();           }         }         v.push_back({-arr[i], i});         if (stk.size() && stk.top() < arr[i]) {           pos = 0;         }         stk.push(arr[i]);       }       if (pos) {         sort(v.begin(), v.end());         int cnt = N;         for (auto p : v) {           arr[p.second] = cnt--;         }         for (int i = 1; i <= N; i++) {           cout << arr[i] <<    ;         }         cout <<   n ;       } else {         cout << -1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   const int __SIZE = (1 << 21) + 1;   char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,                                              __c, qu[55];   int __f, qr, _eof;   inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }   inline void gc(char &x) {     x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                      (iS == iT ? EOF : *iS++))                   : *iS++);   }   inline void pc(char x) {     *oS++ = x;     if (oS == oT) flush();   }   inline void pstr(const char *s) {     int __len = strlen(s);     for (__f = 0; __f < __len; ++__f) pc(s[__f]);   }   inline void gstr(char *s) {     for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++);          __c < 32 || __c > 126 || __c ==    ;)       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                          (iS == iT ? EOF : *iS++))                       : *iS++);     for (; __c > 31 && __c < 127 && __c !=    ;          ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                               : *iS++))       *s = __c;     *s = 0;   }   template <class I>   inline bool gi(I &x) {     _eof = 0;     for (__f = 1,         __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                           (iS == iT ? EOF : *iS++))                         : *iS++);          (__c <  0  || __c >  9 ) && !_eof;          __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++)) {       if (__c ==  - ) __f = -1;       _eof |= __c == EOF;     }     for (x = 0; __c <=  9  && __c >=  0  && !_eof;          __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++))       x = x * 10 + (__c & 15), _eof |= __c == EOF;     x *= __f;     return !_eof;   }   template <class I>   inline void print(I x) {     if (!x) pc( 0 );     if (x < 0) pc( - ), x = -x;     while (x) qu[++qr] = x % 10 +  0 , x /= 10;     while (qr) pc(qu[qr--]);   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_flusher_;   }  // namespace io   using io::gc;   using io::gi;   using io::gstr;   using io::pc;   using io::print;   using io::pstr;   using ll = long long;   using pii = pair<int, int>;   const int MOD = 1000000007;   pii dat[500005 << 2];   bool laz[500005 << 2];   void push(int idx, int l, int r) {     if (!laz[idx] || l == r) return;     dat[idx * 2] = {dat[idx * 2].second, dat[idx * 2].first};     laz[idx * 2] = !laz[idx * 2];     dat[idx * 2 + 1] = {dat[idx * 2 + 1].second, dat[idx * 2 + 1].first};     laz[idx * 2 + 1] = !laz[idx * 2 + 1];     laz[idx] = 0;   }   void upd(int idx, int l, int r, int i, pii v) {     if (!(l <= i && i <= r)) return;     push(idx, l, r);     if (l == r) {       dat[idx] = v;       return;     }     upd(idx * 2, l, (l + r) / 2, i, v);     upd(idx * 2 + 1, (l + r) / 2 + 1, r, i, v);     dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),                 max(dat[idx * 2].second, dat[idx * 2 + 1].second)};   }   void tag(int idx, int l, int r, int ql, int qr) {     if (qr < l || r < ql) return;     push(idx, l, r);     if (ql <= l && r <= qr) {       dat[idx] = {dat[idx].second, dat[idx].first};       laz[idx] = !laz[idx];       return;     }     tag(idx * 2, l, (l + r) / 2, ql, qr);     tag(idx * 2 + 1, (l + r) / 2 + 1, r, ql, qr);     dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),                 max(dat[idx * 2].second, dat[idx * 2 + 1].second)};   }   pii el2[500005];   vector<pii> elist[500005];   pii dfsfar(int u, int f) {     pii ans = {0, u};     for (pii &v : elist[u])       if (v.first != f) ans = max(ans, dfsfar(v.first, u));     return {ans.first + 1, ans.second};   }   int clck = 1;   int n;   int L[500005], R[500005];   int qr[500005], ans[500005];   void dfs(int u, int f, int dep, int cnt) {     L[u] = clck++;     if (cnt % 2 == 0)       upd(1, 1, n, L[u], {dep, 0});     else       upd(1, 1, n, L[u], {0, dep});     for (pii &v : elist[u])       if (v.first != f) dfs(v.first, u, dep + 1, cnt + v.second);     R[u] = clck - 1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     gi(n);     for (int i = (0); i < (n - 1); i++) {       int u, v, w;       gi(u), gi(v), gi(w);       el2[i] = {u, v};       elist[u].push_back({v, w});       elist[v].push_back({u, w});     }     int root = dfsfar(1, -1).second;     dfs(root, -1, 0, 0);     int q;     gi(q);     for (int i = (0); i < (q); i++) gi(qr[i]);     for (int i = (0); i < (q); i++) {       int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;       if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);       tag(1, 1, n, L[ch], R[ch]);       ans[i] = max(ans[i], dat[1].first);     }     root = dfsfar(root, -1).second;     memset(dat, 0, sizeof dat);     memset(laz, 0, sizeof laz);     clck = 1;     dfs(root, -1, 0, 0);     for (int i = (0); i < (q); i++) {       int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;       if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);       tag(1, 1, n, L[ch], R[ch]);       ans[i] = max(ans[i], dat[1].first);       print(ans[i]), pc(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   int yekdast(char c, int l, int r) {     int ans = 0;     for (int i = l; i <= r; i++) {       if (s[i] != c) ans++;     }     return ans;   }   int check(char c, int l, int r) {     if ((r - l) > 1) {       int mid1 = (floor((l * 1.0 + r * 1.0) / 2.0)),           mid2 = (ceil((l * 1.0 + r * 1.0) / 2.0));       int first = check(char(c + 1), l, mid1) + yekdast(c, mid2, r);       int second = check(char(c + 1), mid2, r) + yekdast(c, l, mid1);       return min(first, second);     } else if (r == l + 1) {       int first = check(char(c + 1), l, l) + yekdast(c, r, r);       int second = check(char(c + 1), r, r) + yekdast(c, l, l);       return min(first, second);     } else {       return yekdast(c, l, r);     }   }   int t, n;   int main() {     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> s;       cout << check( a , 0, n - 1) << endl;     }   }


#include <bits/stdc++.h>   const int N = 1e5 + 2, p = 1e9 + 7;   int siz[N], f[N];   int n, m, x, y, z, i, c;   inline void read(int &x) {     c = getchar();     while ((c < 48) || (c > 57)) c = getchar();     x = c ^ 48;     c = getchar();     while ((c >= 48) && (c <= 57)) {       x = x * 10 + (c ^ 48);       c = getchar();     }   }   int getf(register int x) {     if (f[x] == x) return f[x];     f[x] = getf(f[x]);     siz[f[x]] += siz[x];     siz[x] = 0;     return f[x];   }   inline int ksm(register int x, register int y) {     register int r = 1;     while (y) {       if (y & 1) r = (long long)r * x % p;       x = (long long)x * x % p;       y >>= 1;     }     return r;   }   int main() {     read(n);     read(m);     for (i = 1; i <= n; i++) siz[f[i] = i] = 1;     for (i = 1; i < n; i++) {       read(x);       read(y);       read(z);       if (z == 0) {         siz[getf(y)] += siz[getf(x)];         siz[f[x]] = 0;         f[f[x]] = f[y];       }     }     c = ksm(n, m);     for (i = 1; i <= n; i++)       if (siz[i]) c = (c - ksm(siz[i], m) + p) % p;     printf( %d , c);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char name[2000], part[2000000];   int work() {     int p = 0;     for (int i = 0; i < m; i++) {       if (part[i] == name[p]) p++;       if (p == n) return i;     }     return m;   }   int main() {     scanf( %s , name);     scanf( %s , part);     n = strlen(name), m = strlen(part);     int x = work();     reverse(name, name + n);     reverse(part, part + m);     int y = work();     printf( %d n , max(0, m - y - x - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(int b, int pw) {     long long int res = 1;     for (int i = 1; i <= pw; i++) {       res = res * b;     }     return res;   }   long long int typ[1000000];   int main() {     ios_base::sync_with_stdio(false);     long long int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> typ[i];     }     set<int> prev;     vector<pair<int, int> > ns;     long long int cnt = 0;     long long int from = 1;     for (int i = 1; i <= n; i++) {       if (prev.find(typ[i]) != prev.end()) {         ns.push_back(make_pair(from, i));         prev.clear();         from = i + 1;       } else {         prev.insert(typ[i]);       }     }     if (ns.size() == 0) {       printf( -1 n );       return 0;     }     cout << ns.size() << endl;     int temp = ns.size();     for (int i = 0; i < ns.size(); i++) {       if (i == temp - 1) {         cout << ns[i].first <<     << n << endl;         return 0;       }       cout << ns[i].first <<     << ns[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   int n, m;   int pnt[N * 4], last;   char tab[N][N], a[N][N];   int find(int x) {     if (x != pnt[x]) pnt[x] = find(pnt[x]);     return pnt[x];   }   int id(int x, int y, int d) { return (x * m + y) * 4 + d; }   void add(int x, int y) {     pnt[id(x, y, 0)] = x - 1 >= 0 ? id(x - 1, y, 0) : last;     pnt[id(x, y, 1)] = x + 1 < n ? id(x + 1, y, 1) : last;     pnt[id(x, y, 2)] = y - 1 >= 0 ? id(x, y - 1, 2) : last;     pnt[id(x, y, 3)] = y + 1 < m ? id(x, y + 1, 3) : last;   }   void solve() {     int ans = 0, cnt;     last = n * m * 4;     for (int i = 0; i < n; ++i) scanf( %s , tab[i]);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if (tab[i][j] ==  . ) continue;         for (int u = 0; u <= last; ++u) pnt[u] = u;         for (int u = 0; u < n; ++u)           for (int v = 0; v < m; ++v) {             a[u][v] = tab[u][v];             if (a[u][v] ==  . ) add(u, v);           }         int x = i, y = j, t = 0;         while (1) {           t++;           int dir;           if (a[x][y] ==  U ) dir = 0;           if (a[x][y] ==  D ) dir = 1;           if (a[x][y] ==  L ) dir = 2;           if (a[x][y] ==  R ) dir = 3;           add(x, y);           int p = find(id(x, y, dir));           if (p == last) break;           x = p / 4 / m;           y = p / 4 % m;         }         if (ans < t)           ans = t, cnt = 1;         else if (ans == t)           cnt++;       }     printf( %d %d n , ans, cnt);   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100005];   long long a[100005];   long long col;   bool ok;   bool dfs(long long v, long long par) {     ok &= (col == a[v]);     for (auto i : adj[v]) {       if (i != par) dfs(i, v);     }   }   bool fn(long long v) {     bool res = 1;     for (auto i : adj[v]) {       ok = 1;       col = a[i];       dfs(i, v);       res &= ok;     }     return res;   }   int main() {     int t = 1;     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     while (t--) {       long long n;       cin >> n;       long long i;       long long p = -1, q = -1;       for (i = 1; i < n; i++) {         long long x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       for (i = 0; i < n; i++) cin >> a[i + 1];       for (i = 1; i <= n; i++) {         for (auto j : adj[i]) {           if (a[j] != a[i]) {             p = i;             q = j;           }         }       }       if (q == -1) {         cout <<  YES  << endl;         cout << 1 << endl;         continue;       }       bool a1 = fn(p);       bool a2 = fn(q);       if (a1) {         cout <<  YES  << endl;         cout << p << endl;       } else if (a2) {         cout <<  YES  << endl;         cout << q << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int R, r, k;   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d%d , &R, &r, &k);       double a = R, b = r;       printf( %lf n , 1 / (1 / (a - b) + k * k * (a - b) / a / b));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool checkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool checkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int MAXN = 2600 / 2;   const int MAXM = 51;   const int MMAX = MAXN * MAXM + MAXN + MAXM + 100;   const int di[] = {0, 0, 1, 0, -1};   const int dj[] = {0, 1, 0, -1, 0};   struct Graph {    public:     int n, m;     int adj[MAXN][MAXM];     void init() {       n = m = 0;       memset(adj, 0, sizeof(adj));     }     void insert(int u, int v) {       n = max(n, v + 1);       m = max(m, v + 1);       adj[u][v] = 1;     }     int find_ans() {       build_dlx();       for (int ans = 0; ans <= n; ++ans) {         if (dfs(0, ans)) {           return ans;         }       }       return -1;     }       private:     int head;     int U[MMAX], D[MMAX], L[MMAX], R[MMAX], CN[MMAX], RN[MMAX];     void addUD(const int &a, const int &h) {       U[a] = h;       D[a] = D[h];       U[D[h]] = a;       D[h] = a;       CN[a] = h;     }     void addLR(const int &a, const int &h) {       L[a] = h;       R[a] = R[h];       L[R[h]] = a;       R[h] = a;       RN[a] = h;     }     void add(const int &k, const int &r, const int &c) {       addUD(k, c);       addLR(k, r);     }     void remove(const int &k) {       for (int j = R[k]; j != k; j = R[j]) {         for (int i = D[j]; i != j; i = D[i]) {           L[R[i]] = L[i];           R[L[i]] = R[i];         }         D[U[j]] = D[j];         U[D[j]] = U[j];       }     }     void unremove(const int &k) {       for (int j = L[k]; j != k; j = L[j]) {         D[U[j]] = j;         U[D[j]] = j;         for (int i = U[j]; i != j; i = U[i]) {           L[R[i]] = i;           R[L[i]] = i;         }       }     }     void build_dlx() {       head = MMAX - 1;       U[head] = D[head] = L[head] = R[head] = head;       int cnt = 0;       for (int i = 0; i < m; i++) {         U[cnt] = D[cnt] = cnt;         addLR(cnt++, head);       }       for (int i = 0; i < n; i++) {         L[cnt] = R[cnt] = cnt;         addUD(cnt++, head);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++)           if (adj[i][j]) {             addLR(cnt, m + i);             addUD(cnt, j);             cnt++;           }       }     }     int h() {       int hash[MAXM] = {};       int ans = 0;       for (int c = R[head]; c != head; c = R[c]) {         if (hash[c] == 0) {           hash[c] = 1;           ++ans;           for (int j = D[c]; j != c; j = D[j]) {             for (int i = R[j]; i != j; i = R[i]) {               if (CN[i] != head) {                 hash[CN[i]] = 1;               }             }           }         }       }       return ans;     }     bool dfs(int k, int lim) {       if (k + h() > lim) {         return false;       }       if (R[head] == head) {         return true;       }       int c;       c = R[head];       L[R[c]] = L[c];       R[L[c]] = R[c];       for (int i = D[c]; i != c; i = D[i]) {         L[R[i]] = L[i];         R[L[i]] = R[i];       }       for (int i = D[c]; i != c; i = D[i]) {         remove(RN[i]);         if (dfs(k + 1, lim)) {           return true;         }         unremove(RN[i]);       }       for (int i = U[c]; i != c; i = U[i]) {         L[R[i]] = i;         R[L[i]] = i;       }       L[R[c]] = c;       R[L[c]] = c;       return false;     }   } G;   int N, M;   int change(const int &i, const int &j) { return i * M + j; }   int main() {     while (scanf( %d%d , &N, &M) == 2) {       G.init();       for (int i = 0; i < N; i++) {         for (int j = 0; j < M; j++) {           for (int p = 0; p < 5; p++) {             int ii = i + di[p], jj = j + dj[p];             if (0 <= ii && ii < N && 0 <= jj && jj < M) {               G.insert(change(i, j), change(ii, jj));             }           }         }       }       int res = G.find_ans();       printf( %d n , M * N - res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   priority_queue<pair<long long, int> > Q;   int h[N], a[N];   int n, m, k, p;   bool check(long long lim) {     static long long now[N];     for (int i = 1; i <= n; i++) now[i] = lim;     while (!Q.empty()) Q.pop();     for (int i = 1; i <= n; i++)       if (now[i] - 1ll * a[i] * m < h[i]) Q.push(make_pair(-lim / a[i], i));     for (int i = 1; i <= m; i++)       for (int j = 1; j <= k; j++) {         if (Q.empty()) return true;         pair<long long, int> mx = Q.top();         Q.pop();         if (-mx.first < i) return false;         now[mx.second] += p;         if (now[mx.second] - 1ll * a[mx.second] * m < h[mx.second])           Q.push(make_pair(-now[mx.second] / a[mx.second], mx.second));       }     return Q.empty();   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; i++) scanf( %d%d , &h[i], &a[i]);     long long l = 0, r = 6e12, ans;     while (l <= r) {       long long mid = (l + r) >> 1ll;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 5;   const int K = (int)3e5 + 5;   vector<pair<int, int>> adj[N];   queue<pair<int, int>> q;   bool visited[N];   int res[300005];   int n;   int k;   int d;   int main() {     scanf( %d%d%d , &n, &k, &d);     for (int i = 0; i < k; i++) {       int place;       scanf( %d , &place);       q.push({place, 0});     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back({v, i + 1});       adj[v].push_back({u, i + 1});     }     while (!q.empty()) {       int pos = q.front().first;       int from = q.front().second;       q.pop();       if (visited[pos]) continue;       visited[pos] = 1;       for (pair<int, int> u : adj[pos]) {         if (u.first != from) {           if (visited[u.first])             res[u.second] = 1;           else             q.push({u.first, pos});         }       }     }     int rescnt = 0;     for (int i = 1; i <= n - 1; i++)       if (res[i]) rescnt++;     cout << rescnt << endl;     for (int x = 1; x <= n - 1; x++)       if (res[x]) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt, n;   string ss;   int main() {     cin >> n >> ss;     for (int i = 0; i < n; i++) {       if (i < n - 1 && ((ss[i] ==  R  && ss[i + 1] ==  U ) ||                         (ss[i] ==  U  && ss[i + 1] ==  R ))) {         i++;         cnt++;       } else         cnt++;     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, i, x, y;     cin >> n >> s;     int sol = 100;     int f = 1;     for (i = 0; i < n; i++) {       cin >> x >> y;       if (x < s) {         if (y) {           sol = min(sol, y);         }       }       if (x < s || (x == s && y == 0)) {         f = 0;       }     }     if (f)       cout << -1 << endl;     else       cout << 100 - sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l, r, ans = 0;   int main() {     cin >> l >> r;     for (long long i = 1; i <= r; i *= 2) {       for (long long j = 1; j <= r; j *= 3) {         if (i * j >= l && i * j <= r) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using vpii = vector<pii>;   using vi = vector<int>;   using vvi = vector<vi>;   using ll = long long;   using vll = vector<long long>;   template <class T>   using min_queue = priority_queue<T, vector<T>, greater<T>>;   template <class T>   istream &operator>>(istream &, vector<T> &);   template <class T>   ostream &operator<<(ostream &, const vector<T> &);   template <class T, class U>   istream &operator>>(istream &, pair<T, U> &);   template <class T, class U>   ostream &operator<<(ostream &, const pair<T, U> &);   template <class T>   struct Inf {     static constexpr T inf() {       return std::numeric_limits<T>::has_infinity()                  ? std::numeric_limits<T>::infinty()                  : std::numeric_limits<T>::max();     }   };   template <>   struct Inf<int> {     static constexpr int inf() { return 0x3f3f3f3f; }   };   template <>   struct Inf<long long> {     static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; }   };   constexpr int INF = Inf<int>::inf();   constexpr ll BINF = Inf<ll>::inf();   int solve() {     int n, k;     cin >> n >> k;     vi a(n);     cin >> a;     ll ans = a[n - 1] - a[0];     vi wtf;     for (int i = 0; i + 1 < n; i++) wtf.push_back(a[i] - a[i + 1]);     sort(wtf.begin(), wtf.end());     for (int i = 0; i < k - 1; i++) ans += wtf[i];     cout << ans << endl;     return 0;   }   int main() {     ios::sync_with_stdio(0);     solve();     return 0;   }   template <class T>   istream &operator>>(istream &is, vector<T> &v) {     for (auto it = v.begin(); it != v.end(); ++it) is >> *it;     return is;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto it = v.begin(); it != v.end();)       os << *it, os <<    n [++it == v.end()];     return os;   }   template <class T, class U>   istream &operator>>(istream &is, pair<T, U> &p) {     return is >> p.first >> p.second;   }   template <class T, class U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os << p.first <<     << p.second;   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> ll;   typedef vector<long long> vl;   typedef vector<ll> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<   n ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   vvl g(111000);   vl ind(111000, 0), vis(111000, false);   long long c = 0;   bool rec(long long node, long long p) {     vl ch;     ind[node] = c++;     vis[node] = 1;     for (auto &it : g[node]) {       if (it == p) continue;       if (!vis[it]) {         if (!rec(it, node)) ch.push_back((it));       } else if (ind[node] < ind[it])         ch.push_back((it));     }     for (long long i = 0; i + 1 < ch.size(); i += 2)       cout << ch[i] <<     << node <<     << ch[i + 1] <<   n ;     if (ch.size() % 2 == 1) {       cout << p <<     << node <<     << ch[ch.size() - 1] <<   n ;       return true;     }     return false;   }   int main() {     long long n, m;     cin >> n >> m;     if (m % 2 == 1) {       cout <<  No solution             <<   n ;       return 0;     }     while (m--) {       long long x, y;       cin >> x >> y;       g[x].push_back((y));       g[y].push_back((x));     }     rec(1, -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int maxn = 100010;   const int maxbit = 18;   const int sz = 1500;   inline int read() {     int x = 0, f = 1;     char ch = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;     return x * f;   }   struct node {     int l, r, tid, ans, id;     node() {}     node(int _l, int _r, int _tid, int _ans, int _id) {       l = _l;       r = _r;       tid = _tid;       ans = _ans;       id = _id;     }   } que[maxn];   struct node2 {     int p, fr, to;     node2() {}     node2(int _p, int _fr, int _to) {       p = _p;       fr = _fr;       to = _to;     }   } cz[maxn];   vector<int> oo;   inline int bl(int x) { return (x - 1) / sz; }   bool cmp(node x, node y) {     if (bl(x.l) != bl(y.l))       return x.l < y.l;     else if (bl(x.r) != bl(y.r))       return x.r < y.r;     else       return x.tid < y.tid;   }   bool cmp2(node x, node y) { return x.id < y.id; }   int n, q, cntz, cntq;   int a[maxn], fl[maxn], Now, L, R, cnt[maxn << 2];   inline void add(int x) {     --fl[cnt[x]];     ++fl[++cnt[x]];   }   inline void del(int x) {     --fl[cnt[x]];     ++fl[--cnt[x]];   }   inline void go(node2 &t) {     if (t.p >= L && t.p <= R) del(t.fr), add(t.to);     a[t.p] = t.to;   }   inline void re(node2 &t) {     if (t.p >= L && t.p <= R) del(t.to), add(t.fr);     a[t.p] = t.fr;   }   int main() {     fl[0] = INF;     n = read();     q = read();     for (int i = 1; i <= n; ++i) a[i] = read(), oo.push_back(a[i]);     for (int i = 1; i <= q; ++i) {       int t = read();       if (t == 1) {         int l = read(), r = read();         que[++cntq] = node(l, r, Now, 0, i);       } else {         int p = read(), x = read();         oo.push_back(x);         cz[++cntz] = node2(p, a[p], x);         a[p] = x;         ++Now;       }     }     sort(oo.begin(), oo.end());     int ss = unique(oo.begin(), oo.end()) - oo.begin();     oo.resize(ss);     for (int i = 1; i <= n; ++i)       a[i] = lower_bound(oo.begin(), oo.end(), a[i]) - oo.begin() + 1;     for (int i = 1; i <= cntz; ++i) {       cz[i].fr = lower_bound(oo.begin(), oo.end(), cz[i].fr) - oo.begin() + 1;       cz[i].to = lower_bound(oo.begin(), oo.end(), cz[i].to) - oo.begin() + 1;     }     sort(que + 1, que + cntq + 1, cmp);     for (int i = 1; i <= cntq; ++i) {       node now = que[i];       while (R < now.r) add(a[++R]);       while (L > now.l) add(a[--L]);       while (R > now.r) del(a[R--]);       while (L < now.l) del(a[L++]);       while (Now < now.tid) go(cz[++Now]);       while (Now > now.tid) re(cz[Now--]);       while (fl[que[i].ans]) ++que[i].ans;     }     sort(que + 1, que + cntq + 1, cmp2);     for (int i = 1; i <= cntq; ++i) printf( %d n , que[i].ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> myvec[100001];   set<int> myset[2];   set<int>::iterator it;   int mark[100001];   bool isbipartite(int src) {     int color[100001];     memset(color, -1, sizeof(color));     queue<int> q;     q.push(src);     mark[src] = 1;     color[src] = 1;     myset[color[src]].insert(src);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v = 0; v < myvec[u].size(); v++) {         if (color[myvec[u][v]] == -1)           color[myvec[u][v]] = 1 - color[u], q.push(myvec[u][v]),           myset[color[myvec[u][v]]].insert(myvec[u][v]), mark[myvec[u][v]] = 1;         else if (color[myvec[u][v]] == color[u])           return false;       }     }     return true;   }   int main() {     long long int x, y;     int a, b;     cin >> a >> b;     while (b--) {       cin >> x >> y;       myvec[x].push_back(y);       myvec[y].push_back(x);     }     bool solve = true;     for (int i = 1; i <= a; i++) {       if (mark[i] == 0) {         solve = (solve && isbipartite(i));       }     }     if (solve == true) {       cout << myset[0].size() << endl;       for (it = myset[0].begin(); it != myset[0].end(); it++) {         cout << *it <<    ;       }       cout << endl;       cout << myset[1].size() << endl;       for (it = myset[1].begin(); it != myset[1].end(); it++) {         cout << *it <<    ;       }       cout << endl;     } else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int timeTook[50010][10];   int timeSpent[50010];   int main() {     int numOfPictures, numOfPainters;     scanf( %d %d , &numOfPictures, &numOfPainters);     for (int i = 0; i < numOfPictures; i++) {       for (int j = 0; j < numOfPainters; j++) {         scanf( %d , &timeTook[i][j]);       }     }     for (int i = 0; i < numOfPictures; i++) timeSpent[i] = 0;     for (int painter = 0; painter < numOfPainters - 1; painter++) {       int curTime = 0;       for (int i = 0; i < numOfPictures; i++) {         if (curTime >= timeSpent[i]) {           timeSpent[i] += (curTime - timeSpent[i]) + timeTook[i][painter];           curTime += timeTook[i][painter];         } else {           int waitTime = timeSpent[i] - curTime;           timeSpent[i] += timeTook[i][painter];           curTime += waitTime + timeTook[i][painter];         }       }     }     int curTime = 0;     for (int i = 0; i < numOfPictures; i++) {       if (curTime >= timeSpent[i]) {         curTime += timeTook[i][numOfPainters - 1];       } else {         int waitTime = timeSpent[i] - curTime;         curTime += waitTime + timeTook[i][numOfPainters - 1];       }       printf( %d  , curTime);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   string s;   int a[maxn], tot, n;   int main() {     while (cin >> n) {       memset(a, 0, sizeof a);       tot = 0;       cin >> s;       string temp = s;       if (n == 1) {         puts( 0 );         continue;       }       for (int i = n - 1; i >= 1; i--) {         if (s[i] ==  B )           s[i] =  W , s[i - 1] = (s[i - 1] ==  B  ?  W  :  B ), a[++tot] = i - 1;       }       if (s[0] ==  B ) {         tot = 0;         s = temp;         for (int i = n - 1; i >= 1; i--) {           if (s[i] ==  W )             s[i] =  B , s[i - 1] = (s[i - 1] ==  B  ?  W  :  B ),             a[++tot] = i - 1;         }         if (s[0] ==  W )           puts( -1 );         else {           cout << tot << endl;           for (int i = 1; i <= tot; i++) cout << a[i] + 1 <<    ;           cout << endl;         }       } else {         cout << tot << endl;         for (int i = 1; i <= tot; i++) cout << a[i] + 1 <<    ;         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a = 0, b = 0, c = 0, d = 0, n, temp, dl;     cin >> n;     for (int i = 0; i <= n; i++) {       if (i < n) {         cin >> temp;       } else {         temp = max(a, d) + 1;       }       dl = temp - a;       if (dl != 1 && dl != -1) {         if (!b) {           b = i + 1;           d = temp;         } else if (!c) {           c = i;         } else {           b = 0;           c = 0;           break;         }       } else if (!c && b) {         if (dl != -1) {           b = 0;           c = 0;           break;         }       }       a = temp;     }     cout << b <<     << c;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, T, q, w, e, d[100001], v[100001], t[100001], B = 130;   int main() {     scanf( %lld%lld , &a, &b);     for (int i = 1; i <= a; i++) scanf( %lld , &d[i]), v[d[i]] = i, t[i] = i;     for (int i = 1; i <= a; i++)       for (int j = 1; j <= B; j++) t[i] = d[t[i]];     for (int ii = 1; ii <= b; ii++) {       scanf( %lld%lld%lld , &q, &w, &e);       if (q == 1) {         swap(d[w], d[e]);         swap(v[d[w]], v[d[e]]);         long long tt = e, yy = e;         for (int i = 1; i <= B; i++) yy = d[yy];         for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy];         tt = w, yy = w;         for (int i = 1; i <= B; i++) yy = d[yy];         for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy];       } else {         long long ff = w;         for (int i = 1; i <= e / B; i++) ff = t[ff];         e %= B;         for (int i = 1; i <= e; i++) ff = d[ff];         printf( %lld n , ff);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, t, s;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     if (n < 3 * k) return cout << -1, 0;     for (int i = 0; i < n; i++)       if (i / k % 2 == 1)         cout << (1 + i) % k + 1 <<    ;       else         cout << i % k + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long fx[] = {+1, -1, +0, +0};   const long long fy[] = {+0, +0, +1, -1};   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long xo, yo, ax, ay, bx, by, xs, ys, t;   void solve() {     cin >> xo >> yo >> ax >> ay >> bx >> by;     cin >> xs >> ys >> t;     vector<long long> x(1, xo), y(1, yo);     long long LIMIT = (1LL << 62) - 1;     while ((LIMIT - bx) / ax >= x.back() && (LIMIT - by) / ay >= y.back()) {       x.push_back(ax * x.back() + bx);       y.push_back(ay * y.back() + by);     }     long long n = x.size();     long long ans = 0;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         long long length = x[j] - x[i] + y[j] - y[i];         long long dist2Left = abs(xs - x[i]) + abs(ys - y[i]);         long long dist2Right = abs(xs - x[j]) + abs(ys - y[j]);         if (length <= t - dist2Left || length <= t - dist2Right)           ans = max(ans, j - i + 1);       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   #define For(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i)   #define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)   #define Forr(i, a, b) for (int i = (a), _##i = (b); i > _##i; --i)   #define FORR(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)   #define all(a) a.begin(), a.end()   #define range(i, a) for (auto& i : a)   #define RANGE(i, a) for (auto i = a.rbegin(); i != a.rend(); ++i)   #define SINGLE   using ll = long long;   using pii = std::pair<int, int>;   using pdd = std::pair<double, double>;      namespace Solver {     const int N = (1 << 18) + 5;     std::string opt;     int res[N << 1];     int n, cnt;     void update(int p, char c) {       if (opt[p] == c)         return;       opt[p] = c;       // if (c ==  ? )       //   res[p] = res[p << 1] + res[p << 1 | 1];       while (p) {         if (opt[p] ==  ? )           res[p] = res[p << 1] + res[p << 1 | 1];         else if (opt[p] ==  1 )           res[p] = res[p << 1];         else           res[p] = res[p << 1 | 1];         p >>= 1;       }     }     void build(int u) {       if ((u << 1) <= cnt)         build(u << 1);       if ((u << 1 | 1) <= cnt)         build(u << 1 | 1);       if (opt[u] ==  ? )         res[u] = res[u << 1] + res[u << 1 | 1];       else if (opt[u] ==  1 )         res[u] = res[u << 1];       else         res[u] = res[u << 1 | 1];     }     void main() {       std::cin >> n;       std::string temp;       std::cin >> temp;       std::fill(res, res + (N << 1) - 1, 1);       cnt = (1 << n) - 1;       opt =    ;       RANGE (i, temp)         opt.push_back(*i);       build(1);       int T;       for (std::cin >> T; T--;) {         int p;         char c;         std::cin >> p >> c;         update(cnt - p + 1, c);         std::cout << res[1] << std::endl;       }     }   }      int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     #ifndef SINGLE     int T;     for (std::cin >> T; T--;)     #endif       Solver::main();     return 0;   }


#include<iostream>   #include<vector>   #include<queue>   #include<cstring>   #include<cmath>   #include<map>   #include<set>   #include<cstdio>   #include<algorithm>   #define debug(a) cout<<#a<< = <<a<<endl;   using namespace std;   const int maxn=1e3+100;   typedef long long LL;   LL a[maxn];   int main(void)   {     cin.tie(0);std::ios::sync_with_stdio(false);     LL n;cin>>n;     if(n==1){       cout<<4<<endl;     }     else{          if(n&1) cout<<(1+ ( (3*n*(n+4)+2)+ ( (n+4)*n+2 )   )/8 )<<endl;       else cout<<(1+ ( (3*n*(n+4)+2)- ( (n+4)*n+2 )   )/8 )<<endl;     }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     long long int n;     cin >> n;     if (n == 1 || n == 2) {       cout << n << endl;       return 0;     }     if (n % 2 == 1) {       cout << (n * (n - 1) * (n - 2)) << endl;       return 0;     }     if (n == 4 || n == 6) {       cout << ((n * (n - 1) * (n - 2)) / 2) << endl;       return 0;     }     if (n % 3 == 0) {       cout << ((n - 1) * (n - 2) * (n - 3)) << endl;       return 0;     }     cout << (n * (n - 1) * (n - 3)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, t, z;   bool dfs(long long x, long long y) {     if (x < y) swap(x, y);     if (!y) return 0;     if (!dfs(y, x % y)) return 1;     z = x / y;     if (y & 1) return (z & 1) ^ 1;     return z % (y + 1) & 1 ^ 1;   }   signed main() {     scanf( %lld , &t);     while (t--) {       scanf( %lld%lld , &a, &b);       if (dfs(a, b))         printf( First n );       else         printf( Second n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cout.tie(0);     string s, t, b;     int n;     vector<pair<char, char>> v;     set<char> z;     bool fine = false;     char a[26];     for (int i = 0; i < 26; i++) a[i] =  @ ;     cin >> s >> t;     for (int i = 0; i < s.length(); i++)       if (a[s[i] -  a ] ==  @ )         a[s[i] -  a ] = t[i];       else if (a[s[i] -  a ] != t[i]) {         cout << -1;         return 0;       }     for (int i = 0; i < 26; i++)       if (a[i] !=  @ ) {         if (((char)(i +  a ) != a[a[i] -  a ]) && ( @  != a[a[i] -  a ])) {           cout << -1;           return 0;         }       }     for (int i = 0; i < 26; i++)       if ((a[i] != (char)( a  + i)) && (a[i] !=  @ )) {         fine = false;         for (int j = 0; j < v.size(); j++)           if ((v[j].first == a[i]) && (v[j].second == (char)( a  + i)))             fine = true;         if (fine == false) v.push_back(make_pair((char)( a  + i), a[i]));       }     for (int i = 0; i < v.size(); i++) z.insert(v[i].second);     if (z.size() != v.size()) {       cout << -1;       return 0;     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC diagnostic ignored  -Wunused-result    #pragma GCC diagnostic ignored  -Wsign-compare    using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case--) {       solve();     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }   void solve() {     int n, m, t;     vector<int> arr;     bool odd = false;     bool zero = false;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> t;         if (t == 0) {           zero = true;         }         if (t < 0) {           odd = !odd;           arr.push_back(-t);         } else {           arr.push_back(t);         }       }     }     sort(arr.begin(), arr.end());     int sum = 0;     for (int i = 0; i < arr.size(); i++) {       sum += arr[i];     }     if (zero) {       cout << sum << endl;     } else {       if (odd) {         sum -= 2 * arr[0];         cout << sum << endl;       } else {         cout << sum << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200002;   int n, x1, x2, p[N];   pair<int, int> a[N];   int i1, i2;   bool solve() {     i1 = i2 = -1;     for (int i = n; i >= 1; --i) {       if (a[i].first * (n - i + 1) >= x1) {         i1 = i;         break;       }     }     for (int i = i1 - 1; i >= 1; --i) {       if (a[i].first * (i1 - i) >= x2) {         i2 = i;         break;       }     }     return i1 != -1 && i2 != -1;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> x1 >> x2;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a + 1, a + 1 + n);     if (solve()) {       cout <<  Yes  << endl;       cout << (n - i1 + 1) <<     << (i1 - i2) << endl;       for (int i = i1; i <= n; ++i) cout << a[i].second <<    ;       cout << endl;       for (int i = i2; i < i1; ++i) cout << a[i].second <<    ;       cout << endl;       return 0;     }     swap(x1, x2);     if (solve()) {       cout <<  Yes  << endl;       cout << (i1 - i2) <<     << (n - i1 + 1) << endl;       for (int i = i2; i < i1; ++i) cout << a[i].second <<    ;       cout << endl;       for (int i = i1; i <= n; ++i) cout << a[i].second <<    ;       cout << endl;       return 0;     }     cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 9;   vector<int> g[N];   int tin[N];   int tout[N];   int sz[N];   int tt;   int toys[N];   bool root[N];   void dfs(int v) {     tin[v] = tt++;     sz[v] = 1;     for (auto i : g[v]) {       dfs(i);       sz[v] += sz[i];     }     tout[v] = tt++;   }   bool parent(int v, int p) { return (tin[v] > tin[p] && tout[v] < tout[p]); }   int main() {     int n, m, k, q;     cin >> n >> m >> k >> q;     for (int i = 1; i <= n; i++) root[i] = true;     for (int i = 1; i <= k; i++) {       int v, t;       cin >> v >> t;       if (toys[t] == 0) {         toys[t] = v;         continue;       }       g[toys[t]].push_back(v);       root[v] = false;       toys[t] = v;     }     for (int i = 1; i <= n; i++)       if (root[i]) dfs(i);     for (int i = 1; i <= q; i++) {       int v, t;       cin >> v >> t;       if (toys[t] == 0) {         cout << 0 << endl;         continue;       }       if (parent(toys[t], v)) {         cout << sz[v] << endl;         continue;       }       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum, a, b, c, ans = 0;     cin >> sum >> a >> b >> c;     for (int i = 0; i <= a; i += 2)       for (int j = 0; j <= c; ++j)         if (sum - i / 2 - 2 * j <= b && sum - i / 2 - 2 * j >= 0) ans++;     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 128;   struct Matrix {     double a[N][N];     Matrix() {       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++) a[i][j] = (i == j ? 1 : 0);     }     Matrix operator*(const Matrix &A) const {       Matrix R = Matrix();       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++) {           R.a[i][j] = 0;           for (int h = 0; h < N; h++) R.a[i][j] += a[i][h] * A.a[h][j];         }       return R;     }   };   Matrix bin_pow(Matrix A, int p) {     if (p == 0) return Matrix();     if (p == 2 || (p & 1)) return A * bin_pow(A, p - 1);     return bin_pow(bin_pow(A, p / 2), 2);   }   double p[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i <= m; i++) scanf( %lf , &p[i]);     Matrix A = Matrix();     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) A.a[i][j] = p[i ^ j];     A = bin_pow(A, n);     printf( %.13lf n , 1 - A.a[0][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, b, p, f, h, c;     cin >> t;     vector<int> arr(t);     for (int i = 0; i < t; ++i) {       cin >> b >> p >> f;       cin >> h >> c;       if (h > c) {         while (b >= 2 && p > 0) {           arr[i] = arr[i] + h;           b = b - 2;           p--;         }         while (b >= 2 && f > 0) {           arr[i] = arr[i] + c;           b = b - 2;           f--;         }       } else {         while (b >= 2 && f > 0) {           arr[i] = arr[i] + c;           b = b - 2;           f--;         }         while (b >= 2 && p > 0) {           arr[i] = arr[i] + h;           b = b - 2;           p--;         }       }     }     for (int i = 0; i < t; ++i) {       cout << arr[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void solve() {     long long int n, k;     cin >> n >> k;     if (n / 2 > k or n == 1) {       if (k == 0 and n == 1) {         cout << 1 <<   n ;         return;       }       cout << -1 <<   n ;       return;     } else {       vector<long long int> v;       k -= (n / 2);       k++;       if (k == 0) k = 1;       v.push_back(k);       v.push_back(2 * k);       map<long long int, long long int> make_pair;       make_pair[k]++;       make_pair[2 * k]++;       long long int c = 1;       for (__typeof(n / 2 - 1) i = (0) - ((0) > (n / 2 - 1));            i != (n / 2 - 1) - ((0) > (n / 2 - 1));            i += 1 - 2 * ((0) > (n / 2 - 1))) {         while (make_pair[c] + make_pair[c + 1] != 0) {           c++;         }         v.push_back(c);         v.push_back(c + 1);         make_pair[c]++;         make_pair[c + 1]++;         c += 2;       }       if (v.size() != n) {         while (make_pair[2 * k + 1] != 0) k++;         v.push_back(2 * k + 1);       }       for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));            i += 1 - 2 * ((0) > (n))) {         cout << v[i] <<    ;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const long long MOD = 1000000007;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   const double PI = 3.14159265358979323846;   int n, k;   char s[100000];   vector<int> v[2];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf(  %c , s + i);     for (int i = 0; i < n; i++) {       if (s[i] ==  0 )         v[0].push_back(i);       else         v[1].push_back(i);     }     if (v[0].size() == 0 || v[1].size() == 0) {       puts( tokitsukaze );       return 0;     }     if (v[0][v[0].size() - 1] - v[0][0] + 1 <= k ||         v[1][v[1].size() - 1] - v[1][0] + 1 <= k) {       puts( tokitsukaze );       return 0;     }     for (int i = 0; i < n - k + 1; i++) {       for (int j = 0; j < 2; j++) {         if (i <= v[j ^ 1][0] && v[j ^ 1][0] < i + k) {           int pos = lower_bound(v[j ^ 1].begin(), v[j ^ 1].end(), i + k) -                     v[j ^ 1].begin();           if (v[j ^ 1][v[j ^ 1].size() - 1] - v[j ^ 1][pos] + 1 > k) {             puts( once again );             return 0;           }         } else if (i <= v[j ^ 1][v[j ^ 1].size() - 1] &&                    v[j ^ 1][v[j ^ 1].size() - 1] < i + k) {           int pos =               lower_bound(v[j ^ 1].begin(), v[j ^ 1].end(), i) - v[j ^ 1].begin();           pos--;           if (v[j ^ 1][pos] - v[j ^ 1][0] + 1 > k) {             puts( once again );             return 0;           }         } else {           puts( once again );           return 0;         }       }     }     puts( quailty );   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 1e6 + 10;   int max_score[5] = {25, 25, 25, 25, 15};   pair<int, int> dp[6][4][201][201];   void pre() {     for (int i = 0; i < (6); ++i)       for (int win = 0; win < (4); ++win)         for (int j = 0; j < (201); ++j)           for (int k = 0; k < (201); ++k) dp[i][win][j][k].first = -1;     dp[0][0][0][0] = {0, 0};     for (int i = 0; i < (5); ++i)       for (int win = 0; win < (4); ++win)         for (int j = 0; j < (201); ++j)           for (int k = 0; k < (201); ++k) {             if (dp[i][win][j][k].first == -1) continue;             if (win == 3 || i - win == 3) continue;             if (i - win < 3 && k + max_score[i] <= 200) {               for (int score = (0); score <= (max_score[i] - 2); ++score) {                 if (j + score <= 200) {                   dp[i + 1][win][j + score][k + max_score[i]] = {score,                                                                  max_score[i]};                 }               }             }             if (win < 3 && j + max_score[i] <= 200) {               for (int score = (0); score <= (max_score[i] - 2); ++score) {                 if (k + score <= 200) {                   dp[i + 1][win + 1][j + max_score[i]][k + score] = {max_score[i],                                                                      score};                 }               }             }             for (int score = (max_score[i] + 1); score <= (200); ++score) {               int good = 0;               if (i - win < 3 && j + score - 2 <= 200 && k + score <= 200) {                 good = 1;                 dp[i + 1][win][j + score - 2][k + score] = {score - 2, score};               }               if (win < 3 && j + score <= 200 && k + score - 2 <= 200) {                 good = 1;                 dp[i + 1][win + 1][j + score][k + score - 2] = {score, score - 2};               }               if (!good) break;             }           }   }   void print(int i, int win, int j, int k) {     printf( %d:%d n , win, i - win);     vector<pair<int, int> > AA;     while (i) {       AA.push_back(dp[i][win][j][k]);       i--;       if (AA.back().first > AA.back().second) win--;       j -= AA.back().first;       k -= AA.back().second;     }     reverse((AA).begin(), (AA).end());     for (int i = 0; i < (((int)(AA).size())); ++i) {       if (i) printf(   );       printf( %d:%d , AA[i].first, AA[i].second);     }     W(  );   }   void solve(int a, int b) {     for (int lose = (0); lose <= (2); ++lose) {       if (dp[lose + 3][3][a][b].first != -1) {         print(lose + 3, 3, a, b);         return;       }     }     for (int win = 2; win >= 0; win--) {       if (dp[win + 3][win][a][b].first != -1) {         print(win + 3, win, a, b);         return;       }     }     W( Impossible );   }   int main() {     pre();     int ___T;     scanf( %d , &___T);     for (int cs = 1; cs <= ___T; cs++) {       int a, b;       R(a, b);       solve(a, b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void inputOutput() {}   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     inputOutput();     string yelo =  AHIMOTUVWXY ;     string s;     cin >> s;     long long int n = s.length();     for (long long int i = 0; i < n; i++) {       if (yelo.find(s[i]) == string::npos) return cout <<  NO , 0;     }     for (long long int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) return cout <<  NO , 0;     }     cout <<  YES ;     cerr <<  time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100, V = 100;   struct bottle {     int a, b;     bool operator<(const bottle &bt) const { return b > bt.b; }   } bot[N + 1];   int dp[N + 1][N * V + 1];   int main() {     int n, shui = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &bot[i].a);       shui += bot[i].a;     }     for (int j = 1; j <= n; ++j) scanf( %d , &bot[j].b);     sort(bot + 1, bot + n + 1);     int ping = 0;     for (int i = 1, w = shui; w > 0; ++i) {       w -= bot[i].b;       ++ping;     }     memset(dp, -1, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; ++i)       for (int j = ping; j; --j)         for (int k = shui; k >= bot[i].a; --k)           if (~dp[j - 1][k - bot[i].a])             dp[j][k] = max(dp[j][k], dp[j - 1][k - bot[i].a] + bot[i].b);     int mx = 0;     for (int i = shui; ~i; --i)       if (dp[ping][i] >= shui) {         mx = i;         break;       }     printf( %d %d n , ping, shui - mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[300001];   bool mark[300001];   bool vis[300001];   int road_count = 0;   int main(void) {     int n, m;     cin >> n >> m;     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     memset(mark, 0, sizeof(bool) * n);     queue<int> q;     for (int i = 0; i < n; i++) q.push(i);     while (!q.empty()) {       int x = q.front();       q.pop();       int count = 0;       for (int i = 0; i < g[x].size(); i++) {         if (mark[x] == mark[g[x][i]]) count++;       }       if (count > 1) {         mark[x] = !mark[x];         for (int i = 0; i < g[x].size(); i++) {           if (mark[x] == mark[g[x][i]]) q.push(g[x][i]);         }       }     }     for (int i = 0; i < n; i++) {       if (mark[i])         cout <<  1 ;       else         cout <<  0 ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct node {     int id, next;     node() {}     node(int a, int b) {       id = a;       next = b;     }   };   struct Brige {     int x, y;   } brige[maxn];   vector<int> v[maxn], g[maxn];   vector<node> q[maxn];   int dfn[maxn], low[maxn];   int f[maxn], belong[maxn];   bool visit[maxn];   int n, m, k, cnt, t, bge;   void init() {     for (int i = 1; i <= n; i++) {       v[i].clear();       g[i].clear();     }   }   int find(int x) {     if (x != f[x]) f[x] = find(f[x]);     return f[x];   }   void merge(int a, int b) {     int x = find(a), y = find(b);     if (x == y) return;     f[y] = x;   }   void tarjan(int u, int father) {     visit[u] = true;     cnt++;     dfn[u] = low[u] = cnt;     for (int i = 0; i < (int)v[u].size(); i++) {       int x = v[u][i];       if (!visit[x]) {         tarjan(x, u);         low[u] = min(low[u], low[x]);         if (low[x] > dfn[u]) {           bge++;           brige[bge].x = u;           brige[bge].y = x;         }         if (low[x] <= dfn[u]) merge(x, u);       } else if (x != father)         low[u] = min(low[u], dfn[x]);     }   }   void rebuild() {     t = 0;     memset(belong, -1, sizeof(belong));     for (int i = 1; i <= n; i++) {       int x = find(i);       if (belong[x] == -1) {         t++;         belong[x] = t;       }       belong[i] = belong[x];     }     for (int i = 1; i <= bge; i++) {       int a = brige[i].x, b = brige[i].y;       g[belong[a]].push_back(belong[b]);       g[belong[b]].push_back(belong[a]);     }   }   void solve() {     memset(visit, false, sizeof(visit));     cnt = 0;     bge = 0;     for (int i = 1; i <= n; i++) f[i] = i;     tarjan(1, 0);     rebuild();   }   bool Solve[maxn], check[maxn];   int ans[maxn], d[maxn];   void lca(int u) {     visit[u] = true;     for (int i = 0; i < (int)g[u].size(); i++) {       int x = g[u][i];       if (!visit[x]) {         d[x] = d[u] + 1;         lca(x);         f[x] = u;       }     }     check[u] = true;     for (int i = 0; i < (int)q[u].size(); i++) {       int x = q[u][i].next;       if (check[x] == true && Solve[q[u][i].id] == false) {         int ansestor = find(x);         ans[q[u][i].id] = d[u] + d[x] - 2 * d[ansestor];         Solve[q[u][i].id] = true;       }     }   }   int main() {     int a, b;     while (scanf( %d%d , &n, &m) != EOF) {       init();       while (m--) {         scanf( %d%d , &a, &b);         v[a].push_back(b);         v[b].push_back(a);       }       solve();       scanf( %d , &k);       for (int i = 1; i <= k; i++) {         scanf( %d%d , &a, &b);         a = belong[a], b = belong[b];         q[a].push_back(node(i, b));         q[b].push_back(node(i, a));       }       memset(visit, false, sizeof(visit));       memset(Solve, false, sizeof(Solve));       memset(check, false, sizeof(check));       for (int i = 1; i <= t; i++) f[i] = i;       d[1] = 0;       lca(1);       for (int i = 1; i <= k; i++) printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   int a[200100], b[200100];   map<int, int> mp[2];   int arr[200100];   map<int, int> vst;   int main() {     int n, st;     cin >> n >> st;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int m, ed;     cin >> m >> ed;     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     int d = 1;     int ans = 1;     for (int j = 1; j <= 30; j++) {       mp[0].clear();       mp[1].clear();       int x = (1 << j);       int nn = 0;       for (int i = 1; i <= n; i++) {         int r = a[i] % x;         mp[0][r]++;         ans = max(ans, mp[0][r]);         arr[++nn] = r;       }       for (int i = 1; i <= m; i++) {         int r = b[i] % x;         mp[1][r]++;         ans = max(ans, mp[1][r] + mp[0][(r + x / 2) % x]);         arr[++nn] = r;       }     }     for (int i = 1; i <= n; i++) vst[a[i]] = 1;     for (int i = 1; i <= m; i++)       if (vst[b[i]]) ans = max(ans, 2);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x;     cin >> x;     cout << x / 2520;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T a) {     return a < 0 ? -a : a;   }   template <typename T>   T sqr(T a) {     return a * a;   }   const int INF = (int)1e9;   const long double EPS = 1e-9;   const long double PI = 3.1415926535897932384626433832795;   const int N = 1000;   pair<long double, long double> operator-(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return pair<long double, long double>(a.first - b.first, a.second - b.second);   }   pair<long double, long double> operator+(       const pair<long double, long double>& a,       const pair<long double, long double>& b) {     return pair<long double, long double>(a.first + b.first, a.second + b.second);   }   inline pair<long double, long double> rotate(       const pair<long double, long double>& a, const long double& ang) {     return pair<long double, long double>(         a.first * cos(ang) - a.second * sin(ang),         a.first * sin(ang) + a.second * cos(ang));   }   int m;   int n;   pair<long double, long double> p[N];   vector<int> g[N];   vector<int> pol[N];   const long double ROT_ANG = 2 * PI / 5;   void draw(int cnt, int s1, int s2) {     int cp[10];     cp[0] = s1;     cp[1] = s2;     pair<long double, long double> v = p[s2] - p[s1];     int prev = s2;     for (int i = 0; i < int(3); ++i) {       v = rotate(v, ROT_ANG);       p[n] = p[prev] + v;       cp[2 + i] = n;       prev = n;       n++;     }     v = rotate(v, ROT_ANG);     pair<long double, long double> u = p[n - 1] + v;     if (abs(p[s1].first - u.first) > 1e-1 || abs(p[s1].second - u.second) > 1e-1)       throw;     for (int i = 0; i < int(5); ++i) {       int i1 = (i + 1) % 5;       int i2 = (i + 4) % 5;       for (int j = 0; j < int(5); ++j) {         if (j != i1 && j != i && j != i2) g[cp[i]].push_back(cp[j]);       }     }     for (int i = 0; i < int(5); ++i) pol[m - cnt].push_back(cp[i]);     if (cnt > 1) {       int i1 = 0;       for (int i = 1; i < 5; ++i)         if (p[cp[i1]] < p[cp[i]]) i1 = i;       int i2 = i1 + 1;       if (i2 == 5) i2 = 0;       draw(cnt - 1, cp[i2], cp[i1]);     }   }   set<pair<long double, long double> > visited;   vector<int> ans;   void fleury(int v) {     while (!g[v].empty()) {       int u = g[v].back();       g[v].pop_back();       if (visited.count(pair<long double, long double>(min(v, u), max(v, u))))         continue;       visited.insert(pair<long double, long double>(min(v, u), max(v, u)));       fleury(u);       ans.push_back(u);     }   }   int main() {     cin >> m;     p[0] = pair<long double, long double>(0, 0);     p[1] = pair<long double, long double>(10, 0);     n = 2;     draw(m, 0, 1);     long double minY = 1e100, minX = 1e100;     for (int i = 0; i < int(n); ++i) {       minY = min(minY, p[i].second);       minX = min(minX, p[i].first);     }     for (int i = 0; i < int(n); ++i) {       p[i].first -= minX + 4999;       p[i].second -= minY + 4999;     }     cout << n << endl;     for (int i = 0; i < int(n); ++i) {       printf( %0.10lf %0.10lf n , (double)p[i].first, (double)p[i].second);     }     for (int i = 0; i < int(m); ++i) {       for (int j = 0; j < int(5); ++j) {         if (j != 0) printf(   );         printf( %d , pol[i][j] + 1);       }       puts(  );     }     fleury(0);     ans.push_back(0);     for (int i = 0; i < int(int((ans).size())); ++i) {       if (i != 0) printf(   );       printf( %d , ans[i] + 1);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<char> deputi;     vector<vector<char> > off;     int m, n;     char boss;     cin >> n >> m >> boss;     off.resize(n);     for (int i = 0; i < n; i++) off[i].resize(m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) do {           cin >> off[i][j];         } while (off[i][j] ==   n );     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (off[i][j] == boss) {           if (i > 0) deputi.insert(off[i - 1][j]);           if (i < n - 1) deputi.insert(off[i + 1][j]);           if (j > 0) deputi.insert(off[i][j - 1]);           if (j < m - 1) deputi.insert(off[i][j + 1]);         }     deputi.erase( . );     deputi.erase(boss);     cout << deputi.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int num : a) {         m -= num;       }       if (m != 0)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, res = 0, cp = 0, cn = 0, cz = 0;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > 0)         cp++;       else if (arr[i] < 0)         cn++;       else         cz++;     }     if (cp > (cn + cz)) {       cout <<  1 ;     } else if (cn > (cp + cz)) {       cout <<  -1 ;     } else {       if (cp == (cn + cz) && n % 2 == 0)         cout <<  1 ;       else if (cn == (cp + cz) && n % 2 == 0)         cout <<  -1 ;       else         cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 1e9 + 7;   const ll longinf = 1LL << 60;   const ll mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int n;       cin >> n;       cout << n / 2 + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   const int N_ = (int)1e6 + 2;   long long Hash_a[N_];   long long Hash_b[N_];   long long pow26[N_];   string a, b;   long long n;   long long get_hash_a(long long x, long long y) {     return (Hash_a[y] - Hash_a[x - 1] * pow26[y - x + 1] + 1LL * mod * mod) % mod;   }   long long get_hash_b(long long x, long long y) {     return (Hash_b[y] - Hash_b[x - 1] * pow26[y - x + 1] + 1LL * mod * mod) % mod;   }   bool F(long long L1, long long R1, long long L2, long long R2) {     int len = R1 - L1 + 1;     if (len % 2 == 1) {       return get_hash_a(L1, R1) == get_hash_b(L2, R2);     } else {       if (get_hash_a(L1, R1) == get_hash_b(L2, R2)) return true;       int R_1 = L1 + len / 2 - 1;       int L_1 = R_1 + 1;       int R_2 = L2 + len / 2 - 1;       int L_2 = R_2 + 1;       if (F(L1, R_1, L_2, R2) && F(L_1, R1, L2, R_2)) return true;       if (F(L1, R_1, L2, R_2) && F(L_1, R1, L_2, R2)) return true;       return false;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b;     n = a.size();     pow26[0] = 1;     for (int i = 1; i <= n; i++) {       Hash_a[i] = (Hash_a[i - 1] * 26 + (a[i - 1] -  a  + 1)) % mod;       Hash_b[i] = (Hash_b[i - 1] * 26 + (b[i - 1] -  a  + 1)) % mod;       pow26[i] = pow26[i - 1] * 26;       pow26[i] %= mod;     }     if (F(1, n, 1, n))       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, ans(0);     cin >> n;     map<string, int> mp;     string s;     while (n--) {       cin >> s;       mp[s]++;     }     for (auto x : mp) {       if (x.first ==  Tetrahedron )         p = 4;       else if (x.first ==  Cube )         p = 6;       else if (x.first ==  Octahedron )         p = 8;       else if (x.first ==  Dodecahedron )         p = 12;       else         p = 20;       ans += p * x.second;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct ele {     long long a, b;   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       struct ele arr[n];       bool issorted = true, zer0 = false, one = false;       for (long long i = 0; i < n; i++) {         cin >> arr[i].a;         if (i > 0 && arr[i].a < arr[i - 1].a) issorted = false;       }       for (long long i = 0; i < n; i++) {         cin >> arr[i].b;         if (arr[i].b == 1)           one = true;         else           zer0 = true;       }       if (issorted)         cout <<  Yes               <<   n ;       else if (one && zer0)         cout <<  Yes               <<   n ;       else         cout <<  No               <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define ld long double   #define Test int T;cin>>T;while(T--)   #define PI acos(-1)   #define endl   n    #define fx(x) fixed<<setprecision(x)   #define sz(s) (int)s.size()   #define all(v) (v).begin(),(v).end()   #define allr(v) (v).rbegin(),(v).rend()   #define mem(a,n) memset((a),n,sizeof (a))   #define INF 1e9   #define ii pair<ll,ll>   ll gcd(ll x,ll y){return(!y?x:gcd(y,x%y));}   ll lcm(ll x,ll y){return x/gcd(x,y)*y;}   void file(){   #ifndef ONLINE_JUDGE       freopen( in.txt ,  r , stdin);       freopen( out.txt ,  w , stdout);   #else       //freopen( bridges.in ,  r , stdin);       //freopen( bridges.out ,  w , stdout);   #endif   }   void fast(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       file();   }   int dx[]= {-1,0,1,0};   int dy[]= {0,1,0,-1};   const double eps=1e-9;   const int mod=1e9+7;   const int N=1e5+5;   int a[N];   int ask(int i){       if(a[i])return a[i];       cout<< ?  <<i<<endl;       cout.flush();       int x;cin>>x;       return a[i]=x;   }   int main(){       fast();       int n;       cin>>n;       a[0]=a[n+1]=1e9;       int l=1,r=n;       while(l<=r){           int md=l+r>>1;           int xl=ask(md);           int xr=ask(md+1);           if(xl>=xr){               l=md+1;           }           else r=md-1;       }       cout<< !  <<l<<endl;       cout.flush();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int qnt, time, felicity, time_to_eat, best = -999999999;     cin >> qnt >> time;     for (int i = 0; i < qnt; i++) {       cin >> felicity >> time_to_eat;       if (time_to_eat <= time && felicity > best) {         best = felicity;       } else if (time_to_eat > time) {         int aux = felicity - (time_to_eat - time);         if (aux > best) {           best = felicity - (time_to_eat - time);         }       }     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   int va[100000], vb[100000];   int main() {     int na, nb, k, m, i, j;     scanf( %d%d%d%d , &na, &nb, &k, &m);     for (i = 0; i < na; i++) scanf( %d , &va[i]);     for (i = 0; i < nb; i++) scanf( %d , &vb[i]);     if (va[k - 1] < vb[nb - m])       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> erat;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long nd(long long a) {     map<long long, long long> m;     while (a != 1) {       ++m[erat[a]];       a /= erat[a];     }     long long count = 1;     for (auto e : m) count *= e.second + 1;     return count;   }   int main() {     vector<vector<vector<bool> > > count(         8, vector<vector<bool> >(8, vector<bool>(8, true)));     count[1][7][6] = false;     count[3][7][6] = false;     count[5][3][6] = false;     count[5][3][7] = false;     count[5][7][6] = false;     count[7][2][5] = false;     count[7][3][4] = false;     count[7][3][5] = false;     count[7][3][6] = false;     count[7][3][7] = false;     count[7][6][5] = false;     count[7][7][5] = false;     count[7][7][6] = false;     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     erat = vector<long long>(1e5 + 1, 1);     erat[0] = erat[1] = 1;     for (long long i = 2; i <= 1e5; ++i) {       if (erat[i] == 1) {         erat[i] = i;         for (long long j = i * i; j <= 1e5; j += i) {           if (erat[j] == 1) erat[j] = i;         }       }     }     long long t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long d = gcd(a, b);       long long e = gcd(a, c);       long long f = gcd(b, c);       long long g = gcd(d, c);       a = nd(a);       b = nd(b);       c = nd(c);       d = nd(d);       e = nd(e);       f = nd(f);       g = nd(g);       d -= g, e -= g, f -= g;       a -= d + e + g, b -= d + f + g, c -= e + f + g;       vector<long long> v(8);       v[1] = a, v[2] = b, v[3] = d, v[4] = c, v[5] = e, v[6] = f, v[7] = g;       long long total = 0;       for (int i = 0; i < 4; ++i) {         for (int j = 0; j < 4; ++j) {           for (int k = 0; k < 4; ++k) {             int l = 2 * i + 1;             int m = 2 + j;             if (j >= 2) m += 2;             int p = 4 + k;             if (count[l][m][p]) {               if (l == m) {                 if (m == p)                   total += v[l] * (v[m] + 1) * (v[p] + 2) / 6;                 else                   total += v[l] * (v[m] + 1) * v[p] / 2;               } else if (l == p or m == p)                 total += v[l] * v[m] * (v[p] + 1) / 2;               else                 total += v[l] * v[m] * v[p];             }           }         }       }       cout << total << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long x[maxn], y[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long s = 0, sx = 0, sy = 0;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       sx += x[i];       sy += y[i];       s += (n - 1) * (x[i] * x[i]) + (n - 1) * (y[i] * y[i]);     }     for (int i = 0; i < n; i++) {       s -= ((x[i] * (sx - x[i])) + (y[i] * (sy - y[i])));     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   long long max(long long a, long long b) { return a > b ? a : b; }   struct SegmentTree {    public:     SegmentTree() {       null_value = -INF;       null_modifier = 0;     }     void insert_data(vector<long long> values) {       size = 1;       while (size < values.size()) {         size *= 2;       }       modifier_tree.assign(size * 2 - 1, null_modifier);       tree.assign(size * 2 - 1, null_value);       for (int i = 0; i < values.size(); i++) {         tree[size + i - 1] = values[i];       }       for (int i = size - 2; i >= 0; i--) {         tree[i] = merge(tree[l_child(i)], tree[r_child(i)]);       }     }     void modify_segment(int begin, int end, long long modifier) {       modify_segment(begin, end, modifier, 0, 0, size);     }     long long get_segment(int begin, int end) {       return get_segment(begin, end, 0, 0, size);     }       protected:     vector<long long> tree;     vector<long long> modifier_tree;     int size;     long long null_value;     long long null_modifier;     long long merge(long long segment_1, long long segment_2) {       if (segment_1 != null_value && segment_2 != null_value) {         return max(segment_1, segment_2);       } else if (segment_1 != null_value) {         return segment_1;       } else {         return segment_2;       }     }     long long modify(long long segment, long long modifier) {       if (modifier != null_modifier) {         return segment + modifier;       } else {         return segment;       }     }     long long combine(long long new_modifier, long long old_modifier) {       if (new_modifier != null_modifier && old_modifier != null_modifier) {         return new_modifier + old_modifier;       } else if (new_modifier != null_modifier) {         return new_modifier;       } else {         return old_modifier;       }     }     void add_modifier(int inode, long long modifier) {       if (modifier != null_modifier) {         modifier_tree[inode] = combine(modifier, modifier_tree[inode]);         tree[inode] = modify(tree[inode], modifier);       }     }     int l_child(int inode) { return inode * 2 + 1; }     int r_child(int inode) { return inode * 2 + 2; }     void push(int inode) {       if (modifier_tree[inode] != null_modifier) {         add_modifier(l_child(inode), modifier_tree[inode]);         add_modifier(r_child(inode), modifier_tree[inode]);         modifier_tree[inode] = null_modifier;       }     }     void modify_segment(int begin, int end, long long modifier, int inode,                         int lnode, int rnode) {       if (lnode < rnode) {         if (lnode >= begin && rnode <= end) {           add_modifier(inode, modifier);         } else if (lnode >= end || rnode <= begin) {           return;         } else {           push(inode);           int mnode = (lnode + rnode) / 2;           modify_segment(begin, end, modifier, l_child(inode), lnode, mnode);           modify_segment(begin, end, modifier, r_child(inode), mnode, rnode);           tree[inode] = merge(tree[l_child(inode)], tree[r_child(inode)]);         }       }     }     long long get_segment(int begin, int end, int inode, int lnode, int rnode) {       if (lnode >= begin && rnode <= end) {         return tree[inode];       } else if (lnode >= end || rnode <= begin) {         return null_value;       } else {         push(inode);         int mnode = (lnode + rnode) / 2;         long long l_segment =             get_segment(begin, end, l_child(inode), lnode, mnode);         long long r_segment =             get_segment(begin, end, r_child(inode), mnode, rnode);         return merge(l_segment, r_segment);       }     }   };   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int n, m, p;     cin >> n >> m >> p;     vector<pair<long long, long long>> atk(n), def(m);     vector<pair<long long, pair<long long, long long>>> mon(p);     for (int i = 0; i < n; i++) {       cin >> atk[i].first >> atk[i].second;     }     for (int i = 0; i < m; i++) {       cin >> def[i].first >> def[i].second;     }     for (int i = 0; i < p; i++) {       cin >> mon[i].first >> mon[i].second.first >> mon[i].second.second;     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(mon.begin(), mon.end());     vector<long long> b(m), cb(m);     for (int i = 0; i < m; i++) {       b[i] = def[i].first;       cb[i] = -def[i].second;     }     SegmentTree tree;     tree.insert_data(cb);     int imon = 0;     long long ans = -INF;     for (int i = 0; i < n; i++) {       while (imon < p && mon[imon].first < atk[i].first) {         int rb =             upper_bound(b.begin(), b.end(), mon[imon].second.first) - b.begin();         tree.modify_segment(rb, m, mon[imon].second.second);         imon++;       }       ans = max(ans, tree.get_segment(0, m) - atk[i].second);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define int               long long   #define ld                long double   #define ll                unsigned int   #define endl                n       #define mp                make_pair   #define hcf               __gcd   #define test              cout<< hello ;   #define lcm(m,n)          m*(n/__gcd(m,n))   #define maxa(v)           *(max_element(all(v))   #define mina(v)           *(min_element(all(v))      #define pb                push_back   #define ppb               pop_back   #define pf                push_front   #define ppf               pop_front   #define ff                first    #define ss                second   #define doge              cout<< *       #define mod               (int)1e9   #define all(x)            (x).begin(),(x).end()   #define uniq(v)           (v).erase(unique(all(v)),(v).end())   #define sz(x)             (int)((x).size())   #define asort(v)          sort(v.begin(),v.end())   #define dsort(v)          sort(v.begin(),v.end(),greater<int>())   #define present(c,e)      (c.find(e) != c.end())   #define vfind(c,e)     (find(all(c),e) != c.end())   #define tr(c,it)          for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)            //////////////////////////////////////////////////////////////////////////////////////////////////////////                 bool isPrime(ll n)        {            if (n <= 1) return false;            if (n <= 3) return true;                    if (n%2 == 0 || n%3 == 0) return false;                    for (ll i=5; i*i<=n; i=i+6)                if (n%i == 0 || n%(i+2) == 0)                return false;                    return true;        }                        long long power(int n,int k)       {           if(k==0)    return 1;           else return (n*power(n,k-1)%1000000007);       }               long long nCr(int n,int r)       {           if(n==r)    return 1;           else if (r==0)  return 1;           else return ((nCr(n-1,r-1)+nCr(n-1,r))%998244353);       }          long long sumDigit(ll x)       {           ll ans=0;           while(x)           {               ans+=x%10;               x/=10;           }           return ans;vector<int> v;       }              int bs(int a[],int b,int l,int r)       {           int mid=(l+r)/2;           if(l>r) return (int)-1;           if(a[mid]==b||l==r) return mid;           if(a[mid]>b)    return bs(a,b,l,mid-1);           else return bs(a,b,mid+1,r);       }          int divideandconquerbc(int a[],int l,int r)       {           if(l>=r)    return 0;           int mid=(l+r)/2,ans=0;           ans+=divideandconquerbc(a,l,mid);           ans+=divideandconquerbc(a,mid+1,r);           int x=r-l+1,y=mid-l+1;           int c[x];           int i=0,j=0;           for(int k=0;k<x;k++)           {               if((a[l+i]<=a[mid+1+j]&&i<y)||j>=x-y)   {c[k]=a[l+i];i++;}               else {c[k]=a[mid+1+j];j++;ans+=y-i;}           }           for(int k=l;k<=r;k++)               a[k]=c[k-l];           return ans;       }          long long  gcd(ll a,ll b)       {           if (b==0) return a;           return gcd(b,a%b);       }                  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////      // count sum count1, cnt,cnt1 sum1 carry tip mx mn a1 a2 a3    // may the force be with us         void solve(){       int n,q;       cin>>n>>q;       set<int>s;       map<int,int>m;       for (int i = 0; i < n; ++i)       {           int x;           cin>>x;           if(!present(s,x)){               m[x]=i+1;               s.insert(x);           }       }       for (int i = 0; i < q; ++i)       {           int z;           cin>>z;           cout<<m[z]<<   ;           for(auto i:m){               if(i.ss<m[z]){                   m[i.ff]++;               }           }           m[z]=1;       }                                   cout<<endl;}   signed main(){          ios_base::sync_with_stdio(false);       cin.tie(0);cout.tie(0);       #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif          int tsc=1;      // cin>>tsc;       while(tsc--) solve();       return 0;          }


#include <bits/stdc++.h>   using uint = unsigned int;   using cat = long long;   using dbl = long double;   constexpr dbl pi = 3.14159265358979323846;   using namespace std;   template <typename T>   T abs(T x) {     return (x < 0) ? (-x) : x;   }   cat pw(cat a, cat e, cat mod) {     if (e <= 0) return 1;     cat x = pw(a, e / 2, mod);     x = x * x % mod;     return (e & 1) ? x * a % mod : x;   }   struct fin {     vector<int> T;     fin(int N) { T.resize(N + 10, 0); }     int lastone(int x) { return x & (x ^ (x - 1)); }     void put(int pos, int val) {       for (int i = pos + 1; i < (int)T.size(); i += lastone(i)) T[i] += val;     }     int get(int pos) {       int ret = 0;       for (int i = pos + 1; i > 0; i -= lastone(i)) ret += T[i];       return ret;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     int N;     cat K;     cin >> N >> K;     K = 1LL * N * (N - 1) / 2 - K + 1;     vector<pair<cat, cat> > P(N);     for (int i = 0; i < N; i++) cin >> P[i].first >> P[i].second;     dbl ans_le = 0, ans_gt = 1e5;     while (ans_gt - ans_le > 1e-8) {       dbl R = (ans_le + ans_gt) / 2;       vector<pair<dbl, int> > events;       for (int i = 0; i < N; i++) {         dbl d = sqrt(P[i].first * P[i].first + P[i].second * P[i].second);         if (d < R + 1e-8) continue;         dbl ang_c = atan2(P[i].second, P[i].first);         if (ang_c < 0) ang_c = 2 * pi + ang_c;         dbl ang_d = acos(R / d);         if (ang_c - ang_d < 1e-8) {           events.push_back({ang_c + ang_d, 2 * i});           events.push_back({ang_c - ang_d, 2 * i + 1});           events.push_back({ang_c - ang_d + 2 * pi, 2 * i + 1});         } else if (ang_c + ang_d > 2 * pi - 1e-8) {           events.push_back({ang_c + ang_d - 2 * pi, 2 * i});           events.push_back({ang_c - ang_d, 2 * i + 1});           events.push_back({ang_c - ang_d - 2 * pi, 2 * i + 1});         } else {           events.push_back({ang_c + ang_d, 2 * i});           events.push_back({ang_c - ang_d, 2 * i + 1});         }       }       sort(begin(events), end(events));       vector<int> last_open(N, -1);       cat cnt = 0;       fin F(events.size());       for (int i = 0; i < (int)events.size(); i++) {         int id = events[i].second / 2;         if (events[i].second % 2 == 0) {           if (last_open[id] != -1) {             F.put(events.size() - last_open[id], -1);             cnt += F.get(events.size() - last_open[id]);             last_open[id] = -1;           }         } else {           last_open[id] = i;           F.put(events.size() - i, 1);         }       }       if (cnt >= K)         ans_le = R;       else         ans_gt = R;     }     cout << ans_le <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   struct edg {     int u, v, l, r;     edg(int u = 0, int v = 0, int l = 0, int r = 0) : u(u), v(v), l(l), r(r) {}     bool operator<(const edg &n1) const { return l > n1.l; }   };   priority_queue<edg> q;   vector<edg> adj[maxn][2];   int n, m;   int dp[maxn][2];   inline void add(int u, int v, int l, int r) {     int op = l % 2;     if (dp[u][op] >= l) {       if (v == n) {         cout << l + 1 << endl;         exit(0);       }       if (r + 1 > dp[v][op ^ 1]) {         dp[v][op ^ 1] = r + 1;         for (int i = 0; i < adj[v][op ^ 1].size(); i++) {           edg t = adj[v][op ^ 1][i];           if (l + 1 <= t.r) q.push(edg(v, t.v, l + 1, t.r));         }         adj[v][op ^ 1].clear();       }     } else {       adj[u][op].push_back(edg(u, v, l, r));     }   }   int main() {     cin >> n >> m;     memset(dp, 0xf3, sizeof(dp));     dp[1][0] = 0;     for (int i = 1; i <= m; i++) {       int u, v, l, r;       scanf( %d%d%d%d , &u, &v, &l, &r);       if ((r - l + 1) % 2 == 0) {         q.push(edg(u, v, l, r - 1));         q.push(edg(v, u, l, r - 1));         if (l + 1 <= r - 2) {           q.push(edg(u, v, l + 1, r - 2));           q.push(edg(v, u, l + 1, r - 2));         }       } else {         if (l <= r - 2) {           q.push(edg(u, v, l, r - 2));           q.push(edg(v, u, l, r - 2));         }         q.push(edg(u, v, l + 1, r - 1));         q.push(edg(v, u, l + 1, r - 1));       }     }     if (n == 1) {       cout <<  0  << endl;       return 0;     }     while (!q.empty()) {       edg t = q.top();       q.pop();       add(t.u, t.v, t.l, t.r);     }     cout <<  -1  << endl;     return 0;   }