#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     bool neg = false;     cin >> s;     int n = s.length();     if (s[0] ==  - ) {       neg = true;       n--;     }     int cur = 0;     if (n < 3)       cur = 1;     else if (n == 3)       if ((!neg && s <=  127 ) || (neg && s <=  -128 ))         cur = 1;       else         cur = 2;     else if (n < 5)       cur = 2;     else if (n == 5)       if ((!neg && s <=  32767 ) || (neg && s <=  -32768 ))         cur = 2;       else         cur = 3;     else if (n < 10)       cur = 3;     else if (n == 10)       if ((!neg && s <=  2147483647 ) || (neg && s <=  -2147483648 ))         cur = 3;       else         cur = 4;     else if (n < 19)       cur = 4;     else if (n == 19)       if ((!neg && s <=  9223372036854775807 ) ||           (neg && s <=  -9223372036854775808 ))         cur = 4;       else         cur = 5;     else       cur = 5;     if (cur == 1)       cout <<  byte  << endl;     else if (cur == 2)       cout <<  short  << endl;     else if (cur == 3)       cout <<  int  << endl;     else if (cur == 4)       cout <<  long  << endl;     else       cout <<  BigInteger  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mp[2005];   int main() {     memset(mp, 0, sizeof mp);     long long key[2001], a[2001], n, k, p, i, j;     cin >> n >> k >> p;     for (i = 0; i < n; i++) {       scanf( %lld , a + i);     }     for (i = 0; i < k; i++) {       scanf( %lld , key + i);     }     sort(a, a + n);     sort(key, key + k);     long long mn = 1e18;     for (i = 0; i < k - n + 1; i++) {       long long x = -1;       for (int j = i, l = 0; l < n; l++, j++) {         long long y = abs(a[l] - key[j]) + abs(p - key[j]);         x = max(y, x);       }       mn = min(x, mn);     }     cout << mn;   }


#include <bits/stdc++.h>   using namespace std;   long long n, N, m, op, w, ax, ay, bx, by, cx, cy, ix, iy, bit[4][505][505];   long long v(long long x) {     if (x & 1)       return (x >> 1) + 1;     else       return x >> 1;   }   long long P(long long x, long long y) {     if ((x & 1) && (y & 1)) return 0;     if ((x & 1) && !(y & 1)) return 1;     if (!(x & 1) && (y & 1)) return 2;     if (!(x & 1) && !(y & 1)) return 3;   }   long long lowbit(long long x) { return x & (-x); }   void add(long long x, long long y, long long w) {     long long i, j, k = P(x, y);     ix = v(x);     iy = v(y);     for (i = ix; i <= N; i += lowbit(i))       for (j = iy; j <= N; j += lowbit(j)) bit[k][i][j] ^= w;   }   long long get(long long x, long long y) {     if (x == 0 || y == 0) return 0;     long long i, j, k = P(x, y), ret = 0;     ix = v(x);     iy = v(y);     for (i = ix; i; i -= lowbit(i))       for (j = iy; j; j -= lowbit(j)) ret ^= bit[k][i][j];     return ret;   }   signed main() {     long long i, j;     scanf( %lld%lld , &n, &m);     N = v(n);     while (m--) {       scanf( %lld%lld%lld%lld%lld , &op, &ax, &ay, &bx, &by);       if (op == 1)         printf( %lld n , get(bx, by) ^ get(ax - 1, by) ^ get(bx, ay - 1) ^                              get(ax - 1, ay - 1));       else {         scanf( %lld , &w);         add(ax, ay, w);         add(bx + 1, ay, w);         add(ax, by + 1, w);         add(bx + 1, by + 1, w);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long poww(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * poww(a * a % md, b / 2, md) % md                         : poww(a * a % md, b / 2, md) % md));   }   const long long MAXN = 1e5 + 10;   const long long INF = 8e18;   const long long MOD = 1e9 + 7;   set<pair<long long, long long> > st;   set<long long> lst[MAXN], rst[MAXN], ust[MAXN], dst[MAXN];   long long n, m, k;   int main() {     cin >> n >> m >> k;     long long u = 0, d = n + 1, l = 0, r = m + 1;     for (int i = 0; i < k; i++) {       long long x, y;       cin >> x >> y;       st.insert({x, y});       dst[y].insert(x);       ust[y].insert(-x);       rst[x].insert(y);       lst[x].insert(-y);     }     long long dir = 0, cnt = 0;     while (u + 1 < d && l + 1 < r) {       if (dir == 0) {         u++;         auto it = rst[u].lower_bound(l + 1);         if (it != rst[u].end()) r = min(*it, r);         cnt += r - l - 1;       } else if (dir == 1) {         r--;         auto it = dst[r].lower_bound(u + 1);         if (it != dst[r].end()) d = min(*it, d);         cnt += d - u - 1;       } else if (dir == 2) {         d--;         auto it = lst[d].lower_bound(-1 * (r - 1));         if (it != lst[d].end()) l = max(-1 * (*it), l);         cnt += r - l - 1;       } else if (dir == 3) {         l++;         auto it = ust[l].lower_bound(-1 * (d - 1));         if (it != ust[l].end()) u = max(-1 * (*it), u);         cnt += d - u - 1;       }       dir++;       dir %= 4;     }     if (cnt == n * m - k) return cout <<  Yes  <<   n , 0;     cout <<  No  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, a[3333];     int t, n;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long x;       x = a[0] * a[n - 1];       int flag = 1, ans = 0;       for (i = 0; i < n; i++) {         if (x % a[i] != 0) flag = 0;       }       if (flag) {         for (i = 2; i <= sqrt(x); i++) {           if (x % i == 0) {             if (x == i * i)               ans++;             else               ans += 2;           }         }       }       if (flag && ans == n)         cout << x << endl;       else         cout <<  -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> cost[111111];   bool okay[111111];   int main(void) {     int n = 0;     int k = 0;     scanf( %d %d , &n, &k);     long long b = 0;     scanf( %I64d , &b);     for (int i = 0; i < n; i++) {       scanf( %d , &cost[i].first);       cost[i].second = i;     }     cost[n - 1].first = 0;     sort(cost, cost + n);     reverse(cost, cost + n);     long long sum = 0;     for (int i = 0; i < k; i++) {       sum += cost[i].first;       okay[cost[i].second] = true;     }     int last = cost[k - 1].first;     for (int i = 0; i < n; i++) swap(cost[i].first, cost[i].second);     sort(cost, cost + n);     int ans = -1;     if (sum <= b) {       ans = n - 1;     } else {       sum -= last;       for (int i = 0; i < n; i++) {         if (okay[i] || sum + cost[i].second > b) {           ans = i;           break;         }       }     }     printf( %d n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXSZ = 100000;   int req[MAXSZ];   int prob[MAXSZ];   int main(int argc, const char* argv[]) {     int n, m, k;     scanf( %d%d , &n, &m);     int count = 1;     for (int i = 0; i < m; i++) {       scanf( %d , &k);       prob[k]++;       req[prob[k]]++;       if (req[count] == n) {         cout << 1;         count++;       } else {         cout << 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, long long int> m;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long int x = 0, y = n - 1, iff = 1;       vector<long long int> v;       for (long long int i = 0; i < n; i++) {         if (iff) {           v.push_back(a[y]);           y--;           iff = 0;         } else {           v.push_back(a[x]);           x++;           iff = 1;         }       }       for (long long int i = n - 1; i >= 0; i--) cout << v[i] <<    ;       cout << endl;     }   }


#include<iostream>   #include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   ll max(ll a,ll b){       if(a>b)return a;       return b;   }   int main(){       int T;       cin>>T;       while(T--){           int n,k;           cin>>n>>k;           string s1,s2;           cin>>s1;           cin>>s2;           vector<int>c1(26,0),c2(26,0);           for(int i=0;i<s1.length();i++){               c1[s1[i]- a ]++;           }           for(int i=0;i<s2.length();i++){               c2[s2[i]- a ]++;           }           for(int i=0;i<26;i++){               if(c1[i]==c2[i]){                  c1[i]=0;                  c2[i]=0;               }               else if(c1[i]<c2[i]){                   c2[i]-=c1[i];                   c1[i]=0;               }               else{                   c1[i]-=c2[i];                   c2[i]=0;               }           }           int f=0;           int j=25;int i=25;           while(j>=0 && i>=0){               if(c1[i]==0){                  i--;                  continue;               }               if(c2[j]==0){                  j--;                  continue;               }               if(i>j){                  f=1;                  break;               }                         if(c1[i]%k!=0){                  f=1;                  break;              }               if(c2[j]%k!=0){                  f=1;                  break;               }               if(c1[i]==c2[j]){                  c1[i]=0;                  c2[j]=0;                  i--;                  j--;                                 }               else if(c1[i]>c2[j]){                  c1[i]-=c2[j];                  j--;               }               else{                  c2[j]-=c1[i];                  i--;               }           }           if(f==1)           cout<< NO <<endl;           else           cout<< YES <<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char c = getchar();     int d = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; d = d * 10 + c - 48, c = getchar())       ;     return d * f;   }   const int mod = 1e9 + 7;   const int N = 3000010;   int n, q, ft[N + 1], Ft[N + 1], ans[N + 1];   int mi(int a, int b) {     int s = 1;     for (; b; b >>= 1, a = (long long)a * a % mod)       if (b & 1) s = (long long)s * a % mod;     return s;   }   int main() {     n = read(), q = read();     int maxn = n * 3 + 1;     ft[0] = 1;     for (int i = 1; i <= maxn; ++i) ft[i] = 1LL * ft[i - 1] * i % mod;     Ft[maxn] = mi(ft[maxn], mod - 2);     for (int i = maxn; i >= 1; --i) Ft[i - 1] = 1LL * Ft[i] * i % mod;     long long y0 = (3LL * (n + 1) * n / 2) % mod, y1 = (y0 + mod - n * 2) % mod,               y2 = (y0 + mod - n) % mod, ni3 = mi(3, mod - 2);     ans[1] = y0;     for (int i = 2; i <= n * 3; ++i) {       long long sum = 1LL * ft[maxn] * Ft[i + 1] % mod * Ft[maxn - 1 - i] % mod;       long long x1 = (sum - y1 - y1 - y2) * ni3 % mod;       if (x1 < 0) x1 += mod;       long long x2 = (x1 + y1);       if (x2 >= mod) x2 -= mod;       long long x0 = (x2 + y2);       if (x0 >= mod) x0 -= mod;       y0 = x0, y1 = x1, y2 = x2;       ans[i] = x0;     }     for (int i = 1; i <= q; ++i) {       int x = read();       printf( %d n , ans[x]);     }   }


#include <bits/stdc++.h>   using namespace std;   inline int mini(int a, int b) { return a < b ? a : b; }   inline int maxi(int a, int b) { return a > b ? a : b; }   int main() {     int n;     scanf( %d , &n);     int *a = new int[n];     int najm = 1000000010;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       najm = mini(najm, a[i]);     }     vector<int> vec;     for (int i = 0; i < n; i++) {       if (a[i] == najm) {         vec.push_back(i);       }     }     int najv = 0;     for (int i = 0; i < vec.size() - 1; i++) {       najv = maxi(najv, vec[i + 1] - vec[i] - 1);     }     najv = maxi(najv, n - 1 - vec[vec.size() - 1] + vec[0]);     long long res = ((long long)najm) * (long long)n + (long long)najv;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   void setIO(string name) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin.exceptions(istream::failbit);   }   const int inf = 0x3f3f3f3f, mod = 1e9 + 7;   int main() {     setIO( 1 );     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int sol = 0, j = 0, used = 0;     pair<int, int> inter;     for (int i = 0; i < n; ++i, j = max(j, i)) {       if (used < 0) {         used = 0;       }       while (j < n) {         if (used + !a[j] > k) {           break;         }         if (a[j++] == 0) {           ++used;         }       }       if (j - i > sol) {         sol = j - i;         inter = {i, j};       }       if (a[i] == 0) {         --used;       }     }     cout << sol <<   n ;     for (int i = 0; i < inter.first; ++i) {       cout << a[i] <<    ;     }     for (int i = inter.first; i < inter.second; ++i) {       cout << 1 <<    ;     }     for (int i = inter.second; i < n; ++i) {       cout << a[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 80009;   unsigned long long n;   vector<int> adj[inf];   unsigned long long low[inf];   unsigned long long sl[inf];   unsigned long long sz[inf];   unsigned long long als;   unsigned long long ans = 0;   void dfs(int x, int p) {     unsigned long long s = 0;     int k;     unsigned long long tr = 0, fr = 0;     for (int i = 0; i < adj[x].size(); ++i) {       k = adj[x][i];       if (k == p) continue;       dfs(k, x);       sl[x] += sl[k];       fr += sz[k] * tr;       tr += sz[k] * low[x];       low[x] += sz[k] * sz[x];       sz[x] += sz[k];     }     fr += (n - sz[x] - 1) * tr;     tr += (n - sz[x] - 1) * low[x];     ans += (fr + tr) * 6 + ((n - sz[x] - 1) * sz[x] + low[x]) * 2;     low[x] += sz[x];     low[x] += low[x] + 1;     sl[x] += low[x];     sz[x]++;   }   void solve(int x, int p) {     ans += (als - sl[x]) * low[x];     als -= low[x];     unsigned long long g = low[x] / 2 + (n - sz[x]) * sz[x];     int k;     for (int i = 0; i < adj[x].size(); ++i) {       k = adj[x][i];       if (k == p) continue;       ans += sl[k] * ((g - sz[k] * (n - sz[k])) * 2 + 1);       solve(k, x);     }   }   int main() {     int a, b;     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 1);     als = sl[1];     solve(1, 1);     unsigned long long all = (n * (n - 1)) / 2;     all = all * all;     printf( %I64d n , all - ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[200000];   int color[200000], black, white, maxDist, farNode;   void solve(int node, int par, int dis) {     if (dis > maxDist) farNode = node, maxDist = dis;     for (auto &v : graph[node]) {       if (v == par) continue;       solve(v, node, dis + (color[node] != color[v]));     }   }   int main() {     ios ::sync_with_stdio(false);     cin.tie();     int n, a, b, firstNode;     cin >> n;     for (int i = 0; i < n; i++) cin >> color[i];     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       a--, b--;       graph[a].push_back(b);       graph[b].push_back(a);     }     solve(0, -1, 1);     maxDist = 1;     solve(farNode, -1, 1);     cout << (maxDist) / 2;     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int maxn = 3e3 + 50;   const int Mod = 1000000007;   const double PI = acos(-1);   using namespace std;   struct Ans {     int id, x;     string ret;   };   Ans ans[maxn];   string v[maxn];   int cnt;   bool full;   int n;   inline bool cmpById(const Ans &a, const Ans &b) { return a.id < b.id; }   inline bool cmpByX(const Ans &a, const Ans &b) { return a.x < b.x; }   bool cmpByLen(const string &a, const string &b) { return a.size() > b.size(); }   void expend(int dem, int len) {     if (full) return;     while (1) {       int sz = cnt;       for (int i = sz - 1; i >= 0; i--) {         v[cnt++] = v[i] +  0 ;         v[i] = v[i] +  1 ;       }       if (cnt >= dem) full = true;       sort(v, v + cnt, cmpByLen);       if (full || v[cnt - 1].size() == len) return;     }   }   bool solve() {     v[cnt++] =  0 ;     v[cnt++] =  1 ;     for (int i = 0; i < n; i++) {       int tar = ans[i].x;       if (cnt == 0) return false;       if (v[cnt - 1].size() < tar) expend(n - i, tar);       if (full) {         v[cnt - 1] = v[cnt - 1] + string(tar - v[cnt - 1].size(),  1 );       }       ans[i].ret = v[cnt - 1];       cnt--;     }     return true;   }   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) {         ans[i].id = i;         scanf( %d , &ans[i].x);       }       cnt = 0;       full = false;       sort(ans, ans + n, cmpByX);       if (solve()) {         puts( YES );         sort(ans, ans + n, cmpById);         for (int i = 0; i < n; i++) puts(ans[i].ret.c_str());       } else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[100010];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int ans = 0;     int re = 0;     for (int i = 0; i < n; i++) {       int t = 1;       while (a[i + 1] == a[i] && (i < n - 1)) {         t += 1;         i += 1;       }       if (i == n - 1) {         cout << ans;         return 0;       } else if (i == n - 2) {         cout << ans + 1;         return 0;       }       re = max(re, i + 1);       if (t < (n - re)) {         re += t;         ans += t;       } else if (t == n - re) {         ans += t;         cout << ans;         return 0;       } else {         ans += (n - re);         cout << ans;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, z;     std::cin >> n >> m >> z;     int counter = 0;     for (int i = 1; i * n <= z; i++) {       if ((i * n) % m == 0) counter++;     }     std::cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const double eps = 1e-6;   int n, k, q, m;   int a[N], b[N], used[N];   double MinAns = 100.0, MaxAns = 0.0;   double max(double x, double y) { return x - eps >= y ? x : y; }   double min(double x, double y) { return x + eps <= y ? x : y; }   void init() {     scanf( %d %d , &n, &k);     m = n / k;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);   }   void work() {     int x, sum, cnt;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       sum = 0;       for (int j = 1; j <= m; j++) {         scanf( %d , &x);         used[x] = 1;         sum += a[x];       }       MinAns = min(MinAns, 1.0 * sum / m);       MaxAns = max(MaxAns, 1.0 * sum / m);     }     cnt = 0;     for (int i = 1; i <= n; i++)       if (!used[i]) b[++cnt] = a[i];     sort(b + 1, b + 1 + cnt);     if (cnt >= m && n - cnt < k * m) {       sum = 0;       for (int i = 1; i <= m; i++) sum += b[i];       MinAns = min(MinAns, 1.0 * sum / m);       sum = 0;       for (int i = cnt; i > cnt - m; i--) sum += b[i];       MaxAns = max(MaxAns, 1.0 * sum / m);     }     printf( %.10lf %.10lf n , MinAns, MaxAns);   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   int i, n, k, a, s, j;   int main() {     for (std::cin >> n >> k; i < k; i++)       std::cin >> a, a % 2 ? a++, j++ : 0, s += a;     std::cout << (s > 8 * n || s == 8 * n && k == 4 * n && j < n ?  NO  :  YES );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, i;     cin >> n;     string s;     cin >> s;     int k = 1;     for (i = 0; i < n; i++) {       if (s[i] ==  1  && k == 1) {         sum++;       } else if (s[i] ==  0  && k == 1) {         sum++;         k = 0;       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     short negative = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) negative = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     x *= negative;   }   inline void write(long long x) {     static long long sta[35];     long long top = 0;     do {       sta[top++] = x % 10, x /= 10;     } while (x);     while (top) putchar(sta[--top] + 48);     puts(  );   }   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   vector<long long> v;   int n;   void w(string s) {     v.push_back(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==     || s[i] ==  - ) v.push_back(i + 1);     }     v.push_back(s.size());   }   bool check(int mid) {     int len = 0, g = 1;     for (int i = 1; i < v.size(); i++) {       if (v[i] - v[i - 1] > mid) return 0;       if (len + (v[i] - v[i - 1]) <= mid)         len += (v[i] - v[i - 1]);       else {         g++;         len = v[i] - v[i - 1];       }     }     return g <= n;   }   int main() {     read(n);     char s[1000010];     gets(s);     w(s);     int l = 1, r = 1e6, res = 1e5;     while (l <= r) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid - 1;       else {         l = mid + 1;       }     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, a, b, signo, dist, centro;   vector<pair<long long int, long long int> > distancias;   vector<long long int> izq, der;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     a = 1;     b = 2;     for (int i = (3); i <= (n); i++) {       cout <<  2   << a <<     << b <<     << i << endl;       cin >> signo;       if (signo > 0) b = i;     }     for (int i = (1); i <= (n); i++) {       if (i == a || i == b) continue;       cout <<  1   << a <<     << b <<     << i << endl;       cin >> dist;       distancias.push_back({-dist, i});     }     sort(distancias.begin(), distancias.end());     centro = 0;     for (auto d : distancias) {       if (centro == 0) {         centro = d.second;         continue;       }       cout <<  2   << a <<     << centro <<     << d.second << endl;       cin >> signo;       if (signo > 0)         izq.push_back(d.second);       else         der.push_back(d.second);     }     reverse(der.begin(), der.end());     cout <<  0   << a <<    ;     for (auto n : der) cout << n <<    ;     cout << centro <<    ;     for (auto n : izq) cout << n <<    ;     cout << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char x =   0 ;     int fh = 1, sum = 0;     for (x = getchar(); x <  0  || x >  9 ; x = getchar())       if (x ==  - ) fh = -1;     for (; x >=  0  && x <=  9 ; x = getchar()) sum = sum * 10 + x -  0 ;     return fh * sum;   }   const int N = 1e5 + 9;   int fa[N], ch[N][2], sz[N];   long long A[N], B[N], val[N];   int n, a, rt, cnt;   inline long long pd(int x) { return ch[fa[x]][1] == x; }   inline void pushup(int x) {     int ls = ch[x][0], rs = ch[x][1];     sz[x] = sz[ls] + sz[rs] + 1;   }   inline void modify(int x, long long a, long long b) {     val[x] += a * (sz[ch[x][0]] + 1) + b;     A[x] += a, B[x] += b;   }   inline void pushdown(int x) {     if (A[x] || B[x]) {       if (ch[x][0]) modify(ch[x][0], A[x], B[x]);       if (ch[x][1]) modify(ch[x][1], A[x], B[x] + A[x] * (sz[ch[x][0]] + 1));       A[x] = B[x] = 0;     }   }   inline void rotate(int x) {     int y = fa[x], z = fa[y], kx = pd(x), ky = pd(y);     if (z) ch[z][ky] = x;     fa[x] = z, fa[y] = x, fa[ch[x][kx ^ 1]] = y;     ch[y][kx] = ch[x][kx ^ 1];     ch[x][kx ^ 1] = y;     pushup(y), pushup(x);     if (z) pushup(z);   }   inline void splay(int x) {     static int sta[N], tp;     sta[tp = 1] = x;     for (int y = x; fa[y]; y = fa[y]) sta[++tp] = fa[y];     while (tp) pushdown(sta[tp--]);     for (; fa[x]; rotate(x))       if (fa[fa[x]]) rotate((pd(x) ^ pd(fa[x])) ? x : fa[x]);     pushup(rt = x);   }   inline long long getv(int k) {     int x = rt;     while (1) {       if (sz[ch[x][0]] + 1 == k) {         splay(x);         return val[x];       }       if (sz[ch[x][0]] >= k)         x = ch[x][0];       else         k -= sz[ch[x][0]] + 1, x = ch[x][1];     }   }   inline long long getmx(int x) {     if (!x) return -1e18;     pushdown(x);     return std::max(val[x], std::max(getmx(ch[x][0]), getmx(ch[x][1])));   }   int main() {     n = read();     sz[1] = rt = cnt = 1;     for (register int i = 1, endi = n; i <= endi; ++i) {       int a = read();       int lp = 0, rp = i - 2, ans = i - 1;       while (lp <= rp) {         int mid = (lp + rp) >> 1;         if (getv(mid + 1) + (mid + 1LL) * a > getv(mid + 2))           rp = (ans = mid) - 1;         else           lp = mid + 1;       }       getv(ans + 1);       fa[++cnt] = rt, val[cnt] = val[rt], ch[cnt][1] = ch[rt][1];       fa[ch[rt][1]] = cnt;       ch[rt][1] = cnt;       modify(cnt, a, 1LL * a * ans);     }     printf( %lld n , getmx(rt));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k, a;     scanf( %d , &n);     vector<int> nums;     unordered_map<int, int> hashmap, sizes, parent, inp;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       nums.push_back(a);     }     sort(nums.begin(), nums.end());     int smin = -1, smin_pos = 0, res = 1;     for (int i = 0; i < n; i++) {       a = nums[i];       if (smin == -1) {         smin = a;         smin_pos = i;       } else {         if (a - smin <= 5) {           continue;         } else {           res = max(res, i - smin_pos);           while (a - nums[smin_pos] > 5 && smin_pos < i) smin_pos++;           smin = nums[smin_pos];         }       }     }     if (nums[n - 1] - smin <= 5) {       res = max(res, n - smin_pos);     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   int main() {     char str[100][100] = { January ,    February ,  March ,     April ,                            May ,        June ,      July ,      August ,                            September ,  October ,   November ,  December };     char month[100];     scanf(  %[^ n] , month);     int n;     scanf( %d , &n);     int index;     int i;     for (i = 0; i < 12; i++) {       if (strcmp(str[i], month) == 0) {         index = i;         break;       }     }     index = ((index) % 12 + n % 12) % 12;     printf( %s n , str[index]);   }


#include <bits/stdc++.h>   inline int read() {     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     int k = 0, kk = 1;     if (c ==  - ) c = getchar(), kk = -1;     while (c >=  0  && c <=  9 ) k = k * 10 + c -  0 , c = getchar();     return kk * k;   }   using namespace std;   void write(int x) {     if (x < 0) x = -x, putchar( - );     if (x / 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(int x) {     write(x);     puts(  );   }   int n, m, k, x[1000000], y[1000000], l[1000000], r[1000000], f[1000000];   struct lsg {     int x, y, d, bj;   } a[1000000], ff[1000000];   bool cmp1(lsg x, lsg y) { return x.d < y.d; }   bool cmp2(lsg x, lsg y) { return x.x < y.x; }   bool cmp3(lsg x, lsg y) { return x.y > y.y; }   bool pd(int kkk) {     int d = 0, dd = 0, ddd = 0;     memset(a, 0, sizeof(a));     for (int i = 1; i <= k; i++) {       a[++d].d = x[i] - kkk;       a[d].x = y[i] - kkk;       a[d].y = y[i] + kkk;       a[d].bj = i;       a[++d].d = x[i] + kkk + 1;       a[d].bj = -i;     }     a[++d].d = 1;     a[++d].d = n;     sort(a + 1, a + 1 + d, cmp1);     a[d + 1].d = -1e9;     for (int i = 1; i <= d; i++) {       if (a[i].bj > 0) {         ff[++dd].x = a[i].x;         ff[dd].y = a[i].y;         ff[dd].bj = a[i].bj;       } else if (a[i].bj < 0) {         int kk = 0;         for (int j = 1; j <= dd; j++)           if (ff[j].bj != -a[i].bj) ff[++kk] = ff[j];         dd = kk;       }       if (a[i].d != a[i + 1].d && a[i].d >= 1 && a[i].d <= n) {         sort(ff + 1, ff + 1 + dd, cmp2);         l[++ddd] = 1;         r[ddd] = m;         f[ddd] = a[i].d;         for (int j = 1; j <= dd; j++) {           if (l[ddd] >= ff[j].x) l[ddd] = max(l[ddd], ff[j].y + 1);         }         sort(ff + 1, ff + 1 + dd, cmp3);         for (int j = 1; j <= dd; j++) {           if (r[ddd] <= ff[j].y) r[ddd] = min(r[ddd], ff[j].x - 1);         }       }     }     int ll = 1, rr = ddd, lll = m, rrr = 1;     f[ddd + 1] = n;     f[ddd + 2] = n + 1;     while (l[ll] > r[ll] && ll <= rr) ll++;     while (l[rr] > r[rr] && ll <= rr) rr--;     if (f[rr + 1] - 1 - f[ll] > kkk * 2) return 0;     for (int i = ll; i <= rr; i++) lll = min(lll, l[i]), rrr = max(rrr, r[i]);     if (rrr - lll > kkk * 2) return 0;     return 1;   }   signed main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= k; i++) x[i] = read(), y[i] = read();     int l = 0, r = max(n, m);     while (l < r) {       int m = (l + r) / 2;       if (pd(m))         r = m;       else         l = m + 1;     }     cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int> Q[200];   int main() {     int n, k;     cin >> n >> k;     unsigned long long pr[200000];     for (int i = 0; i < n; i++) {       cin >> pr[i];     }     string str;     vector<unsigned long> vec[200];     unsigned long long sum = 0;     cin >> str;     for (int i = 0; i < n; i++) {       Q[str[i]].push(pr[i]);       if (str[i] != str[i - 1] && i > 0) {         int j = 0;         while (!Q[str[i - 1]].empty()) {           if (j <= k - 1) sum += Q[str[i - 1]].top();           Q[str[i - 1]].pop();           j++;         }       }     }     for (int i = 97; i <= 122; i++) {       int j = 0;       while (!Q[i].empty()) {         if (j > k - 1) break;         sum += Q[i].top();         Q[i].pop();         j++;       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[10][10], b[10][10];   struct per {     int x, y;   };   int k;   queue<per> q, q2;   void bf2() {     while (!q2.empty()) {       per aux;       aux = q2.front();       q2.pop();       int xx = aux.x - 1, yy = aux.y - 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x - 1, yy = aux.y;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x - 1, yy = aux.y + 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x, yy = aux.y - 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x, yy = aux.y + 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x + 1, yy = aux.y - 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x + 1, yy = aux.y + 1;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }       xx = aux.x + 1, yy = aux.y;       if (b[xx][yy] == 0) {         b[xx][yy] = b[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         q2.push(nou);       }     }   }   void bf1() {     while (!q.empty()) {       per aux;       aux = q.front();       q.pop();       int xx = aux.x - 1, yy = aux.y - 1;       while (a[xx][yy] == 0) {         a[xx][yy] = a[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         xx--;         yy--;         q.push(nou);       }       xx = aux.x - 1, yy = aux.y + 1;       while (a[xx][yy] == 0) {         a[xx][yy] = a[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         xx--;         yy++;         q.push(nou);       }       xx = aux.x + 1, yy = aux.y + 1;       while (a[xx][yy] == 0) {         a[xx][yy] = a[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         xx++;         yy++;         q.push(nou);       }       xx = aux.x + 1, yy = aux.y - 1;       while (a[xx][yy] == 0) {         a[xx][yy] = a[aux.x][aux.y] + 1;         per nou;         nou.x = xx;         nou.y = yy;         xx++;         yy--;         q.push(nou);       }     }   }   int main() {     int x1, x2, y1, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2 || y1 == y2)       cout << 1 <<    ;     else       cout << 2 <<    ;     int i;     for (i = 0; i <= 9; i++) {       a[i][0] = -1;       a[i][9] = -1;       a[0][i] = -1;       a[9][i] = -1;       b[i][0] = -1;       b[i][9] = -1;       b[0][i] = -1;       b[9][i] = -1;     }     per st;     st.x = x1;     st.y = y1;     q.push(st);     a[x1][y1] = 1;     bf1();     if (a[x2][y2])       cout << a[x2][y2] - 1;     else       cout << 0;     cout <<    ;     int j;     b[x1][y1] = 1;     q2.push(st);     bf2();     if (b[x2][y2])       cout << b[x2][y2] - 1;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   int N, K, D[MAX], S[MAX];   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < (int)N; i++) scanf( %d , &D[i]);     for (int i = 0; i < (int)N; i++) scanf( %d , &S[i]);     int res = 0;     int lho = S[0];     int pos = 0;     int fuel = 0;     while (pos != N) {       if (lho < S[pos]) lho = S[pos];       fuel += S[pos];       int rem = max(0, D[pos] - fuel);       int add = (rem + lho - 1) / lho;       res += add * K;       fuel += add * lho;       fuel -= D[pos];       res += D[pos];       pos++;     }     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const int MAX = 5e3 + 10;   const int MOD = 998244353;   long long fat[MAX], ifat[MAX];   long long choose(int a, int b) {     if (a < b) return 0;     return fat[a] * ifat[b] % MOD * ifat[a - b] % MOD;   }   long long fexp(long long a, long long e) {     long long ans = 1;     while (e) {       if (e & 1) ans = ans * a % MOD;       a = a * a % MOD;       e /= 2;     }     return ans;   }   void compute() {     fat[0] = 1;     ifat[0] = 1;     for (int i = 1; i < MAX; i++) {       fat[i] = i * fat[i - 1] % MOD;       ifat[i] = fexp(fat[i], MOD - 2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     compute();     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0 || count(s.begin(), s.end(),  1 ) < k) {       cout << 1 <<   n ;       return 0;     }     long long ans = 1;     for (int l = 0; l < n; l++) {       int cnt = 0, r = l;       while (r < n && cnt + (s[r] ==  1 ) <= k) cnt += s[r++] ==  1 ;       long long add = 0;       if (s[l] ==  0  && cnt > 0) add = choose((r - l) - 1, cnt - 1);       if (s[l] ==  1  && ((r - l) - cnt) > 0) add = choose((r - l) - 1, cnt);       ans = (ans + add) % MOD;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get() {     int f = 0, v = 0;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) break;     if (ch ==  - )       f = 1;     else       v = ch -  0 ;     while (isdigit(ch = getchar())) v = v * 10 + ch -  0 ;     if (f)       return -v;     else       return v;   }   const int maxn = 1003;   long long a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];   int n, m, k;   int main() {     n = get(), m = get();     k = get();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         a[i][j] = a[i - 1][j] + a[i][j - 1] + get() - a[i - 1][j - 1],         b[i][j] = b[i - 1][j + 1] + a[i][j] -                   (i > k && j + k <= m ? a[i - k][j + k] : 0),         c[i][j] =             c[i - 1][j - 1] + a[i][j] - (i > k && j > k ? a[i - k][j - k] : 0);       b[i][0] = b[i - 1][1] - (i > k ? a[i - k][k] : 0);     }     long long v = -1, t;     int x, y;     for (int i = k; i <= n - k + 1; i++)       for (int j = k; j <= m - k + 1; j++)         if ((t = b[i + k - 1][j] + b[i - 1][j - k] - c[i + k - 1][j - 1] -                  c[i - 1][j + k - 1]) > v)           v = t, x = i, y = j;     printf( %d %d n , x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1153][1153];   int n, m;   unsigned long long int b[1153][1153];   bool pos(int minval) {     memset(b, 0, sizeof(b));     int i, j, k;     for (i = 0; i < n; i++) {       int ccnt = 0;       for (j = 0; j < 1024; j += 63) {         unsigned long long int blk = 0;         for (k = j; k < j + 63; k++) {           blk <<= 1;           if (a[i][k] >= minval) {             blk |= 1;           }         }         b[i][j] = blk;       }       for (j = 0; j < i; j++) {         ccnt = 0;         for (k = 0; k < 1024; k += 63) {           unsigned long long int ret = (b[i][k] & b[j][k]);           if (ret != 0) {             if ((ret & (ret - 1)) == 0)               ccnt++;             else               return true;           }         }         if (ccnt >= 2) return true;       }     }     return false;   }   int main() {     int i, j;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf( %d , &a[i][j]);       }     }     int lb = 0, ub = 1000000004, mid, ans;     while (lb <= ub) {       mid = (lb + ub) / 2;       if (pos(mid)) {         lb = mid + 1;         ans = mid;       } else         ub = mid - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   int n, q;   int len[N];   vector<pair<int, int>> g[N];   double prob[N];   double sum;   int dfs(int v, int p) {     int size = 1;     for (auto e : g[v]) {       int to = e.first;       int ind = e.second;       int w = len[ind];       if (to == p) continue;       int A = dfs(to, v);       size += A;       int B = n - A;       double prob_nom = (long long)A * B * (B - 1) / 2;       prob_nom += (long long)B * A * (A - 1) / 2;       double prob_denom = (long long)n * (n - 1) * (n - 2) / 6;       prob[ind] = prob_nom / prob_denom;       sum += w * prob[ind];     }     return size;   }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       u--;       v--;       len[i] = w;       g[u].push_back(make_pair(v, i));       g[v].push_back(make_pair(u, i));     }     dfs(0, -1);     0;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int r, w;       scanf( %d%d , &r, &w);       r--;       double delta = w - len[r];       sum += delta * prob[r];       len[r] = w;       printf( %.10lf n , 2 * sum);     }   }   int main() {     solve();     0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ts;     cin >> ts;     while (ts--) {       int n;       cin >> n;       vector<int> v(n);       vector<int> pos[2];       for (int i = 0; i < n; i++) {         cin >> v[i];         pos[v[i]].push_back(i);       }       int x = 0;       if (pos[0].size() >= n / 2) {         x = 0;       } else         x = 1;       if (x) {         if (pos[x].size() % 2 != 0) {           int k = pos[x].size() - 1;           if (k < n / 2) {             vector<int> vv;             for (int i = 0; i < k; i++) vv.push_back(pos[x][i]);             int f = lower_bound(pos[0].begin(), pos[0].end(), vv[vv.size() - 1]) -                     pos[0].begin();             int d =                 lower_bound(pos[0].begin(), pos[0].end(), vv[0]) - pos[0].begin();             if (pos[0].size() - f >= 2) {               vv.push_back(pos[0][f]);               vv.push_back(pos[0][f + 1]);               cout << vv.size() <<   n ;               for (int i = 0; i < vv.size(); i++) cout << v[vv[i]] <<    ;               cout << endl;             } else if (d >= 1) {               vv.push_back(pos[0][d]);               vv.push_back(pos[0][d - 1]);               cout << vv.size() <<   n ;               for (int i = vv.size() - 1; i >= 0; i--) {                 cout << v[vv[i]] <<    ;               }               cout << endl;             }           } else {             cout << k <<   n ;             for (int i = 0; i < k; i++) {               cout << 1 <<    ;             }             cout <<   n ;           }         } else {           cout << pos[x].size() <<   n ;           for (int i = 0; i < pos[x].size(); i++) cout <<  1  ;           cout << endl;         }       } else {         cout << pos[x].size() <<   n ;         for (int i = 0; i < pos[x].size(); i++) cout <<  0  ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200007], b[200007];   bool check[200007];   int main() {     string s;     getline(cin, s);     int res = 0;     for (auto i = (0); i <= ((int)s.size() - 1); ++i) {       int tmp = s[i];       int ans = 0;       for (auto i = (1); i <= (8); ++i) {         ans = 2 * ans + tmp % 2;         tmp /= 2;       }       printf( %d n , (res - ans + 256) % 256);       res = ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 20;   int pos[maxn];   int n, m;   long long k, ans[maxn];   int val[maxn];   struct query {     int l, r, id;   } Q[maxn];   long long now = 0;   long long M[maxn];   bool cmp(query a, query b) {     if (pos[a.l] == pos[b.l]) return a.r < b.r;     return pos[a.l] < pos[b.l];   }   void add(int x) {     now += M[val[x] ^ k];     M[val[x]]++;   }   void del(int x) {     M[val[x]]--;     now -= M[val[x] ^ k];   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       long long temp;       scanf( %I64d , &temp);       val[i] = val[i - 1] ^ temp;     }     int block = sqrt(n);     for (int i = 1; i <= n; i++) pos[i] = i / block;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &Q[i].l, &Q[i].r);       Q[i].id = i;     }     sort(Q + 1, Q + m + 1, cmp);     M[0] = 1;     for (int i = 1, L = 1, R = 0; i <= m; i++) {       for (; R < Q[i].r; R++) add(R + 1);       for (; R > Q[i].r; R--) del(R);       for (; L < Q[i].l; L++) del(L - 1);       for (; L > Q[i].l; L--) add(L - 2);       ans[Q[i].id] = now;     }     for (int i = 1; i <= m; i++) printf( %I64d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mod = 998244353;   int n;   long long a[N];   long long p[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     long long m = 1;     p[0] = 1;     p[1] = 3;     for (int i = 2; i < n; i++) {       m = (m << 1) % mod;       p[i] = m * (i + 2) % mod;     }     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + p[n - i - 1] * a[i]) % mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   const int P = 1000000007;   int m, n, mi[N], l[N], r[N];   char a[N], ans[N];   bool Check(int t, int x) {     if (++t < x) return 0;     return ((r[t] - r[t - x] * mi[x]) * mi[t - x] == l[t] - l[t - x]);   }   bool Dfs(int k, bool has) {     if (k == n) {       puts(ans);       return true;     }     for (ans[k] = (has ? a[k] :  a ); ans[k] <=  z ; ++ans[k]) {       l[k + 1] = l[k] + ans[k] * mi[k];       r[k + 1] = r[k] * P + ans[k];       if (!Check(k, m) && !Check(k, m + 1) && Dfs(k + 1, has && (a[k] == ans[k])))         return true;     }     return false;   }   int main() {     scanf( %d%s , &m, a);     int i;     for (i = (n = strlen(a)) - 1; i >= 0 && a[i] ==  z ; --i) a[i] =  a ;     if (i < 0) {       puts( Impossible );       return 0;     }     ++a[i];     mi[0] = 1;     for (int i = 1; i <= n; ++i) mi[i] = mi[i - 1] * P;     if (!Dfs(0, 1)) puts( Impossible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int S = (int)1e6;   int dp[S];   string txt, pat;   vector<int> ans;   void kmp() {     int i = 0, j = -1, n = ((int)(txt.size())), m = ((int)(pat.size()));     dp[0] = -1;     while (i < m) {       while (j >= 0 and pat[i] != pat[j]) j = dp[j];       i++, j++;       dp[i] = j;     }   }   int main() {     ios::sync_with_stdio(0);   a:     string s, s2;     cin >> s >> s2;     int ones = 0, zeros = 0, ones2 = 0, zeros2 = 0, ones3 = 0, zeros3 = 0;     for (char c : s) (c ==  0 ) ? zeros++ : ones++;     pat = s2;     kmp();     string res = s2, r = s2.substr(dp[((int)(s2.size()))],                                    ((int)(s2.size())) - dp[((int)(s2.size()))]);     for (char c : res) (c ==  0 ) ? zeros2++ : ones2++;     for (char c : r) (c ==  0 ) ? zeros3++ : ones3++;     if (zeros2 > zeros or ones2 > ones)       cout << s <<   n ;     else {       while (1) {         if (zeros2 + zeros3 > zeros or ones2 + ones3 > ones) break;         res += r;         zeros2 += zeros3;         ones2 += ones3;       }       for (int i = 0; i < zeros - zeros2; i++) res +=  0 ;       for (int i = 0; i < ones - ones2; i++) res +=  1 ;       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1100100;   long long N, l, r;   long long L[MAX], R[MAX], d, sol;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int I = 0; I < N; I++) {       cin >> L[I] >> R[I];       l += L[I];       r += R[I];     }     d = abs(l - r);     for (int I = 0; I < N; I++) {       l += +R[I] - L[I];       r += -R[I] + L[I];       if (abs(l - r) > d) {         d = abs(l - r);         sol = I + 1;       }       l -= +R[I] - L[I];       r -= -R[I] + L[I];     }     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long p = 1234567, q = 123456, r = 1234, n;     cin >> n;     long long x = n;     for (int a = 0; a <= n; a += 1234567)       for (int b = 0; b <= n - a; b += 123456) {         if ((n - a - b) % 1234 == 0) {           cout <<  YES ;           return 0;         }       }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (n > m) swap(n, m);     if (n == 2) {       if (m % 4 == 0)         cout << m;       else if (m % 4 == 1)         cout << m + 1;       else         cout << (m / 4) * 4 + 4;     } else if ((m < 2) || (n < 2) || ((m == 2) && (n == 2)))       cout << n * m << endl;     else       cout << (n * m + 1) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int size;     cin >> size;     while (size--) {       int nums;       cin >> nums;       while (nums--) cout << 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ask(string s) {     cout <<  ?   << s << endl;     fflush(stdout);     int x;     cin >> x;     return x;   }   int main() {     int n;     scanf( %d , &n);     string s(n,  0 );     int c = ask(s);     s[0] =  1 ;     int a0;     int d = ask(s);     int pos1 = -1, pos0 = -1;     int zo = 0;     if (d < c) {       pos1 = 0;       zo = 1;     } else {       pos0 = 0;     }     if (zo == 1) {       a0 = ask(string(n,  1 ));     } else {       a0 = c;     }     int le(0), ri(n - 2);     while (le != ri) {       string s;       int mid((le + ri + 1) / 2);       for (int i(0); i <= mid; i++) s.push_back( 1  ^ zo);       for (int i(mid + 1); i < n; i++) s.push_back( 0  ^ zo);       if (ask(s) == a0 + mid + 1) {         le = mid;       } else {         ri = mid - 1;       }     }     if (pos1 == -1)       pos1 = le + 1;     else       pos0 = le + 1;     printf( ! %d %d n , 1 + pos0, 1 + pos1);     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[100005][2];   string a, b;   int main() {     int K;     while (cin >> a >> b) {       cin >> K;       memset(dp, 0, sizeof(dp));       if (a == b)         dp[0][1] = 1;       else         dp[0][0] = 1;       int cnt = 0, l = a.length();       a = a + a;       for (int i = 0; i < l; i++)         if (a.compare(i, l, b) == 0) cnt++;       for (int i = 1; i <= K; i++) {         dp[i][1] = (dp[i - 1][1] * (cnt - 1) + dp[i - 1][0] * cnt) % mod;         dp[i][0] =             (dp[i - 1][1] * (l - cnt) + dp[i - 1][0] * (l - cnt - 1)) % mod;       }       cout << dp[K][1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r = 0, u = 0;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  L )         r--;       else if (s[i] ==  R )         r++;       else if (s[i] ==  U )         u++;       else if (s[i] ==  D )         u--;     }     r *= r < 0 ? -1 : 1;     u *= u < 0 ? -1 : 1;     if ((r + u) % 2 == 0)       cout << (r + u) / 2;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005, MAXM = 3e4 + 5;   int N, M, s, t;   int cost[MAXM], low[MAXN], disc[MAXN];   bool vis[MAXN];   vector<int> edges, bridge, ANS;   vector<pair<int, int> > adj[MAXN];   void read() {     scanf( %d %d , &N, &M);     scanf( %d %d , &s, &t);     for (int i = 1; i <= M; i++) {       int u, v, c;       scanf( %d %d %d , &u, &v, &c);       adj[u].push_back(make_pair(v, i));       adj[v].push_back(make_pair(u, i));       cost[i] = c;     }   }   bool dfs(int pos) {     if (pos == t) return true;     vis[pos] = true;     for (pair<int, int> next : adj[pos]) {       if (!vis[next.first] && dfs(next.first)) {         edges.push_back(next.second);         return true;       }     }     return false;   }   bool canReach(int pos, int posID, int forbidEdge) {     static int time = 0;     vis[pos] = true;     low[pos] = disc[pos] = ++time;     bool res = false;     if (pos == t) res = true;     for (pair<int, int> next : adj[pos]) {       if (next.second == forbidEdge || next.second == posID) continue;       if (vis[next.first])         low[pos] = min(low[pos], disc[next.first]);       else {         bool flag = canReach(next.first, next.second, forbidEdge);         if (flag) res = true;         low[pos] = min(low[pos], low[next.first]);         if (low[next.first] > disc[pos] && flag) bridge.push_back(next.second);       }     }     return res;   }   void solve() {     memset(vis, false, sizeof(vis));     if (!dfs(s)) {       printf( 0 n0 n );       return;     }     int res = INT_MAX;     for (int forbidEdge : edges) {       bridge.clear();       memset(vis, false, sizeof(vis));       if (!canReach(s, -1, forbidEdge)) {         if (cost[forbidEdge] < res) {           res = cost[forbidEdge];           ANS = {forbidEdge};         }       }       for (int edge : bridge) {         if (cost[forbidEdge] + cost[edge] < res) {           res = cost[forbidEdge] + cost[edge];           ANS = {forbidEdge, edge};         }       }     }     if (res == INT_MAX) {       printf( -1 n );       return;     }     printf( %d n%d n , res, ANS.size());     for (int i = 0; i < ANS.size(); i++) {       printf( %d%c , ANS[i], i == ANS.size() - 1 ?   n  :    );     }   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M;   const int N_MAX = 2;   template <class T>   void mul(int n, const T A[N_MAX][N_MAX], const T x[N_MAX], T y[N_MAX]) {     static T z[N_MAX];     for (int i = 0; i < (n); i++) {       z[i] = 0;       for (int j = 0; j < (n); j++) z[i] = (z[i] + A[i][j] * x[j]) % M;     }     for (int i = 0; i < (n); i++) y[i] = z[i];   }   template <class T>   void mul(int n, const T A[N_MAX][N_MAX], const T B[N_MAX][N_MAX],            T C[N_MAX][N_MAX]) {     static T tmp[N_MAX][N_MAX];     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) {         tmp[i][j] = 0;         for (int k = 0; k < (n); k++)           tmp[i][j] = (tmp[i][j] + A[i][k] * B[k][j]) % M;       }     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) C[i][j] = tmp[i][j];   }   template <class T>   void pow(int n, const T A[N_MAX][N_MAX], long long m, T B[N_MAX][N_MAX]) {     static T tmp[N_MAX][N_MAX];     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) {         tmp[i][j] = A[i][j];         B[i][j] = (i == j ? 1 : 0);       }     for (int t = 0; m > 0; t++) {       if (m & (1LL << t)) {         mul(n, B, tmp, B);         m -= 1LL << t;       }       mul(n, tmp, tmp, tmp);     }   }   long long fib(long long n) {     long long A[2][2] = {{1, 1}, {1, 0}}, x[2] = {1, 0};     pow(2, A, n - 1, A);     mul(2, A, x, x);     return x[0];   }   int main() {     long long l, r, k;     cin >> M >> l >> r >> k;     vector<long long> cand;     for (long long i = 1; i * i <= r; i++) {       cand.push_back(i);       for (int j = -1; j <= 1; j++) {         cand.push_back(l / i + j);         cand.push_back(r / i + j);       }     }     long long idx = 1;     for (int i = 0; i < (cand.size()); i++) {       long long a = cand[i];       if (a > 0 && r / a - (l - 1) / a >= k) idx = max(idx, a);     }     cout << fib(idx) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   map<long long, long long> mp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n;     vector<long long> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];       if (mp.find(v[i]) == mp.end())         mp[v[i]] = 1;       else         mp[v[i]]++;     }     cin >> m;     vector<long long> a(m), b(m);     for (int i = 0; i < m; ++i) cin >> a[i];     for (int i = 0; i < m; ++i) cin >> b[i];     vector<pair<long long, pair<long long, long long> > > vp;     for (int i = 0; i < m; ++i) {       vp.push_back({mp[a[i]], {mp[b[i]], i}});     }     sort(vp.begin(), vp.end());     int ans = vp.size() - 1;     while (ans > 0 && vp[ans].first == vp[ans - 1].first &&            vp[ans].second.first == vp[ans - 1].second.first)       ans--;     cout << vp[ans].second.second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 5;   const int mod = 1e9 + 7;   int n, k;   long long a[maxn];   template <class T>   inline void read(T &res) {     res = 0;     T f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       res = res * 10 + c -  0 ;       c = getchar();     }     res *= f;   }   long long cal(int n) { return a[n]; }   int nn = 4, mm = 12;   long long call(int i) {     if (i % 3) return (a[i - 1] + 2 * a[i - 2]) % mod;     return (a[i - 1] + 2 * a[i - 2] + 4) % mod;   }   void init() {     a[3] = a[4] = nn;     a[5] = mm;     for (int i = 6; i <= maxn; ++i) {       a[i] = call(i);     }   }   int main() {     int qwq;     init();     read(qwq);     while (qwq--) {       read(n);       long long ans = cal(n);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300;   const double eps = 1e-9;   int px[MAXN], py[MAXN];   int ans[1000100];   int n, m;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < m; ++i) scanf( %d%d , px + i, py + i);       memset(ans, 0, sizeof(ans));       for (int i = 0; i < m; ++i)         for (int j = 0; j < m; ++j) {           double dx = px[j] - px[i];           double dy = py[j] - py[i];           if (abs(dy) < eps) continue;           double axi;           if (abs(dx) < eps)             axi = px[i];           else             axi = (-py[i] * dx) / dy + px[i];           if (abs(axi - (int)axi) > eps || (int)axi > n || (int)axi < 1) continue;           int cnt = 0;           for (int k = 0; k < m; ++k) {             if (k == i || k == j) continue;             if (dy * (px[k] - px[i]) == (py[k] - py[i]) * dx) ++cnt;           }           ans[(int)axi] = max(ans[(int)axi], cnt + 2);         }       int sum(0);       for (int i = 1; i <= n; ++i) {         sum += max(1, ans[i]);       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   template <typename tp>   inline tp max(tp x, tp y) {     return x > y ? x : y;   }   template <typename tp>   inline tp min(tp x, tp y) {     return x < y ? x : y;   }   template <typename tp>   inline bool chkmax(tp& x, tp y) {     return (x >= y) ? false : (x = y, true);   }   template <typename tp>   inline bool chkmin(tp& x, tp y) {     return (x <= y) ? false : (x = y, true);   }   static const int len = 1 << 20 | 1;   char buffer[len], *Ser, *Ter;   inline char Getchar() {     if (Ser == Ter) Ter = (Ser = buffer) + fread(buffer, 1, len, stdin);     return (Ser == Ter) ? (char)EOF : (*Ser++);   }   template <typename tp>   inline tp scanf(tp& in) {     in = 0;     char ch = getchar();     tp f = 1;     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) in = in * 10 + ch -  0 ;     return in *= f;   }   static const int max1 = 1e5 + 11;   static const int max2 = 2e5 + 11;   int n;   int k;   int q;   long long ans;   int ti[max1];   int ai[max1];   long long sum[max1];   long long tot[max1];   int dt;   long long dir[max2];   int cnt1[max2];   int cnt2[max2];   long long output[max1];   class query {    public:     int l;     int r;     int bel;     int id;     bool operator<(const query& t) const {       if (bel ^ t.bel) return bel < t.bel;       if (r ^ t.r) return r < t.r;       return l < t.l;     }   } qi[max1];   int main() {     scanf(n);     scanf(k);     for (int i = (1), ir = (n); i <= (ir); ++i) scanf(ti[i]);     for (int i = (1), ir = (n); i <= (ir); ++i)       ai[i] = scanf(ai[i]) * ((ti[i] == 1) ? 1 : -1);     int N = sqrt(n);     scanf(q);     for (int i = (1), ir = (q); i <= (ir); ++i)       scanf(qi[i].l), scanf(qi[i].r), qi[i].id = i, qi[i].bel = qi[i].l / N;     std ::sort(1 + qi, 1 + q + qi);     for (int i = (1), ir = (n); i <= (ir); ++i)       dir[++dt] = sum[i] = sum[i - 1] + ai[i],       dir[++dt] = tot[i] = sum[i - 1] + k;     std ::sort(1 + dir, 1 + dt + dir);     dt = std ::unique(1 + dir, 1 + dt + dir) - dir - 1;     for (int i = (1), ir = (n); i <= (ir); ++i)       sum[i] = std ::lower_bound(1 + dir, 1 + dt + dir, sum[i]) - dir,       tot[i] = std ::lower_bound(1 + dir, 1 + dt + dir, tot[i]) - dir;     int l = 1, r = 0;     for (int i = (1), ir = (q); i <= (ir); ++i) {       int L = qi[i].l, R = qi[i].r;       while (r < R) ++r, ++cnt1[sum[r]], ++cnt2[tot[r]], ans += cnt2[sum[r]];       while (r > R) ans -= cnt2[sum[r]], --cnt1[sum[r]], --cnt2[tot[r]], --r;       while (l < L) ans -= cnt1[tot[l]], --cnt1[sum[l]], --cnt2[tot[l]], ++l;       while (l > L) --l, ++cnt1[sum[l]], ++cnt2[tot[l]], ans += cnt1[tot[l]];       output[qi[i].id] = ans;     }     for (int i = (1), ir = (q); i <= (ir); ++i) printf( %lld n , output[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, t[100100], tree[100100];   queue<int> q;   set<int> waiting;   long long curT, ans[100100];   int get(int x) {     for (int i = x; i; i -= i & -i)       if (tree[i]) return 1;     return 0;   }   void add(int x, int v) {     for (int i = x; i <= 100000; i += i & -i) tree[i] += v;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<pair<int, int>> a;     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> t[i];       a.push_back({t[i], i});     }     sort(a.begin(), a.end());     int i = 0;     while (1)       if (!q.empty()) {         int x = q.front();         q.pop();         curT += p;         ans[x] = curT;         while (i < n && a[i].first < curT) {           int y = a[i++].second;           if (get(y))             waiting.insert(y);           else {             q.push(y);             add(y + 1, 1);           }         }         add(x + 1, -1);         while (i < n && a[i].first == curT) waiting.insert(a[i++].second);         if (waiting.empty()) continue;         int y = *waiting.begin();         if (get(y)) {           auto it = waiting.lower_bound(x);           if (it == waiting.end()) continue;           y = *it;           if (get(y)) continue;         }         q.push(y);         add(y + 1, 1);         waiting.erase(y);       } else {         if (i == n) break;         int x = a[i++].second;         q.push(x);         curT = t[x];         add(x + 1, 1);       }     for (int i = 0; i < n; i++) cout << ans[i] <<    n [i == n - 1];   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, ans, tmp, t, curr, x, r, sm, k, l;   long long arr[1000005], res[1000005], par1[1000005], par2[1000005];   string s;   vector<long long> vec[1000005];   void dfs(long long idx, long long par, long long col) {     if (col != arr[idx]) {       ans++;       col = arr[idx];     }     for (long long i = 0; i < vec[idx].size(); i++) {       if (vec[idx][i] == par) continue;       dfs(vec[idx][i], idx, col);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (i = 2; i <= n; i++) {       cin >> x;       vec[x].push_back(i);     }     for (i = 1; i <= n; i++) cin >> arr[i];     dfs(1, -1, 0);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, z, last[500039][2], a[500039], s[500039], ans;   long long q[500039];   inline void swap(int &x, int &y) { x ^= y ^= x ^= y; }   inline void check(int x, int y) {     if (y - x < 2 || !x) return;     if (q[y - 1] - q[x] == (a[y] ^ a[x])) ans++;   }   inline void find(int flag) {     register int i, j;     memset(last, 0, sizeof(last));     for (i = 1; i <= n; i++) {       last[s[i]][1] = last[s[i]][0];       last[s[i]][0] = i;       for (j = s[i] + 1; j <= 29; j++) check(last[j][0], i), check(last[j][1], i);       if (!flag) check(last[s[i]][1], i);     }   }   int main() {     register int i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), q[i] = q[i - 1] + a[i];     for (i = 1; i <= n; i++) {       for (j = 29; j >= 0; j--)         if (a[i] & (1 << j)) {           s[i] = j;           break;         }     }     find(0);     for (i = 1; i <= n / 2; i++)       swap(a[i], a[n - i + 1]), swap(s[i], s[n - i + 1]);     for (i = 1; i <= n; i++) q[i] = q[i - 1] + a[i];     find(1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   string employees;   queue<int> d, r;   int main() {     int n;     cin >> n >> employees;     for (int i = 0; i < n; i++) {       if (employees[i] ==  D )         d.push(i);       else         r.push(i);     }     while (!d.empty() && !r.empty()) {       int idx_d = d.front(), idx_r = r.front();       d.pop(), r.pop();       if (idx_d < idx_r)         d.push(idx_d + n);       else         r.push(idx_r + n);     }     if (d.empty())       cout <<  R ;     else       cout <<  D ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     if (n == 1 || n == 4 || n == 6 || n == 8 || n == 9 || n == 10 || n == 13 ||         n == 15) {       cout <<  1 ;       return 0;     }     cout <<  0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000050;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int a[maxn], b[maxn], mi, ans1, ans2, ans3, ans, l, r;   vector<int> v;   char s[maxn];   void pa(int s, int e) {     ans2 = 0;     for (int i = s; i < e; i++)       if (a[i] == mi + 1) ans2++;     if (ans2 > ans) {       ans = ans2;       l = s, r = e;     }     ans3 = 0;     int x = s + 1;     for (int i = s + 1; i < e; i++) {       if (a[i] == mi + 1) {         if (ans3 + ans1 > ans) {           ans = ans1 + ans3;           l = x, r = i;         }         x = i + 1;         ans3 = 0;       }       if (a[i] == mi + 2) ans3++;     }   }   int main() {     int n, m, i, j, k, t;     scanf( %d , &n);     scanf( %s , s + 1);     for (i = 1; i <= n; i++)       a[i] = s[i] ==  (  ? a[i - 1] + 1 : a[i - 1] - 1, mi = min(mi, a[i]);     if (a[n] != 0) printf( 0 n1 1 n ), exit(0);     for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];     for (i = 1; i <= n; i++)       if (a[i] == mi) v.push_back(i);     ans = ans1 = v.size();     l = r = 1;     v.push_back(v[0] + n);     for (i = 0; i < v.size() - 1; i++) pa(v[i] + 1, v[i + 1]);     printf( %d n%d %d n , ans, l > n ? l - n : l, r > n ? r - n : r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[104];   int main() {     int n, avg, mn, flag;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     avg = 0;     avg = arr[1] - arr[0];     flag = 0;     for (int i = 1; i < n; i++) {       int diff = (arr[i] - arr[i - 1]);       if (diff != avg) {         flag = 1;         break;       }     }     if (flag == 1) {       cout << arr[n - 1] << endl;     } else {       cout << arr[n - 1] + avg << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int64_t v, f, c;     Edge(int64_t v, int64_t f, int64_t c) : v(v), f(f), c(c) {}     int64_t get_capacity() { return c - f; }   };   const int64_t INF = (int64_t)(1e9) + 666;   const int64_t N = 10000;   const int64_t S = N - 2;   const int64_t T = N - 1;   vector<Edge> edges;   vector<int64_t> g[N];   int64_t dist[N];   int64_t ptr[N];   void add_edge(int64_t v, int64_t u, int64_t c) {     g[v].emplace_back(edges.size());     edges.emplace_back(u, 0, c);     g[u].emplace_back(edges.size());     edges.emplace_back(v, 0, 0);   }   bool bfs() {     fill(dist, dist + N, INF);     dist[S] = 0;     queue<int64_t> q;     q.push(S);     while (!q.empty()) {       int64_t v = q.front();       q.pop();       for (int64_t id : g[v]) {         if (edges[id].get_capacity() < 1) {           continue;         }         if (dist[edges[id].v] > dist[v] + 1) {           dist[edges[id].v] = dist[v] + 1;           q.push(edges[id].v);         }       }     }     return dist[T] != INF;   }   int64_t dfs(int64_t v, int64_t min_c) {     if (v == T) {       return min_c;     }     while (ptr[v] < g[v].size()) {       int64_t id = g[v][ptr[v]];       ++ptr[v];       if (edges[id].get_capacity() < 1) {         continue;       }       if (dist[edges[id].v] != dist[v] + 1) {         continue;       }       int64_t x = dfs(edges[id].v, min(min_c, edges[id].get_capacity()));       if (x) {         --ptr[v];         edges[id].f += x;         edges[id ^ 1].f -= x;         return x;       }     }     return 0;   }   int main() {     int64_t n, h, m;     cin >> n >> h >> m;     int64_t sum = 0;     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < h; ++j) {         sum += 2 * (j + 1) - 1;         add_edge(S, i * h + j, 2 * (j + 1) - 1);       }     }     for (int64_t q = 0; q < m; ++q) {       int64_t left, right, x, c;       cin >> left >> right >> x >> c;       add_edge(q + N / 2, T, c);       for (int64_t i = left - 1; i < right; ++i) {         for (int64_t j = x; j < h; ++j) {           add_edge(i * h + j, q + N / 2, INF);         }       }     }     while (bfs()) {       fill(ptr, ptr + N, 0);       while (dfs(S, INF)) {       }     }     for (int64_t id : g[S]) {       sum -= edges[id].f;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::ostream& operator<<(std::ostream& os, pair<int, int> p) {     os << p.first <<  ,   << p.second;     return os;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (l * 2 > r) {         cout << -1 <<     << -1 <<   n ;         continue;       } else {         cout << l <<     << 2 * l <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; i++) {       int up = 0, le = 0;       for (int j = i; j < n; j++) {         if (s[j] ==  U ) up++;         if (s[j] ==  D ) up--;         if (s[j] ==  L ) le++;         if (s[j] ==  R ) le--;         if (up == 0 && le == 0) cnt++;       }     }     cout << cnt << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int bt[50 + 10];   map<int, int> MAP;   int main() {     long long int a, b, c, d, e, f, m, n, p, q, x, y, z, w, k;     vector<long long int> v[2525], temp;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       bt[i] = x;       temp.push_back(x);     }     sort(temp.begin(), temp.end(), greater<long long int>());     for (int i = 0; i < temp.size(); i++) {       v[i + 1].push_back(temp[i]);     }     if (n >= k) {       for (int i = 1; i <= k; i++) {         cout << 1 <<     << bt[i] << endl;       }     } else {       long long int start = 2;       long long int end = n;       long long int mul = 1;       long long int cnt = 1;       int p = 0;       long long int get = n + 1;       while (get - 1 < k) {         for (int i = start; i <= end; i++) {           v[get] = v[i];           v[get].insert(v[get].end(), v[mul].begin(), v[mul].end());           get++;         }         start = end + 2;         end = get - 1;         mul++;       }       for (int i = 1; i <= k; i++) {         cout << v[i].size() <<    ;         long long int lmt = v[i].size();         cout << v[i][0];         for (int j = 1; j < lmt; j++) {           cout <<     << v[i][j];         }         cout << endl;       }     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ts = 1, cs = 1;     cin >> ts;     while (ts--) {       int n, m;       cin >> n >> m;       pair<int, int> vec[m + 2];       for (int i = 1; i <= m; i++) {         cin >> vec[i].first;         vec[i].second = i;       }       sort(vec + 1, vec + m + 1);       long long ans = 0;       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= m; j++) {           if (vec[i].second > vec[j].second && vec[i].first > vec[j].first) ans++;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num, i, count = 0, sum = 0, a;     cin >> num;     a = 1;     while (1) {       for (i = 1; i <= a; i++) {         sum += i;       }       a++;       if (sum > num) break;       count++;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long base = 139;   const long long M = 1000012309;   long long p[200007];   vector<pair<long long, char> > vp1;   vector<pair<long long, char> > vp2;   long long hashtable[200007], hv, cnt = 0;   void pcal() {     p[0] = 1;     for (long long i = 1; i < 200007; ++i) p[i] = (p[i - 1] * base) % M;   }   void hashfunc() {     hashtable[0] = (vp1[0].first * vp1[0].second) % M;     ;     long long sz1 = vp1.size();     long long sz2 = vp2.size() - 2;     long long sz3 = vp2.size();     for (long long i = 1; i < sz1; ++i) {       long long val = (vp1[i].first * vp1[i].second) % M;       hashtable[i] = ((hashtable[i - 1] * base) % M + val) % M;     }     for (long long i = 0; i < sz1 - 1; ++i) {       long long l = i + 1;       long long r = i + sz2;       if (vp1[i].second == vp2[0].second && vp1[i].first >= vp2[0].first &&           r < sz1 - 1) {         long long bad = (hashtable[l - 1] * p[r - l + 1]) % M;         long long check = (hashtable[r] - bad + M) % M;         if (check == hv && vp1[r + 1].second == vp2[sz3 - 1].second &&             vp1[r + 1].first >= vp2[sz3 - 1].first)           cnt++;       }     }   }   int main() {     long long n, m;     cin >> n >> m;     long long d;     char c, a;     pcal();     for (long long i = 0; i < n; ++i) {       cin >> d >> c >> a;       if (i == 0)         vp1.push_back({d, a});       else {         long long sz = vp1.size();         if (a == vp1[sz - 1].second)           vp1[sz - 1].first += d;         else           vp1.push_back({d, a});       }     }     for (long long i = 0; i < m; ++i) {       cin >> d >> c >> a;       if (i == 0)         vp2.push_back({d, a});       else {         long long sz = vp2.size();         if (a == vp2[sz - 1].second)           vp2[sz - 1].first += d;         else           vp2.push_back({d, a});       }     }     if (vp1.size() < vp2.size()) {       cout << 0 << endl;       return 0;     } else if (vp2.size() == 1) {       long long sz1 = vp1.size();       cnt = 0;       for (long long i = 0; i < sz1; ++i) {         if (vp2[0].second == vp1[i].second && vp2[0].first <= vp1[i].first)           cnt += vp1[i].first - vp2[0].first + 1;       }       cout << cnt << endl;     } else if (vp2.size() == 2) {       long long sz1 = vp1.size();       cnt = 0;       for (long long i = 0; i < sz1 - 1; ++i) {         if (vp2[0].second == vp1[i].second && vp2[1].second == vp1[i + 1].second)           if (vp2[0].first <= vp1[i].first && vp2[1].first <= vp1[i + 1].first)             cnt++;       }       cout << cnt << endl;     } else if (vp2.size() > 2) {       long long sz = vp2.size();       cnt = 0;       hv = (vp2[0].first * vp2[0].second) % M;       for (long long i = 1; i < sz - 1; ++i) {         long long d = vp2[i].first;         long long a = vp2[i].second;         long long val = (d * a) % M;         hv = ((hv * base) % M + val) % M;       }       long long bad = ((vp2[0].first * vp2[0].second) % M * p[sz - 2]) % M;       hv = (hv - bad + M) % M;       hashfunc();       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-9;   const int INF = 1000 * 1000 * 1000;   const long long LINF = INF * 1ll * INF;   const double DINF = 1e200;   const double PI = 3.1415926535897932384626433832795l;   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long gcdex(long long a, long long b, long long &x, long long &y) {     if (!a) {       x = 0, y = 1;       return b;     }     long long k = b / a;     long long g = gcdex(b - k * a, a, y, x);     x -= k * y;     return g;   }   long long inv(long long a, long long m) {     assert(m > 1);     long long x, y, g;     g = gcdex(a, m, x, y);     return (x % (m / g) + m / g) % m / g;   }   long long crt(long long a1, long long m1, long long a2, long long m2) {     long long a = (a2 - a1 % m2 + m2) % m2;     long long x, y, g;     g = gcdex(m1, m2, x, y);     if (a % g) return -1;     long long m = m1 / g * m2;     assert(x + m2 >= 0);     x = a / g * (x + m2) % m2;     long long r = (a1 + x * m1) % m;     assert(r % m1 == a1 && r % m2 == a2);     return r;   }   long long powmod(long long a, long long p, long long m) {     assert(p >= 0);     long long r = 1;     while (p) {       if (p & 1) r = r * a % m;       p >>= 1;       a = a * a % m;     }     return r;   }   bool isprime(long long a) {     if (a <= 1) return false;     for (long long i = 2; i * i <= a; ++i) {       if (a % i == 0) return false;     }     return true;   }   long long sqrtup(long long a) {     if (!a) return 0;     long long x = max(0ll, (long long)sqrt((double)a));     while (x * x >= a) --x;     while ((x + 1) * (x + 1) < a) ++x;     return x + 1;   }   long long isqrt(long long a) {     if (a <= 0) {       assert(!a);       return 0;     }     long long x = (long long)sqrt((double)a);     while (sqr(x + 1) <= a) ++x;     while (x * x > a) --x;     return x;   }   long long sgn(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }   double randf() {     double m = RAND_MAX + 1.;     return (((rand() + .5) / m + rand()) / m + rand()) / m;   }   int rand30() {     assert(RAND_MAX >= (1 << 15) - 1);     return (         int)((((uint32_t)rand()) * (1u + (uint32_t)RAND_MAX) + (uint32_t)rand()) &              ((1u << 30) - 1));   }   template <class T>   void smin(T &a, T b) {     a = min(a, b);   }   template <class T>   void smax(T &a, T b) {     a = max(a, b);   }   template <class T>   ostream &operator<<(ostream &s, const vector<T> &v);   template <class A, class B>   ostream &operator<<(ostream &s, const pair<A, B> &p);   template <class K, class V>   ostream &operator<<(ostream &s, const map<K, V> &m);   template <class T>   ostream &operator<<(ostream &s, const set<T> &m);   template <class T, size_t N>   ostream &operator<<(ostream &s, const array<T, N> &a);   template <class... T>   ostream &operator<<(ostream &s, const tuple<T...> &t);   template <class T>   ostream &operator<<(ostream &s, const vector<T> &v) {     s <<  [ ;     for (int i = 0; i < (((int)(v).size())); ++i) {       if (i) s <<  , ;       s << v[i];     }     s <<  ] ;     return s;   }   template <class A, class B>   ostream &operator<<(ostream &s, const pair<A, B> &p) {     s <<  (  << p.first <<  ,  << p.second <<  ) ;     return s;   }   template <class K, class V>   ostream &operator<<(ostream &s, const map<K, V> &m) {     s <<  { ;     bool f = false;     for (const auto &it : m) {       if (f) s <<  , ;       f = true;       s << it.first <<  :   << it.second;     }     s <<  } ;     return s;   }   template <class T>   ostream &operator<<(ostream &s, const set<T> &m) {     s <<  { ;     bool f = false;     for (const auto &it : m) {       if (f) s <<  , ;       f = true;       s << it;     }     s <<  } ;     return s;   }   template <class T>   ostream &operator<<(ostream &s, const multiset<T> &m) {     s <<  { ;     bool f = false;     for (const auto &it : m) {       if (f) s <<  , ;       f = true;       s << it;     }     s <<  } ;     return s;   }   template <class T, class V, class C>   ostream &operator<<(ostream &s, const priority_queue<T, V, C> &q) {     auto a = q;     s <<  { ;     bool f = false;     while (!a.empty()) {       if (f) s <<  , ;       f = true;       s << a.top();       a.pop();     }     return s <<  } ;   }   template <class T, size_t N>   ostream &operator<<(ostream &s, const array<T, N> &a) {     s <<  [ ;     for (int i = 0; i < (((int)(a).size())); ++i) {       if (i) s <<  , ;       s << a[i];     }     s <<  ] ;     return s;   }   template <class T>   ostream &operator<<(ostream &s, const deque<T> &a) {     s <<  [ ;     for (int i = 0; i < (((int)(a).size())); ++i) {       if (i) s <<  , ;       s << a[i];     }     s <<  ] ;     return s;   }   template <size_t n, class... T>   struct put1 {     static ostream &put(ostream &s, const tuple<T...> &t) {       s << get<sizeof...(T) - n>(t);       if (n > 1) s <<  , ;       return put1<n - 1, T...>::put(s, t);     }   };   template <class... T>   struct put1<0, T...> {     static ostream &put(ostream &s, const tuple<T...> &t) { return s; }   };   template <class... T>   ostream &operator<<(ostream &s, const tuple<T...> &t) {     s <<  ( ;     put1<sizeof...(T), T...>::put(s, t);     s <<  ) ;     return s;   }   ostream &put3(ostream &s, const char *, bool) { return s; }   template <class U, class... T>   ostream &put3(ostream &s, const char *f, bool fs, U &&u, T &&...t) {     while (*f ==    ) ++f;     if (!fs) s <<  ,  ;     auto nf = f;     int d = 0;     while (*nf && (*nf !=  ,  || d)) {       if (*nf ==  ( )         ++d;       else if (*nf ==  ) )         --d;       ++nf;     }     auto nf2 = nf;     while (nf2 > f && *(nf2 - 1) ==    ) --nf;     fs = *f ==    ;     if (!fs) {       s.write(f, nf2 - f);       s <<  = ;     };     s << u;     if (fs) s <<    ;     if (*nf) ++nf;     return put3(s, nf, fs, forward<T>(t)...);   }   mt19937 mtrng;   struct comp {     vector<int> V;     vector<pair<int, int>> E;   };   struct tree {     vector<pair<int, int>> T;     tree(int n) : T(n * 4) {}     void init(int a, int b, int k, const vector<int> &A) {       if (b == a + 1) {         T[k] = make_pair(A[a], a);         return;       }       int c = (a + b) / 2;       init(a, c, k * 2 + 1, A);       init(c, b, k * 2 + 2, A);       T[k] = max(T[k * 2 + 1], T[k * 2 + 2]);     }     pair<int, int> getmax(int l, int r, int a, int b, int k) {       if (l >= b || r <= a) return make_pair(0, -1);       if (l <= a && r >= b) return T[k];       int c = (a + b) / 2;       return max(getmax(l, r, a, c, k * 2 + 1), getmax(l, r, c, b, k * 2 + 2));     }     void setv(int p, int v, int a, int b, int k) {       if (b == a + 1) {         T[k] = make_pair(v, p);         return;       }       int c = (a + b) / 2;       if (p < c)         setv(p, v, a, c, k * 2 + 1);       else         setv(p, v, c, b, k * 2 + 2);       T[k] = max(T[k * 2 + 1], T[k * 2 + 2]);     }   };   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);     srand(35964);     mtrng.seed(765674737);     int n, m, tc;     cin >> n >> m >> tc;     vector<int> P;     P.resize(n);     for (int i = 0; i < (n); ++i) cin >> P[i];     vector<pair<pair<int, int>, int>> E(m);     for (int i = 0; i < (m); ++i) {       cin >> E[i].first.first >> E[i].first.second;       --E[i].first.first;       --E[i].first.second;     }     vector<pair<int, int>> Q(tc);     for (int i = 0; i < (tc); ++i) {       cin >> Q[i].first >> Q[i].second;       --Q[i].second;       if (Q[i].first == 2) E[Q[i].second].second = 1;     }     vector<int> v2c(n);     vector<comp> cs(n);     for (int i = 0; i < (n); ++i) {       v2c[i] = i;       cs[i].V.push_back(i);     }     auto mer = [&](int a, int b, int q) {       if (a == b) return;       if (((int)(cs[a].V).size()) < ((int)(cs[b].V).size())) swap(a, b);       for (pair<int, int> x : cs[b].E)         cs[a].E.push_back(make_pair(x.first, x.second + ((int)(cs[a].V).size())));       if (q != -1) cs[a].E.push_back(make_pair(q, ((int)(cs[a].V).size())));       for (int v : cs[b].V) {         v2c[v] = a;         cs[a].V.push_back(v);       }       cs[b].V.clear();       cs[b].E.clear();     };     for (auto e : E) {       if (e.second) continue;       mer(v2c[e.first.first], v2c[e.first.second], -1);     }     for (int q = tc - 1; q >= 0; --q) {       if (Q[q].first != 2) continue;       pair<int, int> e = E[Q[q].second].first;       int a = v2c[e.first], b = v2c[e.second];       mer(a, b, q);     }     set<int> B;     vector<int> v2i(n);     vector<int> i2v;     vector<pair<int, int>> ev;     B.insert(0);     for (comp &c : cs) {       if (!((int)(c.V).size())) continue;       for (pair<int, int> e : c.E)         ev.push_back(make_pair(e.first, e.second + ((int)(i2v).size())));       for (int v : c.V) {         v2i[v] = ((int)(i2v).size());         i2v.push_back(v);       }       B.insert(((int)(i2v).size()));     }     assert(((int)(i2v).size()) == n);     sort((ev).begin(), (ev).end());     tree T(n);     vector<int> A(n);     for (int i = 0; i < (n); ++i) A[i] = P[i2v[i]];     T.init(0, n, 0, A);     int ei = 0;     for (int q = 0; q < (tc); ++q) {       if (Q[q].first == 1) {         int i = v2i[Q[q].second];         auto it = B.upper_bound(i);         int b = *it;         --it;         int a = *it;         pair<int, int> t = T.getmax(a, b, 0, n, 0);         T.setv(t.second, 0, 0, n, 0);         cout << t.first <<   n ;       } else if (ei < ((int)(ev).size()) && ev[ei].first == q) {         B.insert(ev[ei].second);         ++ei;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, tmp;   vector<int> nPos;   vector<int> NegPos, ZeroPos;   int minNeg = -1000000001, minNegPos = -1;   int main() {     scanf( %d n , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &tmp);       nPos.push_back(tmp);     }     for (int i = 0; i < n; i++) {       if (nPos[i] == 0) {         ZeroPos.push_back(i);       } else if (nPos[i] < 0) {         if (nPos[i] > minNeg) {           minNeg = nPos[i];           minNegPos = i;         }         NegPos.push_back(i);       }     }     for (int i = 1; i < ZeroPos.size(); i++) {       printf( 1 %d %d n , ZeroPos[i] + 1, ZeroPos[0] + 1);     }     if (NegPos.size() % 2 == 0) {       if ((!ZeroPos.empty()) && ZeroPos.size() < n) {         printf( 2 %d n , ZeroPos[0] + 1);       }       for (int i = 0; i < n; i++) {         if (nPos[i] != 0) {           for (int j = i + 1; j < n; j++) {             if (nPos[j] != 0) {               printf( 1 %d %d n , j + 1, i + 1);             }           }           break;         }       }     } else {       if (!ZeroPos.empty()) {         printf( 1 %d %d n , ZeroPos[0] + 1, minNegPos + 1);       }       if (ZeroPos.size() + 1 < n) {         printf( 2 %d n , minNegPos + 1);       }       for (int i = 0; i < n; i++) {         if (i != minNegPos && nPos[i] != 0) {           for (int j = i + 1; j < n; j++) {             if (j != minNegPos && nPos[j] != 0) {               printf( 1 %d %d n , j + 1, i + 1);             }           }           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int m = 1000000 + 3;   int db[1010];   int twospows[1010];   long long mpow(int b, int e) {     if (e == 0) return 1;     if (e == 1) return b;     return (mpow(b, e / 2) % m) * (mpow(b, e - e / 2) % m) % m;   }   long long twopow(int e) {     if (twospows[e] != -1) return twospows[e];     return twospows[e] = mpow(2, e);   }   long long solve(int n) {     if (n == 0) return 1;     if (db[n] != -1) return db[n];     long long v = twopow(n - 1);     for (int i = n - 1; i != 0; --i) {       v += twopow(n - i - 1) * solve(i);       v %= m;     }     return db[n] = v % m;   }   int main() {     int n;     cin >> n;     fill(db, db + 1010, -1);     fill(twospows, twospows + 1010, -1);     cout << solve(n) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     x = 0;     char c;     while (!isdigit(c = getchar()))       ;     do {       x = x * 10 + c -  0 ;     } while (isdigit(c = getchar()));   }   template <typename T>   inline void write(T x) {     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   void Write(string s) {     for (int i = 0; i < s.length(); i++) {       putchar(s[i]);     }   }   void Sangnt(bool nt[], int n) {     int x = sqrt(n);     nt[0] = true, nt[1] = true;     for (int i = 2; i <= x; i++) {       if (nt[i] == false) {         for (int j = i * i; j <= n; j += i) {           nt[j] = true;         }       }     }   }   void Congdon(int a[], int n) {     for (int i = 1; i < n; i++) {       a[i] += a[i - 1];     }   }   unsigned long long POW(int a, int b) {     if (b == 0) return 1;     unsigned long long y = POW(a, b / 2);     if (b % 2 == 0)       return y * y;     else       return y * y * a;   }   long long UCLN(long long x, long long y) {     long long r, a, b;     a = max(x, y), b = min(x, y);     while (b) {       r = a % b;       a = b, b = r;     }     return a;   }   string add(string a, string b) {     string ans;     while (a.length() < b.length()) a =  0  + a;     while (b.length() < a.length()) b =  0  + b;     ans = a;     int n = ans.length();     int digit, Add = 0;     for (int i = n - 1; i >= 0; i--) {       digit = (a[i] -  0  + b[i] -  0  + Add) % 10;       Add = (a[i] -  0  + b[i] -  0  + Add) / 10;       ans[i] = digit +  0 ;     }     if (Add == 1) ans =  1  + ans;     while (ans[0] ==  0  and ans.length() > 1) ans.erase(0, 1);     return ans;   }   string Minu(string a, string b) {     string ans;     while (a.length() < b.length()) a =  0  + a;     while (b.length() < a.length()) b =  0  + b;     ans = a;     int n = ans.length();     int digit, Add = 0;     for (int i = n - 1; i >= 0; i--) {       digit = a[i] - b[i] - Add;       if (digit < 0) {         digit = digit + 10;         Add = 1;       } else         Add = 0;       ans[i] = digit +  0 ;     }     while (ans[0] ==  0  and ans.length() > 1) ans.erase(0, 1);     return ans;   }   double a, b, c, x, y;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> a >> b >> c;     if (a == 0) {       if (b == 0) {         if (c == 0) {           cout << -1;         } else {           cout << 0;         }       } else {         cout << 1 << endl;         printf( %.10f , -c / b);       }     } else {       double delta = b * b - 4 * a * c;       if (delta == 0) {         x = -b / 2 / a;         cout << 1 << endl;         printf( %.10f , x);       } else if (delta < 0) {         cout << 0;       } else {         cout << 2 << endl;         x = -(b + sqrt(delta)) / 2 / a;         y = -(b - sqrt(delta)) / 2 / a;         if (x > y) {           swap(x, y);         }         printf( %.10f n , x);         printf( %.10f , y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7;   vector<int> check(int n, vector<int> a, int x) {     multiset<int> as;     for (auto u : a) {       as.insert(u);     }     vector<int> res;     for (int i = 0; i < n; ++i) {       auto it1 = as.end();       it1--;       int y = x - *it1;       as.erase(it1);       auto it2 = as.find(y);       if (it2 == as.end()) {         return {};       }       res.push_back(x - y);       res.push_back(y);       x = max(y, x - y);       as.erase(it2);     }     return res;   }   const int N = 3505;   int n, m, k;   int arr[N];   int get(int p, int s) {     int ans = (1 << 30);     for (int j = p; j + s <= m - 1; j++) {       ans = min(ans, max(arr[j], arr[n - (m - 1 - j) - 1]));     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       k = min(k, m - 1);       int ans = 0;       for (int i = 0; i < n; i++) scanf( %d , &arr[i]);       for (int i = 0; i <= k; i++) ans = max(ans, get(i, k - i));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int n, m, K, px[N], py[N];   bool check(int k) {     vector<int> cx, cy;     cx.push_back(1), cx.push_back(n), cx.push_back(n + 1), cy.push_back(1),         cy.push_back(m), cy.push_back(m + 1);     for (int i = 0; i < K; i++) {       cx.push_back(max(1, px[i] - k)), cx.push_back(min(n, px[i] + k + 1));       cy.push_back(max(1, py[i] - k)), cy.push_back(min(m, py[i] + k + 1));     }     sort(cx.begin(), cx.end()),         cx.resize(unique(cx.begin(), cx.end()) - cx.begin());     sort(cy.begin(), cy.end()),         cy.resize(unique(cy.begin(), cy.end()) - cy.begin());     vector<vector<int> > cs(cx.size(), vector<int>(cy.size()));     int mnx = 2e9, mxx = 0, mny = 2e9, mxy = 0;     for (int i = 0; i < K; i++) {       int lx = max(1, px[i] - k), rx = min(n, px[i] + k), ly = max(1, py[i] - k),           ry = min(py[i] + k, m);       for (int j = 0, l, r; j < cx.size() - 1; j++) {         l = cx[j], r = cx[j + 1] - 1;         if (l >= lx && r <= rx) {           l = lower_bound(cy.begin(), cy.end(), ly) - cy.begin();           r = upper_bound(cy.begin(), cy.end(), ry) - cy.begin();           cs[j][l]++, cs[j][r]--;         }       }     }     bool b = 0;     for (int i = 0; i < cs.size() - 1; i++)       for (int j = 0; j < cs[i].size() - 1; j++) {         if (j) cs[i][j] += cs[i][j - 1];         if (!cs[i][j]) {           b = 1;           mnx = min(mnx, cx[i]), mxx = max(mxx, cx[i + 1] - 1);           mny = min(mny, cy[j]), mxy = max(mxy, cy[j + 1] - 1);         }       }     return !b || ((mxx - mnx + 1 <= 2 * k + 1) && (mxy - mny + 1 <= 2 * k + 1));   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 0; i < K; i++) {       scanf( %d%d , &px[i], &py[i]);     }     int l = 0, r = max(n, m), ans = 1e9;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid)) {         ans = min(ans, mid);         r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   int n, k, t, a, b;   long long w, z, x[3008], y[3008];   int main() {     for (ios::sync_with_stdio(0), cin.tie(0), cin >> n >> k; n--; z = b = 0) {       for (cin >> t; t--;)         for (cin >> a, z += a, ++b, a = k + 1; a-- > b;              y[a] < (w = x[a - b] + z) ? y[a] = w : 0)           ;       for (a = k + 1; a--; x[a] = y[a])         ;     }     cout << x[k], exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int n, sum = 0, pos = 0, ans1 = 0, ans2 = 0;     cin >> n;     vector<unsigned long long int> vect;     vect.resize(n);     for (unsigned long long int i = 0; i < n; i++) {       cin >> vect[i];       sum += vect[i];     }     if (sum % n == 0) {       pos = sum / n;       for (unsigned long long int i = 0; i < n; i++) {         if (vect[i] > pos) {           ans1 += vect[i] - pos;         }       }       cout << ans1 << endl;     } else {       pos = (sum / n) + 1;       for (unsigned long long int i = 0; i < n; i++) {         if (vect[i] > pos) {           ans1 += vect[i] - pos;         } else if (vect[i] < pos - 1) {           ans2 += pos - 1 - vect[i];         }       }       cout << max(ans1, ans2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void karem() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     karem();     int n, s = 0, res = 0;     cin >> n;     vector<int> v(12);     for (int i = int(0); i < 12; i++) cin >> v[i];     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = int(0); i < 12; i++) {       if (s >= n) break;       s += v[i];       res++;     }     if (s < n)       cout << -1;     else       cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, a, b, c = 0;     cin >> n >> x;     while (n--) {       cin >> a >> b;       if (x == a || x == b || x == 7 - a || x == 7 - b) c++;       x = 7 - x;     }     if (c > 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void rf() {}   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int k = 0;     string s;     cin >> s;     k = 0;     for (int i = 0; i < s.size(); i++) {       if (k && s[i] ==  B ) {         k--;       } else {         k++;       }     }     cout << k << endl;   }   int main() {     fast();     rf();     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m;   int t;   int a[N];   string s;   int main() {     cin >> t;     while (t--) {       cin >> s;       int c = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  B ) c++;       }       if (s.length() % 2 == 0 && c == s.length() / 2)         puts( yes );       else         puts( no );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 1e5 + 10;   int n, ans = 0;   int dp[N][2];   vector<int> g[N];   void chkmax(int &first, int second) {     if (first < second) first = second;   }   void dfs(int u, int fa) {     dp[u][0] = dp[u][1] = 0;     int flag = 0;     for (int &v : g[u]) {       if (v == fa) continue;       dfs(v, u);       chkmax(dp[u][0], max(dp[v][0], dp[v][1]));       chkmax(dp[u][1], dp[v][0]);     }     int deg = g[u].size();     if (dp[u][0] <= 0)       dp[u][0] += deg - 1;     else       dp[u][0] += deg - 2;     dp[u][1] += 1;     int pre = 0;     for (int &v : g[u]) {       if (v == fa) continue;       chkmax(ans, pre + max(dp[v][0], dp[v][1]) + deg - 2);       chkmax(pre, max(dp[v][0], dp[v][1]));     }     chkmax(ans, pre + deg - 1);     pre = 0;     for (int &v : g[u]) {       if (v == fa) continue;       chkmax(ans, pre + dp[v][0] + 1);       chkmax(pre, dp[v][0]);     }     chkmax(ans, pre + 1);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       g[u].push_back(v), g[v].push_back(u);     }     dfs(1, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   int i, j, k, l, n, m, K[120], tmp, flag, bo;   struct point {     int x, y;   } a[120];   struct ppp {     double x, y;   } O;   double ans;   int dot(point &a, point &b, point &c, point &d) {     return (b.x - a.x) * (d.x - c.x) + (b.y - a.y) * (d.y - c.y);   }   double dist(ppp &a, point &b) {     return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));   }   void calc(double a, double b, double c, double d, double e, double f) {     O.y = (a * f - d * c) / (b * d - e * a);     O.x = (b * f - c * e) / (a * e - b * d);   }   bool Find(int x, int y) {     for (int i = 1; i <= n; ++i)       if (a[i].x == x && a[i].y == y) return 1;     return 0;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].y);     for (i = 1; i <= n; ++i) K[i] = a[i].x * a[i].x + a[i].y * a[i].y;     for (i = 1; i <= n; ++i)       for (j = i + 1; j <= n; ++j)         for (k = j + 1; k <= n; ++k) {           tmp = dot(a[i], a[j], a[i], a[k]);           bo = 0;           if (tmp < 0 || tmp == 0 && !Find(a[j].x + a[k].x - a[i].x,                                            a[j].y + a[k].y - a[i].y))             continue;           if (tmp == 0)             bo = 1, O.x = (a[j].x + a[k].x) / 2.0, O.y = (a[j].y + a[k].y) / 2.0;           tmp = dot(a[j], a[i], a[j], a[k]);           if (tmp < 0 || tmp == 0 && !Find(a[i].x + a[k].x - a[j].x,                                            a[i].y + a[k].y - a[j].y))             continue;           if (tmp == 0)             bo = 1, O.x = (a[i].x + a[k].x) / 2.0, O.y = (a[i].y + a[k].y) / 2.0;           tmp = dot(a[k], a[i], a[k], a[j]);           if (tmp < 0 || tmp == 0 && !Find(a[i].x + a[j].x - a[k].x,                                            a[i].y + a[j].y - a[k].y))             continue;           if (tmp == 0)             bo = 1, O.x = (a[i].x + a[j].x) / 2.0, O.y = (a[i].y + a[j].y) / 2.0;           if (!bo)             calc(a[j].x - a[i].x, a[j].y - a[i].y, (K[i] - K[j]) / 2.0,                  a[k].x - a[i].x, a[k].y - a[i].y, (K[i] - K[k]) / 2.0);           double R = dist(O, a[i]);           for (l = 1; l <= n; ++l)             if (l != i && l != j && l != k && dist(O, a[l]) + eps < R) break;           if (l <= n) continue;           ans = max(ans, R);           flag = 1;         }     if (!flag)       printf( -1 n );     else       printf( %.6lf n , ans);   }