#include<bits/stdc++.h>   using namespace std;   #define ll long long   template <typename Arg1>   //print with endl   void pn(Arg1&& arg1)   { cout<<arg1<<  n ;}   template <typename Arg1, typename... Args>   void pn(Arg1&& arg1, Args&&... args)   { cout<<arg1<<  n ; pn(args...); }    //print with space   template <typename Arg1>   void ps(Arg1&& arg1)   { cout<<arg1<<   ;}   template <typename Arg1, typename... Args>   void ps(Arg1&& arg1, Args&&... args)   { cout<<arg1<<   ; ps(args...); }       template <typename Arg1>   void pvs(Arg1&& arg1, ll n)   { for(ll i=0;i<n;i++)ps(arg1[i]); }   template <typename Arg1>   void pvn(Arg1&& arg1, ll n)   { for(ll i=0;i<n;i++)pn(arg1[i]); }      ll sum(ll n){       ll v=0;       while(n!=0){           v+=(n%10);           n/=10;       }       return v;   }       ll log(ll n, ll b)   { ll c=0;     while(n>(b-1))     { c++; n/=b; } return c; }   #define fast  ios::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL);   #define mod 1000000007 //10^9+7   #define st string   #define ull unsigned long long   #define pb push_back   #define mp make_pair   #define vi vector <int>   #define vll vector <long long>   #define f0(i,a) for(i=0;i<a;i++)   #define f1(i,a) for(i=1;i<=n;i++)   #define all(a) a.begin(),a.end()   #define sz(a) a.size()   #define lb lower_bound   #define ub upper_bound   #define pl pair<ll,ll>   #define vpl vector<pl>   #define ff first   #define ss second   #define um unordered_map   #define dsort(v) sort(v); reverse(v);   #define maxall(v) *max_element(all(v))   #define minall(v) *min_element(all(v))   #define gcd(a,b)        __gcd(a,b)   #define lcm(a,b)        a/__gcd(a,b)*b   #define Y                YES    #define N                NO    #define endl              n    #define debug(x)        cout << #x <<   :   << x << nl;   const ll MOD = 998244353;   const ll inf = 1e18;   const ll MAX = 2e5 + 1;   ll GCD(ll a,ll b){     if(b==0)       return a;     else        return GCD(b,a%b);   }   ll mulmod(ll x,ll n,ll M)   {       ll result=1;       while(n>0)       {           if(n% 2 ==1)               result=(result * x)%M;           x=(x*x)%M;           n=n/2;       }       return result;   }      /////////////////////////   bool isPowerOfTwo(ll n)    {        if (n == 0)            return 0;        while (n != 1)        {            if (n%2 != 0)                return 0;            n = n/2;        }        return 1;    }   void solve(){      ll i;      ll n;      cin>>n;      vll v(n);      f0(i,n) cin>>v[i];      f0(i,n){       if(v[i]&1)         cout<<v[i]<<   ;      }      f0(i,n){       if(!(v[i]&1))         cout<<v[i]<<   ;      }   cout<<endl;                     }   int main(){       fast;     #ifdef Local       freopen( inp.txt ,  r , stdin);      // freopen( out.txt ,  w , stdin);      #endif     // solve();/*     ll t;     cin>>t;     for(ll tt=1;tt<=t;tt++)     {       // cout<< Case # <<tt<< :  ;       solve();     }     //*/   }


#include <bits/stdc++.h>   using namespace std;   char str[40], ans[2][40], p[40];   int pre[40], sum[40];   int main() {     scanf( %s , str);     int L = 0, R = 0;     bool mark = true;     memset(pre, -1, sizeof(pre));     for (int i = 0; i < 27; i++) {       int a = str[i] -  A ;       sum[a]++;       if (pre[a] == -1)         pre[a] = i;       else {         L = pre[a];         R = i;         if (R - 1 == L) {           mark = false;         }       }     }     int k = 0;     for (int i = 0; i < 26; i++) {       if (sum[i] == 0 || sum[i] > 2) mark = false;       if (sum[i] == 2) k++;     }     if (k != 1 || !mark) {       printf( Impossible n );       return 0;     }     R = 26 - R;     int cnt = 0;     if (L > R) {       int o = 0;       for (int i = 26; i >= 0; i--) {         p[o++] = str[i];       }       for (int i = 0; i < 27; i++) str[i] = p[i];       swap(L, R);     }     int num = R - L;     if (num & 1) {       num = (num / 2) + 1;       int i;       for (i = num;; i++) {         if (cnt == L) break;         ans[0][i] = str[cnt++];       }       int flag = i - 1;       ans[1][i - 1] = str[cnt++];       for (; i < 13; i++) ans[0][i] = str[cnt++];       for (int i = 12; i > flag; i--) {         ans[1][i] = str[cnt++];       }       cnt++;       for (int i = flag - 1; i >= 0; i--) ans[1][i] = str[cnt++];       if (num) {         for (int i = 0; i < num; i++) ans[0][i] = str[cnt++];       }     } else {       num = num / 2;       int i;       for (i = num;; i++) {         if (cnt == L) break;         ans[0][i] = str[cnt++];       }       int flag = i;       ans[1][i] = str[cnt++];       for (; i < 13; i++) ans[0][i] = str[cnt++];       for (int i = 12; i > flag; i--) {         ans[1][i] = str[cnt++];       }       cnt++;       for (int i = flag - 1; i >= 0; i--) ans[1][i] = str[cnt++];       if (num) {         for (int i = 0; i < num; i++) ans[0][i] = str[cnt++];       }     }     if (L == 0 && R == 0) {       cnt = 0;       for (int i = 0; i < 13; i++) ans[0][i] = str[cnt++];       for (int i = 12; i >= 0; i--) ans[1][i] = str[cnt++];     }     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 13; j++) printf( %c , ans[i][j]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> V;   bool Do() {     while (V.size() > 0 && V.back() % 2 == 0) V.pop_back();     if (V.size() == 0) return false;     int sum = 0;     int p = -1;     for (int i = 0; i < V.size(); ++i) {       if (V[i] % 2 && i < V.size() - 1) p = i;       sum += V[i];     }     if (sum % 2 == 0)       return true;     else if (p == -1)       return false;     else {       for (int i = p; i + 1 < V.size(); ++i) V[i] = V[i + 1];       V.pop_back();       return true;     }   }   int main() {     int nr_t, nr;     char c;     cin >> nr_t;     for (int i = 1; i <= nr_t; ++i) {       cin >> N;       for (int j = 1; j <= N; ++j) {         cin >> c;         V.push_back(c -  0 );       }       if (!Do())         cout <<  -1  <<   n ;       else {         for (int i = 0; i < V.size(); ++i) cout << V[i];         cout <<   n ;       }       V.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void toogle(vector<vector<int> >& v, int i, int j) {     if (v[i][j] == 1) {       v[i][j] = 0;     } else if (v[i][j] == 0) {       v[i][j] = 1;     }   }   int main() {     vector<vector<int> > v(3, vector<int>(3, 1));     int i, j, e;     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         cin >> e;         if (e % 2 == 0) {           continue;         } else {           toogle(v, i, j);           if (i - 1 >= 0) toogle(v, i - 1, j);           if (j - 1 >= 0) toogle(v, i, j - 1);           if (i + 1 < 3) toogle(v, i + 1, j);           if (j + 1 < 3) toogle(v, i, j + 1);         }       }     }     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         cout << v[i][j];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, next;   } e[200010];   int n, m, q, cnt, father[100010], fa[100010][30], a[100010], dis[100010],       deep[100010], head[100010];   inline void add(int u, int v) {     cnt++;     e[cnt].to = v;     e[cnt].next = head[u];     head[u] = cnt;   }   inline int find(int x) {     return father[x] == x ? x : father[x] = find(father[x]);   }   inline void dfs(int u) {     deep[u] = deep[fa[u][0]] + 1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (!deep[v]) {         fa[v][0] = u;         dfs(v);         if (find(u) == find(v)) a[u] |= a[v];       } else if (deep[v] < deep[u] - 1) {         if ((deep[u] + deep[v] + 1) & 1) a[u] = 1;         for (int x = find(u); deep[x] > deep[v] + 1; x = find(x))           father[x] = fa[x][0];       }     }   }   inline void dfs2(int u) {     dis[u] += a[u];     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (deep[v] != deep[u] + 1) continue;       if (find(u) == find(v)) a[v] |= a[u];       dis[v] = dis[u];       dfs2(v);     }   }   inline int LCA(int x, int y) {     if (deep[x] > deep[y]) swap(x, y);     for (int i = 20; i >= 0; i--)       if (deep[fa[y][i]] >= deep[x]) y = fa[y][i];     if (x == y) return x;     for (int i = 20; i >= 0; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   inline bool check(int u, int v) {     if (!LCA(u, v)) return 0;     if ((deep[u] + deep[v]) & 1) return 1;     if (dis[u] + dis[v] - 2 * dis[LCA(u, v)]) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) father[i] = i;     for (int i = 1, x, y; i <= m; i++) {       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int i = 1; i <= n; i++)       if (!deep[i]) dfs(i), dfs2(i);     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];     scanf( %d , &q);     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       if (check(x, y))         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x;     vector<int> a, b, c;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x == 1)         a.push_back(i + 1);       else if (x == 2)         b.push_back(i + 1);       else         c.push_back(i + 1);     }     int res = min({a.size(), b.size(), c.size()});     cout << res << endl;     for (int i = 0; i < res; i++) {       cout << a[i] <<     << b[i] <<     << c[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int N = 1e6 + 100;   pair<int, int> seg[4 * N];   int lazy[4 * N];   void shift(int nod) {     lazy[nod * 2] += lazy[nod];     lazy[nod * 2 + 1] += lazy[nod];     seg[nod * 2].first += lazy[nod];     seg[nod * 2 + 1].first += lazy[nod];     seg[nod * 2].second += lazy[nod];     seg[nod * 2 + 1].second += lazy[nod];     lazy[nod] = 0;   }   void upd(int nod, int l, int r, int L, int R, int val) {     if (l >= R || L >= r) {       return;     }     if (l >= L && r <= R) {       seg[nod].first += val;       seg[nod].second += val;       lazy[nod] += val;       return;     }     shift(nod);     int mid = (r + l) / 2;     upd(nod * 2, l, mid, L, R, val);     upd(nod * 2 + 1, mid, r, L, R, val);     seg[nod].first = max(seg[nod * 2].first, seg[nod * 2 + 1].first);     seg[nod].second = min(seg[nod * 2].second, seg[nod * 2 + 1].second);   }   int a[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int cnt = 1;     int to = 0, tc = 0;     for (int i = 0; i < n; i++) {       char c;       cin >> c;       if (c ==  ( ) {         if (a[cnt] == 1) {           if (to != tc || seg[1].second < 0) {             cout << -1 <<   n ;           } else {             cout << seg[1].first <<   n ;           }           continue;         }         if (a[cnt] == 2) {           upd(1, 1, N, cnt, N, +2);           tc--;         } else {           upd(1, 1, N, cnt, N, 1);         }         a[cnt] = 1;         to++;       }       if (c ==  ) ) {         if (a[cnt] == 2) {           if (to != tc || seg[1].second < 0) {             cout << -1 <<   n ;           } else {             cout << seg[1].first <<   n ;           }           continue;         }         if (a[cnt] == 1) {           upd(1, 1, N, cnt, N, -2);           to--;         } else {           upd(1, 1, N, cnt, N, -1);         }         tc++;         a[cnt] = 2;       }       if (c ==  R ) {         cnt++;       }       if (c ==  L ) {         cnt--;       }       if (c >=  a  && c <=  z ) {         if (a[cnt] == 1) {           a[cnt] = 0;           upd(1, 1, N, cnt, N, -1);           to--;         }         if (a[cnt] == 2) {           a[cnt] = 0;           upd(1, 1, N, cnt, N, +1);           tc--;         }       }       cnt = max(cnt, (int)1);       if (to != tc || seg[1].second < 0) {         cout << -1 <<   n ;       } else {         cout << seg[1].first <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long k;     cin >> n >> k;     k -= (long long)n * (n + 1) / 2;     if (k < 0) {       cout << -1 << endl;       return 0;     }     long long sum = (long long)n * (n + 1) / 2;     vector<int> ans;     for (int i = n - 1; i >= 0; i--) {       int add = max(0, n - 1 - (n - 1 - i) * 2);       if (k > add) {         ans.push_back(i);         ans[n - 1 - i] = i;         k -= add;         sum += add;       } else {         for (int j = 0; j < i; j++) {           ans.push_back(j);         }         ans.insert(ans.begin() + (n - 1 - i) + (add - k), i);         sum += k;         break;       }     }     cout << sum << endl;     for (int i = 0; i < n; i++) {       cout << i + 1;       if (i < n - 1) {         cout <<    ;       }     }     cout << endl;     for (int i = 0; i < n; i++) {       cout << ans[i] + 1;       if (i < n - 1) {         cout <<    ;       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   int cnt[100 + 2][N + 2];   string s[100 + 2];   set<int> on[100 + 2], of[100 + 2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> s[i];       s[i] =  #  + s[i] +  # ;       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  . )           of[i].insert(j);         else           on[i].insert(j);       }       on[i].insert(0);       on[i].insert(m + 1);       of[i].insert(-1);       of[i].insert(m + 2);     }     long long ans = 0;     int a = 1, b = 1, d = 1;     while (true) {       if (clock() > CLOCKS_PER_SEC * 0.8) cout <<  Never n , exit(0);       if (a == n) break;       if (d) {         int cr = *on[a].lower_bound(b);         int nx = *of[a + 1].lower_bound(b);         if (nx < cr) {           ans += nx - b + 1;           a++;           b = nx;         } else {           ans += cr - b;           b = cr - 1;           d ^= 1;           if (s[a][cr] ==  + ) {             on[a].erase(cr);             s[a][cr] =  . ;             of[a].insert(cr);           }         }       } else {         auto it1 = on[a].upper_bound(b);         auto it2 = of[a + 1].upper_bound(b);         it1--, it2--;         int cr = *it1, nx = *it2;         if (nx > cr) {           ans += b - nx + 1;           a++;           b = nx;         } else {           ans += b - cr;           b = cr + 1;           d ^= 1;           if (s[a][cr] ==  + ) {             on[a].erase(cr);             s[a][cr] =  . ;             of[a].insert(cr);           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 998244353;   struct bucket {     long long size, minm;     vector<long long> off;     vector<long long> dps;     vector<long long> pre;     bucket(long long b) {       size = b;       off = vector<long long>(b);       pre = vector<long long>(b);       dps = vector<long long>(b);       minm = 0;     }     void updoff(long long p, long long l, long long r) {       assert(l >= 0 && l < size && r >= 0 && r < size && l <= r);       long long nmnm = INT_MAX;       for (long long j = l; j <= r; ++j) nmnm = min(nmnm, minm + off[j] + p);       for (long long j = 0; j < l; ++j) nmnm = min(nmnm, minm + off[j]);       for (long long j = r + 1; j < size; ++j) nmnm = min(nmnm, minm + off[j]);       for (long long j = 0; j < l; ++j) off[j] = off[j] + minm - nmnm;       for (long long j = l; j <= r; ++j) off[j] = off[j] + minm + p - nmnm;       for (long long j = r + 1; j < size; ++j) off[j] = off[j] + minm - nmnm;       minm = nmnm;       pre = vector<long long>(size);       for (long long j = 0; j < size; ++j)         pre[off[j]] = (pre[off[j]] + dps[j]) % mod;       for (long long j = 1; j < size; ++j) pre[j] = (pre[j] + pre[j - 1]) % mod;     }     void upddp(long long idx, long long newdp) {       dps[idx] = newdp;       pre = vector<long long>(size);       for (long long j = 0; j < size; ++j)         pre[off[j]] = (pre[off[j]] + dps[j]) % mod;       for (long long j = 1; j < size; ++j) pre[j] = (pre[j] + pre[j - 1]) % mod;     }   };   void update_offset(vector<bucket> &ds, long long n, long long l, long long r,                      long long p, long long b) {     assert(l <= r);     long long j = r / b;     ds[j].updoff(p, max(l, j * b) - j * b, r - j * b);     j--;     while (j * b > l) {       ds[j].minm += p;       j--;     }     if (l >= j * b && l < (j + 1) * b) ds[j].updoff(p, l - j * b, b - 1);   }   long long query(vector<bucket> &ds, long long n, long long r, long long b,                   long long k) {     long long j = r / b;     long long ret = 0;     while (j >= 0) {       long long idx = k - ds[j].minm;       if (idx >= 0) ret = (ret + ds[j].pre[min(idx, b - 1)]) % mod;       j--;     }     return ret;   }   int32_t main() {     long long n, k;     cin >> n >> k;     long long b = sqrt(n);     long long m = ceil((double)n / b);     vector<long long> a(n);     for (auto &x : a) cin >> x;     vector<bucket> ds;     for (long long i = 0; i < m; ++i) {       bucket B = bucket(b);       ds.push_back(B);     }     vector<long long> lo(n + 1, -1);     vector<long long> llo(n + 1, -1);     vector<long long> dp(n);     dp[0] = 1;     lo[a[0]] = 0;     ds[0].updoff(1, 0, 0);     ds[0].upddp(0, 1);     if ((1 / b) < m) ds[1 / b].upddp(1 - (1 / b) * b, 1);     for (long long i = 1; i < n; ++i) {       if (lo[a[i]] != -1) update_offset(ds, n, llo[a[i]] + 1, lo[a[i]], -1, b);       update_offset(ds, n, lo[a[i]] + 1, i, 1, b);       dp[i] = query(ds, n, i, b, k);       long long j = (i + 1) / b;       if (j < m) ds[j].upddp((i + 1) - j * b, dp[i]);       llo[a[i]] = lo[a[i]];       lo[a[i]] = i;     }     cout << dp[n - 1];   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   int main() {     int n;     cin >> n;     int k = min(n, 4);     for (int i = 0; i < k; i++)       for (int j = i; j < n; j += 4) s[j] = i +  a ;     s[n] =   0 ;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   vector<pair<int, int> > headd[10][2];   bitset<10000000> used;   int ad[10000000];   bool valid(long long x) {     int lt = x % 10;     x /= 10;     int flag = 0;     while (x) {       int tmp = x % 10;       x /= 10;       if (tmp < lt) {         if (flag == -1) return false;         flag = -1;       } else if (tmp > lt) {         if (flag == 1) return false;         flag = 1;       } else         return false;       lt = tmp;     }     return true;   }   int check(int st, long long N, int ud, long long& K, long long need) {     if (need >= 10000000) return -1;     int ker = lower_bound((headd[st][ud]).begin(), (headd[st][ud]).end(),                           make_pair((int)need, 0)) -               headd[st][ud].begin();     int ker2 = lower_bound((headd[st][ud]).begin(), (headd[st][ud]).end(),                            make_pair((int)need + 1, 0)) -                headd[st][ud].begin();     if (ker2 - ker < K) {       K -= ker2 - ker;       return -1;     }     for (int i = (ker); i < (((int)(headd[st][ud]).size())); ++i) {       K--;       if (K == 0) return headd[st][ud][i].second;     }     return -1;   }   int main() {     long long N, K;     cin >> N >> K;     if (N > (1e14 + 3) / K) {       puts( -1 );       return 0;     }     if (N > 10000000) {       for (long long now = N; now < 100000000000000LL; now += N) {         if (valid(now)) {           K--;           if (!K) {             cout << now << endl;             return 0;           }         }       }       cout << -1 << endl;       return 0;     }     int tmp[8] = {};     for (int i = (1); i < (10000000); ++i) {       tmp[0]++;       int now = 0;       while (tmp[now] == 10) {         tmp[now] = 0;         now++;         tmp[now]++;       }       bool err = 0;       for (int j = (1); j < (6); ++j) {         if ((tmp[j] - tmp[j - 1]) * (tmp[j] - tmp[j + 1]) <= 0) {           err = 1;           break;         }       }       if (!err) {         headd[tmp[6]][(tmp[6] < tmp[5]) ? 1 : 0].push_back(make_pair(i % N, i));       }     }     for (int i = 0; i < (10); ++i)       for (int j = 0; j < (2); ++j)         sort((headd[i][j]).begin(), (headd[i][j]).end());     for (long long now = 1; now < 10000000; now++) {       if ((now / 10) % 10 == now % 10) continue;       int ha = ((now / 10) % 10) < (now % 10) ? 1 : -1;       if (now < 10 || (used[now / 10] && (ad[now / 10] != ha))) {         if (now < 10) ha = 0;         if (now % N == 0) {           K--;           if (K == 0) {             cout << now << endl;             return 0;           }         }         ad[now] = ha;         used[now] = 1;       }     }     for (int i = (1); i < (10000000); ++i) {       if (used[i]) {         int tail = i % 10;         int flag = 0;         if (i >= 10) {           if ((i / 10) % 10 < tail)             flag = 1;           else             flag = -1;         }         long long r = (i * 10000000LL) % N;         long long need = N - r;         if (need == N) need = 0;         if (flag != -1) {           for (int j = 0; j < (tail); ++j) {             int res = check(j, N, 1, K, need);             if (res >= 0) {               printf( %d%07d n , i, res);               return 0;             }           }         }         if (flag != 1)           for (int j = (tail + 1); j < (10); ++j) {             int res = check(j, N, 0, K, need);             if (res >= 0) {               printf( %d%07d n , i, res);               return 0;             }           }       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int foot = n / 36;     float b = n % 36;     int kkk = b / 3;     double kk = kkk + 0.5;     float inch = b / 3;     if (inch >= kk)       inch = ceil(inch);     else if (inch < kk)       inch = floor(inch);     int sss = (float)(inch);     if (sss % 12 == 0) {       inch = 0;       foot += (sss / 12);     }     cout << foot <<     << inch;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.14159265359;   long long max(long long a, long long b) {     if (a >= b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a <= b)       return a;     else       return b;   }   bool valid(int i, int j, long long n, long long m) {     if (i >= 0 && i < n && j >= 0 && j < m)       return 1;     else       return 0;   }   void yes() { cout <<  YES  <<   n ; }   void no() { cout <<  NO  <<   n ; }   vector<unsigned long long> divisor(10000007);   void printDivisors(long long n) {     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i) {           divisor[n] += i;         } else {           divisor[n] += i;           divisor[n] += n / i;         }       }     }   }   bool prime[1200000];   map<long long, long long> primes;   void SieveOfEratosthenes(long long n = 1200000) {     memset(prime, true, sizeof(prime));     prime[1] = false;     for (int p = 2; p * p < n; p++) {       if (prime[p] == true) {         for (int i = p * 2; i < n; i += p) prime[i] = false;       }     }     for (int i = 1; i < n + 1; i++)       if (prime[i]) {         primes[i]++;       }   }   int gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   string toBinary(long long n) {     string r;     while (n != 0) {       r = (n % 2 == 0 ?  0  :  1 ) + r;       n /= 2;     }     return r;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   map<long long, long long> PF;   void primeFactors(long long n) {     while (n % 2 == 0) {       PF[2]++;       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         PF[i]++;         n = n / i;       }     }     if (n > 2) PF[n]++;   }   long double intlog(long long base, long long x) {     long double ans1 = log10(x), ans2 = log10(base);     return (long double)(ans1 / ans2);   }   bool IsPowerOfTwo(long long x) { return (x & (x - 1)) == 0; }   map<long long, long long> LN;   void GetLuckyNumbers(string s) {     if (s.size() > 10) return;     GetLuckyNumbers(s +  4 );     if (s !=   ) LN[stoll(s)]++;     GetLuckyNumbers(s +  7 );     if (s !=   ) LN[stoll(s)]++;   }   unsigned long long toDecimal(unsigned long long n) {     unsigned long long num = n;     unsigned long long dec_value = 0;     unsigned long long base = 1;     int temp = num;     while (temp) {       unsigned long long last_digit = temp % 10;       temp = temp / 10;       dec_value += last_digit * base;       base = base * 2;     }     return dec_value;   }   long double power(long double b, long long p) {     if (p == 0)       return 1;     else if (p == 1)       return b;     long double a = power(b, p / 2);     if (p % 2 == 0) return (a) * (a);     return (b) * (a) * (a);   }   long largest_power_of_two(long N) {     N = N | (N >> 1);     N = N | (N >> 2);     N = N | (N >> 4);     N = N | (N >> 8);     return (N + 1) >> 1;   }   long long cnt(string s) {     long long c = 0;     for (int i = 0; i < s.size(); i++) c += s[i] -  0 ;     return c;   }   bool ispal(string s) {     for (int i = 0; i < s.size() / 2; i++) {       if (s[i] != s[s.size() - i - 1]) return false;     }     return true;   }   map<string, long long> substrings;   void subString(string s, long long n) {     for (int i = 0; i < n; i++)       for (int len = 1; len <= n - i; len++) {         substrings[s.substr(i, len)]++;       }   }   bool check_divisabilty_prefix(string str, long long a) {     long long len = str.size();     vector<int> lr(len + 1, 0);     lr[0] = (str[0] -  0 ) % a;     for (int i = 1; i < len; i++)       lr[i] = ((lr[i - 1] * 10) % a + (str[i] -  0 )) % a;     if (lr[len - 1] == 0) return 1;     return 0;   }   bool check_divisabilty_suffix(string str, long long b) {     long long len = str.size();     vector<long long> rl(len + 1, 0);     rl[len - 1] = (str[len - 1] -  0 ) % b;     int power10 = 10;     for (int i = len - 2; i >= 0; i--) {       rl[i] = (rl[i + 1] + (str[i] -  0 ) * power10) % b;       power10 = (power10 * 10) % b;     }     if (rl[0] == 0) return 1;     return 0;   }   bool isSubSeq(int idx1, int idx2, string s1, string s2) {     if (idx2 == s2.size()) return true;     if (idx1 == s1.size()) return false;     if (s1[idx1] == s2[idx2])       return isSubSeq(idx1 + 1, idx2 + 1, s1, s2);     else       return isSubSeq(idx1 + 1, idx2, s1, s2);   }   vector<long long> v;   long long bs(long long st, long long en, long long rq, long long val) {     long long ans;     while (st <= en) {       long long mid = (st + en) / 2;       long long aa = v[mid] - v[rq];       if (aa <= val) {         st = mid + 1;         ans = mid;       } else         en = mid - 1;     }     return abs(ans - rq);   }   bool isPerfectSquare(long double x) {     if (x >= 0) {       long long sr = sqrt(x);       return (sr * sr == x);     }     return false;   }   long long fn(long long s) {     if (s < 10) return s;     long long pr = 1;     while (s) {       if (s % 10) pr *= (s % 10);       s /= 10;     }     return fn(pr);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     vector<vector<long long> > v(11, vector<long long>(1e6 + 1, 0));     for (int i = 1; i <= 1000000; i++) {       v[fn(i)].push_back(i);     }     int n;     long long x;     cin >> x;     while (x--) {       long long start, endd, nm;       cin >> start >> endd >> nm;       long long lower =           lower_bound(v[nm].begin(), v[nm].end(), start) - v[nm].begin();       long long upper =           lower_bound(v[nm].begin(), v[nm].end(), endd) - v[nm].begin();       if (v[nm][upper] == endd) {         cout << (upper - lower) + 1 << endl;       } else {         cout << upper - lower << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename INT>   struct TripleDXY {     INT d, x, y;     TripleDXY(INT _d = 0, INT _x = 0, INT _y = 0) : d(_d), x(_x), y(_y) {}   };   template <typename INT>   TripleDXY<INT> egcd(INT a, INT b) {     bool neg_a = a < 0;     if (neg_a) a = -a;     bool neg_b = b < 0;     if (neg_b) b = -b;     INT x = 0, lastx = 1;     INT y = 1, lasty = 0;     while (b != 0) {       INT t = b;       INT q = a / b;       b = a % b;       a = t;       t = x;       x = lastx - q * x;       lastx = t;       t = y;       y = lasty - q * y;       lasty = t;     }     return TripleDXY<INT>(a, neg_a ? -lastx : lastx, neg_b ? -lasty : lasty);   }   long long ChooseMod(int n, int k, int M) {     long long res = 1;     for (int i = 1; i <= k; ++i, --n) {       TripleDXY<int> R = egcd(i, M);       assert(R.d == 1);       res = (res * n) % M;       res = (res * R.x) % M;       if (res < 0) res += M;     }     return res;   }   int N, K;   long long A[2004];   long long R[2004];   long long F[2004];   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> N >> K;     F[0] = 1;     for (int i = 1; i < N; ++i) {       F[i] = ChooseMod(K - 1 + i, i, 1000000007);     }     for (int i = 0; i < N; ++i) cin >> A[i];     R[0] = A[0] % 1000000007;     for (int i = 1; i < N; ++i) {       R[i] = 0;       for (int j = 0; j <= i; ++j) {         R[i] += (A[j] * F[i - j]);         R[i] %= 1000000007;       }     }     for (int i = 0; i < N; ++i) cout << R[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s1;     cin >> s1;     string s2;     cin >> s2;     string s3;     cin >> s3;     vector<pair<char, int> > cnt(26);     for (int i = int(0); i < int(int(s1.size())); i++) {       char c = s1[i];       int pos = tolower(c) -  a ;       cnt[pos].second += 0;       cnt[pos].first = c;     }     for (int i = int(0); i < int(int(s2.size())); i++) {       char c = s2[i];       int pos = tolower(c) -  a ;       cnt[pos].second += 0;       cnt[pos].first = c;     }     for (int i = int(0); i < int(int(s3.size())); i++) {       char c = s3[i];       int pos = tolower(c) -  a ;       cnt[pos].second += 1;       cnt[pos].first = c;     }     for (int i = int(0); i < int(int(s1.size())); i++) {       for (int j = int(0); j < int(26); j++) {         if (s1[i] == cnt[j].first) {           cnt[j].second -= 1;         }       }     }     for (int i = int(0); i < int(int(s2.size())); i++) {       for (int j = int(0); j < int(26); j++) {         if (s2[i] == cnt[j].first) {           cnt[j].second -= 1;         }       }     }     for (int i = int(0); i < int(26); i++) {       if (cnt[i].second < 0 || cnt[i].second > 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   long long ar[5000005];   int main() {     string s;     cin >> s;     long long sz = s.size();     long long cnt = 0;     for (int i = 0; i < sz; i++) {       long long l = 0, w = 0;       for (int j = i; j < sz; j++) {         if (s[j] ==  ( )           l++;         else if (s[j] ==  ) )           l--;         else           w++;         if (w > l && w != 0) {           w--;           l++;         }         if (l < 0) break;         if (w == l) cnt++;       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <class A>   void read(vector<A>& v);   template <class A, size_t S>   void read(array<A, S>& a);   template <class T>   void read(T& x) {     cin >> x;   }   void read(double& d) {     string t;     read(t);     d = stod(t);   }   void read(long double& d) {     string t;     read(t);     d = stold(t);   }   template <class H, class... T>   void read(H& h, T&... t) {     read(h);     read(t...);   }   template <class A>   void read(vector<A>& x) {     for (auto& a : x) read(a);   }   template <class A, size_t S>   void read(array<A, S>& x) {     for (auto& a : x) read(a);   }   const int MAXN = 2e5 + 5;   long long mod = 1e9 + 7;   vector<long long> gr[200005];   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     read(a);     long long val = 0;     for (long long i = int(1); i < int(n); i++) {       if (a[i] < a[i - 1]) {         val += a[i - 1] - a[i];       }       if (val > a[0]) {         cout <<  NO               <<   n ;         return;       }     }     cout <<  YES           <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     test = 1;     cin >> test;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   #define il inline   #define ll long long   const int N=2e5+5,B=316;      int n,q,b[N],c[N]; ll a[N],lz[N];      il int jump(int x){return x?std::max(a[x]-lz[x/B],0ll):-1;}      il void rebuild(int x,int v)   {    if (c[x]+v>B) return ; c[x]+=v; int i;    for (i=x*B; i<x*B+B; i++) b[i]=jump(i)<x*B?i:b[jump(i)];   }      il void add(int x,int y,int v)   {    int i; for (i=x/B*B; i<x; i++) a[i]+=v;    for (i=y+1; i<y/B*B+B; i++) a[i]+=v;    for (i=x/B; i<=y/B; i++) lz[i]+=v,rebuild(i,i!=x/B&&i!=y/B);   }      il int LCA(int x,int y)   {    for ( ; b[x]!=b[y]; x=jump(b[x])) if (jump(b[x])<jump(b[y])) std::swap(x,y);    for ( ; x!=y; x=jump(x)) if (x<y) std::swap(x,y); return x;   }      int main()   {    scanf( %d%d ,&n,&q),a[0]=-1; int i,x,y,k;    for (i=1; i<n; i++) scanf( %d ,a+i),a[i]--;        for (add(0,n-1,0); q; q--)     if (scanf( %d%d%d ,&i,&x,&y),i>1) printf( %d n ,LCA(x-1,y-1)+1);     else scanf( %d ,&k),add(x-1,y-1,k);        return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pi {     bool dir;     int node;     int edge;   };   const int mxn = 200005;   int n;   vector<pi> graph[mxn];   int dp1[mxn];   vector<int> vv;   int ans = 1000000000;   void dfs1(int v, int p) {     for (int i = 0; i < graph[v].size(); i++) {       pi u = graph[v][i];       if (u.node == p) continue;       dfs1(u.node, v);       dp1[v] += dp1[u.node];       if (u.dir) dp1[v]++;     }   }   void dfs2(int v, int p, int l) {     int temp = l + dp1[v];     if (ans == (n - 1) - temp)       vv.push_back(v);     else if (ans > (n - 1) - temp) {       vv.clear();       vv.push_back(v);       ans = (n - 1) - temp;     }     for (int i = 0; i < graph[v].size(); i++) {       pi u = graph[v][i];       if (u.node == p) continue;       int something = temp - dp1[u.node];       if (u.dir)         something--;       else         something++;       dfs2(u.node, v, something);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       pi temp;       temp.dir = 1;       temp.node = y;       temp.edge = i;       graph[x].push_back(temp);       temp.dir = 0;       temp.node = x;       graph[y].push_back(temp);     }     dfs1(1, 1);     dfs2(1, 1, 0);     printf( %d n , ans);     sort(vv.begin(), vv.end());     printf( %d , vv[0]);     for (int i = 1; i < vv.size(); i++) printf(  %d , vv[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pi = pair<ll, ll>;   const ll inf = 0x3f3f3f3f3f3f3f3f;   const ll minf = 0xc0c0c0c0c0c0c0c0;   ll A[400400];   ll B[400400];   inline bool between(ll le, ll ri, ll first) {     return le <= first && first <= ri;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     ll n;     cin >> n;     for (ll i = 1; i <= n; i++) cin >> A[i];     ll res = 0;     for (ll bit = 0; bit <= 24; bit++) {       memcpy(B, A, sizeof(ll) * (n + 5));       ll mask = (1 << (bit + 1)) - 1;       for (ll i = 1; i <= n; i++) {         B[i] &= mask;       }       sort(B + 1, B + n + 1);       ll cnt = 0;       for (ll i = 1; i <= n; i++) {         cnt += (upper_bound(B + 1, B + n + 1, (1 << bit + 1) - 1 - B[i]) - B) -                (lower_bound(B + 1, B + n + 1, (1 << bit) - B[i]) - B);         if ((1 << bit) - B[i] <= B[i] && B[i] <= (1 << bit + 1) - 1 - B[i]) --cnt;         cnt +=             (upper_bound(B + 1, B + n + 1, (1 << bit + 2) - 2 - B[i]) - B) -             (lower_bound(B + 1, B + n + 1, (1 << bit) + (1 << bit + 1) - B[i]) -              B);         if (((1 << bit) + (1 << bit + 1)) - B[i] <= B[i] &&             B[i] <= (1 << bit + 2) - 2 - B[i])           --cnt;       }       assert(cnt % 2 == 0);       cnt /= 2;       if (cnt & 1) res |= (1 << bit);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void work();   int main() {     work();     return 0;   }   char S[222222];   char T[222222];   int t[256][256];   void work() {     int n;     while (scanf( %d , &n) == 1) {       memset(t, 0, sizeof(t));       int ans = 0;       scanf( %s%s , S + 1, T + 1);       for (int i = (1), END = (n); i <= END; i++)         if (S[i] != T[i]) {           ans++;           t[S[i]][T[i]] = i;         }       bool two = false;       for (int i = ( a ), END = ( z ); i <= END; i++)         for (int j = (i + 1), END = ( z ); j <= END; j++)           if (t[i][j] && t[j][i]) {             two = true;             printf( %d n%d %d n , ans - 2, t[i][j], t[j][i]);             i = 256;             j = 256;           }       if (two) continue;       for (int i = ( A ), END = ( Z ); i <= END; i++)         for (int j = (i + 1), END = ( Z ); j <= END; j++)           if (t[i][j] && t[j][i]) {             two = true;             printf( %d n%d %d n , ans - 2, t[i][j], t[j][i]);             i = 256;             j = 256;           }       if (two) continue;       bool one = false;       for (int i = ( a ), END = ( z ); i <= END; i++) {         int pos = -1;         for (int j = ( a ), END = ( z ); j <= END; j++)           if (t[i][j]) pos = t[i][j];         if (pos == -1) continue;         for (int j = ( a ), END = ( z ); j <= END; j++)           if (t[j][i]) {             one = true;             printf( %d n%d %d n , ans - 1, pos, t[j][i]);             i = j = 256;           }       }       if (one) continue;       for (int i = ( A ), END = ( Z ); i <= END; i++) {         int pos = -1;         for (int j = ( A ), END = ( Z ); j <= END; j++)           if (t[i][j]) pos = t[i][j];         if (pos == -1) continue;         for (int j = ( A ), END = ( Z ); j <= END; j++)           if (t[j][i]) {             one = true;             printf( %d n%d %d n , ans - 1, pos, t[j][i]);             i = j = 256;           }       }       if (one) continue;       printf( %d n%d %d n , ans, -1, -1);     }   }


#include <bits/stdc++.h>   using namespace std;   int h;   int seq[200010];   int par[200010];   int cur, cur_par, rem = -1, rem_par;   int main() {     scanf( %d , &(h));     for (int i = 0; i < h + 1; i++) scanf( %d , &(seq[i]));     cur_par = 1;     cur = 1;     for (int i = 0; i < h; i++) {       if (rem == -1 && seq[i] > 1 && seq[i + 1] > 1) {         puts( ambiguous );         rem = cur;         rem_par = cur_par;       }       for (int j = 0; j < seq[i + 1]; j++) par[cur + j] = cur_par;       cur += seq[i + 1];       cur_par = cur;     }     if (rem == -1) {       puts( perfect );       return 0;     }     for (int i = 0; i < cur; i++) printf( %d  , par[i]);     puts(  );     par[rem] = rem_par - 1;     for (int i = 0; i < cur; i++) printf( %d  , par[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   long long a[MAXN], dp[MAXN];   int main() {     long long n, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = n - 2; i >= 0; i--) {       dp[i] = dp[i + 1];       if (a[i + 1] == 0) dp[i]++;     }     for (int i = 0; i < n; i++)       if (a[i] == 1) ans += dp[i];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);   }   int main() {     FastIO();     int A, B;     while (cin >> A >> B) {       int M = min(A, B);       int N = max(A - M, B - M);       cout << M <<     << N / 2 << endl;     }     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m, loc, t;   long long now;   class SegTree {    private:     long long F2(long long k) { return 1 << (long long)ceil(log2(k)); }     vector<long long> seg;     void Merge(long long cur) { seg[cur] = seg[2 * cur] + seg[2 * cur + 1]; }       public:     SegTree(long long n) {       m = F2(n);       for (long long i = 0; i < 2 * m + 2; i++) seg.push_back(0);     }     void Add(long long loc, long long cur = 1, long long l = 1, long long r = m) {       if (r < l || r < loc || loc < l)         return;       else if (l == r)         return void(seg[cur]++);       long long mid = (l + r) / 2;       Add(loc, 2 * cur, l, mid);       Add(loc, 2 * cur + 1, mid + 1, r);       Merge(cur);     }     long long Get(long long a, long long b, long long cur = 1, long long l = 1,                   long long r = m) {       if (r < l || r < a || b < l)         return 0;       else if (a <= l && r <= b)         return seg[cur];       long long mid = (l + r) / 2;       long long x = Get(a, b, 2 * cur, l, mid);       long long y = Get(a, b, 2 * cur + 1, mid + 1, r);       return x + y;     }     long long BinarySearch(long long a, long long l = 1, long long r = now) {       if (r < l) return a;       long long mid = (l + r) / 2;       if (!Get(a + 1, mid)) return max(mid, BinarySearch(a, mid + 1, r));       return BinarySearch(a, l, mid - 1);     }   };   vector<pair<long long, long long>> v;   int main() {     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       now = n;       loc = 0;       long long a[n + 1];       v.clear();       SegTree s(n);       for (long long i = 0; i < n; i++) {         cin >> t;         if (t < loc) s.Add(i + 1);         loc = t;         a[i + 1] = t;       }       loc = 2;       long long ans = 1;       long long last = 1, cur = 0;       while (loc <= n) {         if (last == 0) swap(last, cur), ans++;         last--;         long long now = s.BinarySearch(loc + 1);         if (loc == n)           now = loc;         else if (a[loc + 1] < a[loc])           now = loc;         cur += now - loc + 1;         loc = now + 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, T, t[1005] = {0}, v;   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v);       t[v]++;     }     scanf( %d , &T);     int ans = 0, sum = 0;     for (int i = 1; i <= 1000; i++) {       sum += t[i];       if (i > T + 1) sum -= t[i - T - 1];       if (sum > ans) ans = sum;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int n, k;       cin >> n >> k;       int s[n];       char c;       for (int i = 0; i < n; i++) {         cin >> c;         if (c ==  R )           s[i] = 0;         else if (c ==  G )           s[i] = 1;         else           s[i] = 2;       }       int counter1 = 0;       int counter2 = 0;       int counter3 = 0;       int myMin = k;       for (int l = 0; l < k; l++) {         if (s[l] != l % 3) {           counter1++;         }         if (s[l] != (l + 1) % 3) {           counter2++;         }         if (s[l] != (l + 2) % 3) {           counter3++;         }       }       myMin = min(myMin, min(counter1, min(counter2, counter3)));       for (int j = 0; j < n - k; j++) {         if (j % 3 != s[j]) {           counter1--;         }         if ((k + j) % 3 != s[j + k]) {           counter1++;         }         if ((j + 1) % 3 != s[j]) {           counter2--;         }         if ((k + j + 1) % 3 != s[j + k]) {           counter2++;         }         if ((j + 2) % 3 != s[j]) {           counter3--;         }         if ((k + j + 2) % 3 != s[j + k]) {           counter3++;         }         myMin = min(myMin, min(counter1, min(counter2, counter3)));       }       cout << myMin << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d %d , &a, &b);     int fc, uc, df, sum = 0;     fc = a;     uc = 0;     df = b;     while (1) {       sum += fc;       if (fc == 0 && uc < df) break;       uc += fc;       fc = uc / df;       uc = uc % df;     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N;   bool ask(long long n) {     cout <<  ?   << n << endl;     bool res;     cin >> res;     return res;   }   void solve() {     cin >> N;     long long l = 1;     long long r = N - 1;     long long delta = 0;     long long start = N;     bool t = false;     while (l <= r) {       long long m = (l + r) >> 1;       delta += t ? -m : m;       start = min(start, N - delta);       l = m + 1;       t = !t;     }     l = 1;     r = N - 1;     t = false;     long long ans = N;     ask(start);     while (l <= r) {       long long m = (l + r) >> 1;       long long ns = start + (t ? -m : m);       if (ask(ns)) {         ans = m;         r = m - 1;       } else {         l = m + 1;       }       t = !t;       start = ns;     }     cout <<  =   << ans << endl;     return;   }   int main() {     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int in;     cin >> n >> m;     vector<int> v(n + 1, 0);     for (int i = 1; i <= n; ++i) {       cin >> in;       v[i] = in;     }     int a, b;     double c = 0;     double ret = 0;     for (int i = 0; i < m; ++i) {       cin >> a >> b >> c;       ret = max((double)((v[a] + v[b]) / c), ret);     }     cout << fixed << std::setprecision(10) << ret << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 405;   int n, ans = -1;   int c[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 2; i <= n; i++) {       for (int j = i; j <= n; j++) {         int p = c[i - 1] - 1, cnt = 1, w = c[j];         for (int k = i; k <= j; k++) {           cnt += p / c[k];           w += p / c[k] * c[k];           p %= c[k];         }         p = w;         for (int k = 1; k <= n; k++) {           cnt -= p / c[k];           p %= c[k];         }         if (cnt < 0 && (ans == -1 || w < ans)) ans = w;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100 + 13;   int N, M;   int s[maxN][maxN];   void enlarge(int x, int y, int l) {     int col = s[x][y];     for (int i = x; i <= x + l; i++)       for (int j = y; j <= y + l; j++) s[i][j] = col;     return;   }   void paint(int x, int y) {     int col = 0;     for (int i = 1; i <= 26; i++) {       if (i != s[x - 1][y] && i != s[x][y - 1] && i != s[x][y + 1]) {         col = i;         break;       }     }     s[x][y] = col;     int r = M;     for (int i = y + 1; i <= M; i++) {       if (s[x][i] == col || s[x - 1][i] == col) {         r = i - 1;         break;       }       if (s[x][i]) {         r = i - 1;         break;       }       bool flag(false);       for (int j = 1; j < col; j++) {         if (j != s[x - 1][i]) {           flag = true;           r = i - 1;           break;         }       }       if (flag) break;     }     r -= y;     r = min(N - x, r);     enlarge(x, y, r);     return;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i <= N; i++) s[i][0] = 30;     for (int i = 0; i <= M; i++) s[0][i] = 30;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++)         if (s[i][j] == 0) paint(i, j);     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) cout << (char)(s[i][j] - 1 +  A );       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class TaskA {    public:     void solve(istream& in, ostream& out) {       int n, m;       in >> n >> m;       int cell = m - 1;       for (int i = 0; i < n; ++i) {         if (i & 1) {           for (int j = 0; j < m; ++j) out << (j == cell ?  #  :  . );           cell = (cell == m - 1 ? 0 : m - 1);         } else           for (int j = 0; j < m; ++j) out <<  # ;         out <<   n ;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     TaskA solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   vector<int> ps[200000];   int sum[200000];   int main() {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       int n;       cin >> n;       for (int i = 0; i < n; i++) ps[i].clear();       for (int i = 0; i < n; i++) {         int p, m;         cin >> m >> p;         ps[m].push_back(p);       }       sum[0] = 0;       for (int i = 0; i + 1 < n; i++) {         sum[i + 1] = sum[i] + ps[i].size();       }       priority_queue<int, vector<int>, greater<int>> Q;       int cnt = 0;       long long ans = 0;       for (int i = n - 1; i >= 0; i--) {         for (int p : ps[i]) Q.push(p);         int k = max(i - sum[i] - cnt, 0);         for (int j = 0; j < k; j++) {           ans += Q.top();           Q.pop();         }         cnt += k;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<long long int, pair<int, bool> > p[200005 << 1];   long long int a[200005], tree[200005 << 2][2];   long long int get(int n, int b, int e, int i, int j, bool c) {     if (i > j || j < b || e < i) return 0;     if (i <= b && j >= e) return tree[n][c];     int l, r, m;     m = (b + e) >> 1;     l = (n << 1) + 1;     r = l + 1;     return max(get(l, b, m, i, j, c), get(r, m + 1, e, i, j, c));   }   void update(int n, int b, int e, int i, long long int v, bool c) {     if (i < b || i > e) return;     if (b == e) {       tree[n][c] = v;       return;     }     int l, r, m;     m = (b + e) >> 1;     l = (n << 1) + 1;     r = l + 1;     update(l, b, m, i, v, c);     update(r, m + 1, e, i, v, c);     tree[n][c] = max(tree[l][c], tree[r][c]);   }   int main() {     int n;     long long int t;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       p[i] = make_pair(a[i] - i, make_pair(i, 1));       if (i > 0) p[i + n - 1] = make_pair(a[i] - i + 1, make_pair(i - 1, 0));     }     int m = 2 * n - 1;     sort(p, p + m);     for (int i = 0; i < m; i++) {       t = get(0, 0, n - 1, 0, p[i].second.first - 1, 1);       if (!p[i].second.second)         t = max(t, get(0, 0, n - 1, 0, p[i].second.first - 1, 0));       update(0, 0, n - 1, p[i].second.first, t + 1, p[i].second.second);     }     printf( %lld n , max(0ll, n - 1 - max(tree[0][1], tree[0][0])));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, k, n, m, res, c1, c0;   long long a[200009];   string s;   set<long long> st;   queue<long long> q;   int main() {     int nt;     cin >> nt;     while (nt--) {       cin >> s;       s =  R  + s;       s +=  R ;       long long last = 0, res = 0;       for (i = 0; i < s.length(); i++) {         if (s[i] ==  R ) res = max(res, i - last), last = i;       }       cout << res <<   n ;     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     int a[400010], size, n, dl, dr, dir, len;     inline void set(int x, int v) {       int k = v - query(x, x);       for (; x <= size; x += ((x) & (-(x)))) a[x] += k;     }     inline void add(int x, int v) {       for (; x <= size; x += ((x) & (-(x)))) a[x] += v;     }     inline int query(int x) {       int res = 0;       for (; x; x -= ((x) & (-(x)))) res += a[x];       return res;     }     inline int query(int l, int r) { return query(r) - query(l - 1); }     inline void ope1(int x) {       if (x > len - x) dir = -dir, x = len - x;       if (dir == 1) {         dl += x;         for (int i = 1; i <= x; i++) {           add(dl + i, query(dl - i + 1, dl - i + 1));           set(dl - i + 1, 0);         }       } else {         dr += x;         for (int i = 1; i <= x; i++) {           add(n - (dr + i) + 1, query(n - (dr - i), n - (dr - i)));           set(n - (dr - i), 0);         }       }       len = max(x, len - x);     }     inline void ope2(int l, int r) {       if (dir == 1)         printf( %d n , query(l + dl + 1, r + dl));       else         printf( %d n , query(n - dr - r + 1, n - dr - l));     }     void init(int N) {       for (size = 1; size < N; size <<= 1)         ;       dl = dr = 0, dir = 1, len = n = N;       for (int i = 1; i <= n; i++) set(i, 1);     }     void debug() {       printf( =============== n );       for (int i = 1; i <= n; i++) printf( %d  , query(i, i));       printf(  n );     }   } a;   int n, q;   int main() {     scanf( %d%d , &n, &q);     a.init(n);     for (int i = 1, ope, l, r, p; i <= q; i++) {       scanf( %d , &ope);       if (ope == 1) {         scanf( %d , &p);         a.ope1(p);       } else {         scanf( %d%d , &l, &r);         a.ope2(l, r);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, nrE;   struct Dish {     int p, s, b;   } d[100002];   struct Person {     int inc, pref;   } v[100002];   struct Event {     int x, y, z, t;     bool operator<(const Event &ot) const {       if (x == ot.x) return z > ot.z;       return x < ot.x;     }   } E[100002 * 3];   unordered_map<int, int> Bit[2];   int ans[100002];   void Add(int t, int i, int val) {     for (; i < 2 * 1000000005 && i > 0; i += (i & (-i))) Bit[t][i] += val;   }   int Sum(int t, int i) {     int ret = 0;     for (; i > 0; i -= (i & (-i))) ret += Bit[t][i];     return ret;   }   void readDish() {     for (int i = 0; i < n; ++i) scanf( %d , &d[i].p);     for (int i = 0; i < n; ++i) scanf( %d , &d[i].s);     for (int i = 0; i < n; ++i) scanf( %d , &d[i].b);   }   void readPers() {     for (int i = 0; i < m; ++i) scanf( %d , &v[i].inc);     for (int i = 0; i < m; ++i) scanf( %d , &v[i].pref);   }   void solveEvents() {     sort(E, E + nrE);     for (int i = 0; i < nrE; ++i) {       if (E[i].z <= 0) {         int idx = -E[i].z;         ans[idx] = Sum(0, v[idx].inc + v[idx].pref) +                    Sum(1, v[idx].pref - v[idx].inc + 1000000005);       } else {         Add(0, E[i].x + E[i].y, 1 * E[i].t);         Add(1, E[i].z - E[i].x + 1000000005, -1 * E[i].t);       }     }   }   int main() {     scanf( %d%d , &n, &m);     readDish();     readPers();     for (int i = 0; i < n + m; ++i) {       if (i < n) {         E[nrE++] = {d[i].p, d[i].b, d[i].b + 1, 1};         E[nrE++] = {d[i].s + 1, d[i].b - (d[i].s - d[i].p + 1),                     d[i].b + (d[i].s - d[i].p + 1) + 1, -1};       } else         E[nrE++] = {v[i - n].inc, v[i - n].pref, n - i, 0};     }     solveEvents();     for (int i = 0; i < m; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T, class U>   inline void print(T first, U second) {     printsp(first);     println(second);   }   template <class T, class U, class V>   inline void print(T first, U second, V z) {     printsp(first);     printsp(second);     println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   const int C = 333333;   vector<int> adj[C];   int root[C], sz[C], d[C], src;   pair<int, int> f;   int find_root(int u) {     return (root[u] == u ? u : root[u] = find_root(root[u]));   }   void add(int u, int v) {     int uu = find_root(u), vv = find_root(v);     if (uu == vv) return;     sz[vv] += sz[uu];     root[uu] = vv;     smax(d[vv], max(d[uu], (1 + d[uu]) / 2 + (1 + d[vv]) / 2 + 1));   }   void dfs(int u, int dp = 0) {     root[u] = src;     sz[src]++;     if (dp > f.second) {       f.second = dp;       f.first = u;     }     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (root[v]) continue;       dfs(v, dp + 1);     }   }   void rdfs(int u, int dp = 0, int fa = 0) {     smax(d[src], dp);     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == fa) continue;       rdfs(v, dp + 1, u);     }   }   void solve_C() {     int n, m, q, u, v;     gn(n, m, q);     for (int i = 0; i < m; i++) {       gn(u, v);       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!root[i]) {         f.first = i;         f.second = 0;         src = i;         dfs(i);         rdfs(f.first);       }     while (q--) {       int t;       gn(t);       if (t == 1) {         gn(u);         u = find_root(u);         println(d[u]);       } else {         gn(u, v);         add(u, v);       }     }     exit(0);   }   int main() {     solve_C();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long MOD = 1000000007LL, INF = 1e9, LINF = 1e18;   const long double PI = 3.141592653589793116, EPS = 1e-9,                     GOLD = ((1 + sqrt(5)) / 2);   template <class T>   int getbit(T s, int i) {     return (s >> 1) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   string s;   long long n;   vector<long long> cc(26, 0);   void VarInput() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> s;     n = s.size();   }   void ProSolve() {     for (long long i = 0; i < n; i++) cc[s[i] -  a ]++;     long long appear = 0, onlyOne = 0;     for (long long i = 0; i < 26; i++) {       if (cc[i] > 0) appear++;       if (cc[i] == 1) onlyOne++;     }     if (appear > 4) {       cout <<  No ;       return;     }     if (appear < 2) {       cout <<  No ;       return;     }     if (appear == 2 && onlyOne > 0) {       cout <<  No ;       return;     }     if (appear == 3 && onlyOne > 2) {       cout <<  No ;       return;     }     cout <<  Yes ;   }   int main() {     VarInput();     ProSolve();   }


#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 1e3 + 2;   const long long int mod = 1e3 + 2;   vector<long long int> d;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, x, ans = INT_MAX;     cin >> n >> x;     long long int minx = x, maxx = x, a[maxn];     memset(a, 0, sizeof(a));     for (long long int i = 0; i < n; i++) {       long long int start, stop;       cin >> start >> stop;       if (stop < start) swap(start, stop);       for (long long int j = start; j <= stop; j++) ++a[j];     }     for (long long int i = 0; i <= 1003; i++)       if (a[i] == n) ans = min(abs(x - i), ans);     if (ans == INT_MAX)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a, n2 = 0, n1 = 0;     for (int i = 0; i < n; i++) cin >> a, a - 1 ? n2++ : n1++;     if (n2) cout << 2 <<    ;     if (n1) cout << 1 <<    ;     for (int i = 0; i < n2 - 1; i++) cout << 2 <<    ;     for (int i = 0; i < n1 - 1; i++) cout << 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> res, res2, res3;   int x[10005], y[10005], id[35], b[35], vis[10005], r[10005];   bitset<35> c[35], d[35], tmp;   int insert(int x, int y, bitset<35> now) {     for (int i = 0; i <= 30; i++)       if (x & (1 << i)) {         if (!b[i]) {           b[i] = x;           id[i] = y;           vis[y] = 1;           d[i] = now;           d[i][i] = 1;           return i;         }         x ^= b[i];         now ^= d[i];       }     return -1;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &x[i]), r[i] = insert(x[i], i, bitset<35>());     for (int i = 1; i <= n; i++) scanf( %d , &y[i]);     for (int i = 1; i <= n; i++) {       int now = y[i];       for (int j = 0; j <= 30; j++)         if (now & (1 << j)) {           now ^= b[j];           if (~r[i]) c[r[i]] ^= d[j];         }       if (now) {         puts( -1 );         return 0;       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         int now = y[i] ^ x[i];         tmp.reset();         for (int j = 0; j <= 30; j++)           if (now & (1 << j)) now ^= b[j], tmp ^= d[j];         for (int j = 0; j <= 30; j++)           if (tmp[j]) res.push_back({i, id[j]});       }     for (int i = 0; i <= 30; i++) {       if (!c[i][i])         for (int j = 0; j <= 30; j++)           if (c[j][i] && ((!c[j][j]) || j > i)) {             res2.push_back({id[i], id[j]});             res2.push_back({id[j], id[i]});             res2.push_back({id[i], id[j]});             swap(c[i], c[j]);             break;           }       if (!c[i][i]) continue;       for (int j = 0; j <= 30; j++)         if (i != j && c[j][i]) {           c[j] ^= c[i];           res2.push_back({id[j], id[i]});         }     }     for (int i = 1; i <= 30; i++)       for (int j = 0; j < i; j++)         if (c[j][i]) res3.push_back({id[j], id[i]});     for (int i = 0; i <= 30; i++)       if ((id[i]) && (!(c[i][i]))) res2.push_back({id[i], id[i]});     printf( %d n , (int)(res.size() + res2.size() + res3.size()));     reverse(res2.begin(), res2.end());     for (auto i : res) printf( %d %d n , i.first, i.second);     for (auto i : res3) printf( %d %d n , i.first, i.second);     for (auto i : res2) printf( %d %d n , i.first, i.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   using ll = long long;   using ld = long double;   const int maxn = 1e6 + 5;   int n, r;   ll c[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     ll sum = 0;     cin >> n >> r;     for (int i = 0; i < 1 << n; i++) {       cin >> c[i];       sum += c[i];     }     ld res = 1.0 * sum / (1 << n);     cout << res <<   n ;     while (r--) {       int i, g;       cin >> i >> g;       sum -= c[i];       c[i] = g;       sum += c[i];       ld res = 1.0 * sum / (1 << n);       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, row, column;   int a[5005];   int cnt[1005];   int main() {     int i, j, k, l;     int x, y;     int tc, t;     int res = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     j = *(max_element(cnt, cnt + 1001));     if (j > (n + 1) / 2)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010, Q = 100010;   int n, q, ac;   int a[N][N * 2];   int ans[Q];   vector<pair<pair<int, int>, pair<int, int>>> seq;   void ch(int j, int k, int x) {     for (; j <= n; j += j & -j)       for (int l = k; l <= n * 2; l += l & -l) a[j][l] += x;   }   int qry(int j, int k) {     int ret = 0;     for (; j; j &= j - 1)       for (int l = k; l; l &= l - 1) ret += a[j][l];     return ret;   }   void add1(int j, int k, int x) {     seq.emplace_back(make_pair(j, k), make_pair(1, x));   }   void add2(int j, int k, int x) {     seq.emplace_back(make_pair(j, k + j), make_pair(2, x));   }   void add3(int j, int k, int x) {     seq.emplace_back(make_pair(j, k - j + n), make_pair(3, x));   }   int main() {     scanf( %d%d , &n, &q);     while (q--) {       int opt;       scanf( %d , &opt);       if (opt == 1) {         int d, x, y, l;         scanf( %d%d%d%d , &d, &x, &y, &l);         if (d == 1) {           add1(x, y, 1);           add2(x, y + l + 1, -1);           add2(x + l + 1, y, 1);           add1(x + l + 1, y, -1);         } else if (d == 2) {           add3(x, y - l, 1);           add1(x, y + 1, -1);           add1(x + l + 1, y + 1, 1);           add3(x + l + 1, y + 1, -1);         } else if (d == 3) {           add1(x - l, y, 1);           add3(x - l, y + 1, -1);           add1(x + 1, y, -1);           add3(x + 1, y + l + 2, 1);         } else {           add2(x - l, y, 1);           add1(x - l, y + 1, -1);           add2(x + 1, y - l - 1, -1);           add1(x + 1, y + 1, 1);         }       } else {         int x, y;         scanf( %d%d , &x, &y);         ++ac;         seq.emplace_back(make_pair(x, y), make_pair(-1, ac));         seq.emplace_back(make_pair(x, y + x), make_pair(-2, ac));         seq.emplace_back(make_pair(x, y - x + n), make_pair(-3, ac));       }     }     for (int id = 1; id <= 3; ++id) {       memset(a, 0, sizeof(a));       for (const auto& pr : seq)         if (pr.second.first == id)           ch(pr.first.first, pr.first.second, pr.second.second);         else if (pr.second.first == -id)           ans[pr.second.second] += qry(pr.first.first, pr.first.second);     }     for (int i = 1; i <= ac; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int p[105];     int n, m, i, j, t;     memset(p, 0, sizeof(p));     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d , &t);       for (j = t; p[j] == 0; j++) p[j] = t;     }     for (i = 1; i < n; i++) printf( %d  , p[i]);     printf( %d n , p[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> odds;   int main() {     int n;     scanf( %d , &n);     long long int sum = 0;     int length_odds = 0;     for (int x = 0; x < n; x++) {       long long int num;       scanf( %lld , &num);       if (num % 2 == 0) {         sum += num;       } else {         odds.push_back(num);         length_odds++;       }     }     sort(odds.begin(), odds.end());     reverse(odds.begin(), odds.end());     for (int x = 1; x < length_odds;) {       sum += odds[0] + odds[1];       odds.erase(odds.begin());       odds.erase(odds.begin());       x += 2;     }     printf( %lld , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct _Box {     int pos, weight;   } Box;   Box arr[200010];   long long int bit1[200010], bit2[200010];   const int mod = 1e9 + 7;   int num;   int getLowbit(int n) { return n & (-n); }   void add(long long int* bitArr, int pos, long long int val, bool shouldMod) {     if (shouldMod) val = (val + mod) % mod;     for (int i = pos; i <= num; i += getLowbit(i)) {       bitArr[i] += val;       if (shouldMod) bitArr[i] = (bitArr[i] + mod) % mod;     }   }   long long int getPrefixSum(long long int* bitArr, int pos, bool shouldMod) {     long long int ans = 0;     for (int i = pos; i > 0; i -= getLowbit(i)) {       ans += bitArr[i];       if (shouldMod) ans = (ans + mod) % mod;     }     return ans;   }   long long int getRangeSum(long long int* bitArr, int qLeftPt, int qRightPt,                             bool shouldMod) {     if (qRightPt < qLeftPt) return 0;     long long int ans = getPrefixSum(bitArr, qRightPt, shouldMod) -                         getPrefixSum(bitArr, qLeftPt - 1, shouldMod);     if (shouldMod) ans = (ans + mod) % mod;     return ans;   }   int getMidPos(int qLeftPt, int qRightPt) {     int leftPt = qLeftPt, rightPt = qRightPt;     int ans = rightPt;     while (leftPt <= rightPt) {       int midPt = (leftPt + rightPt) >> 1;       if (getRangeSum(bit1, qLeftPt, midPt, false) >=           getRangeSum(bit1, midPt + 1, qRightPt, false)) {         ans = midPt;         rightPt = midPt - 1;       } else {         leftPt = midPt + 1;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(bit1, 0, sizeof(bit1));     memset(bit2, 0, sizeof(bit2));     int qNum;     cin >> num >> qNum;     for (int i = 1; i <= num; i++) {       cin >> arr[i].pos;     }     for (int i = 1; i <= num; i++) {       cin >> arr[i].weight;       add(bit1, i, arr[i].weight, false);       add(bit2, i, (long long int)arr[i].weight * (arr[i].pos - i), true);     }     while (qNum--) {       int x, y;       cin >> x >> y;       if (x < 0) {         x = -x;         add(bit1, x, y - arr[x].weight, false);         add(bit2, x, ((long long int)y - arr[x].weight) * (arr[x].pos - x), true);         arr[x].weight = y;       } else {         if (x == y) {           cout << 0 << endl;           continue;         }         int midPos = getMidPos(x, y);         long long int leftAns = (getRangeSum(bit1, x, midPos, true) *                                      abs(arr[midPos].pos - midPos) % mod -                                  getRangeSum(bit2, x, midPos, true) + mod) %                                 mod;         long long int rightAns = (getRangeSum(bit1, midPos, y, true) *                                       abs(arr[midPos].pos - midPos) % mod -                                   getRangeSum(bit2, midPos, y, true) + mod) %                                  mod;         long long int ans = (leftAns - rightAns + mod) % mod;         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10, M = 1e6 + 7, K = 200, p = 1e9 + 7;   int n, e[N], s[M], wf[K], q[N][K], f[N][N], ans[N][M];   bitset<40> op, wq[N][M];   unordered_map<bitset<40>, int> rt[N];   inline int read() {     int num = 0;     char g = getchar();     while (g < 48 || 57 < g) g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     return num;   }   inline long long pows(long long u, int v) {     long long ans = 1;     while (v > 0) {       if (v & 1) ans = ans * u % p;       u = u * u % p, v = v >> 1;     }     return ans;   }   inline void find(int u) {     q[u][0] = 0;     int os = 0, of = 0;     for (int i = 0; i < (1 << n); i++)       if (s[i] == u) q[u][++q[u][0]] = i, wf[i] = ++os;     for (int i = 1; i <= e[u - 1]; i++) {       if (!ans[u - 1][i]) continue;       for (int h = 1; h < (1 << n); h++) {         long long opq = 1;         for (int c = 0; c < n; c++)           if ((1 << c) & h)             opq = opq * f[u][c + 1] % p;           else             opq = opq * (1 - f[u][c + 1] + p) % p;         bitset<40> c = wq[u - 1][i], hc = op;         bool tg = 0;         for (int x = 1; x <= q[u - 1][0]; x++) {           if (c[x] == 1) {             for (int t = 0; t < n; t++)               if (((1 << t) & h) && (!(q[u - 1][x] & (1 << t)))) {                 hc[wf[q[u - 1][x] | (1 << t)]] = 1, tg = 1;               }           }         }         if (!tg) continue;         int pos;         if (rt[u][hc] == 0) rt[u][hc] = ++of, e[u]++, wq[u][e[u]] = hc;         pos = rt[u][hc];         ans[u][pos] = (ans[u][pos] + opq * ans[u - 1][i]) % p;       }     }   }   int main() {     n = read();     for (int i = 0; i <= (1 << n); i++) s[i] = __builtin_popcount(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) f[i][j] = read() * pows(100, p - 2) % p;     q[0][0] = 1;     e[0] = 1, ans[0][1] = 1, wq[0][1][1] = 1;     for (int i = 1; i <= n; i++) find(i);     cout << ans[n][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int r, x, y, x1, y1, t, u;     double ans = 0;     cin >> r >> x >> y >> x1 >> y1;     t = abs(x - x1);     u = abs(y - y1);     ans = t * t + u * u;     ans = sqrt(ans);     ans = ans / (2 * r);     ans = ceil(ans);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline int32_t rnd(int32_t l = 0, int32_t r = INT_MAX) {     return uniform_int_distribution<int32_t>(l, r)(rng);   }   template <typename T, typename G>   ostream& operator<<(ostream& out, const pair<T, G>& a) {     return out <<  (  << a.first <<   ,   << a.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& a) {     out <<  [ ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& out, const set<T>& a) {     out <<  { ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  } ;   }   template <typename T, typename G>   ostream& operator<<(ostream& out, const map<T, G>& a) {     out <<  < ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  > ;   }   template <typename T, size_t N>   typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,                      ostream&>::type   operator<<(ostream& out, T (&a)[N]) {     out <<  [ ;     for (size_t i = 0; i < N; ++i) out << a[i] <<   ,  ;     out <<  ] ;     return out;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int32_t n, i, first = 0;     cin >> n;     vector<int32_t> a(n), b(n), o, e;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i] / 2;       first += b[i];       if (a[i] & 1) {         if (a[i] > 0) {           o.push_back(i);         } else {           e.push_back(i);         }       }     }     if (first > 0) {       for (i = 0; i < e.size() && first; i++, first--) b[e[i]]--;     } else if (first < 0) {       for (i = 0; i < o.size() && first; i++, first++) b[o[i]]++;     }     for (i = 0; i < n; i++) cout << b[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400;   const int MOD = (int)1e9 + 7;   int n, x;   long long fac[N], c[N][N];   map<int, int> h;   vector<int> d;   int fix(int x) {     for (int i = 2; i * i <= x; i++) {       while (x % (i * i) == 0) {         x /= i * i;       }     }     return x;   }   void add(long long &x, long long y) {     x += y;     x %= MOD;   }   int main() {     memset(c, 0, sizeof c);     fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = fac[i - 1] * i % MOD;     }     for (int i = 0; i < N; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) {         c[i][j] = c[i - 1][j - 1] + c[i - 1][j];         if (c[i][j] >= MOD) {           c[i][j] -= MOD;         }       }     }     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x = fix(x);       if (h.count(x) == 0) {         h[x] = 1;       } else {         int y = h[x];         h[x] = y + 1;       }     }     for (auto it = h.begin(); it != h.end(); it++) {       d.push_back(it->second);     }     sort(d.begin(), d.end());     int now = d[0] + 1;     vector<long long> dp(now + 1, 0);     dp[d[0] - 1] = fac[d[0]];     for (int i = 1; i < d.size(); i++) {       vector<long long> ndp(now + d[i] + 1, 0);       for (int same = 0; same <= now; same++) {         int dif = now - same;         if (dp[same] == 0) {           continue;         }         for (int j = 1; j <= d[i] && j <= now; j++) {           for (int k = 0; k <= same && k <= j; k++) {             int nsame = same - k + d[i] - j;             add(ndp[nsame], dp[same] * c[d[i] - 1][j - 1] % MOD * c[same][k] %                                 MOD * c[dif][j - k] % MOD * fac[d[i]]);           }         }       }       now += d[i];       dp.swap(ndp);     }     printf( %lld n , dp[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int a[N], f[N][21], la[21];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 0; j <= 18; j++)         if (!(a[i] & (1 << j)))           for (int k = 0; k <= 18; k++)             if (a[i] & (1 << k)) f[i][j] = max(f[i][j], f[la[k]][j]);       for (int j = 0; j <= 18; j++)         if (a[i] & (1 << j)) f[i][j] = i, la[j] = i;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       bool flag = false;       for (int j = 0; j <= 18; j++)         if ((a[l] & (1 << j)) && f[r][j] >= l) flag = true;       if (flag)         printf( Shi n );       else         printf( Fou n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 5;   const int MOD = 1000000007;   int a[300005];   int main() {     int n, p;     cin >> n >> p;     for (int i = 1; i <= n; i++) cin >> a[i];     while (p--) {       int l, r, x;       cin >> l >> r >> x;       int lar = r - x;       int num = a[x];       int count = 0;       for (int i = l; i <= r; i++) {         if (a[i] > num) {           count++;         }       }       if (count == lar) {         cout <<  Yes  << endl;       } else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int a, b, cost;   };   vector<edge> e;   const int INF = 1e8;   char alphabet[26] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                         j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                         s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };   bool consistence_check = false;   bool size_check = true;   int aristas = 0;   vector<int> d(27, INF);   void Bellman_Ford(vector<edge> e, int n, int m) {     d[26] = 0;     vector<int> p(n);     int x;     for (int i = 0; i < n; ++i) {       x = -1;       for (int j = 0; j < m; ++j)         if (d[e[j].a] < INF) {           if (d[e[j].b] > d[e[j].a] + e[j].cost) {             d[e[j].b] = max(-INF, d[e[j].a] + e[j].cost);             p[e[j].b] = e[j].a;             x = e[j].b;           }         }     }     if (x == -1) {       consistence_check = true;     }   }   void compare_strings(string string1, string string2) {     int size1 = string1.size();     int size2 = string2.size();     int minsize = min(size1, size2);     bool failsafe = true;     for (int a = 0; a < minsize; a++) {       if (string1[a] != string2[a]) {         edge tempedge = {string1[a] -  a , string2[a] -  a , -1};         e.emplace_back(tempedge);         aristas += 1;         failsafe = false;         break;       }     }     if (size1 > size2 and failsafe) {       size_check = false;     }   }   int main() {     vector<string> lexico;     int cantidad;     cin >> cantidad;     string temp;     for (int k = 0; k < cantidad; k++) {       cin >> temp;       lexico.emplace_back(temp);     }     for (int a = 0; a < cantidad - 1; a++) {       compare_strings(lexico[a], lexico[a + 1]);     }     for (int k = 0; k < 26; k++) {       edge tempedge = {26, k, 0};       e.emplace_back(tempedge);     }     aristas += 26;     if (size_check) {       Bellman_Ford(e, 27, aristas);     }     if (consistence_check) {       for (int k = 0; k > -26; k--) {         for (int a = 0; a < 26; a++) {           if (d[a] == k) {             cout << alphabet[a];           }         }       }     } else {       cout <<  Impossible ;     }     return 0;   }


/**    * code generated by JHelper    * More info: https://github.com/AlexeyDmitriev/JHelper    * @author    */      #include <iostream>   #include <fstream>      #include <iostream>   #include <algorithm>   #include <queue>   #include <vector>   #include <set>   #include <map>   #include <cassert>   #include <functional>   #include <sstream>   #include <cmath>      #include <cstring>   #include <cstdio>   #ifndef ATCODER_DSU_HPP   #define ATCODER_DSU_HPP 1                  namespace atcoder {      // Implement (union by size) + (path compression)   // Reference:   // Zvi Galil and Giuseppe F. Italiano,   // Data structures and algorithms for disjoint set union problems   struct dsu {     public:       dsu() : _n(0) {}       explicit dsu(int n) : _n(n), parent_or_size(n, -1) {}          int merge(int a, int b) {           assert(0 <= a && a < _n);           assert(0 <= b && b < _n);           int x = leader(a), y = leader(b);           if (x == y) return x;           if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);           parent_or_size[x] += parent_or_size[y];           parent_or_size[y] = x;           return x;       }          bool same(int a, int b) {           assert(0 <= a && a < _n);           assert(0 <= b && b < _n);           return leader(a) == leader(b);       }          int leader(int a) {           assert(0 <= a && a < _n);           if (parent_or_size[a] < 0) return a;           return parent_or_size[a] = leader(parent_or_size[a]);       }          int size(int a) {           assert(0 <= a && a < _n);           return -parent_or_size[leader(a)];       }          std::vector<std::vector<int>> groups() {           std::vector<int> leader_buf(_n), group_size(_n);           for (int i = 0; i < _n; i++) {               leader_buf[i] = leader(i);               group_size[leader_buf[i]]++;           }           std::vector<std::vector<int>> result(_n);           for (int i = 0; i < _n; i++) {               result[i].reserve(group_size[i]);           }           for (int i = 0; i < _n; i++) {               result[leader_buf[i]].push_back(i);           }           result.erase(               std::remove_if(result.begin(), result.end(),                              [&](const std::vector<int>& v) { return v.empty(); }),               result.end());           return result;       }        private:       int _n;       // root node: -1 * component size       // otherwise: parent       std::vector<int> parent_or_size;   };      }  // namespace atcoder      #endif  // ATCODER_DSU_HPP         using namespace std;      typedef pair<int, int> ii;   typedef long long int64;   typedef vector<int> vi;      #define pb push_back   #define mp make_pair   #define all(v) (v).begin(),(v).end()   #define sz(v) ((int)(v).size())      template<class T> T abs(T x) { return x >= 0 ? x : -x; }   template<class T> T sqr(T x) { return x * x; }      class TaskC {   public:       vector<vector<ii>> g;       vector<vi> up;       vi d;       vi tin, tout;       int T;       void solve(std::istream& in, std::ostream& out) {        int n, m;        in >> n >> m;        vector<pair<int, ii>> edges(m);        set<ii> es;        int X = 0;        for (int i = 0; i < m; ++i) {               in >> edges[i].second.first >> edges[i].second.second >> edges[i].first;               X ^= edges[i].first;               --edges[i].second.first;               --edges[i].second.second;               es.insert(ii(edges[i].second.first, edges[i].second.second));               es.insert(ii(edges[i].second.second, edges[i].second.first));               //g[edges[i].second.first].pb(ii(edges[i].second.second, edges[i].first));               //g[edges[i].second.second].pb(ii(edges[i].second.first, edges[i].first));           }        sort(all(edges));   //     for (int i = 0; i < n; ++i) {   //         sort(all(g[i]));   //     }        int64 remaining = n;        remaining *= (n - 1);        remaining /= 2LL;        remaining -= m;        assert(remaining >= 0);        if (remaining >= n) {            atcoder::dsu dsu(n);            set<int> alive;               for (int i = 0; i < n; ++i) {                   alive.insert(i);               }            for (int i = 0; i < n; ++i) {                vi cur(all(alive));                for (int x : cur) {                    if (dsu.same(x, i)) continue;                    if (es.count(ii(x, i))) continue;                    alive.erase(dsu.leader(x));                       alive.erase(dsu.leader(i));                    dsu.merge(x, i);                       alive.insert(dsu.leader(x));                }            }            int64 res = 0;            for (auto e : edges) {                int x = e.second.first;                int y = e.second.second;                if (dsu.same(x, y)) continue;                res += e.first;                dsu.merge(x, y);            }            out << res <<   n ;            return;        }        assert(n <= 1000);        for (int i = 0; i < n; ++i) {               for (int j = i + 1; j < n; ++j) {                   if (!es.count(ii(i, j)))                       edges.emplace_back(0, ii(i, j));               }           }        sort(all(edges));           int64 base = 0;           atcoder::dsu dsu(n);           g = vector<vector<ii>>(n);           vi in_tree(sz(edges), 0);           for (int i = 0; i < sz(edges); ++i) {               auto e = edges[i];               int x = e.second.first;               int y = e.second.second;               if (dsu.same(x, y)) continue;               g[x].pb(ii(e.first, y));               g[y].pb(ii(e.first, x));               base += e.first;               dsu.merge(x, y);               in_tree[i] = 1;           }           int64 res = base + X;              up = vector<vi>(21, vi(n, -1));           tin = vi(n, 0);           tout = vi(n, 0);           d = vi(n, 0);           T = 0;           dfs(0, -1, 0);           for (int i = 1; i < sz(up); ++i) {               for (int j = 0; j < n; ++j) {                   int x = up[i - 1][j];                   if (x != -1) {                       x = up[i - 1][x];                   }                   up[i][j] = x;               }           }           int64 best = (int64)(1e12);           for (int I = 0; I < sz(edges); ++I) {               auto e = edges[I];               //if (e.first == 0) continue;               if (in_tree[I]) continue;               if (e.first >= best) continue;               int x = e.second.first;               int y = e.second.second;               int r = x;               for (int i = sz(up) - 1; i >= 0; --i) {                   int t = up[i][r];                   if (t == -1) continue;                   if (!parent(t, y))                       r = t;               }               if (!parent(r, y))                   r = up[0][r];               assert(parent(r, x));               assert(parent(r, y));               int s = (d[x] - d[r]) + (d[y] - d[r]);               if (s > 0) {                   best = min<int64>(best, e.first);               }           }           res = min(res, base + best);              out << res <<   n ;    }       void dfs(int x, int p, int s) {        up[0][x] = p;        ++T;        tin[x] = T;        d[x] = s;        for (ii e : g[x]) if (e.second != p) {            dfs(e.second, x, s + (e.first == 0 ? 1 : 0));        }        tout[x] = T;    }       bool parent(int x, int y) {        return tin[y] >= tin[x] && tin[y] <= tout[x];    }   };         int main() {    TaskC solver;    std::istream& in(std::cin);    std::ostream& out(std::cout);    solver.solve(in, out);    return 0;   }


/*  Karmanye vadhikaraste Ma Phaleshu Kadachana | Ma Karmaphalaheturbhurma Te Sangostvakarmani ||*/   //----------------------------------------------------------------------------------------------------------------//      /* this is begining have to survive more and go through long journey*/    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   #include<bits/stdc++.h>   using namespace std;   #define pb push_back   #define vi vector<int>   #define vii vector<vi>   #define vll vector<long long>   #define mx(v) *max_element(v.begin(),v.end())   #define mn(v) *min_element(v.begin(),v.end())   #define st(v) sort(v.begin(),v.end())   #define bg .begin()   #define ed .end()   #define fi first   #define sc second   #define fr(i,l,u) for(i=l;i<u;i++)   #define rfr(i,l,u) for(i=l;i>u;i--)   #define ll long long int   #define lld long long double   #define uld unsigned long long int   #define pii pair<int,int>   #define flash ios_base::sync_with_stdio(0);cin.tie(NULL);   #define mod 1000000007        void solve()   {       ll n,i,x,sum=0,rem=0;       cin>>n;       vi v;       fr(i,0,n)       {           cin>>x;           sum+=x;       }       rem=sum%n;       cout<<(n-rem)*rem<<endl;                 }         int main()   {        int t;      cin>>t;      while(t--) solve();      }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, k;   char s[N];   int chk(char s[]) {     for (int i = 1; i <= n; i += k) {       for (int j = 1; j <= k; j++) {         if (i + j - 1 > n || i + j - 1 + k > n) break;         if (s[i + j - 1] != s[i + j - 1 + k]) {           if (s[i + j - 1] > s[i + j - 1 + k])             return -1;           else             return 1;         }       }     }     return 0;   }   int main() {     cin >> n >> k;     scanf( %s , s + 1);     int flag = chk(s);     if (flag == 0) {       printf( %d n , n);       printf( %s n , s + 1);       return 0;     } else if (flag == -1) {       for (int i = 1; i <= n; i += k) {         for (int j = 1; j <= k; j++) {           if (i + j - 1 > n || i + j - 1 + k > n) break;           s[i + j - 1 + k] = s[i + j - 1];         }       }       printf( %d n , n);       printf( %s n , s + 1);       return 0;     } else {       bool ff = 0;       if (s[k] ==  9 )         s[k] =  0 , ff = 1;       else         s[k]++;       if (ff) {         for (int i = k - 1; i >= 1; i--) {           if (s[i] ==  9 ) {             s[i] =  0 ;             continue;           }           s[i]++;           break;         }       }       for (int i = 1; i <= n; i += k) {         for (int j = 1; j <= k; j++) {           if (i + j - 1 > n || i + j - 1 + k > n) break;           s[i + j - 1 + k] = s[i + j - 1];         }       }       printf( %d n , n);       printf( %s n , s + 1);       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0, ar[100001], n, ll, ars[100001];   string s;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &ars[i]);       ar[i] = ar[i - 1] + ars[i];     }     cin >> s;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         ans = max(ans, ar[i] + ll);       }       if (s[i] ==  1 ) ll += (ars[i + 1]);     }     ans = max(ans, ll);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > a;   long long sum, ans;   int e, deg;   int get_e(int num, int deg) {     if (num == 1) return 0;     if (num == 2) return 1;     int res = num * (num - 1) / 2;     if (deg & 1) {       int bad = num - 2;       res += bad / 2;     }     return res;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int q, w;       scanf( %d %d , &q, &w);       a.push_back(make_pair(w, q));     }     sort(a.rbegin(), a.rend());     for (int i = 1; i <= min(3000, m); i++) {       sum += a[i - 1].first;       deg = i - 1;       e = get_e(i, deg);       if (e + 1 <= n) ans = max(ans, sum);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(1919810);   int T, n, K, zr;   inline char qry(int la, int ra, int lb, int rb) {     cout <<  ?   << ra - la + 1 <<     << rb - lb + 1 << endl;     for (int i = la; i <= ra; i++) cout << i << (i == ra ?   n  :    );     for (int i = lb; i <= rb; i++) cout << i << (i == rb ?   n  :    );     fflush(stdout);     char c[15];     return scanf( %s , c), *c;   }   inline char blck1() {     for (int i = 2; i <= n; i++)       if (qry(1, 1, i, i) ==  S ) return 1;     return 0;   }   inline char rdck1() {     for (int i = 1, x = rnd() % (n - 1) + 2; i <= 30;          i++, x = rnd() % (n - 1) + 2)       if (qry(1, 1, x, x) ==  S ) return 1;     return 0;   }   inline void work(int l, int r) {     int md = (l + r) >> 1;     if (l == r) return printf( ! %d n , l), void();     if (qry(1, md - l + 1, l, md) ==  E )       return work(md + 1, r);     else       return work(l, md);   }   inline void solve() {     cin >> n >> K;     if ((n <= 30 && blck1()) || (n > 30 && rdck1())) return puts( ! 1 ), void();     for (int i = 1; i <= n; i <<= 1)       if (qry(1, min(i, n - i), i + 1, min(i << 1, n)) !=  E )         return work(i + 1, min(i << 1, n));   }   int main() {     for (cin >> T; T--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename float_t>   struct _complex_ {     float_t x, y;     _complex_<float_t>(float_t _x = 0, float_t _y = 0) : x(_x), y(_y) {}     float_t real() const { return x; }     void real(float_t _x) { x = _x; }     float_t imag() const { return y; }     void imag(float_t _y) { y = _y; }     _complex_<float_t> &operator+=(const _complex_<float_t> &other) {       x += other.x;       y += other.y;       return *this;     }     _complex_<float_t> &operator-=(const _complex_<float_t> &other) {       x -= other.x;       y -= other.y;       return *this;     }     _complex_<float_t> operator+(const _complex_<float_t> &other) const {       return _complex_<float_t>(*this) += other;     }     _complex_<float_t> operator-(const _complex_<float_t> &other) const {       return _complex_<float_t>(*this) -= other;     }     _complex_<float_t> operator*(const _complex_<float_t> &other) const {       return {x * other.x - y * other.y, x * other.y + other.x * y};     }     _complex_<float_t> operator*(float_t mult) const {       return {x * mult, y * mult};     }   };   template <typename float_t>   _complex_<float_t> conj(const _complex_<float_t> &c) {     return {c.x, -c.y};   }   template <typename float_t>   _complex_<float_t> polar(float_t magnitude, float_t angle) {     return {magnitude * cos(angle), magnitude * sin(angle)};   }   template <typename float_t>   ostream &operator<<(ostream &stream, const _complex_<float_t> &c) {     return stream <<  (  << c.x <<  ,   << c.y <<  ) ;   }   const int mod = 1e9 + 7;   const long long inf = 9223372036854775807;   struct query {     int y, pos, type;     query(int a, int b, int c) { y = a, pos = b, type = c; }   };   bool query_sort(const query &a, const query &b) {     if ((a.y ^ b.y)) {       return (a.y < b.y);     }     return (a.pos ^ b.pos) ? (a.pos < b.pos) : (a.type < b.type);   }   int n, k;   int x_coor[300 * 100001], y_coor[300 * 100001], sorted_x[100001];   long long ans[100001];   map<int, int> pos;   signed main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> x_coor[i] >> y_coor[i];       sorted_x[i] = x_coor[i];     }     sort(sorted_x, sorted_x + n);     int oniichan = 0;     sorted_x[n] = mod;     for (int i = 0; i < n; ++i) {       if (sorted_x[i] ^ sorted_x[i + 1]) {         pos[sorted_x[i]] = oniichan + 1;         oniichan += min(sorted_x[i] + k, sorted_x[i + 1]) - sorted_x[i];       }     }     vector<query> q;     for (int i = 0; i < n; ++i) {       q.push_back(query(y_coor[i], pos[x_coor[i]], 1));       q.push_back(query(y_coor[i] + k, pos[x_coor[i]], -1));     }     sort((q).begin(), (q).end(), query_sort);     memset(x_coor, 0, sizeof(x_coor));     memset(y_coor, 0, sizeof(y_coor));     for (query &i : q) {       for (int j = i.pos; j < i.pos + k; ++j) {         ans[y_coor[j]] += i.y - x_coor[j];         y_coor[j] += i.type;         x_coor[j] = i.y;       }     }     for (int i = 1; i < n + 1; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   const int maxn = 4050;   const int maxsec = 86400;   vector<pair<int, int> > input;   int dp[maxn][maxn];   int main() {     int k, n;     scanf( %d , &n);     ;     scanf( %d , &k);     ;     int i, j;     int x, y;     for (i = 0; i < n; ++i) {       scanf( %d , &x);       ;       scanf( %d , &y);       ;       input.push_back(make_pair(x - 1, y));     }     if (k >= n) {       printf( %d n , maxsec);       ;       return 0;     }     sort(input.begin(), input.end());     int m = input.size();     dp[0][0] = input[0].first + input[0].second;     for (j = 1; j <= k; ++j) dp[0][j] = 0;     for (i = 1; i < m; ++i) {       dp[i][0] = max(input[i].first, dp[i - 1][0]) + input[i].second;       for (j = 1; j <= k; ++j) {         dp[i][j] = min(dp[i - 1][j - 1],                        max(dp[i - 1][j], input[i].first) + input[i].second);       }     }     int ans = input[k].first;     int wakeup;     for (i = 0; i < m; ++i)       for (j = 0; j <= k; ++j) {         if (i + k - j + 1 < m)           wakeup = input[i + k - j + 1].first;         else           wakeup = maxsec;         ans = max(ans, wakeup - dp[i][j]);       }     printf( %d n , ans);     ;     return 0;   }