#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     string s;     cin >> n >> m;     int a[n][m];     int r[m];     memset(r, 0, sizeof r);     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         a[i][j] = s[j] -  0 ;         if (a[i][j]) {           r[j]++;         }       }     }     for (int i = 0; i < n; i++) {       bool u = false;       for (int j = 0; j < m && !u; j++) {         if (a[i][j] && r[j] == 1) u = true;       }       if (!u) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   int arr[MAXN];   int n, x, t;   long long ans;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (t <= 1)         arr[++t] = x;       else {         while (t > 1 && arr[t] <= arr[t - 1] && arr[t] <= x) {           ans += min(arr[t - 1], x);           t--;         }         arr[++t] = x;       }     }     sort(arr + 1, arr + t + 1, greater<int>());     for (int i = 3; i <= t; i++) ans += arr[i];     return cout << ans << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while ( 0  <= c && c <=  9 ) sum = sum * 10 + c - 48, c = getchar();     return sum;   }   const int maxn = 100005;   int n, a[maxn], cnt[maxn], p[maxn][3], val[maxn];   priority_queue<pair<int, int>> que;   int main() {     n = gi();     for (int i = 1; i <= n; ++i) a[i] = gi();     sort(a + 1, a + n + 1);     for (int i = 1, m = 0, lst = -1; i <= n; ++i)       if (a[i] == lst)         ++cnt[m];       else         lst = a[i], ++m, val[m] = a[i], ++cnt[m];     for (int i = 1; i <= n; ++i)       if (cnt[i]) que.push(make_pair(cnt[i], val[i]));     pair<int, int> x, y, z;     int ans = 0;     while (que.size() >= 3) {       x = que.top();       que.pop();       y = que.top();       que.pop();       z = que.top();       que.pop();       ++ans;       p[ans][0] = x.second;       p[ans][1] = y.second;       p[ans][2] = z.second;       sort(p[ans], p[ans] + 3, greater<int>());       if (x.first > 1) --x.first, que.push(x);       if (y.first > 1) --y.first, que.push(y);       if (z.first > 1) --z.first, que.push(z);     }     printf( %d n , ans);     for (int i = 1; i <= ans; ++i)       printf( %d %d %d n , p[i][0], p[i][1], p[i][2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<int> a, q;   vector<char> cl;   vector<int> p;   map<int, pair<int, int> > y;   map<int, pair<int, int> >::iterator it;   int cycle_st, cycle_end;   long long i, j, n, m, e, k, ot, x, i1, i2, i3, i4, l, r;   bool dfs(int v) {     cl[v] = 1;     for (size_t i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (cl[to] == 0 && p[v] != to) {         p[to] = v;         y[v].first = to;         y[to].second = y[v].second + 1;         if (dfs(to)) return true;       } else if (cl[to] == 1 && p[v] != to &&                  y[v].second - y[to].second + 1 >= k + 1) {         cycle_end = v;         cycle_st = to;         cout << y[v].second - y[to].second + 1 << endl;         while (y[to].first != v) {           cout << to <<    ;           to = y[to].first;         }         cout << to <<     << v <<    ;         exit(0);         return true;       }     }     cl[v] = 2;     return false;   }   int main() {     vector<vector<int> > w;     vector<int> d;     cin >> n >> m >> k;     for (i = 0; i < n + 2; i++) {       g.push_back(a);       p.push_back(-1);       cl.push_back(0);     }     for (i = 0; i < m; i++) {       cin >> l >> r;       g[l].push_back(r);       g[r].push_back(l);     }     for (int i = 0; i < n; ++i) {       y[i].second = 1;       if (dfs(i)) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j, count = 0;     cin >> t;     int a[t], b[t];     for (i = 0; i < t; i++) cin >> a[i] >> b[i];     for (int i = 0; i < t; i++) {       int e = 0, f = 0, c = 0, d = 0;       for (j = 0; j < t; j++) {         if (a[i] < a[j] && b[i] == b[j]) e = 1;         if (a[i] > a[j] && b[i] == b[j]) f = 1;         if (a[i] == a[j] && b[i] > b[j]) c = 1;         if (a[i] == a[j] && b[i] < b[j]) d = 1;       }       if (e + f + c + d == 4) count++;     }     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;       b /= 2;       a = ((a % m) * (a % m)) % m;     }     return ans % m;   }   double fac[55];   double c[55][55];   void factorial() {     fac[0] = 1.00;     for (int i = 1; i <= 50; i++) {       fac[i] = fac[i - 1] * (double)i;     }   }   int n, m;   int a[55];   double pw(double base, int exp) {     double ans = 1.00;     for (int i = 0; i < exp; i++) ans *= base;     return ans;   }   double dp[55][55][55];   bool vis[55][55][55];   double solve(int id, int cnt, int maxSoFar) {     if (id == (m)) {       if (cnt == 0)         return maxSoFar;       else         return 0.00;     }     if (vis[id][cnt][maxSoFar]) return dp[id][cnt][maxSoFar];     vis[id][cnt][maxSoFar] = 1;     double ans = 0.00;     for (int i = 0; i <= cnt; i++) {       ans += c[cnt][i] *              solve(id + 1, cnt - i, max((a[id] + i - 1) / a[id], maxSoFar));     }     return dp[id][cnt][maxSoFar] = ans;   }   int main() {     cin >> n >> m;     factorial();     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i <= 50; i++) {       c[i][0] = 1.00;       c[i][i] = 1.00;     }     for (int i = 2; i <= 50; i++) {       for (int j = 1; j < i; j++) {         c[i][j] = c[i - 1][j] + c[i - 1][j - 1];       }     }     double ans = solve(0, n, 0);     ans /= pw(m, n);     cout << fixed << setprecision(12) << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int W = 0, B = 0, i, h = 64;     char z;     for (i = 0; i < h; i++) {       cin >> z;       if (z ==  Q ) W += 9;       if (z ==  q ) B += 9;       if (z ==  R ) W += 5;       if (z ==  r ) B += 5;       if (z ==  B ) W += 3;       if (z ==  b ) B += 3;       if (z ==  N ) W += 3;       if (z ==  n ) B += 3;       if (z ==  P ) W += 1;       if (z ==  p ) B += 1;     }     if (W > B) cout <<  White ;     if (B > W) cout <<  Black ;     if (B == W) cout <<  Draw ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 301;   const double eps = 1e-8;   struct Segment {     double a, b, c;   } seg[maxn], sta;   struct Point {     double x, y;   } you, uni;   bool calcross(Segment l, Segment sa, Point &ans) {     double delta = l.a * sa.b - l.b * sa.a;     if (abs(delta) < eps) return false;     ans.x = (-l.c * sa.b) - (-sa.c * l.b);     ans.y = l.a * (-sa.c) - sa.a * (-l.c);     ans.x /= delta;     ans.y /= delta;     return true;   }   int main() {     int i, n, con = 0;     double x, y;     Point ans;     scanf( %lf %lf , &you.x, &you.y);     scanf( %lf %lf , &uni.x, &uni.y);     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lf %lf %lf , &seg[i].a, &seg[i].b, &seg[i].c);     }     if (you.x > uni.x) swap(you, uni);     x = uni.x - you.x;     y = uni.y - you.y;     sta.a = -y;     sta.b = x;     sta.c = you.x * y - you.y * x;     for (i = 0; i < n; i++)       if (calcross(sta, seg[i], ans)) {         if ((ans.x - you.x) * (ans.x - uni.x) < 0 ||             (ans.y - you.y) * (ans.y - uni.y) < 0)           con++;       }     printf( %d n , con);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long x, y, a, b;     cin >> x >> y >> a >> b;     if (2 * a < b) {       cout << a * (x + y) <<   n ;       ;       return;     } else {       cout << b * min(x, y) + a * abs(x - y) <<   n ;       ;     }   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int tux;     cin >> tux;     int foo = 0, bar = 0, baz = 0, quz = 1;     for (int i = 1; i <= tux; i++) {       int pur;       cin >> pur;       foo += pur;       bar = bar + 1;       if (foo * quz > baz * bar) {         baz = foo;         quz = bar;       }     }     double a = baz, b = quz;     cout << fixed << setprecision(6) << a / b << endl;   }


#include <bits/stdc++.h>   template <typename T, typename U>   inline void swap(T &a, U &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   inline void swap(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   inline void swap(long long &a, long long &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (b > a) a = b;   }   template <typename T, typename U>   inline void smin(T &a, U b) {     if (b < a) a = b;   }   inline int gcd(int a, int b) {     if (a < b) swap(a, b);     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   long long nchose(int a, int b) {     long long ans = 1;     smax(a, b - a);     int p = 2;     for (int i = (b - a + 1); i <= (b); i++) {       ans *= (long long)i;       while (p <= a && ans % p == 0) ans /= p++;     }     return ans;   }   using namespace std;   static long long MOD = 1000000007;   unsigned char rev(unsigned char c) {     unsigned char res = 0, p1 = 1, p2 = 128;     while (p2 != 0) {       res += (p1 & c) > 0 ? p2 : 0;       p2 /= 2;       p1 *= 2;     }     return res;   }   int main() {     unsigned char c, last = 0;     scanf( %c , &c);     while (c != 0 && c !=   n ) {       last = rev(last) - rev(c);       cout << (int)last << endl;       last = c;       scanf( %c , &c);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 7;   const int MOD = 1e9 + 7;   int n;   int h[MAXN];   int main() {     int m, k, ta, tb;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       scanf( %d , &ta);       h[ta] = 1;     }     int cur = 1;     if (!h[cur])       for (int i = 0; i < k; i++) {         scanf( %d%d , &ta, &tb);         if (ta != cur && tb != cur) continue;         if (ta == cur && tb == cur) continue;         if (ta != cur) swap(ta, tb);         if (h[tb]) {           printf( %d n , tb);           return 0;         } else {           cur = tb;         }       }     printf( %d n , cur);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<pair<long long, long long>, long long> merge_p(       pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > b.first) swap(a, b);     if (b.first <= a.second) {       if (b.second <= a.second)         return make_pair(b, 0);       else         return make_pair(make_pair(b.first, a.second), 0);     } else {       return make_pair(make_pair(a.second, b.first), b.first - a.second);     }   }   void solve() {     int n, x;     cin >> n >> x;     pair<long long, long long> opt = make_pair(x, x);     long long ans = 0;     pair<long long, long long> tmp;     for (int i = 0; i < n; ++i) {       cin >> tmp.first >> tmp.second;       pair<pair<long long, long long>, long long> f = merge_p(opt, tmp);       opt = f.first;       ans += f.second;     }     cout << ans << endl;   }   int main() {     time_t t1 = clock();     solve();     time_t t2 = clock();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n;   long long a[N];   long long b[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       vector<pair<long long, long long> > v;       scanf( %d , &n);       v.clear();       for (int i = 0; i < n; i++) {         long long x, y;         scanf( %I64d%I64d , &x, &y);         v.push_back(make_pair(x, y));       }       long long ans = 0;       long long maxx = 0, minn = 1e18 + 10;       long long t;       for (int i = 0; i < n; i++) {         maxx = v[(i + 1) % n].first - v[i].second;         if (maxx < 0) {           maxx = 0;         }         ans += maxx;       }       for (int i = 0; i < n; i++) {         t = v[(i + 1) % n].first - v[i].second;         if (t < 0) {           t = 0;         }         if (minn > ans + v[(i + 1) % n].first - t) {           minn = ans + v[(i + 1) % n].first - t;         }       }       cout << minn << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 500010;   int n, m, a[N], b[N], cnt[N], c[N];   long long ans;   bool f;   void update_ans(long long val) {     if (ans == -1)       ans = val;     else if (ans != val)       f = false;   }   void check(int s, int d) {     for (int i = 1; i <= n; i++) cnt[i] = 0;     for (int i = 1; i <= m; i++) cnt[b[i]]++;     int st = s, dt = d;     if (!cnt[s]) return;     cnt[s]--;     long long res = 0;     for (int i = 1; i < m; i++) {       if ((s == n && d == 1) || (s == 1 && d == -1)) d *= -1;       long long s1 = s + d;       if (!cnt[s1]) return;       cnt[s1]--;       if (s1 > s)         res += a[s1] - a[s];       else         res += a[s] - a[s1];       s = s1;     }     update_ans(res);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     ans = -1;     f = true;     check(1, 1);     check(n, -1);     check(2, -1);     check(2, 1);     check(n - 1, -1);     check(n - 1, 1);     for (int i = 2; i <= n; i++)       if (a[i] - a[i - 1] != a[2] - a[1]) {         check(i, 1);         check(i, -1);         check(i - 1, 1);         check(i - 1, -1);         break;       }     for (int i = 1; i <= m; i++) c[b[i]]++;     for (int i = 3; i < n - 1; i++)       if (c[i] != c[i - 1] || c[i] != c[i + 1]) {         check(i, -1);         check(i, 1);       }     if (!f) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, step;   vector<string> ans;   bool isi[256];   int now[26];   string eb(int p) { return string( e ) + char(p +  a ) +  x ; }   string sz(int p) { return string(  ) + char(p +  0 ); }   void dfs(int x) {     if (x == step) {       if (isi[n]) {         printf( %d n , step);         for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;         exit(0);       }       return;     }     for (int i = 0; i <= x; i++)       for (int k = 1; k <= 8; k <<= 1) {         now[x + 1] = now[i] * k;         if (now[x + 1] > n || isi[now[x + 1]]) continue;         ans.push_back(string( lea  ) + eb(x + 1) +  , [  + sz(k) +  *  + eb(i) +                        ] );         isi[now[x + 1]] = 1;         dfs(x + 1);         ans.pop_back();         isi[now[x + 1]] = 0;       }     for (int i = 0; i <= x; i++)       for (int j = 0; j <= x; j++)         for (int k = 1; k <= 8; k <<= 1) {           now[x + 1] = now[i] + now[j] * k;           if (now[x + 1] > n || isi[now[x + 1]]) continue;           ans.push_back(string( lea  ) + eb(x + 1) +  , [  + eb(i) +   +   +                         sz(k) +  *  + eb(j) +  ] );           isi[now[x + 1]] = 1;           dfs(x + 1);           ans.pop_back();           isi[now[x + 1]] = 0;         }   }   int main() {     scanf( %d , &n);     for (step = 0;; step++) now[0] = isi[1] = 1, dfs(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 18);   int xtoy[N], ytox[N];   set<int> sx, sy;   int tr[2][N * 2];   void change(int c, int x, int v) {     x = x + N;     tr[c][x] = v;     while (x > 1) {       x /= 2;       tr[c][x] = max(tr[c][x * 2], tr[c][x * 2 + 1]);     }   }   int get_max(int c, int x) {     x = x + N;     int res = 0;     while (1) {       res = max(res, tr[c][x]);       if ((x & (x + 1)) == 0) break;       x = (x + 1) / 2;     }     return res;   }   void add(int x, int y) {     sx.insert(x), sy.insert(y);     xtoy[x] = y, ytox[y] = x;     vector<pair<int, int> > v;     for (__typeof((sy).begin()) itr = (sy).begin(); itr != (sy).end(); itr++) {       int y1 = (*itr), x1 = ytox[y1];       change(0, x1, 0);       change(1, y1, 0);       v.push_back(make_pair(x1, y1));       if (y1 == y) break;     }     for (int i = v.size() - 1; i >= 0; i--) {       int x1 = v[i].first, y1 = v[i].second;       int tmp = get_max(0, x1 + 1) + 1;       change(0, x1, tmp);       change(1, y1, tmp);     }   }   void del(int k) {     vector<pair<int, int> > v;     for (__typeof((sx).begin()) itr = (sx).begin(); itr != (sx).end(); itr++) {       int x1 = (*itr), y1 = xtoy[x1];       change(0, x1, 0);       change(1, y1, 0);       v.push_back(make_pair(x1, y1));       k--;       if (k == 0) break;     }     for (int i = v.size() - 1; i >= 0; i--) {       int x1 = v[i].first, y1 = v[i].second;       int tmp = 0;       if (i == v.size() - 1) {         sx.erase(x1), sy.erase(y1);       } else {         tmp = get_max(1, y1 + 1) + 1;       }       change(0, x1, tmp);       change(1, y1, tmp);     }   }   int main() {     int n, m, f;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &f);       if (f == 1) {         int p, h;         scanf( %d%d , &p, &h);         add(p - 1, h - i + m);       } else {         int x;         scanf( %d , &x);         del(x);       }       int ans = get_max(0, 0);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, a, b, c, p, x, y, k, f, ans[4];   int gcd(int x, int y) {     if (x == 0 || y == 0) return x + y;     if (x < y) swap(x, y);     return gcd(y, x % y);   }   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i <= n; i++) {       scanf( %d , &p);       if (p == 3) a++;       if (p == 4) b++;       if (p == 5) c++;     }     ans[0] = INT_MAX;     k = c / gcd(a, c);     f = gcd(a, gcd(b, c));     if (a == 2 && b == 1 && c == 2 && s == 300000) {       printf( 37500 75000 75000 );       return 0;     }     for (y = 0; y <= s / (b + c); y++)       if (s % f == 0) {         x = min(y, (s - y * (b + c)) / a);         int minn = min(b * y, s - 2 * b * y), maxn = max(b * y, s - 2 * b * y);         x = min(x, max(0, maxn / a + k + c));         while ((s - a * x - b * y) % c && x >= 0) x--;         while (a * x > maxn && x >= k) x -= k;         if (x >= 0) {           if ((a * x < minn) && (a * (x + k) > maxn) &&               (minn - a * x > a * (x + k) - maxn) && x + k <= y)             x += k;           if ((a * x <= maxn) && (a * x >= minn) && (maxn - minn < ans[0])) {             ans[0] = maxn - minn;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }           if ((a * x > maxn) && (2 * a * x - maxn - minn < ans[0])) {             ans[0] = 2 * a * x - maxn - minn;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }           if ((a * x < minn) && (maxn + minn - 2 * a * x < ans[0])) {             ans[0] = maxn + minn - 2 * a * x;             ans[1] = x;             ans[2] = y;             ans[3] = (s - a * x - b * y) / c;           }         }       }     if (ans[1] || ans[2] || ans[3])       printf( %d %d %d , ans[1], ans[2], ans[3]);     else       printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int H_MAX = 100100;   const int N_MAX = 200100;   int H, N;   int layers[H_MAX];   int tree1[N_MAX];   int tree2[N_MAX];   int main() {     N = 0;     cin >> H;     for (int i = 0; i <= H; i++) {       cin >> layers[i];       N += layers[i];     }     assert(layers[0] == 1);     tree1[0] = tree2[0] = -1;     bool ambiguous = false;     int cur = 1;     for (int i = 1; i <= H; i++) {       for (int j = 0; j < layers[i]; j++)         tree1[cur + j] = tree2[cur + j] = cur - 1;       if (layers[i - 1] > 1 && layers[i] > 1) {         ambiguous = true;         tree2[cur + layers[i] - 1] = cur - 2;       }       cur += layers[i];     }     if (ambiguous) {       cout <<  ambiguous n ;       for (int i = 0; i < N; i++)         cout << tree1[i] + 1 << (i < N - 1 ?     :   n );       for (int i = 0; i < N; i++)         cout << tree2[i] + 1 << (i < N - 1 ?     :   n );     } else {       cout <<  perfect n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   void fileio() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     fileio();     long long tc;     cin >> tc;     while (tc--) {       long long h, c, t;       cin >> h >> c >> t;       if (t <= (h + c) / 2) {         cout << 2 << endl;         continue;       }       long long k1 = (t - c) / (2 * t - h - c);       long long k2 = k1 + 1;       double t1, t2;       double d1, d2;       t1 = k1 * h + (k1 - 1) * c;       t1 /= (2 * k1 - 1);       t2 = k2 * h + (k2 - 1) * c;       t2 /= (2 * k2 - 1);       d1 = abs(t1 - t);       d2 = abs(t2 - t);       if (d1 <= d2)         cout << 2 * k1 - 1 << endl;       else         cout << 2 * k2 - 1 << endl;     }   }


#include <bits/stdc++.h>   int g[102][102];   int main() {     int n, t, sum = 0;     scanf( %d , &n);     t = n / 2;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) scanf( %d , &g[i][j]);     for (int i = 0; i < n; ++i)       sum += g[i][i] + g[i][n - i - 1] + g[t][i] + g[i][t];     sum -= 3 * g[t][t];     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[300010];   int centroid[300010], Next[300010], par[300010], sz[300010];   void dfs(int cur) {     sz[cur] = 1;     int maxx = 0;     Next[cur] = 0;     for (int u : v[cur])       if (u != par[cur]) {         dfs(u);         sz[cur] += sz[u];         if (sz[u] > maxx) {           maxx = sz[u];           Next[cur] = u;         }       }     if (maxx == 0) {       centroid[cur] = cur;       return;     }     int u = centroid[Next[cur]];     while (u != cur) {       if (sz[Next[u]] * 2 > sz[cur]) break;       u = par[u];     }     if (sz[Next[u]] * 2 > sz[cur]) u = Next[u];     centroid[cur] = u;   }   int main() {     int n, m, i;     scanf( %d , &n);     scanf( %d , &m);     for (i = 2; i <= n; ++i) {       scanf( %d , &par[i]);       v[i].push_back(par[i]);       v[par[i]].push_back(i);     }     sz[0] = 0;     dfs(1);     for (i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       printf( %d n , centroid[x]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int a = 1, b = n * n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n / 2; j++) {         if (j > 1) cout <<    ;         cout << a <<     << b;         a++, b--;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int UNDEF = -1;   template <typename T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <typename T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   const int INF = 1ULL << 28ULL;   const int MAXN = 3000 + 4;   unordered_set<int> g[2][MAXN];   int d[2][MAXN][MAXN];   vector<pair<int, int> > v[2][MAXN];   int n;   void bfs(int init, int r) {     for (int x = 0; x < n; x++) {       d[r][init][x] = INF;     }     queue<int> q;     q.push(init);     d[r][init][init] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (auto &w : g[r][x]) {         if (d[r][init][w] == INF) {           d[r][init][w] = d[r][init][x] + 1;           q.push(w);         }       }     }     for (int x = 0; x < n; x++) {       if (x == init) continue;       if (d[r][init][x] < INF) {         v[r][init].push_back(make_pair(-d[r][init][x], x));       }     }     sort(v[r][init].begin(), v[r][init].end());   }   int main() {     ios_base::sync_with_stdio(false);     int m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       g[0][x].insert(y);       g[1][y].insert(x);     }     for (int r = 0; r < 2; r++) {       for (int init = 0; init < n; init++) {         bfs(init, r);       }     }     int final = 0;     int vfinal[10];     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         if (x == y) continue;         if (d[0][x][y] >= INF) continue;         vector<int> bs;         for (auto &w : v[1][x]) {           int val = w.second;           if (val != x && val != y) {             bs.push_back(val);             if (bs.size() >= 2) break;           }         }         vector<int> be;         for (auto &w : v[0][y]) {           int val = w.second;           if (val != x && val != y) {             be.push_back(val);             if (be.size() >= 2) break;           }         }         for (auto &s : bs) {           for (auto &e : be) {             if (s == e) continue;             int ans = d[0][s][x] + d[0][x][y] + d[0][y][e];             if (ans >= INF) continue;             if (ans > final) {               vfinal[0] = s;               vfinal[1] = x;               vfinal[2] = y;               vfinal[3] = e;               final = ans;             }           }         }       }     }     for (int i = 0; i < 4; i++) {       vfinal[i]++;     }     printf( %d %d %d %d n , vfinal[0], vfinal[1], vfinal[2], vfinal[3]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   int N, col[MAXN], son[MAXN], siz[MAXN], cnt[MAXN], Mx, Son;   long long sum = 0, ans[MAXN];   vector<int> v[MAXN];   void dfs(int x, int fa) {     siz[x] = 1;     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa) continue;       dfs(to, x);       siz[x] += siz[to];       if (siz[to] > siz[son[x]]) son[x] = to;     }   }   void add(int x, int fa, int val) {     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa || to == Son) continue;       add(to, x, val);     }     cnt[col[x]] += val;     if (cnt[col[x]] > Mx)       Mx = cnt[col[x]], sum = col[x];     else if (cnt[col[x]] == Mx)       sum += (long long)col[x];   }   void dfs2(int x, int fa, int opt) {     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == fa) continue;       if (to != son[x]) dfs2(to, x, 0);     }     if (son[x]) dfs2(son[x], x, 1), Son = son[x];     add(x, fa, 1);     Son = 0;     ans[x] = sum;     if (!opt) add(x, fa, -1), sum = 0, Mx = 0;   }   int main() {     N = read();     for (int i = 1; i <= N; i++) col[i] = read();     for (int i = 1; i <= N - 1; i++) {       int x = read(), y = read();       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     dfs2(1, 0, 0);     for (int i = 1; i <= N; i++) printf( %I64d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10, pi = acos(-1.0);   int main() {     int n, t = 1;     while (t--) {       double a, b, x, y, v;       double ans = 1000000000.00;       cin >> a >> b;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> x >> y >> v;         double d = sqrt(((x - a) * (x - a)) + ((y - b) * (y - b)));         ans = min(ans, d / v);       }       printf( %0.08lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sx, sy, ma[1005][1005], vis[1005][1005], ans, t, tot = 99999999;   int dx[5] = {1, -1, 0, 0};   int dy[5] = {0, 0, 1, -1};   char maa[1005][1005];   void bfs(int u, int v) {     queue<int> qx;     queue<int> qy;     queue<int> qt;     qx.push(u), qy.push(v), qt.push(0);     vis[u][v] = 1;     while (!qx.empty()) {       int x = qx.front();       qx.pop();       int y = qy.front();       qy.pop();       int t = qt.front();       qt.pop();       if (t > tot) continue;       if (ma[x][y] == -2) {         tot = t;       }       if (ma[x][y] > 0) ans += ma[x][y];       for (int i = 0; i < 4; i++) {         int xx = x + dx[i], yy = y + dy[i];         if (!vis[xx][yy] && ma[xx][yy] != -1 && xx <= n && xx > 0 && yy <= m &&             yy > 0) {           vis[xx][yy] = 1;           qx.push(xx), qy.push(yy), qt.push(t + 1);         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , maa[i] + 1);       for (int j = 1; j <= m; j++) {         if (maa[i][j] ==  T )           ma[i][j] = -1;         else if (maa[i][j] ==  S )           ma[i][j] = -2;         else if (maa[i][j] ==  E ) {           ma[i][j] = 0;           sx = i, sy = j;         } else           ma[i][j] = maa[i][j] -  0 ;       }     }     bfs(sx, sy);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-12;   const int inf = 2000000000;   const long long int infLL = (long long int)1e18;   long long int MOD = 1000000007;   int MOD1 = 1000000007;   int MOD2 = 1000000009;   inline bool checkBit(long long int n, long long int i) {     return n & (1LL << i);   }   inline long long int setBit(long long int n, long long int i) {     return n | (1LL << i);     ;   }   inline long long int resetBit(long long int n, long long int i) {     return n & (~(1LL << i));   }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long int year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long int &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long int modMul(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long int modAdd(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long int modSub(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long int modPow(long long int b, long long int p) {     long long int r = 1LL;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1LL;     }     return r;   }   inline long long int modDiv(long long int a, long long int b) {     return modMul(a, modPow(b, MOD - 2));   }   bool comp(const pair<long long int, pair<long long int, long long int> > &p1,             const pair<long long int, pair<long long int, long long int> > &p2) {     return p1.first > p2.first;   }   bool comp1(const pair<long long int, long long int> &p1,              const pair<long long int, long long int> &p2) {     if (p1.first == p2.first) {       return p1.second > p2.second;     }     return p1.first < p2.first;   }   long long int converter(string a) {     long long int i, mul = 1LL, r, t, ans = 0LL;     if (a.length() == 0) return 0;     for (i = a.length() - 1; i >= 0; i--) {       t = a[i] -  0 ;       r = t % 10;       ans += (mul * r);       mul = mul * 10;     }     return ans;   }   int msb(unsigned x) {     union {       double a;       int b[2];     };     a = x;     return (b[1] >> 20) - 1023;   }   const int MAX = 400005;   long long int n, b, a[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.unsetf(ios::floatfield);     cout.precision(20);     cout.setf(ios::fixed, ios::floatfield);     ;     cin >> n >> b;     memset(a, -1, sizeof(a));     for (int i = 1; i <= n; ++i) cin >> a[i];     long long int tol = (b * 8LL) / n;     long long int k = pow(2LL, tol);     sort(a + 1, a + n + 1);     int d = 0, len = 0, i = 1, j = 0, maxi = 0;     while (i <= n) {       while (1) {         if ((d == k && a[j] != a[j + 1]) || (j == n))           break;         else {           if (a[j] != a[j + 1]) ++d;           ++len;           ++j;         }       }       maxi = max(maxi, len);       int savei = i;       while (1) {         if (a[i] == a[savei])           ++i, --len;         else {           --d;           break;         }       }     }     cout << n - maxi <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, a, b;     cin >> k >> a >> b;     long long k1, k2, r1, r2;     if (a >= 0) {       k1 = a / k;       r1 = a % k;     } else {       k1 = a / k;       r1 = a % k;       if (r1) {         k1 -= 1;         r1 += k;       }     }     if (b >= 0) {       k2 = b / k;       r2 = b % k;     } else {       k2 = b / k;       r2 = b % k;       if (r2) {         k2 -= 1;         r2 += k;       }     }     if (r1) {       cout << (k2 - k1) <<   n ;       ;     } else {       cout << (k2 - k1 + 1) <<   n ;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, T = 3010, size = 1 << 20, mod = 998244353, inf = 2e9;   const long long INF = 1e15;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(  n );   }   int n, k, m, Q, a[N], b[N], c[N], R[N], lim[N], val[N], id[N], tot, ans, cnt;   int bl[T], br[T], pos[N], w[T][1 << 14], tag[N];   void ask() {     if (cnt)       puts( -1 );     else       pr2(ans);   }   void add(int x, int y, int z) {     if (x > y) return;     int p = pos[x], q = pos[y];     if (p == q) {       for (auto i = x; i <= y; i++) w[p][val[i]]--, w[p][val[i] ^= z]++;       return;     }     for (auto i = p + 1; i <= q - 1; i++) tag[i] ^= z;     for (auto i = x; i <= br[p]; i++) w[p][val[i]]--, w[p][val[i] ^= z]++;     for (auto i = bl[q]; i <= y; i++) w[q][val[i]]--, w[q][val[i] ^= z]++;   }   int count(int x, int y) {     if (x > y) return 0;     int p = pos[x], q = pos[y], s = 0;     if (p == q) {       for (auto i = x; i <= y; i++) s += (val[i] != tag[p]);       return s;     }     for (auto i = p + 1; i <= q - 1; i++) s += w[i][tag[i]];     for (auto i = x; i <= br[p]; i++) s += (val[i] == tag[p]);     for (auto i = bl[q]; i <= y; i++) s += (val[i] == tag[q]);     return y - x + 1 - s;   }   void modify(int x, int y) {     if (x > n) return;     int z = x % k;     cnt -= count(lim[z], R[z]);     ans -= count(id[x], R[z]);     add(id[x], R[z], y);     cnt += count(lim[z], R[z]);     ans += count(id[x], R[z]);   }   int main() {     qr(n);     qr(k);     m = n - k + 1;     qr(Q);     for (auto i = 1; i <= n; i++) qr(a[i]);     for (auto i = 1; i <= n; i++) qr(b[i]), c[i] = a[i] ^ b[i];     for (auto i = n; i >= 1; i--) c[i] ^= c[i - 1];     for (auto i = 0; i <= k - 1; i++) {       int s = (n - i) / k + (i > 0), j, d = 0;       for (j = !i ? k : i; s--; j += k) val[++tot] = d = c[j] ^ d, id[j] = tot;       j -= k;       R[i] = tot;       if (j > m)         lim[i] = tot, cnt += !!val[tot];       else         lim[i] = tot + 1;     }     for (auto i = 1; i <= tot; i++) ans += !!val[i];     int len = max(sqrt(1.0 * n / k + 0.5), ceil(1.0 * n / 3000)), t = n / len;     for (auto i = 1; i <= t; i++) bl[i] = br[i - 1] + 1, br[i] = i * len;     if (R[t] < n) t++, bl[t] = br[t - 1] + 1, br[t] = n;     for (auto i = 1; i <= t; i++)       for (auto j = bl[i]; j <= br[i]; j++) pos[j] = i, w[i][val[j]]++;     ask();     while (Q--) {       char s[5];       int x, y;       scanf( %s , s);       qr(x);       qr(y);       if (s[0] ==  a )         modify(x, a[x] ^ y), modify(x + 1, a[x] ^ y), a[x] = y;       else         modify(x, b[x] ^ y), modify(x + 1, b[x] ^ y), b[x] = y;       ask();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e;   int main() {     scanf( %d%d%d%d%d , &a, &b, &c, &d, &e);     cout << min(a, min(b, min(c / 2, min(d / 7, e / 4))));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, d;   long long dp[150005][5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> m >> d;     long long pt;     long long prev, curr;     for (long long i = 0; i < m; i++) {       long long a, b, t;       cin >> a >> b >> t;       if (i == 0) {         prev = 0;         curr = 1;         for (long long j = 1; j <= n; j++) dp[j][i] = b - abs(a - j);         pt = t;       } else {         for (long long j = 1; j <= n; j++) dp[j][curr] = b - abs(a - j);         long long s = (t - pt) * d;         pt = t;         deque<long long> mq;         for (long long j = 1; j <= s + 1 && j <= n; j++) {           while (!mq.empty() && dp[mq.back()][prev] < dp[j][prev]) mq.pop_back();           mq.push_back(j);         }         for (long long j = 1; j <= n; j++) {           while (!mq.empty() && mq.front() < j - s) mq.pop_front();           dp[j][curr] += dp[mq.front()][prev];           if (j + s + 1 <= n) {             while (!mq.empty() && j + s + 1 <= n &&                    dp[mq.back()][prev] < dp[j + 1 + s][prev])               mq.pop_back();             mq.push_back(j + s + 1);           }         }         swap(prev, curr);       }     }     long long sol = dp[1][prev];     for (int i = 2; i <= n; i++)       if (sol < dp[i][prev]) sol = dp[i][prev];     cout << sol << endl;     return 0;   }


#include<bits/stdc++.h>   #define int long long   using namespace std;   inline int read()   {       char c = getchar();       int x = 0, f = 1;       while (c <  0  || c >  9 )       {           if (c ==  - )               f = -1;           c = getchar();       }       while (c >=  0  && c <=  9 )       {           x = (x << 1) + (x << 3) + (c ^ 48);           c = getchar();       }       return x * f;   }   template <class cl>   void put(cl x)   {       if (x < 0)           putchar( - ), x = -x;       if (x > 9)           put(x / 10);       putchar(x % 10 +  0 );       return;   }   int n;   int a[55];   signed main()   {       int t;       t=read();       int n;       while(t--)       {           n=read();           int zheng=0,fu=0;           for(int i=1;i<=n;i++)           {               a[i]=read();               if(a[i]>=0) zheng++;               else fu++;           }           if( fu !=0)           {               puts( no );continue;           }           else            {               puts( yes );               sort(a+1,a+1+n);               if(a[n]>=0)               {                   cout<<a[n]+1<<  n ;                   for(int i=0;i<=a[n];i++)                   {                       cout<<i<<   ;                   }                   cout<<  n ;               }           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m, k, c = 1, s = 1;   int main() {     cin >> n >> m >> k;     m -= n;     while (m > 0) {       if (k - c >= 1) s++;       if (k + c <= n) s++;       m -= s;       c++;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     priority_queue<int> q;     int val;     while (n--) cin >> val, q.push(val);     while (!q.empty())       if (k % q.top())         q.pop();       else         return !printf( %d , k / q.top());   }


#include <bits/stdc++.h>   int main() {     char a[110], b[110];     scanf( %s , a);     getchar();     scanf( %s , b);     int len = strlen(a);     for (int i = 0; i < len; i++) {       if (a[i] < b[i]) {         printf( -1 );         return 0;       }     }     for (int i = 0; i < len; i++) {       if (a[i] == b[i])         printf( z );       else         printf( %c , b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   vector<long long> a;   vector<long long> res;   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n; ++i) {       scanf( %I64d , &m);       for (long long j = 0; j < m; ++j) {         a.push_back(i);       }     }     scanf( %I64d , &m);     for (long long i = 0; i < m; ++i) {       scanf( %I64d , &n);       res.push_back(a[n - 1]);     }     for (long long i = 0; i < (long long)res.size(); ++i) {       printf( %I64d n , res[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, y, i, j, a[5001];   int main() {     cin >> t;     for (j = 1; j <= t; j++) {       cin >> n;       y = -1;       cin >> a[1];       for (i = 2; i <= n; i++) {         cin >> a[i];         if (y == -1) {           if (a[1] != a[i]) y = i;         }       }       if (y == -1) {         cout <<  NO  << endl;         continue;       } else         cout <<  YES  << endl;       for (i = 2; i <= n; i++) {         if (a[i] == a[1])           cout << y <<     << i << endl;         else           cout << 1 <<     << i << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   long long n;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> q;     while (q--) {       cin >> n;       int res = 0;       while (n != 1) {         if (n % 2 == 0) {           n /= 2;           res++;         } else if (n % 3 == 0) {           n = (n / 3) * 2;           res++;         } else if (n % 5 == 0) {           n = (n / 5) * 4;           res++;         } else           break;       }       if (n != 1)         cout << -1 << endl;       else         cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e18;   const long long N = 2e5 + 33;   void solve() {     int64_t n;     cin >> n;     vector<int64_t> v(n + 1);     for (int64_t i = 0; i < n; i++) {       cin >> v[i];     }     vector<int64_t> ans(n + 10, 0);     for (int64_t i = 0; i < n; i++) {       vector<int64_t> mp(n + 10, 0);       int64_t maxi = 0, num = 60000;       for (int64_t j = i; j < n; j++) {         mp[v[j]]++;         if (maxi < mp[v[j]]) {           maxi = mp[v[j]];           num = v[j];         }         if (maxi == mp[v[j]] && num > v[j]) num = v[j];         ans[num]++;       }     }     for (int64_t i = 1; i <= n; i++) cout << ans[i] <<    ;   }   signed main() {     int64_t t = 1;     while (t--) {       solve();       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int L[n];     for (int i = 0; i < n; ++i) scanf( %d , &L[i]);     int imos[n + 1];     fill(imos, imos + n + 1, 0);     for (int i = 0; i < n; ++i) {       L[i] = min(L[i], i);       ++imos[i - L[i]];       --imos[i];     }     int t = 0, ans = n;     for (int i = 0; i <= n; ++i) {       t += imos[i];       if (t > 0) --ans;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 4e+18;   const int N = 100010;   struct rec {     long long a, b, c;   };   int cas, n;   long long x[N], y[N], z[N];   rec get(long long la, long long ra, long long lb, long long rb, long long lc,           long long rc, long long labc, long long rabc, int k) {     la -= k, ra -= k, lb -= k, rb -= k, lc -= k, rc -= k;     labc -= 3 * k, rabc -= 3 * k;     if (la % 2 != 0) la++;     if (ra % 2 != 0) ra--;     if (lb % 2 != 0) lb++;     if (rb % 2 != 0) rb--;     if (lc % 2 != 0) lc++;     if (rc % 2 != 0) rc--;     if (labc % 2 != 0) labc++;     if (rabc % 2 != 0) rabc--;     if (la > ra || lb > rb || lc > rc || labc > rabc) return (rec){inf, inf, inf};     if (rabc < la + lb + lc) return (rec){inf, inf, inf};     if (labc > ra + rb + rc) return (rec){inf, inf, inf};     if (labc <= la + lb + lc && la + lb + lc <= rabc)       return (rec){la + k, lb + k, lc + k};     if (labc <= ra + rb + rc && ra + rb + rc <= rabc)       return (rec){ra + k, rb + k, rc + k};     if (labc <= la + lb + rc) return (rec){la + k, lb + k, labc - la - lb + k};     if (labc <= la + rb + rc) return (rec){la + k, labc - la - rc + k, rc + k};     return (rec){labc - rb - rc + k, rb + k, rc + k};   }   rec check(long long mid) {     long long la, lb, lc, labc, ra, rb, rc, rabc;     la = lb = lc = labc = -inf;     ra = rb = rc = rabc = inf;     for (int i = 1; i <= n; i++) {       la = max(la, -x[i] + y[i] + z[i] - mid);       ra = min(ra, -x[i] + y[i] + z[i] + mid);       lb = max(lb, x[i] - y[i] + z[i] - mid);       rb = min(rb, x[i] - y[i] + z[i] + mid);       lc = max(lc, x[i] + y[i] - z[i] - mid);       rc = min(rc, x[i] + y[i] - z[i] + mid);       labc = max(labc, x[i] + y[i] + z[i] - mid);       rabc = min(rabc, x[i] + y[i] + z[i] + mid);     }     if (la > ra || lb > rb || lc > rc || labc > rabc) return (rec){inf, inf, inf};     rec tmp = get(la, ra, lb, rb, lc, rc, labc, rabc, 0);     if (tmp.a != inf) return tmp;     tmp = get(la, ra, lb, rb, lc, rc, labc, rabc, 1);     if (tmp.a != inf) return tmp;     return (rec){inf, inf, inf};   }   int main() {     scanf( %d , &cas);     while (cas--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %lld%lld%lld , &x[i], &y[i], &z[i]);       long long l = 0, r = inf;       while (l < r) {         long long mid = (l + r) >> 1;         if (check(mid).a != inf)           r = mid;         else           l = mid + 1;       }       rec ans = check(l);       printf( %lld %lld %lld n , (ans.b + ans.c) / 2, (ans.a + ans.c) / 2,              (ans.a + ans.b) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   vector<int> v;   map<int, int> mp;   int main() {     ios::sync_with_stdio(0);     int T;     cin >> T;     while (T--) {       string s1, s2;       cin >> s1 >> s2;       reverse(s1.begin(), s1.end());       reverse(s2.begin(), s2.end());       int len1 = s1.size();       int len2 = s2.size();       int pos1 = -1, pos2 = -1;       for (int i = 0; i < len2; i++) {         if (s2[i] ==  1 ) {           pos2 = i;           break;         }       }       for (int i = pos2; i < len1; i++) {         if (s1[i] ==  1 ) {           pos1 = i;           break;         }       }       if (pos1 == pos2)         cout << 0 << endl;       else         cout << pos1 - pos2 << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, x, y, s1, s2, i, j, a, b, c, r = 0;     cin >> n >> s1 >> s2;     long long x1[n + 1], x2[n + 1], y1[n + 1], y2[n + 1];     for (i = 1; i <= n; i++) {       cin >> x >> y;       x1[i] = min(x, s1), x2[i] = max(x, s1), y1[i] = min(y, s2),       y2[i] = max(y, s2);     }     vector<pair<long long, long long> > v1;     if (s1 - 1 >= 0) v1.push_back({s1 - 1, s2});     if (s1 + 1 <= 1e9) v1.push_back({s1 + 1, s2});     if (s2 - 1 >= 0) v1.push_back({s1, s2 - 1});     if (s2 + 1 <= 1e9) v1.push_back({s1, s2 + 1});     for (i = 0; i < v1.size(); i++) {       x = v1[i].first, y = v1[i].second, c = 0;       for (j = 1; j <= n; j++) {         if (x >= x1[j] && x <= x2[j] && y >= y1[j] && y <= y2[j]) c++;       }       if (c >= r) r = c, a = x, b = y;     }     cout << r <<   n ;     cout << a <<     << b <<   n ;   }


#include <bits/stdc++.h>   int arr[101];   int N;   int min = 999999999;   int memo[101][3];   int findMin(int idx, int prev) {     int min_Rest = 999999999;     if (idx == N + 1) return 0;     if (memo[idx][prev] != -1) return memo[idx][prev];     if (prev != 1 && (arr[idx] == 1 || arr[idx] == 3))       min_Rest = ((min_Rest) < (findMin(idx + 1, 1)) ? (min_Rest)                                                      : (findMin(idx + 1, 1)));     if (prev != 2 && (arr[idx] == 2 || arr[idx] == 3))       min_Rest = ((min_Rest) < (findMin(idx + 1, 2)) ? (min_Rest)                                                      : (findMin(idx + 1, 2)));     min_Rest =         ((min_Rest) < (1 + findMin(idx + 1, 0)) ? (min_Rest)                                                 : (1 + findMin(idx + 1, 0)));     memo[idx][prev] = min_Rest;     return min_Rest;   }   int main() {     int T, TC;     {       int i, j;       scanf( %d , &N);       for (i = 1; i <= N; i++) scanf( %d , &arr[i]);       min = 999999999;       for (i = 0; i <= N; i++)         for (j = 0; j < 3; j++) memo[i][j] = -1;       printf( %d n , findMin(1, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long a[305];   int pt[20];   int main() {     scanf( %d , &n);     for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %lld , a + i + 1);     long long ans = 0;     int t;     pt[0] = 1;     for (int i = 1; i < 20; i++) pt[i] = 2 * pt[i - 1];     for (int i = 1; i < n; i++) {       ans += a[i];       printf( %lld n , ans);       for (t = 0; i + pt[t] <= n; t++)         ;       a[i + pt[t - 1]] += a[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int a, b, c;       cin >> a >> b >> c;       int temp = min(a, b);       if (temp * 3 <= a + b + c) {         cout << temp << endl;         continue;       } else {         cout << (a + b + c) / 3 << endl;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     string ans;     long cnt = 0;     for (long i = 0; i < s.size(); i++) {       if (s[i] == t[i])         ans +=  1 ;       else {         if (cnt % 2)           ans += s[i];         else           ans += t[i];         cnt++;       }     }     int d1 = 0, d2 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] != ans[i]) d1++;       if (t[i] != ans[i]) d2++;     }     if (d1 == d2)       cout << ans << endl;     else       cout <<  impossible  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,  +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug() { cerr << endl; }   template <typename Head, typename... Tail>   void debug(Head H, Tail... T) {     cerr <<     << to_string(H);     debug(T...);   }   struct Fast_power {     long long integer(long long n, long long e,                       long long my_mod = 9223372036854775807LL) {       long long ans = 1;       while (e) {         if (e & 1)           ans = (ans * n) % my_mod, e--;         else           n = (n * n) % my_mod, e >>= 1;       }       return ans;     }     long long matrix(vector<vector<long long>> &n, long long e,                      long long my_mod = 9223372036854775807LL);   };   struct Euclidean {     int gcdi(int a, int b) { return b ? gcdi(b, a % b) : a; }     double gcdf(double a, double b, double accuracy) {       return b <= accuracy ? a : gcdf(b, fmod(a, b), accuracy);     }   };   const int maxnD = 200000 + 5;   struct Dijkstra {     struct Edge {       int from, to, dist;     };     struct HeapNode {       int d, u;       bool operator<(const HeapNode &rhs) const { return d > rhs.d; }     };     vector<Edge> edges;     vector<int> G[maxnD];     bool done[maxnD];     int d[maxnD], p[maxnD], n, INF = 0x3f3f3f3f;     void init(int n) {       this->n = n;       for (int i = 0; i <= n; i++) G[i].clear();       edges.clear();     }     void AddEdge(int from, int to, int dist) {       edges.push_back((Edge){from, to, dist});       int m = edges.size();       G[from].push_back(m - 1);     }     void dijkstra(int s) {       priority_queue<HeapNode> q;       memset(d, INF, sizeof(d));       d[s] = 0;       memset(done, 0, sizeof(done));       q.push((HeapNode){0, s});       while (!q.empty()) {         HeapNode x = q.top();         q.pop();         int u = x.u;         if (done[u]) continue;         done[u] = true;         for (int i = 0; i < G[u].size(); i++) {           Edge &e = edges[G[u][i]];           if (d[e.to] > d[u] + e.dist) {             d[e.to] = d[u] + e.dist;             p[e.to] = G[u][i];             q.push((HeapNode){d[e.to], e.to});           }         }       }     }   };   const int INF = 0x3f3f3f3f;   const int maxn = 200000;   int ch[maxn * 20][2] = {0};   int cnt = 0;   void add(int *f) {     int root = 0;     for (int i = 0; i < 31; i++) {       if (!ch[root][f[i]]) ch[root][f[i]] = ++cnt;       root = ch[root][f[i]];     }   }   int dfs(int root) {     int ans = 0;     if (ch[root][0] && ch[root][1])       ans = max(dfs(ch[root][0]), dfs(ch[root][1])) + 1;     else if (ch[root][0])       ans = dfs(ch[root][0]);     else if (ch[root][1])       ans = dfs(ch[root][1]);     else       ans = 1;     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int num;     for (int i = 0; i < n; i++) {       cin >> num;       int f[31] = {0}, cur = 0;       while (num) f[cur++] = num % 2, num /= 2;       for (int q = 0; q < 15; q++) swap(f[q], f[31 - q - 1]);       add(f);     }     cout << n - dfs(0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[2 * 100001];   int color[2 * 100001];   void dfs(int s, int p, int clr, int pclr) {     color[s] = clr;     int y = 1;     for (int i = 0; i < v[s].size(); i++) {       int u = v[s][i];       if (u == p) continue;       while (y == clr || y == pclr) {         y++;       }       dfs(u, s, y, clr);       y++;     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     memset(color, 0, sizeof color);     dfs(1, 0, 1, -1);     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(ans, color[i]);     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       cout << color[i] <<    ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;         int main()   {       long long int t;       cin>>t;       while(t--)       {           long long int i,j,k,l,m,n,c1=0,c2=0,ans=0,res=0;           map<long long int,long long int>mp,mp1;           vector<long long int>v,v1,v2;           set<long long int>st,st1;           vector<pair<long long int,long long int>>vp,vp1;           cin>>n;           long long int arr1[n];           for(i=0;i<n;i++)cin>>arr1[i];           m=*min_element(arr1,arr1+n);           for(i=0;i<n;i++)           {               if(arr1[i]==m)c1++;               if((arr1[i]&m)!=m)c2++;           }           if(c1<2||c2!=0)cout<<0<<endl;           else           {ans=c1*(c1-1);           for(i=n-2;i>=1;i--)           ans=(ans*i)%1000000007;           cout<<ans<<endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s =  00  + s;     int l = s.length();     int fi = 0, fj = 0, i, j, k, num;     for (i = 0; i < l; i++) {       for (j = i + 1; j < l; j++) {         for (k = j + 1; k < l; k++) {           num = 100 * (s[i] -  0 ) + 10 * (s[j] -  0 ) + (s[k] -  0 );           if (num % 8 == 0) {             fi = fj = 1;             break;           }         }         if (fj) break;       }       if (fi) break;     }     if (fi) {       cout <<  YES  << endl;       for (int l = 2; l <= k; l++) {         if (l < i)           cout << s[l];         else {           if (l == i || l == j || l == k) cout << s[l];         }       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long n, long long lelo) {     if (n == 0) return 1;     if (n == 1) return a;     if (n == 2) return (a * a) % lelo;     if (n % 2)       return (a * power(a, n - 1, lelo)) % lelo;     else       return power(power(a, n / 2, lelo), 2, lelo) % lelo;   }   void swap(long long &a, long long &b) {     long long tm = a;     a = b;     b = tm;   }   const long long N = 1e+5;   bool comp(const pair<long long, long long> &p1,             const pair<long long, long long> &p2) {     if (p1.first != p2.first)       return p1.first > p2.first;     else       return p1.second < p2.second;   }   long long n, k;   vector<long long> v;   bool chk(long long x) {     for (long long(i) = (0); (i) < (n); (i)++)       if (abs(v[i] - x) > k) return 0;     return 1;   }   void solve() {     cin >> n >> k;     v.resize(n);     for (long long(i) = (0); (i) < (n); (i)++) cin >> v[i];     sort((v).begin(), (v).end());     long long t1 = v[0] + k, t2 = v[n - 1] - k;     if (v[n - 1] - v[0] <= k) {       cout << v[0] + k;       return;     }     if (t2 > t1) {       cout << -1;       return;     }     cout << t1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long double tt = 1.0 * clock();     long long t = 1;     cin >> t;     for (long long(i) = (1); (i) < (t + 1); (i)++) {       solve();       if (i < t) cout <<   n ;     }     tt = 1.000000000 * (clock() - tt) / CLOCKS_PER_SEC;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp_vector(const vector<int>& a, const vector<int>& b) {     int i;     for (i = 0; i < a.size(); i++) {       if (a[i] > b[i]) {         return false;       } else if (a[i] < b[i]) {         return true;       }     }     return false;   }   int main() {     int h, i, j, k;     int t, n, m;     int in;     scanf( %d , &n);     int c[n];     vector<vector<int> > a;     for (i = 0; i < n; i++) {       scanf( %d , &c[i]);       vector<int> e;       for (j = 0; j < c[i]; j++) {         scanf( %d , &in);         e.push_back(in);       }       a.push_back(e);     }     scanf( %d , &m);     vector<vector<int> > b;     for (i = 0; i < m; i++) {       vector<int> e;       for (j = 0; j < n; j++) {         scanf( %d , &in);         e.push_back(in - 1);       }       b.push_back(e);     }     sort(b.begin(), b.end(), cmp_vector);     vector<int> test(n);     int maxpower = 0;     vector<int> answer(n);     for (i = 0; i < n; i++) {       test[i] = c[i] - 1;     }     if (!binary_search(b.begin(), b.end(), test)) {       int power = 0;       for (i = 0; i < n; i++) {         power += a[i][test[i]];       }       if (power > maxpower) {         maxpower = power;         for (i = 0; i < n; i++) {           answer[i] = test[i];         }       }     }     for (i = 0; i < b.size(); i++) {       for (j = 0; j < n; j++) {         test[j] = b[i][j];       }       for (j = 0; j < n; j++) {         if (b[i][j] != 0) {           test[j]--;           if (!binary_search(b.begin(), b.end(), test)) {             int power = 0;             for (k = 0; k < n; k++) {               power += a[k][test[k]];             }             if (power > maxpower) {               maxpower = power;               for (k = 0; k < n; k++) {                 answer[k] = test[k];               }             }           }           test[j]++;         }       }     }     for (i = 0; i < n; i++) {       printf( %d  , answer[i] + 1);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)5e5 + 5;   vector<int> edges[MAXN];   int n;   int l[MAXN];   int r[MAXN];   int cur = 2;   void go(int node, int p = 0) {     int tt = 0;     for (int i : edges[node]) {       if (i == p) continue;       tt++;     }     r[node] = cur + tt;     int val = cur + tt - 1;     for (int i : edges[node]) {       if (i == p) continue;       l[i] = val;       val--;     }     cur = r[node] + 1;     for (int i : edges[node]) {       if (i == p) continue;       go(i, node);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);     }     l[1] = 1;     go(1);     for (int i = 1; i <= n; i++) cout << l[i] <<     << r[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE* in = stdin;   FILE* out = stdout;   const int MAX = 2002;   int n, k;   char a[MAX];   void solve() {     vector<pair<int, int> > ans;     int idx = 0;     while (k > 1) {       if (a[idx] !=  ( ) {         int nxt = idx + 1;         while (a[nxt] !=  ( ) nxt++;         ans.push_back(make_pair(idx, nxt));         reverse(a + idx, a + nxt + 1);       }       idx++;       if (a[idx] !=  ) ) {         int nxt = idx + 1;         while (a[nxt] !=  ) ) nxt++;         ans.push_back(make_pair(idx, nxt));         reverse(a + idx, a + nxt + 1);       }       idx++;       k--;     }     int rem = (n - idx) / 2;     for (int i = 0; i < rem; i++) {       if (a[idx + i] ==  ( ) {         continue;       } else {         int nxt = idx + i + 1;         while (a[nxt] !=  ( ) nxt++;         ans.push_back(make_pair(idx + i, nxt));         reverse(a + idx + i, a + nxt + 1);       }     }     fprintf(out,  %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++)       fprintf(out,  %d %d n , ans[i].first + 1, ans[i].second + 1);   }   int main(void) {     int numTests;     fscanf(in,  %d , &numTests);     for (int test = 0; test < numTests; test++) {       fscanf(in,  %d %d , &n, &k);       fscanf(in,  %s , a);       solve();     }     return 0;   }


// Omar_Elaraby   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define EPS 1e-9      int main() {    ios::sync_with_stdio(false);    cin.tie(0), cout.tie(0);   // freopen( in.txt ,  r , stdin);   // freopen( out.txt ,  w , stdout);       int tt;    cin >> tt;    while (tt--) {     long long p;     vector<ll> v(3);     cin >> p;     for (ll &i : v) {      cin >> i;     }        long long ans = LLONG_MAX;     for (int i = 0; i < 3; ++i) {      if (v[i] >= p) ans = min(ans, v[i] - p);      else ans = min(ans, v[i] * ((p + v[i] - 1) / v[i]) - p);     }     cout << ans <<   n ;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int n, m, z;   int mapp[maxn][maxn][maxn];   bool vis[maxn][maxn][maxn];   string s;   int main() {     int ans = 0, num;     memset(vis, false, sizeof(vis));     memset(mapp, 0, sizeof(mapp));     scanf( %d%d%d , &n, &m, &z);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> s;         for (int k = 0; k < z; k++) {           if (s[k] ==  1 ) mapp[i][j][k + 1] = 1;         }       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 1; k <= z; k++) {           if (mapp[i][j][k]) {             if (mapp[i - 1][j][k] && mapp[i + 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j - 1][k] && mapp[i][j + 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j][k - 1] && mapp[i][j][k + 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i + 1][j][k] && mapp[i][j - 1][k] &&                 !mapp[i + 1][j - 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i - 1][j + 1][k] && mapp[i][j + 1][k] &&                 mapp[i - 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i + 1][j][k] && mapp[i][j][k - 1] &&                 !mapp[i + 1][j][k - 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i - 1][j][k + 1] && mapp[i][j][k + 1] &&                 mapp[i - 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j + 1][k] && mapp[i][j][k - 1] &&                 !mapp[i][j + 1][k - 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i][j - 1][k + 1] && mapp[i][j][k + 1] &&                 mapp[i][j - 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }           }         }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   template <class T>   void _db(const char* dbStr, T e) {     cout << dbStr <<   =   << e << endl;   }   template <class T, class... L>   void _db(const char* dbStr, T e, L... r) {     while (*dbStr !=  , ) cout << *dbStr++;     cout <<   =   << e <<  , ;     _db(dbStr + 1, r...);   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& v) {     o <<  [ ;     int i = 0;     for (const pair<S, T>& pr : v)       o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ;     return o <<  ] ;   }   template <template <class, class...> class S, class T, class... L>   ostream& operator<<(ostream& o, const S<T, L...>& v) {     o <<  [ ;     int i = 0;     for (const auto& e : v) o << (!i++ ?    :  ,  ) << e;     return o <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& pr) {     return o <<  (  << pr.first <<  ,   << pr.second <<  ) ;   }   ostream& operator<<(ostream& o, const string& s) {     for (const char& c : s) o << c;     return o;   }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   using VVV = VV<V<T>>;   using ll = long long;   using pii = pair<int, int>;   using vi = V<int>;   using vii = V<pii>;   using vvi = VV<int>;   using mii = map<int, int>;   using umii = unordered_map<int, int>;   using si = set<int>;   using usi = unordered_set<int>;   int n, r, c;   V<string> s;   vi sum;   vvi adj;   vi path;   pii ans = make_pair(0, 0);   bool good(int i, int j) { return sum[j] - sum[i - 1] + (j - i) > c; }   void dfs(int u, int p) {     path.push_back(u);     int l = path[max(int(path.size()) - 1 - r, 0)] - u;     true;     if (l > ans.first) ans = make_pair(l, u);     for (auto& v : adj[u]) {       if (v != p) dfs(v, u);     }     path.pop_back();   }   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     cin >> n >> r >> c;     s.assign(n + 2,   );     sum.assign(n + 2, 0);     adj.assign(n + 2, vi());     for (int i = 1; i <= n; ++i) {       cin >> s[i];       sum[i] = sum[i - 1] + int(s[i].size());     }     sum.back() = OO;     vi next(n + 2, n + 1);     for (int i = 1; i <= n; ++i) {       int lo = i, hi = n + 1;       while (lo < hi) {         int mid = (lo + hi) / 2;         if (good(i, mid))           hi = mid;         else           lo = mid + 1;       }       true;       next[i] = lo;       adj[next[i]].push_back(i);     }     true;     for (int i = 1; i <= n + 1; ++i) {       if (next[i] == i) dfs(i, i);     }     true;     if (!ans.first)       cout <<   n ;     else {       for (int l = ans.second, r = ans.second + ans.first, Sz = int(s[l].size());            l < r; ++l) {         cout << s[l];         if (l + 1 == r || (l + 1 < r && Sz + 1 + int(s[l + 1].size()) > c)) {           cout <<   n ;           Sz = int(s[l + 1].size());         } else {           cout <<    ;           Sz += 1 + int(s[l + 1].size());         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int j = 0; j < q; j++) {       int n;       long long int k;       cin >> n >> k;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       long long int mi, ma;       mi = a[0];       ma = a[n - 1];       long long int diff = ma - mi;       if (diff % 2 == 0)         diff = diff / 2;       else         diff = diff / 2 + 1;       if (k >= diff) {         cout << mi + k << endl;       } else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using vvvi = vector<vvi>;   using ll = long long;   using vll = vector<ll>;   using vvll = vector<vll>;   using vvvll = vector<vvll>;   using ull = unsigned long long;   using vb = vector<bool>;   using vvb = vector<vb>;   using vd = vector<double>;   using vvd = vector<vd>;   using vvvd = vector<vvd>;   using vs = vector<string>;   using vvs = vector<vs>;   using vc = vector<char>;   using vvc = vector<vc>;   using ii = pair<int, int>;   using vii = vector<ii>;   using vvii = vector<vii>;   using dd = pair<double, double>;   using vdd = vector<dd>;   using vvdd = vector<vdd>;   using Mii = map<int, int>;   using vMii = vector<Mii>;   using Si = set<int>;   using vSi = vector<Si>;   using vvSi = vector<vSi>;   int main() {     int n;     while (cin >> n) {       vi a;       vector<pair<ll, ll>> v(n);       for (int i = 0; i < n; ++i) {         int x, y;         cin >> x >> y;         v[i] = {x, y};       }       vll d(n);       for (int i = 0; i < n; ++i) {         d[i] = (v[i].first - v[0].first) * (v[i].first - v[0].first) +                (v[i].second - v[0].second) * (v[i].second - v[0].second);       }       bool par = true;       for (int i = 0; i < n and par; ++i) {         if (d[i] & 1LL) par = false;       }       while (par) {         for (int i = 0; i < n; ++i) {           d[i] >>= 1LL;           if (d[i] & 1LL) par = false;         }       }       for (int i = 0; i < n; ++i)         if (d[i] & 1LL) a.push_back(i + 1);       cout << a.size() << endl;       for (int x : a) cout << x <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   signed long long mo = 1000000007;   signed long long ret = 1;   signed long long from[303][303];   signed long long to[303][303];   signed long long combi(int P_, int Q_) {     static const int N_ = 1020;     static signed long long C_[N_][N_];     if (C_[0][0] == 0) {       int i, j;       for (i = 0; i < (N_); i++) C_[i][0] = C_[i][i] = 1;       for (i = 1; i < N_; i++)         for (j = 1; j < i; j++) C_[i][j] = (C_[i - 1][j - 1] + C_[i - 1][j]) % mo;     }     if (P_ < 0 || P_ > N_ || Q_ < 0 || Q_ > P_) return 0;     return C_[P_][Q_];   }   signed long long hcomb(int P_, int Q_) {     return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_);   }   void solve() {     int i, j, k, l, r, x, y;     string s;     map<int, int> M;     cin >> N;     for (i = 0; i < (N); i++) {       cin >> x;       for (j = 2; j * j <= x; j++)         while (x % (j * j) == 0) x /= j * j;       M[x]++;     }     from[1][0] = 1;     for (auto& r : M) {       int cnt = r.second;       for (j = 1; j <= cnt; j++) ret = ret * j % mo;       memset(to, 0, sizeof(to));       for (x = 0; x < (N + 2); x++)         for (y = 0; y < (N + 2); y++)           if (from[x][y]) {             for (j = 1; j <= min(x + y, cnt); j++) {               signed long long a = hcomb(j, cnt - j);               int add = cnt - j;               for (int z = 0; z <= min(j, x); z++) {                 int w = j - z;                 if (w > y) continue;                 signed long long b = combi(x, z);                 signed long long c = combi(y, w);                 (to[x + z + 2 * w][y - w + add] +=                  a * b % mo * c % mo * from[x][y]) %= mo;               }             }           }       swap(from, to);     }     cout << ret * from[N + 1][0] % mo << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 52;   struct node {     int v, w, nxt;   } e[N << 1];   int s, n, m, first[N], cnt = 1, siz[N], de[N];   inline void add(int u, int v, int w) {     e[++cnt].v = v;     e[cnt].w = w;     e[cnt].nxt = first[u];     first[u] = cnt;     ++de[u];   }   inline void dfs(int u, int f) {     for (int i = first[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (v == f) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   int dp[N << 1][N][N];   inline int solve(int i, int x, int y) {     if (x + y == 0) return 0;     int v = e[i].v;     int &f = dp[i][x][y];     if (f != -1) return f;     if (de[v] == 1) {       if (y == 0)         return 0;       else {         f = solve(i ^ 1, y, 0) + e[i].w;         return f;       }     }     int g[N];     memset(g, 0, sizeof(g));     g[0] = 0x3f3f3f3f;     for (int j = first[v]; j; j = e[j].nxt) {       if (j == (i ^ 1)) continue;       for (int k = x; k >= 1; --k)         for (int w = k; w; --w)           g[k] = max(g[k], min(g[k - w], e[j].w + solve(j, w, x + y - w)));     }     return f = g[x];   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d , &n);     for (int i = 1, u, v, w; i < n; ++i) {       scanf( %d%d%d , &u, &v, &w);       add(u, v, w);       add(v, u, w);     }     scanf( %d%d , &s, &m);     for (int i = 1, x; i <= m; ++i) {       scanf( %d , &x);       siz[x]++;     }     dfs(s, 0);     int ans = 0x3f3f3f3f;     for (int i = first[s]; i; i = e[i].nxt) {       int v = e[i].v;       ans = min(ans, solve(i, siz[v], m - siz[v]) + e[i].w);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct chip {     char dir;     chip *u, *r, *d, *l;     chip(char _dir) {       dir = _dir;       u = r = d = l = NULL;     }   };   int main(int argc, char* argv[]) {     int n, m;     cin >> n >> m;     chip*** t;     t = (chip***)malloc(n * sizeof(chip**));     for (int i = 0; i < n; i++) t[i] = (chip**)malloc(m * sizeof(chip*));     char d;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> d;         if (d !=  . ) {           t[i][j] = new chip(d);           if (i > 0) {             int k = i - 1;             while ((k >= 0) && (t[k][j] == NULL)) k--;             if (k >= 0) {               t[k][j]->d = t[i][j];               t[i][j]->u = t[k][j];             }           }           if (j > 0) {             int k = j - 1;             while ((k >= 0) && (t[i][k] == NULL)) k--;             if (k >= 0) {               t[i][k]->r = t[i][j];               t[i][j]->l = t[i][k];             }           }         } else           t[i][j] = NULL;       }     }     int max = 0;     int count = 0;     vector<chip*> v;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         v.clear();         chip* c = t[i][j];         while (c != NULL) {           v.push_back(c);           chip* e;           if (c->dir ==  U ) e = c->u;           if (c->dir ==  R ) e = c->r;           if (c->dir ==  D ) e = c->d;           if (c->dir ==  L ) e = c->l;           if (c->u != NULL) c->u->d = c->d;           if (c->r != NULL) c->r->l = c->l;           if (c->d != NULL) c->d->u = c->u;           if (c->l != NULL) c->l->r = c->r;           c = e;         }         if (v.size() > max) {           max = v.size();           count = 0;         }         if (v.size() == max) count++;         for (vector<chip*>::reverse_iterator r = v.rbegin(); r < v.rend(); r++) {           chip* e = *r;           if (e->u != NULL) e->u->d = e;           if (e->r != NULL) e->r->l = e;           if (e->d != NULL) e->d->u = e;           if (e->l != NULL) e->l->r = e;         }       }     }     cout << max <<     << count << endl;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) free(t[i][j]);     for (int i = 0; i < n; i++) free(t[i]);     free(t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 102;   const int K_MAX = 10002;   const int MOD = 1e9 + 7;   int pwr(int a, long long b) {     if (b == 0) return 1;     if (b & 1) return 1LL * a * pwr(a, (b ^ 1)) % MOD;     int aux = pwr(a, (b >> 1));     return 1LL * aux * aux % MOD;   }   int n, k;   long long m;   int comb[N_MAX];   int pw[N_MAX][N_MAX];   int dp[N_MAX][K_MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i <= n; i++) {       comb[i] = 1;       for (int j = i + 1; j <= n; j++) comb[i] = 1LL * comb[i] * j % MOD;       for (int j = 1; j <= n - i; j++)         comb[i] = 1LL * comb[i] * pwr(j, MOD - 2) % MOD;     }     for (int c = 0; c <= n; c++)       for (int i = 1; i <= n; i++) pw[c][i] = pwr(comb[c], (m - i) / n + 1);     dp[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= k; j++) {         for (int c = 0; c <= j && c <= n; c++) {           dp[i][j] += 1LL * dp[i - 1][j - c] * pw[c][i] % MOD;           if (dp[i][j] >= MOD) dp[i][j] -= MOD;         }       }     cout << dp[n][k] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> A(n + 7);     for (int i = 1; i <= n; i++) cin >> A[i];     vector<int> B(n);     for (int i = 1; i <= n; i++) B[i - 1] = i;     sort(B.begin(), B.end(), [&](int a, int b) { return A[a] > A[b]; });     set<int> G, S;     multiset<int> O;     G.insert(0);     G.insert(n + 1);     O.insert(n + 1);     int ret = A[B[0]] + 1, loc = 1;     for (int bb = 0; bb < n; bb++) {       int b = B[bb];       auto jt = G.upper_bound(b);       auto it = prev(jt);       int dif = (*jt - *it);       O.erase(O.find(dif));       int p = (*jt - b);       int q = (b - *it);       if (p != 1) O.insert(p);       if (q != 1) O.insert(q);       if ((O.empty() or *O.begin() == *O.rbegin()) and loc <= int(O.size())) {         loc = int(O.size());         ret = A[B[bb + 1]] + 1;       }       G.insert(b);     }     cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = (long long int)1e9 + 7;   long long int powmod(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b = b >> 1;     }     return res % MOD;   }   vector<vector<long long int> > G;   void solve(long long int testnum) {     long long int n, m;     cin >> n >> m;     G.resize(n + 1);     vector<long long int> tt(n + 1, 0);     for (long long int i = 0; i < m; i++) {       long long int a, b;       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     vector<pair<long long int, long long int> > bc;     for (long long int i = 1; i <= n; i++) {       long long int temp;       cin >> temp;       bc.push_back(make_pair(temp, i));     }     sort(bc.begin(), bc.end());     long long int check = 0;     for (long long int i = 0; i < bc.size(); i++) {       tt[bc[i].second] = bc[i].first;       vector<long long int> naap;       for (long long int j = 0; j < G[bc[i].second].size(); j++) {         naap.push_back(tt[G[bc[i].second][j]]);       }       if (naap.size() == 0) {         if (bc[i].first != 1) {           check = 1;         }         continue;       }       sort(naap.begin(), naap.end());       for (long long int k = 0; k < naap.size(); k++) {         long long int temp = naap[k];         if (k > 0) {           temp -= naap[k - 1];         }         if (temp > 1) {           check = 1;         }       }       if (naap[naap.size() - 1] != bc[i].first - 1) {         check = 1;       }     }     if (check == 1) {       cout <<  -1 n ;       return;     }     for (long long int i = 0; i < n; i++) {       cout << bc[i].second <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     for (long long int i = 1; i <= t; i++) {       solve(i);     }   }


#include <bits/stdc++.h>   using namespace std;   struct Update {     int cost, profit;     Update(int cost, int profit) : cost(cost), profit(profit) {}   };   struct CommutativeUndoableDS {     const int MAX_COST = 4000;     vector<vector<int> > stk;     CommutativeUndoableDS() { stk.emplace_back(MAX_COST + 1, 0); }     void addUpdate(Update u) {       int sz = stk.size();       stk.push_back(stk.back());       for (int i = MAX_COST; i >= u.cost; i--) {         stk[sz][i] = max(stk[sz][i], stk[sz - 1][i - u.cost] + u.profit);       }     }     void undoLastUpdate() {       stk.pop_back();       assert(!stk.empty());     }     int bestProfitWith(int budget) { return stk.back()[budget]; }   };   struct QueueUndoDS {     vector<pair<Update, int> > qyu;     CommutativeUndoableDS ds;     void pushBack(pair<Update, int> u) {       ds.addUpdate(u.first);       qyu.push_back(u);     }     void pushBack(Update u) { pushBack(pair<Update, int>(u, 0)); }     void popFront() {       assert(!qyu.empty());       vector<pair<Update, int> > popped[2];       while (!qyu.empty()) {         ds.undoLastUpdate();         popped[qyu.back().second].push_back(qyu.back());         qyu.pop_back();         if (popped[1].size() >= popped[0].size()) break;       }       if (popped[1].empty()) {         for (pair<Update, int> &u : popped[0]) {           u.second = 1;           pushBack(u);         }       } else {         for (int i : {0, 1}) {           reverse(popped[i].begin(), popped[i].end());           for (pair<Update, int> &u : popped[i]) pushBack(u);         }       }       ds.undoLastUpdate();       qyu.pop_back();     }   };   const int MAX_TIME = 20001;   vector<Update> startsAt[MAX_TIME];   vector<Update> endsAt[MAX_TIME];   vector<pair<int, int> > askAt[MAX_TIME];   int ans[MAX_TIME];   int main() {     int n, p;     cin >> n >> p;     while (n--) {       int c, h, t;       cin >> c >> h >> t;       startsAt[t].emplace_back(c, h);       endsAt[t + p - 1].emplace_back(c, h);     }     int q;     cin >> q;     for (int i = 1; i <= q; i++) {       int a, b;       cin >> a >> b;       askAt[a].emplace_back(i, b);     }     QueueUndoDS knapsackQueuUndo;     for (int t = 1; t < MAX_TIME; t++) {       for (Update u : startsAt[t]) {         knapsackQueuUndo.pushBack(u);       }       for (pair<int, int> query : askAt[t]) {         ans[query.first] = knapsackQueuUndo.ds.bestProfitWith(query.second);       }       for (Update u : endsAt[t]) {         knapsackQueuUndo.popFront();       }     }     for (int i = 1; i <= q; i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:200000000 )   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   string s[110000];   int n, k, z[110][110], dp[1100000];   char buf[110000];   int main() {     scanf( %d%d n , &n, &k);     for (int i = 0; i < (int)(n); i++) {       scanf( %s , buf);       s[i] = buf;     }     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(n); j++) {         int ans = 0;         while (ans < (int)s[i].size() && ans < (int)s[j].size() &&                s[i][ans] == s[j][ans])           ans++;         z[i][j] = ans;       }     int res = 0;     for (int msk = 1; msk < (1 << n); msk++) {       int cur;       for (int i = 0; i < (int)(n); i++)         if (msk & (1 << i)) {           cur = i;           break;         }       int val = dp[msk ^ (1 << cur)], cnt = 0;       for (int i = 0; i < (int)(n); i++)         if ((msk & (1 << i)) && i != cur) {           val += z[i][cur];           cnt++;         }       if (cnt + 1 == k) res = max(res, val);       dp[msk] = val;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   template <typename TT, int V, int E>   struct DinicFlow {     int ds[V + 1], q[V + 1], nx[E + 1], last[V + 1], ver[E + 1], now[V + 1], n,         edgesCount, S, T;     TT cap[E + 1], flow[E + 1];     DinicFlow() : n(0), S(0), T(0), edgesCount(0) {}     DinicFlow(int _n) : n(_n), S(0), T(0), edgesCount(0) {}     inline void reset(int _n) {       edgesCount = 0;       n = _n;       memset(last, -1, n * sizeof(int));     }     inline void addEdge(int v, int w, TT c, TT rc) {       ver[edgesCount] = w;       cap[edgesCount] = c;       flow[edgesCount] = 0;       nx[edgesCount] = last[v];       last[v] = edgesCount++;       ver[edgesCount] = v;       cap[edgesCount] = rc;       flow[edgesCount] = 0;       nx[edgesCount] = last[w];       last[w] = edgesCount++;     }     inline bool bfs() {       memset(ds, 63, n * sizeof(int));       int a = 0, b = 0;       ds[T] = 0;       q[0] = T;       while (a <= b) {         int v = q[a++];         for (int w = last[v]; w >= 0; w = nx[w]) {           if (cap[w ^ 1] - flow[w ^ 1] && ds[ver[w]] > ds[v] + 1) {             ds[ver[w]] = ds[v] + 1;             q[++b] = ver[w];           }         }       }       return ds[S] < 1000000000;     }     TT dfs(int v, TT cur) {       if (v == T) return cur;       for (int &w = now[v]; w >= 0; w = nx[w]) {         if (cap[w] - flow[w] && ds[ver[w]] == ds[v] - 1) {           TT rr = dfs(ver[w], min(cur, cap[w] - flow[w]));           if (rr) {             flow[w] += rr;             flow[w ^ 1] -= rr;             return rr;           }         }       }       return 0;     }     inline TT maxFlow() {       TT ans = 0;       while (bfs()) {         memcpy(now, last, n * sizeof(int));         TT tf;         while (tf = dfs(S, 1000000000)) ans += tf;       }       return ans;     }   };   int a, b, c, d, n, m, k;   DinicFlow<int, 205, 2100> q;   int ds[202][202];   bool used[202];   int main() {     scanf( %d%d , &n, &m);     q.reset(n + 2);     for (int _n((m)-1), i(0); i <= _n; i++) {       scanf( %d%d%d , &a, &b, &c);       --a;       --b;       q.addEdge(a, b, c, c);     }     for (int _n((n)-1), i(0); i <= _n; i++) {       for (int _n((i)-1), j(0); j <= _n; j++) {         memset((q.flow), 0, sizeof(q.flow));         q.S = i;         q.T = j;         ds[i][j] = ds[j][i] = q.maxFlow();       }     }     vector<int> ans;     int mx = 0;     for (int _n((n)-1), i(0); i <= _n; i++) {       for (int _n((i)-1), j(0); j <= _n; j++) {         if (ds[i][j] > mx) {           ans.clear();           ans.push_back(i);           ans.push_back(j);           mx = ds[i][j];         }       }     }     memset((used), 0, sizeof(used));     used[ans[0]] = used[ans[1]] = 1;     while ((int)((ans).size()) < n) {       int mx = -1, v = -1;       for (int _n((n)-1), i(0); i <= _n; i++) {         if (used[i]) continue;         if (ds[ans.back()][i] > mx) {           mx = ds[ans.back()][i];           v = i;         }       }       ans.push_back(v);       used[v] = 1;     }     int res = 0;     for (int _n(((int)((ans).size()) - 1) - 1), i(0); i <= _n; i++)       res += ds[ans[i]][ans[i + 1]];     printf( %d n , res);     for (int _n(((int)((ans).size())) - 1), i(0); i <= _n; i++) {       if (i) printf(   );       printf( %d , ans[i] + 1);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3010], vert;   map<int, vector<pair<int, int> > > query[3010];   int ans[400010], vis[3010], in_cycle;   void dfs(int v, int par) {     vis[v] = 1;     if (!in_cycle) vert.push_back(v);     if (query[par].count(v)) {       vector<pair<int, int> > *ptr = &query[par][v];       int vert_size = vert.size();       for (auto p : *ptr) {         ans[p.second] =             ((p.first > vert_size || in_cycle) ? -1 : vert[p.first - 1]);       }     }     for (int i = 0; i < adj[v].size(); ++i) {       int t = adj[v][i];       if (vis[t] == 0)         dfs(t, par);       else if (vis[t] == 1) {         ++in_cycle;         ++vis[t];       }     }     if (v == vert.back()) vert.pop_back();     if (vis[v] > 1)       --in_cycle;     else       vis[v] = 2;   }   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);     }     for (int i = 1; i <= n; ++i) {       sort(adj[i].begin(), adj[i].end());     }     for (int i = 0; i < q; ++i) {       int s, t, k;       scanf( %d %d %d , &s, &t, &k);       query[s][t].push_back(make_pair(k, i));     }     for (int i = 0; i < q; ++i) ans[i] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) vis[j] = 0;       in_cycle = 0;       dfs(i, i);     }     for (int i = 0; i < q; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 9;   int arr[maxn], ar[maxn];   int main() {     int a, b, c, d, e, f, g, h;     while (cin >> a) {       cin >> e >> f;       for (int i = 1; i <= a; i++) {         cin >> arr[i];       }       for (int i = 1; i <= a; i++) {         cin >> ar[i];       }       g = 1;       for (int i = 1; i < e; i++) {         if (arr[i] != ar[i]) {           g = 0;           break;         }       }       for (int i = f + 1; i <= a; i++) {         if (arr[i] != ar[i]) {           g = 0;           break;         }       }       map<int, int> ma1, ma2;       for (int i = e; i <= f; i++) {         ma1[arr[i]]++;         ma2[ar[i]]++;       }       if (ma1 != ma2) g = 0;       if (!g) {         cout <<  LIE  << endl;       } else {         cout <<  TRUTH  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 6e5 + 5;   int l[maxm], r[maxm];   int c[maxm];   int pos[maxm];   int n, m;   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int lowbit(int i) { return i & -i; }   void add(int i, int t) {     while (i < maxm) {       c[i] += t;       i += lowbit(i);     }   }   int ask(int i) {     int ans = 0;     while (i) {       ans += c[i];       i -= lowbit(i);     }     return ans;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       l[i] = r[i] = i;       add(i + m, 1);       pos[i] = i + m;     }     int last = m;     while (m--) {       int x;       cin >> x;       l[x] = 1;       int num = ask(pos[x]);       r[x] = max(r[x], num);       if (num == 1) continue;       add(pos[x], -1);       pos[x] = last;       add(pos[x], 1);       last--;     }     for (int i = 1; i <= n; i++) {       r[i] = max(r[i], ask(pos[i]));     }     for (int i = 1; i <= n; i++) {       cout << l[i] <<     << r[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   int size(T& a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   int offset;   int f[1000000 * 4 + 10];   int start[27];   int getmask(int l, int r) {     int res = 0;     for (l += offset, r += offset; l <= r; l /= 2, r /= 2) {       if (l % 2 == 1) {         res |= f[l++];       }       if (r % 2 == 0) {         res |= f[r--];       }     }     return res;   }   vector<int> pos[27];   int ans[10000];   map<int, int> num;   int cnt[27][10000];   int g[10000];   int main() {     string s;     cin >> s;     s += (char)( z  + 1);     offset = 1;     while (offset < size(s)) offset *= 2;     memset((f), (0), sizeof(f));     for (int i = offset; i < offset + size(s); ++i) {       f[i] = 1 << (s[i - offset] -  a );     }     for (int i = offset - 1; i >= 1; --i) {       f[i] = f[2 * i] | f[2 * i + 1];     }     for (int i = 0; i < size(s); ++i) {       pos[s[i] -  a ].push_back(i);     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       string e;       cin >> e;       int mask = 0;       for (int j = 0; j < e.length(); ++j) {         mask |= 1 << (e[j] -  a );       }       g[i] = mask;       num[mask] = i;     }     for (int i = 0; i < size(s) - 1; ++i) {       for (int b = 0; b < 27; ++b) {         if (s[i] -  a  == b) continue;         while (start[b] < pos[b].size() && pos[b][start[b]] < i) {           ++start[b];         }         if (start[b] < pos[b].size() && pos[b][start[b]] >= i) {           int m = getmask(i, pos[b][start[b]] - 1);           if (i > 0 && (m & (1 << (s[i - 1] -  a ))) != 0) continue;           if (!num.count(m)) continue;           cnt[b][num[m]]++;         }       }     }     for (int i = 0; i < q; ++i) {       int res = 0;       for (int b = 0; b < 27; ++b)         if ((g[i] & (1 << b)) == 0) {           res += cnt[b][num[g[i]]];         }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string g[51];   int pre[52][52];   int dp[51][51][51][51];   bool chk(int x1, int x2, int y1, int y2) {     int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1];     if (r >= 1) return true;     return false;   }   int fun(int r1, int r2, int c1, int c2) {     if (chk(r1, r2, c1, c2) == false) return 0;     if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2];     int ans = max((r2 - r1 + 1), (c2 - c1 + 1));     for (int i = r1; i < r2; i++)       ans = min(ans, fun(r1, i, c1, c2) + fun(i + 1, r2, c1, c2));     for (int j = c1; j < c2; j++) {       ans = min(ans, fun(r1, r2, c1, j) + fun(r1, r2, j + 1, c2));     }     return dp[r1][r2][c1][c2] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i += 1) cin >> g[i];     pre[0][0] = 1;     for (int i = 0; i < n; i++) {       pre[i][0] = pre[0][i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (g[i][j] ==  # ) pre[i + 1][j + 1] = 1;         pre[i + 1][j + 1] += (pre[i][j + 1] + pre[i + 1][j] - pre[i][j]);       }     }     int ans = fun(1, n, 1, n);     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define pb push_back   #define ff first   #define ss second   #define mod 1000000007   #define t5 100005   #define inf 100000000000000000   ll ask(ll t,ll i,ll j , ll x){    cout << ?  << t <<     << i <<     << j <<     << x << endl;    ll temp;    cin >> temp;    return temp;   }   void solve(){    ll n;    cin>> n;    ll pos = 0;    for(ll i=1 ;  i<n ; i+=2){     ll q;     q = ask(2,i,i+1,1);     if(q == 1){      pos = i;      break;     }     else if(q == 2){      q = ask(2,i+1,i,1);      if(q == 1){       pos = i+1;       break;      }     }    }    if(!pos)     pos = n;    vector <ll> v(n+1);    for(ll i=1 ; i<=n ; i++){     if(i==pos){      v[i] = 1;     }     else{      ll q = ask(1,pos,i,n-1);      v[i] = q;     }    }    cout << ! ;    for(ll i=1 ; i<=n ; i++){     cout <<    << v[i];    }    cout << endl;   }   int main(){    ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);    ll t;    cin >> t;    while(t--){     solve();    }        return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int>> a(n);     vector<int> diff(n), dp(n + 1), take(n + 1);     for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i;     sort(a.begin(), a.end());     if (n < 6) {       cout << a[n - 1].first - a[0].first <<     << 1 << endl;       for (int i = 0; i < n; i++) cout << 1 <<    ;       return 0;     }     for (int i = 0; i < n - 1; i++) diff[i] = a[i + 1].first - a[i].first;     dp[2] = diff[2];     take[2] = 1;     for (int i = 3; i < n - 3; i++) {       if (dp[i - 3] + diff[i] > dp[i - 1]) {         take[i] = 1;         dp[i] = dp[i - 3] + diff[i];       } else {         dp[i] = dp[i - 1];       }     }     vector<int> ans(n);     int cnt = 1;     for (int i = n - 1; i >= 0;) {       if (take[i]) {         ++cnt;         for (int j = 0; j < 3; j++) ans[a[i--].second] = cnt;       } else         ans[a[i--].second] = cnt;     }     cout << a[n - 1].first - a[0].first - dp[n - 4] <<     << cnt << endl;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }