#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int su[N], lst[N], n, i, a, lim;   long long ans;   pair<int, int> b[N];   int xb;   inline int calc(int k) {     int i, j;     long long s = 0, ans = -1, x, y, z;     xb = 0;     for (i = 0; i * k < N; ++i) {       s += 1ll * i * (su[min(N - 1, (i + 1) * k - 1)] - (i ? su[i * k - 1] : 0));       x = lst[min(N - 1, (i + 1) * k)];       if (x && x >= i * k) {         y = su[x] - su[x - 1] > 1 ? x : lst[x];         if (y >= i * k) b[++xb] = make_pair(i, y - i * k);         b[++xb] = make_pair(i, x - i * k);       }     }     for (i = 1; i <= xb; ++i) {       z = 2 * s - b[i].second;       x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;       if (x <= b[i].first) ans = max(ans, s - x);     }     y = -1;     if (k == 7) {       ++k, --k;     }     for (i = xb; i; --i) {       if (y >= 0) {         z = s - min(1ll * b[i].second, y);         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2);       }       y = max(y, 1ll * b[i].second);     }     y = -1;     for (i = xb; i; --i) {       if (b[i].first < b[xb].first) {         z = s - 1 - b[i].second;         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2 - 1);       }       if (y >= 0) {         z = s + 1 + k - y;         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2 + 1);       }       y = max(y, 1ll * b[i].second);     }     return ans == -1 ? lim : (ans < 2 ? 0 : ans);   }   int main() {     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &a), ++su[a];     for (i = 1; i < N; ++i) lst[i] = su[i - 1] ? i - 1 : lst[i - 1];     a = lst[N - 1];     lim = max(a / 2, su[a] > 1 ? a : lst[a]);     for (i = 1; i < N; ++i) su[i] += su[i - 1];     for (i = 2; i < N; ++i) ans = max(ans, 1ll * i * calc(i));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> s[200050 * 4];   pair<int, int> li[200050];   int n, m, st, qu[200050][3], fa[200050], sg[200050];   inline int Read() {     int x = 0;     char y;     bool z = 0;     do y = getchar(), z |= y ==  - ;     while (y <  0  || y >  9 );     do x = x * 10 + y -  0 , y = getchar();     while (y >=  0  && y <=  9 );     return z ? -x : x;   }   void Pretreat() {     int now = 0;     for (int i = 1; i <= n; i++)       if (qu[i][0] == 1)         li[++now].first = qu[i][1], li[now].second = i,         li[++now].first = qu[i][2], li[now].second = -i;     sort(li + 1, li + now + 1);     li[0].first = int(1e9);     for (int i = 1; i <= now; i++) {       st += li[i].first != li[i - 1].first;       if (li[i].second < 0)         qu[-li[i].second][2] = st;       else         qu[li[i].second][1] = st;     }     return;   }   int Find(int x) { return fa[x] == x ? x : (fa[x] = Find(fa[x])); }   inline void Update(int x, int y) {     qu[0][1] = min(qu[0][1], x);     qu[0][2] = max(qu[0][2], y);   }   void Merge(int x, int y, int z, int o) {     int i = x + y >> 1, j = z << 1;     while (!s[z].empty()) {       int k = Find(s[z].back());       s[z].pop_back();       if (k == m) continue;       Update(qu[sg[k]][1], qu[sg[k]][2]);       fa[k] = m;     }     if (x == y) return;     if (o <= i)       Merge(x, i, j, o);     else       Merge(i + 1, y, j + 1, o);   }   void Modify(int x, int y, int z, int o, int p) {     int i = x + y >> 1, j = z << 1;     if (x == o && y == p) {       s[z].push_back(m);       return;     }     if (p <= i)       Modify(x, i, j, o, p);     else if (o > i)       Modify(i + 1, y, j + 1, o, p);     else       Modify(x, i, j, o, i), Modify(i + 1, y, j + 1, i + 1, p);   }   int main() {     n = Read();     for (int i = 1; i <= n; i++)       qu[i][0] = Read(), qu[i][1] = Read(), qu[i][2] = Read();     Pretreat();     for (int i = 1; i <= n; i++)       if (qu[i][0] == 1) {         m++;         sg[fa[m] = m] = i;         qu[0][1] = qu[i][1];         qu[0][2] = qu[i][2];         Merge(1, st, 1, qu[i][1]);         Merge(1, st, 1, qu[i][2]);         qu[i][1] = qu[0][1];         qu[i][2] = qu[0][2];         if (qu[i][1] < qu[i][2] - 1) Modify(1, st, 1, qu[i][1] + 1, qu[i][2] - 1);       } else {         int k = sg[Find(qu[i][1])], l = sg[Find(qu[i][2])];         if (k == l || (qu[k][1] > qu[l][1] && qu[k][1] < qu[l][2]) ||             (qu[k][2] > qu[l][1] && qu[k][2] < qu[l][2]))           puts( YES );         else           puts( NO );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tu(int val) { return (1 << val); }   bool iset(int mask, int id) {     if ((mask & tu(id)) != 0) return true;     return false;   }   void doset(int &mask, int id) { mask |= tu(id); }   void dounset(int &mask, int id) { mask = mask & (~tu(id)); }   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   const int LM = (1 << 19);   int AR[3 * LM], N;   inline void add(int pos, int val) {     pos += LM - 1;     AR[pos] += val;     while (pos /= 2) AR[pos] = AR[pos + pos] + AR[pos + pos + 1];   }   inline int get(int l, int r, int L = 1, int R = LM, int v = 1) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return AR[v];     const int mid = (L + R) / 2;     return get(l, r, L, mid, v + v) + get(l, r, mid + 1, R, v + v + 1);   }   int main() {     int q;     while (cin >> N >> q) {       memset(AR, 0, sizeof AR);       ;       int opt, oa, ob, l, r, lf, rt, dir;       l = 1, r = N;       dir = 1;       for (int i = 1; i <= N; i++) add(i, 1);       for (int(qq) = (0); (qq) < (q); (qq)++) {         scanf( %d , &opt);         if (opt == 1) {           scanf( %d , &oa);           int len = abs(l - r) + 1;           lf = l + (dir * oa) - dir;           rt = lf + dir;           if (2 * oa <= len) {             for (int(loop) = (0); (loop) < (oa); (loop)++) {               int v = get(lf, lf);               add(rt, v);               lf -= dir;               rt += dir;             }             l += oa * dir;           } else {             oa = len - oa;             for (int(loop) = (0); (loop) < (oa); (loop)++) {               int v = get(rt, rt);               add(lf, v);               lf -= dir;               rt += dir;             }             r -= oa * dir;             swap(l, r);             dir *= -1;           }         } else {           scanf( %d %d , &oa, &ob);           ob--;           int ra = l + oa * dir, rb = l + ob * dir;           if (ra > rb) swap(ra, rb);           printf( %d n , get(ra, rb));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     set<pair<int, int>> s;     map<int, int> m;     int temp;     for (int i = 0; i < n; i++) {       cin >> temp;       if (s.size() < k && (!m.count(temp))) {         s.insert({i + 1, temp});         m[temp] = i + 1;       }       if (!m.count(temp) || (!s.count({m[temp], temp}))) {         s.insert({i + 1, temp});         m[temp] = i + 1;         s.erase(*s.begin());       }     }     int ar[k + 10];     int c = 0;     for (auto u : s) {       ar[c] = u.second;       c++;     }     cout << c <<   n ;     for (int i = c - 1; i >= 0; i--) {       cout << ar[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b;     cin >> a >> b;     a--;     string l = to_string(a);     string r = to_string(b);     long long int ans1;     if (l.length() == 1) {       ans1 = a;     } else {       if (l[0] <= l[(l.length() - 1)]) {         ans1 = (a / 10) + 9;       } else {         ans1 = (a / 10) + 8;       }     }     long long int ans2;     if (r.length() == 1) {       ans2 = b;     } else {       if (r[0] <= r[(r.length() - 1)]) {         ans2 = (b / 10) + 9;       } else {         ans2 = (b / 10) + 8;       }     }     cout << ans2 - ans1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200001;   const int mod = 998244353;   int n, m;   int sum[maxn << 2];   int y[maxn], x;   int vis[maxn];   int fac[maxn << 1], rfac[maxn << 1];   int mul(int a, int b) { return 1LL * a * b % mod; }   int qpow(int a, int q) {     int res = 1;     while (q) {       if (q & 1) res = mul(res, a);       q >>= 1;       a = mul(a, a);     }     return res;   }   void init() {     fac[0] = 1;     int n = maxn * 2;     for (int i = 1; i < n; ++i) {       fac[i] = mul(fac[i - 1], i);     }     rfac[n - 1] = qpow(fac[n - 1], mod - 2);     for (int i = n - 2; i >= 0; --i) {       rfac[i] = mul(rfac[i + 1], i + 1);     }   }   void pushup(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; }   void build(int rt, int l, int r) {     if (l == r) {       sum[rt] = 1;       return;     }     int mid = (l + r) / 2;     build((rt << 1), l, mid);     build((rt << 1 | 1), mid + 1, r);     pushup(rt);   }   int query(int rt, int l, int r, int val) {     if (l == r) {       return l;     }     int mid = (l + r) >> 1;     if (val <= sum[(rt << 1)]) return query((rt << 1), l, mid, val);     return query((rt << 1 | 1), mid + 1, r, val - sum[(rt << 1)]);   }   void update(int rt, int l, int r, int pos, int val) {     if (l == r) {       sum[rt] = val;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update((rt << 1), l, mid, pos, val);     else       update((rt << 1 | 1), mid + 1, r, pos, val);     pushup(rt);   }   int C(int a, int b) { return mul(mul(fac[a], rfac[b]), rfac[a - b]); }   int main() {     int t;     scanf( %d , &t);     init();     int len = maxn - 1;     build(1, 1, len);     while (t--) {       scanf( %d%d , &n, &m);       for (int i = 0; i < m; ++i) {         scanf( %d%d , &x, &y[i]);       }       memset(vis, 0, sizeof(vis));       int c = 0;       vector<int> ve;       for (int i = m - 1; i >= 0; --i) {         int p = query(1, 1, len, y[i]);         int q = query(1, 1, len, y[i] + 1);         update(1, 1, len, p, 0);         if (!vis[q]) {           vis[q] = 1;           ++c;         }         ve.push_back(p);       }       printf( %d n , C(2 * n - c - 1, n));       for (auto u : ve) {         update(1, 1, len, u, 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int M = 1e9 + 7;   long long a[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long d;     cin >> a[0] >> a[1] >> a[2] >> d;     sort(a, a + 3);     cout << max(0ll, a[0] - a[1] + d) + max(0ll, a[1] + d - a[2]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k == n) {         cout <<  Alice n ;         continue;       }       if (k > n || k % 3 != 0) {         if (n % 3 == 0) {           cout <<  Bob n ;         } else {           cout <<  Alice n ;         }         continue;       }       long long z = n % (k + 1);       if (z % 3 == 0 && z != k) {         cout <<  Bob n ;       } else {         cout <<  Alice n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, k, m, n, p, s, t, x, a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (cin >> t; t--;) {       cin >> n >> x;       for (i = p = 0; i < n; i++) {         cin >> a[i];         if (a[i] == x) p = 1;       }       sort(a, a + n);       if (p)         cout << 1 << endl;       else if (a[n - 1] > x)         cout << 2 << endl;       else         cout << (x - 1) / a[n - 1] + 1 << endl;     }   }


#include <bits/stdc++.h>   int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};   int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};   int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};   int dr2[] = {0, 0, 1, -1};   int dc2[] = {1, -1, 0, 0};   using namespace std;   vector<int> adj[1000005];   int a[1000005], b[1000005], dp1[1000005];   long long get(string t) {     if (t ==  IN ) return 0;     if (t ==  AND ) return 1;     if (t ==  XOR ) return 2;     if (t ==  OR ) return 3;     if (t ==  NOT ) return 4;   }   long long get1(long long x, long long y, long long v) {     if (a[v] == 1) return (x & y);     if (a[v] == 2) return (x ^ y);     if (a[v] == 3) return (x | y);   }   long long dfs(long long u) {     if (a[u] == 0) {       dp1[u] = b[u];       return dp1[u];     }     long long i, j;     if (adj[u].size() == 1) {       long long p = adj[u][0];       long long r = dfs(p) ^ 1;       dp1[u] = r;       return r;     } else {       long long p = adj[u][0];       long long q = adj[u][1];       p = dfs(p);       q = dfs(q);       long long r;       if (a[u] == 1)         r = p & q;       else if (a[u] == 2)         r = p ^ q;       else if (a[u] == 3)         r = p | q;       dp1[u] = r;       return r;     }   }   int dp[1000005][2][2];   long long cal(long long x, long long f, long long f1) {     if (f1 == 0) return (dp1[x] == f);     if (a[x] == 0) {       if (b[x] ^ 1 == f) return 1;       return 0;     }     int &r = dp[x][f][f1];     if (r != -1) return r;     r = 0;     if (adj[x].size() == 1) {       long long p = adj[x][0];       r = cal(p, f ^ 1, f1);       return r;     } else {       long long i, j;       long long p = adj[x][0];       long long q = adj[x][1];       for (i = 0; i < 2; i++) {         for (j = 0; j < 2; j++) {           long long p1 = get1(i, j, x);           if (p1 == f) {             long long r1 = cal(p, i, f1) & cal(q, j, 1 - f1);             long long r2 = cal(p, i, 1 - f1) & cal(q, j, f1);             r |= r1;             r |= r2;           }         }       }       return r;     }   }   int mark[1000005];   void print(long long x, long long f, long long f1) {     if (a[x] == 0) {       mark[x] = 1;       return;     }     if (adj[x].size() == 1) {       long long p = adj[x][0];       print(p, f ^ 1, f1);       return;     }     long long i, j;     long long p = adj[x][0];     long long q = adj[x][1];     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         long long p1 = get1(i, j, x);         if (p1 == f) {           long long r1 = cal(p, i, f1) & cal(q, j, 1 - f1);           if (r1 == 1) {             print(p, i, f1);           }           r1 = cal(p, i, 1 - f1) & cal(q, j, f1);           if (r1 == 1) {             print(q, j, f1);           }         }       }     }   }   int main() {     int n, i, j, x, y;     while (cin >> n) {       for (i = 1; i <= n; i++) {         string t;         cin >> t;         a[i] = get(t);         if (a[i] == 0 || a[i] == 4) {           cin >> x;           if (a[i] == 0)             b[i] = x;           else             adj[i].push_back(x);         } else {           cin >> x >> y;           adj[i].push_back(x);           adj[i].push_back(y);         }       }       long long ans = dfs(1);       memset(dp, -1, sizeof(dp));       long long p = cal(1, ans ^ 1, 1);       print(1, ans ^ 1, 1);       for (i = 1; i <= n; i++) {         if (a[i] == 0) {           if (mark[i] == 0)             cout << ans;           else             cout << (ans ^ 1);         }       }       cout << endl;     }     return 0;   }


/*       @uthor: Amit Kumar       user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces: dr_virus_ ;AtCoder,Hackerearth,Hakerrank: dr_virus;   */   #include <bits/stdc++.h>   #include <chrono>   using namespace std;   using namespace std::chrono;   //#include <boost/multiprecision/cpp_int.hpp>   //namespace mp = boost::multiprecision;   //#define ln mp::cpp_int;   #define int      long long   #define double   long double   #define uint     unsigned long long   #define endl   n    #define all(vec) vec.begin(),vec.end()   int google_itr = 1;   #define google(x) cout<< Case # <<x<< :     #define pi 3.14159265358979323846264338327950L      vector<string> vec_splitter(string s) {           s +=  , ;           vector<string> res;           while(!s.empty()) {                   res.push_back(s.substr(0, s.find( , )));                   s = s.substr(s.find( , ) + 1);           }           return res;   }   void debug_out(   vector<string> __attribute__ ((unused)) args,   __attribute__ ((unused)) int idx,    __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }    template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {           if(idx > 0) cerr <<  ,  ; else cerr <<  Line(  << LINE_NUM <<  )  ;           stringstream ss; ss << H;           cerr << args[idx] <<   =   << ss.str();           debug_out(args, idx + 1, LINE_NUM, T...);   }      #define XOX   #ifdef XOX       #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)   #else       #define deb(...) 42   #endif         const int mod = 1e9+7;   const int inf = 1e18;         void virus(){           int n;           cin >> n;              vector <int> arr(n), seq(n);           for(auto &i:arr) cin >> i;           iota(all(seq), 0);              partial_sum(all(arr), arr.begin());           partial_sum(all(seq), seq.begin());              for(auto i=0; i<n; i++) {               if(arr[i] < seq[i]) {                   cout <<  NO n ; return;               }           }              cout <<  YES n ;   }         int32_t main(){       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);            /*#ifndef ONLINE_JUDGE       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);       #endif*/          int t;       cin >> t;       while(t--){              auto start = system_clock::now();              virus();              auto stop = system_clock::now();              duration<double> duration = (stop - start);              //cerr <<   nTime:  << fixed << setprecision(10) << (double)duration.count() << sec << endl;              //your code goes here       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     vector<int> a(5);     string s;     long long q = 0;     for (int i = 1; i < 5; ++i) {       cin >> a[i];     }     cin >> s;     for (int i = 0; i < (int)s.size(); ++i) {       q += a[s[i] -  0 ];     }     cout << q;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 2e6 + 5;   int n, m, k;   int last[30], dp[maxn];   char s[maxn];   int main() {     scanf( %d%d%s , &n, &k, s + 1);     m = strlen(s + 1);     n += m;     memset(last, -1, sizeof(last));     dp[0] = 1;     for (int i = (1); i <= (n); ++i) {       if (i <= m)         if (~last[s[i] -  a ])           dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[s[i] -  a ] - 1]) % INF;         else           dp[i] = dp[i - 1] * 2 % INF;       else {         int mn = 0;         for (int j = (0); j < (k); ++j)           if (last[mn] > last[j]) mn = j;         if (~last[mn])           dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[mn] - 1]) % INF;         else           dp[i] = dp[i - 1] * 2 % INF;         s[i] = mn +  a ;       }       last[s[i] -  a ] = i;     }     printf( %d n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::queue;   using std::sort;   using std::string;   using std::vector;   int main() {     char last =  b ;     char x =  b ;     while ((x = getchar()) != EOF) {       if (x >=  a  && x <=  z ) {         last = x -  a  +  A ;       } else if (x >=  A  && x <=  Z ) {         last = x;       }     }     if (last ==  A  || last ==  E  || last ==  I  || last ==  O  || last ==  U  ||         last ==  Y ) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     queue<int> q;     set<int> vals;     for (int i = 0; i < n; ++i) {       int id;       cin >> id;       if (!vals.count(id)) {         if (int(q.size()) >= k) {           int cur = q.front();           q.pop();           vals.erase(cur);         }         vals.insert(id);         q.push(id);       }     }     vector<int> res;     while (!q.empty()) {       res.push_back(q.front());       q.pop();     }     reverse(res.begin(), res.end());     cout << res.size() << endl;     for (auto it : res) cout << it <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l[605], r[605];   string str, tmp;   stack<string> S;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i] >> r[i];     for (int i = n - 1; i >= 0; i--) {       if (l[i] == 1) {         S.push( () );         continue;       } else {         int lenth = 1;         tmp =   ;         while (!S.empty() && lenth < l[i]) {           tmp = tmp + S.top();           lenth += S.top().length();           S.pop();         }         tmp =  (  + tmp +  ) ;         S.push(tmp);         if (lenth > r[i] || lenth < l[i]) {           cout <<  IMPOSSIBLE  << endl;           return 0;         }       }     }     while (!S.empty()) {       cout << S.top();       S.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int t, n;   } a[200005];   int cmp(const void* a, const void* b) {     node* aa = (node*)a;     node* bb = (node*)b;     if (aa->n > bb->n) {       return 1;     } else if (aa->n == bb->n) {       return bb->t - aa->t;     } else {       return -1;     }   }   int main() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       int i;       for (i = 0; i < n; i++) {         scanf( %d , &a[i].n);         a[i].t = 1;       }       for (i = 0; i < n; i++) {         scanf( %d , &a[i + n].n);         a[i + n].n = k - a[i + n].n;         a[i + n].t = 2;       }       int s1 = 0, s2 = 0;       qsort(a, 2 * n, sizeof(a[0]), cmp);       for (i = 0; i < 2 * n; i++) {         if (a[i].t == 2) {           s2++;         } else {           if (s2) {             s2--;             s1++;           }         }       }       printf( 1 %d n , s1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct tree {     int l, r, c, p;   };   int n, K, m, r;   long long res, a[10000011], b[10000011];   bool cmp1(tree a, tree b) { return a.l < b.l; }   bool cmp2(tree a, tree b) { return a.r < b.r; }   void update(int x, int l, int r, int c, int p) {     if (l == r) {       a[x] += c, b[x] += 1ll * l * c;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(x << 1, l, mid, c, p);     else       update(x << 1 | 1, mid + 1, r, c, p);     a[x] = a[x << 1] + a[x << 1 | 1], b[x] = b[x << 1] + b[x << 1 | 1];     return;   }   long long query(int x, int l, int r, int p) {     if (l == r) {       if (p <= a[x]) return 1ll * l * p;       return b[x];     }     int mid = (l + r) >> 1;     if (a[x << 1] >= p) return query(x << 1, l, mid, p);     return query(x << 1 | 1, mid + 1, r, p - a[x << 1]) + b[x << 1];   }   int main() {     scanf( %d%d%d , &n, &K, &m);     tree a[m + 1], b[m + 1];     for (int i = 1; i <= m; i++)       scanf( %d%d%d%d , &a[i].l, &a[i].r, &a[i].c, &a[i].p), b[i] = a[i];     for (int i = 1; i <= m; i++) r = max(r, a[i].p);     sort(a + 1, a + m + 1, cmp1);     sort(b + 1, b + m + 1, cmp2);     for (int i = 1, j = 1, k = 1; i <= n; i++) {       while (j <= m && a[j].l == i) update(1, 1, r, a[j].c, a[j].p), j++;       res += query(1, 1, r, K);       while (k <= m && b[k].r == i) update(1, 1, r, -b[k].c, b[k].p), k++;     }     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k;     string str;     cin >> str;     cin >> k;     int temp[50];     memset(temp, 0, sizeof(temp));     int count = 0;     for (int i = 0; i < str.size(); ++i) {       if (temp[(int)(str[i] -  a )] == 0) {         count++;         temp[str[i] -  a ] = 1;       }     }     if (count >= k) {       cout <<  0  << endl;     } else if (k > (int)str.size()) {       cout <<  impossible  << endl;     } else {       cout << k - count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 2e18;   long long mod = 1e6;   const long long M = 1e5;   string s;   long long a[M];   long long bmm(long long a, long long b) {     if (b == 0) return a;     return bmm(b, a % b);   }   int main() {     long long n;     cin >> n;     string s =   ;     for (long long i = 0; i < n; i++) {       cin >> a[i];       s +=  ? ;     }     long long su = 0;     for (long long i = n - 1; i > -1; i--) {       if (su > 0) {         s[i] =  - ;         su -= a[i];       } else {         s[i] =  + ;         su += a[i];       }     }     if (su < 0)       for (long long i = 0; i < n; i++)         if (s[i] ==  + )           s[i] =  - ;         else           s[i] =  + ;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char *argv[]) {     int n, m;     scanf( %d %d , &n, &m);     int a[n], b[n];     map<int, int> mp_a;     map<int, int> mp_b;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       mp_b[b[i]]++;     }     sort(a, a + n);     int k = a[0];     long long ans = 2000000000000000 + 5;     for (int i = 0; i < n; i++) {       int x;       if (b[i] == k)         x = 0;       else if (b[i] > k)         x = b[i] - k;       else         x = m - k + b[i];       for (int j = 0; j < n; j++) {         mp_a[(a[j] + x) % m]++;       }       bool f = true;       for (auto &it : mp_a) {         if (mp_b.find(it.first) != mp_b.end() && mp_b[it.first] == it.second)           continue;         else           f = false;       }       if (f) ans = min(ans, (long long)x);       mp_a.clear();     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vc, va, vb;   int a[3], b[3], c[3];   long long n, m, s, p[50], pp[1 << 20];   void fac(int k, vector<pair<int, int> > &v) {     int m = sqrt(k);     for (int i = 2; i <= m; i++)       if (k % i == 0) {         int cnt = 0;         while (k % i == 0) k /= i, cnt++;         v.push_back(pair<int, int>(i, cnt));       }     if (k > 1) v.push_back(pair<int, int>(k, 1));     return;   }   void func(vector<pair<int, int> > &v) {     sort(v.begin(), v.end());     vector<pair<int, int> > w;     for (auto first : v) {       if (!w.empty() && w.back().first == first.first)         w.back().second += first.second;       else         w.push_back(first);     }     v = w;     return;   }   long long ans;   void calc(int first, long long up) {     if (first == vc.size()) {       ans++;       return;     }     if (up < vc[first].first) {       ans++;       return;     }     int al = vc[first].second;     for (int i = 0; i <= al; i++) {       calc(first + 1, up);       up /= vc[first].first;       if (up == 0) break;     }     return;   }   int main() {     int T;     for (scanf( %d , &T); T--;) {       scanf( %d %d %d , &a[0], &a[1], &a[2]);       scanf( %d %d %d , &b[0], &b[1], &b[2]);       scanf( %d %d %d , &c[0], &c[1], &c[2]);       long long m = 1ll * b[0] * b[1] * b[2];       va.clear();       vb.clear(), vc.clear();       ans = 0;       for (int i = 0; i < 3; i++) fac(a[i], va);       for (int i = 0; i < 3; i++) fac(c[i], vc);       func(va), func(vc);       if (vc[0].first == 2)         vc[0].second++;       else         vc.insert(vc.begin(), pair<int, int>(2, 1));       n = 1ll * a[0] * a[1] * a[2];       m = 1ll * b[0] * b[1] * b[2];       calc(0, n);       int sz = va.size();       for (int i = 0; i < sz; i++) {         int k =             lower_bound(vc.begin(), vc.end(), pair<int, int>(va[i].first, 0)) -             vc.begin();         int deg = 0;         if (k < vc.size() && vc[k].first == va[i].first) deg = vc[k].second;         if (va[i].second > deg)           vb.push_back(pair<int, int>(va[i].first, deg + 1));       }       sz = vb.size();       for (int i = 0; i < sz; i++) {         int q = vb[i].first, r = vb[i].second;         p[i] = 1;         while (r--) p[i] *= q;       }       int up = 1 << sz;       pp[0] = 1;       for (int i = 1; i < up; i++) {         int t = __builtin_ctz(i);         pp[i] = pp[i - (1 << t)] * p[t];       }       for (int i = 0; i < up; i++) {         int k = __builtin_popcount(i);         if (k & 1)           ans -= m / pp[i];         else           ans += m / pp[i];       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans[1000005], anss[1000005][10];   int make(int n) {     long long g = 1;     if (n % 10 != 0) g = g * (n % 10);     n = n / 10;     while (n > 0) {       if (n % 10 != 0) g = g * (n % 10);       n = n / 10;     }     return g;   }   long long bit[1000005][11];   void update(int idx, int val) {     while (idx <= 1000000) {       bit[idx][val]++;       idx += idx & (-idx);     }   }   long long query(int idx, int val) {     long long sum = 0;     while (idx > 0) {       sum += bit[idx][val];       idx -= idx & (-idx);     }     return sum;   }   int main() {     long long int i;     ans[1] = 1;     ans[0] = 0;     for (i = 2; i <= 9; i++) {       ans[i] = i;     }     int k;     for (int i = 10; i <= 1000000; i++) {       k = i;       while (make(k) >= 10) {         k = make(k);       }       k = make(k);       ans[i] = k;     }     for (i = 1; i <= 1000000; i++) {       update(i, ans[i]);     }     int q;     cin >> q;     while (q--) {       int l, r, k;       cin >> l >> r >> k;       cout << query(r, k) - query(l - 1, k) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c = 0, sum = 0, cn = 0, mx = 0;     char s[101];     scanf( %s , s);     for (b = 0; b <= strlen(s); b++) {       cn++;       if (s[b] ==  A  || s[b] ==  E  || s[b] ==  I  || s[b] ==  O  ||           s[b] ==  U  || s[b] ==  Y ) {         mx = max(cn, mx);         cn = 0;       }       mx = max(mx, cn);     }     printf( %d n , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int n, k, m, x, a, b;   long long t, T;   set<pair<int, pair<long long, int>>> wc;   set<pair<long long, pair<int, int>>> rc;   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i < k + 1; i++)       scanf( %d , &x), wc.insert(make_pair(x, make_pair(0, i)));     for (int i = 0; i < m; i++) {       scanf( %lld%d%d , &t, &a, &b);       T = max(T, t);       while (!rc.empty() && rc.begin()->first <= T) {         int id = rc.begin()->second.first;         int pos = rc.begin()->second.second;         wc.insert(make_pair(pos, make_pair(rc.begin()->first, id)));         rc.erase(rc.begin());       }       if (wc.empty()) {         T = max(T, rc.begin()->first);         while (!rc.empty() && rc.begin()->first <= T) {           int id = rc.begin()->second.first;           int pos = rc.begin()->second.second;           wc.insert(make_pair(pos, make_pair(rc.begin()->first, id)));           rc.erase(rc.begin());         }       }       auto rit = wc.lower_bound(make_pair(a, make_pair(0, 0)));       pair<int, pair<long long, int>> carl, carr;       if (rit == wc.end())         carr = make_pair((1 << 30), make_pair(0, 0));       else         carr = *rit;       auto lit = wc.lower_bound(make_pair(a + 1, make_pair(0, 0)));       if (lit == wc.begin()) {         carl = make_pair(-(1 << 30), make_pair(0, 0));       } else {         --lit;         int pos = lit->first;         lit = wc.lower_bound(make_pair(pos, make_pair(0, 0)));         carl = *lit;       }       if (a - carl.first < carr.first - a ||           (a - carl.first == carr.first - a && carl.second < carr.second))         swap(carl, carr);       printf( %d %lld n , carr.second.second, T + abs(carr.first - a) - t);       wc.erase(carr);       rc.insert(make_pair(T + abs(carr.first - a) + abs(a - b),                           make_pair(carr.second.second, b)));     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const double pi = acos(-1);   inline long long read() {     long long 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;   }   long long a[maxn], b[maxn], dp[maxn];   struct Tree {     long long l, r, maxval;   } tree[maxn * 4];   void push_up(long long p) {     tree[p].maxval = max(tree[p * 2].maxval, tree[p * 2 + 1].maxval);   }   void build(long long p, long long l, long long r) {     tree[p].maxval = 0;     tree[p].l = l;     tree[p].r = r;     if (l == r) {       return;     }     long long mid = (l + r) >> 1;     build(p * 2, l, mid);     build(p * 2 + 1, mid + 1, r);     push_up(p);   }   void modify(long long p, long long l, long long r, long long d) {     if (l <= tree[p].l && r >= tree[p].r) {       tree[p].maxval = d;       return;     }     long long mid = (tree[p].l + tree[p].r) >> 1;     if (l <= mid) modify(p * 2, l, r, d);     if (r > mid) modify(p * 2 + 1, l, r, d);     push_up(p);   }   long long query(long long p, long long l, long long r) {     if (l <= tree[p].l && r >= tree[p].r) {       return tree[p].maxval;     }     long long mid = (tree[p].l + tree[p].r) >> 1;     long long ans = 0;     if (l <= mid) ans = max(ans, query(p * 2, l, r));     if (r > mid) ans = max(ans, query(p * 2 + 1, l, r));     return ans;   }   int main(void) {     cin.tie(0);     std::ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       long long r, h;       cin >> r >> h;       a[i] = r * r * h;       b[i] = a[i];     }     sort(b + 1, b + 1 + n);     build(1, 1, n);     long long ans = 0;     for (long long i = 1; i <= n; i++) {       long long tmp = lower_bound(b + 1, b + 1 + n, a[i]) - b;       dp[i] = max(dp[i], query(1, 1, tmp - 1) + a[i]);       modify(1, tmp, tmp, dp[i]);       ans = max(ans, dp[i]);     }     cout << fixed << setprecision(10) << (1.0 * ans * pi) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void printprecise(double l, long long int precision) {     std::cout << std::fixed;     std::cout << std::setprecision(precision);     std::cout << l;   }   long long int ncr(long long int n, long long int k) {     long long int C[n + 1][k + 1];     long long int i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= min(i, k); j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }     return C[n][k];   }   long long int power_wm(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int root(long long int x, vector<long long int> &roots) {     if (roots[x] != x) roots[x] = root(roots[x], roots);     return roots[x];   }   void unoin(long long int p, long long int q, vector<long long int> &roots,              vector<long long int> &rank) {     long long int rp = root(p, roots);     long long int rq = root(q, roots);     if (rank[rq] < rank[rp]) {       roots[rq] = rp;     } else if (rank[rp] > rank[rq]) {       roots[rp] = rq;     } else {       roots[rp] = rq;       rank[rq]++;     }   }   long long int dig_sum(long long int n) {     long long int s = 0;     while (n) {       s += n % 10;       n /= 10;     }     return s;   }   long long int gcd(long long int a, long long int b) {     if (a < b) {       a = a + b;       b = a - b;       a = a - b;     }     if (b == 0) return a;     return gcd(b, a % b);   }   long long int toD(long long int x, long long int y, long long int m) {     return x * m + y % m;   }   pair<long long int, long long int> twoD(long long int p, long long int m) {     return (make_pair(p / m, p % m));   }   vector<long long int> dist;   vector<vector<long long int> > g;   void dfs(long long int p) {     if (dist[p] != -1) {       return;     }     dist[p] = 0;     long long int maxd = -1;     for (long long int i = 0; i < g[p].size(); i++) {       dfs(g[p][i]);       maxd = max(maxd, dist[g[p][i]]);     }     dist[p] = maxd + 1;   }   vector<long long int> fact;   void calfact() {     fact[0] = 1;     for (long long int i = 1; i < 1000001; i++) {       fact[i] = (fact[i - 1] * i) % 998244353;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     string s;     cin >> s;     s =     + s;     long long int c = 0;     vector<long long int> last_a(n + 1), last_b(n + 1);     for (long long int i = 1; i < n + 1; i++) {       last_b[i] = last_b[i - 1];       last_a[i] = last_a[i - 1];       if (s[i - 1] ==  A ) {         last_a[i] = i - 1;       } else {         last_b[i] = i - 1;       }       if (s[i] ==  A ) {         c += last_a[i];         if (last_b[i] > 0 and last_b[i] < last_a[i]) {           c--;         }       } else {         c += last_b[i];         if (last_a[i] > 0 and last_a[i] < last_b[i]) {           c--;         }       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, i, j, n, t, m;     cin >> t;     while (t--) {       string s;       cin >> s;       n = s.size();       vector<long long> ans;       long long count = 0;       for (i = 0; i < n; i++) {         if (s[i] ==  1 )           count++;         else {           ans.push_back(count);           count = 0;         }       }       if (count != 0) ans.push_back(count);       long long sum = 0;       sort(ans.rbegin(), ans.rend());       for (i = 0; i < ans.size(); i++) {         if (i % 2 == 0) sum += ans[i];       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a, lev[16], loy[16], suf;   double ret;   double dp[16][(2 << 8)];   double calc(int pos, int mask) {     if (pos == n) {       int need = suf - __builtin_popcount(mask);       if (need <= 0)         return 1.0;       else {         int b = 0;         for (int i = 0; i < (n); ++i)           if (!((mask & (1LL << i)) != 0LL)) b += lev[i];         return double(a) / double(a + b);       }     }     double &ret = dp[pos][mask];     if (ret != -1) return ret;     ret = calc(pos + 1, mask) * double(100.0 - loy[pos]) / 100.0 +           calc(pos + 1, mask + (1 << pos)) * double(loy[pos]) / 100.0;     return ret;   }   int llamadas = 0;   double calcprob() {     fill(&dp[0][0], &dp[16][0], -1.0);     llamadas++;     return calc(0, 0);   }   void simu(int pos, int candy) {     if (pos == n) {       ret = max(ret, calcprob());       return;     }     int minus = 0;     simu(pos + 1, candy);     for (int i = 0; i < (candy); ++i) {       if (loy[pos] == 100) break;       minus++;       loy[pos] += 10;       simu(pos + 1, candy - i - 1);     }     loy[pos] -= minus * 10;   }   int main() {     cin >> n >> k >> a;     for (int i = 0; i < (n); ++i) cin >> lev[i] >> loy[i];     suf = n / 2 + 1;     ret = 0.0;     simu(0, k);     printf( %.10f n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long P = 998244353LL;   const int N_MAX = 1e5 + 15;   int A[N_MAX];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     long long ans = 0LL;     bool rem = 1;     long long q = 1LL;     while (rem) {       long long t = 0LL;       for (int i = 0; i < n; i++) {         t += (1LL * (A[i] % 10));         A[i] /= 10;         if (A[i] == 0) rem = 0;       }       t *= q;       t %= P;       q *= 100LL;       q %= P;       ans += t;       ans %= P;     }     ans *= 11LL;     ans %= P;     ans *= n;     ans %= P;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int i, j;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int k, n;     cin >> k;     long long int maxi = -1;     for (i = 0; i < k; i++) {       cin >> n;       maxi = max(maxi, n);     }     if (maxi > 25)       cout << maxi - 25;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long INF = 1e9;   long long b[N];   long long ans[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; ++i) cin >> b[i];       long long sum = 0;       for (int i = 1; i <= n; ++i) sum += b[i];       long long x = (long long)n * (n + 1) / 2;       if (sum % x != 0) {         cout <<  NO  <<   n ;       } else {         sum /= x;         bool cek = true;         for (int i = 1; i <= n; ++i) {           int p = (i + n - 2) % n + 1;           if ((sum - b[i] + b[p]) % n != 0) cek = false;           ans[i] = (sum - b[i] + b[p]) / n;         }         for (int i = 1; i <= n; ++i) {           if (ans[i] <= 0 || ans[i] > INF) cek = false;         }         if (cek) {           cout <<  YES  <<   n ;           for (int i = 1; i <= n; ++i) {             cout << ans[i];             if (i < n) cout <<    ;           }           cout <<   n ;         } else {           cout <<  NO  <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 10;   const int MOD = 998244353;   long long f[maxn];   int lim[maxn];   long long frac[maxn], ifrac[maxn];   int arr[maxn], b[maxn];   int n;   long long fpow(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return ret;   }   void init() {     frac[0] = 1;     for (int i = 1; i < maxn; i++) frac[i] = frac[i - 1] * i % MOD;     ifrac[maxn - 1] = fpow(frac[maxn - 1], MOD - 2);     for (int i = maxn - 2; i >= 0; i--) ifrac[i] = ifrac[i + 1] * (i + 1) % MOD;     return;   }   long long A(int a, int b) {     if (a < b || b < 0) return 0;     return frac[a] * ifrac[a - b] % MOD;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     init();     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       b[i] = arr[i] * 2;     }     sort(arr + 1, arr + 1 + n);     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) {       int dex = upper_bound(b + 1, b + 1 + n, arr[i]) - b;       --dex;       lim[i] = dex;     }     f[0] = 1;     lim[0] = -1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= lim[i]; j++)         f[i] = (f[i] + f[j] * A(n - 2 - lim[j], lim[i] - lim[j] - 1) % MOD) % MOD;     }     if (lim[n] == n - 1)       cout << f[n] <<   n ;     else       cout << 0 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   priority_queue<pair<int, int> > p;   int n;   const int maxn = 1 << 19;   int vis[maxn];   long long dp[maxn][19];   int a[maxn], pos, L, sum;   long long ans;   int main() {     scanf( %d , &n);     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == -1) pos = i;       if (!pos) a[i] = 0;     }     a[pos] = 0;     int tmp = n;     for (L = 0; 1 << L <= n; L++)       ;     for (int j = 1; j <= L; j++) {       long long Mi = inf;       if (j == 1) Mi = 0;       for (int i = n; i > n - j + 1; i--)         if (dp[i][j - 1] != -1) Mi = min(Mi, dp[i][j - 1]);       for (int i = n - j + 1; i >= n - sum; i--) {         dp[i][j] = Mi + a[i];         if (dp[i][j - 1] != -1) Mi = min(Mi, dp[i][j - 1]);       }       sum += tmp / 2;       tmp /= 2;     }     long long ans = inf;     for (int i = 1; i <= n; i++)       if (dp[i][L] != -1) ans = min(ans, dp[i][L]);     cout << ans <<   n ;   }


/// Down with The Sickness   #pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   #pragma GCC optimization ( unroll-loops )      #include  bits/stdc++.h    using namespace std;      using ll = long long;   using ii = pair<int, int>;      #define pb push_back   #define F first   #define S second   #define f(i,a,b)  for(int i = a; i < b; i++)   #define all(a)  a.begin(),a.end()   #define rall(a) a.rbegin(),a.rend()      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());      const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;   vector<int> getF(string s){       vector<int> vt(26);       for(char c : s)           vt[c -  a ] += 1;       return vt;   }   vector<int> getLCPArray(vector<pair<string, int>> v) {       vector<int> ret;       for(int i = 1, j; i < v.size(); i++){           for(j = 0; j < v[i].first.size() && v[i].first[j] == v[i-1].first[j]; j++);           ret.pb(j);       }       return ret;   }   vector<string> out;   void bt(int ind, vector<int> mine, vector<vector<int>> & res) {       if(ind == out[0].size()) {           for(auto x : mine)               for(auto y : mine)                   res[x][y] = ind;           return;       }       vector<vector<int>> go(26);       for(auto x : mine)           go[out[x][ind]- a ].pb(x);          f(i,0,26)if(go[i].size()){           f(j,i+1,26)if(go[j].size()){               for(auto x : go[i])                   for(auto y : go[j])                       res[x][y] = res[y][x] = ind;           }           bt(ind + 1, go[i], res);           go[i].clear();       }   }   ll solveBig(vector<string> v){       int n = v.size();       out = v;       vector<vector<int>> sorted;       for(int i = 0; i < v.size(); i++) {           sorted.push_back(vector<int>());           sorted.back().push_back(1);           int sz = v[i].size();           for(int j = sz - 2; j >= 0; --j) {               if(v[i][j] <= v[i][j+1]){                   sorted.back().pb(sorted.back().back() + 1);               }   else {                   sorted.back().pb(1);               }           }           reverse(all(sorted.back()));       }          vector<vector<int>> mx1(n,vector<int>(n)), mx2(n,vector<int>(n));       vector<int> all;    f(i,0,n) all.pb(i);       bt(0,all,mx1);       for(auto & x : out)           reverse(x.begin(),x.end());       bt(0,all,mx2);       ll ans = 0;       for(int i = 0; i < v.size(); i++)       for(int j = i + 1; j < v.size(); j++){           int l = mx1[i][j];           int r = mx2[i][j];           if(l == v[0].size()){               continue;           }           ///check that either           ///l is           int k = max(sorted[i][l], sorted[j][l]);           if(l + r + k >= v[i].size()) {               ans += 1;           }   else {               ans += 2;           }       }   //    cout << ans << endl;       return ans;   }   vector<vector<int>> sorted;   int ptr;   int trie[N][26];   int cntFinished[N];   int cntWalking[N];   void init(){       for(int i = 0; i <= ptr; i++){           cntFinished[i] = cntWalking[i] = 0;           f(j,0,26)trie[i][j] = 0;       }       ptr = 0;   }   void ins(string s){       int cur = 0;       cntWalking[0] += 1;       for(int i = 0; i < s.size(); i++){           if(!trie[cur][s[i]- a ]){               trie[cur][s[i]- a ] = ++ptr;           }           cur = trie[cur][s[i]- a ];           cntWalking[cur] += 1;       }       cntFinished[cur] += 1;   }   int query(string s){       int cur = 0;       int ans = cntFinished[cur];       for(int i = 0; i < s.size(); i++){           if(!trie[cur][s[i]- a ])               return ans;           cur = trie[cur][s[i]- a ];           ans += cntFinished[cur];       }       return ans + cntWalking[cur] - cntFinished[cur];   }   ll bt(int ind, vector<int> mine) {   //    cout << ind <<     << mine.size() << endl;       if(ind == out[0].size())return 0;       vector<int> go[26];       for(auto x : mine)           go[out[x][ind]- a ].pb(x);       ll ret = 0;       init();       int cnt =  0;       for(int i = 0; i < 26; i++)if(go[i].size()) {           vector<string> toIns;           for(auto x : go[i]){               string lft = out[x].substr(ind+sorted[x][ind]);               reverse(all(lft));               toIns.pb(lft);               ret += cnt * 2;               ret -= query(lft);           }           for(auto x : toIns)               ins(x);           cnt += toIns.size();       }          f(i,0,26)if(go[i].size()){           ret += bt(ind+1,go[i]);           go[i].clear();       }          return ret;   }   ll solveSmall(vector<string> v){       out = v;       ///sizes are <= 450       int n = v.size();       for(int i = 0; i < v.size(); i++) {           sorted.push_back(vector<int>());           sorted.back().push_back(1);           int sz = v[i].size();           for(int j = sz - 2; j >= 0; --j) {               if(v[i][j] <= v[i][j+1]){                   sorted.back().pb(sorted.back().back() + 1);               }   else {                   sorted.back().pb(1);               }           }           reverse(all(sorted.back()));       }       vector<int> all;       f(i,0,n)all.pb(i);       return bt(0,all);      }   int n;   ll solve(vector<string> v){       if(v.size() < 450||n==5001)           return solveBig(v);       return solveSmall(v);   }   int main(){   #ifdef ONLINE_JUDGE       ios_base::sync_with_stdio(0);       cin.tie(0);   #endif // ONLINE_JUDGE       cin >> n;       vector<string> vs(n);       map<vector<int>, vector<string>> mp;       f(i,0,n)    cin >> vs[i], mp[getF(vs[i])].pb(vs[i]);          ll ans = 0, cur = 0;       for(auto it : mp){           auto v= it.second;           ans += 1337ll * cur * v.size();           cur += v.size();              ans += solve(v);       }          cout << ans << endl;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int qmul(int a, int b) {     a = (a % mod + mod) % mod;     b = (b % mod + mod) % mod;     int ans = 0;     while (b) {       if (b & 1) ans = (ans + a) % mod;       a = (a << 1) % mod;       b >>= 1;     }     return ans;   }   int qpow(int a, int p) {     int ans = 1;     while (p) {       if (p & 1) ans = qmul(ans, a);       a = qmul(a, a);       p >>= 1;     }     return ans;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n, a, p = 0, q = 1;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       p = qmul((p + q) % mod, 100);       q = qmul(q, a);       int r = gcd(p, q);       p = p / r;       q = q / r;     }     cout << qmul(p, qpow(q, mod - 2)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111;   const long double Eps = 1e-6;   int sgn(long double a, long double b = 0) {     a -= b;     return (a > Eps) - (a < -Eps);   }   const long double Pi = 4 * atan(1);   struct Point {     long double x, y;     Point operator-(Point p) { return {x - p.x, y - p.y}; }     Point operator+(Point p) { return {x + p.x, y + p.y}; }     Point operator/(long double d) { return {x / d, y / d}; }     bool operator<(Point p) const {       if (sgn(x, p.x) == 0) return sgn(y, p.y) < 0;       return sgn(x, p.x) < 0;     }     Point rot(long double d) {       long double rx = x * cos(d) - y * sin(d);       long double ry = x * sin(d) + y * cos(d);       return {rx, ry};     }     long double len2() { return x * x + y * y; }     long double len() { return sqrt(len2()); }     long double dot(Point p) { return x * p.x + y * p.y; }     long double cross(Point p) { return x * p.y - y * p.x; }   } p[N];   long double xmul(Point a, Point b, Point c) { return (b - a).cross(c - a); }   Point inter(Point p1, Point p2, Point q1, Point q2) {     long double u = xmul(p1, p2, q1);     long double v = xmul(p2, p1, q2);     long double rx = (q1.x * v + q2.x * u) / (v + u);     long double ry = (q1.y * v + q2.y * u) / (v + u);     return {rx, ry};   }   class Cmp {    public:     bool operator()(long double a, long double b) const { return sgn(a, b) < 0; }   };   int main() {     ios ::sync_with_stdio(false);     int n;     cin >> n;     set<Point> st;     for (int i = 0; i < n; i++) {       cin >> p[i].x >> p[i].y;       st.insert(p[i]);     }     bool found = false;     long double ans = 0;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         for (int k = j + 1; k < n; k++) {           if (sgn((p[j] - p[i]).dot(p[k] - p[i])) > 0 &&               sgn((p[k] - p[j]).dot(p[i] - p[j])) > 0 &&               sgn((p[i] - p[k]).dot(p[j] - p[k])) > 0) {             Point mij = (p[i] + p[j]) / 2;             Point dij = (p[i] - p[j]).rot(Pi / 2);             Point mjk = (p[j] + p[k]) / 2;             Point djk = (p[j] - p[k]).rot(Pi / 2);             Point o = inter(mij, mij + dij, mjk, mjk + djk);             bool flag = true;             for (int r = 0; r < n; r++)               if (sgn((p[r] - o).len2(), (p[i] - o).len2()) < 0) flag = false;             if (flag) {               found = true;               ans = max(ans, (p[i] - o).len());             }           }         }     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         Point mij = (p[i] + p[j]) / 2;         Point dij = (p[j] - p[i]) / 2;         Point pk = mij + dij.rot(Pi / 2);         Point ps = mij - dij.rot(Pi / 2);         if (st.find(pk) != st.end() && st.find(ps) != st.end()) {           Point &o = mij;           bool flag = true;           for (int s = 0; s < n; s++)             if (sgn((p[s] - o).len2(), (p[i] - o).len2()) < 0) flag = false;           if (flag) {             found = true;             ans = max(ans, (p[i] - o).len());           }         }       }     if (!found)       cout << -1 <<   n ;     else       cout << setprecision(6) << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void mf() { freopen( input.in ,  r , stdin); }   int a[1007];   int n, k;   map<int, int> mm;   queue<int> q;   bool f(map<int, int>& _mm, int x) { return _mm.find(x) != _mm.end(); }   void solve() {     int m;     n = 0;     cin >> k >> m;     int x;     for (int i = 1; i <= m; i++) {       cin >> x;       x -= k;       if (!f(mm, x)) {         mm[x] = 1;         n++;         a[n] = x;         q.push(x);       }     }     while (!f(mm, 0) && !q.empty()) {       x = q.front();       q.pop();       for (int i = 1; i <= n; i++) {         int nx = x + a[i];         if (nx > 1000 || nx < -1000) continue;         if (!f(mm, nx)) {           mm[nx] = mm[x] + 1;           q.push(nx);         }       }     }     if (f(mm, 0)) {       cout << mm[0];     } else {       cout << -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int> > g[100010];   long long dist[100010];   bool mark[100010];   int req[100010];   void dijkstra(int n) {     memset(mark, 0, sizeof(mark));     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     pq.push(make_pair(dist[n], n));     while (!pq.empty()) {       int u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = true;       for (int i = 0; i < g[u].size(); i++) {         pair<int, int> v = g[u][i].first;         int t = g[u][i].second;         if (dist[v.first] > dist[u] + v.second) {           dist[v.first] = dist[u] + v.second;           pq.push(make_pair(dist[v.first], v.first));           req[v.first] = t;         } else if (t == -1 && dist[v.first] == dist[u] + v.second) {           dist[v.first] = dist[u] + v.second;           req[v.first] = t;         }       }     }   }   int main(int argc, char const *argv[]) {     for (int i = 0; i < 100010; i++) dist[i] = 1LL << 60;     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     while (m--) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       g[x].push_back({{y, z}, -1});       g[y].push_back({{x, z}, -1});     }     dist[1] = 0;     dijkstra(1);     int ans = 0;     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[1].push_back({{x, y}, i + 1});       g[x].push_back({{1, y}, i + 1});     }     dijkstra(1);     for (int i = 1; i <= n; i++) {       if (req[i] > 0) ans++;     }     ans = k - ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c1, c2, c3, c4;   int a[1111], b[1111];   int n, m;   int main() {     while (cin >> c1 >> c2 >> c3 >> c4) {       cin >> n >> m;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < m; i++) cin >> b[i];       int mi = min(c4, 2 * c3);       int nm = c3;       for (int i = 0; i < n; i++) nm += min(c1 * a[i], c2);       mi = min(mi, nm);       nm = c3;       for (int i = 0; i < m; i++) nm += min(c1 * b[i], c2);       mi = min(mi, nm);       nm = 0;       for (int i = 0; i < n; i++) nm += min(c1 * a[i], c2);       for (int i = 0; i < m; i++) nm += min(c1 * b[i], c2);       mi = min(mi, nm);       cout << mi << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k1, k2, m1 = INT_MIN, m2 = INT_MIN, tmp;       cin >> n >> k1 >> k2;       for (long long int i = 0; i < k1; i++) {         cin >> tmp;         m1 = max(m1, tmp);       }       for (long long int i = 0; i < k2; i++) {         cin >> tmp;         m2 = max(m2, tmp);       }       if (m1 > m2) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long power(long long x, int y) {     long long res = 1;     x = x % mod;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res;   }   int modInverse(long long a) { return power(a, mod - 2); }   long long factmod(long long a) {     long long val = 1;     while (a > 0) {       val = (val * a) % mod;       a--;     }     return val;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, ans;     cin >> n >> m;     ans = (factmod(n + 2 * m - 1) * modInverse(factmod(2 * m)) % mod *            modInverse(factmod(n - 1) % mod)) %           mod;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   template <typename T>   inline void read(T& x) {     x = 0;     T f = 1;     char ch = getchar();     while (!isdigit(ch)) f = (ch ==  - ) ? -1 : 1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();     x *= f;   }   template <typename T, typename... Args>   inline void read(T& x, Args&... args) {     read(x), read(args...);   }   constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7;   int n, cnt;   array<int, MAXN> a;   array<vector<pair<int, int>>, MAXN> p;   vector<int> id[4];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int high = n + 1;     for (int i = n; i >= 1; i--) {       if (a[i] == 0)         continue;       else if (a[i] == 1) {         if (high < 1) return cout << -1 <<   n , 0;         p[i].emplace_back(i, --high), id[1].push_back(i), cnt++;       } else if (a[i] == 2) {         if (id[1].size() == 0) return cout << -1 <<   n , 0;         int tmp = id[1].back();         id[1].pop_back();         p[i].emplace_back(i, p[tmp][0].second);         id[2].push_back(i), cnt++;       } else {         if (id[3].size()) {           int tmp = id[3].back();           id[3].pop_back();           if (high < 1) return cout << -1 <<   n , 0;           p[i].emplace_back(i, --high);           p[i].emplace_back(p[tmp][0].first, high);         } else if (id[2].size()) {           int tmp = id[2].back();           id[2].pop_back();           if (high < 1) return cout << -1 <<   n , 0;           p[i].emplace_back(i, --high);           p[i].emplace_back(p[tmp][0].first, high);         } else if (id[1].size()) {           int tmp = id[1].back();           id[1].pop_back();           if (high < 1) return cout << -1 <<   n , 0;           p[i].emplace_back(i, --high);           p[i].emplace_back(p[tmp][0].first, high);         } else           return cout << -1 <<   n , 0;         id[3].push_back(i);         cnt += 2;       }     }     cout << cnt <<   n ;     for (int i = n; i >= 1; i--)       for (auto& j : p[i]) cout << j.second <<     << j.first <<   n ;     return 0;   }


#include <bits/stdc++.h>   const long long MOD = 1e9 + 7;   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     while (n--) {       long long ci, sum;       cin >> ci >> sum;       long long n = sum / ci;       long long rem = sum % ci;       long long ans = rem * (pow(n + 1, 2));       ci -= rem;       ans += ci * (pow(n, 2));       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int id, a;     data() {}     data(int id, int a) : id(id), a(a) {}     bool operator<(const data &r) const { return a < r.a; }   } da[100010];   int n, h;   int main() {     scanf( %d%d , &n, &h);     for (int i = 0; i < n; i++) scanf( %d , &da[i].a), da[i].id = i;     if (n == 2) {       printf( 0 n );       for (int i = 0; i < n; i++) printf( 1  );       puts(  );       return 0;     }     sort(da, da + n);     int f1 = da[n - 1].a + da[n - 2].a - da[0].a - da[1].a;     int f2 = max(da[n - 1].a + da[0].a + h, da[n - 1].a + da[n - 2].a) -              min(da[0].a + da[1].a + h, da[1].a + da[2].a);     if (f1 <= f2) {       printf( %d n , f1);       for (int i = 0; i < n; i++) printf( 1  );       puts(  );     } else {       printf( %d n , f2);       for (int i = 0; i < n; i++)         if (da[0].id == i)           printf( 1  );         else           printf( 2  );       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1605;   int n, m, tot;   int a[MAXN][MAXN];   int sz[MAXN * MAXN];   int ans[MAXN * MAXN];   int cnt[MAXN * MAXN];   int fa1[MAXN * MAXN];   int fa2[MAXN * MAXN];   double v[MAXN][MAXN];   double t[MAXN][MAXN];   int getroot(int *fa, int u) {     return u == fa[u] ? u : fa[u] = getroot(fa, fa[u]);   }   void run() {     memcpy(t, v, sizeof(t));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j]) {           double sum = 0, cnt = 0;           for (int k = i - 4; k <= i + 4; k++)             for (int l = j - 4; l <= j + 4; l++)               if (k >= 1 && k <= n && l >= 1 && l <= m &&                   (i - k) * (i - k) + (j - l) * (j - l) <= 25)                 sum += t[k][l], cnt++;           v[i][j] = sum / cnt;         }   }   void merge(int *fa, int xa, int ya, int xb, int yb) {     if (!a[xa][ya] || !a[xb][yb]) return;     fa[getroot(fa, (xa - 1) * m + ya)] = getroot(fa, (xb - 1) * m + yb);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         fa1[(i - 1) * m + j] = fa2[(i - 1) * m + j] = (i - 1) * m + j;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j]) {           v[i][j] = 1;           if (i > 1) merge(fa1, i, j, i - 1, j);           if (i < n) merge(fa1, i, j, i + 1, j);           if (j > 1) merge(fa1, i, j, i, j - 1);           if (j < m) merge(fa1, i, j, i, j + 1);         }     run();     run();     run();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && v[i][j] < 0.2) {           if (i > 1 && v[i - 1][j] < 0.2) merge(fa2, i, j, i - 1, j);           if (i < n && v[i + 1][j] < 0.2) merge(fa2, i, j, i + 1, j);           if (j > 1 && v[i][j - 1] < 0.2) merge(fa2, i, j, i, j - 1);           if (j < m && v[i][j + 1] < 0.2) merge(fa2, i, j, i, j + 1);         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && v[i][j] < 0.2) sz[getroot(fa2, (i - 1) * m + j)]++;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && v[i][j] < 0.2 &&             getroot(fa2, (i - 1) * m + j) == (i - 1) * m + j &&             sz[(i - 1) * m + j] >= 5)           cnt[getroot(fa1, (i - 1) * m + j)]++;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && getroot(fa1, (i - 1) * m + j) == (i - 1) * m + j)           ans[++tot] = cnt[(i - 1) * m + j];     sort(ans + 1, ans + tot + 1);     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5555;   const long long INF = 1e9 + 19;   int n;   int a[N][3];   bool can[N][3];   int sumH[3];   int cando[3];   void read() {     scanf( %d , &n);     vector<vector<int> > tmp;     tmp.resize(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         int x;         scanf( %d , &x);         tmp[i].push_back(x);       }     }     sort(tmp.begin() + 1, tmp.end(), [](vector<int> a, vector<int> b) {       int fa = 0, fb = 0;       for (auto x : a) fa += x < 0;       for (auto x : b) fb += x < 0;       return fa > fb;     });     for (int i = 0; i < n; i++)       for (int j = 0; j < 3; j++) {         if (tmp[i][j] < 0) can[i][j] = 1;         a[i][j] = abs(tmp[i][j]);       }   }   int sum[3];   int f[10];   int cost[10];   int tmp[3];   int hack[N];   int calcScore(int id, int mask, int g1, int g2, int g3) {     tmp[0] = g1;     tmp[1] = g2;     tmp[2] = g3;     int sum = 0;     for (int i = 0; i < 3; i++) {       if (a[id][i] != 0 && (((mask >> i) & 1) == 0))         sum += (cost[tmp[i]] / 250) * (250 - a[id][i]);     }     return sum;   }   void upd(int& a, int b) { a = min(a, b); }   int preCost[N][3];   void solve() {     cost[1] = 500;     cost[2] = 1000;     cost[3] = 1500;     cost[4] = 2000;     cost[5] = 2500;     cost[6] = 3000;     for (int i = 0; i < n; i++)       for (int j = 0; j < 3; j++) {         hack[i] |= (can[i][j] << j);         if (a[i][j] > 0) {           preCost[i][j] = 2 * (250 - a[i][j]);         }       }     for (int i = 0; i < n; i++)       for (int j = 0; j < 3; j++) {         sum[j] += a[i][j] != 0;         sumH[j] += can[i][j];       }     int total = 0;     for (int j = 0; j < 3; j++) total += sumH[j];     if (total > 90) {       puts( 1 );       return;     }     f[0] = n + 1;     f[1] = n / 2 + 1;     f[2] = n / 4 + 1;     f[3] = n / 8 + 1;     f[4] = n / 16 + 1;     f[5] = n / 32 + 1;     f[6] = 0;     int mainCur = 1;     for (; mainCur < n && hack[mainCur] > 0; mainCur++)       ;     int answer = n;     for (int g1 = 1; g1 <= 6; g1++)       for (int g2 = 1; g2 <= 6; g2++)         for (int g3 = 1; g3 <= 6; g3++) {           int g[3];           g[0] = g1;           g[1] = g2;           g[2] = g3;           int l[3];           int r[3];           bool flag1 = 1;           for (int i = 0; i < 3; i++) {             r[i] = sum[i] - f[g[i]];             l[i] = sum[i] - (f[g[i] - 1] - 1);             r[i] = min(r[i], sumH[i]);             l[i] = max(0, l[i]);             if (r[i] < l[i]) {               flag1 = 0;             }           }           if (!flag1) continue;           int h0 = r[0];           int h1 = r[1];           int h2 = r[2];           if (h0 < 0 || h1 < 0 || h2 < 0) continue;           vector<vector<vector<vector<int> > > > dp(mainCur + 1);           for (int i = 0; i <= mainCur; i++)             dp[i].resize(h0 + 1,                          vector<vector<int> >(h1 + 1, vector<int>(h2 + 1, INF)));           dp[1][0][0][0] = 0;           int myScore = calcScore(0, 0, g1, g2, g3) + (h0 + h1 + h2) * 100;           assert(h0 + h1 + h2 <= 90);           for (int i = 1; i < mainCur; i++) {             for (int x = 0; x <= h0; x++)               for (int y = 0; y <= h1; y++)                 for (int z = 0; z <= h2; z++) {                   if (dp[i][x][y][z] >= INF) continue;                   for (int mask = 0; mask < 8; mask++) {                     bool flag = 1;                     for (int j = 0; j < 3; j++)                       if (((mask >> j) & 1) == 1 && can[i][j] == 0) flag = 0;                     if (!flag) continue;                     int res = calcScore(i, mask, g1, g2, g3);                     int x1 = x;                     int y1 = y;                     int z1 = z;                     if (((mask >> 0) & 1)) x1++;                     if (((mask >> 1) & 1)) y1++;                     if (((mask >> 2) & 1)) z1++;                     if (x1 > h0 || y1 > h1 || z1 > h2) continue;                     if (res > myScore) {                       upd(dp[i + 1][x1][y1][z1], dp[i][x][y][z] + 1);                     } else {                       upd(dp[i + 1][x1][y1][z1], dp[i][x][y][z]);                     }                   }                 }           }           int cc = 0;           for (int i = mainCur; i < n; i++) {             assert(hack[i] == 0);             int res = 0;             for (int j = 0; j < 3; j++) res += preCost[i][j] * g[j];             cc += res > myScore;           }           for (int x = l[0]; x <= r[0]; x++)             for (int y = l[1]; y <= r[1]; y++)               for (int z = l[2]; z <= r[2]; z++) {                 answer = min(answer, dp[mainCur][x][y][z] + cc);               }         }     printf( %d n , answer + 1);   }   void stress() {}   int main() {     if (1) {       int k = 1;       for (int tt = 0; tt < k; tt++) {         read();         solve();       }     } else {       stress();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n;     x = (n + 1) / 2;     string s, even, odd;     cin >> s;     for (int i = 0; i < n; i++) {       if (i % 2 == 0)         odd.push_back(s[i]);       else         even.push_back(s[i]);     }     if (n <= 2) {       cout << s << endl;     } else {       if (n % 2 == 0) {         reverse(odd.begin(), odd.end());         for (int i = 0; i < x; i++) {           odd.push_back(even[i]);         }         even = odd;       } else if (n % 2 == 1) {         reverse(even.begin(), even.end());         for (int i = 0; i < x; i++) {           even.push_back(odd[i]);         }       }       cout << even << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long modl = 1000000007;   int farr[1000000];   int pre[1000000];   int cum[1000000];   unsigned long long poow(int base, int po);   void swaap(int *a, int *b);   long long gcd(long long a, long long b);   void mul_big_int(string s1, string s2);   int cnt_prime(int n);   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n, l, r, cntr = 0, sum = 0, num = 0;     long long x;     int maxi = INT_MIN, mini = INT_MAX;     cin >> n >> l >> r >> x;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         int r;         r = i & (1 << j);         if (r) {           cntr++;           sum += arr[j];           maxi = max(maxi, arr[j]);           mini = min(mini, arr[j]);         }       }       if (cntr >= 2) {         if (sum >= l && sum <= r) {           if (maxi - mini >= x) num++;         }       }       cntr = 0;       maxi = INT_MIN;       mini = INT_MAX;       sum = 0;     }     cout << num <<   n ;     return 0;   }   unsigned long long poow(int base, int po) {     if (po == 0) return 1;     if (po == 1) return base;     unsigned long long ans = poow(base, po / 2);     ans = (ans * ans);     if (po & 1) return (ans * base);     return ans;   }   void swaap(int *a, int *b) {     int temp;     temp = *a;     *a = *b;     *b = temp;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void mul_big_int(string s1, string s2) {     reverse(s1.begin(), s1.end());     reverse(s2.begin(), s2.end());     int mul[1000];     memset(mul, 0, sizeof(mul));     long long ln1 = s1.length(), ln2 = s2.length();     for (int i = 0; i < ln1; i++) {       for (int j = 0; j < ln2; j++) {         mul[i + j] += ((s1[i] -  0 ) * (s2[j] -  0 ));       }     }     for (int i = 0; i < 1000; i++) {       mul[i + 1] += mul[i] / 10;       mul[i] %= 10;     }     int i = 999;     while (i > 0 && mul[i] == 0) i--;     for (; i >= 0; i--) {       cout << mul[i];     }     cout << endl;   }   int cnt_prime(int n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     for (long long i = 2; i * i <= n; i++) {       if (prime[i]) {         for (int j = i * i; j <= n; j += i) prime[j] = 0;       }     }     int cntr = 0;     for (int i = 0; i < (int)prime.size(); i++) {       if (prime[i]) cntr++;     }     return cntr;   }


#include <bits/stdc++.h>   const long long int INF = 1e15;   using namespace std;   const long long int MAX = 1e7 + 5;   const long long int mod = 1e9 + 7;   long long int gcd(long long int a, long long int b) {     while (b > 0) {       a = a % b;       swap(a, b);     }     return a;   }   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b % 2 == 1) res = res * a % mod;       a = a * a % mod;       b /= 2;     }     return res % mod;   }   void solve() {     long long int n;     cin >> n;     long long int ans = 3 * n * n - 2 + 3 * (n - 1) * (n - 1);     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     for (long long int i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 81;   const int M = 2001;   int n, k, m, ans = 1e9;   int cache[N][2][N][N];   vector<pair<int, int> > g[N];   int dp(int idx, int dir, int dist, int taken) {     if (taken == k) return 0;     int &ans = cache[idx][dir][dist][taken];     if (ans != -1) return ans;     ans = 1e9;     for (auto &it : g[idx]) {       if (abs(it.first - idx) <= dist) {         if ((it.first - idx > 0 && dir > 0) || (idx - it.first > 0 && dir == 0)) {           ans = min(               ans,               it.second +                   min(dp(it.first, dir, dist - abs(it.first - idx), taken + 1),                       dp(it.first, dir ^ 1, abs(it.first - idx) - 1, taken + 1)));         }       }     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(cache, -1, sizeof(cache));     cin >> n >> k >> m;     for (int i = 1; i <= m; i++) {       int u, v, c;       cin >> u >> v >> c;       g[u].push_back({v, c});     }     for (int i = 1; i <= n; i++)       ans = min(ans, min(dp(i, 1, n - i, 1), dp(i, 0, i - 1, 1)));     if (ans > 1e8) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool next_n(vector<int> &a) {     int i = n - 1;     for (; i >= 0 && a[i] == 5; --i) {       a[i] = 0;     }     if (i == -1) {       return false;     }     ++a[i];     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int m;     cin >> n >> m;     vector<vector<int>> graph(n);     int from, to;     for (int i = 0; i < m; ++i) {       cin >> from >> to;       --from;       --to;       graph[from].push_back(to);       graph[to].push_back(from);     }     vector<int> ns(n);     int answ = 0;     do {       set<pair<int, int>> ps;       for (int i = 0; i < n; ++i) {         for (int j : graph[i]) {           int a = ns[i];           int b = ns[j];           if (a > b) {             swap(a, b);           }           ps.emplace(a, b);         }       }       answ = max(answ, (int)ps.size());     } while (next_n(ns));     cout << answ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Value>   class feque {    protected:     vector<Value> data;       public:     feque() {}     feque(const feque &f) { data = f.data; }     feque(feque &&f) { this->data = move(f.data); }     feque(initializer_list<Value> list) { data = list; }     feque &operator=(const feque &f) {       data = f.data;       return *this;     }     feque &operator=(feque &&f) {       this->data = move(f.data);       return *this;     }     feque &operator=(initializer_list<Value> list) {       data = list;       return *this;     }     bool empty() const { return data.empty(); }     size_t size() { return data.size(); }     Value &front() { return data.back(); }     const Value &front() const { return data.back(); }     Value &back() { return data.front(); }     const Value &back() const { return data.front(); }     void push(const Value &value) { data.push_back(value); }     void pop() { data.pop_back(); }     typename vector<int>::reverse_iterator begin() { return data.rbegin(); }     typename vector<int>::reverse_iterator end() { return data.rend(); }     Value &operator[](const int &index) { return data[data.size() - 1 - index]; }   };   const int MAX_N = 1e6;   const int ROOT = 1;   int n;   array<vector<int>, MAX_N + 1> adjacency_list;   array<feque<int>, MAX_N + 1> depth_array;   array<int, MAX_N + 1> dominant_index;   void make_adjacent(const int &v, const int &u) {     adjacency_list[v].push_back(u);     adjacency_list[u].push_back(v);   }   bool has_child(const int &vertex) {     return (vertex != ROOT and adjacency_list[vertex].size() > 1) or            (vertex == ROOT and not adjacency_list[ROOT].empty());   }   void compute_depth_array(const int &vertex, const int &parent = -1) {     int deepest_child;     if (has_child(vertex)) {       deepest_child = -1;       for (const int &adjacent : adjacency_list[vertex]) {         if (adjacent != parent) {           compute_depth_array(adjacent, vertex);           if (deepest_child == -1 or               depth_array[deepest_child].size() < depth_array[adjacent].size())             deepest_child = adjacent;         }       }       dominant_index[vertex] =           (depth_array[deepest_child][dominant_index[deepest_child]] > 1                ? dominant_index[deepest_child] + 1                : 0);       swap(depth_array[vertex], depth_array[deepest_child]);       depth_array[vertex].push(1);       for (const int &adjacent : adjacency_list[vertex]) {         if (adjacent != parent and adjacent != deepest_child) {           for (int depth = 1; depth <= depth_array[adjacent].size(); ++depth) {             depth_array[vertex][depth] += depth_array[adjacent][depth - 1];             if (depth_array[vertex][depth] >                     depth_array[vertex][dominant_index[vertex]] or                 (depth_array[vertex][depth] ==                      depth_array[vertex][dominant_index[vertex]] and                  depth < dominant_index[vertex])) {               dominant_index[vertex] = depth;             }           }         }       }     } else {       depth_array[vertex] = {1};       dominant_index[vertex] = 0;     }   }   void optimize_IO() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   int main() {     optimize_IO();     cin >> n;     for (int i = 1; i <= n - 1; ++i) {       int x, y;       cin >> x >> y;       make_adjacent(x, y);     }     compute_depth_array(ROOT);     for (int vertex = 1; vertex <= n; ++vertex)       cout << dominant_index[vertex] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     string input;     cin >> input;     int i = 0;     if (input[0] ==  9 ) ++i;     for (; i < input.length(); ++i) {       if (input[i] >=  5 ) {         input[i] =  0  +  9  - input[i];       }     }     for (int j = 0; j < input.length(); ++j) {       cout << input[j];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char arr[21];   char brr[21];   int player1[100];   int player2[100];   int main() {     char z;     cin >> arr;     cin >> brr;     memset(player1, 0, sizeof(player1));     memset(player2, 0, sizeof(player2));     int n, t, d, i, f, m;     char p, s;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t >> p >> d >> s;       if (p ==  a ) {         if (player1[d] == 0 && s ==  y ) {           f = t;           player1[d]++;         } else if (s =  r  && player1[d] < 2) {           cout << brr <<     << d <<     << t <<   n ;           player1[d] = 5;         } else if (player1[d] == 1 && s ==  y ) {           if (t < f) t = f;           cout << brr <<     << d <<     << t <<   n ;           player1[d] = 5;         }       } else {         if (player2[d] == 0 && s ==  y ) {           m = t;           player2[d]++;         } else if (s =  r  && player2[d] < 2) {           cout << arr <<     << d <<     << t <<   n ;           player2[d] = 5;         } else if (player2[d] == 1 && s ==  y ) {           if (m > t) t = m;           cout << arr <<     << d <<     << t <<   n ;           player2[d] = 5;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     return os <<  (  << v.first <<  ,   << v.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {       if (i) os <<  ,  ;       os << v[i];     }     return os <<  ] ;   }   template <class T>   bool setmax(T& _a, T _b) {     if (_a < _b) {       _a = _b;       return true;     }     return false;   }   template <class T>   bool setmin(T& _a, T _b) {     if (_b < _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   T gcd(T _a, T _b) {     return _b == 0 ? _a : gcd(_b, _a % _b);   }   int main() {     int n, k;     cin >> n >> k;     if (n <= 3 || (n == 4 && k == 2) || (k != 2 && k != 3)) {       printf( -1 n );     } else {       if (k == 2) {         printf( %d n , 3 + (n - 4) * 2);         printf( 1 2 n );         printf( 2 3 n );         printf( 3 4 n );         for (int i = int(5); i <= int(n); ++i) {           printf( %d 1 n , i);           printf( %d 4 n , i);         }       } else {         printf( %d n , 1 + (n - 3) * 2);         printf( 1 2 n );         for (int i = int(4); i <= int(n); ++i) {           printf( %d 2 n , i);           printf( %d 3 n , i);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   char t[1000];   int main() {     string s, sa;     stack<int> sta;     int i, j;     while (cin >> sa) {       s += sa;     }     int cnt = 0;     for (i = 0; i < s.length(); i++) {       if (s[i] !=  < ) continue;       i++;       for (j = 0; i < s.length() && s[i] !=  > ; i++, j++) {         t[j] = s[i];       }       t[j] =   0 ;       if (strcmp(t,  table ) == 0) {         sta.push(0);       } else if (strcmp(t,  /table ) == 0) {         a[cnt++] = sta.top();         sta.pop();       } else if (strcmp(t,  /td ) == 0) {         sta.top()++;       }     }     sort(a, a + cnt);     for (i = 0; i < cnt - 1; i++) cout << a[i] <<    ;     cout << a[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<double> > M, I;   vector<vector<double> > M2[15];   int X[203], Y[203];   int sz = 0;   map<pair<int, int>, int> mp;   map<pair<pair<int, int>, int>, int> conv;   vector<int> vec[40003];   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   vector<vector<double> > operator*(vector<vector<double> > A,                                     vector<vector<double> > B) {     vector<vector<double> > C =         vector<vector<double> >(A.size(), vector<double>(B[0].size(), 0));     for (int i = 1; i < A.size(); i++)       for (int j = 1; j < B[0].size(); j++)         for (int k = 1; k < B.size(); k++) C[i][j] += A[i][k] * B[k][j];     return C;   }   vector<vector<double> > pwr(vector<vector<double> > A, int b) {     if (!b)       return I;     else if (b == 1)       return A;     else if (b == 2)       return A * A;     else if (b & 1)       return pwr(A, b - 1) * A;     else       return pwr(pwr(A, b / 2), 2);   }   void print(vector<vector<double> > X) {     for (int i = 1; i < X.size(); i++) {       for (int j = 1; j < X[i].size(); j++) printf( %.8lf  , X[i][j]);       printf(  n );     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &X[i], &Y[i]);     M.assign(n + 1, vector<double>(n + 1, 0));     I.assign(n + 1, vector<double>(n + 1, 0));     for (int i = 1; i <= n; i++) {       I[i][i] = 1;       mp.clear();       for (int j = 1; j <= n; j++) {         if (j == i) continue;         int x = X[j] - X[i];         int y = Y[j] - Y[i];         if (x < 0) x = -x, y = -y;         pair<int, int> m;         if (x == 0)           m = {1, 0};         else if (y == 0)           m = {0, 1};         else           m = {y / gcd(x, abs(y)), x / gcd(x, abs(y))};         mp[m]++;       }       for (int j = 1; j <= n; j++) {         if (j == i) continue;         int x = X[j] - X[i];         int y = Y[j] - Y[i];         if (x < 0) x = -x, y = -y;         pair<int, int> m;         if (x == 0)           m = {1, 0};         else if (y == 0)           m = {0, 1};         else           m = {y / gcd(x, abs(y)), x / gcd(x, abs(y))};         M[i][j] = (1.0 / mp.size()) * 1.0 / (1.0 + mp[m]);       }       for (auto x : mp) M[i][i] += (1.0 / mp.size()) * 1.0 / (1.0 + x.second);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         int a = X[j] - X[i];         int b = Y[j] - Y[i];         if (a < 0) a = -a, b = -b;         int fpb = gcd(a, abs(b));         pair<int, int> m;         if (a == 0)           m = {1, 0};         else if (b == 0)           m = {0, 1};         else           m = {b / fpb, a / fpb};         if (fpb) {           a /= fpb;           b /= fpb;         }         int c = a * Y[i] - b * X[i];         if (conv.find({m, c}) == conv.end()) {           conv[{m, c}] = ++sz;           int idx = conv[{m, c}];           for (int k = 1; k <= n; k++)             if (a * Y[k] == b * X[k] + c) vec[idx].push_back(k);         }       }     }     M2[0] = M;     for (int i = 1; i < 15; i++) M2[i] = M2[i - 1] * M2[i - 1];     int q;     scanf( %d , &q);     while (q--) {       int x, m;       scanf( %d %d , &x, &m);       vector<vector<double> > s =           vector<vector<double> >(n + 1, vector<double>(2, 0));       s[x][1] = 1;       for (int i = 0; i < 15; i++)         if ((m - 1) & (1 << i)) s = M2[i] * s;       double mx = 0;       for (int i = 1; i <= sz; i++) {         double sum = 0;         for (auto j : vec[i]) sum += s[j][1];         sum *= 1.0 / vec[i].size();         mx = max(mx, sum);       }       printf( %.9lf n , mx);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(const T& a) {     return a * a;   }   template <typename T>   inline int sign(const T& a) {     return a < 0 ? -1 : a > 0;   }   void task();   int main() {     ios_base::sync_with_stdio(0);     task();     return 0;   }   int h, q;   long long int l, r;   vector<pair<long long, long long> > bad;   vector<pair<long long, long long> > ok;   void task() {     cin >> h >> q;     long long int start = 1;     for (int i = 1; i < h; ++i) start *= 2;     l = start;     r = start * 2 - 1;     while (q--) {       long long int i;       long long int _l, _r, ans;       cin >> i >> _l >> _r >> ans;       while (_l < start) _l *= 2;       while (_r < start) _r *= 2, ++_r;       if (ans) {         if (_l > r || _r < l) {           cout <<  Game cheated! ;           return;         }         l = max(l, _l);         r = min(r, _r);         ok.push_back(pair<long long, long long>{_l, _r});       } else {         bad.push_back(pair<long long, long long>{_l, _r});       }     }     bad.push_back(pair<long long, long long>{-2, -2});     bad.push_back(pair<long long, long long>{4 * start, 4 * start});     sort((bad.begin()), (bad.end()));     vector<pair<long long, long long> > v;     pair<long long, long long> cur = bad[0];     for (int i = 1; i < (int)bad.size(); ++i) {       pair<long long, long long> x = bad[i];       if (x.first <= cur.second + 1) {         cur.second = max(cur.second, x.second);       } else {         v.push_back(cur);         cur = x;       }     }     v.push_back(cur);     bad = v;     vector<pair<long long, long long> > well;     long long int sum = 0;     for (int i = 1; i < bad.size(); ++i) {       long long int ll = max(bad[i - 1].second, l - 1);       long long int rr = min(r + 1, bad[i].first);       long long int len = rr - ll - 1;       if (len > 0) {         well.push_back(pair<long long, long long>{ll + 1, rr - 1});         sum += len;       }     }     if (sum == 0) {       cout <<  Game cheated! ;     } else if (sum == 1) {       assert(well.front().first == well.front().second);       assert(well.size() == 1);       cout << well.front().first;     } else {       cout <<  Data not sufficient! ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp[11];   const int N = 2e5 + 5;   int ws(int u) { return (int)log10(u) + 1; }   int n, k, a[N], mo[11][N];   long long ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       mo[0][i] = a[i] % k;       for (int j = 1; j <= 10; j++) {         mo[j][i] = (int)(((long long)mo[j - 1][i] * 10) % k);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 10; j++) {         if (mo[j][i]) {           mp[j][mo[j][i]]++;         } else {           mp[j][0]++;         }       }     }     for (int i = 1; i <= n; i++) {       int w = ws(a[i]);       if (mo[0][i]) {         ans += mp[w][k - mo[0][i]];       } else {         ans += mp[w][0];       }       if ((mo[w][i] + mo[0][i]) % k == 0) {         ans--;       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int gl, bl, br, gr;     cin >> gl >> gr >> bl >> br;     if (br <= (gl + 1) * 2 && br >= gl - 1) {       cout <<  YES ;       return 0;     }     if (bl <= (gr + 1) * 2 && bl >= gr - 1) {       cout <<  YES ;       return 0;     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     int flag = 1;     cin >> str;     int len = str.size();     str[len] =  1 ;     str[len + 1] =  1 ;     for (int i = 0; i < str.size();) {       string temp =   ;       if (str[i] ==  1 ) {         temp = str[i + 1];         if (temp ==  4 ) {           temp += str[i + 2];           if (temp ==  44 ) {             i += 3;           } else {             i += 2;           }         } else {           i++;         }       } else {         flag = 0;         break;       }     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 1e6 + 5;   double q[maxm];   int buf[maxm], len[maxm];   void run_case() {     int n;     cin >> n;     int top = 0;     for (int i = 1; i <= n; ++i) cin >> buf[i];     q[++top] = buf[1], len[1] = 1;     for (int i = 2; i <= n; ++i) {       double now = buf[i];       int nowlen = 1;       while (q[top] > now) {         now = (now * nowlen + q[top] * len[top]) / (nowlen + len[top]);         nowlen += len[top--];       }       q[++top] = now, len[top] = nowlen;     }     for (int i = 1; i <= top; ++i)       for (int j = 0; j < len[i]; ++j) cout << q[i] <<   n ;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cout.setf(ios_base::showpoint);     cout.precision(10);     run_case();     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m = 10000000;   int n;   int a[1000005];   int p[10000005];   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int get(int x) { return p[x] == x ? x : p[x] = get(p[x]); }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       p[a[i]] = a[i];     }     int k = n;     int x, y;     for (long long j = 1; j <= m; j++)       for (long long i = j + 1; 2 * i * j <= m && i * i - j * j <= m; i++)         if (gcd(2 * i * j, i * i - j * j) == 1) {           x = 2 * i * j;           y = i * i - j * j;           if (p[x] != 0 && p[y] != 0) {             x = get(x);             y = get(y);             if (x != y) {               k--;               p[x] = y;             }           }           if (i * i + j * j <= m) {             x = 2 * i * j;             y = i * i + j * j;             if (p[x] != 0 && p[y] != 0) {               x = get(x);               y = get(y);               if (x != y) {                 k--;                 p[x] = y;               }             }           }           if (i * i + j * j <= m) {             x = i * i + j * j;             y = i * i - j * j;             if (p[x] != 0 && p[y] != 0) {               x = get(x);               y = get(y);               if (x != y) {                 k--;                 p[x] = y;               }             }           }         }     cout << k << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1100010;   const double pai = acos(-1.0);   char s[maxn], t[maxn];   int n, m, a[maxn], b[maxn], ans[maxn], fa[maxn][6], rev[maxn], bin[1100010];   struct node {     double a, b;     node(double t0 = 0.0, double t1 = 0.0) {       a = t0;       b = t1;     }   } A[maxn], B[maxn];   node operator+(node a, node b) {     node c;     c.a = a.a + b.a;     c.b = a.b + b.b;     return c;   }   node operator-(node a, node b) {     node c;     c.a = a.a - b.a;     c.b = a.b - b.b;     return c;   }   node operator*(node a, node b) {     node c;     c.a = a.a * b.a - a.b * b.b;     c.b = a.b * b.a + a.a * b.b;     return c;   }   void FFT(node *t, int n, int id) {     int len = bin[n];     for (int i = 0; i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1));     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(t[i], t[rev[i]]);     for (int i = 1; i < n; i <<= 1) {       node Wn;       Wn.a = cos(pai / i);       Wn.b = id * sin(pai / i);       for (int j = 0; j < n; j += (i << 1)) {         node W;         W.a = 1;         W.b = 0;         for (int k = j; k < j + i; k++) {           node t1 = t[k], t2 = t[k + i] * W;           t[k] = t1 + t2;           t[k + i] = t1 - t2;           W = W * Wn;         }       }     }   }   int find(int *f, int x) {     if (f[x] == x) return x;     return f[x] = find(f, f[x]);   }   void solve(int x, int y) {     int len = 1;     while (len <= 2 * (n + m)) len <<= 1;     for (int i = 0; i < len; i++) A[i].a = A[i].b = B[i].a = B[i].b = 0;     for (int i = 0; i < n; i++)       if (s[i] -  a  == x) A[i].a = 1;     for (int i = 0; i < m; i++)       if (t[i] -  a  == y) B[i].a = 1;     reverse(B, B + m);     FFT(A, len, 1), FFT(B, len, 1);     for (int i = 0; i < len; i++) A[i] = A[i] * B[i];     FFT(A, len, -1);     for (int i = m - 1; i < n; i++) {       int temp = (int)(A[i].a / len + 0.5);       if (!temp) continue;       if (find(fa[i], x) != find(fa[i], y)) {         fa[i][fa[i][x]] = fa[i][y];         ans[i]++;       }     }   }   int main() {     for (int i = 0; i <= 20; i++) bin[1 << i] = i;     scanf( %s , s);     scanf( %s , t);     n = strlen(s);     m = strlen(t);     for (int i = 0; i < n; i++)       for (int j = 0; j < 6; j++) fa[i][j] = j;     for (int i = 0; i < 6; i++)       for (int j = 0; j < 6; j++)         if (i != j) solve(i, j);     for (int i = m - 1; i < n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   void file() {}   int main() {     fast();     file();     int n, idx = 0;     cin >> n;     vector<vector<int>> v(n, vector<int>(n));     vector<bool> ans(n, 1);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> v[i][j];         if (v[i][j] == 3) {           ans[i] = 0;           ans[j] = 0;         } else if (v[i][j] == 1)           ans[i] = 0;         else if (v[i][j] == 2)           ans[j] = 0;       }     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (ans[i]) cnt++;     }     cout << cnt << endl;     for (int i = 0; i < n; i++) {       if (ans[i]) cout << i + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void sc(T &x) {     char r;     bool start = false, neg = false;     T ret = 0;     while (true) {       r = getchar();       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && !start) continue;       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && start) break;       if (start) ret *= 10;       start = true;       ret += r -  0 ;     }     if (!neg)       x = ret;     else       x = -ret;   }   template <typename T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     map<int, int> m;     int i, j = 0, k = 0;     i = 6;     while (i--) {       cin >> j;       if (m.find(j) != m.end())         m[j]++;       else         m[j] = 1;     }     i = j = k = 0;     if (m.size() == 1) {       cout <<  Elephant n ;     } else if (m.size() > 3) {       cout <<  Alien n ;     } else if (m.size() == 2) {       for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {         if ((*it).second >= 4) k++;         if ((*it).second == 2) j++;       }       if (k & j) {         cout <<  Elephant n ;       } else if (k) {         cout <<  Bear n ;       } else {         cout <<  Alien n ;       }     } else if (m.size() == 3) {       for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {         if ((*it).second == 4) k++;       }       if (k) {         cout <<  Bear n ;       } else {         cout <<  Alien n ;       }     }   }


#include <bits/stdc++.h>      using namespace std;      void code()   {    int n;    cin>>n;    string s;    cin>>s;       set<char> used;    char last= - ;    bool possible=true;    for(char& c:s)    {     if(c!=last)     {      if(used.find(c)!=used.end())      {       possible=false;       break;      }     }     last=c;     used.insert(c);    }       if(possible)     cout<< YES ;    else     cout<< NO ;    cout<<  n ;   }      int main()   {    ios_base::sync_with_stdio(false);    cin.tie(nullptr);       int t=1;    cin>>t;    for(int tt=1;tt<=t;++tt)    {     code();    }       return 0;   }