#include <bits/stdc++.h>   using namespace std;   void SieveOfErat() {     bool prime[1000001];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= 1000000; p++) {       if (prime[p] == true) {         for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;       }     }   }   long long gcd(long long x, long long y) {     if (x == 0) {       return y;     } else       return gcd(x % y, y);   }   long long n, m;   vector<vector<long long> > v;   vector<long long> res;   signed main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     v.assign(n, vector<long long>(m, 0));     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < m; ++j) cin >> v[i][j];     }     if (n < m) {       for (long long i = 0; i < n; ++i) {         long long mi = 600;         for (long long j = 0; j < m; ++j) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long j = 0; j < mi; ++j) res.push_back(i + 1);         for (long long j = 0; j < m; ++j) v[i][j] -= mi;       }       for (long long j = 0; j < m; ++j) {         long long mi = 600;         for (long long i = 0; i < n; ++i) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long i = 0; i < mi; ++i) res.push_back(-(j + 1));         for (long long i = 0; i < n; ++i) v[i][j] -= mi;       }     } else {       for (long long j = 0; j < m; ++j) {         long long mi = 600;         for (long long i = 0; i < n; ++i) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long i = 0; i < mi; ++i) res.push_back(-(j + 1));         for (long long i = 0; i < n; ++i) v[i][j] -= mi;       }       for (long long i = 0; i < n; ++i) {         long long mi = 600;         for (long long j = 0; j < m; ++j) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long j = 0; j < mi; ++j) res.push_back(i + 1);         for (long long j = 0; j < m; ++j) v[i][j] -= mi;       }     }     long long sum = 0;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < m; ++j) sum += v[i][j];     if (sum > 0) {       cout << -1 << endl;       return 0;     }     cout << res.size() <<   n ;     for (long long i = 0; i < res.size(); ++i) {       if (res[i] > 0)         cout <<  row   << res[i] <<   n ;       else         cout <<  col   << -res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, dx, dy, ans = 0, a, b;     map<long long, int> num;     double k;     scanf( %lld%lld%lld%lld , &n, &m, &dx, &dy);     long long x, y;     for (int i = 0; i < m; i++) {       scanf( %lld%lld , &x, &y);       k = ((dy * x - dx * y) % n + n) % n;       num[k]++;       if (ans < num[k]) {         a = x;         b = y;         ans = num[k];       }     }     printf( %lld %lld n , a, b);     return 0;   }


#include <bits/stdc++.h>   int get() {     int x = 0;     char s = getchar();     while (s <  0  || s >  9 ) s = getchar();     while (s >=  0  && s <=  9 )       x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();     return x;   }   const int M = 1e5 + 5;   int n, m, head[M], cntedge, ans, s, a[M << 2];   bool c[M], vis[M];   struct edge {     int to, nxt;     edge() {}     edge(const int T, const int NX) { to = T, nxt = NX; }   } e[M << 1];   void add(const int u, const int v) {     e[++cntedge] = edge(v, head[u]), head[u] = cntedge;   }   void dfs(int u, int fa) {     vis[u] = 1;     a[++ans] = u;     c[u] ^= 1;     for (int i = head[u]; i; i = e[i].nxt)       if (!vis[e[i].to]) {         dfs(e[i].to, u);         a[++ans] = u;         c[u] ^= 1;       }     if (c[u]) {       a[++ans] = fa;       c[fa] ^= 1;       a[++ans] = u;       c[u] ^= 1;     }   }   int main() {     n = get(), m = get();     for (int u, v; m--;) {       u = get(), v = get();       add(u, v), add(v, u);     }     for (int i = 1; i <= n; ++i) {       c[i] = get();       if (c[i]) s = i;     }     if (s) {       dfs(s, -1);       for (int i = 1; i <= n; ++i)         if (!vis[i] && c[i]) return !printf( -1 );     }     if (ans > 1 && a[ans - 1] == -1) ans -= 3;     printf( %d n , ans);     for (int i = 1; i <= ans; ++i) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 17;   const int LOG = 17;   int n, m, q, tick;   int id[N], st[N], nd[N], ch[N], dep[N], lca[LOG][N];   vector<int> v[N];   void dfs(int p, int x) {     dep[x] = dep[p] + 1;     lca[0][x] = p;     for (int i = 1; i < LOG; i++) lca[i][x] = lca[i - 1][lca[i - 1][x]];     ch[x] = 1;     for (auto u : v[x]) {       if (u != p) {         dfs(x, u);         ch[x] += ch[u];       }     }   }   int head[N], ww[N];   void dfs2(int p, int x, int h) {     id[x] = ++tick;     st[x] = tick;     ww[tick] = x;     head[x] = h;     int mx = -1;     for (auto u : v[x]) {       if (u != p) {         if (mx == -1 or ch[u] > ch[mx]) mx = u;       }     }     if (mx != -1) dfs2(x, mx, h);     for (auto u : v[x]) {       if (u != p and u != mx) dfs2(x, u, u);     }     nd[x] = tick;   }   int getLca(int x, int y) {     if (!x) return y;     if (!y) return x;     if (dep[x] < dep[y]) swap(x, y);     for (int i = LOG - 1; i >= 0; i--)       if (dep[x] - (1 << i) >= dep[y]) x = lca[i][x];     if (x == y) return x;     for (int i = LOG - 1; i >= 0; i--)       if (lca[i][x] != lca[i][y]) x = lca[i][x], y = lca[i][y];     return lca[0][x];   }   vector<int> jun[N];   namespace tree {   pair<long long, int> t[N << 1];   long long lazy[N << 1];   void Do(int x, long long v) {     t[x].first += v;     lazy[x] += v;   }   void push(int x) {     Do(x + x, lazy[x]);     Do(x + x + 1, lazy[x]);     lazy[x] = 0;   }   void up(int x, int l, int r, int x1, int x2, long long v) {     if (x2 < l or r < x1) return;     if (x1 <= l and r <= x2) {       Do(x, v);       return;     }     push(x);     int m = (l + r) >> 1;     up(x + x, l, m, x1, x2, v);     up(x + x + 1, m + 1, r, x1, x2, v);     t[x] = min(t[x + x], t[x + x + 1]);   }   void update(int x, int l, int r, int x1) {     if (l == r) {       if (jun[ww[l]].size())         t[x] = {jun[ww[l]].back() + lazy[x], ww[l]};       else         t[x] = {1e18, -1};       return;     }     push(x);     int m = (l + r) >> 1;     if (x1 <= m)       update(x + x, l, m, x1);     else       update(x + x + 1, m + 1, r, x1);     t[x] = min(t[x + x], t[x + x + 1]);   }   void init(int x, int l, int r) {     if (l == r) {       if (jun[ww[l]].size())         t[x] = {jun[ww[l]].back(), ww[l]};       else         t[x] = {1e18, -1};     } else {       int m = (l + r) >> 1;       init(x + x, l, m);       init(x + x + 1, m + 1, r);       t[x] = min(t[x + x], t[x + x + 1]);     }   }   pair<long long, int> get(int x, int l, int r, int x1, int x2) {     if (x2 < l or r < x1) return {1e18, -1};     if (x1 <= l and r <= x2) return t[x];     push(x);     int m = (l + r) >> 1;     return min(get(x + x, l, m, x1, x2), get(x + x + 1, m + 1, r, x1, x2));   }   }  // namespace tree   pair<long long, int> get(int x, int y) {     pair<long long, int> res = {1e18, -1};     while (dep[x] >= dep[y]) {       int a = head[x];       if (dep[a] < dep[y]) a = y;       res = min(res, tree ::get(1, 1, n, id[a], id[x]));       x = lca[0][a];     }     return res;   }   int w[N];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       scanf( %d , w + i);       jun[w[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       reverse(jun[i].begin(), jun[i].end());     }     dfs(0, 1);     tick = 0;     dfs2(0, 1, 1);     tree ::init(1, 1, n);     for (int i = 1; i <= q; i++) {       int c;       scanf( %d , &c);       if (c == 1) {         int x, y, k;         scanf( %d %d %d , &x, &y, &k);         int lca = getLca(x, y);         vector<int> v;         for (int it = 0; it < k; it++) {           auto tmp = min(get(x, lca), get(y, lca));           if (tmp.first > 5e17) break;           v.push_back(jun[tmp.second].back());           jun[tmp.second].pop_back();           tree ::update(1, 1, n, st[tmp.second]);         }         printf( %d , v.size());         for (auto x : v) printf(  %d , x);         puts(  );       } else {         int x, k;         scanf( %d %d , &x, &k);         tree ::up(1, 1, n, st[x], nd[x], k);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d %d %d %d , &a, &b, &c, &d);     int M, M1, M2, V, V1, V2;     M1 = (3 * a) / 10;     M2 = (a - (a / 250) * c);     if (M1 > M2) {       M = M1;     } else {       M = M2;     }     V1 = (3 * b) / 10;     V2 = (b - (b / 250) * d);     if (V1 > V2) {       V = V1;     } else {       V = V2;     }     if (M > V) {       printf( Misha n );     } else {       if (V > M) {         printf( Vasya );       } else {         printf( Tie );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = 1e18;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const int MAXN = 200050;   int a[MAXN], cnt[105];   unordered_map<int, int> mp;   void solve(int T) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     int maxx = 0, idx;     for (int i = 1; i <= 100; i++) {       if (cnt[i] > maxx) {         maxx = cnt[i];         idx = i;       }     }     int tmp = 0;     for (int i = 1; i <= 100; i++) {       if (cnt[i] == maxx) tmp++;     }     if (tmp >= 2) {       printf( %d n , n);       return;     }     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (i == idx) continue;       mp.clear();       mp[idx] = 0;       int sum = 0;       for (int j = 1; j <= n; j++) {         if (a[j] == idx)           sum++;         else if (a[j] == i)           sum--;         if (sum == 0)           ans = max(ans, j);         else if (mp[sum]) {           ans = max(ans, j - mp[sum]);         } else           mp[sum] = j;       }     }     printf( %d , ans);   }   signed main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve(i);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int mod1 = 1000000007;   long long int mod2 = 67280421310721;   long long int mod3 = 998244353;   long long int INF = 1e18;   long long int binpow1(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int binpow2(long long int a, long long int b, long long int m) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   map<long long int, long long int> fact(long long int n) {     map<long long int, long long int> factorization;     long long int c = 0;     while (n % 2 == 0) {       c++;       n /= 2;     }     if (c > 0) {       factorization.insert({2, c});     }     c = 0;     for (long long int d = 3; d * d <= n; d += 2) {       while (n % d == 0) {         c++;         n /= d;       }       if (c > 0) {         factorization.insert({d, c});       }       c = 0;     }     if (n > 1) {       factorization.insert({n, 1});     }     return factorization;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int n = s.length();       long long int ans = 0;       long long int c = 0, d = 0;       long long int k = 0;       long long int f = 0;       long long int p = n;       for (int i = (0); i < (n); i++) {         if (s[i] ==  A ) {           p = i;           break;         }       }       for (int i = (0); i < (n); i++) {         if (s[i] ==  A ) {           c++;           f++;         } else {           d++;           k++;         }         if (d >= c) {           ans = ans + c;           c = 0;           d = 0;         }       }       ans = ans + min(c, d);       cout << n - 2 * ans - (k - ans - (k - ans) % 2) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)1e6 + 7;   int n, k;   int a[N], bit[N];   map<int, int> cnt[11];   long long dp[N][11];   void Init() {     for (int i = (1); i < (11); ++i) cnt[i].clear();     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     for (int i = (0); i < (n); ++i) {       int x = a[i];       bit[i] = 0;       while (x) {         bit[i]++;         x /= 10;       }     }   }   int Solve() {     for (int i = (0); i < (n); ++i) {       cnt[bit[i]][a[i] % k]++;       dp[i][0] = a[i] % k;       for (int j = (1); j < (11); ++j) dp[i][j] = dp[i][j - 1] * 10 % k;     }     long long ans = 0;     for (int i = (0); i < (n); ++i) {       for (int j = (1); j < (11); ++j) {         if (bit[i] == j && (dp[i][j] + a[i]) % k == 0) --ans;         int t = k - dp[i][j] != k ? k - dp[i][j] : 0;         if (cnt[j].count(t)) ans += cnt[j][t];       }     }     return !printf( %lld n , ans);   }   int main() {     while (~scanf( %d%d , &n, &k)) {       Init();       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     c *= 2;     int d = a / c;     if (d > 1) d -= 1;     int e = b / c;     if (e > 1) e -= 1;     int res = d * e;     if (!res % 2)       cout <<  Second n ;     else       cout <<  First n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   const int M = 1000000007;   int n, p, c[maxn];   long long ans = 0, pw[maxn], od[maxn], ev[maxn], f[maxn][maxn][maxn][maxn];   void init() {     f[0][0][0][0] = 1;     pw[0] = 1;     for (int i = 1; i < maxn; i++) pw[i] = pw[i - 1] * 2 % M;     ev[0] = 1, od[0] = 0;     for (int i = 1; i < maxn; i++) ev[i] = od[i] = pw[i - 1];   }   void find_ans(int ob, int eb, int ow, int ew, int col, long long &ret) {     if (col != 0 && ew != 0)       (ret += f[ob][eb][ow][ew - 1] * pw[ow + ew - 1 + eb] % M * od[ob] % M) %= M;     if (col != 0 && ow != 0)       (ret += f[ob][eb][ow - 1][ew] * pw[ow + ew - 1 + eb] % M * ev[ob] % M) %= M;     if (col != 1 && eb != 0)       (ret += f[ob][eb - 1][ow][ew] * pw[ob + eb - 1 + ew] % M * od[ow] % M) %= M;     if (col != 1 && ob != 0)       (ret += f[ob - 1][eb][ow][ew] * pw[ob - 1 + eb + ew] % M * ev[ow] % M) %= M;     return;   }   int main() {     init();     scanf( %d%d , &n, &p);     for (int i = 1; i <= n; i++) scanf( %d , c + i);     for (int i = 1; i <= n; i++)       for (int ob = 0; ob <= i; ob++)         for (int eb = 0; ob + eb <= i; eb++)           for (int ow = 0; ob + eb + ow <= i; ow++) {             int ew = i - ob - eb - ow;             find_ans(ob, eb, ow, ew, c[i], f[ob][eb][ow][ew]);             if (i == n && ((ob + ow) & 1) == p) (ans += f[ob][eb][ow][ew]) %= M;           }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   int n, q;   namespace BIT {   int seg[100005];   inline void modify(int pos, int val) {     for (; pos <= n; pos += pos & -pos) seg[pos] += val;   }   inline int query(int pos) {     int res = 0;     for (; pos; pos -= pos & -pos) res += seg[pos];     return res;   }   inline int calc_idx(int x) {     int l = 1, r = n, res = n + 1;     while (l <= r) {       int m = l + r >> 1;       if (query(m) > x) {         res = m;         r = m - 1;       } else         l = m + 1;     }     modify(res, -1);     return res;   }   }  // namespace BIT   namespace segT {   int lson[20000005], rson[20000005], sum[20000005], t_cnt;   void modify(int &u, int v, int l, int r, int pos) {     u = ++t_cnt;     lson[u] = lson[v];     rson[u] = rson[v];     sum[u] = sum[v] + 1;     if (l == r) return;     int m = l + r >> 1;     if (pos <= m)       modify(lson[u], lson[v], l, m, pos);     else       modify(rson[u], rson[v], m + 1, r, pos);   }   int query_rk(int u, int l, int r, int rk) {     if (l == r) return l;     int m = l + r >> 1;     if (sum[lson[u]] > rk) return query_rk(lson[u], l, m, rk);     return query_rk(rson[u], m + 1, r, rk - sum[lson[u]]);   }   int query_sum(int u, int l, int r, int pos) {     if (r <= pos) return sum[u];     int m = l + r >> 1, res = 0;     if (m < pos) res = query_sum(rson[u], m + 1, r, pos);     return query_sum(lson[u], l, m, pos) + res;   }   }  // namespace segT   int rep[100005], enp[100005], arr[100005], idx[100005], rt[100005];   ll pre[100005];   std::pair<ll, int> calc(int out, int in, int t) {     in += rep[out] - t;     int res = std::upper_bound(rep, rep + n, in) - rep;     return {(ll)in * res - pre[res], res};   }   int query_out(int x, int t) {     int l = 0, r = n - 1, res = -1;     while (l <= r) {       int m = l + r >> 1;       if (calc(m, 0, t).first <= x) {         res = m;         l = m + 1;       } else         r = m - 1;     }     return res;   }   int query_in(int out, int x, int t) {     int l = 0, r = rep[out + 1] - rep[out], res = -1;     if (out == n - 1) r = x / n + t + 1;     while (l <= r) {       int m = l + r >> 1;       if (calc(out, m, t).first <= x) {         res = m;         l = m + 1;       } else         r = m - 1;     }     return res;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , arr + i);     int stp = arr[0];     for (int i = 0; i < n; i++) arr[i] -= stp;     for (int i = 1; i < n; i++) {       rep[i] = rep[i - 1] + (arr[i] - enp[i - 1]) / i;       enp[i] = enp[i - 1] + (rep[i] - rep[i - 1]) * i;       pre[i + 1] = pre[i] + rep[i];     }     for (int i = 1; i <= n; i++) BIT::modify(i, 1);     for (int i = n - 1; i >= 0; i--) idx[i] = BIT::calc_idx(arr[i] - enp[i]) - 1;     for (int i = 0; i < n; i++) segT::modify(rt[i + 1], rt[i], 0, n - 1, idx[i]);     while (q--) {       int x, t;       scanf( %d%d , &x, &t);       if (x < stp) {         printf( %d n , x);         continue;       }       x -= stp;       int a = query_out(x, t), b = query_in(a, x, t);       auto res = calc(a, b, t);       int rem = x - res.first, rk = segT::query_rk(rt[res.second], 0, n - 1, rem);       printf( %lld n ,              stp + enp[a] + (ll)b * (a + 1) +                  (rk ? segT::query_sum(rt[a + 1], 0, n - 1, rk - 1) : 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Query {     int id, left, right, time, blockLeft, blockRight;     Query()         : id(-1), left(-1), right(-1), time(-1), blockLeft(-1), blockRight(-1) {}     Query(int id, int left, int right, int time, int blockLeft, int blockRight)         : id(id),           left(left),           right(right),           time(time),           blockLeft(blockLeft),           blockRight(blockRight) {}     bool operator<(const Query &otherQuery) const {       if (blockLeft != otherQuery.blockLeft) {         return blockLeft < otherQuery.blockLeft;       }       if (blockRight != otherQuery.blockRight) {         return blockRight < otherQuery.blockRight;       }       return time < otherQuery.time;     }   };   struct Operation {     int pos, oldValue, newValue;     Operation() : pos(-1), oldValue(-1), newValue(-1) {}     Operation(int pos, int oldValue, int newValue)         : pos(pos), oldValue(oldValue), newValue(newValue) {}   };   void del(int value, int *cnts, int *saveValues) {     saveValues[cnts[value]]--;     cnts[value]--;     saveValues[cnts[value]]++;   }   void add(int value, int *cnts, int *saveValues) {     saveValues[cnts[value]]--;     cnts[value]++;     saveValues[cnts[value]]++;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     int sqrtValue = pow(n, 2.0 / 3.0), *values = new int[n + 1],         *tmpValues = new int[n + 1];     if (sqrtValue == 0) sqrtValue = 1;     vector<int> disValues;     for (int i = 1; i <= n; i++) {       cin >> values[i];       tmpValues[i] = values[i];       disValues.push_back(values[i]);     }     Query *querys = new Query[q + 1];     Operation *opts = new Operation[q + 1];     int cntQuerys = 0, cntOpts = 0;     for (int i = 1; i <= q; i++) {       int opt;       cin >> opt;       if (opt == 1) {         int left, right;         cin >> left >> right;         ++cntQuerys;         querys[cntQuerys] = Query(cntQuerys, left, right, cntOpts,                                   left / sqrtValue, right / sqrtValue);       } else {         int pos, value;         cin >> pos >> value;         ++cntOpts;         opts[cntOpts] = Operation(pos, tmpValues[pos], value);         tmpValues[pos] = value;         disValues.push_back(value);       }     }     sort(disValues.begin(), disValues.end());     disValues.resize(unique(disValues.begin(), disValues.end()) -                      disValues.begin());     for (int i = 1; i <= cntOpts; i++) {       Operation &tmpOpt = opts[i];       tmpOpt.oldValue =           lower_bound(disValues.begin(), disValues.end(), tmpOpt.oldValue) -           disValues.begin();       tmpOpt.newValue =           lower_bound(disValues.begin(), disValues.end(), tmpOpt.newValue) -           disValues.begin();     }     for (int i = 1; i <= n; i++) {       values[i] = lower_bound(disValues.begin(), disValues.end(), values[i]) -                   disValues.begin();     }     int valueSize = static_cast<int>(disValues.size()),         *cnts = new int[valueSize + 3], *saveValues = new int[n + 2];     memset(cnts, 0, sizeof(int) * (valueSize + 3));     memset(saveValues, 0, sizeof(int) * (n + 2));     int *results = new int[cntQuerys + 1];     sort(querys + 1, querys + cntQuerys + 1);     int l = 1, r = 0, time = 0;     for (int i = 1; i <= cntQuerys; i++) {       Query &tmpQuery = querys[i];       while (r < tmpQuery.right) {         r++;         add(values[r], cnts, saveValues);       }       while (l > tmpQuery.left) {         l--;         add(values[l], cnts, saveValues);       }       while (r > tmpQuery.right) {         del(values[r], cnts, saveValues);         r--;       }       while (l < tmpQuery.left) {         del(values[l], cnts, saveValues);         l++;       }       while (time < tmpQuery.time) {         time++;         Operation &tmpOpt = opts[time];         if (tmpOpt.pos >= l && tmpOpt.pos <= r) {           del(tmpOpt.oldValue, cnts, saveValues);           add(tmpOpt.newValue, cnts, saveValues);         }         values[tmpOpt.pos] = tmpOpt.newValue;       }       while (time > tmpQuery.time) {         Operation &tmpOpt = opts[time];         if (tmpOpt.pos >= l && tmpOpt.pos <= r) {           del(tmpOpt.newValue, cnts, saveValues);           add(tmpOpt.oldValue, cnts, saveValues);         }         values[tmpOpt.pos] = tmpOpt.oldValue;         time--;       }       for (int i = 1;; i++) {         if (i > n) {           results[tmpQuery.id] = 0;         }         if (saveValues[i] == 0) {           results[tmpQuery.id] = i;           break;         }       }     }     for (int i = 1; i <= cntQuerys; i++) {       cout << results[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[n];     int count = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       int x = 5 - arr[i];       if (x >= k) {         count++;       }     }     cout << count / 3 << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int MAXN = -1;   const int MOD = 1;   int main() {     int n;     while (cin >> n) {       string s;       cin >> s;       vector<int> d(n);       for (int i = 0; i < n; i++) cin >> d[i];       int cur = 0;       vector<int> used(n, 0);       while (1) {         if (cur < 0 || cur >= n) {           cout <<  FINITE  << endl;           break;         }         if (used[cur]) {           cout <<  INFINITE  << endl;           break;         }         used[cur] = 1;         if (s[cur] ==  > )           cur += d[cur];         else           cur -= d[cur];       }     }     return 0;   }


#include <bits/stdc++.h>   const long long inf = 1000000000ll;   const long long inf64 = inf * inf;   const long long base = inf + 7;   const long long MOD = inf + 9;   const double pi = acos(-1.0);   using namespace std;   bool solve() {     int n, q;     scanf( %d %d , &n, &q);     vector<long long> a(2 * n + 1);     for (int i(1); i <= n; i++) scanf( %I64d , &a[i]), a[i + n] = a[i];     vector<int> from(2 * n + 1), dp(2 * n + 1), last(2 * n + 1), used(2 * n + 1);     vector<long long> sum(2 * n + 1, 0);     for (int i(1); i <= 2 * n; i++) sum[i] = sum[i - 1] + a[i];     for (int i(0); i < q; i++) {       long long b;       scanf( %I64d , &b);       int j = -1;       for (int z(1); z <= n; z++) {         from[z] = dp[z] = used[z] = last[z] = 0;         if (sum[z] > b) {           if (j == -1) j = 1;           while (sum[z] - sum[j - 1] > b) j++;           from[z] = j - 1;         }         dp[z] = dp[from[z]] + 1;         if (from[z]) {           last[z] = last[from[z]];         } else           last[z] = z;       }       int ans = n + 1;       long long S = 0;       for (int z(n); z >= 1; z--) {         if (S > b) break;         int tmp = dp[z];         if (sum[last[z]] + S > b) tmp++;         ans = min(ans, tmp);         S += a[z];       }       printf( %d n , ans);     }     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   vector<long long> factorial;   void fill_factorial(long long n) {     factorial.resize(n + 1);     factorial[0] = 1;     for (long long i = 1; i <= n; i++)       factorial[i] = (factorial[i - 1] * i) % mod;   }   long long gcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long x1, y1;     long long d = gcd(b, a % b, x1, y1);     x = y1;     y = x1 - y1 * (a / b);     return d;   }   long long binpow(long long a, long long b) {     a %= mod;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long inv(long long a) {     long long x, y;     long long g = gcd(a, mod, x, y);     x = (x % mod + mod) % mod;     return x;   }   long long CC(long long n, long long k) {     return factorial[n] * inv(factorial[k]) % mod * inv(factorial[n - k]) % mod;   }   void solve() {     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i <= n; ++i) cin >> a[i];     long long h = 0;     queue<pair<long long, long long>> q;     q.push(make_pair(1, 0));     long long j = 2;     long long ans = 0;     while (true) {       long long val = q.front().first, t = q.front().second;       ans = max(ans, t);       q.pop();       q.push(make_pair(a[j], t + 1));       j++;       while (j <= n && a[j] > a[j - 1]) {         if (j > n) break;         q.push(make_pair(a[j], t + 1));         j++;       }       if (j > n) break;     }     while (!q.empty()) {       ans = max(ans, q.front().second);       q.pop();     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long no_of_test_cases;     cin >> no_of_test_cases;     while (no_of_test_cases--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[1100000];     scanf( %s , s);     int l = strlen(s);     int ans = 0;     int m = 0;     int p = 0;     while (s[p] ==  F ) p++;     for (int i = p; i < l; i++) {       if (s[i] ==  M ) {         m++;       }       if (s[i] ==  F ) {         ans = max(ans + 1, m);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   long long int dx[] = {-2, -2, -1, 1, 2, 2, 1, -1};   long long int dy[] = {-1, 1, 2, 2, 1, -1, -2, -2};   using namespace std;   bool comp(long long int x, long long int y) { return abs(x) > abs(y); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int te = 1;     cin >> te;     while (te--) {       long long int n;       cin >> n;       long long int arr[n];       long long int mxi = -INT_MAX;       for (long long int i = 0; i < n; i++) cin >> arr[i], mxi = max(mxi, arr[i]);       sort(arr, arr + n, comp);       if (mxi < 0) {         cout << arr[n - 1] * arr[n - 2] * arr[n - 3] * arr[n - 4] * arr[n - 5]              <<   n ;         continue;       }       long long int ans = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];       if (ans < 0) {         for (long long int i = 5; i < n; i++) {           for (long long int j = 0; j < 5; j++) {             long long int tmp = arr[i];             for (long long int k = 0; k < 5; k++) {               if (k != j) tmp *= arr[k];             }             ans = max(ans, tmp);           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int Gcd(int x, int y) {     while (x > 0 && y > 0) {       if (x > y) {         x = x % y;       } else {         y = y % x;       }     }     return x + y;   }   int Sign(int x) { return (x > 0) ? 1 : -1; }   int Abs(int x) { return (x > 0) ? x : -x; }   void ReduceFraction(int& x, int& y) {     if (x == 0) {       y = 1;     } else if (y == 0) {       x = 1;     } else {       int sgn = Sign(x) * Sign(y);       x = Abs(x);       y = Abs(y);       int g = Gcd(x, y);       x /= g;       y /= g;       x *= sgn;     }   }   struct Vector {     Vector(int vx, int vy) {       ReduceFraction(vx, vy);       x = vx;       y = vy;     }     int x;     int y;     bool operator==(const Vector& other) const {       return (x == other.x) && (y == other.y);     }   };   struct Line {     Line(int x0, int y0, int x1, int y1) : a(x1 - x0, y1 - y0) {       if (a.y != 0) {         u = a.y * x0 - a.x * y0;         v = a.y;         ReduceFraction(u, v);       } else {         u = y0;         v = 10001;       }     }     int u;     int v;     Vector a;     bool operator==(const Line& other) const {       return (u == other.u) && (v == other.v) && (a == other.a);     }   };   struct VectorHasher {     size_t operator()(Vector v) const {       const size_t coef = 39916801;       const hash<int> int_hasher;       return coef * int_hasher(v.x) + int_hasher(v.y);     }   };   struct LineHasher {     size_t operator()(const Line& l) const {       const size_t coef = 514229;       const hash<int> int_hasher;       const VectorHasher vector_hasher;       return coef * coef * int_hasher(l.u) + coef * int_hasher(l.v) +              vector_hasher(l.a);     }   };   long long Cn2(long long n) { return n * (n - 1) / 2; }   int main() {     int n;     cin >> n;     vector<pair<int, int>> pts(n);     for (int i = 0; i < n; ++i) {       cin >> pts[i].first >> pts[i].second;     }     unordered_map<Vector, unordered_set<Line, LineHasher>, VectorHasher> store;     for (int i = 0; i + 1 < n; ++i) {       for (int j = i + 1; j < n; ++j) {         Line new_line(pts[i].first, pts[i].second, pts[j].first, pts[j].second);         store[new_line.a].insert(new_line);       }     }     long long result = 0;     long long count = 0;     for (const auto& p : store) {       result -= Cn2(p.second.size());       count += p.second.size();     }     cout << result + Cn2(count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long binary_expo(long long base, long long expo) {     long long res = 1;     while (expo) {       if (expo % 2) {         res = mul(res, base);         expo /= 2;       }       base = mul(base, base);     }     return res;   }   vector<pair<long long, pair<long long, long long> > > v[1000002];   const long long N = 100002;   long long Arr[N], dep[N];   multiset<long long> S1[N], S2[N];   long long n;   long long BIT1[N], BIT2[N];   void update(long long BIT[], long long idx, long long val) {     while (idx <= n) {       BIT[idx] += val;       idx += (idx & (-idx));     }   }   long long query(long long BIT[], long long idx) {     long long sum = 0;     while (idx > 0) {       sum += BIT[idx];       idx -= (idx & (-idx));     }     return sum;   }   void solve() {     long long m, k;     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) {       Arr[i] = 1e12;       dep[i] = -1e12;     }     for (long long i = 0; i < m; i++) {       long long d, f, t, c;       cin >> d >> f >> t >> c;       v[d].push_back({f, {t, c}});       if (t == 0) {         Arr[f] = min(Arr[f], d);       } else {         dep[t] = max(dep[t], d);       }     }     long long minn = 1e12;     long long maxx = -1e12;     for (long long i = 1; i <= n; i++) {       if (Arr[i] == 1e12 or dep[i] == -1e12) {         cout <<  -1  << endl;         return;       }       maxx = max(maxx, Arr[i]);       minn = min(minn, dep[i]);     }     long long ms = maxx + 1;     long long me = minn - 1;     if (me - ms + 1 < k) {       cout <<  -1  << endl;       return;     }     for (long long i = 1000000; i > (ms + k - 1); i--) {       for (long long j = 0; j < v[i].size(); j++) {         pair<long long, pair<long long, long long> > p = v[i][j];         if (p.first == 0) {           long long val1 = 0;           if (S1[p.second.first].size() != 0) {             val1 = *(S1[p.second.first].begin());           }           S1[p.second.first].insert(p.second.second);           long long val = *(S1[p.second.first].begin());           update(BIT2, p.second.first, val - val1);         }       }     }     for (long long i = 1; i < ms; i++) {       for (long long j = 0; j < v[i].size(); j++) {         pair<long long, pair<long long, long long> > p = v[i][j];         if (p.second.first == 0) {           long long val1 = 0;           if (S2[p.first].size() != 0) {             val1 = *(S2[p.first].begin());           }           S2[p.first].insert(p.second.second);           long long val = *(S2[p.first].begin());           update(BIT1, p.first, val - val1);         }       }     }     long long ans = query(BIT1, n) + query(BIT2, n);     for (long long i = ms + k; i <= me; i++) {       long long ar = i - k;       long long de = i;       for (long long j = 0; j < v[i].size(); j++) {         pair<long long, pair<long long, long long> > p = v[i][j];         if (p.first == 0) {           long long val1 = 0;           if (S1[p.second.first].size() != 0) {             val1 = *(S1[p.second.first].begin());           }           S1[p.second.first].erase(S1[p.second.first].find(p.second.second));           long long val = *(S1[p.second.first].begin());           update(BIT2, p.second.first, val - val1);         }       }       for (long long j = 0; j < v[ar].size(); j++) {         pair<long long, pair<long long, long long> > p = v[ar][j];         if (p.second.first == 0) {           long long val1 = 0;           if (S2[p.first].size() != 0) {             val1 = *(S2[p.first].begin());           }           S2[p.first].insert(p.second.second);           long long val = *(S2[p.first].begin());           update(BIT1, p.first, val - val1);         }       }       ans = min(ans, query(BIT1, n) + query(BIT2, n));     }     cout << ans << endl;   }   signed main() {     long long t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   bool check(int x) {     int s[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};     int t;     while (x > 0) {       t = x % 10;       if (t <= k) s[t]++;       x /= 10;     }     for (int i = 0; i <= k; i++) {       if (s[i] == 0) return false;     }     return true;   }   int main() {     cin >> n >> k;     int res = 0;     int t;     for (int i = 0; i < n; i++) {       cin >> t;       if (check(t)) res++;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x[100005], pn, st;   pair<int, pair<int, int> > p[100005];   priority_queue<pair<int, pair<int, int> > > q, qq;   int main() {     scanf( %d%d , &n, &m);     for (int a = (1); a <= (n); a++)       for (int b = (1); b <= (m); b++)         p[pn++] = make_pair(a + b, make_pair(a, b));     sort(p, p + pn);     scanf( %d , &k);     for (int a = (0); a < (k); a++) scanf( %d , x + a);     sort(x, x + k);     for (int a = (0); a < (k); a++) {       while (st < pn && p[st].first <= x[a]) {         q.push(make_pair(p[st].second.first + m + 1 - p[st].second.second,                          p[st].second));         st++;       }       if (q.empty()) {         printf( NO n );         return 0;       }       q.pop();     }     while (!q.empty()) {       qq.push(q.top());       q.pop();     }     while (st < pn) {       qq.push(make_pair(p[st].second.first + m + 1 - p[st].second.second,                         p[st].second));       st++;     }     scanf( %d , &k);     for (int a = (0); a < (k); a++) scanf( %d , x + a);     sort(x, x + k, greater<int>());     for (int a = (0); a < (k); a++) {       if (qq.top().first > x[a]) {         printf( NO n );         return 0;       }       qq.pop();     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   int n, sa[N], sb[N], a1[N], b1[N], suma, sumb, q[N];   struct nd {     int w, id;   } a[N], b[N];   bool cmp(nd a, nd b) { return a.w > b.w; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       scanf( %d , &a[i].w), a[i].id = i, a1[i] = a[i].w, suma += a[i].w;     for (int i = 1; i <= n; ++i)       scanf( %d , &b[i].w), b[i].id = i, b1[i] = b[i].w, sumb += b[i].w;     sort(a + 1, a + n + 1, cmp);     q[++q[0]] = a[1].id;     for (int i = 2; i < n; i += 2) {       if (b1[a[i].id] > b1[a[i + 1].id])         q[++q[0]] = a[i].id;       else         q[++q[0]] = a[i + 1].id;     }     if (n % 2 == 0) q[++q[0]] = a[n].id;     cout << n / 2 + 1 << endl;     for (int i = 1; i <= q[0]; ++i) cout << q[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5;   const int M = 1e7 + 1;   const long long INF = 1LL << 61;   long long a[N], t[N], cost[N];   inline long long bs(long long bytes, long long maxt) {     long long res = -1;     if (t[0] <= t[2]) {       if ((t[0] * bytes) <= maxt) {         res = 0;       }       return res;     }     if (bytes <= 0) {       return 0;     }     int l = 0;     int r = M;     while (l <= r) {       int mid = l + (r - l) / 2;       long long b_left = bytes - mid * a[2];       long long t_left = maxt - mid * a[2] * t[2];       if (b_left < 0) {         if (llabs(b_left) < a[2]) {           t_left += (b_left * (-t[2]));           b_left = 0;         } else {           r = mid - 1;           continue;         }       }       t_left -= (b_left * t[0]);       if (t_left >= 0) {         res = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     long long size, maxt;     cin >> size >> maxt;     cin >> t[0];     for (int i = int(1); i < int(3); i++) {       cin >> a[i] >> t[i] >> cost[i];     }     if (t[2] < t[1]) {       swap(a[1], a[2]);       swap(t[1], t[2]);       swap(cost[1], cost[2]);     }     long long ans = INF;     for (int i = int(0); i < int(M); i++) {       long long money = i * cost[1];       long long bytes = size - i * a[1];       long long tt = maxt - (i * a[1] * t[1]);       if (bytes > 0) {         long long use2 = bs(bytes, tt);         money += (use2 * cost[2]);         if (use2 >= 0) {           ans = min(ans, money);         }       } else if (bytes < 0) {         tt += (bytes * (-t[1]));       }       if (bytes <= 0 and tt >= 0) {         ans = min(ans, money);       }     }     if (ans >= INF) {       ans = -1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double round(double x) { return ((long long)(x * 1e8 + 0.5)) / 1e8; }   double x[5], y[5], r[5];   set<pair<double, double> > c[5];   set<pair<double, double> > u;   void intersection(int i, int j) {     double d =         sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));     if ((d <= r[i] + r[j] && d >= abs(r[i] - r[j]))) {     } else {       return;     }     double a, h, x1, y1, x2, y2, _x, _y;     a = (r[i] * r[i] - r[j] * r[j] + d * d) / (2 * d);     h = sqrt(r[i] * r[i] - a * a);     _x = x[i] + a * (x[j] - x[i]) / d;     _y = y[i] + a * (y[j] - y[i]) / d;     x1 = _x + h * (y[j] - y[i]) / d;     y1 = _y - h * (x[j] - x[i]) / d;     x2 = _x - h * (y[j] - y[i]) / d;     y2 = _y + h * (x[j] - x[i]) / d;     x1 = round(x1);     x2 = round(x2);     y1 = round(y1);     y2 = round(y2);     c[i].insert({x1, y1});     c[i].insert({x2, y2});     c[j].insert({x2, y2});     c[j].insert({x1, y1});     u.insert({x1, y1});     u.insert({x2, y2});   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i] >> r[i];     }     if (n == 1) {       cout << 2 << endl;       return 0;     } else if (n == 2) {       intersection(0, 1);       if (u.size() == 2) {         cout << 4 << endl;       } else         cout << 3 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         intersection(i, j);       }     }     int v = u.size();     if (v == 0) {       cout << 4 << endl;       return 0;     }     int cc = 0;     int e = 0;     for (int i = 0; i < n; i++) {       e += c[i].size();       if (c[i].size() == 0) {         cc++;       }     }     int f = e - v + 2 + cc;     cout << f << endl;   }


#include <bits/stdc++.h>   const int INF = 1000000;   using namespace std;   int main() {     int a, b, m;     vector<int> r(1);     scanf( %d %d %d %d , &a, &b, &m, &r[0]);     for (int i = 1; i < 2 * m + 2; i++) {       r.push_back((a * r[i - 1] + b) % m);     }     vector<int> ans(2 * m + 2, INF);     int res = 1;     for (int i = 1; i < m + 1; i++) {       for (int t = 1; t < m + 1; t++)         if (r[i] == r[i + t]) {           ans[i] = min(t, ans[i - 1]);           res = ans[i];           cout << res;           return 0;         }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   const int N = 120000;   using namespace std;   vector<string> fig;   int n, m;   vector<vector<string> > figs;   int ans;   vector<pair<pair<int, int>, int> > avec;   int board[200][200];   bool bad(int a, int b) {     return (a < 0 || a >= n || b < 0 || b >= m || board[a][b] == 1);   }   vector<string> rotate(vector<string> cur) {     char temp[10][10];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         temp[i][j] = cur[i][j];       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         cur[i][j] = temp[j][2 - i];       }     }     return cur;   }   vector<pair<pair<int, int>, int> > cur;   bool can_put(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           if (bad(i + x, j + y)) return false;         }       }     }     return true;   }   void do_put(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           board[x + i][y + j] = 1;         }       }     }     cur.push_back(make_pair(make_pair(x, y), id));   }   void unroll(int x, int y, int id) {     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (figs[id][i][j] ==  # ) {           board[x + i][y + j] = 0;         }       }     }     cur.pop_back();   }   int flag, iters;   void dfs(int a, int b) {     int rem_area = n * m - (a * m + b);     if (cur.size() + rem_area / 5 <= avec.size()) return;     ++iters;     if (iters % 1024 == 0) {       double R = clock() * 1.0 / CLOCKS_PER_SEC;       if (R > 1.4) flag = 1;     }     if (flag) return;     if (cur.size() > avec.size()) {       avec = cur;     }     if (a >= n - 2) {       return;     }     for (int i = 0; i < 4; i++) {       if (can_put(a, b, i)) {         do_put(a, b, i);         if (b + 1 == m)           dfs(a + 1, 0);         else           dfs(a, b + 1);         unroll(a, b, i);       }     }     if (b + 1 == m)       dfs(a + 1, 0);     else       dfs(a, b + 1);   }   int main() {     ios_base::sync_with_stdio(0);     fig.push_back( ### );     fig.push_back( .#. );     fig.push_back( .#. );     figs.push_back(fig);     for (int i = 0; i < 3; i++) {       figs.push_back(rotate(figs.back()));     }     cin >> n >> m;     dfs(0, 0);     cout << avec.size() << endl;     for (int i = 0; i < avec.size(); i++) {       int qi, qj;       qi = avec[i].first.first;       qj = avec[i].first.second;       for (int a = 0; a < 3; a++) {         for (int b = 0; b < 3; b++) {           if (figs[avec[i].second][a][b] ==  # ) {             board[qi + a][qj + b] = i + 1;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (board[i][j] == 0)           cout <<  . ;         else           cout << char( A  + board[i][j] - 1);       }       cout << endl;     }     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 9223372036854775807LL;   const int INF = 2147483647;   const int MOD = 1000000007;   const double eps = 1e-7;   const double PI = acos(-1.0);   int dr[] = {1, 0, -1, 0, -1, 1, 1, -1};   int dc[] = {0, -1, 0, 1, 1, 1, -1, -1};   int m;   pair<int, int> arr[100005];   vector<int> v;   bool done[100005];   bool cf(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     scanf( %d , &m);     for (int(i) = (1); (i) <= (m); (i)++)       scanf( %d , &arr[i].first), arr[i].second = i;     sort(arr + 1, arr + 1 + m);     int cur = arr[1].first;     done[arr[1].second] = true;     v.push_back(cur);     for (int(i) = (2); (i) <= (m); (i)++) {       if (arr[i].first > cur) {         cur = arr[i].first;         done[arr[i].second] = true;         v.push_back(cur);       }     }     sort(arr + 1, arr + 1 + m, cf);     for (int(i) = (1); (i) <= (m); (i)++) {       if (arr[i].first < cur && !done[arr[i].second]) {         cur = arr[i].first;         v.push_back(cur);       }     }     cout << (int)(v.size()) << endl;     for (int(i) = (0); (i) < ((int)(v.size())); (i)++) printf( %d  , v[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 1e12;   const int maxnnn = 2e8 + 30;   const long long zero = 0;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (a % b == 0)       return b;     else       gcd(b, a % b);   }   string ntos(long long a) {     string str;     stringstream ss;     ss << a;     ss >> str;     return str;   }   long long ston(string a) {     long long x;     stringstream ss;     ss << a;     ss >> x;     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     bool flag;     long long zimu[26];     long long n, m, a, b, t, y, fans, c, x, z, sw;     string s, s1, s2;     cin >> m >> n;     vector<long long> py(m + 1);     sw = 0;     py.clear();     for (long long i = 0; i < n; ++i) {       cin >> a >> b;       py[min(a, b)]++;       if (py[min(a, b)] == 1) sw++;     }     cin >> c;     while (c--) {       cin >> x;       if (x == 3) {         cout << m - sw << endl;       } else if (x == 1) {         cin >> y >> z;         py[min(y, z)]++;         if (py[min(y, z)] == 1) sw++;       } else {         cin >> y >> z;         py[min(y, z)]--;         if (py[min(y, z)] == 0) sw--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     long long int x = 0;     vector<long long int> sum = {};     vector<long long int> val = {};     for (int i = 0; i < (int)q; i++) {       int op;       cin >> op;       if (op == 1) {         cin >> x;         sum.push_back(((sum.size()) ? sum.back() : 0) + x);         long long int v[2];         v[0] = sum.size() * sum.back();         v[1] = (sum.size() >= 2) ? ((sum.size() + 1) * sum[sum.size() - 2]) : 0;         val.push_back(v[0] - v[1]);       } else {         auto itr = upper_bound(val.begin(), val.end(), x);         itr--;         long long int v = sum[distance(val.begin(), itr)];         cout << setprecision(16)              << x - (double)(x + v) / (double)(distance(val.begin(), itr) + 2)              << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T inverse(T a, T m) {     T u = 0, v = 1;     while (a != 0) {       T t = m / a;       m -= t * a;       swap(a, m);       u -= t * v;       swap(u, v);     }     assert(m == 1);     return u;   }   template <typename T>   class Modular {    public:     using Type = typename decay<decltype(T::value)>::type;     constexpr Modular() : value() {}     template <typename U>     Modular(const U& x) {       value = normalize(x);     }     template <typename U>     static Type normalize(const U& x) {       Type v;       if (-mod() <= x && x < mod())         v = static_cast<Type>(x);       else         v = static_cast<Type>(x % mod());       if (v < 0) v += mod();       return v;     }     const Type& operator()() const { return value; }     template <typename U>     explicit operator U() const {       return static_cast<U>(value);     }     constexpr static Type mod() { return T::value; }     Modular& operator+=(const Modular& other) {       if ((value += other.value) >= mod()) value -= mod();       return *this;     }     Modular& operator-=(const Modular& other) {       if ((value -= other.value) < 0) value += mod();       return *this;     }     template <typename U>     Modular& operator+=(const U& other) {       return *this += Modular(other);     }     template <typename U>     Modular& operator-=(const U& other) {       return *this -= Modular(other);     }     Modular& operator++() { return *this += 1; }     Modular& operator--() { return *this -= 1; }     Modular operator++(int) {       Modular result(*this);       *this += 1;       return result;     }     Modular operator--(int) {       Modular result(*this);       *this -= 1;       return result;     }     Modular operator-() const { return Modular(-value); }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(static_cast<int64_t>(value) *                         static_cast<int64_t>(rhs.value));       return *this;     }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       int64_t q = static_cast<int64_t>(static_cast<long double>(value) *                                        rhs.value / mod());       value = normalize(value * rhs.value - q * mod());       return *this;     }     template <typename U = T>     typename enable_if<!is_integral<typename Modular<U>::Type>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(value * rhs.value);       return *this;     }     Modular& operator/=(const Modular& other) {       return *this *= Modular(inverse(other.value, mod()));     }     template <typename U>     friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend std::istream& operator>>(std::istream& stream, Modular<U>& number);       private:     Type value;   };   template <typename T>   bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value == rhs.value;   }   template <typename T, typename U>   bool operator==(const Modular<T>& lhs, U rhs) {     return lhs == Modular<T>(rhs);   }   template <typename T, typename U>   bool operator==(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) == rhs;   }   template <typename T>   bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(const Modular<T>& lhs, U rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(U lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T>   bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value < rhs.value;   }   template <typename T>   Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T>   Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T>   Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T>   Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> powmod(const Modular<T>& a, const U& b) {     assert(b >= 0);     Modular<T> x = a, res = 1;     U p = b;     while (p > 0) {       if (p & 1) res *= x;       x *= x;       p >>= 1;     }     return res;   }   template <typename T>   string to_string(const Modular<T>& number) {     return to_string(number());   }   template <typename T>   std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {     return stream << number();   }   template <typename T>   std::istream& operator>>(std::istream& stream, Modular<T>& number) {     typename common_type<typename Modular<T>::Type, int64_t>::type x;     stream >> x;     number.value = Modular<T>::normalize(x);     return stream;   }   constexpr int md = 998244353;   using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     Mint m, n;     cin >> n >> m;     Mint res = 0, pre = 1;     for (int i = 1; i <= (int)n + 1; i++) {       Mint tmp = i / (n + m - i + 1);       if (i > 1) pre *= (n - i + 2) / (n + m - i + 2);       tmp *= pre;       res += tmp;     }     res *= m;     Mint h = 0;     for (Mint i = 1; i != (n + 1); i++) h += 1 / i;     h = h * m + 1;     cout << res * h;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const long long INF = numeric_limits<long long>::max();   enum { EVEN, ODD };   int A[MAXN];   long long dp[2][MAXN];   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; ++i) cin >> A[i];     dp[ODD][1] = dp[EVEN][1] = dp[ODD][2] = -INF;     dp[EVEN][2] = abs(A[2] - A[1]);     long long ans = dp[EVEN][2];     for (int i = 3; i <= N; ++i) {       dp[ODD][i] = dp[EVEN][i - 1] - abs(A[i] - A[i - 1]);       dp[EVEN][i] =           max(dp[ODD][i - 1] + abs(A[i] - A[i - 1]), abs(A[i] - A[i - 1]) * 1ll);       ans = max(ans, max(dp[ODD][i], dp[EVEN][i]));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = INT_MAX, df = 8e5 + 7;   int i, j, k = 1, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, le[df], rig[df],             c[df][26], ma[df << 1], head[df], pos[df << 1], tot, ans[df],             fail[df], cnt, yet[df][26];   struct node {     int sum, id;   };   vector<node> vec[df];   struct edge {     int to, nxt;   } e[df << 1];   void add(int u, int v) {     e[++o] = (edge){v, head[u]}, head[u] = o;     return;   }   char ch[df], st[df];   void upd(int x, int y) {     if (!x) return;     for (int i = x; i <= 800000; i += (i & -i)) ma[i] += y;     return;   }   int qry(int x) {     int as = 0;     for (int i = x; i; i -= (i & -i)) as += ma[i];     return as;   }   void insert1(int now, int v, int id) {     if (!c[now][v]) c[now][v] = ++tot;     pos[id] = c[now][v];     return;   }   void insert2(char *s, int id) {     int len = strlen(s), now = 0;     for (int i = (0); i <= (len - 1); ++i) {       int v = s[i] -  a ;       if (!c[now][v]) c[now][v] = ++tot;       now = c[now][v];     }     pos[id + n] = now;     return;   }   void init() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       int op, x;       scanf( %d , &op);       if (op == 1) {         scanf( %s , ch), insert1(0, ch[0] -  a , i);       }       if (op == 2) {         scanf( %d , &x);         scanf( %s , ch);         insert1(pos[x], ch[0] -  a , i);       }     }     scanf( %d , &t);     for (int i = (1); i <= (t); ++i) {       int x;       scanf( %d , &x), scanf( %s , st);       insert2(st, i);       vec[pos[x]].push_back((node){pos[i + n], i});     }     return;   }   void build() {     queue<int> que;     for (int i = (0); i <= (25); ++i)       if (c[0][i]) fail[c[0][i]] = 0, que.push(c[0][i]), yet[0][i] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = (0); i <= (25); ++i) {         if (c[u][i])           fail[c[u][i]] = c[fail[u]][i], yet[u][i] = 1, que.push(c[u][i]);         else           c[u][i] = c[fail[u]][i];       }     }     return;   }   void dfs1(int u) {     le[u] = ++cnt;     for (int i = head[u]; i; i = e[i].nxt) dfs1(e[i].to);     rig[u] = cnt;     return;   }   void dfs2(int u) {     upd(le[u], 1);     int siz = vec[u].size() - 1;     for (int i = (0); i <= (siz); ++i) {       int l = le[vec[u][i].sum], r = rig[vec[u][i].sum];       ans[vec[u][i].id] = qry(r) - qry(l - 1);     }     for (int i = (0); i <= (25); ++i)       if (yet[u][i]) dfs2(c[u][i]);     upd(le[u], -1);     return;   }   int main() {     init();     build();     for (int i = (1); i <= (tot); ++i) add(fail[i], i);     dfs1(0);     dfs2(0);     for (int i = (1); i <= (t); ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int size_c = 26;   const int Maxn = 500010 << 1;   string s[100020];   int w[100020];   int n;   struct Suffix_Automaton {     int ch[Maxn][size_c];     int f[Maxn];     int ml[Maxn];     int sz, head, tail;     long long val[Maxn];     int cnt[Maxn], id[Maxn];     inline int getidx(char c) { return c -  a ; }     int node() {       sz++;       f[sz] = ml[sz] = 0;       memset(ch[sz], 0, sizeof(ch[sz]));       return sz;     }     void init() {       head = tail = 1;       sz = 0;       node();     }     void insert(int idx) {       head = tail = 1;       for (int i = 0; i < s[idx].size(); i++) add(getidx(s[idx][i]));     }     void add(int c) {       int p = tail;       if (ch[p][c]) {         int q = ch[p][c];         if (ml[q] == ml[p] + 1) {           tail = ch[p][c];         } else {           int nq = node();           memcpy(ch[nq], ch[q], sizeof(ch[q]));           f[nq] = f[q];           f[q] = nq;           ml[nq] = ml[p] + 1;           for (; p && ch[p][c] == q; p = f[p]) ch[p][c] = nq;           tail = nq;         }         return;       }       int np = node();       ml[np] = ml[p] + 1;       tail = np;       for (; p && !ch[p][c]; p = f[p]) ch[p][c] = np;       if (!p)         f[np] = head;       else if (ml[ch[p][c]] == ml[p] + 1)         f[np] = ch[p][c];       else {         int q = ch[p][c];         int nq = node();         memcpy(ch[nq], ch[q], sizeof(ch[q]));         f[nq] = f[q];         f[q] = f[np] = nq;         ml[nq] = ml[p] + 1;         for (; p && ch[p][c] == q; p = f[p]) ch[p][c] = nq;       }     }     void solve() {       init();       cin >> n;       for (int i = 1; i <= n; i++) cin >> s[i];       for (int i = 1; i <= n; i++) scanf( %d , w + i);       for (int i = 1; i <= n; i++) insert(i);       memset(cnt, 0, sizeof(cnt));       for (int i = 1; i <= sz; i++) cnt[ml[i]]++;       for (int i = 1; i <= sz; i++) cnt[i] += cnt[i - 1];       for (int i = 1; i <= sz; i++) id[cnt[ml[i]]--] = i;       memset(cnt, 0, sizeof(cnt));       for (int idx = 1; idx <= n; idx++) {         int rt = 1;         for (int i = 0; i < s[idx].size(); i++) {           rt = ch[rt][getidx(s[idx][i])];           val[rt] += w[idx];         }       }       for (int i = sz; i >= 1; i--) {         int cur = id[i];         val[f[cur]] += val[cur];       }       long long ans = 0;       for (int i = 1; i <= sz; i++) ans = max(ans, 1LL * ml[i] * val[i]);       cout << ans << endl;     }   } suf;   int main() { suf.solve(); }


#include <bits/stdc++.h>   using namespace std;   void time() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     time();     int a, s, d, f;     cin >> a >> s >> d >> f;     if (a == s || s > a) {       cout <<  Second  << endl;     } else {       cout <<  First  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     string s;     cin >> s;     int n = s.length();     vector<int> dist(n);     for (int i = 0; i < n; i++)       if (s[i] ==  0 ) dist[i] = (i ? dist[i - 1] : 0) + 1;     vector<int> dp(n + 2), nxt(n + 2, n);     auto get = [&](int i) { return nxt[i] < n ? dp[nxt[i]] : 0; };     for (int i = n - 1; i >= 0; i--) {       dp[i] = ((dist[i] <= dist.back()) + get(0) + get(dist[i] + 1)) % mod;       nxt[dist[i]] = i;     }     int ans = n;     if (nxt[0] < n) ans = ((long long)get(0) * (nxt[0] + 1)) % mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::string;   string x;   int a, b, c;   int main() {     cin >> x;     switch (x[0]) {       case  r :         a = 0;         break;       case  s :         a = 2;         break;       case  p :         a = 5;         break;     }     cin >> x;     switch (x[0]) {       case  r :         b = 0;         break;       case  s :         b = 2;         break;       case  p :         b = 5;         break;     }     cin >> x;     switch (x[0]) {       case  r :         c = 0;         break;       case  s :         c = 2;         break;       case  p :         c = 5;         break;     }     if (a == b &&         ((c == 0 && a == 2) || (c == 2 && a == 5) || (c == 5 && a == 0)))       printf( S );     else if (b == c &&              ((a == 0 && b == 2) || (a == 2 && b == 5) || (a == 5 && b == 0)))       printf( F );     else if (a == c &&              ((b == 0 && a == 2) || (b == 2 && a == 5) || (b == 5 && a == 0)))       printf( M );     else       printf( ? );   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     long long int p = sqrt(n);     for (int i = 5; i <= p; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int b2d(string n) {     string num = n;     long long int dec_value = 0;     long long int base = 1;     long long int len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   int f, f1, f2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       f = 0;       int a[n];       int cnt = 0, sum = 0;       int m1 = 0, m2 = INT_MAX;       for (long long i = 0; i < n; i++) {         cin >> a[i];         if (a[i] != -1) f = 1;       }       for (long long i = 0; i < n; i++) {         if (a[i] != -1) {           if ((i > 0 && a[i - 1] == -1) || (i < n - 1 && a[i + 1] == -1)) {             m1 = max(m1, a[i]);             m2 = min(m2, a[i]);           }         }       }       if (!f) {         cout <<  0 1 n ;         continue;       }       int avg1 = (m1 + m2) / 2;       for (long long i = 0; i < n; i++) {         if (a[i] == -1) {           a[i] = avg1;         }       }       int ma1 = 0;       for (long long i = 0; i < n - 1; i++) {         ma1 = max(ma1, abs(a[i + 1] - a[i]));       }       cout << ma1 <<     << avg1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   struct Cup {     uint cap;     uint ix;     uint cur;   };   int main() {     uint n;     uint total;     cin >> n >> total;     vector<Cup> cups(n);     for (uint i = 0, wi; i < n; ++i) {       cin >> wi;       cups[i] = {wi, i, 0};     }     sort(cups.begin(), cups.end(),          [](const Cup& left, const Cup& right) { return left.cap < right.cap; });     uint cur = 0;     bool done = true;     for (Cup& cup : cups) {       cur = cup.cap / 2 + (cup.cap & 1);       if (cur > total) {         done = false;         break;       }       cup.cur = cur;       total -= cup.cur;     }     uint diff;     for (int i = n - 1; i > -1; --i) {       diff = min(total, cups[i].cap - cups[i].cur);       total -= diff;       cups[i].cur += diff;     }     if (total > 0) {       done = false;     }     if (!done) {       cout <<  -1 n ;     } else {       sort(cups.begin(), cups.end(),            [](const Cup& left, const Cup& right) { return left.ix < right.ix; });       for (Cup& c : cups) {         cout << c.cur <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int n[2], k[2];   string s[] = { First ,  Second };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n[0] >> n[1] >> k[0] >> k[1];     int cur = 0;     while (1) {       if (n[cur] == 0) break;       n[cur]--;       cur ^= 1;     }     cout << s[cur ^ 1];     return 0;   }


#include <bits/stdc++.h>   inline int getint() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   const int N = 101, K = 41, mod = 1e9 + 7;   int k, f[N][K], tmp[K];   std::forward_list<int> e[N];   inline void add_edge(const int &u, const int &v) {     e[u].push_front(v);     e[v].push_front(u);   }   void dfs(const int &x, const int &par) {     f[x][0] = f[x][k + 1] = 1;     for (int &y : e[x]) {       if (y == par) continue;       dfs(y, x);       std::fill(&tmp[0], &tmp[k * 2] + 1, 0);       for (register int i = 0; i <= k * 2; i++) {         for (register int j = 0; j <= k * 2; j++) {           (tmp[i + j <= k * 2 ? std::min(i, j + 1) : std::max(i, j + 1)] +=            (long long)f[x][i] * f[y][j] % mod) %= mod;         }       }       std::copy(&tmp[0], &tmp[k * 2] + 1, f[x]);     }   }   int main() {     const int n = getint();     k = getint();     for (register int i = 1; i < n; i++) {       add_edge(getint(), getint());     }     dfs(1, 0);     int ans = 0;     for (register int i = 0; i <= k; i++) {       (ans += f[1][i]) %= mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> p(n + 1);     for (long long i = 1; i < n + 1; i++) {       long long x;       cin >> x;       p[x] = i;     }     multiset<pair<long long, long long> > k;     vector<long long> ct(n + 1, 1);     for (long long i = 1; i < n + 1; i++) k.insert({1, i});     for (long long i = 1; i < n + 1; i++) {       long long pos = p[i];       if (ct[pos] != k.rbegin()->first) {         cout <<  No  <<   n ;         return;       }       k.erase({ct[pos], pos});       auto it = k.upper_bound({ct[pos], pos});       if (it == k.end()) continue;       long long newpos = it->second;       k.erase(it);       ct[newpos] += ct[pos];       k.insert({ct[newpos], newpos});     }     cout <<  Yes  <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     cin >> TESTS;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int d, n, m;   int deq[200100];   int qs, qe;   struct stt {     int x, p;     bool operator<(const stt& r) const { return x < r.x; }   };   stt a[200100];   int main() {     int i, j;     long long int ans;     scanf( %d%d%d , &d, &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a[i].x, &a[i].p);     }     a[m].x = 0;     a[m].p = 0;     m++;     a[m].x = d;     a[m].p = 0;     m++;     std::sort(a, a + m);     for (i = 1; i < m; i++) {       if (a[i].x > a[i - 1].x + n) {         printf( -1 );         return 0;       }     }     qs = 0;     qe = 0;     j = 0;     ans = 0;     for (i = 0; i < m; i++) {       while (qs < qe && a[deq[qs]].x + n < a[i].x) {         ans += ((long long int)a[deq[qs]].x + n - j) * a[deq[qs]].p;         j = a[deq[qs]].x + n;         qs++;       }       ans += ((long long int)a[i].x - j) * a[deq[qs]].p;       j = a[i].x;       while (qs < qe && a[deq[qe - 1]].p > a[i].p) {         qe--;       }       deq[qe] = i;       qe++;     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool size = false, small = false, cap = false, digit = false;     if (s.size() >= 5) {       size = true;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  !  || s[i] ==  _  || s[i] ==  ;  || s[i] ==  ,  ||             s[i] ==  . )           continue;         else if (s[i] >=  a  && s[i] <=  z )           small = true;         else if (s[i] >=  A  && s[i] <=  Z )           cap = true;         else if (s[i] >= 48 && s[i] <= 57)           digit = true;       }       if (size && small && cap && digit) {         cout <<  Correct  << endl;         return 0;       } else {         cout <<  Too weak  << endl;         return 0;       }     } else {       cout <<  Too weak  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string q;   string d;   int b;   void f(string s, int p) {     char a = 0;     int c = 0;     if (s.size() <= p) return;     for (int i = p; i < s.size(); i++) {       if (s[i] > a) {         a = s[i];         b = i;         c = 1;       } else if (s[i] == a) {         b = i;         c++;       }     }     for (int i = 0; i < c; i++) cout << a;     f(s, b + 1);   }   int main() {     cin >> q;     f(q, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   const int mod = 998244353;   inline int mul(int x, int y) { return (long long)x * y % mod; }   inline void sub(int &x, int y) {     y = x - y;     x = y < 0 ? y + mod : y;   }   inline void add(int &x, int y) {     y += x;     x = y >= mod ? y - mod : y;   }   inline int inc(int x, int y) {     x += y;     return x >= mod ? x - mod : x;   }   inline int qpow(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = mul(x, x))       if (y & 1) res = mul(res, x);     return res;   }   inline int inv(int x) { return x ? qpow(x, mod - 2) : 1; }   const int maxn = 3005;   const int maxm = 305;   int n, c, a[maxn];   namespace task1 {   int f[maxn][maxm], g[maxn][maxm], pw[maxn], sum[maxn], ipw[maxn];   void solve() {     pw[0] = ipw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = mul(pw[i - 1], 2);     for (int i = 1; i <= n; i++) ipw[i] = inv(pw[i] - 1);     int m = n / c;     f[n + 1][0] = g[n + 1][0] = 1;     for (int i = n; i >= 1; i--) {       int cnt = 0, coef = 1;       memset(sum, 0, sizeof sum);       for (int j = i; j <= n; j++) {         if (a[j] != a[i]) {           if (!sum[a[j]])             ++sum[a[j]], ++cnt;           else             coef = mul(coef, mul(ipw[sum[a[j]]], pw[sum[a[j]] + 1] - 1)),             sum[a[j]]++;         } else {           if (!sum[a[j]])             ++sum[a[j]], ++cnt;           else             coef = mul(coef, 2);         }         if (cnt == c && a[i] != a[j]) {           int now_coef = mul(coef, ipw[sum[a[j]]]);           for (int k = 1; k <= m; k++)             if (g[j + 1][k - 1]) add(f[i][k], mul(now_coef, g[j + 1][k - 1]));         }       }       int all = pw[n - i];       for (int k = 1; k <= m; k++) g[i][k] = inc(g[i + 1][k], f[i][k]);       for (int k = 1; k <= m; k++) sub(all, f[i][k]);       f[i][0] = all, g[i][0] = inc(g[i + 1][0], all);     }     sub(g[1][0], 1);     for (int i = 0; i <= m; i++) printf( %d  , g[1][i]);     for (int i = m + 1; i <= n; i++) printf( 0  );     putchar(10);   }   }  // namespace task1   namespace task2 {   int f[2][maxn][(1 << 10) + 10];   void solve() {     f[0][0][0] = 1;     int mx = (1 << c), m = n / c;     for (int i = 0; i < n; i++) {       int np = i & 1, p = np ^ 1;       memset(f[p], 0, sizeof f[p]);       for (int j = 0; j <= m; j++)         for (int k = 0; k < mx; k++)           if (f[np][j][k]) {             int now = f[np][j][k];             add(f[p][j][k], now);             int t = k | (1 << (a[i + 1] - 1));             if (t == mx - 1)               add(f[p][j + 1][0], now);             else               add(f[p][j][t], now);           }     }     for (int i = 0; i <= n; i++) {       int s = 0;       for (int j = 0; j < mx; j++) add(s, f[n & 1][i][j]);       if (!i) sub(s, 1);       printf( %d  , s);     }     putchar(10);   }   }  // namespace task2   int main() {     n = read(), c = read();     for (int i = 1; i <= n; i++) a[i] = read();     if (c <= 10)       task2::solve();     else       task1::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int> > G;   double dfs(int u, int p = -1) {     double res = 0;     int cnt = 0;     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       if (v == p) continue;       cnt++;       res += dfs(v, u);     }     return (cnt ? res / cnt + 1 : 0);   }   int main() {     cin >> n;     m = n - 1;     G.resize(n + 1);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     cout << setprecision(7) << fixed << dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[1000005], y[1000005];   int s[1000005], _sum[1000006], _sumx[1000006], _sumy[1000006],       *sum = _sum + 1, *sumx = _sumx + 1, *sumy = _sumy + 1;   long long _tot[1000006], *tot = _tot + 1;   const int MOD = 1e9 + 7;   inline int area(int x, int y, int xx, int yy) {     int ret = ((long long)x * yy - (long long)xx * y) % MOD;     if (ret < 0) ret += MOD;     return ret;   }   inline long long areaL(int x, int y, int xx, int yy) {     return (long long)x * yy - (long long)xx * y;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) scanf( %d%d , x + i, y + i);     int ans = 0, mul = -1;     for (int times = 0; times < (int)(2); ++times) {       for (int i = 0; i < (int)(n + 5); ++i) {         x[n + i] = x[i];         y[n + i] = y[i];       }       int N = 2 * n + 4;       for (int i = 0; i < (int)(N); ++i)         s[i] = area(x[i], y[i], x[i + 1], y[i + 1]);       tot[-1] = sum[-1] = sumx[-1] = sumy[-1] = 0;       for (int i = 0; i < (int)(N); ++i)         tot[i] = tot[i - 1] + areaL(x[i], y[i], x[i + 1], y[i + 1]);       for (int i = 0; i < (int)(N); ++i)         sum[i] = (sum[i - 1] - (long long)i * s[i]) % MOD;       for (int i = 0; i < (int)(N); ++i) sumx[i] = (sumx[i - 1] + x[i]) % MOD;       for (int i = 0; i < (int)(N); ++i) sumy[i] = (sumy[i - 1] + y[i]) % MOD;       for (int i = 0, j = 1; i < n; ++i) {         if (j == i) ++j;         while (j < i + n - 2 &&                abs(tot[j] - tot[i - 1] + areaL(x[j + 1], y[j + 1], x[i], y[i])) +                        times <=                    abs(tot[n + i - 1] - tot[j] +                        areaL(x[i], y[i], x[j + 1], y[j + 1]))) {           ++j;         }         if (j == i + 1) continue;         ans = (ans + mul * (sum[j - 1] - sum[i - 1] +                             (tot[j - 1] - tot[i - 1]) % MOD * j - s[i])) %               MOD;         ans = (ans + mul * areaL(sumx[j] - sumx[i + 1], sumy[j] - sumy[i + 1],                                  x[i], y[i])) %               MOD;       }       if (times == 0) {         reverse(x + 1, x + n);         reverse(y + 1, y + n);         mul = 1;       }     }     int ss = 0;     for (int i = 0; i < (int)(n); ++i)       ss = (ss + area(x[i], y[i], x[i + 1], y[i + 1])) % MOD;     ans = ((long long)ss * ((long long)n * (n - 3) / 2 % MOD) - ans) % MOD;     if (ans < 0) ans += MOD;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, c;   } a[100005];   int b, c, d, e, f[205], g, h, i, j, k, l, m, n, s[100005];   inline bool cmp(node a, node b) { return a.l < b.l; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i].l);     for (i = 1; i <= n; i++) scanf( %d , &a[i].c);     sort(a + 1, a + 1 + n, cmp);     for (i = 1; i <= n; i++) s[i] = s[i - 1] + a[i].c;     h = s[n];     for (i = 1; i <= n; i = j + 1) {       for (j = i; a[j + 1].l == a[i].l; j++)         ;       k = j - i + 1;       g = s[n] - s[j];       for (l = 1, d = i - k; l <= 200 && d > 0; l++) {         if (d > f[l]) {           d = d - f[l];           g = g + f[l] * l;         } else {           g = g + d * l;           d = 0;         }       }       h = min(h, g);       for (l = i; l <= j; l++) f[a[l].c]++;     }     printf( %d n , h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; }   struct disjoint_sets {     int parent[100000 + 10];     int ccOfParent[100000 + 10];     int cc;     disjoint_sets(int V) {       cc = V;       for (int i = 1; i <= V; i++) parent[i] = i, ccOfParent[i] = 1;     }     int getParent(int a) {       if (parent[a] == a) return a;       return parent[a] = getParent(parent[a]);     }     void link(int a, int b) {       ccOfParent[getParent(b)] += ccOfParent[getParent(a)];       ccOfParent[getParent(a)] = ccOfParent[getParent(b)];       parent[getParent(a)] = getParent(b);     }     bool unionSets(int a, int b) {       int p1 = getParent(a);       int p2 = getParent(b);       if (p1 == p2) return 0;       link(a, b);       cc--;       return 1;     }   };   vector<int> adj[100000 + 10];   int V, E;   vector<pair<int, int> > vec;   bool vis[100000 + 10] = {0};   double solve() {     disjoint_sets s(V);     long long total = 0;     for (int i = 0; i < V; i++) {       int a = vec[i].second;       long long cost = vec[i].first;       for (int j = 0; j < adj[a].size(); j++) {         int b = adj[a][j];         if (!vis[b]) continue;         int cc1 = s.ccOfParent[s.getParent(a)];         int cc2 = s.ccOfParent[s.getParent(b)];         if (s.unionSets(a, b)) total += 2 * cost * cc1 * cc2;       }       vis[a] = 1;     }     return (total / ((double)V * (V - 1)));   }   int main() {     ios_base::sync_with_stdio(false);     cin >> V >> E;     vec.resize(V);     for (int i = 1; i <= V; i++) cin >> vec[i - 1].first, vec[i - 1].second = i;     int a, b;     for (int j = 0; j < E; j++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     sort(vec.rbegin(), vec.rend());     double res = solve();     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }   long long n;   long long x[1010];   long long y[1010];   int main() {     cin >> n;     for (int i = 0; i < n / 3; i++) {       printf( %d %d n , 0, i * 2 + 1);     }     for (int i = 0; i < n - n / 3; i++) {       printf( %d %d n , 3, i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   struct Point {     long long x, y;     int id;     Point(int _x = 0, int _y = 0, int _id = 0) : x(_x), y(_y), id(_id) {}     void read(int i) {       id = i;       scanf( %lld%lld , &x, &y);     }   } ps[maxn];   Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }   long long cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }   Point base;   bool cmp(Point a, Point b) { return cross(a - base, b - base) > 0; }   char s[maxn];   int vis[maxn], ans[maxn];   Point t[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       ps[i].read(i);     }     Point start = ps[1];     for (int i = 2; i <= n; i++) {       if (ps[i].y < start.y) start = ps[i];     }     ans[1] = start.id;     vis[start.id] = 1;     base = start;     scanf( %s , s + 1);     for (int i = 2; i < n; i++) {       int cnt = 0;       for (int j = 1; j <= n; j++)         if (!vis[j]) t[cnt++] = ps[j];       sort(t, t + cnt, cmp);       if (s[i - 1] ==  L ) {         ans[i] = t[0].id;         vis[t[0].id] = 1;         base = t[0];       } else {         ans[i] = t[cnt - 1].id;         vis[t[cnt - 1].id] = 1;         base = t[cnt - 1];       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) ans[n] = i;     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a, b, f = 0;     long long min = 500, max = 0;     string s =   ;     long long suma = 0, sumb = 0;     for (int i = 0; i < n; i++) {       cin >> a >> b;       if (abs((suma + a) - sumb) <= 500) {         s +=  A ;         suma += a;       } else if (abs(suma - (sumb + b)) <= 500) {         s +=  G ;         sumb += b;       } else {         cout <<  -1 n ;         f = 1;         break;       }     }     if (f == 0) cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   int main() {     int n, m, cnt, i, j;     while (~scanf( %d%d , &n, &m)) {       if ((n % 2 == 0 && m * 2 <= n * n) || (n % 2 && m * 2 <= n * n + 1)) {         printf( YES n );         cnt = 0;         for (i = 1; i <= n; i++) {           for (j = 1; j <= n; j++) {             if (i % 2 == j % 2 && cnt < m) {               printf( L );               cnt++;             } else               printf( S );           }           printf(  n );         }       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   const int MAXN = 1e6 + 10;   bool pal(string s) {     string t = s;     reverse(t.begin(), t.end());     return s == t;   }   void solve() {     string s;     cin >> s;     int n = s.size();     int ans = 10;     int m = (n + 1) / 2;     for (int i = m; i + 1 < n; i++) {       if (s[i] != s[i + 1]) {         ans = 3 + n % 2;         break;       }     }     for (int i = 0; i < n / 2; i++) {       string t = s.substr(0, i + 1);       if (!pal(t)) {         ans = 2;         break;       }     }     for (int i = 1; i < n; i++) {       string t = s.substr(i) + s.substr(0, i);       if (t != s && pal(t)) {         ans = 1;         break;       }     }     if (ans < 10) {       cout << ans <<   n ;     } else {       cout <<  Impossible n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using llong = long long;   inline char Flip(char x) { return (x ==  0 ) ?  1  :  0 ; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     vector<int> ans;     while (t--) {       int n;       cin >> n;       n *= 2;       vector<int> a(n);       for (int& i : a) cin >> i;       vector<int> b;       int i = n - 1;       while (i >= 0) {         int j = max_element(a.begin(), a.begin() + i + 1) - a.begin();         b.push_back(i - j + 1);         i = j - 1;       }       bitset<4001> dp;       dp[0] = 1;       for (int len : b) dp = dp | (dp << len);       if (dp[n / 2])         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, u, v, flag, num, vis[100100];   vector<int> edge[100100];   queue<int> sk[100100];   struct G {     int a, b, c;   } ans[100100];   void dfs(int u, int father) {     vis[u] = true;     for (int i = 0; i < edge[u].size(); ++i) {       int v = edge[u][i];       if (vis[v] == false)         dfs(v, u);       else if (v != father && vis[v] == true)         sk[v].push(u);     }     while (sk[u].size() >= 2) {       int x = sk[u].front();       sk[u].pop();       int y = sk[u].front();       sk[u].pop();       ans[++num] = {x, u, y};     }     if (sk[u].size() == 1) {       if (father == 0) flag = 1;       int x = sk[u].front();       sk[u].pop();       ans[++num] = {x, u, father};     } else       sk[father].push(u);   }   int main() {     cin >> n >> m;     if (m % 2 == 1) {       cout <<  No solution  << endl;       return 0;     }     for (int i = 1; i <= m; ++i) {       cin >> u >> v;       edge[u].push_back(v);       edge[v].push_back(u);     }     dfs(1, 0);     if (flag == 1)       cout <<  No solution  << endl;     else {       for (int i = 1; i <= num; ++i) {         cout << ans[i].a <<     << ans[i].b <<     << ans[i].c << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k, i, start;     bool b;     while (scanf( %d%d , &n, &k) != EOF) {       if (n < k || k == 1 && n > 1) {         printf( -1 n );         continue;       }       start = k;       for (i = b = 0; i < n; i++) {         if (b && n - i == k - 2) {           start = 2;           break;         }         if (!b && n - i == k - 1) {           start = 1;           break;         }         printf(i& 1 ? b = 1,  b  :  a );       }       for (i = start; i < k; i++) printf( %c , i +  a );       printf(  n );     }     return 0;   }


#include<bits/stdc++.h>   #define pb push_back   using namespace std;   typedef long long ll;   const int maxn=1e6+100;   const int M=1000000007;   typedef array<int,41> A;   struct hasher {       size_t operator()(const A& p) const {           size_t result = 0;           for (int i=1;i<=40;i++) result = result * 19260817 + p[i];           return result;       }   };   bool vis[50];   int f[50],n,mx,F[50][50],G[50][50],p[50],nf[50],inv[50];   int ways[50][50][50];   unordered_map<A,int,hasher> dp[41][41][41];   void add(int &x,int y){x+=y;if (x>=M)x-=M;}   int C(int x,int y){    if (y<0||y>x) return 0;    return 1ll*f[x]*nf[y]%M*nf[x-y]%M;   }   void init(){    inv[1]=1; for (int i=2;i<=n;i++) inv[i]=M-1ll*(M/i)*inv[M%i]%M;    f[0]=nf[0]=1; for (int i=1;i<=n;i++) f[i]=1ll*f[i-1]*i%M,nf[i]=1ll*nf[i-1]*inv[i]%M;    F[0][0]=f[n-1];    for (int i=0;i<=n-1;i++)    for (int j=1;j+i<=n-1;j++){           F[i][j]=0;           for (int x=0;x<=i;x++)      for (int y=0;y<=j;y++){       add(F[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M);       if (!y) add(G[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M);      }    }    for (int i=0;i<=n-1;i++)    for (int j=0;j+i<=n-1;j++){     int x=1,y=1;     for (int k=1;k<=n;k++){      x=1ll*x*F[i][j]%M;      y=1ll*y*G[i][j]%M;      ways[i][j][k]=(x-y+M)%M;     }    }   }   int solve(int lasttot,int tot,int block,A a){       if (dp[lasttot][tot][block].find(a)!=dp[lasttot][tot][block].end()){     return dp[lasttot][tot][block][a];       }       int ret=0,sum=n;       for (int i=1;i<=mx;i++) sum-=a[i]*i;       if (sum==n) return dp[lasttot][tot][block][a]=nf[block];    A tmp=a;       for (int i=1;i<=mx;i++) {     if (a[i]){      tmp[i]--;               add(ret,1ll*ways[sum-tot-lasttot][lasttot][i]*a[i]%M*solve(lasttot,tot+i,block+1,tmp)%M);               if (block) add(ret,1ll*ways[sum-tot][tot][i]*a[i]%M*nf[block]%M*solve(tot,i,1,tmp)%M);      tmp[i]++;     }       }       return dp[lasttot][tot][block][a]=ret;   }   int main(){    scanf( %d ,&n);    init();    for (int i=1;i<=n;i++) scanf( %d ,&p[i]);    A a;    for (int i=0;i<=40;i++) a[i]=0;    for (int i=1;i<=n;i++) if (!vis[i]){     int w=0,tmp=i;     while (!vis[tmp]){      w++;      vis[tmp]=1;      tmp=p[tmp];     }     a[w]++;     mx=max(mx,w);    }    printf( %d n ,solve(0,0,0,a));    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 1000100;   int link[NN], fail[NN], len[NN], dif[NN], nxt[NN][26];   int ed, sz, cur;   char s[NN], S[NN], T[NN];   int tp[NN], dp[NN], pre[NN], pr[NN];   void clear(int u, int L = 0) { len[u] = L; }   void init() {     sz = 2;     ed = 1;     cur = 0;     s[cur] = -1;     clear(0);     clear(1, -1);     fail[0] = 1;   }   inline int get_fail(int u) {     while (s[cur - len[u] - 1] != s[cur]) u = fail[u];     return u;   }   int insert(char c) {     s[++cur] = c -=  a ;     ed = get_fail(ed);     if (!nxt[ed][c]) {       int p1 = sz++;       clear(p1, len[ed] + 2);       fail[p1] = nxt[get_fail(fail[ed])][c];       nxt[ed][c] = p1;       dif[p1] = len[p1] - len[fail[p1]];       if (dif[p1] == dif[fail[p1]])         link[p1] = link[fail[p1]];       else         link[p1] = fail[p1];     }     ed = nxt[ed][c];     return ed;   }   int main() {     scanf( %s%s , S, T);     int n = strlen(S);     init();     memset(tp, 0x3f, sizeof tp);     for (int i = 1, now; i <= n * 2; i++) {       if (i & 1)         now = insert(S[i - 1 >> 1]);       else         now = insert(T[i - 1 >> 1]);       dp[i] = 0x3f3f3f3f;       if ((~i & 1) && S[i - 1 >> 1] == T[i - 1 >> 1]) {         dp[i] = dp[i - 2];         pre[i] = i - 2;       }       for (int u = now; u; u = link[u]) {         pr[u] = i - len[link[u]] - dif[u];         tp[u] = dp[pr[u]];         if (link[u] ^ fail[u]) {           if (tp[u] > tp[fail[u]]) {             tp[u] = tp[fail[u]];             pr[u] = pr[fail[u]];           }         }         if (~i & 1) {           if (dp[i] > tp[u] + 1) {             dp[i] = tp[u] + 1;             pre[i] = pr[u];           }         }       }     }     if (dp[n * 2] == 0x3f3f3f3f) return puts( -1 );     vector<pair<int, int>> ans;     int now = n * 2;     while (now) {       int pre = ::pre[now];       if (now - pre > 2) ans.emplace_back((pre >> 1) + 1, now >> 1);       now = pre;     }     cout << ans.size() << endl;     for (auto &a : ans) printf( %d %d n , a.first, a.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Fenwick {     vector<long long> BIT;     long long N;     Fenwick(long long n) {       N = n + 2;       BIT.resize(N + 10);     }     void reset() {       for (long long i = 0; i <= N; i++) {         BIT[i] = 0;       }     }     void add(long long r, long long value) {       for (long long i = r; i <= N; i = i | (i + 1)) {         BIT[i] += value;       }     }     long long qry(long long r) {       long long ans = 0;       for (long long i = r; i >= 0; i = (i & (i + 1)) - 1) {         ans += BIT[i];       }       return ans;     }   };   const long long N = (long long)1e6;   void solve() {     long long n, m;     cin >> n >> m;     vector<array<long long, 3>> x(n), y(m);     for (auto &i : x) {       cin >> i[0] >> i[1] >> i[2];     }     for (auto &i : y) {       cin >> i[0] >> i[1] >> i[2];     }     m += 1;     y.push_back({N, 0, N});     long long ans = 0;     Fenwick sg(N + 10);     sg.add(N, 1);     sg.add(0 * 1LL, 1);     sort(y.begin(), y.end());     vector<vector<long long>> add(N + 10), remove(N + 10);     for (auto &i : x) {       if (i[1] == 0) {         add[0].push_back(i[0]);         remove[i[2]].push_back(i[0]);       } else {         add[i[1]].push_back(i[0]);         remove[N - 1].push_back(i[0]);       }     }     long long cur = 0;     42;     for (long long i = 0; i <= N; i++) {       for (auto &j : add[i]) {         sg.add(j, 1);       }       while (cur < m and y[cur][0] == i) {         long long u = max(y[cur][1], y[cur][2]);         long long v = min(y[cur][1], y[cur][2]);         if (v == 0) {           ans += (sg.qry(u) - 1);         } else {           ans += (sg.qry(u) - sg.qry(v - 1) - 1);         }         cur += 1;       }       for (auto &j : remove[i]) {         sg.add(j, -1);       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = 1e18;   const long long INF = 1e9;   const long long MOD = 1000000007;   const long long MAX = 100005;   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -ffloat-store )   #pragma GCC optimize( -fno-defer-pop )   long long strtoll(string second) {     stringstream str(second);     long long number = 0;     str >> number;     return number;   }   string lltostr(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   bool prime[MAX];   void sieve() {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long p = 2; p * p <= MAX; p++) {       if (prime[p] == true) {         for (long long i = p * 2; i <= MAX; i += p) prime[i] = false;       }     }   }   long long power(long long a, long long b, long long m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long t = power(a, b / 2, m);     t = (t * t) % m;     if (b & 1) t = (t * a) % m;     return t;   }   long long modInverse(long long a, long long m) { return power(a, m - 2, m); }   long long __gcd(long long a, long long b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   bool cmp(const pair<long long, long long> &l,            const pair<long long, long long> &r) {     return l.first < r.first;   }   void solve() {     long long n, m;     cin >> n >> m;     long long a[n + 1], c[n + 1];     for (long long i = 0; i < n; i++) cin >> a[i + 1];     for (long long i = 0; i < n; i++) cin >> c[i + 1];     map<long long, long long> mm;     set<pair<long long, long long> > second;     for (long long i = 1; i <= n; i++) second.insert({c[i], i});     for (long long i = 1; i <= n; i++) mm[i] = a[i];     while (m--) {       long long ans = 0;       long long type, q;       cin >> type >> q;       if (mm[type] >= q) {         ans += c[type] * q;         mm[type] -= q;       } else {         ans += mm[type] * c[type];         q -= mm[type];         mm[type] = 0;         while (q && !second.empty()) {           pair<long long, long long> p = *second.begin();           long long x = p.first;           long long y = p.second;           if (mm[y] >= q) {             mm[y] -= q;             ans += (c[y] * q);             q = 0;           } else {             ans += mm[y] * c[y];             q -= mm[y];             mm[y] = 0;             second.erase(second.begin());           }         }         if (q != 0) ans = 0;       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<int> > map1;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       map1[i].push_back(a);       map1[a].push_back(i);     }     int counter = 0;     map<int, bool> check;     for (int i = 1; i <= n; i++) {       if (!check[i]) {         counter++;         queue<int> que;         que.push(i);         while (que.size()) {           int front = que.front();           que.pop();           if (!check[front])             for (int j = 0; j < map1[front].size(); j++) {               que.push(map1[front][j]);             }           check[front] = true;         }       }     }     cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   long long n, q;   long long a[maxn];   long long cost(long long g) {     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < g)         ans += g - a[i];       else         ans += min(a[i] % g, g - a[i] % g);     }     return ans;   }   long long ans = inf;   void DO(long long x) {     if (x <= 1) return;     for (long long i = 2; i <= sqrt(x); i++)       if (x % i == 0) {         ans = min(ans, cost(i));         while (x % i == 0) x /= i;       }     if (x > 1) ans = min(ans, cost(x));   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     random_shuffle(a + 1, a + n + 1);     for (long long i = 1; i <= 10; i++) DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);     for (long long i = n / 3; i <= n / 3 + 15; i++)       DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);     for (long long i = 2 * n / 3; i <= 2 * n / 3 + 15; i++)       DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);     for (long long i = n; i >= n - 10; i--) DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long h, n;   int main() {     cin >> h >> n;     long long ans = 0;     long long l = 1, r = (1LL << h);     int dir = 0;     for (int i = h - 1; i >= 0; i--) {       ans++;       long long mid = (l + r) / 2;       if (dir == 0) {         if (mid < n) {           ans += (1LL << (i + 1)) - 1;           dir = 0;           l = mid + 1;         } else {           r = mid;           dir = 1;         }       } else {         if (n <= mid) {           ans += (1LL << (i + 1)) - 1;           dir = 1;           r = mid;         } else {           l = mid + 1;           dir = 0;         }       }     }     cout << ans << endl;   }