#include <bits/stdc++.h>   using namespace std;   long long int n, I;   vector<long long int> vec;   vector<long long int> comp;   long long int K;   int main() {     scanf( %lld %lld , &n, &I);     for (int i = 1; i <= n; i++) {       long long int a;       scanf( %lld , &a);       vec.push_back(a);     }     K = 1 << min((long long int)20, 8 * I / n);     sort(vec.begin(), vec.end());     long long int pre = -1;     for (int i = 1; i <= n; i++) {       if (vec[i - 1] != pre) {         comp.push_back(i);         pre = vec[i - 1];       }     }     if (8 * I / n >= 20) {       printf( 0 );       return 0;     }     int ans = 1000000000;     for (int i = 0; i < comp.size(); ++i) {       int num = comp[i] - 1 + (i + K < comp.size() ? n + 1 - comp[i + K] : 0);       ans = min(num, ans);     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const double eps = 1e-15;   const long long INF = (1LL << 60);   int cnt[1010];   int a[1010];   int M[1010];   int m;   int dp[1010][1010][2];   int main() {     int n, m, x;     scanf( %d%d , &n, &m);     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       x %= m;       ++cnt[x];     }     if (n > m) {       printf( YES n );       return 0;     }     dp[0][0][0] = 1;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         if (dp[i][j][0]) {           dp[i + 1][j][0] = 1;         }         if (dp[i][j][1]) {           dp[i + 1][j][1] = 1;         }         for (int k = 1; k <= cnt[i]; ++k) {           if (dp[i][j][0] || dp[i][j][1]) {             dp[i + 1][(j + k * i) % m][1] = 1;           }         }       }     }     bool flag = dp[m][0][1];     puts(flag ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   const int N = 200005;   const int M = 1000000007;   long long ast(long long x, long long n) {     x %= M;     long long ans = 1;     while (n) {       if (n % 2 == 1) ans = (ans * x) % M;       x = (x * x) % M;       n /= 2;     }     return ans;   }   int n;   long long a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]);     long long u = 2;     long long k = 1;     for (int i = 1; i <= n; ++i) {       u = ast(u, a[i]);       if (a[i] % 2 == 0) k = 0;     }     u = (u * ast(2, M - 2)) % M;     long long x;     if (k == 0)       x = ((u + 1) * ast(3, M - 2)) % M;     else       x = ((u - 1 + M) % M * ast(3, M - 2)) % M;     printf( %lld/%lld n , x, u);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, st[350005], dr[350005], grad[350005], bad[350005], l, order[350005],       len;   bool used[350005], stare[350005];   vector<int> L[350005];   vector<int>::iterator it[350005];   inline void add_edge(int x, int y) {     ++m;     L[x].push_back(m);     L[y].push_back(m);     st[m] = x;     dr[m] = y;   }   inline void Dfs(int nod) {     while (it[nod] != L[nod].end()) {       if (used[*it[nod]]) {         ++it[nod];         continue;       }       used[*it[nod]] = 1;       Dfs(st[*it[nod]] + dr[*it[nod]] - nod);     }     order[++len] = nod;   }   int main() {     int i, j, x, y;     cin >> n >> m;     for (i = 1; i <= m; ++i) {       cin >> st[i] >> dr[i];       L[st[i]].push_back(i);       L[dr[i]].push_back(i);       ++grad[st[i]];       ++grad[dr[i]];     }     for (i = 1; i <= n; ++i)       if (grad[i] & 1) bad[++l] = i;     for (i = 1; i < l; i += 2) add_edge(bad[i], bad[i + 1]);     if (m & 1) add_edge(1, 1);     for (i = 1; i <= n; ++i) it[i] = L[i].begin();     Dfs(1);     cout << m <<   n ;     for (i = 1; i < len; ++i) {       x = order[i];       y = order[i + 1];       if (!stare[x]) {         cout << y <<     << x <<   n ;         stare[y] = 1;       } else {         cout << x <<     << y <<   n ;         stare[y] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int R, C;     cin >> R >> C;     char m[R][C];     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++) cin >> m[i][j];     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++) {         if (m[i][j] ==  S ) {           if (i > 0)             if (m[i - 1][j] ==  W ) {               cout <<  No n ;               return 0;             }           if (i < R - 1)             if (m[i + 1][j] ==  W ) {               cout <<  No n ;               return 0;             }           if (j > 0)             if (m[i][j - 1] ==  W ) {               cout <<  No n ;               return 0;             }           if (j < C - 1)             if (m[i][j + 1] ==  W ) {               cout <<  No n ;               return 0;             }         }       }     cout <<  Yes n ;     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++)         if (m[i][j] ==  . ) m[i][j] =  D ;     for (int i = 0; i < R; i++) {       for (int j = 0; j < C; j++) {         cout << m[i][j];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long arr[200002], time_freq[101];   void solve() {     long long total_time = 0;     for (long long i = 0; i < n; i++) {       long long exam_start_time = total_time + arr[i] - m;       int student_removed = 0;       if (exam_start_time > 0) {         for (int j = 100; j > 0; j--) {           long long y = time_freq[j] * j;           if (exam_start_time <= y) {             student_removed += ((exam_start_time + j - 1) / j);             break;           }           exam_start_time -= (time_freq[j] * j);           student_removed += time_freq[j];         }       }       total_time += arr[i];       time_freq[arr[i]]++;       cout << student_removed <<    ;     }     cout << endl;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> arr[i];     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   map<int, int> mp;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, k, tmp = 1, mx = 0;     cin >> n >> k;     while (tmp <= k + 1) {       int pos, x;       cout <<  ?  <<    ;       for (int i = 1; i <= k + 1; i++) {         if (i != tmp) cout << i <<    ;       }       cout << endl;       cout.flush();       tmp++;       cin >> pos >> x;       mp[x]++;       mx = max(mx, x);     }     cout <<  !  <<     << mp[mx] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k[3];     while (cin >> k[0] >> k[1] >> k[2]) {       bool flag = false;       int one = 0, two = 0, three = 0, four = 0;       for (int i = 0; i < 3; i++) {         if (k[i] == 1) one++;         if (k[i] == 2) two++;         if (k[i] == 3) three++;         if (k[i] == 4) four++;       }       if (one >= 1 || two >= 2 || three == 3 || two == 1 && four == 2)         flag = true;       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> tc[30];   bool dp[5][110][505];   int vis[5][110][505], n, k, Trow[30], kase, stx, sty;   char mp[5][110];   bool solve(int x, int y, int mv) {     if (x < 1 || x > 3 || y < 1) return 0;     if (y > n) return 1;     bool oc1 = 0, oc2 = 0, oc3 = 0;     if (vis[x][y][mv] == kase) return dp[x][y][mv];     for (int i = 1; i <= k; i++) {       if (x == Trow[i]) {         if (y >= (tc[i].first - mv * 2) && y <= (tc[i].second - mv * 2)) return 0;         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc1 = 1;       } else if (x - Trow[i] == 1) {         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc2 = 1;       } else if (Trow[i] - x == 1) {         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc3 = 1;       }     }     bool op1 = 0, op2 = 0, op3 = 0;     if (!oc1) op1 = solve(x, y + 1, mv + 1);     if (!oc1 && !oc2) op2 = solve(x - 1, y + 1, mv + 1);     if (!oc1 && !oc3) op3 = solve(x + 1, y + 1, mv + 1);     vis[x][y][mv] = kase;     return dp[x][y][mv] = (op1 || op2 || op3);   }   int main() {     int ks;     scanf( %d , &ks);     for (kase = 1; kase <= ks; kase++) {       scanf( %d %d , &n, &k);       for (int i = 1; i <= 3; i++) scanf( %s , &mp[i][1]);       int cnt = 1;       for (int i = 1; i <= 3; i++) {         for (int j = 1; j <= n; j++) {           if (mp[i][j] ==  s )             stx = i, sty = j;           else if (mp[i][j] !=  . ) {             char S = mp[i][j];             int kk = j;             while (kk <= n && mp[i][kk] == S) mp[i][kk] =  . , kk++;             Trow[cnt] = i;             tc[cnt].first = j;             tc[cnt].second = kk - 1;             cnt++;           }         }       }       printf( %s n , solve(stx, sty, 0) ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   #pragma GCC target( fma )   #pragma GCC optimize( unroll-loops,-Ofast )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long a[500005];   int n;   set<long long> buck[1000];   long long c[1000];   void fix(int v) {     int l = v * 700;     int r = (v + 1) * 700;     r = min(r, n);     buck[v].clear();     for (int i = l; i < r; ++i) {       a[i] += c[v];       buck[v].insert(a[i]);     }     c[v] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];       buck[i / 700].insert(a[i]);     }     while (q--) {       int t, l, r, x;       cin >> t;       if (t == 1) {         cin >> l >> r >> x;         --l;         --r;         if (l / 700 == r / 700) {           for (int i = l; i <= r; i++) a[i] += x;           fix(r / 700);           continue;         }         if (l % 700 != 0) {           for (; l % 700 != 0; ++l) {             a[l] += x;           }           fix(l / 700 - 1);         }         l /= 700;         if (r % 700 != 700 - 1) {           for (; r % 700 != 700 - 1; --r) {             a[r] += x;           }           fix(r / 700 + 1);         }         r /= 700;         for (; l <= r; l++) c[l] += x;       } else {         cin >> x;         l = r = -1;         for (int i = 0; i <= n / 700; ++i) {           if (buck[i].count(x - c[i])) {             for (int j = i * 700; 1; ++j) {               if (a[j] == x - c[i]) {                 l = j;                 break;               }             }             break;           }         }         for (int i = n / 700; i >= 0; --i) {           if (buck[i].count(x - c[i])) {             for (int j = i * 700 + 700 - 1; 1; --j) {               if (a[j] == x - c[i]) {                 r = j;                 break;               }             }             break;           }         }         if (l == -1) {           cout << -1 <<   n ;         } else {           cout << r - l <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   int main() {     int n, m, an[120], am[120], fa = -1, fb = -1, f = 0, a, b;     cin >> n >> m;     for (int i = 0; i < n + 1; i++) {       cin >> an[i];       if (f == 0 && an[i] != 0) {         f = 1;         fa = n - i;       }     }     f = 0;     for (int i = 0; i < m + 1; i++) {       cin >> am[i];       if (f == 0 && am[i] != 0) {         f = 1;         fb = m - i;       }     }     a = an[n - fa];     b = am[m - fb];     if (fa < 0 && fb < 0) {       cout <<  0/1  << endl;     }     if (fb == fa) {       f = gcd(a, b);       a /= f;       b /= f;       if (b < 0) {         b = abs(b);         a *= -1;       }       cout << a <<  /  << b << endl;     }     if (fa > fb) {       if (a * b > 0)         cout <<  Infinity  << endl;       else         cout <<  -Infinity  << endl;     } else if (fa < fb) {       cout <<  0/1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},                           {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   template <class T>   inline T abs1(T a) {     return a < 0 ? -a : a;   }   const int maxn = 100110;   template <class t>   struct segment_node {     int be, en;     t num, add;   };   template <class t>   struct segment_tree {     int l;     segment_node<t> tree[maxn * 4];     inline int gleft(int no) { return no << 1; }     inline int gright(int no) { return (no << 1) + 1; }     inline int gfa(int no) { return no >> 1; }     inline segment_tree() { l = 0; }     void build(int no, int l, int r) {       if (l == r) {         tree[no].be = tree[no].en = l;         tree[no].num = -1;         tree[no].add = -1;         return;       }       tree[no].be = l;       tree[no].en = r;       int mid = (l + r) / 2;       build(gleft(no), l, mid);       build(gright(no), mid + 1, r);       tree[no].add = -1;     }     inline void relax(int no) {       tree[gleft(no)].add = tree[no].add;       tree[gright(no)].add = tree[no].add;       tree[no].add = -1;     }     void down(int l, int r, int no, t ranadd) {       if (tree[no].be != tree[no].en && tree[no].add != -1) relax(no);       if (l <= tree[no].be && r >= tree[no].en) {         tree[no].add = ranadd;         return;       }       int mid = (tree[no].be + tree[no].en) / 2;       if (r >= tree[no].be && l <= mid) down(l, r, gleft(no), ranadd);       if (r >= mid + 1 && l <= tree[no].en) down(l, r, gright(no), ranadd);     }     t getnum(int loc, int no) {       if (tree[no].add != -1) {         int ans = tree[no].add;         if (tree[no].be != tree[no].en) relax(no);         return ans;       }       if (tree[no].be == tree[no].en) return tree[no].num;       int mid = (tree[no].be + tree[no].en) / 2;       if (loc <= mid)         return getnum(loc, gleft(no));       else         return getnum(loc, gright(no));     }   };   segment_tree<int> sgt[4];   struct segment {     int from, to, no;     segment(int a = 0, int b = 0, int no1 = 0) {       from = min(a, b);       to = max(a, b);       no = no1;     }   };   vector<segment> orig[2][maxn];   pair<int, int> orig1[maxn * 2], origto[maxn];   long long origdir[maxn * 2], origstep[maxn];   struct vec {     int no, loc;     vec(int a = 0, int b = 0) : no(a), loc(b) {}   };   vector<vec> she[4][maxn];   map<pair<int, int>, int> trans;   long long narrow, b, nq;   struct node {     int fa, delta;     long long dis;     node(int a = 0, int b = 0, int c = 0) { fa = a, dis = b, delta = c; }   } fa[60][maxn * 2];   inline int finddir(pair<int, int> from, pair<int, int> to) {     to.first -= from.first;     to.second -= from.second;     if (to.first) to.first /= abs(to.first);     if (to.second) to.second /= abs(to.second);     for (int j = 0; j < 4; j++)       if (to.first == step[j][0] && to.second == step[j][1]) return j;     return 0;   }   inline long long cntdis(pair<int, int> co, pair<int, int> co1) {     return abs(co.first - co1.first) + abs(co.second - co1.second);   }   inline pair<long long, long long> finddis(int from, int dir, int to) {     pair<long long, long long> ans;     if (to == -1) {       ans = orig1[from];       if (dir > 1) swap(ans.first, ans.second);       if (!(dir & 1)) ans.first = b - ans.first;       ans.second = 0;       return ans;     }     if ((origdir[to] ^ dir) < 2) {       long long dis1 = orig1[from].first - orig1[to].first,                 dis2 = orig1[from].first - origto[to].first;       if (orig1[to].first == orig1[from].first &&           orig1[to].first == origto[to].first)         dis1 = orig1[from].second - orig1[to].second,         dis2 = orig1[from].second - origto[to].second;       if (dis1 * dis2 < 0) {         ans.first = 0;         ans.second = abs1(dis1);       } else {         ans.first = min(abs1(dis1), abs1(dis2));         ans.second = 0;         if (abs1(dis1) > abs1(dis2)) ans.second = abs1(dis1) - abs1(dis2);       }       return ans;     }     ans = orig1[to];     ans.first -= orig1[from].first;     ans.second -= orig1[from].second;     if (dir > 1) swap(ans.first, ans.second);     ans.first = abs1(ans.first);     ans.second = abs1(ans.second);     return ans;   }   int main() {     scanf( %I64d%I64d , &narrow, &b);     for (int i = 0; i < narrow; i++) {       pair<int, int> from, to;       scanf( %d%d%d%d , &from.first, &from.second, &to.first, &to.second);       trans[from] = i;       orig1[i] = from;       origto[i] = to;       if (from.first == to.first) {         orig[0][from.first].push_back(segment(from.second, to.second, i));         orig[1][max(from.second, to.second)].push_back(             segment(from.first, from.first, i));         orig[1][min(from.second, to.second)].push_back(             segment(from.first, from.first, i));       } else {         orig[1][from.second].push_back(segment(from.first, to.first, i));         orig[0][max(from.first, to.first)].push_back(             segment(from.second, from.second, i));         orig[0][min(from.first, to.first)].push_back(             segment(from.second, from.second, i));       }       int randir = finddir(from, to);       origdir[i] = randir;       if (randir > 1) swap(to.first, to.second);       she[randir][to.first].push_back(vec(i, to.second));     }     scanf( %I64d , &nq);     for (int i = 0; i < nq; i++) {       pair<int, int> st;       char randirc;       long long step1, randir;       scanf( %d %d %c %I64d , &st.first, &st.second, &randirc, &step1);       orig1[i + narrow] = st;       trans[st] = i + narrow;       if (randirc ==  L ) randir = 1;       if (randirc ==  R ) randir = 0;       if (randirc ==  U ) randir = 2;       if (randirc ==  D ) randir = 3;       origdir[i + narrow] = randir, origstep[i] = step1;       if (randir > 1) swap(st.first, st.second);       she[randir][st.first].push_back(vec(i + narrow, st.second));     }     for (int i = 0; i < 4; i++) {       sgt[i].build(1, 0, b + 1);       int from = 0, add = 1, to = b + 1;       if (!(i & 1)) from = b, add = -1, to = -1;       int biao = i / 2;       for (int j = from; j != to; j += add) {         for (int t = 0; t < (int)she[i][j].size(); t++)           if (she[i][j][t].no < narrow) {             fa[0][she[i][j][t].no].fa = sgt[i].getnum(she[i][j][t].loc, 1);             pair<long long, long long> randis =                 finddis(she[i][j][t].no, i, fa[0][she[i][j][t].no].fa);             fa[0][she[i][j][t].no].dis = randis.first;             fa[0][she[i][j][t].no].delta = randis.second;           }         for (int t = 0; t < (int)orig[biao][j].size(); t++)           sgt[i].down(orig[biao][j][t].from, orig[biao][j][t].to, 1,                       orig[biao][j][t].no);         for (int t = 0; t < (int)she[i][j].size(); t++)           if (she[i][j][t].no >= narrow) {             fa[0][she[i][j][t].no].fa = sgt[i].getnum(she[i][j][t].loc, 1);             pair<long long, long long> randis =                 finddis(she[i][j][t].no, i, fa[0][she[i][j][t].no].fa);             fa[0][she[i][j][t].no].dis = randis.first;             fa[0][she[i][j][t].no].delta = randis.second;           }       }     }     for (int i = 1; i < 60; i++) {       for (int j = 0; j < narrow + nq; j++) {         if (fa[i - 1][j].fa != -1) {           fa[i][j].fa = fa[i - 1][fa[i - 1][j].fa].fa;           fa[i][j].delta = fa[i - 1][fa[i - 1][j].fa].delta;           fa[i][j].dis = fa[i - 1][fa[i - 1][j].fa].dis + fa[i - 1][j].dis -                          fa[i - 1][j].delta;         } else           fa[i][j] = fa[i - 1][j];         if (fa[i][j].dis > 1000000000000000ll) fa[i][j].dis = 1000000000000001ll;       }     }     for (long long i1 = 0; i1 < nq; i1++) {       long long no = i1 + narrow;       int en = 59;       for (; en != -1;) {         int ranbe = -1, ranen = en;         while (ranbe < ranen) {           int mid = (ranbe + ranen + 1) / 2;           if (fa[mid][no].dis > origstep[i1] || fa[mid][no].fa == -1)             ranen = mid - 1;           else             ranbe = mid;         }         en = ranbe;         if (en == -1) break;         origstep[i1] -= fa[ranbe][no].dis - fa[ranbe][no].delta;         no = fa[ranbe][no].fa;       }       printf(            %I64d %I64d n ,           max(0ll, min(b, orig1[no].first + origstep[i1] * step[origdir[no]][0])),           max(0ll,               min(b, orig1[no].second + origstep[i1] * step[origdir[no]][1])));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     n = (n * (n - 1)) / 2 + (((n * (n - 1)) / 2) * ((2 * n - 1))) / 3 - 2;     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100010];   int main() {     int val90, val1440, n;     cin >> n;     dp[0] = 0;     unsigned int ar[n + 10];     for (int i = 1; i <= n; i++) {       cin >> ar[i];     }     val1440 = val90 = 1;     for (int i = 1; i <= n; i++) {       while (ar[i] - ar[val1440] >= 1440) {         val1440++;       }       while (ar[i] - ar[val90] >= 90) {         val90++;       }       dp[i] = min(dp[i - 1] + 20, dp[val90 - 1] + 50);       dp[i] = min(dp[i], dp[val1440 - 1] + 120);       int ans = dp[i] - dp[i - 1];       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int maxlog = 24;   int par[maxn][maxlog], h[maxn];   int siz[maxn];   bool mark[maxn];   int n;   vector<int> adj[maxn];   void dfs(int x) {     mark[x] = 1;     for (int i = 0; i < adj[x].size(); i++) {       int child = adj[x][i];       if (!mark[child]) {         par[child][0] = x;         h[child] = h[x] + 1;         dfs(child);         siz[x] += siz[child] + 1;       }     }   }   int LCAH(int fi, int se) {     for (int i = maxlog - 1; i >= 0; i--)       if (par[fi][i] != par[se][i]) {         fi = par[fi][i];         se = par[se][i];       }     return n - siz[fi] - siz[se] - 2;   }   int LCA(int fi, int se) {     for (int i = maxlog - 1; i >= 0; i--)       if (h[par[fi][i]] >= h[se]) fi = par[fi][i];     if (fi == se) return fi;     for (int i = maxlog - 1; i >= 0; i--)       if (par[fi][i] != par[se][i]) {         fi = par[fi][i];         se = par[se][i];       }     return par[fi][0];   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int fi, se;       cin >> fi >> se;       adj[fi].push_back(se);       adj[se].push_back(fi);     }     dfs(1);     for (int j = 1; j < maxlog; j++)       for (int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1];     int q;     cin >> q;     while (q--) {       int fi, se;       cin >> fi >> se;       if (h[fi] < h[se]) swap(fi, se);       int dis = h[fi] + h[se] - 2 * h[LCA(fi, se)];       if (fi == se)         cout << n << endl;       else if (dis % 2 == 1)         cout << 0 << endl;       else if (h[fi] == h[se]) {         cout << LCAH(fi, se) << endl;       } else {         dis /= 2;         se = fi;         for (int i = maxlog - 1; i >= 0; i--) {           if ((1 << i) & dis) {             fi = par[fi][i];           }         }         int k = dis - 1;         for (int i = maxlog - 1; i >= 0; i--) {           if ((1 << i) & k) {             se = par[se][i];           }         }         cout << siz[fi] - siz[se] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ALPHABETS = 30;   const int maxN = 410;   bitset<maxN> orig[ALPHABETS][maxN], ans[maxN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N, M;     cin >> N >> M;     string s;     for (int i = 0; i < N; i++) {       cin >> s;       for (int j = 0; j < M; j++) {         orig[s[j] -  a ][i][j] = true;         ans[i][j] = true;       }     }     int R, C;     cin >> R >> C;     for (int i = 0; i < R; i++) {       cin >> s;       for (int j = 0; j < C; j++) {         if (s[j] ==  ? ) continue;         char ch = s[j] -  a ;         int goForward = j % M;         for (int k = 0; k < N; k++) {           int origR = (((k - i) % N) + N) % N;           ans[origR] &=               (orig[ch][k] >> goForward) | (orig[ch][k] << (M - goForward));         }       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (ans[i][j])           cout <<  1 ;         else           cout <<  0 ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     std::cin >> n;     int t, c;     int max = 0, cur = 0, lt = -1;     for (int i = 0; i < n; i++) {       std::cin >> t >> c;       if (lt != -1) {         cur += lt - t;       }       if (cur < 0) cur = 0;       cur += c;       if (cur > max) max = cur;       lt = t;     }     if (cur < c) cur = c;     std::cout << lt + cur <<     << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int N = 230;   const int M = 3500;   int m, n;   int a[N], b[N];   long long dp[M][N];   int main() {     cin >> m >> n;     memset(dp, 0, sizeof(dp));     for (int i = 0; i < m; ++i) {       cin >> a[i] >> b[i];       dp[a[i]][i]++;       if (a[i] != b[i]) {         a[i + m] = b[i];         b[i + m] = a[i];         dp[a[i + m]][i + m]++;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < m * 2; ++j) {         if (!dp[i][j]) continue;         for (int k = 0; k < 2 * m; ++k) {           if (j % m != k % m && a[k] == b[j])             dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % inf;         }       }     }     long long ans = 0;     for (int i = 0; i < 2 * m; ++i) ans = (ans + dp[n][i]) % inf;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   int main() {     int n = 0, u = 0, v = 0;     int d[MAXN] = {0};     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &u, &v);       d[u] += 1;       d[v] += 1;     }     for (int i = 1; i <= n; i++) {       if (d[i] == 2) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, n, c;   bool check(long long t) {     long long ans = 2 * t * t + 2 * t + 1;     if (x + t > n) {       long long m = x + t - n;       ans -= m * m;     }     if (y + t > n) {       long long m = y + t - n;       ans -= m * m;     }     if (x <= t) {       long long m = t - x + 1;       ans -= m * m;     }     if (y - t <= 0) {       long long m = t - y + 1;       ans -= m * m;     }     if (x - 1 + y - 1 < t) {       long long a = t - (x - 1 + y - 1) - 1;       ans += a * (a + 1) / 2;     }     if (x - 1 + n - y < t) {       long long a = t - (x - 1 + n - y) - 1;       ans += a * (a + 1) / 2;     }     if (n - x + y - 1 < t) {       long long a = t - (n - x + y - 1) - 1;       ans += a * (a + 1) / 2;     }     if (n - x + n - y < t) {       long long a = t - (n - x + n - y) - 1;       ans += a * (a + 1) / 2;     }     return ans >= c;   }   int main() {     while (cin >> n >> x >> y >> c) {       long long low = 0, high = 2 * n, mid, ans = 0;       while (low <= high) {         mid = (low + high) / 2;         if (check(mid)) {           ans = mid;           high = mid - 1;         } else           low = mid + 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void gk() {     ios_base::sync_with_stdio(0);     cin.tie(0);     std::cout.tie(0);   }   int64_t mul(int64_t a, int64_t b) { return (a * b) % (int64_t)1000000007; }   int64_t gcd(int64_t a, int64_t b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   const int64_t sz = 2502;   const int64_t sz2 = 2e6 + 5;   int64_t row[4] = {1, -1, 0, 0};   int64_t col[4] = {0, 0, -1, 1};   int64_t val[sz];   int64_t n;   void find() {     int64_t n;     cin >> n;     vector<int64_t> ar(n);     unordered_set<int64_t> ans;     unordered_set<int64_t> curr;     for (int64_t i = 0; i < n; i++) {       cin >> ar[i];     }     ans.insert(ar[0]);     curr.insert(ar[0]);     for (int64_t i = 1; i < n; i++) {       unordered_set<int64_t> aux;       for (int64_t j : curr) {         aux.insert(j | ar[i]);       }       aux.insert(ar[i]);       curr = aux;       for (int64_t i : curr) {         ans.insert(i);       }     }     cout << ans.size();   }   int32_t main() {     int64_t t = 1;     while (t--) {       find();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, edge;   pair<int, int> E[2][200002];   vector<int> V[2][200002];   int in[2][200002], out[2][200002];   bool S[2][200002], isdel[2][200002];   vector<pair<pair<int, int>, int> > ARBf[2][4 * 200002], ARBs[2][4 * 200002];   int Ap1, Ap2, Apv, Ax1, Ax2;   vector<int> auxst;   void updatef(int w, int nod, int i1, int i2) {     ARBf[w][nod].push_back(make_pair(make_pair(Ap1, Ap2), Apv));     if (i1 == i2) return;     int mid = (i1 + i2) / 2;     if (Ap1 <= mid)       updatef(w, nod * 2, i1, mid);     else       updatef(w, nod * 2 + 1, mid + 1, i2);   }   void erasef(int w, int nod, int i1, int i2) {     if (Ax1 <= i1 && i2 <= Ax2) {       while (!ARBf[w][nod].empty() && (ARBf[w][nod].back().first.second > Ax2 ||                                        isdel[w][ARBf[w][nod].back().second])) {         if (!isdel[w][ARBf[w][nod].back().second]) {           auxst.push_back(ARBf[w][nod].back().second);           isdel[w][ARBf[w][nod].back().second] = true;         }         ARBf[w][nod].pop_back();       }       return;     }     int mid = (i1 + i2) / 2;     if (Ax1 <= mid) erasef(w, nod * 2, i1, mid);     if (Ax2 > mid) erasef(w, nod * 2 + 1, mid + 1, i2);   }   void updates(int w, int nod, int i1, int i2) {     ARBs[w][nod].push_back(make_pair(make_pair(Ap1, Ap2), Apv));     if (i1 == i2) return;     int mid = (i1 + i2) / 2;     if (Ap2 <= mid)       updates(w, nod * 2, i1, mid);     else       updates(w, nod * 2 + 1, mid + 1, i2);   }   void erases(int w, int nod, int i1, int i2) {     if (Ax1 <= i1 && i2 <= Ax2) {       while (!ARBs[w][nod].empty() && (ARBs[w][nod].back().first.first < Ax1 ||                                        isdel[w][ARBs[w][nod].back().second])) {         if (!isdel[w][ARBs[w][nod].back().second]) {           auxst.push_back(ARBs[w][nod].back().second);           isdel[w][ARBs[w][nod].back().second] = true;         }         ARBs[w][nod].pop_back();       }       return;     }     int mid = (i1 + i2) / 2;     if (Ax1 <= mid) erases(w, nod * 2, i1, mid);     if (Ax2 > mid) erases(w, nod * 2 + 1, mid + 1, i2);   }   void Dfs(int w, int x) {     S[w][x] = true;     in[w][x] = ++in[w][0];     for (auto it = V[w][x].begin(); it != V[w][x].end(); ++it)       if (!S[w][*it]) Dfs(w, *it);     out[w][x] = in[w][0];   }   int main() {     cin.sync_with_stdio(false);     cin >> N;     for (int w = 0; w < 2; ++w)       for (int i = 2, nod; i <= N; ++i) {         cin >> nod;         V[w][i].push_back(nod);         V[w][nod].push_back(i);         E[w][i - 1] = make_pair(min(i, nod), max(i, nod));       }     cin >> edge;     for (int w = 0; w < 2; ++w) Dfs(w, 1);     for (int w = 0; w < 2; ++w) {       vector<pair<pair<int, int>, int> > aux;       for (int i = 1; i <= N - 1; ++i) {         if (w == 0 && i == edge) continue;         Ap1 = in[!w][E[w][i].first], Ap2 = in[!w][E[w][i].second], Apv = i;         if (Ap1 > Ap2) swap(Ap1, Ap2);         aux.push_back(make_pair(make_pair(Ap1, Ap2), Apv));       }       sort(aux.begin(), aux.end());       for (int i = int(aux.size()) - 1; i >= 0; --i) {         Ap1 = aux[i].first.first, Ap2 = aux[i].first.second, Apv = aux[i].second;         updates(w, 1, 1, N);         swap(aux[i].first.first, aux[i].first.second);       }       sort(aux.begin(), aux.end());       for (int i = 0; i < int(aux.size()); ++i) {         swap(aux[i].first.first, aux[i].first.second);         Ap1 = aux[i].first.first, Ap2 = aux[i].first.second, Apv = aux[i].second;         updatef(w, 1, 1, N);       }     }     vector<int> st;     st.push_back(edge);     for (int i = 0; !st.empty(); ++i) {       if (i & 1)         printf( Red n );       else         printf( Blue n );       int w = i % 2;       auxst.clear();       sort(st.begin(), st.end());       for (int j = 0; j < int(st.size()); ++j) {         int e = st[j];         printf( %d  , e);         if (in[w][E[w][e].first] < in[w][E[w][e].second]) {           Ax1 = in[w][E[w][e].second];           Ax2 = out[w][E[w][e].second];         } else {           Ax1 = in[w][E[w][e].first];           Ax2 = out[w][E[w][e].first];         }         erasef(!w, 1, 1, N);         erases(!w, 1, 1, N);       }       st = auxst;       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int cycl[N], set_val[N], cycl_size[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int h, m, n;     cin >> h >> m >> n;     vector<int> strt;     bool vis[h];     memset(vis, false, sizeof vis);     int kk = 0;     set<int> dmm[h + 1];     for (long long i = 0; i < m; i++) {       if (vis[i]) {         continue;       }       int ii = i;       int jp = 0;       while (1) {         if (vis[ii]) {           break;         }         set_val[ii] = jp;         cycl[ii] = kk;         dmm[kk].insert(jp);         vis[ii] = true;         ii += m;         ii %= h;         jp++;       }       cycl_size[kk] = jp;       kk++;     }     map<int, int> hash;     map<int, int> final;     long long cnt = 0;     while (n--) {       char ch;       cin >> ch;       if (ch ==  + ) {         int id, t;         cin >> id >> t;         hash[id] = t;         if (dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end()) {           final[id] = set_val[t];           dmm[cycl[t]].erase(set_val[t]);           continue;         }         set<int>::iterator it, it1;         it = dmm[cycl[t]].lower_bound(set_val[t]);         int xx1;         if (it == dmm[cycl[t]].end()) {           it = dmm[cycl[t]].begin();           xx1 = cycl_size[cycl[t]] + *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         } else {           xx1 = *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         }         cnt += (long long)xx1;       } else {         int id;         cin >> id;         dmm[cycl[hash[id]]].insert(final[id]);       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   int p[100005], q[100005], n, m, V;   double a[100005], x[100005], y[100005], dx[100005], dy[100005], h, vx, vy, t, w;   bool cmp1(const int i, const int j) { return a[i] < a[j]; }   bool cmp2(const int i, const int j) { return x[i] < x[j]; }   bool up(double t, double y) { return (h = vy * t - 9.8 * t * t / 2) > y; }   int main() {     scanf( %d%d , &n, &V);     for (int i = 0; i < n; i++) scanf( %lf , &a[i]), q[i] = i;     scanf( %d , &m);     for (int i = 0; i < m; i++) scanf( %lf %lf , &x[i], &y[i]), p[i] = i;     std::sort(q, q + n, cmp1);     std::sort(p, p + m, cmp2);     int j = 0;     for (int k = 0; k < n; k++) {       int i = q[k];       vx = V * cos(a[i]), vy = V * sin(a[i]), t = vy / 4.9, w = vx * t;       while (j < m && x[p[j]] < w && up(x[p[j]] / vx, y[p[j]])) j++;       if (j < m && x[p[j]] < w)         dx[i] = x[p[j]], dy[i] = h;       else         dx[i] = w;     }     for (int i = 0; i < n; i++) printf( %lf %lf n , dx[i], dy[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};   int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};   map<int, bool> ans;   map<long long, int> dp;   int rec(long long q) {     if (ans[q] == 1) return dp[q];     vector<int> v;     long long sq = sqrt(q);     int mex, x;     for (int l = 2; l < sq + 1; l++) {       if (!(q % l)) {         x = rec(l);         v.push_back(x);         x = rec(q / l);         v.push_back(x);       }     }     if (v.size() == 0)       mex = 1;     else {       sort(v.begin(), v.end());       (v).erase(unique((v).begin(), (v).end()), (v).end());       int len = v.size();       mex = 0;       for (int l = 0; l < len; l++) {         if (v[l] != mex) break;         mex++;       }     }     ans[q] = 1;     return dp[q] = mex;   }   bool chq(long long q) {     long long sq = sqrt(q);     for (int l = 2; l < sq + 1; l++) {       if (!(q % l)) return 0;     }     return 1;   }   long long go(long long q) {     long long sq = sqrt(q);     int x;     for (int l = 2; l < sq + 1; l++) {       if (!(q % l)) {         x = dp[l];         if (!x) return l;         x = dp[q / l];         if (!x) return q / l;       }     }   }   int main() {     int t, z = 0, len;     long long n, k = 0, m = 0;     scanf( %lld , &n);     bool prime = chq(n);     if (prime) {       printf( 1 n );       printf( 0 n );       return 0;     }     k = rec(n);     if (!k)       printf( 2 n );     else {       printf( 1 n );       m = go(n);       printf( %lld , m);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   char num[10][10];   int main() {     for (int i = 1; i < 9; i++) scanf( %s , num[i]);     bool yes = true;     for (int i = 1; i <= 8; i++) {       int cntb = 0, cntw = 0;       char pre =  * ;       for (int j = 0; j < 8; j++) {         if (num[i][j] == pre) {           yes = false;           break;         }         if (num[i][j] ==  W ) {           cntw++;           pre = num[i][j];         }         if (num[i][j] ==  B ) {           cntb++;           pre = num[i][j];         }       }       if (cntb != cntw) {         yes = false;       }     }     printf( %s n , yes ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct hero {     int power;     int nr;   };   int main() {     int n, m;     int board[100];     hero heroes[100];     vector<int> left, right;     cin >> n >> m;     for (int i = 0; i < n; ++i) heroes[i].nr = -1;     int l_ind = n;     int r_ind = -1;     for (int si, hi, i = 0; i < m; ++i) {       cin >> si >> hi;       heroes[si - 1].nr = i + 1;       heroes[si - 1].power = hi;       if (si - 1 < l_ind) l_ind = si - 1;       if (si - 1 > r_ind) r_ind = si - 1;     }     for (int i = 0; i < n; ++i) cin >> board[i];     int cur_pow = heroes[l_ind].power;     int cur_hero = heroes[l_ind].nr;     if (m == 1) {       cout << l_ind + 1 <<   n1  << endl;       return 0;     }     while (l_ind < n - 1 && l_ind + 1 < r_ind) {       if (board[l_ind + 1] >= 0) {         cur_pow += board[l_ind + 1];         if (heroes[l_ind + 1].nr != -1) {           if (heroes[l_ind + 1].power > cur_pow) {             left.push_back(cur_hero);             cur_hero = heroes[l_ind + 1].nr;             cur_pow = heroes[l_ind + 1].power;           } else {             left.push_back(heroes[l_ind + 1].nr);           }         }       } else {         if (cur_pow + board[l_ind + 1] >= 0)           cur_pow += board[l_ind + 1];         else {           break;         }       }       ++l_ind;     }     left.push_back(cur_hero);     cur_hero = heroes[r_ind].nr;     cur_pow = heroes[r_ind].power;     while (r_ind > 0 && l_ind < r_ind - 1) {       if (board[r_ind - 1] >= 0) {         cur_pow += board[r_ind - 1];         if (heroes[r_ind - 1].nr != -1) {           if (heroes[r_ind - 1].power > cur_pow) {             right.push_back(cur_hero);             cur_hero = heroes[r_ind - 1].nr;             cur_pow = heroes[r_ind - 1].power;           } else {             right.push_back(heroes[r_ind - 1].nr);           }         }       } else {         if (cur_pow + board[r_ind - 1] >= 0)           cur_pow += board[r_ind - 1];         else {           break;         }       }       --r_ind;     }     right.push_back(cur_hero);     if (abs(l_ind - r_ind) > 1)       cout <<  -1  << endl;     else {       cout << l_ind + 1 << endl;       for (auto it = left.end() - 1; it >= left.begin(); --it)         cout << (*it) <<    ;       for (auto it = right.end() - 1; it >= right.begin(); --it)         cout << (*it) <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   const int N = 1e6 + 5;   const long long MOD = 1000000007;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return (a.second < b.second);   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long power(long long n, long long k) {     if (k == 0) return 1;     long long sq = (power(n, k / 2));     sq = (sq * sq);     if (k % 2 == 1) sq = (sq * n);     return sq;   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   string to_binary(int x) {     string s;     while (x > 0) {       s += (x % 2 ?  1  :  0 );       x /= 2;     }     reverse(s.begin(), s.end());     return s;   }   bool isPerfect(long long x) {     if (x < 1) return false;     long long root(round(sqrt(x)));     return x == root * root * 1LL;   }   bool valid(int i, int j, int n, int m) {     return i >= 0 && i < n && j >= 0 && j < m;   }   long long FastPower(long long x, long long y) {     return (!y ? 1                : (((y & 1) ? x : 1) % MOD *                   FastPower((x % MOD) * (x % MOD) % MOD, y >> 1) % MOD) %                      MOD);   }   void solve() {     int n;     cin >> n;     vector<pair<int, int>> arr(n);     vector<int> ans;     long long all_sum = 0;     for (int i = 0; i < n; i++)       cin >> arr[i].first, arr[i].second = i, all_sum += arr[i].first;     sort((arr).begin(), (arr).end());     bool flg = true;     for (int i = 0; i < n - 1; i++) {       if ((all_sum - arr[i].first - arr[n - 1].first) == arr[n - 1].first)         ans.push_back(arr[i].second + 1), flg = false;     }     if ((all_sum - arr[n - 1].first - arr[n - 2].first) == arr[n - 2].first)       ans.push_back(arr[n - 1].second + 1), flg = false;     if (((int)((ans).size())) == 0) {       cout << ((int)((ans).size())) <<   n ;     } else {       cout << ((int)((ans).size())) <<   n ;       for (int i = 0; i < ((int)((ans).size())) - 1; i++) cout << ans[i] <<    ;       cout << ans[((int)((ans).size())) - 1] <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   ifstream in( input.txt );   ofstream out( output.txt );   int main() {     vector<int> a;     int n, x;     cin >> n >> x;     a.resize(100001);     vector<int> b;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a[t]++;       b.push_back(t);     }     unsigned long long ans = 0;     for (int i = 0; i < n; i++) {       if ((b[i] ^ x) == b[i]) {         ans += (a[b[i]] - 1);       } else if ((b[i] ^ x) < 100001) {         ans += a[b[i] ^ x];       }       a[b[i]]--;     }     cout << ans;   }


#include <bits/stdc++.h>   #define ll long long   #define nl   n    #define vpn 1000000   using namespace std;   ll t,n,dismin;   ll a[vpn],b[vpn];   ll gcd(ll x, ll y)   {       if (y==0) return x;       return gcd(y,x%y);   }   int main()   {       ios::sync_with_stdio(0);       cin.tie(0);       cin>>t;       while (t--)       {           cin>>n;           for(ll i=1;i<=n;i++)               cin>>a[i];           sort(a+1,a+n+1);           if (a[1]<0) cout<< NO <<nl;           else           {               if (a[n]<=300)               {                   cout<< YES <<nl;                   if (a[1]!=0)                   {                       cout<<a[n]<<nl;                   for (ll i=1;i<=a[n];i++)                       cout<<i<<   ;                   }                   else                   {                       cout<<a[n]+1<<nl;                       for (ll i=0;i<=a[n];i++)                           cout<<i<<   ;                   }                   cout<<nl;               }               else               {                   bool ans=true;                   vector<ll> dis;                   for (ll i=2;i<=n;i++)                       dis.push_back(a[i]-a[i-1]);                   ll pos;                   pos=dis[0];                   for (ll i=1;i<dis.size();i++)                   {                       pos=gcd(pos,dis[i]);                       if (pos==1)                       {                           cout<< NO <<nl;                           ans=false;                           break;                       }                   }                   if (ans==true)                   {                       if (((a[n]-pos)/pos+1)>300) cout<< NO <<nl;                       else                       {                           cout<< YES <<nl;                           if (a[1]==0)                           {                               cout<<((a[n]-pos)/pos+2)<<nl;                               cout<<a[1]<<   ;                           }                           else cout<<((a[n]-pos)/pos+1)<<nl;                           for (ll i=pos;i<=a[n];i+=pos)                               cout<<i<<   ;                           cout<<nl;                       }                   }               }           }       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long t = 0, i, j, n;     long long arr[100002];     cin >> n;     for (i = 0; i < n; ++i) {       cin >> arr[i];       t += arr[i];     }     if (t % (n - 1) == 0) {       j = t / (n - 1);     } else {       j = t / (n - 1) + 1;     }     long long mx = *max_element(arr, arr + n);     cout << max(mx, j);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<ll, ll>;   inline int get_state(ll s, int x) { return ((s >> (5 * x)) & 0x1f); }   inline ll set_state(ll s, ll v, int x) {     return ((s & ~(0x1fLL << (5 * x))) | (v << (5 * x)));   }   int cs[10];   map<ll, int> st;   map<ll, ii> ps;   bool kill_all(ll s, int n, int a, int b) {     for (int i = 2; i <= n - 1; ++i)       if (cs[i] >           b * get_state(s, i - 1) + a * get_state(s, i) + b * get_state(s, i + 1))         return false;     return true;   }   bool all_dead(ll s, int pos, int a, int b) {     for (int i = pos - 1; i <= pos + 1; ++i) {       if (cs[i] >           b * get_state(s, i - 1) + a * get_state(s, i) + b * get_state(s, i + 1))         return false;     }     return true;   }   int dp(ll s, int n, int a, int b) {     if (s == 0) return 0;     auto it = st.find(s);     if (it != st.end()) {       return it->second;     }     auto res = 1000000000;     for (int i = 2; i <= n - 1; ++i) {       if (get_state(s, i - 1) or get_state(s, i) or get_state(s, i + 1)) {         auto r = set_state(s, max(get_state(s, i) - a, 0), i);         r = set_state(r, max(get_state(r, i - 1) - b, 0), i - 1);         r = set_state(r, max(get_state(r, i + 1) - b, 0), i + 1);         auto value = dp(r, n, a, b) + 1;         if (value < res) {           res = value;           ps[s] = ii(r, i);         }       }     }     st[s] = res;     return res;   }   vector<int> solve(int n, int a, int b) {     vector<int> shoots;     ll s = 0;     for (int i = 1; i <= n; ++i) s = set_state(s, cs[i], i);     while (cs[1] > 0) {       shoots.push_back(2);       cs[1] -= b;       cs[2] -= a;       cs[3] -= b;       s = set_state(s, max(get_state(s, 1) - b, 0), 1);       s = set_state(s, max(get_state(s, 2) - a, 0), 2);       s = set_state(s, max(get_state(s, 3) - b, 0), 3);     }     while (cs[n] > 0) {       shoots.push_back(n - 1);       cs[n] -= b;       cs[n - 1] -= a;       cs[n - 2] -= b;       s = set_state(s, max(get_state(s, n - 2) - b, 0), n - 2);       s = set_state(s, max(get_state(s, n - 1) - a, 0), n - 1);       s = set_state(s, max(get_state(s, n) - b, 0), n);     }     dp(s, n, a, b);     auto it = ps.find(s);     while (it != ps.end()) {       s = it->second.first;       shoots.push_back(it->second.second);       it = ps.find(s);     }     for (int i = 2; i <= n - 1; ++i)       for (int j = 0; j < get_state(s, i); ++j) shoots.push_back(i);     return shoots;   }   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int i = 1; i <= n; ++i) {       cin >> cs[i];       ++cs[i];     }     auto shoots = solve(n, a, b);     cout << shoots.size() << endl;     for (size_t i = 0; i < shoots.size(); ++i)       printf( %d%c , shoots[i],    n [i + 1 == shoots.size()]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init() {}   const int N = 63e5 + 34;   const long long INF = 2e9 + 34;   int MD = 30;   string sym =  AHIMOTUVWXYovwx ;   void fail() {     cout <<  NIE ;     exit(0);   }   int main() {     init();     string s;     cin >> s;     int n = s.length();     if (n % 2 && sym.find(s[n / 2]) > 3000) fail();     for (int i = 0; i < n / 2; i++) {       if (sym.find(s[i]) < 3000 && sym.find(s[n - i - 1]) < 300 &&           s[i] == s[n - i - 1])         continue;       if (s[i] ==  b  && s[n - i - 1] ==  d ) continue;       if (s[i] ==  d  && s[n - i - 1] ==  b ) continue;       if (s[i] ==  p  && s[n - i - 1] ==  q ) continue;       if (s[i] ==  q  && s[n - i - 1] ==  p ) continue;       fail();     }     cout <<  TAK ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 5;   const int MOD = 1000000000 + 7;   int n, k;   int a[maxn], e[maxn], s[maxn], t[maxn];   inline void mm(int a[], int b[]) {     for (int i = 0; i < n; i++) {       t[i] = 0;       for (int j = 0; j <= i; j++)         t[i] = ((long long)a[j] * b[i - j] + t[i]) % MOD;     }     for (int i = 0; i < n; i++) a[i] = t[i];   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       e[i] = 1;     }     s[0] = 1;     while (k) {       if (k & 1) mm(s, e);       mm(e, e);       k >>= 1;     }     mm(a, s);     for (int i = 0; i < n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   int cs1[N];   int cs2[N];   int ss1[N];   int ss2[N];   int sum(int i, int cs[]) {     int s = 0;     while (i > 0) {       s += cs[i];       i -= i & -i;     }     return s;   }   void add(int i, int k, int cs[]) {     while (i < N) {       cs[i] += k;       i += i & -i;     }   }   int main() {     int n, k, a, b, q;     cin >> n >> k >> a >> b >> q;     for (int i = 0; i < q; ++i) {       int c;       scanf( %d , &c);       if (c == 1) {         int d, aa;         scanf( %d%d , &d, &aa);         add(d, min(aa, b - ss1[d]), cs1);         add(d, min(aa, a - ss2[d]), cs2);         ss1[d] = min(ss1[d] + aa, b);         ss2[d] = min(ss2[d] + aa, a);       } else {         int p;         scanf( %d , &p);         int o = sum(n, cs2) - sum(p + k - 1, cs2) + sum(p - 1, cs1);         printf( %d n , o);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0, a, b, a2, b2;     cin >> a >> b;     while (((a != 0) and (b != 0))) {       if ((a + b) <= 2) {         cout << ans << endl;         return 0;       }       if (2 * a <= b) {         cout << ans + a << endl;         return 0;       }       if (2 * b <= a) {         cout << ans + b << endl;         return 0;       }       if (a == 2 and b == 2) {         cout << ans + 1 << endl;         return 0;       }       int aux = a;       int aux2 = b;       a = min(aux, aux2);       b = max(aux, aux2);       while (a < b) {         a--;         b -= 2;         ans++;       }       aux = a / 3;       a = a - aux * 3;       b = b - aux * 3;       aux = aux * 2;       ans += aux;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>      #define modulus 1000000007      //for loops   //-------------------   #define for0(i, N) for (i = 0; i < (int) N; i++)   #define for1(i, N) for (i = 1; i <= (int) N; i++)   #define forr0(i, N) for (i = (int) N - 1; ~i; i--)   #define forr1(i, N) for (i = (int) N; i; i--)   #define foru(i, l, r, x) for (i = l; i <= r; i += x)   //to declare a for loop,   //first declare the primitive on a separate line   //   // int i;   // for0(i, N){   //      code   // }         //primitives & string   //-------------------   using ll = long long;   using str = std::string;         //pairs   //-----   using ii = std::pair<int, int>;   using llll = std::pair<ll, ll>;   #define mp make_pair   #define fi first   #define se second      using mii = std::map<int, int>;   using mllll = std::map<ll, ll>;         //vectors   //-------------   #define pb push_back   using vi = std::vector<int>;   using vvi = std::vector<vi>;   using vii = std::vector<ii>;   using vll = std::vector<ll>;   using vvll = std::vector<vll>;   using vb = std::vector<bool>;         //those grid problems (thanks BenCh)   //----------------------------------   const int dx[] = {1, 0, -1, 0},  dy[] = {0, 1, 0, -1};         //division rounded up and rounded down   //--------   ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }   ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }         using namespace std;      //ACTUAL CODE   //------------------------------------------------------------------------------------------------   //                                                                                |   //                                                                                |               void solve(){          int N; cin >> N;       vector<pair<int, int>> coords;       char arr[N][N];       for (int i = 0; i < N; i++) {           for (int j = 0; j < N; j++) {               cin >> arr[i][j];               if (arr[i][j] ==  * ) {                   coords.pb({i, j});               }           }       }          if (coords[0].first == coords[1].first) {           if (coords[1].first == N - 1) {               arr[N - 2][coords[1].second] =  * ;               arr[N - 2][coords[0].second] =  * ;           }           else {               arr[coords[1].first + 1][coords[1].second] =  * ;               arr[coords[0].first + 1][coords[0].second] =  * ;           }       }       else if (coords[0].second == coords[1].second) {               if (coords[0].second == N - 1) {                   arr[coords[0].first][N - 2] =  * ;                   arr[coords[1].first][N - 2] =  * ;               }               else {                   arr[coords[0].first][coords[0].second + 1] =  * ;                   arr[coords[1].first][coords[1].second + 1] =  * ;               }           }       else {           arr[coords[0].first][coords[1].second] =  * ;           arr[coords[1].first][coords[0].second] =  * ;       }          for (int i = 0; i < N; i++) {           for (int j = 0; j < N; j++) {               cout << arr[i][j];           }           cout <<   n ;       }      }      int main()   {       std::ios::sync_with_stdio(0);       std::cin.tie(0); std::cout.tie(0); std::cout << std::fixed;          int t; std::cin >> t;       while(t--) solve();          return 0;   }                     //                                                                                |   //                                                                                |   //------------------------------------------------------------------------------------------------               //  NOTES:   //~~~~~~~~~~~~~~~~~~~~~~~~   // debug:   // - check int overflow, out of bounds   // - negative indexing?   //  special cases (n = 1, n = 0?)   //  do something instead of nothing   //  *stay organized*   // - write down IDEAS   // - DON T GET CAUGHT ON ONE APPROACH   //   //   //   // most of all, maintain absolute concentration - take a break if you must   //   //


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 10000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       long long n;       cin >> n;       vector<int> vals;       int pos2 = -1;       while (n > 0) {         vals.push_back(n % 3);         if (vals.back() == 2) pos2 = int(vals.size()) - 1;         n /= 3;       }       vals.push_back(0);       if (pos2 != -1) {         int pos0 = find(vals.begin() + pos2, vals.end(), 0) - vals.begin();         vals[pos0] = 1;         for (int i = pos0 - 1; i >= 0; --i) {           vals[i] = 0;         }       }       long long ans = 0;       long long pw = 1;       for (int i = 0; i < int(vals.size()); ++i) {         ans += pw * vals[i];         pw *= 3;       }       if (vals.back() == 1) ans = pw / 3;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const bool MULTI_TESTCASES = 0;   struct Query {     int l, r, id;   };   void solve() {     int n, k;     cin >> n >> k;     vector<int> t(n + 1);     for (int i = 1; i < n + 1; ++i) {       cin >> t[i];       if (t[i] == 2) t[i] = -1;     }     vector<ll> a(n + 1);     for (int i = 1; i < n + 1; ++i) {       cin >> a[i];       a[i] *= t[i];       a[i] += a[i - 1];     }     map<ll, int> comp;     for (int i = 0; i < n + 1; ++i) {       comp[a[i]] = comp[a[i] - k] = comp[a[i] + k] = 0;     }     int z = 0;     for (auto &kv : comp) kv.second = z++;     vector<int> a1(n + 1), a2(n + 1), a3(n + 1);     for (int i = 0; i < n + 1; ++i) {       a1[i] = comp[a[i]];       a2[i] = comp[a[i] - k];       a3[i] = comp[a[i] + k];     }     int q;     cin >> q;     vector<Query> qs(q);     for (int i = 0; i < q; ++i) {       cin >> qs[i].l >> qs[i].r;       --qs[i].l;       qs[i].id = i;     }     int sqrtn = sqrt(n + 1);     sort(qs.begin(), qs.end(), [&](const Query &q1, const Query &q2) {       return make_pair(q1.l / sqrtn, q1.r) < make_pair(q2.l / sqrtn, q2.r);     });     int l = 0, r = -1;     ll cur = 0;     vector<ll> ans(q), oc(z);     for (auto &query : qs) {       while (l > query.l) {         --l;         cur += oc[a3[l]];         oc[a1[l]]++;       }       while (l < query.l) {         oc[a1[l]]--;         cur -= oc[a3[l]];         ++l;       }       while (r < query.r) {         ++r;         cur += oc[a2[r]];         oc[a1[r]]++;       }       while (r > query.r) {         oc[a1[r]]--;         cur -= oc[a2[r]];         --r;       }       ans[query.id] = cur;     }     for (auto x : ans) {       cout << x <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int testcases = 1;     if (MULTI_TESTCASES) cin >> testcases;     while (testcases--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[102];   int main() {     int n, i, l, r, j;     char name[100009];     cin >> n;     scanf( %s , name);     l = 0;     r = 9;     for (i = 0; i < n; i++) {       if (name[i] ==  L )         for (j = 0; j < 10; j++)           if (a[j] == 0) {             a[j] = 1;             break;           }       if (name[i] ==  R )         for (j = 9; j >= 0; j--)           if (a[j] == 0) {             a[j] = 1;             break;           }       if (name[i] >=  0  && name[i] <=  9 ) a[name[i] -  0 ] = 0;     }     for (i = 0; i < 10; i++) printf( %d , a[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma optimize(  , off)   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma comment(linker,  /STACK:36777216 )   const int mod = 1000000007;   using namespace std;   template <class T>   void smin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void smax(T& a, T val) {     if (a < val) a = val;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {     bool first = true;     os <<  [ ;     for (auto i : v) {       if (!first) os <<  ,  ;       os << i;       first = false;     }     return os <<  ] ;   }   const int N = 1e3 + 10;   int n, cnt;   std::vector<pair<int, int> > v;   bool used[N];   void dfs(int x) {     used[x] = 1;     for (int i = 0; i < n; ++i) {       if (!used[i]) {         if (v[x].first == v[i].first or v[x].second == v[i].second) {           dfs(i);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       v.push_back({x, y});     }     for (int i = 0; i < n; ++i) {       if (!used[i]) {         dfs(i);         cnt++;       }     }     cout << max(cnt - 1, 0);     return 0;   }


#include <bits/stdc++.h>   const int N = 100000 + 1;   struct Point {     int x, y;     Point(int x = 0, int y = 0) : x(x), y(y) {}     Point &operator-=(const Point &o) {       x -= o.x;       y -= o.y;       return *this;     }     int quadrant() const {       if (y != 0) {         return y > 0;       }       return x < 0;     }   };   long long det(const Point &a, const Point &b) {     return (long long)a.x * b.y - (long long)a.y * b.x;   }   bool operator<(const Point &a, const Point &b) {     if (a.quadrant() == b.quadrant()) {       return det(a, b) > 0;     }     return a.quadrant() < b.quadrant();   }   Point operator-(Point a, const Point &b) { return a -= b; }   std::istream &operator>>(std::istream &in, Point &p) {     return in >> p.x >> p.y;   }   int n, m;   Point points[N];   int edge_count, first_edge[N], to[N << 1], flow[N << 1], next_edge[N << 1];   void add_edge(int u, int v) {     to[edge_count] = v;     flow[edge_count] = 0;     next_edge[edge_count] = first_edge[u];     first_edge[u] = edge_count++;   }   bool visit[N];   int construct(int u) {     int size = 1;     visit[u] = true;     for (int iter = first_edge[u]; iter != -1; iter = next_edge[iter]) {       int v = to[iter];       if (!visit[v]) {         int ret = construct(v);         flow[iter] = -ret;         flow[iter ^ 1] = -flow[iter];         size += ret;       }     }     return size;   }   int cycle[N];   std::map<std::pair<int, int>, int> edges;   std::vector<int> sums[N];   int main() {     std::cin >> n >> m;     edge_count = 0;     memset(first_edge, -1, sizeof(first_edge));     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       add_edge(a, b);       add_edge(b, a);     }     for (int i = 0; i < n; ++i) {       std::cin >> points[i];     }     int bottom_id = 0;     for (int i = 0; i < n; ++i) {       if (points[i].x < points[bottom_id].x) {         bottom_id = i;       }     }     points[n++] = points[bottom_id] - Point(1, 0);     add_edge(bottom_id, n - 1);     add_edge(n - 1, bottom_id);     memset(visit, 0, sizeof(visit));     construct(n - 1);     for (int u = 0; u < n; ++u) {       std::vector<std::pair<Point, int> > order;       for (int iter = first_edge[u]; iter != -1; iter = next_edge[iter]) {         int v = to[iter];         order.push_back(std::make_pair(points[v] - points[u], iter));       }       std::sort(order.begin(), order.end());       sums[u].push_back(0);       for (int i = 0; i < (int)order.size(); ++i) {         int iter = order[i].second;         edges[std::make_pair(u, to[iter])] = i + 1;         sums[u].push_back(sums[u].back() + flow[iter]);       }     }     int q;     std::cin >> q;     while (q--) {       int m;       scanf( %d , &m);       for (int i = 0; i < m; ++i) {         scanf( %d , cycle + i);         cycle[i]--;       }       long long area = 0;       for (int i = 0; i < m; ++i) {         area += det(points[cycle[i]], points[cycle[(i + 1) % m]]);       }       if (area < 0) {         std::reverse(cycle, cycle + m);       }       int answer = 0;       for (int i = 0; i < m; ++i) {         int u = cycle[i];         int from = edges[std::make_pair(u, cycle[(i + m - 1) % m])];         int to = edges[std::make_pair(u, cycle[(i + 1) % m])];         if (from <= to) {           answer += sums[u][to - 1];           answer -= sums[u][from];         } else {           answer += sums[u][(int)sums[u].size() - 1];           answer -= sums[u][from];           answer += sums[u][to - 1];         }       }       printf( %d n , answer);     }     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-9;   const double PI = acos(-1);   const long long MOD = 1e9 + 7;   using namespace std;   vector<string> powers;   pair<string, string> solution(string s) {     string order;     reverse(s.begin(), s.end());     map<char, int> mp;     for (char c : s) {       if (!mp[c]) {         order.push_back(c);       }       mp[c]++;     }     int m = order.length();     int original_size = 0;     for (int i = 0; i < m; i++) {       original_size += mp[order[i]] / (m - i);     }     reverse(order.begin(), order.end());     return {string(s.rbegin(), s.rbegin() + original_size), order};   }   string check(pair<string, string> p) {     string result = p.first;     for (auto c : p.second) {       string tmp;       for (auto d : p.first) {         if (d != c) {           tmp.push_back(d);           result.push_back(d);         }       }       p.first = tmp;     }     return result;   }   void solve() {     string s;     cin >> s;     auto it = solution(s);     auto res = check(it);     if (res == s) {       cout << it.first <<     << it.second << endl;     } else {       cout << -1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (long long i = 1; i <= 2e18; i *= 2) {       powers.push_back(to_string(i));     }     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     map<string, int> gram;     for (int i = 0; i < n - 1; i++) ++gram[s.substr(i, 2)];     int cnt = 0;     string ans =   ;     for (auto e : gram)       if (e.second > cnt) cnt = e.second, ans = e.first;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e4 + 10;   const int M = (int)1e9 + 7;   int n, k;   int mina, maxa;   void track() {     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (n); j++) {         if (i == j)           cout << k;         else           cout << 0;         if (j != n) cout <<    ;       }       cout << endl;     }     cout << endl;   }   int main() {     cin >> n >> k;     track();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005, N = 333333;   const int D = 1e9 + 7, inv2 = 5e8 + 4;   int n, Q, a[MAXN], mul[N + 233], inv[N + 233];   int val[MAXN << 1];   int id[MAXN], w[MAXN];   int tim, len;   struct node {     int v, id;     node() {}     node(int vv, int ii) { v = vv, id = ii; }   } s[MAXN << 1];   bool operator<(const node &aa, const node &bb) {     if (aa.v != bb.v) return aa.v < bb.v;     return aa.id < bb.id;   }   int v0[MAXN << 4], v1[MAXN << 4], sum[MAXN << 4], cnt[MAXN << 4];   void up(int p) {     cnt[p] = cnt[p << 1] + cnt[p << 1 | 1];     sum[p] = (sum[p << 1] + sum[p << 1 | 1] +               1ll * v0[p << 1] * v1[p << 1 | 1] % D * inv[cnt[p << 1]]) %              D;     v0[p] = (v0[p << 1] + 1ll * v0[p << 1 | 1] * mul[cnt[p << 1]]) % D;     v1[p] = (v1[p << 1] + 1ll * v1[p << 1 | 1] * inv[cnt[p << 1]]) % D;   }   void insert(int p, int l, int r, int x) {     if (l == r) {       cnt[p] = 1, sum[p] = 0;       v0[p] = val[x];       v1[p] = 1ll * val[x] * inv[1] % D;       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       insert(p << 1, l, mid, x);     else       insert(p << 1 | 1, mid + 1, r, x);     up(p);   }   void remove(int p, int l, int r, int x) {     if (l == r) return (void)(cnt[p] = sum[p] = v0[p] = v1[p] = 0);     int mid = (l + r) >> 1;     if (x <= mid)       remove(p << 1, l, mid, x);     else       remove(p << 1 | 1, mid + 1, r, x);     up(p);   }   int main() {     mul[0] = inv[0] = 1;     for (int i = 1; i <= N; i++) mul[i] = mul[i - 1] * 2 % D;     for (int i = 1; i <= N; i++) inv[i] = 1ll * inv[i - 1] * inv2 % D;     scanf( %d , &n);     tim = -n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), s[++len] = node(a[i], ++tim);     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       scanf( %d%d , &id[i], &w[i]);       s[++len] = node(w[i], ++tim);     }     sort(s + 1, s + len + 1);     for (int i = 1; i <= len; i++) {       val[i] = s[i].v;       if (s[i].id <= 0)         a[s[i].id + n] = i;       else         w[s[i].id] = i;     }     for (int i = 1; i <= n; i++) insert(1, 1, len, a[i]);     printf( %d n , sum[1]);     for (int i = 1; i <= Q; i++) {       remove(1, 1, len, a[id[i]]);       insert(1, 1, len, w[i]);       a[id[i]] = w[i];       printf( %d n , sum[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   vector<int> g[N];   int mn[N];   int mx[N];   int ans;   void dfs(int u, int p) {     bool leaf = true;     mn[u] = 1e9;     mx[u] = -1e9;     for (int v : g[u])       if (v != p) {         dfs(v, u);         leaf = false;         mn[u] = min(mn[u], mn[v] + 1);         mx[u] = max(mx[u], mx[v] + 1);       }     if (leaf) {       mn[u] = 0;       mx[u] = 0;     }   }   void dfs2(int u, int p) {     const int m = g[u].size();     bool ok = true;     vector<int> hh;     for (int v : g[u]) {       if (mx[v] != mn[v]) ok = false;       hh.push_back(mx[v] + 1);     }     if (ok) {       sort(hh.begin(), hh.end());       hh.erase(unique(hh.begin(), hh.end()), hh.end());       if (hh.size() <= 2) {         int len = 0;         for (int e : hh) len += e;         while (len % 2 == 0) len /= 2;         ans = min(ans, len);       }     }     vector<int> maxl(m);     vector<int> maxr(m);     vector<int> minl(m);     vector<int> minr(m);     maxl[0] = -1e9;     minl[0] = 1e9;     maxr[m - 1] = -1e9;     minr[m - 1] = 1e9;     for (int i = 1; i < m; i++) {       maxl[i] = max(maxl[i - 1], mx[g[u][i - 1]] + 1);       minl[i] = min(minl[i - 1], mn[g[u][i - 1]] + 1);     }     for (int i = m - 2; i >= 0; i--) {       maxr[i] = max(maxr[i + 1], mx[g[u][i + 1]] + 1);       minr[i] = min(minr[i + 1], mn[g[u][i + 1]] + 1);     }     for (int i = 0; i < m; i++) {       int v = g[u][i];       if (v == p) continue;       mn[u] = min(minl[i], minr[i]);       mx[u] = max(maxl[i], maxr[i]);       dfs2(v, u);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     if (n == 2) {       cout << 1 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       if (g[i].size() >= 2) {         ans = 1e9;         dfs(i, -1);         dfs2(i, -1);         if (ans >= 1e8) ans = -1;         cout << ans << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool found = false;   int b, A[10000], orig_a;   int main() {     int a, b[3], i, j, n, x, y, z, array[100000];     cin >> n;     for (i = 0; i < 3; i++) {       if (i <= 1) {         cout <<  ?   << 1 <<     << i + 2 << endl;       } else {         cout <<  ?   << 2 <<     << 3 << endl;       }       fflush(stdout);       cin >> b[i];     }     z = -(b[0] - b[1] - b[2]) / 2;     y = b[2] - z;     x = b[0] - y;     array[0] = x;     array[1] = y;     array[2] = z;     for (i = 4; i <= n; i++) {       cout <<  ?   << 1 <<     << i << endl;       fflush(stdout);       cin >> a;       array[i - 1] = a - x;     }     cout <<  ! ;     for (i = 0; i < n; i++) {       cout <<     << array[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 1111111, inf = 1000000007;   int n, k, a[max_n], pw[max_n], used[max_n];   int main() {     cin >> n >> k;     if (k == 0) {       long long ans = 1;       for (int i = 1; i < n; ++i) {         ans = (ans * n) % inf;       }       cout << ans << endl;       return 0;     }     if (k == 1) {       long long ans = 1;       for (int i = 0; i < n; ++i) {         ans = (ans * n) % inf;       }       cout << ans << endl;       return 0;     }     pw[0] = 1;     for (int i = 1; i < n; ++i) {       pw[i] = (1LL * pw[i - 1] * k) % n;     }     for (int i = 0; i < n; ++i) {       a[i] = (1LL * i * k) % n;     }     long long ans = 1;     for (int i = 0; i < n; ++i) {       if (used[i] == 0) {         int cnt = 1, v = i, last;         while (used[v] == 0) {           used[v] = cnt;           ++cnt;           last = v;           v = a[v];         }         cnt = used[last] - used[v] + 1;         if (pw[cnt] == 1) {           ans = (ans * n) % inf;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     map<char, int> mp;     for (int i = 0; i < s.length(); i++) {       mp[s[i]]++;     }     int mn;     set<int> st;     set<int>::iterator it;     st.insert(mp[ B ]);     st.insert(mp[ u ] / 2);     st.insert(mp[ l ]);     st.insert(mp[ b ]);     st.insert(mp[ a ] / 2);     st.insert(mp[ s ]);     st.insert(mp[ r ]);     it = st.begin();     cout << *it;   }


#include <bits/stdc++.h>   using namespace std;   char buf[11];   const int MAXC = 20;   double C[MAXC][MAXC + 1];   void count(int &sum, int &q) {     char buf[11];     cin >> buf;     sum = 0;     q = 0;     for (char *p = buf; *p; ++p) {       switch (*p) {         case  + :           ++sum;           break;         case  - :           --sum;           break;         case  ? :           ++q;       }     }   }   void init_C() {     C[0][0] = 1.0;     for (int i = 1; i < MAXC; ++i) {       C[i][0] = C[i][i] = 1.0;       for (int j = 1; j < i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];     }   }   int main() {     init_C();     int sum1, sum2, quest;     count(sum1, quest);     count(sum2, quest);     int diff = sum1 - sum2;     int t = (quest + diff) / 2;     if (abs(diff) > quest || (quest + diff) % 2) {       cout <<  0.0 n ;     } else {       cout << setprecision(12) << C[quest][t] / (1 << quest) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long double x, y;     Point(){};     long double dist(Point b) {       return sqrt((b.x - x) * (b.x - x) + (b.y - y) * (b.y - y));     }   };   int main() {     Point a, b, c;     cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;     long double k = a.dist(b);     long double l = c.dist(b);     if (k == l && k + l != a.dist(c))       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   int main() {     int days, time, count, free;     int x = 0;     scanf( %d , &days);     scanf( %d , &time);     int busyTime[days];     for (x = 0; x < days; x++) {       scanf( %d , &busyTime[x]);     }     count = 0;     while (time > 0) {       free = 86400 - busyTime[count];       time -= free;       count++;     }     printf( %d , count);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   const int N = 1e5 + 5;   const int TN = 1 << 18;   const double PI = acos(-1);   int n, m, k;   long long tree[TN], lazy[TN] = {0};   void probagate(int l, int r, int p) {     tree[p] |= lazy[p];     if (l != r) {       lazy[p << 1] |= lazy[p];       lazy[(p << 1) | 1] |= lazy[p];     }     lazy[p] = 0;   }   void update(int val, int ql, int qr, int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (ql > r || qr < l) return;     if (ql <= l && r <= qr) {       lazy[p] |= val;       probagate(l, r, p);       return;     }     int m = (l + r) >> 1;     update(val, ql, qr, l, m, (p << 1));     update(val, ql, qr, m + 1, r, (p << 1) | 1);     tree[p] = tree[(p << 1)] & tree[(p << 1) | 1];   }   int get(int ql, int qr, int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (ql > r || qr < l) return (1LL << 31) - 1;     if (ql <= l && r <= qr) {       return tree[p];     }     int m = (l + r) >> 1;     return get(ql, qr, l, m, (p << 1)) & get(ql, qr, m + 1, r, (p << 1) | 1);   }   void print(int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (l == r) {       printf( %d  , tree[p]);       return;     }     int m = (l + r) >> 1;     print(l, m, (p << 1));     print(m + 1, r, (p << 1) | 1);   }   int main() {     scanf( %d%d , &n, &m);     vector<pair<pair<int, int>, int>> v;     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       v.push_back({{a, b}, c});       update(c, a, b);     }     for (int i = 0; i < m; i++) {       int a = v[i].first.first;       int b = v[i].first.second;       int c = v[i].second;       if (get(a, b) != c) {         return puts( NO );       }     }     puts( YES );     print();   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int i;     int j;   };   int main() {     vector<char> s;     int n, m;     char c;     char a[102][102];     point first;     first.i = -1;     point last;     memset(a, 0, sizeof(a));     scanf( %d %d %c , &n, &m, &c);     getchar();     for (int i = 0; i < n + 1; i++) {       a[i][0] = c;       a[i][m + 1] = c;     }     for (int i = 0; i < m + 1; i++) {       a[0][i] = c;       a[n + 1][i] = c;     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) {         scanf( %c , &c);         a[i][j] = c;         if (c == a[0][0]) {           if (first.i < 0) {             first.i = i;             first.j = j;           }           last.i = i;           last.j = j;         }       }       getchar();     }     int can;     for (int i = first.i; i < last.i + 1; i++) {       for (int j = first.j; j < last.j + 1; j++) {         can = count(s.begin(), s.end(), a[i][j]);         if (a[i - 1][j] !=  .  && count(s.begin(), s.end(), a[i - 1][j]) == 0)           s.push_back(a[i - 1][j]);         if (a[i][j - 1] !=  .  && count(s.begin(), s.end(), a[i][j - 1]) == 0)           s.push_back(a[i][j - 1]);         if (a[i][j + 1] !=  .  && count(s.begin(), s.end(), a[i][j + 1]) == 0)           s.push_back(a[i][j + 1]);         if (a[i + 1][j] !=  .  && count(s.begin(), s.end(), a[i + 1][j]) == 0)           s.push_back(a[i + 1][j]);       }     }     if (s.size())       printf( %d n , s.size() - 1);     else       printf( %d n , s.size());     return 0;   }


#include <bits/stdc++.h>   #pragma optimize( O3 )   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   const int base = 2e5 + 1;   const int MAX = 1e5 + 2;   const double EPS = 1e-9;   const double PI = acos(-1.);   const int MAXN = 1e6 + 47;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     int n;     cin >> n;     int cnt = 0;     vector<int> res;     set<int> was, is;     for (long long i = (0); i < (n); ++i) {       int a;       cin >> a;       if (a < 0) {         if (is.count(abs(a))) {           is.erase(abs(a));           cnt--;         } else {           cout << -1;           return 0;         }       } else {         if (was.count(a) || is.count(a)) {           cout << -1;           return 0;         } else {           was.insert(a);           is.insert(a);           cnt++;         }       }       if (cnt == 0) {         res.push_back(i + 1);         was.clear();       }     }     if (cnt != 0) {       cout << -1;       return 0;     }     cout << (int)res.size() <<   n ;     int last = 0;     for (long long i = (0); i < ((int)res.size()); ++i) {       cout << res[i] - last <<    ;       last = res[i];     }     cerr <<   nTime elapsed:   << clock() / (double)CLOCKS_PER_SEC <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int s = 0;     int a[5000];     cin >> n;     int i;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       if (a[i] == a[a[a[a[i]]]]) s = s + 1;     }     if (s != 0) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n * 2);     vector<pair<int, int>> ans;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[n + i].first;       a[n + i].second = 1;     }     sort(a.begin(), a.end());     int z = 0;     for (int i = 0; i < n * 2; i++)       if (a[i].second == 0) {         z++;         if (z == k) ans.push_back({a[i].first, 0});       } else {         if (z == k) ans.back().second = a[i].first;         z--;       }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using ld = long double;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vpi = vector<pi>;   using si = set<int>;   using sl = set<ll>;   using qi = queue<int>;   using ql = queue<ll>;   template <class T>   bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   template <class T>   bool uin(T& u, T& v, T a, T b) {     return v - u > b - a ? (u = a, v = b, true) : false;   }   template <class T>   bool uax(T& u, T& v, T a, T b) {     return v - u < b - a ? (u = a, v = b, true) : false;   }   namespace input {   template <class T>   void re(complex<T>& x);   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   void re(ld& x) {     string t;     re(t);     x = stold(t);   }   template <class T, class... Ts>   void re(T& t, Ts&... ts) {     re(t);     re(ts...);   }   template <class T>   void re(complex<T>& x) {     T a, b;     re(a, b);     x = cd(a, b);   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.f, p.s);   }   template <class T>   void re(vector<T>& a) {     for (int i = 0; i < (((int)(a).size())); ++i) re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = 0; i < (SZ); ++i) re(a[i]);   }   }  // namespace input   using namespace input;   namespace output {   void pr(int x) { cout << x; }   void pr(long x) { cout << x; }   void pr(ll x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(unsigned long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(float x) { cout << x; }   void pr(double x) { cout << x; }   void pr(ld x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { pr(x ?  true  :  false ); }   template <class T>   void pr(const complex<T>& x) {     cout << x;   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T>   void pr(const T& x);   template <class T, class... Ts>   void pr(const T& t, const Ts&... ts) {     pr(t);     pr(ts...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.f,  ,  , x.s,  } );   }   template <class T>   void pr(const T& x) {     pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0;     pr( } );   }   void ps() { pr(  n ); }   template <class T, class... Ts>   void ps(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr(   );     ps(ts...);   }   void pc() { pr( ] n ); }   template <class T, class... Ts>   void pc(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr( ,  );     pc(ts...);   }   }  // namespace output   using namespace output;   inline int bs(bool (*valid)(int), int l, int r, bool order) {     l--, r++;     if (!order) swap(l, r);     while (abs(r - l) > 1) {       int mid = (l + r) >> 1;       if (valid(mid))         r = mid;       else         l = mid;     }     valid(r);     return r;   }   struct dsu {     vector<int> p;     dsu(int n) { p.resize(n + 1); }     inline int get(int x) { return p[x] ? p[x] = get(p[x]) : x; }     inline bool mrg(int x, int y) {       return get(x) == get(y) ? false : p[get(x)] = get(y);     }   };   const int M = 1e9 + 7;   const ll lnf = 1e18 + 3;   const int inf = 1e9 + 3;   const int nax = 1e6 + 5;   typedef decay<decltype(M)>::type T;   struct mi {     T val;     explicit operator T() const { return val; }     mi() { val = 0; }     mi(const ll& v) {       val = (-M <= v && v <= M) ? v : v % M;       if (val < 0) val += M;     }     friend void pr(const mi& a) { pr(a.val); }     friend void re(mi& a) {       ll x;       re(x);       a = mi(x);     }     friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }     friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }     friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }     mi operator-() const { return mi(-val); }     mi& operator+=(const mi& m) {       if ((val += m.val) >= M) val -= M;       return *this;     }     mi& operator-=(const mi& m) {       if ((val -= m.val) < 0) val += M;       return *this;     }     mi& operator*=(const mi& m) {       val = (ll)val * m.val % M;       return *this;     }     friend mi pow(mi a, ll p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi& a) {       assert(a != 0);       return pow(a, M - 2);     }     mi& operator/=(const mi& m) { return (*this) *= inv(m); }     friend mi operator+(mi a, const mi& b) { return a += b; }     friend mi operator-(mi a, const mi& b) { return a -= b; }     friend mi operator*(mi a, const mi& b) { return a *= b; }     friend mi operator/(mi a, const mi& b) { return a /= b; }   };   vi invs, fac, ifac;   void genFac(int SZ) {     invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);     invs[1] = fac[0] = ifac[0] = 1;     for (int i = (2); i <= (SZ - 1); ++i)       invs[i] = M - (ll)M / i * invs[M % i] % M;     for (int i = (1); i <= (SZ - 1); ++i) {       fac[i] = (ll)fac[i - 1] * i % M;       ifac[i] = (ll)ifac[i - 1] * invs[i] % M;     }   }   ll comb(int a, int b) {     if (a < b || b < 0) return 0;     return (ll)fac[a] * ifac[b] % M * ifac[a - b] % M;   }   ll p[nax], s, c;   int t, n, q[nax];   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     re(n);     vl a(n);     re(a);     for (int i = 0; i < (n); ++i) {       s = a[i], c = 1;       while (t && p[t] * c >= s * q[t]) s += p[t], c += q[t--];       p[++t] = s, q[t] = c;     }     cout << setprecision(10);     for (int i = (1); i <= (t); ++i)       for (int j = 0; j < (q[i]); ++j) cout << (double)p[i] / q[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int main() {     int n, m;     string s;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s;       mp[s] = 1;     }     int con = 0;     for (int i = 0; i < m; i++) {       cin >> s;       if (mp[s] == 1) {         con++;       }     }     m -= con;     n -= con;     if (con & 1) {       n++;     }     if (n > m) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       if (a == c) {         cout <<  -1   << b <<   n ;       } else if (a > c) {         cout <<  -1 1 n ;       } else {         double x = (double)c / b;         double y = (double)a;         if (x < y)           cout <<  1   << b <<   n ;         else           cout <<  1 -1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj, CC;   const int MX = 1e5 + 69;   int n, m, q, vis[MX], dis[MX], pa[MX], compsz[MX], D[MX];   int parent(int x) {     if (x == pa[x]) return x;     return pa[x] = parent(pa[x]);   }   bool cmp(int a, int b) {     if (dis[a] != dis[b]) return dis[a] < dis[b];     return a < b;   }   long long* cum[MX];   int* compel[MX];   int bfs(int x, bool ok) {     int p = parent(x);     queue<int> q;     q.push(x);     vis[x] = 0;     vector<int> v;     while (!q.empty()) {       int nxt = q.front();       v.push_back(nxt);       q.pop();       for (auto u : adj[nxt]) {         if (vis[u] == -1) {           vis[u] = vis[nxt] + 1;           dis[u] = max(dis[u], vis[u]);           q.push(u);           D[p] = max(D[p], dis[u]);         }       }     }     int mx = -69, opt = x;     while (!v.empty() && ok == 1) {       int nxt = v.back();       v.pop_back();       if (mx < vis[nxt]) {         mx = vis[nxt];         opt = nxt;       }       vis[nxt] = -1;     }     if (ok) return opt;     sort(v.begin(), v.end(), cmp);     int sz = v.size(), j = 0;     long long sum = 0;     p = parent(x);     compel[p] = new int[D[p] + 2];     cum[p] = new long long[D[p] + 2];     for (int i = 0; i <= D[p] + 1; i++) cum[p][i] = compel[p][i] = 0;     for (auto u : v) {       j++;       sum += dis[u];       cum[p][dis[u] + 1] = sum;       compel[p][dis[u] + 1] = j;     }     compsz[p] = v.size();     CC[p] = v;     v.clear();     return opt;   }   long double nig[MX];   void join(int u, int v) {     u = parent(u);     v = parent(v);     if (u == v) return;     pa[u] = v;   }   map<int, long double> quer[MX];   int DD;   long double solve(int u, int v) {     if (compsz[u] > compsz[v]) swap(u, v);     if (quer[u].count(v)) return quer[u][v];     DD = max(D[u], D[v]);     long double ret = 0;     for (int i = 0; i < compsz[u]; i++) {       int nxt = CC[u][i];       int l = min(D[v], max(-1, DD - dis[nxt] - 2));       long double r = compsz[v] - compel[v][l + 1];       ret += r * (dis[nxt] + 1) + cum[v][D[v] + 1] - cum[v][l + 1] +              (long double)compel[v][l + 1] * DD;     }     return quer[u][v] = ret / ((long double)compsz[u] * compsz[v]);   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) pa[i] = i;     memset(vis, -1, sizeof vis);     adj.resize(n + 69);     CC.resize(n + 69);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       join(u, v);     }     for (int i = 1; i <= n; i++) {       if (i != parent(i)) continue;       int p = parent(i);       int u = bfs(i, 1);       u = bfs(u, 1);       bfs(u, 0);     }     cout << fixed;     cout.precision(10);     for (int i = 1; i <= q; i++) {       int u, v;       scanf( %d%d , &u, &v);       u = parent(u);       v = parent(v);       if (u == v)         cout << -1 << endl;       else         cout << solve(u, v) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x1, y1, x2, y2, x0, y0;     while (scanf( %lf%lf%lf%lf%lf%lf , &x0, &y0, &x1, &y1, &x2, &y2) != EOF) {       double area = x0 * y1 + x2 * y0 + x1 * y2 - x2 * y1 - x0 * y2 - x1 * y0;       if (area == 0) {         printf( TOWARDS n );       } else if (area > 0) {         printf( LEFT n );       } else {         printf( RIGHT n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200 * 1000 + 1;   struct Seg {     int s, e, Id;     friend bool operator<(Seg a, Seg b) { return a.s < b.s; }     friend bool operator>(Seg a, Seg b) {       return (a.e != b.e ? a.e > b.e : a.Id > b.Id);     }   } a[MAX + 10];   set<Seg, greater<Seg> > s;   bool mrk[MAX + 10];   int cnt = 0;   int n, m;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++)       cin >> a[i].s >> a[i].e, a[i].Id = i, a[i].e += a[i].s;     sort(a, a + m);     int p = 0;     int next = 0;     for (int i = 1; i <= n; i++) {       while (p < m && a[p].s == i) s.insert(a[p++]);       if (next <= i && !s.empty() && s.begin()->e > i) {         mrk[s.begin()->Id] = true;         next = s.begin()->e;         s.erase(s.begin());         cnt++;       }     }     cout << m - cnt << endl;     for (int i = 0; i < m; i++)       if (!mrk[i]) cout << i + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s;   const int N = 1e5 + 10;   int v[N];   int ans;   bool check(int x, int &res) {     int k[n];     for (int i = 0; i < n; i++) {       k[i] = v[i] + (i + 1) * x;     }     sort(k, k + n);     for (int i = 0; i < x; i++)       if (res <= s) res += k[i];     return res <= s;   }   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int hi = n + 1;     int lo = 0;     for (int i = 0; i < 100; i++) {       int mid = (hi + lo) >> 1;       int valor = 0;       if (check(mid, valor)) {         ans = valor;         lo = mid;       } else         hi = mid;     }     cout << lo <<     << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string sol;   const int kBufferSize = 10000;   int BufferInd = kBufferSize;   char Buffer[kBufferSize];   void cit(int &n) {     ((++BufferInd >= kBufferSize) ? (cin.read(Buffer, kBufferSize), BufferInd = 0)                                   : (0));     for (; not((((Buffer[BufferInd]) >=  0  and (Buffer[BufferInd]) <=  9 ) or                 (Buffer[BufferInd]) ==  - )                    ? (1)                    : (0));          ((++BufferInd >= kBufferSize)               ? (cin.read(Buffer, kBufferSize), BufferInd = 0)               : (0)))       ;     bool sign = false;     if ((Buffer[BufferInd]) ==  - ) {       ((++BufferInd >= kBufferSize)            ? (cin.read(Buffer, kBufferSize), BufferInd = 0)            : (0));       sign = true;     }     n = 0;     for (; ((((Buffer[BufferInd]) >=  0  and (Buffer[BufferInd]) <=  9 ) or              (Buffer[BufferInd]) ==  - )                 ? (1)                 : (0));          ((++BufferInd >= kBufferSize)               ? (cin.read(Buffer, kBufferSize), BufferInd = 0)               : (0))) {       n *= 10;       n += (Buffer[BufferInd]) -  0 ;     }     if (sign) n *= -1;   }   int main() {     std::ios_base::sync_with_stdio(false);     int n, sum = 0;     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         int x;         cin >> x;         if (i == j) sum ^= x;       }     int q;     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1 or t == 2) {         int x;         cin >> x;         sum ^= 1;       } else {         sol +=  0  + sum;       }     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool func(pair<int, int> &a, pair<int, int> &b) { return a.first < b.first; }   int main() {     int n, q;     vector<pair<int, int>> arr;     int input1, input2;     int i, j;     int level[5001] = {         0,     };     priority_queue<int, vector<int>, greater<int>> exit;     int curlev = 1;     int cur, prev = 0;     int acc1[5001], acc2[5001];     pair<int, int> interv1, interv2, temp;     int over1, over2;     int last = 0, sum;     int cand;     int lmax = 0;     scanf( %d %d , &n, &q);     for (i = 0; i < q; i++) {       scanf( %d %d , &input1, &input2);       arr.push_back(pair<int, int>(input1, input2));       for (j = input1; j <= input2; j++) {         level[j]++;       }     }     sort(arr.begin(), arr.end(), func);     sum = n;     for (i = 0; i < q; i++) {       if (arr[i].first > prev + 1) {         sum -= arr[i].first - (prev + 1);       }       if (arr[i].second > prev) {         prev = arr[i].second;       }     }     sum -= n - prev;     acc1[0] = acc2[0] = 0;     for (i = 1; i <= n; i++) {       acc1[i] = acc1[i - 1] + (level[i] == 1);       acc2[i] = acc2[i - 1] + (level[i] == 2);     }     for (i = 0; i < q - 1; i++) {       for (j = i + 1; j < q; j++) {         interv1 = arr[i];         interv2 = arr[j];         over1 = 1;         over2 = 0;         if (interv2.first <= interv1.second) {           over1 = interv2.first;           if (interv2.second < interv1.second) {             over2 = interv2.second;           } else {             over2 = interv1.second;           }         }         cand = sum -                ((acc1[interv1.second] - acc1[interv1.first - 1]) +                 (acc1[interv2.second] - acc1[interv2.first - 1])) -                (acc2[over2] - acc2[over1 - 1]);         if (cand > lmax) {           lmax = cand;         }       }     }     printf( %d n , lmax);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   int main() {     int n;     cin >> n;     if (n == 2) {       cout << 1 << endl << 1 <<     << 1 << endl;       return 0;     } else if (n == 3) {       cout <<  0 n2 1 2 n ;     } else if (n == 4) {       cout <<  0 n2 1 4 n ;     } else {       vector<int> v;       vector<int> c;       lli sum_v = 0, sum_c = 0;       for (lli i = n; i >= 1; i--) {         if (abs(sum_v + i - sum_c) < abs(sum_c + i - sum_v)) {           sum_v += i;           v.push_back(i);         } else {           sum_c += i;           c.push_back(i);         }       }       cout << abs(sum_v - sum_c) << endl;       cout << c.size() <<    ;       int in = c.size();       for (lli i = 0; i < (in); i++) {         cout << c[i];         if (i == in - 1)           cout << endl;         else           cout <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int cnt;   long long int v[100005], lft[100005], rgt[100005], rt[100005];   std::map<long long int, bool> M;   void check(long long int i, long long int left, long long int right) {     if (v[i] <= left && v[i] >= right) {       M[v[i]] = true;     }     if (lft[i] != -1) {       long long int left1 = min(left, v[i]);       check(lft[i], left1, right);     }     if (rgt[i] != -1) {       long long int right1 = max(right, v[i]);       check(rgt[i], left, right1);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long int n, root;     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> v[i] >> lft[i] >> rgt[i];     }     cnt = 0;     for (long long int i = 1; i <= n; i++) {       if (lft[i] != -1) rt[lft[i]] = 1;       if (rgt[i] != -1) rt[rgt[i]] = 1;     }     for (long long int i = 1; i <= n; i++) {       if (rt[i] == 0) {         root = i;         break;       }     }     long long int left = INT_MAX;     long long int right = INT_MIN;     check(root, left, right);     for (long long int i = 1; i <= n; i++) cnt += !M[v[i]];     cout << cnt << endl;     return 0;   }