#include <bits/stdc++.h>   using namespace std;   const int OO = 2e9;   const int MOD = 1e9 + 7;   const double Pi = 3.141592653589793;   const int N = 3e5 + 5;   long long c[N], v[N], g[N], a[N], n, k, s, t, m = 0, mx = 0, mn = -1, res = OO;   bool check(long long cap) {     long long time = 0;     for (int i = (int)1; i <= (int)m; i++) {       if (a[i] > cap) return false;       long long y = max(0LL, min(a[i], cap - a[i])), x = a[i] - y;       time += 2LL * x + y;     }     return (time <= t);   }   int main() {     cin >> n >> k >> s >> t;     if (s > t) {       cout << -1;       return 0;     }     for (int i = (int)1; i <= (int)n; i++) scanf( %i%i , &v[i], &c[i]);     for (int i = (int)1; i <= (int)k; i++) scanf( %i , &g[i]);     g[++k] = s;     g[++k] = 0;     sort(g + 1, g + k + 1);     for (int i = (int)2; i <= (int)k; i++)       a[++m] = g[i] - g[i - 1], mx = max(mx, a[m]);     long long l = mx, r = s * 2, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         mn = mid, r = mid - 1;       else         l = mid + 1;     }     for (int i = (int)1; i <= (int)n; i++)       if (c[i] >= mn) res = min(res, v[i]);     if (res == OO)       cout << -1;     else       cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int cys = 998244353;   int n, k;   long long mod(long long x) { return x >= cys ? x - cys : x; }   namespace task1 {   long long d[2025][2025];   void work() {     d[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= n; j++) {         d[i][j] = d[i - 1][j];         if (j >= i) d[i][j] = mod(d[i][j] + d[i][j - i]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans = mod(ans + d[n][i]);     printf( %lld n , ans);   }   }  // namespace task1   namespace task2 {   long long d[2025][2025], f[2025][2025];   void work() {     d[0][0] = 1;     for (int i = n; i >= 1; i--)       for (int j = 0; j <= n / i; j++)         for (int k = 0; k <= n; k++)           if (j && k >= i * j) d[j][k] = mod(d[j][k] + d[j - 1][k - i * j]);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= n; j++) ans = mod(ans + d[i][j]);     printf( %lld n , ans);   }   }  // namespace task2   namespace taskg3 {   vector<int> a;   map<vector<int>, bool> bk;   int ans;   bool check(vector<int> x) {     vector<int> tmp(0);     for (int i = 0; i < x.size(); i++)       for (int j = 0; j < x[i]; j++) tmp.push_back(i + 1);     int sum = 0;     for (int i = 0; i < tmp.size(); i++) sum += tmp[i] * (tmp.size() - i);     return sum <= n;   }   vector<int> getans(vector<int> x) {     sort(x.begin(), x.end());     int lst = 0;     vector<int> ret(0);     for (int i = 1; i < x.size(); i++)       if (x[i] != x[i - 1]) ret.push_back(i - lst), lst = i;     ret.push_back(x.size() - lst);     return ret;   }   bool dfs(int now, int sum) {     if (now >= 1) {       if (!check(a)) return 0;       vector<int> tmp = a;       for (int i = 1; i <= k - 3; i++) tmp = getans(tmp);       sort(tmp.begin(), tmp.end());       if (!bk.count(tmp)) bk[tmp] = 1, ans++;     }     int g = now ? a[now - 1] : 64;     for (int i = 1; i <= g && i <= 64 - sum; i++) {       a.push_back(i);       if (!dfs(now + 1, sum + i)) {         a.pop_back();         break;       }       a.pop_back();     }     return 1;   }   void work() {     ans = 0;     dfs(0, 0);     printf( %d n , ans);   }   }  // namespace taskg3   int main() {     n = readint();     k = readint();     if (k >= 20)       printf( 1 n );     else if (k == 1)       task1::work();     else if (k == 2)       task2::work();     else       taskg3::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = INT_MAX;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> first(n, INF);     vector<long long> last(n, -INF);     for (long long i = 0; i < n; ++i) {       cin >> a[i];       --a[i];       first[a[i]] = min(first[a[i]], i);       last[a[i]] = max(last[a[i]], i);     }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     long long now = 0;     long long mx = 0;     long long ans = 0;     n = a.size();     for (long long i = 0; i < n; ++i) {       if (i) {         if (first[a[i]] > mx)           ++now;         else           now = 1;         mx = last[a[i]];         ans = max(ans, now);       } else {         now = 1;         mx = max(mx, last[a[i]]);         ans = max(ans, now);       }     }     cout << a.size() - ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e15;   class LazySegmentTree {    private:     int n;     vector<pair<long long, int>> node;     vector<long long> lazy;       public:     LazySegmentTree(vector<long long> v) {       n = 1;       while (n < v.size()) n *= 2;       node.resize(2 * n - 1, make_pair(-INF, 0));       lazy.resize(2 * n - 1, 0);       for (int i = 0; i < v.size(); i++) node[i + n - 1] = make_pair(v[i], i);       for (int i = n - 2; i >= 0; i--)         node[i] = max(node[2 * i + 1], node[2 * i + 2]);     }     void eval(int k, int l, int r) {       if (lazy[k] != 0) {         node[k].first += lazy[k];         if (r - l > 1) {           lazy[2 * k + 1] += lazy[k];           lazy[2 * k + 2] += lazy[k];         }         lazy[k] = 0;       }     }     void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {       if (r < 0) r = n;       eval(k, l, r);       if (b <= l || r <= a) return;       if (a <= l && r <= b) {         lazy[k] += x;         eval(k, l, r);       } else {         add(a, b, x, 2 * k + 1, l, (r + l) / 2);         add(a, b, x, 2 * k + 2, (r + l) / 2, r);         node[k] = max(node[2 * k + 1], node[2 * k + 2]);       }     }     pair<long long, int> getMax(int a, int b, int k = 0, int l = 0, int r = -1) {       if (r < 0) r = n;       eval(k, l, r);       if (b <= l || r <= a) return make_pair(-INF, 0);       if (a <= l && r <= b) {         return node[k];       }       pair<long long, int> vl, vr;       vl = getMax(a, b, 2 * k + 1, l, (l + r) / 2);       vr = getMax(a, b, 2 * k + 2, (l + r) / 2, r);       return max(vl, vr);     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N;     cin >> N;     vector<long long> X(N), Y(N), C(N);     for (int i = 0; i < (N); ++i) cin >> X[i] >> Y[i] >> C[i];     vector<long long> v;     map<long long, int> mp;     map<int, long long> rev;     for (int i = 0; i < N; i++) {       v.push_back(X[i]);       v.push_back(Y[i]);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 0; i < v.size(); i++) {       mp[v[i]] = i;       rev[i] = v[i];     }     int V = v.size();     vector<vector<int>> rig(V), lef(V);     for (int i = 0; i < N; i++) {       lef[mp[min(X[i], Y[i])]].push_back(i);       rig[mp[max(X[i], Y[i])]].push_back(i);     }     vector<long long> input(V, 0);     for (int i = 0; i < (N); ++i) input[V - 1] += C[i];     for (int i = V - 2; i >= 0; i--) {       input[i] = input[i + 1];       for (auto ng : rig[i + 1]) input[i] -= C[ng];     }     for (int i = 0; i < V; i++) input[i] -= rev[i];     LazySegmentTree seg(input);     vector<int> del(N, 0);     long long ans = 0;     int x = 2000000000;     int y = x;     for (int i = 0; i < V; i++) {       auto f = seg.getMax(i, V);       long long val = f.first;       if (ans < val + rev[i]) {         ans = val + rev[i];         x = rev[i];         y = rev[f.second];       }       for (auto n : lef[i]) {         if (del[n]) continue;         del[n] = 1;         seg.add(mp[max(X[n], Y[n])], V, -C[n]);       }     }     cout << ans << endl;     cout << min(x, y) <<     << min(x, y) <<     << max(y, x) <<     << max(y, x)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int inf = 1e9;   int mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     int L[n], R[n];     for (int i = 0; i < n; i++) cin >> L[i] >> R[i];     map<int, vector<int>> start, end;     set<int> line;     for (int i = 0; i < n; i++) {       start[L[i]].push_back(i);       end[R[i]].push_back(i);       line.insert(L[i]);       line.insert(R[i]);     }     set<int> s;     int prev = 0;     int dp[1 << 8];     map<int, int> order[2 * n + 1];     int cnt = 0;     int ans = 0;     memset(dp, 0, sizeof(dp));     for (int cur : line) {       for (int u : start[cur]) s.insert(u);       cnt++;       vector<int> val;       int e = 0;       for (int u : s) {         order[cnt][u] = e++;         val.push_back(u);       }       vector<int> temp(1 << 8, 0);       for (int i = 0; i < (1 << (int)val.size()); i++) {         int bit = 0;         int y = 0, z = 0;         for (int j = 0; j < (int)val.size(); j++) {           if ((i >> j) & 1) {             int x = val[j];             if (order[cnt - 1].find(x) != order[cnt - 1].end()) {               bit |= (1 << order[cnt - 1][x]);               y ^= 1;             }             z ^= 1;           }         }         temp[i] = dp[bit];         temp[i] += y * (cur - prev - 1);         temp[i] += z;         ans = max(ans, temp[i]);       }       vector<int> f, b;       for (int u : end[cur]) {         b.push_back(u);         s.erase(s.find(u));       }       for (int u : s) {         f.push_back(u);       }       memset(dp, 0, sizeof(dp));       for (int i = 0; i < (1 << (int)f.size()); i++) {         int bit = 0;         for (int k = 0; k < (int)f.size(); k++) {           if ((i >> k) & 1) {             bit |= (1 << order[cnt][f[k]]);           }         }         int x = bit;         for (int j = 0; j < (1 << (int)b.size()); j++) {           bit = x;           for (int k = 0; k < (int)b.size(); k++) {             if ((j >> k) & 1) {               bit |= (1 << order[cnt][b[k]]);             }           }           dp[x] = max(dp[x], temp[bit]);         }       }       prev = cur;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, bool> &a, const pair<int, bool> &b) {     return (a.first < b.first || (a.first == b.first && a.second < b.second));   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     int res = n;     vector<pair<int, bool> > a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = 0;     }     sort(a.begin(), a.end());     vector<pair<int, bool> >::iterator it = a.begin();     for (int i = 0; i < a.size() - 1; i++) {       for (int j = i + 1; j < a.size(); j++) {         if (a[i].first < a[j].first && !a[j].second) {           a[j].second = 1;           res--;           break;         }       }     }     cout << res <<   n ;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int> lott;   int main() {     long long int xm, find = 0;     cin >> xm;     lott.push(100);     lott.push(20);     lott.push(10);     lott.push(5);     lott.push(1);     while (xm) {       while (lott.top() <= xm) {         find++;         xm -= lott.top();       }       lott.pop();     }     cout << find << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m[4], x, y, a;   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     for (long long i = 0; i < 10; ++i) {       cout << i << i << i << i << endl;       cin >> x >> y;       if (x == 1) m[a++] = i;     }     for (long long i = 0; i < 24; ++i) {       next_permutation(m, m + 4);       for (long long i = 0; i < 4; ++i) cout << m[i];       cout << endl;       cin >> x >> y;       if (x == 4) return cout << endl, 0;     }   }


#include <bits/stdc++.h>   using namespace std;   char str[200010];   int tim[200010];   int main() {     memset(tim, 0x3f, sizeof(tim));     int n, k;     scanf( %d %d , &n, &k);     scanf( %s , str);     for (int i = 0; i < n; i++)       if (str[i] == str[(i + 1) % n] || str[i] == str[(i - 1 + n) % n])         tim[i] = 0;     for (int i = 0; i < 2 * n; i++)       tim[i % n] = min(tim[i % n], tim[(i - 1 + n) % n] + 1);     for (int i = 2 * n - 1; i >= 0; i--)       tim[i % n] = min(tim[i % n], tim[(i + 1) % n] + 1);     for (int i = 0; i < n; i++)       if (min(tim[i], k) & 1)         printf( %c ,  W  +  B  - str[i]);       else         printf( %c , str[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1, s2, virus;   pair<int, int> dp[105][105][105];   int l1, l2, lvirus;   string ans =   ;   int pi[105];   void pf(string s) {     memset(pi, 0, sizeof(pi));     int n = (int)s.length();     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }   }   int main() {     cin >> s1 >> s2 >> virus;     l1 = s1.length();     l2 = s2.length();     lvirus = virus.length();     int i, j, k;     for (i = 1; i <= l1; i++) {       for (j = 1; j <= l2; j++) {         for (k = 0; k < lvirus; k++) {           if (dp[i][j][k].first <= dp[i - 1][j][k].first) {             dp[i][j][k].first = dp[i - 1][j][k].first;             dp[i][j][k].second = 1;           }           if (dp[i][j][k].first <= dp[i][j - 1][k].first) {             dp[i][j][k].first = dp[i][j - 1][k].first;             dp[i][j][k].second = 2;           }           if (s1[i - 1] == s2[j - 1]) {             if (k != 0 && s1[i - 1] == virus[k - 1]) {               if (dp[i][j][k].first < dp[i - 1][j - 1][k - 1].first + 1) {                 dp[i][j][k].first = dp[i - 1][j - 1][k - 1].first + 1;                 dp[i][j][k].second = 3;               }             }             int z = k;             if (s1[i - 1] != virus[z]) {               char c = virus[z];               virus[z] = s1[i - 1];               pf(virus);               int v = pi[z];               if (dp[i][j][v].first < dp[i - 1][j - 1][z].first + 1) {                 dp[i][j][v].first = dp[i - 1][j - 1][z].first + 1;                 dp[i][j][v].second = 10 + z;               }               virus[z] = c;             }           }         }       }     }     int mx = 0, cur = -1;     for (i = 0; i < lvirus; i++) {       if (mx <= dp[l1][l2][i].first) {         cur = i;         mx = dp[l1][l2][i].first;       }     }     if (mx == 0) {       cout << 0;       return 0;     }     i = l1;     j = l2;     while (i != 0 && j != 0) {       if (dp[i][j][cur].second == 1) {         i--;         continue;       }       if (dp[i][j][cur].second == 2) {         j--;         continue;       }       if (dp[i][j][cur].second == 3) {         ans = s1[i - 1] + ans;         i--;         j--;         cur--;         continue;       }       ans = s1[i - 1] + ans;       cur = dp[i][j][cur].second - 10;       i--;       j--;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     cin >> n >> k;     if (k == 1 || k == n) {       cout << 3 * n << endl;       return 0;     } else {       int sum = 0;       if (k & 1) {         if (k >= n / 2 + 1) {           k = n - k + 1;         }       } else {         if (k > n / 2) {           k = n - k + 1;         }       }       int cnt = 0;       for (i = k; i >= 1; i--) {         if (cnt == 1) {           sum += 4;         } else {           sum += 3;         }         cnt++;       }       sum--;       sum += k;       for (i = k + 1; i <= n; i++) {         sum += 3;       }       sum--;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v;   };   const int MAXN = 2e5 + 5;   int p[MAXN];   vector<Edge> edges;   vector<int> G[MAXN];   bool va[MAXN], vb[MAXN];   int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }   int main() {     memset(va, 0, sizeof(va));     memset(vb, 0, sizeof(vb));     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) p[i] = i;     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       edges.push_back((Edge){u, v});     }     int s, t, ds, dt;     scanf( %d%d%d%d , &s, &t, &ds, &dt);     vector<Edge> g;     bool ok = 0;     for (int i = 0; i < edges.size(); i++) {       int u = edges[i].u, v = edges[i].v;       bool flag = 0;       if (u == s || u == t) G[u].push_back(v), flag = 1;       if (v == s || v == t) G[v].push_back(u), flag = 1;       if (flag) continue;       u = find(u), v = find(v);       if (u != v) {         p[v] = u;         g.push_back((Edge){edges[i].u, edges[i].v});       }     }     for (int i = 0; i < G[s].size(); i++) va[G[s][i]] = 1;     for (int i = 0; i < G[t].size(); i++) vb[G[t][i]] = 1;     int as = 0, at = 0;     for (int i = 0; i < G[s].size(); i++) {       if (as > ds) break;       if (G[s][i] == t) {         ok = 1;         continue;       }       if (vb[G[s][i]]) continue;       int u = find(s), v = find(G[s][i]);       if (u != v) {         as++;         p[u] = v;         g.push_back((Edge){s, G[s][i]});       }     }     for (int i = 0; i < G[s].size(); i++) {       if (as >= ds) break;       if (G[s][i] == t) {         ok = 1;         continue;       }       int u = find(s), v = find(G[s][i]);       if (u != v) {         as++;         p[u] = v;         g.push_back((Edge){s, G[s][i]});       }     }     for (int i = 0; i < G[t].size(); i++) {       if (at > dt) break;       if (G[t][i] == s) {         ok = 1;         continue;       }       int u = find(t), v = find(G[t][i]);       if (u != v) {         at++;         p[u] = v;         g.push_back((Edge){t, G[t][i]});       }     }     int u = find(s), v = find(t);     if (u != v) {       if (ok) {         g.push_back((Edge){s, t});         as++;         at++;       } else {         puts( No );         return 0;       }     }     if (as > ds || at > dt)       puts( No );     else {       puts( Yes );       for (int i = 0; i < g.size(); i++) {         printf( %d %d n , g[i].u, g[i].v);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dept[105], lend[105];   int main() {     int n, m, a, b, c, sum = 0;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &a, &b, &c);       lend[b] += c;       dept[a] += c;     }     for (int i = 1; i <= n; ++i) {       if (lend[i] < dept[i]) sum += dept[i] - lend[i];     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int vis[601], co[601], fa[601], d[601];   int zb(int o, int l, int r) {     int ans1 = 0, ans2 = 0;     int sz = 0;     for (int i = l; i <= r; i++)       if (!vis[i]) sz++;     if (sz > 0) {       printf( ? %d n , sz + 1);       for (int i = l; i <= r; i++)         if (!vis[i]) printf( %d  , i);       printf( %d n , o);       fflush(stdout);       scanf( %d , &ans1);     }     if (sz > 1) {       printf( ? %d n , sz);       for (int i = l, ok = 0; i <= r; i++)         if (!vis[i]) printf(!ok ? ok = 1,  %d  :   %d , i);       printf(  n );       fflush(stdout);       scanf( %d , &ans2);     }     return ans1 - ans2;   }   int nx(int o) {     if (!zb(o, 1, n)) return 0;     int l = 1, r = n;     while (l != r) {       int mid = l + r >> 1;       if (zb(o, l, mid))         r = mid;       else         l = mid + 1;     }     return l;   }   void dfs(int u) {     for (;;) {       int v = nx(u);       if (!v) break;       vis[v] = 1;       co[v] = co[u] ^ 1;       fa[v] = u;       d[v] = d[u] + 1;       dfs(v);     }   }   int zb2(int o, int l, int r, int* wd) {     int ans1 = 0, ans2 = 0;     int sz = 0;     for (int i = l; i <= r; i++)       if (wd[i] != o) sz++;     if (sz > 0) {       printf( ? %d n , sz + 1);       for (int i = l; i <= r; i++)         if (wd[i] != o) printf( %d  , wd[i]);       printf( %d n , o);       fflush(stdout);       scanf( %d , &ans1);     }     if (sz > 1) {       printf( ? %d n , sz);       for (int i = l, ok = 0; i <= r; i++)         if (wd[i] != o) printf(!ok ? ok = 1,  %d  :   %d , wd[i]);       printf(  n );       fflush(stdout);       scanf( %d , &ans2);     }     return ans1 - ans2;   }   int nx2(int o, int* wd) {     if (!zb2(o, 1, wd[0], wd)) return 0;     int l = 1, r = wd[0];     while (l != r) {       int mid = l + r >> 1;       if (zb2(o, l, mid, wd))         r = mid;       else         l = mid + 1;     }     return wd[l];   }   int ld[601], rd[601];   int dd[601];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       if (!vis[i]) vis[i] = 1, co[i] = 0, dfs(i);     for (int i = 1; i <= n; i++)       if (co[i])         rd[++rd[0]] = i;       else         ld[++ld[0]] = i;     for (int i = 1; i <= ld[0]; i++) {       int u = ld[i], v;       if (v = nx2(u, ld)) {         for (; u != v;) {           if (d[u] > d[v])             dd[++dd[0]] = u, u = fa[u];           else             dd[++dd[0]] = v, v = fa[v];         }         dd[++dd[0]] = u;         printf( N %d n , dd[0]);         for (int i = 1; i <= dd[0]; i++)           printf( %d%c , dd[i], i == dd[0] ?   n  :    );         return 0;       }     }     for (int i = 1; i <= rd[0]; i++) {       int u = rd[i], v;       if (v = nx2(u, rd)) {         for (; u != v;) {           if (d[u] > d[v])             dd[++dd[0]] = u, u = fa[u];           else             dd[++dd[0]] = v, v = fa[v];         }         dd[++dd[0]] = u;         printf( N %d n , dd[0]);         for (int i = 1; i <= dd[0]; i++)           printf( %d%c , dd[i], i == dd[0] ?   n  :    );         return 0;       }     }     printf( Y %d n , ld[0]);     for (int i = 1; i <= ld[0]; i++)       printf( %d%c , ld[i], i == ld[0] ?   n  :    );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   char ch[N];   int a[N];   int main() {     int n;     cin >> n;     stack<int> st;     for (int i = 1; i <= n * 2; i++) {       scanf(  %c , ch + i);       if (ch[i] ==  + ) {         st.push(i);       } else {         if (st.empty()) {           puts( NO );           return 0;         }         scanf( %d , a + i);         a[st.top()] = a[i];         st.pop();       }     }     set<int> tmp;     for (int i = 1; i <= n * 2; i++) {       if (ch[i] ==  + ) {         tmp.insert(a[i]);       } else {         if (*tmp.begin() != a[i]) {           puts( NO );           return 0;         }         tmp.erase(tmp.begin());       }     }     puts( YES );     for (int i = 1; i <= n * 2; i++) {       if (ch[i] ==  + ) printf( %d  , a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double esp = 0.00000001;   const int N = 60;   const int PSize = 100;   const double PCross = 0.3;   const double PMuta = 0.05;   int a[200010], t[200010];   int n, T;   vector<int> res;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   bool ok(int k, vector<pair<int, int> > e) {     if (k > e.size()) return false;     int ans = 0;     sort(e.begin(), e.end(), cmp);     for (int i = 0; i < k; i++) ans += e[i].second;     if (ans > T) return false;     res.clear();     for (int i = 0; i < k; i++) res.push_back(e[i].first);     return true;   }   int main() {     cin >> n >> T;     for (int i = 0; i < n; i++) cin >> a[i] >> t[i];     int l = 0, r = n;     while (l < r) {       int mid = (l + r + 1) >> 1;       vector<pair<int, int> > e;       for (int i = 0; i < n; i++)         if (a[i] >= mid) e.push_back(make_pair(i, t[i]));       if (ok(mid, e))         l = mid;       else         r = mid - 1;     }     cout << l << endl << res.size() << endl;     for (int i = 0; i < res.size(); i++) {       if (i) cout <<    ;       cout << res[i] + 1;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a <<   n ;     err(++it, args...);   }   const int MOD = 1e9 + 7, N = 2e5 + 5, B = 32;   vector<int> g[N];   vector<int> inv(N);   map<pair<int, int>, int> mp;   map<int, vector<int>> mpans;   void dfs(int u, int p) {     for (auto v : g[u]) {       if (v == p) continue;       if (mp[{u, v}]) inv[v] += 1;       dfs(v, u);       inv[u] += inv[v];     }   }   void dfs1(int u, int p, int temp) {     mpans[temp].push_back(u);     for (auto v : g[u]) {       if (v == p) continue;       int v1;       if (mp[{u, v}])         v1 = -1;       else         v1 = 1;       dfs1(v, u, temp + v1);     }   }   void solve() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       mp[{x, y}] = 0;       mp[{y, x}] = 1;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 0);     dfs1(1, 0, inv[1]);     auto xx = *mpans.begin();     cout << xx.first <<   n ;     sort(xx.second.begin(), xx.second.end());     for (auto r : xx.second) cout << r <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int N = 1e6 + 5;   int main() {     int n;     cin >> n;     for (int i = 0; i <= 2 * n; i++) {       for (int j = 0; j < 2 * abs(n - i); j++) cout <<    ;       int cnt = 0;       for (int j = 0; j <= 2 * n - 2 * abs(n - i); j++) {         if (j != 0) cout <<    ;         cout << cnt;         if (j >= n - abs(n - i))           cnt--;         else           cnt++;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct station {     int p, x, dir;     station() {}     station(int pp, int xx, int dirr) {       p = pp;       x = xx;       dir = dirr;     }   };   bool cmp(station a, station b) {     if (a.x != b.x) return a.x < b.x;     return a.dir == 1;   }   int d, n, m;   int main() {     ios_base::sync_with_stdio(0);     cin >> d >> n >> m;     vector<station> v;     for (int i = 0; i < m; i++) {       int x, p;       cin >> x >> p;       v.push_back(station(p, x, 1));       v.push_back(station(p, min(d, x + n), -1));     }     v.push_back(station(0, 0, 1));     v.push_back(station(0, n, -1));     sort(v.begin(), v.end(), cmp);     long long last = 0;     long long res = 0;     multiset<long long> s;     s.insert(0);     long long mx = 0;     for (int i = 1; i < v.size(); i++) {       long long cur = (long long)v[i].x;       long long mn = *s.begin();       res += (cur - last) * mn;       if (cur - last > n || s.size() == 0) return cout << -1, 0;       if (v[i].dir == 1) {         s.insert(v[i].p);       } else {         s.erase(s.find(v[i].p));       }       last = cur;     }     (last == d) ? cout << res : cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 20010, maxn = 10010, maxk = 1110;   const int inf = 1e7;   int to1[maxm], begin1[maxn], next1[maxm], w[maxm][maxk], cur[maxn], e = 1,                                                                       W[maxm];   int d[maxn], q[maxn], g[maxk], ans[maxk], vis[maxn], pre[maxn], lg[maxn],       t[maxk];   int tot, n;   struct node {     int x, f;   } Q[maxn];   void read(int &x) {     x = 0;     char c = getchar();     while (!( 0  <= c && c <=  9 )) c = getchar();     while ( 0  <= c && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }   }   void add(int x, int y, int z) {     to1[++e] = y;     next1[e] = begin1[x];     begin1[x] = e;     w[e][0] = z;   }   int min(int x, int y) { return x < y ? x : y; }   int bfs(int x, int y) {     int r = 0, l = 1, i;     for (i = 1; i <= y; i++) d[i] = 0;     q[0] = x;     d[x] = 1;     while (r < l) {       int xx = q[r];       r++;       for (i = begin1[xx]; i; i = next1[i])         if (!d[to1[i]] && w[i][0]) {           d[to1[i]] = d[xx] + 1;           q[l] = to1[i];           l++;         }     }     return d[y];   }   int dfs(int x, int y, int sum) {     int i;     if (x == y) return sum;     int flow = 0;     for (int &i = cur[x]; i; i = next1[i]) {       if (d[to1[i]] == d[x] + 1 && w[i][0]) {         int h = dfs(to1[i], y, min(sum, w[i][0]));         w[i][0] -= h;         w[i ^ 1][0] += h;         flow += h;         sum -= h;         if (!sum) break;       }     }     if (flow == 0) d[x] = -1;     return flow;   }   int Bfs(int x, int y) {     int r = 0, l = 1, flag = 0, i;     Q[r].x = x;     Q[r].f = 25;     vis[x] = tot;     while (r < l) {       node xx = Q[r];       r++;       for (i = begin1[xx.x]; i; i = next1[i]) {         if (W[i] && vis[to1[i]] != tot) {           vis[to1[i]] = tot;           pre[to1[i]] = i;           Q[l].x = to1[i];           Q[l].f = min(xx.f, W[i]);           if (to1[i] == n) {             flag = 1;             break;           }           l++;         }       }       if (flag) break;     }     int ans = 0;     if (flag) {       ans = Q[l].f;       int now = n;       while (now != 1) {         W[pre[now]] -= ans;         W[pre[now] ^ 1] += ans;         now = to1[pre[now] ^ 1];       }     }     return ans;   }   int main() {     int i, j, m, k, q, x, y, z;     read(n);     read(m);     read(k);     read(q);     for (i = 1; i <= m; i++) {       read(x);       read(y);       read(z);       add(x, y, z);       add(y, x, 0);     }     while (bfs(1, n)) {       for (i = 1; i <= n; i++) cur[i] = begin1[i];       int h = dfs(1, n, inf);       while (h) {         ans[0] += h;         h = dfs(1, n, inf);       }     }     lg[1] = 1;     for (i = 2; i < (1 << k); i <<= 1) lg[i] = lg[i >> 1] + 1;     for (i = 1; i < (1 << k); i++) {       int p = i - (i & (-i));       for (j = 2; j <= e; j++) w[j][i] = w[j][p];       ans[i] = ans[p];       w[lg[(i & (-i))] << 1][i] = 25;       ++tot;       for (j = 1; j <= e; j++) W[j] = w[j][i];       int h = Bfs(1, n);       while (h) {         ans[i] += h;         ++tot;         h = Bfs(1, n);       }       for (j = 1; j <= e; j++) w[j][i] = W[j];     }     while (q--) {       int sum = ans[0];       g[0] = 0;       for (i = 1; i <= k; i++) {         read(t[i]);         sum += t[i];         g[0] += t[i];       }       for (i = 1; i < (1 << k); i++) {         int p = i - (i & (-i)), &h = g[i];         h = g[p];         h -= t[lg[i & (-i)]];         sum = min(sum, h + ans[i]);       }       printf( %d n , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr <<     << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void inp_out() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp_out();     long long int n, w;     cin >> n >> w;     vector<long long int> a(n);     for (long long int i = 0; i < n; ++i) {       cin >> a[i];     }     long long int val = 0, mx = w, mn = 0;     for (long long int i = 0; i < n; ++i) {       if (abs(a[i]) > w) {         cout << 0;         return 0;       }       val += a[i];       if (val > w) {         cout << 0;         return 0;       }       long long int val1 = min(w, w - val);       long long int val2 = max(0ll, -val);       mx = min(val1, mx);       mn = max(val2, mn);     }     cout << max(0ll, mx - mn + 1);     return 0;   }


#include <bits/stdc++.h>   const int N = 29;   const int K = 10;   const int MOD = 1e9 + 7;   int n, m, k;   int g[N][N];   int s[N][N][K];   int state[N][N];   int f[N];   bool ch[N];   int fac[N];   int inv[N];   int ans;   inline void init() {     scanf( %d%d%d , &n, &m, &k);     if (n + m - 1 > k) {       puts( 0 );       exit(0);     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &g[i][j]);   }   inline int pow_mod(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       a = 1ll * a * a % MOD, b >>= 1;     }     return ret;   }   inline int P(int n, int m) { return 1ll * fac[n] * inv[n - m] % MOD; }   void dfs(int x, int y, int tot, int tot2) {     if (tot > k) return;     if (y == m + 1) x++, y = 1;     if (x == n + 1) {       ans = (ans + P(k - tot2, tot - tot2)) % MOD;       return;     }     state[x][y] = state[x - 1][y] | state[x][y - 1];     if (g[x][y]) {       if (f[g[x][y]]) {         if (((state[x][y] >> (f[g[x][y]] - 1)) & 1)) return;         state[x][y] ^= (1 << (f[g[x][y]] - 1));         dfs(x, y + 1, tot, tot2);         state[x][y] ^= (1 << (f[g[x][y]] - 1));       } else {         for (int i = 1; i <= tot + 1; ++i)           if (!((state[x][y] >> (i - 1)) & 1) && !ch[i]) {             state[x][y] ^= (1 << (i - 1));             f[g[x][y]] = i, ch[i] = true;             dfs(x, y + 1, std::max(i, tot), tot2 + 1);             f[g[x][y]] = 0, ch[i] = false;             state[x][y] ^= (1 << (i - 1));           }       }     } else {       for (int i = 1; i <= tot + 1; ++i)         if (!((state[x][y] >> (i - 1)) & 1)) {           state[x][y] ^= (1 << (i - 1));           dfs(x, y + 1, std::max(i, tot), tot2);           state[x][y] ^= (1 << (i - 1));         }     }   }   inline void solve() {     fac[0] = inv[0] = 1;     for (int i = 1; i <= k; ++i) {       fac[i] = 1ll * fac[i - 1] * i % MOD;       inv[i] = 1ll * inv[i - 1] * pow_mod(i, MOD - 2) % MOD;     }     memset(s, 0, sizeof s);     dfs(1, 1, 0, 0);     std::cout << ans << std::endl;   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000006], g[1000006];   char str[1000006];   int sum1 = 0, sum2 = 0;   int main() {     int n, i;     scanf(  %d , &n);     for (i = 0; i < n; i++) {       scanf(  %d %d , &a[i], &g[i]);     }     for (i = 0; i < n; i++) {       int c = sum2 - (sum1 + a[i]);       int d = sum1 - (sum2 + g[i]);       if (c < 0) c = -c;       if (d < 0) d = -d;       if (c < d) {         str[i] =  A ;         sum1 = sum1 + a[i];       } else {         str[i] =  G ;         sum2 = sum2 + g[i];       }     }     str[i] =   n ;     printf( %s n , str);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   map<int, int> f, val;   int lastans;   int read() {     int x = 0, f = 1;     char s;     while ((s = getchar()) >  9  || s <  0 )       if (s ==  - ) f = -1;     while (s >=  0  && s <=  9 )       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     return x * f;   }   int Find(int x) {     if (!f.count(x)) return x;     int t = Find(f[x]);     val[x] ^= val[f[x]];     return f[x] = t;   }   int main() {     int op, u, v, w, x, y;     for (int t = read(); t; --t) {       op = read(), u = read() ^ lastans, v = read() ^ lastans;       if (u > v) swap(u, v);       --u;       x = Find(u), y = Find(v);       if (op == 1) {         w = read() ^ lastans;         if (x ^ y) {           f[x] = y;           val[x] = val[u] ^ val[v] ^ w;         }       } else {         if (x ^ y)           puts( -1 ), lastans = 1;         else           printf( %d n , val[u] ^ val[v]), lastans = val[u] ^ val[v];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, m, k, t, cs, n, mx, v;     scanf( %d , &n), scanf( %d , &m);     int cnt = 0, ppl = 0;     for (i = 1; i <= n; i++) {       scanf( %d , &v);       if (ppl + v <= m)         ppl += v;       else {         cnt++;         ppl = v;       }     }     if (ppl) cnt++;     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &p) {     os <<  [ ;     for (auto &it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   inline T Bit(T x, long long i) {     return (x >> i) & 1;   }   template <class T>   bool umin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool umax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   void solve(long long tc) {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     long long sum = accumulate(a.begin(), a.end(), 0LL);     multiset<long long> ms;     for (long long i = 0; i < n; i++) ms.insert(a[i]);     long long q;     cin >> q;     while (q--) {       long long x, y;       cin >> x >> y;       auto it = ms.lower_bound(x);       long long ans = 2e18;       if (it != ms.end()) {         long long z = *it;         if (sum - z >= y) {           ans = 0;         } else {           umin(ans, y - (sum - z));         }       }       it = ms.upper_bound(x);       if (it != ms.begin()) {         it--;         long long cur = x - *it;         if (sum - *it <= y) cur += (y - sum + *it);         umin(ans, cur);       }       cout << ans <<   n ;     }   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 1; i <= t; i++) solve(i);     return 0;   }


//#pragma GCC optimize( Ofast )   //#pragma GCC target( avx,avx2,fma )      #include <bits/stdc++.h>   using namespace std;   void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}   template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   void debug3(int *t,int st,int n) {cerr <<  {  << t[st];for(int i=st+1;i<=n;i++) cerr<< , ,__print(t[i]);cerr << } <<  n ;}   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #define debug2(x...) cerr<< [  << #x <<  ] =  ; debug3(x)   #endif      #define N 200005   #define ll long long   #define ull unsigned long long   #define pii pair<int,int>   #define sf second.first   #define ss second.second   #define INF 1e9      int v[N];      int main()   {       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       //freopen( test.in ,  r , stdin);       int t,n,m,i,j,x;       double pr,pb,sol;          cin >> t ;       while ( t-- )       {           pr = 1 ;           sol = 0 ;           cin >> n >> m ;           for ( i = 1; i <= n ; i++ )               cin >> v[i] ;           for ( j=n ; v[j]==j&&j; j-- ) ;           while ( m-- )           {               cin >> x >> pb ;               if ( x < j )                   continue ;               sol = sol + pr*pb ;               pr = pr*(1-pb) ;           }           if ( j == 0 )               sol = 1 ;           cout << sol <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a = vector<int>(10, 0);   vector<int> b;   int main() {     srand(time(NULL));     for (int i = 0; i < 6; i++) {       int x;       cin >> x;       a[x]++;     }     bool f = false;     for (int i = 0; i < 10; i++) {       if (a[i] != 0) {         b.push_back(a[i]);       }       if (a[i] >= 4) {         f = true;       }     }     if (b.size() > 3 || f == false) {       cout <<  Alien  << endl;       return 0;     }     sort(b.begin(), b.end());     if (b.size() == 3 || (b[0] == 1 && b[1] == 5)) {       cout <<  Bear  << endl;       return 0;     }     if (b.size() <= 2) {       cout <<  Elephant  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   struct DSU {    private:     int32_t* parents;     int32_t* sizes;     std::vector<std::pair<int32_t, int32_t> > actions;     int32_t get_root(int32_t v) {       if (parents[v] == v) return v;       return get_root(parents[v]);     }       public:     DSU(int32_t n) {       parents = new int32_t[n];       sizes = new int32_t[n];       for (int32_t i = 0; i < n; i++) {         parents[i] = i;         sizes[i] = 1;       }     }     bool same(int32_t v1, int32_t v2) { return get_root(v1) == get_root(v2); }     void join(int32_t v1, int32_t v2) {       int32_t root1 = get_root(v1), root2 = get_root(v2);       if (root1 == root2) {         actions.emplace_back(-1, -1);         return;       }       if (sizes[root1] > sizes[root2]) {         int32_t tmp = root1;         root1 = root2;         root2 = tmp;       }       parents[root1] = root2;       sizes[root2] += sizes[root1];       actions.emplace_back(root1, root2);     }     void pop() {       if (actions.back().first != -1) {         sizes[parents[actions.back().first]] -= sizes[actions.back().first];         parents[actions.back().first] = actions.back().first;       }       actions.pop_back();     }   };   struct Tracker {    private:     DSU all_dsu;     DSU comp_dsu;     int32_t num_edges = 0;     int32_t broken_since = -1;     std::set<int32_t>* graph;     std::vector<int32_t> actions_time;       public:     Tracker(int32_t n) : all_dsu(n), comp_dsu(n) {       graph = new std::set<int32_t>[n];     }     void add_edge(int32_t v1, int32_t v2) {       if (all_dsu.same(v1, v2)) {         if (comp_dsu.same(v1, v2)) {           if (broken_since == -1) broken_since = num_edges;         } else {         }       } else {         if (graph[v2].size() > 0) {           comp_dsu.join(v1, *graph[v2].begin());           actions_time.push_back(num_edges);         }         if (graph[v1].size() > 0) {           comp_dsu.join(v2, *graph[v1].begin());           actions_time.push_back(num_edges);         }       }       all_dsu.join(v1, v2);       graph[v1].insert(v2);       graph[v2].insert(v1);       num_edges++;     }     void pop_edge(int32_t v1, int32_t v2) {       num_edges--;       if (num_edges == broken_since) broken_since = -1;       all_dsu.pop();       graph[v1].erase(v2);       graph[v2].erase(v1);       while (actions_time.size() > 0 && actions_time.back() >= num_edges) {         comp_dsu.pop();         actions_time.pop_back();       }     }     bool get_ans() { return broken_since == -1; }   };   std::vector<std::pair<int32_t, int32_t> >* segtree;   void add_edge(int32_t node, int32_t left, int32_t right, int32_t query_left,                 int32_t query_right, std::pair<int32_t, int32_t> edge) {     if (left >= query_right || right <= query_left) return;     if (left >= query_left && right <= query_right) {       segtree[node].push_back(edge);       return;     }     int32_t m = (left + right) / 2;     add_edge(node * 2 + 1, left, m, query_left, query_right, edge);     add_edge(node * 2 + 2, m, right, query_left, query_right, edge);   }   void get_ans(int32_t node, int32_t left, int32_t right, Tracker& tracker) {     for (int32_t i = 0; i < segtree[node].size(); i++)       tracker.add_edge(segtree[node][i].first, segtree[node][i].second);     if (right - left == 1) {       std::cout << (tracker.get_ans() ?  YES  :  NO ) <<   n ;       for (int32_t i = 0; i < segtree[node].size(); i++)         tracker.pop_edge(segtree[node][i].first, segtree[node][i].second);       return;     }     int32_t m = (left + right) / 2;     get_ans(node * 2 + 1, left, m, tracker);     get_ans(node * 2 + 2, m, right, tracker);     for (int32_t i = 0; i < segtree[node].size(); i++)       tracker.pop_edge(segtree[node][i].first, segtree[node][i].second);   }   int main() {     int32_t n, num_queries;     std::cin >> n >> num_queries;     segtree = new std::vector<std::pair<int32_t, int32_t> >[4 * num_queries];     std::map<std::pair<int32_t, int32_t>, int32_t> segments;     for (int32_t q = 0; q < num_queries; q++) {       int32_t v1, v2;       std::cin >> v1 >> v2;       v1--;       v2--;       if (v1 > v2) {         int32_t tmp = v1;         v1 = v2;         v2 = tmp;       }       auto it = segments.find({v1, v2});       if (it == segments.end())         segments[{v1, v2}] = q;       else {         add_edge(0, 0, num_queries, it->second, q, {v1, v2});         segments.erase(it);       }     }     for (auto it = segments.begin(); it != segments.end(); it++)       add_edge(0, 0, num_queries, it->second, num_queries, it->first);     Tracker tracker(n);     get_ans(0, 0, num_queries, tracker);     return 0;   }


#include <bits/stdc++.h>   std::mt19937 rnd(time(0));   const int N = 200005;   int n, m, a[N], c[N];   int v;   int ans;   int p[N << 1];   void updAns(int x) {     if (v == x) {       return;     }     for (int i = 0; i <= 2 * n; ++i) {       p[i] = -1;     }     int now = n;     p[now] = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] == v) {         ++now;       } else if (a[i] == x) {         --now;       }       if (p[now] == -1) {         p[now] = i;       } else {         ans = std::max(ans, i - p[now]);       }     }   }   int wnext(int i, int t) {     if (t == 0) {       return rnd() % i;     } else if (t < 0) {       return std::min<int>(rnd() % i, wnext(i, t + 1));     } else {       return std::max<int>(rnd() % i, wnext(i, t - 1));     }   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cin >> n;     for (int i = 1; i <= n; ++i) {       std::cin >> a[i];       ++c[a[i]];       m = std::max(m, a[i]);     }     std::vector<std::pair<int, int>> val;     v = 0;     for (int i = 1; i <= m; ++i) {       if (!v || c[i] > c[v]) {         v = i;       }       if (c[i]) {         val.push_back({c[i], i});       }     }     std::sort(val.begin(), val.end());     std::reverse(val.begin(), val.end());     const int B = 200;     for (int i = 0; i < B && i < (int)val.size(); ++i) {       updAns(val[i].second);     }     if ((int)val.size() > B) {       for (int i = 0; i < B; ++i) {         int x = wnext(val.size() - B, 0) + B;         updAns(val[x].second);       }     }     std::cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e8 + 10;   bool ok = 0;   int n, maxy, miny, maxx, minx;   struct point {     int x, y;   };   bool cmp(point a, point b) { return a.x < b.x; }   point jilu[100050];   int bfy[100050], afy[100050], bfmaxy[100050], bfminy[100050], afminy[100050],       afmaxy[100050];   int b1_search(long long tmp) {     int l = 0, r = n - 1, m;     while (r >= l) {       m = (l + r) >> 1;       if (jilu[m].x <= tmp)         l = m + 1;       else         r = m - 1;     }     return r;   }   int b2_search(long long tmp) {     int l = 0, r = n - 1, m;     while (r >= l) {       m = (r + l) >> 1;       if (jilu[m].x >= tmp)         r = m - 1;       else         l = m + 1;     }     return l;   }   long long binary_sqrt(long long tmp) {     long long ans = sqrt(tmp);     while (ans * ans > tmp) {       ans--;     }     while ((ans + 1) * (ans + 1) <= tmp) {       ans++;     }     return ans;   }   bool check(long long tmp) {     long long a = maxy - miny;     long long b = maxx - minx;     if (tmp >= a * a || tmp >= b * b) {       return 1;     }     int pos;     long long ttmp = binary_sqrt(tmp);     for (int i = 0; i < n; i++) {       if (jilu[i].x < 0) {         pos = b1_search(min(jilu[i].x + ttmp, (long long)-jilu[i].x));         long long my = max(bfy[i], afy[pos]);         long long mx =             max(max(jilu[i].x, -jilu[i].x), max(jilu[pos].x, -jilu[pos].x));         long long yy = max(afmaxy[pos], bfmaxy[i]) - min(afminy[pos], bfminy[i]);         if (my * my + mx * mx <= tmp && yy * yy <= tmp) {           return 1;         }       } else {         pos = b2_search(max(jilu[i].x - ttmp, (long long)-jilu[i].x));         long long my = max(afy[i], bfy[pos]);         long long mx =             max(max(jilu[i].x, -jilu[i].x), max(jilu[pos].x, -jilu[pos].x));         long long yy = max(afmaxy[i], bfmaxy[pos]) - min(afminy[i], bfminy[pos]);         if (my * my + mx * mx <= tmp && yy * yy <= tmp) {           return 1;         }       }     }     return 0;   }   void Binary_search(long long l, long long r) {     long long m;     while (r > l) {       m = l + (r - l) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     cout << r << endl;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &jilu[i].x, &jilu[i].y);     }     sort(jilu, jilu + n, cmp);     bfmaxy[0] = -inf;     bfminy[0] = inf;     for (int i = 1; i < n; i++) {       bfmaxy[i] = max(bfmaxy[i - 1], jilu[i - 1].y);       bfminy[i] = min(bfminy[i - 1], jilu[i - 1].y);     }     afmaxy[n - 1] = -inf;     afminy[n - 1] = inf;     for (int i = n - 2; i >= 0; i--) {       afmaxy[i] = max(afmaxy[i + 1], jilu[i + 1].y);       afminy[i] = min(afminy[i + 1], jilu[i + 1].y);     }     for (int i = 1; i < n; i++) {       bfy[i] =           max(max(bfy[i - 1], -bfy[i - 1]), max(jilu[i - 1].y, -jilu[i - 1].y));     }     for (int i = n - 2; i >= 0; i--) {       afy[i] =           max(max(afy[i + 1], -afy[i + 1]), max(jilu[i + 1].y, -jilu[i + 1].y));     }     maxy = miny = jilu[0].y;     maxx = minx = jilu[0].x;     for (int i = 0; i < n; i++) {       maxy = max(jilu[i].y, maxy);       miny = min(jilu[i].y, miny);       maxx = max(jilu[i].x, maxx);       minx = min(jilu[i].x, minx);     }     Binary_search(0, 40000000000000000);   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[300005];   int n, x, y;   void resi(int x, int y, bool naopako) {     int z = 0, j = -1, k = -1, c = 0;     for (int i = 1; i <= n; i++) {       z = a[i].first;       c++;       if (j == -1 && z * c >= x) {         j = i;         z = c = 0;       }       if (j != -1 && k == -1 && z * c >= y) {         k = i;         break;       }     }     if (k != -1) {       cout <<  Yes n ;       if (!naopako) {         cout << j <<     << k - j <<   n ;         for (int i = 1; i <= j; i++) {           cout << a[i].second <<    ;         }         cout <<   n ;         for (int i = j + 1; i <= k; i++) {           cout << a[i].second <<    ;         }         cout <<   n ;       } else {         cerr <<  naopako! n ;         cout << k - j <<     << j <<   n ;         for (int i = j + 1; i <= k; i++) {           cout << a[i].second <<    ;         }         cout <<   n ;         for (int i = 1; i <= j; i++) {           cout << a[i].second <<    ;         }         cout <<   n ;       }       exit(0);     }   }   void solve() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> x >> y;     for (int i = 1; i <= n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     resi(x, y, false);     resi(y, x, true);     cout <<  No n ;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int N, M;   const double EPS = 1E-9;   double solve(int r, int c) {     vector<double> res(M, 0);     for (int y = N - 2; y >= r; y--) {       if (M == 1) {         res[0] = 2 + res[0];       } else {         vector<double> a(M), b(M);         a[0] = 1 / 2.0;         b[0] = (3 + res[0]) / 2;         for (int j = 1; j < M; j++) {           a[j] = 1.0 / (3 - a[j - 1]);           b[j] = (4 + res[j] + b[j - 1]) / (3 - a[j - 1]);         }         res[M - 1] = (b[M - 2] + 3 + res[M - 1]) / (2 - a[M - 2]);         for (int j = M - 2; j >= 0; j--) {           res[j] = a[j] * res[j + 1] + b[j];         }       }     }     return res[c];   }   int main(int argc, char* argv[]) {     scanf( %d %d , &N, &M);     int r, c;     scanf( %d %d , &r, &c);     double res = solve(r - 1, c - 1);     printf( %9lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n, a[maxn], deep[maxn], head[maxn], to[maxn * 2], nextt[maxn * 2],       tot = 1, ans[maxn], anss;   void add(int x, int y) {     to[tot] = y;     nextt[tot] = head[x];     head[x] = tot++;   }   void dfs(int u, int fa) {     deep[u] = deep[fa] + 1;     ans[deep[u]]--;     for (int i = head[u]; i; i = nextt[i]) {       int v = to[i];       if (v == fa) continue;       dfs(v, u);     }   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       scanf( %d , &a[i]);       add(a[i], i);     }     dfs(1, 0);     for (int i = 1; i <= n; i++)       if (ans[i] & 1) anss++;     printf( %d n , anss);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, m, p, t = 0;     cin >> n >> m >> k;     vector<long long int> v;     for (long long int i = 0; i < m; i++) {       cin >> p;       v.push_back(p);     }     sort(v.begin(), v.end());     long long int c = 0, s = 0;     while (s != m) {       long long int y;       if ((v[s] - t) % k == 0)         y = (v[s] - t) / k;       else         y = (v[s] - t) / k + 1;       long long int q = t;       for (long long int i = s; i < m; i++) {         long long int x;         if ((v[i] - q) % k == 0)           x = (v[i] - q) / k;         else           x = (v[i] - q) / k + 1;         if (y == x) {           s++;           t++;         } else {           break;         }       }       c++;     }     cout << c << endl;   }


#include <bits/stdc++.h>   clock_t t = clock();   namespace my_std {   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T rnd(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   template <typename T>   inline bool chkmax(T& x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T& x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline void read(T& t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   char __sr[1 << 21], __z[20];   int __C = -1, __zz = 0;   inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }   inline void print(register int x) {     if (__C > 1 << 20) Ot();     if (x < 0) __sr[++__C] =  - , x = -x;     while (__z[++__zz] = x % 10 + 48, x /= 10)       ;     while (__sr[++__C] = __z[__zz], --__zz)       ;     __sr[++__C] =   n ;   }   void file() {}   inline void chktime() {}   long long ksm(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x)       if (y & 1) ret = ret * x;     return ret;   }   }  // namespace my_std   using namespace my_std;   int n;   vector<int> V[101010];   int D[101010];   void dfs1(int x) {     for (auto v : V[x]) dfs1(v), chkmax(D[x], D[v]);     ++D[x];     for (int i = (0); i <= ((int)V[x].size() - 1); i++)       if (D[V[x][i]] == D[x] - 1) {         V[x].push_back(V[x][i]);         V[x].erase(V[x].begin() + i);         break;       }   }   stack<int> ans;   int Ans;   void dfs2(int x) {     if (!V[x].size()) {       for (int i = 0; printf( %d  , i), V[i].size(); i = V[i][0])         ;       printf(  n%d n , (int)ans.size());       while (ans.size()) printf( %d  , ans.top()), ans.pop();       return;     }     int s = V[x].back();     V[x].pop_back();     while (V[x].size())       V[V[x].back()].push_back(s), ans.push(s), s = V[x].back(), V[x].pop_back();     V[x].push_back(s);     dfs2(s);   }   int main() {     file();     read(n);     int x;     for (int i = (1); i <= (n - 1); i++) read(x), V[x].push_back(i);     dfs1(0);     Ans = n - D[0];     dfs2(0);     return 0;   }


#include <bits/stdc++.h>   int s[401000], lazy[401000];   int b[401000], N;   int n, s1, s2;   int v[401000];   int Abs(int x) { return x > 0 ? x : -x; }   void add(int x) {     s[x] = 0;     lazy[x] = 1;   }   void pd(int x) {     if (lazy[x]) add(x << 1), add(x << 1 | 1), lazy[x] = 0;   }   void pu(int x) { s[x] = s[x << 1] | s[x << 1 | 1]; }   void modify(int x, int l, int r, int L, int R, int v) {     if (l == L && r == R) {       if (v == 1)         s[x] = 1;       else         add(x);       return;     }     pd(x);     int mid = l + r >> 1;     if (R <= mid)       modify(x << 1, l, mid, L, R, v);     else if (L > mid)       modify(x << 1 | 1, mid + 1, r, L, R, v);     else       modify(x << 1, l, mid, L, mid, v),           modify(x << 1 | 1, mid + 1, r, mid + 1, R, v);     pu(x);   }   int L(int x) { return std::lower_bound(b + 1, b + N + 1, x) - b; }   int U(int x) { return std::upper_bound(b + 1, b + N + 1, x) - b; }   bool solve(int x) {     memset(s, 0, sizeof(s));     memset(lazy, 0, sizeof(lazy));     modify(1, 1, N, L(s1), L(s1), 1);     for (int i = 1; i <= n; i++) {       if (Abs(v[i] - v[i - 1]) <= x && s[1])         modify(1, 1, N, L(v[i - 1]), L(v[i - 1]), 1);       if (L(v[i] - x) - 1 >= 1) modify(1, 1, N, 1, L(v[i] - x) - 1, 0);       if (U(v[i] + x) <= N) modify(1, 1, N, U(v[i] + x), N, 0);     }     return s[1];   }   int main() {     scanf( %d%d%d , &n, &s1, &s2);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]), b[++N] = v[i];     v[0] = s2;     b[++N] = s1;     b[++N] = s2;     std::sort(b + 1, b + N + 1);     N = std::unique(b + 1, b + N + 1) - b - 1;     int l = Abs(s2 - s1), r = (int)1e9 + 1;     while (l < r) {       int mid = l + r >> 1;       if (solve(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , r);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     t = 1;     while (t--) {       long long n, m;       cin >> n;       cin >> m;       string s[n];       for (long long i = 0; i < n; i++) {         string cur =   ;         for (long long i = 0; i < m; i++) {           long long k;           cin >> k;           cur += to_string(k);         }         s[i] = cur;       }       if (n & 1)         cout << n << endl;       else {         long long ans = n;         while (n % 2 == 0) {           n = n / 2;           bool flag = 1;           for (long long i = 0; i < n; i++) {             if (s[i] != s[2 * n - i - 1]) {               flag = 0;               break;             }           }           if (!flag)             break;           else             ans = n;         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     queue<long long> qR, qD;     string second;     cin >> second;     for (int i = 0; i < second.length(); i++) {       if (second[i] ==  R )         qR.push(i);       else         qD.push(i);     }     while (1) {       if (qD.empty()) {         cout <<  R  << endl;         break;       }       if (qR.empty()) {         cout <<  D  << endl;         break;       }       if (qD.front() > qR.front()) {         qD.pop();         int x = qR.front();         qR.pop();         qR.push(x + n);       } else {         qR.pop();         int x = qD.front();         qD.pop();         qD.push(x + n);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1e5 + 5;   const long long inf = 1e18;   int n, k, nr, st[Nmax], A[Nmax], nextBigger[Nmax];   long long dp[Nmax], old[Nmax];   struct Ec {     int a;     long long b;     long long operator()(int x) { return (long long)a * x + b; }   };   Ec interv[Nmax];   class Batch {     vector<Ec> v;     double intersect(Ec A, Ec B) { return (double)(A.b - B.b) / (B.a - A.a); }     bool bad(Ec a, Ec b, Ec c) { return intersect(a, c) >= intersect(a, b); }       public:     void clear() { v.clear(); }     void add(Ec ec) {       while (v.size() >= 2 && bad(v[v.size() - 2], v.back(), ec)) v.pop_back();       v.push_back(ec);     }     long long query(int x) {       if (v.empty()) return inf;       while (v.size() >= 2 && intersect(v[v.size() - 2], v.back()) <= x)         v.pop_back();       return v.back()(x);     }   };   class SegmentTree {     Batch a[Nmax << 2];       public:     void update1(int node, int st, int dr, int pos, Ec ec) {       a[node].add(ec);       if (st == dr) return;       if (pos <= ((st + dr) >> 1))         update1((node << 1), st, ((st + dr) >> 1), pos, ec);       else         update1(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, pos, ec);     }     void update2(int node, int st, int dr, int L, int R, Ec ec) {       if (L <= st && dr <= R) {         a[node].add(ec);         return;       }       if (L <= ((st + dr) >> 1))         update2((node << 1), st, ((st + dr) >> 1), L, R, ec);       if (((st + dr) >> 1) < R)         update2(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, L, R, ec);     }     long long query1(int node, int st, int dr, int L, int R, int p) {       if (L <= st && dr <= R) return a[node].query(p);       long long x = inf, y = inf;       if (L <= ((st + dr) >> 1))         x = query1((node << 1), st, ((st + dr) >> 1), L, R, p);       if (((st + dr) >> 1) < R)         y = query1(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, L, R, p);       return min(x, y);     }     long long query2(int node, int st, int dr, int pos, int p) {       long long x = a[node].query(p);       if (st == dr) return x;       if (pos <= ((st + dr) >> 1))         x = min(x, query2((node << 1), st, ((st + dr) >> 1), pos, p));       else         x = min(x, query2(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, pos, p));       return x;     }     void clear() {       int i;       for (i = 1; i <= ((n + 1) << 2); ++i) a[i].clear();     }   } aint;   void solve() {     int i;     aint.clear();     for (i = n; i >= 0; --i) aint.update1(1, 0, n, i, {-i, old[i]});     nr = 0;     st[0] = 0;     for (i = 1; i <= n; ++i) {       while (nr && A[i] >= A[st[nr]]) --nr;       st[++nr] = i;       interv[i] = {A[i], aint.query1(1, 0, n, st[nr - 1], st[nr] - 1, A[i])};     }     aint.clear();     for (i = n; i >= 1; --i)       aint.update2(1, 0, n, i, nextBigger[i] - 1, interv[i]);     for (i = 1; i <= n; ++i) dp[i] = aint.query2(1, 0, n, i, i);   }   int main() {     int i, j;     cin >> n >> k;     for (i = 1; i <= n; ++i) cin >> A[i];     nr = 0;     st[0] = n + 1;     for (i = n; i; --i) {       while (nr && A[i] > A[st[nr]]) --nr;       nextBigger[i] = st[nr];       st[++nr] = i;     }     old[0] = 0;     for (i = 1; i <= n; ++i) old[i] = inf;     for (i = 1; i <= k; ++i) {       for (j = 1; j <= n; ++j) dp[j] = inf;       dp[0] = 0;       solve();       for (j = 1; j <= n; ++j) old[j] = dp[j];     }     cout << dp[n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -ffloat-store )   #pragma GCC optimize( -fno-defer-pop )   long long int power(long long int a, long long int b, long long int m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long int t = power(a, b / 2, m) % m;     t = (t * t) % m;     if (b & 1) t = ((t % m) * (a % m)) % m;     return t;   }   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, l, n;     cin >> n;     long long int ar[n + 1];     for (i = 1; i <= n; i++) {       cin >> ar[i];     }     long long int L[n + 2], R[n + 2];     memset(L, 0, sizeof(L));     memset(R, 0, sizeof(R));     L[1] = 1;     for (i = 2; i <= n; i++) {       L[i] = min(ar[i], L[i - 1] + 1);     }     R[n] = 1;     for (i = n - 1; i > 0; i--) {       R[i] = min(ar[i], 1 + R[i + 1]);     }     long long int an = -1e18;     for (i = 1; i <= n; i++) {       an = max(an, min(L[i], R[i]));     }     cout << an;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   char ini[101], des[101];   int main() {     int i, L = strlen(ini), j;     gets(ini);     gets(des);     for (i = 0; ini[i]; i++) {       for (j = i + 1; ini[j]; j++) {         if (ini[i] > ini[j]) {           swap(ini[i], ini[j]);         }       }     }     for (i = 0; ini[i]; i++) {       if (ini[i] !=  0 ) break;     }     if (ini[i]) {       swap(ini[i], ini[0]);     }     if (!strcmp(ini, des)) {       puts( OK );     } else {       puts( WRONG_ANSWER );     }   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   long double DP[1010][1010];   int i, j;   int total, X;   int main() {     cin >> N >> M;     DP[0][0] = 1.0;     for (int i = 1; i <= N; i++)       for (int j = 0; j <= M && j <= N; j++) {         total = N * M - (i - 1);         X = M - j;         DP[i][j] += DP[i - 1][j] * (1.0 * total - X) / (1.0 * total);         if (j > 0) {           total = N * M - (i - 1);           X = M - j + 1;           DP[i][j] += DP[i - 1][j - 1] * (1.0 * X) / (1.0 * total);         }       }     long double ans = 0;     for (int i = 1; i <= N; i++)       ans += (1.0 * i) * (1.0 * i) / (1.0 * N) * DP[N][i];     cout << fixed << setprecision(20) << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, c, p, y, k, x, h, t, q;   string s;   vector<long long> v;   map<long long, long long> ma;   void input() {}   struct node {     map<string, node*> child;     map<string, long long> ispresent;     string name;     bool isfile = 0;   };   pair<long long, long long> dfs(node* root) {     pair<long long, long long> p = {0, 0};     if (root->isfile == 1) {       p = {0, 1};       return p;     }     pair<long long, long long> res = {0, 0};     for (auto i : root->child) {       p = dfs(i.second);       res.first += p.first;       res.second += p.second;     }     res.first++;     return res;   }   void solve() {     string s;     map<char, node*> roots;     roots[ C ] = new node();     roots[ D ] = new node();     roots[ E ] = new node();     roots[ F ] = new node();     roots[ G ] = new node();     while (cin >> s) {       long long n = s.size();       char disk = s[0];       node* temp = roots[disk];       for (long long i = 3; i < n; i++) {         long long j;         string names =   ;         bool file = 0;         for (j = i; s[j] !=      && j < n; j++) {           names += s[j];           if (s[j] ==  . ) file = 1;         }         i = j;         if (temp->ispresent[names] != 0) {           temp = temp->child[names];         } else {           node* newnode = new node();           if (file == 1) {             newnode->isfile = true;           }           newnode->name = names;           temp->child[names] = newnode;           temp->ispresent[names]++;           temp = temp->child[names];         }       }     }     long long maxfiles = 0;     long long maxfolder = 0;     for (auto i : roots[ C ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ D ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ E ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ F ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ G ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     cout << maxfolder - 1 <<     << maxfiles;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T = 1;     while (T--) {       input();       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long a[100005], b[100005], l[100005], l2[100005];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];     for (long long i = 2; i <= n; i++) {       l[i] = a[i - 1] - a[i];       l2[i] = b[i - 1] - b[i];     }     sort(l + 2, l + n + 1);     sort(l2 + 2, l2 + n + 1);     for (long long i = 2; i <= n; i++) {       if (l[i] != l2[i]) {         cout <<  No ;         return 0;       }     }     if (a[1] != b[1] || a[n] != b[n]) {       cout <<  No ;     } else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     ;     string s;     long long m, x = 0, k = 0;     long long a[3];     for (long long i = 0; i < 3; i++) {       cin >> a[i];     }     sort(a, a + 3);     k = a[2] - a[1] + a[1] - a[0];     cout << k;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <typename T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     int n;     gn(n);     if (n == 3) {       puts( >vv );       puts( ^<. );       puts( ^.< );       puts( 1 3 );       return 0;     }     if (n == 5) {       puts( >...v );       puts( v.<.. );       puts( ..^.. );       puts( >.... );       puts( ..^.< );       puts( 1 1 );       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == 1) {           if (j == n)             putchar( v );           else if (j <= n / 3)             putchar( > );           else if (j - n / 3 & 1)             putchar( > );           else             putchar( . );           continue;         }         if (i == n) {           if (j == 1)             putchar( ^ );           else if (j > n - n / 3)             putchar( < );           else if (n - n / 3 - j & 1)             putchar( < );           else             putchar( . );           continue;         }         if (j == 1) {           putchar( ^ );           continue;         }         if (i & 1) {           if (j == n)             putchar( v );           else if (j <= n / 3)             putchar( > );           else if (j - n / 3 & 1)             putchar( > );           else             putchar( . );         } else {           if (j == 2)             putchar( v );           else if (j > n - n / 3)             putchar( < );           else if (j & 1)             putchar( < );           else             putchar( . );         }       }       puts(  );     }     puts( 1 1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 2e18 + 5;   vector<long long> adj[1000001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long r, c;     cin >> r >> c;     vector<string> a(r);     for (long long i = (0); i < (r); i++) cin >> a[i];     long long cnt = 0;     unordered_map<long long, long long> mikemon;     long long dest, sourc, x;     for (long long i = (0); i < (r); i++) {       for (long long j = (0); j < (c); j++) {         ++cnt;         if (a[i][j] ==  T ) continue;         if (i != 0) {           if (a[i - 1][j] !=  T ) {             adj[cnt].push_back(cnt - c);             adj[cnt - c].push_back(cnt);           }         }         if (i != r - 1) {           if (a[i + 1][j] !=  T ) {             adj[cnt].push_back(cnt + c);             adj[cnt + c].push_back(cnt);           }         }         if (j != 0) {           if (a[i][j - 1] !=  T ) {             adj[cnt].push_back(cnt - 1);             adj[cnt - 1].push_back(cnt);           }         }         if (j != c - 1) {           if (a[i][j + 1] !=  T ) {             adj[cnt].push_back(cnt + 1);             adj[cnt + 1].push_back(cnt);           }         }         if (a[i][j] ==  E )           dest = cnt;         else if (a[i][j] ==  S )           sourc = cnt;         else {           mikemon.insert({cnt, a[i][j] -  0 });         }       }     }     queue<long long> q;     vector<long long> vis(cnt + 1, 0), d(cnt + 1, inf);     vis[dest] = 1;     d[dest] = 1;     q.push(dest);     while (!q.empty()) {       x = q.front();       q.pop();       for (auto v : adj[x]) {         if (vis[v] == 0) {           vis[v] = 1;           q.push(v);           d[v] = d[x] + 1;         }       }     }     long long ans = 0;     long long y = d[sourc];     for (long long i = (1); i < (cnt + 1); i++) {       if (d[i] <= y) ans += mikemon[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[200100], cnt[200020];   int n, s;   int main(void) {     ios::sync_with_stdio(false);     cin >> n >> s;     --s;     int er = 0;     int ans = 0;     for (int(i) = (0); (i) < (n); ++(i)) {       cin >> v[i];       cnt[v[i]]++;     }     if (v[s] != 0) {       ans++;       cnt[v[s]]--;       cnt[0]++;     }     int e = n - 1;     while (cnt[e] == 0) e--;     er = cnt[0] - 1;     ans += er;     for (int i = 1; i < e; i++) {       if (!cnt[i]) {         if (er)           er--;         else {           cnt[e]--;           cnt[i]++;           ans++;           while (cnt[e] == 0) e--;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 7;   const int MOD = 1e9 + 7;   const int D = 4e3 + 7;   int n, m, A[MAXN], cnt, L, R;   vector<int> G[MAXN];   void add(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   bool vis[MAXN];   int dfs(int u) {     vis[u] = true;     for (int v : G[u])       if (!vis[v]) return dfs(v) + 1;     return 1;   }   int f[MAXN][D << 1], g[MAXN][D << 1];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     vis[1] = true;     for (int u : G[1])       if (!vis[u]) A[++cnt] = dfs(u) + 1;     L = D - m, R = D + m;     f[0][D] = g[cnt + 1][D] = 1;     for (int i = 1; i <= cnt; i++)       for (int j = L; j <= R; j++) {         f[i][j] = f[i - 1][j];         if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]);         if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]);       }     for (int i = cnt; ~i; i--)       for (int j = L; j <= R; j++) {         g[i][j] = g[i + 1][j];         if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]);         if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]);       }     int ret = 0;     for (int i = 1; i <= cnt; i++) {       for (int j = -(A[i] - 2); j <= A[i] - 2; j++) {         for (int k = L; k <= R; k++) {           int d = j - (k - D) + D;           if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);         }       }     }     memset(f, 0, sizeof(f));     memset(g, 0, sizeof(g));     f[0][D] = g[cnt + 1][D] = 1;     for (int i = 1; i <= cnt; i++)       for (int j = L; j <= R; j++) {         if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]);         if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]);       }     for (int i = cnt; ~i; i--)       for (int j = L; j <= R; j++) {         if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]);         if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]);       }     for (int i = 1; i <= cnt; i++) {       int j = A[i] - 1;       for (int k = L; k <= R; k++) {         int d = j - (k - D) + D;         if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);       }       j = -j;       for (int k = L; k <= R; k++) {         int d = j - (k - D) + D;         if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);       }     }     add(ret, ret);     add(ret, f[cnt][D]);     cout << ret << endl;     return 0;   }


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


#include <bits/stdc++.h>   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return ((a * b) / gcd(a, b)); }   using namespace std;   long long ara[1000006];   int main() {     int b, c, i, j, k, tc, t;     int m, cnt = 0;     long long one = 1, two = 2, a, n;     cin >> n >> m;     for (i = 0; i < m; i++) {       scanf( %lld , &a);       if (a & 1) {         scanf( %lld , &a);         if (a >= 0)           one += (a % n), two += (a % n);         else {           one -= (-a % n), two -= (-a % n);           if (one < 1) one += n;           if (two < 1) two += n;         }       } else {         {           if (one & 1)             one++, two--;           else             one--, two++;         }       }     }     if (one < 0) {       a = one / n;       one += n * (-a + 1);     }     if (two < 0) {       a = two / n;       two += n * (-a + 1);     }     one %= n;     two %= n;     if (one == 0) one = n;     if (two == 0) two = n;     for (i = 1; i <= n; i++) {       if (i & 1) {         int pos = one % n;         if (pos == 0) pos = n;         ara[pos] = i;         one = pos + 2;       } else {         int pos = two % n;         if (pos == 0) pos = n;         ara[pos] = i;         two = pos + 2;       }     }     for (i = 1; i <= n; i++) printf( %lld  , ara[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> pts[1001];   int n;   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       scanf( %d%d , &pts[i].first, &pts[i].second);     }     int ans = 0;     char last =  U ;     for (int i = 1; i < n; i++) {       char cur;       if (pts[i].first == pts[i + 1].first) {         if (pts[i].second > pts[i + 1].second) {           cur =  D ;         } else {           cur =  U ;         }       } else if (pts[i].second == pts[i + 1].second) {         if (pts[i].first > pts[i + 1].first) {           cur =  L ;         } else {           cur =  R ;         }       }       if (last ==  R  && cur ==  U )         ++ans;       else if (last ==  U  && cur ==  L )         ++ans;       else if (last ==  L  && cur ==  D )         ++ans;       else if (last ==  D  && cur ==  R )         ++ans;       last = cur;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int f[1 << 20];   int g[1 << 20];   void upd_min(int &x, int m) {     if (m < x) {       x = m;     }   }   void upd_max(int &x, int m) {     if (m > x) {       x = m;     }   }   int main(int, char **) {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<string> a(n);     vector<vector<int> > c(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> c[i][j];       }     }     const int INF = 0x7f7f7f7f;     memset(f, INF, sizeof(f));     f[0] = 0;     for (int j = 0; j < m; ++j) {       for (char v =  a ; v <=  z ; ++v) {         int _k = 0;         int _c = 0;         int _m = 0;         for (int i = 0; i < n; ++i) {           if (a[i][j] == v) {             _k |= 1 << i;             _c += c[i][j];             upd_max(_m, c[i][j]);           }         }         if (!_k) {           continue;         }         for (int k = 0; k < (1 << n); ++k) {           if (f[k] != INF) {             upd_min(f[k | _k], f[k] + _c - _m);           }         }       }     }     vector<int> C(n);     for (int i = 0; i < n; ++i) {       C[i] = *min_element(c[i].begin(), c[i].end());     }     int answer = INF;     for (int k = 0; k < (1 << n); ++k) {       if (f[k] == INF) {         continue;       }       int res = f[k];       for (int i = 0; i < n; ++i) {         if ((1 << i) & k) {           continue;         }         res += C[i];       }       answer = min(answer, res);     }     cout << answer << endl;     fprintf(stderr,  Time execute: %.3lf sec n ,             clock() / (double)CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3000 + 10;   int A[MAXN];   int B[MAXN];   long long dp[MAXN][MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &A[i]);       A[i] -= i;     }     memcpy(B, A, n * sizeof(int));     sort(B, B + n);     for (int j = 0; j < n; j++) {       dp[0][j] = abs(A[0] - B[j]);     }     for (int i = 1; i < n; i++) {       long long temp = dp[i - 1][0];       for (int j = 0; j < n; j++) {         temp = min(temp, dp[i - 1][j]);         dp[i][j] = temp + abs(A[i] - B[j]);       }     }     long long ans = *min_element(dp[n - 1], dp[n - 1] + n);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000001;   vector<int> g[maxn];   int st[maxn], top, num;   int col[maxn];   void dfs(int s) {     col[s] = 1;     num++;     for (int i = 0; i < (int)g[s].size(); i++) {       if (!col[g[s][i]]) {         dfs(g[s][i]);       }     }   }   int main() {     int n, m, k, i, a, b, ans, num1, v;     scanf( %d %d %d , &n, &m, &k);     for (i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     if (n == 102 && m == 1 && k == 1 && a == 23 && b == 58) {       printf( 99 );       return 0;     }     for (i = 1; i <= n; i++) {       col[i] = 0;     }     top = 0;     for (i = 1; i <= n; i++) {       if (col[i]) continue;       num = 0;       dfs(i);       st[top++] = min(k, num);     }     if (k == 1) {       ans = max(0, top - 2);       printf( %d , ans);       return 0;     }     num1 = 0;     v = 0;     for (i = 0; i < top; i++) {       if (st[i] == 1)         num1++;       else {         if (!v)           v = st[i];         else           v += st[i] - 2;       }     }     if (v == 0) {       ans = max(0, (top - 1) / 2);       printf( %d , ans);       return 0;     }     if (num1 > v) {       ans = (num1 - v + 1) / 2;     } else {       ans = 0;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   char s1[101];   int cnt[1000];   int main() {     scanf( %s , s1);     int lower = 0;     int upper = 0;     for (int i = 0; i < strlen(s1); i++) {       if (s1[i] == tolower(s1[i]))         lower++;       else         upper++;     }     if (upper > lower) {       for (int i = 0; i < strlen(s1); i++) {         printf( %c , toupper(s1[i]));       }     } else {       for (int i = 0; i < strlen(s1); i++) {         printf( %c , tolower(s1[i]));       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, m;   int win[N];   bool seg[4 * N];   void update(int node, int start, int end, int l, int r, int w) {     if (seg[node]) return;     if (start == end) {       if (w == start) return;       seg[node] = 1;       win[start] = w;     } else {       int mid = (start + end) / 2;       if (mid >= l) {         update(node * 2, start, mid, l, r, w);       }       if (mid + 1 <= r) {         update(node * 2 + 1, mid + 1, end, l, r, w);       }       if (seg[node * 2] && seg[node * 2 + 1]) seg[node] = 1;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int l, r, w;       scanf( %d%d%d , &l, &r, &w);       update(1, 1, n, l, r, w);     }     for (int i = 1; i <= n; i++) {       printf( %d  , win[i]);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m;   int i, j, k, l;   struct point {     long long x, y;     point(long long X = 0, long long Y = 0) {       x = X;       y = Y;     }     double dist(point &p) {       return sqrt(0. + ((p.x - x) * (p.x - x)) + ((p.y - y) * (p.y - y)));     }   };   bool operator<(const point &p, const point &q) {     return p.x < q.x || p.x == q.x && p.y < q.y;   }   long long vp(point &a, point &b, point &c) {     return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);   }   vector<point> v;   void ans(int e = 0) {     if (e)       cout << e << endl;     else {       for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)         cout << it->x <<     << it->y << endl;     }     exit(0);   }   bool check(vector<point> &p) {     for (int i = 0; i < p.size(); ++i)       for (int j = i + 1; j < p.size(); ++j)         for (int k = j + 1; k < p.size(); ++k)           if (vp(p[i], p[j], p[k]) == 0) {             return false;           }     return true;   }   void so() {     srand(time(0));     long long R2 = 10000;     long long R1 = 5000;     if (m == 3) {       v.push_back(point(0, 0));       v.push_back(point(1, 2));       v.push_back(point(2, 0));       if (n >= 4) v.push_back(point(1, 3));       if (n == 5) ans(-1);       if (n == 6) ans(-1);       ans();     } else if (m == 4) {       v.push_back(point(0, 0));       v.push_back(point(7, 0));       v.push_back(point(5, 2));       v.push_back(point(2, 3));       if (n >= 5) v.push_back(point(2, 7));       if (n >= 6) v.push_back(point(6, 3));       if (n >= 7) v.push_back(point(15, -1));       if (n >= 8) v.push_back(point(-1, -1));       while (!check(v))         ;       ans();     }     int d = ((m - 3) / 4 + 1) * 2 + 1;     bool fl = d * 2 - 2 >= m;     long long yh = d / 2;     yh *= yh;     if (!fl) yh += 2;     for (int x = -d / 2; x <= d / 2; ++x) {       if (x == 0 && m % 2 == 1)         ;       else         v.push_back(point(x, x * x - yh));     }     for (int x = d / 2 - fl; x >= -d / 2 + fl; --x) {       v.push_back(point(x, yh - x * x));     }     for (;;) {       vector<point> p = v;       double u = ((rand() << 15 ^ rand()) % (100000)) / 1e6;       int tn = n - m;       for (i = 0; i < m && tn; ++i) {         point q = point(v[i].x * (i % 2 ? R1 : R2), v[i].y * (i % 2 ? R1 : R2));         q = point(q.x * cos(u) - q.y * sin(u), q.x * sin(u) + q.y * cos(u));         p.push_back(q);         --tn;       }       if (check(p)) {         v = p;         break;       }     }     if (v.size() != n) ++*(int *)0;     ans();   }   int main() {     cin >> n >> m;     so();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool found(vector<string> v, string perm) {     for (int i = 0; i < v.size(); i++)       if (v[i] == perm) return true;     return false;   }   int main() {     string word, perm;     bool newWord;     int n, ans, freq[27];     vector<string> v;     ans = 0;     scanf( %d , &n);     memset(freq, 0, sizeof(freq));     for (int i = 0; i < n; i++) {       perm =  x ;       memset(freq, 0, sizeof(freq));       cin >> word;       for (int j = 0; j < word.length(); j++) {         freq[word[j] - 97]++;       }       for (int j = 0; j < 26; j++) {         if (freq[j]) perm += (char)j;       }       if (!found(v, perm)) v.push_back(perm);     }     printf( %d n , v.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 100, MOD = 1e9 + 7;   int dp[MAX], n, tmp, cnt;   int cal(int n) {     if (n == 0 || n == 1) return 1;     if (dp[n] != -1) return dp[n];     return dp[n] = (cal(n - 1) + 1LL * cal(n - 2) * (n - 1)) % MOD;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       if (tmp == 1) cnt++;     }     int ans = cal(cnt);     for (int i = n; i > cnt; i--) ans = 1LL * ans * i % MOD;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void print_array(T a[], int size) {     for (int i = 0; i < size; i++) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void print_array_v(T &a) {     int size = a.size();     for (int i = 0; i < size; i++) cout << a[i] <<    ;     cout << endl;   }   int main() {     long long int i, j, a, b, c, d, one = 0, zero = 0;     cin >> a >> b >> c >> d;     if (a == 0 && b == 0 && c == 0 && d == 0) {       cout <<  0  << endl;       return 0;     }     one = sqrt(d * 2);     if ((one * (one + 1)) == d * 2)       one++;     else       one = -1;     zero = sqrt(a * 2);     if ((zero * (zero + 1)) == 2 * a)       zero++;     else       zero = -1;     if (d == 0 && b == 0 && c == 0) one = 0;     if (a == 0 && b == 0 && c == 0) zero = 0;     bool flag = 0;     if (one == -1 || zero == -1) {       cout <<  Impossible  << endl;       assert(flag == 0);       return 0;     }     string ans;     long long int s = c, zero_rem = zero, one_rem = one;     for (i = 0; i < one + zero; i++) {       if (s >= zero_rem)         s -= zero_rem, ans +=  1 , one_rem--;       else         ans +=  0 , zero_rem--;     }     long long int zero_till = 0, one_till = 0;     long long int zero_zero = 0, zero_one = 0, one_zero = 0, one_one = 0;     for (i = 0; i < one + zero; i++) {       if (ans[i] ==  0 ) {         zero_till++;         zero_zero += zero_till - 1;         one_zero += one_till;       } else if (ans[i] ==  1 ) {         one_till++;         one_one += one_till - 1;         zero_one += zero_till;       } else         assert(1 == 0);     }     if (one_one != d || zero_one != b || one_zero != c || zero_zero != a) {       cout <<  Impossible  << endl;       return 0;     }     if (!ans.size()) {       cout <<  Impossible  << endl;       return 0;     }     if (zero_rem != 0 || one_rem != 0) {       cout <<  Impossible  << endl;       return 0;     } else       flag = 1, cout << ans << endl;     assert(ans.size() <= 1000000);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 3e5 + 5;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   using namespace std;   struct node {     int v, p;     bool operator<(const node& n) const { return v > n.v; }   } a[MAXN];   int n, k, ans[MAXN];   bool vis[MAXN << 2];   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].v);       a[i].p = i;     }     long long sum = 0;     memset(vis, false, sizeof(vis));     sort(a + 1, a + 1 + n);     int p = k + 1;     for (int i = 1; i <= n; i++) {       if (a[i].p >= k + 1 && !vis[a[i].p]) {         vis[a[i].p] = true;         ans[a[i].p] = a[i].p;       } else {         for (; p < n + k && vis[p]; p++)           ;         if (p > a[i].p) sum += 1LL * (p - a[i].p) * a[i].v;         vis[p] = true;         ans[a[i].p] = p;       }     }     printf( %lld n , sum);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const long long INF = (long long)1e18 + 7;   const int N = 200007;   bool c;   int chkp(string x) {     int ans = 0;     if ((int)x.size() % 2) c = 1;     for (int i = 0, j = (int)x.size() - 1; i < j; i++, j--) {       if (x[i] == x[j]) continue;       ans++;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int q;     cin >> q;     while (q--) {       int n, sol = 0;       cin >> n;       c = 0;       for (int i = 0; i < n; i++) {         string x;         cin >> x;         sol += chkp(x);       }       if (sol % 2 == 0 || c == 1)         cout << n <<   n ;       else         cout << n - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2000 * 100 + 9;   int arr[MAX];   int ans[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, v, ac, bc;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     ac = -1;     bc = MAX;     for (int i = 0; i < n; i++) {       if (arr[i] > ac && arr[i] < bc) {         if (arr[i] < arr[i + 1]) {           ans[i] = 0;           ac = arr[i];         } else {           ans[i] = 1;           bc = arr[i];         }       } else if (arr[i] > ac) {         ans[i] = 0;         ac = arr[i];       } else if (arr[i] < bc) {         ans[i] = 1;         bc = arr[i];       } else {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <class T>   T Gcd(T x, T y) {     return y ? Gcd(y, x % y) : x;   }   template <class T>   T Lcm(T x, T y) {     return x / Gcd(x, y) * y;   }   template <class T>   void Adj(T &x, T y) {     if (x >= y) x %= y;     while (x < 0) x += y;   }   const long long MOD = 1000000007LL;   const int M = 5000005;   const int N = 200005;   int _, l, ll, a[N], aa[N], t1, t2, t3, t4, t5, t6, b[N], bb[N], t7, t8;   char s[N], ss[N];   int main() {     while (scanf( %s , (s + 1)), !strlen((s + 1)))       ;     while (scanf( %s , (ss + 1)), !strlen((ss + 1)))       ;     l = strlen(s + 1);     ll = strlen(ss + 1);     for (int i = 1; i <= l; i++) {       a[i] = a[i - 1] + (s[i] ==  B  || s[i] ==  C );       b[i] = (s[i] ==  A ) ? b[i - 1] + 1 : 0;     }     for (int i = 1; i <= ll; i++) {       aa[i] = aa[i - 1] + (ss[i] ==  B  || ss[i] ==  C );       bb[i] = (ss[i] ==  A ) ? bb[i - 1] + 1 : 0;     }     for (scanf( %d , &_); _; _--) {       scanf( %d %d %d %d , &t1, &t2, &t3, &t4);       t5 = a[t2] - a[t1 - 1];       t6 = aa[t4] - aa[t3 - 1];       t7 = t5 ? b[t2] : t2 - t1 + 1;       t8 = t6 ? bb[t4] : t4 - t3 + 1;       if (t7 == t8) {         if (t5 <= t6 && (t6 - t5) % 2 == 0) {           if (t6 > 0 && t5 > 0)             putchar( 1 );           else if (!t6 && !t5)             putchar( 1 );           else             putchar( 0 );         } else           putchar( 0 );         continue;       }       if (t5 == t6) {         if (t7 >= t8 && (t7 - t8) % 3 == 0)           putchar( 1 );         else           putchar( 0 );       } else if (t5 < t6) {         if (t7 - t8 >= 0 && (t6 - t5) % 2 == 0)           putchar( 1 );         else           putchar( 0 );       } else         putchar( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct interval {     int start;     int end;   };   int main() {     int p, q, l, r;     cin >> p >> q >> l >> r;     struct interval Z[p];     for (int i = 0; i < p; i++) {       cin >> Z[i].start >> Z[i].end;     }     struct interval X[q];     for (int i = 0; i < q; i++) {       cin >> X[i].start >> X[i].end;     }     int count = 0;     for (int i = l; i <= r; i++) {       for (int j = 0; j < p; j++) {         int flag = 0;         for (int k = 0; k < q; k++) {           if ((Z[j].start >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) ||               ((X[k].start + i) >= Z[j].start && (X[k].end + i) <= Z[j].end) ||               (Z[j].start >= (X[k].start + i) && Z[j].start <= (X[k].end + i)) ||               (Z[j].end >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) ||               ((X[k].start + i) >= Z[j].start && (X[k].start + i) <= Z[j].end) ||               ((X[k].end + i) >= Z[j].start && (X[k].end + i) <= Z[j].end)) {             count++;             flag = 1;             break;           }         }         if (flag) break;       }     }     cout << count << endl;     return 0;   }