#include <bits/stdc++.h>   using namespace std;   const int cap = 1e5 + 10;   int main() {     long long a[cap];     a[1] = 0;     long long n, m;     long long Max, Min;     cin >> n >> m;     if (m == 0)       Max = n;     else {       for (int i = 2; i <= n; i++) {         a[i] = a[i - 1] + i - 1;         if (a[i] >= m) {           Max = n - i;           break;         }       }     }     Min = n - m * 2;     if (Min < 0) Min = 0;     cout << Min <<     << Max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9 + 10;   const int MOD = 1e9 + 7;   const int N = 1e6 + 10;   int n, m, b;   vector<int> st;   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n;     int cnt = 0;     int ans = 0;     for (int i = 1; i <= 2 * n; i++) {       string t;       int val;       cin >> t;       if (t ==  add ) {         cin >> val;         st.push_back(val);       } else {         cnt++;         if (st.empty())           ;         else if (st.back() == cnt)           st.pop_back();         else {           st.clear();           ans++;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e6 + 3;   int toint(string s) {     int ans = 0;     for (char x : s) ans = ans * 10 + (x -  0 );     return ans;   }   int lcs(string a, string b) {     int n = a.size(), m = b.size();     int dp[2][m + 1];     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         if (i == 0 || j == 0)           dp[i % 2][j] = 0;         else {           if (a[i - 1] == b[j - 1])             dp[i % 2][j] = 1 + dp[1 - i % 2][j - 1];           else             dp[i % 2][j] = max(dp[i % 2][j - 1], dp[1 - i % 2][j]);         }       }     }     return dp[n % 2][m];   }   int sum(int x) {     int s = 0;     while (x) {       s += x % 10;       x /= 10;     }     return s;   }   bool equal(string s) {     for (int i = 0, j = s.size() / 2; j < s.size(); i++, j++) {       if (s[i] != s[j]) return false;     }     return true;   }   long long fact(int n) {     long long ans = 1;     for (int i = 2; i < n + 1; i++) ans = (ans * i) % mod;     return ans;   }   unsigned long long f(long long a, long long x) {     if (a < 0) return 0;     return (a / x + 1);   }   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) return a.first > b.first;     return a.second > b.second;   }   long long power(long long a, long long b) {     if (b == 0) return 1;     long long ans = power(a, b / 2);     ans = (ans * ans) % mod;     if (b % 2 == 1) ans = (ans * a) % mod;     return ans;   }   int main() {     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int ans = INT_MAX, ind = -1;     for (int i = 0; i < k; i++) {       int j = i;       int total = 0;       do {         total += a[j];         j = (j + k) % n;       } while (j != i);       if (total < ans) {         ans = total;         ind = i + 1;       }     }     cout << ind << endl;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long get_idx(int p) {     int idx = 1;     while (idx < p) idx *= 2;     return idx;   }   void update(vector<unsigned long long> &tree, unsigned long long idx,               unsigned long long val) {     tree[idx] = val;     idx /= 2;     while (idx) {       tree[idx] = tree[idx * 2] | tree[idx * 2 + 1];       idx /= 2;     }   }   int main() {     unsigned long long n, k, x, a = 1;     unsigned long long ans = 0;     cin >> n >> k >> x;     vector<unsigned long long> data(n);     for (int i = 0; i < k; i++) a *= x;     for (int i = 0; i < n; i++) cin >> data[i];     unsigned long long idx = get_idx(n);     vector<unsigned long long> tree(idx * 2);     for (int i = idx; i < idx + n; i++) update(tree, i, data[i - idx]);     for (int i = 0; i < n; i++) {       update(tree, i + idx, data[i] * a);       ans = max(tree[1], ans);       update(tree, i + idx, data[i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAX_N = 1e5 + 9;   int ans[MAX_N];   void sieve(int n) {     int nw = 1;     for (int i = 2; i <= n; i++) ans[i] = INT_MAX;     for (ll i = 2; i <= n; i++) {       if (ans[i] != INT_MAX) continue;       for (ll j = i; j <= n; j += i) ans[j] = min(ans[j], nw);       nw++;     }   }   int main() {     int n;     cin >> n;     sieve(n);     for (int i = 2; i <= n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> mp;   int main() {     string a, b;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a >> b;       mp[b] = a;     }     for (int i = 0; i < m; i++) {       cin >> a >> b;       b.pop_back();       cout << a <<     << b <<  ; #  << mp[b] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> s[100005];   int n, m, k, from, to, d[100005], f[100005], t[100005], c[100005],       before[100005], cnt = 0;   bool vis[100005] = {false};   void swap(int &a, int &b) {     int t = a;     a = b;     b = t;   }   void qsort(int l, int r) {     int i = l, j = r, x = d[(l + r) >> 1];     do {       while (d[i] < x) i++;       while (d[j] > x) j--;       if (i <= j) {         swap(d[i], d[j]);         swap(f[i], f[j]);         swap(t[i], t[j]);         swap(c[i], c[j]);         i++;         j--;       }     } while (i <= j);     if (l < j) qsort(l, j);     if (i < r) qsort(i, r);   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int min(int a, int b) {     if (a < b) return a;     return b;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     from = 0x3f3f3f3f;     to = 0;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &d[i], &f[i], &t[i], &c[i]);       from = min(from, d[i]);       to = max(to, d[i]);     }     qsort(1, m);     for (int i = 1; i <= n; i++) before[i] = 1000005;     for (int i = m; i > 0; i--) {       if (f[i] == 0) {         int top;         if (!s[t[i]].empty()) top = s[t[i]].top();         if (s[t[i]].empty() || c[top] > c[i]) s[t[i]].push(i);       }     }     int now = 1, now2 = 1;     bool flag = true;     for (int i = 1; i <= n; i++)       if (s[i].empty()) {         flag = false;         break;       }     if (!flag) {       printf( -1 n );       return 0;     }     long long ans, val = 0, qwq;     for (int i = 1; i <= n; i++) {       val += 1000005;       int top = s[i].top();       val += c[top];     }     qwq = 20000000000000;     ans = qwq;     for (int start = from - 1; start <= to + 1; start++) {       if (!flag) break;       int end = start + k;       while (now <= m && d[now] < start) {         if (t[now] == 0) {           val -= before[f[now]];           before[f[now]] = min(before[f[now]], c[now]);           val += before[f[now]];           if (!vis[f[now]]) cnt++;           vis[f[now]] = true;         }         now++;       }       while (now2 <= m && d[now2] < end) {         if (f[now2] == 0) {           if (s[t[now2]].empty()) {             flag = false;             break;           }           int top = s[t[now2]].top();           if (d[top] < end) {             val -= c[top];             s[t[now2]].pop();             if (!s[t[now2]].empty()) val += c[s[t[now2]].top()];           }           if (s[t[now2]].empty()) flag = false;         }         now2++;       }       if (!flag) break;       if (cnt == n) ans = min(ans, val);     }     if (ans == qwq)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2002;   int n, k;   long long a[MAXN];   int dp[MAXN];   int abs1(int a) { return a >= 0 ? a : -a; }   int min1(int a, int b) { return a > b ? b : a; }   bool find(long long mid) {     for (int i = 1; i <= n + 1; i++) dp[i] = i - 1;     dp[1] = 0;     for (int i = 2; i <= n; i++)       for (int j = 1; j < i; j++)         if (abs1(a[i] - a[j]) <= (i - j) * mid)           dp[i] = min1(dp[i], dp[j] + (i - j - 1));     for (int i = 1; i <= n; i++) dp[n + 1] = min1(dp[n + 1], n - i + dp[i]);     if (dp[n + 1] <= k) return true;     return false;   }   int main() {     int i;     long long mid, L, R;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     L = 0;     R = 2000000001;     while (L <= R) {       mid = (L + R) >> 1;       if (find(mid))         R = mid - 1;       else         L = mid + 1;     }     printf( %lld n , R + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     int z;     for (int t = 1; t <= tc; t++) {       cin >> z;       int a, s, d = 0;       s = 0;       a = 0;       int x;       for (int q = 1; q <= z; q++) {         cin >> x;         if (x % 3 == 0)           a++;         else if (x % 3 == 1)           s++;         else           d++;       }       int total = a + (min(s, d));       int temp = min(s, d);       s -= temp;       d -= temp;       total += (s / 3);       total += (d / 3);       cout << total << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N[5];   int K;   int getChoice(int choice) {     if (N[choice]) return choice;     for (int i = 1; true; i++) {       if (choice + i < 5 && N[choice + i]) return choice + i;       if (choice - i >= 0 && N[choice - i]) return choice - i;     }   }   int main() {     for (int i = 0; i < 5; i++) cin >> N[i];     cin >> K;     map<string, int> strToInt;     strToInt[ S ] = 0;     strToInt[ M ] = 1;     strToInt[ L ] = 2;     strToInt[ XL ] = 3;     strToInt[ XXL ] = 4;     map<int, string> intToStr;     intToStr[0] =  S ;     intToStr[1] =  M ;     intToStr[2] =  L ;     intToStr[3] =  XL ;     intToStr[4] =  XXL ;     string temp;     for (int i = 0; i < K; i++) {       cin.ignore(5,   n );       cin >> temp;       int choice = strToInt[temp];       int willGet = getChoice(choice);       N[willGet]--;       cout << intToStr[willGet] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, s1, s2, s3, s4;     cin >> a >> b >> c;     s1 = a + c + b;     s2 = a + a + b + b;     s3 = a + c + c + a;     s4 = b + c + c + b;     cout << min(s1, (min(s2, min(s3, s4))));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<long long> v(n);       for (int i = 0; i < n; i++) {         string s;         cin >> s;         long long a = 0;         for (int j = 0; j < m; j++) {           if (s[j] ==  1 ) {             a += (1LL << (m - 1 - j));           }         }         v[i] = a;       }       sort(v.begin(), v.end());       long long mid = (1LL << (m - 1)) - 1;       long long x = (1 << m);       for (int i = 0; i < n; i++) {         if (v[i] < mid) {           if (x % 2 == 0) mid++;           x--;         } else if (v[i] == mid) {           if (x % 2 == 0) {             mid++;             x--;           } else {             long long q = mid - 1;             int y;             while (1) {               y = 0;               for (int j = 0; j < n; j++) {                 if (q == v[j]) {                   q--;                   y = 1;                   break;                 }               }               if (!y) break;             }             mid = q;             x--;           }         } else {           if (x % 2) {             long long q = mid - 1;             int y;             while (1) {               y = 0;               for (int j = 0; j < n; j++) {                 if (q == v[j]) {                   q--;                   y = 1;                   break;                 }               }               if (!y) break;             }             mid = q;           }           x--;         }       }       for (int j = m - 1; j >= 0; j--) {         if (mid & (1LL << j)) {           cout << 1;         } else           cout << 0;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int LIM = 100005;   long long power(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) {         res = res * x % mod;       }       x = x * x % mod;       n >>= 1;     }     return (res % mod);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 0;     cin >> t;     while (t--) {       long long n = 0, x = 0, y = 0;       cin >> n >> x >> y;       vector<long long> v;       long long dif = y - x;       long long c = n - 1;       long long d = 0;       for (c = n - 1; c >= 1; c--) {         if (dif % c == 0) {           d = dif / c;           break;         }       }       for (long long i = x; i <= y; i += d) {         v.push_back(i);         n--;       }       long long now = x - d;       for (; n > 0;) {         if (now <= 0)           break;         else {           v.push_back(now);           now -= d;           n--;         }       }       now = y + d;       for (; n > 0;) {         if (now <= 0)           break;         else {           v.push_back(now);           now += d;           n--;         }       }       sort(v.begin(), v.end());       for (long long i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s, x, k, ans = 0, ch = 0;     cin >> n >> s;     s = 8 * s;     vector<long long int> vec(n);     vector<pair<long long int, long long int>> dat;     for (long long int i = 0; i < n; i++) cin >> vec[i];     sort(vec.begin(), vec.end());     dat.push_back(make_pair(vec[0], 1));     x = vec[0];     for (long long int i = 1; i < n; i++) {       if (vec[i] != x) {         dat.push_back(make_pair(vec[i], 1));         x = vec[i];       } else {         dat[dat.size() - 1].second++;       }     }     while (1) {       k = 0;       while (pow(2, k) < dat.size() - ch) k++;       k = n * k;       if (k <= s) break;       ch++;     }     x = 0;     for (long long int i = 0; i < ch; i++) x = x + dat[i].second;     ans = x;     for (long long int i = 0; i < ch; i++) {       x = x - dat[ch - i - 1].second + dat[dat.size() - i - 1].second;       if (x < ans) ans = x;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6;   const int inf = (1ll << 31) - 1;   int p[maxn], l[maxn];   int n;   pair<pair<int, int>, int> e[maxn];   pair<int, int> st[maxn];   int sum[maxn], answer[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &p[i], &l[i]);     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       int l, r;       scanf( %d%d , &l, &r);       l--;       r--;       e[i] = make_pair(make_pair(l, r), i);     }     sort(e, e + m);     reverse(e, e + m);     int ei = 0, stn = 0;     for (int i = n - 1; i >= 0; --i) {       int end = p[i] + l[i];       while (stn > 0 && st[stn - 1].first <= p[i] + l[i]) {         end = max(end, st[stn - 1].second);         --stn;       }       st[stn++] = make_pair(p[i], end);       sum[stn - 1] = 0;       if (stn > 1) sum[stn - 1] += sum[stn - 2] + st[stn - 2].first - end;       while (ei < m && e[ei].first.first == i) {         int pos = lower_bound(st, st + stn, make_pair(p[e[ei].first.second], inf),                               greater<pair<int, int> >()) -                   st;         answer[e[ei].second] = sum[stn - 1] - sum[pos];         ei++;       }     }     for (int i = 0; i < m; ++i) printf( %d n , answer[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int cmp(double x, double y = 0, double tol = 1e-9) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   int main() {     int n;     double a, d, t0, vm, t_vm, def, last = 0;     scanf( %d %lf %lf , &n, &a, &d);     def = sqrt(2 * d / a);     for (int i = 0; i < n; ++i) {       scanf( %lf %lf , &t0, &vm);       t_vm = vm / a;       if (t_vm < def)         t_vm += (d - .5 * a * t_vm * t_vm) / vm;       else         t_vm = def;       last = max(t_vm + t0, last);       printf( %.10lf n , last);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double pa[2020], pb[2020], pab[2020];   int n, a, b;   double dp[2020];   int opt[2020];   pair<int, int> solve(double mida, double midb) {     dp[0] = 0;     opt[0] = 0;     for (int i = 1; i <= n; i++) {       double& d = dp[i];       int& o = opt[i];       d = dp[i - 1];       o = 0;       if (d < dp[i - 1] + pa[i] - mida) {         d = dp[i - 1] + pa[i] - mida;         o = 1;       }       if (d < dp[i - 1] + pb[i] - midb) {         d = dp[i - 1] + pb[i] - midb;         o = 2;       }       if (d < dp[i - 1] + pab[i] - mida - midb) {         d = dp[i - 1] + pab[i] - mida - midb;         o = 3;       }     }     pair<int, int> ans = make_pair(0, 0);     for (int i = 1; i <= n; i++) {       if (opt[i] & 1) {         ans.first++;       }       if (opt[i] > 1) {         ans.second++;       }     }     return ans;   }   int main() {     scanf( %d %d %d , &n, &a, &b);     for (int i = 1; i <= n; i++) {       scanf( %lf , &pa[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %lf , &pb[i]);     }     for (int i = 1; i <= n; i++) {       pab[i] = pa[i] + pb[i] - pa[i] * pb[i];     }     double lowa = 0, higha = 1;     double lowb = 0, highb = 1;     for (int it = 0; it < 100; it++) {       double mida = (lowa + higha) / 2;       lowb = 0;       highb = 1;       for (int itb = 0; itb < 100; itb++) {         double midb = (lowb + highb) / 2;         auto ans = solve(mida, midb);         if (ans.second > b) {           lowb = midb;         } else {           highb = midb;         }       }       auto ans = solve(mida, highb);       if (ans.first > a) {         lowa = mida;       } else {         higha = mida;       }     }     auto ret = solve(higha, highb);     printf( %.10lf n , dp[n] + lowa * a + lowb * b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char IO;   inline long long rd() {     long long res = 0, f = 1;     while (IO = getchar(), IO < 48 || IO > 57)       if (IO ==  - ) f = 0;     do res = (res << 3) + (res << 1) + (IO ^ 48);     while (IO = getchar(), IO >= 48 && IO <= 57);     if (f) return res;     return -res;   }   const long long P = 1e9 + 7, M = 1e5 + 5;   long long fac[M], pw[M], inv[M];   char str[M];   long long Pow(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1, a = a * a % P)       if (b & 1) res = res * a % P;     return res;   }   void init() {     fac[0] = pw[0] = 1;     for (long long i = 1, iend = M - 5; i <= iend; ++i) {       fac[i] = fac[i - 1] * i % P;       pw[i] = pw[i - 1] * 10 % P;     }     inv[M - 5] = Pow(fac[M - 5], P - 2);     for (long long i = M - 5, iend = 1; i >= iend; --i)       inv[i - 1] = inv[i] * i % P;   }   long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return fac[n] * inv[m] % P * inv[n - m] % P;   }   int main() {     init();     long long n = rd(), m = rd(), s = 0, ans = 0;     scanf( %s , str + 1);     for (long long i = n, iend = 1; i >= iend; --i) {       ans = (ans + (s + C(i - 1, m) * pw[n - i]) * (str[i] -  0 ) % P) % P;       s = (s + C(i - 2, m - 1) * pw[n - i] % P);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, q[N], top1, top2;   struct ky {     int x, y;     long long w, val;     bool operator<(const ky& p) const { return x < p.x; }   } a[N];   long long f[N], ans;   inline double slope(const int x, const int y) {     return a[x].x == a[y].x ? 1e18                             : (double)(1.0 * (f[x] - f[y])) / (a[x].x - a[y].x);   }   inline long long cal(const int x, const int y) {     return f[y] - (0ll + a[y].x) * a[x].y + a[x].val;   }   template <class I>   inline void ckMax(I& p, I q) {     p = (p > q ? p : q);   }   int main() {     scanf( %d , &n);     register int i;     for (i = 1; i <= n; ++i)       scanf( %d%d%lld , &a[i].x, &a[i].y, &a[i].w),           a[i].val = (0ll + a[i].x) * a[i].y - a[i].w;     std::sort(a + 1, a + 1 + n), f[1] = a[1].val, q[top1 = top2 = 1] = 0;     for (i = 1; i <= n; ++i) {       while (top1 < top2 && slope(q[top1], q[top1 + 1]) >= a[i].y) ++top1;       f[i] = cal(i, q[top1]), ckMax(ans, f[i]);       while (top1 < top2 && slope(q[top2 - 1], q[top2]) < slope(q[top2], i))         --top2;       q[++top2] = i;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int test;     for (cin >> test; test--;) {       int m, n;       cin >> m >> n;       vector<vector<int>> s(m + 5, vector<int>(n + 5));       for (int i = 1; i <= m; ++i) {         for (int j = 1; j <= n; ++j) {           char x;           cin >> x;           s[i][j] = x -  0 ;         }       }       vector<int> ans;       auto f = [&](int i, int j) {         s[i][j] ^= 1;         ans.push_back(i);         ans.push_back(j);       };       auto fp = [&](pair<int, int> a) {         s[a.first][a.second] ^= 1;         ans.push_back(a.first);         ans.push_back(a.second);       };       if (m > 2) {         for (int i = 1; i <= m - 2; ++i) {           for (int j = 1; j < n; ++j) {             if (s[i][j] == 0) continue;             if (s[i][j + 1] == 1) {               if (s[i + 1][j] == 1) {                 f(i, j);                 f(i + 1, j);                 f(i, j + 1);               } else {                 f(i, j);                 f(i, j + 1);                 f(i + 1, j + 1);               }             } else {               f(i, j);               f(i + 1, j + 1);               f(i + 1, j);             }           }           if (s[i][n] == 1) {             f(i, n);             f(i + 1, n);             f(i + 1, n - 1);           }         }         for (int j = 1, i = m - 1; j < n; ++j) {           if (s[i + 1][j] == 0 && s[i][j] == 0 && (!(i == m - 1 && j == n - 1)))             continue;           int sum = s[i][j] + s[i][j + 1] + s[i + 1][j] + s[i + 1][j + 1];           if (sum == 4) {             f(i + 1, j);             f(i + 1, j + 1);             f(i, j + 1);             f(i, j);             f(i + 1, j);             f(i, j + 1);             f(i, j);             f(i, j + 1);             f(i + 1, j + 1);             f(i, j);             f(i + 1, j);             f(i + 1, j + 1);           }           vector<pair<int, int>> e = {               {i, j}, {i + 1, j}, {i, j + 1}, {i + 1, j + 1}};           sort(e.begin(), e.end(), [&](pair<int, int> x, pair<int, int> y) {             return s[x.first][x.second] < s[y.first][y.second];           });           if (sum == 2) {             if (sum == 2) {               fp(e[0]);               fp(e[1]);               fp(e[2]);               fp(e[0]);               fp(e[1]);               fp(e[3]);             }             continue;           }           if (sum == 3) {             if (s[i][j] == 1) f(i, j);             if (s[i + 1][j] == 1) f(i + 1, j);             if (s[i][j + 1] == 1) f(i, j + 1);             if (s[i + 1][j + 1] == 1) f(i + 1, j + 1);             continue;           }           if (sum == 1) {             fp(e[1]);             fp(e[2]);             fp(e[3]);             fp(e[0]);             fp(e[1]);             fp(e[3]);             fp(e[0]);             fp(e[2]);             fp(e[3]);           }         }       } else {         for (int j = 1; j <= n - 2; ++j) {           for (int i = 1; i < m; ++i) {             if (s[i][j] == 0) continue;             if (s[i + 1][j] == 1) {               if (s[i][j + 1] == 1) {                 f(i, j);                 f(i + 1, j);                 f(i, j + 1);               } else {                 f(i, j);                 f(i + 1, j);                 f(i + 1, j + 1);               }             } else {               f(i, j);               f(i, j + 1);               f(i + 1, j + 1);             }           }           if (s[m][j] == 1) {             f(m, j);             f(m - 1, j + 1);             f(m, j + 1);           }         }         for (int i = 1, j = n - 1; i < m; ++i) {           if (s[i][j] == 0 && s[i][j + 1] == 0 && (!(i == m - 1 && j == n - 1)))             continue;           int sum = s[i][j] + s[i][j + 1] + s[i + 1][j] + s[i + 1][j + 1];           if (sum == 4) {             f(i + 1, j);             f(i + 1, j + 1);             f(i, j + 1);             f(i, j);             f(i + 1, j);             f(i, j + 1);             f(i, j);             f(i, j + 1);             f(i + 1, j + 1);             f(i, j);             f(i + 1, j);             f(i + 1, j + 1);           }           vector<pair<int, int>> e = {               {i, j}, {i + 1, j}, {i, j + 1}, {i + 1, j + 1}};           sort(e.begin(), e.end(), [&](pair<int, int> x, pair<int, int> y) {             return s[x.first][x.second] < s[y.first][y.second];           });           if (sum == 2) {             if (sum == 2) {               fp(e[0]);               fp(e[1]);               fp(e[2]);               fp(e[0]);               fp(e[1]);               fp(e[3]);             }             continue;           }           if (sum == 3) {             if (s[i][j] == 1) f(i, j);             if (s[i + 1][j] == 1) f(i + 1, j);             if (s[i][j + 1] == 1) f(i, j + 1);             if (s[i + 1][j + 1] == 1) f(i + 1, j + 1);             continue;           }           if (sum == 1) {             fp(e[1]);             fp(e[2]);             fp(e[3]);             fp(e[0]);             fp(e[1]);             fp(e[3]);             fp(e[0]);             fp(e[2]);             fp(e[3]);           }         }       }       cout << ans.size() / 6 <<   n ;       for (int i = 0; i < ans.size(); i += 6) {         cout << ans[i] <<     << ans[i + 1] <<     << ans[i + 2] <<                  << ans[i + 3] <<     << ans[i + 4] <<     << ans[i + 5] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     int fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     x *= fl;   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   const int N = 200005;   int T, n, m;   vector<int> edge[N];   int main() {     for (read(T); T; T--) {       read(n, m);       for (int i = 1; i <= n; i++) edge[i].clear();       vector<int> deg(n + 1), level(n + 1, 1);       for (int i = 1; i <= m; i++) {         int u, v;         read(u, v);         edge[u].emplace_back(v);         deg[v]++;       }       vector<int> ans;       for (int i = 1; i <= n; i++) {         if (level[i] == 3) {           ans.emplace_back(i);           continue;         }         for (auto &to : edge[i]) level[to] = max(level[to], level[i] + 1);       }       printf( %d n , (int)ans.size());       for (auto &k : ans) printf( %d  , k);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 30000;   const int M = 30000;   struct Input {     int mod;     int n, m;     int a[N];     int l[M], r[M];     bool read() {       if (!(cin >> n >> mod)) {         return 0;       }       for (int i = int(0); i < int(n); ++i) {         scanf( %d , &a[i]);       }       cin >> m;       for (int i = int(0); i < int(m); ++i) {         scanf( %d%d , &l[i], &r[i]);         --l[i];       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     int ans[M];     void write() {       for (int i = int(0); i < int(m); ++i) {         cout << ans[i] << endl;       }     }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     static const int K = 12;     static const int D = N / K + 1;     int f[N + 10];     int p[N], rev[N];     int cnt[M];     int hv[M];     int msk[N + 1];     int mb[1 << K], bt[2][1 << K], v[2][1 << K][2];     void solve() {       f[0] = 1;       f[1] = 0;       for (int i = int(0); i < int(N + 8); ++i) {         f[i + 2] = (f[i] + f[i + 1]) % mod;       }       for (int i = int(0); i < int(n); ++i) {         p[i] = i;       }       sort(p, p + n, [&](int i, int j) { return a[i] < a[j]; });       ;       for (int i = int(0); i < int(n); ++i) {         rev[p[i]] = i;       }       for (int i = int(0); i < int(1 << K); ++i) {         mb[i] = K;         while (mb[i] >= 0 && !(i & (1 << mb[i]))) {           --mb[i];         }       }       memset(ans, 0, sizeof ans);       memset(cnt, 0, sizeof cnt);       memset(hv, -1, sizeof hv);       for (int t = int(0); t < int(D); ++t) {         if (t * K >= n) {           break;         };         msk[0] = 0;         for (int i = int(0); i < int(n); ++i) {           msk[i + 1] = msk[i];           if (rev[i] >= t * K && rev[i] < (t + 1) * K) {             msk[i + 1] |= 1 << (rev[i] - t * K);           }         };         memset(v, 0, sizeof v);         memset(bt, 0, sizeof bt);         for (int w = int(0); w < int(2); ++w) {           for (int i = int(0); i < int(min(K, n - t * K)); ++i) {             for (int q = int(0); q < int(1 << i); ++q) {               if (i ? (a[p[t * K + i]] == a[p[t * K + i - 1]]) : w) {                 if (i) {                   v[w][q | (1 << i)][0] = v[w][q | (1 << (i - 1))][0];                   v[w][q | (1 << i)][1] = v[w][q | (1 << (i - 1))][1];                   bt[w][q | (1 << i)] = bt[w][q | (1 << (i - 1))];                 } else {                   v[w][q | (1 << i)][0] = v[w][q][0];                   v[w][q | (1 << i)][1] = v[w][q][1];                   bt[w][q | (1 << i)] = bt[w][q];                 }               } else {                 v[w][q | (1 << i)][0] =                     (v[w][q][0] + f[bt[w][q]] * (a[p[t * K + i]] % mod)) % mod;                 v[w][q | (1 << i)][1] =                     (v[w][q][1] + f[bt[w][q] + 1] * (a[p[t * K + i]] % mod)) %                     mod;                 bt[w][q | (1 << i)] = bt[w][q] + 1;               }             }           }         }         for (int i = int(0); i < int(m); ++i) {           int ttt = (hv[i] == -1) ? 0 : (a[p[hv[i]]] == a[p[t * K]]);           int mmm = msk[r[i]] & ~msk[l[i]];           ans[i] = (ans[i] + v[ttt][mmm][0] * f[cnt[i] + 2] +                     v[ttt][mmm][1] * f[cnt[i] + 3]) %                    mod;           ;           ;           ;           cnt[i] += bt[ttt][mmm];           if (mb[mmm] != -1) {             hv[i] = t * K + mb[mmm];           }         }       }     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     ;     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     sol.read();     sol.solve();     sol.write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sum_prefix(vector<long long> &t, int len) {     long long res = 0;     int i = len;     while (i >= 0) {       res += t[i];       i &= (i + 1);       i--;     }     return res;   }   long long sum_interval(vector<long long> &t, int l, int r) {     return sum_prefix(t, r) - sum_prefix(t, l - 1);   }   void plus_value(vector<long long> &t, int num, long long val) {     int N = t.size();     int i = num;     while (i < N) {       t[i] += val;       i |= (i + 1);     }   }   void init(vector<int> &a, vector<long long> &t) {     int i;     int N = a.size();     t.assign(N, 0);     for (i = 0; i < N; i++) plus_value(t, i, a[i]);   }   const int MAXN = 200005;   const int MAXQ = 200005;   vector<int> count_i(MAXN, 0);   vector<int> sum_i(MAXN, 0);   vector<long long> coord;   int s;   struct active {     int type;     long long a1;     long long a2;   };   int get_index(long long a) {     return lower_bound(coord.begin(), coord.end(), a) - coord.begin();   }   int main() {     int i;     set<long long>::iterator J;     int n, q;     cin >> n >> q;     vector<active> a(q);     vector<long long> now_v(n);     set<long long> coord_set;     for (i = 0; i < n; i++) {       cin >> now_v[i];       coord_set.insert(now_v[i]);     }     for (i = 0; i < q; i++) {       cin >> a[i].type;       if (a[i].type == 1) {         cin >> a[i].a1 >> a[i].a2;         a[i].a1--;         coord_set.insert(a[i].a2);       } else         cin >> a[i].a1;     }     for (J = coord_set.begin(); J != coord_set.end(); ++J) coord.push_back(*J);     s = coord.size();     for (i = 0; i < n; i++) {       count_i[get_index(now_v[i])]++;       sum_i[get_index(now_v[i])] += now_v[i];     }     vector<long long> count_i_t, sum_i_t;     init(count_i, count_i_t);     init(sum_i, sum_i_t);     int num;     long long val;     int index_now, index_val;     for (i = 0; i < q; i++) {       if (a[i].type == 1) {         num = a[i].a1;         val = a[i].a2;         index_now = get_index(now_v[num]);         index_val = get_index(val);         plus_value(count_i_t, index_now, -1);         count_i[index_now]--;         plus_value(sum_i_t, index_now, -now_v[num]);         sum_i[index_now] -= now_v[num];         plus_value(count_i_t, index_val, 1);         count_i[index_val]++;         plus_value(sum_i_t, index_val, val);         sum_i[index_val] += val;         now_v[num] = val;       } else {         val = a[i].a1;         int left = 0, right = s - 1;         double ans = -1;         while (right > left) {           int mid = (left + right) / 2;           int now_count = sum_prefix(count_i_t, mid);           if (now_count == 0) {             left = mid + 1;             continue;           }           long long now_sum = sum_prefix(sum_i_t, mid);           long long rest = val - (now_count * coord[mid] - now_sum);           if (rest < now_count * (coord[mid + 1] - coord[mid]))             right = mid;           else             left = mid + 1;         }         int now_count = sum_prefix(count_i_t, left);         long long now_sum = sum_prefix(sum_i_t, left);         long long rest = val - (now_count * coord[left] - now_sum);         ans = coord[left] + rest * 1.0 / now_count;         printf( %.6f n , ans);       }     }   }


#include <bits/stdc++.h>   template <typename T>   void scan(T &x) {     x = 0;     bool _ = 0;     T c = getchar();     _ = c == 45;     c = _ ? getchar() : c;     while (c < 48 || c > 57) c = getchar();     for (; c < 48 || c > 57; c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);     x = _ ? -x : x;   }   template <typename T>   void printn(T n) {     bool _ = 0;     _ = n < 0;     n = _ ? -n : n;     char snum[65];     int i = 0;     do {       snum[i++] = n % 10 + 48;       n /= 10;     } while (n);     --i;     if (_) putchar(45);     while (i >= 0) putchar(snum[i--]);   }   template <typename First, typename... Ints>   void scan(First &arg, Ints &...rest) {     scan(arg);     scan(rest...);   }   template <typename T>   void print(T n) {     printn(n);     putchar(10);   }   template <typename First, typename... Ints>   void print(First arg, Ints... rest) {     printn(arg);     putchar(32);     print(rest...);   }   using namespace std;   using ll = long long;   const int MM = 505;   int n;   ll a[MM], ans;   int main() {     scan(n);     for (int i = 0; i < n; i++) {       scan(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= j; k++) {           ans = max(ans, a[i] | a[j] | a[k]);         }       }     }     print(ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void tk_input(vector<T> &arr) {     for (T &i : arr) cin >> i;   }   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     int sc = 0, ls = 0, ls_i = 0, f_i = n, l_i = -1;     for (int i = 0; i <= n - 1; i++) {       if (s[i] ==  W ) {         if ((ls > 0) && (f_i != n)) pq.push(pair<int, int>(ls, ls_i));         f_i = min(f_i, i);         l_i = max(l_i, i);         ls_i = i + 1;         ls = 0;       } else {         ls++;       }     }     while ((!pq.empty()) && (k > 0)) {       auto tp = pq.top();       pq.pop();       for (int i = tp.second; i <= tp.first + tp.second - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     for (int i = f_i - 1; i >= 0; i--) {       if (k == 0) break;       s[i] =  W ;       k--;     }     if (l_i != -1) {       for (int i = l_i + 1; i <= n - 1; i++) {         if (k == 0) break;         s[i] =  W ;         k--;       }     }     sc += (s[0] ==  W );     for (int i = 1; i <= n - 1; i++) {       sc += ((s[i] ==  W ) * (1 + (s[i - 1] ==  W )));     }     cout << sc <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int _t;     cin >> _t;     while (_t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   set<pair<int, int> > s, e;   long long dp[N];   int l[N], r[N];   struct Point {     int x, h, k;     bool f;   } p[2 * N];   struct temp {     int h, k;   } q[N];   int m;   bool cmp1(const temp &a, const temp &b) { return a.h > b.h; }   bool cmp(const Point &a, const Point &b) {     if (a.x != b.x) return a.x < b.x;     if (a.f != b.f) return a.f;     return a.k < b.k;   }   vector<int> tran[N];   int main() {     set<pair<int, int> >::iterator it;     int n, t;     scanf( %d%d , &n, &t);     for (int i = 0; i < n; i++) {       int h;       scanf( %d%d%d , &h, &l[i + 1], &r[i + 1]);       p[m].x = l[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = false;       p[m].x = r[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = true;       q[i].h = h, q[i].k = i + 1;     }     l[0] = -(1 << 30), r[0] = (1 << 30);     l[n + 1] = -(1 << 30), r[n + 1] = (1 << 30);     q[n].h = t, q[n].k = 0;     q[n + 1].h = 0, q[n + 1].k = n + 1;     sort(p, p + m, cmp);     sort(q, q + n + 2, cmp1);     s.insert(make_pair(t, 0));     s.insert(make_pair(0, n + 1));     for (int i = 0; i < m; i++) {       if (p[i].f) {         it = s.find(make_pair(p[i].h, p[i].k));         if (it != s.end()) s.erase(it);       } else {         int a, b;         it = s.lower_bound(make_pair(p[i].h, 0));         a = it->second;         --it;         b = it->second;         it = e.find(make_pair(a, b));         if (it != e.end()) e.erase(it);         e.insert(make_pair(a, p[i].k));         e.insert(make_pair(p[i].k, b));         s.insert(make_pair(p[i].h, p[i].k));       }     }     for (it = e.begin(); it != e.end(); it++)       tran[it->first].push_back(it->second);     dp[0] = (1ll << 50);     for (int i = 0; i < n + 2; i++) {       int now = q[i].k;       for (int j = 0; j < tran[now].size(); j++) {         int tag = tran[now][j];         dp[tag] = max(             dp[tag], min(dp[now], min((long long)r[now], (long long)r[tag]) -                                       max((long long)l[now], (long long)l[tag])));       }     }     printf( %I64d n , dp[n + 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename TH>   void _dbg(const char* sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <typename TH, typename... TA>   void _dbg(const char* sdbg, TH h, TA... t) {     while (*sdbg !=  , ) {       cerr << *sdbg++;     }     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, t...);   }   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class A, class B, class C>   struct Triple {     A first;     B second;     C third;     bool operator<(const Triple& t) const {       if (first != t.first) return first < t.first;       if (second != t.second) return second < t.second;       return third < t.third;     }   };   template <class T>   void ResizeVec(T&, vector<long long>) {}   template <class T>   void ResizeVec(vector<T>& vec, vector<long long> sz) {     vec.resize(sz[0]);     sz.erase(sz.begin());     if (sz.empty()) {       return;     }     for (T& v : vec) {       ResizeVec(v, sz);     }   }   template <class A, class B, class C>   ostream& operator<<(ostream& out, Triple<A, B, C> t) {     return out <<  (  << t.first <<  ,   << t.second <<  ,   << t.third <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, set<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& out, map<L, R> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     if (0) cout << fixed << setprecision(10);     cin.tie(0);     long long t;     cin >> t;     for (long long ii = (1); ii <= (t); ++ii) {       long long n;       cin >> n;       vector<long long> v;       long long sum = 0;       long long ma = 0;       for (long long i = (1); i <= (n); ++i) {         long long a;         cin >> a;         v.push_back(a);         sum += a;         maxi(ma, a);       }       if (n == 1) {         cout <<  T n ;         continue;       }       if (2 * ma > sum) {         cout <<  T n ;       } else {         cout << vector<string>{ HL ,  T }[sum % 2] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, k;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 10000000000;     for (i = 1; i < n - 1; i++) {       long long b[n];       for (k = 0; k < n; k++) {         b[k] = a[k];       }       long long ans1 = 0;       for (j = 0; j < n - 1; j++) {         if (j != i - 1)           ans1 = max(ans1, b[j + 1] - b[j]);         else           ans1 = max(ans1, b[i + 1] - b[i - 1]);       }       ans = min(ans, ans1);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, i, m;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       if (n % 2 == 0) {         int f = 0;         for (i = 0; i < n; i++) {           long long a1 = int(s[i] -  0 );           if ((i + 1) % 2 == 0 && a1 % 2 == 0) {             f = 1;           }         }         if (f == 1) {           cout <<  2 ;         } else {           cout <<  1 ;         }       } else if (n % 2 != 0) {         int f = 0;         for (i = 0; i < n; i++) {           long long a1 = int(s[i] -  0 );           if ((i + 1) % 2 != 0 && a1 % 2 != 0) {             f = 1;           }         }         if (f == 1) {           cout <<  1 ;         } else {           cout <<  2 ;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h, value, width = 0;     vector<int> v;     cin >> n;     cin >> h;     for (int i = 0; i < n; i++) {       cin >> value;       v.push_back(value);     }     for (int j = 0; j < v.size(); j++) {       if (v[j] > h)         width = width + 2;       else         width = width + 1;     }     cout << width;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     if (n == 0 || n == 1) {       cout << 0 << endl;       return;     }     long long a[n];     vector<int> pos;     long long even = n / 2, odds = n - even;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] != 0) {         if (a[i] & 1)           odds--;         else           even--;         pos.push_back(i);       }     }     if (pos.size() == 0) {       cout << 1 << endl;       return;     }     vector<pair<int, int>> good;     int bad = 0;     for (int i = 1; i < pos.size(); ++i) {       if (pos[i] - pos[i - 1] != 1) {         if (a[pos[i]] % 2 == a[pos[i - 1]] % 2) {           good.push_back({pos[i], pos[i - 1]});         }       }       if (a[pos[i]] % 2 != a[pos[i - 1]] % 2) bad++;     }     sort(good.begin(), good.end(), [&](pair<int, int> a, pair<int, int> b) {       return a.first - a.second < b.first - b.second;     });     long long ans = bad;     for (auto i : good) {       int k = i.first - i.second - 1;       if (a[i.first] & 1 && odds >= k)         odds -= k;       else if (!(a[i.first] & 1) && even >= k)         even -= k;       else         ans += 2;     }     if (a[0] == 0) {       int cnt = 0;       while (a[cnt] == 0) cnt++;       if (a[cnt] & 1 && odds >= cnt)         odds -= cnt;       else if (!(a[cnt] & 1) && even >= cnt)         even -= cnt;       else         ans++;     }     if (a[n - 1] == 0) {       int cnt = 0, i = n - 1;       while (a[i] == 0) cnt++, --i;       if (!(a[i] & 1 && odds >= cnt || !(a[i] & 1) && even >= cnt)) ans++;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int maxm = 1e6 + 10;   const int mod = 1e9 + 7;   queue<string> que;   string str;   set<string> se;   int ans, n, k;   void bfs() {     if (k - 1 == 0) return;     que.push(str);     while (que.size()) {       string now = que.front();       que.pop();       for (int i = 0; i < now.size(); i++) {         string zz =   ;         for (int j = 0; j < now.size(); j++)           if (j != i) zz += now[j];         if (se.find(zz) == se.end()) {           se.insert(zz);           que.push(zz);           ans += (n - zz.size());           if (se.size() == k - 1) return;         }       }     }   }   int main() {     scanf( %d %d , &n, &k);     cin >> str;     bfs();     if (se.size() == k - 1)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1000005;   const long long M = 1000000007;   long long n, m, cc, len;   long long s[5];   int main() {     long long sum = 0;     for (long long i = 0; i < 3; i++) scanf( %I64d , &s[i]), sum += s[i];     sort(s, s + 3);     long long ans = -1;     for (long long i = 0; i < 3; i++)       for (long long j = i + 1; j < 3; j++) {         long long ano = sum - s[i] - s[j];         if ((s[i] + s[j]) % 2 == 0 && ano >= (abs(s[j] - s[i]) / 2)) {           if (ans == -1) ans = s[j];           ans = min(ans, s[j]);         }       }     if (ans == -1) ans = s[2];     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = LLONG_MAX;   const long long MINF = LLONG_MIN;   const int N = 2e5 + 5;   template <typename T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   inline long long pow_mod(long long x, long long n) {     long long r = 1;     while (n) {       if (n % 2) r = (r * x) % MOD;       x = (x * x) % MOD;       n /= 2;     }     return r;   }   inline long long pow_(long long x, long long n) {     long long r = 1;     while (n) {       if (n % 2) r = (r * x);       x = (x * x);       n /= 2;     }     return r;   }   void solve() {     int n, k, d;     cin >> n >> k >> d;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     map<int, int> m;     for (int i = 0; i < d; i++) m[a[i]]++;     int ans = (int)m.size();     for (int i = d; i < n; i++) {       m[a[i - d]]--;       if (!m[a[i - d]]) m.erase(a[i - d]);       m[a[i]]++;       ans = min(ans, (int)m.size());     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MOD = 1e9 + 7;   const int n_ = 1e5 + 1000;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   int main() {     ios_base::sync_with_stdio(false);     long long n, x, y, a;     scanf( %lld %lld %lld , &n, &x, &y);     a = y - n + 1;     if (a > 0 && a * a + n - 1 >= x) {       for (int(i) = 0; (i) < (n - 1); (i)++) puts( 1 );       printf( %lld n , a);     } else {       puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string nsp(string s) {     string t =   ;     for (int i = 0; i < s.size(); i++)       if (s[i] !=    ) t = t + s[i];     return t;   }   string gfbu(string s, char c, int a) {     string t =   ;     for (int i = a; i < s.size() - 1; i++) {       if (s[i] == c) return t;       t += s[i];     }     return t;   }   int in(string s) {     return (s ==  double  ? 2 : (s ==  int  ? 3 : (s ==  T  ? 1 : 5)));   }   vector<int> ext(string s) {     int cnt = gfbu(s,  ( , 0).size() + 1;     vector<int> v;     while (cnt < s.size())       v.push_back(in(gfbu(s,  , , cnt))), cnt += gfbu(s,  , , cnt).size() + 1;     return v;   }   int main() {     int n, m, k;     map<string, int> ints;     map<string, vector<vector<int> > > voids;     cin >> n;     for (int i = 0; i < n; i++) {       string trash, s, vo;       if (i == 0) cin.ignore();       getline(cin, s), s = nsp(s), s.erase(0, 4);       vo = gfbu(s,  ( , 0), voids[vo].push_back(ext(s));     }     cin >> m;     for (int i = 0; i < m; i++) {       string s, t;       cin >> s >> t, ints[t] = in(s);     }     cin >> k;     for (int i = 0; i < k; i++) {       if (i == 0) cin.ignore();       string s, vo;       getline(cin, s), s = nsp(s), vo = gfbu(s,  ( , 0);       int ans = 0, cnt = gfbu(s,  ( , 0).size() + 1;       vector<int> vi;       while (cnt < s.size())         vi.push_back(ints[gfbu(s,  , , cnt)]),             cnt += gfbu(s,  , , cnt).size() + 1;       if (voids[vo].size() == 0) {         cout <<  0 n ;         continue;       }       for (int j = 0; j < voids[vo].size(); j++) {         if (voids[vo][j].size() != vi.size()) continue;         for (int k = 0; k < vi.size(); k++)           if (vi[k] % voids[vo][j][k]) {             ans--;             break;           }         ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1000;   const long long INF64 = 1e18;   const int N = 1001000;   const int MOD = 1e9 + 7;   const double EPS = 1E-9;   long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }   int add(int first, int second, int m) {     first += second;     while (first >= m) first -= m;     while (first < 0) first += m;     return first;   }   int sub(int first, int second, int m) { return add(first, -second, m); }   int mul(int first, int second, int m) { return (first * 1ll * second) % m; }   int binpow(int first, int second, int m) {     int z = 1;     while (second) {       if (second & 1) z = mul(z, first, m);       first = mul(first, first, m);       second >>= 1;     }     return z;   }   int divide(int first, int second, int m) {     return mul(first, binpow(second, m - 2, m), m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int first, t, a, b, da, db;     cin >> first >> t >> a >> b >> da >> db;     if (first == 0) {       cout <<  YES n ;       return 0;     }     for (int ta = 0; ta < t; ++ta) {       for (int tb = 0; tb < t; ++tb) {         if (a - da * ta + b - db * tb == first || a - da * ta == first ||             b - db * tb == first) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   const long long int MOD = 1e9 + 7;   using namespace std;   constexpr int mul(int a, int b) { return 1LL * a * b % MOD; }   template <typename... T>   constexpr int mul(int a, int b, T... t) {     return mul(mul(a, b), t...);   }   template <class T>   inline T Min(const T &a, const T &b) {     return a < b ? a : b;   }   template <class T>   inline T Max(const T &a, const T &b) {     return a < b ? b : a;   }   inline void inc(int &x, int &v, int &mod) {     x += v;     if (x >= mod) x -= mod;   }   inline void dec(int &x, int &v, int &mod) {     x -= v;     if (x < 0) x += mod;   }   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long int readl() {     char ch = getchar();     long long int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int T[200010 << 2][9], MIN[200010 << 2][9], minsum[200010 << 2][9];   int a[200010];   int res1, res2;   void pushup(int now, int k) {     T[now][k] = T[now << 1][k] + T[now << 1 | 1][k];     MIN[now][k] = Min(MIN[now << 1][k], MIN[now << 1 | 1][k]);     minsum[now][k] = Min(minsum[now << 1][k], minsum[now << 1 | 1][k]);     if (T[now << 1][k] != 0 && T[now << 1 | 1][k] != 0)       minsum[now][k] =           Min(minsum[now][k], MIN[now << 1][k] + MIN[now << 1 | 1][k]);   }   void build(int l, int r, int now, int k) {     if (l == r) {       int tmp = a[l];       for (int i = 0; i < k; i++) {         tmp /= 10;       }       minsum[now][k] = MIN[now][k] = 2e9;       if (tmp % 10 != 0) {         MIN[now][k] = a[l];         T[now][k] = 1;       } else         T[now][k] = 0;       return;     }     int mid = (l + r) >> 1;     build(l, mid, now << 1, k);     build(mid + 1, r, now << 1 | 1, k);     pushup(now, k);   }   int query(int L, int R, int l, int r, int now, int k) {     if (L <= l && r <= R) {       return T[now][k];     }     int mid = (l + r) >> 1;     int ans = 0;     if (L <= mid) ans += query(L, R, l, mid, now << 1, k);     if (mid < R) ans += query(L, R, mid + 1, r, now << 1 | 1, k);     return ans;   }   int query2(int L, int R, int l, int r, int now, int k) {     if (L <= l && r <= R) {       if (MIN[now][k] < res1) {         res2 = res1;         res1 = MIN[now][k];       } else if (MIN[now][k] < res2) {         res2 = MIN[now][k];       }       return minsum[now][k];     }     int mid = (l + r) >> 1;     int ans1 = 2e9, ans2 = 2e9;     if (L <= mid) ans1 = query2(L, R, l, mid, now << 1, k);     if (mid < R) ans2 = query2(L, R, mid + 1, r, now << 1 | 1, k);     return Min(ans1, ans2);   }   void update(int pos, int C, int l, int r, int now, int k) {     if (l == r) {       int tmp = C;       for (int i = 0; i < k; i++) tmp /= 10;       minsum[now][k] = MIN[now][k] = 2e9;       if (tmp % 10 != 0) {         MIN[now][k] = C;         T[now][k] = 1;       } else         T[now][k] = 0;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update(pos, C, l, mid, now << 1, k);     else       update(pos, C, mid + 1, r, now << 1 | 1, k);     pushup(now, k);   }   int main() {     int n = read(), q = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 0; i < 9; i++) {       build(1, n, 1, i);     }     while (q--) {       int op = read(), a = read(), b = read();       if (op == 1) {         for (int i = 0; i < 9; i++) update(a, b, 1, n, 1, i);       } else {         bool tag = true;         int sum = 2e9;         for (int i = 0; i < 9; i++) {           int cnt = query(a, b, 1, n, 1, i);           if (cnt > 1) {             res1 = res2 = 1e9;             sum = Min(Min((res1 + res2), sum), query2(a, b, 1, n, 1, i));             tag = false;           }         }         if (tag) {           printf( -1 n );         } else {           printf( %d n , sum);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int score(pair<int, int> a) {     int d = abs(a.first - a.second);     return min(d, n - d);   }   const int N = 1e5 + 7;   int nxt[N], prv[N];   vector<int> regions[N];   vector<int> adj[N];   int level[N];   int sz[N];   void dfs1(int u, int par) {     assert(level[u] == 0);     sz[u] = 1;     for (int v : adj[u]) {       if (v == par || level[v]) continue;       dfs1(v, u);       sz[u] += sz[v];     }   }   int dfs2(int u, int par, int s) {     for (int v : adj[u]) {       if (v == par || level[v]) continue;       if (sz[v] > s / 2) return dfs2(v, u, s);     }     return u;   }   void decompose(int u, int lev) {     assert(level[u] == 0);     dfs1(u, -1);     int v = dfs2(u, -1, sz[u]);     level[v] = lev;     for (int w : adj[v])       if (!level[w]) decompose(w, lev + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     vector<pair<int, int>> diags;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       diags.push_back({a, b});     }     auto cmp1 = [](pair<int, int> a, pair<int, int> b) {       return score(a) < score(b);     };     sort(diags.begin(), diags.end(), cmp1);     for (int i = 1; i <= n; i++) {       nxt[i] = 1 + i % n;     }     int id = 0, last = 0;     for (auto pr : diags) {       ++id;       int u = pr.first;       int v = pr.second;       int d = (v - u + n) % n;       if (d >= n - d) swap(u, v);       int cur = u;       while (cur != v) {         regions[id].push_back(cur);         cur = nxt[cur];       }       regions[id].push_back(v);       nxt[u] = v;       last = u;     }     ++id;     int cur = last;     while (true) {       regions[id].push_back(cur);       cur = nxt[cur];       if (cur == last) break;     }     map<pair<int, int>, vector<int>> mp;     for (int i = 1; i <= id; i++) {       for (int j = 0; j < regions[i].size(); j++) {         int u = regions[i][j];         int v = regions[i][(j + 1) % regions[i].size()];         if (u > v) swap(u, v);         mp[make_pair(u, v)].push_back(i);       }     }     for (auto pr : mp) {       assert(pr.second.size() <= 2);       if (pr.second.size() != 2) continue;       int u = pr.second[0];       int v = pr.second[1];       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= id; i++) {       sort(regions[i].rbegin(), regions[i].rend());     }     vector<int> order;     for (int i = 1; i <= id; i++) {       order.push_back(i);     }     sort(order.begin(), order.end(),          [](int a, int b) { return regions[a] < regions[b]; });     decompose(1, 1);     for (int x : order) cout << level[x] <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) {       v.emplace_back(x);     }     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     err(++it, args...);   }   vector<pair<int, int>> vt[101];   int dp[101][101][26][2];   bool rec(int u, int v, int ch, int side) {     if (dp[u][v][ch][side] != -1) return dp[u][v][ch][side];     int ans = 0;     if (side) {       for (auto g : vt[v]) {         if (g.second >= ch) ans |= !rec(u, g.first, g.second, side ^ 1);       }     } else {       for (auto g : vt[u]) {         if (g.second >= ch) ans |= !rec(g.first, v, g.second, side ^ 1);       }     }     return dp[u][v][ch][side] = ans;   }   int main() {     memset(dp, -1, sizeof dp);     int n, m, i, j, u, v;     cin >> n >> m;     char c;     for (i = 0; i < m; ++i) {       cin >> u >> v >> c;       vt[u].push_back({v, c -  a });     }     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         if (rec(i, j, 0, 0))           printf( A );         else           printf( B );       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   long long power(long long a, long long b) {     long long p_res = 1;     while (b > 0) {       if (b % 2 == 1) {         p_res *= a;         b--;       }       a *= a;       b /= 2;     }     return p_res;   }   int cc[300001];   int ans[300001];   set<pair<int, int> > ss;   set<pair<int, int> >::iterator it;   vector<int> adj[300001];   int n, q;   int dfs(int here) {     int res = 1;     for (int i = 0; i < adj[here].size(); i++) {       res += dfs(adj[here][i]);     }     cc[here] = res;     return res;   }   void centroid(int here, int prev) {     int mx = 0;     for (int i = 0; i < adj[here].size(); i++) {       int next = adj[here][i];       mx = max(mx, cc[next]);     }     if (2 * mx <= cc[here])       ans[here] = here;     else       ss.insert(make_pair(cc[here], here));     it = ss.lower_bound(make_pair(2 * mx, -1));     while (it != ss.end()) {       int v = it->first;       int i = it->second;       if (v > 2 * cc[here]) break;       if (2 * mx <= v && 2 * (v - cc[here]) <= v) {         ans[i] = here;         ss.erase(it++);       } else         it++;     }     for (int i = 0; i < adj[here].size(); i++) {       centroid(adj[here][i], here);     }   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 2; i <= n; i++) {       int v;       scanf( %d , &v);       adj[v].push_back(i);     }     dfs(1);     centroid(1, -1);     for (int i = 0; i < q; i++) {       int v;       scanf( %d , &v);       printf( %d n , ans[v]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300100;   const int K = 1001000;   vector<int> v[K];   int a[N], s[N];   int l[N], r[N];   int q[N], id[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     s[0] = a[0] % k;     v[0].push_back(-1);     v[s[0]].push_back(0);     for (int i = 1; i < n; i++) {       s[i] = (s[i - 1] + a[i]) % k;       v[s[i]].push_back(i);     }     int c = 0;     for (int i = 0; i < n; i++) {       while (c && a[q[c - 1]] < a[i]) c--;       l[i] = 0;       if (c) {         l[i] = q[c - 1] + 1;       }       q[c++] = i;     }     c = 0;     for (int i = n - 1; i >= 0; i--) {       while (c && a[q[c - 1]] <= a[i]) c--;       r[i] = n - 1;       if (c) {         r[i] = q[c - 1] - 1;       }       q[c++] = i;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i - l[i] >= r[i] - i) {         for (int j = i; j <= r[i]; j++) {           int x = (s[j] - a[i]) % k;           if (x < 0) {             x += k;           }           int ll = l[i] - 1, rr = i - 1;           if (j == i) rr = i - 2;           ans += upper_bound(v[x].begin(), v[x].end(), rr) -                  lower_bound(v[x].begin(), v[x].end(), ll);         }       } else {         for (int j = l[i]; j <= i; j++) {           int x = (a[i] + s[j - 1]) % k;           if (x < 0) {             x += k;           }           int ll = i, rr = r[i];           if (j == i) ll = i + 1;           ans += upper_bound(v[x].begin(), v[x].end(), rr) -                  lower_bound(v[x].begin(), v[x].end(), ll);         }       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   const int N = 1e5 + 10;   int n, a[N], s[N], c[N << 1];   inline void add(int x) {     for (; x; x -= (x & (-x))) ++c[x];   }   inline void _add(int x) {     for (; x; x -= (x & (-x))) --c[x];   }   inline int ask(int x) {     int res = 0;     for (; x <= (n << 1); x += (x & (-x))) res += c[x];     return res;   }   signed main() {     int T;     read(T);     while (T--) {       int k, ok = 0, kk = 0;       read(n), read(k);       for (int i = 1; i <= n; ++i) read(a[i]);       for (int i = 1; i <= n; ++i)         if (a[i] == k) {           kk = 1;           break;         }       if (n == 1) {         a[1] == k ? puts( yes ) : puts( no );         continue;       }       if (n == 2) {         if (a[1] == k && a[2] >= k || a[2] == k && a[1] >= k)           puts( yes );         else           puts( no );         continue;       }       for (int i = 3; i <= n; ++i) {         int c = 0;         for (int j = i - 2; j <= i; ++j) c += (a[j] >= k);         if (c >= 2) {           ok = 1;           break;         }       }       (ok && kk) ? puts( yes ) : puts( no );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1.0e-5;   const int maxn = 100000 + 10;   const int mod = 1e9 + 7;   int a, b[505], n;   int main() {     memset(b, 0, sizeof(b));     long long ans = 0;     int tmp;     scanf( %d , &n);     for (int i = 1; i <= n - 1; i++) ans = (2 * ans + 1) % mod;     for (int i = 1; i <= n; i++) {       scanf( %d , &tmp);       if (tmp >= 0) {         ans -= (long long)b[tmp] + 1;         b[tmp] = (2 * b[tmp] + 1) % mod;       }     }     printf( %lld n , (ans % mod + mod) % mod);   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5 + 10;   const long long INF = 1e18;   long long n, a[maxn], po, maxx = 0, m[maxn];   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> m[i];       if (m[i] > maxx) {         maxx = m[i];         po = i;       }     }     long long ans, maxx = 0;     for (int po = 1; po <= n; po++) {       long long sum = 0;       a[po] = m[po];       sum += a[po];       for (int i = po - 1; i >= 1; i--) {         a[i] = min(m[i], a[i + 1]);         sum += a[i];       }       for (int i = po + 1; i <= n; i++) {         a[i] = min(m[i], a[i - 1]);         sum += a[i];       }       if (sum > maxx) {         maxx = sum;         ans = po;       }     }     long long po = ans;     a[po] = m[po];     for (int i = po - 1; i >= 1; i--) {       a[i] = min(m[i], a[i + 1]);     }     for (int i = po + 1; i <= n; i++) {       a[i] = min(m[i], a[i - 1]);     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     int a1 = abs(a - c) * 2;     int b1 = abs(b - d) * 2;     int ans = a1 + b1 + 4;     if (a != c && b != d)       printf( %d n , ans);     else       printf( %d n , ans + 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a, b;   long long mini = (long long)1e15;   long long maxi = 0;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void calc(long long l) {     if (l <= 0 || l > n * k) return;     long long tmp = n * k / gcd(n * k, l);     mini = min(tmp, mini);     maxi = max(tmp, maxi);   }   int main() {     cin >> n >> k >> a >> b;     for (int i = -2; i <= n; ++i) {       calc(k * i + b - a);       calc(k * i - b - a);       calc(k * i + b + a);       calc(k * i - b + a);     }     cout << mini <<     << maxi << endl;   }


#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     std::vector<std::vector<int>> graph(n);     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       graph.at(a).push_back(b);       graph.at(b).push_back(a);     }     std::vector<int> color(n, -1);     bool ok = true;     for (int s = 0; s < n && ok; ++s) {       if (!~color[s]) {         std::vector<int> queue;         queue.push_back(s);         color[s] = 0;         for (int h = 0; h < static_cast<int>(queue.size()); ++h) {           auto u = queue[h];           for (int v : graph.at(u)) {             if (!~color[v]) {               color[v] = color[u] ^ 1;               queue.push_back(v);             }             ok &= color[u] != color[v];           }         }       }     }     if (ok) {       std::vector<std::vector<int>> result(2);       for (int i = 0; i < n; ++i) {         result[color[i]].push_back(i);       }       for (int i = 0; i < 2; ++i) {         printf( %d n , static_cast<int>(result[i].size()));         for (auto&& v : result[i]) {           printf( %d  , v + 1);         }         puts(  );       }     } else {       puts( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, l[300], c[300];     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> c[i];     unordered_map<int, int> um;     for (int i = 0; i < n; i++)       if (um.find(l[i]) != um.end())         um[l[i]] = min(um[l[i]], c[i]);       else         um.emplace(l[i], c[i]);     for (int i = 0; i < n; i++) {       vector<pair<int, int>> ve;       for (auto& elem : um) {         int g = gcd(elem.first, l[i]);         if (um.find(g) != um.end())           um[g] = min(um[g], elem.second + c[i]);         else           ve.emplace_back(g, elem.second + c[i]);       }       for (auto& elem : ve) um.insert(elem);     }     cout << (um[1] ?: -1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct B {     int p, id;   };   priority_queue<B> q;   bool operator<(const B &a, const B &b) { return a.p < b.p; }   int main() {     string s;     long long a, b, l, len, cost, i;     B tmp;     cin >> s;     l = 0;     len = s.size();     cost = 0;     for (i = 0; i < len; i++) {       if (s[i] ==  ( )         l++;       else if (s[i] ==  ) )         l--;       else {         cin >> a >> b;         tmp.p = b - a;         tmp.id = i;         q.push(tmp);         s[i] =  ) ;         l--;         cost += b;       }       if (l < 0) {         if (q.empty()) break;         tmp = q.top();         q.pop();         cost -= tmp.p;         s[tmp.id] =  ( ;         l += 2;       }     }     if (l != 0)       cout << -1 << endl;     else {       cout << cost << endl;       cout << s << endl;     }     while (!q.empty()) q.pop();   }


#include <bits/stdc++.h>   using namespace std;   struct p {     int x;     int i;   } a[200123];   int cmp(p a, p b) {     if (a.x != b.x)       return a.x < b.x;     else       return a.i < b.i;   }   int main() {     int n;     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i].x);       a[i].i = i;     }     sort(a, a + n, cmp);     int mi = 0;     long long y = 0;     i = 1;     while (i < n && a[i].x == a[0].x) {       if (a[i].i - a[i - 1].i - 1 > mi) mi = a[i].i - a[i - 1].i - 1;       i++;     }     if (a[0].i + n - a[i - 1].i - 1 > mi) mi = a[0].i + n - a[i - 1].i - 1;     y = (long long)a[0].x * n + mi;     printf( %lld n , y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const double pi = 2 * acos(0.0);   const int MOD = 1000000007;   vector<int> g[5];   int id[222][222], k[222];   bool ok[222];   int wh[222];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> wh[i];       g[wh[i]].push_back(i);     }     for (int i = 1; i <= n; ++i) {       cin >> k[i];       for (int j = 1; j <= k[i]; ++j) cin >> id[i][j];     }     int res = inf;     for (int ST = 1; ST <= 3; ++ST) {       int st = ST;       memset(ok, false, sizeof(ok));       int cnt = 0, ans = 0;       for (;;) {         if (cnt == n) break;         for (;;) {           bool doing = false;           for (int c = 0; c <= (int)g[st].size() - 1; ++c) {             int work = g[st][c];             if (ok[work]) continue;             bool is = true;             for (int i = 1; i <= k[work]; ++i)               if (!ok[id[work][i]]) is = false;             if (is) {               doing = true;               ++ans;               ok[work] = true;               ++cnt;             }           }           if (!doing) break;         }         if (cnt == n) break;         ++ans;         st++;         if (st == 4) st = 1;       }       res = min(res, ans);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     int i = 1;     while (true) {       int cnt = i / 2 + 1;       if (cnt == a) {         break;       }       ++i;     }     cout << i <<     << 2 << endl;     cout <<  1 2 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pdd = pair<double, double>;   using vpii = vector<pii>;   using vvpii = vector<vpii>;   using vpll = vector<pll>;   using vvpll = vector<vpll>;   using vpdd = vector<pdd>;   using vvpdd = vector<vpdd>;   template <typename T>   void ckmin(T& a, const T& b) {     a = min(a, b);   }   template <typename T>   void ckmax(T& a, const T& b) {     a = max(a, b);   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   namespace __input {   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   template <class Arg, class... Args>   void re(Arg& first, Args&... rest) {     re(first);     re(rest...);   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.first, p.second);   }   template <class T>   void re(vector<T>& a) {     for (int i = 0; i < (int((a).size())); i++) re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = 0; i < (SZ); i++) re(a[i]);   }   }  // namespace __input   using namespace __input;   namespace __output {   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T, size_t SZ>   void pr(const array<T, SZ>& x);   template <class T>   void pr(const vector<T>& x);   template <class T>   void pr(const deque<T>& x);   template <class T>   void pr(const set<T>& x);   template <class T1, class T2>   void pr(const map<T1, T2>& x);   template <class T>   void pr(const T& x) {     cout << x;   }   template <class Arg, class... Args>   void pr(const Arg& first, const Args&... rest) {     pr(first);     pr(rest...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.first,  ,  , x.second,  } );   }   template <class T, bool pretty = true>   void prContain(const T& x) {     if (pretty) pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ? pretty ?  ,   :     :   , a), fst = 0;     if (pretty) pr( } );   }   template <class T>   void pc(const T& x) {     prContain<T, false>(x);     pr(  n );   }   template <class T, size_t SZ>   void pr(const array<T, SZ>& x) {     prContain(x);   }   template <class T>   void pr(const vector<T>& x) {     prContain(x);   }   template <class T>   void pr(const deque<T>& x) {     prContain(x);   }   template <class T>   void pr(const set<T>& x) {     prContain(x);   }   template <class T1, class T2>   void pr(const map<T1, T2>& x) {     prContain(x);   }   void ps() { pr(  n ); }   template <class Arg>   void ps(const Arg& first) {     pr(first);     ps();   }   template <class Arg, class... Args>   void ps(const Arg& first, const Args&... rest) {     pr(first,    );     ps(rest...);   }   }  // namespace __output   using namespace __output;   namespace __algorithm {   template <typename T>   void dedup(vector<T>& v) {     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), v.end());   }   template <typename T>   typename vector<T>::iterator find(vector<T>& v, const T& x) {     auto it = lower_bound((v).begin(), (v).end(), x);     return it != v.end() && *it == x ? it : v.end();   }   template <typename T>   size_t index(vector<T>& v, const T& x) {     auto it = find(v, x);     assert(it != v.end() && *it == x);     return it - v.begin();   }   template <typename C, typename T, typename OP>   vector<T> prefixes(const C& v, T id, OP op) {     vector<T> r(int((v).size()) + 1, id);     for (int i = 0; i < (int((v).size())); i++) r[i + 1] = op(r[i], v[i]);     return r;   }   template <typename C, typename T, typename OP>   vector<T> suffixes(const C& v, T id, OP op) {     vector<T> r(int((v).size()) + 1, id);     for (int i = (int((v).size())) - 1; i >= 0; i--) r[i] = op(v[i], r[i + 1]);     return r;   }   }  // namespace __algorithm   using namespace __algorithm;   #pragma GCC diagnostic push   #pragma GCC diagnostic ignored  -Wunused-parameter    struct monostate {     friend istream& operator>>(istream& is, const monostate& ms) { return is; }     friend ostream& operator<<(ostream& os, const monostate& ms) { return os; }     friend monostate operator+(const monostate& a, const monostate& b) {       return a;     }   } ms;   #pragma GCC diagnostic pop   namespace __io {   void setIn(string second) { freopen(second.c_str(),  r , stdin); }   void setOut(string second) { freopen(second.c_str(),  w , stdout); }   void setIO(string second =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(15);     if (int((second).size())) {       setIn(second +  .in ), setOut(second +  .out );     }   }   }  // namespace __io   using namespace __io;   bool taste(int loc) {     cout <<  ?   << loc + 1 << endl;     char r;     re(r);     if (r ==  E ) assert(0);     return r !=  Y ;   }   int main() {     setIO();     int N, K;     re(N, K);     int SZ = max(K / 2, 1);     int M = N / SZ;     vi ct(N, 1);     for (int j = (1); j < (M); j++) {       for (int res = 0; res < (j); res++)         if (res + j < M) {           cout <<  R  << endl;           for (int i = res; i < M; i += j) {             for (int k = 0; k < (SZ); k++) ct[i * SZ + k] &= taste(i * SZ + k);           }         }     }     cout <<  !   << accumulate((ct).begin(), (ct).end(), 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long INF = 1e18;   const double eps = 1e-10;   mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());   template <class T>   inline void upmin(T &x, T y) {     x = x > y ? y : x;   }   template <class T>   inline void upmax(T &x, T y) {     x = x < y ? y : x;   }   const int maxn = 1e5 + 233;   vector<int> G[maxn];   int n;   int col[maxn];   int fa[maxn];   int cnt[maxn];   void dfs(int u, int f) {     for (auto v : G[u]) {       if (v == f) continue;       col[v] = 3 - col[u];       fa[v] = u;       dfs(v, u);     }   }   int deg[maxn];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(10);     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].emplace_back(v);       G[v].emplace_back(u);       deg[u]++;       deg[v]++;     }     for (int i = 1; i <= n; i++) {       if (deg[i] > 1) {         col[i] = 1;         dfs(i, 0);         break;       }     }     int f1 = 0, f2 = 0;     for (int i = 1; i <= n; i++) {       if (deg[i] == 1) {         if (col[i] == 1)           f1 = 1;         else           f2 = 1;         cnt[fa[i]]++;       }     }     int mn, mx;     if (f1 && f2)       mn = 3;     else       mn = 1;     mx = n - 1;     for (int i = 1; i <= n; i++) {       if (cnt[i]) mx -= cnt[i] - 1;     }     cout << mn <<     << mx <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   stack<pair<long long, long long> > q;   long long n, a[N], go[N];   struct cell {     long long max_l, max_r, or_l, or_r;   };   bool d[N][35];   cell b[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) {       long long q = a[i], k = 1;       while (q != 0) {         d[i][k] = q % 2;         q /= 2;         k++;       }     }     q.push({0, 2e9});     for (long long i = 1; i <= n; i++) {       while (q.top().second <= a[i]) q.pop();       b[i].max_l = q.top().first;       q.push({i, a[i]});     }     while (!q.empty()) q.pop();     q.push({n + 1, 2e9});     for (long long i = n; i > 0; i--) {       while (q.top().second < a[i]) q.pop();       b[i].max_r = q.top().first;       q.push({i, a[i]});     }     while (!q.empty()) q.pop();     for (long long i = 1; i <= n; i++) {       long long k = 0;       for (long long j = 1; j < 35; j++)         if (d[i][j] == 0)           k = max(k, go[j]);         else           go[j] = i;       b[i].or_l = k;     }     for (long long i = 1; i < 35; i++) go[i] = n + 1;     for (long long i = n; i > 0; i--) {       long long k = n + 1;       for (long long j = 1; j < 35; j++)         if (d[i][j] == 0)           k = min(k, go[j]);         else           go[j] = i;       b[i].or_r = k;     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (b[i].max_l >= b[i].or_l)         if (b[i].max_r <= b[i].or_r)           continue;         else           ans += (i - b[i].max_l) * (b[i].max_r - b[i].or_r);       else if (b[i].max_r <= b[i].or_r)         ans += (b[i].or_l - b[i].max_l) * (b[i].max_r - i);       else {         ans += (b[i].or_l - b[i].max_l) * (b[i].or_r - i);         ans += (b[i].max_r - b[i].or_r) * (i - b[i].or_l);         ans += (b[i].or_l - b[i].max_l) * (b[i].max_r - b[i].or_r);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> ev[1000099];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> p(n), pos(n);     for (int(i) = (0); (i) < (int)(n); ++(i)) {       cin >> p[i];       p[i]--;       pos[p[i]] = i;       ev[n - i].push_back(p[i]);       int k = (p[i] - i + n) % n;       if (k != n - i) ev[k].push_back(p[i]);     }     long long sm = 0;     int x = 0, y = 0;     vector<int> state(n);     for (int(i) = (0); (i) < (int)(n); ++(i)) {       if (i < p[i])         x++, state[p[i]] = -1;       else         y++, state[p[i]] = 1;       sm += abs(i - p[i]);     }     long long mi = LLONG_MAX;     int ans = -1;     for (int(i) = (0); (i) < (int)(n); ++(i)) {       if (i > 0) {         for (auto &(num) : (ev[i])) {           int nextPos = (pos[num] + i) % n;           int prePos = (pos[num] + i - 1) % n;           int nextState = nextPos < num ? -1 : 1;           sm += abs(nextPos - num) - abs(prePos - num);           if (state[num] == -1 && nextState == 1) {             sm--;             x--;             y++;             state[num] = 1;           } else if (state[num] == 1 && nextState == -1) {             sm++;             x++;             y--;             state[num] = -1;           } else if (state[num] == nextState) {             if (state[num] == 1)               sm--;             else               sm++;           }         }         sm -= x;         sm += y;       }       if (sm < mi) {         ans = i;         mi = sm;       }     }     cout << mi <<     << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int numOfComparisons, HomeUniform, GuestUniform, count = 0;     cin >> numOfComparisons;     int *Home = new int[numOfComparisons];     int *Guest = new int[numOfComparisons];     for (int i = 0; i < numOfComparisons; i++) {       cin >> Home[i] >> Guest[i];     }     for (int i = 0; i < numOfComparisons; i++) {       for (int j = 0; j < numOfComparisons; j++) {         if (Home[i] == Guest[j]) count++;       }     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class T>   using pq = priority_queue<T>;   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   int scan() { return getchar(); }   void scan(int& a) { cin >> a; }   void scan(long long& a) { cin >> a; }   void scan(char& a) { cin >> a; }   void scan(double& a) { cin >> a; }   void scan(long double& a) { cin >> a; }   void scan(char a[]) { scanf( %s , a); }   void scan(string& a) { cin >> a; }   template <class T>   void scan(vector<T>&);   template <class T, size_t size>   void scan(array<T, size>&);   template <class T, class L>   void scan(pair<T, L>&);   template <class T, size_t size>   void scan(T (&)[size]);   template <class T>   void scan(vector<T>& a) {     for (auto& i : a) scan(i);   }   template <class T>   void scan(deque<T>& a) {     for (auto& i : a) scan(i);   }   template <class T, size_t size>   void scan(array<T, size>& a) {     for (auto& i : a) scan(i);   }   template <class T, class L>   void scan(pair<T, L>& p) {     scan(p.first);     scan(p.second);   }   template <class T, size_t size>   void scan(T (&a)[size]) {     for (auto& i : a) scan(i);   }   template <class T>   void scan(T& a) {     cin >> a;   }   void IN() {}   template <class Head, class... Tail>   void IN(Head& head, Tail&... tail) {     scan(head);     IN(tail...);   }   string stin() {     string s;     cin >> s;     return s;   }   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   vector<int> iota(int n) {     vector<int> a(n);     iota(begin(a), end(a), 0);     return a;   }   template <class T>   void UNIQUE(vector<T>& x) {     sort(begin(x), end(x));     x.erase(unique(begin(x), end(x)), x.end());   }   int in() {     int x;     cin >> x;     return x;   }   long long lin() {     unsigned long long x;     cin >> x;     return x;   }   void print() { putchar(   ); }   void print(bool a) { cout << a; }   void print(int a) { cout << a; }   void print(long long a) { cout << a; }   void print(char a) { cout << a; }   void print(string& a) { cout << a; }   void print(double a) { cout << a; }   template <class T>   void print(const vector<T>&);   template <class T, size_t size>   void print(const array<T, size>&);   template <class T, class L>   void print(const pair<T, L>& p);   template <class T, size_t size>   void print(const T (&)[size]);   template <class T>   void print(const vector<T>& a) {     if (a.empty()) return;     print(a[0]);     for (auto i = a.begin(); ++i != a.end();) {       cout <<    ;       print(*i);     }     cout << endl;   }   template <class T>   void print(const deque<T>& a) {     if (a.empty()) return;     print(a[0]);     for (auto i = a.begin(); ++i != a.end();) {       cout <<    ;       print(*i);     }   }   template <class T, size_t size>   void print(const array<T, size>& a) {     print(a[0]);     for (auto i = a.begin(); ++i != a.end();) {       cout <<    ;       print(*i);     }   }   template <class T, class L>   void print(const pair<T, L>& p) {     cout <<  ( ;     print(p.first);     cout <<  , ;     print(p.second);     cout <<  ) ;   }   template <class T>   void print(set<T>& x) {     for (auto e : x) print(e), cout <<    ;     cout << endl;   }   template <class T, size_t size>   void print(const T (&a)[size]) {     print(a[0]);     for (auto i = a; ++i != end(a);) {       cout <<    ;       print(*i);     }   }   template <class T>   void print(const T& a) {     cout << a;   }   int out() {     putchar(  n );     return 0;   }   template <class T>   int out(const T& t) {     print(t);     putchar(  n );     return 0;   }   template <class Head, class... Tail>   int out(const Head& head, const Tail&... tail) {     print(head);     putchar(   );     out(tail...);     return 0;   }   long long gcd(long long a, long long b) {     while (b) {       long long c = b;       b = a % b;       a = c;     }     return a;   }   long long lcm(long long a, long long b) {     if (!a || !b) return 0;     return a * b / gcd(a, b);   }   vector<pair<long long, long long>> factor(long long x) {     vector<pair<long long, long long>> ans;     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) {         ans.push_back({i, 1});         while ((x /= i) % i == 0) ans.back().second++;       }     if (x != 1) ans.push_back({x, 1});     return ans;   }   vector<int> divisor(int x) {     vector<int> ans;     for (int i = 1; i * i <= x; i++)       if (x % i == 0) {         ans.push_back(i);         if (i * i != x) ans.push_back(x / i);       }     return ans;   }   int popcount(long long x) { return __builtin_popcountll(x); }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int rnd(int n) { return uniform_int_distribution<int>(0, n - 1)(rng); }   template <class... T>   void err(const T&...) {}   struct Setup_io {     Setup_io() {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       cout << fixed << setprecision(15);     }   } setup_io;   double d(long long x, long long y) {     return sqrt((long double)x * (long double)x +                 (long double)y * (long double)y);   }   double d(pair<int, int> x) { return d(x.first, x.second); }   int main() {     int n, k;     IN(n, k);     map<pair<int, int>, vector<pair<int, int>>> mp;     for (long long i = 0; i < n; ++i) {       long long a, b;       IN(a, b);       if (!a and !b) continue;       if (b < 0 or (b == 0 and a <= 0)) {         long long g = gcd(a, b);         g = abs(g);         mp[{a / g, b / g}].emplace_back(abs(a), abs(b));       } else {         long long g = gcd(a, b);         g = abs(g);         mp[{a / g, b / g}].emplace_back(abs(a), abs(b));       }     }     vector<long double> ans{0};     bool flag = false;     for (auto [e, v] : mp) {       sort(begin(v), end(v), greater<pair<int, int>>());       if (v.size() > k / 2) {         for (long long i = 0; i < k / 2; ++i) {           long double D = d(v[i]);           ans.emplace_back(D * (k - 1 - i * 2));         }         int c = k / 2;         long double dist = 0;         for (long long i = v.size() - 1; i >= c; --i) {           long double D = d(v[i]);           ans.emplace_back(D * (k - 1 - c * 2) - dist);           dist += D * 2;         }       } else         for (long long i = 0; i < v.size(); ++i) {           long double D = d(v[i]);           ans.emplace_back(D * (k - 1 - i * 2));         }     }     sort(begin(ans), end(ans), greater<long double>());     long double sum = 0;     for (long long i = 0; i < k; ++i) sum += ans[i];     cout << sum <<   n ;   }


// Author : Mc_LaReN      #include <bits/stdc++.h>   #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   using namespace std;   const int MOD = 1e9 + 7, MX = 400005;      #define DEBUG       cerr<< /n>>>I m Here<<</n <<endl;   #define what_is(x) cerr << #x <<   is   << x << endl;   #define pf push_front   #define pb push_back   #define endl   n    #define ll int64_t   #define sz(x) (int)x.size()   #define max(x, y) (y-x >> 31 & (x^y) ^ y)   #define min(x, y) (y-x >> 31 & (x^y) ^ x)      template <class X> void swp( X &a, X &b) { X tp = a; a = b; b = tp; }   template <class X> void print(vector<X> &a) {for(auto& it : a) cout<<it<<   ; cout<<endl;}      ll gcd(ll x,ll y){       return (y==0 ? x : gcd(y, x % y) );   }   ll LCM(ll x,ll y){       return (x/gcd(x,y))*y;   }      char ch,ch1,ch2,ch3;   string s,s1,s2,s3;   vector<long long> v,v1,v2,v3;   vector<int> vi;   vector<string> vstr,vstr2,vstr3;      void run();      int32_t main()   {       IOS;              #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( error.txt ,  w , stderr);       freopen( output.txt ,  w , stdout);       #endif          int t;       cin >> t;       while(t--)       {           run();           cout <<   n ;       }                    #ifndef ONLINE_JUDGE       cerr<< time taken :  <<(float)clock()/CLOCKS_PER_SEC<<  secs <<endl;       #endif             return 0;   }         void run()   {       ll n;       cin>>n;       ll a=1, ans = 0;       for(ll i = 1; i <= n; ++i){       //     ans+=n/a;       //     // a=LCM(a,i);           a=LCM(a,i);           if(a>n)break;           ans+=n/a;       }       cout<< (ans+n) % MOD;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200];   int main() {     long long int n, ans = 0, m, i, j, x, y;     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= m; i++) {       cin >> x >> y;       long long int ret = 0;       for (j = x; j <= y; j++) {         ret += a[j];       }       if (ret > 0) ans += ret;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       long long ar[6];       cin >> a >> b >> c;       ar[0] = a;       ar[1] = b;       ar[2] = c;       sort(ar, ar + 3);       cout << ar[2] + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool mark[72][72][72];   int a[10];   pair<int, pair<int, int> > Par[72][72][72];   pair<int, int> par[72][72][72];   queue<pair<int, pair<int, int> > > q;   vector<pair<int, int> > v;   char c[100][100];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     cin >> a[3] >> a[1] >> a[2];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> c[i][j];     sort(a + 1, a + 3 + 1);     if (a[1] == 1 && a[2] == 2 && a[3] == 3) {       cout << 0;       return 0;     }     bool ans = false;     mark[a[1]][a[2]][a[3]] = true;     q.push(make_pair(a[1], make_pair(a[2], a[3])));     while (q.size()) {       int A = q.front().first;       int B = q.front().second.first;       int C = q.front().second.second;       if (A == 1 && B == 2 && C == 3) {         ans = true;         while (par[A][B][C].first != 0) {           v.push_back(par[A][B][C]);           int AA = A, BB = B, CC = C;           A = Par[AA][BB][CC].first;           B = Par[AA][BB][CC].second.first;           C = Par[AA][BB][CC].second.second;         }       }       for (int i = 1; i <= n; i++) {         if (i != A && i != B && i != C) {           if (c[A][i] == c[B][C]) {             a[1] = i;             a[2] = B;             a[3] = C;             sort(a + 1, a + 3 + 1);             if (!mark[a[1]][a[2]][a[3]]) {               par[a[1]][a[2]][a[3]] = make_pair(A, i);               Par[a[1]][a[2]][a[3]] = make_pair(A, make_pair(B, C));               mark[a[1]][a[2]][a[3]] = true;               q.push(make_pair(a[1], make_pair(a[2], a[3])));             }           }         }       }       for (int i = 1; i <= n; i++) {         if (i != A && i != B && i != C) {           if (c[B][i] == c[A][C]) {             a[1] = A;             a[2] = i;             a[3] = C;             sort(a + 1, a + 3 + 1);             if (!mark[a[1]][a[2]][a[3]]) {               par[a[1]][a[2]][a[3]] = make_pair(B, i);               Par[a[1]][a[2]][a[3]] = make_pair(A, make_pair(B, C));               mark[a[1]][a[2]][a[3]] = true;               q.push(make_pair(a[1], make_pair(a[2], a[3])));             }           }         }       }       for (int i = 1; i <= n; i++) {         if (i != A && i != B && i != C) {           if (c[C][i] == c[B][A]) {             a[1] = A;             a[2] = B;             a[3] = i;             sort(a + 1, a + 3 + 1);             if (!mark[a[1]][a[2]][a[3]]) {               par[a[1]][a[2]][a[3]] = make_pair(C, i);               Par[a[1]][a[2]][a[3]] = make_pair(A, make_pair(B, C));               mark[a[1]][a[2]][a[3]] = true;               q.push(make_pair(a[1], make_pair(a[2], a[3])));             }           }         }       }       q.pop();     }     if (!ans) {       cout << -1;       return 0;     }     cout << v.size() << endl;     for (int i = v.size() - 1; i >= 0; i--)       cout << v[i].first <<     << v[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   bool prime(int num) {     for (int i = 2; i <= sqrt(num); i++) {       if (num % i == 0) return 0;     }     return 1;   }   int main() {     cin >> n;     if (prime(n)) {       return cout << 1 << endl << n, 0;     }     p = (n - 3) / 2;     cout << 3 <<   n  << 3 <<    ;     for (int i = 0; i < p; i++) {       if (prime(p - i) && prime(p + i)) {         cout << p - i <<     << p + i;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void my_functions() { return; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     string s;     cin >> s;     long long int b[n], i;     b[0] = a[0];     for (i = 1; i < n; i++) {       b[i] = a[i] + b[i - 1];     }     long long int m1 = 0, m2 = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         m1 = a[i] + m1;         if (i > 0) {           m2 = b[i - 1];         }         m1 = max(m1, m2);       }     }     long long int ans = max(m1, m2);     cout << ans;     return 0;   }