#include <bits/stdc++.h>   using namespace std;   vector<long long int> v(26, 0);   long long int n, m;   bool myFun(string &a, string &s, long long int i, long long int j) {     if (i >= n && j >= m) {       return true;     }     if (j >= m) {       return false;     }     if (i >= n) {       while (j < m) {         if (s[j] !=  * ) {           return false;         }         j++;       }       return true;     }     if (a[i] == s[j]) {       return myFun(a, s, i + 1, j + 1);     }     if (s[j] ==  ? ) {       long long int temp = a[i] -  a ;       if (v[temp]) {         return myFun(a, s, i + 1, j + 1);       }       return false;     }     if (s[j] ==  * ) {       long long int temp = a[i] -  a ;       if (v[temp]) {         return myFun(a, s, i, j + 1);       } else {         return (myFun(a, s, i + 1, j + 1) || myFun(a, s, i, j + 1)) ||                myFun(a, s, i + 1, j);       }     }     return false;   }   int main() {     string s;     cin >> s;     for (long long int i = 0; i < s.length(); i++) {       long long int temp = s[i] -  a ;       v[temp] = 1;     }     cin >> s;     long long int k;     cin >> k;     for (long long int i = 0; i < k; i++) {       string a;       cin >> a;       n = a.length();       m = s.length();       if (myFun(a, s, 0, 0)) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d, e, f;     scanf( %d , &a);     e = 0;     for (b = 1; b <= a; b++) {       for (c = b; c <= a; c++) {         f = b ^ c;         d = 0 ^ f;         if (b + c > d && d <= a && d >= c) {           e++;         }       }     }     printf( %d n , e);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int *xi, *di, n;     cin >> n;     xi = new int[n];     di = new int[n];     for (int i = 0; i < n; i++) cin >> xi[i] >> di[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (xi[i] + di[i] == xi[j] && xi[j] + di[j] == xi[i] && j != i) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[200005];   long long extgcd(long long a, long long b, long long& x, long long& y) {     long long d = a;     if (b != 0LL) {       d = extgcd(b, a % b, y, x);       y -= (a / b) * x;     } else {       x = 1;       y = 0;     }     return d;   }   long long mod_inverse(long long a, long long m) {     long long x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   long long mod_fact(long long n, long long p, long long& e) {     e = 0;     if (n == 0) return 1;     long long res = mod_fact(n / p, p, e);     e += n / p;     if (n / p % 2 != 0) {       return res * (p - fact[n % p]) % p;     }     return res * fact[n % p] % p;   }   long long mod_comb(long long n, long long k, long long p) {     if (n < 0 || k < 0 || n < k) return 0;     long long e1, e2, e3;     long long a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2),               a3 = mod_fact(n - k, p, e3);     if (e1 > e2 + e3) return 0;     return a1 * mod_inverse(a2 * a3 % p, p) % p;   }   long long mod_pow(long long x, long long n) {     long long ans = 1;     while (n > 0) {       if (n & 1) {         ans = ans * x % 998244353LL;       }       x = x * x % 998244353LL;       n >>= 1;     }     return ans;   }   int n;   long long k;   int h[200005];   int main(void) {     fact[0] = 1;     for (long long i = 1; i <= 200000; i++) {       fact[i] = fact[i - 1] * i % 998244353LL;     }     scanf( %d%lld , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     int cur = 0, nxt = 1;     long long po = 1;     int cnt = 0;     for (int i = 0; i < n; i++) {       int ans = h[i];       int cans = h[(i + 1) % n];       if (ans == cans) {         po = po * k % 998244353LL;       } else {         cnt++;       }     }     long long ans = 0;     long long v1 = 1;     for (int i = 0; i < cnt; i++) {       int rest = cnt - i;       long long v4 = mod_comb(cnt, i, 998244353LL);       long long sum = 0;       if (rest % 2 == 1) {         if (i == cnt) {           sum += v1 * mod_pow(2, rest - 1) % 998244353LL;           sum %= 998244353LL;         } else {           sum += v1 * mod_pow(2, rest - 1) % 998244353LL;           sum %= 998244353LL;         }       } else if (rest > 0) {         long long v3 = mod_pow(2, rest - 1);         long long v5 = mod_comb(rest - 1, rest / 2, 998244353LL);         v3 = (v3 - v5 + 998244353LL) % 998244353LL;         sum += v1 * v3 % 998244353LL;         sum %= 998244353LL;       }       sum = sum * v4 % 998244353LL;       ans += sum;       ans %= 998244353LL;       v1 = v1 * (k - 2LL) % 998244353LL;     }     ans = ans * po % 998244353LL;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k = 0, cl[105 * 35], link[105 * 35];   vector<int> g[105 * 35];   vector<pair<int, int> > has[105];   bool dfs(int u) {     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       if (!cl[v]) {         cl[v] = 1;         if (link[v] == 0 || dfs(link[v]) == true) {           link[v] = u;           return true;         }       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       for (int j = 2; j <= sqrt(x); ++j) {         if (x % j == 0) {           while (x % j == 0) {             x = x / j;             has[i].push_back({j, ++k});           }         }       }       if (x > 1) has[i].push_back({x, ++k});     }     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       if (u % 2 == 0) swap(u, v);       for (int j = 0; j < has[u].size(); ++j)         for (int q = 0; q < has[v].size(); ++q) {           if (has[u][j].first == has[v][q].first) {             g[has[u][j].second].push_back(has[v][q].second);           }         }     }     int rs = 0;     for (int j = 1; j <= k; ++j) {       for (int i = 1; i <= k; ++i) cl[i] = 0;       if (dfs(j)) ++rs;     }     cout << rs;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int l[100005];   int r[100005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       l[i] = min(l[i - 1] + 1, a[i]);     }     for (int i = n; i >= 1; i--) {       r[i] = min(r[i + 1] + 1, a[i]);     }     int ma = 0;     for (int i = 1; i <= n; i++) {       ma = max(ma, min(l[i], r[i]));     }     cout << ma << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   void precalc() {}   const int maxn = 1e4 + 10;   int n;   char s[maxn];   bool read() {     if (scanf( %s , s) < 1) {       return false;     }     n = strlen(s);     return true;   }   set<string> ans;   int dp[maxn][2];   void solve() {     ans.clear();     memset(dp, 0, sizeof(dp));     if (n >= 7) {       dp[n - 2][0] = 1;     }     if (n >= 8) {       dp[n - 3][1] = 1;     }     for (int i = n - 2; i >= 5; --i) {       for (int it = 0; it < 2; ++it) {         int len = it + 2;         if (!dp[i][it]) {           continue;         }         string cur = string(s + i, len);         ans.insert(cur);         for (int nit = 0; nit < 2; ++nit) {           int nlen = nit + 2;           if (i - nlen < 5) {             break;           }           string t = string(s + (i - nlen), nlen);           if (t != cur) {             dp[i - nlen][nit] = 1;           }         }       }     }     printf( %d n , ((int)(ans).size()));     for (auto t : ans) {       printf( %s n , t.c_str());     }   }   int main() {     srand(rdtsc());     precalc();     while (true) {       if (!read()) {         break;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int L(int i) { return i << 1; }   inline int R(int i) { return (i << 1) | 1; }   inline long long max(long long a, long long b) { return a < b ? b : a; }   inline long long min(long long a, long long b) { return a < b ? a : b; }   inline int abs(int x) { return x < 0 ? -x : x; }   struct data {     long long l, r;   } A[2][10100], tmp;   int top[2];   long long B[33];   void init() {     int i;     B[0] = 1;     for (i = 1; i < 33; i++) B[i] = B[i - 1] << 1;   }   void dfs(long long l, long long r, int id, int n) {     l = max(1, l);     r = min(B[n] - 1, r);     if (l <= r) {       tmp.l = l, tmp.r = r;       A[id][top[id]++] = tmp;       if (!((l <= 1) && (r >= B[n - 1] - 1))) {         dfs(l, r, id, n - 1);         dfs(l - B[n - 1], r - B[n - 1], id, n - 1);       }     }   }   int main() {     long long l1, r1, l2, r2, ret;     int i, j;     init();     while (cin >> l1 >> r1 >> l2 >> r2) {       top[0] = top[1] = 0;       dfs(l1, r1, 0, 30);       dfs(l2, r2, 1, 30);       ret = 0;       for (i = 0; i < top[0]; i++)         for (j = 0; j < top[1]; j++)           ret =               max(min(A[0][i].r, A[1][j].r) - max(A[0][i].l, A[1][j].l) + 1, ret);       cout << ret << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int t[60], v[60];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     int nrOfStonesTakenAway = 0;     for (int i = 1; i <= n; i++) {       if (t[i] > v[i]) nrOfStonesTakenAway += (t[i] - v[i]);     }     for (int i = 1; i <= n; i++)       if (t[i] < v[i]) {         nrOfStonesTakenAway -= (v[i] - t[i]);       }     if (nrOfStonesTakenAway < 0)       puts( No );     else       puts( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, i, j, k, l;     cin >> n >> a;     long long arr[n + 2];     for (i = 1; i <= n; i++) {       cin >> arr[i];     }     long long pos;     arr[n + 1] = a;     sort(arr + 1, arr + n + 2);     for (i = 1; i <= n + 1; i++) {       if (arr[i] == a) {         pos = i;         break;       }     }     long long dist, d1, d2, d3, d4;     if (pos == 1 || pos == n + 1) {       if (pos == 1) {         cout << arr[n] - arr[pos] << endl;         return 0;       }       if (pos == n + 1) {         cout << arr[pos] - arr[2] << endl;         return 0;       }     } else {       d1 = 2 * (arr[pos] - arr[1]) + arr[n] - arr[pos];       d2 = arr[pos] - arr[1] + 2 * (arr[n] - arr[pos]);       d3 = 2 * (arr[pos] - arr[2]) + arr[n + 1] - arr[pos];       d4 = arr[pos] - arr[2] + 2 * (arr[n + 1] - arr[pos]);     }     dist = min(min(d1, d2), min(d3, d4));     cout << dist << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   int main() {     int n, s;     cin >> n >> s;     int res = -1;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (y == 0) {         if (s >= x) {           res = max(res, 0);         }       } else {         if (s > x) {           res = max(res, 100 - y);         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1003;   int n, k;   bitset<N * 3> A, dp, dpt;   int main() {     scanf( %d%d , &n, &k);     for (int a; k; k--) scanf( %d , &a), A[a] = 1;     dp[1500] = 1;     for (int __ = 1; __ <= 1009; __++) {       dpt = 0;       for (int i = 0; i < 3000; i++)         if (dp[i] == 1) dpt |= A << (i - n);       dp = dpt;       if (dp[1500] == 1) return !printf( %d n , __);     }     return !printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long n, fir;   int main() {     scanf( %lld , &n);     fir = n;     for (int i = 2; 1ll * i * i <= n; i++)       if (n % i == 0) {         fir = i;         break;       }     for (; n != 1 && n % fir == 0; n /= fir)       ;     printf( %lld n , n == 1 ? fir : 1);   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> m;   long long f(string s) {     long long ff[27] = {0}, ans = 0, i, j;     for (i = 0; i < s.size(); i++) {       ff[s[i] -  a ]++;     }     for (i = 0; i < 26; i++) {       if (ff[i] % 2) {         ans |= (1LL << i);       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, i, j;     cin >> n;     string s[n + 1];     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> s[i];       v.push_back(f(s[i]));     }     for (i = 0; i < v.size(); i++) m[v[i]]++;     long long ans = 0;     for (auto i : m) {       ans += (i.second * (i.second - 1)) / 2;     }     for (i = 0; i < 26; i++) {       map<long long, long long> mm;       for (j = 0; j < n; j++)         if (v[j] & (1 << i)) mm[v[j] ^ (1LL << i)]++;       for (auto j : mm) {         ans += m[j.first] * j.second;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     int result = n - m;     if (k >= abs(result) && k != 0) {       cout <<  ?  <<   n ;     } else {       if (result > 0)         cout <<  + n ;       else if (result < 0)         cout <<  - n ;       else if (result == 0)         cout <<  0 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<char> st;   char s[100005];   int main() {     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; ++i) {       if (st.empty() || st.top() != s[i])         st.push(s[i]);       else         st.pop();     }     if (st.empty())       puts( Yes );     else       puts( No );   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   int n,m;   char a[6][6];   bool used[6][6];   int ans;   void dfs(int x,int y)   {       if(a[x][y]== * )       {           ans++;       }       if(x==n&&y==m)       {           cout << ans;           exit(0);       }       if(x+1<=n&&a[x+1][y]== * )       {           dfs(x+1,y);       }       if(y+1<=m&&a[x][y+1]== * )       {           dfs(x,y+1);       }       if(y+1<=m)       {           dfs(x,y+1);       }       if(x+1<=n)       {           dfs(x+1,y);       }   }   int main()   {       cin >> n >> m;       for(int i = 1;i<=n;i++)       {           for(int j = 1;j<=m;j++)           {               cin >> a[i][j];           }       }       dfs(1,1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(0);     int a, b, c, d;     cin >> a >> b >> c >> d;     for (int i = a; i <= 200; i++) {       for (int j = b; j <= 200; j++) {         for (int k = 1; k <= 200; k++) {           if (a * 2 >= i && b * 2 >= j && c <= k && c * 2 >= k && i > d * 2 &&               j > d * 2 && d <= k && d * 2 >= k && i > j && j > k) {             cout << i << endl << j << endl << k << endl;             return 0;           }         }       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int visit[100005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (i == 0 && j == 0) {             a[i][j] =  W ;           } else {             a[i][j] =  B ;           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cout << a[i][j];         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int from, to;     Edge(int f, int t) : from(f), to(t) {}   };   vector<Edge> edges;   vector<int> G[100005];   int h[100005];   void add_edge(int from, int to) {     edges.push_back(Edge(from, to));     int m = edges.size();     G[from].push_back(m - 1);     return;   }   void bfs(int x) {     queue<int> Q;     Q.push(x);     int cnt = 1, first = 1;     h[x] = cnt;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       if (h[u] == cnt && first) {         cnt++;         first = 0;       }       for (int i = 0; i < G[u].size(); i++) {         Edge &e = edges[G[u][i]];         if (!h[e.to]) {           h[e.to] = cnt;           Q.push(e.to);         }       }       first = 1;     }   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n - 1; i++) {         int u, v;         scanf( %d %d , &u, &v);         add_edge(u, v);         add_edge(v, u);       }       memset(h, 0, sizeof(h));       bfs(1);       double sum = 0.0;       for (int i = 1; i <= n; i++) {         if (h[i] != 0) sum += (double)1 / h[i];       }       printf( %lf n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pot(int x, int y) {     if (y == 0) {       return 1;     } else {       return x * pot(x, y - 1);     }   }   int bin(int x, int y) {     if ((x == 0 && y != 0) || (y == 0 && x != 0)) {       return 1;     } else {       return bin(x, y - 1) + bin(x - 1, y);     }   }   void strlwr(string& s) {     for (int i = 0; (unsigned)i < s.size(); i++) {       if (s[i] >=  A  && s[i] <=  Z ) {         s[i] += 32;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int a[26] = {};     int n;     string s;     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) {       a[s[i] -  a ]++;     }     int k = 25;     for (int i = 0; i < n; i++) {       while (a[k] == 0 && k > 0) {         k--;       }       if (s[i] -  a  < k) {         a[s[i] -  a ]--;       }       if (s[i] -  a  == k) {         a[s[i] -  a ]--;         cout << s[i];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i;   long n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     map<string, int> mp;     string s;     while (n--) {       cin >> s;       mp[s]++;       if (mp[s] > 1) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans[52];     memset(ans, 0, sizeof(ans));     int flag = 0;     for (int i = 0; i < n; ++i) {       int arr[52];       memset(arr, 0, sizeof(arr));       for (int j = 0; j < n; ++j) {         int k;         cin >> k;         arr[k]++;       }       for (int j = 0; j < n; ++j) {         if (arr[j] == n - j) {           ans[i] = j;           if (j == n - 1) {             ans[i] += flag;             flag++;           }           break;         }       }     }     for (int i = 0; i < n; ++i) {       if (ans[i] == 0) ans[i] = n;       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   int const MOD = 998244353;   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     int n, nopt;     std::cin >> n >> nopt;     std::vector<int> h;     h.reserve(n + 1);     h.resize(n);     for (int& hi : h) std::cin >> hi;     h.push_back(h[0]);     std::vector<int> f{1};     f.reserve(n * 2 + 1);     std::vector<int> g;     g.reserve(n * 2 + 1);     for (int i = 0; i < n; ++i) {       if (h[i] == h[i + 1]) {         for (auto& fi : f) fi = int(fi * (int64_t)nopt % MOD);         f.insert(begin(f), 0);         f.push_back(0);       } else {         g.assign(begin(f), end(f));         g.push_back(0);         g.push_back(0);         assert(nopt - 2 >= 0);         std::transform(begin(f), end(f), ++begin(g), ++begin(g),                        [nopt](int fi, int gi) {                          return int((gi + fi * int64_t(nopt - 2)) % MOD);                        });         std::transform(begin(f), end(f), ++ ++begin(g), ++ ++begin(g),                        [](int fi, int gi) {                          return gi + fi >= MOD ? gi + fi - MOD : gi + fi;                        });         std::swap(f, g);       }     }     std::cout << std::accumulate(begin(f) + n + 1, end(f), 0LL) % MOD <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int arr[maxn];   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       for (int i = 0; i < n; ++i) cin >> arr[i];       for (int i = 0; i < n; ++i) {         if (i % 2) {           if (arr[i] > 0) arr[i] = -arr[i];         } else {           if (arr[i] < 0) arr[i] = -arr[i];         }       }       for (int i = 0; i < n; ++i) cout << arr[i] <<    ;       cout << endl;     }     return 0;   }


/* https://codeforces.com/blog/entry/87523 */   #include <stdio.h>   #include <stdlib.h>   #include <string.h>      #define N 100000      int *ej[N], eo[N];      void append(int i, int j) {    int o = eo[i]++;       if (o >= 2 && (o & o - 1) == 0)     ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);    ej[i][o] = j;   }      int main() {    static int dd[N], ll[N + 1], qu[N], *qq[N], kk[N], dp[N + 1], dq[N + 1];    static char ans[N + 1];    int n, x, y, h, i, d, d_, k, s, cnt;       scanf( %d%d , &n, &x);    for (i = 0; i < n; i++)     ej[i] = (int *) malloc(2 * sizeof *ej[i]);    for (i = 1; i < n; i++) {     int p;        scanf( %d , &p), p--;     append(p, i);    }    for (i = 1; i < n; i++)     dd[i] = n;    cnt = 0, qu[cnt++] = 0;    for (d = 0; d < n && cnt; d++) {     qq[d] = (int *) malloc(cnt * sizeof *qq[d]), memcpy(qq[d], qu, (kk[d] = cnt) * sizeof *qu);     cnt = 0;     for (h = 0; h < kk[d]; h++) {      int o;         i = qq[d][h];      for (o = eo[i]; o--; ) {       int j = ej[i][o];          qu[cnt++] = j;      }     }    }    d_ = d;    for (d = 0; d < d_; d++)     ll[kk[d]]++;    dp[0] = -1;    for (k = 1; k <= n; k++) {     if (ll[k] == 0)      continue;     for (s = 0; s <= n; s++)      dq[s] = dp[s] ? 0 : (s >= k && dq[s - k] < ll[k] ? dq[s - k] : ll[k]) + 1;     for (s = 0; s <= n; s++)      if (!dp[s] && dq[s] <= ll[k])       dp[s] = k;    }    if (dp[x]) {     printf( %d n , d_);     memset(ll, 0, (n + 1) * sizeof *ll);     for (k = n, s = x; k >= 1; k--)      while (dp[s] == k)       s -= k, ll[k]++;     for (d = 0; d < d_; d++)      if (ll[kk[d]]) {       ll[kk[d]]--;       for (h = 0; h < kk[d]; h++)        ans[qq[d][h]] =  a ;      } else       for (h = 0; h < kk[d]; h++)        ans[qq[d][h]] =  b ;    } else {     printf( %d n , d_ + 1);     y = n - x;     for (d = 0; d < d_; d++)      if (x >= kk[d])       for (h = 0; h < kk[d]; h++)        ans[qq[d][h]] =  a , x--;      else if (y >= kk[d])       for (h = 0; h < kk[d]; h++)        ans[qq[d][h]] =  b , y--;      else {       for (h = 0; h < kk[d]; h++) {        i = qq[d][h];        if (eo[i])         ans[i] =  a , x--;       }       for (h = 0; h < kk[d]; h++) {        i = qq[d][h];        if (!eo[i]) {         if (x > 0)          ans[i] =  a , x--;         else          ans[i] =  b , y--;        }       }      }    }    printf( %s n , ans);    return 0;   }


#include <bits/stdc++.h>   #ifdef ALGO   #include  el_psy_congroo.hpp    #else   #define DUMP(...) 1145141919810   #define CHECK(...) (__VA_ARGS__)   #endif      struct Dsu {     std::vector<int> dsu;        explicit Dsu(int size) : dsu(size) {       std::iota(dsu.begin(), dsu.end(), 0);     }        int find(int x) {       return dsu[x] == x ? x : dsu[x] = find(dsu[x]);     }   };      using LL = long long;      LL binom2(int x) {     if (x < 2) return 0;     return x * 1LL * (x - 1) / 2;   }      struct Solver {     int n;     std::vector<std::vector<int>> edges;     std::vector<int> sz;     std::vector<int> parent;        Solver(int n, std::vector<std::vector<int>> edges) : n(n), edges(edges), sz(n), parent(n, -1) {}        void dfs(int u, int fa) {       parent[u] = fa;       sz[u] = 1;       for (int v : edges[u]) if (v != fa) {         dfs(v, u);         sz[u] += sz[v];       }     }        void solve() {       dfs(0, -1);       std::vector<LL> result(n + 1);       for (int v : edges[0]) result[0] += binom2(sz[v]);       std::set<int> eds;       Dsu dsu(n);       std::vector<bool> mark(n);       mark[0] = true;       std::set<int> r1;       for (int u = 1; u < n; ++u) {         if (!mark[u]) {           eds.emplace(u);           for (int v = u; ; v = dsu.find(v)) {             mark[v] = true;             int w = parent[v];             if (w == 0) break;             if (eds.count(w)) {               eds.erase(w);             }             dsu.dsu[v] = w;           }         }         r1.emplace(dsu.find(u));         if (r1.size() != eds.size()) {           break;         }         if (eds.size() == 2) {           LL val = 1;           for (int v : eds)             val *= sz[v];           result[u + 1] += val;         } else if (eds.size() == 1) {           LL val = sz[*eds.begin()];           val *= n - sz[dsu.find(u)];           result[u + 1] += val;         }         if (u > 1) result[u] -= result[u + 1];       }       result[1] = binom2(n) - std::accumulate(result.begin(), result.end(), 0LL);       for (int i = 0; i <= n; ++i)         printf( %lld%c , result[i],    n [i == n]);     }   };      int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::istream& reader = std::cin;        int cas;     reader >> cas;     while (cas--) {       int n;       reader >> n;       std::vector<std::vector<int>> edges(n);       for (int i = 0; i < n - 1; ++i) {         int x, y;         reader >> x >> y;         edges[x].emplace_back(y);         edges[y].emplace_back(x);       }       Solver(n, edges).solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxm = 1e+18;   vector<long long> prime;   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   void primeFactors(long long n) {     prime.clear();     while (n % 2 == 0) {       prime.push_back(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         prime.push_back(i);         n = n / i;       }     }     if (n > 2) prime.push_back(n);   }   long long getRes(long long n, long long p) {     long long res = 1;     long long x[101];     long long i = 1;     long long j = 0;     long long z = p;     while (true) {       if (z > n) break;       x[j++] = n / z;       if (maxm / z < p) break;       z *= p;       i++;     }     for (int i = 0; i < j - 1; i++) {       x[i] -= x[i + 1];     }     long long mul = 1;     for (int i = 0; i < j; i++) {       long long val = power(power(p, mul), x[i]);       res = (res * (val) % 1000000007) % 1000000007;       mul += 1;     }     return res;   }   int main() {     long long x, n;     cin >> x >> n;     primeFactors(x);     vector<long long>::iterator ip;     ip = std::unique(prime.begin(), prime.end());     prime.resize(std::distance(prime.begin(), ip));     long long ans = 1;     for (int i = 0; i < prime.size(); i++) {       long long res = getRes(n, prime[i]);       ans = (ans * res) % 1000000007;     }     cout << ans <<   n ;   }


#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...);   }   const int N = 3e5 + 5;   long long a[N];   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     string open =  ([{< ;     string close =  )]}> ;     map<char, char> closeMp;     for (int i = 0; i < 4; i++) closeMp[close[i]] = open[i];     stack<char> st;     int ans = 0;     for (auto i : s) {       if (closeMp.count(i) == 0) {         st.push(i);       } else {         if (st.empty())           return cout <<  Impossible , 0;         else {           if (st.top() != closeMp[i]) ans++;           st.pop();         }       }     }     if (st.empty())       cout << ans;     else       cout <<  Impossible ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum(       long long sum) {     long long lower = 0, upper = (long long)15E8, mid;     while (lower < upper) {       mid = (lower + upper) / 2;       if (mid * (mid + 1) / 2 >= sum)         upper = mid;       else         lower = mid + 1;     }     return lower;   }   long long find_answer(long long n, long long H) {     long long lower = H - 1, upper = (long long)15E8, mid;     while (lower < upper) {       mid = (lower + upper) / 2;       long long current_sum = mid * (mid + 1) / 2 - H * (H - 1) / 2;       long long remaining_sum = n - current_sum;       if (find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum(               remaining_sum) <= mid + 1)         upper = mid;       else         lower = mid + 1;     }     long long current_sum = lower * (lower + 1) / 2 - H * (H - 1) / 2;     long long remaining_sum = n - current_sum;     long long total_blocks_till_now = lower - (H - 1);     return total_blocks_till_now +            find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum(                remaining_sum);   }   int main() {     long long n, H;     cin >> n >> H;     cout << find_answer(n, H) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int A, int B) {     if (B == 0)       return A;     else       return gcd(B, A % B);   }   long long int mod_exponentiation(long long int base, long long int exponent,                                    int modulus) {     long long int result = 1;     while (exponent > 0) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   int fermat(long long int n, long long int m) {     return mod_exponentiation(n, m - 2, m);   }   struct node {     int a;     int cnt;   };   struct Compare {     bool operator()(node &a, node &b) { return a.cnt > b.cnt; }   };   inline int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   inline T sqr(T x) {     return x * x;   }   int main() {     int n;     cin >> n;     int a[8];     for (int i = 0; i < 7; i++) {       cin >> a[i + 1];     }     int sum = 0;     for (int i = 1; i <= 7;) {       sum += a[i];       if (sum >= n) {         cout << i;         return 0;       }       i++;       if (i > 7) {         i %= 7;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200006;   vector<vector<int> > edges(N);   vector<int> color;   bool bipartite;   vector<pair<int, int> > e;   int n, m;   void dfs(int node, int c) {     color[node] = c;     for (auto to : edges[node]) {       if (color[to] == -1) {         dfs(to, c ^ 1);       } else {         if (color[to] == color[node]) {           bipartite = false;         }       }     }     return;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       edges[x].push_back(y);       edges[y].push_back(x);       e.push_back(make_pair(x, y));     }     bipartite = true;     color = vector<int>(n, -1);     dfs(0, 0);     if (!bipartite) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (int i = 0; i < m; i++) {       cout << (color[e[i].first] < color[e[i].second]);     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ask(string q, int x) {     cout << q <<     << x << endl;     int ret;     cin >> ret;     return ret;   }   int getclosestnode(vector<vector<int>> &adj, set<int> &me, int node) {     bool visited[1001];     memset(visited, 0, sizeof visited);     queue<int> q;     q.push(node);     while (!q.empty()) {       int u = q.front();       q.pop();       if (me.count(u) != 0)         return u;       else         for (auto x : adj[u])           if (!visited[x]) {             q.push(x);             visited[x] = 1;           }     }     return -1;   }   void solve() {     int n;     vector<vector<int>> adj(1001);     cin >> n;     for (int i = 0; i < (int)(n - 1); i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     set<int> me, li;     int k;     cin >> k;     for (int i = 0; i < (int)(k); i++) {       int a;       cin >> a;       me.insert(a);     }     cin >> k;     for (int i = 0; i < (int)(k); i++) {       int a;       cin >> a;       li.insert(a);     }     int node = ask( B , *li.begin());     if (me.count(node) != 0)       cout <<  C   << node << endl;     else {       int closest = getclosestnode(adj, me, node);       int liclose = ask( A , closest);       if (li.count(liclose) != 0) {         cout <<  C   << closest << endl;       } else         cout <<  C   << -1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tc;     cin >> tc;     for (int i = 0; i < (int)(tc); i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct arc_t {     int u, v, c;     arc_t(int _u, int _v, int _c) : u(_u), v(_v), c(_c) {}     bool operator<(const arc_t& rhs) const { return c < rhs.c; }   };   int pa[2001];   void set_init(int n) {     for (int i = 1; i <= n; i++) pa[i] = i;   }   int set_find(int x) { return pa[x] == x ? x : pa[x] = set_find(pa[x]); }   int set_union(int x, int y) {     x = set_find(x);     y = set_find(y);     if (x == y) {       return -1;     }     pa[y] = x;     return 0;   }   int f[2001][2001];   vector<pair<int, int> > G[2001];   long long d[2001][2001];   int root;   vector<bool> mark;   int dfs(int u) {     mark[u] = true;     for (vector<pair<int, int> >::iterator i = G[u].begin(); i != G[u].end();          i++) {       int v = i->first;       if (!mark[v]) {         d[root][v] = d[root][u] + i->second;         dfs(v);       }     }   }   int getd(int _r) {     root = _r;     mark.clear();     mark.resize(2001, false);     d[_r][_r] = 0;     dfs(_r);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &f[i][j]);     vector<arc_t> arc;     arc.reserve(n * n / 2 + 1);     for (int i = 1; i <= n; i++) {       if (f[i][i]) {         puts( NO );         return 0;       }       for (int j = i + 1; j <= n; j++) {         if (!f[i][j] || f[i][j] != f[j][i]) {           puts( NO );           return 0;         }         arc.push_back(arc_t(i, j, f[i][j]));       }     }     sort(arc.begin(), arc.end());     set_init(n);     for (vector<arc_t>::iterator it = arc.begin(); it != arc.end(); it++) {       if (!set_union(it->u, it->v)) {         G[it->u].push_back(make_pair(it->v, it->c));         G[it->v].push_back(make_pair(it->u, it->c));       }     }     for (int i = 1; i <= n; i++) {       getd(i);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (d[i][j] != f[i][j]) {           puts( NO );           return 0;         }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   const long long mod = 1e9 + 7;   const long long M = 1e8 + 5;   const long long N = 6e5 + 5;   char s[N];   bool check() {     map<char, long long> mp;     long long len = strlen(s + 1);     long long l = 1;     while (s[l] ==  a ) l++;     if (l == 1) return 0;     long long pos = l;     while (s[l] ==  b ) l++;     if (l == pos) return 0;     while (s[l] ==  c ) l++;     if (l != len + 1) return 0;     for (register long long i = 1; i <= len; i++) mp[s[i]]++;     if (mp[ c ] == mp[ a ] || mp[ c ] == mp[ b ]) return 1;     return 0;   }   inline void solve() {     scanf( %s , s + 1);     puts(check() ?  YES  :  NO );   }   signed main() {     long long T = 1;     for (long long index = 1; index <= T; index++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e2 + 10;   int a[maxx], b[maxx];   int n;   inline bool check(int m) {     int max1 = 0, max2 = 0;     for (int i = 1; i <= n; i++) {       if (a[i] && !b[i])         max1 += m;       else if (a[i] && b[i])         max1 += 1, max2 += 1;       else if (!a[i] && b[i])         max2 += 1;       else         ;     }     return max1 > max2;   }   int main() {     while (cin >> n && n) {       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) cin >> b[i];       int l = 1, r = 1e7, mid;       int ans = -1;       while (l <= r) {         mid = l + r >> 1;         if (check(mid)) {           ans = mid;           r = mid - 1;         } else           l = mid + 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s, ans;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cin.ignore(numeric_limits<streamsize>::max(),   n );     cin >> s;     bool flag = true;     int cnt = 0, max_cnt = 0;     for (int i = 0; i < n - 1; ++i) {       string sub = s.substr(i, 2);       cnt = 0;       for (int j = 0; j < n - 1; ++j) {         flag = true;         for (int k = 0; k < 2; ++k) {           if (sub[k] != s[j + k]) flag = false;         }         if (flag) ++cnt;         if (cnt > max_cnt) {           max_cnt = cnt;           ans = sub;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int FFTMOD = 1007681537;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   const int maxn = 2e5 + 5;   int n;   vector<int> adj[maxn];   int par[maxn];   int size[maxn];   int f[maxn];   void dfs(int u, int p) {     size[u] = 1;     par[u] = p;     for (int v : adj[u]) {       if (v != p) {         dfs(v, u);         size[u] += size[v];       }     }   }   void chemthan() {     cin >> n;     for (int i = (0); i < (n); ++i) {       int u;       cin >> u;       u--;       if (u != -1) {         adj[u].push_back(i);         adj[i].push_back(u);       }     }     if (!(n & 1)) {       cout <<  NO n ;       return;     }     dfs(0, -1);     for (int u = (0); u < (n); ++u) {       int tot = 0;       for (int v : adj[u]) {         if (v != par[u]) {           if (!(size[v] & 1)) {             f[u]++;           }           tot += size[v];         }       }       tot = n - tot - 1;       if (!(tot & 1) && tot) {         f[u]++;       }     }     static int deg[maxn];     static int rem[maxn];     for (int u = (0); u < (n); ++u) deg[u] = int((adj[u]).size());     set<int> st;     for (int u = (0); u < (n); ++u) {       if (!f[u] && !(deg[u] & 1)) {         st.insert(u);       }     }     vector<int> res;     while (int((st).size())) {       int u = *st.begin();       st.erase(u);       if (deg[u] & 1) {         continue;       }       res.push_back(u);       rem[u] = 1;       for (int v : adj[u]) {         deg[v]--;         f[v]--;         if (!f[v] && !rem[v] && !(deg[v] & 1)) {           st.insert(v);         }       }     }     if (int((res).size()) != n) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     for (int u : res) {       cout << u + 1 <<   n ;     }   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0), cin.tie(0);     if (argc > 1) {       assert(freopen(argv[1],  r , stdin));     }     if (argc > 2) {       assert(freopen(argv[2],  wb , stdout));     }     chemthan();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000010;   int n, k;   int C[MAXN];   void load() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , C + i);   }   bool A[MAXN];   int previ[MAXN];   int nexti[MAXN];   int last[MAXN];   void sito() {     int x = 2;     for (int i = 0; i < MAXN; i++) A[i] = true;     while (x * x <= MAXN) {       int y = MAXN - 1;       while (y != x) {         y = previ[y];         long long z = (long long)x * y;         if (z >= MAXN) continue;         last[z] = x;         nexti[previ[z]] = nexti[z];         previ[nexti[z]] = previ[z];         A[z] = false;       }       x = nexti[x];     }   }   int CFactors[MAXN];   bool solve() {     for (int i = 1; i < MAXN; i++) {       previ[i] = i - 1;       nexti[i] = i + 1;     }     sito();     for (int i = 0; i < MAXN; i++)       if (A[i]) last[i] = i;     for (int i = 0; i < n; i++) {       int c = C[i];       while (c > 1) {         int l = last[c];         int br = 0;         while (c % l == 0) {           br++;           c /= l;         }         CFactors[l] = max(CFactors[l], br);       }     }     while (k > 1) {       int l = last[k];       int br = 0;       while (k % l == 0) {         br++;         k /= l;       }       if (br > CFactors[l]) return false;     }     return true;   }   int main() {     load();     if (solve())       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     if (n == 1 || n == 4 || n == 6 || n == 8 || n == 9 || n == 10 || n == 13 ||         n == 15)       cout <<  1  << endl;     else       cout <<  0  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[100];   long long u, v;   int MOD;   void addmod(int &x, int y) { x = (x + y) % MOD; }   int dfs(long long minx, long long maxx, long long left, long long right,           long long state, int step) {     if (left <= minx && maxx <= right) {       int ret = 0;       long long r = (v >= state) ? ((v - state) >> step) : -1;       long long l = (u - 1 >= state) ? ((u - 1 - state) >> step) : -1;       if (r < 0LL) return 0;       long long a = l + r + 1, b = r - l;       if (a & 1)         b >>= 1;       else         a >>= 1;       ret = a % MOD * (b % MOD) % MOD;       ret = (long long)ret * p[step] % MOD;       addmod(ret, (r - l) % MOD * (state % MOD) % MOD);       addmod(ret, (r - l) % MOD);       return ret;     }     long long mid = (minx + maxx) / 2;     int ret = 0;     if (left <= mid) addmod(ret, dfs(minx, mid, left, right, state, step + 1));     if (right > mid)       addmod(ret,              dfs(mid + 1, maxx, left, right, state | (1LL << step), step + 1));     return ret;   }   int main() {     long long n, l, r;     int m;     scanf( %I64d%d%d , &n, &m, &MOD);     p[0] = 1 % MOD;     for (int i = 1; i <= 90; ++i) {       p[i] = (p[i - 1] * 2) % MOD;     }     for (int i = 0; i < m; ++i) {       scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v);       u = max(0LL, u - 1);       v = min(n - 1, v - 1);       if (u > v)         puts( 0 );       else         printf( %d n , dfs(0, n - 1, l - 1, r - 1, 0, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long MAX = 105;   long long n, m, x, y, z, k;   struct Matrix {     long long row, col;     long long m[MAX][MAX];   };   Matrix Multiply(Matrix A, Matrix B) {     Matrix ans;     ans.row = A.row;     ans.col = B.col;     for (long long i = 1; i <= A.row; i++) {       for (long long j = 1; j <= B.col; j++) {         ans.m[i][j] = 0;         for (long long k = 1; k <= A.col; k++) {           ans.m[i][j] += (A.m[i][k] * B.m[k][j]) % mod;           if (ans.m[i][j] >= mod) ans.m[i][j] -= mod;         }       }     }     return ans;   }   Matrix Power(Matrix mat, long long p) {     Matrix res;     Matrix ans;     ans.row = res.row = mat.row;     ans.col = res.col = mat.col;     long long n = ans.row;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         ans.m[i][j] = 0;         res.m[i][j] = mat.m[i][j];       }       ans.m[i][i] = 1;     }     while (p) {       if (p % 2 == 1) ans = Multiply(ans, res);       res = Multiply(res, res);       p = p / 2;     }     return ans;   }   Matrix power(Matrix mat, long long p) {     if (p == 1) return mat;     if (p & 1) return Multiply(mat, power(mat, p - 1));     Matrix re = power(mat, (p / 2));     return Multiply(re, re);   }   Matrix mat;   long long ara[MAX];   int main() {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &ara[i]);     }     if (k == 1) {       cout << n << endl;       return 0;     }     mat.row = mat.col = n;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         long long val = ara[i] ^ ara[j];         if (__builtin_popcountll(val) % 3 == 0)           mat.m[i][j] = 1;         else           mat.m[i][j] = 0;       }     }     mat = power(mat, k - 1);     long long ans = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         ans = (ans + mat.m[i][j]);         if (ans >= mod) ans -= mod;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : (-x);   }   template <class T>   T sqr(T x) {     return x * x;   }   const int maxn = 1000 * 1000 * 2;   const int BUBEN = 40;   long long fib[BUBEN];   int a[maxn];   int n;   long long X, Y;   long long P;   struct M {     long long a[2][2];     M() { memset(a, 0, sizeof(a)); }     long long* operator[](int x) { return a[x]; }     M operator*(M m) {       M res;       for (int i = 0; i < 2; ++i)         for (int j = 0; j < 2; ++j)           for (int k = 0; k < 2; ++k)             res[i][j] = (res[i][j] + a[i][k] * m[k][j]) % P;       return res;     }   };   M pw(M x, long long y) {     M res;     res[0][0] = res[1][1] = 1;     while (y) {       if (y % 2LL == 1LL)         res = res * x, --y;       else         x = x * x, y /= 2LL;     }     return res;   }   const double alpha = (1. + sqrt(5.)) * 0.5;   bool cmp(pair<long long, long long> p, pair<long long, long long> q) {     if (X >= BUBEN - 2)       return p.first * alpha + p.second > q.first * alpha + q.second;     return p.first * fib[X + 1] + p.second * fib[X] >            q.first * fib[X + 1] + q.second * fib[X];   }   int main() {     fib[0] = 0;     fib[1] = 1;     for (int i = 2; i < BUBEN; ++i) fib[i] = fib[i - 1] + fib[i - 2];     cin >> n >> X >> Y >> P;     long long sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       sum += a[i];       sum %= P;     }     sort(a, a + n);     if (0) {       vector<int> v;       for (int i = 0; i < n; ++i) v.push_back(a[i]);       for (int i = 0; i < X; ++i) {         vector<int> w;         w.push_back(v[0]);         for (int j = 1; j < ((int)(v).size()); ++j)           w.push_back(v[j - 1] + v[j]), w.push_back(v[j]);         v = w;       }       sort((v).begin(), (v).end());       for (int i = 0; i < Y; ++i) {         vector<int> w;         w.push_back(v[0]);         for (int j = 1; j < ((int)(v).size()); ++j)           w.push_back(v[j - 1] + v[j]), w.push_back(v[j]);         v = w;       }       long long res = 0;       for (int i = 0; i < ((int)(v).size()); ++i) res += v[i];       res %= P;       cerr << res <<   n ;     }     if (n == 1) {       cout << (a[0] % P) <<   n ;       return 0;     }     long long l1 = a[0], r1 = a[n - 1];     long long l2 = a[0];     pair<long long, long long> _r2(-1, -1);     for (int i = 0; i < n - 1; ++i) {       long long x = a[i], y = a[i + 1];       if (x < y) swap(x, y);       pair<long long, long long> cur(x, y);       if (cmp(cur, _r2)) _r2 = cur;     }     M mf;     mf[0][0] = mf[0][1] = mf[1][0] = 1;     M F = pw(mf, X);     long long r2 = F[0][0] * (_r2.first % P) + F[0][1] * (_r2.second % P);     r2 %= P;     M m1;     m1[0][0] = 3;     m1[0][1] = (P - 1) % P;     m1[1][1] = 1;     M m2 = pw(m1, X);     long long T1 = l1 + r1;     long long T2 = l2 + r2;     T1 %= P;     T2 %= P;     long long s0 = m2[0][0] * sum + m2[0][1] * (T1);     s0 %= P;     M m3 = pw(m1, Y);     long long res = m3[0][0] * s0 + m3[0][1] * (T2);     res %= P;     res += P;     res %= P;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[123];   int l[123];   int t[123][123];   int h[123][123];   int main() {     int n, m, H;     cin >> n >> m >> H;     for (int i = 0; i < m; i++) scanf( %d , f + i);     for (int i = 0; i < n; i++) scanf( %d , l + i);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &t[i][j]);     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++)         if (t[i][j] && l[i] >= f[j]) {           h[i][j] = f[j];         }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (t[i][j] && f[j] >= l[i]) {           h[i][j] = max(h[i][j], l[i]);         }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) printf( %d  , h[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, a[100100], p = 1;     scanf( %lld , &n);     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] >= p) p++;     }     printf( %lld n , p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string toString(int n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   int main() {     int n;     cin >> n;     int arr[100];     map<int, int> mp;     vector<int> vp;     for (int i = 0; i < n; i++) cin >> arr[i], mp[arr[i]]++, vp.push_back(arr[i]);     sort(arr, arr + n);     {       sort((vp).begin(), (vp).end());       (vp).erase(unique((vp).begin(), (vp).end()), vp.end());     };     int ans = 0;     for (int i = 0; i < vp.size(); i++) {       ans += mp[vp[i]] / 2;     }     cout << (ans / 2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     cin >> t;     while (t--) {       int n, nrp = 0, nri = 0;       cin >> n;       while (n--) {         int x;         cin >> x;         if (x % 2)           nri++;         else           nrp++;       }       if (nrp == 0)         if (nri % 2)           cout <<  YES n ;         else           cout <<  NO n ;       else if (nri)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, parent[100002];   long long pl[100002], ans, dp[100002][22][5];   vector<long long> gr[100002];   long long ast[65];   void dfs(long long v) {     for (long long i = 0; i <= 20; i++) {       long long x = ((pl[v] >> i) & 1);       dp[v][i][x]++;     }     long long klir[22][5];     for (long long i = 0; i <= 20; i++) {       klir[i][0] = 0;       klir[i][1] = 0;     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       parent[gr[v][i]] = v;       dfs(gr[v][i]);       for (long long j = 0; j <= 20; j++) {         klir[j][0] += dp[gr[v][i]][j][0];         klir[j][1] += dp[gr[v][i]][j][1];       }     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       for (long long j = 0; j <= 20; j++) {         long long x = ((pl[v] >> j) & 1);         dp[v][j][x] += dp[gr[v][i]][j][0];         dp[v][j][x ^ 1] += dp[gr[v][i]][j][1];         klir[j][0] -= dp[gr[v][i]][j][0];         klir[j][1] -= dp[gr[v][i]][j][1];         if (x == 1) {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][0];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][1];         } else {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][1];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][0];         }       }     }     for (long long i = 0; i <= 20; i++) ans += dp[v][i][1] * (ast[i]);   }   int main() {     cin >> n;     ast[0] = 1;     for (long long i = 1; i < 64; i++) ast[i] = 2 * ast[i - 1];     for (long long i = 1; i <= n; i++) scanf( %lld , &pl[i]);     for (long long i = 1; i < n; i++) {       long long k, l;       scanf( %lld%lld , &k, &l);       gr[k].push_back(l);       gr[l].push_back(k);     }     dfs(1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 7;   int main() {     string s;     cin >> s;     int ans = 0;     int t = 0;     for (int i = s.length() - 1; i >= 0; i--) {       if (s[i] ==  b )         t = (t + 1) % N;       else {         ans = (ans + t) % N;         t = (t * 2) % N;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read(void) {     int x = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + (c -  0 ), c = getchar();     return x;   }   const int N = 150010, M = 300010;   int n, m, c;   int loc[N], p[N];   struct xint {     double max_left, max_right, sum, res;     xint() {}     xint(double A) : max_left(A), max_right(A), sum(A), res(A) {}     inline void print(void) {       printf( %.2lf %.2lf %.2lf %.2lf n , sum, max_left, max_right, res);       puts(  );     }   } tr[N * 5];   xint update(xint lc, xint rc) {     xint k;     k.sum = lc.sum + rc.sum;     k.max_left = max(lc.max_left, lc.sum + rc.max_left);     k.max_right = max(rc.max_right, lc.max_right + rc.sum);     k.res = max(lc.res, rc.res);     k.res = max(k.res, lc.max_right + rc.max_left);     return k;   }   void build(int k, int l, int r) {     if (l == r) {       double P = (double)p[l] / 100.0;       double tmp = (double)(loc[l + 1] - loc[l]) / 2 - P * c;       tr[k] = xint(tmp);       return;     }     int mid = (l + r) >> 1;     int lc = k << 1, rc = k << 1 | 1;     build(lc, l, mid);     build(rc, mid + 1, r);     tr[k] = update(tr[lc], tr[rc]);   }   xint query(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) return tr[k];     if (l > r) return 0;     int mid = (l + r) >> 1;     int lc = k << 1, rc = k << 1 | 1;     if (y <= mid) return query(lc, l, mid, x, y);     if (x > mid) return query(rc, mid + 1, r, x, y);     xint tmp1 = query(lc, l, mid, x, y);     xint tmp2 = query(rc, mid + 1, r, x, y);     return update(tmp1, tmp2);   }   int main(void) {     n = read(), m = read(), c = read();     for (int i = 1; i <= n; ++i) loc[i] = read();     for (int i = 1; i < n; ++i) p[i] = read();     build(1, 1, n - 1);     double ans = 0;     for (int i = 1; i <= m; ++i) {       int l = read(), r = read();       xint tmp = query(1, 1, n - 1, l, r - 1);       ans += max(tmp.res, 0.0);     }     printf( %.8lf n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   template <typename T, typename U>   static void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static void amax(T &x, U y) {     if (x < y) x = y;   }   inline uint32_t ifzero(int num) { return (num - 1) >> 31; }   inline int ifnotzero(int num) { return ~((num - 1) >> 31); }   int main() {     int Q;     while (~scanf( %d , &Q)) {       vector<uint32_t> pos(100000), neg(100000);       for (int ii = 0; ii < Q; ++ii) {         int ty;         scanf( %d , &ty);         if (ty == 1) {           int L;           int R;           int k;           scanf( %d%d%d , &L, &R, &k), --L, --R;           uint32_t *data = k > 0 ? pos.data() : neg.data();           uint32_t b = abs(k) - 1;           for (int(x) = (int)(L); (x) < (int)(R); ++(x)) {             auto a = data[x] - 1;             data[x] = (a < b ? a : b) + 1;           }         } else if (ty == 2) {           int L;           int R;           scanf( %d%d , &L, &R), --L, --R;           long long ans = 0;           for (int(x) = (int)(L); (x) < (int)(R); ++(x)) {             ans += (pos[x] + neg[x]) & ifnotzero(pos[x]) & ifnotzero(neg[x]);           }           printf( %lld n , ans);         } else           abort();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<pair<int, int> > V;   int main(int argc, const char *argv[]) {     cin >> N >> M;     for (int i = 0, x, y; i < M; i++) {       cin >> x >> y;       V.push_back(pair<int, int>(x, y));     }     sort(V.begin(), V.end());     vector<pair<int, int> > currI;     currI.push_back(pair<int, int>(1, 1));     int currRow = 0;     for (int i = 0; i < V.size();) {       pair<int, int> p = V[i];       vector<pair<int, int> > newI;       if (p.first > currRow + 1 && currI.size()) {         int left = currI[0].first;         currI.clear();         currI.push_back(pair<int, int>(left, N));       }       currRow = p.first;       vector<pair<int, int> > temp;       int last = 0;       while (i < V.size() && V[i].first == p.first) {         temp.push_back(pair<int, int>(last + 1, V[i].second - 1));         last = V[i].second;         i++;       }       temp.push_back(pair<int, int>(last + 1, N));       int j = 0;       for (auto x : temp) {         while (j < currI.size() && currI[j].second < x.first) j++;         if (j < currI.size()) {           int x1 = max(x.first, currI[j].first), x2 = x.second;           if (x2 >= x1) {             newI.push_back(pair<int, int>(x1, x2));           }         }       }       currI = newI;     }     bool poss = false;     if (currI.size() > 0) {       pair<int, int> l = currI[currI.size() - 1];       poss = (currRow < N && l.second <= N);       poss = poss || (currRow == N && l.second == N);     }     if (poss) {       cout << 2 * (N - 1) << endl;     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = n - 1; i >= 0; i--) cout << a[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000];     cin >> a;     int n = strlen(a), i, up = 1;     for (i = 1; i < n; i++)       if (a[i] >=  a  && a[i] <=  z ) up = 0;     if (up) {       for (i = 1; i < n; i++) a[i] = a[i] +  a  -  A ;       if (a[0] >=  A  && a[0] <=  Z )         a[0] = a[0] +  a  -  A ;       else         a[0] = a[0] +  A  -  a ;     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return a < b ? b : a;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   const char lf =   n ;   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0;     int b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 500007, __ = _ << 1, inf = 0x3f3f3f3f;   struct cxk {     int v, len;     cxk(int v_ = inf, int len_ = 0) { v = v_, len = len_; }     int f(int x) { return min(x + len, v); }     friend cxk operator+(cxk a, cxk b) {       return cxk(min(a.v + b.len, b.v), a.len + b.len);     }   };   struct sgt {     static const int _t = __ << 2;     cxk t[_t];     int mx[_t];     void up(int x) {       t[x] = t[(x << 1)] + t[(x << 1 | 1)];       mx[x] = max(mx[(x << 1)], mx[(x << 1 | 1)]);     }     void plant(int x, int l, int r) {       t[x] = cxk(), mx[x] = -inf;       if (l == r) return;       plant((x << 1), l, ((l + r) >> 1)),           plant((x << 1 | 1), ((l + r) >> 1) + 1, r), up(x);     }     void change(int x, int l, int r, int tar, int dlt) {       if (l == r) {         t[x].len++, t[x].v = dlt, mx[x] = max(mx[x], dlt);         return;       }       if (tar <= ((l + r) >> 1))         change((x << 1), l, ((l + r) >> 1), tar, dlt);       else         change((x << 1 | 1), ((l + r) >> 1) + 1, r, tar, dlt);       up(x);     }     int findlen(int x, int l, int r, int tl, int tr) {       if (tl <= l && r <= tr) return t[x].len;       if (tr <= ((l + r) >> 1))         return findlen((x << 1), l, ((l + r) >> 1), tl, tr);       if (tl > ((l + r) >> 1))         return findlen((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);       return findlen((x << 1), l, ((l + r) >> 1), tl, tr) +              findlen((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);     }     int findmx(int x, int l, int r, int tl, int tr) {       if (tl <= l && r <= tr) return mx[x];       if (tr <= ((l + r) >> 1))         return findmx((x << 1), l, ((l + r) >> 1), tl, tr);       if (tl > ((l + r) >> 1))         return findmx((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);       return max(findmx((x << 1), l, ((l + r) >> 1), tl, tr),                  findmx((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr));     }     cxk findcxk(int x, int l, int r, int tl, int tr) {       if (tl <= l && r <= tr) return t[x];       if (tr <= ((l + r) >> 1))         return findcxk((x << 1), l, ((l + r) >> 1), tl, tr);       if (tl > ((l + r) >> 1))         return findcxk((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);       return findcxk((x << 1), l, ((l + r) >> 1), tl, tr) +              findcxk((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);     }   } t;   int n, val[_], rk[_] = {0};   pair<int, int> temp[_];   int able(int x) { return t.findmx(1, 1, n, 1, x) <= -t.findlen(1, 1, n, 1, x); }   int main() {     ios::sync_with_stdio(0), cout.tie(nullptr);     n = ty();     for (int i = 1; i <= n; i++) val[i] = ty(), temp[i] = make_pair(val[i], i);     sort(temp + 1, temp + n + 1);     for (int i = 1; i <= n; i++) rk[temp[i].second] = i;     t.plant(1, 1, n);     for (int i = 1; i <= n; i++) {       t.change(1, 1, n, rk[i], temp[rk[i]].first);       int l = 1, r = n, ans = -1;       while (r >= l) {         int mid = (l + r) >> 1;         if (able(mid))           ans = mid, l = mid + 1;         else           r = mid - 1;       }       if (ans < 0)         cout << t.findcxk(1, 1, n, 1, n).f(0) << lf;       else {         int ps = t.findlen(1, 1, n, 1, ans);         if (ans >= n)           cout << -ps << lf;         else           cout << t.findcxk(1, 1, n, ans + 1, n).f(-ps) << lf;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[5010];   int mat[5010][5010];   int dp[5010][5010];   int n;   void findAllPalindromes() {     for (int i = 0; i < n; i++) {       for (int j = 0; i - j >= 0 && i + j < n; j++) {         if (s[i - j] == s[i + j])           mat[i - j][i + j] = 1;         else           break;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; i - j >= 0 && i + j + 1 < n; j++) {         if (s[i - j] == s[i + j + 1])           mat[i - j][i + j + 1] = 1;         else           break;       }     }   }   void filldp() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         dp[i][j] =             dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mat[i - 1][j - 1];       }   }   inline int sum(int l, int r) {     int ans = dp[n][r];     if (l > 0) ans -= dp[l - 1][r];     return ans;   }   int main() {     scanf(  %s , s);     n = strlen(s);     findAllPalindromes();     filldp();     int q;     scanf(  %d , &q);     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       printf( %d n , sum(l, r));     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void read(long long &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   const long long N = 105, mod = 1e9 + 9;   long long n, now, m, sz[N], f[N][N], p[N], in[N], res[N];   long long cnt, h[N], to[N * N], nxt[N * N], c[N], inv[N];   void add(long long u, long long v) {     to[++cnt] = v, nxt[cnt] = h[u], h[u] = cnt, ++c[v];   }   queue<long long> q;   long long vis[N], used[N];   void topo() {     for (long long i = 1; i <= n; ++i)       if (c[i] <= 1) vis[i] = 1, q.push(i);     while (!q.empty()) {       long long t = q.front();       q.pop();       for (long long i = h[t], v; i; i = nxt[i]) {         if ((--c[v = to[i]]) <= 1 && !vis[v]) vis[v] = 1, q.push(v);       }     }   }   long long C(long long x, long long y) {     return p[x] * in[y] % mod * in[x - y] % mod;   }   void dp(long long u) {     used[u] = sz[u] = f[u][0] = 1;     for (long long i = h[u], v; i; i = nxt[i]) {       if (used[v = to[i]] || !vis[v]) continue;       dp(v);       for (long long x = sz[u] - 1; x >= 0; --x)         for (long long y = 1; y <= sz[v]; ++y)           ((f[u][x + y] += f[u][x] * f[v][y] % mod * C(x + y, x) % mod) >= mod &&            (f[u][x + y] -= mod));       sz[u] += sz[v];     }     f[u][sz[u]] = f[u][sz[u] - 1];   }   long long Pow(long long x, long long y) {     long long tmp = 1;     while (y) {       if (y & 1) tmp = tmp * x % mod;       x = x * x % mod, y >>= 1;     }     return tmp;   }   vector<long long> st;   void find(long long u, long long la) {     st.push_back(u);     for (long long i = h[u], v; i; i = nxt[i])       if ((v = to[i]) != la) find(v, u);   }   long long tmp[N];   void work(long long u, long long la) {     memset(f[u], 0, sizeof(f[u]));     sz[u] = f[u][0] = 1;     for (long long i = h[u], v; i; i = nxt[i]) {       if ((v = to[i]) == la) continue;       work(v, u);       for (long long x = sz[u] - 1; x >= 0; --x)         for (long long y = 1; y <= sz[v]; ++y)           ((f[u][x + y] += f[u][x] * f[v][y] % mod * C(x + y, y) % mod) >= mod &&            (f[u][x + y] -= mod));       sz[u] += sz[v];     }     f[u][sz[u]] = f[u][sz[u] - 1];   }   void merge(long long *a, long long tot) {     for (long long i = now; i >= 0; --i)       for (long long j = 1; j <= tot; ++j)         ((res[i + j] += res[i] * a[j] % mod * C(i + j, i) % mod) >= mod &&          (res[i + j] -= mod));     now += tot;   }   signed main() {     read(n), read(m);     for (long long i = 1, u, v; i <= m; ++i)       read(u), read(v), add(u, v), add(v, u);     topo();     p[0] = res[0] = 1;     for (long long i = 1; i <= n; ++i) p[i] = p[i - 1] * i % mod;     in[n] = Pow(p[n], mod - 2);     for (long long i = n - 1; i >= 0; --i) in[i] = in[i + 1] * (i + 1) % mod;     for (long long i = 1; i <= n; ++i) inv[i] = Pow(i, mod - 2);     for (long long i = 1; i <= n; ++i) {       if (vis[i]) continue;       for (long long j = h[i], v; j; j = nxt[j])         if (vis[v = to[j]] && !used[v]) dp(v), merge(f[v], sz[v]);     }     for (long long i = 1; i <= n; ++i)       if (vis[i] && !used[i]) {         st.clear(), find(i, i);         long long tot = st.size();         memset(tmp, 0, sizeof(tmp));         for (long long j = 0; j < tot; ++j) {           work(st[j], st[j]), used[st[j]] = 1;           for (long long k = 0; k <= tot; ++k)             ((tmp[k] += f[st[j]][k]) >= mod && (tmp[k] -= mod));         }         for (long long j = 0; j < tot; ++j) tmp[j] = tmp[j] * inv[tot - j] % mod;         merge(tmp, tot);       }     for (long long i = 0; i <= n; ++i) printf( %lld n , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int id, v;   } tree[4 * 100005];   int in[100005];   void build(int nod, int s, int e) {     if (s == e) {       tree[nod].id = s;       tree[nod].v = in[s];       return;     }     int mid = (s + e) / 2, l = 2 * nod, r = l + 1;     build(l, s, mid);     build(r, mid + 1, e);     if (tree[l].v > tree[r].v) {       tree[nod].v = tree[l].v;       tree[nod].id = tree[l].id;     } else {       tree[nod].v = tree[r].v;       tree[nod].id = tree[r].id;     }   }   pair<int, int> query(int nod, int s, int e, int i, int j) {     if (s > j || e < i) return {-1, -1};     if (s >= i && e <= j) return {tree[nod].v, tree[nod].id};     int mid = (s + e) / 2, l = 2 * nod, r = l + 1;     pair<int, int> a = query(l, s, mid, i, j);     pair<int, int> b = query(r, mid + 1, e, i, j);     if (a.first > b.first)       return a;     else       return b;   }   long long save[100005];   long long ans[100005];   int main() {     int n, i;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d , &in[i]);     }     build(1, 1, n);     save[n - 1] = 1;     ans[n - 1] = 1;     pair<int, int> a = query(1, 1, n, 6, 8);     for (i = n - 2; i >= 1; i--) {       pair<int, int> pp = query(1, 1, n, i + 1, in[i]);       save[i] = pp.second - i + save[pp.second] + n - in[i];       ans[i] = ans[i + 1] + save[i];     }     printf( %I64d n , ans[1]);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, const T &b) {     if (b > a) a = b;   }   const int maxn = 1e3 + 10;   const int inf = 1e9 + 10;   const long long mod = 1e9 + 7;   int dp[maxn][maxn][4], g[maxn];   int n, k;   long long fac[maxn], c[maxn][maxn];   int main() {     scanf( %d%d , &n, &k);     dp[0][0][2] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j <= n; j++)         for (int mask = 0; mask < 4; mask++) {           if (dp[i][j][mask] == 0) continue;           int mask2 = (mask & 1) << 1;           dp[i + 1][j][mask2] += dp[i][j][mask];           dp[i + 1][j][mask2] %= mod;           if (!((mask >> 1) & 1))             dp[i + 1][j + 1][mask2] += dp[i][j][mask],                 dp[i + 1][j + 1][mask2] %= mod;           if (i == n - 1) continue;           mask2 |= 1;           dp[i + 1][j + 1][mask2] += dp[i][j][mask];           dp[i + 1][j + 1][mask2] %= mod;         }     fac[0] = 1;     for (long long i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;     for (int i = k; i <= n; i++) {       long long now = 0;       for (int mask = 0; mask < 4; mask++) now += dp[n][i][mask], now %= mod;       g[i] = now * fac[n - i] % mod;     }     c[0][0] = 1;     for (int i = 1; i < maxn; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;     }     long long ans = 0;     for (int i = k; i <= n; i++) {       if ((i - k) & 1)         ans -= c[i][k] * g[i] % mod, ans += mod;       else         ans += c[i][k] * g[i] % mod;       ans %= mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   template <class T>   bool get_max(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   bool get_min(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   const int maxn = 1000000 + 5;   int n, m, r1, r2, sv[maxn];   void output() {     for (int i = n; i >= 0; i--) {       for (int j = 0; j < sv[i]; j++) {         printf( 7 );       }       if (i) printf( 4 );     }     printf(  n );   }   int main() {     scanf( %d%d%d%d , &n, &m, &r1, &r2);     memset(sv, 0, sizeof(sv));     for (int i = 1; i < n; i++) {       if (r1 && r2) {         if (!m) {           printf( -1 n );           return 0;         } else {           r1--;           r2--;           sv[i]++;           m--;         }       }     }     if (r1) {       if (!m) {         printf( -1 n );         return 0;       } else {         r1--;         sv[0]++;         m--;       }     }     if (r2) {       if (!m) {         printf( -1 n );         return 0;       } else {         r2--;         sv[n]++;         m--;       }     }     if (r1 + r2 != 0) {       printf( -1 n );       return 0;     }     if (sv[0]) {       sv[0] += m;     } else {       sv[1] += m;     }     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn], b[maxn];   int main() {     int n, m;     cin >> n >> m;     int t;     long long sum_n = 0, sum_m = 0;     long long cnt_n = 0, cnt_m = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       cin >> b[i];     }     sum_n = accumulate(a, a + n, 0LL);     sum_m = accumulate(b, b + m, 0LL);     sort(a, a + n);     sort(b, b + m);     for (int i = 0; i < n; i++) {       if (a[i] < sum_m && i < n - 1) {         cnt_n += a[i];       } else {         cnt_n += sum_m;       }     }     for (int i = 0; i < m; i++) {       if (b[i] < sum_n && i < m - 1) {         cnt_m += b[i];       } else {         cnt_m += sum_n;       }     }     printf( %lld n , min(cnt_n, cnt_m));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int a[455];   int b[455];   vector<int> G[455];   int boss[455];   void init() {     for (int i = 1; i < 455; i++) boss[i] = i;   }   int find_boss(int x) {     return boss[x] = (boss[x] == x ? x : find_boss(boss[x]));   }   bool unite(int x, int y) {     int bx = find_boss(x);     int by = find_boss(y);     if (bx == by) return false;     boss[bx] = by;     return true;   }   vector<pair<pair<int, int>, int> > res;   int pour(int from, int to, int d) {     int flow = min(d, max(a[to] - b[to], 0));     a[to] -= flow;     int pos = ((int)(res).size());     for (int i = 0; flow < d && i < ((int)(G[to]).size()); i++) {       int v = G[to][i];       if (v == from) continue;       flow += pour(to, v, d - flow);     }     if (from != -1) {       int po = min(a[to], flow);       if (po > 0)         res.insert(res.begin() + pos, make_pair(make_pair(to, from), po));       if (po < flow) res.push_back(make_pair(make_pair(to, from), flow - po));     }     return flow;   }   int main() {     int n, v, e;     scanf( %d %d %d , &n, &v, &e);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     init();     while (e--) {       int x, y;       scanf( %d %d , &x, &y);       if (unite(x, y)) {         G[x].push_back(y);         G[y].push_back(x);       }     }     for (int i = 1; i <= n; i++)       if (a[i] < b[i]) a[i] += pour(-1, i, b[i] - a[i]);     for (int i = 1; i <= n; i++)       if (a[i] != b[i]) return puts( NO ), 0;     printf( %d n , ((int)(res).size()));     for (__typeof((res).begin()) itr = (res).begin(); itr != (res).end(); itr++)       printf( %d %d %d n , itr->first.first, itr->first.second, itr->second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double t0;   double error(long long t1, long long t2, long long x1, long long x2) {     double c = (t1 * x1 + t2 * x2) / double(x1 + x2);     if (c >= t0) return c - t0;     return 1e9;   }   int main() {     long long t1, t2, x1, x2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     double ER = 1e8;     long long a1 = -1, a2 = -1;     for (int y1 = 0; y1 <= x1; y1++) {       long long mi = (t0 != t2) ? (t1 * y1 - t0 * y1) / (t0 - t2) : 1000000000;       for (long long y2 = min(max(mi - 10, 0LL), x2);            y2 <= max(min(mi + 10, x2), 0LL); ++y2) {         if (y1 == 0 && y2 == 0) continue;         double calc = error(t1, t2, y1, y2);         if (ER > calc) {           ER = calc;           a1 = y1;           a2 = y2;         } else if (ER == calc) {           if (a1 + a2 < y1 + y2) a1 = y1, a2 = y2;         }       }     }     cout << a1 <<     << a2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll A[19], cnt, dp[19][4][3][2][2][504][2];   const int p3[]{1, 3, 9};   ll dfs(int pos, int level2, int level3, int level5, int level7, int sum,          bool limit) {     ll ans = 0;     if (dp[pos][level2][level3][level5][level7][sum][limit] != -1)       return dp[pos][level2][level3][level5][level7][sum][limit];     for (int v = 0; v <= (limit ? A[pos] : 9); ++v) {       int l2 = level2, l3 = level3, l5 = level5, l7 = level7;       int cur = (sum * 10 + v) % 504;       if (v == 2) l2 = max(l2, 1);       if (v == 3) l3 = max(l3, 1);       if (v == 4) l2 = max(l2, 2);       if (v == 5) l5 = 1;       if (v == 6) l2 = max(l2, 1), l3 = max(l3, 1);       if (v == 7) l7 = 1;       if (v == 8) l2 = 3;       if (v == 9) l3 = 2;       if (pos == cnt - 1)         ans += cur % (1 << l2) == 0 && cur % p3[l3] == 0 &&                cur % (l7 ? 7 : 1) == 0 && (!l5 || v == 5 || v == 0);       else         ans += dfs(pos + 1, l2, l3, l5, l7, cur, limit && v == A[pos]);     }     if (!limit) dp[pos][level2][level3][level5][level7][sum][limit] = ans;     return ans;   }   ll f(ll x) {     if (x == 0) return 1;     cnt = 0;     while (x) A[cnt++] = x % 10, x /= 10;     reverse(A, A + cnt);     memset(dp, -1, sizeof(dp));     return dfs(0, 0, 0, 0, 0, 0, true);   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       ll x, y;       cin >> x >> y;       ll l = f(x - 1), r = f(y);       cout << r - l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100;   char str[N];   int G[N][N];   int sum_r[N], sum_c[N];   int n, m;   bool vis[N][N];   bool no() {     int r0 = n, c0 = m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sum_r[i] += G[i][j];       }       if (sum_r[i]) r0--;     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         sum_c[j] += G[i][j];       }       if (sum_c[j]) c0--;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j]) {           int k = j;           while (k <= m && G[i][k]) k++;           if (k - j != sum_r[i]) return true;           break;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         if (G[i][j]) {           int k = i;           while (k <= n && G[k][j]) k++;           if (k - i != sum_c[j]) return true;           break;         }       }     }     for (int i = 1; i <= n; i++) {       if (sum_r[i] == 0) {         if (c0 == 0) return true;       }     }     for (int j = 1; j <= m; j++) {       if (sum_c[j] == 0) {         if (r0 == 0) return true;       }     }     return false;   }   vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   void dfs(int x, int y) {     vis[x][y] = 1;     for (auto [dx, dy] : dir) {       int nx = x + dx, ny = y + dy;       if (vis[nx][ny]) continue;       if (G[nx][ny] && 0 < nx && nx <= n && 0 < ny && ny <= m) dfs(nx, ny);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str + 1);       for (int j = 1; j <= m; j++) {         G[i][j] = str[j] ==  #  ? 1 : 0;       }     }     if (no()) {       puts( -1 );       return 0;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j] && !vis[i][j]) {           dfs(i, j);           ans++;         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     stack<int> q;     string str;     cin >> str;     int open = 0, count = 0, rcount = 0;     for (int i = 0; i < str.length(); ++i) {       if (str[i] ==  ( )         open++;       else if (str[i] ==  ) ) {         if (open != 0)           open--;         else           count--;       }       if (str[i] ==  # ) {         count += open - 1;         open = 0;         rcount++;       }       if (count < 0) {         cout << -1;         return 0;       }     }     if (open > 0) {       cout << -1;       return 0;     }     for (int i = 0; i < rcount - 1; i++) cout <<  1  ;     cout << count + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int MOD = 1e9 + 7;   const int N = 1e5 + 7;   int n, m, x, L, R;   long long pre[N][6];   long long sum[N << 2][6];   int laz[N << 2];   inline void pushup(int rt) {     for (int i = int(0); i <= int(5); ++i)       sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i], sum[rt][i] %= MOD;   }   inline void pushdown(int rt, int l, int r) {     if (laz[rt] != -1) {       int m = (l + r) >> 1;       for (int i = int(0); i <= int(5); ++i) {         sum[rt << 1][i] =             ((pre[m][i] - pre[l - 1][i]) % MOD + MOD) % MOD * laz[rt] % MOD;         sum[rt << 1 | 1][i] =             ((pre[r][i] - pre[m][i]) % MOD + MOD) % MOD * laz[rt] % MOD;       }       laz[rt << 1] = laz[rt << 1 | 1] = laz[rt];       laz[rt] = -1;     }   }   void build(int rt, int l, int r) {     laz[rt] = -1;     if (l == r) {       scanf( %d , &x);       sum[rt][0] = (long long)x;       for (int i = int(1); i <= int(5); ++i)         sum[rt][i] = sum[rt][i - 1] * l % MOD;       return;     }     int m = (l + r) >> 1;     build(rt << 1, l, m);     build(rt << 1 | 1, m + 1, r);     pushup(rt);   }   void setv(int rt, int l, int r) {     if (L <= l && r <= R) {       laz[rt] = x;       for (int i = int(0); i <= int(5); ++i) {         sum[rt][i] = ((pre[r][i] - pre[l - 1][i]) % MOD + MOD) % MOD * x % MOD;       }       return;     }     pushdown(rt, l, r);     int m = (l + r) >> 1;     if (L <= m) setv(rt << 1, l, m);     if (R > m) setv(rt << 1 | 1, m + 1, r);     pushup(rt);   }   long long query(int d, int rt, int l, int r) {     if (L <= l && r <= R) {       return sum[rt][d];     }     pushdown(rt, l, r);     int m = (l + r) >> 1;     long long ret = 0;     if (L <= m) ret += query(d, rt << 1, l, m);     if (R > m) ret += query(d, rt << 1 | 1, m + 1, r);     ret %= MOD;     pushup(rt);     return ret;   }   long long solve() {     long long ret;     long long u = (long long)L - 1;     if (x == 0) ret = query(0, 1, 1, n);     if (x == 1) {       ret = query(1, 1, 1, n) - u * query(0, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       return ret;     }     if (x == 2) {       ret = query(2, 1, 1, n) - 2LL * u * query(1, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + (long long)u * u % MOD * query(0, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;     }     if (x == 3) {       ret = query(3, 1, 1, n) - 3LL * u * query(2, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + 3LL * u * u % MOD * query(1, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret - u * u % MOD * u % MOD * query(0, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;     }     if (x == 4) {       ret = query(4, 1, 1, n) - 4LL * u * query(3, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + 6LL * u * u % MOD * query(2, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret - 4LL * u * u % MOD * u % MOD * query(1, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + u * u % MOD * u % MOD * u % MOD * query(0, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;     }     if (x == 5) {       ret = query(5, 1, 1, n) - 5LL * u * query(4, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + 10LL * u * u % MOD * query(3, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret - 10LL * u * u % MOD * u % MOD * query(2, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret + 5LL * u * u % MOD * u % MOD * u % MOD * query(1, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;       ret = ret -             u * u % MOD * u % MOD * u % MOD * u % MOD * query(0, 1, 1, n) % MOD;       ret = (ret % MOD + MOD) % MOD;     }     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = int(1); i <= int(n); ++i) {       long long t = 1;       for (int j = int(0); j <= int(5); ++j) {         pre[i][j] = pre[i - 1][j] + t, pre[i][j] %= MOD;         t = t * i % MOD;       }     }     build(1, 1, n);     char s[5];     for (int i = int(1); i <= int(m); ++i) {       scanf( %s%d%d%d , s, &L, &R, &x);       if (s[0] ==  = ) {         setv(1, 1, n);       } else {         printf( %I64d n , solve());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = int(2.1e5);   vector<pair<int, int>> g[N];   int n, q;   ll res = 0;   class dsu {    public:     using T = int;     vector<int> p;     vector<ll> sz;     int n;     dsu(int _n) : n(_n) {       p.resize(n);       sz.resize(n);       iota(p.begin(), p.end(), 0);       fill(sz.begin(), sz.end(), 1);     }     inline T get(T x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }     inline bool unite(T x, T y) {       T px = get(x);       T py = get(y);       if (px != py) {         if (sz[px] < sz[py]) {           swap(px, py);         }         p[py] = px;         res -= (sz[px] * (sz[px] - 1)) / 2;         res -= (sz[py] * (sz[py] - 1)) / 2;         sz[px] += sz[py];         res += (sz[px] * (sz[px] - 1)) / 2;         return true;       }       return false;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> q;     vector<pair<int, pair<int, int>>> ed(n - 1);     for (int i = 0; i < n - 1; ++i) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       ed[i] = {w, {u, v}};     }     sort(ed.begin(), ed.end());     vector<pair<int, int>> qr(q);     for (int i = 0; i < q; ++i) {       int x;       cin >> x;       qr[i] = {x, i};     }     sort(qr.begin(), qr.end());     vector<ll> ans(q);     int j = 0;     dsu d(n + 1);     for (int i = 0; i < q; ++i) {       while (j < n - 1 && ed[j].first <= qr[i].first) {         d.unite(ed[j].second.first, ed[j].second.second);         j++;       }       ans[qr[i].second] = res;     }     for (ll x : ans) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     k = min(k, 26);     string s =  ab ;     for (int i = 0; i < k - 2; i++) {       s += char(99 + i);     }     string s1 =   ;     for (int i = 0; i < n / k; i++) {       s1 += s;     }     for (int i = 0; i < n % k; i++) {       s1 = s1 + s[i];     }     cout << s1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct node {     struct node* b[3];     int flag[3];   } node;   node* root;   vector<int> ans;   int bit[32], bit_n[32];   void calc(int u) {     memset(bit_n, 0, sizeof(bit_n));     memset(bit, 0, sizeof(bit));     int j = 0, num;     for (num = u; num > 0; num = num / 2) bit_n[j++] = num % 2;     for (int i = 0; i < 32; i++) bit[i] = bit_n[31 - i];   }   void insert(int u) {     node* head;     head = root;     calc(u);     for (int i = 0; i < 32; i++) {       if (head->b[bit[i]] == NULL) {         node* temp;         temp = (node*)malloc(sizeof(node));         for (int j = 0; j < 3; j++) temp->b[j] = NULL, temp->flag[j] = 0;         head->b[bit[i]] = temp;       }       head->flag[bit[i]]++;       head = head->b[bit[i]];     }     return;   }   void del(int u) {     node* head;     head = root;     calc(u);     for (int i = 0; i < 32; i++) {       head->flag[bit[i]]--;       head = head->b[bit[i]];     }     return;   }   void search(int u) {     calc(u);     node* head;     head = root;     for (int i = 0; i < 32; i++) {       if (bit[i] == 1) {         if (head->flag[0])           ans.push_back(1), head = head->b[0];         else           ans.push_back(0), head = head->b[1];       } else {         if (head->flag[1])           ans.push_back(1), head = head->b[1];         else           ans.push_back(0), head = head->b[0];       }     }   }   int main() {     root = (node*)malloc(sizeof(node));     for (int i = 0; i < 3; i++) root->b[i] = NULL, root->flag[i] = 0;     int n;     cin >> n;     insert(0);     char a;     int num;     for (int i = 0; i < n; i++) {       int calc = 0;       cin >> a >> num;       if (a ==  + )         insert(num);       else if (a ==  - )         del(num);       else {         ans.clear();         search(num);         for (int i = 0; i < ans.size(); i++) calc += (pow(2, 31 - i) * ans[i]);         cout << calc <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 1e9 + 7;   struct Dsu {     long long fa[N << 1], d[N << 1];     struct Tmp {       long long x, y, add;     };     stack<Tmp> s;     long long find(long long x) {       while (x != fa[x]) x = fa[x];       return x;     }     void init(long long n) {       while (!s.empty()) s.pop();       for (long long i = 1; i <= n; i++) fa[i] = i, d[i] = 0;     }     void merge(long long x, long long y) {       long long xx = find(x);       long long yy = find(y);       if (xx == yy) return;       if (d[xx] > d[yy]) swap(xx, yy);       s.push((Tmp){xx, yy, d[xx] == d[yy]});       fa[xx] = yy;       d[yy] += (d[xx] == d[yy]);     }     void ret(long long o) {       while (s.size() > o) {         Tmp x = s.top();         fa[x.x] = x.x;         d[x.y] -= x.add;         s.pop();       }     }   } t;   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar();     return x * f;   }   long long c[N];   map<pair<long long, long long>, vector<pair<long long, long long>>> mp;   int main() {     long long n = read(), m = read(), k = read();     for (long long i = 1; i <= n; i++) c[i] = read();     vector<pair<long long, long long>> e(m + 1);     t.init(2 * n);     for (long long i = 1; i <= m; i++) e[i].first = read(), e[i].second = read();     vector<long long> z(k + 1);     for (long long i = 1; i <= m; i++) {       long long u = e[i].first, v = e[i].second;       if (c[u] == c[v]) {         long long x = t.find(u);         long long y = t.find(v);         if (x == y) {           z[c[u]] = 1;         } else {           t.merge(u, v + n);           t.merge(u + n, v);         }       } else {         pair<long long, long long> tmp = {min(c[u], c[v]), max(c[v], c[u])};         mp[tmp].push_back({u, v});       }     }     long long res = 1ll * k * (k - 1) / 2;     long long gg = 0;     for (long long i = 1; i <= k; i++)       if (z[i] == 1) gg++;     res -= (gg) * (gg - 1) / 2 + gg * (k - gg);     for (auto now : mp) {       if (z[now.first.first] || z[now.first.second]) continue;       auto tmp = now.second;       long long o = t.s.size();       for (pair<long long, long long> qwq : tmp) {         long long u = qwq.first;         long long v = qwq.second;         long long x = t.find(u);         long long y = t.find(v);         if (x == y) {           res -= 1;           break;         } else {           t.merge(u, v + n);           t.merge(u + n, v);         }       }       t.ret(o);     }     cout << res << endl;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long int inf = 1e18;   const long long int ninf = -1e18;   const long long int mod = 1000000007;   const long long int MOD = 998244353;   template <typename T>   bool asc(pair<T, T> &a, pair<T, T> &b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first < b.first;   }   template <typename T>   bool desc(pair<T, T> &a, pair<T, T> &b) {     if (a.first == b.first) {       return a.second > b.second;     }     return a.first > b.first;   }   template <typename T>   T power(T a, T b) {     if (b == 0) return 1;     if (b == 1)       return a;     else {       T res = (power(a, b / 2));       if (b % 2) {         return (res * res * a);       } else {         return res * res;       }     }   }   template <typename T>   T power(T a, T b, T modulo) {     if (b == 0) return 1;     if (b == 1)       return a;     else {       T res = (power(a, b / 2, modulo) % modulo);       if (b % 2) {         return ((((res % modulo) * (res % modulo)) % modulo) * (a % modulo)) %                modulo;       } else {         return ((res % modulo) * (res % modulo)) % modulo;       }     }   }   template <typename T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   T lcm(T p, T q) {     return (p * q) / gcd<T>(p, q);   }   template <typename T>   void primefactorise(T n, vector<T> &vec) {     while (n % 2 == 0) {       vec.emplace_back(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         vec.emplace_back(i);         n = n / i;       }     }     if (n > 2) {       vec.emplace_back(n);     }   }   template <typename T>   void all_factor(T n, vector<T> &vec) {     for (auto i = 1; i <= sqrt(n); ++i) {       if (n % i == 0) {         vec.emplace_back(i);         if (i != (n / i)) {           vec.emplace_back(n / i);         }       }     }   }   long long mulmod(long long a, long long b, long long c) {     if (b == 0) {       return 0;     }     long long s = mulmod(a, b / 2, c);     if (b % 2 == 1) {       long long p = (a % c + 2 * (s % c)) % c;       return p;     } else {       long long p = (2 * (s % c)) % c;       return p;     }   }   long long mod_inv(long long a) {     return (power<long long>(a, mod - 2, mod)) % mod;   }   void factorial(long long n, vector<long long int> fact) {     fact.resize(n + 1, 1);     fact[0] = 1;     fact[1] = 1;     for (int i = 2; i <= n; ++i) {       fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;     }   }   int main() {     std::chrono::time_point<std::chrono::high_resolution_clock> start_timer,         end_timer;     start_timer = std::chrono::high_resolution_clock::now();     bool show_time = false;     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     if (n == 1) {       cout << ((1)) <<   n ;       ;     } else if (n == 2) {       cout << ((2)) <<   n ;       ;     } else if (n == 3) {       cout << ((6)) <<   n ;       ;     } else if (n % 2) {       cout << (((n * (n - 1) * (n - 2)))) <<   n ;       ;     } else       cout << (((max((((n - 3) * (n - 1) * (n - 2))) /                          (gcd<long long>(n - 1, n - 2) *                           gcd<long long>(n - 1, n - 3) *                           gcd<long long>(n - 3, n - 2)),                      (((n) * (n - 1) * (n - 3))) /                          (gcd<long long>(n - 1, n - 3) *                           gcd<long long>(n, n - 3) * gcd<long long>(n, n - 1))))))            <<   n ;     ;     end_timer = std::chrono::high_resolution_clock::now();     long long elapsed_time =         std::chrono::duration_cast<std::chrono::milliseconds>(end_timer -                                                               start_timer)             .count();     if (show_time) {       cout <<   nElapsed Time:   << elapsed_time <<  ms n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int readInt() {     int a;     scanf( %d , &a);     return a;   }   long long readLong() {     long long a;     scanf( %lld , &a);     return a;   }   void readString(char *s) { scanf(  %s , s); }   const int N = 100005;   char s[N];   vector<pair<int, int>> comp;   int f[26];   int dp[N];   void solve() {     int n = readInt();     int m = readInt();     readString(s + 1);     int last = 1;     for (int i = (1); i <= (n); ++i) {       if (s[i] != s[i + 1]) {         comp.emplace_back(s[i] -  a , i - last + 1);         last = i + 1;       }       f[s[i] -  a ]++;     }     long long ans = (int)(comp).size() * (n * 1ll * m - n);     dp[1] = 1;     for (int i = (2); i <= (n); ++i) {       if (s[i] != s[i - 1] && s[i] == s[i - 2])         dp[i] = 1 + dp[i - 1];       else if (s[i] != s[i - 1])         dp[i] = 2;       else         dp[i] = 1;       ans -= dp[i] - 1;     }     printf( %lld , ans);   }   int main() {     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, d;     long long t, v;     double prev = 0;     scanf( %I64d%I64d%I64d , &n, &a, &d);     for (int i = 1; i <= n; i++) {       scanf( %I64d%I64d , &t, &v);       double tt = sqrt((2 * d) / (a * 1.0));       if (tt * a > v) {         tt = v / (a * 1.0) + (d - v * v / (2 * a * 1.0)) / v;       }       tt += t;       if (tt < prev) tt = prev;       printf( %.8lf n , tt);       prev = tt;     }   }