#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool is_pallindrome(string str, long long int left, long long int right) {     if (left > right) return true;     return (str[left] == str[right] && is_pallindrome(str, left + 1, right - 1));   }   long long int convertToInt(string str) {     long long int sum = 0;     long long int power = 1;     for (long long int i = str.length() - 1; i >= 0; i--) {       long long int val = str[i] -  0 ;       long long int prod =           ((val % 1000000007) * (power % 1000000007)) % 1000000007;       sum = ((sum % 1000000007) + prod % 1000000007) % 1000000007;       power *= 10;     }     return sum;   }   bool compare(pair<long long int, long long int> a,                pair<long long int, long long int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second < b.second;   }   int32_t main() {     c_p_c();     long long int t;     cin >> t;     while (t--) {       long long int a, b;       cin >> a >> b;       if (b % 2 == 0) {         cout << a * (b / 2);       } else {         long long int ans = b / 2 * a;         if (a % 2 == 0)           ans += a / 2;         else           ans += (a / 2) + 1;         cout << ans;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long l = 1000000007;   const int MAX_ = 2000;   int T;   void solve(int t) {     long long n;     cin >> n;     vector<int> p[n];     for (int i = 0; i < n; i++) {       int k;       cin >> k;       p[i] = vector<int>(k);       for (int j = 0; j < k; j++) {         cin >> p[i][j];       }     }     set<int> s;     for (int i = 1; i <= n; i++) {       s.insert(i);     }     int pos = -1;     for (int i = 0; i < n; i++) {       bool f = 0;       for (int j = 0; j < p[i].size(); j++) {         int x = p[i][j];         if (s.find(x) != s.end()) {           f = 1;           s.erase(x);           break;         }       }       if (pos < 0 && f == 0) {         pos = i + 1;       }     }     if (pos > 0) {       cout <<  IMPROVE  << endl;       cout << pos <<     << *s.begin() << endl;       return;     }     cout <<  OPTIMAL  << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t, testCases;     testCases = 1;     while (testCases--) {       t = 1;       cin >> t;       T = t;       while (t--) {         solve(t);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   vector<string> vec;   long long int sd(long long int n) {     long long int sum = 0;     while (n != 0) {       sum += n % 10;       n = n / 10;     }     return sum;   }   long long int nd(long long int n) {     long long int ans = 0;     while (n > 0) {       n = n / 10;       ans++;     }     return ans;   }   long long int power(long long int a, long long int b) {     long long int ans = 1ll;     while (b) {       if (b & 1) ans = (ans * a) % 1000000007;       a = (a * a) % 1000000007;       b = b / 2;     }     return ans;   }   int main() {     long long int n, a, b, r, c, d, i, k, j, temp, sum, ct = 0, flag = -1e13,                                                         start = 0, next = 1;     string st, ans;     long long int ar[1005] = {0};     vector<long long int> v;     vector<pair<long long int, long long int> > v2;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> temp;       v.push_back(temp);     }     if (k > n) {       sort(v.begin(), v.end(), greater<long long int>());       cout << v[0];       return 0;     }     for (i = 0; i < n; i++) {       start = (i + 1) % n;       ct = 0;       if (i != 0)         if (v[start] > v[i - 1]) {           ct += 1;         }       while (ct < k) {         if (v[start] > v[i]) break;         ct++;         start++;         if (start == n) start = 0;       }       if (ct == k) {         cout << v[i];         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 7;   const int M = 100000 + 7;   const int inf = 1000000000 + 7;   const long long linf = 1ll * inf * (inf - 1);   const double pi = acos(-1);   const double eps = 1e-9;   const bool multipleTest = 0;   const int mod[2] = {(rand() % (inf - 1000) + 1000),                       (rand() % (inf - 1000) + 1000)};   int lt[2][N];   struct Hash {     string s;     long long val[2][N];     int n;     void init(string& s_) {       s = s_;       n = s.size();       val[0][0] = val[1][0] = 0;       for (int i = 1; i <= n; ++i) {         for (int j = 0; j < 2; ++j)           val[j][i] = (1ll * val[j][i - 1] * mod[j] + s[i - 1]) % inf;       }     }     long long get(int j, int u, int v) {       long long res = val[j][v] - val[j][u - 1] * lt[j][v - u + 1];       res %= inf;       if (res < 0) res += inf;       return res;     }     pair<int, int> get(int u, int v) {       return make_pair(get(0, u, v), get(1, u, v));     }   };   Hash a, b;   int n, m;   string s, t;   int k;   int dp[N][31];   int getLCP(int u, int v) {     int lo = 1, hi = min(n - u, m - v), res = 0;     while (lo <= hi) {       int g = (lo + hi) >> 1;       if (a.get(u + 1, u + g) == b.get(v + 1, v + g)) {         res = g;         lo = g + 1;       } else         hi = g - 1;     }     return res;   }   void solve() {     cin >> n >> s >> m >> t >> k;     lt[0][0] = lt[1][0] = 1;     for (int i = 1; i < N; ++i) {       lt[0][i] = (1ll * mod[0] * lt[0][i - 1]) % inf;       lt[1][i] = (1ll * mod[1] * lt[1][i - 1]) % inf;     }     a.init(s);     b.init(t);     dp[0][0] = 0;     for (int i = 0; i < n; ++i) {       dp[i][0] = 0;       int old = -1, oldRes = 0;       for (int j = 0; j <= k; ++j) {         if (j) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);         if (j < k) {           int res = 0;           if (dp[i][j] == old) {             res = oldRes;           } else {             res = oldRes = getLCP(i, dp[i][j]);             old = dp[i][j];           }           if (res > 0)             dp[i + res][j + 1] = max(dp[i + res][j + 1], dp[i][j] + res);         }       }     }     if (dp[n][k] == m)       puts( YES );     else       puts( NO );   }   int main() {     int Test = 1;     if (multipleTest) {       cin >> Test;     }     for (int i = 0; i < Test; ++i) {       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int n, a, b, T, used, ans;   int lft[N], rgt[N];   char s[N];   void fill_array(int v[]) {     for (int i = 1; i < n; i++) {       v[i] = v[i - 1] + a + 1 + ((s[i] ==  w ) ? b : 0);     }   }   void solve(int lft[], int rgt[]) {     for (int i = 1; i < n; i++) {       int need = used + lft[i];       if (need <= T) {         ans = max(ans, i + 1);       }       need += (i * a);       if (need > T) {         continue;       }       if (rgt[n - i - 1] + need <= T) {         ans = n;         break;       }       int pos = upper_bound(rgt, rgt + n, T - need) - rgt;       ans = max(ans, i + 1 + pos - 1);     }   }   int main() {     scanf( %d %d %d %d , &n, &a, &b, &T);     scanf( %s , s);     fill_array(lft);     reverse(s + 1, s + n);     fill_array(rgt);     reverse(s + 1, s + n);     used = 1;     if (s[0] ==  w ) {       used += b;     }     if (used > T) {       puts( 0 );       return 0;     }     ans = 1;     solve(lft, rgt);     solve(rgt, lft);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   long double pi = 3.141592653589793238;   int main() {     long long t;     cin >> t;     while (t--) {       long long x;       cin >> x;       long double ans;       long double n = 2.0000000000000 * (long double)x;       long double angle =           (180.000000000000000 - 360.00000000000000 / n) / 2.00000000000000;       angle = angle * pi / 180.000000000000;       long double side = (long double)0.500000000000 / (long double)cosl(angle);       if (x % 2 != 0) {         ans = (long double)2.000000000 * side;       } else {         side = side * (long double)sinl(angle);         ans = (long double)2.000000000 * side;       }       cout << to_string(ans) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 5000 + 9;   int t[MX];   int n;   int counts[MX] = {0};   int ans[MX];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t[i];       t[i]--;     }     for (int start = 0; start < n; start++) {       memset(counts, 0, n * sizeof(int));       int best = 0;       for (int finish = start; finish < n; finish++) {         int who = t[finish];         counts[who]++;         if (counts[who] > counts[best] ||             (counts[who] == counts[best] && who < best))           best = who;         ans[best]++;       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     long long int n, s, x, countt = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     int mid = n / 2;     int m = v[mid];     if (m <= s) {       for (int i = mid; i < v.size(); i++) {         if (v[i] <= s) {           countt += abs(v[i] - s);         } else {           break;         }       }     } else if (s <= m) {       for (int i = mid; i >= 0; i--) {         if (v[i] >= s) {           countt += abs(v[i] - s);         } else {           break;         }       }     }     cout << countt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010, LOG = 64;   int n, arr[N], nxt[N][LOG], mx, sum[N];   long long p, ans = 0;   vector<int> seg[2][4 * N];   bool b;   void build(int s, int e, int idx) {     if (s == e) {       if (sum[s] % 2 == b) seg[b][idx].push_back(sum[s]);       return;     }     build(s, (s + e) / 2, idx * 2);     build((s + e) / 2 + 1, e, idx * 2 + 1);     for (int i = 0; i < (int)seg[b][idx * 2].size(); i++)       seg[b][idx].push_back(seg[b][idx * 2][i]);     for (int i = 0; i < (int)seg[b][idx * 2 + 1].size(); i++)       seg[b][idx].push_back(seg[b][idx * 2 + 1][i]);     sort(seg[b][idx].begin(), seg[b][idx].end());   }   int l, r, val;   int get(int s, int e, int idx) {     if (s > r || e < l) return 0;     if (s >= l && e <= r)       return seg[b][idx].end() -              lower_bound(seg[b][idx].begin(), seg[b][idx].end(), val);     return get(s, (s + e) / 2, idx * 2) + get((s + e) / 2 + 1, e, idx * 2 + 1);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < LOG; i++) nxt[n][i] = n;     for (int i = 0; i < n; i++) {       scanf( %lld , &p);       arr[i] = 0;       for (int j = 62; j >= 0; j--) {         if (((p >> j) & 1) == 1) {           arr[i]++;         }       }       sum[i] = arr[i];       if (i) sum[i] += sum[i - 1];     }     b = 0;     build(0, n - 1, 1);     b = 1;     build(0, n - 1, 1);     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < LOG; j++) {         if (arr[i] == j)           nxt[i][j] = i;         else           nxt[i][j] = nxt[i + 1][j];       }       mx = n;       b = (i == 0 ? 0 : sum[i - 1] % 2);       for (int j = LOG - 1; j >= 0; j--) {         if (nxt[i][j] >= mx) continue;         l = nxt[i][j];         r = mx - 1;         val = 2 * j + (i == 0 ? 0 : sum[i - 1]);         ans += get(0, n - 1, 1);         mx = nxt[i][j];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   bool f(int x, int n, int *pre, int p) {     for (int j = 0; j < n; ++j) {       if ((pre[j + x] - j) % p == 0) return false;     }     return true;   }   using namespace std;   int main(int argc, char **argv) {     vector<int> ans;     int t, n, p, a[2000], pre[5001] = {0};     cin >> n >> p;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     int mn = a[0], mx = a[n - 1];     t = 0;     for (int i = 1; i <= 5000; ++i) {       pre[i] = pre[i - 1];       while (t < n && a[t] <= i) ++t, ++pre[i];     }     for (int i = mn; i <= 2000; ++i) {       if (f(i, n, pre, p)) ans.push_back(i);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] << (i == ans.size() - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> avengers;   long long n, k, A, B;   long long rec(long long l, long long r) {     long long i =         lower_bound(avengers.begin(), avengers.end(), l) - avengers.begin();     long long j =         upper_bound(avengers.begin(), avengers.end(), r) - avengers.begin();     j--;     long long x = j - i + 1;     long long power_consumed;     if (x == 0)       power_consumed = A;     else {       power_consumed = B * x * (r - l + 1);     }     if (l == r || x == 0) return power_consumed;     long long mid = (l + r) / 2;     long long minPower = min(power_consumed, rec(l, mid) + rec(mid + 1, r));     return minPower;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k >> A >> B;     int i;     for (i = 0; i < k; i++) {       int val;       cin >> val;       avengers.push_back(val);     }     sort(avengers.begin(), avengers.end());     long long x = (long long)1 << n;     cout << rec(1, x) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long x, y, z, res1 = 0, res2 = 0;     cin >> x >> y >> z;     unsigned long long a = x % z;     unsigned long long b = y % z;     res1 = (x + y) / z;     if (a == 0 || b == 0)       res2 = 0;     else {       if (a > b) {         if ((z - a) <= b) res2 = z - a;       } else {         if ((z - b) <= a) res2 = z - b;       }     }     cout << res1 <<     << res2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ai, bi;   vector<vector<int> > adj(200009);   vector<int> vis(200009, 0);   vector<pair<int, int> > se;   void dfs(int v, int vl) {     if (vis[v]) return;     vis[v] = vl;     vl = (vl == 1) ? 2 : 1;     int len = adj[v].size();     for (int i = 0; i < len; i++) dfs(adj[v][i], vl);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ai >> bi;       se.push_back(make_pair(ai, bi));       adj[ai].push_back(bi);       adj[bi].push_back(ai);       adj[(2 * i)].push_back(2 * i + 1);       adj[(2 * i + 1)].push_back(2 * i);     }     for (int i = 1; i <= 2 * n; i++)       if (!vis[i]) dfs(i, 1);     for (int i = 0; i < n; i++)       cout << vis[se[i].first] <<     << vis[se[i].second] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s[20][20];   string ran =  23456789TJQKA ;   string sui =  CDHS ;   set<string> st;   int j1x = -1, j1y = -1, j2x = -1, j2y = -1;   inline bool ok(int x, int y) {     set<char> ra, su;     for (int i = x; i < x + 3; i++) {       for (int j = y; j < y + 3; j++) {         ra.insert(s[i][j][0]);         su.insert(s[i][j][1]);       }     }     return ra.size() == 9 || su.size() == 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < 13; i++) {       for (int j = 0; j < 4; j++) {         string ss =     ;         ss[0] = ran[i];         ss[1] = sui[j];         st.insert(ss);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> s[i][j];         if (s[i][j] !=  J1  && s[i][j] !=  J2 )           st.erase(s[i][j]);         else if (s[i][j] ==  J1 )           j1x = i, j1y = j;         else           j2x = i, j2y = j;       }     }     for (set<string>::iterator it1 = st.begin(); it1 != st.end(); it1++) {       if (j1x != -1) s[j1x][j1y] = (*it1);       for (set<string>::iterator it2 = st.begin(); it2 != st.end(); it2++) {         if (it1 == it2) continue;         if (j2x != -1) s[j2x][j2y] = (*it2);         vector<pair<int, int> > v;         for (int i = 0; i <= n - 3; i++) {           for (int j = 0; j <= m - 3; j++)             if (ok(i, j)) v.push_back(make_pair(i + 1, j + 1));         }         for (int i = 0; i < v.size(); i++) {           for (int j = 0; j < i; j++) {             if (abs(v[i].first - v[j].first) > 2 ||                 abs(v[i].second - v[j].second) > 2) {               cout <<  Solution exists. n ;               if (j1x == -1 && j2x == -1) cout <<  There are no jokers. n ;               if (j1x == -1 && j2x != -1)                 cout <<  Replace J2 with   << (*it2) <<  . n ;               if (j1x != -1 && j2x == -1)                 cout <<  Replace J1 with   << (*it1) <<  . n ;               if (j1x != -1 && j2x != -1)                 cout <<  Replace J1 with   << (*it1) <<   and J2 with   << (*it2)                      <<  . n ;               cout <<  Put the first square to (  << v[i].first <<  ,                      << v[i].second <<  ). n ;               cout <<  Put the second square to (  << v[j].first <<  ,                      << v[j].second <<  ). n ;               exit(0);             }           }         }       }     }     cout <<  No solution. ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool col[100010];   int a, b, n, k;   int main() {     cin >> n >> k >> a >> b;     int inv(1);     if (a < b) {       swap(a, b);       inv = 0;     }     for (int i(1); i <= k + 1; i++) {       for (int j(i); j <= n; j += k + 1) {         if (a) {           col[j] = 1;           a--;         }       }     }     int frc(0);     for (int i(1); i <= k + 1; i++) frc += col[i];     for (int i(k + 2); i <= n + 1; i++) {       if (frc == k + 1 || frc == 0) {         cout <<  NO ;         return 0;       }       frc -= col[i - k - 1];       frc += col[i];     }     for (int i(1); i <= n; i++) {       if (inv)         cout << (col[i] ?  G  :  B );       else         cout << (!col[i] ?  G  :  B );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cas, b, k;   int main() {     cas = 1;     while (cas--) {       scanf( %d%d , &b, &k);       int ans = 0;       b = b % 2;       for (int i = 1; i <= k; i++) {         int x;         scanf( %d , &x);         if (i == k) b = 1;         ans = ans + b * x;         ans %= 2;       }       if (ans % 2)         printf( odd n );       else         printf( even n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int64_t N = s.size();     vector<int64_t> v(N, 0);     int64_t l = 0, r = N - 1;     for (int64_t i = 0; i < N; ++i) {       if (s[i] ==  l ) {         v[r] = i + 1;         --r;       } else {         v[l] = i + 1;         ++l;       }     }     for (int64_t k : v) {       cout << k <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long maxi = INT_MIN;     while (n--) {       long long x, y;       cin >> x >> y;       long long sum = x + y;       if (sum > maxi) {         maxi = sum;       }     }     cout << maxi <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double inf = 1e+10;   double eps = 1e-10;   inline int sgn(const double& x) { return (x > +eps) - (x < -eps); }   const int MAXN = 500;   const int MAXM = 501;   int n, m;   double A[MAXM + 1][MAXN + 1];   int basis[MAXM + 1], out[MAXN + 1];   void pivot(int a, int b) {     for (int i = 0; i <= m; ++i)       if (i != a && sgn(A[i][b]))         for (int j = 0; j <= n; ++j)           if (j != b) A[i][j] -= A[a][j] * A[i][b] / A[a][b];     for (int i = 0; i <= m; ++i)       if (i != a) A[i][b] /= -A[a][b];     for (int j = 0; j <= n; ++j)       if (j != b) A[a][j] /= A[a][b];     A[a][b] = 1 / A[a][b];     swap(basis[a], out[b]);   }   double simplex() {     for (int j = 0; j < n; ++j) A[0][j] = -A[0][j];     for (int i = 0; i <= m; ++i) basis[i] = -i;     for (int j = 0; j <= n; ++j) out[j] = j;     while (true) {       int a = 1, b = 0;       for (int i = 1; i <= m; ++i)         if (make_pair(A[i][n], basis[i]) < make_pair(A[a][n], basis[a])) a = i;       if (A[a][n] >= 0) break;       for (int j = 0; j < n; ++j)         if (A[a][j] < A[a][b]) b = j;       if (A[a][b] >= 0) return -inf;       pivot(a, b);     }     while (true) {       int a = 1, b = 0;       for (int j = 0; j < n; ++j)         if (A[0][j] < A[0][b] || A[0][j] == A[0][b] && out[j] < out[b]) b = j;       if (A[0][b] >= 0) break;       for (int i = 1; i <= m; ++i)         if (A[i][b] > 0 &&             (A[a][b] <= 0 || make_pair(A[i][n] / A[i][b], basis[i]) <                                  make_pair(A[a][n] / A[a][b], basis[a])))           a = i;       if (A[a][b] <= 0) return +inf;       pivot(a, b);     }     return A[0][n];   }   int d;   vector<int> adj[500];   vector<int> wei[500];   void dfs(double A[], int u, int p, int d) {     if (d >= 0) {       A[u]--;       for (int i = 0; i < ((int((adj[u]).size()))); ++i) {         int v = adj[u][i];         if (v != p) {           dfs(A, v, u, d - wei[u][i]);         }       }     }   }   int main() {     scanf( %d%d , &n, &d);     int ttl = 0;     for (int i = 0; i < (n); ++i) {       int ti;       scanf( %d , &ti), A[0][i] = ti - 1, ttl += ti;     }     for (int i = 0; i < (n - 1); ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w), --u, --v;       adj[u].push_back(v), adj[v].push_back(u);       wei[u].push_back(w), wei[v].push_back(w);     }     A[0][n] = 0;     for (int i = 0; i < (n); ++i) {       dfs(A[i + 1], i, -1, d);       A[i + 1][n] = -1;     }     for (int i = 0; i < (n); ++i) A[n + 1][i] = 1;     A[n + 1][n] = ttl;     m = n + 1;     double get = simplex();     int ans;     if (get == -inf)       ans = -1;     else       ans = -get + 0.5;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const char choice[6][2] = {{ A ,  C }, { A ,  G }, { A ,  T },                              { C ,  G }, { C ,  T }, { G ,  T }};   int n, m;   string str[maxn];   int ord[2][maxn][6], cnt[2][maxn];   string out[maxn];   void print(int rc, int k) {     for (int i = 0; i < n; i++) out[i] =   ;     if (rc == 0) {       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           out[i] += choice[(i & 1) ? 5 - k : k][(j & 1) ^ ord[0][i][k]];     } else {       for (int j = 0; j < m; j++)         for (int i = 0; i < n; i++)           out[i] += choice[(j & 1) ? 5 - k : k][(i & 1) ^ ord[1][j][k]];     }     for (int i = 0; i < n; i++) cout << out[i] << endl;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; i++) {       for (int k = 0; k < 6; k++) {         int now1 = 0, now2 = 0;         for (int j = 0; j < m; j++) {           now1 += (str[i][j] != choice[(i & 1) ? 5 - k : k][j & 1]);           now2 += (str[i][j] != choice[(i & 1) ? 5 - k : k][(j & 1) ^ 1]);         }         ord[0][i][k] = now1 < now2 ? 0 : 1;         cnt[0][k] += min(now1, now2);       }     }     for (int j = 0; j < m; j++) {       for (int k = 0; k < 6; k++) {         int now1 = 0, now2 = 0;         for (int i = 0; i < n; i++) {           now1 += (str[i][j] != choice[(j & 1) ? 5 - k : k][i & 1]);           now2 += (str[i][j] != choice[(j & 1) ? 5 - k : k][(i & 1) ^ 1]);         }         ord[1][j][k] = now1 < now2 ? 0 : 1;         cnt[1][k] += min(now1, now2);       }     }     int ans = 0x3f3f3f3f, RC, K;     for (int rc = 0; rc <= 1; rc++) {       for (int k = 0; k < 6; k++) {         if (cnt[rc][k] < ans) ans = cnt[rc][k], RC = rc, K = k;       }     }     print(RC, K);   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<vector<int>> adj;   vector<long long> d;   vector<bool> visited;   bitset<5000> sol;   void dfs(int m) {     bitset<5000> tmp;     d[m] = 1;     tmp[0] = 1;     for (auto l : adj[m]) {       if (!visited[l]) {         visited[l] = 1;         dfs(l);         d[m] += d[l];         tmp |= (tmp << d[l]);       }     }     tmp |= (tmp << (n - d[m]));     sol |= tmp;   }   int main(int argc, const char* argv[]) {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b;     cin >> n;     adj = vector<vector<int>>(n + 2);     d = vector<long long>(n + 1);     visited = vector<bool>(n + 1, false);     int p = n;     while (--n) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     n = p;     visited[a] = 1;     dfs(a);     int counter = 0;     for (int i = 1; i < n - 1; i++) {       if (sol[i]) {         counter++;       }     }     cout << counter <<   n ;     for (int i = 1; i < n - 1; i++) {       if (sol[i]) {         cout << i <<     << n - i - 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e6 + 50;   bool tot[10000050];   vector<int> prime;   void seive() {     for (int i = 2; i * i <= mx; i++) {       if (!tot[i]) {         for (int j = (2 * i); j <= mx; j += i) {           tot[j] = true;         }       }     }     for (int i = 2; i <= mx; i++) {       if (!tot[i]) {         prime.push_back(i);       }     }   }   vector<int> g[mx];   map<int, bool> mp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     seive();     cin >> n >> m;     long long int sum = 0;     for (int i = 1; i < n - 1; i++) {       sum += 2;     }     int p = upper_bound(prime.begin(), prime.end(), sum) - prime.begin();     int x = prime[p] - sum;     cout << 2 <<     << prime[p] << endl;     cout << 1 <<     << n <<     << 2 << endl;     for (int i = 2; i <= n - 1; i++) {       cout << 1 <<     << i <<     << ((i == 2) ? x : 2) << endl;     }     m -= n - 1;     long long int tot = (int)1e6 + 10;     int j = 2;     mp[1] = true;     int t = 3;     int f = 0;     for (int i = 2; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         if (f == m) {           return 0;         }         f++;         cout << i <<     << j <<     << (++tot) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};   const double eps = 1e-9;   const int INF = 0x7FFFFFFF;   const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;   const double pi = acos(-1);   template <class T>   T take(queue<T> &O) {     T tmp = O.front();     O.pop();     return tmp;   }   template <class T>   T take(stack<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   template <class T>   T take(priority_queue<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   template <class T>   inline void getint(T &num) {     bool neg = 0;     num = 0;     char c;     while ((c = getchar_unlocked()) && (!isdigit(c) && c !=  - ))       ;     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     do num = num * 10 + c -  0 ;     while ((c = getchar_unlocked()) && isdigit(c));     num *= (neg) ? -1 : 1;   }   template <class T>   inline bool inRange(T z, T a, T b) {     return a <= z && z <= b;   }   void OPEN(string in =  input.txt , string out =  output.txt ) {     freopen(in.c_str(),  r , stdin);     freopen(out.c_str(),  w , stdout);     return;   }   int n;   int main(int argc, const char *argv[]) {     cin >> n;     if (n < 4)       cout <<  NO n ;     else {       cout <<  YES n ;       int cnt = 0, nao;       if (n & 1) {         cnt = n - 5, nao = 6;         for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) {           cout << nao + 1 <<   -   << nao <<   = 1 n ;           nao += 2;         }         cout <<  4 + 1 = 5 n                   5 * 5 = 25 n                   3 - 2 = 1 n                   25 - 1 = 24 n ;         for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i))           cout <<  24 * 1 = 24 n ;       } else {         cout <<  1 * 2 = 2 n                   2 * 3 = 6 n                   6 * 4 = 24 n ;         cnt = n - 4, nao = 5;         for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) {           cout << nao + 1 <<   -   << nao <<   = 1 n ;           nao += 2;         }         for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i))           cout <<  24 * 1 = 24 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       cin.sync();       string s;       cin >> s;       stack<char> ss;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  ( ) ss.push(s[i]);         if (!ss.empty()) {           if (s[i] ==  ) ) {             if (ss.top() ==  ( ) {               ss.pop();             }           }         }       }       cout << ss.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};   int n, k, f;   vector<int> v;   int main(void) {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &f);       v.push_back(f);     }     long long ans = 0;     sort(v.rbegin(), v.rend());     int to = 0;     for (int i = 0; i < v.size(); i++) {       to++;       if (to == k || i + 1 == v.size()) {         ans += 2 * (v[i - to + 1] - 1);         to = 0;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, n1, n2, c, b;     cin >> n >> n1 >> n2;     c = n1;     b = n2;     long double sum = 0, sum1 = 0;     long long int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (n1 >= n2) {       long long int i = 0;       while (b > 0) {         sum += a[n - i - 1];         i++;         b--;       }       sum = sum / n2;       while (c > 0) {         sum1 += a[n - i - 1];         i++;         c--;       }       sum1 = sum1 / n1;       cout << fixed << setprecision(8) << sum + sum1 << endl;     } else {       long long int i = 0;       while (c > 0) {         sum += a[n - i - 1];         i++;         c--;       }       sum = sum / n1;       while (b > 0) {         sum1 += a[n - i - 1];         i++;         b--;       }       sum1 = sum1 / n2;       cout << fixed << setprecision(8) << sum + sum1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000001;   int n, t;   int p[MAXN], s[MAXN];   stack<int> st;   int main() {     scanf( %d n , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &p[i]);     scanf( %d , &t);     for (int i = 1; i <= t; ++i) {       int x;       scanf( %d , &x);       p[x] = -p[x];     }     for (int i = n; i >= 1; --i)       if (p[i] < 0)         st.push(-p[i]);       else {         if (!st.empty() && st.top() == p[i]) {           st.pop();         } else           p[i] = -p[i], st.push(-p[i]);       }     if (st.empty()) {       printf( YES n );       for (int i = 1; i <= n; ++i) printf( %d%s , p[i], (i < n) ?     :   n );     } else       printf( NO n );     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 10;   long long a[MAXN];   long long b[MAXN];   void add(long long k, long long val, int start, int end) {     if (start > end) return;     a[start] += k;     a[end + 1] -= k;     long long bias = val - start * k;     b[start] += bias;     b[end + 1] -= bias;   }   int main() {     int n, num;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &num);       if (num >= i) {         add(-1, num - i, 0, num - i);         add(1, 1, num - i + 1, n - i);         add(-1, num - 1, n - i + 1, n - 1);       } else {         add(1, i - num, 0, n - i);         add(-1, num - 1, n - i + 1, n + num - i);         add(1, 1, n + num - i + 1, n - 1);       }     }     int pos = 0;     long long val = b[0];     for (int i = 1; i < n; i++) {       a[i] += a[i - 1];       b[i] += b[i - 1];       if (a[i] * i + b[i] < val) {         val = a[i] * i + b[i];         pos = i;       }     }     cout << val <<     << pos << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double r, L;   double b, u, A;   double x, y, a;   double D[95], B[95];   struct st {     double x, y, a;   };   st bear[50];   int t;   double fun(int i, double l) {     x = bear[i].x;     y = bear[i].y;     t = bear[i].a;     a = B[t];     b = (fabs(l - x) / y);     A = D[t];     if (x < l)       u = ((A + b) / (1 - A * b)) * y - l + x;     else {       if (a < b)         u = x - l - ((b - A) / (1 + b * A)) * y;       else         u = ((A - b) / (1 + A * b)) * y + x - l;     }     if (u < 0) return 1e9;     return u;   }   const int N = (1 << 20) + 10;   double d[N][22];   int main() {     for (int i = 1; i <= 90; i++) {       B[i] = i * acosl(-1) / 180;       D[i] = tan(B[i]);     }     double l;     int n;     cin >> n >> l >> r;     L = l;     for (int i = 0; i < n; i++) cin >> bear[i].x >> bear[i].y >> bear[i].a;     int m = (1 << n) - 1, i, j, k;     double ans = -1e9;     for (i = 1; i <= m; i++) {       for (j = 0; j < n; j++) {         if (((1 << j) & i)) {           d[i][j] = -1e9;           if ((1 << j) == i) {             d[i][j] = l + fun(j, l);             ans = max(ans, d[i][j]);           } else {             for (k = 0; k < n; k++) {               if (((1 << k) & i) && j != k) {                 d[i][j] =                     max(d[i][j], d[i ^ (1 << j)][k] + fun(j, d[i ^ (1 << j)][k]));                 ans = max(ans, d[i][j]);               }             }           }         }       }     }     printf( %.6f , min(ans - L, r - L));   }


#include <bits/stdc++.h>   using namespace std;   const double PI{3.1415926535897932384626433832795};   const int MOD{static_cast<int>(1e9 + 7)};   const double EPS{1e-9};   template <typename T>   T ModAdd(const T &a, const T &b, const int &mod = MOD) {     return ((a) % mod + (a) % mod) % mod;   }   template <typename T>   T ModSub(const T &a, const T &b, const int &mod = MOD) {     return ((((a % mod) - (b % mod)) % mod) + mod) % mod;   }   template <typename T>   T ModMul(const T &a, const T &b, const int &mod = MOD) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename T>   bool AdditionLimitFlow(const T &a, const T &x) {     T MAXIMUM_INT{a}, MINIMUM_INT{a};     switch (sizeof(a)) {       case 8:         MAXIMUM_INT = LLONG_MAX;         MINIMUM_INT = LLONG_MIN;         break;       case 4:         MAXIMUM_INT = INT_MAX;         MINIMUM_INT = INT_MIN;         break;       default:         cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl;         assert(0);         break;     }     bool overflow{false}, underflow{false};     if ((x > 0) && (a > MAXIMUM_INT - x)) overflow = true;     if ((x < 0) && (a < MINIMUM_INT - x)) underflow = true;     if (overflow) {       cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return overflow;     }     if (underflow) {       cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return underflow;     }     return false;   }   template <typename T>   bool SubstractionLimitFlow(const T &a, const T &x) {     T MAXIMUM_INT{}, MINIMUM_INT{};     switch (sizeof(a)) {       case 8:         MAXIMUM_INT = LLONG_MAX;         MINIMUM_INT = LLONG_MIN;         break;       case 4:         MAXIMUM_INT = INT_MAX;         MINIMUM_INT = INT_MIN;         break;       default:         cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl;         assert(0);         break;     }     bool overflow{false}, underflow{false};     if ((x < 0) && (a > MAXIMUM_INT + x)) overflow = true;     if ((x > 0) && (a < MINIMUM_INT + x)) underflow = true;     if (overflow) {       cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return overflow;     }     if (underflow) {       cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return underflow;     }     return false;   }   template <typename T>   bool MultiplicationLimitFlow(const T &a, const T &x) {     T MAXIMUM_INT{}, MINIMUM_INT{};     switch (sizeof(a)) {       case 8:         MAXIMUM_INT = LLONG_MAX;         MINIMUM_INT = LLONG_MIN;         break;       case 4:         MAXIMUM_INT = INT_MAX;         MINIMUM_INT = INT_MIN;         break;       default:         cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl;         assert(0);         break;     }     bool overflow{false}, underflow{false};     if ((a == -1) && (x == MINIMUM_INT)) overflow = true;     if ((x == -1) && (a == MINIMUM_INT)) overflow = true;     if (a > MAXIMUM_INT / x) overflow = true;     if (a < MINIMUM_INT / x) underflow = true;     if (overflow) {       cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return overflow;     }     if (underflow) {       cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl;       return underflow;     }     return false;   }   template <typename T, size_t N>   istream &operator>>(istream &is, array<T, N> &ARR) {     for (T &a : ARR) is >> a;     return is;   }   template <typename T, size_t N>   ostream &operator<<(ostream &os, array<T, N> &ARR) {     for (T const &a : ARR) os << a <<    ;     return os;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &VEC) {     for (T &v : VEC) is >> v;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &VEC) {     for (T const &v : VEC) os << v <<    ;     return os;   }   template <typename T>   istream &operator>>(istream &is, deque<T> &DEQ) {     for (T &d : DEQ) is >> d;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const deque<T> &DEQ) {     for (const T &d : DEQ) os << d <<    ;     return os;   }   template <typename T>   istream &operator>>(istream &is, list<T> &LIS) {     for (T &l : LIS) is >> l;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const list<T> &LIS) {     for (T const &l : LIS) os << l <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &ST) {     for (auto const &s : ST) os << s <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const unordered_set<T> &U_ST) {     for (T const &us : U_ST) os << us <<    ;     return os;   }   template <typename T1, typename T2>   istream &operator>>(istream &is, pair<T1, T2> &PR) {     is >> PR.first >> PR.second;     return is;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &PR) {     os <<  [  << PR.first <<  :   << PR.second <<  ] ;     return os;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const map<T1, T2> &MP) {     os <<  [  ;     for (pair<T1, T2> const &m : MP) os << m <<    ;     os <<  ] ;     return os;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const unordered_map<T1, T2> &U_MP) {     os <<  [  ;     for (pair<T1, T2> const &um : U_MP) os << um <<    ;     os <<  ] ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, stack<T> STACK) {     while (!STACK.empty()) {       os << STACK.top() <<    ;       STACK.pop();     }     return os;   }   template <typename T>   ostream &operator<<(ostream &os, queue<T> QUEUE) {     while (!QUEUE.empty()) {       os << QUEUE.front() <<    ;       QUEUE.pop();     }     return os;   }   template <typename T, size_t R, size_t C>   ostream &operator<<(ostream &os, array<array<T, C>, R> &MAT) {     for (array<T, C> &ROW : MAT) os << ROW << endl;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, vector<vector<T>> &MAT) {     for (vector<T> &ROW : MAT) os << ROW << endl;     return os;   }   template <typename T>   T max(const T &A, const T &B, const T &C) {     T mx{A};     (mx < B) && (mx = B);     (mx < C) && (mx = C);     return mx;   }   template <typename T>   T min(const T &A, const T &B, const T &C) {     T mn{A};     (mn > B) && (mn = B);     (mn > C) && (mn = C);     return mn;   }   template <typename T>   int cntDigits(const T &N) {     return (static_cast<int>(log10(N)) + 1);   }   template <typename T>   bool isPowOfTwo(const T &N) {     return (N && (!(N & (N - 1))));   }   template <typename T>   bool dblEqual(const T &a, const T &b) {     return abs(a - b) < EPS;   }   void TEST_CASES() {     int n{};     cin >> n;     string s{};     cin >> s;     vector<int> jump(n);     for (auto &val : jump) cin >> val;     vector<bool> reached(n);     string res{ FINITE };     int ind{};     while (ind >= 0 && ind < n) {       if (!reached.at(ind)) {         reached.at(ind) = true;         if (s.at(ind) ==  < )           ind -= jump.at(ind);         else           ind += jump.at(ind);       } else {         res =  IN  + res;         break;       }     }     cout << res << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cerr.setf(std::ios::boolalpha);     cout << std::fixed;     cout << std::setprecision(6);     unsigned TT{1};     while (TT--) {       TEST_CASES();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5100;   long long n, s, t, x[N], a[N], b[N], c[N], d[N], w[N];   long long dp[N][N];   inline void print(long long a[]) {     for (long long i = 1; i <= n; i++) printf( %lld  , a[i]);     printf(  n );   }   inline long long read() {     long long f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   signed main() {     n = read();     s = read();     t = read();     for (long long i = 1; i <= n; i++) x[i] = read();     for (long long i = 1; i <= n; i++) a[i] = read() + x[i];     for (long long i = 1; i <= n; i++) b[i] = read() - x[i];     for (long long i = 1; i <= n; i++) c[i] = read() + x[i];     for (long long i = 1; i <= n; i++) d[i] = read() - x[i];     long long x = 0, y = 0;     for (long long i = 0; i <= n; i++)       for (long long j = 0; j <= n; j++) dp[i][j] = 1e18;     if (s == 1)       dp[1][1] = d[1], x--;     else if (t == 1)       dp[1][1] = b[1], y--;     else       dp[1][1] = b[1] + d[1];     for (long long i = 2; i < n; i++) {       if (i == s) {         for (long long j = 1; j <= i; j++) {           if (j > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + d[i]);           dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i]);         }         x--;         continue;       }       if (i == t) {         for (long long j = 1; j <= i; j++) {           if (j > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + b[i]);           dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i]);         }         y--;         continue;       }       for (long long j = 1 + (i > s && i > t); j <= i; j++) {         long long in = j + x, out = j + y;         if (j > 1 || out) dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i] + d[i]);         if (j > 1 || in) dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i] + b[i]);         dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + b[i] + d[i]);         if (j > 1) dp[i][j - 1] = min(dp[i][j - 1], dp[i - 1][j] + a[i] + c[i]);       }     }     long long ans = 1e18;     if (s == n)       ans = min(ans, dp[n - 1][1] + c[n]);     else if (t == n)       ans = min(ans, dp[n - 1][1] + a[n]);     else       ans = min(ans, dp[n - 1][2] + a[n] + c[n]);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k[101], m, mi = 1000000;     cin >> n;     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < n; i++) {       int c = 0, s = 0;       for (int j = 0; j < k[i]; j++) {         cin >> m;         s += m * 5;         c++;       }       s += c * 15;       mi = min(s, mi);     }     cout << mi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 131;   const int N = 210000;   int n, m;   char sr1[N], sr2[N];   unsigned long long hash1[N][28], hash2[N][28], Q[N];   int Ans[N], ans;   int main() {     int i, j, k, x, y;     cin >> n >> m;     scanf( %s%s , sr1 + 1, sr2 + 1);     Q[0] = 1;     for (i = 1; i <= n; ++i) Q[i] = Q[i - 1] * p;     for (j = 0; j <= 25; ++j)       for (i = 1; i <= n; ++i) {         hash1[i][j] = hash1[i - 1][j] * p;         if (sr1[i] -  a  == j) hash1[i][j] += 1;       }     for (j = 0; j <= 25; ++j)       for (i = 1; i <= m; ++i) {         hash2[i][j] = hash2[i - 1][j] * p;         if (sr2[i] -  a  == j) hash2[i][j] += 1;       }     int cnt;     for (i = 1; i <= n - m + 1; ++i) {       cnt = 0;       for (x = 0; x < 26; ++x) {         if (cnt != x) break;         for (y = 0; y < 26; ++y)           if (hash2[m][x] == hash1[i + m - 1][y] - hash1[i - 1][y] * Q[m])             if (hash2[m][y] == hash1[i + m - 1][x] - hash1[i - 1][x] * Q[m]) {               cnt++;               break;             }       }       if (cnt == 26) Ans[++ans] = i;     }     cout << ans << endl;     for (i = 1; i < ans; ++i) printf( %d  , Ans[i]);     if (ans != 0) printf( %d , Ans[ans]);   }


#include <bits/stdc++.h>   using namespace std;   int n, f;   long long ans;   long long k, l;   long long d[100001];   int main() {     cin >> n >> f;     for (int i = 1; i <= n; i++) {       cin >> k >> l;       d[i] = -min(k, l - k);       ans = ans + min(k, l);     }     sort(d + 1, d + n + 1);     for (int i = 1; i <= f; i++) ans = ans + max(-d[i], (long long)(0));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, int> M;   char t[7] = { B ,  u ,  l ,  b ,  a ,  s ,  r };   int num[7] = {1, 2, 1, 1, 2, 1, 1};   char ch[200020];   int main() {     scanf( %s , ch);     int n = strlen(ch);     for (int i = 0; i < n; i++) M[ch[i]]++;     int ans = 1 << 30;     for (int i = 0; i < 7; i++) ans = min(ans, M[t[i]] / num[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void amax(X& x, const Y& y) {     if (x < y) x = y;   }   template <class X, class Y>   void amin(X& x, const Y& y) {     if (x > y) x = y;   }   const int INF = 1e9 + 10;   const long long INFL = 1e18 + 10;   const int MAX = 1e6 + 10;   int n;   int a[MAX], prv[MAX], pos[MAX];   long long gt[MAX * 4], lazy[MAX * 4];   void update(int id, int l, int r, int u, int v) {     if (v < l || u > r) return;     if (u <= l && r <= v) {       lazy[id]++;       gt[id] += (r - l + 1);       return;     }     int mid = (l + r) / 2;     update(id * 2, l, mid, u, v);     update(id * 2 + 1, mid + 1, r, u, v);     gt[id] = gt[id * 2] + gt[id * 2 + 1] + lazy[id] * (r - l + 1);   }   long long query(int id, int l, int r, int u, int v) {     if (v < l || u > r) return 0;     if (u <= l && r <= v) return gt[id];     int mid = (l + r) / 2;     return query(id * 2, l, mid, u, v) + query(id * 2 + 1, mid + 1, r, u, v) +            lazy[id] * (min(r, v) - max(u, l) + 1);   }   void process() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       prv[i] = pos[a[i]];       pos[a[i]] = i;     }     long double sum = 0;     long double choose = (long long)n * n;     for (int i = 1; i <= n; i++) {       update(1, 1, n, prv[i] + 1, i);       sum = sum + (query(1, 1, n, 1, i) * 2 - 1) / choose;     }     cout << fixed << setprecision(10) << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     process();   }


#include <iostream>   #include <vector>   using namespace std;   int t,k,n,m;   vector<int> a,b,v;   int main() {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       cin>>t;       while (t--) {           cin>>k>>n>>m;           a.resize(n);           b.resize(m);           for (int &x:a) cin>>x;           for (int &x:b) cin>>x;           auto solve=[&]()->vector<int> {               vector<int> sequences;               int l=0,r=0,cur=k;               while (true) {                   if (l==n && r==m) break;                   if (l!=n && a[l]>=0 && a[l]<=cur) {                       if (a[l]==0) cur++;                       sequences.emplace_back(a[l++]);                   }                   else if (r!=m && b[r]>=0 && b[r]<=cur) {                       if (b[r]==0) cur++;                       sequences.emplace_back(b[r++]);                   }                   else return vector<int> {-1};               }               return sequences;           };           v=solve();           for (int i=0;i<(int)v.size();i++) cout<<v[i]<<   n [i==(int)v.size()-1];       }   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int u, v, w;   } p[400500];   int father[200100];   int use[200100];   int coo(struct data a, struct data b) {     if (a.w > b.w) return 1;     return 0;   }   int find(int x) { return x == father[x] ? x : father[x] = find(father[x]); }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) father[i] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &p[i].u, &p[i].v, &p[i].w);     }     sort(p + 1, p + m + 1, coo);     long long ans = 0;     for (int i = 1; i <= m; i++) {       int x = find(p[i].u), y = find(p[i].v);       if (use[x] && use[y]) continue;       if (x == y)         use[x] = 1;       else {         father[x] = y;         use[y] |= use[x];       }       ans += p[i].w;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int A[202020];   string S;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> K;     for (i = 0; i < (N); i++) cin >> A[i];     cin >> S;     signed long long ret = 0;     for (i = 0; i < N;) {       j = i;       vector<int> V;       while (j < N && S[i] == S[j]) {         V.push_back(A[j]);         j++;       }       i = j;       sort((V.begin()), (V.end()));       reverse((V.begin()), (V.end()));       for (j = 0; j < (min(K, (int)V.size())); j++) ret += V[j];     }     cout << ret << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[500005], b[500005], reach[500005][19];   int tree[4 * 500005][19];   void build(int i, int layer, int low, int high) {     if (low == high) {       tree[i][layer] = reach[low][layer];       return;     }     int mid = (low + high) / 2;     build(2 * i, layer, low, mid);     build(2 * i + 1, layer, mid + 1, high);     tree[i][layer] = min(tree[2 * i][layer], tree[2 * i + 1][layer]);   }   int get(int i, int layer, int low, int high, int u, int v) {     if (v < low || high < u) return 500005;     if (u <= low && high <= v) return tree[i][layer];     int mid = (low + high) / 2;     return min(get(2 * i, layer, low, mid, u, v),                get(2 * i + 1, layer, mid + 1, high, u, v));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i + n] = a[i];     }     m = 2 * n - 1;     for (int i = 1; i <= m; i++) {       b[i] = i - a[i];       reach[i][0] = max(1, b[i]);     }     build(1, 0, 1, m);     for (int j = 1; j < 19; j++) {       for (int i = 1; i <= m; i++)         reach[i][j] = get(1, j - 1, 1, m, reach[i][j - 1], i);       build(1, j, 1, m);     }     long long ret = 0;     for (int end = n; end <= m; end++) {       int moves = 0;       int prev = end;       for (int j = 19 - 1; j >= 0; j--) {         int tmp = get(1, j, 1, m, prev, end);         if (tmp > end - n + 1) {           moves += 1 << j;           prev = tmp;         }       }       moves++;       ret += moves;     }     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   int mul(long long int a) {     int mi = 10, ma = 0;     while (a != 0) {       int d = a % 10;       mi = min(mi, d);       ma = max(ma, d);       a /= 10;     }     return mi * ma;   }   int main() {     int t = 0;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       k--;       while (k--) {         int mult = mul(n);         if (mult == 0) {           break;         }         n += mult;       }       std::cout << n << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:640000000 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int a, b;     cin >> a >> b;     for (int _n((a)-1), i(0); i <= _n; ++i) cout << i + 1 <<    ;     for (int i = (a + b + 1), _b = (a + 1); i >= _b; --i) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prime_Numbers;   bool primes[1000005];   void prime(int n) {     for (int i = 2; i <= n; i++) primes[i] = true;     for (int i = 2; i <= n; i++) {       if (primes[i] == true) {         prime_Numbers.push_back(i);         for (int j = i + i; j <= n; j += i) primes[j] = false;       }     }   }   int fib(int n) {     if (n == 1 || n == 0) return n;     return fib(n - 1) + fib(n - 2);   }   long long fastpower(int b, int p) {     if (p == 0) return 1;     long long term = fastpower(b, p / 2);     term *= term;     if (p % 2 != 0) return term *= b;     return term;   }   long long arr[3005];   int main() {     int t;     cin >> t;     while (t--) {       int n, k, d;       cin >> n >> k >> d;       int arr[n + 2];       set<int> st;       map<int, int> mp;       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < d; i++) {         st.insert(arr[i]);         mp[arr[i]]++;       }       int mnm = st.size();       for (int i = d; i < n; i++) {         mp[arr[i - d]]--;         if (mp[arr[i - d]] == 0) st.erase(arr[i - d]);         st.insert(arr[i]);         mp[arr[i]]++;         mnm = min(mnm, (int)st.size());       }       cout << min(mnm, (int)st.size()) << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long int add(long long int a, long long int b) {     return a + b - (a + b >= 1000000007) * 1000000007;   }   long long int sub(long long int a, long long int b) {     return a - b + (a - b < 0) * 1000000007;   }   long long int mult(long long int a, long long int b) {     return (1LL * a * b) % 1000000007;   }   inline long long int gcd(long long int a, long long int b) {     long long int t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   long long int powmod(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int k;     cin >> k;     long long int q = (1000000007 - 1) / 2;     long long int d = 2;     for (long long int i = 0; i < k; i++) {       long long int x;       cin >> x;       q = powmod(q, x);       d = powmod(d, x);     }     d = d * powmod(2, 1000000007 - 2) % 1000000007;     q = (q * 2 + 1) % 1000000007 * powmod(3, 1000000007 - 2) % 1000000007;     long long int p = q * d % 1000000007;     cout << p <<  /  << d;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 5;   const long long N = 205;   void solve();   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout << fixed << setprecision(10);     long long _ = 1;     while (_--) solve();     return 0;   }   void solve() {     string s;     cin >> s;     long long n = s.size();     long long ans = LLONG_MAX;     for (long long loop = 0; loop < 26; loop++) {       char ch =  a  + loop;       long long cnt = 0, temp = 0;       for (long long i = 0; i < n; i++) {         cnt++;         if (ch == s[i]) {           temp = max(temp, cnt);           cnt = 0;         }       }       if (cnt) cnt++;       temp = max(temp, cnt);       ans = min(temp, ans);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[100005];   int main() {     {       cin >> n;       for (int i = 0; i < n; i++) scanf( %lld , &a[i]);       sort(a, a + n);       long long ans = LLONG_MAX;       for (int c = 1;; c++) {         long long now = 1;         long long tot = 0;         bool ok = 1;         for (int i = 0; i < n; i++) {           tot += abs(now - a[i]);           now = now * c;           if (now > 1e14) {             ok = 0;             break;           }         }         if (!ok) break;         ans = min(ans, tot);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   vector<int> primes;   void solve() {     int n;     cin >> n;     set<int> divisors;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         divisors.insert(i);         divisors.insert(n / i);       }     }     auto prime = [&](int x) {       if (x == 2 || x == 3) return true;       for (int i = 2; i * i <= x; i++) {         if (x % i == 0) return false;       }       return true;     };     if (divisors.size() == 2) {       if (prime(*divisors.begin()) && prime(*prev(divisors.end()))) {         for (auto d : divisors) cout << d <<    ;         cout << n << endl;         cout << 1 << endl;         return;       }     }     divisors.insert(n);     vector<int> primes;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         primes.push_back(i);         while (n % i == 0) n = n / i;       }     }     if (n > 1) primes.push_back(n);     vector<int> ans;     unordered_set<int> avail(divisors.begin(), divisors.end());     for (int i = 0; i < primes.size(); i++) {       int p = primes[i];       int q = primes[(i + 1) % primes.size()];       for (auto d : divisors) {         if (avail.find(d) != avail.end() && d % p == 0 && d % q != 0) {           ans.push_back(d);           avail.erase(d);         }       }       int r = p * q;       if (avail.find(r) != avail.end()) {         ans.push_back(r);         avail.erase(r);       }     }     for (auto d : divisors) {       if (avail.find(d) != avail.end()) {         ans.push_back(d);         avail.erase(d);       }     }     assert(avail.empty());     for (auto e : ans) cout << e <<    ;     cout << endl;     cout << 0 << endl;   }   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3,Ofast,no-stack-protector,unroll-loops,fast-math )   const int maxn = 2e3 + 7;   int32_t main() {     int n, d, e;     cin >> n >> d >> e;     int ans = 1e9 + 7;     for (int i = 1; i * 5 * e <= n; i++) {       int t = i * 5 * e;       t = n - t;       t %= (d);       ans = min(ans, t);     }     int t = n % d;     ans = min(ans, t);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int power(int x, int e) { return e ? x * power(x, e - 1) : 1; }   template <typename T>   void transpose(std::vector<std::vector<T>>& M) {     auto tmp = M;     M.resize(tmp[0].size());     for (auto& row : M) row.resize(tmp.size());     for (int i = 0; i < (int)M.size(); i++) {       for (int j = 0; j < (int)M[0].size(); j++) {         M[i][j] = tmp[j][i];       }     }   }   class FFT {    public:     using cd = std::complex<double>;     using vcd = std::vector<cd>;     using vvcd = std::vector<vcd>;     static int get_lg(int x) { return x ? 32 - __builtin_clz(x - 1) : 0; }     static void precompute(int lg) {       int size = 1 << lg;       if ((int)reverse.size() <= lg) {         reverse.resize(lg + 1);         ws.resize(lg + 1);       }       if (reverse[lg].empty()) {         reverse[lg].assign(size, 0);         for (int i = 1, j = 0; i < size; i++) {           int bit = size >> 1;           for (; j & bit; bit >>= 1) j ^= bit;           j ^= bit;           reverse[lg][i] = j;         }       }       if (ws[lg - 1].empty()) {         ws[lg - 1].resize(size >> 1);         for (int i = 0; i < (size >> 1); i++) {           double ang = 2 * PI * i / size;           ws[lg - 1][i] = {cos(ang), sin(ang)};         }         for (int j = lg - 2; j >= 0 && ws[j].empty(); j--) {           int sz_level = ws[j + 1].size() >> 1;           ws[j].resize(sz_level);           for (int i = 0; i < sz_level; i++) ws[j][i] = ws[j + 1][i << 1];         }       }     }     static void fft(vcd& a, bool inv) {       int lg = get_lg(a.size());       int size = 1 << lg;       precompute(lg);       auto& rev = reverse[lg];       for (int i = 0; i < size; i++) {         if (i < rev[i]) swap(a[i], a[rev[i]]);       }       for (int k = 0; k < lg; k++) {         int len = 1 << k;         auto& w = ws[k];         for (int i = 0; i < size; i += 2 * len) {           for (int j = 0; j < len; j++) {             cd u = a[i + j], v = a[i + j + len] * w[j];             a[i + j] = u + v;             a[i + j + len] = u - v;           }         }       }       if (inv) {         for (cd& x : a) x /= size;         std::reverse(a.begin() + 1, a.end());       }     }     static void multiply(vcd& fa, vcd& fb) {       int result_size = fa.size() + fb.size() + 1;       int size = 1 << get_lg(result_size);       fa.resize(size);       fb.resize(size);       fft(fa, false);       fft(fb, false);       for (int i = 0; i < size; i++) fa[i] *= fb[i];       fft(fa, true);       fa.resize(result_size);     }     template <typename T>     static std::vector<long long> multiply_brute_force(std::vector<T> const& a,                                                        std::vector<T> const& b) {       vector<long long> result(a.size() + b.size() + 1, 0);       for (auto i = 0u; i < a.size(); i++) {         for (auto j = 0u; j < b.size(); j++) {           result[i + j] += a[i] * b[j];         }       }       return result;     }     template <typename T>     static std::vector<long long> multiply(std::vector<T> const& a,                                            std::vector<T> const& b) {       vector<long long> result;       int result_size = a.size() + b.size() + 1;       if (result_size <= 0) {         result = multiply_brute_force(a, b);       } else {         vcd fa(a.begin(), a.end()), fb(b.begin(), b.end());         multiply(fa, fb);         result.resize(result_size);         for (int i = 0; i < result_size; i++)           result[i] = std::llround(fa[i].real());       }       return result;     }       private:     static std::vector<std::vector<int>> reverse;     static std::vector<vcd> ws;     static const double PI;   };   std::vector<std::vector<int>> FFT::reverse;   std::vector<FFT::vcd> FFT::ws;   const double FFT::PI = std::acos(-1);   class BigInteger {    public:     BigInteger(long long x = 0) {       if (x > 0)         sign = 1;       else if (x == 0)         sign = 0;       else         sign = -1;       x *= sign;       while (x) {         data.push_back(x % BASE);         x /= BASE;       }     }     BigInteger& operator+=(BigInteger const& o) {       data.resize(max(data.size(), o.data.size()) + 1, 0);       int carry = 0;       for (auto i = 0u; i < o.data.size() || carry; i++) {         if (i < o.data.size()) carry += o.data[i];         if (i < data.size()) carry += data[i];         data[i] = carry % BASE;         carry /= BASE;       }       pop_zeros();       return *this;     }     BigInteger& operator*=(int o) {       if (o == 0) {         sign = 0;         data.clear();       } else {         if (o < 0) {           sign *= -1;           o = std::abs(o);         }         int n = data.size();         data.resize(n + 9, 0);         long long carry = 0;         for (int i = 0; i < n || carry; i++) {           carry += (long long)data[i] * o;           data[i] = carry % BASE;           carry /= BASE;         }         pop_zeros();       }       return *this;     }     BigInteger& operator*=(BigInteger const& o) {       sign *= o.sign;       if (sign == 0) {         data.clear();       } else {         auto result = FFT::multiply(data, o.data);         data.resize(result.size());         long long carry = 0;         for (auto i = 0u; i < result.size(); i++) {           carry += result[i];           data[i] = carry % BASE;           carry /= BASE;         }         pop_zeros();       }       return *this;     }     void pop_zeros() {       while (!data.empty() && data.back() == 0) data.pop_back();     }     friend std::ostream& operator<<(std::ostream& stream, BigInteger const& b) {       if (b.data.empty()) {         stream << 0;       } else {         if (b.sign == -1) stream <<  - ;         stream << b.data.back();         for (int i = b.data.size() - 2; i >= 0; i--) {           stream.width(DIGITS);           stream.fill( 0 );           stream << b.data[i];         }       }       return stream;     }     friend std::istream& operator>>(std::istream& is, BigInteger& b) {       std::string s;       is >> s;       int start = 0;       if (s ==  0 ) {         b.sign = 0;         b.data.clear();       } else {         if (s[0] ==  - ) {           b.sign = -1;           start++;         } else {           b.sign = 1;         }         b.data.resize((s.size() - start + DIGITS - 1) / DIGITS);         for (int i = 0, idx = s.size() - 1; i < (int)b.data.size();              i++, idx -= DIGITS) {           int value = 0;           for (int j = max(start, idx - DIGITS + 1); j <= idx; j++)             value = value * 10 + s[j] -  0 ;           b.data[i] = value;         }       }       return is;     }     unsigned int digits() const {       if (data.empty()) return 0;       unsigned int d = (data.size() - 1) * DIGITS;       int x = data.back();       while (x > 0) {         d++;         x /= 10;       }       return d;     }     int compare(BigInteger const& o) const {       if (sign < o.sign) return -1;       if (sign > o.sign) return 1;       if (data.size() != o.data.size())         return (data.size() < o.data.size()) == (sign == 1) ? -1 : 1;       for (int i = data.size() - 1; i >= 0; i--) {         if (data[i] != o.data[i])           return (data[i] < o.data[i]) == (sign == 1) ? -1 : 1;       }       return 0;     }     bool operator==(BigInteger const& o) const { return compare(o) == 0; }     bool operator!=(BigInteger const& o) const { return compare(o) != 0; }     bool operator<(BigInteger const& o) const { return compare(o) == -1; }     bool operator<=(BigInteger const& o) const { return compare(o) <= 0; }     bool operator>(BigInteger const& o) const { return compare(o) == 1; }     bool operator>=(BigInteger const& o) const { return compare(o) >= 0; }       private:     static const int DIGITS = 4;     static const int BASE = power(10, DIGITS);     int sign;     vector<int> data;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     BigInteger a;     cin >> a;     if (a < 5) {       cout << a <<   n ;       return 0;     }     int p = max(0, (int)(a.digits() * log(10) / log(3) - 3));     int sum = p * 3;     BigInteger x = 1;     BigInteger base = 3;     while (p) {       if (p & 1) x *= base;       base *= base;       p >>= 1;     }     int best = std::numeric_limits<int>::max();     for (int twos = 0; twos < 3; twos++) {       int sum_cur = sum;       BigInteger y = x;       for (int i = 0; i < twos; i++) {         sum_cur += 2;         y *= 2;       }       while (y < a) {         sum_cur += 3;         y *= 3;       }       best = min(best, sum_cur);     }     cout << best <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using big = long long;   const int N = 200200;   int a[N];   int f[N][2][2][2][2];   int dfs(int n, int x, int y, int v1, int v2) {     if (!n) {       assert(!x && !y);       return v1 > v2;     }     if (x && !dfs(n - 1, x - 1, y, v2, !v1)) {       return true;     }     if (y && !dfs(n - 1, x, y - 1, v2, v1)) {       return true;     }     return false;   }   vector<int> to_vec(int x, int y) { return {x % 4, y % 4}; }   map<vector<int>, int> init() {     map<vector<int>, int> g;     vector<vector<int>> ans;     for (int n = 1; n <= 16; ++n) {       for (int x = 1; x <= n; x += 2) {         int y = n - x;         int res = dfs(n, x, y, 0, 0);         if (g.count(to_vec(x, y)) && g[to_vec(x, y)] != res) {           cerr <<   ERRRR    << endl;         }         assert(!g.count(to_vec(x, y)) || g[to_vec(x, y)] == res);         g[to_vec(x, y)] = res;         ans.push_back({x, y, res});       }     }     return g;   }   int main() {     ios_base::sync_with_stdio(false);     auto g = init();     int cas;     cin >> cas;     memset(f, -1, sizeof(f));     while (cas--) {       int n;       cin >> n;       int s = 0;       for (int i = 0; i < n; ++i) {         cin >> a[i];         s ^= a[i];       }       int highest = 0;       for (int i = 0; (1ll << i) <= s; ++i) {         highest = i;       }       int cnt = 0;       for (int i = 0; i < n; ++i) {         if (a[i] >> highest & 1) {           ++cnt;         }       }       int other = n - cnt;       if (!s) {         cout <<  DRAW               <<   n ;       } else {         assert(cnt & 1);         if (g[to_vec(cnt, other)]) {           cout <<  WIN                 <<   n ;         } else {           cout <<  LOSE                 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 123456789;   const long long inf = 123456789000000000;   const double EPS = 1e-10;   const double PI = 2 * asin(1.0);   const long long mod = 1e9 + 7;   inline int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   int main() {     string s;     cin >> s;     long long par, impar, ap, ai, bp, bi;     par = impar = ap = ai = bp = bi = 0LL;     for (int i = 0; i < ((int)s.size()); ++i) {       impar++;       if (i % 2 == 0) {         if (s[i] ==  a ) {           par += ai;           impar += ap;           ap++;         } else {           par += bi;           impar += bp;           bp++;         }       } else {         if (s[i] ==  a ) {           par += ap;           impar += ai;           ai++;         } else {           par += bp;           impar += bi;           bi++;         }       }     }     cout << par <<     << impar << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100100], tmp, Ans, Odd, Even;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1)         Odd++;       else         Even++;     }     tmp = min(Odd, Even);     Ans += tmp;     Odd -= tmp;     Ans += Odd / 3;     cout << Ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, x, y;     cin >> a;     while (a--) {       cin >> x >> y;       x = x - 1;       while (x--) {         y = y + 9;       }       cout << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   int n, Q, cc = 1, tp, h[N], s[N];   struct E {     int v, nxt;   } e[N << 1];   inline void add(int u, int v) {     e[cc] = (E){v, h[u]};     h[u] = cc++;   }   struct st {     int n, c[N << 1];     inline void upd(int x, int v) {       for (; x <= n; x += x & -x) c[x] += v;     }     inline int qry(int x) {       int r = 0;       for (; x; x -= x & -x) r += c[x];       return r;     }   } C;   struct tr {     int ch[2], f, r, sz, c, tg;   } t[N];   inline int isrt(int x) { return t[t[x].f].ch[0] != x && t[t[x].f].ch[1] != x; }   inline int wh(int x) { return t[t[x].f].ch[1] == x; }   inline void up(int x) { t[x].sz = t[t[x].ch[0]].sz + t[t[x].ch[1]].sz + 1; }   inline void rot(int x) {     int y = t[x].f, z = t[y].f, c = wh(x);     t[x].f = z;     if (!isrt(y)) t[z].ch[wh(y)] = x;     t[t[x].ch[c ^ 1]].f = y;     t[y].ch[c] = t[x].ch[c ^ 1];     t[y].f = x;     t[x].ch[c ^ 1] = y;     up(y);     up(x);   }   inline void rev(int x) {     swap(t[x].ch[0], t[x].ch[1]);     t[x].r ^= 1;   }   inline void cov(int x, int v) { t[x].c = t[x].tg = v; }   inline void dn(int x) {     if (t[x].r) rev(t[x].ch[0]), rev(t[x].ch[1]), t[x].r ^= 1;     if (t[x].tg) cov(t[x].ch[0], t[x].tg), cov(t[x].ch[1], t[x].tg), t[x].tg = 0;   }   inline void splay(int x) {     for (int i = s[tp = 1] = x; !isrt(i); i = t[i].f) s[++tp] = t[i].f;     while (tp) dn(s[tp--]);     for (int y; !isrt(x); rot(x))       if (!isrt(y = t[x].f)) wh(x) ^ wh(y) ? rot(x) : rot(y);   }   inline void access(int x, int c) {     for (int y = 0; x; x = t[y = x].f) {       splay(x);       t[x].ch[1] = 0;       up(x);       C.upd(t[x].c, -t[x].sz);       cov(x, c);       C.upd(t[x].c, t[x].sz);       t[x].ch[1] = y;       up(x);     }   }   inline int qry(int x) {     splay(x);     return C.qry(t[x].c) - t[t[x].ch[0]].sz;   }   void dfs(int x, int p) {     t[x].c = x;     t[x].sz = 1;     t[x].f = p;     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].v != p) dfs(e[i].v, x), t[x].c = max(t[x].c, t[e[i].v].c);     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].v != p && t[x].c == t[e[i].v].c)         t[x].ch[1] = e[i].v, t[x].sz += t[e[i].v].sz;     C.upd(t[x].c, 1);   }   int main() {     scanf( %d%d , &n, &Q);     C.n = n + Q + 1;     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     dfs(n, 0);     int c = n;     while (Q--) {       char o[10];       scanf( %s , o);       int x, y;       if (o[0] ==  u ) {         scanf( %d , &x);         access(x, c);         splay(x);         rev(x);         dn(x);         C.upd(t[x].c, -1);         t[x].ch[1] = 0;         cov(x, ++c);         t[x].sz = 1;         C.upd(t[x].c, 1);       } else if (o[0] ==  w )         scanf( %d , &x), printf( %d n , qry(x));       else {         scanf( %d%d , &x, &y);         printf( %d n , qry(x) < qry(y) ? x : y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, mod = 1e9 + 7, inf = 1e18;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k, x, s = 0, flag = 0, ans = 0;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       s += x;       if (s / k) flag = 0;       ans += s / k;       s %= k;       if (flag) ans++, s = 0, flag = 0;       if (s) flag = 1;     }     if (s) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 2 * 1e5 + 5;   long long int vis[mxn];   vector<vector<long long int>> ad(mxn);   long long int leaf, ans = 0;   void dfs(long long int n, long long int d) {     vis[n] = 1;     for (auto child : ad[n])       if (!vis[child]) dfs(child, d + 1);     if (d > ans) {       ans = d;       leaf = n;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k, n, m;       cin >> n >> k;       vector<long long int> par(k + 1);       for (j = 1; j <= k; j++) par[j] = j;       vector<vector<long long int>> adj(n + 1);       for (i = 1; i <= k; i++) {         adj[n].emplace_back(i);         ad[n].emplace_back(i);         ad[i].emplace_back(n);       }       for (j = 0; i < n; i++, j++) {         adj[par[j % k + 1]].emplace_back(i);         ad[par[j % k + 1]].emplace_back(i);         ad[i].emplace_back(par[j % k + 1]);         par[j % k + 1] = i;       }       dfs(1, 0);       ans = 0;       memset(vis, 0, sizeof vis);       dfs(leaf, 0);       cout << ans <<   n ;       for (i = 1; i <= n; i++) {         for (auto j : adj[i]) cout << i <<     << j <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A[100005];     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     int mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += A[i];       if (A[i] > mx) mx = A[i];     }     sum -= mx;     if (sum <= mx) {       cout << mx - sum + 1 << endl;     } else {       cout << 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, s;   vector<long long int> v, ans;   void build(const int &last, const int &i, const int &k,              const bool &increasing) {     if (!k)       return;     else if (last != v[i] and int(v.size()) - i == k)       ans.push_back(v[i]), build(v[i], i + 1, k - 1, increasing);     else if (last == v[i])       build(last, i + 1, k, increasing ^ 1);     else       ans.push_back(last + (increasing ? 1 : -1)),           build(last + (increasing ? 1 : -1), i, k - 1, increasing);   }   int main() {     scanf( %lld %lld %lld , &n, &k, &s);     if (k * (n - 1) < s or k > s) return printf( %s n ,  NO ), 0;     for (int i = 0; i < k and s > n - 1; ++i, s -= (n - 1))       v.push_back((i & 1) ? 1 : n);     if (int(v.size()) & 1)       v.push_back(n - s);     else       v.push_back(1 + s);     build(1, 0, k, 1);     printf( %s n ,  YES );     for (int i = 0; i < int(ans.size()); ++i)       printf( %lld%c , ans[i], (i == int(ans.size()) - 1) ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<vector<char>> arr(n + 2, vector<char>(m + 2));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> arr[i][j];       }     }     for (int i = 0; i < n + 2; i++) {       arr[i][0] = arr[i][m + 1] =  . ;     }     for (int i = 0; i < m + 2; i++) {       arr[0][i] = arr[n + 1][i] =  . ;     }     n += 2, m += 2;     int l = 0, r = n + m + 1;     vector<vector<int>> dist(n, vector<int>(m));     queue<pair<int, int>> q;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] ==  . ) {           q.emplace(i, j);           dist[i][j] = 0;         } else {           dist[i][j] = INF;         }       }     }     while (!q.empty()) {       int i = q.front().first, j = q.front().second;       q.pop();       vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                                   {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};       for (auto &add : t) {         int ni = i + add.first, nj = j + add.second;         if (ni >= 0 && ni < n && nj >= 0 && nj < m && dist[ni][nj] == INF) {           dist[ni][nj] = dist[i][j] + 1;           q.emplace(ni, nj);         }       }     }     while (r - l > 1) {       int t = (l + r) / 2;       vector<vector<int>> dist_start(n, vector<int>(m));       deque<pair<int, int>> q;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (arr[i][j] ==  X  && dist[i][j] > t) {             q.emplace_back(i, j);             dist_start[i][j] = 0;           } else {             dist_start[i][j] = INF;           }         }       }       while (!q.empty()) {         int i = q.front().first, j = q.front().second;         q.pop_front();         vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                                     {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};         for (auto &add : t) {           int ni = i + add.first, nj = j + add.second;           if (ni >= 0 && ni < n && nj >= 0 && nj < m &&               dist_start[ni][nj] == INF) {             dist_start[ni][nj] = dist_start[i][j] + 1;             q.emplace_back(ni, nj);           }         }       }       bool flag = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (arr[i][j] ==  X  && dist_start[i][j] > t) {             flag = false;           }         }       }       if (flag) {         l = t;       } else {         r = t;       }     }     cout << l <<   n ;     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         if (arr[i][j] ==  X  && dist[i][j] > l) {           cout <<  X ;         } else {           cout <<  . ;         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct yts {     int v[300010], ne[2 * 300010], x[2 * 300010], y[2 * 300010];     bool val[2 * 300010];     int num;     void put(int s, int t) {       num++;       x[num] = s;       y[num] = t;       ne[num] = v[s];       v[s] = num;     }   } e1, e2;   int q[300010];   bool vis[300010];   char dir[300010];   int S, n, m, undir;   char ty(int x) { return (x & 1) ?  -  :  + ; }   void bfs(int type) {     int h = 0, w = 1;     q[1] = S;     vis[S] = 1;     while (h != w) {       int x = q[++h];       for (int i = e2.v[x]; i; i = e2.ne[i]) {         if (!dir[i >> 1]) {           if (type == 1)             e2.val[i] = 1, e2.val[i ^ 1] = 0, dir[i >> 1] = ty(i);           else             e2.val[i] = 0, e2.val[i ^ 1] = 1, dir[i >> 1] = ty(i ^ 1);         }       }       for (int i = e2.v[x]; i; i = e2.ne[i])         if (e2.val[i]) {           int y = e2.y[i];           if (!vis[y]) vis[y] = 1, q[++w] = y;         }       for (int i = e1.v[x]; i; i = e1.ne[i]) {         int y = e1.y[i];         if (!vis[y]) vis[y] = 1, q[++w] = y;       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans += vis[i];     printf( %d n , ans);     for (int i = 1; i <= undir; i++) putchar(dir[i] ? dir[i] :  + );     puts(  );     memset(vis, 0, sizeof(vis));     memset(dir, 0, sizeof(dir));     memset(e2.val, 0, sizeof(e2.val));   }   int main() {     scanf( %d%d%d , &n, &m, &S);     e2.num = 1;     for (int i = 1; i <= m; i++) {       int x, y, ty;       scanf( %d%d%d , &ty, &x, &y);       if (ty == 1)         e1.put(x, y);       else {         undir++;         e2.put(x, y);         e2.put(y, x);       }     }     bfs(1);     bfs(2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int INF = 1e17;   const long long fact_table = 800008;   double Pi = 3.1415926535897932384626;   priority_queue<long long> pql;   priority_queue<pair<long long, long long> > pqp;   priority_queue<long long, vector<long long>, greater<long long> > pqls;   long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};   long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};   char dir[] =  DRUL ;   long long mod = 998244353;   long long rui(long long number1, long long number2) {     if (number2 == 0) {       return 1;     } else {       long long number3 = rui(number1, number2 / 2);       number3 *= number3;       number3 %= mod;       if (number2 % 2 == 1) {         number3 *= number1;         number3 %= mod;       }       return number3;     }   }   long long gcd(long long number1, long long number2) {     if (number1 > number2) {       swap(number1, number2);     }     if (number1 == 0 || number1 == number2) {       return number2;     } else {       return gcd(number2 % number1, number1);     }   }   void YES(bool condition) {     if (condition) {       cout <<  YES             <<   n ;       ;     } else {       cout <<  NO             <<   n ;       ;     }     return;   }   void Yes(bool condition) {     if (condition) {       cout <<  Yes             <<   n ;       ;     } else {       cout <<  No             <<   n ;       ;     }     return;   }   long long fact[fact_table + 5], rfact[fact_table + 5];   void c3_init() {     fact[0] = rfact[0] = 1;     for (long long i = 1; i <= fact_table; i++) {       fact[i] = (fact[i - 1] * i) % mod;     }     rfact[fact_table] = rui(fact[fact_table], mod - 2);     for (long long i = fact_table; i >= 1; i--) {       rfact[i - 1] = rfact[i] * i;       rfact[i - 1] %= mod;     }     return;   }   long long c3(long long n, long long r) {     return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;   }   namespace NTT {   void DFT(long long m, long long root, vector<long long> &a, bool rev = false) {     long long N = a.size(), h = 0;     for (long long i = 0; 1 << i < N; i++) h++;     for (long long i = 0; i < N; i++) {       long long j = 0;       for (long long k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);       if (i < j) swap(a[i], a[j]);     }     for (long long i = 1; i < N; i *= 2) {       long long base = rui(root, (m - 1) / i / 2);       if (rev) base = rui(base, m - 2);       long long w = 1;       for (long long j = 0; j < i; j++) {         for (long long k = 0; k < N; k += i * 2) {           long long s = a[j + k], t = a[j + k + i] * w % m;           a[j + k + 0] = (s + t) % m;           a[j + k + i] = (s - t + m) % m;         }         w = w * base % m;       }     }     if (rev) {       long long tmp = rui(N, m - 2);       for (long long &v : a) v = v * tmp % m;     }   }   vector<long long> conv(long long _mod, long long root,                          const vector<long long> &a, const vector<long long> &b) {     long long s = 1, t = a.size() + b.size() - 1;     while (s < t) s *= 2;     vector<long long> F(s), G(s);     for (long long i = 0; i < (long long)a.size(); i++) F[i] = a[i];     for (long long i = 0; i < (long long)b.size(); i++) G[i] = b[i];     DFT(_mod, root, F);     DFT(_mod, root, G);     for (long long i = 0; i < s; i++) F[i] = (long long)F[i] * G[i] % _mod;     DFT(_mod, root, F, true);     return F;   }   };  // namespace NTT   long long n, m, num, sum, a, b, c, d, e, h, r, l, q;   long long k;   long long white[500005], red[500005];   long long ans[500005];   long long query[500005];   int main() {     cin >> n >> k;     c3_init();     for (long long i = 0; i < n; i++) {       cin >> white[i];     }     for (long long i = 0; i < k; i++) {       cin >> red[i];     }     cin >> q;     for (long long i = 0; i < q; i++) {       cin >> query[i];     }     sort(white, white + n);     reverse(white, white + n);     long long cnt = 1;     vector<pair<long long, long long> > table;     for (long long i = 0; i < n; i++) {       if (white[i] != white[i + 1] || i == n - 1) {         table.push_back(pair<long long, long long>(white[i], cnt));         cnt = 1;       } else {         cnt++;       }     }     for (long long i = 0; i < k; i++) {       long long a = 0, b = 0;       for (long long j = 0; j < table.size(); j++) {         if (table[j].first >= red[i]) continue;         if (table[j].second >= 2) b++;         if (table[j].second == 1) a++;       }       vector<long long> atable, btable;       for (long long j = 0; j <= a; j++) {         long long tmp = c3(a, j) * rui(2, j);         tmp %= mod;         atable.push_back(tmp);       }       for (long long j = 0; j <= 2 * b; j++) {         long long tmp = c3(2 * b, j);         btable.push_back(tmp);       }       auto res = NTT::conv(mod, 3ll, atable, btable);       for (long long j = 0; j < q; j++) {         long long cnt = query[j] / 2 - red[i] - 1;         if (cnt < 0) continue;         if (cnt > a + b * 2) continue;         ans[j] += res[cnt];         ans[j] %= mod;       }     }     for (long long i = 0; i < q; i++) {       cout << ans[i] <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 1000001;     for (int i = 0; i < n; i++) cout << ans + i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 0x3f3f3f3f3f3f3f3fll;   const int LGN = 25;   const int MOD = 1e9 + 7;   const int N = 3e5 + 5;   int n, a[N], m, l[N], r[N];   int mem[N * LGN], cnt;   int* alloc(int x) {     int* p = mem + cnt;     cnt += x;     return p;   }   struct {     int* a;     int ans;   } st[4 * N];   void build(int p = 1, int L = 1, int R = n) {     if (R < L) return;     if (L == R) {       st[p].a = alloc(1);       st[p].a[0] = ::a[L];       st[p].ans = oo;       return;     }     int m = (L + R) >> 1;     build(2 * p, L, m), build(2 * p + 1, m + 1, R);     st[p].a = alloc(R - L + 1);     int* lf = st[2 * p].a;     int* ri = st[2 * p + 1].a;     merge(lf, lf + (m - L + 1), ri, ri + (R - m), st[p].a);     st[p].ans = oo;     for (long long i = 1, __R = R - L; i <= __R; i++)       st[p].ans = min(st[p].ans, st[p].a[i] - st[p].a[i - 1]);   }   int query(int l, int r, int p = 1, int L = 1, int R = n);   void update(int i, int v, int& d, int p = 1, int L = 1, int R = n) {     if (R < L || i < L || R < i) return;     if (L == R) {       st[p].ans = min(st[p].ans, abs(st[p].a[0] - v));       d = min(d, st[p].ans);       return;     }     int j = upper_bound(st[p].a, st[p].a + (R - L + 1), v) - st[p].a;     if ((j == 0 || d <= v - st[p].a[j - 1]) &&         (j == R - L + 1 || d <= st[p].a[j] - v)) {       d = min(d, query(L, i, p, L, R));       return;     }     int m = (L + R) >> 1;     if (i <= m)       update(i, v, d, 2 * p, L, m);     else {       update(i, v, d, 2 * p + 1, m + 1, R);       update(m, v, d, 2 * p, L, m);     }     st[p].ans = min(st[p].ans, min(st[2 * p].ans, st[2 * p + 1].ans));   }   int query(int l, int r, int p, int L, int R) {     if (R < L || r < L || R < l) return oo;     if (l <= L && R <= r) return st[p].ans;     int m = (L + R) >> 1;     return min(query(l, r, 2 * p, L, m), query(l, r, 2 * p + 1, m + 1, R));   }   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &(n));     for (long long i = 1, __R = n; i <= __R; i++) scanf( %d , &(a[i]));     build();     scanf( %d , &(m));     static int idx[N];     for (long long i = 1, __R = m; i <= __R; i++)       scanf( %d%d , &(l[i]), &(r[i])), idx[i] = i;     sort(idx + 1, idx + m + 1, [](int i, int j) { return r[i] < r[j]; });     int curr = 1;     static int ans[N];     for (long long j = 1, __R = m; j <= __R; j++) {       int i = idx[j];       while (curr < r[i]) {         curr++;         int d = oo;         update(curr - 1, a[curr], d);       }       ans[i] = query(l[i], r[i]);     }     for (long long i = 1, __R = m; i <= __R; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10004;   int v[MAXN];   int solve(int x, int y) {     if (x == y) return 0;     int mid = (x + y) >> 1;     int left = 0, right = 0;     for (int i = x; i < mid + 1; ++i) left = max(left, v[i]);     for (int i = mid + 1; i < y + 1; ++i) right = max(right, v[i]);     return abs(right - left) + solve(x, mid) + solve(mid + 1, y);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     while (cin >> n) {       memset(v, 0, sizeof v);       int m = (1 << (n + 1)) - 1;       for (int i = 0; i < m - 1; ++i) {         int x;         cin >> x;         int u = i + 2;         int p = (u) >> 1;         v[u] = v[p] + x;       }       cout << solve(1 << n, m) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, j = 1, a, b, c, d, maxi = -1;     cin >> n;     cin >> a >> b >> c >> d;     maxi = a + b + c + d;     for (int i = 2; i <= n; i++) {       cin >> a >> b >> c >> d;       if (a + b + c + d > maxi) {         j++;       }     }     cout << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 998244353;   const long long N = 3e5;   long long fact[N + 1];   int32_t main() {     clock_t clk = clock();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = 1;     for (long long i = 1; i <= N; i++) {       fact[i] = (fact[i - 1] * i) % p;     }     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (auto &it : a) cin >> it.first >> it.second;     map<long long, vector<long long> > byA;     map<long long, vector<long long> > byB;     long long ans = 0;     long long temp;     for (pair<long long, long long> pa : a) {       byA[pa.first].push_back(pa.second);     }     temp = 1;     for (auto pa : byA) {       temp = (temp * fact[pa.second.size()]) % p;     }     ans = (ans + temp) % p;     for (pair<long long, long long> pa : a) {       byB[pa.second].push_back(pa.first);     }     temp = 1;     for (auto pa : byB) {       temp = (temp * fact[pa.second.size()]) % p;     }     ans = (ans + temp) % p;     bool isPossible = 1;     for (auto it = byA.begin(); it != byA.end(); it++) {       sort(it->second.begin(), it->second.end());       if (it == byA.begin()) continue;       auto it2 = it;       --it2;       long long v1 = it2->second.back();       long long v2 = it->second[0];       if (v2 < v1) {         isPossible = 0;         break;       }     }     temp = 0;     if (isPossible) {       temp = 1;       for (auto pa : byA) {         long long m = pa.second.size();         vector<long long> isLand;         long long c = 1;         long long flag = pa.second[0];         for (long long i = 1; i < m; i++) {           if (flag == pa.second[i])             c++;           else {             isLand.push_back(c);             c = 1;             flag = pa.second[i];           }         }         if (c) isLand.push_back(c);         long long temp3 = 1;         for (long long x : isLand) {           temp3 = (temp3 * fact[x]) % p;         }         temp = (temp * temp3) % p;       }       ans = (ans + p - temp) % p;     }     long long total = fact[n];     total = (total + p - ans) % p;     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct tree {     queue<int> a;   };   tree num[100005];   long long apple[100005];   int beg = 1;   void dfs(int nn, int beg) {     if (num[nn].a.empty()) return;     while (!num[nn].a.empty()) {       int n1 = num[nn].a.front();       num[nn].a.pop();       apple[beg + 1]++;       dfs(n1, beg + 1);     }   }   int main() {     int number;     cin >> number;     int num1;     memset(apple, 0, sizeof(apple));     apple[1] = 1;     for (int i = 2; i <= number; i++) {       cin >> num1;       num[num1].a.push(i);     }     long long ans = 0;     dfs(1, beg);     for (int i = 1; i <= number; i++) {       if (apple[i] % 2 != 0) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2e5 + 10;   int n, k, a, b, q, i;   int tip, d, p, lll;   pair<int, int> arb[4 * Nmax];   void update(int nod, int st, int dr, int val, int poz) {     if (st >= dr) {       arb[nod].first = min(b, arb[nod].first + val);       arb[nod].second = min(a, arb[nod].second + val);       return;     }     int mij = (st + dr) >> 1;     if (poz <= mij)       update((nod << 1), st, mij, val, poz);     else       update(((nod << 1) | 1), mij + 1, dr, val, poz);     arb[nod].first = arb[(nod << 1)].first + arb[((nod << 1) | 1)].first;     arb[nod].second = arb[(nod << 1)].second + arb[((nod << 1) | 1)].second;   }   int query(int nod, int st, int dr, int a, int b, int r) {     if (a <= st && dr <= b)       if (r == 0)         return arb[nod].first;       else         return arb[nod].second;     int mij = (st + dr) >> 1;     int val1 = (a <= mij) ? query((nod << 1), st, mij, a, b, r) : 0;     int val2 = (mij < b) ? query(((nod << 1) | 1), mij + 1, dr, a, b, r) : 0;     return val1 + val2;   }   int main() {     scanf( %d %d , &n, &k);     scanf( %d %d , &a, &b);     scanf( %d , &q);     for (i = 1; i <= q; ++i) {       scanf( %d , &tip);       if (tip == 1) {         scanf( %d %d , &d, &p);         update(1, 1, n, p, d);       } else {         scanf( %d , &lll);         int v = 0;         if (lll > 1) v += query(1, 1, n, 1, lll - 1, 0);         if (lll + k <= n) v += query(1, 1, n, lll + k, n, 1);         printf( %d n , v);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string l;     cin >> l;     sort(l.begin(), l.end());     int a = 0, ans = 0;     char p = l[0];     for (;;) {       if (l[0] == p) {         a++;         l.erase(l.begin());       } else {         ans = max(ans, a);         if (l.size() > 0) {           p = l[0];           a = 0;         } else           break;       }     }     if (ans > k)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   const int mx = 500010;   int n, m, k, a[1010], c[1010], ans, sum;   int jud[mx];   set<int> s[mx];   set<int>::iterator it;   vector<int> vc[mx];   void dfs(int y, int pre) {     vector<int> v;     if (pre == -1) {       int t = 1;       for (it = s[y].begin(); it != s[y].end(); it++) {         jud[*it] = t++;         sum = max(sum, t - 1);       }     } else {       for (it = s[y].begin(); it != s[y].end(); it++) {         if (jud[(*it)]) v.push_back(jud[(*it)]);       }       int vn = v.size();       sort(v.begin(), v.end());       int f = 0, t = 1;       for (it = s[y].begin(); it != s[y].end(); it++) {         if (!jud[(*it)]) {           while (f < vn && v[f] == t) {             f++;             t++;           }           jud[(*it)] = t++;         }         sum = max(sum, t - 1);       }     }     int nm = vc[y].size();     for (int i = 0; i < nm; i++) {       int vyi = vc[y][i];       if (vyi != pre) dfs(vyi, y);     }   }   int dxy[8] = {1, 0, -1, 0, 0, 1, 0, -1};   int main() {     ios::sync_with_stdio(false);     int t, i, j, l, q, x, y, ss;     int cas = 1, flag;     cin >> n >> m;     {       l = max(n, m);       for (i = 0; i <= l; i++) {         vc[i].clear();         jud[i] = 0;       }       sum = 1;       for (i = 1; i <= n; i++) {         cin >> ss;         for (j = 0; j < ss; j++) {           cin >> x;           s[i].insert(x);         }       }       for (i = 0; i < n - 1; i++) {         cin >> x >> y;         vc[x].push_back(y);         vc[y].push_back(x);       }       dfs(1, -1);       cout << sum << endl;       for (i = 1; i <= m; i++) {         if (jud[i])           cout << jud[i];         else           cout <<  1 ;         if (i != m)           cout <<    ;         else           cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w[101], i, j, S, Sum, k, C, a, t;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &k);       for (j = 1; j <= k; j++) {         scanf( %d , &a);         Sum += a;         t = j * 2 - k;         if (t == 1)           w[C++] = -a;         else if (t <= 0)           S += a;       }     }     sort(w, w + C);     for (i = 0; i < C; i += 2) S -= w[i];     printf( %d %d n , S, Sum - S);   }