#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long cp1[102];   long long cp2[102];   long long dp[102][10002];   long long comb[102][102];   bool mark[102][10002];   long long Calculate_Pow(long long x, long long y) {     long long val = 1;     for (long long i = 1, t = x; i <= y; i <<= 1, t = (t * t) % 1000000007)       if (y & i) val = (val * t) % 1000000007;     return val;   }   void Calculate_Combination() {     for (long long i = 0; i <= n; i++) comb[i][0] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= i; j++)         comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % 1000000007;   }   long long f(long long col, long long last) {     if (last < 0) return 0;     if (col == n && last) return 0;     if (col == n) return 1;     if (mark[col][last]) return dp[col][last];     mark[col][last] = true;     if (col >= m % n) {       for (long long i = 0; i <= n; i++)         dp[col][last] =             (dp[col][last] + cp1[i] * f(col + 1, last - i)) % 1000000007;     } else {       for (long long i = 0; i <= n; i++)         dp[col][last] =             (dp[col][last] + cp2[i] * f(col + 1, last - i)) % 1000000007;     }     return dp[col][last];   }   int main() {     scanf( %I64d%I64d%I64d , &n, &m, &k);     Calculate_Combination();     for (long long i = 0; i <= n; i++) {       cp1[i] = Calculate_Pow(comb[n][i], m / n);       cp2[i] = Calculate_Pow(comb[n][i], m / n + 1);     }     printf( %I64d n , f(0, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int mod = 1e9 + 7;   vector<int> G[maxn];   char s[maxn];   int vis[maxn];   map<string, int> mp;   long long a[maxn], n, L, R, t;   void solve1() {     L = 0, R = n;     for (int i = 0; i <= n - 2; i++) {       if (s[i] ==  < )         L++;       else {         for (int i = R - L; i <= R; i++) printf( %d  , i);         R = R - L - 1, L = 0;       }     }     for (int i = R - L; i <= R && i >= 1; i++) printf( %d  , i);     printf(  n );   }   void solve2() {     L = 0, R = 1;     for (int i = 0; i <= n - 2; i++) {       if (s[i] ==  > )         L++;       else {         for (int i = R + L; i >= R; i--) printf( %d  , i);         R = R + L + 1, L = 0;       }     }     for (int i = R + L; i >= R && i <= n; i--) printf( %d  , i);     printf(  n );   }   int main() {     cin >> t;     while (t--) {       scanf( %lld%s , &n, s);       solve1();       solve2();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   const int MAXN = 1e6 + 10;   int a[MAXN], ans[MAXN], n, K, sz;   vector<int> who[MAXN], vec[2][2];   void solve() {     string s;     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) a[i] = s[i] ==  L ;     set<int> avail[2];     for (int i = 0; i < n; i++) {       if (avail[a[i] ^ 1].empty()) {         avail[a[i]].insert(K);         who[K].push_back(i);         K++;       } else {         int x = *avail[a[i] ^ 1].begin();         avail[a[i] ^ 1].erase(x);         who[x].push_back(i);         avail[a[i]].insert(x);       }     }     for (int i = 0; i < K; i++) {       vec[a[who[i][0]]][a[who[i].back()]].push_back(i);     }     int cur = vec[0][0].size() < vec[1][1].size();     int last = vec[0][0].size() > vec[1][1].size();     while ((int)max(vec[0][0].size(), vec[1][1].size()) > 1) {       int i = vec[cur][cur].back();       vec[cur][cur].pop_back();       for (int x : who[i]) ans[sz++] = x;       cur ^= 1;     }   up:     if (vec[0][0].size() && vec[1][1].size()) {       if (last) {         for (int i : vec[1][1])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][1])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[1][0])           for (int x : who[i]) ans[sz++] = x;       } else {         for (int i : vec[0][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[1][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[1][1])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][1])           for (int x : who[i]) ans[sz++] = x;       }     } else {       if (vec[0][0].size()) {         for (int i : vec[0][1])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[1][0])           for (int x : who[i]) ans[sz++] = x;       } else if (vec[1][1].size()) {         for (int i : vec[1][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[1][1])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][1])           for (int x : who[i]) ans[sz++] = x;       } else if (!!vec[0][1].size() ^ !!vec[1][0].size()) {         for (int i : vec[1][0])           for (int x : who[i]) ans[sz++] = x;         for (int i : vec[0][1])           for (int x : who[i]) ans[sz++] = x;       } else {         int i = vec[0][1].back();         vec[0][1].pop_back();         int j = vec[1][0].back();         for (int k = 1; k < (int)who[i].size(); k++) who[j].push_back(who[i][k]);         while ((int)who[i].size() > 1) who[i].pop_back();         vec[0][0].push_back(i);         goto up;       }     }     cout << K - 1 <<   n ;     for (int i = 0; i < n; i++) cout << ans[i] + 1 <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a[2002];   int b[2002];   vector<int> ans[4];   void Work() {     int l;     int maxT = 0;     int specialNum = -1;     for (int i = 0; i < n; i++) {       cin >> l;       a[l].push_back(i + 1);       if (l > maxT) maxT = l;       b[l]++;       if (b[l] >= 3) specialNum = l;     }     int check = 0;     for (int i = 0; i <= maxT; i++) {       if (b[i] >= 2) check++;       if (b[i] >= 3) check++;       if (check == 2) break;     }     if (check < 2) {       cout <<  NO ;       return;     }     for (int i = 1; i <= maxT; i++) {       for (int j = 0; j < a[i].size(); j++) {         if (a[i][j] > 0) {           ans[1].push_back(a[i][j]);         }       }     }     for (int i = 1; i <= maxT; i++) {       for (int j = a[i].size() - 1; j >= 0; j--) {         if (a[i][j] > 0) {           ans[2].push_back(a[i][j]);         }       }     }     bool tt = false;     if (specialNum == -1)       for (int i = 1; i <= maxT; i++) {         if (b[i] >= 2 && !tt) {           for (int j = a[i].size() - 1; j >= 0; j--) {             if (a[i][j] > 0) {               ans[3].push_back(a[i][j]);               tt = true;             }           }         } else {           for (int j = 0; j < a[i].size(); j++) {             if (a[i][j] > 0) {               ans[3].push_back(a[i][j]);             }           }         }       }     else {       for (int i = 1; i <= specialNum; i++) {         if (i != specialNum)           for (int j = a[i].size() - 1; j >= 0; j--) {             if (a[i][j] > 0) {               ans[3].push_back(a[i][j]);               tt = true;             }           }       }       for (int i = 0; i < a[specialNum].size() / 2; i++) {         if (a[specialNum][i] > 0) {           ans[3].push_back(a[specialNum][i]);         }       }       for (int i = a[specialNum].size() - 1; i >= a[specialNum].size() / 2; i--) {         if (a[specialNum][i] > 0) {           ans[3].push_back(a[specialNum][i]);         }       }       for (int i = specialNum + 1; i <= maxT; i++) {         if (i != specialNum)           for (int j = a[i].size() - 1; j >= 0; j--) {             if (a[i][j] > 0) {               ans[3].push_back(a[i][j]);               tt = true;             }           }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= 3; i++) {       for (int j = 0; j < ans[i].size(); j++) {         cout << ans[i][j];         if (j < ans[i].size() - 1) cout <<    ;       }       if (i != 3) cout << endl;     }   }   int main() {     cin >> n;     Work();   }


#include <bits/stdc++.h>   int main() {     uint64_t a, b, x;     std::cin >> a >> b;     a < b | a - b & 1         ? std::cout << -1         : (x = a - b >> 1,            x ^ a - x ^ b ? std::cout << -1 : std::cout << x <<     << a - x);   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int w = 1, c = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) w = -1;     for (; isdigit(ch); ch = getchar()) c = (c << 3) + (c << 1) + (ch ^ 48);     return w * c;   }   const int mod = 998244353, M = 1e6 + 10;   int n;   long long fac[M], inv[M];   long long C(int x, int y) {     if (y > x || y < 0) return 0;     return fac[x] * inv[y] % mod * inv[x - y] % mod;   }   char s[M];   long long fast(long long x, long long p) {     long long ret = 1;     for (; p; p >>= 1, x = x * x % mod)       if (p & 1) ret = ret * x % mod;     return ret;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;     inv[n] = fast(fac[n], mod - 2);     for (int i = n; i >= 1; --i) inv[i - 1] = inv[i] * i % mod;     int l = 0, x = 0, y = 0, r = 0;     for (int i = 1; i <= n; ++i) {       if (s[i] ==  ( ) l++;       if (s[i] ==  ? ) x++;     }     long long ans = 0;     for (int i = n; i >= 1; --i) {       if (s[i] ==  ( ) l--;       if (s[i] ==  ) ) r++;       if (s[i] ==  ? ) x--, y++;       ans =           (ans + C(x + y, y + r - l) * l + C(x + y - 1, y + r - l - 1) * x) % mod;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   int main(void) {     int c, d, n, m, k, i, j, ans = 10000;     scanf( %d %d %d %d %d , &c, &d, &n, &m, &k);     for (i = 0; i <= 10000; i++)       for (j = 0; j <= 10000; j++)         if (i * n + j >= n * m - k) ans = min(ans, i * c + j * d);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   const int lim = 2001;   int A[lim];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &A[i]);     long long int total = 0ll;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (A[i] > A[j]) total = total + 1ll;       }     }     int q;     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d %d , &a, &b);       total = total + ((b - a + 1) * 1ll * (b - a)) / 2ll;       if (total % 2 == 1ll)         printf( odd n );       else         printf( even n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[105][105];   char s[105][105];   int n, m;   long long k;   void color(int x, int y, char c) {     while (x < n && y >= 0) {       s[x][y] = c;       x++;       y--;     }   }   vector<pair<pair<int, int>, pair<int, int> > > v;   vector<int> vals;   long long mem[305][305];   int vis[305][305];   int id;   long long add(long long x, long long y) {     if (x < 0 || y < 0) return -1;     long long z = x + y;     if (z >= k) return -1;     return z;   }   long long solve(int ind, int r) {     if (r < 0) return 0;     if (ind >= int(vals.size())) return r == 0;     if (vis[ind][r] == id) return mem[ind][r];     vis[ind][r] = id;     long long ans = 0;     if (vals[ind] != 1) ans = add(ans, solve(ind + 1, r + 1));     if (vals[ind] != 0) ans = add(ans, solve(ind + 1, r - 1));     return mem[ind][r] = ans;   }   void gen(int ind) {     if (ind >= int(vals.size())) return;     vals[v[ind].first.second] = 0;     id++;     long long tmp = solve(0, 0);     if (tmp == -1) {       color(v[ind].second.first, v[ind].second.second,  ( );       gen(ind + 1);     } else {       vals[v[ind].first.second] = 1;       k -= tmp;       color(v[ind].second.first, v[ind].second.second,  ) );       gen(ind + 1);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     cin >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> p[i][j];     for (int j = 0; j < m; j++) {       int x = 0, y = j, pr = n * m + 1;       while (x < n && y >= 0) {         pr = min(pr, p[x][y]);         x++;         y--;       }       v.push_back(make_pair(make_pair(pr, v.size()), make_pair(0, j)));       vals.push_back(-1);     }     for (int i = 1; i < n; i++) {       int x = i, y = m - 1, pr = n * m + 1;       while (x < n && y >= 0) {         pr = min(pr, p[x][y]);         x++;         y--;       }       v.push_back(make_pair(make_pair(pr, v.size()), make_pair(i, m - 1)));       vals.push_back(-1);     }     sort(v.begin(), v.end());     gen(0);     for (int i = 0; i < n; i++) cout << s[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   long long powmod(long long a, long long b, long long MOD) {     long long ans = 1;     while (b) {       if (b % 2) ans = ans * a % MOD;       a = a * a % MOD;       b /= 2;     }     return ans;   }   int main() {     int t;     int n, x, y, d;     ios::sync_with_stdio(false);     string a;     cin >> n;     cin >> a;     int l = a.size();     vector<int> v;     v.push_back(-1);     int fa = n + 12, fb = -23;     for (int i = 0; i < l; i++) {       if (a[i] ==  S ) v.push_back(i);       if (fa == n + 12 && a[i] ==  G ) fa = i;       if (a[i] ==  G ) fb = i;     }     v.push_back(n);     if (v.size() == 2) {       cout << n << endl;       return 0;     } else {       int ma = 0;       for (int i = 1; i < v.size() - 1; i++) {         int xa = v[i + 1] - v[i - 1] - 1;         if (v[i + 1] > fb && v[i - 1] < fa) xa--;         if (ma < xa) ma = xa;       }       cout << ma << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-6;   const int maxn = 1 << 17;   int a[maxn];   void merge(int l, int r, int from, int to, int& res) {     if (res <= 0 || l + 1 == r) {       for (int i = l, j = from; i <= r; i++, j++) a[i] = j;       return;     }     res -= 2;     int m = (l + r) >> 1;     int mid = (from + to + 1) >> 1;     merge(l, m, mid, to, res);     merge(m, r, from, mid, res);   }   int main() {     int n, k;     while (cin >> n >> k) {       k--;       merge(0, n, 0, n, k);       if (k)         cout << -1 << endl;       else {         for (int i = 0; i < n; i++) {           if (i) cout <<    ;           cout << a[i] + 1;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e4 + 9;   long long a[maxn];   long long n;   void solve() {     cin >> n;     long long sum = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % n != 0) {       cout <<  -1 n ;       return;     }     sum /= n;     long long j = -1;     for (long long i = n - 1; i >= 1; i--) {       if (a[i] >= i + 1) {         j = i;         break;       }     }     vector<pair<pair<long long, long long>, long long> > ans;     if (j != -1) {       ans.emplace_back(make_pair(j, 0), 1);       a[j] -= j + 1;       a[0] += j + 1;       for (long long e = j; e >= 1; e--) {         if (a[e] % (e + 1) != 0) {           long long x = (e + 1) - a[e] % (e + 1);           ans.emplace_back(make_pair(0, e), x);           a[0] -= x;           a[e] += x;         }         ans.emplace_back(make_pair(e, 0), a[e] / (e + 1));         a[0] += a[e];         a[e] = 0;       }     } else {       j = 0;     }     vector<pair<long long, long long> > kek;     for (long long e = j + 1; e < n; e++) {       kek.emplace_back((e + 1) - a[e], e);     }     sort(kek.begin(), kek.end());     for (auto x : kek) {       if (a[0] >= x.first) {         ans.emplace_back(make_pair(0, x.second), x.first);         ans.emplace_back(make_pair(x.second, 0), 1);         a[0] += a[x.second];         a[x.second] = 0;       } else {         cout <<  -1 n ;         return;       }     }     for (long long i = 1; i < n; i++) {       ans.emplace_back(make_pair(0, i), sum);     }     if ((long long)ans.size() > 3 * n) {       cout <<  -1 n ;       return;     }     cout << ans.size() <<   n ;     for (auto x : ans)       cout << x.first.first + 1 <<     << x.first.second + 1 <<     << x.second            <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int k[n][n];     for (int j = 0; j < n; j++)       for (int i = 0; i < n; i++) k[i][j] = (i)*n + j + 1;     for (int i = 0; i < n; i += 2) reverse(k[i], k[i] + n);     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < n; i++) cout << k[i][j] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     long long t = 1;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       multiset<long long> s;       for (long long i = 0; i < n; i++) cin >> b[i], s.insert(b[i]);       vector<long long> c(n);       for (long long i = 0; i < n; i++) {         multiset<long long>::iterator it = s.begin();         long long ans = (a[i] + *it) % n, num = *it;         it = s.lower_bound(n - a[i]);         if (it != s.end() && (a[i] + *it) % n < ans) {           ans = (a[i] + *it) % n;           num = *it;         }         c[i] = ans;         s.erase(s.find(num));       }       for (long long i = 0; i < n; i++) cout << c[i] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int ans = 9999;   string s, t;   int main() {     cin >> s >> t;     for (int i = 0; i < t.size(); i++) s =  .  + s +  . ;     for (int i = 0; i + t.size() - 1 < s.size(); i++) {       int temp = 0;       for (int j = 0; j < t.size(); j++) temp += (s[i + j] != t[j]);       if (ans > temp) ans = temp;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200005];   vector<long long int> g[200005];   vector<long long int> c[200005];   multiset<long long int> st[200005];   long long int idx[200005], toAdd[200005], ans[200005];   void mergeTree(long long int id1, long long int id2) {     multiset<long long int>::iterator it;     long long int x;     for (it = st[id2].begin(); it != st[id2].end(); it++) {       x = *it + toAdd[id2] - toAdd[id1];       st[id1].insert(x);     }     return;   }   void dfs(long long int u) {     idx[u] = u;     long long int i, j, k, mx;     mx = st[idx[u]].size();     long long int id = idx[u];     for (i = 0; i < g[u].size(); i++) {       long long int v = g[u][i];       dfs(v);       if (st[idx[v]].size() > mx) {         mx = st[idx[v]].size();         id = idx[v];       }       toAdd[idx[v]] -= c[u][i];     }     idx[u] = id;     for (i = 0; i < g[u].size(); i++) {       long long int v = g[u][i];       if (id != idx[v]) mergeTree(id, idx[v]);       st[id].insert((a[v] - c[u][i]) - toAdd[id]);     }     multiset<long long int>::iterator it;     while (!st[id].empty()) {       it = st[id].begin();       if ((*it + toAdd[id]) < 0)         st[id].erase(it);       else         break;     }     ans[u] = (long long int)st[id].size();     return;   }   int main() {     long long int i, j, k, l, m, n;     cin >> n;     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (i = 2; i <= n; i++) {       scanf( %lld %lld , &k, &l);       g[k].push_back(i);       c[k].push_back(l);     }     memset(toAdd, 0, sizeof(toAdd));     dfs(1);     for (i = 1; i <= n; i++) {       printf( %lld , ans[i]);       if (i < n)         printf(   );       else         printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mas[100500];   int main() {     int n, k, p = 1, t;     bool cur = false;     char q;     string s =   , s1;     cin >> n >> k;     mas[1] = 1;     for (int i = 2; i <= n; i++) {       if (p < k) {         if (!cur)           mas[i] = n - mas[i - 1] + 1;         else           mas[i] = mas[i - 2] + 1;         if (!cur)           cur = true;         else           cur = false;         p++;       } else {         if (!cur) {           mas[i] = mas[i - 1] + 1;         } else {           mas[i] = mas[i - 1] - 1;         }       }     }     for (int i = 1; i <= n; i++) {       s1 =   ;       while (mas[i] > 0) {         q = mas[i] % 10 +  0 ;         mas[i] /= 10;         s1 = q + s1;       }       s += s1 +    ;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gr[1000005];   int was[1000005];   long long GetPow(long long val, int deg) {     long long ret = 1;     for (int i = 0; i < deg; ++i) {       ret *= val;     }     return ret;   }   long long arr[100000];   int main() {     long long sq4 = 2, sq2 = 2, val4 = 16, val2 = 4;     int least = 0;     for (int i = 4; i < 1000005; ++i) {       if (val2 == i) {         was[gr[sq2]]++;         ++sq2;         val2 = GetPow(sq2, 2);         while (was[least]) {           ++least;         }       }       gr[i] = least;       if (val4 == i) {         was[gr[sq4]]--;         if (!was[gr[sq4]] && gr[sq4] < least) {           least = gr[sq4];         }         ++sq4;         val4 = GetPow(sq4, 4);       }     }     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr, arr + n);     sq2 = 1;     sq4 = 1;     val2 = 1;     val4 = 1;     long long xr = 0, cur = 0;     memset(was, 0, sizeof was);     least = 0;     for (int i = 0; i < n; ++i) {       if (arr[i] == 1) {         continue;       }       while (val2 <= arr[i]) {         was[gr[sq2]]++;         ++sq2;         val2 = GetPow(sq2, 2);       }       while (val4 < arr[i]) {         was[gr[sq4]]--;         if (!was[gr[sq4]] && least > gr[sq4]) {           least = gr[sq4];         }         ++sq4;         val4 = GetPow(sq4, 4);       }       while (was[least]) {         ++least;       }       xr ^= least;     }     if (xr) {       puts( Furlo );     } else {       puts( Rublo );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long m, n;   void solve() {     cin >> n >> m;     bool visited[n + 5];     memset(visited, 0, sizeof(visited));     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       visited[b] = 1;     }     long long node = -1;     for (long long i = 1; i < n + 1; i++)       if (!visited[i]) {         node = i;         break;       }     for (long long i = 1; i < n + 1; i++) {       if (i == node) continue;       cout << node <<     << i <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long solve(long long n, string str1, string str2) {     long long t1 = 0, t2 = 0;     for (long long i = 0; i < n; i++) {       if (str1[i] != str2[i]) {         if (str1[i] ==  1 )           t1++;         else           t2++;       }     }     if (t1 != t2)       return -1;     else       return 2 * t1;   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       string str1, str2;       cin >> n;       cin >> str1 >> str2;       long long a1 = solve(n, str1, str2);       long long ind = -1;       for (long long i = 0; i < n; i++) {         if (str1[i] ==  1  && str2[i] ==  1 ) {           ind = i;           break;         }       }       long long a2 = -1;       string temp = str1;       if (ind != -1) {         for (long long i = 0; i < n; i++) {           if (str1[i] ==  1  && i != ind)             str1[i] =  0 ;           else if (str1[i] ==  0 )             str1[i] =  1 ;         }         a2 = solve(n, str1, str2);       }       long long a3 = -1;       str1 = temp;       long long ind2 = -1;       for (long long i = 0; i < n; i++) {         if (str1[i] ==  1  && str2[i] ==  0 ) {           ind2 = i;           break;         }       }       if (ind2 != -1) {         for (long long i = 0; i < n; i++) {           if (str1[i] ==  1  && i != ind2)             str1[i] =  0 ;           else if (str1[i] ==  0 )             str1[i] =  1 ;         }         a3 = solve(n, str1, str2);       }       if (a1 == -1 && a2 == -1 && a3 == -1) {         cout <<  -1  << endl;       } else {         if (a1 == -1 && a2 == -1)           cout << (a3 + 1) << endl;         else if (a1 == -1 && a3 == -1)           cout << (a2 + 1) << endl;         else if (a2 == -1 && a3 == -1)           cout << a1 << endl;         else if (a1 == -1)           cout << min(a2 + 1, a3 + 1) << endl;         else if (a2 == -1)           cout << min(a1, a3 + 1) << endl;         else if (a3 == -1)           cout << min(a1, a2 + 1) << endl;         else {           long long b = min(a2 + 1, a3 + 1);           long long ans = min(b, a1);           cout << ans << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1);   vector<int> adj[100005];   bool vis[100005];   map<pair<int, int>, long long> edge;   map<pair<int, int>, pair<long long, int>> weight;   long long mod = 1e9 + 7;   int n, k;   long long dfs(int node) {     vis[node] = 1;     long long ans = 1;     for (auto v : adj[node]) {       if (!vis[v]) {         long long a = dfs(v);         edge[{v, node}] = a;         edge[{node, v}] = a;         ans += a;       }     }     if (ans > 1) ans--;     return ans;   }   void clc() {     for (int i = 0; i <= n; i++) {       adj[i].clear();       vis[i] = 0;     }     edge.clear();     weight.clear();   }   void test_case() {     long long sum = 0, ans = 1e8, s;     cin >> n >> s;     pair<int, int> arr[n];     vector<long long> v1, v2;     v1.push_back(0), v2.push_back(0);     for (int i = 0; i < n - 1; i++) {       int x, y, c, w;       cin >> x >> y >> c >> w;       adj[x].push_back(y), adj[y].push_back(x);       arr[i] = {x, y};       weight[{x, y}] = {c, w}, weight[{y, x}] = {c, w};     }     dfs(1);     for (int i = 0; i < n; i++) {       long long x = edge[{arr[i].first, arr[i].second}],                 y = weight[{arr[i].first, arr[i].second}].first;       sum += x * y;       while (y) {         if (weight[{arr[i].first, arr[i].second}].second == 1)           v1.push_back(x * y - x * (y / 2));         else           v2.push_back(x * y - x * (y / 2));         y /= 2;       }     }     sort(v1.begin() + 1, v1.end());     sort(v2.begin() + 1, v2.end());     reverse(v1.begin() + 1, v1.end());     reverse(v2.begin() + 1, v2.end());     for (int i = 1; i < v1.size(); i++) v1[i] += v1[i - 1];     for (int i = 1; i < v2.size(); i++) v2[i] += v2[i - 1];     for (int i = 0; i < v2.size(); i++) {       long long pos =           lower_bound(v1.begin(), v1.end(), sum - s - v2[i]) - v1.begin();       if (pos == v1.size()) continue;       ans = min(ans, pos + 2 * i);     }     cout << ans <<   n ;     clc();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long x, long long y) { return (x < y) ? x : y; }   long long max(long long x, long long y) { return (x > y) ? x : y; }   const int N = 1000009;   const int E = 1000000;   int x, y, n, m, e, i, u, w, mx, z, sum, l, r, best, cnt, g, j, k, t;   int a[N], flag[N], mark[N];   string s;   vector<int> pos, ans;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       flag[a[i]] = true;     }     for (int i = 1; i <= E / 2; i++)       if (!flag[i] && !flag[E - i + 1]) pos.push_back(i);     for (int i = 0; i < n; i++) {       if (mark[a[i]]) continue;       mark[a[i]] = true;       k = a[i];       if (!flag[E - k + 1])         ans.push_back(E - k + 1);       else {         w = pos[cnt];         cnt++;         ans.push_back(w);         ans.push_back(E - w + 1);         mark[E - k + 1] = true;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ma = -1, mi = 1000000000000000;   inline long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   inline long long int lcm(long long int a, long long int b, long long int MOD) {     return a / gcd(a, b) * b % MOD;   }   long long int power(long long int x, unsigned int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, a[100009] = {0}, b[100009] = {0}, c = 0, d = 0;     string n, m;     cin >> n >> m;     if (n ==  monday ) {       if (m ==  monday  || m ==  wednesday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  tuesday ) {       if (m ==  tuesday  || m ==  friday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  wednesday ) {       if (m ==  friday  || m ==  wednesday  || m ==  saturday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  thursday ) {       if (m ==  saturday  || m ==  sunday  || m ==  thursday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  friday ) {       if (m ==  friday  || m ==  sunday  || m ==  monday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  saturday ) {       if (m ==  saturday  || m ==  monday  || m ==  tuesday ) {         cout <<  YES  << endl;         return 0;       }     }     if (n ==  sunday ) {       if (m ==  sunday  || m ==  wednesday  || m ==  tuesday ) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   void rr(vector<vector<long long>> &m, long long r, long long nr, long long nc) {     long long t = m[r - 1][nc - 1];     for (long long i = nc - 2; i >= 0; i--) m[r - 1][i + 1] = m[r - 1][i];     m[r - 1][0] = t;     return;   }   void rc(vector<vector<long long>> &m, long long c, long long nr, long long nc) {     long long t = m[nr - 1][c - 1];     for (long long i = nr - 2; i >= 0; i--) m[i + 1][c - 1] = m[i][c - 1];     m[0][c - 1] = t;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, q, t;     cin >> n >> m >> q;     vector<vector<long long>> mat(n, vector<long long>(m, 0));     vector<vector<long long>> op;     for (long long i = 0; i < q; i++) {       cin >> t;       if (t == 1 || t == 2) {         long long roc;         cin >> roc;         op.push_back({t, roc});       } else {         long long r, c, x;         cin >> r >> c >> x;         op.push_back({t, r, c, x});       }     }     bool f3 = false;     for (long long i = op.size() - 1; i >= 0; i--) {       if (!f3) {         if (op[i][0] == 3) {           f3 = true;           mat[op[i][1] - 1][op[i][2] - 1] = op[i][3];         }       } else {         if (op[i][0] == 1) {           rr(mat, op[i][1], n, m);         } else if (op[i][0] == 2) {           rc(mat, op[i][1], n, m);         } else {           mat[op[i][1] - 1][op[i][2] - 1] = op[i][3];         }       }     }     for (auto i : mat) {       for (auto j : i) cout << j <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10004;   long long a[N], b[N], c, sa = 0, mb = 0, M;   int n;   bool ok1(long long x) {     long long s = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > 0 && x / b[i] > c / a[i]) return 0;       s += a[i] * x / b[i] + 1;       if (s >= c) return 0;     }     return 1;   }   bool ok2(long long x) {     long long s = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > 0 && x / b[i] > c / a[i]) return 1;       s += a[i] * x / b[i] + 1;       if (s > c) return 1;     }     return 0;   }   int main() {     scanf( %d %lld , &n, &c);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a[i], &b[i]);       sa += a[i];       mb = max(mb, b[i]);     }     long long u, v;     M = c * mb;     if (sa == 0) return puts(n == c ?  -1  :  0 ), 0;     long long l = 0, r = M;     while (l < r) {       long long mid = (l + r + 1) / 2;       if (ok1(mid))         l = mid;       else         r = mid - 1;     }     u = l;     l = 0, r = M;     while (l < r) {       long long mid = (l + r) / 2;       if (ok2(mid))         r = mid;       else         l = mid + 1;     }     v = r;     printf( %lld n , max(v - u - 1, 0ll));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   long long ara[N];   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long x;       cin >> x;       ++ara[x];     }     vector<long long> v;     for (long long i = 1; i <= 100; ++i) {       if (ara[i] != 0) v.push_back(ara[i]);     }     long long mx = 0;     for (long long i = 1; i <= 100; ++i) {       long long s = 0;       for (long long j = 0; j < v.size(); ++j) {         s += v[j] / i;       }       if (s >= n) mx = max(mx, i);     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int main() {     long long a[maxn], b[maxn];     int n, m;     while (cin >> n >> m) {       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       for (int i = 1; i <= m; ++i) {         cin >> b[i];       }       sort(a + 1, a + n + 1);       sort(b + 1, b + m + 1);       long long ans1 = a[1] * b[1], ans2 = a[n] * b[m], ans3 = a[1] * b[m],                 ans4 = a[n] * b[1];       long long maxx = max(ans1, max(ans2, max(ans3, ans4)));       if (maxx == ans1)         cout << max(a[2] * b[1], max(ans2, max(a[2] * b[m], ans4))) << endl;       else if (maxx == ans2)         cout << max(a[n - 1] * b[m], max(ans1, max(ans3, a[n - 1] * b[1])))              << endl;       else if (maxx == ans3)         cout << max(a[2] * b[1], max(ans2, max(a[2] * b[m], ans4))) << endl;       else         cout << max(ans1, max(a[n - 1] * b[m], max(ans3, a[n - 1] * b[1])))              << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = true;   long long n, m, a, b;   int main(int argc, char* argv[]) {     cin >> n >> m >> a >> b;     long long r = n % m;     cout << min(r * b, (m - r) * a);     while (clock() <= 300) {     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct seq {     int num;     char color;   };   int main() {     string s;     cin >> s;     int i = 1, N = 0, j;     seq temp;     vector<seq> arr;     temp.num = 1;     temp.color = s[0];     while (s[i] !=   0 ) {       if (s[i] == temp.color) {         temp.num++;       } else {         arr.push_back(temp);         temp.num = 1;         temp.color = s[i];         N++;       }       i++;     }     arr.push_back(temp);     N++;     if (N % 2 == 0) {       cout << 0 << endl;       return 0;     }     i = 0;     j = N - 1;     while (i < j) {       if (arr[i].color == arr[j].color) {         if (arr[i].num + arr[j].num >= 3) {           i++;           j--;         } else {           break;         }       } else {         break;       }     }     if (i == j) {       if (arr[i].num + 1 >= 3) {         cout << arr[i].num + 1 << endl;       } else {         cout << 0 << endl;       }     } else {       cout << 0 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     char tramp;     cin >> tramp;     string rank =  6789TJQKA ;     char c1_s, c1_r;     cin >> c1_r >> c1_s;     char c2_s, c2_r;     cin >> c2_r >> c2_s;     if (c1_s == tramp && c2_s != tramp) {       cout <<  YES  << endl;       return 0;     }     if (c1_s == c2_s && rank.find(c1_r) > rank.find(c2_r)) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int true_mod(int A, int N) {     A %= N;     if (A < 0) A += N;     return A;   }   const long long MOD = 1000LL * 1000LL * 1000LL + 7LL;   const int MX = 109;   struct matrix {     long long A[MX][MX];   };   int x;   void output(const matrix& A) {     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) cout << A.A[i][j] <<    ;       cout << endl;     }   }   matrix operator*(const matrix& A, const matrix& B) {     matrix R;     for (int i = 0; i < x; i++) {       for (int k = 0; k < x; k++) {         long long t = 0;         for (int j = 0; j < x; j++) t += A.A[i][j] * B.A[j][k] % MOD;         R.A[i][k] = t % MOD;       }     }     return R;   }   matrix unity() {     matrix R;     for (int i = 0; i < x; i++)       for (int j = 0; j < x; j++) R.A[i][j] = (i == j ? 1 : 0);     return R;   }   matrix power(const matrix& A, int N) {     matrix R = unity(), A_pow = A;     while (N != 0) {       if (N % 2 == 1) R = R * A_pow;       A_pow = A_pow * A_pow;       N /= 2;     }     return R;   }   int n, b, k;   const long long B = 10;   int cnt_D[MX] = {0};   matrix get_A() {     matrix R;     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) {         int smth = true_mod(j - 10 * i, x);         R.A[i][j] = cnt_D[smth];       }     }     return R;   }   int main() {     cin >> n >> b >> k >> x;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       cnt_D[a % x]++;     }     matrix A = get_A();     matrix A_pow = power(A, b);     cout << A_pow.A[0][k];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m;   char arr[2004][2004];   pair<int, int> v[2004][2004];   long long int dist[8000003];   const long long int oo = 1000000007;   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   int get_node(int x, int y) { return x * m + y; }   void bfs(int r, int c) {     for (int i = 0; i < n * m; i++) dist[i] = oo;     dist[get_node(r, c)] = 0;     deque<pair<int, int>> dq;     dq.push_back({r, c});     v[r][c] = {0, 0};     while (!dq.empty()) {       int x = dq[0].first;       int y = dq[0].second;       dq.pop_front();       for (int i = 0; i < 4; i++) {         int xx = x + dx[i];         int yy = y + dy[i];         if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;         if (arr[xx][yy] ==  * ) continue;         int flag = 0;         if (yy < y) flag = 1;         int node = get_node(xx, yy);         int u = get_node(x, y);         if (dist[node] > dist[u] + flag) {           dist[node] = dist[u] + flag;           v[xx][yy] = v[x][y];           if (i == 2) v[xx][yy].second++;           if (i == 3) v[xx][yy].first++;           if (flag)             dq.push_back({xx, yy});           else             dq.push_front({xx, yy});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     long long int r, c;     cin >> r >> c;     r--;     c--;     long long int le, ri;     cin >> le >> ri;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> arr[i][j], v[i][j] = {oo, oo};     bfs(r, c);     long long int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] ==  * ) continue;         if (v[i][j].first <= le && v[i][j].second <= ri) ans++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxmn = 505;   long long a[maxmn][maxmn];   long long luu1[maxmn][maxmn];   bool k[1000005];   long long maxx = 1e9;   void readquick() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     readquick();     vector<long long> luu;     memset(k, true, sizeof k);     for (int i = 2; i <= sqrt(1000000); i++) {       if (k[i] == true) {         for (int j = i * i; j <= 1000000; j += i) {           k[j] = false;         }       }     }     for (int i = 2; i <= 1000000; i++) {       if (k[i] == true) luu.push_back(i);     }     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         int w = lower_bound(luu.begin(), luu.end(), a[i][j]) - luu.begin();         luu1[i][j] = luu[w] - a[i][j];       }     }     for (int i = 1; i <= n; i++) {       long long tong = 0;       for (int j = 1; j <= m; j++) {         tong += luu1[i][j];       }       if (tong >= 0) {         maxx = min(maxx, tong);       }     }     for (int i = 1; i <= m; i++) {       long long tong = 0;       for (int j = 1; j <= n; j++) {         tong += luu1[j][i];       }       if (tong >= 0) {         maxx = min(maxx, tong);       }     }     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<vector<int> > v(N);   int col[N];   int par[N];   int n;   int in[N], out[N];   int timer;   bool all_same[N];   bool can[N];   int euler[2 * N];   int tree[8 * N];   int answer = -1;   void dfs(int node) {     all_same[node] = true;     can[node] = true;     timer++;     in[node] = timer;     euler[timer] = col[node];     for (int to : v[node]) {       if (to == par[node]) continue;       par[to] = node;       dfs(to);       can[node] &= (all_same[to]);       all_same[node] &= (all_same[to] and (col[node] == col[to]));     }     out[node] = timer;   }   void build(int id, int lo, int hi) {     if (lo == hi) {       tree[id] = euler[lo];       return;     }     int mid = (lo + hi) >> 1;     build(2 * id, lo, mid);     build(2 * id + 1, mid + 1, hi);     if (tree[2 * id + 1] == tree[2 * id]) tree[id] = tree[2 * id];   }   int query(int id, int lo, int hi, int l, int r) {     if (r < l) return -2;     if (l > hi or r < lo) return -2;     if (l <= lo and r >= hi) {       if (tree[id] == 0) return -1;       return (tree[id]);     }     int mid = (lo + hi) >> 1;     int tmp1 = query(2 * id, lo, mid, l, r);     int tmp2 = query(2 * id + 1, mid + 1, hi, l, r);     if (tmp1 == tmp2) {       return tmp1;     }     if (tmp1 == -2) {       return tmp2;     }     if (tmp2 == -2) {       return tmp1;     }     return -1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].emplace_back(y);       v[y].emplace_back(x);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &col[i]);     }     dfs(1);     build(1, 1, timer);     for (int i = 1; i <= n; i++) {       if (can[i]) {         int node = i;         int tmp1 = query(1, 1, timer, 1, in[node] - 1);         int tmp2 = query(1, 1, timer, out[node] + 1, timer);         if ((tmp1 == tmp2 and tmp1 != -1) or (tmp1 == -2 and tmp2 != -1) or             (tmp1 != -1 and tmp2 == -2)) {           puts( YES );           printf( %d n , i);           return 0;         }       }     }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   clock_t time_p = clock();   void ktj() {     time_p = clock() - time_p;     cerr <<  Time elapsed :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, k;     cin >> n;     vector<long long> a(n);     for (i = 0; i < n; i++) {       cin >> a[i];     }     if (n % 2) {       for (i = 0; i < n; i++) {         if (a[i] >= 0) {           a[i] = -a[i] - 1;         }       }       auto mn = min_element(a.begin(), a.end());       a[mn - a.begin()] = -a[mn - a.begin()] - 1;       for (i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;     } else {       for (i = 0; i < n; i++) {         if (a[i] >= 0)           cout << -a[i] - 1 <<    ;         else           cout << a[i] <<    ;       }       cout <<   n ;     }     ktj();   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, x, y, f[1000001];   void make(int l, int r) {     for (int i = l; i < r; i++) f[i] = i + 1;     f[r] = l;   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (x = 0; x * a <= n; x++)       if ((n - x * a) % b == 0) {         y = (n - x * a) / b;         break;       }     if (a * x + b * y != n) return printf( -1 n ), 0;     for (int i = 1; i <= x; i++) make(i * a - a + 1, i * a);     for (int i = 1; i <= y; i++) make(a * x + i * b - b + 1, a * x + i * b);     for (int i = 1; i <= n; i++) printf( %d%c , f[i], i < n ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx[] = {0, 2, 3, 1};   long long get_base(long long n) {     long long b = 4;     for (;;) {       if (b > n) return b / 4;       b <<= 2;     }     return 0;   }   long long func1(long long n) {     long long b = get_base(n);     return (n - b) / 3 + b;   }   long long func2(long long n) {     long long b = get_base(n);     long long m = (n - b - 1) / 3;     long long bb = b;     vector<int> v;     while (bb >= 4) {       v.push_back(m % 4);       m /= 4;       bb /= 4;     }     long long r = b + b;     bb = b / 4;     for (int i = v.size() - 1; i >= 0; i--) {       r += bb * mx[v[i]];       bb /= 4;     }     if (n == 2) return 2;     return r;   }   int main() {     int t;     long long n, ans;     ios::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       if (n % 3 == 0)         ans = func1(n - 2) ^ func2(n - 1);       else if (n % 3 == 1)         ans = func1(n);       else         ans = func2(n);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3 * 1e5 + 10, D = 313, mod = 1e9 + 7;   long long hsh[maxn], n, ht, ans, tz, p[maxn];   string t, s[maxn];   vector<pair<int, int> > nei[maxn];   void find_p() {     p[0] = 1;     for (int i = 1; i < maxn; i++) p[i] = (p[i - 1] * D) % mod;   }   long long get_hash(int st, int en) {     return ((hsh[en] - hsh[st] * p[en - st]) % mod + mod) % mod;   }   void st_hash() {     for (int i = 0; i < tz; i++) hsh[i + 1] = ((hsh[i] * D) + t[i]) % mod;     ht = hsh[tz];     memset(hsh, 0, sizeof hsh);   }   void dfs(int v, int par, int ptr) {     for (auto u : nei[v])       if (u.first != par) {         for (auto i : s[u.second]) {           hsh[ptr + 1] = ((hsh[ptr] * D) + i) % mod;           ptr++;           if (ptr - tz >= 0 && get_hash(ptr - tz, ptr) == ht) ans++;         }         dfs(u.first, v, ptr);         ptr -= (int)s[u.second].size();       }   }   int main() {     ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);     int a;     string b;     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a >> b;       a--;       s[i] = b;       nei[i].push_back({a, i});       nei[a].push_back({i, i});     }     cin >> t;     tz = (int)t.size();     find_p();     st_hash();     dfs(0, -1, 0);     cout << ans << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   int n, m, i, j, k, l, r, s, t, d, u, ii, jj, x, y, z, lz[4 * N], h[N];   char c[100];   pair<pair<int, int>, pair<int, int> > first[4 * N];   void init(int root, int bas, int son) {     if (bas == son) {       if (h[bas] == 4)         first[root].first.first = 1;       else         first[root].first.second = 1;       first[root].second.first = first[root].second.second = 1;       return;     }     init((root + root), bas, (bas + son >> 1));     init(((root + root) + 1), (bas + son >> 1) + 1, son);     first[root].first.first =         first[(root + root)].first.first + first[((root + root) + 1)].first.first;     first[root].first.second = first[(root + root)].first.second +                                first[((root + root) + 1)].first.second;     first[root].second.first = max(first[(root + root)].second.first +                                        first[((root + root) + 1)].first.second,                                    first[(root + root)].first.first +                                        first[((root + root) + 1)].second.first);     first[root].second.second = max(first[(root + root)].second.second +                                         first[((root + root) + 1)].first.first,                                     first[(root + root)].first.second +                                         first[((root + root) + 1)].second.second);   }   void push(int root, int bas, int son) {     if (lz[root] and bas != son) {       lz[((root + root) + 1)] = 1 - lz[((root + root) + 1)];       lz[(root + root)] = 1 - lz[(root + root)];       swap(first[(root + root)].first.first, first[(root + root)].first.second);       swap(first[((root + root) + 1)].first.first,            first[((root + root) + 1)].first.second);       swap(first[((root + root) + 1)].second.first,            first[((root + root) + 1)].second.second);       swap(first[(root + root)].second.first, first[(root + root)].second.second);     }     lz[root] = 0;   }   void g(int root, int bas, int son) {     push(root, bas, son);     if (x > son or y < bas) return;     if (x <= bas and y >= son) {       swap(first[root].first.first, first[root].first.second);       swap(first[root].second.first, first[root].second.second);       lz[root] = 1;       return;     }     g((root + root), bas, (bas + son >> 1));     g(((root + root) + 1), (bas + son >> 1) + 1, son);     first[root].first.first =         first[(root + root)].first.first + first[((root + root) + 1)].first.first;     first[root].first.second = first[(root + root)].first.second +                                first[((root + root) + 1)].first.second;     first[root].second.first = max(first[(root + root)].second.first +                                        first[((root + root) + 1)].first.second,                                    first[(root + root)].first.first +                                        first[((root + root) + 1)].second.first);     first[root].second.second = max(first[(root + root)].second.second +                                         first[((root + root) + 1)].first.first,                                     first[(root + root)].first.second +                                         first[((root + root) + 1)].second.second);   }   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) {       scanf(  %c , &c[0]);       if (c[0] ==  4 ) h[i] = 4;     }     init(1, 1, n);     while (m--) {       scanf( %s , c);       if (c[0] ==  c )         printf( %d n , first[1].second.first);       else {         scanf( %d%d , &x, &y);         g(1, 1, n);       }     }   }


#include <bits/stdc++.h>   int n, k;   int count;   int x;   std::vector<int> negTemps;   std::priority_queue<int, std::vector<int>, std::greater<int> > intervals;   int main(void) {     scanf(  %d %d , &n, &k);     for (int i = 0; i <= n - 1; ++i) {       scanf(  %d , &x);       if (x < 0) {         negTemps.push_back(i);       }     }     if (!negTemps.size()) {       printf( 0 n );       return 0;     }     if (k < negTemps.size()) {       printf( -1 n );       return 0;     }     int count = negTemps.size() << 1;     int rem = k - negTemps.size();     auto it1 = negTemps.begin();     auto it2 = it1 + 1;     while (it2 != negTemps.end()) {       intervals.push(*it2 - 1 - *it1);       ++it1;       ++it2;     }     while (intervals.size() && intervals.top() <= rem) {       count -= 2;       rem -= intervals.top();       intervals.pop();     }     if (n - *it1 - 1 <= rem) --count;     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e6 + 10;   long long a[maxn], sum[maxn], n, m, big = 0, tmp;   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &m);       a[m]++;       big = max(big, m);     }     for (int i = 0; i <= big; i++) {       for (int j = 0; j <= big; j++) {         if ((long long)i * j > maxn - 10) break;         sum[i * j] += a[i] * a[j];         if (i == j) sum[i * j] -= a[i];       }     }     for (int i = 1; i < maxn; i++) sum[i] += sum[i - 1];     scanf( %lld , &m);     for (int i = 0; i < m; i++) {       scanf( %lld , &tmp);       printf( %lld n , n * (n - 1) - sum[tmp - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e6 + 2e5;   const int N = M >> 1;   const int MX = 2e6;   const int D = 1e6;   double L[M], R[M];   int g[M];   struct pnt {     int x, y;     void input() { scanf( %d %d , &x, &y); }   } p[N];   int n;   double ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       p[i].input();       p[i].x += D, p[i].y += D;     }     function<void(int, double)> update = [&](int y, double x) {       L[y] = min(L[y], x);       R[y] = max(R[y], x);     };     for (int step = 0; step < 2; step++) {       for (int i = 0; i <= MX; i++) L[i] = M, R[i] = -1;       for (int i = 1; i <= n; i++) {         update(p[i].y, p[i].x);         int ni = i == n ? 1 : i + 1;         if (p[i].y == p[ni].y) continue;         double d = (p[ni].x - p[i].x) * 1.0 / (p[ni].y - p[i].y);         double cur;         cur = p[i].x;         for (int j = p[i].y + 1; j < p[ni].y; j++) {           cur += d;           update(j, cur);         }         cur = p[ni].x;         for (int j = p[ni].y + 1; j < p[i].y; j++) {           cur += d;           update(j, cur);         }       }       long long tot = 0;       for (int i = 0; i <= MX; i++) {         int lx = L[i] + 0.9999999;         int rx = R[i] + 0.0000001;         g[i] = rx >= lx ? rx - lx + 1 : 0;         tot += g[i];       }       double c = 0, d = 0, dd = 0;       for (int i = 0; i < MX; i++) {         double r = g[i] * 1.0 / (tot - 1);         d = d + dd + r;         dd = dd + r + r;         c = c + d;         ans += 1.0 * g[i + 1] / tot * c;       }       for (int i = 1; i <= n; i++) swap(p[i].x, p[i].y);     }     cout << fixed << setprecision(10) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   static int v1[100001];   static int v2[100001];   int comp(const void *elem1, const void *elem2) {     return *((const int *)elem2) - *((const int *)elem1);   }   int main(void) {     int k, r, n;     scanf( %d %d %d , &n, &k, &r);     k--;     r--;     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       v1[i] = a;     }     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       v2[i] = a;     }     qsort(v1 + k, r - k + 1, sizeof(int), comp);     qsort(v2 + k, r - k + 1, sizeof(int), comp);     for (int i = 0; i < n; ++i) {       if (v1[i] != v2[i]) {         printf( LIE );         return 0;       }     }     printf( TRUTH );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int r, g, b, w;       cin >> r >> g >> b >> w;       int e = 0;       if (r % 2 == 0) e++;       if (g % 2 == 0) e++;       if (b % 2 == 0) e++;       if (e == 3) {         cout <<  YES n ;         continue;       } else if (e == 2) {         if (w % 2 == 0) {           cout <<  YES n ;           continue;         } else {           cout <<  NO n ;           continue;         }       } else if (e == 1) {         if (r > 0 && b > 0 && g > 0 && w % 2) {           cout <<  YES n ;           continue;         } else {           cout <<  NO n ;           continue;         }       } else {         cout <<  YES n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long powm(long long a, long long n) {     long long base = 1;     a %= MOD;     while (n) {       if (n & 1) base = base * a % MOD;       a = a * a % MOD;       n >>= 1;     }     return base;   }   int main() {     long long a, b, t;     cin >> a >> b >> t;     if ((a & 1) != (b & 1) && t == -1) {       cout << 0 << endl;       return 0;     }     long long ans = powm(2, a - 1);     ans = powm(ans, b - 1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int modpow(long long int a, long long int n, long long int temp) {     long long int res = 1;     while (n > 0) {       res = (res * res) % temp;       if (n & 1) res = (res * a) % temp;       n /= 2;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0)       return (b);     else       return (gcd(b % a, a));   }   int main() {     int n;     vector<int> a;     cin >> n;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a.push_back(t);     }     sort(a.begin(), a.end());     for (int i = 0; i < n - 1; i++) {       while (a[i + 1] == a[i]) i++;       if (i >= n - 1) break;       if (2 * a[i] > a[i + 1]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 998244353;   struct modint {     int val = 0;     modint() {}     modint(int a) : val(a) {       while (val < 0) {         val += M;       }       while (val >= M) {         val -= M;       }     }     modint(long long a) : val(a % M) {       if (val < 0) {         val += M;       }     }     modint operator+=(modint oth) {       val += oth.val;       val -= (val >= M) ? M : 0;       return *this;     }     modint operator-=(modint oth) {       val -= oth.val;       val += (val < 0) ? M : 0;       return *this;     }     modint operator*=(modint oth) {       val = 1LL * val * oth.val % M;       return *this;     }     void operator++() {       ++val;       if (val == M) {         val = 0;       }     }     void operator--() {       --val;       if (val == -1) {         val = M - 1;       }     }     modint operator-() {       modint res;       res.val = (val == 0) ? 0 : M - val;       return res;     }     int mod() { return M; }     modint pow(long long e) {       modint base = val;       modint res = 1;       while (e > 0) {         if (e % 2 == 1) {           res *= base;         }         base *= base;         e /= 2;       }       return res;     }     modint inv() { return pow(M - 2); }     friend modint operator+(modint a, modint b) { return modint(a) += b; }     friend modint operator-(modint a, modint b) { return modint(a) -= b; }     friend modint operator*(modint a, modint b) { return modint(a) *= b; }     friend bool operator==(modint a, modint b) { return a.val == b.val; }     friend bool operator!=(modint a, modint b) { return a.val != b.val; }   };   using mint = modint;   void ntt(vector<mint> &a) {     int n = a.size();     for (int i = 1, j = 0; i < n; ++i) {       int k = n / 2;       while ((j & k) > 0) {         j ^= k;         k /= 2;       }       j ^= k;       if (i < j) {         swap(a[i], a[j]);       }     }     mint base = mint(3).pow((M - 1) / n);     for (int len = 2; len <= n; len *= 2) {       mint root = base.pow(n / len);       for (int i = 0; i < n; i += len) {         mint cur = 1;         for (int j = 0; j < len / 2; ++j) {           mint l = a[i + j];           mint r = a[i + j + len / 2] * cur;           a[i + j] = l + r;           a[i + j + len / 2] = l - r;           cur *= root;         }       }     }   }   vector<mint> mul(const vector<mint> &u, const vector<mint> &v) {     int n = 1;     while (n < int(u.size() + v.size())) {       n *= 2;     }     vector<mint> a(u.begin(), u.end());     vector<mint> b(v.begin(), v.end());     a.resize(n);     b.resize(n);     ntt(a);     ntt(b);     for (int i = 0; i < n; ++i) {       a[i] *= b[i];     }     ntt(a);     mint inv = mint(n).inv();     for (mint &i : a) {       i *= inv;     }     reverse(a.begin() + 1, a.end());     return a;   }   void solve() {     int n;     string s;     cin >> n >> s;     vector<mint> v(n), k(n);     for (int i = 0; i < n; ++i) {       if (s[i] ==  V ) {         v[i] = 1;       } else if (s[i] ==  K ) {         k[n - 1 - i] = 1;       }     }     vector<bool> bad(n + 1);     vector<mint> vk = mul(v, k);     for (int i = 0; i < 2 * n; ++i) {       if (vk[i] != 0) {         bad[abs(n - 1 - i)] = true;       }     }     vector<int> ans;     for (int i = 1; i <= n; ++i) {       bool good = true;       for (int j = i; j <= n; j += i) {         good &= !bad[j];       }       if (good) {         ans.push_back(i);       }     }     cout << ans.size() <<   n ;     for (auto i : ans) {       cout << i <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       int len = s.size();       int ok = 1;       for (int i = 0; i < len; i++) {         if (i == len) {           if (s[i - 1] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b )             s[i] =  b ;           else if (s[i - 1] !=  c )             s[i] =  c ;         }         if (s[i] ==  ?  && i != len) {           if (s[i - 1] !=  a  && s[i + 1] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b  && s[i + 1] !=  b )             s[i] =  b ;           else if (s[i - 1] !=  c  && s[i + 1] !=  c )             s[i] =  c ;         }       }       for (int i = 0; i < len - 1; i++) {         if (s[i] == s[i + 1]) ok = 0;       }       if (!ok)         cout <<  -1               <<   n ;       else         cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != EOF) {       int i;       for (i = 0; i <= n; i++) {         if (i * 2 + (n - i) * 5 >= k && i * 2 + (n - i) * 3 <= k) break;       }       printf( %d n , i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   vector<bool> used;   vector<vector<int>> g;   int dfs(int v) {     if (used[v]) return 0;     used[v] = true;     int size = 1;     for (int i = 0; i < g[v].size(); i++) size += dfs(g[v][i]);     return size;   }   void Solve() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     g.assign(n, vector<int>());     vector<int> c(k);     for (int i = 0; i < k; i++) {       scanf( %d , &c[i]);       c[i]--;     }     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     used.assign(n, false);     int answer = 0;     int maxsize = 0;     for (int i = 0; i < k; i++) {       int size = dfs(c[i]);       maxsize = max(maxsize, size);       answer += size * (size - 1) / 2;     }     for (int i = 0; i < n; i++) {       if (!used[i]) {         int size = dfs(i);         answer += size * (size - 1) / 2 + size * maxsize;         maxsize += size;       }     }     printf( %d , answer - m);   }   int main() {     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, p;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       int c = 0;       for (int i = 0; i < n; i++) {         if (s[i] == s[i + 1]) c++;       }       if (c == 1)         cout << c << endl;       else if (c % 2 != 0) {         c /= 2;         ++c;         cout << c << endl;       } else {         c /= 2;         cout << c << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool diverse(string x) {     sort(x.begin(), x.end());     for (int i = 1; i < x.size(); i++)       if (x[i] - x[i - 1] != 1) return 0;     return 1;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int n;     cin >> n;     cin.ignore(256,   n );     vector<string> in(n);     for (int i = 0; i < n; i++) getline(cin, in[i],   n );     for (int i = 0; i < n; i++) {       if (diverse(in[i]) || in[i].size() == 1)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> inchat;   set<int> inchat2;   bool leaders[100005];   int id[100005];   char in[100005];   int main() {     int N, M;     scanf( %d %d , &N, &M);     for (int i = 1; i <= N; i++) leaders[i] = true;     for (int i = 0; i < M; i++) {       scanf(  %c %d n , &in[i], &id[i]);     }     for (int i = M - 1; i > 0; i--) {       if (in[i] ==  - ) {         inchat2.insert(id[i]);       } else {         auto it = inchat2.find(id[i]);         if (it != inchat2.end()) {           inchat2.erase(it);         }       }     }     for (int i = 0; i < M; i++) {       if (in[i] ==  + ) {         if (inchat.size() == 0 &&             (inchat2.size() == 0 ||              (inchat2.size() == 1 && *inchat2.begin() == id[i]))) {           if (i == 0 || id[i - 1] == id[i]) {           } else {             leaders[id[i]] = false;           }         } else {           leaders[id[i]] = false;         }         inchat.insert(id[i]);       } else {         if (inchat.size() == 0 ||             (inchat.size() == 1 && (*inchat.begin() == id[i]))) {           if (inchat2.size() == 0 ||               (inchat2.size() == 1 && *inchat2.begin() == id[i])) {             if (i == M - 1 || id[i + 1] == id[i]) {             } else {               leaders[id[i]] = false;             }           } else {             leaders[id[i]] = false;           }         } else {           leaders[id[i]] = false;         }         auto it = inchat.find(id[i]);         if (it != inchat.end()) {           inchat.erase(it);         }       }       if (i != M - 1) {         if (in[i + 1] ==  - ) {           auto it = inchat2.find(id[i + 1]);           if (it != inchat2.end()) {             inchat2.erase(it);           }         } else {           inchat2.insert(id[i + 1]);         }       }     }     int cnt = 0;     for (int i = 1; i <= N; i++) {       if (leaders[i]) {         cnt++;       }     }     printf( %d n , cnt);     for (int i = 1; i <= N; i++) {       if (leaders[i]) {         printf( %d  , i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   pair<int, int> a[N];   pair<int, int> ra[N];   int ans[N];   pair<int, int> cross(pair<int, int> a, pair<int, int> b) {     if (a > b) swap(a, b);     return pair<int, int>(b.first, min(a.second, b.second));   }   void solve() {     ra[n] = pair<int, int>(a[n].first, a[n].first + a[n].second);     for (int i = n - 1; i >= 1; i--) {       ra[i] = cross(pair<int, int>(ra[i + 1].first - 1, ra[i + 1].second + 1),                     pair<int, int>(a[i].first, a[i].first + a[i].second));       if (ra[i].first > ra[i].second) {         cout <<  -1 ;         return;       }     }     ans[1] = ra[1].second;     for (int i = 2; i <= n; i++) {       pair<int, int> cur =           cross(pair<int, int>(ans[i - 1] - 1, ans[i - 1] + 1), ra[i]);       ans[i] = cur.second;     }     long long sum = 0;     for (int i = 1; i <= n; i++) sum += ans[i] - a[i].first;     cout << sum <<   n ;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].first, &a[i].second);     solve();   }


#include <bits/stdc++.h>   using namespace std;   double Fib(double x, double z);   string BinDec(unsigned long long x);   string StringInt(long long x);   unsigned long long StringInt(string x);   unsigned long long BinDec(string x);   unsigned long long POWMOD(unsigned long long x, unsigned long long y,                             unsigned long long mod);   unsigned long long POWE(long long, long long);   long long fast_pow(long long a, long long b, long long mod) {     if (b == 0) return 1ll;     long long ans = 1;     if (b % 2) return ans = (fast_pow(a, b - 1, mod) * a) % mod;     ans = (fast_pow(a, b / 2, mod) % mod);     return ((ans * ans) % mod);   }   int arr[10][10] = {};   vector<vector<pair<int, int> > > vec, vec2;   void rec(int i, int j, vector<pair<int, int> > v) {     if (v.size() == 8) {       vec.push_back(v);     }     if (i == 9) return;     if (arr[i][j] == 0) {       for (int k = 1; k <= 8; k++) arr[k][j]++;       for (int l = 1; l <= 8; l++) arr[i][l]++;       arr[i][j]--;       for (int k = 1; k <= 8; k++) {         if (i + k <= 8 && j + k <= 8) arr[i + k][k + j]++;         if (i - k >= 1 && j - k >= 1) arr[i - k][j - k]++;         if (i + k <= 8 && j - k >= 1) arr[i + k][j - k]++;         if (i - k >= 1 && j + k <= 8) arr[i - k][j + k]++;       }       v.push_back({i, j});       if (j == 8)         rec(i + 1, 1, v);       else         rec(i, j + 1, v);       v.pop_back();       for (int k = 1; k <= 8; k++) arr[k][j]--;       for (int l = 1; l <= 8; l++) arr[i][l]--;       arr[i][j]++;       for (int k = 1; k <= 8; k++) {         if (i + k <= 8 && j + k <= 8) arr[i + k][k + j]--;         if (i - k >= 1 && j - k >= 1) arr[i - k][j - k]--;         if (i + k <= 8 && j - k >= 1) arr[i + k][j - k]--;         if (i - k >= 1 && j + k <= 8) arr[i - k][j + k]--;       }     }     if (j == 8)       rec(i + 1, 1, v);     else       rec(i, j + 1, v);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long x, y, a, b, c, d, s;     cin >> x >> y >> a >> b;     if (a == b || y == 1)       s = 1;     else if (b % y == 0 && b - a < y)       s = 1;     else if (b % y > a % y && b - a < y && a % y)       s = 1;     else if (a % y == 1 && b % y == 0)       s = 1;     else if (b == x && a % y == 1)       s = 1;     else if (b == x)       s = 2;     else if (b % y == 0 || a % y == 1)       s = 2;     else if (b % y == ((a - 1) % y))       s = 2;     else if (b - a < y)       s = 2;     else if (b - a < y * 2 && ((b % y == 0 || b % y > y / 2) ||                                ((y - (a % y)) > y / 2 && a % y != 0)))       s = 2;     else       s = 3;     cout << s;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:667772160 )   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   int value[10000000 + 7][3], level[100000 + 7], arr[100000 + 7];   long long odd;   vector<int> graph[100000 + 7];   void dfs(int u) {     level[u] = 1;     int v;     for (int i = 0; i < graph[u].size(); i++) {       v = graph[u][i];       dfs(v);       level[u] = level[v] ^ 1;     }     odd += level[u];   }   int main() {     int mx = 0, n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     int p;     for (int i = 2; i <= n; i++) {       scanf( %d , &p);       graph[p].push_back(i);     }     dfs(1);     int xr = 0;     for (int i = 1; i <= n; i++) {       value[arr[i]][level[i]]++;       if (level[i]) xr = xr ^ arr[i];     }     long long ans = 0;     if (xr == 0) {       ans += (odd * (odd - 1)) / 2LL;       odd = n - odd;       ans += (odd * (odd - 1)) / 2LL;     }     for (int i = 1; i <= n; i++) {       if (level[i] && (arr[i] ^ xr) <= 10000000) ans += value[arr[i] ^ xr][0];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 1000007;   vector<int> adj[NN];   int vst[NN], ans[NN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);     }     for (int i = 1; i <= n; i++)       if (!vst[i]) {         vst[i] = 1;         for (int v : adj[i])           if (!vst[v]) vst[v] = 2;       }     int cnt = 0;     for (int i = n; i; i--)       if (vst[i] == 1) {         ans[++cnt] = i;         for (int v : adj[i]) vst[v] = 2;       }     cout << cnt << endl;     for (int i = 1; i <= cnt; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   long long L, R;   vector<long long> vec, vec2;   long long solve(long long x);   set<int> st;   void precalc() {     for (long long i = 2; i <= 1e6; i++) {       for (long long j = i * i * i; j <= 1e18; j *= i) {         vec.push_back(j);         if (j > (1e18) / i) break;       }     }     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());     for (long long i = 0; i < (long long)vec.size(); i++) {       long long tmp = solve(vec[i]);       if (tmp * tmp == vec[i]) continue;       vec2.push_back(vec[i]);     }     sort(vec2.begin(), vec2.end());   }   long long solve(long long x) {     long long l = 0, r = 1e9 + 1;     while (r - l > 1) {       long long k = (l + r) / 2;       if (k * k > x)         r = k;       else         l = k;     }     return l;   }   int main() {     cin >> q;     precalc();     while (q--) {       scanf( %I64d , &R);       printf( %I64d n , R - (upper_bound(vec2.begin(), vec2.end(), R) -                              vec2.begin() + solve(R)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (1e18);   const int N = (2 * (1e5));   int n;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     pair<int, int> p[n];     for (int i = 0; i < n; i++) {       cin >> p[i].first;       p[i].second = i;     }     sort(p, p + n);     int ans = 0;     int a[n];     for (int i = n - 1; i >= 0; i--) {       int x = n - 1 - i;       ans += p[i].first * x + 1;       a[x] = p[i].second + 1;     }     cout << ans << endl;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = -0x3ffffff;   const int maxn = 5e6 + 5;   int fa[maxn];   int fin(int x) {     if (x == fa[x]) return x;     return fa[x] = fin(fa[x]);   }   long long n, m;   long long vis[maxn];   const long long mod = 1e9 + 7;   long long get(long long x, long long y) {     long long ans = 1;     long long h = x;     while (y) {       if (y % 2) ans = ans * x % mod;       y /= 2;       x = x * x % mod;     }     return (ans - h + mod) % mod;   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= n + 5; i++) fa[i] = i;     for (int i = 0; i < n - 1; i++) {       long long l, r, t;       cin >> l >> r >> t;       if (!t) {         int x = fin(l), y = fin(r);         fa[x] = y;       }     }     for (int i = 1; i <= n; i++) {       vis[fin(i)]++;     }     long long ans = 0;     long long res = get(n, m);     for (int i = 1; i <= n; i++) {       if (fin(i) == i) {         res -= get(vis[i], m);         res = (res + mod) % mod;       }     }     cout << (res + mod) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Dbg {     template <typename T>     Dbg& operator,(const T& v) {       cerr << v <<  ,  ;       return *this;     }   } Dbg;   template <typename T>   ostream& operator<<(ostream& _o_, const vector<T>& _v_) {     if (!_v_.empty()) {       _o_ <<  [ ;       copy(_v_.begin(), _v_.end(), ostream_iterator<T>(_o_,  ,  ));       _o_ <<   b b] ;     }     return _o_;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   vector<long long> num;   long long dp[30][3][15][15];   long long sz;   long long solve(long long pos, bool f, long long first, long long last) {     if (pos == sz) {       if (first == last) {         return 1;       }       return 0;     }     if (dp[pos][f][first][last] != -1) return dp[pos][f][first][last];     long long ans = 0;     long long mx = 0;     if (sz < num.size()) {       mx = 9;     } else {       if (f == 0) {         mx = num[pos];       } else {         mx = 9;       }     }     for (long long digit = 0; digit <= mx; digit++) {       bool tmpf = f;       long long tmpfirst = first;       if (pos == 0 && digit == 0 && sz > 1) continue;       if (pos == 0) tmpfirst = digit;       if (digit < mx) tmpf = 1;       ans += solve(pos + 1, tmpf, tmpfirst, digit);     }     return dp[pos][f][first][last] = ans;   }   long long solve(long long b) {     if (b == 0) {       return 1;     }     num.clear();     while (b > 0) {       num.push_back(b % 10);       b /= 10;     }     reverse(num.begin(), num.end());     long long ans = 0;     for (long long q = 1; q <= num.size(); q++) {       sz = q;       for (long long i = 0; i <= 19; i++) {         for (long long j = 0; j < 2; j++) {           for (long long k = 0; k < 10; k++) {             for (long long l = 0; l < 10; l++) {               dp[i][j][k][l] = -1;             }           }         }       }       ans += solve(0, 0, 0, 0);     }     return ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long l, r;     cin >> l >> r;     cout << solve(r) - solve(l - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[300005];   int indeg[300005];   queue<int> q;   int dp[300005][26], ma = 1;   string s;   int n, m, x, y, cnt = 0;   bool co = 1;   int main() {     cin >> n >> m;     cin >> s;     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--;       y--;       indeg[y]++;       adj[x].push_back(y);     }     for (int i = 0; i < n; i++) {       if (indeg[i] == 0) {         q.push(i);         dp[i][s[i] -  a ]++;       }     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : adj[u]) {         for (int j = 0; j < 26; j++) {           dp[v][j] = max(dp[v][j], dp[u][j] + (s[v] -  a  == j));         }         indeg[v]--;         if (indeg[v] == 0) q.push(v);       }       cnt++;     }     if (cnt < n) {       cout <<  -1 n ;     } else {       for (int i = 0; i < n; i++) {         for (int j = 0; j < 26; j++) {           if (dp[i][j] > ma) ma = dp[i][j];         }       }       cout << ma <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const int mxN = 2e5 + 5;   const long long inf = 1e18;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   pair<int, long long> dp[2][4];   long long mn[mxN], mx[mxN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, k, q;     cin >> n >> m >> k >> q;     vector<pair<long long, long long>> p(k);     for (int i = 0; i < (int)(mxN); i++) mn[i] = inf, mx[i] = -inf;     long long h = 0;     for (int i = 0; i < (int)(k); i++) {       cin >> p[i].first >> p[i].second;       mn[p[i].first] = min(mn[p[i].first], p[i].second);       mx[p[i].first] = max(mx[p[i].first], p[i].second);       h = max(h, p[i].first);     }     vector<int> b(q);     for (int i = 0; i < (int)(q); i++) cin >> b[i];     sort(b.begin(), b.end());     for (int i = 0; i < (int)(2); i++)       for (int j = 0; j < (int)(4); j++) dp[i][j] = make_pair(0, inf);     long long ans = 1e18;     if (mn[1] == inf) {       int pos = 1;       auto it = lower_bound(b.begin(), b.end(), pos);       if (it != b.end()) dp[0][1] = make_pair(*it, (*it - pos));       if (it != b.begin()) {         it--;         dp[0][0] = make_pair(*it, (pos - *it));       }       ans = 0;     } else {       int pos = mx[1];       auto it = lower_bound(b.begin(), b.end(), pos);       if (it != b.end()) dp[0][3] = make_pair(*it, (*it - pos) + (pos - 1));       if (it != b.begin()) {         it--;         dp[0][2] = make_pair(*it, (pos - *it) + (pos - 1));       }       ans = pos - 1;     }     int cnt = 1;     for (int i = (int)(2); i < (int)(mxN); i++)       if (mn[i] != inf) {         int cr = cnt & 1, pr = 1 - cr;         long long A = 1e18, B = 1e18;         for (int j = 0; j < (int)(4); j++)           if (dp[pr][j].second != inf) {             A = min(A, dp[pr][j].second + abs(mx[i] - dp[pr][j].first) +                            (mx[i] - mn[i]));           }         for (int j = 0; j < (int)(4); j++)           if (dp[pr][j].second != inf) {             B = min(B, dp[pr][j].second + abs(mn[i] - dp[pr][j].first) +                            (mx[i] - mn[i]));           }         int pos = mn[i];         auto it = lower_bound(b.begin(), b.end(), pos);         if (it != b.end()) dp[cr][1] = make_pair(*it, A + (*it - pos));         if (it != b.begin()) {           it--;           dp[cr][0] = make_pair(*it, A + (pos - *it));         }         pos = mx[i];         it = lower_bound(b.begin(), b.end(), pos);         if (it != b.end()) dp[cr][3] = make_pair(*it, B + (*it - pos));         if (it != b.begin()) {           it--;           dp[cr][2] = make_pair(*it, B + (pos - *it));         }         ans = min(A, B);         for (int j = 0; j < (int)(4); j++) dp[pr][j] = make_pair(0, inf);         cnt++;       }     cout << ans + h - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define pb push_back   #define pf push_front   #define fi first   #define se second      using namespace std;   typedef long long ll;      int main()   {    ios::sync_with_stdio(0);    cin.tie(0);    ll t, n, k;    cin >> t;    while(t--)       {           cin >> n >> k;           for(ll i=1; i<2*k-n; i++)           {               cout << i <<    ;           }           for(ll i=k; i>=2*k-n; i--)           {               cout << i <<    ;           }           cout <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 13;   int n;   int a[N];   void get(long long T, long long& pr, long long& cnt) {     pr = 0, cnt = 0;     for (int i = 0; i < int(n); i++) {       if (T >= a[i]) {         T -= a[i];         pr += a[i];         ++cnt;       }     }   }   int main() {     long long T;     scanf( %d%lld , &n, &T);     for (int i = 0; i < int(n); i++) scanf( %d , &a[i]);     int mn = *min_element(a, a + n);     long long ans = 0;     while (T >= mn) {       long long pr, cnt;       get(T, pr, cnt);       ans += cnt * (T / pr);       T %= pr;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long OO = 1LL << 61;   const int MOD = 1000000007;   long long dp[1005][20005];   int a[1005];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       memset(dp, 0, sizeof dp);       for (int i = 0; i <= n; i++) dp[i][10000] = 1;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= 20000; j++) {           if (j + a[i] <= 20000)             dp[i][j + a[i]] = (dp[i][j + a[i]] + dp[i - 1][j] + MOD) % MOD;           if (j - a[i] >= 0)             dp[i][j - a[i]] = (dp[i][j - a[i]] + dp[i - 1][j] + MOD) % MOD;         }       }       long long ans = 0;       for (int i = 1; i <= n; i++) ans = (ans + dp[i][10000] - 1 + MOD) % MOD;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, p, q;   int main() {     int t;     scanf( %d , &t);     int x, y, p, q;     while (t--) {       scanf( %d %d %d %d , &x, &y, &p, &q);       if (p == q) {         printf( %d n , x == y ? 0 : -1);         continue;       }       if (p == 0) {         printf( %d n , x == 0 ? 0 : -1);         continue;       }       long long s, d;       s = x % p == 0 ? (x / p) : (x / p + 1);       d = (y - x) % (q - p) == 0 ? ((y - x) / (q - p)) : ((y - x) / (q - p) + 1);       printf( %lld n , (max(s, d)) * q - y);     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int Maxn = (1 << 23) + 5;   const int N = 50;   const int M = 24;   int read() {     int s = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     return s * f;   }   char s[N][N];   unsigned int f[Maxn], g[Maxn];   int h[Maxn], num[Maxn];   int lowbit(int x) { return x & (-x); }   int n, m, tot, Sta, a[N][N], id[N], fa[N], sum[N];   int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }   void Union(int x, int y) {     x = Find(x);     y = Find(y);     if (x != y) {       fa[x] = y;       sum[y] += sum[x];     }   }   int main() {     n = read();     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i <= n; i++) {       fa[i] = i;       sum[i] = 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++)         if (s[i][j] ==  A ) Union(i, j);     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++)         if (s[i][j] ==  X  && Find(i) == Find(j)) {           puts( -1 );           return 0;         }     for (int i = 1; i <= n; i++)       if (!id[Find(i)] && sum[Find(i)] >= 2) id[Find(i)] = ++tot;     if (!tot) {       printf( %d n , n - 1);       return 0;     }     Sta = (1 << tot) - 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++)         if (s[i][j] ==  X ) {           int x = id[Find(i)], y = id[Find(j)];           a[x][y] = a[y][x] = 1;         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (a[i][j]) h[1 << (i - 1)] |= (1 << (j - 1));     f[0] = 1;     for (int S = 1; S <= Sta; S++) {       g[S] = 1;       num[S] = num[S >> 1] + (S & 1);       f[S] = f[S ^ lowbit(S)] + f[(S ^ lowbit(S)) ^ (S & h[lowbit(S)])];     }     for (int S = 1; S <= Sta; S++) f[S]--;     for (int k = 1; k <= tot; k++) {       unsigned int ans = 0;       for (int S = 1; S <= Sta; S++) {         g[S] *= f[S];         ans += (num[Sta ^ S] & 1 ? -1 : 1) * g[S];       }       if (ans) {         printf( %d , n + k - 1);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 5;   const int Mod = 1e9 + 7;   void add(int &a, long long b) { a = (a + b) % Mod; }   long long encode(const vector<int> &p) {     assert(p.size() == K);     long long x = 0;     for (auto i : p) {       x = (x << K) + i;     }     return x;   }   bool insert(vector<int> &p, int x) {     int b = -1;     for (int i = K - 1; i >= 0; i--) {       if (x >> i & 1) {         if (p[i] != 0)           x ^= p[i];         else if (b == -1)           b = i;       }     }     if (b == -1) return false;     p[b] = x;     for (int i = b + 1; i < K; i++) {       if (p[i] >> b & 1) p[i] ^= x;     }     return true;   }   vector<vector<int> > spaces;   unordered_map<long long, int> id;   int basic[1 << K];   int sum[400][400], tot;   int comb(int a, int b) {     vector<int> p = spaces[a];     for (auto x : spaces[b]) {       if (x > 0 && !insert(p, x)) return -1;     }     long long c = encode(p);     assert(id.count(c));     return id[c];   }   void build() {     spaces.push_back(vector<int>(K, 0));     id[0] = 0;     basic[0] = -1;     for (int x = 1; x < (1 << K); x++) {       int sz = spaces.size();       basic[x] = sz;       for (int i = 0; i < sz; i++) {         vector<int> p = spaces[i];         if (insert(p, x)) {           long long c = encode(p);           if (!id.count(c)) {             id[c] = spaces.size();             spaces.push_back(p);           }         }       }     }     tot = spaces.size();     for (int i = 0; i < tot; i++)       for (int j = 0; j < tot; j++) sum[i][j] = comb(i, j);   }   const int N = 1e5 + 10;   vector<pair<int, int> > G[N];   void add_edge(int u, int v, int second) {     if (u > v) swap(u, v);     G[u].push_back(pair<int, int>(v, second));     if (u > 1) G[v].push_back(pair<int, int>(u, second));   }   int n, m;   vector<int> op[N];   int Sum(int x, int y) {     if (x != -1 && y != -1) return sum[x][y];     return -1;   }   bool sp(int v) { return op[v].size(); }   vector<pair<int, int> > ext[N];   int root;   int xorsum[N];   int rtw[N];   bool used[N];   void dfs(int v, int p = -1) {     used[v] = true;     for (auto &e : G[v]) {       int u = e.first;       if (u == p) continue;       if (sp(v) && sp(u)) {         if (v < u) ext[v].push_back(e);         continue;       }       if (used[u]) {         if (v < u) {           op[root].back() =               Sum(op[root].back(), basic[e.second ^ xorsum[v] ^ xorsum[u]]);         }         continue;       }       xorsum[u] = xorsum[v] ^ e.second;       dfs(u, v);     }   }   int dp[2][400];   int main() {     build();     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v, second;       scanf( %d%d%d , &u, &v, &second);       add_edge(u, v, second);     }     for (auto &e : G[1]) {       int v = e.first;       op[v].push_back(0), op[v].push_back(0);     }     for (auto &e : G[1]) {       int v = e.first;       rtw[v] = e.second;       root = v;       dfs(v);     }     for (auto &se : G[1]) {       int v = se.first;       for (auto &e : ext[v]) {         int u = e.first, second = e.second;         assert(sp(v) && sp(u));         int op1 = op[u].back(), op2 = op[v].back();         op[v].clear();         op[u].clear();         op[v] = {0, Sum(op1, op2), Sum(op1, op2),                  Sum(Sum(op1, op2), basic[second ^ rtw[v] ^ rtw[u]])};       }     }     int now = 0;     dp[now][0] = 1;     for (auto &e : G[1]) {       int v = e.first;       if (!sp(v)) continue;       memset(dp[now ^ 1], 0, sizeof dp[now ^ 1]);       for (auto x : op[v]) {         if (x == -1) continue;         for (int i = 0; i < tot; i++) {           int j = Sum(i, x);           if (j != -1) add(dp[now ^ 1][j], dp[now][i]);         }       }       now ^= 1;     }     int ans = 0;     for (int i = 0; i < tot; i++) add(ans, dp[now][i]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void printvector(vector<long long> v) {     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   map<long long, long long> mp;   long long a[100005][3] = {0};   int main() {     long long m, n, i, j, k, l;     cin >> m;     for (i = 0; i < m; i++) {       cin >> a[i][0];       if (a[i][0] == 1)         cin >> a[i][1];       else         cin >> a[i][1] >> a[i][2];     }     vector<long long> v;     v.push_back(0);     for (i = 0; i < m; i++) {       if (a[i][0] == 1) {         v.push_back(1 + v[i]);         mp[1 + v[i]] = a[i][1];       } else         v.push_back(v[i] + a[i][1] * a[i][2]);     }     long long t, x;     cin >> t;     while (t--) {       cin >> x;       while (mp[x] == 0) {         long long idx = lower_bound(v.begin(), v.end(), x) - v.begin();         long long tmp = x - v[idx - 1];         x = (tmp - 1) % (a[idx - 1][1]) + 1;       }       cout << mp[x] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long nCr(long long n, long long r) {     long long C[r + 1];     memset(C, 0, sizeof(C));     C[0] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1];     return C[r];   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     long long m = sqrt(n);     for (long long i = 3; i <= m; i += 2)       if (n % i == 0) return false;     return true;   }   long long M(long long a) { return (a % (1000000007LL)); }   bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int n, k;     cin >> n >> k;     vector<bool> same_name(n - k + 1);     int index = 0;     string s;     while (index < n - k + 1) {       cin >> s;       if (s ==  YES ) same_name[index] = true;       index++;     }     vector<int> ans(n);     vector<string> strings(51,   );     for (long long i = 0; i < (long long)(51); ++i) {       if (i < 26) {         strings[i] += (char)(i +  A );       } else {         strings[i] += (char)(i - 26 +  A );         strings[i] += (char)(i - 26 +  a );       }     }     int counter = k;     if (same_name[0])       for (long long i = 0; i < (long long)(k); ++i) ans[i] = i;     else {       for (long long i = 0; i < (long long)(k - 1); ++i) ans[i] = i;       ans[k - 1] = ans[0];       counter--;     }     for (int i = 1; i < n - k + 1; i++) {       if (same_name[i])         ans[k + i - 1] = counter++;       else         ans[k + i - 1] = ans[i];     }     for (long long i = 0; i < (long long)(n); ++i) cout << strings[ans[i]] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long I1 = 1e9;   const long long I2 = 1e18;   const int32_t M1 = 1e9 + 7;   const int32_t M2 = 998244353;   template <typename T, typename T1>   T maxn(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T minn(T &a, T1 b) {     if (b < a) a = b;     return a;   }   void solve() {     long long int n;     cin >> n;     if (n == 1) {       cout <<  0             <<   n ;       return;     }     long long int l = 1, r = n - 1, m1, m2, ans = 0;     while (l <= r) {       m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;       long long int c1, c2;       c1 = min(2 * m1, m1 + ((n - m1) * (n - m1 - 1)) / 2);       c2 = min(2 * m2, m2 + ((n - m2) * (n - m2 - 1)) / 2);       ans = max({ans, c1, c2});       if (c1 > c2)         r = m2 - 1;       else if (c2 > c1)         l = m1 + 1;       else {         l = m1 + 1, r = m2 - 1;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testcase = 1;     cin >> testcase;     while (testcase--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x, y, n;       cin >> x >> y >> n;       int d = n % x;       if (d < y)         cout << n - d - (x - y) << endl;       else if (d > y)         cout << n - (d - y) << endl;       else         cout << n << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 20;   vector<int> bad[N], comp[N];   int off[N], delta[N], col[N];   long long cnt_on[N];   long long ans = 0;   bool hatman[N];   long long ok(long long x) {     x += 10;     x %= 2;     return x;   }   inline void mer(int u, int v, int f) {     int c1 = col[v], c2 = col[u];     if (c1 == c2) return;     if ((int)comp[c1].size() > (int)comp[c2].size()) swap(c1, c2);     long long avaz = 0;     if (ok(off[u] + off[v] + delta[c1] + delta[c2]) != ok(f)) {       long long d1 = ((int)comp[c1].size() - cnt_on[c1]) - cnt_on[c1];       long long d2 = ((int)comp[c2].size() - cnt_on[c2]) - cnt_on[c2];       avaz = 1;       if (hatman[c1] || (d2 <= d1 && !hatman[c2])) {         cnt_on[c2] = (int)comp[c2].size() - cnt_on[c2] + cnt_on[c1];         delta[c2] = ok(delta[c2] + 1);         ans += d2;         avaz = 0;       } else {         ans += d1;         cnt_on[c2] = cnt_on[c2] + (int)comp[c1].size() - cnt_on[c1];         avaz = 1;       }     } else       cnt_on[c2] += cnt_on[c1];     for (auto x : comp[c1]) {       comp[c2].push_back(x);       col[x] = c2;       off[x] = ok(off[x] + delta[c1]);       if (avaz) off[x] = ok(off[x] + 1);       if (delta[c2]) off[x] = ok(off[x] + 1);     }     hatman[c2] = hatman[c2] || hatman[c1];     vector<int>().swap(comp[c1]);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < n; i++) s[i] = char(1 - (s[i] -  0 ) +  0 );     for (int i = 0; i < k; i++) {       int tt;       cin >> tt;       for (int j = 0; j < tt; j++) {         int x;         cin >> x;         x--;         bad[x].push_back(i);       }     }     for (int i = 0; i < k; i++) {       comp[i].push_back(i);       col[i] = i;       cnt_on[i] = 0;     }     for (int i = 0; i < n; i++) {       if ((int)bad[i].size() == 0) {         cout << ans <<   n ;         continue;       }       if ((int)bad[i].size() == 1) {         int u = bad[i].back();         hatman[col[u]] = true;         int x = s[i] -  0 ;         if (ok(off[u] + delta[col[u]]) == ok(x)) {           cout << ans <<   n ;           continue;         }         u = col[u];         delta[u] = ok(delta[u] + 1);         ans -= cnt_on[u];         cnt_on[u] = (int)comp[u].size() - cnt_on[u];         ans += cnt_on[u];         cout << ans <<   n ;         continue;       }       int x = s[i] -  0 ;       int u = bad[i][0], v = bad[i].back();       mer(u, v, x);       cout << ans <<   n ;     }     return 0;   }