#include <bits/stdc++.h>   using namespace std;   long long dp[5005][5005], bad[30][5005], pre[5005];   const long long MOD = 1e9 + 7;   long long fact[5005];   long long qikpow(long long a, long long b) {     if (!b) {       return 1;     }     long long ret = qikpow(a, b / 2);     ret *= ret;     ret %= MOD;     if (b & 1) {       ret *= a;       ret %= MOD;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int N;     cin >> N;     fact[0] = 1;     dp[0][0] = 1;     pre[0] = 1;     for (int i = 1; i <= N; i++) {       char c;       cin >> c;       fact[i] = (fact[i - 1] * i) % MOD;       for (int k = 1; k <= i; k++) {         dp[i][k] = pre[k - 1];         dp[i][k] = (dp[i][k] - bad[c -  a ][k - 1] + MOD) % MOD;         dp[i][k] = (dp[i][k] - bad[c -  a ][k] + MOD) % MOD;       }       for (int k = 1; k <= i; k++) {         bad[c -  a ][k] = (bad[c -  a ][k] + dp[i][k]) % MOD;         pre[k] = (pre[k] + dp[i][k]) % MOD;       }     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       ans += pre[i] * fact[N - 1] % MOD *              qikpow(fact[i - 1] * fact[N - i] % MOD, MOD - 2) % MOD;       ans %= MOD;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n, s[3000 + 5], c[3000 + 5], f[3000 + 5][5];   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   int main() {     n = read();     memset(f, inf, sizeof(f));     for (int i = 1; i <= n; i++) s[i] = read();     for (int i = 1; i <= n; i++) c[i] = read();     for (int i = 1; i <= n; i++) {       f[i][1] = c[i];       for (int j = 1; j < i; j++)         if (s[j] < s[i]) f[i][2] = min(f[j][1] + c[i], f[i][2]);       for (int j = 1; j < i; j++)         if (s[j] < s[i]) f[i][3] = min(f[j][2] + c[i], f[i][3]);     }     int ans = inf;     for (int i = 1; i <= n; i++)       if (f[i][3]) ans = min(ans, f[i][3]);     if (ans == inf)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long a, sum, l, i, b;     char ch[10];     while (scanf( %I64d , &a) != EOF) {       getchar();       scanf( %s , ch);       l = strlen(ch);       b = 0;       for (i = l - 1; i > 0; i--) b = (ch[i] -  0  + b) * 10;       b = ch[0] -  0  + b;       sum = a + b;       printf( %I64d n , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 50;   long long dp[N];   void solve() {     long long n;     cin >> n;     long long count = 0;     while (n > 0) {       long long quotient = n / 3;       long long rem = n % 3;       n = n / 3;       dp[count] = rem;       count++;     }     for (long long i = 0; i < N; i++) {       if (dp[i] == 0 || dp[i] == 1)         continue;       else {         dp[i] = -1;         dp[i + 1] += 1;       }     }     long long finalAns = 0;     for (long long i = N - 1; i >= 0; i--) {       if (dp[i] == 0) continue;       if (dp[i] == -1)         break;       else {         long long coeff = dp[i];         finalAns += pow(3, i);       }     }     cout << finalAns << endl;     for (long long i = 0; i < N; i++) dp[i] = 0;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9 + 7), MAXN = int(1e3 + 50);   int n, s[MAXN], br, raz, z[MAXN];   vector<int> v[MAXN];   vector<pair<pair<int, int>, int>> rez;   void dfs(int i, int ot) {     s[i] = 1;     for (auto j : v[i])       if (j != ot) {         dfs(j, i);         s[i] += s[j];       }   }   int centroid() {     dfs(1, -1);     int c = 1, ot = -1;     while (1) {       int br = 1;       for (auto j : v[c])         if (j != ot && 2 * s[j] >= n) {           br = 0;           ot = c;           c = j;           break;         }       if (br) break;     }     return c;   }   void dfs2(int i, int ot) {     br += raz;     z[i] = br;     rez.push_back({{i, ot}, z[i] - z[ot]});     for (auto j : v[i])       if (j != ot) dfs2(j, i);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int p, q;       cin >> p >> q;       v[p].push_back(q);       v[q].push_back(p);     }     if (n == 1) {       exit(0);     }     if (n == 2) {       printf( 1 2 1 n );       exit(0);     }     int c = centroid();     dfs(c, -1);     vector<pair<int, int>> v2, g1, g2;     multiset<pair<int, vector<int>>> sv;     for (auto i : v[c]) {       vector<int> vv{i};       sv.insert({s[i], vv});     }     while (sv.size() > 2) {       auto pom1 = *sv.begin();       sv.erase(sv.begin());       auto pom2 = *sv.begin();       sv.erase(sv.begin());       vector<int> vu;       for (auto i : pom1.second) vu.push_back(i);       for (auto i : pom2.second) vu.push_back(i);       sv.insert({pom1.first + pom2.first, vu});     }     auto a = *sv.begin();     sv.erase(sv.begin());     auto b = *sv.begin();     sv.erase(sv.begin());     z[c] = 0;     br = 0;     raz = 1;     for (auto i : a.second) dfs2(i, c);     br = 0;     raz = a.first + 1;     for (auto i : b.second) dfs2(i, c);     for (auto i : rez)       printf( %d %d %d n , i.first.first, i.first.second, i.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const uint64_t seed =       std::chrono::system_clock::now().time_since_epoch().count();   mt19937_64 rnd(seed);   const int MOD = 998244353;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     set<pair<long long, long long>> ss;     int cnt = 0;     long long x = 1, y = 0;     auto has = [&](int v) {       long long d = (v - y) / x;       auto it = ss.upper_bound({d, LLONG_MAX});       if (it != ss.begin()) {         it = prev(it);         return it->first <= d && it->second >= d;       }       return false;     };     for (int p : a) {       if (p % 2 == 0 && has(p / 2)) {         ss.clear();         ss.insert({p / 2, p / 2});         x = 1, y = 0;         continue;       };       x = -x;       y = p - y;       cnt++;       if (p % 2 == 0) {         long long d = (p / 2 - y) / x;         ss.insert({d, d});       }       long long r1 = (1 - y) / x;       long long r2 = (p - 1 - y) / x;       if (r1 > r2) swap(r1, r2);       for (auto it = ss.begin(); it != ss.end();) {         long long aa, bb;         tie(aa, bb) = *it;         aa = max(aa, r1);         bb = min(bb, r2);         if (aa > bb)           it = ss.erase(it);         else {           ss.erase(it);           ss.insert({aa, bb});           break;         }       }       for (auto it = ss.rbegin(); it != ss.rend();) {         long long aa, bb;         tie(aa, bb) = *it;         aa = max(aa, r1);         bb = min(bb, r2);         it = decltype(it){ss.erase(next(it).base())};         if (aa <= bb) {           ss.insert({aa, bb});           break;         }       }       if (ss.empty()) {         cnt++;         ss.insert({r1, r2});       }     }     cout << cnt <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     int T = 1;     cin >> T;     for (int i = 1; i <= T; i++) {       solve();     }     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200005;   long long n, m, u, v, k;   long long flag;   long long a[N];   long long x, y, z;   long long aa, bb, cc, dd;   long long ans[100005];   long long sum;   void init() {}   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   struct node {     long long x, id;     bool operator<(const node t) const { return x < t.x; }   };   long long getn(long long x, long long y, long long z) {     long long n;     cout <<  ?   << x <<     << y <<     << z << endl;     cin >> n;     return n;   }   void solve() {     init();     cin >> n;     sum = 0;     for (long long i = 1; i <= n; i++) {       a[i] = 0;     }     for (long long i = 0; i < n / 3; i++) {       ans[i] = getn(i * 3 + 1, i * 3 + 2, i * 3 + 3);       if (!ans[i]) {         u = i;       } else {         v = i;       }     }     aa = getn(u * 3 + 1, u * 3 + 2, v * 3 + 1);     bb = getn(u * 3 + 1, u * 3 + 2, v * 3 + 2);     cc = getn(v * 3 + 1, v * 3 + 2, u * 3 + 1);     dd = getn(v * 3 + 1, v * 3 + 2, u * 3 + 2);     if (aa + bb == 0) {       x = u * 3 + 1;     } else {       x = u * 3 + 3;     }     a[x] = 0;     if (cc + dd == 2) {       y = v * 3 + 1;     } else {       y = v * 3 + 3;     }     a[y] = 1;     for (long long i = 0; i < n / 3; i++) {       if (ans[i]) {         aa = getn(i * 3 + 1, i * 3 + 2, x);         bb = getn(i * 3 + 2, i * 3 + 3, x);         if (aa + bb == 0) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 1;         } else if (aa + bb == 2) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 1;         } else if (aa == 1) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 0;         } else {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 1;         }       } else {         aa = getn(i * 3 + 1, i * 3 + 2, y);         bb = getn(i * 3 + 2, i * 3 + 3, y);         if (aa + bb == 0) {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 0;         } else if (aa + bb == 2) {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 0;         } else if (aa == 1) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 0;         } else {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 1;         }       }     }     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) sum++;     }     cout <<  !   << sum <<    ;     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) cout << i <<    ;     }     cout << endl;   }   signed main() {     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   bool compare(const int a, const int b) {     if (a <= b) {       return false;     }     return true;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       int last_count = 0;       vector<int> arr;       for (int j = 0; j < s.length(); j++) {         if (j == 0) {           if (s[0] ==  1 ) {             last_count++;           }         } else {           if (s[j] ==  0 ) {             if (last_count != 0) {               arr.push_back(last_count);             }             last_count = 0;           } else {             last_count++;           }         }       }       if (last_count != 0) {         arr.push_back(last_count);       }       if (arr.size() == 0) {         cout << 0 << endl;       } else {         sort(arr.begin(), arr.end(), compare);         int alice_Count = 0;         for (int j = 0; j < arr.size(); j++) {           if (j % 2 == 0) {             alice_Count += arr[j];           }         }         cout << alice_Count << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const double PI = acos(-1.0);   const int MAX = 150005;   int n, len, h;   pair<int, int> a[MAX];   int b[MAX];   pair<int, int> T[MAX * 8];   int lazy[MAX * 8];   bool pzdc[MAX];   void push(int v) {     T[v].first += lazy[v];     lazy[v * 2] += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   void upd(int v, int tl, int tr, int l, int r, int delta) {     push(v);     if (l > r) return;     if (tl == l && tr == r) {       lazy[v] += delta;       push(v);       return;     }     int tm = (tl + tr) / 2;     upd(v * 2, tl, tm, l, min(r, tm), delta);     upd(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, delta);     T[v] = min(T[v * 2], T[v * 2 + 1]);   }   void build(int v, int tl, int tr) {     if (tl == tr) {       T[v].second = tl;       return;     }     int tm = (tl + tr) / 2;     build(v * 2, tl, tm);     build(v * 2 + 1, tm + 1, tr);     T[v] = min(T[v * 2], T[v * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> len >> h;     build(1, 0, n - len);     for (int i = 0; i < len; i++) cin >> b[i];     sort(b, b + len);     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     int ptr = n - 1;     for (int i = 0; i < len; i++) {       while (ptr >= 0 && a[ptr].first + b[i] >= h) {         upd(1, 0, n - len, max(0, a[ptr].second - len + 1),             min(n - len, a[ptr].second), 1);         ptr--;       }       while (T[1].first <= i) {         pzdc[T[1].second] = 1;         upd(1, 0, n - len, T[1].second, T[1].second, INF);       }     }     int ans = 0;     for (int i = 0; i < n - len + 1; i++) ans += !pzdc[i];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a;   int main(int argc, char *argv[]) {     int n;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     if (n == 2) {       cout << 1 <<     << 2;       return 0;     }     if (n == 3) {       cout << 1 <<     << 1 <<     << 3;       return 0;     }     int so = 1, ts = 2, ss = n, luu = 1;     while (ss > 2) {       int m = n / ts;       m = ss - m;       for (int i = 1; i <= m; i++) cout << luu <<    ;       ss = ss - m;       if (ss == 1) {         cout << ts;         return 0;       }       if (ss == 2) {         cout << ts <<     << ts * 2;         return 0;       }       if (ss == 3) {         cout << ts <<     << ts <<     << ts * 3;         return 0;       }       luu = ts;       ts = ts * 2;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > T;   vector<vector<int> > T2;   set<int> att;   bool keep[123456 + 5];   bool hasa(int from, int v) {     keep[v] = false;     if (att.find(v) != att.end()) keep[v] = 1;     for (int i = 0; i < T[v].size(); ++i) {       if (T[v][i] != from) keep[v] |= hasa(v, T[v][i]);     }     return keep[v];   }   map<pair<int, int>, long long> dp[2];   long long get(bool back, int from, int v) {     pair<int, int> state(from, v);     if (dp[back].find(state) == dp[back].end()) {       long long ans = 0;       for (int i = 0; i < T2[v].size(); ++i) {         int u = T2[v][i];         if (u == from) continue;         ans += 2 + get(true, v, u);       }       long long a2 = ans;       if (!back) {         for (int k = 0; k < T2[v].size(); ++k) {           int u = T2[v][k];           if (u == from) continue;           a2 = min(a2, ans - 2 - get(true, v, u) + 1 + get(false, v, u));         }       }       dp[back][state] = a2;     }     return dp[back][state];   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i <= n; ++i) {       T.push_back(vector<int>());       T2.push_back(vector<int>());     }     for (int i = 1; i < n; ++i) {       int a, b;       cin >> a >> b;       T[a].push_back(b);       T[b].push_back(a);     }     for (int i = 0; i < m; ++i) {       int a;       cin >> a;       att.insert(a);     }     fill(keep, keep + n, false);     hasa(-1, *att.begin());     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < T[i].size(); ++j) {         int u = T[i][j];         if (keep[i] && keep[u]) T2[i].push_back(u);       }     }     long long vert = -1, mn = 0x7fffffffffffffff;     for (int i = 1; i <= n; ++i) {       if (keep[i]) {         long long score = get(false, -1, i);         if (score < mn) {           vert = i;           mn = score;         }       }     }     cout << vert <<   n  << mn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const long long inf = 0x3f3f3f3f3f;   long long a[1010][1010];   long long n, k;   int main() {     cin >> n >> k;     long long cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= k; j--) {         a[i][j] = n * n - cnt;         cnt++;       }     }     long long fcnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j < k; j++) {         fcnt++;         a[i][j] = fcnt;       }     }     long long sum = 0;     for (int i = 1; i <= n; i++) sum += a[i][k];     cout << sum << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     string s;     cin >> s;     long long n = s.size();     long long an = 0;     for (long long i = 0; i < n; i++) {       long long r = INT_MAX;       for (long long j = i; j <= min((long long)(i + 9), n - 1); j++) {         for (long long k = 1; k <= 8; k++) {           if (j + 2 * k < n) {             if (s[j] == s[j + k] and s[j] == s[j + 2 * k]) {               r = min(r, j + 2 * k);             }           }         }       }       if (r != INT_MAX) an = an + n - r;     }     cout << an << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(string s1, string s2) { return (s1 + s2) < (s2 + s1); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,         v, w, x, y, z;     cin >> n;     vector<string> v1;     string s1;     for (i = 0; i < n; i++) {       cin >> s1;       v1.push_back(s1);     }     sort(v1.begin(), v1.end(), cmp);     for (i = 0; i < n; i++) cout << v1[i];     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   using namespace std;   const int N = 3e5 + 100;   set<pair<int, int> > s[N];   int a[N];   int nxt[N];   int dp[N];   int mol[N];   int n;   void add(long long int v, long long int u) {     long long int m = mol[u];     if (m != n + 2) s[m].insert({a[v], v});     mol[v] = mol[u];   }   int tt;   void Main(long long int oo) {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       nxt[i] = n + 2;       s[i].clear();       dp[i] = 0;     }     s[n + 1].clear();     s[n + 2].clear();     a[n + 1] = -1;     a[n + 2] = -1;     dp[n + 2] = 0;     dp[n + 1] = 0;     nxt[n + 2] = n + 2;     mol[n + 2] = n + 2;     nxt[n + 1] = n + 1;     for (int i = 1; i <= n + 1; i++) {       mol[i] = n + 1;     }     vector<int> pashm;     for (int i = n; i; i--) {       if (a[i] == a[i + 1]) {         nxt[i] = i + 2;         add(i, i + 2);       } else {         long long int z = mol[nxt[i + 1]];         if (z == n + 3) z = n + 2;         auto y = s[z].lower_bound({a[i], 0});         if (y != s[z].end() && y->first == a[i]) {           long long int p = y->second;           nxt[i] = p + 1;           add(i, p + 1);         } else {           mol[i] = i;           nxt[i] = n + 2;           add(i, i);         }       }     }     long long int ans = 0;     for (int i = n; i; i--) {       if (nxt[i] != n + 2) {         dp[i] = 1 + dp[nxt[i]];       }       ans += dp[i];     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> tt;     for (int i = 1; i <= tt; i++) Main(i);   }


#include <bits/stdc++.h>   using namespace std;   template <class n, class second>   ostream &operator<<(ostream &p, pair<n, second> x) {     return p <<  <  << x.first <<  ,   << x.second <<  > ;   }   template <class n>   auto operator<<(ostream &p, n y) ->       typename enable_if<!is_same<n, string>::value,                          decltype(y.begin(), p)>::type {     int o = 0;     p <<  { ;     for (auto c : y) {       if (o++) p <<  ,  ;       p << c;     }     return p <<  } ;   }   void dor() { cerr << endl; }   template <class n, class... second>   void dor(n p, second... y) {     cerr << p <<    ;     dor(y...);   }   template <class n, class second>   void mini(n &p, second y) {     if (p > y) p = y;   }   template <class n, class second>   void maxi(n &p, second y) {     if (p < y) p = y;   }   const int M = 1024 * 256;   int n, k, x;   int in[M];   int main() {     scanf( %d%d , &n, &k);     for (int i = (2); i <= (int)(n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       in[a]++;       in[b]++;     }     for (int i = (1); i <= (int)(n); ++i) {       if (in[i] == 1) {         x++;       }     }     printf( %.9Lf n , (long double)(k * 2) / x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 5;   const long long INF = 1e18 + 5;   const long long maxn = 5e5 + 5;   long long n = 1000000007, d[151111], mx = -1000000001;   long long a[1511111], ok[100005], sum, cnt, rg[555555], v[555555];   long long bi(long long x, long long y) {     if (y == 0) return 1ll;     if (y == 1) return x;     long long z = bi(x, y / 2);     z = z * z % n;     if (y & 1) z = z * x % n;     return z % n;   }   bool ch(string a, string b) { return a > b; }   map<string, long long> mm;   map<pair<string, string>, long long> ma;   long long first(long long m) {     long long ans = m;     for (long long i = 2; i * i <= m; i++) {       if (m % i == 0) {         while (m % i == 0) m /= i;         ans -= ans / i;       }     }     if (m > 1) ans -= ans / m;     return ans;   }   long long dp[555555][55], b[55][55];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     long long m;     cin >> m;     while (m--) {       long long l, r, x;       cin >> l >> r;       x = l;       for (long long i = 0; i <= 60; i++) {         if ((x | (1ll << i)) <= r) {           x |= (1ll << i);         }       }       cout << x << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int N = 2000005;   long long n, A, B, x, y;   int p[N];   int main() {     scanf( %lld%lld%lld , &n, &A, &B);     y = -1;     for (; x * A <= n; ++x) {       long long tmp = n - x * A;       if (tmp / B * B == tmp) {         y = tmp / B;         break;       }     }     if (y == -1) return 0 * printf( -1 n );     int i = 1;     while (x--) {       int ti = i;       p[ti + A - 1] = i;       for (int ci = 1; ci <= A; ++ci) {         if (ci < A) p[i] = i + 1;         ++i;       }     }     while (y--) {       int ti = i;       p[ti + B - 1] = i;       for (int ci = 1; ci <= B; ++ci) {         if (ci < B) p[i] = i + 1;         ++i;       }     }     for (int i = 1; i <= n; ++i) printf( %d  , p[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   void test_case() {     int n;     scanf( %d , &n);     vector<int> a(n);     const int INF = 1e9 + 5;     long long L = 1, R = INF;     set<long long> s;     long long offset = 0;     int dp = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       if (i % 2 == 1) {         int diff = a[i] - a[i - 1];         L += diff;         R += diff;         offset += diff;       }       L = max(L, 1LL);       R = min(R, a[i] - 1LL);       while (!s.empty() && *s.begin() + offset < 1) {         s.erase(s.begin());       }       while (!s.empty() && *s.rbegin() + offset >= a[i]) {         s.erase(prev(s.end()));       }       if (L <= R || !s.empty()) {         if (i != 0) {           dp++;         }         if (a[i] % 2 == 0) {           if ((L <= a[i] / 2 && a[i] / 2 <= R) || s.count(a[i] / 2 - offset)) {             dp++;             L = R = a[i] / 2;             s.clear();           } else {             s.insert(a[i] / 2 - offset);           }         }       } else {         L = 1;         R = a[i] - 1;         if (a[i] % 2 == 0) {           L = R = a[i] / 2;           dp++;         }       }     }     debug() <<   [              <<  dp                  :               << (dp) <<  ]  ;     printf( %d n , 2 * n - dp);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       test_case();     }   }


#include <bits/stdc++.h>   using namespace std;   struct kmp {     vector<int> lps;     string pattern;     void compute_lps() {       int lptr = 0, rptr = 1;       lps[0] = 0;       while (rptr < lps.size()) {         while (lptr != 0 && pattern[lptr] != pattern[rptr]) lptr = lps[lptr - 1];         if (pattern[lptr] == pattern[rptr]) lptr++;         lps[rptr] = lptr;         rptr++;       }     }     kmp(string& s) {       pattern = s;       lps.resize(s.size());       compute_lps();     }     void search(string& s) {       vector<int> hits;       int lptr = 0, rptr = 0;       while (rptr < s.size()) {         while (lptr != 0 && pattern[lptr] != s[rptr]) lptr = lps[lptr - 1];         if (pattern[lptr] == s[rptr]) lptr++;         rptr++;         if (lptr == pattern.size()) {           hits.push_back(rptr - pattern.size());           lptr = lps[lptr - 1];         }       }     }   };   long long mod = 1e9 + 7;   long long add(long long a, long long b) { return (a + b) % mod; }   long long sub(long long a, long long b) { return ((a - b) % mod + mod) % mod; }   long long mul(long long a, long long b) { return (a * b) % mod; }   const int maxn = 205;   long long dp[maxn][maxn][maxn][2], ans;   int n;   string s;   int getmaxlen(kmp& KMP, char t, int mptr) {     if (mptr == s.size()) mptr = KMP.lps[mptr - 1];     while (s[mptr] != t && mptr != 0) mptr = KMP.lps[mptr - 1];     if (s[mptr] == t) mptr++;     return mptr;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> s;     dp[0][0][0][0] = 1;     kmp KMP(s);     for (int i = 0; i < (2 * n); i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k < (2 * n) && k <= s.size(); k++) {           for (int l = 0; l < 2; l++) {             if (dp[i][j][k][l] == 0) continue;             int mptr = getmaxlen(KMP,  ( , k);             int matched = l;             if (mptr == s.size()) matched = 1;             dp[i + 1][j + 1][mptr][matched] =                 add(dp[i + 1][j + 1][mptr][matched], dp[i][j][k][l]);             if (j != 0) {               mptr = getmaxlen(KMP,  ) , k);               matched = l;               if (mptr == s.size()) matched = 1;               dp[i + 1][j - 1][mptr][matched] =                   add(dp[i + 1][j - 1][mptr][matched], dp[i][j][k][l]);             }           }         }       }     }     for (int i = 0; i <= s.size(); i++) ans = add(ans, dp[2 * n][0][i][1]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const long double INF = 1e100;   const long double eps = 1e-12;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   int n, p, q;   long double a[MAXN], b[MAXN];   long double check(long double x) {     long double y = 1;     for (int i = 1; i <= n; i++) chkmin(y, (1.0 - x * a[i]) / b[i]);     return x * p + y * q;   }   int main() {     read(n), read(p), read(q);     long double l = 0, r = INF;     for (int i = 1; i <= n; i++) {       read(a[i]), read(b[i]);       chkmin(r, 1.0 / a[i]);     }     while (l + eps < r) {       long double ml = (2 * l + r) / 3, mr = (l + 2 * r) / 3;       if (check(ml) > check(mr))         r = mr;       else         l = ml;     }     printf( %.10Lf n , check((l + r) / 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       double l, r;       cin >> l >> r;       if (l > r / 2) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


// In the name of Allah.   // We re nothing and you re everything.   // Ya Ali!      #include <bits/stdc++.h>      using namespace std;   typedef long long ll;   const int MAX_N = 1e5 + 14, MAX_K = 40;   int n, k;      struct XorKeeper {       int a[MAX_K]{};          XorKeeper operator^(const XorKeeper &o) {           XorKeeper ret;           for (int i = 0; i < 2 * k; ++i) {               ret.a[i] = a[i] ^ o.a[i];           }           return ret;       }          XorKeeper &operator^=(const XorKeeper &o) {           return *this = *this ^ o;       }          XorKeeper next() const {           XorKeeper ret = *this;           rotate(ret.a, ret.a + 2 * k - 1, ret.a + 2 * k);           return ret;       }          int get_ans() {           return accumulate(a + k, a + 2 * k, 0, [](int x, int y) { return x ^ y; });       }   } down[MAX_N], up[MAX_N];      vector<int> g[MAX_N];   int a[MAX_N];      void dfs_down(int v = 0, int p = -1) {       down[v].a[0] = a[v];       for (auto u : g[v])           if (u != p) {               dfs_down(u, v);               down[v] ^= down[u].next();           }   }      void dfs_up(int v = 0, int p = -1) {       for (auto u : g[v])           if (u != p) {               up[u] = (up[v] ^ down[v] ^ down[u].next()).next();               dfs_up(u, v);           }   }      int main() {       ios::sync_with_stdio(0), cin.tie(0);       cin >> n >> k;       for (int i = 0; i < n - 1; ++i) {           int v, u;           cin >> v >> u;           v--, u--;           g[v].push_back(u);           g[u].push_back(v);       }       for (int i = 0; i < n; ++i) {           cin >> a[i];       }       dfs_down();       dfs_up();       for (int i = 0; i < n; ++i) {           cout << bool(down[i].get_ans() ^ up[i].get_ans()) <<    ;       }       cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   namespace hjt {   template <typename A, typename B>   std::ostream &operator<<(std::ostream &o, const std::pair<A, B> &x) {     return o <<  (  << x.first <<  ,  << x.second <<  ) ;   }   }  // namespace hjt   using namespace hjt;   const double eps = 1e-7;   const double PI = acos(-1);   const int MOD = 998244353;   const int INF = 0x3f3f3f3f;   const int N = 3e5 + 7;   int n;   int a[N], b[N], dp[N];   pair<int, int> path[N];   set<int> st;   vector<int> ans;   void update(int &x, int y) {     if (x == -1 || y < x) x = y;   }   inline void solve() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> b[i];     st.clear();     for (int i = 0; i <= n + 1; ++i) {       dp[i] = -1;       st.insert(i);     }     queue<int> q;     dp[n] = 0;     q.push(n);     while (q.size()) {       int u = q.front();       q.pop();       while (true) {         int x = *st.lower_bound(u - a[u]);         if (x > u) break;         st.erase(x);         int v = x + b[x];         if (dp[v] == -1 || dp[u] + 1 < dp[v]) {           dp[v] = dp[u] + 1;           path[v] = {u, x};           q.push(v);         }       }     }     if (dp[0] == -1) {       cout <<  -1 n ;       return;     }     ans.clear();     for (int i = 0; i != n; i = path[i].first) {       ans.emplace_back(path[i].second);     }     reverse(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (int &i : ans) cout << i <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T = 1;     for (int t = 1; t <= T; ++t) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, s, f, h, co = 0, sum, savesum, res, re, savere;     cin >> n;     long long a[n + 1];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     cin >> s >> f;     h = f - s;     queue<long long> qu;     i = 1;     sum = 0;     savesum = 0;     res = 1;     for (i = 1; i <= h; i++) {       qu.push(a[i]);       sum += a[i];       savesum = sum;     }     re = s;     savere = s;     for (i = h + 1; i <= n; i++) {       sum += a[i] - qu.front();       qu.pop();       qu.push(a[i]);       if (sum > savesum) {         res = i - h + 1;         savesum = sum;         re = s - res + 1;         if (re < 1) re += n;         savere = re;       } else if (sum == savesum) {         res = i - h + 1;         savesum = sum;         re = s - res + 1;         if (re < 1) re += n;         if (savere > re) savere = re;       }     }     for (i = 1; i <= h; i++) {       sum += a[i] - qu.front();       qu.pop();       qu.push(a[i]);       if (sum > savesum) {         savesum = sum;         res = n - h + 1 + i;         re = s - res + 1;         if (re < 1) re += n;         savere = re;       } else if (sum == savesum) {         res = n - h + 1 + i;         re = s - res + 1;         if (re < 1) re += n;         if (savere > re) savere = re;       }     }     cout << savere;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> tr;   int n;   int mx_bits = 40;   int ind = 0;   long long xor_sum = 0;   long long ans;   vector<long long> v;   void insert_tr(long long num) {     int node = 0;     for (int i = (int)mx_bits; i >= (int)0; --i) {       bool bit = ((num >> i) & 1) > 0;       if (tr[node][bit] == -1) {         tr.push_back(vector<int>(2, -1));         ++ind;         tr[node][bit] = ind;       }       node = tr[node][bit];     }   }   long long query_tr(long long num) {     long long ret = 0;     int node = 0;     long long val = 1;     for (int i = (int)mx_bits; i >= (int)0; --i) {       bool bit = ((num >> i) & 1) > 0;       if (tr[node][1 - bit] != -1) {         ret += val << i;         node = tr[node][1 - bit];       } else         node = tr[node][bit];     }     return ret;   }   void solve() {     ans = xor_sum;     long long cur = 0;     insert_tr(cur);     for (int i = (int)0; i < (int)n; ++i) {       cur ^= v[i];       insert_tr(cur);       long long ret = query_tr(xor_sum ^ cur);       ans = max(ans, ret);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     tr.push_back(vector<int>(2, -1));     cin >> n;     v.resize(n);     for (int i = (int)0; i < (int)n; ++i) {       cin >> v[i];       xor_sum = xor_sum ^ v[i];     }     solve();     return 0;   }


#include <bits/stdc++.h>   using uiII = unsigned int long long;   using II = int long long;   using namespace std;   const II N = 0x3f3f3f3f3f3f3f;   int main() {     vector<pair<II, II>> v;     vector<pair<II, II>>::iterator it;     v.reserve(1000000);     II t, n, l, r, i(0);     for (cin >> t; i < t; i++) {       cin >> n;       v.push_back(make_pair(1, n));       bool x[2000][2000]{false};       for (II i = 0; i < n; i++) {         cin >> l >> r;         x[l][r] = true;       }       bool f = false;       for (II i = 0; i < v.size(); i++) {         for (II j = v[i].first; j <= v[i].second; j++) {           if (v[i].first == v[i].second) {             cout << v[i].first <<     << v[i].second <<     << v[i].first << endl;           }           if (j - v[i].first == 0) {             if (v[i].second - v[i].first >= 2) {               if (x[j + 1][v[i].second] == true) {                 cout << v[i].first <<     << v[i].second <<     << j << endl;                 v.push_back(make_pair(j + 1, v[i].second));               }               continue;             }             if (v[i].second - v[i].first == 1) {               if (x[v[i].second][v[i].second] == true) {                 cout << v[i].first <<     << v[i].second <<     << j << endl;                 v.push_back(make_pair(v[i].second, v[i].second));               }               continue;             }           }           if (j - v[i].second == 0) {             if (j - v[i].first >= 2) {               if (x[v[i].first][v[i].second - 1] == true) {                 cout << v[i].first <<     << v[i].second <<     << j << endl;                 v.push_back(make_pair(v[i].first, v[i].second - 1));               }               continue;             }             if (j - v[i].first == 1) {               if (x[v[i].first][v[i].first] == true) {                 cout << v[i].first <<     << v[i].second <<     << j << endl;                 v.push_back(make_pair(v[i].first, v[i].first));               }               continue;             }           }           if (j != v[i].first && j != v[i].second) {             if (j - v[i].first == 1) {               if (x[v[i].first][v[i].first] == true) {                 if (x[j + 1][v[i].second] == true) {                   cout << v[i].first <<     << v[i].second <<     << j << endl;                   v.push_back(make_pair(v[i].first, v[i].first));                   v.push_back(make_pair(j + 1, v[i].second));                   break;                 }               }               continue;             }             if (v[i].second - j == 1) {               if (x[v[i].first][j - 1] == true) {                 if (x[v[i].second][v[i].second] == true) {                   cout << v[i].first <<     << v[i].second <<     << j << endl;                   v.push_back(make_pair(v[i].second, v[i].second));                   v.push_back(make_pair(v[i].first, j - 1));                   break;                 }               }               continue;             } else {               if (x[v[i].first][j - 1] == true) {                 if (x[j + 1][v[i].second] == true) {                   cout << v[i].first <<     << v[i].second <<     << j << endl;                   v.push_back(make_pair(v[i].first, j - 1));                   v.push_back(make_pair(j + 1, v[i].second));                   break;                 }               }               continue;             }           }         }       }       v.clear();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t-- > 0) {       long long int n, k, can = 0;       cin >> n >> k;       can += n / k;       can = can * k;       if (can < n) {         if (n - can < k / 2)           can += n - can;         else           can += k / 2;       }       cout << can << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int MAXN = 30005;   int lst[MAXN], N;   bool ok(vector<int> &v) {     if ((int)v.size() <= 2) return true;     for (int i = (int)v.size() - 2; i >= max(1, (int)v.size() - 5); i--)       if (v[i + 1] - v[i] != v[1] - v[0]) return false;     return true;   }   bool check(vector<int> &a, vector<int> &b, int n) {     if ((int)a.size() < 2) {       b.push_back(lst[n]);       if (!ok(b)) {         b.erase(b.end() - 1);         a.push_back(lst[n]);       }     } else if ((int)b.size() < 2) {       a.push_back(lst[n]);       if (!ok(a)) {         a.erase(a.end() - 1);         b.push_back(lst[n]);       }     } else {       a.push_back(lst[n]);       if (!ok(a)) {         a.erase(a.end() - 1);         b.push_back(lst[n]);       }     }     return ok(a) && ok(b);   }   int main() {     cin >> N;     for (int i = 0; i < N; i++) cin >> lst[i];     int sz = min(6, N);     vector<int> x, y;     for (int mask = 0; mask < (1 << sz); mask++) {       vector<int> a, b;       for (int i = 0; i < sz; i++) {         if (mask & (1 << i))           a.push_back(lst[i]);         else           b.push_back(lst[i]);       }       if (!ok(a) || !ok(b)) continue;       bool k = true;       for (int i = sz; i < N; i++) {         if (!check(a, b, i)) {           k = false;           break;         }       }       if (k) {         x = a, y = b;         break;       }     }     if ((int)x.size() == 0 && (int)y.size() > 0) {       x.push_back(y[(int)y.size() - 1]);       y.erase(y.end() - 1);     } else if ((int)y.size() == 0 && (int)x.size() > 0) {       y.push_back(x[(int)x.size() - 1]);       x.erase(x.end() - 1);     }     if ((int)x.size() == 0 && (int)y.size() == 0) {       cout <<  No solution  << endl;       return 0;     }     for (int i = 0; i < (int)x.size(); i++) cout << x[i] <<    ;     cout << endl;     for (int i = 0; i < (int)y.size(); i++) cout << y[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   const int INF = 0x7fffffff;   const long long int LNF = 0x7fffffffffffffff;   using namespace std;   int ac[26], az[26];   char aa[105], bb[105];   int main() {     int i, k, nn, kk = 0, len1, len2, s;     scanf( %d , &nn);     getchar();     while (kk < nn) {       gets(aa);       gets(bb);       len1 = strlen(aa);       len2 = strlen(bb);       memset(az, 0, sizeof(az));       k = 0;       while (k < len1) {         az[aa[k] -  a ]++;         k++;       }       k = 0;       s = 1;       while (k + len1 <= len2) {         memset(ac, 0, sizeof(ac));         i = 0;         while (i < len1) {           ac[bb[k + i] -  a ]++;           i++;         }         i = 0;         s = 0;         while (i < 26) {           if (ac[i] != az[i]) {             s = 1;             break;           }           i++;         }         if (s == 0) {           break;         }         k++;       }       if (s == 0) {         printf( YES n );       } else {         printf( NO n );       }       kk++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, c;     cin >> n >> t >> c;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int count = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       if (arr[i] <= t) {         count++;         if (i == n - 1) {           ans += max(0, count - c + 1);         }       } else {         ans += max(0, count - c + 1);         count = 0;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native )   using namespace std;   const long long inf = 1e9 + 5;   struct Node {     Node *l = 0, *r = 0;     long long lo, hi, mset = inf, madd = 0, val = 0, smol = inf;     Node(int lo, int hi) : lo(lo), hi(hi) {}     Node(vector<long long>& v, int lo, int hi) : lo(lo), hi(hi) {       if (lo + 1 < hi) {         int mid = lo + (hi - lo) / 2;         l = new Node(v, lo, mid);         r = new Node(v, mid, hi);         val = l->val + r->val;         smol = min(l->smol, r->smol);       } else         val = v[lo], smol = v[lo];     }     long long query(int L, int R) {       if (R <= lo || hi <= L) return 0;       if (L <= lo && hi <= R) return val;       push();       return l->query(L, R) + r->query(L, R);     }     int find(long long v) {       if (smol > v) return hi;       if (lo + 1 == hi) return lo;       if (mset <= v) return lo;       if (l->smol <= v) return l->find(v);       return r->find(v);     }     void set(int L, int R, int x) {       if (R <= lo || hi <= L) return;       if (L <= lo && hi <= R)         mset = x, val = (hi - lo) * x, smol = x, madd = 0;       else {         push(), l->set(L, R, x), r->set(L, R, x);         val = l->val + r->val;         smol = min(l->smol, r->smol);       }     }     void push() {       if (!l) {         int mid = lo + (hi - lo) / 2;         l = new Node(lo, mid);         r = new Node(mid, hi);       }       if (mset != inf) l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf;     }   };   int n, q;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     vector<long long> l(n, 0);     for (int i = 0; i < n; i++) {       long long v;       cin >> v;       l[i] = v;     }     Node seg = Node(l, 0, n);     for (int it = 0; it < q; it++) {       long long y;       int t, x;       cin >> t >> x >> y;       x -= 1;       if (t == 1) {         int left = seg.find(y);         if (x + 1 > left) {           seg.set(left, x + 1, y);         }       } else {         int out = 0;         x = max(x, seg.find(y));         while (x < n) {           long long dist = y / seg.query(x, x + 1);           int lo = min((long long)n - 1, x + dist - 1);           y -= seg.query(x, lo + 1);           out += (lo - x + 1);           x = max(lo + 1, seg.find(y));         }         cout << out <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int conversion(string p) {     int o;     o = atoi(p.c_str());     return o;   }   string toString(int h) {     stringstream ss;     ss << h;     return ss.str();   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }   long long toi(string p) {     long long x;     istringstream in(p);     in >> x;     return x;   }   long long square(long long n) { return n * n; }   long long fastexp(long long base, long long power) {     if (power == 0)       return 1LL;     else if (power % 2 == 0)       return square(fastexp(base, power / 2));     else       return base * (fastexp(base, power - 1));   }   bool is_prime(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   int logba(int a, int b) { return log(a) / log(b); }   int rd(double d) {     int x = (int)((double)d + 0.5);     return x;   }   vector<pair<int, int> > W, B, Q;   char lab[8][8];   bool go(int x, int y, int id) {     if (id == 0) {       for (int i = x - 1; i >= 0; i--) {         if (lab[i][y] !=  . ) return false;       }     } else {       for (int i = x + 1; i < 8; i++) {         if (lab[i][y] !=  . ) return false;       }     }     return true;   }   int main() {     int res = 0, x, y;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> lab[i][j];         if (lab[i][j] ==  W ) W.push_back(make_pair(i, j));         if (lab[i][j] ==  B ) B.push_back(make_pair(i, j));       }     }     for (int i = 0; i < W.size(); i++) {       x = W[i].first;       y = W[i].second;       if (go(x, y, 0)) Q.push_back(make_pair(x, 0));     }     for (int i = 0; i < B.size(); i++) {       x = B[i].first;       y = B[i].second;       if (go(x, y, 1)) Q.push_back(make_pair(7 - x, 1));     }     sort(Q.begin(), Q.end());     if (Q[0].second == 0)       cout <<  A  << endl;     else       cout <<  B  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long LINF = 2e16;   const int magic = 348;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   struct fastio {     static const int S = 1e7;     char rbuf[S + 48], wbuf[S + 48];     int rpos, wpos, len;     fastio() { rpos = len = wpos = 0; }     inline char Getchar() {       if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin);       if (!len) return EOF;       return rbuf[rpos++];     }     template <class T>     inline void Get(T &first) {       char ch;       bool f;       T res;       while (!isdigit(ch = Getchar()) && ch !=  - ) {       }       if (ch ==  - )         f = false, res = 0;       else         f = true, res = ch -  0 ;       while (isdigit(ch = Getchar())) res = res * 10 + ch -  0 ;       first = (f ? res : -res);     }     inline void getstring(char *s) {       char ch;       while ((ch = Getchar()) <= 32) {       }       for (; ch > 32; ch = Getchar()) *s++ = ch;       *s =   0 ;     }     inline void flush() {       fwrite(wbuf, 1, wpos, stdout);       fflush(stdout);       wpos = 0;     }     inline void Writechar(char ch) {       if (wpos == S) flush();       wbuf[wpos++] = ch;     }     template <class T>     inline void Print(T first, char ch) {       char s[20];       int pt = 0;       if (first == 0)         s[++pt] =  0 ;       else {         if (first < 0) Writechar( - ), first = -first;         while (first) s[++pt] =  0  + first % 10, first /= 10;       }       while (pt) Writechar(s[pt--]);       Writechar(ch);     }     inline void printstring(char *s) {       int pt = 1;       while (s[pt] !=   0 ) Writechar(s[pt++]);     }   } io;   template <typename T>   inline void check_max(T &first, T cmp) {     first = max(first, cmp);   }   template <typename T>   inline void check_min(T &first, T cmp) {     first = min(first, cmp);   }   template <typename T>   inline T myabs(T first) {     return first >= 0 ? first : -first;   }   const int MAXN = 1e5;   inline int add(int first) {     if (first >= MOD) first -= MOD;     return first;   }   inline int sub(int first) {     if (first < 0) first += MOD;     return first;   }   inline int quick_pow(int first, int second) {     int res = 1;     while (second) {       if (second & 1) res = (1ll * res * first) % MOD, second--;       first = (1ll * first * first) % MOD;       second >>= 1;     }     return res;   }   int inv[MAXN + 48], fac[MAXN + 48];   inline void init_inv() {     fac[0] = 1;     for (register int i = 1; i <= MAXN; i++)       fac[i] = (1ll * fac[i - 1] * i) % MOD;     inv[MAXN] = quick_pow(fac[MAXN], MOD - 2);     for (register int i = MAXN - 1; i >= 0; i--)       inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD;   }   inline int C(int first, int second) {     if (first < second || first < 0 || second < 0) return 0;     return 1ll * fac[first] * inv[second] % MOD * inv[first - second] % MOD;   }   inline int split(int first, int second) {     if (!second) {       return first == 0;     }     return C(first + second - 1, second - 1);   }   inline int calc(int c[2][2]) {     if (c[0][1] - c[1][0] < 0 || c[0][1] - c[1][0] > 1) return 0;     return 1ll * split(c[0][0], c[1][0] + 1) * split(c[1][1], c[0][1]) % MOD;   }   int c[2][2], cc[2][2], n;   char A[MAXN + 48], B[MAXN + 48];   inline int solve(int c[2][2], char *s) {     int len = strlen(s + 1);     if (len == 1 && s[1] ==  0 ) return 0;     if (len < n) return 0;     if (len > n)       for (register int i = n; i >= 1; i--) s[i] =  1 ;     char last =  1 ;     int res = 0, i;     for (i = n - 1; i >= 1; i--)       if (s[i] ==  1 ) {         if (c[last -  0 ][0]) {           c[last -  0 ][0]--;           res = add(res + calc(c));           c[last -  0 ][0]++;         }         if (!c[last -  0 ][1]) break;         c[last -  0 ][1]--;         last =  1 ;       } else {         if (!c[last -  0 ][0]) break;         c[last -  0 ][0]--;         last =  0 ;       }     if (!i) res = add(res + 1);     return res;   }   inline void Minus() {     int len = strlen(A + 1), pt = 1;     while (A[pt] ==  0 ) A[pt] =  1 , pt++;     A[pt] =  0 ;     while (len >= 1 && A[len] ==  0 ) len--;     if (!len) len++;     A[len + 1] =   0 ;   }   int main() {     init_inv();     io.getstring(A + 1);     io.getstring(B + 1);     int lena = strlen(A + 1), lenb = strlen(B + 1);     reverse(A + 1, A + lena + 1);     reverse(B + 1, B + lenb + 1);     io.Get(c[0][0]);     io.Get(c[0][1]);     io.Get(c[1][0]);     io.Get(c[1][1]);     Minus();     n = c[0][0] + c[0][1] + c[1][0] + c[1][1] + 1;     for (register int i = 0; i <= 1; i++)       for (register int j = 0; j <= 1; j++) cc[i][j] = c[i][j];     int resb = solve(c, B), resa = solve(cc, A);     io.Print(sub(resb - resa),   n );     io.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int TOUR = 1 << 18, MOD = 1e9 + 7;   int Add(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     return a;   }   int Sub(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   int Mul(int a, int b) { return (int)(((long long)a * b) % MOD); }   int Inverz(int x) {     int ret = 1;     for (int e = MOD - 2; e; e /= 2, x = Mul(x, x))       if (e & 1) ret = Mul(ret, x);     return ret;   }   int Div(int a, int b) { return Mul(a, Inverz(b)); }   struct node {     int sum, mul, prop;   };   struct tour {     node t[2 * TOUR];     tour() {       for (int i = 0; i < 2 * TOUR; i++) {         t[i].sum = 0;         t[i].mul = t[i].prop = 1;       }     }     void propagiraj(int x) {       for (int i = 2 * x; i <= 2 * x + 1; i++) {         t[i].sum = Mul(t[i].sum, t[x].prop);         t[i].mul = Mul(t[i].mul, t[x].prop);         t[i].prop = Mul(t[i].prop, t[x].prop);       }       t[x].prop = 1;     }     void stavi_sum(int pos, int lo, int hi, int ind, int val) {       if (lo >= ind + 1 || hi <= ind) return;       if (lo == ind && hi == ind + 1) {         t[pos].sum = Mul(t[pos].mul, val);         return;       }       propagiraj(pos);       stavi_sum(2 * pos + 0, lo, (lo + hi) / 2, ind, val);       stavi_sum(2 * pos + 1, (lo + hi) / 2, hi, ind, val);       t[pos].sum = Add(t[2 * pos].sum, t[2 * pos + 1].sum);     }     void stavi_sum(int pos, int val) { stavi_sum(1, 0, TOUR, pos, val); }     void stavi_mul(int pos, int lo, int hi, int begin, int end, int val) {       if (lo >= end || hi <= begin) return;       if (lo >= begin && hi <= end) {         t[pos].sum = Mul(t[pos].sum, val);         t[pos].mul = Mul(t[pos].mul, val);         t[pos].prop = Mul(t[pos].prop, val);         return;       }       propagiraj(pos);       stavi_mul(2 * pos + 0, lo, (lo + hi) / 2, begin, end, val);       stavi_mul(2 * pos + 1, (lo + hi) / 2, hi, begin, end, val);       t[pos].sum = Add(t[2 * pos].sum, t[2 * pos + 1].sum);     }     void stavi_mul(int begin, int end, int val) {       stavi_mul(1, 0, TOUR, begin, end, val);     }     int query_sum(int pos, int lo, int hi, int begin, int end) {       if (lo >= end || hi <= begin) return 0;       if (lo >= begin && hi <= end) return t[pos].sum;       propagiraj(pos);       return Add(query_sum(2 * pos + 0, lo, (lo + hi) / 2, begin, end),                  query_sum(2 * pos + 1, (lo + hi) / 2, hi, begin, end));     }     int query_sum(int begin, int end) {       return query_sum(1, 0, TOUR, begin, end);     }     int query_mul(int pos, int lo, int hi, int ind) {       if (lo >= ind + 1 || hi <= ind) return 0;       if (lo == ind && hi == ind + 1) return t[pos].mul;       propagiraj(pos);       return Add(query_mul(2 * pos + 0, lo, (lo + hi) / 2, ind),                  query_mul(2 * pos + 1, (lo + hi) / 2, hi, ind));     }     int query_mul(int ind) { return query_mul(1, 0, TOUR, ind); }   } T;   vector<int> V[TOUR];   pair<int, int> ev[TOUR];   int disc[TOUR], fin[TOUR], vr = 1;   int pocval[TOUR], par[TOUR];   int brdjec[TOUR];   void Dfs(int node) {     disc[node] = vr++;     for (int i = 0; i < (int)V[node].size(); i++) Dfs(V[node][i]);     fin[node] = vr;   }   void Dodaj(int node) {     int p = par[node];     T.stavi_mul(disc[p], fin[p], Mul(Inverz(brdjec[p]), brdjec[p] + 1));     T.stavi_sum(disc[node], pocval[node]);     brdjec[p]++;   }   int Query(int node) {     int ret = T.query_sum(disc[node], fin[node]);     if (node) ret = Div(ret, T.query_mul(disc[par[node]]));     return ret;   }   int main() {     int brq, brcv = 1;     scanf( %d%d , &pocval[0], &brq);     for (int i = 0; i < brq; i++) {       int st;       scanf( %d , &st);       if (st == 2) {         int tmp;         scanf( %d , &tmp);         tmp--;         ev[i] = pair<int, int>(st, tmp);       } else {         scanf( %d%d , &par[brcv], &pocval[brcv]);         par[brcv]--;         V[par[brcv]].push_back(brcv);         ev[i] = pair<int, int>(st, brcv++);       }     }     Dfs(0);     T.stavi_sum(disc[0], pocval[0]);     for (int i = 0; i < brcv; i++) brdjec[i] = 1;     for (int i = 0; i < brq; i++) {       if (ev[i].first == 1)         Dodaj(ev[i].second);       else         printf( %d n , Query(ev[i].second));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 16;   int n, m;   int d[2][N];   int get_n(int x, int n) {     int tmp = 3 << (n * 2);     tmp = x & tmp;     tmp >>= n * 2;     return tmp;   }   int set_n(int x, int n, int y) {     int tmp = 3 << (n * 2);     x = x & (~tmp);     y <<= (n * 2);     x |= y;     return x;   }   void update(int &x, int y) {     if (x == -1 || x < y) x = y;   }   int solve() {     int i, j, k;     int t = 0;     memset(d, -1, sizeof(d));     d[0][0] = 0;     int tot = 1 << (n * 2 + 2);     for (i = 0; i < m; ++i) {       for (j = 0; j < n; ++j) {         memset(d[1 - t], -1, sizeof(d[1 - t]));         for (k = 0; k < tot; ++k) {           if (d[t][k] == -1) continue;           int t0 = get_n(k, j);           int t1 = get_n(k, j + 1);           int st = set_n(k, j, 1);           st = set_n(st, j + 1, 1);           update(d[1 - t][st], d[t][k]);           if (t0 > 0) {             st = set_n(k, j - 1, 2);             st = set_n(st, j, 0);             st = set_n(st, j + 1, 0);             update(d[1 - t][st], d[t][k] + 1);             if (t0 == 1) {               st = set_n(k, j - 1, 0);               st = set_n(st, j, 2);               st = set_n(st, j + 1, 2);               update(d[1 - t][st], d[t][k] + 1);             }           }           if (t1 > 0) {             st = set_n(k, j, 0);             st = set_n(st, j + 1, 0);             update(d[1 - t][st], d[t][k] + 1);             if (t1 == 1) {               st = set_n(k, j, 2);               st = set_n(st, j + 1, 2);               update(d[1 - t][st], d[t][k] + 1);             }           }           if (t0 == 1 && t1 == 1) {             st = set_n(k, j - 1, 0);             st = set_n(st, j, 2);             st = set_n(st, j + 1, 2);             update(d[1 - t][st], d[t][k] + 2);           }         }         t = 1 - t;       }       memset(d[1 - t], -1, sizeof(d[1 - t]));       for (k = 0; k < tot; ++k) {         int st = set_n(k, n, 0);         st <<= 2;         update(d[1 - t][st], d[t][k]);       }       t = 1 - t;     }     int ans = -1;     for (k = 0; k < tot; ++k) {       update(ans, d[t][k]);     }     return ans;   }   int main() {     int i, j, k, t, nc = 0;     while (scanf( %d%d , &n, &m) != EOF) {       if (n > m) swap(n, m);       int ans = solve();       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<long double> ans;   vector<int> sum;   void dfs0(int x) {     sum[x] = 1;     for (int to : g[x]) {       dfs0(to);       sum[x] += sum[to];     }   }   void dfs(int x, long double f) {     ans[x] = f;     int s = sum[x] - 1;     for (int to : g[x]) {       dfs(to, ((s - sum[to]) / 2.0) + f + 1.0);     }   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     g.resize(n);     ans.resize(n);     sum.resize(n);     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       g[p].push_back(i);     }     dfs0(0);     dfs(0, 1.0);     cout << fixed << setprecision(8);     for (long double x : ans) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long k;   long long f(int a[], int l, int r) {     long long m = 0;     for (int i = 0; i < n; i++)       if (a[i] < l)         m += l - a[i];       else if (a[i] > r)         m += a[i] - r;     return m;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     cin >> n >> k;     int a[n];     for (int& i : a) cin >> i;     int l = 0, r = 1e9;     while (l <= r) {       int m = (l + r) / 2;       int lt = 0, rt = 1e9;       while (rt - lt > 1) {         int mt = (lt + rt) / 2;         if (f(a, mt, mt + m) < f(a, mt + 1, mt + 1 + m))           rt = mt;         else           lt = mt;       }       if (f(a, rt, rt + m) <= k)         r = m - 1;       else         l = m + 1;     }     cout << l <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct tree {     int C;     int root;     int number_of_branches;     int *branches;   };   int main() {     int c, p, n, i, j, r = 0;     int start, D[100000] = {0}, k = 0;     struct tree A[100000];     cin >> n;     for (i = 0; i < n; i++) {       A[i].branches = new int[1];       A[i].number_of_branches = 0;     }     for (i = 0; i < n; i++) {       cin >> p >> c;       if (p == -1) {         start = i;       } else {         A[i].C = c;         A[i].root = p - 1;         A[p - 1].branches[A[p - 1].number_of_branches] = i;         A[p - 1].number_of_branches++;         A[p - 1].branches =             (int *)realloc(A[p - 1].branches,                            (A[p - 1].number_of_branches) * sizeof(struct tree));       }     }     for (i = 0; i < n; i++) {       if (A[i].C == 1) {         k = 0;         for (j = 0; j < A[i].number_of_branches; j++) {           if (A[A[i].branches[j]].C == 1) {             k++;           }         }         if ((k == A[i].number_of_branches) ||             (k == 0 && k == A[i].number_of_branches)) {           cout << i + 1 <<    ;           r = 1;         }       }     }     if (r == 0) {       cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int n, k;   long long int a[N];   long long int month[2 * N];   long long int sum(long long int days) { return (days * (days + 1) / 2); }   void solve() {     cin >> n >> k;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       month[i] = a[i];       month[n + i] = a[i];     }     long long int j = 0;     long long int hugs = 0, days = 0, best = 0;     for (long long int i = 0; i < 2 * n; i++) {       hugs += sum(month[i]);       days += month[i];       while (days > k) {         days -= month[j];         hugs -= sum(month[j]);         j++;       }       long long int curr = hugs;       if (j > 0) {         long long int skips = month[j - 1] + days - k;         curr += sum(month[j - 1]) - sum(skips);       }       best = max(best, curr);     }     cout << best <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define ld long double   #define pb push_back   #define VI vector<int>   #define VL vector<ll>   #define MX vector<VI >   #define all(x) x.begin(), x.end()   #define IOS cin.tie(0)->sync_with_stdio(0)      using namespace std;      ll gcd(ll a, ll b){    if(!b) return a;    return gcd(b, a%b);   }      int main(){       int n, m;    cin >> n >> m;       VL a(n), b(m);    for(ll &i : a) cin >> i;    for(ll &i : b) cin >> i;       sort(all(a));       ll t = 0;    for(int i=1; i<n; i++) t = gcd(a[i]-a[i-1], t);       for(ll &i : b) cout << gcd(i+a[0], t) <<    ;    cout <<   n ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   inline int readInt() {     int x;     scanf( %d , &x);     return x;   }   int a[55];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (int)n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     if (a[0] == a[n / 2])       printf( Bob n );     else       printf( Alice n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int INF = 0x7fffffff;   const double PI = acos(-1.0);   const int MAX = 100005;   const int MOD = 1000000007;   inline bool isEq(double a, double b) { return abs(a - b) < EPS; }   inline bool isEq(double a, double b, double eps) { return abs(a - b) < eps; }   inline double toRad(double deg) { return deg * PI / 180; }   inline double toDeg(double rad) { return rad * 180 / PI; }   class Timer {     clock_t start;     string name;       public:     Timer() {       name =   ;       start = clock();     }     Timer(string s) {       name = s;       start = clock();     }     ~Timer() {       fprintf(stderr,  %s: %.3gs n , name.c_str(),               1.0 * (clock() - start) / CLOCKS_PER_SEC);     }   };   double cross(complex<double> &a, complex<double> &b) {     return imag((conj(a) * b));   }   double perpendicularDist(double x1, double y1, double x2, double y2, double x3,                            double y3) {     complex<double> A = complex<double>(x2 - x1, y2 - y1);     complex<double> B = complex<double>(x3 - x1, y3 - y1);     return cross(A, B) / abs(A);   }   double getYaxiyIntersection(complex<double> start, complex<double> a) {     double lo = 0, hi = 1000000000, dist = 0;     int cnt = 300;     a = a / abs(a);     complex<double> en;     while (cnt--) {       dist = (lo + hi) / 2;       en = start + a * dist;       if (start.real() * en.real() > 0)         lo = dist;       else         hi = dist;     }     return en.imag();   }   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     double y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     double lowxw = 0, highxw = xb, xw, y, rxb;     int cnt = 300;     double yweff = yw - r;     bool found = false;     complex<double> A;     while (cnt--) {       xw = (lowxw + highxw) / 2;       rxb = xw - (xb - xw);       A = complex<double>(xw - rxb, yweff - yb);       if (rxb > 0) A = -A;       y = getYaxiyIntersection(complex<double>(rxb, yb), A);       if (y - r >= y1 && y2 >= y + r &&           perpendicularDist(0, y, xw, yweff, 0, y2) >= r) {         found = true;         break;       } else {         if (y - r < y1)           highxw = xw;         else           lowxw = xw;       }     }     if (found)       cout << fixed << setprecision(10) << xw << endl;     else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, n, m, a[200000], q, l, p, k, c[200000], b[200000], j, ans;   string s[200000], ss, s1;   int main() {     ios_base::sync_with_stdio(0);     ans = 1000000007;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (i = 1; i <= n / 2; i++) {       ans = min(ans, a[n / 2 + i] - a[i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int &i : a) {       cin >> i;     }     vector<vector<bool> > match(n + 1, vector<bool>(n + 1, false));     for (int i = 0, x, y; i < m; i++) {       cin >> x >> y;       x--;       y--;       match[x][y] = true;       match[y][x] = true;     }     int ans = INT_MAX;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         for (int z = j + 1; z < n; z++) {           if (match[i][j] && match[j][z] && match[z][i]) {             ans = min(ans, a[i] + a[j] + a[z]);           }         }       }     }     if (ans == INT_MAX) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, ans;   priority_queue<long long> q;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       q.push(x);       if (q.top() > x) {         ans += q.top() - x;         q.pop();         q.push(x);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int *p = new int[100010];     fill(p, p + 100010, -1000000000);     for (int i = 0; i < n; ++i) {       int x, y;       int res = 0;       scanf( %d%d , &x, &y);       int q = (int)sqrt((double)x);       for (int j = 1; j <= q; ++j) {         if (x % j == 0) {           if (p[j] < i - y) ++res;           p[j] = i;           if (p[x / j] < i - y) ++res;           p[x / j] = i;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     if (y == 0) return 1;     long long int d = power(x, y / 2) % 1000000007;     if (y % 2 == 0)       return (d * d) % 1000000007;     else       return (((x * d) % 1000000007) * d) % 1000000007;   }   long long int divmod(long long int num, long long int den) {     return (num * (power(den, 1000000007 - 2))) % 1000000007;   }   int mobius[100001];   int mob(int x) {     int cnt = 0;     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) {         x = x / i;         cnt++;       }       if (x % i == 0) {         return 0;       }     }     if (x > 1) {       cnt++;     }     if (cnt & 1) return -1;     return 1;   }   long long int nmod(long long int x) {     return (x % 1000000007 + 1000000007) % 1000000007;   }   long long int fact[100001];   long long int ncr(long long int n, long long int r) {     long long int num = fact[n];     long long int den = fact[r] * fact[n - r];     den %= 1000000007;     return divmod(num, den);   }   long long int calc(long long int n, long long int k, long long int x) {     n = n / x;     n = n - k;     if (n < 0) return 0;     if (n == 0) return 1;     return ncr(n + k - 1, k - 1);   }   void solve() {     int n, k;     scanf( %d , &n);     scanf( %d , &k);     vector<int> f;     for (int i = 1; i * i <= n; i++) {       if (i * i == n) {         f.push_back(i);         break;       }       if (n % i == 0) {         f.push_back(i);         f.push_back(n / i);       }     }     long long int ans = 0;     for (int i = 0; i < f.size(); i++) {       if (mobius[f[i]] == 0) continue;       ans = ans + mobius[f[i]] * calc(n, k, f[i]);     }     ans = nmod(ans);     printf( %lld n , ans);   }   int main() {     fact[0] = 1;     for (int i = 1; i <= 100000; i++) fact[i] = (i * fact[i - 1]) % 1000000007;     mobius[1] = 1;     for (int i = 2; i <= 100000; i++) {       mobius[i] = mob(i);     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) solve();   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch -  0 );       ch = getchar();     }     return f * x;   }   const int maxn = 1e5 + 10, mod = 1e9 + 7, limit = 1e7;   int n, num[2][maxn], k[2];   int f[2][maxn], cnt[2][maxn], ans[2][maxn];   queue<pair<int, int> > q;   int main() {     n = read();     memset(ans, 127, sizeof(ans));     k[0] = read();     for (int i = 1; i <= k[0]; i++) num[0][i - 1] = read();     k[1] = read();     for (int i = 1; i <= k[1]; i++) num[1][i - 1] = read();     ans[0][0] = ans[1][0] = 0;     q.push(make_pair(0, 0));     q.push(make_pair(1, 0));     while (q.size()) {       while (q.size()) {         int x = q.front().first, y = q.front().second;         q.pop();         for (int i = 0; i < k[x ^ 1]; i++) {           int x1 = x ^ 1, y1 = (y - num[x1][i] + n) % n;           if (!ans[x1][y1] || ans[x1][y1] == 1) continue;           ans[x1][y1] = 1;           for (int j = 0; j < k[x]; j++) {             int y2 = (y1 - num[x][j] + n) % n;             ++cnt[x][y2];           }         }       }       for (int i = 0; i < 2; i++)         for (int j = 0; j < n; j++) {           if (!ans[i][j] || ans[i][j] == 1) continue;           if (cnt[i][j] == k[i]) {             ans[i][j] = 0;             q.push(make_pair(i, j));           }         }     }     for (int i = 0; i < 2; i++) {       for (int j = 1; j < n; j++) {         if (ans[i][j] == 0)           printf( Lose  );         else if (ans[i][j] == 1)           printf( Win  );         else           printf( Loop  );       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     while (cin >> n) {       stack<int> st;       bool ov = true;       int ovs = 0;       int res = 0;       int spd = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &(a));         if (a == 1) {           scanf( %d , &(b));           spd = b;         } else if (a == 2) {           res += ovs;           ovs = 0;         } else if (a == 3) {           scanf( %d , &(b));           st.push(b);         } else if (a == 4) {           ovs = 0;         } else if (a == 5) {           while (!st.empty()) st.pop();         } else if (a == 6) {           ovs++;         }         while (!st.empty() && st.top() < spd) {           st.pop();           res++;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using db = double;   using str = string;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pd = pair<db, db>;   using vi = vector<int>;   using vb = vector<bool>;   using vl = vector<ll>;   using vd = vector<db>;   using vs = vector<str>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpd = vector<pd>;   template <class T>   using V = vector<T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const ll INF = 1e18;   const ld PI = acos((ld)-1);   const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   constexpr int pct(int x) { return __builtin_popcount(x); }   constexpr int bits(int x) { return 31 - __builtin_clz(x); }   ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }   ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U first) {     hi++;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T, class U>   T lstTrue(T lo, T hi, U first) {     lo--;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo + 1) / 2;       first(mid) ? lo = mid : hi = mid - 1;     }     return lo;   }   template <class T>   void remDup(vector<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   template <class T, class U>   void erase(T& t, const U& u) {     auto it = t.find(u);     assert(it != end(t));     t.erase(u);   }   template <class T>   void re(complex<T>& c);   template <class T, class U>   void re(pair<T, U>& p);   template <class T>   void re(vector<T>& v);   template <class T, size_t SZ>   void re(AR<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(db& d) {     str t;     re(t);     d = stod(t);   }   void re(ld& d) {     str t;     re(t);     d = stold(t);   }   template <class T, class... U>   void re(T& t, U&... u) {     re(t);     re(u...);   }   template <class T>   void re(complex<T>& c) {     T a, b;     re(a, b);     c = {a, b};   }   template <class T, class U>   void re(pair<T, U>& p) {     re(p.first, p.second);   }   template <class T>   void re(vector<T>& x) {     for (auto& a : x) re(a);   }   template <class T, size_t SZ>   void re(AR<T, SZ>& x) {     for (auto& a : x) re(a);   }   str to_string(char c) { return str(1, c); }   str to_string(const char* second) { return (str)second; }   str to_string(str second) { return second; }   str to_string(bool b) { return to_string((int)b); }   template <class T>   str to_string(complex<T> c) {     stringstream ss;     ss << c;     return ss.str();   }   str to_string(vector<bool> v) {     str res =  { ;     for (int i = (0); i < ((int)(v).size()); ++i) res += char( 0  + v[i]);     res +=  } ;     return res;   }   template <size_t SZ>   str to_string(bitset<SZ> b) {     str res =   ;     for (int i = (0); i < (SZ); ++i) res += char( 0  + b[i]);     return res;   }   template <class T, class U>   str to_string(pair<T, U> p);   template <class T>   str to_string(T v) {     bool fst = 1;     str res =   ;     for (const auto& x : v) {       if (!fst) res +=    ;       fst = 0;       res += to_string(x);     }     return res;   }   template <class T, class U>   str to_string(pair<T, U> p) {     return to_string(p.first) +     + to_string(p.second);   }   template <class T>   void pr(T x) {     cout << to_string(x);   }   template <class T, class... U>   void pr(const T& t, const U&... u) {     pr(t);     pr(u...);   }   void ps() { pr(  n ); }   template <class T, class... U>   void ps(const T& t, const U&... u) {     pr(t);     if (sizeof...(u)) pr(   );     ps(u...);   }   void DBG() { cerr <<  ]  << endl; }   template <class T, class... U>   void DBG(const T& t, const U&... u) {     cerr << to_string(t);     if (sizeof...(u)) cerr <<  ,  ;     DBG(u...);   }   void setIn(str second) { freopen(second.c_str(),  r , stdin); }   void setOut(str second) { freopen(second.c_str(),  w , stdout); }   void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }   void setIO(str second =   ) {     unsyncIO();     if ((int)(second).size()) {       setIn(second +  .in ), setOut(second +  .out );     }   }   int main() {     setIO();     int l;     cin >> l;     ll num = 0;     vl v;     v.push_back(1);     for (int a = (0); a < (l); ++a) {       string second;       cin >> second;       if (second ==  add ) {         num += v.back();         if (num > 4294967295) {           cout <<  OVERFLOW!!!  << endl;           return 0;         }       } else if (second ==  for ) {         int k;         cin >> k;         v.push_back(min(4294967296LL, k * v.back()));       } else         v.pop_back();     }     cout << num << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int cmax = 1e5 + 8;   int n;   int cnt[cmax];   vector<pair<int, int> > l(cmax);   long long psum[cmax];   int d[202];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i].first, cnt[l[i].first]++;     for (int i = 1; i <= n; i++) cin >> l[i].second;     sort(l.begin() + 1, l.begin() + n + 1);     for (int i = 1; i <= n; i++) psum[i] = psum[i - 1] + l[i].second;     long long ans = 284488937875784;     for (int i = 1; i <= n; i++) {       int p = i;       while (i < n and l[i].first == l[i + 1].first) i++;       long long t = psum[n] - psum[i];       int x = max(0, i - 2 * cnt[l[i].first] + 1);       for (int j = 1; j <= 200 and x > 0; j++) {         int u = min(x, d[j]);         x -= u;         t += (long long)u * j;       }       ans = min(ans, t);       for (int k = p; k <= i; k++) d[l[k].second]++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   typename T::value_type arr_sum(const T& v, int n) {     typename T::value_type sum = 0;     for (int i = 0; i < n; ++i) sum += v[i];     return sum;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int main() {     int n, m;     cin >> n >> m;     vector<int> left;     vector<int> right(n);     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       left.push_back(t);     }     sort(left.begin(), left.end());     for (int i = 0, j = n / 2; i < n; ++i, j = (j + 1) % n) {       right[i] = left[j];     }     int res = 0;     for (int i = 0; i < n; ++i) {       if (left[i] == right[i]) {         ++res;       }     }     cout << n - res <<   n ;     for (int i = 0; i < n; ++i) {       cout << left[i] <<     << right[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long min(long long a, long long b) { return (a < b) ? a : b; }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long fp(long long a, long long b) {     if (b == 0) return 1;     long long x = fp(a, b / 2);     x = (x * x) % mod;     if (b & 1) x = (x * a) % mod;     return x;   }   const long long N = 2000;   long long bit[4 * N];   void update(long long id, long long l, long long r, long long point,               long long val) {     if (point < l || point > r) return;     if (l == r) {       bit[id] += val;       return;     }     long long mid = (l + r) / 2;     update(2 * id, l, mid, point, val);     update(2 * id + 1, mid + 1, r, point, val);     bit[id] = bit[2 * id] + bit[2 * id + 1];   }   long long get(long long id, long long l, long long r, long long point) {     if (point < l) {       return 0;     }     if (r <= point) {       return bit[id];     }     long long mid = (l + r) / 2;     return get(2 * id, l, mid, point) + get(2 * id + 1, mid + 1, r, point);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     map<long long, vector<array<long long, 2>>> mp;     for (long long i = 1; i <= n; i++) {       long long sm = 0;       for (long long j = i; j <= n; j++) {         sm += a[j];         mp[sm].push_back({i, j});       }     }     vector<array<long long, 2>> ans;     for (auto i : mp) {       vector<array<long long, 2>> tmp;       sort(i.second.begin(), i.second.end());       for (long long j = 0; j < i.second.size(); j++) {         update(1, 1, n, i.second[j][1], 1);       }       long long st = 1;       for (long long j = 0; j < i.second.size(); j++) {         update(1, 1, n, i.second[j][1], -1);         if (i.second[j][0] < st) continue;         if (i.second[j][0] == i.second[j][1]) {           tmp.push_back(i.second[j]);           st = i.second[j][1] + 1;         } else {           long long x =               get(1, 1, n, i.second[j][1] - 1) - get(1, 1, n, i.second[j][0]);           if (x > 0) {             continue;           } else {             tmp.push_back(i.second[j]);             st = i.second[j][1] + 1;           }         }       }       if (tmp.size() > ans.size()) ans = tmp;     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i[0] <<     << i[1] <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     std::cout << std::setprecision(6) << std::fixed;     double tux;     cin >> tux;     double foo = 0, bar = 0, baz = 0, quz = 1;     for (; tux != 0.0; tux--) {       double pur;       cin >> pur;       foo = foo + pur;       bar = bar + 1;       if ((foo * quz) >= (bar * baz)) {         baz = foo;         quz = bar;       }     }     cout << (double)(baz / quz);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, d, t, v;   double tim[200000];   double jisuan(double a, double vmax, double s) {     double t = (vmax) / a;     if (0.5 * a * t * t > s)       return sqrt(s * 2 / a);     else       return t + (s - 0.5 * a * t * t) / vmax;   }   int main() {     scanf( %d%d%d , &n, &a, &d);     scanf( %d%d , &t, &v);     tim[1] = t + jisuan(a, v, d);     for (int i = 2; i <= n; ++i) {       scanf( %d%d , &t, &v);       tim[i] = t + jisuan(a, v, d);       if (tim[i] < tim[i - 1]) tim[i] = tim[i - 1];     }     for (int i = 1; i <= n; ++i) printf( %.10lf n , tim[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 7;   vector<int> G[MAXN];   int pic[1007][1007], vis[MAXN], siz[MAXN];   unordered_map<int, int> mp;   int tot, val[MAXN];   int fa[MAXN], sz;   int findfa(int x) {     if (x == fa[x]) return x;     return fa[x] = findfa(fa[x]);   }   void unite(int x, int y, bool flag = 1) {     int u = findfa(x), v = findfa(y);     if (u == v) return;     fa[u] = v;     if (flag) siz[v] += siz[u];     sz++;   }   int main() {     int N, M;     scanf( %d %d , &N, &M);     for (int i = (int)1; i <= (int)N; i++) fa[i] = i, siz[i] = 1;     for (int i = (int)1; i <= (int)M; i++) {       int u, v;       scanf( %d %d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     int mn = 1e9, id = 0;     for (int i = (int)1; i <= (int)N; i++) {       if (G[i].size() < mn) {         mn = G[i].size();         id = i;       }     }     for (int v : G[id]) vis[v] = 1;     vis[id] = 1;     for (int i = (int)1; i <= (int)N; i++)       if (vis[i] == 0) unite(id, i);     for (int i = (int)1; i <= (int)N; i++) {       if (findfa(i) == i) {         mp[i] = ++tot;         val[tot] = i;       }     }     for (int u = (int)1; u <= (int)N; u++) {       for (int v : G[u]) {         int f1 = mp[findfa(u)];         int f2 = mp[findfa(v)];         if (f1 == f2) continue;         pic[f1][f2]++;       }     }     for (int i = (int)1; i <= (int)tot; i++) {       for (int j = (int)i + 1; j <= (int)tot; j++) {         if (1LL * siz[val[i]] * siz[val[j]] != pic[i][j]) {           unite(val[i], val[j], 0);         }       }     }     int ans = N - sz - 1;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     long long int i, a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[0] == a[n - 1] && a[0] == 0) {       while (k--) cout << 0 << endl;     }     long long int b[n], ct = 0;     for (i = 0; i < n; i++) {       while (i < n && a[i] == a[i + 1]) i++;       b[ct++] = a[i];     }     i = 0;     long long int cnt = 0;     while (k--) {       while (b[i] == 0) i++;       if (i >= ct)         cout << 0 << endl;       else         cout << b[i] - cnt << endl;       cnt = b[i];       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   class C_ {};   template <typename T>   C_& operator<<(C_& __m, const T& __s) {     if (!1) cerr <<   E[91m  << __s <<   E[0m ;     return __m;   }   C_ merr;   struct __s {     __s() {       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       merr <<  Execution time:   << (double)clock() / CLOCKS_PER_SEC <<   s. n ;     }   } __S;   char A[2222][2222];   bool u[2222][2222];   int n, m;   bool check(int x, int y) {     int i = x, j = y;     int cnt = 0;     if (!(0 <= x && x < n) || !(0 <= y && y < m) || A[x][y] !=  . ) return false;     cnt += (i == 0 || A[i - 1][j] !=  . );     cnt += (j == 0 || A[i][j - 1] !=  . );     cnt += (i == n - 1 || A[i + 1][j] !=  . );     cnt += (j == m - 1 || A[i][j + 1] !=  . );     return !u[i][j] && cnt == 3;   }   void add(queue<pair<int, int> >& Q, int x, int y) {     if (check(x, y)) {       Q.push(make_pair(x, y));       u[x][y] = 1;     }   }   int main() {     int left = 0;     queue<pair<int, int> > Q;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         A[i][j] = s[j];         if (A[i][j] ==  . ) {           left++;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (A[i][j] !=  . ) continue;         add(Q, i, j);       }     }     while (Q.size()) {       int x = Q.front().first, y = Q.front().second;       Q.pop();       if (A[x][y] !=  . ) continue;       if (x != n - 1 && A[x + 1][y] ==  . ) {         A[x][y] =  ^ ;         A[x + 1][y] =  v ;         left -= 2;         add(Q, x - 1, y);         add(Q, x, y - 1);         add(Q, x, y + 1);         add(Q, x + 1, y - 1);         add(Q, x + 1, y + 1);         add(Q, x + 2, y);       } else if (x != 0 && A[x - 1][y] ==  . ) {         A[x - 1][y] =  ^ ;         A[x][y] =  v ;         left -= 2;         add(Q, x - 2, y);         add(Q, x, y - 1);         add(Q, x, y + 1);         add(Q, x - 1, y - 1);         add(Q, x - 1, y + 1);         add(Q, x + 1, y);       } else if (y != m - 1 && A[x][y + 1] ==  . ) {         A[x][y] =  < ;         A[x][y + 1] =  > ;         left -= 2;         add(Q, x, y - 1);         add(Q, x - 1, y);         add(Q, x - 1, y + 1);         add(Q, x + 1, y);         add(Q, x + 1, y + 1);         add(Q, x + 2, y);       } else if (y != 0 && A[x][y - 1] ==  . ) {         A[x][y - 1] =  < ;         A[x][y] =  > ;         left -= 2;         add(Q, x, y - 2);         add(Q, x - 1, y);         add(Q, x - 1, y - 1);         add(Q, x + 1, y);         add(Q, x + 1, y - 1);         add(Q, x + 2, y);       }       for (int dx = -3; dx <= 3; dx++) {         for (int dy = -3; dy <= 3; dy++) {           add(Q, x + dx, y + dy);         }       }     }     if (left != 0) {       cout <<  Not unique  <<   n ;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << A[i][j];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, m, h[N], mn[N], par[N], t, num, op, uo, ra;   vector<int> adj[N];   set<int> answer, qtr;   bool finish, q[N], vis[N];   struct edge {     int u, v;   } ed[N];   void output() {     if ((int)answer.size() == n) {       cout <<  NO  <<   n ;       finish = true;       return;     }     cout <<  YES  <<   n  << n - answer.size() <<   n ;     for (int i = 0; i < n; i++)       if (!answer.count(i)) cout << i + 1 <<    ;     cout <<   n ;     finish = true;   }   void haveDeg3() {     for (int i = 0; i < n && !finish; i++)       if (!(adj[i].size() % 3)) answer.insert(i), output();   }   void oneEdge() {     for (int i = 0; i < m; i++) {       if (adj[ed[i].v].size() % 3 == 1 && adj[ed[i].u].size() % 3 == 1) {         answer.insert(ed[i].u), answer.insert(ed[i].v), output();         return;       }     }   }   void check(int x) {     vector<int> po;     for (auto v : adj[x])       if (adj[v].size() % 3 == 1) {         q[x] = true;         po.push_back(v);       }     if (po.size() > 1) {       answer.insert(po[0]), answer.insert(po[1]), answer.insert(x), output();       return;     }   }   void Vgraph() {     for (int i = 0; i < n && !finish; i++)       if (adj[i].size() % 3 == 2) check(i);   }   void findCycle(int x) {     vis[x] = true;     for (auto v : adj[x])       if (adj[v].size() % 3 == 2 && v != par[x]) {         if (!vis[v])           h[v] = h[x] + 1, mn[v] = h[v], par[v] = x;         else {           if (mn[x] != h[x])             mn[x] = max(mn[x], h[v]);           else             mn[x] = min(mn[x], h[v]);         }       }     if (mn[x] < h[x] - 1) {       int z = mn[x];       while (h[x] != z) {         answer.insert(x), x = par[x];       }       answer.insert(x), output();       return;     }     for (auto v : adj[x])       if (!vis[v] && !finish && adj[v].size() % 3 == 2) {         findCycle(v);       }   }   void cycle() {     for (int i = 0; i < n && !finish; i++)       if (adj[i].size() % 3 == 2 && !vis[i]) {         findCycle(i);       }   }   void dfs(int x) {     if (finish) return;     vis[x] = true;     if (q[x]) {       if (!qtr.count(x)) {         for (auto v : adj[x])           if (adj[v].size() % 3 == 1) answer.insert(v);         while (x != op) answer.insert(x), x = par[x];         answer.insert(op);         output();       } else if (par[x] != op) {         vis[x] = false;         return;       }     }     for (auto v : adj[x])       if (!vis[v] && adj[v].size() % 3 == 2) par[v] = x, dfs(v);   }   void dfsqt(int x) {     if (finish) return;     vis[x] = true;     if (q[x] && par[x] != op) {       num++;       while (x != op) {         for (auto v : adj[x]) vis[v] = true;         answer.insert(x), x = par[x];       }       if (num > 1) {         answer.insert(x);         output();       }       dfsqt(op);     }     for (auto v : adj[x])       if (!vis[v] && adj[v].size() % 3 == 2) par[v] = x, dfsqt(v);   }   void another() {     num = 0;     for (int i = 0; i < n; i++) par[i] = 0, vis[i] = false;     for (int i = 0; i < n && !finish; i++)       if (adj[i].size() % 3 == 1) {         qtr.clear();         for (auto v : adj[i]) qtr.insert(v);         dfs(op = i);         if (!finish) {           for (int i = 0; i < n; i++) par[i] = 0, vis[i] = false;           dfsqt(op);         }         return;       }   }   void readInput() {     answer.clear();     finish = false;     cin >> n >> m;     for (int i = 0; i < n; i++)       adj[i].clear(), h[i] = mn[i] = par[i] = 0, vis[i] = q[i] = false;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       ed[i].u = --x, ed[i].v = --y;       adj[x].push_back(y);       adj[y].push_back(x);     }   }   void solve() {     haveDeg3();     if (finish) return;     oneEdge();     if (finish) return;     Vgraph();     if (finish) return;     cycle();     if (finish) return;     another();     if (finish) return;     cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) readInput(), solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       int arr[n], brr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       sort(arr, arr + n, greater<int>());       for (int j = 0; j < n; j++) {         cin >> brr[j];       }       sort(brr, brr + n, greater<int>());       int ans = 0;       int i = 0, j = 0;       int cnt = n;       while (cnt--) {         if (arr[i] >= brr[j])           ans += arr[i], i += 1;         else if (k > 0)           ans += brr[j], j += 1, k -= 1;         else           ans += arr[i], i += 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, c0, c1, h;     cin >> n >> c0 >> c1 >> h;     string s;     cin >> s;     int ans = 0;     for (char ch : s) {       if (ch ==  0 ) {         ans += min(c0, c1 + h);       } else {         ans += min(c1, c0 + h);       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> AL[100005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d , &u);       scanf( %d , &v);       AL[u].push_back(v);       AL[v].push_back(u);     }     long long int l = 0;     int fl = 0;     for (int i = 1; i <= n; i++) {       if (AL[i].size() == 2) {         fl = 1;       }     }     if (fl == 0) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define ull unsigned long long      #define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i];   #define invec(ar,n)for(int i  =0 ; i<n;i++){int temp;cin>>temp;ar.push_back(temp);}   #define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i]   #define out(ar,n)     for(int i=0;i<n;i++)     cout<<ar[i]<<   ;     cout<<endl;   #define swap(a,b)    int t = a;     a = b;     b = t;   #define print(val) cout<<val<<endl;   #define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val   #define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)   #define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i])   #define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i])   #define fori(i,a,b) for(ll i=a;i<b;++i)   #define all(ar) ar.begin(),ar.end()   using namespace std;   typedef pair<ll,ll> pll;   typedef pair<int,int> pii;   typedef vector<vector<int>> vvi;   const ll mod = 1e9 + 7;      int main(){       int t;cin>>t;       while(t--){          int n;cin>>n;          string s;cin>>s;          vector<int> ar,ans;          fori(i,0,n){              ar.push_back(s[i]- 0 );             }           ans.push_back(1);          int c = ar[0]+1;             fori(i,1,n){              if(c==2){                  if(ar[i]==1){                      ans.push_back(0);                      c = 1;                  }                  else {                      ans.push_back(1);                      c = 1;                  }              }              else if(c==1){                  if(ar[i]==1){                      ans.push_back(1);                       c = 2;                  }                  else {ans.push_back(0);c = 0;}              }              else {                  if(ar[i]==0){                      ans.push_back(1);                      c = 1;                  }                  else {                      ans.push_back(1);                      c = 2;                  }              }          }          fori(i,0,n){              cout<<ans[i];          }          cout<<endl;       }   }