#include <bits/stdc++.h>   using namespace std;   vector<int> x_coord, y_coord;   vector<vector<int>> adj;   vector<bool> used;   int n;   void dfs(int v) {     used[v] = true;     for (auto u : adj[v]) {       if (!used[u]) {         used[u] = true;         dfs(u);       }     }   }   int main() {     scanf( %d , &n);     x_coord.resize(n);     y_coord.resize(n);     adj.resize(n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x_coord[i], &y_coord[i]);       for (int j = 0; j < i; j++) {         if (x_coord[j] == x_coord[i] || y_coord[j] == y_coord[i]) {           adj[i].push_back(j);           adj[j].push_back(i);         }       }     }     used.resize(n, false);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (!used[i]) {         cnt++;         dfs(i);       }     }     printf( %d n , cnt - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 1e9;   int t, n, a[N], b[N];   int gao(int x) {     int res = b[1] - x;     for (int i = 2; i <= n; i++) {       res = b[i] - max(a[i] - res, 0);       if (res < 0) return -1;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) cin >> b[i];       int l = 0, r = b[1], ans = 0;       while (l <= r) {         int mid = l + r >> 1;         int ret = gao(mid);         if (ret == -1) {           r = mid - 1;         } else           l = mid + 1;         if (ret != -1 && ret + mid >= a[1]) {           ans = 1;         }       }       if (ans)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, mini = 0, maxi = 0;   int x[200005];   bool o[200005];   int main() {     cin >> n;     for (int i = 0; i < (n); i++) {       int a;       cin >> a;       x[a]++;     }     for (int i = 0; i < (n + 1); i++) {       while (i < n + 1 && x[i] == 0) i++;       if (i == n + 1) break;       mini++;       i += 2;     }     for (int i = 0; i < (n + 1); i++) {       while (i < n + 1 && x[i] == 0) i++;       if (i == n + 1) break;       for (int j = 0; j < (min(3, x[i])); j++) {         if (!o[i - 1]) {           o[i - 1] = true;           maxi++;         } else if (!o[i]) {           o[i] = true;           maxi++;         } else if (!o[i + 1]) {           o[i + 1] = true;           maxi++;         }       }     }     cout << mini <<     << maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     char ar[n];     for (int i = 0; i < n; ++i) {       cin >> ar[i];     }     int co = 0;     vector<int> po;     for (int i = 0; i < n - 1; ++i) {       if (ar[i] ==  W ) {         ar[i] =  B ;         co++;         po.push_back(i + 1);         if (ar[i + 1] ==  B ) {           ar[i + 1] =  W ;         } else {           ar[i + 1] =  B ;         }       }     }     if (ar[n - 1] ==  B ) {       cout << co << endl;       for (int i = 0; i < po.size(); ++i) {         cout << po[i] <<    ;       }       cout << endl;     } else {       if (n % 2 == 0) {         cout << -1 << endl;       } else {         cout << co + (n - 1) / 2 << endl;         for (int i = 0; i < po.size(); ++i) {           cout << po[i] <<    ;         }         for (int i = 0; i < (n - 1) / 2; ++i) {           cout << 2 * i + 1 <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long int mod = 1e9 + 7;   long long int pmod(long long int x, long long int n) {     long long int r = 1;     while (n) {       if (n & 1LL) r = (r * x) % mod;       x = (x * x) % mod;       n = n / 2;     }     return r;   }   void solve() {     long long int a, b;     cin >> a >> b;     if (a < b) {       cout << -1;       return;     }     long long int d1 = (a + b) / 2;     d1 /= b;     d1 = d1 * 2;     double ans = (double)(a + b) / d1;     cout << setprecision(10) << ans;   }   int main() {     fast();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long k;     cin >> n >> k;     if (!k) {       cout <<  0 n ;       return 0;     }     vector<int> h(n);     for (int i = 0; i < n; i++) {       cin >> h[i];     }     h.push_back(h[0]);     long long** dp;     dp = new long long*[n + 79];     for (int i = 0; i < n + 2; i++) {       dp[i] = new long long[2 * n + 79];       for (int j = 0; j < 2 * n + 79; j++) {         dp[i][j] = 0;       }     }     dp[0][n + 1] = 1;     for (int i = 1; i <= n; i++) {       for (int score = 1; score <= 2 * n + 2; score++) {         if (h[i] != h[i - 1]) {           dp[i][score] += dp[i - 1][score - 1];           dp[i][score] += dp[i - 1][score + 1];           dp[i][score] += (dp[i - 1][score] * (k - 2ll)) % mod;         } else {           dp[i][score] = dp[i - 1][score] * k;         }         dp[i][score] %= mod;       }     }     long long ans = 0;     for (int score = n + 2; score <= 2 * n + 1; score++) {       ans += dp[n][score];     }     cout << (ans % mod) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x, i, p;     char y;     string ch =   ;     cin >> n >> k;     for (i = 0; i < k; i++) {       p = 97 + i;       y = (char)p;       ch += y;     }     if (n == k)       cout << ch;     else {       x = n - k;       i = 0;       while (x--) {         ch += ch[i];         i++;       }       cout << ch;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long inf = 1e15 + 7;   bool check(long long n) { return __builtin_popcount(n + 1) == 1; }   vector<long long> res;   bool solve(long long n, long long k, long long par) {     if (n == 11 && k == 3) {       res[10] = par;       res[9] = 10;       res[8] = 9;       res[7] = 9;       return solve(7, 2, 10);     }     if (k <= 1) {       if ((!check(n) && k == 0) || (check(n) && k == 1)) return false;       res[0] = par;       for (long long i = 1; i < n; i++) res[i] = (i - 1) / 2;       return true;     }     if (k == 2 && check(n - 2)) {       res[n - 1] = par;       res[n - 2] = n - 1;       res[n - 3] = n - 2;       res[n - 4] = n - 2;       return solve(n - 4, k - 1, n - 1);     }     res[n - 1] = par;     res[n - 2] = n - 1;     return solve(n - 2, k - 1, n - 1);   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     if (n == 1 && k == 0) {       cout <<  YES  << endl << 0;       return 0;     }     if (n % 2 == 0 || (n - 3) / 2 < k || (k == 0 && !check(n)) ||         (k == 1 && check(n)) || (k == 2 && n == 9)) {       cout <<  NO ;       return 0;     }     res.resize(n);     bool temp = solve(n, k, -1);     if (!temp) cout <<  Bad  << endl;     cout <<  YES  << endl;     for (long long i : res) cout << i + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[1001], x;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       a[x]++;     }     sort(a + 1, a + n + 1);     printf( %d n , a[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int binary_exp(long long int a, long long int n) {     long long int i = 1;     while (n > 0) {       if (n % 2 == 1) i = (i * a) % 1000000007;       a = (a * a) % 1000000007;       n /= 2;     }     return i;   }   long long int IsPrime(long long int n) {     if (n == 0 || n == 1) return n;     if (n % 2 == 0) return (long long int)2;     if (n % 3 == 0)       return (long long int)3;     else {       for (long long int i = 5; i * i <= n; i += 6) {         if (n % i == 0) return i;         if (n % (i + 2) == 0) return (i + 2);       }       return n;     }   }   void solve() {     int n, i, j, k, a, b, mex = 1, ans = 0;     cin >> n;     int ind[n + 1];     bool vis[n + 1];     memset(vis, false, sizeof(vis));     for (i = 1; i <= n; i++) {       cin >> k;       ind[k] = i;     }     for (i = 1; i <= n; i++) {       cin >> k;       vis[ind[k]] = true;       while (mex <= n && vis[mex]) mex++;       if (ind[k] > mex) ans++;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 3e5 + 5, inf = 1e9 + 7;   long long int bigmod(long long int b, long long int p, long long int m) {     long long int rt = 1;     while (p) {       if (p & 1) rt = (rt * b) % m;       b = (b * b) % m;       p >>= 1;     }     return rt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, t = 0;     while (tc--) {       long long int x, n;       cin >> x >> n;       vector<long long int> prim;       for (int i = 2; i * i <= x; i++) {         if (x % i == 0) {           prim.push_back(i);           while (x % i == 0) x /= i;         }       }       if (x > 1) prim.push_back(x);       long long int rs = 1;       for (auto x : prim) {         long long int fact = x, pw = 0;         while (fact <= n) {           pw += n / fact;           if (n / x >= fact)             fact *= x;           else             break;         }         rs *= bigmod(x, pw, inf);         rs %= inf;       }       cout << rs <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const int INF = (int)1e9 + 1;   const long double EPS = 1e-9;   void precalc() {}   struct Line {     int a, b, c;     int id;     int read(int _id) {       id = _id;       if (scanf( %d%d%d , &a, &b, &c) < 3) {         return 0;       }       return 1;     }   };   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   struct Ratio {     long long a, b;     Ratio() {}     Ratio(long long _a, long long _b) : a(_a), b(_b) {       assert(b != 0ll);       normalize();     }     void normalize() {       long long d = gcd(a, b);       a /= d, b /= d;       if (b < 0) {         a = -a, b = -b;       }     }     inline bool operator<(const Ratio &r) const {       if (a != r.a) {         return a < r.a;       }       return b < r.b;     }     inline bool operator==(const Ratio &r) const { return a == r.a && b == r.b; }   };   struct Point {     Ratio x, y;     Point() {}     Point(Ratio _x, Ratio _y) : x(_x), y(_y) {}     inline bool operator<(const Point &p) const {       if (x == p.x) {         return y < p.y;       }       return x < p.x;     }     inline bool operator==(const Point &p) const { return x == p.x && y == p.y; }   };   bool inter(const Line &l1, const Line &l2, Point &res) {     long long D = (long long)l1.a * l2.b - (long long)l1.b * l2.a;     if (D == 0ll) {       return 0;     }     long long Dx = (long long)l1.b * l2.c - (long long)l1.c * l2.b;     long long Dy = (long long)l1.c * l2.a - (long long)l1.a * l2.c;     res = Point(Ratio(Dx, D), Ratio(Dy, D));     return 1;   }   int n, k;   const int maxn = (int)1e5 + 10;   Line lines[maxn];   bool read() {     if (scanf( %d%d , &n, &k) < 2) {       return 0;     }     for (int i = 0; i < n; ++i) {       lines[i].read(i);     }     return 1;   }   const int maxk = 5;   int ans[maxk][2];   int res;   Line tmp[maxn];   int used[maxn];   bool gen(int pos, int k) {     if (pos == n) {       return 1;     }     if (used[pos]) {       return gen(pos + 1, k);     }     if (k == 0) {       return 0;     }     {       ans[res][0] = lines[pos].id + 1, ans[res][1] = -1;       ++res;       if (gen(pos + 1, k - 1)) {         return 1;       }       --res;     }     int oks[n];     Point ps[maxk * maxk + 5];     for (int j = pos + 1; j < n; ++j) {       oks[j] = 0;       if (used[j]) {         continue;       }       Point p;       if (!inter(lines[pos], lines[j], p)) {         continue;       }       oks[j] = 1;       ps[j] = p;     }     int tmp[n];     for (int j = pos + 1; j < n; ++j) {       if (!oks[j]) {         continue;       }       ans[res][0] = lines[pos].id + 1, ans[res][1] = lines[j].id + 1;       ++res;       for (int k = pos + 1; k < n; ++k) {         tmp[k] = used[k];         if (!oks[k]) {           continue;         }         if (ps[j] == ps[k]) {           used[k] += 1;           oks[k] = 0;         }       }       if (gen(pos + 1, k - 1)) {         return 1;       }       --res;       for (int k = pos + 1; k < n; ++k) {         used[k] = tmp[k];       }     }     return 0;   }   bool solveSmall() {     random_shuffle(lines, lines + n, rnd);     for (int i = 0; i < n; ++i) {       used[i] = 0;     }     return gen(0, k);   }   void solve() {     res = 0;     while (n > k * k && k > 0) {       const int K = 250;       pair<Point, pair<int, int> > ps[K];       int cnt = 0;       bool ok = 0;       for (int iter = 0; iter < K; ++iter) {         int x = rnd(n), y = rnd(n);         Point p;         if (x == y || !inter(lines[x], lines[y], p)) {           continue;         }         ps[cnt++] = make_pair(p, make_pair(x, y));       }       sort(ps, ps + cnt);       Point p;       int x, y;       bool found = 0;       for (int i = 0; i < cnt;) {         int i0 = i;         while (i < cnt && ps[i].first == ps[i0].first) {           ++i;         }         if (i - i0 > k) {           found = 1;           p = ps[i0].first;           x = ps[i0].second.first, y = ps[i0].second.second;           break;         }       }       if (!found) {         printf( NO n );         return;       }       {         int cnt = 0, cntp = 0;         for (int i = 0; i < n; ++i) {           Point q;           if (!inter(lines[i], lines[i == x ? y : x], q)) {             continue;           }           if (q == p) {             ++cntp;           } else {             tmp[cnt++] = lines[i];           }         }         assert(cntp > k);         ans[res][0] = lines[x].id + 1, ans[res][1] = lines[y].id + 1;         ++res;         for (int i = 0; i < cnt; ++i) {           lines[i] = tmp[i];         }         n = cnt;         --k;       }     }     if (solveSmall()) {       printf( YES n );       printf( %d n , res);       for (int i = 0; i < res; ++i) {         printf( %d %d n , ans[i][0], ans[i][1]);       }     } else {       printf( NO n );     }   }   int main() {     srand(rdtsc());     precalc();     while (1) {       if (!read()) {         break;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a[6];     for (int i = 0; i < 6; i++) scanf( %d , &a[i]);     int tot = a[0] + a[1] + a[2];     int ans = tot * tot - a[0] * a[0] - a[2] * a[2] - a[4] * a[4];     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long hash1 = 201326611;   const unsigned long long hash2 = 50331653;   const int N = 200000 + 10;   const int M = 20;   vector<int> g[N];   int n, vis[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     int u, v;     for (int i = 1; i < n; i++) {       cin >> u >> v;       vis[u]++;       vis[v]++;     }     int flag = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] == 2) flag = 1;     }     if (flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, root;   int val[100000], maxl[100000], maxr[100000];   vector<int> fo[100000];   void dfs(int vr) {     if (fo[vr].size() == 0) {       maxl[vr] = maxr[vr] = val[vr];       return;     }     dfs(fo[vr][0]);     dfs(fo[vr][1]);     maxl[vr] = maxl[fo[vr][0]];     maxr[vr] = maxr[fo[vr][1]];   }   map<int, int> rev1;   map<int, int> revq, vals;   double sum[100000], pl[100000];   void dfs1(int vr, int par = -1) {     if (par == -1) {       pl[vr] = 0;       sum[vr] = 0;     } else {       pl[vr] = pl[par] + 1;       if (fo[par][0] == vr)         sum[vr] = sum[par] + maxl[fo[par][1]];       else         sum[vr] = sum[par] + maxr[fo[par][0]];     }     if (!fo[vr].empty()) {       dfs1(fo[vr][0], vr);       dfs1(fo[vr][1], vr);     }   }   vector<int> ID, IDX;   void dfs2(int vr, int f, int t) {     if (f > t) return;     if (fo[vr].size() == 0) {       for (int i = f; i <= t; ++i) IDX[i] = vr;       return;     }     int DEL = (int)(lower_bound(ID.begin() + f, ID.begin() + t + 1, val[vr]) -                     ID.begin());     dfs2(fo[vr][0], f, DEL - 1);     dfs2(fo[vr][1], DEL, t);   }   int main() {     int i, j, k, l;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       int _p, _v;       scanf( %d%d , &_p, &_v);       --_p;       if (_p < 0)         root = i;       else         fo[_p].push_back(i);       val[i] = _v;     }     for (i = 0; i < n; ++i) {       if (!fo[i].empty())         if (val[fo[i][0]] > val[i]) swap(fo[i][0], fo[i][1]);       rev1[val[i]] = i;     }     dfs(root);     dfs1(root);     int Q;     scanf( %d , &Q);     ID.resize(Q);     IDX.resize(Q);     for (i = 0; i < Q; ++i) {       scanf( %d , &ID[i]);       revq[i] = ID[i];     }     sort(ID.begin(), ID.end());     for (i = 0; i < ID.size(); ++i) vals[ID[i]] = i;     dfs2(root, 0, Q - 1);     for (i = 0; i < Q; ++i)       printf( %.12lf n , sum[IDX[vals[revq[i]]]] / pl[IDX[vals[revq[i]]]]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline void umax(long long &a, long long b) { a = max(a, b); }   inline void umin(long long &a, long long b) { a = min(a, b); }   inline pair<long long, long long> rv(pair<long long, long long> a) {     return make_pair(a.second, a.first);   }   const long long N = 2e5 + 10;   const long long INF = 1e16 + 10;   const pair<long long, long long> NINF = make_pair(INF, INF);   const long double EPS = 1e-6;   const long long II = 1e9;   const long long MOD = 1e9 + 9;   long long dp[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     string second;     cin >> second;     queue<pair<long long, long long> > buf;     for (long long i = 0; i < (min(k, n)); i++)       if (second[i] ==  1 ) buf.push(make_pair(i + 1, i + k));     for (long long i = 0; i < (n + 1); i++) dp[i] = INF;     dp[0] = 1;     for (long long i = 0; i < n; i++) {       if (i + k < n && second[i + k] ==  1 )         buf.push(make_pair(i + k + 1, i + k * 2));       if (buf.size()) {         auto beg = buf.front();         long long pr = beg.second - k * 2 - 1;         long long ll = (pr >= 0 ? dp[pr] : 0LL);         umin(dp[i], ll + beg.first);         if (beg.second == i) buf.pop();       }       if (i) umin(dp[i], dp[i - 1] + i + 1);     }     cout << dp[n - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, t;     cin >> n >> t;     string s;     cin >> s;     char temp;     while (t--) {       for (int i = 0; i < n - 1; i++) {         if (s[i] != s[i + 1] && s[i] ==  B ) {           temp = s[i + 1];           s[i + 1] = s[i];           s[i] = temp;           i++;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long maxn = 3e6;   const long long mod = 1e9 + 7;   const long double PI = acos((long double)-1);   long long pw(long long a, long long b, long long md = mod) {     long long res = 1;     while (b) {       if (b & 1) {         res = (a * res) % md;       }       a = (a * a) % md;       b >>= 1;     }     return (res);   }   int n;   long long l[maxn], r[maxn];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> r[i];     long long p = 1, q = 0, sum = 0, sm = 0;     for (int i = 0; i < n; i++) {       if (i) {         long long a = max(0LL, min(r[i], r[i - 1]) - max(l[i], l[i - 1]) + 1);         long long b = (r[i] - l[i] + 1) * (r[i - 1] - l[i - 1] + 1) % mod;         p = ((b - a + mod) % mod * pw(b, mod - 2)) % mod;       }       sum = (sum + p) % mod;       sm = (sm + pw(p, 2) + (2LL * (p - 1) * (q - 1)) % mod + mod) % mod;       q = p;     }     long long ans = (sum * (sum + 1) - sm + mod * 100LL) % mod;     for (int i = 2; i < n; i++) {       long long a = max(0LL, min({r[i], r[i - 1], r[i - 2]}) -                                  max({l[i], l[i - 1], l[i - 2]}) + 1);       long long b = max(0LL, r[i - 2] - l[i - 2] + 1);       b = (b * max(0LL, r[i - 1] - l[i - 1] + 1)) % mod;       b = (b * max(0LL, r[i] - l[i] + 1)) % mod;       p = (a * pw(b, mod - 2)) % mod;       ans = (ans + 2 * p) % mod;     }     cout << ans <<   n ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> dx = {-1, 0, 0, 1};   vector<int> dy = {0, -1, 1, 0};   const int Mod = (int)((int)1e9 + 7);   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     for (int i = 1; i < n; i++) {       while (a[i] + a[0] <= k) {         a[i] += a[0];         ans++;       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     cin >> q;     for (int i = 1; i <= q; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int game[2];     int m, c;     m = c = 0;     for (int i = 0; i < n; i++) {       cin >> game[0] >> game[1];       if (game[0] > game[1]) {         m++;       } else if (game[0] < game[1]) {         c++;       }     }     if (m > c) {       cout <<  Mishka  << endl;     } else if (m < c) {       cout <<  Chris  << endl;     } else {       cout <<  Friendship is magic!^^  << endl;     }   };


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int nxt[N];   map<int, vector<int>> w;   int extendA[N], extendB[N], l[N], r[N];   char s[N], t[N];   int n, m, k;   void pre_EKMP(char x[], int m, int nxt[]) {     nxt[0] = m;     int j = 0;     while (j + 1 < m && x[j] == x[j + 1]) j++;     nxt[1] = j;     int k = 1;     for (int i = 2; i < m; i++) {       int p = nxt[k] + k - 1;       int L = nxt[i - k];       if (i + L < p + 1)         nxt[i] = L;       else {         j = max(0, p - i + 1);         while (i + j < m && x[i + j] == x[j]) j++;         nxt[i] = j;         k = i;       }     }   }   void EKMP(char x[], int m, char y[], int n, int nxt[], int extend[]) {     pre_EKMP(x, m, nxt);     int j = 0;     while (j < n && j < m && x[j] == y[j]) j++;     extend[0] = j;     int k = 0;     for (int i = 1; i < n; i++) {       int p = extend[k] + k - 1;       int L = nxt[i - k];       if (i + L < p + 1)         extend[i] = L;       else {         j = max(0, p - i + 1);         while (i + j < n && j < m && y[i + j] == x[j]) j++;         extend[i] = j;         k = i;       }     }   }   struct node {     int son[26];     int len, fail;     int id;   } tri[N];   int lst, L;   void add(int last, int c) {     static int v, u, up, up1;     v = ++L;     u = last;     tri[v].len = tri[u].len + 1;     for (; u && !tri[u].son[c]; u = tri[u].fail) tri[u].son[c] = v;     if (!u)       tri[v].fail = 1;     else {       up = tri[u].son[c];       if (tri[up].len == tri[u].len + 1)         tri[v].fail = up;       else {         up1 = ++L;         tri[up1] = tri[up];         tri[up1].len = tri[u].len + 1;         tri[up].fail = tri[v].fail = up1;         for (; u && tri[u].son[c] == up; u = tri[u].fail) tri[u].son[c] = up1;       }     }     lst = v;   }   int rt[N];   int main() {     scanf( %d %d %d , &n, &m, &k);     scanf( %s , s);     scanf( %s , t);     lst = 1, L = 1;     rt[0] = 1;     for (int i = 0; i < m; i++) {       add(lst, t[i] -  a );       rt[i + 1] = lst;     }     EKMP(t, m, s, n, nxt, extendA);     reverse(s, s + n);     reverse(t, t + m);     EKMP(t, m, s, n, nxt, extendB);     reverse(extendB, extendB + n);     for (int i = 0; i < n; i++) {       extendB[i] = min(extendB[i], k), extendA[i] = min(extendA[i], k);       if (extendA[i] == m) {         int l = max(i + extendA[i] - k, 0);         if (l + k + k - 1 < n) {           puts( Yes );           printf( %d %d n , l + 1, l + k + 1);           return 0;         }         l = min(n - 1, i + k - 1);         if (l - k - k + 1 >= 0) {           puts( Yes );           printf( %d %d n , l - k - k + 2, l - k + 2);           return 0;         }       }     }     int last = 1e9;     for (int i = n - 1; i >= 0; i--) {       l[i] = (extendA[i] == k) * k;       for (auto u : w[i + k - 1]) last = min(last, u);       l[i] = max(l[i], i + k - last);       if (extendA[i]) {         int x = i + extendA[i] - 1;         if (x >= (i + k - 1))           last = i;         else           w[x].push_back(i);       }     }     w.clear();     last = -1e9;     for (int i = 0; i < n; i++) {       r[i] = (extendB[i] == k) * k;       for (auto u : w[i - k + 1]) last = max(last, u);       r[i] = max(r[i], last - (i - k));       if (extendB[i]) {         int x = i - extendB[i] + 1;         if (x <= i - k + 1)           last = i;         else           w[x].push_back(i);       }     }     for (int i = 2 * k - 1; i < n; i++) {       int x = rt[l[i - 2 * k + 1]];       while (!tri[x].id) {         tri[x].id = i - 2 * k + 2;         x = tri[x].fail;       }       if (tri[rt[m - r[i]]].id) {         puts( Yes );         printf( %d %d n , tri[rt[m - r[i]]].id, i - k + 2);         return 0;       }     }     printf( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int b[3100];   int a[3100];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);       int bb = b[i] - b[i - 1], l;       if (bb > 0) {       youginzi:         l = 1;         while (bb) {           while (a[l] == 9) l++;           a[l]++;           --bb;         }       } else if (bb < 0) {         while (bb) {           if (bb > 0) goto youginzi;           l = 0;           while (a[++l] == 0)             ;           do {             bb += a[l] - 1;             a[l] = 0;             ++a[++l];           } while (a[l] >= 10);         }       } else {         l = 0;         while (a[++l] == 0)           ;         do {           bb += a[l] - 1;           a[l] = 0;           ++a[++l];         } while (a[l] >= 10);         goto youginzi;       }       int len = 3005;       while (a[len] == 0) --len;       for (int j = len; j >= 1; --j) printf( %d , a[j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   int n, m, i, j, t, a[30005];   long long s0, s1;   int main() {     read(t);     while (t--) {       read(n);       for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]);       a[n + 1] = 0;       for (((i)) = ((n + 1)); ((i)) >= (1); ((i))--) a[i] = a[i] - a[i - 1];       s0 = a[1];       s1 = a[n + 1];       for ((i) = (2); (i) <= (n); (i)++)         if (a[i] > 0)           s1 += a[i];         else           s0 += a[i];       if (s1 <= 0 && s0 >= 0)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       long k;       scanf( %ld , &k);       int d;       scanf( %d , &d);       long arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       if (d == 1) {         cout << 1 << endl;       } else {         set<long> con;         unordered_map<long, int> cnt;         for (int i = 0; i < d; i++) {           con.insert(arr[i]);           cnt[arr[i]]++;         }         long ans = con.size();         long final = con.size();         if (final == 1) {           cout << 1 << endl;         } else {           for (int i = 0; i < n - d; i++) {             cnt[arr[i]]--;             if (cnt[arr[i]] == 0) {               ans--;             }             cnt[arr[i + d]]++;             if (cnt[arr[i + d]] == 1) {               ans++;             }             final = min(final, ans);           }           cout << final << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long a, b, n, m;       scanf( %lld%lld%lld%lld , &a, &b, &n, &m);       if (a < m || b < m) {         printf( No n );         continue;       }       if ((a + b) < (m + n)) {         printf( No n );         continue;       }       if (a <= b) {         a -= m;       } else {         b -= m;       }       if (a + b >= n) {         printf( Yes n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   char scn[N][2];   int l, x, mem;   string s;   int main() {     l = 1;     x = 25;     cin >> s;     for (int i = 1; i <= 10000; i++) {       scn[i][1] =  . ;     }     mem = 0;     l = 1;     for (int i = 0; i < s.size(); i++) {       while (mem != s[i]) {         l++;         scn[l][1] =  X ;         l++;         mem--;         if (mem < 0) {           mem = 256 + mem;         }       }       scn[l][1] =  X ;       l++;     }     for (int i = 1; i <= l; i++) {       cout << scn[i][1] <<  .  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int n, r;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d , &n, &r);       r--;       int sum = 0;       for (int i = 0; i < n - 1; i++) {         int a;         scanf( %d , &a);         a--;         sum = (sum + a) % n;       }       int res = (r - sum + n) % n;       printf( %d n , res + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, n, m, s;   int a[1000], b[1000];   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> l;       a[l]++;     }     for (i = 1; i <= 110; i++) {       s = 0;       for (j = i; j <= i + m; j++) s = s + a[j];       k = max(k, s);     }     cout << n - k;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     long long int brstr = 0;     brstr += (n - 3) * (n - 4);     brstr += 3 * (n - 3);     cout << brstr + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> seive() {     long long n = 2;     vector<long long> pr(200000, -1);     for (int i = n; i < 200000; i++) {       if (pr[i] == -1)         pr[i] = 1;       else         continue;       for (int j = 2 * i; j < 200000; j += i) pr[j] = 0;     }     return pr;   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   bool isprime(long long n) {     bool flag = true;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = false;         break;       }     }     return flag;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     vector<int> le, ri;     int l = 0, r = s.size() - 1;     while (l < r) {       while (l < s.size() && s[l] ==  ) ) l++;       while (r >= 0 && s[r] ==  ( ) r--;       if (l < s.size() && r >= 0 && l < r) {         le.push_back(l + 1);         ri.push_back(r + 1);         l++;         r--;       }     }     if (le.empty()) {       cout <<  0 n ;       return 0;     }     cout <<  1 n ;     cout << 2 * le.size() <<   n ;     for (auto x : le) cout << x <<    ;     reverse(ri.begin(), ri.end());     for (auto x : ri) cout << x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 5, M = 2e4 + 5;   int a[105], b[300];   int dp[105][M];   int main() {     int t;     cin >> t;     while (t--) {       memset(dp, 0, sizeof(dp));       int n, k, l;       scanf( %d %d %d , &n, &k, &l);       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 0; i <= k; i++) b[i] = i;       for (int i = 1; i < k; i++) b[k + i] = k - i;       for (int i = 0; i < 2 * k; i++) dp[0][i] = 1;       for (int i = 1; i <= n; i++)         for (int j = 0; j < 2 * k * n; j++) {           dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - 1]);           if (l < b[j % (2 * k)] + a[i]) dp[i][j] = 0;         }       int flag = 0;       for (int i = 0; i < 2 * k * n; i++)         if (dp[n][i]) {           flag = 1;           break;         }       if (flag)         printf( Yes n );       else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[24], n, Z[24];   bool DP[24][(1 << 23) + 5];   vector<int> X;   map<int, int> Memo;   int main() {   std:     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       Memo[a[i]] = i + 1;     }     Z[0] = 1;     DP[0][0] = 1;     for (int i = 1; i < n; i++) {       int b = 1 << i;       for (int j = 1; j < b; j++) {         if (j & (1 << (i - 1))) {           int cnt = 0, ch = 0;           for (int k = 0; k < i; k++) {             if (j & 1 << k) {               int P = a[i] - a[k];               if (Memo[P] != 0) {                 if (j & 1 << (Memo[P] - 1)) ch = 1;               }               cnt++;             }           }           if (ch == 1) {             int mmask = j & (~(1 << (i - 1)));             if (DP[i - 1][mmask] == 1) ch = 2;             for (int k = 0; k < i - 1; k++) {               if (!(mmask & 1 << k)) {                 int mask = 1 << k;                 mask = mask | mmask;                 if (DP[i - 1][mask] == 1) ch = 2;               }             }           }           if (ch == 2) {             DP[i][j] = 1;             if (cnt < Z[i] || Z[i] == 0) Z[i] = cnt;           }         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (Z[i] == 0) {         cout <<  -1 n ;         return 0;       }       if (ans < Z[i]) ans = Z[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int v = 3 - n % 3, ans = 0;     for (int i = v;; i += 3) {       if (1LL * i * (i + 1) / 2 > (n + i) / 3) break;       ++ans;     }     cout << ans;     return 0;   }


/* -> Written by <-      -----------     |K_A_Z_A_M_A|     |___________|     |    ___    |     |   (^_^)   |     |  /( | )  |     |____|_|____|       H O A N G   */      #include <bits/stdc++.h>      #define Task             running    #define F               first   #define S               second   #define pb              push_back   #define bit(x, i)       ((x >> (i)) & 1)   #define inf             1e9 + 7   #define INF             1e18 + 7   #define ll              long long   #define pii             pair <int, int>   #define debug(x)        cerr << #x <<   is   << x <<   n ;      using namespace std;      const int MOD = 1e9 + 7;   const int maxn = 1e5 + 5;   const int base = 3e5 + 1;      int n;   pair <int, int> a[200005];      int CalDis(int r1, int c1, int r2, int c2) {       if (r1 - c1 == r2 - c2) {           if ((r1 + c1) % 2 == 0) return r2 - r1;           return 0;       }       int newr = r2 - c2 + c1;       int newc = c1;       int x = newr - r1;       if ((newr + newc) % 2) return x / 2;       return (x + 1) / 2;   }      void Solve() {       cin >> n;       for (int i = 1; i <= n; ++ i) {           cin >> a[i].F;       }       for (int i = 1; i <= n; ++ i) {           cin >> a[i].S;       }       sort(a + 1, a + 1 + n);       int r1 = 1, c1 = 1;       ll res = 0;       for (int i = 1; i <= n; ++ i) {           int r2 = a[i].F;           int c2 = a[i].S;           res += CalDis(r1, c1, r2, c2);           c1 = c2;           r1 = r2;       }       cout << res <<   n ;   }      int main(){       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       if (fopen(Task .inp ,  r )){           freopen(Task .inp ,  r , stdin);           freopen(Task .out ,  w , stdout);       }   //    Prepare();       int test_case = 1;       cin >> test_case;       while (test_case --){           Solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int min(long long int a, long long int b) { return a < b ? a : b; }   int getMedian(int ai[100001], int n) {     map<int, int> m;     for (int i = 0; i < n; i++) {       if (m.find(ai[i]) != m.end()) {         m[ai[i]] = m[ai[i]] + 1;       } else         m[ai[i]] = 1;     }     int temp = (m.size() - 1) / 2, k = 0, median;     for (map<int, int>::iterator it = m.begin(); k <= temp; ++it, ++k) {       median = it->first;     }     return median;   }   int main() {     int n, ai[100001];     bool isPossible;     scanf(  n%d , &n);     for (int i = 0; i < n; i++) scanf(  n%d , &ai[i]);     int median = getMedian(ai, n);     bool isDiffSet = false;     int globalDiff, diff;     isPossible = true;     for (int i = 0; i < n; i++) {       diff = ai[i] - median < 0 ? median - ai[i] : ai[i] - median;       if (!diff) continue;       if (isDiffSet) {         if (diff != globalDiff) {           isPossible = false;           break;         }       } else {         globalDiff = diff;         isDiffSet = true;       }     }     printf( %s n , isPossible ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int v, e;     cin >> v >> e;     vector<set<int> > g(v);     int a, b;     for (int i = 0; i < e; i++) {       cin >> a >> b;       g[a - 1].insert(b - 1);       g[b - 1].insert(a - 1);     }     int ans = 0;     while (1) {       vector<int> ve;       for (int i = 0; i < v; i++) {         if (g[i].size() == 1) {           ve.push_back(i);         }       }       for (int i = 0; i < ve.size(); i++) {         set<int>::iterator it = g[ve[i]].begin();         g[ve[i]].clear();         g[*it].erase(ve[i]);       }       if (ve.size())         ans++;       else         break;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int A[100010];   int B[100010];   int C[100010];   int main() {     int n;     scanf( %d , &n);     int m, k;     scanf( %d%d , &m, &k);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , A + i, B + i, C + i);     }     long long sum = 0;     for (int i = 0; i < k; i++) {       int take;       scanf( %d , &take);       for (int t = 0; t < m; t++) {         if (take >= A[t] && take <= B[t]) sum += (C[t] + take - A[t]);       }     }     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp, sum = 0;     cin >> n;     int arr[n];     memset(arr, 0, sizeof(arr));     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];       if (i == 0)         temp = arr[0];       else if (arr[i] > temp)         temp = arr[i];     }     while (((temp * n) - sum) <= sum) {       temp++;     }     cout << temp;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10000;   const int MAXM = 100000;   const int INF = 0x3f3f3f3f;   pair<int, int> nxt[3][3];   int cot[3][3];   map<pair<int, int>, pair<long long, long long> > ma;   int main() {     long long k;     int a, b;     scanf( %I64d%d%d , &k, &a, &b);     a--, b--;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         int x;         scanf( %d , &x);         x--;         nxt[i][j].first = x;       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         int x;         scanf( %d , &x);         x--;         nxt[i][j].second = x;       }     }     pair<int, int> s = pair<int, int>(a, b);     pair<long long, long long> now = pair<long long, long long>(0, 0);     int cc = 0;     while (ma.count(s) == 0) {       if (k == 0) break;       k--;       cot[s.first][s.second] = cc++;       ma[s] = now;       if ((s.first + 1) % 3 == s.second)         now.second++;       else if (s.first == (1 + s.second) % 3)         now.first++;       s = nxt[s.first][s.second];     }     if (ma.count(s)) {       pair<long long, long long> ans = now;       now.first -= ma[s].first;       now.second -= ma[s].second;       long long lun = cc - cot[s.first][s.second];       long long kk = k / lun;       k %= lun;       ans.first += now.first * kk;       ans.second += now.second * kk;       now = pair<long long, long long>(0, 0);       while (k--) {         if ((s.first + 1) % 3 == s.second)           now.second++;         else if (s.first == (1 + s.second) % 3)           now.first++;         s = nxt[s.first][s.second];       }       ans.first += now.first;       ans.second += now.second;       printf( %I64d %I64d n , ans.first, ans.second);     } else {       s = nxt[s.first][s.second];       printf( %I64d %I64d n , now.first, now.second);     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T GCD(T a, T b) {     return b ? GCD(b, a % b) : a;   }   template <class T>   inline T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return a * (b / GCD(a, b));   }   int main() {     int n, s;     cin >> n >> s;     int dol[n];     int cent[n];     int sweet = 0;     int y = 0;     int flag = 0;     for (int i = 0; i < n; i++) {       cin >> dol[i] >> cent[i];       if (cent[i] != 0)         sweet = 100 - cent[i];       else         sweet = 0;       if (dol[i] < s || (dol[i] == s && cent[i] == 0)) {         flag = 1;         if (y < sweet) {           y = sweet;         }       }     }     if (flag == 0)       cout <<  -1  << endl;     else       cout << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000100;   int bit[MAXN];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int w;       cin >> w;       bit[w]++;     }     int step = 0;     for (int i = 0; i < MAXN - 1; ++i) {       bit[i + 1] += bit[i] / 2;       bit[i] %= 2;       step += bit[i];     }     cout << step << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, mod = 1e9 + 7;   int ans[N], a[N];   vector<pair<int, int> > v;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     long long sum = 0;     for (int i = 0; i < m; i++) {       cin >> a[i];       sum += a[i];     }     if (sum < n) return cout << -1, 0;     int cur = 0;     for (int i = 0; i < m; i++) {       if (n - cur < a[i]) return cout << -1, 0;       ans[i] = cur;       sum -= a[i];       cur++;       a[i]--;       while (a[i] && n - cur > sum) cur++, a[i]--;     }     for (int i = 0; i < m; i++) cout << ans[i] + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 5;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   const long long inf = 0x3f3f3f3f;   long long n, m;   long long a[maxn];   long long s1[maxn], s2[maxn];   long long sum1[maxn], sum2[maxn];   int main() {     cin >> n >> m;     a[1] = 0;     for (long long i = 2; i <= n + 1; i++) scanf( %lld , &a[i]);     a[n + 2] = m;     n++, n++;     long long k1 = 1, k2 = 1;     for (long long i = 1; i < n; i += 2) {       s1[k1++] = a[i + 1] - a[i];     }     for (long long i = 2; i < n; i += 2) {       s2[k2++] = a[i + 1] - a[i];     }     for (long long i = 1; i < k1; i++) sum1[i] = sum1[i - 1] + s1[i];     for (long long i = 1; i < k2; i++) sum2[i] = sum2[i - 1] + s2[i];     long long ans = sum1[k1 - 1];     for (long long i = 1; i < n; i++) {       long long sum = 0;       if ((a[i + 1] - a[i] != 1) && (i % 2 != 0)) {         sum += sum1[i / 2] + a[i + 1] - 1 - a[i];         long long num = n - i;         long long nn = n;         if (num % 2) nn--;         sum += sum2[nn / 2] - sum2[i / 2];       } else if (a[i + 1] - a[i] != 1 && (i % 2 == 0)) {         sum += sum1[i / 2] + a[i + 1] - (a[i] + 1);         long long num = n - (i + 1);         long long nn = n;         if (num % 2) nn--;         sum += sum2[nn / 2] - sum2[i / 2];       }       ans = max(ans, sum);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (auto &x : a) cin >> x;     if (*min_element(a.begin(), a.end()) == 1) {       cout << n + 1 <<    ;       for (long long i = 1; i <= n; i++) cout << i <<    ;     } else {       long long k;       for (long long i = n - 1; i >= 0; i--) {         if (!a[i]) {           k = i;           break;         }       }       for (long long i = 0; i <= k; i++) cout << i + 1 <<    ;       cout << n + 1 <<    ;       for (long long i = k + 1; i <= n - 1; i++) cout << i + 1 <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   set<int> s;   int n, t;   char a[maxn];   int pos;   int main() {     register int i, tail, g;     scanf( %d%d , &n, &t);     scanf( %s , a + 1);     for (i = 1; i <= n; i++)       if (a[i] ==  . ) {         pos = i;         break;       }     g = pos;     for (i = pos; i <= n; i++)       if (a[i] >=  5 ) {         g = i;         break;       }     a[0] =  0 ;     bool f;     tail = n;     while (t-- && (g > pos && a[g] >=  5 )) {       a[g] =  0 ;       tail = g;       if (g != pos + 1) {         a[g - 1]++;         f = true;         g = g - 1;       } else {         a[g - 2]++;         g = g - 2;       }       while (g >= 0 && a[g] ==  : ) {         if (g - 1 == pos) {           a[g] =  0 ;           a[g - 2]++;           g -= 2;         } else {           a[g] =  0 ;           a[g - 1]++;           --g;         }       }     }     if (a[0] !=  0 ) printf( %c , a[0]);     for (i = 1; i < pos; i++) printf( %c , a[i]);     while (a[tail] ==  0 ) --tail;     if (tail != pos) {       printf( %c , 46);       for (i = pos + 1; i <= tail; i++) printf( %c , a[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   int a[2020];   struct Dinic {     int V, E, src, tar;     int head[2020], work[2020], dis[2020];     int to[8080], nxt[8080];     long long cap[8080];     int q[2020], qf, qb;     void init(int n, int s, int t) {       V = n + 1;       E = 0;       src = s;       tar = t;       for (int i = 0; i <= V; i++) head[i] = -1;     }     void add(int u, int v, long long c) {       to[E] = v;       cap[E] = c;       nxt[E] = head[u];       head[u] = E++;       to[E] = u;       cap[E] = 0;       nxt[E] = head[v];       head[v] = E++;     }     bool bfs() {       for (int i = 0; i <= V; i++) dis[i] = -1;       qf = qb = 0;       q[qb++] = src;       dis[src] = 0;       while (qf < qb && dis[tar] == -1) {         int u = q[qf++];         for (int i = head[u]; i >= 0; i = nxt[i]) {           int v = to[i];           if (dis[v] == -1 && cap[i] > 0) {             dis[v] = dis[u] + 1;             q[qb++] = v;           }         }       }       return dis[tar] >= 0;     }     long long dfs(int u, long long &bot) {       int v;       long long bot1, delta;       if (u == tar) return bot;       for (int &i = work[u]; i >= 0; i = nxt[i]) {         int v = to[i];         if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;         bot1 = min(bot, cap[i]);         if (delta = dfs(v, bot1)) {           cap[i] -= delta;           cap[i ^ 1] += delta;           bot = bot1;           return delta;         }       }       return 0;     }     long long dinic() {       long long ans = 0, delta, bot;       while (bfs()) {         memcpy(work, head, sizeof(int) * V);         delta = 0x3f3f3f3f3f3f3f3fLL;         while (delta = dfs(src, bot = 0x3f3f3f3f3f3f3f3fLL)) ans += delta;       }       return ans;     }   } dinic;   int main() {     int n, m;     scanf( %d %d , &n, &m);     int src = n + m + 1, tar = src + 1;     dinic.init(tar, src, tar);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       dinic.add(src, i, a[i]);     }     long long ans = 0;     for (int i = n + 1, u, v, w; i <= n + m; i++) {       scanf( %d %d %d , &u, &v, &w);       dinic.add(u, i, 0x3f3f3f3f3f3f3f3fLL);       dinic.add(v, i, 0x3f3f3f3f3f3f3f3fLL);       dinic.add(i, tar, w);       ans += w;     }     printf( %I64d n , ans - dinic.dinic());   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 0.000001;   const long double pi = acos(-1);   const int maxn = 1e7 + 9;   const int mod = 1e9 + 7;   const long long MOD = 1e18 + 9;   const long long INF = 1e18 + 123;   const int inf = 2e9 + 11;   const int mxn = 1e6 + 9;   const int N = 1e6 + 123;   const int M = 22;   const int pri = 997;   const int Magic = 2101;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   int n, m, k;   int cnt[N];   string s;   int a[N];   vector<int> g[N];   int u[N];   int ans, res;   int cur;   long long fac[N];   long long bpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) (res *= a) %= mod;       b /= 2;       a *= a;       a %= mod;     }     return res;   }   inline void upd(long long &ans, long long l, long long r) {     ans *= fac[r];     ans %= mod;     ans = (ans * bpow(fac[l - 1], mod - 2)) % mod;   }   inline long long calc(vector<int> &pw) {     long long ans = 1, pref = 0;     vector<long long> f;     for (auto e : pw) {       f.push_back((n / e) - pref);       (ans *= f.back()) %= mod;       pref = n / e;     }     long long cur = 1;     for (int i = (int)(pw.size()) - 1; ~i; --i) {       upd(ans, cur, cur + f[i] - 2);       cur += f[i];     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     vector<int> pw;     pw.push_back(1);     while (pw.back() * 2 <= n) {       pw.push_back(pw.back() * 2);     }     reverse(pw.begin(), pw.end());     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;     long long ans = calc(pw);     if (pw[0] * 3ll <= n * 2ll) {       for (int i = 1; i < (int)(pw.size()); i++) {         vector<int> o = pw;         for (int j = 0; j < i; j++) {           o[j] = 3ll * o[j] / 2ll;         }         ans += calc(o);         if (ans >= mod) ans -= mod;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 100005;   int a[maxn], lefts[maxn], rights[maxn];   int main() {     int n, l, r, q1, q2;     cin >> n >> l >> r >> q1 >> q2;     memset(lefts, 0, sizeof(lefts));     memset(rights, 0, sizeof(rights));     for (int i = 0; i < n; i++) {       cin >> a[i];       lefts[i + 1] += (lefts[i] + a[i]);     }     for (int i = n - 1; i >= 0; i--) {       rights[n - i] += (rights[n - i - 1] + a[i]);     }     int sum = 0, ans = INF;     for (int i = 0; i <= n; i++) {       sum = 0;       sum += ((lefts[i] * l) + rights[n - i] * r);       if (i > (n - i))         sum += ((2 * i - n - 1) * q1);       else if (i < (n - i))         sum += ((n - 2 * i - 1) * q2);       ans = min(ans, sum);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   double eps = 1e-12;   long long hcf(long long p, long long q) {     if (p > q) return hcf(q, p);     if (!p) return q;     return hcf(q % p, p);   }   long long lcm(long long p, long long q) { return p * q / hcf(p, q); }   long long power(long long a, long long n, long long mod) {     long long ans = 1;     while (n) {       if (n % 2) ans *= a;       a *= a;       n /= 2;       a %= mod;       ans %= mod;     }     return ans;   }   long long fac(long long k, long long mod) {     long long ans = 1;     for (long long i = 1; i < k + 1; i++) {       ans *= i;       ans %= mod;     }     return ans;   }   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long k = a - b;     if (k + c > 0 && k - c > 0)       cout <<  + ;     else if (k + c < 0 && k - c < 0)       cout <<  - ;     else if (k + c == 0 && k - c == 0)       cout << 0;     else       cout <<  ? ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], b[100005];   const long long INF = 1000000009;   int main() {     int n, x, y;     cin >> n >> x >> y;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) b[i] = INF;     for (int i = 0; i < n; i++)       for (int j = i - y; j <= i + x && j < n; j++)         if (j >= 0 && j != i) b[j] = min(a[i], b[j]);     int k = 0;     while (b[k] < a[k]) k++;     cout << k + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w1, h1, w2, h2, s;   int main() {     cin >> w1 >> h1 >> w2 >> h2;     s = 2 * (h1 + h2 + w1 + 2);     cout << s << endl;   }


#include <bits/stdc++.h>   int main() {     int n, m, i, a;     int f[105] = {0};     scanf( %d%d , &n, &m);     while (m--) {       scanf( %d , &a);       for (i = a; i <= n; i++)         if (f[i] == 0) f[i] = a;     }     for (i = 1; i < n; i++) printf( %d  , f[i]);     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double PI = acos(-1.0);   int a[N], l[N], r[N], d[N], cha[N];   int m, n, k, t;   bool check(int x) {     if (!x) return true;     for (int i = 0; i <= n + 1; i++) cha[i] = 0;     int g = a[x];     for (int i = 1; i <= k; i++) {       if (d[i] > g) {         cha[l[i]]++, cha[r[i] + 1]--;       }     }     int res = 0;     for (int i = 1; i <= n + 1; i++) {       cha[i] += cha[i - 1];       if (cha[i] > 0) res++;     }     return res * 2 + n + 1 <= t;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> m >> n >> k >> t;     for (int i = 1; i <= m; i++) cin >> a[i];     sort(a + 1, a + 1 + m, greater<int>());     for (int i = 1; i <= k; i++) cin >> l[i] >> r[i] >> d[i];     int L = 0, R = m, M, ans = 0;     while (L <= R) {       M = (L + R) >> 1;       if (check(M)) {         ans = M;         L = M + 1;       } else         R = M - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, Count = 0, a[2005], Free[2005];   vector<int> V;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] <= k)         Free[a[i]]++;       else         V.push_back(i);     }     for (int i = 1; i <= k; i++)       while (V.size() > 0 && Free[i] < n / k) {         Free[i]++;         Count++;         a[V.back()] = i;         V.pop_back();       }     for (int i = 1; i <= k; i++)       if (Free[i] < n / k) {         for (int j = 1; j <= n; j++)           if (Free[a[j]] > n / k) {             Free[a[j]]--;             Free[i]++;             Count++;             a[j] = i;             if (Free[i] == n / k) break;           }       }     cout << n / k <<     << Count <<   n ;     for (int i = 1; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long aabs(long long a) {     if (a < 0)       return -a;     else       return a;   }   struct node {     long long num;     int id;     bool operator<(const node &a) const { return aabs(num) > aabs(a.num); }   };   long long a[200005];   long long n, k, x;   int main() {     int i;     scanf( %I64d%I64d%I64d , &n, &k, &x);     int sign = 1;     priority_queue<node> que;     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);       if (a[i] < 0) sign = -sign;       que.push((node){a[i], i});     }     while (k--) {       node temp = que.top();       que.pop();       if (a[temp.id] < 0) {         if (sign == -1)           a[temp.id] -= x;         else           a[temp.id] += x;         if (a[temp.id] >= 0) sign = -sign;       } else {         if (sign == -1)           a[temp.id] += x;         else           a[temp.id] -= x;         if (a[temp.id] < 0) sign = -sign;       }       que.push((node){a[temp.id], temp.id});     }     for (i = 1; i < n; i++) {       printf( %I64d  , a[i]);     }     printf( %I64d n , a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const N = 1e5 + 100, INF = 1ll * 1e9 * 1e9 + 100;   long long n, m, s, t;   long long h[N], d[N], dis[2][N], ans[N];   pair<pair<long long, long long>, long long> e[N];   vector<long long> f[N], g[N];   set<pair<long long, long long> > st;   bool vis[N];   void dij(bool b, long long s) {     dis[b][s] = 0;     st.insert({0, s});     while (st.size()) {       long long v = st.begin()->second;       st.erase(st.begin());       for (long long i : g[v]) {         long long u = e[i].first.first + e[i].first.second - v, w = e[i].second;         if (b ^ (u != e[i].first.second)) continue;         if (dis[b][v] + w < dis[b][u]) {           st.erase({dis[b][u], u});           dis[b][u] = dis[b][v] + w;           st.insert({dis[b][u], u});         }       }     }   }   void cut_edge(long long v = 0, long long i = -1) {     long long p = (~i ? e[i].first.first + e[i].first.second - v : -1);     vis[v] = 1;     d[v] = h[v];     for (long long j : f[v]) {       long long u = e[j].first.first + e[j].first.second - v;       if (vis[u]) {         if (i != j) {           ans[j] = 1;           d[v] = min(d[v], h[u]);           if (h[u] == h[p]) ans[i] = 1;         }         continue;       }       h[u] = h[v] + 1;       cut_edge(u, j);       if (d[u] != h[u]) ans[j] = 1;       d[v] = min(d[v], d[u]);     }   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     fill(d, d + N, INF);     fill(dis[0], dis[0] + N, INF);     fill(dis[1], dis[1] + N, INF);     cin >> n >> m >> s >> t;     s--, t--;     for (long long i = 0, u, v, w; i < m; i++) {       cin >> u >> v >> w;       u--, v--;       e[i] = {{u, v}, w};       g[u].push_back(i);       g[v].push_back(i);     }     dij(0, s), dij(1, t);     for (long long i = 0; i < m; i++) {       long long u = e[i].first.first, v = e[i].first.second, w = e[i].second;       long long path = dis[0][u] + w + dis[1][v];       if (path == dis[0][t]) {         f[u].push_back(i);         f[v].push_back(i);       } else {         ans[i] = path - dis[0][t] + 1;       }     }     cut_edge(s);     for (long long i = 0; i < m; i++) {       long long w = e[i].second;       if (w - ans[i] <= 0)         cout <<  NO n ;       else if (!ans[i])         cout <<  YES n ;       else         cout <<  CAN   << ans[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (abs(a + c - b - d) > 1) {       cout <<  NO n ;     } else {       vector<int> v(a + b + c + d);       if (a + c > b + d) {         for (int i = 0; i < v.size(); i += 2) {           if (a) {             v[i] = 0;             a--;           } else {             v[i] = 2;             c--;           }         }         for (int i = 1; i < v.size(); i += 2) {           if (b) {             v[i] = 1;             b--;           } else {             v[i] = 3;             d--;           }         }       } else {         for (int i = 1; i < v.size(); i += 2) {           if (a) {             v[i] = 0;             a--;           } else {             v[i] = 2;             c--;           }         }         for (int i = 0; i < v.size(); i += 2) {           if (b) {             v[i] = 1;             b--;           } else {             v[i] = 3;             d--;           }         }       }       bool check = true;       for (int i = 0; i < (int)v.size() - 1; i++) {         if (abs(v[i] - v[i + 1]) != 1) {           check = false;           break;         }       }       if (a + c == b + d && check == false) {         for (int i = 0; i < (int)v.size() - 1; i += 2) {           swap(v[i], v[i + 1]);         }         check = true;         for (int i = 0; i < (int)v.size() - 1; i++) {           if (abs(v[i] - v[i + 1]) != 1) {             check = false;             break;           }         }       }       if (check) {         cout <<  YES n ;         for (int i : v) cout << i <<    ;         cout <<   n ;       } else         cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string S;   vector<vector<vector<int> > > cc;   int dp(int idx, int d, int s) {     int &ret = cc[idx][d][s];     if (ret != -1) return ret;     if (idx == S.size() / 2) {       if (S.size() % 2) {         int x = S[idx] -  0 ;         if ((10 * d + x - s) < 0 || (x - s) % 2)           return 0;         else           return 1;       } else         return d == s;     }     ret = 0;     for (int i = idx == 0; i <= 18; i++) {       int x = S[idx] -  0 ;       if ((s + i) % 10 != x) continue;       int y = S[S.size() - 1 - idx] -  0 ;       if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue;       ret |= dp(idx + 1, 10 * d + y - i, i + s >= 10);     }     return ret;   }   vector<int> A;   void dfs(int idx, int d, int s) {     if (idx == S.size() / 2) {       if (S.size() % 2) {         int x = S[idx] -  0 ;         A[idx] = (10 * d + x - s) / 2;         return;       } else         return;     }     for (int i = idx == 0; i <= 18; i++) {       int x = S[idx] -  0 ;       if ((s + i) % 10 != x) continue;       int y = S[S.size() - 1 - idx] -  0 ;       if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue;       if (dp(idx + 1, 10 * d + y - i, i + s >= 10)) {         A[idx] = i / 2;         A[S.size() - 1 - idx] = i - i / 2;         dfs(idx + 1, 10 * d + y - i, i + s >= 10);         return;       }     }   }   int main() {     cin >> S;     reverse(S.begin(), S.end());     cc = vector<vector<vector<int> > >(         S.size(), vector<vector<int> >(2, vector<int>(2, -1)));     if (dp(0, 0, 0)) {       A.resize(S.size());       dfs(0, 0, 0);       reverse(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) {         printf( %d , A[i]);       }       return 0;     }     if (S[S.size() - 1] !=  1 ) {       printf( 0 );       return 0;     }     S.erase(S.end() - 1);     cc = vector<vector<vector<int> > >(         S.size() + 1, vector<vector<int> >(2, vector<int>(2, -1)));     if (dp(0, 1, 0)) {       A.resize(S.size());       dfs(0, 1, 0);       reverse(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) {         printf( %d , A[i]);       }       return 0;     }     printf( 0 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100105;   const double eps = 1e-6;   long double x1, y1_, x2, y2, mx, my, vx, vy, d, L, ans = 1e16;   vector<pair<long double, int> > V;   int X[N], Y[N], R[N], n, s = 0;   long double check(int k, long double t, int op) {     return ((sqrt(d * d + t * t) + op * R[k]) *             (sqrt(d * d + t * t) + op * R[k])) -            ((X[k] - mx - vx * t) * (X[k] - mx - vx * t)) -            ((Y[k] - my - vy * t) * (Y[k] - my - vy * t));   }   long double BI(int k, int op) {     long double l = -1e12, r = 1e12, mid, c = check(k, l, op), cc;     while (r - l > eps) {       mid = (l + r) / 2, cc = check(k, mid, op);       (c > 0 && cc > 0 || c < 0 && cc < 0) ? l = mid : r = mid;     }     return (l + r) / 2;   }   int main() {     scanf( %Lf%Lf%Lf%Lf%d , &x1, &y1_, &x2, &y2, &n);     for (int i = (1); i <= (n); ++i) scanf( %d%d%d , &X[i], &Y[i], &R[i]);     mx = (x1 + x2) / 2, my = (y1_ + y2) / 2,     L = sqrt(((x1 - x2) * (x1 - x2)) + ((y1_ - y2) * (y1_ - y2))),     vx = (y1_ - y2) / L, vy = (x2 - x1) / L, d = L / 2;     for (int i = (1); i <= (n); ++i) {       long double l = BI(i, 1), r = BI(i, -1);       if (l > r) swap(l, r);       V.push_back(make_pair(l - eps, -1)), V.push_back(make_pair(r + eps, 1));     }     V.push_back(make_pair(0, 0));     sort((V).begin(), (V).end());     for (int i = 0; i < V.size(); i++) {       s += V[i].second;       if (s == 0 || V[i].second == -1 && s == -1)         ans = min(ans, sqrt(((V[i].first) * (V[i].first)) + ((d) * (d))));     }     printf( %.12Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const double eps = 1e-8;   const double pi = acos(-1.0);   int n, m;   char a[110], b[110], c[110];   int d[26];   int main() {     srand(time(NULL));     scanf( %d%d%s%s , &n, &m, a, b);     int la = strlen(a), lb = strlen(b);     int flag = 1;     for (int i = 0; i < lb; i++)       if (b[i] ==  1 ) {         for (int j = 0; j < la; j++)           if (c[i + j] == 0 || c[i + j] == a[j]) {             c[i + j] = a[j];           } else             flag = 0;         if (flag == 0) break;       }     if (flag) {       for (int i = 0; i < m; i++) d[i] = i;       for (int i = 0; i < lb; i++)         if (b[i] ==  0 ) {           int done = 0;           for (int j = 0; j < la; j++)             if (c[i + j] == 0) {               random_shuffle(d, d + m);               for (int k = 0; k < m; k++) {                 if (d[k] +  a  != a[j]) {                   c[i + j] = d[k] +  a , done = 1;                   break;                 }               }             } else if (c[i + j] != a[j]) {               done = 1;               break;             }           if (!done) {             flag = 0;             break;           }         }     }     for (int i = 0; i < n; i++)       if (c[i] == 0) c[i] =  a ;     if (flag)       puts(c);     else       puts( No solution );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> p(n / 2);     for (int i = 0; i < n / 2; i++) {       cin >> p[i];     }     sort(p.begin(), p.end());     int sum1 = 0, sum2 = 0;     for (int i = 0; i < n / 2; i++) {       sum1 += abs(p[i] - i * 2 - 1);       sum2 += abs(p[i] - i * 2 - 2);     }     cout << min(sum1, sum2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, c = getchar();     bool f = 0;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c & 15);     return f ? -x : x;   }   const int N = 300005;   const int mod = 998244353;   int a[N];   int qpow(int a, int b) {     int t = 1;     while (b) {       if (b & 1) t = 1ll * t * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return t;   }   bool cmp(const int &a, const int &b) { return a < b; }   int main() {     int n = gi();     for (int i = 1; i <= (n << 1); ++i) a[i] = gi();     sort(a + 1, a + (n << 1) + 1, cmp);     int fac = 1;     for (int i = 1; i <= n; ++i) fac = 1ll * fac * i % mod;     int faci = qpow(fac, mod - 2);     for (int i = n + 1; i <= (n << 1); ++i) fac = 1ll * fac * i % mod;     int ans = 0;     for (int i = 1; i <= n; ++i) {       ans += a[n + i] - a[i];       if (ans >= mod) ans -= mod;     }     printf( %d n , 1ll * fac * faci % mod * faci % mod * ans % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   int read() {     int x = 0, w = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     return x * w;   }   void bmax(long long &t1, long long t2) { t1 = max(t1, t2); }   void bmin(long long &t1, long long t2) { t1 = min(t1, t2); }   const int N = 2e5 + 10;   const long long INF = 1e16;   struct Node {     long long mx, mn, ans;     Node(long long _mx = -INF, long long _mn = INF, long long _ans = -INF)         : mx(_mx), mn(_mn), ans(_ans) {}     Node operator+(const Node &tmp) const {       Node res = Node(mx, mn);       res.ans = max(tmp.mx - mn, max(ans, tmp.ans));       bmax(res.mx, tmp.mx);       bmin(res.mn, tmp.mn);       return res;     }   };   int n, m;   long long h[N], s[N];   struct SegmentTree {     Node tr[N << 2];     void Build(int pos, int l, int r) {       if (l == r) {         tr[pos].mx = h[l] + s[l - 1];         tr[pos].mn = s[l - 1] - h[l];         tr[pos].ans = -INF;         return;       }       int mid = (l + r) >> 1;       Build(pos << 1, l, mid);       Build(pos << 1 | 1, mid + 1, r);       tr[pos] = tr[pos << 1] + tr[pos << 1 | 1];     }     Node Query(int pos, int L, int R, int l, int r) {       if (R < l || L > r) return Node();       if (l <= L && R <= r) return tr[pos];       int mid = (L + R) >> 1;       Node res1 = Query(pos << 1, L, mid, l, r),            res2 = Query(pos << 1 | 1, mid + 1, R, l, r);       Node res = res1 + res2;       return res;     }   } Tr;   int main() {     n = read();     m = read();     s[0] = 0;     for (int i = 1; i <= n; i++) s[i] = read(), s[i + n] = s[i];     for (int i = 1; i <= n; i++) h[i] = read() * 2, h[n + i] = h[i];     for (int i = 1; i <= 2 * n; i++) s[i] += s[i - 1];     Tr.Build(1, 1, 2 * n);     while (m--) {       int l = read(), r = read();       Node ans;       if (l <= r)         ans = Tr.Query(1, 1, 2 * n, r + 1, l + n - 1);       else         ans = Tr.Query(1, 1, 2 * n, r + 1, l - 1);       printf( %lld n , ans.ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int c[1005][1005], quadratic = 0, single_x = 0, single_y = 0,                                cnstnt = 0;   void calc_time_function(long long int n, long long int m) {     long long int i, j, centr_x, centr_y;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         centr_x = i * 4 + 2LL;         centr_y = j * 4 + 2LL;         quadratic += c[i][j];         cnstnt += c[i][j] * (centr_x * centr_x + centr_y * centr_y);         single_x += (2 * c[i][j] * centr_x);         single_y += (2 * c[i][j] * centr_y);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int i, j, t, n, m, k, l, r, temp, left, right, mini, maxi, flag,         leftthird, rightthird, x, y;     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> c[i][j];     mini = 1e18;     ;     calc_time_function(n, m);     for (i = 0; i <= n; i++) {       for (j = 0; j <= m; j++) {         x = i * 4;         y = j * 4;         temp = (x * x + y * y) * quadratic - x * single_x - y * single_y + cnstnt;         if (temp < mini) {           mini = temp;           left = i;           right = j;         }       }     }     cout << mini << endl;     cout << left <<     << right << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000000 + 7;   const long long MOD1 = 998244353;   long long mod(long long x) { return (x % MOD + MOD) % MOD; }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   string itos(long long s) {     string str = to_string(s);     return str;   }   long long stoi2(string s) {     long long a = atoi(s.c_str());     return a;   }   long long powerm(long long a, long long b, long long MOD) {     a %= MOD;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return res;   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   bool isSubSequence(string str1, string str2, int m, int n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   bool ispalindrome(long long len, string str) {     for (int i = 0; i < len / 2; i++) {       if (str[i] != str[len - 1 - i]) {         return false;       }     }     return true;   }   inline bool isPowerOfTwo(long long x) {     return ((1LL << (long long)log2(x)) == x);   }   long long isprime(long long N) {     if (N < 2 || (!(N & 1) && N != 2)) return 0;     for (long long i = 3; i * i <= N; i += 2) {       if (!(N % i)) return 0;     }     return 1;   }   vector<long long> factor;   void factors(long long n) {     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (i == n / i)           factor.push_back(i);         else {           factor.push_back(i);           factor.push_back(n / i);         }       }     }     sort((factor).begin(), (factor).end());   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   bool isvalid(long long i, long long j, long long n) {     if (i >= 0 && i < n && j >= 0 && j < n) return true;     return false;   }   long long dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};   long long dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   long long binarytodecimal(string n) {     string num = n;     long long dec_value = 0;     long long base = 1;     long long len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   long long extended_GCD(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long gcd = extended_GCD(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   long long modinv(long long a, long long mod = MOD) {     long long x, y;     extended_GCD(a, mod, x, y);     if (x < 0) x += mod;     return x;   }   string dtb(long long n) {     string s =   ;     while (n > 0) {       if (n % 2 == 0)         s.push_back( 0 );       else         s.push_back( 1 );       n /= 2;     }     reverse((s).begin(), (s).end());     return s;   }   long long getfactorisation(long long n) {     long long N = 5e6 + 5;     vector<long long> fact(N);     for (int i = 0; i < N; i++) fact[i] = i;     for (int i = 2; i < N; i += 2) fact[i] = 2;     for (long long i = 3; i <= N; i += 2)       if (i == fact[i])         for (long long j = i * i; j < N; j += i)           if (fact[j] == j) fact[j] = i;     vector<long long> res;     while (n > 1) {       res.push_back(fact[n]);       n /= fact[n];     }     return res.size();   }   long long maxPrimeFactor(long long n) {     long long maxPrime = -1;     while (n % 2 == 0) {       maxPrime = 2;       n >>= 1;     }     for (int i = 3; i <= sqrt(n); i += 2) {       while (n % i == 0) {         maxPrime = i;         n = n / i;       }     }     if (n > 2) maxPrime = n;     return maxPrime;   }   vector<long long> seive;   void Seive() {     const long long maxn = 1e6 + 5;     seive.resize(maxn);     for (long long i = (long long)0; i < (long long)maxn; i++) seive[i] = i;     for (long long i = 2; i <= maxn; i += 2) seive[i] = 2;     seive[1] = -1;     seive[0] = -1;     for (long long i = 3; i <= maxn; i += 2)       if (i == seive[i])         for (long long j = i * i; j < maxn; j += i)           if (seive[j] == j) seive[j] = i;   }   void factorisation(long long n) {     vector<long long> res;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) {           n /= i;           res.push_back(i);         }       }     }     if (n > 1) res.push_back(n);   }   long long fac[200005];   unsigned long long modInverse(unsigned long long n, int p) {     return powerm(n, p - 2, p);   }   long long nCrModPFermat(unsigned long long n, int r, int p) {     if (n < r) return 0;     if (r == 0) return 1;     unsigned long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long T = 1;     while (T--) {       long long n, q;       cin >> n >> q;       vector<long long> v(n), k(q);       for (long long i = (long long)0; i < (long long)n; i++) cin >> v[i];       for (long long i = (long long)0; i < (long long)q; i++) cin >> k[i];       for (long long i = (long long)1; i < (long long)n; i++) v[i] += v[i - 1];       long long sum = 0;       for (long long i = (long long)0; i < (long long)q; i++) {         sum += k[i];         long long lower = (lower_bound(v.begin(), v.end(), sum) - v.begin());         if (lower == n) {           cout << n;           sum = 0;         } else {           if (v[lower] > sum) {             if (lower == 0) {               cout << n;             } else {               lower--;               cout << n - lower - 1;             }           } else {             if (lower == n - 1) {               cout << n;               sum = 0;             } else               cout << n - lower - 1;           }         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>      typedef long long ll;   typedef unsigned long long ull;   typedef long double ld;      using namespace std;      const int INF = 1e9 + 5;      void failure () {     cout << 0 << endl;     exit(0);   }      namespace Lib {   #define ran(i, a, b) for (auto i = (a); i < (b); i++)          struct ModArithm {       //!pause       ull q = 0; // (1<<(shift+64))/n       char shift = -1;       //!unpause       ull n;       ld rec;       ModArithm(ull _n) : n(_n) { // n in [2, 1<<63)         rec = 1.0L / n;         //!pause         ull rem = 1;         while (rem < n) {           ++shift;           rem <<= 1;         }         for (int i = 63; i >= 0; --i) {           if (rem >= n) {             q |= 1LL << i;             rem -= n;           }           rem *= 2;         }         //!unpause       }       // a, b in [0, min(2*n, 1<<63))       ull multf(ull a, ull b) {         ull mult = (ld)a * b * rec + 0.5L;         ll res = a * b - mult * n;         if (res < 0) res += n;         return res; // in [0, n-1)       }       //!pause   #ifndef ONLINE_JUDGE       ull multa(ll a, ll b) { // a, b in [0, min(2*n, 1<<63))         ull res;         ull tmp;         __asm__(                  mulq %[b]; n t           // a*b                  movq %%rax, %[res]; n t  // ab_l = (a*b) & ((1 <<                 // 64)-1)                  movq %%rdx, %[tmp]; n t  // ab_h = (a*b) >> 64                  mulq %[q]; n t           // ab_l * q                  movq %[tmp], %%rax; n t                   movq %%rdx, %[tmp]; n t  // abq_m = (ab_l * q) >>                 // 64                  mulq %[q]; n t           // ab_h * q                  addq %[tmp], %%rax; n t  // abq_m += (ab_h * q) &                 // ((1 << 64)-1)                  adcq $0, %%rdx; n t  // abq_h = ((ab_h * q) >> 64)                 // + carry                  shrdq %%cl, %%rdx, %%rax; n t  // d = (a*b)/n =                 // (abq_m >> shift)                 // | (abq_h << (64                 // -shift))                  mulq %[n]; n t                 // d*n                  subq %%rax, %[res]; n t        // ab_l - = dn_l                 : [res]  =&r (res), [tmp]  =&r (tmp)                 : [a]  %a (a), [b]  d (b), [q]  r (q),                   [shift]  c (shift), [n]  rm (n)                 :  cc );         return res; // in [0, 2n-1)       }       ull multi(ull a, ull b) {         unsigned __int128 mult = a;         mult *= b;         ull prod =           (((mult >> 64) * q) +            ((unsigned __int128)(ull)mult * q >> 64)) >>           shift;         return (ull)mult - prod * n;       }       ull fix(ull a) {         if (a >= n) a -= n;         return a;       }       ull mult(ull a, ull b) { return fix(multi(a, b)); }   #endif       //!unpause       ull sqp1(ull a) { return multf(a, a) + 1; }     };     //!finish     //!start        ull pow_mod(ull a, ull n, ModArithm &arithm) {       ull res = 1;       for (ull i = 1; i <= n; i <<= 1) {         if (n & i) res = arithm.multf(res, a);         a = arithm.multf(a, a);       }       return res;     }     //!finish     //!start        vector<char> small_primes = {       2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};        bool is_prime(ull n) { // n <= 1<<63, 1M rand/s       ModArithm arithm(n);       if (n == 2 || n == 3) return true;       if (!(n & 1) || n == 1) return false;       int s = __builtin_ctzll(n - 1);       ull d = (n - 1) >> s;       for (ull a : small_primes) {         if (a >= n) break;         a = pow_mod(a, d, arithm);         if (a == 1 || a == n - 1) continue;         ran(r, 1, s) {           a = arithm.multf(a, a);           if (a == 1) return false;           if (a == n - 1) break;         }         if (a != n - 1) return false;       }       return true;     }     //!finish     //!pause      #ifdef ONLINE_JUDGE     ll __gcd(ll a, ll b) {       if (a) return __gcd(b % a, a);       return b;     }   #endif        //!unpause     //!start        ll pollard_rho(ll n) {       ModArithm arithm(n);       int cum_cnt = 64 - __builtin_clzll(n);       cum_cnt *= cum_cnt / 5 + 1;       while (true) {         ll lv = rand() % n;         ll v = arithm.sqp1(lv);         int idx = 1;         int tar = 1;         while (true) {           ll cur = 1;           ll v_cur = v;           int j_stop = min(cum_cnt, tar - idx);           for (int j = 0; j < j_stop; ++j) {             cur = arithm.multf(cur, abs(v_cur - lv));             v_cur = arithm.sqp1(v_cur);             ++idx;           }           //!pause           // cur = arithm.fix(cur);           //!unpause           if (!cur) {             for (int j = 0; j < cum_cnt; ++j) {               ll g = __gcd(abs(v - lv), n);               if (g == 1) {                 v = arithm.sqp1(v);               } else if (g == n) {                 break;               } else {                 return g;               }             }             break;           } else {             ll g = __gcd(cur, n);             if (g != 1) return g;           }           v = v_cur;           idx += j_stop;           if (idx == tar) {             lv = v;             tar *= 2;             v = arithm.sqp1(v);             ++idx;           }         }       }     }     //!finish     //!start           map<ll, int> prime_factor(                               ll n, map<ll, int> *res = NULL) {       // n <= 1<<62, ~1000/s (<500/s on CF)       if (!res) {         map<ll, int> res_act;         for (int p : small_primes) {           while (!(n % p)) {             ++res_act[p];             n /= p;           }         }         if (n != 1) prime_factor(n, &res_act);         return res_act;       }       if (is_prime(n)) {         ++(*res)[n];       } else {         ll factor = pollard_rho(n);         prime_factor(factor, res);         prime_factor(n / factor, res);       }       return map<ll, int>();     } // Usage: fact = prime_factor(n);   }      struct Num {     ll val;     vector<int> divs;   };      const int MAX_N = 1005;      map<ll, int> idx; // prime number -> small number   vector<ll> ppw [MAX_N];   vector<Num> oths;      ll arr [MAX_N];   map<ll, int> factor [MAX_N];      int main () {     int n, K;     cin >> n >> K;        for (int i = 0; i < n; i++) {       cin >> arr[i];       factor[i] = Lib::prime_factor(arr[i]);       if (factor[i].size() == 1) {         idx[factor[i].begin()->first] = 0;       }     }        int pc = 0;     for (auto it = idx.begin(); it != idx.end(); it++) {       it->second = pc;       pc++;     }        for (int i = 0; i < n; i++) {       if (factor[i].size() == 1) {         ppw[idx[factor[i].begin()->first]].push_back(arr[i]);       }     }        set<int> ok_ids;     for (int i = 0; i < pc; i++) {       if ((int) ppw[i].size() >= 2) {         ok_ids.insert(i);       }     }        for (int i = 0; i < n; i++) {       if (factor[i].size() != 1) {         Num cur;         cur.val = arr[i];         cur.divs = vector<int> (0);            bool ok = true;            for (auto it = factor[i].begin(); it != factor[i].end(); it++) {           if (!idx.count(it->first) || !ok_ids.count(idx[it->first])) {             ok = false;           } else {             cur.divs.push_back(idx[it->first]);           }         }                  if (ok) {           oths.push_back(cur);         }       }     }        if (K == 1) {       failure();     }        int ppc = 0, all2 = true;     for (int id : ok_ids) {       ppc += ppw[id].size();       if (ppw[id].size() != 2) {         all2 = false;       }     }        int totc = ppc + (int) oths.size();     if (totc < K) {       failure();     }        // easy case: take all primes and then whatever     if (ppc <= K) {       for (int id : ok_ids) {         for (ll pp : ppw[id]) {           cout << pp <<    ;         }       }          for (int i = 0; i < K - ppc; i++) {         cout << oths[i].val <<    ;       }       cout << endl;       return 0;     }        // take one other thing with the smallest number of requirements     // and then prime powers in pairs     if (all2 && K % 2 == 1) {       pair<int, int> least_req = make_pair(INF, -1);       for (int i = 0; i < (int) oths.size(); i++) {         least_req = min(least_req, make_pair((int) oths[i].divs.size(), i));       }          if (least_req.first > K / 2) {         failure();       }          int lid = least_req.second;       cout << oths[lid].val <<    ;       K--;       for (int d : oths[lid].divs) {         for (ll pp : ppw[d]) {           cout << pp <<    ;         }         ok_ids.erase(d);         K -= 2;       }          for (int u : ok_ids) {         if (K == 0) {           break;         }            for (ll pp : ppw[u]) {           cout << pp <<    ;         }         K -= 2;       }       cout << endl;       return 0;     }        // take two things from each prime power and then some     if (K >= 2 * (int) ok_ids.size()) {       vector<ll> rem_ppws;       for (int id : ok_ids) {         for (int i = 0; i < (int) ppw[id].size(); i++) {           if (i < 2) {             cout << ppw[id][i] <<    ;             K--;           } else {             rem_ppws.push_back(ppw[id][i]);           }         }       }          for (int i = 0; i < K; i++) {         cout << rem_ppws[i] <<    ;       }       cout << endl;       return 0;     }        // take 3 things from an >2 first, then take the others in pairs     int spec = -1;     if (K % 2 == 1) {       for (int id : ok_ids) {         if ((int) ppw[id].size() > 2) {           spec = id;           break;         }       }          for (int i = 0; i < 3; i++) {         cout << ppw[spec][i] <<    ;         K--;       }     }        for (int id : ok_ids) {       if (id != spec) {         if (K == 0) {           break;         }            for (int i = 0; i < 2; i++) {           cout << ppw[id][i] <<    ;           K--;         }       }     }     cout << endl;   }


#include <bits/stdc++.h>   const int INFI = (1 << 29);   const long long INFL = (1LL << 62);   using namespace std;   void solve() {     long long a, n, m;     cin >> a >> n >> m;     bitset<2010> rain;     vector<long long> v(m + 1);     vector<pair<long long, long long> > umb(a + 1, {INFL, 0});     for (long long i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       for (long long j = l; j <= r - 1; j++) rain[j] = 1;     }     for (long long i = 1; i <= m; i++) {       long long l, r;       cin >> l >> r;       v[i] = r;       umb[l] = min(umb[l], {r, i});     }     vector<vector<long long> > dp(a + 1, vector<long long>(m + 1, INFL));     dp[0][0] = 0;     for (long long i = 0; i < a; i++) {       for (long long j = 0; j <= m; j++) {         if (dp[i][j] == INFL) continue;         if (umb[i].first != INFL)           dp[i + 1][umb[i].second] =               min(dp[i + 1][umb[i].second], dp[i][j] + umb[i].first);         if (j) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + v[j]);         if (!rain[i]) dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);       }     }     long long r = *min_element(dp[a].begin(), dp[a].end());     if (r == INFL) r = -1;     cout << r <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> tree[1 << 20];   long long a[1 << 20], goal[1 << 20];   vector<long long> ans;   void dfs(long long v, long long cnt1 = 0, long long cnt2 = 0,            long long par = -1) {     for (long long i = 0; i < cnt1; i++) {       a[v] = !a[v];     }     if (goal[v] != a[v]) {       cnt1++;       ans.push_back(v);     }     for (long long i = 0; i < tree[v].size(); i++) {       if (tree[v][i] != par) dfs(tree[v][i], cnt2, cnt1, v);     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long temp, temp1;       cin >> temp >> temp1;       tree[temp].push_back(temp1);       tree[temp1].push_back(temp);     }     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> goal[i];     dfs(1);     cout << ans.size() <<   n ;     for (long long i = 0; i < ans.size(); i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int ara[100005];   int pri[100005];   vector<int> jog[2 * 100005], biyog[2 * 100005];   map<pair<int, int>, int> dp1, dp2;   int cnt1(int x, int y) {     if (y == m + 1) return x;     if (dp1.find({x, y}) != dp1.end()) return dp1[{x, y}];     int val = x - y + 100005;     int idx =         lower_bound(biyog[val].begin(), biyog[val].end(), y) - biyog[val].begin();     if (idx == biyog[val].size()) return dp1[{x, y}] = min(n, x + m + 1 - y);     int j = biyog[val][idx];     assert(j != y);     return dp1[{x, y}] = cnt1(ara[j], pri[j]);   }   int cnt2(int x, int y) {     if (y == m + 1) return x;     if (dp2.find({x, y}) != dp2.end()) return dp2[{x, y}];     int val = x + y;     int idx = lower_bound(jog[val].begin(), jog[val].end(), y) - jog[val].begin();     if (idx == jog[val].size()) return dp2[{x, y}] = max(1, x - m - 1 + y);     int j = jog[val][idx];     assert(j != y);     return dp2[{x, y}] = cnt2(ara[j], pri[j]);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , ara + i);     if (n == 1) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= m; i++) {       jog[ara[i] + i].push_back(i);       biyog[ara[i] - i + 100005].push_back(i);     }     for (int i = 0; i < 2 * 100005; i++) sort(jog[i].begin(), jog[i].end());     for (int i = 0; i < 2 * 100005; i++) sort(biyog[i].begin(), biyog[i].end());     for (int i = m; i; i--) {       if (ara[i] == ara[i + 1])         pri[i] = pri[i + 1];       else         pri[i] = i + 1;     }     long long ans = 0;     for (int i = 1; i < n; i++) ans += cnt1(i, 0) - i;     for (int i = 2; i <= n; i++) ans += i - cnt2(i, 0);     ans += n;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6, inf = 1e9 + 2;   pair<int, int> a[N + 2], b[N + 2], aa[N + 2], bb[N + 2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, c, d;     cin >> n >> c >> d;     int p = 0, q = 0;     for (int i = 1; i <= n; i++) {       int x, y;       char c;       cin >> x >> y >> c;       if (c ==  C )         a[++p] = {y, x};       else         b[++q] = {y, x};     }     sort(a + 1, a + p + 1);     sort(b + 1, b + q + 1);     for (int i = 1; i <= p; i++) aa[i] = a[i];     for (int i = 1; i <= q; i++) bb[i] = b[i];     for (int i = 1; i <= p; i++) a[i].second = max(a[i].second, a[i - 1].second);     for (int i = 1; i <= q; i++) b[i].second = max(b[i].second, b[i - 1].second);     int ans = 0;     for (int i = 2; i <= p; i++) {       int rm = c - a[i].first;       int id = upper_bound(a + 1, a + p + 1, make_pair(rm, inf)) - a;       id--;       if (id >= i) id = i - 1;       if (id > 0) ans = max(ans, aa[i].second + a[id].second);     }     for (int i = 2; i <= q; i++) {       int rm = d - b[i].first;       int id = upper_bound(b + 1, b + q + 1, make_pair(rm, inf)) - b;       id--;       if (id >= i) id = i - 1;       if (id > 0) ans = max(ans, bb[i].second + b[id].second);     }     int ad1 = -1, ad2 = -1;     for (int i = 1; i <= p; i++)       if (a[i].first <= c) ad1 = a[i].second;     for (int i = 1; i <= q; i++)       if (b[i].first <= d) ad2 = b[i].second;     if (ad1 != -1 && ad2 != -1) ans = max(ans, ad1 + ad2);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mp[5500][5500];   int sum[5500][5500];   const int INF = 0x3f3f3f3f;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , mp[i] + 1);     for (int i = 1; i <= n; ++i) {       int tot = 0;       for (int j = 1; j <= m; ++j) {         if (mp[i][j] ==  1 ) ++tot;         sum[i][j] = tot;       }     }     int mm = max(n, m), ans = INF;     for (int k = mm; k > 1; --k) {       bool fi = true;       int i, j, tj = k, ti = k, t0 = 0, t1 = 0, tans = 0;       for (i = 1; i <= ti; ++i) {         if (i > n || tj > m) {           if (i > n) fi = false;           if (i > n)             t0 += k;           else {             t1 += sum[i][m] - sum[i][tj - k];             t0 += k - (sum[i][m] - sum[i][tj - k]);           }         } else {           if (i == n) fi = false;           t1 += sum[i][tj] - sum[i][tj - k];           t0 += k - (sum[i][tj] - sum[i][tj - k]);         }         if (i == ti) {           tans += min(t0, t1);           t0 = 0, t1 = 0;         }         if (i == ti && tj < m) {           tj += k;           i = ti - k;         } else if (i == ti && fi && tj >= m) {           ti += k;           tj = k;         }       }       ans = min(ans, tans);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[5000];   vector<int> r[5000];   vector<int8_t> vis(5000);   int n, m, s;   void dfs(int src) {     vis[src] = true;     for (auto v : g[src]) {       if (!vis[v]) {         dfs(v);       }     }   }   int root(int src, vector<bool> &df) {     df[src] = true;     int c = 0;     for (int v : g[src]) {       if (!df[v] && !vis[v]) {         c += root(v, df) + 1;       }     }     return c;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> s;     --s;     for (int x, y, i = 0; i < m; ++i) {       cin >> x >> y;       g[--x].push_back(--y);       r[y].push_back(x);     }     dfs(s);     int ans = 0;     vector<pair<int, int>> sl;     for (int i = 0; i < n; ++i) {       if (!vis[i]) {         vector<bool> df(n);         int a = root(i, df);         sl.push_back({-a, i});       }     }     sort(sl.begin(), sl.end());     for (auto c : sl) {       if (!vis[c.second]) {         g[s].push_back(c.second);         dfs(s);         ++ans;       }     }     printf( %d n , ans);     return false & true;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     if (n % 5 == 0)       printf( %d , n / 5);     else       printf( %d , (n / 5) + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const long long inf = 0x3f3f3f3f3f3f;   long long a[3][maxn], dp[3][maxn];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n;     cin >> n;     for (int j = (1); j < (3); j++)       for (int i = (1); i < (n + 1); i++) {         cin >> a[j][i];       }     a[0][0] = a[1][0] = a[2][0] = inf;     for (int i = (1); i < (n + 1); i++) {       dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]);       dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i];       dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + a[2][i];     }     long long ans = 0;     for (int i = (0); i < (3); i++) ans = max(ans, dp[i][n]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N], b[N], len;   bool vis[N];   int xx(int x) {     if (x & 1)       return x / 2;     else       return x / 2 - 1;   }   int main() {     int t;     cin >> t;     while (t--) {       len = 0;       memset(vis, 0, sizeof vis);       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] >= 1 && a[i] <= n) {           if (!vis[a[i]])             vis[a[i]] = 1;           else             b[++len] = a[i];         } else {           b[++len] = a[i];         }       }       sort(b + 1, b + len + 1);       int j = len;       bool flag = 0;       for (int i = n; i > 0; i--) {         if (vis[i]) continue;         if (xx(b[j]) < i) {           flag = 1;           break;         } else {           j--;         }       }       if (flag)         cout << -1 << endl;       else         cout << len << endl;     }     return 0;   }