#include <bits/stdc++.h>   using namespace std;   class Task {    public:     char invert(char c) {       if (c ==  W ) return  B ;       return  W ;     }     void shift_left(string& s, int k) {       int n = s.length();       string t = s;       for (int i = 0; i < n; i++) t[i] = s[(i + k) % n];       s = t;     }     void shift_left(vector<bool>& v, int k) {       int n = v.size();       auto w = v;       for (int i = 0; i < n; i++) w[i] = v[(i + k) % n];       v = w;     }     void solve() {       int n, k;       cin >> n >> k;       string s;       cin >> s;       vector<bool> unstable(n);       for (int i = 0; i < n; i++) {         if (s[(i + 1) % n] != s[i] && s[(i - 1 + n) % n] != s[i]) {           unstable[i] = true;         }       }       bool all_stable = true;       for (int i = 0; i < n; i++) {         if (unstable[i]) {           all_stable = false;           break;         }       }       if (all_stable) {         cout << s <<   n ;         return;       }       int stable = -1;       for (int i = 0; i < n; i++) {         if (!unstable[i]) {           stable = i;           break;         }       }       if (stable == -1) {         k %= 2;         for (int i = 0; i < n; i++) {           if (k % 2 == 1) {             cout << invert(s[i]);           } else {             cout << s[i];           }         }         cout <<   n ;         return;       }       if (stable == 0) {         stable = n - 1;         while (stable > 0 && !unstable[stable]) stable--;         stable = (stable + 1) % n;         shift_left(s, stable);         shift_left(unstable, stable);       } else {         shift_left(s, stable);         shift_left(unstable, stable);       }       for (int i = 2; i < n;) {         if (unstable[i]) {           int j;           for (j = i; j < n && unstable[j]; j++)             ;           for (int t = i; t < min(i + k, i + (j - i + 1) / 2); t++)             s[t] = s[(i - 1 + n) % n];           for (int t = j - 1; t >= max(j - k, j - (j - i + 1) / 2); t--)             s[t] = s[j % n];           if (k % 2 == 1) {             for (int t = min(i + k, i + (j - i + 1) / 2);                  t < max(j - k, j - (j - i + 1) / 2); t++)               s[t] = invert(s[t]);           }           i = j;         } else {           i++;         }       }       shift_left(s, n - stable);       cout << s <<   n ;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     for (int t = 1; t <= T; t++) {       (new Task())->solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 101;   long long n;   pair<long long, long long> a[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;     long long p;     cin >> p;     for (long long i = n - 1; i >= 0; --i) {       if (a[i].first <= p) {         cout << n - i <<   n ;         exit(0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long n, k;     cin >> n >> k;     long long len = (1LL << n) - 1;     while (true) {       long long mid = len / 2 + 1;       if (k == mid) break;       if (k > mid) k -= mid;       n--;       len = (1LL << n) - 1;     }     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1000000007LL;   const int N = 3e2 + 10;   const long long Inf = 2242545357980376863LL;   const long long Log = 30;   long long t1, t2, t3;   long long Get(long long x, long long y) {     if (x < y) return t2;     if (x == y) return t1;     return t3;   }   long long a[N][N];   long long ps1[N][N], ps2[N][N], ps3[N][N], ps4[N][N];   set<pair<long long, long long> > st;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, t;     cin >> n >> m >> t;     cin >> t1 >> t2 >> t3;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 2; j <= m; j++)         ps1[i][j] = ps1[i][j - 1] + Get(a[i][j - 1], a[i][j]);     for (int i = 1; i <= n; i++)       for (int j = m - 1; j >= 1; j--)         ps2[i][j] = ps2[i][j + 1] + Get(a[i][j + 1], a[i][j]);     for (int i = n - 1; i >= 1; i--)       for (int j = 1; j <= m; j++)         ps3[i][j] = ps3[i + 1][j] + Get(a[i + 1][j], a[i][j]);     for (int i = 2; i <= n; i++)       for (int j = 1; j <= m; j++)         ps4[i][j] = ps4[i - 1][j] + Get(a[i - 1][j], a[i][j]);     long long mn = Inf;     long long x1 = 1, y1 = 1, x2 = 3, y2 = 3;     for (int i1 = 1; i1 <= n; i1++)       for (int i2 = i1 + 2; i2 <= n; i2++) {         st.clear();         for (int j = 2; j <= m; j++) {           long long V = ps1[i1][j] - ps4[i1][j] + ps4[i2][j] - ps2[i2][j];           long long R = t - V;           auto it = st.lower_bound({R, -1});           pair<long long, long long> Q;           if (st.size()) {             if (it != st.end()) {               Q = *it;               if (abs(t - (V + Q.first)) < mn) {                 mn = abs(t - (V + Q.first));                 x2 = i2;                 x1 = i1;                 y2 = j;                 y1 = it->second;               }             }             if (it != st.begin()) {               it--;               Q = *it;               if (abs(t - (V + Q.first)) < mn) {                 mn = abs(t - (V + Q.first));                 x2 = i2;                 x1 = i1;                 y2 = j;                 y1 = it->second;               }             }           }           st.insert(               {-ps1[i1][j - 1] + ps3[i1][j - 1] - ps3[i2][j - 1] + ps2[i2][j - 1],                j - 1});         }       }     cout << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using std::string;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int f = 0;     for (int i = 0; i < s.size() - 1; i++) {       if (s[i + 1] < s[i]) {         for (int j = i + 1; j < s.size(); j++) s[j - 1] = s[j];         f = 1;         break;       }     }     s.pop_back();     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, q, x;   map<int, int> M;   map<int, int>::iterator it;   int main() {     scanf( %d %d , &n, &k);     for (int i = (1); i <= (n); i++) {       int a;       scanf( %d , &a);       for (int j = (0); j <= (k); j++) {         if (!M.count(a * j))           M[a * j] = j;         else           M[a * j] = min(M[a * j], j);       }     }     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       int res = 99;       for (it = M.begin(); it != M.end(); it++) {         int v = (*it).first, c = (*it).second;         if (M.count(x - v)) {           int cc = M[x - v];           res = min(res, c + cc);         }       }       if (res > k) res = -1;       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans = 0;   vector<int> a[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int k, x;       cin >> k;       while (k--) {         cin >> x;         a[i].push_back(x);       }       sort(a[i].begin(), a[i].end());     }     a[0] = a[n];     a[n + 1] = a[1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j < a[i].size(); j++) {         if (upper_bound(a[i - 1].begin(), a[i - 1].end(), a[i][j]) -                 lower_bound(a[i - 1].begin(), a[i - 1].end(), a[i][j - 1]) !=             upper_bound(a[i + 1].begin(), a[i + 1].end(), a[i][j]) -                 lower_bound(a[i + 1].begin(), a[i + 1].end(), a[i][j - 1]))           ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   const long double PI = acos(-1);   const int MOD = 998244353, LIM = 2e5 + 5;   const long double EPS = 1e-9;   const int mod = 1000000007;   int main() {     double l, p, q;     std::cin >> l >> p >> q;     double ans = l * p;     ans /= p + q;     std::cout << std::fixed << std::setprecision(9) << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, m, t;     cin >> n >> k >> m >> t;     for (int i = 0; i < t; i++) {       int a, b;       cin >> a >> b;       if (a == 0 && b < k) {         k -= b;         n -= b;       } else if (a == 1 && b <= k) {         k++;         n++;       } else if (a == 0 && b >= k) {         n = b;       } else if (a == 1 && b > k) {         n++;       }       cout << n <<     << k << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 7;   const int INF = (int)1e9 + 7;   const long long LINF = (long long)1e12 + 7;   const int MOD = (int)1e9 + 7;   void file() {}   inline int readChar();   template <class T = int>   inline T readInt();   template <class Tl = long long>   inline Tl readLong();   template <class T>   inline void writeInt(T x, char end = 0);   template <class Tl>   inline void writeLong(Tl x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 4096;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin);     if (pos == len) return -1;     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) c = getChar();     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   template <class Tl>   inline Tl readLong() {     int s = 1, c = readChar();     Tl x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   template <class Tl>   inline void writeLong(Tl x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   vector<vector<int> > G;   vector<pair<int, int> > p;   vector<int> coun;   void insert(int x) {     int v = 0;     for (int i = 30; i >= 0; --i) {       ++coun[v];       if (G[v][(x >> i) & 1] == -1) {         G.push_back(vector<int>(2, -1));         coun.push_back(0);         p.push_back({v, (x >> i) & 1});         G[v][(x >> i) & 1] = G.size() - 1;       }       v = G[v][(x >> i) & 1];     }     ++coun[v];   }   void erase(int x) {     int v = 0;     for (int i = 30; i >= 0; --i) {       --coun[v];       v = G[v][(x >> i) & 1];     }     --coun[v];     while (p[v].first != -1 && !coun[v]) {       G[p[v].first][p[v].second] = -1;       v = p[v].first;     }   }   int get(int x) {     int ans = 0, v = 0;     for (int i = 30; i >= 0; --i) {       if (G[v][(x >> i) & 1] != -1) {         if ((x >> i) & 1) {           ans += (1 << i);         }         v = G[v][(x >> i) & 1];       } else {         if (!((x >> i) & 1)) {           ans += (1 << i);         }         v = G[v][!((x >> i) & 1)];       }     }     return ans;   }   int main() {     file();     int q = readInt();     G.push_back(vector<int>(2, -1));     coun.push_back(0);     p.push_back({-1, 0});     insert(0);     while (q--) {       char c = readChar();       int x = readInt();       if (c ==  + ) {         insert(x);       }       if (c ==  - ) {         erase(x);       }       if (c ==  ? ) {         int cur = x ^ ((1ll << 31) - 1);         int ans = get(cur) ^ x;         writeInt(ans,   n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   int n, a, b;   double ans;   vector<vector<int>> g(N);   void dfs(int u, int par, int depth) {     ans += 1.0 / depth;     for (auto v : g[u])       if (v != par) dfs(v, u, depth + 1);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 1, 1);     cout << fixed << setprecision(9) << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005000;   int A[maxn], sum[maxn][10];   int dfs(int u) {     if (u < 10) return u;     if (A[u]) return A[u];     int now = 1, tmp = u;     while (u) {       if (u % 10 != 0) now *= u % 10;       u /= 10;     }     return A[tmp] = dfs(now);   }   int main() {     for (int i = 1; i <= 1000000; i++) A[i] = dfs(i);     for (int i = 1; i <= 1000000; i++) {       for (int j = 1; j <= 9; j++) {         if (A[i] == j)           sum[i][j] = sum[i - 1][j] + 1;         else           sum[i][j] = sum[i - 1][j];       }     }     int Q;     cin >> Q;     while (Q--) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       cout << sum[r][k] - sum[l - 1][k] << endl;     }   }


#include <bits/stdc++.h>   int tcase, m;   long long n;   int gao(long long x) {     int ret = 0;     for (; x; x /= 10) ret += x % 10;     return ret;   }   int main() {     scanf( %d , &tcase);     while (tcase--) {       scanf( %lld%d , &n, &m);       if (gao(n) <= m) {         printf( 0 n );         continue;       }       long long x = 10;       while (gao(n + (x - n % x)) > m) x *= 10;       printf( %lld n , x - n % x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, k, m;   int p10[maxn];   inline void init() {     p10[0] = 1;     for (register int i = 1; i <= 1000; i++) {       p10[i] = (p10[i - 1] * 10) % k;     }   }   long long f[1010][110][2];   long long dfs(long long pos, long long statu, bool fg) {     if (pos == n + 1) {       if (fg) return 1;       return 0;     }     if (~f[pos][statu][fg]) {       return f[pos][statu][fg];     }     long long ans = 0;     if (pos != n) ans += dfs(pos + 1, statu, fg);     for (register int i = 1; i <= 9; i++) {       ans += dfs(pos + 1, (statu + i * p10[pos - 1]) % k,                  fg || (!((statu + i * p10[pos - 1]) % k)));       ans %= m;     }     f[pos][statu][fg] = ans;     return ans;   }   int main() {     memset(f, -1, sizeof(f));     scanf( %d%d%d , &n, &k, &m);     init();     printf( %lld n , dfs(1, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double PI = 2 * acos(0.0);   const double eps = 1e-7;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int main() {     int n, m;     cin >> n >> m;     string s;     int mx = 0;     int c = 0;     for (int i = 0; i < m; i++) {       cin >> s;       int va = 0;       for (int l = 0; l < ((int)((s).size())); l++)         if (s[l] ==  0 ) {           c++;           va = 1;           break;         }       if (va == 0) {         mx = max(mx, c);         c = 0;       }     }     cout << max(mx, c) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1LL << 62;   const long long mx = 100005;   const double eps = 1e-10;   long long dx[10] = {1, 0, -1, 0};   long long dy[10] = {0, -1, 0, 1};   long long power(long long a, long long b) {     if (b == 0) return 1;     long long x = power(a, b / 2);     x = x * x;     if (b % 2) x = x * a;     return x;   }   long long Set(long long N, long long pos) { return N = N | (1LL << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }   string str, ss;   set<string> s;   int main() {     long long tst, a, b, c, k, n, m, res = 0, ans = 0, t = 0;     cin >> str;     n = (long long)(str).size();     for (char ch =  a ; ch <=  z ; ch++) {       ss.clear();       ss.push_back(ch);       ss += str;       s.insert(ss);     }     long long i, j;     for (i = 0; i < n; i++) {       ss.clear();       for (j = 0; j <= i; j++) {         ss.push_back(str[j]);       }       string first = ss;       for (char ch =  a ; ch <=  z ; ch++) {         ss = first;         ss.push_back(ch);         for (j = i + 1; j < n; j++) {           ss.push_back(str[j]);         }         s.insert(ss);       }     }     cout << (long long)(s).size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M, K, i, st, ed, ans[2], arr[100005];   int main() {     cin >> M >> K;     for (i = st = ed = 0; i < M; i++) cin >> arr[i];     sort(arr, arr + M, greater<int>());     while (1) {       while ((ed + 1) < M && (arr[st] - arr[ed + 1]) <= K)         K -= (arr[st] - arr[++ed]);       if ((ed - st + 1) >= ans[0]) {         ans[0] = (ed - st + 1);         ans[1] = arr[st];       }       if (ed == M - 1 || st == M - 1) break;       K += ((arr[st] - arr[st + 1]) * (ed - st));       st++;     }     cout << ans[0] <<     << ans[1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q;   const long long MXN = 200005;   long long arr[MXN];   long long seg[MXN * 4];   void build(long long ind, long long l, long long r) {     if (l == r) {       seg[ind] = arr[l];       return;     }     long long m = (l + r) / 2;     build(ind << 1, l, m);     build((ind << 1) | 1, m + 1, r);     seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];   }   void upd(long long ind, long long l, long long r, long long pos, long long to) {     if (l == r) {       seg[ind] = to;       return;     }     long long m = (l + r) / 2;     if (pos <= m)       upd(ind << 1, l, m, pos, to);     else       upd((ind << 1) | 1, m + 1, r, pos, to);     seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];   }   long long qry(long long ind, long long l, long long r, long long ql,                 long long qr) {     if (ql <= l && r <= qr) {       return seg[ind];     }     if (ql > r || qr < l) {       return 0;     }     long long m = (l + r) / 2;     return qry(ind << 1, l, m, ql, qr) + qry((ind << 1) | 1, m + 1, r, ql, qr);   }   long long fact[MXN];   set<long long> rm;   long long T(long long dv) {     auto x = rm.begin();     for (long long j = 0; j < dv; j++) x++;     return *x;   }   vector<long long> wh;   void sep(long long kth) {     for (long long i = 1; i <= n; i++) {       rm.insert(i);     }     for (long long pl = n - 1; pl >= 0; pl--) {       long long dv = kth / fact[pl];       kth %= fact[pl];       long long K = T(dv);       wh.push_back(K);       rm.erase(K);     }     for (long long i = 1; i <= n; i++) {       arr[i] = wh[i - 1];     }     wh.clear();   }   long long SP = 0;   void rew(long long kth) {     if (SP == kth) return;     if (n <= 15) {       sep(kth);     } else {       for (long long i = 1; i <= 15; i++) {         rm.insert(i);       }       for (long long pl = 15 - 1; pl >= 0; pl--) {         long long dv = kth / fact[pl];         kth %= fact[pl];         long long K = T(dv);         wh.push_back(K);         rm.erase(K);       }       for (long long i = 1; i <= 15; i++) {         arr[n - 15 + i] = n - 15 + wh[i - 1];       }       wh.clear();     }     SP = kth;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = 1;     cin >> n >> q;     for (long long i = 1; i <= n; i++) arr[i] = i;     for (long long i = 1; i <= 20; i++) {       fact[i] = fact[i - 1] * i;     }     long long k = 0;     build(1, 1, n);     for (long long i = 0; i < q; i++) {       long long t;       cin >> t;       if (t == 1) {         rew(k);         for (long long i = max(1ll, n - 20); i <= n; i++) {           upd(1, 1, n, i, arr[i]);         }         long long l, r;         cin >> l >> r;         cout << qry(1, 1, n, l, r) <<   n ;       } else {         long long w;         cin >> w;         k += w;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int main() {     int n;     scanf( %d , &n);     vector<long long> a(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     vector<long long> t(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &t[i]);     }     multiset<long long> S;     long long sum = 0;     for (int i = 0; i < n; i++) {       S.insert(a[i] + sum);       long long ans = 0;       sum += t[i];       while (!S.empty()) {         long long top = *S.begin();         if (top < sum) {           ans += top - (sum - t[i]);           S.erase(S.begin());         } else {           break;         }       }       ans += (long long)(int)((S).size()) * t[i];       printf( %lld  , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long ori[100005];   int main() {     scanf( %d , &n);     int i = 1;     for (i; i <= n; i++) {       scanf( %I64d , &ori[i]);     }     sort(ori + 1, ori + n + 1);     i = 1;     int ss = n - 2;     bool flag = false;     for (i; i <= ss; i++) {       int j = i + 1;       int k = j + 1;       if (ori[i] + ori[j] > ori[k]) {         flag = true;         break;       }     }     if (flag) {       printf( YES );     } else {       printf( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     vector<int> b(n);     vector<int> c(n);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a[i] = {x, i};     }     while (k--) {       int x, y;       cin >> x >> y;       x--;       y--;       if (a[x].first > a[y].first) b[x]++;       if (a[x].first < a[y].first) b[y]++;     }     sort(a.begin(), a.end());     int l = 0;     for (int i = 0; i < n; i++) {       k = i;       k -= l;       k -= b[a[i].second];       c[a[i].second] = k;       if (i < n - 1) {         if (a[i].first < a[i + 1].first)           l = 0;         else           l++;       }     }     for (auto it : c) cout << it <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300500;   struct node {     long long x;     int id;     node() {}     bool operator<(const node ot) const {       if (x != ot.x) return x < ot.x;       return id < ot.id;     }   } a[maxn];   long long x[maxn];   long long su[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) {       scanf( %lld , &x[i]);       a[i].x = x[i] + 1e9;       a[i].id = i + 1;     }     int k;     scanf( %d , &k);     sort(a, a + n);     long long dif = 1e18, ans = 0;     long long cur = 0;     for (int i = 0; i < (int)(n); ++i) su[i + 1] = su[i] + a[i].x;     for (int i = 0; i < (int)(k); ++i) cur += a[i].x * i - (su[i]);     dif = cur;     for (int i = k; i < n; i++) {       int j = i - k;       cur -= (su[i] - su[j + 1]) - a[j].x * (k - 1);       cur += a[i].x * (k - 1) - (su[i] - su[j + 1]);       if (cur < dif) {         ans = i - k + 1;         dif = cur;       }     }     for (int i = 0; i < (int)(k); ++i) printf( %d  , a[ans + i].id);   }


#include <bits/stdc++.h>   using namespace std;   long double f[1011][1011];   int m, n;   void init() {     memset(f, 0, sizeof f);     f[1][1] = 1;     for (int i = (1), _b = (n - 1); i <= _b; i++) {       for (int x = (0), _b = (min(i, m)); x <= _b; x++)         if (f[i][x] > 1e-50) {           f[i + 1][x] += f[i][x] * ((m * n - m) - (i - x)) / (double)(m * n - i);           f[i + 1][x + 1] += f[i][x] * (m - x) / (double)(m * n - i);         }     }   }   int main() {     ios ::sync_with_stdio(false);     cout << (fixed) << setprecision(8);     while (cin >> n >> m) {       init();       double res = 0.0;       for (int k = (1), _b = (min(m, n)); k <= _b; k++) {         res += f[n][k] * k / (double)n;       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   long long int vis[N];   vector<vector<int> > v;   int dfs(int t) {     vis[t] = 1;     for (int i = 0; i < v[t].size(); i++) {       if (vis[v[t][t]] == 0) {         dfs(v[t][i]);       }     }     return 0;   }   int main() {     long long int n, k;     cin >> n >> k;     long long int y = 1;     long long int i = 0;     long long int ans = 0, p = 0, d = 1;     while (1) {       if (d > n) {         break;       }       p++;       d = pow(2, p);     }     k = min(k, p + 1);     long double o = 1 - (long double)(1 / (long double)(pow(2, k)));     if (k == 1)       cout << max(n, d / 2) << endl;     else {       ans = 2 * (d / 2) - 1;       cout << ans << endl;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int maxn=1000025;   const int mod=998244353;   int n,m,i,j,t,k,s,f[maxn],ans,dp[maxn],iv[10];      inline int calc(int x)   {    int ret=x*1ll*(x-1)%mod*(x-2)%mod*iv[6]%mod;//3    ret=(ret+x*1ll*(x-1))%mod;//2    ret=(ret+x)%mod;//1    //printf( calc %d %d n ,x,ret);    return ret;   }      int main()   {    iv[1]=1;iv[2]=(mod+1)/2;iv[3]=(mod+1)/3;iv[6]=iv[2]*1ll*iv[3]%mod;    scanf( %d ,&n);    f[0]=1;s=1;    for (i=1;i<n;++i)    {     f[i]=(1ll*s*(s-1)/2ll%mod+s*1ll+1)%mod;     dp[i]=(f[i]-f[i-1]+mod)%mod;     //f[i]=(f[i]-s+mod)%mod;     s=(s+f[i])%mod;    }    m=n-1;    ans=(1ll*s*(s-1)/2ll%mod+s*1ll+1ll)%mod;    ans=(ans+calc(s))%mod;    ans=(ans-calc((s+mod-f[m])%mod)+mod)%mod;    ans=2ll*(ans+mod)%mod;    ans=(ans-1+mod)%mod;    for (i=n-1;i>0;--i)    {     ans=(ans+dp[i]*1ll*(f[n-i-1]-1))%mod;    }    //ans=(ans-1ll*(f[(n-1)>>1]-1)+mod)%mod;    ans=(ans+mod)%mod;    printf( %d n ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n][3];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> a[i][j];       }     }     int c = 1;     for (int i = 0; i < 3; i++) {       int sum = 0;       for (int j = 0; j < n; j++) {         sum += a[j][i];       }       if (sum != 0) {         c = 0;         cout <<  NO ;         break;       }     }     if (c) {       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edge[80005];   int cnt[80005];   unsigned long long ret;   int n;   void dfs(int v, int u) {     cnt[v] = 1;     unsigned long long val = 1ull * n * (n - 1) / 2ull;     for (int i = 0; i < edge[v].size(); i++) {       int to = edge[v][i];       if (to == u) continue;       dfs(to, v);       val -= 1ull * cnt[to] * (cnt[to] - 1) / 2ull;       cnt[v] += cnt[to];     }     val -= 1ull * (n - cnt[v]) * (n - cnt[v] - 1) / 2ull;     ret -= (val * val -             (1ull * (n - cnt[v]) * cnt[v]) * (1ull * (n - cnt[v]) * cnt[v]));   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       edge[u].push_back(v);       edge[v].push_back(u);     }     ret = 1ull * n * (n - 1) / 2ull;     ret *= ret;     dfs(rand() % n + 1, -1);     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   set<string> s;   int main() {     cin >> n;     getchar();     while (n--) {       string ss;       getline(cin, ss);       s.insert(ss);     }     cout << s.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 * 100 + 10;   int endss[maxn];   int main() {     int n, M, T;     cin >> n >> M >> T;     vector<pair<pair<int, int>, int> > ps(2 * n);     for (int i = 0; i < n; i++) {       int h, m, s;       scanf( %d:%d:%d n , &h, &m, &s);       int time = 60 * (60 * h + m) + s;       ps[2 * i] = make_pair(make_pair(time, 0), i);       ps[2 * i + 1] = make_pair(make_pair(time + T - 1, 1), i);     }     sort(ps.begin(), ps.end());     int cur = -1;     int online = 0;     vector<int> ans(n);     bool ok = false;     for (int i = 0; i < (int)(ps).size(); i++) {       if (ps[i].first.second == 0) {         online++;         if (online > M) {           online--;         } else {           if (online == M) ok = true;           cur++;         }         ans[ps[i].second] = cur;         endss[cur]++;       } else {         if (endss[ans[ps[i].second]]) endss[ans[ps[i].second]]--;         if (!endss[ans[ps[i].second]]) online--;       }     }     if (!ok)       puts( No solution );     else {       printf( %d n , cur + 1);       for (int i = 0; i < n; i++) printf( %d n , ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n, a[200200], b[200200];   int mx[200200];   set<pair<int, int> > second;   vector<int> g[200200];   void restore(vector<int> &v) {     for (int i = 0; i < v.size(); i++) {       int x = v[i];       if (mx[x] != -1) second.insert(make_pair(-mx[x], x));     }   }   void solve() {     int sz;     int x;     vector<int> v;     scanf( %d , &sz);     for (int i = 0; i < sz; i++) {       scanf( %d , &x);       x--;       v.push_back(x);       if (mx[x] != -1) second.erase(make_pair(-mx[x], x));     }     if (second.size() == 0) {       printf( 0 0 n );       restore(v);       return;     }     if (second.size() == 1) {       int x = (*second.begin()).second;       printf( %d %d n , x + 1, b[g[x][0]]);       restore(v);       return;     }     __typeof(second.begin()) it = second.begin();     int y = (*it).second;     it++;     int X = (*it).second;     int t = mx[X];     vector<int> &a = g[y];     int l = 0, r = (int)a.size() - 1;     int best = r;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] > t) {         best = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d %d n , y + 1, b[a[best]]);     restore(v);   }   int main() {     memset(mx, -1, sizeof mx);     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , a + i, b + i);       a[i]--;       mx[a[i]] = i;       g[a[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       if (mx[i] == -1) continue;       second.insert(make_pair(-mx[i], i));     }     int q;     scanf( %d , &q);     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e9 + 7;   int a[17];   int c[107][107];   int dp[17][107];   int n;   int main() {     cin >> n;     for (int i = 0; i < 10; i++) cin >> a[i];     for (int i = 0; i <= 100; i++) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; j++) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;       }     }     int ans = 0;     dp[10][0] = 1;     for (int dig = 9; dig >= 0; dig--) {       for (int cnt = a[dig]; cnt <= n; cnt++) {         for (int rem = 0; rem + cnt <= n; rem++) {           dp[dig][cnt + rem] =               (dp[dig][cnt + rem] +                (dp[dig + 1][rem] * 1ll * c[cnt + rem - (dig ? 0 : 1)][cnt] % M)) %               M;         }       }     }     for (int len = 1; len <= n; len++) ans = (ans + dp[0][len]) % M;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[101101];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int l = 0, r = n - 1, ans = 0;     for (int i = 0; i < n; i++) {       if (a[l] < a[i]) {         ans++;         l++;       } else         r--;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void maximize(T &x, U y) {     if (x < y) x = y;   }   template <class T, class U>   void minimize(T &x, U y) {     if (x > y) x = y;   }   template <class T>   T Abs(T x) {     return (x < (T)0 ? -x : x);   }   namespace task {   const int N = 505;   bool f[N][N];   int a[N], b[N];   int n, k;   long long tot = 0;   void solve() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i] >> b[i];       tot += a[i];       tot += b[i];     }     f[0][0] = true;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < k; ++j) {         f[i][j] = f[i - 1][(j - a[i] % k + k) % k];         for (int l = 0; l <= min(a[i], k - 1); ++l) {           if ((a[i] - l) % k + b[i] >= k) {             f[i][j] |= f[i - 1][(j - l + k) % k];           }         }       }     }     long long ans = 0;     for (int i = 0; i < k; ++i) {       if (f[n][i]) {         maximize(ans, (tot - 1LL * i) / (1LL * k));       }     }     cout << ans;   }   }  // namespace task   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     task::solve();   }


#include <bits/stdc++.h>   using namespace std;   int ted[1010];   int main() {     memset(ted, 0, sizeof ted);     int n;     cin >> n;     while (n--) {       int x;       cin >> x;       ted[x]++;     }     int ans = 0;     int mx = 0;     for (int i = 1; i <= 1000; i++)       if (ted[i]) {         ans++;         mx = max(mx, ted[i]);       }     cout << mx <<     << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     long long N, M, K;     cin >> N >> K >> M;     vector<long long> A(N);     long long s = 0;     for (int i = 0; i < N; i++) {       cin >> A[i];       s += A[i];     }     sort(A.begin(), A.end());     long double res = (long double)(s + min(M, N * K)) / (long double)N;     for (int i = 0; i < min(N - 1, M); i++) {       s -= A[i];       long long tp = s + min((N - i - 1) * K, M - i - 1);       long double avg = (long double)tp / (long double)(N - i - 1);       res = max(res, avg);     }     cout << fixed << setprecision(20) << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long count = 0;     while (v.size() > 0) {       count++;       long long num = v[0];       for (long long i = 0; i < v.size(); i++) {         if (v[i] % num == 0) {           v.erase(v.begin() + i, v.begin() + i + 1);           i--;         }       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lld = long long;   using pi = pair<int, int>;   using pl = pair<lld, lld>;   using vi = vector<int>;   using vvi = vector<vector<int>>;   using vb = vector<bool>;   using vc = vector<char>;   using vl = vector<lld>;   using vp = vector<pi>;   using vs = vector<string>;   using si = stack<int>;   using qi = queue<int>;   using qp = queue<pi>;   using pqi = priority_queue<int>;   const lld mod = 998244353;   int n, mx;   vi t, c, adj;   vb chk;   void input() {     t.clear();     c.clear();     adj.clear();     chk.clear();     cin >> n;     t = vi(n);     c = vi(n);     adj = vi(n, -1);     chk = vb(n);     for (int i = 0; i < n; ++i) cin >> t[i];   }   void go(int cur) {     chk[cur] = true;     int nxt = adj[cur];     if (nxt == -1) return;     if (c[nxt]) {       c[cur] = c[nxt] == 1 ? 2 : 1;       return;     }     c[nxt] = c[cur] == 1 ? 2 : 1;     int t = c[nxt];     go(nxt);     if (t != c[nxt]) {       c[cur] = c[nxt] == 1 ? 2 : 1;     }   }   void solve() {     for (int i = 0; i < n; ++i)       if (t[i] != t[(i + 1) % n]) adj[i] = (i + 1) % n;     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (chk[i]) continue;       c[i] = 1;       go(i);       cnt++;     }     if (cnt == 1)       if (t[n - 1] != t[0] && c[n - 1] == c[0]) c[n - 1] = 3;     int mx = 1;     for (int i = 0; i < n; ++i) mx = max(mx, c[i]);     cout << mx <<   n ;     for (int i = 0; i < n; ++i) cout << c[i] <<    ;     cout <<   n ;   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(false);     int tc;     cin >> tc;     while (tc--) {       input();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int c = 100005;   void solve() {     string s;     cin >> s;     long long o = 0, e = 0, m = 0;     long long ans = INT_MAX;     long long om = 5, em = 5;     for (long long i = 0; i < s.size(); ++i) {       if (i & 1) {         if (s[i] ==  ?  or s[i] ==  1 ) o += 1;         om -= 1;       } else {         if (s[i] ==  1 ) e += 1;         em -= 1;       }       if ((o > e + em) or (e > o + om)) {         ans = min(ans, i + 1);         break;       }     }     om = 5;     em = 5;     o = e = 0;     for (long long i = 0; i < s.size(); ++i) {       if (i & 1) {         if (s[i] ==  1 ) o += 1;         om -= 1;       } else {         if (s[i] ==  1  or s[i] ==  ? ) e += 1;         em -= 1;       }       if ((o > e + em) or (e > o + om)) {         ans = min(ans, i + 1);         break;       }     }     if (ans == INT_MAX) ans = 10;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 5;   char mp[maxn][maxn];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf(  %c , &mp[i][j]);     int x1, y1, x2, y2;     for (int i = 0; i < n; i++) {       bool bb = false;       for (int j = 0; j < m; j++)         if (mp[i][j] ==  X ) {           x1 = i;           y1 = j;           bb = true;           break;         }       if (bb) break;     }     for (int i = n - 1; i >= 0; i--) {       bool bb = false;       for (int j = m - 1; j >= 0; j--) {         if (mp[i][j] ==  X ) {           x2 = i;           y2 = j;           bb = true;           break;         }       }       if (bb) break;     }     if (x1 > x2 || y1 > y2) {       puts( NO );       return 0;     }     for (int i = x1; i <= x2; i++)       for (int j = y1; j <= y2; j++) {         if (mp[i][j] ==  . ) {           puts( NO );           return 0;         }         mp[i][j] =  . ;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mp[i][j] ==  X ) {           puts( NO );           return 0;         }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d = 0, e = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i > 0) {         e += a[i - 1] - a[i];         if (e < 0) {           d -= e;           e = 0;         }       } else {         d += a[0];       }     }     cout << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test_time, x = 0;     cin >> test_time;     for (int i = 0; i < test_time; ++i) {       string temp;       cin >> temp;       for (int j = 0; j < temp.length(); ++j) {         if (temp[j] ==  - ) {           x--;           break;         } else if (temp[j] ==  + ) {           x++;           break;         }       }     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct SegTree {     int L, R, P, DELTA;     struct node {       int d;       bool zero;     } v[212345 * 4];     inline void set_zero(int x) {       v[x].zero = 1;       v[x].d = 0;     }     inline void fix(int x, int d) {       v[x].zero = 0;       v[x].d += d;     }     inline void rep(int x) {       if (v[x].zero) {         set_zero(x * 2);         set_zero(x * 2 + 1);         v[x].zero = 0;       } else {         fix(x * 2, v[x].d);         fix(x * 2 + 1, v[x].d);         v[x].d = 0;       }     }     void update(int x, int l, int r) {       if (l > R || r < L) return;       if (L <= l && r <= R) {         if (l < r)           rep(x);         else           v[x].zero = 0;         v[x].d += DELTA;         return;       }       int m = (l + r) / 2;       rep(x);       update(x * 2, l, m);       update(x * 2 + 1, m + 1, r);     }     void gao_zero(int x, int l, int r) {       if (l > R || r < L) return;       if (L <= l && r <= R) {         set_zero(x);         return;       }       int m = (l + r) / 2;       rep(x);       gao_zero(x * 2, l, m);       gao_zero(x * 2 + 1, m + 1, r);     }     int add(int x, int y) {       if (~y) return x + y;       return -1;     }     int query(int x, int l, int r) {       if (v[x].zero) return -1;       if (l == r) return v[x].d;       int m = (l + r) / 2;       if (P <= m)         return add(v[x].d, query(x * 2, l, m));       else         return add(v[x].d, query(x * 2 + 1, m + 1, r));     }     void up(int l, int r, int d) {       L = l, R = r, DELTA = d;       update(1, 1, n);     }     void zero(int l, int r) {       L = l, R = r;       gao_zero(1, 1, n);     }     int qr(int p) {       P = p;       return query(1, 1, n);     }   } tree;   int x[212345], len[212345];   vector<pair<int, int> > qu[212345];   int ans[212345], nxt[212345];   int L[212345], D[212345], id[212345], top = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , x + i, len + i);     int q;     scanf( %d , &q);     for (int i = 0; i < int(q); i++) {       int u, v;       scanf( %d%d , &u, &v);       qu[u].push_back(make_pair(v, i));     }     nxt[n] = -1;     for (int i = n - 1; i >= 1; --i) {       int j = i + 1;       while (~j && x[j] + len[j] <= x[i] + len[i]) j = nxt[j];       nxt[i] = j;     }     for (int i = n; i >= 1; --i) {       if (nxt[i] == -1) {       } else {         while (top > 0 && id[top] < nxt[i]) {           tree.up(L[top], n, -D[top]);           --top;         }         if (x[i] + len[i] >= x[nxt[i]]) {         } else {           tree.up(nxt[i], n, x[nxt[i]] - x[i] - len[i]);           ++top;           L[top] = nxt[i];           D[top] = x[nxt[i]] - x[i] - len[i];           id[top] = i;         }       }       for (auto x : qu[i]) ans[x.second] = tree.qr(x.first);     }     for (int i = 0; i < int(q); i++) printf( %d n , ~ans[i] ? ans[i] : 0);   }


#include <bits/stdc++.h>   using namespace std;   struct car {     int c, v;   };   bool operator<(car a, car b) { return a.v < b.v; }   int main() {     ios::sync_with_stdio(false);     int n, k, s, t;     cin >> n >> k >> s >> t;     vector<car> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i].c >> arr[i].v;     vector<int> g(k + 2);     g[0] = 0;     for (int i(1); i <= k; i++) cin >> g[i];     k += 2;     g[k - 1] = s;     sort(arr.begin(), arr.end());     sort(g.begin(), g.end());     int l = -1, r = n;     int cnt = 0;     while (r - l > 1) {       cnt++;       int m = (r + l) / 2;       int time = 0;       for (int i(1); i < k; i++) {         int d = g[i] - g[i - 1];         int a = min(arr[m].v - d, d);         int norm = d - a;         if (arr[m].v < d) {           time = 2000000007;           break;         }         time += a + 2 * norm;       }       if (time > t)         l = m;       else         r = m;     }     if (r == n)       cout << -1 << endl;     else {       int ans = 1000000007;       for (int i = r; i < n; ++i) ans = min(ans, arr[i].c);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char t[200003], p[200003];   int a, pos[200003], nt, np;   bool check(int mid) {     int it = 0;     for (int ip = 0; ip < np; ip++) {       while (it < nt && (t[it] != p[ip] || pos[it + 1] <= mid)) it++;       if (it == nt) return false;       it++;     }     return true;   }   int main() {     scanf( %s , t);     scanf( %s , p);     nt = strlen(t);     np = strlen(p);     for (int i = 1; i <= nt; i++) {       scanf( %d , &a);       pos[a] = i;     }     int lo = 1, mid, hi = nt;     while (hi >= lo) {       mid = (lo + hi) / 2;       if (check(mid))         lo = mid + 1;       else         hi = mid - 1;     }     printf( %d n , hi);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 10;   char ch[N];   int a[N][N];   int h[N], l[N];   int n, m;   int main() {     cin >> n >> m;     int tot = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , ch + 1);       for (int j = 1; j <= m; j++) {         a[i][j] = ch[j] ==  *  ? 1 : 0;         h[i] += a[i][j];         l[j] += a[i][j];         tot += a[i][j];       }     }     int x = -1, y = -1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (h[i] + l[j] - a[i][j] == tot) {           x = i;           y = j;           break;         }     if (x == -1) {       puts( NO );     } else {       puts( YES );       cout << x <<     << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool f = true;     string res =  { ;     for (long long i = (0); i <= (static_cast<long long>(v.size()) - 1); i++) {       if (!f) res +=  ,  ;       res += to_string(v[i]);       f = false;     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (auto& a : v) {       res += (char)( 0  + a);     }     return res;   }   template <typename A>   string to_string(A v) {     bool f = true;     string res =  { ;     for (auto& x : v) {       if (!f) res +=  ,  ;       res += to_string(x);       f = false;     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> t) {     return  (  + to_string(get<0>(t)) +  ,   + to_string(get<1>(t)) +  ,   +            to_string(get<2>(t)) +  ) ;   }   void DBG() { cerr << endl; }   template <typename H, typename... T>   void DBG(H h, T... t) {     cerr <<     << to_string(h);     DBG(t...);   }   template <typename T>   void re(T& x) {     cin >> x;   };   template <typename H, typename... T>   void re(H& h, T&... t) {     re(h);     re(t...);   }   template <typename T>   void pr(T x) {     cout << x;   };   template <typename H, typename... T>   void pr(H h, T... t) {     pr(h);     pr(t...);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long tt;     re(tt);     while (tt--) {       string s;       re(s);       long long n = (long long)s.size();       long long a, b, c;       a = b = c = -1;       long long inf = (long long)9e18;       long long ans = inf;       for (long long i = (0); i <= (n - 1); i++) {         if (s[i] ==  1 ) {           a = i;           if (b == -1 || c == -1) continue;           ans = min(ans, i - min(b, c) + 1);         }         if (s[i] ==  2 ) {           b = i;           if (a == -1 || c == -1) continue;           ans = min(ans, i - min(a, c) + 1);         }         if (s[i] ==  3 ) {           c = i;           if (b == -1 || a == -1) continue;           ans = min(ans, i - min(b, a) + 1);         }       }       pr((ans == inf ? 0 : ans),   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200015], n, k, b[100015];   int cmp(int x, int y) { return x < y; }   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       memset(a, 0, sizeof(a));       int ans = 0, flag = 1, t = 0;       int m = k;       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         if (a[i] < 0) t++;         if (flag == 1 && a[i] < 0) {           flag = 0;           ans++;         } else if (flag == 0 && a[i] >= 0) {           flag = 1;           ans++;         }       }       if (t == 0) {         printf( 0 n );       } else if (t > k) {         printf( -1 n );       } else if (t == k) {         printf( %d n , ans);       } else {         k = k - t;         int sum = 0, c = -1;         for (int i = n - 1; i >= 0; i--) {           if (a[i] < 0) {             if (c == -1) {               t = sum;               c++;             } else if (sum) {               b[c] = sum;               c++;             }             sum = 0;           } else             sum++;         }         sort(b, b + c, cmp);         int ans1 = ans, ans2 = ans, kk = k;         if (kk > 0) {           for (int i = 0; i < c; i++) {             if (kk - b[i] >= 0) {               kk -= b[i];               ans1 -= 2;             } else               break;           }         }         kk = k - t;         if (kk >= 0 && t) {           ans2 = ans - 1;           for (int i = 0; i < c; i++) {             if (kk - b[i] >= 0) {               kk -= b[i];               ans2 -= 2;             } else               break;           }         }         printf( %d n , min(ans1, ans2));       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int mark[(10000000 >> 5) + 1];   void sieve() {     register int i, j, k;     (mark[1 >> 5] |= 1 << (1 & 31));     int n = 10000000;     for (i = 2; i <= n; i++) {       if (!(mark[i >> 5] >> (i & 31) & 1)) {         for (k = n / i, j = i * k; k >= i; k--, j -= i)           (mark[j >> 5] |= 1 << (j & 31));       }     }   }   long long C(long long n, long long k) {     if (k == 0) return 1;     return (n * C(n - 1, k - 1)) / k;   }   long long modular_pow(long long budgetase, long long exponent, int modulus) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 1) result = (result * budgetase) % modulus;       exponent = exponent >> 1;       budgetase = (budgetase * budgetase) % modulus;     }     return result;   }   long long binaryToDec(string number) {     long long result = 0, pow = 1;     for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)       result = (result + (number[i] -  0 ) * pow) % 1000003;     return result;   }   long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }   int main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double r = d / 2;     double area = 3.1415926535897932384626433832795 * r * r;     if (e * area > v || fabs(e * area - v) < 0.0000000001) {       cout <<  NO  << endl;       return 0;     }     double vol = 3.1415926535897932384626433832795 * r * r * h;     double p = e * 3.1415926535897932384626433832795 * r * r;     double dif = fabs(p - v);     cout <<  YES  << endl;     cout << setprecision(12) << fixed << (double)vol / dif << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n, 0);     vector<int> p(n, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     int x;     for (int i = 0; i < n; i++) {       cin >> x;       p[x - 1] = i;     }     int ii = 1;     while (ii < n && p[a[ii - 1]] < p[a[ii]]) {       ii++;     }     cout << n - ii << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s, t, n;   string str;   bool flag = true, flag1 = true;   int main() {     scanf( %d , &n);     cin >> str;     for (int i = 0; i < n; i++) {       if (str[i] ==  R  && flag) {         s = i;         flag = false;       }       if (str[i] ==  L  && flag1) {         t = i;         flag1 = false;       }     }     if (flag1) {       for (int i = 0; i < n; i++)         if (str[i] ==  R ) t = i;       printf( %d %d , s + 1, t + 2);       return 0;     }     if (flag) {       for (int i = 0; i < n; i++)         if (str[i] ==  L ) s = i;       printf( %d %d , s + 1, t);       return 0;     }     printf( %d %d , s + 1, t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = -10000000;   int main() {     long long da, db;     cin >> da >> db;     if (da == db) {       cout << da * 10 <<     << db * 10 + 1;     } else if (da == 9 && db == 1) {       cout << da * 10 + 9 <<     << db * 100;     } else if (da == 0 && db == 1) {       cout << da <<     << db;     } else if (da + 1 == db) {       cout << da * 10 + 9 <<     << db * 10;     } else {       cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(long long first) {     return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   int Prev[int(1e5) + 3];   class EEgorAndAnRPGGame {    public:     void solve(istream& cin, ostream& cout) {       int T;       cin >> T;       for (int t = 0; t < T; ++t) {         int N;         cin >> N;         vector<int> A(N);         cin >> A;         vector<vector<int>> Ans;         while (!A.empty()) {           int M = A.size();           vector<vector<int>> B{{0}};           for (int i = 0; i < M; ++i) {             int s = bsh(0, int(B.size() - 1),                         [&](int first) { return B[first].back() < A[i]; });             if (s == B.size() - 1) B.emplace_back();             B[s + 1].push_back(A[i]);             Prev[A[i]] = B[s].back();           }           vector<int> Cur, Left;           int idx = B.back().back();           while (idx != 0) {             Cur.push_back(idx);             idx = Prev[idx];           }           reverse(Cur.begin(), Cur.end());           int j = 0;           for (int i = 0; i < M; ++i) {             if (j != Cur.size() && Cur[j] == A[i])               ++j;             else               Left.push_back(A[i]);           }           int K = Cur.size();           if (K * (K + 1) / 2 >= A.size()) {             swap(A, Left);             Ans.push_back(Cur);           } else {             for (auto& b : B) {               if (b.front() == 0) continue;               Ans.emplace_back();               for (auto& bb : b) {                 Ans.back().push_back(bb);               }             }             break;           }         }         cout << Ans.size() << endl;         for (auto& ans : Ans) {           cout << ans.size() <<     << ans;         }       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     EEgorAndAnRPGGame solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int c1, c2, c3, c4;     cin >> c1 >> c2 >> c3 >> c4;     int n, m;     cin >> n >> m;     int a[n], b[m];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int sb = 0, st = 0;     for (int i = 0; i < n; i++) sb += min(a[i] * c1, c2);     sb = min(sb, c3);     for (int i = 0; i < m; i++) st += min(b[i] * c1, c2);     st = min(st, c3);     cout << min(st + sb, c4);   }


#include <bits/stdc++.h>   using namespace std;   int fact(int a) {     int res = 1;     while (a > 0) {       res *= a--;     }     return res;   }   int main() {     int a, b;     cin >> a >> b;     cout << fact(min(a, b));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace mine {   long long qread() {     long long ans = 0, f = 1;     char c = getchar();     while (c <  0  or c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while ( 0  <= c and c <=  9 ) ans = ans * 10 + c -  0 , c = getchar();     return ans * f;   }   void write(long long num) {     if (num < 0) putchar( - ), num = -num;     if (num >= 10) write(num / 10);     putchar( 0  + num % 10);   }   void write1(long long num) {     write(num);     putchar(   );   }   void write2(long long num) {     write(num);     putchar(  n );   }   template <typename T>   void chmax(T &x, const T y) {     x = (x > y ? x : y);   }   template <typename T>   void chmin(T &x, const T y) {     x = (x < y ? x : y);   }   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   const int INF = 0x3f3f3f3f;   const int MOD = 998244353;   inline int mm(const int x) { return x >= MOD ? x - MOD : x; }   template <typename T>   inline void add(T &x, const T y) {     x = mm(x + y);   }   inline long long qpower(long long x, long long e, int mod = MOD) {     long long ans = 1;     if (e < 0) {       puts( error );       exit(666);     }     while (e) {       if (e & 1) ans = ans * x % mod;       x = x * x % mod;       e >>= 1;     }     return ans;   }   long long invm(long long x) { return qpower(x, MOD - 2); }   const int N = 2e5 + 10;   int n;   namespace SGT {   int mxc[N * 4];   void change_cnt(int x, int l, int r, int pos, int num) {     if (l == r) {       mxc[x] = num;       return;     }     if (pos <= (l + r) / 2)       change_cnt(x << 1, l, (l + r) / 2, pos, num);     else       change_cnt(x << 1 | 1, (l + r) / 2 + 1, r, pos, num);     mxc[x] = max(mxc[x << 1], mxc[x << 1 | 1]);   }   int ask_cnt(int x, int l, int r, int fl, int fr) {     if (fl > fr) return 0;     if (l == fl and r == fr) return mxc[x];     if (fr <= (l + r) / 2) return ask_cnt(x << 1, l, (l + r) / 2, fl, fr);     if (fl > (l + r) / 2) return ask_cnt(x << 1 | 1, (l + r) / 2 + 1, r, fl, fr);     return max(ask_cnt(x << 1, l, (l + r) / 2, fl, (l + r) / 2),                ask_cnt(x << 1 | 1, (l + r) / 2 + 1, r, (l + r) / 2 + 1, fr));   }   int mif[N * 4], tag[N * 4], mifl[N * 4], mifr[N * 4], sum[N * 4];   void init(int x, int l, int r) {     mifl[x] = l;     mifr[x] = r;     if (l < r) init(x << 1, l, (l + r) / 2), init(x << 1 | 1, (l + r) / 2 + 1, r);   }   void pushdown(int x) {     if (tag[x] != 0)       mif[x << 1] += tag[x], mif[x << 1 | 1] += tag[x], tag[x << 1] += tag[x],           tag[x << 1 | 1] += tag[x], tag[x] = 0;   }   void pushup(int x, int l, int r) {     if (l == r) {       sum[x] = ask_cnt(x, l, r, l, l);       return;     }     pushdown(x);     if (mif[x << 1] == mif[x << 1 | 1]) {       mif[x] = mif[x << 1];       mifl[x] = mifl[x << 1];       mifr[x] = mifr[x << 1 | 1];       sum[x] = sum[x << 1] + sum[x << 1 | 1] -                ask_cnt(x, l, r, mifr[x << 1] + 1, (l + r) / 2) -                ask_cnt(x, l, r, (l + r) / 2 + 1, mifl[x << 1 | 1]) +                ask_cnt(x, l, r, mifr[x << 1] + 1, mifl[x << 1 | 1]);     } else if (mif[x << 1] < mif[x << 1 | 1]) {       mif[x] = mif[x << 1];       mifl[x] = mifl[x << 1];       mifr[x] = mifr[x << 1];       sum[x] = sum[x << 1] - ask_cnt(x, l, r, mifr[x << 1] + 1, (l + r) / 2) +                ask_cnt(x, l, r, mifr[x << 1] + 1, r);     } else {       mif[x] = mif[x << 1 | 1];       mifl[x] = mifl[x << 1 | 1];       mifr[x] = mifr[x << 1 | 1];       sum[x] = sum[x << 1 | 1] -                ask_cnt(x, l, r, (l + r) / 2 + 1, mifl[x << 1 | 1]) +                ask_cnt(x, l, r, l, mifl[x << 1 | 1]);     }   }   void add_f(int x, int l, int r, int fl, int fr, int val) {     if (l == fl and r == fr) {       mif[x] += val;       tag[x] += val;       pushup(x, l, r);       return;     }     pushdown(x);     if (fr <= (l + r) / 2)       add_f(x << 1, l, (l + r) / 2, fl, fr, val);     else if (fl > (l + r) / 2)       add_f(x << 1 | 1, (l + r) / 2 + 1, r, fl, fr, val);     else       add_f(x << 1, l, (l + r) / 2, fl, (l + r) / 2, val),           add_f(x << 1 | 1, (l + r) / 2 + 1, r, (l + r) / 2 + 1, fr, val);     pushup(x, l, r);   }   void add_f(int l, int r, int val) {     if (l <= r) add_f(1, 1, n, l, r, val);   }   void change_cnt(int pos, int num) {     change_cnt(1, 1, n, pos, num);     add_f(pos, pos, 0);   }   };  // namespace SGT   int a[N];   set<int> pos[N];   void main() {     n = qread();     int q = qread();     SGT::init(1, 1, n);     for (int i = (1), I = (n); i <= I; i++) a[i] = qread(), pos[a[i]].insert(i);     for (int num = (1), I = (N - 1); num <= I; num++)       if (((int)(pos[num]).size()))         SGT::change_cnt(*pos[num].begin(), ((int)(pos[num]).size())),             SGT::add_f(*pos[num].begin(), *(--pos[num].end()) - 1, 1);     write2(n - SGT::sum[1]);     while (q--) {       int x = qread(), val = qread();       set<int>::iterator now = pos[a[x]].find(x);       SGT::change_cnt(*pos[a[x]].begin(), 0);       if (((int)(pos[a[x]]).size()) > 1) {         if (now == pos[a[x]].begin())           SGT::add_f(x, *(++now) - 1, -1);         else if (now == --pos[a[x]].end())           SGT::add_f(*(--now), x - 1, -1);       }       pos[a[x]].erase(x);       if (((int)(pos[a[x]]).size()))         SGT::change_cnt(*pos[a[x]].begin(), ((int)(pos[a[x]]).size()));       a[x] = val;       pos[a[x]].insert(x);       SGT::change_cnt(*pos[a[x]].begin(), ((int)(pos[a[x]]).size()));       now = pos[a[x]].find(x);       if (((int)(pos[a[x]]).size()) > 1) {         if (now == pos[a[x]].begin()) {           now++;           SGT::add_f(x, *now - 1, 1);           SGT::change_cnt(*now, 0);         } else if (now == --pos[a[x]].end())           SGT::add_f(*(--now), x - 1, 1);       }       write2(n - SGT::sum[1]);     }   }   };  // namespace mine   signed main() {     srand(time(0));     mine::main();   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 105;   vector<int> adj[MAX];   string s[MAX];   int mark[MAX];   bool cycle;   string ans =   ;   void dfs(int v) {     mark[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (mark[u] == 1) cycle = true;       if (!mark[u]) dfs(u);     }     mark[v] = 2;   }   void print(int v) {     mark[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) print(u);     }     ans +=  a  + v;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n - 1; i++) {       int j = 0;       while (j < s[i].size() && j < s[i + 1].size() && s[i][j] == s[i + 1][j])         j++;       if (j == s[i + 1].size() && s[i].size() > s[i + 1].size()) {         cout <<  Impossible  << endl;         return 0;       }       if (j < s[i].size() && j < s[i + 1].size())         adj[s[i][j] -  a ].push_back(s[i + 1][j] -  a );     }     for (int i = 0; i < 26; i++)       if (!mark[i]) dfs(i);     if (cycle) {       cout <<  Impossible  << endl;       return 0;     }     memset(mark, 0, sizeof(mark));     for (int i = 0; i < 26; i++)       if (!mark[i]) print(i);     reverse(ans.begin(), ans.end());     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& out, const tuple<T>& a) {     out <<  [  << get<0>(a) <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const tuple<T, U>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<  ] ;     return out;   }   template <class T, class U, class V>   ostream& operator<<(ostream& out, const tuple<T, U, V>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<     << get<2>(a) <<  ] ;     return out;   }   template <class T, class U, class V, class W>   ostream& operator<<(ostream& out, const tuple<T, U, V, W>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<     << get<2>(a) <<             << get<3>(a) <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const pair<T, U>& a) {     out <<  [  << a.first <<     << a.second <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const set<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const multiset<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const map<T, U>& a) {     for (auto& it : a) out << it.first <<   ->   << it.second <<   |  ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const multimap<T, U>& a) {     for (auto& it : a) out << it.first <<   ->   << it.second <<   |  ;     return out;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void r(){};   template <typename T, typename... Args>   void r(T& a, Args&... args) {     cin >> a;     r(args...);   }   void p() { cout <<   n ; };   template <typename T, typename... Args>   void p(T& a, Args&... args) {     cout << a <<    ;     p(args...);   }   template <class T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   template <class T>   T lcm(T a, T b) {     return ((a * b) / gcd(b % a, a));   }   template <class T1, class T2>   T1 binpow(T1 number, T2 power) {     T1 result = number;     while (power) {       if (power & 1) result = result * number;       number = number * number;       power /= 2;     }     return result;   }   long long n;   class Segtree {    public:     long long *tree, *lazy, *array, *color, *is_single;     Segtree(long long* arr, long long sz) {       array = new long long[sz];       lazy = new long long[4 * sz];       tree = new long long[4 * sz];       color = new long long[4 * sz];       is_single = new long long[4 * sz];       n = sz;       for (auto i = (0) - ((0) > (n)); i != (n) - ((0) > (n));            i += 1 - 2 * ((0) > (n)))         array[i] = arr[i];       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         tree[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         lazy[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         color[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         is_single[i] = 0;       build();     }     void build(long long id = 1, long long l = 0, long long r = n) {       if (r - l < 2) {         tree[id] = 0;         color[id] = array[l];         is_single[id] = 1;         return;       }       auto mid = (l + r) / 2;       build(2 * id, l, mid);       build(2 * id + 1, mid, r);       tree[id] = tree[2 * id] + tree[2 * id + 1];       if (color[2 * id] == color[2 * id + 1] and color[2 * id] != 0)         is_single[id] = 1, color[id] = color[2 * id];       else         is_single[id] = 0, color[id] = 0;     }     void upd(long long id, long long l, long long r, long long x,              long long coloring) {       lazy[id] += x;       tree[id] += (r - l) * x;       if (coloring != 0) color[id] = coloring;     }     void shift(long long id, long long l, long long r) {       long long mid = (l + r) / 2;       upd(id * 2, l, mid, lazy[id], color[id]);       upd(id * 2 + 1, mid, r, lazy[id], color[id]);       lazy[id] = 0;     }     long long sum(long long x, long long y, long long id = 1, long long l = 0,                   long long r = n) {       if (l >= y or r <= x) return 0;       if (l >= x and r <= y) return tree[id];       shift(id, l, r);       auto mid = (l + r) / 2;       return sum(x, y, 2 * id, l, mid) + sum(x, y, 2 * id + 1, mid, r);     }     void range_update(long long x, long long y, long long coloring,                       long long id = 1, long long l = 0, long long r = n) {       auto mid = (l + r) / 2;       if (l >= y or r <= x) return;       if (x <= l and r <= y) {         if (is_single[id]) {           upd(id, l, r, abs(color[id] - coloring), coloring);         } else {           shift(id, l, r);           range_update(x, y, coloring, 2 * id, l, mid);           range_update(x, y, coloring, 2 * id + 1, mid, r);           tree[id] = tree[2 * id] + tree[2 * id + 1];         }         is_single[id] = 1;         color[id] = coloring;         return;       }       shift(id, l, r);       range_update(x, y, coloring, 2 * id, l, mid);       range_update(x, y, coloring, 2 * id + 1, mid, r);       tree[id] = tree[2 * id] + tree[2 * id + 1];       if (color[2 * id] == color[2 * id + 1] and color[2 * id] != 0)         is_single[id] = 1, color[id] = color[2 * id];       else         is_single[id] = 0, color[id] = 0;     }   };   long long m, arr[112345], types, lef, ri, x;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     r(n, m);     for (auto i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       arr[i] = i + 1;     Segtree tree(arr, n);     for (auto i = (0) - ((0) > (m)); i != (m) - ((0) > (m));          i += 1 - 2 * ((0) > (m))) {       r(types);       if (types == 1) {         r(lef, ri, x);         tree.range_update(lef - 1, ri, x);       } else {         r(lef, ri);         auto sum = tree.sum(lef - 1, ri);         p(sum);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( main.in ,  r ))       freopen( main.in ,  r , stdin);     else if (fopen( something                      .inp ,                     r ))       freopen(            something             .inp ,            r , stdin),           freopen(                something                 .out ,                w , stdout);     int n, m;     cin >> n >> m;     int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       cnt1 += (a % 2 == 1);       cnt2 += (a % 2 == 0);     }     for (int i = 1; i <= m; i++) {       int a;       cin >> a;       cnt3 += (a % 2 == 1);       cnt4 += (a % 2 == 0);     }     cout << min(cnt1, cnt4) + min(cnt2, cnt3) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a;     int b;     scanf( %c%d , &a, &b);     if ((a ==  a  || a ==  h ) && (b == 1 || b == 8))       printf( 3 n );     else if (a ==  a  || a ==  h  || b == 1 || b == 8)       printf( 5 n );     else       printf( 8 n );   }


#include <bits/stdc++.h>   using namespace std;   const long long NMAX = 1000001;   vector<int> v[NMAX];   int tobehappy[NMAX];   void DFS(int node) {     if (v[node].size() == 0) tobehappy[node] = 1;     for (auto x : v[node]) {       DFS(x);       tobehappy[node] += tobehappy[x];     }   }   int main() {     int n, i;     cin >> n;     for (i = 2; i <= n; i++) {       int x, y;       cin >> y;       v[y].push_back(i);     }     DFS(1);     sort(tobehappy + 1, tobehappy + n + 1);     for (i = 1; i <= n; i++) cout << tobehappy[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   int n, u, v, cnt, head[maxn], to[maxn << 1], nex[maxn << 1], deep[maxn],       len[maxn], son[maxn], *f[maxn], tmp[maxn], *id = tmp, ans[maxn];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   inline void add(int u, int v) {     to[++cnt] = v;     nex[cnt] = head[u];     head[u] = cnt;   }   void dfs1(int x, int pre, int deep) {     int maxson = 0;     ::deep[x] = deep;     for (int i = head[x]; i; i = nex[i]) {       if (to[i] == pre) continue;       dfs1(to[i], x, deep + 1);       if (len[to[i]] > maxson) son[x] = to[i], maxson = len[to[i]];     }     len[x] = maxson + 1;   }   void dfs2(int x, int pre) {     f[x][0] = 1;     if (son[x]) {       f[son[x]] = f[x] + 1;       dfs2(son[x], x);       ans[x] = ans[son[x]] + 1;     }     for (int i = head[x]; i; i = nex[i]) {       int v = to[i];       if (v == pre || v == son[x]) continue;       f[v] = id, id += len[v], dfs2(v, x);       for (int j = 1; j <= len[v]; ++j) {         f[x][j] += f[v][j - 1];         if (f[x][j] > f[x][ans[x]] || (f[x][j] == f[x][ans[x]] && j < ans[x]))           ans[x] = j;       }     }     if (f[x][ans[x]] == 1) ans[x] = 0;   }   int main() {     n = read();     for (int i = 1; i < n; ++i) {       u = read(), v = read();       add(u, v);       add(v, u);     }     dfs1(1, 0, 1);     f[1] = id, id += len[1], dfs2(1, 0);     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);   }


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


#include <bits/stdc++.h>   #pragma GCC optimize(                                                                                -fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2 ,        3)   #pragma GCC target( avx ,  sse2 )   const double esp = 1e-6;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const int inf = 1e9;   using namespace std;   long long read() {     char ch = getchar();     long long x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 6e5 + 10;   const int diff = 3e5;   int Q;   struct node {     int pos, to, h;     long long cntx, cnty;     node(int pos, int to, int h, long long cntx, long long cnty) {       this->pos = pos, this->to = to, this->h = h, this->cntx = cntx,       this->cnty = cnty;     }   };   struct DSU {     int par[N], height[N];     long long cntx[N], cnty[N];     long long sum = 0;     DSU() {       for (int i = 1; i <= 6e5 + 1; i++) {         par[i] = i, height[i] = 1;         if (i <= 3e5)           cntx[i] = 1;         else           cnty[i] = 1;       }     }     int find(int x) { return x == par[x] ? x : find(par[x]); }     int unit(int x, int y, stack<node> &st) {       x = find(x), y = find(y);       if (x == y) return 0;       if (height[x] < height[y]) swap(x, y);       node sttemp(y, x, height[y], cntx[y], cnty[y]);       st.push(sttemp);       sum -= cntx[x] * cnty[x];       sum -= cntx[y] * cnty[y];       cntx[x] += cntx[y];       cnty[x] += cnty[y];       sum += cntx[x] * cnty[x];       par[y] = x;       height[x] += height[y];       return 1;     }     void del(stack<node> &st) {       while (st.size()) {         node temp = st.top();         st.pop();         par[temp.pos] = temp.pos;         height[temp.to] -= temp.h;         sum -= cntx[temp.to] * cnty[temp.to];         cntx[temp.to] -= temp.cntx;         cnty[temp.to] -= temp.cnty;         sum += cntx[temp.to] * cnty[temp.to];         sum += temp.cntx * temp.cnty;       }     }   } dsu;   struct SEG {     vector<pair<int, int> > tr[N << 2];     void update(int l, int r, int root, int lf, int rt, pair<int, int> val) {       if (lf <= l && r <= rt) {         tr[root].push_back(val);         return;       }       int mid = (l + r) >> 1;       if (lf <= mid) update(l, mid, root << 1, lf, rt, val);       if (rt > mid) update(mid + 1, r, root << 1 | 1, lf, rt, val);     }     void query(int l, int r, int root) {       stack<node> st;       for (auto k : tr[root]) {         dsu.unit(k.first, k.second + diff, st);       }       if (l == r) {         printf( %lld  , dsu.sum);         dsu.del(st);         return;       }       int mid = (l + r) >> 1;       query(l, mid, root << 1);       query(mid + 1, r, root << 1 | 1);       dsu.del(st);     }   } sgt;   map<pair<int, int>, pair<int, int> > mp;   struct nd {     int x, y, st, ed;   };   vector<nd> query;   int main() {     Q = read();     int x, y;     for (int i = 1; i <= Q; i++) {       x = read(), y = read();       if (mp[{x, y}].first) {         query.push_back(nd{x, y, mp[{x, y}].first, i - 1});         mp[{x, y}].first = 0;       } else {         mp[{x, y}].first = i;       }     }     for (auto k : mp) {       if (k.second.first)         query.push_back(nd{k.first.first, k.first.second, k.second.first, Q});     }     for (auto k : query) {       sgt.update(1, Q, 1, k.st, k.ed, make_pair(k.x, k.y));     }     sgt.query(1, Q, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string mat[n + 5];     int dp[n + 5][n + 5];     for (int i = 0; i < (n); i++) cin >> mat[i];     memset(dp, 0, sizeof(dp));     if (mat[0][0] ==  a ) dp[0][0] = 1;     for (int i = 1; i < (n); i++) {       dp[i][0] = dp[i - 1][0];       if (mat[i][0] ==  a ) dp[i][0]++;       dp[0][i] = dp[0][i - 1];       if (mat[0][i] ==  a ) dp[0][i]++;     }     for (int i = 1; i < (n); i++) {       for (int j = 1; j < (n); j++) {         dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);         if (mat[i][j] ==  a ) dp[i][j]++;       }     }     int maxi = -1;     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (n); j++) {         if (i + j + 1 - dp[i][j] - k <= 0) maxi = max(maxi, i + j);       }     }     set<pair<int, int>> pts;     if (maxi == -1)       pts.insert(make_pair(0, 0));     else {       for (int i = 0; i < (n); i++) {         for (int j = 0; j < (n); j++) {           if (i + j == maxi && (i + j + 1 - dp[i][j] - k) == 0) {             pts.insert(make_pair(i, j));           }         }       }     }     string ans, cont;     for (int i = 0; i < (maxi + 1); i++) ans.push_back( a );     if (maxi == -1) ans.push_back(mat[0][0]), maxi++;     for (int i = maxi; i < (2 * n - 2); i++) {       char mini =  z  + 1;       for (auto x : pts) {         int r = x.first, c = x.second;         if (r < n - 1) mini = min(mini, mat[r + 1][c]);         if (c < n - 1) mini = min(mini, mat[r][c + 1]);       }       ans.push_back(mini);       set<pair<int, int>> temp;       for (auto x : pts) {         int r = x.first, c = x.second;         if (r < n - 1) {           if (mat[r + 1][c] == mini) temp.insert(make_pair(r + 1, c));         }         if (c < n - 1) {           if (mat[r][c + 1] == mini) temp.insert(make_pair(r, c + 1));         }       }       pts = temp;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<int> > ps;     set<int> xs;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       ps[y].push_back(x);       xs.insert(x);     }     map<int, int> rk;     const int INF = 1 << 30;     for (int x : xs) {       int i = rk.size();       rk[x] = i + 1;     }     rk[INF] = xs.size() + 1;     int bit[200100] = {};     long long ans = 0;     xs.clear();     for (auto it = ps.rbegin(); it != ps.rend(); it++) {       int y = it->first;       sort(it->second.begin(), it->second.end());       for (int i = 0; i < it->second.size(); i++) {         int l = it->second[i],             r = (i + 1 == it->second.size() ? INF : it->second[i + 1]);         long long sum1 = 0, sum2 = 0;         if (xs.find(l) == xs.end()) {           xs.insert(l);           for (int j = rk[l]; j <= rk.size() + 1; j += j & -j) bit[j]++;         }         for (int j = rk[l]; j > 0; j -= j & -j) sum1 += bit[j];         for (int j = rk[r] - 1; j > 0; j -= j & -j) sum2 += bit[j];         ans += sum1 * (sum2 - sum1 + 1);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       bool x = false, y = false;       cin >> s;       if (n == 1) {         s[0] % 2 ? cout <<  1 n  : cout <<  2 n ;         continue;       }       for (int i = 0; i < n; i++) {         if ((i + 1) % 2 == 1)           x |= ((s[i] -   0 ) % 2 == 1);         else if ((i + 1) % 2 == 0)           y |= ((s[i] -   0 ) % 2 == 0);       }       if (n % 2 == 1) {         x ? cout << 1 : cout << 2;       } else {         y ? cout << 2 : cout << 1;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long INF = 4e18;   const int inf = 2e9;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   int a[3005], pos[3005];   int main(void) {     int n, i, j, naik = 0;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , a + i);       pos[a[i]] = i;     }     int ans = 0;     for (i = 1; i <= n; ++i) {       while (pos[i] > i) {         swap(a[pos[i]], a[pos[i] - 1]);         swap(pos[a[pos[i]]], pos[a[pos[i] - 1]]);         ans++;       }     }     ans = ((ans >> 1) << 2) + (ans & 1);     printf( %.9f n , (double)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     char s[105][105];     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) scanf( %s , s[i] + 1);       vector<pair<int, int> > r;       bool rc = true;       for (int i = 1; i <= n; ++i) {         int j;         for (j = 1; j <= n; ++j)           if (s[i][j] ==  . ) {             r.push_back(pair<int, int>(i, j));             break;           }         if (j > n) {           rc = false;           break;         }       }       vector<pair<int, int> > c;       bool cc = true;       for (int j = 1; j <= n; ++j) {         int i;         for (i = 1; i <= n; ++i)           if (s[i][j] ==  . ) {             c.push_back(pair<int, int>(i, j));             break;           }         if (i > n) {           cc = false;           break;         }       }       if (rc) {         for (int i = 0; i < n; ++i) printf( %d %d n , r[i].first, r[i].second);       } else if (cc) {         for (int i = 0; i < n; ++i) printf( %d %d n , c[i].first, c[i].second);       } else {         puts( -1 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5 + 10;   vector<string> tot[MaxN];   int cnt;   char s[MaxN];   bool check[MaxN], flag;   set<string> ans;   int main() {     scanf( %s , s);     int len = strlen(s);     check[len] = 1;     for (int i = len - 2; i >= 5; i--) {       if (check[i + 2]) {         string t;         t += s[i];         t += s[i + 1];         if (tot[i + 2].size() == 0) {           check[i] = 1;           tot[i].push_back(t);           ans.insert(t);         } else {           flag = 1;           for (int j = 0; j < tot[i + 2].size(); j++) {             if (tot[i + 2][j] != t) {               flag = 0;               break;             }           }           if (!flag) {             tot[i].push_back(t);             ans.insert(t), check[i] = 1;           }         }       }       if (check[i + 3]) {         string t;         t += s[i];         t += s[i + 1];         t += s[i + 2];         if (tot[i + 3].size() == 0) {           check[i] = 1;           tot[i].push_back(t);           ans.insert(t);         } else {           flag = 1;           for (int j = 0; j < tot[i + 3].size(); j++) {             if (tot[i + 3][j] != t) {               flag = 0;               break;             }           }           if (!flag) {             tot[i].push_back(t);             ans.insert(t), check[i] = 1;           }         }       }     }     printf( %d n , ans.size());     for (set<string>::iterator ite = ans.begin(); ite != ans.end(); ite++) {       cout << *ite << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int r, g, b, w;       cin >> r >> g >> b >> w;       int evens = (r % 2 == 0) + (g % 2 == 0) + (b % 2 == 0) + (w % 2 == 0);       int odds = (r % 2 == 1) + (g % 2 == 1) + (b % 2 == 1) + (w % 2 == 1);       if (evens == 4 || evens == 3 || odds == 4 || (odds == 3 && r && g && b))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string name;     cin >> name;     string right =   , left =   ;     int i = 0;     for (; true; i++) {       if (name[i] ==  | ) {         break;       }       left += name[i];     }     i++;     for (; i < name.length(); i++) {       right += name[i];     }     int ll = left.length();     int rl = right.length();     string toAdd;     cin >> toAdd;     if (abs(rl - ll) == 0) {       if (toAdd.length() % 2 == 0) {         for (int i = 0; i < toAdd.length(); i += 2) {           right += toAdd[i];           left += toAdd[i + 1];         }         cout << left <<  |  << right;       } else {         cout <<  Impossible ;       }     } else if (abs(rl - ll) == toAdd.length()) {       if (rl > ll) {         for (int i = 0; i < (rl - ll); i++) {           left += toAdd[i];         }         cout << left <<  |  << right;       } else {         for (int i = 0; i < (ll - rl); i++) {           right += toAdd[i];         }         cout << left <<  |  << right;       }     } else if (abs(ll - rl) < toAdd.length()) {       if ((rl + ll + toAdd.length()) % 2 == 0) {         if (rl > ll) {           for (int i = 0; i < (rl - ll); i++) {             left += toAdd[i];           }           for (int i = abs(ll - rl); i < toAdd.length(); i += 2) {             right += toAdd[i];             left += toAdd[i + 1];           }           cout << left <<  |  << right;         } else {           for (int i = 0; i < (ll - rl); i++) {             right += toAdd[i];           }           for (int i = abs(ll - rl); i < toAdd.length(); i += 2) {             right += toAdd[i];             left += toAdd[i + 1];           }           cout << left <<  |  << right;         }       } else {         cout <<  Impossible ;       }     } else {       cout <<  Impossible ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   pair<double, double> a[MAXN];   double F[MAXN], S[MAXN];   int n, p;   bool cmp(pair<double, double> x, pair<double, double> y) {     return x.first * y.second > x.second * y.first;   }   int vt = -1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> p;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     if (n == 1) {       if (p >= a[1].first) {         cout << -1;         return 0;       }       double res = a[1].second / (a[1].first - p);       cout << res;       return 0;     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) S[i] = S[i - 1] + a[i].second;     for (int i = 1; i <= n; i++) F[i] = F[i - 1] + a[i].first;     for (int i = 2; i <= n; i++) {       double value = a[i].second / a[i].first;       double res = value * F[i - 1] - S[i - 1];       if (res > p * value) {         vt = i;         break;       }     }     if (vt == -1) {       double res = S[n] / (F[n] - p);       if (F[n] <= p)         cout << -1;       else         cout << res;       return 0;     }     double kq = S[vt - 1] / (F[vt - 1] - p);     cout << fixed;     cout << setprecision(10) << kq;     return 0;   }


#include <bits/stdc++.h>   #include <string>   #include <cstdint>   #include <iterator>   #include <algorithm>   #include <fstream>   #include <vector>   #include <set>      using namespace std;      using ll = long long;   using ld = long double;      #define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define Int int_fast64_t   #define pb push_back   #define mp make_pair   #define all(x) (x).begin(),(x).end()   #define fi first   #define se second      #define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))   #define mine(a)    (*min_element((a).begin(), (a).end()))   #define maxe(a)    (*max_element((a).begin(), (a).end()))      typedef vector<Int> vi;   typedef pair<Int, Int> pii;   typedef pair<Int, bool> pib;   typedef pair<string, Int> psi;   typedef pair<string, string> pss;   typedef vector<pii> vpii;   typedef vector<psi> vpsi;   typedef vector<pss> vpss;         using namespace std;   // Vector   template<typename T>             istream& operator>>(istream& is,  vector<T> &v){for (auto& i : v) is >> i;        return is;}   template<typename T>             ostream& operator<<(ostream& os,  vector<T>  v){for (auto& i : v) os << i <<    ; return os;}   template <typename T>   pair<T, bool> getNthElement(set<T>& searchSet,int index)   {       pair<T, bool> result;          // Check if index is valid or not       if (searchSet.size() > index) {           result.first                   = *(std::next(                   searchSet.begin(),                   index));           result.second = true;       }          else           result.second = false;          // Return the pair       return result;   }         const Int N=7+1e10;      Int gcd(Int a, Int b)   {       // Everything divides 0       if (a == 0)           return b;       if (b == 0)           return a;          // base case       if (a == b)           return a;          // a is greater       if (a > b)           return gcd(a-b, b);       return gcd(a, b-a);   }      int main() {       FAST_IO;          Int t; cin >> t;       while(t--){           Int n; cin >> n;           vi arr(n);           cin >> arr;           Int ans=0;           Int Min=mine(arr);           auto it=find(all(arr), Min);           Int a=it-arr.begin();           if(arr[0]==Min){               cout << n-1 << endl;           }           else{               cout << n << endl;               cout <<  1   << a+1 <<     << Min <<     << Min+1 <<   n ;           }           for(Int i=1;i<n;++i){               cout <<  1   << i+1 <<     << Min <<     << Min+i <<   n ;           }       }          return 0;   }


#include <bits/stdc++.h>   const long long P = 1000000000039LL;   inline long long mul(long long a, long long b) {     long long ans = 0;     for (; b; b >>= 1) {       if (b & 1) {         ans = (ans + a) % P;       }       a = (a << 1) % P;     }     return ans;   }   int k = 0, t = 0;   long long fac[10], ifac[10];   void init() {     fac[0] = 1;     ifac[0] = 1;     fac[1] = 1;     ifac[1] = 1;     for (int i = 2; i < 10; i++) {       ifac[i] = (P - mul(P / i, ifac[P % i])) % P;     }     for (int i = 2; i < 10; i++) {       ifac[i] = mul(ifac[i - 1], ifac[i]);       fac[i] = mul(fac[i - 1], i);     }   }   int cnt[16];   long long f[10], g[10];   long long c[10];   void calc(int len) {     std::fill(f, f + len + 1, 0);     for (int i = 0; i < 16; i++) {       if (cnt[i] < 0) {         return;       }     }     f[0] = 1;     for (int i = 0; i < 16; i++) {       std::fill(g, g + len + 1, 0);       for (int j = 0; j <= cnt[i]; j++) {         for (int u = 0; u <= len - j; u++) {           g[u + j] = (g[u + j] + mul(ifac[j], f[u])) % P;         }       }       std::copy(g, g + len + 1, f);     }   }   void preDP() {     std::fill(cnt, cnt + 16, t);     c[0] = 0;     cnt[1]--;     calc(9);     for (int i = 1; i < 10; i++) {       c[i] = c[i - 1] + 15 * mul(f[i - 1], fac[i - 1]);     }   }   long long solve(long long x) {     long long l = 0, ans = 0;     int d[10];     std::fill(cnt, cnt + 16, t);     for (; x; d[l++] = x % 16, x /= 16)       ;     if (l > 0) {       ans += c[l - 1];     }     for (int i = l - 1; i >= 0; i--) {       for (int u = ((i == l - 1) ? 1 : 0); u < d[i]; u++) {         cnt[u]--;         calc(i);         ans += mul(f[i], fac[i]);         cnt[u]++;       }       cnt[d[i]]--;     }     for (int i = 0; i < 16; i++) {       if (cnt[i] < 0) {         return ans;       }     }     return ans + 1;   }   int main() {     scanf( %d%d , &k, &t);     init();     preDP();     long long l = 0, r = 0xFFFFFFFFFLL;     for (long long mid = 0; l + 1 < r;          solve(mid = (l + r) >> 1) >= k ? r = mid : l = mid)       ;     printf( %I64x n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     double r;     cin >> n >> r;     double X[n];     for (int i = 0; i < n; i++) {       cin >> X[i];     }     double Y[n];     Y[0] = r;     for (int i = 1; i < n; i++) {       Y[i] = r;       for (int j = 0; j < i; j++) {         if (abs(X[i] - X[j]) <= 2 * r)           Y[i] = max(Y[i], Y[j] + sqrt(4 * r * r + 2 * X[i] * X[j] - X[i] * X[i] -                                        X[j] * X[j]));       }     }     for (int i = 0; i < n; i++) {       cout << fixed << setprecision(9) << Y[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> grundies;     grundies.push_back(0);     for (int i = 1; i <= 60; i++) {       long long accum = 0;       long long add = 0;       while (accum < i) {         accum += add;         add++;       }       if (accum > i) {         add--;         accum -= add;       }       add--;       grundies.push_back(add);     }     long long numPiles;     cin >> numPiles;     long long finalState = 0;     for (long long i = 0; i < numPiles; i++) {       long long pile;       cin >> pile;       finalState = finalState ^ grundies[pile];     }     if (!finalState) cout <<  YES  << endl;     if (finalState) cout <<  NO  << endl;     return 0;   }