#include <bits/stdc++.h> n using std::abs; n using std::bitset; n using std::cerr; n using std::cin; n using std::copy; n using std::cout; n using std::deque; n using std::endl; n using std::fill; n using std::fixed; n using std::greater; n using std::iota; n using std::istream; n using std::lower_bound; n using std::make_pair; n using std::make_tuple; n using std::map; n using std::max; n using std::max_element; n using std::min; n using std::min_element; n using std::multiset; n using std::next_permutation; n using std::nth_element; n using std::ostream; n using std::pair; n using std::priority_queue; n using std::queue; n using std::reverse; n using std::rotate; n using std::set; n using std::sort; n using std::string; n using std::swap; n using std::tie; n using std::tuple; n using std::unique; n using std::unordered_map; n using std::unordered_set; n using std::upper_bound; n using std::vector; n long long rnd(long long x, long long y) { n   static auto gen = std::bind(std::uniform_int_distribution<long long>(), n                               std::mt19937(960172)); n   return gen() % (y - x + 1) + x; n } n long long gcd(long long a, long long b) { n   while (b > 0) { n     long long t = a % b; n     a = b; n     b = t; n   } n   return a; n } n template <typename T> n T sqr(T const& a) { n   return a * a; n } n int const INF = 100 + (int)1e9; n long long const INFL = 100 + (long long)1e18; n long double const PI = 3.1415926535897932384626433832795028; n int const N = 211; n int const A = 26; n int next[N][A]; n int link[N]; n int go[N][A]; n int prev[N]; n int back[N]; n int leaf[N]; n int sz; n int getNode(int pr, int edge) { n   std::fill(next[sz], next[sz] + A, -1); n   link[sz] = -1; n   std::fill(go[sz], go[sz] + A, -1); n   prev[sz] = pr; n   back[sz] = edge; n   leaf[sz] = 0; n   return sz++; n } n int getGo(int, int); n int getLink(int v) { n   if (link[v] == -1) { n     if (v == 0 || prev[v] == 0) { n       link[v] = 0; n     } else { n       link[v] = getGo(getLink(prev[v]), back[v]); n     } n   } n   return link[v]; n } n int getGo(int v, int x) { n   if (go[v][x] == -1) { n     if (next[v][x] != -1) { n       go[v][x] = next[v][x]; n     } else if (v == 0) { n       go[v][x] = v; n     } else { n       go[v][x] = getGo(getLink(v), x); n     } n   } n   return go[v][x]; n } n void mul(long long a[N][N], long long b[N][N], long long c[N][N]) { n   static long long t[N][N]; n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < N; ++j) { n       long long cur = -INFL; n       for (int k = 0; k < N; ++k) { n         cur = max(cur, a[i][k] + b[k][j]); n       } n       t[i][j] = cur; n     } n   } n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < N; ++j) { n       c[i][j] = t[i][j]; n     } n   } n } n int a[N]; n void solve() { n   int n; n   long long L; n   scanf( n        %d  n        %lld , n       &n, &L); n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n   } n   static char buf[N]; n   gets(buf); n   getNode(0, 0); n   for (int i = 0; i < n; ++i) { n     gets(buf); n     int v = 0; n     for (int j = 0; buf[j]; ++j) { n       int x = buf[j] -  a ; n       if (next[v][x] == -1) { n         next[v][x] = getNode(v, x); n       } n       v = next[v][x]; n     } n     leaf[v] += a[i]; n   } n   { n     vector<int> q = {0}; n     for (int head = 0; head < (int)q.size(); ++head) { n       int v = q[head]; n       leaf[v] += leaf[getLink(v)]; n       for (int x = 0; x < A; ++x) { n         int to = next[v][x]; n         if (to >= 0) { n           q.push_back(to); n         } n       } n     } n   } n   static long long mat[N][N]; n   for (int i = 0; i < N; ++i) { n     fill(mat[i], mat[i] + N, -INFL); n   } n   for (int from = 0; from < sz; ++from) { n     for (int x = 0; x < A; ++x) { n       int to = getGo(from, x); n       if (mat[to][from] == -INFL) { n         mat[to][from] = 0; n       } n       mat[to][from] += leaf[to]; n     } n   } n   static long long dp[N]; n   fill(dp, dp + N, -INFL); n   dp[0] = 0; n   for (long long l = L; l > 0; l /= 2) { n     if (l % 2 == 1) { n       static long long dp1[N]; n       for (int v = 0; v < N; ++v) { n         long long cur = -INFL; n         for (int u = 0; u < N; ++u) { n           cur = max(cur, dp[u] + mat[v][u]); n         } n         dp1[v] = cur; n       } n       for (int i = 0; i < N; ++i) { n         dp[i] = dp1[i]; n       } n     } n     mul(mat, mat, mat); n   } n   cout << *max_element(dp, dp + N) << endl; n } n int main() { n   cout.precision(15); n   cout << fixed; n   cerr.precision(6); n   cerr << fixed; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n void solve() { n   int n; n   cin >> n; n   long double pi = 2.0 * acos(0.0), ans, x; n   x = pi / (long double)(2.0 * n); n   ans = tan(x); n   cout << fixed << setprecision(9) << 1.0 / ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimise( Ofast ,  unroll-loops) n using namespace std; n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   long long a[n][m], b[n * m + 3], c[n][m]; n   memset(a, 0, sizeof(a)); n   memset(b, 0, sizeof(b)); n   memset(c, 0, sizeof(c)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < k; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     b[y]++; n     c[x][y]++; n   } n   for (int i = 0; i < n - 1; i++) { n     long long ans = 0; n     for (int j = 0; j < m; j++) { n       if (a[i][j] == 1) { n         ans += (b[j] - c[i][j]); n       } n     } n     cout << ans <<    ; n   } n   long long ans = 0; n   for (int j = 0; j < m; j++) { n     if (a[n - 1][j] == 1) { n       ans += (b[j] - c[n - 1][j]); n     } n   } n   cout << ans; n   return; n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long a[14], tmp[14]; n   for (long long i = 0; i < 14; i++) cin >> a[i]; n   long long anss = 0; n   for (long long i = 0; i < 14; i++) { n     for (long long j = 0; j < 14; j++) tmp[j] = a[j]; n     long long ans = 0; n     if (tmp[i]) { n       long long k = tmp[i]; n       long long add = k / 14; n       long long rem = k % 14; n       tmp[i] = 0; n       long long p = i + 1; n       for (long long j = 0; j < 14; j++) { n         tmp[p % 14] += add; n         p++; n       } n       p = i + 1; n       while (rem) { n         tmp[p % 14]++; n         p++; n         rem--; n       } n       for (long long j = 0; j < 14; j++) n         if (tmp[j] % 2 == 0) ans += tmp[j]; n     } n     anss = max(anss, ans); n   } n   cout << anss; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300002; n int n, m, l[MAXN * 4], r[MAXN * 4], d[MAXN * 4], id[MAXN]; n string s; n void input() { n   scanf( %d%d , &n, &m); n   cin.ignore(1); n   getline(cin, s); n   s =  0  + s; n } n void init(int x, int left, int right) { n   l[x] = left; n   r[x] = right; n   if (left == right) { n     d[x] = 0; n     id[left] = x; n     return; n   } n   int mid = (left + right) / 2; n   init(x * 2, left, mid); n   init(x * 2 + 1, mid + 1, right); n   d[x] = d[x * 2] + d[x * 2 + 1]; n   if (s[mid] ==  .  && s[mid + 1] ==  . ) d[x]++; n } n void update(int a) { n   int x = id[a]; n   x /= 2; n   while (x > 0) { n     d[x] = d[x * 2] + d[x * 2 + 1]; n     if (s[r[x * 2]] ==  .  && s[l[x * 2 + 1]] ==  . ) d[x]++; n     x /= 2; n   } n } n int main() { n   input(); n   init(1, 1, n); n   int a; n   char b; n   for (int q = 1; q <= m; q++) { n     scanf( %d %c , &a, &b); n     if ((s[a] ==  .  && b ==  . ) || (s[a] !=  .  && b !=  . )) { n       printf( %d n , d[1]); n       continue; n     } n     s[a] = b; n     update(a); n     printf( %d n , d[1]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, len; n long long a, b, c, l; n void solve() { n   long long tot = ((l + 3) * (l + 2) * (l + 1)) / 6; n   long long i; n   for (i = 0; i <= l; i++) { n     long long x = min(a - b - c + i, l - i); n     if (x < 0) continue; n     tot -= ((x + 2) * (x + 1)) >> 1; n   } n   for (i = 0; i <= l; i++) { n     long long x = min(b - a - c + i, l - i); n     if (x < 0) continue; n     tot -= ((x + 2) * (x + 1)) >> 1; n   } n   for (i = 0; i <= l; i++) { n     long long x = min(c - a - b + i, l - i); n     if (x < 0) continue; n     tot -= ((x + 2) * (x + 1)) >> 1; n   } n   cout << tot <<   n ; n } n int main() { n   long long i, j, k, t; n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> a >> b >> c >> l; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000009; n const int MAXN = 100000; n int n, m; n vector<pair<int, int> > graph[MAXN + 3]; n bool vis[MAXN + 3]; n bool color[MAXN + 3]; n vector<int> ans[2], curr, output; n int counter; n void Read() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b, c; n     char col; n     scanf( %d %d %c , &a, &b, &col); n     if (col ==  B ) n       c = 1; n     else n       c = 0; n     graph[a].push_back(make_pair(b, c)); n     graph[b].push_back(make_pair(a, c)); n   } n } n void Clean() { n   for (int i = 1; i <= n; i++) vis[i] = false; n   for (int i = 1; i <= n; i++) color[i] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < (int)graph[i].size(); j++) n       graph[i][j].second = (graph[i][j].second + 1) % 2; n   curr.clear(); n } n bool Dfs(int v) { n   vis[v] = true; n   curr.push_back(v); n   if (color[v] == 0) counter++; n   for (int i = 0; i < (int)graph[v].size(); i++) { n     int u = graph[v][i].first; n     int sum = graph[v][i].second; n     if (!vis[u]) { n       color[u] = (sum - color[v] + 2) % 2; n       if (Dfs(u) == false) return false; n     } else { n       if (color[u] != (sum - color[v] + 2) % 2) return false; n     } n   } n   return true; n } n bool Solve(int ind) { n   for (int v = 1; v <= n; v++) { n     if (!vis[v]) { n       if (Dfs(v) == false) return false; n     } n     for (int i = 0; i < (int)curr.size(); i++) { n       if (color[curr[i]] == 0 && 2 * counter < (int)curr.size()) n         ans[ind].push_back(curr[i]); n       else if (color[curr[i]] == 1 && 2 * counter >= (int)curr.size()) n         ans[ind].push_back(curr[i]); n     } n     curr.clear(); n     counter = 0; n   } n   return true; n } n int main() { n   Read(); n   bool check0 = Solve(0); n   Clean(); n   bool check1 = Solve(1); n   if (!check0 && !check1) { n     puts( -1 ); n     return 0; n   } n   if (!check1 || (ans[0].size() < ans[1].size() && check0)) n     output = ans[0]; n   else n     output = ans[1]; n   printf( %d n , (int)output.size()); n   for (int i = 0; i < (int)output.size(); i++) { n     printf( %d  , output[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string res; n map<string, int> stv; n map<int, string> vts; n vector<string> a, s({ 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 , n                       1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 }); n vector<vector<int>> dp; n int cnt(string f, string t) { n   int res = 0; n   for (int i = 0; i < 7; i++) { n     if (f[i] != t[i]) { n       ++res; n       if (f[i] ==  1 ) return -1; n     } n   } n   return res; n } n int bt(int in, int k) { n   if (k < 0) return 0; n   if (in >= n) return k == 0; n   int& dpv = dp[in][k]; n   if (dpv == 1) return 0; n   for (int i = 9; i >= 0; i--) { n     int c = cnt(a[in], vts[i]); n     if (c >= 0 && bt(in + 1, k - c)) { n       res.push_back(i +  0 ); n       return 1; n     } n   } n   dpv = 1; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int k; n   cin >> n >> k; n   a.resize(n); n   dp.assign(n, vector<int>(k + 1)); n   for (auto& i : a) cin >> i; n   for (int i = 0; i < 10; i++) { n     stv[s[i]] = i; n     vts[i] = s[i]; n   } n   if (bt(0, k)) { n     reverse(res.begin(), res.end()); n     cout << res; n   } else { n     cout << -1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void et(bool f = 0) { n   puts(f ?  MAGIC  :  NOT MAGIC ); n   exit(0); n } n int a[2505][2505]; n bitset<2505> bs[2505]; n void fmain() { n   scanf( %d , &n); n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     for (int(j) = 1; (j) <= (int)(n); (j)++) scanf( %d , &a[i][j]); n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     if (a[i][i] != 0) et(); n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     for (int j = i + 1; j <= n; j++) n       if (a[i][j] != a[j][i]) et(); n   vector<pair<int, pair<int, int>>> vp; n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     for (int(j) = 1; (j) <= (int)(n); (j)++) vp.push_back({a[i][j], {i, j}}); n   int N = vp.size(); n   sort(vp.begin(), vp.end()); n   for (int i = 0, j = 0; i < N; i = j) { n     for (j = i; j < N && vp[i].first == vp[j].first; j++) n       ; n     for (int k = i; k < j; k++) { n       auto p = vp[k].second; n       if ((bs[p.first] & bs[p.second]).any()) et(); n     } n     for (int k = i; k < j; k++) { n       auto p = vp[k].second; n       bs[p.first][p.second] = 1; n     } n   } n   et(1); n } n int main() { n   fmain(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100, inf = 0x3f3f3f3f, mod = 1e9 + 7, M = 1e6 + 1000; n const long long INF = 0x3f3f3f3f3f3f3f3f; n long long sp(long long a, long long b, long long d) { n   if (!b) return 1; n   return b % 2 ? sp(a * a, b / 2, d) * a % d : sp(a * a, b / 2, d); n } n long long sp1(long long a, long long b) { n   if (!b) return 1; n   return b % 2 ? sp1(a * a, b / 2) * a : sp1(a * a, b / 2); n } n long long lowbit(long long x) { return x & (-x); } n long long exgcd(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1; n     y = 0; n     return a; n   } else { n     long long d = exgcd(b, a % b, y, x); n     y -= (a / b) * x; n     return d; n   } n } n long long t, n; n char str[N]; n long long ck(char s) { n   long long l = 1, r = n, x = 0; n   while (l <= r) { n     if (str[l] == str[r]) { n       l++; n       r--; n     } else { n       if (str[l] == s) { n         l++; n         x++; n       } else if (str[r] == s) { n         r--; n         x++; n       } else { n         return -1; n       } n     } n   } n   return x; n } n int main() { n   cin >> t; n   while (t--) { n     scanf( %lld%s , &n, str + 1); n     long long ans = -1; n     for (int i = 0; i <= 25; i++) { n       char s = i +  a ; n       long long x = ck(s); n       if (x == -1) continue; n       if (ans == -1 || ans > x) ans = x; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[300005]; n vector<long long> adjlist[1048585]; n int main() { n   long long n, i; n   scanf( %lld , &n); n   for (i = 0; i < n; i++) { n     scanf( %lld , a + i); n   } n   for (i = 1; i < n; i++) { n     a[i] = a[i - 1] ^ a[i]; n   } n   adjlist[0].push_back(0); n   for (i = 0; i < n; i++) { n     adjlist[a[i]].push_back(i + 1); n   } n   long long ans = 0; n   for (i = 0; i < 1048580; i++) { n     if (adjlist[i].size() > 0) { n       long long od = 0, ev = 0; n       for (auto e : adjlist[i]) { n         if (e % 2 == 0) n           ev++; n         else n           od++; n       } n       ans += (ev * (ev - 1)) / 2; n       ans += (od * (od - 1)) / 2; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int n, m; n int d[250000]; n int h[250000]; n int c[250000]; n int r[250000]; n int diferencias[160000]; n int a[401]; n bool sirve(int v, int idCamion) { n   int litros = v; n   int cantRecargas = r[idCamion]; n   for (int i = d[idCamion] + 1; i <= h[idCamion]; i++) { n     if (v < a[i] - a[i - 1]) { n       return false; n     } n     if (litros < a[i] - a[i - 1]) { n       if (cantRecargas) { n         litros = v; n         cantRecargas--; n       } else { n         return false; n       } n     } n     litros -= a[i] - a[i - 1]; n   } n   return true; n } n int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , &a[i + 1]); n   for (int i = 0; i < m; i++) scanf( %d %d %d %d , &d[i], &h[i], &c[i], &r[i]); n   int tam2 = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) diferencias[tam2++] = a[j] - a[i]; n   qsort(diferencias, tam2, sizeof(int), cmpfunc); n   int tam = 1; n   for (int i = 1; i < tam2; i++) n     if (diferencias[i] != diferencias[tam - 1]) n       diferencias[tam++] = diferencias[i]; n   long long minV = 0; n   int ini, fin, mid; n   for (int i = 0; i < m; i++) { n     ini = 0; n     fin = tam - 1; n     while (ini + 1 < fin) { n       mid = (ini + fin) / 2; n       if (sirve(diferencias[mid], i)) n         fin = mid; n       else n         ini = mid; n     } n     if (sirve(diferencias[ini], i)) n       minV = (minV > ((long long)diferencias[ini]) * ((long long)c[i]) n                   ? minV n                   : ((long long)diferencias[ini]) * ((long long)c[i])); n     else n       minV = (minV > ((long long)diferencias[fin]) * ((long long)c[i]) n                   ? minV n                   : ((long long)diferencias[fin]) * ((long long)c[i])); n   } n   printf( %I64d n , minV); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[300010][27]; n int val[300010], cost[610]; n int fail[300010]; n string st[610]; n char s[300010], p[300010]; n int main() { n   int T, op, len, slen, i, j, k, x; n   long long ans; n   for (scanf( %d , &T); T; --T) { n     scanf( %d %s , &op, s); n     len = strlen(s); n     if (op <= 2) { n       if (len <= 500) { n         for (i = 0, j = 0; i < len; ++i) { n           if (!a[j][x = s[i] -  a ]) a[j][x] = ++m; n           j = a[j][x]; n         } n         val[j] += op == 1 ? 1 : -1; n       } else { n         st[++n] = s; n         cost[n] = op == 1 ? 1 : -1; n       } n     } else { n       ans = 0; n       for (i = 0; i < len; ++i) n         for (k = i, j = 0; k < len; ++k) { n           if (!a[j][x = s[k] -  a ]) break; n           j = a[j][x]; n           ans += val[j]; n         } n       for (i = 1; i <= n; ++i) { n         if ((slen = st[i].length()) > len) continue; n         fail[0] = fail[1] = 0; n         for (j = 1; j < slen; ++j) { n           for (k = fail[j]; k && st[i][k] != st[i][j]; k = fail[k]) n             ; n           fail[j + 1] = st[i][k] == st[i][j] ? k + 1 : 0; n         } n         for (j = 0, k = 0; j < len; ++j) { n           while (k && st[i][k] != s[j]) k = fail[k]; n           if (st[i][k] == s[j]) ++k; n           if (k == slen) { n             ans += cost[i]; n             k = fail[k]; n           } n         } n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1234567; n vector<int> rev[N]; n char foo[N]; n int on_cycle[N]; n int digit[N], to[N]; n bool found; n void dfs(int v, int pos) { n   if (pos < 0) { n     found = true; n   } n   if (found) { n     return; n   } n   int sz = rev[v].size(); n   for (int j = 0; j < sz; j++) { n     int u = rev[v][j]; n     if (on_cycle[u] != -1) { n       continue; n     } n     dfs(u, pos - (digit[u] == foo[pos] -  0 )); n   } n } n int dx[42], dy[42]; n int last[42]; n bool vis[N]; n const int NNN = 444; n char s[NNN][NNN]; n int main() { n   int n, m, q; n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < n; i++) { n     scanf( %s , s[i]); n   } n   for (int d = 0; d <= 9; d++) { n     scanf( %d %d , dx + d, dy + d); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int d = s[i][j] -  0 ; n       int x = i + dx[d]; n       int y = j + dy[d]; n       if (x < 0 || y < 0 || x >= n || y >= m) { n         x = i; n         y = j; n       } n       digit[i * m + j] = d; n       to[i * m + j] = x * m + y; n     } n   } n   n = n * m; n   for (int i = 0; i < n; i++) { n     vis[i] = false; n     rev[i].clear(); n     on_cycle[i] = -1; n   } n   for (int i = 0; i < n; i++) { n     rev[to[i]].push_back(i); n   } n   for (int i = 0; i < n; i++) { n     if (vis[i]) { n       continue; n     } n     int p = i; n     vector<int> cycle; n     while (!vis[p]) { n       cycle.push_back(p); n       vis[p] = true; n       p = to[p]; n     } n     int id = -1; n     for (int i = 0; i < (int)cycle.size(); i++) { n       if (cycle[i] == p) { n         id = i; n         break; n       } n     } n     if (id == -1) { n       continue; n     } n     int mask = 0; n     for (int i = id; i < (int)cycle.size(); i++) { n       mask |= (1 << digit[cycle[i]]); n     } n     for (int i = id; i < (int)cycle.size(); i++) { n       on_cycle[cycle[i]] = mask; n     } n   } n   while (q--) { n     scanf( %s , foo); n     int len = strlen(foo); n     for (int d = 0; d <= 9; d++) { n       last[d] = -1; n     } n     for (int i = 0; i < len; i++) { n       last[foo[i] -  0 ] = i; n     } n     found = false; n     for (int start = 0; start < n; start++) { n       if (on_cycle[start] == -1) { n         continue; n       } n       int pos = -1; n       for (int d = 0; d <= 9; d++) { n         if (on_cycle[start] & (1 << d)) { n           continue; n         } n         pos = max(pos, last[d]); n       } n       dfs(start, pos); n     } n     puts(found ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   vector<int> v; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int t; n     cin >> t; n     v.push_back(t); n   } n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   v.erase(remove(v.begin(), v.end(), 0), v.end()); n   cout << v.size() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int d, f, t; n   long long c; n } a[100005]; n int cmp(node a, node b) { return a.d < b.d; } n long long INF = 0x3f3f3f3f3f3f; n long long cost[100005]; n int vis[100005]; n int cnt1[1000006]; n int cnt2[1000006]; n long long sum2[1000006]; n long long sum1[1000006]; n int main() { n   int n, m, k; n   memset(cnt1, 0, sizeof(cnt1)); n   memset(cnt2, 0, sizeof(cnt2)); n   memset(vis, 0, sizeof(vis)); n   memset(cost, INF, sizeof(cost)); n   memset(sum1, 0, sizeof(sum1)); n   memset(sum2, 0, sizeof(sum2)); n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d%I64d , &a[i].d, &a[i].f, &a[i].t, &a[i].c); n   } n   sort(a + 1, a + 1 + m, cmp); n   int pre = 0; n   for (int i = 1; i <= m; i++) { n     if (a[i].f == 0) continue; n     int f = a[i].f; n     int d = a[i].d; n     sum1[d] = sum1[pre]; n     cnt1[d] = cnt1[pre]; n     if (cost[f] > a[i].c) { n       if (vis[f] == 1) n         sum1[d] = sum1[d] - cost[f] + a[i].c; n       else n         sum1[d] += a[i].c; n       cost[f] = a[i].c; n       if (vis[f] == 0) { n         cnt1[d]++; n         vis[f] = 1; n       } n     } n     pre = d; n   } n   for (int i = 1; i <= 1000000; i++) { n     if (cnt1[i] == 0) cnt1[i] = cnt1[i - 1]; n     if (sum1[i] == 0) sum1[i] = sum1[i - 1]; n   } n   memset(vis, 0, sizeof(vis)); n   pre = 1000000; n   memset(cost, INF, sizeof(cost)); n   for (int i = m; i >= 1; i--) { n     if (a[i].t == 0) continue; n     int d = a[i].d; n     int t = a[i].t; n     sum2[d] = sum2[pre]; n     cnt2[d] = cnt2[pre]; n     if (cost[t] > a[i].c) { n       if (vis[t] == 1) n         sum2[d] = sum2[d] - cost[t] + a[i].c; n       else n         sum2[d] += a[i].c; n       cost[t] = a[i].c; n       if (vis[t] == 0) { n         cnt2[d]++; n         vis[t] = 1; n       } n     } n     pre = d; n   } n   for (int i = 1000000; i >= 0; i--) { n     if (cnt2[i] == 0) cnt2[i] = cnt2[i + 1]; n     if (sum2[i] == 0) sum2[i] = sum2[i + 1]; n   } n   long long ans = INF; n   for (int i = 1; i <= 1000000; i++) { n     if (i + k + 1 > 1000000) break; n     if (cnt1[i] == n && cnt2[i + k + 1] == n) n       ans = min(ans, (long long)sum1[i] + sum2[i + k + 1]); n   } n   if (ans == INF) { n     printf( -1 n ); n     return 0; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e6; n long long n, b, s[MAXN], m[MAXN], t = 0; n long long i, j, d = 0; n bool q[MAXN]; n int main() { n   cin >> n >> b; n   fill(q, q + n, false); n   for (i = 0; i < n; i++) { n     cin >> s[i] >> m[i]; n   } n   j = 0; n   for (i = 0; i < n; i++) { n     if (i > 0) cout << endl; n     if (j == i && q[j] == false) { n       q[j] = true; n       t = s[i]; n       d++; n       j++; n     } n     if (q[i] == true) { n       t += m[i]; n       d--; n       cout << t; n     } else n       cout << -1; n     while (q[j] == false && t > s[j] && j < n) { n       if (d + 1 > b) n         d--; n       else n         q[j] = true; n       j++; n       d++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2111; n const int mod = 1e9 + 7; n int n; n int pri[N], tot; n long long a[N], b[N]; n struct node { n   long long k, b; n   node(long long _k = 0, long long _b = 0) { n     k = _k; n     b = _b; n   } n } f[N], g[N]; n long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } n long long ksm(long long base, long long x) { n   long long ans = 1; n   while (x) { n     if (x & 1) ans = ans * base % mod; n     base = base * base % mod; n     x >>= 1; n   } n   return ans; n } n void get(int x) { n   for (int i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       pri[++tot] = i; n       while (x % i == 0) x /= i; n     } n   } n   if (x > 1) pri[++tot] = x; n } n void get_g(int id) { n   for (int i = 1; i <= tot; i++) { n     g[i].b = g[i].k = 0; n     while (a[id] % pri[i] == 0) { n       g[i].b++; n       a[id] /= pri[i]; n     } n     while (b[id] % pri[i] == 0) { n       g[i].k++; n       b[id] /= pri[i]; n     } n   } n } n long long ex_gcd(long long A, long long B, long long &x, long long &y) { n   if (!B) { n     x = 1; n     y = 0; n     return A; n   } n   long long xx, yy; n   long long d = ex_gcd(B, A % B, xx, yy); n   x = yy; n   y = xx - A / B * yy; n   return d; n } n bool merge() { n   bool flag = 0; n   for (int t = 0; t < 3; t++) { n     for (int i = 1; i <= tot; i++) { n       long long fk = f[i].k, fb = f[i].b; n       long long gk = g[i].k, gb = g[i].b; n       bool fl = 0; n       if (!fk && !gk) { n         if (fb != gb) return 0; n       } else { n         if (!gk || !fk) { n           if (!fk) swap(fk, gk), swap(fb, gb), fl = 1; n           if (fb > gb || (gb - fb) % fk != 0) return 0; n           long long k = (gb - fb) / fk; n           if (fl) n             for (int j = 1; j <= tot; j++) g[j].b += g[j].k * k, g[j].k = 0; n           else n             for (int j = 1; j <= tot; j++) f[j].b += f[j].k * k, f[j].k = 0; n           flag = 1; n         } n       } n     } n   } n   if (flag) return 1; n   int fl = 0; n   long long A = 0, B = 0, C = 0; n   for (int i = 1; i <= tot; i++) { n     if (!f[i].k || !g[i].k) continue; n     if (!fl) n       A = f[i].k, B = -g[i].k, C = g[i].b - f[i].b, fl = 1; n     else if (fl == 1) { n       long long nA = f[i].k, nB = -g[i].k, nC = g[i].b - f[i].b; n       long long d = gcd(nA, A); n       A *= nA / d; n       B *= nA / d; n       C *= nA / d; n       nA *= A / d; n       nB *= A / d; n       nC *= A / d; n       if (B == nB) { n         if (C != nC) return 0; n         long long d = gcd(A, gcd(abs(B), abs(C))); n         A /= d; n         B /= d; n         C /= d; n         continue; n       } else { n         if ((C - nC) % (B - nB)) return 0; n         long long y = (C - nC) / (B - nB); n         if (y < 0) return 0; n         if ((C - B * y) % A) return 0; n         long long x = (C - B * y) / A; n         if (x < 0) return 0; n         for (int j = 1; j <= tot; j++) f[j].b += f[j].k * x, f[j].k = 0; n         for (int j = i + 1; j <= tot; j++) { n           nA = f[j].k, nB = -g[j].k, nC = g[j].b - f[j].b; n           if (nA * x + nB * y != nC) return 0; n         } n         return 1; n       } n     } n   } n   long long x = -1, y = -1; n   long long d = ex_gcd(A, -B, x, y); n   if (C % d) return 0; n   y *= -1; n   long long kx = (-B) / d; n   long long ky = A / d; n   x *= C / d, y *= C / d; n   long long tx = x < 0 ? -(-x + kx - 1) / kx : x / kx; n   long long ty = y < 0 ? -(-y + ky - 1) / ky : y / ky; n   x -= min(tx, ty) * kx; n   y -= min(tx, ty) * ky; n   for (int i = 1; i <= tot; i++) { n     f[i].b += f[i].k * x; n     f[i].k = f[i].k * kx; n   } n   return 1; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &a[i], &b[i]); n     get(a[i]); n     get(b[i]); n   } n   sort(pri + 1, pri + 1 + tot); n   tot = unique(pri + 1, pri + 1 + tot) - (pri + 1); n   for (int i = 1; i <= tot; i++) { n     while (a[1] % pri[i] == 0) { n       f[i].b++; n       a[1] /= pri[i]; n     } n     while (b[1] % pri[i] == 0) { n       f[i].k++; n       b[1] /= pri[i]; n     } n   } n   for (int i = 2; i <= n; i++) { n     get_g(i); n     if (!merge()) { n       puts( -1 ); n       return 0; n     } n   } n   int ans = 1; n   for (int i = 1; i <= tot; i++) { n     ans = 1LL * ans * ksm(pri[i], f[i].b) % mod; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long u, v, a, b; n   scanf( %lld%lld , &u, &v); n   if (v == 0) n     printf( 0 n ); n   else if (u > v) n     printf( -1 n ); n   else if (u == v) { n     printf( 1 n ); n     printf( %lld n , u); n   } else if ((v - u) % 2 == 0) { n     a = u, b = (v - u) / 2; n     if ((a ^ b) == (a + b)) { n       printf( 2 n ); n       printf( %lld %lld n , a + b, b); n     } else { n       printf( 3 n ); n       printf( %lld %lld %lld n , a, b, b); n     } n   } else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k = 0, c = -1, x, z; n   cin >> n; n   while (true) { n     c += 1; n     x = pow(10, c); n     z = 9 * x; n     if (n - z > 0) { n       n -= z; n       k += (z * (c + 1)); n     } else { n       n *= (c + 1); n       k += n; n       break; n     } n   } n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[27], sum, gcd; n int odd; n int _gcd(int x, int y) { n   if (x == 0 or x == y) return y; n   if (x > y) swap(x, y); n   while (y % x) { n     y %= x; n     swap(x, y); n   } n   return x; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     if (a[i] & 1) odd++; n     sum += a[i]; n     gcd = _gcd(gcd, a[i]); n   } n   if (odd > 1) { n     printf( %d n , 0); n     int k = 0; n     string s(sum,  0 ); n     for (int i = 0; i < n; i++) { n       int j = 0; n       while (j < a[i]) { n         s[j + k] =  a  + i; n         j++; n       } n       k += a[i]; n     } n     cout << s << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) a[i] /= gcd; n   sum /= gcd; n   printf( %d n , gcd); n   if (odd) { n     string s(sum,  0 ); n     int k = 0; n     for (int i = 0; i < n; i++) { n       int j = 0; n       while (j < a[i] / 2) { n         s[j + k] =  a  + i; n         s[sum - 1 - j - k] =  a  + i; n         j++; n       } n       if (a[i] & 1) odd = i; n       k += a[i] / 2; n     } n     s[k] = odd +  a ; n     for (int i = 0; i < gcd; i++) cout << s; n     cout << endl; n   } else { n     string s(sum,  0 ); n     string t(sum,  0 ); n     int k = 0; n     for (int i = 0; i < n; i++) { n       int j = 0; n       while (j < a[i]) { n         s[j + k] =  a  + i; n         t[sum - 1 - j - k] =  a  + i; n         t[sum - 1 - j - k] =  a  + i; n         j++; n       } n       k += a[i]; n     } n     for (int i = 0; i < gcd / 2; i++) cout << s << t; n     cout << endl; n   } n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define mod 1000000007 n void solve() n { n         int k,n,m; n         cin >> k >> n >> m; n         vector<int> a(n); n         for(auto &i:a) n         { n             cin >> i; n         } n         vector<int> b(m); n         for(auto &i:b) n         { n             cin >> i; n         } n         vector<int> res(n+m); n         int i=0,j=0,ind=0; n         while(i!=n && j!=m) n         { n             if(a[i]==0) n             { n                 res[ind]=0; n                 ind++; n                 i++; n                 k++; n             } n             else if(b[j]==0) n             { n                 res[ind]=0; n                 ind++; n                 j++; n                 k++; n             } n             else if(a[i]<=b[j] && a[i]<=k) n             { n                 res[ind]=a[i]; n                 ind++; n                 i++; n             } n             else if(a[i]>=b[j] && b[j]<=k) n             { n                 res[ind]=b[j]; n                 ind++; n                 j++; n             } n             else n             { n                 cout << -1 << endl; n                 return; n             } n         } n         while(i!=n) n         { n             if(a[i]==0) n             { n                 res[ind]=0; n                 ind++; n                 i++; n                 k++; n             } n             else{ n             if(a[i]>k) n             { n                 cout << -1 << endl; n                 return; n             } n             res[ind]=a[i]; n             ind++; n             i++; n             } n         } n         while(j!=m) n         { n             if(b[j]==0) n             { n                 res[ind]=0; n                 ind++; n                 j++; n                 k++; n             } n             else{ n             if(b[j]>k) n             { n                 cout << -1 << endl; n                 return; n             } n             res[ind]=b[j]; n             ind++; n             j++;} n         } n         for(auto x:res) n             cout << x <<    ; n         cout << endl; n } n int main() n { n     int t; n     cin >> t; n     while(t--) n     { n         solve(); n     } n } n  n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ; n   int n; n   cin >> n; n   int odd = 0, even = 0; n   for (int i = 0; i < n; i++) { n     int val; n     cin >> val; n     if (val % 2) n       odd++; n     else n       even++; n   } n   if (odd > even) { n     cout << even + (odd - even) / 3 <<   n ; n   } else n     cout << odd <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct TrieNode { n   TrieNode *arr[2]; n   TrieNode() { arr[0] = arr[1] = nullptr; } n }; n void insert(TrieNode *root, int num) { n   TrieNode *curr = root; n   for (int i = 20; i >= 0; i--) { n     if (curr->arr[(num >> i) & 1] == nullptr) n       curr->arr[(num >> i) & 1] = new TrieNode(); n     curr = curr->arr[(num >> i) & 1]; n   } n   return; n } n int query(TrieNode *root, int xr) { n   int ans = 0; n   TrieNode *curr = root; n   for (int i = 20; i >= 0; i--) { n     if (curr->arr[(xr >> i) & 1] == nullptr) { n       ans |= (1 << i); n       curr = curr->arr[((xr >> i) & 1) ^ 1]; n     } else { n       curr = curr->arr[(xr >> i) & 1]; n     } n   } n   return ans; n } n const int N = 1 << 20 + 1; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   bool present[N]; n   memset(present, false, sizeof(present)); n   vector<int> a(n); n   for (int &i : a) cin >> i, present[i] = true; n   TrieNode *root = new TrieNode(); n   for (int i = 0; i < N; i++) n     if (!present[i]) insert(root, i); n   int curr_xor = 0; n   while (m--) { n     int x; n     cin >> x; n     curr_xor ^= x; n     cout << query(root, curr_xor) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long bp(long long x, long long y) { n   long long ans = 1; n   x %= mod; n   while (y) { n     if (y & 1) ans = ans * x % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long mod_inverse(long long x) { return bp(x, mod - 2); } n long long gcd(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n long long max(long long a, long long b) { n   if (a < b) swap(a, b); n   return a; n } n long long min(long long a, long long b) { n   if (a > b) swap(a, b); n   return a; n } n long long countSetBits(long long n) { n   long long count = 0; n   while (n) { n     count += n & 1; n     n >>= 1; n   } n   return count; n } n void solve() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a[n], b[n]; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     for (long long i = 0; i < n; i++) cin >> b[i]; n     if (n % 2 == 1 && a[n / 2] != b[n / 2]) { n       cout <<  No  << endl; n       continue; n     } n     map<pair<long long, long long>, long long> m; n     for (long long i = 0; i < n / 2; i++) { n       m[make_pair(min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i]))]++; n     } n     long long flag = 0; n     for (long long i = 0; i < n / 2; i++) { n       pair<long long, long long> p = {min(b[i], b[n - 1 - i]), n                                       max(b[i], b[n - 1 - i])}; n       if (m[p] <= 0) { n         flag = 1; n         break; n       } n       m[p]--; n     } n     if (flag == 1) n       cout <<  No  << endl; n     else n       cout <<  yes  << endl; n   } n } n signed main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int modInverse(long long int n, long long int p) { n   return power(n, p - 2, p) % p; n } n void solve() { n   long long int n; n   cin >> n; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   string s =   , s1 =   , s2 =   ; n   for (long long int i = 0; i < 200; i++) { n     s +=  a ; n     s1 +=  b ; n     s2 +=  a ; n   } n   cout << s <<   n ; n   for (long long int i = 0; i < n; i++) { n     if (s[a[i]] ==  a ) { n       s = s.substr(0, a[i]) + s1.substr(0, 200 - a[i]); n     } else { n       s = s.substr(0, a[i]) + s2.substr(0, 200 - a[i]); n     } n     cout << s <<   n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[8] = { vaporeon ,  jolteon ,  flareon ,  espeon , n                 umbreon ,   leafeon ,  glaceon ,  sylveon }; n int f[8] = {0}; n int main() { n   string x; n   int n, k; n   scanf( %d , &n); n   cin >> x; n   for (int i = 0; i < 8; i++) { n     if (s[i].size() != n) { n       f[i] = -1; n     } else { n       f[i] = 1; n       for (int j = 0; j < n; j++) { n         if (s[i][j] == x[j]) { n           f[i]++; n         } else if (s[i][j] != x[j] && x[j] !=  . ) { n           f[i] = -1; n           break; n         } n       } n     } n   } n   for (int i = 0; i < 8; i++) { n     if (f[i] > -1) { n       k = i; n     } n   } n   cout << s[k]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   string second; n   cin >> second; n   int c = 0, d = 0; n   for (auto u : second) { n     if (u ==  n ) n       c++; n     else if (u ==  z ) n       d++; n   } n   while (c--) cout << 1 <<    ; n   while (d--) cout << 0 <<    ; n   cout <<   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(NULL); n   cout.tie(NULL); n   ; n   long long int t = 1; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int ans = -1; n     for (long long int i = 1;; i++) { n       long long int p = n + ((-1) * (i)*k); n       if (p < i) break; n       long long int c = 0; n       while (p > 0) { n         if (p % 2 == 1) c++; n         p /= 2; n       } n       if (c <= i) { n         ans = i; n         break; n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int s1, s11, s12; n   int s2 = 0; n   s1 = s11 = s12 = 0; n   string s, c; n   s = c =   ; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     if (i == 0) { n       s1 = a; n       s2 = 0; n       s =  A ; n     } else { n       if (abs(s1 + a - s2) < abs(s2 + b - s1)) { n         s1 += a; n         s +=  A ; n       } else { n         s2 += b; n         s +=  G ; n       } n     } n     if (i == 0) { n       s11 = 0; n       s12 = b; n       c =  G ; n     } else { n       if (abs(s11 + a - s12) < abs(s12 + b - s11)) { n         s11 += a; n         c +=  A ; n       } else { n         s12 += b; n         c +=  G ; n       } n     } n   } n   if (abs(s1 - s2) <= 500) { n     cout << s; n     return 0; n   } n   if (abs(s11 - s12) <= 500) { n     cout << c; n     return 0; n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n #pragma gcc optimize(O3) n using namespace std; n long long INF = static_cast<long long>(2e18); n long long inf = static_cast<long long>(1e9 + 7); n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n vector<vector<set<long long> > > dp; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   vector<long long> vals(n); n   dp.resize(k, vector<set<long long> >(n)); n   for (auto& it : vals) cin >> it; n   for (long long i = n - 2; i >= 0; --i) vals[i] += vals[i + 1]; n   for (long long i = n - 1; i >= 0; --i) dp[0][i].insert(vals[i]); n   if (k == 1) { n     cout << vals[0]; n     return 0; n   } n   long long res = 0; n   for (long long i = 1; i < k; i++) { n     for (long long j = n - 1 - i; j >= k - i - 1; --j) { n       for (long long q = j + 1; q < n - i + 1; ++q) { n         for (auto& it : dp[i - 1][q]) { n           if (i == (k - 1) && (!j)) { n             res = max(res, ((vals[j] - vals[q]) & it)); n           } else n             dp[i][j].insert((vals[j] - vals[q]) & it); n         } n       } n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dp[2010][2010][2][2]; n int a[2010]; n pair<int, int> le[2010], ri[2010]; n int ll[2010][2], rr[2010][2]; n int h; n double p, q; n double go(int l, int r, int Li, int Ri) { n   if (l > r) return 0; n   if (dp[l][r][Li][Ri] > -1) { n     return dp[l][r][Li][Ri]; n   } n   int L = ll[l][Li], R = rr[r][Ri]; n   double res = 0; n   int d; n   if (L < le[l].second) { n     d = h; n   } else { n     d = a[l] - L; n   } n   res += 0.5 * p * (d + go(l + 1, r, 0, Ri)); n   if (R > ri[r].second) { n     d = h; n   } else { n     d = R - a[r]; n   } n   res += 0.5 * q * (d + go(l, r - 1, Li, 1)); n   if (ri[l].second > R) { n     d = R - a[l]; n   } else { n     d = ri[l].second - a[l]; n   } n   res += 0.5 * q * (d + go(ri[l].first + 1, r, 1, Ri)); n   if (le[r].second < L) { n     d = a[r] - L; n   } else { n     d = a[r] - le[r].second; n   } n   res += 0.5 * p * (d + go(l, le[r].first - 1, Li, 0)); n   return dp[l][r][Li][Ri] = res; n } n int main() { n   int n; n   scanf( %d%d%lf , &n, &h, &p); n   q = 1 - p; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   sort(a, a + n); n   for (int i = 0; i < n; i++) { n     le[i] = make_pair(0, a[0] - h); n     ri[i] = make_pair(i, a[i] + h); n   } n   for (int i = n - 2; i >= 0; i--) { n     if (a[i] + h > a[i + 1]) { n       ri[i] = ri[i + 1]; n     } else { n       ri[i] = make_pair(i, a[i] + h); n     } n   } n   for (int i = 1; i < n; i++) { n     if (a[i] - h < a[i - 1]) { n       le[i] = le[i - 1]; n     } else { n       le[i] = make_pair(i, a[i] - h); n     } n   } n   ll[0][0] = ll[0][1] = -1001001001; n   for (int i = 1; i < n; i++) { n     ll[i][0] = a[i - 1]; n     ll[i][1] = ri[i - 1].second; n   } n   rr[n - 1][0] = rr[n - 1][1] = 1001001001; n   for (int i = n - 2; i >= 0; i--) { n     rr[i][1] = a[i + 1]; n     rr[i][0] = le[i + 1].second; n   } n   for (int i = 0; i < 2010; i++) { n     for (int j = 0; j < 2010; j++) { n       for (int k = 0; k < 2; k++) { n         for (int l = 0; l < 2; l++) { n           dp[i][j][k][l] = -1; n         } n       } n     } n   } n   printf( %.12f n , go(0, n - 1, 0, 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> vis; n vector<pair<long long, long long>> v; n void dfs(long long x, long long y) { n   pair<long long, long long> p = v[x]; n   vis[x] = 1; n   if (x == y) return; n   for (long long i = 0; i < v.size(); i++) { n     if (vis[i]) continue; n     if (p.first > v[i].first && p.first < v[i].second) { n       dfs(i, y); n     } else if (p.second > v[i].first && p.second < v[i].second) { n       dfs(i, y); n     } n   } n } n signed main() { n   ios::sync_with_stdio(0); n   long long n, m, b, c; n   while (cin >> n) { n     v.clear(); n     long long mp[105][105]; n     for (long long i = 0; i < n; i++) { n       cin >> m >> b >> c; n       if (m == 2) { n         vis.assign(100, 0); n         dfs(b - 1, c - 1); n         if (vis[c - 1]) { n           cout <<  YES n ; n         } else { n           cout <<  NO n ; n         } n       } n       if (m == 1) { n         v.push_back(make_pair(b, c)); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 10; n const int mod = 1e9 + 7; n int n, k, a[maxn], f[maxn], g[maxn]; n int fast_pow(int a, int b) { n   int ret = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) ret = 1ll * ret * a % mod; n   return ret; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= min(k + 2, n); i++) n     a[i] = (a[i - 1] + fast_pow(i, k)) % mod; n   if (n <= k + 2) { n     printf( %d n , a[n]); n     return 0; n   } n   int now, ans = 0; n   now = f[0] = g[0] = 1; n   for (int i = 1; i <= k + 2; i++) { n     now = 1ll * now * (n - i) % mod; n     f[i] = 1ll * f[i - 1] * i % mod; n     g[i] = 1ll * -g[i - 1] * i % mod; n   } n   for (int i = 1; i <= k + 2; i++) n     ans = (ans + 1ll * a[i] * now % mod * fast_pow(n - i, mod - 2) % mod * n                      fast_pow(1ll * f[i - 1] * g[k + 2 - i] % mod, mod - 2) % n                      mod) % n           mod; n   ans = (ans + mod) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long bigmod(long long a, long long p) { n   long long ret = 1; n   while (p > 0) { n     if ((p & 1)) ret = (ret * a) % 998244353LL; n     p >>= 1; n     a = (a * a) % 998244353LL; n   } n   return ret; n } n long long modinverse(long long a) { return bigmod(a, 998244353LL - 2); } n long long n, fre[300009], eng[300009], mat[300009]; n vector<int> graph[300009]; n void dfs(int u, int par) { n   fre[u] = eng[u] = mat[u] = 0; n   long long mul = 1, mul2 = 1; n   for (int i = 0; i < graph[u].size(); i++) { n     int v = graph[u][i]; n     if (v == par) continue; n     dfs(v, u); n     mul *= (fre[v] + eng[v]); n     mul2 *= (fre[v] + 2 * eng[v]); n     mul %= 998244353LL; n     mul2 %= 998244353LL; n   } n   fre[u] = mul; n   mat[u] = mul2; n   for (int i = 0; i < graph[u].size(); i++) { n     int v = graph[u][i]; n     if (v == par) continue; n     eng[u] += (modinverse((fre[v] + 2 * eng[v]) % 998244353LL) * mat[v]) % n               998244353LL; n   } n   eng[u] %= 998244353LL; n   eng[u] *= mul2; n   eng[u] %= 998244353LL; n } n int main() { n   scanf( %lld , &n); n   int u, v; n   for (int i = 1; i < n; i++) { n     scanf( %d %d , &u, &v); n     graph[u].push_back(v); n     graph[v].push_back(u); n   } n   dfs(1, -1); n   long long ans = (fre[1] + eng[1]) % 998244353LL; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> m >> n; n   char a[n][m]; n   int i, j, c; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   char b[m][n]; n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       b[i][j] = a[j][i]; n     } n   } n   for (i = 0; i < m; i++) { n     c = 2; n     while (c--) { n       for (j = 0; j < n; j++) { n         cout << b[i][j] << b[i][j]; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int cnt = 0, cur = 0; n   do { n     cur++; n   } while (cur * 5 < n); n   cnt = cur; n   cur = 0; n   do { n     cur++; n   } while (cur * 4 < n); n   cnt = max(cnt, cur); n   for (int i = 0; i < cnt; i++) cout << 5; n   cout << 1; n   cout << endl; n   for (int i = 0; i < cnt; i++) cout << 4; n   cout << 9; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 5, inf = 1e9 + 7; n int n, m, x, y, l, r, f[N]; n struct tt { n   int l, r; n } a[100]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &x, &y); n     l = max(1, x - y), r = min(m, x + y); n     a[i].l = l, a[i].r = r; n   } n   for (int i = 1; i <= m; i++) { n     f[i] = i; n     for (int j = 1; j <= n; j++) { n       if (a[j].l <= i && i <= a[j].r) n         f[i] = min(f[i], f[i - 1]); n       else if (a[j].r < i) n         f[i] = min(f[i], i - a[j].r + f[max(0, a[j].l - i + a[j].r - 1)]); n     } n   } n   printf( %d n , f[m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const int N = 300005; n vector<pair<int, int>> g[N]; n int pre[N], vis[N], sz[N]; n long long d[N]; n void dfs1(int u, int fa) { n   pre[u] = fa; n   for (auto [v, w] : g[u]) { n     if (v != fa) { n       d[v] = d[u] + w; n       dfs1(v, u); n     } n   } n } n long long dfs2(int u) { n   long long ret = 0; n   sz[u] = 1; n   for (auto [v, w] : g[u]) { n     if (!vis[v]) { n       vis[v] = true; n       ret = max(ret, dfs2(v) + w); n       sz[u] += sz[v]; n     } n   } n   return ret; n } n int main(int argc, char *argv[]) { n   std::ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n - 1; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     g[u].emplace_back(v, w); n     g[v].emplace_back(u, w); n   } n   dfs1(1, 0); n   vector<int> path; n   for (int i = n; i; i = pre[i]) path.push_back(i), vis[i] = 1; n   reverse(path.begin(), path.end()); n   long long mx = -inf, now = dfs2(path[0]), now2 = -inf; n   for (int i = 1; i < path.size(); i++) { n     long long x = dfs2(path[i]); n     if (sz[path[i]] > 2) x = inf; n     if (now == 0 && x == 0) { n       if (i > 1) { n         mx = max(mx, now2 + x - (d[path[i]] - d[path[i - 1]])); n       } n     } else { n       mx = max(mx, now + x - (d[path[i]] - d[path[i - 1]])); n     } n     now = now - (d[path[i]] - d[path[i - 1]]); n     now2 = now; n     now = max(now, x); n   } n   while (m--) { n     long long x; n     cin >> x; n     if (x + mx >= 0) n       cout << d[n] << endl; n     else n       cout << d[n] + x + mx << endl; n   } n   return 0; n } n


//doing a 800 difficulty question using dynammic programming n #include<bits/stdc++.h> n #define ll long long n using namespace std; n int main(){ n     int t; n     cin>>t; n     while(t--){ n         ll n,m,k; n         cin>>n>>m>>k; n         ll dp[n][m]; n         for(ll i=0;i<n;i++){ n             for(ll j=0;j<m;j++){ n                 if(i==0){ n                     dp[i][j]=j; n                 } n                 if(i!=0){ n                     dp[i][j]=dp[i-1][j]+(j+1); n                 }}} n                 if(dp[n-1][m-1]==k){ n                     cout<< YES <<  n ; n                 } n                 else{ n                     cout<< NO <<  n ; n                 } n         }}


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> c; n vector<bool> used; n vector<vector<int> > e; n vector<vector<int> > ices; n int colors = 1; n int cur = 1; n int used_colors[1000000]; n void dfs(int v) { n   if (used[v]) return; n   used[v] = 1; n   if (ices[v].size() > colors) { n     colors = ices[v].size(); n   } n   cur++; n   for (int j = 0; j < ices[v].size(); j++) { n     int t = ices[v][j]; n     if (c[t]) { n       used_colors[c[t]] = cur; n     } n   } n   int cur_unused = 1; n   for (int j = 0; j < ices[v].size(); j++) { n     int t = ices[v][j]; n     if (!c[t]) { n       while (used_colors[cur_unused] == cur) cur_unused++; n       c[t] = cur_unused++; n     } n   } n   for (int i = 0; i < e[v].size(); i++) { n     dfs(e[v][i]); n   } n } n int main() { n   for (int i = 0; i < 1e6; i++) { n     used_colors[i] = 0; n   } n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   c.resize(m + 1); n   e.resize(n); n   used.assign(n, 0); n   ices.resize(n); n   int cnt; n   for (int i = 0; i < n; i++) { n     cin >> cnt; n     if (cnt == 0) continue; n     ices[i].resize(cnt); n     for (int j = 0; j < cnt; j++) { n       cin >> ices[i][j]; n     } n   } n   for (int i = 0; i < n - 1; i++) { n     int v, u; n     cin >> v >> u; n     v--, u--; n     e[v].push_back(u); n     e[u].push_back(v); n   } n   dfs(0); n   cout << colors <<   n ; n   for (int i = 0; i < m; i++) { n     cout << max(1, c[i + 1]) <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n namespace my_std { n using namespace std; n inline int read() { n   char c = getchar(); n   int ans = 0, f = 1; n   while (c >  9  || c <  0 ) { n     f ^= (c ==  - ); n     c = getchar(); n   } n   for (; c <=  9  && c >=  0 ; c = getchar()) n     ans = (ans << 1) + (ans << 3) + (c ^ 48); n   return f ? ans : -ans; n } n const int mod = 1e9 + 7, N = 5010; n inline void inc(int &x, const int &y) { n   x += y; n   if (x >= mod) x -= mod; n } n inline int ksm(int x, long long y) { n   int res = 1; n   for (; y; y >>= 1, x = 1ll * x * x % mod) n     if (y & 1) res = 1ll * res * x % mod; n   return res; n } n inline int gcd(int x, int y) { n   if (x > y) swap(y, x); n   return y ? gcd(y, x % y) : x; n } n }  // namespace my_std n using namespace my_std; n vector<int> e[N << 1]; n int n, m, d, lv[N], ans[N], wt[N << 1], vis[N << 1]; n struct People_CF1139E { n   int pot, cl, lf; n } st[N]; n inline bool find(int u) { n   register int v; n   for (register int i = (0); i <= (int(e[u].size()) - 1); ++i) { n     v = e[u][i]; n     if (vis[v]) continue; n     vis[v] = 1; n     if (wt[v] == -1 || find(wt[v])) { n       wt[v] = u; n       return 1; n     } n   } n   return 0; n } n int main() { n   n = read(), m = read(); n   for (register int i = (1); i <= (n); ++i) st[i].pot = read(); n   for (register int i = (1); i <= (n); ++i) st[i].cl = read(); n   d = read(); n   for (register int i = (1); i <= (d); ++i) lv[i] = read(), st[lv[i]].lf = 1; n   for (register int i = (1); i <= (n); ++i) { n     if (!st[i].lf && st[i].pot <= m) { n       e[st[i].pot].push_back(st[i].cl + m); n       e[st[i].cl + m].push_back(st[i].pot); n     } n   } n   memset(wt, -1, sizeof(wt)); n   for (register int i = (d); i >= (1); --i) { n     for (register int j = (ans[i + 1]); j <= (m); ++j) { n       memset(vis, 0, sizeof(vis)); n       if (!find(j)) { n         ans[i] = j; n         break; n       } n     } n     if (st[lv[i]].pot > m) continue; n     e[st[lv[i]].pot].push_back(st[lv[i]].cl + m); n     e[st[lv[i]].cl + m].push_back(st[lv[i]].pot); n   } n   for (register int i = (1); i <= (d); ++i) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   int l, r, id, rng; n   bool operator<(const query &tmp) const { n     return rng != tmp.rng ? rng < tmp.rng : r < tmp.r; n   } n } Q[100100]; n int n, q, a[100100], b[100100], c[100100], cnt[100100], ans[100100]; n int D; n vector<int> v; n void add(int x) { c[cnt[x]++]--, c[cnt[x]]++; } n void del(int x) { c[cnt[x]--]--, c[cnt[x]]++; } n int calc() { n   int rlt = 0; n   for (int i = 1; i <= D; i++) b[i] = c[i]; n   priority_queue<int> pq; n   for (int i = 0; i < v.size(); i++) n     if (cnt[v[i]] > D) pq.push(-cnt[v[i]]); n   for (int i = 1, j = 2; i <= D; i++) { n     rlt += b[i] / 2 * (2 * i); n     if (i * 2 <= D) n       b[i * 2] += b[i] / 2; n     else { n       for (int k = 1; k <= b[i] / 2; k++) pq.push(-i * 2); n     } n     if (b[i] & 1) { n       if (j <= i) j = i + 1; n       while (j <= D && !b[j]) j++; n       if (j > D) { n         pq.push(-i); n         break; n       } n       rlt += i + j; n       b[j]--; n       if (i + j <= D) n         b[i + j]++; n       else n         pq.push(-(i + j)); n     } n   } n   while (!pq.empty()) { n     int x = pq.top(); n     pq.pop(); n     if (pq.empty()) break; n     int y = pq.top(); n     pq.pop(); n     rlt -= x + y; n     pq.push(x + y); n   } n   return rlt; n } n int main() { n   scanf( %d , &n); n   D = 2 * sqrt(n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), cnt[a[i]]++; n   for (int i = 1; i <= 100000; i++) { n     if (cnt[i] > D) v.push_back(i); n     cnt[i] = 0; n   } n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) n     scanf( %d %d , &Q[i].l, &Q[i].r), Q[i].id = i, Q[i].rng = Q[i].l / D; n   sort(Q + 1, Q + q + 1); n   int l = 1, r = 0; n   for (int i = 1; i <= q; i++) { n     while (r < Q[i].r) add(a[++r]); n     while (l < Q[i].l) del(a[l++]); n     while (r > Q[i].r) del(a[r--]); n     while (l > Q[i].l) add(a[--l]); n     ans[Q[i].id] = calc(); n   } n   for (int i = 1; i <= q; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Graph { n   struct Edge { n     int u, v; n     int cost; n     Edge(int _u, int _v, int _cost) : u(_u), v(_v), cost(_cost) {} n   }; n   int n, m; n   bool is_digraph; n   vector<vector<int>> g; n   vector<Edge> e; n   Graph(int _n) : n(_n), m(0) { n     assert(n >= 1); n     g.resize(n); n     set_di(false); n   } n   Graph(int _n, int _m, bool _di = false) : n(_n) { n     assert(n >= 1); n     g.resize(n); n     e.reserve(_m); n     m = 0; n     set_di(_di); n     input(_m); n   } n   void set_di(bool _di) { n     pos = vector<int>(n, 0); n     deg = vector<int>(n, 0); n     is_digraph = _di; n   } n   vector<int> deg; n   inline void add(int u, int v, int cost = 1) { n     assert(0 <= u && u < n); n     assert(0 <= v && v < n); n     if (is_digraph) { n       g[u].emplace_back(m); n     } else { n       deg[u]++; n       deg[v]++; n       g[u].emplace_back(m); n       g[v].emplace_back(m); n     } n     e.emplace_back(u, v, cost); n     m++; n   } n   void input(int _m) { n     int u, v; n     for (int i = 0; i < _m; i++) { n       cin >> u >> v; n       u--; n       v--; n       add(u, v); n     } n   } n   vector<int> pos; n   void dfs(int u) { n     for (; pos[u] < g[u].size(); pos[u]++) { n       int i = g[u][pos[u]]; n       int v = e[i].u ^ e[i].v ^ u; n       dfs(v); n     } n   } n   int k; n   void dele() { n     int need_del = m - (n + m + 1) / 2; n     if (need_del > 0) { n       int cnt = 0; n       random_shuffle(e.begin(), e.end()); n       vector<int> d = deg; n       for (auto& x : e) { n         if (cnt < need_del && d[x.u] - 1 >= (deg[x.u] + 1) / 2 && n             d[x.v] - 1 >= (deg[x.v] + 1) / 2) { n           d[x.u]--; n           d[x.v]--; n           x.cost = 0; n           cnt++; n         } n       } n       assert(cnt == need_del); n       k = (n + m + 1) / 2; n     } else { n       k = m; n     } n   } n   void pri() { n     cout << k <<   n ; n     for (auto& x : e) { n       if (x.cost) cout << x.u + 1 <<     << x.v + 1 <<   n ; n     } n   } n }; n void solve() { n   int n, m; n   cin >> n >> m; n   Graph g(n, m); n   g.dele(); n   g.pri(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   cout << endl; n } n


#include<bits/stdc++.h> n using namespace std; n #define N 1500009 n #define INF 5e8 n #define mymin(x,y) (x>=y?y:x) n #define mymax(x,y) (x>=y?x:y) n typedef long long int LL; n map<LL, int> mp[3]; n int a[4][N]; n struct din{ n     int ap, id; n }dn[4][N]; n bool cmp(din af, din bf){ n     return af.ap < bf.ap; n } n int main() { n  std::ios::sync_with_stdio(0); std::cin.tie(0); n     int n[4]; n     for(int i = 0; i < 4; i++) cin >> n[i]; n     for(int i = 0; i < 4; i++){ n         for(int j = 0; j < n[i]; j++){ n             cin >> dn[i][j].ap; n             dn[i][j].id = j + 1; n         } n     } n     for(int i = 0; i < 3; i++){ n         int m; cin >> m; n         for(int j = 0; j < m; j++){ n             int x, y; cin >> x >> y; n             mp[i][1ll * x * N + y] = 1; n         } n     } n     for(int i = 2; i >= 0; i--){ n         // cout << i <<     << n[i] << endl; n         // cout << dn[3][0].id <<     << mp[2][0 * N + 1] << endl; n         sort(dn[i + 1], dn[i + 1] + n[i + 1], cmp); n         for(int j = 0; j < n[i]; j++){ n             int ind = 0; n             while(ind < n[i + 1] && mp[i][1ll * (j + 1) * N + dn[i + 1][ind].id]) ind++; n             if(ind == n[i + 1]) dn[i][j].ap = INF; n             else dn[i][j].ap += dn[i + 1][ind].ap; n             // cout << dn[i][j].ap <<    ; n         } n         // cout << endl; n     } n     sort(dn[0], dn[0] + n[0], cmp); n     if(dn[0][0].ap >= INF) cout << -1 << endl; n     else cout << dn[0][0].ap << endl; n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int di[] = {-1, -1, -1, 0, 1, 1, 1, 0, 0}, n           dj[] = {-1, 0, 1, 1, 1, 0, -1, -1, 0}; n int st[20][20][20] = {}; n bool fr[20][20][20 * 20] = {}; n int n; n void file_open() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n void xuli() { n   queue<int> q1, q2, q3; n   q1.push(7); n   q2.push(0); n   q3.push(0); n   while (!q1.empty()) { n     int u = q1.front(), v = q2.front(), k = q3.front() + 1, tK = k; n     if (k > 9) k = 9; n     q1.pop(); n     q2.pop(); n     q3.pop(); n     for (int i = 0; i < 9; ++i) { n       int d = u + di[i], e = v + dj[i]; n       if (d >= 0 && d < 8 && e >= 0 && e < 8) { n         if (st[d][e][k] == 0 && st[d][e][k - 1] == 0 && !fr[d][e][tK]) { n           fr[d][e][tK] = 1; n           q1.push(d); n           q2.push(e); n           q3.push(tK); n           if (d == 0 && e == 7) { n             printf( WIN ); n             return; n           } n         } n       } n     } n   } n   printf( LOSE ); n } n int main() { n   char c[20][20] = {}; n   for (int i = 0; i < 8; ++i) { n     for (int j = 0; j < 8; ++j) { n       scanf( %c , &c[i][j]); n       if (c[i][j] ==  S ) { n         int u = 0; n         while (u + i < 8) { n           st[i + u][j][u] = 1; n           ++u; n         } n       } n     } n     scanf(  n ); n   } n   xuli(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr1[100][10000], arr[10000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t, i, j, k, n, m, x, y, z, a, b, mx; n   cin >> t; n   while (t--) { n     cin >> n; n     for (i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     for (i = 1; i < 27; i++) { n       x = 0; n       for (j = 0; j < n; j++) { n         if (arr[j] == i) { n           x++; n           arr1[i][j] = x; n         } else { n           arr1[i][j] = x; n         } n       } n     } n     mx = 1; n     for (i = 0; i < n; i++) { n       for (j = i + 1; j < n; j++) { n         if (arr[j] == arr[i] && n             (arr1[arr[i]][i]) == (arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1)) { n           x = arr1[arr[i]][i] + arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1; n           for (k = 1; k <= 26; k++) { n             y = arr1[k][j - 1] - arr1[k][i]; n             z = x + y; n             mx = max(z, mx); n           } n         } n       } n     } n     cout << mx << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1001][10], cnt, ans[1001]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3], &a[i][4]); n   } n   if (n > 11) { n     printf( 0 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     bool flg = 0; n     for (int j = 1; j <= n; j++) n       if (i != j) n         for (int k = j + 1; k <= n; k++) n           if (k != i) { n             int mx = 0; n             double mmx = 0, mmy = 0; n             for (int p = 0; p < 5; p++) { n               mx += (a[i][p] - a[j][p]) * (a[i][p] - a[k][p]); n               mmx += (a[i][p] - a[j][p]) * (a[i][p] - a[j][p]); n               mmy += (a[i][p] - a[k][p]) * (a[i][p] - a[k][p]); n             } n             mmx = sqrt(mmx); n             mmy = sqrt(mmy); n             if (acos((double)mx / (mmx * mmy)) * 2 <= acos(-1) - 1e-8) flg = 1; n           } n     if (!flg) ans[++cnt] = i; n   } n   printf( %d n , cnt); n   for (int i = 1; i <= cnt; i++) printf( %d n , ans[i]); n } n


#include <bits/stdc++.h> n long long int mod = 1000000000 + 7; n long long int inf = 1000000000000000000; n using namespace std; n int main() { n   iostream::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int ans = 1, a; n     cin >> a; n     for (int i = 0; i < 31; i++) { n       if ((a >> i) & 1) ans *= 2; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5002, NP = 1e9; n int Add[MAXN], MyResult[MAXN], MyCheck[MAXN]; n bool check(int n, vector<pair<int, pair<int, pair<int, int> > > > A) { n   for (int i = 0; i < A.size(); i++) { n     int t = A[i].first, s = A[i].second.first, e = A[i].second.second.first, n         v = A[i].second.second.second; n     if (t == 1) { n       for (int i = s - 1; i <= e - 1; i++) { n         MyCheck[i] += v; n       } n     } else { n       int mx = MyCheck[s - 1]; n       for (int i = s - 1; i <= e - 1; i++) mx = max(mx, MyCheck[i]); n       if (mx != v) return 0; n     } n   } n   return 1; n } n int main() { n   int t, n, m, s, e, v; n   vector<pair<int, pair<int, pair<int, int> > > > A; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i] = NP; n   while (m--) { n     scanf( %d%d%d%d , &t, &s, &e, &v); n     A.push_back(make_pair(t, make_pair(s, make_pair(e, v)))); n     if (t == 1) { n       for (int i = s - 1; i <= e - 1; i++) Add[i] += v; n     } else { n       for (int i = s - 1; i <= e - 1; i++) n         MyResult[i] = min(MyResult[i], v - Add[i]); n     } n   } n   for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i]; n   if (check(n, A)) { n     printf( YES n ); n     for (int i = 0; i < n; i++) { n       if (i) printf(   ); n       printf( %d , MyResult[i]); n     } n     printf(  n ); n   } else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   for (; t; t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     vector<int> gist(3); n     for (int i = 0; i < n; i++) gist[a[i] % 3]++; n     while (gist[1] > 0 && gist[2] > 0) { n       gist[1]--; n       gist[2]--; n       gist[0]++; n     } n     while (gist[1] - 3 >= 0) { n       gist[1] -= 3; n       gist[0]++; n     } n     while (gist[2] - 3 >= 0) { n       gist[2] -= 3; n       gist[0]++; n     } n     cout << gist[0] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2 * acos(0.0); n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); n const string DIGITS =  0123456789 ; n const string ALPH =  abcdefghijklmnopqrstuvwxyz ; n template <class T0, class T1> n inline ostream &operator<<(ostream &out, pair<T0, T1> &a) { n   return out <<  {  << a.first <<  ,   << a.second <<  } ; n } n template <class T0, class T1, class T2> n inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) { n   return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a) n              <<  } ; n } n template <class T0, class T1, class T2, class T3> n inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) { n   return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a) n              <<  ,   << get<3>(a) <<  } ; n } n template <class T> n inline ostream &operator<<(ostream &out, vector<T> &a) { n   out <<  [ ; n   for (int i = 0; i < (int)(a.size()); ++i) n     out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()]; n   return out; n } n void smain(); n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << setprecision(10) << fixed; n   smain(); n   return 0; n } n const int N = 510; n int n, m; n vector<string> t; n vector<vector<int> > glav[4]; n void kek(char p, int u) { n   vector<vector<int> > a(n, vector<int>(m)); n   auto b = a, c = a; n   for (int i = 0; i < n; i++) { n     int u = 0; n     string s = t[i]; n     for (int j = 0; j < m; j++) { n       if (s[j] == p) { n         a[i][j] = 1; n         u++; n       } else { n         a[i][j] = 0; n         u = 0; n       } n       b[i][j] = u; n     } n   } n   for (int i = 0; i < m; i++) { n     int u = 0; n     for (int j = n - 1; j >= 0; j--) { n       if (a[j][i] == 1) n         u++; n       else n         u = 0; n       c[j][i] = u; n     } n   } n   vector<vector<int> > ans(n, vector<int>(m)); n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] == 0) continue; n       if (j == 0 || i == n - 1) { n         ans[i][j] = 1; n       } else { n         int v = min(b[i][j], c[i][j]); n         ans[i][j] = min(ans[i + 1][j - 1] + 1, v); n       } n     } n   } n   glav[u] = ans; n } n int flex[N][N]; n int lol[N][N][251]; n int get(int r, int c, int k) { n   if (r < 0 || c < 0) return 0; n   return lol[r][c][k]; n } n int get(int r1, int c1, int r2, int c2, int k) { n   return get(r2, c2, k) - get(r1 - 1, c2, k) - get(r2, c1 - 1, k) + n          get(r1 - 1, c1 - 1, k); n } n void smain() { n   int q; n   cin >> n >> m >> q; n   string s; n   for (int i = 0; i < n; i++) { n     cin >> s; n     t.push_back(s); n   } n   kek( G , 0); n   kek( R , 1); n   kek( B , 2); n   kek( Y , 3); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int k = 1;; k++) { n         if (i + k >= n || j - k < 0) break; n         if (glav[0][i][j] >= k && glav[1][i][j - k] >= k && n             glav[2][i + k][j] >= k && glav[3][i + k][j - k] >= k) { n           flex[i][j] = k; n         } n       } n     } n   } n   for (int k = 1; k <= 250; k++) { n     for (int i = 0; i < n; i++) { n       int prev = 0; n       for (int j = 0; j < m; j++) { n         prev += (flex[i][j] == k); n         if (i) { n           lol[i][j][k] += lol[i - 1][j][k]; n         } n         lol[i][j][k] += prev; n       } n     } n   } n   while (q--) { n     int r1, c1, r2, c2; n     cin >> r1 >> c1 >> r2 >> c2; n     r1--; n     c1--; n     r2--; n     c2--; n     swap(c1, c2); n     int l = 0, r = 251; n     while (l + 1 < r) { n       int mid = l + r >> 1; n       int r3 = r2 - mid * 2 + 1; n       int c3 = c2 + mid * 2 - 1; n       bool flag = true; n       if (r3 < r1 || c3 > c1) flag = false; n       if (flag) { n         if (get(r1, c3, r3, c1, mid) == 0) flag = false; n       } n       if (flag) n         l = mid; n       else n         r = mid; n     } n     cout << 1LL * l * 2 * l * 2 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n long long mod = 1000000007LL; n long long mod2 = 998244353LL; n int n; n bool mat[2005][2005]; n int cntr[2005], cntc[2005]; n int cnt[2005]; n int main() { n   cin >> n; n   memset(mat, false, sizeof(mat)); n   memset(cntr, 0, sizeof(cntr)); n   memset(cntc, 0, sizeof(cntc)); n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i <= n; ++i) { n     string s; n     cin >> s; n     for (int j = 1; j <= n; ++j) { n       mat[i][j] = (s[j - 1] ==  1 ); n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = n; j >= i; --j) { n       if (j == i) continue; n       bool x = ((cntr[i] + cntc[j]) % 2 > 0); n       if (mat[i][j] != x) { n         ans++; n         cntr[i]++; n         cntc[j]++; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     cnt[i] += cntr[i] + cntc[i]; n   } n   memset(cntr, 0, sizeof(cntr)); n   memset(cntc, 0, sizeof(cntc)); n   for (int i = n; i >= 1; --i) { n     for (int j = 1; j <= i; ++j) { n       if (j == i) continue; n       bool x = ((cntr[i] + cntc[j]) % 2 > 0); n       if (mat[i][j] != x) { n         ans++; n         cntr[i]++; n         cntc[j]++; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     cnt[i] += cntr[i] + cntc[i]; n   } n   for (int i = 1; i <= n; ++i) { n     bool x = (cnt[i] % 2 > 0); n     if (mat[i][i] != x) { n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void _DBG(const char *s, _T x) { n   cerr << s <<   =   << x <<   n ; n } n template <typename _T, typename... args> n void _DBG(const char *s, _T x, args... a) { n   while (*s !=  , ) cerr << *s++; n   cerr <<   =   << x <<  , ; n   _DBG(s + 1, a...); n } n const int N = 1e5 + 7; n vector<int> G[N]; n int dist[N]; n bool vis[N]; n void dfs(int v, int d) { n   vis[v] = true; n   dist[v] = d; n   for (auto &u : G[v]) { n     if (!vis[u]) { n       dfs(u, d + 1); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   int root = -1; n   for (int i = 1; i <= n; i++) { n     if ((int)(G[i]).size() == 1) { n       root = i; n       break; n     } n   } n   dfs(root, 0); n   int parity = dist[root] % 2; n   bool good = true; n   for (int i = 2; i <= n; i++) { n     if ((int)(G[i]).size() == 1 && dist[i] % 2 != parity) { n       good = false; n     } n   } n   if (good) { n     cout << 1 <<    ; n   } else { n     cout << 3 <<    ; n   } n   int edges = n - 1; n   int leaves = 0; n   set<int> leaf_parents; n   for (int i = 1; i <= n; i++) { n     if ((int)(G[i]).size() == 1) { n       leaves++; n     } else { n       for (auto &u : G[i]) { n         if ((int)(G[u]).size() == 1) { n           leaf_parents.insert(i); n         } n       } n     } n   } n   cout << edges - leaves + (int)(leaf_parents).size() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int N, Q; n int a[300005]; n int p[300005]; n int oop[1100005]; n int ui, uv; n void update(int n, int nl, int nr) { n   if (nl == ui && ui + 1 == nr) { n     oop[n] = uv; n   } else { n     int mid = (nl + nr) / 2; n     if (ui < mid) n       update(n * 2 + 1, nl, mid); n     else n       update(n * 2 + 2, mid, nr); n     oop[n] = oop[n * 2 + 1] + oop[n * 2 + 2]; n   } n } n int ql, qr; n int query(int n, int nl, int nr) { n   if (qr <= nl || nr <= ql) n     return 0; n   else if (ql <= nl && nr <= qr) n     return oop[n]; n   else { n     int mid = (nl + nr) / 2; n     return query(n * 2 + 1, nl, mid) + query(n * 2 + 2, mid, nr); n   } n } n int main() { n   scanf( %d , &N); n   a[0] = p[0] = 0; n   for (int i = 1; i <= N; i++) { n     scanf( %d , &a[i]); n     p[a[i]] = i; n   } n   a[N + 1] = p[N + 1] = N + 1; n   for (int i = 1; i < N; i++) { n     ui = i; n     uv = p[i] > p[i + 1]; n     update(0, 0, N + 2); n   } n   scanf( %d , &Q); n   for (int i = 0; i < Q; i++) { n     int t, x, y; n     scanf( %d%d%d , &t, &x, &y); n     if (t == 1) { n       ql = x, qr = y; n       printf( %d n , query(0, 0, N + 2) + 1); n     } else { n       std::swap(a[x], a[y]); n       p[a[x]] = x; n       p[a[y]] = y; n       ui = a[x] - 1; n       uv = p[a[x] - 1] > p[a[x]]; n       update(0, 0, N + 2); n       ui = a[x]; n       uv = p[a[x]] > p[a[x] + 1]; n       update(0, 0, N + 2); n       ui = a[y] - 1; n       uv = p[a[y] - 1] > p[a[y]]; n       update(0, 0, N + 2); n       ui = a[y]; n       uv = p[a[y]] > p[a[y] + 1]; n       update(0, 0, N + 2); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n constexpr int MAXN = 5 + 50; n constexpr ll INF = 1000000000000000002LL; n namespace dsu { n int f[MAXN], sz[MAXN]; n void build(int n) { n   fill(sz, sz + n, 1); n   for (int i = (int)0; i < (int)n; ++i) f[i] = i; n } n int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } n bool join(int x, int y) { n   if ((x = find(x)) == (y = find(y))) return false; n   if (sz[x] < sz[y]) swap(x, y); n   sz[x] += sz[y]; n   f[y] = x; n   return true; n } n bool connected(int i, int j) { return find(i) == find(j); } n }  // namespace dsu n ll memo[MAXN], f[MAXN]; n int res[MAXN]; n bitset<MAXN> used; n ll add(ll a, ll b) { n   if (a + b >= INF) return INF; n   return a + b; n } n ll mul(ll a, ll b) { n   long double ans = (long double)(a) * (long double)(b); n   if (ans >= INF) return INF; n   return a * b; n } n ll dp(int len) { n   ll& ans = memo[len]; n   if (~ans) { n     assert(ans >= 0); n     return ans; n   } n   if (len == 0) return ans = 1; n   ans = 0; n   for (int i = 1; i <= len; ++i) n     ans = add(ans, mul(dp(len - i), f[max(0, i - 2)])); n   return ans; n } n void rebuild(int len, ll k, int pos, int n) { n   if (len == 0) { n     assert(pos == n); n     return; n   } n   ll ans = 0; n   for (int i = 1; i <= len; ++i) { n     ll ol = ans; n     ans = add(ans, mul(dp(len - i), f[max(0, i - 2)])); n     if (k <= ans) { n       k -= ol; n       ll j = k / dp(len - i); n       while (mul(j, dp(len - i)) < k) ++j; n       k -= mul(j - 1, dp(len - i)); n       res[pos] = i + pos; n       dsu::build(MAXN); n       used.reset(); n       for (int posin = 2; posin <= i; ++posin) { n         int put = -1; n         ll ac = 0, olac; n         for (int num = 1; num < i; ++num) { n           if (dsu::connected(num, posin) || used[num]) continue; n           olac = ac; n           ac = add(ac, f[max(0, i - posin - 1)]); n           if (j <= ac) { n             put = num; n             break; n           } n         } n         assert(put != -1); n         res[pos + posin - 1] = put + pos; n         used[put] = true; n         dsu::join(put, posin); n         j -= olac; n       } n       rebuild(len - i, k, i + pos, n); n       return; n     } n   } n   assert(false); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   f[0] = 1; n   for (int i = (int)1; i < (int)MAXN; ++i) { n     if (f[i - 1] == INF) { n       f[i] = f[i - 1]; n     } else { n       f[i] = min(INF, 1LL * i * f[i - 1]); n     } n   } n   memset(memo, -1, sizeof memo); n   int tc; n   cin >> tc; n   while (tc--) { n     int n; n     ll k; n     cin >> n >> k; n     if (k <= dp(n)) { n       rebuild(n, k, 0, n); n       for (int i = (int)0; i < (int)n; ++i) cout << res[i] <<    ; n     } else { n       cout << -1; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n vector<int> a[100005]; n int dp[100005], n, t; n int main() { n   for (int i = 2; i <= 100000; i++) n     for (int j = 1; j * i <= 100000; j++) a[i * j].push_back(i); n   while (cin >> n) { n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i < n; i++) { n       cin >> t; n       int mx = 0; n       for (int j = 0; j < a[t].size(); j++) { n         mx = max(mx, dp[a[t][j]]); n       } n       for (int j = 0; j < a[t].size(); j++) { n         dp[a[t][j]] = mx + 1; n       } n     } n     cout << max(1, *max_element(dp, dp + 100001)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2, k1, k2; n   cin >> n1 >> n2 >> k1 >> k2; n   if (n1 <= n2) n     cout <<  Second ; n   else n     cout <<  First ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, sum, cnt[10]; n bool check; n void ghi() { n   bool check = false; n   for (int i = 9; i > -1; i--) { n     if (cnt[i] == 0) continue; n     if (i != 0) check = true; n     if (!i && !check) cnt[i] = 1; n     for (int j = 1; j <= cnt[i]; j++) printf( %d , i); n   } n   printf(  n ); n } n int main() { n   if (0) { n     freopen( a.inp ,  r , stdin); n   }; n   scanf( %d , &n); n   int x; n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     cnt[x]++; n     sum += x; n     if (x == 0) check = true; n   } n   if (!check) { n     printf( -1 n ); n     return 0; n   } n   if (sum % 3 == 1) { n     for (int i = 0; i < 10; i++) { n       if (i % 3 != 1 || cnt[i] == 0) continue; n       cnt[i]--; n       ghi(); n       return 0; n     } n     for (int i = 0; i < 10; i++) { n       if (i % 3 != 2 || cnt[i] == 0) continue; n       cnt[i]--; n       for (int j = i; j < 10; j++) { n         if (j % 3 != 2 || cnt[j] == 0) continue; n         cnt[j]--; n         ghi(); n         return 0; n       } n     } n   } else if (sum % 3 == 2) { n     for (int i = 0; i < 10; i++) { n       if (i % 3 != 2 || cnt[i] == 0) continue; n       cnt[i]--; n       ghi(); n       return 0; n     } n     for (int i = 0; i < 10; i++) { n       if (i % 3 != 1 || cnt[i] == 0) continue; n       cnt[i]--; n       for (int j = i; j < 10; j++) { n         if (j % 3 != 1 || cnt[j] == 0) continue; n         cnt[j]--; n         ghi(); n         return 0; n       } n     } n   } else n     ghi(); n } n


#include <bits/stdc++.h> n using namespace std; n int nA, nB, m, k, ans, x, y, c1, c2, cnt; n int deg[1310 << 1], be[190010], w[1310], w2[1310]; n int id[10005][1310], f[10005][1310]; n void rv(int x, int c1, int c2) { n   swap(f[x][c1], f[x][c2]); n   swap(id[x][c1], id[x][c2]); n   be[id[x][c2]] = c2; n   if (f[x][c2]) rv(f[x][c2], c2, c1); n } n int main() { n   scanf( %d%d%d , &nA, &m, &k); n   nB = nA; n   int foo; n   for (int i = 1; i <= nA; i++) scanf( %d , &foo); n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d , &x, &y); n     if (x < y) swap(x, y); n     if (deg[x] % k == 0) w[x] = ++cnt; n     if (deg[nA + y] % k == 0) w2[y] = ++cnt; n     deg[x]++, deg[nA + y]++; n     x = w[x], y = w2[y]; n     c1 = 0, c2 = 0; n     for (int j = 1; j <= k; ++j) n       if (!f[x][j]) { n         c1 = j; n         break; n       } n     for (int j = 1; j <= k; ++j) n       if (!f[y][j]) { n         c2 = j; n         break; n       } n     if (f[y][c1]) rv(y, c1, c2); n     f[x][c1] = y; n     id[x][c1] = i; n     f[y][c1] = x; n     id[y][c1] = i; n     be[i] = c1; n   } n   for (int i = 1; i <= m; ++i) printf( %d  , be[i]); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100100; n int N, M; n int app[MAXN]; n char type[MAXN]; n int P[MAXN]; n bool check(int leader) { n   set<int> users; n   users.insert(leader); n   for (int i = 0; i < M; i++) { n     if (type[i] ==  + ) n       users.insert(P[i]); n     else n       users.erase(P[i]); n     if (!users.empty() && users.find(leader) == users.end()) return false; n   } n   return true; n } n int main() { n   cin >> N >> M; n   for (int i = 0; i < M; i++) cin >> type[i] >> P[i]; n   int offp = 0; n   for (int i = 0; i < M; i++) { n     if (type[i] ==  -  && !app[P[i]]) offp = P[i]; n     app[P[i]] = true; n   } n   if (offp != 0) { n     if (check(offp)) app[offp] = false; n   } else { n     if (check(P[0])) app[P[0]] = false; n   } n   int total = 0; n   for (int i = 1; i <= N; i++) total += !app[i]; n   cout << total <<   n ; n   for (int i = 1; i <= N; i++) n     if (!app[i]) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n typedef long long ll; n  n const int N = 1e6 + 9; n  n int main () { n     int t; n     cin >> t; n     while (t--) { n         ll n, last; n         cin >> n; n         for (ll i = 0; i < 33; i++) { n             if (n & (1ll << i)) n                 last = i; n         } n         cout << ((1ll << last) - 1ll) <<   n ; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int total, n; n   cin >> total >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   int ans = 0; n   for (int i = 0; i < n - 1; i++) { n     ans += (total - v[i]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v; n   int total, num, i, koita = 0; n   scanf( %d , &total); n   for (i = 0; i < total; i++) { n     scanf( %d , &num); n     v.push_back(num); n   } n   int maximum = v[0]; n   int minimum = v[0]; n   for (i = 1; i < total; i++) { n     num = v[i]; n     if (num > maximum) { n       maximum = num; n       koita++; n     } n     if (num < minimum) { n       minimum = num; n       koita++; n     } n   } n   printf( %d n , koita); 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], b[n], c = 0, x = 0, y = 0, z = 0, s = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) { n       x++; n     } n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n     if (a[i] != b[i]) { n       c = 1; n     } n     if (b[i] == 1) { n       y++; n     } n   } n   for (int i = 0; i < n; i++) { n     if (a[i] == 1 && b[i] == 0) { n       z++; n     } n   } n   if (c == 0 || x == 0 || z == 0) { n     cout <<  -1  << endl; n   } else { n     for (int i = 1;;) { n       if (s > y) { n         cout << i - 1 << endl; n         break; n       } else { n         s = z * i + (x - z); n         i++; n       } n     } 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 nega = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) nega = -1; n     ch = getchar(); n   } n   long long ans = 0; n   while (isdigit(ch)) { n     ans = ans * 10 + ch - 48; n     ch = getchar(); n   } n   if (nega == -1) return -ans; n   return ans; n } n inline long long min(long long x, long long y, long long z) { n   return min(x, min(y, z)); n } n inline long long max(long long x, long long y, long long z) { n   return max(x, max(y, z)); n } n inline long long add(long long x, long long y) { n   return x + y >= 998244353 ? x + y - 998244353 : x + y; n } n inline long long add(long long x, long long y, long long z) { n   return add(add(x, y), z); n } n inline long long sub(long long x, long long y) { n   return x - y < 0 ? x - y + 998244353 : x - y; n } n inline long long mul(long long x, long long y) { n   return 1LL * x * y % 998244353; n } n inline long long mul(long long x, long long y, long long z) { n   return mul(mul(x, y), z); n } n vector<long long> a, b; n vector<char> ans; n long long n; n void solve1() { n   if (a[0] == b[0]) n     cout <<  SMALL n0 n ; n   else n     cout <<  IMPOSSIBLE n ; n } n bool rsame(vector<long long> x, vector<long long> y) { n   reverse(x.begin(), x.end()); n   return x == y; n } n void fail() { cout <<  IMPOSSIBLE n , exit(0); } n bool push_back(char s) { n   if ((long long)ans.size() <= 200000) { n     ans.push_back(s); n     return 1; n   } n   return 0; n } n void solve2() { n   long long tot = 0, sum = 0; n   while (a != b && !rsame(a, b)) { n     if (b[0] > b[1]) swap(b[0], b[1]), tot++, push_back( R ); n     if (a[0] > a[1] && b[0] == a[1]) { n       if (b[0] == 0) fail(); n       if (b[1] < a[0]) fail(); n       long long ned = b[1] - a[0]; n       if (ned % b[0] != 0) fail(); n       sum += ned / b[0], tot += ned / b[0] + 1; n       if (sum <= 200000) { n         for (long long i = 1; i <= ned / b[0]; i++) push_back( P ); n         push_back( R ); n       } n       if (sum <= 200000) { n         cout <<  SMALL n ; n         reverse(ans.begin(), ans.end()); n         cout << (long long)ans.size() << endl; n         for (auto i : ans) putchar(i); n       } else { n         cout <<  BIG n ; n         cout << sum << endl; n       } n       exit(0); n     } n     if (b[0] == a[0]) { n       if (b[0] == 0) fail(); n       if (b[1] < a[1]) fail(); n       long long ned = b[1] - a[1]; n       if (ned % b[0] != 0) fail(); n       sum += ned / b[0], tot += ned / b[0] + 1; n       if (sum <= 200000) { n         for (long long i = 1; i <= ned / b[0]; i++) push_back( P ); n         push_back( R ); n       } n       if (sum <= 200000) { n         cout <<  SMALL n ; n         reverse(ans.begin(), ans.end()); n         cout << (long long)ans.size() << endl; n         for (auto i : ans) putchar(i); n       } else { n         cout <<  BIG n ; n         cout << sum << endl; n       } n       exit(0); n     } n     if (b[0] == 0) fail(); n     tot += b[1] / b[0]; n     sum += b[1] / b[0]; n     if (sum <= 200000) { n       for (long long i = 1; i <= b[1] / b[0]; i++) push_back( P ); n     } n     b[1] %= b[0]; n   } n   if (a != b) swap(b[0], b[1]), tot++, push_back( R ); n   if (sum <= 200000) { n     cout <<  SMALL n ; n     reverse(ans.begin(), ans.end()); n     cout << (long long)ans.size() << endl; n     for (auto i : ans) putchar(i); n   } else { n     cout <<  BIG n ; n     cout << sum << endl; n   } n   exit(0); n } n bool inc(vector<long long> x) { n   for (long long i = 1; i < n; i++) { n     if (x[i] < x[i - 1]) return 0; n   } n   return 1; n } n bool dec(vector<long long> x) { n   for (long long i = 1; i < n; i++) { n     if (x[i] > x[i - 1]) return 0; n   } n   return 1; n } n bool alz(vector<long long> x) { n   for (long long i = 0; i < n - 1; i++) n     if (x[i] != 0) return 0; n   return 1; n } n void print(vector<long long> x) { n   for (long long i : x) printf( %lld  , i); n   cout <<   n ; n } n void solve3() { n   long long tot = 0, sum = 0; n   while (a != b && !rsame(a, b)) { n     if (alz(b)) fail(); n     if (dec(b)) reverse(b.begin(), b.end()), tot++, push_back( R ); n     if (!inc(b)) fail(); n     sum++; n     tot++; n     push_back( P ); n     for (long long i = n - 1; i > 0; i--) b[i] -= b[i - 1]; n   } n   if (a != b) reverse(b.begin(), b.end()), tot++, push_back( R ); n   if (sum <= 200000) { n     cout <<  SMALL n ; n     cout << ans.size() << endl; n     reverse(ans.begin(), ans.end()); n     for (auto i : ans) putchar(i); n   } else { n     cout <<  BIG n ; n     cout << sum << endl; n   } n } n signed main() { n   cin >> n; n   a.resize(n), b.resize(n); n   for (long long i = 0; i < n; i++) a[i] = read(); n   for (long long i = 0; i < n; i++) b[i] = read(); n   if (n >= 3) n     solve3(); n   else if (n == 2) n     solve2(); n   else n     solve1(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 9; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long s[maxn]; n int f[maxn], F[maxn], p[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &s[i]); n   } n   for (int i = 2; i <= n; ++i) { n     scanf( %d , &p[i]); n   } n   for (int i = n; i > 1; --i) { n     s[p[i]] += s[i]; n   } n   for (int i = n; i; --i) { n     long long t = s[1] / gcd(s[1], s[i]); n     if (t <= n) { n       ++f[t]; n     } n   } n   for (int i = n; i; --i) { n     for (int j = i; (j += i) <= n;) { n       f[j] += f[i]; n     } n   } n   int ans = 0; n   F[1] = 1; n   for (int i = 1; i <= n; ++i) { n     if (f[i] == i) { n       ans += F[i]; n       for (int j = i * 2; j <= n; j += i) { n         F[j] += F[i]; n       } n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, n, m; n int fa[200010], an[200010]; n vector<int> a[200010]; n pair<int, int> f[200010]; n inline void P(int &x, int y) { x = 1ll * x * y % 1000000007; } n inline void merge(pair<int, int> &a, pair<int, int> b) { n   P(a.first, b.first); n   int g = (2ll * b.first + b.second) % 1000000007; n   P(a.second, g); n } n inline void gao(pair<int, int> &a) { n   a.second = (a.second - a.first) % 1000000007; n } n inline void ch(pair<int, int> &a, pair<int, int> b) { n   a.first = 1ll * a.first * b.first % 1000000007; n   a.second = 1ll * a.second * b.second % 1000000007; n } n void dfs(int x) { n   f[x] = make_pair(1, 1); n   for (auto i : a[x]) { n     if (fa[x] == i) continue; n     fa[i] = x; n     dfs(i); n     merge(f[x], f[i]); n   } n   gao(f[x]); n } n void huan(int x) { n   an[x] = (f[x].first + f[x].second) % 1000000007; n   int t = 0, i, len = a[x].size() + 5; n   vector<pair<int, int> > g(len), f1(len), f2(len); n   for (auto i : a[x]) g[++t] = f[i]; n   f1[0] = make_pair(1, 1); n   for (i = 1; i <= t; i++) f1[i] = f1[i - 1], merge(f1[i], g[i]); n   f2[t + 1] = make_pair(1, 1); n   for (i = t; i; i--) f2[i] = f2[i + 1], merge(f2[i], g[i]); n   int _ = 0; n   for (auto i : a[x]) { n     _++; n     if (fa[x] == i) continue; n     pair<int, int> v = f1[_ - 1]; n     ch(v, f2[_ + 1]); n     gao(v); n     swap(f[x], v); n     pair<int, int> tmp = f[i]; n     f[i].second = (f[i].second + f[i].first) % 1000000007; n     merge(f[i], f[x]); n     gao(f[i]); n     huan(i); n     swap(f[x], v); n     f[i] = tmp; n   } n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n - 1; i++) { n     int x; n     scanf( %d , &x); n     a[x].push_back(i + 1); n     a[i + 1].push_back(x); n   } n   dfs(1); n   huan(1); n   for (i = 1; i <= n; i++) printf( %d  , (an[i] + 1000000007) % 1000000007); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int ans[200005]; n void query(int nl, int nr) { n   if (nl > nr) return; n   printf( ? %d %d n , nl, nr); n   fflush(stdout); n   int x, f; n   scanf( %d%d , &x, &f); n   if (nr - f + 1 <= nl + f - 1) { n     for (int i = nr - f + 1; i <= nl + f - 1; i++) ans[i] = x; n     query(nl, nr - f); n     query(nl + f, nr); n   } else { n     query(nl, ((nl + nr) >> 1)); n     query(((nl + nr) >> 1) + 1, nr); n   } n } n int main() { n   scanf( %d , &n); n   query(1, n); n   printf( ! %d , ans[1]); n   for (int i = 2; i <= n; i++) printf(  %d , ans[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   for (int i = 0; i < n - 1; i++) { n     if (s[i] == s[i + 1]) { n       if (i + 2 < n) { n         if (s[i + 1] ==  z  && s[i + 2] !=  a ) n           s[i + 1] =  a ; n         else if (s[i + 1] ==  z  && s[i + 2] ==  a ) n           s[i + 1] =  b ; n         else if (s[i + 1] !=  z  && s[i + 2] !=  z ) n           s[i + 1] =  z ; n         else { n           if (s[i + 1] ==  y ) n             s[i + 1] =  x ; n           else n             s[i + 1] =  y ; n         } n       } else { n         if (s[i + 1] ==  z ) n           s[i + 1] =  a ; n         else n           s[i + 1] =  z ; n       } n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& cout, vector<T> V) { n   cout <<  [  ; n   for (auto v : V) cout << v <<    ; n   return cout <<  ] ; n } n template <class L, class R> n ostream& operator<<(ostream& cout, pair<L, R> P) { n   return cout <<  (  << P.first <<  ,  << P.second <<  ) ; n } n long long int n; n vector<long long int> a, b, c; n vector<vector<long long int>> conn; n vector<long long int> c0, c1; n long long int ans = 0; n void dfs1(long long int node, long long int par, long long int val) { n   a[node] = min(a[node], val); n   for (long long int i : conn[node]) { n     if (i == par) continue; n     dfs1(i, node, a[node]); n   } n } n void dfs2(long long int node, long long int par) { n   for (long long int i : conn[node]) { n     if (i == par) continue; n     dfs2(i, node); n     c0[node] += c0[i]; n     c1[node] += c1[i]; n   } n   if (b[node] == 0 && c[node] == 1) { n     c0[node]++; n   } n   if (b[node] == 1 && c[node] == 0) { n     c1[node]++; n   } n } n long long int dfs3(long long int node, long long int par) { n   long long int ct0 = 0, ct1 = 0; n   if (b[node] == 0 && c[node] == 1) ct0 = 1; n   if (b[node] == 1 && c[node] == 0) ct1 = 1; n   for (long long int i : conn[node]) { n     if (i == par) continue; n     long long int temp = dfs3(i, node); n     if (temp > 0) { n       ct0 += temp; n     } else { n       ct1 -= temp; n     } n   } n   long long int m = min(ct0, ct1); n   ans += a[node] * m; n   ct0 -= m; n   ct1 -= m; n   if (ct0) return ct0; n   return -ct1; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   a.resize(n); n   b.resize(n); n   c.resize(n); n   conn.resize(n); n   for (long long int i = 0; i < (n); i++) cin >> a[i] >> b[i] >> c[i]; n   for (long long int i = 0; i < (n - 1); i++) { n     long long int x; n     cin >> x; n     long long int y; n     cin >> y; n     x--, y--; n     conn[x].push_back(y); n     conn[y].push_back(x); n   } n   dfs1(0, -1, (long long int)1e18); n   c0.resize(n); n   c1.resize(n); n   dfs2(0, -1); n   if (dfs3(0, -1)) { n     cout << -1 <<   n ; n   } else { n     cout << 2 * ans <<   n ; n   } n   cerr <<  Time :   << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC n        <<  ms n ; n   ; n } n


#include <bits/stdc++.h> n long long n, md; n void rid(int n, int m) { n   int i; n   long long sol = 1, p = 1; n   for (i = 0, p = n; i <= 30; i++) { n     if ((m & (1 << i)) == (1 << i)) { n       sol = (long long)sol * p; n       sol = (long long)sol % md; n     } n     p = (long long)p * p; n     p = (long long)p % md; n   } n   if (sol == 0) n     sol = md - 1; n   else n     sol--; n   printf( %I64d , sol); n } n int main() { n   scanf( %I64d%I64d , &n, &md); n   rid(3, n); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[11], mx, n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   printf( %d , *max_element(a + 1, a + n + 1) ^ a[n]); n   return 0; n } n