#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long int n;   long long int v[N];   vector<long long int> a, b;   long long int solve(const vector<long long int> &vet) {     long long int max_so_far = INT_MIN, max_ending_here = 0;     for (int i = 0; i < vet.size(); i++) {       max_ending_here = max_ending_here + vet[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; ++i) {       scanf( %lld , &v[i]);     }     for (int i = 1; i < n; ++i) {       a.push_back(abs(v[i] - v[i - 1]) * ((i & 1) ? 1 : -1));       b.push_back(abs(v[i] - v[i - 1]) * ((i & 1) ? -1 : 1));     }     printf( %lld n , max(solve(a), solve(b)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   int main() {     cout.precision(12);     iostream::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     const int MX = 1e6 + 1;     vector<int> pr(MX, 1);     vector<int> o;     for (int i = 2; i < MX; i++) {       if (!pr[i]) continue;       o.push_back(i);       for (long long j = i * 1ll * i; j < MX; j += i) pr[j] = 0;     }     long long n, x, y;     cin >> n >> x >> y;     unordered_map<long long, long long> q;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       long long c = a[i];       for (int j : o) {         if (j * 1ll * j > a[i]) break;         if (a[i] % j) continue;         while (a[i] % j == 0) a[i] /= j;         q[j]++;       }       if (a[i] != 1) q[a[i]]++;       a[i] = c;     }     long long mx = 0;     for (auto i : q) mx = max(mx, i.second);     if (x <= y) {       cout << (n - mx) * x <<   n ;       return 0;     }     long long ans = (n - q[2]) * y;     for (auto i : q) {       if (i.second <= q[2]) continue;       long long res = 0;       bool ch = 1;       for (long long e : a) {         long long d = (i.first - (e % i.first)) % i.first;         res += min(x, y * d);         if (res > ans) {           ch = 0;           break;         }       }       if (ch) ans = min(ans, res);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     int q = m * a;     if (q < b) {       cout << n * a;     } else {       int v = n / m;       n -= v * m;       cout << v * b + min(b, n * a);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     int l = n, r = n;     bool found = false;     for (int i = 0; i < n; i++) {       if (found == false && s[i] >  a ) {         found = true;         l = i;       }       if (found == true && s[i] ==  a ) {         r = i;         break;       }     }     for (int i = l; i < r; i++) {       s[i] = (char)((int)s[i] - 1);     }     if (l != n)       cout << s;     else {       s[n - 1] =  z ;       cout << s;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i, pos = -1, flag;     string s1, s2;     cin >> n >> m;     cin >> s1;     cin >> s2;     for (i = 0; i < n; i++) {       if (s1[i] ==  * ) {         pos = i;         break;       }     }     if (pos == -1) {       if (s1 == s2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     } else {       if (m < (n - 1))         cout <<  NO  << endl;       else {         flag = 0;         for (i = 0; i < n; i++) {           if (i < pos) {             if (s1[i] != s2[i]) {               cout <<  NO  << endl;               flag = 1;               break;             }           } else if (i > pos) {             if (s1[i] != s2[m - n + i]) {               cout <<  NO  << endl;               flag = 1;               break;             }           }         }         if (flag == 0) cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[100005];   int maxans, maxnum;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int l = 0, r = 0;     int curk = k, curans = 0, curnum = 0;     while (r < n) {       while (r < n && curk >= (long long)curans * (a[r] - curnum)) {         curk -= curans * (a[r] - curnum);         curans++;         curnum = a[r++];       }       if (curans > maxans) {         maxans = curans;         maxnum = curnum;       }       if (l < r) {         curk += curnum - a[l++];         curans--;       }       if (curans > maxans) {         maxans = curans;         maxnum = curnum;       }     }     printf( %d %d n , maxans, maxnum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     long long a[100001];     long long b[100001];     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long x = 0, i = 1, count = 0;     while (m > 0) {       if (a[x] != i) {         if (m - i >= 0) {           m -= i;           b[count] = i;           count++;         } else           break;       } else         x++;       i++;     }     cout << count << endl;     for (int i = 0; i < count; i++) cout << b[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, m, l, r, a[N], b[N], dp[N];   void prework() {     int k = 1;     for (int i = 2; i <= n; ++i)       if (a[i + 1] - a[i] > a[k + 1] - a[k]) k = i;     r = a[k + 1] - a[k] - 1;     for (int i = 1; i <= n; ++i) b[i] = a[i + k];     int t = b[1];     for (int i = 1; i <= n; ++i) b[i] -= t;   }   int check(long long x) {     dp[1] = 0;     for (int i = 2; i <= n; ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= b[i] - 1) dp[i] = max(dp[i], b[i] + x);       if (dp[i - 1] >= b[i] - x - 1) dp[i] = max(dp[i], b[i]);       if (i > 2 && dp[i - 2] >= b[i] - x - 1) dp[i] = max(dp[i], b[i - 1] + x);     }     if (dp[n] >= m - x - 1) return 1;     dp[2] = max(b[2], x);     for (int i = 3; i <= n; ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= b[i] - 1) dp[i] = max(dp[i], b[i] + x);       if (dp[i - 1] >= b[i] - x - 1) dp[i] = max(dp[i], b[i]);       if (dp[i - 2] >= b[i] - x - 1) dp[i] = max(dp[i], b[i - 1] + x);     }     return dp[n] >= min(m - 1, m + b[2] - x - 1);   }   int main() {     ios::sync_with_stdio(false);     cin >> m >> n;     for (int i = 1; i <= n; ++i) cin >> a[i], a[i + n] = a[i] + m;     if (n == 1) return cout << m - 1 << endl, 0;     sort(a + 1, a + n * 2 - 1);     prework();     while (l < r) {       long long mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int l = 8 * n + 1;     double m = sqrt(l);     int k = sqrt(l);     if (m == k)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool mark[100];   int main() {     int n, A[100][100];     cin >> n;     int k = n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> A[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (A[i][j] == 1 or A[i][j] == 3) {           mark[i] = true;           k--;           j = n;         }       }     cout << k << endl;     for (int i = 0; i < n; i++)       if (!mark[i]) cout << i + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   string s[105];   int n, last_hh, last_mm, last_tme, cur_tme, cur_mm, cur_hh, ans = 1, cnt = 0;   int calch(int i) { return (s[i][1] -  0 ) * 10 + s[i][2] -  0 ; }   int calcm(int i) { return (s[i][4] -  0 ) * 10 + s[i][5] -  0 ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n + 1; i++) getline(cin, s[i]);     for (int i = 2; i <= n + 1; i++) {       last_hh = calch(i - 1);       if (last_hh == 12) last_hh = 0;       last_mm = calcm(i - 1);       cur_hh = calch(i);       if (cur_hh == 12) cur_hh = 0;       cur_mm = calcm(i);       last_tme = last_hh * 60 + last_mm;       cur_tme = cur_hh * 60 + cur_mm;       if (s[i - 1][7] ==  p ) last_tme += 12 * 60;       if (s[i][7] ==  p ) cur_tme += 12 * 60;       if (last_tme > cur_tme)         ans++, cnt = 0;       else if (last_tme == cur_tme) {         cnt++;         if (cnt == 10) ans++, cnt = 0;       } else         cnt = 0;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   long long int ans, n, a[N];   string s;   int main() {     cin >> n >> s;     if (n == 1) {       cout <<  Yes ;       return 0;     }     for (int i = 0; i < n; i++) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       if (a[i] == 1) {         ans++;       }     }     if (ans == n) {       cout <<  No ;       return 0;     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, str, ans;   int n, m;   int G[205 * 2][205 * 2];   bool check(int x, int y) {     bool f1 = (a[ans[x] -  a ] ==  C ), f2 = (a[ans[y] -  a ] ==  C );     int ta = 2 * x + 2, tb = 2 * y + 2;     return !G[ta - f1][tb - (!f2)] && !G[tb - f2][ta - (!f1)];   }   bool DFS(int now, bool p) {     if (now == n) {       cout << ans << endl;       return true;     }     int lw = (p == true) ? 0 : str[now] -  a ;     for (int i = lw; i < a.length(); i++) {       ans[now] = i +  a ;       bool f = true;       for (int j = 0; j <= now; j++) {         if (check(j, now) == false) {           f = false;           break;         }       }       if (f == false) continue;       if (DFS(now + 1, p || (ans[now] > str[now]))) return true;     }     return false;   }   int main() {     cin >> a >> n >> m;     for (int i = 1, p1, p2; i <= m; i++) {       char t1, t2;       scanf( %d %c %d %c , &p1, &t1, &p2, &t2);       bool f1 = (t1 ==  C ), f2 = (t2 ==  C );       int x = 2 * p1, y = 2 * p2;       G[x - f1][y - f2] = G[y - (!f2)][x - (!f1)] = 1;     }     int c[2] = {0};     for (int i = 0; i < a.length(); i++) c[a[i] ==  C ] = 1;     if (c[1] == 0 || c[0] == 0) {       for (int i = 1; i <= n; i++) G[2 * i - c[0]][2 * i - (!c[0])] = 1;     }     cin >> str;     for (int t = 1; t <= 2 * n; t++) {       for (int i = 1; i <= 2 * n; i++) {         for (int j = 1; j <= 2 * n; j++)           if (G[i][t] && G[t][j]) G[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       int x = 2 * i, y = 2 * i - 1;       if (G[x][y] && G[y][x]) {         puts( -1 );         return 0;       }       ans +=    ;     }     if (DFS(0, 0) == false) puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   vector<int> A;   vector<int> modded;   int main() {     int n;     cin >> n;     A.resize(n);     modded.resize(n);     for (int i = 0; i < n; i++) {       cin >> A[i];     }     int res = 0;     for (int i = 0; i < 27; i++) {       for (int j = 0; j < n; j++) {         modded[j] = A[j] % (1 << (i + 1));       }       sort((modded).begin(), (modded).end());       int l, r, cnt = 0;       for (int j = 0; j < n; j++) {         auto beg = modded.begin() + j + 1;         auto end = modded.end();         l = lower_bound(beg, end, (1 << i) - modded[j]) - modded.begin();         r = lower_bound(beg, end, (1 << (i + 1)) - modded[j]) - modded.begin();         cnt += (r - l);         l = lower_bound(beg, end, (1 << (i + 1)) + (1 << i) - modded[j]) -             modded.begin();         r = upper_bound(beg, end, (1 << (i + 2)) - 2 - modded[j]) -             modded.begin();         cnt += (r - l);       }       if (cnt & 1) {         res |= (1 << i);       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int TRIE[200005 * 32 * 2][2];   int isword[200005 * 32 * 2];   int nxt;   void ins(string &s) {     int v = 0;     for (int i = 0; i < s.size(); i++) {       if (TRIE[v][s[i] -  0 ] == -1) TRIE[v][s[i] -  0 ] = nxt++;       isword[v]++;       v = TRIE[v][s[i] -  0 ];     }     isword[v]++;   }   void del(string &s) {     int v = 0;     int u;     for (int i = 0; i < s.size(); i++) {       if (isword[v] > 0) isword[v]--;       if (isword[v] == 0 && i > 0) TRIE[u][s[i - 1] -  0 ] = -1;       u = v;       v = TRIE[v][s[i] -  0 ];     }     if (isword[v] > 0) isword[v]--;     if (isword[v] == 0) TRIE[u][s[31] -  0 ] = -1;   }   string bin(int a) {     string k =   ;     while (a) {       k += to_string(a % 2);       a /= 2;     }     int u = k.length();     for (int i = 0; i < 32 - u; i++) k +=  0 ;     reverse(k.begin(), k.end());     return k;   }   long long int query(string &s) {     int v = 0;     string k =   ;     for (int i = 0; i < s.size(); i++) {       if (TRIE[v][1 - (s[i] -  0 )] != -1) {         v = TRIE[v][1 - (s[i] -  0 )];         if (s[i] ==  0 )           k +=  1 ;         else           k +=  0 ;       } else {         v = TRIE[v][s[i] -  0 ];         k += s[i];       }     }     long long int val = 0, bit;     for (int i = 0; i <= 31; i++) {       bit = (s[i] == k[i]) ? 0 : 1;       val <<= 1;       val += bit;     }     return val;   }   int main() {     memset(isword, 0, sizeof(isword));     memset(TRIE, -1, sizeof(TRIE));     isword[0] = 1;     nxt = 1;     int q, a;     string s;     cin >> q;     string k = bin(0);     ins(k);     for (int i = 0; i < q; i++) {       cin >> s >> a;       string k = bin(a);       if (s ==  + )         ins(k);       else if (s ==  - )         del(k);       else         cout << query(k) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   int seg[800006][16], x[800006], n, m, t, p, T, ans, pc, L, R, k;   vector<int> v;   inline int gt(int a, int b) {     int k1 = (pow(10, b));     int k2 = (pow(10, b - 1));     if ((k1 % 10) == 9) k1++;     if ((k2 % 10) == 9) k2++;     return ((a % k1) / (k2));   }   inline int Build_Segtree(int h, int l, int r) {     if (l > r) return 0;     if (l > R) return seg[h][k];     if (r < L) return seg[h][k];     if (l == r) {       if (gt(x[l], k))         return seg[h][k] = l;       else         return seg[h][k] = 0;     }     int lf = Build_Segtree(h << 1, l, ((l + r) >> 1));     int rg = Build_Segtree((h << 1) + 1, ((l + r) >> 1) + 1, r);     if (x[lf] > x[rg]) return seg[h][k] = rg;     if (x[lf] <= x[rg]) return seg[h][k] = lf;   }   inline int get(int h, int l, int r) {     if (l > r) return 0;     if (l > R) return 0;     if (r < L) return 0;     if (l >= L && r <= R) return seg[h][k];     int lf = get(h << 1, l, ((l + r) >> 1));     int rg = get((h << 1) + 1, ((l + r) >> 1) + 1, r);     if (x[lf] > x[rg]) return rg;     if (x[lf] <= x[rg]) return lf;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> x[i];     }     x[0] = 1999999999;     for (int j = 1; j <= 9; j++) {       L = 1;       R = n;       k = j;       Build_Segtree(1, 1, n);     }     for (int i = 1; i <= m; i++) {       int q, a, b;       cin >> q >> a >> b;       if (q == 1) {         x[a] = b;         for (int j = 1; j <= 9; j++) {           L = a;           R = a;           k = j;           Build_Segtree(1, 1, n);         }       }       if (q == 2) {         ans = 1999999999;         for (int j = 1; j <= 9; j++) {           L = a;           R = b;           k = j;           t = get(1, 1, n);           p = x[t];           x[t] = 0;           L = t;           R = t;           k = j;           Build_Segtree(1, 1, n);           L = a;           R = b;           k = j;           T = get(1, 1, n);           x[t] = p;           L = t;           R = t;           k = j;           Build_Segtree(1, 1, n);           if (T) ans = min(ans, x[t] + x[T]);         }         if (ans == 1999999999) {           v.push_back(-1);         } else {           v.push_back(ans);         }       }     }     for (int i = 0; i < v.size(); i++) {       printf( %ld  n , v[i]);     }   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long double TL = 1.0;   bool is_tl = 0;   long long CALLS = 0;   inline bool IS() {     if (++CALLS == 1000) {       CALLS = 0;       is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;     }     return is_tl;   }   template <typename T>   inline void amin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   inline void amax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   inline void print(T a) {     for (auto U : a) cout << U <<    ;     cout <<   n ;   }   const long long N = 1e6 + 7, NS = 1e3 + 7, lg = 18, sq = 550, inf = 1e9 + 7,                   mod = 1e9 + 7, SM = 1e2 + 7;   const long double eps = 1e-9;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   struct edge {     long long to;     long long f;     long long c;     long long get() { return c - f; }   };   vector<edge> e;   vector<long long> v[N];   vector<pair<pair<long long, long long>, long long> > edges;   long long n, m, used[N];   void add_edge(long long a, long long b, long long c) {     v[a].push_back(e.size());     edge ed;     ed.to = b;     ed.f = 0;     ed.c = c;     e.push_back(ed);     v[b].push_back(e.size());     ed.to = a;     ed.c = 0;     e.push_back(ed);   }   long long dfs(long long x, long long f) {     if (x == n - 1) return f;     used[x] = 1;     for (auto u : v[x]) {       if (used[e[u].to] || e[u].get() <= 0) continue;       long long y = dfs(e[u].to, min(f, e[u].get()));       if (y) {         e[u].f += y;         e[u ^ 1].f -= y;         return y;       }     }     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long need;     cin >> n >> m >> need;     for (long long i = 1; i <= m; i++) {       long long a, b, c;       cin >> a >> b >> c;       a--, b--;       edges.push_back({{a, b}, c});     }     long double l = 0, r = inf, mid;     for (long long it = 0; it < 200; it++) {       mid = (l + r) / 2;       e.clear();       for (long long i = 0; i < n; i++) v[i].clear();       for (auto u : edges) {         long long a = u.first.first, b = u.first.second,                   c = (long long)((u.second + 0.) / mid);         add_edge(a, b, c);       }       long long ans = 0;       while (1) {         for (long long i = 0; i < n; i++) used[i] = 0;         long long y = dfs(0, inf);         if (!y) break;         ans += y;       }       if (ans >= need)         l = mid;       else         r = mid;     }     cout << fixed << setprecision(10);     cout << mid * (0. + need);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long int n, i, j, k, l, sum = 0, g = 0, sum1 = 0, q, one, zero, k1;       cin >> n >> k1;       string s;       cin >> s;       for (i = 0; i < k1; i++) {         k = i;         q = 0;         zero = 0, one = 0;         while (k <= n - 1) {           if (s[k] ==  ? )             q++;           else if (s[k] ==  1 )             one++;           else             zero++;           k += k1;         }         if (one != 0 && zero != 0) {           g = 1;           break;         } else if (zero != 0) {           k = i;           while (k <= n - 1) {             s[k] =  0 ;             k += k1;           }         } else if (one != 0) {           k = i;           while (k <= n - 1) {             s[k] =  1 ;             k += k1;           }         }       }       for (i = 0; i < k1; i++) {         if (s[i] ==  1 )           sum++;         else if (s[i] ==  ? )           sum1++;       }       if (sum > k1 / 2)         g = 1;       else if (sum < (k1 / 2) && sum1 < ((k1 / 2) - sum))         g = 1;       if (g == 1)         cout <<  NO               <<   n ;       else         cout <<  YES               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int x, y, z;     long long int x1, y1, z1;     cin >> x >> y >> z >> x1 >> y1 >> z1;     long long int a[6];     for (long long int i = 0; i < 6; i++) cin >> a[i];     long long int sum = 0;     if (y < 0) sum += a[0];     if (y > y1) sum += a[1];     if (x < 0) sum += a[4];     if (x > x1) sum += a[5];     if (z < 0) sum += a[2];     if (z > z1) sum += a[3];     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char str[100010];   int main() {     int ans[] = {4, 0, 0, 0};     while (~scanf( %s , str)) {       int tmp = 0;       int len = strlen(str);       for (int i = 0; i < len; ++i) {         tmp = tmp * 10 + str[i] -  0 ;         tmp %= 4;       }       printf( %d n , ans[tmp]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   int main() {     int n, h;     cin >> n >> h;     for (int i = 0; i < (int)(n); i++) cin >> a[i];     int head = min_element(a, a + n) - a;     sort(a, a + n);     int ret1 = max(a[0] + a[n - 1] + h, a[n - 1] + a[n - 2]) -                min(a[1] + a[2], a[0] + a[1] + h);     int ret2 = (a[n - 1] + a[n - 2]) - (a[0] + a[1]);     cout << min(ret1, ret2) << endl;     if (ret1 < ret2) {       for (int i = 0; i < (int)(n); i++) {         if (i == head)           cout <<  2  ;         else           cout <<  1  ;       }     } else {       for (int i = 0; i < (int)(n); i++) cout <<  1  ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long INF = 100000000000000000;   const int MAXN = 3 * 100000;   struct T {     int left, right, diff;     bool operator>(const T& other) {       if (diff != other.diff) return diff < other.diff;       return left < other.left;     }     bool operator<(const T& other) const {       if (diff != other.diff) return diff > other.diff;       return left > other.left;     }   };   priority_queue<T> q;   vector<pair<int, int> > ans;   char s[MAXN];   bool u[MAXN];   int a[MAXN];   int l[MAXN];   int r[MAXN];   int n;   int main() {     cin >> n;     scanf( %s , s);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       l[i] = i - 1;       r[i] = i + 1;       if (i + 1 == n) r[i] = -1;     }     for (int i = 0; i < n - 1; ++i)       if (s[i] != s[i + 1]) {         T t;         t.left = i;         t.right = i + 1;         t.diff = abs(a[i] - a[i + 1]);         q.push(t);       }     while (!q.empty()) {       int left = q.top().left;       int right = q.top().right;       q.pop();       if (u[left] || u[right]) continue;       u[left] = u[right] = true;       ans.push_back(pair<int, int>(left + 1, right + 1));       left = l[left];       right = r[right];       if (left != -1) r[left] = right;       if (right != -1) l[right] = left;       if (left != -1 && right != -1 && s[left] != s[right]) {         T t;         t.left = left;         t.right = right;         t.diff = abs(a[left] - a[right]);         q.push(t);       }     }     cout << ans.size() << endl;     for (int i = 0; i < (long long)(ans).size(); ++i) {       printf( %d %d n , ans[i].first, ans[i].second);     }   }


#include <bits/stdc++.h>   using namespace std;   void RD(int &x) { scanf( %d , &x); }   void RD(long long &x) { scanf( %I64d , &x); }   void RD(unsigned int &x) { scanf( %u , &x); }   void RD(double &x) { scanf( %lf , &x); }   void RD(int &x, int &y) { scanf( %d%d , &x, &y); }   void RD(long long &x, long long &y) { scanf( %I64d%I64d , &x, &y); }   void RD(unsigned int &x, unsigned int &y) { scanf( %u%u , &x, &y); }   void RD(double &x, double &y) { scanf( %lf%lf , &x, &y); }   void RD(int &x, int &y, int &z) { scanf( %d%d%d , &x, &y, &z); }   void RD(long long &x, long long &y, long long &z) {     scanf( %I64d%I64d%I64d , &x, &y, &z);   }   void RD(unsigned int &x, unsigned int &y, unsigned int &z) {     scanf( %u%u%u , &x, &y, &z);   }   void RD(double &x, double &y, double &z) { scanf( %lf%lf%lf , &x, &y, &z); }   void RD(char &x) { x = getchar(); }   void RD(char *s) { scanf( %s , s); }   void RD(string &s) { cin >> s; }   void PR(int x) { printf( %d n , x); }   void PR(int x, int y) { printf( %d %d n , x, y); }   void PR(long long x) { printf( %I64d n , x); }   void PR(unsigned int x) { printf( %u n , x); }   void PR(unsigned long long x) { printf( %I64u n , x); }   void PR(double x) { printf( %.6lf n , x); }   void PR(char x) { printf( %c n , x); }   void PR(char *x) { printf( %s n , x); }   void PR(string x) { cout << x << endl; }   const int mod = 1000000007;   const long long inf = ((long long)1) << 60;   const int INF = 100000000;   const int N = 1000005;   vector<pair<int, int> > V;   long long Pow[N];   int n, m, K;   void init() {     Pow[0] = 1;     int i;     for (i = 1; i <= N - 1; i++) Pow[i] = Pow[i - 1] * 2 % mod;   }   int main() {     init();     while (scanf( %d , &n) != -1) {       RD(m, K);       V.clear();       int i, x, y, cnt, flag = 1;       for (i = 1; i <= m; i++) {         RD(x, y);         if (y - x != 1 && y - x != K + 1) flag = 0;         if (y - x == K + 1) V.push_back(make_pair(x, y));       }       if (!flag) {         puts( 0 );         continue;       }       sort(V.begin(), V.end());       if (!K || K >= n - 1) {         puts( 1 );         continue;       }       for (i = 0; i < V.size(); i++)         if (!(V[i].first >= V[0].first && V[i].first < V[0].second)) {           break;         }       if (i < V.size()) {         puts( 0 );         continue;       }       long long ans = 0;       if (!V.size()) ans++;       int t = V.size();       for (i = 1; i <= n; i++) {         x = i;         y = i + K + 1;         cnt = t;         if (y > n || t && x > V[0].first) break;         if (t && !(x <= V[0].first && V[t - 1].first < y)) continue;         if (t && x == V[0].first) cnt--;         y = ((y) < (n - K) ? (y) : (n - K));         ans += Pow[y - x - 1 - cnt];         ans %= mod;       }       PR(ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1001];   int main(void) {     int k, l, r, i, j;     cin >> s >> k;     l = strlen(s);     r = l / k;     if (l % k != 0) {       cout <<  NO  << endl;       return 0;     }     for (i = 0; i < l; i += r)       for (j = 0; j < r / 2; j++) {         if (s[i + j] != s[i + r - j - 1]) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   int main() {     int n, k, m;     scanf( %d%d%d , &n, &k, &m);     int interior = 0;     vector<pair<int, int>> t;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       if (t.empty() || t.back().first != x)         t.push_back({x, 1});       else {         t.back().second++;         if (t.back().second == k) {           t.pop_back();           ++interior;         }       }     }     vector<pair<int, int>> memo = t;     int border = 0;     int start = 0;     while ((int)t.size() - start >= 2 && t[start].first == t.back().first &&            t[start].second + t.back().second >= k) {       int tmp = t[start].second + t.back().second;       border += tmp / k;       tmp -= tmp / k * k;       if (tmp == 0) {         ++start;         t.pop_back();       } else {         t.pop_back();         t[start].second = tmp;       }     }     debug() <<   [              <<  interior                  :               << (interior)             <<  ]                    [              <<  border                  :               << (border) <<  ]  ;     long long answer =         (long long)interior * m * k + (long long)border * (m - 1) * k;     if ((int)t.size() == start + 1) {       long long a = (long long)m * t[start].second;       answer += a / k * k;       a -= a / k * k;       if (a == 0) {         debug() <<  spec case ;         vector<pair<int, int>> nowy;         for (int i = 0; i < start; ++i) nowy.push_back(memo[i]);         for (int i = (int)t.size(); i < (int)memo.size(); ++i)           nowy.push_back(memo[i]);         debug() <<   [                  <<  nowy                      :                   << (nowy) <<  ]  ;         vector<pair<int, int>> dwa;         for (pair<int, int> p : nowy) {           if (dwa.empty() || dwa.back().first != p.first)             dwa.push_back(p);           else {             dwa.back().second += p.second;             answer += dwa.back().second / k * k;             dwa.back().second %= k;             if (dwa.back().second == 0) dwa.pop_back();           }         }       }     }     printf( %lld n , (long long)n * m - answer);   }


#include <bits/stdc++.h>   using namespace std;   long long int invmod(long long int x, long long int n, long long int mod) {     if (n == 0) return 1 % mod;     long long int half = invmod(x, n / 2, mod);     half = (half * half) % mod;     if (n % 2 == 1) half = (half * (x % mod)) % mod;     return half;   }   long long int bin(long long int a[], long long int l, long long int r,                     long long int x) {     if (l <= r) {       long long int m = l + (r - l) / 2;       if (a[m] == x)         return m;       else if (a[m] > x)         return bin(a, l, m - 1, x);       else         return bin(a, m + 1, r, x);     } else       return -1;   }   long long int power(long long int b, long long int e, long long int m) {     if (e == 0) return 1;     if (e % 2)       return b * power(b * b % m, (e - 1) / 2, m) % m;     else       return power(b * b % m, e / 2, m);   }   long long int power(long long int b, long long int e) {     if (e == 0) return 1;     if (e % 2)       return b * power(b * b, (e - 1) / 2);     else       return power(b * b, e / 2);   }   long long int ncr(long long int n, long long int r, long long int x) {     if (r == 0) return 1;     long long int fac[n + 1];     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % x;     return (fac[n] * power(fac[r], x - 2, x) % x * power(fac[n - r], x - 2, x) %             x) %            x;   }   long long int ncr(long long int n, long long int p) {     long long int r = min(p, n - p), rf = 1, ln = 1;     for (long long int i = 1; i <= r; i++) rf = rf * i;     for (long long int i = 0; i < r; i++) ln = ln * (n - i);     return ln / rf;   }   bool sbs(pair<long long int, long long int> &a,            pair<long long int, long long int> &b) {     return (a.second < b.second);   }   bool sbds(pair<long long int, long long int> &a,             pair<long long int, long long int> &b) {     return (a.second > b.second);   }   long long int SUM(long long int a[], long long int n) {     long long int sum = 0;     for (long long int i = 0; i < n; i++) sum += a[i];     return sum;   }   long long int chkprm(long long int n) {     for (long long int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   long long int dp[2005][2005];   long long int solve(long long int a[], long long int l1, long long int r1,                       long long int h, long long int l, long long int r,                       long long int t) {     if (l1 == r1) {       if (((t + a[l1]) % h) >= l && ((t + a[l1]) % h) <= r) return 1;       if (((t + a[l1] - 1) % h) >= l && ((t + a[l1] - 1) % h) <= r) return 1;       return 0;     }     if (dp[l1][t] != -1) return dp[l1][t];     long long int x1 = 0, x2 = 0;     if (((t + a[l1]) % h) >= l && ((t + a[l1]) % h) <= r) x1++;     if (((t + a[l1] - 1) % h) >= l && ((t + a[l1] - 1) % h) <= r) x2++;     dp[l1][t] = max(x1 + solve(a, l1 + 1, r1, h, l, r, (t + a[l1]) % h),                     x2 + solve(a, l1 + 1, r1, h, l, r, (t + a[l1] - 1) % h));     return dp[l1][t];   }   void myth() {     long long int n, h, l, r;     cin >> n >> h >> l >> r;     long long int a[n];     for (long long int xxx = 0; xxx < n; xxx++) cin >> a[xxx];     memset(dp, -1, sizeof(dp));     cout << solve(a, 0, n - 1, h, l, r, 0);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int test_case = 1;     while (test_case--) {       myth();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   void clock_out() {     cerr <<   nTime Elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;   }   void fileio() {     freopen( /home/dwai/Desktop/cp/input.txt ,  r , stdin);     freopen( /home/dwai/Desktop/cp/output.txt ,  w , stdout);     freopen( /home/dwai/Desktop/cp/debug.txt ,  w , stderr);   }   void ofileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   int IT_MAX = 1 << 20;   const long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   void solve() {     long long n, sx, sy;     cin >> n >> sx >> sy;     vector<pair<long long, long long> > v(n);     long long i;     long long d[n];     for (i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       d[i] = abs(v[i].first - sx) + abs(v[i].second - sy);     }     pair<long long, long long> p;     long long m = 0;     vector<pair<long long, long long> > pos({{0, 1}, {0, -1}, {1, 0}, {-1, 0}});     for (pair<long long, long long> cord : pos) {       long long cx = cord.first + sx, cy = cord.second + sy;       long long cm = 0;       i = 0;       for (pair<long long, long long> x : v) {         long long cd = abs(cx - x.first) + abs(cy - x.second);         if (cd < d[i]) cm++;         i++;       }       if (cm > m) {         m = cm;         p = make_pair(cx, cy);       }     }     cout << m <<   n  << p.first <<     << p.second;   }   int main() {     42;     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, fp = 0;     cin >> n;     vector<int> p(n);     bool nice = false;     bool entrou = false;     for (int i = 0; i < n; i++) {       cin >> p[i];       if (i == p[i]) fp = fp + 1;     }     for (int i = 0; i < n; i++) {       if (p[i] != i) {         entrou = true;         if (p[p[i]] == i) {           fp = fp + 2;           nice = true;           break;         }       }     }     if (!nice && entrou) {       fp = fp + 1;     }     cout << fp << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct disjoint_set {     vector<int> p;     disjoint_set(int n) : p(n, -1) {}     bool share(int a, int b) { return root(a) == root(b); }     int sz(int u) { return -p[root(u)]; }     int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); }     bool merge(int u, int v) {       u = root(u), v = root(v);       if (u == v) return false;       if (p[u] > p[v]) swap(u, v);       p[u] += p[v], p[v] = u;       return true;     }   };   template <class T>   struct graph {     struct edge {       int from, to;       T cost;     };     int n;     vector<edge> edges;     vector<vector<int>> adj;     function<bool(int)> ignore;     graph(int n) : n(n), adj(n), ignore(nullptr) {}     int link(int u, int v, T w = 1) {       int id = (int)edges.size();       adj[u].push_back(id), adj[v].push_back(id), edges.push_back({u, v, w});       return id;     }     int orient(int u, int v, T w = 1) {       int id = (int)edges.size();       adj[u].push_back(id), edges.push_back({u, v, w});       return id;     }     graph reversed() const {       graph res(n);       for (auto &e : edges) {         res.orient(e.to, e.from, e.cost);       }       return res;     }   };   template <class T, class U>   T &ctmax(T &x, const U &y) {     return x = max<T>(x, y);   }   template <class T, class U>   T &ctmin(T &x, const U &y) {     return x = min<T>(x, y);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(ios::badbit | ios::failbit);     int n, m;     cin >> n >> m;     disjoint_set dsu(n << 1);     graph<int> g(n);     for (auto i = 0; i < m; ++i) {       int u, v;       cin >> u >> v, --u, --v;       dsu.merge(u, v + n), dsu.merge(v, u + n);       if (dsu.share(u, u + n)) {         cout <<  -1 n ;         return 0;       }       g.link(u, v);     }     int res = 0;     vector<int> dist(n, -1), vis(n);     for (auto s = 0; s < n; ++s) {       if (!vis[s]) {         vector<int> cur;         function<void(int)> dfs = [&](int u) {           vis[u] = true;           cur.push_back(u);           for (auto id : g.adj[u]) {             auto &e = g.edges[id];             int v = u ^ e.from ^ e.to;             if (!vis[v]) {               dfs(v);             }           }         };         dfs(s);         auto get_max_dist = [&](int s) {           for (auto u : cur) {             dist[u] = -1;           }           deque<int> dq{s};           dist[s] = 0;           int res = 0;           while (!dq.empty()) {             int u = dq.front();             dq.pop_front();             for (auto id : g.adj[u]) {               auto &e = g.edges[id];               int v = u ^ e.from ^ e.to;               if (!~dist[v]) {                 dq.push_back(v);                 res = dist[v] = dist[u] + 1;               }             }           }           return res;         };         int cur_max = 0;         for (auto s : cur) {           ctmax(cur_max, get_max_dist(s));         }         res += cur_max;       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101000;   int n, m, k[N], g[50][50], cnt[50], tmp[50];   vector<pair<int, int> > v[N];   inline int gcd(int first, int second) {     return (!second) ? first : gcd(second, first % second);   }   inline void init() {     int i, j;     for (i = 1; i <= 40; ++i)       for (j = 1; j <= 40; ++j) g[i][j] = gcd(i, j);   }   inline bool insert(pair<int, int> p) {     int i;     for (i = 1; i <= 40; ++i)       if (cnt[i] && (p.second - tmp[i]) % g[k[p.first]][i]) return 0;     return tmp[k[p.first]] = p.second, ++cnt[k[p.first]], 1;   }   inline void erase(pair<int, int> p) {     --cnt[k[p.first]];     if (!cnt[k[p.first]]) tmp[k[p.first]] = 0;   }   inline void solve(int first) {     int i = 0, j = 0, ans = 0, t = 0;     memset(cnt, 0, sizeof(cnt));     while (j < v[first].size()) {       while (j < v[first].size() &&              j - i == v[first][j].first - v[first][i].first &&              insert(v[first][j]))         ++j;       ans = max(ans, j - i);       erase(v[first][i]), ++i;     }     cout << ans << endl;   }   int main() {     ios ::sync_with_stdio(false);     int i, j, first;     init();     cin >> n >> m;     for (i = 1; i <= n; ++i) {       cin >> k[i];       for (j = 1; j <= k[i]; ++j)         cin >> first, v[first].push_back(make_pair(i, j));     }     for (i = 1; i <= m; ++i) solve(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void moveLeft() { cout <<  LEFT  << endl; }   void moveRight() { cout <<  RIGHT  << endl; }   void print(char ch) { cout <<  PRINT   << ch << endl; }   int main() {     int numberOfCells, currentCell;     cin >> numberOfCells >> currentCell;     string slogan;     cin >> slogan;     if (currentCell <= numberOfCells - currentCell) {       while (currentCell != 1) {         moveLeft();         currentCell--;       }       while (currentCell <= numberOfCells) {         print(slogan[currentCell - 1]);         if (currentCell == numberOfCells) {           break;         }         moveRight();         currentCell++;       }     } else {       while (currentCell != numberOfCells) {         moveRight();         currentCell++;       }       while (currentCell >= 1) {         print(slogan[currentCell - 1]);         if (currentCell == 1) {           break;         }         moveLeft();         currentCell--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = int(2e5);   const long double pi = 3.1415926535897932384626433832795;   char s[MaxN];   int main() {     while (gets(s)) {       int len = strlen(s);       int l = 0;       while (s[l] == 32) ++l;       int r = len - 1;       while (s[r] == 32) --r;       if (l > r) {         puts(  );         continue;       }       bool space = false;       bool znak = false;       for (int i = l; i <= r; i++) {         if (isalpha(s[i])) {           if (space && !znak)             printf(  %c , s[i]);           else             printf( %c , s[i]);           znak = false;           space = false;         }         if (s[i] ==  .  || s[i] ==  ,  || s[i] ==  !  || s[i] ==  ? )           printf( %c  , s[i]), znak = true;         if (s[i] == 32) space = true;       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k, n, m;       cin >> n;       map<long long int, long long int> mp, diff;       for (i = 0; i < n; i++) {         cin >> k;         if (mp.find(k) == mp.end())           mp[k] = i, diff[k] = 0;         else if (diff[k] == 0 || i - mp[k] == diff[k]) {           if (diff[k] == 0) diff[k] = i - mp[k];           mp[k] = i;         } else           diff[k] = -1;       }       set<pair<long long int, long long int> > ans;       for (auto i : diff)         if (i.second != -1) ans.insert(make_pair(i.first, i.second));       cout << ans.size() <<   n ;       for (auto i : ans) cout << i.first <<     << i.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 401;   const int MOD = 1000000007;   struct matr {     long long a[8][8];   };   matr d, f, e;   int n;   void make() {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) f.a[i][j] = d.a[i][j] = e.a[i][j] = 0;     d.a[0][1] = 1;     d.a[0][4] = 1;     d.a[1][0] = 1;     d.a[2][3] = 1;     d.a[2][6] = 1;     d.a[3][2] = 1;     d.a[4][5] = 1;     d.a[4][7] = 1;     d.a[5][1] = 1;     d.a[5][4] = 1;     d.a[6][5] = 1;     d.a[6][7] = 1;     d.a[7][3] = 1;     d.a[7][6] = 1;     for (int i = 0; i < 8; i++) f.a[0][i] = e.a[i][i] = 1;   }   void print(matr a) {     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) cout << a.a[i][j] <<    ;       cout << endl;     }   }   matr mul(matr a, matr b) {     matr c;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         c.a[i][j] = 0;         for (int z = 0; z < 8; z++) {           c.a[i][j] += a.a[i][z] * b.a[z][j];           if (c.a[i][j] >= MOD) c.a[i][j] %= MOD;         }       }     return c;   }   matr sum(matr a, matr b) {     matr c;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) c.a[i][j] = (a.a[i][j] + b.a[i][j]) % MOD;     return c;   }   matr sqr(matr a) { return mul(a, a); }   matr pow_(matr p, int n) {     if (n <= 1) return p;     if (n % 2 == 0) return sqr(pow_(p, n / 2));     return mul(p, sqr(pow_(p, n / 2)));   }   long long sum(matr a) {     long long ans = 0;     for (int i = 0; i < 8; i++) ans += a.a[0][i];     return ans;   }   long long solve_palin(int n) {     if (n == 1) return 4;     if (n == 2) return 4;     return sum(mul(f, pow_(d, n - 2)));   }   long long solve_one(int n) {     if (n == 1) return 4;     if (n == 2) return 4;     if (n % 2 == 0) return solve_palin(n) / 2;     return solve_palin(n) / 2 + solve_palin((n + 1) / 2);   }   matr clear(matr a) {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) a.a[i][j] = 0;     return a;   }   int log_(int n) {     int l = 0;     while ((1 << l) <= n) l++;     return l - 1;   }   int log_less(int n) {     int l = 0;     while ((1 << l) - 1 < n) l++;     return l - 1;   }   int step_2(int n) { return (1 << n); }   matr magic_func(int n) {     if (n == 0) return e;     if (n == 1) return sum(d, e);     matr ans;     ans = clear(ans);     int w = log_less(n);     ans = sum(d, e);     for (int i = 1; i < w; i++) ans = mul(ans, sum(pow_(d, step_2(i)), e));     return sum(ans, mul(pow_(d, step_2(w)), magic_func(n - step_2(w))));   }   long long solve(int n) {     if (n == 1) return 4;     matr ans;     ans = clear(ans);     n -= 2;     ans = magic_func(n);     return sum(mul(f, ans)) + 4;   }   long long real_ans(int n) { return solve(n) / 2 + solve((n + 1) / 2) / 2; }   int l, r;   int main() {     cin >> l >> r;     make();     if (r == 1) {       cout << 4;       return 0;     }     if (l == r) {       cout << solve_one(l) % MOD;       return 0;     }     long long razn = 0;     if (l == 1) {       razn = 4;       l++;     }     cout << ((real_ans(r) - real_ans(l - 1) + razn) % MOD + MOD) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > v;   int x;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int arr[500001];   int tree[500001 * 5];   void init(int node, int b, int e) {     if (b == e) {       tree[node] = arr[b];       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     init(Left, b, mid);     init(Right, mid + 1, e);     tree[node] = gcd(tree[Left], tree[Right]);   }   void query(int node, int b, int e, int i, int j) {     if (i > e || j < b) return;     if (b >= i && e <= j) {       if (tree[node] % x != 0) v.push_back(make_pair(node, make_pair(b, e)));       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     query(Left, b, mid, i, j);     query(Right, mid + 1, e, i, j);   }   void update(int node, int b, int e, int i, int newvalue) {     if (i > e || i < b) return;     if (b >= i && e <= i) {       tree[node] = newvalue;       return;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     if (i <= mid)       update(Left, b, mid, i, newvalue);     else       update(Right, mid + 1, e, i, newvalue);     tree[node] = gcd(tree[Left], tree[Right]);   }   int rquery(int node, int b, int e) {     if (b == e) {       if (tree[node] % x == 0) return 0;       return 1;     }     int Left = node * 2;     int Right = Left + 1;     int mid = (b + e) / 2;     if (tree[Left] % x != 0 && tree[Right] % x != 0)       return 2;     else if (tree[Left] % x != 0)       return rquery(Left, b, mid);     else       return rquery(Right, mid + 1, e);   }   int main() {     int n;     scanf( %d , &n);     int i;     for (i = 1; i <= n; i++) scanf( %d , &arr[i]);     int q;     scanf( %d , &q);     int t, l, r;     init(1, 1, n);     int ans;     while (q--) {       v.clear();       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d , &l, &r, &x);         query(1, 1, n, l, r);         if (v.size() < 2) {           if (v.size() == 1) {             ans = rquery(v[0].first, v[0].second.first, v[0].second.second);             if (ans < 2)               cout <<  YES  << endl;             else               cout <<  NO  << endl;           } else             cout <<  YES  << endl;         } else           cout <<  NO  << endl;       } else {         scanf( %d%d , &l, &r);         update(1, 1, n, l, r);       }     }     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     register char c = getchar();     register bool f = 0;     while (!isdigit(c)) f ^= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   template <class T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void print(T x, char c) {     print(x), putchar(c);   }   const int N = 2e5 + 10;   int T, n, m, q, cur, max, lst, a[N], b[N];   long long ans;   std::set<int> set[N];   struct edge {     int l, r, x;     inline bool operator<(const edge &other) const { return l < other.l; }   } e[N];   signed main() {     read(n), read(q);     for (int i = 1; i <= n; i++) read(a[i]), b[++m] = a[i];     std::sort(b + 1, b + n + 1), m = std::unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) {       a[i] = std::lower_bound(b + 1, b + m + 1, a[i]) - b;       set[a[i]].insert(i);     }     for (int i = 1; i <= m; i++) {       e[i].l = *set[i].begin();       e[i].r = *--set[i].end();       e[i].x = set[i].size();     }     std::sort(e + 1, e + m + 1);     if (!q) {       lst = 0, cur = 0;       for (int i = 1; i <= m; i++) {         cur = std::max(cur, e[i].r);         if (i == m || e[i + 1].l > cur) {           max = 0;           for (int j = lst + 1; j <= i; j++) {             max = std::max(max, e[j].x);             ans += e[j].x;           }           ans -= max;           lst = i, cur = 0;         }       }       print(ans,   n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     int br = 0;     for (int i = 0; i < s.size() / 2; i++) {       if (s[i] == s[s.size() - i - 1]) continue;       br++;     }     if (br >= 2 || br == 0) {       if (s.size() % 2 == 1 && br == 0) {         cout <<  YES ;         return 0;       }       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[10010];   int B[10010];   bool check(int st, int ed) {     int mx = st;     for (int i = st; i <= ed; i++) {       if (A[i] > A[mx]) {         mx = i;       }       if (A[i] == A[mx]) {         if (st <= i - 1 && A[i - 1] < A[i]) mx = i;         if (i + 1 <= ed && A[i + 1] < A[i]) mx = i;       }     }     bool can = false;     if (st <= mx - 1 && A[mx - 1] < A[mx]) can = true;     if (mx + 1 <= ed && A[mx + 1] < A[mx]) can = true;     return can || (st == ed);   }   void consume(int st, int ed) {     int mx = st;     for (int i = st; i <= ed; i++) {       if (A[i] > A[mx]) {         mx = i;       }       if (A[i] == A[mx]) {         if (st <= i - 1 && A[i - 1] < A[i]) mx = i;         if (i + 1 <= ed && A[i + 1] < A[i]) mx = i;       }     }     if (mx + 1 <= ed && A[mx + 1] < A[mx]) {       for (int i = mx + 1; i <= ed; i++) {         printf( %d R n , mx + 1);       }       for (int j = mx - 1; j >= st; j--) {         printf( %d L n , j + 1 + 1);       }     } else if (st <= mx - 1 && A[mx - 1] < A[mx]) {       for (int j = mx - 1; j >= st; j--) {         printf( %d L n , j + 1 + 1);       }       for (int i = mx + 1; i <= ed; i++) {         printf( %d R n , st + 1);       }     }   }   int main() {     for (;;) {       int N;       if (scanf( %d , &N) == EOF) break;       for (int i = 0; i < N; i++) {         scanf( %d , &A[i]);       }       int M;       scanf( %d , &M);       for (int i = 0; i < M; i++) {         scanf( %d , &B[i]);       }       int j = 0;       int sum = 0;       bool possible = true;       vector<int> part;       part.push_back(-1);       for (int i = 0; i < N; i++) {         sum += A[i];         if (j < M && sum == B[j]) {           possible &= check(part.back() + 1, i);           part.push_back(i);           if (!possible) break;           sum = 0;           j += 1;         }       }       if (sum > 0 || j < M) possible = false;       if (possible) {         printf( YES n );         for (int i = part.size() - 2; i >= 0; i--) {           consume(part[i] + 1, part[i + 1]);         }       } else {         printf( NO n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int read(T &a) {     a = 0;     char c = getchar(), f = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) f = (~f) + 1;       if (c == -1) return -1;       c = getchar();     }     while (c <=  9  && c >=  0 )       a = (a << 1) + (a << 3) + (c ^ 48), c = getchar();     a *= f;     return 1;   }   template <typename T>   inline int write(T a) {     if (a < 0) putchar( - ), a = (~a) + 1;     if (a / 10) return write(a / 10) & putchar(a % 10 | 48);     return putchar(a | 48);   }   template <typename T>   inline int write(T a, char c) {     return write(a) + putchar(c);   }   int n, m;   int w[200001];   int x[200001], y[200001];   int need[200001];   bool used[200001];   vector<int> v[200001];   bool ok[200001];   queue<int> q;   int ans[200001], cnt;   int main() {     read(n), read(m);     for (int i = 1; i <= n; i++) read(w[i]);     for (int i = 1; i <= m; i++) {       read(x[i]), read(y[i]), need[x[i]]++, need[y[i]]++;       v[x[i]].push_back(i);       v[y[i]].push_back(i);     }     for (int i = 1; i <= n; i++)       if (need[i] <= w[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     while (!q.empty()) {       int t = q.front();       q.pop();       ans[++cnt] = t;       need[x[t]]--, need[y[t]]--;       int i = y[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }       i = x[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     }     if (cnt != m) return puts( DEAD ) & 0;     puts( ALIVE );     for (int i = cnt; i >= 1; i--) write(ans[i],    );     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, n, k, imp, c, h;     int f[200];     {       imp = 0;       memset(f, 0, sizeof(f));       cin >> k;       cin >> s;       n = ((int)s.size());       h = n % 2 + n / 2;       for (i = 0; i < n; i++)         if (isalpha(s[i])) f[s[i] -  a ]++;       for (i = h - 1; i > -1; i--) {         if (s[i] != s[n - i - 1]) {           if (isalpha(s[i]) && isalpha(s[n - i - 1])) {             imp = 1;             break;           } else if (isalpha(s[i]))             s[n - i - 1] = s[i];           else             s[i] = s[n - i - 1];         } else if (s[i] ==  ? ) {           c = 0;           for (j = k - 1; j > -1; j--)             if (f[j] == 0) {               c = j;               f[j]++;               break;             }           s[i] = s[n - i - 1] =  a  + c;         }       }       if (imp == 0) {         for (i = 0; i < k; i++)           if (!f[i]) {             imp = 1;             break;           }       }       if (!imp)         cout << s << endl;       else         cout <<  IMPOSSIBLE  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 5;   int n, cnt[3], dp[N], sum = 1;   int add(int x, int y) { return (1ll * x + 1ll * y) % mod; }   int mul(int x, int y) { return (1ll * x * 1ll * y) % mod; }   int del(int x, int y) { return ((1ll * x - 1ll * y) % mod + mod) % mod; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       cnt[x]++;     }     dp[0] = 1;     dp[1] = 1;     for (int i = 2; i <= cnt[1]; i++)       dp[i] = add(dp[i - 1], mul(dp[i - 2], i - 1));     for (int i = 1; i <= cnt[2]; i++) sum = mul(sum, cnt[1] + i);     printf( %d , mul(sum, dp[cnt[1]]));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<long long, long long> a[N];   long long top, k, n, avr, mx;   int main() {     scanf( %d %d %d , &n, &mx, &avr);     for (int i = 1; i <= n; i++) {       int b, r;       scanf( %d %d , &b, &r);       a[i] = make_pair(r, b);       top += b;     }     sort(a + 1, a + 1 + n);     long long tmp = 0, i = 1;     while (top < avr * n) {       long long t = min(avr * n - top, mx - a[i].second);       top += t;       tmp += t * a[i].first;       i++;     }     cout << tmp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[55][55];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> ch[i][j];     int ret = 0;     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < m - 1; j++) {         bool f = 0, a = 0, c = 0, e = 0;         for (int h = i; h < i + 2; h++)           for (int k = j; k < j + 2; k++)             if (ch[h][k] ==  f )               f = 1;             else if (ch[h][k] ==  a )               a = 1;             else if (ch[h][k] ==  c )               c = 1;             else if (ch[h][k] ==  e )               e = 1;         if (f && a && c && e) ret++;       }     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.size() == 1) {         if (s[0] ==  ? )           printf( a n );         else           cout << s <<   n ;       } else {         int f = 0;         for (int i = 0; i < s.size(); i++) {           if (s[i] == s[i + 1] && s[i] !=  ? ) {             f = 1;             break;           }         }         if (f == 1)           printf( -1 n );         else {           char ch =  a ;           for (int i = 0; i < s.size() - 1; i++) {             if (s[i] ==  ?  && i == 0) {               for (char c =  a ; c <=  c ; c++) {                 if (s[i + 1] != c) {                   s[i] = c;                   break;                 }               }             } else if (s[i] ==  ? ) {               for (char c =  a ; c <=  c ; c++) {                 if (s[i + 1] != c && s[i - 1] != c) {                   s[i] = c;                   break;                 }               }             }           }           if (s[s.size() - 1] ==  ? ) {             for (char c =  a ; c <=  c ; c++) {               if (s[s.size() - 2] != c) {                 s[s.size() - 1] = c;                 break;               }             }           }           cout << s <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long tcc, n, m;   int main() {     scanf( %lld , &tcc);     while (tcc--) {       scanf( %lld %lld , &n, &m);       unsigned long long sum = 0, m2 = m, t = 10;       while (t-- && m2 <= n) {         sum += m2 % 10;         m2 += m;       }       m2 = m * 10;       t = n / m2;       sum *= t;       n -= m2 * t;       m2 = m;       while (m2 <= n) {         sum += m2 % 10;         m2 += m;       }       printf( %lld n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long SIZE = 100000;   const int INF = 0x3f3f3f3f;   const long long ll_INF = 0x3f3f3f3f3f3f3f3f;   const long double PI = acos(-1);   const long long MAXN = numeric_limits<long long>::max();   const long long MAX = 2000000;   void solve() {     string s;     long long k, i = 1;     cin >> k;     while (((int)(s).size()) < k) {       s += to_string(i);       i++;     }     cout << s[k - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x[100002];   vector<int> P[2 * 100002];   void NoSol() {     printf( No n );     exit(0);   }   long long sqr(int x) { return 1LL * x * x; }   int bs(int x, long long val) {     int i = -1, sz = P[x].size(), p = 1;     while (p < sz) p <<= 1;     while (p) {       if (i + p < sz && sqr(P[x][i + p]) <= val) i += p;       p >>= 1;     }     return i + 1;   }   int main() {     int n;     long long Xmax = 0;     scanf( %d , &n);     for (int i = 0; i < n / 2; ++i) {       scanf( %lld , &x[i * 2 + 1]);       Xmax = max(Xmax, x[i * 2 + 1]);       if (x[i * 2 + 1] % 4 == 2) NoSol();     }     long long s = 0;     for (int a = 1; a < Xmax; ++a)       for (int b = a + 1; sqr(b) - sqr(a) <= Xmax; ++b)         P[sqr(b) - sqr(a)].push_back(a);     long long sum = 0;     for (int i = 0; i < n / 2; ++i) {       long long X = x[i * 2 + 1];       if (P[X].empty()) NoSol();       if (sqr(P[X].back()) <= sum) NoSol();       x[i * 2] = sqr(P[X][bs(X, sum)]) - sum;       sum = sum + x[i * 2] + X;     }     printf( Yes n );     s = 0;     for (int i = 0; i < n; ++i) {       printf( %lld  , x[i]);       s += x[i];       long long r = sqrt(s);       if (r * r != s)         while (1)           ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, m, a[100100], sum = 0;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       pq.push(make_pair(a[i], i));     }     if (sum < k) {       cout << -1 << endl;       return 0;     }     long long last = 0;     while (!pq.empty()) {       long long x = pq.top().first;       if ((x - last) * pq.size() <= k) {         k -= (x - last) * pq.size();         last = x;         while (!pq.empty()) {           if (pq.top().first == x)             pq.pop();           else             break;         }       } else         break;     }     long long temp = pq.size();     if (temp == 0) return 0;     m = k % temp;     long long o = k / temp;     for (int i = 1; i <= n; i++) a[i] -= (last + o);     deque<long long> dq;     m = k % temp;     for (int i = 1; i <= n; i++) {       if (a[i] > 0) dq.push_back(i);     }     for (int i = 0; i < m; i++) {       if (dq.empty()) return 0;       long long x = dq.front();       dq.pop_front();       if (a[x] > 0) dq.push_back(x);       a[x]--;     }     while (!dq.empty()) {       if (a[dq.front()] > 0) cout << dq.front() <<    ;       dq.pop_front();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, q;   unsigned int C[132];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int a[132];   void Init() {     C[0] = 1;     for (int i = 1; i <= min(p, n - 1); ++i) {       a[0] = 0;       for (int j = 0; j < i; ++j) a[++a[0]] = n - j;       for (int k = 1; k <= i; ++k) {         int x = k;         for (int j = 1; j <= a[0] && k != 1; ++j) {           int Gcd = gcd(x, a[j]);           a[j] /= Gcd, x /= Gcd;         }       }       C[i] = 1;       for (int j = 1; j <= a[0]; ++j) C[i] = C[i] * a[j];     }   }   int main() {     scanf( %d%d%d , &n, &p, &q), Init();     unsigned int ans = 0;     for (int i = 1; i <= q; ++i) {       unsigned int tmp = 0, now = 1;       for (int j = 0; j <= min(p, n - 1); ++j, now = now * i) tmp += C[j] * now;       ans ^= tmp * i;     }     printf( %u n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sgn(T x) {     return x < 0 ? -1 : x != 0;   }   template <typename T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   void reads(string& x) {     char kk[((long long)5e2 + 123)];     scanf( %s , kk);     x = kk;   }   long long n, m, ans;   long long v, r[((long long)5e2 + 123)], c[((long long)5e2 + 123)];   long long lp[(long long)1e6 + 1];   vector<long long> pr;   void sieve() {     for (long long i = 2; i <= 1e6; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (long long j = 0;            j < (long long)pr.size() && pr[j] <= lp[i] && i * pr[j] <= 1e6; ++j)         lp[i * pr[j]] = pr[j];     }   }   void solve() {     sieve();     scanf( %lld %lld , &n, &m);     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) {         scanf(  %lld , &v);         v = (*lower_bound(pr.begin(), pr.end(), v) - v);         r[i] += v;         c[j] += v;       }     ans = 1e9;     for (long long i = 0; i < n; i++) ans = min(ans, r[i]);     for (long long i = 0; i < m; i++) ans = min(ans, c[i]);     printf( %lld n , ans);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[100005];   bool d[100005];   int s[100005];   void del(int i, int par) {     if (v[i].size() <= 2) {       d[i] = true;       for (int j : v[i])         if (j != par) del(j, i);     }   }   int main() {     int n;     cin >> n;     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       if (v[i].size() == 1) del(i, 0);     }     for (int i = 1; i <= n; i++) {       for (int j : v[i])         if (d[j]) s[i] = min(s[i] + 1, 2);     }     for (int i = 1; i <= n; i++)       if (!d[i]) {         int cnt = 0;         for (int j : v[i])           if (!d[j] && v[j].size() - s[j] > 1) cnt++;         if (cnt > 2) {           cout <<  No n ;           return 0;         }       }     cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int main() {     ios::sync_with_stdio(0);     double a, b, m, t, dx, dz, mz, mx, vx, vy, vz, ansx, ansz;     int pz, px;     cin >> a >> b >> m;     cin >> vx >> vy >> vz;     t = m / abs(vy);     dz = t * vz;     pz = dz / b;     mz = dz - pz * b;     if ((int)pz % 2 == 0)       ansz = mz;     else       ansz = b - mz;     dx = abs(vx) * t;     if (dx <= a / 2)       ansx = a / 2 + dx;     else {       dx -= a / 2;       px = dx / a;       mx = dx - px * a;       if ((int)px % 2 == 0)         ansx = a - mx;       else         ansx = mx;     }     if (vx < 0) {       ansx = a - ansx;     }     cout << fixed << setprecision(8) << ansx << endl;     cout << ansz << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long large = 2000000000000000000LL;   vector<int> p;   int f(int x) { return p[x] == x ? x : p[x] = f(p[x]); }   vector<vector<pair<int, int> > > adj;   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     p.assign(n, 0);     adj.assign(n, vector<pair<int, int> >());     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       x--;       y--;       int t = 0;       if (z == b) t = 1;       adj[x].push_back(pair<int, int>(y, t));       adj[y].push_back(pair<int, int>(x, t));       if (t == 0) p[f(x)] = f(y);     }     map<int, int> comp;     int sz = 0;     for (int i = 0; i < n; i++) {       if (comp.find(f(i)) == comp.end()) comp[f(i)] = sz++;     }     vector<vector<int> > cc(sz, vector<int>());     for (int i = 0; i < n; i++) cc[comp[f(i)]].push_back(i);     sz = 0;     comp.clear();     for (int i = 0; i < (int)cc.size(); i++) {       if ((int)cc[i].size() > 3) comp[f(cc[i][0])] = sz++;     }     vector<vector<int> > dis(1 << sz, vector<int>(n, 1000000010));     dis[0][0] = 0;     priority_queue<pair<int, pair<int, int> >,                    vector<pair<int, pair<int, int> > >,                    greater<pair<int, pair<int, int> > > >         pq;     pq.push(pair<int, pair<int, int> >(0, pair<int, int>(0, 0)));     while (!pq.empty()) {       pair<int, pair<int, int> > front = pq.top();       pq.pop();       int mask = front.second.first;       int u = front.second.second;       if (front.first > dis[mask][u]) continue;       for (int j = 0; j < (int)adj[u].size(); j++) {         int v = adj[u][j].first;         int ty = adj[u][j].second;         if (ty == 0) {           int cost = dis[mask][u] + a;           if (dis[mask][v] > cost) {             dis[mask][v] = cost;             pq.push(pair<int, pair<int, int> >(dis[mask][v],                                                pair<int, int>(mask, v)));           }         } else {           int cost = dis[mask][u] + b;           if (f(u) != f(v)) {             int vmask = mask;             if (comp.find(f(v)) != comp.end()) {               if (mask & (1 << comp[f(v)])) continue;             }             if (comp.find(f(u)) != comp.end()) {               vmask |= (1 << comp[f(u)]);             }             if (dis[vmask][v] > cost) {               dis[vmask][v] = cost;               pq.push(pair<int, pair<int, int> >(dis[vmask][v],                                                  pair<int, int>(vmask, v)));             }           }         }       }     }     vector<int> dp(n, 1000000010);     for (int i = 0; i < n; i++) {       for (int j = 0; j < (1 << sz); j++) {         dp[i] = min(dp[i], dis[j][i]);       }     }     for (int i = 0; i < n; i++) cout << dp[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n;     string s;     cin >> n >> s;     if (count(s.begin(), s.end(), s[0]) == s.size() || s.size() == 1) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       for (int i = 0; i < s.size() - 1; i++) {         if (s[i] != s[i + 1]) {           cout << s[i] << s[i + 1];           exit(0);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int need, e;   int mat[128][128];   bool found;   int add;   int v;   int main() {     memset(mat, 0, sizeof mat);     cin >> need;     e = 0;     while (e < need) {       found = false;       for (int i = 1; i <= v && found == false; i++)         for (int j = i + 1; j <= v && found == false; j++) {           if (mat[i][j] == 1) continue;           add = 0;           for (int k = 1; k <= v; k++) {             if (k == i || k == j) continue;             if (mat[i][k] && mat[k][j]) add++;           }           if (e + add <= need) {             found = true;             e += add;             mat[i][j] = 1;             mat[j][i] = 1;           }         }       if (found == false) v++;     }     cout << v << endl;     for (int i = 1; i <= v; i++) {       for (int j = 1; j <= v; j++) cout << mat[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     int fu = 1;     char c = getchar();     while (c > 57 || c < 48) {       if (c == 45) fu = -1;       c = getchar();     }     while (c <= 57 && c >= 48) {       x = (x << 3) + (x << 1) + c - 48;       c = getchar();     }     x *= fu;   }   template <typename T>   inline void fprint(T x) {     if (x < 0) putchar(45), x = -x;     if (x > 9) fprint(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void fprint(T x, char ch) {     fprint(x);     putchar(ch);   }   inline char next_char() {     char ch = getchar();     while (ch == 9 || ch == 10 || ch == 32) ch = getchar();     return ch;   }   template <typename T>   inline T mn(T x, T y) {     return x < y ? x : y;   }   template <typename T>   inline T mx(T x, T y) {     return x > y ? x : y;   }   template <typename T>   inline void chmin(T &x, T y) {     (x > y) && (x = y);   }   template <typename T>   inline void chmax(T &x, T y) {     (x < y) && (x = y);   }   long long x, y;   inline void MAIN() {     read(x);     read(y);     if (x % y != 0) {       fprint(x, 10);       return;     } else {       long long mem = x, ans = 1;       for (register long long i = 2; i * i <= y; i++) {         x = mem;         if (y % i == 0) {           while (x % i == 0) x /= i;           while (y % i == 0) {             y /= i;             x *= i;           }           x /= i;           chmax(ans, x);         }       }       x = mem;       if (y > 1) {         while (x % y == 0) x /= y;         chmax(ans, x);       }       fprint(ans, 10);     }   }   int main() {     int T;     read(T);     while (T--) MAIN();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n;     cin >> n;     string s =  ROYGBIV ;     long long x = n - 7;     string st =  GBIV ;     long long i = 0;     while (i < x) {       s += st[(i % 4)];       i++;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, s, a[500009], b[500009];   int chk[500009];   bool ok(int p) {     vector<int> c(500009);     for (int i = 0; i <= p; i++) c[a[i]]++;     for (int i = 0; i < 500009; i++)       if (c[i] < chk[i]) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     cin >> m >> k >> n >> s;     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i < s; i++) cin >> b[i], chk[b[i]]++;     int l = 0, r = m - 1;     if (!ok(r)) {       cout << -1;       return 0;     }     while (l < r) {       int mid = (l + r) >> 1;       if (ok(mid)) {         r = mid;       } else {         l = mid + 1;       }     }     vector<pair<int, int>> cut;     vector<int> chkk(500009);     r = max(r, k - 1);     for (int i = 0; i <= r; i++) chkk[a[i]]++;     for (int i = 0; i < m; i++) {       cut.push_back(make_pair(i, r));       chkk[a[i]]--;       while (r + 1 < m && (chkk[a[i]] < chk[a[i]] || r - i < k)) {         chkk[a[++r]]++;       }       if (chkk[a[i]] < chk[a[i]] || r - i < k) {         break;       }     }     int fid = -1;     for (int i = 0; i < cut.size(); i++) {       if (cut[i].first / k + 1 + (m - cut[i].second - 1) / k >= n) {         fid = i;         break;       }     }     if (fid == -1) {       cout << -1;       return 0;     }     vector<int> ans;     for (int i = cut[fid].first; i <= cut[fid].second; i++) {       if (chk[a[i]] != 0) {         chk[a[i]]--;       } else {         ans.push_back(i);       }     }     cout << cut[fid].second - cut[fid].first + 1 - k + (cut[fid].first % k)          <<   n ;     for (int i = 0; i < cut[fid].first % k; i++) cout << i + 1 <<    ;     for (int i = 0; i < cut[fid].second - cut[fid].first + 1 - k; i++) {       cout << ans[i] + 1 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   char s[MAXN][MAXN];   int n, m, pre[MAXN], nex[MAXN];   bool check[MAXN];   int main() {     scanf( %d%d n , &n, &m);     for (int i = 1; i <= n; ++i) gets(s[i] + 1);     for (int j = 0; j <= m + 1; ++j) pre[j] = j - 1, nex[j] = j + 1;     int res = 0;     for (int j = nex[0]; j <= m; j = nex[j]) {       bool ok = 1;       for (int i = 1; i <= n - 1; ++i) {         if (!check[i] && s[i][j] > s[i + 1][j]) {           ok = 0;           break;         }       }       if (!ok) {         int prevpos = pre[j], nextpos = nex[j];         nex[prevpos] = nextpos;         pre[nextpos] = prevpos;         ++res;       } else {         for (int i = 1; i <= n - 1; ++i)           if (s[i][j] < s[i + 1][j]) check[i] = 1;       }     }     printf( %d , res);   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1000009;   char s[SIZE];   long long int dsum[SIZE];   int dtotal;   long long int usum[SIZE];   int utotal;   int main() {     int N;     scanf( %d%s , &N, s + 1);     for (int i = 1; i <= N; i++) {       if (s[i] ==  U ) {         ++utotal;         usum[utotal] = i + usum[utotal - 1];       } else {         ++dtotal;         dsum[dtotal] = i + dsum[dtotal - 1];       }     }     int meetd = 0;     int meetu = 0;     for (long long int i = 1; i <= N; i++) {       meetd += s[i] ==  D ;       int lu = meetu;       int rd = dtotal - meetd;       int mn = min(lu, rd);       long long int ans =           (dsum[meetd + mn] - dsum[meetd] - (usum[meetu] - usum[meetu - mn])) * 2;       if (s[i] ==  U ) {         if (lu >= rd)           ans += N + 1 - i;         else           ans += (dsum[meetd + mn + 1] - dsum[meetd + mn] - i) * 2 + i;       } else {         if (rd >= lu)           ans += i;         else           ans += (i - usum[meetu - mn] + usum[meetu - mn - 1]) * 2 + N + 1 - i;       }       meetu += s[i] ==  U ;       printf( %lld  , ans);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int n, hitung, arr[212];   void swap(int x, int y) {     for (int i = y; i > x; i--) {       int tmp = arr[i - 1];       arr[i - 1] = arr[i];       arr[i] = tmp;       hitung += 1;     }   }   int main() {     cin >> n;     for (int i = 1; i <= 2 * n; i++) {       cin >> arr[i];     }     int i = 1;     while (i <= 2 * n) {       if (arr[i] == arr[i + 1]) {       } else {         for (int j = i + 2; j <= 2 * n; j++) {           if (arr[i] == arr[j]) {             swap(i + 1, j);             break;           }         }       }       i += 2;     }     cout << hitung <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int A[110][110];   char buf[3];   bool mark[110][110][30][2];   bool memo[110][110][30][2];   bool win(int u, int v, int prev, int turn) {     bool& ans = memo[u][v][prev][turn];     if (mark[u][v][prev][turn]) return ans;     mark[u][v][prev][turn] = true;     ans = true;     for (int i = 1; i <= n && ans; i++) {       if (turn == 0) {         if (A[u][i] < prev) continue;         ans = !win(i, v, A[u][i], 1 - turn);       } else {         if (A[v][i] < prev) continue;         ans = !win(u, i, A[v][i], 1 - turn);       }     }     return ans;   }   int main() {     memset(A, -1, sizeof(A));     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d %s , &x, &y, buf);       A[x][y] = buf[0] -  a  + 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (win(i, j, 0, 0))           printf( B );         else           printf( A );       }       printf(  n );     }     return 0;   }


#include<bits/stdc++.h>      using namespace std;   #define int long long      int32_t main()   {       int t;       cin >> t;       while(t--)       {           string s;           int n;           cin >> n;           cin >> s;           sort(s.begin(),s.end());           cout << s << endl;       }       return 0;   }


#include <bits/stdc++.h>   constexpr int mod = 1e9 + 7;   int main() {    using namespace std;    ios_base::sync_with_stdio(false), cin.tie(nullptr);    int tt; cin >> tt;    while (tt--) {     int n, k; cin >> n >> k;     vector<uint16_t> a(n);     for (uint16_t &x : a) cin >> x;     sort(a.begin(), a.end(), greater<uint16_t> ());     int N = 1, M = 1;     for (int i = k - 2; i >= 0 && a[i] == a[k - 1]; --i) ++N, ++M;     for (int i = k; i < n && a[i] == a[k - 1]; ++i) ++N;     auto qpow = [&](int a, int b) -> int {      int res = 1;      while (b) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod, b >>= 1;      }      return res;     };     auto C = [&](int N, int M) -> int {      int res = 1;      for (int i = 0; i < M; ++i)       res = 1ll * res * (N - i) % mod * qpow(i + 1, mod - 2) % mod;      return res;     };     cout << C(N, M) <<   n ;    }   }


#include <bits/stdc++.h>   const int maxn = 300010;   int n, m, cnt, go_far;   int not_read[maxn], clr[maxn];   int a[maxn];   int main() {     int i, op, x, t, zz;     scanf( %d%d , &n, &m);     cnt = 0;     a[0] = 0;     go_far = 0;     for (zz = 1; zz <= m; zz++) {       scanf( %d%d , &op, &x);       if (op == 1) {         a[++a[0]] = x;         cnt++;         not_read[x]++;       } else if (op == 2) {         cnt -= not_read[x];         clr[x] += not_read[x];         not_read[x] = 0;       } else {         t = x;         for (i = go_far + 1; i <= t; i++) {           x = a[i];           if (clr[x])             clr[x]--;           else             cnt--, not_read[x]--;         }         if (t > go_far) go_far = t;       }       printf( %d n , cnt);     }   }


#include <bits/stdc++.h>   using namespace std;   int a[200005];   int f[200005];   int main() {     ios::sync_with_stdio(false);     int t, n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       int maxx = 0;       int minx = 999999999;       for (int j = 0; j < n; j++) {         cin >> a[j];         f[a[j]] = j;       }       for (int j = 1; j <= n; j++) {         maxx = max(maxx, f[j]);         minx = min(minx, f[j]);         if (maxx - minx == j - 1) {           cout << 1;         } else           cout << 0;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[1001000];   int main() {     int a, b, k;     cin >> a >> b >> k;     for (int i = 2; i <= b + 20; i++) p[i] = 1;     for (int i = 2; i <= b + 20; i++)       if (p[i])         for (int j = i + i; j <= b + 10; j = j + i) p[j] = 0;     for (int i = 1; i < b + 10; i++) p[i] = p[i] + p[i - 1];     int lo, hi, m;     lo = 0;     hi = b - a + 2;     while (lo < hi) {       int f = 1;       m = (lo + hi) / 2;       for (int i = a - 1; i + m <= b; i++) {         if (p[i + m] - p[i] < k) {           f = 0;           break;         }       }       if (f == 1) {         hi = m;       } else         lo = m + 1;     }     if (lo > b - a + 1) {       cout <<  -1  << endl;     } else       cout << lo << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize(4)   using namespace std;   const int N = 9;   const int C = 840;   int n;   long long dp[C * N];   long long cnt[N], M;   int main() {     scanf( %lld , &M);     for (int i = 1; i < N; ++i) scanf( %lld , &cnt[i]);     memset(dp, -1, sizeof(dp));     dp[0] = 0;     for (int i = 1; i < N; ++i) {       for (int j = C * N - 1; j >= 0; --j) {         int c = C / i;         if (cnt[i] < c) c = cnt[i];         for (int k = 1; k <= c; ++k) {           if (j - k * i >= 0) {             if (~dp[j - k * i])               dp[j] = max(dp[j], dp[j - k * i] + (cnt[i] - k) / (C / i));           }         }       }     }     long long ans = 0;     for (int i = 0; i < (N - 1) * C; ++i) {       if (~dp[i]) {         if (M >= i) ans = max(ans, i + min(dp[i], (M - i) / C) * C);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, f = 0;       cin >> n;       vector<char> v1, v2;       for (int i = 0; i < n; i++) {         char a;         cin >> a;         v1.push_back(a);       }       for (int i = 0; i < n; i++) {         char b;         cin >> b;         v2.push_back(b);       }       for (int i = 0; i < n; i++) {         if (v1[i] ==  1  && v2[i] ==  1 ) {           f = 1;           break;         }       }       if (f == 1) {         cout <<  No  << endl;       } else {         cout <<  Yes  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, m;   long long ans;   int main() {     cin >> x >> y >> m;     if (x >= m || y >= m) {       cout << 0;       return 0;     }     if (x <= 0 && y <= 0) {       cout << -1;       return 0;     }     if (y < 0) swap(x, y);     if (x < 0) {       ans += ceil((double)-x / y);       x += y * ans;     }     if (x < y) swap(x, y);     while (x < m) {       y = y + x;       if (x < y) swap(x, y);       ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int memo[5001][501];   int k;   int h[11];   long long distribute(int cards, int players) {     if (cards <= 0 or players <= 0) return 0;     if (cards >= k * players) return players * h[k];     if (memo[cards][players] != -1) {       return memo[cards][players];     }     int min_cards = max(0, cards - k * (players - 1));     long long best = 0;     for (int c = min_cards; c <= min(k, cards); ++c) {       best = max(best, h[c] + distribute(cards - c, players - 1));     }     return memo[cards][players] = best;   }   void solve() {     memset(memo, -1, sizeof memo);     int n;     cin >> n >> k;     vector<int> c, f;     c.reserve(n * k);     copy_n(istream_iterator<int>(cin), n * k, back_inserter(c));     f.reserve(n);     copy_n(istream_iterator<int>(cin), n, back_inserter(f));     h[0] = 0;     for (int i = 1; i <= k; ++i) cin >> h[i];     sort(begin(c), end(c));     sort(begin(f), end(f));     long long joy = 0;     auto itf = begin(f);     auto itc = begin(c);     while (itf != end(f)) {       int x = *itf;       auto foo = equal_range(itf, end(f), x);       auto bar = equal_range(itc, end(c), x);       joy += distribute(bar.second - bar.first, foo.second - foo.first);       itf = foo.second;       itc = bar.second;     }     cout << joy << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   int n, S;   long long tot;   struct Node {     long long val;     long long num;     long long sum;     bool operator<(const Node &rhs) const { return num < rhs.num; }   };   vector<Node> a, b;   long long work(long long ls, vector<Node> &a) {     int id = upper_bound(a.begin(), a.end(), Node{0, ls}) - a.begin();     long long ret = 0;     if (--id >= 0) {       ret = a[id].sum;     }     if (id + 1 != a.size()) {       long long left = ls - (id == -1 ? 0 : a[id].num);       ret += left * a[id + 1].val;     }     return ret;   }   long long cal(long long x) {     long long ret = work(x * S, a);     ret += work((tot - x) * S, b);     return ret;   }   long long solve(long long l, long long r) {     while (r > l) {       long long m1 = (2 * l + r) / 3;       long long m2 = (2 * r + l + 2) / 3;       long long ret1 = cal(m1);       long long ret2 = cal(m2);       if (ret1 > ret2)         r = m2 - 1;       else         l = m1 + 1;     }     return cal(l);   }   int main() {     scanf( %d%d , &n, &S);     long long cnt = 0;     long long now = 0;     for (int i = 0; i < n; ++i) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       cnt += x;       now += 1ll * x * min(y, z);       if (y > z)         a.emplace_back(Node{1ll * y - z, 1ll * x, 1ll * (y - z) * x});       else if (y < z)         b.emplace_back(Node{1ll * z - y, 1ll * x, 1ll * (z - y) * x});     }     sort(a.begin(), a.end(), [](Node x, Node y) { return x.val > y.val; });     sort(b.begin(), b.end(), [](Node x, Node y) { return x.val > y.val; });     tot = cnt / S + (cnt % S > 0);     for (int i = 0; i < a.size(); ++i) {       if (i) a[i].sum += a[i - 1].sum, a[i].num += a[i - 1].num;     }     for (int i = 0; i < b.size(); ++i) {       if (i) b[i].sum += b[i - 1].sum, b[i].num += b[i - 1].num;     }     printf( %I64d n , solve(0, tot) + now);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dd[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   vector<vector<int>> mat(1000, vector<int>(1000));   int n, m, si, sj;   void bfs() {     mat[si][sj] = 1;     queue<pair<int, int>> q;     q.push({si, sj});     while (!q.empty()) {       auto p = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int ti = p.first + dd[i][0];         int tj = p.second + dd[i][1];         if (ti >= 0 && tj >= 0 && ti < n && tj < m && !mat[ti][tj]) {           mat[ti][tj] = mat[p.first][p.second] + 1;           q.push({ti, tj});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     int ei, ej;     vector<pair<int, pair<int, int>>> v;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  E ) {           si = i, sj = j;           mat[i][j] = 0;         } else {           if (s[j] ==  T )             mat[i][j] = -1;           else {             mat[i][j] = 0;             if (s[j] ==  S )               ei = i, ej = j;             else               v.push_back({s[j] -  0 , {i, j}});           }         }       }     }     bfs();     int ans = 0;     int my = mat[ei][ej];     for (auto i : v) {       int cur = mat[i.second.first][i.second.second];       if (cur && cur <= my) {         ans += i.first;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( fast-math )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native )   mt19937 rnd(51);   const int N = 1010;   vector<int> g[N];   vector<bool> used(N);   vector<int> d(N);   void ask(vector<int> v) {     cout <<  ?           <<     << v.size() <<    ;     for (auto to : v) {       cout << to <<    ;     }     cout << endl;   }   void dfs(int v) {     used[v] = 1;     for (auto to : g[v]) {       if (!used[to]) {         d[to] = d[v] + 1;         dfs(to);       }     }   }   void solve() {     vector<int> kek;     int n, need = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       kek.push_back(i);     }     for (int i = 0; i < N; i++) {       g[i].clear();       used[i] = 0;       d[i] = 0;     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     ask(kek);     cin >> need >> need;     dfs(1);     int mx = 0;     for (int i = 1; i <= n; i++) {       mx = max(mx, d[i]);     }     int l = -1, r = mx + 1, j = 0;     while (r - l > 1) {       int mid = (r + l) / 2;       vector<int> lol;       for (int i = 1; i <= n; i++) {         if (d[i] >= mid) {           lol.push_back(i);         }       }       ask(lol);       int i, mn;       cin >> i >> mn;       if (mn == need) {         l = mid;         j = i;       } else {         r = mid;       }     }     kek.clear();     kek.push_back(1);     ask(kek);     int d1;     cin >> d1 >> d1;     d1 = (d1 - need) / 2;     int d2 = d1 + (need - (d[j] - d1));     kek.clear();     for (int i = 1; i <= n; i++) {       if (d[i] == d2) {         kek.push_back(i);       }     }     ask(kek);     int v, lol;     cin >> v >> lol;     bool x = 0;     deque<int> q;     q.push_back(v);     while (q.size() > 0) {       int u = q.front();       q.pop_front();       if (u == j) x = 1;       for (auto to : g[u]) {         if (d[to] > d[u]) {           q.push_back(to);         }       }     }     if (x) {       int last = v;       vector<int> kek1;       for (auto to : kek) {         if (to != v) {           kek1.push_back(to);         }       }       if (kek1.size() != 0) {         ask(kek1);         cin >> v >> lol;         if (lol != need) {           v = last;         }       }     }     cout <<  !  <<     << v <<     << j << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();       string s;       cin >> s;       if (s ==  Correct )         continue;       else {         exit(0);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res % mod) * (a % mod), res %= mod;       a = (a % mod) * (a % mod);       a %= mod;       b >>= 1;     }     return res;   }   long long divide(long long a, int b) {     return ((a % mod) * binpow(b, mod - 2) % mod) % mod;   }   long long nCr(long long n, long long k) {     long long res = 1;     if (k > n - k) k = n - k;     for (int i = 0; i < k; ++i) {       res = ((res % mod) * ((n - i) % mod)) % mod;       res = divide(res, i + 1);     }     return res;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n;     k = n;     bool can = (n == 1);     multiset<long long> st;     for (long long i = 2; i * i <= n; i++) {       while (n % i == 0) {         n /= i;         st.insert(i);       }     }     if (n > 1) st.insert(n);     if (n == k) can = 1;     if (can) {       return cout <<  1 n0 n , 0;     }     if (st.size() == 2) {       cout <<  2 n ;     } else {       cout <<  1 n ;       int cnt = 0;       long long mul = 1;       for (auto i : st) {         mul *= i;         cnt++;         if (cnt == 2) break;       }       cout << mul;     }   }


#include <bits/stdc++.h>   using namespace std;   void FastInputOutput() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     int n, temp;     map<int, int> idx;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &temp);       idx[temp] = i;     }     int q;     long long l = 0, r = 0;     scanf( %d , &q);     while (q--) {       scanf( %d , &temp);       l += idx[temp], r += n - idx[temp] + 1;     }     printf( %lld %lld , l, r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, q, t, c;   string s;   long long inv[200007];   long long p[200007];   long long f[200007];   long long nq[200007];   long long mq[200007];   long long res[200007];   long long dp[200007];   vector<long long> que[200007];   long long fpow(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % 1000000007;     if (b % 2)       return (a * fpow(a, b - 1)) % 1000000007;     else {       long long q = fpow(a, b / 2);       return (q * q) % 1000000007;     }   }   long long dziel(long long a, long long b) {     return (a * fpow(b % 1000000007, 1000000007 - 2)) % 1000000007;   }   long long choose(long long a, long long b) {     return dziel(f[a], f[b] * f[a - b]);   }   void solve(long long m) {     memset(dp, 0, sizeof dp);     dp[m] = 1;     long long dwumian = 1;     for (long long i = m + 1; i <= 1e5; ++i) {       dwumian = (((dwumian * (i - 1)) % 1000000007) * inv[i - m]) % 1000000007;       dp[i] = (26 * dp[i - 1] + dwumian * p[i - m]) % 1000000007;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     f[0] = 1;     p[0] = 1;     for (long long i = 1; i < 200007; ++i) {       f[i] = (f[i - 1] * i) % 1000000007;       p[i] = (25 * p[i - 1]) % 1000000007;       inv[i] = fpow(i, 1000000007 - 2);     }     cin >> q >> s;     m = s.size();     for (long long i = 1; i <= q; ++i) {       cin >> t;       if (t == 1) {         cin >> s;         m = s.size();       } else {         cin >> n;         nq[++c] = n;         mq[c] = m;         que[m].push_back(c);       }     }     for (long long i = 1; i <= 1e5; ++i) {       if (!que[i].empty()) solve(i);       for (auto it : que[i]) res[it] = dp[nq[it]];     }     for (long long i = 1; i <= c; ++i) {       cout << res[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long NLINF = 0xf7f7f7f7f7f7f7f7;   const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;   const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;   const int N = 1e5 + 10;   vector<int> sz;   int t, n, lst;   int main() {     for (scanf( %d , &t); t--;) {       scanf( %d , &n), lst = -1;       printf( 1 );       while (n > 0) {         ;         int k = 1;         while (k * (k - 1) / 2 <= n) k++;         k--;         if (lst != -1) sz.emplace_back(lst - k);         lst = k, n -= k * (k - 1) / 2;       }       sz.emplace_back(lst);       ;       reverse(sz.begin(), sz.end());       for (auto &x : sz) {         for (int i = 0; i < x; i++) printf( 3 );         printf( 7 );       }       sz.clear();       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s, n, a[10000] = {0}, m = -1, y, i;     cin >> s >> n;     int c = n;     while (n--) {       cin >> i >> y;       a[i] += y;       m = max(m, i);     }     for (int i = 0; i < 10000; i++) {       if (s > i) {         s += a[i];       }     }     s > m ? cout <<  YES  : cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, k, x, y, z;     cin >> n >> m >> k;     vector<long long> v(n + 1);     vector<long long> s(n + 2, 0);     vector<long long> m1(m + 1);     vector<long long> m2(m + 1);     vector<long long> m3(m + 1);     vector<long long> k1(m + 2);     for (long long i = 1; i <= n; ++i) {       cin >> x;       v[i] = x;     }     for (long long i = 1; i <= m; ++i) {       cin >> x >> y >> z;       m1[i] = x;       m2[i] = y;       m3[i] = z;     }     for (long long i = 1; i <= k; ++i) {       cin >> x >> y;       k1[x] += 1;       k1[y + 1] += -1;     }     long long sum = 0;     for (long long i = 1; i <= m; ++i) {       sum += k1[i];       s[m1[i]] += sum * m3[i];       s[m2[i] + 1] -= sum * m3[i];     }     sum = 0;     for (long long i = 1; i <= n; ++i) {       s[i] += sum;       sum = s[i];     }     for (long long i = 1; i <= n; ++i) {       s[i] += v[i];       cout << s[i] <<    ;     }     return 0;   }