#include <bits/stdc++.h> n using namespace std; n int N; n int main() { n   cin >> N; n   int dec[2 * N]; n   int all_round_down = 0; n   int z = 0; n   for (int i = 0; i < 2 * N; i++) { n     double x; n     cin >> x; n     dec[i] = int((x + 0.0005 - int(x + 0.0005)) * 1000); n     all_round_down += dec[i]; n     if (dec[i] == 0) z++; n   } n   int mi = max(0, N - z); n   int ma = min(N, 2 * N - z); n   int best = (all_round_down + 500) / 1000; n   int ans; n   if (best >= mi && best <= ma) n     ans = abs(all_round_down - 1000 * best); n   else n     ans = min(abs(all_round_down - 1000 * mi), abs(all_round_down - 1000 * ma)); n   cout << ans / 1000 <<  .  << (ans % 1000) / 100 << (ans % 100) / 10 n        << ans % 10; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> edge[(1 << 18)]; n int degree[(1 << 18)]; n int DelNode; n int DFS(int iDeep, int iNode, int iParent) { n   int iSons = edge[iNode].size(); n   if (iParent) iSons--; n   if (iDeep > n) return -1; n   if (iSons > 3) return -1; n   if (iSons == 0) return 1; n   if (iSons & 1) { n     if (DelNode) return -1; n     DelNode = iNode; n     vector<int> RetList; n     for (auto Iter : edge[iNode]) { n       if (Iter == iParent) continue; n       int iRet = DFS(iDeep + 1, Iter, iNode); n       if (-1 == iRet) return iRet; n       RetList.push_back(iRet); n     } n     sort(RetList.begin(), RetList.end()); n     if (iSons == 1) { n       if (RetList[0] != 1) return -1; n       return RetList[0] + 1; n     } else { n       if (RetList[0] != RetList[1] || RetList[0] + 1 != RetList[2]) return -1; n       return RetList[2] + 1; n     } n   } else { n     assert(iSons == 2); n     int iDeepToButtom = -1; n     for (auto Iter : edge[iNode]) { n       if (Iter == iParent) continue; n       int iRet = DFS(iDeep + 1, Iter, iNode); n       if (-1 == iRet) return iRet; n       if (iDeepToButtom == -1) n         iDeepToButtom = iRet; n       else if (iDeepToButtom != iRet) n         return -1; n     } n     return iDeepToButtom + 1; n   } n } n int main() { n   scanf( %d , &n); n   int k = (1 << n) - 2; n   for (int i = 0; i < k - 1; ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     edge[u].push_back(v); n     edge[v].push_back(u); n     degree[u]++; n     degree[v]++; n   } n   vector<int> list; n   for (int i = 1; i <= k; ++i) n     if (degree[i] == 1) { n       list.push_back(i); n     } n   for (int i = 0; i < list.size(); ++i) { n     int iCur = list[i]; n     for (auto Iter : edge[iCur]) { n       if (--degree[Iter] == 1) list.push_back(Iter); n     } n   } n   assert(list.size() == k); n   int i = 0; n   vector<int> result; n   for (auto Iter = list.rbegin(); i < 5 && Iter != list.rend(); Iter++, i++) { n     DelNode = 0; n     if (DFS(1, *Iter, 0) != -1) { n       assert(DelNode); n       result.push_back(DelNode); n     } n   } n   sort(result.begin(), result.end()); n   result.resize(unique(result.begin(), result.end()) - result.begin()); n   printf( %d n , result.size()); n   for (int i = 0; i < result.size(); ++i) { n     if (i) putchar(   ); n     printf( %d , result[i]); n   } n   putchar(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, sz, i, ans, j, a[200001], t[531172], op; n void upd(int x) { n   for (j = x / 2; j >= 1; j /= 2) t[j] = max(t[j * 2], t[j * 2 + 1]); n } n long long finds(int l, int r) { n   long long sum = -1; n   while (l <= r) { n     if (l % 2 == 1) sum = max(sum, t[l]); n     if (r % 2 == 0) sum = max(sum, t[r]); n     l++, r--, l /= 2, r /= 2; n   } n   return sum; n } n int main() { n   cin >> n; n   sz = 1; n   while (sz < n) sz *= 2; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i <= n; i++) { n     t[a[i] + sz - 1] = finds(sz, a[i] + sz - 1) + 1; n     upd(a[i] + sz - 1); n   } n   cout << max(t[1], 1ll); n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   register int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int Size = 100005; n int n, top; n struct vec { n   double x, y; n } w[Size], a[Size], O, stk[Size]; n inline vec operator-(vec a, vec b) { return (vec){a.x - b.x, a.y - b.y}; } n inline vec operator+(vec a, vec b) { return (vec){a.x + b.x, a.y + b.y}; } n inline bool operator<(vec a, vec b) { n   if (a.x != b.x) return a.x < b.x; n   return a.y < b.y; n } n inline double Xji(vec p, vec q) { return p.x * q.y - p.y * q.x; } n inline double dist(vec mhy) { return mhy.x * mhy.x + mhy.y * mhy.y; } n inline bool comp(vec jzm, vec xjp) { n   double tmp = Xji(jzm, xjp); n   if (fabs(tmp) > 1e-6) return tmp > 1e-6; n   return dist(jzm) < dist(xjp); n } n inline double dist(vec mhy, vec zwt) { n   return sqrt((mhy.x - zwt.x) * (mhy.x - zwt.x) + n               (mhy.y - zwt.y) * (mhy.y - zwt.y)); n } n inline vec rotate(vec a, double rad) { n   return (vec){a.x * cos(rad) - a.y * sin(rad), n                a.x * sin(rad) + a.y * cos(rad)}; n } n int main() { n   n = read(); n   for (register int i = 1; i <= n; i++) { n     double x, y; n     scanf( %lf %lf , &x, &y); n     w[i].x = x; n     w[i].y = y - x * x; n   } n   vec O = w[1]; n   int id = 1; n   for (register int i = 2; i <= n; i++) { n     if (w[i] < O) { n       id = i; n       O = w[i]; n     } n   } n   swap(w[id], w[1]); n   for (register int i = 1; i <= n; i++) { n     a[i] = w[i] - O; n   } n   sort(a + 2, a + 1 + n, comp); n   for (register int i = 1; i <= n; i++) { n     while (top > 1 && Xji(stk[top] - stk[top - 1], a[i] - stk[top - 1]) <= 0) { n       top--; n     } n     stk[++top] = a[i]; n   } n   for (register int i = 1; i <= top; i++) { n     stk[i] = stk[i] + O; n   } n   int ans = 0; n   for (register int i = 1; i <= top; i++) { n     int pos = i % top + 1; n     if (stk[i].x > stk[pos].x) { n       ans++; n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long c[55]; n struct cmp { n   bool operator()(long long a, long long b) { return c[a] < c[b]; } n }; n int main() { n   long long n, m, k; n   long long a[55], b[55], ind[55]; n   long long dp[55][55][105][3]; n   cin >> n >> m >> k; n   for (long long i = 0; i < m; ++i) { n     cin >> a[i] >> b[i] >> c[i]; n     ind[i] = i; n   } n   sort(ind, ind + m, cmp()); n   if (0) n     for (long long i = 0; i < m; i++) cout << ind[i] <<    ; n   if (0) cout << endl; n   memset(dp, -1, sizeof(dp)); n   for (long long i = 0; i < m; i++) { n     for (long long p = 0; p <= (long long)(b[ind[i]] - a[ind[i]]); p++) { n       dp[i][1][p][0] = a[ind[i]] + p; n       dp[i][1][p][1] = i; n       dp[i][1][p][2] = p; n     } n   } n   long long maxVal, maxInd, maxH; n   for (long long i = 1; i < m; i++) { n     for (long long j = 2; j <= min(n, i + 1); j++) { n       for (long long p = 0; p <= (long long)(b[ind[i]] - a[ind[i]]); p++) { n         maxVal = -1; n         maxInd = -1; n         maxH = -1; n         long long cur = a[ind[i]] + p, req1 = cur - k, n                   req2 = ((cur % k) ? -1 : (cur / k)); n         for (long long s = i - 1; s >= 0; s--) { n           if (c[ind[s]] == c[ind[i]]) continue; n           if (0) n             cout <<  hello   << s <<     << req1 <<     << req2 <<     n                  << a[ind[s]] <<     << b[ind[s]] <<     n                  << dp[s][j - 1][(long long)(req1 - a[ind[s]])][0] << endl; n           if (0) cout <<  MAXVAL   << maxVal << endl; n           if (req1 > 0 && req1 <= b[ind[s]] && req1 >= a[ind[s]]) { n             if (dp[s][j - 1][(long long)(req1 - a[ind[s]])][0] > maxVal) { n               maxInd = s; n               maxVal = dp[s][j - 1][(long long)(req1 - a[ind[s]])][0]; n               maxH = (req1 - a[ind[s]]); n             } n           } n           if (req2 > 0 && req2 <= b[ind[s]] && req2 >= a[ind[s]]) { n             if (dp[s][j - 1][(long long)(req2 - a[ind[s]])][0] > maxVal) { n               maxInd = s; n               maxVal = dp[s][j - 1][(long long)(req2 - a[ind[s]])][0]; n               maxH = (req2 - a[ind[s]]); n             } n           } n         } n         if (0) cout <<  FUCK   << maxVal <<     << maxH << endl; n         dp[i][j][p][0] = (maxVal != -1) ? (maxVal + cur) : maxVal; n         dp[i][j][p][1] = maxInd; n         dp[i][j][p][2] = maxH; n         if (0) n           cout << i <<     << j <<     << a[ind[i]] + p <<     << dp[i][j][p][0] n                << endl; n       } n     } n   } n   maxVal = -1; n   maxInd = -1; n   maxH = -1; n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j <= (b[ind[i]] - a[ind[i]]); j++) n       if (maxVal < dp[i][n][j][0]) { n         maxVal = dp[i][n][j][0]; n         maxInd = i; n         maxH = j; n       } n   } n   if (maxVal != -1) { n     long long j = n; n     vector<pair<long long, long long> > v; n     vector<pair<long long, long long> >::iterator it; n     cout <<  YES  << endl; n     while (true) { n       if (0) cout <<  mind mh   << maxInd <<     << maxH << endl; n       v.push_back(make_pair(ind[maxInd] + 1, a[ind[maxInd]] + maxH)); n       long long temp = maxInd; n       maxInd = dp[temp][j][maxH][1]; n       maxH = dp[temp][j][maxH][2]; n       j--; n       if (j == 0) break; n     } n     for (it = --v.end(), j = n; j > 0; it--, j--) { n       cout << (*it).first <<     << (*it).second << endl; n     } n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1010]; n long long b[1010]; n long long c[2020]; n long long d[1010]; n long long mex(long long m) { n   sort(b, b + m); n   long long j = 0; n   long long k = 0; n   long long ans = m; n   while (j < m) { n     if (b[k] > j) { n       ans = j; n       break; n     } else if (b[k] == j) { n       k++; n       j++; n     } else { n       k++; n     } n   } n   return ans; n } n long long check(long long m) { n   long long ct3 = 0; n   for (long long i = 1; i < m; i++) { n     if (a[i] < a[i - 1]) { n       ct3 = 1; n       break; n     } n   } n   if (ct3 == 1) n     return 0; n   else n     return 1; n } n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long ct = 1; n     long long ct1 = 0; n     for (long long i = 0; i <= n; i++) { n       a[i] = 0; n       b[i] = 0; n       c[i] = 0; n       d[i] = 0; n     } n     for (long long i = n; i <= (n + n); i++) { n       c[i] = 0; n     } n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       b[i] = a[i]; n       if (a[i] == i) d[i] = 1; n     } n     while (ct <= (2 * n)) { n       if (check(n) == 1) break; n       ct1 = mex(n); n       if (ct1 == n) { n         for (long long i = 0; i < n; i++) { n           if (d[i] != 1) { n             a[i] = n; n             c[ct] = i; n             break; n           } n         } n       } else { n         c[ct] = ct1; n         a[ct1] = ct1; n         d[ct1] = 1; n       } n       for (long long i = 0; i < n; i++) b[i] = a[i]; n       ct++; n     } n     cout << ct - 1 <<   n ; n     for (long long i = 1; i < ct; i++) { n       cout << c[i] + 1 <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class A> n ostream& operator<<(ostream& out, const vector<A>& v) { n   for (long long i = 0; i < v.size(); i++) { n     if (i) out <<    ; n     out << v[i]; n   } n   return out <<   n ; n } n const long long mod = 1000000007; n inline long long add(long long a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n   return a; n } n inline long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) a += mod; n   return a; n } n inline long long mul(long long a, long long b) { return (a * 1ll * b) % mod; } n inline long long powmod(long long a, long long b) { n   long long rt = 1; n   while (b > 0) { n     if (b & 1) rt = mul(rt, a); n     a = mul(a, a); n     b >>= 1; n   } n   return rt; n } n inline long long inv(long long a) { return powmod(a, mod - 2); } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long n, k; n long long a[100005]; n bool check(long long mid) { n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     sum += min(mid, a[i]); n   } n   return sum <= k; n } n void solve() { n   cin >> n >> k; n   long long rt = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     rt += a[i]; n   } n   if (rt < k) { n     cout << -1 <<   n ; n     return; n   } n   long long lo = 1; n   long long hi = *max_element(a, a + n); n   long long ans = 0; n   while (hi - lo >= 0) { n     long long mid = (hi + lo) >> 1; n     if (check(mid)) { n       lo = mid + 1; n       ans = mid; n     } else { n       hi = mid - 1; n     } n   } n   if (false) cerr << ans <<   n ; n   for (long long i = 0; i < n; i++) { n     k -= min(a[i], ans); n     a[i] -= min(a[i], ans); n   } n   if (false) cerr << k <<   n ; n   long long i = 0; n   for (i = 0; i < n && k > 0; i++) { n     if (a[i] <= 0) n       continue; n     else { n       a[i]--; n       k--; n     } n     if (false) cerr << a[i] <<    ; n   } n   if (false) cerr <<   n ; n   long long y = 0; n   for (long long j = i; j < i + n; j++) { n     long long tmp = j % n; n     if (false) cerr << a[tmp] <<    ; n     if (a[tmp] <= 0) continue; n     y = 1; n     cout << tmp + 1 <<    ; n   } n   cout <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL), n       cout << setprecision(14); n   ; n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string in_name =  sample.in ; n string out_name =  sample.out ; n ifstream in; n ofstream out; n vector<int> v[1001]; n int N; n int main() { n   cin >> N; n   int k, x; n   for (int i = 0; i < N; i++) { n     cin >> k; n     for (int j = 0; j < k; j++) { n       cin >> x; n       v[i].push_back(x); n     } n     sort(v[i].begin(), v[i].end()); n   } n   int res = 0; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < v[i].size() - 1; j++) { n       std::vector<int>::iterator low, up; n       int before = (i - 1 + N) % N; n       int after = (i + 1) % N; n       int left = 0, right = 0; n       up = upper_bound(v[before].begin(), v[before].end(), v[i][j]); n       low = lower_bound(v[before].begin(), v[before].end(), v[i][j + 1]); n       int u = (int)(up - v[before].begin()); n       int l = (int)(low - v[before].begin()); n       if (u < v[before].size() && v[before][u] < v[i][j + 1]) n         left += (l - u) + 1; n       up = upper_bound(v[after].begin(), v[after].end(), v[i][j]); n       low = lower_bound(v[after].begin(), v[after].end(), v[i][j + 1]); n       u = (int)(up - v[after].begin()); n       l = (int)(low - v[after].begin()); n       if (u < v[after].size() && v[after][u] < v[i][j + 1]) n         right += (l - u) + 1; n       if (left != right) { n         res++; n       } n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int firstt(int* a, int n) { n   long long l, r, s; n   for (int i = 0; i <= n - 1; ++i) { n     l = 0; n     r = 10000000000; n     while (l < r - 1) { n       s = (-l + r) / 2 + l; n       if (s * n >= a[i] - i) { n         r = s; n       } else { n         l = s; n       } n     } n     if (l * n >= a[i] - i) { n       a[i] = l; n     } else { n       a[i] = l + 1; n     } n   } n   l = 0; n   int minn = a[0]; n   for (int i = 1; i <= n - 1; ++i) { n     if (a[i] < minn) { n       minn = a[i]; n       l = i; n     } n   } n   return (l + 1); n } n int main() { n   int n, i; n   cin >> n; n   int* a = new int[n]; n   for (i = 0; i <= n - 1; ++i) { n     cin >> a[i]; n   } n   long long res = firstt(a, n); n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > V(7); n vector<vector<string> > S(7); n set<string> SS; n int n, m; n void DFS(int node, string T) { n   if (T.length() == n) { n     SS.insert(T); n     return; n   } n   for (int i = 0; i < S[node].size(); i++) { n     string R = S[node][i]; n     string E; n     E += R[1]; n     if (T.length() + 2 == n) { n       DFS(0, T + R); n     } else n       DFS(R[0] -  a , T + E); n   } n } n int main() { n   cin >> n >> m; n   string y; n   char C; n   char A[m]; n   for (int i = 0; i < m; i++) { n     cin >> y >> C; n     A[i] = C; n     S[C -  a ].push_back(y); n   } n   for (int i = 0; i < m; i++) { n     if (A[i] ==  a ) { n       DFS(A[i] -  a ,   ); n     } n   } n   cout << SS.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 5e5 + 5; n struct Node { n   long long t, h, m; n } a[MAXN]; n bool cmp(Node x, Node y) { return x.m > y.m; } n long long n, x; n long long vis[MAXN]; n long long solve(long long now) { n   memset(vis, 0, sizeof(vis)); n   long long ans = 0; n   long long h = x; n   while (1) { n     long long f = 0; n     for (long long i = 1; i <= n; i++) { n       if (vis[i] == 0 && now != a[i].t && h >= a[i].h) { n         f = 1; n         now = 1 - now; n         vis[i] = 1; n         ans++; n         h += a[i].m; n         break; n       } n     } n     if (f == 0) { n       break; n     } n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> x; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i].t >> a[i].h >> a[i].m; n   } n   sort(a + 1, a + n + 1, cmp); n   long long ans = max(solve(1), solve(0)); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, perm[305], m[305][305]; n   char s[305]; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &perm[i]); n   } n   memset(m, 0, sizeof(m)); n   for (int i = 0; i < n; i++) { n     scanf( %s , s); n     for (int j = 0; j < n; j++) { n       if (s[j] ==  1 ) { n         m[i][j] = 1; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (m[i][j] == 1) { n         for (int a = 0; a < n; a++) { n           if (m[i][a] == 1 || m[j][a] == 1 || m[a][i] == 1 || m[a][j] == 1) { n             m[i][a] = 1; n             m[j][a] = 1; n             m[a][i] = 1; n             m[a][j] = 1; n           } n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (m[i][j] && perm[j] < perm[i]) { n         swap(perm[j], perm[i]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (i != 0) { n       printf(   ); n     } n     printf( %d , perm[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define ll long long int n #define pb push_back n #define mp make_pair n #define deb(x) cout<< #x <<     << x <<   n ; n #define MAX 9223372036854775807 n #define MIN -9223372036854775807 n #define PI 3.141592653589 n #define setbits(n) __builtin_popcountll(n) n #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin()); n const ll mod=998244353; n  n  n  n int main() { n      n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n     ll T=clock(); n  n     ll t; n     cin>>t; n     while(t--){ n         ll n,m; n         cin>>n>>m; n         vector<vector<ll>> a(n,vector<ll>(m)); n         vector<ll> p(n+m); n         for(ll i=0;i<n;i++){ n             for(ll j=0;j<m;j++){ n                 cin>>a[i][j]; n                 p[i+j]^=a[i][j]; n             } n         } n         bool ok=false; n         for(ll i=0;i<n+m;i++) n             if(p[i]!=0) n                 ok=true; n         if(ok) n             cout<< Ashish n ; n         else n             cout<< Jeel n ; n     } n  n  n  n     cerr<<  n nTIME:  <<(double)(clock()-T)/CLOCKS_PER_SEC<<  sec n ; n     T = clock(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int q; n int n; n int nav[200005], pos[200005]; n int main() { n   scanf( %d , &q); n   while (q--) { n     int men = 999999, lar = 999999; n     scanf( %d , &n); n     int a; n     for (int i = 0; i < n; i++) { n       scanf( %d , &a); n       if (nav[a] == 0) nav[a] = 1, pos[a] = i; n       if (nav[a] == 1) lar = i - pos[a], pos[a] = i; n       if (lar < men && lar != 0) men = lar; n     } n     printf( %d n , men == 999999 ? -1 : men + 1); n     for (int i = 0; i < 200001; i++) nav[i] = pos[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < N; i++) n     if (i * (i + 1) <= 2 * n && (i + 2) * (i + 1) > 2 * n) { n       cout << i << endl; n       for (int j = 1; j < i; j++) cout << j <<    ; n       cout << n - (i - 1) * i / 2; n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; n int ans[505][505]; n int col = 1, n, coz = 0; n int main() { n   std::ios::sync_with_stdio(false); n   scanf( %d , &n); n   if (n < 3) { n     printf( -1 ); n     return 0; n   } n   int now_ = 0, cot = n; n   int x = 1, y = 0; n   int rest = n * n; n   while (rest != 9) { n     for (int i = 1; i <= cot; i++) { n       coz++; n       x += dir[now_][0]; n       y += dir[now_][1]; n       ans[x][y] = coz; n     } n     rest -= cot; n     col++; n     if (col % 2 == 0) cot--; n     now_ = (now_ + 1) % 4; n   } n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 1; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 2; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 4; n   now_ = (now_ + 1) % 4; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 5; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 9; n   now_ = (now_ + 1) % 4; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 6; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 7; n   now_ = (now_ + 1) % 4; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 8; n   now_ = (now_ + 1) % 4; n   x += dir[now_][0]; n   y += dir[now_][1]; n   ans[x][y] = coz + 3; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) printf( %d  , ans[i][j]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, tf = 0, f = 0, hun = 0; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 25) n       tf++; n     else if (a[i] == 50) { n       f++; n       tf--; n     } else { n       hun++; n       if (f >= 1) { n         f--; n         tf--; n       } else n         tf = tf - 3; n     } n     if (tf < 0) { n       cout <<  NO ; n       break; n     } n   } n   if (tf >= 0) cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, y; n int main() { n   cin >> n; n   n--; n   for (int i = 1; i <= sqrt(n); i++) n     if (n % i == 0) { n       y = n / i - 1 - i; n       if ((y % 2 == 0) && (y > 0)) { n         cout << i <<     << y / 2; 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 n, m; n   cin >> n >> m; n   int a[n]; n   int b[m]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   int flag = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i] == b[j] && flag == 0) { n         cout << a[i] <<    ; n         flag = 1; n       } n     } n     flag = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int power(int a, int b, int p) { n   int ans = 1 % p; n   for (; b; b >>= 1) { n     if (b & 1) ans = (long long)ans * a % p; n     a = (long long)a * a % p; n   } n   return ans; n } n int a, b, c, d; n int main() { n   scanf( %d%d%d%d , &a, &b, &c, &d); n   if (a == d && (a != 0 || c == 0)) n     printf( 1 n ); n   else n     printf( 0 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXINT = 1000001; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n), b(n); n     vector<bool> used(MAXINT); n     set<int> dif; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a.begin(), a.end()); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < i; j++) { n         dif.insert(a[i] - a[j]); n       } n     } n     int p = 1; n     bool can = true; n     for (int i = 0; i < n; i++) { n       while (p < MAXINT && used[p]) { n         ++p; n       } n       if (p == MAXINT) { n         can = false; n         break; n       } n       b[i] = p; n       used[p] = true; n       for (int d : dif) { n         if (b[i] + d < MAXINT) { n           used[b[i] + d] = true; n         } n       } n     } n     if (can) { n       cout <<  YES n ; n       for (int i : b) { n         cout << i <<    ; n       } n       cout <<   n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[100001]; n int tmp, n, b[100001]; n vector<pair<int, int> > a; n int main() { n   int tt, ss; n   cin >> n; n   for (int i = (0); i <= (n - 1); i++) { n     cin >> tt >> ss; n     a.push_back(make_pair(tt, ss)); n   } n   sort(a.begin(), a.end()); n   tmp = 0; n   int mn = INT_MIN; n   for (int i = (0); i <= (n - 1); i++) { n     int lb = lower_bound(a.begin(), a.end(), n                          make_pair(a[i].first - a[i].second, 0)) - n              a.begin(); n     dp[i] = dp[lb - 1] + 1; n     mn = max(mn, dp[i]); n   } n   cout << n - mn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long b, deocoai, g, n, p, q, i, a[300], t, tong, z, a1, a2, k2, k1; n   cin >> b >> g >> n; n   if (min(b, g) >= n) { n     cout << n + 1; n     return 0; n   } n   if (max(b, g) >= n && min(b, g) <= n) { n     cout << min(b, g) + 1; n     return 0; n   } n   cout << b + g - n + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   long long ans = 0; n   vector<pair<int, int> > v; n   vector<int> all; n   for (int i = 1; i <= n; ++i) { n     int a, b, c, d; n     scanf( %d%d%d%d , &a, &b, &c, &d); n     if (a + b < c + d) { n       if (a > d) v.push_back(make_pair(a - d, d - a)); n       if (b > c) v.push_back(make_pair(c - b, b - c)); n     } else { n       v.push_back(make_pair(a, b)); n       v.push_back(make_pair(c, d)); n     } n   } n   for (auto p : v) { n     int a = p.first, b = p.second; n     all.push_back(a + b); n     ans += a - b; n   } n   sort(all.begin(), all.end(), greater<int>()); n   for (int i = 0; i < (int)all.size(); ++i) { n     if (i & 1) n       ans -= all[i]; n     else n       ans += all[i]; n   } n   printf( %lld n , ans / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long max_sz = 1e5 + 1; n const long long mod = 1e9 + 7; n const long long MAXN = 4e18 + 1; n char flip(char k) { n   if (k ==  0 ) return  1 ; n   return  0 ; n } n long long sum_digit(long long n) { n   long long a = 0, i; n   for (i = n; i > 0; i = i / 10) { n     a += (i % 10); n   } n   return a; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   long long t; n   t = 1; n   while (t--) { n     long long n; n     cin >> n; n     vector<long long> a(n); n     for (int i = 0; i < n; ++i) cin >> a[i]; n     sort(a.begin(), a.end()); n     long long f = 0; n     for (long long i = 0; i < n - 2; i++) { n       if (a[i] == a[i + 1] && a[i] == a[i + 2]) { n         f = 1; n         break; n       } n     } n     if (f == 1) n       cout <<  NO  n            <<   n ; n     else { n       cout <<  YES  n            <<   n ; n       vector<long long> inc, dec; n       for (long long i = 0; i < n;) { n         if (a[i] == a[i + 1]) { n           inc.push_back(a[i]); n           dec.push_back(a[i + 1]); n           i += 2; n         } else { n           inc.push_back(a[i]); n           i++; n         } n       } n       cout << inc.size() << endl; n       for (auto it : inc) cout << it <<    ; n       cout << endl; n       cout << dec.size() << endl; n       sort(dec.begin(), dec.end(), greater<long long>()); n       for (auto it : dec) cout << it <<    ; n       cout << endl; n     } n   } n   cerr << endl n        <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 0x3f3f3f3f; n const double PI = acos(-1.0); n const double EPS = 1e-8; n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     if (n <= 2) n       puts( -1 ); n     else { n       if (n % 2) n         cout << 2 * ((long long)(n / 2) * (n / 2) + n / 2) <<     n              << 2 * ((long long)(n / 2) * (n / 2) + n / 2) + 1 << endl; n       else n         cout << (long long)(n / 2) * (n / 2) - 1 <<     n              << (long long)(n / 2) * (n / 2) + 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double across(int n, int num_sides) { n   double ang = M_PI * ((double)num_sides / n) / 2; n   return 0.5 / sin(M_PI / (2 * n)) * sin(ang) * 2; n } n int main() { n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     double arg = (M_PI * (n - 1)) / ((double)2 * n); n     if (n % 2 == 0) { n       cout << setprecision(50) << tan(arg) <<   n ; n     } else { n       double r = 0.5 / sin(M_PI / (2 * n)); n       double side = r * 2 * sin((M_PI / n * (n - 1)) / 2); n       cout << setprecision(50) n            << sqrt(pow(across(n, n / 2), 2) / (double)2) + n                   sqrt(pow(across(n, n / 2 + 1), 2) / (double)2) n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a, i, j, ans, k, n, m; n   scanf( %d , &t); n   while (t--) { n     ans = 0; n     set<int> a; n     a.clear(); n     scanf( %d , &n); n     for (i = 1; i <= n; i++) { n       scanf( %d , &k); n       if (k % 2 == 0) a.insert(k); n     } n     while (a.size() != 0) { n       m = *a.rbegin(); n       ans++; n       a.erase(m); n       m /= 2; n       if (m % 2 == 0) a.insert(m); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline pair<long long int, long long int> compute_pos( n     pair<long long int, long long int> prev, char ch) { n   int flag = 1; n   pair<long long int, long long int> dest; n   dest = prev; n   if (ch ==  U ) dest.second += flag; n   if (ch ==  D ) dest.second -= flag; n   if (ch ==  R ) dest.first += flag; n   if (ch ==  L ) dest.first -= flag; n   return dest; n } n int main() { n   string str; n   pair<long long int, long long int> dest; n   ios_base::sync_with_stdio(false); n   cin >> dest.first >> dest.second; n   cin >> str; n   long long int R_num = 0, L_num = 0, U_num = 0, D_num = 0, i; n   for (i = 0; i < str.length(); i++) n     if (str[i] ==  U ) n       U_num++; n     else if (str[i] ==  D ) n       D_num++; n     else if (str[i] ==  L ) n       L_num++; n     else n       R_num++; n   long long int initial_moves, initial_moves_1 = 0, initial_moves_2 = 0, n                                R_net = R_num - L_num, U_net = U_num - D_num; n   if (R_net != 0) initial_moves_1 = dest.first / R_net; n   if (U_net != 0) initial_moves_2 = dest.second / U_net; n   int s_bit_1 = 1, s_bit_2 = 1; n   s_bit_1 = dest.first > 0 ? 1 : -1; n   s_bit_2 = dest.second > 0 ? 1 : -1; n   while (initial_moves_1 * R_net * s_bit_1 + R_num >= s_bit_1 * dest.first && n          initial_moves_1 > 0) n     initial_moves_1--; n   while (initial_moves_2 * U_net * s_bit_2 + U_num >= s_bit_2 * dest.second && n          initial_moves_2 > 0) n     initial_moves_2--; n   initial_moves = n       initial_moves_2 < initial_moves_1 ? initial_moves_1 : initial_moves_2; n   pair<long long int, long long int> position; n   position.first = 0; n   position.second = 0; n   initial_moves = initial_moves > 0 ? initial_moves : 0; n   position.first = R_net * initial_moves; n   position.second = U_net * initial_moves; n   int flag = 0; n   { n     if (position == dest) n       flag = 1; n     else if (R_net == 0 && U_net == 0) { n       for (i = 0; i < str.length(); i++) { n         position = compute_pos(position, str[i]); n         if (dest == position) { n           flag = 1; n           break; n         } n       } n     } else { n       while (true) { n         for (i = 0; i < str.length(); i++) { n           if (position == dest) { n             flag = 1; n             break; n           } n           position = compute_pos(position, str[i]); n         } n         if (position == dest) { n           flag = 1; n           break; n         } n         if (position.first - dest.first > L_num) break; n         if (position.second - dest.second > D_num) break; n         if (dest.first - position.first > R_num) break; n         if (dest.second - position.second > U_num) break; n       } n     } n   } n   if (flag == 1) n     cout <<  Yes  <<   n ; n   else n     cout <<  No  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[101], t, m, c, b, i, j, k, l; n string s; n int main() { n   cin >> t >> m; n   for (k = 0; k < t; k++) { n     cin >> s; n     if (s[0] ==  a ) { n       cin >> c; n       for (i = 0, j = -1; i < m; i++) n         if (i - j == c && !d[i]) n           break; n         else if (d[i]) n           j = i; n       if (i - j == c && i < m) { n         cout << ++b << endl; n         for (l = j + 1; l <= i; l++) d[l] = b; n       } else n         cout <<  NULL  << endl; n     } else if (s[0] ==  e ) { n       cin >> c; n       for (i = 0, j = 0; i < m; i++) n         if (d[i] == c && c != 0) d[i] = 0, j = 1; n       if (!j) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl; n     } else if (s[0] ==  d ) n       for (i = 0, j = 0; i < m; i++) n         if (d[i]) l = d[j], d[j] = d[i], d[i] = l, j++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch, s[22][22]; n int n, m, N, sg[22][22][22][22], op[22][22]; n bool ok, bo[100000]; n void read(int &x) { n   for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) ok = 1; n   for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   if (ok) x = -x; n } n int calc(int a, int b, int c, int d) { n   if (a > b || c > d) return 0; n   if (sg[a][b][c][d] != -1) return sg[a][b][c][d]; n   for (int i = a; i <= b; i++) n     for (int j = c; j <= d; j++) n       if (op[i][j] == 1) n         calc(a, b, c, j - 1), calc(a, b, j + 1, d); n       else if (op[i][j] == 2) n         calc(a, i - 1, c, d), calc(i + 1, b, c, d); n       else if (op[i][j] == 3) n         calc(a, i - 1, c, j - 1), calc(a, i - 1, j + 1, d), n             calc(i + 1, b, c, j - 1), calc(i + 1, b, j + 1, d); n   for (int i = a; i <= b; i++) n     for (int j = c; j <= d; j++) n       if (op[i][j] == 1) n         bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 1; n       else if (op[i][j] == 2) n         bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 1; n       else if (op[i][j] == 3) n         bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^ n            calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 1; n   for (int i = 0;; i++) n     if (!bo[i]) { n       sg[a][b][c][d] = i; n       break; n     } n   for (int i = a; i <= b; i++) n     for (int j = c; j <= d; j++) n       if (op[i][j] == 1) n         bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 0; n       else if (op[i][j] == 2) n         bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 0; n       else if (op[i][j] == 3) n         bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^ n            calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 0; n   return sg[a][b][c][d]; n } n int solve(int p) { n   memset(op, 0, sizeof(op)); n   memset(sg, -1, sizeof(sg)); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (((i + j) & 1) == p) { n         op[(i - j + m + 1) >> 1][(i + j) >> 1] = s[i][j] ==  L    ? 1 n                                                  : s[i][j] ==  R  ? 2 n                                                                   : 3; n       } n   int t = calc(1, N, 1, N); n   return t; n } n int main() { n   read(n), read(m), N = (n + m) >> 1; n   for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   puts(solve(0) ^ solve(1) ?  WIN  :  LOSE ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[100010]; n int l[100010], r[100010]; n int tree[100010 << 2]; n int lazy[100010 << 2]; n vector<int> v[100010]; n void build(int l, int r, int rt) { n   if (l == r) { n     tree[rt] = num[l]; n     lazy[rt] = 0; n     return; n   } n   int m = l + r >> 1; n   build(l, m, rt << 1); n   build(m + 1, r, rt << 1 | 1); n   tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]); n } n void update(int L, int R, int l, int r, int rt, int w) { n   if (L <= l && r <= R) { n     tree[rt] += w; n     lazy[rt] += w; n     return; n   } n   if (lazy[rt]) { n     tree[rt << 1] += lazy[rt]; n     tree[rt << 1 | 1] += lazy[rt]; n     lazy[rt << 1] += lazy[rt]; n     lazy[rt << 1 | 1] += lazy[rt]; n     lazy[rt] = 0; n   } n   int m = l + r >> 1; n   if (L <= m) update(L, R, l, m, rt << 1, w); n   if (R > m) update(L, R, m + 1, r, rt << 1 | 1, w); n   tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]); n } n int query(int x, int l, int r, int rt) { n   if (l == r) return tree[rt]; n   int m = l + r >> 1; n   if (lazy[rt]) { n     tree[rt << 1] += lazy[rt]; n     tree[rt << 1 | 1] += lazy[rt]; n     lazy[rt << 1] += lazy[rt]; n     lazy[rt << 1 | 1] += lazy[rt]; n     lazy[rt] = 0; n   } n   int ans = -0x3f3f3f3f; n   if (x <= m) n     ans = query(x, l, m, rt << 1); n   else n     ans = query(x, m + 1, r, rt << 1 | 1); n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> num[i]; n   build(1, n, 1); n   for (int i = 1; i <= m; ++i) { n     cin >> l[i] >> r[i]; n     v[l[i]].emplace_back(i); n     v[r[i] + 1].emplace_back(-i); n   } n   long long ans = -0x3f3f3f3f; n   int mark; n   for (int i = 1; i <= n; ++i) { n     int sz = v[i].size(); n     for (int j = 0; j < sz; j++) { n       int t = v[i][j]; n       if (t > 0) n         update(l[t], r[t], 1, n, 1, -1); n       else n         update(l[-t], r[-t], 1, n, 1, 1); n     } n     long long maxx = tree[1]; n     long long now = query(i, 1, n, 1); n     if (maxx - now > ans) { n       ans = maxx - now; n       mark = i; n     } n   } n   cout << ans << endl; n   long long number = 0; n   for (int i = 1; i <= m; ++i) { n     if (l[i] <= mark && r[i] >= mark) { n       number++; n     } n   } n   cout << number << endl; n   for (int i = 1; i <= m; ++i) { n     if (l[i] <= mark && r[i] >= mark) { n       cout << i <<    ; n     } n   } 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(NULL); n } n int main() { n   fast(); n   long long int t; n   t = 1; n   while (t--) { n     int n; n     cin >> n; n     long long arr[n]; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     sort(arr, arr + n, greater<int>()); n     int a = ceil((float)n / 2); n     int b = n - a; n     int answer = 0; n     int curr = a; n     vector<long long> arr2; n     vector<long long> arr3; n     for (int i = 1; i < a; i++) { n       for (int j = curr; j < n; j++) { n         if (arr[j] < arr[i]) { n           curr = j + 1; n           answer++; n           arr2.push_back(arr[j]); n           break; n         } else n           arr3.push_back(arr[j]); n       } n     } n     cout << answer << endl; n     for (int i = 0; i < arr3.size(); i++) arr2.push_back(arr3[i]); n     if (arr2.size() != b) { n       for (int i = 0; i < (b - arr2.size()); i++) n         arr2.push_back(arr[n - 1 - i]); n     } n     for (int i = 0; i < n; i++) { n       if (i % 2) n         cout << arr2[i / 2] <<    ; n       else n         cout << arr[i / 2] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int cnt(vector<vector<pair<int, int>>>& graph, int cur, int parent, int val) { n   int ans = 1; n   for (auto p : graph[cur]) { n     if (p.first == parent) continue; n     if (p.second == val) ans += cnt(graph, p.first, cur, val); n   } n   return ans; n } n void fill(vector<vector<pair<int, int>>>& graph, n           vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec, n           int cur, int parent, int val, int num) { n   if (val == 0) { n     visited[cur].first = true; n     cnt_vec[cur].first = num; n   } else { n     visited[cur].second = true; n     cnt_vec[cur].second = num; n   } n   for (auto p : graph[cur]) { n     if (p.first == parent) continue; n     if (p.second == val) fill(graph, visited, cnt_vec, p.first, cur, val, num); n   } n } n int process(vector<vector<pair<int, int>>>& graph, n             vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec, n             int start, int val) { n   int n = graph.size(), ans; n   ans = cnt(graph, start, -1, val); n   fill(graph, visited, cnt_vec, start, -1, val, ans); n   return ans; n } n int main() { n   int n, i, a, b, val, tmp; n   long long ans = 0; n   cin >> n; n   vector<vector<pair<int, int>>> graph(n + 1); n   for (i = 0; i < n - 1; ++i) { n     cin >> a >> b >> val; n     graph[a].push_back({b, val}); n     graph[b].push_back({a, val}); n   } n   vector<pair<int, int>> cnt_vec(n + 1, {0, 0}); n   vector<pair<bool, bool>> visited(n + 1, {false, false}); n   vector<int> components; n   for (i = 1; i <= n; ++i) { n     if (!visited[i].first) { n       tmp = process(graph, visited, cnt_vec, i, 0); n       if (tmp > 1) components.push_back(tmp); n     } n     if (!visited[i].second) { n       tmp = process(graph, visited, cnt_vec, i, 1); n       if (tmp > 1) components.push_back(tmp); n     } n   } n   for (auto num : components) ans += 1LL * num * (num - 1); n   for (i = 1; i <= n; ++i) n     ans += 1LL * (cnt_vec[i].first - 1) * (cnt_vec[i].second - 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n void pr_init() {} n void solve() { n   string str[2]; n   cin >> str[0] >> str[1]; n   long long ss = (long long)str[0].size(); n   long long dp[2][ss + 1]; n   for (long long i = 0; i < 2; i++) { n     for (long long j = 0; j < ss; j++) { n       if (str[i][j] ==  X ) n         dp[i][j] = 0; n       else n         dp[i][j] = 1; n     } n   } n   dp[0][ss] = dp[1][ss] = 0; n   long long ways = 0; n   for (long long j = 0; j < ss; j++) { n     if (dp[0][j] == 1 && dp[1][j] == 1) { n       if (dp[0][j + 1] == 1) n         ways++, dp[0][j + 1] = 0; n       else if (dp[1][j + 1] == 1) n         ways++, dp[1][j + 1] = 0; n       continue; n     } else if (dp[0][j] == 1) { n       if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1) n         ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0; n       continue; n     } else if (dp[1][j] == 1) { n       if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1) n         ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0; n       continue; n     } n   } n   cout << ways << endl; n } n int32_t main() { n   pr_init(); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n inline t read(t &x) { n   char c = getchar(); n   bool f = 0; n   x = 0; n   while (!isdigit(c)) f |= c ==  - , c = getchar(); n   while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   if (f) x = -x; n   return x; n } n template <class t, class... A> n inline void read(t &x, A &...a) { n   read(x); n   read(a...); n } n template <class t> n inline void write(t x) { n   if (x < 0) n     putchar( - ), write(-x); n   else { n     if (x > 9) write(x / 10); n     putchar( 0  + x % 10); n   } n } n const int N = 55; n int n, a[N], cnt; n signed main() { n   read(n); n   for (int i = 1; i <= n; i++) read(a[i]); n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= n; i++) cnt += a[i] == a[1]; n   if (cnt > n / 2) n     puts( Bob ); n   else n     puts( Alice ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5, Lim = 18; n int tr[maxn * 19][2], nowxor, cnt = 1, siz[maxn * 19], n, m; n template <typename T> n inline void read(T &x) { n   char c; n   int f = 1; n   while (!isdigit(c = getchar())) (c ==  - ) && (f = -1); n   x = c ^ 48; n   while (isdigit(c = getchar())) x = x * 10 + (c ^ 48); n   x *= f; n } n void insert(int x, int u = 1, int now = Lim) { n   if (now == -1) return siz[u] = 1, void(); n   int s = x >> now & 1; n   if (!tr[u][s]) tr[u][s] = ++cnt; n   insert(x, tr[u][s], now - 1); n   siz[u] = siz[tr[u][0]] + siz[tr[u][1]]; n } n inline int query(int x = nowxor) { n   int u = 1, res = 0; n   for (int i = Lim; i >= 0; --i) { n     int s = x >> i & 1; n     if (siz[tr[u][s]] == ((1 << i))) n       u = tr[u][s ^ 1], res |= (1 << i); n     else n       u = tr[u][s]; n     if (!u) return res; n   } n   return res; n } n int main() { n   int x; n   read(n); n   read(m); n   for (int i = 1; i <= n; ++i) read(x), insert(x); n   while (m--) { n     read(x); n     nowxor ^= x; n     printf( %d n , query()); n   } n   return 0; n   int yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n   yy = 0; n } n


#include <bits/stdc++.h> n long long vx[200010], vy[200010]; n std::map<long long, long long> mp, gg; n int main() { n   int n; n   long long a, b; n   scanf( %d%lld%lld , &n, &a, &b); n   long long ans = 0; n   for (int k = 1; k <= n; k++) { n     long long t; n     scanf( %lld%lld%lld , &t, &vx[k], &vy[k]); n     long long c = a * vx[k] - vy[k]; n     long long d = (long long)2000000000 * vx[k] + vy[k]; n     ans -= gg[d]; n     gg[d]++; n     ans += mp[c]; n     mp[c]++; n   } n   printf( %lld n , 2 * ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int mmmm = 1111; n int n; n char s[mmmm]; n int a[mmmm], f[mmmm]; n void qwe() { n   a[0] = 1989; n   f[0] = 1; n   for (int i = 1; i <= 9; i++) { n     f[i] = f[i - 1] * 10; n     a[i] = a[i - 1] + f[i]; n   } n } n int main() { n   qwe(); n   while (scanf( %d , &n) != EOF) { n     for (int i = 1; i <= n; i++) { n       scanf( %s , s); n       int l = strlen(s) - 4; n       int c = 0; n       for (int i = 4; i < l + 4; i++) { n         c = c * 10 + s[i] -  0 ; n       } n       int asd = a[l - 1]; n       int zxc = a[l]; n       int t1 = asd / f[l] * f[l] + c; n       int t2 = zxc / f[l] * f[l] + c; n       if (t1 >= asd && t1 < zxc) { n         printf( %d n , t1); n       } else { n         printf( %d n , t2); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const double PI = 3.141592653589793238463; n using namespace std; n inline long long add(long long a, long long b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n   return a; n } n inline long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) a += 1000000007; n   return a; n } n inline long long mul(long long a, long long b) { n   return (long long)((long long)a * b % 1000000007); n } n long long fast_power(long long base, long long power) { n   long long result = 1; n   while (power > 0) { n     if (power % 2 == 1) { n       result = (result * base); n     } n     base = (base * base); n     power = power / 2; n   } n   return result; n } n long long min(long long a, long long b) { return a > b ? b : a; } n long long max(long long a, long long b) { return a > b ? a : b; } n void SieveOfEratosthenes(long long n, unordered_set<long long> &s) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long p = 2; p <= n; p++) n     if (prime[p]) s.insert(p); n } n void dfs(long long s, vector<bool> &vis, vector<vector<long long>> &adlist) { n   if (vis[s]) return; n   vis[s] = true; n   for (auto x : adlist[s]) { n     if (vis[x] == false) { n       cout << s <<     << x <<   n ; n     } n     dfs(x, vis, adlist); n   } n } n void bfs(long long x, vector<bool> &vis, vector<vector<long long>> &adlist) { n   queue<long long> q; n   vis[x] = true; n   q.push(x); n   while (!q.empty()) { n     long long s = q.front(); n     q.pop(); n     for (auto u : adlist[s]) { n       if (vis[u]) continue; n       vis[u] = true; n       q.push(u); n     } n   } n } n bool bpchk(vector<vector<long long>> &adj, vector<long long> &color) { n   color[1] = 1; n   queue<long long> q; n   q.push(1); n   while (!q.empty()) { n     long long u = q.front(); n     q.pop(); n     for (auto x : adj[u]) { n       if (color[x] == -1) { n         color[x] = color[u] ^ 1; n         q.push(x); n       } n     } n   } n   for (long long i = 1; i < adj.size(); i++) { n     for (auto x : adj[i]) { n       if (color[x] == color[i]) return false; n     } n   } n   return true; n } n int main() { n   string s; n   cin >> s; n   bool flag = true; n   long long zc = 0, oc = 0; n   for (long long i = 0; i < s.size(); i++) { n     if (s[i] ==  0 ) { n       zc += 1; n     } else { n       oc += 1; n     } n     if (zc < oc) { n       flag = false; n       break; n     } n   } n   zc = 0, oc = 0; n   for (long long i = s.size() - 1; i >= 0; i--) { n     if (s[i] ==  0 ) { n       zc += 1; n     } else { n       oc += 1; n     } n     if (zc < oc) { n       flag = false; n       break; n     } n   } n   if (flag == false) { n     cout << -1 <<   n ; n   } else { n     long long vecsz = 0; n     long long ctr = 1; n     long long i = 0; n     vector<long long> s2; n     while (i < s.size()) { n       if (i == 0) { n         ctr = 1; n         s2.push_back(ctr); n       } else { n         if (s[i] == s[i - 1] && s[i] ==  0 ) { n           ctr += 1; n           s2.push_back(ctr); n         } else if (s[i] == s[i - 1] && s[i] ==  1 ) { n           ctr -= 1; n           s2.push_back(ctr); n         } else { n           s2.push_back(ctr); n         } n       } n       vecsz = max(vecsz, ctr); n       i += 1; n     } n     cout << vecsz <<   n ; n     vector<vector<long long>> v(vecsz + 1, vector<long long>()); n     for (long long i = 0; i < s2.size(); i++) { n       v[s2[i]].push_back(i + 1); n     } n     for (long long i = 1; i < v.size(); i++) { n       cout << v[i].size() <<    ; n       for (long long j = 0; j < v[i].size(); j++) { n         cout << v[i][j] <<    ; n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000000 + 7; n const int N = 10000001; n long long dp[N]; n int main() { n   dp[1] = 0; n   dp[2] = 3; n   for (int i = 3; i < N; i++) dp[i] = (dp[i - 2] * 3 + dp[i - 1] * 2) % mod; n   int n; n   while (scanf( %d , &n) != EOF) printf( %lld n , dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int maxn = 1e4 + 5; n int n, b, q; n int a[maxn], c[maxn]; n inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); } n inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); } n int main() { n   scanf( %d%d%d , &n, &b, &q); n   memset(a, -1, sizeof(a)); n   for (int i = (0); i < (q); ++i) { n     int x, k; n     scanf( %d%d , &x, &k); n     if (~a[x] && a[x] != k) { n       puts( unfair ); n       return 0; n     } n     a[x] = k; n   } n   if (~a[b] && a[b] != n) { n     puts( unfair ); n     return 0; n   } n   a[b] = n; n   a[0] = 0; n   for (int msk = (0); msk < (1 << 5); ++msk) { n     int x, g = 0, lst = 0; n     for (int i = (1); i <= (b); ++i) n       if (~a[i]) { n         int sub = 0, nin = 0; n         if (a[i] < a[lst]) { n           puts( unfair ); n           return 0; n         } n         for (int j = (0); j < (5); ++j) { n           if (msk >> j & 1) n             sub += calc(j, lst + 1, i); n           else n             nin += calc(j, lst + 1, i); n         } n         g += min(a[i] - a[lst], sub); n         if (a[i] - a[lst] > i - lst) { n           puts( unfair ); n           return 0; n         } n         lst = i; n       } n     x = __builtin_popcount(msk) * n / 5; n     if (x > g) { n       puts( unfair ); n       return 0; n     } n   } n   puts( fair ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e7; n int gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   int n, ans = INT_MAX, count = 0; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n     count += (v[i] == 1); n   } n   if (count > 0) { n     cout << n - count << endl; n   } else { n     vector<vector<int>> dp(n, vector<int>(n)); n     for (int i = 0; i < n; i++) dp[i][i] = v[i]; n     for (int i = 0; i < n; i++) n       for (int j = i + 1; j < n; j++) dp[i][j] = gcd(v[j], dp[i][j - 1]); n     for (int i = 0; i < n; i++) n       for (int j = i; j < n; j++) n         if (dp[i][j] == 1) ans = min(ans, j - i); n     if (ans == INT_MAX) n       cout << -1 << endl; n     else n       cout << ans + n - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n pair<int, int> p[10][10]; n int nom[4]; n bool cmp(int a, int b) { n   if (p[a][0] != p[b][0]) n     return (p[a][0] < p[b][0]); n   else n     return (p[a][1] < p[b][1]); n } n int main() { n   for (int i = (0); i < (4); i++) { n     for (int j = (0); j < (2); j++) { n       scanf( %d%d , &p[i][j].first, &p[i][j].second); n     } n     if (p[i][0].first == p[i][1].first) { n       if (p[i][0].second > p[i][1].second) swap(p[i][0], p[i][1]); n     } else { n       if (p[i][0].first > p[i][1].first) swap(p[i][0], p[i][1]); n     } n   } n   for (int i = (0); i < (4); i++) nom[i] = i; n   sort(nom, nom + 4, &cmp); n   if (p[nom[1]][0].second == p[nom[1]][1].second && n       p[nom[1]][0].first != p[nom[1]][1].first) { n     if (p[nom[0]][0].first == p[nom[0]][1].first && n         p[nom[0]][0].second != p[nom[0]][1].second) { n       if (p[nom[2]][0].second == p[nom[2]][1].second && n           p[nom[2]][0].first != p[nom[2]][1].first) { n         if (p[nom[3]][0].first == p[nom[3]][1].first && n             p[nom[3]][0].second != p[nom[3]][1].second) { n           if (p[nom[0]][0] == p[nom[1]][0] && p[nom[0]][1] == p[nom[2]][0] && n               p[nom[2]][1] == p[nom[3]][1] && p[nom[3]][0] == p[nom[1]][1]) { n             printf( YES n ); n             return 0; n           } n         } n       } n     } n   } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[200000]; n int cost[200001]; n int sub() { n   int n, p, k; n   cin >> n >> p >> k; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   sort(A, A + n); n   for (int i = 0; i < n; i++) { n     if (i < k - 1) { n       cost[i + 1] = cost[i] + A[i]; n     } else { n       cost[i + 1] = cost[i - k + 1] + A[i]; n     } n   } n   int ans = 0; n   for (int i = 0; i <= n; i++) { n     if (cost[i] <= p) { n       ans = i; n     } n   } n   cout << ans << endl; n   return 0; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     sub(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const long long INF = 1e18 + 1LL; n const double Pi = acos(-1.0); n const int N = 5e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9; n vector<int> G[N]; n long long dp[N][10], fs[N][10]; n long long ans = 0; n int n, k, a, b; n void dfs(int u, int f) { n   dp[u][0] = 1; n   for (int i = 0; i < G[u].size(); ++i) { n     int to = G[u][i]; n     if (to == f) continue; n     dfs(to, u); n     for (int j = 0; j <= k; ++j) { n       for (int h = 0; h <= k; ++h) { n         if (!dp[u][j] || !dp[to][h]) continue; n         long long tmp = j + h + 1; n         if (tmp % k) n           tmp = tmp / k + 1; n         else n           tmp = tmp / k; n         ans += tmp * dp[to][h] * dp[u][j] + fs[u][j] * dp[to][h] + n                fs[to][h] * dp[u][j]; n       } n     } n     for (int j = 1; j <= k; ++j) n       dp[u][j] += dp[to][j - 1], fs[u][j] += fs[to][j - 1]; n     dp[u][1] += dp[to][k]; n     fs[u][1] += fs[to][k] + dp[to][k]; n   } n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &a, &b); n     G[a].push_back(b); n     G[b].push_back(a); n   } n   dfs(1, 0); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   reverse(s.begin(), s.end()); n   reverse(t.begin(), t.end()); n   int i = 0; n   while (i < s.length() && i < t.length() && s[i] == t[i]) { n     i++; n   } n   cout << s.length() + t.length() - 2 * i; n } n


#include <bits/stdc++.h> n int main() { n   int n, s; n   scanf( %d%d , &n, &s); n   s *= 100; n   int max = 0; n   bool tr = false; n   for (int i = 1; i <= n; i++) { n     int d, c; n     scanf( %d%d , &d, &c); n     int money = d * 100 + c; n     if (money <= s) { n       tr = true; n       int sweet = (s - money) % 100; n       if (max < sweet) max = sweet; n     } n   } n   if (tr == false) n     printf( -1 n ); n   else n     printf( %d n , max); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, m; n int times[45]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k >> m; n   for (int i = 0; i < k; i++) cin >> times[i]; n   int s = 0; n   for (int i = 0; i < k; i++) s += times[i]; n   sort(begin(times), begin(times) + k); n   int currBest = 0; n   for (int numSolves = 0; numSolves < n + 1; numSolves++) { n     if (s * numSolves > m) break; n     int score = 0; n     score += numSolves * (k + 1); n     int timeLeft = m - s * numSolves; n     int numUnsolved = n - numSolves; n     int i = 0; n     while (timeLeft >= times[i] && i < k) { n       score += min(timeLeft / times[i], numUnsolved); n       timeLeft -= times[i] * min(timeLeft / times[i], numUnsolved); n       i++; n     } n     currBest = max(score, currBest); n   } n   cout << currBest <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename V> n void bugp(const pair<T, V> &x) { n   cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl; n } n template <typename T, typename U, typename V> n void bugpp(const pair<T, pair<U, V> > &x) { n   cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second n        <<  }}  << endl; n } n template <typename T> n bool maximize(T &x, const T &y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n template <typename T> n bool minimize(T &x, const T &y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n const int N = 100001; n int n, arr[N], dp[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   int total_sum = 0; n   map<int, int> cnt; n   for (int i = 1, _n = (n); i <= _n; ++i) { n     cin >> arr[i]; n     total_sum += arr[i]; n     if (!(total_sum & 1)) dp[i] = cnt[total_sum - total_sum / 2]; n     ++cnt[total_sum]; n   } n   long long ans = 0; n   int sum = 0; n   for (int i = (n), _b = (3); i >= _b; --i) { n     sum += arr[i]; n     if (3 * sum == total_sum) ans += dp[i - 1]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool chkmin(T &a, const T &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n inline bool chkmax(T &a, const T &b) { n   return a < b ? a = b, 1 : 0; n } n const int oo = 0x3f3f3f3f; n const long long OO = 0x3f3f3f3f3f3f3f3fLL; n const int maxn = 200000; n int d, V, n; n pair<int, int> a[maxn + 5]; n long long dp[maxn + 5]; n int Min[maxn + 5]; n int main() { n   memset(Min, -1, sizeof Min); n   scanf( %d%d%d , &d, &V, &n); n   for (int i = (0), _end_ = (n); i < _end_; ++i) n     scanf( %d%d , &a[i].first, &a[i].second); n   a[n++] = make_pair(0, 0); n   a[n++] = make_pair(d, 0); n   sort(a, a + n); n   for (int i = (0), _end_ = (n - 1); i < _end_; ++i) n     if (a[i].first + V < a[i + 1].first) { n       printf( -1 n ); n       return 0; n     } n   long long ans = 0; n   int lst = 0, cur = 0; n   for (int i = (1), _end_ = (n); i < _end_; ++i) { n     cur = a[i - 1].first; n     while (a[lst].first + V < a[i].first) { n       ans += (long long)(a[lst].first + V - cur) * a[lst].second; n       cur = a[lst].first + V; n       int best = -1; n       for (int j = lst + 1; j <= n; j += j & -j) n         if (best == -1 || (Min[j] != -1 && a[Min[j]].second < a[best].second)) n           best = Min[j]; n       lst = best; n     } n     ans += (long long)(a[i].first - cur) * a[lst].second; n     cur = a[i].first; n     if (a[i].second < a[lst].second) lst = i; n     for (int j = i; j > 0; j -= j & -j) n       if (Min[j] == -1 || a[Min[j]].second > a[i].second) Min[j] = i; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   if (n % 2) n     printf( black n ); n   else n     printf( white n1 2 n ); n } n


#include <bits/stdc++.h> n using namespace std; n namespace fastIO { n bool IOerror = 0; n inline char nc() { n   static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; n   if (p1 == pend) { n     p1 = buf; n     pend = buf + fread(buf, 1, 100000, stdin); n     if (pend == p1) { n       IOerror = 1; n       return -1; n     } n   } n   return *p1++; n } n inline bool blank(char ch) { n   return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n } n inline long long read() { n   bool sign = 0; n   char ch = nc(); n   long long x = 0; n   for (; blank(ch); ch = nc()) n     ; n   if (IOerror) return 0; n   if (ch ==  - ) sign = 1, ch = nc(); n   for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ; n   if (sign) x = -x; n   return x; n } n };  // namespace fastIO n using namespace fastIO; n vector<long long> e[2000010]; n long long dep[2000010], fa[2000010], son[2000010], top[2000010], id[2000010], n     now = 0, f[2000010]; n void dfs1(long long x, long long pre) { n   dep[x] = 1; n   for (auto i : e[x]) { n     if (i == pre) continue; n     dfs1(i, x); n     fa[i] = x; n     if (dep[i] > dep[son[x]]) son[x] = i; n     dep[x] = max(dep[x], dep[i] + 1); n   } n } n void dfs2(long long x, long long tp) { n   id[x] = ++now; n   top[x] = tp; n   if (son[x]) dfs2(son[x], son[x]); n   for (auto i : e[x]) { n     if (i == son[x] || i == fa[x]) continue; n     dfs2(i, tp); n   } n } n long long maxx[1000010], maxi[1000010]; n void merge(long long p, long long x, long long y) { n   for (long long i = 1; i <= dep[y]; i++) { n     f[id[x] + i - 1] += f[id[y] + i - 1]; n     if (f[id[x] + i - 1] > maxx[p] || n         (f[id[x] + i - 1] == maxx[p] && i < maxi[p])) n       maxx[p] = f[id[x] + i - 1], maxi[p] = i; n   } n } n void dfs3(long long x, long long pre) { n   if (son[x]) dfs3(son[x], x); n   if (son[x]) n     maxx[x] = maxx[son[x]], maxi[x] = maxi[son[x]] + 1; n   else n     maxx[x] = 1, maxi[x] = 0; n   for (auto i : e[x]) { n     if (i == fa[x] || i == son[x]) continue; n     dfs3(i, x); n     merge(x, son[x], i); n   } n   f[id[x]] = 1; n   if (maxx[x] == 1) maxi[x] = 0; n } n signed main() { n   long long n = read(); n   for (long long i = 1; i < n; i++) { n     long long x = read(), y = read(); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   dfs1(1, 1); n   dfs2(1, 1); n   dfs3(1, 1); n   for (long long i = 1; i <= n; i++) cout << maxi[i] <<   n ; n   return 0; n } n


#include <iostream> n #include <string.h> n #include <bits/stdc++.h> n using namespace std; n int main() { n     int t; n     cin >> t; n     while(t--) { n         int x; n         cin >> x; n         bool isPossible = false; n         for (int i = 0; i < 11; i++) { n             if (111*i <= x && (x - 111*i)%11 == 0) { n                 isPossible = true; n             } n         } n         if(isPossible) cout <<  YES  << endl; n         else cout <<  NO  << endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000005; n int a[maxn], ra[maxn]; n int main() { n   int n, m, k; n   while (~scanf( %d%d%d , &n, &m, &k)) { n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       ra[a[i]] = i; n     } n     int t; n     long long cnt = 0; n     for (int i = 0; i < m; i++) { n       scanf( %d , &t); n       int j = ra[t]; n       if ((j + 1) % k == 0) n         cnt += (j + 1) / k; n       else n         cnt += ((j + 1) / k + 1); n       if (j != 0) { n         swap(a[j], a[j - 1]); n         swap(ra[t], ra[a[j]]); n       } n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 30; n unsigned long long n, k, x; n unsigned long long a[300000]; n unsigned long long dpL[300000]; n unsigned long long dpR[300000]; n int main() { n   int i, j; n   cin >> n >> k >> x; n   unsigned long long s = 0, MAX = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (i = 0; i < n - 1; i++) { n     dpL[i + 1] = dpL[i] | a[i]; n   } n   for (i = n - 1; i > 0; i--) { n     dpR[i - 1] = dpR[i] | a[i]; n   } n   unsigned long long ans1 = a[0], ans2 = a[n - 1]; n   for (i = 0; i < k; i++) { n     ans1 = ans1 * x; n     ans2 = ans2 * x; n   } n   unsigned long long ans = max(ans1 | dpR[0], ans2 | dpL[n - 1]); n   for (i = 1; i < n - 1; i++) { n     unsigned long long ANS = a[i]; n     for (j = 0; j < k; j++) { n       ANS *= x; n     } n     ans = max(ans, ANS | dpL[i] | dpR[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int64_t n, m; n   cin >> n >> m; n   pair<char, int64_t> a[n][m]; n   for (int64_t i = 0; i < n; ++i) { n     for (int64_t j = 0; j < m; ++j) { n       cin >> a[i][j].first; n       a[i][j].second = 0; n     } n   } n   for (int64_t i = 0; i < n; ++i) { n     for (int64_t j = 0; j < m; ++j) { n       int64_t c = 0; n       for (int64_t k = 0; k < n; ++k) c += a[k][j].first == a[i][j].first; n       if (c > 1) a[i][j].second = 1; n       c = 0; n       for (int64_t k = 0; k < m; ++k) c += a[i][j].first == a[i][k].first; n       if (c > 1) a[i][j].second = 1; n     } n   } n   for (int64_t i = 0; i < n; ++i) { n     for (int64_t j = 0; j < m; ++j) { n       if (a[i][j].second == 0) cout << a[i][j].first; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int l, s, cnt, last, b[100005]; n char a[100005]; n int main() { n   int i, j; n   scanf( %s , a); n   l = strlen(a); n   for (i = 0; i < strlen(a); i++) { n     if (a[i] ==  ( ) n       s++; n     else if (a[i] ==  ) ) n       s--; n     else if (a[i] ==  # ) { n       s--; n       cnt++; n     } n     if (s < 0) { n       puts( -1 ); n       return 0; n     } n   } n   for (i = 0; i < cnt; i++) { n     b[i] = 1; n   } n   b[cnt - 1] += s; n   s = 0; n   for (i = 0, j = 0; i < strlen(a); i++) { n     if (a[i] ==  ( ) n       s++; n     else if (a[i] ==  ) ) n       s--; n     else if (a[i] ==  # ) n       s -= b[j++]; n     if (s < 0) { n       puts( -1 ); n       return 0; n     } n   } n   for (i = 0; i < cnt; i++) { n     printf( %d  , b[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, first, last, ans, flag; n   cin >> n; n   if (n <= 2) { n     cout << 0 << endl; n     return 0; n   } n   ans = flag = 0; n   first = 1; n   last = n; n   for (int i = 1; i < n; i++) { n     ans += (first + last) % (n + 1); n     if (!flag) { n       first++; n       swap((first), last); n     } else { n       first--; n       swap((first), last); n     } n     flag = 1 - flag; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n const int MAX = 1e5 + 55; n const int inf = 1e9 + 77; n const int MOD = 1e9 + 7; n const double PI = acos(-1.0); n const double eps = 1e-7; n int main() { n   long long n; n   scanf( %I64d , &n); n   long long div = 3; n   while (n % div == 0) div *= 3; n   n /= div; n   ++n; n   printf( %I64d , n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   float n; n   cin >> n; n   cout << ceil(n / 5); n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n  n using namespace std; n  n void solve(){ n     ll n, i; n     cin >> n; n     ll u, r, d, l; n     ll u1=0, r1=0, d1=0, l1=0; n     cin >> u >> r >> d >> l; n     if(u==n) r1++,l1++; n     if(d==n) r1++,l1++; n     if(r==n) u1++,d1++; n     if(l==n) u1++,d1++; n  n     if(u==n-1){ n         if(r1<r) r1++; n         else l1++; n     } n     if(d==n-1){ n         if(r1<r) r1++; n         else l1++; n     } n     if(r==n-1){ n         if(u1<u) u1++; n         else d1++; n     } n     if(l==n-1){ n         if(u1<u) u1++; n         else d1++; n     } n     if(u>=u1 and r>=r1 and l>=l1 and d>=d1) cout <<  YES n ; n     else cout <<  NO n ; n } n int main(){ n     ios_base::sync_with_stdio(false); cin.tie(NULL); n     ll t; n     cin >> t; n     while(t--) solve(); n } n  n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int x; n   cin >> x; n   cin.ignore(); n   string input; n   getline(cin, input); n   int len = input.length(); n   int cnt[3] = {0}; n   for (int i = 0; i < len; i++) { n     if (input[i] ==  0 ) n       cnt[0]++; n     else if (input[i] ==  1 ) n       cnt[1]++; n     else if (input[i] ==  2 ) n       cnt[2]++; n   } n   int max = len / 3; n   cnt[0] = max - cnt[0]; n   cnt[1] = max - cnt[1]; n   cnt[2] = max - cnt[2]; n   if (cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0) { n     std::cout << input <<   n ; n   } else { n     for (int i = 0; i < len && cnt[0] > 0; i++) { n       if (input[i] ==  1  && cnt[1] < 0) { n         input[i] =  0 ; n         cnt[1]++; n         cnt[0]--; n       } else if (input[i] ==  2  && cnt[2] < 0) { n         input[i] =  0 ; n         cnt[2]++; n         cnt[0]--; n       } n     } n     for (int i = len - 1; cnt[2] > 0; i--) { n       if (input[i] ==  1  && cnt[1] < 0) { n         input[i] =  2 ; n         cnt[1]++; n         cnt[2]--; n       } else if (input[i] ==  0  && cnt[0] < 0) { n         input[i] =  2 ; n         cnt[0]++; n         cnt[2]--; n       } n     } n     for (int i = 0; i < len && cnt[1] > 0 && cnt[2] < 0; i++) { n       if (input[i] ==  2 ) { n         input[i] =  1 ; n         cnt[1]--; n         cnt[2]++; n       } n     } n     for (int i = len - 1; i >= 0 && cnt[1] > 0 && cnt[0] < 0; i--) { n       if (input[i] ==  0 ) { n         input[i] =  1 ; n         cnt[1]--; n         cnt[2]++; n       } n     } n     std::cout << input <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[120], b[120], c[120], d[120]; n map<int, int> mp; n vector<int> ans; n int main() { n   memset(b, -1, sizeof(b)); n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     b[x] = y; n     mp[x] = i; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= n; i++) { n     ans.clear(); n     memcpy(c, a, sizeof(c)); n     memcpy(d, b, sizeof(d)); n     for (int q = 1; q <= m; q++) { n       int choose = -1, hp = 2000000000; n       for (int j = 1; j <= n; j++) { n         if (d[j] == -1) continue; n         int tmp = d[j], ok = 1; n         if (j <= i) { n           for (int k = j; k <= i; k++) { n             tmp += c[k]; n             if (tmp < 0) { n               ok = 0; n               break; n             } n           } n         } else { n           for (int k = j; k >= i; k--) { n             tmp += c[k]; n             if (tmp < 0) { n               ok = 0; n               break; n             } n           } n         } n         if (!ok) continue; n         if (tmp < hp) { n           choose = j; n           hp = tmp; n         } n       } n       if (choose == -1) break; n       for (int j = min(i, choose); j <= max(i, choose); j++) c[j] = 0; n       d[choose] = -1; n       ans.push_back(choose); n     } n     if (ans.size() == m) { n       printf( %d n , i); n       for (int j = 0; j < ans.size(); j++) printf( %d  , mp[ans[j]]); n       return 0; n     } n   } n   printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 5; n long double x[maxN], y[maxN], r[maxN], val[maxN]; n long double f(long double xx, long double yy) { n   for (int i = 0; i < 3; ++i) { n     val[i] = sqrt((x[i] - xx) * (x[i] - xx) + (y[i] - yy) * (y[i] - yy)) / r[i]; n   } n   val[3] = val[0]; n   long double answer = 0; n   for (int i = 0; i < 3; ++i) n     answer += (val[i] - val[i + 1]) * (val[i] - val[i + 1]); n   return answer; n } n int main() { n   for (int i = 0; i < 3; ++i) cin >> x[i] >> y[i] >> r[i]; n   long double pX = (x[0] + x[1] + x[2]) / 3., pY = (y[0] + y[1] + y[2]) / 3.; n   long double qq = 1.; n   while (qq > 1e-5) { n     if (f(pX - qq, pY) < f(pX, pY)) n       pX -= qq; n     else if (f(pX + qq, pY) < f(pX, pY)) n       pX += qq; n     else if (f(pX, pY - qq) < f(pX, pY)) n       pY -= qq; n     else if (f(pX, pY + qq) < f(pX, pY)) n       pY += qq; n     else n       qq *= 0.777777777; n   } n   if (f(pX, pY) > 1e-5) return 0; n   cout << fixed << setprecision(15) << pX <<     << pY << endl; n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-9; n const double PI = acos(-1.0); n const long long int mod = 1e9 + 7; n const int MAXN = 2e3 + 5; n using namespace std; n vector<vector<int>> adj(MAXN); n int mxd; n void dfs(int u, int d) { n   mxd = max(mxd, d); n   for (int v : adj[u]) dfs(v, d + 1); n } n void cp() { n   int n; n   cin >> n; n   vector<int> roots; n   for (int i = 0; i < n; i++) { n     int p; n     cin >> p; n     if (p == -1) n       roots.push_back(i); n     else n       adj[p - 1].push_back(i); n   } n   for (int u : roots) dfs(u, 1); n   cout << mxd <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t; n   t = 1; n   while (t--) { n     cp(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int power(long long int x, long long int y) { n   long long int temp; n   if (y == 0) return 1; n   temp = power(x, y / 2); n   if (y % 2 == 0) n     return temp * temp; n   else n     return x * temp * temp; n } n bool prime_check(long long int n) { n   long long int i, j; n   if (n == 1) { n     return false; n   } n   for (i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n long long int fact(long long int n) { n   long long int prod = 1; n   for (long long int i = 1; i <= n; i++) { n     prod = (prod * i) % 1000000007; n   } n   return prod; n } n bool vowl(char c) { n   return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, i; n     cin >> n; n     int a[n + 3]; n     multiset<int, greater<int>> ms; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       ms.insert(a[i]); n     } n     bool flag = 0; n     int x = *ms.begin(); n     --x; n     ms.erase(ms.begin()); n     while (!ms.empty()) { n       int first = *ms.begin(); n       --first; n       ms.erase(ms.begin()); n       if (x) ms.insert(x); n       x = first; n       flag = 1 - flag; n     } n     if (!flag) n       cout <<  T  n            <<   n ; n     else n       cout <<  HL  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline char nchar() { n   static const int bufl = 1 << 20; n   static char buf[bufl], *a = NULL, *b = NULL; n   return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF n                                                                         : *a++; n } n inline int read() { n   int x = 0, f = 1; n   char c = nchar(); n   for (; !isdigit(c); c = nchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = nchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const int maxn = 1e5 + 1; n int n, m; n namespace sgt { n struct D { n   double s, j; n   D(double s = 0, double j = 0) : s(s), j(j) {} n   inline void set() { n     int x = read(), y = read(); n     double d = (double)x / y; n     d = (1 - d) / d; n     s = (j = d) + 1; n   } n   inline friend D operator+(D a, D b) { n     return D(a.s + a.j * (b.s - 1), a.j * b.j); n   } n } t[maxn << 1]; n inline int ID(int l, int r) { return l + r | l != r; } n void build(int l, int r) { n   int x = ID(l, r); n   if (l == r) { n     t[x].set(); n     return; n   } n   int mid = l + r >> 1; n   build(l, mid), build(mid + 1, r); n   t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)]; n } n void reset(int l, int r, int p) { n   int x = ID(l, r); n   if (l == r) { n     t[x].set(); n     return; n   } n   int mid = l + r >> 1; n   p <= mid ? reset(l, mid, p) : reset(mid + 1, r, p); n   t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)]; n } n void reset(int p) { reset(1, n, p); } n D query(int L, int R, int l, int r) { n   if (L == l && R == r) return t[ID(L, R)]; n   int mid = L + R >> 1; n   if (r <= mid) return query(L, mid, l, r); n   if (l > mid) return query(mid + 1, R, l, r); n   return query(L, mid, l, mid) + query(mid + 1, R, mid + 1, r); n } n double query(int l, int r) { n   D d = query(1, n, l, r); n   return 1. / d.s; n } n }  // namespace sgt n int main() { n   n = read(), m = read(); n   sgt::build(1, n); n   while (m--) { n     int o = read(); n     if (o == 1) n       sgt::reset(read()); n     else { n       int l = read(), r = read(); n       double ans = sgt::query(l, r); n       printf( %.12lf n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = 9223372036854775807LL; n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroint-loops ) n long long int power(long long int a, long long int b, long long int m) { n   long long int res = 1; n   while (b) { n     if (b & 1) res = ((res % m) * (a % m)) % m; n     a = ((a % m) * (a % m)) % m; n     b >>= 1; n   } n   return res; n } n long long int power(long long int a, long long int b) { n   long long int res = 1; n   while (b) { n     if (b & 1) res *= a; n     a *= a; n     b >>= 1; n   } n   return res; n } n void solve() { n   long long int a, b, c, d, x, y; n   cin >> a >> b >> c >> d >> x >> y; n   if (abs(c - a) % x == 0 and abs(d - b) % y == 0) { n     long long int xx = abs(c - a) / x; n     long long int yy = abs(d - b) / y; n     if ((xx & 1 and yy & 1) or (xx & 1 ^ 1 and yy & 1 ^ 1)) n       cout <<  YES ; n     else n       cout <<  NO ; n   } else n     cout <<  NO ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int tt = 1; n   while (tt--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[10000] = {0}, d[10000] = {0}; n int main() { n   int n, m, i; n   scanf( %d%d , &n, &m); n   for (i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     c[x]++; n     d[y]++; n   } n   int ans = 0, j, kc = 0, kd = 0; n   for (i = 2; i <= n - 1; i++) { n     if (!c[i]) ans++; n     if (!d[i]) ans++; n   } n   if (n % 2 == 1 && !c[(n + 1) / 2] && !d[(n + 1) / 2]) ans--; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int x = a[0], j = 0; n   vector<int> pol(n, 0); n   pol[0] = 1; n   for (int i = 1; i < n; i++) { n     if (a[i] == x) n       pol[j]++; n     else { n       j++; n       pol[j]++; n       x = a[i]; n     } n   } n   bool same = 1; n   for (int i = 1; i <= j; i++) n     if (pol[i] != pol[i - 1]) same = false; n   if (same) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int visited[200001]; n int colour[200001]; n vector<int> adj_list[200001]; n int* graph[1000001]; n int* finalcolour[1000001]; n int size[1000001]; n int check; n int count1 = 0; n int k[9]; n int l[9]; n int dp[9][1001]; n int A[9][11]; n int c[9][10]; n bool pairCompare(const pair<int, int>& firstElem, n                  const pair<int, int>& secondElem) { n   return firstElem.first > secondElem.first; n } n int solve(int cards, int coins) { n   int i; n   if (cards <= 0) return 0; n   if (dp[cards][coins] != -1) return dp[cards][coins]; n   int ret = A[cards][l[cards]] + solve(cards - 1, coins); n   int use = 0; n   int coins_left = coins; n   for (i = l[cards] + 1; i <= k[cards]; i++) { n     coins_left = coins_left - c[cards][i - 1]; n     if (coins_left >= 0) n       ret = max(ret, A[cards][i] + solve(cards - 1, coins_left)); n     else n       break; n   } n   dp[cards][coins] = ret; n   return ret; n } n long long powe(long long a, long long b, long long k) { n   if (b == 0) return 1; n   long long temp = powe(a, b / 2, k); n   temp *= temp; n   if (temp >= k) temp %= k; n   if (b % 2 == 1) temp *= a; n   if (temp >= k) temp %= k; n   return temp; n } n void dfs(int x) { n   int i; n   visited[x] = 1; n   for (i = 0; i < adj_list[x].size(); i++) { n     if (visited[adj_list[x][i]] == 0) { n       printf( %d  , x); n       if (colour[x] == -1) { n         colour[x] = 1; n       } else { n         colour[x] = -1; n       } n       dfs(adj_list[x][i]); n       if (colour[adj_list[x][i]] == -1) { n         printf( %d %d  , x, adj_list[x][i]); n         colour[adj_list[x][i]] = 1; n         if (colour[x] == -1) { n           colour[x] = 1; n         } else { n           colour[x] = -1; n         } n       } n     } n   } n   printf( %d  , x); n   if (colour[x] == -1) { n     colour[x] = 1; n   } else { n     colour[x] = -1; n   } n } n int main() { n   int n, i, count = 0; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &colour[i]); n     visited[i] = 0; n     if (colour[i] == 1) count++; n   } n   for (i = 1; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     adj_list[x].push_back(y); n     adj_list[y].push_back(x); n   } n   if (count == n) { n     printf( 1 n ); n     return 0; n   } n   if (colour[1] == -1) n     colour[1] = 1; n   else n     colour[1] = -1; n   dfs(1); n   if (colour[1] == -1) { n     printf( %d 1 %d  , adj_list[1][0], adj_list[1][0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long inf = 4e18, mod = 1e9 + 7; n vector<pair<pair<long long, long long>, pair<long long, long long>>> v; n int segt[4 * 6000000 + 5], lazy[4 * 6000000 + 5]; n void push(int v, int l, int r) { n   segt[v] += lazy[v]; n   if (l != r) { n     lazy[2 * v] += lazy[v]; n     lazy[2 * v + 1] += lazy[v]; n   } n   lazy[v] = 0; n } n void update_range(int v, int l, int r, int qs, int qe, int x) { n   push(v, l, r); n   if (l > qe || r < qs) return; n   if (qs <= l && r <= qe) { n     lazy[v] += x; n     push(v, l, r); n     return; n   } n   int m = (l + r) / 2; n   update_range(2 * v, l, m, qs, qe, x); n   update_range(2 * v + 1, m + 1, r, qs, qe, x); n   segt[v] = max(segt[2 * v], segt[2 * v + 1]); n } n int query(int v, int l, int r, int qs, int qe) { n   push(v, l, r); n   if (l > qe || r < qs) return 0; n   if (qs <= l && r <= qe) return segt[v]; n   int m = (l + r) / 2; n   int val1 = query(2 * v, l, m, qs, qe); n   int val2 = query(2 * v + 1, m + 1, r, qs, qe); n   return max(val1, val2); n } n void solve() { n   int n, r; n   cin >> n >> r; n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     int X = x + y, Y = y - x; n     int lx, ly, ux, uy; n     lx = X - r, ux = X + r, ly = Y - r, uy = Y + r; n     lx += 3000000; n     ux += 3000000; n     ly += 3000000; n     uy += 3000000; n     v.push_back({{ly, 0}, {lx, ux}}); n     v.push_back({{uy, 1}, {lx, ux}}); n   } n   sort(v.begin(), v.end()); n   int res = 0; n   for (auto it : v) { n     if (it.first.second == 0) n       update_range(1, 0, 6000000, it.second.first, it.second.second, 1); n     else n       update_range(1, 0, 6000000, it.second.first, it.second.second, -1); n     int val = query(1, 0, 6000000, 0, 6000000); n     res = max(res, val); n   } n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n bool m[1001][1001]; n bool ff[1001][1001]; n int n, num; n int ans; n int main() { n   cin >> n >> num; n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= i + num; j++) n       if (!m[i][(j - 1) % n + 1]) { n         m[i][(j - 1) % n + 1] = true; n         m[(j - 1) % n + 1][i] = true; n         ff[i][(j - 1) % n + 1] = true; n       } else { n         cout << -1 << endl; n         return 0; n       } n   if (n == 1) { n     cout << -1 << endl; n     return 0; n   } n   cout << num * n << endl; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (ff[i][j]) printf( %d %d n , i, j); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 0) { n     cout << n / 2 - 1; n   } else { n     cout << (n + 1) / 2 - 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n int a[N]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t, i, j, n, m, l, r; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> l; n     a[l] = 1; n   } n   l = r = 0; n   if (a[1] == 1) l++; n   if (a[(int)1e6] == 1) l++; n   for (i = 2, j = 1e6 - 1; i < j && l < n; i++, j--, r++) { n     if (a[i] == 1) l++; n     if (a[j] == 1) l++; n   } n   cout << r <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int AbsDifference(int a, int b) { n   if (a >= b) return a - b; n   return b - a; n } n long long AbsDifference(long long a, long long b) { n   if (a >= b) return a - b; n   return b - a; n } n const int mod = 1000000007; n const int mod2 = 1000000009; n const int inf = 1 << 30; n const long long infLL = 1ll << 62; n const int impossible = -1; n struct stoyan_point { n   int x, y; n   int id; n }; n struct stoyan_pointLL { n   long long x, y; n   int id; n }; n struct stoyan_segment { n   stoyan_point first, second; n   int lenght; n   bool type; n   int id; n }; n struct stoyan_segmentLL { n   stoyan_pointLL first, second; n   long long lenght; n   bool type; n   int id; n }; n string translate(int number, int lenght, int k) { n   string ans; n   while (number) { n     ans += char(( 1 ) + number & 1); n     number >>= 1; n   } n   reverse(ans.begin(), ans.end()); n   return ans; n } n vector<int> find_divisors(long long number) { n   vector<int> ans; n   int sq = sqrt(number), j; n   for (j = 1; j <= sq; j++) { n     if (number % j == 0) { n       ans.push_back(j); n       if (j * j != number) ans.push_back(number / j); n     } n   } n   sort(ans.begin(), ans.end()); n   return ans; n } n int cnt_divisors(long long number) { n   int ans = 0; n   int sq = sqrt(number), j; n   for (j = 1; j <= sq; j++) { n     if (number % j == 0) { n       ans++; n       if (j * j != number) ans++; n     } n   } n   return ans; n } n int n; n string s; n int x, y; n int where_last = 0; n int AnswerProblem; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   cin >> s; n   for (int i = 0; i < int(s.size()); i++) { n     if (s[i] ==  R ) n       x++; n     else n       y++; n     if (y > x) { n       if (where_last == -1) { n         AnswerProblem++; n       } n       where_last = 1; n     } n     if (y < x) { n       if (where_last == 1) { n         AnswerProblem++; n       } n       where_last = -1; n     } n   } n   cout << AnswerProblem << endl; n   return 0; n } n


#include <bits/stdc++.h> n int t[10000]; n int main() { n   int n, m, k; n   std::cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       std::cin >> t[100 * i + j]; n     } n   } n   int ans = 1000000; n   if (n > k) { n     for (int j = 0; j < n; j++) { n       int dc = 0; n       for (int j2 = 0; j2 < m; j2++) { n         int c = 0; n         for (int i = 0; i < n; i++) { n           if (t[100 * i + j] == t[100 * i + j2]) c++; n         } n         dc += std::min(c, n - c); n       } n       ans = std::min(ans, dc); n     } n   } else { n     for (int j = 0; j < (1 << n); j++) { n       int dc = 0; n       for (int j2 = 0; j2 < m; j2++) { n         int c = 0; n         for (int i = 0; i < n; i++) { n           if (((int)(bool)(j & (1 << i))) == t[100 * i + j2]) c++; n         } n         dc += std::min(c, n - c); n       } n       ans = std::min(ans, dc); n     } n   } n   if (ans > k) { n     std::cout << -1; n   } else { n     std::cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char c[101]; n int n, ans; n int check(int k) { n   int cnt = 0, sum = 0; n   for (int i = 0; i < n; i++) { n     sum += c[i] -  0 ; n     if (sum > k) return 0; n     if (sum == k) sum = 0, cnt++; n   } n   return (sum == 0 && cnt > 1) ? 1 : 0; n } n int main() { n   scanf( %d , &n); n   scanf( %s , c); n   for (int i = 0; i <= 1000; i++) { n     if (check(i)) { n       printf( YES ); n       return 0; n     } n   } n   printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long t, i, l, k, j, b[23132], s, n; n   char ch[1000000]; n   while (gets(ch)) { n     l = strlen(ch); n     for (k = 0; k < 124; k++) b[k] = 0; n     for (k = 0; k < l; k++) { n       b[ch[k] - 48]++; n     } n     s = 0; n     for (j = 0; j < 124; j++) { n       if (0 < b[j]) s += b[j] * b[j]; n     } n     printf( %lld n , s); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long w, m, k; n int main() { n   scanf( %I64d%I64d%I64d , &w, &m, &k); n   w /= k; n   if (!w) { n     puts( 0 ); n     return 0; n   } n   long long cnt = 0; n   long long tmp = m; n   while (tmp) { n     cnt++; n     tmp /= 10; n   } n   tmp = 1; n   for (int i = 0; i < cnt; i++) tmp *= 10; n   long long x = m - 1, y = tmp - 1; n   while (w) { n     if (w < cnt) break; n     if (w >= (y - x) * cnt) { n       w -= (y - x) * cnt; n       x = y; n       y = y * 10 + 9; n       cnt++; n     } else { n       x += w / cnt; n       w = 0; n       break; n     } n   } n   cout << x - m + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF = (1e19); n int n, m; n int a[105]; n bool cmp(int a, int b) { return a > b; } n bool check(int d) { n   int i = 1, k = 0, ans = 0; n   while (a[i] - k > 0 && i <= n) { n     ans += (a[i] - k); n     if (i % d == 0) { n       k++; n     } n     if (ans >= m) { n       return true; n     } n     i++; n   } n   return false; n } n int main() { n   scanf( %d%d , &n, &m); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     ans += a[i]; n   } n   if (ans < m) { n     printf( -1 ); n   } else { n     sort(a + 1, a + 1 + n, cmp); n     int l = 1, r = n, p; n     while (l <= r) { n       int mid = (l + r) / 2; n       if (check(mid)) { n         r = mid - 1; n         p = mid; n       } else { n         l = mid + 1; n       } n     } n     printf( %d n , p); n   } 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   long long n; n   cin >> n; n   vector<long long> a(n); n   map<long long, long long> mp; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (mp[a[i]]) { n       mp[a[i]] = 0; n       mp[i + 1] = 1; n     } else { n       mp[i + 1] = 1; n       ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n const int MAXN = 1005; n vector<int> child[200000]; n int ceng[200000]; n void dfs(int v, int ii) { n   ceng[ii]++; n   for (int i = 0; i < child[v].size(); i++) { n     dfs(child[v][i], ii + 1); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   int temp; n   for (int i = 2; i <= n; i++) { n     scanf( %d , &temp); n     child[temp].push_back(i); n   } n   int ans = 0; n   dfs(1, 1); n   for (int i = 1; i <= n; i++) { n     if (ceng[i] % (2) == 0) ceng[i] = 0; n     if (ceng[i]) ceng[i] = 1; n     ans += ceng[i]; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 309, mod = 1e9 + 7; n inline long long read() { n   register long long x = 0, f = 1; n   register char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c - 48, c = getchar(); n   } n   return x * f; n } n void pls(long long &x, long long y) { n   x += y; n   x = (x >= mod ? x - mod : x); n } n long long n, a[N], s[N]; n namespace Solution_1 { n long long s[N], f[2][N][N]; n void solve() { n   long long d = 0; n   for (register long long i = (1); i <= (n); i++) { n     if (a[i] == a[i - 1]) n       s[i] = s[i - 1] + 1; n     else n       s[i] = 0; n   } n   f[0][0][0] = 1; n   for (register long long i = (1); i <= (n); i++) { n     if (a[i] != a[i - 1]) { n       for (register long long j = (0); j <= (i); j++) n         for (register long long k = (1); k <= (s[i - 1]); k++) n           pls(f[d ^ 1][j][0], f[d ^ 1][j][k]), f[d ^ 1][j][k] = 0; n     } n     for (register long long j = (0); j <= (i); j++) { n       long long upk = min(s[i], j); n       for (register long long k = (0); k <= (upk); k++) { n         if (j && k) n           pls(f[d][j][k], f[d ^ 1][j - 1][k - 1] * (2 * s[i] - k + 1) % mod); n         pls(f[d][j][k], f[d ^ 1][j][k] * (i - 2 * s[i] + 2 * k - j) % mod); n         pls(f[d][j][k], f[d ^ 1][j + 1][k] * (j - k + 1) % mod); n       } n     } n     memset(f[d ^ 1], 0, sizeof(f[d ^ 1])); n     if (i != n) d ^= 1; n   } n   printf( %lld n , f[d][0][0]); n } n }  // namespace Solution_1 n signed main() { n   n = read(); n   for (register long long i = (1); i <= (n); i++) { n     a[i] = read(); n     for (long long j = 2; j * j <= a[i]; j++) n       while (a[i] % (j * j) == 0) a[i] /= j * j; n   } n   sort(a + 1, a + n + 1); n   Solution_1::solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int poww(int a, int b) { n   for (int i = 0; i < b; i++) a *= a; n   return a; n } n int main() { n   int n, t; n   cin >> n; n   if (n < 10) { n     cout << n << endl; n     return 0; n   } n   long long i = 2; n   long long sum = 9; n   long long x = 10, v[] = {999999999, 99999999, 9999999, 999999, 99999, 9999, n                            999,       99,       9,       0,      0}; n   reverse(v, v + 11); n   for (int i = 10; i > 1; i--) { n     if (n - v[i] > 0) { n       sum += (n - v[i]) * i; n       n -= (n - v[i]); n     } n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3 + 5; n char g1[N][N]; n int dp1[N][N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   int n = 0, m = 0, ans1 = 0; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> g1[i]; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < m; ++j) { n       dp1[i][j] = 1; n       if (i > 2 && j > 0 && j < m - 1 && g1[i][j] == g1[i - 1][j] && n           g1[i][j] == g1[i - 2][j] && g1[i][j] == g1[i - 1][j - 1] && n           g1[i][j] == g1[i - 1][j + 1]) { n         dp1[i][j] += n             min(min(dp1[i - 1][j - 1], dp1[i - 1][j + 1]), dp1[i - 2][j]); n       } n       ans1 += dp1[i][j]; n     } n   } n   cout << ans1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 3; n int sz, mn, o, rt, s[N], s2[N], fa[N], ch[N][2], lf[N], cnt; n bool vis[N]; n void findrt(int u) { n   if (vis[u]) { n     s[u] = 0; n     return; n   } n   int mx; n   if (ch[u][0]) { n     int x = ch[u][0], y = ch[u][1]; n     findrt(x), findrt(y); n     s[u] = s[x] + s[y] + 1, mx = max(s2[u] = sz - s[u], max(s[x], s[y])); n   } else n     s[u] = 1, mx = s2[u] = sz - s[u]; n   if (mx < mn) mn = mx, o = u; n } n void lk(int f, int c, int x) { ch[fa[x] = f][c] = x; } n void solve(int u, int f, int c, int nd) { n   vis[u] = true; n   char str[5]; n   int x = ch[u][0], y = ch[u][1]; n   if (x) { n     printf( %d %d %d n , lf[x], lf[y], nd); n     fflush(stdout), scanf( %s , str); n   } n   if (!x || str[0] ==  X ) { n     if (!fa[u] || vis[fa[u]]) { n       if (!fa[u]) n         rt = ++cnt; n       else n         lk(fa[u], c, ++cnt); n       lk(cnt, 0, u), lk(cnt, 1, nd), lf[cnt] = lf[nd] = nd; n       return; n     } n     sz = mn = s2[u], findrt(f ? ch[f][c] : rt), solve(o, f, c, nd); n   } else { n     int t = str[0] ==  Y , x = ch[u][t]; n     if (vis[x]) { n       lk(++cnt, 0, x), lk(cnt, 1, nd), lk(u, t, cnt), lf[cnt] = lf[nd] = nd; n       return; n     } n     sz = mn = s[x], findrt(x), solve(o, u, t, nd); n   } n } n int main() { n   srand(time(0)); n   int n; n   scanf( %d , &n); n   cnt = n; n   lk(rt = ++cnt, 0, 1), lk(rt, 1, 2), lf[1] = lf[rt] = 1, lf[2] = 2; n   for (int i = 3; i <= n; ++i) { n     memset(vis, 0, sizeof(vis)); n     sz = mn = 2 * (i - 1) - 1, findrt(rt), solve(o, 0, 0, i); n   } n   puts( -1 ); n   for (int i = 1; i <= cnt; ++i) printf( %d  , fa[i] ? fa[i] : -1); n   fflush(stdout); n   return 0; n } n