#include <bits/stdc++.h> n using namespace std; n const int N = 105; n char arr[N], dp[N][N * N], ndp[N][N * N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   int sz = 0; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     arr[x]++; n     if (arr[x] == 1) sz++; n   } n   dp[0][0] = 1; n   for (int i = 1; i < N; i++) { n     for (int x1 = 0; x1 < N; x1++) n       for (int x2 = 0; x2 < N * N; x2++) ndp[x1][x2] = 0; n     for (int f = 0; f <= arr[i]; f++) n       for (int x1 = 0; x1 < N; x1++) n         for (int x2 = 0; x2 < N * N; x2++) n           if (x2 + f * i < N * N && x1 + f < N) n             ndp[x1 + f][x2 + f * i] = n                 min(100, ndp[x1 + f][x2 + f * i] + dp[x1][x2]); n     for (int x1 = 0; x1 < N; x1++) n       for (int x2 = 0; x2 < N * N; x2++) dp[x1][x2] = ndp[x1][x2]; n   } n   if (sz <= 2) { n     cout << n <<   n ; n     return 0; n   } n   int ans = 0; n   for (int i = 1; i < N; i++) n     for (int f = 1; f <= arr[i]; f++) n       if (dp[f][f * i] == 1) ans = max(ans, f); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream in( in.txt ); n bool needToDelete(char c) { n   return tolower(c) ==  a  || tolower(c) ==  o  || tolower(c) ==  y  || n          tolower(c) ==  e  || tolower(c) ==  u  || tolower(c) ==  i ; n } n int main(int argc, char** argv) { n   string s; n   cin >> s; n   string ans; n   for (int i = 0; i < s.size(); i++) { n     if (!needToDelete(s[i])) { n       ans +=  . ; n       ans += tolower(s[i]); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n long long MAX(long long x, long long y) { return (x > y) ? x : y; } n long long MIN(long long x, long long y) { return (x < y) ? x : y; } n const int MAXN = 123; n const int MAXNM = 223; n const int MAXK = 7; n const int inf = 0x3f3f3f3f; n using namespace std; n inline int Read() { n   register int x = 0; n   bool flag = false; n   register char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) flag = true; n     ch = getchar(); n   } n   if (flag) { n     while ( 0  <= ch && ch <=  9 ) { n       x = x * 10 - ch +  0 ; n       ch = getchar(); n     } n   } else { n     while ( 0  <= ch && ch <=  9 ) { n       x = x * 10 + ch -  0 ; n       ch = getchar(); n     } n   } n   return x; n } n int N, M, K; n int cg(int x, int y) { return (x - 1) * M + y; } n pair<int, int> split(int z) { n   int y = (z - 1) % M + 1; n   return make_pair((z - y) / M + 1, y); n } n int dirx[4] = {1, 0, -1, 0}; n int diry[4] = {0, 1, 0, -1}; n int trans(int z, int dir) { n   pair<int, int> p = split(z); n   p = make_pair(p.first + dirx[dir], p.second + diry[dir]); n   if (1 <= p.first && p.first <= N && 1 <= p.second && p.second <= M) n     return cg(p.first, p.second); n   else n     return -1; n } n int a[MAXNM]; n int f[MAXNM][(1 << MAXK) - 1]; n vector<pair<int, int> > frm[MAXNM][(1 << MAXK) - 1]; n int ele[MAXK]; n queue<int> q; n bool inq[MAXNM]; n void spfa(int s) { n   while (!q.empty()) { n     int hd = q.front(); n     q.pop(); n     inq[hd] = false; n     for (int i = 0; i <= 3; i++) { n       int v = trans(hd, i); n       if (~v) { n         if (f[v][s] > f[hd][s] + a[v]) { n           f[v][s] = f[hd][s] + a[v]; n           frm[v][s].clear(); n           frm[v][s].push_back(make_pair(hd, s)); n           if (!inq[v]) { n             q.push(v); n             inq[v] = true; n           } n         } n       } n     } n   } n } n char mp[MAXN][MAXN]; n void print(int i, int s) { n   pair<int, int> p = split(i); n   mp[p.first][p.second] =  X ; n   for (auto &v : frm[i][s]) print(v.first, v.second); n } n int main() { n   memset(f, 0x3f, sizeof(f)); n   N = Read(); n   M = Read(); n   K = Read(); n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= M; j++) mp[i][j] =  . ; n   for (int i = 1; i <= N * M; i++) a[i] = Read(); n   for (int i = 0; i <= K - 1; i++) { n     int x = Read(), y = Read(); n     ele[i] = cg(x, y); n     f[ele[i]][1 << i] = a[ele[i]]; n   } n   for (int s = 1; s <= (1 << K) - 1; s++) { n     for (int ss = s & (s - 1); ss; ss = s & (ss - 1)) n       for (int i = 1; i <= N * M; i++) n         if (f[i][s] > f[i][ss] + f[i][s ^ ss] - a[i]) { n           f[i][s] = f[i][ss] + f[i][s ^ ss] - a[i]; n           frm[i][s].clear(); n           frm[i][s].push_back(make_pair(i, ss)); n           frm[i][s].push_back(make_pair(i, s ^ ss)); n         } n     for (int i = 1; i <= N * M; i++) n       if (f[i][s] < inf) { n         q.push(i); n         inq[i] = true; n       } n     spfa(s); n   } n   int ans = inf, id; n   for (int i = 1; i <= N * M; i++) n     if (f[i][(1 << K) - 1] < ans) ans = f[id = i][(1 << K) - 1]; n   printf( %d n , ans); n   print(id, (1 << K) - 1); n   for (int i = 1; i <= N; i++) printf( %s n , mp[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> getPrimes(int n) { n   vector<bool> sieve(n + 1, true); n   sieve[0] = sieve[1] = false; n   for (int i = 2; i * i <= n; i++) n     if (sieve[i]) n       for (int j = i * i; j <= n; j += i) sieve[j] = false; n   vector<int> primes; n   for (int i = 2; i <= n; i++) n     if (sieve[i]) primes.push_back(i); n   return primes; n } n void storePrimes(int n, unordered_map<int, int> &m, vector<int> &primes) { n   for (int p : primes) { n     if (p * p > n) break; n     while (n % p == 0) { n       m[p]++; n       n /= p; n     } n     if (n == 1) break; n   } n   if (n > 1) m[n]++; n } n void removePrimes(int n, unordered_map<int, int> &m, vector<int> &primes) { n   for (int p : primes) { n     if (p * p > n) break; n     while (n % p == 0) { n       m[p]--; n       n /= p; n     } n     if (n == 1) break; n   } n   if (n > 1) m[n]--; n } n bool isAtleast(unordered_map<int, int> &m1, unordered_map<int, int> &m2) { n   for (auto it = m2.begin(); it != m2.end(); it++) { n     int num = it->first, freq = it->second; n     if (m1.find(num) == m1.end() or m1[num] < freq) return false; n   } n   return true; n } n void printMap(unordered_map<int, int> &m) { n   for (auto it = m.begin(); it != m.end(); it++) n     cout << it->first <<  :   << it->second <<   n ; n } n long long int solve(int arr[], int n, int k) { n   vector<int> primes = getPrimes(1000003); n   unordered_map<int, int> mapK, currMap; n   storePrimes(k, mapK, primes); n   int i = 0, j = 0; n   long long int count = 0; n   while (j < n) { n     storePrimes(arr[j], currMap, primes); n     if (isAtleast(currMap, mapK)) { n       while (i <= j and isAtleast(currMap, mapK)) { n         count += (n - j); n         removePrimes(arr[i], currMap, primes); n         i++; n       } n     } n     j++; n   } n   return count; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k; n   cin >> n >> k; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   long long int ans = solve(arr, n, k); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, p, p1, maxi, a[1000000], idx; n stack<int> t, t1, id; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   maxi = -1; n   id.push(0); n   t.push(200000); n   t1.push(-1); n   for (int i = 1; i < n; i++) { n     p = 0; n     q = 5; n     while (q == 5) { n       idx = id.top(); n       p1 = t.top(); n       p = t1.top() + 1; n       if (a[idx] > a[i] && p <= p1) { n         q = 6; n         t1.top() = p; n         if (p > maxi) maxi = p; n         id.push(i); n         t.push(p); n         t1.push(-1); n       } else if (p1 == 200000) { n         q = 7; n         id.push(i); n         t.push(200000); n         t1.push(-1); n       } else { n         id.pop(); n         t.pop(); n         t1.pop(); n       } n     } n   } n   printf( %d , maxi + 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int i, n, m; n   cin >> n >> m; n   vector<int> a(n + m); n   for (i = 0; i < n + m; i++) { n     cin >> a[i]; n   } n   set<int> tax, per; n   for (i = 0; i < n + m; i++) { n     int t; n     cin >> t; n     if (t == 0) { n       per.insert(a[i]); n     } else { n       tax.insert(a[i]); n     } n   } n   map<int, int> ans; n   for (auto cur : per) { n     auto right = tax.upper_bound(cur); n     auto left = --tax.upper_bound(cur); n     if (left == tax.end()) { n       ans[*right]++; n     } else if (right == tax.end()) { n       ans[*left]++; n     } else { n       int l = *left, r = *right; n       if (cur - l <= r - cur) { n         ans[l]++; n       } else { n         ans[r]++; n       } n     } n   } n   for (auto cur : tax) { n     cout << ans[cur] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n auto fio = (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)); n int32_t main() { n   long long n; n   cin >> n; n   vector<long long> g(n); n   for (long long& x : g) cin >> x; n   vector<vector<long long>> idx(8192); n   for (long long i = 0; i < n; i++) idx[g[i]].push_back(i); n   vector<long long> mn(8192, n); n   mn[0] = -1; n   for (long long i = 0; i <= 5000; i++) { n     if (idx[i].empty()) continue; n     for (long long j = 0; j < 8192; j++) { n       if (mn[j] <= mn[i ^ j] || mn[i ^ j] >= idx[i].back()) continue; n       auto it = upper_bound(idx[i].begin(), idx[i].end(), mn[i ^ j]); n       if (it != idx[i].end() && *it < mn[j]) mn[j] = *it; n     } n   } n   cout << 8192 - count(mn.begin(), mn.end(), n) << endl; n   for (long long i = 0; i < 8192; i++) n     if (mn[i] != n) cout << i <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct _ { n   _() { ios_base::sync_with_stdio(0); } n } _; n template <class T> n void PV(T a, T b) { n   while (a != b) cout << *a++, cout << (a != b ?     :   n ); n } n template <class T> n inline bool chmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n inline bool chmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n } n const int inf = 0x3f3f3f3f; n const int mod = int(1e9) + 7; n const int N = 3 * 111111; n int n, q; n int d[N]; n int p[N]; n int v[N]; n void add(int first, int t) { n   if (first == 0) return; n   while (first <= n) { n     v[first] += t; n     first += first & (first ^ (first - 1)); n   } n } n int sum(int first) { n   int r = 0; n   while (first > 0) { n     r += v[first]; n     first -= first & (first ^ (first - 1)); n   } n   return r; n } n int main() { n   cin >> n; n   p[0] = 0, p[n + 1] = n + 1; n   for (int i = 1; i <= n; i++) cin >> d[i], p[d[i]] = i; n   for (int i = 1; i <= n; i++) n     if (p[d[i] - 1] > i) add(d[i], 1); n   cin >> q; n   while (q--) { n     int op, l, r, t; n     cin >> op >> l >> r; n     if (op == 1) { n       cout << sum(r) - sum(l) + 1 << endl; n     } else { n       if (d[l] > d[r]) { n         t = p[d[r] - 1]; n         if (l < t && t < r) add(d[r], 1); n         t = p[d[r] + 1]; n         if (l < t && t < r) add(d[r] + 1, -1); n         t = p[d[l] + 1]; n         if (l < t && t < r) add(d[l] + 1, 1); n         t = p[d[l] - 1]; n         if (l < t && t < r) add(d[l], -1); n         if (d[l] == d[r] + 1) add(d[l], -1); n       } else if (d[l] < d[r]) { n         t = p[d[l] - 1]; n         if (l < t && t < r) add(d[l], -1); n         t = p[d[l] + 1]; n         if (l < t && t < r) add(d[l] + 1, 1); n         t = p[d[r] + 1]; n         if (l < t && t < r) add(d[r] + 1, -1); n         t = p[d[r] - 1]; n         if (l < t && t < r) add(d[r], 1); n         if (d[l] == d[r] - 1) add(d[r], 1); n       } n       swap(d[l], d[r]); n       p[d[l]] = l, p[d[r]] = r; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( popcnt ) n using namespace std; n mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count()); n const long long N = 2e5 + 100; n const long long mod = 1e9 + 7; n const long long big = 1e17; n long long t, n, h; n long long a[N]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n >> h; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     sort(a + 1, a + n + 1); n     long long l = 1, r = 1e18, ans = h; n     while (l <= r) { n       long long m = (l + r) >> 1ll; n       long long sum = 0, rtst = 0; n       for (int i = 1; i <= n; i++) { n         long long l = max(a[i] - 1ll, rtst), r = a[i] + m - 1; n         sum = sum + (r - l); n         rtst = r; n       } n       if (sum >= h) n         r = m - 1ll, ans = m; n       else n         l = m + 1ll; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int in(char &c) { return scanf( %c , &c); } n int in(char s[]) { return scanf( %s , s); } n int in(int &x) { return scanf( %d , &x); } n int in(long long &x) { return scanf( %lld , &x); } n int in(double &x) { return scanf( %lf , &x); } n int in(pair<int, int> &p) { return scanf( %d%d , &p.first, &p.second); } n int in(pair<long long, long long> &p) { n   return scanf( %lld%lld , &p.first, &p.second); n } n int in(pair<double, double> &p) { return scanf( %lf%lf , &p.first, &p.second); } n int in(long double &a) { return scanf( %Lf , &a); } n int in(int &x, long long &y) { return scanf( %d%lld , &x, &y); } n int in(long long &x, int &y) { return scanf( %lld%d , &x, &y); } n int in(int &x, int &y) { return scanf( %d%d , &x, &y); } n int in(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); } n int in(int &n, char s[]) { return scanf( %d%d , &n, s); } n int in(char a[], char b[]) { return scanf( %s%s , a, b); } n int in(double &x, double &y) { return scanf( %lf%lf , &x, &y); } n int in(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); } n int in(long long &x, long long &y, long long &z) { n   return scanf( %lld%lld%lld , &x, &y, &z); n } n int in(double &x, double &y, double &z) { n   return scanf( %lf%lf%lf , &x, &y, &z); n } n int in(int &x, int &y, int &z, int &k) { n   return scanf( %d%d%d%d , &x, &y, &z, &k); n } n int in(long long &x, long long &y, long long &z, long long &k) { n   return scanf( %lld%lld%lld%lld , &x, &y, &z, &k); n } n int in(double &x, double &y, double &z, double &k) { n   return scanf( %lf%lf%lf%lf , &x, &y, &z, &k); n } n const int N = 3e5 + 10, M = 1e3 + 10, mod = 1e9 + 7; n const double eps = 1e-6, Pi = acos(-1.0); n int a[N], b[N], L[N], R[N], s[N]; n vector<int> vc[N]; n int check(int x, int y) { return (L[y] > R[x]); } n int query(int x, int p) { n   x = max(0, x); n   p = max(0, p); n   int pos = upper_bound(vc[x].begin(), vc[x].end(), p) - vc[x].begin(); n   return pos; n } n int main() { n   int T, t; n   in(T); n   t = T; n   while (T--) { n     int n; n     in(n); n     for (int i = 1; i <= n; i++) { n       in(a[i]); n       b[i] = a[i]; n     } n     sort(b + 1, b + 1 + n); n     int m = unique(b + 1, b + 1 + n) - b; n     for (int i = 1; i <= n; i++) n       a[i] = lower_bound(b + 1, b + m, a[i]) - b, s[a[i]]++, n       vc[a[i]].push_back(i); n     for (int i = n; i >= 1; i--) L[a[i]] = i; n     for (int i = 1; i <= n; i++) s[i] += s[i - 1], R[a[i]] = i; n     m--; n     int l, r, ans = 0; n     l = r = 1; n     L[m + 1] = L[m]; n     R[m + 1] = R[m]; n     for (int i = 1; i <= m; i++) { n       while (r <= m && check(r, r + 1)) r++; n       int t = query(l - 1, L[l]) + (int)vc[r + 1].size() - query(r + 1, R[r]); n       ans = max(ans, s[r] - s[l - 1] + t); n       if (l == r) { n         for (int j = 0; j < vc[l].size(); j++) { n           ans = max(ans, (int)vc[l].size() + query(l - 1, vc[l][j]) - j); n         } n       } n       ans = max(ans, s[r] - s[l - 1] + query(l - 1, L[l])); n       if (r == m) break; n       l = r + 1; n       r++; n     } n     printf( %d n , n - ans); n     for (int i = 1; i <= n; i++) s[i] = 0, vc[i].clear(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long xa, ya, xb, yb, xc, yc; n   cin >> xa >> ya >> xb >> yb >> xc >> yc; n   long long s1 = (ya - yb) * (xa - xc); n   long long s2 = (xa - xb) * (ya - yc); n   if (s1 == s2) { n     cout <<  TOWARDS ; n     return 0; n   } n   if (s1 > s2) n     cout <<  RIGHT ; n   else n     cout <<  LEFT ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int big = 0, small = 1000000000; n   int a[1000]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > big) { n       big = a[i]; n     } n     if (a[i] < small) { n       small = a[i]; n     } n   } n   cout << big - small + 1 - n; n } n


#include <bits/stdc++.h> n using namespace std; n int a, ta, b, tb, hh, mm, res1, res2; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> a >> ta >> b >> tb; n   char tmp; n   cin >> hh >> tmp >> mm; n   hh -= 5; n   mm += hh * 60; n   if (mm - tb >= 0) res1 = (mm - tb) / b + 1; n   mm += ta; n   mm = min(mm, (24 - 5) * 60); n   mm--; n   res2 = mm / b + 1; n   cout << res2 - res1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int maxl[300005][20], minl[300005][20]; n int vis[2 * 300005]; n int a[300005]; n int lmax[300005], lmin[300005], rmax[300005], rmin[300005]; n int min(int a, int b) { n   if (a > b) return b; n   return a; n } n int max(int a, int b) { n   if (a > b) return a; n   return b; n } n void S_table(int n) { n   int l = int(log((double)n) / log(2.0)); n   for (int j = 1; j <= l; j++) { n     for (int i = 1; i + (1 << (j - 1)) - 1 <= n; ++i) { n       maxl[i][j] = max(maxl[i][j - 1], maxl[i + (1 << (j - 1))][j - 1]); n       minl[i][j] = min(minl[i][j - 1], minl[i + (1 << (j - 1))][j - 1]); n     } n   } n } n int w[300005]; n int rmq(int l, int r) { n   int k = w[r - l + 1]; n   int a1 = max(maxl[l][k], maxl[r - (1 << k) + 1][k]); n   return a1; n } n void init(void) { n   int i; n   for (i = 1; i <= 300002; i++) { n     int k = int(log((double)(i)) / log(2.0)); n     w[i] = k; n   } n } n int rmq1(int l, int r) { n   int k = w[r - l + 1]; n   int a2 = min(minl[l][k], minl[r - (1 << k) + 1][k]); n   return a2; n } n struct pi { n   int a, b; n } pp[300005]; n int cmp(pi a, pi b) { return a.a < b.a; } n long long dfs(int x, int y) { n   if (x == y) return 1; n   if (y - x == 1) { n     if (abs(pp[y].b - pp[x].b) == 1) return 3; n     return 2; n   } n   long long s = 0; n   s = dfs(x, (x + y) / 2); n   s += dfs((x + y) / 2 + 1, y); n   int mid = (x + y) / 2; n   int i; n   lmin[mid + 1] = 1000000000; n   lmax[mid + 1] = -1000000000; n   for (i = mid; i >= x; i--) { n     lmin[i] = min(lmin[i + 1], pp[i].b); n     lmax[i] = max(lmax[i + 1], pp[i].b); n   } n   rmin[mid] = 1000000000; n   rmax[mid] = -1000000000; n   for (i = mid + 1; i <= y; i++) { n     rmin[i] = min(rmin[i - 1], pp[i].b); n     rmax[i] = max(rmax[i - 1], pp[i].b); n   } n   for (i = mid; i >= x; i--) { n     int a, b; n     a = lmax[i]; n     b = lmin[i]; n     if (a - b + 1 > mid - i + 1) { n       int p = a - b + 1 - (mid - i + 1); n       if (p <= y - mid) { n         if (rmax[mid + p] < a && rmin[mid + p] > b) { n           s++; n         } n       } n     } n   } n   for (i = mid + 1; i <= y; i++) { n     int a, b; n     a = rmax[i]; n     b = rmin[i]; n     if (a - b + 1 > i - mid) { n       int p = a - b + 1 - (i - mid); n       if (p <= mid - x + 1) { n         if (lmax[mid - p + 1] < a && lmin[mid - p + 1] > b) { n           s++; n         } n       } n     } n   } n   int ss, tt; n   ss = mid + 1; n   tt = mid + 1; n   for (i = mid; i >= x; i--) { n     int a = lmax[i]; n     int b = lmin[i]; n     while (tt <= y && rmin[tt] >= b) { n       vis[rmax[tt] - tt + 300005]++; n       tt++; n     } n     while (ss <= y && rmax[ss] < a) { n       vis[rmax[ss] - ss + 300005]--; n       ss++; n     } n     if (tt <= ss) continue; n     int p = vis[lmin[i] - i + 300005]; n     if (p > 0) s += p; n   } n   ss = mid; n   tt = mid; n   for (i = mid + 1; i <= y; i++) { n     vis[rmax[i] - i + 300005] = 0; n   } n   for (i = mid + 1; i <= y; i++) { n     int a = rmax[i]; n     int b = rmin[i]; n     while (tt >= x && lmin[tt] >= b) { n       vis[lmax[tt] + tt]++; n       tt--; n     } n     while (ss >= x && lmax[ss] < a) { n       vis[lmax[ss] + ss]--; n       ss--; n     } n     if (tt >= ss) continue; n     int p = vis[rmin[i] + i]; n     if (p > 0) s += p; n   } n   for (i = x; i <= mid; i++) { n     vis[lmax[i] + i] = 0; n   } n   return s; n } n int main() { n   int i, n; n   init(); n   cin >> n; n   for (i = 1; i <= n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     pp[a].b = b; n   } n   for (i = 1; i <= n; i++) { n     maxl[i][0] = pp[i].b; n     minl[i][0] = pp[i].b; n   } n   S_table(n); n   cout << dfs(1, n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string K; n   cin >> K; n   if (K.size() == 1 and k != 0) { n     cout << 0; n     return 0; n   } n   if (k == 0) { n     cout << K; n     return 0; n   } n   if (K[0] !=  1 ) { n     K[0] =  1 ; n     k -= 1; n     for (int i = 1; i < n; ++i) { n       if (k == 0) { n         cout << K; n         return 0; n       } n       if (K[i] !=  0 ) { n         K[i] =  0 ; n         k--; n       } n     } n   } else { n     for (int i = 1; i < n; ++i) { n       if (k == 0) { n         cout << K; n         return 0; n       } n       if (K[i] !=  0 ) { n         K[i] =  0 ; n         k--; n       } n     } n   } n   cout << K; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, p, a[100000], sum = 0; n   cin >> n >> p; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n     sum %= p; n   } n   sum = (sum + p - (a[0] % p)) % p; n   int cur = a[0] % p, ans = cur + sum; n   for (int i = 1; i < n - 1; ++i) { n     cur = (cur + a[i]) % p, sum = (sum + p - (a[i] % p)) % p; n     ans = max(ans, cur + sum); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, c, i, j, flag = 0; n   cin >> r >> c; n   char a1[r][c]; n   for (i = 0; i < r; i++) { n     for (j = 0; j < c; j++) { n       cin >> a1[i][j]; n     } n   } n   for (i = 0; i < r; i++) { n     for (j = 0; j < c; j++) { n       if (a1[i][j] ==  . ) { n         a1[i][j] =  D ; n       } n     } n   } n   for (i = 0; i < r; i++) { n     for (j = 0; j < c; j++) { n       if (a1[i][j] ==  S ) { n         if (i > 0) { n           if (a1[i - 1][j] ==  W ) { n             cout <<  No ; n             return 0; n           } n         } n         if (i < r - 1) { n           if (a1[i + 1][j] ==  W ) { n             cout <<  No ; n             return 0; n           } n         } n         if (j > 0) { n           if (a1[i][j - 1] ==  W ) { n             cout <<  No ; n             return 0; n           } n         } n         if (j < c - 1) { n           if (a1[i][j + 1] ==  W ) { n             cout <<  No ; n             return 0; n           } n         } n       } n     } n   } n   cout <<  Yes  << endl; n   for (i = 0; i < r; i++) { n     for (j = 0; j < c; j++) { n       cout << a1[i][j]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n long long w, m, k; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   cin >> w >> m >> k; n   long long aa = 0; n   int nc = 0; n   while (aa < m) aa = aa * 10 + 9, ++nc; n   long long m2 = m; n   while (w) { n     if ((aa - m + 1) <= w / k / nc) { n       w = w - k * (aa - m + 1) * nc; n       ++nc; n       m = aa + 1; n       aa = aa * 10 + 9; n     } else { n       m = m + w / k / nc; n       break; n     } n   } n   cout << m - m2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x; n vector<int> w; n vector<int> v; n bool volt[1111]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     v.push_back(x); n   } n   reverse(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     if (volt[v[i]] == false) { n       w.push_back(v[i]); n       volt[v[i]] = true; n     } n   } n   reverse(w.begin(), w.end()); n   cout << w.size() << endl; n   for (int i = 0; i < w.size(); i++) { n     cout << w[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2005; n int n, m; n int a[maxn]; n int cnt[maxn], vis[maxn]; n int ans2 = 0; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int ans1 = n / m; n   int p = n % m; n   for (int i = 1; i <= n; i++) { n     if (a[i] > m) continue; n     if (cnt[a[i]] >= ans1) continue; n     cnt[a[i]]++; n     vis[i] = 1; n   } n   for (int i = 1; i <= n; i++) { n     if (vis[i]) continue; n     int Ans1 = 1e9, Ans2 = 1e9; n     for (int j = 1; j <= m; j++) { n       if (cnt[j] < Ans2) Ans2 = cnt[j], Ans1 = j; n     } n     if (Ans2 == ans1) continue; n     ans2++; n     cnt[Ans1]++, a[i] = Ans1; n   } n   cout << ans1 <<     << ans2 << endl; n   for (int i = 1; i <= n; i++) cout << a[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i = 0, j = 0, cs = 0, in; n   int n; n   cin >> n; n   vector<int> v; n   int sum = 0, s = 0; n   for (int i = 1; i < n; i++) { n     cout <<  ?   << i <<     << n <<   n ; n     int x; n     cin >> x; n     if (i > 1) { n       v.push_back(sum - x - s); n       s += v.back(); n     } else n       sum = x; n   } n   cout <<  ?   << 1 <<     << n - 1 <<   n ; n   int x; n   cin >> x; n   cout <<  !  ; n   for (int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   cout << x - s <<     << sum - x <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5; n int N, M, A[MAXN + 10], ans[MAXN + 10]; n int main() { n   int i, j; n   scanf( %d%d , &N, &M); n   long long sum = 0; n   for (i = 1; i <= M; i++) scanf( %d , &A[i]), sum += A[i]; n   if (sum < N) return !printf( -1 ); n   int last = 987654321; n   for (i = M; i >= 1; i--) { n     int t = min(N - A[i] + 1, last - 1); n     if (t <= 0) return !printf( -1 ); n     ans[i] = t; n     last = t; n   } n   int start = 1; n   for (i = 1; i <= M; i++) { n     if (start >= ans[i]) break; n     ans[i] = start; n     start = A[i] + ans[i]; n   } n   for (i = 1; i <= M; i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double p[100008]; n struct Tprogram { n   void open() { n     freopen( 1.in ,  r , stdin); n     freopen( 1.out ,  w , stdout); n   } n   void close() {} n   void init() { n     scanf( %d , &n); n     for (int i = 0; i <= n; i++) scanf( %lf , &p[i]); n   } n   void work() { n     double ans = 0; n     for (int i = 0; i <= n >> 1; i++) n       for (int j = (n >> 1) + 1; j <= n; j++) n         ans = ((p[i] * (2 * j - n) + p[j] * (n - 2 * i)) / (2 * j - 2 * i) > ans n                    ? (p[i] * (2 * j - n) + p[j] * (n - 2 * i)) / (2 * j - 2 * i) n                    : ans); n     printf( %.10lf n , ans); n   } n } Program; n int main() { n   Program.init(); n   Program.work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int m; n   cin >> n >> m; n   vector<int> zahlen(n); n   for (int i = 0; i < n; i++) cin >> zahlen[i]; n   for (int i = 0; i < m; i++) { n     int l, r, x; n     cin >> l >> r >> x; n     l--; n     x--; n     r--; n     int tr = zahlen[x]; n     int count = 0; n     for (int i = l; i <= r; i++) { n       if (zahlen[i] < tr) count++; n     } n     if ((l + count) == x) 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 using ll = long long; n using ii = pair<int, int>; n using vi = vector<int>; n using vll = vector<ll>; n using vii = vector<ii>; n const ll MOD = 998244353; n const ll INF = 1e15 + 9; n const int MAXN = 1000006; n int n, m, a[MAXN], p[MAXN], b[MAXN]; n int rev[MAXN]; n vi pos[MAXN]; n vll sum[MAXN]; n ll dp[MAXN], negsum[MAXN]; n inline ll isum(int val, int R) { n   int index = n       lower_bound(pos[val].begin(), pos[val].end(), R) - pos[val].begin(); n   return sum[val][index]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; ++i) { n     cin >> p[i]; n   } n   cin >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> b[i]; n   } n   a[n + 1] = n + 1; n   b[m + 1] = n + 1; n   ++n, ++m; n   for (int i = 0; i <= m; ++i) { n     sum[2 * i + 1] = sum[2 * i] = vll(1); n   } n   for (int i = 0; i <= n; ++i) { n     int bi = lower_bound(b, b + m, a[i]) - b; n     a[i] = 2 * bi - (b[bi] != a[i]); n     pos[a[i]].push_back(i); n     ll prevsum = sum[a[i]].back(); n     sum[a[i]].push_back(prevsum + max(p[i], 0)); n     negsum[i + 1] = negsum[i] + min(p[i], 0); n   } n   for (int i = 1; i <= n; ++i) { n     if (a[i] & 1) { n       dp[i] = INF; n       continue; n     } n     auto it = lower_bound(pos[a[i] - 2].begin(), pos[a[i] - 2].end(), i); n     if (it == pos[a[i] - 2].begin()) { n       dp[i] = INF; n       continue; n     } n     --it; n     dp[i] = dp[*it] + isum(a[i] - 1, i) + isum(a[i], i) + negsum[i] - n             negsum[*it + 1]; n     it = lower_bound(pos[a[i]].begin(), pos[a[i]].end(), i); n     if (it != pos[a[i]].begin()) { n       --it; n       dp[i] = min(dp[i], dp[*it] + negsum[i + 1] - negsum[*it + 1]); n     } n   } n   if (dp[n] >= INF / 2) { n     cout <<  NO n ; n   } else { n     cout <<  YES n  << dp[n] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, ans; n vector<long long> v[100005]; n vector<long long> res; n long long cost(long long num) { n   res.clear(); n   long long sum = 0; n   long long need = num - v[0].size(); n   for (long long i = 1; i <= 100000; i++) { n     for (long long j = 0; j < v[i].size(); j++) { n       if (v[i].size() - j >= num) { n         need--; n         sum += v[i][j]; n       } else n         res.push_back(v[i][j]); n     } n   } n   sort(res.begin(), res.end()); n   for (long long i = 1; i <= need; i++) { n     sum += res[i - 1]; n   } n   return sum; n } n int main() { n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld%lld , &a, &b); n     v[a].push_back(b); n   } n   for (long long i = 1; i <= 100000; i++) sort(v[i].begin(), v[i].end()); n   long long l = v[0].size(), r = n, m1, m2; n   ans = min(cost(l), cost(r)); n   while (l + 2 < r) { n     m1 = l + (r - l) / 3; n     m2 = r - (r - l) / 3; n     long long a1 = cost(m1); n     long long a2 = cost(m2); n     if (a1 > a2) n       l = m1, ans = min(ans, a2); n     else n       r = m2, ans = min(ans, a1); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Container> n void print(Container& container) { n   auto Start = container.begin(), End = container.end(); n   while (Start != End) cout << *(Start++) <<    ; n   cout <<   n ; n } n const int N = 5e2 + 1; n int dp[2][N][N], a[N]; n inline void solve() { n   int n, m, b, mod; n   cin >> n >> m >> b >> mod; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   dp[0][0][0] = 1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= m; ++j) { n       for (int k = 0; k <= b; ++k) { n         dp[i & 1][j][k] = dp[i & 1 ^ 1][j][k]; n         if (j && k >= a[i]) dp[i & 1][j][k] += dp[i & 1][j - 1][k - a[i]]; n         dp[i & 1][j][k] %= mod; n       } n     } n   } n   int ans = 0; n   for (int k = 0; k <= b; ++k) ans = (ans + dp[n & 1][m][k]) % mod; n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int T = 1; n   while (T--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2; n   getline(cin, s1); n   getline(cin, s2); n   sort(s1.begin(), s1.end()); n   sort(s2.begin(), s2.end()); n   int j(0); n   for (int i = 0; i < s1.size(); i++) { n     while (s2[j] ==    ) j++; n     while (s1[i] ==    ) i++; n     if (s1[i] == s2[j]) j++; n     if (j == s2.size()) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<int> list; n     int maxx, ma; n     for (int i = 0; i < n; i++) { n       int u; n       cin >> u; n       list.push_back(u); n     } n     int u1, u2, u3; n     int flag; n     for (int i = 1; i < n - 1; i++) { n       flag = 0; n       for (int j = 0; j < i; j++) { n         if (list[i] > list[j]) { n           flag = 1; n           u1 = j; n           break; n         } n       } n       for (int j = i + 1; j < n; j++) { n         if (list[i] > list[j]) { n           if (flag == 1) { n             flag = 2; n             u2 = j; n             break; n           } else { n             break; n           } n         } n       } n       if (flag == 2) { n         u3 = i; n         break; n       } n     } n     if (flag == 2) { n       cout <<  YES  << endl; n       cout << u1 + 1 <<     << u3 + 1 <<     << u2 + 1 << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a1[1000007], b1[1000007]; n int main() { n   long long n, i, j, k = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     string st; n     cin >> st; n     long long si = st.size(), c1 = 0, c2 = 0; n     for (j = 0; j < si; j++) { n       if (st[j] ==  ( ) { n         c1++; n       } n       if (st[j] ==  ) ) { n         if (c1 > 0) { n           c1--; n         } else { n           c2++; n         } n       } n     } n     if (c1 == 0 && c2 == 0) n       k++; n     else if (c2 == 0) n       a1[c1]++; n     else if (c1 == 0) n       b1[c2]++; n   } n   long long ans = 0; n   ans = ans + (k / 2); n   for (i = 0; i <= 1000007; i++) { n     ans = ans + min(a1[i], b1[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int DEBUG = 0; n bool isss(vector<int> s1, vector<int> s2) { n   int si1, si2; n   si1 = s1.size(); n   si2 = s2.size(); n   for (int i = 0; i < si1; i++) { n     bool ttt = false; n     for (int j = 0; j < si2; j++) { n       if (s1[i] == s2[j]) { n         ttt = true; n       } n     } n     if (!ttt) return false; n   } n   return true; n } n int main(int argc, char **argv) { n   DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; n   int n; n   cin >> n; n   int m[n]; n   vector<int> a[n]; n   for (int i = 0; i < n; i++) { n     cin >> m[i]; n     for (int j = 0; j < m[i]; j++) { n       int tmp; n       cin >> tmp; n       a[i].push_back(tmp); n     } n   } n   bool isp[n]; n   for (int i = 0; i < n; i++) isp[i] = true; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i != j) { n         if (isss(a[i], a[j])) { n           isp[j] = false; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) n     if (isp[i]) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; 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 arr[3][3]; n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) cin >> arr[i][j]; n   } n   bool chk[3][3]; n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) chk[i][j] = 1; n   } n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       if (arr[i][j] % 2 == 0) n         continue; n       else { n         if (chk[i][j] == 1) n           chk[i][j] = 0; n         else n           chk[i][j] = 1; n         if (j + 1 <= 2) { n           if (chk[i][j + 1] == 1) n             chk[i][j + 1] = 0; n           else n             chk[i][j + 1] = 1; n         } n         if (j - 1 >= 0) { n           if (chk[i][j - 1] == 1) n             chk[i][j - 1] = 0; n           else n             chk[i][j - 1] = 1; n         } n         if (i + 1 <= 2) { n           if (chk[i + 1][j] == 1) n             chk[i + 1][j] = 0; n           else n             chk[i + 1][j] = 1; n         } n         if (i - 1 >= 0) { n           if (chk[i - 1][j] == 1) n             chk[i - 1][j] = 0; n           else n             chk[i - 1][j] = 1; n         } n       } n     } n   } n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       cout << chk[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = (long long)1e5 + 10; n vector<long long> G[MAXN]; n pair<long long, long long> p; n vector<long long> v; n long long n, x, y, k, ans, sum, flag; n string s; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     v.push_back(x); n     v.push_back(y); n   } n   cin >> k; n   long long i = 0; n   while (!flag) { n     if (v[i] < k) { n       i++; n     } else { n       flag = 1; n       i--; n     } n   } n   cout << n - (i + 1) / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, i, j, k; n   cin >> n; n   vector<string> v; n   vector<pair<int, string> > v1; n   for (i = 0; i < n; i++) { n     string s; n     cin >> s; n     v.push_back(s); n     v1.push_back(make_pair(s.length(), s)); n   } n   sort(v1.begin(), v1.end()); n   int flag = 1; n   for (i = n - 1; i >= 0; i--) { n     pair<int, string> temp = v1[i]; n     string s = temp.second; n     for (j = 0; j < i; j++) { n       pair<int, string> temp1 = v1[j]; n       string s1 = temp1.second; n       if (s.length() != s1.length()) { n         if (s.find(s1) != std::string::npos) n           continue; n         else { n           flag = 0; n           break; n         } n       } else { n         if (s != s1) { n           flag = 0; n           break; n         } n       } n     } n     if (flag == 0) break; n   } n   if (flag == 0) n     cout <<  NO n ; n   else { n     cout <<  YES n ; n     for (i = 0; i < n; i++) cout << v1[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 50 + 10; n int a[maxn][maxn]; n int dx[10] = {0, 2, 1, 0, -1, -2}; n int dy[10] = {2, 0, 1, -2, -1, 0}; n int sx, sy; n struct Node { n   int x, y; n }; n int main() { n   int n; n   scanf( %d , &n); n   memset(a, -1, sizeof(a)); n   a[1][1] = 1; n   a[n][n] = 0; n   queue<Node> q; n   q.push((Node){1, 1}); n   while (!q.empty()) { n     Node tmp = q.front(); n     q.pop(); n     int x = tmp.x, y = tmp.y; n     for (int i = 0; i < 3; i++) { n       int tx = x + dx[i], ty = y + dy[i]; n       if (tx < 1 || ty < 1 || tx > n || ty > n) continue; n       if (a[tx][ty] != -1) continue; n       cout <<  ?  <<     << x <<     << y <<     << tx <<     << ty <<   n ; n       cout.flush(); n       int t; n       cin >> t; n       a[tx][ty] = t ? a[x][y] : a[x][y] ^ 1; n       q.push((Node){tx, ty}); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (i + 2 > n) break; n     for (int j = 1; j <= n; j++) { n       if (j + 2 > n) break; n       if (a[i][j] == 1 && a[i + 2][j + 2] == 0) { n         sx = i, sy = j; n         break; n       } n     } n   } n   int tmp; n   cout <<  ?  <<     << sx <<     << sy + 1 <<     << sx + 1 <<     << sy + 2 n        <<   n ; n   cout.flush(); n   cin >> tmp; n   if (tmp) { n     cout <<  ?  <<     << sx <<     << sy <<     << sx + 1 <<     << sy + 2 n          <<   n ; n     cout.flush(); n     cin >> tmp; n     if (tmp) { n       a[sx][sy + 1] = a[sx + 1][sy + 2] = 1; n     } else { n       if (a[sx][sy + 2] == 1) { n         a[sx][sy + 1] = a[sx + 1][sy + 2] = 0; n       } else { n         cout <<  ?  <<     << sx <<     << sy + 1 <<     << sx + 2 <<     n              << sy + 2 <<   n ; n         cout.flush(); n         cin >> tmp; n         if (tmp) { n           a[sx][sy + 1] = a[sx + 1][sy + 2] = 0; n         } else { n           a[sx][sy + 1] = a[sx + 1][sy + 2] = 1; n         } n       } n     } n   } else { n     cout <<  ?  <<     << sx <<     << sy <<     << sx + 1 <<     << sy + 2 n          <<   n ; n     cout.flush(); n     cin >> tmp; n     if (tmp) { n       a[sx][sy + 1] = 0; n       a[sx + 1][sy + 2] = 1; n     } else { n       cout <<  ?  <<     << sx <<     << sy + 1 <<     << sx + 2 <<     n            << sy + 2 <<   n ; n       cout.flush(); n       cin >> tmp; n       if (tmp) { n         a[sx][sy + 1] = 0; n         a[sx + 1][sy + 2] = 1; n       } else { n         a[sx][sy + 1] = 1; n         a[sx + 1][sy + 2] = 0; n       } n     } n   } n   q.push((Node){sx, sy + 1}); n   while (!q.empty()) { n     Node tmp = q.front(); n     q.pop(); n     int x = tmp.x, y = tmp.y; n     for (int i = 0; i < 6; i++) { n       int tx = x + dx[i], ty = y + dy[i]; n       if (tx < 1 || ty < 1 || tx > n || ty > n) continue; n       if (a[tx][ty] != -1) continue; n       if (i < 3) n         cout <<  ?  <<     << x <<     << y <<     << tx <<     << ty <<   n ; n       else n         cout <<  ?  <<     << tx <<     << ty <<     << x <<     << y <<   n ; n       cout.flush(); n       int t; n       cin >> t; n       a[tx][ty] = t ? a[x][y] : a[x][y] ^ 1; n       q.push((Node){tx, ty}); n     } n   } n   cout <<  !  <<   n ; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cout << a[i][j]; n     } n     cout <<   n ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, i, sum = 0, x, count = 0; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     sum = sum + a[i]; n   } n   sort(a, a + n); n   if (sum % 2 == 0) { n     cout << sum; n     return 0; n   } else { n     for (i = 0; i < n; i++) { n       x = sum - a[i]; n       if (x % 2 == 0) { n         cout << x; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool m(int i, int j) { return (i % 10) > (j % 10); } n int main() { n   int x, y; n   cin >> y >> x; n   vector<int> vi; n   int i = 0, j = 0; n   int k = 0; n   for (i = 0; i < y; i++) { n     cin >> j; n     k += (j % 10); n     vi.push_back(j); n   } n   sort(vi.begin(), vi.begin() + y, m); n   for (i = 0; i < y && x > 0; i++) { n     k = (10 - (vi[i] % 10)); n     if (x >= k && (vi[i] + k) <= 100) { n       x -= k; n       vi[i] += k; n     } n   } n   for (i = 0; i < y && x > 0; i++) { n     while ((vi[i] < 100) && (x >= 10)) { n       vi[i] += 10; n       x -= 10; n     } n   } n   k = 0; n   for (i = 0; i < y; i++) k += vi[i] / 10; n   cout << k <<    ; n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n const int T = 1 << 19; n struct nod { n   int best = 0, best2 = 0; n   int pref0 = 0, pref1 = 0, suf0 = 0, suf1 = 0; n   int pref01 = 0, pref10 = 0, suf01 = 0, suf10 = 0; n   int cnt0 = 0, cnt1 = 0; n }; n void umax(int &a, int b) { a = max(a, b); } n nod merge(nod a, nod b) { n   nod c; n   c.cnt0 = a.cnt0 + b.cnt0; n   c.cnt1 = a.cnt1 + b.cnt1; n   c.best = max({a.best, b.best, a.suf01 + b.pref1, a.suf0 + b.pref01}); n   c.best2 = max({a.best2, b.best2, a.suf10 + b.pref0, a.suf1 + b.pref10}); n   c.suf0 = (b.cnt1 == 0 ? b.suf0 + a.suf0 : b.suf0); n   c.suf1 = (b.cnt0 == 0 ? b.suf1 + a.suf1 : b.suf1); n   c.pref0 = (a.cnt1 == 0 ? a.pref0 + b.pref0 : a.pref0); n   c.pref1 = (a.cnt0 == 0 ? a.pref1 + b.pref1 : a.pref1); n   c.pref01 = (a.cnt1 == 0 ? a.cnt0 + b.pref01 : a.pref01); n   if (a.pref01 == a.cnt0 + a.cnt1) umax(c.pref01, a.pref01 + b.pref1); n   umax(c.pref01, max(c.pref0, c.pref1)); n   c.pref10 = (a.cnt0 == 0 ? a.cnt1 + b.pref10 : a.pref10); n   if (a.pref10 == a.cnt0 + a.cnt1) umax(c.pref10, a.pref10 + b.pref0); n   umax(c.pref10, max(c.pref0, c.pref1)); n   c.suf01 = (b.cnt0 == 0 ? b.cnt1 + a.suf01 : b.suf01); n   if (b.suf01 == b.cnt0 + b.cnt1) umax(c.suf01, b.suf01 + a.suf0); n   umax(c.suf01, max(c.suf0, c.suf1)); n   c.suf10 = (b.cnt1 == 0 ? b.cnt0 + a.suf10 : b.suf10); n   if (b.suf10 == b.cnt0 + b.cnt1) umax(c.suf10, b.suf10 + a.suf1); n   umax(c.suf10, max(c.suf0, c.suf1)); n   return c; n } n nod t[T + T]; n bool tag[T + T]; n int n, m; n char s[T]; n void odwroc(int v) { n   swap(t[v].best, t[v].best2); n   swap(t[v].cnt0, t[v].cnt1); n   swap(t[v].pref01, t[v].pref10); n   swap(t[v].suf01, t[v].suf10); n   swap(t[v].pref0, t[v].pref1); n   swap(t[v].suf0, t[v].suf1); n } n void push(int v) { n   if (!tag[v]) return; n   for (auto u : {2 * v, 2 * v + 1}) { n     tag[u] ^= 1; n     odwroc(u); n   } n   tag[v] = 0; n } n void invert(int x, int y, int v = 1, int l = 0, int r = T - 1) { n   if (x <= l && r <= y) { n     tag[v] ^= 1; n     odwroc(v); n     return; n   } n   push(v); n   int m = (l + r) / 2; n   if (x <= m) invert(x, y, 2 * v, l, m); n   if (m < y) invert(x, y, 2 * v + 1, m + 1, r); n   t[v] = merge(t[2 * v], t[2 * v + 1]); n } n nod query(int x, int y, int v = 1, int l = 0, int r = T - 1) { n   if (x <= l && r <= y) { n     return t[v]; n   } n   push(v); n   nod res; n   int m = (l + r) / 2; n   if (x <= m) res = merge(res, query(x, y, 2 * v, l, m)); n   if (m < y) res = merge(res, query(x, y, 2 * v + 1, m + 1, r)); n   return res; n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %s , s + 1); n   for (int i = 1; i <= n; ++i) { n     int v = i + T; n     t[v].best = 1; n     if (s[i] ==  > ) n       t[v].pref0 = t[v].suf0 = t[v].pref01 = t[v].pref10 = t[v].suf01 = n           t[v].suf10 = t[v].cnt0 = t[v].best2 = 1; n     else n       t[v].pref1 = t[v].suf1 = t[v].pref01 = t[v].pref10 = t[v].suf01 = n           t[v].suf10 = t[v].cnt1 = t[v].best2 = 1; n   } n   for (int i = T - 1; 1 <= i; --i) t[i] = merge(t[2 * i], t[2 * i + 1]); n   while (m--) { n     int a, b; n     scanf( %d%d , &a, &b); n     invert(a, b); n     printf( %d n , query(a, b).best); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long y = 0; n   unsigned int x = 0; n   int i; n   string s; n   cin >> s; n   if (s.length() > 19) n     printf( BigInteger n ); n   else if (s.length() > 10) { n     y = 0; n     for (i = 0; i < s.length(); i++) { n       if (y > 0) y *= 10; n       y += s[i] -  0 ; n     } n     if (y > 9223372036854775807) n       printf( BigInteger n ); n     else n       printf( long n ); n   } else if (s.length() > 5) { n     y = 0; n     for (i = 0; i < s.length(); i++) { n       if (y > 0) y *= 10; n       y += s[i] -  0 ; n     } n     if (y > 2147483647) n       printf( long n ); n     else n       printf( int n ); n   } else if (s.length() > 3) { n     y = 0; n     for (i = 0; i < s.length(); i++) { n       if (y > 0) y *= 10; n       y += s[i] -  0 ; n     } n     if (y > 32767) n       printf( int n ); n     else n       printf( short n ); n   } else if (s.length() > 0) { n     y = 0; n     for (i = 0; i < s.length(); i++) { n       if (y > 0) y *= 10; n       y += s[i] -  0 ; n     } n     if (y > 127) n       printf( short n ); n     else n       printf( byte n ); n   } else n     printf( byte n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, sum = 0, p = 0, res = 0; n   map<long long, long long> m; n   cin >> n; n   m[0] = 1; n   for (long long i = 1; i <= n; i++) { n     cin >> a; n     sum += a; n     p = max(p, m[sum]); n     res += i - p; n     m[sum] = i + 1; n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n int lo[N]; n int n, r[N], lb[N], rb[N], i, j, k; n struct ST { n   pair<int, int> f[20][N]; n   function<pair<int, int>(pair<int, int>, pair<int, int>)> uni; n   void ini(int* a) { n     for (int i = 1; i <= n * 3; ++i) f[0][i] = {a[i], i}; n     for (int i = 1; (1 << i) <= n * 3; ++i) n       for (int j = 1; j + (1 << i) - 1 <= n * 3; ++j) n         f[i][j] = uni(f[i - 1][j], f[i - 1][j + (1 << i - 1)]); n   } n   inline pair<int, int> ask(int x, int y) { n     int l = lo[y - x + 1]; n     return uni(f[l][x], f[l][y - (1 << l) + 1]); n   } n } ss[2]; n int anc[2][20][N]; n inline int calc(int x, int y) { n   int x1, y1, step = 0, x2, y2; n   x1 = ss[0].ask(x, y).second; n   y1 = ss[1].ask(x, y).second; n   for (int i = 19; i >= 0; --i) { n     x2 = anc[0][i][x1]; n     y2 = anc[1][i][y1]; n     if (rb[y2] - lb[x2] + 1 >= n || n         (lb[x2] < x && ss[1].ask(lb[x2], x - 1).first > y) || n         (y < rb[y2] && ss[0].ask(y + 1, rb[y2]).first < x)) n       continue; n     step += 1 << i; n     x1 = x2; n     y1 = y2; n   } n   x1 = lb[x1]; n   y1 = rb[y1]; n   ++step; n   return y1 - x1 + 1 >= n ? step : calc(x1, y1) + step; n } n int main() { n   for (i = 2; i < N; ++i) lo[i] = lo[i >> 1] + 1; n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (i = 1; i <= n; ++i) cin >> r[i], r[i + n] = r[i + n * 2] = r[i]; n   for (i = 1; i <= n * 3; ++i) n     lb[i] = max(1, i - r[i]), rb[i] = min(n * 3, i + r[i]); n   ss[0].uni = [&](pair<int, int> a, pair<int, int> b) { return min(a, b); }; n   ss[1].uni = [&](pair<int, int> a, pair<int, int> b) { return max(a, b); }; n   ss[0].ini(lb); n   ss[1].ini(rb); n   for (i = 1; i <= n * 3; ++i) n     anc[0][0][i] = ss[0].ask(lb[i], rb[i]).second, n     anc[1][0][i] = ss[1].ask(lb[i], rb[i]).second; n   for (k = 0; k < 2; ++k) n     for (i = 1; i < 20; ++i) n       for (j = 1; j <= n * 3; ++j) n         anc[k][i][j] = anc[k][i - 1][anc[k][i - 1][j]]; n   for (i = n + 1; i <= n * 2; ++i) cout << (n == 1 ? 0 : calc(i, i)) <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int gcd(int a, int b) { n   if (b == 0) return a; n   gcd(b, a % b); n } n int lcm(int a, int b) { return a * b / gcd(a, b); } n int main() { n   Fast(); n   string s; n   cin >> s; n   int cnt = 0; n   while (s.size() >= 2) { n     int n = 0; n     for (int i = 0; i < s.length(); i++) n += s[i] -  0 ; n     s = to_string(n); n     cnt++; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int inf = 0x7fffffff; n const int maxn = 505; n const long long mod = 1e9 + 7; n long long dp[maxn][maxn]; n int n; n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   dp[1][1] = dp[1][0] = 1; n   for (int i = 2; i <= n; i++) { n     for (int j = 0; j <= n; j++) { n       for (int k = 0; k + j <= n; k++) { n         long long x = (dp[i - 1][j] * dp[i - 1][k]) % mod; n         dp[i][k + j] += x * (2 * (k + j) + 1); n         dp[i][k + j] %= mod; n         dp[i][k + j + 1] = (dp[i][k + j + 1] + x) % mod; n         dp[i][k + j - 1] += x * (k + j) * (k + j - 1); n         dp[i][k + j - 1] %= mod; n       } n     } n   } n   cout << dp[n][1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> primes; n int prime_marker[1000000]; n void PrecomputePrimes() { n   const int MAX_PRIME = 1000000; n   for (int i = 2; i * i < MAX_PRIME; ++i) { n     for (int j = i; i * j < MAX_PRIME; ++j) { n       prime_marker[i * j] = 1; n     } n   } n   for (int i = 2; i < MAX_PRIME; ++i) { n     if (prime_marker[i]) continue; n     primes.push_back(i); n   } n } n vector<int64_t> prime_factors; n vector<int> factor_max_power; n void ComputePrimeFactors(int64_t val) { n   for (int i = 0; i < primes.size(); ++i) { n     if (val % primes[i] == 0) { n       prime_factors.push_back(primes[i]); n       factor_max_power.push_back(0); n       while (val % primes[i] == 0) { n         val /= primes[i]; n         factor_max_power.back()++; n       } n     } n   } n   if (val > 1000000) { n     prime_factors.push_back(val); n     factor_max_power.push_back(1); n   } n } n vector<int64_t> arr; n vector<int> cofactor_power; n void ComputeCofactorPower(int64_t val) { n   cofactor_power.resize(prime_factors.size()); n   for (int i = 0; i < prime_factors.size(); ++i) { n     cofactor_power[i] = 0; n     if (val % prime_factors[i] == 0) { n       while (val % prime_factors[i] == 0) { n         val /= prime_factors[i]; n         cofactor_power[i]++; n       } n     } n   } n } n vector<int> basis; n void InitializeBasis() { n   basis.resize(prime_factors.size()); n   basis[0] = 1; n   for (int i = 1; i < prime_factors.size(); ++i) { n     basis[i] = basis[i - 1] * (factor_max_power[i - 1] + 1); n   } n } n void MapToIndices(int hash, vector<int>* indices) { n   for (int i = basis.size() - 1; i >= 0; --i) { n     (*indices)[i] = hash / basis[i]; n     hash -= (*indices)[i] * basis[i]; n   } n } n int IndicesToHash(const vector<int>& indices) { n   int hash = 0; n   for (int i = 0; i < indices.size(); ++i) { n     hash += indices[i] * basis[i]; n   } n   return hash; n } n vector<vector<int>> hash_indices; n void InitHashIndices(int max_hash) { n   hash_indices.resize(max_hash, vector<int>(basis.size())); n   for (int i = 0; i < max_hash; ++i) { n     MapToIndices(i, &hash_indices[i]); n   } n } n struct DpState { n   int length = 100000; n   int64_t cost = 0; n   int parent; n   bool is_chosen = false; n   DpState(int length, int64_t cost, int parent, bool is_chosen) n       : length(length), cost(cost), parent(parent), is_chosen(is_chosen) {} n   DpState() {} n   bool operator<(const DpState& other) const { n     if (length == other.length) return cost < other.cost; n     return length < other.length; n   } n }; n DpState dp[1003][7000]; n void UpdateDP(int cur, int hash, const vector<int>& indices) { n   if (cur == 0) { n     if (hash == 0) { n       dp[cur][hash] = DpState{0, 0, -1, false}; n       return; n     } n     bool is_divisible = true; n     for (int i = 0; i < indices.size(); ++i) { n       if (indices[i] > cofactor_power[i]) { n         is_divisible = false; n         break; n       } n     } n     if (is_divisible) { n       dp[cur][hash] = DpState{1, arr[cur], -1, true}; n     } n     return; n   } n   vector<int> prev_indices(indices.size()); n   for (int i = 0; i < indices.size(); ++i) { n     prev_indices[i] = max(0, indices[i] - cofactor_power[i]); n   } n   int prev_hash = IndicesToHash(prev_indices); n   DpState state1 = {dp[cur - 1][prev_hash].length + 1, n                     dp[cur - 1][prev_hash].cost + arr[cur], prev_hash, true}; n   DpState state2 = {dp[cur - 1][hash].length, dp[cur - 1][hash].cost, hash, n                     false}; n   if (state1 < state2) { n     dp[cur][hash] = state1; n   } else { n     dp[cur][hash] = state2; n   } n } n int main() { n   int n; n   int64_t k; n   PrecomputePrimes(); n   scanf( %d , &n); n   cin >> k; n   int64_t val; n   for (int i = 0; i < n; ++i) { n     cin >> val; n     arr.push_back(val); n   } n   if (k == 1) { n     int lowest_index = 0; n     for (int i = 1; i < n; ++i) { n       if (arr[i] < arr[lowest_index]) lowest_index = i; n     } n     printf( 1 n%d n , lowest_index + 1); n     return 0; n   } n   ComputePrimeFactors(k); n   InitializeBasis(); n   int max_hash = basis.back() * (factor_max_power.back() + 1); n   InitHashIndices(max_hash); n   for (int i = 0; i < n; ++i) { n     ComputeCofactorPower(arr[i]); n     for (int hash = 0; hash < max_hash; ++hash) { n       UpdateDP(i, hash, hash_indices[hash]); n     } n   } n   int cur_hash = max_hash - 1; n   if (dp[n - 1][cur_hash].length >= 100000) { n     printf( -1 n ); n     return 0; n   } n   printf( %d n , dp[n - 1][cur_hash].length); n   for (int i = n - 1; i >= 0; --i) { n     if (dp[i][cur_hash].is_chosen) { n       printf( %d  , i + 1); n     } n     cur_hash = dp[i][cur_hash].parent; n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int n, i, d; n   cin >> n; n   long int a[n], b[n], c[1000000]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (i = 0; i < n; i++) { n     cin >> b[i]; n     c[b[i]] = i; n   } n   d = 0; n   for (i = 1; i < n; i++) { n     if (c[a[i]] < c[a[i - 1]]) { n       d++; n       c[a[i]] = c[a[i - 1]]; n     } n   } n   cout << d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> per, obs; n long long n, k, p; n bool check(long long t) { n   long long i = 0; n   for (long long j = 0; j <= obs.size() - 1; j++) { n     if (abs(per[i] - obs[j]) + abs(p - obs[j]) <= t) { n       i++; n       if (i == n) return 1; n     } n   } n   return 0; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   t = 1; n   for (long long test = 1; test <= t; test++) { n     cin >> n >> k >> p; n     per.resize(n); n     obs.resize(k); n     for (long long i = 0; i <= n - 1; i++) cin >> per[i]; n     for (long long i = 0; i <= k - 1; i++) cin >> obs[i]; n     sort(per.begin(), per.end()); n     sort(obs.begin(), obs.end()); n     long long ans = 1e10, st = 0, end = 1e10; n     while (st <= end) { n       long long mid = (st + end) >> 1; n       if (check(mid)) { n         ans = min(ans, mid); n         end = mid - 1; n       } else n         st = mid + 1; n     } n     cout << ans; n   } n   return 0; n } n


#include <cstdio> n #include <cstring> n #include <iostream> n #include <vector> n #include <cmath> n #include <cstdlib> n #include <ctime> n #include <algorithm> n #include <string> n #include <map> n #define ll long long n #define ls id << 1 n #define rs id << 1 | 1 n #define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type)) n #define memarray(array, value) memset(array, value, sizeof(array)) n #define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value) n #define fillvector(v, value) fill((v).begin(), (v).end(), value) n #define pb(x) push_back(x) n #define st(x) (1LL << (x)) n #define pii pair<int, int> n #define mp(a, b) make_pair((a), (b)) n #define Flush fflush(stdout) n #define vecfirst (*vec.begin()) n #define veclast (*vec.rbegin()) n #define vecall(v) (v).begin(), (v).end() n #define vecupsort(v) (sort((v).begin(), (v).end())) n #define vecdownsort(v, type) (sort(vecall(v), greater<type>())) n #define veccmpsort(v, cmp) (sort(vecall(v), cmp)) n using namespace std; n const int N = 500050; n const int inf = 0x3f3f3f3f; n const ll llinf = 0x3f3f3f3f3f3f3f3f; n const int mod = 998244353; n const int MOD = 1e9 + 7; n const double PI = acos(-1.0); n clock_t TIME__START, TIME__END; n void program_end() n { n #ifdef ONLINE n     printf(  n nTime used: %.6lf(s) n , ((double)TIME__END - TIME__START) / 1000); n     system( pause ); n #endif n } n int n; n int ask1(int x, int y) n { n     printf( 1 %d %d n , x, y), Flush; n     int ret; n     scanf( %d , &ret); n     return ret; n } n int ask2(int x, const vector<int> &vec) n { n     printf( 2 %d %d , x, (int)vec.size()); n     for (auto i : vec) n         printf(  %d , i); n     putchar(  n ), Flush; n     int ret; n     scanf( %d , &ret); n     return ret; n } n int ans[105][105]; n vector<int> e; n  n vector<int> mergesort(int l, int r) n { n     vector<int> ret; n     if (l == r) n     { n         ret.push_back(l); n         return ret; n     } n     int mid = (l + r) >> 1; n     auto vl = mergesort(l, mid); n     auto vr = mergesort(mid + 1, r); n     int i = 0, j = 0; n     while (i < (int)vl.size() && j < (int)vr.size()) n     { n         int r = ask1(vl[i], vr[j]); n         if (r == 1) n         { n             ret.push_back(vl[i]); n             i++; n         } n         else n         { n             ret.push_back(vr[j]); n             j++; n         } n     } n     while (i < (int)vl.size()) n         ret.push_back(vl[i]), i++; n     while (j < (int)vr.size()) n         ret.push_back(vr[j]), j++; n     return ret; n } n  n void work1() n { n     e.clear(); n     e = mergesort(0, n - 1); n     for (int i = 0; i < (int)e.size(); ++i) n         for (int j = i; j < (int)e.size(); ++j) n             ans[e[i]][e[j]] = 1; n } n  n inline void solve() n { n     memarray(ans, 0); n     scanf( %d , &n); n     work1(); n     int u = n - 1, p = n - 2; n #ifdef VINGYING n     printf( Hamiton:  ); n     for (auto i : e) n         cout << i <<    ; n     putchar(  n ); n #endif n     while (u >= 0 && p >= 0) n     { n         vector<int> v; n         for (int i = 0; i <= p; ++i) n             v.push_back(e[i]); n         int r = ask2(e[u], v); n         if (r == 1) n             p--; n         if (p < 0) n         { n             ans[e[u]][e[0]]=1; n             break; n         } n         if (r == 0) n         { n             ans[e[u]][e[p+1]]=1; n             u--; n             if (p==u)p--; n             if (p < 0) n          { n              ans[e[u]][e[0]]=1; n              break; n          } n         } n     } n     for(int k=0;k<n;k++) n      for(int i=0;i<n;i++) n       for(int j=0;j<n;j++) n        ans[i][j]=(ans[i][j]||(ans[i][k]&&ans[k][j])); n     printf( 3 n ); n     for (int i = 0; i < n; ++i, putchar(  n )) n         for (int j = 0; j < n; ++j) n             printf( %d , ans[i][j]); n     Flush; n     int resp; n     scanf( %d ,&resp); n     if(resp==-1)exit(0); n } n  n int main() n { n     TIME__START = clock(); n     int Test = 1; n     scanf( %d , &Test); n     while (Test--) n     { n         solve(); n         // if (Test) n         //     putchar(  n ); n     } n     TIME__END = clock(); n     program_end(); n     return 0; n }


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n template <class T> n inline void checkmin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (a < b) a = b; n } n const int oo = 1 << 30; n const double eps = 1e-7; n const int N = 512; n const int M = 1; n const long long P = 10000000097ll; n int sgn(double x) { return (x > eps) - (x < -eps); } n int fcmp(double a, double b) { return sgn(a - b); } n double sqr(double x) { return x * x; } n struct Point { n   double x, y; n   Point() {} n   Point(double a, double b) : x(a), y(b) {} n   Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } n   Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } n   Point operator*(double d) const { return Point(x * d, y * d); } n   double operator*(const Point &p) const { return x * p.y - y * p.x; } n   Point operator/(double d) const { return Point(x / d, y / d); } n   double norm() const { return sqrt(x * x + y * y); } n   Point rot(double alpha) const { n     return Point(x * cos(alpha) - y * sin(alpha), n                  x * sin(alpha) + y * cos(alpha)); n   } n   void cin() { scanf( %lf %lf , &x, &y); } n   void cout(char *s =  p =  ) const { printf( %s %f %f , s, x, y); } n }; n struct Line { n   Point a, b; n   Line() {} n   Line(const Point &p, const Point &q) : a(p), b(q) {} n   bool para(const Line &lin) const { n     Point u, v; n     u = b - a; n     v = lin.b - lin.a; n     return sgn(u * v) == 0; n   } n   bool l_to_s(const Line &seg) const { n     return sgn((b - a) * (seg.a - a)) * sgn((b - a) * (seg.b - a)) < 0; n   } n   bool s_to_s(const Line &seg) const { n     return l_to_s(seg) && seg.l_to_s(*this); n   } n   Point l_on_l(const Line &lin) const { n     double s1, s2; n     s1 = (lin.a - a) * (lin.b - a); n     s2 = (lin.b - b) * (lin.a - b); n     return (a * s2 + b * s1) / (s1 + s2); n   } n   int l_to_p(const Point &p) const { return sgn((b - a) * (p - a)); } n }; n Point ar[N][5]; n Point br[N][5]; n Point tmple[2][N]; n Point *x, *y; n double h, f; n int n; n double ans; n double area(Point *p, int pn) { n   int i, j, k; n   double ans = 0; n   for (i = 1; i < pn; i++) ans += (p[i] - p[0]) * (p[i + 1] - p[0]); n   if (pn < -11) { n     for (i = 0; i < (pn); i++) printf( %.3f %.3f-->  , p[i].x, p[i].y); n     puts(  ); n   } n   return ans; n } n void read() { n   int i, j, k; n   double a, b; n   double fix, low; n   ans = 0; n   scanf( %d , &n); n   scanf( %lf %lf , &h, &f); n   fix = f / (f - h); n   low = (f + h) / (f - h); n   for (i = 0; i < (n); i++) { n     scanf( %lf %lf , &a, &b); n     ar[i][0] = Point(a * fix, 0); n     ar[i][1] = Point(b * fix, 0); n     ar[i][2] = Point(b, h); n     ar[i][3] = Point(a, h); n     ar[i][4] = ar[i][0]; n     br[i][0] = Point(a * fix, 0); n     br[i][1] = Point(b * fix, 0); n     br[i][2] = Point(b * low, h); n     br[i][3] = Point(a * low, h); n     br[i][4] = br[i][0]; n     ans += area(ar[i], 4) + area(br[i], 4); n   } n } n void cut(Point *p) { n   int xn, yn; n   int i, j, k; n   int ii, jj; n   Line lin, seg; n   for (i = 0; i < (n); i++) { n     for (j = 0; j < (5); j++) x[j] = p[j]; n     xn = 4; n     for (j = 0; j < (4); j++) { n       lin = Line(ar[i][j], ar[i][j + 1]); n       yn = 0; n       for (ii = 1; ii <= xn; ii++) { n         seg = Line(x[ii - 1], x[ii]); n         if (lin.l_to_s(seg)) y[yn++] = lin.l_on_l(seg); n         if (lin.l_to_p(x[ii]) >= 0) y[yn++] = x[ii]; n       } n       y[yn] = y[0]; n       swap(x, y); n       swap(xn, yn); n     } n     ans -= area(x, xn); n   } n } n void sub() { n   int i, j, k; n   x = tmple[0]; n   y = tmple[1]; n   for (i = 0; i < (n); i++) cut(br[i]); n } n int main() { n   int T, _ = 0; n   read(); n   sub(); n   printf( %.6f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int n, c; n void p(int a) { n   if (a <= n) { n     c++; n     p(a * 10); n     p(a * 10 + 1); n   } n } n int main() { n   std::cin >> n; n   p(1); n   std::cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200100; n const int M = 2 * N; n const long long MOD1 = 98764321261LL; n const long long MOD = 998244353LL; n inline int lowbit(int x) { return x & (-x); } n struct fenwick { n   long long a[N]; n   int n; n   void init(int n) { n     for (int i = 0; i <= n; ++i) a[i] = 0; n     this->n = n; n   } n   void add(int x, long long v) { n     for (int i = x; i <= n; i += lowbit(i)) a[i] += v; n   } n   long long query(int x) { n     long long ret = 0; n     for (int i = x; i; i ^= lowbit(i)) ret += a[i]; n     return ret; n   } n   void rangeadd(int l, int r, long long v) { n     add(l, v); n     add(r + 1, -v); n   } n   long long rangequery(int l, int r) { n     l = max(l, 1); n     r = min(r, n); n     if (r < l) return 0; n     long long ret = query(r); n     ret -= query(l - 1); n     return ret; n   } n }; n inline long long powmod(long long x, long long y, long long MOD) { n   long long ret = 1; n   while (y) { n     if (y & 1LL) ret = ret * x % MOD; n     x = x * x % MOD; n     y = y >> 1; n   } n   return ret; n } n struct graph { n   int head[N], next[M], to[M]; n   int tot; n   inline void init(int n) { n     for (int i = 0; i <= n; ++i) head[i] = -1; n     tot = 0; n   } n   inline void addedge(int x, int y) { n     to[tot] = y; n     next[tot] = head[x]; n     head[x] = tot; n     ++tot; n   } n }; n struct point { n   long long x, y; n   point() {} n   point(long long x, long long y) : x(x), y(y) {} n   void read() { scanf( %lld%lld , &x, &y); } n   point operator+(const point &rhs) const { n     return point(x + rhs.x, y + rhs.y); n   } n   point operator-(const point &rhs) const { n     return point(x - rhs.x, y - rhs.y); n   } n   long long operator^(const point &rhs) const { return x * rhs.y - y * rhs.x; } n   bool operator<(const point &rhs) const { n     if (y != rhs.y) return y < rhs.y; n     return x < rhs.x; n   } n }; n long long phi(long long x) { n   long long res = x; n   for (long long i = 2; i * i <= x; ++i) { n     if (x % i == 0) { n       res = res / i * (i - 1); n       while (x % i == 0) x /= i; n     } n   } n   if (x > 1) res = res / x * (x - 1); n   return res; n } n int n, m; n int ans; n int a[N], b[N], deg[N]; n graph G; n void dfs(int x, int p) { n   a[x] = 1; n   b[x] = 0; n   int chcnt = 0; n   int maxa = -1; n   int maxb = -1; n   for (int i = G.head[x]; i != -1; i = G.next[i]) { n     int y = G.to[i]; n     if (y == p) continue; n     dfs(y, x); n     int temp; n     if (maxa != -1) { n       temp = a[maxa] + a[y] + deg[x] - 2; n       ans = max(ans, temp); n       temp = a[maxa] + b[y] + deg[x] - 2; n       ans = max(ans, temp); n     } n     if (maxb != -1) { n       temp = b[maxb] + b[y] + deg[x] - 2; n       ans = max(ans, temp); n       temp = b[maxb] + b[y] + 1; n       ans = max(ans, temp); n       temp = b[maxb] + a[y] + deg[x] - 2; n       ans = max(ans, temp); n     } n     a[x] = max(a[x], b[y] + 1); n     b[x] = max(b[x], a[y] + deg[x] - 1 - (p != 0)); n     b[x] = max(b[x], b[y] + deg[x] - 1 - (p != 0)); n     if (maxa == -1 || a[y] > a[maxa]) maxa = y; n     if (maxb == -1 || b[y] > b[maxb]) maxb = y; n   } n   ans = max(ans, a[x]); n   ans = max(ans, b[x] + (p != 0)); n } n int main() { n   int cases = 1; n   for (int iii = 1; iii <= cases; ++iii) { n     scanf( %d , &n); n     G.init(n); n     for (int i = 1; i < n; ++i) { n       int x, y; n       scanf( %d%d , &x, &y); n       G.addedge(x, y); n       G.addedge(y, x); n       ++deg[x]; n       ++deg[y]; n     } n     ans = 0; n     dfs(1, 0); n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void prt(long x) { cerr << x; } n void prt(long long x) { cerr << x; } n void prt(unsigned x) { cerr << x; } n void prt(unsigned long x) { cerr << x; } n void prt(unsigned long long x) { cerr << x; } n void prt(float x) { cerr << x; } n void prt(double x) { cerr << x; } n void prt(long double x) { cerr << x; } n void prt(char x) { cerr <<      << x <<     ; } n void prt(const char *x) { cerr <<     << x <<    ; } n void prt(const string &x) { cerr <<     << x <<    ; } n void prt(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void prt(const pair<T, V> &x) { n   cerr <<  { ; n   prt(x.first); n   cerr <<  , ; n   prt(x.second); n   cerr <<  } ; n } n template <typename T> n void prt(const T &x) { n   long long f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), prt(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   prt(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void err(istream_iterator<string> it) {} n template <typename T, typename... brgs> n void err(istream_iterator<string> it, T a, brgs... args) { n   cerr << *it <<   =   << a << endl; n   err(++it, args...); n } n long long kadane(long long *a, long long n) { n   long long max_so_far = INT_MIN, max_ending_here = 0; n   for (__typeof(n) i = (0); i != (n); i += 1 - 2 * ((0) > (n))) { n     max_ending_here += a[i]; n     max_so_far = max(max_so_far, max_ending_here); n     if (max_ending_here < 0) max_ending_here = 0; n   } n   return max_so_far; n } n void solve() { n   long long n; n   cin >> n; n   double ans = 1.0 / tan(3.1415926535897932384626 / (2 * n)); n   cout << fixed; n   cout << setprecision(10) << ans << endl; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > ed[200005]; n int n, m, k; n unsigned long long Hash[200005]; n unsigned long long H = 1e9 + 7; n unsigned long long a[10][10]; n unsigned long long sum; n long long ans = 0; n void dfs(int kk1, unsigned long long s) { n   if (kk1 == k) { n     if (s == sum) { n       ans += 1; n     } n     return; n   } n   for (int i = 0; i < kk1 + 1; i++) { n     dfs(kk1 + 1, s + a[kk1 + 1][i]); n   } n } n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     ed[u].push_back(make_pair(w, v)); n   } n   for (int i = 1; i <= n; i++) { n     sort(ed[i].begin(), ed[i].end()); n   } n   Hash[1] = 1; n   sum = 1; n   for (int i = 2; i <= n; i++) { n     Hash[i] = Hash[i - 1] * H; n     sum += Hash[i]; n   } n   for (int i = 1; i <= n; i++) { n     int tp = ed[i].size(); n     for (int j = 0; j < tp; j++) { n       int tpp = ed[i][j].second; n       a[tp][j] += Hash[tpp]; n     } n   } n   dfs(1, a[1][0]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int compare(const void *a, const void *b) { n   int A = *((int *)a); n   int B = *((int *)b); n   return B - A; n } n int main() { n   long long a[200000], b, c = 0, d, f = 0, i, j, k, n, m, p = 0, q = 0, r, n                           t = 0, l, mid = 0, sum = 0, x, y, s = 0; n   string ch[3000][2]; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   i = 0; n   j = n - 1; n   while (i <= j) { n     c++; n     if (c % 2 != 0) { n       if (a[i] > a[j]) { n         s = s + a[i]; n         i++; n       } else { n         s = s + a[j]; n         j--; n       } n     } else { n       if (a[i] > a[j]) { n         f = f + a[i]; n         i++; n       } else { n         f = f + a[j]; n         j--; n       } n     } n   } n   cout << s <<     << f; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n + 2]; n   vector<int> s; n   s.push_back(n); n   for (int i = 2; i < n + 1; i++) cin >> arr[i]; n   arr[1] = 0; n   int k = n; n   while (k > 0) { n     s.push_back(arr[k]); n     k = arr[k]; n   } n   for (int i = s.size() - 2; i > -1; i--) { n     cout << s[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)1e6; n vector<int> g[MAXN + 1]; n pair<int, int> arr[MAXN + 1]; n int k; n void dfs(int nod, int par, int lvl) { n   arr[nod] = {2 * MAXN, 0}; n   for (auto it : g[nod]) { n     if (it != par) { n       dfs(it, nod, lvl + 1); n       if (lvl >= arr[it].first) { n         arr[nod].first = min(arr[nod].first, arr[it].first); n         arr[nod].second += arr[it].second; n       } n     } n   } n   if (g[nod].size() == 0) { n     arr[nod] = {lvl - k, 1}; n   } n } n int dp[MAXN + 1]; n void dfs1(int nod, int par, int lvl) { n   dp[nod] = (g[nod].size() == 0); n   for (auto it : g[nod]) { n     if (it != par) { n       dfs1(it, nod, lvl + 1); n       int cur = arr[nod].second; n       if (lvl >= arr[it].first) { n         cur -= arr[it].second; n       } n       dp[nod] = max(dp[nod], cur + dp[it]); n     } n   } n } n int main() { n   int i, n, x, y; n   ios::sync_with_stdio(false); n   cin >> n >> k; n   for (i = 2; i <= n; i++) { n     cin >> x; n     g[x].push_back(i); n   } n   dfs(1, 0, 1); n   dfs1(1, 0, 1); n   cout << dp[1]; n   return 0; n } n


#include <bits/stdc++.h> n char s[101]; n char t[10] =  ><+-.,[] ; n int c[10] = {8, 9, 10, 11, 12, 13, 14, 15}; n void func() { n   int n = strlen(s), i, j, ans = 0; n   const int mod = 1000003; n   for (i = 0; i < n; i++) { n     for (j = 0; j < 8; j++) { n       if (t[j] == s[i]) { n         ans = (ans * 16 + c[j]) % mod; n         break; n       } n     } n   } n   printf( %d n , ans); n } n int main(int argc, char **argv) { n   while (scanf( %s , s) == 1) { n     func(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     int x1, x2, y1, y2; n     string arr[8]; n     for (int i = 0; i < 8; i++) cin >> arr[i]; n     bool check = 0; n     for (int i = 0; i < 8; i++) { n       for (int j = 0; j < 8; j++) { n         if (arr[i][j] ==  K  && check == 0) { n           check = 1; n           x1 = j; n           y1 = i; n         } else if (arr[i][j] ==  K ) { n           x2 = j; n           y2 = i; n         } n       } n     } n     if ((x1 == x2 && abs(y1 - y2) == 4) || (y1 == y2 && abs(x1 - x2) == 4)) n       cout <<  YES ; n     else if (abs(x1 - x2) == 4 && abs(y1 - y2) == 4) n       cout <<  YES ; n     else n       cout <<  NO ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long MAX = 9223372036854775807; n int visited[1001][1001]; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   int n, m; n   cin >> n >> m; n   int a[n][m], l[n][m], r[n][m], u[n][m], d[n][m]; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     for (int j = 0; j < s.size(); ++j) { n       if (s[j] ==  . ) n         a[i][j] = 0; n       else n         a[i][j] = 1; n     } n   } n   for (int i = 0; i < n; ++i) { n     int temp = 0; n     for (int j = 0; j < m; ++j) { n       l[i][j] = temp; n       temp += a[i][j]; n       if (a[i][j] == 0) temp = 0; n     } n     temp = 0; n     for (int j = m - 1; j >= 0; j--) { n       r[i][j] = temp; n       temp += a[i][j]; n       if (a[i][j] == 0) temp = 0; n     } n   } n   for (int j = 0; j < m; ++j) { n     int temp = 0; n     for (int i = 0; i < n; ++i) { n       u[i][j] = temp; n       temp += a[i][j]; n       if (a[i][j] == 0) temp = 0; n     } n     temp = 0; n     for (int i = n - 1; i >= 0; i--) { n       d[i][j] = temp; n       temp += a[i][j]; n       if (a[i][j] == 0) temp = 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (a[i][j]) { n         l[i][j] = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j])); n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       u[i][j] = 0; n       r[i][j] = 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (a[i][j] and l[i][j] > 0) { n         int k = l[i][j]; n         u[i - k][j]++; n         if (i + k + 1 < n) u[i + k + 1][j]--; n         r[i][j - k]++; n         if (j + k + 1 < m) r[i][j + k + 1]--; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     int temp = 0; n     for (int j = 0; j < m; ++j) { n       temp += r[i][j]; n       visited[i][j] = temp; n     } n   } n   for (int j = 0; j < m; ++j) { n     int temp = 0; n     for (int i = 0; i < n; ++i) { n       temp += u[i][j]; n       visited[i][j] += temp; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (a[i][j] and visited[i][j] == 0) { n         cout << -1 <<   n ; n         return 0; n         ; n       } n       if (a[i][j] == 0 and visited[i][j] > 0) { n         cout << -1 <<   n ; n         return 0; n         ; n       } n     } n   } n   vector<pair<pair<int, int>, int> > ans; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (a[i][j] and l[i][j] > 0) { n         ans.push_back({{i + 1, j + 1}, l[i][j]}); n       } n     } n   } n   cout << ans.size() <<   n ; n   ; n   for (auto i : ans) { n     cout << i.first.first <<    ; n     ; n     cout << i.first.second <<    ; n     ; n     cout << i.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> p(n); n   for (int i = 0; i < n; ++i) cin >> p[i]; n   vector<int> s(n); n   for (int i = 0; i < n; ++i) cin >> s[i]; n   vector<int> c(k); n   for (int i = 0; i < k; ++i) cin >> c[i]; n   vector<vector<int>> schools(m + 1, vector<int>()); n   for (int i = 0; i < n; ++i) { n     schools[s[i]].push_back(p[i]); n   } n   int ans = 0; n   for (int i = 0; i < k; ++i) { n     int cur = c[i]; n     int school = s[cur - 1]; n     int power = p[cur - 1]; n     vector<int> ss = schools[school]; n     sort(ss.rbegin(), ss.rend()); n     if (ss[0] != power) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n const double oo = 1E7, eps = 1E-7; n struct point { n   double x, y; n } P[maxn]; n int n; n double ansl, ansr; n point operator+(point a, point b) { return (point){a.x + b.x, a.y + b.y}; } n point operator-(point a, point b) { return (point){a.x - b.x, a.y - b.y}; } n double operator*(point a, point b) { return a.x * b.x + a.y * b.y; } n double operator/(point a, point b) { return a.x * b.y - b.x * a.y; } n double get(point A, point B) { n   double a, b, c, res; n   a = A.y - B.y; n   b = B.x - A.x; n   c = A / B; n   if (a) n     res = (-c - b * P[1].y) / a; n   else n     res = oo; n   return res; n } n int main() { n   int i, j; n   double x, sita; n   scanf( %d , &n); n   scanf( %lf%lf , &P[n].x, &P[n].y); n   for (i = 1; i < n; ++i) scanf( %lf%lf , &P[i].x, &P[i].y); n   ansl = min(P[1].x, P[n].x), ansr = max(P[1].x, P[n].x); n   for (i = 2; i < n; ++i) { n     j = i + 1; n     x = get(P[i], P[j]); n     sita = (P[1].y - P[i].y) * (P[j].x - P[i].x); n     if (sita > (P[j].y - P[i].y) * (ansl - P[i].x)) ansl = max(ansl, x); n     if (sita > (P[j].y - P[i].y) * (ansr - P[i].x)) ansr = min(ansr, x); n   } n   if (ansr >= ansl) n     printf( %.0lf , floor(ansr) - floor(ansl - eps)); n   else n     printf( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[100001] = {0}; n long long int d[100001] = {0}; n long long int vis[100001] = {0}; n long long int cons[100001] = {0}; n vector<long long int> vec[100001]; n void dfs(long long int x, long long int p) { n   vis[x] = 1; n   if (a[x] == 1) { n     if (a[p] == 1) { n       cons[x] = cons[p] + 1; n     } else { n       cons[x] = 1; n     } n     d[x] = max(d[p], cons[x]); n   } else { n     cons[x] = 0; n     d[x] = d[p]; n   } n   for (long long int i = 0; i < vec[x].size(); i++) { n     if (vis[vec[x][i]] == 1) n       continue; n     else { n       dfs(vec[x][i], x); n     } n   } n } n signed main() { n   long long int n, m; n   cin >> n >> m; n   for (long long int i = 0; i < n; i++) cin >> a[i + 1]; n   for (long long int i = 0; i < n - 1; i++) { n     long long int x, y; n     cin >> x >> y; n     vec[x].push_back(y); n     vec[y].push_back(x); n   } n   dfs(1, 0); n   long long int count = 0; n   for (long long int i = 2; i <= n; i++) { n     if (vec[i].size() == 1 && d[i] <= m) count++; n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int res = 0; n   int neg; n   while (true) { n     char ch = getchar(); n     if (ch >=  0  && ch <=  9  || ch ==  - ) { n       if (ch ==  - ) n         neg = -1; n       else n         neg = 1, res = ch -  0 ; n       break; n     } n   } n   while (true) { n     char ch = getchar(); n     if (ch >=  0  && ch <=  9 ) n       res *= 10, res += ch -  0 ; n     else n       break; n   } n   return res * neg; n } n const int maxn = 100020; n const int MOd = 1e7; n int a, L, R, st[maxn], at; n bool flag, used[maxn]; n vector<pair<int, pair<int, int> > > w[maxn]; n vector<pair<int, int> > w2[maxn]; n int dfs(int n, int back, int sz) { n   int ret = 1; n   st[++at] = n; n   for (int i = 0; i < w[n].size(); i++) n     if (w[n][i].first != back && !used[w[n][i].first]) { n       int t = dfs(w[n][i].first, n, sz); n       w[n][i].second.second = t; n       ret += t; n     } n   for (int i = 0; i < w[n].size(); i++) n     if (w[n][i].first == back) w[n][i].second.second = sz - ret; n   return ret; n } n vector<int> Cw[maxn]; n int ans1, ans2, sz[maxn]; n void center(int n, int back, int szz) { n   at = 0; n   dfs(n, 0, szz); n   int C = n; n   for (int i = 1; i <= at; i++) { n     int t = st[i]; n     int c = 0; n     for (int j = 0; j < w[t].size(); j++) n       if (w[t][j].second.second > szz / 2) { n         c = 1; n         break; n       } n     if (!c) C = t; n   } n   Cw[back].push_back(C); n   sz[C] = szz; n   used[C] = 1; n   for (int i = 0; i < w[C].size(); i++) n     if (!used[w[C][i].first]) center(w[C][i].first, C, w[C][i].second.second); n } n int N, T; n pair<int, int> segment[maxn * 3]; n pair<int, pair<int, int> > st2[maxn]; n void dfss(int &n, int &back, int der, int s) { n   st2[++at].first = n; n   st2[at].second.first = der; n   st2[at].second.second = s + s - der; n   pair<int, int> t; n   t.first = -1e9; n   t.second = 0; n   int l = L - der, r = R - der; n   if (l < N && 0 <= l) { n     if (r > N - 1) r = N - 1; n     for (l += N, r += N; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) { n       if (l & 1) t = max(t, (segment[l])); n       if (~r & 1) t = max(t, (segment[r])); n     } n   } n   if (t.first + s + s - der >= 0) { n     ans1 = n; n     ans2 = t.second; n     flag = 1; n     return; n   } n   for (int i = 0; i < w2[n].size() && !flag; i++) n     if (w2[n][i].first != back && !used[w2[n][i].first]) n       dfss(w2[n][i].first, n, der + 1, s + w2[n][i].second); n } n void calc(int &C) { n   N = 1; n   while (N < sz[C]) N <<= 1; n   for (int i = 1; i < N + N; i++) segment[i] = pair<int, int>(-1e9, 0); n   for (int k = N; k; k >>= 1) segment[k] = pair<int, int>(0, C); n   for (int i = 0; i < w2[C].size(); i++) n     if (!used[w2[C][i].first]) { n       at = 0; n       dfss(w2[C][i].first, C, 1, w2[C][i].second); n       if (flag) return; n       for (int i = 1; i <= at; i++) { n         pair<int, pair<int, int> > &t = st2[i]; n         int k = t.second.first + N; n         if (segment[k].first < t.second.second) { n           segment[k] = pair<int, int>(t.second.second, t.first); n           for (k >>= 1; k; k >>= 1) n             segment[k] = max(segment[k + k], segment[k + k + 1]); n         } n       } n     } n   used[C] = 1; n   for (int i = 0; i < Cw[C].size(); i++) { n     calc(Cw[C][i]); n     if (flag) return; n   } n } n bool f(int n) { n   for (int i = 1; i <= a; i++) n     for (int j = 0; j < w[i].size(); j++) n       w2[i][j].second = (w[i][j].second.first >= n); n   flag = 0; n   memset(used, 0, sizeof(used)); n   calc(Cw[0][0]); n   return flag; n } n int main() { n   scanf( %d %d %d , &a, &L, &R); n   for (int i = 1, j, k, t; i < a; i++) { n     scanf( %d %d %d , &j, &k, &t); n     w[j].push_back(pair<int, pair<int, int> >(k, pair<int, int>(t, 0))); n     w[k].push_back(pair<int, pair<int, int> >(j, pair<int, int>(t, 0))); n     w2[j].push_back(pair<int, int>(k, 0)); n     w2[k].push_back(pair<int, int>(j, 0)); n   } n   center(1, 0, a); n   int t = -1; n   for (int k = 29; k >= 0; k--) n     if (f(t + (1 << k))) t += 1 << k; n   printf( %d %d n , ans1, ans2); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   return x * f; n } n void write(long long x) { n   if (x < 0) x = -x, putchar( - ); n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n void writeln(long long x) { n   write(x); n   puts(  ); n } n const int N = 500000; n int E[N], X[N], R[N], D[N]; n int u[N], v[N]; n bool b[N]; n int i, m, n, t, w, x, y, S_E; n inline void A_E(int x, int y) { n   S_E++, E[S_E] = y, X[S_E] = R[x], R[x] = S_E, D[x]++; n   return; n } n inline int O_E(int x) { return ((x - 1) ^ 1) + 1; } n inline void dfs(int x) { n   for (int i = R[x]; R[x] = X[i], i != 0; i = R[x]) n     if (!b[i]) { n       b[i] = true, b[O_E(i)] = true; n       dfs(E[i]); n       w++, u[w] = x, v[w] = E[i]; n     } n   return; n } n int main() { n   n = read(), m = read(); n   for (i = 1; i <= m; i++) { n     x = read(), y = read(); n     A_E(x, y), A_E(y, x); n   } n   for (i = 1; i <= n; i++) n     if (D[i] & 1) n       if (t) n         m++, A_E(i, t), A_E(t, i), t = 0; n       else n         t = i; n   if (m & 1) m++, A_E(1, 1), A_E(1, 1); n   writeln(m); n   dfs(1); n   for (i = w; i > 0; i--) n     if (!(i & 1)) n       printf( %d %d n , u[i], v[i]); n     else n       printf( %d %d n , v[i], u[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int a[100005]; n   cin >> n; n   int fa = 1; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] != i) { n       fa = 0; n     } n   } n   if (fa == 1) { n     cout <<  0 ; n   } else { n     int ji = n - 1; n     while (a[ji] < a[ji + 1]) { n       ji--; n     } n     cout << ji; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9, MOD = 1e9 + 7, N = 1e5 + 1, M = 20; n void setIO(string name =   ) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   if (name.size()) { n     freopen((name +  .in ).c_str(),  r , stdin); n     freopen((name +  .out ).c_str(),  w , stdout); n   } n } n int n, m, a[N], s, pxor[1000001], ans[N]; n void pre() { n   pxor[0] = 0; n   for (int i = 1; i < 1000001; i++) pxor[i] = pxor[i - 1] ^ i; n } n string bit(int j) { n   string ans; n   for (int i = 0; i < M; i++) { n     ans += (j & 1) +  0 ; n     j >>= 1; n   } n   reverse(ans.begin(), ans.end()); n   return ans; n } n struct node1 { n   int mx = -INF; n   node1 *nxt[2]{}; n }; n struct node2 { n   int mn = INF; n   node2 *nxt[2]{}; n }; n node1 *rt1 = new node1(); n node2 *rt2 = new node2(); n void insert1(node1 *o, int i) { n   string s = bit(pxor[i]); n   for (char c : s) { n     if (!o->nxt[c -  0 ]) o->nxt[c -  0 ] = new node1(); n     o = o->nxt[c -  0 ]; n     o->mx = max(o->mx, i); n   } n } n void insert2(node2 *o, int i) { n   string s = bit(pxor[i]); n   for (char c : s) { n     if (!o->nxt[c -  0 ]) o->nxt[c -  0 ] = new node2(); n     o = o->nxt[c -  0 ]; n     o->mn = min(o->mn, i); n   } n } n void insert(int i) { n   insert1(rt1, i); n   insert2(rt2, i - 1); n } n int get1(node1 *o, int i) { n   string s = bit(pxor[i]); n   int ans = 0, shift = M - 1; n   for (char c : s) { n     int tmp = 1 ^ (c -  0 ); n     if (o->nxt[tmp] && o->nxt[tmp]->mx > i) { n       o = o->nxt[tmp]; n       ans += (1 << shift); n     } else if (o->nxt[1 ^ tmp] && o->nxt[1 ^ tmp]->mx > i) { n       o = o->nxt[tmp ^ 1]; n     } else n       return 0; n     shift--; n   } n   return ans; n } n int get2(node2 *o, int i) { n   string s = bit(pxor[i]); n   int ans = 0, shift = M - 1; n   for (char c : s) { n     int tmp = 1 ^ (c -  0 ); n     if (o->nxt[tmp] && o->nxt[tmp]->mn < i) { n       o = o->nxt[tmp]; n       ans += (1 << shift); n     } else if (o->nxt[1 ^ tmp] && o->nxt[1 ^ tmp]->mn < i) { n       o = o->nxt[tmp ^ 1]; n     } else n       return 0; n     shift--; n   } n   return ans; n } n int get(int i) { return max(get1(rt1, i - 1), get2(rt2, i)); } n void clearall(node1 *o) { n   o->mx = -INF; n   if (o->nxt[0] && o->nxt[0]->mx != -INF) clearall(o->nxt[0]); n   if (o->nxt[1] && o->nxt[1]->mx != -INF) clearall(o->nxt[1]); n } n void clearall(node2 *o) { n   o->mn = INF; n   if (o->nxt[0] && o->nxt[0]->mn != INF) clearall(o->nxt[0]); n   if (o->nxt[1] && o->nxt[1]->mn != INF) clearall(o->nxt[1]); n } n void init() { n   clearall(rt1); n   clearall(rt2); n } n struct query { n   int l, r, id, bl; n   query(int ll, int rr, int i) : l(ll), r(rr), id(i), bl(l / s) {} n   bool operator<(const query &other) const { n     return make_pair(bl, r) < make_pair(other.bl, other.r); n   } n }; n query make_query(int ll, int rr, int i) { return query(ll, rr, i); } n vector<query> qry; n signed main() { n   setIO(); n   pre(); n   cin >> n >> m; n   s = ceil(sqrt(n)); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     qry.push_back(make_query(l - 1, r - 1, i)); n   } n   sort(qry.begin(), qry.end()); n   for (int i = 0, j = 0; i < m; i = j) { n     while (j < m && qry[j].bl == qry[i].bl) j++; n     int lmx = 0, mid = j, right, nowmx = 0; n     for (int k = i; k < j; k++) right = lmx = max(lmx, qry[k].l); n     for (int k = i; k < j; k++) n       if (qry[k].r > lmx) { n         mid = k; n         break; n       } n     init(); n     for (int k = mid; k < j; k++) { n       ans[qry[k].id] = nowmx; n       while (right <= qry[k].r) { n         insert(a[right]); n         nowmx = ans[qry[k].id] = max(ans[qry[k].id], get(a[right])); n         right++; n       } n       for (int l = lmx; l >= qry[k].l; l--) { n         ans[qry[k].id] = max(ans[qry[k].id], get(a[l])); n       } n     } n     for (int k = i; k < j; k++) { n       init(); n       for (int l = min(qry[k].r, lmx); l >= qry[k].l; l--) { n         insert(a[l]); n         ans[qry[k].id] = max(ans[qry[k].id], get(a[l])); n       } n     } n   } n   for (int i = 0; i < m; i++) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:65777216 ) n using namespace std; n char s[1111][1111]; n int n, m; n int best; n int now; n int v[1111][1111]; n vector<pair<int, int> > c; n bool u[1111][1111]; n void dfs(int x, int y) { n   if (u[x][y]) return; n   u[x][y] = true; n   for (int dx(-1); dx < (2); dx++) n     for (int dy(-1); dy < (2); dy++) { n       int nx = dx + x; n       int ny = dy + y; n       if (nx >= 0 && nx < n && ny >= 0 && ny < m) n         if (s[nx][ny] ==  0 ) n           dfs(nx, ny); n         else n           c.push_back(pair<int, int>(nx, ny)); n       else n         c.push_back(pair<int, int>(-1, -1)); n     } n } n int startx, starty; n int dfs2(int x, int y, int prevx = -1, int prevy = -1) { n   if (x == startx && y == starty && prevx != -1) return 0; n   int res = 1; n   for (int dx(-1); dx < (2); dx++) n     for (int dy(-1); dy < (2); dy++) n       if (abs(dx) + abs(dy) == 1) { n         int nx = x + dx; n         int ny = y + dy; n         if (nx >= 0 && nx < n && ny >= 0 && ny < m && v[nx][ny] == v[x][y]) n           if (nx != prevx || ny != prevy) { n             res += dfs2(nx, ny, x, y); n             if (prevx == -1) return res; n           } n       } n   return res; n } n int main() { n   cin >> n >> m; n   for (int i(0); i < (n); i++) scanf(  %s , s[i]); n   for (int i(1); i < (n); i++) n     for (int j(1); j < (m); j++) n       if (s[i][j] ==  1  && s[i][j - 1] ==  1  && s[i - 1][j - 1] ==  1  && n           s[i - 1][j] ==  1 ) n         best = 4; n   for (int i(0); i < (n); i++) n     for (int j(0); j < (m); j++) n       if (s[i][j] ==  0  && !u[i][j]) { n         c.clear(); n         dfs(i, j); n         now++; n         bool good = 1; n         int num = 0; n         for (int k(0); k < (c.size()); k++) n           if (c[k].first == -1) { n             good = 0; n             break; n           } else if (v[c[k].first][c[k].second] != now) n             v[c[k].first][c[k].second] = now, num++; n         for (int k(0); k < (c.size()); k++) { n           int num = 0; n           for (int dx(-1); dx < (2); dx++) n             for (int dy(-1); dy < (2); dy++) n               if (abs(dx) + abs(dy) == 1) { n                 int nx = c[k].first + dx; n                 int ny = c[k].second + dy; n                 if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] ==  1 ) n                   if (v[nx][ny] == now) num++; n               } n           if (num != 2) { n             good = 0; n             break; n           } n         } n         if (good && num > 4) { n           startx = c[0].first; n           starty = c[0].second; n           if (dfs2(c[0].first, c[0].second) == num) best = max(best, num); n         } n       } n   cout << best << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string l, r; n   cin >> l >> r; n   vector<stack<int>> l_array; n   vector<stack<int>> r_array; n   for (int i = 0; i < 27; i++) { n     stack<int> buf; n     l_array.push_back(buf); n     r_array.push_back(buf); n   } n   for (int i = 0; i < n; i++) { n     if (l[i] ==  ? ) { n       l_array[26].push(i); n     } else { n       l_array[l[i] -  a ].push(i); n     } n     if (r[i] ==  ? ) { n       r_array[26].push(i); n     } else { n       r_array[r[i] -  a ].push(i); n     } n   } n   vector<pair<int, int>> answer; n   for (int i = 0; i < 26; i++) { n     while (!l_array[i].empty() && !r_array[i].empty()) { n       answer.push_back(make_pair(l_array[i].top(), r_array[i].top())); n       l_array[i].pop(); n       r_array[i].pop(); n     } n     while (!l_array[i].empty() && !r_array[26].empty()) { n       answer.push_back(make_pair(l_array[i].top(), r_array[26].top())); n       l_array[i].pop(); n       r_array[26].pop(); n     } n     while (!r_array[i].empty() && !l_array[26].empty()) { n       answer.push_back(make_pair(l_array[26].top(), r_array[i].top())); n       l_array[26].pop(); n       r_array[i].pop(); n     } n   } n   while (!l_array[26].empty() && !r_array[26].empty()) { n     answer.push_back(make_pair(l_array[26].top(), r_array[26].top())); n     l_array[26].pop(); n     r_array[26].pop(); n   } n   int count = answer.size(); n   cout << count << endl; n   for (int i = 0; i < count; i++) { n     cout << answer[i].first + 1 <<     << answer[i].second + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, z, x, c, sum, a[101][101], us[101][101]; n char cc, stl; n set<long long> s; n void dfs(long long i, long long j) { n   if (a[i][j] == 0 || us[i][j] == 1 || i > n || j > m || i < 1 || j < 1) return; n   us[i][j] = 1; n   if (s.count(a[i][j]) == 0) sum++, s.insert(a[i][j]); n   if (a[i][j] == stl -  A  + 1) { n     dfs(i + 1, j); n     dfs(i - 1, j); n     dfs(i, j + 1); n     dfs(i, j - 1); n   } n } n int main() { n   cin >> n >> m >> stl; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> cc; n       if (cc !=  . ) a[i][j] = cc -  A  + 1; n       if (cc == stl) z = i, x = j; n     } n   } n   s.insert((int)stl -  A  + 1); n   dfs(z, x); n   cout << sum <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int okX[] = {0, 0, 0, 1, 1, 2, 2, 2}; n const int okY[] = {0, 1, 2, 0, 2, 0, 1, 2}; n const int n = 8; n void normalize(int a[n]) { n   vector<int> v(a, a + n); n   sort(v.begin(), v.end()); n   map<int, int> m; n   for (int i = 0; i < v.size(); ++i) n     if (!m.count(v[i])) m.insert(make_pair(v[i], m.size())); n   for (int i = 0; i < 8; ++i) a[i] = m[a[i]]; n } n int main() { n   int x[n], y[n]; n   for (int i = 0; i < n; ++i) cin >> x[i] >> y[i]; n   normalize(x); n   normalize(y); n   bool used[n]; n   memset(used, false, sizeof(used)); n   for (int i = 0; i < 8; ++i) { n     bool ok = false; n     for (int j = 0; j < 8; ++j) n       if (x[i] == okX[j] && y[i] == okY[j] && !used[j]) n         ok = true, used[j] = true; n     if (!ok) { n       printf( ugly n ); n       return 0; n     } n   } n   printf( respectable n ); n   return 0; n } n