#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool chmax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n inline bool chmin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n const int INF = 1e9; n struct UnionFind { n   vector<int> par; n   vector<int> rank; n   vector<long long> Size; n   UnionFind(int n = 1) { init(n); } n   void init(int n = 1) { n     par.resize(n + 1); n     rank.resize(n + 1); n     Size.resize(n + 1); n     for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; n   } n   int root(int x) { n     if (par[x] == x) { n       return x; n     } else { n       int r = root(par[x]); n       return par[x] = r; n     } n   } n   bool issame(int x, int y) { return root(x) == root(y); } n   bool merge(int x, int y) { n     x = root(x); n     y = root(y); n     if (x == y) return false; n     if (rank[x] == rank[y]) ++rank[x]; n     par[y] = x; n     Size[x] += Size[y]; n     return true; n   } n   long long size(int x) { return Size[root(x)]; } n }; n long long N, Q; n long long node[150000][27]; n long long subtree[150000][27]; n int p[150000]; n int tmpp[150000]; n vector<int> children[150000]; n int val[150000]; n int tmpval[150000]; n void f(int now) { n   if (children[now].size() == 0) { n     for (int i = 0; i < 27; i++) { n       subtree[now][i] = node[now][i]; n     } n   } n   if (children[now].size() == 1) { n     for (int i = 0; i < 27; i++) { n       subtree[now][i] = node[now][i] + subtree[children[now][0]][i]; n     } n   } n   if (children[now].size() == 2) { n     int num[2] = {0, 0}; n     for (int i = 0; i < 2; i++) { n       for (int j = 0; j < 27; j++) { n         num[i] += subtree[children[now][i]][j]; n       } n     } n     if (num[0] != num[1]) { n       for (int i = 0; i < 27; i++) subtree[now][i] = -INF; n     } else { n       int tmpnum = num[0]; n       for (int i = 0; i < 26; i++) { n         subtree[now][i] = n             max(subtree[children[now][0]][i], subtree[children[now][1]][i]); n         tmpnum -= subtree[now][i]; n       } n       if (tmpnum < 0) { n         for (int i = 0; i < 27; i++) subtree[now][i] = -INF; n       } else { n         subtree[now][26] = tmpnum; n         for (int i = 0; i < 27; i++) { n           subtree[now][i] += node[now][i]; n         } n       } n     } n   } n } n void dfs(int now) { n   cerr <<  ---dfs:   << now << endl; n   cerr <<  children:  ; n   for (auto tmp : children[now]) { n     cerr << tmp <<    ; n   } n   cerr << endl; n   for (auto tmp : children[now]) dfs(tmp); n } n UnionFind uni; n void print() { n   for (int i = 0; i < N; i++) { n     if (uni.root(i) != i) continue; n     cerr <<  -------------  << i <<  -------------  << endl; n     for (int j = 0; j < 27; j++) { n       cerr << subtree[i][j] <<    ; n     } n     cerr << endl; n   } n } n int main() { n   cin >> N >> Q; n   p[0] = -1; n   for (int i = 1; i < N; i++) { n     cin >> p[i]; n     p[i]--; n     char tmp; n     cin >> tmp; n     if (tmp ==  ? ) n       tmpval[i] = 26; n     else n       tmpval[i] = (int)(tmp -  a ); n     val[i] = 26; n     children[p[i]].push_back(i); n   } n   uni.init(N); n   for (int i = 0; i < N; i++) { n     if (children[i].size() == 1) { n       uni.merge(i, children[i][0]); n     } n   } n   for (int i = 1; i < N; i++) { n     node[uni.root(i)][val[i]]++; n   } n   for (int i = 0; i < N; i++) { n     tmpp[i] = p[i]; n     p[i] = -1; n   } n   for (int i = 0; i < N; i++) { n     if (children[i].size() == 2) { n       p[children[i][0]] = uni.root(i); n       p[children[i][1]] = uni.root(i); n     } n   } n   for (int i = 0; i < N; i++) children[i].clear(); n   for (int i = 0; i < N; i++) { n     if (p[i] != -1) { n       children[p[i]].push_back(i); n     } n   } n   for (int i = N - 1; i >= 0; i--) { n     if (uni.root(i) == i) f(i); n   } n   if (subtree[0][0] < 0) { n     for (int q = 0; q < Q; q++) { n       cout <<  Fou  << endl; n     } n     return 0; n   } n   for (int i = 1; i < N; i++) { n     val[i] = tmpval[i]; n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < 27; j++) { n       subtree[i][j] = 0; n       node[i][j] = 0; n     } n   } n   for (int i = 1; i < N; i++) { n     node[uni.root(i)][val[i]]++; n   } n   for (int i = N - 1; i >= 0; i--) { n     if (uni.root(i) == i) f(i); n   } n   for (int q = 0; q < Q; q++) { n     int v; n     char tmp; n     cin >> v >> tmp; n     v--; n     int c; n     if (tmp ==  ? ) n       c = 26; n     else n       c = (int)(tmp -  a ); n     int now = uni.root(v); n     node[now][val[v]]--; n     val[v] = c; n     node[now][val[v]]++; n     int nownode = now; n     while (true) { n       f(nownode); n       if (p[nownode] == -1) break; n       nownode = p[nownode]; n     } n     if (subtree[0][0] < 0) { n       cout <<  Fou  << endl; n     } else { n       cout <<  Shi  ; n       long long ans = 0; n       for (long long i = 0; i < 26; i++) { n         ans += (i + 1) * (subtree[0][i] + subtree[0][26]); n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n template <class _, class __> n bool checkmax(_ &a, __ b) { n   return a < b ? a = b, true : false; n } n template <class _, class __> n bool checkmin(_ &a, __ b) { n   return a > b ? a = b, true : false; n } n using namespace std; n const int INF = 1e9; n struct node { n   int x, p; n   bool operator<(const node &a) const { return x < a.x; } n } A[200086]; n int n, c, m; n stack<int> stk; n int nxt[200086]; n int main() { n   cin >> n >> c >> m; n   for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) { n     scanf( %d%d , &A[i].x, &A[i].p); n   } n   A[0] = (node){0, 0}; n   A[++m] = (node){n, INF}; n   sort(A, A + m + 1); n   for (register int i = (m), i_end_ = (0); i >= i_end_; --i) { n     while (!stk.empty() && A[stk.top()].p >= A[i].p) stk.pop(); n     nxt[i] = stk.empty() ? -1 : stk.top(); n     stk.push(i); n   } n   int rest = c; n   long long ans = 0; n   for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) { n     if (rest < A[i].x - A[i - 1].x) { n       puts( -1 ); n       return EXIT_SUCCESS; n     } n     if (i == m) break; n     rest -= A[i].x - A[i - 1].x; n     if (nxt[i] != -1) { n       int dis = A[nxt[i]].x - A[i].x; n       if (rest >= dis) continue; n       ans += 1ll * (min(dis, c) - rest) * A[i].p; n       rest = min(dis, c); n     } else { n       if (rest >= A[m].x - A[i].x) continue; n       ans += 1ll * (min(A[m].x - A[i].x, c) - rest) * A[i].p; n       rest = min(A[m].x - A[i].x, c); n     } n   } n   printf( %I64d n , ans); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int len, star = 0, question = 0, k = 0, n = 0; n   cin >> s; n   cin >> k; n   len = s.length(); n   for (int i = 0; i < len; i++) { n     if (s[i] ==  ? ) { n       question++; n     } n     if (s[i] ==  * ) { n       star++; n     } n   } n   n = len - (star + question); n   if (n == k) { n     for (int i = 0; i < len; i++) { n       if (s[i] !=  ?  && s[i] !=  * ) { n         cout << s[i]; n       } n     } n   } else if (n < k && star < 1) { n     cout <<  Impossible ; n   } else if (n > k && n - star - question > k) { n     cout <<  Impossible ; n   } else { n     if (n > k) { n       for (int i = 0; i < len; i++) { n         if (s[i] !=  ?  && s[i] !=  * ) { n           if (i + 1 < len && (s[i + 1] ==  ?  || s[i + 1] ==  * ) && n > k) { n             n--; n           } else { n             cout << s[i]; n           } n         } n       } n     } else { n       for (int i = 0; i < len; i++) { n         if (s[i] !=  ?  && s[i] !=  * ) { n           if (i + 1 < len && s[i + 1] ==  * ) { n             cout << s[i]; n             while (n < k) { n               cout << s[i]; n               n++; n             } n           } else { n             cout << s[i]; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const long double PI2 = atan2(1.L, 0.L); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   long double r; n   cin >> n >> r; n   long double res = n       r * r * n * sin(PI2 / n) * sin(2 * PI2 / n) / sin(3 * PI2 / n); n   cout << fixed << setprecision(10) << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, A[100], B[100]; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> A[i]; n   for (int i = 0; i < k; i++) cin >> B[i]; n   if (k > 1) { n     cout <<  Yes n ; n     return 0; n   } n   for (int i = 0; i < n; i++) n     if (!A[i]) A[i] = B[0]; n   for (int i = 1; i < n; i++) n     if (A[i] < A[i - 1]) { n       cout <<  Yes n ; n       return 0; n     } n   cout <<  No n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   string num; n   cin >> num; n   num = num.substr(num.length() - x, x); n   cout << count(num.begin(), num.end() - y - 1,  1 ) + n               count(num.end() - y, num.end(),  1 ) + n               (*(num.end() - y - 1) ==  1  ? 0 : 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e6 + 7; n int n; n long long dp[2][maxn]; n int main() { n   cin >> n; n   int now = 1; n   dp[0][1] = 1; n   dp[0][2] = 1; n   long long ans = 0; n   ans += dp[0][n]; n   for (int i = 1; i <= 19; i++) { n     memset(dp[now], 0, sizeof(dp[now])); n     for (int j = (1 << (i)) - 1; j < (1 << (i + 1)) - 1; j++) { n       if (dp[now ^ 1][j] == 0) continue; n       for (int l = (1 << (i)) - 1; l < (1 << (i + 1)) - 1; l++) { n         if (j + l + 1 < maxn && l % 2 == 0) n           dp[now][j + l + 1] += dp[now ^ 1][j] * dp[now ^ 1][l]; n       } n     } n     ans += dp[now][n]; n     now ^= 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse2 ) n using namespace std; n const int N = 2020; n namespace Gause { n static const int N = ::N; n int equ, var; n bitset<N> a[N]; n int x[N]; n int free_x[N]; n int free_num; n int l[N]; n void ini(int n) { n   for (int i = (0); i < (n); ++i) x[i] = 0; n   for (int i = (0); i < (n); ++i) a[i].reset(); n } n int Gauss() { n   int max_r, col, k; n   free_num = 0; n   for (k = 0, col = 0; k < equ && col < var; k++, col++) { n     max_r = k; n     for (int i = k + 1; i < equ; i++) { n       if (abs(a[i][col]) > abs(a[max_r][col])) max_r = i; n     } n     if (a[max_r][col] == 0) { n       k--; n       free_x[free_num++] = col; n       continue; n     } n     l[k] = col; n     if (max_r != k) { n       swap(a[k], a[max_r]); n     } n     for (int i = k + 1; i < equ; i++) { n       if (a[i][col] != 0) a[i] ^= a[k]; n     } n   } n   for (int i = k; i < equ; i++) { n     if (a[i][col] != 0) return -1; n   } n   for (int i = k - 1; i >= 0; i--) { n     int t = l[i]; n     x[t] = a[i][var]; n     for (int j = t + 1; j < var; j++) x[t] ^= (a[i][j] & x[j]); n   } n   return 0; n } n }  // namespace Gause n int T, n, m, u, v; n bool du[N], vis[N][N]; n int main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   cin >> T; n   for (int cas = (0); cas < (T); ++cas) { n     cin >> n >> m; n     Gause ::ini(n); n     for (int i = (1); i < (n + 1); ++i) n       for (int j = (1); j < (n + 1); ++j) vis[i][j] = 0; n     for (int i = (1); i < (n + 1); ++i) du[i] = 0; n     for (int i = (1); i < (m + 1); ++i) { n       cin >> u >> v; n       du[u] ^= 1; n       du[v] ^= 1; n       vis[u][v] = vis[v][u] = 1; n     } n     Gause ::equ = Gause ::var = n; n     for (int i = (1); i < (n + 1); ++i) { n       vis[i][i] = du[i]; n       for (int j = (1); j < (n + 1); ++j) Gause ::a[i - 1][j - 1] = vis[i][j]; n       Gause ::a[i - 1][n] = du[i]; n     } n     Gause::Gauss(); n     bool Vis[2] = {0}; n     for (int i = (1); i < (n + 1); ++i) Vis[Gause::x[i - 1]] = 1; n     if (Vis[0] && Vis[1]) { n       cout << 2 <<   n ; n     } else { n       cout << 1 <<   n ; n       if (Vis[1]) n         for (int i = (1); i < (n + 1); ++i) Gause::x[i - 1] = 0; n     } n     for (int i = (1); i < (n + 1); ++i) cout << Gause::x[i - 1] + 1 <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long double EPS = 0.000000001; n const long long INF64 = 1000000000000000000; n const long long INF32 = 2000000000; n bool iss_pt_in_triangle(pair<long long, long long> a, n                         pair<long long, long long> b, n                         pair<long long, long long> c, n                         pair<long long, long long> point) { n   long long x1 = a.first, x2 = b.first, x3 = c.first, x0 = point.first; n   long long y1 = a.second, y2 = b.second, y3 = c.second, y0 = point.second; n   long long aa = (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0); n   long long bb = (x2 - x0) * (y3 - y2) - (x3 - x2) * (y2 - y0); n   long long cc = (x3 - x0) * (y1 - y3) - (x1 - x3) * (y3 - y0); n   if (aa == 0 || bb == 0 || cc == 0) return 1; n   if (aa >= 0 && bb >= 0 && cc >= 0) return 1; n   if (aa <= 0 && bb <= 0 && cc <= 0) return 1; n   return 0; n } n bool iss_ll(long long &__1, long long &__2) { return INF64 / __1 >= __2; } n bool equal(long double _1, long double _2) { return (abs(_1 - _2) < EPS); } n bool iss_sqr(long long &__1) { n   long long __2 = sqrt((long double)__1); n   return __2 * __2 == __1; n }; n bool iss_prime(long long __1) { n   for (long long i = 2; i * i <= __1; ++i) n     if (!(__1 % i)) return 0; n   return 1; n } n long long gcd(long long __1, long long __2) { n   while (__1 && __2) n     if (__1 > __2) n       __1 = __1 % __2; n     else n       __2 = __2 % __1; n   return __1 + __2; n } n long long lcm(long long &__1, long long &__2) { n   return __1 * __2 / (gcd(__1, __2)); n } n long long sq_cube(long long x) { n   if (x == 0) return 1; n   long long l = 0, r = 2e6; n   while (l + 1 < r) { n     long long m = (l + r) / 2; n     if (m * m * m > x) n       r = m; n     else n       l = m; n   } n   return l; n } n set<long long> G[100100]; n vector<long long> GR[100100]; n bool used[100100]; n void dfs(long long v) { n   if (used[v]) return; n   used[v] = 1; n   for (long long i : G[v]) dfs(i); n } n long long n, k; n long long step(long long k) { n   long long res = 1; n   for (long long i = 0; i < k; ++i) res *= 3; n   return res; n } n long long dfss(long long v, long long deep) { n   long long ans = deep; n   used[v] = 1; n   if (deep != k) { n     if ((GR[v].size() < 4 && deep > 0 && deep != k) || n         (deep == 0 && GR[v].size() < 3)) { n       cout <<  No  n            <<   n ; n       exit(0); n     } n   } n   for (long long i : GR[v]) { n     if (used[i]) continue; n     ans = max(dfss(i, deep + 1), ans); n   } n   if (ans != k) { n     cout <<  No  n          <<   n ; n     exit(0); n   } n   return ans; n } n signed main(signed argc, const char *argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   if (k > 20) { n     cout <<  No  n          <<   n ; n     return 0; n   } n   for (long long i = 1; i < n; ++i) { n     long long x, y; n     cin >> x >> y; n     G[x].insert(y); n     G[y].insert(x); n     GR[x].push_back(y); n     GR[y].push_back(x); n   } n   dfs(1); n   for (long long i = 1; i <= n; ++i) { n     if (!used[i]) { n       cout <<  No  n            <<   n ; n       return 0; n     } n   } n   vector<long long> VEC; n   long long k1 = k; n   long long pos = 0; n   for (long long i = 1; i <= n; ++i) n     if (G[i].size() == 1) VEC.push_back(i); n   while (k--) { n     if (VEC.size() == 0) { n       cout <<  No  n            <<   n ; n       return 0; n     } n     if (k == 0) { n       pos = *G[VEC.front()].begin(); n     } n     for (long long i : VEC) { n       G[*G[i].begin()].erase(i); n       G[i].clear(); n     } n     VEC.clear(); n     for (long long i = 1; i <= n; ++i) { n       if (G[i].size() == 1) VEC.push_back(i); n       if (G[i].size() == 2) { n         cout <<  No  n              <<   n ; n         return 0; n       } n     } n   } n   memset(used, 0, sizeof(used)); n   k = k1; n   dfss(pos, 0); n   cout <<  Yes  n        <<   n ; n } n


#include <bits/stdc++.h> n const int maxn = 2e5 + 5; n using namespace std; n int rd() { n   int x = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar(); n   return x * f; n } n int n, q, cnt, id, now; n map<long long, int> mp; n map<pair<int, int>, int> ans; n vector<pair<int, int> > a[maxn]; n vector<pair<int, int> >::iterator it; n int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } n int get(long long x) { n   if (!mp.count(x)) mp[x] = ++id; n   return mp[x]; n } n pair<int, int> fac(int x, int y) { n   int z = gcd(x, y); n   return make_pair(x / z, y / z); n } n int main() { n   n = rd(); n   for (int i = 1, op, x, y; i <= n; i++) { n     op = rd(); n     x = rd(); n     y = rd(); n     long long r = 1ll * x * x + 1ll * y * y; n     if (op == 1) { n       ++cnt; n       now = get(r); n       for (int i = 0; i < ((int)a[now].size()); i++) n         ans[fac(a[now][i].first + x, a[now][i].second + y)] += 2; n       ans[fac(x, y)]++; n       a[now].push_back(make_pair(x, y)); n     } else if (op == 2) { n       --cnt; n       now = get(r); n       for (int i = 0; i < ((int)a[now].size()); i++) n         if (a[now][i] != make_pair(x, y)) n           ans[fac(a[now][i].first + x, a[now][i].second + y)] -= 2; n       ans[fac(x, y)]--; n       it = a[now].begin(); n       while (*it != make_pair(x, y)) ++it; n       a[now].erase(it); n     } else n       printf( %d n , cnt - ans[fac(x, y)]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   long long q; n   cin >> q; n   for (int i = 0; i < (int)(q); ++i) { n     long long n, ans = 0; n     cin >> n; n     vector<int> a(n); n     for (int j = 0; j < (int)(n); ++j) { n       cin >> a[j]; n     } n     sort((a).rbegin(), (a).rend()); n     for (int j = 0; j < (int)(n); ++j) { n       if (a[j] > j) { n         ans++; n       } else { n         break; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long int, long long int> > arr; n bool fun(pair<long long int, long long int> fi, n          pair<long long int, long long int> se) { n   if (fi.first < se.first) { n     return true; n   } else n     return false; n } n void solve() { n   long long int i, j, k, l, m, n, x; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> x; n     arr.push_back(make_pair(x, i + 1)); n   } n   sort(arr.begin(), arr.end(), fun); n   if (n <= 3) { n     cout << 1 << endl; n     return; n   } n   long long int d = arr[1].first - arr[0].first; n   long long int count = 0; n   long long int index = arr[0].second; n   for (i = 0; i < n; i++) { n     if (arr[i].first != arr[0].first + (i - count) * d) { n       count++; n       index = arr[i].second; n       if (count > 1) { n         break; n       } n     } n   } n   if (count <= 1) { n     cout << index << endl; n     return; n   } n   d = arr[2].first - arr[0].first; n   count = 1; n   index = arr[1].second; n   for (i = 3; i < n; i++) { n     if (arr[i].first != arr[0].first + (i - count) * d) { n       count++; n       index = arr[i].second; n       if (count > 1) { n         break; n       } n     } n   } n   if (count <= 1) { n     cout << index << endl; n     return; n   } n   d = arr[2].first - arr[1].first; n   count = 1; n   index = arr[0].second; n   for (i = 3; i < n; i++) { n     if (arr[i].first != arr[1].first + (i - count) * d) { n       count++; n       index = arr[i].second; n       if (count > 1) { n         break; n       } n     } n   } n   if (count <= 1) { n     cout << index << endl; n     return; n   } n   cout << -1 << endl; n   return; n } n int main() { n   long long int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, b, a[105]; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     b += a[i]; n   } n   if (b != 0) { n     cout <<  YES n1 n1   << n; n     return 0; n   } n   for (i = 1; i <= n; i++) { n     if (a[i] != 0) { n       break; n     } n   } n   if (i <= n) { n     cout <<  YES n2 n1   << i << endl; n     cout << i + 1 <<     << n; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, CountDog[400]; n char x[100005]; n int main() { n   scanf( %d , &n); n   if (n == 1) { n     printf( Yes ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     cin >> x[i]; n     CountDog[x[i]]++; n   } n   for (int i = 1; i <= n; i++) n     if (CountDog[x[i]] >= 2) { n       printf( Yes ); n       return 0; n     } n   printf( No ); n } n


#include <bits/stdc++.h> n using namespace std; n string to_string(string s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int md = 998244353; n inline void add(int &x, int y) { n   x += y; n   if (x >= md) { n     x -= md; n   } n } n inline void sub(int &x, int y) { n   x -= y; n   if (x < 0) { n     x += md; n   } n } n inline int mul(int x, int y) { return (long long)x * y % md; } n inline int power(int x, int y) { n   int result = 1; n   for (; y; y >>= 1, x = mul(x, x)) { n     if (y & 1) { n       result = mul(result, x); n     } n   } n   return result; n } n template <typename T> n class fenwick_t { n  public: n   vector<T> fenw; n   int n; n   fenwick_t(int n) : n(n) { fenw.resize(n); } n   void modify(int x, T value) { n     while (x < n) { n       fenw[x] += value; n       x |= x + 1; n     } n   } n   T query(int x) { n     T result{}; n     while (x >= 0) { n       result += fenw[x]; n       x = (x & x + 1) - 1; n     } n     return result; n   } n   T get(int l, int r) { return query(r) - query(l - 1); } n }; n int main() { n   int n; n   scanf( %d , &n); n   if (n == 1) { n     puts( 0 ); n     return 0; n   } n   vector<int> w(n + 1); n   w[1] = 0; n   w[2] = 1; n   for (int i = 3; i <= n; ++i) { n     w[i] = mul(i - 1, w[i - 1] + w[i - 2]); n   } n   vector<int> fact(n + 1); n   fact[0] = 1; n   for (int i = 1; i <= n; ++i) { n     fact[i] = mul(fact[i - 1], i); n   } n   vector<vector<int>> f(n + 1, vector<int>(n + 1)); n   for (int i = 0; i <= n; ++i) { n     f[i][0] = fact[i]; n     for (int j = 1; j <= i; ++j) { n       f[i][j] = f[i][j - 1]; n       sub(f[i][j], f[i - 1][j - 1]); n     } n   } n   vector<vector<int>> a(n, vector<int>(n)); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       scanf( %d , &a[i][j]); n       --a[i][j]; n     } n   } n   int answer = 0; n   { n     fenwick_t<int> fenw(n); n     for (int i = 0; i < n; ++i) { n       fenw.modify(i, 1); n     } n     int coef = power(w[n], n - 1); n     for (int i = 0; i < n; ++i) { n       fenw.modify(a[0][i], -1); n       add(answer, mul(fact[n - i - 1], mul(coef, fenw.query(a[0][i] - 1)))); n     } n   } n   for (int i = 1; i < n; ++i) { n     fenwick_t<int> foo(n), bar(n); n     vector<int> cnt(n); n     int current = 0; n     auto insert = [&](int x) { n       if (++cnt[x] == 2) { n         ++current; n         foo.modify(x, 1); n       } n     }; n     auto get = [&](int x, int y) { return y < 0 || y > x ? 0 : f[x][y]; }; n     int coef = power(w[n], n - i - 1); n     for (int j = n - 1; ~j; --j) { n       insert(a[i - 1][j]); n       insert(a[i][j]); n       bar.modify(a[i][j], 1); n       int u = foo.query(a[i][j] - 1), v = bar.query(a[i][j] - 1) - u; n       add(answer, n           mul(coef, n               mul(u, get(n - j - 1, current - (cnt[a[i - 1][j]] == 2) - 1)))); n       add(answer, n           mul(coef, mul(v, get(n - j - 1, current - (cnt[a[i - 1][j]] == 2))))); n       if (cnt[a[i - 1][j]] == 2 && a[i - 1][j] < a[i][j]) { n         sub(answer, mul(coef, get(n - j - 1, current - 2))); n       } n     } n   } n   printf( %d n , answer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[200001]; n long long int q[200001]; n long long int pre[200001]; n long long int binarysearch(long long int n, long long int p) { n   long long int low = 1, high = n; n   while (low <= high) { n     long long int mid = (low + high) / 2; n     if (pre[mid] <= p) n       low = mid + 1; n     else n       high = mid - 1; n   } n   return high; n } n int main() { n   long long int n, q1; n   cin >> n >> q1; n   for (long long int i = 1; i <= n; i++) cin >> a[i]; n   for (long long int i = 1; i <= q1; i++) cin >> q[i]; n   pre[1] = a[1]; n   for (long long int i = 2; i <= n; i++) pre[i] = a[i] + pre[i - 1]; n   long long int cal = 0; n   for (long long int i = 1; i <= q1; i++) { n     long long int ser = q[i] + cal; n     long long int ans = binarysearch(n, ser); n     if (ans < n) n       cout << n - ans <<   n ; n     else n       cout << n <<   n ; n     cal += q[i]; n     if (ans == n) cal = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, cost = 0, r, min = 100000000; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (int i = 1; i <= a[n - 1]; i++) { n     t = i; n     for (int j = 0; j < n; j++) { n       if (a[j] - t > 1) { n         cost = cost + a[j] - (t + 1); n       } else if (t - a[j] > 1) { n         cost = cost + t - 1 - a[j]; n       } n     } n     if (cost < min) { n       min = cost; n       r = t; n     } n     cost = 0; n   } n   cout << r <<     << min; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m; n   cin >> n >> m; n   if (m == 0) { n     cout <<  YES  << endl; n     return 0; n   } n   vector<long long int> v(m); n   for (long long int i = 0; i < m; cin >> v[i++]) n     ; n   sort(v.begin(), v.end()); n   if (v[0] == 1 || v[m - 1] == n) { n     cout <<  NO  << endl; n     return 0; n   } n   int ind = 1, ans = 0; n   for (int i = 0; i < (m - 2); i++) { n     if ((v[i] == (v[i + 1] - 1)) && (v[i + 1] == (v[i + 2] - 1))) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1010][1010]; n vector<int> arr; n int m; n int solve(int idx, int mod) { n   if (idx == (int)arr.size()) n     return (mod == 0); n   else if (dp[idx][mod] != -1) n     return dp[idx][mod]; n   int ret = solve(idx + 1, mod); n   if (ret) return (dp[idx][mod] = ret); n   ret = solve(idx + 1, (mod + arr[idx]) % m); n   return (dp[idx][mod] = ret); n } n int main() { n   ios_base::sync_with_stdio(false); n   for (int i = (int)(0); i < (int)(1010); i++) n     for (int j = (int)(0); j < (int)(1010); j++) dp[i][j] = -1; n   int n; n   cin >> n >> m; n   arr.resize(n); n   for (int i = (int)(0); i < (int)(n); i++) cin >> arr[i]; n   if (n > m) n     cout <<  YES  << endl; n   else { n     int yes = 0; n     for (int i = (int)(0); i < (int)(n); i++) yes |= solve(i + 1, arr[i] % m); n     if (yes) 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 const double PI = acos(-1); n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n long long bigmod(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = (ret * a) % 1000000007; n     b >>= 1; n     a = (a * a) % 1000000007; n   } n   return ret; n } n long long inverse(long long n) { return bigmod(n, 1000000007 - 2); } n long long add(long long a, long long b) { n   long long ret = a + b; n   if (ret >= 1000000007) ret %= 1000000007; n   return ret; n } n long long subtract(long long a, long long b) { n   long long ret = a - b; n   if (ret < 0) ret += 1000000007; n   return ret; n } n long long mult(long long a, long long b) { n   long long ret = a * b; n   if (ret >= 1000000007) ret %= 1000000007; n   return ret; n } n bool checkBit(int n, int i) { return (n & (1 << i)); } n int setBit(int n, int i) { return (n | (1 << i)); } n int resetBit(int n, int i) { return (n & (~(1 << i))); } n long long a[500010], p[500010]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %lld , &a[i]); n     sum += a[i]; n   } n   sort(a, a + n); n   long long avg = sum / n, rem = sum % n; n   for (int i = 0; i < n; ++i) p[i] = avg; n   for (int i = n - 1; rem; --i) { n     --rem; n     ++p[i]; n   } n   long long up = 0, down = n - 1, days = 0; n   for (int i = 0; i < n; ++i) { n     if (a[i] <= p[i]) { n       up = i; n       days += p[i] - a[i]; n     } else n       break; n   } n   for (int i = n - 1; i >= 0; --i) { n     if (a[i] >= p[i]) n       down = i; n     else n       break; n   }; n   ; n   ; n   if (k >= days) { n     printf( %lld n , p[n - 1] - p[0]); n     return 0; n   } n   long long mn = -1, mx = -1; n   sum = 0, days = 0; n   for (int i = 0; i < up + 1; ++i) { n     ++sum; n     long long x = a[i], y = min(a[i + 1], p[i + 1]); n     days += sum * (y - x); n     ; n     if (days == k) { n       mn = y; n       break; n     } else if (days > k) { n       days -= sum * (y - x); n       rem = k - days; n       ; n       mn = a[i] + rem / sum; n       break; n     } n   }; n   sum = 0, days = 0; n   for (int i = n - 1; i >= down; --i) { n     ++sum; n     long long x = a[i], y = max(a[i - 1], p[i - 1]); n     days += sum * (x - y); n     ; n     if (days == k) { n       mx = y; n       break; n     } else if (days > k) { n       days -= sum * (x - y); n       rem = k - days; n       ; n       mx = a[i] - rem / sum; n       break; n     } n   }; n   cout << mx - mn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using Long = long long; n vector<vector<int>> G(100010); n int D[100010]; n int dist[100010]; n int P[100010]; n int ep1 = -1, ep1lvl = -1, ep2 = -1, ep2lvl = -1; n void dfs(int u, int p, int lvl) { n   if (lvl > ep1lvl) { n     ep1lvl = lvl; n     ep1 = u; n   } n   for (auto v : G[u]) { n     if (v != p) dfs(v, u, lvl + 1); n   } n } n void dfs1(int u, int p, int lvl) { n   P[u] = p; n   if (lvl > ep2lvl) { n     ep2lvl = lvl; n     ep2 = u; n   } n   for (auto v : G[u]) { n     if (v != p) dfs1(v, u, lvl + 1); n   } n } n int md; n vector<int> path; n void getMid(int u) { n   while (P[u] != -1) { n     path.push_back(u); n     u = P[u]; n   } n   path.push_back(u); n   reverse(path.begin(), path.end()); n } n bool ok = true; n int n, k; n int main() { n   cin >> n >> k; n   memset(D, 0, sizeof(D)); n   for (int i = 0; i < 100000; i++) P[i] = -1, dist[i] = 1 << 30; n   int first = 0; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     u--, v--; n     if (!i) first = u; n     G[u].push_back(v); n     G[v].push_back(u); n     D[u]++, D[v]++; n   } n   dfs(first, -1, 1); n   dfs1(ep1, -1, 1); n   if (ep2lvl <= k) { n     puts( No ); n     return 0; n   } n   getMid(ep2); n   md = path[k]; n   queue<int> Q; n   Q.push(md); n   dist[md] = 0; n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     if (u == md) { n       if (D[u] < 3) ok = false; n     } else { n       if (dist[u] != k && (D[u] - 1) < 3) ok = false; n       if (dist[u] == k && D[u] > 1) ok = false; n     } n     for (int v : G[u]) { n       if (dist[v] == 1 << 30) { n         dist[v] = dist[u] + 1; n         Q.push(v); n       } n     } n   } n   (ok) ? puts( Yes ) : puts( No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   if (e == 0) return 1; n   if (e % 2 == 0) { n     long long t = bigmod(p, e / 2, M); n     return (T)((t * t) % M); n   } n   return (T)(((long long)bigmod(p, e - 1, M) * (long long)(p)) % M); n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n long long seg[4000001], ar[1000001], val[1000001]; n void insert(int idx, int s, int e, int p, int v) { n   if (s == e) { n     seg[idx] = v; n     return; n   } n   int mid = (s + e) / 2; n   if (p <= mid) n     insert(idx * 2 + 1, s, mid, p, v); n   else n     insert(idx * 2 + 2, mid + 1, e, p, v); n   seg[idx] = seg[idx * 2 + 1] + seg[idx * 2 + 2]; n } n long long query(int idx, int s, int e, int p) { n   if (seg[idx] < p) return -1; n   if (s == e) return s; n   int mid = (s + e) / 2; n   if (p <= seg[idx * 2 + 1]) n     return query(idx * 2 + 1, s, mid, p); n   else n     return query(idx * 2 + 2, mid + 1, e, p - seg[idx * 2 + 1]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long a, b, c, d, e, f, g, h = 1, x, y, z; n   cin >> a >> b; n   for (int i = (0); i < (b); ++i) cin >> ar[i]; n   c = 0; n   for (int i = (0); i < (a); ++i) { n     cin >> d; n     if (d == -1) { n       for (int j = (0); j < (b); ++j) { n         e = query(0, 1, 1000000, ar[j] - j); n         if (e == -1) break; n         insert(0, 1, 1000000, e, 0); n       } n     } else { n       c++; n       val[c] = d; n       insert(0, 1, 1000000, c, 1); n     } n   } n   if (seg[0] == 0) n     cout <<  Poor stack!  << endl; n   else { n     for (int i = (1); i < (seg[0] + 1); ++i) { n       e = query(0, 1, 1000000, i); n       cout << val[e]; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int row[1008], col[1008], n, m, a, b, cnt; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n + 1; i++) row[i] = col[i] = true; n   while (m--) { n     cin >> a >> b; n     row[a] = col[b] = false; n   } n   for (int i = 2; i < n; i++) cnt += (row[i] + col[i]); n   if (n % 2) cnt -= (row[n / 2 + 1] && col[n / 2 + 1]); n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream& operator<<(ostream& out, pair<T1, T2> p) { n   out <<  (  << p.first <<  ,  << p.second <<  ) ; n   return out; n } n template <class T1, class T2> n istream& operator>>(istream& in, pair<T1, T2>& p) { n   in >> p.first >> p.second; n   return in; n } n template <class T> n istream& operator>>(istream& in, vector<T>& v) { n   for (T& x : v) in >> x; n   return in; n } n template <class T> n ostream& operator<<(ostream& out, vector<vector<T>>& v) { n   for (vector<T>& x : v) out << x <<   n ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, vector<T>& v) { n   for (T& x : v) out << x <<    ; n   return out; n } n long long gcd(long long a, long long b) { n   if (b > a) swap(a, b); n   return (b ? gcd(b, a % b) : a); n } n using ll = long long; n using pii = pair<int, int>; n using pll = pair<long long, long long>; n using tiii = pair<pair<int, int>, int>; n using vi = vector<int>; n using vl = vector<long long>; n using vvi = vector<vector<int>>; n using vvl = vector<vector<long long>>; n const int h = 1000000007; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.setstate(ios::failbit); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vi v(n); n     cin >> v; n     vi x{v[0]}; n     for (int i = (1); i < (n); i++) { n       if (v[i] == x.back() + 1) n         x.back()++; n       else n         x.push_back(v[i]); n     } n     int y = true; n     for (int i = (1); i < (x.size()); i++) n       if (x[i - 1] < x[i]) y = false; n     cout << (y ?  Yes  :  No ) <<   n ; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n #pragma GCC optimize(2) n using namespace std; n const int maxn = 2e5 + 10; n char s[maxn]; n int N, K; n long long T; n int A[22][22]; n long long DP[1 << 22]; n long long t[22]; n int mask[22]; n int main() { n   scanf( %d %d %lld , &N, &K, &T); n   scanf( %s , s + 1); n   for (int i = 0; i < K; ++i) { n     scanf( %lld , &t[i]); n   } n   for (int i = 0; i < K; ++i) { n     for (int j = 0; j < K; ++j) { n       scanf( %d , &A[i][j]); n     } n   } n   for (int i = 0; i < K; ++i) { n     DP[1 << i] = t[i]; n     mask[i] = -1; n   } n   int S = 0; n   for (int i = 1; i <= N; ++i) { n     int x = s[i] -  A ; n     S |= (1 << x); n     for (int j = 0; j < K; ++j) { n       if (mask[j] >= 0) { n         if ((mask[j] & (1 << j)) == 0 && (mask[j] & (1 << x)) == 0) { n           DP[mask[j]] += A[j][x]; n           DP[mask[j] | (1 << j)] -= A[j][x]; n           DP[mask[j] | (1 << x)] -= A[j][x]; n           DP[mask[j] | (1 << j) | (1 << x)] += A[j][x]; n         } n         mask[j] |= (1 << x); n       } n     } n     mask[x] = 0; n   } n   for (int i = 0; i < K; ++i) { n     for (int s = 0; s < (1 << K); ++s) { n       if (s & (1 << i)) { n         DP[s] += DP[s ^ (1 << i)]; n       } n     } n   } n   long long ret = 0; n   for (int s = 0; s < (1 << K); ++s) { n     if ((s & S) == s && DP[s] <= T && s != S) { n       ++ret; n     } n   } n   printf( %lld n , ret); n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, l, m, n, x, y, z, ans, counting; n int ara[2000]; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> ara[i]; n   } n   sort(ara, ara + n); n   for (i = 0; i < n; i++) { n     if (ara[i] != 0) break; n   } n   for (j = i + 1, counting = 1; j < n; j++) { n     if (ara[j] == ara[j - 1]) { n       counting++; n     } else { n       counting = 1; n     } n     if (counting > 2) { n       printf( -1 ); n       return 0; n     } else if (counting == 2) n       ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int isWinning(string str) { n   int n = str.length(); n   int arr[n + 1][n + 1]; n   for (int i = 0; i <= n; i++) arr[i][i] = 1; n   return arr[1][n]; n } n int main() { n   int n; n   cin >> n; n   int arr[n]; n   long long ans; n   long long sum = 0; n   for (int i = 0; i < (n); ++i) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   sort(arr, arr + n); n   ans = sum; n   if (n - 2 >= 0) { n     for (int i = 0; i < n - 2; i++) { n       ans += sum; n       sum -= arr[i]; n     } n     ans += arr[n - 2]; n     ans += arr[n - 1]; n   } else if (n == 1) n     ans = arr[0]; n   else { n     ans = 2 * sum; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char st[1000010]; n int n, K; n int main() { n   int i, j; n   scanf( %d%d , &n, &K); n   scanf( %s , st + 1); n   for (i = 1; i < n && K; ++i) n     if (st[i] ==  4  && st[i + 1] ==  7 ) { n       if (i % 2) n         st[i + 1] =  4 ; n       else { n         st[i] =  7 ; n         if (i > 1 && st[i - 1] ==  4 ) { n           if (K % 2 == 0) st[i] =  4 ; n           break; n         } n       } n       K--; n     } n   printf( %s n , st + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> go(int x, int d) { n   long long mx = 0; n   for (int i = 1; i <= d; i++) mx += 1ll << i; n   if (mx < x) return vector<int>(); n   return vector<int>(); n } n void solve() { n   int n; n   cin >> n; n   long long x = n - 1; n   long long curr = 1; n   vector<long long> ans; n   while (x > 0) { n     if (curr <= x && x <= 2 * curr) { n       ans.push_back(x - curr); n       break; n     } else if (x <= 4 * curr) { n       ans.push_back(x / 2 - curr); n       ans.push_back(x % 2); n       break; n     } n     ans.push_back(curr); n     curr *= 2; n     x -= curr; n   } n   cout << ((int)ans.size()) <<   n ; n   for (long long i : ans) cout << i <<    ; n   cout <<   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 maxn = 1e5 + 10; n const int INF = 0x3f3f3f3f; n int a[110][110]; n int dp[100][2]; n const int M = 1e5 + 10; n int vis[M], prime[M]; n void prim() { n   memset(vis, 0, sizeof(vis)); n   memset(prime, 0, sizeof(prime)); n   int cun = 1; n   for (int i = 2; i <= M; i++) { n     if (vis[i] == 0) { n       prime[cun++] = i; n     } n     for (int j = 1; j <= cun && prime[j] * i < M; j++) { n       vis[i * prime[j]] = 1; n       if (i % prime[j] == 0) { n         break; n       } n     } n   } n } n int main() { n   int t; n   cin >> t; n   int sum = 0; n   prim(); n   while (t--) { n     long long n, m; n     cin >> n >> m; n     int temp = n + m - 2; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) a[i][j] += i - i + j - j; n     } n     for (int i = 0; i <= (temp / 2); i++) { n       dp[i][0] = 0; n       dp[i][1] = 0; n     } n     if (temp % 2) { n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           int fl = i + j; n           if (fl <= temp / 2) n             dp[fl][a[i][j]]++; n           else n             dp[temp - fl][a[i][j]]++; n         } n       } n       int ans = 0; n       for (int i = 0; i <= temp / 2; i++) { n         ans += min(dp[i][0], dp[i][1]); n       } n       cout << ans << endl; n     } else { n       int ans = 0; n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           int fl = i + j; n           if (fl == temp / 2) continue; n           if (fl < temp / 2) n             dp[fl][a[i][j]]++; n           else { n             dp[temp - fl][a[i][j]]++; n           } n         } n       } n       for (int i = 0; i <= (temp / 2 - 1); i++) { n         ans += min(dp[i][0], dp[i][1]); n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 350009; n long long Q, N, currentS[NMAX], s[NMAX], t[NMAX], l[NMAX], r[NMAX], v[NMAX], n     type[NMAX]; n vector<long long> ts; n map<long long, long long> inverseT; n void read() { n   scanf( %I64d , &Q); n   for (int i = 1; i <= Q; i++) { n     scanf( %I64d , &type[i]); n     if (type[i] == 1) n       scanf( %I64d %I64d , &t[i], &s[i]), ts.push_back(t[i]); n     else if (type[i] == 2) n       scanf( %I64d , &t[i]); n     else { n       scanf( %I64d %I64d %I64d , &l[i], &r[i], &v[i]); n       ts.push_back(l[i]), ts.push_back(r[i]); n     } n   } n   sort(ts.begin(), ts.end()); n   ts.erase(unique(ts.begin(), ts.end()), ts.end()), N = ts.size(); n   for (long long i = 0; i < N; i++) inverseT[ts[i]] = i + 1; n   long long lastVal = ts[N - 1]; n   ts.push_back(lastVal); n   for (int i = 1; i <= Q; i++) n     if (type[i] <= 2) n       t[i] = inverseT[t[i]]; n     else n       l[i] = inverseT[l[i]], r[i] = inverseT[r[i]]; n } n set<long long> currTimes; n long long sum[4 * NMAX], mi[4 * NMAX]; n long long vl[4 * NMAX]; n bool lzy[4 * NMAX]; n long long getLength(long long x, long long y) { return ts[y] - ts[x - 1]; } n void split(long long nod, long long st, long long mij, long long dr, n            long long f1, long long f2) { n   if (lzy[nod] == 0) return; n   lzy[f1] = lzy[f2] = 1; n   vl[f1] = vl[f2] = vl[nod]; n   sum[f1] = 1LL * vl[nod] * getLength(st, mij); n   mi[f1] = min(0LL, sum[f1]); n   sum[f2] = 1LL * vl[nod] * getLength(mij + 1, dr); n   mi[f2] = min(0LL, sum[f2]); n   lzy[nod] = 0; n } n void setValue(long long nod, long long st, long long dr, long long x, n               long long y, long long s) { n   if (x <= st && dr <= y) { n     vl[nod] = s, lzy[nod] = 1; n     sum[nod] = 1LL * s * getLength(st, dr); n     mi[nod] = min(0LL, sum[nod]); n     return; n   } n   long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1; n   split(nod, st, mij, dr, f1, f2); n   if (x <= mij) setValue(f1, st, mij, x, y, s); n   if (mij < y) setValue(f2, mij + 1, dr, x, y, s); n   sum[nod] = sum[f1] + sum[f2]; n   mi[nod] = min(mi[f1], sum[f1] + mi[f2]); n } n long double ansQ = -1.0; n const long double eps = 1e-9; n long long curr; n void query(long long nod, long long st, long long dr, long long x, n            long long y) { n   if (ansQ > -0.5) return; n   if (x <= st && dr <= y) { n     long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1; n     if (st == dr) { n       if (mi[nod] + curr > 0) { n         curr += sum[nod]; n         return; n       } n       long long t1 = ts[st - 1], t2 = ts[st]; n       assert(vl[nod] < 0); n       ansQ = t1 + 1.0 * curr / (-vl[nod]); n       assert(ansQ > -0.5); n       return; n     } n     split(nod, st, mij, dr, f1, f2); n     if (curr + mi[f1] <= 0) { n       query(f1, st, mij, x, y); n       assert(ansQ > -0.5); n     } else if (curr + sum[f1] + mi[f2] <= 0) { n       curr += sum[f1], query(f2, mij + 1, dr, x, y); n       assert(ansQ > -0.5); n     } else n       curr += sum[nod]; n     return; n   } n   long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1; n   split(nod, st, mij, dr, f1, f2); n   if (x <= mij) query(f1, st, mij, x, y); n   if (mij < y) query(f2, mij + 1, dr, x, y); n } n int main() { n   read(); n   for (long long i = 1; i <= Q; i++) { n     if (type[i] == 1) { n       currTimes.insert(t[i]); n       auto it = currTimes.find(t[i]); n       it++; n       long long rgt = N; n       if (it != currTimes.end()) rgt = (*it) - 1; n       setValue(1, 1, N, t[i], rgt, s[i]); n       currentS[t[i]] = s[i]; n       continue; n     } n     if (type[i] == 2) { n       auto it = currTimes.find(t[i]); n       long long s = 0; n       if (it != currTimes.begin()) { n         auto it2 = it; n         it2--; n         s = currentS[*it2]; n       } n       it++; n       long long rgt = N; n       if (it != currTimes.end()) rgt = (*it) - 1; n       setValue(1, 1, N, t[i], rgt, s); n       currTimes.erase(t[i]), currentS[t[i]] = 0; n       continue; n     } n     ansQ = -1.0; n     if (v[i] == 0) { n       printf( %I64d n , ts[l[i] - 1]); n       continue; n     } n     if (l[i] != r[i]) { n       auto it = currTimes.lower_bound(l[i]); n       if (it != currTimes.end() && (*it) < r[i]) n         curr = v[i], query(1, 1, N, *it, r[i] - 1); n     } n     assert(ansQ <= ts[r[i] - 1] + eps); n     cout << setprecision(15) << ansQ <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5; n int d[maxn]; n std::vector<int> G[maxn]; n int dp(int u) { n   if ((int)G[u].size() == 0) { n     return d[u] = 1; n   } else if (d[u]) { n     return d[u]; n   } n   for (int i : G[u]) { n     d[u] += dp(i); n   } n   return d[u]; n } n int c[maxn]; n int main(int argc, char const *argv[]) { n   int n; n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 2; i <= n; ++i) { n     int u; n     cin >> u; n     G[u].push_back(i); n   } n   dp(1); n   for (int i = 1; i <= n; ++i) { n     c[d[i]]++; n   } n   int sum = c[1]; n   int res = 1; n   for (int i = 1; i <= n; ++i) { n     while (i > sum) { n       sum += c[++res]; n     } n     cout << res <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T nextInt() { n   T x = 0, p = 1; n   char ch; n   do { n     ch = getchar(); n   } while (ch <=    ); n   if (ch ==  - ) { n     p = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + (ch -  0 ); n     ch = getchar(); n   } n   return x * p; n } n const int maxN = (int)3e5 + 10; n const int INF = (int)1e9; n const int mod = (int)1e9 + 7; n const long long LLINF = (long long)1e18; n const long double pi = acos(-1.0); n int x[2]; n int y[2]; n int r[2]; n long double d; n long double solve(int xa, int ya, int ra, int xb, int yb, int rb) { n   long double angle = n       2 * acos((rb * 1LL * rb - ra * 1LL * ra - d * d) / (-2 * ra * d)); n   return pi * ra * ra * angle / (2 * pi) - 1LL * ra * ra * sin(angle) / 2; n } n int main() { n   cin >> x[0] >> y[0] >> r[0] >> x[1] >> y[1] >> r[1]; n   d = sqrtl((x[0] - x[1]) * 1LL * (x[0] - x[1]) + n             (y[0] - y[1]) * 1LL * (y[0] - y[1])); n   cout.precision(21); n   if (d >= r[0] + r[1]) { n     cout << 0 <<   n ; n     return 0; n   } n   if (d <= abs(r[0] - r[1])) { n     cout << pi * min(r[0], r[1]) * min(r[0], r[1]) <<   n ; n     return 0; n   } n   cout << solve(x[0], y[0], r[0], x[1], y[1], r[1]) + n               solve(x[1], y[1], r[1], x[0], y[0], r[0]) n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int abss(int x) { return x > 0 ? x : -x; } n int main() { n   int n, m, x1, y1, x2, y2; n   while (scanf( %d %d %d %d %d %d , &n, &m, &x1, &y1, &x2, &y2) == 6) { n     int chax = abss(x1 - x2); n     int chay = abss(y1 - y2); n     bool ansflag = 0; n     if (x1 == x2 && y1 == y2) n       ansflag = 1; n     else { n       if (chax == 0 || chay == 0) { n         if (chax + chay <= 4) ansflag = 1; n       } else { n         if (chax < chay) n           chay--; n         else n           chax--; n         if ((chax < 3 && chay <= 3) || (chax <= 3 && chay < 3)) ansflag = 1; n       } n     } n     if (ansflag) n       puts( First ); n     else n       puts( Second ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string obj; n bool solve(int x) { n   string s = to_string(x); n   string ans; n   for (int i = 0; i < s.size(); i++) n     if (s[i] ==  7  || s[i] ==  4 ) ans.push_back(s[i]); n   return ans == obj; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int a, b; n   cin >> a >> b; n   obj = to_string(b); n   int i = a + 1; n   while (!solve(i)) i++; n   cout << i <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int s = 0; n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     ; n   do { n     s = s * 10 + c -  0 ; n   } while ((c = getchar()) >=  0  && c <=  9 ); n   return s; n } n bool descending(int a, int b) { return a > b; } n string toStr(char c) { return string(1, c); } n const int maxN = (int)1e2 + 10; n const int inf = (int)1e9; n int x; n int a[maxN]; n long long dp[maxN]; n vector<int> vl; n int main() { n   int n; n   cin >> n; n   int cnt = 0; n   for (int i = 0; i < (n); i++) { n     cin >> x; n     cnt += x; n   } n   cout << fixed << setprecision(12); n   cout << cnt / double(n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[501][501]; n bool visited[501]; n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     visited[i] = false; n     for (long long j = 0; j < n; j++) { n       cin >> a[i][j]; n     } n   } n   vector<long long> order(n); n   for (long long i = 0; i < n; i++) { n     cin >> order[i]; n     order[i]--; n   } n   visited[order[n - 1]] = true; n   vector<long long> values; n   for (long long k = 0; k < n; k++) { n     long long ans = 0; n     long long p = order[n - k - 1]; n     visited[p] = true; n     for (long long i = 0; i < n; i++) { n       for (long long j = 0; j < n; j++) { n         a[i][j] = min(a[i][j], a[i][p] + a[p][j]); n         if (visited[i] && visited[j] && visited[p]) { n           ans += a[i][j]; n         } n       } n     } n     values.push_back(ans); n   } n   for (long long i = 0; i < n; i++) { n     cout << values[n - 1 - i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n class Node { n  public: n   Node<T> *prev; n   Node<T> *next; n   T data; n   Node(T data); n }; n template <class T> n Node<T>::Node(T data) { n   this->data = data; n } n template <class T> n class Stack { n  public: n   Node<T> *top; n   int size; n   Stack(); n   bool empty(); n   void push(T a); n   void pop(); n   void clear(); n }; n template <class T> n Stack<T>::Stack() { n   top = NULL; n   size = 0; n } n template <class T> n bool Stack<T>::empty() { n   return (size == 0); n } n template <class T> n void Stack<T>::push(T data) { n   Node<T> *t = new Node<T>(data); n   t->next = top; n   top = t; n   size++; n   return; n } n template <class T> n void Stack<T>::pop() { n   top = top->next; n   size--; n   return; n } n template <class T> n void Stack<T>::clear() { n   top = NULL; n   size = 0; n } n int main() { n   Stack<int> *st = new Stack<int>(); n   int n; n   cin >> n; n   int a; n   int answer = 0; n   int size = 0; n   int leftSum = 0, rightSum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a; n     rightSum = rightSum + a; n     st->push(a); n     size++; n   } n   while (!st->empty()) { n     leftSum = leftSum + st->top->data; n     rightSum = rightSum - st->top->data; n     if (leftSum == rightSum && size != 1) answer++; n     st->pop(); n     size--; n   } n   cout << answer; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cekTanda(char ch) { n   switch (ch) { n     case  > : n       return 8; n     case  < : n       return 9; n     case  + : n       return 10; n     case  - : n       return 11; n     case  . : n       return 12; n     case  , : n       return 13; n     case  [ : n       return 14; n     case  ] : n       return 15; n   } n } n int main() { n   char str[1024]; n   scanf( %s , str); n   int panjang = strlen(str); n   int res = 0; n   for (int i = 0; i < panjang; i++) { n     res = (res << 4) % 1000003; n     res += cekTanda(str[i]); n     res %= 1000003; n   } n   printf( %d , res); n } n


#include <bits/stdc++.h> n const long long N = 500005; n const long long mod = 1e9 + 7; n using namespace std; n std::vector<long long> adj[N]; n std::vector<bool> vis(N); n void solve() { n   long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0; n   cin >> n >> m; n   for (long long i = 0; i < m; ++i) { n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   x = 0; n   for (int i = 1; i <= n; ++i) { n     if (x < adj[i].size()) { n       x = adj[i].size(); n       y = i; n     } n   } n   std::vector<pair<long long, long long> > v; n   queue<long long> nodes; n   nodes.push(y); n   vis[y] = 1; n   while (!nodes.empty()) { n     x = nodes.front(); n     nodes.pop(); n     for (auto i : adj[x]) { n       if (!vis[i]) { n         vis[i] = 1; n         nodes.push(i); n         v.push_back({x, i}); n       } n     } n   } n   for (int i = 0; i < v.size(); ++i) { n     cout << v[i].first <<     << v[i].second <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int nb; n   scanf( %d , &nb); n   int arr[nb]; n   for (int i = 0; i < nb; i++) scanf( %d , arr + i); n   sort(arr, arr + nb); n   int occ[3] = {0}; n   for (int i = 0; i < nb; i++) { n     for (int j = 0; j < 3; j++) n       if (arr[i] == arr[j]) occ[j]++; n   } n   if ((occ[0] == 1 && occ[1] == 1) || (occ[0] == 2)) { n     printf( %d , occ[2]); n     return 0; n   } n   if (occ[0] == 1 && occ[1] >= 2) { n     long long res = (occ[1] * (long long)(occ[1] - 1)) / 2; n     printf( %lld , res); n     return 0; n   } n   long long res = (occ[0] * (long long)(occ[0] - 1) * (occ[0] - 2)) / 6; n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n void solve() { n   int n, k, d; n   cin >> n >> k >> d; n   vector<int> a(n); n   map<int, int> used; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int cnt = 0, ans = INF; n   for (int i = 0; i < d; i++) { n     if (used[a[i]] == 0) cnt++; n     used[a[i]]++; n   } n   for (int i = d; i < n; i++) { n     ans = min(ans, cnt); n     used[a[i - d]]--; n     if (used[a[i - d]] == 0) cnt--; n     if (used[a[i]] == 0) cnt++; n     used[a[i]]++; n   } n   ans = min(cnt, ans); n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int _t; n   cin >> _t; n   for (int _q = 0; _q < _t; _q++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int *arr = new int[n]; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     int j, k; n     for (int i = 0; i < n; i++) { n       if (arr[i] == 1) { n         j = i; n         break; n       } n     } n     for (int i = n - 1; i >= 0; i--) { n       if (arr[i] == 1) { n         k = i; n         break; n       } n     } n     int ans = 0; n     for (int i = j; i <= k; i++) { n       if (arr[i] == 0) ans++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, d, bd[4]; n vector<long long> pst[4][100069]; n int main() { n   long long i, j, ii, k, l, z = 1, y, x, p; n   bool ft = 1; n   scanf( %lld%lld%lld , &n, &m, &d); n   for (i = 0; i < d; i++) { n     scanf( %lld%lld , &k, &l); n     for (ii = 0; ii < 4; ii++) { n       pst[ii][k].push_back(l); n       l = m + 1 - l; n       swap(k, l); n       swap(n, m); n     } n   } n   for (ii = 0; ii < 4; ii++) { n     for (i = 1; i <= n; i++) { n       sort(pst[ii][i].begin(), pst[ii][i].end()); n       pst[ii][i].push_back(m + 1); n     } n     bd[ii] = m + 1; n     swap(n, m); n   } n   y = 1; n   x = 1; n   for (ii = 0; 1; ii = (ii + 1) % 4) { n     p = min(bd[ii], *upper_bound(pst[ii][y].begin(), pst[ii][y].end(), x)) - 1; n     k = p - x; n     bd[(ii + 3) % 4] = n + 1 - y; n     x = p; n     z += k; n     if (k == 0 && !ft) { n       break; n     } n     ft = 0; n     x = m + 1 - x; n     swap(y, x); n     swap(n, m); n   } n   if (z == n * m - d) { n     printf( Yes n ); n   } else { n     printf( No n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n void SieveOfEratosthenes(long long n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long p = 2; p <= n; p++) n     if (prime[p]) v.push_back(p); n } n signed main() { n   long long n; n   cin >> n; n   SieveOfEratosthenes(n); n   long long m = v.size(); n   vector<long long> ans; n   long long ct = 0; n   for (long long i = 0; i < m; i++) { n     long long p = v[i]; n     while (p <= n) { n       ct++; n       ans.push_back(p); n       p = p * v[i]; n     } n   } n   cout << ct <<   n ; n   long long k = ans.size(); n   for (long long i = 0; i < k; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sqr(T x) { n   return x * x; n } n struct sp { n   int x, y; n   bool operator<(const sp &a) const { return x < a.x || x == a.x && y < a.y; } n   bool operator==(const sp &a) const { return x == a.x && y == a.y; } n }; n namespace std { n template <> n struct hash<sp> { n   size_t operator()(sp a) const { return a.x * 9875321 + a.y; } n }; n }  // namespace std n unordered_map<sp, int> m1; n vector<int> b; n vector<int> a[110000]; n int n, m, ans; n int main() { n   int i, j, k, x, y, d; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d%d , &x, &y); n     a[x].push_back(y); n     m1[sp{x, y}] = 1; n   } n   m = sqrt(n); n   for (i = 0; i <= 100000; i++) n     if (a[i].size() >= m) b.push_back(i); n   for (i = 0; i < b.size(); i++) n     for (j = i + 1; j < b.size(); j++) { n       d = b[j] - b[i]; n       x = b[i]; n       for (k = 0; k < a[x].size(); k++) { n         y = a[x][k]; n         if (m1.count(sp{x + d, y}) && m1.count(sp{x, y + d}) && n             m1.count(sp{x + d, y + d})) n           ans++; n       } n     } n   for (i = 0; i <= 100000; i++) n     if (a[i].size() < m) { n       sort(a[i].begin(), a[i].end()); n       x = i; n       for (j = 0; j < a[x].size(); j++) { n         y = a[x][j]; n         for (k = j + 1; k < a[x].size(); k++) { n           d = a[x][k] - a[x][j]; n           if (m1.count(sp{x + d, y}) && m1.count(sp{x + d, y + d})) ans++; n           if (x - d >= 0 && a[x - d].size() >= m) n             if (m1.count(sp{x - d, y}) && m1.count(sp{x - d, y + d})) ans++; n         } n       } n     } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int kN = int(4E3 + 10), kInf = int(1E9 + 10); n int a[kN]; n void solve() { n   int n, m, k, lft, ans = 0, tmp; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   m--; n   k = min(k, m); n   lft = m - k; n   for (int i = 0; i <= k; i++) { n     tmp = kInf; n     for (int j = 0; j <= lft; j++) n       tmp = min(tmp, max(a[i + j + 1], a[n - (k - i) - (lft - j)])); n     ans = max(ans, tmp); n   } n   printf( %d n , ans); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n const long long int MOD = 1000000007; n const long long int MAXN = 1000005; n const long long int INF = 100000000000005; n void solve() { n   long long int n; n   cin >> n; n   vector<long long int> a(n), pos, neg; n   for (long long int i = 0; i < n; ++i) cin >> a[i]; n   long long int ans = 1; n   if (n == 5) { n     for (long long int i = 0; i < n; ++i) { n       ans = ans * a[i]; n     } n     cout << ans << endl; n     return; n   } n   for (auto itr : a) { n     if (itr < 0) { n       neg.push_back(itr); n     } else { n       pos.push_back(itr); n     } n   } n   if (pos.size() == 0 and neg.size() == 0) { n     ans = 0; n   } else if (pos.size() == 0) { n     sort(neg.begin(), neg.end()); n     reverse(neg.begin(), neg.end()); n     if (neg.size() < 5) { n       ans = 0; n     } else { n       for (long long int i = 0; i < 5; ++i) { n         ans = ans * neg[i]; n       } n     } n   } else if (neg.size() == 0) { n     sort(pos.begin(), pos.end()); n     reverse(pos.begin(), pos.end()); n     if (pos.size() < 5) { n       ans = 0; n     } else { n       for (long long int i = 0; i < 5; ++i) { n         ans = ans * pos[i]; n       } n     } n   } else { n     sort(pos.begin(), pos.end()); n     sort(neg.begin(), neg.end()); n     long long int si_pos = pos.size(), si_neg = neg.size(), res = -INF; n     if (si_neg + si_pos < 5) { n       ans = 0; n     } else { n       if (si_pos >= 5) { n         res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] * n                            pos[si_pos - 4] * pos[si_pos - 5]); n       } n       if (si_pos >= 3 and si_neg >= 2) { n         res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] * n                            neg[0] * neg[1]); n       } n       if (si_pos >= 1 and si_neg >= 4) { n         res = max(res, pos[si_pos - 1] * neg[2] * neg[3] * neg[0] * neg[1]); n       } n       ans = res; n     } n   } n   cout << ans << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[200005]; n int lis[200005]; n int main() { n   int n1, n2, n3; n   cin >> n1 >> n2 >> n3; n   for (int i = 1; i <= n1 + n2 + n3; i++) { n     cin >> num[i]; n   } n   sort(num + 1, num + 1 + n1); n   sort(num + 1 + n1, num + 1 + n1 + n2); n   sort(num + 1 + n1 + n2, num + 1 + n1 + n2 + n3); n   int st = 1, et = 1; n   lis[1] = num[1]; n   for (int i = 2; i <= n1 + n2 + n3; i++) { n     int l = st, r = et; n     if (num[i] >= lis[et]) { n       et++; n       lis[et] = num[i]; n       continue; n     } n     while (l < r) { n       int mid = (l + r) >> 1; n       if (lis[mid] < num[i]) { n         l = mid + 1; n       } else { n         r = mid; n       } n     } n     lis[l] = num[i]; n   } n   cout << n1 + n2 + n3 - et << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     long long ans = 0; n     for (int i = 0; i <= 8 && i <= n; i++) { n       for (int j = 0; j <= (i == 0 ? 8 : 4) && i + j <= n; j++) { n         ans += n + 1 - i - j; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, ar, b, fi; n int i, j, ans, o1[3000], o2[3000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> a >> b; n   ar = a; n   reverse(ar.begin(), ar.end()); n   for (; i < b.size(); ++i) { n     if (a.find(b[i]) == string::npos) { n       cout <<  -1 n ; n       return 0; n     } n   } n   for (i = 0; i < b.size();) { n     for (j = 1; i + j <= b.length(); ++j) { n       fi = b.substr(i, j); n       if (a.find(fi) == string::npos && ar.find(fi) == string::npos) { n         if (a.find(b.substr(i, j - 1)) == string::npos) { n           o1[ans] = a.length() - ar.find(b.substr(i, j - 1)); n           o2[ans] = a.length() - ar.find(b.substr(i, j - 1)) - j + 2; n         } else { n           o1[ans] = a.find(b.substr(i, j - 1)) + 1; n           o2[ans] = a.find(b.substr(i, j - 1)) + j - 1; n         } n         i += j - 1; n         ++ans; n         break; n       } else if (i + j == b.length()) { n         if (a.find(b.substr(i, j)) == string::npos) { n           o1[ans] = a.length() - ar.find(b.substr(i, j)); n           o2[ans] = a.length() - ar.find(b.substr(i, j)) - j + 1; n         } else { n           o1[ans] = a.find(b.substr(i, j)) + 1; n           o2[ans] = a.find(b.substr(i, j)) + j; n         } n         i += j; n         ++ans; n       } n     } n   } n   cout << ans <<   n ; n   for (i = 0; i < ans; ++i) cout << o1[i] <<     << o2[i] <<   n ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n template <class T> n inline void amin(T &x, const T &y) { n   if (y < x) x = y; n } n template <class T> n inline void amax(T &x, const T &y) { n   if (x < y) x = y; n } n template <class Iter> n void rprintf(const char *fmt, Iter begin, Iter end) { n   for (bool sp = 0; begin != end; ++begin) { n     if (sp) n       putchar(   ); n     else n       sp = true; n     printf(fmt, *begin); n   } n   putchar(  n ); n } n int N; n int T[100011]; n int X[100011]; n int Y[100011]; n int val[100011]; n void MAIN() { n   int R; n   scanf( %d%d , &R, &N); n   for (int i = 0, i_len = (N); i < i_len; ++i) n     scanf( %d%d%d , T + i, X + i, Y + i); n   const int INF = 1 << 29; n   for (int i = 0, i_len = (N); i < i_len; ++i) { n     val[i] = -INF; n     if (X[i] + Y[i] - 2 <= T[i]) val[i] = 1; n     for (int j = i - 1; j >= 0; j--) { n       if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= T[i] - T[j]) { n         amax(val[i], val[j] + 1); n       } n       if (T[i] - T[j] > 2000) break; n     } n   } n   int ans = 0; n   for (int i = 0, i_len = (N); i < i_len; ++i) amax(ans, val[i]); n   printf( %d n , ans); n } n int main() { n   int TC = 1; n   for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n pair<long long, long long> dp[20][1 << 10]; n int a[20]; n long long pw[20]; n int change(long long n) { n   int cnt = 0; n   while (n) { n     if (n & 1) cnt++; n     n /= 2; n   } n   return cnt; n } n int k; n long long pow(int e, int n) { n   long long ans = 1; n   while (n--) { n     ans *= e; n   } n   return ans; n } n pair<long long, long long> dfs(int len, long long Set, bool zero, bool limit) { n   if (len == 0) { n     if (change(Set) <= k) return make_pair(1, 0); n     return make_pair(0, 0); n   } n   if (!limit && dp[len][Set].first != 0 && !zero) return dp[len][Set]; n   int u = limit ? a[len - 1] : 9; n   pair<long long, long long> ans = make_pair(0, 0); n   for (int i = 0; i <= u; i++) { n     pair<long long, long long> tem = make_pair(0, 0); n     if (change(Set | (1 << i)) > k) continue; n     if (zero && i == 0) n       tem = dfs(len - 1, Set, zero, i == u && limit); n     else { n       tem = dfs(len - 1, Set | (1 << i), zero && i == 0, i == u && limit); n     } n     ans.first += tem.first; n     ans.first %= mod; n     ans.second = n         (ans.second + i * tem.first % mod * pw[len - 1] % mod + tem.second) % n         mod; n   } n   if (!limit && !zero) dp[len][Set] = ans; n   return ans; n } n void init() { n   pw[0] = 1; n   for (int i = 1; i < 20; i++) pw[i] = (pw[i - 1] * 10) % mod; n   for (int i = 0; i < 20; i++) n     for (int j = 0; j < 1 << 9; j++) dp[i][j].first = dp[i][j].second = 0; n } n long long solve(long long n) { n   int len = 0; n   init(); n   while (n) { n     a[len++] = n % 10; n     n /= 10; n   } n   return dfs(len, 0, 1, 1).second; n } n int main() { n   long long l, r; n   while (cin >> l >> r >> k) { n     cout << (solve(r) - solve(l - 1) + mod) % mod << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> ans(n); n   int a1, a2, a3; n   cout <<  ? 1 2  << endl; n   fflush(stdout); n   cin >> a1; n   cout <<  ? 1 3  << endl; n   fflush(stdout); n   cin >> a2; n   cout <<  ? 2 3  << endl; n   fflush(stdout); n   cin >> a3; n   int t = (a1 + a2 - a3) / 2; n   ans[0] = t; n   ans[2] = a2 - t; n   ans[1] = a3 - ans[2]; n   for (int i = 3; i < n; i++) { n     int now = 0; n     cout <<  ? 1   << i + 1 << endl; n     fflush(stdout); n     cin >> now; n     ans[i] = now - t; n   } n   cout <<  !  ; n   for (int i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a, ok, ans, occ[10]; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     int total = k + 1; n     memset(occ, 0, sizeof(occ)); n     while (a) { n       if (!occ[a % 10] && (a % 10 <= k)) { n         total--; n       } n       occ[a % 10] = 1; n       a /= 10; n     } n     if (!total) { n       ans++; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int R = 1000; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, s, d; n   cin >> n >> s >> d; n   vector<bitset<R>> a(s); n   for (int i = 0, k, x; i < s; ++i) { n     cin >> k; n     while (k--) cin >> x, a[i][x - 1] = 1; n   } n   vector<pair<int, bitset<R>>> f1; n   int m = min(s, 10); n   for (int i = 0; i < 1 << m; ++i) { n     f1.push_back({0, {}}); n     for (int j = 0; j < m; ++j) n       if (i >> j & 1) ++f1.back().first, f1.back().second ^= a[j]; n   } n   unordered_map<bitset<R>, int> mp; n   int m2 = s - m; n   for (int i = 0; i < 1 << m2; ++i) { n     bitset<R> b; n     int c = 0; n     for (int j = 0; j < m2; ++j) n       if (i >> j & 1) ++c, b ^= a[m + j]; n     if (!mp.count(b)) n       mp[b] = c; n     else n       mp[b] = min(mp[b], c); n   } n   for (int k, x; d--;) { n     cin >> k; n     bitset<R> b; n     while (k--) cin >> x, b[x - 1] = 1; n     int ans = 1 << 30; n     for (auto &i : f1) { n       b ^= i.second; n       if (mp.count(b)) ans = min(ans, i.first + mp[b]); n       b ^= i.second; n     } n     if (ans == 1 << 30) ans = -1; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 10000 + 10; n int n, m; n int second[200], a[200]; n bool vis[200]; n int main() { n   scanf(  %d %d , &n, &m); n   for (int i = 0; i < m; i++) scanf(  %d , &second[i]); n   for (int i = 0; i < m; i++) second[i]--; n   bool win = true; n   for (int i = 0; i < m - 1; i++) { n     int next = second[i + 1]; n     if (next <= second[i]) next += n; n     if (a[second[i]] == 0 || n         a[second[i]] != 0 && a[second[i]] == next - second[i]) n       a[second[i]] = next - second[i]; n     else n       win = false; n   } n   for (int i = 0; i < n; i++) { n     if (vis[a[i]] && a[i] != 0) win = false; n     vis[a[i]] = true; n   } n   if (win) { n     int ind = 1; n     for (int i = 0; i < n; i++) { n       if (a[i] == 0) { n         while (vis[ind]) ind++; n         a[i] = ind; n         vis[ind] = true; n       } n     } n     for (int i = 0; i < n; i++) { n       if (i > 0) printf(   ); n       printf( %d , a[i]); n     } n     printf(  n ); n   } else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e3 + 10; n int n, a[MAXN], k, dp[MAXN]; n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long l = -1, r = 2e9 + 1; n   while (l + 1 < r) { n     long long mid = (r + l) / 2; n     bool flag = false; n     for (int i = 0; i < n; i++) { n       dp[i] = i; n       for (int j = 0; j < i; j++) { n         if (abs(a[i] - a[j]) > (i - j) * mid) continue; n         dp[i] = min(dp[i], dp[j] + i - j - 1); n       } n       if (dp[i] + n - i - 1 <= k) { n         flag = true; n         break; n       } n     } n     if (flag) n       r = mid; n     else n       l = mid; n   } n   cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n long long* parent; n long long* size; n void make_set(long long v) { n   parent[v] = v; n   size[v] = 1; n } n long long find_set(long long v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_set(long long u, long long v) { n   long long p1, p2; n   p1 = find_set(u); n   p2 = find_set(v); n   if (p1 != p2) { n     if (size[p1] < size[p2]) swap(p1, p2); n     parent[p2] = p1; n     size[p1] += size[p2]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   vector<long long> vc(n + 1); n   parent = new long long[n + 1]; n   size = new long long[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> vc[i]; n     make_set(i); n   } n   long long a, b; n   for (long long i = 0; i < m; i++) { n     cin >> a >> b; n     union_set(a, b); n   } n   unordered_map<long long, long long> mp; n   vector<vector<long long> > ele(n + 1); n   vector<vector<long long> > ind(n + 1); n   long long k; n   long long p = 0, pp; n   for (long long i = 1; i <= n; i++) { n     k = find_set(i); n     if (mp[k] == 0) { n       p++; n       pp = p; n       mp[k] = p; n     } else { n       pp = mp[k]; n     } n     ele[pp].push_back(vc[i]); n     ind[pp].push_back(i); n   } n   for (long long i = 1; i <= p; i++) { n     sort(ele[i].begin(), ele[i].end(), greater<long long>()); n     sort(ind[i].begin(), ind[i].end()); n     for (long long j = 0; j < ele[i].size(); j++) { n       vc[ind[i][j]] = ele[i][j]; n     } n   } n   for (long long i = 1; i <= n; i++) cout << vc[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = 3e5 + 2; n struct Ant { n   int id; n   long long pos, speed; n   Ant(){}; n   Ant(int id, long long pos, long long speed) { n     this->id = id; n     this->pos = pos; n     this->speed = speed; n   } n }; n bool comparePosition(Ant a, Ant b) { return (a.pos < b.pos); } n long long mod(long long x, long long m) { return ((x % m) + m) % m; } n int ans[MAX_N]; n std::vector<Ant> startPosition, endPosition; n int main() { n   int n; n   long long cycleLength, time; n   std::cin >> n >> cycleLength >> time; n   for (int i = 1; i <= n; i++) { n     int pos; n     char dir; n     std::cin >> pos >> dir; n     startPosition.push_back(Ant(i, pos, (dir ==  R ) ? 1 : -1)); n   } n   std::sort(startPosition.begin(), startPosition.end(), comparePosition); n   for (int i = 0; i < (int)startPosition.size(); i++) n     endPosition.push_back(startPosition[i]); n   long long cyclicShift = 0; n   for (int i = 0; i < n; i++) cyclicShift += startPosition[i].speed; n   cyclicShift = mod(cyclicShift * (time / cycleLength), n); n   time %= cycleLength; n   for (int i = 0; i < n; i++) { n     endPosition[i].pos = n         mod((startPosition[i].pos - 1) + time * startPosition[i].speed, n             cycleLength) + n         1; n     if (startPosition[i].speed == 1) { n       if (endPosition[i].pos < startPosition[i].pos) cyclicShift++; n     } else { n       if (endPosition[i].pos > startPosition[i].pos) cyclicShift--; n     } n   } n   cyclicShift = mod(cyclicShift, n); n   std::sort(endPosition.begin(), endPosition.end(), comparePosition); n   for (int i = 0; i < n; i++) { n     endPosition[i].id = startPosition[mod(i - cyclicShift, n)].id; n     ans[endPosition[i].id] = endPosition[i].pos; n   } n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 810; n int gi() { n   int x = 0, o = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n int n, ans[N], pos[N], odd[N], p[N]; n bool vis[10]; n int query(vector<int> a) { n   cout <<  ?   << int(a.size()); n   for (auto x : a) cout <<     << x; n   cout << endl; n   int t = gi(); n   if (t == -1) throw  orzxzz ; n   return t; n } n int query_3(int x) { n   if (query({pos[1], pos[2], x})) return 0; n   if (query({pos[1], pos[3], x})) return 2; n   return 1; n } n int query_5(int x) { n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= 4; i++) { n     int val = (5 - (3 * n - 3 + i) % 5) % 5; n     if (query({pos[n], pos[n - 1], pos[n - 2], pos[i], x})) return val; n     vis[val] = 1; n   } n   for (int i = 0; i < 5; i++) n     if (!vis[i]) return i; n   throw  orzxzz ; n } n int query_7(int x) { n   memset(vis, 0, sizeof(vis)); n   int cnt = 0; n   for (int i = 1; i <= 4 && cnt <= 5; i++) n     for (int j = 1; j <= 4 && cnt <= 5; j++) { n       int val = (7 - (4 * n + 4 - i - (n - j + 1)) % 7) % 7; n       if (vis[val]) continue; n       vector<int> vec = {x}; n       for (int k = 1; k <= 4; k++) n         if (i != k) vec.push_back(pos[k]); n       for (int k = 1; k <= 4; k++) n         if (j != k) vec.push_back(pos[n - k + 1]); n       if (query(vec)) return val; n       vis[val] = 1; n       ++cnt; n     } n   for (int i = 0; i < 7; i++) n     if (!vis[i]) return i; n   throw  orzxzz ; n } n int query_8(int x) { n   int ret = odd[x]; n   for (int i = 1; i <= 4; i++) { n     int val = (4 - (10 - i) % 4) % 4; n     if (val != ret) continue; n     vector<int> vec = {x}; n     for (int j = 1; j <= 4; j++) n       if (i != j) vec.push_back(pos[j]); n     if (!query(vec)) ret += 2; n     break; n   } n   for (int i = 1; i <= 4; i++) { n     int val = (8 - (4 * n + 4 - i) % 8) % 8; n     if (val != ret && val != ret + 4) continue; n     vector<int> vec = {x}; n     for (int j = 1; j <= 4; j++) n       if (i != j) vec.push_back(pos[j]); n     for (int j = 1; j <= 4; j++) vec.push_back(pos[n - j + 1]); n     if (query(vec) ^ (val == ret)) ret += 4; n     break; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     vector<int> vec; n     for (int j = 1; j <= n; j++) n       if (i != j) vec.push_back(j); n     if (query(vec)) { n       if (!pos[1]) n         pos[1] = i, ans[i] = 1; n       else n         pos[n] = i, ans[i] = n; n     } n   } n   for (int i = 1; i <= n; i++) n     if (!ans[i]) { n       if (query({pos[1], i})) odd[i] = 1; n     } n   for (int t = 2; 2 * t <= n && t <= 4; t++) { n     for (int i = 1; i <= n; i++) n       if (!ans[i]) { n         vector<int> vec; n         for (int j = 1; j <= n; j++) n           if (!ans[j] && j != i) vec.push_back(j); n         if (query(vec)) { n           if (!pos[t]) n             pos[t] = i; n           else n             pos[n - t + 1] = i; n         } n       } n     if (odd[pos[t]] != (t & 1)) swap(pos[t], pos[n - t + 1]); n     ans[pos[t]] = t; n     ans[pos[n - t + 1]] = n - t + 1; n   } n   for (int i = 1; i <= n; i++) n     if (!ans[i]) { n       int a = query_3(i), b = query_5(i), c = query_7(i), d = query_8(i); n       for (int j = 1; j <= n; j++) n         if (j % 3 == a && j % 5 == b && j % 7 == c && j % 8 == d) { n           ans[i] = j; n           break; n         } n     } n   if (ans[1] > n / 2) { n     for (int i = 1; i <= n; i++) ans[i] = n + 1 - ans[i]; n   } n   cout <<  ! ; n   for (int i = 1; i <= n; i++) cout <<     << ans[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> v(n); n   vector<int> c(m + 5, 0); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   int l = 0, r = 0; n   int res = 1; n   c[v[0] - 1]++; n   int maxC = 1; n   int maxI = v[0] - 1; n   while (r < n) { n     if (c[v[r] - 1] > maxC) { n       maxC = c[v[r] - 1]; n       maxI = v[r] - 1; n     } n     if (c[v[l] - 1] > maxC) { n       maxC = c[v[l] - 1]; n       maxI = v[l] - 1; n     } n     if (r - l + 1 - maxC > k) { n       if (v[l] - 1 == maxI) { n         maxC--; n       } n       c[v[l] - 1]--; n       l++; n     } else if (r == n - 1) { n       break; n     } else { n       r++; n       c[v[r] - 1]++; n       if (c[v[r] - 1] > maxC) { n         maxC = c[v[r] - 1]; n         maxI = v[r] - 1; n       } n       if (r - l + 1 - maxC <= k) { n         res = max(res, maxC); n       } n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const int MOD = 1e9 + 7; n const int N = 0, BAR = 1e6, LIM = 5e6; n int x, y, n; n int main() { n   scanf( %d , &n); n   int xa = inf, xb = -inf, ya = inf, yb = -inf; n   while (n--) { n     scanf( %d%d , &x, &y); n     x += BAR, y += BAR; n     xa = min(xa, x - y - 1), xb = max(xb, x + y + 1); n     ya = min(ya, x - (LIM - y + 1)), yb = max(yb, x + (LIM - y + 1)); n   } n   int ans = 0; n   int rya = (LIM - (yb - ya) / 2); n   ans += (yb - ya) % 2; n   int ryb = (xb - xa) / 2; n   ans += (xb - xa) % 2; n   ans += 2 * (ryb - rya); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fin( lol.in ); n ofstream fout( lol.out ); n char c; n int m[10][10], ok; n int main() { n   ios::sync_with_stdio(false); n   for (int i = 1; i <= 6; ++i) { n     m[1][i] = m[6][i] = 100; n     m[i][1] = m[i][6] = 100; n   } n   for (int i = 2; i <= 5; ++i) { n     for (int j = 2; j <= 5; ++j) { n       cin >> c; n       if (c ==  x ) m[i][j] = 1; n       if (c ==  o ) m[i][j] = 100; n     } n   } n   for (int i = 2; i <= 5; ++i) { n     for (int j = 2; j <= 5; ++j) { n       if (m[i][j] + m[i + 1][j] + m[i + 2][j] == 2) ok = 1; n       if (m[i][j] + m[i + 1][j + 1] + m[i + 2][j + 2] == 2) ok = 1; n       if (m[i][j] + m[i + 1][j - 1] + m[i + 2][j - 2] == 2) ok = 1; n       if (m[i][j] + m[i][j + 1] + m[i][j + 2] == 2) ok = 1; n       if (ok == 1) { n         cout <<  YES ; n         return 0; n       } n     } n   } n   if (ok == 1) { n     cout <<  YES ; n     return 0; n   } else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x7f7f7f7f; n int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; n int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; n vector<int> arr; n int main() { n   int n; n   string st; n   int x; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     arr.push_back(x); n   } n   cin >> st; n   int beg = 0; n   int flag = 0; n   for (int i = 0; i < st.size(); i++) { n     if (st[i] ==  1  && flag == 0) { n       beg = i; n       flag = 1; n     } else if (st[i] ==  0 ) { n       if (flag) { n         sort(arr.begin() + beg, arr.begin() + i + 1); n         flag = 0; n         beg = -1; n       } n     } n   } n   if (flag == 1) sort(arr.begin() + beg, arr.end()); n   bool f = 0; n   for (int i = 0; i < n; i++) { n     if (arr[i] != i + 1) { n       f = 1; n       break; n     } n   } n   if (f == 1) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, x, t; n   char card, ha; n   map<int, pair<int, int> > mh; n   map<int, pair<int, int> > ma; n   map<int, pair<int, int> >::iterator it; n   string h, a; n   cin >> h >> a; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> t >> ha; n     getchar(); n     cin >> x >> card; n     getchar(); n     if (ha ==  a ) { n       for (it = ma.begin(); it != ma.end(); it++) { n         if ((it->second).first == x) break; n       } n       if (it == ma.end() && card ==  y ) n         ma[t] = make_pair(x, 1); n       else if (it == ma.end() && card ==  r ) n         ma[t] = make_pair(x, 2); n       else if (it != ma.end() && (it->second).second == 1) { n         ma[t] = make_pair(x, 2); n         ma.erase(it); n       } n     } n     if (ha ==  h ) { n       for (it = mh.begin(); it != mh.end(); it++) { n         if ((it->second).first == x) break; n       } n       if (it == mh.end() && card ==  y ) n         mh[t] = make_pair(x, 1); n       else if (it == mh.end() && card ==  r ) n         mh[t] = make_pair(x, 2); n       else if (it != ma.end() && (it->second).second == 1) { n         mh[t] = make_pair(x, 2); n         mh.erase(it); n       } n     } n   } n   for (i = 0; i <= 90; i++) { n     if (ma[i].second == 2) cout << a <<     << ma[i].first <<     << i << endl; n     if (mh[i].second == 2) cout << h <<     << mh[i].first <<     << i << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 101000; n struct p { n   long long x, y; n } a[N]; n long long n, m; n long long pro(p o, p b, p c) { n   return (b.x - o.x) * (c.y - o.y) - (c.x - o.x) * (b.y - o.y); n } n int main() { n   scanf( %I64d , &n); n   for (long long i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i].x, &a[i].y); n   scanf( %I64d , &m); n   for (long long i = 1; i <= m; i++) { n     p b; n     scanf( %I64d%I64d , &b.x, &b.y); n     if (pro(a[1], a[2], b) >= 0 || pro(a[1], a[n], b) <= 0) { n       puts( NO ); n       return 0; n     } n     long long l = 2, r = n; n     while (l < r) { n       long long mid = (l + r) / 2; n       if (pro(a[1], a[mid], b) >= 0) n         r = mid; n       else n         l = mid + 1; n     } n     if (pro(a[l], a[l - 1], b) <= 0) { n       puts( NO ); n       return 0; n     } n   } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j; n   char s[60]; n   cin >> n >> s; n   for (i = 0, j = 0; i < n; i += ++j) cout << s[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma optimize( -O3 ) n string to_string(string s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n string to_string(const bool& b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(const A& v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) res +=  ,  ; n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n template <typename T> n inline void _read(T& x) { n   cin >> x; n } n template <typename A, typename B> n inline void _read(pair<A, B>& x) { n   _read(x.first); n   _read(x.second); n } n template <typename T> n inline void _read(vector<T>& x) { n   for (auto& v : x) _read(v); n } n void R() {} n template <typename T, typename... U> n void R(T& head, U&... tail) { n   _read(head); n   R(tail...); n } n template <typename T> n inline void _write(const T& x) { n   cout << x <<    ; n } n template <typename A, typename B> n inline void _write(const pair<A, B>& x) { n   _write(x.first); n   _write(x.second); n } n template <typename T> n inline void _write(const vector<T>& in) { n   for (const auto& x : in) _write(x); n } n void W() { cout <<   n ; } n template <typename T, typename... U> n void W(const T& head, const U&... tail) { n   _write(head); n   W(tail...); n } n void go(); n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   go(); n   return 0; n } n const int M = 1 << 4; n const int N = 1 << 17; n const int K = 4; n const int mod = 1e9 + 7; n int dp[N][M][1 << K]; n void go() { n   int n, k, m; n   R(n, k, m); n   dp[0][0][0] = 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j <= k; j++) n       for (int s = 0; s < (1 << m); s++) { n         int t = (s << 1) % (1 << m); n         (dp[i + 1][j][t] += dp[i][j][s]) %= mod; n         if (j < k) { n           int w = __builtin_popcount(s) + 1; n           (dp[i + 1][j + 1][t | 1] += 1LL * w * dp[i][j][s] % mod) %= mod; n         } n       } n   long long ans = 0; n   for (int s = 0; s < (1 << m); s++) (ans += dp[n][k][s]) %= mod; n   W(ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005, INF = 9999999; n const long long P = 1e9 + 7; n template <typename T> n inline void read(T& first, char s = getchar()) { n   first = 0; n   while (s >  9  || s <  0 ) s = getchar(); n   while (s <=  9  && s >=  0 ) first = first * 10 + s -  0 , s = getchar(); n } n int k, a, b; n int main() { n   read(k), read(a), read(b); n   if (a < k && b < k) { n     cout << -1 << endl; n     return 0; n   } n   if (a < k || b < k) { n     if (a < b) swap(a, b); n     if (a % k != 0) { n       cout << -1 << endl; n       return 0; n     } else { n       cout << (a / k) << endl; n       return 0; n     } n   } n   int ans = a / k + b / k; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> t >> s; n   set<char> b(t.begin(), t.end()); n   int n; n   cin >> n; n   for (int k = 0; k < n; ++k) { n     cin >> t; n     int i = 0; n     int j = 0; n     while (i < s.size() || j < t.size()) { n       if (s[i] ==  ? ) { n         if (b.find(t[j]) != b.end()) { n           ++i; n           ++j; n         } else { n           break; n         } n       } else if (s[i] ==  * ) { n         int x = t.size() - s.size() + 1; n         if (x < 0) { n           break; n         } else if (all_of(t.begin() + i, t.begin() + i + x, n                           [&](char c) { return b.find(c) == b.end(); })) { n           ++i; n           j += x; n         } else { n           break; n         } n       } else { n         if (s[i] == t[j]) { n           ++i; n           ++j; n         } else { n           break; n         } n       } n     } n     if (i == s.size() && j == t.size()) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 998244353, N = 2e5 + 5, M = 59, S = 32771; n inline int poww(int x, int y) { n   int ans = 1; n   for (; y; y >>= 1, x = 1ll * x * x % mo) n     if (y & 1) ans = 1ll * ans * x % mo; n   return ans; n } n int n, m, i, j, k, mi[N], C[M][M], ct[M]; n long long a[M], x, val[2][S]; n vector<long long> ve; n bool bb[M]; n inline void solve1(vector<long long> ve) { n   int p1 = 0, p2 = min(15, (int)ve.size()), p3 = ve.size(); n   for (i = 0; i < 1 << p2 - p1; ++i) n     for (j = 0; j < p2 - p1; ++j) n       if (i >> j & 1) val[0][i] ^= ve[j]; n   for (i = 0; i < 1 << p3 - p2; ++i) n     for (j = 0; j < p3 - p2; ++j) n       if (i >> j & 1) val[1][i] ^= ve[j + p2]; n   int s1 = (1 << p2) - 1, s2 = ((1 << p3) - 1) ^ s1; n   for (i = 0; i < 1 << p3; ++i) n     ++ct[__builtin_popcountll(val[0][i & s1] ^ val[1][(i & s2) >> p2])]; n } n int id[M], xb; n inline void solve2() { n   for (i = 0; i < m; ++i) n     if (!bb[i]) id[xb++] = i; n   vector<long long> v2; n   for (i = 0; i < xb; ++i) { n     long long x = 1 << i; n     for (j = 0; j < ve.size(); ++j) n       if (ve[j] >> id[i] & 1) x |= 1ll << j + xb; n     v2.push_back(x); n   } n   solve1(v2); n   static int cc[M], dd[M]; n   for (i = 0; i <= m; ++i) dd[i] = ((long long)ct[i] << ve.size()) % mo; n   for (i = 0; i <= m; ++i) n     for (j = 0; j <= m; ++j) n       for (k = 0; k <= i; ++k) n         if (k <= j && i - k <= m - j) n           cc[i] = (cc[i] + 1ll * C[j][k] * C[m - j][i - k] % mo * n                                (k & 1 ? mo - dd[j] : dd[j])) % n                   mo; n   for (i = 0; i <= m; ++i) n     cc[i] = 1ll * cc[i] * poww((1ll << m) % mo, mo - 2) % mo; n   memcpy(ct, cc, sizeof cc); n } n int main() { n   for (i = ** C = 1; i < M; ++i) n     for (j = *C[i] = 1; j <= i; ++j) n       C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mo; n   for (i = *mi = 1; i < N; ++i) mi[i] = 2 * mi[i - 1] % mo; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; ++i) { n     scanf( %lld , &x); n     for (j = m - 1; j >= 0; --j) n       if (x >> j & 1) { n         if (!a[j]) { n           a[j] = x; n           break; n         } n         x ^= a[j]; n       } n   } n   for (i = 0; i < m; ++i) n     if (a[i]) n       for (j = i + 1; j < m; ++j) n         if (a[j] >> i & 1) a[j] ^= a[i]; n   for (i = 0; i < m; ++i) n     if (a[i]) ve.push_back(a[i]), bb[i] = 1; n   if (ve.size() <= 26) n     solve1(ve); n   else n     solve2(); n   for (i = 0; i <= m; ++i) ct[i] = 1ll * ct[i] * mi[n - ve.size()] % mo; n   for (i = 0; i <= m; ++i) printf( %d%c , ct[i], i == m ?   n  :    ); n } n


#include <bits/stdc++.h> n using namespace std; n const int Inf = (int)1e9 + 7; n const long long LongInf = (long long)1e18 + 7; n namespace { n const int N = 1007; n const int MOD = (int)1e9 + 7; n int k, pa, pb; n long long dp[N][N]; n long long pw(long long x, int m) { n   if (m == 0) return 1; n   long long y = pw(x, m / 2); n   y = (y * y) % MOD; n   if (m % 2) y = (y * x) % MOD; n   return y; n } n long long inv(int x) { return pw(x, MOD - 2); } n void solve() { n   cin >> k >> pa >> pb; n   long long s = inv(pa + pb); n   pa = (pa * s) % MOD; n   pb = (pb * s) % MOD; n   long long res = 0; n   dp[1][0] = 1; n   long long rem = (pa * inv(pb)) % MOD; n   for (int i = 1; i <= k; i++) { n     for (int j = 0; j <= k; j++) { n       if (i + j >= k) { n         res += (dp[i][j] * (i + j + rem)) % MOD; n         res %= MOD; n       } else { n         (dp[i + 1][j] += (dp[i][j] * pa) % MOD) %= MOD; n         (dp[i][i + j] += (dp[i][j] * pb) % MOD) %= MOD; n       } n     } n   } n   cout << res <<   n ; n } n }  // namespace n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(9); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   char str[n]; n   scanf( %s , &str); n   int count = 0; n   for (int i = 0; i < n; i++) n     if (str[i] == str[i + 1]) count++; n   printf( %d , count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 1e4 + 10; n int n, b, q; n pair<int, int> h[MaxN]; n unordered_map<int, int> e[MaxN]; n vector<int> c[MaxN]; n int flow, parent[MaxN], mini, curr; n void dfs(int x) { n   if (parent[q + 6] != -1) return; n   for (int i = 0; i < c[x].size(); i++) { n     if (e[x][c[x][i]] > 0 && parent[c[x][i]] == -1) { n       parent[c[x][i]] = x; n       dfs(c[x][i]); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> b >> q; n   for (int i = 0; i < q; i++) cin >> h[i].first >> h[i].second; n   for (int i = 1; i <= 5; i++) { n     c[0].push_back(i); n     c[i].push_back(0); n     e[0][i] = n / 5; n     e[i][0] = 0; n   } n   sort(h, h + q); n   h[q].first = b; n   h[q].second = n; n   q++; n   for (int i = q - 1; i >= 0; i--) { n     e[i + 6][q + 6] = h[i].second; n     e[q + 6][i + 6] = 0; n     c[i + 6].push_back(q + 6); n     c[q + 6].push_back(i + 6); n     if (i < q - 1) { n       e[i + 7][q + 6] -= h[i].second; n       if (e[i + 7][q + 6] < 0) { n         cout <<  unfair ; n         return 0; n       } n     } n     for (int j = 0; j < 5; j++) { n       e[j + 1][i + 6] = h[i].first / 5; n       if (j > 0 && h[i].first % 5 >= j) e[j + 1][i + 6]++; n       e[i + 6][j + 1] = 0; n       c[j + 1].push_back(i + 6); n       c[i + 6].push_back(j + 1); n       if (i < q - 1) e[j + 1][i + 7] -= e[j + 1][i + 6]; n     } n   } n   while (true) { n     for (int i = 0; i < MaxN; i++) parent[i] = -1; n     parent[0] = 0; n     dfs(0); n     if (parent[q + 6] == -1) break; n     curr = q + 6; n     mini = 1e6; n     while (curr != 0) { n       mini = min(mini, e[parent[curr]][curr]); n       curr = parent[curr]; n     } n     flow += mini; n     curr = q + 6; n     while (curr != 0) { n       e[parent[curr]][curr] -= mini; n       e[curr][parent[curr]] += mini; n       curr = parent[curr]; n     } n   } n   if (flow == n) n     cout <<  fair ; n   else n     cout <<  unfair ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   const int maxN = 3002; n   bool tests[maxN] = {0}; n   int n(0); n   scanf( %d , &n); n   for (int k = 0; k < n; k++) { n     int temp; n     scanf( %d , &temp); n     tests[temp] = 1; n   } n   for (int index = 1; index < maxN; index++) { n     if (!tests[index]) { n       printf( %d n , index); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, sum = 0; n   cin >> n; n   bool isLR = false; n   char a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] ==  L  || a[i] ==  R ) isLR = true; n   } n   bool flag = false; n   int count = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  .  && flag == true) n       count++; n     else if (a[i] ==  L ) n       flag = true; n     else if (a[i] ==  R ) { n       sum += count; n       count = 0; n       flag = false; n     } n   } n   flag = false; n   count = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  .  && flag == true) n       count++; n     else if (a[i] ==  R ) n       flag = true; n     else if (a[i] ==  L ) { n       if (count % 2 != 0) sum++; n       count = 0; n       flag = false; n     } n   } n   count = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  . ) n       count++; n     else if (a[i] ==  L ) n       break; n     else if (a[i] ==  R ) { n       sum += count; n       break; n     } n   } n   count = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (a[i] ==  . ) n       count++; n     else if (a[i] ==  R ) n       break; n     else if (a[i] ==  L ) { n       sum += count; n       break; n     } n   } n   if (isLR == true) n     cout << sum; n   else n     cout << n; n   return 0; n } n