#include <bits/stdc++.h>   using namespace std;   struct segment_tree {     long long a[1 << 20][5];     int sz[1 << 20];     int N;     void initi(int x) {       N = 1;       while (N < x) N <<= 1;     }     void pushup(int x) {       int pos = x + N - 1;       while (x > 0) {         x = (x - 1) >> 1;         sz[x] = sz[(x << 1) + 1] + sz[(x << 1) + 2];         for (int i = 0; i < 5; i++) a[x][i] = 0;         for (int i = 0; i < 5; i++) {           a[x][i] += a[(x << 1) + 1][i];           a[x][(i + sz[(x << 1) + 1]) % 5] += a[(x << 1) + 2][i];         }       }     }     void ins(int x, int y) {       int pos = x + N - 1;       sz[pos]++;       a[pos][0] = y;       pushup(pos);     }     void del(int x) {       int pos = x + N - 1;       sz[pos]--;       a[pos][0] = 0;       pushup(pos);     }   } tr;   int n;   int s[100010];   vector<int> v;   vector<int> vc;   map<int, int> mp;   int l;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       string t;       int x;       cin >> t;       if (t ==  add ) {         cin >> x;         v.push_back(x);         vc.push_back(x);       } else if (t ==  del ) {         cin >> x;         v.push_back(-x);       } else {         v.push_back(0);       }     }     sort(vc.begin(), vc.end());     tr.initi((int)vc.size());     for (int i = 0; i < vc.size(); i++) {       mp[vc[i]] = i;     }     for (int i = 0; i < v.size(); i++) {       if (!v[i]) {         printf( %lld n , tr.a[0][2]);       } else if (v[i] < 0) {         tr.del(mp[-v[i]]);       } else {         tr.ins(mp[v[i]], v[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   void answer(int u) {     printf( ! %d n , u);     fflush(stdout);   }   int ask(int u) {     printf( ? %d n , u);     fflush(stdout);     int res;     scanf( %d , &res);     return res;   }   bool inside(int u, pair<int, int> v) {     return ((u > v.first) ^ (u >= v.second)) == 1;   }   bool check(pair<int, int> u, pair<int, int> v) {     if (inside(u.first, v) && inside(u.second, v)) {       return 1;     }     if (inside(v.first, u) && inside(v.second, u)) {       return 1;     }     if (inside(u.first, v) && inside(v.first, u)) {       return 1;     }     if (inside(u.second, v) && inside(v.second, u)) {       return 1;     }     return 0;   }   int main() {     int n;     scanf( %d , &n);     if ((n / 2) % 2 != 0) {       answer(-1);       return 0;     }     int x = ask(1);     int y = ask(1 + n / 2);     if (x == y) {       answer(1);       return 0;     }     pair<int, int> u(x, y);     pair<int, int> v(y, x);     int low = 1, high = n / 2 + 1;     while (high - low > 1) {       int mid = (high + low) / 2;       int foo = ask(mid);       int bar = ask(mid + n / 2);       if (foo == bar) {         answer(mid);         return 0;       }       pair<int, int> a(u.first, foo);       pair<int, int> b(v.first, bar);       if (check(a, b)) {         high = mid;         u = a;         v = b;       } else {         low = mid;         u = make_pair(foo, u.second);         v = make_pair(bar, v.second);       }     }     answer(low);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFL = (int)1e9;   const long long int INFLL = (long long int)1e18;   const double INFD = numeric_limits<double>::infinity();   const double PI = 3.14159265358979323846;   bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }   bool inrange(int x, int t) { return x >= 0 && x < t; }   long long int rndf(double x) {     return (long long int)(x + (x >= 0 ? 0.5 : -0.5));   }   long long int floorsqrt(long long int x) {     long long int m = (long long int)sqrt((double)x);     return m + (m * m <= x ? 0 : -1);   }   long long int ceilsqrt(long long int x) {     long long int m = (long long int)sqrt((double)x);     return m + (x <= m * m ? 0 : 1);   }   long long int rnddiv(long long int a, long long int b) {     return (a / b + (a % b * 2 >= b ? 1 : 0));   }   long long int ceildiv(long long int a, long long int b) {     return (a / b + (a % b == 0 ? 0 : 1));   }   long long int gcd(long long int m, long long int n) {     if (n == 0)       return m;     else       return gcd(n, m % n);   }   long long int lcm(long long int m, long long int n) {     return m * n / gcd(m, n);   }   class Max_Queue {    private:     stack<pair<long long int, long long int> > stk0, stk1;     void rebuffer() {       while (stk1.size()) {         long long int x = stk1.top().first;         long long int y = stk0.size() ? stk0.top().second : LLONG_MIN;         stk0.push({x, max(x, y)});         stk1.pop();       }     }       public:     void push(long long int x) {       long long int y = stk1.size() ? stk1.top().second : LLONG_MIN;       stk1.push({x, max(x, y)});     }     long long int front() {       if (stk0.empty()) rebuffer();       return stk0.top().first;     }     void pop() {       if (stk0.empty()) rebuffer();       stk0.pop();     }     size_t size() { return stk0.size() + stk1.size(); }     void clear() {       while (stk0.size()) stk0.pop();       while (stk1.size()) stk1.pop();     }     long long int get_max() {       long long int x = LLONG_MIN, y = LLONG_MIN;       if (stk0.size()) x = stk0.top().second;       if (stk1.size()) y = stk1.top().second;       return max(x, y);     }   };   long long int dist(long long int s, long long int t, long long int n) {     if (s <= t)       return t - s;     else       return t + n - s;   }   int main() {     int n, m;     cin >> n >> m;     vector<long long int> a(n, LLONG_MAX);     vector<long long int> cnt(n, 0);     for (int i = 0; i < (int)(m); i++) {       long long int s, t;       cin >> s >> t;       s--;       t--;       a[s] = min(a[s], dist(s, t, n));       cnt[s]++;     }     vector<long long int> ans(n, 0);     Max_Queue mq;     for (int j = 0; j < (int)(n); j++) {       long long int buf = -n;       if (cnt[j] > 0) buf = dist(0, j, n) + (cnt[j] - 1) * n + a[j];       mq.push(buf);     }     for (int i = 0; i < (int)(n); i++) {       ans[i] = mq.get_max() - i;       long long int x = mq.front();       mq.pop();       mq.push(x + n);     }     for (int extra_i = 0; extra_i < (int)(ans.size()); extra_i++) {       cout << ans[extra_i] <<    ;     }     cout << endl;     ;   }


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


#include <bits/stdc++.h>   using namespace std;   void display(vector<int> v1) {     for (long long int i = 0; i < v1.size(); i++) {       cout << v1[i] <<    ;     }     cout << endl;   }   long long int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};   long long int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};   int n, dp[9000][2];   vector<int> v1[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     memset(dp, -1, sizeof(dp));     for (int p = 0, k; p < 2; p += 1) {       cin >> k;       v1[p].resize(k);       for (long long int i = 0; i < k; i++) {         cin >> v1[p][i];       }     }     dp[1][0] = 0;     dp[1][1] = 0;     bool flag = true;     while (flag) {       flag = false;       for (int i = n; i >= 2; i--)         for (int p = 0; p < 2; p++)           if (dp[i][p] == -1) {             bool can = false;             for (int x : v1[p]) {               int nxt = (i + x) % n + n * !bool((i + x) % n);               if (!dp[nxt][p ^ 1]) {                 dp[i][p] = 1;                 flag = true;                 can = true;                 break;               } else if (dp[nxt][p ^ 1] == -1)                 can = true;             }             if (!can) dp[i][p] = 0, flag = true;           }     }     for (int p = 0; p < 2; p++) {       for (int i = 2; i <= n; i++) {         if (dp[i][p] == -1) {           cout <<  Loop  ;         } else if (dp[i][p] == 1) {           cout <<  Win  ;         } else {           cout <<  Lose  ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 5e5 + 5;   long long l[N], r[N], x[N], d[N], s[N], pre[N], dp[N];   int n, m;   inline long long solve(int u) {     for (int i = 1; i <= n; i++) d[i] = s[i] = pre[i] = 0;     for (int i = 1; i <= m; i++) {       if (x[i] >> u & 1) {         d[r[i] + 1]--;         d[l[i]]++;       } else {         pre[r[i]] = max(pre[r[i]], l[i]);       }     }     dp[0] = s[0] = 1;     for (int i = 1; i <= n; i++) {       d[i] += d[i - 1];       pre[i] = max(pre[i], pre[i - 1]);       if (d[i] > 0)         dp[i] = 0;       else if (pre[i - 1] > 0)         dp[i] = (s[i - 1] - s[pre[i - 1] - 1]) % mod;       else         dp[i] = s[i - 1];       s[i] = (s[i] + s[i - 1] + dp[i]) % mod;     }     return pre[n] == 0 ? s[n] % mod : (s[n] - s[pre[n] - 1]) % mod;   }   int main() {     int k;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= m; i++) scanf( %lld%lld%lld , &l[i], &r[i], &x[i]);     long long ans = 1;     for (int i = 0; i < k; i++) ans = ans * solve(i) % mod;     printf( %lld n , (ans + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int inf = 1e9;   double eps = 1e-6;   int main() {     int n, k;     cin >> n >> k;     vector<int> a;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a.push_back(t);     }     if (k == 1) {       int ans = a[0];       for (int i = 1; i < n; i++) {         ans = min(ans, a[i]);       }       cout << ans;     } else if (k > 2) {       int ans = a[0];       for (int i = 1; i < n; i++) {         ans = max(ans, a[i]);       }       cout << ans;     } else {       int ans = INT_MIN;       multiset<int> p;       multiset<int> q;       p.insert(a[0]);       for (int i = 1; i < n; i++) {         q.insert(a[i]);       }       ans = max(ans, max(*q.begin(), *p.begin()));       for (int i = 1; i < n - 1; i++) {         p.insert(a[i]);         q.erase(q.find(a[i]));         ans = max(ans, max(*q.begin(), *p.begin()));       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   int a[100005] = {};   int p[100005] = {};   int mbuy[100005] = {};   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     int n, currmin = 1000000, buy = 0, last = 0;     std::cin >> n;     for (int i = 0; i < n; i++) std::cin >> a[i] >> p[i];     for (int i = 0; i < n; i++) {       if (p[i] < currmin) {         mbuy[last] = buy;         currmin = p[i];         last = i;         buy = 0;       }       buy += a[i];     }     mbuy[last] = buy;     long long int ans = 0;     for (int i = 0; i < n; i++) {       ans += mbuy[i] * p[i];     }     std::cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int inf = 1e7;   int tree[4 * N + 100], ans[2 * N + 100];   vector<int> R[N + 100], C[N + 100];   vector<pair<pair<int, int>, pair<int, int> > > qr[N + 100], qc[N + 100];   void update(int v, int tl, int tr, int idx, int val) {     if (tl == tr) {       tree[v] = val;     } else {       int tm = (tl + tr) / 2;       if (idx <= tm) {         update(v * 2, tl, tm, idx, val);       } else {         update(v * 2 + 1, tm + 1, tr, idx, val);       }       tree[v] = min(tree[v * 2], tree[v * 2 + 1]);     }   }   int getMin(int v, int tl, int tr, int l, int r) {     if (l > r) {       return inf;     }     if (l == tl && r == tr) {       return tree[v];     }     int tm = (tl + tr) / 2;     return min(getMin(v * 2, tl, tm, l, min(r, tm)),                getMin(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));   }   int main() {     int n, m, k, q;     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d%d , &x, &y);       R[y].push_back(x);       C[x].push_back(y);     }     for (int i = 1; i <= q; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       qc[x2].push_back(make_pair(make_pair(y1, y2), make_pair(x1, i)));       qr[y2].push_back(make_pair(make_pair(x1, x2), make_pair(y1, i)));     }     memset(tree, 0, sizeof tree);     for (int i = 1; i <= n; i++) {       for (auto it : C[i]) {         update(1, 1, m, it, i);       }       for (auto it : qc[i]) {         int mn = getMin(1, 1, m, it.first.first, it.first.second);         if (mn >= it.second.first) {           ans[it.second.second] = 1;         }       }     }     memset(tree, 0, sizeof tree);     for (int i = 1; i <= m; i++) {       for (auto it : R[i]) {         update(1, 1, n, it, i);       }       for (auto it : qr[i]) {         int mn = getMin(1, 1, n, it.first.first, it.first.second);         if (mn >= it.second.first) {           ans[it.second.second] = 1;         }       }     }     for (int i = 1; i <= q; i++) {       if (ans[i]) {         printf( YES n );       } else {         printf( NO n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long INF = 1ll << 60;   const double Inf = 1e20;   const double eps = 1e-9;   void gmax(int &a, int b) { a = (a > b ? a : b); }   void gmin(int &a, int b) { a = (a < b ? a : b); }   const int P = 1e9 + 7;   const int maxn = 1000050;   int n, m, x[5], y[5], sz[maxn], Ans;   set<int> key;   map<int, int> id, g;   vector<int> adj[maxn];   bool vis[maxn];   int calc(int x) {     int l = x, r = x, ret = 0;     while (l <= n) {       ret = (ret + min(r, n) - l + 1) % P;       l = l << 1;       r = r << 1 | 1;     }     return ret;   }   void dfs(int x, int t) {     Ans = (Ans + 1ll * sz[x] * t) % P;     vis[x] = true;     for (auto p : adj[x])       if (!vis[p]) dfs(p, t);     vis[x] = false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &x[i], &y[i]);       int t = x[i];       while (t) {         key.insert(t);         t >>= 1;       }       t = y[i];       while (t) {         key.insert(t);         t >>= 1;       }     }     key.insert(1);     for (auto p : key) {       if (key.find(p << 1) == key.end() && key.find(p << 1 | 1) == key.end())         g[p] = calc(p);       else {         g[p] = 1;         if (key.find(p << 1) == key.end() && (p << 1) <= n)           g[p << 1] = calc(p << 1);         if (key.find(p << 1 | 1) == key.end() && (p << 1 | 1) <= n)           g[p << 1 | 1] = calc(p << 1 | 1);       }     }     for (pair<int, int> p : g) {       id[p.first] = ((int)(id).size());       sz[id[p.first]] = p.second;     }     for (pair<int, int> p : id)       if (p.first != 1) {         adj[id[p.first >> 1]].push_back(p.second);         adj[p.second].push_back(id[p.first >> 1]);       }     for (int i = 1; i <= m; ++i)       adj[id[x[i]]].push_back(id[y[i]]), adj[id[y[i]]].push_back(id[x[i]]);     for (pair<int, int> p : id) dfs(p.second, sz[p.second]);     printf( %d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 7;   const int MX = 1e9 + 7;   const long long int INF = 1e18 + 9LL;   int n, m, k;   long long int value[N];   pair<long long int, pair<int, int> > edge[N];   int pt[N];   int rep[N];   int res = 0;   int Find(int a) {     if (rep[a] == a) return a;     return rep[a] = Find(rep[a]);   }   bool Union(int a, int b) {     a = Find(a), b = Find(b);     if (a == b) return false;     rep[a] = b;     return true;   }   void solve(int from, int to) {     int cnt = n;     for (int i = from; i <= to; ++i)       if (Union(edge[i].second.first, edge[i].second.second)) --cnt;     res = (res + pt[cnt]) % MX;     for (int i = from; i <= to; ++i)       rep[edge[i].second.first] = edge[i].second.first,       rep[edge[i].second.second] = edge[i].second.second;   }   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &value[i]);       rep[i] = i;     }     pt[0] = 1;     for (int i = 1; i < N; ++i) pt[i] = (pt[i - 1] + pt[i - 1]) % MX;     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       edge[i] = {value[u] ^ value[v], {u, v}};     }     long long int ok = pt[k];     sort(edge + 1, edge + m + 1);     for (int i = 1; i <= m; ++i) {       int t = i;       while (t < m && edge[t + 1].first == edge[t].first) ++t;       solve(i, t);       i = t;       --ok;     }     res = (res + 1LL * pt[n] * (ok % MX)) % MX;     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s;     while (n--) cin >> s;     bool wall = false;     int segments = 0, i = 0;     while (i < s.size()) {       if (!wall && s[i] ==  B ) {         segments++;         wall = true;       } else if (wall && s[i] ==  . ) {         wall = false;       }       i++;     }     cout << segments << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MAXN = (int)3e5 + 5;   long long n;   string s;   bool vr[27];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  a ) {         vr[0] = 1;         cout <<  Mike  <<   n ;       } else {         bool cnt = 1;         for (int j = 0; j < s[i] -  a ; j++) {           if (vr[j]) {             cnt = 0;             cout <<  Ann  <<   n ;             break;           }         }         if (cnt) {           vr[s[i] -  a ] = true;           cout <<  Mike  <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 200005;   const int mod = 998244353;   vector<int> graph[nax];   vector<int> degree(nax);   vector<int> level(nax);   vector<int> vis(nax);   vector<int> parent(nax);   vector<int> str[nax];   void dfs(int node, int l) {     vis[node] = 1;     level[node] = l + 1;     str[l + 1].push_back(node);     int d = 0;     for (auto i : graph[node]) {       if (vis[i] == 0) {         dfs(i, l + 1);         parent[i] = node;         d++;       }     }     degree[node] = d;     return;   }   void solve() {     int n;     cin >> n;     for (int i = 1; i < n + 1; i++) degree[i] = 0;     for (int i = 1; i < n + 1; i++) level[i] = 0;     for (int i = 1; i < n + 1; i++) parent[i] = 0;     for (int i = 1; i < n + 1; i++) vis[i] = 0;     for (int i = 1; i <= n; ++i) {       graph[i].clear();       str[i].clear();     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     dfs(1, 0);     int ans = 0;     for (int i = 1; i < n + 1; i++)       if (degree[i] == 0) ans++;     vector<int> rem(n + 1);     for (int i = n; i >= 2; i--) {       for (auto item : str[i]) {         if (degree[item] == 0) continue;         int check = 1;         for (auto child : graph[item]) {           if (level[child] > level[item] && rem[child] == 0) {             check = check & (!degree[child]);           }         }         if (check) {           rem[item] = 1;           degree[parent[item]]--;           if (degree[parent[item]] > 0) ans--;         }       }     }     cout << ans << endl;     return;   }   int main() {     int T;     T = 1;     scanf( %d , &T);     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int flag;       if (n & 1) {         flag = 2;         for (int i = 1, tmp; i <= n; i++) {           scanf( %1d , &tmp);           if ((i & 1) && (tmp & 1)) flag = 1;         }         printf( %d n , flag);       } else {         flag = 1;         for (int i = 1, tmp; i <= n; i++) {           scanf( %1d , &tmp);           if (!(i & 1) && !(tmp & 1)) flag = 2;         }         printf( %d n , flag);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const string T =  abacaba ;   bool check(string s) {     int cnt = 0;     for (int i = 0; i < s.length() - 6; i++)       if (s.substr(i, 7) == T) cnt++;     return (cnt == 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, f = 0, q = 0, qq = 0, p = 0;       cin >> n;       string s;       cin >> s;       bool flag = true;       for (int i = 0; i < n - 6; i++) {         string ss = s;         bool f = true;         for (int j = 0; j < 7; j++) {           if (s[i + j] != T[j] && s[i + j] !=  ? ) {             f = false;             break;           }           ss[i + j] = T[j];         }         if (f && check(ss)) {           flag = false;           cout <<  Yes  << endl;           for (int i = 0; i < n; i++) cout << ((ss[i] ==  ? ) ?  z  : ss[i]);           cout << endl;           break;         }       }       if (flag) cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[26];   bool work() {     char ch;     while (isalpha(ch = getchar())) ++cnt[ch -  a ];     int c = 0;     for (int x = 0; x < 26; ++x)       if (cnt[x] & 1) ++c;     return c == 0 || (c & 1);   }   int main() { puts(work() ?  First  :  Second ); }


#include <bits/stdc++.h>   const int mod = 998244353;   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   long long pwr(long long a, long long b) {     if (b == 0) {       return 1;     }     long long p = pwr(a, b / 2);     p = (p * p) % mod;     if (b % 2 != 0) {       p = (p * a) % mod;     }     return p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     while (m > n) {       a +=  0 ;       n++;     }     while (n > m) {       b +=  0 ;       m++;     }     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     long long ans = 0;     long long settillnow = 0;     for (long long i = 0; i < n; i++) {       if (b[i] ==  1 ) {         settillnow++;       }       if (a[i] ==  1 ) {         long long c = pwr(2, n - 1 - i);         c = (c * settillnow) % mod;         ans += c;         ans %= mod;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t, n, m, xa, ya, xb, yb;     scanf( %lld , &t);     while (t--) {       scanf( %lld%lld%lld%lld%lld%lld , &n, &m, &xa, &ya, &xb, &yb);       long long miny = min(ya, yb), minx = min(xa, xb), maxy = max(ya, yb),                 maxx = max(xa, xb);       long long s = (m - (maxy - miny)) * (n - (maxx - minx)) * 2;       long long lx = n - (maxx - minx), ly = m - (maxy - miny);       long long len1 = max(0ll, lx - (maxx - minx + 1) + 1),                 len2 = max(0ll, ly - (maxy - miny + 1) + 1);       printf( %lld n , max(0ll, n * m - (s - len1 * len2)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 5e3 + 7;   vector<vector<long long int> > v(N);   long long int cl[N];   void dfs(long long int s, long long int c) {     if (cl[s] == -1 || cl[s] == c) return;     cl[s] = c;     for (auto it = v[s].begin(); it != v[s].end(); it++) {       if (cl[*it] != c) dfs(*it, c);     }   }   int main() {     long long int n, m, s, i, j, k;     cin >> n >> m >> s;     memset(cl, 0, sizeof cl);     for (i = 0; i < m; i++) {       scanf( %lld%lld , &j, &k);       v[j].push_back(k);     }     dfs(s, -1);     for (i = 1; i <= n; i++) {       if (!cl[i]) dfs(i, i);     }     set<long long int> se;     for (i = 1; i <= n; i++) se.insert(cl[i]);     cout << se.size() - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e18;   const int INF = 0x3f3f3f3f;   int a[200010];   int dp[1000010];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       dp[a[i]] = 1;     }     int t = 0, p = 0;     int res = 0;     for (int i = 1; i <= 1e6; i++) {       t += dp[i];       if (i > m) t -= dp[i - m];       if (t == k) {         dp[i] = 0;         res++;         t--;       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int temp;   vector<long long int> v;   long long int n;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       long long int n, strt, cnst, lwr = 0, upr = 0, t, l, r, pt = 0, flag = 0;       cin >> n >> strt;       lwr = strt, upr = strt;       for (long long int i = 0; i < n; i++) {         cin >> t >> l >> r;         temp = t - pt;         lwr = lwr - temp;         upr = upr + temp;         if (lwr <= l && upr >= r)           lwr = l, upr = r;         else if (lwr <= l && upr <= r && upr >= l)           lwr = l;         else if (lwr >= l && upr >= r && lwr <= r)           upr = r;         else if (lwr > l && upr < r)           lwr = lwr, upr = upr;         else           flag = 1;         pt = t;       }       if (flag == 1)         cout <<  NO ;       else         cout <<  YES ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma optimize( O3 )   const int N = 200005;   int arr[N];   int fst[1000000], lst[1000000];   int minVal(int x, int y) { return (x < y) ? x : y; }   int getMid(int s, int e) { return s + (e - s) / 2; }   int RMQUtil(int *st, int ss, int se, int qs, int qe, int index) {     if (qs <= ss && qe >= se) return st[index];     if (se < qs || ss > qe) return INT_MAX;     int mid = getMid(ss, se);     return minVal(RMQUtil(st, ss, mid, qs, qe, 2 * index + 1),                   RMQUtil(st, mid + 1, se, qs, qe, 2 * index + 2));   }   int RMQ(int *st, int n, int qs, int qe) {     if (qs < 0 || qe > n - 1 || qs > qe) {       printf( Invalid Input );       return -1;     }     return RMQUtil(st, 0, n - 1, qs, qe, 0);   }   int constructSTUtil(int arr[], int ss, int se, int *st, int si) {     if (ss == se) {       st[si] = arr[ss];       return arr[ss];     }     int mid = getMid(ss, se);     st[si] = minVal(constructSTUtil(arr, ss, mid, st, si * 2 + 1),                     constructSTUtil(arr, mid + 1, se, st, si * 2 + 2));     return st[si];   }   int *constructST(int arr[], int n) {     int x = (int)(ceil(log2(n)));     int max_size = 2 * (int)pow(2, x) - 1;     int *st = new int[max_size];     constructSTUtil(arr, 0, n - 1, st, 0);     return st;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= q; i++) fst[i] = lst[i] = -1;     for (int i = 0; i < n; i++) {       cin >> arr[i];       fst[arr[i]] = (fst[arr[i]] == -1 ? i : fst[arr[i]]);       lst[arr[i]] = i;       if (arr[i] == 0) arr[i] = INT_MAX;     }     int *st = constructST(arr, n);     for (int i = 1; i <= q; i++) {       if (fst[i] == -1) continue;       int a = RMQ(st, n, fst[i], lst[i]);       if (a < i) {         cout <<  NO  << (  n );         return 0;       }     }     if (lst[q] == -1) {       bool b = false;       for (int i = 0; i < n; i++) {         if (arr[i] == INT_MAX) {           b = true, arr[i] = q;           break;         }       }       if (!b) {         cout <<  NO  << (  n );         return 0;       }     }     vector<int> pos;     for (int i = 0; i < n; i++)       if (arr[i] != INT_MAX) pos.push_back(i);     for (auto i : pos) {       int s = i - 1, e = i + 1;       bool poss = true;       while (poss) {         if (s >= 0 && arr[s] != INT_MAX) s = -1;         if (e < n && arr[e] != INT_MAX) e = n;         if (s >= 0) arr[s] = arr[i];         if (e < n) arr[e] = arr[i];         s--;         e++;         if (s < 0 && e >= n) poss = false;       }     }     cout <<  YES  << (  n );     for (int i = 0; i < n; i++) cout << arr[i] <<    ;     cout << (  n );   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int arr[100009], val[100009], n, k;   int ok(int x) {     long long res = 0;     for (int i = 1; i <= n; i++) res += (arr[i] + x - 1) / x;     return (res <= k);   }   long long f(int x, int y) {     int a = x % y, aa = x / y + 1;     int b = y - a, bb = x / y;     return aa * 1LL * aa * a + bb * 1LL * bb * b;   }   set<pair<long long, int> > s;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       val[i] = 1;       if (arr[i] > 1)         s.insert(make_pair(f(arr[i], val[i] + 1) - f(arr[i], val[i]), i));     }     for (int j = 0; j < k - n; j++) {       pair<long long, int> nd = *s.begin();       s.erase(nd);       int i = nd.second;       val[i]++;       if (val[i] < arr[i])         s.insert(make_pair(f(arr[i], val[i] + 1) - f(arr[i], val[i]), i));     }     long long res = 0;     for (int i = 1; i <= n; i++) res += f(arr[i], val[i]);     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check[41][41];   int above[41][41];   int dp[41][41][41][41];   int main() {     int n, m, q, s1, s2, s3, s4;     char s[42];     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++)         if (s[j] ==  0 ) check[i][j] = 1, above[i][j] = above[i - 1][j] + 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = i; k <= n; k++)           for (int l = j; l <= m; l++) {             dp[i][j][k][l] =                 dp[i][j][k - 1][l] + dp[i][j][k][l - 1] - dp[i][j][k - 1][l - 1];             int temp = min(k - i + 1, above[k][l]);             for (int p = l; p >= j; p--) {               temp = min(temp, above[k][p]);               if (temp == 0)                 break;               else                 dp[i][j][k][l] += temp;             }           }     for (int i = 0; i < q; i++)       scanf( %d %d %d %d , &s1, &s2, &s3, &s4),           printf( %d n , dp[s1][s2][s3][s4]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       set<int> used;       for (int i = 2; i * i <= n; i++) {         if (n % i == 0 && !used.count(i)) {           used.insert(i);           n /= i;           break;         }       }       for (int i = 2; i * i <= n; i++) {         if (n % i == 0 && !used.count(i)) {           used.insert(i);           n /= i;           break;         }       }       if (used.size() < 2 || used.count(n) || n == 1) {         cout <<  NO  << endl;       } else {         cout <<  YES               <<   n ;         used.insert(n);         for (auto it : used) cout << it <<    ;         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int n;       cin >> n;       vector<int> a(n);       for (int j = 0; j < n; ++j) {         cin >> a[j];         --a[j];       }       int pos = 0;       while (pos < n) {         int nxt = min_element(a.begin() + pos, a.end()) - a.begin();         int el = a[nxt];         a.erase(a.begin() + nxt);         a.insert(a.begin() + pos, el);         if (pos == nxt)           pos = nxt + 1;         else           pos = nxt;       }       for (auto it : a) cout << it + 1 <<    ;       cout << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef pair<int,int> PII;   const int maxn=111111,mod=998244353;   const double PI=3.141592653589793;   #define MP make_pair   #define PB push_back   #define lson o<<1,l,mid   #define rson o<<1|1,mid+1,r   #define FOR(i,a,b) for(int i=(a);i<=(b);i++)   #define ROF(i,a,b) for(int i=(a);i>=(b);i--)   #define MEM(x,v) memset(x,v,sizeof(x))   inline ll read(){    char ch=getchar();ll x=0,f=0;    while(ch< 0  || ch> 9 ) f|=ch== - ,ch=getchar();    while(ch>= 0  && ch<= 9 ) x=x*10+ch- 0 ,ch=getchar();    return f?-x:x;   }   inline int qpow(int a,int b){    int ans=1;    for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;    return ans;   }   int n,at,id[maxn],a[maxn],cnt,ans[maxn][2],al;   bool vis[maxn];   struct point{    int x,y,id;    point operator-(const point &p)const{return (point){x-p.x,y-p.y,id};}    double ang()const{return atan2(y,x);}    bool operator<(const point &p)const{     if(p.id==at) return false;     if(id==at) return true;     return ang()<p.ang();    }   }p[maxn],q[maxn];   inline void add(int x,int y){    ans[++al][0]=x;    ans[al][1]=y;    swap(a[x],a[y]);   }   void dfs(int x){    id[x]=cnt;    if(!id[a[x]]) dfs(a[x]);   }   int main(){    n=read();    FOR(i,1,n) p[i].x=read(),p[i].y=read(),a[i]=read(),p[i].id=i;    FOR(i,1,n) if(i!=a[i]){     if(!at || MP(p[i].x,p[i].y)<MP(p[at].x,p[at].y)) at=i;    }    if(!at) return puts( 0 ),0;    FOR(i,1,n) if(!id[i]) cnt++,dfs(i);    FOR(i,1,n) if(i!=at) p[i]=p[i]-p[at];    sort(p+1,p+n+1);    if(p[n].ang()-p[2].ang()>PI){     ROF(i,n,2) if(p[i].ang()-p[2].ang()<PI){      q[1]=p[1];      FOR(j,i+1,n) q[j-i+1]=p[j];      FOR(j,2,i) q[n-i+j]=p[j];      break;     }    }    else FOR(i,1,n) q[i]=p[i];    vis[id[q[2].id]]=true;    FOR(i,3,n) if(!vis[id[q[i].id]]){     add(q[i].id,q[i-1].id);     vis[id[q[i].id]]=true;    }    while(a[at]!=at) add(a[at],at);    printf( %d n ,al);    FOR(i,1,al) printf( %d %d n ,ans[i][0],ans[i][1]);   }


#ifndef _MY   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,abm,mmx,tune=native )   #endif   #include  bits/stdc++.h    #define int ll   #define all(x) (x).begin(), (x).end()   using namespace std;   typedef long long ll;   typedef long double ld;   const int64_t INF = (int64_t)(2e18);   const int inf = (int)(1e9 + 7);   const int maxn = 500 * 1000 + 100;   chrono::time_point<chrono::steady_clock> cl;   double current_time() { return (double)(chrono::steady_clock::now() - cl).count() / 1e9; }   //------------------------------------------//               int32_t main(){       cl = chrono::steady_clock::now();       ios_base::sync_with_stdio(false);       cout << fixed << setprecision(10);       cin.tie(nullptr);   #ifdef _MY       freopen( VimProject/input.txt ,  r , stdin);       freopen( VimProject/output.txt ,  w , stdout);   #endif          int n, k;       cin >> n >> k;       if (k == 1) {           cout << 0;           return 0;       }       vector<int> a(n);       vector<int> sieve(1300000, 1);       sieve[0] = sieve[1] = 0;       vector<int> primes;       map<int, vector<int>> ma;       vector<pair<int, vector<int>>> gen;       for (int i = 2; i < (int)sieve.size(); ++i){           if (sieve[i] == 0) continue;           primes.push_back(i);           for (int j = 2*i; j < (int)sieve.size(); j += i)               sieve[j] = 0;       }          auto isprime = [&](int aa)->bool{           if (aa > ll(100000)*ll(100000)) return false;           if (aa == 1) return false;           for (int i = 2; i * i <= aa; ++i){               if (aa % i == 0) return false;           }           return true;       };       for (auto& it : a) cin >> it;       for (auto& it : a){           int cur = it;           int rt = (int)sqrt((double)cur+0.1);           if (rt*rt == cur && isprime(rt))                ma[rt].push_back(cur);           else{               //cout << cur << endl;               map<int, int> dec;               for (auto& p : primes){                   if (p*p > cur) break;                   while(cur % p == 0) {                       dec[p]++;                       cur /= p;                   }               }               if (isprime(cur)) {                   dec[cur]++;                   cur = 1;               }               //for (auto& it : dec) cout << it.first <<     << it.second << endl;               if (cur != 1) continue;               if (dec.size() == 0) continue;               if (dec.size() == 1) ma[dec.begin()->first].push_back(it);               if (dec.size() >= 2) {                   gen.push_back(make_pair(it, vector<int>()));                   for (auto& itt : dec) gen.back().second.push_back(itt.first);               }           }       }       //for (auto& it : ma) {       //    cout << it.first <<  :  ;       //    for (auto& itt : it.second) cout << itt <<    ;       //    cout << endl;       //}       vector<int> bad;       for (auto& it : ma){           sort(all(it.second));           if (it.second.size() == 1)                bad.push_back(it.first);       }       for (auto& it : bad) ma.erase(it);          vector<int> res;       int cnt = 0;       for (auto& it : ma) cnt += (int)it.second.size();       if (cnt <= k){           for (auto& it : ma){               for (auto& itt : it.second)                   res.push_back(itt);           }           for (auto& it : gen){               if ((int)res.size() == k) break;               bool good = true;               for (auto& itt : it.second)                   if (ma.count(itt) == 0) good = false;               if (good) res.push_back(it.first);           }           if ((int)res.size() != k) cout << 0;           else for (auto& it : res) cout << it <<    ;           return 0;       } else{           for (auto& it : ma) reverse(all(it.second));           if (k % 2 == 0){               for (auto& it : ma) {                   if ((int)res.size() == k) break;                   for (int i = 0; i < 2; ++i){                       res.push_back(it.second.back());                       it.second.pop_back();                   }               }               for (auto& it : ma){                   for (auto& itt : it.second){                       if ((int)res.size() == k) break;                       res.push_back(itt);                       it.second.pop_back();                   }               }               for (auto& it: res) cout << it <<    ;               return 0;           } else {               int ok = -1;               for (auto& it : ma){                   if (ok != -1) break;                   if (it.second.size() > 2) ok = it.first;               }               if (ok != -1){                   for (int i = 0; i < 3; ++i){                       res.push_back(ma[ok].back());                       ma[ok].pop_back();                   }                   for (auto& it : ma){                       if (it.first == ok) continue;                       if ((int)res.size() == k) break;                       for (int i = 0; i < 2; ++i){                           res.push_back(it.second.back());                           it.second.pop_back();                       }                   }                   for (auto& it : ma){                       for (auto& itt : it.second){                           if ((int)res.size() == k) break;                           res.push_back(itt);                       }                   }                   for (auto& it : res) cout << it <<    ;               } else{                   pair<int, vector<int>> fine(-1, vector<int>());                   for (auto& it : gen){                       bool good = true;                       for (auto& itt : it.second)                           if (ma.count(itt) == 0) good = false;                       if (!good) continue;                       if (fine.first == -1 || fine.second.size() > it.second.size())                           fine = it;                   }                   if (fine.first == -1) {                       cout << 0;                       return 0;                   }                   res.push_back(fine.first);                   set<int> used;                   for (auto& it : fine.second){                       used.insert(it);                       for (int i = 0; i < 2; ++i){                           res.push_back(ma[it].back());                           ma[it].pop_back();                       }                   }                   if ((int)res.size() > k){                       cout << 0;                       return 0;                   }                   for (auto& it : ma){                       if (used.count(it.first)) continue;                       if ((int)res.size() == k) break;                       for (int i = 0; i < 2; ++i){                           res.push_back(it.second.back());                           it.second.pop_back();                       }                   }                   for (auto& it : ma){                       for (auto& itt : it.second){                           if ((int)res.size() == k) break;                           res.push_back(itt);                       }                   }                   for (auto& it : res) cout << it <<    ;               }           }          }             return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int inf = 1e9 + 10;   const long long INF = 1e18;   const long double EPS = 1e-10;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(25);     int t;     cin >> t;     while (t--) {       int n;       string s;       cin >> n >> s;       string ans =   ;       int idx = 0;       while (idx < n && s[idx] ==  0 ) {         ans += s[idx];         idx++;       }       s = s.substr(idx);       reverse(s.begin(), s.end());       n = s.size();       string ans2 =   ;       idx = 0;       while (idx < n && s[idx] ==  1 ) {         ans2 += s[idx];         idx++;       }       s = s.substr(idx);       n = s.size();       if (n) ans +=  0 ;       ans += ans2;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     for (int t = 0; t < test; t++) {       int n;       cin >> n;       int k = 2;       while (n % (int)(pow(2, k) - 1) != 0) {         k++;       }       int ans = n / (pow(2, k) - 1);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 1e5 + 5;   struct node {     int x, y;   } Node1[Max], Node2[Max];   int hash1[Max], hash2[Max];   bool cmp(const node a, const node b) {     if (a.y == b.y) return a.x < b.x;     return a.y < b.y;   }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       memset(hash1, 0, sizeof(hash1));       memset(hash2, 0, sizeof(hash2));       for (int i = 0; i < n; ++i) {         scanf( %d%d , &Node1[i].x, &Node1[i].y);         hash1[Node1[i].y]++;       }       for (int i = 0; i < m; ++i) {         scanf( %d%d , &Node2[i].x, &Node2[i].y);         hash2[Node2[i].y]++;       }       int coun = 0;       for (int i = 0; i <= 1000; ++i) {         if (hash1[i] > 0 && hash2[i] > 0)           coun += (max(hash1[i], hash2[i]) - abs(hash1[i] - hash2[i]));       }       sort(Node1, Node1 + n, cmp);       sort(Node2, Node2 + m, cmp);       int i = 0, j = 0, cou = 0;       while (i < n && j < m) {         if (Node1[i].y == Node2[j].y) {           if (Node1[i].x == Node2[j].x) {             cou++;             i++;             j++;           } else if (Node1[i].x < Node2[j].x)             i++;           else             j++;         } else if (Node1[i].y < Node2[j].y)           i++;         else           j++;       }       printf( %d %d n , coun, cou);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     if (a.size() - 1 > b.size()) {       cout <<  NO n ;       return 0;     }     if (a == b) {       cout <<  YES n ;       return 0;     }     int l = 0, r = m - 1;     while (a[l] == b[l] && l < min(n, m)) l++;     while (a.back() == b.back() && min(a.size(), b.size()) > l)       a.pop_back(), b.pop_back();     if (a.size() - l == 1 && a.back() ==  * ) {       cout <<  YES ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100010][400];   vector<int> nima[100010];   int a[100010], b[100010];   int n, m, s, e;   int main() {     while (cin >> n >> m >> s >> e) {       memset(dp, -1, sizeof(dp));       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i < m; ++i) {         scanf( %d , &b[i]);         nima[b[i]].push_back(i + 1);       }       int ans = 0;       int cnt = s / e;       for (int i = 0; i < n; ++i) {         dp[i][0] = 0;         if (nima[a[i]].size())           dp[i][1] = nima[a[i]][0];         else           dp[i][1] = -1;         if (i == 0) continue;         for (int j = 1; j <= cnt; ++j) {           unsigned int now = -1;           int w = a[i];           int last = dp[i - 1][j - 1];           now =               upper_bound(nima[w].begin(), nima[w].end(), last) - nima[w].begin();           if (now == nima[w].size() || dp[i - 1][j - 1] == -1) {             now = -1;           } else {             now = nima[w][now];           }           dp[i][j] = min(dp[i - 1][j], now);         }       }       for (int i = 0; i < n; ++i)         for (int j = 0; j < cnt + 1; ++j) {           if (dp[i][j] != -1) {             if (i + dp[i][j] + 1 + j * e <= s) ans = max(ans, j);           }         }       cout << ans << endl;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   struct compleks {     double x, y;   };   compleks operator*(compleks a, compleks b) {     compleks c;     c.x = a.x * b.x - a.y * b.y;     c.y = a.x * b.y + a.y * b.x;     return c;   }   compleks operator-(compleks a, compleks b) {     compleks c;     c.x = a.x - b.x, c.y = a.y - b.y;     return c;   }   compleks operator+(compleks a, compleks b) {     compleks c;     c.x = a.x + b.x, c.y = a.y + b.y;     return c;   }   int pos[65536 * 8];   void fft(compleks a[], int typ) {     for (int i = 0; i < 65536 * 8; i++)       if (pos[i] > i) swap(a[i], a[pos[i]]);     for (int p = 1; p < 65536 * 8; p <<= 1) {       int m = p + p;       compleks wx;       wx.x = cos(2 * 3.141592653589793 / m * typ),       wx.y = sin(2 * 3.141592653589793 / m * typ);       for (int i = 0; i < 65536 * 8; i += m) {         compleks w;         w.x = 1, w.y = 0;         for (int j = 0; j < p; j++, w = w * wx) {           compleks e = a[i + j], f = a[i + j + p] * w;           a[i + j] = e + f, a[i + j + p] = e - f;         }       }     }     if (typ == -1)       for (int i = 0; i < 65536 * 8; i++)         a[i].x /= 65536 * 8, a[i].y /= 65536 * 8;   }   void getpos() {     for (int i = 0; i < 65536 * 8; i++)       pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << 16 + 3 - 1);   }   int a[65536 * 8];   int n;   int x;   int pre[65536 * 8];   int cnt[65536 * 8];   compleks c[65536 * 8], d[65536 * 8];   int main() {     cin >> n >> x;     cnt[0]++;     long long di = 0;     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), pre[i] = pre[i - 1] + (a[i] < x), di += cnt[pre[i]],                           cnt[pre[i]]++;     getpos();     for (int i = 0; i <= n; i++)       c[i].x = cnt[i], d[-i + 65536 * 8 / 2].x = cnt[i];     fft(c, 1);     fft(d, 1);     for (int i = 0; i < 65536 * 8; i++) c[i] = c[i] * d[i];     fft(c, -1);     for (int i = 0; i <= n; i++) {       long long ai = (long long)(c[i + 65536 * 8 / 2].x + 0.5);       if (i == 0) ai = di;       printf( %lld  , ai);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, n, m, k, x, z, c, a[500007], b[500007], ans, bad, total;   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     set<long long> st;     for (i = 1; i <= n; i++) {       st.insert(a[i]);       if (st.find(i) != st.end()) st.erase(i);       if (st.size() == 0) c++;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> primes;   void Sieve(long long int n) {     vector<bool> prime(n + 1, true);     for (long long int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (prime[p]) primes.push_back(p);   }   vector<bool> vis;   long long int dia = 0;   long long int dfs(long long int x, vector<vector<long long int>>& vec) {     vis[x] = true;     priority_queue<long long int> pq;     for (auto it : vec[x]) {       if (vis[it] != true) pq.push(dfs(it, vec) + 1);     }     if (pq.size() == 0)       return 0;     else if (pq.size() == 1) {       long long int p = pq.top();       dia = max(dia, p);       return p;     } else {       long long int p = pq.top();       pq.pop();       long long int y = pq.top();       dia = max(dia, p + y);       return p;     }   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, a, b, da, db;       cin >> n;       cin >> a;       cin >> b;       cin >> da;       cin >> db;       vector<vector<long long int>> vec(n + 1);       for (long long int i = 0; i < n - 1; i++) {         long long int x, y;         cin >> x;         cin >> y;         vec[x].push_back(y);         vec[y].push_back(x);       }       vector<bool> visited(n + 1, 0);       queue<pair<long long int, long long int>> q;       q.push({a, 0});       long long int dis = 0;       while (!q.empty()) {         pair<long long int, long long int> p = q.front();         q.pop();         if (p.first == b) {           dis = p.second;           break;         }         for (auto it : vec[p.first]) {           if (!visited[it]) {             q.push({it, p.second + 1});             visited[it] = true;           }         }       }       vis = vector<bool>(n + 1, 0);       dfs(1, vec);       cout << (2 * da >= min(dia, db) || dis <= da ?  Alice  :  Bob ) <<   n ;       dia = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d;     cin >> d;     for (int i = 0; i < d; ++i) {       long long n;       cin >> n;       if (n * (n - 4) >= 0) {         cout <<  Y   << fixed << setprecision(9) << (n + sqrt(n * n - 4 * n)) / 2              <<     << n - (n + sqrt(n * n - 4 * n)) / 2;         cout <<   n ;       } else {         cout <<  N n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   char s[N], t[N];   int vis[N], vs[N];   int main() {     cin >> s + 1 >> t + 1;     int j = 1;     int n = strlen(s + 1);     int m = strlen(t + 1);     for (int i = 1; i <= n && j <= m; ++i) {       if (s[i] == t[j]) {         vis[j] = i;         ++j;       }     }     j = m;     for (int i = n; i >= 1 && j >= 1; --i) {       if (s[i] == t[j]) {         vs[j] = i;         --j;       }     }     int ans = max(vis[1] - 1, n - vis[m]);     ans = max(ans, vs[1] - 1);     ans = max(ans, n - vs[m]);     for (int i = 1; i <= m; ++i) {       ans = max(ans, vs[i] - vis[i - 1] - 1);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % 1000000007;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % 1000000007;       res %= 1000000007;     }     return res;   }   struct compare {     bool operator()(const pair<long long, long long> a,                     const pair<long long, long long> b) const {       return a.first < b.first;     }   };   void __solve__(long long testCase) {     long long x, y, ans = 2e18 + 7;     cin >> y >> x;     vector<long long> c(6);     for (long long &e : c) cin >> e;     for (long long i = 0; i < 3; i++)       for (long long j = 0; j < 3; j++) {         long long s = 0;         if (i == j) {           if (i == 0 && y == 0)             if (x > 0)               s += c[1] * x;             else               s += c[4] * -x;           if (i == 1 && x == 0)             if (y > 0)               s += c[5] * y;             else               s += c[2] * -y;           if (i == 2 && x == y)             if (x > 0)               s += c[0] * x;             else               s += c[3] * -x;           if (s) ans = min(ans, s);           continue;         } else if (i != 2 && j != 2) {           if (x > 0)             s += c[1] * x;           else             s += c[4] * -x;           if (y > 0)             s += c[5] * y;           else             s += c[2] * -y;         } else {           if (j == 0 || i == 0) {             if (y > 0)               s += c[0] * y;             else               s += c[3] * -y;             if (x - y > 0)               s += c[1] * (x - y);             else               s += c[4] * -(x - y);           } else {             if (x > 0)               s += c[0] * x;             else               s += c[3] * -x;             if (y - x > 0)               s += c[5] * (y - x);             else               s += c[2] * -(y - x);           }         }         ans = min(ans, s);       }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long testCase = 1;     cin >> testCase;     for (long long tc = 1; tc <= testCase; tc++) {       __solve__(tc);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 7;   const int inf = 1e9;   char s[60][60];   char s1[60];   int l;   int n;   int num[60];   int check(char *s) {     for (int i = 0; i < l; ++i) {       int j;       for (j = 0; j < l; ++j) {         if (s1[j] != s[(j + i) % l]) break;       }       if (j >= l) return i;     }     return -1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %s , s[i]);     l = strlen(s[0]);     int ans = inf;     for (int i = 0; i < l; ++i) {       int sum = 0;       for (int j = 0; j < l; ++j) s1[j] = s[0][(j + i) % l];       for (int j = 0; j < n; ++j) {         int t = check(s[j]);         if (t == -1) {           puts( -1 );           return 0;         }         sum += t;       }       ans = min(ans, sum);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[2][100];   int fun(char a, char b) {     if (a ==  8 ) {       if (b ==  [ )         return 1;       else if (b ==  ( )         return -1;       else         return 0;     }     if (a ==  [ ) {       if (b ==  8 )         return -1;       else if (b ==  ( )         return 1;       else         return 0;     }     if (a ==  ( ) {       if (b ==  [ )         return -1;       else if (b ==  8 )         return 1;       else         return 0;     }   }   int main() {     while (cin >> s[0] >> s[1]) {       int sum1 = 0, sum2 = 0;       for (int i = 0; s[0][i]; i += 2) sum1 += fun(s[0][i], s[1][i]);       if (sum1 > 0)         printf( TEAM 1 WINS n );       else if (sum1 < 0)         printf( TEAM 2 WINS n );       else         printf( TIE n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c1, c2;     cin >> c1 >> c2;     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  undefined  << endl;     } else {       int n1, n2;       switch (c1) {         case  ^ :           n1 = 1;           break;         case  > :           n1 = 2;           break;         case  v :           n1 = 3;           break;         case  < :           n1 = 4;           break;       }       switch (c2) {         case  ^ :           n2 = 1;           break;         case  > :           n2 = 2;           break;         case  v :           n2 = 3;           break;         case  < :           n2 = 4;           break;       }       n %= 4;       if (n1 != 4) {         if (n2 - n1 == 1) {           if (n == 1)             cout <<  cw  << endl;           else             cout <<  ccw  << endl;         } else {           if (n == 1)             cout <<  ccw  << endl;           else             cout <<  cw  << endl;         }       } else {         if (n1 - n2 == 3) {           if (n == 1)             cout <<  cw  << endl;           else             cout <<  ccw  << endl;         } else {           if (n == 1)             cout <<  ccw  << endl;           else             cout <<  cw  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int MOD = 1000000007;   long long power(long long a, long long n, long long m) {     if (n == 0) return 1;     long long p = power(a, n / 2, m);     p = (p * p) % m;     if (n % 2) p = (p * a) % m;     return p;   }   int fact[N];   int ifact[N];   int main() {     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = ((long long)i * fact[i - 1]) % MOD;     }     ifact[N - 1] = power(fact[N - 1], MOD - 2, MOD);     for (int i = N - 1; i >= 1; i--) {       ifact[i - 1] = ((long long)i * ifact[i]) % MOD;     }     int n;     scanf( %d , &n);     int ans = fact[2 * n - 1];     ans = ((long long)ans * ifact[n]) % MOD;     ans = ((long long)ans * ifact[n - 1]) % MOD;     ans = (2 * ans) % MOD;     ans = (ans - n + MOD) % MOD;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long summ(long long a) {     long long ans = 0;     while (a) {       ans += a % 10;       a = a / 10;     }     return ans;   }   long long digit(int n) {     int count = 0;     while (n) {       n = n / 10;       count++;     }     return count;   }   long long sum(long long a) {     long long ans = 0;     while (a) {       ans += (a % 10);       a = a / 10;     }     return ans;   }   int main() {     long long n;     cin >> n;     long long a = n;     long long b;     long long count = 0;     while (a) {       b = a % 10;       a = a / 10;       count++;     }     count--;     b--;     b = b * pow(10, count);     long long c = 0;     for (int i = 0; i < count; i++) {       c = (10 * c) + 9;     }     b = b + c;     c = n - b;     cout << sum(b) + sum(c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long k, x;   long long a[200010];   int main() {     int n;     while (cin >> n >> k >> x) {       int negative = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] < 0) ++negative;       }       if (negative % 2 == 0) {         int minId = 0;         for (int i = 1; i < n; i++) {           if (abs(a[i]) < abs(a[minId])) minId = i;         }         long long num = abs(a[minId]) / x + 1;         if (a[minId] >= 0)           a[minId] -= min(num, k) * x;         else           a[minId] += min(num, k) * x;         k = max(k - num, 0LL);       }       priority_queue<pair<long long, int>, vector<pair<long long, int> >,                      greater<pair<long long, int> > >           que;       for (int i = 0; i < n; i++) {         que.push(make_pair(abs(a[i]), i));       }       while (k--) {         pair<int, int> cur = que.top();         que.pop();         int id = cur.second;         if (a[id] >= 0)           a[id] += x;         else           a[id] -= x;         que.push(make_pair(abs(a[id]), id));       }       for (int i = 0; i < n; i++) {         if (i != n - 1)           cout << a[i] <<    ;         else           cout << a[i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double PI = acos(-1.0);   using namespace std;   double dp[1005][1005];   int main(void) {     int n, m;     scanf( %d %d , &n, &m);     if (n == 1) {       puts( 1.0000000 );       return 0;     }     dp[0][0] = 1;     for (int i = 1; i <= n - 1; i++) {       dp[i][0] = dp[i - 1][0] * (1 - (m - 1.0) / (n * m - i));       for (int j = 1; j <= i && j <= m; j++) {         dp[i][j] = dp[i - 1][j - 1] * (m - j + 0.0) / (n * m - i) +                    dp[i - 1][j] * (1 - (m - j - 1.0) / (n * m - i));       }     }     double ans = 0;     for (int i = 0; i <= n - 1; i++) {       ans += dp[n - 1][i] * (i + 1.0) / n;     }     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     std::vector<std::pair<int, int> > a(n + 1);     for (int p = 0; p < n; p++) {       int x;       scanf( %d , &x);       a[p] = std::make_pair(x, p + 1);     }     sort(++a.begin(), a.end(), std::greater<std::pair<int, int> >());     int ind(0);     std::vector<std::pair<int, int> > comm;     for (int p = 0; p < n; p++) {       for (int q = ind + 1; q <= ind + a[p].first; q++) {         if (q >= n) {           break;         }         comm.push_back(std::make_pair(a[p].second, a[q].second));       }       ind += a[p].first;       if (ind <= p) {         break;       }     }     if (comm.size() < n - 1) {       puts( -1 );     } else {       printf( %d n , n - 1);       for (int p = 0; p < comm.size(); p++) {         printf( %d %d n , comm[p].first, comm[p].second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200005;   int main() {     long long n, z, x, y;     cin >> n;     z = (n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120;     x = (z * (n - 5)) / 6;     y = (x * (n - 6)) / 7;     cout << z + x + y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   int main(int argc, char* argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     int n;     cin >> n;     auto g = vector<vector<ll>>(n, vector<ll>(n, 2000000000));     for (int i = 0; i < (n - 1); ++i)       for (int j = 0; j < (n - i - 1); ++j) {         int d;         cin >> d;         g[i][i + j + 1] = g[i + j + 1][i] = d;       }     auto min_adj = vector<ll>(n);     for (int i = 0; i < (n); ++i)       min_adj[i] = *min_element((g[i]).begin(), (g[i]).end());     auto smallest = *min_element((min_adj).begin(), (min_adj).end());     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (n); ++j) g[i][j] -= smallest;     auto dist = move(min_adj);     for (int i = 0; i < (n); ++i) dist[i] = 2 * (dist[i] - smallest);     auto done = vector<char>(n, false);     for (int _ = 0; _ < (n); ++_) {       int v = -1;       for (int i = 0; i < (n); ++i)         if (!done[i] && (v == -1 || dist[i] < dist[v])) v = i;       done[v] = true;       for (int i = 0; i < (n); ++i) dist[i] = min(dist[i], dist[v] + g[i][v]);     }     for (int i = 0; i < (n); ++i) cout << dist[i] + (n - 1) * smallest <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 99;   int n, m, pre[maxn], nxt[maxn], vst[maxn], flag[maxn];   vector<int> G[maxn];   void del(int i) {     nxt[pre[i]] = nxt[i];     if (~nxt[i]) pre[nxt[i]] = pre[i];   }   void bfs(int id) {     queue<int> que;     que.push(id);     while (!que.empty()) {       int now = que.front();       que.pop();       for (int x : G[now])         if (!vst[x]) flag[x] = 1;       for (int i = nxt[0]; ~i; i = nxt[i]) {         if (flag[i])           flag[i] = 0;         else           vst[i] = 1, que.push(i), del(i);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     nxt[0] = 1;     nxt[n] = -1;     for (int i = 1; i < n; i++) pre[i + 1] = i, nxt[i] = i + 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (vst[i]) continue;       ans++;       bfs(i);     }     cout << ans - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[200001];   int main() {     memset(t, 0x3f, sizeof(t));     int n, k;     string str;     cin >> n >> k >> str;     for (int x = 0; x < n; x++)       if (str[x] == str[(x + 1) % n] || str[x] == str[(x - 1 + n) % n]) t[x] = 0;     for (int x = 0; x < 2 * n; x++)       t[x % n] = min(t[x % n], t[(x - 1 + n) % n] + 1);     for (int x = 2 * n - 1; x >= 0; x--)       t[x % n] = min(t[x % n], t[(x + 1) % n] + 1);     for (int x = 0; x < n; x++)       if (min(t[x], k) % 2) str[x] = 153 - str[x];     cout << str << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   int main() {     int n;     while (scanf( %d , &n) != -1) {       if (n == 1) {         printf( 1 n );         continue;       }       if ((n & 1) && (n - 1) % 4) {         printf( -1 n );         continue;       }       if (!(n & 1) && n % 4) {         printf( -1 n );         continue;       }       for (int i = 1; i + i <= n; i += 2)         arr[i] = i + 1, arr[i + 1] = n - i + 1, arr[n - i + 1] = n - i,         arr[n - i] = i;       if (n % 2) arr[n / 2 + 1] = n / 2 + 1;       for (int i = 1; i <= n; ++i) printf(i > 1 ?   %d  :  %d , arr[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9;   const long long mod = 1e9 + 7;   bool dp[105][55][2][2][205];   string s;   int n, sz, realans;   int offset(int x) { return x + 100; }   bool f(int idx, int sisa, bool flip, bool arah, int ans) {     if (idx == sz + 1) {       if (sisa == 0) {         realans = max(realans, abs(ans));       }       return 1;     }     bool &res = dp[idx][sisa][flip][arah][offset(ans)];     if (res == 1) return res;     char now = s[idx - 1];     if (flip) {       if (now ==  F )         now =  T ;       else         now =  F ;     }     if (now ==  F ) {       res = f(idx + 1, sisa, 0, arah, ans + (arah ? 1 : -1));       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     } else if (now ==  T ) {       res = f(idx + 1, sisa, 0, !arah, ans);       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     }     return res = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     cin >> n;     sz = s.size();     f(1, n, 0, 1, 0);     cout << realans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[500005], tot, s[500005], c[500005], tmp[1500005], num;   priority_queue<int> q;   bool cmp(int x, int y) { return x > y; }   int main() {     long long ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i];     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) {       if (i == 1 || a[i] != a[i - 1])         s[++tot] = a[i], c[tot]++;       else         c[tot]++;     }     int sum = 0;     for (int i = 1; i <= tot; i++) {       int pt = min((int)(sum - (int)2 * q.size()), c[i]);       int rst = min(c[i] - pt, sum - pt);       num = 0;       for (int j = 1; j <= pt; j++) tmp[++num] = s[i];       for (int j = 1; j <= rst; j += 2) {         int k = -q.top();         q.pop();         if (k < s[i]) {           tmp[++num] = s[i];           if (j < rst) tmp[++num] = s[i];         } else {           tmp[++num] = k;           if (j < rst) tmp[++num] = 2 * s[i] - k;         }       }       for (int j = 1; j <= num; j++)         if (tmp[j] >= 0) q.push(-tmp[j]);       sum += c[i];     }     while (!q.empty()) ans += q.top(), q.pop();     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int ar[2111111], br[2111111], cr[2111111], dr[2111111];   int main() {     cin.sync_with_stdio(false);     int n, i, j, x, y, pos, m;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ar[i];       if (ar[i] == 0) pos = i;     }     for (i = n + 1; i < n + n; i++) ar[i] = ar[i - n];     for (j = 1, i = pos + 1; i <= pos + n - 1; i++, j++) cr[j] = ar[i];     m = j - 1;     for (i = m + 1; i <= m + m; i++) cr[i] = cr[i - m];     for (i = 1; i <= n; i++) {       cin >> br[i];       if (br[i] == 0) pos = i;     }     for (i = n + 1; i < n + n; i++) br[i] = br[i - n];     for (j = 1, i = pos + 1; i <= pos + n - 1; i++, j++) dr[j] = br[i];     for (i = 1; i <= m + m; i++)       if (cr[i] == dr[1]) {         pos = i;         break;       }     bool cond = true;     for (j = 1, i = pos; i <= pos + m - 1 && cond; i++, j++)       if (cr[i] != dr[j]) cond = false;     if (cond)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;   template <class T1, class T2>   inline void gadd(T1 &a, T2 b) {     a = (a + b) % Z;   }   int casenum, casei;   int D, n, m;   int lft[N], rgt[N], bot[N], top[N];   struct A {     int l, r, t, b;   } a[N];   int main() {     while (~scanf( %d%d%d , &D, &n, &m)) {       memset(lft, 0, sizeof(lft));       memset(rgt, 0, sizeof(rgt));       memset(top, 0, sizeof(top));       memset(bot, 0, sizeof(bot));       int x1, y1, x2, y2;       for (int i = 1; i <= D; ++i) {         scanf( %d%d%d%d , &x1, &y1, &x2, &y2);         if (x1 > x2) swap(x1, x2);         if (y1 > y2) swap(y1, y2);         a[i] = {x1, x2, y2, y1};         ++lft[x1];         ++rgt[x2];         ++bot[y1];         ++top[y2];       }       for (int i = 1; i <= n + 1; ++i) {         lft[i] += lft[i - 1];       }       for (int i = 1; i <= m + 1; ++i) {         bot[i] += bot[i - 1];       }       for (int i = n; i >= 0; --i) {         rgt[i] += rgt[i + 1];       }       for (int i = m; i >= 0; --i) {         top[i] += top[i + 1];       }       int L, R, T, B;       scanf( %d%d%d%d , &L, &R, &T, &B);       int ans = -1;       for (int i = 1; i <= D; ++i) {         int lr = (a[i].r > a[i].l);         int tb = (a[i].t > a[i].b);         if (lft[a[i].r - 1] - lr == L && rgt[a[i].l + 1] - lr == R &&             top[a[i].b + 1] - tb == B && bot[a[i].t - 1] - tb == T) {           ans = i;           break;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int n, m, c[256];   int main() {     int a, j;     scanf( %d%d , &n, &m);     memset(c, -1, sizeof(c));     for (int i = 0; i < n; ++i) {       scanf( %d , &a);       if (~c[a])         printf( %d  , c[a]);       else {         j = a;         while (j && !~c[j - 1] && j > a - m + 1) --j;         if (j && ~c[j - 1] && a - c[j - 1] < m)           c[j] = c[j - 1];         else           c[j] = j;         for (int k = j + 1; k <= a; ++k) c[k] = c[j];         printf( %d  , c[j]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   long long a[200000 + 5];   int main() {     long long i, j, k, l;     long long n, m;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     a[n] = 2000000009;     long long maxn = 0;     k = 0;     for (i = 1; i <= n; i++) {       if (a[i] > a[i - 1] * 2) {         maxn = max(maxn, i - k);         k = i;       }     }     cout << maxn << endl;   }


#include <bits/stdc++.h>   const double pi = 3.141592653589793238462643383279;   using namespace std;   long long GCD(long long a, long long b) {     if (b == 0) return a;     return GCD(b, a % b);   }   int arr[1000010];   int rev[1000010];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << fixed << setprecision(10);     int n;     cin >> n;     string s;     cin >> s;     if (s[0] ==  )  && s[s.size() - 1] ==  ( ) {       cout << 0 << endl;       return 0;     } else if (s[0] ==  ) ) {       arr[0]++;       arr[1] += arr[0];       bool f = true;       for (int i = 1; i < s.size(); i++) {         if (s[i] ==  ( )           arr[i]++;         else           arr[i]--;         arr[i + 1] += arr[i];         if (arr[i] < 0) f = false;       }       if (f && arr[s.size() - 1] == 0)         cout << 1 << endl;       else         cout << 0 << endl;       return 0;     } else if (s[s.size() - 1] ==  ( ) {       bool f = true;       for (int i = 0; i < s.size() - 1; i++) {         if (s[i] ==  ( )           arr[i]++;         else           arr[i]--;         arr[i + 1] += arr[i];         if (arr[i] < 0) f = false;       }       arr[s.size() - 1]--;       if (f && arr[s.size() - 1] == 0)         cout << 1 << endl;       else         cout << 0 << endl;       return 0;     }     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ( ) {         arr[i]++;       } else {         arr[i]--;       }       arr[i + 1] += arr[i];     }     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  ( ) {         rev[i]++;       } else {         rev[i]--;       }       rev[i] += rev[i + 1];     }     if (arr[s.size() - 1] == 2) {       int ans = 0;       for (int i = 0; i < s.size(); i++) {         if (arr[i] < 0) {           cout << 0 << endl;           return 0;         }       }       for (int i = s.size() - 1; i >= 0; i--) {         if (arr[i] <= 1) break;         if (s[i] ==  ( ) ans++;       }       cout << ans << endl;     } else if (arr[s.size() - 1] == -2) {       int ans = 0;       for (int i = 0; i < s.size(); i++) {         if (arr[i] <= -3) {           cout << 0 << endl;           return 0;         }       }       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  ) ) {           ans++;           if (arr[i] < 0) {             break;           }         }       }       cout << ans << endl;     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000210;   inline int scan() {     char c = getchar();     int x = 0;     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x;   }   long long int n, m;   long long int a[N];   long long int parent[N];   long long int sz[N];   void reset() {     for (long long int i = 0; i <= n; i++) parent[i] = i, sz[i] = 1;   }   long long int findparent(long long int x) {     if (x != parent[x]) return findparent(parent[x]);     return parent[x];   }   void merge(long long int x, long long int y) {     x = findparent(x);     y = findparent(y);     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     parent[y] = x;   }   vector<long long int> g[N];   vector<long long int> l[N];   bool comp1(long long int x, long long int y) { return x < y; }   bool comp2(long long int x, long long int y) { return x > y; }   long long int minparent = INT_MAX, maxparent = INT_MIN;   int main() {     scanf( %lld %lld , &n, &m);     for (long long int i = 1; i <= n; i++) scanf( %lld , &a[i]);     reset();     while (m--) {       long long int a, b;       scanf( %lld %lld , &a, &b);       merge(a, b);     }     for (long long int i = 1; i <= n; i++) {       g[findparent(i)].push_back(i);       l[findparent(i)].push_back(a[i]);       minparent = min(minparent, parent[i]);       maxparent = max(maxparent, parent[i]);     }     for (long long int i = 1; i <= n; i++) {       if (findparent(i) == i) {         sort(l[i].begin(), l[i].end(), comp2);         sort(g[i].begin(), g[i].end(), comp1);         for (long long int j = 0; j < g[i].size(); j++) {           a[g[i][j]] = l[i][j];         }       }     }     for (long long int i = 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MAXN = 200000;   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   int a[200000];   vector<pair<double, double> > lines;   double intersection(pair<double, double> a, pair<double, double> b) {     double x = (a.second - b.second) / (a.first - b.first);     double y = (a.first * x) - a.second;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     RI(n);     for (int i = 0; i < int(n); i++) RI(a[i]);     double c = 0;     lines.push_back(make_pair(0, 0));     for (int i = 0; i < int(n); i++) {       c = c + a[i];       lines.push_back(make_pair(i + 1, c));     }     vector<int> s1;     vector<int> s2;     s1.push_back(n);     s1.push_back(n - 1);     for (int j = n - 2; j >= 0; j--) {       while (1) {         if (s1.size() == 1) {           break;         }         if (intersection(lines[s1[s1.size() - 2]], lines[j]) >=             intersection(lines[s1[s1.size() - 2]], lines[s1[s1.size() - 1]])) {           s1.pop_back();         } else {           break;         }       }       s1.push_back(j);     }     s2.push_back(0);     s2.push_back(1);     for (int j = 2; j <= n; j++) {       while (1) {         if (s2.size() == 1) {           break;         }         if (intersection(lines[s2[s2.size() - 2]], lines[j]) >=             intersection(lines[s2[s2.size() - 2]], lines[s2[s2.size() - 1]])) {           s2.pop_back();         } else {           break;         }       }       s2.push_back(j);     }     int curr_line = 0;     double ans = 1000000000.0;     for (int j = 0; j < s2.size() - 1; j++) {       double inter1 = intersection(lines[s2[j]], lines[s2[j + 1]]);       while (1) {         if (curr_line >= s1.size() - 1) {           break;         }         double inter =             intersection(lines[s1[curr_line]], lines[s1[curr_line + 1]]);         if (inter <= inter1) {           break;         } else {           curr_line++;         }       }       double y1 = (lines[s2[j]].first * inter1) - lines[s2[j]].second;       double y2 =           (lines[s1[curr_line]].first * inter1) - lines[s1[curr_line]].second;       ans = min(abs(y2 - y1), ans);     }     curr_line = 0;     for (int j = 0; j < s1.size() - 1; j++) {       double inter1 = intersection(lines[s1[j]], lines[s1[j + 1]]);       while (1) {         if (curr_line >= s2.size() - 1) {           break;         }         double inter =             intersection(lines[s2[curr_line]], lines[s2[curr_line + 1]]);         if (inter <= inter1) {           break;         } else {           curr_line++;         }       }       double y1 = (lines[s1[j]].first * inter1) - lines[s1[j]].second;       double y2 =           (lines[s2[curr_line]].first * inter1) - lines[s2[curr_line]].second;       ans = min(abs(y2 - y1), ans);     }     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool judge(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y )       return false;     else       return true;   }   int main() {     char a[110];     int n, m = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (judge(a[i])) {         cout << a[i];         m = 0;       } else if (m == 1)         continue;       else if (!judge(a[i]))         cout << a[i], m = 1;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize(4)   using namespace std;   const int N = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-8;   const double PI = acos(-1);   template <class T, class S>   inline void add(T &a, S b) {     a += b;     if (a >= mod) a -= mod;   }   template <class T, class S>   inline void sub(T &a, S b) {     a -= b;     if (a < 0) a += mod;   }   template <class T, class S>   inline bool chkmax(T &a, S b) {     return a < b ? a = b, true : false;   }   template <class T, class S>   inline bool chkmin(T &a, S b) {     return a > b ? a = b, true : false;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, m, k, q;   int mx[N], mn[N];   int cnt;   int tot[N];   map<int, long long> Map[N];   vector<int> V;   int calc(int p, int p1, int p2) { return abs(p - p1) + abs(p1 - p2); }   int main() {     memset(mx, 0xc0, sizeof(mx));     memset(mn, 0x3f, sizeof(mn));     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = 1; i <= k; i++) {       int r, c;       scanf( %d%d , &r, &c);       chkmax(mx[r], c);       chkmin(mn[r], c);       tot[r]++;       cnt++;     }     if (!cnt) {       puts( 0 );       return 0;     }     while (!tot[n]) n--;     V.push_back(0);     V.push_back(m + 1);     for (int i = 1; i <= q; i++) {       int b;       scanf( %d , &b);       V.push_back(b);     }     sort((V).begin(), (V).end());     if (tot[1]) {       Map[1][mx[1]] = mx[1] - 1;     } else {       Map[1][1] = 0;     }     for (int i = 1; i < n; i++) {       assert(((int)Map[i].size()) <= 2);       int d = 1;       int cur = i;       while (!tot[i + 1]) {         i++;         d++;       }       for (auto &t : Map[cur]) {         int p = t.first;         long long val = t.second;         int pos = lower_bound((V).begin(), (V).end(), p) - V.begin();         if (V[pos] != m + 1) {           long long dis = abs(V[pos] - p) + d;           long long nVal = calc(V[pos], mn[i + 1], mx[i + 1]);           if (!Map[i + 1].count(mx[i + 1])) {             Map[i + 1][mx[i + 1]] = val + dis + nVal;           } else {             chkmin(Map[i + 1][mx[i + 1]], val + dis + nVal);           }           nVal = calc(V[pos], mx[i + 1], mn[i + 1]);           if (!Map[i + 1].count(mn[i + 1])) {             Map[i + 1][mn[i + 1]] = val + dis + nVal;           } else {             chkmin(Map[i + 1][mn[i + 1]], val + dis + nVal);           }         }         pos--;         if (V[pos] != 0) {           long long dis = abs(V[pos] - p) + d;           long long nVal = calc(V[pos], mn[i + 1], mx[i + 1]);           if (!Map[i + 1].count(mx[i + 1])) {             Map[i + 1][mx[i + 1]] = val + dis + nVal;           } else {             chkmin(Map[i + 1][mx[i + 1]], val + dis + nVal);           }           nVal = calc(V[pos], mx[i + 1], mn[i + 1]);           if (!Map[i + 1].count(mn[i + 1])) {             Map[i + 1][mn[i + 1]] = val + dis + nVal;           } else {             chkmin(Map[i + 1][mn[i + 1]], val + dis + nVal);           }         }       }       Map[cur].clear();     }     long long ans = INF;     for (auto &t : Map[n]) {       chkmin(ans, t.second);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[55][55];   int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1}, n, vis[55][55];   bool check(int x, int y) {     for (int i = 0; i < 4; i++) {       int tx = x + dx[i], ty = y + dy[i];       if (tx < 1 || tx > n || ty < 1 || ty > n || s[tx][ty] ==  #  || vis[tx][ty])         return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j] || s[i][j] ==  # ) continue;         if (check(i, j)) {           vis[i][j] = 1;           for (int k = 0; k < 4; k++) vis[i + dx[k]][j + dy[k]] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j])           continue;         else if (s[i][j] ==  # )           continue;         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool notis[30] = {false}, mayis[30] = {false};   string str;   int main() {     int n, flag = 0, cnt = 0, tem, i, j;     char p;     std::ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) {       cin >> p >> str;       if (flag && (p ==  !  || p ==  ? ))         cnt++;       else {         tem = str.length();         if (p ==  ! ) {           for (j = 0; j < tem; j++) mayis[str[j] -  a ] = true;           for (j = 0; j < 26; j++) {             if (!mayis[j]) notis[j] = true;             mayis[j] = false;           }         } else           for (j = 0; j < tem; j++) notis[str[j] -  a ] = true;         for (tem = j = 0; j < 26; j++)           if (!notis[j]) tem++;         if (tem == 1) flag = 1;       }     }     printf( %d , cnt > 0 ? (cnt - 1) : 0);   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long N = 5e5 + 1;   bool prime[N];   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<vector<long long>> v(k);     long long cnt = 0, c = 0;     string t = s;     bool f = 0;     while (1) {       bool b = 0;       for (long long i = 0; i < n; i++) {         if (t[i] ==  R  && t[i + 1] ==  L ) {           if (cnt >= k) {             f = 1;             break;           }           b = 1;           t[i] =  L ;           t[i + 1] =  R ;           i++;           v[cnt].push_back(i);           c++;         }       }       if (f) break;       if (b == 0) break;       cnt++;     }     if (cnt > k || c < k || f) {       cout << -1 <<   n ;       return;     } else if (cnt == k) {       for (auto i : v) {         cout << i.size() <<    ;         for (auto j : i) cout << j <<    ;         cout <<   n ;       }     } else {       long long t = cnt - 1, b = k - 1;       while (t < b) {         long long m = v[t].size();         while (!v[t].empty()) {           v[b].push_back(v[t].back());           b--;           v[t].pop_back();           if (t >= b) break;         }         if (t == b && v[t].size()) break;         t--;       }       for (auto i : v) {         cout << i.size() <<    ;         for (auto j : i) cout << j <<    ;         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));     n = v.size();     for (int i = 2; i < n; i++) {       int a = v[i - 2];       int b = v[i - 1];       int c = v[i];       if (a + 1 == b && b + 1 == c) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[maxn], b[maxn];   int main() {     int n, x, T;     cin >> T;     while (T--) {       cin >> n;       set<int> s;       s.clear();       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) {         scanf( %d , &b[i]);       }       int l = 1, r = n;       while (l <= n && a[l] == b[l]) l++;       while (r >= 1 && a[r] == b[r]) r--;       if (l > r) {         cout <<  YES n ;         continue;       }       int flag = 1;       if (a[l] - b[l] > 0) flag = 0;       for (int i = l + 1; i <= r; i++) {         if (a[l] - b[l] != a[i] - b[i]) flag = 0;       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, sum, ans, a[100005];   inline long long read() {     long long q = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (isdigit(ch)) {       q = (q << 3) + (q << 1) + (ch ^ 48);       ch = getchar();     }     return f ? q : -q;   }   inline void print(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) a[i] = read(), sum += a[i];     sort(a + 1, a + n + 1, greater<long long>());     for (register long long i = 1; i <= (sum % n); ++i)       ans += abs(a[i] - sum / n - 1);     for (register long long i = (sum % n) + 1; i <= n; ++i)       ans += abs(a[i] - sum / n);     print(ans >> 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 66666;   const int M = 55;   const int sM = 105;   const int inf = 1e9 + 7;   const double pi = acos(-1);   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 * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   int lim, pp[N];   struct CP {     double x, y;     CP(double xx = 0, double yy = 0) { x = xx, y = yy; }   };   CP operator+(CP aa, CP bb) { return CP(aa.x + bb.x, aa.y + bb.y); }   CP operator-(CP aa, CP bb) { return CP(aa.x - bb.x, aa.y - bb.y); }   CP operator*(CP aa, CP bb) {     return CP(aa.x * bb.x - aa.y * bb.y, aa.x * bb.y + aa.y * bb.x);   }   void FFT(CP *f, int flag) {     for (int i = (0), iE = (lim - 1); i <= iE; i++)       if (i < pp[i]) swap(f[i], f[pp[i]]);     for (int i = 2; i <= lim; i <<= 1) {       CP ch(cos(2 * pi / i), flag * sin(2 * pi / i));       for (int l = (i >> 1), j = 0; j < lim; j += i) {         CP now(1, 0);         for (int k = j; k < j + l; k++) {           CP pa = f[k], pb = now * f[k + l];           f[k] = pa + pb, f[k + l] = pa - pb, now = now * ch;         }       }     }     if (flag == -1)       for (int i = (0), iE = (lim - 1); i <= iE; i++)         f[i].x /= lim, f[i].y /= lim;   }   CP A[N], B[N];   int n, m, t, x, dis[N];   int fu[N], fv[N], fval[N];   double ans[M][N], p[sM][N], calc[sM][N];   void Solve(int l, int mid, int r) {     for (int d = (1), dE = (m); d <= dE; d++) {       int tota = -1, totb = 0;       B[0] = CP(0, 0);       for (int i = (l), iE = (mid); i <= iE; i++)         A[++tota] = CP(ans[fv[d]][i], 0);       for (int i = (1), iE = (min(r - l + 1, t)); i <= iE; i++)         B[++totb] = CP(p[d][i], 0);       for (lim = 1; lim <= tota + totb; lim <<= 1)         ;       for (int i = (0), iE = (lim - 1); i <= iE; i++)         pp[i] = ((pp[i >> 1] >> 1) | ((i & 1) * (lim >> 1)));       for (int i = (tota + 1), iE = (lim - 1); i <= iE; i++) A[i] = CP(0, 0);       for (int i = (totb + 1), iE = (lim - 1); i <= iE; i++) B[i] = CP(0, 0);       FFT(A, 1), FFT(B, 1);       for (int i = (0), iE = (lim - 1); i <= iE; i++) A[i] = A[i] * B[i];       FFT(A, -1);       for (int i = (1), iE = (r - mid); i <= iE; i++)         calc[d][i + mid] += A[i + tota].x;     }   }   void Divide(int l, int r) {     if (l == r) {       for (int j = (1), jE = (m); j <= jE; j++)         ans[fu[j]][l] = min(ans[fu[j]][l], calc[j][l] + fval[j]);       return;     }     int mid = (l + r) / 2;     Divide(l, mid);     Solve(l, mid, r);     Divide(mid + 1, r);   }   int main() {     n = read(), m = read(), t = read(), x = read();     dis[n] = 0;     for (int i = (1), iE = (n - 1); i <= iE; i++) dis[i] = inf;     for (int i = (1), iE = (n - 1); i <= iE; i++)       for (int j = (t), jE = (t * 2); j <= jE; j++) ans[i][j] = inf;     for (int i = (1), iE = (m); i <= iE; i++) {       fu[i] = read(), fv[i] = read(), fval[i] = read();       for (int j = (1), jE = (t); j <= jE; j++) p[i][j] = 1. * read() / 100000;     }     for (int i = (1), iE = (n); i <= iE; i++)       for (int j = (1), jE = (m); j <= jE; j++)         dis[fu[j]] = min(dis[fu[j]], dis[fv[j]] + fval[j]);     for (int i = (1), iE = (n); i <= iE; i++)       for (int j = (0), jE = (t - 1); j <= jE; j++) ans[i][j] = dis[i] + x;     Solve(0, t - 1, t * 2);     Divide(t, t * 2);     printf( %.10lf n , ans[1][2 * t]);     return 0;   }


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


#include <bits/stdc++.h>   struct City {     long long g;     long long w;     long long gf;     long long bg;     long long minbg;   };   class Data {    public:     City cities[100000];     int n;     int k;     long long gifts;     long long gas;     long long nextGas;     int maxL;     City* end;     City* head;     City* tail;     City* start;     City* finish;     City* lastMinBackwardGasCity;     City* firstMinBackwardGasCity;     void init() {       std::streambuf* sbuf = std::cin.rdbuf();       auto getCinValue = [=]() -> long long {         long long retVal = 0;         int ch =    ;         while (ch ==     || ch ==   r  || ch ==   n ) ch = sbuf->sbumpc();         while (ch >=  0  && ch <=  9 ) {           retVal = retVal * 10 + ch -  0 ;           ch = sbuf->sbumpc();         }         return retVal;       };       n = getCinValue();       k = getCinValue();       for (int i = 0; i < n - 1; i++) cities[i].w = getCinValue();       for (int i = 0; i < n; i++) cities[i].g = getCinValue();       end = cities + n;       head = cities;       tail = cities;       start = cities;       finish = cities;       lastMinBackwardGasCity = cities;       firstMinBackwardGasCity = cities;       gifts = k;       gas = 0;       nextGas = 0;       maxL = 1;     }   };   struct Result {     City* start;     City* finish;     int length() { return finish - start + 1; }   };   void backCount(City* city, Data& data) {     if (city == data.tail) {       city->bg = city->minbg = 0;       data.firstMinBackwardGasCity = data.lastMinBackwardGasCity = data.tail;     } else {       city->bg = (city - 1)->bg + (city - 1)->w - city->g - city->gf;       if (city->bg < (city - 1)->minbg) {         city->minbg = city->bg;         data.firstMinBackwardGasCity = city;         data.lastMinBackwardGasCity = city;       } else if (city->bg == (city - 1)->minbg) {         city->minbg = city->bg;         data.lastMinBackwardGasCity = city;       } else         city->minbg = (city - 1)->minbg;     }   };   void backRecountAll(Data& data) {     for (City* city = data.tail; city < data.head; city++) backCount(city, data);   };   bool backCheck(City* city, long long gifts, Data& data) {     if (gifts + city->g >= (city - 1)->bg - (city - 1)->minbg + (city - 1)->w) {       int l = city - data.tail + 1;       if (l > data.maxL) {         data.maxL = l;         data.start = data.tail;         data.finish = city;         return true;       }     }     return false;   };   long long backCheckAll(Data& data) {     long long gifts_ = data.gifts;     long long minGiftsDeficit = 9223372036854775807LL;     for (City* city = data.head;          city > (((data.tail) > (data.tail + data.maxL - 1))                      ? (data.tail)                      : (data.tail + data.maxL - 1));          city--) {       gifts_ += city->gf;       long long giftsLeft =           gifts_ + city->g - ((city - 1)->bg - (city - 1)->minbg + (city - 1)->w);       if (giftsLeft >= 0) {         data.maxL = city - data.tail + 1;         data.start = data.tail;         data.finish = city;         break;       } else         minGiftsDeficit = (((minGiftsDeficit) < (-giftsLeft)) ? (minGiftsDeficit)                                                               : (-giftsLeft));     }     return minGiftsDeficit;   };   Result testData(Data& data) {     while (1) {       while (data.head < data.end - 1) {         long long g = data.head->g;         long long w = data.head->w;         long long gf = 0;         data.nextGas = (data.head == data.end - 1) ? (-9223372036854775807LL - 1)                                                    : data.gas + g - w;         if (data.nextGas >= 0) {           data.gas = data.nextGas;           data.head->gf = gf = 0;           data.nextGas = 0;         } else if (data.gifts >= -data.nextGas) {           data.head->gf = gf = -data.nextGas;           data.gifts += data.nextGas;           data.gas = 0;           data.nextGas = 0;         } else           break;         backCount(data.head, data);         data.head++;         backCheck(data.head, data.gifts, data);       }       long long minGiftsDeficit = 0;       while (data.tail < data.head) {         if (data.k < -data.nextGas && data.head - data.tail + 1 <= data.maxL)           break;         if (data.head - data.tail + 1 <= data.maxL) {           while (!data.tail->gf) data.tail++;         }         while (!data.tail->gf && data.tail->w <= (data.tail + 1)->g) data.tail++;         if (long long tailGifts = data.tail->gf) {           data.gifts += tailGifts;           data.tail->gf = 0;           data.tail++;           minGiftsDeficit -= tailGifts;           if (minGiftsDeficit <= 0) minGiftsDeficit = backCheckAll(data);         } else {           data.tail++;           long long gas_ = 0;           bool gasChanged = true;           for (City* city = data.tail; city < data.head; city++) {             gas_ += city->g + city->gf - city->w;             if (gas_ <= 0 && city->gf) {               data.gifts += gas_;               city->gf -= gas_;               gas_ = 0;               gasChanged = false;               break;             } else if (gas_ < 0) {               data.gifts += gas_;               city->gf = -gas_;               gas_ = 0;             }           }           if (gasChanged) data.gas = gas_;           while (data.gifts < 0) {             data.head--;             data.gas -= data.head->g + data.head->gf - data.head->w;             data.gifts += data.head->gf;             data.head->gf = 0;             data.head->bg = 0;             data.head->minbg = 0;             minGiftsDeficit = 0;           }           data.nextGas = data.gas + data.head->g - data.head->w;           if (data.head <= data.firstMinBackwardGasCity) {             backRecountAll(data);             minGiftsDeficit = backCheckAll(data);           } else if (data.head <= data.lastMinBackwardGasCity)             while (data.lastMinBackwardGasCity->bg !=                    data.lastMinBackwardGasCity->minbg)               data.lastMinBackwardGasCity--;         }         if (data.tail == data.head) break;         if (data.tail > data.lastMinBackwardGasCity) {           backRecountAll(data);           minGiftsDeficit = backCheckAll(data);         } else if (data.tail > data.firstMinBackwardGasCity)           while (data.firstMinBackwardGasCity->bg !=                  data.firstMinBackwardGasCity->minbg)             data.firstMinBackwardGasCity++;         if (data.head == data.end - 1) {           if (data.maxL >= data.head - data.tail + 1) break;         } else if (data.gifts >= -data.nextGas) {           data.head->gf = -data.nextGas;           data.gifts -= -data.nextGas;           data.gas = 0;           data.nextGas = 0;           backCount(data.head, data);           data.head++;           backCheck(data.head, data.gifts, data);           break;         }       }       if (data.k < -data.nextGas && data.head - data.tail + 1 <= data.maxL) {         data.head++;         data.tail = data.head;       }       if (data.tail == data.head) {         data.tail = data.head;         data.firstMinBackwardGasCity = data.head;         data.lastMinBackwardGasCity = data.head;         data.gifts = data.k;         data.gas = 0;         data.nextGas = 0;       }       if (data.maxL >= data.end - data.tail) break;     }     return {data.start, data.finish};   }   int test() {     static Data data;     data.init();     Result result = testData(data);     return result.length();   }   int main() { std::cout << test(); }