#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <class S, class T>   inline S smax(S &l, T r) {     return l = max(l, (S)r);   }   template <class S, class T>   inline S smin(S &l, T r) {     return l = min(l, (S)r);   }   const int N = 1e6 + 10;   int nex[N][26], sz, cnt[N], lvl[N];   inline void In(string &s) {     int now = 0;     for (auto c : s) {       c -=  a ;       if (!nex[now][c]) {         nex[now][c] = ++sz;         lvl[sz] = lvl[now] + 1;       }       now = nex[now][c];     }     cnt[now]++;   }   vector<int> dp[N];   inline int f(int i) { return i * (i - 1) / 2; }   inline void merge(int v, int u) {     vector<int> tmp(dp[v].size() + dp[u].size() - 1);     for (int i = 0; i < (int)dp[v].size(); i++)       for (int j = 0; j < (int)dp[u].size(); j++)         tmp[i + j] = max(tmp[i + j], dp[v][i] + dp[u][j] + i * j * lvl[v]);     dp[v] = tmp;   }   void dfs(int v) {     for (int i = 0; i <= cnt[v]; i++) dp[v].emplace_back(lvl[v] * f(i));     for (int i = 0; i < 26; i++)       if (nex[v][i]) {         dfs(nex[v][i]);         merge(v, nex[v][i]);       }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       In(s);     }     dfs(0);     cout << dp[0][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int inp[100005];   int main() {     int n, a, b;     cin >> n;     int flag = 0;     string str;     for (int i = 0; i < n; i++) {       cin >> str;       int a, b;       cin >> a >> b;       if (a >= 2400 && b > 2400 && b - a > 0) {         flag = 1;       }     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long sum = (a + b + c + d) / 3;     if (sum == a)       cout << sum - b <<     << sum - c <<     << sum - d;     else if (sum == b)       cout << sum - a <<     << sum - c <<     << sum - d;     else if (sum == c)       cout << sum - a <<     << sum - b <<     << sum - d;     else       cout << sum - a <<     << sum - b <<     << sum - c;   }


#include<bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef vector<int> vi;   typedef pair<int, int> pi;      #define rep(i,k,n) for (int i = k; i < n; ++i)   #define repr(i,k,n) for (int i = k; i >= n; --i)      int main()   {       ios_base::sync_with_stdio(false);    cin.tie(NULL);      #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif    int t;    cin >> t;    while (t--)    {     int n; cin >> n;     string r, b;     cin >> r >> b;     int count1 = 0, count2 = 0;     rep(i, 0, n)     {      if (r[i] > b[i])      {       count1++;      }      else if (b[i] > r[i])      {       count2++;      }      else      {       count1++;       count2++;      }     }     if (count1 > count2)     {      cout <<  RED  << endl;     }     else if (count2 > count1)     {      cout <<  BLUE  << endl;     }     else cout <<  EQUAL  << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r;   long long getMin() {     long long ret = 0ll;     for (long long i = 1, p = 1; i <= min(l, n); i++, p *= 2) {       ret += p;     }     ret += max(0ll, (n - l));     return ret;   }   long long getMax() {     long long ret = 0ll, p = 1ll;     for (long long i = 1; i <= min(r, n); i++, p *= 2) {       ret += p;     }     p /= 2ll;     ret += max(0ll, (n - r)) * p;     return ret;   }   int main() {     scanf( %lld %lld %lld , &n, &l, &r);     printf( %lld %lld n , getMin(), getMax());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void solve() {     long long n, i, j;     cin >> n;     long long x[n];     for (i = 0; i < n; i++) {       cin >> x[i];     }     long long m;     cin >> m;     long long y[m];     for (i = 0; i < m; i++) {       cin >> y[i];     }     long long k;     cin >> k;     long long z[k];     for (i = 0; i < k; i++) {       cin >> z[i];     }     long long a, b;     sort(x, x + n);     sort(y, y + m);     sort(z, z + k);     cin >> a >> b;     double r = double(x[n - 1] * sqrt((double(b * y[m - 1])) /                                       double(a * z[0] + b * y[m - 1])));     cout << fixed << setprecision(18) << r <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 2e5 + 10;   const ll inf = 1e18;   const ll MOD = 1e9 + 100;   int n;   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       if (n < 4)         printf( -1 n );       else {         deque<int> q;         q = {3, 1, 4, 2};         for (int i = 5; i <= n; i++) {           if (i % 2) {             q.push_back(i);           } else             q.push_front(i);         }         for (int i = 0; i < q.size(); i++) printf( %d  , q[i]);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > g;   long long vis[200005], w[200005];   long long cycle[200005];   long long taken[200005];   long long s;   void dfs(long long x, long long par) {     vis[x] = 1;     for (long long i = 0; i < g[x].size(); i++) {       long long y = g[x][i];       if (y == par) continue;       if (vis[y] == 1)         cycle[y] = 1, cycle[x] = 1;       else if (vis[y] == 0) {         dfs(y, x);         if (cycle[y] == 1) cycle[x] = 1;       }     }     vis[x] = 2;   }   long long maxi;   long long dfs2(long long x) {     vis[x] = 1;     long long ans = 0, res = 0;     for (long long i = 0; i < g[x].size(); i++) {       long long y = g[x][i];       if (cycle[x] == 1) {         if (!vis[y]) {           if (cycle[y])             ans += dfs2(y);           else {             maxi = max(maxi, dfs2(y));           }         }       } else {         if (!vis[y]) {           res = max(res, dfs2(y));         }       }     }     if (x == s - 1) {       return ans + maxi + w[x];     }     if (cycle[x] == 0) ans += res, maxi = max(maxi, ans + w[x]);     return w[x] + ans;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> v;     for (long long i = 0; i < n; i++) g.push_back(v);     maxi = 0;     for (long long i = 0; i < n; i++) cin >> w[i];     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y), g[y].push_back(x);     }     cin >> s;     dfs(s - 1, -1);     for (long long i = 0; i < n; i++) vis[i] = 0;     cout << dfs2(s - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int &i : a) cin >> i;     int ans = -1, now = 0;     vector<bool> vis(n);     while (now < n) {       ans++;       if (ans % 2)         for (int i = n - 1; i >= 0; i--)           if (!vis[i] && a[i] <= now)             vis[i] = true, now++;           else             ;       else         for (int i = 0; i < n; i++)           if (!vis[i] && a[i] <= now)             vis[i] = true, now++;           else             ;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, el[101];   set<int> st;   int main() {     cin >> n >> k;     for (int i = 1; i < (int)n + 1; ++i) st.insert(i);     set<int>::iterator it = st.begin(), er;     for (int i = 0; i < (int)k; ++i) {       int a;       cin >> a;       int ind = ((a) % (int)(st).size());       for (; ind--;) {         if (++it == st.end()) it = st.begin();       }       cout << *it <<    ;       er = it;       if (++it == st.end()) it = st.begin();       st.erase(er);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 1e18;   const long long int N = 1e5 + 5;   const long long int M = N;   const long long int LG = 19;   long long int n, m;   long long int tim = 0, grp = 1;   long long int u[N], v[N], storecomp[N];   long long int level[N];   bool vis[N], vis2[N], isBridge[M];   long long int tin[N], tout[N], minAncestor[N];   queue<long long int> Q[N];   vector<pair<long long int, long long int> > g[N];   vector<long long int> tree[N], vertices[N];   long long int parent[LG][N];   void dfs(long long int k, long long int par) {     vis[k] = 1;     tin[k] = ++tim;     minAncestor[k] = tin[k];     for (auto it : g[k]) {       if (it.first == par) continue;       if (vis[it.first]) {         minAncestor[k] = min(minAncestor[k], tin[it.first]);         continue;       }       dfs(it.first, k);       minAncestor[k] = min(minAncestor[k], minAncestor[it.first]);       if (minAncestor[it.first] > tin[k]) isBridge[it.second] = 1;     }     tout[k] = tim;   }   void dfs2(long long int k) {     long long int comp = grp;     Q[comp].push(k);     vis2[k] = 1;     while (!Q[comp].empty()) {       long long int u = Q[comp].front();       Q[comp].pop();       vertices[comp].push_back(u);       storecomp[u] = comp;       for (auto it : g[u]) {         long long int v = it.first;         long long int edgeidx = it.second;         if (vis2[v]) continue;         if (isBridge[edgeidx]) {           grp++;           tree[comp].push_back(grp);           tree[grp].push_back(comp);           dfs2(v);         } else {           Q[comp].push(v);           vis2[v] = 1;         }       }     }   }   void dfs3(long long int v, long long int par, long long int lvl) {     tin[v] = ++tim;     parent[0][v] = par;     level[v] = lvl;     for (auto &u : tree[v]) {       if (u == par) continue;       dfs3(u, v, lvl + 1);     }     tout[v] = tim;   }   bool is_ancestor(long long int u, long long int v) {     return (tin[u] <= tin[v] and tout[u] >= tout[v]);   }   void precompute() {     for (long long int i = 1; i < LG; i++) {       for (long long int j = 1; j <= n; j++) {         if (parent[i - 1][j]) {           parent[i][j] = parent[i - 1][parent[i - 1][j]];         }       }     }   }   long long int __lca(long long int u, long long int v) {     if (level[u] < level[v]) swap(u, v);     long long int diff = level[u] - level[v];     for (long long int i = LG - 1; i >= 0; i--) {       if ((1 << i) & diff) {         u = parent[i][u];       }     }     if (u == v) return u;     for (long long int i = LG - 1; i >= 0; i--) {       if (parent[i][u] and parent[i][u] != parent[i][v]) {         u = parent[i][u];         v = parent[i][v];       }     }     return parent[0][u];   }   long long int dist(long long int u, long long int v) {     return level[u] + level[v] - 2 * level[__lca(u, v)];   }   void HyperBeast() {     cin >> n >> m;     for (long long int i = 1; i <= m; i++) {       cin >> u[i] >> v[i];       g[u[i]].push_back({v[i], i});       g[v[i]].push_back({u[i], i});     }     dfs(1, 0);     dfs2(1);     tim = 0;     dfs3(1, 1, 1);     precompute();     long long int k;     cin >> k;     for (long long int i = 1; i <= k; i++) {       long long int u, v;       cin >> u >> v;       cout << dist(storecomp[u], storecomp[v]) <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       HyperBeast();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   const int MaxN = 2e5 + 10;   int endd, vis[MaxN];   int main() {     int tt;     cin >> tt;     while (tt--) {       cin >> s;       stack<int> sta;       for (int i = 0; i < s.size(); i++) {         sta.push(s[i]);         if (sta.top() ==  B  && sta.size() > 1) {           sta.pop();           sta.pop();         }       }       cout << sta.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void naive(int x, int y) {     if (x == y) {       cout <<  Yes n ;       return;     }     for (int i = 2; i * i <= x; i++) {       while (x % i == 0) {         if (y % (i * i) == 0) {           y /= i * i;           x /= i;         } else if (x % (i * i) == 0 && y % i == 0) {           x /= i * i;           y /= i;         } else {           cout <<  No n ;           return;         }       }     }     if (x == y * y || x * x == y)       cout <<  Yes n ;     else       cout <<  No n ;   }   void fast(long long x, long long y) {     long long p = x * y;     long long l = 1, r = 1e6 + 42;     while (r - l > 1) {       long long m = ((r + l) >> 1);       if (m * m * m > p)         r = m;       else         l = m;     }     if (l * l * l == p && x % l == 0 && y % l == 0)       cout <<  Yes n ;     else if (r * r * r == p && x % r == 0 && y % r == 0)       cout <<  Yes n ;     else       cout <<  No n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 0;     cin >> n;     while (n--) {       long long a, b;       cin >> a >> b;       if (a > b) swap(a, b);       fast(a, b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ent;     long long int a, b;     cin >> ent;     while (ent--) {       int div = 0, pls = 0;       cin >> a >> b;       if (a % b == 0) {         cout << 0 << endl;         continue;       }       div = a / b;       pls = (div + 1) * b;       cout << pls - a << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n;   double t, ans, x, y;   map<pair<double, double>, bool> b;   pair<double, double> p[1005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     for (int i = 1; i <= n; i++) {       cin >> x >> y;       p[i].first = x - y / 2;       p[i].second = x + y / 2;     }     sort(p + 1, p + 1 + n);     p[0].second = -1e18;     for (int i = 1; i <= n; i++) {       if (p[i].first - p[i - 1].second >= t &&           b[{p[i].first - t, p[i].first}] == false) {         b[{p[i].first - t, p[i].first}] = true;         ans++;       }       if (p[i].second + t <= p[i + 1].first) {         b[{p[i].second, p[i].second + t}] = true;         ans++;       }     }     ans++;     cout << ans <<   n ;     return 0;   }


#include <iostream>   #include <cstdio>   #include <cstring>   using namespace std;   char s[5010];   int n;      bool ok(int x,int y,int fx,int fy){    if(x==fx && y==fy)return 0;    return 1;   }      bool check(int fx,int fy){    int x=0,y=0;    for(int i=1;i<=n;i++){     if(s[i]== D ){      if(ok(x,y-1,fx,fy))y--;     }     if(s[i]== U ){      if(ok(x,y+1,fx,fy))y++;     }     if(s[i]== L ){      if(ok(x-1,y,fx,fy))x--;     }     if(s[i]== R ){      if(ok(x+1,y,fx,fy))x++;     }    }    if(x==0 && y==0)return 1;    else return 0;   }      void work(){    int x=0,y=0;    for(int i=1;i<=n;i++){     if(s[i]== D ){      if(check(x,y-1)){       printf( %d %d n ,x,y-1);       return;      }      else y--;     }     else if(s[i]== U ){      if(check(x,y+1)){       printf( %d %d n ,x,y+1);       return;      }      else y++;     }     else if(s[i]== L ){      if(check(x-1,y)){       printf( %d %d n ,x-1,y);       return;      }      else x--;     }     else if(s[i]== R ){      if(check(x+1,y)){       printf( %d %d n ,x+1,y);       return;      }      else x++;     }    }    puts( 0 0 );    return;   }      int main(){    int T;    scanf( %d ,&T);    while(T--){     scanf( %s ,s+1);     n=strlen(s+1);     if(check(5001,5001)){      printf( 5001 5001 n );      continue;     }     work();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 125000 + 10;   int n, m;   char s[N], t[N];   int bl[N], ans[N];   int nxt[N];   void getnext() {     for (int i = 2, j = 0; i <= m; ++i) {       while (j && bl[t[j + 1]] != bl[t[i]]) j = nxt[j];       if (bl[t[j + 1]] == bl[t[i]]) ++j;       nxt[i] = j;     }   }   void calc(int w) {     getnext();     for (int i = 1, j = 0; i <= n; ++i) {       while (j && bl[t[j + 1]] != bl[s[i]]) j = nxt[j];       if (bl[t[j + 1]] == bl[s[i]]) ++j;       if (j == m) ans[i - m + 1] = min(ans[i - m + 1], w);     }   }   void dfs(char c, int tot) {     if (c >  f ) {       calc(6 - tot);       return;     }     for (int i = 1; i <= tot; ++i) bl[c] = i, dfs(c + 1, tot);     bl[c] = tot + 1, dfs(c + 1, tot + 1);   }   int main() {     scanf( %s%s , s + 1, t + 1), n = strlen(s + 1), m = strlen(t + 1);     memset(ans, 0x3f, sizeof(ans));     dfs( a , 0);     for (int i = 1; i <= n - m + 1; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     int N;     cin >> N;     ll ans = 0;     priority_queue<int, vector<int>, greater<int>> q;     for (int i = 0; i < N; ++i) {       int v;       cin >> v;       q.emplace(v);       q.emplace(v);       ans += v - q.top();       q.pop();     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int ar[maxn], num[maxn];   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       memset(num, 0, sizeof(num));       memset(ar, 0, sizeof(ar));       cin >> n >> m;       string s;       cin >> s;       for (int i = 1; i <= m; i++) {         int x;         cin >> x;         x--;         ar[x]++;       }       int len = s.length();       for (int i = 0; i < len; i++) {         num[s[i] - 97]++;       }       for (int i = len - 1; i >= 0; i--) {         ar[i] += ar[i + 1];         num[s[i] - 97] += ar[i];       }       for (int i = 0; i < 26; i++) {         if (i < 25)           cout << num[i] <<    ;         else           cout << num[i] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int getDaysOfMonth(int m) {     if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)       return 31;     if (m == 2) return 28;     return 30;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     char a[n];     for (int i = 0; i < int(n); i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         reverse(a, a + i);       }     }     for (int i = 0; i < int(n); i++) cout << a[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   string yes =  YES n ;   string no =  NO n ;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long dp[k + 1][n + 1];     memset(dp, 0, sizeof(dp));     for (long long i = 1; i <= n; i++) dp[1][i] = 1;     for (long long i = 2; i <= k; i++) {       for (long long j = 1; j <= n; j++) {         for (long long t = j; t <= n; t += j)           dp[i][t] = (dp[i][t] + dp[i - 1][j]) % MOD;       }     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       ans += dp[k][i];       ans %= MOD;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using uint = unsigned int;   using ull = unsigned long long;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   ll myRand(ll B) { return (ull)rng() % B; }   clock_t startTime;   double getCurrentTime() {     return (double)(clock() - startTime) / CLOCKS_PER_SEC;   }   const ll MOD = 998244353;   ll add(ll x, ll y) {     x += y;     if (x >= MOD) return x - MOD;     return x;   }   ll sub(ll x, ll y) {     x -= y;     if (x < 0) return x + MOD;     return x;   }   ll mult(ll x, ll y) { return (x * y) % MOD; }   ll bin_pow(ll x, ll p) {     if (p == 0) return 1;     if (p & 1) return mult(x, bin_pow(x, p - 1));     return bin_pow(mult(x, x), p / 2);   }   ll rev(ll x) { return bin_pow(x, MOD - 2); }   const int N = 1505;   const int M = 2 * N;   const int K = N * N / 2;   vector<int> g[M];   vector<int> a[M];   vector<int> b[M];   int par[M];   int sz[M];   int cntEd[M];   int dp[M][N];   int ed[K][2];   int n, m;   void unite(int v, int u) {     v = par[v];     u = par[u];     if (v == u) {       cntEd[v]++;       if (cntEd[v] == sz[v] * (sz[v] - 1) / 2) {         for (int w : b[v]) {           g[v].push_back(w);         }         b[v].clear();         b[v].push_back(v);       }       return;     }     sz[m] = sz[v] + sz[u];     cntEd[m] = cntEd[v] + cntEd[u] + 1;     for (int x : a[v]) {       a[m].push_back(x);       par[x] = m;     }     for (int x : a[u]) {       a[m].push_back(x);       par[x] = m;     }     for (int x : b[v]) b[m].push_back(x);     for (int x : b[u]) b[m].push_back(x);     v = m;     m++;     if (cntEd[v] == sz[v] * (sz[v] - 1) / 2) {       for (int w : b[v]) {         g[v].push_back(w);       }       b[v].clear();       b[v].push_back(v);     }   }   void dfs(int v) {     if (g[v].empty()) {       dp[v][1] = 1;       return;     }     dp[v][0] = 1;     int cur = 0;     for (int u : g[v]) {       dfs(u);       int inner[N];       for (int i = 0; i <= cur + sz[u]; i++) inner[i] = 0;       for (int i = 0; i <= cur; i++)         for (int j = 1; j <= sz[u]; j++)           inner[i + j] = add(inner[i + j], mult(dp[v][i], dp[u][j]));       cur += sz[u];       for (int i = 0; i <= cur; i++) dp[v][i] = inner[i];     }     assert(cur == sz[v]);     dp[v][1] = add(dp[v][1], 1);   }   int main() {     startTime = clock();     scanf( %d , &n);     m = n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int x;         scanf( %d , &x);         if (i < j) {           ed[x][0] = i;           ed[x][1] = j;         }       }     }     for (int i = 0; i < n; i++) {       par[i] = i;       a[i].push_back(i);       b[i].push_back(i);       sz[i] = 1;       cntEd[i] = 0;     }     for (int x = 1; x <= n * (n - 1) / 2; x++) {       int v = ed[x][0], u = ed[x][1];       assert(u > 0);       unite(v, u);     }     dfs(m - 1);     for (int i = 1; i <= n; i++) printf( %d  , dp[m - 1][i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void doicho(int &t1, int &t2) {     if (t1 > t2) swap(t1, t2);   }   void sapxep(pair<double, int> result[], int n) {     for (int i = 0; i < n - 1; i++) {       for (int j = i + 1; j < n; j++) {         if (result[i].first < result[j].first) {           swap(result[i].first, result[j].first);           swap(result[i].second, result[j].second);         } else if (result[i].first == result[j].first &&                    result[i].second > result[j].second) {           swap(result[i].first, result[j].first);           swap(result[i].second, result[j].second);         }       }     }   }   int main() {     int n, t1, t2, k;     cin >> n >> t1 >> t2 >> k;     int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     pair<double, int> result[n];     for (int i = 0; i < n; i++) {       double x, y, z, t;       x = (a[i] * t1 - t1 * a[i] * ((double)k / 100) + b[i] * t2);       t = (a[i] * t2 - t1 * b[i] * ((double)k / 100) + b[i] * t1);       double max2 = x > t ? x : t;       result[i].first = max2;       result[i].second = i + 1;     }     sapxep(result, n);     for (int i = 0; i < n; i++)       printf( %d %.2f n , result[i].second, result[i].first);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1LL << 61;   int n, r;   long long a[30], b[30], k[30], p[30];   long long dfs(int u, bool op1) {     long long res = -INF;     if (u % 2 == 0) res = max(res, inner_product(a, a + n, k, 0LL));     if (u == 0) return res;     if (!op1) {       for (int i = 0; i < (n); i++) a[i] ^= b[i];       res = max(res, dfs(u - 1, true));       for (int i = 0; i < (n); i++) a[i] ^= b[i];     }     long long tmp[30];     memcpy(tmp, a, sizeof a);     for (int i = 0; i < (n); i++) a[i] = tmp[p[i]] + r;     res = max(res, dfs(u - 1, false));     memcpy(a, tmp, sizeof a);     return res;   }   int main() {     int u;     scanf( %d%d%d , &n, &u, &r);     for (int i = 0; i < (n); i++) scanf( %I64d , a + i);     for (int i = 0; i < (n); i++) scanf( %I64d , b + i);     for (int i = 0; i < (n); i++) scanf( %I64d , k + i);     for (int i = 0; i < (n); i++) scanf( %I64d , p + i), p[i]--;     printf( %I64d n , dfs(u, false));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool flag = true;   const long long int N = 2e5 + 5;   const long long int inf = 998244353;   void solve() {     long long int i = 0, j = 0, ans = 0, x = 0, y = 0, z = 0;     long long int n, k = 0, m = 0, mn = LLONG_MAX, mx = LLONG_MIN;     cin >> n >> k;     vector<long long int> a(n), v;     for (auto &it : a) {       cin >> it;       mx = max(mx, it);       mn = min(mn, it);     }     if (mx == mn) {       cout <<  0 ;       return;     }     sort(a.begin(), a.end());     for (i = mx; i >= mn; i--) {       j = upper_bound(a.begin(), a.end(), i) - a.begin();       v.push_back(n - j);     }     x = 0;     ans = 1;     for (i = 0; i < (long long int)v.size(); i++) {       if (x + v[i] <= k)         x += v[i];       else {         ans++;         x = v[i];       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     long long int T = 1, te = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<char> v;   int n;   string s;   bool potR() {     int freq[1000];     freq[ G ] = 0;     freq[ B ] = 0;     freq[ R ] = 0;     for (int i = 0; i < s.size(); ++i) {       ++freq[s[i]];     }     int cnt1 = freq[ B ];     int cnt2 = freq[ G ];     if (cnt1 >= 1 && cnt2 >= 1) {       return true;     }     if (cnt1 == 0 && cnt2 == 0) {       return true;     }     if (cnt1 == 0 && cnt2 >= 2) {       if (freq[ R ] >= 1) {         return true;       } else {         return false;       }     }     if (cnt1 >= 2 && cnt2 == 0) {       if (freq[ R ] >= 1) {         return true;       } else {         return false;       }     }     return false;   }   bool potG() {     int freq[1000];     freq[ G ] = 0;     freq[ B ] = 0;     freq[ R ] = 0;     for (int i = 0; i < s.size(); ++i) {       ++freq[s[i]];     }     int cnt1 = freq[ R ];     int cnt2 = freq[ B ];     if (cnt1 >= 1 && cnt2 >= 1) {       return true;     }     if (cnt1 == 0 && cnt2 == 0) {       return true;     }     if (cnt1 == 0 && cnt2 >= 2) {       if (freq[ G ] >= 1) {         return true;       } else {         return false;       }     }     if (cnt1 >= 2 && cnt2 == 0) {       if (freq[ G ] >= 1) {         return true;       } else {         return false;       }     }     return false;   }   bool potB() {     int freq[1000];     freq[ G ] = 0;     freq[ B ] = 0;     freq[ R ] = 0;     for (int i = 0; i < s.size(); ++i) {       ++freq[s[i]];     }     int cnt1 = freq[ G ];     int cnt2 = freq[ R ];     if (cnt1 >= 1 && cnt2 >= 1) {       return true;     }     if (cnt1 == 0 && cnt2 == 0) {       return true;     }     if (cnt1 == 0 && cnt2 >= 2) {       if (freq[ B ] >= 1) {         return true;       } else {         return false;       }     }     if (cnt1 >= 2 && cnt2 == 0) {       if (freq[ B ] >= 1) {         return true;       } else {         return false;       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     cin.get();     cin >> s;     v.push_back( R );     v.push_back( G );     v.push_back( B );     set<char> mySet;     if (potR()) {       mySet.insert( R );     }     if (potB()) {       mySet.insert( B );     }     if (potG()) {       mySet.insert( G );     }     for (auto i : mySet) {       cout << i;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b, long long mod) {     long long res = 1;     while (b != 0) {       if (1 & b) res = (res * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return res;   }   long long mminvprime(long long a, long long b) { return binpow(a, b - 2, b); }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   long long combination(long long n, long long r, long long m, long long *fact) {     long long val1 = fact[n];     long long val2 = mod_mul(fact[n - r], fact[r], m);     return mod_mul(val1, binpow(val2, m - 2, m), m);   }   void solve() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n - i; j++) {         cout <<  ( ;       }       for (long long j = 0; j < n - i; j++) {         cout <<  ) ;       }       for (long long j = 0; j < i; j++) {         cout <<  () ;       }       cout <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     string s;     cin >> s;     long long n = s.size();     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += s[i] -  0 ;     }     string a = s;     for (long long i = n - 2; i >= 0; i--) {       if (s[i] !=  0 ) {         string p = s;         p[i] = p[i] - 1;         for (long long j = i + 1; j < n; j++) {           p[j] =  9 ;         }         long long su = 0;         for (long long i = 0; i < n; i++) {           su += p[i] -  0 ;         }         if (su > sum) {           sum = su;           a = p;         }       }     }     long long f = 0;     for (long long i = 0; i < a.size(); i++) {       if (a[i] !=  0 ) {         f = 1;         cout << a[i];       }       if (a[i] ==  0  && f == 1) {         cout << a[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, pre[1000000], a[1000000], f[100], vis[100], ans, rec[100],       temp[100];   int main() {     cin >> n >> q;     for (long long i = n; i >= 1; i--) pre[i] = pre[i + 1] + n - i + 1;     f[0] = 1;     for (long long i = 1; i <= 20; i++) f[i] = f[i - 1] * i;     long long num = 0;     for (long long o = 1; o <= q; o++) {       long long tag;       cin >> tag;       if (tag == 1) {         long long l, r;         cin >> l >> r;         if (n - r + 1 > 20) {           cout << pre[n - r + 1] - pre[n - l + 2] << endl;           continue;         }         long long t = num;         for (long long i = min(n, (long long)20); i >= 1; i--)           if (t >= f[i - 1]) {             rec[i] = t / f[i - 1] + 1;             t = t % f[i - 1];           } else             rec[i] = 1;         memset(vis, 0, sizeof vis);         long long base = n - 20;         if (n <= 20) base = 0;         for (long long i = min(n, (long long)20); i >= 1; i--) {           long long xx, cnt = 0, now = 1;           while (cnt < rec[i]) {             if (!vis[now]) cnt++;             now++;           }           now--;           temp[i] = now + base;           vis[now] = 1;         }         for (int i = min(n, (long long)20); i >= 1; i--)           pre[i] = pre[i + 1] + temp[i];         cout << pre[n - r + 1] - pre[n - l + 2] << endl;       } else {         long long x;         cin >> x;         num += x;       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long INF = 1e18;   const long long N = 1e5 + 100;   long long n;   long long a[N], dp_right[N], dp_left[N], full_right[N], full_left[N];   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];     }     for (long long i = 1; i <= n; i++) {       if (a[i] != 1)         full_left[i] = full_left[i - 1] + (a[i] % 2 == 0 ? a[i] : a[i] - 1);       dp_left[i] = dp_left[i - 1] + (a[i] % 2 == 0 ? a[i] - 1 : a[i]);       dp_left[i] = max(dp_left[i], full_left[i]);     }     for (long long i = n; i >= 1; i--) {       if (a[i] != 1)         full_right[i] = full_right[i + 1] + (a[i] % 2 == 0 ? a[i] : a[i] - 1);       dp_right[i] = dp_right[i + 1] + (a[i] % 2 == 0 ? a[i] - 1 : a[i]);       dp_right[i] = max(dp_right[i], full_right[i]);     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       long long x = max({dp_right[i], dp_left[i], dp_left[i] + full_right[i + 1],                          full_left[i] + dp_right[i + 1]});       ans = max(ans, x);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, l, c, d, p, nl, np;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     cout << min(k * l / nl, min(c * d, p / np)) / n <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   const double Eps = 1e-6;   const int Mod = (int)1e9 + 7;   long long Bigmod(long long b, long long p, long long m) {     if (p == 0) return 1LL;     if (p % 2 == 0) {       long long c = Bigmod(b, p / 2, m);       return ((c % m) * (c % m)) % m;     } else       return ((b % m) * (Bigmod(b, p - 1, m))) % m;   }   long long ModInverse(long long a, long long M) { return Bigmod(a, M - 2, M); }   template <class T>   inline T GCD(T x, T y) {     if (y == 0) return x;     return GCD(y, x % y);   }   template <class T>   inline T LCM(T x, T y) {     return ((x / GCD(x, y)) * y);   }   bool Reverse(long long a, long long b) { return a > b; }   bool Compare(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first == b.first) return a.second > b.second;     return a.first < b.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) {       string A, B;       cin >> A >> B;       if (A < B)         cout << A << endl;       else {         int Pos[27];         for (int i = 0; i < 27; i++) Pos[i] = -1;         for (int i = 0; i < A.size(); i++) {           int Position = A[i] -  A  + 1;           Pos[Position] = max(Pos[Position], i);         }         bool PreBreak = false, SolutionFound = false;         for (int i = 1; i <= 26; i++) {           if (Pos[i] == -1) continue;           for (int j = 0; j < Pos[i]; j++) {             if (A[j] > A[Pos[i]]) {               string Temp = A;               swap(Temp[j], Temp[Pos[i]]);               if (Temp < B) {                 cout << Temp << endl;                 SolutionFound = true;                 PreBreak = true;                 break;               }             }           }           if (PreBreak) break;         }         if (SolutionFound == false) cout <<  ---  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s);   void multiple(string s, string d);   constexpr long long MAXN = 1e5 + 15;   int n;   string a[MAXN];   string ans =  1 , s;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (a[i] ==  0 ) {         return cout <<  0 n , false;       } else if (check(a[i])) {         ans += a[i].substr(1, a[i].size() - 1);       } else {         s = a[i];       }     }     if (s ==   ) return cout << ans <<   n , false;     s = s + ans.substr(1, ans.size() - 1);     cout << s <<   n ;   }   bool check(string s) {     int cnt = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) cnt++;       if (s[i] !=  1  && s[i] !=  0 ) return false;     }     return (cnt < 2 ? true : false);   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000007;   const long double PI = 2 * acos(0.0);   const vector<long long int> dx = {1, -1, 0, 0};   const vector<long long int> dy = {0, 0, 1, -1};   vector<long long int> ga(long long int n, bool oneIndexed = false) {     vector<long long int> a;     if (oneIndexed) a.push_back(0ll);     for (long long int i = 0; i < n; i++) {       long long int p;       cin >> p;       a.push_back(p);     }     return move(a);   }   vector<unsigned long long int> gau(unsigned long long int n,                                      bool oneIndexed = false) {     vector<unsigned long long int> a;     if (oneIndexed) a.push_back(0llu);     for (unsigned long long int i = 0; i < n; i++) {       unsigned long long int p;       cin >> p;       a.push_back(p);     }     return move(a);   }   vector<string> gas(unsigned long long int n, bool oneIndexed = false) {     vector<string> a;     if (oneIndexed) a.push_back(  );     for (unsigned long long int i = 0; i < n; i++) {       string p;       cin >> p;       a.push_back(p);     }     return move(a);   }   template <typename T, typename A>   void pa(vector<T, A> const &a, long long int begin = 0,           long long int end = -1) {     if (end == -1) end = (long long int)a.size() - 1;     for (long long int i = begin; i <= end; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   template <typename T, typename A>   void papair(vector<T, A> const &a, long long int begin = 0,               long long int end = -1) {     if (end == -1) end = (long long int)a.size() - 1;     for (long long int i = begin; i <= end; i++) {       cout << a[i].first <<     << a[i].second <<   n ;     }     cout <<   n ;   }   void yes() { cout <<  YES n ; }   void no() { cout <<  NO n ; }   void yesno(int f) {     if (f)       yes();     else       no();   }   void solve() {     vector<long long int> infreq, outfreq;     long long int n, q;     cin >> n >> q;     vector<long long int> a = ga(n, 1);     infreq = vector<long long int>(n + 1, 0);     outfreq = vector<long long int>(n + 1, 0);     while (q--) {       long long int l, r;       cin >> l >> r;       infreq[l] += 1;       outfreq[r] += 1;     }     vector<long long int> freq(n + 1, 0);     for (long long int i = 1; i <= n; i++) {       freq[i] += freq[i - 1];       freq[i] += infreq[i];       freq[i] -= outfreq[i - 1];     }     vector<pair<long long int, long long int> > data;     for (long long int i = 1; i <= n; i++) data.push_back({freq[i], i});     sort(data.begin(), data.end());     sort(a.begin(), a.end());     long long int s = 0;     while (!data.empty()) {       s += data.back().first * a.back();       a.pop_back();       data.pop_back();     }     cout << s;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 1;   int plot[MAX], n, k;   void input() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %d , &plot[i]);   }   int main() {     input();     int res = 0, k1 = 0, k2 = 0;     for (int i = 1; i <= n; i++) {       if (plot[i] != k1) k2++;       if (plot[i] == k1) res = max(res, k2), k2 = 1;       k1 = plot[i];     }     res = max(res, k2);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100000;   struct Node {     int t;     int id;   };   bool cmp(Node lhs, Node rhs) {     return lhs.t == rhs.t ? lhs.id < rhs.id : lhs.t < rhs.t;   }   int N, P;   Node A[Maxn + 5];   queue<int> q1;   priority_queue<int, vector<int>, greater<int> > q2;   long long ans[Maxn + 5];   int main() {     scanf( %d %d , &N, &P);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i].t);       A[i].id = i;     }     sort(A + 1, A + N + 1, cmp);     long long now = 0;     int last = N + 1;     for (int i = 1; i <= N;) {       if (!q1.empty()) {         int id = q1.front();         q1.pop();         ans[id] = now + P;         now += P, last = id;       } else if (A[i].t <= now) {         if (q1.empty() && A[i].id < last)           q1.push(A[i].id);         else if (!q1.empty() && q1.back() > A[i].id && A[i].id < last)           q1.push(A[i].id);         else           q2.push(A[i].id);         i++;       } else {         if (!q2.empty()) {           int id = q2.top();           q2.pop();           ans[id] = now + P;           now += P, last = id;         } else           now = A[i].t, last = N + 1;       }     }     while (!q1.empty()) {       int id = q1.front();       q1.pop(), ans[id] = now + P;       now += P;     }     while (!q2.empty()) {       int id = q2.top();       q2.pop(), ans[id] = now + P;       now += P;     }     for (int i = 1; i <= N; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T& a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T& a, Others&... b) {     a = read(a);     read(b...);   }   int n, m, tp1, tp2, cnt, a[200010], L[200010], M[200010], R[200010],       pre[200010], nxt[200010];   int sta1[200010], sta2[200010], pop1[200010], pop2[200010], buck[200010],       back[200010];   int suf1[200010], suf2[200010], st1[20][200010], st2[20][200010];   set<int> s;   int upper(int x) {     int l = 1, r = tp1;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[sta1[mid]] > x)         l = mid + 1;       else         r = mid - 1;     }     if (!r) return n + 1;     return sta1[r];   }   int lower(int x) {     int l = 1, r = tp2;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[sta2[mid]] < x)         l = mid + 1;       else         r = mid - 1;     }     if (!r) return n + 1;     return sta2[r];   }   int query1(int l, int r) {     int k = log2(r - l + 1);     int ls = st1[k][l], rs = st1[k][r - (1 << k) + 1];     if (back[ls] <= back[rs]) return ls;     return rs;   }   int query2(int l, int r) {     int k = log2(r - l + 1);     int ls = st2[k][l], rs = st2[k][r - (1 << k) + 1];     if (R[ls] <= R[rs]) return ls;     return rs;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 1; i <= n; i++) {       if (a[i - 1] != a[i])         pre[i] = i - 1;       else         pre[i] = pre[i - 1];     }     for (int i = n; i >= 1; i--) {       if (a[i + 1] != a[i])         nxt[i] = i + 1;       else         nxt[i] = nxt[i + 1];     }     R[0] = n + 1;     for (int i = 1; i <= n; i++) {       if (!pre[i] || nxt[i] == n + 1) continue;       if (1ll * (a[i] - a[pre[i]]) * (a[i] - a[nxt[i]]) > 0) {         cnt += 1;         L[cnt] = pre[i];         M[cnt] = i;         R[cnt] = nxt[i];         if (nxt[i] < R[st2[0][pre[i]]]) st2[0][pre[i]] = cnt;       }     }     s.insert(n + 1);     for (int i = n; i >= 1; i--) {       while (tp1 && a[sta1[tp1]] < a[i]) {         buck[sta1[tp1]] -= 1;         pop1[sta1[tp1]] = i;         if (!buck[sta1[tp1]]) s.insert(sta1[tp1]);         tp1 -= 1;       }       sta1[++tp1] = i;       buck[i] += 1;       while (tp2 && a[sta2[tp2]] > a[i]) {         buck[sta2[tp2]] -= 1;         pop2[sta2[tp2]] = i;         if (!buck[sta2[tp2]]) s.insert(sta2[tp2]);         tp2 -= 1;       }       sta2[++tp2] = i;       buck[i] += 1;       suf1[i] = upper(a[i]);       suf2[i] = lower(a[i]);       back[i] = *s.lower_bound(max(suf1[i], suf2[i]));     }     for (int i = 1; i <= n; i++) st1[0][i] = i;     for (int i = 1; (1 << i) <= n; i++)       for (int j = 1; j + (1 << i) - 1 <= n; j++) {         int ls = st1[i - 1][j], rs = st1[i - 1][j + (1 << (i - 1))];         if (back[ls] <= back[rs])           st1[i][j] = ls;         else           st1[i][j] = rs;         ls = st2[i - 1][j], rs = st2[i - 1][j + (1 << (i - 1))];         if (R[ls] <= R[rs])           st2[i][j] = ls;         else           st2[i][j] = rs;       }     for (int i = 1; i <= m; i++) {       int l, r;       read(l, r);       int mn = query1(l, r);       if (back[mn] <= r) {         int x = pop1[back[mn]], y = pop2[back[mn]];         if (a[mn] < a[back[mn]])           y = suf2[mn];         else           x = suf1[mn];         printf( 4 n%d %d %d %d n , mn, min(x, y), max(x, y), back[mn]);       } else {         int k = query2(l, r);         if (R[k] <= r)           printf( 3 n%d %d %d n , L[k], M[k], R[k]);         else           printf( 0 n n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int n;     cin >> n;     map<int, long long> cnt;     map<int, long long> last;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       map<int, long long> next;       last[x]++;       for (map<int, long long>::iterator j = last.begin(); j != last.end(); j++) {         int g = gcd(j->first, x);         next[g] += j->second;         cnt[g] += j->second;       }       last = next;     }     int q;     cin >> q;     while (q--) {       int x;       cin >> x;       cout << cnt[x] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 301, maxk = 10, maxs = 1 << 9, INF = 0x3f3f3f3f;   int n, a[maxn], c[maxn], tot, fact[maxk], f[maxs], ans = INF;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= n; ++i) scanf( %d , c + i);     for (int i = 1, j, k; i <= n; ++i) {       tot = 0;       for (j = 2, k = a[i]; j * j <= k; ++j)         if (k % j == 0) {           fact[tot++] = j;           while (k % j == 0) k /= j;         }       if (k > 1) fact[tot++] = k;       memset(f, 0x3f, sizeof f);       f[(1 << tot) - 1] = c[i];       for (j = 1; j <= n; ++j) {         int mask = 0;         for (k = 0; k < tot; ++k)           if (a[j] % fact[k] == 0) mask |= 1 << k;         for (int s = (1 << tot) - 1; s >= 0; --s)           if (f[s & mask] > f[s] + c[j]) f[s & mask] = f[s] + c[j];       }       if (ans > f[0]) ans = f[0];     }     if (ans == INF)       puts( -1 );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   } q[1010 * 1010 * 4];   struct node {     int next, now;   } d[1010 * 1010 * 2];   int c_c[1010], c_r[1010];   int dis[1010 * 1010];   bool vis[1010 * 1010], use_r[1010], use_c[1010];   int n, m;   void add_edge_col(int u, int v, int i) {     d[i].next = c_c[u];     c_c[u] = i;     d[i].now = v;   }   void add_edge_row(int u, int v, int i) {     d[i].next = c_r[u];     c_r[u] = i;     d[i].now = v;   }   void init() {     cin >> n >> m;     int l = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         char ch;         cin >> ch;         if (ch ==  # ) {           add_edge_col(j, i, ++l);           add_edge_row(i, j, ++l);         }       }     add_edge_row(n, m + 1, ++l);   }   void solve() {     int head = 1, tail = 1;     memset(dis, 64, sizeof(dis));     q[1].x = 1;     q[1].y = 0;     dis[0] = 0;     vis[0] = true;     bool flag = 0;     while (head <= tail) {       int u = (q[head].x - 1) * m + q[head].y;       if (dis[u] >= dis[n * m + 1]) {         vis[u] = false;         head++;         continue;       }       if (!use_r[q[head].x])         for (int i = c_r[q[head].x]; i; i = d[i].next) {           int v = (q[head].x - 1) * m + d[i].now;           if (dis[v] > dis[u] + 1) {             if (v == n * m + 1) flag = 1;             if (!vis[v] && v != n * m + 1) {               tail++;               q[tail].x = q[head].x;               q[tail].y = d[i].now;               vis[v] = true;             }             dis[v] = dis[u] + 1;           }         }       use_r[q[head].x] = true;       if (!use_c[q[head].y])         for (int i = c_c[q[head].y]; i; i = d[i].next) {           int v = (d[i].now - 1) * m + q[head].y;           if (dis[v] > dis[u] + 1) {             if (v == n * m + 1) flag = 1;             if (!vis[v] && v != n * m + 1) {               tail++;               q[tail].x = d[i].now;               q[tail].y = q[head].y;               vis[v] = true;             }             dis[v] = dis[u] + 1;           }         }       use_c[q[head].y] = true;       vis[u] = false;       head++;     }     if (flag)       cout << dis[n * m + 1] - 1 << endl;     else       cout <<  -1  << endl;   }   int main() {     ios::sync_with_stdio(false);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, A, B, Q, x, y, t, ans;   int data[200010];   class segleaf {    public:     int s[2];   } seg[2000010];   void change(int x, int l, int r, int t, int delta) {     if (l == r) {       data[t] += delta;       seg[x].s[0] = min(data[t], B);       seg[x].s[1] = min(data[t], A);       return;     }     int mid = (l + r) >> 1;     if (t <= mid)       change(x << 1, l, mid, t, delta);     else       change((x << 1) + 1, mid + 1, r, t, delta);     seg[x].s[0] = seg[x << 1].s[0] + seg[(x << 1) + 1].s[0];     seg[x].s[1] = seg[x << 1].s[1] + seg[(x << 1) + 1].s[1];   }   int ask(int x, int l, int r, int ll, int rr, int tt) {     if (l == ll && r == rr) return seg[x].s[tt];     int mid = (l + r) >> 1;     if (rr <= mid)       return ask(x << 1, l, mid, ll, rr, tt);     else if (ll > mid)       return ask((x << 1) + 1, mid + 1, r, ll, rr, tt);     else       return ask(x << 1, l, mid, ll, mid, tt) +              ask((x << 1) + 1, mid + 1, r, mid + 1, rr, tt);   }   int main() {     scanf( %d%d%d%d%d , &N, &K, &A, &B, &Q);     for (int i = 1; i <= Q; i++) {       scanf( %d , &t);       if (t == 1) {         scanf( %d%d , &x, &y);         change(1, 1, N, x, y);       } else {         scanf( %d , &x);         ans = 0;         if (x > 1) ans += ask(1, 1, N, 1, x - 1, 0);         if (x + K <= N) ans += ask(1, 1, N, x + K, N, 1);         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, w, b;     int a[100];     cin >> n >> w >> b;     for (int i = 0; i < n; i++) cin >> a[i];     int mini, maxi;     if (w <= b) {       mini = w;       maxi = b;     } else {       mini = b;       maxi = w;     }     int st = 0, endi = n - 1, cost = 0;     while (st <= endi) {       if (a[st] == a[endi] && a[st] == 2) {         if (st != endi)           cost += 2 * mini;         else           cost += mini;       }       if (a[st] != a[endi]) {         if (a[st] != 2 && a[endi] != 2) {           cout <<  -1  << endl;           return 0;         }         if (a[st] == 0 || a[endi] == 0)           cost += w;         else if (a[st] == 1 || a[endi] == 1)           cost += b;       }       st++;       endi--;     }     cout << cost << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long fact(long long n) {     long long ret = 1;     for (int i = 1; i <= n; i++) ret *= i;     return ret;   }   bool is_vowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y )       return 1;     return 0;   }   long double getDistance(long double x1, long double y1, long double x2,                           long double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   int n, b, q, upto[N], qu[N];   vector<pair<int, int> > v;   int main() {     scanf( %d%d%d , &n, &b, &q);     for (int i = 0; i < q; i++) {       scanf( %d%d , &upto[i], &qu[i]);       v.push_back(pair<int, int>(upto[i], qu[i]));     }     sort(v.begin(), v.end());     v.push_back(pair<int, int>(b, n));     for (int i = 0; i < q; i++) {       if (v[i].second > v[i + 1].second) {         cout <<  unfair ;         return 0;       }     }     for (int i = 1; i < (1 << 5); i++) {       int sum = 0;       for (int j = 0; j < 5; j++) {         if (i & (1 << j)) sum++;       }       sum *= (n / 5);       int cur = 1, prev = 0;       for (int j = 0; j < v.size(); j++) {         if (v[j].first < cur) continue;         int matching = 0;         while (cur <= v[j].first) {           int rem = cur % 5;           if (i & (1 << rem)) {             matching++;           }           cur++;         }         sum -= min(matching, v[j].second - prev);         prev = v[j].second;       }       if (sum > 0) {         printf( unfair );         return 0;       }     }     printf( fair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   const int mod = 95542721, magic = 48;   int inf = 1e9;   int tr[4 * N][magic], lz[4 * N];   int a[N];   void build(int cn, int b, int e) {     if (b == e) {       int x = a[b];       for (int i = 0; i < magic; i++) {         tr[cn][i] = x;         int y = 1ll * x * x % mod;         y = 1ll * y * x % mod;         x = y;       }       return;     }     int lc = cn << 1, rc = lc | 1, mid = b + e >> 1;     build(lc, b, mid);     build(rc, mid + 1, e);     for (int i = 0; i < magic; i++) tr[cn][i] = (tr[lc][i] + tr[rc][i]) % mod;   }   void propagate(int u, int st, int en) {     if (!lz[u]) return;     if (st != en) {       lz[2 * u] += lz[u];       lz[2 * u] %= magic;       lz[2 * u + 1] += lz[u];       lz[2 * u + 1] %= magic;     }     int tmp[magic];     for (int i = 0; i < magic; i++) tmp[i] = tr[u][(i + lz[u]) % magic];     for (int i = 0; i < magic; i++) tr[u][i] = tmp[i];     lz[u] = 0;   }   void update(int u, int st, int en, int l, int r) {     propagate(u, st, en);     if (r < st || en < l)       return;     else if (l <= st && en <= r) {       lz[u]++;       lz[u] %= magic;       propagate(u, st, en);     } else {       int mid = (st + en) / 2;       update(2 * u, st, mid, l, r);       update(2 * u + 1, mid + 1, en, l, r);       for (int i = 0; i < magic; i++)         tr[u][i] = (tr[u << 1][i] + tr[(u << 1) | 1][i]) % mod;     }   }   int query(int u, int st, int en, int l, int r) {     propagate(u, st, en);     if (r < st || en < l)       return 0;     else if (l <= st && en <= r)       return tr[u][0];     else {       int mid = (st + en) / 2;       return (query(2 * u, st, mid, l, r) + query(2 * u + 1, mid + 1, en, l, r)) %              mod;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     cin >> q;     while (q--) {       int t, l, r;       cin >> t >> l >> r;       if (t == 2)         update(1, 1, n, l, r);       else         cout << query(1, 1, n, l, r) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 1e6 + 10;   ll n, m, q, v;   ll kl, ke;   ll l[N];   ll e[N];   void umin(ll &a, ll b) { a = min(a, b); }   signed main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     cin >> kl >> ke;     cin >> v;     for (ll i = 0; i < kl; ++i) {       cin >> l[i];     }     for (ll i = 0; i < ke; ++i) {       cin >> e[i];     }     sort(l, l + kl);     sort(e, e + ke);     cin >> q;     while (q--) {       ll x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (y1 > y2) {         swap(x1, x2);         swap(y1, y2);       }       ll ans = (ll)1e18;       auto it = lower_bound(l, l + kl, y1);       if (it != l + kl) {         umin(ans, abs(y1 - *it) + abs(y2 - *it) + abs(x1 - x2));       }       it = upper_bound(l, l + kl, y2);       if (it != l) {         --it;         umin(ans, abs(y1 - *it) + abs(y2 - *it) + abs(x1 - x2));       }       it = lower_bound(e, e + ke, y1);       if (it != e + ke) {         umin(ans, abs(y1 - *it) + abs(y2 - *it) + (abs(x1 - x2) + v - 1) / v);       }       it = upper_bound(e, e + ke, y2);       if (it != e) {         --it;         umin(ans, abs(y1 - *it) + abs(y2 - *it) + (abs(x1 - x2) + v - 1) / v);       }       if (x1 == x2) {         ans = abs(y1 - y2);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int cg(long long int n) { return n ^ (n >> 1); }   long long int SUM(long long int a) { return (a * (a + 1) / 2); }   bool CAN(int x, int y, int n, int m) {     if (x >= 0 && y >= 0 && x < n && y < m) {       return true;     }     return false;   }   double her(double x1, double arayikhalatyan, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) +                 (arayikhalatyan - y2) * (arayikhalatyan - y2));   }   string strsum(string a, string b) {     int p = 0;     string c;     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     if (b.length() < a.length()) {       for (int i = b.length(); i < a.length(); i++) {         b +=  0 ;       }     } else {       for (int i = a.length(); i < b.length(); i++) {         a +=  0 ;       }     }     a +=  0 , b +=  0 ;     for (int i = 0; i < a.length(); i++) {       c += (a[i] -  0  + b[i] -  0  + p) % 10 +  0 ;       p = (a[i] + b[i] -  0  -  0  + p) / 10;     }     if (c[c.length() - 1] ==  0 ) c.erase(c.length() - 1, 1);     reverse(c.begin(), c.end());     return c;   }   string strmin(string a, string b) {     if (a.length() > b.length()) return b;     if (b.length() > a.length()) return a;     for (int i = 0; i < a.length(); i++) {       if (a[i] > b[i]) return b;       if (b[i] > a[i]) return a;     }     return a;   }   char vow[] = { a ,  e ,  i ,  o ,  u };   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   const int N = 1e6 + 30;   const long long int mod = 1e9 + 7;   int q;   int n, k;   vector<pair<long long int, int> > g[N];   long long int dp[N][2];   void dfs(int v, int par) {     vector<int> sm;     for (auto p : g[v]) {       if (p.second == par) continue;       dfs(p.second, v);       dp[v][0] += dp[p.second][1];       dp[v][1] += dp[p.second][1];       sm.push_back(p.first + dp[p.second][0] - dp[p.second][1]);     }     sort(sm.begin(), sm.end(), greater<int>());     for (int i = 0; i < sm.size(); i++) {       if (i == k) break;       if (i == k - 1) {         dp[v][1] += max(0, sm[i]);       } else {         dp[v][0] += max(0, sm[i]);         dp[v][1] += max(0, sm[i]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> q;     while (q--) {       cin >> n >> k;       for (int i = 0; i < n - 1; i++) {         int a, b, c;         cin >> a >> b >> c;         g[a].push_back(make_pair(c, b));         g[b].push_back(make_pair(c, a));       }       dfs(1, -1);       cout << dp[1][1] << endl;       for (int i = 1; i <= n; i++) {         g[i].clear();         dp[i][0] = 0;         dp[i][1] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, fut, duim;   int main() {     cin >> a;     a += 1;     fut = a / 36;     duim = round((a - fut * 36) / 3);     cout << fut <<     << duim << endl;     fclose(stdin);     fclose(stdout);   }


#include <bits/stdc++.h>   struct itv {     int s1;     int e1;     int s2;     int e2;     int gr;     void up() {       gr = (e2 - s2) + 1;       if (e1) {         gr += (e1 - s1) + 1;       };     };   };   std::vector<std::pair<int, int> > aus;   void merge(int s1, int s2, int sz) {     for (int i = 0; i < sz; i++) {       aus.push_back({s1 + i, s2 + i});     };   };   itv tt[1000];   int main(void) {     int n;     scanf( %d , &n);     int akt = 1;     for (int i = 1; i <= 20; i++) {       int sz = (1 << i);       if (sz > n) break;       for (int j = 1; j <= n; j += sz) {         int s1 = j;         int s2 = j + (sz / 2);         if (s1 + sz > n + 1) break;         merge(s1, s2, sz / 2);       };     };     akt = n;     std::vector<int> pw;     for (int i = 0; i <= 20; i++) {       if (n & (1 << i)) {         pw.push_back(i);         tt[i].s2 = (akt - (1 << i)) + 1;         tt[i].e2 = akt;         tt[i].s1 = 0;         tt[i].e1 = 0;         tt[i].up();         akt -= (1 << i);       };     };     if (pw.size() > 2) {       int ak = 1;       for (int i = 0; i < pw.size() - 2; i++) {         int ap = pw[i];         int np = pw[i + 1];         int ss = tt[ap].e2 - tt[ap].s2 + 1;         if (!i) {           merge(tt[ap].s2, ak, ss);           tt[ap].s1 = ak;           ak += (ss);           tt[ap].e1 = ak - 1;         };         tt[ap].up();         while (tt[ap].gr < tt[np].gr) {           merge(tt[ap].s1, ak, tt[ap].e1 - tt[ap].s1 + 1);           ak += (tt[ap].e1 - tt[ap].s1 + 1);           merge(tt[ap].s2, ak, ss);           ak += (ss);           tt[ap].e1 = ak - 1;           tt[ap].up();         };         merge(tt[ap].s2, tt[np].s2, ss);         merge(tt[ap].s1, tt[np].s2 + ss, tt[ap].e1 - tt[ap].s1 + 1);         tt[np].e2 = tt[ap].e2;         tt[np].s1 = tt[ap].s1;         tt[np].e1 = tt[ap].e1;         tt[np].up();       };     };     printf( %d n , aus.size());     for (auto i : aus) {       printf( %d %d n , i.first, i.second);     };     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   int n, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     int odd = 0, even = 0, ans = 0;     for (int i = 0; i < n; i++) {       int num;       cin >> num;       if (num % 2)         odd++;       else         even++;     }     for (int i = 0; i < k; i++) {       int num;       cin >> num;       if (num % 2 && even) {         ans++;         even--;       }       if (num % 2 == 0 && odd) {         ans++;         odd--;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long v, n, arr[50005], ans, o = 9999, minans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       v = max(arr[i], v);       o = min(arr[i], o);       ans += arr[i];     }     minans = ans;     for (int x = 1; x <= n; x++) {       for (int i = 1; i <= v; i++) {         if (arr[x] % i == 0) {           long long nowc = arr[x] / i - arr[x] + o * (i - 1);           minans = min(minans, ans + nowc);         }       }     }     cout << minans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, N, val[53][53], rk[53][53], fr[103];   vector<int> peo[53];   int pos[53];   void go(bool flg) {     queue<int> q;     for (int i = 1; i <= N; ++i) {       peo[i].clear();       for (int j = 1; j <= N; ++j) peo[i].push_back(j);       sort(peo[i].begin(), peo[i].end(),            [&](int p, int q) { return (val[i][p] < val[i][q]) ^ flg; });       q.push(i);       pos[i] = fr[i] = fr[i + N] = 0;     }     for (int i = 1; i <= N; ++i) {       vector<int> tmp;       for (int j = 1; j <= N; ++j) tmp.push_back(j);       sort(tmp.begin(), tmp.end(),            [&](int p, int q) { return (val[p][i] > val[q][i]) ^ flg; });       for (int j = 0; j < tmp.size(); ++j) rk[i][tmp[j]] = j + 1;     }     while (!q.empty()) {       int t = q.front();       q.pop();       while (!fr[t]) {         int tar = peo[t][pos[t]++];         if (!fr[tar + N] || rk[tar][fr[tar + N]] > rk[tar][t]) {           fr[fr[tar + N]] = 0;           if (fr[tar + N]) q.push(fr[tar + N]);           fr[tar + N] = t;           fr[t] = tar + N;         }       }     }   }   int main() {     for (cin >> T; T; --T) {       cin >> N;       for (int i = 1; i <= N; ++i)         for (int j = 1; j <= N; ++j) cin >> val[i][j];       cout <<  B  << endl;       char c;       cin >> c;       if (c ==  D )         for (int i = 1; i <= N; ++i)           for (int j = 1; j <= N; ++j) val[i][j] = -val[i][j];       int p;       cin >> p;       go(p > N);       while (p != -1) {         cout << fr[p] << endl;         cin >> p;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long n;     scanf( %ld n , &n);     std::vector<long> array(n, 0);     for (int p = 0; p < n; p++) {       scanf( %ld  , &array[p]);     }     bool down = 0, possible = 1;     long moves(0);     for (int p = 1; p < n; p++) {       if (array[p - 1] <= array[p]) {         continue;       }       if (down) {         possible = 0;         break;       }       down = 1;       moves = n - p;       if (array[p] > array[0]) {         possible = 0;         break;       }     }     if (down && array[n - 1] > array[0]) {       possible = 0;     }     if (!possible) {       puts( -1 );     } else {       printf( %ld n , moves);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100000], p[100000], b[100000];   vector<int> v[100000];   set<int> s;   int main() {     int n, cnt = -1;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       p[i] = arr[i];     }     sort(p, p + n);     int i, j = 0;     while (s.size() != n) {       i = j;       if (b[i] != -1) cnt++;       while (b[i] != 1) {         b[i] = 1;         v[cnt].push_back(i);         s.insert(i);         i = lower_bound(p, p + n, arr[i]) - p;       }       j++;     }     int ans = 0;     for (int i = 0; i <= cnt; i++) {       if (v[i].size() > 0) ans++;     }     cout << ans << endl;     for (int i = 0; i <= cnt; i++) {       if (v[i].size() > 0) {         cout << v[i].size() <<    ;         for (int j = 0; j < v[i].size(); j++) cout << v[i][j] + 1 <<    ;         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long getLCM(int a, int b) {     int copyA = a, copyB = b;     int r = a % b;     while (r) {       a = b;       b = r;       r = a % b;     }     int gcd = b;     return 1LL * copyA * copyB / gcd;   }   int main() {     int n, a, b, p, q;     cin >> n >> a >> b >> p >> q;     int divA = n / a;     int divB = n / b;     int divAB = n / getLCM(a, b);     divA -= divAB;     divB -= divAB;     cout << 1LL * divA * p + 1LL * divB * q + 1LL * divAB * max(p, q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1005;   bool vis[mx][mx][2];   double dp[mx][mx][2];   double func(int white, int black, int turn) {     if (white <= 0) {       return 0.0;     }     if (black <= 0) {       if (!turn) return 1.0;       return 0.0;     }     if (vis[white][black][turn]) return dp[white][black][turn];     double up, down, p, q, r, ans, x, y;     if (!turn) {       up = white;       down = (double)white + black;       ans = up / down;       p = (1.0 - ans);       ans += p * func(white, black - 1, 1);     } else {       up = black;       down = white + black;       p = up / down;       black--;       q = 0.0;       x = 0.0;       if (black) {         up = black;         down = black + white;         q = up / down;         x = q * func(white, black - 1, 0);       }       r = (1.0 - q);       y = r * func(white - 1, black, 0);       ans = p * (x + y);     }     vis[white][black][turn] = 1;     return dp[white][black][turn] = ans;   }   int main() {     int b, w;     scanf( %d %d , &w, &b);     memset(vis, 0, sizeof(vis));     double ans = func(w, b, 0);     printf( %.15lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = ~(((long long)0x1) << 63) / 2;   const int INF = 0X3F3F3F3F;   const double eps = 1e-7;   int num[10];   int ok[10];   int main() {     int n, k, i, j, v;     string s, ans, now, ss;     cin >> n >> v;     cin >> s;     for (i = 0; i < n; i++) num[s[i] -  0 ]++;     int minvalue = INF;     for (i = 0; i < 10; i++) {       memset(ok, 0, sizeof(ok));       int now = v, last = -1;       now -= num[i];       ok[i] = 1;       last = i;       for (j = 1; j < 10 && now > 0; j++) {         if (i - j >= 0) {           now -= num[i - j];           ok[i - j] = 1;         }         if (now <= 0) {           last = i - j;           now += num[last];           break;         }         if (i + j < 10) {           now -= num[i + j];           ok[i + j] = 1;         }         if (now <= 0) {           last = i + j;           now += num[last];           break;         }       }       if (last == i) now += num[i];       int value = 0;       ans =   ;       for (j = 0; j < n; j++)         if (ok[s[j] -  0 ] && s[j] -  0  != last)           ans += i +  0 , value += abs(s[j] -  0  - i);         else           ans += s[j];       if (last >= i) {         for (j = 0; j < n && now > 0; j++)           if (ans[j] == last +  0 )             ans[j] = i +  0 , value += abs(ans[j] -  0  - last), now--;       } else {         for (j = n; j >= 0 && now > 0; j--)           if (ans[j] == last +  0 )             ans[j] = i +  0 , value += abs(ans[j] -  0  - last), now--;       }       if (value < minvalue) {         minvalue = value;         ss = ans;       } else if (value == minvalue && ans < ss)         ss = ans;       memset(ok, 0, sizeof(ok));       now = v, last = -1;       now -= num[i];       ok[i] = 1;       last = i;       for (j = 1; j < 10 && now > 0; j++) {         if (i + j < 10) {           now -= num[i + j];           ok[i + j] = 1;         }         if (now <= 0) {           last = i + j;           now += num[last];           break;         }         if (i - j >= 0) {           now -= num[i - j];           ok[i - j] = 1;         }         if (now <= 0) {           last = i - j;           now += num[last];           break;         }       }       if (last == i) now += num[i];       value = 0;       ans =   ;       for (j = 0; j < n; j++)         if (ok[s[j] -  0 ] && s[j] -  0  != last)           ans += i +  0 , value += abs(s[j] -  0  - i);         else           ans += s[j];       if (last >= i) {         for (j = 0; j < n && now > 0; j++)           if (ans[j] == last +  0 )             ans[j] = i +  0 , value += abs(ans[j] -  0  - last), now--;       } else {         for (j = n; j >= 0 && now > 0; j--)           if (ans[j] == last +  0 )             ans[j] = i +  0 , value += abs(ans[j] -  0  - last), now--;       }       if (value < minvalue) {         minvalue = value;         ss = ans;       } else if (value == minvalue && ans < ss)         ss = ans;     }     cout << minvalue << endl;     cout << ss << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a[100010], l[100010], r[100010], LS[100010], T;   int G[100010][10];   struct MAT {     int data[10][10];     MAT() { memset(data, 0, sizeof(data)); }     MAT operator*(const MAT& ma) const {       MAT ret;       for (int i = 1; i <= 3; ++i)         for (int j = 1; j <= 3; ++j)           for (int k = 1; k <= 3; ++k)             ret.data[i][j] =                 (ret.data[i][j] + 1ll * data[i][k] * ma.data[k][j]) % 1000000007;       return ret;     }   };   MAT A;   int main() {     scanf( %lld%lld , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d%lld%lld , &a[i], &l[i], &r[i]);       LS[++T] = l[i], LS[++T] = r[i] + 1;     }     LS[++T] = 2, LS[++T] = m + 1;     sort(LS + 1, LS + T + 1);     T = unique(LS + 1, LS + T + 1) - LS - 1;     for (int i = 1; i <= n; ++i) {       l[i] = lower_bound(LS + 1, LS + T + 1, l[i]) - LS;       r[i] = lower_bound(LS + 1, LS + T + 1, r[i] + 1) - LS;       G[l[i]][a[i]]++, G[r[i]][a[i]]--;     }     for (int i = 1; i <= 3; ++i) A.data[i][i] = 1;     for (int i = 1; i < T; ++i) {       for (int j = 1; j <= 3; ++j) G[0][j] += G[i][j];       MAT I;       for (int j = 1; j <= 3; ++j)         for (int k = max(1, j - 1); k <= min(3, j + 1); ++k)           if (!G[0][k]) I.data[j][k] = 1;       long long len = LS[i + 1] - LS[i];       for (; len; len >>= 1, I = I * I)         if (len & 1) A = A * I;     }     printf( %d , A.data[2][2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 10000007;   using pii = pair<long long, long long>;   const long long mod = 1e9 + 7;   const double pi = acos(-1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<pii> v;       vector<long long> ev, od;       set<long long> s;       for (long long i = 0; i < n; i++) {         s.insert(i + 1);         if ((i + 1) % 2 == 0)           ev.push_back(i + 1);         else           od.push_back(i + 1);       }       if (n == 2) {         cout << 2 << endl;         cout << 1 <<     << 2 << endl;         continue;       }       sort(ev.begin(), ev.end());       sort(od.begin(), od.end());       reverse(ev.begin(), ev.end());       reverse(od.begin(), od.end());       long long d;       if (n % 2 == 0) {         d = ev[0];         s.erase(d);         long long i = 1, j = 0;         while (1) {           if (d % 2 == 0) {             long long a = d;             long long b = ev[i];             s.erase(b);             v.push_back({a, b});             d = (a + b) / 2;             if (s.size() == 0) break;             i++;             if (i > ev.size()) break;           } else {             long long a = d;             long long b = od[j];             s.erase(b);             v.push_back({a, b});             j++;             d = (a + b) / 2;             if (s.size() == 0) break;             if (j > od.size()) break;           }           if (s.size() == 0) break;         }       } else if (n % 2 == 1) {         d = od[0];         s.erase(d);         long long i = 1, j = 0;         while (1) {           if (d % 2 == 1) {             long long a = d;             long long b = od[i];             s.erase(b);             v.push_back({a, b});             d = (a + b) / 2;             if (s.size() == 0) break;             i++;             if (i > od.size()) break;           } else {             long long a = d;             long long b = ev[j];             s.erase(b);             v.push_back({a, b});             j++;             d = (a + b) / 2;             if (s.size() == 0) break;             if (j > ev.size()) break;           }           if (s.size() == 0) break;         }       }       cout << d << endl;       for (long long i = 0; i < v.size(); i++) {         cout << v[i].first <<     << v[i].second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     vector<double> vv;     vv.push_back(0);     for (double i = 1; i <= 400; i++) {       vv.push_back(180 / i);     }     cin >> t;     while (t--) {       double n;       cin >> n;       bool is = 0;       for (int i = 3; i < vv.size(); i++) {         double x = 0;         bool don = 0;         for (int j = 0; j < i - 2; j++) {           x += vv[i];           if (x == n) {             cout << i << endl;             don = 1;             break;           }         }         if (don) {           is = 1;           break;         }       }       if (!is) cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20, K = (1 << 16) + 5, M = 2005, mod = 998244353;   int k, sum, a[N], b[N];   bitset<M> f[K];   inline void dfs(register int s, register int now) {     if (!s) return;     register int i;     for (; now * k <= sum && f[s][now * k]; now *= k)       for (i = s; i; i ^= i & -i) ++b[__builtin_ctz(i & -i)];     for (i = s; i; i ^= i & -i)       if (now >= a[__builtin_ctz(i & -i)] &&           f[s ^ i & -i][now - a[__builtin_ctz(i & -i)]]) {         dfs(s ^ i & -i, now - a[__builtin_ctz(i & -i)]);         return;       }   }   priority_queue<pair<int, int> > q;   int main() {     register int n, i, s, t;     scanf( %d%d , &n, &k);     for (i = 0; i ^ n; ++i) scanf( %d , &a[i]), sum += a[i];     t = (1 << n) - 1;     f[0][0] = 1;     for (s = 1; s <= t; ++s) {       for (i = s; i; i ^= i & -i)         f[s] |= f[s ^ i & -i] << a[__builtin_ctz(i & -i)];       for (i = sum / k; i >= 1; --i)         if (f[s][i * k]) f[s][i] = 1;     }     if (!f[t][1])       puts( NO );     else {       puts( YES );       dfs(t, 1);       register pair<int, int> x1, x2;       for (i = 0; i ^ n; ++i) q.push(make_pair(b[i], a[i]));       while (q.size() > 1) {         x1 = q.top();         q.pop();         x2 = q.top();         q.pop();         printf( %d %d n , x1.second, x2.second);         x1.second += x2.second;         while (x1.second % k == 0) x1.second /= k, --x1.first;         q.push(x1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int B[1 << 17];   int R[1 << 17];   vector<int> Add(const vector<int>& a, const vector<int>& b) {     vector<int> res = a;     int i;     for (i = (0); i < (int((b).size())); ++i) res.push_back(b[i]);     return res;   }   int main() {     int n;     scanf( %d , &n);     int i, j;     for (i = (0); i < (n); ++i) {       int a;       scanf( %d , &a);       --a;       R[a] = i;     }     memset(B, 0, sizeof(B));     vector<vector<int> > ret;     vector<vector<int> > ret2;     vector<vector<int> > A[8];     for (i = (0); i < (n); ++i)       if (B[i] == 0) {         int pos = i;         vector<int> v;         while (B[pos] == 0) {           B[pos] = 1;           v.push_back(pos);           pos = R[pos];         }         pos = 0;         int len = int((v).size());         while (len - pos > 4) {           vector<int> r;           for (j = (0); j < (5); ++j) r.push_back(v[pos + j]);           ret.push_back(r);           rotate(r.begin(), r.end() - 1, r.end());           ret2.push_back(r);           pos += 4;         }         if (len - pos > 1) {           vector<int> w;           for (j = (pos); j < (len); ++j) w.push_back(v[j]);           A[len - pos].push_back(w);         }       }     int L[8];     int C[8];     memset(L, 0, sizeof(L));     memset(C, 0, sizeof(C));     for (i = (0); i < (8); ++i) L[i] = int((A[i]).size());     for (i = (0); i < (L[4]); ++i) {       vector<int> r = A[4][i];       ret.push_back(r);       rotate(r.begin(), r.end() - 1, r.end());       ret2.push_back(r);     }     while (C[2] + C[3] != L[2] + L[3]) {       if (C[2] != L[2]) {         vector<int> r = A[2][C[2]];         ++C[2];         vector<int> r2;         if (C[3] != L[3]) {           r2 = A[3][C[3]];           ++C[3];         } else if (C[2] != L[2]) {           r2 = A[2][C[2]];           ++C[2];         }         ret.push_back(Add(r, r2));         rotate(r.begin(), r.end() - 1, r.end());         if (!r2.empty()) rotate(r2.begin(), r2.end() - 1, r2.end());         ret2.push_back(Add(r, r2));         continue;       }       vector<int> r = A[3][C[3]];       ++C[3];       vector<int> r2;       if (C[3] != L[3]) {         r2 = A[3][C[3]];         r2.erase(r2.end() - 1);         ++C[3];       }       ret.push_back(Add(r, r2));       rotate(r.begin(), r.end() - 1, r.end());       if (!r2.empty()) rotate(r2.begin(), r2.end() - 1, r2.end());       ret2.push_back(Add(r, r2));       if (!r2.empty()) {         vector<int> t;         t.push_back(A[3][C[3] - 1][1]);         t.push_back(A[3][C[3] - 1][2]);         A[2].push_back(t);         ++L[2];       }     }     printf( %d n , int((ret).size()));     for (i = (0); i < (int((ret).size())); ++i) {       printf( %d n , int((ret[i]).size()));       for (j = (0); j < (int((ret[i]).size())); ++j)         printf( %d%c , ret[i][j] + 1, j == int((ret[i]).size()) - 1 ?   n  :    );       for (j = (0); j < (int((ret2[i]).size())); ++j)         printf( %d%c , ret2[i][j] + 1,                j == int((ret2[i]).size()) - 1 ?   n  :    );     }     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 300005;   const long long INF = 0x3f3f3f3f3f3f3f3f;   long long n;   long long Read() {     long long x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x * 10) + (c ^ 48);       c = getchar();     }     return x * f;   }   void Put1(long long x) {     if (x > 9) Put1(x / 10);     putchar(x % 10 ^ 48);   }   void Put(long long x, char c = -1) {     if (x < 0) putchar( - ), x = -x;     Put1(x);     if (c >= 0) putchar(c);   }   template <typename T>   T Max(T x, T y) {     return x > y ? x : y;   }   template <typename T>   T Min(T x, T y) {     return x < y ? x : y;   }   template <typename T>   T Abs(T x) {     return x < 0 ? -x : x;   }   long long a, d[MAXN], c[MAXN], f[MAXN];   struct node {     long long d, maxf, maxans;     node() {}     node(long long d1, long long maxf1, long long maxans1) {       d = d1;       maxf = maxf1;       maxans = maxans1;     }   } sta[MAXN];   long long pow2(long long x) { return x * x; }   void solve() {     long long ans = Max(0ll, a - (c[n] - c[n - 1])), max_pref, ed = 0;     sta[0].maxans = -INF;     sta[++ed] = node(0, f[n], f[n]);     for (long long l = n - 1; l >= 1; --l) {       max_pref = -INF;       while (ed > 0 && sta[ed].d <= d[l + 1] - d[l]) {         max_pref = Max(max_pref, sta[ed].maxf);         sta[ed--] = node(0, 0, 0);       }       if (max_pref != -INF)         sta[++ed] =             node(d[l + 1] - d[l], max_pref,                  Max(max_pref - pow2(d[l + 1] - d[l]), sta[ed - 1].maxans));       sta[++ed] = node(0, f[l], Max(f[l], sta[ed - 1].maxans));       ans = Max(ans, sta[ed].maxans - f[l - 1]);     }     Put(ans,   n );   }   signed main() {     n = Read(), a = Read();     for (long long i = 1; i <= n; ++i)       d[i] = Read(), c[i] = c[i - 1] + Read(), f[i] = a * i - c[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_LN = 20;   const int D = 10;   const long long INF = 1LL << 60;   const double EPS = 1e-9;   const double PI = 3.14159265358979;   long long n;   long long dp[MAX_LN][1 << D][D][D];   long long pat[2][D];   void init(int S, int v0) {     long long sdp[20];     fill(sdp, sdp + 20, INF);     sdp[10 + v0] = 0;     sdp[10] = min(sdp[10], 1LL);     for (int i = (0); i < (D); i++)       if (S & (1 << i)) {         for (int j = (10 - i); j < (20 - i); j++) {           sdp[j] = min(sdp[j], sdp[j + i] + 1);         }       }     for (int i = (0); i < (D); i++) dp[0][S][v0][i] = sdp[i];   }   void calc(int d, int S) {     long long sdp[2][D];     long long *curr = sdp[0], *next = sdp[1];     for (int s = (0); s < (D); s++) {       for (int i = (0); i < (2); i++)         for (int j = (0); j < (D); j++) sdp[i][j] = INF;       curr[s] = 0;       if (d > 0) {         {           for (int j = (0); j < (D); j++) next[j] = INF;           for (int j = (0); j < (D); j++)             for (int k = (0); k < (D); k++) {               next[k] = min(next[k], curr[j] + dp[d][S | (1 << 9)][j][k]);             }           swap(curr, next);         }         for (int i = 9; i >= 1; i--) {           {             for (int j = (0); j < (D); j++) next[j] = INF;             for (int j = (0); j < (D); j++)               for (int k = (0); k < (D); k++) {                 next[k] = min(next[k], curr[j] + dp[0][S | (1 << i)][j][k]);               }             swap(curr, next);           }           {             for (int j = (0); j < (D); j++) next[j] = INF;             for (int j = (0); j < (D); j++)               for (int k = (0); k < (D); k++) {                 next[k] = min(next[k], curr[j] + dp[d][S | (1 << (i - 1))][j][k]);               }             swap(curr, next);           }         }       } else {         for (int i = 9; i >= 1; i--) {           for (int j = (0); j < (D); j++) next[j] = INF;           for (int j = (0); j < (D); j++)             for (int k = (0); k < (D); k++) {               next[k] = min(next[k], curr[j] + dp[0][S | (1 << i)][j][k]);             }           swap(curr, next);         }       }       for (int i = (0); i < (D); i++) dp[d + 1][S][s][i] = curr[i];     }   }   int main() {     cin >> n;     if (n == 0) {       cout << 0 << endl;       return 0;     }     int m = 0;     long long t = n;     while (t > 0) {       t /= 10;       m++;     }     for (int i = (0); i < (m - 1); i++)       for (int j = (0); j < (D); j++)         for (int k = (0); k < (D); k++)           for (int l = (0); l < (D + 1); l++) dp[i][j][k][l] = INF;     for (int i = (0); i < (1 << D); i++)       for (int j = (0); j < (D); j++) {         init(i, j);       }     for (int i = (0); i < (m - 2); i++) {       for (int S = (0); S < (1 << D); S++) {         calc(i, S);       }     }     long long *curr = pat[0], *next = pat[1];     for (int i = (0); i < (D); i++) {       curr[i] = (n % 10 == i) ? 0 : INF;     }     for (int i = (0); i < (m - 1); i++) {       n /= 10;       int S = 0;       int mod = n % 10;       long long t = n / 10;       while (t > 0) {         S |= (1 << (t % 10));         t /= 10;       }       if (i > 0) {         for (int j = mod; j >= 1; j--) {           {             for (int k = (0); k < (D); k++) next[k] = INF;             for (int k = (0); k < (D); k++)               for (int l = (0); l < (D); l++) {                 next[l] = min(next[l], curr[k] + dp[0][S | (1 << j)][k][l]);               }             swap(curr, next);           }           {             for (int k = (0); k < (D); k++) next[k] = INF;             for (int k = (0); k < (D); k++)               for (int l = (0); l < (D); l++) {                 next[l] = min(next[l], curr[k] + dp[i][S | (1 << (j - 1))][k][l]);               }             swap(curr, next);           }         }       } else {         for (int j = mod; j >= 1; j--) {           for (int k = (0); k < (D); k++) next[k] = INF;           for (int k = (0); k < (D); k++)             for (int l = (0); l < (D); l++) {               next[l] = min(next[l], curr[k] + dp[i][S | (1 << j)][k][l]);             }           swap(curr, next);         }       }     }     cout << *min_element(curr, curr + D) + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 2;   bool v[N], use[N];   int main() {     int n, i, j;     long long T;     vector<int> p;     scanf( %d , &n);     for (i = 2; i <= n; ++i) {       if (!v[i]) {         p.push_back(i);         T = i;         T *= i;         while (T <= n) v[T] = 1, T += i;       }     }     vector<pair<int, int> > ret;     vector<int> x;     for (i = p.size() - 1; i >= 1; --i) {       j = p[i];       x.clear();       while (j <= n) {         if (!use[j]) {           x.push_back(j);         }         j = j + 2 * p[i];       }       for (j = 0; j < x.size(); j += 2) {         if (j == x.size() - 1) break;         ret.push_back(make_pair(x[j], x[j + 1]));         use[x[j]] = 1, use[x[j + 1]] = 1;       }       if (x.size() & 1) {         if (p[i] * 2 <= n) {           ret.push_back(make_pair(x.back(), p[i] * 2));           use[x.back()] = 1, use[p[i] * 2] = 1;         }       }     }     x.clear();     for (i = 2; i <= n; i += 2)       if (!use[i]) x.push_back(i);     int sz = x.size() / 2;     sz *= 2;     for (i = 0; i < sz; i += 2) ret.push_back(make_pair(x[i], x[i + 1]));     printf( %d n , (int)ret.size());     for (i = 0; i < ret.size(); ++i)       printf( %d %d n , ret[i].first, ret[i].second);   }


#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   const int inf = ~0u >> 2;   const long long INF = ~0ull >> 2;   const double err = 1e-11;   const double pi = acos(-1);   inline long long read() {     long long x;     if (scanf( %lld , &x) == -1) exit(0);     return x;   }   inline double readf() {     double x;     if (scanf( %lf , &x) == -1) exit(0);     return x;   }   template <typename _>   inline _ sqr(_ x) {     return x * x;   }   ostream &operator<<(ostream &o, const pair<int, int> &x) {     return o <<  (  << x.first <<  ,  << x.second <<  ) ;   }   mt19937 rnd(time(0));   const int N = 20010;   const int mod = (0 ? 1000000007 : 998244353);   long long T;   string s;   deque<char> a;   set<char> Set;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> T;     while (T--) {       cin >> s;       Set.clear();       a.clear();       long long i = 0, f = 1;       for (auto c : s) {         if (Set.empty()) {           Set.insert(c);           a.push_back(c);           continue;         }         if (Set.count(c)) {           if (i != 0 && a[i - 1] == c) {             i--;             continue;           }           if (i != (long long)a.size() - 1 && a[i + 1] == c) {             i++;             continue;           }           f = false;         } else {           if (i == 0) {             a.push_front(c);             Set.insert(c);             continue;           }           if (i == (long long)a.size() - 1) {             a.push_back(c);             Set.insert(c);             i++;             continue;           }           f = false;         }       }       if (f) {         cout <<  YES  << endl;         for (long long i = ( a ), _ = ( z  + 1); i < _; i++)           if (!Set.count(i)) {             a.push_back(i);           }         for (auto i : a) cout << char(i);         cout << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};   int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};   int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};   const int M = 100005;   vector<int> Slope[M * 4], C[M * 4], idx[M * 4];   long long get(int n, long long id, long long x) {     return (Slope[n][id] * x + C[n][id]);   }   double cross(int n, int x, int y) {     return (double)(C[n][x] - C[n][y]) / (Slope[n][y] - Slope[n][x]);   }   void AddLine(int n, int id, long long p, long long q) {     if (Slope[n].size() > 0 && Slope[n].back() == p) {       if (C[n].back() < q) {         Slope[n].pop_back();         C[n].pop_back();         idx[n].pop_back();       } else         return;     }     Slope[n].push_back(p);     C[n].push_back(q);     idx[n].push_back(id);     int hsz = Slope[n].size();     while (hsz >= 3 && cross(n, hsz - 3, hsz - 2) > cross(n, hsz - 3, hsz - 1)) {       --hsz;       Slope[n][hsz - 1] = Slope[n][hsz];       C[n][hsz - 1] = C[n][hsz];       idx[n][hsz - 1] = idx[n][hsz];       Slope[n].pop_back();       C[n].pop_back();       idx[n].pop_back();     }   }   pair<long long, long long> query(int n, long long x) {     long long hsz = (int)Slope[n].size() - 1;     long long lw = 0, hi = hsz, mid, midd;     pair<long long, long long> ans = {-9e18, 0};     while (hi - lw > 3) {       mid = (lw + hi) / 2;       midd = min(hsz, mid + 1);       if (get(n, mid, x) >= get(n, midd, x)) {         hi = mid;       } else {         lw = midd;       }     }     for (long long i = lw; i <= hi; i++)       ans = max(ans, {get(n, i, x), idx[n][i]});     return ans;   }   void update(int l, int r, int k, int L, pair<long long, long long> p) {     if (l > L || r < L) return;     AddLine(k, L, p.first, p.second);     if (l == r) return;     int mid = (l + r) / 2;     update(l, mid, k * 2, L, p);     update(mid + 1, r, k * 2 + 1, L, p);   }   pair<long long, long long> query(int l, int r, int k, int L, int R,                                    long long val) {     if (l > R || r < L) return {-9e18, 0};     if (l >= L && r <= R) {       return query(k, val);     }     int mid = (l + r) / 2;     pair<long long, long long> ret = {-9e18, 0};     ret = max(ret, query(l, mid, k * 2, L, R, val));     ret = max(ret, query(mid + 1, r, k * 2 + 1, L, R, val));     return ret;   }   vector<pair<pair<long long, long long>, long long> > vec;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       vec.push_back({{y, x}, i});     }     sort(vec.begin(), vec.end());     for (auto z : vec) {       int id = z.second;       update(1, n, 1, id, z.first);     }     for (int i = 1; i <= m; i++) {       int l, r, x;       cin >> l >> r >> x;       cout << query(1, n, 1, l, r, x).second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y;   long long a[300010];   vector<long long> fac, facn;   vector<int> facx, facy;   vector<pair<int, int> > facv;   vector<long long> check;   int n;   long long sum[300010];   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void factorize(long long val) {     for (long long i = 2; i <= val && i <= 1000000ll; i++)       if (val % i == 0) {         fac.push_back(i);         while (val % i == 0) val /= i;       }     if (val > 1) {       long long q = (long long)(sqrt(val));       if (q * q == val) {         fac.push_back(q);         return;       }       for (int i = 1; i <= n; i++) check.push_back(a[i]);       check.push_back(x);       check.push_back(y);       long long g = val;       for (int i = 0; i < check.size(); i++) {         g = gcd(val, check[i]);         if (g != 1 && g != val) {           if (g < val / g) {             fac.push_back(g);             fac.push_back(val / g);           } else {             fac.push_back(val / g);             fac.push_back(g);           }           return;         }       }       fac.push_back(val);     }   }   int main() {     scanf( %d%I64d%I64d , &n, &x, &y);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     factorize(y);     if (y % x) {       printf( 0 );       return 0;     }     for (int i = 0; i < fac.size(); i++) facv.push_back(make_pair(0, 0));     long long x1 = x;     long long chunhua = y;     for (int i = 0; i < fac.size(); i++) {       int cnt = 0;       while (x1 % fac[i] == 0) {         x1 /= fac[i];         cnt++;       }       facv[i].first = cnt;     }     for (int i = 0; i < fac.size(); i++) {       int cnt = 0;       while (chunhua % fac[i] == 0) {         chunhua /= fac[i];         cnt++;       }       facv[i].second = cnt;     }     for (int i = 0; i < fac.size(); i++) {       if (facv[i].first != facv[i].second) {         facn.push_back(fac[i]);         facx.push_back(facv[i].first);         facy.push_back(facv[i].second);       }     }     for (int i = 1; i <= n; i++) {       if (a[i] % x) continue;       long long val = a[i];       int mask = 0;       for (int j = 0; j < facn.size(); j++) {         int cnt = 0;         while (val % facn[j] == 0) {           val /= facn[j];           cnt++;         }         mask += ((cnt > facx[j]) << j);       }       sum[mask]++;     }     for (int i = 0; i < facn.size(); i++)       for (int mask = 0; mask < (1 << facn.size()); mask++)         if (mask & (1 << i)) sum[mask] += sum[mask - (1 << i)];     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (y % a[i]) continue;       long long val = a[i];       int mask = 0;       for (int j = 0; j < facn.size(); j++) {         int cnt = 0;         while (val % facn[j] == 0) {           val /= facn[j];           cnt++;         }         mask += ((cnt < facy[j]) << j);       }       ans += sum[(1 << facn.size()) - mask - 1];     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc;     cin >> tc;     while (tc--) {       long long a, b, c, r;       cin >> a >> b >> c >> r;       if (a > b) swap(a, b);       long long left = c - r, right = c + r;       long long dist = 0;       if (b < left) {         cout << b - a <<   n ;       } else if (a > right) {         cout << b - a <<   n ;       } else {         dist += max(0ll, left - a);         dist += max(0ll, b - right);         cout << dist <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M = 1e9;   int ask(int x, int y) {     cout <<  ?   << x <<     << y << endl;     cin >> x;     return x;   }   int main() {     int s = ask(1, 1), k;     int u, v, l = 1, r = M, mid;     while (r > l + 1) {       mid = l + r >> 1;       k = ask(1, mid);       if (k + mid - 1 != s)         r = mid;       else         l = mid;     }     u = ask(1, l) + 1;     v = l;     printf( ! %d %d %d %d , u, v, v - 1 + M - ask(M, 1), u - 1 + M - ask(1, M));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l, r, k, x, y;   int main() {     scanf( %lld%lld%lld , &l, &r, &k), x = 1;     if (k == 1 || l == r || (r - l == 1 && l % 2 && (l ^ r) >= l))       return printf( %lld n1 n%lld n , l, l), 0;     for (int i = 0;; i++) {       if (x > l) {         y = i;         break;       }       x *= 2;     }     if (x + x / 2 <= r && k >= 3)       return printf( 0 n3 n%lld %lld %lld n , x - 1, x + x / 2, x + x / 2 - 1), 0;     if (r - l == 1)       return printf( %lld n2 n%lld %lld n , l ^ (l + 1), l, l + 1), 0;     if (l % 2) l++;     if (l + 3 <= r && k >= 4)       return printf( 0 n4 n%lld %lld %lld %lld n , l, l + 1, l + 2, l + 3), 0;     else       return printf( 1 n2 n%lld %lld n , l, l + 1), 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 10004, NA = -1, MaxC = 0x3F3F3F3F;   int m, n, x;   int f(int n, int m, int x) {     n -= x + x;     m -= x + x;     if (n <= 0 || m <= 0) return 0;     return (n * m + 1) >> 1;   }   int main(void) {     while (scanf(  %d %d %d , &n, &m, &x) != EOF) {       printf( %d n , f(n, m, x - 1) - f(n, m, x));     }     return 0;   }