#include <bits/stdc++.h> n using namespace std; n const int N = 15; n const char inf =  z ; n bool g[N][N]; n vector<string> gen_cand_strings(int n); n void rec_gen(vector<string>& ans, string& cur, char c, int n); n vector<string> get_good_strings(vector<string>& cand, int n); n vector<string> gen_cand2_strings(int n); n void rec_gen2(vector<string>& ans, string& cur, char c, int n); n bool is_ok(string s, vector<string>& good, int n); n bool is_ok_rec(string& s, vector<string>& good, vector<bool>& done, int c, n                int n); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < m; ++i) { n     int u, v; n     cin >> u >> v; n     --u; n     --v; n     g[u][v] = g[v][u] = 1; n   } n   vector<string> cand = gen_cand_strings(n); n   vector<string> good = get_good_strings(cand, n); n   sort(good.begin(), good.end()); n   vector<string> cand2 = gen_cand2_strings(n); n   sort(cand2.begin(), cand2.end()); n   cand2.erase(unique(cand2.begin(), cand2.end()), cand2.end()); n   long long ans = 0; n   for (auto& s : cand2) { n     if (is_ok(s, good, n)) { n       long long tmp = 1; n       int cnt = *max_element(s.begin(), s.end()) + 1; n       for (int i = 0; i < cnt; ++i) { n         tmp *= (k - i); n       } n       ans += tmp; n     } else { n     } n   } n   cout << ans <<   n ; n } n vector<string> gen_cand_strings(int n) { n   vector<string> ans; n   string base(n, inf); n   rec_gen(ans, base, 0, n); n   return ans; n } n void rec_gen(vector<string>& ans, string& cur, char c, int n) { n   for (int i = 0; i < n; ++i) { n     if (cur[i] == inf) { n       cur[i] = c; n       for (int j = i + 1; j < n; ++j) { n         if (cur[j] == inf) { n           cur[j] = c; n           rec_gen(ans, cur, c + 1, n); n           cur[j] = inf; n         } n       } n       cur[i] = inf; n       return; n     } n   } n   ans.push_back(cur); n } n vector<string> get_good_strings(vector<string>& cand, int n) { n   vector<string> good; n   for (auto& s : cand) { n     vector<vector<int>> pos(n / 2); n     for (int i = 0; i < n; ++i) { n       pos[s[i]].push_back(i); n     } n     int tot = (1 << (n / 2)); n     vector<vector<int>> dp(tot, vector<int>(n / 2, 0)); n     for (int i = 0; i < n / 2; ++i) { n       dp[(1 << i)][i] = g[pos[i][0]][pos[i][1]]; n     } n     for (int mask = 0; mask < tot; ++mask) { n       if (__builtin_popcount(mask) < 2) { n         continue; n       } n       for (int i = 0; i < n / 2; ++i) { n         if (!((mask >> i) & 1)) { n           continue; n         } n         int u0 = pos[i][0], u1 = pos[i][1]; n         int submask = mask - (1 << i); n         for (int j = 0; j < n / 2; ++j) { n           if (dp[submask][j]) { n             int v0 = pos[j][0], v1 = pos[j][1]; n             if ((g[u0][v0] and g[u1][v1]) or (g[u0][v1] and g[u1][v0])) { n               dp[mask][i] = true; n               break; n             } n           } n         } n       } n     } n     for (int i = 0; i < n / 2; ++i) { n       if (dp[tot - 1][i]) { n         good.push_back(s); n         break; n       } n     } n   } n   return good; n } n vector<string> gen_cand2_strings(int n) { n   vector<string> ans; n   string base(n, inf); n   rec_gen2(ans, base, 0, n); n   return ans; n } n void rec_gen2(vector<string>& ans, string& cur, char c, int n) { n   for (int i = 0; i < n; ++i) { n     if (cur[i] == inf) { n       for (int j = i + 1; j < n; ++j) { n         if (cur[j] == inf) { n           for (int nc = 0; nc <= c; ++nc) { n             cur[i] = cur[j] = nc; n             rec_gen2(ans, cur, max(int(c), nc + 1), n); n             cur[i] = cur[j] = inf; n           } n         } n       } n       return; n     } n   } n   ans.push_back(cur); n } n bool is_ok(string s, vector<string>& good, int n) { n   vector<bool> done(n, 0); n   return is_ok_rec(s, good, done, 0, n); n } n bool is_ok_rec(string& s, vector<string>& good, vector<bool>& done, int c, n                int n) { n   if (c == n / 2) { n     auto it = lower_bound(good.begin(), good.end(), s); n     if (it != good.end() and *it == s) { n       return true; n     } n   } else { n     for (int i = 0; i < n; ++i) { n       if (!done[i]) { n         for (int j = i + 1; j < n; ++j) { n           if (!done[j] and s[i] == s[j]) { n             char tmp = s[i]; n             s[i] = s[j] = c; n             done[i] = done[j] = true; n             if (is_ok_rec(s, good, done, c + 1, n)) { n               return true; n             } n             s[i] = s[j] = tmp; n             done[i] = done[j] = false; n           } n         } n         break; n       } n     } n   } n   return false; n } n


#include <bits/stdc++.h> n #pragma optimize( O3 ) n using namespace std; n const int up = 1e5 + 5; n int la, ra, ta, lb, rb, tb; n int gcd(int x, int y) { n   if (x == 0 || y == 0) { n     return x + y; n   } n   int r = x % y; n   while (r) { n     x = y; n     y = r; n     r = x % y; n   } n   return y; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> la >> ra >> ta; n   cin >> lb >> rb >> tb; n   if (lb < la) { n     swap(la, lb); n     swap(ra, rb); n     swap(ta, tb); n   } n   int g = gcd(ta, tb); n   int rem = (lb - la) % g; n   int res = 0; n   if (rem != 0) { n     res = max(res, min(g - rem + ra - la, rb - lb) - (g - rem) + 1); n     res = max(res, min(ra - la, rem + rb - lb) - rem + 1); n   } else { n     res = max(res, min(ra - la, rb - lb) + 1); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 2e18; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> a(n); n   map<long long, long long> dp; n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     dp[a[i]] = dp[a[i] - 1] + 1; n   } n   long long x, mx = -INF; n   for (auto &[last, len] : dp) { n     if (len > mx) { n       mx = len; n       x = last; n     } n   } n   cout << mx <<   n ; n   long long l = x - mx + 1; n   for (long long i = 0; i < n; ++i) { n     if (a[i] == l) { n       cout << i + 1 <<    ; n       ++l; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n set<long long> sset; n void add(int n) { n   set<long long>::iterator it = sset.find(n); n   if (it == sset.end()) { n     sset.insert(n); n   } else { n     sset.erase(it); n     add(n + 1); n   } n } n int main() { n   cin.sync_with_stdio(false); n   int n; n   cin >> n; n   while (n--) { n     int t; n     cin >> t; n     add(t); n   } n   set<long long>::iterator it = sset.end(); n   it--; n   cout << *it - sset.size() + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 1e3 + 10; n int a[mx], b[mx]; n int main() { n   int n, k; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i); n   scanf( %d , &k); n   for (int i = 1; i <= n; i++) n     if (k <= b[i]) return 0 * printf( %d n , n - i + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   a = abs(a - b); n   b = a / 2; n   a = a / 2 + (a & 1); n   cout << (a * a + a) / 2 + (b * b + b) / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int ask(int l) { n   cout <<  ?  ; n   for (int i = 0; i < n - 1; i++) cout << 1 <<    ; n   cout << l << endl; n   cout.flush(); n   int k; n   cin >> k; n   if (k == 0) n     return 1; n   else n     return 0; n } n int ask1(int l, int x) { n   cout <<  ?  ; n   for (int i = 0; i < n - 1; i++) { n     cout << x <<    ; n   } n   cout << l <<   n ; n   cout.flush(); n   int k; n   cin >> k; n   return k; n } n int main() { n   cin >> n; n   int t = 0; n   int k = n; n   for (int i = 0; i < n - 1; ++i) { n     if (ask(i + 2)) { n       break; n     } n     k--; n   } n   int ans[n]; n   ans[n - 1] = k; n   for (int i = 1; i <= n; i++) { n     if (i != k) { n       int m = ask1(i, k); n       ans[m - 1] = i; n     } n   } n   cout <<  !  ; n   for (int i = 0; i < n; ++i) cout << ans[i] <<    ; n   cout <<   n ; n   cout.flush(); n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   vector<int> a; n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     a.push_back(x); n   } n   int b = 0, c = n - 1; n   while (a[b + 1] > a[b] && b < n - 1) { n     b++; n   } n   while (a[c - 1] > a[c] && c > 0) { n     c--; n   } n   int j = b; n   while (a[j] == a[j + 1]) { n     j++; n   } n   if (j == c) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[100001]; n vector<long long int> adj[100001]; n long long int ans[21] = {}; n long long int dp[100001][21][2]; n void dfs(long long int i, long long int par) { n   long long int u = 0; n   for (long long int j = 0; j < adj[i].size(); j++) { n     long long int x = adj[i][j]; n     if (x != par) { n       dfs(x, i); n       if (u == 0) { n         u = 1; n         long long int z = a[i]; n         for (long long int k = 0; k <= 20; k++) { n           if (z % 2) { n             dp[i][k][1] = dp[x][k][0] + 1; n             dp[i][k][0] = dp[x][k][1]; n           } else { n             dp[i][k][1] = dp[x][k][1]; n             dp[i][k][0] = dp[x][k][0] + 1; n           } n           z = z / 2; n           ans[k] += dp[i][k][1]; n         } n       } else { n         long long int z = a[i]; n         for (long long int k = 0; k <= 20; k++) { n           ans[k] += dp[i][k][1] * dp[x][k][0] + dp[i][k][0] * dp[x][k][1]; n           if (z % 2) { n             dp[i][k][1] += dp[x][k][0]; n             dp[i][k][0] += dp[x][k][1]; n           } else { n             dp[i][k][1] += dp[x][k][1]; n             dp[i][k][0] += dp[x][k][0]; n           } n           z = z / 2; n         } n       } n     } n   } n   if (u == 0) { n     long long int z = a[i]; n     for (long long int k = 0; k <= 20; k++) { n       if (z % 2) { n         ans[k]++; n         dp[i][k][1]++; n       } else { n         dp[i][k][0]++; n       } n       z = z / 2; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   for (long long int i = 1; i <= n; i++) cin >> a[i]; n   for (long long int i = 1; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1, 0); n   long long int f = 1, pt = 0; n   for (long long int i = 0; i <= 20; i++) { n     pt += f * ans[i]; n     f = f * 2; n   } n   cout << pt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     n *= 2; n     vector<int> a, b, x; n     for (int i = 0; i < n; i++) { n       int tn; n       cin >> tn; n       x.push_back(tn); n     } n     sort(x.begin(), x.end()); n     cout << x[n / 2] - x[n / 2 - 1] << endl; n   } n } n


#include<bits/stdc++.h> n #define rep(i, a, n) for(int i = a; i <= n; i++) n #define _rep(i, n, a) for(int i = n; i >= a; i--) n typedef long long LL; n using namespace std; n const int maxn = 2e5 + 10; n const int mod = 1004535809; n inline LL read(){ n  LL x = 0, fl = 1; char c = getchar(); n  while (c <  0  || c >  9 ) { if(c ==  - ) fl = -1; c = getchar(); } n  while (c >=  0  && c <=  9 ) { x = x * 10 + c -  0 ; c = getchar(); } n  return x * fl; n } n int n, m, t; n LL cnt[maxn]; n int main(){ n  cin >> t; n  while(t--){ n   cin >> n; n   memset(cnt, 0, (n + 5) * sizeof(LL)); n   int x; n   rep(i, 1, n) cin >> x, cnt[x]++; n   LL ans = 0; n   rep(i, 2, n - 1) ans += cnt[i - 1] * cnt[i] * cnt[i + 1]; n   rep(i, 1, n - 1) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 1]; n   rep(i, 1, n - 1) ans += cnt[i] * cnt[i + 1] * (cnt[i + 1] - 1) / 2; n   rep(i, 1, n - 2) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 2]; n   rep(i, 1, n - 2) ans += cnt[i] * cnt[i + 2] * (cnt[i + 2] - 1) / 2; n   rep(i, 1, n) ans += cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6; n   cout << ans << endl; n  } n } n  n


#include <bits/stdc++.h> n const int maxnm = 9 + 2; n int n, m; n char map[maxnm][maxnm], best[maxnm][maxnm]; n bool shape[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}}, n                        {{0, 1, 0}, {0, 1, 0}, {1, 1, 1}}, n                        {{1, 0, 0}, {1, 1, 1}, {1, 0, 0}}, n                        {{0, 0, 1}, {1, 1, 1}, {0, 0, 1}}}; n inline bool valid(int x, int y, int k) { n   if (x < 1 || x + 2 > n || y < 1 || y + 2 > m) return false; n   for (int i = 0; i <= 2; ++i) n     for (int j = 0; j <= 2; ++j) { n       if (shape[k][i][j] && map[x + i][y + j] !=  . ) return false; n     } n   return true; n } n inline void set(int x, int y, int k, char c) { n   for (int i = 0; i <= 2; ++i) n     for (int j = 0; j <= 2; ++j) { n       if (shape[k][i][j]) map[x + i][y + j] = c; n     } n } n int ans; n void dfs(int x, int y, int now) { n   if (now + ((n - x - 1) * m + m - y + 1) / 5 <= ans) return; n   if (y > m) return dfs(x + 1, 1, now); n   if (x <= n) { n     for (int i = x; i <= n; ++i) n       for (int j = (i == x ? y : 1); j <= m; ++j) { n         for (int k = 0; k < 4; ++k) { n           if (!valid(i, j, k)) continue; n           set(i, j, k,  A  + now); n           dfs(i, j + 1, now + 1); n           set(i, j, k,  . ); n         } n       } n   } n   if (now > ans) { n     ans = now; n     memcpy(best, map, sizeof(map)); n   } n } n int main() { n   int a; n   a = 1; n   a = 0; n   a = (a == 1); n   scanf( %d%d , &n, &m); n   memset(map,  . , sizeof(map)); n   memset(best,  . , sizeof(best)); n   dfs(1, 1, 0); n   printf( %d n , ans); n   for (int i = 1; i <= n; ++i, putchar(  n )) n     for (int j = 1; j <= m; ++j) { n       putchar(best[i][j]); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void _R(T &x) { n   cin >> x; n } n void _R(int &x) { scanf( %d , &x); } n void _R(long long &x) { scanf( %lld , &x); } n void _R(double &x) { scanf( %lf , &x); } n void _R(char &x) { scanf(  %c , &x); } n void _R(char *x) { scanf( %s , x); } n void R() {} n template <class T, class... U> n void R(T &head, U &...tail) { n   _R(head); n   R(tail...); n } n template <class T> n void _W(const T &x) { n   cout << x; n } n void _W(const int &x) { printf( %d , x); } n void _W(const long long &x) { printf( %lld , x); } n void _W(const double &x) { printf( %.16f , x); } n void _W(const char &x) { putchar(x); } n void _W(const char *x) { printf( %s , x); } n template <class T, class U> n void _W(const pair<T, U> &x) { n   _W(x.first); n   putchar(   ); n   _W(x.second); n } n template <class T> n void _W(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _W(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void W() {} n template <class T, class... U> n void W(const T &head, const U &...tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n int MOD = 1e9 + 7; n void ADD(long long &x, long long v) { n   x = (x + v) % MOD; n   if (x < 0) x += MOD; n } n const int SIZE = 210; n int AA[SIZE][SIZE], BB[SIZE][SIZE]; n int n, m; n int col[SIZE], row[SIZE]; n void check(int x) { n   for (int i = 0; i < (m); ++i) { n     col[i] = (i >= x) ^ AA[0][i]; n     BB[0][i] = col[i] ^ AA[0][i]; n   } n   for (int i = (1); i < (n); ++i) { n     bool suc = 0; n     for (int j = 0; j < (2); ++j) { n       row[i] = AA[i][0] ^ j ^ col[0]; n       for (int k = 0; k < (m); ++k) { n         BB[i][k] = AA[i][k] ^ row[i] ^ col[k]; n       } n       if (BB[i][0] < BB[i - 1][m - 1]) continue; n       bool fail = 0; n       for (int k = (1); k < (m); ++k) { n         if (BB[i][k] < BB[i][k - 1]) { n           fail = 1; n         } n       } n       if (fail) continue; n       suc = 1; n       break; n     } n     if (!suc) return; n   } n   W( YES ); n   for (int i = 0; i < (n); ++i) _W(row[i]); n   W(  ); n   for (int i = 0; i < (m); ++i) _W(col[i]); n   W(  ); n   exit(0); n } n int main() { n   R(n, m); n   for (int i = 0; i < (n); ++i) n     for (int j = 0; j < (m); ++j) { n       R(AA[i][j]); n     } n   for (int i = (1); i <= (m); ++i) { n     check(i); n   } n   W( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n long long spf[MAXN]; n long long min1[MAXN]; n long long min2[MAXN]; n void sieve() { n   spf[1] = 1; n   for (int i = 2; i < MAXN; i++) spf[i] = i; n   for (int i = 4; i < MAXN; i += 2) spf[i] = 2; n   for (int i = 3; i * i < MAXN; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j < MAXN; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n vector<pair<int, int>> getFactorization(int x) { n   vector<pair<int, int>> ret; n   while (x != 1) { n     int cur = spf[x]; n     int cnt = 0; n     while (x && spf[x] == cur) { n       ++cnt; n       x = x / spf[x]; n     } n     ret.push_back({cur, cnt}); n   } n   return ret; n } n void solve() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (auto &a : arr) { n     cin >> a; n   } n   sieve(); n   memset(min1, -1, sizeof(min1)); n   memset(min2, -1, sizeof(min2)); n   vector<int> many(MAXN, 0); n   for (int i = 0; i < n; ++i) { n     int x = arr[i]; n     vector<pair<int, int>> fact = getFactorization(x); n     for (auto ff : fact) { n       int p = ff.first; n       int c = ff.second; n       if (min1[p] == -1) { n         min1[p] = c; n       } else if (min2[p] == -1) { n         int m = min1[p]; n         if (c <= m) { n           min1[p] = c; n           min2[p] = m; n         } else { n           min1[p] = m; n           min2[p] = c; n         } n       } else { n         int m1 = min1[p]; n         int m2 = min2[p]; n         if (c <= m1) { n           min1[p] = c; n           min2[p] = m1; n         } else if (c <= m2) { n           min2[p] = m2; n         } n       } n       ++many[p]; n     } n   } n   long long res = 1; n   for (int i = 2; i < MAXN; ++i) { n     if (many[i] == n) { n       res *= pow(1ll * i, min2[i]); n     } else if (many[i] == n - 1) { n       res *= pow(1ll * i, min1[i]); n     } n   } n   cout << res <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n bool vis[10005]; n long long n, m, k; n int main() { n   cin >> n >> m >> k; n   if ((n * m * 2) % k != 0) n     puts( NO ); n   else { n     puts( YES ); n     puts( 0 0 ); n     if ((n * 2) % k == 0) { n       printf( %lld 0 n , n * 2 / k); n       printf( %lld %lld n , n / 2, m); n     } else if ((m * 2) % k == 0) { n       printf( %lld 0 n , n); n       printf( %lld %lld n , n / 2, m * 2 / k); n     } else { n       for (int i = 2; i * i <= k; i++) { n         if (k % i == 0) { n           while (k % i == 0) { n             v.push_back(i); n             k /= i; n           } n         } n       } n       if (k != 1) v.push_back(k); n       long long len = v.size(), N = n, M = m; n       for (int i = 0; i < len; i++) { n         if (N % v[i] == 0) { n           N /= v[i]; n           vis[i] = 1; n         } n       } n       for (int i = 0; i < len; i++) { n         if (vis[i]) continue; n         if (M % v[i] == 0) { n           M /= v[i]; n           vis[i] = 1; n         } n       } n       long long cnt = 2; n       for (int i = 0; i < len; i++) { n         if (!vis[i]) cnt = 1; n       } n       if (N < n) { n         printf( %lld 0 n , N * cnt); n         printf( %lld %lld n , N, M); n       } else { n         printf( %lld 0 n , N); n         printf( %lld %lld n , N, M * cnt); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-11; n int n, d; n const int M = 30001; n int f[M][250 * 2]; n int v[M]; n int solve(int i, int j) { n   if (i >= M) return 0; n   int jj = j - (d - 250); n   if (f[i][jj] != -1) return f[i][jj]; n   f[i][jj] = 0; n   int res = 0; n   if (j == 1) n     res += max(solve(i + j, j), solve(i + j + 1, j + 1)) + v[i]; n   else n     res += max(solve(i + j - 1, j - 1), n                max(solve(i + j, j), solve(i + j + 1, j + 1))) + n            v[i]; n   return f[i][jj] = res; n } n int main() { n   ios_base::sync_with_stdio(false); n   for (int i = 0; i < (int)M; i++) n     for (int j = 0; j < (int)250 * 2; j++) f[i][j] = -1; n   cin >> n >> d; n   for (int i = 0; i < (int)n; i++) { n     int j; n     cin >> j; n     v[j]++; n   } n   cout << solve(d, d) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000100, M = 100100, K = 1000100, mod = 1000000007; n int n, m, k, l = N, r = 0, tot = 0, p[K] = {1}; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1, u, v; i <= m; ++i) { n     scanf( %d%d , &u, &v); n     if (v - u > 1) { n       if (v - u != k + 1) { n         puts( 0 ); n         return 0; n       } n       l = min(l, u); n       r = max(r, u); n       ++tot; n     } n   } n   for (int i = 1; i <= k; ++i) p[i] = p[i - 1] * 2 % mod; n   if (l == N && r == 0) { n     int ans = 1; n     for (int i = 1; i <= n - k + 1; ++i) n       ans = (ans + p[min(k, n - i - k - 1)]) % mod; n     printf( %d n , ans); n   } else { n     int ans = 0; n     for (int i = 1; i <= n - k + 1; ++i) n       if (i <= l && i + k >= r) n         ans = (ans + p[min(k, n - i - k - 1) - tot + (i == l)]) % mod; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long UNDEF = -1; n const int INF = 1 << 25; n template <typename T> n inline bool chkmax(T& aa, T bb) { n   return aa < bb ? aa = bb, true : false; n } n template <typename T> n inline bool chkmin(T& aa, T bb) { n   return aa > bb ? aa = bb, true : false; n } n static char stdinBuffer[1024]; n static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer); n static const char* stdinPos = stdinDataEnd; n void readAhead(size_t amount) { n   size_t remaining = stdinDataEnd - stdinPos; n   if (remaining < amount) { n     memmove(stdinBuffer, stdinPos, remaining); n     size_t sz = fread(stdinBuffer + remaining, 1, n                       sizeof(stdinBuffer) - remaining, stdin); n     stdinPos = stdinBuffer; n     stdinDataEnd = stdinBuffer + remaining + sz; n     if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0; n   } n } n int readInt() { n   readAhead(16); n   int x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n char readCh() { n   readAhead(16); n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   char ans = *stdinPos; n   ++stdinPos; n   return ans; n } n const int mn = 1000000; n pair<int, int> vp[mn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n = readInt(); n   for (int i = 0; i < n; i++) { n     int val = readInt(); n     vp[i] = make_pair(val, i); n   } n   sort(vp, vp + n); n   long long final = 0; n   long long sign = -1; n   for (int k = 0; k < 2; k++) { n     set<int> s; n     s.insert(-1); n     s.insert(n); n     for (int i = 0; i < n; i++) { n       int x = vp[i].second; n       auto got = s.insert(x); n       auto it = got.first; n       auto lit = it; n       --lit; n       auto rit = it; n       ++rit; n       long long l = x - *lit; n       long long r = *rit - x; n       long long prod = l * r; n       long long val = (long long)vp[i].first * (long long)prod * sign; n       final += val; n     } n     reverse(vp, vp + n); n     sign = -sign; n   } n   printf( %lld n , final); 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 n; n     cin >> n; n     int maxi = 0, mini = 1000000000; n     vector<long long int> a(n, 0); n     long long int xor1 = 0; n     long long int sum1 = 0; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       xor1 ^= a[i]; n       sum1 += a[i]; n     } n     sum1 += xor1; n     cout << 2 << endl << xor1 <<     << sum1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char S[111111]; n long long cnt1[26], cnt2[26 * 26]; n int main() { n   scanf( %s , S); n   int len = strlen(S); n   for (int i = 0; i < len; i++) { n     for (int j = 0; j < 26; j++) cnt2[26 * j + S[i] -  a ] += cnt1[j]; n     cnt1[S[i] -  a ]++; n   } n   long long ans = 0; n   for (int i = 0; i < 26; i++) ans = max(ans, cnt1[i]); n   for (int i = 0; i < 26 * 26; i++) ans = max(ans, cnt2[i]); n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d = 2; n bool P[100100]; n int A[100100]; n vector<pair<int, int> > R; n void criba() { n   for (int i = 0; i < 100100; i++) P[i] = 1; n   P[0] = 0; n   P[1] = 0; n   for (int i = 2; i < 100100; i++) { n     if (P[i]) { n       for (int j = 2 * i; j < 100100; j += i) P[j] = 0; n     } n   } n } n void solve(int a, int b) { n   if (a == b) return; n   if (a > b) swap(a, b); n   for (int i = b; i > a; i--) n     if (P[i - a + 1]) { n       swap(A[a], A[i]); n       R.push_back(make_pair(a, i)); n       solve(i, b); n       break; n     } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> A[i]; n   criba(); n   for (int i = 1; i <= n; i++) { n     while (A[i] != i) solve(i, A[i]); n   } n   cout << R.size() << endl; n   for (int i = 0; i < R.size(); i++) { n     cout << R[i].first <<     << R[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100100; n inline long long int gcd(long long int ga, long long int gb) { n   if (!gb) return ga; n   return gcd(gb, ga % gb); n } n inline long long int lcm(long long int a, long long int b, long long int c) { n   long long int ans = a * b / gcd(a, b); n   return ans * c / gcd(ans, c); n } n int main() { n   long long int n; n   scanf( %lld , &n); n   if (n == 1) n     printf( 1 ); n   else if (n == 2) n     printf( 2 ); n   else if (n & 1) n     printf( %lld , n * (n - 1) * (n - 2)); n   else { n     long long int ans(1); n     for (int i = 1; i <= n; ++i) ans = max(ans, lcm(n, n - 1, i)); n     printf( %lld , max(ans, max((n - 1) * (n - 2) * (n - 3), n                                 n * (n - 1) * (n - 2) / 2))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, a, b, s = 0; n   cin >> n; n   map<int, int> m1, m2; n   for (i = 1; i < n + 1; ++i) { n     int a, b; n     cin >> a >> b; n     s += m1[a + b]++; n     s += m2[a - b]++; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double n, m; n   scanf( %lf %lf , &n, &m); n   printf( %.6lf , pow(1.000000011, m) * n); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int b, x; n   double a, c; n   cin >> a >> b >> c; n   a = ceil(a * (c / 100)); n   x = a; n   x -= b; n   if (x < 1) x = 0; n   cout << x << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int a[1200]; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= 2 * n; i++) scanf( %d , &a[i]); n     sort(a + 1, a + 2 * n + 1); n     if (a[n] == a[n + 1]) n       printf( NO n ); n     else n       printf( YES n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 30; n class Solution; n class LinearBasis { n  public: n   friend class Solution; n   LinearBasis() : size(0) { fill(begin(bs), end(bs), 0); } n   LinearBasis& operator=(const LinearBasis& other) { n     copy(begin(other.bs), end(other.bs), begin(bs)); n     size = other.size; n     return *this; n   } n   void add(int num) { n     for (int i = 0; i < N; ++i) { n       if (num & (1 << i)) { n         if (bs[i] == 0) { n           bs[i] = num; n           ++size; n           break; n         } else { n           num ^= bs[i]; n         } n       } n     } n   } n   bool isValid(int num) { n     if (num == 0) { n       return true; n     } n     for (int i = 0; i < N; ++i) { n       if (num & (1 << i)) { n         num ^= bs[i]; n         if (num == 0) { n           return true; n         } n       } n     } n     return false; n   } n  n  protected: n   int bs[N]; n   int size; n }; n class Solution { n  public: n   Solution(vector<int>& _A, int n) : nums(_A), size(n) { init(); } n   int query(int l, int x) { n     if (l <= 0) { n       return 0; n     } n     l = min(l, size); n     if (lbs[l].isValid(x)) { n       return powM(2, l - lbs[l].size); n     } else { n       return 0; n     } n   } n  n  private: n   int size; n   vector<int> nums; n   vector<LinearBasis> lbs; n   const int M = 1e9 + 7; n   void init() { n     lbs.clear(); n     lbs.resize(size + 1); n     for (int i = 0; i < size; ++i) { n       int a = nums[i]; n       lbs[i + 1] = lbs[i]; n       lbs[i + 1].add(a); n     } n   } n   long long normalize(long long a) { n     a %= M; n     if (a < 0) { n       a += M; n     } n     return a; n   } n   long long addM(long long a, long long b) { return normalize(a + b); } n   long long mulM(long long a, long long b) { return normalize(a * b); } n   long long powM(long long x, long long e) { n     long long res = 1; n     while (e > 0) { n       if (e & 0x1) { n         res = mulM(res, x); n       } n       x = mulM(x, x); n       e >>= 1; n     } n     return res; n   } n }; n int main(int argc, char** argv) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   vector<int> nums(n); n   for (int i = 0; i < n; ++i) { n     cin >> nums[i]; n   } n   Solution sol(nums, n); n   for (int i = 0, l = 0, x = 0; i < q; ++i) { n     cin >> l >> x; n     cout << sol.query(l, x) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 30; i >= 0; i--) { n     if (n >> i & 1) printf( %d  , i + 1); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[100], b[100]; n int res[100][3001][101] = {0}; n bool us[100][3001][101] = {0}; n const int mod = 1000000007; n int work(int ll, int pr = -1, int lpred = -1) { n   if (ll < 0) return 0; n   if (ll == 0) return 1; n   if (pr != -1 && us[pr][ll][lpred] != 0) return res[pr][ll][lpred]; n   int r = 0; n   for (int i = 0; i < n; i++) n     if (i != pr) { n       if ((lpred == -1) || (a[i] == lpred)) n         r = (r + work(ll - a[i], i, b[i])) % mod; n       if ((a[i] != b[i]) && ((lpred == -1) || (b[i] == lpred))) n         r = (r + work(ll - b[i], i, a[i])) % mod; n     } n   if (pr != -1) { n     res[pr][ll][lpred] = r; n     us[pr][ll][lpred] = 1; n   } n   return r; n } n int main() { n   ios_base::sync_with_stdio(false); n   int l; n   cin >> n >> l; n   for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; n   cout << work(l); n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 2e6 + 10; n long long n, a[maxn], Begin[maxn], Next[maxn], To[maxn], e, sum; n bool vis[maxn], use[maxn]; n inline void add(long long u, long long v) { n   To[++e] = v; n   Next[e] = Begin[u]; n   Begin[u] = e; n } n inline void DFS(long long u, long long op) { n   if (vis[u]) return; n   vis[u] = true; n   if (op == 0) { n     use[u] = true; n     sum += u; n   } n   for (long long i = Begin[u]; i; i = Next[i]) DFS(To[i], op ^ 1); n } n signed main() { n   scanf( %lld , &n); n   if (n % 2 == 0) { n     puts( First ); n     for (long long i = (1), _end_ = (n); i <= _end_; ++i) printf( %lld  , i); n     for (long long i = (1), _end_ = (n); i <= _end_; ++i) printf( %lld  , i); n     fflush(stdout); n     return 0; n   } n   puts( Second ); n   fflush(stdout); n   for (long long i = (1), _end_ = (n + n); i <= _end_; ++i) { n     long long x; n     scanf( %lld , &x); n     if (a[x]) { n       add(a[x], i); n       add(i, a[x]); n     } else n       a[x] = i; n   } n   for (long long i = (1), _end_ = (n); i <= _end_; ++i) { n     add(i, i + n); n     add(i + n, i); n   } n   for (long long i = (1), _end_ = (n + n); i <= _end_; ++i) n     if (!vis[i]) DFS(i, 0); n   if (sum % (n + n) == 0) { n     for (long long i = (1), _end_ = (n + n); i <= _end_; ++i) n       if (use[i]) printf( %lld  , i); n   } else { n     for (long long i = (1), _end_ = (n + n); i <= _end_; ++i) n       if (!use[i]) printf( %lld  , i); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 gen(chrono::system_clock::now().time_since_epoch().count()); n const int M = 3e5 + 7; n const int N = 1e6 + 7; n int n, q, l, r, t[N * 4], ans[N], k, x, tn = 1; n map<int, vector<int> > p; n map<int, vector<pair<int, int> > > otr; n map<int, vector<pair<int, int> > > R; n void update(int v, int tl, int tr, int pos, int x) { n   if (tr == tl + 1) { n     t[v] = min(t[v], x); n     return; n   } n   int mid = (tl + tr) / 2; n   if (pos < mid) n     update(v << 1, tl, mid, pos, x); n   else n     update((v << 1) + 1, mid, tr, pos, x); n   t[v] = min(t[v << 1], t[(v << 1) + 1]); n   return; n } n long long query(int v, int tl, int tr, int l, int r) { n   if (r <= tl || tr <= l) return 1e9; n   if (l <= tl && tr <= r) return t[v]; n   int mid = (tl + tr) / 2; n   return min(query(v << 1, tl, mid, l, r), query((v << 1) + 1, mid, tr, l, r)); n } n int query(int l, int r) { return query(1, 0, tn, l, r); } n void update(int pos, int x) { n   update(1, 0, tn, pos, x); n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> q; n   while (tn < N) tn <<= 1; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (p[x].size()) otr[i].push_back({p[x].back(), i - p[x].back()}); n     p[x].push_back(i); n   } n   for (int i = 0; i < q; i++) { n     cin >> l >> r; n     l--; n     r--; n     R[r].push_back({l, i}); n   } n   for (int i = 1; i < tn * 2; i++) t[i] = 1e9 + 7; n   for (int i = 0; i < q; i++) ans[i] = 1e9 + 7; n   for (int i = 1; i < N; i++) { n     for (int j = 0; j < otr[i].size(); j++) n       update(otr[i][j].first, otr[i][j].second); n     for (int j = 0; j < R[i].size(); j++) n       ans[R[i][j].second] = query(R[i][j].first, i + 1); n   } n   for (int i = 0; i < q; i++) cout << (ans[i] >= n * 2 ? -1 : ans[i]) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<int> res; n std::vector<int> adj[200005]; n std::vector<int> DEPTH(200005); n std::vector<int> NODENUM(200005); n std::vector<int> funct(200005); n vector<bool> taken(200005); n vector<bool> visited(200005); n int dfs(int v, int depth) { n   int nodeNum = 0; n   visited[v] = 1; n   DEPTH[v] = depth; n   for (int u : adj[v]) { n     if (!visited[u]) { n       nodeNum += dfs(u, depth + 1); n     } n   } n   NODENUM[v] = nodeNum; n   return NODENUM[v] + 1; n } n long long dfsV2(int v) { n   visited[v] = 1; n   long long ans = 0; n   for (int u : adj[v]) { n     if (!visited[u]) { n       if (taken[u]) { n         ans += (long long)(NODENUM[u] + 1) * DEPTH[u]; n       } else n         ans += (long long)dfsV2(u); n     } n   } n   return ans; n } n bool func(int x, int y) { n   if (funct[x] > funct[y]) return true; n   return false; n } n void solve() { n   int n, k, x, y, i; n   cin >> n >> k; n   for (i = 0; i < n - 1; i++) { n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1, 0); n   for (i = 1; i <= n; i++) { n     funct[i] = DEPTH[i] - NODENUM[i]; n     res.push_back(i); n   } n   sort(res.begin(), res.end(), func); n   for (i = 0; i < k; i++) { n     taken[res[i]] = 1; n   } n   for (i = 0; i < n + 2; i++) { n     visited[i] = 0; n   } n   cout << dfsV2(1) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, dig = 0, rem; n   cin >> n; n   while (n != 0) { n     rem = n % 10; n     if (rem == 4 || rem == 7) { n       dig++; n     } n     n = n / 10; n   } n   if (dig == 4 || dig == 7) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int place_to_score[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; n int t, n; n map<string, int> ids; n int next_id = 1; n char names[50][64]; n char tmp[64]; n int score[50]; n int places[50][50]; n int main() { n   scanf( %d , &t); n   for (int i = 0; i < t; i++) { n     scanf( %d , &n); n     int place = 0; n     for (int j = 0; j < n; j++) { n       scanf( %s , tmp); n       int id = ids[tmp]; n       if (!id) { n         ids[tmp] = id = next_id++; n         strcpy(names[id - 1], tmp); n       } n       id--; n       if (place < 10) score[id] += place_to_score[place]; n       places[id][place]++; n       place++; n     } n   } n   vector<int> best; n   int points = -1; n   for (int i = 0; i < next_id - 1; i++) { n     if (score[i] > points) { n       best.clear(); n       points = score[i]; n     } n     if (score[i] == points) best.push_back(i); n   } n   for (int place = 0; best.size() > 1 && place < next_id - 1; place++) { n     vector<int> new_best; n     points = -1; n     for (int i = 0; i < best.size(); i++) { n       if (places[best[i]][place] > points) { n         new_best.clear(); n         points = places[best[i]][place]; n       } n       if (places[best[i]][place] == points) new_best.push_back(best[i]); n     } n     best = new_best; n   } n   printf( %s n , names[best[0]]); n   best.clear(); n   points = -1; n   for (int i = 0; i < next_id - 1; i++) { n     if (places[i][0] > points) { n       best.clear(); n       points = places[i][0]; n     } n     if (places[i][0] == points) best.push_back(i); n   } n   if (best.size() > 1) { n     vector<int> new_best; n     points = -1; n     for (int i = 0; i < best.size(); i++) { n       if (score[best[i]] > points) { n         new_best.clear(); n         points = score[best[i]]; n       } n       if (score[best[i]] == points) new_best.push_back(best[i]); n     } n     best = new_best; n   } n   for (int place = 1; best.size() > 1 && place < next_id - 1; place++) { n     vector<int> new_best; n     points = -1; n     for (int i = 0; i < best.size(); i++) { n       if (places[best[i]][place] > points) { n         new_best.clear(); n         points = places[best[i]][place]; n       } n       if (places[best[i]][place] == points) new_best.push_back(best[i]); n     } n     best = new_best; n   } n   printf( %s n , names[best[0]]); n } n


#include <bits/stdc++.h> n using namespace std; n string dst__; n stringstream dss__; n void debug(stringstream& ds) { n   cerr << endl; n   return; n } n template <typename F, typename... R> n void debug(stringstream& ds, const F& f, const R&... r) { n   string n; n   ds >> n; n   cerr << n <<  =  << f <<    ; n   debug(ds, r...); n } n constexpr long long LINF = 334ll << 53; n constexpr int INF = 15 << 26; n constexpr long long MOD = 1E9 + 7; n void sieve(long long n, vector<long long>& p) { n   vector<char> isprime(n + 1, 1); n   isprime[0] = isprime[1] = 0; n   for (long long i = 2; i <= n; i++) { n     if (isprime[i]) { n       p.push_back(i); n       for (long long j = i * i; j <= n; j += i) isprime[j] = 0; n     } n   } n } n vector<long long> primes; n vector<vector<long long>> dp(22, vector<long long>(1000010)); n long long r, c; n long long primeFactor(long long k) { n   vector<pair<long long, int>> ret; n   for (int i = 0;; ++i) { n     if (primes[i] * primes[i] > k) { n       if (k != 1ll) ret.push_back(make_pair(k, 1)); n       break; n     } n     if (k % primes[i] == 0) { n       ret.push_back(make_pair(primes[i], 0)); n       while (k % primes[i] == 0) { n         k /= primes[i]; n         ret.back().second++; n       } n     } n   } n   long long ans = 1; n   for (auto& y : ret) { n     ans = ans * dp[y.second][r] % MOD; n   } n   return ans; n } n int main() { n   sieve(1000003, primes); n   for (int i = 1; i < 22; ++i) { n     dp[i][0] = 2; n     if (i == 1) { n       for (int j = 1; j < 1000010; ++j) { n         dp[i][j] = j + 2; n       } n     } else { n       for (int j = 1; j < 1000010; ++j) { n         dp[i][j] = dp[i - 1][j] + dp[i][j - 1] % MOD; n       } n     } n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     scanf( %lld%lld , &r, &c); n     auto ans = primeFactor(c); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int cnt[26] = {0}; n   for (int i = 0; i < s.size(); i++) { n     cnt[s[i] -  a ]++; n   } n   int ans[26] = {0}; n   vector<int> v; n   for (int i = 0; i < 26; i++) { n     ans[i] = cnt[i] / 2; n     cnt[i] = cnt[i] % 2; n     if (cnt[i] == 1) v.push_back(i); n   } n   for (int i = 0; i < v.size() / 2; i++) { n     ans[v[i]]++; n   } n   int tmp = -1; n   if (v.size() % 2 == 1) { n     tmp = v[v.size() / 2]; n   } n   for (int i = 0; i < 26; i++) { n     for (int j = 0; j < ans[i]; j++) { n       cout << (char)( a  + i); n     } n   } n   if (tmp != -1) { n     cout << (char)( a  + tmp); n   } n   for (int i = 25; i >= 0; i--) { n     for (int j = 0; j < ans[i]; j++) { n       cout << (char)( a  + i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const double pi = acos(-1); n const int MOD = 1e9 + 7; n const int INF = 1e9 + 7; n const int MAXN = 1e6 + 5; n const double eps = 1e-9; n using namespace std; n double xp, yp, vp, x, y, v, r, R; n double P, len, L; n pair<double, double> pos[2]; n double f(double dphi) { n   if (dphi > pi) dphi = 2 * pi - dphi; n   if (dphi > P) return ((dphi - P) * r + L) / v; n   return sqrt(len * len + R * R - 2 * len * R * cos(dphi)) / v; n } n int main() { n   scanf( %lf %lf %lf %lf %lf %lf %lf , &xp, &yp, &vp, &x, &y, &v, &r); n   double lo = 0, hi = 1e18; n   R = hypot(xp, yp); n   double omega = vp / R; n   double phi0 = 0; n   if (x * yp == xp * y) { n     if (x * xp < 0 || y * yp < 0) phi0 = pi; n   } else { n     phi0 = acos((x * xp + y * yp) / (hypot(xp, yp) * hypot(x, y))); n     if (x * yp < xp * y) phi0 = 2 * pi - phi0; n   } n   len = hypot(x, y); n   L = sqrt(len * len - r * r) + sqrt(R * R - r * r); n   P = acos(r / len) + acos(r / R); n   hi = fabs(R - len) / v + 2 * pi * R / vp; n   while (abs(hi - lo) > eps) { n     double T = (lo + hi) / 2.; n     double dphi = fmod(omega * T + phi0, 2 * pi); n     if (dphi < 0) dphi += 2 * pi; n     if (f(dphi) < T) n       hi = T; n     else n       lo = T; n   } n   printf( %.20f n , lo); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:667772160 ) n using namespace std; n struct __isoff { n   __isoff() { n     if (0) freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout); n     srand( C  +  T  +  A  +  C  +  Y  +  M  +  B  +  A ); n   } n   ~__isoff() {} n } __osafwf; n const unsigned long long p1 = 31; n const unsigned long long p2 = 29; n const double eps = 1e-8; n const double pi = acos(-1.0); n const int infi = 1e9 + 7; n const long long inf = 1e18 + 7; n const long long dd = 2e5 + 7; n const long long mod = 1e9 + 7; n const int logc = 20; n int up[dd][logc], H[dd], in[dd], out[dd], ti = 0; n vector<int> P[dd]; n void dfs(int v, int p = 0, int h = 0) { n   H[v] = h; n   in[v] = ti++; n   up[v][0] = p; n   for (int i = 1; i < logc; i++) { n     up[v][i] = up[up[v][i - 1]][i - 1]; n   } n   for (auto it : P[v]) { n     if (it != p) { n       dfs(it, v, h + 1); n     } n   } n   out[v] = ti++; n } n void build() { dfs(0); } n bool is(int a, int b) { return in[a] <= in[b] && out[b] <= out[a]; } n int lca(int a, int b) { n   if (is(a, b)) { n     return a; n   } n   if (is(b, a)) { n     return b; n   } n   for (int i = logc - 1; i >= 0; i--) { n     int t = up[a][i]; n     if (!is(t, b)) { n       a = t; n     } n   } n   return up[a][0]; n } n int dis(int a, int b) { return H[a] + H[b] - 2 * H[lca(a, b)]; } n int main() { n   int n; n   cin >> n; n   vector<int> E; n   for (long long i = 0; i < (long long)n - 1; i++) { n     int t; n     cin >> t; n     t--; n     P[t].push_back(i + 1); n     E.push_back(i + 1); n   } n   build(); n   int a = 0, b = 0, l = 0; n   for (long long i = 0; i < (long long)n - 1; i++) { n     int t = E[i]; n     if (l < dis(a, t)) { n       l = dis(a, t); n       b = t; n     } n     if (l < dis(b, t)) { n       l = dis(b, t); n       a = t; n     } n     cout << l <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int modulo = 1e9 + 7; n template <class __Ty> n bool mini(__Ty& a, __Ty b) { n   return a > b ? ((a = b) | 1) : (0); n } n template <class __Ty> n bool maxi(__Ty& a, __Ty b) { n   return a < b ? ((a = b) | 1) : (0); n } n template <class __Ty> n __Ty add(__Ty a, __Ty b) { n   return (a + b) % (__Ty(modulo)); n } n template <class __Ty> n __Ty sub(__Ty a, __Ty b) { n   __Ty m(modulo); n   return ((a - b) % m + m) % m; n } n int a[int(1e6) + 3] = {0}; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   if ((n <= m + 1) && (m <= 2 * (n + 1))) { n     m -= n - 1; n     for (int i = 1; i < n; ++i) a[i] = 1; n     for (int i = 0; i <= n; ++i) n       while (m && a[i] < 2) { n         m--; n         a[i]++; n       } n     for (int i = 0; i <= n; ++i) { n       if (i > 0) cout << 0; n       while (a[i]--) cout << 1; n     } n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   cout << (a + b + c) * (a + b + c) - (a * a + c * c + e * e); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MXN = 2e5 + 10; n long long n, m, sum, maxi; n long long A[MXN], Ans[MXN], Max[MXN]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) cin >> A[i], sum += A[i]; n   if (sum < n) return cout << -1, 0; n   for (int i = 1; i <= m; i++) { n     if (i > n - A[i] + 1) return cout << -1, 0; n     Ans[i] = i; n     Max[i] = max(Max[i - 1], i + A[i] - 1); n   } n   long long l = Max[m] + 1, r = n, p = m; n   while (p >= 1 && l <= r) { n     Ans[p] = r - A[p] + 1; n     r = r - A[p]; n     l = Max[p - 1] + 1; n     p--; n   } n   for (int i = 1; i <= m; i++) cout << Ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n const int MOD = 1e9 + 7; n vector<pair<int, int> > G[maxn]; n int vis[maxn]; n int dp[maxn]; n int dfs(int x, int v) { n   vis[x] = 1; n   dp[x] = v; n   for (pair<int, int> e : G[x]) { n     int a = e.first; n     int b = 1 - e.second; n     if (vis[a]) { n       if (dp[a] != (dp[x] ^ b)) return 0; n     } else { n       if (!dfs(a, v ^ b)) return 0; n     } n   } n   return 1; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int x, y, v; n     scanf( %d%d%d , &x, &y, &v); n     G[x].push_back(make_pair(y, v)); n     G[y].push_back(make_pair(x, v)); n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       if (!dfs(i, 0)) { n         puts( 0 ); n         return 0; n       } else { n         if (!ans) n           ans = 1; n         else n           ans = ans * 2 % MOD; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string t; n int ct, z; n vector<int> vi; n int gcd(int a, int b) { n   if (!b) return a; n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n int main() { n   int a, b, k; n   cin >> a >> b >> k; n   if (a + k < b) { n     printf( 0.0000000 n ); n     exit(0); n   } n   if (!b) { n     printf( 1.000000 n ); n     exit(0); n   } n   double p = 1; n   for (int i = 0; i <= k; ++i) { n     p *= (1.0 * (b - i)) / (a + i + 1); n   } n   printf( %.6lf n , 1 - p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n int a[N]; n int dp[N][N]; n int deal(int L, int R) { n   if (L >= R) return 1; n   if (dp[L][R] != N) return dp[L][R]; n   if (a[L] == a[R]) dp[L][R] = min(dp[L][R], deal(L + 1, R - 1)); n   for (int i = L; i < R; ++i) { n     dp[L][R] = min(dp[L][R], deal(L, i) + deal(i + 1, R)); n   } n   return dp[L][R]; n } n void gao(int n) { n   for (int i = 0; i < N; ++i) n     for (int j = 0; j < N; ++j) dp[i][j] = N; n   int ans = deal(0, n - 1); n   cout << ans << endl; n } n int main() { n   int n; n   while (cin >> n) { n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n     } n     gao(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n const int MAX = (int)(2e5) + 7; n const int MOD = (int)(1e9) + 7; n const int INF_I = (int)(1e9) + 7; n const ll INF_LL = (ll)(1e18); n template <typename T> n void info(T& v) { n   for (const auto& i : v) cout << i <<    ; n   cout << endl; n } n template <typename T> n bool chkmin(T& a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <typename T> n bool chkmax(T& a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n void boot_up() { n   cin.tie(nullptr); n   cout.tie(nullptr); n   ios_base::sync_with_stdio(false); n } n int q; n int n, k; n void solve(); n signed main() { n   boot_up(); n   cin >> q; n   while (cin >> n >> k) solve(); n } n void solve() { n   string s; n   cin >> s; n   int curr_pos = 0; n   string a =   , b =   , c =   ; n   vector<string> mask = { R ,  G ,  B }; n   for (int i = 0; i < n; ++i) { n     a += mask[curr_pos % 3]; n     b += mask[(curr_pos + 1) % 3]; n     c += mask[(curr_pos + 2) % 3]; n     curr_pos = (curr_pos + 1) % 3; n   } n   vector<int> pref_a(n); n   vector<int> pref_b(n); n   vector<int> pref_c(n); n   pref_a[0] = (s[0] ==  R  ? 0 : 1); n   pref_b[0] = (s[0] ==  G  ? 0 : 1); n   pref_c[0] = (s[0] ==  B  ? 0 : 1); n   for (int i = 1; i < n; ++i) { n     pref_a[i] = pref_a[i - 1] + 1 - (int)(s[i] == a[i]); n     pref_b[i] = pref_b[i - 1] + 1 - (int)(s[i] == b[i]); n     pref_c[i] = pref_c[i - 1] + 1 - (int)(s[i] == c[i]); n   } n   int ans = INF_I; n   for (int i = 0; i < n - k + 1; ++i) { n     chkmin(ans, pref_a[i + k - 1] - (i == 0 ? 0 : pref_a[i - 1])); n     chkmin(ans, pref_b[i + k - 1] - (i == 0 ? 0 : pref_b[i - 1])); n     chkmin(ans, pref_c[i + k - 1] - (i == 0 ? 0 : pref_c[i - 1])); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long n; n   long long t1(0), t2(0); n   long long mn = 0, mx = 0; n   cin >> n; n   vector<long> vec(n, 0); n   for (long i = 0; i < n; i++) { n     cin >> vec[i]; n   } n   sort(vec.begin(), vec.end()); n   mn = vec[0]; n   mx = vec[n - 1]; n   for (long i = 0; i < vec.size(); i++) { n     t1 += (vec[i] == mn); n     t2 += (vec[i] == mx); n   } n   cout << mx - mn <<    ; n   if (mx - mn == 0) n     cout << n * (n - 1) / 2 << endl; n   else n     cout << t1 * t2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 1000000 + 5; n int N; n int p[2 * NMAX]; n int main() { n   cin >> N; n   iota(p + 1, p + N + 1, 1); n   int st = 1, dr = N; n   for (int phase = 2; phase <= N; ++phase, ++st) { n     int old = 0; n     for (int i = st; i <= dr; i += phase) { n       int aux = p[i]; n       p[i] = old; n       old = aux; n     } n     p[++dr] = old; n   } n   for (int i = st; i <= dr; ++i) cout << p[i] <<    n [i == dr]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 7; n int n; n long long a[maxn]; n long long work(long long m) { n   long long res = 0; n   while (m) { n     if (m & 1) res++; n     m >>= 1; n   } n   return res; n } n long long dp[maxn][2]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &a[i]); n     a[i] = work(a[i]); n   } n   dp[0][0] = 0; n   dp[0][1] = 0; n   dp[1][0] = 0; n   dp[1][1] = 0; n   for (int i = 2; i <= n; ++i) { n     if (a[i] & 1) { n       dp[i][0] = dp[i - 1][1] + (a[i - 1] & 1); n       dp[i][1] = dp[i - 1][0] + !(a[i - 1] & 1); n     } else { n       dp[i][0] = dp[i - 1][0] + !(a[i - 1] & 1); n       dp[i][1] = dp[i - 1][1] + (a[i - 1] & 1); n     } n   } n   long long ans = 0; n   for (int i = 2; i <= n; ++i) { n     int l_ = max(1, i - 119); n     long long max_ = a[i], cnt = 0, sum = a[i]; n     for (int j = i - 1; j >= l_; --j) { n       sum += a[j]; n       max_ = max(max_, a[j]); n       if (sum & 1) continue; n       if (max_ > sum / 2) cnt++; n     } n     ans += (dp[i][0] - cnt); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   unsigned long int val; n   long int index; n   unsigned long int other; n }; n bool cmp(node& a, node& b) { n   if (a.val != b.val) n     return a.val < b.val; n   else n     return a.other > b.other; n } n struct node2 { n   bool operator()(const node& a, const node& b) const { n     if (a.other != b.other) n       return a.other < b.other; n     else if (a.val != b.val) n       return a.val < b.val; n     else n       return a.index < b.index; n   } n }; n int main() { n   unsigned long int n; n   scanf( %lu , &n); n   vector<node> all(n); n   for (unsigned long int i = 0; i < n; i++) { n     scanf( %lu , &all[i].other); n     scanf( %lu , &all[i].val); n     if (all[i].other > all[i].val) swap(all[i].other, all[i].val); n     all[i].index = i + 1; n   } n   sort(all.begin(), all.end(), cmp); n   unsigned long int outer = 0, id = 0; n   set<node, node2> ended; n   for (unsigned long int i = 0; i < n; i++) { n     auto it = ended.insert(all[i]).first; n     auto it1 = it, it2 = it; n     it1++; n     if (it1 != ended.end()) { n       outer = (*it).index; n       id = (*it1).index; n       break; n     } else if (it2 != ended.begin()) { n       it2--; n       if ((*it2).other >= (*it).other) { n         outer = (*it).index; n         id = (*it2).index; n       } n     } n   } n   if (outer == 0) n     printf( -1 -1 n ); n   else n     printf( %lu %lu n , id, outer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void printvec(vector<T>& x, int a, int b) { n   for (int i = (a); i <= (b); i++) cout << x[i] <<    ; n   cout <<   n ; n } n const double PI = acos((double)-1); n const double EPSILON = 1e-7; n const int N = 1e6 + 1; n const int NN = 1e3 + 1; n const long long MOD = 998244353; n const long long oo = LLONG_MAX; n const int BASE = 10000; n void query() { n   int n, x; n   cin >> n >> x; n   vector<vector<int>> g(n + 1); 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   if ((int)(g[x]).size() <= 1) { n     cout <<  Ayush  n          <<   n ; n     return; n   } n   if (n % 2) { n     cout <<  Ashish  n          <<   n ; n   } else { n     cout <<  Ayush  n          <<   n ; n   } n } n void solve() { n   int q; n   cin >> q; n   while (q--) { n     query(); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout << fixed << setprecision(10); n   solve(); n   cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n string s; n int cnt; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  # ) { n       cnt++; n     } else { n       if (cnt >= k) { n         cout <<  NO  << endl; n         return 0; n       } n       cnt = 0; n     } n   } n   if (cnt >= k) { n     cout <<  NO  << endl; n     return 0; n   } else { n     cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, A[100], i, j; n bool w; n string S; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> N; n   for (i = 0; i < N; i++) { n     cin >> A[i]; n   } n   getline(cin, S); n   for (j = 0; j < N; j++) { n     getline(cin, S); n     if (!w) { n       for (i = S.length() - 1; i >= 0; i--) { n         if (S[i] ==  a  || S[i] ==  i  || S[i] ==  u  || S[i] ==  e  || n             S[i] ==  o  || S[i] ==  y ) { n           A[j]--; n         } n       } n       if (A[j] != 0) { n         w = 1; n       } n     } n   } n   if (w) { n     cout <<  NO  << endl; n   } else n     cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int n, k; n vector<int> g[N]; n int fa[N]; n int dep[N]; n bool vis[N]; n int anc[N][35]; n void dfs(int u, int f) { n   fa[u] = f; n   anc[u][0] = fa[u]; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v != f) { n       dep[v] = dep[u] + 1; n       dfs(v, u); n     } n   } n } n void rdfs(int u, int f) { n   vis[u] = 1; n   if (u == f) return; n   rdfs(fa[u], f); n } n void preprocess() { n   for (int j = 1; (1 << j) < n; j++) { n     for (int i = 0; i < n; i++) { n       if (anc[i][j - 1] != -1) { n         int a = anc[i][j - 1]; n         anc[i][j] = anc[a][j - 1]; n       } n     } n   } n } n int main() { n   memset(anc, -1, sizeof(anc)); n   scanf( %d%d , &n, &k); n   k = n - k; n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--, y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(n - 1, -1); n   preprocess(); n   int num = 1; n   vis[n - 1] = 1; n   for (int i = n - 2; i >= 0; i--) { n     if (vis[i]) continue; n     int t = i; n     for (int j = 20; j >= 0; j--) { n       if (anc[t][j] == -1) n         continue; n       else { n         if (!vis[anc[t][j]]) { n           t = anc[t][j]; n         } n       } n     } n     if (dep[i] - dep[t] + 1 + num <= k) { n       num += dep[i] - dep[t] + 1; n       rdfs(i, t); n     } n   } n   for (int i = 0; i < n; i++) { n     if (!vis[i]) printf( %d  , i + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char ch = getchar(); n   long long x = 0; n   int op = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) op = -1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return x * op; n } n inline void write(long long a) { n   if (a < 0) putchar( - ), a = -a; n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n const int N = 1010; n int n, m, k; n long long a[N][N], s1[N][N], s2[N][N]; n int main() { n   n = read(), m = read(), k = read(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + read(); n   for (int i = 1; i <= n; i++) n     for (int j = 0; j <= m; j++) { n       s1[i][j] = s1[i - 1][j + 1] + a[i][j] - n                  ((i - k >= 0 && j + k <= m) ? a[i - k][j + k] : 0); n       if (j) n         s2[i][j] = s2[i - 1][j - 1] + a[i][j] - n                    ((i - k >= 0 && j - k >= 0) ? a[i - k][j - k] : 0); n     } n   long long mx = -1, x, y; n   for (int i = k; i <= n - k + 1; i++) n     for (int j = k; j <= m - k + 1; j++) { n       long long tmp = s1[i + k - 1][j] + s1[i - 1][j - k] - n                       s2[i - 1][j + k - 1] - s2[i + k - 1][j - 1]; n       if (tmp > mx) { n         mx = tmp; n         x = i; n         y = j; n       } n     } n   write(x); n   putchar(   ); n   write(y); 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[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int sum = 2 * n - 1 + a[0]; n   if (n > 1) { n     if (a[0] > a[1]) sum += a[0] - a[1]; n     for (int i = 1; i < n - 1; i++) { n       if (a[i] > a[i - 1]) sum += a[i] - a[i - 1]; n       if (a[i] > a[i + 1]) sum += a[i] - a[i + 1]; n     } n     if (a[n - 1] > a[n - 2]) sum += a[n - 1] - a[n - 2]; n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = (int)1e9; n const double PI = 2 * acos(0); n const double eps = 1e-9; n inline int comp(const double &a, const double &b) { n   if (fabs(a - b) < eps) return 0; n   return a > b ? 1 : -1; n } n int di[] = {1, -1, 0, 0, 1, -1, 1, -1}; n int dj[] = {0, 0, 1, -1, 1, -1, -1, 1}; n int diK[] = {-2, -2, -1, 1, 2, 2, 1, -1}; n int djK[] = {-1, 1, 2, 2, 1, -1, -2, -2}; n int I, J; n inline bool val(const int &i, const int &j) { n   if (i < 0 || j < 0 || i >= I || j >= J) return false; n   return true; n } n int N; n int n; n int ret[109][109]; n bool val() { n   for (int i = 0; i < (int)(I); i++) n     for (int j = 0; j < (int)(J); j++) n       for (int k = 0; k < (int)(4); k++) { n         int ni = i + di[k]; n         int nj = j + dj[k]; n         if (val(ni, nj) && abs(ret[i][j] - ret[ni][nj] == 1)) return 0; n       } n   return 1; n } n bool vis[10009]; n bool dfs(int i, int j) { n   if (i == I) return 1; n   if (j == J) return dfs(i + 1, 0); n   for (int a = 1; a <= I * J; a++) n     if (!vis[a]) { n       if (i && abs(a - ret[i - 1][j]) == 1) continue; n       if (j && abs(a - ret[i][j - 1]) == 1) continue; n       vis[a] = 1; n       ret[i][j] = a; n       if (dfs(i, j + 1)) return 1; n       vis[a] = 0; n     } n   return 0; n } n int main() { n   cin >> I >> J; n   if (I * J <= 1000000) { n     if (dfs(0, 0)) { n       for (int i = 0; i < (int)(I); i++) { n         for (int j = 0; j < (int)(J); j++) { n           if (j) printf(   ); n           printf( %d , ret[i][j]); n         } n         printf(  n ); n       } n     } else n       cout << -1 << endl; n     return 0; n   } n   vector<pair<int, int> > v; n   for (int i = 0; i < (int)(I); i++) n     for (int j = 0; j < (int)(J); j++) v.push_back(make_pair(i, j)); n   int cc = 1; n   for (int i = 1; i < I * J; i += 2) ret[v[i].first][v[i].second] = cc++; n   for (int i = 0; i < I * J; i += 2) ret[v[i].first][v[i].second] = cc++; n   if (!val()) { n     cc = 1; n     for (int i = 0; i < I * J; i += 2) ret[v[i].first][v[i].second] = cc++; n     for (int i = 1; i < I * J; i += 2) ret[v[i].first][v[i].second] = cc++; n     if (!val()) { n       cout << -1 << endl; n       return 0; n     } n   } n   for (int i = 0; i < (int)(I); i++) { n     for (int j = 0; j < (int)(J); j++) { n       if (j) printf(   ); n       printf( %d , ret[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a; n int n; n int main() { n   cin >> a; n   scanf( %d , &n); n   int i; n   for (i = 0; i < a.size(); i++) n     if (a[i] >=  A  && a[i] <=  Z ) a[i] =  a  + a[i] -  A ; n   for (i = 0; i < a.size(); i++) n     if (a[i] -  a  + 1 <= n) a[i] =  A  + a[i] -  a ; n   cout << a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[4] = {1, -1, 0, 0}; n int dy[4] = {0, 0, 1, -1}; n void fast() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(0); n   cout.tie(0); n } n void online_judge() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n const int flag_max = 0x3f3f3f3f; n const long long OO = 2e9 + 10; n const double EPS = (1e-8); n int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n const long long MOD = 1e14 + 7; n long long Power(long long n, long long deg) { n   if (!deg) n     return 1; n   else if (deg & 1) n     return (Power(n, deg - 1) * n); n   else { n     long long half = Power(n, deg / 2); n     return ((half * half)); n   } n } n int k, ans = 0; n string s; n vector<pair<char, char> > pr; n int main() { n   fast(); n   cin >> s; n   cin >> k; n   for (int i = 0; i < k; i++) { n     string q; n     cin >> q; n     int F = 0, S = 0; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] == q[0] || s[i] == q[1]) n         if (s[i] == q[0]) n           F++; n         else n           S++; n       else n         ans += min(F, S), S = F = 0; n     } n     ans += min(F, S); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n long long BASE = 101; n bool is_enough(int h, int n, int m) { n   int n1 = h / 2; n   int m1 = h / 3; n   int mn1 = h / 6; n   if (n1 - mn1 >= n && m1 - mn1 >= m) { n     return true; n   } n   int need_n = max(0, n - (n1 - mn1)); n   int need_m = max(0, m - (m1 - mn1)); n   if (need_n + need_m <= mn1) { n     return true; n   } n   return false; n } n int main() { n   std::cout.precision(15); n   std::ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   int l = 2; n   int r = 6000000; n   while (r - l > 1000) { n     int mid = l + (r - l) / 2; n     if (is_enough(mid, n, m)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   for (int i = l; i <= r; ++i) { n     if ((i % 2 == 0 || i % 3 == 0) && is_enough(i, n, m)) { n       cout << i; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200500; n const int inf = 2e9; n const double eps = 1e-8; n const int base = 1073676287; n long long a[maxn]; n int b[maxn]; n int c[maxn]; n int bit[64]; n int bits2[64]; n void check(int n) { n   long long sum = 0LL; n   for (int j = 0; j < n; j++) { n     sum += a[j]; n     int x = a[j]; n     int pos = 0; n     while (x) { n       bit[pos++] += x % 2; n       x /= 2; n     } n   } n   for (int j = 0; j < n; j++) { n     int x = a[j]; n     int pos = 0; n     for (int i = 0; i < 64; i++) bits2[i] = 0; n     while (x) { n       bits2[pos++] = x % 2; n       x /= 2; n     } n     long long cnt = 0LL; n     long long deg = 1LL; n     for (int i = 0; i < 60; i++) { n       if (bits2[i]) cnt += 1LL * bit[i] * deg; n       deg *= 2LL; n     } n     if (cnt != b[j]) { n       puts( -1 ); n       exit(0); n     } n     if (1LL * a[j] * n + sum != 1LL * b[j] + 1LL * c[j]) { n       puts( -1 ); n       exit(0); n     } n   } n } n int main() { n   srand(time(0)); n   int n; n   long long sum = 0LL; n   scanf( %d , &n); n   for (int j = 0; j < n; j++) { n     scanf( %d , &b[j]); n     sum += 1LL * b[j]; n   } n   for (int j = 0; j < n; j++) { n     scanf( %d , &c[j]); n     sum += 1LL * c[j]; n   } n   if (sum % (2LL * n) != 0LL) { n     puts( -1 ); n     return 0; n   } n   sum /= 2LL * n; n   for (int j = 0; j < n; j++) { n     int cur = b[j] + c[j]; n     a[j] = cur - sum; n     if (a[j] < 0LL) { n       puts( -1 ); n       return 0; n     } n     if (1LL * a[j] % n != 0LL) { n       puts( -1 ); n       return 0; n     } n     a[j] /= 1LL * n; n   } n   check(n); n   for (int j = 0; j < n; j++) cout << a[j] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct wor { n   int x, y; n   bool start; n }; n struct node { n   int maxN; n   int plus; n }; n vector<node> t(16 * 1000000 + 1000, {0, 0}); n int m = 4 * 1000000 + 5; n bool operator<(wor a, wor b) { return a.y < b.y or a.y == b.y and a.x < b.x; } n void update(int v, int l, int r, int a, int b, int val) { n   if (l >= b or r <= a) { n     return; n   } else if (a <= l and r <= b) { n     t[v].plus += val; n   } else { n     int m = (l + r) / 2; n     update(2 * v + 1, l, m, a, b, val); n     update(2 * v + 2, m, r, a, b, val); n     t[v].maxN = max(t[2 * v + 1].maxN + t[2 * v + 1].plus, n                     t[2 * v + 2].maxN + t[2 * v + 2].plus); n   } n } n int query(int v, int l, int r, int a, int b) { n   if (l >= b or r <= a) { n     return -1; n   } else if (a <= l and r <= b) { n     return t[v].maxN + t[v].plus; n   } else { n     int m = (l + r) / 2; n     return max(query(2 * v + 1, l, m, a, b), query(2 * v + 2, m, r, a, b)) + n            t[v].plus; n   } n } n int main() { n   int add = 1000000; n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int r; n   cin >> r; n   r *= 2; n   vector<wor> a(2 * n); n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     int newX = x + y; n     int newY = x - y; n     newX += add; n     newY += add; n     a[2 * i] = {newX, newY, true}; n     a[2 * i + 1] = {newX, newY + r + 1, false}; n   } n   int best = 0; n   sort(a.begin(), a.end()); n   for (auto e : a) { n     if (e.start) { n       update(0, 0, m, e.x, e.x + r + 1, 1); n       int q = query(0, 0, m, e.x, e.x + r + 1); n       best = max(best, q); n     } else { n       update(0, 0, m, e.x, e.x + r + 1, -1); n     } n   } n   cout << best; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n typedef long long LL; n set<LL>a; n int main(){ n  for(LL i = 1;i <= 10000;i++)a.insert(i*i*i); n  scanf( %d ,&t); n  while(t--){ n   LL x; n   cin >> x; n   int flag = 0; n   for(LL i = 1;i <= 10000;i++) n    if(a.count(x-i*i*i)){ n     puts( YES ); n     flag = 1; n     break; n    } n   if(!flag)puts( NO ); n  } 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[100 + 10][100 + 10]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> a[i][j]; n     } n   } n   int sum = 0; n   for (int i = 0; i < n; i++) { n     sum += a[i][i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     sum += a[i][n - i - 1]; n   } n   for (int i = 0; i < n; i++) { n     sum += a[i][n / 2]; n   } n   for (int i = 0; i < n; i++) { n     sum += a[n / 2][i]; n   } n   sum -= a[n / 2][n / 2] * 3; n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n int pp(int x, int y) { n   int i = 0; n   int min = 1; n   for (i = 0; i < y; i++) { n     min = min * x; n   } n   return min; n } n int main() { n   int n; n   int a[100001]; n   int i, k, t, flag; n   long long int min; n   while (scanf( %d , &n) != EOF) { n     for (i = 1; i <= n; i++) { n       cin >> a[i]; n     } n     min = 0; n     for (k = 1; k < n; k++) { n       for (t = 0; k + pp(2, t) <= n; t++) { n         flag = k + pp(2, t); n       } n       min = min + a[k]; n       a[flag] += a[k]; n       a[k] = 0; n       cout << min << endl; n     } 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   long long t, i, j; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     set<long long> s; n     s.insert(0); n     s.insert(1); n     for (i = sqrt(n); i > 0; i--) { n       s.insert(n / i); n       s.insert(i); n     } n     cout << s.size() <<   n ; n     for (auto i = s.begin(); i != s.end(); i++) cout << *i <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n const int inf = 50000000; n const int maxn = 100010; n int check(vector<int> &v) { n   int i, first, cur, j; n   for (i = 0; i < v.size(); i++) { n     first = j = 0; n     cur = v[i]; n     while (j < 8) { n       if (cur == 1) { n         first = 1; n         break; n       } n       cur = v[cur]; n       j++; n     } n     if (!first) return 0; n   } n   return 1; n } n int generator(vector<int> &v, int left, int k) { n   if (left == 0) return check(v); n   int i, ret = 0; n   for (i = 1; i <= k; i++) { n     v.push_back(i); n     ret += generator(v, left - 1, k); n     v.pop_back(); n   } n   return ret; n } n long long modpow(long long a, long long b) { n   long long x = 1, y = a; n   while (b) { n     if (b % 2) x = (x * y) % mod; n     y = (y * y) % mod; n     b /= 2; n   } n   return x; n } n long long temp[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152}; n int main() { n   int n, k; n   scanf( %d , &n), scanf( %d , &k); n   vector<int> v; n   long long ans = temp[k]; n   ans = (ans * modpow(n - k, n - k)) % mod; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nBox, testC, iBox, nBird, A[109]; n int main() { n   scanf( %d , &nBox); n   for (int i = 0; i < nBox; ++i) scanf( %d , &A[i]); n   scanf( %d , &testC); n   for (int i = 0; i < testC; ++i) { n     scanf( %d%d , &iBox, &nBird); n     --iBox; n     if (iBox != 0) A[iBox - 1] += nBird - 1; n     if (iBox != nBox - 1) A[iBox + 1] += A[iBox] - nBird; n     A[iBox] = 0; n   } n   for (int i = 0; i < nBox; ++i) printf( %d n , A[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int calc(int x, int k) { n   int SG; n   if (k % 2 == 0) { n     if (x >= 3) n       SG = !(x % 2); n     else n       SG = x; n   } else { n     if (x >= 6) { n       if (x % 2) n         SG = 0; n       else { n         if (calc(x / 2, k) == 1) n           SG = 2; n         else n           SG = 1; n       } n     } else { n       if (x == 4) n         SG = 2; n       else if (x == 5) n         SG = 0; n       else n         SG = x % 2; n     } n   } n   return SG; n } n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   int res = 0; n   for (int i = 0; i < n; i++) { n     res ^= calc(a[i], k); n   } n   puts(res > 0 ?  Kevin  :  Nicky ); 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   ; n   cout.tie(0); n   int n, i; n   cin >> n; n   int a[n], f[105] = {0}; n   int m = 0; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     f[a[i]]++; n     if (f[a[i]] > m) m = f[a[i]]; n   } n   cout << m << endl; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     string a, b; n     cin >> a; n     cin >> b; n     if (n == 1) { n       if (a[0] ==  1  || a[0] ==  2 ) n         cout <<  NO n ; n       else if (b[0] ==  1  || b[0] ==  2 ) n         cout <<  NO n ; n       else n         cout <<  YES n ; n       continue; n     } n     a = a + b; n     int i = 0; n     bool dir = false; n     while (i != 2 * n - 1) { n       if (!dir) { n         if (a[i] ==  1  || a[i] ==  2 ) { n           i++; n           if (i == n) break; n           dir = false; n         } else { n           if (i < n) n             i = i + n; n           else n             i = i - n; n           dir = true; n         } n       } else { n         if (a[i] ==  1  || a[i] ==  2 ) { n           break; n         } else { n           i++; n           dir = false; n         } n       } n     } n     if (i != 2 * n - 1) n       cout <<  NO n ; n     else { n       if (!dir) { n         if (a[i] ==  2  || a[i] ==  1 ) n           cout <<  YES n ; n         else n           cout <<  NO n ; n       } else { n         if (a[i] ==  2  || a[i] ==  1 ) n           cout <<  NO n ; n         else n           cout <<  YES n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1000000007; n const long double PI = 2 * acos(0.0); n const vector<long long int> dx = {1, -1, 0, 0}; n const vector<long long int> dy = {0, 0, 1, -1}; n vector<long long int> ga(long long int n, bool oneIndexed = false) { n   vector<long long int> a; n   if (oneIndexed) a.push_back(0ll); n   for (long long int i = 0; i < n; i++) { n     long long int p; n     cin >> p; n     a.push_back(p); n   } n   return move(a); n } n vector<unsigned long long int> gau(unsigned long long int n, n                                    bool oneIndexed = false) { n   vector<unsigned long long int> a; n   if (oneIndexed) a.push_back(0llu); n   for (unsigned long long int i = 0; i < n; i++) { n     unsigned long long int p; n     cin >> p; n     a.push_back(p); n   } n   return move(a); n } n vector<string> gas(unsigned long long int n, bool oneIndexed = false) { n   vector<string> a; n   if (oneIndexed) a.push_back(  ); n   for (unsigned long long int i = 0; i < n; i++) { n     string p; n     cin >> p; n     a.push_back(p); n   } n   return move(a); n } n template <typename T, typename A> n void pa(vector<T, A> const &a, long long int begin = 0, n         long long int end = -1) { n   if (end == -1) end = a.size() - 1; n   for (long long int i = begin; i <= end; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n } n template <typename T, typename A> n void papair(vector<T, A> const &a, long long int begin = 0, n             long long int end = -1) { n   if (end == -1) end = (long long int)a.size() - 1; n   for (long long int i = begin; i <= end; i++) { n     cout << a[i].first <<     << a[i].second <<   n ; n   } n   cout <<   n ; n } n void yes() { cout <<  YES n ; } n void no() { cout <<  NO n ; } n void yesno(int f) { n   if (f) n     yes(); n   else n     no(); n } n void solve() { n   long long int n; n   cin >> n; n   vector<pair<long long int, long long int>> edges; n   long long int p1 = n / 2, p2 = n / 2; n   if (p1 + p2 < n) p2++; n   for (long long int i = 1; i <= p1; i++) { n     for (long long int j = p1 + 1; j <= n; j++) { n       edges.push_back({i, j}); n     } n   } n   cout << (long long int)edges.size(); n   cout <<   n ; n   papair(edges); n } n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n vector<long long> G[500005]; n long long t1, d1, t2, d2; n long long dis1[500005], dis2[500005]; n long long inp[500005], in[500005]; n stringstream ss; n void dfs1(long long u, long long fa, long long d) { n   if (d > d1) { n     d1 = d; n     t1 = u; n   } n   for (long long i = 0; i < G[u].size(); i++) { n     if (G[u][i] == fa) continue; n     dfs1(G[u][i], u, d + 1); n   } n } n void dfs2(long long u, long long fa, long long d) { n   if (d > d2) { n     d2 = d; n     t2 = u; n   } n   dis1[u] = d; n   for (long long i = 0; i < G[u].size(); i++) { n     if (G[u][i] == fa) continue; n     dfs2(G[u][i], u, d + 1); n   } n } n void dfs3(long long u, long long fa, long long d) { n   dis2[u] = d; n   for (long long i = 0; i < G[u].size(); i++) { n     if (G[u][i] == fa) continue; n     dfs3(G[u][i], u, d + 1); n   } n } n void findpath(long long u, long long fa, long long t) { n   inp[u] = true; n   if (u == t) { n     memcpy(in, inp, sizeof inp); n     return; n   } n   for (long long i = 0; i < G[u].size(); i++) { n     if (G[u][i] == fa) continue; n     findpath(G[u][i], u, t); n   } n   inp[u] = false; n } n long long ans; n bool del[500005]; n long long deg[500005]; n void dfs4(long long u, long long fa) { n   del[u] = true; n   if ((dis1[u] > dis2[u] || del[t2]) && !del[t1]) { n     ans += dis1[u]; n     ss << t1 <<     << u <<     << u << endl; n   } else if (!del[t2]) { n     ans += dis2[u]; n     ss << t2 <<     << u <<     << u << endl; n   } n   for (long long i = 0; i < G[u].size(); i++) { n     if (G[u][i] == fa) continue; n     if (in[G[u][i]]) dfs4(G[u][i], u); n   } n } n signed main() { n   cin >> n; n   for (long long i = 1; i <= n - 1; i++) { n     long long u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n     deg[u]++; n     deg[v]++; n   } n   dfs1(1, 0, 0); n   dfs2(t1, 0, 0); n   dfs3(t2, 0, 0); n   findpath(t1, 0, t2); n   queue<long long> Q; n   for (long long i = 1; i <= n; i++) { n     if (deg[i] == 1) Q.push(i); n   } n   while (Q.size()) { n     long long i = Q.front(); n     Q.pop(); n     if (in[i]) continue; n     if (del[i]) continue; n     del[i] = true; n     if (dis1[i] > dis2[i]) { n       ans += dis1[i]; n       ss << t1 <<     << i <<     << i << endl; n     } else { n       ans += dis2[i]; n       ss << t2 <<     << i <<     << i << endl; n     } n     for (long long j = 0; j < G[i].size(); j++) { n       deg[G[i][j]]--; n       if (deg[G[i][j]] == 1) Q.push(G[i][j]); n     } n   } n   dfs4(t1, 0); n   cout << ans << endl; n   cout << ss.str() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct segtree { n   int size = 1; n   vector<pair<int, int>> v; n   vector<pair<int, int>> lazy; n   void init(int n) { n     while (n > size) { n       size *= 2; n     } n     v.assign(size * 2, {0, -1}); n     lazy.assign(size * 2, {0, -1}); n   } n   void prop(int x, int lx, int rx) { n     if (rx - lx == 1) return; n     if (lazy[x] == make_pair(0, -1)) return; n     v[x * 2 + 1] = lazy[x]; n     v[x * 2 + 2] = lazy[x]; n     lazy[x * 2 + 1] = lazy[x]; n     lazy[x * 2 + 2] = lazy[x]; n     lazy[x] = {0, -1}; n   } n   void update(int l, int r, pair<int, int> val, int x, int lx, int rx) { n     prop(x, lx, rx); n     if (rx <= l || lx >= r) { n       return; n     } n     if (lx >= l && rx <= r) { n       v[x] = val; n       lazy[x] = val; n       return; n     } n     int m = (lx + rx) / 2; n     update(l, r, val, x * 2 + 1, lx, m); n     update(l, r, val, x * 2 + 2, m, rx); n     v[x] = max(v[x * 2 + 1], v[x * 2 + 2]); n   } n   void update(int l, int r, pair<int, int> val) { n     update(l, r + 1, val, 0, 0, size); n   } n   pair<int, int> get(int l, int r, int x, int lx, int rx) { n     prop(x, lx, rx); n     if (rx <= l || lx >= r) { n       return {0, -1}; n     } n     if (lx >= l && rx <= r) { n       return v[x]; n     } n     int m = (lx + rx) / 2; n     pair<int, int> m1 = get(l, r, x * 2 + 1, lx, m); n     pair<int, int> m2 = get(l, r, x * 2 + 2, m, rx); n     return max(m1, m2); n   } n   pair<int, int> get(int l, int r) { return get(l, r + 1, 0, 0, size); } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   set<int> s; n   vector<vector<pair<int, int>>> v(n); n   vector<tuple<int, int, int>> actions; n   for (int i = 0; i < m; i++) { n     int j, l, r; n     cin >> j >> l >> r; n     j--; n     actions.push_back({j, l, r}); n     s.insert(l); n     s.insert(r); n     v[j].push_back(make_pair(l, r)); n   } n   auto s1 = s.begin(); n   auto s2 = s.begin(); n   if (s2 != s.end()) s2++; n   map<int, int> mapa; n   int ctr = 0; n   mapa[*s1] = ctr; n   ctr++; n   while (s2 != s.end()) { n     if ((*s1) != (*s2)) { n       mapa[*s2] = ctr; n       ctr++; n     } n     s1++; n     s2++; n   } n   segtree prev; n   prev.init(2 * m + 2); n   vector<int> before(n, -1); n   for (int i = 0; i < n; i++) { n     pair<int, int> mx = {0, -1}; n     for (auto x : v[i]) { n       int a = mapa[x.first]; n       int b = mapa[x.second]; n       mx = max(mx, prev.get(a, b)); n     } n     mx.first++; n     before[i] = mx.second; n     mx.second = i; n     for (auto x : v[i]) { n       int a = mapa[x.first]; n       int b = mapa[x.second]; n       prev.update(a, b, mx); n     } n   } n   vector<int> ok(n, false); n   int lastmx = prev.get(0, 2 * m + 1).second; n   while (lastmx >= 0) { n     ok[lastmx] = true; n     lastmx = before[lastmx]; n   } n   vector<int> res; n   int resnum = 0; n   for (int i = 0; i < n; i++) { n     if (!ok[i]) { n       res.push_back(i); n       resnum++; n     } n   } n   cout << resnum <<   n ; n   for (auto w : res) cout << w + 1 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int SIZE = 9000; n const int mod = 1e9 + 7; n const int maxv = 9000; n bool vis[maxv + 1][maxv + 1], in[maxv + 1][maxv + 1]; n vector<int> v[maxv + 1]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   int a[n + 1]; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= maxv; i++) v[i].push_back(0), in[i][0] = true; n   for (int i = 1; i <= n; i++) { n     for (auto it : v[a[i]]) { n       if (vis[a[i]][it]) continue; n       for (int j = a[i] + 1; j <= maxv; j++) { n         if (in[j][it ^ a[i]]) break; n         v[j].push_back(it ^ a[i]); n         in[j][it ^ a[i]] = true; n       } n       vis[a[i]][it] = true; n     } n     v[a[i]].clear(); n   } n   set<int> ordered(v[maxv].begin(), v[maxv].end()); n   cout << ordered.size() <<   n ; n   for (auto it : ordered) cout << it <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, j, k, l, m, n, cnt = 0, ans = 0; n   char a[8][8]; n   for (i = 0; i < 8; i++) n     for (j = 0; j < 8; j++) cin >> a[i][j]; n   for (i = 0; i < 8; i++) { n     for (j = 0; j < 8; j++) { n       if (a[i][j] ==  B ) cnt++; n     } n     if (cnt == 8) ans++; n     cnt = 0; n   } n   for (i = 0; i < 8; i++) { n     for (j = 0; j < 8; j++) { n       if (a[j][i] ==  B ) cnt++; n     } n     if (cnt == 8) ans++; n     cnt = 0; n   } n   if (ans == 16) ans = 8; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, l, v1, v2, k; n   while (~scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k)) { n     if (k >= n) { n       printf( %.10lf n , l * 1.0 / v2); n       continue; n     } n     int t = (n - 1) / k; n     double s = v2 * 1.0 / v1; n     double kk = (1 + s) / (3 + s); n     double temp = kk + t * (1 - kk); n     temp = l * 1.0 / (temp * v1); n     printf( %.10lf n , temp * (kk / s + t * (1 - kk))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 55; n int n, m; n int a[MAXN][MAXN]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     set<int> rows, columns; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         cin >> a[i][j]; n         if (a[i][j] == 1) rows.insert(i), columns.insert(j); n       } n     } n     int res = min(n - rows.size(), m - columns.size()); n     if (res % 2 == 0) n       cout <<  Vivek  << endl; n     else n       cout <<  Ashish  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j, k, cnt1, cnt2; n   scanf( %d %d , &n, &m); n   string str1, str2; n   cin >> str1 >> str2; n   if (str1 == str2) { n     return !printf( YES n ); n   } n   cnt1 = cnt2 = 0; n   int l2; n   for (i = 0; i < n && i < m; i++) { n     if (str1[i] == str2[i]) { n       cnt1++; n     } else { n       l2 = i; n       break; n     } n   } n   for (i = n - 1, j = m - 1; i >= 0 && j >= l2; i--, j--) { n     if (str1[i] == str2[j]) { n       cnt2++; n     } else { n       break; n     } n   } n   bool ok = 0; n   for (i = 0; i < n; i++) n     if (str1[i] ==  * ) ok = 1; n   if (cnt1 + cnt2 + 1 == n && ok) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n int main() { n   scanf( %d , &t); n   while (t--) { n     int a, b; n     scanf( %d%d , &a, &b); n     int k = min(max(2 * a, b), max(a, 2 * b)); n     printf( %d n , k * k); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n const int L = 30; n int n; n int a[N]; n struct Trie { n   Trie *l, *r; n   Trie(Trie *l_, Trie *r_) { n     l = l_; n     r = r_; n   } n }; n struct Ans { n   Trie *t; n   long long ans; n }; n int get(Trie *l, Trie *r, int i) { n   if (i == -1) return 0; n   if (l->l && r->l && l->r && r->r) n     return min(get(l->l, r->l, i - 1), get(l->r, r->r, i - 1)); n   else if (l->l && r->l) n     return get(l->l, r->l, i - 1); n   else if (l->r && r->r) n     return get(l->r, r->r, i - 1); n   else if (l->l) n     return get(l->l, r->r, i - 1) + (1 << i); n   else n     return get(l->r, r->l, i - 1) + (1 << i); n } n Ans solve(int i, int mn, int mx) { n   if (i == -1) return {new Trie(NULL, NULL), 0}; n   int l = lower_bound(a, a + n, mn) - a; n   int r = upper_bound(a, a + n, mx) - a - 1; n   if (a[r] < mn + (1 << i)) { n     auto t = solve(i - 1, mn, mn + (1 << i) - 1); n     t.t = new Trie(t.t, NULL); n     return t; n   } n   if (mn + (1 << i) <= a[l]) { n     auto t = solve(i - 1, mn + (1 << i), mx); n     t.t = new Trie(NULL, t.t); n     return t; n   } n   { n     auto l = solve(i - 1, mn, mn + (1 << i) - 1); n     auto r = solve(i - 1, mn + (1 << i), mx); n     Ans ans; n     ans.ans = l.ans + r.ans + get(l.t, r.t, i - 1) + (1 << i); n     ans.t = new Trie(l.t, r.t); n     return ans; n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   sort(a, a + n); n   cout << solve(L - 1, 0, (1 << L) - 1).ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct _lap { n   int p; n   int qu; n } lap; n bool cmp(const lap &a, const lap &b) { return a.p < b.p; } n void remain() { n   int n; n   cin >> n; n   vector<lap> laps; n   for (int i = 0; i < n; ++i) { n     lap x; n     cin >> x.p >> x.qu; n     laps.push_back(x); n   } n   sort(laps.begin(), laps.end(), cmp); n   enum RE { HAPPY_ALEX, POOR_ALEX }; n   RE re = POOR_ALEX; n   for (int i = 0; i < laps.size() - 1; ++i) { n     if (!(laps[i].qu < laps[i + 1].qu)) { n       re = HAPPY_ALEX; n       break; n     } n   } n   if (re == HAPPY_ALEX) n     cout <<  Happy Alex ; n   else n     cout <<  Poor Alex ; n } n int main() { n   remain(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n int n, k; n int ans; n int f[1000001]; n bool done[1000001]; n vector<int> g[1000001]; n void dfs(int u) { n   done[u] = 1; n   for (int &v : g[u]) n     if (done[v]) { n       swap(v, g[u].back()); n       g[u].pop_back(); n       break; n     } n   for (int v : g[u]) dfs(v); n   sort(g[u].begin(), g[u].end(), [](int x, int y) { return f[x] < f[y]; }); n   while ((g[u].size() >= 2) && n          (f[g[u].back()] + f[g[u][g[u].size() - 2]] + 2 > k)) { n     ans++; n     g[u].pop_back(); n   } n   if (g[u].empty()) n     return; n   else if (f[g[u].back()] > k) { n     ans++; n     f[u] = -1e9; n   } else n     f[u] = f[g[u].back()] + 1; n } n int main() { n   read(n); n   read(k); n   { n     int u, v; n     for (int i = (1); i < (n); i++) { n       read(u); n       read(v); n       g[u].push_back(v); n       g[v].push_back(u); n     } n   } n   int root = 1; n   for (int i = (1); i <= (n); i++) n     if (g[i].size() > 1) { n       root = i; n       break; n     } n   dfs(root); n   if (f[root] >= 0) ans++; n   writeln(ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, i, flag = 0, j; n     cin >> n; n     long long int a[n]; n     set<int> s; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       s.insert(a[i]); n     } n     for (i = 1; i <= 1024; i++) { n       set<int> temp; n       for (j = 0; j < n; j++) { n         temp.insert(i ^ a[j]); n       } n       if (temp == s) { n         flag = 1; n         cout << i << endl; n         break; n       } n     } n     if (flag == 0) cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   unsigned short int m, n, c; n   scanf( %hu%hu , &m, &n); n   c = m * n; n   int i = 1; n   while (i) { n     if (c >= 2 * i) n       i++; n     else n       break; n   } n   printf( %d n , (i - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long c, hr, hb, wr, wb; n int main() { n   cin >> c >> hr >> hb >> wr >> wb; n   long long i, mx = 0, mxi; n   for (i = 0; i <= c / wr; i += 1000) n     if (i * hr + ((c - i * wr) / wb) * hb > mx) { n       mx = i * hr + ((c - i * wr) / wb) * hb; n       mxi = i; n     } n   for (i = max((long long)0, mxi - 20005); i <= min(c / wr, mxi + 20005); i++) n     if (i * hr + ((c - i * wr) / wb) * hb > mx) { n       mx = i * hr + ((c - i * wr) / wb) * hb; n       mxi = i; n     } n   cout << mx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010; n int n, m; n char str[N][N]; n int use[N]; n int ans[N], tot; n int Ncnt, root; n struct Node { n   vector<int> ch; n   int color; n   int leaf; n   int kind; n   Node(void){}; n } tree[N * N * 2]; n void fail() { n   puts( NO ); n   exit(0); n } n void build() { n   root = Ncnt; n   tree[root].kind = 0; n   for (int i = 1; i <= m; i++) { n     ++Ncnt; n     tree[Ncnt].leaf = i; n     tree[root].ch.push_back(Ncnt); n   } n } n void paint(int rt) { n   if (tree[rt].leaf) { n     if (use[tree[rt].leaf]) n       tree[rt].color = 2; n     else n       tree[rt].color = 0; n     return; n   } n   int empty = 1, half = 0, full = 1; n   for (int i = 0; i < tree[rt].ch.size(); i++) { n     int v = tree[rt].ch[i]; n     paint(v); n     if (tree[v].color) empty = 0; n     if (!tree[v].color) full = 0; n     if (tree[v].color == 1) half = 1; n   } n   if ((!empty && !full) || (half)) n     tree[rt].color = 1; n   else if (full) n     tree[rt].color = 2; n   else if (empty) n     tree[rt].color = 0; n } n void clear(int rt) { n   vector<int> newch; n   for (int i = 0; i < tree[rt].ch.size(); i++) { n     int v = tree[rt].ch[i]; n     if (tree[v].leaf) { n       newch.push_back(v); n       continue; n     } n     if (tree[v].ch.size() == 1) n       newch.push_back(tree[v].ch[0]); n     else n       newch.push_back(v); n   } n   tree[rt].ch = newch; n   if (tree[rt].ch.size() <= 2) tree[rt].kind = 0; n } n void arrange(int rt) { n   if (tree[rt].leaf) return; n   vector<int> son = tree[rt].ch, emp, ful; n   int d = -1; n   for (int i = 0; i < son.size(); i++) { n     int v = tree[rt].ch[i]; n     if (tree[v].color == 1) { n       if (d != -1) fail(); n       if (d == -1) d = i; n     } n     if (tree[v].color == 0) emp.push_back(i); n     if (tree[v].color == 2) ful.push_back(i); n   } n   if (d != -1) arrange(son[d]); n   int empn = emp.size(), fuln = ful.size(); n   if (tree[rt].kind) { n     if ((empn && emp[empn - 1] - emp[0] != empn - 1) || n         (fuln && ful[fuln - 1] - ful[0] != fuln - 1)) n       fail(); n     if (d != -1) { n       if (empn && fuln) { n         if (d == 0 || d == son.size() - 1) { n           fail(); n         } n       } n     } n     if (empn && fuln) { n       if (emp[0] > ful[0]) { n         reverse(emp.begin(), emp.end()); n         reverse(ful.begin(), ful.end()); n       } n     } n     if (empn && !fuln && d != -1) { n       if (emp[0] > d) reverse(emp.begin(), emp.end()); n     } n     if (fuln && !empn && d != -1) { n       if (ful[0] < d) reverse(ful.begin(), ful.end()); n     } n     vector<int> newch; n     for (int i = 0; i < empn; i++) newch.push_back(son[emp[i]]); n     if (d != -1) { n       int v = son[d]; n       for (int i = 0; i < tree[v].ch.size(); i++) n         newch.push_back(tree[v].ch[i]); n     } n     for (int i = 0; i < fuln; i++) newch.push_back(son[ful[i]]); n     tree[rt].ch = newch; n   } else { n     tree[rt].kind = 1; n     vector<int> newch; n     if (empn) { n       ++Ncnt; n       for (int i = 0; i < empn; i++) tree[Ncnt].ch.push_back(son[emp[i]]); n       clear(Ncnt); n       newch.push_back(Ncnt); n     } n     if (d != -1) { n       int v = son[d]; n       for (int i = 0; i < tree[v].ch.size(); i++) n         newch.push_back(tree[v].ch[i]); n     } n     if (fuln) { n       ++Ncnt; n       for (int i = 0; i < fuln; i++) tree[Ncnt].ch.push_back(son[ful[i]]); n       clear(Ncnt); n       newch.push_back(Ncnt); n     } n     tree[rt].ch = newch; n   } n   clear(rt); n } n void solve(int rt) { n   if (tree[rt].leaf) return; n   int count = 0, full = 0; n   for (int i = 0; i < tree[rt].ch.size(); i++) { n     int v = tree[rt].ch[i]; n     if (tree[v].color == 1) count++; n     if (tree[v].color == 2) full++; n   } n   if (count > 2) fail(); n   if (full || count > 1) { n     vector<int> son = tree[rt].ch, ful, hlf; n     for (int i = 0; i < son.size(); i++) { n       int v = son[i]; n       if (tree[v].color == 1) hlf.push_back(i); n       if (tree[v].color == 2) ful.push_back(i); n     } n     int fuln = ful.size(), hlfn = hlf.size(); n     if (tree[rt].kind == 1) { n       if (fuln && ful[fuln - 1] - ful[0] != fuln - 1) fail(); n       for (int i = 0; i < hlfn; i++) n         if (fuln && hlf[i] != ful[0] - 1 && hlf[i] != ful[fuln - 1] + 1) fail(); n       vector<int> newch; n       for (int i = 0; i < son.size(); i++) { n         if (tree[son[i]].color != 1) n           newch.push_back(son[i]); n         else { n           arrange(son[i]); n           vector<int> pp = tree[son[i]].ch; n           if ((hlfn != 1 && i != hlf[0]) || n               (hlfn == 1 && fuln && hlf[0] == ful[fuln - 1] + 1)) n             reverse(pp.begin(), pp.end()); n           for (int i = 0; i < pp.size(); i++) newch.push_back(pp[i]); n         } n       } n       tree[rt].ch = newch; n     } else { n       vector<int> newch; n       for (int i = 0; i < hlfn; i++) arrange(son[hlf[i]]); n       for (int i = 0; i < son.size(); i++) n         if (tree[son[i]].color == 0) newch.push_back(son[i]); n       int nowq = ++Ncnt; n       tree[nowq].kind = 1; n       newch.push_back(nowq); n       if (hlfn) { n         int v = son[hlf[0]]; n         for (int i = 0; i < tree[v].ch.size(); i++) n           tree[nowq].ch.push_back(tree[v].ch[i]); n       } n       if (fuln) { n         int nowp = ++Ncnt; n         tree[nowp].kind = 0; n         for (int i = 0; i < fuln; i++) tree[nowp].ch.push_back(son[ful[i]]); n         clear(nowp); n         tree[nowq].ch.push_back(nowp); n       } n       if (hlfn == 2) { n         int v = son[hlf[1]]; n         for (int i = tree[v].ch.size() - 1; i >= 0; i--) n           tree[nowq].ch.push_back(tree[v].ch[i]); n       } n       clear(nowq); n       tree[rt].ch = newch; n     } n   } else { n     for (int i = 0; i < tree[rt].ch.size(); i++) { n       int v = tree[rt].ch[i]; n       if (tree[v].color == 1) solve(v); n     } n   } n   clear(rt); n } n void dfs(int rt) { n   if (tree[rt].leaf) { n     ans[++tot] = tree[rt].leaf; n     return; n   } n   for (int i = 0; i < tree[rt].ch.size(); i++) dfs(tree[rt].ch[i]); n } n int main() { n   scanf( %d , &n); n   m = n; n   for (int i = 1; i <= n; i++) scanf( %s , str[i] + 1); n   build(); n   for (int i = 1; i <= n; i++) { n     memset(use, 0, sizeof use); n     for (int j = 1; j <= m; j++) n       if (str[i][j] ==  1 ) use[j]++; n     paint(root); n     solve(root); n   } n   dfs(root); n   puts( YES ); n   for (int i = 1; i <= n; i++, puts(  )) n     for (int j = 1; j <= n; j++) printf( %c , str[i][ans[j]]); n   return 0; n } n