#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   inline int read() {     int ans = 0;     bool f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar();     return f ? ans : -ans;   }   long long n, m;   bool CanMove(long long x, long long y) {     return (x >= 0 && x < n && y >= 0 && y < m);   }   long long DFS1(long long x, long long y, long long sx, long long sy) {     x--, y--;     sx--, sy--;     long long val[n][m];     queue<pair<long long, long long> > q;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) val[i][j] = 0;     q.push(make_pair(x, y));     val[x][y] = 1;     while (!q.empty()) {       pair<long long, long long> p = q.front();       q.pop();       long long X = p.first, Y = p.second;       if (CanMove(X + 1, Y + 2) && val[X + 1][Y + 2] == 0) {         q.push(make_pair(X + 1, Y + 2));         val[X + 1][Y + 2] = val[X][Y] + 1;       }       if (CanMove(X + 1, Y - 2) && val[X + 1][Y - 2] == 0) {         q.push(make_pair(X + 1, Y - 2));         val[X + 1][Y - 2] = val[X][Y] + 1;       }       if (CanMove(X - 1, Y + 2) && val[X - 1][Y + 2] == 0) {         q.push(make_pair(X - 1, Y + 2));         val[X - 1][Y + 2] = val[X][Y] + 1;       }       if (CanMove(X - 1, Y - 2) && val[X - 1][Y - 2] == 0) {         q.push(make_pair(X - 1, Y - 2));         val[X - 1][Y - 2] = val[X][Y] + 1;       }       if (CanMove(X + 2, Y + 1) && val[X + 2][Y + 1] == 0) {         q.push(make_pair(X + 2, Y + 1));         val[X + 2][Y + 1] = val[X][Y] + 1;       }       if (CanMove(X + 2, Y - 1) && val[X + 2][Y - 1] == 0) {         q.push(make_pair(X + 2, Y - 1));         val[X + 2][Y - 1] = val[X][Y] + 1;       }       if (CanMove(X - 2, Y + 1) && val[X - 2][Y + 1] == 0) {         q.push(make_pair(X - 2, Y + 1));         val[X - 2][Y + 1] = val[X][Y] + 1;       }       if (CanMove(X - 2, Y - 1) && val[X - 2][Y - 1] == 0) {         q.push(make_pair(X - 2, Y - 1));         val[X - 2][Y - 1] = val[X][Y] + 1;       }     }     return val[sx][sy];   }   vector<pair<long long, long long> > DFS2(long long x, long long y, long long sx,                                            long long sy) {     x--, y--;     sx--, sy--;     long long val[n][m];     pair<long long, long long> pre[n][m];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) val[i][j] = 0;     vector<pair<long long, long long> > v;     v.clear();     queue<pair<long long, long long> > q;     q.push(make_pair(x, y));     val[x][y] = 1;     while (!q.empty()) {       pair<long long, long long> pp = q.front();       q.pop();       long long X = pp.first, Y = pp.second;       if (CanMove(X + 1, Y + 2) && val[X + 1][Y + 2] == 0) {         q.push(make_pair(X + 1, Y + 2));         val[X + 1][Y + 2] = val[X][Y] + 1;         pre[X + 1][Y + 2] = make_pair(X, Y);       }       if (CanMove(X + 1, Y - 2) && val[X + 1][Y - 2] == 0) {         q.push(make_pair(X + 1, Y - 2));         val[X + 1][Y - 2] = val[X][Y] + 1;         pre[X + 1][Y - 2] = make_pair(X, Y);       }       if (CanMove(X - 1, Y + 2) && val[X - 1][Y + 2] == 0) {         q.push(make_pair(X - 1, Y + 2));         val[X - 1][Y + 2] = val[X][Y] + 1;         pre[X - 1][Y + 2] = make_pair(X, Y);       }       if (CanMove(X - 1, Y - 2) && val[X - 1][Y - 2] == 0) {         q.push(make_pair(X - 1, Y - 2));         val[X - 1][Y - 2] = val[X][Y] + 1;         pre[X - 1][Y - 2] = make_pair(X, Y);       }       if (CanMove(X + 2, Y + 1) && val[X + 2][Y + 1] == 0) {         q.push(make_pair(X + 2, Y + 1));         val[X + 2][Y + 1] = val[X][Y] + 1;         pre[X + 2][Y + 1] = make_pair(X, Y);       }       if (CanMove(X + 2, Y - 1) && val[X + 2][Y - 1] == 0) {         q.push(make_pair(X + 2, Y - 1));         val[X + 2][Y - 1] = val[X][Y] + 1;         pre[X + 2][Y - 1] = make_pair(X, Y);       }       if (CanMove(X - 2, Y + 1) && val[X - 2][Y + 1] == 0) {         q.push(make_pair(X - 2, Y + 1));         val[X - 2][Y + 1] = val[X][Y] + 1;         pre[X - 2][Y + 1] = make_pair(X, Y);       }       if (CanMove(X - 2, Y - 1) && val[X - 2][Y - 1] == 0) {         q.push(make_pair(X - 2, Y - 1));         val[X - 2][Y - 1] = val[X][Y] + 1;         pre[X - 2][Y - 1] = make_pair(X, Y);       }     }     while (sx != x || sy != y) {       v.push_back(make_pair(sx + 1, sy + 1));       pair<long long, long long> pp = pre[sx][sy];       sx = pp.first, sy = pp.second;     }     return v;   }   vector<pair<long long, long long> > v;   long long x, y, sx, sy;   long long fl1, fl2;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> x >> y >> sx >> sy;     fl1 = ((x + y) % 2 != (sx + sy) % 2);     long long aa = DFS1(x, y, n / 2, m / 2);     long long bb = DFS1(sx, sy, n / 2, m / 2);     long long cc = DFS1(x, y, n / 2 + 1, m / 2);     long long dd = DFS1(sx, sy, n / 2 + 1, m / 2);     if (fl1 == 0)       fl2 = ((dd < aa) || (bb <= aa));     else       fl2 = (!((aa <= dd) || ((cc - 1) <= dd)));     cout << (fl2 ?  BLACK  :  WHITE ) << endl;     if (fl2) {       if (fl1) {         v = DFS2(sx, sy, n / 2 + 1, m / 2);         for (long long i = (long long)v.size() - 1; i >= 0; i--) {           long long a, b;           cin >> a >> b;           cout << v[i].first <<     << v[i].second << endl;         }       } else {         if (dd < aa) {           v = DFS2(sx, sy, n / 2 + 1, m / 2);           for (long long i = (long long)v.size() - 1; i >= 0; i--) {             long long a, b;             cin >> a >> b;             cout << v[i].first <<     << v[i].second << endl;             if ((a == v[i].first) && (b == v[i].second)) return 0;           }         } else {           v = DFS2(sx, sy, n / 2, m / 2);           for (long long i = (long long)v.size() - 1; i >= 0; i--) {             long long a, b;             cin >> a >> b;             long long c, d;             c = abs(sx - a);             d = abs(sy - b);             if ((c == 1 && d == 2) || (c == 2 && d == 1)) {               cout << a <<     << b << endl;               return 0;             } else {               cout << v[i].first <<     << v[i].second << endl;               sx = v[i].first, sy = v[i].second;             }           }           long long a, b;           cin >> a >> b;           long long c, d;           c = abs(sx - a);           d = abs(sy - b);           if ((c == 1 && d == 2) || (c == 2 && d == 1)) {             cout << a <<     << b << endl;             return 0;           } else {             sx++, sy += 2;             cout << sx <<     << sy << endl;             cin >> a >> b;             c = abs(sx - a);             d = abs(sy - b);             if ((c == 1 && d == 2) || (c == 2 && d == 1)) {               cout << a <<     << b << endl;               return 0;             } else {               sx -= 2;               sy--;               cout << sx <<     << sy << endl;               sx += 2;               sy--;               cin >> a >> b;               cout << sx <<     << sy << endl;             }           }         }       }     } else {       if (!fl1) {         v = DFS2(x, y, n / 2, m / 2);         cout << v[v.size() - 1].first <<     << v[v.size() - 1].second << endl;         for (long long i = (long long)v.size() - 2; i >= 0; i--) {           long long a, b;           cin >> a >> b;           cout << v[i].first <<     << v[i].second << endl;         }       } else {         if (aa <= dd) {           v = DFS2(x, y, n / 2, m / 2);           cout << v[v.size() - 1].first <<     << v[v.size() - 1].second << endl;           if (v[v.size() - 1].first == x && v[v.size() - 1].second == y) return 0;           for (long long i = (long long)v.size() - 2; i >= 0; i--) {             long long a, b;             cin >> a >> b;             cout << v[i].first <<     << v[i].second << endl;             if (v[i].first == x && v[i].second == y) return 0;           }         } else {           v = DFS2(x, y, n / 2 + 1, m / 2);           long long P = sx, Q = sy;           long long X = x, Y = y;           for (long long i = (long long)v.size() - 1; i >= 0; i--) {             long long c, d;             c = abs(X - P);             d = abs(Y - Q);             if ((c == 1 && d == 2) || (c == 2 && d == 1)) {               cout << P <<     << Q << endl;               return 0;             } else {               cout << v[i].first <<     << v[i].second << endl;               cin >> P >> Q;               X = v[i].first;               Y = v[i].second;             }           }           long long c, d;           c = abs(X - P);           d = abs(Y - Q);           if ((c == 1 && d == 2) || (c == 2 && d == 1)) {             cout << P <<     << Q << endl;             return 0;           } else {             X -= 2, Y++;             cout << X <<     << Y << endl;             cin >> P >> Q;             c = abs(X - P);             d = abs(Y - Q);             if ((c == 1 && d == 2) || (c == 2 && d == 1)) {               cout << P <<     << Q << endl;               return 0;             } else {               X += 2, Y++;               cout << X <<     << Y << endl;               cin >> P >> Q;               X--, Y -= 2;               cout << X <<     << Y << endl;               return 0;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   int col[N], par[N], to[N];   int num = 0;   void dfs(int u, int from) {     if (col[u] == 2) return;     if (col[u] == 1) {       ++num;       return;     }     col[u] = 1;     par[u] = from;     dfs(to[u], u);     col[u] = 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, cnt = 0;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> to[i];     int b[N];     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x) ++cnt;     }     for (int i = 1; i <= n; ++i)       if (!col[i]) dfs(i, -1);     if (num == 1) num = 0;     cout << num + ((cnt % 2) ? 0 : 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, q;     long long int i, j;     cin >> n >> k >> q;     long long int arr[n][2];     for (i = 0; i < n; i++) {       cin >> arr[i][0] >> arr[i][1];     }     long long int temp[200010];     for (i = 0; i < 200001; i++) {       temp[i] = 0;     }     for (i = 0; i < n; i++) {       temp[arr[i][0]] = temp[arr[i][0]] + 1;       temp[arr[i][1] + 1] = temp[arr[i][1] + 1] - 1;     }     for (i = 1; i < 200001; i++) {       temp[i] = temp[i - 1] + temp[i];     }     long long int ans[200010];     ans[0] = 0;     for (i = 1; i < 200001; i++) {       if (temp[i] >= k)         ans[i] = ans[i - 1] + 1;       else         ans[i] = ans[i - 1];     }     int s, e;     while (q--) {       cin >> s >> e;       cout << ans[e] - ans[s - 1] << endl;     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i, j;     int arr1[n], arr2[n], p[n];     for (i = 1; i <= n; i++) cin >> arr1[i];     for (i = 1; i <= n; i++) cin >> arr2[i];     for (i = 1; i <= n; i++) p[arr1[i]] = arr2[i];     for (i = 1; i <= n; i++) cout << p[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, Count = 1;   int main() {     cin >> a >> b >> c;     if ((a + b > c) && (a + c > b) && (b + c > a)) {       cout << 0 << endl;       return 0;     }     while ((a + b < c) || (a + c < b) || (b + c < a)) {       ++Count;       if (a + b < c) {         if (a < b)           a++;         else           b++;       } else if (a + c < b) {         if (a < c)           a++;         else           c++;       } else if (b + c < a) {         if (b < c)           b++;         else           c++;       }     }     cout << Count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long x = __builtin_popcount(n);     if (k > n || k < x) {       cout <<  NO  << endl;     } else {       cout <<  YES n ;       k = k - x;       long long count[30] = {0};       int i = 0;       int a = n;       n = 0;       while (a > 0) {         count[i] = a % 2;         n++;         a = a / 2;         i++;       }       long long cur = 29;       while (k--) {         if (count[cur]) {           count[cur - 1] += 2;           count[cur]--;         } else if (count[cur] == 0) {           cur = cur - 1;           k++;         }       }       cur = 1;       for (int i = 0; i < 30; i++) {         for (int j = 0; j < count[i]; j++) {           cout << cur <<    ;         }         cur *= 2;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<vector<long long>> adj(n + 1, vector<long long>(n + 1, 0));     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cin >> adj[i][j];       }     }     vector<long long> del(n + 1), v, ans;     for (long long i = 1; i <= n; i++) cin >> del[i];     for (long long k = n; k >= 1; k--) {       v.push_back(del[k]);       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= n; j++) {           adj[i][j] = min(adj[i][j], adj[i][del[k]] + adj[del[k]][j]);         }       }       long long sum = 0;       for (long long i = 0; i < v.size(); i++) {         for (long long j = 0; j < v.size(); j++) {           sum += adj[v[i]][v[j]];         }       }       ans.push_back(sum);     }     for (long long i = ans.size() - 1; i >= 0; i--) {       cout << ans[i] <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long qu = 1;     for (long long cas = 1; cas <= qu; cas++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     if (b - a >= 5l)       printf( 0 );     else {       long long p = 1l, t = b;       while (t > a && t > 0) {         p *= t;         p %= 10;         t--;       }       printf( %I64d , p);     }   }


#include <bits/stdc++.h>   using namespace std;   const long int m = 1000000007;   int prsb(long long int n) {     int pos = 0;     long long int m = 1;     while (!(n & m)) {       m = m << 1;       pos++;     }     return pos;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b;       cin >> a >> b;       long long int x, y, z;       int n, c = 0;       x = min(a, b);       y = max(a, b);       z = y / x;       if (y % x != 0) {         c = -1;       } else if (z == 1) {         c = 0;       } else if (z && (!(z & (z - 1)))) {         n = prsb(z);         c += n / 3;         n = n % 3;         c += n / 2;         n = n % 2;         c += n / 1;       } else {         c = -1;       }       cout << c << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, a, b, c, d, mn, mx;     cin >> a >> b >> c >> d;     mn = min(b, d);     b -= mn;     d -= mn;     if (d > b) {       for (i = 0; i < 1000; i++) {         if (d % a == 0) {           cout << d + mn;           return 0;         }         d += c;       }     } else if (d < b) {       for (i = 0; i < 1000; i++) {         if (b % c == 0) {           cout << b + mn;           return 0;         }         b += a;       }     } else if (d == b) {       cout << d + mn;       return 0;     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     double x, y;   };   T ball;   double g1, g2, r, h;   double ll, rr, eps = 1e-8;   int main() {     scanf( %lf%lf%lf%lf%lf%lf , &g1, &g2, &h, &ball.x, &ball.y, &r);     ll = 0;     rr = ball.x;     while (rr - ll > eps) {       double m = (ll + rr) / 2;       double xl = m - (ball.x - m);       double a, b, c;       a = ball.y - (h - r);       b = m - xl;       c = -a * m - b * (h - r);       double yl = -c / b;       if (yl < g1)         rr = m;       else if (yl > g2)         ll = m;       else {         if ((b * g2 + c) / sqrt(a * a + b * b) < r)           ll = m;         else if (yl - r < g1)           rr = m;         else {           printf( %.10lf , m);           return 0;         }       }     }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 301000, MMax = 200;   int N, A[NMax];   map<int, int> S;   long long sum[NMax];   vector<int> R;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , A + i);       S[A[i]] = max(S[A[i]], i);       if (A[i] >= 0)         sum[i] = sum[i - 1] + A[i];       else         sum[i] = sum[i - 1];     }     long long maxx = -(~0uLL >> 1);     pair<int, int> ans;     for (int i = 1; i <= N; i++) {       int t = S[A[i]];       if (t > i) {         long long first = sum[t] - sum[i - 1];         if (A[i] < 0) first += (long long)A[i] * 2;         if (first > maxx) {           maxx = first;           ans = make_pair(i, t);         }       }     }     printf( %I64d  , maxx);     for (int i = 1; i < ans.first; i++) R.push_back(i);     for (int i = ans.first + 1; i < ans.second; i++)       if (A[i] < 0) R.push_back(i);     for (int i = ans.second + 1; i <= N; i++) R.push_back(i);     printf( %d n , (int)R.size());     for (int i = 0; i < R.size(); i++) printf( %d  , R[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long toInt(string s) {     long v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   inline T sqr(T x) {     return x * x;   }   long long pw(long long x, long long y) {     long long ans = 1;     for (long long i = 0; i < y; i++) {       ans = ans * x;     }     return ans;   }   long long factorial(long long x) {     long long ans = 1;     for (int i = 1; i < x + 1; i++) {       ans = ans * i;     }     return ans;   }   long long combination(long long x, long long y) {     return factorial(x) / factorial(y) / factorial(x - y);   }   long long permutation(long long x, long long y) {     return factorial(x) / factorial(x - y);   }   string flip(string s) {     string ss;     for (int i = 0; i < s.size(); i++) {       ss = toString(s[i]) + ss;     }     return ss;   }   long long mod(long long a, long long b) {     if (a % b == 0) {       return 0;     } else {       return a % b;     }   }   int main() {     long long n;     cin >> n;     vector<long long> v(n);     long long a, b;     for (long long i = 0; i < n - 1; i++) {       cin >> a >> b;       v[a - 1]++;       v[b - 1]++;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (v[i] >= 2) {         ans += combination(v[i], 2);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int deg[200040], erased[200500], depth[200040];   void dfs(int x, int d, vector<vector<int>>& adj, int pa) {     for (auto u : adj[x])       if (u != pa) dfs(u, d + 1, adj, x);     depth[x] = d;   }   int main() {     int n;     cin >> n;     vector<vector<int>> adj(n + 1);     int root;     for (int i = 1; i <= n; i++) {       int p;       cin >> p;       if (p == 0) {         root = i;         continue;       }       adj[p].push_back(i);       adj[i].push_back(p);       deg[i]++;       deg[p]++;     }     dfs(root, 0, adj, 0);     set<pair<int, int>> S;     for (int i = 1; i <= n; i++) {       if (deg[i] % 2 == 0) S.insert({-depth[i], i});     }     vector<int> res;     while (!S.empty()) {       int x = (*S.begin()).second;       S.erase({-depth[x], x});       erased[x] = 1;       for (auto u : adj[x]) {         if (erased[u]) continue;         deg[u]--;         if (deg[u] % 2 == 0) {           S.insert({-depth[u], u});         } else           S.erase({-depth[u], u});       }       res.push_back(x);     }     if (res.size() != n) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (auto u : res) {       cout << u << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   int main() {     int i, t, mini = 1000000, s, val, tfin;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (t = 1; t <= 105; t++) {       s = 0;       for (i = 1; i <= n; i++) {         val = abs(t + 1 - a[i]);         val = min(val, abs(t - a[i]));         val = min(val, abs(t - 1 - a[i]));         s += val;       }       if (mini > s) {         mini = s;         tfin = t;       }     }     cout << tfin <<     << mini;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long md = 1000000007;   long long bexp(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long r = bexp(a, b / 2);     r = r * r;     if (b % 2 == 0)       return r;     else       return r * a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case--) {       long long n, i, j, m, k;       cin >> n;       long long a[n];       for (i = 0; i < n; i++) {         cin >> a[i];       }       long long pr = -1;       long long ans = 0;       for (i = 0; i < n; i++) {         if (a[i] != 0) {           if (pr == -1) {             pr = i;           } else {             ans += i - pr - 1;             pr = i;           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int P = 998244353;   int n, m, a[N], pre[N], rec[N], f[N];   inline void add(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) x += P;   }   struct BL {     int bel[N], tag[450], w[N], size, cnt, sum[450][N], ans[450];     void init() {       sum[1][0] = ans[1] = 1;       size = sqrt(n);       for (int i = 1; i <= n; ++i) bel[i] = (i - 1) / size + 1;       cnt = bel[n];       for (int i = 1; i <= cnt; ++i) tag[i] = m;     }     void update(int pos, int x) {       int px = bel[pos];       sub(sum[px][w[pos]], f[pos - 1]);       if (w[pos] <= tag[px]) sub(ans[px], f[pos - 1]);       w[pos] = x;       add(sum[px][x], f[pos - 1]);       if (x <= tag[px]) add(ans[px], f[pos - 1]);     }     void ins(int x, int y, int d) {       if (x > y) return;       if (bel[x] + 1 >= bel[y]) {         for (int i = x; i <= y; ++i) update(i, w[i] + d);         return;       }       for (int i = x; i <= bel[x] * size; ++i) update(i, w[i] + d);       for (int i = (bel[y] - 1) * size + 1; i <= y; ++i) update(i, w[i] + d);       for (int i = bel[x] + 1; i <= bel[y] - 1; ++i) {         if (d > 0) sub(ans[i], sum[i][tag[i]]);         tag[i] -= d;         if (d < 0) add(ans[i], sum[i][tag[i]]);       }     }     int qry(int x) {       int res = 0;       for (int i = x; bel[i] == bel[x]; --i)         if (w[i] <= tag[bel[x]]) add(res, f[i - 1]);       for (int i = bel[x] - 1; i >= 1; --i) add(res, ans[i]);       return res;     }   } bl;   int main() {     scanf( %d%d , &n, &m);     bl.init();     f[0] = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       pre[i] = rec[a[i]], rec[a[i]] = i;       bl.ins(pre[pre[i]] + 1, pre[i], -1), bl.ins(pre[i] + 1, i, 1);       f[i] = bl.qry(i);       add(bl.sum[bl.bel[i + 1]][0], f[i]);       add(bl.ans[bl.bel[i + 1]], f[i]);     }     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b <= 0 ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <class T>   T large(T a, T b) {     return a > b ? a : b;   }   template <class T>   T small(T a, T b) {     return a < b ? a : b;   }   template <class T>   T dif(T a, T b) {     return a - b < 0 ? b - a : a - b;   }   template <class T>   string toStr(const T &x) {     stringstream s;     s << x;     return s.str();   }   template <class T>   int toInt(const T &x) {     stringstream s;     s << x;     int r;     s >> r;     return r;   }   void in() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     map<int, vector<pair<int, string> > > m1;     map<int, string> m2;     int n, m, a, b, i;     string s;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> s >> a >> b;       m1[a].push_back(make_pair(b, s));     }     for (i = 0; i < m1.size(); i++) {       sort(m1[i].rbegin(), m1[i].rend());     }     for (auto it : m1) {       for (i = 0; i < it.second.size(); i++) {         if (it.second[1].first == it.second[2].first) {           cout <<  ?  << endl;           break;         } else {           if (i < 1)             cout << it.second[i].second <<     << it.second[i + 1].second << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 1e6;   const int INF = 0x7fffffff;   const int mod = 1e9 + 7;   const double eps = 1e-7;   const double Pi = acos(-1.0);   inline int read_int() {     char c;     int ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   inline long long read_ll() {     char c;     long long ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   int n, res = 1;   string s;   int main() {     cin >> n >> s;     for (int i = 1; i < n; i++) {       res += (s[i] != s[i - 1]);     }     cout << ((res + 2) < (n) ? (res + 2) : (n)) << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main(){    int t;    cin >> t;    while(t--){     int n;     cin >> n;     vector <int> a(n);     int k = INT_MAX,z = -1;     for(int i=0;i<n;i++){      cin >> a[i];      k = min(k,a[i]);      if(k==a[i]){       z = i;      }     }     cout << n-1 << endl;     for(int i=0;i<n;i++){      if(i!=z){       cout << i+1 <<     << z+1 <<     << max(1,k+abs(z-i)) <<     << k << endl;      }     }     //cout << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 999;   vector<int> v[maxn];   vector<pair<int, int> > g[maxn];   int fa[maxn], dep[maxn], siz[maxn], Top[maxn], son[maxn], dfn[maxn], clk;   void dfs1(int x) {     siz[x] = 1;     dfn[x] = ++clk;     for (int y : v[x]) {       if (y == fa[x]) continue;       fa[y] = x;       dep[y] = dep[x] + 1;       dfs1(y);       siz[x] += siz[y];       if (siz[y] > siz[son[x]]) son[x] = y;     }   }   void dfs2(int x, int topf) {     Top[x] = topf;     if (son[x]) dfs2(son[x], topf);     for (int y : v[x]) {       if (y != fa[x] && y != son[x]) dfs2(y, y);     }   }   int LCA(int x, int y) {     while (Top[x] ^ Top[y])       if (dep[Top[x]] < dep[Top[y]])         y = fa[Top[y]];       else         x = fa[Top[x]];     return dep[x] > dep[y] ? y : x;   }   int n, st[maxn], V[maxn], imp[maxn], top, a[maxn], s[maxn];   bool cmp(int x, int y) { return dfn[x] < dfn[y]; }   inline int dis(int x, int y) {     int lca = LCA(x, y);     return dep[x] + dep[y] - 2 * dep[lca];   }   void add(int x, int y) {     int t = dis(x, y);     g[x].push_back(make_pair(y, t));     g[y].push_back(make_pair(x, t));   }   void insert(int x) {     int lca = LCA(x, s[top]);     while (top > 1 && dfn[s[top - 1]] >= dfn[lca]) add(s[top - 1], s[top]), --top;     if (lca != s[top]) add(lca, s[top]), s[top] = lca;     s[++top] = x;   }   struct node {     int x, t, id, d, fl;     friend bool operator<(node a, node b) {       return a.t == b.t ? (a.id == b.id ? a.d > b.d : a.id < b.id) : a.t < b.t;     }   } Dis[maxn];   struct nd {     node first;     int second;     friend bool operator<(nd x, nd y) { return y.first < x.first; }   };   priority_queue<nd> q;   int vis[maxn];   vector<int> tmp;   void dfs3(int x, int faa) {     tmp.push_back(x);     for (auto now : g[x]) {       int y = now.first;       if (y == faa) continue;       dfs3(y, x);     }   }   int n1, n2;   node To(int x, pair<int, int> y) {     node ret = Dis[x];     if (y.second <= ret.d) {       ret.d -= y.second;       return ret;     }     int dist = y.second - ret.d;     ret.t += (dist + V[ret.id] - 1) / V[ret.id];     ret.d = (V[ret.id] * ((dist + V[ret.id] - 1) / V[ret.id]) - dist);     return ret;   }   void dj() {     while (q.size()) q.pop();     for (int i = (1); i <= (n1); ++i)       Dis[st[i]] = node{st[i], 0, i, 0, 1}, q.push(nd{Dis[st[i]], st[i]});     while (q.size()) {       int x = q.top().second;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (auto y : g[x]) {         node t = To(x, y);         if ((!Dis[y.first].fl) || t < Dis[y.first])           Dis[y.first] = t, q.push(nd{Dis[y.first], y.first});       }     }     for (int i = (1); i <= (n2); ++i) cout << Dis[imp[i]].id <<    ;     cout << endl;   }   void init() {     top = 0;     for (int x : tmp) g[x].clear(), vis[x] = 0, Dis[x] = node{0, 0, 0, 0};     tmp.clear();   }   int main() {     cin >> n;     for (int i = (1); i <= (n - 1); ++i) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs1(1);     dfs2(1, 1);     int q;     cin >> q;     while (q--) {       cin >> n1 >> n2;       for (int i = (1); i <= (n1); ++i) cin >> st[i] >> V[i], a[i] = st[i];       for (int i = (1); i <= (n2); ++i) cin >> imp[i], a[i + n1] = imp[i];       sort(a + 1, a + 1 + n1 + n2);       int len = unique(a + 1, a + 1 + n1 + n2) - a - 1;       sort(a + 1, a + 1 + len, cmp);       s[top = 1] = 1;       for (int i = (1); i <= (len); ++i)         if (a[i] != 1) insert(a[i]);       while (top > 1) add(s[top - 1], s[top]), --top;       dj();       dfs3(1, 0);       init();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     map<int, vector<int> > vec;     for (int i = 0; i < a; i++) {       int g;       cin >> g;       vec[g % c].push_back(g);     }     for (int i = 0; i < c; i++) {       if (vec[i].size() >= b) {         cout <<  Yes  << endl;         for (int j = 0; j < b; j++) {           cout << vec[i][j];           if (j != b - 1) {             cout <<    ;           } else {             cout << endl;           }         }         return 0;       }     }     cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-4;   const long double PI = acos((long double)-1.0);   const long long int MOD = 1e9 + 7;   long long int powmod(long long int a, long long int b, long long int mod) {     long long int res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   const int debug = 1;   template <typename T>   void DBG(vector<T> v) {     if (debug) {       for (T t : v) cout << t <<     ;       cout << endl;     }   }   template <typename T>   void DBG(T t) {     if (debug) cout << t << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     cout << fixed;     string s;     cin >> s;     vector<int> counts(26, 0);     for (char c : s) {       counts[c -  a ]++;     }     vector<char> result(s.size(),  . );     for (int prime = 2; prime <= s.size(); prime++) {       bool is_prime = true;       for (int divisor = 2; divisor * divisor <= prime; divisor++) {         if (prime % divisor == 0) {           is_prime = false;           break;         }       }       if (is_prime) {         set<char> se;         for (int i = prime; i <= s.size(); i += prime) {           for (int divisor = 2; divisor * divisor <= i; divisor++) {             if (i % divisor == 0) se.insert(result[divisor - 1]);           }         }         se.erase( . );         if (se.size() > 1) {           cout <<  NO  << endl;           return 0;         }         char c;         if (se.size() == 1) {           char c = *se.begin();         } else {           int m = 0;           for (int k = 0; k < (26); ++k) {             if (counts[m] < counts[k]) m = k;           }           c =  a  + m;         }         for (int i = prime; i <= s.size(); i += prime) {           if (result[i - 1] ==  . ) {             if (!counts[c -  a ]) {               cout <<  NO  << endl;               return 0;             }             counts[c -  a ]--;             result[i - 1] = c;           }         }       }     }     for (int i = 0; i < (26); ++i) {       if (counts[i]) result[0] =  a  + i;     }     DBG( YES );     DBG(string(result.begin(), result.end()));   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   void debugi(vector<int>& vec) {     int n = (int)vec.size();     for (int i = 0; i < n; i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   void debugl(vector<ll>& vec) {     int n = (int)vec.size();     for (int i = 0; i < n; i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   void debugmap(map<int, int>& mp) {     for (auto x : mp) {       cout << x.first <<     << x.second <<   ,  ;     }     cout << endl;   }   void debugset(set<int>& st) {     for (auto x : st) {       cout << x <<    ;     }     cout << endl;   }   void debugparri(vector<pair<int, int>>& arr) {     for (int i = 0; i < (int)arr.size(); i++) {       cout <<  [  << arr[i].first <<   :   << arr[i].second <<  ]             <<    ;     }     cout << endl;   }   void debugpi(pair<int, int>& pi) {     cout << pi.first <<     << pi.second << endl;   }   void debugq(queue<int> q) {     while (!q.empty()) {       cout << q.front() <<    ;       q.pop();     }     cout << endl;   }   ll mod = 1000000007;   bool check(int n, int i, int j) {     if ((0 <= i & i < n) && (0 <= j & j < n)) {       return true;     }     return false;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int tt = 0; tt < t; tt++) {       int n;       cin >> n;       vector<int> arr(n);       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       vector<int> pre(n), suf(n);       int s = 0;       for (int i = 0; i < n; i++) {         if (arr[i] != i + 1) {           s += 1;         }         pre[i] = s;       }       s = 0;       for (int i = n - 1; i >= 0; i--) {         if (arr[i] != i + 1) {           s += 1;         }         suf[i] = s;       }       int cnt = 0;       for (int i = 0; i < n; i++) {         if (pre[i] != 0 && suf[i] != 0 && arr[i] == i + 1) {           cnt += 1;         }       }       if (cnt == 0) {         if (s == 0) {           cout << 0 << endl;           continue;         } else {           cout << 1 << endl;           continue;         }       }       cout << 2 << endl;       continue;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 200;   long long c[N][N], dp[N][N * N + N], g[N][N];   long long modp(long long a, long long b) {     if (b == 0) return 1;     long long u = modp(a, b / 2);     u = (u * u) % mod;     if (b & 1) return (a * u) % mod;     return u;   }   int32_t main() {     long long n, m, o;     cin >> n >> m >> o;     for (long long i = 0; i < N; i++) c[i][0] = dp[i][0] = 1;     for (long long i = 1; i < N; i++)       for (long long j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     for (long long i = 1; i <= n; i++)       for (long long j = 0; j <= n; j++) g[i][j] = modp(c[n][j], (m + n - i) / n);     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n * i; j++)         for (long long k = max(j - n, 0LL); k <= j; k++) {           dp[i][j] = (dp[i][j] + dp[i - 1][k] * g[i][j - k]) % mod;         }     cout << dp[n][o] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1LL * 1001 * 1001 * 1001 * 1001 * 1001 * 1001;   const int N = 10000;   struct edge {     long long a, b, cap, flow;     edge(long long a, long long b, long long cap)         : a(a), b(b), cap(cap), flow(0) {}     long long cap_to(long long u) { return u == b ? cap - flow : flow; }     long long another(long long u) { return u == b ? a : b; }     void add_flow(long long u, long long first) {       flow += (u == b ? first : -first);     }   };   struct dinic_graph {     vector<edge> e;     vector<long long> g[N];     long long pos[N], d[N], p[N];     void add_edge(long long a, long long b, long long c) {       g[a].push_back((int)e.size());       g[b].push_back((int)e.size());       e.push_back(edge(a, b, c));     }     bool bfs(long long S, long long T) {       d[S] = 1;       queue<long long> q;       q.push(S);       while (q.size()) {         long long u = q.front();         q.pop();         if (u == T) return 1;         for (int i = 0; i < g[u].size(); i++) {           long long to = e[g[u][i]].another(u);           if (!d[to] && e[g[u][i]].cap_to(to)) {             d[to] = d[u] + 1;             q.push(to);           }         }       }       return 0;     }     bool dfs(long long u, long long t) {       if (u == t) return 1;       for (; pos[u] < g[u].size(); pos[u]++) {         long long to = e[g[u][pos[u]]].another(u);         if (d[to] == d[u] + 1 && e[g[u][pos[u]]].cap_to(to)) {           p[to] = g[u][pos[u]];           if (dfs(to, t)) return 1;         }       }       return 0;     }     long long dinic(long long S, long long T) {       long long max_flow = 0;       while (1) {         memset(d, 0, sizeof(d));         if (!bfs(S, T)) return max_flow;         memset(pos, 0, sizeof(pos));         while (dfs(S, T)) {           long long cur_f = INF;           for (long long u = T; u != S; u = e[p[u]].another(u))             cur_f = min(cur_f, e[p[u]].cap_to(u));           for (long long u = T; u != S; u = e[p[u]].another(u))             e[p[u]].add_flow(u, cur_f);           max_flow += cur_f;         }       }     }   };   int n, m;   int x1[55], mezhdy[55], x2[55], nami[55];   vector<int> x, y;   dinic_graph g;   bool in(double x, double y, int pos) {     return x >= min(x1[pos], x2[pos]) && x <= max(x1[pos], x2[pos]) &&            y >= min(mezhdy[pos], nami[pos]) && y <= max(mezhdy[pos], nami[pos]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x1[i] >> mezhdy[i] >> x2[i] >> nami[i];       x2[i]++;       nami[i]++;       x.push_back(x1[i]);       x.push_back(x2[i]);       y.push_back(mezhdy[i]);       y.push_back(nami[i]);     }     sort(x.begin(), x.end());     sort(y.begin(), y.end());     x.erase(unique(x.begin(), x.end()), x.end());     y.erase(unique(y.begin(), y.end()), y.end());     int S = 0;     int T = (int)x.size() + (int)y.size() + 1;     for (int i = 1; i < x.size(); i++) g.add_edge(S, i, x[i] - x[i - 1]);     for (int i = 1; i < y.size(); i++)       g.add_edge(i + x.size(), T, y[i] - y[i - 1]);     for (int i = 1; i < x.size(); i++)       for (int j = 1; j < y.size(); j++) {         double xx = 1.0 * (x[i] + x[i - 1]) / 2;         double yy = 1.0 * (y[j] + y[j - 1]) / 2;         bool ok = 0;         for (int p = 0; p < m; p++)           if (in(xx, yy, p)) ok = 1;         if (ok) g.add_edge(i, j + x.size(), INF);       }     cout << g.dinic(S, T);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     if (abs(a) + abs(b) <= n) {       if ((n - abs(a) - abs(b)) % 2 == 0)         cout <<  Yes ;       else         cout <<  No ;     } else {       cout <<  No ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, now;   int a[3005], b[3005];   int vis[3005], f[3005], c[3005];   int ok[3005];   int findcir(int *a, int n) {     int ret = 0;     for (int i = 1; i <= n; i++) b[a[i]] = i;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int j;       ret++;       for (j = i; !vis[j]; j = b[j]) {         f[j] = ret;         vis[j] = 1;         c[ret]++;       }     }     return ret;   }   void Swap(int x) {     if (!x) return;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (f[i] == f[j]) {           printf( %d %d  , i, j);           x--;           if (!x) return;           swap(a[i], a[j]);           findcir(a, n);         }   }   void move(int x) {     if (!x) return;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (f[i] != f[j]) {           printf( %d %d  , i, j);           x--;           if (!x) return;           swap(a[i], a[j]);           findcir(a, n);         }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     now = findcir(a, n);     now = n - now;     scanf( %d , &m);     printf( %d n , abs(now - m));     if (now > m) {       Swap(now - m);     } else       move(m - now);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   set<long long> s;   set<int> si;   set<long long>::iterator it;   vector<long long> v;   vector<int> vi;   int n, m, q, k;   int a[200005];   int main() {     int i, j, t;     int w, h;     ;     scanf( %d%d , &w, &h);     ;     int u1, d1, u2, d2;     ;     scanf( %d%d , &u1, &d1);     ;     ;     scanf( %d%d , &u2, &d2);     ;     for (i = h; i >= 0; i--) {       w = w + i;       if (d1 == i) w -= u1;       if (d2 == i) w -= u2;       w = max(0, w);     }     printf( %d n , w);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int n, x;   vector<int> a;   long long int tarkib(long long int r, long long int n) {     long long int a = 1;     for (long long int i = n; i > (n - r); i--) a = a * i;     for (long long int i = 2; i < r + 1; i++) a = a / i;     return a;   }   int main() {     long long int r;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     long long int i;     for (i = 3; i < n; i++) {       if (a[i] > a[i - 1]) break;     }     i--;     i--;     if (a[0] == a[1]) {       if (a[1] == a[2]) {         r = 3;         i += 2;       } else {         r = 1;       }     } else {       if (a[1] == a[2]) {         i++;         r = 2;       } else {         r = 1;       }     }     cout << tarkib(r, i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     if (n <= 450 and m == n * (n - 1) / 2) {       cout <<  NO n ;       return 0;     }     vector<set<int>> g(n + 1);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       g[u].insert(v);       g[v].insert(u);     }     int x = -1, y = -1;     for (int i = 1; i <= n and x == -1; ++i) {       if ((int)g[i].size() == n - 1) continue;       for (int j = 1; j <= n and x == -1; ++j) {         if (i == j) continue;         if (g[i].find(j) == g[i].end()) tie(x, y) = tie(i, j);       }     }     vector<int> v1, v2;     int cur = 3;     for (int i = 1; i <= n; ++i) {       if (i == x) {         v1.push_back(1);         v2.push_back(1);       } else if (i == y) {         v1.push_back(2);         v2.push_back(1);       } else {         v2.push_back(cur);         v1.push_back(cur++);       }     }     cout <<  YES n ;     for (auto x : v1) cout << x <<    ;     cout <<   n ;     for (auto x : v2) cout << x <<    ;   }


#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   const long long maxn = 1e5 + 7;   const double pi = acos(-1);   using namespace std;   long long t, n, m;   long long hang;   long long weizhi;   long long temp;   long long four = 1;   long long weishu;   long long weishu2;   long long lie;   int ans[50];   map<int, int> MP;   long long cal() {     long long res = 0;     long long a = 1;     weishu2 = weishu;     for (int i = weishu2; i >= 1; i--) {       res += a * ans[i];       a <<= 2;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     MP[1] = 2;     MP[2] = 3;     MP[3] = 1;     cin >> t;     while (t--) {       memset(ans, 0, sizeof(ans));       weishu = 1;       four = 1;       cin >> n;       hang = (n - 1) / 3 + 1;       while (hang > four) {         hang -= four;         four <<= 2;         weishu++;       }       if (n % 3 == 0) {         lie = 3;       } else {         lie = n % 3;       }       weishu2 = weishu;       temp = hang - 1;       while (temp) {         ans[weishu2--] = temp % 4;         temp >>= 2;       }       ans[1] = 1;       if (lie == 2) {         for (int i = 1; i <= weishu; i++) {           ans[i] = MP[ans[i]];         }       } else if (lie == 3) {         for (int i = 1; i <= weishu; i++) {           ans[i] = MP[ans[i]];           ans[i] = MP[ans[i]];         }       }       cout << cal() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = LLONG_MAX;   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long power(long long x, unsigned long long y) {     long long res = 1;     x = x % MOD;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % MOD;       y = y >> 1;       x = (x * x) % MOD;     }     return res;   }   void solve() {     long long n, m, b, c, d, ans = 0, one = 0;     cin >> n;     long long a[n];     for (long long i = (long long)0; i < n; i++) {       cin >> a[i];       if (a[i] >= 2 * one) {         a[i] -= 2 * one;         ans += one + a[i] / 3;         one = a[i] % 3;       } else {         one += a[i] % 2;         one -= a[i] / 2;         ans += a[i] / 2;       }     }     cout << ans <<   n ;   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, n, hold;     cin >> t;     while (t--) {       bool ans = false;       cin >> n;       long long int x;       for (long long int i = 0; i < n; i++) {         cin >> hold;         if (i == 0) x = hold;         if (x != hold) ans = true;       }       if (ans)         cout << 1 << endl;       else         cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 200005;   vector<long long> byk[MAXN];   long long pangkat(long long x, long long y) {     long long ret = 1;     for (long long i = 1; i <= y; i++) ret *= x;     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, a;     cin >> n;     for (long long no = 1; no <= n; no++) {       cin >> a;       for (long long i = 2; i * i <= a; i++) {         long long pa = 0;         while (a % i == 0) {           pa++;           a /= i;         }         if (pa) byk[i].push_back(pa);       }       if (a > 1) byk[a].push_back(1);     }     long long ans = 1;     for (long long i = 1; i <= 200000; i++) {       if (byk[i].size() > n - 2) {         sort(byk[i].begin(), byk[i].end());         if (byk[i].size() == n - 1)           ans *= pangkat(i, byk[i][0]);         else           ans *= pangkat(i, byk[i][1]);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   long long mpow(long long a, long long n, long long mod) {     long long ret = 1;     long long b = a;     while (n) {       if (n & 1) ret = (ret * b) % mod;       b = (b * b) % mod;       n >>= 1;     }     return (long long)ret;   }   using namespace std;   int n, m, s;   pair<int, int> bug[(int)(1e5 + 25)];   int ANS[(int)(1e5 + 25)];   pair<pair<int, int>, int> ch[(int)(1e5 + 25)];   bool chk(int x) {     priority_queue<pair<int, int> > pq;     long long ans = 0;     int last = m;     for (int i = n; i >= 1;) {       int j = i;       while (j > 0 && ch[j].first.first >= bug[last].first) {         pq.push(make_pair(-ch[j].first.second, ch[j].second));         j--;       }       i = j;       if (j == 0) {         break;       }       if (pq.empty()) {         return 0;       }       pair<int, int> temp = pq.top();       pq.pop();       int dum = x;       ans += (-temp.first);       while (last > 0 && dum > 0) {         ANS[bug[last].second] = temp.second;         dum--;         last--;       }       if (last <= 0) {         break;       }     }     while (last > 0) {       if (pq.empty()) {         return 0;       }       pair<int, int> temp = pq.top();       pq.pop();       int dum = x;       ans += (-temp.first);       while (last > 0 && dum > 0) {         ANS[bug[last].second] = temp.second;         dum--;         last--;       }     }     return (ans <= s);   }   void solve() {     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &s);     for (int i = 1; i <= m; i++) {       scanf( %d , &bug[i].first);       bug[i].second = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &ch[i].first.first);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &ch[i].first.second);       ch[i].second = i;     }     sort(bug + 1, bug + m + 1);     sort(ch + 1, ch + n + 1);     int lo = 1, hi = m;     while (lo < hi) {       int mid = (lo + hi) >> 1;       if (chk(mid)) {         hi = mid;       } else {         lo = mid + 1;       }     }     if (!chk(lo)) {       printf( NO );       return;     }     printf( YES n );     for (int i = 1; i <= m; i++) {       cout << ANS[i] <<    ;     }   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int dir8[8][2] = {{-1, 0}, {1, 0},  {0, 1}, {0, -1},                     {-1, 1}, {1, -1}, {1, 1}, {-1, -1}};   int dir8h[8][2] = {{2, 1}, {-2, -1}, {-1, 2}, {1, -2},                      {1, 2}, {-2, 1},  {2, -1}, {-1, -2}};   int setbit(int num, int index, int value) {     return (value) ? (num | (1 << index)) : (num & ~(1 << index));   }   bool getbit(int num, int index) { return ((num >> index) & 1) == 1; }   int cntbits(int num) {     int cnt = 0;     while (num) {       if (num & 1) cnt++;       num /= 2;     }     return cnt;   }   double eps = 1e-8;   const int N = 1e5 + 100;   vector<int> v[N];   bool a[N], can[N];   int root;   bool dfs(int node, int pa) {     if (node != root && v[node].size() == 1) {       if (a[node]) {         can[node] = 1;         return 1;       } else {         can[node] = 0;         return 0;       }     } else {       if (a[node])         can[node] = 1;       else         can[node] = 0;       for (int i = 0; i < v[node].size(); i++) {         if (v[node][i] != pa) {           bool x = dfs(v[node][i], node);           if (!x) can[node] = 0;         }       }       if (a[node]) return 1;       return 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     int n, p, c;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p >> c;       a[i] = c;       if (p != -1)         v[p].push_back(i), v[i].push_back(p);       else         root = i;     }     bool cc = dfs(root, -1);     vector<int> res;     for (int i = 1; i <= n; i++) {       if (can[i]) res.push_back(i);     }     if (res.size() > 0) {       for (int i = 0; i < res.size(); i++) cout << res[i] <<    ;     } else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 51;   const long long inf = (long long)1e14;   const long long real_inf = (long long)1e18;   inline long long value(const pair<long long, long long>& task, long long t) {     return task.first - t * task.second;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<long long, long long>> tasks(n);     for (int i = 0; i < n; ++i) {       cin >> tasks[i].first;       tasks[i].first *= 1000;     }     for (int i = 0; i < n; ++i) {       cin >> tasks[i].second;     }     sort(tasks.begin(), tasks.end());     reverse(tasks.begin(), tasks.end());     auto ok = [&](long long t) -> bool {       long long dp[N][N][N];       for (int i = 0; i < n; ++i) {         for (int j = 0; j <= n; ++j) {           for (int k = 0; k <= n; ++k) {             dp[i][j][k] = real_inf;           }         }       }       dp[0][0][1] = value(tasks[0], t);       for (int i = 0; i < n - 1; ++i) {         for (int j = 0; j <= n; ++j) {           for (int k = 0; k <= n; ++k) {             if (dp[i][j][k] == real_inf) {               continue;             }             if (tasks[i].first == tasks[i + 1].first) {               dp[i + 1][j][k + 1] =                   min(dp[i + 1][j][k + 1], dp[i][j][k] + value(tasks[i + 1], t));               if (j > 0) {                 dp[i + 1][j - 1][k] = min(dp[i + 1][j - 1][k], dp[i][j][k]);               }             } else {               dp[i + 1][j + k][1] =                   min(dp[i + 1][j + k][1], dp[i][j][k] + value(tasks[i + 1], t));               if (j > 0 || k > 0) {                 dp[i + 1][j + k - 1][0] =                     min(dp[i + 1][j + k - 1][0], dp[i][j][k]);               }             }           }         }       }       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= n; ++j) {           if (dp[n - 1][i][j] <= 0) {             return true;           }         }       }       return false;     };     long long left = 0, right = inf, best = inf;     while (left <= right) {       long long middle = (left + right) / 2;       if (ok(middle)) {         best = middle;         right = middle - 1;       } else {         left = middle + 1;       }     }     cout << best <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int power(int num1, int num2) {     int ans = 1;     for (int i = 0; i < num2; i++) {       ans *= num1;     }     return ans;   }   int main() {     string str;     int num1, help = 0;     cin >> num1 >> str;     for (int i = 0; i < str.size(); i++) {       help += power(10, i) * (str[i] -  0 );     }     cout << help + num1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   vector<int> G[MAXN + 5];   int maxFrom[MAXN + 5], down[MAXN + 5], up[MAXN + 5];   int id[MAXN + 5], sz[MAXN + 5], diam[MAXN + 5];   bool flag[MAXN + 5];   int ID;   int n, m, Q;   map<int, int> cnt;   vector<int> accSum[MAXN + 5];   vector<double> accWeightedSum[MAXN + 5];   vector<int> vals[MAXN + 5];   map<pair<int, int>, double> oldAns;   void dfs(int u, int p = -1) {     id[u] = ID;     sz[ID]++;     down[u] = 0;     flag[u] = 1;     for (int v : G[u]) {       if (v == p) continue;       dfs(v, u);       down[u] = max(down[u], 1 + down[v]);     }   }   void dfs2(int u, int p = -1, int parentWithoutme = 0) {     if (~p)       up[u] = 1 + parentWithoutme;     else       up[u] = 0;     maxFrom[u] = max(up[u], down[u]);     diam[ID] = max(diam[ID], maxFrom[u]);     cnt[maxFrom[u]]++;     vector<int> paths = {up[u], 0};     for (int v : G[u]) {       if (v == p) continue;       paths[1] = max(paths[1], 1 + down[v]);       if (paths[0] < paths[1]) swap(paths[0], paths[1]);     }     for (int v : G[u]) {       if (v == p) continue;       dfs2(v, u, ((paths[0] != (1 + down[v])) ? paths[0] : paths[1]));     }   }   void calc(int u) {     cnt.clear();     ID = u;     dfs(u);     dfs2(u);     accSum[ID].resize(cnt.size() + 1);     accWeightedSum[ID].resize(cnt.size() + 1);     accSum[ID][0] = 0;     accWeightedSum[ID][0] = 0;     int i = 0;     for (auto p : cnt) {       vals[ID].push_back(p.first);       accSum[ID][i + 1] = accSum[ID][i] + p.second;       accWeightedSum[ID][i + 1] =           accWeightedSum[ID][i] + p.first * (1. * p.second / sz[ID]);       i++;     }   }   int main() {     int c, c2;     scanf( %d%d%d , &n, &m, &Q);     for (c = 0; c < m; c++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       G[u].push_back(v);       G[v].push_back(u);     }     for (c = 0; c < n; c++) {       if (flag[c]) continue;       calc(c);     }     for (c = 0; c < Q; c++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       if (id[u] == id[v])         printf( -1 n );       else {         if (id[u] > id[v]) swap(u, v);         if (oldAns.count({id[u], id[v]}) > 0) {           printf( %.9f n , oldAns[{id[u], id[v]}]);         } else {           if (sz[id[u]] > sz[id[v]]) swap(u, v);           int minDiam = max(diam[id[u]], diam[id[v]]);           double ret = 0;           int j = 0;           for (int x : vals[id[u]]) {             int i =                 lower_bound(vals[id[v]].begin(), vals[id[v]].end(), minDiam - x) -                 vals[id[v]].begin();             double f = 1. * (accSum[id[u]][j + 1] - accSum[id[u]][j]) / sz[id[u]];             ret += f * (accWeightedSum[id[v]].back() - accWeightedSum[id[v]][i] +                         (x + 1.0) * (sz[id[v]] - accSum[id[v]][i]) / sz[id[v]]);             ret += f * (1. * accSum[id[v]][i] / sz[id[v]]) * minDiam;             j++;           }           if (id[u] > id[v]) swap(u, v);           oldAns[{id[u], id[v]}] = ret;           printf( %.9f n , ret);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int main() {     int n, k, x;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     bool yes = true;     for (int i = 0; i < n; i++)       if (a[i] < k) {         yes = false;         break;       }     while (!yes) {       for (int i = 0; i < n; i++)         if ((a[i] < a[i + 1] || i == n - 1) && a[i] < k) a[i]++;       yes = true;       for (int i = 0; i < n; i++)         if (a[i] < k) {           yes = false;           break;         }       ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[300005] = {0};   long long two[300005] = {0};   const long long mod = 1e9 + 7;   int main() {     two[0] = 1;     for (int i = 1; i <= 300000; i++) {       two[i] = (two[i - 1] * 2LL) % mod;     }     long long res = 0;     int n;     while (cin >> n) {       a[0] = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       sort(a, a + n + 1);       res = 0;       for (int i = 1; i <= n; i++) {         res += (a[i] * (two[i - 1] - two[n - i]));         res %= mod;       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     int N, M;     cin >> N >> M;     vector<string> data(N);     for (int i = 0; i < N; i++) cin >> data[i];     vector<string> data_rev(M, string(N,  . ));     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) data_rev[j][i] = data[i][j];     vector<vector<int> > starts(M);     for (int i = 0; i < M; i++) {       starts[i].push_back(0);       for (int j = 1; j < N; j++) {         if (data_rev[i][j] != data_rev[i][j - 1]) {           starts[i].push_back(j);         }       }       starts[i].push_back(N);     }     vector<vector<short> > already_counted(starts.size());     for (size_t i = 0; i < starts.size(); i++) {       already_counted[i] = vector<short>(starts[i].size(), (short)0);     }     long long main_res = 0LL;     for (int i = 0; i < M; i++) {       for (size_t j = 3; j < starts[i].size(); j++) {         if (!already_counted[i][j - 1]) {           int h = starts[i][j - 1] - starts[i][j - 2];           if (h <= starts[i][j] - starts[i][j - 1] &&               h <= starts[i][j - 2] - starts[i][j - 3]) {             int i_after_last = i + 1;             while (i_after_last < M) {               int j_absolute_1 = starts[i][j - 1];               int j_absolute_2 = starts[i][j - 2];               int j_absolute_3 = starts[i][j - 2] - 1;               if (data_rev[i][j_absolute_1] !=                       data_rev[i_after_last][j_absolute_1] ||                   data_rev[i][j_absolute_2] !=                       data_rev[i_after_last][j_absolute_2] ||                   data_rev[i][j_absolute_3] !=                       data_rev[i_after_last][j_absolute_3]) {                 break;               }               int idx_ =                   lower_bound(starts[i_after_last].begin(),                               starts[i_after_last].end(), starts[i][j - 1]) -                   starts[i_after_last].begin();               if (idx_ < starts[i_after_last].size() &&                   starts[i_after_last][idx_] == starts[i][j - 1] &&                   starts[i_after_last][idx_ - 1] == starts[i][j - 2] &&                   h <= starts[i_after_last][idx_ - 1] -                            starts[i_after_last][idx_ - 2] &&                   h <= starts[i_after_last][idx_ + 1] -                            starts[i_after_last][idx_]) {                 already_counted[i_after_last][idx_] = (short)1;                 i_after_last++;               } else                 break;             }             int sz = (i_after_last - i);             main_res += (sz * (sz + 1)) / 2;           }         }       }     }     cout << main_res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     while (~scanf( %d%d%d%d , &a, &b, &c, &d)) {       int t = d - c;       if (c - b == t && b - a == t) {         printf( %d n , d + t);       } else if (a != 0 && b != 0 && c != 0 && d != 0 && b * b == a * c &&                  c * c == b * d && d * d % c == 0) {         printf( %d n , d * d / c);       } else         printf( 42 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, d;   long long k, now;   int a[1005][1005];   void Dfs(int u, int i) {     if (a[u][i] == k) {       a[u][i] = 0;       a[u][i + 1]++;       Dfs(u, i + 1);     }   }   int main() {     n = read();     k = read();     d = read();     int t = n;     for (int i = 1; i <= d; i++) t = t / k + (int)(t % k > 0);     memset(a, 0, sizeof(a));     if (t == 1) {       for (int u = 2; u <= n; u++) {         for (int i = 1; i <= d; i++) a[u][i] = a[u - 1][i];         a[u][1] += 1;         Dfs(u, 1);       }       for (int i = 1; i <= d; i++) {         for (int j = 1; j <= n; j++) printf( %d  , a[j][i] + 1);         puts(  );       }     } else       puts( -1 );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int t, n, m;   int tot;   int op[1005 * 1005 * 3][7];   string s;   int a[1005][1005];   int p[1005][1005];   int sum;   void check(int x1, int x2, int x3, int x4, int x, int y, int add) {     sum = x1 + x2 + x3 + x4;     if (!sum) return;     if (sum == 1) {       if (x3 != 1) p[x][y + 1] += add;       if (x2 != 1) p[x + 1][y] += add;       if (x4 != 1) p[x][y] += add;       if (x1 != 1) p[x + 1][y + 1] += add;       return;     }     if (sum == 2) {       if (x3 == 1) p[x][y + 1] += add;       if (x2 == 1) p[x + 1][y] += add;       if (x4 == 1) p[x][y] += add;       if (x1 == 1) p[x + 1][y + 1] += add;       return;     }     if (sum == 3) {       if (x3 != 1) p[x][y + 1] += add;       if (x2 != 1) p[x + 1][y] += add;       if (x4 != 1) p[x][y] += add;       if (x1 != 1) p[x + 1][y + 1] += add;       return;     }     if (sum == 4) {       p[x][y + 1] += add;       p[x + 1][y] += add;       p[x + 1][y + 1] += add;       p[x][y] += add;       return;     }   }   namespace solve1 {   void main() {     for (int i = 1; i < n; i += 2)       for (int j = 1; j < m; j += 2)         check(a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1], i, j, 1);     return;   }   }  // namespace solve1   namespace solve2 {   void main() {     for (int i = 1; i < n; i += 2)       for (int j = 1; j < m; j += 2)         check(a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1], i, j, 1);     for (int j = 1; j < m; j += 2)       check(0, 0, a[n][j], a[n][j + 1], n - 1, j, 10000);     return;   }   }  // namespace solve2   namespace solve3 {   void main() {     for (int i = 1; i < n; i += 2)       for (int j = 1; j < m; j += 2)         check(a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1], i, j, 1);     for (int i = 1; i < n; i += 2)       check(0, a[i][m], 0, a[i + 1][m], i, m - 1, 100);     return;   }   }  // namespace solve3   namespace solve4 {   void main() {     for (int i = 1; i < n; i += 2)       for (int j = 1; j < m; j += 2)         check(a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1], i, j, 1);     for (int j = 1; j <= m - 2; j += 2)       check(0, 0, a[n][j], a[n][j + 1], n - 1, j, 10000);     for (int i = 1; i <= n - 2; i += 2)       check(0, a[i][m], 0, a[i + 1][m], i, m - 1, 100);     check(0, 0, 0, a[n][m], n - 1, m - 1, 1000000);     return;   }   }  // namespace solve4   void Print(int x, int y) {     if (x % 2 == 1 && y % 2 == 1)       printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y + 1);     if (x % 2 == 0 && y % 2 == 1)       printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y + 1);     if (x % 2 == 1 && y % 2 == 0)       printf( %d %d %d %d %d %d n , x, y, x, y - 1, x + 1, y);     if (x % 2 == 0 && y % 2 == 0)       printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y - 1);   }   void pRint(int x, int y) {     if (y == m - 1) {       if (x % 2 == 1)         printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y + 1);       else         printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y + 1);     } else {       if (x % 2 == 1)         printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y - 1);       else         printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y - 1);     }   }   void prInt(int x, int y) {     if (x == n - 1) {       if (y % 2 == 1)         printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y + 1);       else         printf( %d %d %d %d %d %d n , x, y, x, y - 1, x + 1, y);     } else {       if (y % 2 == 1)         printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y + 1);       else         printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y - 1);     }   }   void priNt(int x, int y) {     if (x == n - 1 && y == m - 1)       printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y + 1);     if (x == n - 1 && y == m)       printf( %d %d %d %d %d %d n , x, y, x + 1, y, x, y - 1);     if (x == n && y == m - 1)       printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y + 1);     if (x == n && y == m) printf( %d %d %d %d %d %d n , x, y, x - 1, y, x, y - 1);   }   void print() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if ((p[i][j] % 100) & 1) tot++;         if ((p[i][j] / 100) & 1) tot++;         if ((p[i][j] / 10000) & 1) tot++;         if ((p[i][j] / 1000000) & 1) tot++;       }     printf( %d n , tot);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if ((p[i][j] % 100) & 1) Print(i, j);         if ((p[i][j] / 100) & 1) pRint(i, j);         if ((p[i][j] / 10000) & 1) prInt(i, j);         if ((p[i][j] / 1000000) & 1) priNt(i, j);       }   }   int main() {     scanf( %d , &t);     while (t--) {       memset(p, 0, sizeof p);       tot = 0;       scanf( %d %d , &n, &m);       for (int i = 1; i <= n; i++) {         cin >> s;         for (int j = 0; j < m; j++) a[i][j + 1] = (s[j] ==  1 );       }       if (n % 2 == 0 && m % 2 == 0) solve1::main();       if (n % 2 == 1 && m % 2 == 0) solve2::main();       if (n % 2 == 0 && m % 2 == 1) solve3::main();       if (n % 2 == 1 && m % 2 == 1) solve4::main();       print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long bin(long long l, long long h) {     long long ans;     while (l <= h) {       long long mid = (l + h) / 2;       if (n - (mid * (mid + 1)) / 2 <= 0) {         ans = mid;         h = mid - 1;       } else         l = mid + 1;     }     return ans;   }   int main() {     long long p = 1414213562;     cin >> n >> m;     if (m >= n) {       cout << n << endl;       return 0;     }     long long ans = m;     n -= m;     long long ans2 = bin(1, p);     ans += ans2;     cout << ans << endl;   }


#include <bits/stdc++.h>   int main() {     char c;     std::set<char> s;     while (std::cin >> c) {       if ((c >=  a ) && (c <=  z )) {         s.insert(c);       }     }     std::cout << s.size() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char c;   string s;   set<char> q;   int i, sum;   int main() {     getline(cin, s);     for (i = 0; i < s.size(); i++)       if (isalpha(s[i])) q.insert(s[i]);     cout << q.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> mas;   int n, m;   void input() {     cin >> n >> m;     mas.clear();     mas.resize(n);     for (int i = 0; i < n; ++i) cin >> mas[i];   }   void solve() {     string ans = mas[0];     for (int i = 0; i < m; ++i) {       char save = ans[i];       for (char d =  a ; d <=  z ; d++) {         ans[i] = d;         bool f = 1;         for (int j = 0; j < n; ++j) {           int err = 0;           for (int c = 0; c < m; ++c) {             if (ans[c] != mas[j][c]) err++;           }           if (err > 1) {             f = 0;             break;           }         }         if (f) {           cout << ans <<   n ;           return;         }       }       ans[i] = save;     }     cout <<  -1 n ;   }   int main() {     int Q;     cin >> Q;     while (Q--) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> roda(int f, vector<int> valores) {     vector<int> temp(valores);     if (f == 0) {       temp[17] = valores[5];       temp[18] = valores[6];       temp[21] = valores[17];       temp[22] = valores[18];       temp[13] = valores[21];       temp[14] = valores[22];       temp[5] = valores[13];       temp[6] = valores[14];     } else if (f == 1) {       temp[3] = valores[17];       temp[4] = valores[19];       temp[16] = valores[3];       temp[14] = valores[4];       temp[10] = valores[16];       temp[9] = valores[14];       temp[17] = valores[10];       temp[19] = valores[9];     } else if (f == 2) {       temp[20] = valores[7];       temp[19] = valores[8];       temp[24] = valores[20];       temp[23] = valores[19];       temp[15] = valores[24];       temp[16] = valores[23];       temp[7] = valores[15];       temp[8] = valores[16];     } else if (f == 3) {       temp[1] = valores[24];       temp[3] = valores[22];       temp[5] = valores[1];       temp[7] = valores[3];       temp[9] = valores[5];       temp[11] = valores[7];       temp[24] = valores[9];       temp[22] = valores[11];     } else if (f == 4) {       temp[2] = valores[23];       temp[4] = valores[21];       temp[6] = valores[6];       temp[8] = valores[8];       temp[10] = valores[10];       temp[12] = valores[12];       temp[23] = valores[23];       temp[21] = valores[21];     } else if (f == 5) {       temp[1] = valores[15];       temp[2] = valores[13];       temp[18] = valores[1];       temp[20] = valores[2];       temp[12] = valores[18];       temp[11] = valores[20];       temp[15] = valores[12];       temp[13] = valores[11];     }     return temp;   }   bool checa(vector<int> valores) {     for (int i = 0; i < 6; i++) {       int cor = valores[1 + i * 4];       for (int j = 1; j < 4; j++)         if (valores[1 + i * 4 + j] != cor) return false;     }     return true;   }   int main() {     vector<int> valores(25);     int i;     for (i = 1; i < 25; i++) cin >> valores[i];     int resp = 0;     for (i = 0; i < 6; i++) {       resp = resp || checa(roda(i, valores));       resp = resp || checa(roda(i, roda(i, roda(i, valores))));     }     if (resp)       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const int p = 1e9 + 7;   struct edge {     int l, r, uk;   };   edge a[MAXN];   int dp[4 * MAXN];   int b[MAXN];   int n, m;   void update(int k) {     dp[k] = (dp[k * 2] + dp[k * 2 + 1]) % p;     if (k > 1) update(k / 2);   }   long long getsum(int v, int ll, int rr, int l, int r) {     if (ll > r || rr < l) return 0;     if (ll >= l && rr <= r) return dp[v];     return (getsum(v * 2, ll, (ll + rr) / 2, l, r) +             getsum(v * 2 + 1, (ll + rr) / 2 + 1, rr, l, r)) %            p;   }   bool operator<(edge a, edge b) { return a.r < b.r; }   int binr(int l, int r, int q) {     while (l < r - 1) {       if (b[(l + r) / 2] < q)         l = (l + r) / 2;       else         r = (l + r) / 2;     }     return r;   }   int main() {     int i, size = 1, uk, l;     cin >> n >> m;     while (size < m) {       size *= 2;     }     for (i = 0; i < m; i++) {       cin >> a[i].l >> a[i].r;     }     sort(a, a + m);     b[0] = 0;     b[1] = a[0].r;     uk = 2;     for (i = 1; i < m; i++) {       if (a[i - 1].r != a[i].r) {         b[uk] = a[i].r;         uk++;       }       a[i].uk = uk;     }     dp[size] = 1;     update(size / 2);     int uk1 = 1;     for (i = 0; i < m; i++) {       l = binr(-1, uk - 1, a[i].l);       l++;       if (i != 0 && a[i - 1].r != a[i].r) uk1++;       dp[size + uk1] = (dp[size + uk1] + getsum(1, 1, size, l, uk1)) % p;       update((size + uk1) / 2);     }     uk--;     if (a[m - 1].r != n)       cout << 0;     else       cout << dp[size + uk1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int res = 0, ans = 0;     a[0] = -10;     for (int i = 1; i <= n; i++) {       if (a[i] == a[i - 1] + 1)         res++;       else         res = 0;       ans = max(res, ans);     }     ans = max(ans - 1, 0);     int f1 = 0;     for (int i = 1; i <= n + 1; i++) {       if (a[i] == i) {         f1++;       }     }     int f2 = 0;     for (int i = n; i >= 0; i--) {       if (a[i] == (1000 - n + i)) {         f2++;       }     }     if (f1 >= n || f2 >= n) {       f1 = n;       f2 = n;     }     ans = max(ans, max(f1, f2) - 1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<long int> a[n + 1], b[n + 1];     vector<pair<int, int> > v;     for (int i = 0; i <= n; i++) a[i].resize(m + 1), b[i].resize(m + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> a[i][j];     }     for (int i = 1; i <= n - 1; i++) {       for (int j = 1; j <= m - 1; j++) {         if (a[i][j + 1] == 1 && a[i + 1][j] == 1 && a[i + 1][j + 1] == 1 &&             a[i][j] == 1) {           v.push_back(make_pair(i, j));           b[i][j + 1] = 1;           b[i][j] = 1;           b[i + 1][j] = 1;           b[i + 1][j + 1] = 1;         }       }     }     int ct = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] != b[i][j]) ct = 0;       }     }     if (ct == 0)       cout << -1;     else {       cout << v.size() <<   n ;       for (int i = 0; i < v.size(); i++)         cout << v[i].first <<     << v[i].second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, a, b, m, k, y, z, cos, pos, color;     long long r[5005], c[5005], x[100009];     cin >> n >> m >> k;     for (i = 1; i <= k; i++) {       cin >> cos >> pos >> color;       x[i] = color;       if (cos == 1)         r[pos] = i;       else         c[pos] = i;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         y = max(r[i], c[j]);         cout << x[y] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, swaps = 0;     vector<int> seq;     cin >> n;     seq.resize(n * 2);     for (int i = 0; i < n * 2; i++) cin >> seq[i];     for (int i = 0; i < 2 * n - 1; i += 2) {       int j = i + 1;       while (seq[j] != seq[i]) j++;       for (int k = j; k > i + 1; k--) {         swap(seq[k - 1], seq[k]);         swaps++;       }     }     cout << swaps << endl;   }


#include <bits/stdc++.h>   using namespace std;   char s[2000][2000];   int n, m;   bool h[300][300];   bool v[300][300];   const long long mod = 1000000007;   void get(int x, int y, bool& h, bool& v) {     int cnt = 0;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         if (s[x + i][y + j] ==  O ) cnt++;       }     if (cnt == 5 || cnt == 4 || cnt == 1 || cnt == 0) {       v = h = true;       return;     }     if (cnt == 2 || cnt == 3) {       h = s[x][y] ==  O ;       v = !h;       return;     }     h = (s[x][y + 1] ==  O );     v = !h;   }   long long calc1(int y) {     if (n % 2 != 0) return 0;     for (int i = 0; i < n; i++)       if (!v[i][y]) return 0;     return 1;   }   long long tmp[300];   long long dp[300];   long long calc2(int y) {     if (y + 1 >= m) return 0;     for (int i = 0; i <= n; i++) tmp[i] = 0;     tmp[0] = 1;     for (int i = 0; i < n; i++) {       if (h[i][y] && h[i][y + 1]) {         tmp[i + 1] += tmp[i];         tmp[i + 1] %= mod;       }       if (i < n - 1 && v[i][y] && v[i + 1][y] && v[i + 1][y + 1] && v[i][y + 1]) {         tmp[i + 2] += tmp[i];         tmp[i + 2] %= mod;       }     }     if (calc1(y) && calc1(y + 1)) tmp[n] = (tmp[n] - 1 + mod) % mod;     return tmp[n];   }   int main() {     scanf( %d %d n , &n, &m);     for (int i = 0; i < 4 * n + 1; i++) {       gets(s[i]);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) get(4 * i + 1, 4 * j + 1, h[i][j], v[i][j]);     dp[0] = 1;     for (int i = 0; i < m; i++) {       dp[i + 1] += dp[i] * calc1(i);       dp[i + 2] += dp[i] * calc2(i);       dp[i + 1] %= mod;       dp[i + 2] %= mod;     }     cout << dp[m] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long a[N];   long long dp[N][20];   int main() {     int n, m, k;     cin >> n >> m >> k;     a[0] = 0;     for (int i = 1; i <= m; i++) dp[0][i] = -1e10;     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       for (int j = 1; j <= m; j++) {         if (j == 1)           dp[i][j] = max(a[i] - k, dp[i - 1][m] + a[i] - k);         else           dp[i][j] = dp[i - 1][j - 1] + a[i];         ans = max(ans, dp[i][j]);       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long ar[100100];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     sort(ar, ar + n);     long long dif1 = ar[1] - ar[0], dif2 = -1;     int cnt1 = 0, cnt2 = 0;     if (n == 1) {       cout << -1 << endl;       return 0;     } else if (n == 2) {       if (ar[0] == ar[1]) {         cout << 1 << endl << ar[0];         return 0;       } else {         if ((ar[0] + ar[1]) % 2 == 0) {           cout << 3 << endl                << ar[0] - (ar[1] - ar[0]) <<     << (ar[1] + ar[0]) / 2 <<                    << ar[1] + (ar[1] - ar[0]) << endl;           return 0;         } else {           cout << 2 << endl                << ar[0] - (ar[1] - ar[0]) <<     << ar[1] + (ar[1] - ar[0])                << endl;           return 0;         }       }     } else {       set<long long> nd;       set<long long> ans;       for (int i = 1; i < n; i++) {         nd.insert(ar[i] - ar[i - 1]);       }       if (nd.size() > 2) {         cout << 0 << endl;       } else if (nd.size() == 1) {         ans.insert(ar[0] - (ar[1] - ar[0]));         ans.insert(ar[n - 1] + (ar[1] - ar[0]));         cout << ans.size() << endl;         for (auto it : ans) {           cout << it << endl;         }       } else {         int ls1 = -1, ls2 = -1;         dif1 = *nd.begin();         dif2 = *(++nd.begin());         if (dif1 != 2 * dif2 && dif2 != 2 * dif1) {           cout << 0 << endl;           return 0;         }         for (int i = 1; i < n; i++) {           if (ar[i] - ar[i - 1] == dif1) {             cnt1++;             ls1 = i;           } else {             cnt2++;             ls2 = i;           }         }         if (cnt1 == 1 && dif1 % 2 == 0 && dif1 > dif2) {           cout << 1 << endl;           cout << ar[ls1 - 1] + dif2 << endl;           return 0;         }         if (cnt2 == 1 && dif2 % 2 == 0 && dif1 < dif2) {           cout << 1 << endl;           cout << ar[ls2 - 1] + dif1 << endl;           return 0;         }         cout << 0 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100009], b[100009], s[100009];   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long i, j, n, m, c;     cin >> n >> m >> c;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= m; i++) cin >> b[i], s[i] = (b[i] + s[i - 1]);     long long x = n - m;     for (i = 1; i <= n; i++) {       long long t = min(i, m);       long long g = min(i, min(n + 1 - i, x + 1));       long long y = s[t] - s[max(t - g, 0ll)];       a[i] = (a[i] + y) % c;     }     for (i = 1; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long mas[200004];   long long mas2[200004];   struct ver {     long long abs;     int number;     long long maxabs;     int masnumber;     ver *l;     ver *r;   };   void build(ver *v, int l, int r, long long *m) {     if (l == r) {       v->abs = m[l];       v->number = l;       v->masnumber = l;       v->maxabs = m[l];     } else {       ver *a = new ver;       ver *b = new ver;       v->l = a;       v->r = b;       build(a, l, (l + r) / 2, m);       build(b, (l + r) / 2 + 1, r, m);       if (a->maxabs < b->maxabs) {         v->maxabs = b->maxabs;         v->masnumber = b->masnumber;       } else {         v->maxabs = a->maxabs;         v->masnumber = a->masnumber;       }     }   }   pair<long long, long long> maxver(ver *v, int l, int r, int zl, int zr) {     pair<long long, long long> answer;     answer.first = -100000;     answer.second = 0;     if (l > zr || r < zl)       return answer;     else {       if (zl <= l && r <= zr) {         answer.first = v->maxabs;         answer.second = v->masnumber;         return answer;       } else {         pair<long long, long long> left;         pair<long long, long long> right;         left = maxver(v->l, l, (l + r) / 2, zl, zr);         right = maxver(v->r, (l + r) / 2 + 1, r, zl, zr);         if (left.first < right.first)           return right;         else           return left;       }     }   }   int main() {     ver *root = new ver;     int n, k;     pair<long long, long long> answer;     long long maxans = 0;     answer.first = 0;     answer.second = 0;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> mas[i];     for (int i = 0; i < 200004; i++) mas2[i] = 0;     for (int i = n - k + 1; i <= n; i++) mas2[n - k + 1] += mas[i];     for (int i = n - k; i >= 1; i--) mas2[i] = mas2[i + 1] + mas[i] - mas[i + k];     build(root, 1, n, mas2);     for (int i = 1; i <= n - 2 * k + 1; i++) {       pair<long long, long long> an = maxver(root, 1, n, i + k, n);       if (an.first + mas2[i] > maxans) {         maxans = an.first + mas2[i];         answer.first = i;         answer.second = an.second;       }     }     cout << answer.first <<     << answer.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double x[100000];   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> x[i];     double ans = 0;     for (int i = 1; i <= m; i++) {       int fi, se, we;       cin >> fi >> se >> we;       ans = max(ans, (x[fi] + x[se]) / (double)(we));     }     if (n == 1) {       cout <<  0.0000000000  << endl;       return 0;     }     cout << fixed << setprecision(10) << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       bool b = true, b1 = false, b2 = true, b3 = false;       int sum = 0;       for (int i = 0; i < s.size(); i++) {         sum += (int)s[i] - 48;         int x = (int)s[i] - 48;         if (x % 2 == 0) {           if (x != 0) b3 = true;           if (x == 0 && b2 == false) b3 = true;         }         if (s[i] ==  0  && b2) {           b1 = true;           b2 = false;         }       }       if (sum % 3 == 0 && b1 && b3)         cout <<  red  << endl;       else         cout <<  cyan  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;   char ch;   string ss =   , str =   ;   long long a[200003], b[200003];   long long pref[200003];   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;     for (i = 0; i < 26; i++) cin >> a[i];     cin >> ss;     n = ss.length();     pref[1] = a[ss[0] -  a ];     for (i = 1; i < n; i++) pref[i + 1] = pref[i] + a[ss[i] -  a ];     vector<long long> v[26];     for (i = 0; i < n; i++) v[ss[i] -  a ].push_back(i + 1);     for (i = 0; i < 26; i++) {       m = v[i].size();       if (m <= 1) continue;       y = 0;       vector<long long> diff;       for (auto h : v[i]) diff.push_back(pref[h - 1]);       map<long long, long long> mp;       for (j = 0; j < diff.size(); j++) {         ans += mp[diff[j] - a[i]];         mp[diff[j]]++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long maps[105][105];   int main() {     long long a, b, c, d, i, j, k, l, t, n, m;     scanf( %lld , &t);     while (t--) {       scanf( %lld , &a);       for (i = 2; i * i <= a; i++) {         if (a % i) {           b = a % i;           c = a - b;           break;         }       }       printf( %lld %lld n , i, c);     }   }


#include <bits/stdc++.h>   int main() {     int64_t n;     std::cin >> n;     int64_t total(0), smallestOdd(0);     while (n--) {       int64_t x;       std::cin >> x;       total += x;       if ((x % 2) && (smallestOdd == 0 || x < smallestOdd)) {         smallestOdd = x;       }     }     if (total % 2) {       total -= smallestOdd;     }     std::cout << total << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1.0);   long long int inf = 0x3f3f3f3f3f3f3f3f;   const long long int mod = 1e9 + 7;   const long long int mx = 5 * 1000000;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, T, a, b;       cin >> n >> T >> a >> b;       long long int type[n + 1];       for (long long int i = 0; i < n; i++) cin >> type[i];       vector<long long int> easy, hard;       vector<long long int> seq;       seq.push_back(0);       set<long long int> ss;       for (long long int i = 0; i < n; i++) {         long long int in;         cin >> in;         ss.insert(in);         if (type[i] == 0)           easy.push_back(in);         else           hard.push_back(in);       }       for (auto i : ss) seq.push_back(max(i - 1, 0ll));       seq.push_back(T);       sort(easy.begin(), easy.end());       sort(hard.begin(), hard.end());       long long int ans = 0;       for (auto i : seq) {         auto ee = upper_bound(easy.begin(), easy.end(), i);         long long int ee1;         if (ee == easy.end())           ee1 = easy.size();         else           ee1 = ee - easy.begin();         auto hh = upper_bound(hard.begin(), hard.end(), i);         long long int hh1;         if (hh == hard.end())           hh1 = hard.size();         else           hh1 = hh - hard.begin();         long long int mandt = ee1 * a + hh1 * b;         long long int temp = 0;         if (mandt <= i) temp = ee1 + hh1;         long long int rem_time = i - mandt;         long long int rem_easy = easy.size() - ee1;         long long int rem_hard = hard.size() - hh1;         temp += min(rem_easy, rem_time / a);         rem_time -= min(rem_easy, rem_time / a) * a;         temp += min(rem_hard, rem_time / b);         ans = max(ans, temp);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> D0, D1;   vector<vector<pair<long long, long long> > > G;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.second - a.first > b.second - b.first;   }   void dfs(int x, int k, int p = -1) {     vector<pair<long long, long long> > F;     for (auto it : G[x]) {       int y = it.first;       if (y == p) continue;       dfs(y, k, x);       F.push_back(pair<long long, long long>(D0[y], it.second + D1[y]));     }     sort(F.begin(), F.end(), comp);     for (int i = 0; i < (int)F.size(); ++i) {       if (i < k - 1 and F[i].second > F[i].first)         D1[x] += F[i].second;       else         D1[x] += F[i].first;       if (i < k and F[i].second > F[i].first)         D0[x] += F[i].second;       else         D0[x] += F[i].first;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q;     while (q--) {       int n, k;       cin >> n >> k;       G = vector<vector<pair<long long, long long> > >(n);       D0 = D1 = vector<long long>(n, 0);       for (int i = 0; i < n - 1; ++i) {         int x, y, k;         cin >> x >> y >> k;         --x;         --y;         G[x].push_back(pair<long long, long long>(y, k));         G[y].push_back(pair<long long, long long>(x, k));       }       dfs(0, k);       cout << D0[0] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct line {     long long int a, b, c;   };   int main() {     long long int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     long long int n;     cin >> n;     vector<line> data(n);     for (auto &p : data) {       cin >> p.a >> p.b >> p.c;     }     vector<bool> s1(n), s2(n);     for (int i = 0; i < n; ++i) {       s1[i] = data[i].a * x1 + data[i].b * y1 + data[i].c > 0;       s2[i] = data[i].a * x2 + data[i].b * y2 + data[i].c > 0;     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       cnt += s1[i] ^ s2[i];     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long a[100005];   bool moze(long long x) {     long long st[100005];     long long curr = 0;     for (long long i = 0; i < n; i++) {       long long t = x - a[i];       if (t < 0) t = 0;       if (i >= k) curr -= st[i - k];       st[i] = t - curr;       if (st[i] < 0) st[i] = 0;       curr += st[i];     }     long long res = 0;     for (long long i = 0; i < n; i++) res += st[i];     return res <= m;   }   void solve() {     long long l = 1;     long long r = 1000100000;     long long x;     while (l <= r) {       long long m = (l + r) / 2;       if (moze(m)) {         l = m + 1;         x = m;       } else         r = m - 1;     }     printf( %lld , x);   }   int main() {     scanf( %lld%lld%lld , &n, &m, &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 2e5 + 5;   const int MAXM = 9e4 + 500;   const int N = 300 + 10;   const double EPS = 1e-5;   int i, j, d;   int n, k, m, p;   int a[N][N], dp[2][N][N], last[N][N];   vector<pair<int, int> > grid[MAXM];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> p;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         cin >> a[i][j];         grid[a[i][j]].push_back({i, j});       }     }     int ans = 1e9;     for (int now = 1; now <= p; now++) {       for (auto g : grid[now]) {         int first = g.first;         int second = g.second;         int dist = 1e9;         for (i = 1; i <= n; i++) {           if (last[i][second] == now - 1)             dist = min(dist, dp[1][i][second] + abs(first - i));         }         dp[0][first][second] =             (now == 1 ? abs(first - 1) + abs(second - 1) : dist);         if (now == p) ans = min(ans, dist);       }       for (auto g : grid[now]) {         int first = g.first;         int second = g.second;         for (i = 1; i <= m; i++) {           if (last[first][i] < now ||               last[first][i] == now &&                   dp[0][first][second] + abs(second - i) < dp[1][first][i]) {             last[first][i] = now;             dp[1][first][i] = dp[0][first][second] + abs(second - i);           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   struct edge {     int v, next;   } e[200010];   int ecnt = 0, head[100010];   int n;   int d[100010];   int leg[100010];   void addedge(int a, int b) {     e[++ecnt].v = b;     e[ecnt].next = head[a];     head[a] = ecnt;   }   void del(int x) {     while (d[x] <= 2) {       d[x] = 0;       int xx = x;       for (int i = head[x]; ~i; i = e[i].next) {         if (d[e[i].v]) {           x = e[i].v;           break;         }       }       if (x == xx) break;     }     leg[x]++;   }   bool solve() {     for (int i = (1); i <= (n); i++) {       if (d[i]) {         int cnt = 0;         for (int j = head[i]; ~j; j = e[j].next) {           int v = e[j].v;           if (d[v]) {             if (leg[v] > 2)               cnt++;             else if (d[v] - leg[v] > 1)               cnt++;           }         }         if (cnt > 2) return false;       }     }     return true;   }   int main() {     cin >> n;     memset((head), (-1), sizeof(head));     memset((d), (0), sizeof(d));     memset((leg), (0), sizeof(leg));     for (int i = (1); i <= (n - 1); i++) {       int u, v;       scanf( %d%d , &u, &v);       addedge(u, v);       addedge(v, u);       d[u]++;       d[v]++;     }     for (int i = (1); i <= (n); i++) {       if (d[i] == 1) del(i);     }     puts(solve() ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   int n, a[N];   struct pp {     int val, id;   } p[N];   bool cmp(pp x, pp y) { return x.val < y.val; }   int f[N], siz[N], vis[N];   int find(int x) { return x == f[x] ? x : (f[x] = find(f[x])); }   bool merge(int u, int v) {     if (!vis[u] || !vis[v]) return 0;     int fu = find(u), fv = find(v);     if (fu == fv) return 0;     f[fu] = fv;     siz[fv] += siz[fu];     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) p[i].val = a[i], p[i].id = i;     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;     int mx = 0, cnt = 0, ans = 1, num = 0;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       cnt++;       int x = p[i].id;       vis[x] = 1;       if (x < n && merge(x, x + 1)) cnt--;       if (x > 1 && merge(x, x - 1)) cnt--;       int fa = find(x);       mx = max(mx, siz[fa]);       if (1ll * cnt * mx == i) {         if (cnt > num) num = cnt, ans = p[i].val + 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   vector<int> a[MAXN];   int n, tot, father[MAXN], p[MAXN], ans[MAXN];   void work(int pos, int fa) {     father[pos] = fa;     for (unsigned i = 0; i < a[pos].size(); i++)       if (a[pos][i] != fa) work(a[pos][i], pos);     p[++tot] = pos;   }   int f(int x) {     if (ans[x] != -1) return ans[x];     static int res[MAXN];     int tans = 0;     for (int i = 1; i <= n; i++) {       int Max = 1, Nax = 1, pos = p[i];       for (unsigned i = 0; i < a[pos].size(); i++)         if (a[pos][i] != father[pos]) {           int tmp = res[a[pos][i]] + 1;           if (tmp > Max) {             Nax = Max;             Max = tmp;           } else             chkmax(Nax, tmp);         }       if (Max + Nax - 1 >= x)         tans++, res[pos] = 0;       else         res[pos] = Max;     }     return ans[x] = tans;   }   int main() {     read(n);     for (int i = 1; i <= n - 1; i++) {       int x, y;       read(x), read(y);       a[x].push_back(y);       a[y].push_back(x);     }     work(1, 0);     memset(ans, -1, sizeof(ans));     for (int i = 1, nxt; i <= n; i = nxt + 1) {       int now = f(i);       if (now >= 65 || f(i + 1) != now) {         ans[nxt = i] = now;         continue;       }       int l = i + 1, r = n;       while (l < r) {         int mid = (l + r + 1) / 2;         if (f(mid) == now)           l = mid;         else           r = mid - 1;       }       nxt = l;       for (int j = i; j <= nxt; j++) ans[j] = now;     }     for (int i = 1; i <= n; i++) writeln(ans[i]);     return 0;   }