#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long n, m;   string p, s;   vector<int> pos;   long long exp(long long a, long long x) {     if (x == 0) return 1;     long long tmp = exp(a, x / 2);     tmp *= tmp;     tmp %= MOD;     if (x % 2) tmp *= a;     tmp %= MOD;     return tmp;   }   bool z(string str) {     int n = (int)str.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && str[z[i]] == str[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     for (int i = 0; i < pos.size(); ++i) {       if (z[pos[i] + p.size() + 1] != p.size()) return false;     }     return true;   }   int main() {     cin >> n >> m >> p;     pos.assign(m, 0);     for (int i = 0; i < m; ++i) {       cin >> pos[i];       pos[i]--;     }     sort(pos.begin(), pos.end());     for (int i = 0; i < m; ++i) {       while (s.size() < pos[i]) s +=  . ;       int stp = s.size();       for (int j = stp - pos[i]; j < p.size(); ++j) {         s += p[j];       }     }     while (s.size() < n) s +=  . ;     s = p +  #  + s;     if (z(s)) {       int cnt = 0;       for (auto i : s) cnt += i ==  . ;       cout << exp(26, cnt);     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   long long INF = 1000000000000000005ll;   double PI = acos(-1);   inline string IntToString(long long int a) {     char x[100];     sprintf(x,  %lld , a);     string s = x;     return s;   }   inline long long int StringToInt(string a) {     char x[100];     long long int res;     strcpy(x, a.c_str());     sscanf(x,  %lld , &res);     return res;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (long long int i = 0; i < n; i++)       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (long long int i = 0; i < n; i++)       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) {     return v1[0] > v2[0];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t-- > 0) {       long long int n;       cin >> n;       n *= 2;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       cout << a[n / 2] - a[n / 2 - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, i, j, k, l, t;     cin >> t;     while (t--) {       cin >> n;       vector<int> a(n);       for (i = 0; i < n; i++) {         cin >> a[i];       }       k = 1;       long long total = 0;       for (i = 0; i < n; i++) {         if (k % 2 != 0) {           total += a[i];           if (a[i + 1] == 0) {             while (i + 1 < n && a[i + 1] == 0) {               i++;             }           }         } else {           if (a[i + 1] == 1) i++;         }         k++;       }       cout << total << endl;     }   }


#include <bits/stdc++.h>   const long long INF = (1e9 + 12312), MOD = 1e9 + 7;   const long double EPS = 0.0000000001;   using namespace std;   bool ask(long long first, long long second) {     cout << first <<     << second << endl;     string s;     cin >> s;     if (s ==  Bad ) {       exit(1);     }     return s ==  Yes ;   }   signed main() {     ios_base::sync_with_stdio(false);     srand(time(0));     long long n, k;     cin >> n >> k;     long long now = 0;     long long first = 1, second = n;     long long lastl = 1, lastr = n;     for (int i = 0; i < 4500; i++) {       if (now >= 7) {         first = max(lastl - 8 * k, 1LL);         second = min(lastr + 8 * k, n);         lastl = -1;         now = 0;       }       long long askl = first, askr = second;       if (second - first == 0) {         if (ask(first, first)) {           return 0;         }         first = 1, second = n;         continue;       }       if (second - first + 1 <= 50) {         if (lastl == -1) {           lastr = second;           lastl = first;         }         now++;         long long askl = first + rand() % (second - first + 1);         if (ask(askl, askl)) {           return 0;         }         continue;       } else {         now = 0;         lastl = -1;         lastr = -1;         if (rand() % 2) {           askl = first + (second - first + 1) / 2;         } else {           askr = second - (second - first + 1) / 2;         }       }       if (ask(askl, askr)) {         first = max(askl - k, 1LL);         second = min(askr + k, n);       } else {         if (askl != first) {           first -= k;           first = max(first, 1LL);           second = min(askl + k, n);         } else {           first = max(askr - k, 1LL);           second += k;           second = min(second, n);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c *x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug &operator<<(const c &) {       return *this;     }   };   long long __pow(long long x, long long y, long long M) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % M;       y >>= 1;       x = (x * x) % M;     }     return res % M;   }   long long __pow(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y >>= 1;       x = (x * x);     }     return res;   }   long long mi(long long x, long long M) { return __pow(x, M - 2, M); }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long add(long long a, long long b, long long M) { return (a + b) % M; }   long long mul(long long a, long long b, long long M) { return (a * b) % M; }   long long sub(long long a, long long b, long long M) { return (a - b + M) % M; }   long long div(long long a, long long b, long long M) {     return (a * mi(b, M)) % M;   }   void umax(long long &a, long long b) { a = max(a, b); }   void umin(long long &a, long long b) { a = min(a, b); }   const long long N = 3e5 + 2, inf = 1e18, M = 998244353;   long long Test, n, m, k, query;   bool ok = 1;   void test_case() {     cin >> n >> k;     string s;     cin >> s;     s =  $  + s;     vector<long long> last(26);     vector<vector<long long>> dp(n + 1, vector<long long>(n + 1));     dp[0][0] = 1;     for (long long i = 1; i <= n; i++) {       dp[i][0] = 1;       for (long long j = 1; j <= n; j++) {         dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];         if (last[s[i] -  a ]) dp[i][j] -= dp[last[s[i] -  a ] - 1][j - 1];       }       last[s[i] -  a ] = i;     }     long long ans = 0;     for (long long i = n; i >= 0 && k; i--) {       ans += min(k, dp[n][i]) * (n - i), k -= min(k, dp[n][i]);       debug() <<   [                <<  ans                    :                 << (ans)               <<  ]                      [                <<  k                    :                 << (k) <<  ]  ;     }     if (k)       cout << -1 << endl;     else       cout << ans << endl;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     Test = 1;     while (Test--) test_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5100;   int N, M;   vector<int> edge[MAXN];   int cdist[MAXN][MAXN];   int loc[3];   int target[3];   int eloc;   void play(bool finish) {     cout << loc[0] + 1 <<     << loc[1] + 1 <<     << loc[2] + 1 <<   n ;     cout << flush;     if (!finish) {       cin >> eloc;       eloc--;     }   }   void bfs(int cloc) {     vector<int> q;     q.push_back(cloc);     cdist[cloc][cloc] = 0;     for (int nq = 0; nq < q.size(); nq++) {       int ccur = q[nq];       for (int neigh : edge[ccur]) {         if (cdist[cloc][neigh] > cdist[cloc][ccur] + 1) {           cdist[cloc][neigh] = cdist[cloc][ccur] + 1;           q.push_back(neigh);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     srand(time(NULL));     for (int i = 0; i < MAXN; i++)       for (int j = 0; j < MAXN; j++) cdist[i][j] = MAXN;     cin >> N >> M;     for (int i = 0; i < M; i++) {       int x, y;       cin >> x >> y;       x--, y--;       edge[x].push_back(y);       edge[y].push_back(x);     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < edge[i].size(); j++)         swap(edge[i][j], edge[i][rand() % (j + 1)]);     }     for (int i = 0; i < N; i++) bfs(i);     for (int i = 0; i < 3; i++) {       while (true) {         loc[i] = rand() % N;         bool bad = false;         for (int j = 0; j < i; j++)           if (loc[j] == loc[i]) bad = true;         if (!bad) break;       }     }     play(false);     for (int run = 0; run < N; run++) {       if (eloc == loc[0] || eloc == loc[1] || eloc == loc[2]) break;       vector<pair<int, pair<int, int> > > v;       for (int i = 0; i < 3; i++)         for (int j = 0; j < edge[eloc].size(); j++) {           v.push_back(make_pair(cdist[i][j], make_pair(i, j)));         }       sort(v.begin(), v.end());       for (int i = 0; i < 3; i++) target[i] = -1;       for (auto ppp : v) {         int ci = ppp.second.first, cv = ppp.second.second;         bool bad = false;         for (int i = 0; i < 3; i++)           if (target[i] == cv) bad = true;         if (target[ci] == -1 && !bad) target[ci] = cv;       }       for (int i = 0; i < 3; i++)         if (target[i] == -1) target[i] = 0;       bool done = false;       for (int i = 0; i < 3; i++) {         if (cdist[loc[i]][eloc] == 1) {           done = true;           loc[i] = eloc;           break;         } else {           vector<int> choice;           int nneigh = edge[eloc][target[i]];           for (int neigh : edge[loc[i]])             if (cdist[neigh][nneigh] < cdist[loc[i]][nneigh]) {               choice.push_back(neigh);             }           loc[i] = choice[rand() % choice.size()];         }       }       play(done);     }   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> m;   int main() {     int n;     cin >> n;     string x, y;     for (int i = 0; i < n; i++) {       cin >> x >> y;       m[y]++;     }     int t1, t2, temp, temp1;     t1 = m[ hard ];     t2 = m[ soft ];     if (t1 > t2) {       temp = t1;       t1 = t2;       t2 = temp;     }     for (int i = 1; i < 100; i++) {       temp = i * i;       temp1 = temp / 2;       temp -= temp1;       if (temp1 >= t1 && temp >= t2) {         cout << i << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   using namespace std;   const int N = 1e3 + 7;   const int SZ = 1e6 * 14;   int val[SZ];   pair<int, int> ans;   int A[N], X[N], vis[N], maxind;   void solve(int need, int pos, int mask = 0, int sum = 0) {     if (pos > maxind) {       if (need != 0) return;       if (val[sum])         ans = {val[sum], mask};       else         val[sum] = mask;       return;     }     solve(need - 1, pos + 1, (mask << 1) + 1, sum + A[pos]);     solve(need, pos + 1, (mask << 1), sum);   }   void solve() {     int n;     cin >> n;     maxind = min(26, n);     int cnt[2] = {0, 0};     for (int i = 1; i <= n; ++i) {       cin >> A[i];       cnt[A[i] & 1]++;     }     if (n == 2) {       if (A[1] == A[2])         cout <<  YES n0   << A[1] <<   n ;       else         cout <<  NO n ;       return;     }     if (cnt[0] >= 3 || (cnt[0] && cnt[1] >= 2)) {       vector<int> V;       if (cnt[0] >= 3) {         for (int i = 1; i <= n; ++i) {           if (A[i] & 1) continue;           V.push_back(A[i]);           vis[i] = 1;           if (V.size() == 3) break;         }       } else {         for (int i = 1; i <= n; ++i) {           if (!(A[i] & 1)) {             V.push_back(A[i]);             vis[i] = 1;             break;           }         }         for (int i = 1; i <= n; ++i) {           if (A[i] & 1) V.push_back(A[i]), vis[i] = 1;           if (V.size() == 3) break;         }       }       assert(V.size() == 3);       X[1] = (V[0] + V[2] - V[1]) >> 1;       X[2] = V[0] - X[1];       X[3] = V[2] - X[1];       int ptr = 4;       for (int i = 1; i <= n; ++i) {         if (vis[i]) continue;         X[ptr++] = A[i] - X[1];       }       cout <<  YES n ;       for (int i = 1; i <= n; ++i) cout << X[i] <<    ;       cout <<   n ;       return;     }     for (int s = 1; s <= (n >> 1); ++s) {       solve(s, 1);       if (ans == pair<int, int>{0, 0}) {         memset(val, 0, sizeof(val));         continue;       }       vector<int> V1, V2;       for (int i = 1; i <= maxind; ++i) {         if ((1 << (maxind - i)) & ans.first) V1.push_back(A[i]), vis[i] = 1;         if ((1 << (maxind - i)) & ans.second) V2.push_back(A[i]), vis[i] = 1;       }       vector<int> V;       for (int i = 0; i < s; ++i) {         V.push_back(V1[i]);         V.push_back(V2[i]);       }       X[1] = 0;       for (int i = 2; i <= (s << 1); ++i) {         X[i] = V[i - 2] - X[i - 1];       }       assert(X[1] + X[s << 1] == V[(s << 1) - 1]);       int ptr = s * 2 + 1;       for (int i = 1; i <= n; ++i) {         if (vis[i]) continue;         X[ptr++] = A[i] - X[1];       }       cout <<  YES n ;       for (int i = 1; i <= n; ++i) cout << X[i] <<    ;       cout <<   n ;       return;     }     cout <<  NO n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc, w, h, flag = 0, a, b;     cin >> tc;     for (int i = 1; i <= tc; i++) {       cin >> w >> h;       if (w > h) swap(h, w);       if (i > 1) {         if (b < h && b >= w) {           int t = w;           w = h;           h = t;         } else if (b < w && b < h) {           flag = 1;         }       }       a = w, b = h;     }     if (flag == 1)       puts( NO );     else       puts( YES );   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (ch <  0  || ch >  9 );     do {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f * x;   }   int r, x, y, px, py;   int main() {     scanf( %d%d%d%d%d , &r, &x, &y, &px, &py);     double dis = sqrt(1.0 * (x - px) * (x - px) + 1.0 * (y - py) * (y - py));     printf( %d n , (int)(ceil(1.0 * dis / (2.0 * r))));   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int maxm = 2000005;   const int inf = 0x3f3f3f3f;   const int mod = 1000000000 + 7;   void init() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   };   int n, m;   vector<int> v[100005];   vector<int> vv[100005];   int sum[100005];   int to[100005];   int cnt = 0;   bool cmp(int x, int y) { return x > y; }   int main() {     init();     cin >> n >> m;     int mx = 0;     int top = 0;     for (int i = 1; i <= n; i++) {       int id, score;       cin >> id >> score;       if (sum[id] == 0) to[++cnt] = id;       v[id].push_back(score);       sum[id]++;       mx = max(mx, sum[id]);     }     for (int kk = 1; kk <= cnt; kk++) {       int i = to[kk];       sort(v[i].begin(), v[i].end(), cmp);       if (v[i].size()) vv[i].push_back(v[i][0]);       for (int j = 1; j < v[i].size(); j++) {         int k = vv[i][j - 1];         if (k <= 0) break;         vv[i].push_back(k + v[i][j]);       }     }     int ans = 0;     for (int i = 1; i <= mx; i++) {       int tmp = 0;       for (int k = 1; k <= cnt; k++) {         int j = to[k];         if (sum[j] < i) continue;         if (i > vv[j].size()) continue;         if (vv[j][i - 1] < 0) continue;         tmp += vv[j][i - 1];       }       ans = max(ans, tmp);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char buffer[1048576];   int main() {     scanf( %s , buffer);     string dat(buffer);     int n = dat.length();     int Q;     scanf( %d , &Q);     int lgstep = 1;     while ((1 << lgstep) <= n) lgstep++;     while (Q--) {       int k, d;       scanf( %d%d , &k, &d);       vector<int> invpi(k);       {         int lastval = 0;         int grp = 0;         for (int i = 1; i < k; i++) {           lastval += d;           if (lastval >= k) {             grp++;             lastval = grp;           }           invpi[i] = lastval;         }       }       vector<int> from(k);       vector<vector<int>> logfrom(lgstep, vector<int>(k));       for (int i = 0; i < k; i++) {         from[i] = invpi[i] + 1;         logfrom[0][i] = from[i];       }       for (int i = 1; i < lgstep; i++) {         for (int j = 0; j < k; j++) {           int p = logfrom[i - 1][j];           int p2 = (p != k) ? logfrom[i - 1][p] : (k);           logfrom[i][j] = p2;         }       }       string answer(n, 0);       for (int i = 0; i < n; i++) {         int base = min(i, n - k);         int fpos = i - base;         int tracepos = fpos;         int steps = 0;         {           int remain = base + 1;           for (int l = lgstep - 1; l >= 0; l--) {             if (remain >= (1 << l)) {               if (logfrom[l][tracepos] != k) {                 remain -= (1 << l);                 steps += (1 << l);                 tracepos = logfrom[l][tracepos];               }             }           }           if (remain) {             tracepos = logfrom[0][tracepos];             remain--;             steps++;           }         }         answer[i] = dat[base + tracepos - steps];       }       dat = move(answer);       puts(dat.c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, q;   long long b[100000 + 1];   long long suma;   long long sums;   long long sum[100000 + 1];   long long sign(long long i) { return ((i & 1) ? 1 : (-1)); }   inline long long poz(long long a) { return (a > 0 ? a : (-a)); }   void readFile() {     scanf( %lld%lld%lld , &n, &m, &q);     long long i, nr;     for (i = 1; i <= n; i++) {       scanf( %lld , &nr);       suma += nr * sign(i);     }     long long sumb = 0;     long long cr = 1;     for (i = 1; i <= m; i++) {       scanf( %lld , &b[i]);       if (i > n) {         sumb -= (-b[i - n]);         sumb = (-sumb);       }       if (i <= n) cr = (-cr);       sumb += cr * b[i];       if (i >= n) sum[++sums] = sumb;     }   }   long long elem(long long i) {     if (i >= 1 && i <= sums) return sum[i];     return sum[1];   }   void printRez() {     long long i = 0;     long long pas = (1 << 16);     long long caut = -suma;     while (pas != 0) {       if (i + pas <= sums && sum[i + pas] <= caut) i += pas;       pas >>= 1;     }     printf( %lld n , min(min(poz(suma + elem(i)), poz(suma + elem(i + 1))),                          poz(suma + elem(i - 1))));   }   void ansQues() {     sort(sum + 1, sum + sums + 1);     printRez();     while (q > 0) {       q--;       long long st, dr, nr;       scanf( %lld%lld%lld , &st, &dr, &nr);       long long mns = (dr >> 1) - ((st - 1) >> 1);       long long pls = (dr - st + 1) - mns;       suma += 1LL * pls * nr;       suma -= 1LL * mns * nr;       printRez();     }   }   int main() {     readFile();     ansQues();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kMod = 1e9 + 7;   const int kNmax = 2e5 + 10;   int n, v[kNmax], sub[kNmax], up[kNmax][2], down[kNmax][2], res, res_even;   vector<int> g[kNmax];   void dfs(int node, int father = 0) {     sub[node] = 1;     down[node][0] = 1;     int ways = (1LL * n * n) % kMod;     for (int vec : g[node]) {       if (vec == father) continue;       dfs(vec, node);       ways = (ways - 1LL * sub[vec] * sub[vec]) % kMod;       if (ways < 0) ways += kMod;       sub[node] += sub[vec];       down[node][0] += down[vec][1];       down[node][1] += down[vec][0];     }     ways = (ways - 1LL * (n - sub[node]) * (n - sub[node])) % kMod;     if (ways < 0) ways += kMod;     res = (res + 1LL * ways * v[node]) % kMod;     if (res < 0) res += kMod;   }   void dfs_bad(int node, int father = 0) {     int s0 = 0, s1 = 0;     int ways = (1LL * down[node][1] * (n - sub[node])) % kMod;     ways = (ways + 1LL * up[node][1] * sub[node]) % kMod;     for (int vec : g[node]) {       if (vec == father) continue;       ways = (ways + 1LL * down[vec][0] * (sub[node] - sub[vec])) % kMod;       s0 += down[vec][0];       s1 += down[vec][1];     }     res_even = (res_even + 1LL * ways * v[node]) % kMod;     if (res_even < 0) res_even += kMod;     for (int vec : g[node]) {       if (vec == father) continue;       up[vec][0] = up[node][1] + s0 - down[vec][0];       up[vec][1] = n - sub[vec] - up[vec][0];       dfs_bad(vec, node);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1, a, b; i < n; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1);     up[1][0] = 1;     dfs_bad(1);     res = (res - 2LL * res_even) % kMod;     if (res < 0) res += kMod;     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> bariers;     int n, m, s, d, temp;     scanf( %d%d%d%d , &n, &m, &s, &d);     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       bariers.push_back(temp);     }     sort(bariers.begin(), bariers.end());     int sing_dist, temp_dist = 0;     if (bariers[0] <= s || d == 1) {       printf( IMPOSSIBLE );       return 0;     }     for (int i = 0; i < bariers.size() - 1; i++) {       sing_dist = bariers[i + 1] - bariers[i];       if (sing_dist <= s + 1) {         bariers.erase(bariers.begin() + i);         temp_dist += sing_dist;         i--;       } else {         temp_dist = 0;       }       if (temp_dist + 1 >= d) {         printf( IMPOSSIBLE );         return 0;       }     }     int cur_pos = 0;     for (int i = 0; i < bariers.size(); i++) {       temp_dist = bariers[i] - d - s + 1;       if (cur_pos < temp_dist) {         printf( RUN %d n , temp_dist + s - cur_pos);         printf( JUMP %d n , d);       } else {         printf( RUN %d n , s);         printf( JUMP %d n , bariers[i] + 1 - cur_pos - s);       }       cur_pos = bariers[i] + 1;     }     if (cur_pos != m) {       printf( RUN %d n , m - cur_pos);     }     return 0;   }


#include <cstdio>   #include <algorithm>   #include <vector>   #include <set>   #include <cstdlib>   #include <utility>   #include <cmath>   #include <queue>   #include <stack>   #include <cstring>      using namespace std;      #define ll long long      #ifndef ONLINE_JUDGE   #define debug(format, ...) fprintf(stderr,         %s:%d:   format   n , __func__, __LINE__,##__VA_ARGS__)   #else   #define debug(format, ...)   #define NDEBUG   #endif      #define BLKSIZE 300      int n, q;   int b[100005];   int blkid[100005];   int blkbegin[100005];   // for block i, minimum start value required for j increases   int mincnt[400][405];   int f[100005];      int fen[300005];      #define lowbit(x) ((x)&(-(x)))      int rquery(int* arr, int v)   {       int ans = 0;       while (v) {           ans += arr[v]; v -= lowbit(v);       }       return ans;   }      void modify(int* arr, int loc, int val)   {       //printf( %d %lld n , loc, val);       while (loc <= n) {           arr[loc] += val; loc += lowbit(loc);       }   }      void updateblock(int id)   {       int start = max(id * BLKSIZE, 1);       for (int i = start; blkid[i] == id; i++) {           int x = 0; int curv = 0;           for (int j = 16; j >= 0; j--) {               int nx = x + (1 << j);               if (nx <= n && curv + fen[nx] + nx <= b[i]) {                   x = nx; curv += fen[nx];               }           }           f[i] = x + 1; if (f[i] <= n) modify(fen, f[i], 1);       }       vector<int> vals;       for (int i = start; blkid[i] == id; i++) {           vals.push_back(f[i]);           if (f[i] <= n) modify(fen, f[i], -1);       }       sort(vals.begin(), vals.end());       for (int i = 0; i < vals.size(); i++) {           mincnt[id][i+1] = vals[i];       }       for (int i = vals.size() + 1; i <= BLKSIZE; i++) {           mincnt[id][i] = 10000000;       }   }      int main()   {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , b + i);       blkid[0] = blkid[n + 1] = -1;       for (int i = 1; i <= n; i++) {           blkid[i] = i / BLKSIZE;           blkbegin[i] = (blkid[i-1] == blkid[i] ? blkbegin[i-1] : i);       }       for (int i = 0; i <= n / BLKSIZE; i++) {           updateblock(i);       }       scanf( %d , &q);       for (int qr = 1; qr <= q; qr++) {           int typ; scanf( %d , &typ);           if (typ == 1) {               int x, y; scanf( %d%d , &x, &y);               b[x] = y; updateblock(blkid[x]);           } else {               int x; scanf( %d , &x);               int cur = b[x] + 1; int i;               for (i = x + 1; blkid[i] == blkid[x]; i++) {                   if (cur > b[i]) cur++;               }               if (i <= n) {                   for (int j = blkid[i]; j <= n / BLKSIZE; j++) {                       int l = 0; int r = BLKSIZE;                       while (l < r) {                           int mid = (l + r) / 2 + 1;                           if (cur >= mincnt[j][mid]) {                               l = mid;                           } else {                               r = mid - 1;                           }                       }                       cur += l;                   }               }               printf( %d n , n + 1 - cur);           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double r, v;   double a, b;   bool check(double l) {     double arfa = l / r;     double A = r * (1 - cos(arfa));     double B = r * sin(arfa);     return l + sqrt(A * A + B * B) >= b - a;   }   int main() {     cin >> n >> r >> v;     while (n--) {       scanf( %lf%lf , &a, &b);       double l = 0, r = b - a, ans;       for (int i = 1; i <= 100; i++) {         double mid = (l + r) / 2.0;         if (check(mid))           ans = mid, r = mid;         else           l = mid;       }       printf( %.10f n , ans / v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int maxn = 3e5 + 7;   int n, f[maxn][20], dep[maxn];   set<int> s1, s2;   int mx = 0;   long long ans = 0;   int path(int o, int p) {     if (dep[o] < dep[p]) swap(o, p);     int dis = dep[o] - dep[p];     for (int i = 19; i >= 0; --i) {       if (dep[f[o][i]] >= dep[p]) {         o = f[o][i];       }     }     if (o == p) return dis;     for (int i = 19; i >= 0; --i) {       if (f[o][i] != f[p][i]) {         dis += 2 * (dep[o] - dep[f[o][i]]);         o = f[o][i];         p = f[p][i];       }     }     return dis + 2;   }   void solve(int v) {     int u;     scanf( %d , &u);     f[v][0] = u;     dep[v] = dep[u] + 1;     for (int i = 1; i < 20; ++i) {       f[v][i] = f[f[v][i - 1]][i - 1];     }     int dis1 = s1.empty() ? 0 : path(v, *s1.begin());     int dis2 = s2.empty() ? 0 : path(v, *s2.begin());     if (max(dis1, dis2) < mx) return;     if (max(dis1, dis2) > mx) {       mx = max(dis1, dis2);       if (dis1 >= dis2) {         for (auto &i : s2) {           if (path(i, v) == mx) {             s1.insert(i);           }         }         s2.clear();         s2.insert(v);       } else {         for (auto &i : s1) {           if (path(i, v) == mx) {             s2.insert(i);           }         }         s1.clear();         s1.insert(v);       }     } else {       if (dis1 >= dis2) {         s2.insert(v);       } else {         s1.insert(v);       }     }     ans = s1.size() + s2.size();   }   int main() {     scanf( %d , &n);     for (int i = 0; i < 20; ++i) {       f[1][i] = 1;       f[2][i] = 1;     }     s1.insert(1);     mx = 1;     for (int i = 2; i <= n + 1; ++i) {       solve(i);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, max = 0, max2 = 0, indexm, indexm2;     cin >> n;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       if (temp >= max) {         max2 = max;         indexm2 = indexm;         max = temp;         indexm = i + 1;       } else if (temp > max2) {         max2 = temp;         indexm2 = i + 1;       }     }     cout << indexm <<     << max2 << endl;     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;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 998244353) {     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 = 998244353) {     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; }   int t;   long long a[205], b[205], c[205];   long long sa[205], sb[205];   long long f[205][205][2], g[205][205][2];   void fmain(int ID) {     scanf( %d%d%d , &n, &t, &k);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %lld%lld%lld , a + i, b + i, c + i);     }     n++;     a[n] = (1 << 30);     b[n] = (1 << 30);     c[n] = (1LL << 60);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       sa[i] = sa[i - 1] + a[i];       sb[i] = sb[i - 1] + b[i];     }     for (int(i) = 0; (i) < (int)(205); (i)++)       for (int(j) = 0; (j) < (int)(205); (j)++)         for (int(z) = 0; (z) < (int)(2); (z)++) {           f[i][j][z] = g[i][j][z] = (1LL << 60);         }     for (int(j) = 0; (j) < (int)(205); (j)++)       for (int(z) = 0; (z) < (int)(2); (z)++) f[0][j][z] = g[0][j][z] = 0;     for (int(i) = 1; (i) <= (int)(n); (i)++) {       for (int j = 0; j <= t; j++)         for (int(z) = 0; (z) < (int)(2); (z)++) {           if (a[i] * z + b[i] * j <= c[i] && f[i - 1][j][z] < (1LL << 60)) {             mintt(f[i][j][z], f[i - 1][j][z]);             long long cnt = (sa[i - 1] * z + sb[i - 1] * j + k - 1) / k;             if (cnt * k <= sa[i] * z + sb[i] * j) mintt(g[i][j][z], cnt);           }           for (int r = 0; r < j; r++) {             long long cnt = g[i][r][z];             if (cnt == (1LL << 60)) continue;             long long rem = sa[i] * z + sb[i] * r - cnt * k;             assert(0 <= rem);             long long need = (max(0LL, rem + b[i] * (j - r) - c[i]) + k - 1) / k;             if (need * k <= rem && f[i - 1][j - r][0] < (1LL << 60)) {               mintt(f[i][j][z], cnt + need + f[i - 1][j - r][0]);               long long n2 = (sb[i - 1] * (j - r) + k - 1) / k;               if (n2 * k <= sb[i] * (j - r) + rem - need * k) {                 mintt(g[i][j][z], cnt + need + n2);               }             }           }         }     }     printf( %lld n , f[n][t][1]);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int main(int argc, char const *argv[]) {     int t;     cin >> t;     while (t--) {       int a, b, ans = 0;       cin >> a >> b;       if (a == b)         cout << (a * 2) / 3 << endl;       else {         if (a > b) swap(a, b);         if (b >= 2 * a)           cout << a << endl;         else {           ans = b - a;           a = 2 * a - b;           ans += (a * 2) / 3;           cout << ans << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x *= 10, x += (c -  0 ), c = getchar();     return x;   }   vector<pair<int, int> > ans;   int n, m, tag;   int a[40][40], b[40][40], cnt[910];   void init() {     n = getint();     m = getint();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         a[i][j] = getint();         cnt[a[i][j]]++;         if (cnt[a[i][j]] == 1) tag++;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         b[i][j] = getint();         cnt[b[i][j]]--;         if (cnt[b[i][j]] == 0) tag--;         if (cnt[b[i][j]] < 0) tag = 10000;       }   }   void solve2() {     if (n == 1) {       for (int i = 1; i <= m; i++)         if (a[1][i] != b[1][i]) {           for (int j = i + 1; j <= m; j++) {             if (a[1][j] != b[1][i]) continue;             bool tflag = true;             for (int k = i; k < j; k++)               if (a[1][k] != b[1][k + 1]) {                 tflag = false;                 break;               }             for (int k = j + 1; k <= m; k++)               if (a[1][k] != b[1][k]) {                 tflag = false;                 break;               }             if (tflag) {               printf( %d n , j - i);               for (int k = j; k >= i; k--) printf( 1 %d n , k);               return;             }           }           break;         }       for (int i = m; i >= 1; i--)         if (a[1][i] != b[1][i]) {           for (int j = i - 1; j >= 1; j--) {             if (a[1][j] != b[1][i]) continue;             bool tflag = true;             for (int k = i; k > j; k--)               if (a[1][k] != b[1][k - 1]) {                 tflag = false;                 break;               }             for (int k = j - 1; k >= 1; k--)               if (a[1][k] != b[1][k]) {                 tflag = false;                 break;               }             if (tflag) {               printf( %d n , i - j);               for (int k = j; k <= i; k++) printf( 1 %d n , k);               return;             }           }           break;         }       puts( -1 );       return;     } else {       for (int i = 1; i <= n; i++)         if (a[i][1] != b[i][1]) {           for (int j = i + 1; j <= n; j++) {             if (a[j][1] != b[i][1]) continue;             bool tflag = true;             for (int k = i; k < j; k++)               if (a[k][1] != b[k + 1][1]) {                 tflag = false;                 break;               }             for (int k = j + 1; k <= n; k++)               if (a[k][1] != b[k][1]) {                 tflag = false;                 break;               }             if (tflag) {               printf( %d n , j - i);               for (int k = j; k >= i; k--) printf( %d 1 n , k);               return;             }           }         }       for (int i = n; i >= 1; i--)         if (a[i][1] != b[i][1]) {           for (int j = i - 1; j >= 1; j--) {             if (a[j][1] != b[i][1]) continue;             bool tflag = true;             for (int k = i; k > j; k--)               if (a[k][1] != b[k - 1][1]) {                 tflag = false;                 break;               }             for (int k = j - 1; k >= 1; k--)               if (a[k][1] != b[k][1]) {                 tflag = false;                 break;               }             if (tflag) {               printf( %d n , i - j);               for (int k = j; k <= i; k++) printf( %d 1 n , k);               return;             }           }           break;         }       puts( -1 );       return;     }   }   int sn, sm;   void move(int ttn, int ttm) {     while (sn != ttn && sm != ttm) {       if (sn > ttn && sm > ttm) {         int tswap = a[sn][sm];         a[sn][sm] = a[sn - 1][sm - 1];         a[sn - 1][sm - 1] = tswap;         sn--;         sm--;       } else if (sn > ttn && sm < ttm) {         int tswap = a[sn][sm];         a[sn][sm] = a[sn - 1][sm + 1];         a[sn - 1][sm + 1] = tswap;         sn--;         sm++;       } else if (sn < ttn && sm > ttm) {         int tswap = a[sn][sm];         a[sn][sm] = a[sn + 1][sm - 1];         a[sn + 1][sm - 1] = tswap;         sn++;         sm--;       } else {         int tswap = a[sn][sm];         a[sn][sm] = a[sn + 1][sm + 1];         a[sn + 1][sm + 1] = tswap;         sn++;         sm++;       }       ans.push_back(make_pair(sn, sm));     }     while (sn != ttn) {       if (sn < ttn) {         int tswap = a[sn][sm];         a[sn][sm] = a[sn + 1][sm];         a[sn + 1][sm] = tswap;         sn++;       } else {         int tswap = a[sn][sm];         a[sn][sm] = a[sn - 1][sm];         a[sn - 1][sm] = tswap;         sn--;       }       ans.push_back(make_pair(sn, sm));     }     while (sm != ttm) {       if (sm < ttm) {         int tswap = a[sn][sm];         a[sn][sm] = a[sn][sm + 1];         a[sn][sm + 1] = tswap;         sm++;       } else {         int tswap = a[sn][sm];         a[sn][sm] = a[sn][sm - 1];         a[sn][sm - 1] = tswap;         sm--;       }       ans.push_back(make_pair(sn, sm));     }   }   void turn(int rn) {     for (int i = m; i >= 1; i--) {       move(1, 1);       if (a[rn][i] == b[rn][i]) continue;       int xn = 0, xm;       for (int j = rn; j >= 1; j--) {         for (int k = (j == rn ? i - 1 : m); k >= 1; k--)           if (a[j][k] == b[rn][i]) {             xn = j;             xm = k;             break;           }         if (xn) break;       }       if (xm > i && xn < rn) {         while (xm > i && xn < rn && xm - i > rn - xn) {           if (xn == 1) {             move(xn, xm - 1);             move(xn + 1, xm - 1);             move(xn, xm);             xn++;             xm--;           } else {             move(xn - 1, xm);             move(xn, xm - 1);             move(xn, xm);             xm--;           }         }       }       while (xn != rn && xm != i) {         if (xm < i) {           if (xn == 1) {             move(xn, xm - 1);             move(xn + 1, xm);             move(xn + 1, xm + 1);             move(xn, xm);             xn++;             xm++;           } else {             move(xn - 1, xm + 1);             move(xn + 1, xm + 1);             move(xn, xm);             xn++;             xm++;           }         } else {           if (xn == 1) {             move(xn, xm - 1);             move(xn + 1, xm - 1);             move(xn, xm);             xn++;             xm--;           } else {             move(xn - 1, xm - 1);             move(xn + 1, xm - 1);             move(xn, xm);             xn++;             xm--;           }         }       }       while (xn != rn) {         if (xn == 1) {           move(xn, xm - 1);           move(xn + 1, xm);           move(xn, xm);           xn++;         } else {           move(xn - 1, xm);           if (xm == 1)             move(xn, xm + 1);           else             move(xn, xm - 1);           move(xn + 1, xm);           move(xn, xm);           xn++;         }       }       while (xm != i) {         assert(xn - 1 >= 1 && xm + 1 <= m);         move(xn - 1, xm);         move(xn, xm + 1);         move(xn, xm);         xm++;       }     }   }   void turn2() {     for (int j = m; j >= 1; j--)       for (int i = 2; i >= 1; i--) {         move(1, 1);         if (a[i][j] == b[i][j]) continue;         int xn = 0, xm;         for (int k = j; k >= 1; k--) {           for (int l = (k == j ? i - 1 : 2); l >= 1; l--) {             if (a[l][k] == b[i][j]) {               xn = l;               xm = k;               break;             }           }           if (xn) break;         }         while (xn != i && xm != j) {           if (xn < i) {             move(xn + 1, xm - 1);             move(xn + 1, xm + 1);             move(xn, xm);             xn++;             xm++;           } else {             move(xn - 1, xm + 1);             move(xn, xm);             xn--;             xm++;           }         }         while (xn != i) {           if (xn < i) {             move(xn, xm - 1);             move(xn + 1, xm);             move(xn, xm);             xn++;           } else {             move(xn - 1, xm);             move(xn, xm);             xn--;           }         }         while (xm != j) {           if (xn != 1) {             move(xn - 1, xm);             move(xn, xm + 1);             move(xn, xm);             xm++;           } else {             move(xn, xm - 1);             move(xn + 1, xm);             move(xn, xm + 1);             move(xn, xm);             xm++;           }         }       }   }   void solve3() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (a[i][j] == b[1][1]) {           sn = i;           sm = j;           break;         }       if (sn) break;     }     int an = sn, am = sm;     move(1, 1);     for (int i = n; i > 2; i--) turn(i);     turn2();     printf( %d n , (int)ans.size());     printf( %d %d n , an, am);     for (int i = 0; i < (int)ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);   }   void solve() {     if (tag != 0) {       puts( -1 );       return;     }     if (n == 1 || m == 1)       solve2();     else       solve3();   }   int main() {     init();     solve();   }


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


/**    *  created: 06/03/2021, 16:16:13   **/      #include <bits/stdc++.h>      using namespace std;      const int max_n = 100111, inf = 1000111222;   const int max_c = 26;      int t, n, k, cnt[max_c], need[max_c];   char s[max_n];      bool check(int mx) {       int tot = 0;       for (int i = 0; i < max_c; ++i) {           need[i] = 0;           if (cnt[i] % k) {               need[i] = k - (cnt[i] % k);           }           tot += need[i];       }       return tot <= mx;   }      void solve() {       for (int i = n - 1; i >= 0; --i) {           --cnt[s[i] -  a ];           for (int c = s[i] + 1; c <=  z ; ++c) {               ++cnt[c -  a ];               bool res = check(n - i - 1);               --cnt[c -  a ];               if (res) {                   for (int j = 0; j < i; ++j) {                       printf( %c , s[j]);                   }                   printf( %c , c);                   int tot = accumulate(need, need + max_c, 0), all = n - i - 1;                   for (int j = tot; j < all; ++j) {                       printf( a );                   }                   for (int c2 = 0; c2 < max_c; ++c2) {                       for (int j = 0; j < need[c2]; ++j) {                           printf( %c , c2 +  a );                       }                   }                   puts(  );                   return;               }           }       }   }      int main() {       //freopen( input.txt ,  r , stdin);       //freopen( output.txt ,  w , stdout);       scanf( %d , &t);       while (t--) {           scanf( %d%d%s , &n, &k, s);           if (n % k) {               puts( -1 );               continue;           }           memset(cnt, 0, sizeof(cnt));           for (int i = 0; i < n; ++i) {               ++cnt[s[i] -  a ];           }           bool ok = 1;           for (int i = 0; i < max_c; ++i) {               if (cnt[i] % k) {                   ok = 0;                   break;               }           }           if (ok) {               puts(s);               continue;           }           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;   };   point operator+(point a, point b) { return (point){a.x + b.x, a.y + b.y}; }   point operator*(point a, double b) { return (point){a.x * b, a.y * b}; }   double len(point x) { return sqrt(x.x * x.x + x.y * x.y); }   void print(point x) { printf( %.10lf %.10lf n , x.x, x.y); }   int main() {     ios::sync_with_stdio(false);     point p, v;     cin >> p.x >> p.y >> v.x >> v.y;     double a, b, c, d;     cin >> a >> b >> c >> d;     print(p + v * (b / len(v)));     point u = v * (-1);     point l = (point){-v.y, v.x};     point r = l * (-1);     point tmp = p;     print(tmp = tmp + l * (a / 2 / len(l)));     print(tmp = tmp + r * ((a - c) / 2 / len(r)));     print(tmp = tmp + u * (d / len(u)));     print(tmp = tmp + r * (c / len(r)));     print(tmp = tmp + v * (d / len(v)));     print(tmp = tmp + r * ((a - c) / 2 / len(r)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     if (k == 1) {       long long int ans = n * (n - 1) / 2;       cout << ans <<     << ans << endl;     } else {       long long int ans = (n - k + 1) * (n - k) / 2;       long long int x = n / k;       long long int y = n % k;       long long int ans2 = x * (x - 1) / 2;       long long int ans3 = (x + 1) * x / 2;       cout << ans3 * y + ans2 * (k - y) <<     << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = (int)1e9 + 7;   const int MX = 1073741822;   const long long MXLL = 4e18;   const int Sz = 1110111;   inline void Read_rap() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline void randomizer3000() {     unsigned int seed;     asm( rdtsc  :  =A (seed));     srand(seed);   }   void files(string problem) {     if (fopen((problem +  .in ).c_str(),  r )) {       freopen((problem +  .in ).c_str(),  r , stdin);       freopen((problem +  .out ).c_str(),  w , stdout);     }   }   int n;   long long d[Sz], m[Sz], r[Sz], p[Sz];   bool used[Sz];   struct fenwick {     int n;     vector<vector<pair<int, int> > > t;     fenwick(int n) : n(n), t(n + 1) {}     void add(int x, int y, int id) {       for (int i = x; i <= n; i |= (i + 1)) t[i].push_back(make_pair(y, id));     }     void preSort() {       for (int i = 0; i <= n; i++)         sort(t[i].begin(), t[i].end(),              [](pair<int, int> a, pair<int, int> b) { return a > b; });     }     void expand(int x, int y, queue<int> &q) {       for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {         while ((int)(t[i].size()) && t[i].back().first <= y) {           int id = t[i].back().second;           if (!used[id]) {             used[id] = 1;             q.push(id);           }           t[i].pop_back();         }       }     }   };   int Bfs(int st) {     fenwick T(2 * (n + 1));     for (int i = 1; i <= n; i++) T.add(m[i], d[i], i);     T.preSort();     queue<int> q;     q.push(st);     int cnt = 0;     while (!q.empty()) {       int i = q.front();       q.pop();       int p = ::p[i];       int r = ::r[i];       T.expand(p, r, q);       cnt++;     }     return cnt - 1;   }   void compress(long long a[], long long b[]) {     static vector<long long> c;     c.clear();     for (int i = 0; i <= n; i++) {       c.push_back(a[i]);       c.push_back(b[i]);     }     sort(c.begin(), c.end());     for (int i = 0; i <= n; i++)       a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();     for (int i = 0; i <= n; i++)       b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();   }   long long dist(int x, int y) { return x * 1ll * x + y * 1ll * y; }   int main() {     int sx, sy;     scanf( %d %d %d %d %d , &sx, &sy, p + 0, r + 0, &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d %d %d %d %d , &x, &y, m + i, p + i, r + i);       d[i] = dist(x - sx, y - sy);     }     for (int i = 0; i <= n; i++) r[i] *= r[i];     compress(r, d);     compress(p, m);     cout << Bfs(0);     return 0;   }


#include <bits/stdc++.h>   const int N = 41;   long long bin_p(long long a, long long b) {     if (!b) return 1;     if (b % 2 == 0) {       long long cur = bin_p(a, b / 2);       return cur * cur;     }     return a * bin_p(a, b - 1);   }   long long color[N];   std::vector<long long> g[N];   long long g1[N], cmpSz = 0;   bool fl = false;   void dfs(int v, int clr = 1) {     color[v] = clr;     for (auto e : g[v]) {       if (color[e] == 0) {         color[e] = (3 - clr);         dfs(e, 3 - clr);       }       if (color[e] == clr) {         fl = true;       }     }   }   const long long LEFT = 22;   const long long MASK_LEFT = (1LL << LEFT) - 1,                   MASK_RIGHT = ((1LL << 40) - 1) ^ MASK_LEFT;   long long dp1[1LL << 21], dp2[1LL << 21];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n, m;     std::cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       std::cin >> a >> b;       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);       g1[a] |= (1LL << b);       g1[b] |= (1LL << a);     }     long long isolated = 0;     for (int i = 0; i < n; ++i) {       if (!color[i]) {         dfs(i);         cmpSz++;       }       if (g[i].size() == 0) isolated++;     }     long long answ = (1LL << n);     if (m == 0) {       answ -= (1LL << n);     }     if (!fl) {       answ += (1LL << cmpSz);     }     answ += 2LL * (1LL << isolated);     answ -= (1LL << cmpSz);     for (long long mask = 0; mask < (1 << std::max(0LL, (n - LEFT))); ++mask) {       long long realMask = (mask << LEFT), adMask = 0;       for (long long j = 0; j < n; ++j) {         if ((realMask >> j) & 1) {           adMask |= g1[j];         }       }       if ((adMask & realMask) == 0) {         dp2[mask]++;       }     }     for (long long j = 0; j < std::max(0LL, n - LEFT); ++j) {       for (long long msk = 0; msk < (1LL << std::max(0LL, (n - LEFT))); ++msk) {         if (((msk >> j) & 1)) {           dp2[msk] += dp2[msk ^ (1LL << j)];         }       }     }     for (long long mask = 0; mask < (1 << std::min((long long)n, LEFT)); ++mask) {       long long adMask = 0;       for (long long j = 0; j < n; ++j) {         if ((mask >> j) & 1) {           adMask |= g1[j];         }       }       if ((adMask & mask) == 0) {         answ -= 2 * dp2[(adMask ^ ((1LL << n) - 1)) >> LEFT];       }     }     std::cout << answ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int ans = -1, ansd, a[MAXN], b[MAXN], n, m;   inline int Pow(int x, int y, int mod) {     int s = 1;     for (; y; y >>= 1, x = 1ll * x * x % mod)       if (y & 1) s = 1ll * s * x % mod;     return s;   }   inline bool find(int *a, int n, int x) {     int t = lower_bound(a + 1, a + n + 1, x) - a;     return a[t] == x;   }   inline void solve(int *a, int n) {     if (n == 1) {       ans = a[1], ansd = 1;       return;     }     int tmp = a[2] - a[1], cnt = 0;     for (int i = 1; i <= n; i++)       if (find(a, n, (a[i] + tmp) % m)) cnt++;     ansd = 1ll * tmp * Pow(n - cnt, m - 2, m) % m;     int d = (m - ansd) % m;     for (int i = 1; i <= n; i++)       if (!find(a, n, (a[i] + d) % m)) {         if (ans == -1)           ans = a[i];         else {           ans = -1;           return;         }       }   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     if (n == 1 || n == m) return printf( %d 1 n , a[1], 1), 0;     if (2 * n - 4 < m)       solve(a, n);     else {       int t = 0;       for (int i = 0; i < m; i++)         if (!find(a, n, i)) b[++t] = i;       solve(b, t);       if (ans != -1) (ans += 1ll * ansd * t % m) %= m;     }     if (ans == -1) return printf( -1 n ), 0;     return printf( %d %d n , ans, ansd), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, i;     while (scanf( %lld %lld , &n, &k) != EOF) {       vector<long long int> v;       for (i = 1; i * i <= n; i++) {         if (n % i == 0) {           v.push_back(i);           if ((n / i) != i) v.push_back(n / i);         }       }       sort(v.begin(), v.end());       if (v.size() < k) {         cout <<  -1  << endl;       } else {         printf( %lld n , v[k - 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int i, j, n, ct = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     if (n < 2) {       cout <<  -1 n ;       return;     }     sort(a, a + n);     set<int> ans;     if (n == 2) {       ans.insert(a[1] + a[1] - a[0]);       ans.insert(a[0] - (a[1] - a[0]));       if ((a[1] - a[0]) % 2 == 0) ans.insert((a[0] + a[1]) / 2);     } else {       set<int> dif;       for (i = 1; i < n; i++) dif.insert(a[i] - a[i - 1]);       if (dif.size() == 1) {         int d = *dif.begin();         ans.insert(a[0] - d);         ans.insert(a[n - 1] + d);       } else if (dif.size() == 2) {         int d1 = *dif.begin();         int d2 = *dif.upper_bound(d1);         if (2 * d1 == d2) {           for (i = 0; i + 1 < n; i++) {             if (a[i] + d1 == a[i + 1]) continue;             ct++;             ans.insert(a[i] + d1);           }         }       }     }     if (ct > 1) ans.clear();     cout << ans.size() <<   n ;     for (auto &x : ans) cout << x <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     int test = 1;     while (test--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, l, m, n;     cin >> n;     string s[n], t;     for (i = 0; i < n; i++) {       cin >> s[i];     }     map<string, vector<long long int>> mp;     set<string> ss;     for (i = 1; i <= 9; i++) {       for (j = 0; j < n; j++) {         for (k = 0; k + i - 1 < 9; k++) {           t = s[j].substr(k, i);           ss.insert(t);         }         while (ss.empty() != true) {           mp[*(ss.begin())].push_back(j);           ss.erase(ss.begin());         }       }     }     map<string, vector<long long int>>::iterator it;     string fir;     map<long long int, long long int> mpp;     string ans[n];     for (it = mp.begin(); it != mp.end(); it++) {       fir = it->first;       if (mp[fir].size() == 1 && mpp[mp[fir][0]] == 0) {         mpp[mp[fir][0]] = 1;         ans[mp[fir][0]] = fir;       } else if (mp[fir].size() == 1 && mpp[mp[fir][0]] == 1) {         if (fir.length() < ans[mp[fir][0]].length()) {           ans[mp[fir][0]] = fir;         }       }     }     for (i = 0; i < n; i++) {       cout << ans[i] << endl;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   string ToStr(char k) {     stringstream ss;     ss << k;     return ss.str();   }   bool check(string str) {     int n = (int)str.length();     for (int i = 0; i < n / 2; i++) {       if (str[i] != str[n - i - 1]) return false;     }     return true;   }   int main() {     string s;     cin >> s;     for (int i = 0; i <= (int)s.length(); i++) {       for (int j = 0; j < 26; j++) {         string tmp = s;         tmp.insert(i, ToStr( a  + j));         if (check(tmp)) {           cout << tmp << endl;           return 0;         }       }     }     cout <<  NA  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1000 * 101;   const long long INF = 1e18;   long long n, a[maxn];   vector<pair<char, long long> > ans1;   vector<pair<long long, long long> > ans;   queue<long long> bra;   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[0] = 0;     a[n + 1] = 0;     for (int i = 1; i <= n + 1; i++) {       if (a[i] > a[i - 1]) {         long long dis = a[i] - a[i - 1];         for (int j = 0; j < dis; j++) ans1.push_back({ ( , i});       } else if (a[i] < a[i - 1]) {         long long dis = a[i - 1] - a[i];         for (int j = 0; j < dis; j++) ans1.push_back({ ) , i - 1});       }     }     for (int i = 0; i < ans1.size(); i++) {       if (ans1[i].first ==  ( ) {         bra.push(ans1[i].second);       } else {         long long x2 = bra.front();         ans.push_back({x2, ans1[i].second});         bra.pop();       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, kMaxP = 3000007, kMaxN = 200007, root = 15311432,             root_1 = 469870224, root_pw = 1 << 23;   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;   }   int inverse(int a) { return binpow(a, mod - 2); }   int counts[kMaxP];   vector<vector<int>> polynomials_of_degree[kMaxN];   void fft(vector<int>& a, bool invert) {     int n = a.size();     for (int i = 1, j = 0; i < n; i++) {       int bit = n >> 1;       for (; j & bit; bit >>= 1) j ^= bit;       j ^= bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       int wlen = invert ? root_1 : root;       for (int i = len; i < root_pw; i <<= 1)         wlen = (int)(1LL * wlen * wlen % mod);       for (int i = 0; i < n; i += len) {         int w = 1;         for (int j = 0; j < len / 2; j++) {           int u = a[i + j], v = (int)(1LL * a[i + j + len / 2] * w % mod);           a[i + j] = u + v < mod ? u + v : u + v - mod;           a[i + j + len / 2] = u - v >= 0 ? u - v : u - v + mod;           w = (int)(1LL * w * wlen % mod);         }       }     }     if (invert) {       int n_1 = inverse(n);       for (int& x : a) x = (int)(1LL * x * n_1 % mod);     }   }   vector<int> multiply(vector<int> const& a, vector<int> const& b) {     vector<int> fa(a.begin(), a.end()), fb(b.begin(), b.end());     ;     int n = 1;     while (n < (static_cast<int>((a).size())) + (static_cast<int>((b).size())))       n <<= 1;     fa.resize(n);     fb.resize(n);     fft(fa, false);     fft(fb, false);     for (int i = 0; i < n; i++) fa[i] = int64_t{1} * fa[i] * fb[i] % mod;     fft(fa, true);     fa.resize((static_cast<int>((a).size())) + (static_cast<int>((b).size())) -               1);     ;     return fa;   }   int solve() {     int n;     cin >> n;     for (int i = n; i--;) {       int p;       cin >> p;       counts[p]++;     }     for (int i = 2; i < kMaxP; i++) {       if (counts[i] > 0) {         vector<int> all_ones(counts[i] + 1, 1);         polynomials_of_degree[counts[i]].emplace_back(all_ones);         ;       }     }     for (int i = 1; true; i++) {       while (!polynomials_of_degree[i].empty()) {         vector<int> a = polynomials_of_degree[i].back();         polynomials_of_degree[i].pop_back();         vector<int> b;         for (int j = i; j < n; j++)           if (!polynomials_of_degree[j].empty()) {             b = polynomials_of_degree[j].back();             polynomials_of_degree[j].pop_back();             break;           }         if (b.empty()) return a[(n >> 1)];         polynomials_of_degree[(static_cast<int>((a).size())) - 1 +                               (static_cast<int>((b).size())) - 1]             .emplace_back(multiply(a, b));         ;       }     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int test_cases_num = 1;     for (int i = 1; i <= test_cases_num; i++) {       if (false)         if (test_cases_num > 1)           if (false) cerr <<  Test #  << i <<  : n ;       cout << solve() <<   n ;       if (false)         if (test_cases_num > 1)           if (false) cerr <<  End of test #  << i <<  . n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool gone[1000000];   int n;   int ord[1000000], put[1000000];   int main() {     scanf( %i , &n);     for (int(a) = 0; (a) < (n); (a)++) scanf( %i , ord + a);     for (int(a) = 0; (a) < (n); (a)++) scanf( %i , put + a);     int i = 0;     for (int(a) = 0; (a) < (n); (a)++) {       int res = 0;       if (gone[put[a]] || i >= n) {         printf( %i  , res);         continue;       }       while (ord[i] != put[a]) {         gone[ord[i]] = true;         i++;         res++;       }       gone[ord[i]] = true;       i++;       res++;       printf( %i  , res);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   enum { MAXN = 102 };   int reverse[MAXN], target[MAXN], init[MAXN];   int n;   int eq(int *a, int *b) {     int i;     for (i = 1; i <= n; i++)       if (a[i] != b[i]) return 0;     return 1;   }   void proc(int *a, int *b) {     int ans[MAXN], i;     for (i = 1; i <= n; i++) {       ans[i] = a[b[i]];     }     for (i = 1; i <= n; i++) a[i] = ans[i];   }   void print(int *a) {     int i;     for (i = 1; i <= n; i++) printf( %d  , a[i]);     puts(  );   }   int main(void) {     int k, m1, m2, i;     scanf( %d %d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , init + i);       reverse[init[i]] = i;     }     for (i = 1; i <= n; i++) scanf( %d , target + i);     int natur[MAXN];     for (i = 1; i <= n; i++) natur[i] = i;     m1 = 0;     m2 = 0;     while (m1 < 1000 && !eq(natur, target)) {       proc(natur, init);       m1++;     }     if (!eq(natur, target)) m1 = -1;     for (i = 1; i <= n; i++) natur[i] = i;     while (m2 < 1000 && !eq(natur, target)) {       proc(natur, reverse);       m2++;     }     if (!eq(natur, target)) m2 = -1;     char *ans =  NO ;     if (m1 == 1 && m2 == 1) {       if (k == 1) ans =  YES ;     } else if (m1 == 1 || m2 == 1) {       if (k % 2 == 1) ans =  YES ;     }     if (m1 > 1 && (k - m1) >= 0 && (k - m1) % 2 == 0) ans =  YES ;     if (m2 > 1 && (k - m2) >= 0 && (k - m2) % 2 == 0) ans =  YES ;     puts(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int R[N], czy[N], dp[N], siz[N];   pair<int, int> E[N], E2[N];   int M;   pair<int, int> Find(int x) {     if (x == R[x]) return {x, 0};     pair<int, int> a = Find(R[x]);     a.second ^= czy[x];     return a;   }   void Union(int a, int b) {     if (a == b) return;     if (siz[a] > siz[b]) swap(a, b);     siz[b] += siz[a];     R[a] = b;     czy[a] ^= 1 ^ czy[b];     czy[b] = 0;   }   void sep(int a, int b) {     if (a == b) return;     czy[a] = 0;     czy[b] = 0;     if (siz[a] > siz[b]) swap(a, b);     siz[b] -= siz[a];     R[a] = a;   }   void solve(int l, int r, int a, int b) {     if (l > r) return;     int m = (l + r) >> 1;     dp[m] = N;     for (int i = l; i < m; i++) {       pair<int, int> A = Find(E[i].first), B = Find(E[i].second);       E2[i] = {A.first, B.first};       if (A.first == B.first && (A.second ^ B.second ^ 1)) {         dp[m] = i;         break;       }       if (A.first != B.first) {         czy[A.first] = A.second;         czy[B.first] = B.second;       }       Union(A.first, B.first);     }     if (dp[m] < m) {       for (int i = dp[m] - 1; i >= l; i--) sep(E2[i].first, E2[i].second);       solve(l, dp[m], a, b);       for (int i = dp[m] + 1; i <= r; i++) dp[i] = b;       return;     }     for (int i = b; i >= a; i--) {       if (i < m) {         dp[m] = m - 1;         break;       }       pair<int, int> A = Find(E[i].first), B = Find(E[i].second);       E2[i] = {A.first, B.first};       if (A.first == B.first && (A.second ^ B.second ^ 1)) {         dp[m] = i;         break;       }       if (A.first != B.first) {         czy[A.first] = A.second;         czy[B.first] = B.second;       }       Union(A.first, B.first);     }     for (int i = dp[m] + 1; i <= b; i++) sep(E2[i].first, E2[i].second);     pair<int, int> A = Find(E[m].first), B = Find(E[m].second);     if (A.first == B.first && (A.second ^ B.second ^ 1)) {       for (int i = m + 1; i <= r; i++) dp[i] = b;     } else {       if (A.first != B.first) {         czy[A.first] = A.second;         czy[B.first] = B.second;       }       Union(A.first, B.first);       solve(m + 1, r, dp[m], b);       sep(A.first, B.first);     }     for (int i = m - 1; i >= l; i--) {       sep(E2[i].first, E2[i].second);     }     for (int i = b; i > dp[m]; i--) {       A = Find(E[i].first), B = Find(E[i].second);       E2[i] = {A.first, B.first};       if (A.first != B.first) {         czy[A.first] = A.second;         czy[B.first] = B.second;       }       Union(A.first, B.first);     }     solve(l, m - 1, a, dp[m]);     for (int i = dp[m] + 1; i <= b; i++) sep(E2[i].first, E2[i].second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, q;     cin >> n >> m >> q;     M = m;     for (int i = 1; i <= n + 2; i++) {       R[i] = i;       siz[i] = 1;     }     for (int i = 1; i <= m; i++) {       cin >> E[i].first >> E[i].second;     }     E[m + 1] = {n + 1, n + 2};     solve(1, m, 0, m + 1);     while (q--) {       int l, r;       cin >> l >> r;       if (r >= dp[l])         cout <<  NO n ;       else         cout <<  YES n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long pw[19];   long long val[19];   char A[100009];   string s[100009];   int main() {     scanf( %s , A);     scanf( %d , &m);     for (int i = 0; i < 10; i++) {       val[i] = i;       pw[i] = 10;     }     for (int i = 0; i < m; i++) cin >> s[i];     for (int j = m - 1; j >= 0; j--) {       int ln = s[j].length();       int nm = s[j][0] -  0 ;       long long nmpw = 1;       long long san = 0;       for (int i = ln - 1; i > 2; i--) {         san = (san + (nmpw * val[s[j][i] -  0 ])) % 1000000007;         nmpw = (nmpw * pw[s[j][i] -  0 ]) % 1000000007;       }       val[nm] = san;       pw[nm] = nmpw;     }     int ln = strlen(A);     long long ans = 0;     long long nmpw = 1;     for (int i = ln - 1; i >= 0; i--) {       ans = (ans + (val[A[i] -  0 ] * nmpw)) % 1000000007;       nmpw = (nmpw * pw[A[i] -  0 ]) % 1000000007;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = (((1 << 30) - 1) << 1) + 1;   const int nINF = 1 << 31;   string s;   vector<int> v[2], ans;   int n, t;   void print(vector<int>& vec) {     for (int x : vec) cout << x <<    ;     cout << endl;   }   signed main() {     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       v[0].clear(), v[1].clear(), ans.clear();       cin >> n >> s;       bool good = true, two = false;       int lo = 10;       for (int i = 0; i < (n); i++) {         if (two) {           if (s[i] == lo && s[v[1].back()] == lo) {             v[1].push_back(i);           } else if (s[i] <= lo) {             if (!v[0].empty() && s[i] < s[v[0].back()]) {               good = false;               break;             } else {               v[0].push_back(i);             }           } else {             if (!v[1].empty() && s[i] < s[v[1].back()]) {               good = false;               break;             } else {               v[1].push_back(i);             }           }         } else {           if (!v[0].empty() && s[i] < s[v[0].back()]) {             two = true;             vector<int> temp;             while (!v[0].empty() && s[i] < s[v[0].back()]) {               temp.push_back(v[0].back());               v[0].pop_back();             }             lo = s[temp.back()];             while (!temp.empty()) {               v[1].push_back(temp.back());               temp.pop_back();             }           }           v[0].push_back(i);         }       }       ans.resize(n, 1);       for (int i = 0; i < (v[1].size()); i++) {         ans[v[1][i]] = 2;       }       if (!good)         cout <<  -  << endl;       else {         for (int x : ans) cout << x;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 0x3f3f3f3f3f3f3f3fll;   const int LGN = 25;   const int MOD = 1e9 + 7;   const int N = 3e5 + 5;   const int hashmod[] = {(int)1e9 + 7, (int)1e9 + 9};   const int hashlen = sizeof(hashmod) / sizeof(int);   struct Hash {     static long long mul;     static long long div[hashlen];     static long long power(long long a, long long b, long long m) {       long long ans = 1;       while (b > 0) {         if (b & 1) ans = (ans * a) % m;         b >>= 1;         a = (a * a) % m;       }       return ans;     }     static void init() {       static bool ok;       if (ok) return;       ok = true;       for (int i = 0; i < hashlen; i++) {         div[i] = power(mul, hashmod[i] - 2, hashmod[i]);       }     }     int h[hashlen];     Hash(char s) {       memset(h, 0, sizeof h);       operator+=(s);     }     Hash(const string& s =   ) {       memset(h, 0, sizeof h);       operator+=(s);     }     bool operator<(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return h[i] < o.h[i];       return false;     }     bool operator==(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return false;       return true;     }     bool operator!=(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return true;       return false;     }     Hash& operator+=(char s) {       int c = s + 1;       for (int i = 0; i < hashlen; i++) h[i] = (h[i] * mul + c) % hashmod[i];       return *this;     }     Hash& operator+=(const string& s) {       for (char c : s) operator+=(c);       return *this;     }     Hash& operator+=(const Hash& o) {       for (int i = 0; i < hashlen; i++) h[i] = (h[i] + o.h[i]) % hashmod[i];       return *this;     }     Hash& operator-=(char s) {       int c = s + 1;       for (int i = 0; i < hashlen; i++) {         h[i] = ((h[i] + hashmod[i] - c) * div[i]) % hashmod[i];       }       return *this;     }     Hash& operator-=(const string& s) {       for (int i = s.size() - 1; 0 <= i; i--) operator-=(s[i]);       return *this;     }     Hash& operator-=(const Hash& o) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] + hashmod[i] - o.h[i]) % hashmod[i];       }       return *this;     }     Hash& operator*=(long long pwr) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] * power(mul, pwr, hashmod[i])) % hashmod[i];       }       return *this;     }     Hash& operator/=(long long pwr) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] * power(div[i], pwr, hashmod[i])) % hashmod[i];       }       return *this;     }     Hash operator+(char s) const {       Hash ans = *this;       ans += s;       return ans;     }     Hash operator+(const string& s) const {       Hash ans = *this;       ans += s;       return ans;     }     Hash operator+(const Hash& o) const {       Hash ans = *this;       ans += o;       return ans;     }     Hash operator-(char s) const {       Hash ans = *this;       ans -= s;       return ans;     }     Hash operator-(const string& s) const {       Hash ans = *this;       ans -= s;       return ans;     }     Hash operator-(const Hash& o) const {       Hash ans = *this;       ans -= o;       return ans;     }     Hash operator*(long long pwr) const {       Hash ans = *this;       ans *= pwr;       return ans;     }     Hash operator/(long long pwr) const {       Hash ans = *this;       ans /= pwr;       return ans;     }   };   long long Hash::mul = 257;   long long Hash::div[hashlen];   int n, x[N * 2], y[N * 2];   char c[N * 2];   vector<int> T[N];   int depans[N];   Hash h[N];   int sub[N], big[N], dep[N], depcnt[N];   void dfs1(int u = 1, int p = 0, Hash h = 0, int d = 1) {     ::h[u] = h;     sub[u] = 1;     dep[u] = d;     depcnt[d]++;     for (int i : T[u])       if (y[i] != p) {         int v = y[i];         dfs1(v, u, h + c[i], d + 1);         sub[u] += sub[v];         if (sub[big[u]] < sub[v]) big[u] = v;       }   }   set<Hash> s[N];   void add(set<Hash>& tmp, int u, int p, Hash h) {     tmp.insert(h);     for (int i : T[u])       if (y[i] != p) add(tmp, y[i], u, h + c[i]);   }   void dfs2(int u = 1, int p = 0, bool keep = false) {     if (!big[u]) {       depans[dep[u]]++;       return;     }     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) dfs2(y[i], u);     dfs2(big[u], u, true), s[u].swap(s[big[u]]), s[u].insert(h[big[u]]);     set<Hash> sml;     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) add(sml, y[i], u, h[big[u]]);     int ans = s[u].size();     for (auto& h : sml)       if (!s[u].count(h)) ans++;     depans[dep[u]] += ans;     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) add(s[u], y[i], u, h[y[i]]);     if (!keep) s[u].clear();   }   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &(n));     int cnt = 0;     for (long long i = 2, __R = n; i <= __R; i++) {       int u, v;       scanf( %d%d , &(u), &(v));       char c[2];       scanf( %s , c);       x[++cnt] = u, y[cnt] = v, ::c[cnt] = c[0], T[u].push_back(cnt);       x[++cnt] = v, y[cnt] = u, ::c[cnt] = c[0], T[v].push_back(cnt);     }     dfs1();     dfs2();     int depsum = 0, ans = oo, p;     for (long long d = 1, __R = n; d <= __R; d++) {       depsum += depcnt[d - 1];       int alt = depsum + depans[d];       if (alt < ans) ans = alt, p = d;     }     printf( %d n%d n , ans, p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int n, m;   int popCount(int x) {     int count = 0;     while (x) {       ++count;       x &= x - 1;     }     return count;   }   inline bool Okay(int x) { return (((1 << m) - 1) & x) == ((1 << m) - 1); }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     if (n < m) swap(n, m);     int*** Arr = new int**[n + 1];     for (int i = 0; i <= n; ++i) {       Arr[i] = new int*[1 << m];       for (int j = 0; j < (1 << m); ++j) {         Arr[i][j] = new int[1 << m];         for (int k = 0; k < (1 << m); ++k) {           Arr[i][j][k] = 100000000;         }       }     }     Arr[0][(1 << m) - 1][0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < (1 << m); ++j) {         for (int k = 0; k < (1 << m); ++k) {           for (int t = 0; t < (1 << m); ++t) {             if (Okay(j | k | t | (k >> 1) | (k << 1)))               Arr[i + 1][k][t] =                   min(Arr[i + 1][k][t], Arr[i][j][k] + popCount(t));           }         }       }     }     int _ans = 100000;     for (int k = 0; k < (1 << m); ++k) {       for (int t = 0; t < (1 << m); ++t) {         if (Okay(k | t | (t << 1) | (t >> 1))) _ans = min(_ans, Arr[n][k][t]);       }     }     cout << n * m - _ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l, k;   double probs[200];   int bags[200];   double dp[201][410][201];   double solve(int index, int currCapacity, int wonTours) {     if (index == n) {       if (wonTours >= l) {         if (currCapacity >= 0)           return 1.0;         else           return 0.0;       } else {         return 0.0;       }     }     double &calculated = dp[index][currCapacity + 201][wonTours];     if (calculated + 1.0 > 1e-4) return calculated;     double ans = 0.0;     ans = probs[index] * solve(index + 1, min(405, currCapacity + bags[index]),                                wonTours + 1) +           (1.0 - probs[index]) * solve(index + 1, currCapacity, wonTours);     return calculated = ans;   }   int main() {     cin >> n >> l >> k;     memset(dp, -1.0, sizeof(dp));     for (int i = 0; i <= n - 1; i++) {       cin >> probs[i];       probs[i] /= 100.0;     }     for (int i = 0; i <= n - 1; i++) {       cin >> bags[i];     }     printf( %.10f , solve(0, k, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, sum = 0, t;     vector<int> a;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t;       sum += t;       a.push_back(sum);     }     cin >> n;     for (i = 0; i < n; i++) {       cin >> t;       cout << lower_bound(a.begin(), a.end(), t) - a.begin() + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n != 2) {       cout << 1 <<   n ;     } else {       cout << 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void DBG() {     cerr <<  ]           <<   n ;   }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   template <class H>   void DBG(vector<H> v) {     for (int i = 0; i < (int)v.size(); i++) {       cerr << v[i];       if (i != (int)v.size() - 1) cerr <<  ,  ;     }     cerr <<  ]  <<   n ;   }   long long randNum(long long a, long long b) { return a + rand() % (b - a + 1); }   long long mPow(long long b, long long p, long long m) {     b %= m;     long long result = 1;     while (p > 0) {       if (p & 1) result = (result * b) % m;       b = (b * b) % m;       p >>= 1;     }     return result;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long b, long long m) {     long long x, y;     long long g = gcdExtended(b, m, &x, &y);     if (g != 1) return -1;     return (x % m + m) % m;   }   long long modDivide(long long a, long long b, long long m) {     a = a % m;     long long inv = modInverse(b, m);     if (inv == -1)       return -1;     else       return (inv * a) % m;   }   unsigned long long nCrModPFermat(unsigned long long n, int r, int p) {     if (n < (unsigned long long)r) return 0;     if (r == 0) return 1;     unsigned long long fac[n + 1];     fac[0] = 1;     for (unsigned long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   bool sortfunc(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   const int dx4[4] = {-1, 0, 1, 0}, dy4[4] = {0, -1, 0, 1};   const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1},             dy8[8] = {0, 1, -1, -1, 1, 0, 1, -1};   void solve() {     vector<string> s;     int n, m;     cin >> n >> m;     string temp;     vector<int> cnt(m, 0);     for (int i = 0; i < n; i++) {       cin >> temp;       for (int j = 0; j < m; j++) {         if (temp[j] ==  1 ) {           cnt[j]++;         }       }       s.push_back(temp);     }     for (int i = 0; i < n; i++) {       bool flag = true;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  0  and cnt[j] == 0) {           flag = false;           break;         }         if (s[i][j] ==  1  and cnt[j] - 1 == 0) {           flag = false;           break;         }       }       if (flag) {         cout <<  YES               <<   n ;         return;       }     }     cout <<  NO           <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 100005, inf = 1000000005, mod = 1000000007;   const long long INF = 1000000000000000005LL;   const long double eps = (long double)1e-10;   long long det(pair<int, int> x, pair<int, int> y) {     return 1LL * x.first * y.second - 1LL * x.second * y.first;   }   long long det_pts(pair<int, int> x, pair<int, int> y, pair<int, int> z) {     y.first -= x.first;     y.second -= x.second;     z.first -= x.first;     z.second -= x.second;     return det(y, z);   }   long double detf(pair<long double, long double> x,                    pair<long double, long double> y) {     return x.first * y.second - x.second * y.first;   }   namespace hull {   vector<pair<int, int> > half_oto(vector<pair<int, int> >& P) {     vector<pair<int, int> > H;     for (auto p : P) {       while (H.size() > 1 && det_pts(H[H.size() - 2], H.back(), p) >= 0LL)         H.pop_back();       H.push_back(p);     }     return H;   }   vector<pair<int, int> > oto(vector<pair<int, int> > P) {     vector<pair<int, int> > L, U, ret;     sort((P).begin(), (P).end());     U = half_oto(P);     reverse((P).begin(), (P).end());     L = half_oto(P);     int su = U.size(), sl = L.size();     for (int i = 0; i < su; ++i) ret.push_back(U[i]);     for (int i = 1; i < sl - 1; ++i) ret.push_back(L[i]);     return ret;   }   };  // namespace hull   pair<long double, long double> daj(pair<long double, long double> a,                                      pair<long double, long double> b,                                      long double alfa) {     return {a.first * alfa + b.first * (1.0 - alfa),             a.second * alfa + b.second * (1.0 - alfa)};   }   long double P, Q;   long double wyn(pair<long double, long double> p) {     if (min(p.first, p.second) < eps) return (long double)INF;     return max(P / p.first, Q / p.second);   }   long double tern(pair<int, int> a, pair<int, int> b) {     pair<long double, long double> af = {(long double)a.first,                                          (long double)a.second};     pair<long double, long double> bf = {(long double)b.first,                                          (long double)b.second};     long double zd = 0.0, zg = 1.0;     for (int i = 1; i <= 60; ++i) {       long double one_th = (zg - zd) / 3.0, a1 = zd + one_th, a2 = zg - one_th;       pair<long double, long double> l = daj(af, bf, a1), r = daj(af, bf, a2);       if (wyn(l) > wyn(r))         zd = a1;       else         zg = a2;     }     long double alfa = (zd + zg) / 2.0;     return wyn(daj(af, bf, alfa));   }   int main() {     int n, p, q;     scanf( %d%d%d , &n, &p, &q);     P = p, Q = q;     vector<pair<int, int> > pts;     for (int i = 1; i <= n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       pair<int, int> p = {a, b};       pts.push_back(p);       p = {a, 0};       pts.push_back(p);       p = {0, b};       pts.push_back(p);     }     pts = hull::oto(pts);     int s = pts.size();     long double ans = (long double)INF;     for (int i = 1; i < s; ++i) {       auto cur_wyn = tern(pts[i - 1], pts[i]);       ans = min(ans, cur_wyn);     }     printf( %.9Lf , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long Llinf = LLONG_MAX;   const int Inf = INT_MAX;   const int Maxn = 400 + 10;   const int Mod = 1e9 + 7;   char* _c = new char[Maxn];   string GetString() {     scanf( %s , _c);     return string(_c);   }   int n;   string s[Maxn];   string ns[Maxn];   unordered_map<string, bool> m;   int ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) s[i] = GetString();     for (int i = 0; i < n; i++)       for (int j = 0; j < s[i].size(); j++) {         if (s[i][j] ==  u ) s[i][j] =  o , s[i].insert(j + 1,  o );         if (s[i][j] ==  h ) {           int k = j - 1;           while (k >= 0 && s[i][k] ==  k ) s[i][k] =  . , k--;         }       }     for (int i = 0; i < n; i++)       for (int j = 0; j < s[i].size(); j++)         if (s[i][j] !=  . ) ns[i].push_back(s[i][j]);     for (int i = 0; i < n; i++)       if (!m[ns[i]]) ans++, m[ns[i]] = true;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int digit, base, pos, n;     long long int sum = 0, sum_1 = 0, weight;     cin >> digit >> base;     pos = digit - 1;     for (int i = 0; i < digit; i++, pos--) {       cin >> n;       weight = base;       if (pos == 0) weight = 1;       for (int j = 1; j < pos; j++) {         weight *= base;       }       sum += n * weight;     }     cin >> digit >> base;     pos = digit - 1;     for (int i = 0; i < digit; i++, pos--) {       cin >> n;       weight = base;       if (pos == 0) weight = 1;       for (int j = 1; j < pos; j++) {         weight *= base;       }       sum_1 += n * weight;     }     if (sum == sum_1)       cout <<  =  << endl;     else if (sum > sum_1)       cout <<  >  << endl;     else       cout <<  <  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 200005;   struct node {     long long ab;     long long cab;   } a[maxn], b[maxn];   struct mon {     long long x, y, z;   } mo[maxn];   bool cmpab(struct node ab1, struct node ab2) { return ab1.ab < ab2.ab; }   bool cmpm(struct mon mo1, struct mon mo2) { return mo1.x < mo2.x; }   struct cmp1 {     bool operator()(const node &a, const node &b) const { return a.ab < b.ab; }   };   long long trb[4 * maxn + 1] = {0}, trbk[4 * maxn + 1] = {0};   void build(long long k, long long l, long long r, long long l1, long long r1,              long long val) {     if (l1 <= l && r <= r1) {       trbk[k] += val;     } else if (!(r < l1 || r1 < l)) {       long long m = (l + r) / 2;       trbk[k * 2 + 2] += trbk[k], trbk[k * 2 + 1] += trbk[k];       trbk[k] = 0;       build(k * 2 + 1, l, m, l1, r1, val);       build(k * 2 + 2, m + 1, r, l1, r1, val);       trb[k] =           max(trb[k * 2 + 1] + trbk[k * 2 + 1], trb[k * 2 + 2] + trbk[k * 2 + 2]);     } else {       return;     }   }   long long cal(long long k, long long l, long long r, long long l1,                 long long r1) {     if (l1 <= l && r <= r1) {       return trb[k] + trbk[k];     } else if (!(r < l1 || r1 < l)) {       long long m = (l + r) / 2;       trbk[k * 2 + 2] += trbk[k], trbk[k * 2 + 1] += trbk[k];       trbk[k] = 0;       trb[k] =           max(trb[k * 2 + 1] + trbk[k * 2 + 1], trb[k * 2 + 2] + trbk[k * 2 + 2]);       long long ans1 = cal(k * 2 + 1, l, m, l1, r1);       long long ans2 = cal(k * 2 + 2, m + 1, r, l1, r1);       return max(ans1, ans2);     } else {       return 0;     }   }   long long bi(long long l, long long r, long long val) {     long long m = (l + r) / 2;     if (l == r) {       return m;     } else if (b[m].ab <= val) {       return bi(m + 1, r, val);     } else {       return bi(l, m, val);     }   }   int main(void) {     long long n, m, p;     scanf( %lld%lld%lld , &n, &m, &p);     for (long long i = 0; i < n; i++) {       scanf( %lld%lld , &a[i].ab, &a[i].cab);     }     for (long long i = 0; i < m; i++) {       scanf( %lld%lld , &b[i].ab, &b[i].cab);     }     for (long long i = 0; i < p; i++) {       scanf( %lld%lld%lld , &mo[i].x, &mo[i].y, &mo[i].z);     }     sort(a, a + n, cmpab);     sort(b, b + m, cmpab);     sort(mo, mo + p, cmpm);     long long ma = -a[0].cab - b[0].cab;     long long monu = 0;     for (long long i = 0; i < m; i++) {       build(0, 0, m - 1, i, i, -b[i].cab);     }     for (long long i = 0; i < n; i++) {       while (a[i].ab > mo[monu].x && monu < p) {         if (mo[monu].y >= b[m - 1].ab) {           monu++;           continue;         }         long long num = bi(0, m - 1, mo[monu].y);         build(0, 0, m - 1, num, m - 1, mo[monu].z);         monu++;       }       ma = max(ma, -a[i].cab + cal(0, 0, m - 1, 0, m - 1));     }     printf( %lld , ma);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double m, n, c = 0, k = 0, a = 0, b = 0, d;     cin >> m >> n >> c >> d;     long double s1, s2, x, y;     a = (3 * m) / 10;     b = m - (m / 250) * c;     x = (3 * n) / 10;     y = n - (n / 250) * d;     s1 = max(a, b);     s2 = max(x, y);     if (s1 > s2)       cout <<  Misha  << endl;     else if (s1 < s2)       cout <<  Vasya  << endl;     else       cout <<  Tie  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long res;   const long long mod = 1073741824;   long long d(int a, int b, int c) {     vector<int> q(102, 0);     for (int i = 2; i <= a; i++)       if (a % i == 0) {         while (a % i == 0) {           a /= i;           q[i]++;         }       }     for (int i = 2; i <= b; i++)       if (b % i == 0) {         while (b % i == 0) {           b /= i;           q[i]++;         }       }     for (int i = 2; i <= c; i++)       if (c % i == 0) {         while (c % i == 0) {           c /= i;           q[i]++;         }       }     long long res = 1;     for (int i = 0; i < 102; i++) res = (res * (q[i] + 1)) % mod;     return res;   }   int main() {     int a, b, c;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++)       for (int j = 1; j <= b; j++)         for (int k = 1; k <= c; k++) res = (res % mod + d(i, j, k) % mod) % mod;     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   const int mod = 998244353;   long long d[N][N];   long long p[N];   long long inv[N];   long long _inv[N];   long long f[N];   void init(int n) {     d[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         d[i][j] =             (d[i - 1][j - 1] * (i - j + 1) % mod + d[i - 1][j] * j % mod) % mod;       }     }     p[0] = p[1] = inv[0] = inv[1] = _inv[0] = _inv[1] = 1;     for (int i = 2; i <= n; i++) {       p[i] = p[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       _inv[i] = _inv[i - 1] * inv[i] % mod;     }   }   int ans[N];   int main() {     int n;     cin >> n;     init(n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         ans[i] = (ans[i] + d[j][i] * _inv[j] % mod) % mod;       }     for (int i = 1; i <= n; i++) ans[i] = ans[i] * p[n] % mod;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   vector<pair<long long, long long> > g[N];   int n, m;   stack<int> st;   bool inStack[N];   int cmp[N], ind[N], low[N], cnt, cont;   void dfs(int x) {     ind[x] = low[x] = cnt++;     st.push(x);     inStack[x] = true;     for (int i = 0; i < g[x].size(); ++i) {       int y = g[x][i].first;       if (ind[y] == -1) {         dfs(y);         low[x] = min(low[x], low[y]);       } else if (inStack[y]) {         low[x] = min(low[x], ind[y]);       }     }     if (ind[x] == low[x]) {       int idx;       do {         idx = st.top();         st.pop();         inStack[idx] = 0;         cmp[idx] = cont;       } while (idx != x);       cont++;     }   }   inline void initTarjan() { memset(ind, -1, sizeof ind); }   bool componentProcessed[N];   vector<pair<long long, long long> > compressedGraph[N];   long long componentCost[N];   inline long long getCost(long long x) {     long long lo = 0, hi = 1000000LL;     while (lo < hi) {       long long md = (lo + hi + 1) >> 1;       if ((md * (md - 1)) / 2LL <= x)         lo = md;       else         hi = md - 1;     }     return x * lo - lo * (lo + 1) * (lo - 1) / 6LL;   }   long long pd[N];   long long func(int x) {     if (pd[x] != -1) return pd[x];     pd[x] = componentCost[x];     for (int i = 0; i < compressedGraph[x].size(); ++i) {       int y = compressedGraph[x][i].first;       long long w = compressedGraph[x][i].second;       pd[x] = max(pd[x], func(y) + w + componentCost[x]);     }     return pd[x];   }   int main() {     initTarjan();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       g[a].emplace_back(make_pair(b, c));     }     for (int i = 1; i <= n; ++i) {       if (ind[i] == -1) dfs(i);     }     int s;     scanf( %d , &s);     for (int x = 1; x <= n; ++x) {       for (int j = 0; j < g[x].size(); ++j) {         int y = g[x][j].first;         if (cmp[x] != cmp[y])           compressedGraph[cmp[x]].emplace_back(make_pair(cmp[y], g[x][j].second));         else           componentCost[cmp[x]] += getCost(g[x][j].second);       }     }     memset(pd, -1, sizeof pd);     printf( %lld n , func(cmp[s]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long ar[51];     vector<vector<long long>> price(5);     long long currentBalance = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     for (int i = 0; i < 5; i++) {       price[i].assign(2, 0);       cin >> price[i][0];     }     for (int i = 0; i < n; i++) {       currentBalance += ar[i];       for (int j = 4; j >= 0; j--) {         int k = currentBalance / price[j][0];         price[j][1] += k;         currentBalance -= k * price[j][0];       }     }     for (int i = 0; i < 5; i++) {       cout << price[i][1] <<    ;     }     cout <<   n  << currentBalance;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long a = 0, b = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) b = -1;       c = getchar();     }     while (isdigit(c)) {       a = a * 10 + c -  0 ;       c = getchar();     }     return a * b;   }   const long long N = 3e5 + 50, M = 6e5 + 50;   long long n, m, w[N], tot, h[N], nx[M], ver[M], ed[M], dat[N * 8], lazy[N * 8],       ans;   void add(long long u, long long v, long long z) {     ver[++tot] = v;     ed[tot] = z;     nx[tot] = h[u];     h[u] = tot;   }   void spread(long long p) {     if (lazy[p]) {       dat[(p << 1)] += lazy[p];       dat[(p << 1 | 1)] += lazy[p];       lazy[(p << 1)] += lazy[p];       lazy[(p << 1 | 1)] += lazy[p];       lazy[p] = 0;     }   }   void change(long long p, long long l, long long r, long long u, long long v,               long long z) {     if (l >= u && r <= v) {       dat[p] += z;       lazy[p] += z;       return;     }     spread(p);     long long mid = (l + r) >> 1;     if (u <= mid) change((p << 1), l, mid, u, v, z);     if (v > mid) change((p << 1 | 1), mid + 1, r, u, v, z);     dat[p] = max(dat[(p << 1)], dat[(p << 1 | 1)]);   }   signed main() {     n = read();     m = read();     for (register long long i = 1; i <= n; i++) {       w[i] = read();     }     for (register long long i = 1, u, v, z; i <= m; i++) {       u = read();       v = read();       z = read();       add(v, u, z);     }     for (register long long i = 1; i <= n; i++) {       change(1, 1, n, i, i, ans);       change(1, 1, n, 1, i, -w[i]);       for (register long long j = h[i]; j; j = nx[j]) {         change(1, 1, n, 1, ver[j], ed[j]);       }       ans = max(ans, dat[1]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   int n, m, a[N], rt, tot, L[N], siz[N], R[N], ls[N], rs[N];   long long val[N], dp[N][N];   inline void build(int &p, int l, int r) {     if (l > r) return;     p = ++tot;     int pos = l;     for (int i = l; i <= r; ++i)       if (a[i] < a[pos]) pos = i;     val[p] = a[pos];     build(ls[p], l, pos - 1);     build(rs[p], pos + 1, r);     dp[p][0] = 0;     dp[p][1] = m * val[p] - val[p];     siz[p] = 1;     for (int i = siz[p]; i >= 0; --i)       for (int j = 0; j <= siz[ls[p]]; ++j)         dp[p][i + j] =             max(dp[p][i + j], dp[p][i] + dp[ls[p]][j] - 2ll * i * j * val[p]);     siz[p] += siz[ls[p]];     for (int i = siz[p]; i >= 0; --i)       for (int j = 0; j <= siz[rs[p]]; ++j)         dp[p][i + j] =             max(dp[p][i + j], dp[p][i] + dp[rs[p]][j] - 2ll * i * j * val[p]);     siz[p] += siz[rs[p]];   }   int main() {     memset(dp, -0x3f, sizeof(dp));     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     build(rt, 1, n);     printf( %lld n , dp[1][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, w;   int v[100010];   long long mark[100010];   bool test(long long x) {     memset(mark, 0, sizeof mark);     long long qnt = 0;     long long sum = 0;     for (int i = 0; i < n; ++i) {       if (qnt > m) return false;       sum -= mark[i];       long long val = v[i] + sum;       if (val < x) {         qnt += x - val;         mark[min(i + w, n)] += x - val;         sum += x - val;       }     }     return qnt <= m;   }   long long bs(long long lo, long long hi) {     while (hi - lo > 1) {       long long mid = (hi + lo) / 2;       if (test(mid)) {         lo = mid;       } else         hi = mid;     }     if (test(hi)) return hi;     return lo;   }   int main(void) {     cin >> n >> m >> w;     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     cout << bs(0, 1000000000000000LL) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[105][5];   int n, Ans, b[105];   bool check(int i) {     for (int j = 1; j <= n; j++)       for (int k = j + 1; k <= n; k++)         if (i != j && i != k) {           long long tmp = 0;           for (int l = 1; l <= 5; l++)             tmp += (a[j][l] - a[i][l]) * (a[k][l] - a[i][l]);           if (tmp > 0) return 0;         }     return 1;   }   int main() {     scanf( %d , &n);     if (n > 66) {       puts( 0 );     } else {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= 5; j++) scanf( %I64d , &a[i][j]);       for (int i = 1; i <= n; i++) {         Ans += b[i] = check(i);       }       printf( %d n , Ans);       for (int i = 1; i <= n; i++)         if (b[i]) {           printf( %d n , i);         }     }   }


#include <bits/stdc++.h>   using namespace std;   void printReverseStack(stack<int> &ans) {     int x = ans.top();     ans.pop();     if (!ans.empty()) printReverseStack(ans);     cout << x <<    ;   }   int main() {     int n, d, l, x;     stack<int> ans;     cin >> n >> d >> l;     ans.push(d);     while (ans.size() < n) {       x = ans.top();       ans.pop();       if (x <= 0) {         ans.push(1);         ans.push(1 - x);       } else {         ans.push(l);         ans.push(l - x);       }     }     if (ans.top() <= 0 || ans.top() > l)       cout << -1;     else       printReverseStack(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + (c & 15), c = getchar();   }   const int P = 998244353;   int n, m;   char c[500001];   struct matrix {     int n, m, a[3][3];     inline matrix(int n = 0, int m = 0) : n(n), m(m) { memset(a, 0, sizeof(a)); }   } s[500001 << 2];   inline matrix operator*(const matrix &a, const matrix &b) {     matrix c(a.n, b.m);     for (int i = 1; i <= c.n; i++)       for (int k = 1; k <= a.m; k++)         for (int j = 1; j <= c.m; j++)           c.a[i][j] = (c.a[i][j] + (long long)a.a[i][k] * b.a[k][j]) % P;     return c;   }   inline void build(int p, int l, int r) {     if (l == r) {       s[p] = matrix(2, 2), s[p].a[1][2] = (c[l - 1] == 1 ? 9 - c[l] : 0),       s[p].a[2][1] = 1, s[p].a[2][2] = c[l] + 1;       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);     s[p] = s[p << 1] * s[p << 1 | 1];   }   inline void add(int p, int l, int r, int x) {     if (x > r || x < l) return;     if (l == r) {       s[p].a[1][2] = (c[l - 1] == 1 ? 9 - c[l] : 0), s[p].a[2][1] = 1,       s[p].a[2][2] = c[l] + 1;       return;     }     int mid = (l + r) >> 1;     if (mid >= x)       add(p << 1, l, mid, x);     else       add(p << 1 | 1, mid + 1, r, x);     s[p] = s[p << 1] * s[p << 1 | 1];   }   signed main() {     read(n), read(m), scanf( %s , c + 1);     for (int i = 1; i <= n; i++) c[i] -=  0 ;     build(1, 1, n);     while (m--) {       int x, y;       read(x), read(y), c[x] = y, add(1, 1, n, x), add(1, 1, n, x + 1);       matrix ans(1, 2);       ans.a[1][1] = ans.a[1][2] = 1;       ans = ans * s[1];       printf( %d n , ans.a[1][2]);     }     return 0;   }