#include <bits/stdc++.h>   int main() {     long long n, m, i;     scanf( %lld%lld , &n, &m);     printf( YES n );     for (i = n; i < m; i += 2) printf( %lld %lld n , i, i + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int ttt;     cin >> ttt;     for (long long int iq = 0; iq < ttt; ++iq) {       long long int n, e = 0;       cin >> n;       long long int s = n % 10;       while (n >= 10) {         n = n / 10;         n = n * 10;         e += n;         n = n / 10;         n += s;         s = n % 10;       }       cout << e + s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<char>> grid;   vector<pair<int, int>> wind;   int n, m;   int k;   int t;   int w;   unordered_map<char, pair<int, int>> charToDir;   vector<pair<int, int>> dirs({pair<int, int>(1, 0), pair<int, int>(-1, 0),                                pair<int, int>(0, 1), pair<int, int>(0, -1),                                pair<int, int>(0, 0)});   pair<int, int> getLocation(char c) {     for (int i = 0; i < ((int)(grid).size()); ++i)       for (int j = 0; j < ((int)(grid[i]).size()); ++j) {         if (grid[i][j] == c) {           return pair<int, int>(i, j);         }       }     assert(false);     return pair<int, int>(0, 0);   }   bool legal(pair<int, int> a) {     int i = a.first;     int j = a.second;     return !(i < 0 || j < 0 || i >= n || j >= m) && grid[i][j] !=  L ;   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(cin.failbit);     charToDir[ S ] = pair<int, int>(1, 0);     charToDir[ N ] = pair<int, int>(-1, 0);     charToDir[ E ] = pair<int, int>(0, 1);     charToDir[ W ] = pair<int, int>(0, -1);     charToDir[ X ] = pair<int, int>(0, 0);     cin >> n >> m;     cin >> k;     cin >> t;     cin >> w;     grid.resize(n, vector<char>(m));     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j) cin >> grid[i][j];     wind.resize(w);     for (int i = 0; i < (w); ++i) {       char c;       cin >> c;       wind[i] = charToDir[c];     }     vector<vector<vector<bool>>> shop(4010,                                       vector<vector<bool>>(n, vector<bool>(m)));     for (int i = 0; i < (t); ++i) {       int y, x, f;       cin >> y >> x >> f;       shop[f][y][x] = true;     }     pair<int, int> startLocation = getLocation( M );     pair<int, int> goal = getLocation( P );     vector<vector<int>> maxFood(n, vector<int>(m, -1));     maxFood[startLocation.first][startLocation.second] = k;     for (int d = 0; d < (w); ++d) {       vector<vector<int>> newMaxFood(n, vector<int>(m, -1));       bool changedSomething = false;       for (int i = 0; i < (n); ++i)         for (int j = 0; j < (m); ++j)           if (maxFood[i][j] > 0) {             for (auto& movement : dirs) {               int newI = i + movement.first;               int newJ = j + movement.second;               pair<int, int> a(newI, newJ);               pair<int, int> windMovement = wind[d];               newI += windMovement.first;               newJ += windMovement.second;               pair<int, int> b(i + windMovement.first, j + windMovement.second);               if (newI != i || newJ != j) {                 if (!legal(a) && !legal(b)) continue;                 if (!legal(pair<int, int>(newI, newJ))) continue;               }               newMaxFood[newI][newJ] =                   max(newMaxFood[newI][newJ], maxFood[i][j] - 1);               changedSomething = true;               if (shop[d + 1][newI][newJ]) {                 newMaxFood[newI][newJ] = k;               }               if (pair<int, int>(newI, newJ) == goal) {                 cout << d + 1 << endl;                 return 0;               }             }           }       if (!changedSomething) {         cout << -1 << endl;         return 0;       }       maxFood = newMaxFood;     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     long long int n, k;     cin >> t;     while (t--) {       cin >> n >> k;       if (n < k * k) {         cout <<  NO  << endl;         continue;       } else {         if ((n % 2 == 1 && k % 2 == 1) || (n % 2 == 0 && k % 2 == 0))           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     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;   int n, m;   vector<int> a;   bool chk(int c) {     int lst = a[0];     if (a[0] + c >= m) lst = 0;     for (int i = 1; i <= (n - 1); ++i) {       if (a[i] + c >= m + lst) continue;       if (a[i] < lst && a[i] + c >= lst) continue;       if (a[i] + c < lst) return false;       lst = a[i];     }     return true;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     cin >> n >> m;     a.resize(n);     for (int i = 0; i < (n); ++i) cin >> a[i];     bool sorted = true;     for (int i = 0; i < (n); ++i) {       if (i != 0 && a[i - 1] > a[i]) sorted = false;     }     if (sorted) {       cout << 0 << endl;       return 0;     }     int lo = 0, hi = m, mid = (hi + lo) / 2;     while (hi - lo > 1) {       if (chk(mid))         hi = mid;       else         lo = mid;       mid = (hi + lo) / 2;     }     cout << hi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   bool lt(double a, double b) { return a + eps < b; }   bool gt(double a, double b) { return lt(b, a); }   bool eq(double a, double b) { return !lt(a, b) && !gt(a, b); }   bool lte(double a, double b) { return lt(a, b) || eq(a, b); }   bool gte(double a, double b) { return gt(a, b) || eq(a, b); }   double dmin(double a, double b) { return lt(a, b) ? a : b; }   double dmax(double a, double b) { return gt(a, b) ? a : b; }   double sq(double d) { return d * d; }   int N;   int x[4][505];   int y[4][505];   struct point {     double x, y;     point() { x = y = 0.0; }     point(double X, double Y) {       x = X;       y = Y;     }   };   bool operator<(point a, point b) {     if (eq(a.x, b.x)) return lt(a.y, b.y);     return lt(a.x, b.x);   }   bool operator==(point a, point b) { return eq(a.x, b.x) && eq(a.y, b.y); }   double d(point a, point b) { return sqrt(sq(a.x - b.x) + sq(a.y - b.y)); }   struct segment {     point a, b;     segment() {       a = point();       b = point();     }     segment(point A, point B) {       a = A;       b = B;     }     double len() { return d(a, b); }     double k() { return (a.y - b.y) / (a.x - b.x); }     double l() { return a.y - k() * a.x; }   };   double Total;   double Union;   struct line {     double a, b, c;     line(point p) {       a = p.x;       b = -1.0;       c = -p.y;     }     line(point p, point q) {       a = p.y - q.y;       b = q.x - p.x;       c = a * p.x + b * p.y;     }   };   bool ccutl(line p, line q) {     if (eq(p.a * q.b - q.a * p.b, 0.0)) return 0;     return 1;   }   point cutl(line p, line q) {     double x = (p.c * q.b - q.c * p.b) / (p.a * q.b - q.a * p.b);     double y = (p.c * q.a - q.c * p.a) / (p.b * q.a - q.b * p.a);     return point(x, y);   }   bool onseg(point p, segment s) {     if (lt(p.x, dmin(s.a.x, s.b.x)) || gt(p.x, dmax(s.a.x, s.b.x))) return 0;     if (lt(p.y, dmin(s.a.y, s.b.y)) || gt(p.y, dmax(s.a.y, s.b.y))) return 0;     return 1;   }   bool ccut(segment p, segment q) {     if (!ccutl(line(p.a, p.b), line(q.a, q.b))) return 0;     point r = cutl(line(p.a, p.b), line(q.a, q.b));     if (!onseg(r, p) || !onseg(r, q)) return 0;     return 1;   }   point cut(segment p, segment q) { return cutl(line(p.a, p.b), line(q.a, q.b)); }   struct event {     double x;     int type;     event() {       x = 0.0;       type = 0;     }     event(double X, int T) {       x = X;       type = T;     }   };   bool operator<(event a, event b) { return lt(a.x, b.x); }   vector<segment> s, A, B;   double solve(vector<segment> *v) {     double ret = 0;     vector<point> lines;     for (int i = 0; i < v->size(); ++i)       lines.push_back(point((*v)[i].k(), (*v)[i].l()));     sort(lines.begin(), lines.end());     lines.resize(unique(lines.begin(), lines.end()) - lines.begin());     for (int i = 0; i < lines.size(); ++i) {       vector<event> e;       for (int j = 0; j < s.size(); j += 4) {         bool touch = 0;         for (int k = 0; k < 4; ++k)           if (lines[i] == point(s[j + k].k(), s[j + k].l())) touch = 1;         if (touch) continue;         vector<point> cuts;         for (int k = 0; k < 4; ++k) {           if (!ccutl(line(lines[i]), line(s[j + k].a, s[j + k].b))) continue;           point r = cutl(line(lines[i]), line(s[j + k].a, s[j + k].b));           if (onseg(r, s[j + k])) cuts.push_back(r);         }         sort(cuts.begin(), cuts.end());         cuts.resize(unique(cuts.begin(), cuts.end()) - cuts.begin());         if (cuts.size() == 2) {           e.push_back(event(cuts[0].x, 0));           e.push_back(event(cuts[1].x, 1));         }       }       for (int j = 0; j < v->size(); ++j) {         if (lines[i] == point((*v)[j].k(), (*v)[j].l())) {           e.push_back(event(dmin((*v)[j].a.x, (*v)[j].b.x), 2));           e.push_back(event(dmax((*v)[j].a.x, (*v)[j].b.x), 3));         }       }       sort(e.begin(), e.end());       double last = e[0].x;       int cntg = 0;       int cntb = 0;       for (int j = 0; j < e.size(); ++j) {         double y0 = lines[i].x * last + lines[i].y;         double y1 = lines[i].x * e[j].x + lines[i].y;         if (cntb == 0 && cntg) ret += (y0 + y1) * (e[j].x - last) * 0.5;         last = e[j].x;         if (e[j].type == 0) ++cntb;         if (e[j].type == 1) --cntb;         if (e[j].type == 2) ++cntg;         if (e[j].type == 3) --cntg;       }     }     return ret;   }   int main(void) {     scanf( %d , &N);     for (int i = 0; i < N; ++i) {       for (int j = 0; j < 4; ++j) {         scanf( %d%d , x[j] + i, y[j] + i);       }       double area = 0.0;       for (int j = 0; j < 4; ++j) {         point p0(x[j][i], y[j][i]);         point p1(x[(j + 1) & 3][i], y[(j + 1) & 3][i]);         area += p0.x * p1.y - p0.y * p1.x;       }       if (gt(area, 0.0)) {         for (int j = 0; j < 2; ++j) {           swap(x[j][i], x[3 - j][i]);           swap(y[j][i], y[3 - j][i]);         }       }       for (int j = 0; j < 4; ++j) {         point p0(x[j][i], y[j][i]);         point p1(x[(j + 1) & 3][i], y[(j + 1) & 3][i]);         s.push_back(segment(p0, p1));       }       Total += s[s.size() - 2].len() * s[s.size() - 1].len();     }     for (int i = 0; i < s.size(); ++i) {       if (eq(s[i].a.x, s[i].b.x)) continue;       if (lt(s[i].a.x, s[i].b.x)) A.push_back(s[i]);       if (gt(s[i].a.x, s[i].b.x)) B.push_back(s[i]);     }     printf( %.8lf n , Total / (solve(&A) - solve(&B)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     Node() : vis(0), comp(-1) {}     int vis;     int comp;     vector<int> adj;   };   vector<int> vis;   bool dfs(vector<vector<int> >& a, int u, string& res) {     vis[u] = true;     for (int i = 0; i < a.size(); i++) {       if (i == u) continue;       if (vis[i] == false) {         if (a[u][i] == 0) {           if (res[u] ==  b ) res[u] =  a ;           res[i] = (res[u] ==  a ) ?  c  :  a ;           if (!dfs(a, i, res)) return false;         }       } else {         if (a[u][i] == 0) {           if (res[u] == res[i]) return false;         }       }     }     return true;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int> > a(n, vector<int>(n));     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       a[u][v] = 1;       a[v][u] = 1;     }     string res(n,  b );     vis.assign(n, false);     for (int i = 0; i < n; i++) {       if (vis[i] == false) {         if (!dfs(a, i, res)) {           cout <<  No  << endl;           return 0;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (abs(res[i] - res[j]) == 2 && a[i][j] == 1) {           cout <<  No  << endl;           return 0;         }         if (abs(res[i] - res[j]) <= 1 && a[i][j] == 0) {           cout <<  No  << endl;           return 0;         }       }     }     cout <<  Yes  << endl;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 9;   const int N = 333333;   int fib[N][2], fibSum[N][2];   void PreSolve() {     fib[1][0] = fib[2][1] = 1;     for (int i = 3; i < N; ++i) {       for (int j = 0; j < 2; ++j) {         fib[i][j] = fib[i - 1][j] + fib[i - 2][j];         if (fib[i][j] >= MOD) {           fib[i][j] -= MOD;         }       }     }     for (int i = 1; i < N; ++i) {       for (int j = 0; j < 2; ++j) {         fibSum[i][j] = fibSum[i - 1][j] + fib[i][j];         if (fibSum[i][j] >= MOD) {           fibSum[i][j] -= MOD;         }       }     }   }   void Add(int &a, const int b) {     a += b;     if (a >= MOD) {       a -= MOD;     }   }   int sum[N << 2], add[N << 2][2];   void Up(const int rt) {     sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];     if (sum[rt] >= MOD) {       sum[rt] -= MOD;     }   }   void Down(const int len, const int rt) {     if (add[rt][0] || add[rt][1]) {       int ls = rt << 1, rs = rt << 1 | 1;       int rl = len >> 1, ll = len - rl;       int temp[2];       for (int i = 0; i < 2; ++i) {         Add(add[ls][i], add[rt][i]);         Add(add[rs][i], temp[i] = ((long long)add[rt][0] * fib[ll + i + 1][0] +                                    (long long)add[rt][1] * fib[ll + i + 1][1]) %                                   MOD);       }       Add(sum[ls], ((long long)add[rt][0] * fibSum[ll][0] +                     (long long)add[rt][1] * fibSum[ll][1]) %                        MOD);       Add(sum[rs], ((long long)temp[0] * fibSum[rl][0] +                     (long long)temp[1] * fibSum[rl][1]) %                        MOD);       add[rt][0] = add[rt][1] = 0;     }   }   void Build(int l, int r, int rt) {     add[rt][0] = add[rt][1] = 0;     if (l == r) {       cin >> sum[rt];       return;     }     int m = l + r >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);     Up(rt);   }   void Update(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       int temp[2];       for (int i = 0; i < 2; ++i) {         Add(add[rt][i],             temp[i] = (fib[l - L + i + 1][0] + fib[l - L + i + 1][1]) % MOD);       }       Add(sum[rt], ((long long)fibSum[r - l + 1][0] * temp[0] +                     (long long)fibSum[r - l + 1][1] * temp[1]) %                        MOD);       return;     }     int m = l + r >> 1;     Down(r - l + 1, rt);     if (L <= m) {       Update(L, R, l, m, rt << 1);     }     if (m < R) {       Update(L, R, m + 1, r, rt << 1 | 1);     }     Up(rt);   }   int Query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return sum[rt];     }     int m = l + r >> 1, result = 0;     Down(r - l + 1, rt);     if (L <= m) {       Add(result, Query(L, R, l, m, rt << 1));     }     if (m < R) {       Add(result, Query(L, R, m + 1, r, rt << 1 | 1));     }     Up(rt);     return result;   }   int main() {     int n, m;     PreSolve();     while (cin >> n >> m) {       Build(1, n, 1);       int op, x, y;       for (int i = 0; i < m; ++i) {         cin >> op >> x >> y;         if (op == 1) {           Update(x, y, 1, n, 1);         } else {           cout << Query(x, y, 1, n, 1) << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     cout << 6 - n <<   n ;     vector<bool> chk(6, false);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (s[0] ==  p )         chk[0] = true;       else if (s[0] ==  g )         chk[1] = true;       else if (s[0] ==  b )         chk[2] = true;       else if (s[0] ==  o )         chk[3] = true;       else if (s[0] ==  r )         chk[4] = true;       else if (s[0] ==  y )         chk[5] = true;     }     if (chk[0] == false) cout <<  Power  <<   n ;     if (chk[1] == false) cout <<  Time  <<   n ;     if (chk[2] == false) cout <<  Space  <<   n ;     if (chk[3] == false) cout <<  Soul  <<   n ;     if (chk[4] == false) cout <<  Reality  <<   n ;     if (chk[5] == false) cout <<  Mind  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   const long long M = 1e12;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long inf = -1e18;   int n, arr[5], m;   vector<int> vec, verr;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n;     if (n == 0) {       cout <<  YES  <<   n ;       cout << 1 <<   n ;       cout << 1 <<   n ;       cout << 3 <<   n ;       cout << 3;       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> arr[i];       verr.push_back(arr[i]);       verr.push_back(arr[i] + 1);       verr.push_back(arr[i] + 2);       verr.push_back(arr[i] + 3);       verr.push_back(arr[i] - 1);       verr.push_back(arr[i] - 2);       if (i > 1) {         verr.push_back(abs(arr[i] - arr[i - 1]));         verr.push_back(abs(arr[i] - arr[i - 1]) + 1);         verr.push_back(abs(arr[i] - arr[i - 1]) - 1);         verr.push_back(abs(arr[i] - arr[i - 1]) - 50);         verr.push_back(abs(arr[i] - arr[i - 1]) - 500);         verr.push_back(abs(arr[i] + arr[i - 1]));         verr.push_back(abs(arr[i] + arr[i - 1]) + 1);         verr.push_back(abs(arr[i] + arr[i - 1]) - 1);         verr.push_back(abs(arr[i] + arr[i - 1]) - 50);         verr.push_back(abs(arr[i] + arr[i - 1]) - 500);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         verr.push_back(arr[i] + arr[j]);         verr.push_back(arr[i] - arr[j]);       }     }     sort(arr + 1, arr + n + 1);     m = 4;     if (n == 1) {       for (auto a : verr) {         for (int b = 1; b <= 500; b++) {           for (int c = 1; c <= 500; c++) {             for (int d = arr[1]; d <= arr[1]; d++) {               vec.clear();               vec.push_back(a);               vec.push_back(b);               vec.push_back(c);               vec.push_back(d);               sort(vec.begin(), vec.end());               if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 ||                   (vec[1] + vec[2]) % 2 != 0)                 continue;               if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 ==                       (vec[1] + vec[2]) / 2 &&                   (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) {                 cout <<  YES  <<   n ;                 cout << a <<   n ;                 cout << b <<   n ;                 cout << c;                 return 0;               }             }           }         }       }     }     if (n == 2) {       for (int a = 1; a <= 500; a++) {         for (int b = 1; b <= 500; b++) {           for (int c = arr[2]; c <= arr[2]; c++) {             for (int d = arr[1]; d <= arr[1]; d++) {               vec.clear();               vec.push_back(a);               vec.push_back(b);               vec.push_back(c);               vec.push_back(d);               sort(vec.begin(), vec.end());               if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 ||                   (vec[1] + vec[2]) % 2 != 0)                 continue;               if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 ==                       (vec[1] + vec[2]) / 2 &&                   (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) {                 cout <<  YES  <<   n ;                 cout << a <<   n ;                 cout << b <<   n ;                 return 0;               }             }           }         }       }     }     if (n == 3) {       for (int a = 1; a <= 500; a++) {         for (int b = arr[3]; b <= arr[3]; b++) {           for (int c = arr[2]; c <= arr[2]; c++) {             for (int d = arr[1]; d <= arr[1]; d++) {               vec.clear();               vec.push_back(a);               vec.push_back(b);               vec.push_back(c);               vec.push_back(d);               sort(vec.begin(), vec.end());               if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 ||                   (vec[1] + vec[2]) % 2 != 0)                 continue;               if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 ==                       (vec[1] + vec[2]) / 2 &&                   (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) {                 cout <<  YES  <<   n ;                 cout << a <<   n ;                 return 0;               }             }           }         }       }     }     if (n == 4) {       sort(arr + 1, arr + n + 1);       vec.clear();       vec.push_back(arr[1]);       vec.push_back(arr[2]);       vec.push_back(arr[3]);       vec.push_back(arr[4]);       if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 ||           (vec[1] + vec[2]) % 2 != 0)         goto in;       if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 == (vec[1] + vec[2]) / 2 &&           (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) {         cout <<  YES  <<   n ;         return 0;       }     }   in:;     if (n == 2 && arr[2] == 500 && arr[1] == 497) {       cout <<  YES  <<   n ;       cout << 1488 <<   n ;       cout << 1491;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};   int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};   const int MOD = 1e9 + 7, N = 2e5 + 5, oo = 2e9;   const double pi = acos(-1);   using namespace std;   long long day[N], h[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long ans = -1;     for (int i = 0; i < m; i++) {       cin >> day[i] >> h[i];       ans = max(ans, h[i]);       if (i and day[i] - day[i - 1] < abs(h[i] - h[i - 1]))         return cout <<  IMPOSSIBLE , 0;     }     ans = max(ans, h[0] + day[0] - 1);     ans = max(ans, h[m - 1] + (n - day[m - 1]));     for (int i = 1; i < m; i++) {       long long dif = day[i] - day[i - 1], cur = h[i - 1];       if (h[i] > h[i - 1])         ans = max(ans, h[i] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2);       else         ans =             max(ans, h[i - 1] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long INF = 1LL << 60;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<long long> l(n), r(n), m(n);     for (long long i = (long long)(0); i < (n); i++) {       cin >> m[i];     }     stack<pair<long long, long long>> stk;     stk.push(make_pair(0, -1));     stk.push(make_pair(m[0], 0));     l[0] = m[0];     for (long long i = (long long)(1); i < (n); i++) {       if (m[i] > stk.top().first) {         l[i] = l[i - 1] + m[i];       } else {         while (!stk.empty() && m[i] < stk.top().first) {           stk.pop();         }         int ind = stk.top().second;         long long prv;         if (ind == -1) {           prv = 0;         } else {           prv = l[ind];         }         l[i] = prv + (i - ind) * m[i];       }       stk.push(make_pair(m[i], i));     }     while (!stk.empty()) {       stk.pop();     };     reverse(m.begin(), m.end());     ;     stk.push(make_pair(0, -1));     stk.push(make_pair(m[0], 0));     r[0] = m[0];     for (long long i = (long long)(1); i < (n); i++) {       if (m[i] > stk.top().first) {         r[i] = r[i - 1] + m[i];       } else {         while (!stk.empty() && m[i] < stk.top().first) {           stk.pop();         }         int ind = stk.top().second;         long long prv;         if (ind == -1) {           prv = 0;         } else {           prv = r[ind];         }         r[i] = prv + (i - ind) * m[i];       }       stk.push(make_pair(m[i], i));     };     reverse(m.begin(), m.end());     ;     ;     reverse(r.begin(), r.end());     ;     int ind = 0;     long long out = 0;     long long temp;     for (long long i = (long long)(0); i < (n); i++) {       temp = l[i] + r[i] - m[i];       if (temp > out) {         ind = i;         out = temp;       }     }     vector<long long> outt(n);     outt[ind] = m[ind];     long long big = m[ind];     for (int i = ind - 1; i >= 0; i--) {       if (m[i] < big) {         big = m[i];       }       outt[i] = big;     }     big = m[ind];     for (int i = ind + 1; i < n; i++) {       if (m[i] < big) {         big = m[i];       }       outt[i] = big;     }     for (long long i = (long long)(0); i < (n); i++) {       cout << outt[i] <<    ;     }   }


#include <bits/stdc++.h>   const int N = 2e3 + 9;   using namespace std;   int n, dp[5][N], a[N], b[5] = {0, 1, 2, 1, 2};   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = max(dp[i - 1][j], dp[i][j - 1] + (a[j] == b[i]));       }     }     printf( %d n , dp[4][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     int hash[201] = {0};     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       v.push_back(make_pair(l, r));       for (int j = l; j < r + 1; j++) hash[j]++;     }     vector<int> ans(n);     for (int j = 0; j < 250; j++) {       while (hash[j] > k) {         int m = -1;         for (int i = 0; i < n; i++) {           if (!ans[i] && (j >= v[i].first && j <= v[i].second)) {             if (m == -1 || v[i].second > v[m].second) m = i;           }         }         if (m == -1) break;         for (int i = v[m].first; i < v[m].second + 1; i++) hash[i]--;         ans[m] = 1;       }     }     cout << accumulate(ans.begin(), ans.end(), 0) << endl;     for (int i = 0; i < n; i++)       if (ans[i]) cout << i + 1 <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int row[n * m + 1], col[n * m + 1];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int a;           cin >> a;           col[a] = j;         }       }       for (int j = 0; j < m; j++) {         for (int i = 0; i < n; i++) {           int a;           cin >> a;           row[a] = i;         }       }       int ans[n][m];       for (int i = 1; i < n * m + 1; i++) {         ans[row[i]][col[i]] = i;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cout << ans[i][j] <<    ;         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int t, tr, br, b, bl, tl;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t >> tr >> br >> b >> bl >> tl;     long long ans = 0;     int k = min(tr, tl);     ans += (2 * t + k) * ((long long)k);     ans += 2 * (max(tr, tl) - k) * (t + k);     int a = min(bl, br);     ans += (2 * b + a) * ((long long)a);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100100];   int main() {     long long n;     int q;     scanf( %I64d%d , &n, &q);     int k = 0;     long long tmp = n + 1;     while (tmp % 2 == 0) tmp /= 2, k++;     while (q--) {       long long st;       scanf( %I64d , &st);       cin >> str;       int L = strlen(str);       for (int i = 0; i < L; i++) {         int t = 0;         while (st % 2 == 0) t++, st /= 2;         if (str[i] ==  U ) {           if (t == k - 1) {             st = (1ll << t);             continue;           }           if (st % 4 == 3)             st = (st - 1) * (1ll << t);           else             st = (st + 1) * (1ll << t);         } else {           if (t == 0) continue;           t--;           st *= 2;           if (str[i] ==  L )             st = (st - 1) * (1ll << t);           else             st = (st + 1) * (1ll << t);         }       }       printf( %I64d n , st);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> divisors(long long n) {     vector<long long> ans;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         ans.push_back(i);         if (n / i != i) ans.push_back(n / i);       }     }     ans.push_back(1);     return ans;   }   void precision_print(long double n, long long p) {     cout << fixed << setprecision(p) << n <<   n ;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long x1, p1, x2, p2;       cin >> x1 >> p1 >> x2 >> p2;       string temp = to_string(x1);       long long a = ((long long)(temp).size());       temp = to_string(x2);       long long b = ((long long)(temp).size());       if (a + p1 > b + p2) {         cout <<  >  <<   n ;         continue;       }       if (a + p1 < b + p2) {         cout <<  <  <<   n ;         continue;       }       if (p1 < p2)         x2 *= pow(10, p2 - p1);       else         x1 *= pow(10, p1 - p2);       if (x1 > x2)         cout <<  > n ;       else if (x1 == x2)         cout <<  = n ;       else         cout <<  < n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long num[200005], rig[200005], lef[200005];   int main() {     scanf( %d%d%d , &n, &m, &k);     long long tmp = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &num[i]);     }     int t = 1;     while (m--) t *= k;     for (int i = 1; i <= n; ++i) {       rig[i] = rig[i - 1] | num[i];     }     for (int i = n; i >= 1; --i) {       lef[i] = lef[i + 1] | num[i];     }     for (int i = 1; i <= n; ++i)       tmp = max(tmp, num[i] * t | rig[i - 1] | lef[i + 1]);     printf( %I64d , tmp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 2, maxm = 1000 * 1000 + 2;   int n, m, q, parent[maxn], r[maxn], b[maxn];   pair<pair<long long, int>, pair<int, int> > v[maxm];   bool chek = false;   int par(int x) {     if (x == parent[x]) return x;     int y = par(parent[x]);     b[x] += b[parent[x]];     b[x] %= 2;     return parent[x] = y;   }   void merge(int x, int y) {     int second = x, e = y;     x = par(x);     y = par(y);     if (x == y) {       if (b[second] == b[e]) chek = true;       return;     }     if (r[x] < r[y]) {       swap(x, y);       swap(second, e);     }     r[x] += r[y];     parent[y] = x;     b[y] = (b[e] + 1 + b[second]) % 2;   }   int main() {     ios::sync_with_stdio(false);     int x, y, second, e;     long long z;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       cin >> x >> y >> z;       x--;       y--;       v[i] = make_pair(make_pair(z, i + 1), make_pair(x, y));     }     sort(v, v + m);     reverse(v, v + m);     for (int t = 0; t < q; t++) {       chek = false;       cin >> second >> e;       for (int i = 0; i < n; i++) {         parent[i] = i;         r[i] = 1;         b[i] = 0;       }       for (int i = 0; i < m; i++)         if (v[i].first.second >= second && v[i].first.second <= e) {           x = v[i].second.first;           y = v[i].second.second;           z = v[i].first.first;           merge(x, y);           if (chek == true) {             cout << z << endl;             break;           }         }       if (chek == false) cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, z = 1, k;   int main() {     cin >> n >> m;     if (n > m + 1 || n * 2 + 2 < m) return cout << -1, 0;     while (n || m) {       if ((m > n && k < 2) || z == 0)         m--, z = 1, k++;       else         n--, z = 0, k = 0;       cout << z;     }   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   vector<int> res;   int main() {     scanf( %d%d , &a, &b);     while (true) {       res.push_back(b);       if (b == a) break;       if (b < a) {         printf( NO );         return 0;       }       if (b % 2 == 0)         b /= 2;       else if (b % 10 == 1)         b /= 10;       else {         printf( NO );         return 0;       }     }     printf( YES n%u n , res.size());     while (!res.empty()) printf( %d  , res.back()), res.pop_back();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, k;     cin >> n >> k;     multiset<pair<long long, long long>> s;     vector<tuple<long long, long long, long long>> v;     long long i;     for (i = 0; i < n; i++) {       long long a, b, p;       cin >> a >> b >> p;       s.insert({(a * a + b * b), i});       v.push_back(make_tuple(a, b, p));     }     if (k >= 1e6) {       cout << 0.00000000 <<   n ;       return 0;     }     long long f = -1;     double ans;     for (pair<long long, long long> x : s) {       pair<long long, long long> pp = x;       long long y = pp.second;       k += get<2>(v[y]);       f++;       if (k >= 1e6) {         double aa = get<0>(v[y]);         double bb = get<1>(v[y]);         ans = sqrt(aa * aa + bb * bb);         break;       }     }     if (k < 1e6) {       cout <<  -1 n ;       return 0;     }     std::cout << std::fixed;     std::cout << std::setprecision(10);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 998244353, N = 3e5;   int n, L, C, r[N], A[N], B[N];   int g[N], g0[N], g1[N], g2[N];   int f0[N], f1[N], f2[N];   int q0[N], q1[N];   int t1[N], t2[N], t3[N], t4[N];   inline void Add(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   inline int Mul(int x, int y) { return 1ll * x * y % P; }   inline int fpow(int x, int k) {     int s = 1;     for (; k; k >>= 1, x = Mul(x, x))       if (k & 1) s = Mul(s, x);     return s;   }   inline void NTT_prepare(int len) {     for (L = 1, C = 0; L < len; L <<= 1, ++C)       ;     for (int i = 0; i < L; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (C - 1));   }   void NTT(int *A, int op) {     for (int i = 0; i < L; ++i)       if (i < r[i]) swap(A[i], A[r[i]]);     for (int i = 1; i < L; i <<= 1) {       int Wn = fpow(3, (P - 1) / (i << 1));       if (op == -1) Wn = fpow(Wn, P - 2);       for (int j = 0; j < L; j += i << 1) {         int w = 1;         for (int k = 0; k < i; ++k, w = Mul(w, Wn)) {           int p = A[j + k], q = Mul(w, A[j + i + k]);           A[j + k] = (p + q) % P;           A[j + i + k] = ((p - q) % P + P) % P;         }       }     }     if (op == -1) {       int inv_L = fpow(L, P - 2);       for (int i = 0; i < L; ++i) A[i] = Mul(A[i], inv_L);     }   }   void Convolve(int *a, int *b, int *C) {     for (int i = 0; i < L / 2; ++i) A[i] = a[i];     for (int i = 0; i < L / 2; ++i) B[i] = b[i];     for (int i = L / 2; i < L; ++i) A[i] = B[i] = 0;     NTT(A, 1);     NTT(B, 1);     for (int i = 0; i < L; ++i) C[i] = Mul(A[i], B[i]);     NTT(C, -1);   }   void Solve_1(int l, int r) {     if (l == r) {       Add(f0[l], g0[l]);       Add(f1[l], g1[l]);       return;     }     int mid = (l + r) / 2;     Solve_1(l, mid);     NTT_prepare(2 * (r - l + 1));     for (int i = 0; i < L; ++i) q0[i] = (i + l <= mid ? f0[i + l] : 0);     for (int i = 0; i < L; ++i) q1[i] = (i + l <= mid ? f1[i + l] : 0);     Convolve(g0, q0, t1);     Convolve(g1, q0, t2);     Convolve(g1, q1, t3);     Convolve(g2, q1, t4);     for (int i = 0; i < L / 2; ++i) {       if (mid + 1 <= i + l + 1 && i + l + 1 <= r) {         Add(f0[i + l + 1], t1[i]);         Add(f1[i + l + 1], t2[i]);       }       if (mid + 1 <= i + l + 3 && i + l + 3 <= r) {         Add(f0[i + l + 3], t3[i]);         Add(f1[i + l + 3], t4[i]);       }     }     Solve_1(mid + 1, r);   }   void Solve_2(int l, int r) {     if (l == r) {       Add(f2[l], g2[l]);       Add(f2[l], l >= 1 ? t1[l - 1] : 0);       return;     }     int mid = (l + r) / 2;     Solve_2(l, mid);     NTT_prepare(2 * (r - l + 1));     for (int i = 0; i < L; ++i) q0[i] = (i + l <= mid ? f2[i + l] : 0);     Convolve(g2, q0, t2);     for (int i = 0; i < L / 2; ++i) {       if (mid + 1 - 3 <= i + l && i + l <= r - 3) {         Add(f2[i + l + 3], t2[i]);       }     }     Solve_2(mid + 1, r);   }   int main() {     scanf( %d , &n);     g[0] = 1;     g[2] = 1;     for (int i = 4; i <= n; i += 2) g[i] = (g[i - 2] + g[i - 4]) % P;     for (int i = 0; i <= n; ++i) {       g0[i] = Mul(g[i], Mul(i, i));       g1[i] = Mul(g[i], Mul(i + 1, i + 1));       g2[i] = Mul(g[i], Mul(i + 2, i + 2));     }     Solve_1(0, n);     NTT_prepare(2 * n);     Convolve(g1, f1, t1);     Solve_2(0, n);     int ans = Mul(Mul((g[n - 1] + g[n - 3]) % P, Mul(n - 1, n - 1)), n);     for (int i = 2; i <= n - 2; ++i) {       Add(ans, Mul(Mul(Mul(g[i - 1], Mul(i - 1, i - 1)), f0[n - i - 1]), i));       Add(ans,           Mul(Mul(Mul(g[i - 2], Mul(i - 1, i - 1)), f1[n - i - 2]), Mul(2, i)));       if (3 <= i && i <= n - 3)         Add(ans, Mul(Mul(Mul(g[i - 3], Mul(i - 1, i - 1)), f2[n - i - 3]), i));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   template <class T, class U>   inline void add_self(T &a, U b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   template <class T, class U>   inline void min_self(T &x, U y) {     if (y < x) x = y;   }   template <class T, class U>   inline void max_self(T &x, U y) {     if (y > x) x = y;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     cout << t;     ;     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <class T, class U>   void print_m(const map<T, U> &m, int w = 3) {     if (m.empty()) {       cout <<  Empty  << endl;       return;     }     for (auto x : m) cout <<  (  << x.first <<  :   << x.second <<  ),  << endl;     cout << endl;   }   template <class T, class U>   void debp(const pair<T, U> &pr, bool end_line = 1) {     cout <<  {  << pr.first <<     << pr.second <<  } ;     cout << (end_line ?   n  :  ,  );   }   template <class T>   void print_vp(const T &vp, int sep_line = 0) {     if (vp.empty()) {       cout <<  Empty  << endl;       return;     }     if (!sep_line) cout <<  {  ;     for (auto x : vp) debp(x, sep_line);     if (!sep_line) cout <<  } n ;     cout << endl;   }   template <typename T>   void print(const T &v, bool show_index = false) {     int w = 2;     if (show_index) {       for (int i = 0; i < int((v).size()); i++) cout << setw(w) << i <<    ;       cout << endl;     }     for (auto &el : v) cout << setw(w) << el <<    ;     cout << endl;   }   template <typename T>   void print_vv(const T &vv) {     if (int((vv).size()) == 0) {       cout <<  Empty  << endl;       return;     }     int w = 3;     cout << setw(w) <<    ;     for (int j = 0; j < int((*vv.begin()).size()); j++)       cout << setw(w) << j <<    ;     cout << endl;     int i = 0;     for (auto &v : vv) {       cout << i++ <<   { ;       for (auto &el : v) cout << setw(w) << el <<    ;       cout <<  }, n ;     }     cout << endl;   }   int n, t;   const int nax = 200;   vector<double> glass(nax);   void dfs(int g, int l) {     if (l > n) return;     if (glass[g] > 1) {       double half = (glass[g] - 1) / 2;       glass[g] = 1;       int c1 = (g + l);       int c2 = (g + l + 1);       glass[c1] += half;       glass[c2] += half;       if (glass[c1] > 1) dfs(c1, l + 1);       if (glass[c2] > 1) dfs(c2, l + 1);     }   }   void bfs() {     set<int> q;     if (glass[1] > 1) q.insert(1);     int l = 1;     while (!q.empty()) {       if (l > 10) break;       set<int> nq;       for (auto top : q) {         double half = (glass[top] - 1) / 2;         glass[top] = 1;         int c1 = (top + l);         int c2 = (top + l + 1);         glass[c1] += half;         glass[c2] += half;         if (glass[c1] > 1) nq.insert(c1);         if (glass[c2] > 1) nq.insert(c2);       }       q = nq;       ++l;     }   }   int main() {     while (cin >> n >> t) {       glass.clear();       glass.resize(nax);       for (int i = 0; i < int(t); i++) {         glass[1] += 1;         bfs();       }       int ed = (n * (n + 1)) / 2;       int cnt = 0;       for (int i = int(1); i < int(ed + 1); i++)         if (glass[i] >= 1) ++cnt;       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char nl =   n ;   const int MAX_N = 100011;   const long long INF = (1 << 29) + 123;   const long long MOD = 1000000007;   const long double PI = 4 * atan((long double)1);   template <typename T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   bool ckmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr << H <<    ;     dbg_out(T...);   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MX = 1 << 20;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int m = n;     vector<int> LOC[n + 1];     int A[n];     for (int i = 0; i < n; i++) {       cin >> A[i];       LOC[A[i]].push_back(i);     }     int hi = 0, best = -1;     for (int i = 1; i <= m; i++)       if (ckmax(hi, (int)LOC[i].size())) best = i;     bool done = 0;     for (int i = 1; i <= m; i++)       if (i != best && hi == (int)LOC[i].size()) done = 1;     if (done) {       cout << n << nl;       return 0;     }     n += 2;     int a[n];     for (int i = 0; i < n - 2; i++) a[i + 1] = A[i];     a[0] = a[n - 1] = best;     vector<int> loc[n + 1];     for (int i = 0; i < n; i++) loc[a[i]].push_back(i);     hi = (int)loc[best].size();     int idxBest[n];     for (int i = 0; i < n; i++)       if (i == 0)         idxBest[i] = 1;       else         idxBest[i] = idxBest[i - 1] + (a[i] == best);     int ans = 0;     int SQRTN = sqrt(n) - 100;     for (int i = 1; i <= m; i++) {       int SZ = (int)loc[i].size();       if (i == best || !SZ) continue;       if (SZ > SQRTN) {         int j = 0, k = 0;         int sum = 0;         int firstLoc[2 * n + 1];         for (int ii = 0; ii < 2 * n + 1; ii++) firstLoc[ii] = -1;         firstLoc[sum + n] = 0;         while (j != hi - 1 || k != SZ) {           int curPos;           if (k < SZ && loc[best][j] > loc[i][k]) {             curPos = loc[i][k] + 1;             ckmax(ans, curPos - 1 - firstLoc[sum + n]);             sum++;             k++;           } else {             curPos = loc[best][j] + 1;             ckmax(ans, curPos - 1 - firstLoc[sum + n]);             sum--;             j++;           }           if (firstLoc[sum + n] == -1) firstLoc[sum + n] = curPos;         }         ckmax(ans, loc[best][j] - firstLoc[sum + n]);       } else {         int kkk = 0;         for (int kk = 0; kk < SZ; kk++) {           int j = max(0, idxBest[loc[i][kk]] - SZ - 2);           int jEnd = min(hi, idxBest[loc[i][kk]] + SZ + 2);           while (kkk < SZ && loc[best][j] > loc[i][kkk]) kkk++;           int k = kkk;           int PAD = 2 * SZ + 5;           int firstLoc[2 * PAD + 1];           for (int ii = 0; ii < 2 * PAD + 1; ii++) firstLoc[ii] = -1;           int sum = -1;           if (j == 0) firstLoc[0 + PAD] = 0;           firstLoc[sum + PAD] = loc[best][j] + 1;           j++;           while (j < jEnd) {             int curPos;             if (k < SZ && loc[i][k] < loc[best][j]) {               curPos = loc[i][k] + 1;               ckmax(ans, loc[i][k] - firstLoc[sum + PAD]);               sum++;               k++;             } else {               curPos = loc[best][j] + 1;               ckmax(ans, loc[best][j] - firstLoc[sum + PAD]);               sum--;               j++;             }             if (firstLoc[sum + PAD] == -1) firstLoc[sum + PAD] = curPos;           }           if (j != hi) ckmax(ans, loc[best][j] - firstLoc[sum + PAD]);         }       }     }     cout << ans << nl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, cnt = 0;     scanf( %d %d %d , &n, &m, &k);     int p[n], s[n], c[k];     for (int i = 0; i < n; i++) scanf( %d , &p[i]);     for (int i = 0; i < n; i++) scanf( %d , &s[i]);     for (int i = 0; i < k; i++) scanf( %d , &c[i]);     for (int i = 0; i < k; i++) {       int po = p[c[i] - 1];       int so = s[c[i] - 1];       for (int j = 0; j < n; j++) {         if (p[j] > po && s[j] == so) {           cnt++;           break;         }       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       mx = max(a[i], mx);     }     int cnt = 0;     int maxcnt = 0;     for (int i = 0; i < n; i++) {       if (a[i] == mx)         cnt++;       else {         maxcnt = max(cnt, maxcnt);         cnt = 0;       }       if (i == n - 1) {         maxcnt = max(cnt, maxcnt);       }     }     cout << maxcnt;   }


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


#include <bits/stdc++.h>   using namespace std;   int rd();   int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }   int J(int x) {     int sum = 0;     for (int i = 1; i * i <= x; ++i) {       if (x % i == 0 && gcd(i, x / i) == 1) {         sum += i;         sum += x / i;       }     }     return sum;   }   const int N = 1000007;   int n, cnt, pr[N], lp[N];   void sieve() {     for (int i = 2; i < N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr[cnt++] = i;       }       for (int j = 0; j < cnt && pr[j] <= lp[i] && pr[j] * i < N; ++j) {         lp[i * pr[j]] = pr[j];       }     }   }   long long getp(long long d) {     --d;     for (int i = 0; i < cnt && (long long)pr[i] * pr[i] <= d; ++i) {       if (d % pr[i] == 0) {         while (d % pr[i] == 0) d /= pr[i];         if (d == 1) return pr[i];         return -1;       }     }     return d;   }   vector<pair<long long, long long> > mas;   long long ans;   bool used[N];   void rec(int ptr, long long rem) {     if (rem == 1) {       ++ans;       return;     }     if (ptr == (int)(mas).size()) return;     if (rem % mas[ptr].first == 0 && !used[mas[ptr].second]) {       used[mas[ptr].second] = true;       rec(ptr + 1, rem / mas[ptr].first);       used[mas[ptr].second] = false;     }     rec(ptr + 1, rem);   }   void solve() {     sieve();     long long x;     cin >> x;     vector<long long> divs;     for (int i = 1; (long long)i * i <= x; ++i) {       if (x % i == 0) {         if (i != 1) divs.push_back(i);         if (i * i != x) divs.push_back(x / i);       }     }     sort((divs).begin(), (divs).end());     vector<long long> pp;     for (long long d : divs) {       long long p = getp(d);       if (p == -1 || p == 1) continue;       mas.push_back(make_pair(d, p));       pp.push_back(p);     }     sort((mas).begin(), (mas).end());     reverse((mas).begin(), (mas).end());     sort((pp).begin(), (pp).end());     for (int i = 0; i < ((int)(mas).size()); ++i)       mas[i].second =           lower_bound((pp).begin(), (pp).end(), mas[i].second) - pp.begin();     rec(0, x);     cout << ans << endl;   }   int rd() { return (((long long)rand() << 16) ^ rand()) % 1000000000; }   void testGen() {     FILE *f = fopen( input.txt ,  w );     fclose(f);   }   int main() {     cerr << fixed;     cerr.precision(9);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   const long long mod = 1000000007ll;   int n, cnt;   long long ans = 1;   int to[N], vis[N], dep[N];   long long power(long long x, long long t) {     long long ret = 1;     for (; t; t >>= 1ll, x = x * x % mod)       if (t & 1ll) ret = ret * x % mod;     return ret;   }   void dfs(int u, int step, int d) {     vis[u] = d;     dep[u] = step;     if (!vis[to[u]])       dfs(to[u], step + 1, d);     else if (vis[to[u]] == vis[u]) {       ans = ans * (power(2, dep[u] - dep[to[u]] + 1) - 2) % mod;       cnt += dep[u] - dep[to[u]] + 1;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &to[i]);     for (int i = 1; i <= n; ++i)       if (!vis[i]) dfs(i, 0, i);     ans = ans * power(2, n - cnt) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2001;   const int INF = 1e9 + 1;   struct T {     int u, f, w, num;     T(int u, int f, int w, int num) : u(u), f(f), w(w), num(num){};     T(){};   };   vector<T> G[N];   int n, m, s, t;   bool used[N];   bool ist[N];   int parent[N];   pair<int, pair<int, int> > ans;   pair<int, int> mn;   int Time = 0;   int tin[N];   int fin[N];   void dfs(int v) {     used[v] = true;     for (int i = 0; i < G[v].size(); ++i) {       int to = G[v][i].u;       if (used[to] == false && G[v][i].f == 1) {         parent[to] = v;         dfs(to);       }     }   }   vector<int> getPath(int s, int t) {     memset(used, false, sizeof(used));     vector<int> ans;     dfs(s);     if (used[t] == false) return ans;     int v = t;     while (v != s) {       ans.push_back(v);       v = parent[v];     }     ans.push_back(v);     return ans;   }   void DeleteEdge(int v, int u, int& num) {     for (int i = 0; i < G[v].size(); ++i) {       if (G[v][i].u == u) {         G[v][i].f = 0;         num = i;         break;       }     }     for (int i = 0; i < G[u].size(); ++i) {       if (G[u][i].u == v) {         G[u][i].f = 0;         break;       }     }   }   void AddEdge(int v, int u) {     for (int i = 0; i < G[v].size(); ++i) {       if (G[v][i].u == u) {         G[v][i].f = 1;         break;       }     }     for (int i = 0; i < G[u].size(); ++i) {       if (G[u][i].u == v) {         G[u][i].f = 1;         break;       }     }   }   void update(int weight, pair<int, int> num) {     if (ans.first == -1 || weight < ans.first) {       ans.first = weight;       ans.second = num;     }   }   void findMinBridge(int v, int num) {     if (v == t) ist[v] = true;     used[v] = true;     Time++;     tin[v] = Time;     fin[v] = Time;     for (int i = 0; i < G[v].size(); ++i) {       int to = G[v][i].u;       if (G[v][i].num == num || G[v][i].f == 0) continue;       if (used[to] == true) {         fin[v] = min(fin[v], tin[to]);       } else {         findMinBridge(to, G[v][i].num);         ist[v] |= ist[to];         fin[v] = min(fin[v], fin[to]);         if (fin[to] > tin[v] && ist[to] == true) {           if (mn.first > G[v][i].w) {             mn.first = G[v][i].w;             mn.second = G[v][i].num;           }         }       }     }   }   int main() {     ans.first = -1;     scanf( %d%d%d%d , &n, &m, &s, &t);     s--;     t--;     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       u--;       v--;       G[u].push_back(T(v, 1, w, i));       G[v].push_back(T(u, 1, w, i));     }     vector<int> path = getPath(s, t);     if (path.size() == 0) {       printf( 0 n0 n );       return 0;     }     for (int i = (int)path.size() - 1; i > 0; --i) {       int num;       DeleteEdge(path[i], path[i - 1], num);       vector<int> tmp = getPath(s, t);       if (tmp.size() == 0) {         update(G[path[i]][num].w, make_pair(G[path[i]][num].num, -1));       } else {         memset(used, false, sizeof(used));         memset(ist, false, sizeof(ist));         mn.first = INF;         Time = 0;         findMinBridge(s, -1);         if (mn.first != INF)           update(G[path[i]][num].w + mn.first,                  make_pair(G[path[i]][num].num, mn.second));       }       AddEdge(path[i], path[i - 1]);     }     if (ans.first == -1) {       printf( -1 n );       return 0;     }     printf( %d n , ans.first);     if (ans.second.second == -1) {       printf( 1 n%d , ans.second.first + 1);     } else {       printf( 2 n%d %d n , ans.second.first + 1, ans.second.second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int flow;     int next;     int inv;     int cap;     int cost;   };   const int N = 1100000;   vector<edge> v[N];   int d[N];   int phi[N];   int from[N];   bool vis[N];   void add_edge(int x1, int x2, int x3, int x4) {     edge x;     x.next = x2;     x.cost = x4;     x.cap = x3;     x.flow = 0;     x.inv = v[x2].size();     v[x1].push_back(x);     x.next = x1;     x.cost = -x4;     x.cap = 0;     x.flow = 0;     x.inv = v[x1].size() - 1;     v[x2].push_back(x);   }   const int inf = (int)1e9;   void init() {     for (int i = 0; i < N; i++) {       phi[i] = 0;       v[i].clear();     }   }   void bfs(int n) {     for (int i = 0; i < n; i++) vis[i] = false;     queue<int> q;     q.push(0);     vis[0] = true;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < v[x].size(); i++)         if (!vis[v[x][i].next] && v[x][i].cap > v[x][i].flow) {           vis[v[x][i].next] = true;           from[v[x][i].next] = v[x][i].inv;           q.push(v[x][i].next);         }     }   }   void dijkstra(int n) {     for (int i = 0; i < n; i++) {       d[i] = inf;       vis[i] = false;     }     for (int i = 0; i < n; i++) vis[i] = false;     set<pair<int, int> > q;     d[0] = 0;     for (int i = 1; i < n; i++) {       d[i] = inf;       q.insert(make_pair(d[i], i));     }     q.insert(make_pair(0, 0));     while (!q.empty()) {       int x = q.begin()->second;       vis[x] = true;       q.erase(q.begin());       if (d[x] == inf) break;       for (int i = 0; i < v[x].size(); i++)         if (!vis[v[x][i].next] && v[x][i].cap > v[x][i].flow) {           int to = v[x][i].next;           if (d[to] > d[x] + v[x][i].cost + phi[x] - phi[to]) {             q.erase(make_pair(d[to], to));             d[to] = d[x] + v[x][i].cost + phi[x] - phi[to];             from[to] = v[x][i].inv;             q.insert(make_pair(d[to], to));           }         }     }   }   int id[N];   void fuckin_levit(int n) {     for (int i = 0; i < n; i++) {       d[i] = inf;       id[i] = 0;     }     d[0] = 0;     deque<int> q;     q.push_back(0);     while (!q.empty()) {       int x = q.front();       q.pop_front();       vis[x] = true;       if (d[x] == inf) break;       id[x] = 1;       for (int i = 0; i < v[x].size(); i++)         if (v[x][i].cap - v[x][i].flow > 0) {           int to = v[x][i].next;           int len = v[x][i].cost;           if (d[to] > d[x] + len) {             d[to] = d[x] + len;             if (id[to] == 0)               q.push_front(to);             else if (id[to] == 1)               q.push_back(to);             from[to] = v[x][i].inv;             id[to] = 1;           }         }     }   }   pair<int, int> maxflow(int n, int mode) {     int res_flow = 0;     int res_cost = 0;     while (true) {       if (mode == 1) dijkstra(n);       if (mode == 0) bfs(n);       if (mode == 2) fuckin_levit(n);       if (!vis[n - 1]) break;       if (d[n - 1] == inf) break;       if (mode == 1) {         for (int i = 0; i < n - 1; i++) phi[i] += vis[i] ? d[i] : d[n - 1];       }       int x = n - 1;       int dflow = inf;       int dcost = 0;       while (x != 0) {         int a = v[x][from[x]].next;         int b = v[x][from[x]].inv;         dflow = min(dflow, v[a][b].cap - v[a][b].flow);         dcost += v[a][b].cost;         x = a;       }       x = n - 1;       while (x != 0) {         int a = v[x][from[x]].next;         int b = v[x][from[x]].inv;         v[a][b].flow += dflow;         v[x][from[x]].flow -= dflow;         x = a;       }       res_flow += dflow;       res_cost += dflow * dcost;     }     return make_pair(res_flow, res_cost);   }   int a[100][100];   vector<pair<int, int> > v1;   vector<pair<int, int> > v2;   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     init();     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (((i + j) % 2) == 0)           v1.push_back(make_pair(i, j));         else           v2.push_back(make_pair(i, j));       }     for (int i = 0; i < v2.size(); i++)       add_edge(i + v1.size() + 1, n * m + 1, 1, 0);     for (int i = 0; i < n * m / 2; i++) add_edge(0, i + 1, 1, 0);     for (int i = 0; i < v1.size(); i++)       for (int j = 0; j < v2.size(); j++) {         int cost = 1;         if (a[v1[i].first][v1[i].second] == a[v2[j].first][v2[j].second])           cost = 0;         if ((abs(v1[i].first - v2[j].first) + abs(v1[i].second - v2[j].second)) ==             1)           if (cost == 0) add_edge(i + 1, j + v1.size() + 1, 1, cost);       }     maxflow(n * m + 2, 0);     for (int i = 0; i < v1.size(); i++)       for (int j = 0; j < v2.size(); j++) {         int cost = 1;         if (a[v1[i].first][v1[i].second] == a[v2[j].first][v2[j].second])           cost = 0;         if ((abs(v1[i].first - v2[j].first) + abs(v1[i].second - v2[j].second)) ==             1)           if (cost == 1) add_edge(i + 1, j + v1.size() + 1, 1, cost);       }     pair<int, int> res = maxflow(n * m + 2, 2);     cout << res.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int get(int x) {     int t = log2(x);     if ((1 << t) < x) t++;     return (1 << t) - x;   }   unordered_map<int, int> to, pos;   unordered_map<int, vector<pair<pair<int, int>, int> > > mp;   int a[200005];   pair<pair<int, int>, int> num[200005];   int len = 0;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int ans = 0, a1 = 0, a2 = 0;     for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;     sort(a + 1, a + n + 1, greater<int>());     for (int i = 1; i <= n; i++) {       int x = a[i];       int cnt = 0;       while (x) {         int t = get(x);         cnt++;         mp[t].emplace_back(make_pair(make_pair(cnt, x), pos[a[i]]));         to[x] = t;         if (pos.count(t)) {           if (cnt > ans) {             ans = cnt;             a1 = pos[a[i]];             a2 = pos[t];           }         }         x = t;       }     }     for (auto u : mp) {       len = 0;       for (auto tu : u.second) {         num[++len] = tu;       }       sort(num + 1, num + len + 1);       pair<pair<int, int>, int> now = num[len];       while (len && num[len].first.second == now.first.second) len--;       if (len) {         pair<pair<int, int>, int> p2 = num[len];         if (now.first.first + p2.first.first > ans) {           ans = now.first.first + p2.first.first;           a1 = now.second;           a2 = p2.second;         }       }     }     cout << a1 <<     << a2 <<     << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T>   using vec = std::vector<T>;   bool __hack = std::ios::sync_with_stdio(false);   auto __hack1 = cin.tie(nullptr);   struct Input {     Input(istream &in) : in(&in) {}     template <class T>     T next() const {       T x;       *in >> x;       return x;     }     int ni() const { return next<int>(); }     istream *in;   };   Input in(cin);   class Output {    private:     ostream *out;     template <typename T>     void printSingle(const T &value) {       *out << value;     }       public:     Output(ostream &out) : out(&out) {}     inline void setPrecision(int d) { *out << fixed << setprecision(d); }     inline void print() {}     template <typename T, typename... Ts>     inline void print(const T &f, const Ts &...args) {       printSingle(f);       if (sizeof...(args) != 0) {         *out <<    ;         print(args...);       }     }     template <typename... Ts>     inline void println(const Ts &...args) {       print(args...);       (*out) <<   n ;     }     template <typename... Ts>     inline void operator()(const Ts &...args) {       println(args...);     }   };   Output out(cout);   namespace template_util {   constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }   template <int N>   struct bytetype {};   template <uint64_t N>   struct minimal_uint : bytetype<bytecount(N)> {};   }  // namespace template_util   double EPS = 1e-10;   bool doubleEqual(double a, double b) { return fabs(a - b) < EPS; }   void solveOne() {     auto n = in.ni();     auto len = in.ni();     vec<int> a(n + 2);     a[0] = 0;     a[n + 1] = len;     for (int i = (1); i <= (n); ++i) a[i] = in.ni();     int i = 0, j = n + 1;     double t = 0;     int s1 = 1, s2 = 1;     double x1 = 0, x2 = len;     out.setPrecision(15);     while (i + 1 < j) {       double d1 = a[i + 1] - x1;       double t1 = d1 / s1;       double d2 = x2 - a[j - 1];       double t2 = d2 / s2;       if (doubleEqual(t1, t2)) {         t += t1;         ++s1;         ++s2;         ++i;         --j;         x1 = a[i];         x2 = a[j];         if (i == j) {           out(t);           return;         }       } else if (t1 < t2) {         t += t1;         ++s1;         ++i;         x1 = a[i];         x2 -= t1 * s2;       } else {         t += t2;         ++s2;         --j;         x2 = a[j];         x1 += t2 * s1;       }     }     double d = x2 - x1;     double s = s1 + s2;     t += d / s;     out(t);   }   void solve(istream &inStream, ostream &outStream) {     in = Input(inStream);     out = Output(outStream);     auto tests = in.ni();     while (tests--) {       solveOne();     }   }   int main() {     solve(cin, cout);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma comment(linker,  /STACK:2000000 )   using namespace std;   template <int D, typename T>   struct Vec : public vector<Vec<D - 1, T>> {     static_assert(D >= 1,  Vector dimension must be greater than zero! );     template <typename... Args>     Vec(int n = 0, Args... args)         : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}   };   template <typename T>   struct Vec<1, T> : public vector<T> {     Vec(int n = 0, T val = T()) : vector<T>(n, val) {}   };   using ll = long long;   using db = long double;   using ii = pair<int, int>;   const int N = 2e5 + 5, LG = 19, MOD = 998244353;   const int SQ = 320;   const long double EPS = 1e-7;   void printCase(int cs) { cout <<  Case #  << cs <<  :  ; }   int n;   vector<ii> arr;   int mx[3005][3005];   void read() {     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       arr.push_back(ii(x, i));     }     sort(arr.rbegin(), arr.rend());     arr.push_back(ii(0, n));   }   int getVal(int i) { return arr[i].first - arr[i + 1].first; }   void initMax() {     for (int i = 0; i < n; i++) {       mx[i][i] = i;       for (int j = i + 1; j < n; j++) {         mx[i][j] = mx[i][j - 1];         if (getVal(j) > getVal(mx[i][j])) {           mx[i][j] = j;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     initMax();     vector<int> ans(6, INT_MIN);     for (int i = 1; i < n; i++)       for (int j = i; j < n; j++)         if (i <= (j - i + 1) * 2 && i * 2 >= (j - i + 1)) {           int mn = min(j - i + 1, i);           int mx = max(j - i + 1, i);           int r = mn * 2;           int l = (mx + 1) / 2;           if (j + l < n) {             int k = ::mx[j + l][min(n - 1, j + r)];             vector<int> v({getVal(i - 1), getVal(j), getVal(k), i, j + 1, k + 1});             ans = max(ans, v);           }         }     vector<int> out(n, -1);     for (int i = 0; i < ans[3]; i++) out[arr[i].second] = 1;     for (int i = ans[3]; i < ans[4]; i++) out[arr[i].second] = 2;     for (int i = ans[4]; i < ans[5]; i++) out[arr[i].second] = 3;     for (int i = 0; i < n; i++) cout << out[i] <<    n [i + 1 == n];     return 0;   }


#include <bits/stdc++.h>   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int main() {     int n, m, p, r, x, y, c, i, j, zb, maxz;     int max1, max2, max3, max4, minz;     scanf( %d %d , &n, &m);     scanf( %d , &c);     for (i = 1; i <= c; i++) {       scanf( %d %d , &x, &y);       if (i == 1) max1 = x + y, max2 = x - y, max3 = -x + y, max4 = -x - y;       if (i > 1 && x + y > max1) max1 = x + y;       if (i > 1 && x - y > max2) max2 = x - y;       if (i > 1 && -x + y > max3) max3 = -x + y;       if (i > 1 && -x - y > max4) max4 = -x - y;     }     scanf( %d , &r);     for (i = 1; i <= r; i++) {       scanf( %d %d , &x, &y);       maxz = max(max1 - (x + y), max2 - (x - y));       maxz = max(maxz, max3 - (-x + y));       maxz = max(maxz, max4 - (-x - y));       if (i == 1) minz = maxz, zb = 1;       if (i > 1 && maxz < minz) minz = maxz, zb = i;     }     printf( %d n , minz);     printf( %d n , zb);   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> g;   vector<vector<pair<long long, int> > > vec;   const int MAXN = 100010;   pair<long long, int> msum[MAXN][2];   bool cmp2(pair<long long, int> a, pair<long long, int> b) {     return b.first < a.first;   }   int main() {     int n, c, s;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &c, &s);       if (g.find(c) == g.end()) {         g[c] = vec.size();         vec.push_back(vector<pair<long long, int> >());       }       int id = g[c];       vec[id].push_back(make_pair(s, i + 1));     }     int len = 0;     for (int i = 0; i < vec.size(); ++i) {       sort(vec[i].begin(), vec[i].end(), cmp2);       len = max(len, (int)vec[i].size());       for (int j = 0; j < vec[i].size(); ++j) {         if (j != 0) vec[i][j].first += vec[i][j - 1].first;         if (vec[i][j].first >= msum[j][0].first) {           msum[j][1] = msum[j][0];           msum[j][0].first = vec[i][j].first;           msum[j][0].second = i;         } else if (vec[i][j].first > msum[j][1].first) {           msum[j][1].first = vec[i][j].first;           msum[j][1].second = i;         }       }     }     long long ans = 0;     int fc = -1, fl, sc, sl;     for (int i = 0; i < len; ++i) {       if (msum[i][0].first == 0) continue;       if (msum[i][1].first != 0) {         if (msum[i][0].first + msum[i][1].first > ans) {           ans = msum[i][0].first + msum[i][1].first;           fc = msum[i][0].second, fl = i + 1;           sc = msum[i][1].second, sl = i + 1;         }       }       if (i + 1 == len || msum[i + 1][0].first == 0) continue;       if (msum[i + 1][0].second != msum[i][0].second) {         if (msum[i][0].first + msum[i + 1][0].first > ans) {           ans = msum[i][0].first + msum[i + 1][0].first;           fc = msum[i][0].second, fl = i + 1;           sc = msum[i + 1][0].second, sl = i + 2;         }       } else {         if (msum[i][1].first != 0 &&             msum[i][1].first + msum[i + 1][0].first > ans) {           ans = msum[i][1].first + msum[i + 1][0].first;           fc = msum[i][1].second, fl = i + 1;           sc = msum[i + 1][0].second, sl = i + 2;         }         if (msum[i + 1][1].first != 0 &&             msum[i][0].first + msum[i + 1][1].first > ans) {           ans = msum[i][0].first + msum[i + 1][1].first;           fc = msum[i][0].second, fl = i + 1;           sc = msum[i + 1][1].second, sl = i + 2;         }       }     }     cout << ans << endl;     if (fc != -1) {       cout << fl + sl << endl;       for (int i = 0; i < fl; ++i) {         if (i) putchar(   );         printf( %d %d , vec[sc][i].second, vec[fc][i].second);       }       if (sl != fl) {         printf(  %d , vec[sc][fl].second);       }       puts(  );     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int c[N], ctr[N] = {0};   vector<pair<int, int> > candidates, edges;   int main() {     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       edges.push_back({u, v});     }     for (int i = 1; i <= n; ++i) cin >> c[i];     for (auto &i : edges) {       if (c[i.first] != c[i.second]) candidates.push_back(i);     }     if (candidates.empty()) {       cout <<  YES n1 ;       return 0;     }     int m = candidates.size();     for (auto &i : candidates) {       ctr[i.first]++;       ctr[i.second]++;     }     for (int i = 1; i <= n; ++i) {       if (ctr[i] == m) {         cout <<  YES n  << i;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   string s1, s2;   set<char> st;   vector<int> t[300];   int bin_search(char k, int ind) {     int l = 0, r = t[k].size() - 1, m;     while (l < r) {       m = (l + r) / 2;       if (ind == t[k][m]) return t[k][m];       if (ind < t[k][m])         r = m;       else         l = m + 1;     }     if (l && t[k][l - 1] == ind) return t[k][l - 1];     return t[k][l];   }   int main() {     cin >> s1 >> s2;     for (int i = 0; i < s1.size(); i++) t[s1[i]].push_back(i);     for (int j = 0; j < s2.size(); j++)       if (!t[s2[j]].size()) {         cout <<  -1 ;         return 0;       }     int ans = 1, j = 0;     for (int i = 0; i < s2.size(); i++) {       int p = bin_search(s2[i], j);       if (p < j) {         ans++;         j = bin_search(s2[i], 0) + 1;       } else {         j = p + 1;       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 300;   int main() {     string s;     int h;     cin >> h;     cin >> s;     int ans = s.size();     for (int i = 1; s[i]; i++) {       if ((s[i] ==  U  && s[i - 1] ==  R ) || (s[i] ==  R  && s[i - 1] ==  U )) {         s[i] =  p ;         --ans;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 300010;   vector<long long> arr[MAXN];   vector<pair<long long, long long>> holdqs[MAXN];   bool visited[MAXN];   long long answer[MAXN];   long long temp[MAXN];   long long n;   void dfs(long long curr, long long par, long long level, long long ans) {     for (auto x : holdqs[curr]) {       long long lb = level;       long long rb = level + 1 + x.first;       temp[lb] += x.second;       if (rb <= n) {         temp[rb] -= x.second;       }     }     ans += temp[level];     answer[curr] = ans;     for (auto x : arr[curr]) {       if (x != par) {         dfs(x, curr, level + 1, ans);       }     }     for (auto x : holdqs[curr]) {       long long lb = level;       long long rb = level + 1 + x.first;       temp[lb] -= x.second;       if (rb <= n) {         temp[rb] += x.second;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       arr[x].push_back(y);       arr[y].push_back(x);     }     long long q;     cin >> q;     while (q--) {       long long v, d, x;       cin >> v >> d >> x;       holdqs[v].push_back(make_pair(d, x));     }     dfs(1, 1, 1, 0);     for (long long i = 1; i <= n; i++) {       std::cout << answer[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char a[25][25];   int dp[40][1 << 20], n;   bool vis[40][1 << 20];   int f(int xx, int st) {     if (vis[xx][st]) return dp[xx][st];     int &res = dp[xx][st];     vis[xx][st] = true;     if (xx == n * 2 - 2) {       res = 0;     } else {       if (xx & 1)         res = -0x3f3f3f3f;       else         res = 0x3f3f3f3f;       int mask[30];       memset(mask, 0, sizeof(mask));       int cnt = 0;       for (int j = 0; j <= xx + 1; ++j) {         int x = xx + 1 - j;         int y = j;         if (x >= n || y >= n) continue;         mask[a[x][y] -  a ] |= (1 << cnt);         cnt++;       }       for (int i = 0; i < 26; ++i) {         if (mask[i]) {           int xt;           if (xx + 1 < n)             xt = (st | (st << 1)) & mask[i];           else             xt = (st | (st >> 1)) & mask[i];           if (xt == 0) continue;           int tmp = 0;           if (i == 0)             tmp = 1;           else if (i == 1)             tmp = -1;           if (xx & 1)             res = max(res, tmp + f(xx + 1, xt));           else             res = min(res, tmp + f(xx + 1, xt));         }       }     }     if (xx == 0) {       if (a[0][0] ==  a )         res += 1;       else if (a[0][0] ==  b )         res -= 1;     }     return res;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) scanf( %s , a[i]);       memset(vis, 0, sizeof(vis));       int res = f(0, 1);       if (res == 0)         printf( DRAW n );       else if (res > 0)         printf( FIRST n );       else         printf( SECOND n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const long long MAXN = 500010;   const long long Mod = 1000000007LL;   struct data {     long long x, y;     inline void ModT() { x %= Mod, y %= Mod; }   } a[MAXN + 1], pre[MAXN + 1];   inline data md(long long x, long long y) {     data xxx;     xxx.x = x, xxx.y = y;     return xxx;   }   inline long long operator*(const data &a, const data &b) {     return a.x * b.y - b.x * a.y;   }   inline data operator+(const data &a, const data &b) {     return md(a.x + b.x, a.y + b.y);   }   inline data operator-(const data &a, const data &b) {     return md(a.x - b.x, a.y - b.y);   }   long long N, tmp, Sum0[MAXN + 1], Sum1[MAXN + 1], ans;   int main() {     N = read();     for (long long i = 1; i <= N; i++) {       long long x = read(), y = read();       a[i] = md(x, y);       pre[i] = pre[i - 1] + a[i], pre[i].ModT();     }     for (int i = 2; i <= N; i++) {       tmp = a[i - 1] * a[i];       Sum0[i] = Sum0[i - 1] + tmp;       Sum1[i] = (Sum1[i - 1] + Sum0[i]) % Mod;     }     long long Now = abs(Sum0[N + 1] = Sum0[N] + a[N] * a[1]);     long long j = 1;     for (long long i = 3; i <= N; i++) {       for (; j < i - 1 && abs(Sum0[i] - Sum0[j] + a[i] * a[j]) > Now / 2.0; ++j)         ;       ans = (ans + Sum0[i] % Mod * (i - 1 - j) - (Sum1[i - 2] - Sum1[j - 1]) +              a[i] * (pre[i - 2] - pre[j - 1])) %             Mod;       ans = (ans + Sum1[j - 1] + pre[j - 1] * a[i] +              (Sum0[N + 1] - Sum0[i]) % Mod * (j - 1)) %             Mod;     }     ans = ((Now % Mod * (Mod + 1 >> 2) % Mod * N % Mod * (N - 3) % Mod + ans) %                Mod +            Mod) *           2LL % Mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 Rand(time(0));   const int maxn = 5e2 + 5;   const long long maxc = 1e9 + 7;   int n, m;   vector<int> adj[maxn];   int d[maxn][maxn];   pair<int, int> trace[maxn][maxn];   vector<int> resOne, resN;   void bfs() {     queue<pair<int, int> > q;     q.push(make_pair(1, n));     memset(d, (-1), sizeof(d));     d[1][n] = 0;     while (!q.empty()) {       int s = q.front().first;       int t = q.front().second;       q.pop();       for (auto u : adj[s]) {         for (auto v : adj[t]) {           if (d[u][v] != -1 || u == v) continue;           trace[u][v] = make_pair(s, t);           d[u][v] = d[s][t] + 1;           q.push(make_pair(u, v));         }       }     }     cout << d[n][1] <<   n ;     if (d[n][1] == -1) return;     int s = 1, t = n;     while (t != 0) {       resOne.push_back(t);       resN.push_back(s);       pair<int, int> cur = trace[t][s];       t = cur.first, s = cur.second;     }     reverse((resOne).begin(), (resOne).end());     reverse((resN).begin(), (resN).end());     for (auto u : resOne) cout << u <<    ;     cout <<   n ;     for (auto u : resN) cout << u <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     bfs();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 + 5;   const int LEN = 1e6 + 10;   int n, m, q;   int a[N];   int b[N];   int f[N][N];   char ch[LEN];   int g[LEN], l;   int xt[N * N], yt[N * N];   int dp[N][N];   int cnt, cir[N * N][10];   int lc[N * N];   int c0[N][N];   int bel[N][N];   int nx[N][N], ny[N][N];   int rd[N][N];   int v[N][N], cc;   int pre[N][N];   bool check(int x, int y) {     if (x <= 0 || y <= 0 || x >= n + 1 || y >= m + 1)       return false;     else       return true;   }   void dfs_1(int x, int y) {     v[x][y] = cc;     int x0 = nx[x][y], y0 = ny[x][y];     if (v[x0][y0] > 0) {       if (v[x0][y0] == cc) c0[x0][y0] = ++cnt;       return;     }     dfs_1(x0, y0);   }   void dfs_2(int x, int y, int k) {     v[x][y] = k;     bel[x][y] = k;     cir[k][f[x][y]] = true;     int x0 = nx[x][y], y0 = ny[x][y];     if (v[x0][y0] > 0) return;     dfs_2(x0, y0, k);   }   void init() {     cin >> n >> m >> q;     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; i++) {       scanf( %s , ch);       for (int j = 1; j <= m; j++) f[i][j] = ch[j - 1] -  0 ;     }     for (int i = 0; i < 10; i++) scanf( %d %d , &a[i], &b[i]);     cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         nx[i][j] = i + a[f[i][j]];         ny[i][j] = j + b[f[i][j]];         if (!check(nx[i][j], ny[i][j])) {           nx[i][j] = i;           ny[i][j] = j;           bel[i][j] = ++cnt;           v[i][j] = cnt;           cir[cnt][f[i][j]] = true;         }         rd[nx[i][j]][ny[i][j]]++;       }     cc = cnt;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (v[i][j] == 0) {           cc++;           dfs_1(i, j);         }     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (c0[i][j] > 0) {           dfs_2(i, j, c0[i][j]);         }   }   bool bfs() {     int L, R, x1, y1, x2, y2;     L = 1, R = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (rd[i][j] == 0) {           R++;           xt[R] = i, yt[R] = j;           pre[i][j] = 0;         } else           pre[i][j] = rd[i][j];     while (L <= R) {       x1 = xt[L], y1 = yt[L];       x2 = nx[x1][y1], y2 = ny[x1][y1];       if (dp[x1][y1] >= l) return true;       if (g[dp[x1][y1] + 1] == f[x1][y1]) dp[x1][y1]++;       dp[x2][y2] = max(dp[x1][y1], dp[x2][y2]);       pre[x2][y2]--;       if (pre[x2][y2] == 0) {         R++;         xt[R] = x2, yt[R] = y2;       }       if (bel[x2][y2] != 0) {         if (lc[bel[x2][y2]] <= dp[x2][y2]) return true;       }       L++;     }     return false;   }   void work() {     bool sign;     for (int i = 1; i <= q; i++) {       scanf( %s , ch);       l = strlen(ch);       memset(dp, 0, sizeof(dp));       for (int j = 1; j <= l; j++) g[j] = ch[j - 1] -  0 ;       sign = false;       for (int j = 1; j <= cnt; j++) {         lc[j] = l;         while (cir[j][g[lc[j]]] && lc[j] != 0) lc[j]--;         if (lc[j] == 0) {           sign = true;           break;         }       }       if (sign) {         cout <<  YES  << endl;         continue;       }       if (bfs())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   int m, n, s;   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 0; i <= 40; i++)       for (int j = 0; j <= 40; j++) {         if (i * i + j == n && j * j + i == m) ans++;       }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int n;   long long x1, x2;   struct sss {     long long val;     int num;   } a[maxn];   bool cmp(const sss &a, const sss &b) { return a.val > b.val; }   void scanff() {     scanf( %d%I64d%I64d , &n, &x1, &x2);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i].val);       a[i].num = i;     }     sort(a + 1, a + n + 1, cmp);   }   void work() {     int now1, now2;     bool flag = false;     if (x1 < x2) {       swap(x1, x2);       flag = true;     }     for (now1 = 1; now1 <= n; now1++) {       if (a[now1].val * now1 >= x1) break;     }     if (now1 > n) {       printf( No n );       return;     }     for (now2 = now1 + 1; now2 <= n; now2++) {       if (a[now2].val * (now2 - now1) >= x2) break;     }     if (now2 > n) {       int head = 1, tail = now1;       for (;;) {         if (tail + 1 <= n) {           if (a[tail + 1].val * (tail - head + 1) >= x1) {             tail++;             head++;             if (a[head - 1].val * (head - 1) >= x2) {               printf( Yes n );               if (!flag) {                 printf( %d %d n , tail - head + 1, head - 1);                 for (int i = head; i <= tail; i++) {                   printf( %d  , a[i].num);                 }                 printf(  n );                 for (int i = 1; i <= head - 1; i++) {                   printf( %d  , a[i].num);                 }                 return;               } else {                 printf( %d %d n , head - 1, tail - head + 1);                 for (int i = 1; i <= head - 1; i++) {                   printf( %d  , a[i].num);                 }                 printf(  n );                 for (int i = head; i <= tail; i++) {                   printf( %d  , a[i].num);                 }                 return;               }             }           } else {             tail++;           }         } else           break;       }       printf( No n );       return;     }     printf( Yes n );     if (!flag) {       printf( %d %d n , now1, now2 - now1);       for (int i = 1; i <= now1; i++) {         printf( %d  , a[i].num);       }       printf(  n );       for (int i = now1 + 1; i <= now2; i++) {         printf( %d  , a[i].num);       }     } else {       printf( %d %d n , now2 - now1, now1);       for (int i = now1 + 1; i <= now2; i++) {         printf( %d  , a[i].num);       }       printf(  n );       for (int i = 1; i <= now1; i++) {         printf( %d  , a[i].num);       }     }   }   int main() {     scanff();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct state {     int i, j, dp, cp;   };   int di[] = {0, 1, 0, -1};   int dj[] = {1, 0, -1, 0};   state n[50][50][4][2];   state current;   char b[50][51];   int r, c;   int moves;   void read() {     cin >> r >> moves;     for (int i = 0; i < r; i++) {       cin >> b[i];     }     c = strlen(b[0]);   }   void write() { cout << b[current.i][current.j] <<   n ; }   inline bool valid(int i, int j) {     return i > -1 && i < r && j > -1 && j < c && b[i][j] !=  0 ;   }   void preprocess(int i, int j, int dp, int cp) {     int ni = i, nj = j;     while (valid(ni, nj) && b[ni][nj] == b[i][j]) {       ni += di[dp];       nj += dj[dp];     }     ni -= di[dp];     nj -= dj[dp];     int p = (dp + (cp ? +1 : -1) + 4) % 4;     while (valid(ni, nj) && b[ni][nj] == b[i][j]) {       ni += di[p];       nj += dj[p];     }     ni -= di[p];     nj -= dj[p];     ni += di[dp];     nj += dj[dp];     if (valid(ni, nj)) {       n[i][j][dp][cp].i = ni;       n[i][j][dp][cp].j = nj;       n[i][j][dp][cp].dp = dp;       n[i][j][dp][cp].cp = cp;     } else {       n[i][j][dp][cp].i = i;       n[i][j][dp][cp].j = j;       n[i][j][dp][cp].dp = !cp ? dp : (dp + 1) % 4;       n[i][j][dp][cp].cp = !cp;     }   }   void preprocess() {     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         for (int dp = 0; dp < 4; dp++) {           for (int cp = 0; cp < 2; cp++) {             preprocess(i, j, dp, cp);           }         }       }     }   }   void move() {     for (int i = 0; i < moves; i++) {       current = n[current.i][current.j][current.dp][current.cp];     }   }   int main() {     current.i = current.j = current.dp = current.cp = 0;     read();     preprocess();     move();     write();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize  Ofast,omit-frame-pointer,inline    using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int mx = -INT_MAX;     multiset<int> vs;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       mx = max(mx, x);       vs.insert(x);     }     mx += m;     while (m--) {       int p = *vs.begin();       vs.insert(p + 1);       vs.erase(vs.begin());     }     cout << (*vs.rbegin()) <<     << mx << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int main() {     int n, m, t;     cin >> n >> m >> t;     int total = (n - 2) * (n - 1) / 2 + 1;     if (total >= m && m >= n - 1) {       m = m - n + 1;       int cant = 0;       if (t != 1)         cant = 1;       else         cant = n;       printf( %d %d n , t, cant);       for (int i = 1; i < n; i++) {         if (i != cant && i + 1 != cant) printf( %d %d n , i, i + 1);       }       for (int i = 1; i <= n && m; i++) {         if (t - i == 1 || i - t == 1 || t == i || i == cant) continue;         printf( %d %d n , i, t);         m--;       }       for (int i = 1; i <= n && m; i++) {         if (i == t || i == cant) continue;         for (int j = i + 2; j <= n && m; j++) {           if (j == t || j == cant) continue;           printf( %d %d n , i, j);           m--;         }       }     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e6;   const long long MOD = 1e9 + 7;   const long long N = 1e6 + 7;   const long long N_N = 1e3;   const int INF = 1e9 + 228;   const long double eps = 1e-12;   long long n, a[N], ans, l, ans1;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 2; i <= n; ++i) {       if (a[i - 1] > a[i]) {         ans++;         ans1 = i;       }     }     if (ans > 1) {       cout << -1;     }     if (ans == 0) {       cout << 0;     }     if (ans == 1) {       if (a[1] >= a[ans1] && a[1] >= a[n]) {         cout << n - ans1 + 1;       } else         cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 2e6 + 5;   const int oo = 1e9 + 7;   int lp[N + 1];   vector<int> pr;   void sieve() {     for (int i = 2; i <= N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)         lp[i * pr[j]] = pr[j];     }   }   int n;   int a[N];   bool isp[N];   int cnt(int x) { return upper_bound(a, a + n, x) - lower_bound(a, a + n, x); }   int chk() {     for (int i = upper_bound(a, a + n, 1) - a; i < n; i++) {       if (isp[a[i] + 1]) return a[i];     }     return 0;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     sieve();     for (int i : pr) isp[i] = 1;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int y = chk();     int x = cnt(1) + (y > 0);     if (x >= 2) {       cout << x <<   n ;       if (y) {         cout << y <<    ;         x--;       }       for (int i = 1; i <= x; i++) cout <<  1  ;       cout <<   n ;     } else {       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           if (isp[a[i] + a[j]]) {             cout <<  2 n ;             cout << a[i] <<     << a[j] << endl;             return 0;           }         }       }       cout <<  1 n ;       cout << a[0] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   const int maxn = 16;   char tp[maxn];   int r[maxn], b[maxn];   int dp[1 << maxn][2][16 * 16 * 1];   int inf = (int)(1e9);   int go(int msk, int R, int B, int x, int y) {     x = min(x, n * n);     y = min(y, n * n);     if (msk == (1 << n) - 1) return 0;     int &res = dp[msk][y == 0][max(x, y)];     if (res != -1) return res;     res = inf;     for (int i = 0; i < n; i++) {       if (msk & (1 << i)) continue;       int costr = max(0, r[i] - R);       int costb = max(0, b[i] - B);       int needr = max(0, costr - x);       int needb = max(0, costb - y);       int t = max(needr, needb);       res = min(res, t + go(msk | (1 << i), R + (tp[i] ==  R ),                             B + (tp[i] ==  B ), x + t - costr, y + t - costb));     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tp[i] >> r[i] >> b[i];     }     int needr = 0, needb = 0;     for (int i = 0; i < n; i++) {       needr += max(0, r[i] - n);       needb += max(0, b[i] - n);       r[i] = min(r[i], n);       b[i] = min(b[i], n);     }     int t = max(needr, needb);     memset(dp, -1, sizeof(dp));     cout << n + t + go(0, 0, 0, t - needr, t - needb) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve(int i, int a, int b, int c) {     if (i == 0) return a + b + c;     if (i == 1) return max((a + b) * c, a + b * c);     if (i == 2) return max(a * (b + c), a * b + c);     return a * b * c;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b, c;     cin >> a >> b >> c;     int ans = 0;     for (int i = 0; i < 4; ++i) {       ans = max(ans, solve(i, a, b, c));       ans = max(ans, solve(i, c, b, a));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k;   string s;   vector<string> ans;   bool all[26];   int main() {     ios_base::sync_with_stdio(0);     cin >> k >> s;     string build =   ;     for (int i = 0; i < s.size(); ++i)       if (!all[s[i] -  a ]) {         if (!build.empty()) ans.push_back(build);         build = s[i];         all[s[i] -  a ] = 1;       } else         build += s[i];     ans.push_back(build);     if (ans.size() < k)       cout <<  NO ;     else {       cout <<  YES             <<   n ;       while (ans.size() > k) {         int last = ans.size() - 1;         string s1 = ans[last], s2 = ans[last - 1];         ans.pop_back();         ans.pop_back();         ans.push_back(s2 + s1);       }       for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int mxn = 21;   long long n, res;   int m;   struct Node {     long long a;     int b;     bool operator<(const Node& c) const { return b > c.b; }   } nodes[mxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> nodes[i].a >> nodes[i].b;     }     sort(nodes + 1, nodes + 1 + m);     for (int i = 1; i <= m; ++i) {       if (n >= nodes[i].a) {         res += nodes[i].a * nodes[i].b;         n -= nodes[i].a;       } else {         res += n * nodes[i].b;         break;       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   vector<pair<int, int> > g[3005];   pair<int, int> es[3005];   int dfs(int v, int p) {     int res = 0;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res += e.second + dfs(e.first, v);     }     return res;   }   int move(int v, int p, int val) {     int res = val;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res = min(res, move(e.first, v, val + 1 - e.second * 2));     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(make_pair(b, 0));       g[b].push_back(make_pair(a, 1));       es[i] = make_pair(a, b);     }     int ans = INF;     if (n <= 2) ans = 0;     for (int i = 0; i < n - 1; ++i) {       int A, B;       A = es[i].first;       B = es[i].second;       int sum1 = dfs(A, B), sum2 = dfs(B, A);       ans = min(ans, move(A, B, sum1) + move(B, A, sum2));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[500005], b[500005], dp[500005], t;   vector<long long> c;   void poisk_del(long long z) {     for (int del = 2; del * del <= z; del++) {       if (z % del == 0) c.push_back(del);       while (z % del == 0) {         z /= del;       }     }     if (z != 1) c.push_back(z);   }   void add(int s) {     for (long long mask = 1; mask < (1 << s); mask++) {       long long proz = 1;       int kol = 0;       for (int j = 0; j < s; j++) {         if ((mask & (1 << j)) > 0) {           proz *= c[j];           kol++;         }       }       if (kol % 2 == 1) {         t += dp[proz];         dp[proz]++;       } else {         t -= dp[proz];         dp[proz]++;       }     }   }   void delet(int s) {     for (long long mask = 1; mask < (1 << s); mask++) {       long long proz = 1;       int kol = 0;       for (int j = 0; j < s; j++) {         if ((mask & (1 << j)) > 0) {           proz *= c[j];           kol++;         }       }       if (kol % 2 == 1) {         dp[proz]--;         t -= dp[proz];       } else {         dp[proz]--;         t += dp[proz];       }     }   }   int main() {     long long n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     n = 0;     for (int i = 0; i < q; i++) {       int x;       cin >> x;       x--;       c.clear();       if (b[x] == 0) {         n++;         b[x] = 1;         poisk_del(a[x]);         int s = c.size();         long long ans = (n * (n + 1) / 2) - n;         add(s);         cout << ans - t << endl;       } else {         n--;         b[x] = 0;         poisk_del(a[x]);         int s = c.size();         long long ans = (n * (n + 1) / 2) - n;         delet(s);         cout << ans - t << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   map<pair<int, int>, int> mp;   int cnt[1000000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i + 1];       ans += arr[i + 1];     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int s, t, u;       cin >> s >> t >> u;       if (mp[make_pair(s, t)]) {         cnt[mp[make_pair(s, t)]]--;         if (cnt[mp[make_pair(s, t)]] < arr[mp[make_pair(s, t)]]) {           ans++;         }       }       cnt[u]++;       mp[make_pair(s, t)] = u;       if (cnt[u] <= arr[u]) ans--;       cout << max(ans, n) << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160 )   using namespace std;   int n, i, j, a, b, x[100001], y[100001], v, k, uns[100001], p, q, w[6];   int findd(int l, int r, int xx) {     int t;     t = (l + r) / 2;     if (l == r) {       if (x[l] == xx)         return l;       else         return -1;     } else {       if (x[t] >= xx)         return findd(l, t, xx);       else         return findd(t + 1, r, xx);     }   }   int main() {     cin >> n;     cin >> a >> b;     if (a > b) {       p = 1;       q = 2;     } else {       p = 2;       q = 1;     }     for (i = 0; i < n; i++) {       cin >> x[i];       y[i] = x[i];     }     sort(x, x + n);     if (a == b) {       for (i = 1; i <= a; i++) cout << 1 <<    ;       for (i = 1; i <= b; i++) cout << 2 <<    ;       cout << endl;       return 0;     }     memset(w, 0, sizeof(w));     for (i = 0; i < n; i++) uns[i] = q;     k = 0;     v = max(a, b);     for (i = 0; i < v; i++) w[x[i]]++;     if (p == 1) {       for (i = 0; i < n; i++) {         if (w[y[i]]) {           uns[i] = p;           k++;           w[y[i]]--;         }       }     } else {       for (i = n - 1; i >= 0; i--) {         if (w[y[i]]) {           uns[i] = p;           k++;           w[y[i]]--;         }       }     }     for (i = 0; i < n; i++) cout << uns[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int D[1 << 20], cnt[20][20];   bool chk[1 << 20];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int N, M;     queue<int> Q;     string s;     cin >> N >> M >> s;     for (int i = 1; i < N; i++)       if (s[i - 1] != s[i]) {         cnt[s[i - 1] -  a ][s[i] -  a ]++;         cnt[s[i] -  a ][s[i - 1] -  a ]++;       }     memset(D, 0x7f, sizeof(D));     chk[0] = true;     D[0] = 0;     Q.push(0);     while (!Q.empty()) {       int b = Q.front(), bc = __builtin_popcount(b) + 1;       Q.pop();       for (int i = 0; i < M; i++)         if (~b & (1 << i)) {           int diff = 0;           for (int j = 0; j < M; j++) {             if (b & (1 << j))               diff += bc * cnt[i][j];             else               diff -= bc * cnt[i][j];           }           D[b | (1 << i)] = min(D[b | (1 << i)], D[b] + diff);           if (!chk[b | (1 << i)]) {             chk[b | (1 << i)] = true;             Q.push(b | (1 << i));           }         }     }     cout << D[(1 << M) - 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   void solve() {     int n;     cin >> n;     vector<string> s(n);     for (int i = 0; i < n; i++) cin >> s[i];     sort(s.begin(), s.end(), compare);     for (int i = 0; i < n - 1; i++)       if (s[i + 1].find(s[i]) == -1) {         cout <<  NO n ;         return;       }     cout <<  YES n ;     for (int i = 0; i < n; i++) cout << s[i] << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }