#include <bits/stdc++.h> n using namespace std; n int main() { n   char c; n   int n, b = 0, a = 0; n   cin >> n; n   while (n > 0) { n     cin >> c; n     if (c ==  A ) n       a++; n     else n       b++; n     n--; n   } n   if (a > b) n     cout <<  Anton ; n   else if (a < b) n     cout <<  Danik ; n   else n     cout <<  Friendship ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 5e5 + 10; n int a[N]; n int dp[2][N]; n int minv[N]; n int sum[N]; n int n, k, p; n class BIT { n   int a[110]; n  n  public: n   void init() { memset((a), (0x1f), sizeof(a)); } n   inline int lowbit(int x) { return x & -x; } n   void add(int x, int v) { n     x = p - x; n     while (x < 110) { n       a[x] = min(a[x], v); n       x += lowbit(x); n     } n   } n   int sum(int x) { n     int ret = INF; n     while (x) { n       ret = min(ret, a[x]); n       x -= lowbit(x); n     } n     return ret; n   } n } b; n template <class T> n inline void readint(T &ret) { n   char c; n   ret = 0; n   while ((c = getchar()) <  0  || c >  9 ) n     ; n   while (c >=  0  && c <=  9 ) { n     ret = ret * 10 + (c -  0 ), c = getchar(); n   } n } n int main() { n   readint(n); n   readint(k); n   readint(p); n   int o = 0; n   for (int i = 1; i <= n; i++) { n     readint(a[i]); n     a[i] %= p; n     sum[i] = sum[i - 1] + a[i]; n     dp[o][i] = (a[i] + dp[o][i - 1]) % p; n   } n   for (int i = 2; i <= k; i++) { n     o ^= 1; n     b.init(); n     memset((dp[o]), (0x1f), sizeof(dp[o])); n     b.add(0, sum[i - 1]); n     int tot = 0; n     for (int j = i; j <= n; j++) { n       tot = (tot + a[j]); n       if (tot >= p) tot -= p; n       dp[o][j] = min(b.sum(tot) - p, b.sum(p)) + tot; n       int t = (p - tot); n       if (t == p) t = 0; n       b.add(t, dp[o ^ 1][j] + t); n     } n   } n   printf( %d n , dp[o][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, s[444], dp[444][55][444]; n int main() { n   cin >> n >> k; n   s[0] = 0; n   for (int i = 1; i <= n; i++) cin >> s[i], s[i] += s[i - 1]; n   int ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 2; j <= min(i, k); j++) n       for (int l = 1; l <= i - j + 1; l++) n         for (int h = 1; h <= i - l - j + 2; h++) n           dp[i][j][l] = n               max(dp[i][j][l], dp[i - l][j - 1][h] + n                                    abs(s[i] + s[i - l - h] - 2 * s[i - l])); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= i - k + 1; j++) ans = max(ans, dp[i][k][j]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> m; n int main() { n   int n; n   cin >> n; n   string h; n   cin >> h; n   m[h]++; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     string a =   , b =   ; n     for (int i = 0; i < 3; i++) a += s[i]; n     for (int i = 5; i < 8; i++) b += s[i]; n     m[a]++; n     m[b]++; n   } n   cout << (m[h] % 2 ?  home  :  contest ) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(int hr, int min) { n   if (hr % 10 == 7 || hr / 10 == 7 || min % 10 == 7) { n     return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int x, hr, min, res = 0; n   cin >> x >> hr >> min; n   while (!check(hr, min)) { n     min -= x; n     if (min < 0) { n       min += 60; n       hr--; n     } n     if (hr < 0) { n       hr += 24; n     } n     res++; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long k, n, i, j, m; n unsigned long long v[105][105]; n vector<unsigned long long> l; n int main() { n   cin >> n >> m; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       cin >> v[i][j]; n       k = max(k, v[i][j]); n     } n   k++; n   if (n == 1) { n     cout <<  YES n ; n     cout << k <<   n ; n     cout << 0 <<   n ; n     for (i = 1; i <= m; i++) cout << v[1][i] <<    ; n     cout <<   n ; n     return 0; n   } n   if (m == 1) { n     cout <<  YES n ; n     cout << k <<   n ; n     for (i = 1; i <= n; i++) cout << v[i][1] <<    ; n     cout <<   n ; n     cout << 0 <<   n ; n     return 0; n   } n   unsigned long long a = v[1][1] + v[2][2]; n   unsigned long long b = v[1][2] + v[2][1]; n   unsigned long long j = max(a, b) - min(a, b); n   if (j == 0) j = k; n   if (k > j) { n     cout <<  NO n ; n     return 0; n   } n   k = j; n   unsigned long long x = 0; n   l.push_back(x); n   for (i = 2; i <= n; i++) { n     if (v[i][1] < v[i - 1][1]) n       x = (x + k - v[i - 1][1] + v[i][1]) % k; n     else n       x = (x + v[i][1] - v[i - 1][1]) % k; n     l.push_back(x); n   } n   for (i = 0; i < l.size(); i++) { n     for (j = 1; j <= m; j++) { n       if ((l[i] + v[1][j]) % k != v[i + 1][j]) { n         cout <<  NO n ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   cout << k <<   n ; n   for (i = 0; i < l.size(); i++) cout << l[i] <<    ; n   cout <<   n ; n   for (i = 1; i <= m; i++) cout << v[1][i] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (n > m) swap(n, m); n   cout << n + 1 << endl; n   for (m = 0; n >= 0; m++, n--) cout << n <<     << m << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void print(vector<T> v) { n   cerr <<  [ ; n   if (v.size()) cerr << v[0]; n   for (int i = (1); i < (v.size()); ++i) cerr <<  ,   << v[i]; n   cerr <<  ] n ; n } n template <class T> n string i2s(T x) { n   ostringstream o; n   o << x; n   return o.str(); n } n vector<string> splt(string s, char c =    ) { n   vector<string> all; n   int p = 0, np; n   while (np = s.find(c, p), np >= 0) { n     if (np != p) all.push_back(s.substr(p, np - p)); n     p = np + 1; n   } n   if (p < s.size()) all.push_back(s.substr(p)); n   return all; n } n int h, w; n int data[1700][1700]; n int edge[1700][1700]; n int dr[] = {-1, 1, 0, 0, -1, -1, 1, 1}; n int dc[] = {0, 0, -1, 1, -1, 1, -1, 1}; n int main() { n   cin >> h >> w; n   for (int i = (0); i < (h); ++i) n     for (int j = (0); j < (w); ++j) scanf( %d , &data[i][j]); n   for (int r = (0); r < (h); ++r) n     for (int c = (0); c < (w); ++c) n       if (data[r][c]) { n         for (int d = (0); d < (4); ++d) { n           int nr = r + dr[d]; n           int nc = c + dc[d]; n           if (nr < 0 || nr >= h || nc < 0 || nc >= w || data[nr][nc] == 0) n             edge[r][c] = 1; n         } n       } n   vector<int> rays; n   for (int r = (0); r < (h); ++r) n     for (int c = (0); c < (w); ++c) n       if (edge[r][c]) { n         vector<pair<int, int> > v; n         int cr = r; n         int cc = c; n         while (edge[cr][cc]) { n           v.push_back(make_pair(cr, cc)); n           edge[cr][cc] = 0; n           for (int d = (0); d < (8); ++d) { n             int nr = cr + dr[d]; n             int nc = cc + dc[d]; n             if (nr >= 0 && nr < h && nc >= 0 && nc < w && edge[nr][nc]) { n               cr = nr; n               cc = nc; n               break; n             } n           } n         } n         int bv = -1; n         int bp = -1; n         for (int i = (0); i < (v.size()); ++i) n           for (int j = (15); j < (110); ++j) { n             int sx = v[i].first; n             int sy = v[i].second; n             int ex = v[(i + j) % v.size()].first; n             int ey = v[(i + j) % v.size()].second; n             if (abs(sx - ex) > 35 || abs(sy - ey) > 35) break; n             if (abs(sx - ex) <= 5 && abs(sy - ey) <= 5 && n                 abs(sx - ex) + abs(sy - ey) <= 7) { n               if (j > bv) { n                 bv = j; n                 bp = i; n               } n             } n           } n         int count = 0; n         for (int i = (0); i < (v.size()); ++i) n           for (int j = (15); j < (110); ++j) { n             int sx = v[(i + bp) % v.size()].first; n             int sy = v[(i + bp) % v.size()].second; n             int ex = v[(i + j + bp) % v.size()].first; n             int ey = v[(i + j + bp) % v.size()].second; n             if (i + j > v.size()) break; n             if (abs(sx - ex) > 35 || abs(sy - ey) > 35) break; n             if (abs(sx - ex) <= 5 && abs(sy - ey) <= 5 && n                 abs(sx - ex) + abs(sy - ey) <= 7) { n               count++; n               i += j; n               break; n             } n           } n         if (count) rays.push_back(count); n       } n   sort(rays.begin(), rays.end()); n   cout << rays.size() << endl; n   for (int i = (0); i < (rays.size()); ++i) cout << rays[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[500005]; n int A[500005][2]; n int B[500005]; n int C[500005]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   memset(A, 0, sizeof(A)); n   memset(B, 0, sizeof(B)); n   memset(C, 0, sizeof(C)); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     int len = strlen(s); n     if (s[0] ==  )  && s[len - 1] ==  ( ) continue; n     for (int j = 0; j < len; j++) { n       if (s[j] ==  ( ) n         A[i][0]++; n       else if (s[j] ==  )  && A[i][0] > 0) n         A[i][0]--; n       else n         A[i][1]--; n     } n     if (A[i][0] >= 0 && A[i][1] == 0) C[i] = A[i][0]; n     if (A[i][0] == 0 && A[i][1] <= 0) C[i] = A[i][1]; n     if (C[i] >= 0 && (A[i][0] == 0 || A[i][1] == 0)) B[C[i]]++; n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if (C[i] < 0) { n       int t = 0 - C[i]; n       if (B[t] > 0) { n         ans++; n         B[t]--; n       } n     } n   } n   ans += B[0] / 2; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, p, i; n struct reg { n   int x, y, z; n } v[100100]; n inline bool cmp1(reg a, reg b) { n   if (a.x != b.x) return a.x > b.x; n   return a.y > b.y; n } n inline bool cmp2(reg a, reg b) { return a.y < b.y; } n char s[5000]; n int main() { n   int n, sol = 0; n   cin >> n; n   cin >> (s + 1); n   for (i = n + 1; s[i]; i += n) n     if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) ++sol; n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a, b, mas[30], summ[100005]; n long long sum, countt; n string s; n map<pair<char, long long>, int> matr; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   for (int i = 0; i < 26; ++i) cin >> mas[i]; n   cin >> s; n   for (int i = 0; i < s.size(); ++i) { n     if (matr.count(make_pair(s[i], sum))) countt += matr[make_pair(s[i], sum)]; n     sum += mas[s[i] -  a ]; n     matr[make_pair(s[i], sum)]++; n   } n   cout << countt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF_INT = 2147483647; n const long long INF_LL = 9223372036854775807LL; n int gcd(int a, int b) { return ((b == 0) ? a : gcd(b, a % b)); } n int lcm(int a, int b) { return a * b / gcd(a, b); } n void solve() { n   int n; n   cin >> n; n   long long tmp = 1; n   while (n) { n     if (tmp % 3 == 0 || tmp % 10 == 3) { n       tmp++; n       continue; n     } n     tmp++; n     n--; n   } n   cout << tmp - 1 << endl; n } n int main() { n   ios::sync_with_stdio(); n   cin.tie(); n   ; n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n template <class T> n using V = vector<T>; n template <class T> n using VV = V<V<T>>; n constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } n template <class T, class U> n void chmin(T &t, const U &u) { n   if (t > u) t = u; n } n template <class T, class U> n void chmax(T &t, const U &u) { n   if (t < u) t = u; n } n template <class T, class U> n ostream &operator<<(ostream &os, const pair<T, U> &p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   for (int i = 0; i < (v.size()); i++) { n     if (i) os <<  , ; n     os << v[i]; n   } n   os <<  } ; n   return os; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int tc; n   cin >> tc; n   while (tc--) { n     int n, m; n     cin >> n >> m; n     V<int> ans; n     VV<int> g(n); n     for (int i = 0; i < (m); i++) { n       int a, b; n       cin >> a >> b; n       --a, --b; n       g[a].push_back(b); n     } n     VV<int> st(n, V<int>(3)); n     for (int i = 0; i < (n); i++) { n       int c; n       if (st[i][1]) { n         c = 2; n       } else if (st[i][0]) { n         c = 1; n       } else { n         c = 0; n       } n       if (c == 2) ans.push_back(i); n       for (int to : g[i]) { n         st[to][c] = 1; n       } n     } n     cout << ans.size() <<   n ; n     for (auto v : ans) cout << v + 1 <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = LLONG_MAX; n int main() { n   string s; n   cin >> s; n   int x = s.size(); n   cout << 26 * (x + 1) - x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, A, B; n double p[25]; n double a[625][625], l[625][625], u[625][625]; n vector<int> g[25]; n double y[625], x[625], b[625]; n int id[25][25]; n void edge(int ea, int b, int c, int d, double e) { n   if (ea < b) swap(ea, b); n   if (c < d) swap(c, d); n   a[id[ea][b]][id[c][d]] += e; n } n int main() { n   scanf( %d %d %d %d , &n, &m, &A, &B); n   A--, B--; n   if (A < B) swap(A, B); n   for (int i = 0; i < (int)(m); i++) { n     int ue, v; n     scanf( %d %d , &ue, &v); n     ue--, v--; n     g[ue].push_back(v); n     g[v].push_back(ue); n   } n   for (int i = 0; i < (int)(n); i++) scanf( %lf , &p[i]); n   int N = 0; n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(i + 1); j++) id[i][j] = ++N; n   for (int i = 0; i < (int)(N + 1); i++) n     for (int j = 0; j < (int)(N + 1); j++) a[i][j] = 0; n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(i + 1); j++) { n       if (i == j) { n         edge(i, j, i, j, 1); n         continue; n       } n       edge(i, j, i, j, p[i] * p[j]); n       for (int q = 0; q < (int)(g[i].size()); q++) { n         int qi = g[i][q]; n         edge(i, j, qi, j, (1 - p[i]) / g[i].size() * p[j]); n         for (int qq = 0; qq < (int)(g[j].size()); qq++) { n           int qj = g[j][qq]; n           edge(i, j, qi, qj, n                (1 - p[i]) / g[i].size() * (1 - p[j]) / g[j].size()); n         } n       } n       for (int qq = 0; qq < (int)(g[j].size()); qq++) { n         int qj = g[j][qq]; n         edge(i, j, i, qj, (1 - p[j]) / g[j].size() * p[i]); n       } n     } n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(i); j++) a[id[i][j]][id[i][j]] -= 1; n   for (int j = 1; j <= N; j++) u[1][j] = a[1][j]; n   for (int j = 2; j <= N; j++) l[j][1] = a[j][1] / u[1][1]; n   for (int i = 2; i <= N; i++) { n     for (int j = i; j <= N; j++) { n       u[i][j] = a[i][j]; n       for (int k = 1; k <= i - 1; k++) u[i][j] -= l[i][k] * u[k][j]; n     } n     for (int j = i + 1; j <= N; j++) { n       l[j][i] = a[j][i]; n       for (int k = 1; k <= i - 1; k++) l[j][i] -= l[j][k] * u[k][i]; n       l[j][i] /= u[i][i]; n     } n   } n   for (int i = 1; i <= N; i++) l[i][i] = 1.0; n   for (int d = 0; d < (int)(n); d++) { n     for (int i = 0; i < (int)(n); i++) n       for (int j = 0; j < (int)(i + 1); j++) n         if (i != j) { n           b[id[i][j]] = 0; n         } else n           b[id[i][j]] = i == d; n     for (int i = 1; i <= N; i++) { n       y[i] = b[i]; n       for (int j = 1; j < i; j++) y[i] -= l[i][j] * y[j]; n     } n     for (int i = N; i >= 1; i--) { n       x[i] = y[i]; n       for (int j = i + 1; j <= N; j++) x[i] -= u[i][j] * x[j]; n       x[i] /= u[i][i]; n     } n     if (d) printf(   ); n     printf( %.8f , x[id[A][B]]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Freopen() { n   freopen( n        title  n        .in , n        r , stdin); n   freopen( n        title  n        .out , n        w , stdout); n } n int read() { n   int g = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  ||  9  < ch) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while ( 0  <= ch && ch <=  9 ) { n     g = g * 10 + ch -  0 ; n     ch = getchar(); n   } n   return g * f; n } n const int N = 5e5 + 5; n const int mod = 1e9 + 7; n int st[N][20], dep[N], vis[N], ta, tb, top, sa[N], sb[N], sta[N]; n vector<int> G[N], F[N], R[N], C[N], size[N]; n int n, fir[N], las[N], fac[N], du[N]; n unordered_map<int, int> M[N]; n void dfs(int x, int fa) { n   st[x][0] = fa; n   dep[x] = dep[fa] + 1; n   for (int i = (1); i <= (19); i++) n     if (st[x][i - 1]) n       st[x][i] = st[st[x][i - 1]][i - 1]; n     else n       break; n   for (auto y : G[x]) n     if (y ^ fa) dfs(y, x); n } n int Lca(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   for (int i = (19); i >= (0); i--) n     if (dep[st[x][i]] >= dep[y]) x = st[x][i]; n   if (x == y) return x; n   for (int i = (19); i >= (0); i--) n     if (st[x][i] != st[y][i]) x = st[x][i], y = st[y][i]; n   return st[x][0]; n } n int get(int x, vector<int>& f) { return f[x] == x ? x : f[x] = get(f[x], f); } n bool Merge(int x, int y, vector<int>& f, vector<int>& size, vector<int>& ru, n            vector<int>& cu) { n   cu[x]++, ru[y]++; n   if (cu[x] > 1 || ru[y] > 1) return false; n   int fx = get(x, f), fy = get(y, f); n   if (fx == fy) return false; n   size[fx] += size[fy]; n   f[fy] = fx; n   return true; n } n signed main() { n   n = read(); n   memset(fir, -1, sizeof(fir)); n   memset(las, -1, sizeof(las)); n   if (n == 1) return cout << 1, signed(); n   fac[0] = 1; n   for (int i = (1); i <= (n); i++) fac[i] = 1ll * fac[i - 1] * i % mod; n   for (int i = (1); i <= (n - 1); i++) { n     int x = read(), y = read(); n     G[x].push_back(y), G[y].push_back(x); n     M[x][y] = G[x].size() - 1, M[y][x] = G[y].size() - 1; n     F[x].push_back(G[x].size() - 1), F[y].push_back(G[y].size() - 1); n     size[x].push_back(1), size[y].push_back(1); n     R[x].push_back(0), R[y].push_back(0); n     C[x].push_back(0), C[y].push_back(0); n     du[x]++, du[y]++; n   } n   dfs(1, 0); n   for (int x = (1); x <= (n); x++) { n     int y = read(); n     if (y == 0) continue; n     int anc = Lca(x, y); n     if (x == y) return cout << 0, signed(); n     if (vis[y]) return cout << 0, signed(); n     vis[y] = 1; n     ta = tb = top = 0; n     for (int t = x; t != anc; t = st[t][0]) sa[++ta] = t; n     for (int t = y; t != anc; t = st[t][0]) sb[++tb] = t; n     for (int i = (1); i <= (tb); i++) sta[++top] = sb[i]; n     sta[++top] = anc; n     for (int i = (ta); i >= (1); i--) sta[++top] = sa[i]; n     for (int i = (2); i <= (top - 1); i++) { n       int ipre = M[sta[i]][sta[i - 1]], isuf = M[sta[i]][sta[i + 1]]; n       if (!Merge(ipre, isuf, F[sta[i]], size[sta[i]], R[sta[i]], C[sta[i]])) n         return cout << 0, signed(); n     } n     fir[sta[1]] = M[sta[1]][sta[2]]; n     las[sta[top]] = M[sta[top]][sta[top - 1]]; n     for (int i = (1); i <= (top); i++) { n       if (fir[sta[i]] >= 0 && las[sta[i]] >= 0 && n           get(fir[sta[i]], F[sta[i]]) == get(las[sta[i]], F[sta[i]]) && n           size[sta[i]][get(fir[sta[i]], F[sta[i]])] != du[sta[i]]) n         return cout << 0, signed(); n     } n   } n   int ans = 1; n   for (int i = (1); i <= (n); i++) { n     for (int j = (0); j <= (du[i] - 1); j++) vis[j] = 0; n     int cnt = 0; n     for (int j = (0); j <= (du[i] - 1); j++) { n       int x = get(j, F[i]); n       if (vis[x]) continue; n       vis[x] = 1; n       cnt++; n     } n     if (fir[i] >= 0) cnt--; n     if (las[i] >= 0) cnt--; n     if (fir[i] >= 0 && las[i] >= 0 && get(fir[i], F[i]) == get(las[i], F[i])) n       cnt++; n     ans = 1ll * ans * fac[cnt] % mod; n   } n   return cout << ans, signed(); n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n template <typename T> n void printVec(const T &v, char sep =    ) { n   for (auto &i : v) cout << i << sep; n } n template <typename T> n void printVecPair(const T &v, char sep =    ) { n   for (auto &i : v) cout << i.first <<     << i.second << sep; n } n struct Points { n   int x1, y1, x2, y2, x3, y3; n }; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<string> g(n); n   for (int i = 0; i < n; i++) { n     cin >> g[i]; n   } n   vector<Points> ans; n   for (int i = 0; i < n - 1; i++) { n     for (int j = 0; j < m - 1; j++) { n       if (g[i][j] ==  1 ) { n         g[i][j] =  0 ; n         ans.push_back({i, j, i, j + 1, i + 1, j}); n         g[i][j + 1] = (g[i][j + 1] ==  1  ?  0  :  1 ); n         g[i + 1][j] = (g[i + 1][j] ==  1  ?  0  :  1 ); n       } n     } n   } n   for (int i = 0; i < n - 1; i += 2) { n     int cntOne = 0; n     cntOne += (g[i][m - 1] ==  1 ); n     cntOne += (g[i + 1][m - 1] ==  1 ); n     if (cntOne == 1) { n       if (g[i][m - 1] ==  1 ) { n         ans.push_back({i, m - 1, i, m - 2, i + 1, m - 2}); n         ans.push_back({i, m - 1, i + 1, m - 1, i + 1, m - 2}); n         ans.push_back({i, m - 1, i, m - 2, i + 1, m - 1}); n         for (int i = ans.size() - 3; i < ans.size(); i++) { n           g[ans[i].x1][ans[i].y1] = n               (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n           g[ans[i].x2][ans[i].y2] = n               (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n           g[ans[i].x3][ans[i].y3] = n               (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n         } n       } else { n         ans.push_back({i, m - 2, i, m - 1, i + 1, m - 1}); n         ans.push_back({i, m - 1, i + 1, m - 1, i + 1, m - 2}); n         ans.push_back({i, m - 2, i + 1, m - 1, i + 1, m - 2}); n         for (int i = ans.size() - 3; i < ans.size(); i++) { n           g[ans[i].x1][ans[i].y1] = n               (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n           g[ans[i].x2][ans[i].y2] = n               (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n           g[ans[i].x3][ans[i].y3] = n               (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n         } n       } n     } else if (cntOne == 2) { n       ans.push_back({i, m - 2, i + 1, m - 2, i + 1, m - 1}); n       ans.push_back({i, m - 2, i, m - 1, i + 1, m - 2}); n       for (int i = ans.size() - 2; i < ans.size(); i++) { n         g[ans[i].x1][ans[i].y1] = (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n         g[ans[i].x2][ans[i].y2] = (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n         g[ans[i].x3][ans[i].y3] = (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n       } n     } n   } n   for (int i = 0; i < m - 1; i += 2) { n     int cntOne = 0; n     cntOne += (g[n - 1][i] ==  1 ); n     cntOne += (g[n - 1][i + 1] ==  1 ); n     if (cntOne == 1) { n       if (g[n - 1][i] ==  1 ) { n         ans.push_back({n - 2, i, n - 1, i, n - 2, i + 1}); n         ans.push_back({n - 2, i, n - 1, i, n - 1, i + 1}); n         ans.push_back({n - 2, i + 1, n - 1, i + 1, n - 1, i}); n         for (int i = ans.size() - 3; i < ans.size(); i++) { n           g[ans[i].x1][ans[i].y1] = n               (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n           g[ans[i].x2][ans[i].y2] = n               (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n           g[ans[i].x3][ans[i].y3] = n               (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n         } n       } else { n         ans.push_back({n - 2, i, n - 2, i + 1, n - 1, i + 1}); n         ans.push_back({n - 2, i, n - 1, i, n - 1, i + 1}); n         ans.push_back({n - 2, i + 1, n - 1, i + 1, n - 1, i}); n         for (int i = ans.size() - 3; i < ans.size(); i++) { n           g[ans[i].x1][ans[i].y1] = n               (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n           g[ans[i].x2][ans[i].y2] = n               (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n           g[ans[i].x3][ans[i].y3] = n               (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n         } n       } n     } else if (cntOne == 2) { n       ans.push_back({n - 2, i, n - 2, i + 1, n - 1, i}); n       ans.push_back({n - 2, i, n - 2, i + 1, n - 1, i + 1}); n       for (int i = ans.size() - 2; i < ans.size(); i++) { n         g[ans[i].x1][ans[i].y1] = (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n         g[ans[i].x2][ans[i].y2] = (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n         g[ans[i].x3][ans[i].y3] = (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n       } n     } n   } n   if (g[n - 1][m - 1] ==  1 ) { n     ans.push_back({n - 2, m - 2, n - 2, m - 1, n - 1, m - 1}); n     ans.push_back({n - 2, m - 2, n - 1, m - 2, n - 1, m - 1}); n     ans.push_back({n - 2, m - 1, n - 1, m - 2, n - 1, m - 1}); n     for (int i = ans.size() - 3; i < ans.size(); i++) { n       g[ans[i].x1][ans[i].y1] = (g[ans[i].x1][ans[i].y1] ==  1  ?  0  :  1 ); n       g[ans[i].x2][ans[i].y2] = (g[ans[i].x2][ans[i].y2] ==  1  ?  0  :  1 ); n       g[ans[i].x3][ans[i].y3] = (g[ans[i].x3][ans[i].y3] ==  1  ?  0  :  1 ); n     } n   } n   cout << ans.size() << endl; n   for (auto p : ans) { n     cout << p.x1 + 1 <<     << p.y1 + 1 <<    ; n     cout << p.x2 + 1 <<     << p.y2 + 1 <<    ; n     cout << p.x3 + 1 <<     << p.y3 + 1 << endl; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000; n long long x[N], y[N]; n vector<int> ids[N]; n int order[N]; n long long cross(int a, int b, int c) { n   return x[c] * y[c] * (x[b] * y[a] - x[a] * y[b]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> x[i] >> y[i]; n   } n   iota(order, order + n, 0); n   sort(order, order + n, n        [&](int a, int b) { return x[a] == x[b] ? y[a] > y[b] : x[a] > x[b]; }); n   vector<int> hull; n   for (int i = 0, j = 0; i < n; i = j) { n     int a = order[i]; n     while (hull.size() >= 2) { n       int b = hull[hull.size() - 1], c = hull[hull.size() - 2]; n       if (cross(a, c, b) + cross(b, a, c) + cross(c, b, a) >= 0) { n         break; n       } n       hull.pop_back(); n     } n     hull.push_back(a); n     while (j < n && x[order[j]] == x[a] && y[order[j]] == y[a]) { n       ids[a].push_back(order[j++]); n     } n   } n   while (hull.size() >= 2) { n     int a = hull[hull.size() - 1], b = hull[hull.size() - 2]; n     if (y[b] < y[a]) { n       break; n     } n     hull.pop_back(); n   } n   vector<int> ans; n   for (auto i : hull) { n     ans.insert(ans.begin(), ids[i].begin(), ids[i].end()); n   } n   sort(ans.begin(), ans.end()); n   for (auto i : ans) { n     cout << i + 1 <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000005; n class fenwick { n   int n; n   vector<int> v; n  n  public: n   fenwick(int _n) : n(_n) { v.resize(n); } n   void update(int at, int by) { n     while (at < v.size()) { n       v[at] += by; n       at |= (at + 1); n     } n   } n   int query(int at) { n     int res = 0; n     while (at >= 0) { n       res += v[at]; n       at = (at & (at + 1)) - 1; n     } n     return res; n   } n }; n map<int, int> indexes; n int get_index(int x) { n   if (indexes.count(x) == 0) { n     int sz = indexes.size(); n     indexes[x] = sz; n   } n   return indexes[x]; n } n vector<int> f(vector<int> &v) { n   int n = v.size(); n   vector<int> cnt(maxn, 0); n   vector<int> ret; n   for (auto &x : v) { n     cnt[x]++; n     ret.push_back(cnt[x]); n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     v[i] = get_index(x); n   } n   auto left = f(v); n   reverse(v.begin(), v.end()); n   auto right = f(v); n   reverse(right.begin(), right.end()); n   fenwick ft = fenwick(maxn); n   for (int i = 0; i < n; ++i) { n     ft.update(right[i], 1); n   } n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     ft.update(right[i], -1); n     int cnt = ft.query(left[i] - 1); n     ans += cnt; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 998244353; n vector<long long int> prime; n long long int n = 1000001; n vector<bool> vis(n, true); n void sieve() { n   vis[0] = vis[1] = false; n   for (long long int i = 2; i * i <= n; i++) n     if (vis[i]) n       for (long long int j = i * i; j <= n; j += i) vis[j] = false; n   for (long long int i = 2; i <= n; i++) n     if (vis[i]) prime.push_back(i); n } n bool check(long long int n, long long int k) { n   if (n < 2 * k) return false; n   if (k == 1) return vis[n]; n   if (k == 2) { n     if (n % 2) return vis[n - 2]; n     return true; n   } n   return true; n } n int32_t main() { n   sieve(); n   long long int n; n   cin >> n; n   for (auto it = lower_bound(prime.begin(), prime.end(), n); it != prime.end(); n        it++) { n     if (*it > ((n * (n - 1)) >> 1)) break; n     if (!check((*it) << 1, n)) continue; n     long long int m = *it; n     cout << m << endl; n     m -= n; n     for (long long int i = 1; i <= n; i++) { n       long long int z = i + 1; n       if (z > n) z = 1; n       cout << i <<     << z << endl; n     } n     long long int diff = 2, init = (n >> 1) + (n & 1); n     while (m--) { n       cout << init <<     << init + diff << endl; n       diff += 2; n       init--; n     } n     return 0; n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MAXN = 1e5 + 3; n const int inf = 2e9; n int max(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int min(int a, int b) { n   if (a < b) n     return a; n   else n     return b; n } n bool cmp(pair<int, int> p1, pair<int, int> p2) { n   if (p1.first < p2.first) n     return true; n   else if (p1.first == p2.first) { n     if (p1.second < p2.second) return true; n     return false; n   } n   return false; n } n void solve() { n   int n, m, d; n   cin >> n >> m >> d; n   int a[n][m]; n   for (int i = (int)0; i < (int)n; ++i) { n     for (int j = (int)0; j < (int)m; ++j) { n       cin >> a[i][j]; n     } n   } n   int check = a[0][0] % d; n   vector<int> v; n   bool pr = false; n   for (int i = (int)0; i < (int)n; ++i) { n     for (int j = (int)0; j < (int)m; ++j) { n       if (a[i][j] % d == check) { n         v.push_back(a[i][j]); n       } else { n         pr = true; n         break; n       } n     } n   } n   if (pr) n     cout << -1 <<   n ; n   else { n     sort((v).begin(), (v).end()); n     int cc = (n * m); n     int bi = (cc / 2); n     int ans = 0; n     for (int i = (int)0; i < (int)cc; ++i) { n       ans += abs(v[i] - v[bi]); n     } n     cout << ans / d <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if ((a == 0) || (b == 0)) return a + b; n   return gcd(b, a % b); n } n long long pow_mod(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % 1000000007; n     a = (a * a) % 1000000007; n     b >>= 1; n   } n   return (res % 1000000007); n } n long long pow_2(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a); n     a = (a * a); n     b >>= 1; n   } n   return res; n } n bool isPrime(long long a) { n   for (int i = 3; (i * i) <= a; i += 2) { n     if ((a % i) == 0) return false; n   } n   if ((a != 2) && ((a % 2) == 0)) return false; n   if (a == 1) return false; n   return true; n } n string con_ll_to_str(int a) { n   stringstream mystr; n   mystr << a; n   return mystr.str(); n } n long long con_str_to_ll(string st) { n   long long numb = 0; n   int len = st.size(), i, j = 0; n   for (i = len - 1; i >= 0; i--) { n     numb += (pow_2(10, j) * (st[i] -  0 )); n     j++; n   } n   return numb; n } n long long baseno_to_decimal(string st, long long basee) { n   long long i = 0, j, anss = 0; n   for (j = (int)st.length() - 1; j >= 0; j--) { n     anss += (st[j] -  0 ) * pow_2(basee, i); n     i++; n   } n   return anss; n } n string decimal_to_string(long long num, long long basee) { n   long long i = 0, j, opop; n   string anss =   ; n   vector<string> stri; n   stri.push_back( 0 ); n   stri.push_back( 1 ); n   stri.push_back( 2 ); n   stri.push_back( 3 ); n   stri.push_back( 4 ); n   stri.push_back( 5 ); n   stri.push_back( 6 ); n   stri.push_back( 7 ); n   stri.push_back( 8 ); n   stri.push_back( 9 ); n   stri.push_back( A ); n   stri.push_back( B ); n   stri.push_back( C ); n   stri.push_back( D ); n   stri.push_back( E ); n   stri.push_back( F ); n   if (num == 0) { n     return  0 ; n   } n   while (num) { n     opop = num % basee; n     anss += stri[opop]; n     num /= basee; n   } n   reverse(anss.begin(), anss.end()); n   return anss; n } n const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}; n const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}; n long long arr[100010]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long T, N, K, i, j; n   string st =   ; n   cin >> N >> K; n   if (K > N) { n     cout <<  -1 ; n     return 0; n   } n   if (K == 1 && N > 1) { n     cout <<  -1 ; n     return 0; n   } n   if (N == 1) { n     cout <<  a ; n     return 0; n   } n   long long opop = (N - K + 2); n   for (i = 1; i <= opop; i++) { n     if (i % 2) { n       st.push_back( a ); n     } else { n       st.push_back( b ); n     } n   } n   long long po = st.length(), pu = 0; n   for (i = po + 1; i <= N; i++) { n     st.push_back( c  + pu); n     pu++; n   } n   cout << st; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double mas[10000][3]; n void optim(int cnt, double Px, double Py, double Pz, double vs, double vp) { n   double l = 0, r = 0; n   double x1 = mas[cnt][0]; n   double y1 = mas[cnt][1]; n   double z1 = mas[cnt][2]; n   double x2 = mas[cnt + 1][0]; n   double y2 = mas[cnt + 1][1]; n   double z2 = mas[cnt + 1][2]; n   for (int i = 0; i < cnt; i++) { n     l += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) + n               (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) + n               (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2])); n     r += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) + n               (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) + n               (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2])); n   } n   int j = cnt; n   r += sqrt((mas[j][0] - mas[j + 1][0]) * (mas[j][0] - mas[j + 1][0]) + n             (mas[j][1] - mas[j + 1][1]) * (mas[j][1] - mas[j + 1][1]) + n             (mas[j][2] - mas[j + 1][2]) * (mas[j][2] - mas[j + 1][2])); n   l /= vs; n   r /= vs; n   while (r - l > 1E-12) { n     double m = (r + l) / 2; n     double xx = (x1 + x2) / 2, yy = (y1 + y2) / 2, zz = (z1 + z2) / 2; n     double dist2 = sqrt((xx - Px) * (xx - Px) + (yy - Py) * (yy - Py) + n                         (zz - Pz) * (zz - Pz)); n     double t2 = dist2 / vp; n     if (t2 - m > 1E-10) { n       l = m; n       x1 = xx; n       y1 = yy; n       z1 = zz; n     } else if (t2 - m < -1E-10) { n       r = m; n       x2 = xx; n       y2 = yy; n       z2 = zz; n     } else { n       l = m; n       x1 = xx; n       y1 = yy; n       z1 = zz; n       break; n     } n   } n   printf( %.6lf n , l); n   printf( %.6lf %.6lf %.6lf n , x1, y1, z1); n } n int main() { n   int n; n   cin >> n; n   double vs, vp; n   for (int i = 0; i <= n; i++) cin >> mas[i][0] >> mas[i][1] >> mas[i][2]; n   cin >> vp >> vs; n   double Px, Py, Pz; n   cin >> Px >> Py >> Pz; n   bool f = false; n   int cnt = 0; n   double dist = 0; n   if (fabs(Px - mas[0][0]) < 1E-7 && fabs(Py - mas[0][1]) < 1E-7 && n       fabs(Pz - mas[0][2]) < 1E-7) { n     cout <<  YES  << endl; n     printf( %.6lf n , 0.0); n     printf( %.6lf %.6lf %.6lf n , Px, Py, Pz); n     return 0; n   } n   for (int i = 0; i < n; i++) { n     dist += sqrt((mas[i][0] - mas[i + 1][0]) * (mas[i][0] - mas[i + 1][0]) + n                  (mas[i][1] - mas[i + 1][1]) * (mas[i][1] - mas[i + 1][1]) + n                  (mas[i][2] - mas[i + 1][2]) * (mas[i][2] - mas[i + 1][2])); n     double dist2 = sqrt((mas[i + 1][0] - Px) * (mas[i + 1][0] - Px) + n                         (mas[i + 1][1] - Py) * (mas[i + 1][1] - Py) + n                         (mas[i + 1][2] - Pz) * (mas[i + 1][2] - Pz)); n     double t1 = dist / vs; n     double t2 = dist2 / vp; n     if (t1 - t2 > -1E-14) { n       cnt = i; n       f = true; n       break; n     } n   } n   if (!f) { n     cout <<  NO ; n     return 0; n   } else n     cout <<  YES  << endl; n   optim(cnt, Px, Py, Pz, vs, vp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long MOD = 1e9 + 7; n struct { n   int val, lazy; n } tree[4 * 1000010]; n int bal(int p) { return tree[p].val + tree[p].lazy; } n void ins(int S, int val, int L = 1, int R = 1000000, int p = 1) { n   if (S < L || R < 1) return; n   if (1 <= L && R <= S) { n     tree[p].lazy += val; n     return; n   } n   tree[2 * p].lazy += tree[p].lazy; n   tree[2 * p + 1].lazy += tree[p].lazy; n   tree[p].lazy = 0; n   int M = (L + R) / 2; n   ins(S, val, L, M, 2 * p); n   ins(S, val, M + 1, R, 2 * p + 1); n   tree[p].val = max(bal(2 * p), bal(2 * p + 1)); n } n int query(int L = 1, int R = 1000000, int p = 1) { n   if (L == R) { n     return bal(p) > 0 ? L : -1; n   } n   int M = (L + R) / 2; n   tree[2 * p].lazy += tree[p].lazy; n   tree[2 * p + 1].lazy += tree[p].lazy; n   tree[p].val += tree[p].lazy; n   tree[p].lazy = 0; n   if (bal(2 * p + 1) > 0) return query(M + 1, R, 2 * p + 1); n   return query(L, M, 2 * p); n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   vector<int> a[2]; n   for (int i = 0; i < n; ++i) { n     int x; n     scanf( %d , &x); n     a[0].push_back(x); n     ins(x, 1); n   } n   for (int i = 0; i < m; ++i) { n     int x; n     scanf( %d , &x); n     a[1].push_back(x); n     ins(x, -1); n   } n   int q; n   scanf( %d , &q); n   while (q--) { n     int idx, i, x; n     scanf( %d%d%d , &idx, &i, &x); n     --i; n     --idx; n     if (idx == 0) { n       ins(a[idx][i], -1); n       ins(x, 1); n     } else { n       ins(a[idx][i], 1); n       ins(x, -1); n     } n     a[idx][i] = x; n     printf( %d n , query()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int main() { n   long long k; n   long long now = 9; n   long long last = 1; n   cin >> k; n   if (k <= 9) { n     cout << k; n     return 0; n   } n   long long finalk = k; n   long long pow = 1; n   for (int step = 1; step <= 15; step++) { n     long long tmplast = last - 1; n     if (k <= now) { n       long long this_num = tmplast + (k / step); n       bool OK = 1; n       long long tmpnum = this_num; n       for (int i = 1; i <= step; i++) { n         if (tmpnum % 10 != 9) OK = false; n         tmpnum /= 10; n       } n       if (OK) step++; n       if (k % step) this_num += 1; n       long long yiwei = (step - k % step); n       if (yiwei == step) yiwei = 0; n       for (int i = 1; i <= yiwei; i++) { n         this_num /= 10; n       } n       printf( %d n , this_num % 10); n       return 0; n     } n     k -= now; n     pow *= 10; n     now = 9 * pow; n     now *= (step + 1); n     last *= 10; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int m; n vector<vector<int>> row; n vector<vector<int>> col; n vector<string> g; n vector<vector<bool>> vis; n struct node { n   int d; n   int i; n   int j; n }; n struct NODE { n   vector<int> e; n   bool vis = false; n }; n vector<NODE> G; n bool operator<(const node a, const node b) { return a.d > b.d; } n int dijk() { n   priority_queue<pair<int, int>> q; n   q.push({-1, n - 1}); n   pair<int, int> cur; n   while (!q.empty()) { n     cur = q.top(); n     q.pop(); n     if (!G[cur.second].vis) { n       G[cur.second].vis = true; n       if (cur.second == 0) { n         return -cur.first - 1; n       } n       for (int i = 0; i < G[cur.second].e.size(); ++i) { n         int nex = G[cur.second].e[i]; n         q.push({cur.first - 1, nex}); n       } n     } n   } n   return -1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   g.resize(n); n   row.resize(n); n   col.resize(m); n   string T1(n,  . ); n   string T2(m,  # ); n   vis.resize(n, (vector<bool>(m, false))); n   G.resize(n + m); n   for (int i = 0; i < n; ++i) { n     cin >> g[i]; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (g[i][j] ==  # ) { n         G[i].e.push_back(n + j); n         G[n + j].e.push_back(i); n       } n     } n   } n   cout << dijk() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n istream &operator>>(istream &in, pair<T1, T2> &a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &out, pair<T1, T2> a) { n   out << a.first <<     << a.second; n   return out; n } n template <typename T, typename T1> n T amax(T &a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T amin(T &a, T1 b) { n   if (b < a) a = b; n   return a; n } n const long long INF = 1e18; n const int32_t M = 1e9 + 7; n const int32_t MM = 998244353; n const int N = 5e5 + 5; n const int32_t MOD = MM; n struct mod_int { n   int32_t val; n   mod_int(long long v = 0) { n     if (v < 0) v = v % MOD + MOD; n     if (v >= MOD) v %= MOD; n     val = v; n   } n   static int32_t mod_inv(int32_t a, int32_t m = MOD) { n     int32_t g = m, r = a, x = 0, y = 1; n     while (r != 0) { n       int32_t q = g / r; n       g %= r; n       swap(g, r); n       x -= q * y; n       swap(x, y); n     } n     return x < 0 ? x + m : x; n   } n   static unsigned fast_mod(uint64_t x, unsigned m = MOD) { n     return x % m; n     unsigned x_high = x >> 32, x_low = (unsigned)x; n     unsigned quot, rem; n     asm( divl %4 n  :  =a (quot),  =d (rem) :  d (x_high),  a (x_low),  r (m)); n     return rem; n   } n   explicit operator int() const { return val; } n   mod_int &operator+=(const mod_int &other) { n     val += other.val; n     if (val >= MOD) val -= MOD; n     return *this; n   } n   mod_int &operator-=(const mod_int &other) { n     val -= other.val; n     if (val < 0) val += MOD; n     return *this; n   } n   mod_int &operator*=(const mod_int &other) { n     val = fast_mod((uint64_t)val * other.val); n     return *this; n   } n   mod_int &operator/=(const mod_int &other) { return *this *= other.inv(); } n   friend mod_int operator+(const mod_int &a, const mod_int &b) { n     return mod_int(a) += b; n   } n   friend mod_int operator-(const mod_int &a, const mod_int &b) { n     return mod_int(a) -= b; n   } n   friend mod_int operator*(const mod_int &a, const mod_int &b) { n     return mod_int(a) *= b; n   } n   friend mod_int operator/(const mod_int &a, const mod_int &b) { n     return mod_int(a) /= b; n   } n   mod_int &operator++() { n     val = val == MOD - 1 ? 0 : val + 1; n     return *this; n   } n   mod_int &operator--() { n     val = val == 0 ? MOD - 1 : val - 1; n     return *this; n   } n   mod_int operator++(int32_t) { n     mod_int before = *this; n     ++*this; n     return before; n   } n   mod_int operator--(int32_t) { n     mod_int before = *this; n     --*this; n     return before; n   } n   mod_int operator-() const { return val == 0 ? 0 : MOD - val; } n   bool operator==(const mod_int &other) const { return val == other.val; } n   bool operator!=(const mod_int &other) const { return val != other.val; } n   mod_int inv() const { return mod_inv(val); } n   friend ostream &operator<<(ostream &stream, const mod_int &m) { n     return stream << m.val; n   } n   friend istream &operator>>(istream &stream, mod_int &m) { n     return stream >> m.val; n   } n   mod_int pow(long long p) const { n     assert(p >= 0); n     mod_int a = *this, result = 1; n     while (p > 0) { n       if (p & 1) result *= a; n       a *= a; n       p >>= 1; n     } n     return result; n   } n }; n int n, k, m; n pair<pair<int, int>, int> x[N]; n vector<int> v[N]; n bool is1[N][32]; n int cnt[32]; n int last[32]; n int f[N][32]; n mod_int dp[N][32]; n mod_int ps[N][32]; n void solve() { n   cin >> n >> k >> m; n   for (int i = 1; i < m + 1; i++) { n     cin >> x[i]; n   } n   sort(x + 1, x + m + 1); n   for (int i = 1; i < m + 1; i++) { n     v[x[i].first.first].push_back(i); n     v[x[i].first.second].push_back(-i); n   } n   for (int i = 1; i < n + 2; i++) { n     for (int y : v[i]) { n       if (y < 0) { n       } else { n         for (int j = 0; j < k; j++) { n           if (((x[y].second >> j) & 1)) cnt[j]++; n         } n       } n     } n     for (int j = 0; j < k; j++) { n       if (cnt[j]) is1[i][j] = 1; n     } n     for (int j = 0; j < k; j++) { n       f[i][j] = last[j]; n     } n     for (int y : v[i]) { n       if (y < 0) { n         y *= -1; n         for (int j = 0; j < k; j++) { n           if (((x[y].second >> j) & 1)) n             cnt[j]--; n           else n             amax(last[j], x[y].first.first); n         } n       } n     } n   } n   for (int j = 0; j < k; j++) { n     dp[0][j] = 1; n     ps[0][j] = 1; n   } n   for (int i = 1; i < n + 2; i++) { n     for (int j = 0; j < k; j++) { n       if (!is1[i][j]) { n         dp[i][j] = ps[i - 1][j]; n         if (f[i][j]) dp[i][j] -= ps[f[i][j] - 1][j]; n       } n       ps[i][j] = dp[i][j] + ps[i - 1][j]; n     } n   } n   mod_int ans = 1; n   for (int i = 0; i < k; i++) { n     ans *= dp[n + 1][i]; n   } n   cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int f[200005][3], ans, dep[200005]; n int head[200005], cnt; n struct data { n   int next, to; n   data(int next = 0, int to = 0) : next(next), to(to) {} n } edge[200005 << 1]; n int read() { n   char c = getchar(); n   int x = 0; n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   return x; n } n void connect(int u, int v) { n   edge[++cnt] = data(head[u], v); n   head[u] = cnt; n } n void DFS(int u, int pre) { n   f[u][0] = 1; n   dep[u] = dep[pre] + 1; n   int mini = 0x3f3f3f3f; n   for (int i = head[u]; i; i = edge[i].next) { n     int v = edge[i].to; n     if (v == pre) continue; n     DFS(v, u); n     f[u][0] = f[u][0] + min(min(f[v][0], f[v][1]), f[v][2]); n     f[u][2] = f[u][2] + min(f[v][0], f[v][1]); n     mini = min(mini, f[v][0] - min(f[v][0], f[v][1])); n   } n   f[u][1] = f[u][2] + mini; n   if (dep[u] == 3) ans = ans + min(f[u][0], min(f[u][1], f[u][2])); n } n int main() { n   n = read(); n   for (int i = 1; i < n; ++i) { n     int u = read(), v = read(); n     connect(u, v); n     connect(v, u); n   } n   DFS(1, 0); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int q; n   cin >> q; n   vector<int> powers; n   powers.reserve(10000); n   for (int i = 0; i < (1 << 10); i++) { n     long long tot = 0; n     long long pow = 1; n     for (int j = 0; j < 10; j++) { n       if (i & (1 << j)) tot += pow; n       pow *= 3; n     } n     powers.push_back(tot); n   } n   sort(powers.begin(), powers.end()); n   while (q--) { n     int n; n     cin >> n; n     if (find(powers.begin(), powers.end(), n) == powers.end()) n       cout << *upper_bound(powers.begin(), powers.end(), n) <<   n ; n     else n       cout << n <<   n ; n   } n } n


#include <bits/stdc++.h> n void dfs(int x); n struct node { n   int n, h; n } h[100001]; n bool operator<(const node &A, const node &B) { return A.h < B.h; } n std::vector<int> map[100001]; n int range[100001][2]; n void init(int n); n int getmax(int f, int r); n void set(int x, int v); n int imax[100001][3]; n int dmax[100001][3]; n int main() { n   int n; n   int i, j; n   int t, a, b; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &h[i].h); n     h[i].n = i; n   } n   std::sort(h + 1, h + n + 1); n   for (i = 1; i < n; i++) { n     scanf( %d%d , &a, &b); n     map[a].push_back(b); n     map[b].push_back(a); n   } n   dfs(1); n   init(n); n   for (i = 1; i <= n; i = j) { n     for (j = i; j <= n && h[j].h == h[i].h; j++) { n       int x = h[j].n; n       for (int k = 0; k < map[x].size(); k++) { n         int xx = map[x][k]; n         if (range[xx][0] < range[x][0]) continue; n         int t = getmax(range[xx][0], range[xx][1]); n         if (t > imax[x][0]) { n           imax[x][2] = imax[x][0]; n           imax[x][1] = xx; n           imax[x][0] = t; n         } else if (t > imax[x][2]) { n           imax[x][2] = t; n         } n       } n     } n     for (j = i; j <= n && h[j].h == h[i].h; j++) { n       int x = h[j].n; n       set(range[x][0], imax[x][0] + 1); n     } n   } n   init(n); n   for (i = n; i >= 1; i = j) { n     for (j = i; j >= 1 && h[j].h == h[i].h; j--) { n       int x = h[j].n; n       for (int k = 0; k < map[x].size(); k++) { n         int xx = map[x][k]; n         if (range[xx][0] < range[x][0]) continue; n         int t = getmax(range[xx][0], range[xx][1]); n         if (t > dmax[x][0]) { n           dmax[x][2] = dmax[x][0]; n           dmax[x][1] = xx; n           dmax[x][0] = t; n         } else if (t > dmax[x][2]) { n           dmax[x][2] = t; n         } n       } n     } n     for (j = i; j >= 1 && h[j].h == h[i].h; j--) { n       int x = h[j].n; n       set(range[x][0], dmax[x][0] + 1); n     } n   } n   int ans = 0; n   for (i = 1; i <= n; i++) { n     if (imax[i][1] == dmax[i][1]) { n       if (ans < imax[i][0] + dmax[i][2] + 1) ans = imax[i][0] + dmax[i][2] + 1; n       if (ans < imax[i][2] + dmax[i][0] + 1) ans = imax[i][2] + dmax[i][0] + 1; n     } else { n       if (ans < imax[i][0] + dmax[i][0] + 1) ans = imax[i][0] + dmax[i][0] + 1; n     } n   } n   init(n); n   for (i = 1; i <= n; i = j) { n     for (j = i; j <= n && h[j].h == h[i].h; j++) { n       int x = h[j].n; n       int t = getmax(range[x][1] + 1, n); n       if (ans < t + dmax[x][0] + 1) ans = t + dmax[x][0] + 1; n     } n     for (j = i; j <= n && h[j].h == h[i].h; j++) { n       int x = h[j].n; n       set(range[x][0], imax[x][0] + 1); n     } n   } n   init(n); n   for (i = n; i >= 1; i = j) { n     for (j = i; j >= 1 && h[j].h == h[i].h; j--) { n       int x = h[j].n; n       int t = getmax(range[x][1] + 1, n); n       if (ans < t + imax[x][0] + 1) ans = t + imax[x][0] + 1; n     } n     for (j = i; j >= 1 && h[j].h == h[i].h; j--) { n       int x = h[j].n; n       set(range[x][0], dmax[x][0] + 1); n     } n   } n   printf( %d , ans); n   return 0; n } n int dT = 0; n void dfs(int x) { n   range[x][0] = ++dT; n   for (int i = 0; i < map[x].size(); i++) { n     int xx = map[x][i]; n     if (range[xx][0] != 0) continue; n     dfs(xx); n   } n   range[x][1] = dT; n } n int IT[400001]; n int b; n void init(int n) { n   for (b = 1; b <= n; b *= 2) n     ; n   for (int i = b * 2; i >= 1; i--) IT[i] = 0; n } n int max(int a, int b) { return a > b ? a : b; } n int getmax(int f, int r) { n   f += b; n   r += b; n   int m = 0; n   while (f < r) { n     if (f % 2 == 1) m = max(m, IT[f++]); n     if (r % 2 == 0) m = max(m, IT[r--]); n     f /= 2; n     r /= 2; n   } n   if (f == r) m = max(m, IT[f]); n   return m; n } n void set(int x, int v) { n   IT[x += b] = v; n   while (x /= 2) IT[x] = max(IT[x * 2], IT[x * 2 + 1]); n } n


#include<bits/stdc++.h> n #define ll long long n #define L(i, j, k) for(int i = (j); i <= (k); ++i) n #define R(i, j, k) for(int i = (j); i >= (k); --i) n #define vi vector < int >  n #define sz(a) ((int) a.size())  n using namespace std; n const int N = 1e6 + 7; n int T; n  n int n, m, c[N], a[N], b[N];  n void Main () { n  n = m = 0; n  int x; n  cin >> x; n  L(i, 1, x) { n   int w; n   cin >> w; n   c[i] = w; n   if(i & 1) a[++n] = w; n   else b[++m] = w; n  } n  sort(a + 1, a + n + 1); n  sort(b + 1, b + m + 1); n  sort(c + 1, c + x + 1); n  n = 0, m = 0; n  L(i, 1, x) { n   if(i & 1) { n    if(a[++n] != c[i]) return cout <<  NO n , void(); n   } n   else { n    if(b[++m] != c[i]) return cout <<  NO n , void(); n   }  n  } n  cout <<  YES n ; n } n int main() {  n  ios::sync_with_stdio(false); n  cin.tie(0); cout.tie(0); n  cin >> T; n  while (T--) Main(); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T BMOD(T p, T e, T m) { n   T ret = 1; n   while (e) { n     if (e & 1) ret = (ret * p) % m; n     p = (p * p) % m; n     e >>= 1; n   } n   return (T)ret; n } n template <class T> n inline T MODINV(T a, T m) { n   return BMOD(a, m - 2, m); n } n template <class T> n inline T isPrime(T a) { n   for (T i = 2; i <= sqrt(double(a)); i++) { n     if (a % i == 0) { n       return 0; n     } n   } n   return 1; n } n template <class T> n inline T lcm(T a, T b) { n   return (a / __gcd(a, b)) * b; n } n template <class T> n inline T power(T a, T b) { n   return (b == 0) ? 1 : a * power(a, b - 1); n } n template <class T> n inline string to_str(T t) { n   stringstream ss; n   ss << t; n   return ss.str(); n } n int main() { n   int h, m; n   scanf( %d:%d , &h, &m); n   h %= 12; n   double a = h * 30.0 + (m / 2.0); n   double b = m * 6.0; n   printf( %.10lf %.10lf n , a, b); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long f[102][102]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i <= n; i++) f[0][i] = 1; n   for (int j = 1; j <= n; j++) n     for (int i = 1; i <= n; i++) n       for (int k = 0; k < i; k++) f[i][j] += f[k][j - 1] * f[i - k - 1][j - 1]; n   printf( %lld , f[n][n] - f[n][m - 1]); n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[26]; n void sol() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long k, x; n     cin >> k >> x; n     cout << (x + (k - 1) * 9) <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) sol(); 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 n; n   cin >> n; n   int ans = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) { n       int inp; n       cin >> inp; n       if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += inp; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 1 << 19; n const int MOD = 1000000007; n int arr[MXN]; n int suf[2 * MXN]; n int pre[2 * MXN]; n int lb[2 * MXN]; n int rb[2 * MXN]; n void build(int c, int l, int r) { n   lb[c] = l; n   rb[c] = r; n   if (l == r) return; n   int k = (l + r) / 2; n   build(2 * c, l, k); n   build(2 * c + 1, k + 1, r); n } n void updatesuf(int c, int idx, int amt) { n   if (lb[c] == rb[c]) { n     suf[c] += amt; n     return; n   } n   int k = (lb[c] + rb[c]) / 2; n   if (idx <= k) n     updatesuf(2 * c, idx, amt); n   else n     updatesuf(2 * c + 1, idx, amt); n   suf[c] = suf[2 * c] + suf[2 * c + 1]; n   suf[c] %= MOD; n } n void updatepre(int c, int idx, int amt) { n   if (lb[c] == rb[c]) { n     pre[c] += amt; n     return; n   } n   int k = (lb[c] + rb[c]) / 2; n   if (idx <= k) n     updatepre(2 * c, idx, amt); n   else n     updatepre(2 * c + 1, idx, amt); n   pre[c] = pre[2 * c] + pre[2 * c + 1]; n   pre[c] %= MOD; n } n int querysuf(int c, int l, int r) { n   if (lb[c] == l && rb[c] == r) return suf[c]; n   int k = (lb[c] + rb[c]) / 2; n   if (l <= k && k < r) n     return (querysuf(2 * c, l, k) + querysuf(2 * c + 1, k + 1, r)) % MOD; n   else if (r <= k) n     return querysuf(2 * c, l, r); n   else n     return querysuf(2 * c + 1, l, r); n } n int querypre(int c, int l, int r) { n   if (lb[c] == l && rb[c] == r) return pre[c]; n   int k = (lb[c] + rb[c]) / 2; n   if (l <= k && k < r) n     return (querypre(2 * c, l, k) + querypre(2 * c + 1, k + 1, r)) % MOD; n   else if (r <= k) n     return querypre(2 * c, l, r); n   else n     return querypre(2 * c + 1, l, r); n } n int main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, int> > proc; n   for (int i = 1; i <= n; i++) { n     scanf( %d , arr + i); n     proc.emplace_back(arr[i], i); n   } n   build(1, 0, MXN - 1); n   sort(proc.begin(), proc.end()); n   int ans = 0; n   for (auto p : proc) { n     int x = p.first; n     int idx = p.second; n     int l = idx - 1; n     int r = n - l - 1; n     int a = querysuf(1, idx, n); n     int b = querypre(1, 1, idx); n     long long cur = n         1ll * a * (l + 1) + 1ll * b * (r + 1) + 1ll * (l + 1) * (r + 1); n     cur %= (long long)MOD; n     cur *= (long long)x; n     cur %= (long long)MOD; n     ans += cur; n     ans %= MOD; n     updatesuf(1, idx, r + 1); n     updatepre(1, idx, l + 1); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool chkmin(T &x, T y) { n   return x > y ? x = y, 1 : 0; n } n template <typename T> n inline bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n inline void read(int &x) { n   char ch = getchar(); n   int f = 1; n   x = 0; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   x *= f; n } n int n, m, p[100050], v[100050], nx[100050], pr[100050], id[100050]; n set<pair<int, int> > se; n int get(int x, int y) { n   if (x == y) return 1000000005; n   int d = (p[y] - p[x] + m) % m; n   if (x > y) d += v[y]; n   if (d <= v[x]) return 1; n   if (v[x] <= v[y]) return 1000000005; n   return (d - v[y] - 1) / (v[x] - v[y]) + 1; n } n bool cmp(int x, int y) { return p[x] < p[y]; } n int main() { n   read(n), read(m); n   for (register int i = 1; i <= n; ++i) n     read(p[i]), --p[i], read(v[i]), id[i] = i; n   sort(id + 1, id + n + 1, cmp); n   for (register int i = 1; i <= n; ++i) n     pr[id[i]] = id[i - 1], nx[id[i]] = id[i + 1]; n   nx[pr[id[1]] = id[n]] = id[1]; n   for (register int i = 1; i <= n; ++i) se.insert(make_pair(get(i, nx[i]), i)); n   while (1) { n     set<pair<int, int> >::iterator it = se.begin(); n     if (it->first >= 1000000005) break; n     int u = it->second, t = it->first; n     se.erase(it); n     se.erase(make_pair(get(pr[u], u), pr[u])), n         se.erase(make_pair(get(nx[u], nx[nx[u]]), nx[u])); n     pr[nx[u] = nx[nx[u]]] = u; n     p[u] = (p[u] + t) % m, --v[u]; n     se.insert(make_pair(get(pr[u], u), pr[u])), n         se.insert(make_pair(get(u, nx[u]), u)); n   } n   printf( %d n , se.size()); n   for (auto v : se) printf( %d  , v.second); n   puts(  ); n   return 0; n } n


#include  bits/stdc++.h  n using namespace std; n typedef long long ll; n typedef long double ld; n typedef unsigned long long ull; n #define int ll n #define sz(a) int(a.size()) n #define dbg(a) cout << #a <<   =   << a << endl n #define dbg1(a) cout << #a <<   = [  ; for (auto& _ : a) cout << _ <<    ; cout <<  ]  << endl n #define dbg2(a) cout << #a <<   = [  ; for (auto& _ : a) cout <<  (  << _.first <<     << _.second <<  )  ; cout <<  ]  << endl n const int inf = int(1e9) + 7; n void solve() { n   int n; n   cin >> n; n   bool ok = false; n   for (int i = 0; i < n; ++i) { n     int q; n     cin >> q; n     ok |= q != int(sqrt(q)) * int(sqrt(q)); n   } n   cout << (ok ?  YES n  :  NO n ); n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(15); n   int tests = 1; n   cin >> tests; n   while (tests--) { n     solve(); n   } n }


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, a[12][12]; n   cin >> n; n   memset(a, 0, sizeof(a)); n   for (int i = 1; i <= n; i++) { n     a[1][i] = 1; n     a[i][1] = 1; n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 2; j <= n; j++) { n       a[i][j] = a[i - 1][j] + a[i][j - 1]; n     } n   } n   cout << a[n][n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<pair<int, int>> v(n); n   vector<int> v2(k); n   for (int i = 0; i < n; i++) { n     cin >> v[i].first; n     v[i].second = i + 1; n   } n   sort(v.begin(), v.end()); n   int sum = 0; n   for (int i = 0; i < k; i++) { n     sum += v[n - 1 - i].first; n     v2[i] = v[n - 1 - i].second; n   } n   cout << sum << endl; n   sort(v2.begin(), v2.end()); n   for (int i = k - 1; i > 0; i--) { n     v2[i] = v2[i] - v2[i - 1]; n   } n   int cnt = 0; n   for (int i = 0; i < k - 1; i++) { n     cout << v2[i] <<    ; n     cnt += v2[i]; n   } n   cout << n - cnt; n   return 0; n } n


#pragma GCC optimize ( Ofast ) n #include<bits/stdc++.h> n using namespace std; n void*wmem; n char memarr[96000000]; n template<class S, class T> inline S min_L(S a,T b){ n   return a<=b?a:b; n } n template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ n   static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; n   (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); n   (*arr)=(T*)(*mem); n   (*mem)=((*arr)+x); n } n template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ n   walloc1d(arr, x2-x1, mem); n   (*arr) -= x1; n } n template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){ n   sort(a, a+N); n } n template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){ n   int i; n   pair<T1, T2>*arr; n   walloc1d(&arr, N, &mem); n   for(i=(0);i<(N);i++){ n     arr[i].first = a[i]; n     arr[i].second = b[i]; n   } n   sort(arr, arr+N); n   for(i=(0);i<(N);i++){ n     a[i] = arr[i].first; n     b[i] = arr[i].second; n   } n } n inline int my_getchar(){ n   static char buf[1048576]; n   static int s = 1048576; n   static int e = 1048576; n   if(s == e && e == 1048576){ n     e = fread(buf, 1, 1048576, stdin); n     s = 0; n   } n   if(s == e){ n     return EOF; n   } n   return buf[s++]; n } n inline void rd(int &x){ n   int k; n   int m=0; n   x=0; n   for(;;){ n     k = my_getchar(); n     if(k== - ){ n       m=1; n       break; n     } n     if( 0 <=k&&k<= 9 ){ n       x=k- 0 ; n       break; n     } n   } n   for(;;){ n     k = my_getchar(); n     if(k< 0 ||k> 9 ){ n       break; n     } n     x=x*10+k- 0 ; n   } n   if(m){ n     x=-x; n   } n } n inline void rd(long long &x){ n   int k; n   int m=0; n   x=0; n   for(;;){ n     k = my_getchar(); n     if(k== - ){ n       m=1; n       break; n     } n     if( 0 <=k&&k<= 9 ){ n       x=k- 0 ; n       break; n     } n   } n   for(;;){ n     k = my_getchar(); n     if(k< 0 ||k> 9 ){ n       break; n     } n     x=x*10+k- 0 ; n   } n   if(m){ n     x=-x; n   } n } n inline int rd_int(void){ n   int x; n   rd(x); n   return x; n } n struct MY_WRITER{ n   char buf[1048576]; n   int s; n   int e; n   MY_WRITER(){ n     s = 0; n     e = 1048576; n   } n   ~MY_WRITER(){ n     if(s){ n       fwrite(buf, 1, s, stdout); n     } n   } n } n ; n MY_WRITER MY_WRITER_VAR; n void my_putchar(int a){ n   if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ n     fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); n     MY_WRITER_VAR.s = 0; n   } n   MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; n } n inline void wt_L(char a){ n   my_putchar(a); n } n inline void wt_L(int x){ n   int s=0; n   int m=0; n   char f[10]; n   if(x<0){ n     m=1; n     x=-x; n   } n   while(x){ n     f[s++]=x%10; n     x/=10; n   } n   if(!s){ n     f[s++]=0; n   } n   if(m){ n     my_putchar( - ); n   } n   while(s--){ n     my_putchar(f[s]+ 0 ); n   } n } n template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){ n   int i; n   sz++; n   for(i=sz-1;i>k;i--){ n     a[i] = a[i-1]; n   } n   a[k] = aval; n } n template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){ n   int i; n   sz++; n   for(i=sz-1;i>k;i--){ n     a[i] = a[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     b[i] = b[i-1]; n   } n   a[k] = aval; n   b[k] = bval; n } n template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){ n   int i; n   sz++; n   for(i=sz-1;i>k;i--){ n     a[i] = a[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     b[i] = b[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     c[i] = c[i-1]; n   } n   a[k] = aval; n   b[k] = bval; n   c[k] = cval; n } n template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){ n   int i; n   sz++; n   for(i=sz-1;i>k;i--){ n     a[i] = a[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     b[i] = b[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     c[i] = c[i-1]; n   } n   for(i=sz-1;i>k;i--){ n     d[i] = d[i-1]; n   } n   a[k] = aval; n   b[k] = bval; n   c[k] = cval; n   d[k] = dval; n } n template<class S, class T> inline S chmin(S &a, T b){ n   if(a>b){ n     a=b; n   } n   return a; n } n template<class S, class T> inline S chmax(S &a, T b){ n   if(a<b){ n     a=b; n   } n   return a; n } n int N; n int C; n int Q; n int A[30000]; n int X; n long long Y; n long long cnt[5][30000+2]; n int sz; n int lis[5]; n int ind[5]; n int usz[30000+2]; n int ulis[30000+2][5]; n int dsz[30000+2]; n int dlis[30000+2][5]; n long long skipL[5][30000+2]; n long long skipR[5][30000+2]; n long long skipV[5][30000+2]; n int skip = 150; n long long skip2L[5][30000+2]; n long long skip2R[5][30000+2]; n long long skip2V[5][30000+2]; n int skip2 = 30; n int main(){ n   int t_ynMSdg; n   wmem = memarr; n   int i; n   int j; n   int k; n   int c; n   for(i=(0);i<(5);i++){ n     cnt[i][0] = 1; n   } n   for(i=(0);i<(5);i++){ n     for(k=(0);k<(30000);k++){ n       for(j=(0);j<(min_L(k, i)+1);j++){ n         cnt[i][k+1] += cnt[i-j][k-j]; n         if(cnt[i][k+1] > 2000000000000000000LL){ n           cnt[i][k+1] = 2000000000000000000LL; n         } n       } n     } n   } n   int KrdatlYV = rd_int(); n   for(t_ynMSdg=(0);t_ynMSdg<(KrdatlYV);t_ynMSdg++){ n     int dtiCQK_a; n     rd(N); n     rd(C); n     rd(Q); n     { n       int a2conNHc; n       for(a2conNHc=(0);a2conNHc<(N);a2conNHc++){ n         rd(A[a2conNHc]); n       } n     } n     for(k=(0);k<(N);k++){ n       sz = 0; n       for(i=(0);i<(C+1);i++){ n         if(k+i < N){ n           arrInsert(sz, sz, ind, i, lis, A[k+i]); n         } n       } n       sortA_L(sz, lis, ind); n       j = usz[k] = dsz[k] = 0; n       for(i=(0);i<(sz);i++){ n         if(ind[i] == 0){ n           j++; n           continue; n         } n         if(j==0){ n           ulis[k][usz[k]++] = ind[i]; n         } n         if(j==1){ n           dlis[k][dsz[k]++] = ind[i]; n         } n       } n     } n     for(k=(0);k<(N);k++){ n       for(c=(0);c<(C+1);c++){ n         long long sm = 0; n         skipL[c][k] = -4611686016279904256LL; n         skipR[c][k] = 4611686016279904256LL; n         if(k+skip+5 >= N){ n           swap(skipL[c][k], skipR[c][k]); n           continue; n         } n         for(j=(k);j<(k+skip);j++){ n           for(i=(0);i<(usz[j]);i++){ n             if(c >= ulis[j][i]){ n               sm += cnt[c-ulis[j][i]][N-j-ulis[j][i]-1]; n             } n           } n           if(sm > 4611686016279904256LL){ n             sm = 2000000000000000000LL; n           } n           chmax(skipL[c][k], sm); n           chmin(skipR[c][k], sm + cnt[c][N-j-1]); n         } n         skipV[c][k] = sm; n       } n     } n     for(k=(0);k<(N);k++){ n       for(c=(0);c<(C+1);c++){ n         long long sm = 0; n         skip2L[c][k] = -4611686016279904256LL; n         skip2R[c][k] = 4611686016279904256LL; n         if(k+skip2+5 >= N){ n           swap(skip2L[c][k], skip2R[c][k]); n           continue; n         } n         for(j=(k);j<(k+skip2);j++){ n           for(i=(0);i<(usz[j]);i++){ n             if(c >= ulis[j][i]){ n               sm += cnt[c-ulis[j][i]][N-j-ulis[j][i]-1]; n             } n           } n           if(sm > 4611686016279904256LL){ n             sm = 2000000000000000000LL; n           } n           chmax(skip2L[c][k], sm); n           chmin(skip2R[c][k], sm + cnt[c][N-j-1]); n         } n         skip2V[c][k] = sm; n       } n     } n     for(dtiCQK_a=(0);dtiCQK_a<(Q);dtiCQK_a++){ n       rd(X);X += (-1); n       rd(Y);Y += (-1); n       if(Y >= cnt[C][N]){ n         wt_L(-1); n         wt_L(  n ); n         continue; n       } n       c = C; n       for(k=(0);k<(N);k++){ n         if(skipL[c][k] <= Y  &&  Y < skipR[c][k]){ n           if(X < k + skip){ n             wt_L(A[X]); n             wt_L(  n ); n             break; n           } n           Y -= skipV[c][k]; n           k += skip - 1; n           continue; n         } n         if(skip2L[c][k] <= Y  &&  Y < skip2R[c][k]){ n           if(X < k + skip2){ n             wt_L(A[X]); n             wt_L(  n ); n             break; n           } n           Y -= skip2V[c][k]; n           k += skip2 - 1; n           continue; n         } n         for(i=(0);i<(usz[k]);i++){ n           if(c >= ulis[k][i]){ n             if(Y < cnt[c-ulis[k][i]][N-k-ulis[k][i]-1]){ n               if(X <= k + ulis[k][i]){ n                 wt_L(A[k+ulis[k][i]-(X-k)]); n                 wt_L(  n ); n                 goto qE8LMwYZ; n               } n               c -= ulis[k][i]; n               k += ulis[k][i]; n               goto lQU550vz; n             } n             else{ n               Y -= cnt[c-ulis[k][i]][N-k-ulis[k][i]-1]; n             } n           } n         } n         if(Y < cnt[c][N-k-1]){ n           if(X == k){ n             wt_L(A[k]); n             wt_L(  n ); n             break; n           } n           continue; n         } n         else{ n           Y -= cnt[c][N-k-1]; n         } n         for(i=(0);i<(dsz[k]);i++){ n           if(c >= dlis[k][i]){ n             if(Y < cnt[c-dlis[k][i]][N-k-dlis[k][i]-1]){ n               if(X <= k + dlis[k][i]){ n                 wt_L(A[k+dlis[k][i]-(X-k)]); n                 wt_L(  n ); n                 goto qE8LMwYZ; n               } n               c -= dlis[k][i]; n               k += dlis[k][i]; n               goto lQU550vz; n             } n             else{ n               Y -= cnt[c-dlis[k][i]][N-k-dlis[k][i]-1]; n             } n           } n         } n         lQU550vz:; n       } n       qE8LMwYZ:; n     } n   } n   return 0; n } n // cLay version 20210103-1 n  n // --- original code --- n // //no-unlocked n // int N, C, Q, A[3d4], X; ll Y; n // ll cnt[5][3d4+2]; n // int sz, lis[5], ind[5]; n // int usz[3d4+2], ulis[3d4+2][5]; n // int dsz[3d4+2], dlis[3d4+2][5]; n // ll skipL[5][3d4+2], skipR[5][3d4+2], skipV[5][3d4+2]; int skip = 150; n // ll skip2L[5][3d4+2], skip2R[5][3d4+2], skip2V[5][3d4+2]; int skip2 = 30; n // { n //   int i, j, k, c; n //   rep(i,5) cnt[i][0] = 1; n //   rep(i,5) rep(k,3d4) rep(j,min(k,i)+1){ n //     cnt[i][k+1] += cnt[i-j][k-j]; n //     if(cnt[i][k+1] > 2d18) cnt[i][k+1] = 2d18; n //   } n //   REP(rd_int()){ n //     rd(N,C,Q,A(N)); n //  n //     rep(k,N){ n //       sz = 0; n //       rep(i,C+1) if(k+i < N) arrInsert(sz, sz, ind, i, lis, A[k+i]); n //       sortA(sz, lis, ind); n //       j = usz[k] = dsz[k] = 0; n //       rep(i,sz){ n //         if(ind[i] == 0) j++, continue; n //         if(j==0) ulis[k][usz[k]++] = ind[i]; n //         if(j==1) dlis[k][dsz[k]++] = ind[i]; n //       } n //     } n //  n //     rep(k,N) rep(c,C+1){ n //       ll sm = 0; n //       skipL[c][k] = -ll_inf; n //       skipR[c][k] = ll_inf; n //       if(k+skip+5 >= N) swap(skipL[c][k], skipR[c][k]), continue; n //       rep(j,k,k+skip){ n //         rep(i,usz[j]) if(c >= ulis[j][i]) sm += cnt[c-ulis[j][i]][N-j-ulis[j][i]-1]; n //         if(sm > ll_inf) sm = 2d18; n //         skipL[c][k] >?= sm; n //         skipR[c][k] <?= sm + cnt[c][N-j-1]; n //       } n //       skipV[c][k] = sm; n //     } n //  n //     rep(k,N) rep(c,C+1){ n //       ll sm = 0; n //       skip2L[c][k] = -ll_inf; n //       skip2R[c][k] = ll_inf; n //       if(k+skip2+5 >= N) swap(skip2L[c][k], skip2R[c][k]), continue; n //       rep(j,k,k+skip2){ n //         rep(i,usz[j]) if(c >= ulis[j][i]) sm += cnt[c-ulis[j][i]][N-j-ulis[j][i]-1]; n //         if(sm > ll_inf) sm = 2d18; n //         skip2L[c][k] >?= sm; n //         skip2R[c][k] <?= sm + cnt[c][N-j-1]; n //       } n //       skip2V[c][k] = sm; n //     } n //  n //     rep(Q){ n //       rd(X--, Y--); n //       if(Y >= cnt[C][N]) wt(-1), continue; n //       c = C; n //       rep(k,N){ n //         if(skipL[c][k] <= Y < skipR[c][k]){ n //           if(X < k + skip) wt(A[X]), break; n //           Y -= skipV[c][k]; n //           k += skip - 1; n //           continue; n //         } n //         if(skip2L[c][k] <= Y < skip2R[c][k]){ n //           if(X < k + skip2) wt(A[X]), break; n //           Y -= skip2V[c][k]; n //           k += skip2 - 1; n //           continue; n //         } n //         rep(i,usz[k]) if(c >= ulis[k][i]){ n //           if(Y < cnt[c-ulis[k][i]][N-k-ulis[k][i]-1]){ n //             if(X <= k + ulis[k][i]) wt(A[k+ulis[k][i]-(X-k)]), break_break; n //             c -= ulis[k][i]; n //             k += ulis[k][i]; n //             break_continue; n //           } else { n //             Y -= cnt[c-ulis[k][i]][N-k-ulis[k][i]-1]; n //           } n //         } n //         if(Y < cnt[c][N-k-1]){ n //           if(X == k) wt(A[k]), break; n //           continue; n //         } else { n //           Y -= cnt[c][N-k-1]; n //         } n //         rep(i,dsz[k]) if(c >= dlis[k][i]){ n //           if(Y < cnt[c-dlis[k][i]][N-k-dlis[k][i]-1]){ n //             if(X <= k + dlis[k][i]) wt(A[k+dlis[k][i]-(X-k)]), break_break; n //             c -= dlis[k][i]; n //             k += dlis[k][i]; n //             break_continue; n //           } else { n //             Y -= cnt[c-dlis[k][i]][N-k-dlis[k][i]-1]; n //           } n //         } n //       } n //     } n //   } n // } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct Trie { n   int trie[6000005][2]; n   int cnt[6000005]; n   int root = 0; n   long long val[6000005]; n   long long xorsum = 0; n   long long ans[6000005 / 10]; n   int C = 0; n   int newroot() { n     trie[C][0] = trie[C][1] = -1; n     cnt[C] = 0; n     return C++; n   } n   void Insert(long long x) { n     long long p = root; n     for (int i = 60; i >= 0; i--) { n       long long id = (x >> i) & 1; n       if (trie[p][id] == -1) trie[p][id] = newroot(); n       p = trie[p][id]; n       cnt[p]++; n     } n     val[p] = x; n   } n   bool check(long long xorsum, long long &res, int index, bool limit, int dep) { n     if (index != root && (cnt[index] == 0 || index == -1)) return false; n     if (dep == -1) { n       res = val[index]; n       cnt[index]--; n       return true; n     } n     int id = (xorsum >> dep) & 1; n     if (id == 0) { n       bool ret = (check(xorsum, res, trie[index][0], limit, dep - 1)) || n                  (!limit && check(xorsum, res, trie[index][1], limit, dep - 1)); n       if (ret == 0) return false; n       cnt[index]--; n       return true; n     } else { n       bool ret = (check(xorsum, res, trie[index][0], limit, dep - 1)) || n                  (check(xorsum, res, trie[index][1], false, dep - 1)); n       if (ret == 0) return false; n       cnt[index]--; n       return true; n     } n   } n   void solve() { n     for (int i = n - 1; i >= 0; i--) { n       long long res; n       bool ret = check(xorsum, res, root, true, 60); n       if (ret == 0) { n         puts( No ); n         return; n       } n       ans[i] = res; n       assert(xorsum > (xorsum ^ res)); n       xorsum ^= res; n     } n     puts( Yes ); n     for (int i = 0; i < n; i++) { n       cout << ans[i] <<    ; n     } n     puts(  ); n   } n } Tree; n int main() { n   scanf( %d , &n); n   Tree.root = Tree.newroot(); n   for (int i = 0; i < n; i++) { n     long long x; n     scanf( %I64d , &x); n     Tree.Insert(x); n     Tree.xorsum ^= x; n   } n   Tree.solve(); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a << endl; n   err(++it, args...); n } n long long powm(long long a, long long b, long long mod) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n const long long mod = 1e9 + 7; n const long long N = 1000005; n const long long inf = 1e9; n void solve() { n   int n; n   cin >> n; n   deque<long long> dq; n   long long ans = 0; n   while (n--) { n     long long x; n     cin >> x; n     if (dq.size() == 0) { n       dq.push_back(x); n       continue; n     } n     if (dq.size() > 0) ans = max(ans, (dq.back() ^ x)); n     while (dq.size() > 0 and dq.back() < x) { n       ans = max(ans, (x ^ dq.back())); n       dq.pop_back(); n     } n     if (dq.size() > 0) ans = max(ans, (dq.back() ^ x)); n     dq.push_back(x); n   } n   long long curr = dq.back(); n   dq.pop_back(); n   while (!dq.empty()) { n     ans = max(ans, (curr ^ dq.back())); n     curr = dq.back(); n     dq.pop_back(); n   } n   cout << ans << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cout << fixed << setprecision(15); n   int tc = 1; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double g = 9.8; n const double eps = 1e-9; n int n, m, v; n struct Ques { n   double angle; n   int id; n } ques[10010]; n struct Wall { n   double x, y; n } wall[100010]; n double ans_x[10010], ans_y[10010]; n bool cmp(const Ques &a, const Ques &b) { return a.angle < b.angle; } n bool cmp2(const Wall &a, const Wall &b) { return a.x < b.x; } n int main() { n   scanf( %d%d , &n, &v); n   for (int i = 1; i <= n; i++) { n     scanf( %lf , &ques[i].angle); n     ques[i].id = i; n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) scanf( %lf%lf , &wall[i].x, &wall[i].y); n   sort(ques + 1, ques + n + 1, cmp); n   sort(wall + 1, wall + m + 1, cmp2); n   int h = 1; n   for (int i = 1; i <= n; i++) { n     double v_y = v * sin(ques[i].angle), v_x = v * cos(ques[i].angle); n     while (h <= m) { n       double time = wall[h].x / v_x; n       double y = v_y * time - 0.5 * g * time * time; n       if (y < eps) { n         ans_x[ques[i].id] = v_x * (v_y / (0.5 * g)); n         ans_y[ques[i].id] = 0; n         break; n       } else if (y < wall[h].y + eps) { n         ans_x[ques[i].id] = wall[h].x; n         ans_y[ques[i].id] = y; n         break; n       } else n         h++; n     } n   } n   for (int i = 1; i <= n; i++) n     if (ans_x[ques[i].id] < eps) { n       double v_y = v * sin(ques[i].angle), v_x = v * cos(ques[i].angle); n       ans_x[ques[i].id] = v_x * (v_y / (0.5 * g)); n       ans_y[ques[i].id] = 0; n     } n   for (int i = 1; i <= n; i++) printf( %.9lf %.9lf n , ans_x[i], ans_y[i]); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const double eps = 1e-6; n const int mod = 1000000007; n inline string getstr(string &s, int l, int r) { n   string ret =   ; n   for (int i = l; i <= r; i++) ret.push_back(s[i]); n   return ret; n } n int modpow(int x, int y, int md = mod) { n   if (y == 0) return 1; n   int ret = modpow(x, y >> 1, md); n   ret = (long long)ret * ret % md; n   if (y & 1) ret = (long long)ret * x % md; n   return ret; n } n string s, t; n int n; n int main() { n   cin >> n >> s >> t; n   int l, r; n   for (l = 0;; l++) { n     if (s[l] != t[l]) { n       break; n     } n   } n   for (r = n - 1;; r--) { n     if (s[r] != t[r]) { n       break; n     } n   } n   int lft = 1, rgt = 1; n   for (int i = l; i < r; i++) { n     if (s[i] != t[i + 1]) lft = 0; n     if (s[i + 1] != t[i]) rgt = 0; n   } n   cout << lft + rgt << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int nax = 1e5 + 5; n using namespace std; n int gcd(int x, int y) { n   if (x % y == 0) return y; n   return gcd(y, x % y); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n, m; n   cin >> n >> m; n   vector<int> a(n + 1), b(m + 1); n   for (int i = 0; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i <= m; i++) { n     cin >> b[i]; n   } n   if (n != m) { n     if (n > m) { n       if ((a[0] > 0 && b[0] > 0) || (a[0] < 0 && b[0] < 0)) { n         puts( Infinity ); n       } else { n         puts( -Infinity ); n       } n     } else { n       cout <<  0/1  n            <<   n ; n     } n     return 0; n   } else { n     int ans = gcd(a[0], b[0]); n     if ((a[0] > 0 && b[0] > 0) || (a[0] < 0 && b[0] < 0)) n       cout << a[0] / ans <<  /  << b[0] / ans <<   n ; n     else n       cout << -abs(a[0] / ans) <<  /  << abs(b[0] / ans) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(int p) { n   if (p == 2) return 1; n   if (p % 2 == 0) return 0; n   for (long long int i = 3; i * i <= p; i += 2) { n     if (p % i == 0) return 0; n   } n   if (p > 2) return 1; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     int n; n     cin >> n; n     if (check(n)) { n       cout <<  1  <<   n ; n       cout << n <<   n ; n       continue; n     } n     if (check(n - 2)) { n       cout <<  2  <<   n ; n       cout <<  2  <<     << n - 2 <<   n ; n       continue; n     } n     cout <<  3  <<   n ; n     int a; n     for (int i = n; i > 3; i--) { n       if (check(i)) { n         a = i; n         n -= a; n         break; n       } n     } n     cout << a <<    ; n     for (int i = 2; i <= n; i++) { n       if (check(i) && check(n - i)) { n         cout << i <<     << n - i <<   n ; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> m; n bool fd(int x, int y) { n   if (x == y) return m[y] >= 2; n   return m.find(y) != m.end(); n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < (n); i++) { n     int x; n     cin >> x; n     m[x]++; n   } n   int cnt = 0; n   for (auto& xp : m) { n     int x = xp.first; n     for (int s = 1; s <= 30; s++) { n       if ((1 << s) <= x) continue; n       if (fd(x, (1 << s) - x)) goto cont; n     } n     cnt += xp.second; n   cont:; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, j, k, l, a, v, b, n, m; n   string s; n   while (cin >> s) { n     k = 0; n     j = 0; n     l = s.size(); n     for (i = 0; i < l; i++) { n       if (s[i] ==  W  && s[i + 1] ==  U  && s[i + 2] ==  B ) { n         i = i + 2; n         if (k > 0) { n           if (j == 1) cout <<    ; n           j = 0; n         } n       } else { n         cout << s[i]; n         j = 1; n       } n       k = 1; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int read(); n int a[14250]; n unsigned long long ans; n bool cmp(int a, int b) { return a < b; } n int main() { n   int n = read(), k = read(); n   for (int i = 1; i <= n; i++) { n     a[i] = read(); n   } n   sort(a + 1, a + n + 1, cmp); n   for (int i = 1; i <= k; i++) { n     ans += a[i]; n   } n   cout << ans; n   return 0; n } n inline int read() { n   int x = 0, w = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * w; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[1000009]; n int in[1000009], out[1000009]; n bool vs[22][1000009]; n void dfs(int x, int n) { n   vs[x][n] = 1; n   for (auto& it : adj[n]) n     if (!vs[x][it]) dfs(x, it); n } n int main() { n   int N, M; n   scanf( %d%d , &N, &M); n   while (M--) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     in[v]++; n     out[u]++; n   } n   vector<int> src, snk; n   for (int i = 1; i <= N; i++) { n     if (in[i] == 0) src.push_back(i); n     if (out[i] == 0) snk.push_back(i); n   } n   int s = src.size(); n   for (int i = 0; i < s; i++) { n     dfs(i, src[i]); n   } n   for (int i = 1; i < (1 << s) - 1; i++) { n     set<int> st; n     int c = 0; n     for (int j = 0; j < s; j++) { n       if (i & (1 << j)) { n         ++c; n         for (auto& it : snk) n           if (vs[j][it]) st.insert(it); n       } n     } n     if (c >= (int)st.size()) return !printf( NO ); n   } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char z[500005]; n int Qs1[500005], b, Qs2[500005]; n int f(char a) { n   if (a ==  w ) return b + 1; n   return 1; n } n int main() { n   int i, j, n, a, t, Max = 0; n   int *qs2 = Qs2 + 1, *qs1 = Qs1 + 1; n   scanf( %d %d %d %d  , &n, &a, &b, &t); n   gets(z); n   qs1[0] = f(z[0]); n   for (i = 1; i < n; i++) { n     qs1[i] = a + f(z[i]) + qs1[i - 1]; n   } n   for (i = n - 1; i >= 0; i--) { n     qs2[n - 1 - i] = a + f(z[i]) + qs2[n - 2 - i]; n   } n   for (i = 0; i < n; i++) { n     if (qs1[i] <= t) Max = max(min(i + 1, n), Max); n     if (qs2[i] + qs1[0] <= t) Max = max(min(i + 2, n), Max); n   } n   for (i = 0; i < n; i++) { n     int tmp = lower_bound(qs2, qs2 + n, t - qs1[i] - a * i) - qs2; n     if (t - qs1[i] - a * i < qs2[tmp]) tmp--; n     if (tmp == -1) continue; n     Max = max(min(tmp + i + 2, n), Max); n   } n   for (i = 0; i < n; i++) { n     int tmp = lower_bound(qs1, qs1 + n, t - qs2[i] - a * i - a) - qs1; n     if (t - qs2[i] - a * i - a < qs1[tmp]) tmp--; n     if (tmp == -1) continue; n     Max = max(min(tmp + i + 2, n), Max); n   } n   printf( %d , Max); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[105][105], c[105], r[105]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) cin >> a[i][j]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       c[j] += a[i][j]; n       r[i] += a[i][j]; n     } n   int co = 0; n   set<int> sc, sr; n   set<int>::iterator it; n   while (co <= 10) { n     for (int i = 1; i <= n; i++) n       if (r[i] < 0) { n         if (sr.find(i) != sr.end()) n           sr.erase(sr.find(i)); n         else n           sr.insert(i); n         r[i] = -r[i]; n         for (int j = 1; j <= m; j++) c[j] -= 2 * a[i][j]; n         for (int j = 1; j <= m; j++) a[i][j] = -a[i][j]; n       } n     for (int j = 1; j <= m; j++) n       if (c[j] < 0) { n         if (sc.find(j) != sc.end()) n           sc.erase(sc.find(j)); n         else n           sc.insert(j); n         c[j] = -c[j]; n         for (int i = 1; i <= n; i++) r[i] -= 2 * a[i][j]; n         for (int i = 1; i <= n; i++) a[i][j] = -a[i][j]; n       } n     co++; n   } n   cout << sr.size() <<    ; n   for (it = sr.begin(); it != sr.end(); it++) cout << *it <<    ; n   cout << endl; n   cout << sc.size() <<    ; n   for (it = sc.begin(); it != sc.end(); it++) cout << *it <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 2e5 + 5; n const double pi = acos(-1.0); n long long addM(long long a, long long b) { return (a + b) % MOD; } n long long multM(long long a, long long b) { return (a * b) % MOD; } n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res *= a; n     a *= a; n     b >>= 1; n   } n   return res; n } n long long ModInverse(long long n) { return binpow(n, MOD - 2); } n vector<long long> findFact() { n   vector<long long> fact(N); n   fact[0] = 1; n   for (long long i = 1; i <= N; i++) { n     fact[i] = multM(i, fact[i - 1]); n   } n   return fact; n } n long long ncr(long long n, long long r) { n   vector<long long> fact = findFact(); n   return ((fact[n] * ModInverse(fact[n - r])) % MOD * ModInverse(fact[r])) % n          MOD; n } n vector<bool> findPrime() { n   vector<bool> is_prime(N + 1, true); n   is_prime[0] = false; n   is_prime[1] = false; n   for (long long i = 2; i <= N; i++) { n     if (is_prime[i] && i * i <= N) { n       for (long long j = i * i; j <= N; j += i) is_prime[j] = false; n     } n   } n   return is_prime; n } n vector<bool> segmentedSieveNoPreGen(long long L, long long R) { n   vector<bool> isPrime(R - L + 1, true); n   long long lim = sqrt(R); n   for (long long i = 2; i <= lim; ++i) n     for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i) n       isPrime[j - L] = false; n   if (L == 1) isPrime[0] = false; n   return isPrime; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long tt; n   cin >> tt; n   while (tt--) { n     long long n; n     cin >> n; n     string x, y; n     cin >> x >> y; n     bool check = true; n     for (long long i = 0; i < n; i++) { n       if (x[i] > y[i]) { n         check = false; n       } n     } n     if (check) { n       long long ans = 0; n       for (char c =  a ; c <=  z ; c++) { n         char mn =  z ; n         bool check = false; n         for (long long i = 0; i < n; i++) { n           if (x[i] == c && x[i] != y[i]) { n             check = true; n             mn = min(mn, y[i]); n           } n         } n         for (long long i = 0; i < n; i++) { n           if (x[i] == c && x[i] != y[i]) { n             x[i] = mn; n           } n         } n         if (check) ans++; n       } n       cout << ans <<   n ; n     } else { n       cout <<  -1 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 10; n int a[N], nx[N]; n long long pr[N]; n int main() { n   int n, q; n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i + n] = a[i]; n   for (int i = 1; i <= n + n; i++) pr[i] = pr[i - 1] + a[i]; n   while (q--) { n     long long b; n     scanf( %lld , &b); n     int now = 1; n     int mx = n + n + 1, id; n     for (int i = 1; i <= n + n; i++) { n       while (now <= n + n && pr[i - 1] + b >= pr[now]) now++; n       nx[i] = now; n       if (nx[i] - i >= n) nx[i] = i + n; n       if (nx[i] <= n + n && mx > nx[i] - i) { n         mx = nx[i] - i; n         id = i; n       } n     } n     int ans = n + n; n     for (int i = id; i < nx[id]; i++) { n       int p = i; n       int res = 0; n       while (p < i + n) { n         res++; n         if (nx[p] > i + n && res > 1) { n           if (pr[i + n - 1] - pr[p - 1] + pr[nx[i] - 1] - pr[i - 1] <= b) res--; n         } n         p = nx[p]; n       } n       ans = min(ans, res); n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, q; n char s[N]; n struct node { n   int s, x, z, xz, zy, d; n } tr[N << 2]; n void upd(int o) { n   int S = tr[(o << 1)].s, lx = tr[(o << 1)].x, lz = tr[(o << 1)].z, n       lxz = tr[(o << 1)].xz, lzy = tr[(o << 1)].zy; n   int rx = tr[(o << 1 | 1)].x + S, rz = tr[(o << 1 | 1)].z - 2 * S, n       rxz = tr[(o << 1 | 1)].xz - S, rzy = tr[(o << 1 | 1)].zy - S; n   tr[o].s = S + tr[(o << 1 | 1)].s; n   tr[o].x = max(lx, rx), tr[o].z = max(lz, rz); n   tr[o].xz = max(max(lxz, rxz), lx + rz); n   tr[o].zy = max(max(lzy, rzy), lz + rx); n   tr[o].d = n       max(max(tr[(o << 1)].d, tr[(o << 1 | 1)].d), max(lxz + rx, lx + rzy)); n } n void mdf(int o, int l, int r, int p, int c) { n   if (l == r) { n     tr[o] = {c, c, -2 * c, -c, -c, 0}; n     return; n   } n   int mid = (l + r) >> 1; n   if (p <= mid) n     mdf((o << 1), l, mid, p, c); n   else n     mdf((o << 1 | 1), mid + 1, r, p, c); n   upd(o); n } n int main() { n   scanf( %d%d%s , &n, &q, s + 1); n   for (int i = (1); i <= (2 * n - 2); ++i) n     mdf(1, 1, 2 * n - 2, i, s[i] ==  (  ? 1 : -1); n   printf( %d n , tr[1].d); n   while (q--) { n     int x, y; n     scanf( %d%d , &x, &y); n     swap(s[x], s[y]); n     mdf(1, 1, 2 * n - 2, x, s[x] ==  (  ? 1 : -1); n     mdf(1, 1, 2 * n - 2, y, s[y] ==  (  ? 1 : -1); n     printf( %d n , tr[1].d); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n long long n, k; n bool solveIt(long long d1, long long d2) { n   if ((k - d1 + d2) % 3 != 0) return false; n   long long Y = (k - d1 + d2) / 3; n   long long X = d1 + Y; n   long long Z = Y - d2; n   if (X >= 0 && Y >= 0 && Z >= 0 && X <= k && Y <= k && Z <= k && n       X <= (n / 3) && Y <= (n / 3) && Z <= (n / 3) && abs(X - Y) == abs(d1) && n       abs(Y - Z) == abs(d2)) n     return true; n   return false; n } n int main() { n   std::ios_base::sync_with_stdio(0); n   long long t, d2, d1; n   cin >> t; n   while (t--) { n     bool flg = false; n     cin >> n >> k >> d1 >> d2; n     if (n % 3 != 0) { n       cout <<  no  << endl; n       continue; n     } n     if (solveIt(d1, d2)) flg = true; n     if (solveIt(d1, -d2)) flg = true; n     if (solveIt(-d1, d2)) flg = true; n     if (solveIt(-d1, -d2)) flg = true; n     if (flg) n       cout <<  yes  << endl; n     else n       cout <<  no  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   vector<pair<long long, long long> > v; n   for (int i = 0; i < m; i++) { n     long long a, b; n     cin >> b >> a; n     v.push_back(make_pair(a, b)); n   } n   sort(v.rbegin(), v.rend()); n   long long total = 0, i = 0, count = 0; n   while (i < m && (count + v[i].second) <= n) { n     total += v[i].first * v[i].second; n     count += v[i].second; n     i++; n   } n   if (i != m) total += v[i].first * (n - count); n   cout << total << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int MAX = 1000005; n int SetBit(int n, int x) { return n | (1 << x); } n int ClearBit(int n, int x) { return n & ~(1 << x); } n int ToggleBit(int n, int x) { return n ^ (1 << x); } n bool CheckBit(int n, int x) { return (bool)(n & (1 << x)); } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int w, y, max; n   cin >> w >> y; n   int a; n   if (w > y) { n     max = w; n   } else if (w == y) { n     max = w; n   } else { n     max = y; n   } n   if ((w == 6 && y == 6)) { n     cout <<  1  n          <<  /  n          <<  6  << endl; n   } else if ((w == 6 && (y == 1 || y == 2 || y == 3 || y == 4 || y == 5))) { n     cout <<  1  n          <<  /  n          <<  6  << endl; n   } else if ((y == 6 && (w == 1 || w == 2 || w == 3 || w == 4 || w == 5))) { n     cout <<  1  n          <<  /  n          <<  6  << endl; n   } else { n     a = 6 - max + 1; n     if (a == 2) { n       cout <<  1  n            <<  /  n            <<  3  << endl; n     } n     if (a == 3) { n       cout <<  1  n            <<  /  n            <<  2  << endl; n     } n     if (a == 4) { n       cout <<  2  n            <<  /  n            <<  3  << endl; n     } n     if (a == 5 || a == 1) { n       cout << a <<  /  n            <<  6  << endl; n     } n     if (a == 6) { n       cout <<  1  n            <<  /  n            <<  1  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int max(int &a, int &b) { return (a > b ? a : b); } n unsigned long long max(unsigned long long &a, unsigned long long &b) { n   return (a > b ? a : b); n } n int min(int &a, int &b) { return (a < b ? a : b); } n long long int bits_needed(long long int val) { n   long long int count = 0; n   while (val) count++, val >>= 1; n   return count; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 0, n = 0, i = 0; n   long long int val = 0, prev = 0, ans = 0; n   cin >> t; n   while (t-- > 0) { n     ans = 0; n     cin >> n; n     cin >> prev; n     for (i = 1; i < n; i++) { n       cin >> val; n       if (val < prev) { n         ans = max(ans, bits_needed(prev - val)); n       } else n         prev = val; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d, sum, ans; n char s[105]; n int main() { n   scanf( %d %d , &n, &d); n   for (int i = 0; i < d; i++) { n     scanf( %s , s); n     bool ok = true; n     for (int j = 0; j < n; j++) n       if (s[j] ==  0 ) ok = false; n     if (ok) n       sum = 0; n     else n       sum++, ans = max(ans, sum); n   } n   printf( %d n , ans); n   return 0; n } n