#include <bits/stdc++.h>   using namespace std;   int n;   vector<array<int, 2>> v, good;   long long f(int x, int y) {     return abs(v[x][0] - v[y][0]) + abs(v[x][1] - v[y][1]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     v.resize(n);     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> v[i][0] >> v[i][1];     }     int min_x = -1, max_x = -1, min_y = -1, max_y = -1;     for (int i = 0; i < n; i++) {       if (min_x == -1 || v[i][0] < v[min_x][0]) {         min_x = i;       }       if (max_x == -1 || v[i][0] > v[max_x][0]) {         max_x = i;       }       if (min_y == -1 || v[i][1] < v[min_y][1]) {         min_y = i;       }       if (max_y == -1 || v[i][1] > v[max_y][1]) {         max_y = i;       }       ans += f(i, (i + 1) % n);     }     if (n == 3) {       return cout << ans, 0;     }     set<int> st;     st.insert(min_x), st.insert(max_x), st.insert(min_y), st.insert(max_y);     for (int i : st) good.push_back(v[i]);     long long ans3 = 0;     if ((int)(good).size() < 4) {       ans3 = ans;     } else {       for (int i = 0; i < n; i++) {         for (int j = 0; j < 4; j++) {           for (int k = j + 1; k < 4; k++) {             long long cur = 0;             cur += abs(good[j][0] - v[i][0]) + abs(good[j][1] - v[i][1]);             cur += abs(good[j][0] - good[k][0]) + abs(good[j][1] - good[k][1]);             cur += abs(good[k][0] - v[i][0]) + abs(good[k][1] - v[i][1]);             ans3 = max(ans3, cur);           }         }       }     }     cout << ans3 <<    ;     for (int i = 4; i <= n; i++) {       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long base = 7;   const long long maxn = 1e6 + 9;   const long long inf = 1e9 + 7;   queue<long long> l[30], r[30], l1, r1, lf, rf;   vector<pair<long long, long long> > res;   long long n, i;   string a, b;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b;     a =     + a;     b =     + b;     for (i = 1; i <= n; i++) {       if (a[i] !=  ? )         l[a[i] -  a ].push(i);       else         l1.push(i);     }     for (i = 1; i <= n; i++) {       if (b[i] !=  ? )         r[b[i] -  a ].push(i);       else         r1.push(i);     }     for (i = 0; i <= 27; i++) {       while (true) {         if (!l[i].empty() && !r[i].empty()) {           res.push_back(make_pair(l[i].front(), r[i].front()));           l[i].pop();           r[i].pop();         } else {           while (!l[i].empty()) {             lf.push(l[i].front());             l[i].pop();           }           while (!r[i].empty()) {             rf.push(r[i].front());             r[i].pop();           }           break;         }       }     }     while (true) {       if (!lf.empty() && !r1.empty()) {         res.push_back(make_pair(lf.front(), r1.front()));         lf.pop();         r1.pop();       } else         break;     }     while (true) {       if (!rf.empty() && !l1.empty()) {         res.push_back(make_pair(l1.front(), rf.front()));         rf.pop();         l1.pop();       } else         break;     }     while (true) {       if (!r1.empty() && !l1.empty()) {         res.push_back(make_pair(l1.front(), r1.front()));         r1.pop();         l1.pop();       } else         break;     }     cout << res.size() <<   n ;     for (i = 0; i < res.size(); i++)       cout << res[i].first <<     << res[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     int ans, cnt, k;     string str;     while (cin >> str >> k) {       ans = 0;       cnt = 0;       int len = str.length();       for (int i = len - 1; i >= 0; i--) {         if (str[i] ==  0 ) {           ans++;         }       }       if (ans < k) {         cout << len - 1 << endl;       } else {         for (int i = len - 1; i >= 0; i--) {           if (str[i] !=  0 ) {             cnt++;           } else {             k--;           }           if (k == 0) {             break;           }         }         cout << cnt << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b, d, ans, l, h;   char a[105], c[105];   bool letter[30];   int lena, lenc;   int ll[105], yy[105];   char aa[105 * 105];   inline int ok() {     memset(letter, 0, sizeof(letter));     for (char *p = a; *p; ++p) letter[*p -  a ] = 1;     for (char *p = c; *p; ++p)       if (letter[*p -  a ] == 0) return 0;     return 1;   }   inline int init() {     for (int i = 0; i < 105; ++i) strcpy(aa + i * lena, a);     for (int i = 0; i < lena; ++i) {       char *p = aa + i, *q = c;       while (*p && *q) {         while (*p && *p != *q) ++p;         if (*p != *q) return 0;         ++p, ++q;       }       if (*q != 0) return 0;       ll[i] = p - (aa + i);       yy[i] = (p - aa) % lena;     }     return 1;   }   inline int test(int p) {     p = p * d;     long long pos = 0;     long long vst[105], cnt[105];     memset(vst, -1, sizeof(vst));     for (int i = 0; i < p; ++i) {       if (pos >= lena * b) return 0;       if (vst[pos % lena] > -1) {         long long tmp = pos - vst[pos % lena];         long long tem = i - cnt[pos % lena];         pos += tmp * ((p - i) / tem);         i = (p - i) / tem * tem + i - 1;         memset(vst, -1, sizeof(vst));         continue;       }       if (i) {         vst[pos % lena] = pos;         cnt[pos % lena] = i;       }       pos += ll[pos % lena];     }     if (pos - 1 >= lena * b) return 0;     return 1;   }   int main(int argc, char **argv) {     scanf( %d%d , &b, &d);     scanf( %s%s , a, c);     lena = strlen(a), lenc = strlen(c);     if (!ok() || !init())       puts( 0 );     else {       ans = 0, l = 1, h = lena * b / (lenc * d);       while (l <= h) {         int mid = (l + h) >> 1;         if (test(mid))           ans = mid, l = mid + 1;         else           h = mid - 1;       }       printf( %d n , ans);     }     return 0;   }


#include<bits/stdc++.h>   #define pb push_back   #define mk make_pair   #define ll long long   #define ss second   #define ff first   #define pll pair<ll,ll>   #define vll vector<ll>   #define mll map<ll,ll>   #define mod 1000000007   #define w(x) ll x; cin>>x; while(x--)   #define ps(x,y) fixed<<setprecision(y)<<x;   #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)   #define re(i, j) fo(i, 0, j, 1)   #define pi 3.1415926535897932384626433832795   #define all(cont) cont.begin(), cont.end()   #define countbit(x) __builtin_popcount(x)   #define mod 1000000007   #define lo lower_bound   #define de(n) ll n;cin>>n;   #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}   #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}   #define deb(x) cout<<#x<< = <<x<<endl;   #define tr(it,a) for(auto it=a.begin();it!=a.end();it++)   #define nl cout<<endl;      using namespace std;            int main()   {   ios_base::sync_with_stdio(0);   cin.tie(0);                  int n;           cin>>n;           int x[2]={1,-1};              int y[2]={1,-1};           pair<int,int> p;           p.first=0;           p.second=0;           int a1=n/2;           int a2=n-n/2;           if(n%2!=0){               int c=a2+1;               int d=(a1+1);               ll ans=1ll*2*(c*d);               cout<<ans<<endl;           }           else{               int c=a2+1;               int d=a1+1;               ll ans=1ll*c*d;               cout<<ans<<endl;           }                                                                       return 0;   }


#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...);   }   inline long long int GCD(long long int x, long long int y) {     if (x < y) swap(x, y);     if (x == 0) return y;     if (y == 0) return x;     return GCD(x % y, y);   }   long long int phi(long long int n) {     long long int result = n;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   long long int power(long long int x, long long int n, long long int mod) {     long long int res = 1;     x %= mod;     while (n) {       if (n & 1) {         res = ((res * x) % mod + mod) % mod;       }       x = ((x * x) % mod + mod) % mod;       n >>= 1;     }     return res;   }   long long int A[105][105];   long long int row[105], col[105], fr[105] = {0}, fc[105] = {0}, cr = 0, cc = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n, m;     cin >> n >> m;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         cin >> A[i][j];         row[i] += A[i][j];         col[j] += A[i][j];       }     }     while (1) {       bool f = true;       for (long long int i = 1; i <= n; i++) {         if (row[i] < 0) {           f = false;           fr[i] ^= 1;           cr--;           if (fr[i]) cr += 2;           for (long long int j = 1; j <= m; j++) {             row[i] -= (2 * A[i][j]);             col[j] -= (2 * A[i][j]);             A[i][j] = -A[i][j];           }         }       }       for (long long int j = 1; j <= m; j++) {         if (col[j] < 0) {           f = false;           fc[j] ^= 1;           cc--;           if (fc[j]) cc += 2;           for (long long int i = 1; i <= n; i++) {             row[i] -= (2 * A[i][j]);             col[j] -= (2 * A[i][j]);             A[i][j] = -A[i][j];           }         }       }       if (f) break;     }     cout << cr <<    ;     for (long long int i = 1; i <= n; i++) {       if (fr[i]) cout << i <<    ;     }     cout << endl;     cout << cc <<    ;     for (long long int j = 1; j <= m; j++) {       if (fc[j]) cout << j <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int MAXV = 100010;   const int MAXT = 333;   int a[MAXN], n;   int b[MAXN], m;   int s, e;   vector<int> ind[MAXV];   int p[MAXN][MAXT];   int main() {     scanf( %d%d%d%d , &n, &m, &s, &e);     for (int i = int(0); i <= int((MAXV)-1); ++i) ind[i].clear();     for (int i = int(1); i <= int(n); ++i)       scanf( %d , a + i), ind[a[i]].push_back(i);     for (int i = int(1); i <= int(m); ++i) scanf( %d , b + i);     int mt = s / e;     int ans = 0;     for (int t = int(1); t <= int(mt); ++t) p[0][t] = n + 1;     p[0][0] = 0;     for (int j = int(1); j <= int(m); ++j) {       for (int t = int(0); t <= int(mt); ++t) p[j][t] = p[j - 1][t];       for (int t = int(0); t <= int(mt - 1); ++t) {         vector<int>::iterator it =             lower_bound(ind[b[j]].begin(), ind[b[j]].end(), p[j - 1][t] + 1);         if (it != ind[b[j]].end()) p[j][t + 1] = min(p[j][t + 1], *it);       }       for (int t = int(1); t <= int(mt); ++t) {         int i = p[j][t];         if (i > n) break;         int rest = s - (i + j);         int cnt = rest / e;         ans = max(ans, min(cnt, t));       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int Tea;     int Index;     friend bool operator<(const node& a, const node& b) { return a.Tea > b.Tea; }   } D[105];   int main() {     int i, n, w, Ans[105];     scanf( %d%d , &n, &w);     for (i = 0; i < n; i++) {       scanf( %d , &D[i].Tea);       D[i].Index = i;     }     sort(D, D + n);     int Judge = 0;     for (i = 0; i < n; i++) Judge += (D[i].Tea + 1) / 2;     if (Judge > w)       printf( -1 n );     else {       w -= Judge;       for (i = 0; i < n; i++) Ans[D[i].Index] = (D[i].Tea + 1) / 2;       for (i = 0; i < n && w; i++) {         if (w >= D[i].Tea - Ans[D[i].Index])           w -= D[i].Tea - Ans[D[i].Index], Ans[D[i].Index] = D[i].Tea;         else           Ans[D[i].Index] += w, w = 0;       }       for (i = 0; i < n; i++) {         if (i) printf(   );         printf( %d , Ans[i]);       }       printf(  n );     }     return 0;   }


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


#include <bits/stdc++.h>      using namespace std;      #define y1 temp_y1   #define all(x) x.begin(), x.end()      const int N = 3e5 + 5;      int n;      int lst[N];   int fa[N];      vector<int> g[N];      int min_leaf = -1;   int ext_cnt = 0;   bool ok = true;      void dfs1(int u, int k) {     for (auto v : g[u]) {       dfs1(v, k);     }     if (ext_cnt < k && lst[u] != ext_cnt) {       ok = false;     }     if (ext_cnt == k) {       min_leaf = u;     }     ++ext_cnt;   }   long long ans = 0;   int seq[N];   int dfs_cnt = 0;   int siz[N];      void dfs2(int u, int k, int dep) {     seq[u] = dfs_cnt++;     if (lst[u] < k) {       ans += dep;       siz[u]++;     }      for (auto v : g[u]) {       dfs2(v, k, dep + 1);       siz[u] += siz[v];     }     if (lst[u] < k && lst[u] != ext_cnt) {       ok = false;     }     if (lst[u] >= k && siz[u] + seq[u] != lst[u]) {       ok = false;     }     ++ext_cnt;   }      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> lst[i];       --lst[i];     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       fa[v] = u;       g[u].push_back(v);     }     for (int i = 0; i < n; ++i) {       sort(all(g[i]), [&](int x, int y) -> bool {         return lst[x] < lst[y];       });     }          if (lst[0] == 0) {       dfs2(0, 0, 0);       if (ok) {         cout <<  YES  << endl;         cout << 0 << endl;         for (int i = 0; i < n; ++i) {    cout << lst[i] + 1 <<    ;         }         cout << endl;         return 0;       } else {         cout <<  NO  << endl;         return 0;       }     }     int v = lst[0] - 1;     dfs1(0, v);     int u = min_leaf;     bool is_find = false;     fa[0] = -1;     //cerr << v + 1 <<     << u + 1 <<     << lst[u] + 1 <<endl;     do {       if (lst[u] == v) {         is_find = true;       }       if (lst[u] == v && fa[u] != -1) {         swap(lst[u], lst[fa[u]]);         ++ans;       }       u = fa[u];     } while (u != -1);     if (!is_find) {       cout <<  NO  << endl;       return 0;     }     ext_cnt = 0;     dfs2(0, v, 0);        if (ok) {       cout <<  YES  << endl;       cout << ans << endl;       for (int i = 0; i < n; ++i) {         cout << seq[i] + 1 <<     ;       }       cout << endl;     } else {       cout <<  NO  << endl;     }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int>> flowers;   vector<int> first_flowers;   vector<long long> pref_sum;   long long answer;   void In() {     flowers.clear();     pref_sum.clear();     first_flowers.clear();     answer = LLONG_MIN;     cin >> n >> m;     flowers.resize(m);     for (int i = 0; i < m; i++) cin >> flowers[i].first >> flowers[i].second;   }   long long GetPrefSum(int start_index) {     return pref_sum.back() -            ((start_index - 1 >= 0) ? pref_sum[start_index - 1] : 0);   }   void Try(int index) {     auto range = equal_range(first_flowers.begin(), first_flowers.end(),                              flowers[index].second);     int less_or_equal = range.second - first_flowers.begin();     int remaining = m - less_or_equal;     remaining = min(remaining, n);     int start_index = m - remaining;     if (index >= start_index) {       long long result = GetPrefSum(start_index);       long long left_take = n - remaining;       result += left_take * flowers[index].second;       answer = max(answer, result);     } else {       long long result = flowers[index].first;       int really_remaining = m - less_or_equal;       really_remaining = min(really_remaining, n - 1);       start_index = m - really_remaining;       result += GetPrefSum(start_index);       long long left_take = n - 1 - really_remaining;       result += left_take * flowers[index].second;       answer = max(answer, result);     }   }   void Solve() {     sort(flowers.begin(), flowers.end());     pref_sum.resize(m);     pref_sum[0] = flowers[0].first;     for (int i = 1; i < m; i++) pref_sum[i] = flowers[i].first + pref_sum[i - 1];     first_flowers.resize(m);     for (int i = 0; i < m; i++) first_flowers[i] = flowers[i].first;     for (int i = 0; i < m; i++) Try(i);   }   void Out() { cout << answer <<   n ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       In();       Solve();       Out();     }   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   int main() {     long long a, b, n;     while (cin >> a >> b) {       n = b - 1;       long long ans = 0;       for (int k = 1; k <= a; ++k) {         ans = (ans + (((((k * b) % mo) * ((n * (n + 1) / 2) % mo)) % mo +                        (n * (n + 1) / 2) % mo)) %                          mo) %               mo;       }       cout << ans % mo << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T MDINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   template <class T>   bool ISLEFT(T a, T b, T c) {     if (((a.first - b.first) * (b.second - c.second) -          (b.first - c.first) * (a.second - b.second)) < 0.0)       return 1;     else       return 0;   }   char a[10009];   int z[10009];   char ch[5000 + 2];   int ar[5000 + 2][5000 + 2];   int res[5000 + 2][5000 + 2];   void zalgo() {     int l, r;     l = r = 0;     z[0] = strlen(a);     for (int i = 1; i < z[0]; i++) {       if (i > r) {         l = r = i;         for (int j = i; j < z[0]; j++) {           if (a[j - i] != a[j])             break;           else             r = j;         }         if (a[i] != a[0])           z[i] = 0;         else           z[i] = r - l + 1;       } else {         int k = i - l;         if (z[k] < r - i + 1) {           z[i] = z[k];         } else {           l = i;           for (int j = r + 1; j < z[0]; j++) {             if (a[j - l] != a[j])               break;             else               r = j;           }           z[i] = r - l + 1;         }       }     }   }   int dp[5009][5009];   void update(int x1, int y1, int val) {     while (y1 <= 5002) {       dp[x1][y1] = (dp[x1][y1] + val) % 1000000007;       y1 += (y1 & -y1);     }   }   int query(int x1, int y1) {     int sum1 = 0;     while (y1 > 0) {       sum1 = (sum1 + dp[x1][y1]) % 1000000007;       y1 -= (y1 & -y1);     }     return sum1;   }   int main() {     int n;     scanf( %d , &n);     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) {       int sz = 0;       for (int j = i; j <= n; j++) {         a[sz++] = ch[j];       }       int len = sz;       for (int j = i + 1; j <= n; j++) {         a[sz++] = ch[j];       }       a[sz] =   0 ;       zalgo();       for (int j = i + 1; j <= n; j++) {         ar[i][j] = z[len + (j - i - 1)];       }     }     res[0][0] = 1;     for (int i = 1; i <= n; i++) {       if (ch[i] ==  0 ) continue;       for (int j = i; j <= n; j++) {         if (i == 1)           res[i][j] = 1;         else {           int ga = j - i;           int x = i - 1 - ga;           int y = i - 1;           x = max(1, x);           if (y - x == ga) {             int in = x;             int mil = ar[x][i];             if (mil < (ga + 1)) {               if (ch[x + mil] < ch[i + mil]) {                 in = x - 1;               }             }             int sum = query(y, y) - query(y, in);             if (sum < 0) sum += 1000000007;             res[i][j] = sum;           } else {             int sum = query(y, y) - query(y, x - 1);             if (sum < 0) sum += 1000000007;             res[i][j] = sum;           }         }         update(j, i, res[i][j]);       }     }     int su = 0;     for (int i = 1; i <= n; i++) {       su = (su + res[i][n]) % 1000000007;     }     printf( %d n , su);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(false);     int al, ar, bl, br;     cin >> al >> ar >> bl >> br;     if ((al * 2 + 3 > br && br >= al - 1) || (ar * 2 + 3 > bl && bl >= ar - 1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int c = 0;   void bfs(map<long long int, vector<long long int> > &map, vector<bool> &visited,            long long int x) {     queue<long long int> q;     q.push(x);     visited[x] = true;     while (!q.empty()) {       long long int y = q.front();       q.pop();       for (long long int i : map[y]) {         if (!visited[i]) {           q.push(i);           visited[i] = true;         }       }     }   }   int main() {     long long int x, y, n, m;     cin >> n >> m;     map<long long int, vector<long long int> > map;     std::vector<bool> visited(n + 1, false), visitedf(n + 1, false);     for (long long int i = 0; i < m; i++) {       cin >> x >> y;       map[x].push_back(y);       map[y].push_back(x);     }     if (m != n - 1) {       cout <<  no ;       return 0;     }     bfs(map, visited, map.begin()->first);     for (long long int i = 1; i <= n; i++) {       if (!visited[i]) {         cout <<  no ;         return 0;       }     }     cout <<  yes ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = (int)2e5 + 100;   const int M = (int)2e6 + 100;   const int inf = (int)1e9 + 100;   int a[N];   int b[N];   int t[4 * N];   map<int, int> m[4 * N];   void add(int x, int L, int R, int pos, int val) {     t[x] = min(t[x], val);     m[x][val]++;     if (R - L == 1) {       return;     }     int c = (L + R) >> 1;     if (c > pos) {       add(2 * x + 1, L, c, pos, val);     } else {       add(2 * x + 2, c, R, pos, val);     }   }   int sum(int x, int L, int R, int l, int r) {     if (R == r && L == l) {       return t[x];     }     int c = (L + R) >> 1;     int o = inf;     if (c > l) {       o = sum(2 * x + 1, L, c, l, min(c, r));     }     if (c < r) {       o = min(o, sum(2 * x + 2, c, R, max(l, c), r));     }     return o;   }   int del(int x, int L, int R, int l, int r, int val) {     if (R - L == 1) {       m[x][val]--;       if (!m[x][val]) m[x].erase(val);       if (m[x].size())         t[x] = m[x].begin()->first;       else         t[x] = inf;       return L;     }     int c = (L + R) >> 1;     int o = -1;     m[x][val]--;     if (!m[x][val]) m[x].erase(val);     if (c > l && m[2 * x + 1].count(val)) {       o = del(2 * x + 1, L, c, l, min(c, r), val);     }     if (c < r && m[2 * x + 2].count(val) && o == -1) {       o = del(2 * x + 2, c, R, max(l, c), r, val);     }     t[x] = min(t[2 * x + 1], t[2 * x + 2]);     return o;   }   void print(int x, int L, int R) {     cout << x <<     << L <<     << R <<  :  << t[x] <<   n ;     for (auto j : m[x]) {       cout << j.first <<     << j.second <<   n ;     }     cout <<   n ;     if (R - L == 1) return;     int c = (L + R) >> 1;     print(2 * x + 1, L, c);     print(2 * x + 2, c, R);   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, M, i;     cin >> n >> M;     vector<int> v;     for ((i) = 0; (i) < (n); (i)++) {       cin >> a[i];       v.push_back(a[i]);     }     for ((i) = 0; (i) < (4 * N); (i)++) {       t[i] = inf;     }     for ((i) = 0; (i) < (M); (i)++) {       cin >> b[i];       v.push_back(b[i]);     }     sort((v).begin(), (v).end()),         v.resize(unique((v).begin(), (v).end()) - v.begin());     map<int, int> m;     for ((i) = 0; (i) < (v.size()); (i)++) {       m[v[i]] = i;     }     int R = v.size();     for ((i) = 0; (i) < (M); (i)++) {       int p;       cin >> p;       add(0, 0, R, m[b[i]], p);     }     int ma = 0;     vector<pair<int, long long> > g;     for ((i) = n - 1; (i) >= 0; (i)--) {       if (a[i] > ma) {         ma = a[i];         g.push_back({i, a[i]});       } else {         g[g.size() - 1].second += a[i];       }     }     int ans = 0;     for ((i) = 0; (i) < (g.size()); (i)++) {       int x = sum(0, 0, R, 0, m[a[g[i].first]] + 1);       int y;       while (x != inf && x <= g[i].second) {         y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x);         ans++;         g[i].second -= x;         x = sum(0, 0, R, 0, m[a[g[i].first]] + 1);       }       if (x != inf) {         y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x);         add(0, 0, R, y, x - g[i].second);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   bool custom(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first < b.first;   }   bool c1(string a) {     int dec = 0;     for (int i = 0; i < a.size() - 1; i++) {       if (a[i] >= a[i + 1]) {         dec += (a[i] > a[i + 1]);       } else {         dec = 0;       }       if (dec == 2) {         return true;       }     }     return false;   }   bool c2(string b) {     char ant = b[0];     for (auto& first : b) {       if (ant > first) {         return true;       }       ant = first;     }     return false;   }   int main() {     int k;     cin >> k;     int i = 1;     string first = to_string(i);     while (k > first.size()) {       k -= first.size();       i++;       first = to_string(i);     }     int c = 0;     char an = first[0];     while (k > 0) {       an = first[c];       c++;       k--;     }     cout << an;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   vector<vector<int> > adj;   vector<int> col;   queue<int> x, y;   void colorear(int u, int c) {     col[u] = c;     for (int v : adj[u])       if (col[v] == -1) colorear(v, 1 - c);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     adj = vector<vector<int> >(2 * n + 2);     for (int i = 0; i < n; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);       x.push(a);       y.push(b);       if (a % 2) {         adj[a].push_back(a + 1);         adj[a + 1].push_back(a);       }       if (b % 2) {         adj[b].push_back(b + 1);         adj[b + 1].push_back(b);       }     }     col = vector<int>(2 * n + 2, -1);     for (int i = 1; i <= 2 * n; i++) {       if (col[i] == -1) {         colorear(i, 0);       }     }     while (n--) {       cout << col[x.front()] + 1 <<     << col[y.front()] + 1 <<   n ;       x.pop();       y.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100000];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int go;       cin >> go;       a[i].first = go;       a[i].second = i;     }     sort(a, a + n);     int an = 0;     for (int i = 0; i < n; i++) {       k -= a[i].first;       if (k < 0) break;       an++;     }     cout << an << endl;     for (int i = 0; i < an; i++) {       cout << a[i].second + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #ifdef tabr   #include  library/debug.cpp    #else   #define debug(...)   #endif      template <long long mod>   struct modular {       long long value;       modular(long long x = 0) {           value = x % mod;           if (value < 0) value += mod;       }       modular& operator+=(const modular& other) {           if ((value += other.value) >= mod) value -= mod;           return *this;       }       modular& operator-=(const modular& other) {           if ((value -= other.value) < 0) value += mod;           return *this;       }       modular& operator*=(const modular& other) {           value = value * other.value % mod;           return *this;       }       modular& operator/=(const modular& other) {           long long a = 0, b = 1, c = other.value, m = mod;           while (c != 0) {               long long t = m / c;               m -= t * c;               swap(c, m);               a -= t * b;               swap(a, b);           }           a %= mod;           if (a < 0) a += mod;           value = value * a % mod;           return *this;       }       modular operator+(const modular& rhs) const { return modular(*this) += rhs; }       modular operator-(const modular& rhs) const { return modular(*this) -= rhs; }       modular operator*(const modular& rhs) const { return modular(*this) *= rhs; }       modular operator/(const modular& rhs) const { return modular(*this) /= rhs; }       modular& operator++() { return *this += 1; }       modular& operator--() { return *this -= 1; }       modular operator++(int) {           modular res(*this);           *this += 1;           return res;       }       modular operator--(int) {           modular res(*this);           *this -= 1;           return res;       }       modular operator-() const { return modular(-value); }       bool operator==(const modular& rhs) const { return value == rhs.value; }       bool operator!=(const modular& rhs) const { return value != rhs.value; }       bool operator<(const modular& rhs) const { return value < rhs.value; }   };   template <long long mod>   string to_string(const modular<mod>& x) {       return to_string(x.value);   }   template <long long mod>   ostream& operator<<(ostream& stream, const modular<mod>& x) {       return stream << x.value;   }   template <long long mod>   istream& operator>>(istream& stream, modular<mod>& x) {       stream >> x.value;       x.value %= mod;       if (x.value < 0) x.value += mod;       return stream;   }      constexpr long long mod = (long long) 1e9 + 7;   using mint = modular<mod>;      mint power(mint a, long long n) {       mint res = 1;       while (n > 0) {           if (n & 1) {               res *= a;           }           a *= a;           n >>= 1;       }       return res;   }      vector<mint> fact(1, 1);   vector<mint> finv(1, 1);      mint C(int n, int k) {       if (n < k || k < 0) {           return mint(0);       }       while ((int) fact.size() < n + 1) {           fact.emplace_back(fact.back() * (int) fact.size());           finv.emplace_back(mint(1) / fact.back());       }       return fact[n] * finv[k] * finv[n - k];   }      int main() {       ios::sync_with_stdio(false);       cin.tie(0);       int n;       cin >> n;       vector<int> c(n), b(n - 1);       for (int i = 0; i < n; i++) {           cin >> c[i];       }       for (int i = 0; i < n - 1; i++) {           cin >> b[i];       }       vector<int> d(n);       for (int i = 1; i < n; i++) {           for (int j = 0; j < i; j++) {               d[i] += b[j];           }       }       int q;       cin >> q;       map<int, mint> mp;       mp[(int) 2e9] = 0;       mp[(int) -2e9] = 1;       for (int i = 0; i < n; i++) {           mp[(int) -2e9] *= c[i] + 1;       }       while (q--) {           int x;           cin >> x;           if (mp.count(x)) {               cout << mp[x] <<   n ;               continue;           }           auto nxt = mp.lower_bound(x);           auto pre = prev(nxt);           if ((*pre).second == (*nxt).second) {               cout << (*pre).second <<   n ;               continue;           }           int m = 10100;           vector<mint> dp(m);           dp[0] = 1;           int t = 0;           for (int i = 0; i < n; i++) {               vector<mint> new_dp(m);               new_dp[0] = dp[0];               for (int j = 1; j < m; j++) {                   new_dp[j] = new_dp[j - 1] + dp[j];                   if (j - c[i] - 1 >= 0) {                       new_dp[j] -= dp[j - c[i] - 1];                   }               }               swap(dp, new_dp);               t += x + d[i];               for (int j = 0; j < min(m, t); j++) {                   dp[j] = 0;               }           }           mp[x] = accumulate(dp.begin(), dp.end(), mint(0));           cout << mp[x] <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Day = 86400;   const long long INF = 1e18;   const int N = 4004;   long long dp[N][N], t[N], d[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int(i) = 0; (i) < (n); (i)++) scanf( %d%d , &t[i], &d[i]), t[i]--;     if (n == k) return printf( %d n , Day) & 0;     memset(dp, INF, sizeof dp);     dp[0][0] = 0;     for (int(i) = (1); (i) <= (n); (i)++)       for (int(j) = (0); (j) <= (k); (j)++)         if (j <= i) {           long long last = dp[i - 1][j];           if (last != INF) {             dp[i][j] = max(last, t[i - 1]) + d[i - 1];           }           if (j > 0) dp[i][j] = min(dp[i - 1][j - 1], dp[i][j]);         }     long long ans = 0;     for (int(left) = (0); (left) <= (n); (left)++) {       int right = min(k, left);       long long start = dp[left][right];       long long finish = left < n ? t[left] : Day;       if (start >= Day || finish > Day || start >= finish) continue;       ans = max(ans, finish - start);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limN = 1e5 + 5;   vector<pair<long long, int> > adj[limN];   bool usd[limN];   long long minP[limN];   int main() {     int ans = 0;     int N, E1, E2;     priority_queue<tuple<long long, int, int> > Q;     scanf( %d%d%d , &N, &E1, &E2);     for (int a, b, c; E1; E1--) {       scanf( %d%d%d , &a, &b, &c);       a--, b--;       adj[a].push_back({c, b});       adj[b].push_back({c, a});     }     for (int b, c; E2; E2--) {       scanf( %d%d , &b, &c);       b--;       Q.push({-c, 0, b});     }     Q.push({0, 1, 0});     while (!Q.empty()) {       long long dst;       int tip, pos;       tie(dst, tip, pos) = Q.top();       Q.pop();       if (usd[pos]) {         ans += 1 - tip;         continue;       }       dst *= -1;       usd[pos] = true;       for (const auto &second : adj[pos]) {         if (!usd[second.second] || minP[second.second] > dst + second.first) {           minP[second.second] = dst + second.first;           Q.push({-minP[second.second], 1, second.second});         }       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[30];   char A[30], ch[205];   int d[405][405];   int now[205], minv[205], minc[205];   int fan(int x) { return (x > n) ? (x - n) : (x + n); }   int main() {     scanf( %s , A);     int tot = strlen(A);     for (int i = 0; i < tot; ++i) {       p[i] = A[i] ==  V ;     }     minv[0] = minc[0] = 26;     for (int i = 0; i < tot; ++i) {       if (p[i]) {         minv[0] = i;         break;       }     }     for (int i = 0; i < tot; ++i) {       if (p[i] == 0) {         minc[0] = i;         break;       }     }     scanf( %d%d , &n, &m);     int x, y;     char chx[2], chy[2];     for (int i = 0; i < m; ++i) {       scanf( %d%s%d%s , &x, chx, &y, chy);       if (chx[0] ==  V ) x += n;       if (chy[0] ==  V ) y += n;       d[x][y] = 1;       d[fan(y)][fan(x)] = 1;     }     for (int i = 1; i <= 2 * n; ++i) {       d[i][i] = 1;     }     for (int k = 1; k <= 2 * n; ++k) {       for (int i = 1; i <= 2 * n; ++i) {         for (int j = 1; j <= 2 * n; ++j) {           d[i][j] |= d[i][k] & d[k][j];         }       }     }     for (int i = 1; i <= n; ++i) {       minv[i] = minv[0];       minc[i] = minc[0];       for (int j = 1; j <= n; ++j) {         if (d[i][j] && d[i][j + n]) {           minc[i] = 26;         }         if (d[i + n][j] && d[i + n][j + n]) {           minv[i] = 26;         }       }     }     scanf( %s , ch + 1);     for (int i = n + 1; i >= 1; --i) {       memset(now, -1, sizeof(now));       int iminv = 26, iminc = 26;       if (minv[i] != 26)         for (int j = ch[i] -  a  + 1; j < tot; ++j) {           if (p[j]) {             iminv = j;             break;           }         }       if (minc[i] != 26)         for (int j = ch[i] -  a  + 1; j < tot; ++j) {           if (p[j] == 0) {             iminc = j;             break;           }         }       int flag = 1;       for (int j = 1; j < i; ++j) {         now[j] = ch[j] -  a ;       }       for (int j = 1; j < i; ++j) {         int type = p[now[j]];         if (type == 0 && minc[j] == 26) {           flag = 0;           break;         }         if (type == 1 && minv[j] == 26) {           flag = 0;           break;         }         for (int k = 1; k <= n; ++k) {           if (d[j + type * n][k]) {             if (now[k] != -1) {               if (p[now[k]] != 0) {                 flag = 0;                 break;               }             } else {               if (k != i)                 now[k] = minc[k];               else                 now[k] = iminc;             }           }           if (d[j + type * n][k + n]) {             if (now[k] != -1) {               if (p[now[k]] != 1) {                 flag = 0;                 break;               }             } else {               if (k != i)                 now[k] = minv[k];               else                 now[k] = iminv;             }           }         }       }       for (int j = i; j <= n; ++j) {         if (now[j] != -1) continue;         if (j != i) {           now[j] = min(minv[j], minc[j]);         } else {           now[j] = min(iminv, iminc);         }         int type = p[now[j]];         for (int k = 1; k <= n; ++k) {           if (d[j + type * n][k]) {             if (now[k] != -1) {               if (p[now[k]] != 0) {                 flag = 0;                 break;               }             } else {               if (k != i)                 now[k] = minc[k];               else                 now[k] = iminc;             }           }           if (d[j + type * n][k + n]) {             if (now[k] != -1) {               if (p[now[k]] != 1) {                 flag = 0;                 break;               }             } else {               if (k != i)                 now[k] = minv[k];               else                 now[k] = iminv;             }           }         }       }       for (int i = 1; i <= n; ++i) {         if (now[i] == 26) {           flag = 0;           break;         }       }       if (flag) {         for (int i = 1; i <= n; ++i) {           printf( %c , now[i] +  a );         }         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.size();     bool flag = false;     for (int i = 0; i < len - 1; i++) {       if ((s[i] !=  a  && s[i] !=  e  && s[i] !=  i  && s[i] !=  o  &&            s[i] !=  u )) {         if (s[i] ==  n )           continue;         else {           if ((s[i + 1] ==  a  || s[i + 1] ==  e  || s[i + 1] ==  i  ||                s[i + 1] ==  o  || s[i + 1] ==  u )) {             continue;           } else {             flag = true;             break;           }         }       }     }     if ((s[len - 1] !=  a  && s[len - 1] !=  e  && s[len - 1] !=  i  &&          s[len - 1] !=  o  && s[len - 1] !=  u  && s[len - 1] !=  n ))       flag = true;     if (!flag) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1007;   bool ans[MAXN];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int n = s.size();     int l = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  a  && (i == n - 1 || s[i + 1] ==  b )) {         ans[l] = 1;         ans[i] = 1;       }       if (s[i] ==  b ) l = i;     }     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_MEM = (int)1e8;   int mpos = 0;   char mem[MAX_MEM];   inline void *operator new(size_t n) {     char *res = mem + mpos;     mpos += n;     return (void *)res;   }   inline void operator delete(void *) {}   struct __io_dev {     __io_dev(const bool &__fastio = false) {       if (__fastio) ios_base::sync_with_stdio(false), cin.tie(nullptr);       srand(time(nullptr));       if (!string(  ).empty())         freopen(                             .in ,              r , stdin),             freopen(                                     .out ,                  w , stdout);     }     ~__io_dev() { fprintf(stderr,  %.6f ms n , 1e3 * clock() / CLOCKS_PER_SEC); }   } __io(false);   const long long inf = (long long)1e+9 + 7ll;   const long long linf = (long long)1e+18 + 7ll;   const long double eps = (long double)1e-9;   const long double pi = acosl((long double)-1.0);   const int alph = 26;   const int maxs = 512l;   static char buff[(int)2e6 + 17];   long long __p[3] = {29ll, 31ll, 33ll};   long long __mod[3] = {inf, inf + 2ll, 14881337ll};   const int maxn = (int)2e5 + 17;   int n;   string s;   long long R, K;   void print(int R, int K) {     string r;     int cnt = 0;     for (; R > 0; R /= 10) {       r.push_back(char( 0  + R % 10));       ++cnt;       if (cnt % 3 == 0) r.push_back( . );     }     if (r.back() ==  . ) r.pop_back();     if (((int)(r.size())) == 0) r.push_back( 0 );     reverse(r.begin(), r.end());     printf( %s , r.c_str());     if (K != 0) printf( .%.2d , K);   }   int main() {     scanf( %s , buff);     s = string(buff);     n = ((int)(s.size()));     for (int i = 0; i < n; ++i)       if (!( a  <= s[i] && s[i] <=  z )) {         int r = i;         string t =   ;         for (; r < n && !( a  <= s[r] && s[r] <=  z ); ++r) t += s[r];         if (((int)(t.size())) >= 3 && t[((int)(t.size())) - 3] ==  . ) {           K += 10 * (t[((int)(t.size())) - 2] -  0 ) + t[((int)(t.size())) - 1] -                 0 ;           int cursize = ((int)(t.size()));           t.resize(cursize - 3);         }         long long cur = 0;         for (auto c : t)           if ( 0  <= c && c <=  9 ) cur = cur * 10ll + c -  0 ;         R += cur;         i = r - 1;       }     R += K / 100;     K %= 100;     print(R, K);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, p[100002];   bool id[100002];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         int a;         scanf( %d , &a);         p[a] = i;         id[i] = true;       }       id[n + 1] = 0;       bool succeed = true;       int num = 1;       int tp = p[1];       p[1] = 0;       id[tp] = 0;       for (int i = 2; i <= n; i++) {         if (id[tp + 1] == false) {           id[p[i]] = false;           tp = p[i];         } else {           if (tp + 1 != p[i]) {             succeed = false;             break;           } else {             id[tp + 1] = false;             tp = tp + 1;           }         }       }       if (succeed)         printf( Yes n );       else         printf( No n );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   void swap(int *a, int *b) {     int temp = *a;     *a = *b;     *b = temp;   }   unsigned long long int POW(unsigned long long int p, int b) {     unsigned long long int ans = 1LL;     while (b > 0) {       if (b & 1) {         ans = ans * 1LL * p;       }       b /= 2;       p = p * 1LL * p;     }     return ans;   }   long long int power(long long int a, long long int b, long long int mod) {     long long int x = 1;     long long int y = a;     while (b > 0) {       if (b & 1) {         x = x * y;         x %= mod;       }       y = y * y;       y %= mod;       b /= 2;     }     return x;   }   long long int add(long long int a, long long int b, long long int m = MOD) {     long long int x = a + b;     while (x >= m) x -= m;     while (x < 0) x += m;     return x;   }   long long int sub(long long int a, long long int b, long long int m = MOD) {     long long int x = a - b;     while (x < 0) x += m;     while (x >= m) x -= m;     return x;   }   long long int mul(long long int a, long long int b, long long int m = MOD) {     long long int x = a * 1ll * b;     x %= m;     if (x < 0) x += m;     return x;   }   vector<char> g[1001];   int main() {     string str;     cin >> str;     string temp =   ;     int idx = 0;     bool ek = false;     for (int i = 0; i < str.size();) {       if (isdigit(str[i])) {         int j = i;         bool hai = false;         for (j = i; j < str.size(); j++) {           if (!isdigit(str[j]) and !(str[j] ==  . )) break;           if (str[j] ==  .  and (j + 2) < str.size() and               (j + 3 >= (int)str.size() or !isdigit(str[j + 3]) ? 1 : 0)) {             g[idx].push_back(str[j]);             hai = true;             ek = true;           }           if (isdigit(str[j])) g[idx].push_back(str[j]);         }         if (!hai) {           g[idx].push_back( . );           g[idx].push_back( 0 );           g[idx].push_back( 0 );         }         i = j;         idx++;       } else         i++;     }     if (ek == false) {       int s = 0;       int cnt = 0;       int carry = 0;       vector<char> ans;       for (int i = 0; i < idx; i++) {         for (int j = 0; j < 3; j++) g[i].pop_back();       }       while (true) {         s = 0;         bool mila = false;         for (int i = 0; i < idx; i++) {           if (g[i].empty()) continue;           s += (g[i].back() -  0 );           g[i].pop_back();           mila = true;         }         if (mila == false) break;         if (cnt == 3) {           ans.push_back( . );           cnt = 0;         }         s += carry;         ans.push_back(s % 10 +  0 );         carry = s / 10;         cnt++;       }       while (carry != 0) {         if (cnt == 3) {           ans.push_back( . );           cnt = 0;         }         ans.push_back(carry % 10 +  0 );         carry /= 10;         cnt++;       }       reverse(ans.begin(), ans.end());       for (int i = 0; i < ans.size(); i++) cout << ans[i];     } else {       vector<char> ans;       int s = 0;       int cnt = 0;       int carry = 0;       for (int i = 0; i < idx; i++) {         s += g[i].back() -  0 ;         g[i].pop_back();       }       s += carry;       ans.push_back(s % 10 +  0 );       carry = s / 10;       s = 0;       for (int i = 0; i < idx; i++) {         s += g[i].back() -  0 ;         g[i].pop_back();         g[i].pop_back();       }       s += carry;       ans.push_back(s % 10 +  0 );       carry = s / 10;       ans.push_back( . );       while (true) {         s = 0;         bool mila = false;         for (int i = 0; i < idx; i++) {           if (g[i].empty()) continue;           s += (g[i].back() -  0 );           g[i].pop_back();           mila = true;         }         if (mila == false) break;         if (cnt == 3) {           ans.push_back( . );           cnt = 0;         }         s += carry;         ans.push_back(s % 10 +  0 );         carry = s / 10;         cnt++;       }       while (carry != 0) {         if (cnt == 3) {           ans.push_back( . );           cnt = 0;         }         ans.push_back(carry % 10 +  0 );         carry /= 10;         cnt++;       }       int value = 0;       if (ans[0] ==  0  and ans[1] ==  0 ) value = 3;       reverse(ans.begin(), ans.end());       for (int i = 0; i < ans.size() - value; i++) cout << ans[i];     }   }


#include <bits/stdc++.h>   using namespace std;   long long q, dp[105][100005], a[555555], b[555555], k, l, m, n, o, p;   map<long long, long long> mp;   vector<long long> adj[555555];   const long long mod = 1e9 + 7;   void solve() {     cin >> n;     for (long long i = 1; i <= n; i++) {       string s =   ;       cin >> s;       long long op[26], po = 0;       memset(op, 0, sizeof op);       for (auto u : s) {         op[u -  a ]++;       }       for (long long i = 0; i < 26; i++) {         po += (1 << i) * (op[i] % 2);       }       mp[po]++;       a[i] = po;     }     for (long long i = 1; i <= n; i++) {       mp[a[i]]--;       k += mp[a[i]];       for (long long j = 0; j < 26; j++) {         k += mp[a[i] ^ (1 << j)];       }     }     cout << k;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     q = 1;     while (q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const bool debug = false;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string s[8];     for (int i = 0; i < 8; i++) {       cin >> s[i];     }     int r = 0, col = 0;     for (int i = 0; i < 8; i++) {       int c = 0;       for (int j = 0; j < 8; j++) {         if (s[i][j] ==  B ) c++;       }       if (c == 8) r++;     }     for (int i = 0; i < 8; i++) {       int c = 0;       for (int j = 0; j < 8; j++) {         if (s[j][i] ==  B ) c++;       }       if (c == 8) col++;     }     if (r == 0 and col == 0) {       cout << 0;       return 0;     }     if (r == 8 or col == 8) {       cout << 8;       return 0;     }     cout << r + col;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   const int mod = 1000000007;   long long dp[maxn][maxn];   long long s[maxn][maxn], ss[maxn][maxn];   void upd(long long &t, long long k) {     t += k;     t %= mod;   }   int main() {     int n, i, j, m;     long long t;     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 0; j + 1 < m; j++) {         long long t = 1 + s[i - 1][j] * (j + 1) - ss[i - 1][j];         upd(dp[i][j], t);       }       s[i][0] = dp[i][0];       for (j = 1; j + 1 < m; j++) {         s[i][j] = s[i][j - 1] + dp[i][j], ss[i][j] = ss[i][j - 1] + dp[i][j] * j;         s[i][j] %= mod;         ss[i][j] %= mod;       }     }     long long ans = 0;     for (i = 1; i <= n; i++) {       for (j = 0; j + 1 < m; j++) {         long long t1 = dp[i][j] - dp[i - 1][j];         long long t2 = dp[n - i + 1][j];         ans += t1 * t2 % mod * (m - j - 1);         ans %= mod;       }     }     cout << (ans + mod) % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, w, x, c, ans;   int main() {     cin >> a >> b >> w >> x >> c;     if (c <= a) {       cout << 0 << endl;     } else {       ans = ceil(1.0 * (x * (c - a) - b) / (w - x));       cout << ans + c - a << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d, b, l, r, need, ans1, ans2;   long long a[500011], n1[500011], n2[500011];   int main() {     scanf( %lld%lld%lld , &n, &d, &b);     long long re = (n >> 1) * b;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++)       n1[i] = min(a[i], re) + n1[i - 1], re -= min(a[i], re);     re = (n >> 1) * b;     for (int i = n; i; i--)       n2[i] = min(a[i], re) + n2[i + 1], re -= min(a[i], re);     for (int i = 1; i <= n / 2; i++) {       r = min(r + d + 1, n);       if (need + b <= n1[r])         need += b;       else         ans1++;     }     l = n + 1;     need = 0;     for (int i = n; i >= ((n + 1) / 2) + 1; i--) {       l = max(1LL, l - d - 1);       if (need + b <= n2[l])         need += b;       else         ans2++;     }     printf( %lld n , max(ans1, ans2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, ans;     cin >> s;     ans = s;     s += s;     for (int k = 0; k < 10; k++) {       for (int i = 0; i < s.length(); i++) {         s[i]++;         if (s[i] >  9 ) s[i] =  0 ;       }       for (int i = 0; i < n; i++) {         ans = min(ans, s.substr(i, n));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     str[0] = toupper(str[0]);     cout << str;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int inf = 1e9;   int mod = 1e9 + 7;   const int M = 20;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int n = (int)s.length();     int dp[(1 << M)];     memset(dp, 0, sizeof(dp));     int maxi = 0;     for (int i = 0; i < n; i++) {       int mask = 0;       int cnt = 0;       for (int j = i; j < n; j++) {         int x = s[j] -  a ;         if ((mask >> x) & 1) {           break;         }         mask ^= (1 << x);         cnt++;         dp[mask] = cnt;       }       maxi = max(maxi, cnt);     }     for (int i = 0; i < M; i++) {       for (int j = 0; j < (1 << M); j++) {         if (j & (1 << i)) {           dp[j] = max(dp[j], dp[j ^ (1 << i)]);         }       }     }     for (int i = 0; i < (1 << M); i++) {       int comp = (1 << M) - 1 - i;       maxi = max(maxi, dp[i] + dp[comp]);     }     cout << maxi <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 2e6 + 5;   struct task {     int t, k, d;   } tasks[maxm];   int times[110];   int main() {     for (int i = 0; i < 110; ++i) {       times[i] = 0;     }     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &tasks[i].t, &tasks[i].k, &tasks[i].d);     }     for (int i = 0; i < m; ++i) {       int num = 0, j = 1, res = 0;       if (tasks[i].k > n) {         printf( -1 n );         continue;       }       while (j <= n) {         if (times[j] <= tasks[i].t) {           num++;         }         if (num == tasks[i].k) break;         j++;       }       j = 1;       if (num == tasks[i].k) {         int cnt = 0;         while (j <= n) {           if (times[j] <= tasks[i].t) {             res += j;             times[j] = tasks[i].t + tasks[i].d;             cnt++;           }           if (cnt == tasks[i].k) break;           j++;         }         printf( %d n , res);       } else {         printf( -1 n );         continue;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510;   int t, n, m, a, b, c;   vector<pair<int, int> > g[N];   int dp[N][N], inDegree[N][N], source, ans[N][N];   bool vis[N];   void dfs(int u) {     if (vis[u]) return;     vis[u] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first;       int newCost = g[u][i].second + dp[source][u];       if (dp[source][v] == newCost) {         inDegree[source][v]++;         dfs(v);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = 1e9;       }       dp[i][i] = 0;     }     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &a, &b, &c);       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));       dp[a][b] = min(dp[a][b], c);       dp[b][a] = min(dp[b][a], c);     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);         }       }     }     for (source = 1; source <= n; source++) {       memset(vis, 0, sizeof vis);       dfs(source);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (dp[i][k] + dp[k][j] == dp[i][j]) {             ans[i][j] += inDegree[i][k];           }         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         printf( %d  , ans[i][j]);       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005];   bool got[200004], gave[200004];   queue<int> q;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       got[a[i]] = 1;       if (a[i] != 0) {         gave[i] = 1;       }     }     for (int i = 1; i <= n; i++) {       if (!got[i]) {         q.push(i);       }     }     for (int i = 1; i <= n; i++) {       if (!got[i] && !gave[i]) {         int x = q.front();         q.pop();         if (x == i) {           q.push(x);           x = q.front();           q.pop();         }         a[i] = x;         gave[i] = 1;         got[x] = 1;       }     }     for (int i = 1; i <= n; i++) {       if (!gave[i]) {         int x = q.front();         q.pop();         a[i] = x;         gave[i] = 1;         got[x] = 1;       }     }     for (int i = 0; i < n; i++) {       cout << a[i + 1] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   bool check(string pattern, string text) {     int j = 0;     int i = 0;     while (i < text.size()) {       if (pattern[j] == text[i]) {         j++;       }       i++;     }     return j == pattern.size();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int d;     cin >> d;     while (d--) {       string s, t, p;       cin >> s >> t >> p;       string k = s;       s = s + p;       map<char, long long int> m_s;       map<char, long long int> m_t;       for (int i = 0; i < s.size(); ++i) {         m_s[s[i]]++;       }       for (int i = 0; i < t.size(); ++i) {         m_t[t[i]]++;       }       bool checks = true;       for (auto i : m_t) {         if (m_s[i.first] < i.second) {           checks = false;         }       }       if (checks && check(k, t)) {         cout <<  YES               <<   n ;       } else {         cout <<  NO               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   t ;     err(++it, args...);   }   const long double eps = 1e-9;   const long long mod = 1e9 + 7;   pair<long long, long long> dir[8] = {{-1, 0}, {1, 0},   {0, -1}, {0, 1},                                        {1, 1},  {-1, -1}, {-1, 1}, {1, -1}};   const long long nn = 3e5 + 5;   vector<long long> g[nn];   long long par[nn];   long long sz[nn];   long long centroid[nn];   void dfs(long long v) {     sz[v] = 1;     for (long long to : g[v]) {       dfs(to);       sz[v] += sz[to];     }     long long bad = -1;     for (long long to : g[v]) {       if (sz[to] * 2 > sz[v]) bad = to;     }     if (bad == -1) {       centroid[v] = v;     } else {       centroid[v] = centroid[bad];       while (sz[centroid[v]] * 2 <= sz[v]) {         centroid[v] = par[centroid[v]];       }     }   }   void robin() {     long long n, q;     cin >> n >> q;     for (long long i = 2; i <= n; i++) {       long long v;       cin >> v;       par[i] = v;       g[v].push_back(i);     }     dfs(1);     while (q--) {       long long v;       cin >> v;       cout << centroid[v] <<   n ;     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T = 1;     for (long long tc = 1; tc <= T; tc++) {       robin();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int k;     cin >> k;     int sum = (1 << 18) - 1;     cout <<  3 3 n ;     cout << sum <<     << (1 << 17) <<     << 0 <<   n ;     cout << k <<     << sum <<     << 0 <<   n ;     cout << 0 <<     << k <<     << k <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int a[200000];   int b[200001];   int br[200001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) cin >> b[i];     int minimum = 0;     for (int i = 1; i <= m; i++) minimum += b[i];     int ok = 0;     for (int i = 1; i <= m; i++) ok += !b[i];     int left = 0;     int ans = n + 1;     for (int right = 0; right < n; right++) {       br[a[right]]++;       if (br[a[right]] == b[a[right]]) ok++;       while (ok == m) {         ans = min(ans, right - left + 1);         if (br[a[left]] == b[a[left]]) ok--;         br[a[left]]--;         left++;       }     }     if (ans == n + 1)       cout << -1 << endl;     else       cout << ans - minimum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   vector<pair<string, int> > ch[MAXN];   int nxt[MAXN][27], n, gp, ans;   string t;   void adds(string &tmp) {     for (int i = 0; i < tmp.size(); i++) {       gp = nxt[gp][tmp[i] -  a ];       if (gp == t.size()) ans++;     }   }   void dfs(int v, int p) {     for (int i = 0; i < ch[v].size(); i++) {       gp = p;       adds(ch[v][i].first);       dfs(ch[v][i].second, gp);     }   }   int main() {     cin >> n;     for (int i = 2; i <= n; i++) {       string tmp;       int r;       cin >> r >> tmp;       ch[r].push_back({tmp, i});     }     cin >> t;     nxt[0][t[0] -  a ] = 1;     int cp = 0;     for (int i = 1; i <= t.size(); i++) {       for (char c =  a ; c <=  z ; c++) {         if (t[cp] == c)           nxt[i][c -  a ] = cp + 1;         else           nxt[i][c -  a ] = nxt[cp][c -  a ];       }       if (i < t.size()) {         nxt[i][t[i] -  a ] = i + 1;         if (t[cp] == t[i])           cp++;         else           cp = nxt[cp][t[i] -  a ];       }     }     dfs(1, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void gmin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   void gmax(T &a, T b) {     a = a > b ? a : b;   }   const int MAXV = 410;   const int MAXE = 1650;   const int INF = 0x3f3f3f3f;   struct Edge {     int to, cap, nxt, cost;     Edge() {}     Edge(int to, int cap, int nxt, int cost)         : to(to), cap(cap), nxt(nxt), cost(cost) {}   } edge[MAXE << 1];   int head[MAXV], cnt;   void initedge() {     memset(head, -1, sizeof(head));     cnt = 0;   }   inline void addedge(int from, int to, int cap, int cost) {     edge[cnt] = Edge(to, cap, head[from], cost);     head[from] = cnt++;   }   inline void addedge2(int from, int to, int cap, int cost) {     addedge(from, to, cap, cost);     addedge(to, from, 0, -cost);   }   int dist[MAXV];   int iter[MAXV];   bool inq[MAXV];   bool SPFA(int S, int T) {     static int q[MAXV];     int f = 0, r = 0;     memset(dist, INF, sizeof(dist));     memset(inq, 0, sizeof(inq));     dist[S] = 0;     q[r++] = S;     inq[S] = true;     while (f != r) {       int x = q[f++];       inq[x] = false;       if (f == MAXV) f = 0;       for (int p = head[x]; ~p; p = edge[p].nxt) {         Edge e = edge[p];         if (e.cap && dist[e.to] > dist[x] + e.cost) {           dist[e.to] = dist[x] + e.cost;           if (!inq[e.to]) {             q[r++] = e.to;             inq[e.to] = true;             if (r == MAXV) r = 0;           }         }       }     }     return dist[T] < INF;   }   int getflow(int x, int lim, int T) {     if (x == T) return lim;     inq[x] = true;     int nowflow = 0, newflow;     for (register int &p = iter[x]; ~p; p = edge[p].nxt) {       register Edge &e = edge[p];       if (!inq[e.to] && e.cap && dist[e.to] == dist[x] + e.cost) {         newflow = getflow(e.to, min(e.cap, lim - nowflow), T);         e.cap -= newflow;         edge[p ^ 1].cap += newflow;         nowflow += newflow;         if (nowflow >= lim) break;       }     }     return nowflow;   }   int mincostmaxflow(int S, int T) {     int nowcost = 0, newflow;     while (SPFA(S, T)) {       for (int i = 0; i < MAXV; i++) iter[i] = head[i];       memset(inq, 0, sizeof(inq));       do {         newflow = getflow(S, INF, T);         nowcost += newflow * dist[T];       } while (newflow);     }     return nowcost;   }   const int MAXN = 210;   const int MAXM = 210;   int S, T, second, TT;   int n1, n2, m, r, b;   int id[MAXM];   int delta[MAXV];   char s[MAXN];   int ans;   int main() {     initedge();     scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b);     S = 0;     T = n1 + n2 + 1;     scanf( %s , s);     for (int i = 1; i <= n1; i++) {       char c = s[i - 1];       if (c ==  R ) {         addedge2(i, T, INF - 1, 0);         delta[i] -= 1;         delta[T] += 1;       }       if (c ==  B ) {         addedge2(S, i, INF - 1, 0);         delta[S] -= 1;         delta[i] += 1;       }       if (c ==  U ) {         addedge2(S, i, INF - 0, 0);         addedge2(i, T, INF - 0, 0);       }     }     scanf( %s , s);     for (int i = 1; i <= n2; i++) {       char c = s[i - 1];       if (c ==  B ) {         addedge2(n1 + i, T, INF - 1, 0);         delta[n1 + i] -= 1;         delta[T] += 1;       }       if (c ==  R ) {         addedge2(S, n1 + i, INF - 1, 0);         delta[S] -= 1;         delta[n1 + i] += 1;       }       if (c ==  U ) {         addedge2(S, n1 + i, INF - 0, 0);         addedge2(n1 + i, T, INF - 0, 0);       }     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       id[i] = cnt;       addedge2(x, n1 + y, 1 - 0, b);       addedge2(n1 + y, x, 1 - 0, r);     }     addedge2(T, S, INF - 0, 0);     second = n1 + n2 + 2;     TT = n1 + n2 + 3;     int sum = 0;     for (int i = S; i <= T; i++) {       if (delta[i] > 0) addedge2(second, i, delta[i], 0), sum += delta[i];       if (delta[i] < 0) addedge2(i, TT, -delta[i], 0);     }     ans = mincostmaxflow(second, TT);     sum = 0;     for (int p = head[second]; ~p; p = edge[p].nxt) sum += edge[p].cap;     if (!sum) {       printf( %d n , ans);       for (int i = 0; i < m; i++) {         if (edge[id[i]].cap == 0)           putchar( B );         else if (edge[id[i] + 2].cap == 0)           putchar( R );         else           putchar( U );       }       putchar(  n );     } else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   const int N = 810;   const int M = 10;   int mod[N][M];   int ans[N], inv[N], a[N];   int n;   void print() {     if (ans[1] > n / 2) {       for (int i = 1; i <= n; ++i) {         ans[i] = n + 1 - ans[i];       }     }     printf( ! );     for (int i = 1; i <= n; ++i) {       printf(  %d , ans[i]);     }     puts(  );   }   int ask(std::vector<int> vec, int calcmod) {     int n = vec.size();     printf( ? %d , n);     for (auto u : vec) {       printf(  %d , u);     }     puts(  );     fflush(stdout);     int ret;     scanf( %d , &ret);     if (calcmod > 0) {       if (ret) {         int sum = 0;         for (auto u : vec) {           if (u != calcmod) {             sum = (sum + ans[u]) % n;           }         }         mod[calcmod][n] = (n - sum) % n;       }     }     return ret;   }   int main() {     scanf( %d , &n);     memset(mod, -1, sizeof(mod));     mod[1][2] = 1;     for (int i = 1; i < n; ++i) {       mod[i + 1][2] = mod[i][2] ^ (1 - ask({i, i + 1}, 0));     }     for (int i = 1; i <= 4 && i <= n / 2; ++i) {       std::vector<int> todo;       for (int j = 1; j <= n; ++j) {         if (!ans[j]) {           todo.emplace_back(j);         }       }       for (auto j : todo) {         std::vector<int> vec;         for (auto k : todo) {           if (j != k) {             vec.emplace_back(k);           }         }         if (ask(vec, 0)) {           ans[j] = mod[j][2] == i % 2 ? i : n + 1 - i;           inv[ans[j]] = j;         }       }     }     if (n <= 8) {       print();       return 0;     }     for (int i = 3; i <= 7; i += 2) {       using pii = std::pair<int, int>;       std::vector<pii> to_check;       std::vector<int> known;       for (int j = 0; j <= i / 2; ++j) {         to_check.emplace_back(1, n - 3 + j);       }       for (int j = 1; j <= i / 2; ++j) {         to_check.emplace_back(i / 2 + 1, n - 3 + j);       }       for (int j = 0; j <= i / 2; ++j) {         known.emplace_back(j + 1);         known.emplace_back(j + n - 3);       }       for (auto p : to_check) {         for (int j = 1; j <= n; ++j) {           if (ans[j] || mod[j][i] != -1) {             continue;           }           std::vector<int> vec = {j};           for (auto u : known) {             if (u == p.first || u == p.second) {               continue;             }             vec.emplace_back(inv[u]);           }           ask(vec, j);         }       }     }     for (int i = 1; i <= n; ++i) {       if (ans[i]) {         continue;       }       ask({inv[1], inv[2], inv[3], i}, i);       if (mod[i][4] != -1) {         continue;       }       ask({inv[1], inv[2], inv[4], i}, i);       if (mod[i][4] != -1) {         continue;       }       mod[i][4] = mod[i][2] == 1 ? 3 : 0;     }     std::vector<bool> calced(8);     int sum = 0;     for (int i = 1; i <= 4; ++i) {       sum += n - 4 + i;       sum += i;     }     for (int i = 1; i <= 4; ++i) {       calced[(8 - (sum - i) % 8) % 8] = true;     }     for (int i = 1; i <= n; ++i) {       if (ans[i]) {         continue;       }       int pos = 0;       for (int j = 1; j <= 4; ++j) {         if ((sum - j) % 4 == (4 - mod[i][4]) % 4) {           pos = j;           break;         }       }       std::vector<int> vec = {i};       for (int j = 1; j <= 4; ++j) {         vec.emplace_back(inv[n - 4 + j]);         if (j != pos) {           vec.emplace_back(inv[j]);         }       }       ask(vec, i);       if (mod[i][8] == -1) {         mod[i][8] = (calced[mod[i][4]] ? 4 : 0) ^ mod[i][4];       }     }     for (int i = 1; i <= n; ++i) {       if (ans[i]) {         continue;       }       for (int j = 1; j <= n; ++j) {         bool flag = true;         for (auto u : {3, 5, 7, 8}) {           if (j % u != mod[i][u]) {             flag = false;             break;           }         }         if (flag) {           ans[i] = j;           break;         }       }     }     print();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int x = 0, y = 0, p, q, sum = 0;       set<pair<int, int> > ma;       for (long long int i = 0; i < s.size(); i++) {         p = x;         q = y;         if (s[i] ==  N )           y++;         else if (s[i] ==  S )           y--;         else if (s[i] ==  W )           x++;         else           x--;         if (!ma.count({x + p, q + y})) {           sum = sum + 5;           ma.insert({x + p, q + y});         } else           ++sum;       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e6 + 100;   const long long maxM = 1e3 + 100;   const long long mod = 1e9 + 7;   const long long hmod = 1e16 + 7;   const long double PI = 3.141592653;   const long double eps = 1e-8;   const long long D = 1379;   const long long INF = 1e18 + 20;   const long long Inf = 1e9 + 140;   void NO() {     cout <<  NO  << endl;     exit(0);   }   void YES() {     cout <<  YES  << endl;     exit(0);   }   long long n, k;   bool mrk[2][maxN], mark[2][maxN];   void dfs(long long v, long long x = 0, long long W = 0) {     if (v > n) YES();     if (v <= 0 || mrk[x][v] || mark[x][v] || v <= W) return;     mark[x][v] = true;     W++;     dfs(v + k, x ^ 1, W);     dfs(v + 1, x, W);     dfs(v - 1, x, W);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       char c;       cin >> c;       if (c ==  X ) mrk[0][i] = true;     }     for (long long i = 1; i <= n; i++) {       char c;       cin >> c;       if (c ==  X ) mrk[1][i] = true;     }     dfs(1);     NO();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, x;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> x;       cout << 2 * x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double prb[(1 << 21)], p[25], ans[25];   int vis[(1 << 21)];   bool eq(double a, double b) { return (abs(a - b) < 1e-12); }   int main() {     int i, n, k, tmp;     scanf( %d , &n);     scanf( %d , &k);     tmp = n;     for (i = 0; i < n; i++) {       scanf( %lf , &p[i]);       if (eq(p[i], 0)) tmp--;     }     k = min(k, tmp);     prb[0] = 1;     queue<int> all;     all.push(0);     while (!all.empty()) {       int now = all.front();       all.pop();       if (__builtin_popcount(now) == k)         for (i = 0; i < n; i++)           if (now & (1 << i)) ans[i] += prb[now];       double gun = 0;       for (i = 0; i < n; i++)         if (!(now & (1 << i))) gun += p[i];       gun = 1 / gun;       if (__builtin_popcount(now) < k)         for (i = 0; i < n; i++) {           if ((now & (1 << i)) || eq(p[i], 0)) continue;           tmp = now ^ (1 << i);           prb[tmp] += (p[i] * gun * prb[now]);           if (!vis[tmp]) {             vis[tmp] = 1;             all.push(tmp);           }         }     }     for (i = 0; i < n; i++) printf( %.15f  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 100;   vector<int> v[MAX_N];   int dp[MAX_N], ans, deep[MAX_N];   void dfs(int x, int fa, int dep) {     int i;     deep[x] = dep;     for (i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (y == fa) continue;       dfs(y, x, dep + 1);     }   }   void dfs(int x, int fa) {     int i;     dp[x] = 0;     for (i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (y == fa) continue;       dfs(y, x);       ans = max(ans, dp[x] + dp[y] + 1);       dp[x] = max(dp[x], dp[y] + 1);     }   }   int main(void) {     int T, n, a, b, da, db, i, x, y;     cin >> T;     while (T--) {       scanf( %d%d%d%d%d , &n, &a, &b, &da, &db);       for (i = 1; i <= n; i++) v[i].clear();       for (i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         v[x].push_back(y);         v[y].push_back(x);       }       dfs(a, -1, 0);       if (deep[b] <= da) {         puts( Alice );         continue;       }       if (da * 2 >= db) {         puts( Alice );         continue;       }       ans = 0;       dfs(1, -1);       if (da * 2 >= ans)         puts( Alice );       else         puts( Bob );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Count(int ar[], int m, int n) {     int count = 0, i;     for (i = 0; i < n; i++) {       if (ar[i] == m) {         count++;       }     }     return count;   }   void change(int br[], int ar[], int n, int clr, int d, int m) {     int count = 0, i;     for (i = 0; i < n; i++) {       if (ar[i] == m) {         count++;         br[i] = ceil(float(count) / d) + clr;         ar[i] = -1;       }     }   }   int main() {     int n, i, cnt = 0;     cin >> n;     int ar[n], br[n];     for (i = 0; i < n; i++) {       br[i] = 0;     }     for (i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] == 0) {         cnt++;       }     }     if (cnt == n) {       cout <<  Possible n ;       for (i = 0; i < n; i++) {         cout << 1 <<    ;       }       return 0;     }     if (cnt != 0) {       cout <<  Impossible ;       return 0;     }     int m, count, clr = 0;     m = *max_element(ar, ar + n);     while (m != -1) {       m = *max_element(ar, ar + n);       count = Count(ar, m, n);       if ((n - count) > m) {         cout <<  Impossible ;         return 0;       }       if (m == n - count) {         change(br, ar, n, clr, count, m);         clr++;       } else {         int bp = m - (n - count);         if (bp % (count - bp) == 0) {           change(br, ar, n, clr, count - bp, m);           clr += count / (count - bp);         } else {           cout <<  Impossible ;           return 0;         }       }       m = *max_element(ar, ar + n);     }     cout <<  Possible n ;     for (i = 0; i < n; i++) {       cout << br[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct hash_pair {     template <class T1, class T2>     size_t operator()(const pair<T1, T2>& p) const {       auto hash1 = hash<T1>{}(p.first);       auto hash2 = hash<T2>{}(p.second);       return hash1 ^ hash2;     }   };   string ans =   ;   int flag = 0;   int res = 0;   void permut(string n, int s, int l) {     if (flag == 1) return;     if (s == l) {       if ((res * 10000 + stoi(n)) % 7 == 0) {         flag = 1;         ans += n;       }       return;     }     for (int i = s; i <= l; i++) {       swap(n[s], n[i]);       permut(n, s + 1, l);       swap(n[s], n[i]);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string n;     cin >> n;     int one = 0;     int six = 0;     int eight = 0;     int nine = 0;     string zero =   ;     for (int i = 0; i < n.length(); i++) {       if (n[i] ==  1  && one == 0) {         one = 1;       } else if (n[i] ==  6  && six == 0) {         six = 1;       } else if (n[i] ==  8  && eight == 0) {         eight = 1;       } else if (n[i] ==  9  && nine == 0) {         nine = 1;       } else {         if (n[i] ==  0  && ans.length() == 0) {           zero +=  0 ;         } else {           ans += n[i];           res *= 10;           res += n[i] -  0 ;           res %= 7;         }       }     }     permut( 1689 , 0, 3);     if (ans.length() != 0)       cout << ans + zero;     else       cout <<  0 ;   }


#include <bits/stdc++.h>   int main() {     int i, y, ans, z, b, x[2];     for (i = 0; i < 2; i++) {       scanf( %d , &x[i]);     }     y = x[0] * x[1];     ans = y / 2;     { printf( %d , ans); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NUM = 2e5 + 10;   struct node {     int index, q;     bool operator<(const node &a) const { return index + q < a.index + a.q; }   } no[NUM];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &no[i].index, &no[i].q);     sort(no, no + n);     int ans = 1, last = 0;     for (int i = 1; i < n; i++) {       if (no[i].index - no[i].q >= no[last].index + no[last].q) {         last = i;         ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   const long double PI = acos(-1.0);   const int MX = 1e5 + 5;   long long mod = 1e9 + 7;   pair<long long, int> tr[5 * MX];   long long lz[5 * MX];   vector<int> ids[MX];   int rnum[MX];   inline void prop(int n, int l, int r) {     if (lz[n]) {       tr[n].first += lz[n];       if (l != r) lz[n << 1] += lz[n], lz[n << 1 | 1] += lz[n];       lz[n] = 0;     }   }   const long long inf = 1e15;   void bld(int n, int l, int r) {     if (l == r) {       if (((int)(ids[l]).size()))         tr[n] = {ids[l].back(), rnum[l]};       else         tr[n] = {inf, 0};       return;     }     int m = (l + r) >> 1;     bld(n << 1, l, m);     bld(n << 1 | 1, m + 1, r);     tr[n] = min(tr[n << 1], tr[n << 1 | 1]);   }   int I, L, R, V;   void del(int n, int l, int r) {     prop(n, l, r);     if (I < l or I > r) return;     if (l == r) {       long long aded = tr[n].first - ids[l].back();       ids[l].pop_back();       if (((int)(ids[l]).size()))         tr[n] = {ids[l].back(), rnum[l]};       else         tr[n] = {inf, rnum[l]};       tr[n].first += aded;       return;     }     int m = (l + r) >> 1;     del(n << 1, l, m);     del(n << 1 | 1, m + 1, r);     tr[n] = min(tr[n << 1], tr[n << 1 | 1]);   }   void upd(int n, int l, int r) {     prop(n, l, r);     if (l > R or r < L) return;     if (l >= L and r <= R) {       lz[n] += V;       prop(n, l, r);       return;     }     int m = (l + r) >> 1;     upd(n << 1, l, m);     upd(n << 1 | 1, m + 1, r);     tr[n] = min(tr[n << 1], tr[n << 1 | 1]);   }   pair<long long, int> qry(int n, int l, int r) {     prop(n, l, r);     if (l > R or r < L) return {inf, 0};     if (l >= L and r <= R) {       return tr[n];     }     int m = (l + r) >> 1;     pair<long long, int> a = qry(n << 1, l, m);     pair<long long, int> b = qry(n << 1 | 1, m + 1, r);     tr[n] = min(tr[n << 1], tr[n << 1 | 1]);     return min(a, b);   }   vector<int> adj[MX];   int par[MX], sz[MX], heavy[MX];   void dfs1(int u, int p) {     par[u] = p;     sz[u] = 1;     for (int v : adj[u]) {       if (v != p) {         dfs1(v, u);         sz[u] += sz[v];         if (sz[v] > sz[heavy[u]]) heavy[u] = v;       }     }   }   int st[MX], chain[MX], num[MX], ed[MX], cl, cn, head[MX];   void dfs(int u) {     st[u] = cl;     chain[u] = cn;     num[u] = cl;     rnum[cl++] = u;     if (heavy[u]) dfs(heavy[u]);     for (int v : adj[u]) {       if (v != par[u] and v != heavy[u]) {         head[++cn] = v;         dfs(v);       }     }     ed[u] = cl - 1;   }   inline int climb(int u, int v, int n) {     pair<long long, int> res = {inf, 0};     while (chain[u] != chain[v]) {       if (chain[v] > chain[u]) swap(u, v);       R = num[u];       L = num[head[chain[u]]];       res = min(res, qry(1, 0, n - 1));       u = par[head[chain[u]]];     }     if (num[v] > num[u]) swap(u, v);     L = num[v], R = num[u];     res = min(res, qry(1, 0, n - 1));     if (res.first >= inf) return 0;     int ret = ids[num[res.second]].back();     I = num[res.second];     del(1, 0, n - 1);     return ret;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs1(1, 0);     head[0] = 1;     dfs(1);     for (int i = 1; i <= m; i++) {       int c;       cin >> c;       ids[num[c]].emplace_back(i);     }     for (int i = 0; i < n; i++) reverse((ids[i]).begin(), (ids[i]).end());     bld(1, 0, n - 1);     while (q--) {       int t;       cin >> t;       int u, v, k;       if (t == 1) {         cin >> u >> v >> k;         vector<int> ans;         while (k--) {           int i = climb(u, v, n);           if (i)             ans.push_back(i);           else             break;         }         cout << ((int)(ans).size());         for (int i : ans) cout <<     << i;         cout <<   n ;       } else {         cin >> u >> k;         L = st[u];         R = ed[u];         V = k;         upd(1, 0, n - 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[105], k;   int n;   bool check(long long x) {     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += (arr[i] + x - 1LL) / x;     }     return x * sum <= k;   }   int main(int argc, char const *argv[]) {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i], k += arr[i];     long long ans = 0;     for (long long i = 1; i <= sqrt(k) + 1; i++) {       if (check(i)) ans = max(ans, i);       if (check(k / i)) ans = max(ans, k / i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int cnt, n;     cin >> n;     cnt = 0;     cnt += n / 100;     n %= 100;     cnt += n / 20;     n %= 20;     cnt += n / 10;     n %= 10;     cnt += n / 5;     n %= 5;     cnt += n;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   int Cmp(const void *a, const void *b);   int main(void) {     int i, n, x, w, gpos = -2 * 1000000000, ans = 0, grange[200000][2];     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &x, &w);       grange[i][0] = x - w;       grange[i][1] = x + w;     }     qsort(grange, n, sizeof(int) * 2, Cmp);     for (i = 0; i < n; i++) {       if (gpos <= grange[i][0]) {         ans++;         gpos = grange[i][1];       }     }     printf( %d n , ans);   }   int Cmp(const void *a, const void *b) {     int ta = *(*(int(*)[2])a + 1), tb = *(*(int(*)[2])b + 1);     if (ta > tb)       return 1;     else if (tb > ta)       return -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       map<int, int> cur;       set<pair<int, int>> st;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (!cur.count(a[i])) {           st.insert(make_pair(a[i], i));         }         cur[a[i]] = i;       }       if (st.size() == 1) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         vector<pair<int, int>> res;         auto e = st.begin(), g = prev(st.end());         for (int i = 0; i < n; i++) {           if (a[i] != e->first) {             res.emplace_back(i + 1, e->second + 1);           } else if (i != g->second && i != e->second)             res.emplace_back(i + 1, g->second + 1);         }         for (auto j : res) cout << j.first <<     << j.second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Max = INT_MIN, Min = INT_MAX;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m, mx = 0;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       if ((a[i] - a[i + 1] - m) > mx) {         mx = (a[i] - a[i + 1] - m);       }     }     cout << ((mx > 0) ? mx : 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, n, i, j, z, mx;   string s, s2;   int main() {     cin >> a >> b >> c;     mx = max(max(a, b), c);     for (i = 1; i <= mx; i++) {       for (j = 1; j <= mx; j++) {         z = c / j;         if (i * j == a && i * z == b && j * z == c) {           cout << i * 4 + j * 4 + z * 4;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, t;     cin >> t;     while (t--) {       cin >> n;       if (n % 2 == 0)         cout << n / 2 <<   n ;       else         cout << (n / 2) + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6;   long long seg_t[MAXN * 4];   long long n, k, cur, ans = 1;   void add(long long u, long long curl, long long curr, long long l, long long r,            long long delta) {     long long curm = (curl + curr) / 2;     if (l == curl && r == curr) {       seg_t[u] += delta;       return;     }     if (l <= curm) {       if (r >= curm) {         add(u * 2, curl, curm, l, curm, delta);       } else {         add(u * 2, curl, curm, l, r, delta);       }     }     if (r >= curm + 1) {       if (l <= curm + 1) {         add(u * 2 + 1, curm + 1, curr, curm + 1, r, delta);       } else {         add(u * 2 + 1, curm + 1, curr, l, r, delta);       }     }   }   long long get(long long u, long long curl, long long curr, long long x) {     long long ret = 0;     long long curm = (curl + curr) / 2;     ret += seg_t[u];     if (curl == curr) return ret;     if (x <= curm) {       ret += get(u * 2, curl, curm, x);     } else if (x >= curm + 1) {       ret += get(u * 2 + 1, curm + 1, curr, x);     }     return ret;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     k = min(k, n - k);     long long r, l = 1;     for (long long i = 0; i < n; ++i) {       r = l + k;       if (r > n) {         add(1, 1, n + 1, l + 1, n + 1, 1);         r -= n;         if (r > 1) add(1, 1, n + 1, 1, r - 1, 1);       } else {         add(1, 1, n + 1, l + 1, r - 1, 1);       }       ans += 1 + get(1, 1, n + 1, l) + get(1, 1, n + 1, r);       cout << ans <<    ;       l = r;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100;   int ara[N];   int main() {     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , ara + i);     }     if (n == 1)       puts( -1 );     else if (n == 2 && ara[0] == ara[1])       puts( -1 );     else {       int mn = 10000;       int nm = 0;       for (int i = 0; i < n; ++i) {         if (ara[i] < mn) {           mn = ara[i];           nm = i;         }       }       ++nm;       printf( 1 n%d n , nm);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   struct node{    int x, y, id;    bool operator <(const node& W) const{     if (W.x != x) return x < W.x;     else return y < W.y;    }   };      void work() {    int n;    cin >> n;    vector<node> v(n);    for (int i = 0; i < n; i++) {     int x, y;     cin >> x >> y;     if (x > y) swap(x, y);     v[i] = {x, y, i + 1};    }    sort(v.begin(), v.end());    vector<int> res(n + 1);    int pos = -1;        for (int i = 0; i < v.size(); i++) {     int j = i;     while (j < v.size() && v[i].x == v[j].x) j++;     j--;     if (pos == -1) for (int k = i; k <= j; k++) res[v[k].id] = -1;     else {      for (int k = i; k <= j; k++)        if (v[k].y > v[pos].y) res[v[k].id] = v[pos].id;       else res[v[k].id] = -1;     }     if (pos == -1) pos = 0;     else if (v[i].y < v[pos].y) pos = i;     i = j;    }        for (int i = 1; i < res.size(); i++) cout << res[i] <<    ;    cout << endl;   }   int32_t main() {    ios::sync_with_stdio(false);    cin.tie(0);    int cas;    cin >> cas;    while (cas--) work();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> sieve;   vector<long long int> *Sieve(int N) {     const long long int maxn = N;     sieve.resize(maxn);     for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1;     sieve[1] = 0;     sieve[0] = 0;     for (long long int(i) = 2; (i) <= (maxn); (i) += (1))       if (1 == sieve[i])         for (long long int j = i * i; j < maxn; j += i) sieve[j] = 0;     vector<long long int> *primes = new vector<long long int>();     primes->push_back(2);     for (int i = 3; i < maxn; i += 2)       if (sieve[i]) {         primes->push_back(i);       }     return primes;   }   long long int extended_GCD(long long int a, long long int b, long long int &x,                              long long int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long int x1, y1;     long long int gcd = extended_GCD(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   long long int ncr(long long int n, long long int k) {     long long int r = 1;     if (k > n - k) k = n - k;     for (long long int i = 0; i < k; i++) {       r *= (n - i);       r /= (i + 1);     }     return r;   }   long long int power(long long int a, long long int b,                       long long int m = 1000000007) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % m;       a = (a * a) % m;       b >>= 1;     }     return res;   }   long long int modinv(long long int a, long long int mod = 1000000007) {     long long int x, y;     extended_GCD(a, mod, x, y);     if (x < 0) x += mod;     return x;   }   bool prime(int n) {     int c = 0;     for (int i = 2; (i * i) <= n; i++) {       if (n % i == 0) {         c++;         return false;       }     }     if (c == 0) return true;   }   vector<int> v[200006];   int vis[200006];   int c;   void dfs(int n) {     vis[n] = 1;     c++;     for (int i : v[n]) {       if (!vis[i]) dfs(i);     }   }   int a[100001];   void solve() {     int n, k;     cin >> n >> k;     int a[n];     for (long long int(i) = 0; (i) < (n); ++(i)) cin >> a[i];     int sa = 1, sb = 1;     double ca = 0, cb = k;     int i = 0, j = n - 1;     double ans = 0;     while (i <= j) {       double t1, t2, d1, d2;       d1 = a[i] - ca;       d2 = cb - a[j];       t1 = (double)d1 / sa;       t2 = (double)d2 / sb;       if (t1 <= t2) {         ans += t1;         ca += d1;         i++;         sa++;         cb -= (double)t1 * sb;       } else {         ans += t2;         cb -= d2;         j--;         sb++;         ca += (double)t2 * sa;       }     }     ans += double(cb - ca) / (sa + sb);     cout << fixed << setprecision(10) << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int    int main()   {       int t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           vector<ll>a(n);           for(ll i=0;i<n;i++)           {               cin>>a[i];           }           ll maxi=INT_MIN;           for(ll i=n-1;i>-1;i--)           {               ll total=0;               total+=a[i];               if(i+a[i]<n)               {                   total+=a[i+a[i]];               }               a[i]=total;               maxi=max<ll>(maxi,total);           }           //cout<<  t ;           cout<<maxi<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   class subtractions {    private:     int _a, _b;     int _operations;     bool even_divide(int& a, int& b) {       if (b > a && !(b % a)) {         _operations += (b / a);         return true;       } else if (a >= b && !(a % b)) {         _operations += (a / b);         return true;       }       return false;     }     bool quick_divide(int& a, int& b) {       if (b > a) {         int factor = b / a;         b -= a * factor;         _operations += factor;         return true;       } else if (a >= b) {         int factor = a / b;         a -= b * factor;         _operations += factor;         return true;       }       return false;     }       public:     subtractions(int a = 0, int b = 0) : _a(a), _b(b) { _operations = 0; }     int operate() {       while (_a > 0 && _b > 0) {         if (even_divide(_a, _b)) break;         if (quick_divide(_a, _b)) continue;         ++_operations;       }       return _operations;     }   };   int main() {     int tests = 0;     cin >> tests;     while (tests > 0) {       int a, b;       cin >> a >> b;       subtractions s(a, b);       cout << s.operate() << endl;       --tests;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long w[3][300500];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0, qwerty = n; i < qwerty; i++) {       cin >> s;       stack<char> st;       st.push(s[0]);       for (int j = 1, qwerty = s.size(); j < qwerty; j++) {         char c = s[j];         if (!st.empty() && c ==  )  && st.top() ==  ( )           st.pop();         else           st.push(c);       }       int r1 = 0, r2 = 0;       while (!st.empty()) {         if (st.top() ==  ( )           r1++;         else           r2++;         st.pop();       }       if (r1 && r2) continue;       if (r1 + r2 == 0)         w[2][0]++;       else if (r1)         w[0][r1]++;       else if (r2)         w[1][r2]++;     }     long long ans = w[2][0] * w[2][0];     if (w[2][0] == 1) ans = 1;     for (int i = 0, qwerty = 300200; i < qwerty; i++) ans += w[0][i] * w[1][i];     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, t;     cin >> t;     while (t--) {       cin >> a >> b;       int num = abs(a - b);       if (a > b && num % 2 != 0)         cout << 2 << endl;       else if (a < b && num % 2 != 0)         cout << 1 << endl;       else if (a > b && num % 2 == 0)         cout << 1 << endl;       else if (a < b && num % 2 == 0)         cout << 2 << endl;       else if (a == b)         cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct DSU {     struct Node {       int pr;       long long max_sum;       long long max_pref;       long long sum;       long long max_suff;     };     vector<Node> t;     multiset<long long> mx;     DSU(int n, vector<int>& c) {       t.resize(n);       for (int i = 0; i < n; ++i) {         t[i].pr = i;         t[i].sum = c[i];         t[i].max_sum = max(0, c[i]);         t[i].max_pref = max(0, c[i]);         t[i].max_suff = max(0, c[i]);         mx.insert(t[i].max_sum);       }     }     int f(int v) {       if (t[v].pr != v) {         t[v].pr = f(t[v].pr);       }       return t[v].pr;     }     void merge(int x, int y) {       x = f(x);       y = f(y);       if (x == y) {         return;       }       t[x].pr = y;       mx.erase(mx.lower_bound(t[x].max_sum));       mx.erase(mx.lower_bound(t[y].max_sum));       Node new_node;       new_node.sum = t[x].sum + t[y].sum;       new_node.pr = y;       new_node.max_sum = max(t[y].max_sum, t[x].max_sum);       new_node.max_sum = max(new_node.max_sum, t[x].max_suff + t[y].max_pref);       new_node.max_pref = max(t[x].max_pref, t[x].sum + t[y].max_pref);       new_node.max_suff = max(t[y].max_suff, t[y].sum + t[x].max_suff);       new_node.max_sum = max(new_node.max_sum, 0LL);       new_node.max_pref = max(new_node.max_pref, 0LL);       new_node.max_suff = max(new_node.max_suff, 0LL);       t[y] = new_node;       mx.insert(t[y].max_sum);     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long long m;     cin >> n >> m;     vector<int> d(n), c(n);     for (int i = 0; i < n; ++i) {       cin >> d[i] >> c[i];       c[i] = m - c[i];     }     set<pair<int, int> > q;     for (int i = 0; i + 1 < n; ++i) {       q.insert({d[i + 1] - d[i], i});     }     q.insert({-1, -1});     DSU t(n, c);     long long ans = 0;     while (q.size()) {       auto i = *q.begin();       q.erase(q.begin());       if (i.second != -1) {         t.merge(i.second, i.second + 1);         ans = max(ans, *--t.mx.end() - i.first * 1LL * i.first);       } else {         ans = max(ans, *--t.mx.end());       }     }     cout << ans <<   n ;   }


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