#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long powmod(long long x, long long y) {     long long t;     for (t = 1; y; y >>= 1, x = x * x % mod)       if (y & 1) t = t * x % mod;     return t;   }   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); }   void smask(int pos, int &i) { i = i ^ (1 << pos); }   void clmask(int pos, int &i) { i = i & ~(1 << pos); }   bool chmask(int pos, int i) { return i & (1 << pos); }   double cordist(pair<double, double> a, pair<double, double> b) {     return sqrt(((a.first - b.first) * (a.first - b.first)) +                 ((a.second - b.second) * (a.second - b.second)));   }   long long n, m, q, r;   int primes[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};   void solve() {     cin >> n;     long long arr[n];     long long brr[n];     unordered_map<int, int> mp;     int k = 1;     for (int i = 0; i < n; i++) {       cin >> arr[i];       for (int j = 0; j < 11; j++) {         if (arr[i] % primes[j] == 0) {           if (mp.count(primes[j]) == 0) {             brr[i] = k;             mp[primes[j]] = k++;           } else {             brr[i] = mp[primes[j]];           }           break;         }       }     }     cout << k - 1 << endl;     for (int i = 0; i < n; i++) cout << brr[i] <<    ;     cout << endl;   }   int main() {     int k = 1;     cin >> k;     while (k--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       if (m >= 2 * n) {         cout << n <<     << 2 * n << endl;       } else {         cout <<  -1                <<  -1  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535897;   int main() {     string pass;     string str[10];     cin >> pass;     for (int i = 0; i < 10; i++) {       cin >> str[i];     }     for (int i = 0; i < 80; i += 10) {       string tmp = pass.substr(i, 10);       for (int io = 0; io < 10; io++) {         if (tmp == str[io]) {           cout << io;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, m, q;   struct Graph {     struct Edge {       int to, next;     } edge[N << 1];     int head[N], cnt;     Graph() {       memset(head, 0, sizeof(head));       cnt = 1;       return;     }     void add_edge(int u, int v) {       if (u == 0 || v == 0) return;       cnt++;       edge[cnt].to = v;       edge[cnt].next = head[u];       head[u] = cnt;       return;     }   };   Graph G1;   int dfn1[N], low1[N], Index1;   stack<int> s1;   int bel1[N], tot1;   void tarjan1(int u, int pre) {     dfn1[u] = low1[u] = ++Index1;     s1.push(u);     for (int i = G1.head[u]; i; i = G1.edge[i].next) {       int v = G1.edge[i].to;       if ((i ^ 1) == pre) continue;       if (!dfn1[v]) {         tarjan1(v, i);         low1[u] = min(low1[u], low1[v]);       } else         low1[u] = min(low1[u], dfn1[v]);     }     if (dfn1[u] == low1[u]) {       tot1++;       while (s1.top() != u) {         bel1[s1.top()] = tot1;         s1.pop();       }       bel1[u] = tot1;       s1.pop();       return;     }     return;   }   vector<int> G[N];   int f[N][20], dep[N];   int dfn[N], Index;   void dfs(int u, int father) {     dfn[u] = ++Index;     dep[u] = dep[father] + 1;     f[u][0] = father;     for (int i = 1; (1 << i) <= n; i++) f[u][i] = f[f[u][i - 1]][i - 1];     for (int v : G[u]) {       if (v == father) continue;       dfs(v, u);     }     return;   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = log2(n); i >= 0; i--)       if (dep[f[u][i]] >= dep[v]) u = f[u][i];     if (u == v) return u;     for (int i = log2(n); i >= 0; i--)       if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   int s[N << 1], top;   Graph G2;   vector<int> pos;   void ins(int u) {     int z = LCA(u, s[top]);     pos.push_back(u);     if (z == s[top])       s[++top] = u;     else {       pos.push_back(z);       while (top >= 2 && dep[s[top - 1]] > dep[z]) {         if (s[top - 1] != s[top])           G2.add_edge(s[top - 1], s[top]), G2.add_edge(s[top], s[top - 1]);         top--;       }       if (top) {         if (z != s[top]) G2.add_edge(z, s[top]), G2.add_edge(s[top], z);         top--;       }       s[++top] = z;       s[++top] = u;     }     return;   }   bool cmp(int a, int b) { return dfn[a] < dfn[b]; }   void build(vector<int>& k) {     sort(k.begin(), k.end());     k.erase(unique(k.begin(), k.end()), k.end());     sort(k.begin(), k.end(), cmp);     top = 0;     s[++top] = 0;     for (int x : k)       if (x != 0) ins(x);     while (top >= 2) {       if (s[top - 1] != s[top])         G2.add_edge(s[top - 1], s[top]), G2.add_edge(s[top], s[top - 1]);       top--;     }     sort(pos.begin(), pos.end());     pos.erase(unique(pos.begin(), pos.end()), pos.end());     return;   }   int dfn2[N], low2[N], Index2;   stack<int> s2;   int bel2[N], tot2;   void tarjan2(int u, int pre) {     dfn2[u] = low2[u] = ++Index2;     s2.push(u);     for (int i = G2.head[u]; i; i = G2.edge[i].next) {       int v = G2.edge[i].to;       if ((i ^ 1) == pre) continue;       if (!dfn2[v]) {         tarjan2(v, i);         low2[u] = min(low2[u], low2[v]);       } else         low2[u] = min(low2[u], dfn2[v]);     }     if (dfn2[u] == low2[u]) {       tot2++;       while (s2.top() != u) {         bel2[s2.top()] = tot2;         s2.pop();       }       bel2[u] = tot2;       s2.pop();       return;     }     return;   }   int x[N];   long long R;   int rotate(int element) {     element = (element + R) % n;     if (element == 0) {       element = n;     }     return element;   }   void clear() {     for (int u : pos) {       G2.head[u] = 0;       dfn2[u] = low2[u] = 0;       bel2[u] = 0;     }     pos.clear();     return;   }   int Case = 0;   void solve() {     Case++;     int ni, mi;     scanf( %d%d , &ni, &mi);     vector<int> k;     for (int i = 1; i <= ni; i++) {       scanf( %d , &x[i]);       x[i] = rotate(x[i]);       x[i] = bel1[x[i]];       k.push_back(x[i]);     }     G2.cnt = 1;     for (int i = 1; i <= mi; i++) {       int x, y;       scanf( %d%d , &x, &y);       x = rotate(x), y = rotate(y);       x = bel1[x], y = bel1[y];       if (x == y) continue;       G2.add_edge(x, y);       G2.add_edge(y, x);       k.push_back(x), k.push_back(y);     }     build(k);     Index2 = tot2 = 0;     while (!s2.empty()) s2.pop();     for (int u : pos)       if (!dfn2[u]) tarjan2(u, 0);     for (int i = 2; i <= ni; i++)       if (bel2[x[i]] != bel2[x[i - 1]]) {         printf( NO n );         clear();         return;       }     printf( YES n );     R += Case;     clear();     return;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       G1.add_edge(x, y);       G1.add_edge(y, x);     }     for (int i = 1; i <= n; i++)       if (!dfn1[i]) tarjan1(i, 0);     for (int u = 1; u <= n; u++)       for (int i = G1.head[u]; i; i = G1.edge[i].next) {         int v = G1.edge[i].to;         int x = bel1[u], y = bel1[v];         if (x < y) G[x].push_back(y), G[y].push_back(x);       }     for (int i = 1; i <= tot1; i++)       if (!dep[i]) dfs(i, 0);     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (long long &i : a) cin >> i;     sort(a.begin(), a.end());     a.resize(unique(a.begin(), a.end()) - a.begin());     n = a.size();     if (k == 1 and n > 1) {       cout << -1 << endl;       return;     } else if (k >= n) {       cout << 1 << endl;       return;     }     long long ans;     ans = 1, n -= k, k--;     ans += (n + k - 1) / k;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);     long long t_c = 1;     cin >> t_c;     while (t_c--) solve();   }


#include <bits/stdc++.h>   int read() {     int ans = 0, c, f = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) f *= -1;     do ans = ans * 10 + c -  0 ;     while (isdigit(c = getchar()));     return ans * f;   }   const int N = 1000050;   int n, a[N];   long long S;   long long calc(long long p) {     long long ans = 0, t = 0;     for (int i = 0; i < n; ++i) {       t = (t + a[i]) % p;       ans += std::min(t, p - t);     }     return ans;   }   int main() {     n = read();     for (int i = 0; i < n; ++i) S += a[i] = read();     if (S == 1) {       puts( -1 );       return 0;     }     long long ans = 0x7fffffffffffffffLL;     for (long long i = 2; i * i <= S; ++i)       if (S % i == 0) {         ans = std::min(ans, calc(i));         while (S % i == 0) S /= i;       }     if (S != 1) ans = std::min(ans, calc(S));     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   vector<long long int> adj[N];   long long int depth[N];   void dfs(long long int n, long long int p) {     for (auto x : adj[n]) {       if (x != p) {         depth[x] = depth[n] + 1;         dfs(x, n);       }     }   }   void solve() {     long long int n, a, b, da, db;     cin >> n >> a >> b >> da >> db;     for (long long int i = 1; i <= n; ++i) {       adj[i].clear();       depth[i] = 0;     }     for (long long int i = 1; i < n; ++i) {       long long int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     long long int maxi = -1, idx = -1;     dfs(1, -1);     for (long long int i = 1; i <= n; ++i) {       if (depth[i] > maxi) {         idx = i;         maxi = depth[i];       }     }     for (long long int i = 1; i <= n; ++i) {       depth[i] = 0;     }     dfs(idx, -1);     for (long long int i = 1; i <= n; ++i) {       if (depth[i] > maxi) {         idx = i;         maxi = depth[i];       }     }     for (long long int i = 1; i <= n; ++i) {       depth[i] = 0;     }     if (2 * da >= min(maxi, db)) {       cout <<  Alice  << endl;       return;     }     dfs(a, -1);     if (da >= depth[b]) {       cout <<  Alice  << endl;     } else {       cout <<  Bob  << endl;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int sz = 1;   int t[N << 2], clr[N << 2];   inline void pushclear(int k) {     if (!clr[k]) return;     t[k] = 0;     if (k < sz) clr[k << 1] = clr[k << 1 | 1] = 1;     clr[k] = 0;   }   inline void clear(int k, int l, int r, int a, int b) {     pushclear(k);     if (a > r || b < l) return;     if (a >= l && b <= r) {       clr[k] = 1;       pushclear(k);       return;     }     int mid = (a + b) >> 1;     clear(k << 1, l, r, a, mid), clear(k << 1 | 1, l, r, mid + 1, b);     t[k] = t[k << 1] + t[k << 1 | 1];   }   inline void add(int k, int pos, int a, int b, int x) {     pushclear(k);     if (a == b) {       t[k] += x;       return;     }     int mid = (a + b) >> 1;     if (pos <= mid)       add(k << 1, pos, a, mid, x);     else       add(k << 1 | 1, pos, mid + 1, b, x);     t[k] = t[k << 1] + t[k << 1 | 1];   }   int n, init_x, init_y;   int a[N];   vector<int> vec;   inline int getpos(int x) {     return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;   }   bool check(int mid) {     for (int i = 1; i < (sz << 1); i++) t[i] = clr[i] = 0;     add(1, getpos(init_x), 1, sz, 1);     add(1, getpos(init_y), 1, sz, 1);     for (int i = 1; i <= n; i++) {       int l = lower_bound(vec.begin(), vec.end(), a[i] - mid) - vec.begin() + 1;       int r = lower_bound(vec.begin(), vec.end(), a[i] + mid) - vec.begin() + 1;       if (r > vec.size() || vec[r - 1] > a[i] + mid) r--;       if (l - 1 >= 1) clear(1, 1, l - 1, 1, sz);       if (r + 1 <= sz) clear(1, r + 1, sz, 1, sz);       if (t[1] == 0) return false;       add(1, getpos(a[i]), 1, sz, 1);     }     return true;   }   int main() {     scanf( %d%d%d , &n, &init_x, &init_y);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vec.emplace_back(a[i]);     }     vec.emplace_back(init_x);     vec.emplace_back(init_y);     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     while (sz < vec.size()) sz <<= 1;     int l = abs(init_x - init_y), r = 1000000000, mid, ans;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid - 1, ans = mid;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout <<  Black  << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:836777216 )   using namespace std;   int n, t, m;   int nextId = 0;   int max_online = 0;   int cur_online = 0;   deque<pair<int, int> > id_q;   int cnt[86400];   vector<int> answer;   int main(void) {     memset((cnt), (0), sizeof((cnt)));     scanf( %d%d%d , &n, &m, &t);     for (int(i) = 0; (i) < (n); (i)++) {       int hh, mm, ss;       scanf( %d:%d:%d , &hh, &mm, &ss);       int time_ = hh * 60 * 60 + mm * 60 + ss;       cnt[time_]++;     }     for (int(i) = 0; (i) < (86400); (i)++) {       while ((int)(id_q).size() && (id_q.front().second + t == i)) {         id_q.pop_front();         cur_online--;       }       if (cnt[i]) {         for (int(j) = 0; (j) < (cnt[i]); (j)++) {           if (cur_online < m) {             id_q.push_back(make_pair(nextId++, i));             cur_online++;             max_online = max(max_online, cur_online);             answer.push_back(nextId);           } else {             id_q.back().second = i;             answer.push_back(nextId);           }         }       }     }     if (max_online != m) {       printf( No solution n );     } else {       printf( %d n , nextId);       for (int(i) = 0; (i) < ((int)(answer).size()); (i)++) {         printf( %d n , answer[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a1;       cin >> a1;       cout << 1 <<     << (a1 - 1);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   long long n, a, cnt, ans, sum, l, r;   string g;   void DNM() {     cin >> n;     cin >> g;     sort(g.begin(), g.end());     cout << g << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int Qu_l_uQ = 1;     while (Qu_l_uQ--) DNM();   }


#include <bits/stdc++.h>   using namespace std;   long long t[2300];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , &t[i]);     sort(t, t + n);     long long sum = 0;     for (int i = 0; i < k; i++) sum += t[i];     printf( %lld n , sum);   }


#include <bits/stdc++.h>   using namespace std;   int M = 1000000007;   map<string, long long int> b1;   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     long long int n, k;     cin >> n >> k;     long long int c = max(n - 2 * k, 0ll);     long long int a = n * (n - 1) / 2 - c * (c - 1) / 2;     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& t) {     T f = 1;     char ch = getchar();     t = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar();     t *= f;   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   int t, T, n, m;   int n1 = 1e9, n2 = -1e9;   int l[100005], r[100005];   char ans[100005];   inline bool pd(int i, int x) { return l[i] <= x && x <= r[i]; }   vector<int> edge[100005];   bool dfs(int now) {     for (int i = 0; i < edge[now].size(); i++)       if (ans[edge[now][i]] == 0) {         ans[edge[now][i]] = 3 - ans[now];         if (dfs(edge[now][i]) == 0) return 0;       } else if (ans[edge[now][i]] == ans[now])         return 0;     return 1;   }   int main() {     read(t, T, n, m);     for (int i = 1; i <= n; i++)       read(l[i], r[i]), n1 = min(n1, r[i]), n2 = max(n2, l[i]);     if (n1 + n2 < t) n2 = t - n1;     if (n1 + n2 > T) n1 = T - n2;     if (n1 < 0 || n2 < 0) return printf( IMPOSSIBLE n ), 0;     for (int i = 1; i <= n; i++) {       if (pd(i, n1) == 0 && pd(i, n2) == 0) return printf( IMPOSSIBLE n ), 0;       if (pd(i, n1) == 1 && pd(i, n2) == 0) ans[i] = 1;       if (pd(i, n1) == 0 && pd(i, n2) == 1) ans[i] = 2;     }     for (int i = 1, x, y; i <= m; i++) {       read(x, y);       edge[x].push_back(y);       edge[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (ans[i])         if (dfs(i) == 0) return printf( IMPOSSIBLE n ), 0;     for (int i = 1; i <= n; i++)       if (ans[i] == 0) {         ans[i] = 1;         if (dfs(i) == 0) return printf( IMPOSSIBLE n ), 0;       }     printf( POSSIBLE n%d %d n , n1, n2);     for (int i = 1; i <= n; i++) ans[i] +=  0 ;     printf( %s n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T &first) {     return first * first;   }   template <class _T>   inline string tostr(const _T &a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 1e-9;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void fft(vector<complex<long double> > &a, bool invert) {     int n = (int)a.size();     for (int i = 1, j = 0; i < n; ++i) {       int bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       long double ang = 2 * PI / len * (invert ? -1 : 1);       complex<long double> wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         complex<long double> w(1);         for (int j = 0; j < len / 2; ++j) {           complex<long double> u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   inline void input(int &a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = (a << 3) + (a << 1) + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(long long a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[20];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   struct lnum {     vector<int> a;     int base;     lnum(int num = 0, int base = 1000000000) : base(base) {       if (!num) a.resize(1);       while (num) {         a.push_back(num % base);         num /= base;       }     }     inline int len() const { return a.size(); }     lnum &operator=(const lnum &l) {       if (this != &l) {         a = l.a;         base = l.base;       }       return *this;     }     inline friend lnum operator+(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int ln = l.len(), rn = r.len();       int n = max(ln, rn);       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = o;         if (i < ln) s += l.a[i];         if (i < rn) s += r.a[i];         o = s >= base;         if (o) s -= base;         ret.a[i] = s;       }       if (o) ret.a.push_back(1);       return ret;     }     inline friend lnum operator-(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int n = l.len();       int rn = r.len();       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = l.a[i] - o;         if (i < rn) s -= r.a[i];         o = s < 0;         if (o) s += base;         ret.a[i] = s;       }       if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator*(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       if (l.len() * r.len() > 1000000) {         vector<complex<long double> > fa(l.a.begin(), l.a.end()),             fb(r.a.begin(), r.a.end());         int n = 1;         while (n < max(l.len(), r.len())) n <<= 1;         n <<= 1;         fa.resize(n), fb.resize(n);         fft(fa, false), fft(fb, false);         for (int i = 0; i < n; ++i) fa[i] *= fb[i];         fft(fa, true);         ret.a.resize(n);         for (int i = 0; i < n; ++i) ret.a[i] = int(fa[i].real() + 0.5);         int carry = 0;         for (int i = 0; i < n; ++i) {           ret.a[i] += carry;           carry = ret.a[i] / base;           ret.a[i] %= base;         }       } else {         ret.a.resize(l.len() + r.len());         for (int i = 0; i < l.len(); ++i)           for (int j = 0, carry = 0; j < r.len() || carry; ++j) {             long long cur = ret.a[i + j] +                             (long long)l.a[i] * (j < r.len() ? r.a[j] : 0) +                             carry;             ret.a[i + j] = cur % base;             carry = cur / base;           }       }       while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator/(const lnum &l, const int &r) {       lnum ret(0, l.base);       ret.a.resize(l.len());       int carry = 0;       for (int i = l.len() - 1; i >= 0; --i) {         long long cur = l.a[i] + (long long)carry * l.base;         ret.a[i] = cur / r;         carry = cur % r;       }       while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back();       return ret;     }     inline friend bool operator<(const lnum &l, const lnum &r) {       if (l.len() < r.len()) return true;       if (l.len() > r.len()) return false;       int n = l.len();       for (int i = n - 1; i >= 0; --i) {         if (l.a[i] < r.a[i]) return true;         if (l.a[i] > r.a[i]) return false;       }       return false;     }     inline friend bool operator>(const lnum &l, const lnum &r) { return r < l; }     inline friend bool operator==(const lnum &l, const lnum &r) {       if (l.len() != r.len()) return false;       int n = l.len();       for (int i = n - 1; i; --i) {         if (l.a[i] != r.a[i]) return false;       }       return true;     }     inline friend bool operator!=(const lnum &l, const lnum &r) {       return !(l == r);     }     inline void print() {       if (base == 1000000000) {         printf( %d , a.back());         for (int i = a.size() - 2; i >= 0; --i) printf( %09d , a[i]);       } else {         for (int i = a.size() - 1; i >= 0; --i) printf( %d , a[i]);       }     }   };   int main() {     string s;     cin >> s;     int n = s.length();     int ans[n][n];     memset((ans), 0, sizeof(ans));     for (int i = 0; i < n; ++i)       for (int j = i; j < n; ++j)         for (int k = 0; k < (j - i + 1) / 2; ++k)           if (s[i + k] != s[j - k]) ++ans[i][j];     int(k);     input((k));     ;     int dp[n + 1][k + 1];     int p[n + 1][k + 1];     for (int i = 0; i <= n; ++i)       for (int j = 0; j <= k; ++j) dp[i][j] = 1e9;     dp[0][0] = 0;     for (int i = 0; i < n; ++i)       for (int j = 1; j <= k; ++j)         for (int l = 0; l <= i; ++l)           if (dp[i + 1][j] > dp[l][j - 1] + ans[l][i]) {             dp[i + 1][j] = dp[l][j - 1] + ans[l][i];             p[i + 1][j] = l;           }     int best = 1;     for (int i = 1; i <= k; ++i)       if (dp[n][i] < dp[n][best]) best = i;     cout << dp[n][best] << endl;     vector<string> t;     int cur = n;     while (best) {       t.push_back(s.substr(p[cur][best], cur - p[cur][best]));       cur = p[cur][best];       --best;     }     reverse((t).begin(), (t).end());     for (int i = 0; i < t.size(); ++i) {       if (i) cout <<  + ;       for (int j = 0; j < t[i].length(); ++j)         if (t[i][j] != t[i][t[i].length() - 1 - j])           t[i][j] = t[i][t[i].length() - 1 - j];       cout << t[i];     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, m;   int cnt1[N], cnt2[N];   struct Fenwick_tree {     vector<long long> t;     int n;     void init(int _n) {       n = _n;       t.assign(n + 1, 0);     }     void add(int r, int x) {       for (; r <= n; r = (r | (r + 1))) t[r] += 1LL * x;     }     long long get_sum(int r) {       long long res = 0LL;       for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r];       return res;     }     long long get_sum(int l, int r) {       if (r < l) return 0LL;       return get_sum(r) - get_sum(l - 1);     }   };   Fenwick_tree t1, t2;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     t1.init(n);     t2.init(n);     long long free = 1LL * n * n;     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       if (cnt2[y] == 0)         free -= (n - 1 - t1.get_sum(1, x - 1) - t1.get_sum(x + 1, n));       if (cnt1[x] == 0)         free -= (n - 1 - t2.get_sum(1, y - 1) - t2.get_sum(y + 1, n));       if (cnt1[x] == 0 && cnt2[y] == 0) free--;       cnt1[x] = cnt2[y] = true;       if (t1.get_sum(x, x) == 0) t1.add(x, 1);       if (t2.get_sum(y, y) == 0) t2.add(y, 1);       cout << free <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 200010, ALPHA = 30;   int N;   long long Sum[ALPHA];   double Ans;   char A[NMAX], B[NMAX];   int main() {     scanf( %i n , &N);     gets(A + 1);     gets(B + 1);     long long Posib = (1LL * N * (N + 1) * (2 * N + 1)) / 6;     for (int i = N; i; --i) {       int C = B[i] -  A  + 1;       Sum[C] += N - i + 1;       C = A[i] -  A  + 1;       Ans += (1LL * i * Sum[C]) / (1.0 * Posib);     }     for (int i = 0; i < ALPHA; ++i) Sum[i] = 0;     for (int i = N; i; --i) {       int C = B[i] -  A  + 1;       Ans += (1LL * i * Sum[C]) / (1.0 * Posib);       C = A[i] -  A  + 1;       Sum[C] += N - i + 1;     }     printf( %.9f n , 1.0 * Ans);   }


#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int to, next, w;   } e[400010];   int head[200010], top;   void add(int u, int v, int w) {     e[top].to = v;     e[top].next = head[u];     e[top].w = w;     head[u] = top++;   }   vector<int> vv;   int vis[200010], tmpp = -1;   long long in_max;   int fa[200010], id[400010];   long long dep[200010];   long long l[400010], r[400010], wl[400010], idtop, val[400010];   vector<int> o;   void dfs(int x, int fa) {     if (vis[x]) {       tmpp = x;       throw  w23c3c3 ;     }     vis[x] = 1;     vv.push_back(x);     int i;     for (i = head[x]; ~i; i = e[i].next) {       if (e[i].to == fa) continue;       o.push_back(e[i].w);       dfs(e[i].to, x);       o.pop_back();     }     vv.pop_back();   }   void dfs1(int x) {     int i;     long long max_ = 0, se = 0, tmp;     for (i = head[x]; ~i; i = e[i].next) {       if (vis[e[i].to] || e[i].to == fa[x]) continue;       fa[e[i].to] = x;       dfs1(e[i].to);       tmp = dep[e[i].to] + e[i].w;       if (tmp > max_) {         se = max_;         max_ = tmp;       } else {         if (tmp > se) {           se = tmp;         }       }     }     in_max = max(in_max, max_ + se);     dep[x] = max_;   }   struct __ {     int id;     long long val;     bool operator<(const __ &ob) const {       if (val != ob.val) return val > ob.val;       return id < ob.id;     }   };   multiset<__> L, R;   int main() {     memset(head, 255, sizeof(head));     int n;     scanf( %d , &n);     int i;     int u, v, w;     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &u, &v, &w);       add(u, v, w);       add(v, u, w);     }     int tmp;     try {       dfs(1, 0);     } catch (...) {     }     tmp = tmpp;     memset(vis, 0, sizeof(vis));     int len = 1;     wl[idtop] = o.back();     o.pop_back();     id[idtop++] = tmp;     vis[tmp] = 1;     while (1) {       if (vv.back() == tmp) break;       len++;       wl[idtop] = o.back();       o.pop_back();       id[idtop++] = vv.back();       vv.pop_back();       vis[id[idtop - 1]] = 1;     }     vv.clear();     for (i = 1; i <= n; i++) {       if (vis[i]) {         dfs1(i);       }     }     for (i = 0; i < len; i++) {       val[i] = dep[id[i]];     }     for (i = 0; i < len; i++) {       id[i + len] = id[i];       wl[i + len] = wl[i];       val[i + len] = val[i];     }     l[0] = r[0] = val[0];     for (i = 1; i < (len << 1) - 1; i++) {       l[i] = l[i - 1] - val[i - 1] - wl[i - 1] + val[i];       r[i] = r[i - 1] - val[i - 1] + wl[i - 1] + val[i];     }     long long ans = 998244353998244347;     for (i = 0; i < len - 1; i++) {       L.insert((__){id[i], l[i]});       R.insert((__){id[i], r[i]});     }     __ tmpl1, tmpl2, tmpr1, tmpr2;     for (i = len - 1; i + 1 < len << 1; i++) {       L.insert((__){id[i], l[i]});       R.insert((__){id[i], r[i]});       tmpl1 = *L.begin();       tmpl2 = *++L.begin();       tmpr1 = *R.begin();       tmpr2 = *++R.begin();       if (tmpl1.id != tmpr1.id) {         ans = min(ans, max(in_max, tmpl1.val + tmpr1.val));       } else {         ans = min(ans,                   max(in_max, max(tmpl1.val + tmpr2.val, tmpl2.val + tmpr1.val)));       }       L.erase(L.lower_bound((__){id[i - (len - 1)], l[i - (len - 1)]}));       R.erase(R.lower_bound((__){id[i - (len - 1)], r[i - (len - 1)]}));     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long v[2][200005];   long long c[2][200005];   int n, k, a, b, q, e, day, ord;   const int maxn = 200005;   void add(int i, int value, int z) {     for (; i < maxn; i += (i + 1) & -(i + 1)) v[z][i] += value;   }   long long get(int i, int z) {     long long res = 0;     for (; i >= 0; i -= (i + 1) & -(i + 1)) res += v[z][i];     return res;   }   long long g = 0;   int main() {     scanf( %d%d%d%d%d , &n, &k, &a, &b, &q);     while (q--) {       scanf( %d , &e);       if (e == 1) {         scanf( %d %d , &day, &ord);         long long ord1 = ord, ord2 = ord;         if (c[0][day] <= b) {           long long need = (long long)b - c[0][day];           if (need <= ord1) {             ord1 = need;             c[0][day] = b;           } else             c[0][day] += (long long)ord1;           add(day, ord1, 0);         }         if (c[1][day] <= a) {           long long need = (long long)a - c[1][day];           if (need <= ord2) {             ord2 = need;             c[1][day] = a;           } else             c[1][day] += ord2;           add(day, ord2, 1);         }       } else {         scanf( %d , &day);         g = 0;         if (day - 1) g = get(day - 1, 0);         g += (long long)(get(200004, 1) - get(day + k - 1, 1));         printf( %I64d n , g);       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     long long n = s.size();     long long b = n / 2;     if (n % 2) {       while (1) {         if (s[b] ==  A ) break;         if (s[b] ==  H ) break;         if (s[b] ==  I ) break;         if (s[b] ==  M ) break;         if (s[b] ==  U ) break;         if (s[b] ==  T ) break;         if (s[b] ==  O ) break;         if (s[b] ==  I ) break;         if (s[b] ==  W ) break;         if (s[b] ==  V ) break;         if (s[b] ==  Y ) break;         if (s[b] ==  X ) break;         cout <<  NO  << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (s[i] ==  A ) {         continue;       } else if (s[i] ==  W ) {         continue;       } else if (s[i] ==  T ) {         continue;       } else if (s[i] ==  Y ) {         continue;       } else if (s[i] ==  U ) {         continue;       } else if (s[i] ==  I ) {         continue;       } else if (s[i] ==  O ) {         continue;       } else if (s[i] ==  H ) {         continue;       } else if (s[i] ==  X ) {         continue;       } else if (s[i] ==  V ) {         continue;       } else if (s[i] ==  M ) {         continue;       } else {         cout <<  NO  << endl;         return 0;       }     }     for (int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000;   long long n, ans;   int main() {     while (~scanf( %lld , &n)) {       n--;       int l = 0;       for (int i = 0; i < 50; i++)         if ((1ll << i) & n) l = i;       ans = n / 2 + n % 2;       int f = l;       for (; f > 0; f--) {         if ((1ll << f) & n) {           int k = f;           ans += (1ll << f);           for (int i = 1; i < k; i++) {             ans += (1ll << i) * (1ll << (k - 1 - i));           }         }       }       printf( %lld n , ans);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int M127;   string s;   int S, k, n;   int e[N][N];   int f[N][N][N];   int conv(char c) { return c -  a  + 1; }   int main() {     cin >> s;     S = s.size();     s =     + s;     memset(f, -127, sizeof(f));     M127 = f[0][0][0];     k = ({       long long first = 0;       int c = getchar(), n = 0;       for (; !isdigit(c); c = getchar()) n = (c ==  - );       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     });     n = ({       long long first = 0;       int c = getchar(), n = 0;       for (; !isdigit(c); c = getchar()) n = (c ==  - );       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     });     for (int i(1); i <= n; i++)       e[conv(({         char c = getchar();         while (c ==     || c ==   n ) c = getchar();         c;       }))][conv(({         char c = getchar();         while (c ==     || c ==   n ) c = getchar();         c;       }))] = ({         long long first = 0;         int c = getchar(), n = 0;         for (; !isdigit(c); c = getchar()) n = (c ==  - );         for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;         n ? -first : first;       });     for (int i(1); i <= 26; i++) f[1][i][i != conv(s[1])] = 0;     for (int i(2); i <= S; i++)       for (int j(1); j <= 26; j++)         for (int kk(0); kk <= k; kk++) {           int ok = j != conv(s[i]);           if (kk < ok) continue;           for (int j2(1); j2 <= 26; j2++)             if (f[i - 1][j2][kk - ok] != M127)               f[i][j][kk] = max(f[i - 1][j2][kk - ok] + e[j2][j], f[i][j][kk]);         }     int res = M127;     for (int j(1); j <= 26; j++)       for (int kk(0); kk <= k; kk++) res = max(res, f[S][j][kk]);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1000000007;   void solve() {     int p, f;     cin >> p >> f;     if (f > p) swap(p, f);     int cs, cw;     cin >> cs >> cw;     int s, w;     cin >> s >> w;     if (w > s) {       swap(w, s);       swap(cs, cw);     }     int maxv = 0;     for (int x = 0; x <= min(cw, f / w); x++) {       int curr = x;       int fr = f - x * w;       int pr = p;       int csr = cs;       int cwr = cw - x;       int t = min(csr, fr / s);       curr += t;       csr -= t;       curr += min(cwr, pr / w);       pr -= min(cwr, pr / w) * w;       curr += min(csr, pr / s);       maxv = max(maxv, curr);     }     cout << maxv << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt = 1;     cin >> tt;     for (int ttt = 1; ttt <= tt; ttt++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, l, a[100001], i, check, p, d;   bool b[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> l;     t = 0;     fill(b + 1, b + 1 + n, false);     for (i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > l) {         if (i - 1 == 0 || (i - 1 > 0 && b[i - 1] == false)) t++;         b[i] = true;       }     }     for (i = 1; i <= m; i++) {       cin >> check;       if (check == 0)         cout << t <<   n ;       else {         cin >> p >> d;         a[p] += d;         if (a[p] > l && b[p] == false) {           if (p > 1 && p < n) {             if (b[p - 1] == true && b[p + 1] == true) {               if (t > 1) t--;             } else if (b[p - 1] == false && b[p + 1] == false) {               if (t < n) t++;             }           } else if (p == 1) {             if (b[p + 1] == false) {               if (t < n) t++;             }           } else if (p == n) {             if (b[p - 1] == false) {               if (t < n) t++;             }           }           b[p] = true;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-6;   vector<int> mp[105], ans;   char s[105][105];   int len[105], tmp[30];   queue<int> q;   bool solve(int x, int y) {     for (int i = 0; i < len[x] && i < len[y]; i++) {       if (s[x][i] != s[y][i]) {         mp[s[x][i] -  a ].push_back(s[y][i] -  a );         tmp[s[y][i] -  a ]++;         return true;       }     }     if (len[x] > len[y]) return false;   }   bool ok() {     for (int i = 0; i < 26; i++)       if (tmp[i] == 0) {         ans.push_back(i);         q.push(i);       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < mp[u].size(); i++) {         int v = mp[u][i];         tmp[v]--;         if (tmp[v] == 0) {           q.push(v);           ans.push_back(v);         }       }     }     return ans.size() == 26;   }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         scanf( %s , s[i]);         len[i] = strlen(s[i]);       }       bool flag = 0;       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++)           if (!solve(i, j)) flag = 1;       if ((!flag) && ok()) {         for (int i = 0; i < 26; i++) printf( %c , ans[i] +  a );         printf(  n );       } else         printf( Impossible n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c, delta, x1, x2;     cin >> a >> b >> c;     delta = b * b - 4.0 * a * c;     delta = sqrt(delta);     x1 = (-b + delta) / (2.0 * a);     x2 = (-b - delta) / (2.0 * a);     if (x1 < x2) swap(x1, x2);     cout << fixed << setprecision(8) << x1 << endl          << fixed << setprecision(8) << x2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int main() {     unsigned long long n, m, k;     cin >> n >> m >> k;     unsigned long long h = 2 * n * m;     if (h % k == 0) {       cout <<  YES  << endl;       bool isKEven = false;       if (k % 2 == 0) {         isKEven = true;         k /= 2;       }       int y1 = 0, x2 = 0, x3 = 0, y3 = 0;       unsigned long long gx = gcd(n, k);       k /= gx;       unsigned long long x1 = n / gx;       unsigned long long gy = gcd(m, k);       k /= gy;       unsigned long long y2 = m / gy;       if (!isKEven) {         if (x1 < n) {           x1 *= 2;         } else {           y2 *= 2;         }       }       cout << x1 <<     << y1 << endl;       cout << x2 <<     << y2 << endl;       cout << x3 <<     << y3 << endl;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     int c[n];     memset(c, 0, sizeof(c));     while (m--) {       int x, y = 0, p = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &x);         if (x > y) {           y = x;           p = i;         }       }       c[p]++;     }     int y = 0, p;     for (int i = 0; i < n; i++) {       if (c[i] > y) {         y = c[i];         p = i;       }     }     printf( %d , p + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp(int a, int b, int row) {     if (row == 1 && a < 3 && b >= 3) {       return -1;     }     if (row == 0 && a < 3 && b >= 3) {       return 0;     }     if (row == 1 && a < 3 && b < 3) {       return 1;     }     if (row == 0 && a < 3 && b < 3) {       return 0;     }     if (row == 1 && a >= 3 && b >= 3) {       return 0;     }     if (row == 0 && a >= 3 && b >= 3) {       return 1;     }     if (row == 1 && a >= 3 && b < 3) {       return 1;     }     if (row == 0 && a >= 3 && b < 3) {       return -1;     } else {       return -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string arr, brr;       cin >> arr;       cin >> brr;       int x = dp(arr[0] -  0 , brr[0] -  0 , 0);       for (int i = 1; i < n; i++) {         x = dp(arr[i] -  0 , brr[i] -  0 , x);         if (x == -1) {           break;         }       }       if (x != 1) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long linf = 1LL << 62;   const int mod = 1e9 + 7;   const int MAX = 510000;   const int V = 100005;   struct UnionFind {     vector<long long> p;     vector<long long> rank;     vector<long long> cnt;     UnionFind(long long n) {       rank.resize(n, 0);       p.resize(n, 0);       cnt.resize(n, 1);       for (long long i = 0; i < (n); i++) {         p[i] = i;         rank[i] = 0;         cnt[i] = 1;       }     }     long long find(long long x) {       if (x != p[x]) p[x] = find(p[x]);       return p[x];     }     bool same(long long x, long long y) { return find(x) == find(y); }     void unite(long long x, long long y) {       x = find(x);       y = find(y);       if (x == y) return;       if (rank[x] > rank[y]) {         p[y] = x;         cnt[x] += cnt[y];       } else {         p[x] = y;         cnt[y] += cnt[x];         if (rank[x] == rank[y]) rank[y]++;       }     }     long long getcnt(long long x) { return cnt[find(x)]; }   };   int main() {     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       UnionFind uf(n);       for (long long i = 0; i < (n); i++) {         long long a;         cin >> a;         a--;         uf.unite(i, a);       }       for (long long i = 0; i < (n); i++) cout << uf.getcnt(i) <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1};   const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6;   int Case = 1, cas = 0;   string S;   struct exo {     int Open, Close, SubLen;     exo() {}     exo(int a, int b, int c) { Open = a, Close = b, SubLen = c; }   } tree[3 * mx + 5];   exo Combine(exo p, exo q) {     int mn = min(p.Open, q.Close);     int a = p.Open + q.Open - mn;     int b = p.Close + q.Close - mn;     int c = p.SubLen + q.SubLen + 2 * mn;     return exo(a, b, c);   }   void build(int node, int L, int R) {     if (L > R) return;     if (L == R) {       if (S[L] ==  ( )         tree[node] = exo(1, 0, 0);       else         tree[node] = exo(0, 1, 0);       return;     }     int mid = (L + R) >> 1;     int Left = node << 1;     int Right = Left | 1;     build(Left, L, mid);     build(Right, mid + 1, R);     tree[node] = Combine(tree[Left], tree[Right]);   }   exo query(int node, int L, int R, int i, int j) {     if (i > R || j < L) return exo(0, 0, 0);     if (i <= L && R <= j) return tree[node];     int mid = (L + R) >> 1;     int Left = node << 1;     int Right = Left | 1;     exo p = query(Left, L, mid, i, j);     exo q = query(Right, mid + 1, R, i, j);     return Combine(p, q);   }   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0);     ;     cin >> S;     int n = S.size();     build(1, 0, n - 1);     int Q;     cin >> Q;     while (Q--) {       int L, R;       cin >> L >> R;       L--, R--;       cout << query(1, 0, n - 1, L, R).SubLen << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   vector<int> v[100010];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) ans += v[i].size() % 2;     ans /= 2;     for (int i = 1; i <= n; ++i) {       if (v[i].size() != 2) continue;       int x = v[i][0], y = v[i][1];       if (x == y) {         v[x].clear();         ++ans;         continue;       }       v[x][v[x][1] == i] = y;       v[y][v[y][1] == i] = x;     }     cout << ans <<     << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s =   , s1 =   , tmp;     cin >> tmp;     s += tmp;     cin >> tmp;     reverse(tmp.begin(), tmp.end());     s += tmp;     cin >> tmp;     s1 += tmp;     cin >> tmp;     reverse(tmp.begin(), tmp.end());     s1 += tmp;     s.erase(s.find( X ), 1);     s1.erase(s1.find( X ), 1);     s += s;     int i = 0;     while (s[i] != s1[0]) i++;     if (s.substr(i, 3) == s1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 150001;   int t[MAX_N];   int main() {     int n, k, q;     cin >> n >> k >> q;     for (int i = 0; i < n; ++i) {       cin >> t[i];     }     set<int> s;     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       if (x == 1) {         s.insert(-t[y - 1]);         if (s.size() > k) {           auto it = s.begin();           for (int j = 0; j < k; ++j) it++;           s.erase(it);         }       } else {         cout << (s.find(-t[y - 1]) == s.end() ?  NO  :  YES ) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v, w;   } a[100005];   bool cmp(node a, node b) { return a.v > b.v; }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].v, &a[i].w);     sort(a, a + n, cmp);     int ma = a[0].w;     for (int i = 1; i < n; i++) {       if (a[i].w > ma) {         printf( Happy Alex n );         return 0;       }       ma = min(ma, a[i].w);     }     printf( Poor Alex n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ll(long double x) { return x; }   int main() {     int n;     cin >> n;     while (n--) {       long long a, b;       cin >> a >> b;       if (ceil((2 * a - b) / 3.0) == floor((2 * a - b) / 3.0) and           ceil((2 * b - a) / 3.0) == floor((2 * b - a) / 3.0) and           ceil((2 * b - a) / 3.0) >= 0 and ((2 * a - b) / 3.0) >= 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 1e2 + 2;   vector<bool> a[maxn];   int n, m, k;   void read() {     RI(n, m, k);     for (int i = 0; i < int(n); i++) a[i].resize(m);     for (int i = 0; i < int(n); i++)       for (int j = 0; j < int(m); j++) {         int x;         RI(x);         a[i][j] = (x == 1);       }   }   void build() {}   int doo(const vector<bool> &v) {     int ans = 0;     for (int i = 0; i < int(n); i++) {       int c[2] = {0, 0};       for (int j = 0; j < int(m); j++) c[v[j] ^ a[i][j]]++;       ans += min(c[0], c[1]);     }     return ans;   }   void sol() {     int ans = k + 1;     if (n > 10) {       for (int i = 0; i < int(n); i++) ans = min(ans, doo(a[i]));     } else {       vector<bool> c[maxn];       for (int i = 0; i < int(m); i++) c[i].resize(n);       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(m); j++) c[j][i] = a[i][j];       swap(n, m);       for (int i = 0; i < int(n); i++) a[i] = c[i];       vector<bool> v(m);       for (int i = 0; i < int((1 << m)); i++) {         for (int j = 0; j < int(m); j++) v[j] = ((i >> j) & 1);         ans = min(ans, doo(v));       }     }     if (ans <= k)       PL(ans);     else       PL(-1);   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 0, 1, -1};   const int dy[] = {1, -1, 0, 0};   int s[505][505];   queue<pair<int, int> > q;   char c[505][505];   bitset<505> b[505];   int main(void) {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> (c[i] + 1);     int x1, y1, first, second;     cin >> first >> second >> x1 >> y1;     s[first][second] = 1;     q.push(make_pair(first, second));     while (q.size()) {       int k = q.front().first, l = q.front().second;       q.pop();       for (int p = 0; p < 4; ++p) {         int f = k + dx[p];         int g = l + dy[p];         if ((c[f][g] ==  . ) && !s[f][g])           s[f][g] = s[k][l] + 1, q.push(make_pair(f, g));       }     }     int p = 0, g = 0;     for (int l = 0; l < 4; ++l)       p += c[x1 + dx[l]][y1 + dy[l]] ==  . , g |= s[x1 + dx[l]][y1 + dy[l]];     if (c[x1][y1] ==  X ) return cout << (g ?  YES  :  NO ) <<   n , 0;     if (!s[x1][y1]) return cout <<  NO n , 0;     if (p > 1 || (abs(first - x1) + abs(second - y1) == 1 && p >= 1))       return cout <<  YES n , 0;     return cout <<  NO n , 0;   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t, n, x;     cin >> t;     int sum = 0;     int cnt = 0;     int item = 0;     int s = 0;     while (t--) {       cin >> n >> x;       cnt = 0;       s = 0;       for (int i = 0; i < n; ++i) {         cin >> item;         if (item == x) {           ++cnt;         }         s += item;         sum += (x - item);       }       if (cnt == n) {         cout << 0 <<   n ;       } else if (cnt > 0 or s == n * x or sum == 0) {         cout << 1 <<   n ;       } else {         cout << 2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[9], aa[9];   int c[9], cc[9];   int n;   int ans;   void dfs(int u, int cnt, int self) {     if (u == n) {       ans = min(ans, cnt + (self > 1));       return;     }     dfs(u + 1, cnt + cc[u] + (c[u] != 1), self + 1);     for (int i = u + 1; i < n; i++)       if (aa[i] % a[u] == 0) {         aa[i] /= a[u];         cc[i] -= c[u];         dfs(u + 1, cnt + cc[u] + (c[u] != 1), self);         aa[i] *= a[u];         cc[i] += c[u];       }   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     sort(a, a + n);     for (i = 0; i < n; i++) {       long long x = a[i];       long long m = sqrt(x + 0.5);       for (j = 2; j <= m; j++)         while (x % j == 0) {           c[i]++;           x /= j;         }       if (x > 1) c[i]++;       aa[i] = a[i];       cc[i] = c[i];     }     ans = 1e9;     dfs(0, 0, 0);     printf( %d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define pii pair<int,int>   #define fi first   #define sc second   #define pb push_back   #define ll long long   #define trav(v,x) for(auto v:x)   using namespace std;   const int N = 1e6 + 100;   const ll mod = 998244353;      int n, m, need;   int sa[N], rnk[N];   ll fac[N], ifac[N];      ll C(ll x, ll y)   {return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;}      ll qpow(ll x, ll y = mod - 2)   {       ll res = 1;       while(y)       {           if(y & 1)res = res * x % mod;           x = x * x % mod, y >>= 1;       }       return res;   }      signed main()   {    ios::sync_with_stdio(0);    cin.tie(0);    cin >> n >> m;    for(int i = 1; i <= n; i++)           cin >> sa[i], ++sa[i], rnk[sa[i]] = i;       need = 1;       sa[n + 1] = 0;       for(int i = 2; i <= n; i++)       {           int bf_ps = sa[i - 1], nw_ps = sa[i];           if(rnk[bf_ps + 1] < rnk[nw_ps + 1]);           else ++need;       }       m -= need;    //   cerr << !!  << m <<   n ;       ll ans = 0;       fac[0] = 1;       for(int i = 1; i < N; i++)fac[i] = fac[i - 1] * i % mod;       ifac[N - 1] = qpow(fac[N - 1]);       for(int i = N - 2; i >= 0; i--)ifac[i] = ifac[i + 1] * (i + 1) % mod;       for(ll x = 0; x <= m; x++)           ans = (ans + C(x + n - 1, n - 1)) % mod;       cout << ans  <<   n ;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long g(long long n, long long m) {     long long ans = 0;     for (long long x = 1; x <= n; x++) {       long long minY = 5 - (x % 5);       if (minY <= m) ans += (m - minY) / 5 + 1;     }     return ans;   }   long long gs(long long n, long long m) {     long long ans = 0;     for (long long x = 1; x <= n; x++) {       for (long long y = 1; y <= m; y++) {         if ((x + y) % 5 == 0) ans++;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     cout << g(n, m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 101;   int N, Q, freq[11];   char commands[MAXN], commands2[MAXN];   void solve(int l, int r) {     l--;     r--;     for (int i = 0; i < N; i++) commands2[i] = commands[i];     for (int i = 0; i < 10; i++) freq[i] = 0;     int cur = l;     int dir = 1;     int prev;     while (cur >= l && cur <= r) {       if (commands2[cur] == 0)         cur += dir;       else if (commands2[cur] ==  > ) {         prev = cur;         dir = 1;         cur += dir;         while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir;         if (cur < l || cur > r) break;         if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0;       } else if (commands2[cur] ==  < ) {         prev = cur;         dir = -1;         cur += dir;         while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir;         if (cur < l || cur > r) break;         if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0;       } else {         freq[commands2[cur] -  0 ]++;         commands2[cur]--;         if (commands2[cur] <  0 ) commands2[cur] = 0;         cur += dir;       }     }     for (int i = 0; i < 10; i++) {       printf( %d , freq[i]);       if (i == 9)         printf(  n );       else         printf(   );     }   }   int main() {     scanf( %d %d , &N, &Q);     scanf( %s , commands);     for (int i = 0; i < Q; i++) {       int L, R;       scanf( %d %d , &L, &R);       solve(L, R);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100;   int n, x, a;   int f[MAXN + 1];   int main() {     cin >> n >> x;     memset(f, 0, sizeof f);     for (int i = 0; i < n; i++) {       cin >> a;       f[a] = 1;     }     int ans = 0;     for (int i = 0; i < x; i++) {       if (f[i] == 0) ans++;     }     if (f[x] == 1) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxx = 2e5 + 7;   const int maxn = 1e9 + 7;   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   long long n, h, l, r;   int dp[2005][2005], a[2006];   int check(int op) {     if (op <= r && op >= l)       return 1;     else       return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> h >> l >> r;     memset(dp, -1, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       for (int j = 0; j < h; j++) {         if (dp[i - 1][(j - a[i] + h) % h] < 0 &&             dp[i - 1][(j - a[i] + 1 + h) % h] < 0)           continue;         dp[i][j] = max(dp[i - 1][(j - a[i] + h) % h],                        dp[i - 1][(j - a[i] + 1 + h) % h]) +                    check(j);       }     }     int ans = 0;     for (int i = 0; i < h; i++) {       ans = max(ans, dp[n][i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ma = 35;   int n, m, mat[ma][ma];   int main() {     int t;     scanf( %d , &t);     int ans, one, zero;     int sum, temp;     int l, r;     while (t--) {       scanf( %d%d , &n, &m);       one = zero = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           scanf( %d , &mat[i][j]);           if (mat[i][j])             one++;           else             zero++;         }       ans = min(zero, one);       zero = one = sum = 0;       if (m > n) {         l = 1, r = m;         while (1) {           temp = one = zero = 0;           while ((1 + temp <= n) && (l - temp >= 1)) {             if (mat[1 + temp][l - temp])               one++;             else               zero++;             temp++;           }           temp--;           if ((1 + temp == n) && (l - temp == r)) break;           temp = 0;           while ((n - temp >= 1) && (r + temp <= m)) {             if (mat[n - temp][r + temp])               one++;             else               zero++;             temp++;           }           sum += min(zero, one);           if ((l + 1) == r + temp - 1) break;           l++, r--;         }       } else {         l = 1, r = n;         while (1) {           temp = one = zero = 0;           while (l - temp >= 1 && 1 + temp <= m) {             if (mat[l - temp][1 + temp])               one++;             else               zero++;             temp++;           }           temp--;           if (l - temp == r && 1 + temp == m) break;           temp = 0;           while (r + temp <= n && m - temp >= 1) {             if (mat[r + temp][m - temp])               one++;             else               zero++;             temp++;           }           sum += min(zero, one);           if (l + 1 == r + temp - 1) break;           l++, r--;         }       }       printf( %d n , min(ans, sum));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int freq[26];   int main() {     string s;     cin >> s;     int mx = -1;     char g = s[0];     for (int i = 0; i < s.size(); i++) {       freq[s[i] -  a ]++;       if (s[i] >= g) {         mx = max(mx, freq[s[i] -  a ]);         g = s[i];       }     }     string d(freq[g -  a ], g);     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 2e5 + 5;   int n, m;   char a[N], b[N];   void solve() {     scanf( %d , &n);     scanf( %s , a + 1);     scanf( %s , b + 1);     int res = 0;     for (int i = 1; i <= n; ++i) {       if (b[i] ==  1 ) {         if (a[i] ==  0  || a[i - 1] ==  1 )           ++res;         else if (a[i + 1] ==  1 ) {           a[i + 1] =  * ;           ++res;         }       }     }     printf( %d n , res);   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p, x, y;   queue<int> q;   int mmap[100000];   bool check(int s) {     int i = s / 50 % 475;     for (int j = 0; j < 25; ++j) {       i = (i * 96 + 42) % 475;       if (26 + i == p) return true;     }     mmap[s] = 1;     return false;   }   int main() {     cin >> p >> x >> y;     q.push(0);     while (!q.empty()) {       int n = q.front();       q.pop();       int s = x + n * 100;       while (s >= y) {         if (mmap[s]) {           s -= 50;           continue;         }         if (check(s)) {           cout << n << endl;           return 0;         }         s -= 50;       }       q.push(n + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int left0 = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           left0 = i + 1;         } else {           break;         }       }       int right1 = 0;       for (int i = n - 1; i >= 0; i--) {         if (s[i] ==  1 ) {           right1 = right1 + 1;         } else {           break;         }       }       for (int i = 0; i < left0; i++) {         cout << 0;       }       if (left0 + right1 == n - 1 && (left0 != 0 || right1 != 0)) {         cout << s[left0];       } else if (left0 + right1 != n) {         cout << 0;       }       for (int i = 0; i < right1; i++) {         cout << 1;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct no {     long long i, h, m;   };   long long dp[40][40][40];   char str[40];   no pre[40][40][40];   long long pw[19];   vector<char> ans;   int main() {     long long n;     scanf( %lld , &n);     scanf( %s , str + 1);     pw[0] = 1;     for (long long i = 1; i < 19; i++) pw[i] = pw[i - 1] * 10LL;     for (long long i = 0; i < 40; i++)       for (long long j = 0; j < 40; j++)         for (long long k = 0; k < 40; k++) dp[i][j][k] = -9999999999999LL;     dp[0][0][0] = 0;     pre[0][0][0] = {-1, -1, -1};     for (long long i = 1; i <= 2 * n; i++) {       for (long long h = 0; h <= n; h++) {         for (long long m = 0; m <= n; m++) {           if (h) {             if (dp[i - 1][h - 1][m] + pw[n - h] * (str[i] -  0 ) > dp[i][h][m]) {               dp[i][h][m] = dp[i - 1][h - 1][m] + pw[n - h] * (str[i] -  0 );               pre[i][h][m] = {i - 1, h - 1, m};             }           }           if (m) {             if (dp[i - 1][h][m - 1] + pw[n - m] * (str[i] -  0 ) > dp[i][h][m]) {               dp[i][h][m] = dp[i - 1][h][m - 1] + pw[n - m] * (str[i] -  0 );               pre[i][h][m] = {i - 1, h, m - 1};             }           }         }       }     }     no check = {-1, -1, -1};     no tren = {2 * n, n, n};     no pred = pre[tren.i][tren.h][tren.m];     while (pred.i != -1) {       if (tren.h == pred.h)         ans.push_back( M );       else         ans.push_back( H );       tren = pred;       pred = pre[tren.i][tren.h][tren.m];     }     reverse(ans.begin(), ans.end());     for (long long i = 0; i < ans.size(); i++) printf( %c , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[5005];   void input() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a[i + 1] = a[i] + x;     }   }   void solve() {     long long outx, outy, outz, ans;     ans = outx = outy = outz = 0;     for (int i = 0; i <= n; i++) {       long long z = a[i], lft = i;       for (int j = i; j <= n; j++) {         if (a[j] < z) {           lft = j, z = a[j];         }         if (a[i] - a[lft] + a[j] > ans) {           ans = a[i] - a[lft] + a[j];           outx = i, outz = j, outy = lft;         }       }     }     printf( %lld %lld %lld , outx, outy, outz);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[18];     for (int i = 1; i <= 8; i++) {       cin >> s;       bool p = false;       for (int j = 1; j < 8; j++)         if (s[j] == s[j - 1]) {           p = true;           break;         }       if (p) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define inf 1999999999999999999   #define mod 1000000007   #define lb lower_bound   #define ub upper_bound   #define pb push_back   #define pf push_front   #define bn binary_search   #define pq priority_queue   #define int long long   #define pii pair<int,int>   #define mii map<int,int>   #define umii unordered_map<int,int>   #define um unordered_map   #define vi vector<int>   #define mii map<int,int>   #define si set<int>   #define ft first   #define sc second   #define gcd(a,b) __gcd(a,b)   #define lcm(a,b) a*(b/gcd(a,b))   #define bp(a) __builtin_popcountll(a)   #define mmst(a,b) memset(a,b,sizeof(a))   #define ld long double   void lc(){cout<<endl;}   int md(int n){return n%mod;}   void solve()   {    int n;    ld k;    cin>>n>>k;    //k=k*((ld)(sqrt(2)));    pii p[n];    for(int i=0;i<n;i++)    cin>>p[i].ft>>p[i].sc;    for(int i=0;i<n;i++)    {     int mind=0;     for(int j=0;j<n;j++)     {      if(i==j)continue;      int dis=abs(p[i].ft-p[j].ft)+abs(p[i].sc-p[j].sc);      mind=max(mind,dis);     }     if(mind<=k)      {       cout<< 1 ;       return;      }    }       cout<< -1 ;       }   signed main()   {     ios::sync_with_stdio(0);    cin.tie(0);    int t=1;    cin>>t;    while(t--)    {      solve();      lc();    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   const long long OO = 0x3f3f3f3f3f3f3f3f;   long long n, a, b;   vector<int> primes, v;   long long mem[N][3];   void fact(int num) {     if (num % 2 == 0) primes.push_back(2);     while (num % 2 == 0) num /= 2;     for (int i = 3; i * i <= num; ++i) {       if (num % i == 0) primes.push_back(i);       while (num % i == 0) num /= i;     }     if (num > 1) primes.push_back(num);   }   long long solve(int idx, int typ, const int& gcd) {     if (idx == n) return 0;     long long& ret = mem[idx][typ];     if (~ret) return ret;     ret = OO;     if (typ < 2) {       ret = min(ret, a + solve(idx + 1, 1, gcd));     }     if (typ == 1) typ = 2;     for (int i = -1; i <= 1; ++i) {       if (((v[idx] + i) % gcd) == 0)         ret = min(ret, (i == 0 ? 0 : b) + solve(idx + 1, typ, gcd));     }     return ret;   }   int main() {     cin >> n >> a >> b;     v = vector<int>(n);     for (auto& it : v) cin >> it;     for (int i = -1; i <= 1; ++i) {       fact(v[0] + i);       fact(v[n - 1] + i);     }     set<int> st(primes.begin(), primes.end());     primes = vector<int>(st.begin(), st.end());     long long ans = OO;     for (auto it : primes) {       memset(mem, -1, sizeof mem);       long long rt = solve(0, 0, it);       ans = min(ans, rt);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int mx = (int)1e9;   char an;   void ask_query(int i, int j) {     cout <<  ?   << i <<     << j << endl;     cin >> an;     if (an ==  e ) exit(0);   }   int solbin(int l, int r) {     if (r == l + 1) return r;     int mid = (l + r) / 2;     ask_query(l, mid);     if (an ==  x ) {       return solbin(l, mid);     } else {       return solbin(mid, r);     }   }   int sol(int shift, int en) {     if (en == 2) {       ask_query(shift, shift + 1);       if (an ==  y ) {         return shift + 2;       } else {         return shift + 1;       }     }     an =  y ;     int i = 0, j = 2;     int it = 0;     while (an !=  x  && 2 * j < en) {       if (it != 0) {         i = j;         j = min(2 * j, en);       }       ask_query(shift + i, shift + j);       it++;     }     if (2 * j >= en && an !=  x ) {       i = j;       j = en;     }     return solbin(shift + i, shift + j);   }   void solve() {     string s;     cin >> s;     while (s ==  start ) {       int ans = sol(0, mx);       cout <<  !   << ans << endl;       cin >> s;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   class Piece {    public:     int up[600];     int down[600];     vector<int> pcs;     Piece() {}   } pieces[20];   int x[600][600], w, h, p, u;   void readPhoto() {     cin >> h >> w >> p;     for (int i = 0; i < h; ++i)       for (int j = 0; j < w; ++j) cin >> x[i][j];     h /= p;   }   void setPieces() {     int st = 0;     for (int i = 0; i < p; ++i) {       pieces[i].pcs.push_back(i + 1);       for (int j = 0; j < w; j++) {         pieces[i].up[j] = x[st][j] + x[st + 1][j];         pieces[i].down[j] = x[st + h - 2][j] + x[st + h - 1][j];       }       st += h;     }     u = p;   }   bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {     return a.first < b.first;   }   int calcDiff(int a, int b) {     int diff = 0;     for (int i = 0; i < w; ++i)       diff += ((pieces[a].down[i] - pieces[b].up[i]) *                (pieces[a].down[i] - pieces[b].up[i]));     return diff;   }   void mrgPieces(int a, int b) {     pieces[a].pcs.insert(pieces[a].pcs.end(), pieces[b].pcs.begin(),                          pieces[b].pcs.end());     swap(pieces[a].down, pieces[b].down);     swap(pieces[b], pieces[--u]);   }   void cmpPieces() {     vector<pair<int, pair<int, int> > > v;     for (int i = 0; i < u; ++i)       for (int j = 0; j < u; ++j)         if (i != j) {           int diff = calcDiff(i, j);           v.push_back(make_pair(diff, make_pair(i, j)));         }     sort(v.begin(), v.end(), comp);     mrgPieces(v[0].second.first, v[0].second.second);     v.clear();   }   void cleanPieces() {     for (int i = 0; i < 20; ++i) pieces[i].pcs.clear();   }   int main() {     ios_base::sync_with_stdio(false);     int c;     cin >> c;     while (c--) {       readPhoto();       setPieces();       while (u > 1) cmpPieces();       int tmpPrint[20];       int spx = 1;       for (__typeof(pieces[0].pcs.begin()) it = pieces[0].pcs.begin();            it != pieces[0].pcs.end(); ++it)         tmpPrint[*it - 1] = spx++;       for (int i = 0; i < p; ++i) cout << tmpPrint[i] <<    ;       cout << endl;       cleanPieces();     }   }


#include <bits/stdc++.h>   using namespace std;   bool dp[5001][5001];   vector<int> bits[10001];   vector<pair<int, int> > cur;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s, ans;     cin >> s;     int n = s.size();     dp[0][0] = 1;     cur.push_back(make_pair(0, 0));     int cnt = 0;     while ((1 << cnt) < n) cnt++;     cnt--;     ans =   ;     for (int i = 0; i < (1 << cnt); i++)       for (int j = 0; j < cnt; j++)         if ((i & (1 << j)) == 0) bits[i].push_back(j);     int l = 1;     int m = n;     while (m > l) {       m -= l;       l *= 2;     }     while (ans.size() < m) {       char min_chr =  z ;       for (int i = 0; i < cur.size(); i++) {         auto x = cur[i];         for (auto j : bits[x.second]) {           if (dp[x.first + (1 << j)][x.second | (1 << j)] == 0) {             cur.push_back(make_pair(x.first + (1 << j), x.second | (1 << j)));             dp[x.first + (1 << j)][x.second | (1 << j)] = 1;           }         }         min_chr = min(min_chr, s[x.first]);       }       ans.push_back(min_chr);       vector<pair<int, int> > tmp;       for (auto x : cur) {         if (s[x.first] == min_chr) {           dp[x.first + 1][x.second] = 1;           tmp.push_back(make_pair(x.first + 1, x.second));         }       }       cur = tmp;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int n, m;   vector<int> me, a, nme;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int num;     for (int i = 1; i <= n; i++) {       cin >> num;       me.push_back(num);     }     for (int i = 1; i <= m; i++) {       cin >> num;       a.push_back(num);     }     for (int i = 0; i < 30; i++) {       for (int j = 0; j < me.size(); j++) {         if (me[j] & (1 << i)) {           nme.push_back((1 << i));         }       }     }     sort(a.begin(), a.end());     int ans = 0;     int cm = 0;     for (int i = 0; i < nme.size(); i++) {       while (cm < a.size() and nme[i] >= (1 << a[cm])) {         nme[i] -= (1 << a[cm]);         cm += 1;         ans += 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   bool isp(int n) {     if (n == 1) return false;     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   int mpow(long long x, int k) {     long long ans = 1;     while (k > 0) {       if (k & 1) ans = (ans * x) % n;       x = (x * x) % n;       k /= 2;     }     return ans;   }   int main() {     cin >> n >> x;     ++n;     if (!isp(n)) {       cout <<  -1 ;       return 0;     }     int m = n - 1;     vector<int> p;     for (int i = 2; i <= m; ++i) {       if (m % i == 0) {         p.push_back(i);         while (m % i == 0) m /= i;       }     }     if (m > 1) p.push_back(m);     for (int y = x - 1; y > 0; --y) {       bool ok = true;       for (int i = 0; i < p.size(); ++i) {         int k = (n - 1) / p[i];         if (mpow(y % n, k) == 1) {           ok = false;           break;         }       }       if (ok) {         cout << y;         return 0;       }     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 100;   const int oo = 1e9 + 7;   int N;   int H[MAXN];   deque<int> dq;   int L[MAXN], R[MAXN], l[MAXN], r[MAXN];   int d[MAXN];   vector<int> G[MAXN];   void Dijkstra(int u) {     for (int i = (1), _b = (N + 1); i <= _b; ++i) d[i] = +oo;     d[u] = 0;     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     pq.push(pair<int, int>(0, u));     while (pq.size()) {       int du = pq.top().first;       int u = pq.top().second;       pq.pop();       if (du != d[u]) continue;       for (auto &v : G[u]) {         if (d[v] > du + 1) {           d[v] = du + 1;           pq.push(pair<int, int>(d[v], v));         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = (1), _b = (N); i <= _b; ++i) cin >> H[i];     dq.clear();     for (int i = (N), _a = (1); i >= _a; --i) {       while (dq.size() && H[dq.front()] <= H[i]) dq.pop_front();       if (dq.size())         R[i] = dq.front() - 1;       else         R[i] = i;       dq.push_front(i);     }     dq.clear();     for (int i = (1), _b = (N); i <= _b; ++i) {       while (dq.size() && H[dq.front()] <= H[i]) dq.pop_front();       if (dq.size())         L[i] = dq.front() + 1;       else         L[i] = i;       dq.push_front(i);     }     dq.clear();     for (int i = (1), _b = (N); i <= _b; ++i) {       while (dq.size() && H[dq.front()] >= H[i]) dq.pop_front();       if (dq.size())         l[i] = dq.front() + 1;       else         l[i] = i;       dq.push_front(i);     }     dq.clear();     for (int i = (N), _a = (1); i >= _a; --i) {       while (dq.size() && H[dq.front()] >= H[i]) dq.pop_front();       if (dq.size())         r[i] = dq.front() - 1;       else         r[i] = i;       dq.push_front(i);     }     for (int i = (1), _b = (N); i <= _b; ++i) G[i].push_back(i + 1);     for (int i = (1), _b = (N); i <= _b; ++i) {       if (H[i] < min(H[L[i] - 1], H[R[i] + 1])) {         G[L[i] - 1].push_back(R[i] + 1);       }     }     for (int i = (1), _b = (N); i <= _b; ++i) {       if (max(H[l[i] - 1], H[r[i] + 1]) < H[i]) {         G[l[i] - 1].push_back(r[i] + 1);       }     }     Dijkstra(1);     cout << d[N] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   const long long INF = 1e12;   const long long N = 1e6 + 10;   vector<long long> G[100001];   long long n, m, match[100001], dist[100001];   bool bfs() {     long long i, u, v, len;     queue<long long> Q;     for (i = 1; i <= n; i++) {       if (match[i] == 0) {         dist[i] = 0;         Q.push(i);       } else         dist[i] = (1 << 28);     }     dist[0] = (1 << 28);     while (!Q.empty()) {       u = Q.front();       Q.pop();       if (u != 0) {         len = G[u].size();         for (i = 0; i < len; i++) {           v = G[u][i];           if (dist[match[v]] == (1 << 28)) {             dist[match[v]] = dist[u] + 1;             Q.push(match[v]);           }         }       }     }     return (dist[0] != (1 << 28));   }   bool dfs(long long u) {     long long i, v, len;     if (u != 0) {       len = G[u].size();       for (i = 0; i < len; i++) {         v = G[u][i];         if (dist[match[v]] == dist[u] + 1) {           if (dfs(match[v])) {             match[v] = u;             match[u] = v;             return true;           }         }       }       dist[u] = (1 << 28);       return false;     }     return true;   }   long long hopcroft_karp() {     long long matching = 0, i;     while (bfs())       for (i = 1; i <= n; i++)         if (match[i] == 0 && dfs(i)) matching++;     return matching;   }   vector<pair<long long, pair<long long, long long>>> edges;   long long check(long long x) {     for (long long i = 0; i <= 2 * n + 1; i++) {       G[i].clear();       match[i] = 0;       dist[i] = (1 << 28);     }     for (long long i = 0; i < (long long)edges.size() && edges[i].first <= x;          i++) {       long long u = edges[i].second.first, v = edges[i].second.second;       G[u].push_back(v);       G[v].push_back(u);     }     long long res = hopcroft_karp();     return n == res;   }   void solve() {     long long V;     cin >> n >> V;     m = n;     for (long long i = 0; i < V; i++) {       long long d, u, v;       cin >> u >> v >> d;       edges.push_back({d, {u, v + n}});     }     sort(edges.begin(), edges.end());     long long l = 1, h = 1e9 + 1;     long long ans = h;     while (l <= h) {       long long mid = (l + h) / 2;       if (check(mid)) {         h = mid - 1;         ans = mid;       } else {         l = mid + 1;       }     }     if (ans == 1e9 + 1)       cout << -1 <<   n ;     else       cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     double x, y;   } g[500];   int main() {     int i, j, k, n, m;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %lf%lf , &g[i].x, &g[i].y);     }     double maxx = 0;     double m1, m2;     for (i = 0; i < n - 1; ++i)       for (j = i + 1; j < n; ++j) {         m1 = m2 = 0;         for (k = 0; k < n; ++k) {           if (i == k || j == k) continue;           double temp = (g[i].x - g[k].x) * (g[j].y - g[k].y) -                         (g[j].x - g[k].x) * (g[i].y - g[k].y);           if (temp > 0) {             if (temp > m1) m1 = temp;           } else {             if (temp < m2) m2 = temp;           }         }         if (m1 != 0 && m2 != 0)           if (maxx < m1 + abs(m2)) maxx = m1 + abs(m2);       }     printf( %lf , maxx / 2);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000000 + 11;   const int mod = 1e9 + 7;   const int MAXN = 3000000 + 5;   int n, m;   int c[MAXN];   struct Node {     int l, r;   } a[MAXN];   int lowbit(int i) { return i & (-i); }   long long sum(int x) {     long long sum = 0;     while (x) {       sum += c[x];       x -= lowbit(x);     }     return sum;   }   void add(int x, long long val) {     while (x <= n) {       c[x] += val;       x += lowbit(x);     }   }   int two_query(int x) {     int l = 1, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (sum(mid) >= x) {         r = mid;       } else         l = mid + 1;     }     return l;   }   long long p[100];   int lim;   void bz_init() {     p[0] = 1;     for (int i = 1; i < 30; i++) p[i] = p[i - 1] << 1;     lim = log(n) / log(2) + 1;   }   int bz_query(int x) {     int ans = 0, sum = 0;     for (int j = lim; j >= 0; j--) {       if (ans + p[j] <= n && sum + c[ans + p[j]] < x) {         sum += c[ans + p[j]];         ans += p[j];       }     }     return ans + 1;   }   int f[N];   char ans[N], s[N];   int main() {     scanf( %s , s + 1);     scanf( %d%d , &n, &m);     memset(c, 0, sizeof(c));     for (int i = 1; i <= n; i++) {       add(i, 1);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i].l, &a[i].r);     }     bz_init();     for (int now = n, i = m; i >= 1; i--) {       for (int x = a[i].l + 1, j = 1; a[i].r < now && j <= a[i].r - a[i].l + 1;            x += 2, j++, now--) {         if (x > a[i].r) x = a[i].l;         int pos = bz_query(a[i].r + 1);         add(pos, -1);         f[pos] = bz_query(x);       }     }     for (int i = 1, j = 0; i <= n; i++) {       if (f[i] != 0)         ans[i] = ans[f[i]];       else         ans[i] = s[++j];     }     printf( %s , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   inline void chkmax(int &x, int y) { x = x > y ? x : y; }   const int MAXN = 1e5 + 5;   const int INF = 1e9;   int ch[MAXN][26], fail[MAXN];   int N, M, cnt;   bool nd[MAXN];   char s[MAXN], t[MAXN];   vector<int> dp[MAXN];   inline void build() {     int p = 0;     for (int i = 1; i <= M; i++) {       int x = t[i] -  a ;       ch[p][x] = ++cnt;       p = ch[p][x];     }     nd[p] = true;     queue<int> Q;     for (int i = 0; i < 26; i++)       if (ch[0][i]) Q.push(ch[0][i]);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = 0; i < 26; i++)         if (!ch[x][i])           ch[x][i] = ch[fail[x]][i];         else {           int y = ch[x][i];           fail[y] = ch[fail[x]][i];           Q.push(y);         }     }   }   int main() {     scanf( %s , s + 1);     scanf( %s , t + 1);     N = strlen(s + 1);     M = strlen(t + 1);     build();     for (int i = 0; i <= N; i++) {       dp[i].resize(M + 1);       for (int j = 0; j <= M; j++) dp[i][j] = -INF;     }     dp[0][0] = 0;     for (int i = 0; i < N; i++)       if (s[i + 1] !=  ? ) {         int t = s[i + 1] -  a ;         for (int j = 0; j <= M; j++) {           int p = ch[j][t];           chkmax(dp[i + 1][p], dp[i][j] + nd[p]);         }       } else {         for (int t = 0; t < 26; t++)           for (int j = 0; j <= M; j++) {             int p = ch[j][t];             chkmax(dp[i + 1][p], dp[i][j] + nd[p]);           }       }     int ans = 0;     for (int i = 0; i <= M; i++) chkmax(ans, dp[N][i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int maxn, n, t, x;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int in1, in2;       cin >> in1 >> in2;       x -= in1 - t;       if (x < 0) x = 0;       x += in2;       maxn = max(maxn, x);       t = in1;     }     cout << t + x <<     << maxn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   pair<int, long long> operator+(const pair<int, long long> &A,                                  const pair<int, long long> &B) {     return {A.first + B.first, A.second + B.second};   }   pair<int, long long> operator-(const pair<int, long long> &A,                                  const pair<int, long long> &B) {     return {A.first - B.first, A.second - B.second};   }   struct FenwickTree {     pair<int, long long> fw[N];     void Update(int i, pair<int, long long> v) {       for (i; i < N; i += i & -i) fw[i] = fw[i] + v;     }     pair<int, long long> Query(int i) {       pair<int, long long> ans = {0, 0};       for (i; i > 0; i -= i & -i) ans = ans + fw[i];       return ans;     }     pair<int, long long> Query(int l, int r) {       if (l > r) return {0, 0};       return Query(r) - Query(l - 1);     }   } active_task;   int n, m;   int a[N], b[N];   long long t;   vector<int> val[N];   int find_index(int x, int r) {     int l = 1, f = 0;     while (l <= r) {       int m = (l + r) >> 1;       pair<int, long long> ret = active_task.Query(m);       if (ret.first <= x) {         f = m;         l = m + 1;       } else         r = m - 1;     }     return f;   }   void Solve() {     cin >> n >> m >> t;     int number = m;     pair<int, long long> ans = {t, 0};     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     int bSize = unique(b + 1, b + n + 1) - (b + 1);     for (int i = 1; i <= n; ++i) val[a[i]].push_back(i);     for (int i = 1; i <= bSize; ++i) {       int value = b[i];       for (int idx : val[value]) {         active_task.Update(idx, {1, a[idx]});       }       int l = 1, r = n, f = -1;       while (l <= r) {         int m = (l + r) >> 1;         pair<int, long long> ret1 = active_task.Query(m);         int idx = find_index((ret1.first - 1) / number * number, m);         pair<int, long long> ret2 = active_task.Query(idx);         long long sum = ret2.second * 2LL + active_task.Query(idx + 1, m).second;         if (sum <= t) {           l = m + 1;           f = m;         } else           r = m - 1;       }       if (f != -1) {         pair<int, long long> ret = active_task.Query(f);         if (ret.first > ans.second) ans = {value, ret.first};       }     }     cout << ans.second <<     << ans.first <<   n ;     for (int i = 1; i <= n; ++i)       active_task.Update(i, {-1, -a[i]}), val[a[i]].clear();   }   int main() {     int TC;     cin >> TC;     while (TC--) {       Solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int compareAscending(const void *a, const void *b) {     return (*(int *)a - *(int *)b);   }   int compareDecending(const void *a, const void *b) {     return (*(int *)b - *(int *)a);   }   int compareFirst(const void *a, const void *b) {     if (((pair<int, int> *)a)->first == ((pair<int, int> *)b)->first)       return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;     else       return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;   }   int compareSecond(const void *a, const void *b) {     if (((pair<int, int> *)a)->second == ((pair<int, int> *)b)->second)       return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;     else       return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;   }   bool isPrime(int a) {     if (a < 2) return false;     if (a < 4) return true;     if (a % 2 == 0) return false;     int s = (int)sqrt(a);     for (int i = 3; i <= s; i += 2) {       if (a % i == 0) return false;     }     return true;   }   int bsearch(int *a, int value, int l, int r) {     if (l == r) return l;     if (l + 1 == r) return a[l] >= value ? l : r;     int m = (l + r) / 2;     if (a[m] >= value)       return bsearch(a, value, l, m);     else       return bsearch(a, value, m + 1, r);   }   int main() {     long long a, b, res = 0, t;     scanf( %lld %lld , &a, &b);     while (a != 0 && b != 0) {       res += a / b;       t = a % b;       a = b;       b = t;     }     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multimap<long long int, long long int> par;   char en =   n ;   long long int inf = pow(10, 14);   long long int mod = 1e9 + 7;   long long int parent[2][500005];   long long int findRoot(long long int a, long long int which) {     if (parent[which][a] == a) return a;     parent[which][a] = findRoot(parent[which][a], which);     return parent[which][a];   }   void union1(long long int a, long long int b) {     long long int root1 = findRoot(a, 0);     long long int root2 = findRoot(b, 0);     if (root1 == root2) return;     long long int root11 = findRoot(a, 1);     long long int root21 = findRoot(b, 1);     if (root1 < root2) {       parent[0][root1] = root2;     } else {       parent[0][root2] = root1;     }     if (root11 > root21) {       parent[1][root11] = root21;     } else {       parent[1][root21] = root11;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, p;     cin >> n >> m >> p;     string s;     cin >> s;     char arr[500005];     for (long long int i = 1; i < n + 1; i += 1) {       arr[i] = s[i - 1];       parent[0][i] = parent[1][i] = i;     }     bool visited[500005];     memset(visited, (false), sizeof(visited));     string s1;     cin >> s1;     long long int curr = p;     for (long long int i = 0; i < s1.length(); i += 1) {       if (s1[i] ==  R ) {         if (visited[curr + 1])           curr = findRoot(curr + 1, 0) + 1;         else           curr++;       } else if (s1[i] ==  L ) {         if (visited[curr - 1])           curr = findRoot(curr - 1, 1) - 1;         else           curr--;       } else {         if (arr[curr] ==  ( ) {           stack<char> st;           while (curr <= n) {             visited[curr] = true;             if (visited[curr - 1]) union1(curr - 1, curr);             if (visited[curr + 1]) union1(curr + 1, curr);             if (arr[curr] ==  ( ) {               st.push( ( );             } else {               st.pop();             }             if (st.empty()) {               long long int temp;               temp = findRoot(curr, 0) + 1;               if (temp > n) {                 temp = findRoot(curr, 1) - 1;               }               curr = temp;               break;             }             curr = findRoot(curr, 0) + 1;           }         } else {           stack<char> st;           while (curr >= 1) {             visited[curr] = true;             if (visited[curr - 1]) union1(curr - 1, curr);             if (visited[curr + 1]) union1(curr + 1, curr);             if (arr[curr] ==  ) ) {               st.push( ) );             } else {               st.pop();             }             if (st.empty()) {               long long int temp;               temp = findRoot(curr, 0) + 1;               if (temp > n) {                 temp = findRoot(curr, 1) - 1;               }               curr = temp;               break;             }             curr = findRoot(curr, 1) - 1;           }         }       }     }     for (long long int i = 1; i < n + 1; i += 1) {       if (!visited[i]) cout << arr[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, i = 0, j, k, x, y, z, count = 0, p, flag = 0, ans = 0, sum = 0,                  l, n, m, max1, min1, pos, tmp, q;     t = 1;     while (t--) {       long long n, r;       scanf( %lld%lld , &n, &r);       long double x[1005], y[1005];       for (i = 0; i < n; i++) {         scanf( %Lf , &x[i]);       }       for (i = 0; i < n; i++) {         y[i] = -1.0 * 1000000000;         for (j = 0; j < i; j++) {           double p = abs(x[i] - x[j]);           if (p <= 2 * r) {             double q = y[j] + sqrtl(4 * r * r - p * p);             if (q > y[i]) y[i] = q;           }         }         if (y[i] == -1.0 * 1000000000) y[i] = 1.0 * r;         printf( %.15Lf  , y[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const long double ep = 1e-10;   struct pnt {     long double x, y;     pnt() { x = y = 0; }     pnt(long double xx, long double yy) { x = xx, y = yy; }     pnt operator+(pnt a) { return pnt(x + a.x, y + a.y); }     void in() {       int xx, yy;       cin >> xx >> yy;       x = xx, y = yy;     }     long double operator^(const pnt &a) const { return x * a.y - y * a.x; }     bool operator<(const pnt &a) const { return x != a.x ? x < a.x : y < a.y; }     bool int_pnt(pnt &a) {       int xx = x + (x > 0 ? 0.5 : -0.5), yy = y + (y > 0 ? 0.5 : -0.5);       if (abs(x - xx) < ep && abs(y - yy) < ep) {         a = pnt(xx, yy);         return 1;       }       return 0;     }   } p[N], M, MM;   vector<pnt> P;   int n;   map<pnt, int> h;   bool opp[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       p[i].in();       M = M + p[i];       h[p[i]] = i;     }     M.x /= n, M.y /= n;     MM.x = M.x * 2, MM.y = M.y * 2;     for (int i = 1; i <= n; i++)       if (!opp[i]) {         pnt pp = pnt(MM.x - p[i].x, MM.y - p[i].y), qq;         if (pp.int_pnt(qq) && h.count(qq)) {           int t = h[qq];           opp[t] = 1;           opp[i] = 1;         }       }     for (int i = 1; i <= n; i++)       if (!opp[i]) P.push_back(p[i]);     if (P.empty())       puts( -1 );     else {       pnt A = P[0];       int ans = 0;       vector<pnt> D;       for (auto x : P) {         pnt AM = A + x;         AM.x /= 2, AM.y /= 2;         pnt d = pnt(M.x - AM.x, M.y - AM.y);         vector<long double> pos, neg;         for (auto y : P) {           long double l = d ^ pnt(y.x - AM.x, y.y - AM.y);           if (abs(l) < ep) continue;           if (l < 0)             neg.push_back(-l);           else             pos.push_back(l);         }         if (neg.size() != pos.size()) continue;         sort(neg.begin(), neg.end());         sort(pos.begin(), pos.end());         bool flag = 0;         for (int i = 0; i < pos.size(); i++)           if (abs(pos[i] - neg[i]) > ep) flag = 1;         if (!flag) D.push_back(d);       }       for (auto &x : D) {         if (x.y < 0) x.y = -x.y, x.x = -x.x;         if (x.y == 0 && x.x < 0) x.x = -x.x;       }       sort(D.begin(), D.end(),            [](const pnt &x, const pnt &y) { return (x ^ y) > 0; });       int sz = D.size();       for (int i = 0, j; i < sz; i = j) {         for (j = i; j < sz && (D[i] ^ D[j]) == 0; j++)           ;         ans++;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   std::pair<long long, long long> go(long long m) {     long long cur = 1;     long long cur3 = 1;     long long cur13 = 8;     long long h = 0;     long long num = 0;     std::vector<long long> what;     while (1) {       while (h + cur3 >= cur13) {         if (cur3 > m) break;         cur++;         cur3 = cur13;         cur13 = (cur + 1) * (cur + 1) * (cur + 1);       }       if (h + cur3 > m) break;       h += cur3;       what.push_back(cur3);       num++;     }     std::vector<long long> ch(num + 1, 0);     long long sum = 0;     for (int i = 0; i < num; i++) {       sum += what[i];       ch[i + 1] = sum;     }     cur = 1;     while (cur * cur * cur <= m) cur++;     long long left = m;     long long ans = 0;     deque<long long> revans;     for (int step = num - 1; step >= 0; step--) {       cur++;       while (1) {         cur--;         if (ch[step] + cur * cur * cur > left) continue;         long long cum = ch[step] + cur * cur * cur;         bool f = false;         for (int i = 0; i < revans.size(); i++) {           cum += revans[i] * revans[i] * revans[i];           long long ra3 = (revans[i] + 1) * (revans[i] + 1) * (revans[i] + 1);           if (cum >= ra3) {             f = true;             break;           }         }         if (!f) break;       }       revans.push_front(cur);       cur3 = cur * cur * cur;       left -= cur3;       ans += cur3;     }     return make_pair(num, ans);   }   int main() {     long long m;     cin >> m;     std::pair<long long, long long> x = go(m);     cout << x.first <<     << x.second;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   typedef unsigned long long int ull;   #define pii acos(-1)   #define sc(n) scanf( %d ,&n)   #define sc2(n,x) scanf( %d%d ,&n,&x)   #define pr(n) printf( %d ,n)   #define scl(n) scanf( %I64d ,&n)   #define scl2(n,m) scanf( %I64d%I64d ,&n,&m)   #define prl(n) printf( %I64d ,n)   #define loop(x,n) for(int i=x;i<n;i++)   #define mp make_pair   #define pb push_back   #define nl printf(  n )   #define mod 998244353   #define lv -100000000   typedef pair<int,int> pi;   #define fastio           ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)   using namespace std;   int a[300005],c[300005];   int main()   {       int t,n,k;       cin>>t;       while(t--)       {           cin>>n>>k;           for(int i=0;i<n;i++)           {               cin>>a[i];           }           for(int i=0;i<k;i++)           {               cin>>c[i];           }           sort(a,a+n);           ll ans=0;           int l=0,flag=0;           for(int i=n-1;i>=0;i--)           {               if(flag==0 && c[l]<=c[a[i]-1]&&l<k)               {                   ans+=c[l];                   l++;                   //cout<< YES <<endl;               }               else               {                   flag++;                   ans+=c[a[i]-1];               }           }           cout<<ans<<endl;       }   }