#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   const long long LINF = (long long)1e18 + 5;   const int INF = (int)1e9 + 5;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <class T>   long long round(T x) {     return x < 0 ? x - 0.5 : x + 0.5;   }   template <class T>   bool chmin(T& x, const T& y) {     if (y < x) {       x = y;       return true;     }     return false;   }   template <class T>   bool chmax(T& x, const T& y) {     if (x < y) {       x = y;       return true;     }     return false;   }   template <class P, class Q>   ostream& operator<<(ostream& os, const pair<P, Q>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     bool was = false;     os <<  { ;     for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {       if (was) {         os <<  ,  ;       } else {         was = true;       }       os << *it;     }     os <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& v) {     bool was = false;     os <<  { ;     for (typename set<T>::const_iterator it = v.begin(); it != v.end(); it++) {       if (was) {         os <<  ,  ;       } else {         was = true;       }       os << *it;     }     os <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const multiset<T>& v) {     bool was = false;     os <<  { ;     for (typename multiset<T>::const_iterator it = v.begin(); it != v.end();          it++) {       if (was) {         os <<  ,  ;       } else {         was = true;       }       os << *it;     }     os <<  } ;     return os;   }   template <class P, class Q>   ostream& operator<<(ostream& os, const map<P, Q>& v) {     bool was = false;     os <<  { ;     for (typename map<P, Q>::const_iterator it = v.begin(); it != v.end(); it++) {       if (was) {         os <<  ,  ;       } else {         was = true;       }       os << *it;     }     os <<  } ;     return os;   }   template <class T>   T nextInt() {     long long x = 0;     bool p = false;     char c;     do {       c = getchar();     } while (c <= 32);     if (c ==  - ) {       p = true;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return (p ? -x : x);   }   string nextToken() {     static char str[200200];     scanf( %s , str);     return str;   }   const int N = 300300;   int n;   long long t[N], w[N];   struct cmpByDiff {     bool operator()(int i, int j) {       return make_pair(w[i] - t[i], i) < make_pair(w[j] - t[j], j);     }   };   struct cmpByT {     bool operator()(int i, int j) {       return make_pair(t[i], i) > make_pair(t[j], j);     }   };   set<int, cmpByDiff> topSet;   set<int, cmpByT> loserSet;   void answer(int x) {     printf( %d n , x);     exit(0);   }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld%lld , t + i, w + i);     }     long long curT = t[0];     for (int i = 1; i < n; i++) {       if (t[i] > curT) {         topSet.insert(i);       } else {         loserSet.insert(i);       }     }     int best = (int)topSet.size() + 1;     while (true) {       best = min(best, (int)topSet.size() + 1);       if (topSet.empty()) {         answer(1);       }       int idx = *topSet.begin();       topSet.erase(idx);       long long cost = w[idx] - t[idx] + 1;       if (cost > curT) break;       curT -= cost;       while (!loserSet.empty()) {         int jdx = *loserSet.begin();         loserSet.erase(jdx);         if (t[jdx] > curT) {           topSet.insert(jdx);         } else {           loserSet.insert(jdx);           break;         }       }     }     answer(best);   }   int main() {     srand(time(0));     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   char a1[] =  ### ..# .#. #.. ;   char a2[] =  .#. ### .#. ### ;   char a3[] =  .#. ..# ### #.. ;   vector<int> px[4], py[4];   int n, m, grid[10][10], mx, res[10][10];   void solve(int x, int y, int curr) {     if (y >= m) {       solve(x + 1, 0, curr);       return;     }     if (x >= n) {       if (curr > mx) mx = curr, memcpy(res, grid, sizeof(res));       return;     }     int i, j, k, d, tmp[10][10], nx, ny;     int mxPossible = 0;     for (i = y; i < m; i++)       if (grid[x][i] == 0) mxPossible++;     for (i = x; i < n; i++)       for (j = 0; j < m; j++)         if (grid[i][j] == 0) mxPossible++;     mxPossible /= 5;     if (mxPossible + curr <= mx) return;     memcpy(tmp, grid, sizeof(tmp));     for (d = 0; d < 4; d++) {       bool canPlace = 1;       memcpy(grid, tmp, sizeof(tmp));       for (i = 0; i < px[d].size(); i++) {         nx = x + px[d][i];         ny = y + py[d][i];         if (nx >= n or ny >= m or grid[nx][ny]) {           canPlace = 0;           break;         }         grid[nx][ny] = curr + 1;       }       if (canPlace) {         solve(x, y + 1, curr + 1);       }     }     memcpy(grid, tmp, sizeof(tmp));     solve(x, y + 1, curr);   }   int main() {     int i, j, tcc, tc = 1 << 28;     for (i = 0; i < 4; i++) {       for (j = 0; j < 3; j++)         if (a1[i * 4 + j] ==  # ) px[i].push_back(0), py[i].push_back(j);       for (j = 0; j < 3; j++)         if (a2[i * 4 + j] ==  # ) px[i].push_back(1), py[i].push_back(j);       for (j = 0; j < 3; j++)         if (a3[i * 4 + j] ==  # ) px[i].push_back(2), py[i].push_back(j);     }     for (tcc = 0; tcc < tc; tcc++) {       n = getint(), m = getint(), mx = 0;       if (n == 9 and m == 9) {         puts( 13 );         puts(              AAA.BCCC. n.ABBB.CD. n.AE.BFCD. nEEEFFFDDD nG.E.HFIII nGGGJHHHI.                nGK.JHL.IM n.KJJJLMMM nKKK.LLL.M n );         continue;       }       memset(res, 0, sizeof(res));       memset(grid, 0, sizeof(grid));       solve(0, 0, 0);       printf( %d n , mx);       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           if (res[i][j] == 0)             putchar( . );           else             putchar( A  + res[i][j] - 1);         }         puts(  );       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int v[300001], sol[300001], S;   int cnt = 0, marked[300001], dp[300001][2];   vector<int> g[300001];   long long int dfs(int node, int p) {     sol[node] = v[node];     long long int res = sol[node];     for (auto it : g[node])       if (it != p) {         res = max(res, dfs(it, node));         if (sol[it] > 0) sol[node] += sol[it];       }     res = max(res, sol[node]);     return res;   }   void getcnt(int node, int p) {     for (auto it : g[node])       if (it != p) {         getcnt(it, node);         if (sol[it] > 0 && marked[it]) marked[node] = 1;       }     if (!marked[node] && sol[node] == S) {       cnt++;       marked[node] = 1;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, i, a, b, k;     cin >> n;     for (i = 0; i < n; i++) cin >> v[i];     for (i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u - 1].push_back(v - 1);       g[v - 1].push_back(u - 1);     }     S = dfs(0, 0);     getcnt(0, 0);     cout << S * cnt <<     << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   using ll = long long;   using vll = int64_t;   const int N = 1e6 + 1;   vector<int> adj[N];   vector<bool> vis(N, false);   vector<short> col(N, -1);   inline bool bfs(int src) {     queue<pair<int, int>> q;     q.push({src, 0});     vis[src] = true;     col[src] = 0;     while (!q.empty()) {       auto p = q.front();       q.pop();       for (int i : adj[p.first]) {         if (vis[i]) {           if (col[i] == col[p.first]) {             return false;           }           continue;         }         vis[i] = true;         col[i] = (p.second == 1 ? 0 : 1);         q.push({i, col[i]});       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int m;     cin >> m;     unordered_set<int> hs;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       hs.insert(a);       hs.insert(b);     }     for (int i = 0; i < n; i++) {       if (!vis[i] && hs.find(i) != hs.end()) {         bool ok = bfs(i);         if (!ok) {           cout <<  -1 n ;           return 0;         }       }     }     int red = 0, black = 0;     for (int i = 0; i < n; i++) {       if (col[i] == 1)         black++;       else if (col[i] == 0)         red++;     }     cout << red <<   n ;     for (int i = 0; i < n; i++) {       if (col[i] == 0) cout << 1 + i <<    ;     }     cout <<   n ;     cout << black <<   n ;     for (int i = 0; i < n; i++) {       if (col[i] == 1) cout << i + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long b, long long p) {     long long res = 1;     a %= p;     b %= p - 1;     while (b) {       if (b & 1) res = (1LL * a * res) % p;       a = (1LL * a * a) % p;       b >>= 1;     }     return res;   }   long long a, b, x, p, ans;   vector<pair<long long, long long> > pir;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a >> b >> p >> x;     for (long long i = 0; i < p - 1; i++) {       long long t = pw(a, i, p);       t = pw(t, p - 2, p);       t = (1LL * b * t) % p;       pir.push_back({i, t});     }     long long lcm = p * (p - 1);     for (auto i : pir) {       long long z = i.first - i.second;       long long w = z * p + i.second;       w %= lcm;       if (w < 0) w += lcm;       if (w > x) continue;       ans += (x - w) / lcm + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double esp = 1e-8;   const int msz = 100000;   const int mod = 2015;   struct Child {     int v, d;     long long p;   };   Child c[4444];   bool vis[4444];   queue<int> q;   int n;   void cut(int id) {     long long v = c[id].v + 1;     long long d = 0;     for (int i = id + 1; i <= n; ++i) {       if (vis[i]) continue;       if (v > 0) v--;       c[i].p -= (d + v);       if (c[i].p < 0) {         vis[i] = 1;         d += c[i].d;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d %d %lld , &c[i].v, &c[i].d, &c[i].p);     }     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; ++i) {       if (vis[i]) continue;       cut(i);       q.push(i);     }     int sz = q.size();     printf( %d n , sz);     while (sz--) {       printf( %d , q.front());       q.pop();       if (sz) putchar(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   char s[maxn], t[maxn];   int n, m;   vector<int> id;   vector<int> ans;   int main() {     scanf( %d%d , &n, &m);     getchar();     gets(s);     gets(t);     int Ans = 0x3f3f3f3f;     for (int i = 0; i < m - n + 1; i++) {       id.clear();       int temp = 0;       for (int j = 0; j < n; j++) {         if (s[j] != t[i + j]) {           temp++;           id.push_back(j + 1);         }       }       if (temp < Ans) {         ans.clear();         for (int j = 0; j < id.size(); j++) {           ans.push_back(id[j]);         }         Ans = temp;       }     }     printf( %d n , Ans);     for (int i = 0; i < ans.size(); i++) {       printf( %d%c , ans[i], i == ans.size() - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d, n, d1 = 1, a;     long long cnt = 0;     cin >> d >> n;     for (int i = 0; i < n; i++) {       cin >> a;       d1 = a;       if (i != n - 1 && d1 != d) {         cnt += d - d1;         d1 = 1;       } else if (d1 == d) {         d1 = 1;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   class fraction {    public:     int a, b;     fraction() { a = 0, b = 1; }     fraction(int a, int b) {       if (b < 0) {         a *= -1;         b *= -1;       }       if (a == 0) b = 1;       int g = gcd(abs(a), abs(b));       a /= g;       b /= g;       this->a = a;       this->b = b;     }     bool operator==(fraction oth) const { return a == oth.a and b == oth.b; }     bool operator!=(fraction oth) const { return !(*this == oth); }     bool operator<(fraction oth) const {       if (a < 0 and oth.a >= 0) return true;       if (oth.a < 0 and a >= 0) return false;       return (long long)a * oth.b < (long long)b * oth.a;     }     bool operator>(fraction oth) const {       return !(*this < oth) and (*this != oth);     }     bool operator<=(fraction oth) const { return !(*this > oth); }     bool operator>=(fraction oth) const { return !(*this < oth); }   };   int main() {     int n;     scanf( %d , &n);     int x1, y1, x2, y2;     scanf( %d %d %d %d , &x1, &y1, &x2, &y2);     fraction x(0, 1);     fraction y(1e9, 1);     for (int i = 1; i <= n; i++) {       int rx, ry, vx, vy;       scanf( %d %d %d %d , &rx, &ry, &vx, &vy);       if ((rx == x1 or rx == x2) and vx == 0) {         puts( -1 );         return 0;       }       if ((ry == y1 or ry == y2) and vy == 0) {         puts( -1 );         return 0;       }       fraction tox1(x1 - rx, vx);       fraction toy1(y1 - ry, vy);       fraction tox2(x2 - rx, vx);       fraction toy2(y2 - ry, vy);       if (tox2 < tox1) swap(tox1, tox2);       if (toy2 < toy1) swap(toy1, toy2);       x = max(x, tox1);       x = max(x, toy1);       y = min(y, tox2);       y = min(y, toy2);     }     if (x >= y) {       puts( -1 );     } else {       double l = (double)x.a / x.b;       printf( %.9lf n , l);     }     return 0;   }


#include <bits/stdc++.h>   const int N = 300005;   int t[N << 2], tag[N << 2], size[N << 2], st1[N], st2[N], tp1, tp2, n, x, y,       a[N];   long long ans;   void up(int x) {     int t1 = t[x << 1] + tag[x << 1], t2 = t[x << 1 | 1] + tag[x << 1 | 1];     if (t1 == t2) size[x] = size[x << 1] + size[x << 1 | 1];     if (t1 < t2) size[x] = size[x << 1];     if (t1 > t2) size[x] = size[x << 1 | 1];     t[x] = std::min(t1, t2);   }   void pushdown(int x) {     if (tag[x]) {       t[x] += tag[x];       tag[x << 1] += tag[x];       tag[x << 1 | 1] += tag[x];       tag[x] = 0;     }   }   void build(int k, int l, int r) {     if (l == r) {       t[k] = n + 1;       size[k] = 1;       return;     }     int mid = (l + r) >> 1;     build(k << 1, l, mid);     build(k << 1 | 1, mid + 1, r);     up(k);   }   void modify(int k, int L, int R, int l, int r, int val) {     if (r < l) return;     if (L == l && R == r) {       tag[k] = tag[k] + val;       return;     }     int mid = (L + R) >> 1;     pushdown(k);     if (r <= mid)       modify(k << 1, L, mid, l, r, val);     else if (l > mid)       modify(k << 1 | 1, mid + 1, R, l, r, val);     else {       modify(k << 1, L, mid, l, mid, val);       modify(k << 1 | 1, mid + 1, R, mid + 1, r, val);     }     up(k);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       a[x] = y;     }     int tp1 = tp1 = 0;     build(1, 1, n);     for (int i = 1; i <= n; i++) {       x = a[i];       while (tp1 && x > a[st1[tp1]])         modify(1, 1, n, st1[tp1 - 1] + 1, st1[tp1], x - a[st1[tp1]]), tp1--;       st1[++tp1] = i;       while (tp2 && x < a[st2[tp2]])         modify(1, 1, n, st2[tp2 - 1] + 1, st2[tp2], a[st2[tp2]] - x), tp2--;       st2[++tp2] = i;       modify(1, 1, n, i, i, -n - 1);       modify(1, 1, n, 1, i - 1, -1);       if (t[1] + tag[1] == 0) ans = ans + size[1];     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 0x3f3f3f3f, N = 1e3 + 5, mod = 1e9 + 7;   string str;   vector<int> p, v;   vector<pair<int, vector<int>>> pos;   pair<int, char> occ[26];   int c[N], x = 1, n;   char ans[N];   int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }   int LCM(int a, int b) { return a / GCD(a, b) * b; }   void primes() {     for (int i = 2; i <= str.size(); ++i) {       bool flag = 1;       for (int j = 2; j * j <= i; ++j)         if (i % j == 0) flag = 0;       if (flag) p.push_back(i);     }   }   void sames() {     map<int, vector<int>> mp;     bool f[N] = {};     for (int i = 0; i < p.size(); ++i) {       if (f[c[i]]) continue;       f[c[i]] = 1;       for (int j = 0; j < p.size(); ++j)         if (c[i] == c[j]) mp[c[i]].push_back(p[j]);     }     for (auto& ptr : mp) {       bool flag[N] = {};       pair<int, vector<int>> tmp = {0, ptr.second};       for (int ch : ptr.second)         for (int i = ch; i <= n; i += ch) flag[i] = 1;       for (int i = 0; i < N; ++i) tmp.first += flag[i];       pos.push_back(tmp);     }     sort(pos.rbegin(), pos.rend());   }   void occur() {     for (int i = 0; i < 26; ++i) occ[i].second = (char)(i +  a );     for (char ch : str) ++occ[ch -  a ].first;   }   int main() {     memset(c, -1, sizeof c);     cin >> str;     n = str.size();     primes();     for (int i = 0; i < p.size(); ++i) {       if (c[i] == -1) c[i] = x;       for (int j = 0; j < p.size(); ++j)         if (LCM(p[i], p[j]) <= str.size()) c[j] = c[i];       ++x;     }     sames();     occur();     for (auto go : pos) {       bool flag = 1;       sort(occ, occ + 26);       for (int i = 0; i < 26; ++i)         if (occ[i].first >= go.first) {           flag = 0;           char chr = occ[i].second;           occ[i].first -= go.first;           for (int ch : go.second)             for (int i = ch; i <= n; i += ch) ans[i] = chr;           break;         }       if (flag) exit(puts( NO ));     }     puts( YES );     for (int i = 1; i <= n; ++i) {       if (ans[i] >=  a  && ans[i] <=  z )         cout << ans[i];       else {         for (int j = 0; j < 26; ++j)           if (occ[j].first) {             --occ[j].first;             cout << occ[j].second;             break;           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(long long case_no) {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; ++i) cin >> a[i];     map<long long, long long> mp;     long long mx = LONG_LONG_MIN;     for (long long i = 0; i < n; ++i) {       long long x = i + a[i] % n + n;       ++mp[x % n];       if (mp[x % n] > 1) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     for (long long i = 0; i < t; ++i) {       solve(i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &first) {     first = 0;     while (1) {       char ch = getchar();       if (ch ==     || ch ==   n ) break;       first = first * 10 + ch -  0 ;     }   }   inline void write(int first) {     char wr[12];     int k = 0;     if (!first) ++k, wr[k] =  0 ;     while (first) {       ++k;       wr[k] = char(first % 10 +  0 );       first /= 10;     }     for (int i = k; i >= 1; --i) putchar(wr[i]);   }   const int N = 1e5 + 5;   int n, k, s[N], a[N];   char ch;   bool f(int len) {     for (int i = 1; i <= n; ++i) {       if (!a[i]) continue;       int s1 = s[min(n, i + len)] - s[i - 1];       int s2 = s[i] - s[max(0, i - len - 1)];       if (s1 + s2 - a[i] >= k + 1) return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= n; ++i)       cin >> ch, s[i] = s[i - 1] + (ch ==  0 ), a[i] = ch ==  0 ;     int l = 1, r = n;     while (r - l > 1) {       int mid = (l + r) >> 1;       if (f(mid))         r = mid;       else         l = mid;     }     if (f(l))       cout << l;     else       cout << r;   }


#include <bits/stdc++.h>   using namespace std;   int prime[100010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int cnt = 0;     for (int i = 2; i <= n; i++) {       if (!prime[i]) {         cnt++;         for (int j = i; j <= n; j += i) prime[j] = cnt;       }     }     for (int i = 2; i <= n; i++) cout << prime[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int _ = 1e2;   const int maxn = 2e6 + _;   const int mod = 998244353;   inline int ad(int x, int y) { return x >= mod - y ? x - mod + y : x + y; }   inline int re(int x, int y) { return x < y ? x - y + mod : x - y; }   inline int mu(int x, int y) { return (long long)x * y % mod; }   inline int qp(int x, long long y) {     int r = 1;     while (y) {       if (y & 1) r = mu(r, x);       x = mu(x, x);       y >>= 1;     }     return r;   }   inline int iv(int x) { return qp(x, mod - 2); }   inline int dv(int x, int y) { return mu(x, qp(y, mod - 2)); }   inline int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }   int a[maxn];   char ss[maxn];   set<int> S;   set<int>::iterator it, jt, kt;   int main() {     int n, mx = 0;     scanf( %d , &n);     for (int i = 0; i <= 2000001; i++) S.insert(i);     for (int i = 1; i <= n; i++) {       int len;       scanf( %s , ss + 1);       len = strlen(ss + 1);       int m, l, r;       scanf( %d , &m);       for (int j = 1; j <= m; j++) {         scanf( %d , &l), r = l + len - 1;         mx = max(mx, r);         it = S.lower_bound(l), jt = S.lower_bound(r + 1);         for (kt = it; kt != jt;) a[*kt] = ss[(*kt) - l + 1] -  a , S.erase(kt++);       }     }     for (int i = 1; i <= mx; i++) printf( %c ,  a  + a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void _redirect_streams(const string input =   ,                                 const string output =   ) {     if (not input.empty()) assert(freopen(input.c_str(),  r , stdin) != nullptr);     if (not output.empty())       assert(freopen(output.c_str(),  w , stdout) != nullptr);   }   inline void _speed_up_iostreams() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   inline void _prepare() { _speed_up_iostreams(); }   long double a, b, c, d;   inline pair<long double, long double> prod(pair<long double, long double> a,                                              pair<long double, long double> b) {     vector<long double> v = {a.first * b.first, a.first * b.second,                              a.second * b.first, a.second * b.second};     return {*min_element(v.begin(), v.end()), *max_element(v.begin(), v.end())};   }   inline bool f(long double m) {     pair<long double, long double> p1 = prod({a - m, a + m}, {d - m, d + m});     pair<long double, long double> p2 = prod({b - m, b + m}, {c - m, c + m});     if (p1.first <= p2.first and p2.first <= p1.second) return true;     if (p1.first <= p2.second and p2.second <= p1.second) return true;     if (p2.first <= p1.first and p1.first <= p2.second) return true;     return p2.first <= p1.second and p1.second <= p2.second;   }   int main() {     _prepare();     cin >> a >> b >> c >> d;     long double l = 0, r = 1e18;     const long double EPS = 1e-10;     cout.precision(20);     while (r - l > EPS) {       long double m = (l + r) / 2;       if (f(m))         r = m;       else         l = m;     }     cout.precision(30);     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   vector<long long> fac, ifac;   long long fast_pow(long long a, long long b, long long mod) {     if (!b) return 1;     long long l = fast_pow(a, b >> 1, mod);     l = l * l % mod;     if (b & 1) l = l * a % mod;     return l;   }   long long nk(int n, int k) {     if (n - k < 0) return 0;     return fac[n] * ifac[k] % mod * ifac[n - k] % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int h, w, n;     cin >> h >> w >> n;     int mx = 2 * max(h, w) + 1;     fac.resize(mx);     ifac.resize(mx);     fac[0] = ifac[0] = 1;     for (int i = 1; i < mx; ++i)       fac[i] = fac[i - 1] * i % mod, ifac[i] = fast_pow(fac[i], mod - 2, mod);     vector<pair<int, int> > bad(n);     for (auto &el : bad) cin >> el.first >> el.second;     sort(bad.begin(), bad.end());     auto f = [&](pair<int, int> &x, pair<int, int> &y) {       return x.first <= y.first && x.second <= y.second;     };     vector<long long> dp(n);     for (int i = 0; i < n; ++i) {       dp[i] = nk(bad[i].first + bad[i].second - 2, bad[i].first - 1);       for (int j = 0; j < i; ++j)         if (f(bad[j], bad[i])) {           long long x =               nk(bad[i].first - bad[j].first + bad[i].second - bad[j].second,                  bad[i].first - bad[j].first);           dp[i] = (dp[i] - (dp[j] * x % mod) + mod) % mod;         }     }     for (int i = 0; i < n; ++i)       dp[i] = dp[i] * nk(h + w - bad[i].first - bad[i].second, h - bad[i].first) %               mod;     long long ans = accumulate(dp.begin(), dp.end(), 0ll) % mod;     ans = (nk(h + w - 2, w - 1) - ans + mod) % mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long int dp[503][5030];   long long int cnt[100100];   long long int fav[100100];   int t[550];   int used[100100];   long long int h[15];   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n * m; i++) {       int x;       cin >> x;       cnt[x]++;     }     for (int i = 0; i < n; i++) {       cin >> t[i];       fav[t[i]]++;     }     for (int i = 0; i < m; i++) {       cin >> h[i];     }     long long int ans = 0;     for (int i = 0; i < n; i++) {       if (used[t[i]]) continue;       used[t[i]] = 1;       cnt[t[i]] = min(cnt[t[i]], fav[t[i]] * (long long int)m);       for (int j = 0; j <= fav[t[i]]; j++) {         for (int k = 0; k <= cnt[t[i]]; k++) {           dp[j][k] = -1e15;         }       }       dp[0][0] = 0;       for (int j = 0; j < fav[t[i]]; j++) {         for (int k = 0; k <= cnt[t[i]]; k++) {           if (dp[j][k] < 0) continue;           for (int l = 0; l <= min((int)m, (int)cnt[t[i]] - k); l++) {             dp[j + 1][k + l] =                 max(dp[j + 1][k + l],                     dp[j][k] + (l == 0 ? 0 : (long long int)h[l - 1]));           }         }       }       long long int ma = 0;       for (int j = 0; j <= cnt[t[i]]; j++) {         ma = max(ma, dp[fav[t[i]]][j]);       }       ans += ma;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   clock_t startTime;   double getCurrentTime() {     return (double)(clock() - startTime) / CLOCKS_PER_SEC;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     int totalXor = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       totalXor ^= a[i];     }     if (totalXor == 1) {       cout <<  NO n ;       return;     }     auto solve = [](int l, int r) {       assert((r - l + 1) % 2 == 1);       vector<int> res;       for (int i = l; i <= r - 2; i += 2) {         res.push_back(i);       }       for (int i = r - 4; i >= l; i -= 2) {         res.push_back(i);       }       return res;     };     if (n % 2 == 1) {       auto res = solve(0, n - 1);       cout <<  YES n ;       cout << res.size() <<   n ;       for (auto x : res) {         cout << x + 1 <<    ;       }       cout <<   n ;     } else {       bool ok = false;       int prefXor = 0;       for (int i = 0; i < n; ++i) {         prefXor ^= a[i];         if (prefXor == 0 && i % 2 == 0) {           auto res1 = solve(0, i);           auto res2 = solve(i + 1, n - 1);           cout <<  YES n ;           cout << res1.size() + res2.size() <<   n ;           for (auto x : res1) {             cout << x + 1 <<    ;           }           for (auto x : res2) {             cout << x + 1 <<    ;           }           cout <<   n ;           ok = true;           break;         }       }       if (!ok) cout <<  NO n ;     }   }   int main() {     startTime = clock();     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int tests;     cin >> tests;     for (int t = 0; t < tests; ++t) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, t, s, x, i, count;     vector<long long int> a;     vector<pair<long long int, pair<long long int, long long int> > > r;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     long long int mcount = -1;     long long int ind = 0;     for (long long int i = 0; i < n; i++) {       count = 1;       t = 1;       for (long long int j = i + 1; j < n; j++) {         if (a[j] == a[i] + t * k) count++;         t++;       }       if (count > mcount && a[i] > i * k) {         mcount = count;         ind = i;       }     }     vector<long long int> res(n);     res[ind] = a[ind];     for (long long int i = ind - 1; i >= 0; i--) {       res[i] = res[i + 1] - k;     }     for (long long int i = ind + 1; i < n; i++) {       res[i] = res[i - 1] + k;     }     for (long long int i = 0; i < n; i++) {       if (a[i] > res[i]) {         s = a[i] - res[i];         r.push_back(make_pair(-1, make_pair(i + 1, s)));       } else if (a[i] < res[i]) {         s = res[i] - a[i];         r.push_back(make_pair(1, make_pair(i + 1, s)));       }     }     cout << r.size() << endl;     for (int i = 0; i < (int)r.size(); i++) {       if (r[i].first == 1)         cout <<  +  ;       else         cout <<  -  ;       cout << r[i].second.first <<     << r[i].second.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 100001, inf = 2147483647;   const long long mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807;   const double pi = acos(-1);   inline long long mi(long long a, long long b, long long mm = mod) {     a %= mm;     long long u = 1;     while (b) {       if (b & 1) u = u * a % mm;       a = a * a % mm, b >>= 1;     }     return u;   }   inline long long gcd(long long a, long long b) {     long long c = a % b;     while (c) a = b, b = c, c = a % b;     return b;   }   inline void mem(int* a, int p = 0, int len = maxn) {     for (int i = 0; i < len; i++) a[i] = p;   }   struct p {   } e;   int t, n, a[maxn], b[maxn], x;   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       map<int, int> ma;       x = 0;       for (int i = 0; i < n; i++) cin >> b[i], ma[b[i]]++, x = max(x, ma[b[i]]);       if (x > 1)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   vector<int> g[N];   bool visited[N];   vector<int> z;   void dfs(int v, int depth) {     visited[v] = true;     bool isLeaf = true;     for (auto& i : g[v]) {       if (!visited[i]) {         dfs(i, depth + 1);         isLeaf = false;       }     }     if (isLeaf) z.push_back(depth);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     int ans = -1;     visited[1] = true;     for (auto& j : g[1]) {       z.clear();       dfs(j, 0);       sort(z.begin(), z.end());       int prev = z[0], cur = -1;       for (int i = 1; i < z.size(); i++) {         cur = max(z[i], prev + 1);         prev = cur;       }       ans = max(ans, prev + 1);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn], n, b[maxn], f[maxn];   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), b[i] = a[i];     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (j == 1)           f[j] += abs(b[j] - a[i]);         else           f[j] = min(f[j - 1], f[j] + abs(b[j] - a[i]));     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   pair<int, int> a[N];   int s[N], ss[N];   int main() {     int n, m;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &ss[i], &a[i].first);       a[i].second = i;     }     s[n - 1] = ss[n - 1];     for (int i = n - 2; i >= 0; i--) s[i] = ss[i] + s[i + 1];     sort(a, a + n);     int now = n, ans = 0;     for (int i = 0; i < n; i++) {       if (a[i].second < now) {         ans += (a[i].first * (s[a[i].second] - s[now]));         now = a[i].second;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, n, x[10000], y[10000], z[10000], ans, xx[10000], yy[10000], r,       la[10][10000], d[10000];   bool flag[10000], ff[10000];   struct lsg {     int x, y;   } a[10000], b[10000];   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   bool dfs(int l) {     if (l > r) return true;     int rr = r;     for (int i = 1; i <= k; i++)       if (!flag[i]) {         while (r > rr) ff[d[r--]] = false;         for (int j = la[i][d[l]]; j; j = la[i][j])           if (!ff[j]) d[++r] = j, ff[j] = true;         if (r > k) continue;         flag[i] = true;         if (dfs(l + 1)) return true;         flag[i] = false;       }     return false;   }   signed main() {     ios::sync_with_stdio(false);     cin >> k >> n;     for (int i = 1; i <= k; i++) cin >> b[i].x >> b[i].y;     for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     for (int l = 1; l <= k; l++) {       for (int i = 1; i <= n; i++)         x[i] = a[i].x - b[l].x, y[i] = a[i].y - b[l].y,         z[i] = gcd(abs(x[i]), abs(y[i])), xx[i] = x[i] / z[i],         yy[i] = y[i] / z[i];       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (xx[i] == xx[j] && yy[i] == yy[j]) {             if (i == j) continue;             if (z[i] > z[j]) {               if (!la[l][i] || z[la[l][i]] < z[j]) la[l][i] = j;             } else if (!la[l][j] || z[la[l][j]] < z[i])               la[l][j] = i;           }     }     for (int i = 1; i <= n; i++) {       r = 1;       d[1] = i;       memset(flag, 0, sizeof(flag));       memset(ff, 0, sizeof(ff));       if (dfs(1)) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum;     cin >> n >> sum;     if (n == 0 || (sum == 0 && n > 1))       cout <<  -1             <<                <<  -1  << endl;     else {       int ma;       string t =   ;       int x = sum;       while (x > 0 && t.length() != n) {         if ((x - 9) >= 0) {           t = t +  9 ;           x = x - 9;         } else {           char c = x +  0 ;           t = t + c;           x = 0;         }       }       if (t.length() == n && x != 0)         cout <<  -1               <<                  <<  -1  << endl;       else {         int ctr = 0;         int x = (n - t.length());         if (t.length() != n) {           for (int i = 1; i <= x; i++) {             t = t +  0 ;           }         }         int a[t.length()];         for (int i = 0; i < t.length(); i++) a[i] = ((int)t[i] - 48);         int flag = 0;         for (int i = t.length() - 1; i >= 0; i--) {           if (t[t.length() - 1] ==  0  && t.length() != 1) {             t[t.length() - 1] =  1 ;             flag = 1;           }           if (flag == 0) break;           if (t[i] !=  0  && i != t.length() - 1 && flag) {             int r = (int)t[i] - 48;             r = r - 1;             char c = r +  0 ;             t[i] = c;             break;           }         }         int y[t.length()];         for (int i = t.length() - 1; i >= 0; i--) {           y[i] = (t[i] -  0 );         }         for (int i = t.length() - 1; i >= 0; i--) cout << y[i];         cout <<    ;         for (int i = 0; i < t.length(); i++) cout << a[i];       }     }   }


#include <bits/stdc++.h>   bool match(const char* text, const char* pattern, int n, int m) {     int post = 0, posp = 0;     while (post < n && posp < m) {       if (text[post] == pattern[posp]) {         ++post;         ++posp;       } else         ++post;     }     return (posp == m);   }   char data[200002], filt[200002], srch[200002], pat[200002];   int perm[200002];   int main() {     scanf( %s , data + 1);     scanf( %s , pat);     int n = strlen(data + 1);     int m = strlen(pat);     for (int _k = (1), _n = (n), i = _k; i <= _n; ++i) {       scanf( %d , &perm[i]);     }     int lo = 0;     int hi = n;     while (lo <= hi) {       int mid = (lo + hi) / 2;       memcpy(filt + 1, data + 1, n + 1);       for (int _k = (1), _n = (mid), i = _k; i <= _n; ++i) filt[perm[i]] = -1;       int pos = 0;       memset(srch, 0, n);       for (int _k = (1), _n = (n), i = _k; i <= _n; ++i)         if (filt[i] != -1) srch[pos++] = filt[i];       if (!match(srch, pat, pos, m))         hi = mid - 1;       else         lo = mid + 1;     }     int answer = hi;     printf( %d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, n;   int a[200010];   int sum;   int ans[200010];   map<int, vector<pair<int, int> > > o;   int exgcd(int a, int b, int &x, int &y) {     if (!b) {       x = 1, y = 0;       return a;     }     int t = exgcd(b, a % b, y, x);     y -= a / b * x;     return t;   }   int main() {     scanf( %d%d , &T, &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum = (sum + a[i]) % T;       a[i] = i == 1 ? 0 : (a[i] + a[i - 1]) % T;     }     int x, y;     int len = exgcd(sum, T, x, y);     int tot = T / len;     for (int i = 1; i <= n; i++) {       int cas = a[i] % len, num = tot - a[i] / len;       num = 1ll * num * x % tot;       o[cas].push_back(make_pair(num, i));     }     for (pair<int, vector<pair<int, int> > > u : o) {       vector<pair<int, int> > p = u.second;       sort(p.begin(), p.end());       int last = p.back().first - tot;       for (pair<int, int> v : p) ans[v.second] = v.first - last, last = v.first;     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     std::cin >> n;     std::vector<std::vector<int>> a(n, std::vector<int>(n));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         a[i][j] = 4 * (i % (n / 2) * (n / 2) + j % (n / 2)) + i / (n / 2) * 2 +                   j / (n / 2);       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         std::cout << a[i][j] <<    ;       }       std::cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long qr() {     long long x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())       ;     return x * f;   }   const int N = 100010;   int n, k, a[N], res;   int s[N], top, b[N], c[N];   int lt[N], nt[N];   vector<int> ans[500];   int LIS() {     for (int i = 1; i <= top; ++i) b[i] = lt[i] = nt[i] = 0;     s[top = 1] = 1e5 + 1;     for (int i = 1; i <= n; ++i) {       int p = upper_bound(s + 1, s + 1 + top, a[i]) - s;       s[p] = a[i];       lt[i] = b[p];       b[p] = i;       nt[i] = b[p - 1];       if (p == top) s[++top] = 1e5 + 1;     }     return top - 1;   }   void Find(int x) {     ans[++res].clear();     for (int i = b[x]; i; i = nt[i]) ans[res].push_back(a[i]), a[i] = -1;   }   void Div(int n) {     for (int i = 1; i <= n; ++i) {       ans[++res].clear();       for (int j = b[i]; j; j = lt[j]) ans[res].push_back(a[j]);     }   }   int main() {     int kase = qr();     while (kase--) {       n = qr();       res = 0;       for (int i = 1; i <= n; ++i) a[i] = qr();       while (n) {         int k = LIS();         if (1LL * k * (k + 1) > 2 * n)           Find(k);         else {           Div(k);           break;         }         int ct = 0;         for (int i = 1; i <= n; ++i)           if (a[i] != -1) a[++ct] = a[i];         n = ct;       }       printf( %d n , res);       for (int i = 1; i <= res; ++i) {         int l = ans[i].size();         printf( %d  , l);         for (int j = l - 1; j >= 0; --j) printf( %d  , ans[i][j]);         puts(  );       }     }     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, x;     cin >> n >> x;     vector<int> v[n + 1];     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     bool vstd[n + 1];     int dst1[n + 1];     int dst2[n + 1];     memset(vstd, false, sizeof vstd);     memset(dst1, 0x7f, sizeof dst1);     memset(dst2, 0x7f, sizeof dst2);     queue<int> q;     q.push(1);     dst1[1] = 0;     while (q.size()) {       int node = q.front();       q.pop();       if (vstd[node]) continue;       vstd[node] = true;       for (auto u : v[node]) {         dst1[u] = min(dst1[u], dst1[node] + 1);         q.push(u);       }     }     q.push(x);     dst2[x] = 0;     memset(vstd, false, sizeof vstd);     while (q.size()) {       int node = q.front();       q.pop();       if (vstd[node]) continue;       vstd[node] = true;       for (auto u : v[node]) {         dst2[u] = min(dst2[u], dst2[node] + 1);         q.push(u);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (dst1[i] > dst2[i]) {         ans = max(ans, max(2 * dst1[i], 2 * dst2[i]));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s;   pair<int, int> A[200000];   pair<pair<int, int>, int> B[200000];   set<pair<pair<int, int>, int> > candidates;   pair<int, int> q[200000];   int sp, st;   int answer[200000];   bool check(int days) {     int j = n - 1;     sp = st = 0;     int used = 0;     candidates.clear();     for (int i = m - 1; i >= 0; --i) {       while (j >= 0 && B[j].first.first >= A[i].first) {         candidates.insert(make_pair(             make_pair(B[j].first.second, B[j].first.first), B[j].second));         --j;       }       if (st < sp) {         answer[A[i].second] = q[st].second + 1;         --q[st].first;         if (q[st].first == 0) ++st;       } else {         if (candidates.size() == 0) return false;         pair<pair<int, int>, int> best = *candidates.begin();         candidates.erase(candidates.begin());         used += best.first.first;         if (used > s) return false;         answer[A[i].second] = best.second + 1;         if (days > 1) q[sp++] = make_pair(days - 1, best.second);       }     }     return true;   }   int main() {     scanf( %d %d %d , &n, &m, &s);     for (int i = 0; i < m; ++i) {       scanf( %d , &A[i].first);       A[i].second = i;     }     for (int i = 0; i < n; ++i) {       scanf( %d , &B[i].first.first);       B[i].second = i;     }     for (int i = 0; i < n; ++i) scanf( %d , &B[i].first.second);     sort(A, A + m);     sort(B, B + n);     int left = 1, right = m;     while (left < right) {       int middle = (left + right) / 2;       if (check(middle))         right = middle;       else         left = middle + 1;     }     if (check(left)) {       printf( YES n%d , answer[0]);       for (int i = 1; i < m; ++i) printf(  %d , answer[i]);       printf(  n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <typename T>   inline bool chkmax(T& aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T& aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   int rint();   char rch();   long long rlong();   const int MOD = 1000000007;   int extgcd(int a, int b, int& x, int& y) {     for (int u = y = 1, v = x = 0; a;) {       int q = b / a;       swap(x -= q * (long long)u, u);       swap(y -= q * (long long)v, v);       swap(b -= q * (long long)a, a);     }     return b;   }   int mod_inv(int a, int m) {     int x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   int mod_pow(int a, int n, int mod) {     int ret = 1;     int p = a % mod;     while (n) {       if (n & 1) ret = (ret * (long long)p) % mod;       p = (p * (long long)p) % mod;       n >>= 1;     }     return ret;   }   template <int _MAXSEG>   class MinSegTree {    public:     static const int MAXSEG = _MAXSEG;     int segn = _MAXSEG;     long long t[2 * MAXSEG];     long long identity = LLONG_MAX;     long long combine(const long long& lefts, const long long& rights) {       return min(lefts, rights);     }     void init(int n) { segn = n; }     void build() {       int n = segn;       for (int i = n - 1; i > 0; --i) t[i] = combine(t[i << 1], t[i << 1 | 1]);     }     void sset(int p, const long long& value) {       int n = segn;       for (t[p += n] = value; p >>= 1;) t[p] = combine(t[p << 1], t[p << 1 | 1]);     }     long long query(int l, int r) {       r++;       int n = segn;       long long resl = identity, resr = identity;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) resl = combine(resl, t[l++]);         if (r & 1) resr = combine(t[--r], resr);       }       return combine(resl, resr);     }   };   const int mn = 100000 + 4;   int inp[mn];   long long vdiff[mn];   int n;   MinSegTree<mn> at, abt;   pair<long long, long long> getab(int x) {     long long l = max(0ll, -vdiff[x - 1]);     long long r = max(0ll, vdiff[x]);     return make_pair(l, r);   }   void change(int x) {     pair<long long, long long> got = getab(x);     long long a = min(got.first, got.second), b = max(got.first, got.second);     at.sset(x, a);     abt.sset(x, a + b);   }   void place(int x) {     pair<long long, long long> got = getab(x);     long long a = min(got.first, got.second), b = max(got.first, got.second);     at.t[x + at.segn] = a;     abt.t[x + abt.segn] = a + b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     n = rint();     int segn = n + 1;     at.init(segn);     abt.init(segn);     for (int x = 1; x <= n; x++) inp[x] = rint();     long long allsum = 0;     for (int x = 1; x <= n - 1; x++) {       vdiff[x] = inp[x + 1] - inp[x];       allsum += abs(vdiff[x]);     }     for (int x = 1; x <= n; x++) {       place(x);     }     at.build();     abt.build();     int qlim = rint();     for (int qi = 0; qi < qlim; qi++) {       int t = rint(), l = rint(), r = rint(), val = rint();       if (t == 1) {         long long mina = at.query(l, r);         long long minsum = abt.query(l, r);         long long ansleft = max(-2 * mina, -2LL * val);         long long ansright = 2 * (val - minsum);         long long ans = max(ansleft, ansright);         long long final = allsum + ans;         printf( %lld n , final);       } else {         {           allsum -= abs(vdiff[l - 1]);           vdiff[l - 1] += val;           allsum += abs(vdiff[l - 1]);           change(l);           if (l - 1 >= 1) change(l - 1);         }         if (r != n) {           allsum -= abs(vdiff[r]);           vdiff[r] -= val;           allsum += abs(vdiff[r]);           change(r);           if (r + 1 <= n) change(r + 1);         }       }     }   }   static char stdinBuffer[1024];   static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char* stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   int rint() {     readAhead(16);     int x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   char rch() {     readAhead(16);     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     char ans = *stdinPos;     ++stdinPos;     return ans;   }   long long rlong() {     readAhead(32);     long long x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }


#include <bits/stdc++.h>   using namespace std;   namespace debug {   void __(short x) { cout << x; }   void __(int x) { cout << x; }   void __(long long x) { cout << x; }   void __(unsigned long long x) { cout << x; }   void __(double x) { cout << x; }   void __(long double x) { cout << x; }   void __(char x) { cout << x; }   void __(const char* x) { cout << x; }   void __(const string& x) { cout << x; }   void __(bool x) { cout << (x ?  true  :  false ); }   template <class P1, class P2>   void __(const pair<P1, P2>& x) {     __( ( ), __(x.first), __( ,  ), __(x.second), __( ) );   }   template <class T>   void __(const vector<T>& x) {     __( { );     bool _ffs = 0;     for (const auto& v : x) __(_ffs ?  ,   :   ), __(v), _ffs = 1;     __( } );   }   void screm() { __(  n ); }   template <class T1, class... T2>   void screm(const T1& t1, const T2&... t2) {     __(t1);     if (sizeof...(t2))       __(  |  ), screm(t2...);     else       __(  n );   }   void pr() { __(  n ); }   template <class T1, class... T2>   void pr(const T1& t1, const T2&... t2) {     __(t1);     if (sizeof...(t2))       __(   ), pr(t2...);     else       __(  n );   }   }  // namespace debug   using namespace debug;   long long h, m, k, ans, h1, h2, m1, m2, ms, mh, mmm;   int main() {     scanf( %lld%lld%lld%lld%lld%lld%lld , &h, &m, &k, &h1, &m1, &h2, &m2);     long long sw = m - 1;     while (sw) {       if (sw % 10 != 0) ms++;       sw /= 10;     }     sw = h - 1;     while (sw) {       if (sw % 10 != 0) mh++;       sw /= 10;     }     int ch = max(0LL, k - ms - 1);     long long mn = 1, hr = 1;     for (int i = 0; i < k - 1; i++) mn *= 10;     for (int i = 0; i < ch; i++) hr *= 10;     if (h1 == h2 && m1 <= m2) {       ans += (m2 / mn);       if (m1 > 1) ans -= (m1 / mn);       printf( %lld n , ans);       return 0;     }     if (m1) ans += ((m - 1) / mn) - (m1 / mn);     long long rr = h1;     ans -= (h1 / hr);     int flg = 0;     if (m1) {       h1++;       m1 = 0;       if (h1 == h) {         h1 = 0;         if (ms + mh >= k) ans++;       } else if ((h1 / hr) != (rr / hr))         ans++, flg = 1;     }     if (m2) ans += (m2 / mn), m2 = 0;     long long kek = (m - 1) / mn;     if (h1 > h2) {       ans += ((h - 1) / hr) + (h2 / hr) - flg;       long long delta = (h - h1) + (h2);       ans += delta * kek;       if (ms + mh >= k) ans++;     } else {       ans += (rr / hr) - (h1 / hr) + (h2 / hr) + kek * (h2 - h1);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     long long sum = 0;     for (int& x : a) {       scanf( %d , &x);       sum += x;     }     if (sum != 0) {       puts( YES );       puts( 1 );       printf( %d %d n , 1, n);       exit(0);     }     sum = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       if (sum != 0) {         puts( YES );         puts( 2 );         printf( %d %d n , 1, i + 1);         printf( %d %d n , i + 2, n);         exit(0);       }     }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s, ans = 0, mid = 0;     scanf( %lld %lld , &n, &s);     long long int a[n];     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     mid = n / 2;     if (s >= a[mid]) {       for (int i = n / 2; i < n; i++) {         if (a[i] >= s)           break;         else           ans += abs(s - a[i]);       }     } else {       for (int i = n / 2; i >= 0; i--) {         if (a[i] <= s)           break;         else           ans += abs(a[i] - s);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tot, ans, Head[100000 + 5], q[100000 + 5], T[100000 + 5],       Deg[100000 + 5];   bool Flag[100000 + 5];   struct Edge {     int next, node;   } h[100000 + 5 << 1];   inline void addedge(int u, int v) {     h[++tot].next = Head[u], Head[u] = tot;     h[tot].node = v;   }   inline void dfs(int z) {     if (Flag[z]) return;     Flag[z] = 1;     q[++q[0]] = z;     for (int i = Head[z]; i; i = h[i].next) {       int d = h[i].node;       dfs(d);     }   }   inline bool T_Sort() {     int l = 1, r = 0;     for (int i = 1; i <= q[0]; i++)       if (!Deg[q[i]]) T[++r] = q[i];     while (l <= r) {       int z = T[l++];       for (int i = Head[z]; i; i = h[i].next) {         if (i + 1 & 1) continue;         int d = h[i].node;         Deg[d]--;         if (!Deg[d]) T[++r] = d;       }     }     return r == q[0];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, u, v; i <= m; i++) {       scanf( %d%d , &u, &v);       addedge(u, v), addedge(v, u);       Deg[v]++;     }     for (int i = 1; i <= n; i++) {       if (Flag[i]) continue;       q[0] = 0;       dfs(i);       ans += T_Sort() ? q[0] - 1 : q[0];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int mas[105] = {0};     int n;     scanf( %d  , &n);     int res = -1;     int resl = -1;     for (int i = 0; i < n; i++) scanf( %d  , &mas[i]);     for (int i = 0; i < n; i++) {       int len = 0;       int mest = 0;       for (int j = i; j < n; j++) {         len++;         mest ^= mas[j];         if (mest > res) {           res = mest;           resl = len;         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)2e5 + 10;   const int maxM = (int)4e5 + 10;   int n, m, k, type[maxN], a[maxN], pa[maxN];   long long d[maxN];   vector<int> c[maxN], w[maxN];   set<pair<long long, int> > s;   int en, ea[maxM], eb[maxM], ep[maxM];   long long ew[maxM];   inline bool wless(int i, int j) { return ew[i] < ew[j]; }   int get(int v) { return v == pa[v] ? v : (pa[v] = get(pa[v])); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(m); i++) {       int a, b, x;       scanf( %d%d%d , &a, &b, &x), a--, b--;       c[a].push_back(b), w[a].push_back(x);       c[b].push_back(a), w[b].push_back(x);     }     scanf( %d , &k);     for (int i = 0; i < (int)(n); i++) d[i] = (long long)1e18;     for (int i = 0; i < (int)(k); i++) {       scanf( %d , &a[i]), a[i]--;       d[a[i]] = 0, type[a[i]] = i;     }     for (int i = 0; i < (int)(n); i++) s.insert(make_pair(d[i], i));     while ((int)(s).size()) {       int v = s.begin()->second;       s.erase(s.begin());       for (int i = 0; i < (int)((int)(c[v]).size()); i++) {         int u = c[v][i];         long long tmp = d[v] + w[v][i];         if (d[u] > tmp) {           s.erase(make_pair(d[u], u));           d[u] = tmp, type[u] = type[v];           s.insert(make_pair(d[u], u));         }       }     }     for (int v = 0; v < (int)(n); v++)       for (int i = 0; i < (int)((int)(c[v]).size()); i++) {         int u = c[v][i];         if (type[v] != type[u]) {           ea[en] = type[v];           eb[en] = type[u];           ep[en] = en;           ew[en] = d[v] + d[u] + w[v][i];           en++;         }       }     long long ans = d[0];     sort(ep, ep + en, wless);     for (int i = 0; i < (int)(k); i++) pa[i] = i;     for (int _i = 0; _i < (int)(en); _i++) {       int i = ep[_i];       if (get(ea[i]) != get(eb[i])) pa[get(ea[i])] = get(eb[i]), ans += ew[i];     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[300005];   int main() {     int n;     cin >> n;     cout << 1 <<    ;     int right = n;     for (int i = 1; i <= n; i++) {       int temp;       scanf( %d , &temp);       arr[temp] = 1;       while (arr[right]) right--;       printf( %d  , i - (n - right) + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool good(int64_t a, int64_t b) {     if (a == 0) return false;     if (!good(b % a, a)) return true;     int64_t c = b / a;     return (c % (a + 1)) % 2 == 0;   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cout << fixed << setprecision(10);     int t;     cin >> t;     while (t--) {       int64_t a, b;       cin >> a >> b;       if (a > b) swap(a, b);       cout << (good(a, b) ?  First  :  Second ) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int D = 1e6 + 3;   const int MAXN = 110;   int F[MAXN];   struct Mt {     int v[MAXN][MAXN];     int N, M;     Mt() {       for (int i = 0; i < MAXN; i++) {         for (int j = 0; j < MAXN; j++) {           v[i][j] = 0;         }       }     }     void I() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < M; j++) {           v[i][j] = 0;         }         v[i][i] = 1;       }     }     void pr() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < M; j++) {           cout << v[i][j];         }         cout << endl;       }     }   };   Mt operator*(Mt A, Mt B) {     Mt Res;     Res.N = A.N;     Res.M = B.M;     for (int k = 0; k < A.M; k++) {       for (int i = 0; i < Res.N; i++) {         for (int j = 0; j < Res.M; j++) {           Res.v[i][j] += (1ll * A.v[i][k] * B.v[k][j]) % D;           Res.v[i][j] %= D;         }       }     }     return Res;   }   Mt pw(Mt A, int p) {     Mt Res;     Res.N = A.N;     Res.M = A.M;     Res.I();     while (p) {       if (p & 1) {         Res = Res * A;       }       A = A * A;       p >>= 1;     }     return Res;   }   int main() {     int C, W, H;     cin >> C >> W >> H;     F[0] = 1;     for (int i = 1; i < W + 1; i++) {       F[i] = H * F[i - 1];       F[i] %= D;     }     Mt A;     A.N = W + 1;     A.M = W + 1;     for (int i = 0; i < W; i++) {       A.v[i][i + 1] = 1;     }     for (int i = 0; i < W + 1; i++) {       A.v[W][i] = F[W - i];     }     Mt ans = pw(A, C);     cout << (ans.v[W][W] + ans.v[W][W - 1]) % D << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[1000];   int i, n, d, t, q;   int main() {     cin >> c;     n = strlen(c);     i = 0;     while (i < n && c[i] !=  @ ) {       if (!isalnum(c[i]) && c[i] !=  _ ) {         cout <<  NO ;         return 0;       }       i++;     }     i++;     t = i;     if (i == n || i > 16 || i < 1) {       cout <<  NO ;       return 0;     }     while (i < n && c[i] !=  / ) {       d = 0;       q = i;       while (i < n && c[i] !=  .  && c[i] !=  / ) {         if (!isalnum(c[i]) && c[i] !=  _ ) {           cout <<  NO ;           return 0;         }         i++;         d = 1;       }       if (i - q > 16 || i - q < 1) {         cout <<  NO ;         return 0;       }       if (c[i] !=  / ) i++;     }     if (i - t > 32 || i - t < 1 || (i == n && c[i - 1] ==  . )) {       cout <<  NO ;       return 0;     }     if (c[i] ==  / ) {       if (i == n) {         cout <<  NO ;         return 0;       }       t = i + 1;       i++;       while (i < n) {         if (!isalnum(c[i]) && c[i] !=  _ ) {           cout <<  NO ;           return 0;         }         i++;       }       if (i - t > 16 || i - t < 1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int dir[8][2] = {{0, 1}, {1, 0},  {0, -1},  {-1, 0},                          {1, 1}, {1, -1}, {-1, -1}, {-1, 1}};   const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9;   const int MAXN = 1e6 + 5, MAXM = 1e6 + 5;   const int MAXQ = 100010, INF = 1e9;   inline void read(int &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) {         p = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   int n, m;   int len;   int anser = INT_MAX;   int num[55];   void dfs(int x, int where, int sum) {     for (int i = x + 1; i <= len; i++) {       if (num[i] >= num[x] + 2) {         if (where == m - 1) {           anser = min(anser, sum + num[i]);           return;         }         dfs(i, where + 1, sum + num[i]);         break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     string ch;     cin >> ch;     len = ch.size();     for (int i = 0; i < len; i++) {       num[i + 1] = (ch[i] -  a ) + 1;     }     sort(num + 1, num + 1 + len);     num[len + 1] = INT_MAX;     if (m == 1) {       cout << num[1] << endl;       return 0;     }     for (int i = 1; i <= len - m + 1; i++) {       dfs(i, 1, num[i]);     }     if (anser == INT_MAX) {       cout << -1 << endl;     } else {       cout << anser << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 100005;   int n, q, A[MAXN], B[MAXN];   double ans, f[MAXN][105];   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i)       scanf( %d , A + i), f[i][B[i] = A[i]] = 1, ans += f[i][0];     scanf( %d , &q);     register int u, v, k;     while (q--) {       scanf( %d%d%d , &u, &v, &k);       ans -= f[u][0];       for (register int i = 1; i <= k; ++i)         for (register int j = 0; j <= A[u]; ++j)           f[u][j] = f[u][j] * (B[u] - i + 1 - j) / (B[u] - i + 1) +                     f[u][j + 1] * (j + 1) / (B[u] - i + 1);       ans += f[u][0];       B[u] -= k;       B[v] += k;       printf( %.12lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int l = 2, h = 1e5;       int ans = 2;       while (l <= h) {         int m = l + (h - l) / 2;         if ((long long)m * (m - 1) / 2 <= n) {           ans = m;           l = m + 1;         } else {           h = m - 1;         }       }       int rem = n - (long long)ans * (ans - 1) / 2;       cout <<  133 ;       for (int i = 1; i <= rem; i++) cout << 7;       for (int i = 1; i <= ans - 2; i++) cout << 3;       cout << 7 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       t -= 86400 - a;       if (t <= 0) {         cout << i << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const double PI = 3.1415926535897932;   const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};   const int maxn = 2e5 + 5;   const int MOD = 998244353;   int n, m;   int d[maxn];   long long sum[maxn];   long long qpow(long long a, long long p) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * a % MOD;       a = a * a % MOD;       p >>= 1;     }     return ans;   }   long long inv(long long a) { return qpow(a, MOD - 2); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &d[i]);     sort(d + 1, d + 1 + n);     for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + d[i]) % MOD;     while (m--) {       long long A, B;       scanf( %lld%lld , &A, &B);       int st = lower_bound(d + 1, d + 1 + n, B) - d;       if (n - st + 1 < A) {         printf( 0 n );         continue;       }       long long k = n - st + 1;       long long kk = (k - A) * inv(k) % MOD;       long long ans = (sum[n] - sum[st - 1]) % MOD * kk % MOD;       kk = (k - A + 1) * inv(k + 1) % MOD;       ans = (ans + sum[st - 1] * kk % MOD) % MOD;       ans = (ans + MOD) % MOD;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1000;   int dp[MX][MX], a[MX], x[MX], y[MX], n, d;   int dis(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }   int main() {     cin >> n >> d;     for (int i = 2; i < n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (i != j) dp[i][j] = dis(i, j) * d - a[i];       }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (dp[i][j] > dp[i][k] + dp[k][j]) dp[i][j] = dp[i][k] + dp[k][j];     cout << dp[1][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int n, m;   vector<int> c[100005];   int nc;   bool b[100005];   int v[100005];   vector<pair<int, int> > e;   int s0[100005], s1[100005];   int w[100005];   void add(int x, int y) {     e.push_back(make_pair(x, y));     if (((int)e.size()) == m) {       for (auto p : e) printf( %d %d n , p.first + 1, p.second + 1);       exit(0);     }   }   void add2(int i, int j) {     add(i, j);     if (s0[j] == s0[i])       s0[s0[i]] = -1, s0[i] = s0[j] = s1[i] = s1[j] = -1;     else {       s1[s0[i]] = s1[s0[j]];       s0[s0[j]] = s0[s0[i]];     }     n--;   }   void dfs(int x) {     if (v[x] >= 0) return;     v[x] = nc;     c[nc].push_back(x);     for (int y : g[x]) dfs(y);   }   priority_queue<pair<int, int> > q;   int main() {     scanf( %d%d , &n, &m);     for (int _ = 0, ThxDem = m; _ < ThxDem; ++_) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     memset(v, -1, sizeof(v));     for (int i = 0, ThxDem = n; i < ThxDem; ++i)       if (!((int)g[i].size())) b[nc] = true, v[i] = nc, c[nc++] = {i};     for (int i = 0, ThxDem = n; i < ThxDem; ++i)       if (((int)g[i].size()) == 1 && v[i] < 0) dfs(i), b[nc++] = false;     for (int i = 0, ThxDem = n; i < ThxDem; ++i)       if (v[i] < 0) dfs(i), b[nc++] = true;     if (nc == 1) {       if (n >= 5)         for (int i = 0, ThxDem = n; i < ThxDem; ++i)           add(c[0][i], c[0][(i + 2) % n]);       else if (n == 4 && !b[0]) {         add(c[0][1], c[0][3]);         add(c[0][3], c[0][0]);         add(c[0][0], c[0][2]);         assert(0);       }     } else {       for (int i = 0, ThxDem = n; i < ThxDem; ++i) s0[i] = s1[i] = i;       pair<int, int> t = make_pair(-1, -1);       for (int i = 0, ThxDem = nc; i < ThxDem; ++i)         t = max(t, make_pair(((int)c[i].size()), i));       int k = t.second;       if (((int)c[k].size()) > n - ((int)c[k].size())) {         if (((int)c[k].size()) == 2) {           add(c[k][0], c[k ^ 1][0]);           assert(0);         }         if (((int)c[k].size()) == 3) {           if (!b[k]) add2(c[k][0], c[k][2]);         } else if (((int)c[k].size()) == 4 && b[k]) {           add2(c[k][0], c[k][2]);           if (((int)c[k].size()) - 1 > n - (((int)c[k].size()) - 1))             add2(c[k][1], c[k][3]);         } else if (((int)c[k].size()) == 4) {           add2(c[k][1], c[k][3]);           if (((int)c[k].size()) - 1 > n - (((int)c[k].size()) - 1)) {             add2(c[k][3], c[k][0]);             if (((int)c[k].size()) - 2 > n - (((int)c[k].size()) - 2))               add2(c[k][0], c[k][2]);           }         } else {           for (int i = 0, ThxDem = ((int)c[k].size()); i < ThxDem; ++i) {             add2(c[k][i], c[k][(i + 2) % ((int)c[k].size())]);             if (((int)c[k].size()) - i - 1 <= n - (((int)c[k].size()) - i - 1))               break;           }         }         vector<int> t;         for (int x : c[k])           if (s0[x] == x) t.push_back(x);         c[k] = t;       }       int l = -1;       for (int i = 0, ThxDem = nc; i < ThxDem; ++i)         q.push(make_pair(((int)c[i].size()), i == k ? i : -i));       while (!q.empty()) {         auto p = q.top();         q.pop();         int i = abs(p.second);         if (l >= 0 && v[l] == i) {           if (q.empty()) break;           auto qwe = p;           p = q.top();           q.pop();           q.push(qwe);           i = abs(p.second);         }         if (l >= 0) add(s1[l], s0[c[i][w[i]]]);         l = c[i][w[i]++];         if (p.first > 1) q.push(make_pair(p.first - 1, i == k ? i : -i));       }       if (v[l] != k) {         add(s1[l], s0[c[k][0]]);       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   int main() {     cout << fixed << setprecision(12);     int n, k;     cin >> n >> k;     vector<vector<int>> y(n, vector<int>(k + 1));     for (auto &yi : y)       for (auto &yij : yi) cin >> yij;     vector<double> sum(n);     for (int j = 0; j < k; j++) {       vector<tuple<int, int, int>> v;       for (int i = 0; i < n; i++) {         v.emplace_back(y[i][j + 1] - y[i][j], y[i][j], i);       }       sort(begin(v), end(v));       auto calc = [&](int k) {         vector<double> x(n + 1), y(n + 1);         x[0] = 0.0, y[0] = 0.0;         x[1] = 1.0, y[1] = 0.0;         int sz = 2;         for (auto &t : v)           if (get<2>(t) < k) {             auto a = get<0>(t), b = get<1>(t);             auto f = [&](double x) { return a * x + b; };             int p = sz - 1;             while (p >= 0 && f(x[p]) + eps >= y[p]) p--;             if (p == -1) {               y[0] = f(x[0] = 0.0);               y[1] = f(x[1] = 1.0);               sz = 2;             } else if (p != sz - 1) {               double a2 = (y[p + 1] - y[p]) / (x[p + 1] - x[p]);               double b2 = y[p] - x[p] * a2;               double x2 = (b2 - b) / (a - a2);               y[p + 1] = f(x[p + 1] = x2);               y[p + 2] = f(x[p + 2] = 1.0);               sz = p + 3;             }           }         double sum = 0.0;         for (int i = 0; i + 1 < sz; i++) {           sum += (x[i + 1] - x[i]) * (y[i + 1] + y[i]) / 2;         }         return sum;       };       vector<double> acc(n + 1);       for (int i = 0; i < n; i++) acc[i + 1] = calc(i + 1);       for (int i = 0; i < n; i++) sum[i] += acc[i + 1] - acc[i];     }     for (int i = 0; i < n; i++) cout << sum[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int a[maxn];   int f[maxn];   int miss[maxn];   int sum[maxn];   int main() {     int n, s;     cin >> n >> s;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int ans1 = 0;     if (a[s] != 0) {       ans1++;       a[s] = 0;     }     int zero = 0;     for (int i = 1; i <= n; i++) {       f[a[i]]++;       if (a[i] == 0) {         zero++;       }     }     zero--;     int i = 0;     while (zero--) {       while (f[i] != 0) {         i++;       }       f[0]--;       f[i]++;       ans1++;     }     sum[0] = 1;     for (int i = 1; i < n; i++) {       if (f[i] == 0) {         miss[i] = miss[i - 1] + 1;       } else {         miss[i] = miss[i - 1];       }       sum[i] = sum[i - 1] + f[i];     }     int ans2 = 1e9;     for (int i = n - 1; i >= 1; i--) {       int tmp = max((n - sum[i]), miss[i]);       ans2 = min(ans2, tmp);     }     if (n == 1) {       ans2 = 0;     }     cout << ans1 + ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = acos(-1);   long double DEL = 1e-10;   int M =  1e9 + 7;   const int N = 3e5 + 10;      #define ftt cin>>tc;for(int cas=1;cas<=tc;++cas)   #define all(a) a.begin(),a.end()   #define vpii vector<pair<int,int> >   #define vvi vector<vector<int> >   #define va(x) vector<array<int,(x)> >   #define pii pair<int,int>   #define vi vector<int>   #define sq(a) ((a)*(a))   #define double long double   #define dbg cout<<  nhi n ;   #define int long long   #define nl cout<<  n    #define sp <<   <<   #define S second   #define F first      template<class T> using minpq = priority_queue<T,vector<T>,greater<T> >;   struct DSU   {           vi par,size;           DSU (int n)           {                   par.resize(n+1);                   size.resize(n+1);                   for(int i=0;i<=n;i++)                   {                           par[i] = i;                           size[i] = 1;                   }           }                      int find(int x)           {                   return par[x] = (x == par[x]? par[x]:find(par[x]));                              }                      void join(int x,int y)           {                   int parx = find(x),pary = find(y);                   if(parx == pary)                   {                           return;                   }                   if(size[parx] > size[pary])                   {                           size[parx] += size[pary];                           par[pary] = parx;                   }                   else                   {                           size[pary] += size[parx];                           par[parx] = pary;                   }           }   };   int fpow(int x, int n)   {           int res = 1;           x %= M;           while(n)           {                   if(n&1)res = res * x % M;                   x = x * x % M;                   n>>=1;           }           return res;   }   int gcd(int a,int b)   {           if(b == 0)return a;           return gcd(b,a % b);   }   int lcm(int a,int b)   {           return a*(b/gcd(a,b));   }   int popcount(int x)   {           return bitset<65>(x).count();   }   vector<int> fac(N),inv(N);      void create_fac(int n)   {           fac[0] = inv[0] = 1;           for(int i=1;i<=n;i++)           {                   fac[i] = fac[i-1]*i % M;                   inv[i] = fpow(fac[i],M-2);           }   }   int ncr(int n,int r)   {           if(r > n)return 0;           return fac[n] * (inv[r] * inv[n-r] % M) % M;           return fac[n] * (fpow(fac[r],M-2) * fpow(fac[n-r],M-2) % M ) % M;   }      void sieve (int n)   {           vector<int> pf(N);           pf[0] = pf[1] = 1;           for (int i = 2; i <= n; i++) {                   if (!pf[i]) {                           pf[i] = i;                           for (int j = i * i; j <= n; j += i){                                   pf[j] = i;                           }                   }           }              }      //**************************************** CHECK CONSTRAINTS ***************************************   int cnt, sum, mid, mx, mn, ans, a[N], b[N];   int n, m, d, i, j, k, l, p, q, r, t, w, x, y, z, tc;   string s;      vvi dp(402,vi(402));         int32_t main()   {           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);           #ifndef ONLINE_JUDGE           freopen( /Users/jenish/XCode/cp/input.txt , r ,stdin);           #endif           cin >> n >> M;                      // dp[i][j] => done till i and had j gaps.                                 for(int i = 1;i <= n;i++){                   dp[i][0] = fpow(2,i-1);           }           create_fac(n+2);           for(int i = 2;i <= n;i++){                   for(int gaps = 1;gaps <= i - 2;gaps++){                           //lgp = last gap position                           for(int lgp = 2;lgp < i;lgp++){                                   //cout << i sp gaps sp lgp;nl;                                   //cout << dp[lgp - 1][gaps - 1] sp fpow(2,i - lgp - 1) sp ncr(i - gaps,i - lgp);nl;                                   dp[i][gaps] += (dp[lgp - 1][gaps - 1] * fpow(2,i - lgp - 1) % M) * ncr(i - gaps,i - lgp) % M;                                   dp[i][gaps] %= M;                           }                   }           }                      for(int gaps = 0;gaps < n - 1;gaps++){                   //cout<<gaps sp dp[n][gaps];nl;                   ans += dp[n][gaps];                   ans %= M;           }           cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const string nl =   n ;   vector<int> readVector(int n) {     vector<int> ret(n);     for (int i = 0; i < n; i++) cin >> ret[i];     return ret;   }   void setIO(string name) {     freopen((name +  .in ).c_str(),  r , stdin);     freopen((name +  .out ).c_str(),  w , stdout);   }   int recur(vector<int> vec, int sig) {     vector<int> s1, s0;     for (int i = 0; i < vec.size(); i++) {       if ((vec[i] & (1 << sig)) == 0) {         s0.push_back(vec[i]);       } else         s1.push_back(vec[i]);     }     if (s1.size() < 2 && s0.size() < 2) return 0;     if (s1.size() < 2) return recur(s0, sig - 1);     if (s0.size() < 2) return recur(s1, sig - 1);     return min(s0.size() - 1 + recur(s1, sig - 1),                s1.size() - 1 + recur(s0, sig - 1));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n;     cin >> n;     vector<int> a = readVector(n);     cout << recur(a, 30) << nl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   struct mat {     long long** val;     mat() {       val = new long long*[6];       for (int i = 0; i < 6; i++) {         val[i] = new long long[6];         for (int j = 0; j < 6; j++) val[i][j] = 0;         val[i][i] = 1;       }     }     mat(long long v[6][6]) {       val = new long long*[6];       for (int i = 0; i < 6; i++) {         val[i] = new long long[6];         for (int j = 0; j < 6; j++) val[i][j] = v[i][j];       }     }     mat operator*(const mat& b) {       mat ans;       for (int i = 0; i < 6; i++) {         for (int j = 0; j < 6; j++) {           ans.val[i][j] = 0;           for (int k = 0; k < 6; k++) {             ans.val[i][j] += (val[i][k] * b.val[k][j]) % n;             ans.val[i][j] %= n;           }         }       }       return ans;     }     mat& operator=(const mat& b) {       for (int i = 0; i < 6; i++) {         for (int j = 0; j < 6; j++) val[i][j] = b.val[i][j];       }       return *this;     }   };   long long rec[6][6] = {{2, 1, 1, 0, 1, 2}, {1, 2, 0, 1, 1, 2},                          {1, 1, 1, 0, 1, 2}, {1, 1, 0, 1, 1, 2},                          {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}};   mat matrec;   mat matexp(long long e) {     if (e == 0ll) return mat();     mat tmp = matexp(e / 2ll);     tmp = (tmp * tmp);     if (e & 1) return tmp * matrec;     return tmp;   }   int main() {     ios::sync_with_stdio(0);     matrec = mat(rec);     long long sx, sy, dx, dy, t;     cin >> n >> sx >> sy >> dx >> dy >> t;     if (t == 0ll) {       cout << sx <<     << sy <<   n ;       return 0;     }     sx--;     sy--;     dx %= n;     dy %= n;     while (dx < 0) dx += n;     while (dy < 0) dy += n;     long long vec[] = {sx, sy, dx, dy, 0, 1};     mat ans = matexp(t);     long long ansx = 0, ansy = 0;     for (int i = 0; i < 6; i++) {       ansx += (vec[i] * ans.val[0][i]) % n;       ansy += (vec[i] * ans.val[1][i]) % n;       ansx %= n;       ansy %= n;     }     cout << ansx + 1 <<     << ansy + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   const int mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n, x, y;       cin >> n >> x >> y;       cout << max(min(n, x + y - n + 1), 1) <<     << min(x + y - 1, n) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   namespace SCCKosaraju {   vector<vector<int>> adj, radj;   vector<int> todo, comp, curr;   vector<bool> vis;   void dfs1(int x) {     vis[x] = 1;     for (int y : adj[x])       if (!vis[y]) dfs1(y);     todo.push_back(x);   }   void dfs2(int x, int i) {     comp[x] = i;     curr.push_back(x);     for (int y : radj[x])       if (comp[y] == -1) dfs2(y, i);   }   vector<int> scc(vector<vector<int>>& _adj) {     adj = _adj;     int time = 0, n = adj.size();     comp.resize(n, -1), radj.resize(n), vis.resize(n);     for (int x = 0; x < n; x++)       for (int y : adj[x]) radj[y].push_back(x);     for (int x = 0; x < n; x++)       if (!vis[x]) dfs1(x);     reverse(todo.begin(), todo.end());     for (int x : todo)       if (comp[x] == -1) dfs2(x, time++);     return comp;   }   };  // namespace SCCKosaraju   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(cin.failbit);     const ll MOD = 1000000007;     int n;     cin >> n;     vector<int> cost(n);     for (int& x : cost) cin >> x;     vector<vector<int>> adj(n);     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       adj[u - 1].push_back(v - 1);     }     vector<int> comp = SCCKosaraju::scc(adj);     vector<ll> add(comp.size(), (int)1e9 + 10);     vector<ll> cnt(comp.size(), 1);     int ncomps = 0;     for (int i = 0; i < n; i++) {       ncomps = max(ncomps, comp[i] + 1);       if (cost[i] < add[comp[i]]) {         add[comp[i]] = cost[i];         cnt[comp[i]] = 1;       } else if (cost[i] == add[comp[i]])         cnt[comp[i]]++;     }     ll ans = 0, ways = 1;     for (int i = 0; i < ncomps; i++) ans += add[i];     for (int i = 0; i < ncomps; i++) ways = (ways * cnt[i]) % MOD;     cout << ans <<     << ways <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 10000005, p = 1e9 + 7;   int n, k, cnt, phi[Maxn], prim[Maxn], sum[Maxn], ct[Maxn];   long long ans;   bool vis[Maxn];   void init(void) {     phi[1] = 1;     for (int i = 2; i <= n; i++) {       if (!vis[i]) prim[++cnt] = i, phi[i] = i - 1;       for (int j = 1; j <= cnt && i * prim[j] <= n; j++) {         vis[i * prim[j]] = true;         if (i % prim[j] == 0) {           phi[i * prim[j]] = phi[i] * prim[j];           break;         }         phi[i * prim[j]] = phi[i] * (prim[j] - 1);       }     }   }   long long get_inv(int x) {     if (x <= 1) return 1;     return (p - p / x) * get_inv(p % x) % p;   }   int main() {     scanf( %d%d , &n, &k);     init();     for (int i = 2; i <= n; i++) sum[i] = (sum[i - 1] + phi[i]) % p;     for (int i = 1; i <= n; i++) ct[i] = n - i - 1;     for (int i = 1; i < n; i++) {       int l = (n - 1) / i;       (ct[i] += sum[l + 1]) %= p;       (ct[(l + 1) * i - n] += p - phi[l + 1]) %= p;     }     long long now = 1;     for (int i = 1; i < n; i++) {       now = now * k % p;       (ans += ct[i] * now) %= p;     }     printf( %lld , ans * get_inv(now * k % p) % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[100000 + 10];   int num[30];   int main() {     scanf( %d , &n);     scanf( %s , s);     sort(s, s + n);     printf( %s n , s);   }


#include <bits/stdc++.h>   using namespace std;   void fileioe() {     freopen( input.txt ,  r , stdin);     freopen( xyz.txt ,  w , stdout);     freopen( error.txt ,  w , stderr);   }   const long long mod = 1000000007;   const long long INF = 1e18;   const long long MAX = 100001;   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     string str1, str2;     int flag1 = 0, flag0 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         flag1 = 1;         for (int j = 0; j < i; j++) {           if (s[j] ==  0 ) str1 +=  0 ;         }         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         flag0 = 1;         str2 = s.substr(i);         break;       }     }     if (flag1 == 0 || flag0 == 0) {       cout << s << endl;       return;     }     string res = str1 + str2;     if (res.length() > n) {       cout << res.substr(1) << endl;       return;     }     cout << res << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lkd(long long a, long long b) {     while (b > 0) {       long long c = b;       b = a % b;       a = c;     }     return a;   }   int main() {     long long a, s, b = 1;     cin >> a >> s;     for (long long i = 0; i < s; i++) b = b * 10;     cout << (a * b) / lkd(a, b);   }


#include <bits/stdc++.h>   using namespace std;   const int M = 110000;   long long a[M], b[M], c[M], be[M];   long long n, d, x;   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     long long i;     for (i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   int main() {     long long i, j, k;     while (~scanf( %I64d%I64d%I64d , &n, &d, &x)) {       initAB();       vector<int> vt;       memset(be, 0, sizeof(be));       int cnt = 0;       for (i = 0; i < n; i++)         if (b[i]) cnt++;       if (cnt <= sqrt(n)) {         for (i = 0; i < n; i++)           if (b[i]) vt.push_back(i);         for (i = 0; i < n; i++) {           long long mx = 0;           for (j = 0; j < vt.size(); j++) {             k = vt[j];             if (k > i) break;             c[i] = max(c[i], a[i - k]);           }         }       } else {         vector<pair<int, int> > vc;         for (i = 0; i < n; i++) vc.push_back(make_pair(a[i], i));         sort(vc.begin(), vc.end());         for (i = 0; i < n; i++) {           for (j = n - 1; j >= 0; j--) {             if (vc[j].second <= i && b[i - vc[j].second]) {               c[i] = vc[j].first;               break;             }           }         }       }       for (i = 0; i < n; i++) cout << c[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int ans[N << 1];   int main() {     int n;     cin >> n;     int b1 = n + 1;     int b2 = 2 * n - 1;     int a1 = 1;     int a2 = n;     int cnt = 1;     for (int i = 1; i <= n - 1; ++i) {       if (cnt & 1)         ans[a1++] = i, ans[a2--] = i;       else         ans[b1++] = i, ans[b2--] = i;       cnt++;     }     for (int i = 1; i <= 2 * n; ++i)       if (ans[i] == 0)         cout << n <<    ;       else         cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   typedef struct {     long long s, l, r, m;   } value;   long long maxll(long long a, long long b) { return a > b ? a : b; }   void sum(value *v, value *l, value *r) {     v->s = l->s + r->s;     v->l = maxll(l->l, l->s + r->l);     v->r = maxll(r->r, r->s + l->r);     v->m = maxll(l->r + r->l, maxll(l->m, r->m));   }   value t[4 * 150000];   long long a[150000];   void build(int i, int l, int r) {     if (l == r) {       t[i].s = a[l];       t[i].l = t[i].r = t[i].m = maxll(a[l], 0);     } else {       int m = (l + r) / 2;       build(2 * i + 1, l, m);       build(2 * i + 2, m + 1, r);       sum(&t[i], &t[2 * i + 1], &t[2 * i + 2]);     }   }   value get(int ll, int rr, int i, int l, int r) {     if (rr < l || r < ll) {       value v = {0, 0, 0, 0};       return v;     }     if (ll <= l && r <= rr) return t[i];     int m = (l + r) / 2;     value lv, rv, av;     lv = get(ll, rr, 2 * i + 1, l, m);     rv = get(ll, rr, 2 * i + 2, m + 1, r);     sum(&av, &lv, &rv);     return av;   }   int main() {     int n, m, c;     scanf( %d%d%d , &n, &m, &c);     int i, x[150000];     for (i = 0; i < n; i++) scanf( %d , &x[i]);     int p[150000];     for (i = 0; i < n - 1; i++) scanf( %d , &p[i]);     for (i = 0; i < n - 1; i++) a[i] = 1LL * (x[i + 1] - x[i]) * 50 - c * p[i];     build(0, 0, n - 2);     long long s = 0;     for (i = 0; i < m; i++) {       int l, r;       scanf( %d%d , &l, &r);       l--;       r--;       r--;       s += get(l, r, 0, 0, n - 2).m;     }     printf( %.2lf n , 1. * s / 100);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     x = f ? -x : x;   }   int n, x, len, res, minn = 0x7fffffff;   char s[400001];   string ans, c[6] = { RGB ,  RBG ,  BRG ,  BGR ,  GRB ,  GBR };   int main() {     read(n);     scanf( %s , s), len = strlen(s);     for (int i = 0; i < 6; i++) {       res = 0, x = 0;       for (int j = 0; j < len; j++) {         if (s[j] != c[i][x++]) res++;         if (x == 3) x = 0;       }       if (res < minn) {         minn = res;         ans = c[i];       }     }     x = 0;     cout << minn <<   n ;     for (int j = 0; j < len; j++) {       putchar(ans[x++]);       if (x == 3) x = 0;     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   using namespace std;   const long double PI = 3.14159265358979323846;   const long long mod = 1e+9 + 7;   const int INFi = INT_MAX;   const long long INF = (long long)1e+9 + 7;   const int N = 1200300, LOGN = 30, V = N * LOGN;   long long dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   int t = 1;   long long a, b, c, ans;   string second;   void MAIN() {     cin >> a >> b >> c;     ans = 0;     ans = max(ans, a / 3 + b / 3 + c / 3);     if (a > 0 && b > 0 && c > 0)       ans = max(ans, 1 + (a - 1) / 3 + (b - 1) / 3 + (c - 1) / 3);     if (a > 1 && b > 1 && c > 1)       ans = max(ans, 2 + (a - 2) / 3 + (b - 2) / 3 + (c - 2) / 3);     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(10);     ;     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());     ;     while (t--) {       MAIN();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3005;   int prv[maxn], nxt[maxn], cnt[maxn];   int le[maxn];   int r, c, n, k;   vector<int> pos[maxn];   signed main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> r >> c >> n >> k;     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> x >> y;       pos[y].emplace_back(x);     }     long long res = 0;     for (int i = 1; i <= c; ++i) {       set<int> second;       second.insert(0);       second.insert(r + 1);       for (int j = 0; j <= r; ++j) cnt[j] = 0, le[j] = 0;       nxt[0] = r + 1;       prv[r + 1] = 0;       long long sum = 0;       for (int j = i; j <= c; ++j) {         for (int val : pos[j]) {           if (!cnt[val]) {             int l = *prev(second.lower_bound(val));             int r = *(second.upper_bound(val));             nxt[l] = val;             nxt[val] = r;             prv[r] = val;             prv[val] = l;             sum -= 1ll * le[l] * (nxt[val] - val);             second.insert(val);           }           cnt[val]++;           int cur = val, now = 0;           while (cur != 0) {             now += cnt[cur];             if (now >= k) break;             cur = prv[cur];           }           int total = cnt[val];           if (cur > le[val]) {             sum += 1ll * (cur - le[val]) * (nxt[val] - val);             le[val] = cur;           }           while (true) {             val = nxt[val];             total += cnt[val];             now += cnt[val];             if (val > r || total > k) break;             while (cur < val && now - cnt[cur] >= k) {               now -= cnt[cur];               cur = nxt[cur];             }             if (cur > le[val]) {               assert(now >= k);               sum += 1ll * (cur - le[val]) * (nxt[val] - val);               le[val] = cur;             }           }         }         res += sum;       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   string s[555];   int dp[555], v[555], ones[555];   vector<pair<int, int> > vc[555];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int cnt = 0;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  1 ) ones[cnt++] = j + 1;       }       memset(v, 0, sizeof(v));       v[cnt] = m;       for (int j = 0; j < cnt; j++) {         for (int k = j; k < cnt; k++) {           int len = cnt - (k - j + 1);           int value = m - (ones[k] - ones[j] + 1);           v[len] = max(v[len], value);         }       }       for (int j = 0; j <= k; j++) {         if (v[j]) vc[i].push_back(make_pair(j, v[j]));       }     }     for (int i = 1; i <= n; i++) {       for (int j = k; j >= 0; j--) {         for (int k = 0; k < vc[i].size(); k++) {           if (j >= vc[i][k].first)             dp[j] = max(dp[j], dp[j - vc[i][k].first] + vc[i][k].second);         }       }     }     cout << n * m - dp[k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = int(2e5) + 256;   const int INF = int(1e9);   const int mod = (int)(1e9) + 7;   const double pi = 3.1415926535897932384626433832795;   long long n, m, ans, A[MaxN], k, a, b, q;   long long t[MaxN * 8], t1[MaxN * 8];   void upd(int v, int l, int r, int pos, int val) {     if (l == r) {       t[v] += val;       t1[v] += val;       t[v] = min(a, t[v]);       t1[v] = min(t1[v], b);       return;     }     int m = (l + r) / 2;     if (pos <= m) {       upd(v + v, l, m, pos, val);     } else       upd(v + v + 1, m + 1, r, pos, val);     t[v] = t[v + v] + t[v + v + 1];     t1[v] = t1[v + v] + t1[v + v + 1];   }   long long get(int v, int l, int r, int tl, int tr) {     if (l > tr || r < tl) return 0;     if (tl <= l & r <= tr) return t[v];     int m = (l + r) / 2;     return get(v + v, l, m, tl, tr) + get(v + v + 1, m + 1, r, tl, tr);   }   long long get1(int v, int l, int r, int tl, int tr) {     if (l > tr || r < tl) return 0;     if (tl <= l & r <= tr) return t1[v];     int m = (l + r) / 2;     return get1(v + v, l, m, tl, tr) + get1(v + v + 1, m + 1, r, tl, tr);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k >> a >> b >> q;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int x, y;         cin >> x >> y;         upd(1, 1, n, x, y);       } else {         int p;         cin >> p;         int S = 0;         if (p > 1) {           S = get1(1, 1, n, 1, p - 1);         }         int S1 = 0;         if (p + k <= n) {           S1 = get(1, 1, n, p + k, n);         }         cout << S + S1 <<   n ;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, depth = 0;   string loc[500];   string comm;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> comm;       if (comm ==  cd ) {         cin >> comm;         int pos = 0;         if (comm[0] ==  / ) {           depth = 0;           pos = 1;         }         string dir =   ;         for (; pos < comm.length(); ++pos) {           if (comm[pos] !=  / ) dir += comm[pos];           if (comm[pos] ==  /  || pos == comm.length() - 1) {             if (dir ==  .. )               depth--;             else               loc[depth++] = dir;             dir =   ;           }         }       } else {         for (int i = 0; i < depth; ++i) cout <<  /  << loc[i];         cout <<  /  << endl;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #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 main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, p;     cin >> n >> p;     if (p == 0) {       cout << __builtin_popcount(n);       return 0;     }     if (p > 0) {       long long int a = n;       long long int cnt = 0;       while (a > 0) {         long long int temp = __builtin_popcount(a);         long long int c = 0, k = 0;         while (a) {           if (a & 1) {             k += (c + 1);           }           a = a / 2;           c++;         }         if (temp <= cnt) {           if (k >= cnt) {             cout << cnt;             return 0;           }         }         cnt++;         a = n - cnt * p;       }     } else {       long long int a = n;       long long int cnt = 0;       while (cnt < 1000) {         long long int temp = __builtin_popcount(a);         long long int c = 0, k = 0;         while (a) {           if (a & 1) {             k += (c + 1);           }           a = a / 2;           c++;         }         if (temp <= cnt) {           if (k >= cnt) {             cout << cnt;             return 0;           }         }         cnt++;         a = n - cnt * p;       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1000000000000000000;   const int N = 100005;   int main() {     int n, x;     scanf( %d , &n);     multiset<int> a, b;     for (int i = 0; i < int(n); i++) {       scanf( %d , &x);       a.insert(x);     }     for (int i = 0; i < int(n - 1); i++) {       scanf( %d , &x);       b.insert(x);       a.erase(a.find(x));     }     printf( %d n , *a.begin());     a.clear();     swap(a, b);     for (int i = 0; i < int(n - 2); i++) {       scanf( %d , &x);       b.insert(x);       a.erase(a.find(x));     }     printf( %d n , *a.begin());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double Eps = 1e-8;   char what[27] =  A??????HI???M?O????TUVWXY? ;   char str[100005];   void input() { scanf( %s , str); }   bool good() {     int N = strlen(str);     for (int i = 0; i < N; i++) {       if (str[i] != what[str[N - i - 1] -  A ]) return false;     }     return true;   }   int main() {     input();     printf(good() ?  YES n  :  NO n );   }