#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 113;   const double eps = 1e-7;   struct pt {     long double x, y;     int ind;     pt(long double x = 0, long double y = 0, int ind = 0)         : x(x), y(y), ind(ind) {}   };   long double dist(pt a, pt b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   int n;   pt a, b, t, rat[N];   pt mnA[2], mnB[2];   int used[N];   long double ans = 1000000000000, newAns;   bool cnt1(pt x, pt y) {     long double toX = sqrt(dist(a, x)) + sqrt(dist(t, y));     long double toY = sqrt(dist(a, y)) + sqrt(dist(t, x));     return (toX - toY < eps);   }   bool cnt2(pt x, pt y) {     long double toX = sqrt(dist(b, x)) + sqrt(dist(t, y));     long double toY = sqrt(dist(b, y)) + sqrt(dist(t, x));     return (toX - toY < eps);   }   int main() {     cout.precision(30);     cin >> a.x >> a.y >> b.x >> b.y >> t.x >> t.y;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> rat[i].x >> rat[i].y;       rat[i].ind = i;     }     sort(rat + 1, rat + n + 1, cnt1);     mnA[0] = rat[1];     mnA[1] = rat[2];     sort(rat + 1, rat + n + 1, cnt2);     mnB[0] = rat[1];     mnB[1] = rat[2];     if (n == 1) {       ans = min(sqrt(dist(a, rat[1])), sqrt(dist(b, rat[1]))) +             sqrt(dist(rat[1], t));       cout << ans;       return 0;     }     ans = sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t));     used[mnA[0].ind] = 1;     for (int i = 1; i <= n; i++) {       if (used[rat[i].ind]) continue;       ans += 2 * sqrt(dist(t, rat[i]));     }     memset(used, 0, sizeof(used));     newAns = sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t));     used[mnB[0].ind] = 1;     for (int i = 1; i <= n; i++) {       if (used[rat[i].ind]) continue;       newAns += 2 * sqrt(dist(t, rat[i]));     }     ans = min(ans, newAns);     memset(used, 0, sizeof(used));     newAns = sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t));     used[mnA[0].ind] = 1;     if (used[mnB[0].ind]) {       newAns += sqrt(dist(b, mnB[1])) + sqrt(dist(mnB[1], t));       used[mnB[1].ind] = 1;     } else {       newAns += sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t));       used[mnB[0].ind] = 1;     }     for (int i = 1; i <= n; i++) {       if (used[rat[i].ind]) continue;       newAns += 2 * sqrt(dist(t, rat[i]));     }     ans = min(ans, newAns);     memset(used, 0, sizeof(used));     newAns = sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t));     used[mnB[0].ind] = 1;     if (used[mnA[0].ind]) {       newAns += sqrt(dist(a, mnA[1])) + sqrt(dist(mnA[1], t));       used[mnA[1].ind] = 1;     } else {       newAns += sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t));       used[mnA[0].ind] = 1;     }     for (int i = 1; i <= n; i++) {       if (used[rat[i].ind]) continue;       newAns += 2 * sqrt(dist(t, rat[i]));     }     ans = min(ans, newAns);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, l, r, poss_rn, poss_rm, poss_n, poss_m, k, ans1, ans2;   priority_queue<tuple<long long, int, int>> pq;   map<pair<int, int>, bool> um;   long long f(int x, int y) {     long long a, b;     if (x == poss_rn)       a = poss_n;     else       a = 2;     if (y == poss_rm)       b = poss_m;     else       b = 2;     return a * b;   }   int main() {     cin >> n >> m >> r >> k;     if (n > m) swap(n, m);     poss_rn = min(r, n - r + 1);     poss_rm = min(r, m - r + 1);     ans2 = (n - r + 1) * (m - r + 1);     poss_n = n - 2 * (poss_rn - 1);     poss_m = m - 2 * (poss_rm - 1);     r++;     pq.push(make_tuple(poss_rn * poss_rm, poss_rn, poss_rm));     um[{poss_rn, poss_rm}] = true;     while (k) {       tie(m, i, j) = pq.top();       pq.pop();       l = f(i, j);       if (l != 0) {         if (k <= l) {           ans1 += k * m;           k = 0;         } else {           ans1 += l * m;           k -= l;         }       }       if (i != 1 && um[{i - 1, j}] == false) {         um[{i - 1, j}] = true;         pq.push(make_tuple((i - 1) * j, i - 1, j));       }       if (j != 1 && um[{i, j - 1}] == false) {         --j;         pq.push(make_tuple(i * j, i, j));         um[{i, j}] = true;       }     }     printf( %.9f , (double)ans1 / (double)ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 2000010;   int N, M;   int A[MXN], B[MXN], T[32] = {};   void init() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) scanf( %d , A + i);     for (int i = 1; i <= M; i++) scanf( %d , B + i), T[B[i]]++;   }   namespace solve {   long long answer = 0;   int sat[MXN], m = 0, p = 1;   void solve() {     for (int b = 30; b >= 0; b--) {       for (int i = 1; i <= N; i++) {         int x = min(T[b], A[i] >> b);         A[i] -= x << b;         T[b] -= x;         for (int i = 0; i < x; i++) sat[++m] = b;       }       while (T[b] && p <= m && sat[p] > b) {         A[++N] = 1 << sat[p++];         int x = min(T[b], A[N] >> b);         A[N] -= x << b;         T[b] -= x;         for (int i = 0; i < x; i++) sat[++m] = b;       }     }     cout << m - p + 1 << endl;   }   }  // namespace solve   int main() {     init();     solve::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000001];   int nodeNumber[1000001], nodeStart[1000001], nodeEnd[1000001],       leftStart[1000001], leftEnd[1000001], rightStart[1000001],       rightEnd[1000001];   void Initialise(int n) {     sort(a + 1, a + n + 1);     for (int i = 0; i <= n; ++i) {       nodeStart[i] = 0;       nodeEnd[i] = -1;       nodeNumber[i] = 1;     }     nodeStart[1] = 1;     nodeEnd[1] = n;   }   void FixStartEnd(int &i, int &j) {     if (i > j) {       i = 0, j = -1;     }   }   void FillChildNumbers(int n, int k) {     for (int i = 0; i <= n; ++i) {       int j = nodeStart[i];       for (; j <= nodeEnd[i] && (a[j] & (1ll << k)) == 0; ++j)         ;       leftStart[i] = nodeStart[i], leftEnd[i] = j - 1;       rightStart[i] = j, rightEnd[i] = nodeEnd[i];       FixStartEnd(leftStart[i], leftEnd[i]);       FixStartEnd(rightStart[i], rightEnd[i]);       j = (nodeStart[i] > 0) ? nodeEnd[i] : i;       nodeStart[i] = 0;       nodeEnd[i] = -1;       i = j;     }   }   long long ZeroBitCount(int n, int k) {     long long ans = 0;     for (int i = 1; i <= n; ++i) {       int targetBit = ((a[i] & (1ll << k)) > 0), j = nodeNumber[i];       ans += ((targetBit == 1) ? (rightEnd[j] - rightStart[j] + 1)                                : (leftEnd[j] - leftStart[j] + 1));     }     return ans;   }   void TakeZeroBit(int n, int k) {     for (int i = 1; i <= n; ++i) {       int targetBit = ((a[i] & (1ll << k)) > 0), j = nodeNumber[i], x, start, end;       if (targetBit) {         x = rightStart[j], start = rightStart[j], end = rightEnd[j];       } else {         x = leftStart[j], start = leftStart[j], end = leftEnd[j];       }       nodeNumber[i] = x, nodeStart[x] = start, nodeEnd[x] = end;     }   }   void TakeOneBit(int n, int k) {     for (int i = 1; i <= n; ++i) {       int targetBit = 1 - ((a[i] & (1ll << k)) > 0), j = nodeNumber[i], x, start,           end;       if (targetBit) {         x = rightStart[j], start = rightStart[j], end = rightEnd[j];       } else {         x = leftStart[j], start = leftStart[j], end = leftEnd[j];       }       nodeNumber[i] = x, nodeStart[x] = start, nodeEnd[x] = end;     }   }   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     for (int j = 2; j <= n; ++j) {       int i;       long long w;       scanf( %d%lld , &i, &w);       a[j] = (w ^ a[i]);     }     Initialise(n);     long long ans = 0;     for (int k = 61; k > -1; --k) {       FillChildNumbers(n, k);       long long cnt = ZeroBitCount(n, k);       if (cnt >= m) {         TakeZeroBit(n, k);       } else {         ans += (1ll << k);         m -= cnt;         TakeOneBit(n, k);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, s, p, i, c;     scanf( %d , &n);     s = 1;     while (1) {       c = 0;       p = n * s + 1;       for (i = 2; i < p; i++) {         if (p % i == 0) {           c++;         }       }       if (c >= 1) {         break;       }       s++;     }     printf( %d n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x, c1 = 0, c2 = 0;     bool flag = false;     cin >> n;     while (n--) {       cin >> x;       if (x == 100)         ++c1;       else         ++c2;     }     if (c1 % 2 == 0) {       if ((c1 == 0 && c2 % 2 == 0) || (c1 > 0)) flag = true;     }     if (flag) {       cout <<  YES ;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   const int MOD = 1000000007;   const int MOD1 = 998244353;   const int maxn = 100010;   const int lim = (int)1e9;   struct flowEdge {     int v, u;     lli cap, flow = 0ll;     flowEdge(int v, int u, lli cap) : v(v), u(u), cap(cap) {}   };   struct Dinic {     const lli flow_inf = 1e18;     vector<flowEdge> edges;     vector<vector<int> > adj;     int n, m = 0;     int s, t;     vector<int> level, ptr;     queue<int> q;     Dinic(int n, int s, int t) : n(n), s(s), t(t) {       adj.resize(n);       level.resize(n);       ptr.resize(n);     }     void addEdge(int v, int u, lli cap) {       edges.emplace_back(v, u, cap);       edges.emplace_back(u, v, 0);       adj[v].push_back(m);       adj[u].push_back(m + 1);       m += 2;     }     bool bfs() {       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto id : adj[v]) {           if (edges[id].cap - edges[id].flow < 1) continue;           if (level[edges[id].u] != -1) continue;           level[edges[id].u] = level[v] + 1;           q.push(edges[id].u);         }       }       return level[t] != -1;     }     lli dfs(int v, lli pushed) {       if (pushed == 0ll) return 0ll;       if (v == t) return pushed;       for (int &cid = ptr[v]; cid < (int)adj[v].size(); ++cid) {         int id = adj[v][cid];         int u = edges[id].u;         if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)           continue;         lli tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));         if (tr == 0ll) continue;         edges[id].flow += tr;         edges[id ^ 1].flow -= tr;         return tr;       }       return 0ll;     }     lli flow() {       lli f = 0ll;       while (true) {         fill(level.begin(), level.end(), -1);         level[s] = 0;         q.push(s);         if (!bfs()) break;         fill(ptr.begin(), ptr.end(), 0);         while (lli pushed = dfs(s, flow_inf)) f += pushed;       }       return f;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n = 0, m = 0, x = 0, y = 0, w = 0;     cin >> n >> m;     vector<pair<int, pair<int, int> > > v;     for (int i = 0; i < m; ++i) {       cin >> x >> y >> w;       --x;       --y;       v.push_back({w, {x, y}});     }     sort(v.begin(), v.end());     int l = n, r = m;     while (l != r) {       int mid = (l + r) / 2;       Dinic g(2 * n + 2, 2 * n, 2 * n + 1);       for (int i = 0; i < n; ++i) {         g.addEdge(2 * n, i, 1);         g.addEdge(n + i, 2 * n + 1, 1);       }       for (int i = 0; i <= mid; ++i)         g.addEdge(v[i].second.first, n + v[i].second.second, 1);       if (g.flow() == n)         r = mid;       else         l = mid + 1;     }     if (l >= m)       cout <<  -1 ;     else       cout << v[l].first;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, t;     cin >> n >> t;     vector<int> books(n);     for (int i = 0; i < n; i++) {       cin >> books[i];     }     int i, j;     i = 0, j = 0;     int ac = 0;     int ans = 0;     while (i < n) {       if (i > j) j = i;       while (ac < t && j < n) {         ac += books[j];         j++;       }       ans = max(ans, (j - (ac > t)) - i);       ac -= books[i];       i++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int ans, a[5010], K, n;   map<int, int> g;   int main() {     int i, j, k, ca = 0, m;     scanf( %d%d , &n, &K);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++)       for (j = 1; j <= K; j++) {         int first = a[i] * j;         if (!g.count(first))           g[first] = j;         else           g[first] = min(g[first], j);       }     scanf( %d , &m);     while (m--) {       int first;       scanf( %d , &first);       if (first < a[0]) {         puts( -1 );         continue;       } else {         int ans = K + 1;         if (g.count(first)) ans = min(ans, g[first]);         for (i = 0; i < n; i++) {           if (a[i] > first) break;           int second = min(K, first / a[i]);           for (j = 1; j < second; j++) {             int rem = first - j * a[i];             if (g.count(rem)) ans = min(ans, j + g[rem]);           }         }         if (ans >= K + 1) ans = -1;         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double tiaohe = 0.57721566490153286060651209;   long long oula(long long x) {     long long res = x;     for (register int i = 2; i <= x / i; ++i) {       if (x % i == 0) {         res = res / i * (i - 1);         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res / x * (x - 1);     return res;   }   long long quickmod(long long a, long long n, long long m) {     long long s = 1;     while (n) {       if (n & 1) {         s = s * a % m;       }       a = (a * a) % m;       n = n / 2;     }     return s;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void ex_gcd(long long a, long long b, long long &x, long long &y,               long long &d) {     if (!b) {       d = a, x = 1, y = 0;     } else {       ex_gcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   long long inv(long long t, long long p) {     long long d, x, y;     ex_gcd(t, p, x, y, d);     return d == 1 ? (x % p + p) % p : -1;   }   bool isPrime(long long x) {     if (x == 2) return true;     if (x % 2 == 0) return false;     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   double eqa = (1 + sqrt(5.0)) / 2.0;   const int N = 6e5 + 5;   int t;   int main() {     cin >> t;     long long n, w;     while (t--) {       cin >> n >> w;       set<long long> st;       long long x, y;       long long mx = 0;       for (register int i = 1; i <= n; ++i) {         scanf( %lld%lld , &x, &y);         mx = max(mx, x);         if (x - y > 0) st.insert(x - y);       }       if (st.empty()) {         if (mx >= w)           puts( 1 );         else           puts( -1 );       } else {         auto it = st.end();         it--;         cout << (long long)ceil((max(w - mx, (long long)0)) * 1.0 / (*it)) + 1              << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ans[100000];   int main() {     long long int n, m, mx, mn, i, j, k, diff, flag = 0, flag1 = 0, flag2 = 0;     cin >> n >> m >> mn >> mx;     long long int arr[m + 5];     for (i = 0; i < m; i++) {       cin >> arr[i];       if (arr[i] == mn) flag1 = 1;       if (arr[i] == mx) flag2 = 1;       if (arr[i] < mn || arr[i] > mx) flag = 1;     }     diff = n - m;     if (flag == 1)       cout <<  Incorrect  << endl;     else if (flag1 == 1 && flag2 == 1)       cout <<  Correct  << endl;     else if (flag1 == 1 && diff >= 1 || flag2 == 1 && diff >= 1)       cout <<  Correct  << endl;     else if (flag1 == 0 && flag2 == 0 && diff >= 2)       cout <<  Correct  << endl;     else       cout <<  Incorrect  << endl;     return 0;   }


#include<bits/stdc++.h>   #define int long long   #define ld long double   #define fi first   #define se second   #define vll vector<int>   #define pii pair<int,int>   #define pb push_back   #define sz(v) (int)(v).size()   #define inf (int)(1e18)   #define md (int)(998244353)   #define all(v) (v).begin(),(v).end()   #define rep(i,a,b) for(int i=a;i<b;++i)   using namespace std;      const int M = 1e6 + 10;      int ans[M],d[M];      int32_t main(){       ios_base::sync_with_stdio(false);       cin.tie(0);              rep(i,1,M)for(int j=i;j<M;j+=i) d[j]++;              ans[1]=1,ans[2]=3;       int sum=4;       rep(i,3,M) {        ans[i]=(sum+d[i])%md;        (sum+=ans[i])%=md;       }       int n;       cin>>n;       cout<<ans[n];              return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   struct node {     int u, v, val;   } ans[maxn * 10];   std::vector<int> g[maxn];   int n, tot;   int in[maxn];   int x[maxn], y[maxn], val[maxn];   void addedge(int u, int v, int val) { ans[++tot] = (node){u, v, val}; }   void find(int u, int fa, int &x3, int &x4) {     if (g[u].size() == 1) {       if (x3 == 0)         x3 = u;       else         x4 = u;       return;     } else       for (int i = 0; i < g[u].size(); i++) {         if (g[u][i] == fa) continue;         find(g[u][i], u, x3, x4);       }   }   int main() {     scanf( %d , &n);     if (n == 2) {       printf( YES n1 n );       int x, y, k;       scanf( %d%d%d , &x, &y, &k);       printf( %d %d %d n , x, y, k);       return 0;     }     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &x[i], &y[i], &val[i]);       g[x[i]].push_back(y[i]);       g[y[i]].push_back(x[i]);       in[x[i]]++;       in[y[i]]++;     }     for (int i = 1; i <= n; i++)       if (in[i] == 2) return !printf( NO n );     printf( YES n );     for (int k = 1; k < n; k++) {       if (in[x[k]] > in[y[k]]) swap(x[k], y[k]);       if (in[x[k]] == 1) {         int x4 = 0, x1 = 0, x2 = 0, x5 = 0, x3 = 0;         x1 = y[k];         x3 = x[k];         find(x1, x3, x4, x5);         addedge(x3, x4, val[k] / 2);         addedge(x3, x5, val[k] / 2);         addedge(x4, x5, -val[k] / 2);       } else {         int x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0;         x1 = x[k];         x2 = y[k];         find(x1, x2, x3, x4);         find(x2, x1, x5, x6);         addedge(x3, x5, val[k] / 2);         addedge(x4, x6, val[k] / 2);         addedge(x3, x4, -val[k] / 2);         addedge(x5, x6, -val[k] / 2);       }     }     printf( %d n , tot);     for (int i = 1; i <= tot; i++) {       printf( %d %d %d n , ans[i].u, ans[i].v, ans[i].val);     }   }


#include <bits/stdc++.h>   using namespace std;   char yam[1 << 23];   int main() {     long long b, n, c;     gets(yam);     char *bp = yam;     char *np = strchr(bp,    ) + 1;     char *cp = strchr(np,    ) + 1;     c = atoi(cp);     for (b = 0; isdigit(*bp); bp++) {       b = (10 * b + (*bp -  0 )) % c;     }     long long res = (b - 1 + c) % c;     int carry = 1;     for (np = cp - 2; isdigit(*np); np--) {       int cur = *np -  0  - carry;       if (cur < 0) {         cur += 10;         carry = 1;       } else         carry = 0;       while (cur--) {         res = (res * b) % c;       }       long long oldb = b;       for (int i = 0; i < 9; i++) {         b = (b * oldb) % c;       }     }     cout << (res ?: c);     return 0;   }


/********   All Required Header Files ********/   #include <iostream>   #include <string>   #include <vector>   #include <algorithm>   #include <sstream>   #include <queue>   #include <deque>   #include <bitset>   #include <iterator>   #include <list>   #include <stack>   #include <map>   #include <set>   #include <functional>   #include <numeric>   #include <utility>   #include <limits>   #include <time.h>   #include <math.h>   #include <stdio.h>   #include <string.h>   #include <stdlib.h>   #include <assert.h>      using namespace std;   /*******  All Required define Pre-Processors and typedef Constants *******/   #define ll long long int   #define ull unsigned long long int   #define li long int   #define uli unsigned long int   #define MOD 1e10+7   #define all(a) a.begin(),a.end()   #define FOR(i,j,k,l) for(int i=j;i<k;i+=l)   #define RFOR(i,j,k,l) for(int i=j;i>=k;i-=l)   #define REP(i,j) FOR(i,0,j,1)   #define RREP(i,j) FOR(i,j,0,1)   #define PB push_back   #define _finout ios::sync_with_stdio(0);cin.tie(0)   typedef vector<int> VI;   typedef vector<char> VC;   typedef vector<string> VS;   typedef vector<VI> VVI;   typedef vector<ll> VL;   typedef set<int> SETI;   typedef map<int,int> MPII;   typedef multiset<int> MSETI;   // const int N = (int)(2*1e5 +10);   long long sq(int x){return 1ll * x*x;}   // ll dp[N];   // ll lev[N];   // VL adj[N];   bool isprime(long long int num){       for(long long int i=2;i<=sqrt(num);i++){           if (num%i == 0) return false;       }       return true;   }   vector<int> check(int n,vector<int>a,int x){       MSETI s;       for(auto e:a) s.insert(e);       vector<int> res;       for(int i=0;i<n;i++){           auto it1 = s.end();           it1--;           int y = x - *it1;           s.erase(it1);           auto it2 = s.find(y);           if(it2==s.end()) return {};           res.push_back(x-y);           res.push_back(y);           x = max(x-y,y);           s.erase(it2);       }       return res;   }   void solve()   {       int n;       cin >> n;       vector<int> a(2 * n);       for (int i = 0; i < 2 * n; i++)           cin >> a[i];       sort(a.begin(), a.end());       for (int i = 0; i < 2 * n - 1; i++)       {           int x = a[i] + a[2 * n - 1];           vector<int> res = check(n, a, x);           if (res.size())           {               cout <<  YES n ;               cout << x <<   n ;               for (int j = 0; j < n; j++)               {                   cout << res[2 * j] <<     << res[2 * j + 1] <<   n ;               }               return;           }       }       cout <<  NO n ;   }   int main(){       _finout;       int T;       cin>>T;       while(T--){           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   void file() {}   const long long nax = 2e5 + 1, mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     file();     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       n *= 3;       vector<int> vis(n + 1), cnt(n + 1);       pair<int, int> p[m + 1];       map<pair<int, int>, int> mapp;       for (long long i = 1; i <= m; i++) {         cin >> p[i].first >> p[i].second;         cnt[p[i].first]++;         cnt[p[i].second]++;         mapp[make_pair(p[i].first, p[i].second)] = i;       }       vector<pair<int, pair<int, int> > > v;       for (long long i = 1; i <= m; i++) {         v.push_back(make_pair(cnt[p[i].first] + cnt[p[i].second],                               make_pair(p[i].first, p[i].second)));       }       sort(v.begin(), v.end());       vector<int> ans1, ans2;       for (auto it : v) {         if (!vis[it.second.first] && !vis[it.second.second])           ans1.push_back(mapp[make_pair(it.second.first, it.second.second)]),               vis[it.second.first] = true, vis[it.second.second] = true;       }       for (long long i = 1; i <= n; i++) {         if (!vis[i]) ans2.push_back(i);       }       if (ans1.size() >= n / 3) {         cout <<  Matching               <<   n ;         int ct = n / 3;         for (auto it : ans1) {           ct--;           cout << it <<    ;           if (ct == 0) break;         }       } else {         cout <<  IndSet               <<   n ;         int ct = n / 3;         for (auto it : ans2) {           ct--;           cout << it <<    ;           if (ct == 0) break;         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ans = 0;     long long total;     long long tleft = 0;     long long tright = 0;     vector<pair<long long, long long> > soldier;     for (long long i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       soldier.push_back(make_pair(a, b));       tleft += a;       tright += b;     }     total = abs(tleft - tright);     for (long long i = 0; i < n; i++) {       tleft -= soldier[i].first;       tleft += soldier[i].second;       tright -= soldier[i].second;       tright += soldier[i].first;       if (total < abs(tleft - tright)) {         total = abs(tleft - tright);         ans = i + 1;       }       tleft += soldier[i].first;       tleft -= soldier[i].second;       tright += soldier[i].second;       tright -= soldier[i].first;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN();   map<string, int> d;   int main() {     d[ void ] = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       string a, b, c;       cin >> a;       if (a ==  typedef ) {         cin >> b >> c;         int k1 = 0, k2 = b.size() - 1, m = 0;         while (k1 < b.size() && b[k1] ==  & ) k1++, m--;         while (k2 >= 0 && b[k2] ==  * ) k2--, m++;         string t = b.substr(k1, k2 - k1 + 1);         if (!d.count(t) || d[t] == -1 || d[t] + m < 0)           d[c] = -1;         else           d[c] = d[t] + m;       } else {         cin >> b;         int k1 = 0, k2 = b.size() - 1, m = 0;         while (k1 < b.size() && b[k1] ==  & ) k1++, m--;         while (k2 >= 0 && b[k2] ==  * ) k2--, m++;         string t = b.substr(k1, k2 - k1 + 1);         if (!d.count(t) || d[t] == -1 || d[t] + m < 0)           printf( errtype n );         else {           printf( void );           int l = d[t];           for (int j = 0; j < l + m; j++) printf( * );           printf(  n );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool f[300010];   map<pair<int, int>, int> mp;   vector<int> g[300010];   long long nm[300010], kk[300010], x, y, p;   long long ans, n, i;   void go(int now) {     f[now] = 1;     for (int i = 0; i < g[now].size(); i++)       if (!f[g[now][i]])         if (nm[now] + nm[g[now][i]] - mp[make_pair(now, g[now][i])] < p &&             p <= nm[now] + nm[g[now][i]])           ans -= 2;     for (int i = 0; i < g[now].size(); i++)       if (!f[g[now][i]]) go(g[now][i]);   }   int main() {     cin >> n >> p;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       mp[make_pair(x, y)]++;       mp[make_pair(y, x)]++;       if (mp[make_pair(x, y)] == 1) {         g[x].push_back(y);         g[y].push_back(x);       }       nm[x]++;       nm[y]++;     }     for (i = 1; i <= n; i++)       if (2 * nm[i] >= p) ans--;     for (i = 1; i <= n; i++) kk[nm[i]]++;     for (i = 300000; i >= 0; i--) kk[i] += kk[i + 1];     for (i = 1; i <= n; i++) ans += kk[max(0LL, p - nm[i])];     for (i = 1; i <= n; i++)       if (!f[i]) go(i);     cout << ans / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     set<long long> v;     set<long long>::iterator j;     for (long long i = 1; i <= pow(n, 0.5); i++) {       if (n % i == 0) {         long long x = n / i;         v.insert((x * (2 + (x - 1) * i)) / 2);         v.insert((i * (2 + (i - 1) * x)) / 2);       }     }     for (j = v.begin(); j != v.end(); j++) {       cout << *j <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline int dcmp(double a, double b) {     return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1;   }   const int N = 1000 + 9;   int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};   int ans[N];   vector<vector<int> > g;   int x[N];   bitset<N> del;   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       int n;       scanf( %d , &n);       for (auto i = 0; i < n; ++i) scanf( %d , x + i);       for (int cnt = 0, p = 0; cnt != n; p++) {         g.emplace_back(vector<int>());         for (auto i = 0; i < n; ++i)           if (!del[i] && x[i] % pr[p] == 0)             del[i] = 1, g.back().emplace_back(i), cnt++;         if (g.back().empty()) g.pop_back();       }       for (auto i = 0; i < ((int)((g).size())); ++i)         for (auto j = 0; j < ((int)((g[i]).size())); ++j) ans[g[i][j]] = i;       printf( %d n , ((int)((g).size())));       for (auto i = 0; i < n; ++i) printf( %d  , ans[i] + 1);       puts(  );       del.reset();       g.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     int n, m, x, y, a, b;     while (cin >> n >> m >> x >> y >> a >> b) {       int g = gcd(a, b);       a /= g;       b /= g;       g = min(n / a, m / b);       a *= g;       b *= g;       int lx = max(0, x - (a + 1) / 2);       int ly = max(0, y - (b + 1) / 2);       int rx = lx + a;       int ry = ly + b;       if (rx > n) {         lx -= rx - n;         rx = n;       }       if (ry > m) {         ly -= ry - m;         ry = m;       }       if (lx > rx) swap(lx, rx);       if (ly > ry) swap(ly, ry);       cout << lx <<     << ly <<     << rx <<     << ry << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > a;   vector<long long> bus;   long long n, t, z;   int main() {     cin >> n >> t;     for (int i = 0; i < n; i++) {       cin >> z;       t -= z;     }     if (t > n - 1 || t < n - 1) {       cout <<  NO ;     } else       cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     cin >> n >> d;     int a[n];     int x = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       x += a[i];     }     if (x + (n - 1) * 10 > d) {       cout << -1;     } else {       cout << 2 * n - 2 + (d - x - (n - 1) * 10) / 5;     }   }


#include <bits/stdc++.h>   using namespace std;   long long arr[1000000], pref[1000000], suf[1000000];   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i];     long long mini = 1e18;     for (long long i = 0, j = 0; i < n; i = j) {       for (; j < n && arr[j] == arr[i]; j++)         ;       long long dif = j - i;       if (dif >= k) {         cout << 0;         return 0;       }       long long l = ((arr[i] - 1) * i) - pref[i],                 r = pref[n] - pref[j] - ((arr[i] + 1) * (n - j));       if (i + dif >= k && mini > l + k - dif) mini = l + k - dif;       if (dif + n - j >= k && mini > r + k - dif) mini = r + k - dif;       if (mini > l + r + k - dif) mini = l + r + k - dif;     }     cout << mini;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long INF64 = 1e18;   const int INF32 = 1e9;   const int MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       int x;       cin >> x;       string s = to_string(x);       set<char> st;       for (char &c : s) st.insert(c);       int sqrtX = sqrt(x), res = 0;       for (int i = (1); i <= (sqrtX); i++)         if (x % i == 0) {           s = to_string(i);           for (char &c : s)             if (st.count(c)) {               res++;               break;             }           int j = x / i;           if (j == i) break;           s = to_string(x / i);           for (char &c : s)             if (st.count(c)) {               res++;               break;             }         }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   void fix_mod(ll &v, ll M) { v = ((v - 1) % M + M) % M + 1; }   int main() {     int N;     ll M;     ll T;     cin >> N >> M >> T;     vii Si(N, {0LL, 0LL});     vi pos(N, 0LL);     ll shift = 0;     for (int i = 0; i < N; i++) {       ll x;       char c;       cin >> x >> c;       ll slope = (c ==  L  ? -1 : 1);       ll ic = (slope == 1 ? 1 - x : x);       shift += ((T / M) % N) * slope;       fix_mod(ic, M);       if (ic <= T % M) shift += slope;       Si[i] = {x, i};       pos[i] = x + (T % M) * slope;       fix_mod(pos[i], M);     }     sort(Si.begin(), Si.end());     sort(pos.begin(), pos.end());     fix_mod(shift, N);     vi ans(N, 0LL);     for (int i = 0; i < N; i++) ans[Si[i].second] = pos[(i + shift) % N];     for (int i = 0; i < N - 1; i++) cout << ans[i] <<    ;     cout << ans[N - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int k, h;     k = a[n - 1] - a[1];     h = a[n - 2] - a[0];     if (k > h) {       cout << h;     } else {       cout << k;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r[10005];   struct N {     int l, r, x;   } p[10005];   bool cmp(N a, N b) { return a.l < b.l; }   bool vis[10005];   int main() {     int n, q;     cin >> n >> q;     memset(vis, 0, sizeof vis);     for (int i = 0; i < q; i++) {       cin >> p[i].l >> p[i].r >> p[i].x;     }     sort(p, p + q, cmp);     for (int i = 0; i < q; i++) {       for (int j = n - p[i].x; j >= 0; j--) {         if (r[j] >= p[i].l)           vis[j + p[i].x] = 1,                   r[j + p[i].x] = max(r[j + p[i].x], min(p[i].r, r[j]));       }       r[p[i].x] = max(r[p[i].x], p[i].r);       vis[p[i].x] = 1;     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if (vis[i]) cnt++;     cout << cnt << endl;     for (int i = 1; i <= n; i++) {       if (vis[i]) {         if (i == n)           cout << i << endl;         else           cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct nod {     int x, y;   } num[110000];   struct nod2 {     int qian, zhi;   } bian[110000];   struct nod3 {     int ls, rs, l, r, mi;   } t[410000];   int n, p, a, b, mi, i, x[110000], wei[410000], use[110000], use2[110000],       w[110000];   int build(int l, int r) {     int mid, k;     k = ++p;     mid = (l + r) / 2;     t[k].mi = 10000000;     t[k].l = l;     t[k].r = r;     if (l == r) return (k);     t[k].ls = build(l, mid);     t[k].rs = build(mid + 1, r);     return (k);   }   bool cmp(nod a, nod b) {     if (a.x != b.x) return (a.x > b.x);     return (a.y > b.y);   }   void build2(int d, int a) {     p++;     bian[p].qian = wei[d];     bian[p].zhi = a;     wei[d] = p;   }   int qiu(int d, int l, int r) {     int mid;     if (l <= t[d].l && r >= t[d].r) return (t[d].mi);     mid = (t[d].l + t[d].r) / 2;     if (l > mid) return (qiu(t[d].rs, l, r));     if (r <= mid) return (qiu(t[d].ls, l, r));     return (min(qiu(t[d].ls, l, mid), qiu(t[d].rs, mid + 1, r)));   }   void jia(int d, int a, int b) {     int mid;     if (t[d].l == t[d].r) {       t[d].mi = min(t[d].mi, b);       return;     }     mid = (t[d].l + t[d].r) / 2;     if (a <= mid) jia(t[d].ls, a, b);     if (a > mid) jia(t[d].rs, a, b);     t[d].mi = min(t[t[d].ls].mi, t[t[d].rs].mi);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &num[i].x, &num[i].y);       use[i] = num[i].y - num[i].x;     }     for (i = 1; i <= n; i++) {       scanf( %d , &w[i]);       use2[i] = w[i];     }     sort(use + 1, use + 1 + n);     sort(use2 + 1, use2 + 1 + n);     for (i = 1; i <= n; i++)       if (use[i] != use2[i]) {         printf( No n );         return (0);       }     build(0, 100000);     p = 0;     for (i = 1; i <= n; i++) build2(w[i] + 110000, i);     sort(num + 1, num + 1 + n, cmp);     for (i = 1; i <= n; i++) {       a = 110000 + num[i].y - num[i].x;       b = wei[a];       mi = qiu(1, num[i].y, 100000);       if (bian[b].zhi > mi) {         printf( No n );         return (0);       }       jia(1, num[i].y, bian[b].zhi);       x[bian[b].zhi] = i;       wei[a] = bian[b].qian;     }     printf( Yes n );     for (i = 1; i <= n; i++) printf( %d %d n , num[x[i]].x, num[x[i]].y);   }


#include <bits/stdc++.h>   using namespace std;   long long m, l, r, k, n;   long long a[2][2], b[2][2];   void cc(long long a[2][2], long long b[2][2]) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) a[i][j] = b[i][j];   }   void mul(long long a[2][2], long long b[2][2], long long m) {     long long c[2][2];     memset(c, 0, sizeof(c));     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k < 2; k++) c[i][j] += a[i][k] * b[k][j], c[i][j] %= m;     cc(a, c);   }   void mi(long long a[2][2], long long n, long long m) {     long long y[2][2];     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) y[i][j] = 0;     y[0][0] = 1;     y[1][1] = 1;     while (n > 0) {       if (n % 2 == 1) mul(y, a, m);       n = n / 2;       mul(a, a, m);     }     cc(a, y);   }   int main() {     cin >> m >> l >> r >> k;     n = -1;     for (long long i = k;; i++) {       long long x = r / i;       long long y = r / x;       long long z = (l - 1) / x;       if (x <= 1000000) break;       if (y - z >= k) {         n = x;         break;       }     }     if (n == -1)       for (long long i = 1000000; i >= 1; i--) {         long long y = r / i;         long long z = (l - 1) / i;         if (y - z >= k) {           n = i;           break;         }       }     a[0][1] = 1;     a[1][0] = 1;     a[1][1] = 1;     b[0][1] = 1;     b[0][0] = 1;     mi(a, n - 2, m);     mul(b, a, m);     cout << b[0][1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int total;     cin >> total;     while (total--) {       int n, k, cont_l = 0, cont_r = 0;       vector<pair<int, int> > ans;       string s;       cin >> n >> k;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if ((i + 2) / 2 < k) {           if (i % 2 == 0) {             if (s[i] !=  ( ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ( ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           } else {             if (s[i] !=  ) ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ) ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           }         } else {           int cont = (n - (k - 1) * 2);           if (cont_l < cont) {             if (s[i] !=  ( ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ( ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           } else {             if (s[i] !=  ) ) {               for (int j = i + 1; j < s.size(); j++) {                 if (s[j] ==  ) ) {                   ans.push_back(make_pair(i, j));                   int l = i, r = j;                   while (l < r) {                     swap(s[l], s[r]);                     l++;                     r--;                   }                   break;                 }               }             }           }         }       }       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); i++) {         cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e18;   const long long minN = -1e18;   const long long MOD = 1e9 + 7;   const long long MOD1 = 998244353;   const int baseHash = 331;   const int bigNumLength = 5000;   const long double PI = acos(-1);   const long long limit = 2e5 + 5;   const long long limit1 = 1e6 + 5;   const long long limit2 = 1e3 + 5;   pair<long long, long long> dir[] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},                                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   int n, m;   map<int, bool> check[limit];   set<int> s;   int root[limit];   int cur[limit];   int d = 0;   bool compo[limit];   long long ans = 0;   int findRoot(int u) { return (root[u] < 0) ? u : findRoot(root[u]); }   void mergeRoot(int u, int v) {     u = findRoot(u);     v = findRoot(v);     if (u == v) return;     if (root[u] > root[v]) swap(u, v);     root[u] += root[v];     root[v] = u;   }   void solveProblem() {     queue<int> q;     vector<int> cur;     memset(root, -1, sizeof(root));     for (int i = (1); i <= (n); ++i) s.insert(i);     for (int i = (1); i <= (n); ++i) {       if (s.count(i)) {         s.erase(i);         q.push(i);         ++ans;         while (!q.empty()) {           int u = q.front();           q.pop();           for (auto it : s) {             if (check[it][u]) continue;             cur.push_back(it);             mergeRoot(u, it);             q.push(it);           }           for (auto it : cur) s.erase(it);           cur.clear();         }       }     }     cout << ans - 1 <<   n ;   }   void fastInput() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void readInput() {     cin >> n >> m;     for (int i = (1); i <= (m); ++i) {       int u, v;       cin >> u >> v;       check[u][v] = true;       check[v][u] = true;     }   }   int main() {     fastInput();     readInput();     solveProblem();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 10, N = 2e6 + 10, mod = 1e9 + 7, LG = 20, SQ = 450;   long long n, T[N], L[N], dp[N], ps[N];   inline void KMP(string s) {     long long k = -1;     T[0] = -1;     for (int i = 1; i < s.size(); i++) {       while (k != -1 and s[k + 1] != s[i]) k = T[k];       if (s[k + 1] == s[i]) k++;       T[i] = k;     }   }   string s, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> t;     n = s.size();     KMP(t +  #  + s);     for (int i = t.size() + 1; i < s.size() + t.size() + 1; i++)       T[i - t.size() - 1] = T[i] + 1;     L[0] = -1;     for (int i = 0; i < n; i++) {       L[i + 1] = L[i];       if (T[i] == t.size()) L[i + 1] = i - t.size() + 1;     }     dp[0] = 1;     ps[0] = 1;     for (int i = 1; i <= n; i++) {       dp[i] = dp[i - 1];       if (L[i] > -1) dp[i] = (ps[L[i]] + dp[i]) % mod;       ps[i] = (ps[i - 1] + dp[i]) % mod;     }     cout << ((dp[n] + mod - 1) % mod);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     if (m == 3 && n >= 5) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       cout << i <<     << i * i + 10000000 << endl;     }     for (int i = 1; i <= n - m; i++) {       cout << i <<     << -i * i - 10000000 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int n, d, a[N], dp[N * 10005], gao[N * 10005];   vector<int> v;   int main() {     int sum = 0;     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     dp[0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = sum; j >= a[i]; j--) {         dp[j] |= dp[j - a[i]];       }     }     for (int i = 0; i <= sum; i++) {       if (dp[i]) v.push_back(i);     }     memset(gao, 0x11, sizeof(dp));     int now = 0, step = 0;     while (true) {       if (now == v.size() - 1) break;       int nxt = now;       while (nxt + 1 < v.size() && v[nxt + 1] - v[now] <= d) nxt++;       if (nxt == now) break;       now = nxt;       step++;     }     cout << v[now] <<     << step << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   long long arr[200010];   long long factorial[200010];   long long factinv[200010];   long long fact[200010];   long long ans;   long long pw(long long a, long long b) {     a %= 1000000007;     if (b == 0) {       return 1ll;     }     if (b == 1) {       return a;     }     long long res = pw(a, b / 2);     if (b % 2) {       return (((res * res) % 1000000007) * a) % 1000000007;     }     return (res * res) % 1000000007;   }   long long inv(long long a) { return pw(a, 1000000007 - 2); }   long long choose(long long a, long long b) {     return ((factorial[a] * factinv[b] % 1000000007) * factinv[a - b]) %            1000000007;   }   int32_t main() {     ios_base::sync_with_stdio(false);     if (fopen( cf815b.in ,  r )) {       freopen( cf815b.in ,  r , stdin);       freopen( cf815b.out ,  w , stdout);     }     cin >> N;     for (int i = 0; i < N; i++) {       cin >> arr[i];       arr[i] %= 1000000007;     }     factorial[0] = 1;     for (int i = 1; i <= N; i++) {       factorial[i] = factorial[i - 1] * i;       factorial[i] %= 1000000007;     }     for (int i = 0; i <= N; i++) {       factinv[i] = inv(factorial[i]);     }     if (N % 4 == 0) {       long long choosev = (N - 2) / 2;       for (int i = 0; i < N; i++) {         fact[i] = choose(choosev, i / 2);         if (i % 2) {           fact[i] *= (1000000007 - 1);         }         fact[i] %= 1000000007;       }     }     if (N % 4 == 1) {       long long choosev = (N - 1) / 2;       for (int i = 0; i < N; i += 2) {         fact[i] = choose(choosev, i / 2);       }     }     if (N % 4 == 2) {       long long choosev = (N - 2) / 2;       for (int i = 0; i < N; i++) {         fact[i] = choose(choosev, i / 2);       }     }     if (N % 4 == 3) {       long long choosev = (N - 3) / 2;       fact[0] = 1;       fact[N - 1] = 1000000007 - 1;       for (int i = 1; i < N - 1; i++) {         if (i % 2) {           fact[i] = choose(choosev, (i - 1) / 2) + choose(choosev, (i - 1) / 2);         } else {           fact[i] = choose(choosev, (i / 2)) - choose(choosev, (i - 1) / 2);         }         fact[i] %= 1000000007;         fact[i] += 1000000007;         fact[i] %= 1000000007;       }     }     for (int i = 0; i < N; i++) {       cerr << fact[i] <<    ;       ans += fact[i] * arr[i];       ans %= 1000000007;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct seg {     int l, r, i;     bool operator<(const seg& b) const { return l < b.l; }   };   int n, k;   seg a[200005];   bool u[400005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i].l >> a[i].r, a[i].i = i;     sort(a, a + n);     set<pair<int, int>> pq;     for (int i = 0; i < k; i++) pq.insert({0, n + i});     for (int i = 0; i < n; i++) {       auto it = pq.lower_bound({a[i].l, -1});       if (it == pq.begin()) {         it = --pq.end();         if (a[i].r < it->first) {           u[it->second] = 1;           pq.erase(it);           pq.insert({a[i].r, a[i].i});         } else {           u[a[i].i] = 1;         }       } else {         --it;         pq.erase(it);         pq.insert({a[i].r, a[i].i});       }     }     cout << count(u, u + n, 1) <<   n ;     for (int i = 0; i < n; i++)       if (u[i]) cout << i + 1 <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n / 2 << endl;     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++) {         cout <<  2  ;       }     } else {       for (int i = 0; i < n / 2 - 1; i++) {         cout <<  2  ;       }       cout << 3;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e3 + 10;   int n;   int a[N], b[N];   long long dp[N][N];   long long solve(int idx = 0, int val = 0) {     if (idx == n) return 0;     if (val == n) return 1e18;     long long &ret = dp[idx][val];     if (ret == -1)       ret = min(solve(idx + 1, val) + abs(a[idx] - b[val]), solve(idx, val + 1));     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       b[i] = a[i] -= i;     }     sort(b, b + n);     memset(dp, -1, sizeof(dp));     printf( %lld n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ans, s;     int n, t, p;     char ch;     scanf( %d , &n);     ans.clear();     for (int i = 1; i <= n; i++) {       t = i;       s.clear();       while (t > 0) {         p = t % 10;         ch = p +  0 ;         s = ch + s;         t = t / 10;       }       ans = ans + s;     }     cout << ans[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, zhan[100500], tree[100500], o, ans[100500], now = 1;   struct edge {     int x, t, id, r;     bool operator<(const edge &xx) const {       if (x != xx.x) return x < xx.x;       return id < xx.id;     }   } aa[100500];   void add(int x, int y) {     for (int i = x; i <= n; i += (i & (-i))) tree[i] += y;   }   int get(int x) {     int ans = 0;     for (int i = x; i >= 1; i -= (i & (-i))) ans += tree[i];     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &aa[i].r, &aa[i].t, &aa[i].x);       aa[i].id = i;       zhan[++o] = aa[i].t;     }     sort(zhan + 1, zhan + o + 1);     o = unique(zhan + 1, zhan + o + 1) - zhan - 1;     for (int i = 1; i <= n; i++) {       aa[i].t = lower_bound(zhan + 1, zhan + o + 1, aa[i].t) - zhan;     }     sort(aa + 1, aa + n + 1);     memset(ans, -1, sizeof(ans));     for (int i = 1; i <= n; i++) {       if (aa[i].x != aa[i - 1].x)         while (now != i) {           if (aa[now].r == 1) add(aa[now].t, -1);           if (aa[now].r == 2) add(aa[now].t, 1);           now++;         }       if (aa[i].r == 1) add(aa[i].t, 1);       if (aa[i].r == 2) add(aa[i].t, -1);       if (aa[i].r == 3) ans[aa[i].id] = get(aa[i].t);     }     for (int i = 1; i <= n; i++)       if (ans[i] != -1) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, num[100010], w[100010];   int x[100010], y[100010];   struct edge {     int w, f, id;   } e[100010];   inline bool operator<(edge a, edge b) { return a.w < b.w; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].w, &e[i].f);       e[i].id = i;     }     sort(e + 1, e + m + 1);     for (int i = 1; i <= m; i++) {       if (e[i].f) {         cnt++;         num[cnt] = cnt - 1;         w[cnt] = e[i].w;         x[e[i].id] = cnt;         y[e[i].id] = cnt + 1;       }     }     int now = cnt;     for (int i = m; i >= 1; i--) {       if (e[i].f) continue;       while (w[now] > e[i].w && now) now--;       if (now == 0 || now == 1) {         puts( -1 );         return 0;       }       y[e[i].id] = now + 1;       x[e[i].id] = num[now];       num[now]--;       if (num[now] == 0) now--;     }     for (int i = 1; i <= m; i++) {       printf( %d %d n , x[i], y[i]);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int ans = 0;       int sum = 0;       while (n--) {         int x;         scanf( %d , &x);         if (x == -1) {           if (!sum)             ans++;           else             sum--;         } else           sum += x;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long int gcd(long long int a, long long int b) {     if (!b)       return a;     else       return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long int> a(n);       vector<bool> vis(n);       deque<long long int> b;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         bool x;         cin >> x;         vis[i] = x;         if (!vis[i]) b.push_back(a[i]);       }       sort(b.begin(), b.end(), greater<long long int>());       for (int i = 0; i < n; i++) {         if (!vis[i]) {           cout << b.front() <<    ;           b.pop_front();         } else {           cout << a[i] <<    ;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, n1, ans, m, per1, per2, add;   const int maxn = 1000007;   long long tree[maxn * 4][4];   void build() {     for (int j = n1 - 1; j < n1 + n - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 + n - 1; j < 2 * n1 - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 - 2; j > -1; j -= 1) {       tree[j][0] = tree[j * 2 + 1][0];       tree[j][1] = tree[j * 2 + 2][1];       tree[j][2] = 0;       tree[j][3] = 0;     }   }   void push(int node) {     tree[2 * node + 1][3] += tree[node][3];     tree[2 * node + 2][3] += tree[node][3];     tree[node][3] = 0;   }   void update(int node, int a, int b, int val) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (l == a and r == b) {       tree[node][3] += val;     } else if (r >= a and b >= l) {       push(node);       update(2 * node + 1, a, min(b, (l + r) / 2), val);       update(2 * node + 2, max(a, (l + r) / 2 + 1), b, val);       tree[node][2] = (tree[node * 2 + 1][2] + tree[node * 2 + 1][3] +                        tree[node * 2 + 2][2] + tree[node * 2 + 2][3]);     }   }   int query(int node, int a, int b) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (r < a || b < l) {       return 0;     }     if (l == a && r == b) {       return tree[node][2] + tree[node][3];     }     push(node);     ans = (query(node * 2 + 1, a, min(b, (l + r) / 2)) +            query(node * 2 + 2, max(a, (l + r) / 2 + 1), b));     tree[node][2] = (tree[2 * node + 1][2] + tree[2 * node + 1][3] +                      tree[2 * node + 2][2] + tree[2 * node + 2][3]);     return ans;   }   int main() {     cin >> n >> k;     n1 = pow(2, ceil(log2(n)));     ;     build();     long long answer = 1;     int now = 1;     for (int j = 0; j < n; j++) {       update(0, now, now, 1);       per1 = 0;       per2 = 0;       if (now + k > n) {         if (k - 1 <= (n - 2) / 2) {           if (now != n) {             per2 = query(0, now + 1, n);           }           if (now + k - n >= 2) {             per1 = query(0, 1, now + k - 1 - n);           }           answer += (1 + per1 + per2);         } else {           answer += (query(0, now + 1 + k - n, now - 1) + 1);         }         now = now + k - n;       } else {         if (k - 1 <= (n - 2) / 2)           answer += (query(0, now + 1, now + k - 1) + 1);         else {           if (now + k != n) {             per2 = query(0, now + k + 1, n);           }           if (now >= 2) {             per1 = query(0, 1, now - 1);           }           answer += (1 + per1 + per2);         }         now += k;       }       cout << answer <<    ;       update(0, now, now, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   int dblcmp(double d) {     if (fabs(d) < eps) return 0;     return (d > 0) ? 1 : -1;   }   int n, m, T;   bool win(long long a, long long b) {     if (a * b == 0) return false;     if (a > b) swap(a, b);     if (!win(a, b % a)) return 1;     return ((b / a) % (a + 1)) % 2 == 0;   }   int main() {     cin >> T;     while (T--) {       long long a, b;       cin >> a >> b;       if (win(a, b))         printf( First n );       else         printf( Second n );     }     return 0;   }


#include<bits/stdc++.h>      #define N 5000007   #define M 200007   #define ll long long      const ll Mod=1000000007;   using namespace std;   inline int read()   {    int x=0,f=1;char ch=getchar();    while(!isdigit(ch)){if(ch== - )f=-1;ch=getchar();}    while(isdigit(ch)){x=(x<<1)+(x<<3)+ch- 0 ;ch=getchar();}    return x*f;   }      ll n,m,seed,base,tem;   ll num1,num2,ans;   ll a[N],t[N],hh[N];   ll p[M],k[M],b[M],w[M];   ll T1[N],T2[N],c1,c2;      ll rnd()   {    int ret=seed;    seed=1ll*(1ll*seed*base+233)%1000000007;    return ret;   }   int main()   {    n=read(),m=read();    num1=num2=0;    for (int i=1;i<=m;i++)     p[i]=read(),k[i]=read(),b[i]=read(),w[i]=read();    for (int i=1;i<=m;i++)    {     seed=b[i],base=w[i];     for (int j=p[i-1]+1;j<=p[i];j++)     {      t[j]=(rnd()%2)+1;      a[j]=(rnd()%k[i])+1;      hh[j]=a[j];      if (t[j]==1) num1+=a[j];      else num2+=a[j];     }    }   // cout<<num1<<   <<num2<<endl;     //for (int i=1;i<=n;i++)    // cout<<a[i]<<   <<t[i]<<endl;   /* for (int i=1;i<=n;i++)     a[i]=hh[i]=read();    for (int i=1;i<=n;i++)     t[i]=read();    for (int i=1;i<=n;i++)     if (t[i]==1) num1+=a[i];     else num2+=a[i];*/    if (num1==0||num2==0)    {     ans=1;     if (num1!=0)     {      ans=1ll*ans*(((1)^(1ll*1*1))%Mod+1)%Mod;      for (int i=2;i<=n;i++)       ans=1ll*ans*(((0)^(1ll*i*i))%Mod+1)%Mod;      printf( %lld n ,ans);     }     else     {      for (int i=1;i<=n;i++)       ans=1ll*ans*(((0)^(1ll*i*i))%Mod+1)%Mod;      printf( %lld n ,ans);     }    }    else    {     if (num1>num2) tem=2;     else tem=1;        // cout<<tem<<endl;         /*if (t[1]!=tem)     {      if (tem==1&&hh[1]>=num1)      {       hh[1]-=num1;       for (int i=1;i<=n;i++)        if (t[i]==tem) hh[i]=0;      }      else if (tem==2&&hh[1]>=num2)      {       hh[1]-=num2;       for (int i=1;i<=n;i++)        if (t[i]==tem) hh[i]=0;      }      else      {       int z=2;       while(hh[1])       {        if (t[z]!=t[1])        {         if (hh[1]>hh[z]) hh[1]-=hh[z],hh[z]=0;         else hh[z]-=hh[1],hh[1]=0;        }        z++;        }      }     }*/     //cout<<tem<<   <<num1<<   <<num2<<endl;     int z=1;ll num=0;     if (t[1]!=tem)     {      hh[1]--;      while(t[z]!=tem)z++;      }    // for (int i=1;i<=z;i++)    //  cout<<z<<   <<t[i]<<   <<hh[i]<<endl;     for (int i=z;i<=n<<1;i++)     {      int p=(i>n)?i%n:i;      if (t[p]==tem) num+=hh[p],hh[p]=0;      else      {       if (hh[p]>num) hh[p]-=num,num=0;       else num-=hh[p],hh[p]=0;      }     // cout<<num<<   <<hh[p]<<endl;     }          ans=1;     for (int i=1;i<=n;i++)      ans=1ll*ans*(((a[i]-hh[i])^(1ll*i*i))%Mod+1)%Mod;     printf( %lld n ,ans);    }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> di = {0, 0, 1, -1};   vector<int> dj = {1, -1, 0, 0};   int main() {     ios::sync_with_stdio(0), cin.tie(0);     vector<vector<int>> dpa(1001, vector<int>(1001, 2140000000));     vector<vector<int>> dpb(1001, vector<int>(1001, 2140000000));     vector<vector<int>> dpc(1001, vector<int>(1001, 2140000000));     vector<vector<pair<int, int>>> pa(         1001, vector<pair<int, int>>(1001, {2140000000, 0}));     vector<vector<pair<int, int>>> pb(         1001, vector<pair<int, int>>(1001, {2140000000, 0}));     vector<vector<pair<int, int>>> pc(         1001, vector<pair<int, int>>(1001, {2140000000, 0}));     int xa, ya;     cin >> xa >> ya;     dpa[xa][ya] = 0;     int xb, yb;     cin >> xb >> yb;     dpb[xb][yb] = 0;     int xc, yc;     cin >> xc >> yc;     dpc[xc][yc] = 0;     queue<pair<int, int>> q;     q.push({xa, ya});     while (!q.empty()) {       int vx = q.front().first;       int vy = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int tx = vx + di[i];         int ty = vy + dj[i];         if (tx >= 0 && tx <= 1000 && ty >= 0 && ty <= 1000 &&             dpa[tx][ty] == 2140000000) {           q.push({tx, ty});           dpa[tx][ty] = dpa[vx][vy] + 1;           pa[tx][ty] = {vx, vy};         }       }     }     q.push({xb, yb});     while (!q.empty()) {       int vx = q.front().first;       int vy = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int tx = vx + di[i];         int ty = vy + dj[i];         if (tx >= 0 && tx <= 1000 && ty >= 0 && ty <= 1000 &&             dpb[tx][ty] == 2140000000) {           q.push({tx, ty});           dpb[tx][ty] = dpb[vx][vy] + 1;           pb[tx][ty] = {vx, vy};         }       }     }     q.push({xc, yc});     while (!q.empty()) {       int vx = q.front().first;       int vy = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int tx = vx + di[i];         int ty = vy + dj[i];         if (tx >= 0 && tx <= 1000 && ty >= 0 && ty <= 1000 &&             dpc[tx][ty] == 2140000000) {           q.push({tx, ty});           dpc[tx][ty] = dpc[vx][vy] + 1;           pc[tx][ty] = {vx, vy};         }       }     }     int ans = 2140000000;     int ansx;     int ansy;     for (int i = 0; i <= 1000; i++) {       for (int j = 0; j <= 1000; j++) {         if (dpa[i][j] + dpb[i][j] + dpc[i][j] + 1 < ans) {           ans = dpa[i][j] + dpb[i][j] + dpc[i][j] + 1;           ansx = i;           ansy = j;         }       }     }     cout << ans << endl;     int sax = ansx;     int say = ansy;     int sbx = ansx;     int sby = ansy;     int scx = ansx;     int scy = ansy;     vector<vector<int>> used(1001, vector<int>(1001, 0));     while (make_pair(sax, say) != make_pair(2140000000, 0)) {       int tx = sax;       sax = pa[sax][say].first;       say = pa[tx][say].second;       if (make_pair(sax, say) != make_pair(2140000000, 0) && !used[sax][say]) {         cout << sax <<     << say << endl;         used[sax][say] = 1;       }     }     while (make_pair(sbx, sby) != make_pair(2140000000, 0)) {       int tx = sbx;       sbx = pb[sbx][sby].first;       sby = pb[tx][sby].second;       if (make_pair(sbx, sby) != make_pair(2140000000, 0) && !used[sbx][sby]) {         cout << sbx <<     << sby << endl;         used[sbx][sby] = 1;       }     }     while (make_pair(scx, scy) != make_pair(2140000000, 0)) {       int tx = scx;       scx = pc[scx][scy].first;       scy = pc[tx][scy].second;       if (make_pair(scx, scy) != make_pair(2140000000, 0) && !used[scx][scy]) {         cout << scx <<     << scy << endl;         used[scx][scy] = 1;       }     }     cout << ansx <<     << ansy << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const long long maxn = (long long)2e3 + 10;   const long long maxm = (long long)20;   const int LOGN = 20;   const long long INF = 1e15 + 10;   const long long MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double EPS = 1e-12;   long long Power(long long x, long long n) {     if (n == 0) return 1;     long long r = Power(x, n / 2);     r = r * r % MOD;     if (n & 1) r = r * x % MOD;     return r;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s1, s2;     cin >> s1 >> s2;     set<char> d1(s1.begin(), s1.end());     set<char> d2(s2.begin(), s2.end());     for (auto c : d2)       if (!d1.count(c)) {         cout << -1 << endl;         return 0;       }     vector<vector<int>> a(128);     for (int i = 0; i < s1.size(); ++i) {       a[s1[i]].push_back(i);     }     int ans = 1;     int p = -1;     for (int i = 0; i < s2.size(); ++i) {       auto c = s2[i];       auto it = upper_bound(a[c].begin(), a[c].end(), p);       if (it == a[c].end()) {         ++ans;         p = *upper_bound(a[c].begin(), a[c].end(), -1);       } else {         p = *it;       }     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define lop(i,n) for(ll i=0;i<n;i++)   #define lop1(i,n) for(ll i=1;i<=n;i++)   #define lopr(i,n) for(ll i=n-1;i>=0;i--)   #define ll long long int   #define pb push_back   #define all(v) v.begin(),v.end()   #define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define endl   n    #define F first   #define S second    #define mem(arr,val) memset(arr,val,sizeof(arr))   #define pii pair<int,int>   #define pll pair<ll,ll>   #define LCM(a,b) (a*b)/__gcd(a,b)   #define mii map<int,int>   #define mll map<ll,ll>   #define ub upper_bound   #define lb lower_bound   #define sz(x) (ll)x.size()   #define ld long double   #define pcnt(x) __builtin_popcountll(x)   const long long I1=1e9;   const long long I2=1e18;   const int32_t M1=1e9+7;   const int32_t M2=998244353;   template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}   template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}      void solve()   {     //code begins from here//       int n,q,k;       cin>>n>>q>>k;       ll a[n+2];       lop1(i,n){           cin>>a[i];       }       a[0] = 0;       a[n+1] = k+1;       ll pre[n+2];       lop1(i,n){           pre[i] = (a[i]-a[i-1]-1)+(a[i+1]-a[i]-1);           pre[i]+=pre[i-1];       }       while(q--){           int l,r;           cin>>l>>r;           if (l==r){               cout << k-1<<endl;               continue;           }           ll cnt = 0;           cnt += a[l+1]-2;           cnt += k - a[r-1] -1;           l++; r--;           if (l<=r){               cnt += pre[r]-pre[l-1];           }           cout << cnt<<endl;       }   }      signed main()   {       IOS;       #ifdef MODULO           initialize();       #endif       #ifdef SIEVE           sieve();       #endif       int testcase=1;      // cin>>testcase;       while(testcase--) solve();       return 0;   }


#include <bits/stdc++.h>   template <typename _Tp>   void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   const int N = 10000005, mod = 998244353;   template <typename _Tp1, typename _Tp2>   inline void add(_Tp1 &a, _Tp2 b) {     a = a + b >= mod ? a + b - mod : a + b;   }   template <typename _Tp1, typename _Tp2>   inline void sub(_Tp1 &a, _Tp2 b) {     a = a - b < 0 ? a - b + mod : a - b;   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   int pw[N], a[N];   void init() {     pw[0] = 1;     for (int i = 1; i < N; ++i) pw[i] = pw[i - 1], add(pw[i], pw[i - 1]);     int mul = 1;     for (int i = 1; i < N; ++i) mul = 1ULL * mul * (pw[i] - 1) % mod;     a[N - 1] = ksm(mul);     for (int i = N - 2; i >= 1; --i)       a[i] = 1ULL * a[i + 1] * (pw[i + 1] - 1) % mod;   }   void MAIN() {     int n, k, x;     read(n, k, x);     if (!x) {       if (n > k) return puts( 0 ), void();       int ans = 1;       for (int i = 0; i < n; ++i) ans = 1LL * ans * (pw[k] - pw[i] + mod) % mod;       printf( %d n , ans);       return;     }     int ans = pw[k] - 1, cur = 1, qwq = ksm(2, n), iq = ksm(2);     for (int i = 1, coef = pw[k] - 1; i < k; ++i) {       cur = 1ULL * cur * (qwq - 1) % mod, qwq = 1ULL * qwq * iq % mod,       coef = 1ULL * coef * (pw[k] - pw[i] + mod) % mod;       add(ans, 1ULL * coef * cur % mod * a[i] % mod);     }     printf( %lld n , ksm(pw[k] - 1) * ans % mod);   }   int main() {     init();     int _;     read(_);     while (_--) MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long a[26] = {0};       long long cnt = 0;       for (long long i = 0; i < s.size(); i++) {         a[s[i] - 97]++;       }       for (long long i = 0; i < 26; i++) {         if (a[i] <= 2)           cnt += a[i];         else           cnt += 2;       }       cout << cnt / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, i, sum;     int a[100010];     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     sum = a[n - 1];     int f = 1;     for (i = 0; i < n - 1; i++) {       sum -= a[i];       if (sum < 0) {         f = 0;         break;       }     }     if (f)       printf( %d , sum + 1);     else       printf( 1 );     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   const int INF = 0x3f3f3f3f;   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   inline int read() {     int X = 0;     bool flag = 1;     char ch = getchar();     while (ch< 0  | ch>  9 ) {       if (ch ==  - ) flag = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       X = (X << 1) + (X << 3) + ch -  0 ;       ch = getchar();     }     if (flag) return X;     return ~(X - 1);   }   int t;   string s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> s;       sort(s.begin(), s.end());       bool flag = true;       for (int i = 0; i <= (int)s.size() - 2; ++i) {         if (s[i] + 1 != s[i + 1]) {           flag = false;           break;         }       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, j, K;     int num[101];     memset(num, 0, sizeof(num));     cin >> n >> k;     for (i = 0; i < n; i++) {       scanf( %d , &K);       num[K]++;     }     int cut = 0;     int Max = 0;     for (i = 1; i <= 100; i++) {       if (num[i]) {         cut++;         Max = max(Max, num[i]);       }     }     Max % k ? (j = Max / k + 1) : (j = Max / k);     long long ans = 0;     ans = cut * j * k - n;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 1010, K = 51;   int n, m, k, u, v, x, y, t, a, b, ans;   short dp[2][MAXN][K][K];   bool good[2][MAXN];   inline void upd(short &a, short b) { a = max(a, b); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < 2; i++) {       cin >> t;       while (t--) cin >> x, good[i][x] = 1;     }     m = min(m, 2 * n / k + 2);     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int x = 0; x <= k; x++)           for (int y = 0; y <= k; y++) {             int tmp = (x && good[0][i]) || (y && good[1][i]);             upd(dp[1][j][x][y], dp[0][j][max(x - 1, 0)][max(y - 1, 0)] + tmp);             if (j) {               upd(dp[1][j][x][y], dp[1][j - 1][k][y]);               upd(dp[1][j][x][y], dp[1][j - 1][x][k]);             }           }       }       for (int j = 0; j <= m; j++)         for (int x = 0; x <= k; x++)           for (int y = 0; y <= k; y++) {             dp[0][j][x][y] = dp[1][j][x][y];             dp[1][j][x][y] = 0;           }     }     cout << dp[0][m][0][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200200, M = 110, K = 30030, Inf = 1e17;   void Max(long long &x, long long y) { x = max(x, y); }   long long dp[4 * K];   long long a[M], b[M];   vector<pair<long long, long long>> p, neg;   bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {     return p1.first - p1.second < p2.first - p2.second;   }   int main() {     long long n, r, c = 0;     cin >> n >> r;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (b[i] >= 0)         p.push_back({a[i], b[i]});       else         neg.push_back({a[i], -b[i]});     }     sort(p.begin(), p.end());     for (int i = 0; i < p.size(); i++) {       if (p[i].first <= r) r += p[i].second, c++;     }     sort(neg.begin(), neg.end(), cmp);     for (int i = 0; i < neg.size(); i++) {       for (int j = 2 * K - 1; j >= neg[i].first; j--) {         if (j - neg[i].second >= 0) Max(dp[j], dp[j - neg[i].second] + 1);       }     }     long long Ans = 0;     for (int i = 0; i <= r; i++) {       Max(Ans, dp[i]);     }     Ans += c;     cout << Ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   namespace LCT {   int fa[500005], ch[500005][2];   bool rev[500005], val[500005];   bool isr(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }   bool isc(int x) { return ch[fa[x]][1] == x; }   void upd(int x) { val[x] = val[ch[x][0]] | val[ch[x][1]] | (x > n); }   void pd(int x) {     if (rev[x])       swap(ch[x][0], ch[x][1]), rev[x] = 0, rev[ch[x][0]] ^= 1,                                 rev[ch[x][1]] ^= 1;   }   void pdpath(int x) {     if (!isr(x)) pdpath(fa[x]);     pd(x);   }   void rot(int x) {     int y = fa[x], z = fa[y], c = isc(x);     if (!isr(y)) ch[z][ch[z][1] == y] = x;     fa[ch[y][c] = ch[x][!c]] = y;     fa[ch[x][!c] = y] = x, fa[x] = z;     upd(y);   }   void splay(int x) {     for (pdpath(x); !isr(x); rot(x))       if (!isr(fa[x])) rot(isc(fa[x]) == isc(x) ? fa[x] : x);     upd(x);   }   void access(int x) {     for (int y = 0; x; x = fa[y = x]) splay(x), ch[x][1] = y, upd(x);   }   void prefer(int x) { access(x), splay(x); }   void bert(int x) { prefer(x), rev[x] ^= 1; }   void link(int x, int y) { bert(x), fa[x] = y; }   void cut(int x, int y) { bert(x), prefer(y), fa[x] = ch[y][0] = 0, upd(y); }   int find(int x) {     pd(x);     if (val[ch[x][1]])       return find(ch[x][1]);     else       return x > n ? x : find(ch[x][0]);   }   }  // namespace LCT   using LCT::cut;   using LCT::link;   vector<int> G[500005];   int X[500005], Y[500005], deg[500005], stk[500005], top, fa[500005];   void dfs(int u) {     for (int i = G[u].size() - 1, v; i >= 0; i--)       if ((v = G[u][i]) != fa[u]) fa[v] = u, dfs(v);   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), G[x].push_back(y), G[y].push_back(x);     for (int i = 1; i < n; i++)       scanf( %d%d , &X[i], &Y[i]), link(X[i], n + i), link(Y[i], n + i);     dfs(1);     for (int i = 1; i <= n; i++) deg[fa[i]]++;     for (int i = 1; i <= n; i++)       if (!deg[i]) stk[++top] = i;     printf( %d n , n - 1);     for (int i = 1, k; i < n; i++) {       int x = stk[i];       if (!--deg[fa[x]]) stk[++top] = fa[x];       LCT::bert(fa[x]), LCT::prefer(x);       k = LCT::find(LCT::ch[x][0]) - n;       printf( %d %d %d %d n , x, fa[x], X[k], Y[k]);       cut(X[k], n + k), cut(Y[k], n + k), link(x, fa[x]);     }   }


#include <bits/stdc++.h>   using namespace std;   int a[3005], b[3005], c[3005], vis[3005];   bool cmp(int i, int j) { return a[i] > a[j]; }   int main() {     vector<int> p, q;     int T, i, j, k, ca = 0, n, m, K;     int s, t;     scanf( %d%d%d , &n, &s, &t);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]), c[i] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     sort(c, c + n, cmp);     for (int i = 0; i < s; i++) {       vis[c[i]] = 1;     }     while (t--) {       k = 0;       while (k < n && vis[c[k]]) k++;       int mx = -1, v, l = c[k];       for (int i = n - 1; i >= 0; i--) {         j = -0x7f7f7f7f;         if (vis[i] == 0)           j = b[i];         else if (vis[i] == 1)           j = -a[i] + a[l] + b[i];         if (j > mx) mx = j, v = i;       }       if (vis[v]) vis[l] = 1;       vis[v] = 2;     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (vis[i] == 1) {         p.push_back(i + 1);         ans += a[i];       } else if (vis[i] == 2) {         q.push_back(i + 1);         ans += b[i];       }     }     printf( %d n , ans);     for (auto it : p) {       printf( %d  , it);     }     puts(  );     for (auto it : q) {       printf( %d  , it);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   vector<pair<int, int> > des[110];   int dist(int i, int j) {     if (i <= j) return j - i;     return n - i + j;   }   bool cmp(pair<int, int> a, pair<int, int> b) {     int i = a.second;     int x = a.first, y = b.first;     return dist(i, x) < dist(i, y);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       des[a].push_back(pair<int, int>(b, a));     }     for (int i = 1; i <= n; i++) sort(des[i].begin(), des[i].end(), cmp);     for (int s = 1; s <= n; s++) {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (des[i].empty()) continue;         int d;         if (s <= i)           d = i - s;         else           d = n - s + i;         d += n * (des[i].size() - 1);         int j = des[i][0].first;         if (i <= j)           d += j - i;         else           d += n - i + j;         ans = max(ans, d);       }       cout << ans <<    ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   const double G = 6.67430e-11;   int n, q;   set<int> p;   multiset<int> d;   void in(int x) {     p.insert(x);     if (p.size() == 1) return;     auto pos = p.find(x);     if (pos == --p.end()) {       d.insert(x - *--pos);     } else if (pos == p.begin()) {       int y = *++pos;       d.insert(y - x);     } else {       auto r = ++pos;       pos--;       auto l = --pos;       pos++;       d.insert(x - *l);       d.insert(*r - x);       d.erase(d.find(*r - *l));     }   }   void er(int x) {     set<int>::iterator pos;     pos = p.find(x);     if (p.size() < 2) {       p.erase(x);       return;     }     if (pos == --p.end())       d.erase(d.find(x - *--pos));     else if (pos == p.begin())       d.erase(d.find(*++pos - x));     else {       set<int>::iterator l;       set<int>::iterator r;       l = --pos;       ++pos;       r = ++pos;       --pos;       d.erase(d.find(x - *l));       d.erase(d.find(*r - x));       d.insert(*r - *l);     }     p.erase(x);   }   int kk() {     if (p.size() <= 2) return 0;     auto l = p.begin();     auto r = --p.end();     return (*r - *l - *--d.end());   }   int main() {     cin >> n >> q;     int x;     for (int i = 1; i <= n; ++i) {       cin >> x;       in(x);     }     cout << kk() <<   n ;     int op;     while (q--) {       cin >> op >> x;       if (op == 1)         in(x);       else         er(x);       cout << kk() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 2, MAX2 = 2e6 + 4;   int ans[MAX], val[MAX], depth[MAX];   vector<int> G[MAX], d[MAX2], occ[MAX2];   void init(int a) {     if (d[a].size()) return;     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         d[a].push_back(a / i);         if (i * i != a) d[a].push_back(i);       }     }     if (a != 1) d[a].push_back(a);   }   void dfs(int vv, int par, int dv = 0) {     ans[vv] = -1, depth[vv] = dv;     int v = val[vv];     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       if (not occ[u].empty()) {         int x = occ[u].back();         if (ans[vv] == -1 or depth[ans[vv]] < depth[x]) ans[vv] = x;       }       occ[u].push_back(vv);     }     for (int i = 0; i < G[vv].size(); i++) {       int u = G[vv][i];       if (u == par) continue;       dfs(u, vv, dv + 1);     }     for (int i = 0; i < d[v].size(); i++) {       int u = d[v][i];       occ[u].pop_back();     }   }   int main() {     int n, q;     cin >> n >> q;     for (int i = 1; i < n + 1; i++) {       scanf( %d , val + i);       init(val[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 0);     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int x;         scanf( %d , &x);         printf( %d n , ans[x]);       } else {         int x, v;         scanf( %d %d , &x, &v);         val[x] = v;         init(val[x]);         dfs(1, 0);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 27, maxm = 5e4 + 20, inf = 1e9;   vector<int> ar[maxn][maxn][maxn][maxn];   int q, a[maxm], bs[4], bs2[4];   string s, qs, qss;   map<pair<string, string>, int> mp;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s >> q;     for (int i = 0; i < s.size(); i++)       a[i] = (int)s[i] -  a , ar[(int)s[i] -  a ][26][26][26].push_back(i);     for (int i = 0; i < (int)s.size() - 1; i++)       ar[a[i]][a[i + 1]][26][26].push_back(i);     for (int i = 0; i < (int)s.size() - 2; i++)       ar[a[i]][a[i + 1]][a[i + 2]][26].push_back(i);     for (int i = 0; i < (int)s.size() - 3; i++)       ar[a[i]][a[i + 1]][a[i + 2]][a[i + 3]].push_back(i);     while (q--) {       cin >> qs >> qss;       if (qss < qs) swap(qss, qs);       fill(bs, bs + 4, 26), fill(bs2, bs2 + 4, 26);       for (int i = 0; i < qs.size(); i++) bs[i] = qs[i] -  a ;       for (int i = 0; i < qss.size(); i++) bs2[i] = qss[i] -  a ;       if (ar[bs[0]][bs[1]][bs[2]][bs[3]].size() >           ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].size())         swap(qs, qss), swap(bs, bs2);       if (mp.count(make_pair(qs, qss))) {         cout << mp[make_pair(qs, qss)] << endl;         continue;       }       int ans = inf, j;       for (int i : ar[bs[0]][bs[1]][bs[2]][bs[3]]) {         auto it = upper_bound(ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].begin(),                               ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].end(), i);         if (it != ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].end()) {           j = *it;           ans = min(ans, max(i + (int)qs.size(), j + (int)qss.size()) - i);         }         if (it != ar[bs2[0]][bs2[1]][bs2[2]][bs2[3]].begin()) {           it--;           j = *it;           ans = min(ans, max(i + (int)qs.size(), j + (int)qss.size()) - j);         }       }       if (ans == inf) ans = -1;       mp[make_pair(qs, qss)] = ans;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int deg[100000], x[100000];   map<pair<int, int>, int> m;   vector<pair<int, int> > v;   int main() {     int n, k;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &deg[i], &x[i]);       if (deg[i] > 0) {         pair<int, int> a;         a.first = deg[i];         a.second = i;         m[a] = i;       }     }     while (!m.empty()) {       pair<pair<int, int>, int> b = *(m.begin());       m.erase(m.begin());       int neighbor = x[b.first.second];       v.push_back(pair<int, int>(b.first.second, neighbor));       map<pair<int, int>, int>::iterator it =           m.find(pair<int, int>(deg[neighbor], neighbor));       pair<int, int> c = it->first;       m.erase(it);       deg[neighbor]--;       x[neighbor] ^= b.first.second;       if (deg[neighbor] > 0) {         c.first--;         m[c] = neighbor;       }     }     k = v.size();     printf( %d n , v.size());     for (int i = 0; i < k; i++) {       printf( %d %d n , v[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 7340033;   long long n, k;   long long DP[100][1009], dp[100][1009];   long long DFS(int h, int k);   long long dfs(int h, int k) {     long long &d = dp[h][k];     if (~d) return d;     d = 0;     for (int i = 0; i <= k; i++)       d = (d + DFS(h - 1, i) * DFS(h - 1, k - i)) % mod;     return d;   }   long long DFS(int h, int k) {     long long &d = DP[h][k];     if (~d) return d;     if (h == 0) {       if (k == 0) return d = 1;       return d = 0;     }     if (k == 0) return 1;     d = 0;     for (int i = 0; i < k; i++) d = (d + dfs(h, i) * dfs(h, k - 1 - i)) % mod;     return d;   }   void pre() {     memset(dp, -1, sizeof(dp));     memset(DP, -1, sizeof(DP));     for (int i = 0; i <= 30; i++)       for (int j = 0; j <= 1000; j++) DFS(i, j);   }   int main() {     int w;     cin >> w;     pre();     while (w--) {       int n, k;       cin >> n >> k;       int cnt = 0;       while (n > 1 && (n & 1)) cnt++, n >>= 1;       cout << DFS(cnt, k) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int ku[maxn], kd[maxn], posu[maxn], posd[maxn];   long long tl[maxn], tr[maxn];   int main() {     int n;     cin >> n;     char s[maxn];     scanf( %s , s + 1);     int a = 0, b = 0;     for (int i = 1; i <= n; i++) {       ku[i + 1] = ku[i] + (s[i] ==  U );       kd[n - i] = kd[n - i + 1] + (s[n - i + 1] ==  D );       tl[i] = tl[i - 1] + 2 * ku[i] + 1;       tr[n - i + 1] = tr[n - i + 2] + 2 * kd[n - i + 1] + 1;       if (s[i] ==  U )         posu[a++] = i;       else         posd[b++] = i;     }     long long ans = 0, nb, ind;     for (int i = 1; i <= n; i++) {       if (s[i] ==  U ) {         if (ku[i] < kd[i]) {           nb = kd[i] - ku[i] - 1;           ind = posd[b - nb - 1];           ans = tl[i] + tr[i] - tr[ind] - (2 * nb + 1) * (ind - i);         } else {           nb = ku[i] - kd[i];           ind = posu[nb];           ans = tl[i] + tr[i] - tl[ind] - (2 * nb + 1) * (i - ind);         }       } else {         if (kd[i] < ku[i]) {           nb = ku[i] - kd[i] - 1;           ind = posu[nb];           ans = tl[i] + tr[i] - tl[ind] - (2 * nb + 1) * (i - ind);         } else {           nb = kd[i] - ku[i];           ind = posd[b - nb - 1];           ans = tl[i] + tr[i] - tr[ind] - (2 * nb + 1) * (ind - i);         }       }       cout << ans <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 5e5 + 100, OO = 1e6, T = (1 << 20) + 10, M = 998244353, P = 6151,             SQ = 280, lg = 64;   int a[N], b[N];   vector<int> v, v1, t, t1;   vector<pair<int, int> > is[N];   int dp[N], dp1[N], ant[N], ans[N], n1[N], n2[N];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       is[x - 1].push_back({y, i});     }     for (int i = 0; i < n; i++) {       for (auto u : is[i]) {         int l = 0, r = (int)v.size();         int nw = u.first;         while (l < r) {           int mid = (l + r) / 2;           if (v[mid] >= nw)             r = mid;           else             l = mid + 1;         }         n1[u.second] = l + 1;       }       int l = 0, r = (int)v.size();       while (l < r) {         int mid = (l + r) / 2;         if (v[mid] >= a[i])           r = mid;         else           l = mid + 1;       }       if (l == (int)v.size())         v.push_back(a[i]);       else         v[l] = a[i];       dp[i] = l + 1;       b[i] = -1 * a[i];     }     int lis = (int)v.size();     for (int i = n - 1; i >= 0; i--) {       for (auto u : is[i]) {         int l = 0, r = (int)v1.size();         int nw = u.first * -1;         while (l < r) {           int mid = (l + r) / 2;           if (v1[mid] >= nw)             r = mid;           else             l = mid + 1;         }         n2[u.second] = l;       }       int l = 0, r = (int)v1.size();       while (l < r) {         int mid = (l + r) / 2;         if (v1[mid] >= b[i])           r = mid;         else           l = mid + 1;       }       if (l + dp[i] == (int)v.size())         ans[i] = 3, t.push_back(a[i]), t1.push_back(i);       else         ans[i] = 1;       if (l == (int)v1.size())         v1.push_back(b[i]);       else         v1[l] = b[i];     }     v.clear();     v1.clear();     for (int i = t.size() - 1; i >= 0; i--) {       int l = 0, r = (int)v.size();       while (l < r) {         int mid = (l + r) / 2;         if (v[mid] >= t[i])           r = mid;         else           l = mid + 1;       }       if (l == (int)v.size()) {         v.push_back(t[i]);         v1.push_back(t1[i]);       } else {         ans[v1[l]] = 2;         ans[t1[i]] = 2;         v[l] = t[i];         v1[l] = t1[i];       }     }     for (int i = 0; i < n; i++) {       for (auto u : is[i]) {         int lt = n1[u.second] + n2[u.second];         if (lt >= lis) {           ant[u.second] = lt;           continue;         }         if (ans[i] == 1 || ans[i] == 2) {           ant[u.second] = lis;           continue;         } else           ant[u.second] = lis - 1;       }     }     for (int i = 0; i < m; i++) cout << ant[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     cin >> TESTS;     while (TESTS--) {       int n;       cin >> n;       string s;       cin >> s;       if ((long long int)s.size() == 1)         cout <<  NO n ;       else if ((long long int)s.size() == 2) {         if (s[0] < s[1]) {           cout <<  YES n2 n ;           cout << s[0] <<     << s[1] <<   n ;         } else           cout <<  NO n ;       } else {         cout <<  YES n2 n ;         cout << s[0] <<     << s.substr(1, n - 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int solve(int c, int d, int n, int m, int k) {     int s = n * m;     if (k >= n * m) return 0;     s = n * m - k;     int sum = 0;     while (1) {       if (s <= n) {         if (c < s * d)           sum += c;         else           sum += s * d;         break;       }       if (c < n * d)         sum += c;       else         sum += n * d;       s -= n;     }     return sum;   }   int main() {     int c, d, n, m, k;     while (scanf( %d%d%d%d%d , &c, &d, &n, &m, &k) != EOF) {       int s = solve(c, d, n, m, k);       printf( %d n , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int maxn = 100 + 10;   long long ma[100];   void init() {     long long x = 1;     for (int i = 0; i <= 32; i++) {       ma[i] = x;       x *= 2;     }   }   int main() {     init();     int T;     scanf( %d , &T);     while (T--) {       long long n;       long long ans = 0;       scanf( %lld , &n);       long long x1 = n;       long long x2 = (n + 1);       if (x1 % 2 == 0)         x1 /= 2;       else         x2 /= 2;       ans = x1 * x2;       for (int i = 0; i <= 32; i++) {         if (n < ma[i])           break;         else           ans -= 2 * ma[i];       }       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, p = 0;     cin >> n >> m;     if (n == 1 && m != 0) {       cout << m <<     << m << endl;       return 0;     } else if (m == 1 && n != 0) {       cout << n <<     << n << endl;       return 0;     } else if (n == 0 && m == 0) {       cout << p <<     << p << endl;       return 0;     } else if (n == 0) {       cout <<  Impossible n ;       return 0;     } else if (m == 0) {       cout << n <<     << n << endl;       return 0;     } else if (n == m) {       cout << m <<     << n + m - 1 << endl;       return 0;     } else if (n > m) {       if (n % m == 0)         cout << m + (n / m) <<     << n + m - 1 << endl;       else         cout << m + (n - m) <<     << n + m - 1 << endl;     } else if (m > n) {       if (m % n == 0)         cout << n + (m / n) <<     << n + m - 1 << endl;       else         cout << n + (m - n) <<     << n + m - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, s;     cin >> n >> k >> s;     if ((n - 1) * k < s || s < k) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     long long m = s / k;     int rem = s % k;     int count = 0;     int room = 1;     for (; count < rem; ++count) {       room = (count % 2 == 0) ? room + m + 1 : room - m - 1;       cout << room <<    ;     }     for (; count < k; ++count) {       room = (count % 2 == 0) ? room + m : room - m;       cout << room <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     int N;     vector<int> V;     cin >> N;     int X;     for (int i = 0; i < N; i++) {       cin >> X;       V.push_back(X);     }     int ans = 100100, t = 0;     for (int i = 1; i <= 100; i++) {       int cost = 0;       for (int j = 0; j < N; j++) {         if (abs(V[j] - i) > 1) {           cost += min(abs(V[j] - (i + 1)), abs(V[j] - (i - 1)));         }       }       if (cost < ans) {         ans = cost;         t = i;       }     }     cout << t <<     << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   const long long mod = 1e9 + 7;   unsigned long long base = 1000000007;   char a[2][2011], s[2011];   int n, m;   unsigned long long hsl[2][2011], hsr[2][2011], hss[2011], pw[2011];   unsigned long long gethsl(int i, int x, int y) {     return hsl[i][y] - hsl[i][x - 1] * pw[y - x + 1];   }   unsigned long long gethsr(int i, int x, int y) {     return hsr[i][y] - hsr[i][x + 1] * pw[x - y + 1];   }   unsigned long long gethss(int x, int y) {     return hss[y] - hss[x - 1] * pw[y - x + 1];   }   long long dp[2][2011][2], pre[2][2011][2];   long long solve() {     for (int i = 0; i < 2; i++) {       hsl[i][0] = 0;       for (int j = 1; j <= n; j++) hsl[i][j] = hsl[i][j - 1] * base + a[i][j];       hsr[i][n + 1] = 0;       for (int j = n; j >= 1; j--) hsr[i][j] = hsr[i][j + 1] * base + a[i][j];     }     long long ans = 0;     memset(dp, 0, sizeof(dp));     for (int p = 1; p <= m; p++) {       for (int i = 0; i < 2; i++)         for (int j = 1; j <= n; j++)           for (int t = 0; t < 2; t++) pre[i][j][t] = dp[i][j][t];       memset(dp, 0, sizeof(dp));       if (p % 2 == 0 && p > 2 && p < m) {         int len = p >> 1;         for (int i = 0; i < 2; i++) {           for (int j = len + 1; j <= n + 1; j++) {             if (gethsr(i, j - 1, j - len) * pw[len] +                     gethsl(!i, j - len, j - 1) !=                 gethss(1, p))               continue;             dp[!i][j - 1][1] = 1;           }         }       } else if (p == 1) {         for (int i = 0; i < 2; i++)           for (int j = 1; j <= n; j++) dp[i][j][0] = (s[1] == a[i][j]);       }       for (int i = 0; i < 2; i++) {         for (int j = 1; j <= n; j++) {           if (a[i][j] != s[p]) continue;           dp[i][j][0] = (dp[i][j][0] + pre[i][j - 1][0] + pre[i][j - 1][1]) % mod;           dp[i][j][1] = (dp[i][j][1] + pre[!i][j][0]) % mod;         }       }       if ((m - p) % 2 == 0 && m - p > 2) {         int len = (m - p) >> 1;         for (int i = 0; i < 2; i++) {           for (int j = 1; j <= n - len; j++) {             if (gethsl(i, j + 1, j + len) * pw[len] +                     gethsr(!i, j + len, j + 1) !=                 gethss(p + 1, m))               continue;             for (int t = 0; t < 2; t++) ans = (ans + dp[i][j][t]) % mod;           }         }       } else if (p == m) {         for (int i = 0; i < 2; i++)           for (int j = 1; j <= n; j++)             for (int t = 0; t < 2; t++) ans = (ans + dp[i][j][t]) % mod;       }     }     return ans;   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 2005; i++) pw[i] = pw[i - 1] * base;     scanf( %s , a[0] + 1);     scanf( %s , a[1] + 1);     n = strlen(a[0] + 1);     scanf( %s , s + 1);     m = strlen(s + 1);     if (m == 1) {       int cnt = 0;       for (int i = 0; i < 2; i++)         for (int j = 1; j <= n; j++) cnt += (a[i][j] == s[1]);       cout << cnt << endl;       return 0;     } else if (m == 2) {       int cnt = 0;       for (int i = 0; i < 2; i++)         for (int j = 1; j <= n; j++) cnt += (a[i][j] == s[1] && a[!i][j] == s[2]);       for (int i = 0; i < 2; i++)         for (int j = 1; j <= n; j++)           cnt += (a[i][j] == s[1] && a[i][j + 1] == s[2]) +                  (a[i][j] == s[1] && a[i][j - 1] == s[2]);       cout << cnt << endl;       return 0;     }     for (int i = 1; i <= m; i++) hss[i] = hss[i - 1] * base + s[i];     long long ans = solve();     reverse(a[0] + 1, a[0] + n + 1);     reverse(a[1] + 1, a[1] + n + 1);     ans = (ans + solve()) % mod;     if (m % 2 == 0) {       int len = m >> 1;       for (int i = 0; i < 2; i++) {         for (int j = 0; j <= n - len; j++) {           ans +=               (gethsl(i, j + 1, j + len) * pw[len] + gethsr(!i, j + len, j + 1) ==                gethss(1, m));         }       }       for (int i = 0; i < 2; i++) {         for (int j = len + 1; j <= n + 1; j++) {           ans +=               (gethsr(i, j - 1, j - len) * pw[len] + gethsl(!i, j - len, j - 1) ==                gethss(1, m));         }       }     }     cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     bool temp = false;     cin >> n;     string *arr = new string[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       if (arr[i][0] ==  O  && arr[i][1] ==  O ) {         temp = true;         cout <<  YES  << endl;         arr[i][0] =  + ;         arr[i][1] =  + ;         for (int i = 0; i < n; i++) cout << arr[i] << endl;         break;       }       if (arr[i][3] ==  O  && arr[i][4] ==  O ) {         temp = true;         cout <<  YES  << endl;         arr[i][3] =  + ;         arr[i][4] =  + ;         for (int i = 0; i < n; i++) cout << arr[i] << endl;         break;       }     }     if (temp == false) {       cout <<  NO  << endl;     }     return 0;   }