#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t, n, i, j; n   string second; n   cin >> t; n   while (t--) { n     cin >> second; n     vector<int> v1, v2; n     n = second.length(); n     for (i = 0; i < n; i++) { n       if ((second[i] -  0 ) % 2) n         v1.push_back(second[i] -  0 ); n       else n         v2.push_back(second[i] -  0 ); n     } n     string ans =   ; n     i = j = 0; n     while (i < v1.size() && j < v2.size()) { n       if (v1[i] < v2[j]) n         ans += char(v1[i++] +  0 ); n       else n         ans += char(v2[j++] +  0 ); n     } n     while (i < v1.size()) ans += char(v1[i++] +  0 ); n     while (j < v2.size()) ans += char(v2[j++] +  0 ); n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char question[4][100]; n int len[4]; n int main() { n   for (int i = 0; i < 4; i++) { n     cin >> question[i]; n     string s = question[i]; n     len[i] = s.size() - 2; n   } n   int count_ = 0; n   int index = -1; n   for (int i = 0; i < 4; i++) { n     int n; n     n = len[0]; n     len[0] = len[i]; n     len[i] = n; n     if (((len[0] <= (len[1] / 2)) && (len[0] <= (len[2] / 2)) && n          (len[0] <= (len[3] / 2))) || n         ((len[0] >= (2 * len[1])) && (len[0] >= (2 * len[2])) && n          (len[0] >= (2 * len[3])))) { n       index = i; n       count_++; n     } n   } n   if (count_ == 1) { n     cout << (char)(index + 65); n   } else { n     cout <<  C ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[1005], y[1005], r[1005], level[1005]; n long long sum[1005]; n vector<pair<int, int> > X[1005]; n void dfs(int node, int l) { n   level[node] = l; n   int i; n   for (i = 0; i < X[node].size(); i++) { n     if (level[X[node][i].second] <= level[node]) dfs(X[node][i].second, l + 1); n   } n } n bool check(int ind1, int ind2) { n   if (r[ind1] < r[ind2]) return false; n   long double dist = (long long)(x[ind1] - x[ind2]) * (x[ind1] - x[ind2]) + n                      (long long)(y[ind1] - y[ind2]) * (y[ind1] - y[ind2]); n   dist = sqrtl(dist); n   if (dist + r[ind2] > (long double)r[ind1]) return false; n   return true; n } n int main() { n   int n; n   scanf( %d , &n); n   int i; n   for (i = 1; i <= n; i++) { n     scanf( %d%d%d , x + i, y + i, r + i); n   } n   for (i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (check(i, j)) X[i].push_back(make_pair(r[j], j)); n       if (check(j, i)) X[j].push_back(make_pair(r[i], i)); n     } n   } n   for (i = 1; i <= n; i++) { n     sort(X[i].begin(), X[i].end()); n     reverse(X[i].begin(), X[i].end()); n   } n   for (i = 1; i <= n; i++) { n     if (!level[i]) dfs(i, 1); n   } n   for (i = 1; i <= n; i++) { n     sum[level[i]] += (long long)r[i] * r[i]; n   } n   int cnt = 0; n   long long ans = 0; n   for (i = 1; i <= 1000; i++) { n     if (i <= 2) { n       ans += sum[i]; n       continue; n     } n     if (i % 2) n       ans -= sum[i]; n     else n       ans += sum[i]; n   } n   long double p = (long double)(3.14159265359) * ans; n   cout.precision(9); n   cout << fixed << p; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(const int a, const int b) { return a > b; } n long long binpow(long long a, long long n, int mod) { n   long long res = 1; n   while (n) n     if (n & 1) { n       res *= a; n       res %= mod; n       --n; n     } else { n       a *= a; n       a %= mod; n       n >>= 1; n     } n   if (res == 0) res = mod; n   return res; n } n vector<int> prefix_function(string s) { n   int n = (int)s.length(); n   vector<int> pi(n); n   for (int i = 1; i < n; ++i) { n     int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) ++j; n     pi[i] = j; n   } n   return pi; n } n string ss1, ss2; n int main() { n   vector<int> a = prefix_function( a#aa ); n   int n; n   cin >> n; n   string s, str; n   vector<string> v; n   for (int i = 0; i < n; i++) { n     cin >> str; n     v.push_back(str); n   } n   for (int i =  a ; i <=  z ; i++) { n     bool bb = true; n     ss1 = i; n     string f = ss1; n     for (int ii = 0; ii < n && bb == true; ii++) { n       vector<int> a = prefix_function(f +  #  + v[ii]); n       for (int jj = f.length() + 1; jj < a.size() && bb == true; jj++) { n         if (a[jj] == f.size()) { n           bb = false; n           break; n         } n       } n     } n     if (bb == true) { n       cout << f; n       return 0; n     } n   } n   for (int i =  a ; i <=  z ; i++) { n     for (int j =  a ; j <=  z ; j++) { n       bool bb = true; n       ss1 = i; n       ss2 = j; n       string f = ss1.append(ss2); n       for (int ii = 0; ii < n && bb == true; ii++) { n         vector<int> a = prefix_function(f +  #  + v[ii]); n         for (int jj = f.length() + 1; jj < a.size() && bb == true; jj++) { n           if (a[jj] == f.size()) { n             bb = false; n             break; n           } n         } n       } n       if (bb == true) { n         cout << f; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct l { n   int index; n   int depth; n   int color; n }; n int a[100001]; n struct BFSearch { n   vector<pair<l, vector<int> > > adj; n   queue<l> k; n   void clear1() { n     for (int i = 0; i < adj.size(); i++) { n       adj[i].first.color = 0; n       adj[i].first.depth = -1; n     } n   } n   void bfs(int i) { n     if (i > adj.size() - 1) return; n     l o; n     int p; n     adj[i].first.color = 0; n     adj[i].first.depth = 0; n     k.push(adj[i].first); n     while (k.size() != 0) { n       o = k.front(); n       k.pop(); n       for (int i = 0; i < adj[o.index].second.size(); i++) { n         p = adj[o.index].second[i]; n         if (adj[p].first.color == 0) { n           adj[p].first.color = 1; n           adj[p].first.depth = o.depth + 1; n           k.push(adj[p].first); n         } n       } n       adj[o.index].first.color = 2; n     } n   } n }; n int main() { n   pair<l, vector<int> > op; n   BFSearch k; n   int n, temp; n   l p; n   p.depth = -1; n   p.color = 0; n   cin >> n; n   vector<int> x; n   for (int i = 0; i < n; i++) { n     op.second = x; n     p.index = i; n     op.first = p; n     k.adj.push_back(op); n   } n   for (int i = 1; i < n; i++) { n     cin >> temp; n     k.adj[i].second.push_back(temp - 1); n     k.adj[temp - 1].second.push_back(i); n   } n   k.bfs(0); n   for (int i = 0; i < k.adj.size(); i++) { n     a[k.adj[i].first.depth]++; n   } n   long sum = 0; n   for (int i = 0; i < k.adj.size(); i++) { n     if (a[i] % 2 == 1) sum += 1; n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n char s[N]; n int main(void) { n   int n; n   while (cin >> n) { n     int cntl = 0; n     int cntr = 0; n     int cntq = 0; n     getchar(); n     n = abs(n); n     scanf( %s , s); n     if (s[0] ==  )  || s[n - 1] ==  ( ) { n       puts( :( ); n       continue; n     } n     if (n == 0) { n       puts( :( ); n       continue; n     } n     if (n & 1) { n       puts( :( ); n       continue; n     } n     for (int i = 0; i < n; i++) { n       if (s[i] ==  ) ) n         cntr++; n       else if (s[i] ==  ( ) n         cntl++; n       else n         cntq++; n     } n     if (abs(cntl - cntr) > cntq) { n       puts( :( ); n       continue; n     } n     int needl = n / 2 - cntl; n     for (int i = 0; i < n; i++) { n       if (needl) { n         if (s[i] ==  ? ) { n           s[i] =  ( ; n           needl--; n         } n       } else { n         if (s[i] ==  ? ) s[i] =  ) ; n       } n     } n     bool flg = false; n     cntl = 0; n     cntr = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  ) ) n         cntr++; n       else n         cntl++; n       if ((i + 1) % 2 == 0) { n         if (cntr == cntl && i + 1 != n) { n           flg = true; n           break; n         } n       } n     } n     if (flg == false) { n       printf( %s n , s); n     } else n       puts( :( ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n FILE* in = stdin; n FILE* out = stdout; n const int MAX = 100001; n int n, k; n int a[MAX]; n int color[256]; n void solve() { n   memset(color, -1, sizeof(color)); n   color[0] = 0; n   for (int i = 0; i < n; i++) { n     if (color[a[i]] != -1) continue; n     int left = -1; n     for (int c = 0;; c++) { n       if (color[a[i] - c] != -1) { n         left = a[i] - c; n         break; n       } n     } n     if (color[left] + k - 1 >= a[i]) { n       for (int c = left + 1; c <= a[i]; c++) color[c] = color[left]; n       continue; n     } n     int at = a[i]; n     if (at - k + 1 > left) { n       for (int c = at - k + 1; c <= at; c++) color[c] = at - k + 1; n       continue; n     } n     for (int c = left + 1; c <= a[i]; c++) color[c] = left + 1; n   } n   for (int i = 0; i < n; i++) n     fprintf(out,  %d%c , color[a[i]], i + 1 == n ?   n  :    ); n } n int main(void) { n   fscanf(in,  %d %d , &n, &k); n   for (int i = 0; i < n; i++) fscanf(in,  %d , &a[i]); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   set<char> s; n   char ch; n   int rep = 0; n   for (int i = 0; i < n; i++) { n     cin >> ch; n     if (s.find(ch) != s.end()) rep++; n     s.insert(ch); n   } n   if (26 - s.size() >= rep) n     cout << rep; n   else n     cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> p; n   vector<int> n; n   vector<int> z; n   int t; n   cin >> t; n   int x; n   for (int i = 0; i < t; i++) { n     cin >> x; n     if (x > 0) n       p.push_back(x); n     else if (x < 0) n       n.push_back(x); n     else n       z.push_back(x); n   } n   if (t == 1) n     cout << x; n   else if (z.size() == t) { n     for (int i = 0; i < z.size(); i++) cout << z[i] <<    ; n   } else if (z.size() + n.size() == t) { n     if (n.size() == 1) n       cout << 0; n     else { n       if (n.size() % 2 != 0) { n         sort(n.rbegin(), n.rend()); n         for (int i = 1; i < n.size(); i++) cout << n[i] <<    ; n       } else { n         for (int i = 0; i < n.size(); i++) cout << n[i] <<    ; n       } n     } n   } else if ((p.size() > 0 || p.size() == 0) && n              (n.size() > 0 || n.size() == 0)) { n     for (int i = 0; i < p.size(); i++) cout << p[i] <<    ; n     if (n.size() % 2 == 0) { n       for (int i = 0; i < n.size(); i++) cout << n[i] <<    ; n     } else { n       sort(n.rbegin(), n.rend()); n       for (int i = 1; i < n.size(); i++) cout << n[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t; n void solve() { n   while (t--) { n     long long int n, k, res = 0; n     cin >> n >> k; n     if (n < k) n       res = k - n; n     else if ((n - k) % 2 == 0 && n >= k) { n       res = 0; n     } else n       res = 1; n     cout << res <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], n, k; n bool cmp(int x, int y) { return x % 10 > y % 10; } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n, cmp); n   for (int i = 0; i < n; i++) { n     if (a[i] % 10 == 0 || k < 10 - a[i] % 10) break; n     k -= 10 - a[i] % 10; n     a[i] += 10 - a[i] % 10; n   } n   for (int i = 0; i < n; i++) { n     if (k < 10) break; n     int cpy = a[i]; n     a[i] = min(100, a[i] + k - k % 10); n     k -= (a[i] - cpy); n   } n   int ans = 0; n   for (int i = 0; i < n; i++) ans += a[i] / 10; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n const int N = 1e5 + 5; n int a[N]; n int b[N]; n int main() { n   ios_base::sync_with_stdio(false); n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     vector<int> ve1, ve2; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     for (int i = 0; i < n; i++) ve1.push_back(a[i]); n     for (int i = 0; i < n; i++) ve2.push_back(b[i]); n     sort(ve1.begin(), ve1.end()); n     sort(ve2.begin(), ve2.end()); n     multiset<pair<int, long long> > mse; n     bool res = true; n     for (int i = 0; i < (n + 1) / 2; i++) { n       int mn = min(a[i], a[n - i - 1]); n       int mx = max(a[i], a[n - i - 1]); n       mse.insert({mn, mx}); n     } n     for (int i = 0; i < (n + 1) / 2; i++) { n       int mn = min(b[i], b[n - i - 1]); n       int mx = max(b[i], b[n - i - 1]); n       pair<int, long long> x = {mn, mx}; n       if (mse.find(x) != mse.end()) { n         mse.erase(mse.find(x)); n       } else { n         res = false; n       } n     } n     if (res) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modexp(long long int a, long long int b) { n   long long int ret = 1; n   while (b) { n     if ((b & 1)) { n       ret *= a; n       ret %= 1000000007; n     } n     a *= a; n     a %= 1000000007; n     b >>= 1; n   } n   return ret; n } n long long int fact[200000]; n int main() { n   int n, k; n   long long int ret = 1; n   fact[0] = 1; n   int i; n   for (i = 1; i <= 1000; i++) { n     fact[i] = fact[i - 1] * i; n     fact[i] %= 1000000007; n   } n   scanf( %d %d , &n, &k); n   ret *= modexp(k, k - 1); n   ret %= 1000000007; n   ret *= modexp(n - k, n - k); n   ret %= 1000000007; n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long m; n long long from, to; n long long x, y; n int visit[2][1000010]; n int main() { n   std::cin >> m; n   int i, time; n   int cs[2], ci[2], targ[2]; n   for (i = 0; i < 2; ++i) { n     std::cin >> from >> to >> x >> y; n     time = 1; n     int cur = from; n     while (true) { n       if (visit[i][cur]) { n         cs[i] = time - visit[i][cur]; n         ci[i] = visit[i][cur]; n         break; n       } n       visit[i][cur] = time; n       cur = (cur * x + y) % m; n       ++time; n     } n     targ[i] = visit[i][to]; n   } n   if (targ[0] == 0 || targ[1] == 0) { n     std::cout << -1; n   } else { n     bool oncyc[2]; n     for (i = 0; i < 2; ++i) oncyc[i] = (targ[i] >= ci[i]); n     if (!oncyc[0] && !oncyc[1]) { n       if (targ[0] != targ[1]) n         std::cout << -1; n       else n         std::cout << targ[0] - 1; n     } else if (!oncyc[0]) { n       if (targ[0] >= targ[1] && !((targ[0] - targ[1]) % cs[1])) n         std::cout << targ[0] - 1; n       else n         std::cout << -1; n     } else if (!oncyc[1]) { n       if (targ[1] >= targ[0] && !((targ[1] - targ[0]) % cs[0])) n         std::cout << targ[1] - 1; n       else n         std::cout << -1; n     } else { n       long long cur = targ[0]; n       for (i = 0; i <= m + 1; ++i) { n         if (cur >= targ[1] && (cur - targ[1]) % cs[1] == 0) break; n         cur += cs[0]; n       } n       if (i <= m + 1) n         std::cout << cur - 1; n       else n         std::cout << -1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 150001; n int a[N], vis[N]; n int main() { n   int n; n   while (cin >> n) { n     for (int i = 1; i <= n; i++) cin >> a[i]; n     sort(a + 1, a + n + 1); n     memset(vis, 0, sizeof(vis)); n     int ans = 0; n     for (int i = 1; i <= n; i++) { n       if (vis[a[i] - 1] == 0 && a[i] != 1) n         vis[a[i] - 1] = 1, ans++; n       else if (vis[a[i]] == 0) n         vis[a[i]] = 1, ans++; n       else if (vis[a[i] + 1] == 0) n         vis[a[i] + 1] = 1, ans++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const string kStart = n      What are you doing at the end of the world? Are you busy? Will you save   n      us? ; n const string kPrefix =  What are you doing while sending   ; n const string kCenter =   ? Are you busy? Will you send   ; n const string kTail =   ? ; n const int64_t kMaxK = 1.0E18; n const int64_t kInf = numeric_limits<int64_t>::max(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int Q; n   cin >> Q; n   vector<int64_t> L; n   L.push_back(75); n   for (;;) { n     int64_t cand = 68 + 2 * L.back(); n     if (cand > kMaxK) { n       break; n     } n     L.push_back(cand); n   } n   string R; n   for (int q = 0; q < Q; ++q) { n     int N; n     int64_t K; n     cin >> N >> K; n     if (N < L.size()) { n       if (K > L[N]) { n         R +=  . ; n         continue; n       } n     } n     for (;;) { n       if (N == 0) { n         R += kStart[K - 1]; n         break; n       } n       if (K <= kPrefix.size()) { n         R += kPrefix[K - 1]; n         break; n       } n       int64_t prev_len = N - 1 < L.size() ? L[N - 1] : kInf; n       if (prev_len == kInf || K <= kPrefix.size() + prev_len) { n         --N; n         K -= kPrefix.size(); n         continue; n       } n       if (K <= kPrefix.size() + prev_len + kCenter.size()) { n         R += kCenter[K - kPrefix.size() - prev_len - 1]; n         break; n       } n       if (K <= kPrefix.size() + 2 * prev_len + kCenter.size()) { n         --N; n         K -= kPrefix.size() + kCenter.size() + prev_len; n         continue; n       } n       R += kTail[K - 2 * prev_len - kPrefix.size() - kCenter.size() - 1]; n       break; n     } n   } n   cout << R <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1000000000,1000000000 ) n using namespace std; n const long long inf = 1e18 + 7; n const long long mod = 1e9 + 7; n const double eps = 1e-9; n const double PI = 2 * acos(0.0); n const double E = 2.71828; n int f[1 << 24], sum[1 << 24], n, k, a[24], b[2]; n int main(void) { n   scanf( %d , &n); n   for (long long(i) = 0; (i) < (long long)(n); (i)++) scanf( %d , &a[i]); n   scanf( %d , &k); n   b[0] = b[1] = -1; n   for (long long(i) = 0; (i) < (long long)(k); (i)++) scanf( %d , &b[i]); n   f[0] = 1; n   for (long long(i) = 0; (i) < (long long)(1 << n); (i)++) { n     if (i) sum[i] = sum[i & (i - 1)] + a[__builtin_ctz(i)]; n     if (sum[i] == b[0] || sum[i] == b[1]) continue; n     for (long long j = i; j; j &= j - 1) { n       f[i] += f[i ^ (j & -j)]; n       if (f[i] >= mod) f[i] -= mod; n     } n   } n   printf( %d n , f[(1 << n) - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n struct node { n   int u, v, w, t; n } e[1000005], E[1000005]; n int cmp(node a, node b) { return a.w < b.w; } n struct Union_Find_Set { n   int top, stk[1000005], siz[1000005], tot, fa[1000005]; n   void init(int x) { n     tot = x; n     for (int i = 1; i <= x; i++) fa[i] = i, siz[i] = 1; n     return; n   } n   int find(int x) { n     while (x != fa[x]) x = fa[x]; n     return x; n   } n   void link(int x, int y) { n     int u = find(x), v = find(y); n     if (u == v) return; n     if (siz[u] < siz[v]) swap(u, v); n     tot -= (siz[u] & 1); n     tot -= (siz[v] & 1); n     siz[u] += siz[v]; n     fa[v] = u; n     tot += (siz[u] & 1); n     stk[++top] = v; n     return; n   } n   void cut() { n     int x = stk[top], u = find(x); n     --top; n     tot -= (siz[u] & 1); n     siz[u] -= siz[x]; n     fa[x] = x; n     tot += (siz[u] & 1); n     tot += (siz[x] & 1); n   } n } S; n int n, m, ans[1000005], id[1000005]; n void solve(int l, int r, int x, int y) { n   if (l > r) return; n   int mid = (l + r) >> 1, pre = S.top; n   for (int i = l; i <= mid; i++) n     if (id[i] < x) S.link(E[i].u, E[i].v); n   for (int i = x; i <= y; i++) { n     if (e[i].t <= mid) S.link(e[i].u, e[i].v); n     if (!S.tot) { n       ans[mid] = i; n       break; n     } n   } n   while (S.top > pre) S.cut(); n   if (!ans[mid]) { n     for (int i = l; i <= mid; i++) n       if (id[i] < x) S.link(E[i].u, E[i].v); n     solve(mid + 1, r, x, y); n     while (S.top > pre) S.cut(); n     return; n   } n   for (int i = l; i <= mid; i++) n     if (id[i] < x) S.link(E[i].u, E[i].v); n   solve(mid + 1, r, x, ans[mid]); n   while (S.top > pre) S.cut(); n   for (int i = x; i < ans[mid]; i++) n     if (e[i].t < l) S.link(e[i].u, e[i].v); n   solve(l, mid - 1, ans[mid], y); n   while (S.top > pre) S.cut(); n } n int main() { n   n = read(); n   m = read(); n   S.init(n); n   for (int i = 1; i <= m; i++) { n     e[i].u = read(); n     e[i].v = read(); n     e[i].w = read(); n     e[i].t = i; n   } n   for (int i = 1; i <= m; i++) E[i] = e[i]; n   sort(e + 1, e + 1 + m, cmp); n   for (int i = 1; i <= m; i++) id[e[i].t] = i; n   solve(1, m, 1, m); n   for (int i = 1; i <= m; i++) printf( %d n , ans[i] ? e[ans[i]].w : -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[30001]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cin >> arr[i]; n     } n     int dp1 = arr[1]; n     int dp2 = 0; n     bool fail = 0; n     for (int i = 2; i < n; i++) { n       arr[i] = arr[i] - dp2; n       if (arr[i] < 0) { n         fail = 1; n         break; n       } n       if (arr[i] > dp1) { n         arr[i] = arr[i] - dp1; n         dp2 = dp2 + arr[i]; n       } else { n         dp1 = arr[i]; n       } n     } n     if (dp2 > arr[n]) { n       fail = 1; n     } n     if (fail) { n       cout <<  NO  n            <<   n ; n     } else { n       cout <<  YES  n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k; n long long s[16], sum; n map<long long, int> id; n vector<long long> v; n bool vis[16]; n bool dp[1 << 15]; n vector<pair<int, int> > way[1 << 15]; n int pre[1 << 15]; n pair<int, int> ans[16]; n int main() { n   scanf( %d , &k); n   for (int i = 0; i < k; i++) { n     int n; n     scanf( %d , &n); n     while (n--) { n       int x; n       scanf( %d , &x); n       s[i] += x, sum += x; n       id[x] = i; n       v.push_back(x); n     } n   } n   if (sum % k) n     printf( No n ); n   else { n     sum /= k; n     for (auto x : v) { n       for (int i = 0; i < k; i++) vis[i] = false; n       long long now = x; n       int mask = 0; n       vector<pair<int, int> > opt; n       bool f = true; n       while (!vis[id[now]]) { n         vis[id[now]] = true; n         long long pre = now; n         now = sum - s[id[now]] + now; n         if (id.count(now) == 0) { n           f = false; n           break; n         } n         if (vis[id[now]] && now != x) { n           f = false; n           break; n         } n         mask |= 1 << id[pre]; n         opt.push_back(pair<int, int>(now, pre)); n       } n       if (f == true) way[mask] = opt; n     } n     dp[0] = 1; n     for (int i = 1; i < (1 << k); i++) { n       for (int j = i - 1; j != i; j = (j - 1) & i) { n         if (dp[j] && !way[i ^ j].empty()) { n           dp[i] = 1; n           pre[i] = j; n           break; n         } n       } n     } n     if (!dp[(1 << k) - 1]) n       printf( No n ); n     else { n       printf( Yes n ); n       int now = (1 << k) - 1; n       while (now) { n         int x = now ^ (pre[now]); n         for (auto p : way[x]) n           ans[id[p.first]] = pair<int, int>(p.first, id[p.second]); n         now = pre[now]; n       } n       for (int i = 0; i < k; i++) n         printf( %d %d n , ans[i].first, ans[i].second + 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool mark[100007] = {0}; n vector<pair<long long int, long long int> > adj[100007]; n vector<long long int> ans; n long long int d[100007]; n long long int par[100007]; n void dijkstra(long long int v) { n   d[v] = 0; n   long long int u; n   priority_queue<pair<long long int, long long int>, n                  vector<pair<long long int, long long int> >, n                  greater<pair<long long int, long long int> > > n       pq; n   pq.push(make_pair(d[v], v)); n   while (!pq.empty()) { n     u = pq.top().second; n     pq.pop(); n     if (mark[u]) continue; n     mark[u] = true; n     for (auto p : adj[u]) n       if (d[p.first] > d[u] + p.second) { n         par[p.first] = u; n         d[p.first] = d[u] + p.second; n         pq.push({d[p.first], p.first}); n       } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m; n   cin >> n >> m; n   for (long long int i = 1; i <= m; i++) { n     long long int a, b, w; n     cin >> a >> b >> w; n     adj[a].push_back(make_pair(b, w)); n     adj[b].push_back(make_pair(a, w)); n   } n   for (long long int i = 1; i <= n; i++) { n     d[i] = 100000000000000; n     par[i] = -1; n   } n   dijkstra(1); n   if (d[n] == 100000000000000) n     cout <<  -1  << endl; n   else { n     long long int x = n; n     while (x != 1) { n       ans.push_back(x); n       x = par[x]; n     } n     ans.push_back(1); n     reverse(ans.begin(), ans.end()); n     for (auto it : ans) cout << it <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn = 1e5 + 5; n const int inf = 1e9; n vector<int> adj[mxn]; n bool f1[mxn], f2[mxn]; n bool done; n int ask(char x, int y) { n   cout << x <<     << y << endl; n   int r; n   cin >> r; n   return r; n } n int dfs(int cur, int prev) { n   if (done) return -1; n   if (f1[cur]) { n     done = true; n     int x = ask( A , cur); n     if (f2[x]) return cur; n     return -1; n   } n   for (int u : adj[cur]) { n     if (u == prev) continue; n     int x = dfs(u, cur); n     if (done) return x; n   } n   return -1; n } n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     adj[i].clear(); n     f1[i] = false; n     f2[i] = false; n   } n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   int k1; n   cin >> k1; n   int x[k1]; n   for (int i = 0; i < k1; i++) { n     cin >> x[i]; n     f1[x[i]] = true; n   } n   int k2; n   cin >> k2; n   int y[k2]; n   for (int i = 0; i < k2; i++) { n     cin >> y[i]; n     f2[y[i]] = true; n   } n   done = false; n   int r = ask( B , y[0]); n   cout <<  C   << dfs(r, -1) << endl; n } n int main() { n   int t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char s[3]; n   cin >> s; n   int a; n   char b; n   b = s[0]; n   a = s[1]; n   if ((b ==  a  || b ==  h ) && (a ==  1  || a ==  8 )) n     cout << 3; n   else if ((b ==  a  || b ==  h ) && (a >  1  && a <  8 )) n     cout << 5; n   else if ((a ==  1  || a ==  8 ) || (a >  a  && a <  h )) n     cout << 5; n   else n     cout << 8; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string& s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int maxn = 1e5 + 5; n pair<int, int> node[maxn]; n vector<int> V[maxn]; n int n; n set<pair<int, int> > Snode; n int xx[maxn], xcnt; n bool find(int x, int y) { n   if (x < maxn) n     return binary_search(V[x].begin(), V[x].end(), y); n   else n     return false; n } n int main() { n   scanf( %d , &n); n   int x, y; n   for (int i = 1; i <= n; i++) { n     scanf( %d %d , &x, &y); n     node[i] = {x, y}; n     xx[++xcnt] = x; n   } n   sort(node + 1, node + 1 + n); n   for (int i = 1; i <= n; i++) { n     V[node[i].first].push_back(node[i].second); n   } n   sort(xx + 1, xx + 1 + xcnt); n   xcnt = unique(xx + 1, xx + 1 + xcnt) - xx - 1; n   42; n   int sz = sqrt(maxn); n   int res = 0; n   for (int i = 1; i <= xcnt; i++) { n     x = xx[i]; n     if (V[x].size() <= sz) { n       for (int j = 0; j < V[x].size(); j++) { n         for (int k = j + 1; k < V[x].size(); k++) { n           int tmp = V[x][k] - V[x][j]; n           if (find(x + tmp, V[x][j]) && find(x + tmp, V[x][k])) res++; n         } n       } n     } else { n       for (int j = i + 1; j <= xcnt; j++) { n         int x2 = xx[j]; n         if (V[x2].size() <= 1) continue; n         for (int k = 0; k < V[x2].size(); k++) { n           int tmp = x2 - x; n           if (find(x, V[x2][k]) && find(x, V[x2][k] + tmp) && n               find(x2, V[x2][k] + tmp)) n             res++; n         } n       } n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1 << 18]; n long long sum[1 << 18]; n int p[1 << 18]; n int n, T, m; n double c; n void Calc() { n   double mean = 0.0; n   for (int i = 0, j = 0; i < n && j < m; i++) { n     mean = (mean + (a[i] + .0) / T) / c; n     if (i == p[j] - 1) { n       double real = (.0 + sum[i + 1] - sum[i - T + 1]) / T; n       printf( %.9lf  , real); n       printf( %.9lf  , mean); n       printf( %.9lf n , fabs(real - mean) / real); n       j++; n     } n   } n } n int main() { n   scanf( %d%d%lf , &n, &T, &c); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     sum[i + 1] = sum[i] + a[i]; n   } n   scanf( %d , &m); n   for (int i = 0; i < m; i++) scanf( %d , &p[i]); n   Calc(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, res = -1000000000; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     if (floor(sqrt(x)) != ceil(sqrt(x))) { n       res = max(res, x); n     } n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, pay = 0, kd; n   int U = 0, R = 0; n   char c; n   cin >> n; n   cin >> c; n   if (c ==  U ) { n     kd = 1; n     U++; n   } else { n     kd = 0; n     R++; n   } n   for (int i = 1; i < n; i++) { n     cin >> c; n     if (c ==  U ) n       U++; n     else if (c ==  R ) n       R++; n     if (kd == 0 && R < U) { n       pay++; n       kd = 1; n     } else if (kd && R > U) { n       pay++; n       kd = 0; n     } n   } n   cout << pay; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20500; n int A[N]; n int n; n int B[N]; n int get(int k) { n   if (n / k < 3) return -1e9; n   for (int i = 0; i < k; i++) B[i] = 0; n   for (int i = 0; i < n; i++) B[i % k] += A[i]; n   int ans = -1e9; n   for (int i = 0; i < k; i++) ans = max(ans, B[i]); n   return ans; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> A[i]; n   int ans = -1e9; n   for (int k = 1; k * k <= n; k++) n     if (n % k == 0) ans = max(ans, max(get(k), get(n / k))); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int a = 0, b = 0, c = 0; n     string line; n     cin >> line; n     for (char d : line) { n       if (d ==  B ) b++; n       if (d ==  A ) a++; n       if (d ==  C ) c++; n     } n     if (b == a + c) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1000000007; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long int t; n   t = 1; n   while (t--) { n     long long int n, m, k; n     cin >> n >> m >> k; n     vector<long long int> xs, ys; n     for (long long int i = 0; i < n * m; i++) { n       ys.push_back(i / n + 1); n       if ((i / n) % 2 == 0) { n         xs.push_back(i % n + 1); n       } else { n         xs.push_back(n - i % n); n       } n     } n     for (long long int i = 0; i < k - 1; i++) { n       cout << 2 <<     << xs[2 * i] <<     << ys[2 * i] <<     << xs[2 * i + 1] n            <<     << ys[2 * i + 1] << endl; n     } n     cout << n * m - 2 * (k - 1) <<    ; n     for (long long int i = 2 * (k - 1); i < n * m; i++) { n       cout << xs[i] <<     << ys[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long solve(int N, const vector<int>& A) { n   long long res = 0; n   vector<int> freq(32); n   for (int x : A) { n     int hsb = (sizeof(int) * 8 - 1 - __builtin_clz((x))); n     res += freq[hsb]; n     ++freq[hsb]; n   } n   return res; n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int TC; n   cin >> TC; n   for (int tc = (1), _b = (TC); tc <= _b; ++tc) { n     int N; n     cin >> N; n     vector<int> A(N); n     for (int i = 0, _n = (N); i < _n; ++i) cin >> A[i]; n     long long res = solve(N, A); n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(vector<T>& a) { n   for (auto& e : a) { n     cin >> e; n   } n } n template <class T> n void print(vector<T>& a) { n   for (auto& e : a) { n     cout << e <<    ; n   } n   cout <<   n ; n } n void solve() { n   long long n, h; n   cin >> n >> h; n   vector<long long> a(n); n   read(a); n   if (n == 1) { n     cout << h <<   n ; n     return; n   } n   vector<long long> b; n   for (long long i = 1; i < n; ++i) { n     b.push_back(a[i] - a[i - 1]); n   } n   long long l = 0, r = 1e18; n   while (l + 1 != r) { n     long long m = (l + r) / 2; n     long long res = m; n     for (long long i = 0; i < n - 1; ++i) { n       res += min(m, b[i]); n     } n     if (res >= h) { n       r = m; n     } else { n       l = m; n     } n   } n   cout << r <<   n ; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n const int N = 505, M = 25005000, inf = 0x3f3f3f3f; n int n, m, num, dfn[N][N], dis[N]; n bool mtr[2505][2505], v[2505]; n char s[N][N]; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n int q[2505], head[2505], nxt[M], to[M], edgenum; n void addedge(int u, int v) { n   to[++edgenum] = v; n   nxt[edgenum] = head[u]; n   head[u] = edgenum; n } n inline void dfs(int x, int y) { n   dfn[x][y] = num; n   for (register int i = 0; i <= 3; i++) { n     int nx = x + dx[i], ny = y + dy[i]; n     if (nx >= 1 && nx <= n && ny >= 1 && ny <= m) { n       if (s[nx][ny] == s[x][y] && !dfn[nx][ny]) dfs(nx, ny); n       if (s[nx][ny] != s[x][y] && dfn[nx][ny]) n         mtr[num][dfn[nx][ny]] = mtr[dfn[nx][ny]][num] = 1; n     } n   } n } n inline int getdis(int s) { n   memset(dis, inf, sizeof(dis)); n   int res = 0, f = 0, r = 1; n   q[f] = s; n   dis[s] = 0; n   while (f != r) { n     int u = q[f++]; n     res = max(res, dis[u]); n     for (int i = head[u]; i != 0; i = nxt[i]) n       if (dis[to[i]] > dis[u] + 1) { n         dis[to[i]] = dis[u] + 1; n         q[r++] = to[i]; n       } n   } n   return res; n } n int main() { n   read(n); n   read(m); n   for (register int i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   for (register int i = 1; i <= n; i++) n     for (register int j = 1; j <= m; j++) n       if (!dfn[i][j]) { n         ++num; n         v[num] = s[i][j] ==  B ; n         dfs(i, j); n       } n   for (register int i = 1; i <= num; i++) n     for (register int j = 1; j <= num; j++) n       if (mtr[i][j]) addedge(i, j); n   int ans = 1e9; n   for (register int i = 1; i <= num; i++) { n     int d = getdis(i); n     ans = min(ans, d + (((d + v[i]) & 1) ? 1 : 0)); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); n int main() n { n     fast; n     int t; n     cin >> t; n     while (t--) n     { n         int n; n         cin >> n; n         vector<int> a(n + 1); n         a[0] = 0; n         for (int i = 1; i <= n; i++) n             a[i] = i; n         if (n % 2 == 0) n         { n             for (int i = 1; i < n; i += 2) n                 swap(a[i], a[i + 1]); n         } n         else n         { n             for (int i = 1; i < n - 2; i+= 2) n                 swap(a[i], a[i + 1]); n             int temp = a[n]; n             a[n] = a[n - 1]; n             a[n - 1] = a[n - 2]; n             a[n - 2] = temp; n         } n         for (int i = 1; i <= n; i++) n             cout << a[i] <<    ; n         cout << endl; n     } n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 3, Mod = 1e9 + 7; n const int maxN = 1e5 + 3; n void solve() { n   long long n; n   cin >> n; n   long long ans = 6; n   long long bin = 4; n   for (int i = 1; i < n; i++) { n     bin *= bin; n     bin %= Mod; n     ans *= bin; n     ans %= Mod; n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int t = 1; n   for (int i = 0; i < t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int x[102], pile[102]; n int MN(int a, int b) { return (a < b) ? a : b; } n int main() { n   int n, i, sz, j, flag; n   while (scanf( %d , &n) != EOF) { n     for (i = 1; i <= n; i++) { n       scanf( %d , &x[i]); n     } n     sort(x + 1, x + n + 1); n     sz = 1; n     pile[sz] = 1; n     for (i = 2; i <= n; i++) { n       flag = 0; n       for (j = 1; j <= sz; j++) { n         if (pile[j] <= x[i]) { n           flag = 1; n           pile[j]++; n           break; n         } n       } n       if (flag == 0) pile[++sz] = 1; n     } n     printf( %d n , sz); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n int n; n int inDegree[MAXN]; n long long A[MAXN], _A[MAXN], B[MAXN]; n vector<int> adj[MAXN]; n void build() { n   for (int i = 0; i < n; i++) { n     if (B[i] == -1) continue; n     adj[i].push_back(B[i]); n     inDegree[B[i]]++; n   } n } n vector<int> solve() { n   vector<int> pos, neg; n   queue<int> q; n   for (int i = 0; i < n; i++) { n     if (inDegree[i] == 0) { n       q.push(i); n     } n   } n   while (!q.empty()) { n     int i = q.front(); n     q.pop(); n     if (A[i] > 0) { n       pos.push_back(i); n       if (B[i] != -1) A[B[i]] += A[i]; n     } else { n       neg.push_back(i); n     } n     for (auto v : adj[i]) { n       inDegree[v]--; n       if (inDegree[v] == 0) q.push(v); n     } n   } n   reverse(neg.begin(), neg.end()); n   pos.insert(pos.end(), neg.begin(), neg.end()); n   return pos; n } n int main() { n   ; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n     _A[i] = A[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> B[i]; n     if (B[i] != -1) B[i]--; n   } n   build(); n   long long ans = 0; n   vector<int> v = solve(); n   for (auto i : v) { n     ans += _A[i]; n     if (B[i] != -1) _A[B[i]] += _A[i]; n   } n   cout << ans <<   n ; n   for (auto i : v) cout << i + 1 <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t; n int ask(int r) { n   cout <<  ?   << 1 <<     << r << endl; n   int ans; n   cin >> ans; n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   srand(time(0)); n   cin >> n >> t; n   vector<int> a(1, t); n   int inv = 0, rep = 0; n   for (int i = n - 1; i >= 1; i--) { n     int t2 = ask(i); n     inv ^= 1; n     int cur = i - (t - t2 + i) / 2; n     if (inv) cur = i - cur; n     if (t2 == n - t && rep < 25) { n       i++; n       rep++; n     } else { n       a.push_back(cur); n       rep = 0; n     } n     t = t2; n   } n   reverse(a.begin(), a.end()); n   cout <<  !   << a[0]; n   for (int i = 1; i < (int)a.size(); i++) cout << a[i] - a[i - 1]; n   cout << endl; n } n


//a.9 n #include<bits/stdc++.h> n #define ll long long n #define all(x) x.begin(),x.end() n #define CASE(t) cout<< Case # <<(t)<< :  ; n #define endll endl n #define endl   n  n #define INF 1e18 n #define deb(x) cout <<  [  << (#x) <<  =  << x <<  ]  <<   n  n #define deb2(x,y) cout <<  [  << (#x) <<  =  << x <<  ] [  << (#y) <<  =  << y <<  ]  <<   n  n #define deb3(x,y,z) cout <<  [  << (#x) <<  =  << x <<  ] [  << (#y) <<  =  << y <<  ] [  << (#z) <<  =  << z <<  ]  <<   n  n #define popcnt __builtin_popcountll n #define precise(x) fixed << setprecision(x) n #define ios ios_base::sync_with_stdio(false); cin.tie(NULL) n using namespace std; n const ll mod=1000000007; n const ll maxN=50005; n  n ll ceill(ll a,ll b){return a/b+bool(a%b);} n ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);} n ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} n ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;} n void bin(unsigned n,string &str){str=  ;if(n>1)bin(n>>1,str);str+=to_string(n&1);} n bool isPrime(ll n) n { n     if(n<=1)return false;else if(n<=3)return true;else if(n%2==0 || n%3==0)return false; n     for(ll i=5;i*i<=n;i=i+6){if(n%i==0 || n%(i+2)==0)return false;}return true; n } n  n vector<ll>primes; n void SieveOfEratosthenes() n { n     bool prime[maxN];primes.clear(); n     memset(prime, true, sizeof(prime)); n     for(ll i=2;i*i<maxN;i++)if(prime[i]==true)for(ll j=i*i;j<maxN;j+=i)prime[j]=false; n     for(ll i=2;i<maxN;i++)if(prime[i])primes.push_back(i); n } n //vector<ll>fact(maxN); n //void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i)%mod;} n //ll mul(ll a,ll b){return (a*1LL*b)%mod;} n //ll nCr(ll n,ll k){if(k>n)return 0;return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));} n  n /*ll spf[maxN]; n void sieve() n { n     spf[1]=1;for(ll i=2;i<maxN;i++)spf[i]=i;for(ll i=4;i<maxN;i+=2)spf[i]=2; n     for(ll i=3;i*i<maxN;i++){if(spf[i]==i)for(ll j=i*i;j<maxN;j+=i)if(spf[j]==j)spf[j]=i;} n } n vector<ll>getfacts(ll x){vector<ll>vec;while(x!=1)vec.push_back(spf[x]),x=x/spf[x];return vec;}*/ n  n /*ll fen[maxN]; n void update(ll i,ll val,ll n){i++;for(;i<=n;i+=i&-i)fen[i]+=val;} n ll get(ll i){i++;ll res=0;for(;i>0;i-=i&-i)res+=fen[i];return res;}*/ n  n void solve() n { n     ll a,b;cin>>a>>b; n     if(b==1){cout<< NO <<endl;return;} n     cout<< YES <<endl; n     cout<<a<<   <<a*b<<   <<a*(b+1)<<endl; n } n signed main() n { n     ios; n     ll tc=1; cin>>tc; n     for(ll t=1;t<=tc;t++) n     { n         //CASE(t); n         solve(); n     } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   int b[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int c = 0, r = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == 0 and b[i] == 1) c++; n     if (a[i] == 1 and b[i] == 0) r++; n   } n   if (r > c) { n     cout <<  1  << endl; n   } else if (r == 0) n     cout <<  -1  << endl; n   else { n     int val = ceil(((float)(c + 1) / (float)r)); n     cout << val << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[90]; n void error() { n   cout << -1 << endl; n   exit(0); n } n int main() { n   int n, m, l = 1, r; n   scanf( %d%d n , &n, &m); n   r = n; n   while (m--) { n     int v; n     scanf( To the %s of %d n , s, &v); n     if (!strcmp(s,  left )) { n       if (l >= v) error(); n       if (r >= v) r = v - 1; n     } else { n       if (r <= v) error(); n       if (l <= v) l = v + 1; n     } n   } n   cout << r - l + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10000005; n int sum[MAXN]; n bool ok[MAXN]; n int n; n char a[200005]; n bool grp[200005]; n void submit(int s) { n   vector<string> ret; n   for (int i = 0; i < n; i++) { n     if (grp[i]) { n       string str; n       str.push_back(a[i]); n       str.push_back(a[i + 1]); n       ret.push_back(str); n       i++; n       continue; n     } else { n       string str = {a[i]}; n       ret.push_back(str); n     } n   } n   for (int i = 0; i < ret.size(); i++) { n     printf( %s , ret[i].c_str()); n     if (i + 1 < ret.size()) printf( + ); n   } n   puts(  ); n   if (s >= 10) { n     vector<int> a; n     int bs = sum[s]; n     while (s) { n       a.push_back(s % 10); n       s /= 10; n     } n     reverse(a.begin(), a.end()); n     for (int i = 0; i < a.size(); i++) { n       printf( %d , a[i]); n       if (i + 1 < a.size()) printf( + ); n     } n     puts(  ); n     if (bs >= 10) n       printf( %d+%d , bs / 10, bs % 10); n     else n       printf( %d , bs); n   } else { n     printf( %d n%d n , s, s); n   } n   exit(0); n } n int main() { n   for (int i = 1; i < MAXN; i++) { n     sum[i] = sum[i / 10] + (i % 10); n   } n   for (int i = 0; i < MAXN; i++) { n     if (sum[sum[i]] <= 9) ok[i] = 1; n   } n   scanf( %d %s , &n, a); n   int sum = 0; n   for (int i = 0; i < n; i++) sum += a[i] -  0 ; n   if (ok[sum]) submit(sum); n   for (int i = 0; i + 1 < n; i += 2) { n     sum -= a[i] -  0 ; n     sum -= a[i + 1] -  0 ; n     sum += (a[i] -  0 ) * 10 + (a[i + 1] -  0 ); n     grp[i] = 1; n     if (ok[sum]) submit(sum); n   } n   for (int i = 0; i + 1 < n; i += 2) { n     sum += a[i] -  0 ; n     sum += a[i + 1] -  0 ; n     sum -= (a[i] -  0 ) * 10 + (a[i + 1] -  0 ); n     grp[i] = 0; n     if (ok[sum]) submit(sum); n   } n   for (int i = 1; i + 1 < n; i += 2) { n     sum -= a[i] -  0 ; n     sum -= a[i + 1] -  0 ; n     sum += (a[i] -  0 ) * 10 + (a[i + 1] -  0 ); n     grp[i] = 1; n     if (ok[sum]) submit(sum); n   } n   for (int i = 1; i + 1 < n; i += 2) { n     sum += a[i] -  0 ; n     sum += a[i + 1] -  0 ; n     sum -= (a[i] -  0 ) * 10 + (a[i + 1] -  0 ); n     grp[i] = 0; n     if (ok[sum]) submit(sum); n   } n   assert(0); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000; n int H[N]; n vector<int> g[N], b[N]; n int ans[N]; n int n, q; n map<int, set<pair<int, int> > > m; n void dfs(int v, int h = 0, int p = -1) { n   ans[v] = -1; n   H[v] = h; n   for (auto i : b[v]) { n     if (!m[i].empty()) { n       auto t = *m[i].begin(); n       if (ans[v] == -1 || H[ans[v]] < -t.first) ans[v] = t.second; n     } n     m[i].insert({-h, v}); n   } n   for (auto u : g[v]) { n     if (p != u) { n       dfs(u, h + 1, v); n     } n   } n   for (auto i : b[v]) { n     m[i].erase({-h, v}); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> q; n   for (int j = 1; j <= n; j++) { n     int w; n     cin >> w; n     for (int i = 2; i * i <= w; i++) { n       if (w % i == 0) { n         b[j].push_back(i); n         while (w % i == 0) w /= i; n       } n     } n     if (w > 1) b[j].push_back(w); n   } n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1); n   while (q--) { n     int t; n     cin >> t; n     if (t == 2) { n       int v, w; n       cin >> v >> w; n       b[v].clear(); n       for (int i = 2; i * i <= w; i++) { n         if (w % i == 0) { n           b[v].push_back(i); n           while (w % i == 0) w /= i; n         } n       } n       if (w > 1) b[v].push_back(w); n       dfs(1); n     } else { n       int v; n       cin >> v; n       cout << ans[v] << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long t, a[200010]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> t; n   while (t--) { n     long long n; n     set<long long> s; n     cin >> n; n     for (long long i = 0; i < n; i++) cin >> a[i], a[i] = a[i] % n; n     for (long long i = 0; i < n * 3; i++) s.insert(i + (a[i % n])); n     if (s.size() != 3 * n) n       cout <<  NO  <<   n ; n     else n       cout <<  YES  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   string s; n   cin >> s; n   int n = s.size(); n   long long maxDiff = 0; n   long long ans = 0; n   int x; n   if (n == 1) { n     cout << s << endl; n     return 0; n   } n   vector<pair<char, vector<long long> > > a; n   char t =  o ; n   for (int i = 0; i < n; i += 2) { n     x = s[i] -  0 ; n     if (((i > 0) && (s[i - 1] ==  * )) || ((i < n - 1) && (s[i + 1] ==  * ))) { n       if (t !=  * ) { n         t =  * ; n         a.push_back(make_pair(t, vector<long long>(1, x))); n       } else { n         a.back().second.push_back(a.back().second.back() * x); n       } n       if ((i < n - 1) && (s[i + 1] ==  + )) { n         t =  o ; n       } n     } else { n       if (t !=  + ) { n         t =  + ; n         a.push_back(make_pair(t, vector<long long>(1, x))); n       } else { n         a.back().second.push_back(a.back().second.back() + x); n       } n     } n   } n   n = a.size(); n   vector<long long> b(n); n   for (int i = 0; i < n; i++) { n     b[i] = a[i].second.back(); n     if (i) { n       b[i] += b[i - 1]; n     } n   } n   ans = b[n - 1]; n   maxDiff = 0; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       for (int si = 0; si < a[i].second.size(); si++) { n         for (int sj = 0; sj < a[j].second.size(); sj++) { n           long long old = b[j]; n           if (i > 0) { n             old -= b[i - 1]; n           } n           long long vLeft, vRight, vMiddle = 0; n           vLeft = a[i].second.back(); n           if (si > 0) { n             if (a[i].first ==  + ) { n               vLeft -= a[i].second[si - 1]; n             } else { n               vLeft /= a[i].second[si - 1]; n             } n           } n           vRight = a[j].second[sj]; n           if (j - 1 > i) { n             vMiddle = b[j - 1] - b[i]; n           } n           long long v = vLeft + vRight + vMiddle; n           if (si > 0) { n             if (a[i].first ==  + ) { n               v += a[i].second[si - 1]; n             } else { n               v *= a[i].second[si - 1]; n             } n           } n           if (sj < a[j].second.size() - 1) { n             if (a[j].first ==  + ) { n               v += a[j].second.back() - a[j].second[sj]; n             } else { n               v *= a[j].second.back() / a[j].second[sj]; n             } n           } n           maxDiff = max(maxDiff, v - old); n         } n       } n     } n   } n   cout << ans + maxDiff << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct TPoint { n   double x, y; n   TPoint(){}; n   TPoint(double _x, double _y) { n     x = _x; n     y = _y; n   } n }; n struct TVector { n   double x, y; n   TVector() {} n   TVector(TPoint p) { n     x = p.x; n     y = p.y; n   } n   TVector(TPoint p1, TPoint p2) { n     x = p2.x - p1.x; n     y = p2.y - p1.y; n   } n }; n double cosv(TVector v1, TVector v2) { n   return (double)(v2.x * v1.y - v1.x * v2.y); n } n int main() { n   int n; n   cin >> n; n   vector<TPoint> in; n   for (int i = 0; i < n; ++i) { n     double x, y; n     cin >> x >> y; n     in.push_back(TPoint(x, y)); n   } n   double maxpl = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       double lefter = -1, righter = -1; n       for (int k = 0; k < n; ++k) { n         if (k != i && k != j) { n           double cosven = cosv(TVector(in[i], in[j]), TVector(in[i], in[k])); n           if (cosven > 0) { n             lefter = max(lefter, cosven / 2); n           } else { n             righter = max(righter, -cosven / 2); n           } n         } n       } n       if (lefter > 0 && righter > 0) maxpl = max(maxpl, lefter + righter); n     } n   } n   cout.precision(10); n   cout << maxpl << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 400010; n inline long long read() { n   long long s = 0, w = 1; n   register char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     s = (s << 3) + (s << 1) + (ch -  0 ), ch = getchar(); n   return s * w; n } n void print(long long x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) print(x / 10); n   putchar(x % 10 +  0 ); n } n long long n, deg[N], root, cnt; n struct Node { n   long long a, b, c; n } h[N]; n long long head[N], maxE; n struct Edge { n   long long nxt, to, rdis; n } e[N << 1]; n inline void Add(long long u, long long v, long long w) { n   e[++maxE].nxt = head[u]; n   head[u] = maxE; n   e[maxE].to = v; n   e[maxE].rdis = w; n } n long long DFS(long long x, long long fa, long long w) { n   long long res; n   long long p, q; n   res = p = q = 0; n   for (long long i = head[x]; i; i = e[i].nxt) { n     if (e[i].to == fa) continue; n     res += e[i].rdis; n     long long gt = DFS(e[i].to, x, e[i].rdis); n     (p ? q : p) = gt; n   } n   if (x == root) return p; n   if (!p) n     p = x, h[++cnt] = (Node){p, root, w}; n   else { n     h[++cnt] = (Node){p, q, (res - w) / 2}; n     h[++cnt] = (Node){p, root, (w - res) / 2}; n     h[++cnt] = (Node){q, root, (w - res) / 2}; n   } n   return p; n } n signed main() { n   n = read(); n   for (register long long i = 1; i < n; i++) { n     long long u, v, w; n     u = read(), v = read(), w = read(); n     Add(u, v, w), Add(v, u, w); n     deg[u]++, deg[v]++; n   } n   for (register long long i = 1; i <= n; i++) { n     if (deg[i] == 2) { n       puts( NO ); n       return 0; n     } n     if (deg[i] == 1) root = i; n   } n   puts( YES ); n   DFS(root, 0, 0); n   printf( %lld n , cnt); n   for (register long long i = 1; i <= cnt; i++) n     printf( %lld %lld %lld n , h[i].a, h[i].b, h[i].c); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chkmin(T& a, T b) { n   return a > b ? a = b, true : false; n } n template <class T> n bool chkmax(T& a, T b) { n   return a < b ? a = b, true : false; n } n template <class T> n void read(T& a) { n   char c = getchar_unlocked(); n   T f = 1; n   a = 0; n   for (; !isdigit(c); c = getchar_unlocked()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar_unlocked()) a = a * 10 + c -  0 ; n   a *= f; n } n const int maxN = 2e5 + 5; n int N; n pair<int, int> a[maxN]; n map<int, int> f; n map<pair<int, int>, int> g; n int main() { n   read(N); n   for (int i = (1), _ = (N); i <= _; ++i) read(a[i].first), read(a[i].second); n   for (int i = (1), _ = (N); i <= _; ++i) f[a[i].first]++; n   long long ans = 0; n   for (map<int, int>::iterator it = f.begin(); it != f.end(); ++it) n     ans += (long long)it->second * (it->second - 1) / 2; n   f.clear(); n   for (int i = (1), _ = (N); i <= _; ++i) f[a[i].second]++; n   for (map<int, int>::iterator it = f.begin(); it != f.end(); ++it) n     ans += (long long)it->second * (it->second - 1) / 2; n   for (int i = (1), _ = (N); i <= _; ++i) g[a[i]]++; n   for (map<pair<int, int>, int>::iterator it = g.begin(); it != g.end(); ++it) n     ans -= (long long)(it->second) * (it->second - 1) / 2; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f = ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   return f ? -x : x; n } n const int N = 1005; n int n, k, b; n long long a[N][N], c[N][N]; n int x[N], y[N]; n int main() { n   k = read(), b = 1 << k; n   for (int i = (0); i <= (b - 1); i++) n     for (int j = (0); j <= (b - 1); j++) a[i][j] = read(); n   n = read(); n   for (int i = (1); i <= (n); i++) x[i] = read(), y[i] = read(); n   for (int d = (0); d <= (k - 1); d++) { n     memset(c, 0, sizeof(c)); n     for (int i = (0); i <= (b - 1); i++) n       for (int j = (0); j <= (b - 1); j++) n         for (int t = (1); t <= (n); t++) n           c[(i + (x[t] << d)) & (b - 1)][(j + (y[t] << d)) & (b - 1)] ^= n               a[i][j]; n     swap(a, c); n   } n   int c = 0; n   for (int i = (0); i <= (b - 1); i++) n     for (int j = (0); j <= (b - 1); j++) n       if (a[i][j]) c++; n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, is, it; n vector<int> res; n string s, t; n int getis() { n   for (int i = it; i < t.size(); ++i) { n     if (s[i] == t[it]) return i; n   } n   return -1; n } n int main() { n   cin >> n >> s >> t; n   while (s != t) { n     is = getis(); n     if (is == -1) { n       cout << -1; n       return 0; n     } n     while (is >= 0 && is > it) { n       res.push_back(is - 1); n       swap(s[is - 1], s[is]); n       is--; n     } n     it++; n   } n   if (res.size() > 10000) { n     cout << -1; n     return 0; n   } n   cout << res.size() << endl; n   for (int i : res) cout << i + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   bool flag = 1; n   int c = 0, a[] = {5, 7, 5}, k = 0; n   map<char, bool> m{{ a , 1}, { e , 1}, { o , 1}, { u , 1}, { i , 1}}; n   while (getline(cin, s)) { n     c = 0; n     for (int i = 0; i < s.size(); i++) c += m[s[i]]; n     if (c != a[k]) flag = 0; n     k++; n   } n   if (flag == 1) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b; n   cin >> a >> b; n   stringstream ss; n   ss << b; n   string str; n   str = ss.str(); n   reverse((str).begin(), (str).end()); n   stringstream ss1; n   ss1 << str; n   ss1 >> b; n   cout << a + b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T big(T a, T b) { n   return a > b ? a : b; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n bool mod(long double a, long double b) { return a / b - floor(a / b); } n long long occurs(vector<long long> v, long long n) { n   auto it = lower_bound(((v)).begin(), ((v)).end(), (n)); n   auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n)); n   long long x = it1 - it; n   return x; n } n long long logb(long long base, long long x) { return (log(x) / log(base)); } n long long pow(long long n, long long m) { n   long long ans = 1; n   for (long long i{0}; i < m; i++) { n     ans *= n; n   } n   return ans; n } n long long factors(long long ans) { n   long long count = 0; n   for (long long i = 1; i <= sqrt(ans); i++) { n     if (ans % i == 0) { n       if (ans / i == i) n         count++; n       else n         count += 2; n     } n   } n   return count; n } n bool isSubSequence(string str1, string str2, long long m, long long n) { n   if (m == 0) return true; n   if (n == 0) return false; n   if (str1[m - 1] == str2[n - 1]) n     return isSubSequence(str1, str2, m - 1, n - 1); n   return isSubSequence(str1, str2, m, n - 1); n } n long long log2(long long n) { n   long long count = 0; n   while (n != 0) { n     n /= 2; n     count++; n   } n   return count - 1; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   string s; n   cin >> s; n   if (n == 1 && m != 0) { n     cout << 0; n     return 0; n   } n   if (m == 0) { n     for (long long i{0}; i < n; i++) { n       cout << s[i]; n     } n     return 0; n   } n   if (s[0] ==  1 ) { n     m++; n   } n   cout << 1; n   for (long long i{1}; i < m; i++) { n     if (s[i] ==  0 ) { n       m++; n     } n     cout << 0; n     if (i == n - 1) break; n   } n   if (m <= n) { n     for (long long i{m}; i < n; i++) { n       cout << s[i]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n struct Item { n   int parent; n   int count; n }; n int Find(int x, std::vector<Item>* items) { n   if (items->at(x).parent == x) { n     return x; n   } n   return items->at(x).parent = Find(items->at(x).parent, items); n } n void Unite(int x, int y, std::vector<Item>* items) { n   assert(x == Find(x, items)); n   assert(y == Find(y, items)); n   if (items->at(x).count < items->at(y).count) { n     std::swap(x, y); n   } n   items->at(y).parent = x; n   items->at(x).count += items->at(y).count; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   int N, M; n   cin >> N >> M; n   std::vector<std::pair<int, int>> A(N); n   std::vector<Item> items(N); n   for (int i = 0; i < N; ++i) { n     int a; n     cin >> a; n     A[i].first = a; n     A[i].second = i; n     items[i].parent = i; n     items[i].count = 1; n   } n   std::vector<std::vector<int>> gr(N); n   for (int i = 0; i < M; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   std::sort(A.begin(), A.end()); n   int64_t answer = 0; n   std::vector<int> visited(N, false); n   for (int index = N - 1; index >= 0; --index) { n     int value = A[index].first; n     int vertex = A[index].second; n     int64_t sum = 0, sum_sq = 0; n     for (int neib : gr[vertex]) { n       int x = Find(vertex, &items); n       int y = Find(neib, &items); n       if (x == y) { n         continue; n       } n       if (!visited[y]) { n         continue; n       } n       sum += items[y].count; n       sum_sq += (int64_t)items[y].count * items[y].count; n       Unite(x, y, &items); n     } n     answer += (int64_t)value * (sum * sum - sum_sq + 2 * sum); n     visited[Find(vertex, &items)] = true; n   } n   long double result = (long double)answer / ((int64_t)N * (N - 1)); n   cout.precision(6); n   cout << std::fixed << result <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, i, c, x, y, z, k, h; n int main() { n   cin >> x >> y; n   for (a = 0; a <= 1000; a++) { n     for (b = 0; b <= 1000; b++) n       if (a * a + b == x && a + b * b == y) h++; n   } n   cout << h; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 999999; n const double Eps = 1e-12; n const double PI = acos(-1.0); n int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); } n long long pe[2222], key[2222]; n char a[100], b[100]; n int p[11111]; n using namespace std; n int num[200004], ans[200005]; n int main() { n   int n; n   while (cin >> n) { n     for (int i = 1; i <= n; i++) scanf( %d , num + i); n     memset(ans, -1, sizeof(ans)); n     ans[1] = 0; n     queue<int> q; n     q.push(1); n     while (!q.empty()) { n       int s = q.front(); n       q.pop(); n       for (int i = -1; i <= 1; ++i) { n         if (i == 0) continue; n         int d = s + i; n         if (d >= 1 && d <= n && ans[d] == -1) { n           ans[d] = ans[s] + 1; n           q.push(d); n         } n       } n       int d = num[s]; n       if (ans[d] == -1) { n         ans[d] = ans[s] + 1; n         q.push(d); n       } n     } n     cout << ans[1]; n     for (int i = 2; i <= n; i++) printf(  %d , ans[i]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string in =  111 ; n   cin >> in; n   vector<vector<int>> result; n   set<int> last1, last0; n   for (int i = 0; i < in.size(); i++) { n     if (in[i] ==  0 ) { n       if (last1.empty()) { n         result.push_back({i}); n         last0.insert(result.size() - 1); n       } else { n         int cur = *last1.begin(); n         result[cur].push_back(i); n         last1.erase(cur); n         last0.insert(cur); n       } n     } else { n       if (last0.empty()) { n         cout << -1; n         return 0; n       } else { n         int cur = *last0.begin(); n         result[cur].push_back(i); n         last0.erase(cur); n         last1.insert(cur); n       } n     } n   } n   if (last1.size()) { n     cout << -1; n     return 0; n   } n   cout << result.size() << endl; n   for (auto &it : result) { n     cout << it.size() <<    ; n     for (auto it2 : it) { n       cout << (it2 + 1) <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct abcd { n   int to, next; n } table[300300 << 1]; n int head[300300], tot; n int n, m; n char ans[300300]; n void Add(int x, int y) { n   table[++tot].to = y; n   table[tot].next = head[x]; n   head[x] = tot; n } n void DFS(int x) { n   int i, cnt = 0; n   for (i = head[x]; i; i = table[i].next) n     if (ans[table[i].to] == ans[x]) ++cnt; n   if (cnt >= 2) { n     ans[x] ^= 1; n     for (i = head[x]; i; i = table[i].next) DFS(table[i].to); n   } n } n int main() { n   vector<int>::iterator it; n   int i, x, y; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &x, &y); n     Add(x, y); n     Add(y, x); n   } n   for (i = 1; i <= n; i++) ans[i] =  0 ; n   for (i = 1; i <= n; i++) DFS(i); n   printf( %s n , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int INF = 2e9; n vector<string> v; n int n, m; n int diff(string a, string b) { n   int i, cc = 0; n   for (i = 0; i < m; ++i) cc += (a[i] != b[i]); n   return cc; n } n string solve() { n   string s = v[0], t; n   int i, j, cc; n   char c; n   bool f; n   for (i = 0; i < m; ++i) { n     t = s; n     for (c =  a ; c <=  z ; ++c) { n       t[i] = c; n       cc = 0; n       f = 1; n       for (j = 0; j < n; ++j) { n         cc = diff(t, v[j]); n         if (cc > 1) f = 0; n       } n       if (f) return t; n     } n   } n   return  -1 ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc, ti = 1; n   cin >> tc; n   while (tc--) { n     int i, j; n     cin >> n >> m; n     v.resize(n); n     for (i = 0; i < n; ++i) cin >> v[i]; n     cout << solve() <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000010; n int a[MAXN], parent[MAXN], rnk[MAXN]; n vector<int> arr[MAXN]; n vector<int> ans; n void make_set(int v) { n   parent[v] = v; n   rnk[v] = 0; n } n int find_set(int v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_sets(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (rnk[a] < rnk[b]) swap(a, b); n     parent[b] = a; n     if (rnk[a] == rnk[b]) rnk[a]++; n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   ans.clear(); n   ans.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     make_set(i); n   } n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     u--, v--; n     union_sets(u, v); n   } n   for (int i = 0; i < n; i++) { n     int st = find_set(i); n     arr[st].push_back(a[i]); n   } n   for (int i = 0; i < n; i++) { n     sort(arr[i].begin(), arr[i].end()); n   } n   for (int i = 0; i < n; i++) { n     int st = find_set(i); n     int x = arr[st].back(); n     arr[st].pop_back(); n     ans[i] = x; n   } n   for (int i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 9; n long long c[4005][4005]; n void getc() { n   memset(c, 0, sizeof(c)); n   c[0][0] = 1; n   for (int i = 1; i < 4001; i++) { n     c[i][0] = 1; n     for (int j = 1; j <= i; j++) { n       c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; n     } n   } n } n long long a[4005]; n void geta() { n   a[0] = 1; n   a[1] = 1; n   for (long long i = 2; i <= 4000; i++) a[i] = a[i - 1] * i % mod; n } n int main() { n   getc(); n   geta(); n   int n, w, b; n   while (scanf( %d%d%d , &n, &w, &b) == 3) { n     int x = max(1, n - w), y = min(b, n - 2); n     long long ans = 0; n     for (int i = x; i <= y; i++) { n       ans = (ans + n              c[b - 1][i - 1] * c[w - 1][n - i - 1] % mod * (n - i - 1) % mod) % n             mod; n     } n     ans = ans * a[w] % mod * a[b] % mod; n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (long long)1e9 + 7; n long long dp[12][65][1024], dp0[12][65][1024]; n void upd(long long &a, long long b) { a = (a + b); } n int get_next(int a, int b) { n   if ((a & (1 << b)) == 0) { n     a += (1 << b); n   } else { n     a -= (1 << b); n   } n   return a; n } n void precalc() { n   for (int i = 2; i <= 10; ++i) { n     dp[i][0][0] = 1; n     dp0[i][0][0] = 1; n   } n   for (int osn = 2; osn <= 10; ++osn) { n     for (int len = 0; len <= 62; ++len) { n       for (int mask = 0; mask < (1 << osn); ++mask) { n         for (int next = 0; next < osn; ++next) { n           upd(dp[osn][len + 1][get_next(mask, next)], dp[osn][len][mask]); n           if (next == 0 && len == 0) { n             continue; n           } n           upd(dp0[osn][len + 1][get_next(mask, next)], dp0[osn][len][mask]); n         } n       } n     } n   } n } n int digits[1000]; n int cur[10]; n int build(int x) { n   int ans = 0; n   for (int i = x - 1; i >= 0; --i) { n     ans = ans * 2 + cur[i] % 2; n   } n   return ans; n } n long long f(long long n, long long x) { n   int cnt = 0; n   if (n == 0) { n     return 0; n   } n   while (n > 0) { n     ++cnt; n     digits[cnt] = n % x; n     n /= x; n   } n   reverse(digits + 1, digits + cnt + 1); n   memset(cur, 0, sizeof cur); n   long long answer = 0; n   for (int i = 1; i <= cnt; ++i) { n     for (int new_digit = 0; new_digit < x; ++new_digit) { n       if (new_digit == 0 && i == 1) continue; n       if (new_digit < digits[i]) { n         ++cur[new_digit]; n         int cur_mask = build(x); n         answer = answer + dp[x][cnt - i][cur_mask]; n         --cur[new_digit]; n       } else { n         ++cur[new_digit]; n         break; n       } n     } n   } n   int cur_mask = build(x); n   if (cur_mask == 0) ++answer; n   for (int i = 1; i < cnt; ++i) { n     answer += dp0[x][i][0]; n   } n   return answer; n } n void solve(long long b, long long l, long long r) { n   long long ans = f(r, b) - f(l - 1, b); n   cout << ans << endl; n } n int main() { n   precalc(); n   ios_base::sync_with_stdio(0); n   int test; n   cin >> test; n   for (int tst = 1; tst <= test; ++tst) { n     long long b, l, r; n     cin >> b >> l >> r; n     solve(b, l, r); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3610, mod = 998244353; n template <typename T> n void read(T &x) { n   int ch = getchar(); n   x = 0; n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     ; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ; n } n void qmo(int &x) { x += x >> 31 & mod; } n int ksm(int a, int b) { n   int res = 1; n   for (; b; b >>= 1, a = (long long)a * a % mod) n     if (b & 1) res = (long long)res * a % mod; n   return res; n } n int n, m, k, cnt1, cnt2, f[N][N >> 1], g[N][N >> 1], fac[N], inv[N], ans; n bool vis1[N], vis2[N]; n void init(int n) { n   fac[0] = 1; n   for (int i = 1; i <= n; ++i) fac[i] = (long long)fac[i - 1] * i % mod; n   inv[n] = ksm(fac[n], mod - 2); n   for (int i = n; i; --i) inv[i - 1] = (long long)inv[i] * i % mod; n } n int main() { n   read(n); n   read(m); n   read(k); n   for (int i = 1, a1, b1, a2, b2; i <= k; ++i) { n     read(a1); n     read(b1); n     read(a2); n     read(b2); n     vis1[a1] = vis1[a2] = vis2[b1] = vis2[b2] = true; n   } n   init(max(n, m)); n   for (int i = 0; i <= n; ++i) f[i][0] = 1; n   for (int i = 1; i <= n; ++i) n     if (!vis1[i]) ++cnt1; n   for (int i = 0; i <= m; ++i) g[i][0] = 1; n   for (int i = 1; i <= m; ++i) n     if (!vis2[i]) ++cnt2; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= (i >> 1); ++j) { n       f[i][j] = f[i - 1][j]; n       if (j && !vis1[i] && !vis1[i - 1]) qmo(f[i][j] += f[i - 2][j - 1] - mod); n     } n   for (int i = 1; i <= m; ++i) n     for (int j = 1; j <= (i >> 1); ++j) { n       g[i][j] = g[i - 1][j]; n       if (j && !vis2[i] && !vis2[i - 1]) qmo(g[i][j] += g[i - 2][j - 1] - mod); n     } n   for (int i = 0; (i << 1) <= cnt1; ++i) n     for (int j = 0; (i << 1) + j <= cnt1 && (j << 1) + i <= cnt2; ++j) n       ans = (ans + (long long)f[n][i] * g[m][j] % mod * fac[cnt2 - (j << 1)] % n                        mod * inv[cnt2 - (j << 1) - i] % mod * n                        fac[cnt1 - (i << 1)] % mod * inv[cnt1 - (i << 1) - j]) % n             mod; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void chmin(T &t, const T &f) { n   if (t > f) t = f; n } n template <class T> n void chmax(T &t, const T &f) { n   if (t < f) t = f; n } n int main() { n   long long int n, a, c1, c2, m, len = 0, prev = 0, ans = 0, rlow, rlen, rind, n                                  ret[100005]; n   vector<pair<long long int, long long int> > v; n   vector<long long int> sum; n   scanf( %I64d %I64d %I64d %I64d %I64d , &n, &a, &c1, &c2, &m); n   for (long long int i = 0; i < n; ++i) { n     long long int x; n     scanf( %I64d , &x); n     v.push_back(make_pair(x, i)); n   } n   if (n == 1) { n     long long int maxi = min(a, v[0].first + m); n     printf( %I64d n , c1 * (maxi == a ? 1 : 0) + maxi * c2); n     printf( %I64d  , maxi); n     return 0; n   } n   sort(v.begin(), v.end()); n   sum.push_back(0); n   for (int i = 1; i < n; ++i) n     sum.push_back((v[i].first - v[i - 1].first) * i + sum[i - 1]); n   while (len <= n) { n     if (len - 1 >= 0) prev += a - v[n - len].first; n     if (prev > m) break; n     long long int newm = m - prev; n     long long int ind = upper_bound(sum.begin(), sum.end(), newm) - sum.begin(); n     ind = max(0ll, min((long long int)ind - 1, (long long int)n - len - 1)); n     newm -= sum[ind]; n     long long int low = min(v[ind].first + (newm / (ind + 1)), a); n     if (ans < len * c1 + low * c2) { n       ans = len * c1 + low * c2; n       rlow = low; n       rind = ind; n       rlen = len; n     } n     len++; n   } n   for (int i = 0; i < n; ++i) ret[v[i].second] = v[i].first; n   for (int i = 0; i <= rind; ++i) ret[v[i].second] = max(v[i].first, rlow); n   for (int i = n - 1; i >= n - rlen; --i) ret[v[i].second] = a; n   printf( %I64d n , ans); n   for (int i = 0; i < n; ++i) printf( %I64d  , ret[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int max_of_num; n int n, test_Q, point_num[100005], f_delp[100005][2]; n vector<int> vc[100005]; n bool flag = false; n void search1(int u, int fa) { n   for (int i = 0; i < vc[u].size(); i++) { n     int v = vc[u][i]; n     if (v != fa) { n       if (point_num[v] == 1) { n         if (f_delp[u][0]) { n           flag = true; n         } n         f_delp[u][1] = true; n       } else { n         search1(v, u); n         if (f_delp[v][1] && f_delp[u][1]) { n           flag = true; n         } n         if (f_delp[v][0] && f_delp[u][0]) { n           flag = true; n         } n         f_delp[u][0] = f_delp[u][0] | f_delp[v][1]; n         f_delp[u][1] = f_delp[u][1] | f_delp[v][0]; n       } n     } n   } n } n void connect_add(int u = 0, int v = 0) { n   scanf( %d%d , &u, &v); n   point_num[u]++; n   point_num[v]++; n   vc[u].push_back(v); n   vc[v].push_back(u); n } n void search2(int u, int fa) { n   int qaq = 0; n   for (int i = 0; i < vc[u].size(); i++) { n     int v = vc[u][i]; n     if (v != fa) { n       if (point_num[v] == 1) n         qaq++; n       else n         search2(v, u); n     } n   } n   if (qaq) max_of_num = max_of_num - (qaq - 1); n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     connect_add(); n   } n   test_Q = 0; n   for (int i = 1; i <= n; ++i) { n     if (point_num[i] > 1) { n       test_Q = i; n     } n   } n   search1(test_Q, 0); n   if (flag) { n     printf( 3  ); n   } else { n     printf( 1  ); n   } n   max_of_num = n - 1; n   search2(test_Q, 0); n   printf( %d n , max_of_num); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const MAX_CH = 110; n char st1[MAX_CH], st2[MAX_CH], st3[MAX_CH]; n int dp[MAX_CH][MAX_CH][MAX_CH]; n int new_pref_len[MAX_CH][30]; n struct { n   int i, j, k; n   char ad_ch; n } from[MAX_CH][MAX_CH][MAX_CH]; n int main() { n   gets(st1); n   int len_1 = (int)strlen(st1); n   gets(st2); n   int len_2 = (int)strlen(st2); n   gets(st3); n   int len_3 = (int)strlen(st3); n   for (int taked = 0; taked < len_3; taked++) n     for (int ch = 0; ch < 26; ch++) { n       string cur; n       for (int j = 0; j < taked; j++) cur += st3[j]; n       cur += (char)( A  + ch); n       int mx_pref = 0; n       for (int bg = 0; bg < (int)cur.length(); bg++) { n         int Ok = 1; n         for (int r = 0; r < len_3 && bg + r < (int)cur.length(); r++) n           if (st3[r] != cur[bg + r]) { n             Ok = 0; n             break; n           } n         if (Ok) mx_pref = max(mx_pref, ((int)cur.length()) - bg); n       } n       new_pref_len[taked][ch] = mx_pref; n     } n   for (int i = 0; i < MAX_CH; i++) n     for (int j = 0; j < MAX_CH; j++) n       for (int k = 0; k < MAX_CH; k++) dp[i][j][k] = -1; n   for (int i = 0; i < MAX_CH; i++) { n     dp[i][0][0] = 0; n     dp[0][i][0] = 0; n   } n   for (int i = 1; i <= len_1; i++) n     for (int j = 1; j <= len_2; j++) n       for (int k = 0; k < len_3; k++) { n         if (st1[i - 1] == st2[j - 1]) { n           int new_k; n           if (st3[k] == st1[i - 1]) n             new_k = k + 1; n           else n             new_k = new_pref_len[k][st1[i - 1] -  A ]; n           if (new_k >= len_3) n             ; n           else if (dp[i - 1][j - 1][k] + 1 > dp[i][j][new_k]) { n             dp[i][j][new_k] = dp[i - 1][j - 1][k] + 1; n             from[i][j][new_k].i = i - 1; n             from[i][j][new_k].j = j - 1; n             from[i][j][new_k].k = k; n             from[i][j][new_k].ad_ch = st1[i - 1]; n           } n         } n         if (dp[i - 1][j][k] > dp[i][j][k]) { n           dp[i][j][k] = dp[i - 1][j][k]; n           from[i][j][k].i = i - 1; n           from[i][j][k].j = j; n           from[i][j][k].k = k; n           from[i][j][k].ad_ch = 0; n         } n         if (dp[i][j - 1][k] > dp[i][j][k]) { n           dp[i][j][k] = dp[i][j - 1][k]; n           from[i][j][k].i = i; n           from[i][j][k].j = j - 1; n           from[i][j][k].k = k; n           from[i][j][k].ad_ch = 0; n         } n       } n   int cur_i = len_1, cur_j = len_2, cur_k = -1; n   int mx = -1; n   for (int k = 0; k < len_3; k++) n     if (dp[len_1][len_2][k] > mx) { n       mx = dp[len_1][len_2][k]; n       cur_k = k; n     } n   if (mx <= 0) { n     printf( 0 ); n     return 0; n   } n   string ans; n   while (cur_i >= 1 && cur_j >= 1) { n     if (from[cur_i][cur_j][cur_k].ad_ch > 0) n       ans += from[cur_i][cur_j][cur_k].ad_ch; n     int new_i = from[cur_i][cur_j][cur_k].i; n     int new_j = from[cur_i][cur_j][cur_k].j; n     int new_k = from[cur_i][cur_j][cur_k].k; n     cur_i = new_i; n     cur_j = new_j; n     cur_k = new_k; n   } n   for (int i = ((int)ans.length()) - 1; i >= 0; i--) printf( %c , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n long long int invmod(long long int x, long long int n, long long int mod) { n   if (n == 0) return 1 % mod; n   long long int half = invmod(x, n / 2, mod); n   half = (half * half) % mod; n   if (n % 2 == 1) half = (half * (x % mod)) % mod; n   return half; n } n long long int bin(vector<long long int> &a, long long int l, long long int r, n                   long long int x) { n   if (l <= r) { n     long long int m = l + (r - l) / 2; n     if (a[m] == x) n       return m; n     else if (a[m] > x) n       return bin(a, l, m - 1, x); n     else n       return bin(a, m + 1, r, x); n   } else n     return -1; n } n long long int power(long long int b, long long int e, long long int m) { n   if (e == 0) return 1; n   if (e % 2) n     return b * power(b * b % m, (e - 1) / 2, m) % m; n   else n     return power(b * b % m, e / 2, m); n } n long long int power(long long int b, long long int e) { n   if (e == 0) return 1; n   if (e % 2) n     return b * power(b * b, (e - 1) / 2); n   else n     return power(b * b, e / 2); n } n long long int ncr(long long int n, long long int p) { n   long long int r = min(p, n - p), rf = 1, ln = 1; n   for (long long int i = 1; i <= r; i++) rf = rf * i; n   for (long long int i = 0; i < r; i++) ln = ln * (n - i); n   return ln / rf; n } n bool sbs(pair<long long int, long long int> &a, n          pair<long long int, long long int> &b) { n   return (a.second < b.second); n } n bool sbds(pair<long long int, long long int> &a, n           pair<long long int, long long int> &b) { n   return (a.second > b.second); n } n long long int SUM(vector<long long int> &a, long long int n) { n   long long int sum = 0; n   for (long long int i = 0; i < n; i++) sum += a[i]; n   return sum; n } n long long int chkprm(long long int n) { n   long long int x = 5, s = sqrt(n); n   if (n < 2) return 0; n   if (n < 4) return 1; n   if ((n & 1) == 0) return 0; n   if (n % 3 == 0) return 0; n   while (x <= s) { n     if (n % x == 0) return 0; n     x += 2; n     if (n % x == 0) return 0; n     x += 4; n   } n   return 1; n } n long long int merge(long long int arr[], long long int temp[], n                     long long int left, long long int mid, n                     long long int right) { n   long long int inv_count = 0; n   long long int i = left; n   long long int j = mid; n   long long int k = left; n   while ((i <= mid - 1) && (j <= right)) { n     if (arr[i] <= arr[j]) n       temp[k++] = arr[i++]; n     else { n       temp[k++] = arr[j++]; n       inv_count = inv_count + (mid - i); n     } n   } n   while (i <= mid - 1) temp[k++] = arr[i++]; n   while (j <= right) temp[k++] = arr[j++]; n   for (i = left; i <= right; i++) arr[i] = temp[i]; n   return inv_count; n } n long long int _mergeSort(long long int arr[], long long int temp[], n                          long long int left, long long int right) { n   long long int mid, inv_count = 0; n   if (right > left) { n     mid = (right + left) / 2; n     inv_count = _mergeSort(arr, temp, left, mid); n     inv_count += _mergeSort(arr, temp, mid + 1, right); n     inv_count += merge(arr, temp, left, mid + 1, right); n   } n   return inv_count; n } n long long int countSwaps(long long int arr[], long long int n) { n   long long int temp[n]; n   return _mergeSort(arr, temp, 0, n - 1); n } n void myth() { n   long long int n; n   cin >> n; n   string s; n   cin >> s; n   set<long long int> s1[26]; n   for (long long int i = 0; i < n; i++) s1[s[i] -  a ].insert(i + 1); n   vector<long long int> cnt(n + 1); n   reverse(s.begin(), s.end()); n   for (long long int i = 0; i < n; i++) { n     cnt[*s1[s[i] -  a ].begin()] = i + 1; n     s1[s[i] -  a ].erase(s1[s[i] -  a ].begin()); n   } n   long long int a[n]; n   for (long long int i = 1; i <= n; i++) a[i - 1] = cnt[i]; n   cout << countSwaps(a, n); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int test_case = 1; n   while (test_case--) { n     myth(); n     cout <<   n ; n   } n   cerr <<   n  n        <<  Time Elasped :   << 1.0 * clock() / CLOCKS_PER_SEC <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n void cmin(long long& x, long long y) { n   if (x > y) { n     x = y; n   } n } n int n, a[N]; n long long f[N][2]; n bool best[N][2]; n vector<int> adj[N], answer; n void dfs1(int u, int p) { n   long long min_diff = 0; n   bool go = false; n   for (auto v : adj[u]) { n     if (v != p) { n       go = true; n       dfs1(v, u); n       f[u][0] += f[v][0]; n       f[u][1] += f[v][0]; n       cmin(min_diff, f[v][1] - f[v][0]); n     } n   } n   f[u][1] += min_diff; n   if (!go) { n     f[u][0] = a[u]; n   } else { n     cmin(f[u][0], f[u][1] + a[u]); n   } n } n void dfs2(int u, int p) { n   if (f[u][0] == f[u][1] + a[u]) { n     best[u][1] |= best[u][0]; n     if (best[u][0]) { n       answer.push_back(u); n     } n   } n   long long sumf = 0; n   for (auto v : adj[u]) { n     if (v != p) { n       sumf += f[v][0]; n     } n   } n   vector<int> diff_nodes; n   for (auto v : adj[u]) { n     if (v != p) { n       if (sumf == f[u][0]) { n         best[v][0] |= best[u][0]; n       } n       if (sumf + f[v][1] - f[v][0] == f[u][1] && best[u][1]) { n         best[v][1] = true; n         diff_nodes.push_back(v); n       } else if (sumf + f[v][1] - f[v][0] + a[u] == f[u][0] && best[u][0]) { n         diff_nodes.push_back(v); n       } n     } n   } n   for (auto v : adj[u]) { n     if (v != p) { n       if (diff_nodes.size() > 1) { n         best[v][0] |= true; n       } else if (diff_nodes.size() == 1 && v != diff_nodes.back()) { n         best[v][0] |= true; n       } n       dfs2(v, u); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i < n; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs1(1, 0); n   best[1][0] = true; n   dfs2(1, 0); n   printf( %lld %d n , f[1][0], answer.size()); n   sort(answer.begin(), answer.end()); n   for (auto v : answer) { n     printf( %d  , v); n   } n   return puts(  ), 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n const int INF = (int)(1e9 + 1e6); n const long long LINF = (long long)(4e18); n const double EPS = 1e-9; n const long long mod = 1e9 + 7; n mt19937 ggen; n void solve(); n int main() { n   iostream::sync_with_stdio(false); n   cin.tie(0); n   ggen = mt19937(1337); n   solve(); n } n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   int x, f; n   cin >> x >> f; n   long long ans = 0; n   long long ft = x + f; n   for (int i = 0; i < n; ++i) { n     long long gh = static_cast<long long>(a[i]); n     long long mt = gh / ft; n     ans += mt * f; n     if (gh - mt * ft > x) { n       ans += f; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int x, y; n   cin >> x >> y; n   int tx = x - y; n   int ty = x + y; n   x = tx; n   y = ty; n   if (x < 0) n     cout <<  -1 n ; n   else { n     int l = 1, r = 1e9 + 5; n     while (r - l > 1) { n       int mid = (l + r) / 2; n       if ((1LL * y * (mid - 1) + mid - 1) / mid <= x) n         l = mid; n       else n         r = mid; n     } n     long double ans = y; n     ans /= l; n     ans /= 2.0; n     cout << setprecision(19) << fixed << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nxt() { n   int res; n   scanf( %d , &res); n   return res; n } n bool is_perm(int *p, int n) { n   char used[n]; n   memset(used, 0, sizeof(used)); n   for (int i = 0; i < n; ++i) { n     used[p[i]] = 1; n   } n   for (int i = 0; i < n; ++i) { n     if (!used[i]) { n       return false; n     } n   } n   return true; n } n void solve(int n) { n   int a[n]; n   for (int i = 0; i < n; ++i) { n     a[i] = i + 1; n   } n   do { n     int p[n]; n     p[0] = a[0] % n; n     for (int i = 1; i < n; ++i) { n       p[i] = p[i - 1] * a[i] % n; n     } n     if (is_perm(p, n)) { n       for (int i = 0; i < n; ++i) { n         cout << a[i] <<    ; n       } n       cout << endl; n     } n   } while (next_permutation(a, a + n - 1)); n } n void solveTest(int n) { n   cout <<  YES n ; n   if (n == 1) { n     cout <<  1 n ; n     return; n   } n   if (n == 2) { n     cout <<  1 n2 n ; n     return; n   } n   if (n == 3) { n     cout <<  1 n2 n3 n ; n     return; n   } n   if (n == 4) { n     cout <<  1 n3 n2 n4 n ; n     return; n   } n } n bool isprime(int n) { n   for (int i = 2; i * i <= n; ++i) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n long long powMod(long long a, int n, long long mod) { n   long long ret = 1; n   while (n) { n     if (n & 1) ret = ret * a % mod; n     n >>= 1; n     a = a * a % mod; n   } n   return ret; n } n void solve() { n   int n = nxt(); n   if (n <= 4) { n     solveTest(n); n     return; n   } n   if (!isprime(n)) { n     cout <<  NO n ; n     return; n   } n   int ans[n]; n   ans[0] = 1; n   ans[n - 1] = n; n   long long pw = 1; n   for (int i = 1; i + 1 < n; ++i) { n     ans[i] = (i + 1) * powMod(pw, n - 2, n) % n; n     pw = pw * ans[i] % n; n   } n   cout <<  YES n ; n   for (int i = 0; i < n; ++i) { n     cout << ans[i] <<   n ; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a, b, i, c = 0; n   a = 8 * n; n   b = 9 * n; n   c = b - a; n   cout << b <<     << a << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   std::string data; n   cin >> data; n   long long int counter = 0; n   char ch; n   for (int i = 0; i < data.length(); i++) { n     if (data[i] ==  0 ) n       counter++; n     else n       counter = 0; n   } n   std::string to_join; n   while (counter != 0) { n     counter--; n     data =  0  + data; n   } n   int flag = 0; n   for (int i = 0; i < data.length() / 2; i++) { n     if (data[i] != data[data.length() - i - 1]) { n       flag = 1; n       break; n     } n   } n   if (flag) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[20]; n bool ischange[300000]; n int main() { n   memset(ischange, 0, sizeof ischange); n   int n; n   scanf( %d , &n); n   string a; n   cin >> a; n   for (int i = 1; i <= 9; i++) { n     scanf( %d , &f[i]); n   } n   int ff = 0; n   for (int i = 0; i < a.length(); i++) { n     if (ff == 1) break; n     int now = a[i] -  0 ; n     int change = f[now]; n     if (change > now) { n       ff = 1; n       while (f[a[i] -  0 ] >= a[i] -  0  && i < a.length()) { n         ischange[i] = 1; n         i++; n       } n     } n     if (ff == 1) break; n   } n   for (int i = 0; i < a.length(); i++) { n     if (ischange[i]) n       cout << f[a[i] -  0 ]; n     else n       cout << a[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void show(T *a, int n) { n   for (int i = 0; i < n; i++) cout << a[i] <<     ; n   puts(  ); n } n template <class T> n void queue_clear(T *a, int n) { n   for (int i = 0; i < n; i++) { n     while (!a->empty()) a->pop(); n   } n } n template <class T> n void Bit_add(T *a, int x, int p, int MAX) { n   while (p < MAX) { n     a[p] += x; n     p += p & (-p); n   } n } n template <class T> n T Bit_sum(T *a, int p) { n   T ret = 0; n   while (p) { n     ret += a[p]; n     p -= p & (-p); n   } n   return ret; n } n const int MAXN = 1007; n int d[MAXN], s[MAXN]; n int main() { n   int m, k; n   while (~scanf( %d%d , &m, &k)) { n     int i; n     for (i = 1; i <= m; i++) scanf( %d , d + i); n     for (i = 1; i <= m; i++) scanf( %d , s + i); n     int tank = s[1], mx = s[1]; n     int p = 1, ans = 0; n     while (p <= m) { n       if (tank < d[p]) { n         int t = ((d[p] - tank) + mx - 1) / mx; n         ans += t * k; n         tank += t * mx; n       } n       tank -= d[p]; n       ans += d[p]; n       p++; n       mx = max(mx, s[p]); n       tank += s[p]; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   int i = 0; n   cin >> s; n   int z = 0, o = 0; n   while (s[i] ==  0 ) { n     i++; n   } n   for (; i < s.length(); i++) { n     if (s[i] ==  0 ) { n       z++; n     } else { n       if (!o) { n         o = s.length() - i; n       } n     } n   } n   if (z >= 6 && o >= 7) { n     cout <<  Yes  n          <<   n ; n   } else { n     cout <<  No  n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 1; n char a[N], b[N]; n int f[N][N]; n int res; n int n, m; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) cin >> b[i]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (a[i] == b[j]) { n         f[i][j] = f[i - 1][j - 1] + 2; n       } n       f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]) - 1); n       res = max(res, f[i][j]); n     } n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int dp[1501][1501], sum[1501], tsum[1501], pro, ex[2][100001], c[100001], n     P[1501]; n int sp[1501], gp[1501], inv[1501]; n int power(int a, int n) { n   if (n == 0) return 1; n   int res = power(a, n / 2); n   res = (int)((long long)res * (long long)res % mod); n   if (n % 2) res = (int)((long long)res * (long long)a % mod); n   return res; n } n int main() { n   int n, m, a, b, k, i, j, s, p, q, tmp; n   scanf( %d%d%d%d%d , &n, &m, &a, &b, &k); n   pro = (int)((long long)a * (long long)power(b, mod - 2) % mod); n   for (i = 0; i <= 100000; i++) { n     if (i == 0) { n       ex[0][i] = ex[1][i] = 1; n       c[i] = 1; n     } else { n       ex[1][i] = (int)((long long)ex[1][i - 1] * (long long)(1 - pro) % mod); n       if (ex[1][i] < 0) ex[1][i] += mod; n       ex[0][i] = (int)((long long)ex[0][i - 1] * (long long)pro % mod); n       c[i] = (int)((long long)c[i - 1] * (long long)(k - i + 1) % mod); n       c[i] = (int)((long long)c[i] * (long long)power(i, mod - 2) % mod); n     } n   } n   memset(P, 0, sizeof(P)); n   for (i = 0; i <= m; i++) { n     if (i <= k) { n       P[i] = (int)((long long)c[i] * (long long)ex[0][i] % mod); n       P[i] = (int)((long long)P[i] * (long long)ex[1][k - i] % mod); n     } n     sp[i] = P[i]; n     if (i) sp[i] = (sp[i - 1] + sp[i]) % mod; n     inv[i] = power(P[i], mod - 2); n   } n   memset(dp, 0, sizeof(dp)); n   dp[0][m] = 1; n   for (i = 0; i < n; i++) { n     for (j = 0; j <= m; j++) { n       sum[j] = (int)((long long)P[j] * (long long)dp[i][j] % mod); n       if (j) sum[j] = (sum[j - 1] + sum[j]) % mod; n     } n     for (j = 0; j < m; j++) { n       tsum[j] = (int)((long long)sp[m - 1 - j] * (long long)dp[i][m] % mod); n       tmp = (int)((long long)sp[m - 1 - j] * (long long)dp[i][j] % mod); n       tsum[j] = (tsum[j] - tmp + mod) % mod; n       tsum[j] = (tsum[j] - sum[m - 1 - j] + mod) % mod; n       tsum[j] = (int)((long long)tsum[j] * (long long)P[j] % mod); n       if (j) tsum[j] = (tsum[j - 1] + tsum[j]) % mod; n     } n     dp[i + 1][0] = 0; n     dp[i + 1][m] = tsum[m - 1]; n     for (j = 1; j < m; j++) { n       if (j == 0) n         dp[i + 1][m - j] = tsum[j - 1]; n       else n         dp[i + 1][m - j] = (dp[i + 1][m] - tsum[j - 1] + mod) % mod; n     } n   } n   printf( %d n , dp[n][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF; n int n; n long long v[100005]; n int c[100005]; n long long mx[100005]; n pair<long long, int> st[2]; n int q; n long long a, b; n void solve(long long a, long long b) { n   long long ans = 0; n   st[0].first = 0; n   st[0].second = -2; n   st[1].first = 0; n   st[1].second = -1; n   fill(mx, mx + n, -INF); n   for (int i = 0; i < n; i++) { n     int clr = c[i]; n     long long val = v[i]; n     long long w1, w2, w; n     int td = 1; n     if (st[td].second == clr) td--; n     w1 = st[td].first + v[i] * b; n     w2 = mx[clr] + v[i] * a; n     w = max(w1, w2); n     if (w > mx[clr]) { n       if (st[1].second == clr) { n         st[1].first = w; n       } else if (st[0].second == clr) { n         st[0].first = w; n       } else { n         if (w >= st[1].first) { n           st[0] = st[1]; n           st[1] = make_pair(w, clr); n         } else if (w > st[0].first) { n           st[0] = make_pair(w, clr); n         } n       } n       mx[clr] = w; n       if (st[0] > st[1]) swap(st[0], st[1]); n     } n   } n   for (int i = 0; i < n; i++) { n     ans = max(ans, mx[i]); n   } n   cout << ans << endl; n } n int main() { n   INF = 1.0e18; n   cin >> n >> q; n   for (int i = 0; i < n; i++) cin >> v[i]; n   for (int i = 0; i < n; i++) cin >> c[i], c[i]--; n   for (int i = 0; i < q; i++) cin >> a >> b, solve(a, b); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 500; n using namespace std; n int n, yh, yhuo = 0, huo = 0, yu, x = 0, y; n char pd; n int main() { n   y = 1023; n   x = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     cin >> pd >> yh; n     if (pd ==  & ) x &= yh, y &= yh; n     if (pd ==  | ) x |= yh, y |= yh; n     if (pd ==  ^ ) x ^= yh, y ^= yh; n   } n   huo = 0; n   yhuo = 0; n   for (int i = 0; i <= 9; i++) { n     int a = x & (1 << i), b = y & (1 << i); n     if (a && b == 0) yhuo |= (1 << i); n     if (a == 0 && b == 0) huo |= (1 << i), yhuo |= (1 << i); n     if (a && b) huo |= (1 << i); n   } n   printf( 2 n ); n   printf( | %d n^ %d n , huo, yhuo); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string ss, tt; n   cin >> ss >> tt; n   int l = ss.size(); n   vector<int> s(30); n   vector<int> t(30); n   for (int i = 0; i < l; i++) { n     s[ss[i] -  a ]++; n     t[tt[i] -  a ]++; n   } n   bool ok = false; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] && t[i]) { n       ok = true; n     } n   } n   cout << (ok ?  YES n  :  NO n ); n   return; n } n int main() { n   int q; n   cin >> q; n   while (q--) { n     solve(); n   } n } n