#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int l = s.length(); n   if ((s[l - 1] - 48) % 2 == 0) { n     int temp = s[l - 2] * 10 + s[l - 1]; n     if (temp % 4 == 0) { n       cout << 4 << endl; n     } else { n       cout << 0 << endl; n     } n   } else { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int c[100010]; n int x[100010], y[100010]; n vector<int> t[100010]; n int f[100010]; n int find(int x) { return (f[x] == -1 ? x : f[x] = find(f[x])); } n int fa[100010], dep[100010]; n int dfn[100010], rnk[100010], totn = 0; n int siz[100010], son[100010], top[100010]; n void dfs1(int k) { n   dep[k] = dep[fa[k]] + 1; n   siz[k] = 1; n   for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) { n     if (*it == fa[k]) continue; n     fa[*it] = k; n     dfs1(*it); n     siz[k] += siz[*it]; n     if (son[k] == 0 || siz[*it] > siz[son[k]]) son[k] = *it; n   } n   return; n } n void dfs2(int k, int tp) { n   dfn[k] = ++totn; n   rnk[totn] = k; n   top[k] = tp; n   if (son[k]) dfs2(son[k], tp); n   for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) { n     if (*it == fa[k] || *it == son[k]) continue; n     dfs2(*it, *it); n   } n   return; n } n int LCA(int a, int b) { n   while (top[a] != top[b]) { n     if (dep[top[a]] < dep[top[b]]) swap(a, b); n     a = fa[top[a]]; n   } n   return (dep[a] < dep[b] ? a : b); n } n long long v[100010]; n void dfs3(int k) { n   v[k] = c[k]; n   for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) { n     if (*it == fa[k]) continue; n     dfs3(*it); n     v[k] -= v[*it]; n   } n   return; n } n long long ve[100010]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &c[i]); n   for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &y[i]); n   memset(f, -1, sizeof(f)); n   for (int i = 1; i <= m; ++i) { n     int p = find(x[i]), q = find(y[i]); n     if (p == q) continue; n     f[p] = q; n     t[x[i]].push_back(y[i]); n     t[y[i]].push_back(x[i]); n   } n   dfs1(1); n   dfs2(1, 1); n   dfs3(1); n   for (int i = 1; i <= m; ++i) { n     if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) continue; n     if ((dep[x[i]] + dep[y[i]] - 2 * dep[LCA(x[i], y[i])]) % 2 == 0) { n       int val = v[1] / 2; n       val = val * (dep[x[i]] % 2 == 0 ? -1 : 1); n       ve[i] = val; n       c[x[i]] -= val; n       c[y[i]] -= val; n       break; n     } n   } n   dfs3(1); n   if (v[1] != 0) { n     puts( NO ); n     return 0; n   } n   puts( YES ); n   for (int i = 1; i <= m; ++i) { n     if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) { n       if (dep[x[i]] < dep[y[i]]) swap(x[i], y[i]); n       ve[i] = v[x[i]]; n     } n     printf( %lld n , ve[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( fast-math ) n using namespace std; n const int INF = 1e9; n const long long INFll = 2e18; n const int BASE1 = 179; n const int BASE2 = 653; n const long long MOD = 1e9 + 7; n const int MAXN = 2e5; n const long double PI = 3.1415926535; n const long double EPS = 1e-10; n void solve() { n   int n; n   cin >> n; n   vector<vector<char>> dop(n, vector<char>(n,  * )); n   for (int i = 0; i < (n); i++) { n     for (int j = 0; j < (n); j++) { n       if (abs(i - n / 2) + abs(j - n / 2) <= n / 2) dop[i][j] =  D ; n     } n   } n   for (int i = 0; i < (n); i++) { n     for (int j = 0; j < (n); j++) { n       cout << dop[i][j]; n     } n     cout <<   n ; n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(15); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 10; n long long n, m; n long long res[N], sum[N], a[N]; n long long len; n struct Node { n   int x, p, id; n } Q[N]; n inline long long read() { n   long long x = 0, f = 0; n   char ch; n   while (((ch = getchar()) <  0  || ch >  9 ) && (ch !=  - )) n     ; n   while (!isdigit(ch)) f |= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); n   return f ? -x : x; n } n inline bool cmp(Node a, Node b) { return a.p != b.p ? a.p < b.p : a.x > b.x; } n signed main() { n   n = read(); n   len = sqrt(n); n   for (long long i = 1; i <= n; i++) a[i] = read(); n   m = read(); n   for (int i = 1; i <= m; i++) { n     long long x, p; n     x = read(), p = read(); n     Q[i].x = x, Q[i].p = p; n     Q[i].id = i; n   } n   sort(Q + 1, Q + m + 1, cmp); n   int last = n; n   for (int i = 1; i <= m; i++) { n     long long ans = 0; n     if (Q[i].p >= len) { n       for (int j = Q[i].x; j <= n; j += Q[i].p) { n         ans += a[j]; n       } n     } else { n       int p = Q[i].p, x = Q[i].x; n       if (Q[i].p != Q[i - 1].p) last = n; n       for (int j = last; j >= x; j--) { n         sum[j] = a[j]; n         if (j + p <= n) sum[j] += sum[j + p]; n       } n       last = x - 1; n       ans = sum[x]; n     } n     res[Q[i].id] = ans; n   } n   for (int i = 1; i <= m; i++) printf( %lld n , res[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long readi() { n   long long input = 0; n   char c =    ; n   while (c <  - ) { n     c = getchar(); n   } n   bool negative = false; n   if (c ==  - ) { n     negative = true; n     c = getchar(); n   } n   while (c >=  0 ) { n     input = 10 * input + (c -  0 ); n     c = getchar(); n   } n   if (negative) { n     input = -input; n   } n   return input; n } n void printi(long long output) { n   if (output == 0) { n     putchar( 0 ); n     return; n   } n   if (output < 0) { n     putchar( - ); n     output = -output; n   } n   int aout[20]; n   int ilen = 0; n   while (output) { n     aout[ilen] = ((output % 10)); n     output /= 10; n     ilen++; n   } n   for (int i = ilen - 1; i >= 0; i--) { n     putchar(aout[i] +  0 ); n   } n   return; n } n string reads() { n   string input =   ; n   char c =    ; n   while (c <=    ) { n     c = getchar(); n   } n   while (c >    ) { n     input += c; n     c = getchar(); n   } n   return input; n } n void prints(string output) { n   for (int i = 0; i < output.length(); i++) { n     putchar(output[i]); n   } n   return; n } n long long getrand() { n   long long rand1 = (rand() % 536870912); n   long long rand2 = (rand() % 536870912); n   return (rand1 * 536870912ll + rand2); n } n int N, E; n vector<string> pretest, systest; n vector<int> badp, bads; n vector<pair<string, int> > ans; n int nump[1000010], nums[1000010]; n bool used[1000010]; n vector<int> vp, vs, num; n int32_t main() { n   srand(time(NULL)); n   cout << fixed << setprecision(10); n   cerr << fixed << setprecision(10); n   ios_base::sync_with_stdio(false); n   if (fopen( cf860c.in ,  r )) { n     freopen( cf860c.in ,  r , stdin); n   } n   cin >> N; n   for (int i = 0; i < N; i++) { n     string s; n     cin >> s; n     bool idx; n     cin >> idx; n     if (idx) { n       pretest.push_back(s); n     } else { n       systest.push_back(s); n     } n   } n   E = pretest.size(); n   for (int i = 0; i < pretest.size(); i++) { n     bool isnum = true; n     for (int j = 0; j < pretest[i].length(); j++) { n       if (!isdigit(pretest[i][j])) { n         isnum = false; n       } n     } n     if (pretest[i][0] ==  0 ) { n       isnum = false; n     } n     if (isnum) { n       nump[i] = stoi(pretest[i]); n       used[nump[i]] = true; n       if (E + 1 <= nump[i] && nump[i] <= N) { n         badp.push_back(i); n       } n     } n   } n   for (int i = 0; i < systest.size(); i++) { n     bool isnum = true; n     for (int j = 0; j < systest[i].length(); j++) { n       if (!isdigit(systest[i][j])) { n         isnum = false; n       } n     } n     if (systest[i][0] ==  0 ) { n       isnum = false; n     } n     if (isnum) { n       nums[i] = stoi(systest[i]); n       used[nums[i]] = true; n       if (1 <= nums[i] && nums[i] <= E) { n         bads.push_back(i); n       } n     } n   } n   for (int i = 100000; i < 1000000; i++) { n     if (!used[i]) { n       num.push_back(i); n     } n   } n   for (int i = 1; i <= E; i++) { n     if (!used[i]) { n       vp.push_back(i); n     } n   } n   for (int i = E + 1; i <= N; i++) { n     if (!used[i]) { n       vs.push_back(i); n     } n   } n   while (!badp.empty() || !bads.empty()) { n     if (!badp.empty() && !vp.empty()) { n       int idx = badp.back(); n       badp.pop_back(); n       vs.push_back(nump[idx]); n       ans.push_back(make_pair(pretest[idx], vp.back())); n       pretest[idx] = to_string(vp.back()); n       nump[idx] = vp.back(); n       vp.pop_back(); n     } else if (!bads.empty() && !vs.empty()) { n       int idx = bads.back(); n       bads.pop_back(); n       vp.push_back(nums[idx]); n       ans.push_back(make_pair(systest[idx], vs.back())); n       systest[idx] = to_string(vs.back()); n       nums[idx] = vs.back(); n       vs.pop_back(); n     } else if (!badp.empty()) { n       int idx = badp.back(); n       badp.pop_back(); n       vs.push_back(nump[idx]); n       ans.push_back(make_pair(pretest[idx], num.back())); n       pretest[idx] = to_string(num.back()); n       nump[idx] = num.back(); n       num.pop_back(); n     } else if (!bads.empty()) { n       int idx = bads.back(); n       bads.pop_back(); n       vp.push_back(nums[idx]); n       ans.push_back(make_pair(systest[idx], num.back())); n       systest[idx] = to_string(num.back()); n       nums[idx] = num.back(); n       num.pop_back(); n     } n   } n   for (int i = 0; i < pretest.size(); i++) { n     if (1 <= nump[i] && nump[i] <= E) { n       continue; n     } n     ans.push_back(make_pair(pretest[i], vp.back())); n     pretest[i] = vp.back(); n     vp.pop_back(); n   } n   for (int i = 0; i < systest.size(); i++) { n     if (E + 1 <= nums[i] && nums[i] <= N) { n       continue; n     } n     ans.push_back(make_pair(systest[i], vs.back())); n     systest[i] = vs.back(); n     vs.pop_back(); n   } n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); i++) { n     cout <<  move   << ans[i].first <<     << ans[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const int MAXN = 200010; n char str[MAXN + 1], S[MAXN + 1]; n int main() { n   scanf( %s , str + 1); n   int N = strlen(str + 1); n   for (int i = 0; i <= N; i++) n     for (char c =  a ; c <=  z ; c++) { n       int top = 0; n       for (int j = 1; j <= i; j++) S[++top] = str[j]; n       S[++top] = c; n       for (int j = i + 1; j <= N; j++) S[++top] = str[j]; n       bool flag = 1; n       for (int j = 1; j <= top; j++) n         if (S[j] != S[top - j + 1]) { n           flag = 0; n           break; n         } n       if (flag) { n         for (int j = 1; j <= top; j++) printf( %c , S[j]); n         printf(  n ); n         return 0; n       } n     } n   printf( NA n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int main() { n   cin >> N >> M; n   int putere = 1; n   for (int i = 1; i <= M; i++) { n     putere <<= 1; n     if (putere >= 1000000009) putere -= 1000000009; n   } n   int val = 1; n   for (int i = putere - 1; i >= putere - N; i--) n     val = (1LL * val * i) % 1000000009; n   cout << val; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 4e5 + 10; n long long t, n, k, p, a[M], dp[M], s[M], ans; n long long bs(long long r, long long rem) { n   long long l = 0, mid; n   r++; n   while (r - l > 1) { n     mid = (r + l) / 2; n     if (s[mid] > rem) n       r = mid; n     else n       l = mid; n   } n   return l; n } n int32_t main() { n   cin >> t; n   while (t--) { n     scanf( %lld%lld%lld , &n, &p, &k); n     for (long long i = 1; i <= n; i++) { n       scanf( %lld , a + i); n     } n     sort(a + 1, a + n + 1); n     fill(s, s + n + 1, 0); n     fill(dp, dp + n + 1, 0); n     ans = 0; n     for (long long i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; n     for (long long i = k; i < k + k; i++) dp[i] = a[i]; n     for (long long i = k + k; i <= n; i++) dp[i] = dp[i - k] + a[i]; n     for (long long i = n; i >= k; i--) n       if (dp[i] <= p) ans = max(ans, i - (i % k) + bs(i % k, p - dp[i])); n     ans = max(ans, bs(k - 1, p)); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100001]; n long long n, k; n int main() { n   long long p = 0, no = 0; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   p = 0; n   for (int i = 0; i < n; i++) { n     if (p != a[i]) { n       no++; n       cout << a[i] - p << endl; n     } n     p = a[i]; n     if (no == k) break; n   } n   for (int i = 0; i < (k - no); i++) cout <<  0  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1001], m, cnt[1001]; n set<int> S; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> a[i]; n     cnt[a[i]]++; n   } n   cout << *min_element(cnt + 1, cnt + n + 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int q; n   cin >> q; n   vector<int> ta(n, -1); n   vector<int> payouts(q, 0); n   for (int i = 0; i < q; i++) { n     int k, p, x; n     cin >> k; n     if (k == 1) { n       cin >> p >> x; n       a[p - 1] = x; n       ta[p - 1] = i; n     } else { n       cin >> x; n       payouts[i] = x; n     } n   } n   vector<int> maxpayouts(q, payouts[q - 1]); n   for (int i = q - 2; i >= 0; i--) { n     maxpayouts[i] = max(maxpayouts[i + 1], payouts[i]); n   } n   maxpayouts.push_back(0); n   for (int i = 0; i < n; i++) { n     int res = max(maxpayouts[ta[i] + 1], a[i]); n     cout << res <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long maxn = 200005; n unsigned long long n, m, vis[maxn]; n unsigned long long sum, A, B, C, he[maxn]; n struct node { n   unsigned long long x, y; n   bool operator<(const node &a) const { return x == a.x ? x < a.x : y < a.y; } n } chongtu[maxn]; n vector<unsigned long long> to[maxn], from[maxn]; n vector<unsigned long long> toq[maxn], fromq[maxn]; n map<pair<unsigned long long, unsigned long long>, unsigned long long> mp; n inline unsigned long long read() { n   unsigned long long 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 = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n inline void write(unsigned long long a) { n   if (a < 0) { n     putchar( - ); n     putchar( 1 ); n   } else { n     if (a >= 10) write(a / 10); n     putchar(a % 10 +  0 ); n   } n } n signed main() { n   n = read(), m = read(); n   A = read(), B = read(), C = read(); n   for (unsigned long long i = 0; i <= n - 3; ++i) { n     unsigned long long len = (n - 1) - (i + 1) + 1; n     sum += 1ull * len * (len - 1) / 2 * A * i; n   } n   for (unsigned long long j = 1; j <= n - 2; ++j) { n     unsigned long long len1 = (j - 1) - 0 + 1, len2 = (n - 1) - (j + 1) + 1; n     sum += 1ull * len1 * len2 * B * j; n   } n   for (unsigned long long k = 2; k <= n - 1; ++k) { n     unsigned long long len = (k - 1) - 0 + 1; n     sum += 1ull * len * (len - 1) / 2 * C * k; n   } n   for (unsigned long long i = 1; i < n; ++i) he[i] = he[i - 1] + i; n   for (unsigned long long i = 1; i <= m; ++i) { n     unsigned long long x = read(), y = read(); n     if (x > y) swap(x, y); n     chongtu[i].x = x, chongtu[i].y = y; n   } n   sort(chongtu + 1, chongtu + m + 1); n   for (unsigned long long i = 1; i <= m; ++i) { n     unsigned long long x = chongtu[i].x, y = chongtu[i].y; n     mp[make_pair(x, y)]++; n     to[x].push_back(y); n     toq[x].push_back(1); n     from[y].push_back(x); n     fromq[y].push_back(1); n     if (x >= 1) n       sum -= 1ull * ((x - 1) - 0 + 1) * (B * x + C * y) + n              1ull * A * (he[x - 1] - he[0]); n     if (y - x >= 2) n       sum -= 1ull * ((y - 1) - (x + 1) + 1) * (A * x + C * y) + n              1ull * B * (he[y - 1] - he[x]); n     if (y <= n - 2) n       sum -= 1ull * ((n - 1) - (y + 1) + 1) * (A * x + B * y) + n              1ull * C * (he[n - 1] - he[y]); n   } n   for (unsigned long long i = 0; i < n; ++i) { n     sort(to[i].begin(), to[i].end()); n     sort(from[i].begin(), from[i].end()); n   } n   for (unsigned long long fu = 0; fu < n; ++fu) { n     unsigned long long size11 = to[fu].size(); n     for (unsigned long long k = 0; k < size11; ++k) { n       unsigned long long zi = to[fu][k]; n       toq[fu][k] = zi; n       if (k) toq[fu][k] += toq[fu][k - 1]; n     } n   } n   for (unsigned long long zi = 0; zi < n; ++zi) { n     unsigned long long size11 = from[zi].size(); n     for (unsigned long long k = 0; k < size11; ++k) { n       unsigned long long fu = from[zi][k]; n       fromq[zi][k] = fu; n       if (k) fromq[zi][k] += fromq[zi][k - 1]; n     } n   } n   for (unsigned long long fu = 0; fu < n; ++fu) { n     unsigned long long size = to[fu].size(); n     sum += 1ull * (size - 1) * (size) / 2 * A * fu; n     for (unsigned long long j = 0; j < size; ++j) { n       unsigned long long zi1 = to[fu][j]; n       sum += 1ull * B * ((size - 1) - (j + 1) + 1) * zi1; n       sum += 1ull * C * (toq[fu][size - 1] - toq[fu][j]); n     } n   } n   for (unsigned long long zi = 0; zi < n; ++zi) { n     unsigned long long size = from[zi].size(); n     sum += 1ull * (size - 1) * (size) / 2 * C * zi; n     for (unsigned long long j = 0; j < size; ++j) { n       unsigned long long fu1 = from[zi][j]; n       sum += 1ull * A * ((size - 1) - (j + 1) + 1) * fu1; n       sum += 1ull * B * (fromq[zi][size - 1] - fromq[zi][j]); n     } n   } n   for (unsigned long long zi = 0; zi < n; ++zi) { n     unsigned long long size1 = to[zi].size(), size2 = from[zi].size(); n     sum += 1ull * B * (size1) * (size2)*zi; n     for (unsigned long long j = 0; j < size1; ++j) { n       unsigned long long sun = to[zi][j]; n       sum += 1ull * C * sun * size2; n       if (size2) sum += 1ull * A * fromq[zi][size2 - 1]; n       for (unsigned long long k = 0; k < size2; ++k) { n         unsigned long long fu = from[zi][k]; n       } n     } n   } n   for (unsigned long long fu = 0; fu < n; ++fu) { n     unsigned long long size = to[fu].size(); n     for (unsigned long long j = 0; j < size; ++j) vis[to[fu][j]] = 1; n     for (unsigned long long j = 0; j < size; ++j) { n       unsigned long long zi = to[fu][j]; n       unsigned long long sizez = to[zi].size(); n       for (unsigned long long k = 0; k < sizez; ++k) { n         unsigned long long sun = to[zi][k]; n         if (vis[sun]) sum -= (1ull * A * fu + 1ull * B * zi + 1ull * C * sun); n       } n     } n     for (unsigned long long j = 0; j < size; ++j) vis[to[fu][j]] = 0; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[300005], key[300005]; n struct node { n   int cnt; n   struct node *zero, *one; n   node() { n     cnt = 0; n     zero = NULL, one = NULL; n   } n } * root; n void Insert(int pat) { n   struct node *curr = root; n   int on = 1; n   for (int i = 30; i >= 0; i--) { n     int bit = (pat & (on << i)); n     if (bit) { n       if (curr->one == NULL) curr->one = new node(); n       curr = curr->one; n       curr->cnt++; n     } else { n       if (curr->zero == NULL) curr->zero = new node(); n       curr = curr->zero; n       curr->cnt++; n     } n   } n } n void Search(int val) { n   struct node *curr = root; n   int on = 1; n   long long int ans = 0; n   for (int i = 30; i >= 0; i--) { n     int bit = (val & (on << i)); n     if (bit) { n       if (curr->one != NULL && curr->one->cnt > 0) { n         curr = curr->one; n         curr->cnt--; n       } else if (curr->zero != NULL && curr->zero->cnt > 0) { n         curr = curr->zero; n         curr->cnt--; n         ans += (on << i); n       } n     } else { n       if (curr->zero != NULL && curr->zero->cnt > 0) { n         curr = curr->zero; n         curr->cnt--; n       } else if (curr->one != NULL && curr->one->cnt > 0) { n         curr = curr->one; n         curr->cnt--; n         ans += (on << i); n       } n     } n   } n   cout << ans <<    ; n } n int main() { n   int n; n   cin >> n; n   root = new node(); n   for (int i = 1; i <= n; i++) cin >> arr[i]; n   for (int i = 1; i <= n; i++) { n     cin >> key[i]; n     Insert(key[i]); n   } n   for (int i = 1; i <= n; i++) { n     Search(arr[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int i, j, k, l, p, q, m = 1, a = 0, b = 0, c = 0; n   char s[50001]; n   scanf( %s , s); n   l = strlen(s); n   i = 0; n   if (s[i] ==  a  && l > 1) { n     for (j = i + 1; j < l; j++) { n       if (s[j] !=  a ) { n         if (s[j] ==  b ) { n           for (p = j + 1; p < l; p++) { n             if (s[p] !=  b ) { n               if (s[p] ==  c ) { n                 for (q = p + 1; q < l; q++) { n                   if (s[q] !=  c ) { n                     m = 0; n                     break; n                   } n                 } n               } else { n                 m = 0; n                 break; n               } n             } else { n               if (p == l - 1) { n                 m = 0; n                 break; n               } n             } n           } n         } else { n           m = 0; n         } n         break; n       } else { n         if (j == l - 1) { n           m = 0; n           break; n         } n       } n     } n   } else { n     m = 0; n   } n   for (k = 0; s[k] !=   0 ; k++) { n     if (s[k] ==  a ) n       a++; n     else if (s[k] ==  b ) n       b++; n     else n       c++; n   } n   if (m == 1 && (a == c || b == c)) { n     printf( YES ); n   } else { n     printf( NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int F[30030]; n int n; n int mod; n int a[30030], id[30030]; n int nxt[30030]; n bool cmp(int i, int j) { return a[i] < a[j]; } n int m; n struct pnt { n   int l, r, i; n   pnt(int l = 0, int r = 0, int i = 0) : l(l), r(r), i(i){}; n } q[30030]; n bool operator<(pnt a, pnt b) { return b.l != a.l ? a.l < b.l : a.r < b.r; } n int answer[30030]; n int calc(int l, int r) { n   int s = 0, m = 0; n   for (int j, i = 1; i <= n; i++) { n     j = id[i]; n     if (j >= l && j <= r) { n       s = (s + F[++m] * a[j]) % mod; n       i = nxt[i]; n     } n   } n   return s; n } n int main() { n   scanf( %d %d , &n, &mod); n   F[1] = F[2] = 1 % mod; n   for (int i = 3; i <= n; i++) { n     F[i] = (F[i - 1] + F[i - 2]) % mod; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     id[i] = i; n   } n   sort(id + 1, id + n + 1, cmp); n   nxt[n] = n; n   for (int j = n - 1; j >= 1; j--) { n     if (a[id[j]] == a[id[j + 1]]) { n       nxt[j] = nxt[j + 1]; n     } else { n       nxt[j] = j; n     } n   } n   for (int j = 1; j <= n; j++) { n     a[j] %= mod; n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &q[i].l, &q[i].r); n     q[i].i = i; n   } n   sort(q + 1, q + m + 1); n   for (int i = 1; i <= m; i++) { n     if (i > 1 && q[i].l == q[i - 1].l && q[i].r == q[i - 1].r) { n       answer[q[i].i] = answer[q[i - 1].i]; n     } else { n       answer[q[i].i] = calc(q[i].l, q[i].r); n     } n   } n   for (int i = 1; i <= m; i++) { n     printf( %d n , answer[i]); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n #define ll          long long n #define int         ll n #define ld          long double n #define ff          first n #define ss          second n #define io          ios_base::sync_with_stdio(false); cin.tie(NULL); n #define yes         cout<< YES  n #define no          cout<< NO  n #define loop(i,a,n) for(int i=a;i<n;i++) n #define rloop(i,n,a)for(int i=n-1;i>=a;i--) n #define test        int tt=1; cin>>tt; while(tt--) n #define pb          push_back n #define pi          3.141592653589793238 n #define all(v)      v.begin(),v.end() n #define vecl        vector<int> n #define pii         pair<int,int> n #define vpii        vector<pii> n const int MOD = 1e9 + 7; n int fast_expo(int x, int p) { n     if (p == 0) return 1; n     else if (p % 2 == 0) { int t = fast_expo(x, p / 2) % MOD; return (t * t) % MOD;} n     else return (x * (fast_expo(x, p - 1)) % MOD) % MOD; n } n int gcd(int a, int b) { n     if (a == 0 || b == 0) return a + b; n     else return gcd(b % a, a); n } n  n int lcm(int a, int b) n { n     return (a * b) / gcd(a, b); n } n vecl v; n void primeFactors(int n) n { n     // Print the number of 2s that divide n n     while (n % 2 == 0) n     { n         v.pb(2); n         n = n / 2; n     } n  n     // n must be odd at this point. So we can skip n     // one element (Note i = i +2) n     for (int i = 3; i <= sqrt(n); i = i + 2) n     { n         // While i divides n, print i and divide n n         while (n % i == 0) n         { n             v.pb(i); n             n = n / i; n         } n     } n  n     // This condition is to handle the case when n n     // is a prime number greater than 2 n     if (n > 2) n         v.pb(n); n } n //int t[101][101]; n void calc(vecl &a, int l, int r, vecl &b, int d) n { n     if (l >= r) n         return; n  n     int mx = 0, ans = 0; n     loop(i, l, r) n     { n         mx = max(mx, a[i]); n     } n     loop(i, l, r) n     { n         if (mx == a[i]) n         { n             ans = i; break; n         } n     } n     b[ans] = d; n     calc(a, ans + 1, r, b, d + 1); n     calc(a, l, ans, b, d + 1); n } n  n void solve() n { n     int n; n     cin >> n; n     vecl a(n); n     loop(i, 0, n) n     { n         cin >> a[i]; n     } n     //memset(t,-1, sizeof t); n     int l = 0, r = n; n     vecl ans(n + 1, 0); n     int d = 0; n     calc(a, l, r, ans, d); n     loop(i, 0, n) n     cout << ans[i] <<    ; n } n  n signed main() { n  n     io n #ifndef ONLINE_JUDGE n     freopen( inputf.in ,  r , stdin); n     freopen( outputf.out ,  w , stdout); n #endif n     //calc(); n     test n     { n         solve(); n         cout << endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n unsigned long long min(unsigned long long x, unsigned long long y) { n   if (x < y) return x; n   return y; n } n unsigned long long max(unsigned long long x, unsigned long long y) { n   if (x < y) return y; n   return x; n } n long long min(long long x, long long y) { n   if (x < y) return x; n   return y; n } n long long max(long long x, long long y) { n   if (x < y) return y; n   return x; n } n double min(double x, double y) { n   if (x < y) return x; n   return y; n } n double max(double x, double y) { n   if (x < y) return y; n   return x; n } n unsigned long long gcd(unsigned long long x, unsigned long long y) { n   if (!x) return y; n   if (!y) return x; n   if (x > y) swap(x, y); n   return gcd(x, y % x); n } n unsigned long long inv(unsigned long long a, unsigned long long c) { n   if (a == 1) { n     return 1; n   } n   return ((c - (c / a)) * inv(c % a, c)) % c; n } n int n, l[300005] = {0}, r[300005] = {0}, idx[300005] = {0}; n int comp(int a, int b) { n   if (l[a] == l[b]) return r[a] > r[b]; n   return l[a] < l[b]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> l[i] >> r[i]; n     idx[i] = i; n   } n   sort(idx, idx + n, comp); n   int minr = r[idx[n - 1]], j = n - 1; n   for (int i = n - 2; i >= 0; --i) { n     if (minr <= r[idx[i]]) { n       cout << (idx[j] + 1) <<     << (idx[i] + 1) <<   n ; n       return 0; n     } n     if (r[idx[i]] < minr) { n       j = i; n       minr = r[idx[i]]; n     } n   } n   cout <<  -1 -1 n ; n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 200000; n using namespace std; n int a[maxn], b[maxn]; n int l[maxn], r[maxn]; n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   a[0] = 0; n   for (int i = 1; i <= n; i++) n     scanf( %d , &a[i]), b[i - 1] = abs(a[i] - a[i - 1]); n   for (int i = 1; i <= q; i++) { n     int x, y; n     long long ans = 0; n     scanf( %d%d , &x, &y); n     y--; n     l[x] = x - 1; n     r[y] = y + 1; n     for (int j = x + 1; j <= y; j++) { n       l[j] = j - 1; n       while (l[j] >= x && b[l[j]] < b[j]) l[j] = l[l[j]]; n     } n     for (int j = y - 1; j >= x; j--) { n       r[j] = j + 1; n       while (r[j] <= y && b[r[j]] <= b[j]) r[j] = r[r[j]]; n     } n     for (int j = x; j <= y; j++) n       ans += (long long)(l[j] - j) * (j - r[j]) * b[j]; n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     vector<long long> a(n); n     long long mn = 1e5; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] < mn) { n         mn = a[i]; n       } n     } n     long long ans = 0; n     bool is_mn = false; n     for (int i = 0; i < n; i++) { n       if (a[i] == mn && not is_mn) { n         is_mn = true; n         continue; n       } n       while (a[i] + mn <= k) { n         a[i] += mn; n         ans++; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const string roman[] = { M ,   CM ,  D ,   CD ,  C ,   XC ,  L , n                          XL ,  X ,   IX ,  V ,   IV ,  I }; n const int roman_num[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; n int a; n string b, c; n string ans; n long long toint(string s, int base) { n   long long res = 0, add; n   for (int i = 0; i < s.size(); i++) { n     res = res * base; n     if (isdigit(s[i])) n       add = s[i] -  0 ; n     else n       add = s[i] -  A  + 10; n     res += add; n   } n   return res; n } n string roman_convert(int num) { n   int pos = 0; n   string res =   ; n   while (num > 0) { n     while (roman_num[pos] <= num) { n       num -= roman_num[pos]; n       res += roman[pos]; n     } n     pos++; n   } n   return res; n } n string convert(string c, int from, int to) { n   long long base_10 = 0LL; n   string temp = c; n   for (int i = 0; i < temp.size(); i++) { n     int add; n     if (isdigit(temp[i])) n       add = temp[i] -  0 ; n     else n       add = temp[i] -  A  + 10; n     base_10 = base_10 * from + add; n   } n   string res =   ; n   while (base_10) { n     int digit = base_10 % to; n     if (digit >= 10) n       res.push_back( A  + digit - 10); n     else n       res.push_back(digit +  0 ); n     base_10 /= to; n   } n   if (res.empty()) return  0 ; n   reverse(res.begin(), res.end()); n   while (res.at(0) ==  0  && res.size() > 11) res.erase(0, 1); n   return res; n } n int main() { n   cin.sync_with_stdio(0); n   cin >> a >> b >> c; n   while (c[0] ==  0  && c.size() > 1) c.erase(0, 1); n   if (b ==  R ) { n     int temp = toint(c, a); n     ans = roman_convert(temp); n   } else { n     int base = toint(b, 10); n     ans = convert(c, a, base); n   } n   puts(ans.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main(void) { n   int n, x, k; n   scanf( %d %d %d , &n, &x, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n   } n   sort(a, a + n); n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     long long p = (long long)ceil(a[i] * 1.0 / x) * x; n     sum += n         lower_bound(a, a + n, p + (long long)k * x) - n         lower_bound(a, a + n, max((long long)a[i], p + (long long)(k - 1) * x)); n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int min_answer; n long long int max_answer = -1; n void test_this_order(long long int a, long long int b, long long int c) { n   long long int new_n = (a + 1) * (b + 2) * (c + 2) - a * b * c; n   min_answer = std::min(min_answer, new_n); n   max_answer = std::max(max_answer, new_n); n } n void test(long long int a, long long int b, long long int c) { n   test_this_order(a, b, c); n   test_this_order(b, a, c); n   test_this_order(c, b, a); n } n int main() { n   long long int n; n   cin >> n; n   test(n, 1, 1); n   min_answer = max_answer; n   for (long long int i = 1; i * i <= n; ++i) { n     if (n % i == 0) { n       long long new_n = n / i; n       for (long long int j = 1; j * j <= new_n; ++j) { n         if (new_n % j == 0) { n           test(i, j, new_n / j); n         } n       } n     } n   } n   cout << min_answer <<     << max_answer << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const int level = 20; n vector<int> adj[N]; n bool checked[N]; n int parent[N]; n int sz[N]; n int centroid; n int sparse[N][level]; n int depth[N]; n void subtree(int cur, int prev) { n   sz[cur] = 1; n   for (auto &child : adj[cur]) { n     if (child != prev and !checked[child]) { n       subtree(child, cur); n       sz[cur] += sz[child]; n     } n   } n } n void decompose(int cur, int prev, int total_size) { n   for (auto &child : adj[cur]) { n     if (child != prev and !checked[child]) { n       decompose(child, cur, total_size); n     } n   } n   if (centroid != -1) { n     return; n   } n   if (2 * sz[cur] >= total_size) { n     centroid = cur; n     return; n   } n } n int get_centroid(int cur) { n   subtree(cur, 0); n   centroid = -1; n   decompose(cur, 0, sz[cur]); n   return centroid; n } n void dfs(int cur, int prev) { n   int root = get_centroid(cur); n   parent[root] = prev; n   checked[root] = true; n   for (auto &child : adj[root]) { n     if (!checked[child]) { n       dfs(child, root); n     } n   } n } n void dfs_sparse(int cur, int prev) { n   sparse[cur][0] = prev; n   for (auto &child : adj[cur]) { n     if (child != prev) { n       depth[child] = depth[cur] + 1; n       dfs_sparse(child, cur); n     } n   } n } n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n - 1; i++) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1, 0); n   dfs_sparse(1, -1); n   for (int l = 1; l < level; l++) { n     for (int node = 1; node <= n; node++) { n       if (sparse[node][l - 1] != -1) { n         sparse[node][l] = sparse[sparse[node][l - 1]][l - 1]; n       } n     } n   } n   auto lca = [&](int u, int v) -> int { n     if (depth[v] < depth[u]) { n       swap(u, v); n     } n     int diff = depth[v] - depth[u]; n     for (int i = 0; i < level; i++) { n       if ((diff >> i) & 1) { n         v = sparse[v][i]; n       } n     } n     if (u == v) { n       return u; n     } n     for (int i = level - 1; i >= 0; i--) { n       if (sparse[u][i] != sparse[v][i]) { n         u = sparse[u][i]; n         v = sparse[v][i]; n       } n     } n     return sparse[u][0]; n   }; n   auto get_dist = [&](int x, int y) { n     int lc = lca(x, y); n     return depth[x] + depth[y] - 2 * depth[lc]; n   }; n   vector<int> dist(n + 1, n); n   int node = 1; n   for (int i = node; i; i = parent[i]) { n     dist[i] = get_dist(i, node); n   } n   for (int i = 1; i <= m; i++) { n     int type, node; n     cin >> type >> node; n     if (type == 1) { n       for (int i = node; i; i = parent[i]) { n         dist[i] = min(dist[i], get_dist(i, node)); n       } n     } else { n       int ans = n; n       for (int i = node; i; i = parent[i]) { n         ans = min(ans, get_dist(i, node) + dist[i]); n       } n       cout << (dist[node] = ans) <<   n ; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 2000 + 1; n const int M = 1e9 + 7; n vector<pair<int, int>> adj[MX]; n int dp[MX][MX]; n int add(int a, int b) { return (a += b) < M ? a : a - M; } n int mul(int a, int b) { return 1LL * a * b % M; } n int floor_div(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); } n int intersect(pair<int, int> p, pair<int, int> q) { n   return floor_div(p.second - q.second, q.first - p.first); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, q; n   cin >> n >> m >> q; n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     adj[u].emplace_back(v, w); n     adj[v].emplace_back(u, w); n   } n   memset(dp, -1, sizeof dp); n   dp[0][1] = 0; n   for (int i = 0; i < m; ++i) { n     for (int j = 1; j <= n; ++j) { n       if (dp[i][j] != -1) { n         for (auto [v, w] : adj[j]) { n           dp[i + 1][v] = max(dp[i + 1][v], dp[i][j] + w); n         } n       } n     } n   } n   vector<pair<int, int>> lns; n   for (int i = 1; i <= n; ++i) { n     if (dp[m][i] == -1) continue; n     int mx = 0; n     for (auto [_, w] : adj[i]) { n       mx = max(mx, w); n     } n     lns.emplace_back(mx, dp[m][i]); n   } n   sort(lns.begin(), lns.end()); n   vector<pair<int, int>> hull; n   for (auto i : lns) { n     if (!hull.empty() && hull.back().first == i.first) { n       hull.pop_back(); n     } n     while (hull.size() >= 2u && n            intersect(i, hull.back()) <= intersect(i, hull[hull.size() - 2u])) { n       hull.pop_back(); n     } n     hull.push_back(i); n   } n   int ans = 0; n   for (int i = 1; i <= m; ++i) { n     ans = add(ans, *max_element(dp[i], dp[i] + n + 1) % M); n   } n   int left = 1; n   for (int i = 0; i < int(hull.size()); ++i) { n     int right = q - m; n     if (i + 1 < int(hull.size())) { n       right = min(right, intersect(hull[i], hull[i + 1])); n     } n     if (right < left) continue; n     int len = right - left + 1; n     ans = add(ans, mul(hull[i].second % M, len)); n     ans = add(ans, mul(hull[i].first % M, n                        mul(mul(len, add(right, left)), (M + 1) / 2))); n     left = right + 1; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { n   uniform_int_distribution<int64_t> generator(l, r); n   return generator(rng); n } n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n const long long inf = 1e18; n const int32_t M = 1e9 + 7; n const int32_t MM = 998244353; n bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } n long long binpow(long long a, long long b, long long m) { n   a %= m; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n const int N = 2e6 + 1; n void solve() { n   long long a, b; n   cin >> a >> b; n   long long target = a * b; n   long long l = 0; n   long long r = 1e6, mid, d; n   bool k = false; n   while (l <= r) { n     mid = l + (r - l) / 2; n     d = mid * mid * mid; n     if (d == target) { n       k = true; n       break; n     } n     if (d < target) { n       l = mid + 1; n     } else { n       r = mid - 1; n     } n   } n   if (k == true && a % mid == 0 && b % mid == 0) { n     cout <<  Yes  n          <<   n ; n   } else { n     cout <<  No  n          <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n long long read() { n   long long s = 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     s = s * 10 + ch -  0 ; n     ch = getchar(); n   } n   return s * f; n } n inline void print(long long *f, long long len) { n   for (long long i = 0; i < len; i++) printf( %lld  , f[i]); n   puts(  ); n } n long long a[101010]; n long long pw[101010]; n long long cnt[101010]; n long long dp[101010]; n const long long mod = 1e9 + 7; n signed main() { n   n = read(); n   pw[0] = 1; n   for (long long i = 1, iend = n; i <= iend; ++i) n     a[i] = read(), pw[i] = (pw[i - 1] * 2) % mod, cnt[a[i]]++; n   for (long long i = 100000, iend = 1; i >= iend; --i) { n     long long sum = 0; n     for (long long j = i; j <= 100000; j += i) sum += cnt[j]; n     dp[i] = pw[sum] - 1; n     for (long long j = i * 2; j <= 100000; j += i) n       dp[i] += mod, dp[i] -= dp[j], dp[i] %= mod; n   } n   cout << dp[1]; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const long long inf = 1e18; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, b; n   cin >> n >> b; n   long long i = 2; n   long long ans = inf; n   while (i <= b) { n     if (i * i > b) i = b; n     long long cnt = 0; n     while (b % i == 0) { n       b /= i; n       cnt++; n     } n     if (cnt == 0) { n       i++; n       continue; n     } n     long long tmp = 0; n     long long j = 1; n     while (j <= n / i) { n       j *= i; n       tmp += n / j; n     } n     ans = min(ans, tmp / cnt); n     i++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ss = 1000; n int n, k, ans, x; n bool flag1, flag2; n bool a[5000][5000]; n int b[1002], tot; n int main() { n   scanf( %d%d , &n, &k); n   memset(a, false, sizeof(a)); n   memset(b, false, sizeof(b)); n   flag1 = flag2 = false; n   n += ss; n   for (int i = 1; i <= k; ++i) { n     scanf( %d , &x); n     a[0][x + ss] = true; n     if (x + ss > n) flag1 = true; n     if (x + ss < n) flag2 = true; n   } n   tot = 0; n   for (int i = 0; i <= 1000 + ss; ++i) { n     if (a[0][i]) b[++tot] = i; n   } n   if (a[0][n]) n     ans = 1; n   else if (flag1 ^ flag2 || (k == 1)) n     ans = -1; n   else n     for (int i = 1; i <= 5010; ++i) { n       for (int j = 0; j <= 3000; ++j) n         if (a[i - 1][j]) { n           for (int k = 1; k <= tot; ++k) { n             if (j + b[k] - n >= 0 && j + b[k] - n <= 3000) { n               a[i][j + b[k] - n] = true; n             } n           } n         } n       if (a[i][n]) { n         ans = i + 1; n         break; n       } n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int q; n   cin >> q; n   while (q--) { n     long long n, a, b; n     cin >> n >> a >> b; n     if (n == 1) { n       cout << a << endl; n       continue; n     } n     if (n % 2 == 0) { n       long long gu = min(n * a, (n / 2) * b); n       cout << gu << endl; n     } else { n       long long gu = min(n * a, (n / 2) * b + a); n       cout << gu << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   double i = n / 3.0; n   int in = i; n   if (i - in > 0.6) in += 1; n   int f = in / 12; n   cout << f <<     << in - f * 12 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int pwr(int a, long long b) { n   int res = 1; n   for (; b; b >>= 1) { n     if (b & 1) res = 1LL * res * a % MOD; n     a = 1LL * a * a % MOD; n   } n   return res; n } n int T, n; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   T = 1; n   while (T--) { n     cin >> n; n     if (n == 1) return cout << 6 <<   n , 0; n     long long x = (1LL << n); n     x -= 2; n     cout << 1LL * 6 * pwr(4, x) % MOD <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long t = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) t = t * 10 + c - 48, c = getchar(); n   return t * f; n } n char s[10000001]; n long long len, hsh[2000001][11], bas = 10; n long long mo[4] = {1000000007, 1000000009, 998244353, 1000000037}; n inline long long ksm1(long long x, long long y, long long m) { n   long long sum = 1; n   for (; y; y /= 2) { n     if (y & 1) sum = sum * x % m; n     x = x * x % m; n   } n   return sum; n } n inline long long ksm(long long x, long long y) { n   long long sum = 1; n   for (; y; y /= 2) { n     if (y & 1) sum = sum * x; n     x = x * x; n   } n   return sum; n } n inline long long get(int l, int r, int k) { n   long long t = 0, ret = 0; n   if (k == 10) n     t = ksm(bas, r - l + 1), ret = hsh[r][10] - t * hsh[l - 1][10]; n   else n     t = ksm1(bas, r - l + 1, mo[k]), n     ret = ((hsh[r][k] - t * hsh[l - 1][k]) % mo[k] + mo[k]) % mo[k]; n   return ret; n } n int a1[2000001], a2[2000001], a3[2000001], a4[2000001], len1, len2, len3; n bool flag = 0; n inline void solve(int x) { n   int rest = len - x; n   for (long long l = rest / 2; l <= rest / 2 + 1; ++l) { n     if ((get(1, x, 10) + get(x + 1, len - l, 10)) == n         get(len - l + 1, len, 10)) { n       flag = 1; n       for (long long i = 0; i <= 3; ++i) n         if (((get(1, x, i) + get(x + 1, len - l, i)) % mo[i] + mo[i]) % mo[i] != n             get(len - l + 1, len, i)) { n           flag = 0; n           break; n         } n       if (!flag) continue; n       if (s[1] ==  0  && x != 1) continue; n       if (s[x + 1] ==  0  && len - l != x + 1) continue; n       if (s[len - l + 1] ==  0  && len != len - l + 1) continue; n       for (long long i = 1; i <= x; ++i) putchar(s[i]); n       putchar( + ); n       for (long long i = x + 1; i <= len - l; ++i) putchar(s[i]); n       putchar( = ); n       for (long long i = len - l + 1; i <= len; ++i) putchar(s[i]); n       exit(0); n     } n   } n   for (long long l = x; l <= x + 1; ++l) { n     if ((get(1, x, 10) + get(x + 1, len - l, 10)) == n         get(len - l + 1, len, 10)) { n       flag = 1; n       for (long long i = 0; i <= 3; ++i) n         if (((get(1, x, i) + get(x + 1, len - l, i)) % mo[i] + mo[i]) % mo[i] != n             get(len - l + 1, len, i)) { n           flag = 0; n           break; n         } n       if (!flag) continue; n       if (s[1] ==  0  && x != 1) continue; n       if (s[x + 1] ==  0  && len - l != x + 1) continue; n       if (s[len - l + 1] ==  0  && len != len - l + 1) continue; n       for (long long i = 1; i <= x; ++i) putchar(s[i]); n       putchar( + ); n       for (long long i = x + 1; i <= len - l; ++i) putchar(s[i]); n       putchar( = ); n       for (long long i = len - l + 1; i <= len; ++i) putchar(s[i]); n       exit(0); n     } n   } n } n int main() { n   scanf( %s , s + 1); n   len = strlen(s + 1); n   hsh[0][4] = 0; n   for (long long i = 1; i <= len; ++i) n     hsh[i][10] = hsh[i - 1][10] * bas + s[i] - 48; n   for (long long i = 1; i <= len; ++i) n     for (long long j = 0; j <= 3; ++j) n       hsh[i][j] = (hsh[i - 1][j] * bas + s[i] - 48) % mo[j]; n   for (long long i = 1; i <= len / 2 + 1; ++i) solve(i); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, c; n   int n, t = 0; n   cin >> n; n   cin >> s >> c; n   for (int i = 0; i < n; i++) { n     int p = s[i], k = c[i]; n     if (p <= k) n       t += min(abs(p - k), (p + 1) + (9 - k)); n     else n       t += min((9 - p) + (k + 1), abs(p - k)); n   } n   cout << t << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_BUF_SIZE = 16384; n char BUFOR[MAX_BUF_SIZE]; n int BUF_SIZE, BUF_POS; n char ZZZ; n const int MXN = 100010; n const int C = 262144; n const int INF = 1000000001; n string a[MXN]; n int aa; n int typ[MXN], gender[MXN]; n string fem[3] = { liala ,  etra ,  inites }; n string masc[3] = { lios ,  etr ,  initis }; n string mowa[6] = { lios ,  etr ,  initis ,  liala ,  etra ,  inites }; n int n; n void test() { n   string tmp; n   while (cin >> tmp) a[aa++] = tmp; n   n = aa; n   bool czy = 1; n   for (int i = 0; i < aa; i++) { n     int dec = -1; n     gender[i] = -1; n     for (int j = 0; j < 3; j++) { n       string w = masc[j]; n       if (w.length() <= a[i].length() && n           w == string(a[i], (int)(a[i]).size() - (int)(w).size(), n                       (int)(w).size())) n         dec = 1; n       gender[i] = dec; n     } n     dec = -1; n     for (int j = 0; j < 3; j++) { n       string w = fem[j]; n       if (w.length() <= a[i].length() && n           w == string(a[i], (int)(a[i]).size() - (int)(w).size(), n                       (int)(w).size())) n         dec = 0; n       if (gender[i] == -1) gender[i] = dec; n     } n     for (int j = 0; j < 6; j++) { n       string w = mowa[j]; n       typ[i] = -1; n       if (w.length() <= a[i].length() && n           w == string(a[i], (int)(a[i]).size() - (int)(w).size(), n                       (int)(w).size())) { n         typ[i] = j % 3; n         break; n       } n     } n     if (gender[i] == -1 || typ[i] == -1) czy = 0; n   } n   int iter = 0; n   while (iter < n && typ[iter] == 0) iter++; n   if (typ[iter] == 1) n     iter++; n   else if (n > 1) n     czy = 0; n   while (czy && iter < n) n     if (typ[iter++] != 2) czy = 0; n   for (int i = 1; i < n; i++) n     if (gender[0] != gender[i]) czy = 0; n   if (czy) n     printf( YES n ); n   else n     printf( NO n ); n } n int main() { n   int te = 1; n   while (te--) test(); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 1e5; n class union_find { n   int n, no_of_comp; n   vector<int> par, sz; n  n  public: n   union_find(int nv) { n     n = no_of_comp = nv; n     par = sz = vector<int>(n + 1, 1); n     for (int i = 1; i <= n; i++) par[i] = i; n   } n   int get_root(int i) { n     while (i != par[i]) i = par[i]; n     return i; n   } n   void take_union(int i, int j) { n     int u = get_root(i); n     int v = get_root(j); n     if (u == v) return; n     if (sz[u] < sz[v]) swap(u, v); n     par[v] = u; n     sz[u] += sz[v]; n     no_of_comp--; n   } n   int num_of_comp() { return no_of_comp; } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   union_find dsu(n); n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     dsu.take_union(u, v); n   } n   cout << (long long)pow(2, n - dsu.num_of_comp()); n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   int s = 0; n   s = n * (n + 1) / 2; n   if (s % 2 == 0) { n     printf( 0 ); n   } else { n     printf( 1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> com; n vector<long long> all; n long long c, a, n, k, mm; n void solve() { n   long long s = 0, e = (long long)1e9 * 2 + 5; n   long long mid = 0; n   long long sum = 0; n   while (s <= e) { n     mid = (s + e) / 2; n     for (int i = 0; i < n; i++) { n       sum += max((long long)0, (com[i] * mid - all[i])); n       if (sum > (long long)1e18) { n         sum = k + 1; n         break; n       } n     } n     if (sum <= k) { n       mm = mid; n       s = mid + 1; n     } else n       e = mid - 1; n     sum = 0; n   } n   cout << mm; n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> c; n     com.push_back(c); n   } n   for (int i = 0; i < n; i++) { n     cin >> a; n     all.push_back(a); n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline bool equal(double _x, double _y) { n   return _x > _y - 1e-9 && _x < _y + 1e-9; n } n int l[105], r[105], t[105], c[105], ans, mx, id; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) scanf( %d%d%d%d , &l[i], &r[i], &t[i], &c[i]); n   for (int j = 1; j <= n; j++) { n     mx = 1e9; n     id = -1; n     for (int i = 0; i < m; i++) { n       if (l[i] <= j && j <= r[i] && t[i] < mx) { n         mx = t[i]; n         id = i; n       } n     } n     if (~id) ans += c[id]; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1, typename Arg2> n ostream& operator<<(ostream& out, const pair<Arg1, Arg2>& x) { n   return out <<  (  << x.first <<  ,  << x.second <<  ) ; n } n template <typename Arg1> n ostream& operator<<(ostream& out, const vector<Arg1>& a) { n   out <<  [ ; n   for (const auto& x : a) out << x <<  , ; n   return out <<  ] ; n } n template <typename Arg1> n ostream& operator<<(ostream& out, const set<Arg1>& a) { n   out <<  [ ; n   for (const auto& x : a) out << x <<  , ; n   return out <<  ] ; n } n template <typename Arg1, typename Arg2> n ostream& operator<<(ostream& out, const map<Arg1, Arg2>& a) { n   out <<  [ ; n   for (const auto& x : a) out << x <<  , ; n   return out <<  ] ; n } n template <typename Arg1> n void __trace__(const string name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 <<   ]   << endl; n } n template <typename Arg1, typename... Args> n void __trace__(const string names, Arg1&& arg1, Args&&... args) { n   const string name = names.substr(0, names.find( , )); n   cerr << name <<   :   << arg1 <<   |  ; n   __trace__(names.substr(1 + (int)name.size()), args...); n } n clock_t time_p = clock(); n void time_taken() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n const long long mod = 1e9 + 7; n const long long INF = 1e18; n const int maxn = 2e5 + 5; n vector<int> adj[maxn]; n int Q[maxn]; n int n; n void bfs(int s, int* d) { n   for (int i = 1; i <= n; i++) { n     d[i] = -1; n   } n   d[s] = 0; n   int N = 0; n   Q[N++] = s; n   for (int i = 0; i < N; i++) { n     int u = Q[i]; n     for (int v : adj[u]) { n       if (d[v] == -1) { n         d[v] = d[u] + 1; n         Q[N++] = v; n       } n     } n   } n } n void solve() { n   int m, a, b, c; n   cin >> n >> m >> a >> b >> c; n   for (int i = 1; i <= n; i++) { n     adj[i].clear(); n   } n   vector<long long> p(m); n   for (int i = 0; i < m; i++) cin >> p[i]; n   sort(p.begin(), p.end()); n   for (int i = 1; i <= m - 1; i++) p[i] += p[i - 1]; n   for (int _ = 0; _ < m; _++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   int da[n + 1], db[n + 1], dc[n + 1]; n   bfs(a, da); n   bfs(b, db); n   bfs(c, dc); n   if (a == b) { n     int foo = dc[a]; n     if (foo) { n       cout << p[foo - 1] <<   n ; n     } else { n       cout << 0 <<   n ; n     } n     return; n   } n   if (b == c) { n     int foo = da[b]; n     if (foo) { n       cout << p[foo - 1] <<   n ; n     } else { n       cout << 0 <<   n ; n     } n     return; n   } n   if (c == a) { n     int foo = da[b]; n     if (foo) { n       cout << 2 * p[foo - 1] <<   n ; n     } else { n       cout << 0 <<   n ; n     } n     return; n   } n   long long ans = INF; n   for (int i = 1; i <= n; i++) { n     long long cur = 0; n     int cnt = 0; n     long long foo = 0; n     if (db[i]) { n       foo = p[db[i] - 1]; n       cur += 2 * p[db[i] - 1]; n     } n     int tot = da[i] + db[i] + dc[i] - 1; n     if (tot < m) n       cur += p[tot] - foo; n     else n       continue; n     ans = min(ans, cur); n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout.precision(12); n   cout << fixed; n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   time_taken(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const int mod = (int)1e+9 + 7; n const double pi = acos(-1.); n const int maxn = 100100; n int x[maxn]; n int z[10 * maxn]; n int a, b; n void fill(int u) { n   int lpos = (u - b % u) % u; n   for (; lpos <= a - b; lpos += u) { n     z[lpos] = max(z[lpos], lpos + u - 1); n   } n } n int main() { n   srand(time(0)); n   const string file =   ; n   if (!file.empty()) { n     freopen((file +  .in ).c_str(),  r , stdin); n     freopen((file +  .out ).c_str(),  w , stdout); n   } n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x[i]); n   } n   scanf( %d%d , &a, &b); n   sort(&x[0], &x[n]); n   n = unique(&x[0], &x[n]) - &x[0]; n   for (int i = 0; i < 10 * maxn; i++) { n     z[i] = i + 1; n   } n   for (int i = 0; i < n; i++) { n     fill(x[i]); n   } n   for (int i = 1; i <= a - b; i++) { n     z[i] = max(z[i], z[i - 1]); n   } n   int cnt = 0; n   for (int i = 0; i < a - b;) { n     i = z[i]; n     cnt++; n   } n   cout << cnt; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const int MOD = 1000000007; n const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; n const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; n int n, m; n char grid[65][65]; n bool row(int row, char c) { n   for (int i = 0; i < m; i++) n     if (grid[row][i] != c) return false; n   return true; n } n bool col(int col, char c) { n   for (int i = 0; i < n; i++) n     if (grid[i][col] != c) return false; n   return true; n } n void solve() { n   cin >> n >> m; n   int a = 0, b = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> grid[i][j]; n       if (grid[i][j] ==  A ) n         ++a; n       else n         ++b; n     } n   if (a == 0) { n     cout <<  MORTAL  n          <<   n ; n     return; n   } n   if (b == 0) { n     cout << 0 <<   n ; n     return; n   } n   if (row(0,  A ) || row(n - 1,  A ) || col(0,  A ) || col(m - 1,  A )) { n     cout << 1 <<   n ; n     return; n   } n   for (int i = 0; i < n; i++) n     if (row(i,  A )) { n       cout << 2 <<   n ; n       return; n     } n   for (int i = 0; i < m; i++) n     if (col(i,  A )) { n       cout << 2 <<   n ; n       return; n     } n   if (grid[0][0] ==  A  || grid[n - 1][0] ==  A  || grid[0][m - 1] ==  A  || n       grid[n - 1][m - 1] ==  A ) { n     cout << 2 <<   n ; n     return; n   } n   for (int i = 0; i < n; i++) { n     if (grid[i][0] ==  A  || grid[i][m - 1] ==  A ) { n       cout << 3 <<   n ; n       return; n     } n   } n   for (int j = 0; j < m; j++) { n     if (grid[0][j] ==  A  || grid[n - 1][j] ==  A ) { n       cout << 3 <<   n ; n       return; n     } n   } n   cout << 4 <<   n ; n } n signed main() { n   cin.tie(0), cout.tie(0); n   ios::sync_with_stdio(0); n   int q; n   cin >> q; n   while (q--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   string s, t; n   cin >> s >> t; n   int n = s.size(), m = t.size(); n   vector<vector<int> > f(n + 1); n   vector<vector<int> > what(n + 1); n   vector<vector<pair<int, int> > > from(n + 1); n   for (int i = 0; i < int((f).size()); i++) n     f[i].resize(m + 1), what[i].resize(m + 1), from[i].resize(m + 1); n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= m; ++j) { n       if (i == 0 && j == 0) continue; n       int a, b, c, d; n       a = b = c = d = 1000000000; n       if (i - 1 >= 0 && j - 1 >= 0 && s[i - 1] == t[j - 1]) a = f[i - 1][j - 1]; n       if (i - 1 >= 0) b = f[i - 1][j] + 1; n       if (j - 1 >= 0) c = f[i][j - 1] + 1; n       if (i - 1 >= 0 && j - 1 >= 0) d = f[i - 1][j - 1] + 1; n       int mn = min(min(a, b), min(c, d)); n       if (mn == b) n         what[i][j] = 1, from[i][j] = make_pair(i - 1, j); n       else if (mn == c) n         what[i][j] = 2, from[i][j] = make_pair(i, j - 1); n       else if (mn == d) n         what[i][j] = 3, from[i][j] = make_pair(i - 1, j - 1); n       else n         from[i][j] = make_pair(i - 1, j - 1); n       f[i][j] = mn; n     } n   cout << f[n][m] << endl; n   int i = n, j = m; n   while (i != 0 || j != 0) { n     if (what[i][j] == 1) n       cout <<  DELETE   << i << endl; n     else if (what[i][j] == 2) n       cout <<  INSERT   << i + 1 <<     << t[j - 1] << endl; n     else if (what[i][j] == 3) n       cout <<  REPLACE   << i <<     << t[j - 1] << endl; n     pair<int, int> h = from[i][j]; n     i = h.first; n     j = h.second; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int m = pow(10, 9) + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s, t; n   cin >> s >> t; n   int j = 0, l = -1, r = -1; n   for (int i = 0; i < t.length(); i++) { n     if (s[j] == t[i]) j++; n     if (j == s.length()) { n       l = i + 1; n       break; n     } n   } n   reverse(s.begin(), s.end()); n   j = 0; n   reverse(t.begin(), t.end()); n   for (int i = 0; i < t.length(); i++) { n     if (s[j] == t[i]) j++; n     if (j == s.length()) { n       r = t.length() - i; n       break; n     } n   } n   if (l >= r || l == -1 || r == -1) n     cout << 0 << endl; n   else n     cout << r - l << endl; n   return 0; n } n


#include <bits/stdc++.h> n bool local = false; n using namespace std; n template <class T> n string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n template <class T> n void print(T v) { n   cout << ((int)(v).size()) <<   n ; n   for (auto x : v) cout << x <<    ; n   cout <<   n ; n }; n template <class T> n void print1(T v) { n   cout << ((int)(v).size()) <<   n ; n   for (auto x : v) cout << x + 1 <<    ; n   cout <<   n ; n }; n template <class T1, class T2> n ostream &operator<<(ostream &o, pair<T1, T2> x) { n   return o << x.first <<     << x.second; n } n template <class T1, class T2> n istream &operator>>(istream &o, pair<T1, T2> &x) { n   return o >> x.first >> x.second; n } n template <class T1, class T2> n pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) { n   a.first += b.first; n   a.second += b.second; n   return a; n } n template <class T1, class T2> n pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) { n   a.first -= b.first; n   a.second -= b.second; n   return a; n } n template <class T1, class T2> n void operator+=(pair<T1, T2> &a, pair<T1, T2> b) { n   a.first += b.first; n   a.second += b.second; n } n template <class T1, class T2> n void operator-=(pair<T1, T2> &a, pair<T1, T2> b) { n   a.first -= b.first; n   a.second -= b.second; n } n int nint() { n   int x; n   cin >> x; n   return x; n } n double getTime() { return clock() / (double)CLOCKS_PER_SEC; }; n mt19937 rnd(0); n int rand(int n) { return rnd() % n; } n int rand(int l, int r) { return rnd() % (r - l + 1) + l; } n const int mod = 1000000000 + 7; n void initIO() { n   if (local) { n     freopen( input.txt ,  r , stdin); n     srand((int)time(0)); n     rnd.seed((int)time(0)); n   } else { n   } n   { n     ios::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n   }; n } n void solve(); n int main() { n   initIO(); n   int tc = 1; n   for (int tt = 0; tt < (tc); tt++) { n     solve(); n   } n   if (local) n     cout <<   n  n          <<  time =   << getTime() <<   n ; n } n int n; n int m; n vector<int> v1, v2; n pair<int, int> val[300500]; n bool f1(int a, int b) { return val[a].second > val[b].second; } n bool f2(int a, int b) { return val[a].second < val[b].second; } n void solve() { n   cin >> n; n   for (int i = 0; i < (n); i++) { n     pair<int, int> o; n     cin >> o; n     val[i] = o; n     if (o.first > o.second) n       v2.emplace_back(i); n     else n       v1.emplace_back(i); n   } n   sort(v1.begin(), v1.end(), f1); n   sort(v2.begin(), v2.end(), f2); n   if (((int)(v1).size()) > ((int)(v2).size())) n     print1(v1); n   else n     print1(v2); n } n


#include <bits/stdc++.h> n using namespace std; n #define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++) n #define FORI(i, a, b) for (int (i) = (a); (i) < (b); (i)++) n   n #define ll long long n #define mp(m, n) make_pair((m), (n)) n // #define DEBUG n   n #ifdef DEBUG n template<typename T> n void _debug(string s, T x) { n     cerr << s <<  : ; n     for (auto it = x.begin(); it != x.end(); ++it) { n         cerr <<     << *it; n     } n     cerr << endl; n } n   n template<typename T, typename K> n void _debug(string s, map<T, K> x) { n     cerr << s <<  : ; n     for (auto it = x.begin(); it != x.end(); ++it) { n         cerr <<     << it->first <<  :  << it->second; n     } n     cerr << endl; n } n  n template<typename T, typename K> n void _debug(string s, set<T, K> x) { n     cerr << s <<  : ; n     for (auto it = x.begin(); it != x.end(); ++it) { n         cerr <<     << *it; n     } n     cerr << endl; n } n   n template<typename T, typename K> n void _debug(string s, vector<pair<T, K> > x) { n     cerr << s <<  : ; n     for (auto it = x.begin(); it != x.end(); ++it) { n         cerr <<     << it->first <<  ,  << it->second; n     } n     cerr << endl; n } n  n void _debug(string s, int x) { n     cerr << s <<  :   << x << endl; n } n void _debug(string s, long long x) { n     cerr << s <<  :   << x << endl; n } n void _debug(string s, double x) { n     cerr << s <<  :   << x << endl; n } n #define debug(x) _debug(#x, (x)) n #else n #define debug(x) n #endif n   n #define db debug n  n const long long N = 2e3 + 4; n int t[4*N] = {}; n  n void add(int L, int R, int val, int index = 1, int l = 1, int r = N - 1) { n      n     if (L > R) return; n     if (r < L || l > R) return; n     if (L <= l && r <= R) {t[index] += val; return; } n     int mid = (l + r) / 2; n     // debug(l);debug(r);debug(mid); n     add(L, R, val, index * 2, l, mid); n     add(L, R, val, index * 2 + 1, mid + 1, r); n  n     // if (pos < l || pos > r) return; n     // if (l == r) { n     //     t[index] = val; n     //     return; n     // } n     // int mid = (l + r) / 2; n     // upd(pos, val, index * 2, l, mid); n     // upd(pos, val, index * 2 + 1, mid + 1, r); n     // t[index] = min(t[index * 2], t[index * 2 + 1]); n } n  n int get_val(int pos, int index = 1, int l = 1, int r = N - 1) { n     if (pos < l || pos > r) return 0; n     if (l == r) { n         return t[index]; n     } n     int mid = (l + r) / 2; n     return t[index] + get_val(pos, index * 2, l, mid) + get_val(pos, index * 2 + 1, mid + 1, r); n } n  n inline int in(int a, int b, int c, int d) { n     int x = max(a, c); n     int y = min(b, d); n     return max(0, y - x + 1); n } n  n int main() { n     ios_base::sync_with_stdio(false); std::cin.tie(0); n     int n, m, k; n     cin >> n >> m >> k; n     vector<int> l(m), r(m); n     FOR(i, m) cin >> l[i] >> r[i]; n     int R = 0; n     for (int i = 1; i + k - 1 <= n; i++) { n         memset(t, 0, sizeof(t)); n         int ans = 0; n         for (int j = 0; j < m; j++) { n             ans += in(i, i + k - 1, l[j], r[j]); n             int x, y; n             x = max(i + 1, l[j] - k + 1); n             y = l[j]; n             vector<int> vvv; n             vvv = {x, y, 1}; n             debug(vvv); n             add(x, y, 1); n             // int xx = r[j] - k + 2; n             // int yy = r[j] + 1; n             // yy = min(yy, xx + y - x); n             int xx = r[j] - k + 2; n             int yy = r[j] + 1; n             xx = max(i + 1, xx); n             yy = min(yy, xx + y - x); n  n             add(xx, yy, -1); n             vvv = {xx, yy, -1}; n             debug(vvv); n         } n         debug(i); n         debug(ans); n         R = max(R, ans); n         for (int j = i + 1; j + k - 1 <= n; j++) { n             ans += get_val(j); n             R = max(R, ans); n             debug(j); debug(ans); n         } n     } n     cout << R << endl; n } n  n      n      n


#include <bits/stdc++.h> n using namespace std; n inline unsigned RD() { n   unsigned intmp(0); n   char rdch(getchar()); n   while (rdch <  0  || rdch >  9 ) rdch = getchar(); n   while (rdch >=  0  && rdch <=  9 ) { n     intmp = (intmp << 3) + (intmp << 1) + rdch -  0 ; n     rdch = getchar(); n   } n   return intmp; n } n inline int RDsg() { n   int rdtp(0), rdsg(1); n   char rdch(getchar()); n   while ((rdch <  0  || rdch >  9 ) && (rdch !=  - )) rdch = getchar(); n   if (rdch ==  - ) { n     rdsg = -1; n     rdch = getchar(); n   } n   while (rdch >=  0  && rdch <=  9 ) { n     rdtp = (rdtp << 3) + (rdtp << 1) + rdch -  0 ; n     rdch = getchar(); n   } n   return rdtp * rdsg; n } n unsigned Bd[500005], Pos1[500005], Pos2[500005], m, n, q, Cnt(0), A, B, C, D, t, n     Ans(0); n char a[500005], b[500005]; n inline void Clr() {} n int main() { n   n = RD(), m = RD(), q = RD(); n   scanf( %s%s , a + 1, b + 1); n   Bd[0] = -1; n   for (register unsigned i(2), Tmp; i <= m; ++i) { n     Tmp = Bd[i - 1]; n     while ((b[i] ^ b[Tmp + 1]) && (Tmp < 0x3f3f3f3f)) { n       Tmp = Bd[Tmp]; n     } n     Bd[i] = Tmp + 1; n   } n   for (register unsigned i(1), j(0); i <= n; ++i) { n     while ((a[i] ^ b[j + 1]) && (j < 0x3f3f3f3f)) { n       j = Bd[j]; n     } n     if (j > 0x3f3f3f3f) { n       j = 0; n       continue; n     } else { n       ++j; n       if (Pos1[j] < q) { n         Pos1[j] = i; n       } n       if ((j == m) && (!A)) { n         A = i; n       } n     } n   } n   for (register unsigned i(m - 1); i; --i) { n     if ((Pos1[i + 1] > q) && Pos1[i + 1]) { n       Pos1[i] = min(Pos1[i], Pos1[i + 1] - 1); n     } n   } n   for (register unsigned i(m); i; --i) { n     if (Pos1[i] < q) { n       Pos1[i] = 0; n       continue; n     } n     if (Pos1[Bd[i]] < q) n       Pos1[Bd[i]] = Pos1[i]; n     else n       Pos1[Bd[i]] = min(Pos1[Bd[i]], Pos1[i]); n   } n   Bd[m + 1] = -1; n   Bd[m] = 0; n   for (register unsigned i(m - 1), Tmp; i; --i) { n     Tmp = Bd[i + 1]; n     while ((b[i] ^ b[m - Tmp]) && (Tmp < 0x3f3f3f3f)) { n       Tmp = Bd[m - Tmp + 1]; n     } n     Bd[i] = Tmp + 1; n   } n   for (register unsigned i(n), j(0); i; --i) { n     while ((j < 0x3f3f3f3f) && (a[i] ^ b[m - j])) { n       j = Bd[m - j + 1]; n     } n     if (j > 0x3f3f3f3f) { n       j = 0; n       continue; n     } else { n       if ((n - Pos2[m - j] + 1 < q) || (!Pos2[m - j])) { n         Pos2[m - j] = i; n       } n       ++j; n       if ((j == m) && (!B)) { n         B = i; n       } n     } n   } n   for (register unsigned i(2); i <= m; ++i) { n     if ((n - Pos2[i - 1] + 1 > q) && (Pos2[i - 1])) { n       Pos2[i] = max(Pos2[i], Pos2[i - 1] + 1); n     } n   } n   for (register unsigned i(1); i <= m; ++i) { n     if (n - Pos2[i] + 1 < q) { n       Pos2[i] = 0; n       continue; n     } n     if (n - Pos2[m - Bd[i] + 1] + 1 < q) n       Pos2[m - Bd[i] + 1] = Pos2[i]; n     else n       Pos2[m - Bd[i] + 1] = max(Pos2[i], Pos2[m - Bd[i] + 1]); n   } n   if (q >= m) { n     if (A && (n >= q + max(A, q))) { n       printf( Yes n%u %u n , max(A, q) - q + 1, max(A, q) + 1); n       return 0; n     } n     if (B && (min(B, n - q + 1) > q)) { n       printf( Yes n%u %u n , min(B, n - q + 1) - q, min(B, n - q + 1)); n       return 0; n     } n   } n   for (register unsigned i(m - min(m - 1, q)); i <= min(m - 1, q); ++i) { n     if (Pos1[i] && Pos2[i + 1] && (Pos1[i] < Pos2[i + 1])) { n       printf( Yes n%u %u n , Pos1[i] - q + 1, Pos2[i + 1]); n       return 0; n     } n   } n   printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long BIG = 1000000000000000000LL; n void solve(); n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n   return 0; n } n const long long borne = 3 * (long long)(1e5) + 5; n long long tab[borne]; n long long som[borne]; n long long nbElem, nbParties; n void solve() { n   cin >> nbElem >> nbParties; n   for (long long i = (0); i < (nbElem); ++i) { n     cin >> tab[i]; n   } n   som[0] = tab[0]; n   for (long long i = (1); i < (nbElem); ++i) som[i] = tab[i] + som[i - 1]; n   vector<long long> ww(nbElem - 1); n   for (long long i = (0); i < (nbElem - 1); ++i) ww[i] = som[i]; n   sort(ww.begin(), ww.end()); n   long long res = nbParties * som[nbElem - 1]; n   for (long long i = (0); i < (nbParties - 1); ++i) res -= ww[i]; n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c, x; n   cin >> a >> b >> c; n   if (a * c % 100 == 0) n     x = (a * c) / 100; n   else n     x = (a * c) / 100 + 1; n   if (x < b) n     cout <<  0  << endl; n   else n     cout << x - b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   char name[20]; n   int id; n   int num; n } a[100005]; n bool cmp(node x, node y) { n   if (x.id == y.id) return x.num > y.num; n   return x.id < y.id; n } n int main() { n   int n, m; n   while (cin >> n >> m) { n     for (int i = 0; i < n; i++) { n       scanf(  %s %d %d , a[i].name, &a[i].id, &a[i].num); n     } n     sort(a, a + n, cmp); n     int st = 0, ed = 0; n     for (st = 0; st < n; st = ed) { n       while (ed < n && a[ed].id == a[st].id) ed++; n       int fir = a[st].num; n       int sec = a[st + 1].num; n       if (ed - st > 2 && sec == a[st + 2].num) { n         printf( ? n ); n       } else { n         printf( %s %s n , a[st].name, a[st + 1].name); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int maxn = 4e2 + 5, maxk = 4e2 + 5, inf = 1e9 + 69, delta = 1e9 + 7, n           max_sum = 10000 + 5; n inline void in_out_optimize() { n   ios::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n } n int main() { n   in_out_optimize(); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     long long eq = inf - (inf % n); n     set<int> dest; n     for (int i = 0; i < n; i++) { n       int a; n       cin >> a; n       if (a < 0) a += eq; n       a %= n; n       dest.insert((i + a) % n); n     } n     if (dest.size() == n) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k; n string n, m; n int a[1001], b[1001], ns, ms; n int fs, ss; n int lcm(int, int); n int gcd(int, int); n int main() { n   cin >> k >> n >> m; n   ns = n.size(); n   ms = m.size(); n   for (int i = 0; i < ns; i++) { n     a[i] = (n[i] ==  R  ? 0 : (n[i] ==  P  ? 1 : 2)); n   } n   for (int i = 0; i < ms; i++) { n     b[i] = (m[i] ==  R  ? 0 : (m[i] ==  P  ? 1 : 2)); n   } n   int q = 0, p = 0, l = lcm(ns, ms); n   for (int i = 0; i < l; i++) { n     if ((a[q] == 0 && b[p] == 2) || (a[q] == 2 && b[p] == 1) || n         (a[q] == 1 && b[p] == 0)) n       fs++; n     else if (a[q] != b[p]) n       ss++; n     q++, p++; n     if (q == ns) q = 0; n     if (p == ms) p = 0; n   } n   fs *= k / l; n   ss *= k / l; n   p = q = 0; n   for (int i = 0; i < k % l; i++) { n     if ((a[q] == 0 && b[p] == 2) || (a[q] == 2 && b[p] == 1) || n         (a[q] == 1 && b[p] == 0)) n       fs++; n     else if (a[q] != b[p]) n       ss++; n     q++, p++; n     if (q == ns) q = 0; n     if (p == ms) p = 0; n   } n   cout << ss <<     << fs; n } n int lcm(int q, int p) { return q * p / gcd(q, p); } n int gcd(int q, int p) { n   if (q > p) { n     q += p, p = q - p, q -= p; n   } n   if (!q) return p; n   return gcd(p - q, q); n } n


#include <bits/stdc++.h> n using namespace std; n int rd() { n   int x = 0, flg = 1; n   char c = getchar(); n   for (; (c < 48 || c > 57) && c !=  - ; c = getchar()) n     ; n   if (c ==  - ) flg = -1, c = getchar(); n   for (; c > 47 && c < 58; x = x * 10 + c - 48, c = getchar()) n     ; n   return flg * x; n } n const int mxn = 100010; n struct nd { n   int sm, px, py, sx, sy, mx, ml, mr, _px, _py, _sx, _sy, _mx, _ml, _mr; n   nd operator!() { n     return (nd){-sm, -_px, _py, -_sx, _sy, -_mx, _ml, _mr, n                 -px, py,   -sx, sy,   -mx, ml,   mr}; n   } n } tr[mxn << 2], ret; n int tag[mxn << 2]; n void mrg(nd x, nd y) { n   ret.sm = x.sm + y.sm; n   if (x.px < x.sm + y.px) n     ret.px = x.px, ret.py = x.py; n   else n     ret.px = x.sm + y.px, ret.py = y.py; n   if (y.sx < y.sm + x.sx) n     ret.sx = y.sx, ret.sy = y.sy; n   else n     ret.sx = y.sm + x.sx, ret.sy = x.sy; n   if (x.mx < y.mx) n     if (x.mx < x.sx + y.px) n       ret.mx = x.mx, ret.ml = x.ml, ret.mr = x.mr; n     else n       ret.mx = x.sx + y.px, ret.ml = x.sy, ret.mr = y.py; n   else if (y.mx < x.sx + y.px) n     ret.mx = y.mx, ret.ml = y.ml, ret.mr = y.mr; n   else n     ret.mx = x.sx + y.px, ret.ml = x.sy, ret.mr = y.py; n   if (x._px > x.sm + y._px) n     ret._px = x._px, ret._py = x._py; n   else n     ret._px = x.sm + y._px, ret._py = y._py; n   if (y._sx > y.sm + x._sx) n     ret._sx = y._sx, ret._sy = y._sy; n   else n     ret._sx = y.sm + x._sx, ret._sy = x._sy; n   if (x._mx > y._mx) n     if (x._mx > x._sx + y._px) n       ret._mx = x._mx, ret._ml = x._ml, ret._mr = x._mr; n     else n       ret._mx = x._sx + y._px, ret._ml = x._sy, ret._mr = y._py; n   else if (y._mx > x._sx + y._px) n     ret._mx = y._mx, ret._ml = y._ml, ret._mr = y._mr; n   else n     ret._mx = x._sx + y._px, ret._ml = x._sy, ret._mr = y._py; n } n void mrg_rev(nd x, nd y) { n   ret.sm = -x.sm - y.sm; n   if (x._px > x.sm + y._px) n     ret.px = -x._px, ret.py = x._py; n   else n     ret.px = -x.sm - y._px, ret.py = y._py; n   if (y._sx > y.sm + x._sx) n     ret.sx = -y._sx, ret.sy = y._sy; n   else n     ret.sx = -y.sm - x._sx, ret.sy = x._sy; n   if (x._mx > y._mx) n     if (x._mx > x._sx + y._px) n       ret.mx = -x._mx, ret.ml = x._ml, ret.mr = x._mr; n     else n       ret.mx = -x._sx - y._px, ret.ml = x._sy, ret.mr = y._py; n   else if (y._mx > x._sx + y._px) n     ret.mx = -y._mx, ret.ml = y._ml, ret.mr = y._mr; n   else n     ret.mx = -x._sx - y._px, ret.ml = x._sy, ret.mr = y._py; n   if (x.px < x.sm + y.px) n     ret._px = -x.px, ret._py = x.py; n   else n     ret._px = -x.sm - y.px, ret._py = y.py; n   if (y.sx < y.sm + x.sx) n     ret._sx = -y.sx, ret._sy = y.sy; n   else n     ret._sx = -y.sm - x.sx, ret._sy = x.sy; n   if (x.mx < y.mx) n     if (x.mx < x.sx + y.px) n       ret._mx = -x.mx, ret._ml = x.ml, ret._mr = x.mr; n     else n       ret._mx = -x.sx - y.px, ret._ml = x.sy, ret._mr = y.py; n   else if (y.mx < x.sx + y.px) n     ret._mx = -y.mx, ret._ml = y.ml, ret._mr = y.mr; n   else n     ret._mx = -x.sx - y.px, ret._ml = x.sy, ret._mr = y.py; n } n void pushup(int i) { n   if (tag[i]) n     mrg_rev(tr[(i << 1)], tr[(i << 1 | 1)]); n   else n     mrg(tr[(i << 1)], tr[(i << 1 | 1)]); n   tr[i] = ret; n } n void update(int i, int l, int r, int p, int v) { n   if (l == r) { n     tr[i] = (nd){v, v, l, v, l, v, l, l, v, l, v, l, v, l, l}; n     return; n   } n   if (p <= ((l + r) >> 1)) n     update((i << 1), l, ((l + r) >> 1), p, v); n   else n     update((i << 1 | 1), ((l + r) >> 1) + 1, r, p, v); n   pushup(i); n } n void modify(int i, int l, int r, int x, int y) { n   if (r < x || l > y) return; n   if (l >= x && r <= y) { n     tag[i] ^= 1, tr[i] = !tr[i]; n     return; n   } n   modify((i << 1), l, ((l + r) >> 1), x, y); n   modify((i << 1 | 1), ((l + r) >> 1) + 1, r, x, y); n   pushup(i); n } n int tot, id[mxn], fl[mxn], bl[mxn], br[mxn]; n void query(int i, int l, int r, int x, int y, bool fg) { n   if (r < x || l > y) return; n   if (l >= x && r <= y) { n     id[++tot] = i; n     fl[tot] = fg; n     bl[tot] = l, br[tot] = r; n     return; n   } n   query((i << 1), l, ((l + r) >> 1), x, y, fg ^ tag[i]); n   query((i << 1 | 1), ((l + r) >> 1) + 1, r, x, y, fg ^ tag[i]); n } n void qry() { n   if (fl[1]) n     ret = !tr[id[1]]; n   else n     ret = tr[id[1]]; n   for (int i = 2; i <= tot; ++i) n     if (fl[i]) n       mrg(ret, !tr[id[i]]); n     else n       mrg(ret, tr[id[i]]); n } n int n, q, a[mxn], qi[mxn], ql[mxn], qr[mxn], qx[mxn], qy[mxn]; n void build(int i, int l, int r) { n   if (l == r) { n     tr[i] = n         (nd){a[l], a[l], l, a[l], l, a[l], l, l, a[l], l, a[l], l, a[l], l, l}; n     return; n   } n   build((i << 1), l, ((l + r) >> 1)), n       build((i << 1 | 1), ((l + r) >> 1) + 1, r); n   pushup(i); n } n int main() { n   n = rd(); n   for (int i = 1; i <= n; ++i) a[i] = rd(); n   build(1, 1, n); n   q = rd(); n   for (int i = 1; i <= q; ++i) n     if (rd()) { n       int l = rd(), r = rd(), k = rd(), m = 0, ans = 0; n       tot = 0; n       query(1, 1, n, l, r, 0); n       for (; k--;) { n         qry(); n         if (ret._mx <= 0) break; n         ans += ret._mx; n         int x = ret._ml, y = ret._mr; n         modify(1, 1, n, x, y); n         ql[++m] = x, qr[m] = y; n       } n       printf( %d n , ans); n       for (int j = 1; j <= m; ++j) modify(1, 1, n, ql[j], qr[j]); n     } else { n       int x = rd(), y = rd(); n       update(1, 1, n, x, y); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[1 << 21], *p1 = buf, *p2 = buf; n template <class T> n void read(T &x) { n   x = 0; n   int c = getchar(); n   int flag = 0; n   while (c <  0  || c >  9 ) flag |= (c ==  - ), c = getchar(); n   while (c >=  0  && c <=  9 ) n     x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); n   if (flag) x = -x; n } n template <class T> n T _max(T a, T b) { n   return b < a ? a : b; n } n template <class T> n T _min(T a, T b) { n   return a < b ? a : b; n } n template <class T> n bool checkmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n } n template <class T> n bool checkmin(T &a, T b) { n   return b < a ? a = b, 1 : 0; n } n const int N = 1000005; n int n; n int a[N], b[N], sa[N], sb[N]; n void init() { n   read(n); n   for (int i = 1; i <= n; ++i) read(a[i]); n   for (int i = 1; i <= n; ++i) read(b[i]); n   sa[n + 1] = 0; n   for (int i = n; i >= 1; --i) sa[i] = sa[i + 1] + a[i]; n   sb[0] = 0; n   for (int i = 1; i <= n; ++i) sb[i] = sb[i - 1] + b[i]; n } n void solve() { n   int ans = -1; n   for (int i = 1; i <= n; ++i) { n     int w = max(sb[i - 1], sa[i + 1]); n     if (i == 1) n       ans = w; n     else n       checkmin(ans, w); n   } n   printf( %d n , ans); n } n int main() { n   int t; n   read(t); n   while (t--) { n     init(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dist(double x1, double y1, double x2, double y2) { n   double dx = x1 - x2; n   double dy = y1 - y2; n   return sqrt(dx * dx + dy * dy); n } n double catet(double a, int b) { n   double z = a * a - b * b; n   if (z < 1e-12) z = 0; n   return sqrt(z); n } n int main() { n   int xp, yp, vp; n   cin >> xp >> yp >> vp; n   int x, y, v, r; n   cin >> x >> y >> v >> r; n   const double eps = 1e-10; n   const double R = sqrt(1.0 * xp * xp + 1.0 * yp * yp); n   double lo = 0; n   double hi = 1e7; n   double T; n   while ((hi - lo) / hi > eps) { n     T = (lo + hi) / 2; n     const double alpha = T / (R / vp); n     double nx = xp * cos(alpha) - yp * sin(alpha); n     double ny = xp * sin(alpha) + yp * cos(alpha); n     double a = ny - y; n     double b = x - nx; n     double c = -(a * x + b * y); n     double z = sqrt(a * a + b * b); n     a /= z; n     b /= z; n     c /= z; n     double need; n     if (fabs(c) < r - 1e-8) { n       double mx = a * (-c); n       double my = b * (-c); n       if (dist(x, y, mx, my) + dist(mx, my, nx, ny) > n           dist(x, y, nx, ny) + 1e-8) { n         need = dist(x, y, nx, ny); n       } else { n         need = catet(dist(x, y, 0, 0), r) + catet(dist(nx, ny, 0, 0), r); n         double alp = fabs(atan2(y, x) - atan2(ny, nx)); n         if (alp > M_PI) alp = 2 * M_PI - alp; n         alp -= acos(r / dist(x, y, 0, 0)); n         alp -= acos(r / dist(nx, ny, 0, 0)); n         need += alp * r; n       } n     } else { n       need = dist(x, y, nx, ny); n     } n     if (need <= v * T) { n       hi = T; n     } else { n       lo = T; n     } n   } n   printf( %.6f n , T); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n using vi = vector<int>; n const int N = 2 * 5e5 + 5; n int n, m, q; n int par[N], sub[N]; n int p[N]; n struct edge { n   int l, r, tag = 0; n } elist[N]; n vi g[N]; n int dp[19][500005]; n const int lg = 19; n int position[N]; n int in[N], out[N], tym = 0; n int what[N]; n void setPar(int u, int dad) { n   dp[0][u] = dad; n   for (int i = 1; i < lg; ++i) { n     dp[i][u] = dp[i - 1][dp[i - 1][u]]; n   } n } n void dfs(int u) { n   if (u <= n) { n     in[u] = out[u] = ++tym; n     what[tym] = u; n     position[p[u]] = tym; n   } else { n     in[u] = INT_MAX; n     out[u] = INT_MIN; n     for (int v : g[u]) { n       setPar(v, u); n       dfs(v); n       in[u] = min(in[u], in[v]); n       out[u] = max(out[u], out[v]); n     } n   } n } n int getHighest(int u, int tag) { n   for (int i = lg - 1; i >= 0; --i) { n     if (dp[i][u]) { n       if (elist[dp[i][u] - n].tag >= tag) { n         u = dp[i][u]; n       } n     } n   } n   return u; n } n int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); } n int mx[N]; n void build(int u = 1, int b = 1, int e = n) { n   if (b == e) { n     return void(mx[u] = p[what[b]]); n   } n   int mid = (b + e) >> 1; n   build(u << 1, b, mid); n   build(u << 1 | 1, mid + 1, e); n   mx[u] = max(mx[u << 1], mx[u << 1 | 1]); n } n int Max(int l, int r, int u = 1, int b = 1, int e = n) { n   if (l <= b and e <= r) return mx[u]; n   if (b > r or e < l) return INT_MIN; n   int mid = (b + e) >> 1; n   return max(Max(l, r, u << 1, b, mid), Max(l, r, u << 1 | 1, mid + 1, e)); n } n void makeZero(int pos, int u = 1, int b = 1, int e = n) { n   if (b == e) { n     return void(mx[u] = 0); n   } n   int mid = (b + e) >> 1; n   if (pos <= mid) { n     makeZero(pos, u << 1, b, mid); n   } else { n     makeZero(pos, u << 1 | 1, mid + 1, e); n   } n   mx[u] = max(mx[u << 1], mx[u << 1 | 1]); n } n int main(int argc, char const *argv[]) { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &p[i]); n   } n   for (int i = 1; i < N; ++i) { n     par[i] = i, sub[i] = 1; n   } n   for (int i = 1; i <= m; ++i) { n     scanf( %d %d , &elist[i].l, &elist[i].r); n   } n   vector<ii> updates; n   for (int i = 1; i <= q; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     updates.emplace_back(x, y); n     if (x == 2) { n       elist[y].tag = i; n     } n   } n   for (int i = 1; i <= m; ++i) { n     if (!elist[i].tag) { n       elist[i].tag = q + i; n     } n   } n   vi perm(m); n   iota(begin(perm), end(perm), 1); n   sort(begin(perm), end(perm), n        [](int x, int y) { return elist[x].tag > elist[y].tag; }); n   for (int i : perm) { n     int nu = n + i; n     int x = find(elist[i].l); n     int y = find(elist[i].r); n     if (x != y) { n       par[x] = par[y] = nu; n       g[nu].emplace_back(x); n       g[nu].emplace_back(y); n     } n   } n   for (int i = 2; i <= 4; ++i) { n   } n   set<int> roots; n   for (int i = 1; i <= n; ++i) { n     roots.insert(find(i)); n   } n   for (int x : roots) { n     setPar(x, 0); n     dfs(x); n   } n   build(); n   vi ans; n   for (int i = 0; i < (int)(updates).size(); ++i) { n     int tag = i + 1; n     auto [op, u] = updates[i]; n     if (op == 1) { n       int anc = getHighest(u, tag); n       int mxVal = Max(in[anc], out[anc]); n       ans.emplace_back(mxVal); n       if (mxVal) makeZero(position[mxVal]); n     } else { n     } n   } n   for (int x : ans) { n     printf( %d n , x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, q; n long long f(long long md) { return n - md + min(n - md, md * (md - 1) / 2); } n signed main() { n   cin >> q; n   while (q--) { n     cin >> n; n     long long lo = 1, hi = n; n     while (lo + 1 < hi) { n       long long md = (lo + hi) >> 1; n       if (f(md) < f(md + 1)) n         lo = md; n       else n         hi = md; n     } n     cout << max(f(hi), f(lo)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 100005; n int n, q, tree_ct, k[Maxn], r[Maxn], ord[Maxn], Head[Maxn]; n struct Tree { n   int lson, rson; n   long long k, b; n } tree[24 * Maxn]; n void build_first(int root, int lt, int rt) { n   if (lt + 1 == rt) n     tree[root].k = k[lt], tree[root].b = 0; n   else { n     int mid = (lt + rt) >> 1; n     tree[root].lson = ++tree_ct; n     tree[root].rson = ++tree_ct; n     build_first(tree[root].lson, lt, mid); n     build_first(tree[root].rson, mid, rt); n     tree[root].k = tree[tree[root].lson].k + tree[tree[root].rson].k; n     tree[root].b = tree[tree[root].lson].b + tree[tree[root].rson].b; n   } n } n void build(int root, int las, int lt, int rt, int pos) { n   if (lt + 1 == rt) n     tree[root].k = 0, tree[root].b = r[lt]; n   else { n     int mid = (lt + rt) >> 1; n     if (pos >= mid) { n       tree[root].rson = ++tree_ct; n       tree[root].lson = tree[las].lson; n       build(tree[root].rson, tree[las].rson, mid, rt, pos); n     } else { n       tree[root].lson = ++tree_ct; n       tree[root].rson = tree[las].rson; n       build(tree[root].lson, tree[las].lson, lt, mid, pos); n     } n     tree[root].k = tree[tree[root].lson].k + tree[tree[root].rson].k; n     tree[root].b = tree[tree[root].lson].b + tree[tree[root].rson].b; n   } n } n pair<long long, long long> operator+(pair<long long, long long> a, n                                      pair<long long, long long> b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n pair<long long, long long> ask(int root, int lt, int rt, int L, int R) { n   if (lt == L && rt == R) n     return make_pair(tree[root].k, tree[root].b); n   else { n     int mid = (lt + rt) >> 1; n     if (L >= mid) n       return ask(tree[root].rson, mid, rt, L, R); n     else if (R <= mid) n       return ask(tree[root].lson, lt, mid, L, R); n     else n       return ask(tree[root].lson, lt, mid, L, mid) + n              ask(tree[root].rson, mid, rt, mid, R); n   } n } n struct sta { n   int lt, rt; n   double t; n   bool operator<(const sta &tmp) const { return lt < tmp.lt; } n }; n set<sta> Se; n set<sta>::iterator spilt(int x) { n   if (x > n) return Se.end(); n   sta tmp = *(--Se.upper_bound((sta){x, 0, 0})); n   Se.erase(tmp); n   if (tmp.lt != x) Se.insert((sta){tmp.lt, x - 1, tmp.t}); n   return Se.insert((sta){x, tmp.rt, tmp.t}).first; n } n pair<long long, long long> cal(double t, int lt, int rt) { n   int L = 0, R = n; n   while (L + 1 <= R) { n     int mid = (L + R + 1) >> 1; n     if (r[ord[mid]] > t * k[ord[mid]]) n       R = mid - 1; n     else n       L = mid; n   } n   return ask(Head[L], 1, n + 1, lt, rt + 1); n } n set<pair<int, int> > S; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d%d%d , &x, &r[i], &k[i]), ord[i] = i; n     if (!r[i] && !k[i]) r[i] = 1; n     if (k[i]) n       Se.insert((sta){i, i, -x / (double)k[i]}); n     else n       Se.insert((sta){i, i, 0}), S.insert(make_pair(i, x)); n   } n   S.insert(make_pair(n + 1, 0)); n   Head[0] = ++tree_ct; n   build_first(Head[0], 1, n + 1); n   sort(ord + 1, ord + 1 + n, [](int x, int y) { n     return r[x] * (long long)k[y] < r[y] * (long long)k[x]; n   }); n   for (int i = 1; i <= n; i++) n     Head[i] = ++tree_ct, build(Head[i], Head[i - 1], 1, n + 1, ord[i]); n   scanf( %d , &q); n   while (q--) { n     int t, lt, rt; n     long long ans = 0; n     scanf( %d%d%d , &t, &lt, &rt); n     set<pair<int, int> >::iterator it; n     while (S.size() > 1 && n            (it = S.lower_bound(make_pair(lt, 0)))->first <= rt) { n       ans += it->second; n       S.erase(it); n     } n     set<sta>::iterator it_r = spilt(rt + 1), it_l = spilt(lt), tmp_it; n     tmp_it = it_l; n     for (; it_l != it_r; it_l++) { n       pair<long long, long long> now = cal(t - it_l->t, it_l->lt, it_l->rt); n       ans += now.second + (long long)(now.first * (t - it_l->t) + 0.5); n     } n     Se.erase(tmp_it, it_r); n     Se.insert((sta){lt, rt, (double)t}); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 100005; n long long n, x[maxn], y[maxn]; n bool flag; n inline long long nxt(long long id) { return (id + 1) % n; } n inline bool check(long long i, long long j) { n   return (x[i] + x[j] == x[nxt(i)] + x[nxt(j)]) && n          (y[i] + y[j] == y[nxt(i)] + y[nxt(j)]); n } n int main() { n   scanf( %lld , &n); n   if (n % 2 == 1) { n     printf( No n ); n     return 0; n   } n   for (register long long i = 0; i < n; i++) scanf( %lld%lld , &x[i], &y[i]); n   for (register long long i = 0; i * 2 < n; i++) n     if (!check(i, i + (n / 2))) { n       flag = true; n       break; n     } n   if (flag) n     printf( No n ); n   else n     printf( Yes n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long GCD(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n int main() { n   int n, k, i; n   long double x, y, xant, yant; n   scanf( %d%d , &n, &k); n   double sol = 0; n   for (i = 0; i < n; i++) { n     cin >> x >> y; n     if (i) sol += sqrt((x - xant) * (x - xant) + (y - yant) * (y - yant)); n     xant = x, yant = y; n   } n   sol = (sol * (long double)k) / 50.0; n   printf( %.9lf n , sol); n   return 0; n } n


#include <bits/stdc++.h> n inline int A(int x, int y) { return x && y; } n inline int O(int x, int y) { return x ^ y; } n inline int X(int x, int y) { return x || y; } n int main() { n   int t1, t2, t3, t4; n   scanf( %d%d%d%d , &t1, &t2, &t3, &t4); n   int a1 = O(t1, t2); n   int a2 = X(t3, t4); n   int a3 = A(t2, t3); n   int a4 = O(t1, t4); n   int b1 = A(a1, a2); n   int b2 = X(a3, a4); n   int c1 = O(b1, b2); n   printf( %d , c1); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n int t, n, m; n string x, y; n int main() { n   cin >> t; n   while (t--) { n     cin >> x; n     cin >> y; n     n = (int)(x.length()); n     m = (int)(y.length()); n     reverse(x.begin(), x.end()); n     reverse(y.begin(), y.end()); n     int pos1 = 0; n     while (y[pos1] !=  1 ) { n       ++pos1; n     } n     int pos2 = pos1; n     while (x[pos2] !=  1 ) { n       ++pos2; n     } n     cout << pos2 - pos1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n int w[MAXN]; n map<int, int> f; n long long Calc(long long Res, long long Mod) { n   if (Res > Mod) return Res % Mod + Mod; n   return Res; n } n long long power(long long a, long long n, long long Mod) { n   long long Res = 1; n   while (n) { n     if (n & 1) Res = Calc(Res * a, Mod); n     a = Calc(a * a, Mod); n     n >>= 1; n   } n   return Res; n } n int phi(int n) { n   int result = 1; n   if (f.count(n)) return f[n]; n   for (int i = 2; i * i <= n; ++i) { n     if (n % i == 0) { n       while (n % i == 0) { n         n /= i; n         result *= i; n       } n       result /= i; n       result *= (i - 1); n     } n   } n   if (n != 1) result *= (n - 1); n   f[n] = result; n   return f[n]; n } n long long Solve(int l, int r, int Mod) { n   if (l == r || Mod == 1) return Calc(w[l], Mod); n   return power(w[l], Solve(l + 1, r, phi(Mod)), Mod); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int q, n, Mod; n   cin >> n >> Mod; n   for (int i = 1; i <= n; ++i) cin >> w[i]; n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     long long ans = Solve(l, r, Mod); n     cout << ans % Mod << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int check(int x) { n   int sum = 0; n   if (n <= ceil(x / 2)) sum++; n   if (m <= ceil(x / 3)) sum++; n   if ((n + m <= ceil(x / 2) + ceil(x / 3) - ceil(x / 6))) sum++; n   if (sum == 3) return 1; n   return 0; n } n int main() { n   cin >> n >> m; n   int x; n   x = max(2 * n, max(3 * m, (2 * n + 3 * m) / 2)); n   for (int i = x; i <= 10000000; i++) { n     if (check(i)) { n       cout << i << endl; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a[60][60]; n int ch(int r, int c) { n   int i, j, f = 0; n   for (i = 0; i < c; i++) { n     if (a[0][i] ==  P ) f = 1; n   } n   if (f == 0) return 0; n   f = 0; n   for (i = 0; i < c; i++) { n     if (a[r - 1][i] ==  P ) f = 1; n   } n   if (f == 0) return 0; n   f = 0; n   for (i = 0; i < r; i++) { n     if (a[i][0] ==  P ) f = 1; n   } n   if (f == 0) return 0; n   f = 0; n   for (i = 0; i < r; i++) { n     if (a[i][c - 1] ==  P ) f = 1; n   } n   return f; n } n int chh(int r, int c) { n   int i, j, f = 0; n   for (i = 1; i < r - 1; i++) { n     f = 0; n     for (j = 0; j < c; j++) { n       if (a[i][j] ==  P ) f = 1; n     } n     if (f == 0) return 0; n   } n   for (i = 1; i < c - 1; i++) { n     f = 0; n     for (j = 0; j < r; j++) { n       if (a[j][i] ==  P ) f = 1; n     } n     if (f == 0) return 0; n   } n   return 1; n } n int al(int r, int c) { n   int i, j, f = 0; n   for (i = 0; i < r; i++) { n     for (j = 0; j < c; j++) { n       if (a[i][j] ==  P ) return 1; n     } n   } n   return 0; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int r, c, i, j, f = 0; n     cin >> r >> c; n     cin.ignore(256,   n ); n     for (i = 0; i < r; i++) { n       string s; n       getline(cin, s); n       for (j = 0; j < c; j++) a[i][j] = s[j]; n     } n     for (i = 0; i < r; i++) { n       for (j = 0; j < c; j++) { n         if (a[i][j] ==  A ) { n           f = 1; n           break; n         } n       } n     } n     if (f == 0) { n       cout <<  MORTAL n ; n     } else if (al(r, c) == 0) n       cout << 0 << endl; n     else { n       if (ch(r, c) == 0) n         cout << 1 << endl; n       else if (a[0][0] ==  A  || a[0][c - 1] ==  A  || a[r - 1][0] ==  A  || n                a[r - 1][c - 1] ==  A  || chh(r, c) == 0) n         cout << 2 << endl; n       else { n         f = 0; n         for (i = 1; i < c - 1; i++) { n           if (a[0][i] ==  A ) f = 1; n           if (a[r - 1][i] ==  A ) f = 1; n         } n         for (i = 1; i < r - 1; i++) { n           if (a[i][0] ==  A ) f = 1; n           if (a[i][c - 1] ==  A ) f = 1; n         } n         if (f == 1) n           cout << 3 << endl; n         else n           cout << 4 << endl; n       } n     } n   } n } n