#include <bits/stdc++.h>   using namespace std;   int main() {     int s, n, x, y;     cin >> s >> n;     vector<pair<int, int> > v;     pair<int, int> p;     for (int i = 0; i < n; i++) {       cin >> x >> y;       p = make_pair(x, y);       v.push_back(p);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       if (v[i].first < s)         s += v[i].second;       else {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10, maxm = 10000 + 10;   long long n, m, drt = 1, x = 1, y = 1, ans = 0, dis = 0, o = 0;   char mat[maxn][maxm];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       mat[i][0] =  # ;       mat[i][m + 1] =  # ;       for (int j = 1; j <= m; j++) {         cin >> mat[i][j];       }     }     while (x != n) {       if (mat[x][y + drt] ==  #  && o == 2) {         break;       }       if (mat[x + 1][y] ==  . ) {         x++;         dis = 0;         o = 0;       } else if (mat[x][y + drt] ==  # ) {         drt *= (-1);         y += (drt * dis);         ans += dis;         o++;       } else if (mat[x][y + drt] ==  + ) {         mat[x][y + drt] =  . ;         drt *= (-1);         y += (drt * dis);         ans += dis;         o = 0;       } else {         y += drt;         dis++;         o = 0;       }       ans++;     }     if (o == 2) {       cout <<  Never  << endl;     } else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 12, INF = 1e9 + 7;   int a[N];   int main() {     int n, m, i, j, k;     scanf( %d , &(n));     ;     vector<int> dp;     dp.push_back(-100001);     for (i = 0; i < (n); ++i) {       dp.push_back(100001);       scanf( %d , &(a[i]));       ;     }     for (i = 0; i < n; ++i) {       int j = int(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin());       if (dp[j - 1] < a[i] && a[i] < dp[j]) dp[j] = a[i];     }     for (i = 1; i <= n; ++i) {       if (dp[i] == 100001) break;     }     cout << i - 1;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int SIZE = 1e5 + 10;   int t[SIZE * 3], thing[SIZE * 3];   int main() {     int a, b, c, d, start, len, n;     scanf( %d%d%d%d%d%d%d , &n, &a, &b, &c, &d, &start, &len);     for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &thing[i]);     vector<int> T;     T.push_back(-1);     for (int i = 0; i < n; i++) T.push_back(t[i]);     int now = 0;     long long ori = start, ans = 0, MIN = 0;     for (int i = 0; i < n; i++) {       while (now < n && t[now] - t[i] < len) {         ans += thing[now] ? c : -d;         MIN = min(ans, MIN);         now++;       }       if (MIN + ori >= 0) {         printf( %d n , T[i] + 1);         return 0;       }       ans -= (thing[i] ? c : -d);       MIN -= (thing[i] ? c : -d);       ori += (thing[i] ? a : -b);       if (ori < 0) {         printf( -1 n );         return 0;       }     }     printf( %d n , T[n] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, x, y;   void upd(pair<int, int> &pos, char mv, int d) {     switch (mv) {       case  U :         pos.second += d;         break;       case  D :         pos.second -= d;         break;       case  L :         pos.first -= d;         break;       case  R :         pos.first += d;         break;     }   }   bool can(pair<int, int> u, pair<int, int> v, int len) {     int d = abs(u.first - v.first) + abs(u.second - v.second);     if ((d & 1) != (len & 1)) return false;     return len >= d;   }   bool ok(int len) {     pair<int, int> pos = make_pair(0, 0);     for (int i = len; i < n; ++i) upd(pos, s[i], 1);     int l = 0, r = len;     while (true) {       if (can(pos, make_pair(x, y), len)) return true;       if (r == n) break;       upd(pos, s[l++], 1);       upd(pos, s[r++], -1);     }     return false;   }   int main() {     cin >> n >> s >> x >> y;     if (!ok(n)) {       cout << -1 << endl;       return 0;     }     int l = 0, r = n;     while (l < r) {       int m = (l + r) >> 1;       if (ok(m))         r = m;       else         l = m + 1;     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const long long int INF = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     long long int i, j, k, a, b, flag = 0, m, n, q, sum, x, y, temp = 1, l, r, g,                                  ans = LLONG_MAX, idx = 0;     cin >> n;     vector<pair<long long int, long long int> > arr;     long long int front[n], back[n];     for (i = 0; i < n; i++) {       cin >> a;       arr.push_back(make_pair(a, i + 1));     }     sort(arr.begin(), arr.end());     front[n - 2] = back[n - 2] = arr[n - 1].second;     for (i = n - 3; i >= 0; i--) {       front[i] = min(front[i + 1], arr[i + 1].second);       back[i] = max(back[i + 1], arr[i + 1].second);     }     for (i = 0; i < n - 1; i++) {       idx = max(abs(arr[i].second - front[i]), abs(arr[i].second - back[i]));       if (arr[i].first < idx)         temp = 0;       else {         temp = arr[i].first / idx;       }       ans = min(ans, temp);       if (ans == 0) break;     }     if (ans == LLONG_MAX) ans = 0;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     while (cin >> str) {       int len = str.size();       int times = 0;       int c = 0, p = 0;       char tmp;       for (int i = int(0); i <= int(len - 1); i++) {         c = 0, p = 0;         tmp = str[i];         if (tmp ==  C ) {           while (str[i] == tmp && i < len) {             c++;             if (c > 5) {               break;             }             i++;           }           i--;           times++;         }         if (tmp ==  P ) {           while (str[i] == tmp && i < len) {             p++;             if (p > 5) {               break;             }             i++;           }           i--;           times++;         }       }       cout << times << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   int* array;   int f(int index) {     if (array[index] == -1) {       array[index] = index;       return index;     }     if (array[index] == index) return index;     int r = f(array[index]);     array[index] = r;     return r;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int coils = 0;     int connect[n];     array = connect + 0;     int notcoils[n];     for (int i = 0; i < n; i++) {       connect[i] = -1;       notcoils[i] = 0;     }     for (int i = 0; i < m; i++) {       int b, e;       scanf( %d %d , &b, &e);       --b;       --e;       if (b == e) {         if (connect[b] == -1) connect[b] = b;         ++coils;       } else {         int rootb = f(b);         int roote = f(e);         connect[roote] = rootb;         ++notcoils[b];         ++notcoils[e];       }     }     int notcoilsTotal = m - coils;     int r = -1;     for (int i = 0; i < n; i++) {       if (connect[i] != -1)         if (f(i) != r) {           if (r == -1)             r = connect[i];           else {             printf( %d , 0);             return 0;           }         }     }     long long ans = coils;     ans = ans * (ans - 1) / 2 + notcoilsTotal * ans;     for (int i = 0; i < n; i++) {       long long nc = notcoils[i];       ans += nc * (nc - 1) / 2;     }     std::cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 2e5 + 34;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  ( ;     os << v.first <<  ,  << v.second <<  ) ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     int sz = v.size();     for (int i = 0; i < sz; ++i) {       os << v[i];       if (i != sz - 1) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     T last = *v.rbegin();     os <<  [ ;     for (auto it : v) {       os << it;       if (it != last) os <<  , ;     }     os <<  ] n ;     return os;   }   vector<int> fact[MM];   void pre() {     for (int i = 1; i < MM; i++) {       for (int j = i; j < MM; j += i) {         fact[j].push_back(i);       }     }   }   int dp[MM];   bool done[MM];   int ans[MM];   int cnt = 100;   int grund(int x) {     if ((x & (x - 1)) == 0) {       done[x] = 1;       dp[x] = 0;     }     if (done[x]) {       return dp[x];     }     int maxx = fact[2 * x].size() + 5;     vector<bool> mex(maxx, 0);     for (int u : fact[2 * x]) {       if (u == 1) {         continue;       }       int cnt = u;       int st = (((2 * x) / u) + 1 - u) / 2;       if ((((2 * x) / u) + 1 - u) % 2) {         continue;       }       int cur = 0;       if (st <= 0) {         break;       }       for (int i = 0; i < cnt; i++) {         cur ^= grund(st + i);       }       if (cur == 0) {         ans[x] = min(ans[x], cnt);       }       if (cur < maxx) {         mex[cur] = 1;       }     }     done[x] = 1;     while (mex[dp[x]]) {       dp[x]++;     }     return dp[x];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pre();     int N;     cin >> N;     ans[N] = 1e9;     int u = grund(N);     if (u == 0) {       cout << -1 <<   n ;       return 0;     }     cout << ans[N];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, dp[200000];   vector<long long> bit(200000, 0);   void update(long long x, long long val) {     while (x <= n) {       bit[x] ^= val;       x += x & -x;     }   }   long long query(long long x) {     long long ans = 0;     while (x) {       ans ^= bit[x];       x -= x & -x;     }     return ans;   }   long long mex(vector<long long> v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), v.end());     v.push_back(1000000000000000000);     long long i = 0;     while (v[i] == i) i++;     return i;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> n;     for (long long i = 3; i < n + 1; i++) {       vector<long long> v;       for (long long j = 2; j * (j + 1) / 2 <= i; j++) {         if ((2 * i - j * (j + 1)) % (2 * j) != 0) continue;         long long l = (2 * i - j * (j + 1)) / (2 * j) + 1;         long long r = l + j - 1;         v.push_back(query(r) ^ query(l - 1));       }       dp[i] = mex(v);       update(i, dp[i]);     }     if (!dp[n])       cout <<  -1 n ;     else {       for (long long j = 2; j * (j + 1) / 2 <= n; j++) {         if ((2 * n - j * (j + 1)) % (2 * j) != 0) continue;         long long l = (2 * n - j * (j + 1)) / (2 * j) + 1;         long long r = l + j - 1;         if ((query(r) ^ query(l - 1)) == 0) return cout << j <<   n , 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mxnn = 300000 + 10, inf = 0x3f3f3f3f;   int n, q, a, cnt;   int head[mxnn], son[mxnn], ans[mxnn], fa[mxnn];   struct node {     int u, v, next;   } e[mxnn << 1];   void adde(int u, int v) {     e[++cnt].u = u;     e[cnt].v = v;     e[cnt].next = head[u];     head[u] = cnt;   }   void read(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = getchar();     }     x *= f;   }   void dfs(int u, int va) {     ans[u] = u;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       dfs(v, u);       son[u] += son[v];     }     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       if (son[v] * 2 > son[u]) {         ans[u] = ans[v];         break;       }     }     while (son[u] > 2 * son[ans[u]]) ans[u] = fa[ans[u]];   }   int main() {     memset(head, -1, sizeof head);     read(n), read(q);     for (int i = 1; i <= n; ++i) son[i] = 1;     for (int i = 2; i <= n; ++i) {       read(a);       adde(a, i);       adde(i, a);       fa[i] = a;     }     dfs(1, 0);     while (q--) {       read(a);       printf( %d n , ans[a]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > v(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> v[i][j];       }     }     vector<vector<int> > res(n, vector<int>(m));     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         if (i == 0)           res[i][j] = 0;         else {           if (v[i][j] >= v[i - 1][j])             res[i][j] = res[i - 1][j];           else             res[i][j] = i;         }       }     }     vector<int> ans(n);     for (int i = 0; i < n; i++) {       int curres = 0;       for (int j = 0; j < m; j++) {         int c = res[i][j];         if (res[i][j] < res[i][curres]) {           curres = j;         }       }       ans[i] = res[i][curres];     }     int k;     cin >> k;     for (int i = 0; i < k; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       if (ans[r] <= l)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 51;   const int mod = (int)1e9 + 7;   long long dp0[N][N];   long long dp1[N][N];   long long C[N][N];   inline long long modpow(long long x, long long p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % mod;       x = x * x % mod;       p >>= 1;     }     return res;   }   void solve() {     long long i2 = modpow(2, mod - 2);     C[0][0] = 1;     for (int i = 1; i < N; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;       }     }     memset(dp0, 0, sizeof(dp0));     memset(dp1, 0, sizeof(dp1));     int n, K;     cin >> n >> K;     dp1[0][0] = 1;     dp0[1][0] = 1;     for (int sz = 2; sz <= n; sz++) {       for (int k = 0; k <= sz / 2; k++) {         for (int szl = 0; szl < sz; szl++) {           int szr = sz - 1 - szl;           if (szl > szr) break;           long long enumerate = sz == n ? 1 : sz;           enumerate = enumerate * C[sz - 1][szl] % mod;           for (int kl = 0; kl <= k; kl++) {             if (szl == szr && kl > k - kl) break;             if (szl == szr && kl == k - kl) enumerate = enumerate * i2 % mod;             dp0[sz][k] += dp1[szl][kl] * dp1[szr][k - kl] % mod * enumerate;             dp0[sz][k] %= mod;             dp1[sz][k + 1] += (dp1[szl][kl] * dp0[szr][k - kl] +                                dp0[szl][kl] * dp1[szr][k - kl] +                                dp0[szl][kl] * dp0[szr][k - kl]) %                               mod * enumerate;             dp1[sz][k + 1] %= mod;             if (szl == szr && kl == k - kl) enumerate = enumerate * 2 % mod;           }         }       }     }     cout << (dp0[n][K] + dp1[n][K]) % mod << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n = 0, temp1 = 0, temp2 = 0;     cin >> n;     std::vector<long long int> v1;     std::vector<long long int> v2;     long long int hash1[100001], hash2[100001];     for (long long int i = 0; i < 100001; ++i) {       hash1[i] = 0;       hash2[i] = 0;     }     for (long long int i = 0; i < n; ++i) {       cin >> temp1 >> temp2;       v1.push_back(temp1);       v2.push_back(temp2);     }     for (long long int i = 0; i < n; ++i) {       hash1[v1[i]]++;       hash2[v2[i]]++;     }     for (long long int i = 0; i < n; ++i) {       cout << (n - 1 + hash1[v2[i]]) <<     << (n - 1 - hash1[v2[i]]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long row[1000], col[1000];   char ch[1000][1000];   list<int> ax, ay;   int main() {     int i, j, x, y;     long long res = 0;     cin >> x >> y;     memset((row), (-1), sizeof((row)));     memset((col), (-1), sizeof((col)));     for (i = 0; i < x; i++) {       for (j = 0; j < y; j++) {         cin >> ch[i][j];         if (ch[i][j] ==  * ) {           ax.push_back(i);           ay.push_back(j);           row[i]++;           col[j]++;         }       }     }     list<int>::iterator it, it2;     it = ax.begin();     it2 = ay.begin();     while (it != ax.end()) {       if (row[*it] >= 1 && col[*it2] >= 1) res += row[*it] * col[*it2];       it++;       it2++;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, L, a;   void read() {     int x = 0, y = 0, lx = 0, ly = 0, ans = 0;     scanf( %d %d %d , &n, &L, &a);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x, &y);       ans += (x - (lx + ly)) / a;       lx = x;       ly = y;     }     ans += (L - (x + y)) / a;     printf( %d n , ans);   }   int main() {     read();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long a, long long b, long long MOD) {     long long res = 1;     a %= MOD;     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   const int N = 1e5 + 5;   double pos[N];   double getExpe(int l, int r, int p) {     int ans = ((r / p) - ((l - 1) / p));     return double(ans) / (r - l + 1);   }   double calculate(int x, int n, int p) {     int l = (x == 1 ? n : x - 1);     int r = (x == n ? 1 : x + 1);     return pos[x] * (2.0 - pos[l] / 2 - pos[r] / 2);   }   int main() {     int l, r, n, p;     double ans = 0.0;     scanf( %d%d , &n, &p);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       pos[i] = getExpe(l, r, p);     }     for (int i = 1; i <= n; i++) {       ans += calculate(i, n, p);     }     printf( %.9f n , ans * 1000.0 * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 200000;   long long const inf = 1e18;   int w[N + 1], h[N + 1];   long long dp[N + 1][2];   vector<int> tr[N + 1];   void up(long long &x, long long y) {     if (y < x) x = y;   }   void fn(int v, vector<long long> const &ch, long long s, int in, int out,           bool d) {     for (int i = 0; i < (int)(ch.size() + 1); ++i) {       if (i) {         s += ch[i - 1];         --out;         ++in;       }       up(dp[v][d], s + (long long)w[v] * max(in, out));     }   }   void go(int v = 1, int p = 0) {     dp[v][0] = dp[v][1] = inf;     vector<long long> ch;     int in = 0, out = 0;     long long s = 0;     for (int u : tr[v])       if (u != p) {         go(u, v);         if (dp[u][0] < inf) {           ++out;           s += dp[u][0];           if (dp[u][1] < inf) ch.push_back(dp[u][1] - dp[u][0]);         } else {           ++in;           s += dp[u][1];         }       }     sort(ch.begin(), ch.end());     if (p) {       if (h[v] <= h[p]) fn(v, ch, s, in, out + 1, true);       if (h[v] >= h[p]) fn(v, ch, s, in + 1, out, false);     } else       fn(v, ch, s, in, out, false);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < (int)(n + 1); ++i) scanf( %d , w + i);     for (int i = 1; i < (int)(n + 1); ++i) scanf( %d , h + i);     for (int i = 1; i < (int)(n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       tr[a].push_back(b);       tr[b].push_back(a);     }     go();     printf( %lld n , dp[1][0]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n;   long long sol(long long* data) {     long long ans = 0, fang = 0, sum = 0;     for (int i = 1; i <= n; i++) {       ans += data[i] * data[i] * (i - 1);       ans -= sum * data[i] * 2;       ans += fang;       fang += data[i] * data[i];       sum += data[i];     }     return ans;   }   long long x[maxn], y[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld%lld , x + i, y + i);     sort(x + 1, x + n + 1);     sort(y + 1, y + n + 1);     cout << sol(x) + sol(y) << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point() {}     point(int a, int b) { x = a, y = b; }   };   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T power(T n, T p) {     T res = 1;     for (int i = 0; i < p; i++) res *= n;     return res;   }   template <class T>   double getdist(T a, T b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   template <class T>   T extract(string s, T ret) {     stringstream ss(s);     ss >> ret;     return ret;   }   template <class T>   string tostring(T n) {     stringstream ss;     ss << n;     return ss.str();   }   long long mod = 1000000009;   long long arr[300010], F[300010];   namespace fibonacci {   void gen(int n) {     F[1] = F[2] = 1;     for (int i = 3; i <= n; i++) F[i] = (F[i - 1] + F[i - 2]) % mod;   }   long long kth_fibo(long long f1, long long f2, long long k) {     if (k == 1) return f1;     if (k == 2) return f2;     long long ret = (F[k - 1] * f2) % mod;     ret += (F[k - 2] * f1) % mod;     ret %= mod;     return ret;   }   long long sum(long long f1, long long f2, long long k) {     long long ret = (kth_fibo(f1, f2, k + 2) - f2) % mod;     ret += mod;     return ret % mod;   }   }  // namespace fibonacci   struct node {     long long f1, f2, sum;     node(long long sum = 0, long long f1 = 0, long long f2 = 0)         : sum(sum), f1(f1), f2(f2){};     void add(long long _f1, long long _f2, long long k) {       f1 += _f1;       f2 += _f2;       f1 %= mod;       f2 %= mod;       sum += fibonacci::sum(_f1, _f2, k);       sum %= mod;     }   };   node segtree[300010 * 4];   void build(int l, int r, int cur) {     if (l == r) {       segtree[cur] = node(arr[l] % mod);       return;     }     int lchild = cur << 1, rchild = lchild | 1, m = (l + r) >> 1;     build(l, m, lchild);     build(m + 1, r, rchild);     segtree[cur].sum = segtree[lchild].sum + segtree[rchild].sum;     segtree[cur].sum %= mod;   }   void push_down(int l, int r, int cur) {     if (segtree[cur].f1 == 0 && segtree[cur].f2 == 0) return;     if (l == r) return;     int lchild = cur << 1, rchild = lchild | 1, m = (l + r) >> 1;     long long f1, f2, nf1, nf2;     f1 = segtree[cur].f1;     f2 = segtree[cur].f2;     segtree[lchild].add(f1, f2, m - l + 1);     nf1 = fibonacci::kth_fibo(f1, f2, max(1, m - l + 2));     nf2 = fibonacci::kth_fibo(f1, f2, max(2, m - l + 3));     segtree[rchild].add(nf1, nf2, r - m);     segtree[cur].sum = segtree[lchild].sum + segtree[rchild].sum;     segtree[cur].sum %= mod;     segtree[cur].f1 = segtree[cur].f2 = 0;   }   void update(int L, int R, int l, int r, int cur) {     push_down(l, r, cur);     if (l > R || r < L) return;     if (l >= L && r <= R) {       long long f1 = F[l - L + 1];       long long f2 = F[l - L + 2];       segtree[cur].add(f1, f2, r - l + 1);       return;     }     int lchild = cur << 1, rchild = lchild | 1, m = (l + r) >> 1;     update(L, R, l, m, lchild);     update(L, R, m + 1, r, rchild);     segtree[cur].sum = segtree[lchild].sum + segtree[rchild].sum;     segtree[cur].sum %= mod;   }   long long query(int L, int R, int l, int r, int cur) {     push_down(l, r, cur);     if (l > R || r < L) return 0;     if (l >= L && r <= R) return segtree[cur].sum;     int lchild = cur << 1, rchild = lchild | 1, m = (l + r) >> 1;     return (query(L, R, l, m, lchild) + query(L, R, m + 1, r, rchild)) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, i, q, l, r;     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> arr[i];     fibonacci::gen(n);     build(1, n, 1);     while (m--) {       cin >> q >> l >> r;       if (q == 1)         update(l, r, 1, n, 1);       else         cout << query(l, r, 1, n, 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e4;   vector<string> pri;   string s;   int X, n;   bool check(string cur) {     for (int i = 0; i < cur.size(); i++) {       int sum = 0;       for (int j = i; j < cur.size(); j++) {         sum += cur[j] -  0 ;         if (sum < X && X % sum == 0) return 0;       }     }     return 1;   }   void generate(string cur, int sum) {     if (sum == X) {       if (check(cur)) pri.push_back(cur);       return;     }     for (int i = 1; i < 10 && sum + i <= X; i++)       generate(cur + (char)(i +  0 ), sum + i);   }   int cnt, nxt[100000][10], fal[100000];   bool flg[100000];   void add(string s) {     int cur = 0;     for (int i = 0; i < s.size(); i++) {       if (!nxt[cur][s[i] -  0 ]) nxt[cur][s[i] -  0 ] = ++cnt;       cur = nxt[cur][s[i] -  0 ];     }     flg[cur] = 1;   }   void getnxt() {     queue<int> que;     for (int i = 1; i < 10; i++)       if (nxt[0][i]) {         fal[nxt[0][i]] = 0;         que.push(nxt[0][i]);       }     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = 1; i < 10; i++) {         if (nxt[u][i]) {           fal[nxt[u][i]] = nxt[fal[u]][i];           que.push(nxt[u][i]);         }       }       for (int i = 1; i < 10; i++)         if (nxt[u][i] < 1) nxt[u][i] = nxt[fal[u]][i];     }   }   int main() {     cin >> s >> X, n = s.size();     generate(  , 0);     for (int i = 0; i < pri.size(); i++) add(pri[i]);     getnxt();     vector<int> dp(cnt + 1, INF);     dp[0] = 0;     for (int i = 0; i < n; i++) {       vector<int> dps(cnt + 1, INF);       for (int j = 0; j <= cnt; j++)         if (dp[j] < INF) {           dps[j] = min(dps[j], dp[j] + 1);           if (!flg[nxt[j][s[i] -  0 ]])             dps[nxt[j][s[i] -  0 ]] = min(dps[nxt[j][s[i] -  0 ]], dp[j]);         }       swap(dp, dps);     }     cout << (*min_element(dp.begin(), dp.end()));   }


#include <bits/stdc++.h>   using namespace std;   int BIN[30], P[1000005], vis[1000005];   int _bin(int n) {     int i, now;     for (i = 0; BIN[i] <= n; i++) now = BIN[i];     return BIN[i];   }   int main() {     int i, j, n, k, now, t;     long long ans = 0;     for (i = 1, BIN[0] = 1; i < 30; i++) BIN[i] = BIN[i - 1] * 2;     for (scanf( %d , &n), i = n; i; i--)       if (vis[i] == 0) {         now = _bin(i);         t = (now - 1) ^ i;         ans += t + i + t + i;         P[i] = t, P[t] = i;         vis[t] = 1;       }     for (i = 0, printf( %I64d n , ans); i <= n; i++)       printf( %d%c , P[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 2e5 + 5;   long long rowdp[101][101];   vector<long long> a[101];   void f(long long id) {     vector<long long> dp(101, 0);     for (long long i = 0; i < a[id].size(); ++i) {       if (i == 0)         dp[i] = a[id][i];       else         dp[i] = dp[i - 1] + a[id][i];     }     long long tot = rowdp[id][a[id].size()] = dp[a[id].size() - 1];     for (long long l = 1; l <= a[id].size(); ++l) {       for (long long i = 0; i + l - 1 < a[id].size(); ++i) {         long long curr = 0;         if (i) curr = dp[i - 1];         rowdp[id][a[id].size() - l] =             max(rowdp[id][a[id].size() - l], tot - (dp[i + l - 1] - curr));       }     }   }   long long dp[101][10001];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     for (long long i = 0; i < n; ++i) {       long long x;       cin >> x;       while (x--) {         long long y;         cin >> y;         a[i].emplace_back(y);       }       f(i);     }     long long tot = 0;     for (long long i = 0; i < n; ++i) {       if (i) {         for (long long j = 0; j <= min(m, tot); ++j) {           for (long long k = 0; k <= a[i].size(); ++k) {             if (j + k > m) continue;             dp[i][j + k] = max(dp[i][j + k], dp[i - 1][j] + rowdp[i][k]);           }         }       } else {         for (long long j = 1; j <= a[0].size(); ++j) {           dp[0][j] = rowdp[0][j];         }       }       tot += a[i].size();     }     cout << dp[n - 1][m] <<   n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   int main() {     int n, size = 1, arr[200005], arr1[200005];     long long sum = 0;     memset(arr, 0, sizeof(arr));     memset(arr1, 0, sizeof(arr1));     cin >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a == 1) {         int b, c;         cin >> b >> c;         arr[b - 1] += c;         sum += b * c;       } else if (a == 2) {         int b;         cin >> b;         arr1[size] = b;         sum += b;         size++;       } else {         size--;         sum -= arr1[size];         arr1[size] = 0;         sum -= arr[size];         arr[size - 1] += arr[size];         arr[size] = 0;       }       printf( %.15f n , 1.0 * sum / size);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cp(int a, int b) { return a > b; }   int main() {     int a[55], i, j, k, l, coun, flag;     int n;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + n + 1, cp);     if (k <= n) {       for (i = 1; i <= k; i++) {         printf( 1 %d n , a[i]);       }     } else {       for (i = 1; i <= n; i++) {         printf( 1 %d n , a[i]);       }       coun = n;       flag = 0;       for (i = 2; i <= n; i++) {         for (j = i; j <= n; j++) {           printf( %d , i);           for (l = 1; l < i; l++) {             printf(  %d , a[l]);           }           printf(  %d n , a[j]);           coun++;           if (coun >= k) {             flag = 1;             break;           }         }         if (flag == 1) {           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 100000005;   const int p = 31;   const int mod = (1 << 8) - 1;   char s[200005];   const int siz = 5;   struct node {    public:     int c[5][5];     void out() {       for (int i = 0; i < siz; i++) {         for (int j = 0; j < siz; j++) {           printf( %8d  , c[i][j]);         }         puts(  );       }       puts(  );     }     node operator^(long long m) {       int i;       node tmp, a = (*this);       memset(tmp.c, 0, sizeof(tmp.c));       for (i = 1; i <= siz; i++) tmp.c[i][i] = 1;       while (m) {         if (m & 1) {           tmp = (tmp * a);         }         a = (a * a);         m >>= 1;       }       return tmp;     }     node operator*(node& b) {       node tmp;       int i, j, k;       for (i = 0; i < siz; i++)         for (j = i; j < siz; j++) {           tmp.c[i][j] = INF;           for (k = i; k <= j; k++)             tmp.c[i][j] = min(tmp.c[i][j], c[i][k] + b.c[k][j]);           if (tmp.c[i][j] > INF) tmp.c[i][j] = INF;         }       return tmp;     }     node operator+(node& b) {       node tmp;       int i, j;       for (i = 1; i <= siz; i++)         for (j = 1; j <= siz; j++) {           tmp.c[i][j] = (c[i][j] + b.c[i][j]) % mod;         }       return tmp;     }     void init() {       for (int i = 0; i < siz; i++)         for (int j = i; j < siz; j++) c[i][j] = INF;     }   };   struct Tree {     node a;     int l, r;   } tr[200005 << 2];   int n;   void upd(int x, int num) {     int i, j;     for (i = 0; i < siz; i++) tr[x].a.c[i][i] = 0;     if (num == 6) tr[x].a.c[3][3] = tr[x].a.c[4][4] = 1;     if (num == 2) tr[x].a.c[0][1] = 0, tr[x].a.c[0][0] = 1;     if (num == 0) tr[x].a.c[1][2] = 0, tr[x].a.c[1][1] = 1;     if (num == 1) tr[x].a.c[2][3] = 0, tr[x].a.c[2][2] = 1;     if (num == 7) tr[x].a.c[3][4] = 0, tr[x].a.c[3][3] = 1;   }   void pushup(int x) { tr[x].a = tr[x << 1].a * tr[x << 1 | 1].a; }   void build(int l, int r, int x) {     tr[x].l = l, tr[x].r = r;     tr[x].a.init();     if (l == r) {       upd(x, s[l] -  0 );       return;     }     int mid = (l + r) / 2;     build(l, mid, x << 1);     build(mid + 1, r, x << 1 | 1);     pushup(x);   }   node query(int L, int R, int x) {     int l = tr[x].l, r = tr[x].r;     if (l == L && R == r) {       return tr[x].a;     }     int mid = (l + r) / 2;     if (R <= mid)       return query(L, R, x << 1);     else if (L > mid)       return query(L, R, x << 1 | 1);     else {       node nw, n1, n2;       nw.init();       n1 = query(L, mid, x << 1);       n2 = query(mid + 1, R, x << 1 | 1);       nw = n1 * n2;       return nw;     }   }   int main() {     int l, r, i, j, m;     scanf( %d %d , &n, &m);     scanf( %s , s + 1);     build(1, n, 1);     while (m--) {       scanf( %d %d , &l, &r);       node nw;       nw = query(l, r, 1);       if (nw.c[0][4] == INF)         printf( -1 n );       else         printf( %d n , nw.c[0][4]);     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, c = 0, j = 0, index[3], sum = 0, avg;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     avg = sum / n;     if (avg * n != sum)       cout <<  Unrecoverable configuration. ;     else {       for (i = 0; i < n; i++) {         if (a[i] == avg)           c++;         else {           index[j] = i;           j++;         }         if (j == 3) break;       }       if (c == n)         cout <<  Exemplary pages. ;       else if (c == n - 2) {         if (a[index[1]] > a[index[0]])           cout << (a[index[1]] - a[index[0]]) / 2 <<   ml. from cup #                 << index[0] + 1 <<   to cup #  << index[1] + 1 <<  . ;         else           cout << (a[index[0]] - a[index[1]]) / 2 <<   ml. from cup #                 << index[1] + 1 <<   to cup #  << index[0] + 1 <<  . ;       } else         cout <<  Unrecoverable configuration. ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, a, b;     cin >> n >> k >> a >> b;     if (k == 1) {       cout << (n - 1) * a << endl;       return 0;     }     long long ans = 0;     while (n != 1) {       if (n >= k) {         long long md = n % k;         ans += md * a;         n -= md;         long long prev = n;         long long curr = n / k;         ans += min(a * (prev - curr), b);         n /= k;       } else if (n < k) {         ans += (n - 1) * a;         break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dcmp(double a, double b) {     return fabs(a - b) <= 0.0000000001 ? 0 : (a > b) ? 1 : -1;   }   int main() {     int x1, y1, x2, y2, r1, r2, R1, R2;     cin >> x1 >> y1 >> r1 >> R1 >> x2 >> y2 >> r2 >> R2;     double dis = sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));     int ans = 0;     if (dcmp(abs(dis - r1), R2) != -1 || dcmp(dis + r1, r2) != 1) ans++;     if (dcmp(abs(dis - R1), R2) != -1 || dcmp(dis + R1, r2) != 1) ans++;     if (dcmp(abs(dis - r2), R1) != -1 || dcmp(dis + r2, r1) != 1) ans++;     if (dcmp(dis + R2, r1) != 1 || dcmp(abs(dis - R2), R1) != -1) ans++;     cout << ans << endl;   }


#include <bits/stdc++.h>   template <class T>   inline void chkmax(T &x, const T &y) {     if (x < y) x = y;   }   template <class T>   inline void chkmin(T &x, const T &y) {     if (x > y) x = y;   }   template <class T>   inline void read(T &x) {     char c;     int f = 1;     x = 0;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     if (c ==  - )       f = -1;     else       x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= f;   }   int outn;   char out[(int)2e7];   template <class T>   inline void write(T x) {     if (x < 0) out[outn++] =  - , x = -x;     if (x) {       static int tmpn;       static char tmp[20];       tmpn = 0;       while (x) tmp[tmpn++] = x % 10 +  0 , x /= 10;       while (tmpn) out[outn++] = tmp[--tmpn];     } else       out[outn++] =  0 ;   }   const int N = 1e5;   const double lim = 1.8 * CLOCKS_PER_SEC;   const double eps = 1e-8;   int n, k;   struct pot {     double x, y;     pot() { x = y = 0; }     pot(double _x, double _y) : x(_x), y(_y) {}     inline friend pot operator+(const pot &p, const pot &q) {       return pot(p.x + q.x, p.y + q.y);     }     inline friend pot operator-(const pot &p, const pot &q) {       return pot(p.x - q.x, p.y - q.y);     }     inline friend double operator*(const pot &p, const pot &q) {       return p.x * q.x + p.y * q.y;     }     inline friend double operator^(const pot &p, const pot &q) {       return p.x * q.y - p.y * q.x;     }     inline friend pot operator*(const pot &p, const double &k) {       return pot(p.x * k, p.y * k);     }     inline friend pot operator/(const pot &p, const double &k) {       return pot(p.x / k, p.y / k);     }   };   struct line {     pot p, v;     line() {}     line(pot _p, pot _v) : p(_p), v(_v) {}     line(int a, int b, int c) {       if (!b)         p = pot((double)-c / a, 0), v = pot(0, 1);       else if (!a)         p = pot(0, (double)-c / b), v = pot(1, 0);       else         p = pot(0, (double)-c / b), v = pot(1, (double)-a / b);     }   } l[N + 9];   std::vector<int> res;   std::vector<std::pair<int, int> > ans;   inline int getrand(int lim) { return 1ll * rand() * rand() % lim; }   inline bool parallel(const line &a, const line &b) {     return fabs(a.v ^ b.v) < eps;   }   inline pot intersection(const line &a, const line &b) {     pot w = b.p - a.p;     double k = (w ^ a.v) / (a.v ^ b.v);     return b.p + b.v * k;   }   inline bool online(const pot &x, const line &l) {     return fabs((l.p - x) ^ l.v) < eps;   }   void dfs(int k, std::vector<int> res) {     if (!(int)(res).size()) {       puts( YES );       write((int)(ans).size()), out[outn++] =   n ;       for (int i = 0; i < (int)(ans).size(); ++i) {         write(ans[i].first), out[outn++] =    ;         write(ans[i].second), out[outn++] =   n ;       }       printf( %s , out);       exit(0);     }     if (!k) return;     int p = getrand((int)(res).size()), q = getrand((int)(res).size());     if (p == q) {       ans.push_back(std::make_pair(res[p], -1));       res.erase(find(res.begin(), res.end(), res[p]));       dfs(k - 1, res);       ans.pop_back();     } else {       if (parallel(l[res[p]], l[res[q]])) return;       ans.push_back(std::make_pair(res[p], res[q]));       if ((res[p] == 1 && res[q] == 2) || (res[p] == 2 && res[q] == 1)) p++, p--;       pot x = intersection(l[res[p]], l[res[q]]);       std::vector<int> nex;       for (int i = 0; i < (int)(res).size(); ++i)         if (!online(x, l[res[i]])) nex.push_back(res[i]);       dfs(k - 1, nex);       ans.pop_back();     }   }   int main() {     read(n), read(k);     for (int i = 1; i <= n; ++i) {       int a, b, c;       read(a), read(b), read(c);       l[i] = line(a, b, c);     }     for (int i = 1; i <= n; ++i) res.push_back(i);     while (clock() < lim) dfs(k, res);     puts( NO );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  inline,Ofast )   using namespace std;   int siz[1505], ans[1505], X, Y, n;   bool vis[1505];   vector<int> fir[1505];   struct P {     int x, y, d;     bool operator<(const P& o) const {       if (x - X >= 0 && o.x - X <= 0) return 1;       if (x - X <= 0 && o.x - X >= 0) return 0;       return 1ll * (y - Y) * (o.x - X) < 1ll * (o.y - Y) * (x - X);     }   } poi[1505];   void dfs(int u, int f) {     siz[u] = 1;     for (int v : fir[u])       if (v != f) dfs(v, u), siz[u] += siz[v];   }   void get(int l, int r, int o) {     vis[o] = 1;     int t = l;     for (int i = l + 1; i <= r; ++i)       if ((poi[i].y < poi[t].y) || (poi[t].y == poi[i].y && poi[i].x < poi[t].x))         t = i;     if (t != l) swap(poi[l], poi[t]);     ans[poi[l].d] = o;     X = poi[l].x;     Y = poi[l].y;     sort(poi + l + 1, poi + r + 1);     int pos = l + 1;     for (int v : fir[o])       if (!vis[v]) {         get(pos, pos + siz[v] - 1, v);         pos += siz[v];       }   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       fir[u].push_back(v);       fir[v].push_back(u);     }     for (int i = 1, x, y; i <= n; ++i) {       scanf( %d%d , &x, &y);       poi[i] = P{x, y, i};     }     dfs(1, 0);     get(1, n, 1);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   const ll LINF = 1e13;   using namespace std;   namespace ProconLib {   template <typename cost_t = long long, bool hasNegativeCost = false,             cost_t INF = LINF>   class Flow {    public:     struct Edge {       int to;       cost_t cap, rev;       cost_t cost;     };     using Edges = vector<Edge>;     using Graph = vector<Edges>;       private:     int N;     Graph g;     vector<int> level;     vector<int> iter;     void bfs(int s);     cost_t dfs(int v, int t, cost_t f);       public:     Flow(int N) : N(N), g(N){};     void addEdge(int from, int to, cost_t cap);     void addEdge(int from, int to, cost_t cap, cost_t cost);     cost_t maxFlow(int s, int t);     cost_t minCostFlow(int s, int t, cost_t f);   };   template <typename cost_t, bool hasNegativeCost, cost_t INF>   void Flow<cost_t, hasNegativeCost, INF>::addEdge(int from, int to, cost_t cap) {     g[from].push_back({to, cap, int(g[to].size()), 0});     g[to].push_back({from, cost_t(0), int(g[from].size()) - 1, 0});   }   template <typename cost_t, bool hasNegativeCost, cost_t INF>   void Flow<cost_t, hasNegativeCost, INF>::addEdge(int from, int to, cost_t cap,                                                    cost_t cost) {     g[from].push_back({to, cap, int(g[to].size()), cost});     g[to].push_back({from, cost_t(0), int(g[from].size()) - 1, -cost});   }   template <typename cost_t, bool hasNegativeCost, cost_t INF>   cost_t Flow<cost_t, hasNegativeCost, INF>::maxFlow(int s, int t) {     cost_t flow = 0;     while (true) {       bfs(s);       if (level[t] < 0) return flow;       iter.assign(N, 0);       cost_t f;       while ((f = dfs(s, t, INF)) > 0) {         flow += f;       }     }   }   template <typename cost_t, bool hasNegativeCost, cost_t INF>   void Flow<cost_t, hasNegativeCost, INF>::bfs(int s) {     level.assign(N, -1);     queue<int> que;     level[s] = 0;     que.push(s);     while (!que.empty()) {       int v = que.front();       que.pop();       for (int i = 0; i < g[v].size(); i++) {         Edge& e = g[v][i];         if (e.cap > 0 && level[e.to] < 0) {           level[e.to] = level[v] + 1;           que.push(e.to);         }       }     }   }   template <typename cost_t, bool hasNegativeCost, cost_t INF>   cost_t Flow<cost_t, hasNegativeCost, INF>::dfs(int v, int t, cost_t f) {     if (v == t) return f;     for (int& i = iter[v]; i < g[v].size(); i++) {       Edge& e = g[v][i];       if (e.cap > 0 && level[v] < level[e.to]) {         cost_t d = dfs(e.to, t, min(f, e.cap));         if (d > 0) {           e.cap -= d;           g[e.to][e.rev].cap += d;           return d;         }       }     }     return 0;   }   template <typename cost_t, bool hasNegativeCost, cost_t INF>   cost_t Flow<cost_t, hasNegativeCost, INF>::minCostFlow(int s, int t, cost_t f) {     using P = pair<cost_t, int>;     cost_t res = 0;     vector<cost_t> h(N, 0);     vector<int> used(N), preve(N), prevv(N);     vector<cost_t> dist(N);     while (f > 0) {       fill(dist.begin(), dist.end(), INF);       dist[s] = 0;       if (!hasNegativeCost) {         fill(used.begin(), used.end(), 0);         priority_queue<P, vector<P>, greater<P>> que;         que.push(make_pair(cost_t(0), s));         while (!que.empty()) {           P p = que.top();           que.pop();           int v = p.second;           if (used[v]) continue;           used[v] = true;           for (int i = 0; i < g[v].size(); i++) {             Edge& e = g[v][i];             if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {               dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];               prevv[e.to] = v;               preve[e.to] = i;               que.push(make_pair(dist[e.to], e.to));             }           }         }       } else {         bool update = true;         while (update) {           update = false;           for (int v = 0; v < N; v++) {             if (dist[v] == INF) continue;             for (int i = 0; i < g[v].size(); i++) {               Edge& e = g[v][i];               if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {                 dist[e.to] = dist[v] + e.cost;                 prevv[e.to] = v;                 preve[e.to] = i;                 update = true;               }             }           }         }       }       if (dist[t] == INF) {         return -1;       }       if (!hasNegativeCost) {         for (int v = 0; v < N; v++) h[v] += dist[v];       }       cost_t d = f;       for (int v = t; v != s; v = prevv[v]) {         d = min(d, g[prevv[v]][preve[v]].cap);       }       f -= d;       if (!hasNegativeCost) {         res += d * h[t];       } else {         res += d * dist[t];       }       for (int v = t; v != s; v = prevv[v]) {         Edge& e = g[prevv[v]][preve[v]];         e.cap -= d;         g[v][e.rev].cap += d;       }     }     return res;   }   }  // namespace ProconLib   struct Spaceship {     int x, a, f, p;   };   struct Base {     int x, d, g;   };   using namespace ProconLib;   using vvi = vector<vector<int>>;   void dfs(int v, vvi& g, vector<int>& used, vector<int>& vs) {     used[v] = true;     vs.push_back(v);     for (auto to : g[v]) {       if (used[to]) continue;       dfs(to, g, used, vs);     }   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int>> dist(n, vector<int>(n, 1e9 + 5));     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       dist[u][v] = 1;       dist[v][u] = 1;     }     for (int i = 0; i < n; i++) dist[i][i] = 0;     int s, b, k;     cin >> s >> b >> k;     vector<Spaceship> ship(s);     for (int i = 0; i < s; i++) {       cin >> ship[i].x >> ship[i].a >> ship[i].f >> ship[i].p, ship[i].x--;     }     vector<Base> base(b);     for (int i = 0; i < b; i++) {       cin >> base[i].x >> base[i].d >> base[i].g;       base[i].x--;     }     vvi sg(s);     for (int i = 0; i < k; i++) {       int s1, s2;       cin >> s1 >> s2;       s1--, s2--;       sg[s1].push_back(s2);     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);         }       }     }     vector<ll> profit(s, -LINF);     vector<vector<int>> bids(n);     for (int i = 0; i < b; i++) {       bids[base[i].x].push_back(i);     }     auto cmp = [&](int lhs, int rhs) { return base[lhs].d < base[rhs].d; };     for (int i = 0; i < n; i++) sort(bids[i].begin(), bids[i].end(), cmp);     vector<vector<int>> accMax(n);     for (int i = 0; i < n; i++) {       accMax[i].resize(bids[i].size() + 1);       for (int j = 0; j < bids[i].size(); j++) {         accMax[i][j + 1] = max(accMax[i][j], base[bids[i][j]].g);       }     }     for (int i = 0; i < s; i++) {       int x = ship[i].x;       for (int v = 0; v < n; v++) {         if (dist[x][v] <= ship[i].f) {           int lb = -1, ub = bids[v].size();           while (ub - lb > 1) {             int mid = (lb + ub) / 2;             if (base[bids[v][mid]].d <= ship[i].a)               lb = mid;             else               ub = mid;           }           ll sc = accMax[v][ub] - ship[i].p;           if (ub > 0) profit[i] = max(profit[i], sc);         }       }     }     auto doFlow = [&](const vvi& graph, const vector<ll>& mpPro) {       int n = graph.size();       const int S = n;       const int T = n + 1;       Flow<ll> flow(n + 2);       ll sum = 0;       for (int i = 0; i < n; i++) {         if (mpPro[i] > 0) {           sum += mpPro[i];           flow.addEdge(S, i, mpPro[i]);           flow.addEdge(i, T, 0);         } else {           flow.addEdge(S, i, 0);           flow.addEdge(i, T, -mpPro[i]);         }       }       for (int i = 0; i < n; i++) {         for (auto to : graph[i]) {           flow.addEdge(i, to, LINF);         }       }       return sum - flow.maxFlow(S, T);     };     vvi undirSG(s);     for (int i = 0; i < s; i++) {       for (auto to : sg[i]) {         undirSG[i].push_back(to);         undirSG[to].push_back(i);       }     }     ll res = 0;     vector<int> used(s);     for (int i = 0; i < s; i++) {       if (!used[i]) {         vector<int> vs;         dfs(i, undirSG, used, vs);         if (vs.size() == 1) {           if (profit[i] > 0) res += profit[i];           continue;         }         map<int, int> mp;         int id = 0;         for (auto v : vs) {           mp[v] = id++;         }         vvi mapG(id);         vector<ll> mpPro(id);         for (auto v : vs) {           mpPro[mp[v]] = profit[v];           for (auto to : sg[v]) {             mapG[mp[v]].push_back(mp[to]);           }         }         res += doFlow(mapG, mpPro);       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     char s[100];     scanf( %s , s);     int ans = 0;     for (int i = 0; s[i]; ++i) {       if (isalpha(s[i])) {         if (s[i] <=  Z )           ans += s[i] -  A  + 1;         else           ans -= s[i] -  a  + 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y;     cin >> x >> y;     double ans = (x * x + y * y) / (x * 2);     ans -= x;     printf( %.12lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> _edge;   set<int> se, to_del;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int t, n, m, i, j, k, x, y, z, a, b, c;     cin >> t;     while (t--) {       cin >> n >> m;       n *= 3;       se.clear();       _edge.clear();       for (i = 1; i <= n; ++i) se.insert(i);       for (i = 1; i <= m; ++i) {         cin >> x >> y;         if (se.find(x) != se.end() && se.find(y) != se.end()) {           se.erase(x);           se.erase(y);           _edge.push_back(i);         }       }       n = n / 3;       if (_edge.size() >= n) {         cout <<  Matching  << endl;         for (i = 0; i < _edge.size() && i < n; ++i) cout << _edge[i] <<    ;         cout << endl;       } else if (se.size() >= n) {         cout <<  IndSet  << endl;         i = 0;         for (auto it : se) {           cout << it <<    ;           i += 1;           if (i == n) break;         }         cout << endl;       } else         cout <<  Impossible  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(const int &a, const int &b) { return a < b; }   int main() {     int n;     cin >> n;     int i = 0;     double aux = 0;     while (n >= aux) {       aux = (1.0 / 6.0) * (i) * (i + 1) * (i + 2);       i++;     }     cout << i - 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     multiset<int> b;     int c[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       int z;       cin >> z;       b.insert(z);     }     for (int i = 0; i < n; i++) {       auto z = b.lower_bound(n - a[i]);       if (z == b.end()) z = b.lower_bound(0);       cout << (a[i] + *z) % n <<    ;       b.erase(z);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long max_n = 2e5 + 100;   long long n;   vector<pair<long long, long long> > adj[max_n];   long long S[max_n];   vector<long long> G[max_n];   struct Edge {     long long x, y, w, idx;     Edge() {}     Edge(long long x, long long y, long long w, long long idx)         : x(x), y(y), w(w), idx(idx) {}   };   Edge edges[max_n];   class Disjoint_Sets {    public:     long long* parent;     long long* size;     Disjoint_Sets() {}     Disjoint_Sets(long long n) {       parent = new long long[n];       size = new long long[n];       for (long long i = 0; i < n; i++) {         parent[i] = i;         size[i] = 1;       }     }     void merge(long long a, long long b) {       long long parent_a = find(a);       long long parent_b = find(b);       if (parent_a == parent_b) return;       if (size[parent_a] < size[parent_b]) {         parent[parent_a] = parent_b;         size[parent_b] += size[parent_a];         size[parent_a] = 0;       } else {         parent[parent_b] = parent_a;         size[parent_a] += size[parent_b];         size[parent_b] = 0;       }     }     long long find(long long a) {       if (parent[a] == a) {         return a;       }       parent[a] = find(parent[a]);       return parent[a];     }   };   long long st[max_n];   long long total[max_n];   Disjoint_Sets D;   long long get_st(long long v, long long p) {     if (st[v] != -1) return st[v];     st[v] = D.size[v];     for (long long x : G[v])       if (x != p) {         get_st(x, v);         st[v] += st[x];       }     return st[v];   }   void update_total(long long v, long long p, long long T) {     total[v] = T;     for (long long x : G[v])       if (x != p) {         update_total(x, v, T);       }   }   long long ans[max_n];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     memset(st, -1, sizeof(st));     memset(total, -1, sizeof(total));     cin >> n;     D = Disjoint_Sets(n);     for (long long i = 0; i < n - 1; i++) {       long long x, y, w;       cin >> x >> y >> w;       x--;       y--;       adj[x].push_back({y, w});       adj[y].push_back({x, w});       edges[i] = Edge(x, y, w, i);     }     sort(edges, edges + n - 1,          [](const Edge& a, const Edge& b) -> bool { return a.w < b.w; });     long long i = 0;     while (i < n - 1) {       long long j = i;       while (j < n - 1 && edges[i].w == edges[j].w) {         j++;       }       for (long long k = i; k < j; k++) {         G[D.find(edges[k].x)].push_back(D.find(edges[k].y));         G[D.find(edges[k].y)].push_back(D.find(edges[k].x));       }       for (long long k = i; k < j; k++) {         long long u = D.find(edges[k].x);         long long v = D.find(edges[k].y);         if (st[u] == -1) {           get_st(u, -1);           update_total(u, -1, st[u]);         }         long long X = min(st[u], st[v]);         long long Y = total[u] - X;         ans[edges[k].idx] = (2 * X * Y);       }       for (long long k = i; k < j; k++) {         long long u = D.find(edges[k].x);         long long v = D.find(edges[k].y);         G[u].clear();         G[v].clear();         st[u] = -1;         st[v] = -1;         total[u] = -1;         total[v] = -1;         D.merge(u, v);       }       i = j;     }     long long maxi = *max_element(ans, ans + n - 1);     vector<long long> final;     for (long long i = 0; i < n - 1; i++)       if (ans[i] == maxi) {         final.push_back(i);       }     cout << maxi <<     << final.size() <<   n ;     for (long long x : final) {       cout << x + 1 <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>      using namespace std;   bool func(pair<long long,long long> &fi,pair<long long,long long>&se){       return fi.first<se.first;   }   int main()   {      int t=1;      cin>>t;      while(t--){          long long a,b,n;          cin>>a>>b>>n;          pair<long long,long long>arr[n];                    for(int i=0;i<n;i++){              cin>>arr[i].first;          }          for(int i=0;i<n;i++){              cin>>arr[i].second;          }          sort(arr,arr+n,func);                   bool gamovida=true;          for(int i=0;i<n;i++){              int num=arr[i].second/a;              if(num*a<arr[i].second)num++;              b-=arr[i].first*num;              if(b<=0&&i!=n-1){                  gamovida=false;              }              if(b<=0&&i==n-1){                  if(b+arr[i].first<=0){                      gamovida=false;                  }              }          }          if(gamovida==false){              cout<< NO <<endl;              continue;          }               if(gamovida==false){              cout<< NO <<endl;          }else{              cout<< YES <<endl;          }                }            return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     stack<char> Stack;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       char ch = s[i];       if (!Stack.empty() && ch == Stack.top())         Stack.pop();       else         Stack.push(ch);     }     if (Stack.empty())       printf( Yes n );     else       printf( No n );   }


#include <bits/stdc++.h>   using namespace std;   int number[1003][1003][2];   int n, m, sum;   int part = -1;   int parts[1000003];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   string s[1003];   bool isvalid(int x, int y) {     if (x >= 0 && x < n && y >= 0 && y < m) return 1;     return 0;   }   int findsum(int x, int y) {     int ans = 0;     int anses[4];     int point = 0;     for (int i = 0; i < 4; i++) {       if (isvalid(x + dx[i], y + dy[i]) && s[x + dx[i]][y + dy[i]] ==  . ) {         bool flag = 0;         int p = number[x + dx[i]][y + dy[i]][1];         for (int j = 0; j < point; j++) {           if (p == anses[j]) {             flag = 1;           }         }         if (flag == 0) {           ans += parts[p];         }         anses[point] = p;         point++;       }     }     return ans + 1;   }   void dfs(int x, int y) {     if (number[x][y][0] == 0) {       sum++;       number[x][y][0] = 1;       number[x][y][1] = part;       for (int i = 0; i < 4; i++) {         if (isvalid(x + dx[i], y + dy[i])) {           if (s[x + dx[i]][y + dy[i]] ==  . ) {             dfs(x + dx[i], y + dy[i]);           }         }       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  . ) {           if (number[i][j][0] == 0) {             part++;             dfs(i, j);             parts[part] = sum;             sum = 0;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  * ) {           s[i][j] =  0  + findsum(i, j) % 10;         }       }     }     for (int i = 0; i < n; i++) {       cout << s[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > score;   map<pair<int, int>, int> freq;   bool compare(const pair<int, int> a, const pair<int, int> b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   void solve() {     int n, k;     cin >> n >> k;     for (int(i) = (0); (i) < (n); ++(i)) {       int x, y;       cin >> x >> y;       pair<int, int> curr = make_pair(x, y);       score.push_back(curr);       ++freq[curr];     }     sort((score).begin(), (score).end(), compare);     cout << freq[score[k - 1]];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[200005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     string s, ans;     int test, n;     cin >> test;     while (test--) {       cin >> s;       n = s.length();       for (int i = 1; i <= n; ++i) t[i] = t[i - 1] + s[i - 1] -  0 ;       ans =   ;       bool can = true, less = false;       int m = 0;       for (int i = 0; i < n; ++i) {         int l = ans.length();         string f =   ;         for (int j = 9; j >= 0; --j)           if (m & 1 << j) f += j +  0 ;         if (less) {           l = n - i - f.length();           while (l--) ans +=  9 ;           for (auto j : f) ans += j;           break;         } else {           for (char j = s[i]; j >=  0  + (i == 0); --j) {             auto cp = f;             if (m & 1 << (j -  0 ))               f.erase(f.find(j), 1);             else               f += j;             sort(f.begin(), f.end());             int fl = f.length();             if (i + fl <= n) {               if (n - i - 1 > fl && t[n - fl] - t[i + 1] > 0) {                 if (j < s[i]) less = true;                 ans += j;                 m ^= 1 << (j -  0 );                 break;               } else if (j < s[i] || f < s.substr(n - fl, fl)) {                 if (j < s[i]) less = true;                 ans += j;                 m ^= 1 << (j -  0 );                 break;               } else if (f == s.substr(n - fl, fl) && j < s[i]) {                 less = true;                 ans += j;                 m ^= 1 << (j -  0 );                 break;               }             }             f = cp;           }         }         if (ans.length() == l) {           can = false;           break;         }       }       if (!can) {         ans =   ;         for (int i = 2; i < n; ++i) ans +=  9 ;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct info {     int red, yel, chk;   } v[1000];   struct info1 {     int red, yel, chk;   } v1[1000];   int main() {     string home, away;     cin >> home >> away;     int in, n, i, j, time, number;     char formation, card;     cin >> n;     while (n--) {       cin >> time >> formation >> number >> card;       if (formation ==  h ) {         if (card ==  y ) {           v[number].yel++;         } else {           v[number].red++;         }         if ((v[number].yel == 2 || v[number].red == 1) && v[number].chk == 0) {           cout << home <<     << number <<     << time << endl;           v[number].chk = 1;         }       } else {         if (card ==  y ) {           v1[number].yel++;         } else {           v1[number].red++;         }         if ((v1[number].yel == 2 || v1[number].red == 1) && v1[number].chk == 0) {           cout << away <<     << number <<     << time << endl;           v1[number].chk = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   int a[101010];   int dp[1010101];   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       sort(a, a + n);       n = unique(a, a + n) - a;       int b, c;       scanf( %d%d , &b, &c);       int sum = 0;       while (b > c) {         int next = b - 1;         for (int i = 0; i < n; i++) {           int to = b - b % a[i];           if (to < c)             a[i--] = a[--n];           else if (to < next)             next = to;         }         b = next;         sum++;       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, m, r;   };   node t[3000005];   int arr[300005], n, m;   long long a[300005];   int sign(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   void cal(int x, int l, int r) {     int m = (l + r) / 2;     t[x].m = max(t[x * 2].m, t[x * 2 + 1].m);     t[x].l = t[x * 2].l;     t[x].r = t[x * 2 + 1].r;     if (!!a[m] && !!a[m + 1] && sign(a[m]) >= sign(a[m + 1])) {       t[x].m = max(t[x].m, t[x * 2].r + t[x * 2 + 1].l);       if (t[2 * x].m == m - l + 1) t[x].l = t[2 * x].l + t[2 * x + 1].l;       if (t[2 * x + 1].m == r - m) t[x].r = t[2 * x].r + t[2 * x + 1].r;     }   }   void build(int x, int l, int r) {     if (l == r) {       int tmp = !!a[l];       t[x].l = t[x].m = t[x].r = tmp;       return;     }     int m = (l + r) / 2;     build(x * 2, l, m);     build(x * 2 + 1, m + 1, r);     cal(x, l, r);   }   void update(int x, int l, int r, int pos, int d) {     if (l == r) {       a[pos] += d;       int tmp = !!a[pos];       t[x].l = t[x].m = t[x].r = tmp;       return;     }     int m = (l + r) / 2;     if (pos <= m)       update(x * 2, l, m, pos, d);     else       update(x * 2 + 1, m + 1, r, pos, d);     cal(x, l, r);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     for (int i = 0; i + 1 < n; i++) a[i] = arr[i + 1] - arr[i];     if (n > 1) build(1, 0, n - 2);     cin >> m;     while (m--) {       int l, r, d;       scanf( %d%d%d , &l, &r, &d);       if (n == 1) {         printf( %d n , 1);         continue;       }       if (l > 1) update(1, 0, n - 2, l - 2, d);       if (r < n) update(1, 0, n - 2, r - 1, -d);       printf( %d n , t[1].m + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, cnt[100010], beg_cnt[100010];   double ans = 0, dp[100010][110], buf[110];   int main() {     scanf( %d , &N);     for (int i = 0; i < N; ++i) {       scanf( %d , &cnt[i]), dp[i][cnt[i]] = 1;       beg_cnt[i] = cnt[i];       if (cnt[i] == 0) ++ans;     }     int M;     scanf( %d , &M);     for (int i = 0; i < M; ++i) {       int f, t, how;       scanf( %d%d%d , &f, &t, &how);       --f;       --t;       ans -= dp[f][0];       for (int S = 0; S < how; ++S) {         memset(buf, 0, (beg_cnt[f] + 1) * sizeof(double));         for (int i = 0; i <= beg_cnt[f]; ++i) {           buf[i] += dp[f][i] * ((cnt[f] - i + 0.0) / cnt[f]);           if (i) buf[i - 1] += dp[f][i] * ((i + 0.0) / cnt[f]);         }         memcpy(dp[f], buf, (beg_cnt[f] + 1) * sizeof(double));         --cnt[f];       }       cnt[t] += how;       ans += dp[f][0];       printf( %.18lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 2e5 + 10;   long long arr[maxx + 5];   int main() {     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       arr[i] = x + arr[i - 1];     }     long long lag = 0, best = 0, x, y, ans;     for (int i = n - (2 * k) + 1; i > 0; i--) {       long long j = i + k;       if (arr[j + k - 1] - arr[j - 1] >= lag) {         lag = arr[j + k - 1] - arr[j - 1];         ans = j;       }       if (arr[j - 1] - arr[i - 1] + lag >= best) {         best = arr[j - 1] - arr[i - 1] + lag;         y = ans;         x = i;       }     }     cout << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   char ss[N], s[N];   int fail[N], trie[N][30];   struct node {     int v, next;   } e[N];   int n, opt, m, dfsclock, id, siz[N], tree[N], fa[N], dfsxu[N], ans[N], head[N],       cnt, tot;   void add(int u, int v) {     e[++cnt].v = v;     e[cnt].next = head[u];     head[u] = cnt;   }   vector<pair<int, int> > que[N];   struct BinaryIndexTree {     int tree[800001];     void clear() { memset(tree, 0, sizeof(tree)); }     inline int lowbit(int x) { return x & (-x); }     inline void updata(int x, int cost) {       for (int i = x; i <= tot + 1; i += lowbit(i)) tree[i] += cost;     }     inline int sum(int x) {       int sum1 = 0;       for (int i = x; i > 0; i -= lowbit(i)) sum1 += tree[i];       return sum1;     }   } tt;   int add(char *t) {     int n = strlen(t + 1), p = 0;     for (int i = 1; i <= n; ++i) {       if (!trie[p][t[i] -  a ]) trie[p][t[i] -  a ] = ++tot;       p = trie[p][t[i] -  a ];     }     return p;   }   queue<int> q;   vector<int> E[N];   void build() {     for (int i = 0; i < 26; ++i)       if (trie[0][i]) q.push(trie[0][i]);     while (!q.empty()) {       int u = q.front();       q.pop();       E[fail[u]].push_back(u);       for (int i = 0; i < 26; ++i) {         if (!trie[u][i])           trie[u][i] = trie[fail[u]][i];         else           fail[trie[u][i]] = trie[fail[u]][i], q.push(trie[u][i]);       }     }   }   void dfs1(int u) {     dfsxu[u] = ++dfsclock;     siz[u] = 1;     for (int i = 0; i < E[u].size(); ++i) {       int v = E[u][i];       dfs1(v);       siz[u] += siz[v];     }   }   int getans(int p) {     return tt.sum(dfsxu[p] + siz[p] - 1) - tt.sum(dfsxu[p] - 1);   }   void dfs(int u, int p) {     p = trie[p][s[u] -  a ];     tt.updata(dfsxu[p], 1);     for (int i = head[u]; i != 0; i = e[i].next) dfs(e[i].v, p);     for (int i = 0; i < que[u].size(); ++i)       ans[que[u][i].second] = getans(que[u][i].first);     tt.updata(dfsxu[p], -1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &opt);       if (opt == 2) scanf( %d , &fa[i]);       add(fa[i], i);       scanf( %s , &s[i]);     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d %s , &id, ss + 1);       que[id].push_back(make_pair(add(ss), i));     }     build();     dfs1(0);     for (int i = 1; i <= n; ++i)       if (!fa[i]) dfs(i, 0);     for (int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod1 = 1000000007;   const long long mod2 = 998244353;   mt19937 rng(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   long long power(long long a, long long b) {     long long result = 1;     while (b > 0) {       if (b % 2 == 1) {         result *= a;       }       a *= a;       b /= 2;     }     return result;   }   long long gcd(long long x, long long y) {     long long r;     while (y != 0 && (r = x % y) != 0) {       x = y;       y = r;     }     return y == 0 ? x : y;   }   long long countSetBits(long long x) {     long long Count = 0;     while (x > 0) {       if (x & 1) Count++;       x = x >> 1;     }     return Count;   }   long long mod(long long x, long long M) { return ((x % M + M) % M); }   long long add(long long a, long long b, long long M) {     return mod(mod(a, M) + mod(b, M), M);   }   long long mul(long long a, long long b, long long M) {     return mod(mod(a, M) * mod(b, M), M);   }   long long powerM(long long a, long long b, long long M) {     long long res = 1ll;     while (b) {       if (b % 2ll == 1ll) {         res = mul(a, res, M);       }       a = mul(a, a, M);       b /= 2ll;     }     return res;   }   void solve() {     long long h, w;     cin >> w >> h;     long long x;     cin >> x;     vector<long long> v(x);     for (long long i = 0; i < x; i++) {       cin >> v[i];     }     long long y;     cin >> y;     vector<long long> v1(y);     for (long long i = 0; i < y; i++) {       cin >> v1[i];     }     long long z;     cin >> z;     vector<long long> v2(z);     for (long long i = 0; i < z; i++) {       cin >> v2[i];     }     long long a;     cin >> a;     vector<long long> v3(a);     for (long long i = 0; i < a; i++) {       cin >> v3[i];     }     sort(v.begin(), v.end());     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     sort(v3.begin(), v3.end());     long long t = max(v[x - 1] - v[0], v1[y - 1] - v1[0]);     long long ans1 = t * h;     long long t1 = max(v2[z - 1] - v2[0], v3[a - 1] - v3[0]);     long long ans2 = t1 * w;     cout << max(ans2, ans1) <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(20);     long long t = 1;     cin >> t;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, sum = 0;   string a, b;   int main() {     cin >> T;     while (T--) {       int temp = 0, flag = 0;       cin >> a;       cin >> b;       int k = 0;       int LA = a.size();       int LB = b.size();       for (int i = 0; i <= LA; i++) {         if (flag == 0 && a[i] != b[k]) {           while (b[k] == b[k - 1]) {             k++;           }           flag = 1;         }         if (a[i] == b[k]) {           k++;           flag = 0;           continue;         }         if (flag == 1) {           cout <<  NO  << endl;           temp = 1;           break;         }       }       if (temp == 0) {         cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   template <typename T>   inline void cmin(T &x, T y) {     if (x > y) x = y;   }   template <typename T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   int n, cnt[MAXN], pos;   int vis[MAXN], siz[MAXN], son[MAXN], tsiz, root;   long long dis[MAXN];   double sum[MAXN], sq, cur, ans;   struct Edge {     int v, w, nxt;   } e[MAXN << 1];   int first[MAXN], eCnt;   inline void AddEdge(int u, int v, int w) {     e[++eCnt].v = v;     e[eCnt].w = w;     e[eCnt].nxt = first[u];     first[u] = eCnt;   }   void GetRoot(int u, int fa) {     siz[u] = 1;     son[u] = 0;     for (int i = first[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (v == fa || vis[v]) continue;       GetRoot(v, u);       cmax(son[u], siz[v]);       siz[u] += siz[v];     }     cmax(son[u], tsiz - siz[u]);     if (son[u] < son[root]) root = u;   }   void GetCost(int u, int fa) {     sq = sqrt(dis[u]) * cnt[u];     sum[u] = sq;     cur += sq * dis[u];     for (int i = first[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (v == fa) continue;       dis[v] = dis[u] + e[i].w;       GetCost(v, u);       sum[u] += sum[v];     }   }   void PointDC(int u) {     vis[u] = 1;     cur = dis[u] = 0;     GetCost(u, 0);     if (cur < ans) {       ans = cur;       pos = u;     }     for (int i = first[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (vis[v]) continue;       if (sum[u] < sum[v] * 2) {         tsiz = siz[v];         root = 0;         GetRoot(v, 0);         PointDC(root);         break;       }     }   }   void init() {     read(n);     for (int i = 1; i <= n; ++i) {       read(cnt[i]);     }     for (int i = 1, u, v, w; i < n; ++i) {       read(u);       read(v);       read(w);       AddEdge(u, v, w);       AddEdge(v, u, w);     }   }   void solve() {     ans = 1e30;     son[0] = tsiz = n;     GetRoot(1, 0);     PointDC(root);     printf( %d %.8lf n , pos, ans);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, u, v, w = 0, l = 0;     scanf( %d%d , &n, &k);     for (i = 1; i <= k; ++i)       scanf( %d%d , &u, &v), w = (w + u * 1ll * v) % n, l += v;     if (l < n)       puts( 1 );     else if (l > n)       puts( -1 );     else if ((1ll + n) * n / 2 % n == w)       puts( 1 );     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 10;   char a[maxn], b[maxn], t[maxn];   int main() {     int n;     char c[1];     scanf( %d , &n);     gets(c);     scanf( %s , a + 1);     int d = 0;     while (d <= n) {       d++;       if (n % d == 0) {         for (int i = 1; i <= d; i++) {           b[i] = a[d - i + 1];         }         for (int j = d + 1; j <= n; j++) {           b[j] = a[j];         }         for (int i = 1; i <= n; i++) a[i] = b[i];       }     }     for (int i = 1; i <= n; i++) printf( %c , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = (long long)(5e5) + 322;   const long long INF = (long long)(1e9);   const long long mod = (long long)(1e9) + 7;   const double eps = 1e-9;   int xp, yp, xv, yv, distp, distv;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cin >> xp >> yp >> xv >> yv;     distp = xp + yp;     distv = max(xv, yv);     if (distp <= distv) {       cout <<  Polycarp ;       return 0;     }     if (xp <= xv && yp <= yv) {       cout <<  Polycarp ;       return 0;     }     cout <<  Vasiliy ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void pb_200() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     long long int x;     cin >> x;     while (x--) {       long long int n;       cin >> n;       long long int *arr = new long long int[n];       ;       for (long long int i = 0; i < n; ++i) cin >> arr[i];       long long int i = n - 1;       while (i > 0 and arr[i] <= arr[i - 1]) i--;       if (i == 0) {         cout << 0 << endl;         continue;       }       while (i > 0 and arr[i] >= arr[i - 1]) i--;       cout << i << endl;     }   }


#include <bits/stdc++.h>   int a[1005][1005];   int n;   void solve(int x) {     for (int flag = 0; flag < n; flag++) {       if (a[x][flag] == 0) {         for (int flag1 = flag; flag1 < n; flag1++) {           a[x][flag1] = a[x][flag1 + 1];         }         break;       }     }   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(a, 0, sizeof(a));       for (int flag = 0; flag < n; flag++) {         for (int flag1 = 0; flag1 < n; flag1++) {           a[flag][flag1] = (flag + flag1) % n;         }       }       for (int flag = 1; flag < n; flag++) {         solve(flag);       }       for (int flag = 1; flag < n; flag++) {         a[flag][n - 1] = a[flag][flag];         a[flag][flag] = 0;       }       for (int flag = 0; flag < n; flag++) {         for (int flag1 = 0; flag1 < flag; flag1++) {           a[flag][flag1] = a[flag1][flag];         }       }       for (int flag = 0; flag < n; flag++) {         printf( %d , a[flag][0]);         for (int flag1 = 1; flag1 < n; flag1++) {           printf(  %d , a[flag][flag1]);         }         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int m = n * 2 - 1;       printf( %d 2 n , m);       printf( 1 2 n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long fact[(long long)(1e6 + 10)], mod_inv[(long long)(1e6 + 10)];   long long _pow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 == 1) return (a * _pow(a, n - 1)) % (long long)(1e9 + 7);     long long x = _pow(a, n / 2) % (long long)(1e9 + 7);     return (x * x) % (long long)(1e9 + 7);   }   void inv() {     mod_inv[0] = 1;     for (int i = 1; i < (long long)(1e6 + 10) - 1; i++) {       mod_inv[i] = _pow(fact[i], (long long)(1e9 + 7) - 2);     }   }   void f() {     fact[0] = 1;     mod_inv[0] = 1;     for (int i = 1; i < (long long)(1e6 + 10) - 1; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= (long long)(1e9 + 7);       mod_inv[i] = _pow(fact[i], (long long)(1e9 + 7) - 2);     }   }   void init() { f(); }   long long nCr(long long n, long long r) {     return (((mod_inv[n - r] * mod_inv[r]) % (long long)(1e9 + 7)) * fact[n]) %            (long long)(1e9 + 7);   }   pair<long long, long long> black[2010];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first == b.first) ? a.second < b.second : a.first < b.first;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     init();     int h, w, n;     cin >> h >> w >> n;     for (int i = 0; i < n; i++) {       cin >> black[i].first >> black[i].second;       black[i].first--;       black[i].second--;     }     long long dp[n + 1];     memset(dp, 0, sizeof(dp));     black[n] = make_pair(h - 1, w - 1);     sort(black, black + n, cmp);     for (int i = 0; i < n + 1; i++) {       dp[i] = nCr(black[i].first + black[i].second, black[i].first);       for (int j = 0; j < i; j++) {         if (black[j].second > black[i].second) continue;         dp[i] -= (dp[j] * nCr(black[i].first - black[j].first + black[i].second -                                   black[j].second,                               black[i].second - black[j].second)) %                  (long long)(1e9 + 7);         dp[i] += (long long)(1e9 + 7);         dp[i] %= (long long)(1e9 + 7);       }     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n, m, k;       cin >> n >> m >> k;       vector<vector<int>> G(n + 1);       vector<int> deg(n + 1);       for (int i = 1; i <= m; i++) {         int x, y;         cin >> x >> y;         G[x].push_back(y);         G[y].push_back(x);         deg[x] += 1;         deg[y] += 1;       }       for (int i = 1; i <= n; i++) {         sort(G[i].begin(), G[i].end());       }       auto del = [&](int x, int y) -> void {         deg[x] -= 1;         deg[y] -= 1;       };       queue<int> Q;       for (int i = 1; i <= n; i++) {         if (deg[i] < k - 1) {           Q.push(i);         }       }       while (!Q.empty()) {         int cur = Q.front();         Q.pop();         for (auto nx : G[cur]) {           if (deg[nx] == 0) {             continue;           }           del(cur, nx);           if (deg[nx] == k - 2) {             Q.push(nx);           }         }         assert(deg[cur] == 0);       }       auto go = [&]() -> void {         for (int i = 1; i <= n; i++) {           if (deg[i] == k - 1) {             Q.push(i);           }         }         while (!Q.empty()) {           int cur = Q.front();           Q.pop();           if (deg[cur] == k - 1) {             bool good = true;             vector<int> vec;             for (auto nx : G[cur]) {               if (deg[nx]) {                 vec.push_back(nx);               }             }             assert(vec.size() == k - 1);             for (int i = 0; good && i < k - 1; i++) {               for (int j = i + 1; good && j < k - 1; j++) {                 int x = vec[i];                 int y = vec[j];                 auto it = lower_bound(G[x].begin(), G[x].end(), y);                 if (it == G[x].end() || *it != y) {                   good = false;                 }               }             }             if (good) {               cout <<  2 n ;               for (auto t : vec) {                 cout << t <<    ;               }               cout << cur <<   n ;               return;             }           }           for (auto nx : G[cur]) {             if (deg[nx] == 0) {               continue;             }             del(cur, nx);             if (deg[nx] == k - 1) {               Q.push(nx);             }           }         }         vector<int> ans;         for (int i = 1; i <= n; i++) {           if (deg[i]) {             ans.push_back(i);           }         }         if (ans.empty()) {           cout << -1 <<   n ;         } else {           cout <<  1   << ans.size() <<   n ;           for (auto t : ans) {             cout << t <<    ;           }           cout <<   n ;         }       };       go();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 100100;   int n;   int deg[N];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int v, u;       scanf( %d%d , &v, &u);       v--;       u--;       deg[v]++;       deg[u]++;     }     for (int v = 0; v < n; v++) {       if (deg[v] == 2) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cal(long long n) {     int sum = 0;     string s = to_string(n);     for (int i = 0; i < s.size(); i++) {       sum = sum + (s[i] -  0 );     }     return sum;   }   int main() {     long long n;     cin >> n;     if (n < 9) {       cout << n << endl;       return 0;     }     long long i = 9;     long long a = -1;     for (int j = 0; j < 13; j++) {       if (i <= n) {         a = i;         i = i * 10 + 9;       } else {         break;       }     }     long long b = n - a;     cout << cal(a) + cal(b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &a, T b) {     return (a < b) ? a = b, 1 : 0;   }   template <typename T>   bool chkmin(T &a, T b) {     return (a > b) ? a = b, 1 : 0;   }   inline int read() {     int x = 0, fh = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fh = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^  0 );     return x * fh;   }   int n, m, k, K;   int mp[605][605];   int st[605];   vector<int> G[605];   int vis[605];   int mat[605];   bool dfs(int x) {     for (int v : G[x]) {       if (!vis[v]) {         vis[v] = 1;         if (!mat[v] || dfs(mat[v])) {           mat[v] = x;           return 1;         }       }     }     return 0;   }   bool check(int x) {     for (int i = (1), _end_ = (int)(n); i <= _end_; ++i) G[i].clear();     for (int i = (1), _end_ = (int)(k); i <= _end_; ++i) {       for (int j = (1), _end_ = (int)(n); j <= _end_; ++j) {         if (mp[st[i]][j] <= x) G[i].push_back(j);       }     }     int ans = 0;     memset(mat, 0, sizeof(mat));     for (int i = (1), _end_ = (int)(k); i <= _end_; ++i) {       memset(vis, 0, sizeof(vis));       if (dfs(i)) ans++;     }     return ans >= K;   }   int main() {     n = read();     m = read();     k = read();     K = read();     memset(mp, 0x3f3f3f3f, sizeof(mp));     for (int i = (1), _end_ = (int)(n); i <= _end_; ++i) mp[i][i] = 0;     for (int i = (1), _end_ = (int)(k); i <= _end_; ++i) st[i] = read();     for (int i = (1), _end_ = (int)(m); i <= _end_; ++i) {       int x = read(), y = read(), w = read();       if (chkmin(mp[x][y], w)) mp[x][y] = mp[y][x] = w;     }     for (int kk = (1), _end_ = (int)(n); kk <= _end_; ++kk) {       for (int i = (1), _end_ = (int)(n); i <= _end_; ++i) {         for (int j = (1), _end_ = (int)(n); j <= _end_; ++j) {           if (chkmin(mp[i][j], mp[i][kk] + mp[kk][j])) mp[j][i] = mp[i][j];         }       }     }     int l = 0, r = 0x3f3f3f3f;     int ans = 0x3f3f3f3f;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     if (ans == 0x3f3f3f3f)       puts( -1 );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[4000009][3];   int a[1000009];   void init(int node, int b, int e) {     if (b == e) {       tree[node][a[b]] = 1;       tree[node][1 - a[b]] = 0;       tree[node][2] = 0;       return;     }     int mid = (b + e) / 2;     int left = node * 2;     int right = node * 2 + 1;     init(left, b, mid);     init(right, mid + 1, e);     tree[node][2] = min(tree[left][0], tree[right][1]);     tree[node][0] = tree[left][0] - tree[node][2] + tree[right][0];     tree[node][1] = tree[left][1] + tree[right][1] - tree[node][2];     tree[node][2] += tree[left][2] + tree[right][2];   }   pair<int, pair<int, int>> query(int node, int b, int e, int l, int r) {     if (l > e || r < b) return {0, {0, 0}};     if (b >= l && e <= r) return {tree[node][2], {tree[node][0], tree[node][1]}};     int mid = b + e >> 1;     int left = node * 2;     int right = node * 2 + 1;     pair<int, pair<int, int>> p1 = query(left, b, mid, l, r);     pair<int, pair<int, int>> p2 = query(right, mid + 1, e, l, r);     int mn = min(p1.second.first, p2.second.second);     int tot = p1.first + p2.first + mn;     int lf = p1.second.first + p2.second.first - mn;     int rf = p1.second.second + p2.second.second - mn;     return {tot, {lf, rf}};   }   int main() {     string s;     cin >> s;     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] ==  ( )         a[i + 1] = 0;       else         a[i + 1] = 1;     }     int q;     cin >> q;     init(1, 1, n);     while (q--) {       int l, r;       cin >> l >> r;       cout << 2 * query(1, 1, n, l, r).first << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int n, tmp;   long long int k, c = 0;   list<int> game;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> tmp;       game.push_back(tmp);     }     while (*game.begin() != n) {       if (*game.begin() > *(++game.begin())) {         tmp = *(++game.begin());         game.erase(++game.begin());         game.push_back(tmp);         c++;       } else {         tmp = *game.begin();         game.erase(game.begin());         game.push_back(tmp);         c = 1;       }       if (c == k) {         cout << *game.begin();         return 0;       }     }     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200003];   long long k;   struct pos {     char c;     int nom;   };   pos a[100003];   pos b[100003];   pos c[100003];   void mergesort(pos *a, pos *b, int n) {     int i, i1, i0, iRight, iEnd, width, j;     for (width = 1; width < n; width *= 2)       for (i = 0; i < n; i += width * 2) {         i0 = i;         i1 = iRight = min(i + width, n);         iEnd = min(i + width * 2, n);         for (j = i; j < iEnd; j++)           if (i0 < iRight && (i1 == iEnd || a[i0].c <= a[i1].c))             b[j] = a[i0++];           else             b[j] = a[i1++];         for (j = i; j < iEnd; j++) a[j] = b[j];       }   }   int main() {     scanf( %s , s);     scanf( %I64d , &k);     int i, j, jj;     for (i = 0; s[i]; i++) {       a[i].nom = i;       a[i].c = s[i];     }     long long n = i;     if (k > ((n * (n + 1)) >> 1)) {       printf( No such line. n );       return 0;     }     long long sum;     long long add;     int coun = n;     while (k > 0) {       mergesort(a, c, coun);       sum = 0;       i = 0;       while (i < coun) {         add = 0;         j = i;         while (j < coun && a[j].c == a[i].c) j++;         for (jj = i; jj < j; jj++) add += n - a[jj].nom;         if (sum + add >= k) break;         sum += add;         i = j;       }       printf( %c , a[i].c);       k -= sum;       k -= j - i;       coun = 0;       for (jj = i; jj < j; jj++) {         if (a[jj].nom != n - 1) {           b[coun].c = s[a[jj].nom + 1];           b[coun++].nom = a[jj].nom + 1;         }       }       for (jj = 0; jj < coun; jj++) a[jj] = b[jj];     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200001];   int b[200001];   int main() {     cin >> n;     int tong = 0;     int i;     for (i = 1; i <= n; i++) cin >> a[i], tong += a[i];     int k = 1;     i = 1;     bool ok = true;     while (i <= n) {       if (tong % n == 0 && a[i] == tong / n) {         b[k] = i;         k++;         ok = false;       }       i++;     };     if (ok) {       cout << 0 << endl;       return 0;     }     cout << k - 1 << endl;     for (i = 1; i < k; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct SEG {     int segment_length;     char chars;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     string s;     cin >> s;     SEG cur;     vector<SEG> st;     cur.segment_length = 0;     cur.chars =  - ;     for (char x : s) {       if (x == cur.chars) {         cur.segment_length++;       } else {         if (cur.segment_length > 0) st.push_back(cur);         cur.segment_length = 1;         cur.chars = x;       }     }     st.push_back(cur);     int ans = 0;     int p;     while (((int)(st).size()) > 1) {       vector<SEG> effect;       for (int x = 0; x < ((int)(st).size()); x++) {         cur = st[x];         if (x == 0 or x == ((int)(st).size()) - 1) {           cur.segment_length--;         } else {           cur.segment_length -= 2;         }         if (cur.segment_length <= 0) {           continue;         }         if (effect.empty()) {           effect.push_back(cur);         } else {           if (effect.back().chars == cur.chars) {             effect.back().segment_length += cur.segment_length;           } else {             effect.push_back(cur);           }         }       }       st = effect;       ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s, min, max, l, r;     cin >> n;     s = pow(n, 2);     long long int v[s + 1];     for (long long int i = 0; i < s; i++) {       v[i] = i + 1;     }     for (long long int i = 0; i < n; i++) {       l = i;       r = n - 1;       if (n % 2 == 0) {         for (long long int j = 1; j <= n; j++) {           if (j <= n / 2) {             min = *min_element(v + l, v + r);             cout << min <<    ;             l = l + n;             r = r + n;           }           if (j > n / 2) {             max = *max_element(v + l - i, v + r - i + 1);             cout << max <<    ;             l = l + n;             r = r + n;           }         }       }       if (n % 2 != 0) {         for (long long int j = 1; j <= n; j++) {           if (j <= (n / 2) + 1) {             min = *min_element(v + l, v + r);             cout << min <<    ;             l = l + n;             r = r + n;           }           if (j > (n / 2) + 1) {             max = *max_element(v + l - i, v + r - i + 1);             cout << max <<    ;             l = l + n;             r = r + n;           }         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string n;     int s;     cin >> n >> s;     int sum = 0;     vector<int> digit;     for (int i = 0; i < (int)n.size(); i++) {       digit.push_back(n[i] -  0 );       sum += digit[i];     }     if (sum <= s) {       cout << 0 <<   n ;       return;     }     sum = 0;     int pos = -1;     for (int i = 0; i < (int)digit.size(); i++) {       sum += digit[i];       if (sum >= s) {         pos = i;         s -= (sum - digit[i]);         break;       }     }     if (pos == 0) {       digit.insert(digit.begin(), 1);       pos++;     } else {       digit[pos - 1]++;     }     for (int i = pos; i < (int)digit.size(); i++) digit[i] = 0;     long long num = 0;     for (int i = 0; i < (int)digit.size(); i++) num = num * 10 + digit[i];     long long res = num - stoll(n);     cout << res <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using LD = long double;   void err() { cerr <<   033[39;0m  << endl; }   template <typename T, typename... A>   void err(T a, A... x) {     cerr << a <<    ;     err(x...);   }   const int N = 1e6 + 10;   struct Node {     map<int, Node*> link;     Node* fa;     int count;   } pool[N];   int cnt;   Node* new_node(Node* fa) {     Node* ret = pool + cnt++;     ret->fa = fa;     ret->link.clear();     ret->count = 0;     return ret;   }   int stk[N], top;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       top = 0;       LL ans = 0;       auto cur = new_node(nullptr);       cur->count = 1;       for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i) {         int c;         cin >> c;         if (top == 0 || stk[top - 1] != c) {           if (!cur->link[c]) {             cur->link[c] = new_node(cur);           }           cur = cur->link[c];           ans += cur->count++;           stk[top++] = c;         } else {           cur = cur->fa;           ans += cur->count++;           --top;         }       }       cout << ans << endl;     }     return 0;   }