#include <bits/stdc++.h>   using namespace std;   char a[1001], b[1001];   int main() {     int sa, sb, i, j, ta = 0, tb = 0;     cin >> a >> b;     sa = strlen(a);     sb = strlen(b);     for ((i) = 0; (i) < (sa); (i)++)       if (a[i] ==  1 ) ta++;     for ((i) = 0; (i) < (sb); (i)++)       if (b[i] ==  1 ) tb++;     if (ta >= tb)       cout <<  YES  << endl;     else if (ta % 2 && tb == ta + 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tree[100005];   int bad[100005];   vector<int> result;   int SubTree[100005];   int dfs(int v, int pv) {     SubTree[v] = (int)(bad[v] == 1);     for (auto u : tree[v]) {       if (u == pv) continue;       SubTree[v] += dfs(u, v);     }     if (SubTree[v] == 1) result.push_back(v);     return SubTree[v];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N;     cin >> N;     for (int i = 0; i < N - 1; i++) {       int a, b, c;       cin >> a >> b >> c;       tree[a].push_back(b);       tree[b].push_back(a);       if (c == 2) {         bad[a] = bad[b] = 1;       }     }     dfs(1, 0);     cout << result.size() <<   n ;     for (auto i : result) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int mod = 1000000007;   int N;   vector<int> g[100001];   vector<int> time_in(100001);   vector<int> time_out(100001);   int cnt;   void dfs(int v) {     cnt++;     time_in[v] = cnt;     for (int i : g[v]) {       if (time_in[i] == 0) dfs(i);     }     cnt++;     time_out[v] = cnt;   }   void slv() {     cin >> N;     if (N % 2) {       cout << -1;       return;     }     int x, y;     for (int i = 1; i <= N - 1; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= N; i++) {       if (g[i].size() == 1) {         dfs(i);         break;       }     }     int ans = 0;     for (int i = 1; i <= N; i++) {       int cur = time_out[i] - time_in[i] + 1;       if (cur == 0) continue;       if (cur % 4 == 0) {         ans++;       }     }     cout << (ans == 0 ? -1 : ans - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) slv();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100009;   long long n, a[maxn], b[maxn], c[maxn], in[maxn], color[maxn];   void read(long long a[]) {     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);   }   void over() {     cout << -1;     exit(0);   }   vector<int> vec[maxn];   void dfs(int now, int fa, int se1, int se2) {     for (int i = 0; i < vec[now].size(); i++) {       int v = vec[now][i];       if (v == fa) continue;       color[v] = 6 - se1 - se2;       dfs(v, now, se2, color[v]);     }   }   long long ans = 1e18;   long long isok(int i, int s) {     if (s == 1)       return a[i];     else if (s == 2)       return b[i];     else       return c[i];   }   void DP(int q, int w, int e) {     long long temp = 0;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         temp += isok(i, q);       else if (color[i] == 2)         temp += isok(i, w);       else         temp += isok(i, e);     ans = min(ans, temp);   }   void sovle(int q, int w, int e) {     long long temp = 0;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         temp += isok(i, q);       else if (color[i] == 2)         temp += isok(i, w);       else         temp += isok(i, e);     if (temp != ans) return;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         cout << q <<    ;       else if (color[i] == 2)         cout << w <<    ;       else         cout << e <<    ;     exit(0);   }   int main() {     cin >> n;     read(a), read(b), read(c);     for (int i = 1; i < n; i++) {       int l, r;       scanf( %d%d , &l, &r);       in[l]++, in[r]++;       vec[l].push_back(r);       vec[r].push_back(l);     }     for (int i = 1; i <= n; i++)       if (in[i] >= 3) over();     int last;     for (int i = 1; i <= n; i++)       if (in[i] == 1) last = i;     color[last] = 1, color[vec[last][0]] = 2;     dfs(vec[last][0], last, 1, 2);     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) {         if (j == i) continue;         for (int q = 1; q <= 3; q++) {           if (q == i || q == j) continue;           DP(i, j, q);         }       }     cout << ans << endl;     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) {         if (j == i) continue;         for (int q = 1; q <= 3; q++) {           if (q == i || q == j) continue;           sovle(i, j, q);         }       }   }


#include <bits/stdc++.h>   using namespace std;   unordered_set<int> int_set;   set<int, greater<int> > divisors;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string a;     cin >> a;     if ((a.size()) == 1) {       cout << a << a <<   n ;       return 0;     } else {       string rev = string(a.rbegin(), a.rend());       a += rev;       cout << a <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int a[100005];   bitset<100005> sign;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     long long sum = 0LL;     for (int i = n - 1; i >= 0; i--) {       if (abs(sum - a[i]) < abs(sum + a[i])) {         sum -= a[i];         sign[i] = true;       } else {         sum += a[i];       }     }     for (int i = 0; i < n; i++) printf( %c , sign[i] ^ (sum > 0) ?  +  :  - );     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct Node {     long long x, y;   } p[N];   int n;   double ans, a, b, c, xx, x1, yy1, x2, x3, y2, y3, x, y;   int tf;   map<pair<long long, long long>, int> f;   inline double dis(Node a, Node b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   inline long long dis1(Node a, Node b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   inline double check(double x, double y) {     double ans = 2e9 + 7;     for (int i = 1; i <= n; i++)       ans = std::min(           ans, sqrt((x - p[i].x) * (x - p[i].x) + (y - p[i].y) * (y - p[i].y)));     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &p[i].x, &p[i].y);       f[make_pair(p[i].x, p[i].y)] = 1;     }     ans = -1;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         for (int k = j + 1; k <= n; k++) {           a = dis(p[i], p[j]), b = dis(p[i], p[k]), c = dis(p[j], p[k]), tf = 1;           if (abs(a - b) < 1e-10 && abs(c * c - a * a - b * b) < 1e-10 &&               f[make_pair(p[j].x + p[k].x - p[i].x, p[j].y + p[k].y - p[i].y)])             x = (p[j].x + p[k].x) / 2.0, y = (p[j].y + p[k].y) / 2.0;           else if (abs(a - c) < 1e-10 && abs(b * b - a * a - c * c) < 1e-10 &&                    f[make_pair(p[i].x + p[k].x - p[j].x,                                p[i].y + p[k].y - p[j].y)])             x = (p[i].x + p[k].x) / 2.0, y = (p[i].y + p[k].y) / 2.0;           else if (abs(b - c) < 1e-10 && abs(a * a - b * b - c * c) < 1e-10 &&                    f[make_pair(p[j].x + p[i].x - p[k].x,                                p[j].y + p[i].y - p[k].y)])             x = (p[j].x + p[i].x) / 2.0, y = (p[j].y + p[i].y) / 2.0;           else             tf = 0;           if (tf) {             xx = check(x, y);             if (abs(xx - sqrt((x - p[i].x) * (x - p[i].x) +                               (y - p[i].y) * (y - p[i].y))) < 1e-10 ||                 xx - sqrt((x - p[i].x) * (x - p[i].x) +                           (y - p[i].y) * (y - p[i].y)) >                     1e-10)               ans = std::max(ans, sqrt((x - p[i].x) * (x - p[i].x) +                                        (y - p[i].y) * (y - p[i].y)));           }           if (abs(a + b - c) < 1e-10 || c - a - b > 1e-10 ||               abs(a + c - b) < 1e-10 || b - a - c > 1e-10 ||               abs(b + c - a) < 1e-10 || a - b - c > 1e-10)             continue;           if (dis1(p[i], p[j]) + dis1(p[i], p[k]) <= dis1(p[j], p[k]) ||               dis1(p[j], p[i]) + dis1(p[j], p[k]) <= dis1(p[i], p[k]) ||               dis1(p[k], p[i]) + dis1(p[k], p[j]) <= dis1(p[i], p[j]))             continue;           x1 = p[i].x, x2 = p[j].x, x3 = p[k].x, yy1 = p[i].y, y2 = p[j].y,           y3 = p[k].y;           x = ((x1 * x1 - x2 * x2 + yy1 * yy1 - y2 * y2) * (yy1 - y3) -                (x1 * x1 - x3 * x3 + yy1 * yy1 - y3 * y3) * (yy1 - y2)) /               (2 * (yy1 - y3) * (x1 - x2) - 2 * (yy1 - y2) * (x1 - x3));           y = ((x1 * x1 - x2 * x2 + yy1 * yy1 - y2 * y2) * (x1 - x3) -                (x1 * x1 - x3 * x3 + yy1 * yy1 - y3 * y3) * (x1 - x2)) /               (2 * (yy1 - y2) * (x1 - x3) - 2 * (yy1 - y3) * (x1 - x2));           xx = check(x, y);           if (abs(xx - sqrt((x - p[i].x) * (x - p[i].x) +                             (y - p[i].y) * (y - p[i].y))) < 1e-10 ||               xx - sqrt((x - p[i].x) * (x - p[i].x) +                         (y - p[i].y) * (y - p[i].y)) >                   1e-10)             ans = std::max(ans, sqrt((x - p[i].x) * (x - p[i].x) +                                      (y - p[i].y) * (y - p[i].y)));         }       }     }     if (ans < 0)       printf( -1 n );     else       printf( %.6lf n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   void solve() {     int m, n;     cin >> n >> m;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (char c : s) {         v[i] *= 2;         v[i] += c -  0 ;       }     }     long long need = ((1ll << m) - n - 1) / 2 + 1;     long long cur = (1ll << (m - 1)) - 1;     while (true) {       long long left = cur + 1;       bool flag = false;       for (int i = 0; i < n; i++) {         flag |= v[i] == cur;         if (v[i] <= cur) {           left--;         }       }       if (left == need && !flag) {         string s;         for (int i = 0; i < m; i++) {           s += (char)(cur % 2 +  0 );           cur /= 2;         }         reverse(s.begin(), s.end());         cout << s << endl;         return;       } else if (left < need) {         cur++;       } else {         cur--;       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int q;   int cnt[1 << 20];   int trans(long long v) {     int rt = 0;     for (int i = 0; i < 18; i++, v /= 10) {       if ((v % 10) & 1) {         rt |= 1 << i;       }     }     return rt;   }   void insert(long long v) { cnt[trans(v)]++; }   void erase(long long v) { cnt[trans(v)]--; }   int query(long long v) {     int bit = 0;     for (int i = 0; i < 18; i++, v /= 10) {       if (v & 1) {         bit |= 1 << i;       }     }     return cnt[bit];   }   int main() {     cin >> q;     while (q--) {       char ch[10];       long long v;       cin >> ch >> v;       if (ch[0] ==  + ) {         insert(v);       } else if (ch[0] ==  - ) {         erase(v);       } else {         cout << query(v) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[201];   int main() {     int n, t, w, sumt = 0, sumw = 0;     memset(dp, -1, sizeof(dp));     dp[0] = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &t, &w);       sumt += t;       sumw += w;       for (int j = 200; j >= t; j--) {         if (dp[j - t] != -1) dp[j] = max(dp[j], dp[j - t] + w);       }     }     int ans = sumt;     for (int i = 0; i <= sumt; i++) {       if (sumw - dp[i] <= i) {         ans = i;         break;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int inf = (1 << 28) - 1;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) {       x = _x;       y = _y;     }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator^(const Point &b) const { return x * b.y - y * b.x; }     double operator*(const Point &b) const { return x * b.x + y * b.y; }     void transXY(double B) {       double tx = x, ty = y;       x = tx * cos(B) - ty * sin(B);       y = tx * sin(B) + ty * cos(B);     }   };   struct Line {     Point s, e;     Line() {}     Line(Point _s, Point _e) {       s = _s;       e = _e;     }   };   double dist(Point a, Point b) { return sqrt((a - b) * (a - b)); }   Point NearestPointToLineSeg(Point P, Line L) {     Point result;     double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s));     if (t >= 0 && t <= 1) {       result.x = L.s.x + (L.e.x - L.s.x) * t;       result.y = L.s.y + (L.e.y - L.s.y) * t;     } else {       if (dist(P, L.s) < dist(P, L.e))         result = L.s;       else         result = L.e;     }     return result;   }   const double PAI = acos(-1);   int main() {     Point A, tmp, now, sta;     int n;     scanf( %d%lf%lf , &n, &A.x, &A.y);     double Max = -1, Min = inf;     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &now.x, &now.y);       if (i > 1)         Min = min(Min, dist(A, NearestPointToLineSeg(A, Line(tmp, now))));       else         sta = now;       Min = min(Min, dist(A, now));       Max = max(Max, dist(A, now));       tmp = now;     }     Min = min(Min, dist(A, NearestPointToLineSeg(A, Line(sta, now))));     printf( %.18lf n , (PAI * Max * Max) - (PAI * Min * Min));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     long long n;     int k;     cin >> n >> k;     long long num = 0;     long long idx = 1;     long long todie = n;     for (int i = 0; i < k; ++i) {       long long x;       cin >> x;       if (n % x < todie) {         todie = n % x;         idx = i + 1;         num = n / x;       }     }     cout << idx <<     << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int N;     scanf( %d , &N);     long long res = 0;     for (int i = 2; i <= N / 2; i++) {       long long m = N / i;       res += (m * (m + 1) / 2 - 1) * 4;     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const int MAXN = 2e3 + 10;   int ans[MAXN * 3], vis[MAXN][MAXN];   int dp[MAXN][MAXN], n, kk, dir[4][2] = {1, 0, 0, 1};   char mp[MAXN][MAXN];   struct Node {     int x, y, s;     Node(int x, int y, int s) : x(x), y(y), s(s){};   };   queue<Node> q;   void bfs() {     while (!q.empty()) {       Node u = q.front();       q.pop();       int x = u.x;       int y = u.y;       int s = u.s;       if (n == 100 && kk == 1 && q.size() > 100000) {         printf( siz = %d, x = %d, y = %d, s = %d n , q.size(), x, y, s);         return;       }       if (s >= 2 * n - 1) continue;       if (mp[x][y] -  a  > ans[s]) continue;       for (int i = 0; i < 2; i++) {         int dx = x + dir[i][0];         int dy = y + dir[i][1];         if (dx > n || dy > n) continue;         if (mp[dx][dy] -  a  <= ans[s + 1] && vis[dx][dy] == 0) {           vis[dx][dy] = 1;           ans[s + 1] = mp[dx][dy] -  a ;           q.push(Node(dx, dy, s + 1));         }       }     }   }   int main() {     cin >> n >> kk;     memset(ans, INF, sizeof ans);     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     int cnt = 0;     if (kk) {       if (mp[1][1] ==  a )         dp[1][1] = kk;       else         dp[1][1] = kk - 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) {           if (i - 1 >= 1 && dp[i - 1][j] >= 0) {             int tmp = dp[i - 1][j];             if (mp[i][j] !=  a ) tmp--;             dp[i][j] = max(dp[i][j], tmp);           }           if (j - 1 >= 1 && dp[i][j - 1] >= 0) {             int tmp = dp[i][j - 1];             if (mp[i][j] !=  a ) tmp--;             dp[i][j] = max(dp[i][j], tmp);           }           if (dp[i][j] >= 0) cnt = max(cnt, i + j - 1);         }       if (dp[n][n] >= 0) {         for (int i = 1; i < 2 * n; i++) printf( a );         return 0;       }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (dp[i][j] == 0 && i + j - 1 == cnt) {             vis[i][j] = 1;             q.push(Node(i, j, cnt));             mp[i][j] =  a ;           }       for (int i = 1; i <= cnt; i++) ans[i] = 0;     } else {       vis[1][1] = 1;       q.push(Node(1, 1, 1));       ans[1] = mp[1][1] -  a ;     }     bfs();     for (int i = 1; i < 2 * n; i++) printf( %c , ans[i] +  a );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &sum) {     sum = 0;     char c = getchar();     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     if (f) sum = -sum;   }   void read(long long &sum) {     sum = 0;     char c = getchar();     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     if (f) sum = -sum;   }   void readvec(vector<int> &a, int n) {     for (int i = 0; i < n; i++) read(a[i]);   }   void readvec(vector<long long> &a, long long n) {     for (int i = 0; i < n; i++) read(a[i]);   }   const int MOD = 1e9 + 7;   const int INF = (int)2e9 + 7;   const long long LINF = (long long)1e18;   const long double PI = 3.1415926535897932384626433832795;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n;     read(n);     vector<int> v(n);     readvec(v, n);     if (n == 1) {       cout << -1;       return;     }     if (n == 2 && v[0] == v[1]) {       cout << -1;       return;     }     int ind, mn = 1001;     for (int i = 0; i < n; i++) {       if (v[i] < mn) {         mn = v[i];         ind = i;       }     }     cout << 1 <<   n ;     cout << ind + 1 <<   n ;   }   int32_t main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1000010;   int prime[5005];   long long f[MAXN][22];   void getPrime() {     for (int i = 2; i <= 5000; i++) {       if (!prime[i]) prime[++prime[0]] = i;       for (int j = 1; j <= prime[0] && prime[j] <= 5000 / i; j++) {         prime[prime[j] * i] = 1;         if (i % prime[j] == 0) break;       }     }   }   void init() {     f[0][0] = 1;     for (int i = 1; i <= 20; ++i) {       f[0][i] = 2;     }     for (int i = 1; i <= 1000000; ++i) {       f[i][0] = 1;       for (int j = 1; j <= 20; ++j) {         f[i][j] = (f[i][j - 1] + f[i - 1][j]) % MOD;       }     }   }   int q, r, n;   int main() {     init();     getPrime();     scanf( %d , &q);     while (q--) {       scanf( %d%d , &r, &n);       long long ans = 1;       int cnt = 0;       for (int i = 1, tmp; prime[i] * prime[i] <= n && i <= prime[0]; ++i) {         tmp = prime[i];         if (n == 1) break;         if (n % tmp == 0) {           while (n % tmp == 0) {             n /= tmp;             cnt++;           }         }         ans = ans * f[r][cnt] % MOD;         cnt = 0;       }       if (n > 1) {         ans = ans * (long long)f[r][1] % MOD;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     int x;     scanf( %d , &x);     return x;   }   struct Segment_Tree {     int dep, f, tag;   } t[200005 << 2];   struct Qry {     int x, tm, id;   } q[200005];   struct _Edge {     int to, next;   } Edge[200005 << 1];   int head[200005], CNT;   int top[200005], dfn[200005], rec[200005], dep[200005], son[200005], sz[200005],       ans[200005], fa[200005], n, m, tot;   inline void AddEdge(int u, int v) {     Edge[++CNT] = (_Edge){v, head[u]};     head[u] = CNT;     return;   }   void dfs1(int u, int deep) {     dep[u] = deep;     son[u] = 0;     sz[u] = 1;     for (int e = head[u]; e; e = Edge[e].next) {       int v = Edge[e].to;       dfs1(v, deep + 1);       sz[u] += sz[v];       if (!son[u] || sz[son[u]] < sz[v]) son[u] = v;     }     return;   }   void dfs2(int u, int upp) {     top[u] = upp;     dfn[u] = ++tot;     rec[tot] = u;     if (son[u])       dfs2(son[u], upp);     else       return;     for (int e = head[u]; e; e = Edge[e].next)       if (Edge[e].to != son[u]) dfs2(Edge[e].to, Edge[e].to);     return;   }   void Build(int o, int l, int r) {     t[o].f = t[o].tag = -2147483640;     if (l == r) {       t[o].dep = 2 * dep[rec[l]];       return;     }     int mid = (l + r) >> 1;     Build(o << 1, l, mid);     Build(o << 1 | 1, mid + 1, r);     t[o].dep = max(t[o << 1].dep, t[o << 1 | 1].dep);   }   inline void up(int o, int v) {     t[o].f = max(t[o].f, v + t[o].dep);     t[o].tag = max(t[o].tag, v);   }   inline void PushDown(int o) {     if (t[o].tag == -2147483640) return;     up(o << 1, t[o].tag);     up(o << 1 | 1, t[o].tag);     t[o].tag = -2147483640;     return;   }   void Update(int o, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) {       up(o, v);       return;     }     int mid = (l + r) >> 1;     PushDown(o);     if (ql <= mid) Update(o << 1, l, mid, ql, qr, v);     if (mid < qr) Update(o << 1 | 1, mid + 1, r, ql, qr, v);     t[o].f = max(t[o << 1].f, t[o << 1 | 1].f);   }   int Query(int o, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return t[o].f;     int mid = (l + r) >> 1, ret = -2147483640;     PushDown(o);     if (ql <= mid) ret = max(ret, Query(o << 1, l, mid, ql, qr));     if (mid < qr) ret = max(ret, Query(o << 1 | 1, mid + 1, r, ql, qr));     return ret;   }   inline int Calc(int x, int tm) {     int vl = dep[x] + tm, u = x, ret = 0, Ans;     while (u) {       if (Query(1, 1, n, dfn[top[u]], dfn[u]) <= vl) {         u = fa[top[u]];       } else {         int l = dfn[top[u]] + 1, r = dfn[u] + 1;         if (Query(1, 1, n, dfn[u], dfn[u]) > vl)           ret = u;         else {           while (l <= r) {             int mid = (l + r) >> 1;             if (Query(1, 1, n, mid, dfn[u]) <= vl)               ret = mid, r = mid - 1;             else               l = mid + 1;           }           ret = fa[rec[ret]];         }         break;       }     }     if (!ret) ret = 1;     u = x;     Ans = 2 * (dep[x] - dep[ret]) + tm;     while (top[u] ^ top[ret]) {       Update(1, 1, n, dfn[top[u]], dfn[u], Ans - dep[x]);       u = fa[top[u]];     }     Update(1, 1, n, dfn[ret], dfn[u], Ans - dep[x]);     return Ans;   }   inline bool cmp1(Qry A, Qry B) {     return ((dep[A.x] + A.tm) ^ (dep[B.x] + B.tm))                ? dep[A.x] + A.tm < dep[B.x] + B.tm                : A.x < B.x;   }   int main() {     n = gi() + 1;     m = gi();     for (int i = 2; i <= n; i++) fa[i] = gi() + 1, AddEdge(fa[i], i);     dfs1(1, 1);     dfs2(1, 1);     Build(1, 1, n);     for (int i = 1; i <= m; i++) q[i].x = gi() + 1, q[i].tm = gi(), q[i].id = i;     sort(q + 1, q + m + 1, cmp1);     for (int i = 1; i <= m; i++) ans[q[i].id] = Calc(q[i].x, q[i].tm);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, i;       int d = 0, c = 0;       cin >> n;       string s;       cin >> s;       for (i = n - 1; i >= 0; i--) {         if (s[i] ==  P )           c++;         else {           d = max(d, c);           c = 0;         }       }       cout << d << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long inf = 1e18;   const int maxn = 2e5 + 10;   const double eps = 1e-7;   const double pi = 3.14159265359;   long long n, m, a[maxn], par[maxn];   bool check(int x) {     long long now = 0;     long long cnt = 0;     long long cal = 0;     for (int i = 0; i < n; i++) {       if (cal >= x) {         cal = 0;         cnt++;       }       if (a[i] - cnt > 0) {         now += a[i] - cnt;         cal++;       }     }     if (now >= m) {       return 1;     }     return 0;   }   int main() {     std::ios::sync_with_stdio(0);     ;     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     reverse(a, a + n);     par[0] = a[0];     for (int i = 1; i < n; i++) {       par[i] = par[i - 1] + a[i];     }     int ans = -1;     long long l = 1, r = n + 5, mid;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct str {     long long num;     long long id;   } st[666666];   long long arr[666666];   bool cmp(str a, str b) { return a.num < b.num; }   signed main() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];     }     long long ans = min(arr[1], arr[n]) / (n - 1);     for (long long i = 2; i < n; i++) {       long long t1 = min(arr[i], arr[1]) * 1ll / (i - 1) * 1ll;       long long t2 = min(arr[i], arr[n]) / (n - i) * 1ll;       ans = min(ans, min(t1, t2));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int a[100005];   long long tree[2 * 100005], tree2[2 * 100005];   vector<long long> mapa;   int mp(double val) {     return upper_bound(mapa.begin(), mapa.end(), val) - mapa.begin();   }   void update(int pos, int val) {     for (int i = pos; i < 2 * 100005; i += i & -i) tree[i] += val;   }   void update2(int pos, int val) {     for (int i = pos; i < 2 * 100005; i += i & -i) tree2[i] += val;   }   void upd(int pos, int val) {     int posi = mp(a[pos - 1]);     update(posi, -a[pos - 1]);     update2(posi, -1);     a[pos - 1] = val;     posi = mp(val);     update(posi, val);     update2(posi, 1);   }   long long query(int pos) {     long long res = 0;     for (int i = pos; i > 0; i -= i & -i) res += tree[i];     return res;   }   long long query2(int pos) {     long long res = 0;     for (int i = pos; i > 0; i -= i & -i) res += tree2[i];     return res;   }   long double f(long double x) {     double res;     int pos = mp(x);     res = x * query2(pos) - query(pos);     return res;   }   struct quer {     int t, p;     long long v;     quer(){};     quer(int t, int p, long long v) : t(t), p(p), v(v){};   } qry[100005];   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , a + i), mapa.push_back(a[i]);     for (int i = 0, t, p = 0; i < q; i++) {       long long v;       cin >> t;       if (t == 1)         cin >> p >> v, mapa.push_back(v);       else         cin >> v;       qry[i] = quer(t, p, v);     }     sort(mapa.begin(), mapa.end());     mapa.resize(unique(mapa.begin(), mapa.end()) - mapa.begin());     for (int i = 0; i < n; i++) {       int posi = mp(a[i]);       update(posi, a[i]);       update2(posi, 1);     }     for (int i = 0; i < q; i++) {       quer Q = qry[i];       if (Q.t == 1) {         upd(Q.p, Q.v);       } else {         double l = 0, r = 1000000001;         while (l + 1e-5 <= r) {           double m = l + (r - l) / 2;           if (f(m) < Q.v)             l = m + 1e-5;           else             r = m;         }         if (abs(l - 1000000001) <= 1e-5 && abs(f(l) - Q.v) > 1e-5) {           l = 1.0 * (Q.v + query(2 * 100005 - 1)) / n;         }         printf( %.5lf n , l);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void solve() {     scanf( %d , &n);     int tmp, tot;     if (n == 0) {       printf( O-|-OOOO n );       return;     }     while (n) {       tmp = n % 10;       if (tmp >= 5) {         tot = tmp - 5;         printf( -O| );       } else {         tot = tmp;         printf( O-| );       }       for (int i = 1; i <= tot; i++) printf( O );       printf( - );       for (int i = 1; i <= 4 - tot; i++) printf( O );       printf(  n );       n /= 10;     }   }   int main() {     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10;   int n, m, c = 0, ans = 0;   vector<int> adj[maxn], bkadj[maxn], components, nodes[maxn], sink;   bool mark[maxn];   int cmp[maxn], d[maxn], o[maxn];   stack<int> st;   queue<int> q;   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int fi, se;       cin >> fi >> se;       adj[fi].push_back(se);       bkadj[se].push_back(fi);     }   }   void dfs1(int x) {     mark[x]++;     for (int i = 0; i < adj[x].size(); i++) {       int child = adj[x][i];       if (!mark[child]) dfs1(child);     }     st.push(x);   }   void dfs2(int x) {     mark[x]++;     nodes[cmp[x]].push_back(x);     for (int i = 0; i < bkadj[x].size(); i++) {       int child = bkadj[x][i];       if (!mark[child]) {         cmp[child] = cmp[x];         dfs2(child);       } else if (cmp[child] != cmp[x])         o[cmp[child]]++;     }   }   int bfs(int x) {     memset(mark, 0, sizeof mark);     q.push(x);     d[x] = 1;     mark[x]++;     int mi = 1e8;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < adj[cur].size(); i++) {         int child = adj[cur][i];         if (!mark[child]) {           mark[child]++;           d[child] = d[cur] + 1;           q.push(child);         } else if (child == x)           mi = min(mi, d[cur]);       }     }     return mi;   }   void task() {     for (int i = 1; i <= n; i++)       if (!mark[i]) dfs1(i);     memset(mark, 0, sizeof mark);     while (!st.empty()) {       int x = st.top();       st.pop();       if (!mark[x]) cmp[x] = x, components.push_back(x), dfs2(x);     }     for (int i = 0; i < components.size(); i++)       if (o[components[i]] == 0) sink.push_back(components[i]);     for (int i = 0; i < sink.size(); i++) {       int cm = sink[i];       if (nodes[cm].size() != 1) {         c++;         int mi = 1e8;         for (int i = 0; i < nodes[cm].size(); i++) {           int cur = nodes[cm][i];           mi = min(mi, bfs(cur));         }         ans += mi;       }     }   }   void debug() {     for (int i = 1; i <= n; i++) cerr << i <<  :  << cmp[i] << endl;   }   int main() {     input();     task();     cout << n + (ans * 998) + c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[150000], b[510000], arr[226660];   int main() {     int n, x, k;     cin >> n >> k >> x;     int cnt = 1;     int l = 0;     cin >> arr[0];     for (int i = 1; i < n; i++) {       cin >> arr[i];       if (arr[i] == arr[i - 1]) {         cnt++;       } else {         a[l] = arr[i - 1];         b[l++] = cnt;         cnt = 1;       }     }     a[l] = arr[n - 1];     b[l++] = cnt;     int sum = 0;     for (int i = 0; i < l; i++) {       int ans = 0;       if (a[i] == x) {         if (b[i] + 1 >= 3) {           ans += b[i];           int u = i - 1;           int v = i + 1;           while (a[u] == a[v] && b[u] + b[v] >= 3 && u >= 0 && v < n) {             ans += b[u] + b[v];             u--;             v++;           }           sum = max(sum, ans);         }       }     }     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     n /= 2;     vector<long long> x(n);     for (long long i = 0; i < n; ++i) {       cin >> x[i];     }     vector<vector<pair<long long, long long>>> as(n);     for (long long i = 0; i < n; ++i) {       for (long long a = 1; a * a < x[i]; ++a) {         if (x[i] % a) {           continue;         }         long long b = x[i] / a;         if ((b + a) % 2) {           continue;         }         as[i].emplace_back((b - a) / 2, (b + a) / 2);       }       reverse(as[i].begin(), as[i].end());     }     vector<long long> y(n);     long long last = 0;     for (long long i = 0; i < n; ++i) {       pair<long long, long long> tf = {last, 0};       long long j = lower_bound(as[i].begin(), as[i].end(), tf) - as[i].begin();       if (j >= as[i].size()) {         cout <<  No ;         return 0;       }       tf = as[i][j];       y[i] = tf.first * tf.first - last * last;       last = tf.second;     }     for (long long i = 0; i < n; ++i) {       if (y[i] < 1) {         cout <<  No ;         return 0;       }     }     cout <<  Yes  <<   n ;     for (long long i = 0; i < n; ++i) {       cout << y[i] <<     << x[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int t, a, b, a1, b1;     cin >> t;     while (t--) {       cin >> a >> b;       a1 = max(a, b);       b1 = min(a, b);       if (a1 >= (2 * b1)) {         cout << b1 << endl;       } else {         cout << (a1 - b1) + (2 * ((b1 - (a1 - b1)) / 3)) +                     (((b1 - (a1 - b1)) % 3) == 2 ? 1 : 0)              << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   unsigned char a[200042];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %hhu , &a[i]);     int q;     scanf( %d , &q);     while (q--) {       int l, r;       unsigned char x, y;       scanf( %d%d%hhu%hhu , &l, &r, &x, &y);       for (int i = l - 1; i < r; i++) a[i] = a[i] == x ? y : a[i];     }     for (int i = 0; i < n; ++i) printf( %hhu  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 12;   int a[maxn], n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int cnt = 0;     for (int i = 2; i < n; i++) {       if (a[1] < a[i] && a[i] < a[n]) cnt++;     }     cout << cnt;   }


#include <bits/stdc++.h>   int main() {     int n, k;     scanf( %d %d , &n, &k);     while (k--) {       if (n % 10 != 0) {         n = n - 1;       } else {         n = n / 10;       }     }     printf( %d n , n);   }


#include <bits/stdc++.h>   int in() {     int r = 0, c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) return -in();     for (; c > 32; r = (r << 1) + (r << 3) + c -  0 , c = getchar())       ;     return r;   }   using namespace std;   const int INF = int(1e9 + 7);   long long v[100010];   int main() {     long long n, u;     double ans = -1;     cin >> n >> u;     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n - 2; i++) {       long long a = v[i], b = v[i + 1];       long long lo = i + 2, hi = n - 1, mid;       double res = -1;       while (lo <= hi) {         mid = (lo + hi) / 2;         if (v[mid] - a <= u) {           res = (double)(v[mid] - b) / (double)(v[mid] - a);           lo = mid + 1;         } else           hi = mid - 1;       }       ans = max(ans, res);     }     if (ans >= 0)       cout << fixed << setprecision(10) << ans << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K = 0;   int ans[1005];   int main() {     scanf( %d , &N);     int i, j, tmp = 0;     for (i = 1; i * 2 < N; i++) {       ++K;       ans[K] = i;       N -= i;     }     printf( %d n , K + 1);     for (i = 1; i <= K; i++) printf( %d  , ans[i]);     printf( %d n , N);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w[1010000], n, Res[1010000], Mod = 1000000007;   long long S[1010000], K;   vector<int> E[1010000], G[1010000], d;   void DFS(int a) {     S[a] = w[a];     for (auto &x : E[a]) {       DFS(x);       S[a] += S[x];     }   }   void Go(int a) {     int i, c = 0;     for (i = 1; i * i < a; i++) {       if (a % i == 0) {         c += G[i].size();         c += G[a / i].size();       }     }     if (i * i == a) c += G[i].size();     if (c == a) {       Res[a] = 1;       for (auto &x : d) {         if (x % a == 0) Res[a] = (Res[a] + Res[x]) % Mod;       }       d.push_back(a);     }   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     int i, a, b;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &w[i]);     for (i = 2; i <= n; i++) {       scanf( %d , &a);       E[a].push_back(i);     }     DFS(1);     for (i = 1; i <= n; i++) {       long long g = gcd(S[1], S[i]);       if (S[1] / g <= n) {         G[S[1] / g].push_back(i);       }     }     for (i = n; i >= 1; i--) {       if (S[1] % i == 0) Go(i);     }     printf( %d n , Res[1]);   }


#include <bits/stdc++.h>   using namespace std;   string s, dum;   int idx = 0;   int A[5000];   stack<int> S;   int main() {     while (cin >> dum) {       s += dum;     }     for (int i = 0; i < s.length(); i++) {       dum =   ;       while (s[i] !=  > ) {         dum += s[i];         i++;       }       dum +=  > ;       if (dum ==  <table> ) {         S.push(idx);         idx++;       } else if (dum ==  </table> ) {         S.pop();       } else if (dum ==  <td> ) {         A[S.top()]++;       }     }     sort(A, A + idx);     for (int i = 0; i < idx; i++) {       if (i > 0) printf(   );       printf( %d , A[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793;   const long long MOD = 1000000007;   const long double EPS = 1e-9;   const long long MAX = LLONG_MAX;   const long long MIN = LLONG_MIN;   const int N = 2e5 + 7;   long long power(long long base, unsigned long long exp, const long long MOD) {     long long res = 1;     base %= MOD;     while (exp) {       if (exp & 1) {         res = (res * base) % MOD;       }       exp >>= 1;       base = (base * base) % MOD;     }     return res;   }   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool palin(const string& s) {     long long i = 0, j = s.length() - 1;     while (i <= j) {       if (s[i] != s[j]) return false;       ++i;       --j;     }     return true;   }   long long modinv(long long a, const long long MOD) {     if (MOD == 1) {       return 0;     }     long long x = 1, y = 0, m = MOD;     while (a > 1) {       long long q = a / m, t = m;       m = a % m;       a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) {       x += MOD;     }     return x;   }   template <typename T>   void input(vector<T>& v) {     for (int i = 0; i < v.size(); ++i) {       cin >> v[i];     }   }   template <typename T>   void printarr(vector<T>& v) {     for (int x : v) {       cout << x <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, x, ans = 0, next = 1;     bool queue = false;     string s;     stack<int> st;     cin >> n;     for (int i = 0; i < 2 * n; ++i) {       cin >> s;       if (s ==  add ) {         cin >> x;         st.push(x);       } else {         if (!st.empty()) {           if (st.top() == next) {             st.pop();           } else {             ++ans;             st = stack<int>();           }         }         ++next;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum[101000 << 2], lsum[101000 << 2], rsum[101000 << 2], lazy[101000 << 2];   int L[105];   int ans[105];   int max(int a, int b) { return a > b ? a : b; }   void pushup(int rt, int len) {     sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]);     sum[rt] = max(sum[rt], rsum[rt << 1] + lsum[rt << 1 | 1]);     lsum[rt] = lsum[rt << 1];     if (lsum[rt] == len - (len >> 1)) lsum[rt] += lsum[rt << 1 | 1];     rsum[rt] = rsum[rt << 1 | 1];     if (rsum[rt] == (len >> 1)) rsum[rt] += rsum[rt << 1];   }   void pushdown(int rt, int len) {     lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];     if (lazy[rt] == 0) {       sum[rt << 1] = sum[rt << 1 | 1] = 0;       lsum[rt << 1] = lsum[rt << 1 | 1] = 0;       rsum[rt << 1] = rsum[rt << 1 | 1] = 0;     } else {       sum[rt << 1] = lsum[rt << 1] = rsum[rt << 1] = len - (len >> 1);       sum[rt << 1 | 1] = lsum[rt << 1 | 1] = rsum[rt << 1 | 1] = len >> 1;     }     lazy[rt] = -1;   }   void update(int l, int r, int rt, int L, int R, int val) {     if (l >= L && r <= R) {       sum[rt] = val * (r - l + 1);       lsum[rt] = val * (r - l + 1);       rsum[rt] = val * (r - l + 1);       lazy[rt] = val;       return;     }     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (L <= m) update(l, m, rt << 1, L, R, val);     if (R > m) update(m + 1, r, rt << 1 | 1, L, R, val);     pushup(rt, r - l + 1);   }   int query(int l, int r, int rt, int L) {     if (sum[rt] < L) return -1;     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (sum[rt << 1] >= L) {       return query(l, m, rt << 1, L);     } else if (rsum[rt << 1] + lsum[rt << 1 | 1] >= L) {       return m - rsum[rt << 1] + 1;     }     return query(m + 1, r, rt << 1 | 1, L);   }   void print(int l, int r, int rt) {     printf(           l = %d r = %d sum[rt] = %d , lsum[rt] = %d , rsum[rt] = %d lazy[rt] =            %d  n ,         l, r, sum[rt], lsum[rt], rsum[rt], lazy[rt]);     if (l == r) return;     int m = (l + r) >> 1;     print(l, m, rt << 1);     print(m + 1, r, rt << 1 | 1);   }   int main() {     int n, b, f;     while (scanf( %d%d%d , &n, &b, &f) != EOF) {       memset(lazy, -1, sizeof(lazy));       n += b + f;       update(1, n, 1, 1, n, 1);       int k, i;       scanf( %d , &k);       for (i = 1; i <= k; i++) {         int t;         scanf( %d%d , &t, &L[i]);         if (t == 1) {           int pos = query(1, n, 1, L[i] + b + f);           if (pos == -1) {             printf( -1 n );             ans[i] = -1;           } else {             printf( %d n , pos - 1);             update(1, n, 1, pos + b, pos + b + L[i] - 1, 0);             ans[i] = pos + b;           }         } else {           if (ans[L[i]] == -1) continue;           update(1, n, 1, ans[L[i]], ans[L[i]] + L[L[i]] - 1, 1);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   const int mod = 998244353;   int n;   int p[N];   namespace fft {   struct num {     double x, y;     num() { x = y = 0; }     num(double x, double y) : x(x), y(y) {}   };   inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }   inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }   inline num operator*(num a, num b) {     return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   inline num conj(num a) { return num(a.x, -a.y); }   int base = 1;   vector<num> roots = {{0, 0}, {1, 0}};   vector<int> rev = {0, 1};   const double PI = acosl(-1.0);   void ensure_base(int nbase) {     if (nbase <= base) return;     rev.resize(1 << nbase);     for (int i = 0; i < (1 << nbase); i++)       rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));     roots.resize(1 << nbase);     while (base < nbase) {       double angle = 2 * PI / (1 << (base + 1));       for (int i = 1 << (base - 1); i < (1 << base); i++) {         roots[i << 1] = roots[i];         double angle_i = angle * (2 * i + 1 - (1 << base));         roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));       }       base++;     }   }   void fft(vector<num> &a, int n = -1) {     if (n == -1) n = a.size();     assert((n & (n - 1)) == 0);     int zeros = __builtin_ctz(n);     ensure_base(zeros);     int shift = base - zeros;     for (int i = 0; i < n; i++)       if (i < (rev[i] >> shift)) swap(a[i], a[rev[i] >> shift]);     for (int k = 1; k < n; k <<= 1) {       for (int i = 0; i < n; i += 2 * k) {         for (int j = 0; j < k; j++) {           num z = a[i + j + k] * roots[j + k];           a[i + j + k] = a[i + j] - z;           a[i + j] = a[i + j] + z;         }       }     }   }   vector<num> fa, fb;   vector<int> multiply_mod(vector<int> &a, vector<int> &b, int m, int eq = 0) {     int need = a.size() + b.size() - 1;     int nbase = 0;     while ((1 << nbase) < need) nbase++;     ensure_base(nbase);     int sz = 1 << nbase;     if (sz > (int)fa.size()) fa.resize(sz);     for (int i = 0; i < (int)a.size(); i++) {       int x = (a[i] % m + m) % m;       fa[i] = num(x & ((1 << 15) - 1), x >> 15);     }     fill(fa.begin() + a.size(), fa.begin() + sz, num{0, 0});     fft(fa, sz);     if (sz > (int)fb.size()) fb.resize(sz);     if (eq)       copy(fa.begin(), fa.begin() + sz, fb.begin());     else {       for (int i = 0; i < (int)b.size(); i++) {         int x = (b[i] % m + m) % m;         fb[i] = num(x & ((1 << 15) - 1), x >> 15);       }       fill(fb.begin() + b.size(), fb.begin() + sz, num{0, 0});       fft(fb, sz);     }     double ratio = 0.25 / sz;     num r2(0, -1), r3(ratio, 0), r4(0, -ratio), r5(0, 1);     for (int i = 0; i <= (sz >> 1); i++) {       int j = (sz - i) & (sz - 1);       num a1 = (fa[i] + conj(fa[j]));       num a2 = (fa[i] - conj(fa[j])) * r2;       num b1 = (fb[i] + conj(fb[j])) * r3;       num b2 = (fb[i] - conj(fb[j])) * r4;       if (i != j) {         num c1 = (fa[j] + conj(fa[i]));         num c2 = (fa[j] - conj(fa[i])) * r2;         num d1 = (fb[j] + conj(fb[i])) * r3;         num d2 = (fb[j] - conj(fb[i])) * r4;         fa[i] = c1 * d1 + c2 * d2 * r5;         fb[i] = c1 * d2 + c2 * d1;       }       fa[j] = a1 * b1 + a2 * b2 * r5;       fb[j] = a1 * b2 + a2 * b1;     }     fft(fa, sz);     fft(fb, sz);     vector<int> res(need);     for (int i = 0; i < need; i++) {       long long aa = fa[i].x + 0.5;       long long bb = fb[i].x + 0.5;       long long cc = fa[i].y + 0.5;       res[i] = (aa + ((bb % m) << 15) + ((cc % m) << 30)) % m;     }     return res;   }   };  // namespace fft   struct pol {     vector<int> a;     pol() {}     pol(const pol &oth) { a = oth.a; }     bool operator<(const pol &oth) const { return a.size() <= oth.a.size(); }   };   set<pol> st;   int main() {     cin >> n;     map<int, int> rep;     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       rep[p[i]]++;     }     for (map<int, int>::iterator it = rep.begin(); it != rep.end(); it++) {       int sz = it->second;       pol temp;       for (int i = 0; i <= sz; i++) {         temp.a.push_back(1);       }       st.insert(temp);     }     while (st.size() > 1) {       pol x = *st.begin();       st.erase(st.begin());       pol y = *st.begin();       st.erase(st.begin());       x.a = fft::multiply_mod(x.a, y.a, mod);       st.insert(x);     }     long long res = 0;     pol x = *st.begin();     if (x.a.size() > n / 2) res = x.a[n / 2];     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, N;   int P;   vector<int> v, A, B;   long long pw(long long a, int n) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a % 1000000007;       a = a * a % 1000000007;       n >>= 1;     }     return ret;   }   int main() {     scanf( %d , &T);     while (T--) {       v.clear();       A.clear();       B.clear();       scanf( %d %d , &N, &P);       v.resize(N);       for (int i = 0; i < N; i++) scanf( %d , &v[i]);       if (P == 1) {         if (v.size() % 2)           printf( 1 n );         else           printf( 0 n );         continue;       }       sort(v.rbegin(), v.rend());       int i = 0;       while (i < N) {         A.push_back(v[i]);         long long need = 1;         int prv = v[i];         i++;         while (i < N) {           B.push_back(v[i]);           int now = v[i];           i++;           if (prv - now >= 20) break;           while (prv > now) {             need *= P;             prv--;             if (need > N) break;           }           if (need > N) break;           need--;           if (need == 0) break;         }         if (need) {           while (i < N) {             B.push_back(v[i]);             i++;           }         }       }       long long res = 0;       for (int k : A) {         res += pw(P, k);         res %= 1000000007;       }       for (int k : B) {         res -= pw(P, k);         res %= 1000000007;       }       res += 1000000007;       res %= 1000000007;       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sieve(vector<bool> &arr, vector<int> &ans) {     int res = INT_MAX;     for (int i = 2; i <= sqrt(arr.size()); i++) {       if (arr[i]) {         for (int j = i * i; j < arr.size(); j += i) {           arr[j] = false;           if (ans[j] == ans[i]) ans[j]++;           res = min(res, ans[j]);         }       }     }     return arr.size() > 4 ? res : 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<bool> arr(n + 2, true);     vector<int> ans(n + 2, 1);     int res = sieve(arr, ans);     cout << res << endl;     for (int i = 2; i < arr.size(); i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   long long MOD = 1000000007;   long long C[2000 + 200][2000 + 200];   int pos = 0;   bool notfree[2000 + 200];   int n;   void combin() {     C[0][0] = 1;     for (int i = 1; i <= 2000; i++) {       C[0][i] = 1;       C[i][i] = 1;       for (int j = 1; j < i; j++) C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % MOD;     }   }   long long f[2000 + 200];   int cpos = 0;   void init() {     f[0] = 1;     for (int i = 1; i <= 2000; i++) f[i] = (f[i - 1] * i) % MOD;   }   int a[2000 + 200];   void fix(long long &n) {     if (n < 0) n += MOD;   }   void solve() {     for (int i = 1; i <= n; i++)       if (a[i] != -1) notfree[a[i]] = true;     for (int i = 1; i <= n; i++)       if (a[i] == -1) pos++;     for (int i = 1; i <= n; i++)       if (a[i] == -1 && !notfree[i]) cpos++;     init();     long long res = 0;     for (int i = 1; i <= cpos; i++) {       if (i % 2)         res = (res + C[i][cpos] * f[pos - i]) % MOD;       else {         res = (res - C[i][cpos] * f[pos - i]) % MOD;         fix(res);       }     }     res = (f[pos] - res) % MOD;     fix(res);     printf( %I64d , res);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     combin();     solve();   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = 1 << 29;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return n & two(b); }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   template <class T>   void chmax(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void chmin(T& a, const T& b) {     a = min(a, b);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long nsn(long long a, long long b) { return a / gcd(a, b) * b; }   int main() {     long long a, b;     cin >> a >> b;     long long N = nsn(a, b);     long long sum1 = N / a - 1, sum2 = N / b - 1;     if (a < b)       sum2++;     else       sum1++;     if (sum1 > sum2)       cout <<  Dasha  << endl;     else if (sum1 < sum2)       cout <<  Masha  << endl;     else       cout <<  Equal  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], b[100010], c[100010];   int main(int argc, char* argv[]) {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = 0; i < n - 1; i++) scanf( %d , &b[i]);     sort(b, b + n - 1);     for (int i = 0; i < n - 2; i++) scanf( %d , &c[i]);     sort(c, c + n - 2);     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         printf( %d n , a[i]);         break;       }     }     for (int i = 0; i < n - 1; i++) {       if (b[i] != c[i]) {         printf( %d n , b[i]);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[500001];   map<int, int> cnt, pos;   vector<int> ans;   struct mypair {     int left;     int right;     int value;   };   mypair Mypair[500001];   int pointer = 0;   void writeans(int a, int b) {     ans.push_back(a);     ans.push_back(b);     ans.push_back(a);     ans.push_back(b);     cnt.clear();     pos.clear();     pointer = 0;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       if (cnt.find(a[i]) != cnt.end()) {         cnt[a[i]]++;       } else         cnt[a[i]] = 1;       if (cnt[a[i]] == 4) {         writeans(a[i], a[i]);         continue;       }       if (pos.find(a[i]) == pos.end()) {         pos[a[i]] = i;         continue;       }       int left = pos[a[i]];       pos[a[i]] = i;       while (pointer > 0) {         int lastl = Mypair[pointer - 1].left;         int lastr = Mypair[pointer - 1].right;         if (lastl < left && left < lastr) {           writeans(Mypair[pointer - 1].value, a[i]);           break;         } else if (lastl >= left) {           pointer--;         } else {           Mypair[pointer].left = left;           Mypair[pointer].right = i;           Mypair[pointer].value = a[i];           pointer++;           break;         }       }       if (pointer == 0) {         Mypair[pointer].left = left;         Mypair[pointer].right = i;         Mypair[pointer].value = a[i];         pointer++;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> pos[8];   vector<int> construct_vector(int a, int b, int c) {     vector<int> ret;     ret.push_back(a);     ret.push_back(b);     ret.push_back(c);     return ret;   }   long long dist(vector<int> p1, vector<int> p2) {     return (long long)(p1[0] - p2[0]) * (p1[0] - p2[0]) +            (long long)(p1[1] - p2[1]) * (p1[1] - p2[1]) +            (long long)(p1[2] - p2[2]) * (p1[2] - p2[2]);   }   map<long long, int> mpdist;   bool dfs(int k) {     if (k == 8) return true;     sort(pos[k].begin(), pos[k].end());     do {       bool f = true;       for (int i = 0; f && i < k; ++i)         if (pos[k] == pos[i]) f = false;       if (!f) continue;       for (int i = 0; i < k; ++i) ++mpdist[dist(pos[i], pos[k])];       if (mpdist.size() <= 3u && dfs(k + 1)) return true;       for (int i = 0; i < k; ++i) {         long long dis = dist(pos[i], pos[k]);         --mpdist[dis];         if (!mpdist[dis]) mpdist.erase(dis);       }     } while (next_permutation(pos[k].begin(), pos[k].end()));     return false;   }   int main() {     for (int i = 0; i < 8; ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       pos[i] = construct_vector(a, b, c);     }     if (dfs(0)) {       printf( YES n );       for (int i = 0; i < 8; ++i)         printf( %d %d %d n , pos[i][0], pos[i][1], pos[i][2]);     } else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int max_n = (1 << 21) + 100;   vector<int> ans;   int a[max_n];   void de(int i) {     int l = i << 1;     int r = (i << 1) | 1;     if (a[l] == 0 && a[r] == 0) {       a[i] = 0;       return;     } else {       if (a[l] > a[r]) {         a[i] = a[l];         de(l);       } else {         a[i] = a[r];         de(r);       }     }     return;   }   int n, m;   long long sum;   int find(int i, int dep) {     int l = i << 1;     int r = (i << 1) | 1;     if (a[l] > a[r]) {       return find(l, dep + 1);     } else if (a[r] > a[l]) {       return find(r, dep + 1);     } else {       return dep;     }   }   void dfs(int x, int dep) {     if (a[x] == 0) {       return;     }     while (find(x, dep) > m) {       ans.push_back(x);       sum -= a[x];       de(x);     }     dfs(x << 1, dep + 1);     dfs((x << 1) | 1, dep + 1);   }   int main() {     int t;     int h, g;     scanf( %d , &t);     while (t--) {       sum = 0;       scanf( %d%d , &h, &m);       n = (1 << h) - 1;       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         sum += a[i];       }       for (int i = n + 1; i <= (1 << (h + 1)) - 1; ++i) {         a[i] = 0;       }       dfs(1, 1);       printf( %lld n , sum);       for (int i = 0; i < ans.size(); ++i) {         printf( %d  , ans[i]);       }       printf(  n );       ans.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 998244353, maxn = 1000011;   int Fact[maxn], nFact[maxn];   char s[maxn];   inline int C(int n, int m) {     if (n < m || m < 0) return 0;     return 1LL * Fact[n] * nFact[m] % p * nFact[n - m] % p;   }   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     Fact[0] = 1;     for (int i = 1; i <= n; ++i) Fact[i] = 1LL * Fact[i - 1] * i % p;     nFact[0] = nFact[1] = 1;     for (int i = 2; i <= n; ++i) nFact[i] = 1LL * (p - p / i) * nFact[p % i] % p;     for (int i = 1; i <= n; ++i) nFact[i] = 1LL * nFact[i] * nFact[i - 1] % p;     static int sl[maxn], sq[maxn];     sl[0] = 0;     sq[0] = 0;     for (int i = 1; i <= n; ++i)       sl[i] = sl[i - 1] + (s[i] ==  ( ), sq[i] = sq[i - 1] + (s[i] ==  ? );     int ans = 0;     for (int qtol = 0; qtol <= sq[n]; ++qtol) {       int qtor = sq[n] - qtol;       int SR = (n - sl[n] - sq[n]) + qtor;       ans = (ans + 1LL * sl[SR] * C(sq[n], qtol)) % p;       ans = (ans + 1LL * sq[SR] * C(sq[n] - 1, qtol - 1)) % p;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long K, statc;   int qc;   bool query(long long l, long long r) {     qc++;     assert(qc <= 4499);     cout << l <<     << r <<   n ;     fflush(stdout);     string ans;     cin >> ans;     if (l == r && ans[0] ==  Y ) {       exit(0);     }     if (ans[0] ==  B ) {       exit(0);     }     return ans[0] ==  Y ;   }   long long randrange(long long l, long long r) {     long long mod = r - l + 1;     return l + rand() % mod;   }   long long extl(long long x) { return max(1LL, x - K); }   long long extr(long long x) { return min(statc, x + K); }   int main() {     srand(time(NULL));     ios::sync_with_stdio(false);     cin >> statc >> K;     long long l = 1, r = statc;     while (true) {       long long w = r - l + 1;       if (w <= 7 * K) {         long long guess = randrange(l, r);         query(guess, guess);       } else {         long long mid = (l + r) / 2;         if (query(l, mid)) {           r = mid;         } else {           l = mid + 1;         }       }       l = extl(l);       r = extr(r);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int mod = 20010905;   const int inf = 0x3f3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   long long lowbit(long long x) { return x & (-x); }   long long qpow(long long a, long long b, long long c) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res % c;   }   long long qmul(long long a, long long b, long long c) {     long long res = 0;     while (b) {       if (b & 1) res = (res + a) % c;       a = (a + a) % c;       b >>= 1;     }     return res % c;   }   struct Bit {     long long Bit[maxn], N;     void addBit(long long x, long long v) {       x = N - x + 1;       while (x <= N) Bit[x] = max(Bit[x], v), x += lowbit(x);     }     long long qBit(long long x) {       x = N - x + 1;       long long res = -linf;       while (x) res = max(res, Bit[x]), x -= lowbit(x);       return res;     }   };   char s[maxn];   vector<int> e[maxn];   int pre[maxn], sz[maxn];   int fin(int x) { return pre[x] == x ? x : pre[x] = fin(pre[x]); }   int n, k;   void add(int x, int y) {     x = fin(x), y = fin(y);     if (x == y) return;     pre[x] = y;     sz[y] += sz[x];   }   int calc(int x) {     int y = fin(x + k);     x = fin(x);     return min(sz[x], sz[y]);   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int i = 1; i <= k; i++) {       int kk, x;       scanf( %d , &kk);       while (kk--) {         scanf( %d , &x);         e[x].push_back(i);       }     }     sz[0] = inf;     for (int i = 1; i <= 2 * k; i++) pre[i] = i, sz[i] = (i <= k);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (e[i].size()) {         if (s[i] ==  1 ) {           if (e[i].size() == 1) {             ans -= calc(e[i][0]);             add(e[i][0], 0);             ans += calc(e[i][0]);           } else {             int x = e[i][0], y = e[i][1];             if (fin(x) != fin(y)) {               ans -= calc(x) + calc(y);               add(x, y), add(x + k, y + k);               ans += calc(x);             }           }         } else {           if (e[i].size() == 1) {             ans -= calc(e[i][0]);             add(e[i][0] + k, 0);             ans += calc(e[i][0]);           } else {             int x = e[i][0], y = e[i][1];             if (fin(x) != fin(y + k)) {               ans -= calc(x) + calc(y);               add(x, y + k), add(x + k, y);               ans += calc(x);             }           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 239;   int n;   vector<vector<int>> g;   vector<vector<pair<int, int>>> g2;   namespace Lca {   const int LIM = 20;   int timer = 0;   vector<int> tin;   vector<int> tout;   vector<int> p;   vector<int> c;   vector<int> h;   vector<vector<int>> uc;   vector<vector<int>> up;   void dfs(int cur, int pr, int cs, int ch) {     c[cur] = cs;     p[cur] = pr;     h[cur] = ch;     tin[cur] = timer;     timer++;     for (auto [t, w] : g2[cur]) {       if (t != pr) {         dfs(t, cur, w, ch + 1);       }     }     tout[cur] = timer;     timer++;   }   bool parent(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   void calc_up() {     up.resize(LIM, vector<int>(n));     uc.resize(LIM, vector<int>(n));     for (int i = 0; i < n; i++) {       up[0][i] = p[i];       uc[0][i] = c[i];     }     for (int i = 0; i + 1 < LIM; i++) {       for (int j = 0; j < n; j++) {         int mid = up[i][j];         if (mid != -1) {           up[i + 1][j] = up[i][mid];           uc[i + 1][j] = max(uc[i][mid], uc[i][j]);         }       }     }   }   int get(int a, int b) {     if (parent(a, b)) {       return a;     } else if (parent(b, a)) {       return b;     } else {       int cur = a;       for (int i = LIM - 1; i >= 0; i--) {         if (up[i][cur] != -1 && !parent(up[i][cur], b)) {           cur = up[i][cur];         }       }       return p[cur];     }   }   int get_up(int a, int h) {     int ans = -INF;     for (int i = 0; i < LIM; i++) {       if ((h >> i) & 1) {         ans = max(ans, uc[i][a]);         a = up[i][a];       }     }     return ans;   }   int get_cost(int a, int b) {     auto l = get(a, b);     return max(get_up(a, h[a] - h[l]), get_up(b, h[b] - h[l]));   }   void init() {     tin.resize(n);     tout.resize(n);     p.resize(n, -1);     c.resize(n, -1);     h.resize(n, -1);     dfs(0, -1, 0, 0);     calc_up();   }   }  // namespace Lca   namespace Dsu {   vector<int> p;   vector<int> rank;   int get(int v) {     if (p[v] != v) {       p[v] = get(p[v]);     }     return p[v];   }   void merge(int a, int b) {     a = get(a);     b = get(b);     if (a != b) {       if (rank[a] < rank[b]) {         swap(a, b);       }       p[b] = a;       if (rank[a] == rank[b]) {         rank[a]++;       }     }   }   void init() {     p.resize(n);     for (int i = 0; i < n; i++) {       p[i] = i;     }     rank.resize(n);   }   }  // namespace Dsu   struct SegmentTree {     vector<int> a;     vector<vector<int>> st;     vector<vector<int>> en;     void modify(int l, int r, int val) {       st[l].push_back(val);       en[r].push_back(val);     }     void solve() {       multiset<int> cur;       cur.insert(INF);       for (int i = 0; i < (int)a.size(); i++) {         for (auto t : st[i]) {           cur.insert(t);         }         for (auto t : en[i]) {           cur.erase(cur.find(t));         }         a[i] = *(cur.begin());       }     }     int get(int pos) { return a[pos]; }     SegmentTree(vector<int> &a_) {       a = a_;       for (auto &t : a) {         t = INF;       }       st.resize(a.size());       en.resize(a.size() + 1);     }   };   namespace Hld {   vector<int> p;   vector<int> h;   vector<int> sz;   vector<int> where;   vector<int> pos_in_list;   vector<vector<int>> lists;   vector<SegmentTree> lists_st;   int cur_cnt = 1;   void dfs(int cur, int pr, int ch) {     sz[cur] = 1;     h[cur] = ch;     for (auto t : g[cur]) {       if (t != pr) {         dfs(t, cur, ch + 1);         sz[cur] += sz[t];       }     }   }   void build(int v, int wh, int pr) {     p[v] = pr;     where[v] = wh;     pos_in_list[v] = (int)lists[wh].size();     lists[wh].push_back(v);     int mx = -1;     for (auto t : g[v]) {       if (t == pr) {         continue;       }       if (2 * sz[t] > sz[v]) {         assert(mx == -1);         mx = t;       }     }     if (mx != -1) {       build(mx, wh, v);     }     for (auto t : g[v]) {       if (t == pr || t == mx) {         continue;       }       {         lists.push_back(vector<int>());         build(t, cur_cnt, v);         cur_cnt++;       }     }   }   void init_st() {     for (auto t : lists) {       lists_st.push_back(SegmentTree(t));     }   }   void mod_up(int v, int to, int val) {     while (to > 0) {       int i = where[v];       int j = pos_in_list[v];       int can = min(to, j + 1);       int l = (j + 1) - can;       int r = j + 1;       lists_st[i].modify(l, r, val);       to -= can;       v = p[lists[i].front()];     }   }   void mod(int u, int v, int val) {     int l = Lca::get(u, v);     mod_up(u, h[u] - h[l], val);     mod_up(v, h[v] - h[l], val);   }   void solve() {     for (int i = 0; i < (int)lists_st.size(); i++) {       lists_st[i].solve();     }   }   void init() {     p.resize(n);     h.resize(n);     sz.resize(n);     where.resize(n);     pos_in_list.resize(n);     lists.push_back(vector<int>());     dfs(0, -1, 0);     build(0, 0, -1);     init_st();   }   int get(int v) {     int i = where[v];     int j = pos_in_list[v];     return lists_st[i].get(j);   }   };  // namespace Hld   struct Edge {     int u, v, c;     Edge() {}   };   vector<int> in;   vector<Edge> ed;   void Kr() {     auto cmp = [&](int a, int b) { return ed[a].c < ed[b].c; };     vector<int> ind((int)ed.size());     for (int i = 0; i < (int)ed.size(); i++) {       ind[i] = i;     }     sort(ind.begin(), ind.end(), cmp);     Dsu::init();     for (int i = 0; i < (int)ed.size(); i++) {       Edge t = ed[ind[i]];       int f = Dsu::get(t.u);       int s = Dsu::get(t.v);       if (f != s) {         in[ind[i]] = 1;         g[t.u].push_back(t.v);         g[t.v].push_back(t.u);         g2[t.u].push_back({t.v, t.c});         g2[t.v].push_back({t.u, t.c});         Dsu::merge(f, s);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int m;     cin >> n >> m;     g.resize(n);     g2.resize(n);     in.resize(m);     ed.resize(m);     for (auto &t : ed) {       cin >> t.u >> t.v >> t.c;       t.u--;       t.v--;     }     Kr();     cerr <<  Kr ok  << endl;     Lca::init();     cerr <<  Lca ok  << endl;     Hld::init();     cerr <<  Hld ok  << endl;     for (auto &t : ed) {       if (Hld::h[t.u] > Hld::h[t.v]) {         swap(t.u, t.v);       }     }     vector<int> ans(m, -1);     for (int i = 0; i < m; i++) {       if (!in[i]) {         ans[i] = Lca::get_cost(ed[i].u, ed[i].v) - 1;       }     }     cerr <<  st md  << endl;     for (int i = 0; i < m; i++) {       if (!in[i]) {         Hld::mod(ed[i].u, ed[i].v, ed[i].c);       }     }     cerr <<  slv   << endl;     Hld::solve();     cerr <<  st qr  << endl;     for (int i = 0; i < m; i++) {       if (in[i]) {         ans[i] = Hld::get(ed[i].v) - 1;         if (ans[i] == INF - 1) {           ans[i] = -1;         }       }     }     for (auto t : ans) {       cout << t <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 1;   long long arr[N];   long long n, k;   long long sum;   long long mnm = -1;   long long mxm = -1;   void input() {     cin >> n >> k;     for (long long i = 0; i < n; ++i) {       cin >> arr[i];       sum += arr[i];     }     sort(arr, arr + n);   }   void solve() {     long long K = k;     for (long long i = 0; i < n;) {       long long j = i;       for (; j < n && arr[i] == arr[j]; ++j)         ;       long long dif = arr[j] - arr[i];       long long cnt = j;       if (K >= dif * cnt) {         K -= dif * cnt;       } else {         mnm = arr[i] + K / j;         break;       }       i = j;     }     K = k;     for (long long i = n - 1; i >= 0;) {       long long j = i;       for (; j >= 0 && arr[i] == arr[j]; --j)         ;       long long dif = arr[i] - arr[j];       long long cnt = n - 1 - j;       if (K >= dif * cnt) {         K -= dif * cnt;       } else {         mxm = arr[i] - K / cnt;         break;       }       i = j;     }     if (mnm == -1) mnm = arr[n - 1];     if (mxm == -1) mxm = arr[0];     if (mnm >= mxm) {       if (sum % n) {         cout <<  1 n ;       } else {         cout <<  0 n ;       }     } else {       cout << mxm - mnm <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     input();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, val[300005];   struct node {     multiset<int> val;     int p, v;     node *chd[26], *fail;     node() {       memset(chd, 0ll, sizeof(chd));       fail = 0ll;       p = v = 0;       val.clear();     }   };   node *root;   node *place[300005];   void resetAC() { root = new node(); }   char s[300005];   void insert() {     node *now = root;     int l = 0, len = strlen(s);     while (l < len) {       if (now->chd[s[l] -  a ] == NULL) now->chd[s[l] -  a ] = new node();       now = now->chd[s[l] -  a ];       l++;     }     now->p++;     place[i] = now;     now->val.insert(0);   }   queue<node *> qAC;   void buildAC() {     node *now, *q;     int i;     for (i = 0; i < 26; i++)       if (root->chd[i] != NULL) root->chd[i]->fail = root, qAC.push(root->chd[i]);     while (!qAC.empty()) {       now = qAC.front();       qAC.pop();       for (i = 0; i < 26; i++)         if (now->chd[i] != NULL) {           q = now->fail;           while (q != NULL && q->chd[i] == NULL) q = q->fail;           if (q == NULL)             now->chd[i]->fail = root;           else             now->chd[i]->fail = q->chd[i];           qAC.push(now->chd[i]);         }     }   }   int AC() {     node *now = root, *p;     int ans = -1, len = strlen(s);     for (int l = 0; l < len; l++) {       while (now != root && now->chd[s[l] -  a ] == NULL) now = now->fail;       now = (now->chd[s[l] -  a ] == NULL ? root : now->chd[s[l] -  a ]);       p = now;       while (p != NULL && p->v != i) {         if (!p->val.empty()) {           auto x = p->val.end();           --x;           ans = max(ans, *x);         }         p->v = i;         p = p->fail;       }     }     return ans;   }   char c;   int flag;   void read(int &x) {     x = 0;     c = getchar();     flag = 1;     while (c <  0  || c >  9 ) flag = (c ==  -  ? -1 : flag), c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     x *= flag;   }   int opt;   int main() {     resetAC();     read(n);     read(m);     for (i = 1; i <= n; i++) {       scanf( %s , s);       insert();     }     buildAC();     for (i = 1; i <= m; i++) {       read(opt);       if (opt == 1) {         int x, vl;         read(x);         read(vl);         place[x]->val.erase(place[x]->val.find(val[x]));         val[x] = vl;         place[x]->val.insert(val[x]);       }       if (opt == 2) {         scanf( %s , s);         cout << AC() << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int INF = 2000;   int gauss(vector<vector<double> > a, vector<double> &ans) {     int n = (int)a.size();     int m = (int)a[0].size() - 1;     vector<int> where(m, -1);     for (int col = 0, row = 0; col < m && row < n; ++col) {       int sel = row;       for (int i = row; i < n; ++i)         if (abs(a[i][col]) > abs(a[sel][col])) sel = i;       if (abs(a[sel][col]) < EPS) continue;       for (int i = col; i <= m; ++i) swap(a[sel][i], a[row][i]);       where[col] = row;       for (int i = 0; i < n; ++i)         if (i != row) {           double c = a[i][col] / a[row][col];           for (int j = col; j <= m; ++j) a[i][j] -= a[row][j] * c;         }       ++row;     }     ans.assign(m, 0);     for (int i = 0; i < m; ++i)       if (where[i] != -1) ans[i] = a[where[i]][m] / a[where[i]][i];     for (int i = 0; i < n; ++i) {       double sum = 0;       for (int j = 0; j < m; ++j) sum += ans[j] * a[i][j];       if (abs(sum - a[i][m]) > EPS) return 0;     }     for (int i = 0; i < m; ++i)       if (where[i] == -1) return INF;     return 1;   }   double dp[123][2];   int vis[123][2];   int id[12][12];   int to[123];   double f(int n, int t) {     if (vis[n][t]) return dp[n][t];     vis[n][t] = 1;     dp[n][t] = 1e9;     double s = 0;     for (int i = 1; i <= 6; i++) {       s += f(n + i, 0);     }     s += 6;     s /= 6;     if (t == 1) {       dp[n][t] = s;     } else {       dp[n][t] = min(to[n] == n ? 1000000000. : f(to[n], 1), s);     }     return dp[n][t];   }   int main(int argc, char const *argv[]) {     cout << fixed << setprecision(8);     {       int cnt = 0;       for (int i = 0; i < 10; i += 2) {         for (int j = 0; j < 10; j++) {           id[i][j] = cnt++;         }         for (int j = 9; j >= 0; j--) {           id[i + 1][j] = cnt++;         }       }     }     for (int i = 9; i >= 0; i--) {       for (int j = 0; j < 10; j++) {         int x;         cin >> x;         to[id[i][j]] = id[i + x][j];       }     }     dp[99][0] = 0;     dp[98][0] = dp[97][0] = dp[96][0] = dp[95][0] = dp[94][0] = 6;     for (int i = 0; i < 6; i++) {       dp[99 - i][1] = dp[99 - i][0];       vis[99 - i][0] = vis[99 - i][1] = 1;     }     cout << f(0, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool pr(int n) {     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       char a[51][51];       bool f = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cin >> a[i][j];         }       }       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < n - 1; j++) {           if ((a[i][j] ==  1  && (a[i + 1][j] ==  0  && a[i][j + 1] ==  0 ))) {             f = true;             break;           }         }         if (f == true) {           cout <<  NO  << endl;           break;         }       }       if (f == false) cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[200000], *s;     cin >> a;     if ((s = strstr(a,  AB )) && (strstr(s + 2,  BA )))       puts( YES );     else if ((s = strstr(a,  BA )) && strstr(s + 2,  AB ))       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int shi(int a[], int k, int len) {     int s = 0, j;     for (j = len - 1; j >= 0; j--) {       s = s * k + a[j];     }     return s;   }   int bian(int n, int k) {     int i;     for (i = 0; n > 0; i++) {       n /= k;     }     return i;   }   int change(int a[1000], int n) {     int i;     for (i = 0; n > 0; i++) {       a[i] = n % 10;       n /= 10;     }     return i;   }   int main() {     int a, b;     int ta[1000], tb[1000];     int i, la, lb;     while (scanf( %d%d , &a, &b) != -1) {       int max = 0;       la = change(ta, a);       lb = change(tb, b);       for (i = 0; i < la; i++) {         if (ta[i] > max) max = ta[i];       }       for (i = 0; i < lb; i++) {         if (tb[i] > max) max = tb[i];       }       max += 1;       int sa = shi(ta, max, la), sb = shi(tb, max, lb);       int sum = sa + sb;       int ss = bian(sum, max);       printf( %d n , ss);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, i;     cin >> n;     long long cnt = 0;     while (n >= 10) {       n++;       while (n % 10 == 0) {         n = n / 10;       }       cnt++;     }     cout << cnt + 9 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int MX = 1e9 + 7;   const long long int INF = 1e18 + 9LL;   int n, k, r;   bool spec[N];   vector<int> G[N];   int id[N];   queue<int> Q;   int rep[N];   int tr[N], add[N];   set<pair<int, int> > S[N];   int lvl[N];   int jump[18][N];   int pre[N], post[N];   int q;   int ans[N];   vector<pair<int, int> > req[N];   int sz[N];   bool block[N];   int dists[N];   vector<int> colors;   void dfs(int u, int p) {     static int Time = 0;     pre[u] = ++Time;     jump[0][u] = p;     for (auto v : G[u])       if (v != p) {         lvl[v] = lvl[u] + 1;         dfs(v, u);       }     post[u] = Time;   }   int Find(int u) {     if (rep[u] == u) return u;     return rep[u] = Find(rep[u]);   }   void Union(int u, int v) { rep[Find(u)] = Find(v); }   int connect(int a, int b) {     add[b]++;     if (S[a].size() > S[b].size()) swap(a, b);     for (auto v : S[a]) S[b].insert({v.first + add[a] - add[b], v.second});     S[a].clear();     if (S[b].size() > 1) {       auto it = *S[b].begin();       S[b].erase(S[b].begin());       while (S[b].size() > 0 &&              (*S[b].begin()).first + it.first + 2 * add[b] <= k) {         Union((*S[b].begin()).second, it.second);         S[b].erase(S[b].begin());       }       S[b].insert(it);     }     return b;   }   void getGraph(int u, int p) {     tr[u] = u;     if (spec[u]) S[u].insert({0, u});     for (auto v : G[u])       if (v != p) {         getGraph(v, u);         tr[u] = connect(tr[u], tr[v]);       }   }   void prepare() {     for (int i = 1; i <= n; ++i)       if (spec[i]) {         id[i] = i;         Q.push(i);       } else         id[i] = -1;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (auto v : G[u])         if (id[v] == -1) {           id[v] = id[u];           Q.push(v);         }     }     dfs(1, 1);     for (int i = 1; i < 18; ++i)       for (int j = 1; j <= n; ++j) jump[i][j] = jump[i - 1][jump[i - 1][j]];     for (int i = 1; i <= n; ++i) rep[i] = i;     getGraph(1, 0);   }   bool dad(int u, int v) { return pre[u] <= pre[v] && post[v] <= post[u]; }   int lca(int u, int v) {     for (int i = 18 - 1; i >= 0; --i)       if (!dad(jump[i][u], v)) u = jump[i][u];     if (!dad(u, v)) u = jump[0][u];     return u;   }   int getHigher(int u, int d) {     for (int i = 0; i < 18; ++i)       if (d & (1 << i)) u = jump[i][u];     return u;   }   void consider(int u, int v, int t) {     int m = lca(u, v);     if (lvl[u] + lvl[v] - 2 * lvl[m] <= k) {       ans[t] = 3;       return;     }     int d = lvl[u] + lvl[v] - 2 * lvl[m];     d /= 2;     if (lvl[u] > lvl[v]) swap(u, v);     m = getHigher(v, d);     int who = Find(id[m]);     req[u].push_back({who, t});     req[v].push_back({who, -t});   }   int getSizes(int u, int p) {     sz[u] = 1;     for (auto v : G[u])       if (!block[v] && v != p) sz[u] += getSizes(v, u);     return sz[u];   }   int centroid(int u) {     int half = getSizes(u, u) / 2;     bool change = true;     while (change) {       change = false;       for (auto v : G[u])         if (!block[v] && sz[v] < sz[u] && sz[v] >= half) {           u = v;           change = true;           break;         }     }     return u;   }   void go(int u, int p, int d) {     if (spec[u]) {       int t = Find(u);       colors.push_back(t);       dists[t] = min(dists[t], d);     }     for (auto v : G[u])       if (!block[v] && v != p) go(v, u, d + 1);   }   void ask(int u, int p, int d) {     for (auto v : req[u]) {       if (d + dists[v.first] > k) continue;       if (v.second < 0)         ans[-v.second] |= 2;       else         ans[v.second] |= 1;     }     for (auto v : G[u])       if (!block[v] && v != p) ask(v, u, d + 1);   }   void Decompose(int u) {     u = centroid(u);     block[u] = true;     go(u, u, 0);     ask(u, u, 0);     for (auto c : colors) dists[c] = N;     colors.clear();     for (auto v : G[u])       if (!block[v]) Decompose(v);   }   int main() {     scanf( %d %d %d , &n, &k, &r);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d %d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= r; ++i) {       int t;       scanf( %d , &t);       spec[t] = true;     }     prepare();     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       int u, v;       scanf( %d %d , &u, &v);       consider(u, v, i);     }     for (int i = 1; i <= n; ++i) dists[i] = N;     Decompose(1);     for (int i = 1; i <= q; ++i) puts((ans[i] == 3) ?  YES  :  NO );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 10;   int A[N][N * N], B[N][N * N], C[N][N * N];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) cin >> A[i][j] >> B[i][j] >> C[i][j];     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         vector<pair<int, int> > vec(m);         for (int z = 0; z < m; z++) {           vec[z] = {B[j][z] - A[i][z], C[i][z]};         }         sort(vec.rbegin(), vec.rend());         int rem = k;         int tempAns = 0;         for (int z = 0; z < m && rem && vec[z].first > 0; z++) {           tempAns += vec[z].first * min(vec[z].second, rem);           rem -= min(rem, vec[z].second);         }         ans = max(ans, tempAns);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long PM(long long a, long long b) { return ((a % b) + b) % b; }   void solve() {     int n;     cin >> n;     string a;     cin >> a;     long long sum = 0;     long long ans = 0;     map<long long, long long> m;     m[0] = 1;     for (int i = 0; i < n; i++) {       sum += a[i] -  0 ;       ans += m[sum - i - 1];       m[sum - i - 1]++;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int tinf = (int)1e9 + 7;   const long long inf = (long long)1e18 + 7;   const int N = 1e3 + 5;   int main() {     {       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     }     long long n, k;     cin >> n >> k;     long long a[n], Min = inf, Max = -inf;     for (int i = 0; i < n; i++)       cin >> a[i], Min = min(Min, a[i]), Max = max(Max, a[i]);     if (k == 1)       cout << Min;     else if (k == 2)       cout << max(a[0], a[n - 1]);     else if (k >= 3)       cout << Max;     else       cout << Min;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1000000001, INF = (ll)1e18 + 1;   const int maxn = 1e6;   int n, m;   vector<int> a, b;   pair<ll, ll> fact[maxn];   ll power(ll a, ll b) {     ll result = 1;     while (b) {       if (b % 2) result = (result * a) % m;       a = (a * a) % m;       b /= 2;     }     return result;   }   void precalc() {     fact[0].first = 1;     fact[0].second = 0;     for (int i = 1; i < maxn; i++) {       int d = i;       fact[i].second = fact[i - 1].second;       while (d % 2 == 0) {         fact[i].second++;         d /= 2;       }       (fact[i].first = fact[i - 1].first * d) %= m;     }   }   void solve() {     map<int, int> u;     for (int i = 0; i < n; i++) {       u[a[i]]++;       u[b[i]]++;     }     ll ans = 1, cntws = 0;     for (auto i : u) {       (ans *= fact[i.second].first) %= m;       cntws += fact[i.second].second;     }     for (int i = 0; i < n; i++)       if (a[i] == b[i]) cntws--;     (ans *= power(2, cntws)) %= m;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     a.resize(n), b.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     cin >> m;     precalc();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l1, r1, l2, r2, k;     cin >> l1 >> r1 >> l2 >> r2 >> k;     l1 = max(l1, l2);     r1 = min(r1, r2);     if ((l1 <= k) && (r1 >= k))       cout << r1 - l1;     else       cout << max((long long)0, r1 - l1 + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[100100], y[100100], id[100100];   bool cmp(int i, int j) {     if (y[i] >= 0 && y[j] < 0)       return true;     else if (y[i] < 0 && y[j] >= 0)       return false;     if (y[i] == 0 && y[j] == 0) {       return x[j] < 0;     }     return x[i] * y[j] >= x[j] * y[i];   }   bool cmp_frac(long long ap, long long aq, long long bp, long long bq) {     if (ap >= 0 && bp < 0) return false;     if (ap < 0 && bp >= 0) return true;     if (ap < 0 && bp < 0) return cmp_frac(-bp, bq, -ap, aq);     long long as = ap / aq, ar = ap % aq, bs = bp / bq, br = bp % bq;     if (as < bs)       return true;     else if (as > bs)       return false;     if (br == 0)       return false;     else if (ar == 0)       return true;     return cmp_frac(bq, br, aq, ar);   }   int main() {     int n;     long long ap, aq, tp, tq;     int now = -1;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]), id[i] = i;     sort(id, id + n, cmp);     for (int i = 0; i < n; i++) {       int a = id[i], b = id[(i + 1) % n];       tp = x[a] * x[b] + y[a] * y[b];       if (tp > 0)         tp = tp * tp;       else         tp = -tp * tp;       tq = 1LL * (x[a] * x[a] + y[a] * y[a]) * (x[b] * x[b] + y[b] * y[b]);       if (now == -1 || cmp_frac(ap, aq, tp, tq)) {         ap = tp;         aq = tq;         now = i;       }     }     printf( %d %d n , id[now] + 1, id[(now + 1) % n] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string vow =  aeiou ;   int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   const long double pie = 3.1415926535897932384626;   const long long mod = 1e9 + 7;   void solve(int test_case) {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     vector<int> div;     for (int d = 1; d * d <= n; d++) {       if (n % d) continue;       ;       int d1 = n / d;       int d2 = d;       div.push_back(d1);       if (d1 != d2) div.push_back(d2);     }     int ans = 0;     for (auto i : v) ans += i;     for (auto d : div) {       int take = n / d;       if (take < 3) continue;       ;       for (int i = 0; i < d; i++) {         int s = 0;         for (int j = i; j < n; j += d) s += v[j];         ans = max(ans, s);       }     }     cout << ans;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) solve(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     string A;     cin >> n >> p >> A;     int i = n - 1;     while (i >= 0 && i < n) {       A[i]++;       if (A[i] - 96 > p) {         A[i] = 96;         i--;         continue;       }       if (i > 0 && A[i] == A[i - 1]) continue;       if (i > 1 && A[i] == A[i - 2]) continue;       i++;     }     if (i < 0)       cout <<  NO n ;     else       cout << A <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 5;   long long C[N][5], dif_fact[5];   void calc() {     for (long long i = 0; i < N; i++) {       for (long long j = 0; j <= min(i, 4LL); j++) {         if (j == 0 || j == i) {           C[i][j] = 1;         } else {           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];         }       }     }     dif_fact[1] = 0;     dif_fact[2] = 1;     dif_fact[3] = 2;     dif_fact[4] = 9;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     calc();     long long n, k;     cin >> n >> k;     long long ans = 1;     for (long long i = 2; i <= k; i++) {       long long curr = C[n][i] * dif_fact[i];       ans += curr;     }     cout << ans;   }


#include <bits/stdc++.h>   long long a[10000];   using namespace std;   int main() {     long long n, i, j, c;     cin >> n;     for (i = 1; i < n + 1; i++) cin >> a[i];     for (i = 1; i < n + 1; i++) {       for (j = i + 1; j < n + 1; j++) {         if (a[i] > a[j]) {           c = a[i];           a[i] = a[j];           a[j] = c;         }       }     }     i = 1;     while ((a[i] == 0) && (i < n + 1)) i++;     int rez = 0;     j = i;     while ((a[j] != a[j + 2]) && (j < n)) {       if (a[j] == a[j + 1]) rez++;       j++;     }     if (i == n + 1)       cout << rez;     else {       if (j == n)         cout << rez;       else         cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200010];   int main() {     bool bo = 0;     int X, Y = -1, t, Mx = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       Mx = max(Mx, a[i]);     }     for (int i = 2; i <= n; i++) {       t = abs(a[i] - a[i - 1]);       if (t == 0) {         bo = 1;         break;       }       if (t == 1) continue;       if (Y == -1)         Y = t;       else {         if (t == Y)           continue;         else {           bo = 1;           break;         }       }     }     if (!bo && Y <= 1e9 && Y != -1) {       for (int i = 1; i < n; i++) {         if (a[i] % Y == 0 && a[i + 1] == a[i] + 1) {           bo = 1;           break;         }         if (a[i] % Y == 1 && a[i + 1] == a[i] - 1) {           bo = 1;           break;         }       }     }     if (Y == -1) Y = Mx;     if (bo || Y > 1e9)       printf( NO n );     else {       X = Mx / Y;       if (Mx % Y != 0) X++;       if (X > 1e9)         printf( NO n );       else {         printf( YES n );         printf( %d %d , X, Y);       }     }     return 0;   }


#include <bits/stdc++.h>   int a[18];   int sum(int i, int n) {     int j, s = 0;     for (j = i; j < n; j++) s = s + a[j];     return s;   }   void print(int n) {     int i;     printf( %d n , n);     for (i = 1; i <= n; i++) printf( %d  , i);   }   int main() {     int n, i, sum1 = 0, sum2 = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     if (n == 1) {       printf( -1 );       return 0;     } else if (n == 2) {       if (a[0] == a[1])         printf( -1 );       else         printf( 1 n1 );       return 0;     } else {       for (i = 1; i < n; i++) {         sum2 = sum(0, i);         sum1 = sum(i, n);         if (sum1 != sum2) {           print(i);           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int main() {     char s[1005];     scanf( %s , s);     int n;     scanf( %d , &n);     int len = strlen(s);     int cnt[26] = {0};     for (int i = 0; i < len; i++) cnt[s[i] -  a ]++;     bool found = false;     for (int res = 1; res <= len; res++) {       int need = 0;       int res_cnt[26] = {0};       for (int k = 0; k < 26; k++)         need += res_cnt[k] = (int)ceil((double)cnt[k] / res);       if (need <= n) {         found = true;         printf( %d n , res);         for (int k = 0; k < 26; k++)           for (int j = 0; j < res_cnt[k]; j++) putchar(k +  a );         for (int i = 0; i < n - need; i++) putchar( z );         puts(  );         break;       }     }     if (!found) puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main(int argc, const char** argv) {     int t = 1;     cin >> t;     while (bool(t--)) {       solve();       cout <<   n ;     }   }   void solve() {     vector<int> v(3);     int s = 0;     for (int i = 0; i < 3; i++) {       cin >> v[i];       s += v[i];     }     sort(v.begin(), v.end());     if (v[1] == v[0]) {       if (v[2] % 2 != 0) {         cout <<  NO ;         return;       } else {         cout <<  YES ;         return;       }     }     if (v[2] != v[1]) {       if (s != 2 * v[2]) {         cout <<  NO ;         return;       } else {         cout <<  YES ;         return;       }     } else {       if (v[0] % 2 != 0) {         cout <<  NO ;         return;       } else {         cout <<  YES ;         return;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5 * 100 + 10;   int n, dp1[N][N], dp2[N][N], k, par[N][N];   string s;   void printpath(int i, int j) {     if (j == 0) return;     printpath(i - par[i][j], j - 1);     if (j > 1) cout <<  + ;     if (par[i][j] == 1)       cout << s[i - 1];     else {       for (int l = i - par[i][j]; l <= i - (((par[i][j] + 1) / 2) + 1); l++)         cout << s[l];       if (par[i][j] % 2 == 1) cout << s[i - (((par[i][j] + 1) / 2) + 1) + 1];       for (int l = i - (((par[i][j] + 1) / 2) + 1); l >= i - par[i][j]; l--)         cout << s[l];     }   }   int main() {     cin >> s >> k;     n = s.size();     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         for (int l = i; l <= ((j - i) / 2) + i; l++)           if (s[l] != s[j - l + i]) dp1[i][j]++;     for (int i = 0; i < N; i++) fill(dp2[i], dp2[i] + N, INT_MAX);     dp2[0][0] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < k; j++)         for (int len = 1; len <= n; len++)           if (dp2[i][j] != INT_MAX)             if (dp2[i + len][j + 1] >= dp2[i][j] + dp1[i][i + len - 1])               dp2[i + len][j + 1] = dp2[i][j] + dp1[i][i + len - 1],                                par[i + len][j + 1] = len;     int ans = INT_MAX, r;     for (int i = 1; i <= k; i++)       if (dp2[n][i] < ans) ans = dp2[n][i], r = i;     cout << ans << endl;     printpath(n, r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long R() {     char c;     long long res, sign = 1;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) sign = -1;     res = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ;     return res * sign;   }   priority_queue<long long> q;   const long long N = 210000;   long long a[N], n, m, pre[N], cnt;   signed main() {     n = R();     m = R();     for (long long i = 1; i <= n; i++) a[i] = R();     for (long long i = n; i >= 1; i--) {       if (a[i] < 0)         q.push(a[i]);       else {         while (!q.empty() && a[i] >= 0) a[i] += q.top(), q.pop();         if (a[i] < 0) q.push(a[i]);       }     }     while (!q.empty()) pre[++cnt] = q.top(), q.pop();     for (long long i = 1; i <= cnt; i++) pre[i] = -pre[i] + pre[i - 1];     while (m--)       printf( %lld n ,              (cnt - (upper_bound(pre + 1, pre + 1 + cnt, R()) - pre) + 1));   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = (int)(1e9 + 1337);   const long long LINF = (long long)(2e18);   const double EPS = 1e-11;   const int MAXN = 200100;   string a;   void solve() {     cin >> a;     a +=  # ;     int cur = 0;     int sz = 0;     long long sum = 0;     for (int i = 0; i < a.size(); ++i) {       if (a[i] >=  0  && a[i] <=  9 ) {         cur *= 10;         cur += a[i] -  0 ;         sz++;       } else if (a[i] ==  . ) {         sz = 0;       } else {         if (sz != 2) cur *= 100;         sum += cur;         cur = 0;         sz = 0;       }     }     int kop = sum % 100;     sum /= 100;     string ans;     if (sum == 0) ans =  0 ;     int pr = 0;     while (sum) {       pr++;       ans += (sum % 10) +  0 ;       sum /= 10;       if (sum && pr % 3 == 0) ans +=  . ;     }     reverse(ans.begin(), ans.end());     cout << ans;     if (kop) {       if (kop >= 10)         cout <<  .  << kop;       else         cout <<  .0  << kop;     }   }   int main() {     srand(1337);     int ts = 1;     for (int i = 0; i < ts; ++i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3002;   int n, m, a, b;   long long G[N][N], x, y, z, g[N * N], r[N][N], ans;   deque<int> q;   void init() {     for (int i = 1; i <= (n - 1) * m + m - 1; i++) {       g[i] = (g[i - 1] * x % z + y) % z;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         G[i][j] = g[(i - 1) * m + j - 1];       }     }   }   void cal1() {     for (int i = 1; i <= n; i++) {       while (!q.empty()) q.pop_back();       for (int j = 1; j <= m + 1; j++) {         if (j >= b + 1) {           while (!q.empty() && q.front() < j - b) q.pop_front();           r[i][j - b] = G[i][q.front()];         }         while (!q.empty() && G[i][q.back()] > G[i][j]) q.pop_back();         q.push_back(j);       }     }   }   void cal2() {     for (int j = 1; j <= m; j++) {       while (!q.empty()) q.pop_back();       for (int i = 1; i <= n + 1; i++) {         if (i >= a + 1) {           while (!q.empty() && q.front() < i - a) q.pop_front();           ans += r[q.front()][j];         }         while (!q.empty() && r[q.back()][j] > r[i][j]) q.pop_back();         q.push_back(i);       }     }   }   int main() {     scanf( %d %d %d %d %lld %lld %lld %lld , &n, &m, &a, &b, &g[0], &x, &y, &z);     init();     cal1();     cal2();     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long long a, b, c;     while (~scanf( %I64d%I64d%I64d , &a, &b, &c)) {       if (c == 0) {         if (a == b)           printf( YES n );         else           printf( NO n );       } else {         long long d = (b - a) / c;         long long h = (b - a) % c;         if (d >= 0 && !h)           printf( YES n );         else {           printf( NO n );         }       }     }   }