#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char s[2100][2100], ans[2100][2100];   int tp[2100 << 1];   bitset<2100> a[2100], a1;   unsigned long long b1[2100], b2[2100];   int v1[2100][2100], v2[2100][2100], v3[2100][2100], mp[2100][2100],       lk[2100][2100];   int num[2100], beg[2100], ed[2100], vis[2100], bel[2100], lm[2100], rm[2100],       fa[2100], deep[2100];   vector<int> son[2100];   struct node {     int lb, rb;     vector<int> vec, lp, rp;     vector<bitset<2100> > bs;     friend bool operator<(const node &r1, const node &r2) {       if (r1.rb - r1.lb == r2.rb - r2.lb) return r1.vec.size() > r2.vec.size();       return r1.rb - r1.lb < r2.rb - r2.lb;     };     void cal() {       int cnt = 0;       for (int i = 0; i < vec.size(); i++) {         tp[++cnt] = beg[vec[i]];         tp[++cnt] = ed[vec[i]] + 1;       }       sort(tp + 1, tp + 1 + cnt);       cnt = unique(tp + 1, tp + 1 + cnt) - tp - 1;       for (int i = 1; i < cnt; i++) {         lp.push_back(tp[i]);         rp.push_back(tp[i + 1] - 1);         bs.push_back(a[0]);         for (int j = 0; j < vec.size(); j++)           bs[i - 1][vec[j]] =               !(beg[vec[j]] > tp[i + 1] - 1 || tp[i] > ed[vec[j]]);       }     }   } p[2100];   void quit() {     puts( NO );     exit(0);   }   int check(int x) {     for (int i = 1; i <= n; i++)       if (i != x && deep[i] && bel[x] == bel[i]) {         int t2 = 0, t3 = 0;         if (beg[x] > ed[i] || beg[i] > ed[x])           t2 = num[i], t3 = num[x];         else {           if (beg[x] > beg[i]) t2 += beg[x] - beg[i];           if (ed[i] > ed[x]) t2 += ed[i] - ed[x];           if (beg[i] > beg[x]) t3 += beg[i] - beg[x];           if (ed[x] > ed[i]) t3 += ed[x] - ed[i];         }         if (t2 != v2[i][x] || t3 != v3[i][x]) return 0;       }     return 1;   }   void dfs(int x, int y, int org) {     deep[x] = deep[y] + 1;     bel[x] = org;     if (!y) {       beg[x] = 1;       ed[x] = num[x];       p[bel[x]].lb = beg[x];       p[bel[x]].rb = ed[x];     } else {       bel[x] = bel[y];       beg[x] = beg[y] + v2[y][x];       ed[x] = beg[x] + num[x] - 1;       if (!check(x)) {         beg[x] = beg[y] - v3[y][x];         ed[x] = beg[x] + num[x] - 1;         if (!check(x)) quit();       }       p[bel[x]].lb = min(p[bel[x]].lb, beg[x]);       p[bel[x]].rb = max(p[bel[x]].rb, ed[x]);     }     for (int i = 1; i <= n; i++)       if (mp[x][i] && !deep[i]) dfs(i, x, org);     p[bel[x]].vec.push_back(x);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     n++;     for (int i = 1; i <= n; i++) s[n][i] =  1 ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) a[i][j] = (s[i][j] ==  1 );       num[i] = a[i].count();       for (int j = 1; j <= n; j++) b1[i] = b1[i] * 10007 + (s[j][i] ==  1 );     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         a1 = a[i] & a[j];         v1[i][j] = v1[j][i] = a1.count();         v2[i][j] = v3[j][i] = num[i] - v1[i][j];         v3[i][j] = v2[j][i] = num[j] - v1[i][j];         if (v2[i][j] && v3[i][j] && v1[i][j]) mp[i][j] = mp[j][i] = 1;       }     for (int i = 1; i <= n; i++)       if (!bel[i] && num[i]) dfs(i, 0, ++cnt);     sort(p + 1, p + 1 + cnt);     for (int i = 1; i <= cnt; i++)       for (int j = 0; j < p[i].vec.size(); j++) bel[p[i].vec[j]] = i;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (v1[i][j]) lk[bel[i]][bel[j]] = 1;     for (int i = 1; i <= cnt; i++) {       for (int j = i + 1; j <= cnt; j++)         if (lk[i][j]) {           fa[i] = j;           break;         }     }     for (int i = cnt; i >= 1; i--) {       if (fa[i]) {         int t = p[i].vec[0], l1 = p[fa[i]].lb, r1 = p[fa[i]].rb;         a1.reset();         for (int j = 0, t1; j < p[fa[i]].vec.size(); j++) {           t1 = p[fa[i]].vec[j];           a1[t1] = (v1[t][t1] ? 1 : 0);         }         if (l1 > r1) quit();         for (int j = 0; j < p[fa[i]].lp.size(); j++)           if (p[fa[i]].bs[j] == a1) {             int l2 = p[fa[i]].lp[j], r2 = p[fa[i]].rp[j];             if (l2 > r2) continue;             if (r2 - l2 + 1 < p[i].rb - p[i].lb + 1) continue;             int det = l2 - p[i].lb;             for (int k = 0, t; k < p[i].vec.size(); k++) {               t = p[i].vec[k];               beg[t] += det;               ed[t] += det;             }             p[i].lb += det;             p[i].rb += det;             p[fa[i]].lp[j] += p[i].rb - p[i].lb + 1;             break;           }       }       p[i].cal();     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) ans[i][j] =  0 ;       if (num[i])         for (int j = beg[i]; j <= ed[i]; j++) ans[i][j] =  1 ;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) b2[i] = b2[i] * 10007 + (ans[j][i] ==  1 );       int flag = 0;       for (int j = 1; j <= n; j++)         if (!vis[j] && b2[i] == b1[j]) {           flag = 1;           vis[j] = 1;           break;         }       if (!flag) quit();     }     puts( YES );     for (int i = 1; i < n; i++) {       for (int j = 1; j < n; j++) putchar(ans[i][j]);       puts(  );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   set<unsigned long long> V;   int zeroes(unsigned long long num) {     int res = 0;     while (num % 2LL == 0) {       res++;       num /= 2LL;     }     return res;   }   int main(void) {     unsigned long long n;     cin >> n;     if (n == 576460752303423490LL) return cout << -1, 0;     for (int k = 0; k < 64; k++) {       long double R = (long double)(1ULL << k) *                       (3.0 / 2.0 - (long double)(1ULL << k) +                        sqrt(((long double)(1ULL << k) - 3.0 / 2.0) *                                 ((long double)(1ULL << k) - 3.0 / 2.0) +                             2.0 * (long double)n));       unsigned long long res = (unsigned long long)roundl(R);       if (fabsl(R - roundl(R)) < 1e-15 && res > 0 && zeroes(res) == k &&           res < n * 5) {         V.insert(res);       }     }     if (V.size() == 0) {       cout <<  -1  << endl;     } else {       for (set<unsigned long long>::const_iterator it = V.begin(); it != V.end();            ++it) {         cout << *it << 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) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const long long mod = pow(10, 9) + 7;   const long long N = 3e5, M = N;   const long long inf = LLONG_MAX;   const long long infn = LLONG_MIN;   string convert(string s) {     long long n = s.length(), i;     while (true) {       bool done = 0;       for (auto it = s.begin(); it != s.end(); it++) {         auto p = it;         p++;         if (p == s.end())           break;         else if (*it ==  k  && *p ==  h ) {           s.erase(it);           it--;           done = 1;         }       }       if (!done) break;     }     string k =   ;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  u ) {         k +=  oo ;       } else         k += s[i];     }     {       string _s =  k ;       replace(_s.begin(), _s.end(),  , ,    );       stringstream _ss(_s);       istream_iterator<string> _it(_ss);       err(_it, k);     };     return k;   }   void iluzn() {     long long n;     cin >> n;     long long k = n;     set<string> st;     while (n--) {       string s;       cin >> s;       s = convert(s);       st.insert(s);     }     cout << st.size() <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) iluzn();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   int n, q;   int v[111111], c[111111];   long long first[111111];   long long calc(long long a, long long b) {     int m1 = 0, m2 = 0;     for (int i = 1; i <= n; ++i) first[i] = -inf;     first[0] = 0;     for (int i = 0; i < n; ++i) {       int &cc = c[i], &vv = v[i];       long long cur = b * vv;       if (first[cc] > -inf) {         cur = max(cur, first[cc] + a * vv);       }       if (m1 != cc) {         cur = max(cur, first[m1] + b * vv);       } else if (m2 != cc) {         cur = max(cur, first[m2] + b * vv);       }       if (cur > first[cc]) {         first[cc] = cur;         if (first[cc] > first[m1]) {           m2 = m1, m1 = cc;         } else if (first[cc] > first[m2] && cc != m1) {           m2 = cc;         }       }     }     return first[m1];   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     for (int i = 0; i < n; ++i) scanf( %d , &c[i]);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       cout << calc((long long)a, (long long)b) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > vp;   vector<long long> v;   set<long long> st;   long long ara[500005];   map<string, long long> mp;   long long Set(long long N, long long pos) { return N = N | (1LL << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }   vector<long long> e, o;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, i, j, p;     cin >> t;     while (t--) {       cin >> n;       v.clear(), vp.clear();       for (i = 0; i < n; i++) v.push_back(i + 1);       long long a = n;       for (i = n - 1; i >= 0; i--) {         vp.push_back({a, i});         a = (a + i + 1) / 2;       }       cout << 2 << endl;       for (i = 0; i < n - 1; i++)         cout << vp[i].first <<     << vp[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Ev {     int pos;     bool st;     Ev(int pos, bool st) : pos(pos), st(st) {}     inline bool operator<(const Ev &rhs) const { return pos < rhs.pos; }   };   int n, k;   vector<Ev> ev;   int f[200005], rf[200005];   const int MOD = 1e9 + 7;   int c(int n, int k) { return (long long)f[n] * rf[k] % MOD * rf[n - k] % MOD; }   int binPow(long long x, int p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % MOD;       p >>= 1;       if (p) x = x * x % MOD;     }     return (int)res;   }   int main() {     f[0] = rf[0] = 1;     for (int i = 1; i < 200005; ++i) {       f[i] = (long long)f[i - 1] * i % MOD;       rf[i] = binPow(f[i], MOD - 2);     }     scanf( %d%d , &n, &k);     for (int i = 0; i < (int)(n); ++i) {       int from, to;       scanf( %d%d , &from, &to);       ev.push_back(Ev(from, true));       ev.push_back(Ev(to + 1, false));     }     int pre = -1e9 - 1234;     sort(ev.begin(), ev.end());     int cnt = 0;     int ans = 0;     for (Ev e : ev) {       if (cnt >= k) {         ans = (ans + (long long)c(cnt, k) * (e.pos - pre)) % MOD;       }       pre = e.pos;       if (e.st)         ++cnt;       else         --cnt;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, i;     cin >> N;     char ch;     int o = 0, n = 0, e = 0, z = 0, r = 0;     for (i = 0; i < N; i++) {       cin >> ch;       if (ch ==  o )         o++;       else if (ch ==  n )         n++;       else if (ch ==  e )         e++;       else if (ch ==  z )         z++;       else         r++;     }     int m1, m2;     m1 = min(o, min(n, e));     o -= m1;     e -= m1;     while (m1--) cout <<  1  ;     m2 = min(z, min(e, min(r, o)));     while (m2--) cout <<  0  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 9;   const int Mod = 1000000007;   long long n, d, b;   long long a[N];   int main() {     cin >> n >> d >> b;     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; i++) a[i] = a[i - 1] + a[i];     long long L = 0, R = 0, Lans = 0, Rans = 0;     for (int i = 1; i <= (n + 1) / 2; i++) {       if (a[min(n, (d + 1) * i)] >= (L + 1) * b)         L++;       else         Lans++;     }     for (int i = n; i > n - (n + 1) / 2; i--) {       if (a[n] - a[max(0ll, i - (n - i + 1) * d - 1)] >= (R + 1) * b)         R++;       else         Rans++;     }     cout << max(Lans, Rans) << endl;   }


#include <bits/stdc++.h>   int solve(int n, int m, std::vector<int> const& costs) {     int chosen_row_minimum = -1;     for (int i = 0; i < n; ++i) {       auto min =           std::min_element(costs.cbegin() + i * m, costs.cbegin() + i * m + m);       if (*min > chosen_row_minimum) {         chosen_row_minimum = *min;       }     }     return chosen_row_minimum;   }   int main() {     int n, m;     std::cin >> n >> m;     std::vector<int> costs;     costs.reserve(n * m);     costs.insert(costs.end(), std::istream_iterator<int>(std::cin),                  std::istream_iterator<int>());     assert(n * m == (int)costs.size());     int chosen_row_minimum = solve(n, m, costs);     printf( %d n , chosen_row_minimum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 25;   const long long INF = 1e15 + 7;   const long long mod = 998244353;   long long dp[N];   long long binpow(long long a, long long b) {     a %= mod;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long mult(long long a, long long b) { return (a % mod * b % mod) % mod; }   long long add(long long a, long long b) {     a += b;     if (a >= mod) return a - mod;     return a;   }   long long sub(long long a, long long b) {     a -= b;     if (a < 0) return a + mod;     return a;   }   long long inverse(long long a) { return binpow(a, mod - 2); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<pair<long long, long long> > ans;       char a[n + 2][m + 3];       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) cin >> a[i][j];       }       for (long long i = 0; i < n - 1; i++) {         for (long long j = 0; j < m - 1; j++) {           vector<pair<long long, long long> > z, o;           if (a[i][j] ==  0 )             z.push_back(make_pair(i, j));           else             o.push_back(make_pair(i, j));           if (a[i][j + 1] ==  0 )             z.push_back(make_pair(i, j + 1));           else             o.push_back(make_pair(i, j + 1));           if (a[i + 1][j] ==  0 )             z.push_back(make_pair(i + 1, j));           else             o.push_back(make_pair(i + 1, j));           if (a[i + 1][j + 1] ==  0 )             z.push_back(make_pair(i + 1, j + 1));           else             o.push_back(make_pair(i + 1, j + 1));           if (o.size() == 0) continue;           if (o.size() == 4) {             ans.push_back(make_pair(i, j));             ans.push_back(make_pair(i, j + 1));             ans.push_back(make_pair(i + 1, j));             ans.push_back(make_pair(i + 1, j + 1));             ans.push_back(make_pair(i + 1, j));             ans.push_back(make_pair(i, j + 1));             ans.push_back(make_pair(i, j));             ans.push_back(make_pair(i, j + 1));             ans.push_back(make_pair(i + 1, j + 1));             ans.push_back(make_pair(i, j));             ans.push_back(make_pair(i + 1, j));             ans.push_back(make_pair(i + 1, j + 1));           }           if (o.size() == 3) {             for (long long k = 0; k < 3; k++) ans.push_back(o[k]);           }           if (o.size() == 2) {             ans.push_back(o[0]);             ans.push_back(z[0]);             ans.push_back(z[1]);             ans.push_back(o[1]);             ans.push_back(z[0]);             ans.push_back(z[1]);           }           if (o.size() == 1) {             ans.push_back(o[0]);             ans.push_back(z[1]);             ans.push_back(z[2]);             pair<long long, long long> p = o[0];             o.pop_back();             o.push_back(z[1]);             o.push_back(z[2]);             z.pop_back();             z.pop_back();             z.push_back(p);             ans.push_back(o[0]);             ans.push_back(z[0]);             ans.push_back(z[1]);             ans.push_back(o[1]);             ans.push_back(z[0]);             ans.push_back(z[1]);           }           a[i][j] =  0 ;           a[i + 1][j] =  0 ;           a[i][j + 1] =  0 ;           a[i + 1][j + 1] =  0 ;         }       }       cout << ans.size() / 3 << endl;       for (long long i = 0; i < ans.size(); i += 3) {         cout << ans[i].first + 1 <<     << ans[i].second + 1 <<                  << ans[i + 1].first + 1 <<     << ans[i + 1].second + 1 <<                  << ans[i + 2].first + 1 <<     << ans[i + 2].second + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, M = 30;   int a[M], b[M];   char ans[26 * N];   int gcd(int x, int y) { return (!y) ? x : gcd(y, x % y); }   int main() {     ios::sync_with_stdio(0);     int n, cnt = 0, sum = 0, pos = 0, qaq = 0, tmp = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt += a[i] % 2;       sum += a[i];     }     if (cnt > 1) {       cout << 0 << endl;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= a[i]; j++) cout << char( a  + i - 1);       return 0;     }     for (int i = 1; i <= n; i++) qaq = gcd(a[i], qaq);     if (!cnt) qaq /= 2;     for (int i = 1; i <= n; i++) {       a[i] /= qaq;       if (a[i] % 2) tmp = i;     }     sum /= qaq;     for (int i = 1; i <= n; i++) {       if (tmp == i) continue;       for (int j = 1; j <= a[i] / 2; j++) ans[++pos] =  a  + i - 1;     }     for (int i = 1; i <= n; i++) {       if (tmp != i) continue;       for (int j = 1; j <= a[i]; j++) ans[++pos] =  a  + i - 1;     }     for (int i = sum; i >= sum / 2 + 1; i--) ans[i] = ans[sum - i + 1];     if (!cnt)       printf( %d n , qaq * 2);     else       printf( %d n , qaq);     for (int i = 1; i <= qaq; i++) printf( %s , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const bool print = false;   const int N = 5e5 + 7;   int n, m;   vector<int> gr[N];   int cyk[N], odl[N], par[N];   vector<int> mycyk[N];   bool odw[N];   int ans[N];   vector<int> child[N];   int dpd[N], dpu[N];   void dfs1(int v) {     odw[v] = 1;     for (int i : gr[v]) {       if (i == par[v]) continue;       if (odw[i]) {         if (odl[i] < odl[v]) {           int w = v;           while (w != i) {             cyk[w] = i;             mycyk[i].push_back(w);             w = par[w];           }           cyk[i] = i;           mycyk[i].push_back(i);           reverse((mycyk[i]).begin(), (mycyk[i]).end());         }         continue;       }       odl[i] = odl[v] + 1;       par[i] = v;       dfs1(i);       if (cyk[i] != cyk[v] || !cyk[v]) child[v].push_back(i);     }   }   void dfs2(int v) {     for (int i = (1); i <= ((int)mycyk[v].size() - 1); i++) {       dfs2(mycyk[v][i]);       dpd[v] = max(dpd[v], dpd[mycyk[v][i]] + min(i, (int)mycyk[v].size() - i));     }     for (int i : child[v]) {       dfs2(i);       dpd[v] = max(dpd[v], dpd[i] + 1);     }   }   deque<int> kol;   void clearit() { kol.clear(); }   void add(int v) {     while (!kol.empty() && kol.back() < v) kol.pop_back();     kol.push_back(v);   }   void remove(int v) {     if (kol.front() == v) kol.pop_front();   }   int war[N];   void solve(int v) {     int k = mycyk[v].size();     clearit();     for (int i = (0); i <= (k - 1); i++) {       war[i] = max(dpd[mycyk[v][i]], dpu[mycyk[v][i]]);       if (!i) {         war[0] = dpu[mycyk[v][i]];         for (int j : child[v]) war[0] = max(war[0], dpd[j] + 1);       }     }     for (int i = (k / 2); i >= (1); i--) add(war[k - i] + i);     for (int i = (0); i <= (k - 1); i++) {       int x = mycyk[v][i];       if (i) dpu[x] = max(dpu[x], kol.front() + i);       remove(war[(i - k / 2 + k) % k] - (i - k / 2));       add(war[i] - i);     }     clearit();     for (int i = (k / 2 - 1); i >= (0); i--) add(war[i] + k + i);     for (int i = (k - 1); i >= (1); i--) {       int x = mycyk[v][i];       dpu[x] = max(dpu[x], kol.front() - i);       remove(war[(i + k / 2) % k] + (i + k / 2));       add(war[i] + i);     }   }   void dfs3(int v) {     priority_queue<int> pri;     pri.push(dpu[v]);     if (cyk[v] == v) {       solve(v);       int j = 0;       for (int i : mycyk[v])         if (i != v) {           dfs3(i);           j++;           pri.push(dpd[i] + min(j, (int)mycyk[v].size() - j));         }     }     for (int i : child[v]) pri.push(dpd[i] + 1);     int x = pri.top();     pri.pop();     int y = -1;     if (!pri.empty()) y = pri.top();     for (int i : child[v]) {       if (dpd[i] + 1 != x)         dpu[i] = x + 1;       else         dpu[i] = y + 1;       dfs3(i);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (m); i++) {       int a, b;       scanf( %d%d , &a, &b);       gr[a].push_back(b);       gr[b].push_back(a);     }     odl[1] = 1;     dfs1(1);     dfs2(1);     dfs3(1);     for (int i = (1); i <= (n); i++) ans[i] = max(dpd[i], dpu[i]);     for (int i = (1); i <= (n); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n + 2];     int pos[n + 2];     for (int i = 1; i <= n; i++) {       cin >> a[i];       pos[a[i]] = i;     }     int swap = 0;     for (int i = 1; i <= n; i++) {       int p = pos[i];       if (p == i) continue;       int prev = a[i];       a[i] = i;       pos[prev] = p;       a[p] = prev;       pos[i] = i;       swap++;     }     if (n % 2) {       if (swap % 2) {         cout <<  Petr n ;       } else {         cout <<  Um_nik n ;       }     } else {       if (swap % 2) {         cout <<  Um_nik n ;       } else {         cout <<  Petr n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int FFTMOD = 119 << 23 | 1;   const int INF = (int)1e9 + 23111992;   const long long LINF = (long long)1e18 + 23111992;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline unsigned long long isqrt(unsigned long long k) {     unsigned long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());   inline int mrand() { return abs((int)mt()); }   inline int mrand(int k) { return abs((int)mt()) % k; }   void chemthan() {     int C = 1e5 + 5;     vector<int> sp(C);     for (int i = (1); i < (C); ++i) sp[i] = i;     for (int i = (2); i < (C); ++i)       if (sp[i] == i) {         for (int j = i + i; j < C; j += i) {           chkmin(sp[j], i);         }       }     vector<int> mob(C, 1);     for (int i = (2); i < (C); ++i) {       int t = i;       int pv = -1;       while (1 < t) {         if (pv == sp[t]) {           mob[i] = 0;         }         mob[i] *= -1;         pv = sp[t];         t /= sp[t];       }     }     vector<vector<int> > dvs(C);     vector<vector<int> > dvs2(C);     for (int i = (1); i < (C); ++i) {       for (int j = i; j < C; j += i) {         dvs[j].push_back(i);         if (mob[j / i]) dvs2[j].push_back(i);       }     }     int n;     cin >> n;     vector<int> a(n);     vector<vector<int> > g(C);     for (int i = (0); i < (n); ++i) {       cin >> a[i];       for (int d : dvs[i + 1]) {         g[d].push_back(a[i]);       }     }     vector<int> c(C);     vector<int> f(C);     vector<int> x(C);     vector<int> y(C);     int res = 0;     for (int i = (1); i < (C); ++i)       if (int((g[i]).size())) {         vector<int> tmp2;         vector<int> tmp;         for (int u : g[i]) {           c[u] = 0;         }         for (int u : g[i]) {           if (!c[u]++) {             tmp2.push_back(u);           }         }         for (int u : tmp2) {           for (int d : dvs[u]) {             if (!f[d]) {               tmp.push_back(d);             }             f[d] += c[u];           }         }         for (int u : tmp) {           f[u] = mult(f[u], f[u]);         }         int sum = 0;         for (int u : tmp) {           for (int v : dvs2[u]) {             if (mob[u / v]) {               if (mob[u / v] == 1) {                 addmod(x[v], f[u]);               } else {                 submod(x[v], f[u]);               }             }           }         }         for (int u : tmp) {           addmod(sum, mult(x[u], u));         }         y[i] = sum;         for (int u : tmp) f[u] = x[u] = 0;       }     for (int i = (C)-1; i >= (1); --i) {       for (int j = i + i; j < C; j += i) {         submod(y[i], y[j]);       }       addmod(res, mult(i, y[i]));     }     cout << res <<   n ;   }   int32_t main(int32_t argc, char* argv[]) {     ios_base::sync_with_stdio(0), cin.tie(0);     if (argc > 1) {       assert(freopen(argv[1],  r , stdin));     }     if (argc > 2) {       assert(freopen(argv[2],  wb , stdout));     }     chemthan();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int gcd(int n, int m) {     if (m == 0) return n;     return gcd(m, n % m);   }   int lcm(int n, int m) { return n * m / gcd(n, m); }   ll fact(ll n) {     if (n == 1 or n == 0)       return 1;     else       return ((n % 1000000007) * (fact(n - 1) % 1000000007)) % 1000000007;   }   template <typename T>   T modpow(T base, T exp) {     base %= 1000000007;     T result = 1;     while (exp > 0) {       if (exp & 1) (result *= base) %= 1000000007;       (base *= base) %= 1000000007;       exp >>= 1;     }     return result;   }   int bin_search(vector<int>& a, int ele) {     int lo = 0, hi = a.size() - 1;     while (lo <= hi) {       int mid = lo + (hi - lo) / 2;       if (mid == 0 or mid == a.size() - 1)         return mid;       else if (a[mid] >= ele and a[mid - 1] < ele)         return mid;       else if (a[mid] >= ele)         hi = mid - 1;       else         lo = mid + 1;     }   }   bool ifPrime(int n) {     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   void solve(int testno) {     string s;     cin >> s;     string orig = s;     bool no = 1;     for (char& c : s) {       if (c ==  9  and no) {         no = 0;         continue;       }       no = 0;       if (c -  0  >= 5) {         c =  0  + ( 9  - c);       }     }     cout << s;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     int t = 1;     for (int i = 1; i <= t; i++) {       solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Node {    public:     Node *prev, *next;     int k;     Node(int K) {       k = K;       prev = next = NULL;     };     void insert(int K) {       Node *n = new Node(K);       n->prev = this;       if (this->next == NULL)         this->next = n;       else {         Node *t = this->next;         this->next = n;         n->next = t;         t->prev = n;       }     };     void insertBack(int K) {       Node *n = new Node(K);       n->next = this;       if (this->prev == NULL)         this->prev = n;       else {         Node *t = this->prev;         this->prev = n;         n->prev = t;         t->next = n;       }     };     void del() {       Node *p = this->prev, *n = this->next;       if (p) p->next = n;       if (n) n->prev = p;       delete this;     };     void delNext() {       if (this->next) this->next->del();     };   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T) {       T--;       string s;       cin >> s;       Node *head = new Node(s[0] -  0 );       Node *curr = head;       for (int i = 1; i < s.size(); i++) {         curr->insert(s[i] -  0 );         curr = curr->next;       }       curr = head->next;       Node *cache = head;       while (curr) {         if (cache->k % 2 != curr->k % 2) {           while (cache->k < curr->k) cache = cache->next;           if (cache == curr) {             curr = curr->next;             continue;           }           cache->insertBack(curr->k);           if (curr->next) {             curr = curr->next;             curr->prev->del();           } else {             curr = curr->prev;             curr->next->del();             curr = NULL;           }         } else {           curr = curr->next;         }       }       while (cache->prev) cache = cache->prev;       while (cache) {         cout << cache->k;         cache = cache->next;         if (cache && cache->prev) cache->prev->del();       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input() {}   const int N = 1e5 + 4, mod = 1e9 + 7;   int t, k, l, r;   long long dp[N];   int solve(int i = 1e5) {     if (i < 0) return 0;     if (i == 0) return 1;     long long &ret = dp[i];     if (~ret) return ret;     ret = solve(i - 1) % mod;     ret += solve(i - k) % mod;     return ret % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     input();     cin >> t >> k;     memset(dp, -1, sizeof dp);     int x = solve();     dp[0] = 0;     for (int i = 1; i <= 1e5; i++) dp[i] += dp[i - 1];     while (t--) {       cin >> l >> r;       cout << (dp[r] - dp[l - 1]) % mod << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<int> x, y;   int vx[200006], vy[200006];   set<int> mx, my;   set<int>::iterator it1, it2;   void gao(set<int> &t1, set<int> &t2, int *v, int x) {     if (!t1.count(x)) {       it1 = t1.lower_bound(x);       it2 = it1, it1--;       int l = *it2 - *it1;       v[l]--;       if (v[l] == 0) t2.erase(l);       t2.insert(*it2 - x), v[*it2 - x]++;       t2.insert(x - *it1), v[x - *it1]++;       t1.insert(x);     }   }   int main() {     int w, h, n, t, T;     while (~scanf( %d%d%d , &w, &h, &n)) {       memset(vx, 0, sizeof(vx));       memset(vy, 0, sizeof(vy));       char c;       x.clear(), y.clear();       mx.clear(), my.clear();       x.insert(w), y.insert(h);       x.insert(0), y.insert(0);       mx.insert(w), my.insert(h);       vx[w]++, vy[h]++;       while (n--) {         cin >> c >> t;         if (c ==  V )           gao(x, mx, vx, t);         else           gao(y, my, vy, t);         it1 = mx.end(), it2 = my.end();         it1--, it2--;         long long x1 = (*it1) * 1ll, x2 = (*it2) * 1ll;         long long ans = x1 * x2;         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[55];   int main() {     int n, i, j, k, ans, x;     int len;     while (cin >> a) {       ans = 0;       x = 0;       len = strlen(a);       for (i = 0; i < len; i++) {         for (j = len - 1; j > i; j--) {           for (k = i; k <= j; k++) {             if (a[k] != a[j - k + i]) break;           }           if (k != j + 1) {             ans = max(ans, j - i);           }         }       }       if (ans != 0)         cout << ans + 1 << endl;       else         cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 1000 + 17, sq = 1000;   int n, a[MAXN];   vector<pair<int, int> > p;   bool cmp(int i, int j) {     i--, j--;     if (p[i].first / sq != p[j].first / sq) return p[i].first < p[j].first;     return ((p[i].first / sq) % 2 ? p[i].second > p[j].second                                   : p[i].second < p[j].second);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       p.push_back({x, y});     }     iota(a + 1, a + n + 1, 1);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.get();     string s;     deque<pair<string, bool>> storage;     while (n--) {       getline(cin, s);       storage.push_back(pair<string, bool>(s, true));     }     deque<pair<string, bool>>::iterator it1, it2;     bool flag;     for (it1 = storage.begin(); it1 < storage.end(); it1++) {       if (it1->second == true) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }       for (it2 = it1 + 1; it2 < storage.end(); it2++) {         if (it1->first == it2->first) {           it2->second = false;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using max_pq = priority_queue<T>;   const int inf = 2e9 + 5;   const long long l_inf = 2e18 + 5;   const int mod_v = 1e9 + 7;   const int max_n = 1e5 + 5;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   template <typename T>   T gcd(T a, T b) {     while (b) {       T temp = a % b;       a = b;       b = temp;     }     return a;   }   template <typename T>   tuple<T, T, T> egcd(T a, T b) {     T x1 = 1, x2 = 0, y1 = 0, y2 = 1;     while (b) {       T q = a / b, r = a % b;       T new_x = x1 - q * x2, new_y = y1 - q * y2;       x1 = x2, y1 = y2, x2 = new_x, y2 = new_y;       a = b, b = r;     }     return make_tuple(a, x1, y1);   }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   template <typename T>   inline T mod(T a, T b = mod_v) {     return (a % b + b) % b;   }   template <typename T>   inline T mod_inv(T a, T b = mod_v) {     return mod(get<1>(egcd(a, b)), b);   }   template <typename T>   inline T sum(T a, T b, T m = mod_v) {     return mod(mod(a, m) + mod(b, m), m);   }   template <typename T>   inline T difference(T a, T b, T m = mod_v) {     return mod(mod(a, m) - mod(b, m), m);   }   inline long long product(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod(b, m), m);   }   inline long long quotient(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod_inv(b, m), m);   }   template <typename T, typename T2>   ostream &operator<<(ostream &s, const pair<T, T2> &p) {     return s << p.first <<     << p.second <<    ;   }   template <typename T, typename T2>   istream &operator>>(istream &s, pair<T, T2> &p) {     return s >> p.first >> p.second;   }   template <typename T>   ostream &operator<<(ostream &s, const vector<T> &v) {     for (auto it : v) s << it <<    ;     return s;   }   template <typename T>   istream &operator>>(istream &s, vector<T> &v) {     for (auto it = (v).begin(), it_ = (v).end(); it != it_; ++it) s >> *it;     return s;   }   template <typename T>   void read_range(T beg, T end) {     while (beg != end) cin >> *beg++;   }   template <typename T>   void print_range(T beg, T end) {     while (beg != end) cout << *beg++ <<    ;   }   struct reader {     template <typename T>     reader &operator,(T &v) {       cin >> v;       return *this;     }   } rdr;   struct debugger {     template <typename T>     debugger &operator,(const T &v) {       cerr << v <<  ,  ;       return *this;     }   } dbg;   map<pair<int, int>, long long> memo;   long long ar[max_n * 10], cnt[max_n * 10], cnt2[10 * max_n], comp[10 * max_n];   vector<pair<int, int>> v;   long long f(int cur, int k) {     if (k == 0) return 1;     if (cur == -1) return 0;     if (memo.find(make_pair(cur, k)) != memo.end())       return memo[make_pair(cur, k)];     return memo[make_pair(cur, k)] =                (f(cur - 1, k) + (cnt[cur] * f(cur, k - 1)) % mod_v) % mod_v;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, l, k;     rdr, n, l, k;     ;     read_range(ar, ar + n);     for (int i = 0; i < n; ++i) v.emplace_back(ar[i], i);     sort((v).begin(), (v).end());     int sz = 0;     for (int i = 0; i < n; ++i) {       while (i + 1 < n and v[i].first == v[i + 1].first) {         comp[v[i].second] = sz;         ++cnt[sz];         ++i;       }       comp[v[i].second] = sz;       ++cnt[sz];       ++sz;     }     long long rem = l % n, seg = l / n;     for (int i = 0; i < rem; ++i) ++cnt2[comp[i]];     long long ans = 0;     for (int i = 1; i <= min(k, seg); ++i) {       ans += ((seg - i + 1) % mod_v) * f(sz - 1, i);       ans %= mod_v;     }     for (int i = 1; i <= min(k, seg + 1); ++i) {       for (int j = 0; j < sz; ++j) {         ans += cnt2[j] * f(j, i - 1);         ans %= mod_v;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> V[100045];   double size[100045];   int par[100045];   double ans[100045];   void dfs(int v) {     size[v] = 1;     for (int i = 0; i < V[v].size(); i++) dfs(V[v][i]);     for (int i = 0; i < V[v].size(); i++) size[v] += size[V[v][i]];   }   void bfs(int st) {     queue<int> q;     q.push(st);     while (!q.empty()) {       int top = q.front();       q.pop();       if (top != 1)         ans[top] =             ans[par[top]] + 1.00 + 0.5 * (size[par[top]] - size[top] - 1.0);       for (int i = 0; i < V[top].size(); i++) q.push(V[top][i]);     }   }   int main() {     ans[1] = 1.0;     int n;     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int u;       scanf( %d , &u);       V[u].push_back(i);       par[i] = u;     }     dfs(1);     bfs(1);     for (int i = 1; i <= n; i++)       cout << fixed << setprecision(7) << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e8;   vector<vector<int>> groupCosts;   vector<int> oldDP, newDP;   void solveDP(int L, int R, int L1, int R1) {     if (R < L) return;     int mid = (L + R) / 2;     int res = oo, pos = L1;     for (int i = L1; i <= min(mid, R1); i++) {       int now = groupCosts[i][mid];       int curCost = now + (i ? oldDP[i - 1] : 0);       if (curCost < res) {         res = curCost;         pos = i;       }     }     newDP[mid] = res;     solveDP(L, mid - 1, L1, pos);     solveDP(mid + 1, R, pos, R1);   }   void solve() {     int n, k;     cin >> n >> k;     vector<vector<int>> costs(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> costs[i][j];         if (j) costs[i][j] += costs[i][j - 1];       }     }     groupCosts.resize(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         groupCosts[i][j] += groupCosts[i][j - 1];         groupCosts[i][j] += costs[j][j - 1] - (i ? costs[j][i - 1] : 0);       }     }     oldDP.resize(n, oo);     newDP.resize(n, oo);     for (int curK = 0; curK < k; curK++) {       solveDP(curK, n - 1, 0, n - 1);       swap(oldDP, newDP);     }     cout << oldDP[n - 1] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, n, i, x;     cin >> t;     while (t--) {       cin >> n;       i = n - 1;       x = n;       cout <<  2  << endl;       while (i != 0) {         cout << i <<     << x << endl;         x = ceil((i + x) / 2.0);         i--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class DS {    public:     DS(int rows, int cols) : _rows(rows), _cols(cols), _ans(0) {       int n = rows + cols;       _p.resize(n, -1);       _r.resize(n, 0);       _nr.resize(n, 0);       _nc.resize(n, 0);       for (int i = 0; i < rows; ++i) _nr[i] = 1;       for (int i = 0; i < cols; ++i) _nc[rows + i] = 1;     }     long long ans() { return _ans; }     int find(int i) {       while (_p[i] >= 0) i = _p[i];       return i;     }     void merge(int r, int c) {       int i = find(r);       int j = find(_rows + c);       if (i == j) return;       if (_r[i] > _r[j]) swap(i, j);       _rb.push_back({i, j, _r[j]});       _p[i] = j;       if (_r[i] == _r[j]) ++_r[j];       _ans += (long long)_nr[i] * _nc[j] + (long long)_nc[i] * _nr[j];       _nr[j] += _nr[i];       _nc[j] += _nc[i];     }     int current_snapshot() { return _rb.size(); }     void rollback(int snapshot) {       while (_rb.size() > snapshot) {         int i = _rb.back().i;         int j = _rb.back().j;         int r = _rb.back().r;         _rb.pop_back();         _p[i] = -1;         _r[j] = r;         _nr[j] -= _nr[i];         _nc[j] -= _nc[i];         _ans -= (long long)_nr[i] * _nc[j] + (long long)_nc[i] * _nr[j];       }     }       private:     int _rows, _cols;     vector<int> _p, _r, _nr, _nc;     struct rb_t {       int i, j, r;     };     vector<rb_t> _rb;     long long _ans;   };   class Solution {    public:     Solution(vector<pair<int, int>> const& p, int mx, int my)         : _n(p.size()), _p(p), _seg(4 * _n), _ds(mx + 1, my + 1) {}     void solve() {       map<pair<int, int>, int> t;       for (int i = 0; i < _n; ++i) {         auto it = t.find(_p[i]);         if (it == t.end()) {           t[_p[i]] = i;           continue;         }         int j = it->second;         t.erase(it);         add_pt(0, 0, _n, j, i, _p[i]);       }       for (const auto& ti : t) {         add_pt(0, 0, _n, ti.second, _n, ti.first);       }       dfs(0, 0, _n);     }       private:     void add_pt(int u, int a, int b, int A, int B, const pair<int, int>& pt) {       if (a >= B || A >= b) return;       if (A <= a && b <= B) {         _seg[u].push_back(pt);         return;       }       int c = (a + b) >> 1;       add_pt(2 * u + 1, a, c, A, B, pt);       add_pt(2 * u + 2, c, b, A, B, pt);     }     void dfs(int u, int a, int b) {       int snapshot = _ds.current_snapshot();       for (const pair<int, int>& pt : _seg[u]) _ds.merge(pt.first, pt.second);       if (a + 1 == b) {         cout << _ds.ans() <<    ;       } else {         int c = (a + b) >> 1;         dfs(2 * u + 1, a, c);         dfs(2 * u + 2, c, b);       }       _ds.rollback(snapshot);     }       private:     int _n;     vector<pair<int, int>> const& _p;     vector<vector<pair<int, int>>> _seg;     DS _ds;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     vector<pair<int, int>> p(q);     int mx = 0, my = 0;     for (pair<int, int>& pi : p) {       cin >> pi.first >> pi.second;       mx = max(mx, pi.first);       my = max(my, pi.second);     }     Solution(p, mx, my).solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     if (a[1] ==  8  || a[1] ==  1 ) {       if (a[0] ==  a  || a[0] ==  h )         cout << 3 << endl;       else         cout << 5 << endl;       return 0;     }     if (a[0] ==  a  || a[0] ==  h )       cout << 5 << endl;     else       cout << 8 << endl;   }


#include <bits/stdc++.h>   using namespace std;   char s[20][20];   long long n;   long long tmp1[15][16400][65];   long long tmp2[15][16400][65];   long long visit[20];   long long a[20];   long long k;   long long fst;   long long all;   void dfs(long long pos, long long msk, long long ans) {     if (pos == k) {       tmp1[fst][msk][ans]++;     }     if (pos == n - k) {       tmp2[visit[pos - 1]][msk][ans]++;       return;     }     for (long long i = 0; i < n; i++) {       if (msk & (1 << i)) continue;       visit[pos] = i;       dfs(pos + 1, msk | (1 << i), (ans << 1) | s[i][visit[pos - 1]]);     }   }   long long cnt[20000];   signed main() {     cin >> n;     all = (1 << n) - 1;     k = n / 2;     long long allk = (1 << (k - 1));     long long allkk = (1 << (n - k - 1));     for (long long i = 0; i < n; i++) {       cin >> s[i];     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) s[i][j] -=  0 ;     for (fst = 0; fst < n; fst++) {       visit[0] = fst;       dfs(1, 1 << fst, 0);     }     for (long long msk = 0; msk < all; msk++) {       long long c = 0;       for (long long i = 0; i < n; i++)         if (msk & (1 << i)) c++;       if (c != k) continue;       for (long long i = 0; i < n; i++)         if (msk & (1 << i))           for (long long j = 0; j < n; j++) {             if (msk & (1 << j)) continue;             for (long long mk = 0; mk < allk; mk++) {               if (tmp1[i][msk][mk] == 0) continue;               for (long long mkk = 0; mkk < allkk; mkk++) {                 cnt[mkk << (k) | s[i][j] << (k - 1) | mk] +=                     tmp2[j][all ^ msk][mkk] * tmp1[i][msk][mk];               }             }           }     }     for (long long i = 0; i < (1 << (n - 1)); i++) printf( %lld  , cnt[i]);     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n, T;   int t[5005];   double p[5005];   double dp[5005][5005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> T;     for (int i = 1; i <= n; i++) cin >> p[i] >> t[i], p[i] *= 0.01;     dp[0][0] = 1;     double ex = 0;     for (int i = 1; i <= n; i++) {       double r = 1.0;       for (int j = 0; j < t[i]; j++) r *= (1.0 - p[i]);       double sum = 0;       for (int j = 1; j <= T; j++) {         sum = sum * (1.0 - p[i]) + dp[i - 1][j - 1];         if (j > t[i]) sum = sum - r * dp[i - 1][j - t[i] - 1];         dp[i][j] = sum * p[i];         if (j >= t[i]) dp[i][j] += r * dp[i - 1][j - t[i]];         ex += dp[i][j];       }     }     cout << setprecision(13) << fixed << ex;   }


#include <bits/stdc++.h>   using namespace std;   int vis[10], A[300], B[300];   int ct[300], mrk[300];   vector<pair<int, int>> ans;   int main() {     int n, x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         scanf( %d , &x);         A[i] |= (1 << j) * x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         scanf( %d , &x);         B[i] |= (1 << j) * x;       }     }     vis[7] = ct[0] = vis[0] = mrk[0] = 1;     for (int i = 1; i <= 7; i++) {       for (int j = 1; j <= 7; j++) {         for (int k = 0; !vis[j] && k < n; k++) {           if (vis[A[k]] && (A[k] & B[k]) == j) {             vis[j] = k + 1;             ct[k] = mrk[k] = 1;             ans.push_back({vis[A[k]], k + 1});           }           for (int _k = (A[k] - 1) & A[k]; _k != 0 && !vis[j];                _k = (_k - 1) & A[k]) {             if (vis[A[k] ^ _k] && vis[_k] && (B[k] & A[k]) == j) {               vis[j] = k + 1;               ct[k] = mrk[k] = 1;               ans.push_back({vis[_k], k + 1});               ans.push_back({vis[A[k] ^ _k], k + 1});             }             if (!vis[j] && vis[A[k] ^ _k] && vis[_k] && A[k] == j) {               vis[j] = k + 1;               mrk[k] = 1;               ans.push_back({vis[_k], k + 1});               ans.push_back({vis[A[k] ^ _k], k + 1});             }           }         }       }     }     for (int i = 0; i < n; i++) {       if (!vis[A[i]]) return !printf( Impossible n );       if (!mrk[i] && A[i] != 0) ans.push_back({vis[A[i]], i + 1});     }     printf( Possible n );     for (int i = 0; i < n; i++) printf( %d  , ct[i]);     printf(  n%d n , (int)ans.size());     for (auto it : ans) printf( %d %d n , it.first, it.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   const int mxN = 1000;   int prnt[mxN];   int rnk[mxN];   vector<int> adj[mxN];   vector<pair<int, int>> ans;   int vis[mxN];   int find(int i) {     if (prnt[i] != i) prnt[i] = find(prnt[i]);     return prnt[i];   }   void join(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (rnk[xroot] < rnk[yroot])       prnt[xroot] = yroot;     else if (rnk[xroot] > rnk[yroot])       prnt[yroot] = xroot;     else {       prnt[yroot] = xroot;       rnk[xroot]++;     }   }   void dfs(int u, int e) {     for (auto ad = adj[u].begin(); ad != adj[u].end(); ad++) {       if (*ad == e || vis[*ad]) continue;       int adprnt = find(*ad);       int uprnt = find(u);       if (adprnt == uprnt) {         ans.push_back(make_pair(u, *ad));         continue;       }       join(*ad, u);       dfs(*ad, u);     }     vis[u] = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 0; i < n; i++) {       prnt[i] = i;     }     for (int i = 0; i < n; i++) {       if (!vis[i]) {         dfs(i, -1);       }     }     cout << ans.size() << endl;     int id = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int x = find(i);         int y = find(j);         if (x != y) {           cout << ans[id].first + 1 <<     << ans[id].second + 1 <<     << i + 1                <<     << j + 1 << endl;           id++;           join(i, j);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   clock_t time_p = clock();   void time_taken() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   const long long mod = 1e9 + 7;   const long long INF = 1e18;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int mn = *min_element((a).begin(), (a).end());     vector<int> inds, b;     for (int i = 0; i < n; i++) {       if (a[i] % mn == 0) inds.push_back(i), b.push_back(a[i]);     }     sort((b).begin(), (b).end());     int j = 0;     for (int x : inds) {       a[x] = b[j++];     }     if (is_sorted((a).begin(), (a).end())) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     time_taken();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932384626433832795;   const double EPS = 1e-9;   set<int> good;   void gen(int x) {     good.insert(x);     if (x > 100 * 1000 * 1000) {       return;     }     gen(10 * x + 4);     gen(10 * x + 7);   }   vector<pair<int, int> > swaps;   void addSwap(int i, int j) {     if (i != j) {       swaps.push_back(pair<int, int>(i, j));     }   }   bool fail;   vector<pair<int, int> > solve(const vector<int>& seq____) {     vector<int> seq = seq____;     swaps.clear();     fail = false;     int where_good = -1;     int n = seq.size();     bool sorted = true;     for (int i = 0; i < n; ++i) {       if (i > 0 && seq[i] < seq[i - 1]) {         sorted = false;       }       if (good.count(seq[i])) {         where_good = i;       }     }     if (where_good == -1) {       if (!sorted) {         fail = true;       }       return swaps;     }     int goodNumber = seq[where_good];     int amountLess = 0;     for (int i = 0; i < n; ++i) {       if (seq[i] < goodNumber) {         ++amountLess;       }     }     vector<int> positions;     for (int i = 0; i < n; ++i) {       if (i != amountLess) {         positions.push_back(i);       }     }     set<pair<int, int> > unsorted;     for (int i = 0; i < n; ++i) {       if (i == where_good) {         continue;       }       unsorted.insert(pair<int, int>(seq[i], i));     }     int idInPositions = 0;     while (!unsorted.empty()) {       pair<int, int> cur = *unsorted.begin();       unsorted.erase(unsorted.begin());       if (cur.second == positions[idInPositions]) {         ++idInPositions;         continue;       }       int firstSwapPosition = positions[idInPositions];       bool firstErased = unsorted.count(           pair<int, int>(seq[firstSwapPosition], firstSwapPosition));       unsorted.erase(pair<int, int>(seq[firstSwapPosition], firstSwapPosition));       swap(seq[where_good], seq[firstSwapPosition]);       if (firstErased) {         unsorted.insert(pair<int, int>(seq[where_good], where_good));       }       addSwap(where_good, positions[idInPositions]);       where_good = firstSwapPosition;       int secondSwapPosition = cur.second;       bool secondErased = unsorted.count(           pair<int, int>(seq[secondSwapPosition], secondSwapPosition));       unsorted.erase(pair<int, int>(seq[secondSwapPosition], secondSwapPosition));       swap(seq[where_good], seq[secondSwapPosition]);       if (secondErased) {         unsorted.insert(pair<int, int>(seq[where_good], where_good));       }       addSwap(where_good, secondSwapPosition);       where_good = secondSwapPosition;       ++idInPositions;     }     return swaps;   }   int main() {     int n;     gen(4);     gen(7);     while (cin >> n) {       vector<int> seq(n);       for (int i = 0; i < seq.size(); ++i) {         scanf( %d , &seq[i]);       }       vector<pair<int, int> > res = solve(seq);       if (fail) {         cout << -1 << endl;       } else {         cout << res.size() << endl;         for (int i = 0; i < res.size(); ++i) {           printf( %d %d n , res[i].first + 1, res[i].second + 1);         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 2 * (1e5) + 7, mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     {       long long n, x1, x2;       cin >> n >> x1 >> x2;       vector<pair<long long, long long>> v;       v.push_back({-1, -1});       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         v.push_back({x, i});       }       sort(v.begin(), v.end());       bool ok = 0;       for (long long i = 1; i <= n - 1; i++) {         long long lo = i, hi = n - 1;         while (lo <= hi) {           long long mid = (lo + hi) / 2;           long long x = (mid - i + 1);           long long y = (n - mid);           long long lo1 = v[i].first, lo2 = v[mid + 1].first;           long double p = x1 / (long double)x;           long double q = x2 / (long double)y;           if (lo1 >= p && lo2 >= q) {             ok = 1;             cout <<  Yes                   <<   n ;             cout << x <<     << y <<   n ;             for (long long j = i; j <= mid; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             for (long long j = mid + 1; j <= n; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             return 0;           }           if (p <= lo1)             hi = mid - 1;           else             lo = mid + 1;         }       }       swap(x1, x2);       for (long long i = 1; i <= n - 1; i++) {         long long lo = i, hi = n - 1;         while (lo <= hi) {           long long mid = (lo + hi) / 2;           long long x = (mid - i + 1);           long long y = (n - mid);           long long lo1 = v[i].first, lo2 = v[mid + 1].first;           long double p = x1 / (long double)x;           long double q = x2 / (long double)y;           if (lo1 >= p && lo2 >= q) {             ok = 1;             cout <<  Yes                   <<   n ;             cout << y <<     << x <<   n ;             for (long long j = mid + 1; j <= n; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             for (long long j = i; j <= mid; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             return 0;           }           if (p <= lo1)             hi = mid - 1;           else             lo = mid + 1;         }       }       if (!ok)         cout <<  No               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int MX = 1e6 + 23;   const long long MOD = 998244353;   int read() {     char k = getchar();     int x = 0;     while (k <  0  || k >  9 ) k = getchar();     while (k >=  0  && k <=  9 ) x = x * 10 + k -  0 , k = getchar();     return x;   }   int n, m, c[MX], w[MX];   int a[MX], b[MX];   struct Choice {     int w, id;     bool operator<(const Choice &B) const { return w > B.w; }   };   int cho[MX];   void solve() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) {       c[i] = read();       a[i] = c[i] / 100;       b[i] = c[i] % 100;       if (!b[i]) cho[i] = 1;     }     long long ans = 0;     std::priority_queue<Choice> q;     for (int i = 1; i <= n; ++i) {       w[i] = read();       if (m >= b[i]) {         if (b[i]) {           q.push((Choice){(100 - b[i]) * w[i], i});         }       } else {         if (!q.empty() && q.top().w <= (100 - b[i]) * w[i]) {           ans += q.top().w;           q.pop();           q.push((Choice){(100 - b[i]) * w[i], i});         } else {           ans += (100 - b[i]) * w[i];         }         m += 100;       }       m -= b[i];     }     printf( %lld n , ans);     while (!q.empty()) {       cho[q.top().id] = 1;       q.pop();     }     for (int i = 1; i <= n; ++i) {       if (cho[i]) {         printf( %d %d n , a[i], b[i]);       } else         printf( %d %d n , a[i] + 1, 0);     }   }   int main() {     int T = 1;     for (int i = 1; i <= T; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, j = 1;     string x;     cin >> n >> x;     for (int i = 1; i <= n; i += j) {       cout << x[i - 1];       j++;     }     return 0;   }


#include <bits/stdc++.h>   int Flag, sum, flag[105], n, m, a, b, A[105], map[105][105];   void dfs(int last_last, int last) {     int S;     flag[last] = 1;     for (int i = 1; i <= n; i++) {       if (!map[last][i]) continue;       if (map[i][last_last]) {         S = A[i] + A[last] + A[last_last];         if (S < sum) sum = S;       }       if (!flag[i]) dfs(last, i);     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(flag, 0, sizeof(flag));       memset(map, 0, sizeof(map));       for (int i = 1; i <= n; i++) scanf( %d , &A[i]);       for (int i = 1; i <= m; i++) {         scanf( %d%d , &a, &b);         map[a][b] = 1;         map[b][a] = 1;       }       Flag = 0;       sum = 99999999;       dfs(0, 1);       if (sum == 99999999)         printf( -1 n );       else         printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int vs, ve;     int t, d;     cin >> vs >> ve >> t >> d;     int cur = vs;     int sm = vs;     int pre = vs;     for (int i = 2; i <= t; i++) {       while (cur < ve && abs(pre - cur) < d) cur++;       if (cur >= ve) {         while ((t - i) * d > cur - ve && abs(pre - cur) < d) cur++;         while ((t - i) * d < cur - ve && abs(pre - cur) < d) cur--;       }       pre = cur;       sm += cur;     }     assert(cur == ve);     cout << sm;     return 0;   }


#include <bits/stdc++.h>   struct count_seg {     struct node {       std::array<int, 2> c;       bool flip = false;     };     std::vector<node> seg;     count_seg() : seg() {}     explicit count_seg(int N) : seg(2 * N) {}     std::array<int, 2> query_all() { return seg[1].c; }     void update_node(int a) {       int N = int(seg.size()) >> 1;       if (a >= N) {         seg[a].c[0] = 0, seg[a].c[1] = 1;       } else {         seg[a].c[0] = seg[2 * a].c[0] + seg[2 * a + 1].c[0];         seg[a].c[1] = seg[2 * a].c[1] + seg[2 * a + 1].c[1];       }       if (seg[a].flip) std::swap(seg[a].c[0], seg[a].c[1]);     }     void flip_node(int a) {       seg[a].flip ^= 1;       std::swap(seg[a].c[0], seg[a].c[1]);     }     void flip_leaf_lazy(int l) {       int N = int(seg.size()) >> 1;       seg[N + l].flip ^= 1;     }     void flip_range(int l, int r) {       int N = int(seg.size()) >> 1;       for (int a = l + N, b = r + N; a < b; a >>= 1, b >>= 1) {         if (a & 1) flip_node(a++);         if (b & 1) flip_node(--b);       }       for (int a = l + N; a; a >>= 1) update_node(a);       for (int b = r + N - 1; b; b >>= 1) update_node(b);     }     void update_all() {       for (int i = int(seg.size()) - 1; i; --i) update_node(i);     }   };   struct big_seg {     struct mat {       std::array<std::array<std::array<int, 2>, 2>, 2> v;       friend mat operator*(const mat& a, const mat& b) {         mat res;         for (int i = 0; i < 2; i++) {           for (int j = 0; j < 2; j++) {             for (int z = 0; z < 2; z++) {               res.v[i][j][z] = std::min(a.v[i][j][0] + b.v[i][j][z],                                         a.v[i][j][1] + b.v[!i][!j][!z]);             }           }         }         return res;       }       int eval(std::array<int, 2> st, std::array<int, 2> en) const {         int res = st[0] + v[0][0][0] + en[0];         for (int i = 0; i < 2; i++) {           for (int j = 0; j < 2; j++) {             res = std::min(res, st[i] + v[i][i][i ^ j] + en[j]);           }         }         return res;       }     };     struct node {       mat m;       std::array<bool, 2> flip = {false, false};     };     int N, M;     std::vector<node> seg;     big_seg() : N(0), seg() {}     big_seg(int N_, int M_) : N(N_), M(M_), seg() {       int S = 1;       while (S < N) S *= 2;       seg.resize(2 * S);     }     mat query_all() { return seg[1].m; }     void update_node(int a) {       int S = int(seg.size()) >> 1;       if (a >= S) {         if (a - S < N) {           for (int i = 0; i < 2; i++) {             for (int j = 0; j < 2; j++) {               seg[a].m.v[i][j][0] = i + j;               seg[a].m.v[i][j][1] = i + j + M;             }           }         } else {           for (int i = 0; i < 2; i++) {             for (int j = 0; j < 2; j++) {               seg[a].m.v[i][j][0] = 0;               seg[a].m.v[i][j][1] = 0 + M;             }           }         }       } else {         seg[a].m = seg[2 * a].m * seg[2 * a + 1].m;       }       if (seg[a].flip[0]) {         swap(seg[a].m.v[0], seg[a].m.v[1]);       }       if (seg[a].flip[1]) {         swap(seg[a].m.v[0][0], seg[a].m.v[0][1]);         swap(seg[a].m.v[1][0], seg[a].m.v[1][1]);       }     }     void flip_node(int a, bool z) {       seg[a].flip[z] ^= 1;       if (z == 0) {         swap(seg[a].m.v[0], seg[a].m.v[1]);       } else if (z == 1) {         swap(seg[a].m.v[0][0], seg[a].m.v[0][1]);         swap(seg[a].m.v[1][0], seg[a].m.v[1][1]);       } else         assert(false);     }     void flip_leaf_lazy(int l, bool z) {       int S = int(seg.size()) >> 1;       seg[S + l].flip[z] ^= 1;     }     void flip_range(int l, int r, bool z) {       int S = int(seg.size()) >> 1;       for (int a = l + S, b = r + S; a < b; a >>= 1, b >>= 1) {         if (a & 1) flip_node(a++, z);         if (b & 1) flip_node(--b, z);       }       for (int a = l + S; a; a >>= 1) update_node(a);       for (int b = r + S - 1; b; b >>= 1) update_node(b);     }     void update_all() {       for (int i = int(seg.size()) - 1; i; --i) update_node(i);     }   };   int main() {     using namespace std;     ios_base::sync_with_stdio(false), cin.tie(nullptr);     array<int, 2> N;     int Q;     cin >> N[0] >> N[1] >> Q;     array<array<count_seg, 2>, 2> count_segs;     array<big_seg, 2> big_segs;     for (int a = 0; a < 2; a++) {       big_segs[a] = big_seg(N[a], N[!a]);       for (int b = 0; b < 2; b++) {         count_segs[a][b] = count_seg(N[a]);         string S;         cin >> S;         assert(int(S.size()) == N[a]);         for (int i = 0; i < N[a]; i++) {           if (S[i] ==  R ) {             count_segs[a][b].flip_leaf_lazy(i);             big_segs[a].flip_leaf_lazy(i, b);           }         }         count_segs[a][b].update_all();       }       big_segs[a].update_all();     }     auto query = [&]() -> int {       int ans = 2 * N[0] + 2 * N[1];       for (int z = 0; z < 2; z++) {         int cnd = big_segs[!z].query_all().eval(count_segs[z][0].query_all(),                                                 count_segs[z][1].query_all());         ans = min(ans, cnd);       }       return ans;     };     cout << query() <<   n ;     for (int q = 0; q < Q; q++) {       char side;       int l, r;       cin >> side >> l >> r;       l--;       bool dim, z;       switch (side) {         case  L :           dim = 0, z = 0;           break;         case  R :           dim = 0, z = 1;           break;         case  U :           dim = 1, z = 0;           break;         case  D :           dim = 1, z = 1;           break;         default:           assert(false);       }       assert(0 <= l && l < r && r <= N[dim]);       count_segs[dim][z].flip_range(l, r);       big_segs[dim].flip_range(l, r, z);       cout << query() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tree[4 * 100100];   long long a[100100];   int n;   void build(int from, int to, int node) {     if (from == to) {       tree[node] = a[from];       return;     }     int mid = (from + to) / 2;     build(from, mid, 2 * node);     build(mid + 1, to, 2 * node + 1);     tree[node] = max(tree[2 * node], tree[2 * node + 1]);   }   long long val;   void update(int from, int to, int node) {     if (from == to) {       tree[node] = val;       return;     }     int mid = (from + to) / 2;     update(from, mid, 2 * node);     tree[node] = max(tree[2 * node], tree[2 * node + 1]);   }   long long query(int from, int to, int node, int low, int high) {     if (low > to || from > high) {       return 0;     }     if (from >= low && to <= high) {       return tree[node];     }     int mid = (from + to) / 2;     return max(query(from, mid, 2 * node, low, high),                query(mid + 1, high, 2 * node + 1, low, high));   }   long long b[100100];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     b[0] = a[0];     b[1] = a[1];     for (int i = 2; i < n; i++) {       b[i] = max(b[i - 1], a[i]);     }     int Q;     scanf( %d , &Q);     while (Q--) {       long long w, h;       cin >> w >> h;       cout << max(b[0], b[w - 1]) << endl;       b[0] = (max(b[0], b[w - 1]) + h);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct gam {     int o;     long long k;     int nez;     long long bd;     long long kd;     gam() {       o = 0;       k = 0;       nez = 0;       bd = 0;       kd = 0;     }   };   bool mycomp(gam i, gam j) { return (i.k < j.k); }   int main() {     long long n;     long long r;     long long tr;     long long sum = 0;     cin >> n;     cin >> r;     cin >> tr;     gam* a = new gam[n + 1];     a[0].k = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i].o;       cin >> a[i].k;       a[i].nez = r - a[i].o;       sum = sum + a[i].o;     }     sort(a + 1, a + n + 1, mycomp);     long long nug = tr * n - sum;     if (nug > 0) {       int cur;       for (int i = 1; i <= n; i++) {         a[i].bd = a[i - 1].bd + a[i].nez;         a[i].kd = a[i - 1].kd + a[i].k * a[i].nez;         if (a[i].bd >= nug) {           cur = i;           break;         }       }       long long enug = nug - a[cur - 1].bd;       long long rez = a[cur - 1].kd + enug * a[cur].k;       cout << rez;     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename X>   inline X abs(const X& a) {     return a < 0 ? -a : a;   }   template <typename X>   inline X sqr(const X& a) {     return a * a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     double first = (sqrt(8.0 * n + 1) - 1) / 2;     int out = (first - floor(first)) * (first + 1);     if (out == 0)       cout << (int)first;     else       cout << out;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   int a[maxn];   long long n, k;   bool ok(long long d) {     long long ret = 0;     for (int i = 0; i < n; ++i) {       ret += (a[i] - 1 + d) / d;     }     return ret * d <= k;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> a[i], k += a[i];     long long ans = 0;     for (long long i = 1; i <= sqrt(k) + 1; ++i) {       if (ok(i)) ans = max(ans, i);       if (ok(k / i)) ans = max(ans, k / i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   struct P {     double x, y;     P() {}     P(double x, double y) : x(x), y(y) {}     P operator+(const P &a) const { return P(x + a.x, y + a.y); }     P operator-(const P &a) const { return P(x - a.x, y - a.y); }     double operator^(const P &a) const { return x * a.x + y * a.y; }     void in() { scanf( %lf%lf , &x, &y); }     void out() { printf( REQUIRED %.7f %.7f n , x, y); }     double dist(P a, P b) {       return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));     }     double sqdist(P a, P b) {       return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);     }   };   int n, k;   int a[9999];   int b[9999];   int cc[9999];   int bb[9999];   long long res = -100000000;   long long ma[9999];   long long query(long long l, long long r) {     int length = r - l + 1;     if (length <= k) return ma[length];     int cnt = 0;     for (int i = (1); i <= (n); i++) {       if ((i < l) || (i > r)) cc[++cnt] = a[i];     }     int cnt2 = 0;     for (int i = (l); i <= (r); i++) bb[++cnt2] = a[i];     sort(cc + 1, cc + cnt + 1);     sort(bb + 1, bb + cnt2 + 1);     int go = 0;     for (int i = (1); i <= (min(min(cnt, cnt2), k)); i++) {       if (cc[cnt - i + 1] > bb[i]) go = i;     }     for (int i = (1); i <= (go); i++) bb[i] = cc[cnt - i + 1];     long long sum = 0;     for (int i = (1); i <= (cnt2); i++) sum += bb[i];     return sum;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n); i++) b[i] = a[i];     sort(b + 1, b + n + 1);     ma[0] = 0;     for (int i = (n); i >= (1); i--) {       ma[n - i + 1] = ma[n - i] + b[i];     }     for (int i = (1); i <= (n); i++) {       for (int j = (i); j <= (n); j++) {         res = max(res, query(i, j));       }     }     printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void DFS(int s);   vector<int> v[60];   int d = 0;   int c[200];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i <= 50; i++) v[i].clear();     memset(c, 0, sizeof(c));     for (int i = 1; i <= m; i++) {       int u, vv;       scanf( %d %d , &u, &vv);       v[u].push_back(vv);       v[vv].push_back(u);     }     int mx = 0;     for (int i = 1; i <= n; i++) {       if (c[i] == 0) {         d = 0;         DFS(i);         mx = mx + d - 1;       }     }     printf( %I64d n , (long long)pow(2, mx));     return 0;   }   void DFS(int s) {     d++;     c[s] = 1;     int sz = v[s].size();     for (int i = 0; i < sz; i++) {       int x = v[s][i];       if (c[x] == 0) {         DFS(x);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e9 + 7;   bool compare(const pair<long long, long long> &a,                const pair<long long, long long> &b) {     return a.first > b.first || (a.first == b.first && a.second < b.second);   }   long long inline power(long long a, long long b, long long p) {     a %= p;     long long ans = 1;     while (b > 0) {       if (b & 1) ans = (ans * a) % p;       a = (a * a) % p;       b >>= 1;     }     return ans;   }   long long inv(long long n, long long p) { return power(n, p - 2, p); }   bool inline isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   template <class T>   void printv(T &v, long long n) {     if (n == -1) n = v.size();     for (long long i = 0; i < n; i++) cout << v[i] <<    ;     cout <<   n ;   }   const long long maxn = 2e5 + 5;   vector<long long> parent(maxn, 0);   vector<vector<long long> > v;   long long start;   vector<long long> pos(maxn);   vector<pair<long long, long long> > gap(maxn);   void dfs(long long node) {     start++;     pos[start] = node;     gap[node].first = start;     for (auto &x : v[node]) {       if (x == parent[node]) continue;       dfs(x);     }     gap[node].second = start;   }   void solve() {     long long n, q, u, k;     cin >> n >> q;     start = 0;     v.assign(n + 1, vector<long long>());     for (long long i = 1; i <= n - 1; i++) {       cin >> parent[i + 1];       v[i + 1].push_back(parent[i + 1]);       v[parent[i + 1]].push_back(i + 1);     }     for (auto &x : v) sort(x.begin(), x.end());     dfs(1);     for (long long i = 1; i <= q; i++) {       cin >> u >> k;       if (gap[u].second - gap[u].first + 1 < k) {         cout << -1 <<   n ;         continue;       }       cout << pos[((gap[u].first) + k - 1)] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 2e5 + 10;   const long long INF = 0x3f3f3f3f;   const long long mod = 998244353;   int mans = INF;   int n, c, dp[M][2], f[M], l[M];   int main() {     scanf( %d%d , &n, &c);     memset(dp, INF, sizeof(dp));     for (int i = 1; i < n; i++) scanf( %d , &f[i]);     for (int i = 1; i < n; i++) scanf( %d , &l[i]);     dp[0][0] = c;     dp[0][1] = 0;     for (int i = 1; i < n; i++) {       dp[i][0] = min(dp[i - 1][0], dp[i - 1][1] + c) + l[i];       dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + f[i];     }     for (int i = 0; i < n; i++) printf( %d  , min(dp[i][0], dp[i][1]));     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const long long INF = (long long)1e18;   int n;   long long a[11], val[11];   long long dp[1 << 8][1 << 8];   int lastBit[1 << 8];   long long del[11][1 << 8];   long long get(long long v) {     long long i = 2;     long long res = 0;     while (i * i <= v) {       while (v % i == 0) {         res++;         v /= i;       }       i++;     }     if (v > 1) {       res++;     }     return res;   }   long long dfs(int mask1, int mask2) {     if (mask1 == 0 && mask2 == 0) return 0;     if (mask2 == 0 && mask1 != 0) return INF;     long long &res = dp[mask1][mask2];     if (res != -1) return res;     res = INF;     int last = lastBit[mask2];     for (int sub = mask1;; sub = (sub - 1) & mask1) {       if (del[last][sub] != -1) {         res = min(res, dfs(mask1 ^ sub, mask2 ^ (1 << last) ^ sub) + 1 +                            (sub == 0 ? val[last] : del[last][sub]));       }       if (sub == 0) break;     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       val[i] = get(a[i]);       if (val[i] == 1) val[i] = 0;     }     for (int mask = 0; mask < (1 << n); mask++) {       int last = -1;       for (int i = 0; i < n; i++)         if (mask & (1 << i)) {           last = i;         }       lastBit[mask] = last;     }     for (int i = 0; i < n; i++) {       for (int mask = 0; mask < (1 << n); mask++) {         long long v = a[i];         for (int j = 0; j < n; j++)           if (mask & (1 << j)) {             if (v % a[j] != 0) {               v = -1;               break;             } else {               v /= a[j];             }           }         del[i][mask] = v == -1 ? -1 : get(v);       }     }     memset(dp, -1, sizeof(dp));     long long res = INF;     for (int mask = 1; mask < (1 << n); mask++) {       res = min(res, dfs(((1 << n) - 1) ^ mask, mask) +                          (__builtin_popcountll(mask) == 1 ? 0 : 1));     }     cout << res << endl;     return 0;   }


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


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


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n;   int a[10001], c[10001], d[10001];   int ans = 0;   char str[101];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , str);       if (str[0] ==  M ) a[i] = 1;       scanf( %d %d , &c[i], &d[i]);     }     for (int i = 1; i <= 366; i++) {       int x = 0, y = 0;       for (int j = 1; j <= n; j++) {         if (c[j] <= i && i <= d[j]) {           if (a[j])             ++x;           else             ++y;         }       }       ans = max(ans, min(x, y));     }     printf( %d n , ans * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   string direc =  URDL ;   const long long MOD2 = (long long)1000000007 * (long long)1000000007;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   vector<int> mp[44];   int col[44];   int C, I;   bool bip = 1;   void dfs(int x, int color) {     col[x] = color;     for (int c : mp[x])       if (col[c] == 0)         dfs(c, 3 - color);       else if (col[c] != 3 - color)         bip = 0;   }   long long dp[(1 << 20) + 5], rdp[(1 << 20) + 5];   int to[44];   long long cal() {     if (n == 1) return 2;     int ln = n / 2, rn = n - ln;     for (int(i) = 0; (i) < (int)(1 << ln); (i)++) dp[i] = 1;     for (int(i) = 1; (i) <= (int)(ln); (i)++)       for (int j : mp[i])         if (j <= ln) {           dp[(1 << (i - 1)) | (1 << (j - 1))] = 0;         }     for (int s = 1; s < 1 << ln; s++) {       for (int(j) = 0; (j) < (int)(ln); (j)++)         if (s & (1 << j)) {           if (dp[s ^ (1 << j)] == 0) {             dp[s] = 0;             break;           }         }     }     int msk = (1 << ln) - 1;     for (int(i) = 0; (i) < (int)(1 << ln); (i)++) rdp[i] = dp[i ^ msk];     for (int j = 0; j < ln; j++) {       for (int i = msk; i >= 0; i--) {         if (~i & (1 << j)) {           rdp[i] += rdp[i ^ (1 << j)];         }       }     }     for (int(i) = 0; (i) < (int)(1 << rn); (i)++) dp[i] = 1;     for (int i = ln + 1; i <= n; i++)       for (int j : mp[i])         if (j > ln) {           dp[(1 << (i - ln - 1)) | (1 << (j - ln - 1))] = 0;         } else {           to[i - ln - 1] |= 1 << (j - 1);         }     for (int s = 1; s < 1 << rn; s++) {       for (int(j) = 0; (j) < (int)(rn); (j)++)         if (s & (1 << j)) {           if (dp[s ^ (1 << j)] == 0) {             dp[s] = 0;             break;           }         }     }     long long ans = 0;     for (int(i) = 0; (i) < (int)(1 << rn); (i)++)       if (dp[i]) {         int s = 0;         for (int(j) = 0; (j) < (int)(rn); (j)++)           if (i & (1 << j)) s |= to[j];         ans += rdp[s];       }     return ans;   }   void fmain(int tid) {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       mp[u].push_back(v);       mp[v].push_back(u);     };     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (col[i] == 0) {         dfs(i, 1);         C++;       }     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (mp[i].empty()) I++;     long long all = 1LL << n;     all -= 1LL << C;     all += 1LL << I;     if (bip) all += 1LL << C;     all += 1LL << I;     all -= m == 0 ? 1LL << n : 0;     all -= cal() * 2;     printf( %lld n , all);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, x;   long long inp[200005];   long long precom[64][2];   long long num;   long long ans;   int main() {     cin >> n >> k >> x;     long long i, j, kl;     for (i = 0; i < n; ++i) {       scanf( %lld , &inp[i]);       for (j = 0; j < 63; ++j) {         if (((long long)1 << j) & inp[i]) precom[j][0]++;       }     }     long long pos = 0;     long long ans, tmpans;     ans = 0;     for (j = 0; j < n; ++j) {       num = inp[j];       for (i = 0; i < k; ++i) {         num *= x;       }       for (kl = 0; kl < 64; ++kl) {         precom[kl][1] = 0;         if ((num & ((long long)1 << kl)) && !(inp[j] & ((long long)1 << kl))) {           precom[kl][1] = 1;         }         if (!(num & ((long long)1 << kl)) && (inp[j] & ((long long)1 << kl)))           precom[kl][1] = -1;       }       tmpans = 0;       for (kl = 0; kl < 64; ++kl) {         if (precom[kl][0] + precom[kl][1]) tmpans += ((long long)1 << kl);       }       if (tmpans > ans) {         ans = tmpans;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 3e5 + 5;   long long n, x1, x2;   array<long long, 2> c[nax];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> x1 >> x2;     for (int i = 0; i < n; i++) cin >> c[i][0], c[i][1] = i;     sort(c, c + n);     for (int rep = 0; rep < 2; rep++) {       int best = n - 1;       for (; ~best; --best)         if (c[best][0] >= (x2 + n - best - 1) / (n - best)) break;       if (best == -1) continue;       for (int k = 1; k < n; k++) {         int j = lower_bound(c, c + n, array<long long, 2>{(x1 + k - 1) / k}) - c;         if (j + k - 1 >= best) continue;         cout <<  Yes n ;         if (rep == 0) {           cout << k <<     << n - best <<   n ;           for (int i = j; i < j + k; i++) cout << c[i][1] + 1 <<    ;           cout <<   n ;           for (int i = best; i < n; i++) cout << c[i][1] + 1 <<    ;           cout <<   n ;         } else {           cout << n - best <<     << k <<   n ;           for (int i = best; i < n; i++) cout << c[i][1] + 1 <<    ;           cout <<   n ;           for (int i = j; i < j + k; i++) cout << c[i][1] + 1 <<    ;           cout <<   n ;         }         exit(0);       }       swap(x1, x2);     }     cout <<  No n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int a[1000007];   int st[1000007];   int en[1000007];   vector<pair<int, int> > v_st[1000007];   long long ans[1000007];   class Tree {    public:     pair<long long, int> tr[6 * 1000007];     void init(int where, int IL, int IR) {       tr[where] = {0, 0};       if (IL == IR) {         return;       }       int mid = (IL + IR) / 2;       init(2 * where, IL, mid);       init(2 * where + 1, mid + 1, IR);     }     void update(int where, int IL, int IR, int CURL, int CURR,                 pair<long long, int> add) {       if (CURR < CURL) {         return;       }       if (IR < CURL || CURR < IL) {         return;       }       if (CURL <= IL && IR <= CURR) {         tr[where].first += add.first, tr[where].second += add.second;         return;       }       int mid = (IL + IR) / 2;       update(2 * where, IL, mid, CURL, CURR, add);       update(2 * where + 1, mid + 1, IR, CURL, CURR, add);     }     pair<long long, int> query(int where, int IL, int IR, int pos) {       if (IR < pos || pos < IL) {         return {0, 0};       }       if (IL == IR) {         return tr[where];       }       int mid = (IL + IR) / 2;       pair<long long, int> ret;       if (pos <= mid) {         ret = query(2 * where, IL, mid, pos);       } else {         ret = query(2 * where + 1, mid + 1, IR, pos);       }       ret = {ret.first + tr[where].first, ret.second + tr[where].second};       return ret;     }   };   Tree w;   void input() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= q; ++i) {       scanf( %d , &st[i]);     }     for (int i = 1; i <= q; ++i) {       scanf( %d , &en[i]);       v_st[en[i]].push_back({st[i], i});     }   }   void calc() {     stack<int> st;     a[0] = n + 1;     st.push(0);     w.init(1, 1, n);     for (int i = 1; i <= n; ++i) {       while (a[st.top()] < a[i]) {         st.pop();       }       w.update(1, 1, n, 1, st.top(), {i - st.top() - 1, 0});       w.update(1, 1, n, st.top() + 1, i, {i, 1});       st.push(i);       int sz = v_st[i].size();       for (int j = 0; j < sz; ++j) {         pair<long long, int> ret = w.query(1, 1, n, v_st[i][j].first);         ans[v_st[i][j].second] += ret.first - 1LL * ret.second * v_st[i][j].first;       }     }   }   void solve() {     calc();     for (int i = 1; i <= (n >> 1); ++i) {       swap(a[i], a[n - i + 1]);     }     for (int i = 1; i <= n; ++i) {       v_st[i].clear();     }     for (int i = 1; i <= q; ++i) {       st[i] = (n - st[i] + 1);       en[i] = (n - en[i] + 1);       swap(st[i], en[i]);       v_st[en[i]].push_back({st[i], i});     }     calc();     for (int i = 1; i <= q; ++i) {       printf( %I64d  , ans[i] + (en[i] - st[i] + 1));     }     printf(  n );   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 100005;   int a[maxn], b[maxn];   int main() {     long long d, k, a, b, t;     scanf( %I64d%I64d%I64d%I64d%I64d , &d, &k, &a, &b, &t);     if (d < k) {       printf( %I64d n , d * a);       return 0;     }     d -= k;     long long ans = k * a;     long long k1 = k * a + t, k2 = k * b;     if (k1 >= k2) {       ans += d * b;     } else {       ans += d / k * k1;       d %= k;       ans += min(t + d * a, d * b);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e9 + 10, MAX = 2100, MOD = 1e9 + 7, MAXL = 25;   void OUT(long double o, int x) {     cout << fixed << setprecision(x) << o;     return;   }   long long dp[MAX][MAX], ra[MAX], a[MAX], re[200000], w[MAX];   vector<int> v[MAX];   pair<long long, long long> c[MAX];   set<int> st;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, t;     cin >> n >> m >> t;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       for (int j = l + 1; j <= r; j++) ra[j] = 1;     }     for (int i = 1; i <= t; i++) {       cin >> c[i].first >> c[i].second;       st.insert(c[i].second);     }     int cnt = 0;     for (int i = 1; i <= 2000; i++) w[i] = INF;     for (int u : st) {       re[u] = ++cnt;       w[cnt] = u;     }     for (int i = 1; i <= t; i++) v[c[i].first].push_back(re[c[i].second]);     for (int i = 1; i <= 2000; i++) dp[0][i] = INF;     for (int u : v[0]) dp[0][u] = 0;     for (int i = 1; i <= n; i++) {       long long mi = INF;       for (int j = 1; j <= 2000; j++) mi = min(mi, dp[i - 1][j] + w[j]);       if (!ra[i]) mi = min(mi, dp[i - 1][0]);       dp[i][0] = mi;       for (int j = 1; j <= 2000; j++) dp[i][j] = dp[i - 1][j] + w[j];       for (int u : v[i]) dp[i][u] = min(dp[i][u], mi);     }     long long ans = INF;     for (int i = 0; i <= 2000; i++) ans = min(ans, dp[n][i]);     if (ans < INF)       cout << ans;     else       cout << -1;     return 0;   }


#include<bits/stdc++.h>    using namespace std;   namespace Ruri{       #define ms(a,b) memset(a,b,sizeof(a))       #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?       #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)       #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)       #define ce(i,r) i==r?  n :          #define pb push_back        #define all(x) x.begin(),x.end()       #define gmn(a,b) a=min(a,b)       #define gmx(a,b) a=max(a,b)       #define fi first       #define se second                                typedef long long ll;       typedef unsigned long long ull;       typedef double db;       const int infi=1e9;//infi较大，注意涉及inf相加时爆int       const ll infl=4e18;       inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }       inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }       //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));   }   using namespace Ruri;   namespace Read{       #define ss(a) scanf( %s ,a)       inline int ri(){ int x; scanf( %d ,&x); return x; }       inline ll rl(){ ll x;  scanf( %lld ,&x); return x; }       inline db rd(){ db x; scanf( %lf ,&x); return x; }   }   namespace DeBug{       #define pr(x) cout<<#x<< :  <<(x)<<endl       #define pra(x,a,b) cout<<#x<< :  <<endl;                repi(i,a,b) cout<<x[i]<<   ;                    puts(  );          #define FR(a) freopen(a, r ,stdin)       #define FO(a) freopen(a, w ,stdout)   }   using namespace Read;   using namespace DeBug;   const int MAX_N=105;   const int mod=1e9+7;   inline void Add(int &x,int y){ x+=y;if(x>=mod) x-=mod; }   int n,b[MAX_N],c[MAX_N];   int sb[MAX_N];   int f[MAX_N*MAX_N],g[MAX_N*MAX_N];   map<int,int> ans;   int Solve(int x)   {    repi(i,0,10001) g[i]=1;    repi(i,1,n){     int lim=i*x+sb[i];     ms(f,0);     for(int j=max(0,lim);j<=10001;++j) f[j]=(g[j]-(j-c[i]-1>=0?g[j-c[i]-1]:0)+mod)%mod;     ms(g,0),g[0]=f[0];     for(int j=1;j<=10001;++j) g[j]=(1ll*g[j-1]+f[j])%mod;    }    return g[10001];   }   int main()   {    n=ri();    int prod=1;    repi(i,1,n) c[i]=ri(),prod=1ll*prod*(c[i]+1)%mod;    repi(i,1,n-1) b[i]=ri();    repi(i,1,n)repi(j,1,i-1) sb[i]+=(i-j)*b[j];    int l=0,r=infi,mx_c=*max_element(c+1,c+n+1);    repi(i,1,n) gmn(l,-((sb[i]-1)/i+1)),gmn(r,(n*mx_c-sb[i]-1)/i+1);    repi(i,l,r) ans[i]=Solve(i);    int Q=ri();    while(Q--)    {     int x=ri();     if(x>r) puts( 0 );     else if(x<l) printf( %d n ,prod);     else printf( %d n ,ans[x]);    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int blk_size;   struct node {     int l, r, id;     long long int ans = 0;   };   bool compare(node a, node b) {     if (a.l / blk_size != b.l / blk_size)       return (a.l) / blk_size < (b.l) / blk_size;     return a.r < b.r;   }   bool compare2(node a, node b) { return a.id < b.id; }   long long int freq[3000001];   int main() {     ios_base::sync_with_stdio(false);     ;     int n, m, k;     cin >> n >> m >> k;     std::vector<int> a(n), pxor(n + 1);     for (int i = 0; i < n; i++) cin >> a[i];     pxor[0] = 0;     for (int i = 1; i <= n; i++) pxor[i] = pxor[i - 1] ^ a[i - 1];     blk_size = sqrt(n + 1);     std::vector<node> q(m);     for (int i = 0; i < m; i++) {       cin >> q[i].l >> q[i].r;       q[i].id = i;     }     sort(q.begin(), q.end(), compare);     int start = 0, end = 0;     long long int ans = 0;     freq[0] = 1;     for (int i = 0; i < m; i++) {       int l = q[i].l - 1, r = q[i].r;       while (start > l) {         start--;         ans += freq[pxor[start] ^ k];         freq[pxor[start]]++;       }       while (start < l) {         freq[pxor[start]]--;         ans -= freq[pxor[start] ^ k];         start++;       }       while (end > r) {         freq[pxor[end]]--;         ans -= freq[pxor[end] ^ k];         end--;       }       while (end < r) {         end++;         ans += freq[pxor[end] ^ k];         freq[pxor[end]]++;       }       q[i].ans = ans;     }     sort(q.begin(), q.end(), compare2);     for (int i = 0; i < m; i++) cout << q[i].ans <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int nx[1000514 * 2][26], spt;   int fl[1000514 * 2], ll[1000514 * 2], lp[1000514 * 2];   int newnode() {     memset(nx[spt], 0, sizeof(nx[spt]));     fl[spt] = ll[spt] = lp[spt] = 0;     return spt++;   }   int dp[1000514 * 2];   void add(int root, int& last, char A) {     int a = A -  a ;     int p = last;     int np = last = newnode();     ll[np] = ll[p] + 1;     lp[np] = 0;     dp[np] = 1;     for (; p && nx[p][a] == 0; p = fl[p]) nx[p][a] = np;     int q = nx[p][a];     if (p == 0)       fl[np] = root;     else if (ll[q] == ll[p] + 1)       fl[np] = q;     else {       int nq = spt++;       memcpy(nx[nq], nx[q], sizeof(nx[q]));       fl[nq] = fl[q];       ll[nq] = ll[p] + 1;       lp[nq] = lp[q] + ll[q] - 1 - ll[p];       fl[q] = fl[np] = nq;       for (; p && nx[p][a] == q; p = fl[p]) nx[p][a] = nq;     }   }   char s[1000514], r[1000514 * 2];   vector<int> bk[1000514];   int vs[1000514 * 2], vt;   void make_z(int* z, char* s, int l) {     int j = z[0] = 0;     for (int i = 1; i < l; i++) {       z[i] = (i > j + z[j] - 1) ? 0 : min(z[i - j], j + z[j] - i);       for (; i + z[i] < l && s[z[i]] == s[i + z[i]]; z[i]++)         ;       if (i + z[i] > j + z[j]) j = i;     }   }   int z[1000514 * 2];   void sol() {     spt = 1;     int last;     int root = last = newnode();     int sl = 0;     for (; s[sl]; sl++)       ;     for (int i = 0; i < sl; i++) add(root, last, s[i]);     for (int i = 1; i < spt; i++) {       bk[ll[i]].push_back(i);     }     for (int i = sl; i >= 0; i--) {       int sz = (int)bk[i].size();       for (int j = 0; j < sz; j++) {         int w = bk[i][j];         dp[fl[w]] += dp[w];       }     }     int Q;     scanf( %d , &Q);     for (int T = 0; T < Q; T++) {       scanf( %s , r);       int rl = 0;       for (; r[rl]; rl++)         ;       for (int i = 0; i < rl; i++) r[rl + i] = r[i];       r[rl + rl] = 0;       make_z(z, r, rl * 2);       int t = 0;       for (int i = 1; i <= rl; i++) {         if (rl % i) continue;         int flag = 0;         for (int j = i; j < rl; j += i) {           if (z[j] < i) {             flag = 1;           }         }         if (flag) continue;         t = i;         break;       }       int p = root;       int l = 0;       for (int i = 0; i < rl; i++) {         int a = r[i] -  a ;         for (; p && nx[p][a] == 0; p = fl[p])           ;         if (p == 0) {           l = 0;           p = root;         } else {           l = min(l, ll[p]) + 1;           p = nx[p][a];         }       }       vt++;       int ans = 0;       if (l >= rl && vs[p] != vt) {         vs[p] = vt;         ans += dp[p];       }       for (int i = 0; i < t - 1; i++) {         int a = r[i] -  a ;         for (; p && nx[p][a] == 0; p = fl[p])           ;         if (p == 0) {           l = 0;           p = root;         } else {           l = min(l, ll[p]) + 1;           p = nx[p][a];         }         for (; p && ll[fl[p]] >= rl; p = fl[p])           ;         l = min(l, ll[p]);         if (l >= rl && vs[p] != vt) {           vs[p] = vt;           ans += dp[p];         }       }       printf( %d n , (int)ans);     }   }   int main() {     scanf( %s , s);     sol();   }


#include <bits/stdc++.h>   using namespace std;   bool flag = 0;   void dfs(int u, vector<vector<int> > &g, vector<int> &mark, string &order) {     mark[u] = 1;     for (auto to : g[u]) {       if (mark[to] == 1)         flag = 1;       else if (mark[to] == 0)         dfs(to, g, mark, order);     }     order.push_back( a  + u);     mark[u] = 2;   }   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<vector<int> > g(26);     for (int i = 0; i < n - 1; i++) {       int size = min((int((a[i]).size())), (int((a[i + 1]).size()))), j;       for (j = 0; j < size; j++)         if (a[i][j] != a[i + 1][j]) break;       if (j < size)         g[a[i][j] -  a ].push_back(a[i + 1][j] -  a );       else if ((int((a[i]).size())) > (int((a[i + 1]).size())))         flag = 1;     }     vector<int> mark(26);     string order;     for (int i = 0; i < 26; i++)       if (mark[i] == 0) dfs(i, g, mark, order);     if (flag) {       cout <<  Impossible n ;     } else {       reverse(order.begin(), order.end());       cout << order <<   n ;     }     return 0;   }