#include <bits/stdc++.h>   using namespace std;   long long int binarySearch(long long int* arr, long long int l, long long int r,                              long long int x) {     if (r >= l) {       long long int mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, n1, n2, n3, i, j, l, x;     cin >> t;     for (l = 0; l < t; l++) {       string s =   ;       cin >> n1 >> n2 >> n3;       if (n1 > 0) {         for (i = 0; i <= n1; i++) s +=  0 ;       }       if (n3 > 0 && n1 > 0) n2 -= 1;       if (n3 > 0) {         for (i = 0; i <= n3; i++) s +=  1 ;       }       if (n2 > 0 && n3 > 0) {         x = 0;         for (i = 0; i < n2; i++) {           s += (x +  0 );           x = (x + 1) % 2;         }       } else if (n2 > 0 && n1 > 0) {         x = 1;         for (i = 0; i < n2; i++) {           s += (x +  0 );           x = (x + 1) % 2;         }       } else if (n2 > 0) {         s +=  1 ;         x = 0;         for (i = 0; i < n2; i++) {           s += (x +  0 );           x = (x + 1) % 2;         }       }       cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(int x, int y) { return x > y; }   int main() {     double sum;     int n, r[110];     while (~scanf( %d , &n)) {       sum = 0;       for (int i = 0; i < n; i++) scanf( %d , &r[i]);       sort(r, r + n, cmp);       int tmp = 1;       for (int i = 0; i < n; i++) {         sum += tmp * r[i] * r[i];         tmp *= -1;       }       printf( %.15f n , sum * 3.141592653589793);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct line {     long long m, b;     int id;   };   long long floordiv(long long a, long long b) {     return a / b - (a % b && ((a < 0) ^ (b < 0)));   }   long long intersect(line a, line b) { return floordiv(b.b - a.b, a.m - b.m); }   pair<int, int> org[262192 >> 1];   pair<pair<int, int>, int> ist[262192 >> 1];   struct Convex {     vector<line> cht;     void insert(line l) {       auto n = cht.size();       while ((n >= 1 && l.m == cht[n - 1].m && l.b >= cht[n - 1].b) ||              (n >= 2 &&               intersect(cht[n - 1], cht[n - 2]) >= intersect(cht[n - 1], l))) {         cht.pop_back();         n = cht.size();       }       cht.push_back(l);     }     long long query(long long x) {       int low = 0, high = (int)cht.size() - 2;       int ret = (int)cht.size() - 1;       while (low <= high) {         int mid = low + (high - low) / 2;         if (intersect(cht[mid], cht[mid + 1]) >= x) {           ret = mid;           high = mid - 1;         } else {           low = mid + 1;         }       }       return cht[ret].id;     }   };   Convex tree[262192];   void insert(int pos, int l, int r, int index, line li) {     if (l > r || pos < l || pos > r) return;     tree[index].insert(li);     if (l == r) return;     int mid = (l + r) >> 1;     if (pos <= mid) {       insert(pos, l, mid, index << 1, li);     } else {       insert(pos, mid + 1, r, index << 1 | 1, li);     }   }   int query(int start, int end, int l, int r, int index, long long t) {     if (start > end || l > r || start > r || l > end) return 0;     if (start <= l && r <= end) return tree[index].query(t);     int mid = (l + r) >> 1;     if (end <= mid) return query(start, end, l, mid, index * 2, t);     if (mid + 1 <= start) return query(start, end, mid + 1, r, index * 2 + 1, t);     int id1 = query(start, end, l, mid, index * 2, t);     int id2 = query(start, end, mid + 1, r, index * 2 + 1, t);     long long y1 = 1ll * org[id1].first * t + org[id1].second;     long long y2 = 1ll * org[id2].first * t + org[id2].second;     if (y1 > y2) return id1;     return id2;   }   int main() {     int n, m, i;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d%d , &org[i].second, &org[i].first);       ist[i].first = org[i], ist[i].second = i;     }     sort(ist + 1, ist + n + 1);     for (i = 1; i <= n; i++) {       insert(ist[i].second, 1, n, 1,              line{ist[i].first.first, ist[i].first.second, ist[i].second});     }     while (m > 0) {       int l, r, t;       scanf( %d%d%d , &l, &r, &t);       printf( %d n , query(l, r, 1, n, 1, t));       m--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const long long oo = 1LL << 60;   const int N = 10010;   const int E = 200010;   class Graph {    public:     int pnt[E], nxt[E], id[E];     int head[N], nv, ne;     void init(const int v) {       nv = v;       ne = 0;       memset(head, 255, sizeof(head));     }     void add(const int u, const int v, const int i) {       pnt[ne] = v, id[ne] = i, nxt[ne] = head[u], head[u] = ne++;       pnt[ne] = u, id[ne] = i, nxt[ne] = head[v], head[v] = ne++;     }   } ga, gb;   int n, rt;   int dfn[N], low[N], idx;   int stk[N], top;   int belong[N], bcnt;   bool vis[N];   int cnt[N];   void dfs(const Graph &g, int u, int f) {     int i, v, e;     dfn[u] = low[u] = idx++;     stk[++top] = u;     vis[u] = 1;     for (i = g.head[u]; ~i; i = g.nxt[i]) {       v = g.pnt[i], e = g.id[i];       if (dfn[v] < 0) {         dfs(g, v, e);         low[u] = min(low[u], low[v]);       } else if (e != f && vis[v] && low[u] > dfn[v])         low[u] = dfn[v];     }     if (dfn[u] == low[u]) {       do {         v = stk[top--];         vis[v] = 0;         belong[v] = bcnt;       } while (v != u);       bcnt++;     }   }   void bcc(const Graph &g) {     top = bcnt = idx = 0;     memset(dfn, 255, sizeof(dfn));     memset(vis, 0, sizeof(vis));     for (int i = 0; i < g.nv; i++)       if (dfn[i] < 0) dfs(g, i, -1);   }   void find(const Graph &g) {     rt = -1;     int mm = -1;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < g.nv; i++) cnt[belong[i]]++;     for (int i = 0; i < bcnt; i++)       if (cnt[i] > mm) {         mm = cnt[i];         rt = i;       }   }   void shrink(const Graph &ga, Graph &gb) {     int v, cnt = 1;     gb.init(bcnt);     for (int i = 0; i < ga.nv; i++)       for (int j = ga.head[i]; ~j; j = ga.nxt[j])         if (belong[i] != belong[v = ga.pnt[j]])           gb.add(belong[i], belong[v], cnt++);   }   bool in[N];   int Q[N], dist[N];   void spfa(const Graph &g, int src) {     int i, u, v, l, r = 0;     memset(dist, 63, sizeof(dist));     memset(in, 0, sizeof(in));     dist[Q[r++] = src] = 0;     in[src] = 1;     for (l = 0; l != r; l = (l + 1) % N)       for (i = g.head[u = Q[l]], in[u] = 0; ~i; i = g.nxt[i])         if (dist[v = g.pnt[i]] > dist[u] + 1) {           dist[v] = dist[u] + 1;           if (!in[v]) in[Q[r++] = v] = 1, r %= N;         }   }   int main(void) {     scanf( %d , &n);     ga.init(n);     for (int i = 1; i <= n; i++) {       int u, v;       scanf( %d%d , &u, &v);       ga.add(u - 1, v - 1, i);     }     bcc(ga);     find(ga);     shrink(ga, gb);     spfa(gb, rt);     for (int i = 0; i < ga.nv; i++)       printf( %d%c , dist[belong[i]], i == ga.nv - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   namespace _buff {   const size_t BUFF = 1 << 19;   char buff[BUFF], *begin = buff, *end = buff;   char getc() {     if (begin == end) {       begin = buff;       end = buff + fread(buff, 1, BUFF, stdin);     }     return begin == end ? -1 : *begin++;   }   }  // namespace _buff   LL read() {     using namespace _buff;     LL ret = 0;     bool pos = true;     char c = getc();     for (; (c <  0  || c >  9 ) && c !=  - ; c = getc()) {       assert(~c);     }     if (c ==  - ) {       pos = false;       c = getc();     }     for (; c >=  0  && c <=  9 ; c = getc()) {       ret = (ret << 3) + (ret << 1) + (c ^ 48);     }     return pos ? ret : -ret;   }   const size_t N = 1 << 19;   const int MOD = 998244353;   const int ROOT = 3;   int qpow(int base, int e) {     int ret = 1;     for (; e; e >>= 1) {       if (e & 1) ret = 1LL * ret * base % MOD;       base = 1LL * base * base % MOD;     }     return ret;   }   int rmod(int x) {     if (x >= MOD) x -= MOD;     if (x < 0) x += MOD;     return x;   }   void fft(int a[], int lg, int flag) {     static int rev[N], rev_lg = -1;     int n = 1 << lg;     if (lg != rev_lg) {       for (int i = 0; i < n; ++i) {         rev[i] = rev[i >> 1] >> 1 | ((i & 1) << (lg - 1));       }     }     for (int i = 0; i < n; ++i) {       if (i < rev[i]) swap(a[i], a[rev[i]]);     }     for (int m = 1, l = 2; m < n; m <<= 1, l <<= 1) {       int wn = qpow(ROOT, flag ? (MOD - 1) - (MOD - 1) / l : (MOD - 1) / l);       for (int i = 0, j, w, x, y; i < n; i += l) {         for (j = 0, w = 1; j < m; ++j, w = 1LL * w * wn % MOD) {           x = a[i + j];           y = 1LL * w * a[i + j + m] % MOD;           a[i + j] = rmod(x + y);           a[i + j + m] = rmod(x - y);         }       }     }     if (flag) {       int inv = qpow(n, MOD - 2);       for (int i = 0; i < n; ++i) {         a[i] = 1LL * a[i] * inv % MOD;       }     }   }   vector<int> operator*(const vector<int> &a, const vector<int> &b) {     static int aa[N], bb[N], cc[N];     int n = a.size(), m = b.size(), l = n + m - 1, lg = 0;     vector<int> ans(l);     if (static_cast<LL>(n) * m <= 4096) {       static unsigned long long tmp[N];       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           if ((tmp[i + j] += static_cast<unsigned long long>(a[i]) * b[j]) >>               62) {             tmp[i + j] %= MOD;           }         }       }       for (int i = 0; i < l; ++i) {         ans[i] = tmp[i] % MOD;         tmp[i] = 0;       }       return ans;     }     for (; (1 << lg) < l; ++lg) {     }     memset(aa, 0, sizeof(int) << lg);     copy(a.begin(), a.end(), aa);     fft(aa, lg, 0);     memset(bb, 0, sizeof(int) << lg);     copy(b.begin(), b.end(), bb);     fft(bb, lg, 0);     for (int i = 0, _ = 1 << lg; i < _; ++i) {       cc[i] = 1LL * aa[i] * bb[i] % MOD;     }     fft(cc, lg, 1);     copy(cc, cc + l, ans.begin());     return ans;   }   vector<int> operator+(const vector<int> &a, const vector<int> &b) {     const vector<int> &aa = a.size() > b.size() ? a : b;     const vector<int> &bb = a.size() > b.size() ? b : a;     vector<int> ret(aa);     auto it = ret.begin();     auto jt = bb.begin();     for (; jt != bb.end(); ++it, ++jt) {       *it = rmod(*it + *jt);     }     return ret;   }   vector<int> g[N];   int pa[N], dep[N], nxt[N], sz[N];   void dfs1(int u) {     sz[u] = 1;     for (int v : g[u]) {       if (v == pa[u]) continue;       pa[v] = u;       dep[v] = dep[u] + 1;       dfs1(v);       sz[u] += sz[v];       if (sz[v] > sz[nxt[u]]) nxt[u] = v;     }   }   vector<int> polys[N];   pair<vector<int>, vector<int> > solve(const vector<int> &idx, int l, int r) {     if (l + 1 == r) {       return {polys[idx[l]], polys[idx[l]]};     }     int mid = (l + r) >> 1;     auto ans1 = solve(idx, l, mid), ans2 = solve(idx, mid, r);     return {ans1.first + ans2.first * ans1.second, ans1.second * ans2.second};   }   void dfs2(int u) {     assert(!pa[u] || nxt[pa[u]] != u);     vector<int> idx(1, u);     for (int v = nxt[u]; v; v = nxt[v]) {       idx.emplace_back(v);     }     for (int u : idx) {       polys[u] = {0, 1};       for (int v : g[u]) {         if (v == pa[u] || v == nxt[u]) continue;         dfs2(v);         polys[v][0] += 1;         polys[u] = polys[u] * polys[v];       }     }     polys[u] = solve(idx, 0, idx.size()).first;   }   int main() {     int n = read();     LL x = read();     for (int i = 1, a, b; i < n; ++i) {       a = read();       b = read();       g[a].emplace_back(b);       g[b].emplace_back(a);     }     dfs1(1);     dfs2(1);     vector<int> &vc = polys[1];     int ans = 0, mul = 1;     for (unsigned i = 1; i < vc.size(); ++i) {       ans = (ans + 1LL * mul * vc[i]) % MOD;       mul = (x + i) % MOD * qpow(i, MOD - 2) % MOD * mul % MOD;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> s;     for (i = 1; i <= n; i++) {       if (n % i == 0) {         reverse(s.begin(), s.begin() + i);       }     }     cout << s;   }


#include <bits/stdc++.h>   #pragma GCC target( avx )   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   using namespace std;   const int mod = 998244353;   int n, m, x, a[4000005], ans, w[4000005], r[4000005], invn, mx, lenk;   int ksm(int a, int b) {     int s = 1;     while (b > 0) {       if (b & 1) s = (long long)s * a % mod;       a = (long long)a * a % mod, b >>= 1;     }     return s;   }   void pre(int &n) {     int len = 0;     while (1 << len < n) len++;     n = 1 << len;     int G = ksm(3, (mod - 1) / n);     invn = ksm(n, mod - 2);     w[0] = w[n] = 1;     for (int i = 1; i < n; i++)       w[i] = (long long)w[i - 1] * G % mod,       r[i] = (r[i >> 1] >> 1) | ((i & 1) << (len - 1));   }   void fft(int *a, int all, int fl) {     for (int i = 0; i < all; i++)       if (i < r[i]) swap(a[i], a[r[i]]);     int n = 2, m = 1, x = all / 2;     for (; n <= all; m = n, n <<= 1, x >>= 1)       for (int i = 0; i < all; i += n)         for (int k = 0; k < m; k++) {           int t = (long long)w[fl ? all - x * k : x * k] * a[i + m + k] % mod;           a[i + m + k] = (a[i + k] + mod - t) % mod;           a[i + k] = (a[i + k] + t) % mod;         }     if (fl)       for (int i = 0; i < all; i++) a[i] = (long long)a[i] * invn % mod;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , &x), a[x]++, mx = max(mx, x);     lenk = n / 2 * mx + 1;     pre(lenk);     fft(a, lenk, 0);     for (int i = 0; i < lenk; i++) a[i] = ksm(a[i], n / 2);     fft(a, lenk, 1);     for (int i = 0; i <= n / 2 * mx; i++)       ans = (ans + (long long)a[i] * a[i] % mod) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans, k, d, cnt1, cnt2, l, r;   int a[200050];   struct node {     int x, b;   };   node s[200050];   int main() {     k = 1;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     l = 1, r = n, s[0].x = 0;     d = 0;     while ((a[l] > s[d].x || a[r] > s[d].x) && l <= r) {       if (a[l] != a[r]) {         if (a[l] < a[r] && a[l] > s[d].x || (a[l] > a[r] && a[r] <= s[d].x)) {           d++;           s[d].x = a[l];           s[d].b = 0;           ans = d;           l++;           continue;         }         if (a[r] > s[d].x) {           d++;           s[d].x = a[r];           s[d].b = 1;           ans = d;           r--;           continue;         }       }       if (a[l] == a[r] && l != r) {         k = 0;         cnt1 = 0, cnt2 = 0;         for (int j = l; j <= r - 1; ++j) {           if (a[j + 1] > a[j])             cnt1++;           else             break;         }         for (int j = r; j >= l + 1; --j) {           if (a[j] < a[j - 1])             cnt2++;           else             break;         }         if (cnt1 >= cnt2) {           ans += cnt1 + 1;           printf( %d n , ans);           for (int j = 1; j <= ans - cnt1 - 1; ++j) {             if (s[j].b == 0)               printf( L );             else               printf( R );           }           for (int j = 0; j < cnt1 + 1; ++j) {             printf( L );           }           break;         }         if (cnt1 < cnt2) {           ans += cnt2 + 1;           printf( %d n , ans);           for (int j = 1; j <= ans - cnt2 - 1; ++j) {             if (s[j].b == 0)               printf( L );             else               printf( R );           }           for (int j = 0; j < cnt2 + 1; ++j) {             printf( R );           }           break;         }       }       if (l == r && k == 1) {         ans++;         s[ans].b = 1;         break;       }     }     if (k == 1) {       printf( %d n , ans);       for (int i = 1; i <= ans; ++i) {         if (s[i].b == 0)           printf( L );         else           printf( R );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, a[200100], cnt[200100], ans, kol;   set<int> st;   int main() {     cin >> n >> s;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       if (i == s) {         if (a[i] != 0) {           a[i] = 0;           ans++;         }         st.insert(a[i]);         continue;       }       if (a[i] == 0) {         a[i] = n;         kol++;       }       cnt[a[i]]++;       st.insert(a[i]);     }     for (int i = 1; i <= n; ++i) {       if (i > *st.rbegin()) break;       if (cnt[i] == 0) {         int pp = *st.rbegin();         if (cnt[pp] == 1) {           st.erase(pp);         }         ans++;         st.insert(i);         cnt[pp]--;       }     }     cout << max(ans, kol);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int cnt[N * N], par[N][N], sum[N][N], sz[N * N];   char grid[N][N];   int n, k;   int cur = 0;   void change(int id, int add) {     if (id == 0) return;     if (cnt[id]) cur -= sz[id];     cnt[id] += add;     if (cnt[id]) cur += sz[id];   }   void paint(int r, int c, int col) {     if (r < 1 || c < 1 || r > n || c > n) return;     if (grid[r][c] !=  . ) return;     if (par[r][c] != 0) return;     par[r][c] = col;     ++sz[col];     paint(r - 1, c, col);     paint(r + 1, c, col);     paint(r, c - 1, col);     paint(r, c + 1, col);   }   int inside(int r, int c) {     return sum[r + k - 1][c + k - 1] - sum[r - 1][c + k - 1] -            sum[r + k - 1][c - 1] + sum[r - 1][c - 1];   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf(  %c , &grid[i][j]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (grid[i][j] ==  . ) {           if (par[i][j] == 0) {             paint(i, j, i * n + j);           }         }     for (int i = 1; i < N; ++i)       for (int j = 1; j < N; ++j)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +                     (grid[i][j] !=  . );     int ans = 0;     for (int i = 1; i <= n - k + 1; ++i) {       memset(cnt, 0, sizeof(cnt));       cur = 0;       for (int r = i - 1; r <= i + k; ++r)         for (int c = 0; c <= k + 1; ++c) change(par[r][c], 1);       change(par[i - 1][k + 1], -1);       change(par[i + k][k + 1], -1);       ans = max(ans, cur + inside(i, 1));       for (int j = 2; j <= n - k + 1; ++j) {         for (int r = i - 1; r <= i + k; ++r) {           change(par[r][j + k], 1);         }         change(par[i - 1][j + k - 1], +1);         change(par[i + k][j + k - 1], +1);         change(par[i - 1][j - 2], +1);         change(par[i + k][j - 2], +1);         for (int r = i - 1; r <= i + k; ++r) {           change(par[r][j - 2], -1);         }         change(par[i - 1][j + k], -1);         change(par[i + k][j + k], -1);         change(par[i - 1][j - 1], -1);         change(par[i + k][j - 1], -1);         ans = max(ans, cur + inside(i, j));       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool setmax(T &_a, T _b) {     if (_b > _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   bool setmin(T &_a, T _b) {     if (_b < _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   T gcd(T _a, T _b) {     return _b == 0 ? _a : gcd(_b, _a % _b);   }   const int MAXN = 1010;   bool vis[MAXN];   vector<int> es[MAXN];   int n;   int que[MAXN], lst[MAXN], d[MAXN], ss, tt;   void bfs(int start) {     ss = tt = 1;     que[1] = start;     vis[start] = true;     d[start] = 0;     while (ss <= tt) {       int x = que[ss++];       for (int y : es[x])         if (!vis[y]) {           vis[y] = true;           d[y] = d[x] + 1;           que[++tt] = y;         }     }   }   int solve_component(int start) {     bfs(start);     int len = tt;     for (int i = int(1); i <= int(len); ++i) lst[i] = que[i];     int ans = -1;     for (int k = int(1); k <= int(len); ++k) {       for (int i = int(1); i <= int(len); ++i) vis[lst[i]] = false;       bfs(lst[k]);       bool ok = true;       for (int i = int(1); i <= int(tt); ++i) {         int x = que[i];         for (int y : es[x])           if (abs(d[x] - d[y]) != 1) ok = false;       }       if (ok) setmax(ans, d[que[tt]]);     }     return ans;   }   int main() {     int m;     scanf( %d%d , &n, &m);     for (int i = int(1); i <= int(n); ++i) es[i].clear();     for (int i = int(1); i <= int(m); ++i) {       int x, y;       scanf( %d%d , &x, &y);       es[x].push_back(y), es[y].push_back(x);     }     memset(vis, false, sizeof(vis));     int ans = 0;     for (int i = int(1); i <= int(n); ++i)       if (!vis[i]) {         int tmp = solve_component(i);         if (tmp < 0) {           ans = -1;           break;         }         ans += tmp;       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       int n, e;       set<int> v;       map<int, int> m;       cin >> n;       for (long long int i = 0; i < n; i++) {         cin >> e;         m[e]++;         if (m[e] == 1) v.insert(e);       }       int np = 0, ps = 0;       while (!v.empty()) {         ps = 0;         for (map<int, int>::iterator itm = m.begin(); itm != m.end(); itm++) {           while (itm->second != 0 && itm->first >= ps) {             itm->second -= 1;             ps += 1;           }           if (itm->second == 0) v.erase(itm->first);         }         np++;       }       cout << np;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > S;   set<pair<long long, long long> >::iterator it;   set<pair<long long, long long> >::iterator it2;   pair<long long, long long> temp;   void intersect_yes(long long s, long long e) {     if (S.empty()) return;     for (it = S.begin(); it != S.end();) {       if (it->first < s && it->second < s)         S.erase(it++);       else         break;     }     if (S.empty()) return;     bool finish = 0;     for (it = --S.end(); !finish;) {       if (it == S.begin()) finish = true;       if (it->first > e)         S.erase(it--);       else         break;     }     if (S.empty()) return;     temp = *S.begin();     S.erase(temp);     temp.first = max(s, temp.first);     S.insert(temp);     temp = *(--S.end());     S.erase(temp);     temp.second = min(temp.second, e);     S.insert(temp);   }   const long long big = 1LL << 55;   void intersect_no(long long s, long long e) {     it = S.lower_bound(make_pair(s, big));     if (it != S.begin()) it--;     it2 = S.upper_bound(make_pair(e, big));     while (it != it2) {       if (it->second < s)         it++;       else if (it->first < s) {         if (it->second >= s && it->second <= e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(temp.first, s - 1));         } else if (it->second > e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(temp.first, s - 1));           S.insert(make_pair(e + 1, temp.second));         }       } else if (it->first >= s && it->first <= e) {         if (it->second <= e) {           S.erase(it++);         } else if (it->second > e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(e + 1, temp.second));         }       }     }   }   int main() {     int h, q, lvl, ans;     long long l, r;     scanf( %d%d , &h, &q);     long long begining = 1LL << (h - 1), ending = (1LL << h) - 1;     S.insert(make_pair(begining, ending));     for (int i = 0; i < q; i++) {       scanf( %d%I64d%I64d%d , &lvl, &l, &r, &ans);       long long left = l * (1LL << (h - lvl)),                 right = (r + 1) * (1LL << (h - lvl)) - 1;       if (S.empty()) {         printf( Game cheated! n );         return 0;       }       if (ans)         intersect_yes(left, right);       else         intersect_no(left, right);     }     if (S.empty())       printf( Game cheated! n );     else if (S.size() == 1 && (*S.begin()).first == (*S.begin()).second)       printf( %I64d n , (*S.begin()).first);     else       printf( Data not sufficient! n );   }


#include<stdio.h>   #include<bits/stdc++.h>      typedef long long ll;      using namespace std;         int main()   {       ll deva;       cin>>deva;       for(ll ol=0;ol<deva;ol++)       {           int n;           cin>>n;           string s;           cin>>s;           int a[26]={0};           int flag=1;           a[s[0]- A ]+=1;           for(int i=1;i<n;i++)           {               if(a[s[i]- A ]>0 && s[i]!=s[i-1])               {                   flag=0;                   break;               }               a[s[i]- A ]+=1;           }           if(flag)               cout<< YES <<endl;           else                   cout<< NO <<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INF = 1000000007;   string FILENAME =  input ;   string FILEINPUT = FILENAME;   void writeln(int a) { printf( %d n , a); }   void writeln(int a, int b) { printf( %d %d n , a, b); }   void writeln(int a, int b, int c) { printf( %d %d %d n , a, b, c); }   void writeln(int a, int b, int c, int d) {     printf( %d %d %d %d n , a, b, c, d);   }   void write(int a) { printf( %d , a); }   void write(int a, int b) { printf( %d %d , a, b); }   void write(int a, int b, int c) { printf( %d %d %d , a, b, c); }   void write(int a, int b, int c, int d) { printf( %d %d %d %d , a, b, c, d); }   void read(int &a) { scanf( %d , &a); }   void read(int &a, int &b) { scanf( %d %d , &a, &b); }   void read(int &a, int &b, int &c) { scanf( %d %d %d , &a, &b, &c); }   void read(int &a, int &b, int &c, int &d) {     scanf( %d %d %d %d , &a, &b, &c, &d);   }   void readln(int &a) { scanf( %d n , &a); }   void readln(int &a, int &b) { scanf( %d %d n , &a, &b); }   void readln(int &a, int &b, int &c) { scanf( %d %d %d n , &a, &b, &c); }   void readln(int &a, int &b, int &c, int &d) {     scanf( %d %d %d %d n , &a, &b, &c, &d);   }   void readln(vector<int> &f, int n) {     int x;     for (int i = 1; i <= n; i++) {       read(x);       f.push_back(x);     }   }   void writeln(vector<int> &f) {     for (int i = 0; i < f.size(); i++)       printf( %d%c , f[i], i == f.size() - 1 ?   n  :    );   }   void run() {     int n;     vector<int> a;     read(n);     readln(a, n);     sort(a.begin(), a.end());     int i = -1, j = 0, t, mx = 0;     read(t);     while (j != n) {       i++;       while (j < n && a[j] - a[i] <= t) j++;       mx = max(mx, j - i);     }     writeln(mx);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int r;   void solve(int x) {     r = 0;     while (x) {       a[r++] = x % 3;       x /= 3;     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       memset(a, 0, sizeof a);       int n;       scanf( %d , &n);       solve(n);       a[r] = 0;       for (int i = r; i >= 0; i--) {         if (a[i] == 2) {           for (int j = i + 1; j <= r; j++) {             if (a[j] == 1)               a[j] = 0;             else if (a[j] == 0) {               a[j] = 1;               break;             }           }           for (int k = i; k >= 0; k--) a[k] = 0;           break;         }       }       int ans = 0;       for (int i = r; i >= 0; i--) {         ans += a[i] * pow(3, i);       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   int main() {     int n, m1, m2, m3, min1, min2, min3, max1, max2, max3;     scanf( %d%d%d%d%d%d%d , &n, &min1, &max1, &min2, &max2, &min3, &max3);     m1 = n - min2 - min3;     if (m1 <= max1)       printf( %6d %6d %6d , m1, min2, min3);     else {       m2 = min2 + m1 - max1;       if (m2 < max2)         printf( %6d %6d %6d , max1, m2, min3);       else {         m3 = n - max1 - max2;         printf( %6d %6d %6d , max1, max2, m3);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   const long long MAX = -1000000000000000000;   const long long MIN = 1000000000000000000;   const long long inf = 1000000000;   const long long KOK = 100000;   const long long LOG = 30;   const long long li = 500005;   const long long mod = 1000000007;   int n, m, b[li], a[li], k, flag, t, fa[li], si[li], vis[li], visit[li], x[li],       y[li], use[li];   int cev;   queue<int> q;   set<pair<long long, long long> > st;   string s;   vector<int> v[li], vec;   inline int dsu(int x) {     if (x == fa[x]) return x;     return fa[x] = dsu(fa[x]);   }   int main(void) {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= k; i++) {       scanf( %d %d , &x[i], &y[i]);       use[x[i]]++;       use[y[i]]++;       v[x[i]].push_back(i);       v[y[i]].push_back(i);     }     for (int i = 1; i <= k; i++) {       if (use[x[i]] <= a[x[i]] || use[y[i]] <= a[y[i]]) q.push(i);     }     while (q.size()) {       int node = q.front();       q.pop();       if (vis[node]) continue;       vis[node] = 1;       vec.push_back(node);       use[x[node]]--;       use[y[node]]--;       int nodee = node;       node = x[node];       for (int i = 0; i < (int)v[node].size(); i++) {         if ((use[x[v[node][i]]] <= a[x[v[node][i]]] ||              use[y[v[node][i]]] <= a[y[v[node][i]]]) &&             vis[v[node][i]] == 0)           q.push(v[node][i]);       }       node = y[nodee];       for (int i = 0; i < (int)v[node].size(); i++) {         if ((use[x[v[node][i]]] <= a[x[v[node][i]]] ||              use[y[v[node][i]]] <= a[y[v[node][i]]]) &&             vis[v[node][i]] == 0)           q.push(v[node][i]);       }     }     if ((int)vec.size() != k) {       printf( DEAD n );       return 0;     }     printf( ALIVE n );     reverse(vec.begin(), vec.end());     for (int i = 0; i < (int)vec.size(); i++) {       printf( %d  , vec[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MXN = 1e6 + 1;   const long long MNN = 1e3 + 1;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long MAGIC = 1000;   const long double EPS = 1e-9;   const long double PI = 3.1415926536;   const string TIME =  rovno_ushten_push_ketti ;   long long n;   long long cnt[MXN];   set<long long> s;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       s.insert(x);       ++cnt[x];     }     if (s.size() == 2) {       long long x = *s.begin();       s.erase(s.begin());       long long y = *s.begin();       if (cnt[x] == cnt[y]) {         cout <<  YES n ;         cout << x <<     << y;       } else {         cout <<  NO ;       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, ns, ne, v, i;     cin >> n >> m >> ns >> ne >> v;     vector<long long int> s(ns), e(ne);     for (i = 0; i < ns; i++) cin >> s[i];     for (i = 0; i < ne; i++) cin >> e[i];     long long int q;     cin >> q;     while (q--) {       long long int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2) {         cout << abs(y1 - y2) << endl;         continue;       }       long long int ans = INT_MAX, tmp, c;       c = lower_bound(s.begin(), s.end(), y1) - s.begin();       if (c < s.size()) {         tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2);         ans = min(tmp, ans);       }       if (c >= 1) {         c -= 1;         tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2);         ans = min(tmp, ans);       }       c = lower_bound(e.begin(), e.end(), y1) - e.begin();       if (c < e.size()) {         tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2);         ans = min(tmp, ans);       }       if (c >= 1) {         c -= 1;         tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2);         ans = min(tmp, ans);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> mp;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       mp[{a, b}] = 1;       mp[{b, a}] = 1;     }     if (n < 7) {       cout << m << endl;     } else {       long long ans = m;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           long long ctr = 0;           for (long long k = 0; k < n; k++) {             if (mp[{i, k}] == 1 and mp[{j, k}]) {               ctr++;             }           }           ans = min(ans, ctr);         }       }       cout << m - ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long getres(long long n) {     if (n == 0) {       return 0;     }     vector<long long> now;     for (long long i = 0;; i++) {       long long t = pow(2, i);       if (t <= n) {         n -= t;         now.push_back(t);         if (n == 0) {           break;         }       } else {         now.push_back(n);         break;       }     }     long long even = 0, odd = 0;     for (long long i = 0; i < now.size(); i++) {       if (i % 2) {         even = (even + now[i]) % mod;       } else {         odd = (odd + now[i]) % mod;       }     }     long long odd_sum = (((odd) % mod) * (odd % mod)) % mod;     long long even_sum = (((even) % mod) * ((even + 1) % mod)) % mod;     long long res = (odd_sum + even_sum) % mod;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     long long ans = (getres(r) - getres(l - 1) + mod) % mod;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct zero {     int nxt, to;   } edge[200000 << 1];   int head[200000], tot = 0;   void add_edge(int a, int b) {     edge[++tot] = (zero){head[a], b};     head[a] = tot;   }   int n, m, plk, poi, d1, d2, dep[200000], kl[200000], d[200000], op[200000],       h[200000];   bool flag;   void aux(int x, int fa) {     if (dep[x] > plk) plk = dep[x], poi = x;     for (int i = head[x]; i; i = edge[i].nxt) {       int to = edge[i].to;       if (to == fa) continue;       dep[to] = dep[x] + 1;       kl[to] = x;       aux(to, x);     }   }   bool cmp(int a, int b) { return h[a] < h[b]; }   void solve(int x, int fa) {     vector<int> v;     for (int i = head[x]; i; i = edge[i].nxt) {       int to = edge[i].to;       if (to == fa) continue;       v.push_back(to);     }     op[x] = 0;     if (v.size() == 0)       h[x] = op[x] = 0;     else if (v.size() == 1) {       int to = v[0];       solve(to, x);       if (op[to] || h[to]) flag = 0;       op[x] = x, h[x] = h[v[0]] + 1;     } else if (v.size() == 2) {       solve(v[0], x), solve(v[1], x);       if ((op[v[0]] && op[v[1]]) || h[v[0]] != h[v[1]])         flag = 0;       else if (op[v[0]] || op[v[1]])         op[x] = op[v[0]] + op[v[1]];       h[x] = h[v[0]] + 1;     } else if (v.size() == 3) {       solve(v[0], x), solve(v[1], x), solve(v[2], x);       sort(v.begin(), v.end(), cmp);       if (op[v[0]] || op[v[1]] || op[v[2]]) flag = 0;       if (!(h[v[1]] == h[v[0]] && h[v[2]] == h[v[0]] + 1)) flag = 0;       op[x] = x, h[x] = h[v[2]] + 1;     } else       flag = 0;   }   int main() {     scanf( %d , &n);     m = (1 << n) - 2;     for (int i = 1; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       add_edge(a, b), add_edge(b, a);       d[a]++, d[b]++;     }     poi = plk = dep[1] = 0;     aux(1, 0);     d1 = poi;     poi = plk = dep[d1] = kl[d1] = 0;     aux(d1, 0);     d2 = poi;     int poss = d2;     vector<int> syk;     while (poss) {       if (abs(2 * dep[poss] - dep[d2]) <= 1) {         flag = 1;         solve(poss, 0);         if (op[poss] && flag && h[poss] == n - 1) syk.push_back(op[poss]);       }       poss = kl[poss];     }     cout << syk.size() << endl;     sort(syk.begin(), syk.end());     for (int i = 0; i < syk.size(); i++) cout << syk[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> fibton;   void Fib(int n) {     int x = 0, y = 1, z = 0;     fibton.push_back(0);     for (int i = 0; i <= n; i++) {       z = x + y;       fibton.push_back(z);       if (fibton[fibton.size() - 1] >= n) {         break;       }       x = y;       y = z;     }   }   int main() {     int n;     cin >> n;     Fib(n);     for (int i = 0; i < fibton.size(); i++) {       for (int j = i; j < fibton.size(); j++) {         for (int k = j; k < fibton.size(); k++) {           if ((fibton[i] + fibton[j] + fibton[k]) == n) {             cout << fibton[i] <<     << fibton[j] <<     << fibton[k];             return 0;           }         }       }     }     return 0;   }


#include <iostream>   #include <iomanip>   #include <cstdio>   #include <vector>   #include <algorithm>   #include <cmath>   #include <cstring>   #include <cassert>   #include <string>   #include <set>   #include <map>   #include <random>   #include <bitset>   #include <string>   #include <unordered_set>   #include <unordered_map>   #include <deque>   #include <queue>   #define rep(i, n) for (int i = 0; i < (n); i++)   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()      using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;      int main() {     ios_base::sync_with_stdio(0); cin.tie(0);     int k;     string s;     cin >> k >> s;     int n = 1 << k, pos = 0;     vector<int> a(n * 2, 1), num(n * 2), rn(n);     for (int i = k - 1; i >= 0; --i)       rep(j, 1 << i) {         num[(1 << i) + j] = pos;         rn[pos] = (1 << i) + j;         ++pos;       }     auto rel = [&](int v, char c) {       if (c ==  0 )         a[v] = a[v * 2];       else if (c ==  1 )         a[v] = a[v * 2 + 1];       else         a[v] = a[v * 2] + a[v * 2 + 1];     };     for (int i = n - 1; i; --i)       rel(i, s[num[i]]);     int q;     cin >> q;     while (q--) {       int v;       char c;       cin >> v >> c;       --v;       s[v] = c;       v = rn[v];       while (v > 0) {         rel(v, s[num[v]]);         v /= 2;       }       cout << a[1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int lim;   char c[1000];   int g[1000][1000];   int f[1000][1000], pre[1000][1000];   void back(int v, int k) {     int p = pre[v][k];     if (p) {       back(p, k - 1);       printf( + );     }     int i1 = p + 1;     int j1 = v;     for (; i1 < j1; i1++, j1--)       if (c[i1 - 1] != c[j1 - 1]) c[j1 - 1] = c[i1 - 1];     for (int i = p + 1; i <= v; i++) printf( %c , c[i - 1]);   }   int main() {     scanf( %s , c);     scanf( %d , &lim);     for (int i = 1; i < strlen(c); i++)       for (int j = i + 1; j <= strlen(c); j++) {         int i1 = i;         int j1 = j;         for (; i1 < j1; i1++, j1--)           if (c[i1 - 1] != c[j1 - 1]) g[i][j]++;       }     memset(f, 127, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= strlen(c); i++)       for (int j = 0; j < i; j++)         for (int k = 0; k < lim && k <= j; k++)           if (f[j][k] + g[j + 1][i] < f[i][k + 1])             f[i][k + 1] = f[j][k] + g[j + 1][i], pre[i][k + 1] = j;     int min = 2000000000;     int pos = lim + 1;     for (int i = 0; i <= lim; i++)       if (f[strlen(c)][i] < min) {         min = f[strlen(c)][i], pos = i;       }     printf( %d n , min);     back(strlen(c), pos);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int mm = 500050;   int n, ss, tt, kk, m;   int c[1001001], v[1001001];   int g[1001001];   int xx[1001001], yy[1001001], minvv = 0, initi = 0;   long long sum[500500], ti[500500];   vector<int> num[500500];   inline void solve() {     int i = 0;     while (i <= m) {       if (initi - ti[i] <= tt) break;       initi -= ti[i];       minvv += mm;       ++i;     }     memset(xx, 0, sizeof(xx));     int j = 0;     while (j < num[i].size()) {       int vv = num[i][j];       ++xx[1];       --xx[vv + 1];       ++j;     }     int now = i;     i = 1;     while (i <= mm) {       xx[i] += xx[i - 1];       ++i;     }     i = 1;     while (i <= mm) {       ++minvv;       if (initi - xx[i] - sum[now] <= tt) break;       initi -= xx[i] + sum[now];       ++i;     }   }   int main() {     scanf( %d%d%d%d , &n, &kk, &ss, &tt);     int i = 1;     while (i <= n) {       scanf( %d%d , &c[i], &v[i]);       ++i;     }     g[0] = 0;     i = 1;     while (i <= kk) {       scanf( %d , &g[i]);       ++i;     }     g[kk + 1] = ss;     ++kk;     sort(g + 1, g + kk + 1);     i = 1;     while (i <= kk) {       minvv = max(minvv, g[i] - g[i - 1]);       ++i;     }     i = 1;     while (i <= kk) {       int x = minvv - (g[i] - g[i - 1]), y = 2 * (g[i] - g[i - 1]) - minvv;       if (y <= 0) {         initi += g[i] - g[i - 1];       } else {         initi += x + 2 * y;         num[y / mm].push_back(y % mm);         ti[y / mm] += y % mm;         ;       }       ++i;     }     m = 2000000000 / mm;     sum[m + 1] = 0;     i = m;     while (i >= 0) {       sum[i] = sum[i + 1] + num[i + 1].size();       ti[i] += 1ll * sum[i] * mm;       --i;     }     if (initi > tt) solve();     int ans = 2000000000;     i = 1;     while (i <= n) {       if (v[i] >= minvv) ans = min(ans, c[i]);       ++i;     }     if (ans == 2000000000) ans = -1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int n, k;   struct edge {     int v;     edge *nxt;   } g[maxn << 1], *he[maxn];   int cnt;   void add_edge(int a, int b) {     edge *e = g + (++cnt);     e->v = b, e->nxt = he[a];     he[a] = e;   }   bool in[maxn];   int mxs[maxn], dep[maxn], fa[maxn];   int f[maxn][25];   void dfs(int p, int ffa) {     dep[p] = dep[ffa] + 1;     f[p][0] = ffa;     fa[p] = ffa;     for (int i = 1; i <= 20; ++i) f[p][i] = f[f[p][i - 1]][i - 1];     for (edge *e = he[p]; e; e = e->nxt) {       int to = e->v;       if (to == ffa) continue;       dfs(to, p);     }   }   int main() {     scanf( %d%d , &n, &k);     k = n - k;     int a, b;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       add_edge(a, b);       add_edge(b, a);     }     dep[n] = -1;     dfs(n, 0);     k--;     in[n] = true;     int now = n;     for (int i = n - 1; i; --i) {       if (k == 0) break;       int p = i;       for (int j = 20; ~j; --j)         if (!in[f[p][j]] && f[p][j] != 0) {           p = f[p][j];         }       int lc = f[p][0];       if (dep[i] - dep[lc] <= k) {         p = i;         while (!in[p] && p != lc) {           in[p] = true;           p = fa[p];           k--;         }       }     }     vector<int> ans;     for (int i = 1; i <= n; ++i) {       if (!in[i]) ans.push_back(i);     }     for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int t, tot, type[N];   long long r, f[N];   vector<int> son[N];   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   inline char getch() {     char c = getchar();     while (c ==    ) c = getchar();     return c;   }   int solve(int fa) {     char c = getch();     int now = ++tot;     type[now] = 0, son[now].clear();     if (c ==  * ) return f[now] = 1, now;     son[now].push_back(solve(now));     while (1) {       c = getch();       if (c ==  S )         type[now] = 1;       else if (c ==  P )         type[now] = 2;       else         break;       son[now].push_back(solve(now));     }     if (type[now] == 1) {       f[now] = 1e18;       for (auto &v : son[now]) f[now] = min(f[v], f[now]);     } else {       f[now] = 0;       for (auto &v : son[now]) f[now] += f[v];     }     return now;   }   void resolve(int now, long long r) {     if (type[now] == 0) {       printf( %lld  , r);       return;     }     if (type[now] == 1) {       int pos = 0;       long long minV = 1e18;       for (auto &k : son[now])         if (f[k] < minV) minV = f[k], pos = k;       for (auto &k : son[now]) resolve(k, pos == k ? r : 0);       return;     }     for (auto &k : son[now]) resolve(k, r);     return;   }   int main() {     read(t);     while (t--) {       read(r), tot = 0;       int root = solve(0);       printf( REVOLTING  );       resolve(root, r * f[root]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b;     bool operator<(const node& r) const { return r.b < b; }   } e[105];   int dp[10005][105];   int main() {     int n, sum = 0, num = 0, sum2 = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &e[i].a);       sum += e[i].a;     }     for (int i = 0; i < n; i++) {       scanf( %d , &e[i].b);       sum2 += e[i].b;     }     sort(e, e + n);     for (int i = 0; i < n; i++) {       num += e[i].b;       if (num >= sum) {         num = i + 1;         break;       }     }     for (int i = sum2; i >= 0; i--) {       for (int k = num; k >= 0; k--) {         dp[i][k] = -234723846;       }     }     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int k = sum2; k >= e[i].b; k--) {         for (int j = num; j >= 1; j--) {           dp[k][j] = max(dp[k][j], dp[k - e[i].b][j - 1] + e[i].a);         }       }     }     int ans = 0;     for (int i = sum; i <= sum2; i++) {       ans = max(ans, dp[i][num]);     }     printf( %d %d n , num, sum - ans);   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cout << fixed << setprecision(15);     int t;     cin >> t;     for (ll _ = 0, _Len = (t); _ < _Len; ++_) {       ll n;       cin >> n;       vector<ll> a(n);       vector<pair<ll, ll>> sorted;       for (ll i = 0, iLen = (n); i < iLen; ++i) {         cin >> a[i];         sorted.emplace_back(a[i], i);       }       sort(sorted.begin(), sorted.end());       int comp_n = -1, prev_n = -1;       vector<int> num_cnt;       for (auto &[num, index] : sorted) {         if (prev_n < num) {           prev_n = num;           comp_n++;           num_cnt.emplace_back(0);         }         a[index] = comp_n;         num_cnt.back()++;       }       map<int, int> mp;       vector<int> current_cnt(num_cnt.size());       vector<vector<int>> dp(n + 1, vector<int>(3, 1));       int ans = 0;       for (ll i = 0, iLen = (n); i < iLen; ++i) {         current_cnt[a[i]]++;         auto itr1 = mp.find(a[i]), itr2 = mp.find(a[i] - 1);         if (itr1 != mp.end()) {           int j = itr1->second;           dp[i][0] = dp[j][0] + 1;           dp[i][1] = dp[j][1] + 1;           dp[i][2] = dp[j][2] + 1;         }         if (itr2 != mp.end()) {           int j = itr2->second;           dp[i][2] = max(dp[i][2], dp[j][0] + 1);           if (current_cnt[a[i]] == 1) {             dp[i][1] = max(dp[i][1], dp[j][0] + 1);           }           if (num_cnt[a[i] - 1] == current_cnt[a[i] - 1]) {             dp[i][2] = max(dp[i][2], dp[j][1] + 1);           }           if (itr1 == mp.end() && num_cnt[a[i] - 1] == current_cnt[a[i] - 1]) {             dp[i][1] = max(dp[i][1], dp[j][1] + 1);           }         }         ans = max({ans, dp[i][0], dp[i][1], dp[i][2]});         mp[a[i]] = i;       }       cout << n - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 10e-11;   class VagueDouble {    public:     double vd;     VagueDouble() { vd = nan(  ); }     VagueDouble(const double d) { vd = d; }     inline VagueDouble operator-() const { return VagueDouble(-vd); }     inline VagueDouble operator+(const VagueDouble VD) const {       return VagueDouble(vd + VD.vd);     }     inline VagueDouble operator-(const VagueDouble VD) const {       return VagueDouble(vd - VD.vd);     }     inline VagueDouble operator*(const VagueDouble VD) const {       return VagueDouble(vd * VD.vd);     }     inline VagueDouble operator/(const VagueDouble VD) const {       return VagueDouble(vd / VD.vd);     }     inline VagueDouble operator+(const double d) const {       return VagueDouble(vd + d);     }     inline VagueDouble operator-(const double d) const {       return VagueDouble(vd - d);     }     inline VagueDouble operator*(const double d) const {       return VagueDouble(vd * d);     }     inline VagueDouble operator/(const double d) const {       return VagueDouble(vd / d);     }     inline bool operator<(const VagueDouble VD) const {       return vd + EPS < VD.vd && vd + EPS * abs(vd) < VD.vd;     }     inline bool operator>(const VagueDouble VD) const {       return vd - EPS > VD.vd && vd - EPS * abs(vd) > VD.vd;     }     inline bool operator==(const VagueDouble VD) const {       return !(*this < VD.vd) && !(*this > VD.vd);     }     inline bool operator<(const double d) const { return *this < VagueDouble(d); }     inline bool operator>(const double d) const { return *this > VagueDouble(d); }     inline bool operator==(const double d) const {       return *this == VagueDouble(d);     }     inline void operator+=(const VagueDouble VD) { *this = *this + VD; }     inline void operator-=(const VagueDouble VD) { *this = *this - VD; }     inline void operator*=(const VagueDouble VD) { *this = *this * VD; }     inline void operator/=(const VagueDouble VD) { *this = *this / VD; }     inline friend VagueDouble operator+(const double d, const VagueDouble &VD) {       return VagueDouble(d) + VD;     }     inline friend VagueDouble operator-(const double d, const VagueDouble &VD) {       return VagueDouble(d) - VD;     }     inline friend VagueDouble operator*(const double d, const VagueDouble &VD) {       return VagueDouble(d) * VD;     }     inline friend VagueDouble operator/(const double d, const VagueDouble &VD) {       return VagueDouble(d) / VD;     }     inline friend bool operator<(const double d, const VagueDouble &VD) {       return VagueDouble(d) < VD;     }     inline friend bool operator>(const double d, const VagueDouble &VD) {       return VagueDouble(d) > VD;     }     inline friend bool operator==(const double d, const VagueDouble &VD) {       return VagueDouble(d) == VD;     }     inline double to_double() { return vd; }     inline friend std::ostream &operator<<(std::ostream &os,                                            const VagueDouble VD) {       os << VD.vd;       return os;     }     inline friend std::istream &operator>>(std::istream &is, VagueDouble &VD) {       double d;       is >> d;       VD = VagueDouble(d);       return is;     }   };   inline VagueDouble abs(VagueDouble VD) {     return (VD.vd < 0) ? (-VD.vd) : VD.vd;   }   inline VagueDouble sqr(VagueDouble VD) { return VD.vd * VD.vd; }   inline VagueDouble sqr(double d) { return d * d; }   inline VagueDouble sqrt(VagueDouble VD) { return VagueDouble(sqrt(VD.vd)); }   inline bool isnan(VagueDouble VD) { return isnan(VD.vd); }   class P {    private:    public:     VagueDouble x, y;     P() {       x = nan(  );       y = nan(  );     }     P(double _x, double _y) {       x = _x;       y = _y;     }     P(VagueDouble _x, VagueDouble _y) {       x = _x;       y = _y;     }     P operator-() const { return P(-x, -y); }     P operator+(const P p) const { return P(x + p.x, y + p.y); }     P operator-(const P p) const { return P(x - p.x, y - p.y); }     P operator*(const double d) const { return P(x * d, y * d); }     P operator/(const double d) const { return P(x / d, y / d); }     bool operator<(const P &p) const {       return (x == p.x) ? (y < p.y) : (x < p.x);     }     bool operator>(const P &p) const {       return (x == p.x) ? (y > p.y) : (x > p.x);     }     bool operator==(const P &p) const { return (x == p.x) && (y == p.y); }     void operator+=(const P &p) { *this = *this + p; }     void operator-=(const P &p) { *this = *this - p; }     void operator*=(const double &p) { *this = *this * p; }     void operator/=(const double &p) { *this = *this / p; }     VagueDouble operator*(const P p) const { return x * p.x + y * p.y; }     VagueDouble operator^(const P p) const { return x * p.y - y * p.x; }     friend std::ostream &operator<<(std::ostream &os, const P &p) {       os << p.x.vd <<     << p.y.vd;       return os;     }     friend std::istream &operator>>(std::istream &is, P &p) {       double _x, _y;       is >> _x >> _y;       p = P(_x, _y);       return is;     }     VagueDouble length() { return sqrt(x * x + y * y); }   };   inline VagueDouble dist(P p0, P p1) {     return sqrt(sqr(p0.x - p1.x) + sqr(p0.y - p1.y));   }   inline VagueDouble area(P p0, P p1, P p2) {     return abs((p1 - p0) ^ (p2 - p0)) * 0.5;   }   inline bool isnan(P p) { return isnan(p.x); }   VagueDouble distPL(P l0, P l1, P p) {     if (l0 == l1) return dist(l0, p);     return abs((p - l0) ^ (l1 - l0)) / (l1 - l0).length();   }   bool onLine(P l0, P l1, P p) {     if (l0 == l1) return l0 == p;     if (p.x < min(l0.x, l1.x) || max(l0.x, l1.x) < p.x) return false;     if (p.y < min(l0.y, l1.y) || max(l0.y, l1.y) < p.y) return false;     return distPL(l0, l1, p) == 0;   }   P findCross(P a0, P a1, P b0, P b1) {     P a = a0 - a1, b = b0 - b1, res;     VagueDouble den = a ^ b;     if (den == 0) return P();     res.x =         (a.x * b.x * (a0.y - b0.y) + a.x * b.y * b0.x - a.y * b.x * a0.x) / den;     if (res.x < min(a0.x, a1.x) || max(a0.x, a1.x) < res.x) return P();     if (res.x < min(b0.x, b1.x) || max(b0.x, b1.x) < res.x) return P();     res.y =         -(a.y * b.y * (a0.x - b0.x) + a.y * b.x * b0.y - a.x * b.y * a0.y) / den;     if (res.y < min(a0.y, a1.y) || max(a0.y, a1.y) < res.y) return P();     if (res.y < min(b0.y, b1.y) || max(b0.y, b1.y) < res.y) return P();     return res;   }   class Polygon {    private:    public:     vector<P> points;     Polygon() {}     Polygon(vector<P> vec) { points = vec; }     Polygon(long long int num) { points.resize(num); }     long long int size() { return ((long long int)(points).size()); }     P &operator[](long long int pos) { return points[pos]; }     bool onPoly(P p) {       long long int n = ((long long int)(points).size());       for (long long int i = 0; i < ((long long int)(n)); ++i)         if (onLine(points[i], points[(i + 1) % n], p)) return true;       return false;     }     bool inPoly(P p) {       long long int n = ((long long int)(points).size());       if (n == 0) return false;       if (onPoly(p)) return true;       P right_point = p;       for (long long int i = 0; i < ((long long int)(n)); ++i)         right_point.x = max(right_point.x, points[i].x);       if (right_point == p) return false;       long long int cnt = 0;       for (long long int i = 0; i < ((long long int)(n)); ++i) {         P cross = findCross(points[i], points[(i + 1) % n], p, right_point);         if (!isnan(cross)) cnt++;       }       for (long long int i = 0;            i < ((long long int)(((long long int)(points).size()))); ++i)         if (onLine(p, right_point, points[i])) {           VagueDouble dy0 = points[(i - 1 + n) % n].y - p.y;           VagueDouble dy1 = points[(i + 1 + n) % n].y - p.y;           if (dy0 * dy1 < 0) cnt++;         }       return cnt % 2 == 1;     }     friend std::ostream &operator<<(std::ostream &os, Polygon &poly) {       for (long long int i = 0;            i < ((long long int)(((long long int)(poly).size()))); ++i)         os << poly[i] <<    ;       return os;     }     friend std::istream &operator>>(std::istream &is, Polygon &poly) {       for (long long int i = 0;            i < ((long long int)(((long long int)(poly).size()))); ++i)         is >> poly[i];       return is;     }   };   int main() {     long long int n;     cin >> n;     vector<Polygon> base(n, Polygon(3));     for (long long int i = 0; i < ((long long int)(n)); ++i) cin >> base[i];     set<P> seg[10005];     for (long long int i = 0;          i < ((long long int)(((long long int)(base).size()))); ++i)       for (long long int j = 0;            j < ((long long int)(((long long int)(base[i]).size()))); ++j)         seg[i * 3 + j].insert(base[i][(j + 0) % 3]);     for (long long int i = 0;          i < ((long long int)(((long long int)(base).size()))); ++i)       for (long long int j = 0;            j < ((long long int)(((long long int)(base[i]).size()))); ++j)         seg[i * 3 + j].insert(base[i][(j + 1) % 3]);     for (long long int i = 0;          i < ((long long int)(((long long int)(base).size()))); ++i)       for (long long int j = 0;            j < ((long long int)(((long long int)(base[i]).size()))); ++j)         for (long long int k = 0; k < ((long long int)(i)); ++k)           for (long long int l = 0;                l < ((long long int)(((long long int)(base[k]).size()))); ++l) {             if (i == k) continue;             P cross = findCross(base[i][j], base[i][(j + 1) % 3], base[k][l],                                 base[k][(l + 1) % 3]);             if (isnan(cross)) continue;             seg[i * 3 + j].insert(cross);             seg[k * 3 + l].insert(cross);           }     VagueDouble res = 0.0;     vector<P> vec[10005];     for (long long int i = 0;          i < ((long long int)(((long long int)(base).size()))); ++i)       for (long long int j = 0;            j < ((long long int)(((long long int)(base[i]).size()))); ++j)         for (__typeof((seg[i * 3 + j]).begin()) it = (seg[i * 3 + j]).begin();              it != (seg[i * 3 + j]).end(); it++)           vec[i * 3 + j].push_back(*it);     for (long long int i = 0;          i < ((long long int)(((long long int)(base).size()))); ++i)       for (long long int j = 0;            j < ((long long int)(((long long int)(base[i]).size()))); ++j)         for (long long int k = 0;              k < ((long long int)(((long long int)(vec[i * 3 + j]).size()) - 1));              ++k) {           P mid = (vec[i * 3 + j][k] + vec[i * 3 + j][k + 1]) / 2.0;           bool ok = true;           for (long long int l = 0;                l < ((long long int)(((long long int)(base).size()))); ++l)             if (i != l && base[l].inPoly(mid)) {               ok = false;               break;             }           if (ok) res += dist(vec[i * 3 + j][k], vec[i * 3 + j][k + 1]);         }     printf( %0.20lf n , res.to_double());   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T first, T second) {     while (second > 0) {       first %= second;       swap(first, second);     }     return first;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class _T>   inline _T sqr(const _T &first) {     return first * first;   }   template <class _T>   inline string tostr(const _T &a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   template <typename T>   inline void input(T &a) {     static int ed;     a = 0;     while (!isdigit(ed = getchar()) && ed !=  - ) {     }     char neg = 0;     if (ed ==  - ) {       neg = 1;       ed = getchar();     }     while (isdigit(ed)) {       a = 10 * a + ed -  0 ;       ed = getchar();     }     if (neg) a = -a;   }   template <typename T = int>   inline T nxt() {     T res;     input(res);     return res;   }   mt19937 generator;   bool check(int v) {     if (v < 2) return false;     for (int i = 2; i * i <= v; ++i) {       if (v % i == 0) {         return false;       }     }     return true;   }   long long pw(long long a, long long n, long long m) {     long long res = 1;     while (n) {       if (n & 1ll) {         res = res * a % m;       }       a = a * a % m;       n >>= 1;     }     return res;   }   long long bin[5][5];   void pre() {     for (int i = 0; i < 5; ++i) {       bin[i][0] = 1;       for (int j = 1; j <= i; ++j) {         bin[i][j] = bin[i - 1][j] + bin[i - 1][j - 1];       }     }   }   void read() {}   void test() {}   long long mod = 1000000007;   vector<int> g[1 << 20];   int dp[1 << 20];   int solve(int v) {     int &res = dp[v];     if (res != -1) {       return res;     }     res = 1;     for (int to : g[v]) {       if (to < v) {         res = max(res, solve(to) + 1);       }     }     return res;   }   void solve() {     int n = nxt();     int m = nxt();     for (int i = 0; i < m; ++i) {       int u = nxt() - 1;       int v = nxt() - 1;       g[u].push_back(v);       g[v].push_back(u);     }     memset(dp, 255, sizeof(dp));     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, 1ll * solve(i) * (int)g[i].size());     }     cout << ans << endl;   }   void solve2() {}   int main() {     int t = 1;     pre();     while (t--) {       read();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inv = 1000000000;   const int minv = -inv;   const int max_n = 100010;   const int max_m = 100010;   const int max_k = 110;   const int modref = 1000000007;   int n, m;   int a[max_n];   int b[max_n][max_k + 1] = {0};   int c[max_k + 1] = {0};   int bin[max_n + max_k + 1][max_k + 1];   int main() {     for (int i = 0; i <= max_n + max_k; ++i) {       bin[i][0] = 1;       if (i <= max_k) bin[i][i] = 1;       for (int j = 1; j <= min(i - 1, max_k); ++j) {         bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j];         bin[i][j] %= modref;       }     }     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < m; ++i) {       int l, r, k;       scanf( %d , &l);       scanf( %d , &r);       scanf( %d , &k);       --l;       --r;       ++b[l][k];       b[l][k] %= modref;       if (r + 1 < n)         for (int j = 0; j <= k; ++j) {           b[r + 1][j] += (modref - bin[r + 1 - l - 1 + k - j][k - j]);           b[r + 1][j] %= modref;         }     }     for (int i = 0; i < n; ++i) {       int res = a[i];       for (int j = 99; j >= 0; --j) {         c[j] = c[j + 1] + c[j];         c[j] %= modref;       }       for (int j = 100; j >= 0; --j) {         c[j] += b[i][j];         c[j] %= modref;         res += c[j];         res %= modref;       }       printf( %d  , res);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math )   using namespace std;   int f[5020][5020];   inline int Mod(int x) { return x + ((x >> 31) & 998244353); }   int Power(int x, int y) {     int o;     for (o = 1; y; y >>= 1) {       if (y & 1) o = (long long)o * x % 998244353;       x = (long long)x * x % 998244353;     }     return o;   }   int P(int n, int m) {     int i, o;     if (m < 0 || m > n) return 0;     for (i = o = 1; i <= m; i++) o = (long long)o * (n - i + 1) % 998244353;     return o;   }   int main(void) {     int n, m, k;     int i, j, o;     cin >> n >> m >> k;     for (i = f[0][0] = 1; i <= k; i++)       for (j = 1; j <= i; j++)         f[i][j] = Mod(f[i - 1][j - 1] + (long long)f[i - 1][j] * j % 998244353 -                       998244353);     m = Power(m, 998244353 - 2);     for (i = o = 0; i <= k; i++)       o = Mod(o +               (long long)f[k][i] * P(n, i) % 998244353 * Power(m, i) % 998244353 -               998244353);     cout << o << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long INF = 1000 * 1000 * 1000;   const long long int mod = 1000000007;   int dp[100050];   int main() {     std::ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long double d;       cin >> d;       long double a, b, x, y;       x = d * d - 4 * d;       if (x < 0) {         cout <<  N  <<   n ;         continue;       }       x = sqrt(x);       if (d - x < 0) {         cout <<  N  <<   n ;         continue;       }       a = (d + x) / 2.0;       b = (d - x) / 2.0;       cout <<  Y             <<    ;       cout << setprecision(12) << fixed << a <<    ;       cout << setprecision(12) << fixed << b <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int m[120], n, k = 0;   int main() {     cin >> n;     char a, b;     getchar();     for (int i = 1; i < n; i++) {       a = getchar();       b = getchar();       m[a -  a ]++;       if (m[b -  A ] > 0) {         m[b -  A ]--;       } else {         k++;       }     }     cout << k << endl;     return 0;   }


#define _CRT_SECURE_NO_WARNINGS   #include <vector>   #include <string>   #include <map>   #include <queue>   #include <unordered_map>   #include <unordered_set>   #include <cassert>   #include <complex>   #include <cstdio>   #include <iostream>   #include <iomanip>   #include <cmath>   #include <functional>   #include <algorithm>   #include <stack>   #include <numeric>   #include <set>   #include <chrono>   #include <random>      #define all(X) (X).begin(), (X).end()   #define int long long   #define m_p make_pair   #define endl   n    using namespace std;   mt19937_64 rnd(std::chrono::system_clock::now().time_since_epoch().count());      const int MAXN = 1e6 + 100, mod = 1e9 + 7;      int gcd(int a, int b) {    if (b == 0)     return a;    else     return gcd(b, a % b);   }      void extgcd(int a, int b, int &x, int &y) {    if (b == 0) {     x = 1; y = 0;     return;    }    else {     extgcd(b, a % b, x, y);     int temp = y;     y = x - (a / b) * y;     x = temp;    }   }      int inv(int a, int mod) {    int x, y;    extgcd(a, mod, x, y);    x = (x % mod + mod) % mod;    return x;   }      int f[MAXN];      int c(int n, int k) {    if (n < 0 || n < 0 || n - k < 0)     return 0;    return (f[n] * inv(f[n - k] * f[k], mod)) % mod;   }      signed main() {    ios::sync_with_stdio(0);    cin.tie(0);   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);   #endif       int n; cin >> n;    f[0] = 1;    for (int i = 1; i <= n; i++)     f[i] = (f[i - 1] * i) % mod;       int ans = 0;    for (int k = 0; k <= n; k++) {     if ((n - k) % 2)      continue;     ans += (f[n - k] * ((2 * c(n - k - 1, k) + 4 * c(n - k - 1, k - 1)) % mod)) % mod;     ans %= mod;    }    cout << ans;    return 0;   }


#include <bits/stdc++.h>   const long long N = 5e5 + 5;   const int MOD = 1e9 + 7;   using namespace std;   int n;   int a[N];   long long b[N], c[N];   multiset<long long> s;   void xuly() {     cin >> n;     for (int i = (1); i <= (n); ++i) cin >> a[i];     sort(a + 1, a + 1 + n);     cout << (n - 1) / 2 <<   n ;     int top2 = n, top1 = 1;     for (int i = (1); i <= (n); ++i) {       if (i & 1)         cout << a[top2--] <<    ;       else         cout << a[top1++] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     xuly();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct gg {     int a, b, num;   } g[maxn], out[maxn];   bool cmp(gg g1, gg g2) { return g1.a < g2.a || (g1.a == g2.a && g1.b > g2.b); }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> g[i].a >> g[i].b;       g[i].num = i;     }     sort(g, g + m, cmp);     int node = 1;     int flag = 0;     int a = 2, b = 3;     for (int i = 0; i < m; ++i) {       if (g[i].b) {         node++;         out[g[i].num].a = node;         out[g[i].num].b = 1;       } else {         if (1ll * node * (node - 1) / 2ll < i + 1) {           flag = 1;           break;         }         out[g[i].num].a = a;         out[g[i].num].b = b;         if (a == b - 1) {           b++;           a = 2;         } else {           a++;         }       }     }     if (flag) {       cout <<  -1 n ;     } else {       for (int i = 0; i < m; ++i) {         cout << out[i].a <<     << out[i].b << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printArray(T arr, int l) {     for (int i = 0; i < l; i++) cout << arr[i] <<    ;     cout << endl;   }   int main(void) {     int n, k;     cin >> n >> k;     vector<int> floors;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       floors.push_back(temp);     }     sort(floors.begin(), floors.end(), greater<int>());     int done = 0;     long long int cost = 0;     while (done < n) {       cost += 2 * (floors[done] - 1);       done += k;     }     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int t, n, m;   bool check() {     int flag = 1;     for (int i = 1; i < n; i++) {       if (a[i] > a[i + 1]) return 0;     }     return 1;   }   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) cin >> a[i];       set<int> s;       int x;       for (int i = 1; i <= m; i++) {         cin >> x;         s.insert(x);       }       int flag = 1;       while (1) {         if (check()) break;         for (int i = 1; i < n; i++) {           if (a[i] > a[i + 1]) {             set<int>::iterator it = s.lower_bound(i);             if (*it != i) {               flag = 0;               break;             }             swap(a[i], a[i + 1]);           }         }         if (flag == 0) break;       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void rd(T& x) {     int f = 0, c;     while (!isdigit(c = getchar())) f ^= !(c ^ 45);     x = (c & 15);     while (isdigit(c = getchar())) x = x * 10 + (c & 15);     if (f) x = -x;   }   template <typename T>   void pt(T x, int c = -1) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) pt(x / 10);     putchar(x % 10 + 48);     if (c != -1) putchar(c);   }   const int N = 1000005;   const long long INFLL = 0X3F3F3F3F3F3F3F3FLL;   int n, m, p, a[N];   long long sum[N * 4];   vector<long long> v[N * 4];   void upd(int k1, int sz) {     sum[k1] = sum[k1 * 2] + sum[k1 * 2 + 1];     int lsz = (sz + 1) >> 1;     int rsz = sz >> 1;     v[k1].assign(sz + 2, INFLL);     int j = 0;     for (int i = (0); i <= (lsz); ++i) {       if (j > rsz) --j;       for (; j <= rsz; ++j) {         long long tem = v[k1 * 2 + 1][j] + 1LL * i * p - sum[k1 * 2];         long long w = v[k1 * 2][i + 1] - 1 - 1LL * i * p + sum[k1 * 2];         if (w < v[k1 * 2 + 1][j]) {           if (j) --j;           break;         }         v[k1][i + j] = min(v[k1][i + j], max(v[k1 * 2][i], tem));       }     }   }   void bud(int k1, int k2, int k3) {     ((void)0);     if (k2 == k3) {       v[k1].push_back(~INFLL);       v[k1].push_back(p - a[k2]);       v[k1].push_back(INFLL);       sum[k1] = a[k2];       return;     }     int mid = (k2 + k3) >> 1;     bud(k1 * 2, k2, mid), bud(k1 * 2 + 1, mid + 1, k3);     upd(k1, k3 - k2 + 1);   }   long long qry(int k1, int k2, int k3, int k4, int k5, long long k6) {     ((void)0);     if (k2 > k5 || k3 < k4) return k6;     if (k4 <= k2 && k3 <= k5) {       long long pos =           upper_bound(v[k1].begin(), v[k1].end(), k6) - v[k1].begin() - 1;       return k6 - p * pos + sum[k1];     }     int mid = (k2 + k3) >> 1;     return qry(k1 * 2 + 1, mid + 1, k3, k4, k5, qry(k1 * 2, k2, mid, k4, k5, k6));   }   signed main() {     rd(n), rd(m), rd(p);     for (int i = (1); i <= (n); ++i) rd(a[i]);     bud(1, 1, n);     for (int i = (1); i <= (m); ++i) {       int l, r;       rd(l), rd(r);       pt(qry(1, 1, n, l, r, 0),   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int ans[6];     cout <<  ? 1 2  <<   n ;     cout.flush();     double a;     cin >> a;     cout <<  ? 2 3  <<   n ;     cout.flush();     double b;     cin >> b;     map<double, bool> have;     have[4] = 1;     have[8] = 1;     have[15] = 1;     have[16] = 1;     have[23] = 1;     have[42] = 1;     double arr[6] = {4, 8, 15, 16, 23, 42};     for (int i = 0; i < 6; i++) {       if ((have[a / arr[i]] && a / arr[i] != arr[i]) &&           (have[b / arr[i]] && b / arr[i] != arr[i])) {         ans[1] = arr[i];         ans[0] = a / arr[i];         ans[2] = b / arr[i];         break;       }     }     cout <<  ? 4 5  <<   n ;     cout.flush();     double c;     cin >> c;     cout <<  ? 5 6  <<   n ;     cout.flush();     double d;     cin >> d;     for (int i = 0; i < 6; i++) {       if ((have[c / arr[i]] && c / arr[i] != arr[i]) &&           (have[d / arr[i]] && d / arr[i] != arr[i])) {         ans[4] = arr[i];         ans[3] = c / arr[i];         ans[5] = d / arr[i];         break;       }     }     cout <<  !  ;     for (int i = 0; i < 6; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[3505][305];   int a[305], b[305];   const int mod = 1e9 + 7;   int main() {     int n, l;     cin >> n >> l;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i], &b[i]);       dp[a[i]][i]++;       if (a[i] != b[i]) {         a[i + n] = b[i];         b[i + n] = a[i];         dp[a[i + n]][i + n]++;       }     }     for (int i = 1; i <= l; i++) {       for (int j = 0; j < n * 2; j++) {         if (dp[i][j] == 0) continue;         for (int k = 0; k < 2 * n; k++) {           if (k % n != j % n && a[k] == b[j]) {             dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % mod;           }         }       }     }     long long ans = 0;     for (int i = 0; i < n * 2; i++) {       ans = (ans + dp[l][i]) % mod;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   using mseti = multiset<int>;   using mmapii = multimap<int, int>;   inline int int_max() { return numeric_limits<int>::max(); }   inline int int_min() { return numeric_limits<int>::min(); }   inline ll ll_max() { return numeric_limits<ll>::max(); }   inline ll ll_min() { return numeric_limits<ll>::min(); }   inline void fastIO() {     cin.tie(nullptr);     cout.tie(nullptr);     ios_base::sync_with_stdio(0);   }   template <class T>   inline ostream& operator<<(ostream& p, deque<T>& o) {     for (auto& e : o) p << e <<    ;     p <<   n ;     return p;   }   template <class T>   inline istream& operator>>(istream& p, vector<T>& o) {     for (auto& e : o) p >> e;     return p;   }   const int M = 1e9;   const int N = 1e2;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= 2 * n; i++) {       if (2 * n + i <= m) cout << 2 * n + i <<    ;       if (i <= m) cout << i <<    ;     }     cout <<   n ;   }   int main() {     fastIO();     int T = 1;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300007];   int main() {     int n, k;     scanf( %d%d , &n, &k);     string s;     cin >> s;     int sum = 1;     a[0] = 1;     for (int i = (1); i <= (n - 1); ++i) {       if (sum && s[i] ==  . ) a[i] = 1;       sum += a[i];       if (i >= k) sum -= a[i - k];     }     if (a[n - 1])       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1, -1, -1, 1, 1};   int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   int main() {     ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     if (n == 1)       cout << 0;     else if (n <= k)       cout << 1;     else {       n--;       long long mx = k * (k - 1) / 2;       if (n > mx) {         cout << -1;         return 0;       }       long long l = 1, r = k - 1, mid, res;       while (l <= r) {         mid = (l + r) >> 1;         long long sum = mx - mid * (mid - 1) / 2;         if (sum > n)           l = mid + 1;         else           res = mid, r = mid - 1;       }       long long sum = mx - res * (res - 1) / 2;       res = k - res;       if (sum < n) res++;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, f[1000010], a[1000010];   char s[1000010];   bool vis[1000010];   long long Pow(int x) {     if (x < 0) return 0;     if (x == 0) return 1;     long long ans = Pow(x >> 1);     ans = ans * ans % 1000000007ll;     if (x & 1) ans = (ans * 26ll) % 1000000007ll;     return ans;   }   long long ans;   int main() {     scanf( %d%d , &n, &m);     if (m == 0) {       printf( %lld n , Pow(n));       return 0;     }     scanf( %s , s);     int len = strlen(s);     for (int i = 1, j; i < len; i++) {       for (j = f[i]; j && s[i] != s[j]; j = f[j])         ;       f[i + 1] = s[i] == s[j] ? j + 1 : 0;     }     for (int i = f[len]; i; i = f[i]) vis[len - i] = true;     scanf( %d , &a[1]);     a[1]--;     ans = Pow(a[1]);     for (int i = 2; i <= m; i++) {       scanf( %d , &a[i]);       a[i]--;       if (a[i] - a[i - 1] < len) {         if (!vis[a[i] - a[i - 1]]) {           printf( 0 );           return 0;         }       } else         ans = (ans * Pow(a[i] - a[i - 1] - len)) % 1000000007ll;     }     printf( %lld n , ans * Pow(n - a[m] - len) % 1000000007ll);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 511111;   int num[maxn];   int q[maxn];   int main() {     int i, j, n, m, k;     scanf( %d%d , &n, &m);     memset(num, 0, sizeof(num));     num[0] = 1;     for (i = 1; i <= n; i++) {       scanf( %d , &k);       for (j = 500000; j >= k; j--) {         if (num[j - k]) num[j] = 1;       }     }     int tot = 0;     for (i = 0; i <= 500000; i++)       if (num[i]) q[++tot] = i;     q[0] = 0;     int tt = 0;     int ans = 0;     q[++tot] = 1111111111;     for (i = 1; i <= tot;) {       if (q[i] - ans <= m) {         i++;       } else {         i--;         if (ans == q[i]) break;         ans = q[i];         tt++;       }     }     printf( %d %d n , ans, tt);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:134217728 )   using namespace std;   int main() {     int p[4], a, b;     for (int i(0); i <= (4 - 1); ++i) scanf( %d , &p[i]);     scanf( %d%d , &a, &b);     int res(0);     for (int i = a; i <= b; ++i) {       int perm[] = {0, 1, 2, 3};       int k(0);       do {         if (((((i % p[perm[0]]) % p[perm[1]]) % p[perm[2]]) % p[perm[3]]) == i)           ++k;       } while (next_permutation(perm, perm + 4));       if (k >= 7) ++res;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   const long long MOD = 1e9 + 7;   long long dp[MAXN][MAXN], tmp[MAXN][MAXN];   void fillTmp() {     for (int i = 0; i < MAXN; i++) fill(tmp[i], tmp[i] + MAXN, 0);     return;   }   void fillDp() {     for (int i = 0; i < MAXN; i++)       for (int t = 0; t < MAXN; t++) dp[i][t] = tmp[i][t];     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, d;     cin >> n >> k >> d;     dp[0][0] = 1;     long long res = 0;     for (int i = 0; i < MAXN; i++) {       fillTmp();       for (int w = 1; w <= k; w++)         for (int t = 0; t < MAXN; t++)           for (int j = 0; j < MAXN; j++)             if (dp[t][j] != 0 && t + w < MAXN)               tmp[t + w][max(w, j)] = (dp[t][j] + tmp[t + w][max(w, j)]) % MOD;       fillDp();       for (int i = d; i < MAXN; i++) res = (res + dp[n][i]) % MOD;     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1e4 + 10;   int T, n;   int id[N], cnt[10], ans[10];   char s[N];   inline int check(int id) {     int mini = inf;     for (int i = 1; i <= 4; i++) mini = min(mini, cnt[i]);     if (cnt[id] == mini) return 1;     return 0;   }   inline void cal(char *s, int flag) {     memset(cnt, 0, sizeof(cnt));     int len = strlen(s + 1);     for (int i = 1; i <= len; i++) {       if (s[i] ==  G ) cnt[1]++;       if (s[i] ==  H ) cnt[2]++;       if (s[i] ==  R ) cnt[3]++;       if (s[i] ==  S ) cnt[4]++;       if (s[i] ==  ?  && flag == 0) {         int t;         while (1) {           int t = rand() % 4 + 1;           if (check(t)) {             cnt[t]++;             break;           }         }       }     }     int mini = inf;     for (int i = 1; i <= 4; i++) mini = min(mini, cnt[i]);     for (int i = 1; i <= 4; i++)       if (cnt[i] == mini) ans[i] = 1;   }   int main() {     srand(unsigned(time(0)));     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= 4; i++) id[i] = i;     for (int i = 1; i <= 400; i++) cal(s, 0);     if (ans[1]) puts( Gryffindor );     if (ans[2]) puts( Hufflepuff );     if (ans[3]) puts( Ravenclaw );     if (ans[4]) puts( Slytherin );     memset(ans, 0, sizeof(ans));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sum = 0, a = 101;   int main() {     cin >> n;     while (n--) {       cin >> m;       sum += m;       if (m & 1 && m < a) a = m;     }     if (sum & 1)       cout << sum << endl;     else {       if (a == 101)         cout << 0 << endl;       else         cout << sum - a << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const bool debug = false;   const int inf = 1000 * 1000 * 1000;   const int MAKSN = 1000 + 13;   const long long MOD = 123456789LL;   int n, m, k, l, x, y, a, b, p;   string s;   vector<int> v;   void readIn() {     cin >> n >> m >> p;     x = 0;     for (int i = 0; i < (int)n; i++) {       cin >> k;       if (k % p != 0 && x == 0) {         a = i;         x = 1;       }     }     for (int i = 0; i < (int)m; i++) {       cin >> k;       if (k % p != 0) {         cout << a + i <<   n ;         return;       }     }   }   void solve() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     readIn();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[200], pat[20][200];   map<pair<int, int>, int> H[20];   set<pair<int, int> > st;   int a[20], b[20];   int N;   int main() {     int i, j, k, h, len, ans, cnt;     scanf( %s , str);     scanf( %d , &N);     for (i = 0; i < N; i++) scanf( %s%d%d , &pat[i], &a[i], &b[i]);     for (i = 0; i < N; i++) {       len = strlen(pat[i]);       for (j = 0; j < len; j++) {         h = 0;         for (k = j; k < len; k++) {           h = h * 129 + pat[i][k];           if (!H[i].count(pair<int, int>(h, k - j + 1)))             H[i][pair<int, int>(h, k - j + 1)] = 0;           H[i][pair<int, int>(h, k - j + 1)]++;         }       }     }     ans = 0;     len = strlen(str);     for (i = 0; i < len; i++) {       h = 0;       for (j = i; j < len; j++) {         h = h * 129 + str[j];         if (st.find(pair<int, int>(h, j - i + 1)) != st.end()) continue;         st.insert(pair<int, int>(h, j - i + 1));         for (k = 0; k < N; k++) {           if (!H[k].count(pair<int, int>(h, j - i + 1)))             cnt = 0;           else             cnt = H[k][pair<int, int>(h, j - i + 1)];           if (cnt < a[k] || cnt > b[k]) break;         }         if (k == N) ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int lim = 1e6 + 1;   int criba[lim];   void fun_criba(int n) {     for (int i = 2; i <= 2; i++) {       if (criba[i] == 0)         for (int j = i + i; j <= n; j += i) {           criba[j] = i;         }     }     for (int i = 3; i <= n; i += 2) {       if (criba[i] == 0)         for (int j = i + i; j <= n; j += i) {           criba[j] = i;         }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x;     cin >> x;     memset(criba, 0, sizeof criba);     fun_criba(x);     int a = x;     int num = x;     for (int i = x - criba[x] + 1; i < x; i++) {       if (a >= (i - criba[i])) {         a = i - criba[i];         num = i;       }     }     x = num;     if (criba[x] != 0)       num = x - criba[x] + 1;     else       num = x - criba[x];     cout << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long N;     cin >> N;     cout << 3 * (N - 2) - 2 + (N - 4) * (N - 3) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c;   int n, m, cnt, f[3600][3];   bool a[60][60], flag, heng[51][51][51], shu[51][51][51];   bool go(int x1, int y1, int x2, int y2) {     if (heng[x1][min(y1, y2)][max(y1, y2)] && shu[y2][min(x1, x2)][max(x1, x2)])       return true;     if (heng[x2][min(y1, y2)][max(y1, y2)] && shu[y1][min(x1, x2)][max(x1, x2)])       return true;     return false;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         if (c ==  B ) a[i][j] = 1, f[++cnt][1] = i, f[cnt][2] = j;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j]) {           heng[i][j][j] = true;           for (int k = j + 1; k <= m; k++) {             if (a[i][k])               heng[i][j][k] = true;             else               break;           }         }     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++)         if (a[j][i]) {           shu[i][j][j] = true;           for (int k = j + 1; k <= n; k++) {             if (a[k][i])               shu[i][j][k] = true;             else               break;           }         }     flag = true;     for (int i = 1; i < cnt; i++)       for (int j = i + 1; j <= cnt; j++)         if (!go(f[i][1], f[i][2], f[j][1], f[j][2])) {           flag = false;           break;         }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (int)1e3 + 6;   int n, ax, ay, cx, cy, bx, by;   int dirx8[] = {0, 0, 1, -1, 1, -1, 1, -1};   int diry8[] = {1, -1, 0, 0, 1, -1, -1, 1};   bool vis[MX][MX];   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool vaild(int &x, int &y) {     if (x < 1 || x > n || y < 1 || y > n || vis[x][y] || x == ax || y == ay ||         x + y - 1 == ax + ay - 1 || x + (n - y + 1) - 1 == ax + (n - ay + 1) - 1)       return false;     return true;   }   int main() {     cin >> n;     cin >> ax >> ay;     cin >> bx >> by;     cin >> cx >> cy;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         vis[i][j] = false;       }     }     vis[bx][by] = true;     queue<pair<int, int>> q;     q.push({bx, by});     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       if (p.first == cx && p.second == cy) {         cout <<  YES ;         return 0;       }       for (int k = 0; k < 8; k++) {         int px = p.first + dirx8[k], py = p.second + diry8[k];         if (vaild(px, py)) {           vis[px][py] = true;           q.push({px, py});         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using vi = vector<int>;   using ll = long long;   vi prefix_function(string &s) {     int n = int((s).size()), j = 0;     vi pre(n);     for (int i = int(1); i < int(n); i++) {       while (j > 0 && s[i] != s[j]) j = pre[j - 1];       pre[i] = s[i] == s[j] ? ++j : j;     }     return pre;   }   vector<vi> kmp_automaton(string &s) {     s +=  # ;     int n = int((s).size());     vi pre = prefix_function(s);     vector<vi> aut(n, vi(26));     for (int i = int(0); i < int(n); i++)       for (int c = int(0); c < int(26); c++) {         if (i > 0 &&  a  + c != s[i])           aut[i][c] = aut[pre[i - 1]][c];         else           aut[i][c] = i + ( a  + c == s[i]);       }     return aut;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string t, s;     cin >> t >> s;     int m = int((t).size()), n = int((s).size());     vector<vi> aut = kmp_automaton(s), dp(m + 1, vi(n + 1));     for (int i = int(m - 1); i >= int(0); i--)       for (int j = int(0); j < int(n + 1); j++) {         int &x = dp[i][j];         if (t[i] ==  ? ) {           for (int c = int(0); c < int(26); c++) {             int v = aut[j][c];             x = max(x, dp[i + 1][v] + (v == n));           }         } else {           int v = aut[j][int(t[i] -  a )];           x = dp[i + 1][v] + (v == n);         }       }     cout << dp[0][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   int n, m, d;   pair<long long, long long> a[N];   deque<pair<long long, long long> > D;   int res;   int ans[N];   void Input() {     cin >> n >> m >> d;     for (int i = 1; i <= (int)n; i++) {       cin >> a[i].first;       a[i].second = i;     }   }   void Process() {     sort(a + 1, a + 1 + n);     res = 1;     int t = 2;     D.push_back(pair<long long, long long>(a[1].first, 1));     ans[a[1].second] = 1;     while (t <= n) {       if (a[t].first - D.front().first >= d + 1) {         D.push_back(pair<long long, long long>(a[t].first, D.front().second));         ans[a[t].second] = D.front().second;         D.pop_front();       } else {         ++res;         D.push_back(pair<long long, long long>(a[t].first, res));         ans[a[t].second] = res;       }       ++t;     }     cout << res << endl;     for (int i = 1; i <= (int)n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     Input();     Process();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int maxn5 = 3e5 + 10;   const int maxn3 = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 2e18;   int a[maxn5], righ[24][maxn5], lef[24][maxn5];   int mn[18][maxn5], mx[18][maxn5], n, ans[maxn5], l[maxn5], r[maxn5];   void rmq(int k) {     for (int i = 0; i < 3 * n; i++) {       mn[0][i] = i - lef[k][i % n];       mx[0][i] = i + righ[k][i % n];     }     for (int i = 1; i < 18; i++) {       for (int j = 0; j < 3 * n and (j + (1 << i) - 1) < 3 * n; j++) {         mn[i][j] = min(mn[i - 1][j], mn[i - 1][j + (1 << (i - 1))]);         mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << (i - 1))]);       }     }     return;   }   int get_left(int l, int r) {     int k = 31 - __builtin_clz(r - l + 1);     return min(mn[k][l], mn[k][r - (1 << k) + 1]);   }   int get_right(int l, int r) {     int k = 31 - __builtin_clz(r - l + 1);     return max(mx[k][l], mx[k][r - (1 << k) + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < 3 * n; i++) lef[0][i] = a[i % n], righ[0][i] = a[i % n];     for (int i = 1; i < 18; i++) {       rmq(i - 1);       for (int j = 0; j < n; j++) {         if (lef[i - 1][j] >= n or righ[i - 1][j] >= n) {           lef[i][j] = maxn;           righ[i][j] = maxn;           continue;         }         lef[i][j] =             n + j - get_left(n + j - lef[i - 1][j], n + j + righ[i - 1][j]);         righ[i][j] =             get_right(n + j - lef[i - 1][j], n + j + righ[i - 1][j]) - j - n;       }     }     for (int i = 0; i < n; i++) l[i] = i + n, r[i] = i + n;     for (int i = 17; i >= 0; i--) {       rmq(i);       for (int j = 0; j < n; j++)         if (get_right(l[j], r[j]) - get_left(l[j], r[j]) < n) {           int a = get_left(l[j], r[j]);           int b = get_right(l[j], r[j]);           l[j] = a, r[j] = b;           ans[j] += (1 << i);         }     }     for (int i = 0; i < n; i++)       cout << ans[i] + (r[i] - l[i] < n - 1 ? 1 : 0) <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vvx;   vector<pair<int, int> > vvz;   bool contained(int a, int b, int c, int d) {     if (c <= b && d >= a)       return true;     else       return false;   }   int main() {     int p, q, l, r;     cin >> p >> q >> l >> r;     vvx.resize(p + 1);     vvz.resize(q + 1);     for (int i = 0; i < p; i++) {       cin >> vvx[i].first >> vvx[i].second;     }     for (int i = 0; i < q; i++) {       cin >> vvz[i].first >> vvz[i].second;     }     int res = 0;     bool ok = false;     for (int i = l; i <= r; i++) {       ok = false;       for (int j = 0; j < p; j++) {         if (ok) {           ok = false;           break;         }         for (int k = 0; k < q; k++) {           if (contained(vvx[j].first, vvx[j].second, vvz[k].first + i,                         vvz[k].second + i)) {             ok = true;             res++;             break;           }         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pint = pair<int, int>;   using pll = pair<ll, ll>;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     ll n, m;     cin >> n >> m;     vector<ll> a(n);     for (ll i = 0; i < (ll)n; i++) cin >> a[i];     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     ll sum = 0;     for (ll i = 0; i < (ll)n; i++) sum += a[i];     if (sum < m) {       cout << -1 << endl;       return 0;     }     ll l = 0, r = n;     while (r - l > 1) {       ll mid = (l + r) / 2;       ll power = 0;       ll cnt = 0, cost = 0;       for (ll i = 0; i < (ll)n; i++) {         if (a[i] < cost) break;         power += a[i] - cost;         cnt++;         if (cnt == mid) {           cnt = 0;           cost++;         }       }       if (power >= m)         r = mid;       else         l = mid;     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using std::abs;   using std::array;   using std::cerr;   using std::cin;   using std::cout;   using std::generate;   using std::make_pair;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::pair;   using std::reverse;   using std::set;   using std::sort;   using std::string;   using std::unique;   using std::vector;   template <typename T>   T input() {     T res;     cin >> res;     return res;   }   template <typename IT>   void input_seq(IT b, IT e) {     std::generate(b, e,                   input<typename std::remove_reference<decltype(*b)>::type>);   }   int main() {     std::iostream::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     string st;     cin >> st;     int prev = -1;     int ans = -10;     int i = 0;     for (char ch : st) {       char tmp[6] = { A ,  E ,  I ,  O ,  U ,  Y };       if (std::find(tmp, tmp + 6, ch) != tmp + 6) {         ans = max(ans, i - prev);         prev = i;       }       ++i;     }     ans = max(ans, int((st).size()) - prev);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long phi(long long x) {     long long ret = 1;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         ret *= i - 1;         x /= i;         while (x % i == 0) x /= i, ret *= i;       }     }     if (x > 1) ret *= x - 1;     return ret;   }   int main() {     scanf( %I64d%I64d , &n, &k);     if (k % 2 == 0) k--;     while (k != -1 && n != 1) {       n = phi(n);       k -= 2;     }     printf( %I64d n , n % 1000000007ll);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[2];   long long fac[2];   void sieve() {     spf[1] = 1;     for (long long i = 2; i < 2; i++) spf[i] = i;     for (long long i = 4; i < 2; i += 2) spf[i] = 2;     for (long long i = 3; i * i < 2; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < 2; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   map<long long, long long> getfactor(long long a) {     map<long long, long long> m;     while (a > 1) {       m[spf[a]]++;       a /= spf[a];     }     return m;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long inverse(long long a, long long p) { return power(a, p - 2, p); }   long long ncr(long long n, long long r, long long p) {     if (r == 0) return 1;     return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > v;     multiset<long long> s;     long long a[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> a[i];       s.insert(a[i]);     }     long long flag = 0;     for (long long i = 0; i < m; i++) {       long long t, r;       cin >> t >> r;       if (v.size()) {         while (v[v.size() - 1].first <= r) {           v.pop_back();           if (v.size() == 0) break;         }       }       v.push_back(make_pair(r, t));     }     v.push_back(make_pair(0, 0));     long long j = 0, cur = 0;     for (long long i = n; i >= 1; i--) {       if (i == v[j].first) {         flag++;         cur = v[j].second;         j++;       }       if (flag) {         if (cur == 1) {           auto it = s.end();           it--;           a[i] = *it;           s.erase(it);         } else {           auto it = s.begin();           a[i] = *it;           s.erase(it);         }       } else         s.erase(s.find(a[i]));     }     for (long long i = 1; i <= n; i++) cout << a[i] <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }