#include <bits/stdc++.h>   using namespace std;   const int inf = 999999999;   int n;   template <typename T>   struct SegTree_t {     int n;     vector<int> tree, A;     SegTree_t(int _n) : n(_n), tree(4 * n, 0), A(4 * n, 0) {}     T operation(const T &a, const T &b) { return max(a, b); }     T query(int node, int l, int r, int a, int b) {       if (a > r || b < l) return 0;       if (l >= a && r <= b) return tree[node];       return operation(query(node << 1, l, (l + r) / 2, a, b),                        query((node << 1) + 1, (l + r) / 2 + 1, r, a, b));     }     T query(int a, int b) { return query(1, 0, n - 1, a, b); }     void update(int node, int l, int r, int idx, int val) {       if (l == r) {         A[idx] = val;         tree[node] = val;       } else {         int mid = (l + r) / 2;         if (l <= idx and idx <= mid)           update(node << 1, l, mid, idx, val);         else           update((node << 1) + 1, mid + 1, r, idx, val);         tree[node] = operation(tree[(node << 1)], tree[(node << 1) + 1]);       }     }     void update(int idx, int val) { return update(1, 0, n - 1, idx, val); }   };   int main() {     scanf( %d , &n);     int ret = 0;     SegTree_t<int> segtree(n);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       int y = segtree.query(0, x - 1);       ret = max(ret, y + 1);       segtree.update(x, y + 1);     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<int, int> ar[3001];   const long long INF = 1000000000000000;   long long dp[3001][3001];   int func(int pos, int pre) {     if (pos > n) return 0;     if (dp[pos][pre] != -INF) return dp[pos][pre];     int x = ar[pos].second + func(pos + 1, pos);     int y = abs(ar[pos].first - ar[pre].first) + func(pos + 1, pre);     return dp[pos][pre] = min(x, y);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> ar[i].first >> ar[i].second;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) dp[i][j] = -INF;     }     sort(ar + 1, ar + n + 1);     long long ans = func(2, 1) + ar[1].second;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6, mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, sum = 0;     cin >> n;     long long x;     long long nm = 0;     for (long long i = 0; i < n; i++) {       cin >> x;       nm = max(nm, x);       sum += x;     }     if (sum % (n - 1) == 0)       sum = sum / (n - 1);     else       sum = sum / (n - 1) + 1;     cout << max(sum, nm) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 30007;   const int MAXD = 6;   const int MOD = 998244353;   int n, d;   int a[MAXN][MAXD][MAXD];   int tmp[MAXD][MAXD];   int ans[MAXN];   int m1[MAXN], m2[MAXN];   map<vector<int>, int> mp;   map<vector<int>, int>::iterator it;   void init();   void input();   void work();   vector<int> gauss(int a[][MAXD]);   int add(int x, int y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   void addv(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   int dec(int x, int y) {     x -= y;     if (x < 0) x += MOD;     return x;   }   void decv(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   int qpow(int a, int b) {     long long base = a, ans = 1;     while (b) {       if (b & 1) (ans *= base) %= MOD;       (base *= base) %= MOD;       b >>= 1;     }     return static_cast<int>(ans);   }   int main() {     init();     input();     work();   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d%d , &n, &d);     int nk;     for (int i = 1; i <= n; ++i) {       scanf( %d , &nk);       for (int j = 1; j <= nk; ++j) {         for (int k = 1; k <= d; ++k) scanf( %d , &a[i][j][k]);       }     }   }   void work() {     int kc = 0;     vector<int> v;     for (int i = 1; i <= n; ++i) {       v = gauss(a[i]);       if ((it = mp.find(v)) == mp.end())         mp[v] = ans[i] = ++kc;       else         ans[i] = it->second;     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     putchar(  n );   }   vector<int> gauss(int a[][MAXD]) {     for (int i = 1; i <= d; ++i) m1[i] = m2[i] = 0;     for (int i = 1; i <= d; ++i)       for (int j = 1; j <= d; ++j) tmp[i][j] = (a[i][j] + MOD) % MOD;     long long g;     int ni = 1;     for (int i = 1; i <= d; ++i) {       for (int j = ni; j <= d; ++j) {         if (tmp[j][i]) {           for (int k = 1; k <= d; ++k) swap(tmp[ni][k], tmp[j][k]);         }       }       if (tmp[ni][i]) {         m1[ni] = i, m2[i] = ni;         for (int j = ni + 1; j <= d; ++j) {           g = qpow(tmp[ni][i], MOD - 2) * static_cast<long long>(tmp[j][i]) % MOD;           for (int k = i; k <= d; ++k) decv(tmp[j][k], g * tmp[ni][k] % MOD);         }         ++ni;       }     }     for (int i = ni - 1; i > 0; --i) {       for (int j = m1[i] + 1; j <= d; ++j) {         if (m2[j]) {           g = qpow(tmp[m2[j]][j], MOD - 2) * static_cast<long long>(tmp[i][j]) %               MOD;           for (int k = j; k <= d; ++k) decv(tmp[i][k], tmp[m2[j]][k] * g % MOD);         }       }     }     for (int i = 1; i < ni; ++i) {       g = qpow(tmp[i][m1[i]], MOD - 2);       for (int j = m1[i]; j <= d; ++j)         tmp[i][j] = static_cast<long long>(tmp[i][j]) * g % MOD;     }     vector<int> ans;     for (int i = 1; i < ni; ++i)       for (int j = 1; j <= d; ++j) ans.push_back(tmp[i][j]);     return ans;   }


#include <bits/stdc++.h>   using namespace std;   int a[150005];   int main() {     int n, k, q;     scanf( %d %d %d , &n, &k, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     multiset<int> t;     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d %d , &x, &y);       if (x == 1) {         t.insert(a[y]);         if ((int)t.size() > k) {           t.erase(t.begin());         }       } else {         auto it = t.find(a[y]);         printf(it != t.end() ?  YES n  :  NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const int LG = 20;   int go[N][LG];   int a[N];   int last[LG];   int main() {     int n, qq;     scanf( %d %d , &n, &qq);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     for (int i = 0; i < LG; i++) {       go[n][i] = n;       last[i] = n;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < LG; j++) {         go[i][j] = n;       }       for (int j = 0; j < LG; j++) {         if ((a[i] >> j) & 1) {           for (int k = 0; k < LG; k++) {             go[i][k] = min(go[i][k], go[last[j]][k]);           }           last[j] = i;           go[i][j] = i;         }       }     }     while (qq--) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       bool ok = false;       for (int i = 0; i < LG; i++) {         ok |= (((a[y] >> i) & 1) && go[x][i] <= y);       }       puts(ok ?  Shi  :  Fou );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     long long k;     cin >> k;     vector<int> a(n);     int i;     int mx_pos = -1;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == n) {         mx_pos = i;       }     }     int p1 = -1, p2 = -1;     long long w = 0;     for (i = 0; w < k && i < mx_pos; i++) {       if (p1 == -1) {         p1 = a[i];       } else if (p2 == -1) {         p2 = a[i];       }       if (p2 != -1) {         if (p1 < p2) {           p1 = p2;           p2 = -1;           w = 1;         } else {           p2 = -1;           w++;         }       }     }     if (w == k) {       cout << p1;     } else {       cout << n;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long d, n, m;     cin >> d >> n >> m;     vector<pair<long long, long long> > stations(m + 2);     stations[0] = pair<long long, long long>(0, 0);     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       stations[i] = pair<long long, long long>(x, y);     }     stations[m + 1] = pair<long long, long long>(d, 0);     sort(stations.begin(), stations.end());     long long cost = 0, current = n, i = 0;     while (i < m + 1) {       bool found = false;       int last = i + 1;       while (stations[last].first <= stations[i].first + n) {         if (stations[last].second <= stations[i].second) {           int needed =               max(0LL, stations[last].first - stations[i].first - current);           current += needed - stations[last].first + stations[i].first;           cost += needed * stations[i].second;           i = last;           if (last == m + 1) {             cout << cost << endl;             return 0;           }           found = true;         }         last++;       }       if (!found) {         if (last == i + 1) {           cout << -1 << endl;           return 0;         }         cost += (n - current) * stations[i].second;         current = n - (stations[i + 1].first - stations[i].first);         i++;       }     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 3e5 + 5;   vector<int> ic[MAX];   vector<int> adj[MAX];   int used[MAX];   int cn;   vector<int> tr;   int ans[MAX];   void dfs(int s, int p) {     for (int i = 0; i < ic[s].size(); i++) {       int u = ic[s][i];       if (!ans[u] || used[ans[u]]) {         tr.push_back(u);       } else {         used[ans[u]] = 1;       }     }     int cur = 1;     for (int i = 0; i < tr.size(); i++) {       int u = tr[i];       while (used[cur]) {         cur++;       }       ans[u] = cur;       cur++;     }     cn = max(cn, cur);     tr.clear();     for (int i = 0; i < ic[s].size(); i++) {       int u = ic[s][i];       used[ans[u]] = 0;     }     for (int i = 0; i < adj[s].size(); i++) {       int u = adj[s][i];       if (u != p) {         dfs(u, s);       }     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       int cnt;       scanf( %d , &cnt);       for (int j = 1; j <= cnt; j++) {         int a;         scanf( %d , &a);         ic[i].push_back(a);       }     }     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     if ((cn - 1) == 0) {       printf( 1 n );       for (int i = 1; i <= m; i++) {         printf( 1  );       }     } else {       printf( %d n , cn - 1);       for (int i = 1; i <= m; i++) {         if (ans[i] == 0) {           ans[i] = 1;         }         printf( %d  , ans[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const int Max = 256;   const int MaxE = Max * 2;   struct edge {     int to;     edge *s;   };   edge E[MaxE], *hd[Max], *cp;   int n, k, D[Max];   int mp[Max][Max];   int F[Max][Max];   int A[Max], R[Max];   void addEdge(int x, int y) { cp->to = y, cp->s = hd[x], hd[x] = cp++; }   inline void update(int &r, int d) {     if (d < r) r = d;   }   void dfs(int x, int f) {     for (edge *p = hd[x]; p; p = p->s)       if (p->to != f) dfs(p->to, x);     for (int i = 1; i <= n; i++) {       int &cr = F[x][i] = 0;       int dx = mp[x][i];       for (edge *p = hd[x]; p; p = p->s)         if (p->to != f) {           int y = p->to;           cr += dx < mp[y][i] ? min(R[y], F[y][i]) : F[y][i];         }       cr += D[dx];       if (x == i) cr += k;       if (dx < mp[f][i]) update(R[x], cr);     }   }   void aDfs(int x, int f, int g) {     if (g == 0) {       for (int i = 1; i <= n; i++)         if (mp[x][i] < mp[f][i] && F[x][i] == R[x]) {           aDfs(x, f, i);           return;         }     }     A[x] = g;     for (edge *p = hd[x]; p; p = p->s)       if (p->to != f) {         int y = p->to;         aDfs(y, x, mp[x][g] < mp[y][g] && R[y] < F[y][g] ? 0 : g);       }   }   int main() {     while (scanf( %d%d , &n, &k) != EOF && n) {       for (int i = 1; i < n; i++) scanf( %d , &D[i]);       D[n] = oo;       memset(hd, 0, sizeof(hd));       memset(mp, 0x3f, sizeof(mp));       cp = E;       for (int i = 1; i < n; i++) {         int x, y;         scanf( %d%d , &x, &y);         mp[x][y] = mp[y][x] = 1;         addEdge(x, y);         addEdge(y, x);       }       for (int z = 1; z <= n; z++)         for (int x = 1; x <= n; x++)           for (int y = 1; y <= n; y++) update(mp[x][y], mp[x][z] + mp[z][y]);       for (int x = 1; x <= n; x++) mp[x][x] = 0;       memset(R, 0x3f, sizeof(R));       dfs(1, 0);       printf( %d n , R[1]);       aDfs(1, 0, 0);       for (int i = 1; i <= n; i++) printf( %d%c , A[i], i == n ?   n  :    );     }   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 2000000000;   long long INFF = 8000000000000000000LL;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   inline string IntToString(int a) {     char x[100];     sprintf(x,  %d , a);     string s = x;     return s;   }   inline int StringToInt(string a) {     char x[100];     int res;     strcpy(x, a.c_str());     sscanf(x,  %d , &res);     return res;   }   inline string GetString(void) {     char x[1000005];     scanf( %s , x);     string s = x;     return s;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int k, n = 500;   int sisa[1005];   void process(int a, int b) {     sisa[a] = k - 1;     for (int(i) = (a + 1); (i) <= (b); ++(i)) sisa[i] = k;     for (int(i) = (a); (i) <= (b); ++(i)) {       vector<pair<int, int> > besar;       for (int(j) = (i + 1); (j) <= (b); ++(j))         if (i != j) besar.push_back(make_pair(sisa[j], j));       sort(besar.begin(), besar.end());       reverse(besar.begin(), besar.end());       for (int(j) = (0); (j) < (sisa[i]); ++(j)) {         printf( %d %d n , i, besar[j].second);         --sisa[besar[j].second];       }       sisa[i] = 0;     }   }   int main() {     scanf( %d , &k);     if (k == 1) {       puts( YES );       puts( 2 1 );       puts( 1 2 );       return 0;     }     if (k % 2 == 0) {       puts( NO );       return 0;     }     puts( YES );     printf( %d %d n , n, (k * n) / 2);     process(1, n / 2 - 1);     process(n / 2, n);     printf( %d %d n , 1, n / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q;     scanf( %d %d , &n, &q);     string s;     cin >> s;     int size = s.size();     int cnt = 0;     for (int i = 1; i < size; i++) {       if (s[i] ==  .  && s[i] == s[i - 1]) cnt++;     }     while (q--) {       int n1;       char x;       scanf( %d %c , &n1, &x);       n1--;       if (isalpha(x) == isalpha(s[n1]))         ;       else if (x ==  .  && s[n1] !=  . ) {         if (n1 < n - 1)           if (s[n1 + 1] ==  . ) cnt++;         if (n1 > 0)           if (s[n1 - 1] ==  . ) cnt++;       } else {         if (n1 < n - 1)           if (s[n1 + 1] ==  . ) cnt--;         if (n1 > 0)           if (s[n1 - 1] ==  . ) cnt--;       }       s[n1] = x;       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int u[1005], v[1005], fa[1005], n, m, k;   bool zt[1005][1005];   int getv(int x) {     if (x == fa[x]) return x;     fa[x] = getv(fa[x]);     return fa[x];   }   void merge(int x, int y) {     x = getv(x);     y = getv(y);     if (x == y) return;     if (x < y) {       int t = x;       x = y;       y = t;     }     fa[x] = y;     for (int i = 1; i <= m; i++) {       if (zt[x][i]) zt[y][i] = true;     }   }   unsigned long long ha(char zf[1005]) {     unsigned long long rt = 0;     for (int i = 0; zf[i]; i++) rt = rt * 13131 + zf[i];     return rt;   }   map<unsigned long long, int> mp;   char zf[1005];   int wz[1005], rw[1005], yw[1005];   int w2[1005], r2[1005], y2[1005];   bool b1[1005], b2[1005];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) scanf( %d%d , &u[i], &v[i]);     for (int i = 1; i <= k; i++) {       int a, s;       scanf( %s%d%d , zf, &a, &s);       rw[i] = a;       mp[ha(zf)] = i;       for (int j = 0; j < s; j++) {         int b;         scanf( %d , &b);         zt[a][b] = 1;         yw[b] = a;       }     }     for (int a = 1; a <= m; a++) {       for (int i = 1; i <= m; i++) {         if (!b1[i] && (zt[getv(u[i])][i] || zt[getv(v[i])][i])) {           merge(u[i], v[i]);           b1[i] = true;         }       }     }     for (int i = 1; i <= n; i++) wz[i] = getv(i);     for (int i = 1; i <= m; i++) yw[i] = getv(yw[i]);     for (int i = 1; i <= k; i++) rw[i] = getv(rw[i]);     for (int i = 1; i <= n; i++) {       fa[i] = i;       for (int j = 1; j <= m; j++) zt[i][j] = 0;     }     for (int i = 1; i <= k; i++) {       int a, s;       scanf( %s%d%d , zf, &a, &s);       r2[mp[ha(zf)]] = a;       for (int j = 0; j < s; j++) {         int b;         scanf( %d , &b);         zt[a][b] = 1;         y2[b] = a;       }     }     for (int a = 1; a <= m; a++) {       for (int i = 1; i <= m; i++) {         if (!b2[i] && (zt[getv(u[i])][i] || zt[getv(v[i])][i])) {           merge(u[i], v[i]);           b2[i] = true;         }       }     }     for (int i = 1; i <= n; i++) w2[i] = getv(i);     for (int i = 1; i <= m; i++) y2[i] = getv(y2[i]);     for (int i = 1; i <= k; i++) r2[i] = getv(r2[i]);     bool zd = false;     for (int i = 1; i <= n; i++) {       if (wz[i] != w2[i]) zd = true;     }     for (int i = 1; i <= k; i++) {       if (rw[i] != r2[i]) zd = true;     }     for (int i = 1; i <= m; i++) {       if (yw[i] != y2[i]) zd = true;     }     for (int i = 1; i <= m; i++) {       if (b1[i] != b2[i]) zd = true;     }     if (zd)       printf( NO );     else       printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 55;   long long n, m;   int sol[MAXN];   void solve(int l, int r, long long k) {     if (l == r) {       assert(k == 1);       sol[l] = n;       return;     }     int len = r - l + 1;     long long cant = (1LL << (len - 1));     if (k <= cant / 2) {       sol[l] = n - len + 1;       solve(l + 1, r, k);     } else {       sol[r] = n - len + 1;       solve(l, r - 1, k - cant / 2);     }   }   int main() {     cin >> n >> m;     solve(0, n - 1, m);     for (int i = 0; i < n; i++) cout << sol[i] <<    n [i == n - 1];   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 3e-5;   double x, h, l;   int main() {     cin >> x;     for (double h = 1.0; h <= (10.0 + eps); h += 1.0) {       if (h + eps < x) continue;       l = h / (sqrt((h * h) / (x * x) - 1)) * 2.0;       for (double q = 1.0; q <= (10.0 + eps); q += 1.0) {         if (l - q < eps && q - l < eps) {           printf( %d %d n , (int)q, (int)h);           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve();   void precalc();   int main() {     string s =  change me please ;     int t = 1;     while (t--) solve();     return 0;   }   void solve() {     int n;     cin >> n;     vector<int> a(n), h(n);     for (int i = 0; i < n; ++i) cin >> a[i] >> h[i];     int ans = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         if (a[i] == h[j]) ++ans;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string A;     cin >> A;     if (A.size() > 1 and A.size() % 2 == 0) {       int x = (A.size() / 2) - 1;       cout << A[x];       for (int i = 1; i <= x; i++) {         cout << A[x + i] << A[x - i];       }       cout << A[2 * x + 1];     } else if (A.size() % 2 != 0 and A.size() > 1) {       int x = (A.size() / 2);       cout << A[x];       for (int i = 1; i <= x; i++) {         cout << A[x + i] << A[x - i];       }     } else {       cout << A[0];     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 3;   const long long INF = 4e18 + 3;   vector<long long> v[3];   int r[3];   long long ans;   auto iter1 = v[0].begin();   auto iter2 = v[1].begin();   long long X, Y;   void rob(int a, int b, int c) {     for (auto it : v[b]) {       if (it < v[a][0] || it > v[c].back()) continue;       iter1 = upper_bound(v[a].begin(), v[a].end(), it);       iter1--;       iter2 = lower_bound(v[c].begin(), v[c].end(), it);       X = *iter1;       Y = *iter2;       ans =           min(ans, (X - Y) * (X - Y) + (X - it) * (X - it) + (Y - it) * (Y - it));     }   }   int main() {     int z;     long long x;     scanf( %d , &z);     while (z--) {       ans = INF;       for (int i = 0; i < 3; i++) v[i].clear();       for (int i = 0; i < 3; i++) scanf( %d , &r[i]);       for (int i = 0; i < 3; i++) {         for (int j = 1; j <= r[i]; j++) {           scanf( %lld , &x);           v[i].push_back(x);         }       }       for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());       rob(0, 1, 2);       rob(0, 2, 1);       rob(1, 0, 2);       rob(1, 2, 0);       rob(2, 0, 1);       rob(2, 1, 0);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       vector<long long int> v(n);       for (long long int i = 0; i < n; i++) cin >> v[i];       long long int maxi = 1;       long long int l = 1;       for (long long int i = 1; i < n; i++) {         if (v[i] <= 2 * v[i - 1])           l++;         else           l = 1;         maxi = max(maxi, l);       }       cout << maxi << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int maxn = 100000, maxlog = 12;   long long pw[maxlog];   int n, qn;   long long a[maxn + 5];   struct lab_type {     bool ty;     long long val;     lab_type() : ty(0), val(0) {}     lab_type(int _ty, const long long &_val) : ty(_ty), val(_val) {}     bool empty() { return !ty && !val; }     friend lab_type &operator+=(lab_type &first, const lab_type &second) {       if (second.ty) return first = second;       if (!first.ty || first.val) first.val += second.val;       return first;     }     friend long long &operator+=(long long &first, const lab_type &second) {       if (second.ty) return first = second.val;       if (!first) return first;       return first += second.val;     }   };   struct node {     node *c[2];     long long Max;     lab_type label;     node() : Max(0) { memset(c, 0, sizeof c); }     void update() {       Max = 0;       for (int i = (0), _end_ = (2); i < _end_; ++i)         if (c[i]) chkmax(Max, c[i]->Max);     }     void flag_label(const lab_type &_label) {       label += _label;       Max += _label;     }     void push_down() {       if (!label.empty()) {         for (int i = (0), _end_ = (2); i < _end_; ++i)           if (c[i]) c[i]->flag_label(label);         label = lab_type();       }     }   };   const int max0 = 100000;   node *nd_pool;   int nd_res = 0;   node *newnode() {     if (!nd_res) nd_pool = new node[max0], nd_res = max0;     return nd_pool + (--nd_res);   }   node *rt[maxlog];   int seg_x, seg_y;   lab_type seg_z;   long long seg_ret;   int seg_id;   void add(node *&rt, int l, int r) {     if (seg_x <= l && r <= seg_y) {       rt->flag_label(seg_z);       return;     }     int mid = (l + r) >> 1;     rt->push_down();     if (seg_x < mid) add(rt->c[0], l, mid);     if (seg_y > mid) add(rt->c[1], mid, r);     rt->update();   }   void doit(node *rt, int l, int r) {     if (!rt) return;     if (rt->Max <= pw[seg_id]) return;     if (r - l <= 1) {       rt->Max = 0;       return;     }     if (rt->label.ty) {       rt->flag_label(lab_type(1, 0));       return;     }     rt->push_down();     int mid = (l + r) >> 1;     doit(rt->c[0], l, mid);     doit(rt->c[1], mid, r);     rt->update();   }   void query(node *rt, int l, int r) {     if (!rt) return;     if (seg_x <= l && r <= seg_y) {       chkmax(seg_ret, rt->Max);       return;     }     rt->push_down();     int mid = (l + r) >> 1;     if (seg_x < mid) query(rt->c[0], l, mid);     if (seg_y > mid) query(rt->c[1], mid, r);     rt->update();   }   void build(node *&rt, int l, int r) {     if (!rt) rt = newnode();     if (r - l <= 1) {       if (a[l] <= pw[seg_id])         rt->Max = a[l];       else         rt->Max = 0;       return;     }     rt->push_down();     int mid = (l + r) >> 1;     build(rt->c[0], l, mid);     build(rt->c[1], mid, r);     rt->update();   }   int main() {     pw[0] = 1;     for (int i = (1), _end_ = (maxlog); i < _end_; ++i) pw[i] = pw[i - 1] * 42;     scanf( %d%d , &n, &qn);     for (int i = (0), _end_ = (n); i < _end_; ++i) scanf( %I64d , a + i);     for (int i = (0), _end_ = (maxlog); i < _end_; ++i) {       seg_id = i;       build(rt[i], 0, n);     }     for (int i = (0), _end_ = (qn); i < _end_; ++i) {       int ty, l, r, first;       scanf( %d , &ty);       if (ty == 1) {         scanf( %d , &first), --first;         seg_x = first, seg_y = first + 1, seg_ret = 0;         query(rt[maxlog - 1], 0, n);         printf( %I64d n , seg_ret);       } else {         scanf( %d%d%d , &l, &r, &first), --l;         seg_x = l, seg_y = r;         if (ty == 2) {           seg_z = lab_type(1, first);           for (int i = maxlog - 1; i >= 0; --i) {             if (first > pw[i]) seg_z.val = 0;             add(rt[i], 0, n);           }         } else {           static long long Max[maxlog];           static long long cnt[maxlog];           for (int i = (0), _end_ = (maxlog); i < _end_; ++i) {             seg_ret = 0;             query(rt[i], 0, n);             Max[i] = seg_ret;             cnt[i] = 0;           }           while (1) {             bool ok = 1;             for (int i = (0), _end_ = (maxlog); i < _end_; ++i) {               cnt[i] += first;               if (Max[i] && Max[i] + cnt[i] > pw[i]) {                 seg_z = lab_type(0, cnt[i]);                 add(rt[i], 0, n);                 cnt[i] = 0;                 seg_id = i;                 doit(rt[i], 0, n);                 seg_ret = 0;                 query(rt[i], 0, n);                 Max[i] = seg_ret;               }               if (Max[i] && Max[i] + cnt[i] == pw[i]) ok = 0;             }             if (ok) break;           }           for (int i = (0), _end_ = (maxlog); i < _end_; ++i)             if (cnt[i]) {               seg_z = lab_type(0, cnt[i]), add(rt[i], 0, n), cnt[i] = 0;               assert(rt[i]->Max != pw[i]);             }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long s, n;     cin >> n >> s;     if (n >= s)       cout <<  1 n ;     else {       int div = s / n;       (s % n == 0) ? cout << div << endl : cout << (div + 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int mod = 1e7 + 9;   const int oo = (1 << 31) - 1;   template <class T>   inline void readInt(T &n) {     n = 0;     T ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     n = n * sign;   }   const int maxn = 100005;   int n, m, q, x, y, a[505][505], b[505];   int main() {     cin >> n >> m >> q;     for (int i = ((int)(0)); i < ((int)(n)); i++) b[i] = 0;     for (int i = ((int)(0)); i < ((int)(n)); i++)       for (int j = ((int)(0)); j < ((int)(m)); j++) cin >> a[i][j];     for (int i = ((int)(0)); i < ((int)(n)); i++) {       int c = a[i][0];       for (int j = ((int)(1)); j < ((int)(m)); j++) {         if (a[i][j] == 0) {           if (a[i][j - 1] == 1) b[i] = max(b[i], c);           c = 0;           continue;         }         if (a[i][j - 1] == 0)           c = 1;         else           c++;       }       b[i] = max(b[i], c);     }     for (int i = ((int)(0)); i < ((int)(q)); i++) {       cin >> x >> y;       --x;       --y;       a[x][y] = 1 - a[x][y];       int res = 0, c = a[x][0];       for (int j = ((int)(1)); j < ((int)(m)); j++) {         if (a[x][j] == 0) {           if (a[x][j - 1] == 1) res = max(res, c);           c = 0;           continue;         }         if (a[x][j - 1] == 0)           c = 1;         else           c++;       }       res = max(res, c);       b[x] = res;       res = 0;       for (int j = ((int)(0)); j < ((int)(n)); j++)         if (b[j] > res) res = b[j];       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   namespace fdd {   int n, m1, m2;   std::priority_queue<int> q[1010];   std::vector<int> v1, v2;   void solve() {     std::cin >> n;     for (int i = 3; i < n; i++) {       scanf( %d%d , &m1, &m2);       if (m1 > m2) std::swap(m1, m2);       q[m1].push(m2);     }     for (int i = 2; i <= n; i++) {       while (!q[i].empty()) {         m1 = q[i].top();         q[i].pop();         v1.push_back(i);         v1.push_back(m1);       }     }     for (int i = 3; i < n; i++) {       scanf( %d%d , &m1, &m2);       if (m1 > m2) std::swap(m1, m2);       q[m1].push(m2);     }     for (int i = 2; i <= n; i++) {       while (!q[i].empty()) {         m1 = q[i].top();         q[i].pop();         if (q[i].empty())           m2 = i + 1;         else           m2 = q[i].top();         v2.push_back(1);         v2.push_back(m2);       }     }     printf( %d n , (v1.size() + v2.size()) >> 1);     int l = v1.size();     for (int i = 0; i < l; i += 2) printf( %d %d n , v1[i], v1[i + 1]);     l = v2.size();     for (int i = l - 1; i >= 0; i -= 2) printf( %d %d n , v2[i - 1], v2[i]);   }   }  // namespace fdd   int main() {     fdd::solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native )   #pragma GCC optimize( Ofast,O3,unroll-loops )   using namespace std;   struct cplx {     long double a, b;     cplx(long double a = 0, long double b = 0) : a(a), b(b) {}     const cplx operator+(const cplx &c) const { return cplx(a + c.a, b + c.b); }     const cplx operator-(const cplx &c) const { return cplx(a - c.a, b - c.b); }     const cplx operator*(const cplx &c) const {       return cplx(a * c.a - b * c.b, a * c.b + b * c.a);     }     const cplx operator/(const long double &x) const {       return cplx(a / x, b / x);     }     const cplx conj() const { return cplx(a, -b); }   };   const long double PI = acosl(-1);   const int N = (1 << 20) + 5;   int rev[N];   cplx w[N];   void prepare(int &n) {     int sz = __builtin_ctz(n);     for (int i = 1; i < n; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (sz - 1));     w[0] = 0, w[1] = 1, sz = 1;     while (1 << sz < n) {       cplx w_n =           cplx(cosl(2 * PI / (1 << (sz + 1))), sinl(2 * PI / (1 << (sz + 1))));       for (int i = 1 << (sz - 1); i < (1 << sz); ++i) {         w[i << 1] = w[i], w[i << 1 | 1] = w[i] * w_n;       }       ++sz;     }   }   void fft(cplx *a, int n) {     for (int i = 1; i < n - 1; ++i) {       if (i < rev[i]) swap(a[i], a[rev[i]]);     }     for (int h = 1; h < n; h <<= 1) {       for (int s = 0; s < n; s += h << 1) {         for (int i = 0; i < h; ++i) {           cplx &u = a[s + i], &v = a[s + i + h], t = v * w[h + i];           v = u - t, u = u + t;         }       }     }   }   static cplx f[N];   vector<long long> multiply(vector<long long> a, vector<long long> b) {     int n = a.size(), m = b.size(), sz = 1;     while (sz < n + m - 1) sz <<= 1;     prepare(sz);     for (int i = 0; i < sz; ++i) f[i] = cplx(i < n ? a[i] : 0, i < m ? b[i] : 0);     fft(f, sz);     for (int i = 0; i <= (sz >> 1); ++i) {       int j = (sz - i) & (sz - 1);       cplx x = (f[i] * f[i] - (f[j] * f[j]).conj()) * cplx(0, -0.25);       f[j] = x, f[i] = x.conj();     }     fft(f, sz);     vector<long long> c(n + m - 1);     for (int i = 0; i < n + m - 1; ++i) c[i] = f[i].a / sz + 0.3;     return c;   }   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = (b - a + 1) * (c - b + 1) * (d - c + 1);     std::vector<long long> A(b + 1);     std::vector<long long> B(c + 1);     for (int i = a; i <= b; i++) A[i] = 1;     for (int i = b; i <= c; i++) B[i] = 1;     std::vector<long long> C = multiply(A, B);     long long prev = 0;     for (int i = 0; i <= d; i++) {       if (i < C.size()) prev += C[i];       if (i >= c) {         ans -= prev;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans[60];   int main() {     long long t, a, n, m, b, v, xmin, xmax, act, sum, i, vmi;     cin >> t;     while (t--) {       cin >> a >> b >> m;       if (a == b) {         cout <<  1   << a <<   n ;         continue;       }       for (n = 2; n <= 50; n++) {         v = ((1ll) << (n - 2));         xmin = v * a + v;         xmax = v * a + v * m;         if (xmin > b) {           n = 51;           break;         }         if (b <= xmax) {           act = xmax;           ans[1] = a;           sum = ans[1];           for (i = 2; i <= n; i++) {             v = ((1ll) << (max(n - i - 1, 0ll)));             vmi = m - (act - b) / v;             vmi = max(vmi, 1ll);             ans[i] = sum + vmi;             sum = sum + ans[i];             act -= (m - vmi) * v;           }           if (i <= n || ans[n] != b) continue;           cout << n <<    ;           for (i = 1; i <= n; i++) cout << ans[i] <<    ;           cout <<   n ;           break;         }       }       if (n == 51) {         cout << -1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int n, m, k, ans, a;   vector<int> adj[N], lan[N];   bool mark[N];   void input() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> k;       if (k == 0) a++;       while (k--) {         int v;         cin >> v;         lan[v].push_back(i);       }     }   }   void aa_adj() {     for (int i = 1; i <= m; i++) {       if (lan[i].size() == 0) continue;       for (int j = 0; j < lan[i].size() - 1; j++) {         adj[lan[i][j]].push_back(lan[i][j + 1]),             adj[lan[i][j + 1]].push_back(lan[i][j]);       }     }   }   void dfs(int v) {     mark[v] = true;     for (int u : adj[v])       if (!mark[u]) dfs(u);   }   void find_ans() {     for (int i = 1; i <= n; i++) {       if (!mark[i]) {         dfs(i), ans++;       }     }     if (a == n)       cout << ans << endl;     else       cout << ans - 1 << endl;   }   int main() {     input();     aa_adj();     find_ans();   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167177216 )   using namespace std;   const int MAXN = 9;   int main() {     long long n, A;     scanf( %I64d %I64d , &n, &A);     long long sum = 0;     vector<int> d(n);     for (int i = 0; i < n; i++) {       scanf( %d , &d[i]);       sum += d[i];     }     for (int i = 0; i < n; i++) {       long long without = sum - d[i];       long long need = A - without;       if (need <= 0) {         long long need = A - (n - 1);         if (d[i] <= need)           cout << 0 <<    ;         else {           cout << d[i] - need <<    ;         }       } else {         long long ans = need - 1;         long long razn = d[i] - need;         if (without - (n - 1) < razn) ans += (razn - without + (n - 1));         cout << ans <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-6;   const int MOD = 1e9 + 7;   const int MAXN = 110;   const double PI = acos(-1.0);   int ipt[MAXN][MAXN];   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       int ans = INF, all = 1 << m;       for (int i = 0; i < (n); ++i)         for (int j = 0; j < (m); ++j) scanf( %d , &ipt[i][j]);       if (n < m) {         for (int i = 0; i < (n); ++i)           for (int j = (i + 1); j < (m); ++j) swap(ipt[i][j], ipt[j][i]);         swap(n, m);       }       if (n > k) {         for (int i = 0; i < (n); ++i) {           int tans = 0;           for (int j = 0; j < (n); ++j) {             int cnt = 0;             for (int k = 0; k < (m); ++k) cnt += ipt[i][k] ^ ipt[j][k];             tans += min(cnt, m - cnt);           }           ans = min(ans, tans);         }       } else {         for (int mask = 0; mask < all; mask++) {           int tans = 0;           for (int i = 0; i < (n); ++i) {             int cnt = 0;             for (int j = 0; j < (m); ++j) cnt += ipt[i][j] ^ (mask >> j & 1);             tans += min(cnt, m - cnt);           }           ans = min(ans, tans);         }       }       printf( %d n , ans <= k ? ans : -1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int t, n;   int cnt, num, maxx;   int a[maxn];   int vis[maxn];   int m1[maxn];   int m2[maxn];   void init() {     num = 0;     maxx = 0;     memset(vis, 0, sizeof(vis));   }   int main() {     scanf( %d , &t);     while (t--) {       cnt = 0;       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) m1[i] = 0, m2[i] = 0;       init();       for (int i = 1; i <= n; i++) {         maxx = max(maxx, a[i]);         if (!vis[a[i]]) {           num++;           vis[a[i]] = 1;         } else           break;         if (num == maxx)           m1[i] = 1;         else           m1[i] = 0;       }       init();       for (int i = n; i >= 1; i--) {         maxx = max(maxx, a[i]);         if (!vis[a[i]]) {           num++;           vis[a[i]] = 1;         } else           break;         if (num == maxx) {           m2[i] = 1;           if (i > 1 && m1[i - 1]) cnt++;         } else           m2[i] = 0;       }       printf( %d n , cnt);       for (int i = 1; i < n; i++)         if (m1[i] && m2[i + 1]) printf( %d %d n , i, n - i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100, M = 10000;   int n, m, a[N + 9], ca;   double x, ans;   void into() {     scanf( %d%lf , &n, &x);     int p = 0;     for (int i = 1; i <= n; ++i) {       int t;       scanf( %d , &t);       t << 1 <= x ? ans += t : m += a[++ca] = t;     }     x /= 2;   }   double dp[N + 9][M + 9];   void Get_dp() {     dp[0][0] = 1;     for (int i = 1; i <= ca; ++i)       for (int j = i; j >= 1; --j)         for (int k = m; k >= a[i]; --k)           dp[j][k] += dp[j - 1][k - a[i]] * j / (ca - j + 1);   }   void Get_ans() {     for (int i = 1; i <= ca; ++i)       for (int j = 0; j <= m; ++j)         ans += dp[i][j] * min((1.0 * n / i + 1) * x, 1.0 * j / i);   }   void work() {     Get_dp();     Get_ans();   }   void outo() { printf( %.12lf n , ans); }   int main() {     into();     work();     outo();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30);   const int MAXN = 100000;   struct node {     int le, ri;     set<int> Set;     int mx, mn;   } tree[24 * MAXN + 5];   bool tag[MAXN + 5];   void pushup(int x) {     if (tree[x].le == tree[x].ri)       tree[x].mx = tree[x].mn = *tree[x].Set.rbegin();     else {       tree[x].mn =           max(*tree[x].Set.rbegin(), min(tree[x << 1].mn, tree[x << 1 | 1].mn));       tree[x].mx =           max(*tree[x].Set.rbegin(), max(tree[x << 1].mx, tree[x << 1 | 1].mx));     }     if (tree[x].mx < tree[x].mn) tree[x].mx = -1;     if (tree[x].mx != -1 && tag[tree[x].mx]) tree[x].mx = -1;   }   void build(int x, int l, int r) {     tree[x].le = l, tree[x].ri = r;     tree[x].mx = tree[x].mn = 0;     tree[x].Set.clear();     tree[x].Set.insert(0);     if (l == r) return;     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   void modify(int x, int l, int r, int k, int type) {     if (l > tree[x].ri || r < tree[x].le) return;     if (l <= tree[x].le && tree[x].ri <= r) {       if (type)         tree[x].Set.insert(k);       else         tree[x].Set.erase(k);       pushup(x);       return;     }     modify(x << 1, l, r, k, type);     modify(x << 1 | 1, l, r, k, type);     pushup(x);   }   void update(int x, int l, int r) {     if (l > tree[x].ri || r < tree[x].le) return;     if (l <= tree[x].le && tree[x].ri <= r) {       pushup(x);       return;     }     update(x << 1, l, r);     update(x << 1 | 1, l, r);     pushup(x);   }   int N;   int Xa[MAXN + 5], Xb[MAXN + 5], Ya[MAXN + 5], Yb[MAXN + 5];   int dct[2][6 * MAXN + 5], dcnt[2];   void discrete() {     for (int i = 0; i < 2; i++) sort(dct[i] + 1, dct[i] + dcnt[i] + 1);     for (int i = 0; i < 2; i++)       dcnt[i] = unique(dct[i] + 1, dct[i] + dcnt[i] + 1) - dct[i] - 1;     for (int i = 1; i <= N; i++) {       Xa[i] = lower_bound(dct[0] + 1, dct[0] + dcnt[0] + 1, Xa[i]) - dct[0];       Xb[i] = lower_bound(dct[0] + 1, dct[0] + dcnt[0] + 1, Xb[i]) - dct[0];       Ya[i] = lower_bound(dct[1] + 1, dct[1] + dcnt[1] + 1, Ya[i]) - dct[1];       Yb[i] = lower_bound(dct[1] + 1, dct[1] + dcnt[1] + 1, Yb[i]) - dct[1];     }   }   void insert_dct(int val, int type) { dct[type][++dcnt[type]] = val; }   struct query {     int le, ri, num;     bool type;     query(int _l = 0, int _r = 0, int _n = 0, bool _t = 0)         : le(_l), ri(_r), num(_n), type(_t) {}   };   vector<query> vec[6 * MAXN + 5];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d%d%d%d , &Xa[i], &Ya[i], &Xb[i], &Yb[i]);       Xb[i]--, Yb[i]--;       insert_dct(Xa[i], 0);       insert_dct(Xa[i] + 1, 0);       insert_dct(Xa[i] - 1, 0);       insert_dct(Xb[i], 0);       insert_dct(Xb[i] + 1, 0);       insert_dct(Xb[i] - 1, 0);       insert_dct(Ya[i], 1);       insert_dct(Ya[i] + 1, 1);       insert_dct(Ya[i] - 1, 1);       insert_dct(Yb[i], 1);       insert_dct(Yb[i] + 1, 1);       insert_dct(Yb[i] - 1, 1);     }     discrete();     for (int i = 1; i <= N; i++) {       vec[Xa[i]].push_back(query(Ya[i], Yb[i], i, 1));       vec[Xb[i] + 1].push_back(query(Ya[i], Yb[i], i, 0));     }     build(1, 1, dcnt[1]);     Ya[0] = 1;     Yb[0] = dcnt[1];     for (int i = 1; i <= dcnt[0]; i++) {       for (int j = 0; j < vec[i].size(); j++)         modify(1, vec[i][j].le, vec[i][j].ri, vec[i][j].num, vec[i][j].type);       while (tree[1].mx != -1) {         tag[tree[1].mx] = true;         update(1, Ya[tree[1].mx], Yb[tree[1].mx]);       }     }     int ans = 0;     for (int i = 0; i <= N; i++)       if (tag[i]) ans++;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   using PII = pair<int, int>;   using PLL = pair<long long, long long>;   using VLL = vector<long long>;   using VI = vector<int>;   inline void fastio() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fL;   const int mod1 = 998244353;   const int mod2 = 1e9 + 7;   void solve() {     int n, m, k;     cin >> n >> m >> k;     if (k <= 1) {       cout <<  NO  << endl;       return;     }     if (m < n - 1) {       cout <<  NO  << endl;       return;     }     long long cnt = 1ll * n * (n - 1) / 2;     if (m > cnt) {       cout <<  NO  << endl;       return;     }     if (k == 2 && n > 1) {       cout <<  NO  << endl;       return;     }     if (k >= 2 && n == 1) {       cout <<  YES  << endl;       return;     }     if (k > 3) {       cout <<  YES  << endl;       return;     }     if (m == cnt) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }   signed main() {     fastio();     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime[100000 + 5];   int ans[100000 + 5];   int main() {     long long int n;     cin >> n;     for (int i = 0; i <= n; i++) prime[i] = true;     long long int k = 1;     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         ans[p] = k;         for (int i = p * p; i <= n; i += p) {           if (i <= n) {             prime[i] = false;             ans[i] = k;           }         }         prime[p] = false;         k++;       }     }     for (int p = 2; p <= n; p++) {       if (prime[p] == true) {         for (int i = p; i <= n; i += p) {           if (i <= n) {             prime[i] = false;             ans[i] = k;           }         }         k++;       }     }     for (int p = 2; p <= n; p++) cout << ans[p] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     string s;     cin >> n >> k;     cin >> s;     int isThere[26];     for (int i = 0; i < 26; i++) isThere[i] = 0;     bool ok = true;     for (int i = 0; i < n; i++) {       isThere[s[i] -  a ]++;       if (isThere[s[i] -  a ] > k) {         ok = false;         break;       }     }     if (ok)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXD = 60 + 5;   const int MAXN = 2e3 * 60 + 5;   const int mod = 1e9 + 7;   inline long long pw(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   inline int get_lb(long long x) {     int res = 0;     while (x >> res) ++res;     return res - 1;   }   int d;   long long a[MAXN];   int b[MAXN];   long long pt[MAXN];   int pcnt = 0, must[MAXN], dp[MAXN][5];   int f[MAXD];   inline int get(long long u) {     int pos = lower_bound(pt + 1, pt + pcnt + 1, u) - pt;     if (pos > pcnt || pt[pos] != u) return -1;     return pos;   }   inline vector<int> get_dp(long long u) {     int id = get(u);     if (id != -1)       return vector<int>(dp[id], dp[id] + 3);     else       return vector<int>(3, f[d - get_lb(u)]);   }   int main(void) {     int n;     scanf( %d%d , &d, &n);     for (int i = 1; i <= n; ++i) {       static char t[100];       scanf( %lld%s , &a[i], t + 1);       b[i] = t[1] ==  w  || t[1] ==  y  ? 1 : t[1] ==  g  || t[1] ==  b  ? 2 : 3;     }     f[1] = 1;     for (int i = 2; i <= d; ++i) f[i] = 4ll * f[i - 1] * f[i - 1] % mod;     pt[++pcnt] = 1;     for (int i = 1; i <= n; ++i) {       long long u = a[i];       while (u) {         pt[++pcnt] = u;         u >>= 1;       }     }     sort(pt + 1, pt + pcnt + 1);     pcnt = unique(pt + 1, pt + pcnt + 1) - pt - 1;     for (int i = 1; i <= n; ++i) must[get(a[i])] = b[i];     for (int i = pcnt; i >= 1; --i) {       if (pt[i] >= (1ll << (d - 1))) {         if (!must[i])           dp[i][0] = dp[i][1] = dp[i][2] = 1;         else           dp[i][must[i] - 1] = 1;         continue;       }       long long u = pt[i];       vector<int> ls = get_dp(u << 1);       vector<int> rs = get_dp(u << 1 | 1);       for (int x = 0; x < 3; ++x) {         if (must[i] && x != must[i] - 1) continue;         for (int y = 0; y < 3; ++y)           if (y != x)             for (int z = 0; z < 3; ++z)               if (z != x) dp[i][x] = (dp[i][x] + (long long)ls[y] * rs[z]) % mod;       }     }     int ans = 0;     for (int i = 0; i < 3; ++i) ans = (ans + dp[1][i]) % mod;     ans = ans * pw(2, (1ll << d) - 1 - n) % mod;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> ans;   bool check(string s, int L, int R) {     if (s[L] ==  0 ) {       if (R == L + 1) {         return true;       }       return false;     }     int n = 0;     for (int i = L; i < R; i++) {       n *= 10;       n += s[i] -  0 ;     }     return (n >= 0 && n < 256);   }   void func(string s) {     int N = s.length();     for (int i = 1; i <= 3; i++) {       for (int j = i + 1; j <= i + 3; j++) {         for (int k = j + 1; k <= j + 3; k++) {           if (N - k >= 1 && N - k <= 3) {             if (check(s, 0, i) && check(s, i, j) && check(s, j, k) &&                 check(s, k, N)) {               string final;               final = s.substr(0, i) +  .  + s.substr(i, j - i) +  .  +                       s.substr(j, k - j) +  .  + s.substr(k, N - k);               ans.push_back(final);             }           }         }       }     }   }   void dfs(int L, string s, int mask, int pos, int used) {     if (pos == L) {       if (used == mask) {         func(s);         return;       }     }     int pos2 = L - 1 - pos;     if (pos2 < pos) {       if (mask != used) {         return;       }       char c = s[pos2];       dfs(L, s + c, mask, pos + 1, used);     } else {       char c;       for (int i = 0; i < 10; i++) {         if (mask & (1 << i)) {           c = i +  0 ;           dfs(L, s + c, mask, pos + 1, (used | (1 << i)));         }       }     }   }   int main() {     int n;     int a[11];     cin >> n;     int mask = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       mask |= (1 << a[i]);     }     if (n <= 6) {       for (int i = 4; i <= 12; i++) {         dfs(i,   , mask, 0, 0);       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].c_str() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long int a;     long long int b;   };   node p[100005];   bool comp(node x, node y) {     if (x.b < y.b) return true;     return false;   }   int main() {     long long int n, r, avg;     cin >> n >> r >> avg;     long long int s = 0;     for (int i = (0); i < (n); ++i) {       cin >> p[i].a >> p[i].b;       s += p[i].a;     }     long long int cc = avg * n;     if (s >= cc)       cout << 0 << endl;     else {       long long int to = avg * n;       long long int add = to - s;       long long int count = 0;       sort(p, p + n, comp);       for (int j = (0); j < (n); ++j) {         if (add == 0) break;         long long int maxim = r - p[j].a;         if (r < p[j].a) continue;         if (add > maxim) {           add = add - maxim;           count += p[j].b * maxim;         } else {           count += add * p[j].b;           add = 0;         }       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int columns[n + 1];     memset(columns, 0, sizeof(columns));     for (int i = 0; i < m; i++) {       int tmp;       cin >> tmp;       columns[tmp]++;     }     int ans = 1001;     for (int i = 1; i <= n; i++) {       ans = min(ans, columns[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int head[100005];   struct edge {     int vet, next;   } E[200005];   int i, j, k, n, m, s, t, tot, L;   int top[100005];   int fa[100005];   int dep[100005];   int a[100005];   int dist[3005][3005];   double ans;   int X, Y, all;   int cyc[100005];   int getf(int x) {     if (x != fa[x]) fa[x] = getf(fa[x]);     return fa[x];   }   void add(int u, int v) {     E[++tot] = (edge){v, head[u]};     head[u] = tot;   }   void getroad(int u, int dad) {     if (u == Y) {       L = cyc[u] = 1;       return;     }     for (int e = head[u]; e != -1; e = E[e].next)       if (e != dad) {         getroad(E[e].vet, e ^ 1);         if (cyc[E[e].vet] > 0) {           cyc[u] = cyc[E[e].vet] + 1;           L = max(L, cyc[u]);         }       }   }   void dfs(int u, const int &anc, int dad, int deep) {     dep[u] = deep;     top[u] = anc;     for (int e = head[u]; e != -1; e = E[e].next)       if (e != dad && cyc[E[e].vet] == 0) dfs(E[e].vet, anc, e ^ 1, deep + 1);   }   void getdis(int u, const int &anc, int dad, int D) {     dist[anc][u] = D;     for (int e = head[u]; e != -1; e = E[e].next)       if (e != dad) getdis(E[e].vet, anc, e ^ 1, D + 1);   }   void DO() {     for (int i = 1; i <= n; i++) getdis(i, i, -1, 0);   }   int main() {     tot = -1;     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++;       y++;       if (getf(x) == getf(y)) {         X = x;         Y = y;         continue;       }       add(x, y);       add(y, x);       fa[getf(x)] = getf(y);     }     DO();     getroad(X, -1);     for (int i = 1; i <= n; i++)       if (cyc[i] > 0) dfs(i, i, -1, 0);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) {           if (top[i] == top[j])             ans += 1.0 / (dist[i][j] + 1);           else {             int x = dep[i] + dep[j];             int y = abs(cyc[top[i]] - cyc[top[j]]);             int z = L - y;             ans += 1.0 / (x + y + 1) + 1.0 / (x + z + 1) - 1.0 / (x + L);           }         }     ans += n;     printf( %.14f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double pi = 2 * acos(0.0);   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (const auto &x : v) os <<     << x;     return os <<  } ;   }   void solve() {     long long int l, r, m;     cin >> l >> r >> m;     long long int a, b, c;     long long int mm = r - l;     long long int p, q, ss;     if (m < l) {       a = l;       b = l;       c = l + (l - m);       cout << a <<     << b <<     << c << endl;       return;     }     for (long long int i = l; i <= r; i++) {       p = m % i;       q = m / i;       q++;       ss = q * i;       ss -= m;       if (p <= mm) {         a = i;         c = l;         b = c + p;         break;       } else if (ss <= mm) {         a = i;         b = l;         c = l + ss;         break;       }     }     cout << a <<     << b <<     << c << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int test_cases;     cin >> test_cases;     for (int tc = 1; tc <= test_cases; tc++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   long long mod = 1e9 + 7, mod2 = 998244353;   using namespace std;   long long fac[10000000];   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long fexp(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % m;       b /= 2;       a = a * a % m;     }     return ans;   }   long long inverse(long long a, long long p) { return fexp(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[n - r], p) % p * inverse(fac[r], p) % p) % p;   }   vector<long long> za(string s) {     long long n = s.size();     vector<long long> z(n);     long long x = 0, y = 0, p = 0;     for (long long i = 1; i < n; i++) {       z[i] = max(p, min(z[i - x], y - i + 1));       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {         x = i;         y = i + z[i];         z[i]++;       }     }     return z;   }   void subset(long long a[], long long k) {     for (int i = 1; i < pow(2, k); i++) {       for (int j = 0; j < k; j++) {         if (i & 1 << j) {           cout << a[j] <<    ;         }       }       cout <<   n ;       ;     }   }   vector<long long> pr(string s) {     long long n = s.length();     vector<long long> pi(n);     for (int i = 1; i < n; i++) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) j++;       pi[i] = j;     }     return pi;   }   long long d[100005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, s, l, r, x = 0;     cin >> n >> s;     for (long long i = 1; i < n; i++) {       cin >> l >> r;       d[l]++;       d[r]++;     }     for (long long i = 1; i <= n; i++) {       if (d[i] == 1) x++;     }     cout << fixed << setprecision(50) << ((2 * s) / (1.0 * x));   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, a = 0, b = 0;     cin >> n;     vector<pair<int, int>> v;     while (n--) {       cin >> x >> y;       a += x;       b += y;       v.push_back(make_pair(x, y));     }     bool ok = 0;     if (a % 2 == 0 && b % 2 == 0) {       cout << 0;       return 0;     }     if (a % 2 && b % 2) {       for (auto i : v) {         if ((i.first % 2 == 0 && i.second % 2) ||             (i.first % 2 && i.second % 2 == 0)) {           ok = 1;           break;         }       }     }     cout << (ok ? 1 : -1);   }


#include <bits/stdc++.h>   const int MAXN = 3000 + 1000;   int n, sum;   int in[MAXN], out[MAXN];   struct Union_Find_Set {     int f[MAXN];     void Init(int N) {       for (int i = 1, _ = N; i <= _; i++) f[i] = i;     }     int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); }     bool Union(int x, int y) {       x = Find(x);       y = Find(y);       if (x == y) return 0;       in[x] += in[y];       out[x] += out[y];       f[y] = x;       if (in[x] + out[x] > sum) return 1;       return 0;     }   } t;   struct Edge {     int u, v, w;     Edge() {}     Edge(int u, int v, int w) : u(u), v(v), w(w) {}     bool operator<(const Edge &a) const { return w < a.w; }   } G[MAXN];   void Init() {     int u, v, w;     scanf( %d , &n);     t.Init(n);     for (int i = 1, _ = n - 1; i <= _; i++) {       scanf( %d%d%d , &u, &v, &w);       G[i] = Edge(u, v, w);     }     for (int i = 1, _ = n; i <= _; i++) {       scanf( %d , &out[i]);       sum += out[i];       in[i] = 1;     }   }   void Solve() {     if (n == 1) {       puts( 0 );       return;     }     int u, v;     std::sort(G + 1, G + n);     for (int i = 1, _ = n - 1; i <= _; i++) {       if (t.Union(G[i].u, G[i].v)) {         printf( %d n , G[i].w);         return;       }     }   }   int main() {     Init();     Solve();   }


#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 = 100 + 5;   const int MOD = 1e9 + 7;   void add(int &dp, LL val) { dp = (dp + val) % MOD; }   int f[N][N], g[N][N][N], cnt3[N], d[N];   LL getG(int i, int j, int k) {     if (i < 0 || j < 0 || k < 0) return 0;     return g[i][j][k];   }   int main() {     int n = read();     for (int i = 1; i <= n; ++i) {       cnt3[i] = cnt3[i - 1] + ((d[i] = read()) & 1);     }     g[0][0][0] = 1;     for (int c0 = 0; c0 <= n; ++c0) {       for (int c2 = 0; c2 <= n; ++c2) {         for (int c1 = !c2; c1 <= n; ++c1) {           int &cg = g[c0][c1][c2];           if (c2 > 0) {             add(cg, getG(c0 - 2, c1, c2 - 1) * c0 * (c0 - 1) / 2);             add(cg, getG(c0 - 1, c1 + 1, c2 - 2) * c0 * (c2 - 1));             add(cg, getG(c0, c1 + 2, c2 - 3) * (c2 - 1) * (c2 - 2) / 2);             add(cg, getG(c0, c1, c2 - 2) * (c2 - 1) * c1);             add(cg, getG(c0 - 1, c1 - 1, c2 - 1) * c0 * c1);             add(cg, getG(c0, c1 - 2, c2 - 1) * c1 * (c1 - 1) / 2);           } else {             add(cg, getG(c0 - 1, c1 - 1, c2) * c0);             add(cg, getG(c0, c1 - 2, c2) * (c1 - 1));           }         }       }     }     f[n + 1][n] = 1;     for (int l = n; l >= 2; --l) {       for (int r = l; r <= n; ++r) {         int c2 = cnt3[r] - cnt3[l - 1];         int c1 = r - l + 1 - c2;         for (int k = 0; k + r <= n; ++k) {           add(f[l][r], static_cast<LL>(f[r + 1][r + k]) * g[k][c1][c2]);         }       }     }     printf( %d n , f[2][d[1] + 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void func(void) {     freopen( input.c ,  r , stdin);     freopen( output.c ,  w , stdout);   }   void print(vector<long long> &v) {     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       printf( %lld  , v[i]);     }     printf(  n );   }   void print(vector<pair<long long, long long> > &v) {     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       printf( %lld %lld n , v[i].first, v[i].second);     }   }   void print(double d) { cout << fixed << setprecision(10) << d << endl; }   void print(string s, double d) {     cout << s <<    ;     cout << fixed << setprecision(10) << d << endl;   }   int main() {     long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m,                        fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000,                        mn1 = 8000000000000000000;     cin >> t;     while (t--) {       cin >> n;       vector<int> v1, v2, temp1;       for (int i = 0; i < n; i++) {         cin >> x;         v1.push_back(x);       }       for (int i = 0; i < n; i++) {         cin >> x;         v2.push_back(x);       }       int mid = (n + 1) / 2;       vector<pair<int, int> > vp1, vp2;       for (int i = 0; i < mid; i++) {         vp1.push_back({v1[i], v1[n - i - 1]});         vp2.push_back({v2[i], v2[n - i - 1]});         if (vp1[i].first > vp1[i].second) swap(vp1[i].first, vp1[i].second);         if (vp2[i].first > vp2[i].second) swap(vp2[i].first, vp2[i].second);       }       sort(vp1.begin(), vp1.end());       sort(vp2.begin(), vp2.end());       if (vp1 == vp2) {         cout <<  Yes n ;       } else         cout <<  No n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 1e9;   const int MAXN = 20010;   const int MAXK = 110;   int N, K;   int A[MAXN];   int ord[MAXN];   int lo[MAXN], hi[MAXN];   struct line {     int k, b;     line() {}     line(int k_, int b_) : k(k_), b(b_) {}     int eval(int x) const { return k * x + b; }   };   bool bad(const line& a, const line& b, const line& c) {     return ll(b.b - a.b) * (b.k - c.k) <= ll(c.b - b.b) * (a.k - b.k);   }   void insert_hull(vector<line>& hull, const line& l) {     while (hull.size() >= 2 && bad(hull.end()[-2], hull.end()[-1], l)) {       hull.pop_back();     }     hull.push_back(l);   }   int get_min(vector<line>& hull, int x) {     if (hull.empty()) {       return INF;     }     while (hull.size() >= 2 && hull.back().eval(x) >= hull.end()[-2].eval(x)) {       hull.pop_back();     }     return hull.back().eval(x);   }   vector<line> segg[2 * MAXN];   void update_g(int a, const line& l) {     for (a += N + 1; a >= 1; a /= 2) {       insert_hull(segg[a], l);     }   }   int query_g(int a, int b, int x) {     int res = INF;     for (a += N + 1, b += N + 1; a < b; a /= 2, b /= 2) {       if (a & 1) {         res = min(res, get_min(segg[a], x));         a++;       }       if (b & 1) {         b--;         res = min(res, get_min(segg[b], x));       }     }     return res;   }   vector<line> segdp[2 * MAXN];   void update_dp(int a, int b, const line& l) {     for (a += N + 1, b += N + 1; a < b; a /= 2, b /= 2) {       if (a & 1) {         insert_hull(segdp[a], l);         a++;       }       if (b & 1) {         b--;         insert_hull(segdp[b], l);       }     }   }   int query_dp(int a, int x) {     int res = INF;     for (a += N + 1; a >= 1; a /= 2) {       res = min(res, get_min(segdp[a], x));     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> N >> K;     for (int i = 1; i <= N; i++) {       cin >> A[i];     }     iota(ord, ord + N + 1, 0);     sort(ord, ord + N + 1, [&](int i, int j) { return A[i] < A[j]; });     vector<int> st;     for (int i = 0; i <= N; i++) {       while (st.size() && A[i] >= A[st.back()]) st.pop_back();       if (st.size()) {         lo[i] = st.back();       } else {         lo[i] = 0;       }       st.push_back(i);     }     A[N + 1] = INF;     st = {N + 1};     for (int i = N; i >= 1; i--) {       while (A[i] >= A[st.back()]) st.pop_back();       hi[i] = st.back();       st.push_back(i);     }     vector<int> dp(N + 1, INF);     dp[0] = 0;     for (int k = 0; k < K; k++) {       for (int i = 1; i < 2 * (N + 1); i++) {         segg[i].clear();         segdp[i].clear();       }       for (int i = 0; i <= N; i++) {         if (dp[i] != INF) {           update_g(i, line(i, dp[i]));         }       }       vector<int> vals(N + 1);       for (int o = N; o >= 0; o--) {         int i = ord[o];         vals[o] = query_g(lo[i], i, -A[i]);       }       for (int o = 0; o <= N; o++) {         int i = ord[o];         if (vals[o] < INF) {           update_dp(i, hi[i], line(A[i], vals[o]));         }       }       for (int i = 0; i <= N; i++) {         dp[i] = query_dp(i, i);       }     }     cout << dp[N] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 1000005;   int aib[2 * kMaxN];   int x[kMaxN], poz[kMaxN];   int el[2 * kMaxN];   bool first[kMaxN];   void aib_update(int ind, int val) {     while (ind < 2 * kMaxN) {       aib[ind] += val;       ind += ind & (-ind);     }     return;   }   int aib_search(int val) {     int p = 20;     int rez = 0;     for (; p >= 0; --p)       if ((1 << p) + rez < 2 * kMaxN)         if (aib[(1 << p) + rez] < val) {           val -= aib[(1 << p) + rez];           rez += (1 << p);         }     return rez + 1;   }   int main() {     int n, m;     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> x[i] >> poz[i];     int st = m + 2;     for (int i = st; i < st + n; ++i) {       el[i] = 0;       aib_update(i, +1);     }     bool ok = true;     for (int i = 1; i <= m and ok; ++i) {       st--;       int p = aib_search(poz[i]);       if (first[x[i]] == false) {         if (el[p] != false) ok = false;         el[p] = x[i];         first[x[i]] = true;         el[st] = x[i];         aib_update(p, -1);         aib_update(st, +1);       } else {         if (el[p] != x[i]) ok = false;         aib_update(p, -1);         aib_update(st, +1);         el[st] = x[i];       }     }     if (not ok)       cout <<  -1 n ;     else {       int st = m + 2;       int dr = 1;       for (int i = st; i < st + n; ++i)         if (el[i] == 0) {           while (first[dr] != 0) ++dr;           cout << dr <<    ;           ++dr;         } else {           cout << el[i] <<    ;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     unsigned long long t;     cin >> t;     while (t--) {       unsigned long long x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2 || y1 == y2) {         cout << 1 <<   n ;       } else {         unsigned long long d = x2 - x1;         unsigned long long r = y2 - y1;         cout << d * r + 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int p[N], used[N];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 1; i <= n; i++) {       if (p[i] == i) {         cout <<  YES n ;         for (int j = 1; j <= n; j++) {           if (i == j) continue;           cout << i <<     << j <<   n ;         }         return;       }     }     for (int i = 1; i <= n; i++) {       if (used[i]) continue;       int j = i, length = 0;       while (!used[j]) {         used[j] = 1;         length++;         j = p[j];       }       if (length & 1) {         cout <<  NO ;         return;       }     }     memset(used, 0, sizeof used);     for (int i = 1; i <= n; i++) {       int j = p[i];       if (p[j] == i) {         cout <<  YES n ;         cout << i <<     << j <<   n ;         for (int l = 1; l <= n; l++) {           if (l == i || l == j || used[l]) continue;           int v = l, xr = 0;           while (!used[v]) {             used[v] = 1;             cout << v <<     << (xr == 0 ? i : j) <<   n ;             xr ^= 1;             v = p[v];           }         }         return;       }     }     cout <<  NO ;   }   int main() {     ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);     cout.setf(ios::fixed), cout.precision(20);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111;   vector<pair<int, int> > g[N];   void printAns(int id, int v, int u, double x) {     if (x >= 1) {       swap(v, u);       x -= 1;     }     x = 1 - x;     printf( 1 %d %d %d %.12lf n , id, u, v, x);   }   void dfs(int v, int par, double x) {     for (pair<int, int> e : g[v]) {       if (e.first == par) continue;       x += 2. / (int)g[v].size();       if (x >= 2) x -= 2;       printAns(e.second, v, e.first, x);       double y = x + 1;       if (y >= 2) y -= 2;       dfs(e.first, v, y);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int v, u;       scanf( %d%d , &v, &u);       g[v].push_back(make_pair(u, i));       g[u].push_back(make_pair(v, i));     }     printf( %d n , n - 1);     double x = 0;     for (pair<int, int> e : g[1]) {       printAns(e.second, 1, e.first, x);       double y = x + 1;       if (y >= 2) y -= 2;       dfs(e.first, 1, y);       x += 2. / (int)g[1].size();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5 * 100005;   int sum[N];   char str[5 * 100005];   int costf[5 * 100005];   int costb[5 * 100005];   int n, a, b, t;   int main() {     scanf( %d , &n);     scanf( %d , &a);     scanf( %d , &b);     scanf( %d , &t);     cin >> str;     if (str[0] ==  h )       costf[1] = 1;     else       costf[1] = 1 + b;     for (int i = 2; i <= n; i++) {       if (str[i - 1] ==  h )         costf[i] = (costf[i - 1] + 1 + a);       else         costf[i] = (costf[i - 1] + 1 + a + b);     }     if (str[n - 1] ==  h )       costb[n] = 1;     else       costb[n] = (1 + b);     for (int i = n - 1; i >= 1; i--) {       if (str[i - 1] ==  h )         costb[i] = (costb[i + 1] + 1 + a);       else         costb[i] = (costb[i + 1] + 1 + a + b);     }     vector<int> v;     for (int i = n; i >= 1; i--) {       v.push_back(costb[i]);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int x = t;       if (costf[i] > x) {         break;       } else {         int temp = 0;         temp += i;         x -= costf[i];         x -= (a * i);         if (x > 0) temp += (upper_bound(v.begin(), v.end(), x) - v.begin());         if (temp > n) temp = n;         ans = max(ans, temp);       }     }     vector<int> vv;     for (int i = 2; i <= n; i++) {       vv.push_back(costf[i] - a - costf[1]);     }     for (int i = n; i >= 1; i--) {       int x = t;       if (costb[i] + costf[1] + a > x)         break;       else {         int temp = 0;         temp += (n - i + 1);         temp += 1;         x -= (costb[i] + a + costf[1]);         x -= (n - i + 2) * a;         if (x > 0) temp += (upper_bound(vv.begin(), vv.end(), x) - vv.begin());         if (temp > n) temp = n;         ans = max(ans, temp);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T MDINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   string h;   long long int b;   long long int vis[13][2][13];   long long int dp(long long int i, long long int choto, long long int ld) {     if (i == h.size()) {       if (ld == b)         return 1;       else         return 0;     }     long long int &ret = vis[i][choto][ld];     if (ret != -1) return ret;     ret = 0;     if (!choto) {       long long int ab = h[i] -  0 ;       for (long long int j = 0; j <= ab; j++) {         if (j == ab) {           if (j == 4 || j == 7)             ret += dp(i + 1, choto, ld + 1);           else             ret += dp(i + 1, choto, ld);         } else {           if (j == 4 || j == 7)             ret += dp(i + 1, 1, ld + 1);           else             ret += dp(i + 1, 1, ld);         }       }     } else {       for (long long int j = 0; j <= 9; j++) {         if (j == 4 || j == 7)           ret += dp(i + 1, 1, ld + 1);         else           ret += dp(i + 1, 1, ld);       }     }     return ret;   }   long long int fact(long long int num1, long long int num2) {     if (num1 < num2) return 0;     if (num1 == num2)       return 1;     else {       long long int sum = num1 - num2;       long long int res = 1;       for (long long int i = sum + 1; i <= num1; i++) {         res = (res * i) % 1000000007LL;       }       for (long long int i = 1; i <= num2; i++) {         res = (res * MDINV(i, 1000000007LL)) % 1000000007LL;       }       return res;     }   }   long long int digi[12];   long long int vi[12][100][7];   long long int dp1(long long int i, long long int ld, long long int nu) {     if (i == b) {       if (nu == 6 && ld < b)         return 720;       else         return 0;     }     if (nu == 6) {       if (ld < b)         return 720;       else         return 0;     }     long long int &ret = vi[i][ld][nu];     if (ret != -1) return ret;     ret = 0;     for (long long int j = 1; j <= min(6 - nu, digi[i]); j++) {       ret = (ret + fact(digi[i], j) * dp1(i + 1, j * i + ld, nu + j)) %             1000000007LL;     }     ret = (ret + dp1(i + 1, ld, nu)) % 1000000007LL;     return ret;   }   int main() {     long long int n, m;     scanf( %lld , &n);     h = NTS(n);     long long int tot = 0;     for (long long int i = 1; i <= ((int)h.size()); i++) {       b = i;       memset(vis, -1, sizeof vis);       digi[i] = dp(0, 0, 0);       tot += digi[i];     }     long long int res = 0;     digi[0] = n - tot;     for (int j = 1; j <= ((int)h.size()); j++) {       b = j;       memset(vi, -1, sizeof vi);       res = (res + digi[j] * dp1(0, 0, 0)) % 1000000007LL;     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(1);     cout << fixed;     double n, x, y;     cin >> n >> x >> y;     double s = (y * n) / 100;     int p = ceil(s) - x;     if (p >= 0)       cout << p;     else       cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     cin >> n;     int a, b;     int s1 = 0;     int s2 = 0;     int flag = 0;     while (n--) {       cin >> a >> b;       if ((a & 1) != (b & 1)) flag = 1;       s1 += a;       s2 += b;     }     cerr << s1 <<     << s2 << endl;     int ans = 0;     if (s1 % 2 != s2 % 2) {       ans = -1;     } else {       if (s1 % 2 == 0)         ans = 0;       else if (!flag)         ans = -1;       else         ans = 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     int i;     cin >> m >> n;     double p[m];     double pre[m];     p[0] = pow(1.0 / m, n);     pre[0] = p[0];     for (i = 1; i < m; i++) {       p[i] = pow(double(i + 1) / m, n) - pre[i - 1];       pre[i] = pre[i - 1] + p[i];     }     double a = 0;     for (int k = 1; k <= m; k++) {       a += k * p[k - 1];     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[200] = {}, i, j, k, w, ans = 0;     for (i = 0; i < n; i++) cin >> arr[i];     cin >> w;     sort(arr, arr + n);     for (i = 0; i < n; i++) {       int c = 1;       for (j = i + 1; j < n; j++) {         if (arr[j] - arr[i] <= w)           c++;         else           break;       }       ans = (ans > c ? ans : c);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 200001;   long long n, k;   int main() {     cin >> n >> k;     int p = (n / k) % 2;     cout << (p % 2 == 1 ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   const int INF = (int)1e9;   char ch[N][N];   int n, m, k;   int CountSpider(int x, int y, int time) {     int ans = 0;     if (x - time >= 1 && ch[y][x - time] ==  R ) ans++;     if (x + time <= m && ch[y][x + time] ==  L ) ans++;     if (y - time >= 1 && ch[y - time][x] ==  D ) ans++;     if (y + time <= n && ch[y + time][x] ==  U ) ans++;     return ans;   }   int main() {     scanf( %d%d%d n , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) scanf( %c , &ch[i][j]);       scanf(  n );     }     for (int j = 1; j <= m; ++j) {       int time = 0;       int ans = 0;       for (int i = 1; i <= n; ++i) {         ans += CountSpider(j, i, time);         time++;       }       printf( %d  , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, F, M;     cin >> N >> F >> M;     int FR[200], MO[200];     vector<int> V;     int mi = 10000;     for (int i = 0; i < F; ++i) cin >> FR[i];     for (int j = 0; j < M; ++j) cin >> MO[j];     for (int i = 0; i < F; ++i) {       int cnt = 0;       for (int j = 0; j < M; ++j)         if (MO[j] % FR[i] == 0) cnt++;       if (cnt < mi) {         V.clear();         V.push_back(i + 1);         mi = cnt;       } else if (mi == cnt)         V.push_back(i + 1);     }     cout << V.size() << endl;     for (int i = 0; i < V.size(); ++i) {       if (i < V.size() - 1)         cout << V[i] <<    ;       else         cout << V[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;         void solve(){       int n; scanf( %d , &n);       if (n == 2){           printf( 1 n2 1 n1 n2 1 n );       }       else if (n == 3){           printf( 5 n2 3 1 n2 n1 3 n2 3 n );       }       else {           long long t = 0;           vector<int> ans;           vector<pair<int, int>> vc;           ans.push_back(n / 2 + 1);           for (int i = 3; i <= n / 2; ++i) ans.push_back(i);           ans.push_back(1);           for (int i = n / 2 + 2; i <= n; ++i) ans.push_back(i);           ans.push_back(2);           for (int i = 2; i <= n / 2; ++i){               vc.push_back({i, n});               t += (long long)(n - i) * (n - i);           }           for (int i = n / 2 + 1; i <= n; ++i){               vc.push_back({i, 1});               t += (long long)(i - 1) * (i - 1);           }           printf( %lld n , t);           for (int it : ans) printf( %d  , it);           printf(  n );           printf( %d n , n - 1);           for (auto it : vc){               printf( %d %d n , it.first, it.second);           }       }   }      int main(){       int T; scanf( %d , &T);       while (T--) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long bmm(long long x, long long y) {     if (y) return bmm(y, x % y);     return x;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     long long d = k;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       d = bmm(d, x % k);     }     if (d == k) {       cout << 1 <<   n ;       cout << 0 <<   n ;     } else {       n = (k + d - 1) / d;       cout << n <<   n ;       for (long long i = 0; i < n; i++) cout << i * d <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 2e5 + 4;   int main() {     string s;     int n;     scanf( %d , &n);     cin >> s;     int pre[n], suf[n], minm = 0, bal = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ( ) {         pre[i] = 1;         suf[i] = -1;       } else {         pre[i] = -1;         suf[i] = 1;       }       bal += pre[i];       minm = min(minm, bal);     }     if (bal == 0) {       if (minm > -2) {         printf( Yes );         return 0;       }     }     printf( No );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, o = 0, x = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a)         x++;       else         o++;     }     int s = x / 9;     if (s && o) {       for (int i = 0; i < 9 * s; i++) {         cout << 5;       }       for (int i = 0; i < o; i++) {         cout << 0;       }     } else if (o)       cout << 0;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   char a[200005], b[200005], c[200005];   int v[200005], n, m;   bool verif(int poz) {     int i, j;     for (i = 1; i <= n; i++) c[i] = a[i];     for (i = 1; i <= poz; i++) c[v[i]] = 0;     for (i = 1, j = 1; i <= n && j <= m; i++)       if (c[i] == b[j]) j++;     if (j == m + 1) return true;     return false;   }   int main() {     int i, st, dr, mij, rasp = 0;     char ch;     ch = fgetc(stdin);     while (ch >=  a  && ch <=  z ) {       n++;       a[n] = ch;       ch = fgetc(stdin);     }     ch = fgetc(stdin);     while (ch >=  a  && ch <=  z ) {       m++;       b[m] = ch;       ch = fgetc(stdin);     }     for (i = 1; i <= n; i++) fscanf(stdin,  %d , &v[i]);     st = 1;     dr = n;     while (st <= dr) {       mij = (st + dr) / 2;       if (verif(mij) == true) {         rasp = mij;         st = mij + 1;       } else {         dr = mij - 1;       }     }     fprintf(stdout,  %d , rasp);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, c, ans;   int main() {     cin >> n >> a >> b >> c;     if (n >= b)       ans = (n - ((n - b) / (b - c) + 1) * (b - c)) / a + (n - b) / (b - c) + 1;     cout << max(n / a, ans);   }


#include <bits/stdc++.h>   using namespace std;   inline string to_string(char c) {     string s;     s.push_back(c);     return s;   }   struct Node {     bool can_delete_all = true;     char first_cant = 0;     bool more = false;     string first =   ;     string last =   ;     int ans_len = 0;     Node(bool can_delete_all = true, char first_cant = 0, bool more = false,          string first =   , string last =   , int ans_len = 0)         : can_delete_all(can_delete_all),           first_cant(first_cant),           more(more),           first(first),           last(last),           ans_len(ans_len) {}     friend Node operator+(pair<int, char> p, Node n) {       auto [len, c] = p;       if (n.can_delete_all)         return Node(len % 2 == 0, c, false, (len % 2 == 0 ?    : to_string(c)),                     (len % 2 == 0 ?    : to_string(c)), len % 2);       auto add = [](string &first, string &last, int len, char c, int &ans_len) {         ans_len += len;         reverse(last.begin(), last.end());         for (int i = 0; i < len && (int)last.size() < 2; i++) last.push_back(c);         reverse(last.begin(), last.end());         reverse(first.begin(), first.end());         for (int i = 0; i < len && i < 12; i++) first.push_back(c);         reverse(first.begin(), first.end());         while ((int)first.size() > 12) first.pop_back();       };       if (c == n.first_cant) {         if (n.more)           add(n.first, n.last, len, c, n.ans_len);         else           add(n.first, n.last, len % 2, c, n.ans_len);         return n;       }       if (c < n.first_cant) {         add(n.first, n.last, len, c, n.ans_len);         n.more = true;         n.first_cant = c;         return n;       }       assert(c > n.first_cant);       if (len % 2 == 0) return n;       add(n.first, n.last, 1, c, n.ans_len);       n.more = false;       n.first_cant = c;       return n;     }     void print() {       cout << ans_len <<    ;       if (ans_len <= 10)         cout << first <<   n ;       else         cout << first.substr(0, 5) <<  ...  << last <<   n ;     }   };   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     int n = (int)s.size();     vector<pair<int, int>> segs;     for (int i = 0; i < n;) {       int j = i;       while (j < n && s[i] == s[j]) j++;       segs.emplace_back(i, j);       i = j;     }     int m = (int)segs.size();     segs.emplace_back(n, n);     vector<Node> dp(m + 1);     for (int i = m - 1; i >= 0; i--)       dp[i] = pair<int, char>{segs[i].second - segs[i].first, s[segs[i].first]} +               dp[i + 1];     int segi = 0;     pair<int, char> cur;     for (int i = 0; i < n; i++) {       while (segs[segi].first < i) segi++;       if (segs[segi].first == i) {         dp[segi].print();         cur = {segs[segi].second - segs[segi].first, s[segs[segi].first]};         cur.first--;       } else {         (cur + dp[segi]).print();         cur.first--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   int a[MAXN], ans[MAXN];   pair<int, int> tab[MAXN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       cin >> tab[i].first;       tab[i].second = i;     }     sort(a, a + n, greater<int>());     sort(tab, tab + n);     for (int i = 0; i < n; i++) ans[tab[i].second] = a[i];     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[15][123];   int b[15][123];   int c[15][123];   vector<int> v;   bool cmp(int x, int y) { return x > y; }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j];     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (i == j) continue;         v.clear();         for (int h = 0; h < m; h++)           for (int t = 0; t < c[i][h]; t++)             if (b[j][h] - a[i][h] > 0) v.push_back(b[j][h] - a[i][h]);         sort(v.begin(), v.end(), cmp);         int tmp = 0;         for (int h = 0; h < min(k, (int)v.size()); h++) tmp += v[h];         ans = max(ans, tmp);       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const inf = 1000 * 1000 * 1000;   long long const inf64 = 1ll * inf * inf;   struct Fenwick {     int n;     vector<long long> fen;     Fenwick() { n = 0; }     Fenwick(int nn) {       n = nn;       fen.resize(n + 1);     }     void put(int pos, int val) {       for (int cur = pos; cur <= n; cur |= (cur + 1)) fen[cur] += val;     }     long long get(int pos) {       long long res = 0;       for (int cur = pos; cur > 0; cur = (cur & (cur + 1)) - 1) res += fen[cur];       return res;     }     long long get(int l, int r) { return get(r) - get(l - 1); }   };   bool solve() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     vector<vector<pair<pair<int, int>, int> > > add(m + 1);     for (int i = 1; i <= m; i++) add[i].reserve(n);     for (int len, i, j, w, iter = 0; iter < k; iter++) {       scanf( %d , &len);       for (int iter2 = 0; iter2 < len; iter2++) {         scanf( %d %d %d , &i, &j, &w);         add[j].push_back({{i, w}, iter});       }     }     int q;     scanf( %d , &q);     vector<char> type(q);     vector<int> sw(q);     vector<pair<int, int> > ask(q);     vector<vector<long long> > res(2005, vector<long long>(k));     vector<vector<int> > era(m + 1), ins(m + 1);     vector<int> ide(q);     char buffer[10];     for (int i, x1, y1, x2, y2, iter = 0; iter < q; iter++) {       scanf( %s , buffer);       if (string(buffer) ==  SWITCH ) {         scanf( %d , &i);         type[iter] = 0;         sw[iter] = i - 1;       } else {         scanf( %d %d %d %d , &x1, &y1, &x2, &y2);         type[iter] = 1;         ask[iter] = {x1, x2};         ins[y1].push_back(iter);         era[y2].push_back(iter);         static int rectange_size = 0;         ide[iter] = rectange_size++;       }     }     vector<Fenwick> fen(k, Fenwick(n));     for (int pos, value, id, l, r, j = 1; j <= m; j++) {       for (int iter : ins[j]) {         tie(l, r) = ask[iter];         for (int kk = 0; kk < k; kk++) {           res[ide[iter]][kk] -= fen[kk].get(l, r);         }       }       for (auto _iter : add[j]) {         tie(pos, value) = _iter.first;         id = _iter.second;         fen[id].put(pos, value);       }       for (int iter : era[j]) {         tie(l, r) = ask[iter];         for (int kk = 0; kk < k; kk++) {           res[ide[iter]][kk] += fen[kk].get(l, r);         }       }     }     vector<char> state(k, 1);     for (int iter = 0; iter < q; iter++) {       if (type[iter] == 0) {         state[sw[iter]] ^= 1;       } else {         long long result = 0;         for (int i = 0; i < k; i++) {           if (state[i]) result += res[ide[iter]][i];         }         printf( %I64d n , result);       }     }     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> id;   vector<int> a[100005];   int main() {     int i, j, k, n;     cin >> n;     cout << n - 1 << endl;     int idd = 1;     for (k = (1); k <= (n - 1); k++) {       cin >> i >> j;       a[i].push_back(j);       a[j].push_back(i);       id[make_pair(i, j)] = idd;       id[make_pair(j, i)] = idd++;       printf( 2 %d %d n , i, j);     }     for (i = (1); i <= (n); i++)       for (j = 1; j < a[i].size(); j++) {         cout << id[make_pair(i, a[i][j - 1])] <<     << id[make_pair(i, a[i][j])]              << endl;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   char a[30];   int main() {     cin >> t;     while (t--) {       string s;       cin >> s;       int len = s.size(), id = 0;       for (int i = 0; i < len; i++) {         int temp = 1;         while (s[i + 1] == s[i]) {           i++;           temp++;         }         if (temp % 2 == 0) continue;         int flag = 0;         for (int j = 0; j < id; j++) {           if (a[j] == s[i]) {             flag = 1;             break;           }         }         if (!flag) a[id++] = s[i];       }       if (!id)         cout << endl;       else {         sort(a, a + id);         for (int i = 0; i < id; i++) cout << a[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(long long &a, long long &b) {     long long t = a;     a = b;     b = t;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       set<long long> s;       long long arr[n];       for (long long i = 0; i < n; i++) {         cin >> arr[i];         s.insert(arr[i]);       }       if (n > 1 && s.size() > 1 && k == 1) {         cout << -1 << endl;         continue;       }       if (s.size() == 1) {         cout << 1 << endl;         continue;       }       long long count = 0;       while (1) {         if (s.size() == 1) {           break;         }         set<long long> s1;         long long j = 0;         long long last = 0;         for (auto x : s) {           if (j < k) {             s1.insert(0);             j++;             last = x;           } else {             s1.insert(x - last);             j++;           }         }         count++;         s = s1;       }       cout << count << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 19;   int a[1 << N];   int main() {     int n, q;     cin >> n >> q;     long long sum = 0;     for (int i = 0; i < (1 << n); i++) cin >> a[i], sum += a[i];     cout << setprecision(10) << 1.0 * sum / (1 << n) <<   n ;     for (int i = 0; i < q; i++) {       int id, v;       cin >> id >> v;       sum += v - a[id];       a[id] = v;       cout << setprecision(10) << 1.0 * sum / (1 << n) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int p(string s) {     string a = s;     s +=  # ;     reverse(a.begin(), a.end());     s += a;     int n = s.size();     vector<int> pi(n);     pi[0] = 0;     int j = 0;     for (int i = 1; i < n; i++) {       j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) j++;       pi[i] = j;     }     return j;   }   int main() {     int t = 1;     cin >> t;     while (t--) {       string s;       cin >> s;       int cnt = 0;       int n = s.size();       for (int i = 0; i < n / 2; i++) {         if (s[i] != s[n - 1 - i]) break;         cnt++;       }       string ans;       if (cnt > 0) cout << s.substr(0, cnt);       ;       string a = s;       reverse(a.begin(), a.end());       int pos = p(s.substr(cnt, n - 2 * cnt));       string w = s.substr(cnt, pos);       pos = p(a.substr(cnt, n - 2 * cnt));       w = (pos > w.length()) ? a.substr(cnt, pos) : w;       cout << w;       if (cnt > 0) cout << s.substr(n - cnt, cnt);       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     deque<char> vec;     cin >> s;     for (int i = 0; i < s.size(); ++i) vec.push_back(s[i]);     int cnt = 0, i;     while (vec.size() > 1) {       if (vec[vec.size() - 1] ==  0 ) {         ++cnt;         vec.pop_back();       } else {         for (i = vec.size() - 1; i >= 0; --i) {           if (vec[i] ==  0 ) break;           vec[i] =  0 ;         }         if (i < 0)           vec.push_front( 1 );         else           vec[i] =  1 ;         ++cnt;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<long long> v;   vector<pair<pair<long long, long long>, long long> > vv;   vector<long long> ary;   void update(int pos, long long val, int mx) {     while (pos <= mx) {       ary[pos] += val;       pos += pos & -pos;     }   }   long long get(int pos, int mx) {     long long re = 0;     while (pos > 0) {       re += ary[pos];       pos -= pos & -pos;     }     return re;   }   int main(void) {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     v.resize(n);     for (int i = 0; i < (n); i++) cin >> v[i];     vv.resize(m);     for (int i = 0; i < (m); i++)       cin >> vv[i].first.first >> vv[i].first.second >> vv[i].second;     ary.resize(m + 1, 0);     for (int i = 0; i < (k); i++) {       long long t, tt;       cin >> t >> tt;       update(t, 1, m);       update(tt + 1, -1, m);     }     for (int i = 0; i < (m); i++) {       vv[i].second *= get(i + 1, m);     }     ary.clear();     ary.resize(n + 2, 0);     for (int i = 0; i < (m); i++) {       update(vv[i].first.first, vv[i].second, n);       update(vv[i].first.second + 1, -vv[i].second, n);     }     for (int i = 0; i < (n); i++) {       v[i] += get(i + 1, n);     }     for (int i = 0; i < (n); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int X, t[10000], h[10000], m[10000], v[10000];   int f(int x) {     int ht = X;     memset(v, 0, sizeof(v));     for (int i = (0); i < (n); i++) {       int tmp = -1;       for (int j = (0); j < (n); j++) {         if (v[j] || t[j] != ((i + x) & 1) || h[j] > ht) continue;         if (tmp == -1) tmp = j;         if (m[j] > m[tmp]) tmp = j;       }       if (tmp == -1) return i;       ht += m[tmp];       v[tmp] = 1;     }     return n;   }   int main() {     scanf( %d%d , &n, &X);     for (int i = (0); i < (n); i++) scanf( %d%d%d , t + i, h + i, m + i);     int ans = 0, tmp = 0;     ans = f(0);     ans = max(ans, f(1));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   set<string> aux;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> s;       string ns =   ;       for (int j = 0; j < s.size(); j++) {         if (s[j] ==  u )           ns +=  oo ;         else if (s[j] ==  h ) {           while (!ns.empty() && ns.back() ==  k ) ns.pop_back();           ns += s[j];         } else           ns += s[j];       }       aux.insert(ns);     }     printf( %d n , aux.size());     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int   #define inf 1e18   #define F first   #define S second   #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define pb push_back   #define pll pair<ll,ll>   #define vl vector<ll>   #define all(x) (x).begin(),(x).end()   #define siz 300005   #define MOD   998244353   vector<vector<ll> > adj(siz);   vector<ll> vis(siz,0);   ll mod=MOD;   ll power(ll x, ll y){       if (y == 0)           return 1;       else if (y % 2 == 0)           return ((power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod;       else           return (x%mod * (power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod;   }   ll foo(ll n){    return ( n*(n+1) )/2;   }   int main(){    ll q=1;    cin>>q;    while(q--){     string s;     cin>>s;     ll n=s.size(),gap=0,last=-1,l=0,r=0,ans=0;     while(l<n){      //cout<<last<<   <<l<<   <<r<<   <<ans<<endl;      if(r==n or (last!=-1 and s[r]!= ?  and        ((s[r]!=s[last] and gap%2==1)        or(s[r]==s[last] and gap%2==0)) ) ){       if(r==n){        ans+=foo(r-l);        break;       }       ll nl=last+1;       ans+=(foo(r-l)-foo(r-nl));       if(last<nl)last=-1;l=nl;      }      else{       if(s[r]!= ? ){last=r;gap=0;}       else gap++;       r++;      }     }     cout<<ans<<endl;    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, l;     cin >> n >> m;     k = (n - m) / 2;     j = 1;     while (j <= n) {       if (j % (k + 1) == 0) {         cout <<  1 ;       } else {         cout <<  0 ;       }       j++;     }   }