#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     char arr[1000];     cin >> arr;     int flag = 1, curr = 0;     for (int i = 0; i < strlen(arr); i++) {       if (i == 0)         curr = 1;       else if (flag == 1) {         if (arr[i] == arr[i - 1]) {           curr++;           if (curr >= 7) {             flag = 0;             cout <<  YES ;             return 0;           }         } else {           curr = 1;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int sf[26][200005], tf[26][200005];   int main() {     long long int n, i, j;     cin >> n;     double ans = 0.0;     string s, t;     cin >> s >> t;     for (i = 0; i < n; ++i) {       sf[s[i] -  A ][i] += (i + 1);       tf[t[i] -  A ][i] += (i + 1);       if (i)         for (j = 0; j < 26; ++j) {           sf[j][i] += sf[j][i - 1];           tf[j][i] += tf[j][i - 1];         }       ans = ans + (n - i) * ((i ? sf[t[i] -  A ][i - 1] : 0) + tf[s[i] -  A ][i]);     }     ans = (6 * ans) / (n * (n + 1) * (2 * n + 1));     cout << fixed << setprecision(8) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   long long a[maxn], b[maxn], c[maxn];   int num[64];   int n;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> c[i];     long long sum = 0;     for (int i = 0; i < n; i++) {       a[i] = b[i] + c[i];       sum += a[i];     }     if (sum % (2 * n)) {       cout << -1 << endl;       return 0;     }     sum /= 2 * n;     for (int i = 0; i < n; i++) {       a[i] = (a[i] - sum);       if (a[i] % n) {         cout << -1 << endl;         return 0;       } else {         a[i] /= n;       }     }     for (int i = 0; i < n; i++) {       long long temp = a[i];       for (int j = 0; j < 64; j++) {         num[j] += temp % 2;         temp /= 2;       }     }     for (int i = 0; i < n; i++) {       long long b_ = 0, c_ = 0;       for (int j = 0; j < 64; j++) {         if (a[i] & (1LL << j)) {           b_ += num[j] * (1LL << j);           c_ += n * (1LL << j);         } else           c_ += num[j] * (1LL << j);       }       if (b_ != b[i] || c_ != c[i]) {         cout << -1 << endl;         return 0;       }     }     cout << a[0];     for (int i = 1; i < n; i++) {       cout <<     << a[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> v(n, 0);       priority_queue<pair<long long int, pair<long long int, long long int>>> pq;       pq.push({n, {0, n - 1}});       long long int count = 0;       while (!pq.empty()) {         long long int l = -1 * pq.top().second.first;         long long int r = pq.top().second.second;         long long int length = pq.top().first;         pq.pop();         if (l > r) {           continue;         }         count++;         long long int mid = (l + r) / 2;         v[mid] = count;         pq.push({mid - l + 1, {(-1 * l), mid - 1}});         pq.push({r - mid + 1, {-1 * (mid + 1), r}});       }       for (auto it : v) {         cout << it <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool isPal(string s) {     for (long long i = 0, j = s.length() - 1; i < j; i++, j--)       if (s[i] != s[j]) return 0;     return 1;   }   string lts111(long long n) {     string a =  00:00 ;     long long hr = n / 60;     long long min = n % 60;     long long fh = hr % 10;     hr = hr / 10;     a[0] = hr + 48;     a[1] = fh + 48;     fh = min % 10;     min = min / 10;     a[3] = min + 48;     a[4] = fh + 48;     return a;   }   long long stl111(string s) {     long long hr = (s[0] - 48) * 10 + (s[1] - 48);     long long min = (s[3] - 48) * 10 + (s[4] - 48);     return hr * 60 + min;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     long long m = stl111(s);     m = m + 1;     while (1) {       m = m % 1440;       s = lts111(m);       if (isPal(s)) {         cout << s << endl;         return 0;       }       m = m + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 0;     int temp;     stack<int> st;     for (int i = 0; i < n; ++i) {       cin >> temp;       while (!st.empty() && st.top() < temp) {         ans = max(ans, (st.top() ^ temp));         st.pop();       }       if (!st.empty()) ans = max(ans, (st.top() ^ temp));       st.push(temp);     }     temp = st.top();     st.pop();     while (!st.empty()) {       ans = max(ans, (st.top() ^ temp));       temp = st.top();       st.pop();     }     cout << ans, cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int fastExpo(long long int a, long long int n, long long int mod) {     long long int result = 1;     while (n > 0) {       if (n & 1) result = (result * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return result;   }   long long int modInverse(long long int n, long long int mod) {     return fastExpo(n, mod - 2, mod);   }   vector<long long int> factorial(long long int n) {     std::vector<long long int> fac(n + 2, 0);     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % 1000000007;     return fac;   }   long long int __nCr(long long int n, long long int r,                       vector<long long int>& Fact, long long int mod) {     long long int ans = (((Fact[n] * modInverse(Fact[r], mod)) % mod) *                          modInverse(Fact[n - r], mod)) %                         mod;     return ans;   }   void runcases(long long int T) {     string s, p;     cin >> s >> p;     s = p +  #  + s;     long long int n = s.size();     long long int m = p.size();     long long int count = 0;     vector<long long int> lps(n, 0);     long long int j = 0;     for (long long int i = 1; i < n; i++) {       j = lps[i - 1];       while (j > 0 && s[i] != s[j]) {         j = lps[j - 1];       }       if (s[i] == s[j]) {         j++;       }       lps[i] = j;       if (lps[i] == m) {         s[i] =  * ;         count++;         lps[i] = 0;       }     }     cout << count <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     for (long long int t = 1; t <= T; t++) {       runcases(t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> num, sum;   int NUM[1005], Ind[1005];   int Set[1005];   int Top_sort(int n, int m) {     queue<int> q;     int i, j, ret;     for (i = 1; i <= n; i++)       if (Ind[i] == 0) q.push(i);     while (!q.empty()) {       i = q.front(), q.pop();       int now = 0, tab = 0;       for (j = i; true; j = NUM[j]) {         if (j == m) tab = 1, now = 0;         if (now++, NUM[j] == 0) break;       }       if (tab == 0)         num.push_back(now);       else         ret = now;     }     return ret;   }   int main() {     int n, m, i, j;     for (i = 1, scanf( %d%d , &n, &m); i <= n; i++)       if (scanf( %d , &NUM[i]), NUM[i]) Ind[NUM[i]]++;     int ans = Top_sort(n, m), end = 0;     Set[0] = 1;     for (i = 0; i < num.size(); i++)       for (j = end; j >= 0; j--)         if (Set[j]) Set[j + num[i]] = 1, end = max(end, j + num[i]);     for (j = 0; j <= end; j++)       if (Set[j]) printf( %d n , ans + j);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MOD = 1e9 + 7;   const int MOD2 = 1e9 + 9;   const int PR = 727;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   struct node {     int x;     int k;     int m;   };   const int N = 1e2 + 20;   const int M = 21;   long long dp[1 << M], n, m, b, ans = LINF;   node a[N];   bool cmp(node x, node y) { return x.k < y.k; }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> b;     for (int i = 0, mi; i < n; i++) {       cin >> a[i].x >> a[i].k >> mi;       for (int j = 0, x; j < mi; j++) {         cin >> x;         a[i].m += (1 << (x - 1));       }     }     sort(a, a + n, cmp);     memset(dp, 63, sizeof dp);     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (int mask = 1; mask < (1 << m); mask++)         if (mask & a[i].m)           dp[mask] = min(dp[mask], dp[mask ^ (mask & a[i].m)] + a[i].x);       ans = min(ans, (dp[(1 << m) - 1] == dp[(1 << M) - 1]                           ? LINF                           : dp[(1 << m) - 1] + a[i].k * b));     }     cout << (ans == LINF ? -1 : ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e6 + 50;   const int oo = 1e9;   const int mod = 1e9 + 7;   long long a[N];   int main() {     long long n, m;     cin >> n >> m;     long long c = 1;     int cur = 0;     for (int i = 30; i; i--) {       while (n >= (1 << i) - 1) {         for (int j = 1; j <= i; j++) a[cur++] = c;         c += m;         n -= (1 << i) - 1;       }     }     cout << cur << endl;     for (int i = 0; i < cur; i++) cout << a[i] <<    ;     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     long long res = 0;     while (a >= 1 && b >= 1) {       if (a < b) swap(a, b);       res += a / b;       a %= b;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     string s;     cin >> s;     map<int, int> cnt;     for (int i = 0; i < s.size(); ++i) {       cnt[s[i] -  0 ]++;     }     cnt[1]--;     cnt[6]--;     cnt[8]--;     cnt[9]--;     string ans =   ;     for (int i = 1; i <= 9; ++i) {       for (int j = 0; j < cnt[i]; ++j) ans += (char)( 0  + i);     }     int powr = 1;     int su = 0;     for (int i = 0; i < ans.size(); ++i) {       su = su * 10 + (ans[i] -  0 );       su %= 7;     }     vector<int> perm = {1, 6, 8, 9};     do {       int n =           su * 10000 + perm[0] * 1000 + perm[1] * 100 + perm[2] * 10 + perm[3];       if (n % 7 == 0) {         cout << ans;         for (int x : perm) cout << x;         for (int i = 0; i < cnt[0]; ++i) cout << 0;         return 0;       }     } while (next_permutation(perm.begin(), perm.end()));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n, long long m) {     long long ret = n % m;     if (ret < 0) ret += m;     return ret;   }   long long gcd(long long a, long long b) {     return (b == 0LL ? a : gcd(b, a % b));   }   long long exp(long long a, long long b, long long m) {     if (b == 0LL) return 1LL;     if (b == 1LL) return mod(a, m);     long long k = mod(exp(a, b / 2, m), m);     if (b & 1LL) {       return mod(a * mod(k * k, m), m);     } else       return mod(k * k, m);   }   long long modpow(long long b, long long e, long long mod) {     long long ans = 1;     for (; e; b = b * b % mod, e /= 2)       if (e & 1) ans = ans * b % mod;     return ans;   }   const int N = 1e6 + 10;   int p[N];   bool vis[N];   int n;   int dp[2][N];   int cnt[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     vector<int> tam;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         int cur = p[i];         vis[cur] = 1;         int t = 1;         while (cur != i) {           t++;           cur = p[cur];           vis[cur] = 1;         }         tam.push_back(t);       }     }     int mx = 0;     int kk = k;     for (int x : tam) {       int poe = min(kk, x / 2);       kk -= poe;       mx += poe * 2;     }     mx += kk;     mx = min(mx, n);     for (int x : tam) cnt[x]++;     sort(tam.begin(), tam.end());     tam.erase(unique(tam.begin(), tam.end()), tam.end());     int tot = 0;     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     kk = 0;     for (int i = 1; i <= (int)tam.size(); i++) {       int val = tam[i - 1];       int prv = (i - 1) & 1;       int cur = (i & 1);       kk += val * cnt[val];       for (int j = 0; j <= kk; j++) {         if (dp[prv][j] >= 0)           dp[cur][j] = 0;         else if (j - val >= 0 and dp[cur][j - val] >= 0 and                  dp[cur][j - val] < cnt[val]) {           dp[cur][j] = dp[cur][j - val] + 1;         } else           dp[cur][j] = -1;       }     }     int mn = 0;     if (dp[(int)tam.size() & 1][k] != -1) {       mn = k;     } else       mn = min(n, k + 1);     cout << mn <<     << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 1e6 + 7, K = 21, M = 1e9 + 7;   long long n;   signed dp[MAX_N][K][2];   long long get(long long x) {     if (x > n) return 0;     return (n / x);   }   signed main() {     memset(dp, 0, sizeof(dp));     cin >> n;     long long poww = 0, cur = 1;     while (cur * 2 <= n) {       cur *= 2;       poww++;     }     dp[1][poww][0] = 1;     if ((cur / 2) * 3 <= n) dp[1][poww - 1][1] = 1;     for (long long i = 1; i < n; i++) {       for (long long j = 0; j <= poww; j++) {         for (long long k = 0; k <= 1; k++) {           long long t = 1;           if (k == 1) t = 3;           dp[i + 1][j][k] =               (dp[i + 1][j][k] + dp[i][j][k] * (get((1 << j) * t) - i)) % M;           if (j > 0)             dp[i + 1][j - 1][k] =                 (dp[i + 1][j - 1][k] +                  dp[i][j][k] * (get((1 << (j - 1)) * t) - get((1 << j) * t))) %                 M;           if (k == 1)             dp[i + 1][j][0] = (dp[i + 1][j][0] +                                dp[i][j][k] * (get(1 << j) - get((1 << j) * t))) %                               M;         }       }     }     cout << dp[n][0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug(int n, ...) {     va_list v1;     va_start(v1, n);     for (int i = 0; i < n; i++) {       int val = va_arg(v1, int);       printf( %d  , val);     }     va_end(v1);     printf(  n );   }   double n, k;   double sum;   int ans;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       double m;       cin >> m;       sum += m;     }     while (sum / (double)n < (k - 0.5)) {       sum += k;       ans++;       n++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long const M = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;   long long par[M][30], dp[M], zt[M], sum[M], val[M][30], sum2[M], n, dp2[M],       len = 0, h[M];   vector<long long> adj[M], edg[M], inc[M];   long long mrg(long long x, long long y, long long sm, long long cnt) {     long long ans = (x + ((y * y) % mod) * cnt + ((sm * y) % mod) * 2) % mod;     return ans;   }   void dfs_down(long long v, long long l, long long c) {     zt[v] = 1;     val[v][0] = c;     h[v] = h[l] + 1;     par[v][0] = l;     for (long long i = 1; i <= 20; i++) {       par[v][i] = par[par[v][i - 1]][i - 1];       val[v][i] = val[par[v][i - 1]][i - 1] + val[v][i - 1];       val[v][i] %= mod;     }     for (long long i = 0; i < adj[v].size(); i++) {       long long u = adj[v][i];       if (u != l) dfs_down(u, v, edg[v][i]);       if (u == l) {         inc[v].push_back(0);         continue;       }       zt[v] += zt[u];       sum[v] += sum[u];       sum[v] %= mod;       sum[v] += edg[v][i] * zt[u];       sum[v] %= mod;       long long res = mrg(dp[u], edg[v][i], sum[u], zt[u]);       inc[v].push_back(res);       dp[v] += res;       dp[v] %= mod;     }     dp2[v] = dp[v];   }   void dfs_up(long long v, long long l, long long c, long long cc) {     if (v == 1) sum2[v] = sum[v];     if (v != 1) {       sum2[v] += (sum2[l] - ((cc * zt[v] + sum[v]) % mod) + mod) % mod;       sum2[v] %= mod;       long long res = dp[l] - c;       res += mod;       res %= mod;       dp[v] += mrg(res, cc, sum2[v], n - zt[v]);       dp[v] %= mod;       sum2[v] += sum[v];       sum2[v] %= mod;       sum2[v] += cc * (n - zt[v]);       sum2[v] %= mod;     }     for (long long i = 0; i < adj[v].size(); i++) {       long long u = adj[v][i];       if (u != l) dfs_up(u, v, inc[v][i], edg[v][i]);     }   }   long long lca(long long v, long long u) {     if (h[v] < h[u]) swap(v, u);     for (long long i = 20; i >= 0; i--) {       if (h[v] - (1 << i) >= h[u]) len += val[v][i], v = par[v][i];     }     len %= mod;     if (v == u) return v;     for (long long i = 20; i >= 0; i--) {       if (par[v][i] != par[u][i])         len += val[v][i], len += val[u][i], v = par[v][i], u = par[u][i];     }     len += val[v][0];     len += val[u][0];     len %= mod;     v = par[v][0];     return v;   }   int32_t main() {     cin >> n;     for (long long i = 1; i <= n - 1; i++) {       long long a, b, c;       cin >> a >> b >> c;       adj[a].push_back(b);       adj[b].push_back(a);       edg[a].push_back(c);       edg[b].push_back(c);     }     dfs_down(1, 0, 0);     dfs_up(1, 0, 0, 0);     long long q;     cin >> q;     while (q--) {       long long v, u;       cin >> u >> v;       len = 0;       long long lc = lca(u, v);       len %= mod;       long long all = 0;       if (lc != v) {         all = -dp[u];         all += mod;         all %= mod;         long long res = mrg(dp2[v], len, sum[v], zt[v]);         all += res * 2;         all %= mod;       } else {         all = dp[u];         long long res = sum2[v] - sum[v];         long long bad = dp[v] - dp2[v];         bad += mod;         bad %= mod;         res += mod;         res %= mod;         long long hlp = mrg(bad, len, res, n - zt[v]);         all -= 2 * hlp;         all += 3 * mod;         all %= mod;       }       cout << all <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void Read(int &x) {     static char c;     while (!isdigit(c = getchar()))       ;     x = (c ^ 48);     while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);     return;   }   void Print(int x, char end) {     static int i;     for (i = 1; i * 10LL <= x; i *= 10)       ;     for (; i; i /= 10) putchar(x / i % 10 | 48);     putchar(end);     return;   }   inline int mmin(int a, int b) { return a < b ? a : b; }   inline int mmax(int a, int b) { return a > b ? a : b; }   inline void Swap(int &a, int &b) {     static int t;     t = a, a = b, b = t;     return;   }   set<int> rm;   int n, q, a[(200005)], pre[(200005)], nxt[(200005)], gd[(200005)], b2[(200005)],       b3[(200005)], b4[(200005)], cnt[(200005)], stk1[(200005)], p1[(200005)],       tot1, stk2[(200005)], p2[(200005)], tot2, Log2[(200005)];   pair<int, int> maxa[20][(200005)], mina[20][(200005)], st[20][(200005)];   void init_ST_A() {     int i, j;     Log2[1] = 0;     for (i = 2; i <= n; ++i) Log2[i] = Log2[i >> 1] + 1;     for (i = 1; i <= n; ++i) {       mina[0][i].first = a[i], mina[0][i].second = i;       maxa[0][i] = mina[0][i];     }     for (i = 1; (1 << i) <= n; ++i)       for (j = 1; j + (1 << i) - 1 <= n; ++j) {         mina[i][j] = min(mina[i - 1][j], mina[i - 1][j + (1 << (i - 1))]);         maxa[i][j] = max(maxa[i - 1][j], maxa[i - 1][j + (1 << (i - 1))]);       }     return;   }   void init_ST_B() {     int i, j;     for (i = 1; i <= n; ++i) st[0][i].first = b4[i], st[0][i].second = i;     for (i = 1; (1 << i) <= n; ++i)       for (j = 1; j + (1 << i) - 1 <= n; ++j)         st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);     return;   }   inline int AskMinA(int l, int r) {     int k = Log2[r - l + 1];     return min(mina[k][l], mina[k][r - (1 << k) + 1]).second;   }   inline int AskMaxA(int l, int r) {     int k = Log2[r - l + 1];     return max(maxa[k][l], maxa[k][r - (1 << k) + 1]).second;   }   inline pair<int, int> AskMinB(int l, int r) {     int k = Log2[r - l + 1];     return min(st[k][l], st[k][r - (1 << k) + 1]);   }   int main() {     int L, R, pt;     pair<int, int> p;     Read(n);     Read(q);     for (int i = 1; i <= n; ++i) Read(a[i]);     init_ST_A();     pt = 0;     pre[0] = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] != a[i - 1]) pt = i - 1;       pre[i] = pt;     }     pt = n + 1;     nxt[n + 1] = n + 1;     for (int i = n; i; --i) {       if (a[i] != a[i + 1]) pt = i + 1;       nxt[i] = pt;     }     gd[n + 1] = gd[n] = n + 1;     for (int i = n - 1; i > 1; --i)       gd[i] = (pre[i] && nxt[i] != n + 1 &&                ((a[pre[i]] < a[i] && a[i] > a[nxt[i]]) ||                 (a[pre[i]] > a[i] && a[i] < a[nxt[i]])))                   ? (i)                   : (gd[i + 1]);     stk1[0] = stk2[0] = n + 1;     rm.insert(n + 1);     for (int i = n; i; --i) {       while (tot1 && a[i] < a[stk1[tot1]]) {         if ((++cnt[stk1[tot1]]) == 2) rm.insert(stk1[tot1]);         --tot1;       }       stk1[++tot1] = i;       p1[tot1] =           ((a[stk1[tot1 - 1]] == a[i]) ? (p1[tot1 - 1]) : (stk1[tot1 - 1]));       while (tot2 && a[i] > a[stk2[tot2]]) {         if ((++cnt[stk2[tot2]] == 2)) rm.insert(stk2[tot2]);         --tot2;       }       stk2[++tot2] = i;       p2[tot2] =           ((a[stk2[tot2 - 1]] == a[i]) ? (p2[tot2 - 1]) : (stk2[tot2 - 1]));       b4[i] = *rm.lower_bound(mmax(p1[tot1], p2[tot2]));       if (b4[i] != n + 1) {         b2[i] = AskMinA(i, b4[i]);         b3[i] = AskMaxA(i, b4[i]);         if (b2[i] > b3[i]) Swap(b2[i], b3[i]);       }     }     init_ST_B();     while (q--) {       Read(L);       Read(R);       p = AskMinB(L, R);       if (p.first <= R) {         Print(4,   n );         Print(p.second,    );         Print(b2[p.second],    );         Print(b3[p.second],    );         Print(p.first,   n );       } else {         pt = gd[nxt[L]];         if (nxt[pt] > R) {           Print(0,   n );           putchar(  n );         } else {           Print(3,   n );           Print(pre[pt],    );           Print(pt,    );           Print(nxt[pt],   n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int n, k, dep[N], fa[N];   bitset<N> s[2], t[4], a, b;   vector<bitset<N> > S;   inline bitset<N> qry(bitset<N> x, int y) {     y = min(y, n - 1);     char c[N];     putchar( ? );     for (int i = 1; i <= n; i++) printf(  %d , x[i] ? y : 0);     puts(  );     fflush(stdout);     scanf( %s , c + 1);     for (int i = 1; i <= n; i++)       if (c[i] ==  1 ) x[i] = 1;     return x;   }   int main() {     scanf( %d , &n);     while ((1 << k) <= n) k++;     s[0][1] = 1;     for (int i = 1; i <= n; i++) a[i] = 1;     S.push_back(a);     for (int i = k - 1; ~i; i--) {       int len = 1 << i;       for (int j = 0; j < 4; j++) t[j] = qry(s[j & 1], len - (j >> 1));       s[0] |= s[1];       s[1].reset();       vector<bitset<N> > nS;       for (int j = 0; j < S.size(); j++) {         a = t[j & 1] & S[j];         b = t[(j & 1) + 2] & S[j];         s[1] |= a ^ b;         nS.push_back(b);         nS.push_back(S[j] ^ b);       }       S = nS;     }     for (int i = 0; i < S.size(); i++)       for (int j = 1; j <= n; j++)         if (S[i][j]) dep[j] = i;     for (int i = 0; i < 3; i++)       for (int j = 0; j < k; j++) {         a.reset();         for (int x = 1; x <= n; x++) a[x] = (dep[x] % 3 == i && (x >> j & 1));         a = qry(a, 1);         for (int x = 1; x <= n; x++)           fa[x] |= ((dep[x] + 2) % 3 == i && a[x]) << j;       }     puts( ! );     for (int i = 2; i <= n; i++) printf( %d %d n , fa[i], i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n, m, a[N], b[N], t[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i], &b[i]);     int x = a[1], cnt = 0;     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = b[1], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = a[2], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = b[2], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     return puts( NO ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, pos[100001];   vector<int> d[100001];   void sieve() {     memset(d, 0, sizeof(d));     for (int i = 1; i < 100001; i++)       for (int j = i; j < 100001; j += i) d[j].push_back(i);     memset(pos, 0, sizeof(pos));   }   int main() {     sieve();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       if (y == 0) {         printf( %d n , d[x].size());         for (int j = 0; j < d[x].size(); j++) pos[d[x][j]] = i;         continue;       }       int Count = 0;       for (int j = 0; j < d[x].size(); j++) {         int num = d[x][j];         if (pos[num] < i - y) Count++;         pos[num] = i;       }       printf( %d n , Count);     }     return 0;   }


#include <bits/stdc++.h>   const long long inf = 1ll << 60;   const long long maxn = 30010;   using namespace std;   struct lsg {     long long x, y;   } a[maxn], b[maxn];   signed n, q, ffa[maxn], ffb[maxn], ban[maxn], x, y;   long long f[maxn], w1[maxn], w2[maxn], w3[maxn];   bool pd(lsg a, lsg b) { return a.x < b.x; }   inline void doit(long long i) {     w1[i] = w2[i] = w3[i] = -inf;     if (i >= 1 && ban[i] != i) w1[i] = a[i].x * b[i].x;     if (i >= 2 && ban[i] != i - 1 && ban[i - 1] != i)       w2[i] = a[i].x * b[i - 1].x + a[i - 1].x * b[i].x;     if (i >= 3) {       if (ban[i] != i - 2 && ban[i - 1] != i && ban[i - 2] != i - 1)         w3[i] =             a[i].x * b[i - 2].x + a[i - 1].x * b[i].x + a[i - 2].x * b[i - 1].x;       if (ban[i] != i - 1 && ban[i - 1] != i - 2 && ban[i - 2] != i)         w3[i] = max(w3[i], a[i].x * b[i - 1].x + a[i - 1].x * b[i - 2].x +                                a[i - 2].x * b[i].x);     }   }   inline signed read() {     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     signed k = 1, kk = 0;     if (c ==  - )       k = -1;     else       kk = c -  0 ;     c = getchar();     while (c >=  0  && c <=  9 ) kk = kk * 10 + c -  0 , c = getchar();     return k * kk;   }   inline long long max(long long x, long long y) { return x > y ? x : y; }   inline long long min(long long x, long long y) { return x < y ? x : y; }   signed main() {     n = read();     q = read();     for (signed i = 1; i <= n; i++) a[i].x = read(), a[i].y = i;     for (signed i = 1; i <= n; i++) b[i].x = read(), b[i].y = i;     sort(a + 1, a + 1 + n, pd), sort(b + 1, b + 1 + n, pd);     for (signed i = 1; i <= n; i++) ffa[a[i].y] = i, ffb[b[i].y] = i;     for (signed i = 1; i <= n; i++) ban[i] = ffb[a[i].y];     for (signed i = 1; i <= n; i++) doit(i);     for (signed j = 1; j <= q; j++) {       x = ffa[read()], y = ffa[read()], swap(ban[x], ban[y]);       for (signed i = max(1, x - 5); i <= min(n, x + 5); i++) doit(i);       for (signed i = max(1, y - 5); i <= min(n, y + 5); i++) doit(i);       f[0] = 0;       for (signed i = 1; i <= n; i++) {         if (i >= 1) f[i] = f[i - 1] + w1[i];         if (i >= 2) f[i] = max(f[i], f[i - 2] + w2[i]);         if (i >= 3) f[i] = max(f[i], f[i - 3] + w3[i]);       }       cout << f[n] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> nums(n);     vector<string> nums_str(n);     unordered_map<string, int> counts;     for (int i = 0; i < n; i++) {       cin >> nums[i];       nums_str[i] = to_string(nums[i]);       unordered_map<string, bool> used;       for (int l = 1; l <= 9; l++) {         for (int j = 0; j <= 9 - l; j++) {           string part = nums_str[i].substr(j, l);           if (used.find(part) == used.end()) {             used[part] = true;             if (counts.find(part) == counts.end()) counts[part] = 0;             counts[part]++;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int l = 1; l <= 9; l++) {         for (int j = 0; j <= 9 - l; j++) {           string part = nums_str[i].substr(j, l);           if (counts[part] == 1) {             cout << part <<   n ;             goto end_number;           }         }       }     end_number : {}     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans = 3;   int main() {     cin >> n;     while (n % ans == 0) {       ans *= 3;     }     cout << n / ans + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, ans, a[500001], f[2][1200001];   int main() {     scanf( %lld , &n);     f[0][0] = 1;     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] ^= a[i - 1];       ans += f[i % 2][a[i]];       f[i % 2][a[i]]++;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int fac(long long int n) {     long long int g = 1;     for (int x = 1; x <= n; x++) g *= x;     return g;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int g[25] = {0};       long long int f = 2;       long long int r = 0;       while (n > 0) {         ++g[n % f];         n /= f;         ++f;         ++r;       }       long long int ans = 0;       for (int x = 1; x < 25; x++) {         if (g[x] > 0) {           long long int e[25] = {0};           e[0] = g[0];           for (int y = 1; y < 25; y++) {             if (y != x)               e[y] = e[y - 1] + g[y];             else               e[y] = e[y - 1] + g[y] - 1;           }           long long int h = 0;           long long int k = 1;           for (int y = 0; y < r - 1; y++) {             k *= (e[y + 1] - h);             ++h;           }           for (int y = 0; y < 25; y++) {             if (x != y)               k /= fac(g[y]);             else               k /= fac(g[y] - 1);           }           ans += k;         }       }       cout << ans - 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long losn = 1e6 + 5;   const long long maxn = 1e5 + 5;   const long long minn = 1e3 + 5;   const long long tiny = 1e2 + 5;   const long long inf = 1e9;   const long long mod = 1e9 + 7;   const long long hmod = 4698571;   long long n;   char c[maxn * 2];   map<pair<long long, long long>, long long> mp;   int main() {     long long t;     cin >> t;     while (t--) {       cin >> n;       long long ansl = 1, ansr = n;       scanf(  %s , c + 1);       long long anslen = inf;       mp.clear();       long long x = 0, y = 0;       pair<long long, long long> ps(x, y);       mp[ps] = 0;       for (long long i = 1; i <= n; i++) {         if (c[i] ==  L ) {           x--;         } else if (c[i] ==  R ) {           x++;         } else if (c[i] ==  D ) {           y--;         } else if (c[i] ==  U ) {           y++;         }         pair<long long, long long> p(x, y);         if (mp.count(p)) {           long long len = i - mp[p];           if (len < anslen) {             anslen = len;             ansl = mp[p] + 1;             ansr = i;           }         }         mp[p] = i;       }       if (anslen != inf) {         cout << ansl <<     << ansr << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lcs(string X, string Y) {     int i, j, m = X.length(), n = Y.length();     int L[m + 1][n + 1];     for (i = 0; i <= m; i++) {       for (j = 0; j <= n; j++) {         if (i == 0 || j == 0)           L[i][j] = 0;         else if (X[i - 1] == Y[j - 1])           L[i][j] = L[i - 1][j - 1] + 1;         else           L[i][j] = max(L[i - 1][j], L[i][j - 1]);       }     }     return L[m][n];   }   int main() {     long long n;     cin >> n;     vector<long long> v;     string x, y;     x = to_string(n);     int max = 0;     for (long long i = 1; i <= sqrt(n); i++) {       v.push_back(i * i);       y = to_string(i * i);       if (max < lcs(x, y) && (lcs(x, y) == y.length())) {         max = lcs(x, y);       }     }     if (max != 0) {       cout << x.length() - max;     } else {       cout <<  -1 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 1e6 + 6;   const int mod = 1e9 + 7;   int n, k;   int val[K];   int ans, cur;   int power(int a, int b) {     int res = 1;     while (b) {       if (b & 1) {         res = (1LL * res * a) % mod;       }       a = (1LL * a * a) % mod;       b >>= 1;     }     return res;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= k + 2; ++i) {       val[i] = (val[i - 1] + power(i, k)) % mod;     }     if (n <= k + 2) {       printf( %d n , val[n]);       return 0;     }     ans = 0;     cur = 1;     for (int i = 2; i <= k + 2; ++i) {       cur = (1LL * cur * (n - i)) % mod;       cur = (1LL * cur * power(mod + 1 - i, mod - 2)) % mod;     }     for (int i = 1; i <= k + 2; ++i) {       ans = (ans + 1LL * cur * val[i]) % mod;       cur = (1LL * cur * (n - i)) % mod;       cur = (1LL * cur * (i - k - 2 + mod)) % mod;       cur = (1LL * cur * power((1LL * (n - i - 1) * i) % mod, mod - 2)) % mod;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mm = 2e5 + 30;   long long a1, a2, a3, a4, a5, a6, a7, a8, a9, ez1, ans, n, m, k, sum;   string s, s1, s2, s3;   int flag[mm];   bool y = 0;   bool omm(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   void input() { cin >> n; }   void solve() {     for (int i = 1; i <= n; i++) {       cin >> ez1;       flag[ez1] = i;     }     int l = 0;     for (int i = 0; i < n; i++) {       cin >> ez1;       if (flag[ez1] < l) {         cout << 0 <<    ;       } else {         cout << abs(flag[ez1] - l) <<    ;         l = flag[ez1];       }     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = 998244353;   int add(int x, int y) { return (x + y) % MOD; }   int sub(int x, int y) { return (x + MOD - y) % MOD; }   int mul(int x, int y) { return (1ll * x * y) % MOD; }   int modpow(int base, int exp) {     base %= MOD;     int result = 1;     while (exp > 0) {       if (exp & 1) result = (1ll * result * base) % MOD;       base = (1ll * base * base) % MOD;       exp >>= 1;     }     return result;   }   int modinv(int a) { return modpow(a, MOD - 2); }   int divide(int x, int y) { return mul(x, modinv(y)); }   int n, m;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int rlen = 0;     int roll1 = 1, roll2 = n + m;     for (int i = 1; i <= n + 1; ++i) {       rlen = add(rlen, divide(mul(roll1, i), roll2));       roll1 = mul(roll1, n + 1 - i);       roll2 = mul(roll2, n + m - i);     }     rlen = mul(rlen, m);     int I = 1;     for (int i = 1; i <= n; ++i) {       I = add(I, divide(m, i));     }     cout << mul(rlen, I) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Pow[10005];   long long ans[10005];   int main() {     long long N, X, now = 1, i, con = 0, t;     Pow[0] = 1;     for (i = 1; i <= 40; i++) Pow[i] = Pow[i - 1] * 2;     scanf( %lld %lld , &X, &N);     for (i = 40; i >= 0; i--) {       while (X && X - (Pow[i] - 1) >= 0) {         t = i;         while (t--) ans[con++] = now;         X -= (Pow[i] - 1);         now += N;         now++;       }     }     printf( %lld n , con);     for (i = 0; i < con; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1000 + 10;   const int maxm = 4e5 + 10;   const int inf_max = 0x3f3f3f;   using namespace std;   int a, b, c;   int main() {     int t;     cin >> t;     while (t--) {       cin >> a >> b >> c;       string ans =   ;       if (a) ans +=  0 ;       for (int i = 1; i <= a; ++i) ans +=  0 ;       if (c) {         ans +=  1 ;         if (a) b--;       }       for (int i = 1; i <= c; ++i) ans +=  1 ;       int len = ans.size();       if (len == 0 && b) ans +=  0 ;       len = ans.size();       if (ans[len - 1] ==  0 ) {         while (b >= 2) ans +=  10 , b -= 2;         if (b) ans +=  1 ;       } else {         if (b) ans +=  0 , b--;         while (b >= 2) ans +=  10 , b -= 2;         if (b) ans +=  1 ;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll inf = 1e18;   using vb = vector<bool>;   using vc = vector<char>;   using vd = vector<double>;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using pi = pair<int, int>;   using pll = pair<ll, ll>;   int a[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   int b[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   ll mod = 998244353;   ll ans = 0;   ll x(string s, char a) {     ll n = s.size();     if (n == 1) {       if (s[0] == a) {         return 0;       } else {         return 1;       }     }     ll d = 0;     ll e = 0;     string q, w;     for (ll i = 0; i < n / 2; i++) {       q += s[i];       if (s[i] == a) {         d++;       }     }     for (ll i = n / 2; i < n; i++) {       w += s[i];       if (s[i] == a) {         e++;       }     }     ll p = n / 2;     ll ans1 = (p - d) + x(w, a + 1);     ll ans2 = (p - e) + x(q, a + 1);     return min(ans1, ans2);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t;     cin >> t;     while (t--) {       ll n;       cin >> n;       string s;       cin >> s;       ll ans = x(s,  a );       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long sumfirst = 0, sumsecond = 0;     long long n;     vector<long long> first, second;     long long arr[200000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > 0)         sumfirst += arr[i];       else if (arr[i] < 0)         sumsecond += arr[i];       if (arr[i] > 0)         first.push_back(arr[i]);       else         second.push_back(arr[i]);     }     if (sumfirst > (sumsecond * -1)) {       cout <<  first  << endl;       return 0;     } else if (sumfirst < (sumsecond * -1)) {       cout <<  second  << endl;       return 0;     }     for (int i = 0; i < min(second.size(), first.size()); i++) {       if (first[i] > (second[i] * -1)) {         cout <<  first  << endl;         return 0;       } else if ((second[i] * -1) > first[i]) {         cout <<  second  << endl;         return 0;       }     }     if (arr[n - 1] > 0) {       cout <<  first  << endl;       return 0;     } else       cout <<  second  << endl;     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 220000;   const long long MOD = 1e9 + 7;   int n;   int was[MAXN * 2];   vector<int> beds[MAXN * 2];   int go[MAXN * 2];   int tm1;   long long dfs1(int v) {     was[v] = 1;     long long ans = 1;     for (int u : beds[v]) ans = (ans + dfs1(u)) % MOD;     return ans;   }   int dfs2(int v) {     was[v] = tm1;     if (was[go[v]] == tm1) {       return 1;     }     if (was[go[v]]) return 0;     return dfs2(go[v]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < 2 * n; ++i) go[i] = -1;     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       --x, --y;       go[x] = y;       beds[y].push_back(x);     }     long long ans = 1;     for (int i = 0; i < 2 * n; ++i) {       if (go[i] == -1)         ans = (ans * dfs1(i)) % MOD;       else if (go[i] == i) {         was[i] = 1;       }     }     tm1 = 1;     for (int i = 0; i < 2 * n; ++i) {       if (was[i]) continue;       ++tm1;       if (dfs2(i)) ans = (ans * 2) % MOD;     }     cout << ans <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define int long long int   #define intu unsigned long long int   #define vi vector<int>   #define ii pair<int,int>   #define pb push_back   #define ff first   #define ss second   #define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);   # define PI           3.14159265358979323846    #define all(a) a.begin(),a.end()   #define for0(i, n) for (int i = 0; i < n; i++)   #define for1(i, n) for (int i = 1; i <= n; i++)   #define loop(i,a,b) for (int i = a; i < b; i++)   #define bloop(i,a,b) for (int i = a ; i>=b;i--)   #define tc(t) int t; cin >> t; while (t--)   int mod = 1000000007;   int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}   int lcm(int a, int b) {return a * b / gcd(a, b); }   int bpow(int a,int b)    {     int res = 1;     while (b > 0) {       if (b & 1)res = ((res) * (a));         a = ((a) * (a));         b >>= 1;     }     return res;   }   int fact(int n) {       if ((n==0)||(n==1))         return 1;       else         return ((n%mod) * (fact(n-1))%mod)%mod;   }   void go()   {   #ifndef ONLINE_JUDGE     freopen( input.txt , r ,stdin);     freopen( output.txt , w ,stdout);     #endif   }      map<int,int> mp;      signed main()      {          fast_io         go();            tc(t){           int n;cin>>n;           vi v(n);           bool yes=0;           for0(i,n){             cin>>v[i];                        }           for0(i,n){                          int yo=sqrt(v[i]);             if(yo*yo!=v[i]){               yes=1;               break;             }           }                if(yes)             cout <<  YES  <<   n ;           else             cout <<  NO  <<   n ;                    }       }


#include <bits/stdc++.h>   using namespace std;   long long a[2000000];   int main() {     long long n, t, i;     cin >> n;     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     cin >> t;     for (i = 0; i < t; i++) {       long long x;       scanf( %lld , &x);       a[x - 1] = -a[x - 1];     }     stack<long long> st;     for (i = n - 1; i >= 0; i--) {       if (a[i] < 0) {         st.push(a[i]);       } else {         if (st.empty() || st.top() != -a[i]) {           st.push(-a[i]);           a[i] = -a[i];         } else {           st.pop();         }       }     }     if (st.empty()) {       cout <<  YES n ;       for (i = 0; i < n; i++) printf( %lld  , a[i]);     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, x, y;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       ++a;       if (a == n + 1) {         a = 1;       }       --b;       if (b == 0) {         b = n;       }       if (a == b) {         return 0 * puts( YES );       }     }     return 0 * puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, i;     long long dx, dy;   };   vector<vector<int> > e;   vector<int> sz;   vector<int> ans;   vector<point> pt;   int dfs(int s) {     sz[s] = 1;     for (int i = 0; i < e[s].size(); i++)       if (sz[e[s][i]] == 0) sz[s] += dfs(e[s][i]);     return sz[s];   }   bool cmp(const point &p1, const point &p2) {     return (p1.dx * p2.dy - p1.dy * p2.dx) < 0;   }   void go(int begin, int end, int s) {     for (int i = begin + 1; i < end; i++)       if (make_pair(pt[i].x, pt[i].y) < make_pair(pt[begin].x, pt[begin].y))         swap(pt[begin], pt[i]);     for (int i = begin; i < end; i++) {       pt[i].dx = pt[i].x - pt[begin].x;       pt[i].dy = pt[i].y - pt[begin].y;     }     sort(pt.begin() + begin + 1, pt.begin() + end, cmp);     ans[pt[begin].i] = s + 1;     for (int i = 0, k = begin + 1; i < e[s].size(); i++) {       int v = e[s][i];       if (sz[v] < sz[s]) {         go(k, k + sz[v], v);         k += sz[v];       }     }   }   int main(int argc, char *argv[]) {     int n;     cin >> n;     e.resize(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       e[u].push_back(v);       e[v].push_back(u);     }     pt.resize(n);     for (int i = 0; i < n; i++) {       cin >> pt[i].x >> pt[i].y;       pt[i].i = i;     }     sz.assign(n, 0);     dfs(0);     ans.assign(n, -1);     go(0, n, 0);     for (int i = 0; i < n; i++) cout << (i ?     :   ) << ans[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, sum = 0;     cin >> n >> s;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n - 1; i++) {       sum += arr[i];     }     if (sum > s)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cout << 9 * n <<     << 8 * n << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, d, count = 0;     int n;     char a;     cin >> n >> x;     while (n--) {       cin >> a >> d;       if (a ==  + ) {         x += d;       } else {         if (d <= x)           x -= d;         else           count++;       }     }     cout << x <<     << count;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   int ar[MAXN][MAXN], star[MAXN][MAXN];   int main() {     int n, m, t;     char a;     cin >> n >> m >> t;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf(  %c , &a);         ar[i][j] = a -  0 ;       }     for (int i = 2; i < n; i++)       for (int j = 2; j < m; j++)         if (ar[i][j] && ar[i - 1][j] && ar[i][j - 1] && ar[i + 1][j] &&             ar[i][j + 1])           star[i][j] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         star[i][j] += star[i][j - 1] + star[i - 1][j] - star[i - 1][j - 1];     long long tmp, fl, res = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         tmp = 1;         for (int k = j - 2; k >= 1; k--) {           fl = 1;           while (fl && tmp < i - 1) {             fl = 0;             if (star[i - 1][j - 1] - star[tmp][j - 1] - star[i - 1][k] +                     star[tmp][k] >=                 t)               tmp++, fl = 1;           }           res += tmp - 1;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, mod;   long long fast(long long base, long long pow) {     long long res = 1;     while (pow) {       if (pow % 2) res = ((res % mod) * (base % mod)) % mod;       pow /= 2;       base = ((base % mod) * (base % mod)) % mod;       if (!base) base = mod;     }     return res;   }   int main() {     cin >> n >> mod;     long long res = ((long long)(2 * ((1 - fast(3, n)) / -2.0)) % mod);     if (res == -1)       cout << mod - 1 << endl;     else       cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int _c, n, m;   int e[70];   long long p[70][70], V, A, B, C, ans, G, F;   void dfs2(const long long b, int x) {     if (F / b < b) return;     if (x > n) {       long long c = F / b;       if (G * b + b * c + c * G < ans)         ans = G * b + b * c + c * G, A = G, B = b, C = c;       return;     }     for (int E = e[x]; E >= 0; --E) dfs2(b * p[x][E], x + 1);   }   void dfs(const long long a, int x) {     if (V / a / a < a) return;     if (x > n) {       double T = sqrt(V / a);       G = a, F = V / a;       if (T * a * 2 + V / a < ans) dfs2(1, 1);       return;     }     int E = e[x];     e[x] = 0;     for (; E >= 0; --E, ++e[x]) dfs(a * p[x][E], x + 1);     --e[x];   }   void work() {     scanf( %d , &n);     V = 1;     for (int i = 1; i <= n; ++i) {       scanf( %I64d%d , &p[i][1], &e[i]);       p[i][0] = 1;       for (int j = 2; j <= e[i]; ++j) p[i][j] = p[i][1] * p[i][j - 1];       V *= p[i][e[i]];     }     ans = V * 2 + 1;     A = V, B = C = 1;     dfs(1, 1);     printf( %I64d %I64d %I64d %I64d n , ans << 1, A, B, C);   }   int main() {     for (scanf( %d , &_c); _c--;) work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000000 + 7;   int main() {     string s;     long long n;     cin >> n;     long long a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     long long x = 0, y = n - 1, z = 0;     while (x <= y) {       if (max(a[x], a[y]) < z)         break;       else {         if (a[x] < a[y] && a[x] > z) {           z = a[x];           s +=  L ;           x++;         } else if (a[y] > z) {           z = a[y];           s +=  R ;           y--;         } else {           z = a[x];           s +=  L ;           x++;         }       }     }     cout << s.size() << endl;     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const ll OO = 1e18;   int di[8] = {0, 0, 1, -1, -1, 1, -1, 1};   int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1};   string ys =  YES , no =  NO ;   const long double dgr = acos(-1) / 180, dg = 180 / acos(-1);   const int mod = 1e9 + 9, N = 1e5 + 5, M = 2001;   ll fast_power(ll base, ll power) {     ll ans = 1;     while (power > 0) {       if (power & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       power >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     ll n, m;     cin >> n >> m;     ll pw_m = fast_power(2, m);     ll ans = 1;     for (int i = 1; i <= n; i++) {       ans = ans * (pw_m - i) % mod;     }     cout << ans % mod <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int many;   int s[100010];   int a[100010];   int p[100010];   int run(int o) {     int zuo = 1;     int you = o - 1;     int re = -1;     int k;     while (zuo <= you) {       k = (zuo + you) / 2;       if (a[k] < s[o]) {         re = k;         you = k - 1;       } else         zuo = k + 1;     }     return re;   }   int main() {     cin >> many;     for (int i = 1; i <= many; i++) scanf( %d , &s[many + 1 - i]);     a[1] = s[1];     p[1] = -1;     for (int i = 2; i <= many; i++) a[i] = min(a[i - 1], s[i]);     for (int i = 2; i <= many; i++) {       if (a[i - 1] >= s[i])         p[i] = -1;       else         p[i] = i - 1 - run(i);     }     for (int i = 1; i <= many; i++) printf( %d  , p[many + 1 - i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pl = pair<ll, ll>;   using vll = vector<ll>;   using vpl = vector<pl>;   using mat = vector<vll>;   const ll MAX = 1e5;   const ll mod = 1e9 + 7;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto &ele : v) {       cout << ele <<    ;     }     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &ele : v) {       cin >> ele;     }     return in;   }   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   class graph {    public:     struct edge {       int from;       int to;       T cost;     };     vector<edge> edges;     vector<vector<int>> g;     int n;     graph(int _n) : n(_n) { g.resize(n); }     virtual int add(int from, int to, T cost) = 0;   };   template <typename T>   class forest : public graph<T> {    public:     using graph<T>::edges;     using graph<T>::g;     using graph<T>::n;     forest(int _n) : graph<T>(_n) {}     int add(int from, int to, T cost = 1) {       assert(0 <= from && from < n && 0 <= to && to < n);       int id = (int)edges.size();       assert(id < n - 1);       g[from].push_back(id);       g[to].push_back(id);       edges.push_back({from, to, cost});       return id;     }   };   template <typename T>   class dfs_forest : public forest<T> {    public:     using forest<T>::edges;     using forest<T>::g;     using forest<T>::n;     vector<int> pv;     vector<int> pe;     vector<int> order;     vector<int> pos;     vector<int> end;     vector<int> sz;     vector<int> root;     vector<int> depth;     vector<T> dist;     dfs_forest(int _n) : forest<T>(_n) {}     void init() {       pv = vector<int>(n, -1);       pe = vector<int>(n, -1);       order.clear();       pos = vector<int>(n, -1);       end = vector<int>(n, -1);       sz = vector<int>(n, 0);       root = vector<int>(n, -1);       depth = vector<int>(n, -1);       dist = vector<T>(n);     }     void clear() {       pv.clear();       pe.clear();       order.clear();       pos.clear();       end.clear();       sz.clear();       root.clear();       depth.clear();       dist.clear();     }       private:     void do_dfs(int v) {       pos[v] = (int)order.size();       order.push_back(v);       sz[v] = 1;       for (int id : g[v]) {         if (id == pe[v]) {           continue;         }         auto &e = edges[id];         int to = e.from ^ e.to ^ v;         depth[to] = depth[v] + 1;         dist[to] = dist[v] + e.cost;         pv[to] = v;         pe[to] = id;         root[to] = (root[v] != -1 ? root[v] : to);         do_dfs(to);         sz[v] += sz[to];       }       end[v] = (int)order.size() - 1;     }     void do_dfs_from(int v) {       depth[v] = 0;       dist[v] = T{};       root[v] = v;       pv[v] = pe[v] = -1;       do_dfs(v);     }       public:     void dfs(int v, bool clear_order = true) {       if (pv.empty()) {         init();       } else {         if (clear_order) {           order.clear();         }       }       do_dfs_from(v);     }     void dfs_all() {       init();       for (int v = 0; v < n; v++) {         if (depth[v] == -1) {           do_dfs_from(v);         }       }       assert((int)order.size() == n);     }   };   void solve() {     ll N;     cin >> N;     dfs_forest<ll> g(N);     for (ll i = (0); (1) > 0 ? i < (N - 1) : i >= (N - 1); i += (1)) {       ll x, y;       cin >> x >> y;       x -= 1, y -= 1;       g.add(x, y);     }     g.dfs(0);     vll cnt(2, 0);     cerr <<  [           <<  g.depth           <<  ]: ,         debug_out(g.depth);     for (ll i = (0); (1) > 0 ? i < (N) : i >= (N); i += (1)) {       cnt[g.depth[i] % 2] += 1;     }     cout << min(cnt[0], cnt[1]) - 1 << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll tc = 1;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void printVector(T begin, T end) {     for (auto i = begin; i != end; i++) {       cout << *i <<    ;     }     cout << endl;   }   long long readLL() {     long long x;     cin >> x;     return x;   }   int a[200];   int b[200];   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int res = 0;     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         b[j] = a[j];       }       for (int j = i; j < n; j += k) {         b[j] = 0;       }       int q = 0, w = 0;       for (int j = 0; j < n; j++) {         if (b[j] < 0) q++;         if (b[j] > 0) w++;       }       res = max(res, abs(q - w));     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2710;   const double eps = 1e-9;   const double pi = 3.1415926536;   int dp[maxn][maxn];   string s;   int main(int argc, char const *argv[]) {     dp[0][0] = 1;     for (int i = 1; i <= 100; i++) {       for (int j = 0; j <= (i - 1) * 26; j++) {         for (int k = 0; k < 26; k++) {           dp[i][j + k] = (dp[i][j + k] + dp[i - 1][j]) % 1000000007;         }       }     }     int t;     std::cin >> t;     while (t--) {       std::cin >> s;       int len;       len = s.size();       int sum = 0;       for (int i = 0; i < len; i++) {         sum += s[i] -  a ;       }       std::cout << dp[len][sum] - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   namespace mem {   namespace stdval {   using i32 = int;   using i64 = long long;   using u32 = unsigned int;   using u64 = unsigned long long;   using f32 = float;   using f64 = double;   using i128 = __int128_t;   using u128 = __uint128_t;   }  // namespace stdval   namespace utils {   using std::cerr;   using std::cin;   using std::cout;   using std::endl;   using std::function;   using std::lower_bound;   using std::make_pair;   using std::make_tuple;   using std::max_element;   using std::min_element;   using std::reverse;   using std::shuffle;   using std::sort;   using std::swap;   using std::tie;   using std::upper_bound;   }  // namespace utils   namespace io {   namespace fastio {   const int BUFFER = 1 << 21;   char ibuf[BUFFER], *iS, *iT;   inline int getc() {     if (iS == iT) {       iT = (iS = ibuf) + fread(ibuf, 1, BUFFER, stdin);       return iS == iT ? EOF : *iS++;     } else {       return *iS++;     }   }   char obuf[BUFFER], *oS = obuf, *oT = oS + BUFFER - 1;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(int x) {     *oS++ = x;     if (oS == oT) flush();   }   struct Flusher {     ~Flusher() { flush(); }   } flusher;   }  // namespace fastio   using fastio::getc;   using fastio::putc;   template <class T>   inline void readDigit(T &x) {     x = getc();     while (!isdigit(x)) x = getc();   }   inline int readDigit() {     int x;     readDigit(x);     return x;   }   template <class T>   inline void readAlpha(T &x) {     x = getc();     while (!isalpha(x)) x = getc();   }   inline int readAlpha() {     int x;     readAlpha(x);     return x;   }   template <class T>   inline void readInt(T &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(unsigned int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(long long &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(unsigned long long &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(char &x) { x = getc(); }   template <class T = int>   inline T read() {     T x;     read(x);     return x;   }   template <class T, class... Args>   inline void read(T &x, Args &...args) {     read(x), read(args...);   }   inline void print(int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(unsigned int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(long long x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(unsigned long long x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(char x) { putc(x); }   inline void print(const char *s) {     int len = strlen(s);     for (int i = 0; i < len; i++) putc(s[i]);   }   inline void print(const std::string &s) {     for (int i = 0; i < s.length(); i++) putc(s[i]);   }   template <class T, class... Args>   inline void print(const T &x, Args... args) {     print(x), print(args...);   }   template <class... Args>   inline void println(Args... args) {     print(args...), putchar(  n );   }   }  // namespace io   namespace random {   const int LuckyNumber = 20040725;   std::mt19937 rng(LuckyNumber ^                    std::chrono::steady_clock::now().time_since_epoch().count());   std::mt19937_64 rng64(       LuckyNumber ^ std::chrono::steady_clock::now().time_since_epoch().count());   template <class T>   inline T rand(T l, T r) {     return std::uniform_int_distribution<T>(l, r)(rng);   }   template <class T>   inline T rand64(T l, T r) {     return std::uniform_int_distribution<T>(l, r)(rng);   }   }  // namespace random   namespace modint {   template <const int mod>   struct Z {     int x;     inline Z() { x = 0; }     inline Z(int t) { x = t; }     inline void operator-=(Z a) { (x -= a.x) < 0 && (x += mod); }     inline void operator+=(Z a) { (x += a.x) >= mod && (x -= mod); }     inline void operator*=(Z a) { x = (long long)x * a.x % mod; }     friend inline Z operator*(Z a, Z b) { return (long long)a.x * b.x % mod; }     friend inline Z operator-(Z a, Z b) {       return ((a.x -= b.x) < 0 && (a.x += mod)), a;     }     friend inline Z operator+(Z a, Z b) {       return ((a.x += b.x) >= mod && (a.x -= mod)), a;     }   };   template <const int mod>   inline Z<mod> finv(Z<mod> x) {     if (x.x < 2) return x;     return (mod - mod / x.x) * finv(mod % x.x);   }   template <const int mod>   inline Z<mod> fpow(Z<mod> a, int b) {     Z<mod> s = 1;     for (; b; b >>= 1, a = a * a)       if (b & 1) s = s * a;     return s;   }   template <const int mod>   inline void init_inverse(int n, Z<mod> *inv) {     inv[0] = inv[1] = 1;     for (int i = 2; i < n; i++) inv[i] = (mod - mod / i) * inv[mod % i];   }   template <const int mod>   inline void init_factorial(int n, Z<mod> *fac, Z<mod> *ifac) {     fac[0] = 1, init_inverse(n, ifac);     for (int i = 1; i < n; i++)       fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * ifac[i];   }   }  // namespace modint   namespace math {   using std::max;   using std::min;   template <class T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   template <class T>   inline T gcd(T n, T m) {     return m ? gcd(m, n % m) : n;   }   template <class T>   inline T lcm(T n, T m) {     return n / gcd(n, m) * m;   }   template <const stdval::u64 p>   struct FastDiv {     stdval::u64 t, i;     inline FastDiv() : t(stdval::u64(-1) / p), i(mul_inv(p)) {}     inline bool divide(stdval::u64 n) { return n * i <= t; }     inline bool divide(stdval::i64 n) {       return stdval::u64(n < 0 ? -n : n) * i <= t;     }     inline stdval::u64 mul_inv(stdval::u64 n) {       stdval::u64 x = n;       for (int i = 0; i < 5; ++i) x *= 2 - n * x;       return x;     }   };   template <const stdval::u64 b>   struct FastMod {     stdval::u64 m;     inline FastMod() : m(stdval::u64((stdval::u128(1) << 64) / b)) {}     inline stdval::u64 reduce(stdval::u64 a) {       stdval::u64 q = (stdval::u64)((stdval::u128(m) * a) >> 64);       stdval::u64 r = a - q * b;       return r >= b ? r - b : r;     }   };   }  // namespace math   namespace container {   using std::map;   using std::pair;   using std::set;   using std::tuple;   using std::unordered_map;   using std::unordered_set;   template <class T>   struct vector : std::vector<T> {     using std::vector<T>::vector;     vector() : std::vector<T>() {}     vector(const std::vector<T> &plain) : std::vector<T>(plain) {}     inline void read(int s = -1) {       if (~s) this->resize(s);       for (size_t i = 0; i < this->size(); i++) {         io::read(this->operator[](i));       }     }     inline void print(char pt0 =    , char pt1 =   n ) {       for (size_t i = 0; i < this->size(); i++) {         io::print(this->operator[](i));         if (i + 1 < this->size()) io::putc(pt0);       }       io::putc(pt1);     }     inline void sort() { std::sort(this->begin(), this->end()); }     inline void concat(const vector &rhs) {       this->insert(this->end(), rhs.begin(), rhs.end());     }     inline bool includes(const T &x) const {       return std::find(this->begin(), this->end(), x) != this->end();     }     inline vector slice(int l, int r) const {       if (l > r) return {};       if (r < this->size()) return vector(this->begin() + l, this->begin() + r);       vector<int> rsp = (this->begin() + l, this->end());       return rsp.resize(r - l), rsp;     }     inline void from(const std::set<T> &src) {       this->resize(src.size());       auto it = this->begin();       for (const T e : src) *it++ = e;     }     template <class Function>     inline void forEach(Function func) {       for (const auto &it : *this) func(it);     }     template <class R, class Function>     inline vector<R> _map(Function func) const {       vector<R> res(this->size());       for (size_t i = 0; i < this->size(); i++)         res[i] = func(this->operator[](i));       return res;     }     template <class R>     inline vector<R> map(R func(T)) const {       return this->_map<R>(func);     }     template <class R>     inline vector<R> map(const std::function<R(T)> &func) const {       return this->_map<R>(func);     }   };   }  // namespace container   namespace str {   using namespace mem::container;   struct string : std::string {     using std::string::string;     string() : std::string(  ) {}     string(const std::string &plain) : std::string(plain) {}     inline string join(const vector<string> &) const;     inline string join(const std::vector<string> &) const;     template <class T>     inline string join(const vector<T> &) const;     template <class T>     inline string join(const std::vector<T> &) const;     vector<string> split(const string &delim) const {       if (this->empty()) return {};       char *src = new char[this->length() + 1];       strcpy(src, this->c_str());       char *tar = new char[delim.length() + 1];       strcpy(tar, delim.c_str());       vector<string> rsp;       for (char *pos = strtok(src, tar); pos; pos = strtok(nullptr, tar))         rsp.push_back(string(pos));       delete[] src;       delete[] tar;       return rsp;     }     template <class... Args>     static inline string format(const char *fm, Args... args) {       int len = snprintf(nullptr, 0, fm, args...);       char *buf = new char[len + 1];       snprintf(buf, len + 1, fm, args...);       string str(buf);       delete[] buf;       return str;     }     template <class... Args>     static inline string format(const string &fm, Args... args) {       return format(fm.c_str(), args...);     }   };   inline string to_string(const float &x) { return std::to_string(x); }   inline string to_string(const double &x) { return std::to_string(x); }   inline string to_string(const int &x) { return std::to_string(x); }   inline string to_string(const unsigned int &x) { return std::to_string(x); }   inline string to_string(const long long &x) { return std::to_string(x); }   inline string to_string(const unsigned long long &x) {     return std::to_string(x);   }   template <class T>   inline string to_string(const vector<T> &vet) {     return  {  + string( , ).join(vet) +  } ;   }   template <class T>   inline string to_string(const std::vector<T> &vet) {     return to_string(vector<T>(vet.begin(), vet.end()));   }   template <const int mod>   inline string to_string(const mem::modint::Z<mod> &zval) {     return std::to_string(zval.x);   }   inline string string::join(const vector<string> &vet) const {     if (!vet.size()) return   ;     string res = string(vet[0]);     for (size_t i = 1; i < vet.size(); i++) {       res += *this;       res += string(vet[i]);     }     return res;   }   inline string string::join(const std::vector<string> &vet) const {     if (!vet.size()) return   ;     string res = string(vet[0]);     for (size_t i = 1; i < vet.size(); i++) {       res += *this;       res += string(vet[i]);     }     return res;   }   template <class T>   inline string string::join(const vector<T> &vet) const {     if (!vet.size()) return   ;     string res = to_string(vet[0]);     for (size_t i = 1; i < vet.size(); i++) {       res += *this;       res += to_string(vet[i]);     }     return res;   }   template <class T>   inline string string::join(const std::vector<T> &vet) const {     if (!vet.size()) return   ;     string res = to_string(vet[0]);     for (size_t i = 1; i < vet.size(); i++) {       res += *this;       res += to_string(vet[i]);     }     return res;   }   inline void print(const str::string &s) {     for (size_t i = 0; i < s.length(); i++) mem::io::putc(s[i]);   }   template <class... Args>   inline void printfm(const char *fm, Args... args) {     print(str::string().format(fm, args...));   }   template <class... Args>   inline void printfm(const string &fm, Args... args) {     print(str::string().format(fm, args...));   }   template <class... Args>   inline void printfm(const std::string &fm, Args... args) {     print(str::string().format(fm, args...));   }   }  // namespace str   using namespace io;   using namespace str;   using namespace math;   using namespace utils;   using namespace modint;   using namespace random;   using namespace stdval;   using namespace container;   }  // namespace mem   const int N = 5e5 + 10;   using namespace mem::io;   using namespace mem::container;   int n, m, q, p[N], anc[N];   bool mrk[N], vis[N];   vector<int> ele[N];   pair<vector<int>, int> dat[N];   struct cmp {    public:     inline bool operator()(const int x, const int y) { return p[x] < p[y]; }   };   std::priority_queue<int, std::vector<int>, cmp> f[N], g[N];   struct Edge {     int u, v;   } e[N];   struct Query {     int o, x;   } y[N];   int find(int x) {     if (x == anc[x]) return x;     return find(anc[x]);   }   int pop(int k) {     while (f[k].size() && g[k].size()) {       if (f[k].top() == g[k].top()) {         f[k].pop(), g[k].pop();       } else {         int x = f[k].top();         f[k].pop();         return x;       }     }     if (f[k].size()) {       int x = f[k].top();       f[k].pop();       return x;     } else {       return 0;     }   }   pair<vector<int>, int> merge(int u, int v) {     u = find(u), v = find(v);     if (u == v) return {{}, -1};     if (ele[u].size() > ele[v].size()) std::swap(u, v);     ele[v].insert(ele[v].end(), ele[u].begin(), ele[u].end());     anc[u] = v;     return {ele[u], u};   }   int main() {     read(n, m, q);     for (int i = 1; i <= n; i++) read(p[i]);     for (int i = 1; i <= m; i++) read(e[i].u), read(e[i].v);     for (int i = 1; i <= q; i++) {       read(y[i].o), read(y[i].x);       if (y[i].o == 2) mrk[y[i].x] = true;     }     for (int i = 1; i <= n; i++) {       anc[i] = i;       ele[i].push_back(i);     }     for (int i = 1; i <= m; i++)       if (!mrk[i]) {         merge(e[i].u, e[i].v);       }     for (int i = q; i >= 1; i--) {       if (y[i].o == 2) {         dat[i] = merge(e[y[i].x].u, e[y[i].x].v);       }     }     for (int i = 1; i <= n; i++) {       f[find(i)].push(i);     }     for (int i = 1; i <= q; i++) {       if (y[i].o == 1) {         int ans = pop(find(y[i].x));         vis[ans] = true;         print(p[ans],   n );       } else {         int src = find(e[y[i].x].u);         for (int x : dat[i].first) {           anc[x] = dat[i].second;           if (!vis[x]) {             f[dat[i].second].push(x);             g[src].push(x);           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, v, cost, i;     cin >> n >> v;     if (v >= (n - 1))       cout << n - 1;     else {       cost = v;       for (i = 2; i <= n; i++) {         v--;         if ((n - i) <= v) {           cout << cost;           break;         } else {           cost += i;           v++;         }       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   int t, n, m, j, ans, k, a, b, c, d, e, f, sum, i, sz, row, col, l;   string s, s2, s3, s4;   deque<pair<int, int> > v;   void brainfuck();   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     brainfuck();     return 0;   }   void brainfuck() {     cin >> n >> m >> k;     for (i = 1; i <= n; i++) {       for (j = 1; i & 1 && j <= m; j++) v.push_back({i, j});       for (j = m; i % 2 == 0 && j >= 1; j--) v.push_back({i, j});     }     for (j = 1; j <= k; j++) {       if (j != k)         a = 2;       else         a = v.size();       cout << a;       while (a--) {         cout <<     << v.front().first <<     << v.front().second;         v.pop_front();       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int s[18257 + 1];   int main() {     memset(s, 0, sizeof(s));     s[1] = 1;     for (int i = 2; i <= 18257; i++) {       s[i] = (2 * i - 3) * 6 + 6;     }     int a;     scanf( %d , &a);     if (a == 1) {       cout << s[1] << endl;     } else {       int sum = 0;       for (int i = 1; i <= a; i++) {         sum += s[i];       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 210, MAX_K = 1010, MOD = 1e9 + 7;   int N, K, arr[MAX_N], dp[MAX_N][MAX_N][MAX_K];   void add(int& a, long long b) {     b %= MOD;     a = (a + b) % MOD;   }   int solve() {     sort(arr + 1, arr + N + 1);     dp[0][0][0] = 1;     for (int i = 1; i <= N; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= K; k++) {           int v = dp[i - 1][j][k];           int nk = k + j * (arr[i] - arr[i - 1]);           if (nk > K) continue;           add(dp[i][j][nk], v);           add(dp[i][j][nk], 1LL * j * v);           add(dp[i][j + 1][nk], v);           if (j) add(dp[i][j - 1][nk], 1LL * j * v);         }       }     }     int ret = 0;     for (int k = 0; k <= K; k++) {       add(ret, dp[N][0][k]);     }     return ret;   }   void read() {     cin >> N >> K;     for (int i = 1; i <= N; i++) cin >> arr[i];   }   int main() {     read();     cout << solve() << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 1000000007;   const int N = 5e5 + 5;   int n, m, q, ans[N];   struct node {     int cnt, id;   } c[N];   struct ask {     int id;     long long x;   } Q[N];   int st[N << 2];   void update(int o, int l, int r, int pos) {     if (l == r) {       ++st[o];       return;     }     int mid = l + r >> 1;     if (pos <= mid)       update(o << 1, l, mid, pos);     else       update(o << 1 | 1, mid + 1, r, pos);     st[o] = st[o << 1] + st[o << 1 | 1];   }   int query(int o, int l, int r, int k) {     if (l == r) return l;     int mid = l + r >> 1;     if (k <= st[o << 1])       return query(o << 1, l, mid, k);     else       return query(o << 1 | 1, mid + 1, r, k - st[o << 1]);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       ++c[x].cnt;     }     for (int i = 1; i <= m; i++) c[i].id = i;     for (int i = 1; i <= q; i++) {       long long x;       scanf( %lld , &x);       Q[i].id = i, Q[i].x = x;     }     sort(c + 1, c + 1 + m, [](const node& a, const node& b) {       return a.cnt == b.cnt ? a.id < b.id : a.cnt < b.cnt;     });     sort(Q + 1, Q + 1 + q, [](const ask& a, const ask& b) { return a.x < b.x; });     long long now = n;     int j = 1;     for (int i = 1; i <= m; i++) {       long long nxt = (i == m ? 2e18 : 1ll * (c[i + 1].cnt - c[i].cnt) * i + now);       update(1, 1, m, c[i].id);       while (j <= q && Q[j].x <= nxt) {         long long x = Q[j].x;         int tmp = (x - now) % i;         if (!tmp) tmp = i;         ans[Q[j].id] = query(1, 1, m, tmp);         ++j;       }       now = nxt;     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[1000005];   int num[1000005];   int main() {     int i, j, len, ans;     while (scanf( %s , str) != EOF) {       len = strlen(str);       for (i = 0, j = len - 1; i < j; i++, j--) {         swap(str[i], str[j]);       }       str[len] =  0 ;       memset(num, 0, sizeof(num));       ans = 0;       for (i = 0; i <= len; i++) {         if (str[i] ==  1 ) {           for (j = i + 1; j <= len; j++) {             if (str[j] ==  0 ) break;           }           if (j != i + 1) {             num[j] = 1;             num[i] = -1;             str[j] =  1 ;           } else {             num[i] = 1;           }           i = j - 1;         }       }       for (i = 0; i <= len; i++) {         if (num[i]) ans++;       }       printf( %d n , ans);       for (i = 0; i <= len; i++) {         if (num[i]) {           if (num[i] == 1) printf( + );           if (num[i] == -1) printf( - );           printf( 2^%d n , i);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> z;   vector<int> pr;   vector<vector<int>> ans;   int s, f;   long long pow(long long n, long long s) {     if (s == 0)       return 1;     else {       if (s % 2 == 1) {         return (n * (pow(n, s - 1))) % 1000000007;       }       if (s % 2 == 0) {         long long k = (pow(n, s / 2)) % 1000000007;         return (k * k) % 1000000007;       }     }   }   void prfix(string s) {     for (int i = 1; i < s.size(); i++) {       pr[i] = pr[i - 1];       while (pr[i] > 0 && s[i] != s[pr[i]]) {         pr[i] = pr[pr[i] - 1];       }       if (s[i] == s[pr[i]]) pr[i]++;     }   }   void zet(string s) {     int l = 0, r = 0;     for (int i = 1; i < s.size(); i++) {       if (i <= r) {         z[i] = min(z[i - l], r - i + 1);       }       for (; z[i] + i < s.size() && s[z[i] + i] == s[z[i]]; z[i]++)         ;       if (i + z[i] - 1 >= r) {         l = i;         r = i + z[i] - 1;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long double R, x1, y1, x2, y2;     cin >> R >> x1 >> y1 >> x2 >> y2;     if (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) >= R) {       cout << x1 <<     << y1 <<     << R;       return 0;     }     if (x1 == x2 && y1 == y2) {       long double y3 = y1 + R / 2;       cout << x1 <<     << y3 <<     << R / 2;       return 0;     }     long double c = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));     long double x4 = (x1 - x2) * (R + c) / 2 / c + x2;     long double y4 = (y1 - y2) * (R + c) / 2 / c + y2;     cout.precision(10);     cout << fixed << x4 <<     << y4 <<     << (R + c) / 2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0, n;     bool ok(false);     cin >> n;     while (i * (i + 1) / 2 <= n && ok == false) {       if (i * (i + 1) / 2 == n) {         ok = true;       }       i++;     }     (ok == true) ? cout <<  YES  : cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9 + 7;   template <class X, class Y>   void minimize(X &x, const Y &y) {     if (x > y) x = y;   }   template <class X, class Y>   void maximize(X &x, const Y &y) {     if (x < y) x = y;   }   vector<int> adj[5050];   int nLeaf[5050];   int f[5050][5050][2];   int tmp[5050][2];   int n;   void loadTree(void) {     scanf( %d , &n);     for (int love = 0, _n = (n - 1); love < _n; love = love + 1) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     if (n == 2) {       printf( 1 n );       exit(0);     }     memset(f, 0x3f, sizeof f);   }   void dfs(int u, int p) {     bool leaf = true;     for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();          it++)       if (*it != p) {         int v = *it;         dfs(v, u);         leaf = false;       }     if (leaf) {       nLeaf[u] = 1;       for (int i = 0, _n = (2); i < _n; i = i + 1) f[u][i][i] = 0;       return;     }     for (int i = 0, _n = (2); i < _n; i = i + 1) f[u][0][i] = 0;     for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();          it++)       if (*it != p) {         int v = *it;         for (int i = 0, _n = (nLeaf[u] + 1); i < _n; i = i + 1)           for (int j = 0, _n = (2); j < _n; j = j + 1) {             tmp[i][j] = f[u][i][j];             f[u][i][j] = INF;           }         for (int i = 0, _n = (nLeaf[u] + 1); i < _n; i = i + 1)           for (int j = 0, _n = (2); j < _n; j = j + 1)             for (int k = 0, _n = (nLeaf[v] + 1); k < _n; k = k + 1)               for (int l = 0, _n = (2); l < _n; l = l + 1)                 minimize(f[u][i + k][j], tmp[i][j] + f[v][k][l] + (j != l));         nLeaf[u] += nLeaf[v];       }   }   void process(void) {     for (int i = (1), _b = (n); i <= _b; i = i + 1)       if (adj[i].size() > 1) {         dfs(i, -1);         printf( %d n , min(f[i][nLeaf[i] / 2][0], f[i][nLeaf[i] / 2][1]));         return;       }     assert(false);   }   int main(void) {     loadTree();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const int INF = 0x3f3f3f3f;   const int N = 1e2 + 10, Node = 2e3 + 10, Edge = Node * Node / 2;   int Dis[N][N], p[Node], a[Node], f[Node];   int to[Edge], nex[Edge], beg[Node], flow[Edge], dis[Node], cur[Node];   int S, T, e = 1;   inline int read() {     int x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch) && ch !=  - ) ch = getchar();     if (ch ==  - ) flag = -1, ch = getchar();     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch -  0 ), ch = getchar();     return x * flag;   }   inline void add(int x, int y, int z) {     to[++e] = y, nex[e] = beg[x], beg[x] = e, flow[e] = z;     to[++e] = x, nex[e] = beg[y], beg[y] = e, flow[e] = 0;   }   inline bool bfs() {     queue<int> q;     memset(dis, 0, sizeof(dis));     dis[S] = 1;     q.push(S);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = beg[x]; i; i = nex[i])         if (flow[i] && !dis[to[i]]) dis[to[i]] = dis[x] + 1, q.push(to[i]);     }     return dis[T];   }   inline int dfs(int x, int f) {     if (x == T) return f;     int res = f;     for (int &i = cur[x]; i; i = nex[i])       if (flow[i] && dis[to[i]] == dis[x] + 1) {         int v = dfs(to[i], min(f, flow[i]));         flow[i] -= v, flow[i ^ 1] += v, f -= v;         if (!f) return res;       }     return res - f;   }   int main() {     int n = read(), m = read();     memset(dis, 63, sizeof(dis));     for (int i = (1), iend = (m); i <= iend; i++) {       int u = read(), v = read();       Dis[u][v] = Dis[v][u] = 1;     }     for (int i = (1), iend = (n); i <= iend; i++) Dis[i][i] = 0;     for (int k = (1), kend = (n); k <= kend; k++)       for (int i = (1), iend = (n); i <= iend; i++)         for (int j = (1), jend = (n); j <= jend; j++)           chkmin(Dis[i][j], Dis[i][k] + Dis[k][j]);     int A = read(), B = read(), k = read(), h = read();     S = A + B + 1, T = A + B + 2;     for (int i = (1), iend = (A); i <= iend; i++)       p[i] = read(), a[i] = read(), f[i] = read(), add(S, i, 1);     for (int i = (1), iend = (B); i <= iend; i++) {       add(i + A, T, 1);       int x = read(), d = read();       for (int j = (1), jend = (A); j <= jend; j++)         if (Dis[p[j]][x] <= f[j] && a[j] >= d) add(j, i + A, 1);     }     int ans = 0;     while (bfs()) {       memcpy(cur, beg, sizeof(cur));       ans += dfs(S, 1e9);     }     long long Ans = 1e18;     for (int i = (0), iend = (A); i <= iend; i++)       chkmin(Ans, 1ll * k * min(A - i, ans) + 1ll * i * h);     printf( %lld n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   namespace io {   const int SIZE = (1 << 21) + 1;   char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;   inline char getc() {     return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                         (iS == iT ? EOF : *iS++))                      : *iS++);   }   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char x) {     *oS++ = x;     if (oS == oT) flush();   }   template <class T>   inline void read(T &x) {     char ch;     int f = 1;     x = 0;     while (isspace(ch = getc()))       ;     if (ch ==  - ) ch = getc(), f = -1;     do x = x * 10 + ch -  0 ;     while (isdigit(ch = getc()));     x *= f;   }   template <class T, class... Args>   inline void read(T &x, Args &...args) {     read(x);     read(args...);   }   template <class T>   inline void write(T x) {     static char stk[128];     int top = 0;     if (x == 0) {       putc( 0 );       return;     }     if (x < 0) putc( - ), x = -x;     while (x) stk[top++] = x % 10, x /= 10;     while (top) putc(stk[--top] +  0 );   }   template <class T, class... Args>   inline void write(T x, Args... args) {     write(x);     putc(   );     write(args...);   }   inline void space() { putc(   ); }   inline void endl() { putc(  n ); }   struct _flush {     ~_flush() { flush(); }   } __flush;   };  // namespace io   using io::endl;   using io::flush;   using io::getc;   using io::putc;   using io::read;   using io::space;   using io::write;   const int M = 1000000007;   inline int add(int x, int y) { return x + y >= M ? x + y - M : x + y; }   template <class... Args>   inline int add(int x, int y, Args... args) {     return add(add(x, y), args...);   }   inline int sub(int x, int y) { return x - y < 0 ? x - y + M : x - y; }   inline int mul(int x, int y) { return 1LL * x * y % M; }   template <class... Args>   inline int mul(int x, int y, Args... args) {     return mul(mul(x, y), args...);   }   inline void inc(int &x, int y = 1) {     x += y;     if (x >= M) x -= M;   }   inline void dec(int &x, int y = 1) {     x -= y;     if (x < 0) x += M;   }   inline int power(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = mul(x, x))       if (y & 1) res = mul(res, x);     return res;   }   inline int inv(int x) { return power(x, M - 2); }   const int N = 4005;   int _g[N * 2], *g = _g + N;   int n, m;   struct DP {     int a[N * 2];     int *f;     DP() {       f = a + N;       fill(f - m, f + m + 1, 0);       f[0] = 1;     }     void update(int x) {       fill(g - m, g + m + 1, 0);       for (int i = -m + x; i <= m - x; ++i) g[i - x] = (g[i - x] + f[i]) % M;       for (int i = -m + x; i <= m - x; ++i) g[i + x] = (g[i + x] + f[i]) % M;       for (int i = -m; i <= m; ++i) f[i] = (f[i] + g[i]) % M;     }     void select(int x) {       fill(g - m, g + m + 1, 0);       for (int i = -m + x; i <= m; ++i) g[i - x] = (g[i - x] + f[i]) % M;       for (int i = -m; i <= m - x; ++i) g[i + x] = (g[i + x] + f[i]) % M;       for (int i = -m; i <= m; ++i) f[i] = g[i];     }     void operator=(const DP &r) {       for (int i = -m; i <= m; ++i) f[i] = r.f[i];     }     int query(int x) {       int res = 0;       for (int i = 2 - x; i <= x - 2; ++i) inc(res, f[i]);       return res;     }   };   vector<int> G[N];   int a[N];   bool vis[N];   DP f;   DP stk[20];   int top = 0;   int dfs(int x, int fa) {     vis[x] = true;     for (int v : G[x]) {       if (v == fa) continue;       if (v == 1) return 1;       return dfs(v, x) + 1;     }     return 1;   }   int res = 0;   void solve(int l, int r) {     if (l == r) {       inc(res, f.query(a[l]));       return;     }     stk[top] = f;     ++top;     int mid = (l + r) >> 1;     for (int i = l; i <= mid; ++i) f.update(a[i]);     solve(mid + 1, r);     f = stk[top - 1];     for (int i = mid + 1; i <= r; ++i) f.update(a[i]);     solve(l, mid);     --top;   }   void solve2(int l, int r) {     if (l == r) {       inc(res, add(f.f[a[l]], f.f[a[l] - 1], f.f[1 - a[l]], f.f[-a[l]]));       inc(res, add(f.f[a[l]], f.f[a[l] - 1], f.f[1 - a[l]], f.f[-a[l]]));       return;     }     stk[top] = f;     ++top;     int mid = (l + r) >> 1;     for (int i = l; i <= mid; ++i) f.select(a[i]);     solve2(mid + 1, r);     f = stk[top - 1];     for (int i = mid + 1; i <= r; ++i) f.select(a[i]);     solve2(l, mid);     --top;   }   int main() {     read(n, m);     for (int i = 1; i <= m; ++i) {       int u, v;       read(u, v);       G[u].push_back(v);       G[v].push_back(u);     }     int cnt = 0;     for (int v : G[1]) {       if (!vis[v]) a[++cnt] = dfs(v, 1) + 1;     }     solve(1, cnt);     res = mul(res, 2);     if ((m & 1) == 0) {       f = DP();       for (int i = 1; i <= cnt; ++i) f.select(a[i]);       inc(res, f.f[0]);     } else {       f = DP();       solve2(1, cnt);     }     write(res), endl();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char sign[1000][1000], cpy[1000][1000];   int n, m;   void tryFill(int i, int j) {     for (int ii = i - 1; ii <= i + 1; ii++) {       for (int jj = j - 1; jj <= j + 1; jj++) {         if (i == ii && j == jj) {           continue;         }         if (sign[ii][jj] ==  . ) {           return;         }       }     }     for (int ii = i - 1; ii <= i + 1; ii++) {       for (int jj = j - 1; jj <= j + 1; jj++) {         if (i == ii && j == jj) {           continue;         }         cpy[ii][jj] =  # ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> sign[i][j];         cpy[i][j] =  . ;       }     }     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         tryFill(i, j);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (sign[i][j] != cpy[i][j]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   inline int chkmax(T &x, const T2 &y) {     return x < y ? x = y, 1 : 0;   }   template <class T, class T2>   inline int chkmin(T &x, const T2 &y) {     return x > y ? x = y, 1 : 0;   }   const int MAXN = (1 << 20);   int n;   void read() { cin >> n; }   vector<pair<int, int> > change_list = {       {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 3}, {0, 3}, {1, 2}, {2, 0},       {3, 1}, {2, 1}, {1, 1}, {2, 2}, {3, 0}, {3, 3}, {2, 3}, {3, 2},   };   void solve() {     if (n % 4 >= 2) {       cout <<  NO  <<   n ;       return;     }     cout <<  YES  <<   n ;     bool odd_flag = n % 2;     for (int i = 0; i < (n / 4); i++) {       int a = i * 4 + 1, b = i * 4 + 2, c = i * 4 + 3, d = i * 4 + 4;       if (odd_flag) cout << a <<     << n <<   n ;       cout << a <<     << c <<   n ;       if (odd_flag) cout << c <<     << n <<   n ;       if (odd_flag) cout << b <<     << n <<   n ;       cout << b <<     << d <<   n ;       if (odd_flag) cout << d <<     << n <<   n ;       cout << a <<     << b <<   n ;       cout << c <<     << d <<   n ;       cout << a <<     << d <<   n ;       cout << b <<     << c <<   n ;     }     for (int i = 0; i < (n / 4); i++)       for (int j = i + 1; j < (n / 4); j++)         for (auto it : change_list)           cout << 4 * i + 1 + it.first <<     << 4 * j + 1 + it.second <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out << p.first <<     << p.second;     return out;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> v) {     for (auto a : v) out << a <<    ;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& a : v) in >> a;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, multiset<T> S) {     for (auto a : S) out << a <<    ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, set<T> S) {     for (auto a : S) out << a <<    ;     return out;   }   template <typename T>   set<T> operator+(set<T> A, set<T> B) {     for (auto b : B) A.insert(b);     return A;   }   int main() {     string s, t;     cin >> s >> t;     int i = 0;     for (int j = 0; j < t.size(); j++) {       if (s[i] == t[j]) i++;     }     cout << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, l, k;     cin >> n >> l >> k;     vector<int> cnt(26, 0);     for (int i = 0; i < n * l; ++i) {       char c;       cin >> c;       cnt[c -  a ]++;     }     int last = 0;     int cur = 0;     vector<string> ans(n, string(l,  # ));     for (int i = 0; i < l; ++i) {       while (!cnt[cur]) cur++;       while (cnt[cur] < k - last && k - last > 0) {         for (int j = 0; j < cnt[cur]; ++j) {           ans[last + j][i] = char( a  + cur);         }         last += cnt[cur];         cur++;       }       for (int j = 0; j < k - last; ++j) {         ans[j + last][i] = char( a  + cur);       }       cnt[cur] -= k - last;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < l; ++j) {         if (ans[i][j] ==  # ) {           cnt[cur]--;           cout << char( a  + cur);         } else           cout << ans[i][j];         while (!cnt[cur]) cur++;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long int n, i, m, j, f, k;     cin >> n;     m = n * n;     vector<long long int> v[n];     for (i = m; i >= n; i -= n) {       if (f == 0) {         k = 0;         for (j = i; j > (i - n); j--, k++) {           v[k].push_back(j);         }       } else {         k = n - 1;         for (j = i; j > (i - n); j--, k--) {           v[k].push_back(j);         }       }       (f == 0) ? f = 1 : f = 0;     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) cout << v[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 15e4 + 4;   const int MAXQ = MAXN;   const int MAXK = 6 + 2;   int n, k, q;   int t[MAXN];   set<int, greater<int> > st;   int main() {     scanf( %d%d%d , &n, &k, &q);     for (int i = 0; i < n; ++i) scanf( %d , t + i);     while (q--) {       int op, id;       scanf( %d%d , &op, &id);       --id;       if (op == 1) {         st.insert(t[id]);       } else {         if (!st.count(t[id])) {           puts( NO );           continue;         }         int cnt = k;         bool ok = false;         for (auto it : st) {           if (it == t[id]) {             puts( YES );             ok = true;             break;           }           --cnt;           if (ok) break;           if (cnt == 0) break;         }         if (!ok) puts( NO );       }     }     return 0;   }