#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n const int inf = 2012345678; n const int N = 2e5 + 10; n string s, ans, tmp; n bool ch() { n   int i = 0; n   while (s[i] == tmp[i] && i < tmp.length()) ++i; n   return i == tmp.length(); n } n int main() { n   int n, k; n   cin >> n >> k >> s; n   ans = s, --k; n   int ps = 1; n   while (k--) { n     while (true) { n       if (ps == ans.length()) { n         ans += s, ps = ans.length(); n         break; n       } n       tmp = ans.substr(ps); n       if (ch()) { n         for (int i = tmp.length(); i < (int)(s.length()); ++i) ans += s[i]; n         ++ps; n         break; n       } else n         ++ps; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char d[8][8]; n int i, j, sch, k, m; n int main() { n   k = 0; n   m = 0; n   for (i = 0; i < 8; i++) { n     sch = 0; n     for (j = 0; j < 8; j++) { n       cin >> d[i][j]; n       if (d[i][j] ==  B ) sch++; n     } n     if (sch == 8) n       k++; n     else if (sch > m) n       m = sch; n   } n   cout << k + m; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, nn = 0, range; n   int a, b, c, d, pos, neg, ok = 1, finddd = 0; n   int ara[200], ara2[200]; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &ara[i], &ara2[i]); n     if (ara2[i] == m || ara[i] == m) { n       finddd = 1; n     } n   } n   if (n == 1 && ara[0] == 1) { n     finddd = 0; n   } n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < i; j++) { n       if (ara[i] <= ara2[j]) { n         pos = 1; n       } n     } n     if (pos == 1) { n       ok = 1; n     } else { n       ok = 0; n       break; n     } n     pos = 0; n     neg = 0; n   } n   if (ok == 1 && finddd == 1) { n     printf( YES n ); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n char s[8][10]; n int i; n vector<int> p; n int cnt() { n   int v[8]; n   int i, j; n   for (i = 0; i < n; i++) { n     v[i] = 0; n     for (j = 0; j < k; j++) v[i] = v[i] * 10 + (int)(s[i][p[j]] -  0 ); n   } n   int minv = v[0]; n   int maxv = v[0]; n   for (i = 0; i < n; i++) { n     if (v[i] > maxv) maxv = v[i]; n     if (v[i] < minv) minv = v[i]; n   } n   return maxv - minv; n } n int main() { n   scanf( %d %d , &n, &k); n   for (i = 0; i < n; i++) scanf( %s , s[i]); n   for (i = 0; i < k; i++) p.push_back(i); n   int sol = cnt(); n   while (next_permutation(p.begin(), p.end())) { n     int res = cnt(); n     if (res < sol) sol = res; n   } n   printf( %d n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   long long t, n, h, i, j, x, y, z, k, e, m; n   string s; n   cin >> n >> m; n   x = 0; n   for (i = 1; i <= n; i++) { n     y = i / 5; n     z = (i + m) / 5; n     x += (z - y); n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool read(T &x) { n   int c = getchar(); n   int sgn = 1; n   while (~c && c< 0  | c>  9 ) { n     if (c ==  - ) sgn = -1; n     c = getchar(); n   } n   for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   x *= sgn; n   return ~c; n } n const long long N = 100005; n const long long MOD = 1e9 + 7; n long long dp[N][2]; n string str; n long long n; n long long solve(long long pos, long long c) { n   if (pos >= n) return 0; n   if (dp[pos][c] != -1) return dp[pos][c]; n   long long x = n; n   if (c == 1) { n     x = solve(pos + 1, 1) + (str[pos] >  Z ); n     x = min(x, solve(pos + 1, 0) + (str[pos] <  a )); n   } else { n     x = min(x, solve(pos + 1, 0) + (str[pos] <  a )); n   } n   return dp[pos][c] = x; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   cin >> str; n   n = str.size(); n   cout << solve(0, 1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, u, v, a, b, A, B, C; n   A = B = C = 0; n   cin >> a >> b; n   for (i = 1; i <= 6; i++) { n     u = abs(i - a); n     v = abs(i - b); n     if (u < v) n       A++; n     else if (u == v) n       B++; n     else n       C++; n   } n   cout << A <<     << B <<     << C; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int n = 10000000; n bitset<n> b; n vector<int> v; n void sieve() { n   b.set(); n   b[0] = 0; n   b[1] = 0; n   for (long long i = 2; i <= n; i++) { n     if (b[i]) { n       v.push_back(i); n       for (long long j = i * i; j <= n; j = j + i) { n         b[j] = 0; n       } n     } n   } n } n bool large_prime(long long no) { n   if (no <= n) { n     if (b[no]) { n       return true; n     } else { n       return false; n     } n   } n   for (long long i = 0; v[i] * (long long)v[i] <= no; i++) { n     if (no % v[i] == 0) { n       return false; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   sieve(); n   long long a, b; n   while (t--) { n     cin >> a >> b; n     if (a - b == 1) { n       long long ans = (a - b) * (a + b); n       if (large_prime(ans)) { n         cout <<  YES  n              <<   n ; n       } else { n         cout <<  NO  n              <<   n ; n       } n     } else { n       cout <<  NO  n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n void checkmin(int &x, int y) { n   if (x > y) x = y; n } n void checkmax(int &x, int y) { n   if (x < y) x = y; n } n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c >  9  || c <  0 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) n     x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return x * f; n } n const int N = 20; n const int M = (1 << 20); n int n; n long long a[N], sum[M]; n int dp[M], vis[M], sz[M]; n signed main() { n   n = read(); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a[i]); n     if (!a[i]) n--, i--; n   } n   int full = (1 << n) - 1; n   for (int i = 0; i <= full; i++) n     for (int j = 0; j < n; j++) n       if (i >> j & 1) sum[i] += a[j], sz[i]++; n   for (int mask1 = 1; mask1 <= full; mask1++) { n     for (int mask2 = (mask1 - 1) & mask1; (mask2 << 1) >= mask1; n          mask2 = mask1 & (mask2 - 1)) { n       int mask3 = mask1 ^ mask2; n       long long tmp = abs(sum[mask2] - sum[mask3]); n       if (tmp < sz[mask1] && (sz[mask1] - tmp) & 1) { n         vis[mask1] = 1; n         break; n       } n     } n   } n   for (int i = 1; i <= full; i++) n     if (vis[i]) { n       int rest = full ^ i; n       checkmax(dp[i], 1); n       for (int j = rest; j; j = rest & (j - 1)) n         checkmax(dp[i | j], dp[j] + dp[i]); n     } n   int mx = 0; n   for (int mask = 1; mask <= full; mask++) checkmax(mx, dp[mask]); n   printf( %d n , n - mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long p = 1000000007; n char s[100005]; n long long w[100005]; n long long te[100005] = {1}; n void build() { n   for (int i = 1; i <= 100000; i++) { n     te[i] = (te[i - 1] * 10) % p; n   } n } n long long quick_mod(long long a, long long b) { n   long long ans = 1; n   a %= p; n   while (b) { n     if (b & 1) { n       ans = ans * a % p; n       b--; n     } n     b >>= 1; n     a = a * a % p; n   } n   return ans; n } n long long C(long long n, long long m) { n   if (m > n) return 0; n   long long ans = 1; n   for (int i = 1; i <= m; i++) { n     long long a = (n + i - m) % p; n     long long b = i % p; n     ans = ans * (a * quick_mod(b, p - 2) % p) % p; n   } n   return ans; n } n int main() { n   build(); n   long long n, k; n   scanf( %I64d%I64d , &n, &k); n   scanf( %s , s); n   long long ans = 0; n   w[n - 1] = C(n - 1, k); n   long long t = w[n - 1]; n   for (int i = n - 1; i >= 1; i--) { n     t = t * ((i - k) * quick_mod(i, p - 2) % p) % p; n     w[i - 1] = (w[i] + (te[n - i - 1] * t) % p * 9) % p; n   } n   for (int i = 0; i < n; i++) ans = (ans + w[i] * (s[i] -  0 )) % p; n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MAX = 1e6 + 5; n const int N = 2e5 + 5; n const long long int mod = 1e9 + 7; n const long long int mx = 1e16; n bool comp(const int a, const int b) { return a > b; } n const double PI = 2 * acos(0.0); n long long int fac[N]; n void pre() { n   fac[0] = 1LL; n   for (long long int i = 1; i < N; i++) { n     fac[i] = 1LL * i * fac[i - 1]; n     if (fac[i] >= mod) fac[i] %= mod; n   } n } n long long int power(long long int a, long long int b) { n   long long int x = 1; n   while (b) { n     if (b & 1) { n       x *= a; n       if (x >= mod) x %= mod; n     } n     a *= a; n     if (a >= mod) a %= mod; n     b >>= 1; n   } n   return x; n } n long long int inv(long long int k) { return power(k, mod - 2); } n string strngtoint(int n) { n   ostringstream str1; n   str1 << n; n   string ans = str1.str(); n   return ans; n } n bool fun(long long int z, long long int x, long long int y, long long int p, n          long long int q) { n   if (p * z >= x && q * z - p * z >= y - x) n     return true; n   else n     return false; n } n int main() { n   long long t; n   scanf( %lld n , &t); n   while (t--) { n     long long int x, y, p, q; n     scanf( %lld %lld %lld %lld , &x, &y, &p, &q); n     long long int low = -1, high = 1e9, mid; n     if (!fun(high, x, y, p, q)) { n       cout << -1 << endl; n       continue; n     } n     while (high - low > 1) { n       mid = (low + high) / 2; n       if (fun(mid, x, y, p, q)) { n         high = mid; n       } else { n         low = mid; n       } n     } n     cout << high * q - y << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int main() { n   char s1[15], s2[15], s3[15]; n   int p[15]; n   scanf( %s%s , s1, s2); n   int len = strlen(s1); n   int pos = 0; n   for (int i = 0; i < len; i++) { n     if (s1[i] ==  + ) n       pos++; n     else n       pos--; n   } n   int cnt = 0; n   for (int i = 0; i < len; i++) n     if (s2[i] ==  ? ) p[cnt++] = i; n   int m = 1 << cnt, ans = 0; n   for (int i = 0; i < m; i++) { n     int k = i, u = 0; n     strcpy(s3, s2); n     for (int j = 0; j < cnt; j++) { n       if (k & 1) n         s3[p[u]] =  + ; n       else n         s3[p[u]] =  - ; n       k >>= 1; n       u++; n     } n     int w = 0; n     for (int j = 0; j < len; j++) { n       if (s3[j] ==  + ) n         w++; n       else n         w--; n     } n     if (w == pos) ans++; n   } n   printf( %.12f n , ans * 1.0 / m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n string s; n int main() { n   cin >> s; n   int len = s.size(); n   int index7[20], index2[20], index5[20], index0[20]; n   int sum7 = 0, sum0 = 0, sum5 = 0, sum2 = 0; n   for (int i = 0; i < len; i++) { n     if (s[i] ==  5 ) { n       index5[sum5] = i; n       sum5++; n     } n     if (s[i] ==  0 ) { n       index0[sum0] = i; n       sum0++; n     } n     if (s[i] ==  7 ) { n       index7[sum7] = i; n       sum7++; n     } n     if (s[i] ==  2 ) { n       index2[sum2] = i; n       sum2++; n     } n   } n   int res = 1000; n   bool flag = false; n   if (sum0 >= 2) { n     flag = true; n     int temp = (len - 1 - index0[sum0 - 1]) + (len - 2 - index0[sum0 - 2]); n     res = min(res, temp); n   } n   if (sum0 > 0 && sum5 > 0) { n     flag = true; n     int temp = 0; n     if (index0[sum0 - 1] < index5[sum5 - 1]) { n       temp = ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0) + n              ((index0[sum0 - 1] <= len - 2) ? len - 2 - index0[sum0 - 1] : 0); n       temp++; n     } else { n       temp = ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0) + n              ((index0[sum0 - 1] <= len - 1) ? len - 1 - index0[sum0 - 1] : 0); n     } n     if (index5[sum5 - 1] == 0) { n       int i = 1; n       while (s[i] ==  0  && i < index0[sum0 - 1]) i++; n       temp += i - 1; n     } n     res = min(res, temp); n   } n   if (sum5 > 0 && sum2 > 0) { n     flag = true; n     int temp = 0; n     if (index5[sum5 - 1] < index2[sum2 - 1]) { n       temp = ((index2[sum2 - 1] <= len - 1) ? len - 1 - index2[sum2 - 1] : 0) + n              ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0); n       temp++; n     } else { n       temp = ((index2[sum2 - 1] <= len - 2) ? len - 2 - index2[sum2 - 1] : 0) + n              ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0); n     } n     if (index5[sum5 - 1] == 0 || index2[sum2 - 1] == 0) { n       int i = 1; n       while (s[i] ==  0 ) i++; n       temp += i - 1; n     } n     res = min(res, temp); n   } n   if (sum7 > 0 && sum5 > 0) { n     flag = true; n     int temp = 0; n     if (index5[sum5 - 1] < index7[sum7 - 1]) { n       temp = ((index7[sum7 - 1] <= len - 1) ? len - 1 - index7[sum7 - 1] : 0) + n              ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0); n       temp++; n     } else { n       temp = ((index7[sum7 - 1] <= len - 2) ? len - 2 - index7[sum7 - 1] : 0) + n              ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0); n     } n     if (index5[sum5 - 1] == 0 || index7[sum7 - 1] == 0) { n       int i = 1; n       while (s[i] ==  0 ) i++; n       temp += i - 1; n     } n     res = min(res, temp); n   } n   if (!flag) n     cout << -1 << endl; n   else n     cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, cnt, ans, tot; n unordered_map<long long, int> id; n int op[400010], d[400010], fa[400010], rk[400010], lg[400010], hs[400010]; n struct node { n   int u, v; n   long long h; n   void bb() { n     if (u > v) swap(u, v); n     h = (long long)u << 30 | v; n   } n } e[400010], g[400010]; n int getfa(int x) { return fa[x] == x ? x : getfa(fa[x]); } n void uni(int x, int y, int z) { n   x = getfa(x), y = getfa(y); n   if (rk[x] <= rk[y]) { n     fa[x] = y; n     lg[++tot] = x; n     hs[tot] = z; n     if (rk[x] == rk[y]) rk[y]++; n   } else { n     fa[y] = x; n     lg[++tot] = y; n     hs[tot] = z; n   } n } n void del(int x) { n   int i; n   for (i = tot; hs[i] != x; i--) { n     fa[lg[i]] = lg[i]; n   } n   fa[lg[i]] = lg[i]; n   int u = tot; n   tot = i - 1; n   for (i++; i <= u; i++) uni(g[hs[i]].u, g[hs[i]].v, hs[i]); n } n void solve(int be, int en) { n   for (int i = 1; i <= n; i++) fa[i] = i, rk[i] = 0; n   tot = 0; n   vector<int> v(cnt + 3), vv(cnt + 3); n   for (int i = 1; i < be; i++) n     if (op[i] == 1) v[d[i]] ^= 1; n   for (int i = be; i <= en; i++) n     if (op[i] == 1) vv[d[i]] = vv[d[i + m]] = 1; n   for (int i = 1; i <= cnt; i++) n     if (v[i] && !vv[i]) uni(g[i].u, g[i].v, i); n   for (int i = 1; i <= cnt; i++) n     if (v[i] && vv[i]) uni(g[i].u, g[i].v, i); n   for (int i = be; i <= en; i++) { n     if (ans) e[i] = e[i + m], d[i] = d[i + m]; n     if (op[i] == 1) { n       v[d[i]] ^= 1; n       if (v[d[i]]) n         uni(e[i].u, e[i].v, d[i]); n       else n         del(d[i]); n     } else { n       int x = getfa(e[i].u), y = getfa(e[i].v); n       if (x != y) n         putchar( 0 ), ans = 0; n       else n         putchar( 1 ), ans = 1; n     } n   } n } n int main(int argc, char const *argv[]) { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &op[i]); n     scanf( %d%d , &e[i].u, &e[i].v); n     e[i].bb(); n     op[i + m] = op[i]; n     e[i + m] = {e[i].u % n + 1, e[i].v % n + 1}; n     e[i + m].bb(); n   } n   for (int i = 1, tot = m * 2; i <= tot; i++) { n     long long t = e[i].h; n     if (!id[t]) id[t] = ++cnt, g[cnt] = e[i]; n     d[i] = id[t]; n   } n   int B = sqrt(m); n   for (int i = 1; i <= m; i += B) solve(i, min(i + B - 1, m)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int x; n int dfs(int xx, int yy, int cc) { n   if (cc == 0) { n     if (xx == 1 || yy == 1) { n       int tt = xx * yy; n       if (tt % 2 == 0) n         return tt / 2; n       else n         return tt / 2 + 1; n     } else n       return ((xx + yy) * 2 - 4) / 2; n   } n   if (xx <= 2 || yy <= 2) { n     if (cc >= 1) return 0; n     int k = xx * yy; n     if (k % 2 == 0) return k / 2; n     return k / 2 + 1; n   } n   int g = dfs(xx - 2, yy - 2, cc - 1); n   return g; n } n int main() { n   while (cin >> n >> m >> x) { n     int t = dfs(n, m, x - 1); n     cout << t << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1 << 28; n const long long LINF = 1ll << 61; n const long long mod = 1e9 + 7; n long long kissme(long long x, long long t) { n   long long ans = 1; n   while (t > 0) { n     if (t & 1) ans = ans * x % mod; n     x = x * x % mod; n     t >>= 1; n   } n   return ans; n } n struct number { n   int x, y; n   number(int _x = 0, int _y = 0) { n     x = _x; n     y = _y; n   } n   number operator+(number t) { n     return number((x + t.x) % mod, (y + t.y) % mod); n   } n   number operator-(number t) { n     return number((x - t.x + mod) % mod, (y - t.y + mod) % mod); n   } n   number operator*(number t) { n     return number((1ll * x * t.x + 1ll * y * t.y * 5) % mod, n                   (1ll * x * t.y + 1ll * y * t.x) % mod); n   } n   number operator*(int t) { n     return number((1ll * x * t) % mod, (1ll * y * t) % mod); n   } n   bool operator!=(number t) { return x != t.x || y != t.y; } n   number inv() { n     long long t = (1ll * x * x % mod - 5ll * y * y % mod + mod) % mod; n     t = kissme(t, mod - 2); n     return number(x * t % mod, (-y * t % mod + mod) % mod); n   } n   void operator=(int t) { n     x = t; n     y = 0; n   } n   number operator^(long long t) { n     number ret(1, 0), b = (*this); n     while (t > 0) { n       if (t & 1) ret = ret * b; n       b = b * b; n       t >>= 1; n     } n     return ret; n   } n   void out() { cout << x <<  ,  << y << endl; } n }; n number sigma(number x, long long l, long long r) { n   if (x.x == 1 && x.y == 0) n     return (r - l + 1) % mod; n   else n     return ((x ^ l) - (x ^ (r + 1))) * (number(1, 0) - x).inv(); n } n long long k, l, r; n long long dp[211]; n long long f[211], revf[211]; n long long C(long long x, long long y) { n   if (x < y) n     return 0; n   else n     return f[x] * revf[y] % mod * revf[x - y] % mod; n } n number A, B, pa[211], pb[211]; n int sign(long long n) { return n & 1 ? mod - 1 : 1; } n long long solve(long long l, long long r) { n   number c = 1, bs = number(0, kissme(5, mod - 2)); n   number sum; n   for (int i = 1; i <= k; i++) { n     c = c * bs; n     number tsum; n     for (int j = 0; j <= i; j++) { n       tsum = tsum + sigma(pa[j] * pb[i - j], l, r) * C(i, j) * sign(i - j); n     } n     tsum = tsum * c; n     sum = sum + tsum * dp[i]; n   } n   return sum.x; n } n int main() { n   f[0] = 1; n   for (int i = 1; i <= 205; i++) f[i] = f[i - 1] * i % mod; n   revf[205] = kissme(f[205], mod - 2); n   for (int i = 204; i >= 0; i--) revf[i] = revf[i + 1] * (i + 1) % mod; n   number A = number(1, 1) * kissme(2, mod - 2), B = number(1, 0) - A; n   pa[0] = 1; n   pb[0] = 1; n   for (int i = 1; i <= 205; i++) pa[i] = pa[i - 1] * A, pb[i] = pb[i - 1] * B; n   cin >> k >> l >> r; n   l += 2; n   r += 2; n   dp[1] = 1; n   long long fac = 1; n   for (int i = 1; i < k; i++) { n     fac = fac * (i + 1) % mod; n     for (int j = i; j >= 0; j--) { n       dp[j + 1] = (dp[j + 1] + dp[j]) % mod; n       dp[j] = dp[j] * (-i + mod) % mod; n     } n   } n   cout << solve(l, r) % mod * kissme(fac, mod - 2) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed 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   vector<int> cnt(200002, 0); n   for (int i = 0; i < n; i++) { n     cnt[a[i]]++; n   } n   int mx = 0; n   int res = 0; n   for (int i = 0; i < 200002; i++) { n     if (cnt[i] > mx) { n       mx = cnt[i]; n       res = i; n     } n   } n   int ind = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == res) { n       ind = i; n       break; n     } n   } n   cout << n - mx <<   n ; n   int ind1 = ind; n   while (ind1 > 0) { n     if (a[ind1 - 1] < res) { n       cout <<  1   << ind1 <<     << ind1 + 1 <<   n ; n     } n     if (a[ind1 - 1] > res) { n       cout <<  2   << ind1 <<     << ind1 + 1 <<   n ; n     } n     ind1--; n   } n   ind1 = ind; n   while (ind1 < n - 1) { n     if (a[ind1 + 1] < res) { n       cout <<  1   << ind1 + 2 <<     << ind1 + 1 <<   n ; n     } n     if (a[ind1 + 1] > res) { n       cout <<  2   << ind1 + 2 <<     << ind1 + 1 <<   n ; n     } n     ind1++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   istream& in = cin; n   int n; n   in >> n; n   vector<string> v; n   for (int i = 0; i < n; i++) { n     string str; n     in >> str; n     v.push_back(str); n   } n   set<char> use; n   map<char, set<char> > use2; n   for (int i = 0; i < n; i++) { n     char p, c; n     for (int j = 0; j < v[i].length(); j++) { n       c = v[i][j]; n       use.insert(c); n       if (j != 0) { n         use2[p].insert(c); n       } n       p = c; n     } n   } n   if (use.size() != 26) { n     for (char ch =  a ; ch <=  z ; ch++) { n       if (use.find(ch) == use.end()) { n         cout << ch << endl; n         break; n       } n     } n   } else { n     bool find = false; n     for (char c1 =  a ; c1 <=  z  && !find; c1++) { n       set<char> s = use2[c1]; n       for (char c2 =  a ; c2 <=  z  && !find; c2++) { n         if (s.find(c2) == s.end()) { n           cout << c1 << c2 << endl; n           find = true; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   bool f = 0; 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 ^ 48); n   if (f) x = -x; n } n template <typename F> n inline void write(F x, char ed =   n ) { n   static short st[30]; n   short tp = 0; n   if (x < 0) putchar( - ), x = -x; n   do st[++tp] = x % 10, x /= 10; n   while (x); n   while (tp) putchar( 0  | st[tp--]); n   putchar(ed); n } n template <typename T> n inline void Mx(T &x, T y) { n   x < y && (x = y); n } n template <typename T> n inline void Mn(T &x, T y) { n   x > y && (x = y); n } n const int N = 500050; n int c[N], col[N], f[N], fl; n struct node { n   int x, y; n   bool operator<(const node &i) const { n     return c[x] == c[i.x] ? c[y] < c[i.y] : c[x] < c[i.x]; n   } n } ed[N]; n int ne[N << 1], to[N << 1], h[N], tot, m, n, k; n inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; } n void dfs(int x, int &f2, int &f1) { n   if (col[x] == 1) { n     if (!f1) f1 = x; n     f[x] = f1; n   } n   if (col[x] == 2) { n     if (!f2) f2 = x; n     f[x] = f2; n   } n   for (int i = h[x]; i; i = ne[i]) { n     int y = to[i]; n     if (fl) return; n     if (col[y]) { n       if (col[y] != 3 - col[x]) { n         fl = 1; n         return; n       } n     } else n       col[y] = 3 - col[x], dfs(y, f2, f1); n   } n } n vector<int> v[N]; n int vis[N], cnt; n void check(int x, int tim) { n   vis[x] = tim; n   for (auto y : v[x]) { n     if (fl) return; n     if (vis[y] == tim) { n       if (col[y] != 3 - col[x]) { n         fl = 1; n         return; n       } n       continue; n     } n     col[y] = 3 - col[x]; n     check(y, tim); n   } n } n int ban[N]; n int main() { n   read(n), read(m), read(k); n   for (int i = 1; i <= n; i++) read(c[i]); n   for (int i = 1, x, y; i <= m; i++) { n     read(x), read(y); n     if (c[x] == c[y]) n       add(x, y), add(y, x); n     else { n       if (c[x] > c[y]) swap(x, y); n       ed[++cnt] = (node){x, y}; n     } n   } n   long long ans = k; n   for (int i = 1; i <= n; i++) f[i] = i; n   for (int i = 1; i <= n; i++) { n     if (!col[i] && !ban[c[i]]) { n       int f1 = 0, f2 = 0; n       col[i] = 1; n       fl = 0; n       dfs(i, f2, f1); n       if (fl) ban[c[i]] = 1, ans--; n       if (f1 && f2) { n         v[f1].push_back(f2), v[f2].push_back(f1); n       } n     } n   } n   sort(ed + 1, ed + cnt + 1); n   ans = ans * (ans - 1) / 2; n   int tim = 0; n   for (int l = 1, r = 1; l <= cnt; l = r + 1, r = l) { n     while (r <= cnt && c[ed[r + 1].x] == c[ed[l].x] && n            c[ed[r + 1].y] == c[ed[l].y]) n       r++; n     if (ban[c[ed[l].x]] || ban[c[ed[l].y]]) continue; n     for (int i = l; i <= r; i++) { n       int x = ed[i].x, y = ed[i].y; n       v[f[x]].push_back(f[y]), v[f[y]].push_back(f[x]); n     } n     tim++; n     for (int i = l; i <= r; i++) { n       int x = f[ed[i].x]; n       fl = 0; n       if (vis[x] != tim) col[x] = 1, check(x, tim); n       if (fl) break; n     } n     if (fl) ans--; n     for (int i = l; i <= r; i++) { n       int x = ed[i].x, y = ed[i].y; n       v[f[x]].pop_back(), v[f[y]].pop_back(); n     } n   } n   write(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int f = 1, x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) f = (ch ==  - ) ? -1 : 1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return f * x; n } n const int N = 500 + 5; n const int P = 1e9 + 7; n int n, m, len; n inline int add(int a, int b) { n   a += b; n   return a >= P ? a - P : a; n } n inline int mul(int a, int b) { return (unsigned long long)a * b % P; } n char s[N][N]; n int dp[2][N][N]; n int dx1[] = {0, 1}, dy1[] = {1, 0}; n int dx2[] = {0, -1}, dy2[] = {-1, 0}; n bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } n void solve_odd() { n   int u = 0, v = 1; n   dp[u][0][n - 1] = 1; n   len = (len + 1) >> 1; n   for (int i = (0); i < (len - 1); ++i) { n     u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u])); n     for (int j = (0); j < (n); ++j) n       for (int k = (0); k < (n); ++k) { n         int x1 = j, y1 = i - j; n         int x2 = k, y2 = m - 1 - (i - (n - 1 - x2)); n         if (ok(x1, y1) && ok(x2, y2)) { n           for (int p = (0); p < (2); ++p) n             for (int q = (0); q < (2); ++q) { n               int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p]; n               int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q]; n               if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) { n                 dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]); n               } n             } n         } n       } n   } n   int ans = 0; n   for (int i = (0); i < (n); ++i) ans = add(ans, dp[u][i][i]); n   cout << ans << endl; n } n void solve_even() { n   int u = 0, v = 1; n   dp[u][0][n - 1] = 1; n   len = (len) >> 1; n   for (int i = (0); i < (len - 1); ++i) { n     u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u])); n     for (int j = (0); j < (n); ++j) n       for (int k = (0); k < (n); ++k) { n         int x1 = j, y1 = i - j; n         int x2 = k, y2 = m - 1 - (i - (n - 1 - x2)); n         if (ok(x1, y1) && ok(x2, y2)) { n           for (int p = (0); p < (2); ++p) n             for (int q = (0); q < (2); ++q) { n               int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p]; n               int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q]; n               if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) { n                 dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]); n               } n             } n         } n       } n   } n   int ans = 0; n   for (int i = (0); i < (n); ++i) n     ans = add(ans, add(dp[u][i][i], dp[u][i][i + 1])); n   cout << ans << endl; n } n int main() { n   n = read(), m = read(); n   for (int i = (0); i < (n); ++i) scanf( %s , s[i]); n   if (s[0][0] != s[n - 1][m - 1]) { n     puts( 0 ); n     return 0; n   } n   len = n + m - 1; n   if (len & 1) n     solve_odd(); n   else n     solve_even(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int gotcha() { n   int a = 0, b = 1, c = getchar(); n   while (!isdigit(c)) b ^= c ==  - , c = getchar(); n   while (isdigit(c)) a = a * 10 + c - 48, c = getchar(); n   return b ? a : -a; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   map<int, int> mp; n   int n; n   scanf( %d , &n); n   int b, i, index = 0, j; n   for (i = 1; i <= n; i++) { n     scanf( %d , &b); n     mp[b] = i; n   } n   for (i = 0; i < n; i++) { n     b = gotcha(); n     if (mp[b] - index > 0) { n       printf( %d  , mp[b] - index); n       index = mp[b]; n     } else n       printf( 0  ); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int maxn = 1e5 + 5; n vector<int> a[maxn]; n vector<int> ans[maxn]; n int n, m, cas = 0; n void change2(int t) { n   ans[t].resize(m + 1); n   ans[t + 1].resize(m + 1); n   for (int i = 1; i <= m; ++i) { n     if (i & 1) n       ans[t][i] = a[t][i]; n     else n       ans[t + 1][i] = a[t][i]; n   } n   ans[t][2] = a[t + 1][m]; n   ans[t + 1][1] = a[t + 1][m - 1]; n   for (int i = 3; i <= m; ++i) { n     if (i & 1) n       ans[t + 1][i] = a[t + 1][i - 2]; n     else n       ans[t][i] = a[t + 1][i - 2]; n   } n } n void change3(int t) { n   ans[t].resize(m + 1); n   ans[t + 1].resize(m + 1); n   ans[t + 2].resize(m + 1); n   for (int i = 1; i <= m; ++i) { n     if (i & 1) n       ans[t][i] = a[t][i]; n     else n       ans[t + 2][i] = a[t][i]; n   } n   ans[t][2] = a[t + 1][m]; n   ans[t + 1][1] = a[t + 1][m - 1]; n   for (int i = 3; i <= m; ++i) { n     if (i & 1) n       ans[t + 1][i] = a[t + 1][i - 2]; n     else n       ans[t][i] = a[t + 1][i - 2]; n   } n   for (int i = 1; i <= m; ++i) { n     if (i & 1) n       ans[t + 2][i] = a[t + 2][i]; n     else n       ans[t + 1][i] = a[t + 2][i]; n   } n } n void change1(int t) { n   ans[t].push_back(123); n   for (int i = 1; i <= m; ++i) { n     if ((i & 1) == cas) ans[t].push_back(a[t][i]); n   } n   for (int i = 1; i <= m; ++i) { n     if ((i & 1) == (cas ^ 1)) ans[t].push_back(a[t][i]); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int i, j, k; n   cin >> n >> m; n   if (n == 3 && m == 3) { n     cout <<  YES  << endl; n     cout <<  1 8 3  << endl; n     cout <<  9 2 4  << endl; n     cout <<  5 7 6  << endl; n     return 0; n   } n   if (n == 1 && m == 1) { n     cout <<  YES  << endl; n     cout <<  1  << endl; n     return 0; n   } n   if (n <= 2 && m <= 2) { n     cout <<  NO  << endl; n     return 0; n   } n   if ((n == 1 && m <= 3) || (m == 1 && n == 3) || n       (n + m == 5 && n != 1 && m != 1)) { n     cout <<  NO  << endl; n     return 0; n   } n   if (n <= m) { n     for (int i = 1; i <= n; ++i) { n       a[i].push_back(123); n       for (int j = 1; j <= m; ++j) a[i].push_back((i - 1) * m + j); n     } n     if (n != 1) { n       if (n % 2 == 0) { n         for (int i = 1; i <= n; i += 2) change2(i); n       } else { n         for (int i = 1; i <= n - 3; i += 2) change2(i); n         change3(n - 2); n       } n     } else n       change1(1); n     cout <<  YES  << endl; n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) cout << ans[i][j] <<    ; n       cout << endl; n     } n   } else { n     int cnt = 1; n     swap(m, n); n     for (int i = 1; i <= n; ++i) a[i].push_back(23); n     for (int i = 1; i <= m; ++i) n       for (int j = 1; j <= n; ++j) a[j].push_back(cnt++); n     if (n != 1) { n       if (n % 2 == 0) { n         for (int i = 1; i <= n; i += 2) change2(i); n       } else { n         for (int i = 1; i <= n - 3; i += 2) change2(i); n         change3(n - 2); n       } n     } else n       change1(1); n     cout <<  YES  << endl; n     for (int i = 1; i <= m; ++i) { n       for (int j = 1; j <= n; ++j) cout << ans[j][i] <<    ; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, k, u = 0, ans1 = 0, ans2 = 0; n   cin >> n >> m >> k; n   bool a[n][m]; n   long long sum[n + 2][m]; n   memset(sum, 0, sizeof(sum)); n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       cin >> a[i][j]; n       sum[i][j] = (i ? sum[i - 1][j] : 0) + a[i][j]; n       if (i >= k) sum[i][j] -= a[u][j]; n       if (sum[i][j] > sum[n][j]) { n         sum[n][j] = sum[i][j]; n         sum[n + 1][j] = i - k + 1; n       } n     } n     u += (i >= k); n   } n   for (long long j = 0; j < m; j++) { n     ans1 += sum[n][j]; n     for (long long i = 0; i < sum[n + 1][j]; i++) ans2 += a[i][j]; n   } n   cout << ans1 <<     << ans2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct ii { n   string zl; n   int x, id; n } zl[1000005]; n bool cmp1(ii a, ii b) { n   if (a.x < b.x) return 1; n   if (a.x > b.x) return 0; n   return a.zl < b.zl; n } n bool cmp2(ii a, ii b) { return a.id < b.id; } n int n, cnt, zhi[1000005], sz[1000005], i; n long long sum[1000005][5], ans; n map<int, int> mp; n void update(int id, int le, int ri, int pos) { n   sz[id]++; n   if (le == pos && ri == pos) { n     sum[id][1] += zhi[pos]; n     return; n   } n   if (pos > (le + ri) / 2) n     update(id * 2 + 1, (le + ri) / 2 + 1, ri, pos); n   else n     update(id * 2, le, (le + ri) / 2, pos); n   int i; n   for (i = 0; i < 5; i++) { n     sum[id][i] = n         sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5]; n   } n } n void erase(int id, int le, int ri, int pos) { n   sz[id]--; n   if (le == pos && ri == pos) { n     sum[id][1] -= zhi[pos]; n     return; n   } n   if (pos > (le + ri) / 2) n     erase(id * 2 + 1, (le + ri) / 2 + 1, ri, pos); n   else n     erase(id * 2, le, (le + ri) / 2, pos); n   int i; n   for (i = 0; i < 5; i++) { n     sum[id][i] = n         sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5]; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> zl[i].zl; n     if (zl[i].zl[0] ==  s ) n       zl[i].x = 0; n     else n       cin >> zl[i].x; n     zl[i].id = i; n   } n   sort(zl + 1, zl + n + 1, cmp1); n   cnt = 1; n   for (i = 1; i <= n; i++) { n     if (zl[i].zl[0] ==  a ) { n       if (!mp[zl[i].x]) mp[zl[i].x] = cnt++; n       zhi[mp[zl[i].x]] = zl[i].x; n       zl[i].x = mp[zl[i].x]; n     } else if (zl[i].zl[0] ==  d ) { n       zl[i].x = mp[zl[i].x]; n     } n   } n   sort(zl + 1, zl + n + 1, cmp2); n   for (i = 1; i <= n; i++) { n     if (zl[i].zl ==  add ) update(1, 1, cnt, zl[i].x); n     if (zl[i].zl ==  del ) erase(1, 1, cnt, zl[i].x); n     if (zl[i].zl ==  sum ) cout << sum[1][3] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int primes[10001]; n int p[10001]; n int numbers[10001]; n int cnt; n void sieve() { n   for (int a = 2; a <= 10000; ++a) n     if (primes[a] == 0) n       for (int b = 2; b * a <= 10000; b++) primes[a * b] = 1; n   int c = 0; n   for (int a = 2; a <= 10001; ++a) n     if (primes[a] == 0) { n       p[c] = a; n       c++; n     } n   cnt = 0; n   for (int a = 1; a < c; ++a) { n     if (primes[p[a] + p[a - 1] + 1] == 0) { n       numbers[cnt] = p[a] + p[a - 1] + 1; n       cnt++; n     } n   } n } n int main() { n   sieve(); n   int n, k; n   cin >> n >> k; n   if (lower_bound(numbers, numbers + cnt, n) - numbers >= k - 1) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, m; n   int i = 0, tmp; n   int P, Q; n   cin >> n >> m; n   i = n; n   cin >> P; n   while (i--) { n     cin >> tmp; n   } n   cin >> Q; n   i = m; n   while (i--) { n     cin >> tmp; n   } n   int sm = 1, sn = 1; n   if (P < 0) sn = -1; n   if (Q < 0) sm = -1; n   if (m == n) { n     if (sm * sn < 0) cout <<  - ; n     P = (P < 0) ? -P : P; n     Q = (Q < 0) ? -Q : Q; n     int a = P, b = Q; n     while (b) { n       if (a > b) n         a -= b; n       else n         b -= a; n     } n     P /= a; n     Q /= a; n     if (m >= 0) cout << P <<  /  << Q << endl; n   } else { n     if (n < m) n       cout <<  0/1  << endl; n     else { n       if (sm * sn < 0) cout <<  - ; n       cout <<  Infinity  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int A = 1e7 + 10; n const int B = 1e6 + 10; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n inline int read() { n   char c = getchar(); n   int x = 0, f = 1; n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); n   return x * f; n } n struct node { n   int v, nxt, w, kkk; n } e[B]; n int cnt, in[B], id[B], cg[B], k = 0, n, m, head[B]; n void modify(int u, int v, int w, int kkk) { n   e[++cnt].nxt = head[u]; n   e[cnt].w = w; n   e[cnt].v = v; n   e[cnt].kkk = kkk; n   head[u] = cnt; n } n queue<int> q; n bool check(int mid) { n   int kc = 0; n   memset(in, 0, sizeof(in)); n   memset(id, 0, sizeof(id)); n   for (int i = 1; i <= n; i++) { n     for (int j = head[i]; j; j = e[j].nxt) { n       int v = e[j].v, w = e[j].w; n       if (w <= mid) continue; n       ++in[v]; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!in[i]) { n       q.push(i); n     } n   } n   int js = 0; n   while (!q.empty()) { n     int now = q.front(); n     id[now] = ++kc; n     js++; n     q.pop(); n     for (int i = head[now]; i; i = e[i].nxt) { n       int v = e[i].v, w = e[i].w; n       if (w <= mid) continue; n       --in[v]; n       if (!in[v]) q.push(v); n     } n   } n   if (js != n) return 0; n   k = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = head[i]; j; j = e[j].nxt) { n       if (e[j].w > mid) continue; n       int v = e[j].v; n       if (id[v] < id[i]) { n         cg[++k] = e[j].kkk; n       } n     } n   } n   return 1; n } n int main() { n   n = read(), m = read(); n   int r = 0; n   for (int i = 1; i <= m; i++) { n     int u = read(), v = read(), w = read(); n     modify(u, v, w, i); n     r = max(r, w); n   } n   int l = 0, ans = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) { n       r = mid - 1; n       ans = mid; n     } else n       l = mid + 1; n   } n   sort(cg + 1, cg + k + 1); n   printf( %d %d n , ans, k); n   for (int i = 1; i <= k; i++) printf( %d  , cg[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007LL; n long long large = 2000000000000000000LL; n bitset<20011> vis; n vector<int> primes; n void sieve(long long n) { n   vis.set(); n   vis[0] = 0; n   vis[1] = 0; n   for (long long i = 2; i <= n; i++) { n     if (vis[i]) primes.push_back((int)i); n     for (int j = 0; j < (int)primes.size() && i * primes[j] <= n; j++) { n       vis[i * primes[j]] = 0; n       if (i % primes[j] == 0) break; n     } n   } n } n int main() { n   int n; n   unsigned int a, b, c, d; n   cin >> n >> a >> b >> c >> d; n   sieve(20010); n   unsigned int ans = 0; n   int sq = 20000; n   int p = 2; n   while (p < n + 1) { n     int l = p; n     int r = min(l + sq, n + 1); n     int sz = r - l; n     vector<bool> vis(sz, true); n     for (int i = 0; i < (int)primes.size(); i++) { n       int x = primes[i]; n       int y = l; n       y = max(y, 2 * x); n       y = ((y - 1) / x + 1) * x; n       while (y < r) { n         vis[y - l] = false; n         y += x; n       } n     } n     for (int i = 0; i < sz; i++) { n       if (vis[i]) { n         unsigned int x = i + l; n         if (x < 2) continue; n         unsigned int temp = a * x * x * x + b * x * x + c * x + d; n         unsigned int d = x; n         while (n / d) { n           ans += temp * (n / d); n           if (n / x < d) break; n           d *= x; n         } n       } n     } n     p += sq; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n; n int a[N]; n int f[N]; n int sumf[N]; n long long sum; n long long best; n vector<int> freq; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     f[a[i]]++; n     sum += a[i]; n   } n   if (f[1]) { n     printf( %lld n , sum); n     return 0; n   } n   for (int i = 2; i < N; i++) { n     if (f[i]) freq.push_back(i); n     sumf[i] = f[i] + sumf[i - 1]; n   } n   for (int i = 0; i < freq.size(); i++) { n     int leading = freq[i]; n     long long total = 0; n     for (int j = leading; j < N; j += leading) { n       total += 1ll * (sumf[min(j + leading - 1, N - 1)] - sumf[j - 1]) * j; n     } n     best = max(best, total); n   } n   printf( %lld n , best); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n struct par { n   ll l; n   ll r; n }; n int n; n ll s; n par mas[200100]; n bool cmp(par a, par b) { return (a.l < b.l); } n bool good(ll m) { n   vector<par> grp1; n   vector<par> grp2; n   vector<par> grp3; n   for (int i = 0; i < n; i++) { n     if (mas[i].r < m) n       grp1.push_back(mas[i]); n     else if (m <= mas[i].l) n       grp2.push_back(mas[i]); n     else n       grp3.push_back(mas[i]); n   } n   int rem = max(0, (n + 1) / 2 - (int)grp2.size()); n   if (rem > grp3.size()) return false; n   ll sum = 0; n   for (auto el : grp1) sum += el.l; n   for (auto el : grp2) sum += el.l; n   if (grp3.size() > 0) sort(grp3.begin(), grp3.end(), cmp); n   for (int i = 1; i <= rem; i++) sum += m; n   for (int i = 0; i < grp3.size() - rem; i++) sum += grp3[i].l; n   return (sum <= s); n } n ll bin_s() { n   ll l = 1, r = 1e9; n   ll m; n   while (l < r) { n     m = (l + r + 1) / 2; n     if (good(m)) n       l = m; n     else n       r = m - 1; n   } n   return l; n } n void solve() { n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     cin >> mas[i].l >> mas[i].r; n   } n   ll med = bin_s(); n   cout << med <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7, siz = 1e6 + 5; n long long t, n, m, k, a[siz], dp[5002][5002], dp2[5002]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     string s; n     cin >> s; n     s =  0  + s; n     for (long long i = 1; i <= n + 1; i++) n       for (long long j = i + 1; j <= n + 1; j++) dp[i][j] = 0; n     for (long long i = n; i >= 1; i--) { n       for (long long j = i - 1; j >= 1; j--) { n         if (s[i] == s[j]) { n           dp[j][i] = 1 + dp[j + 1][i + 1]; n         } n       } n     } n     long long ans = 0; n     for (long long i = 1; i <= n; i++) { n       dp2[i] = n - i + 1; n       for (long long j = 1; j < i; j++) { n         if (s[i] > s[j]) n           dp2[i] = max(dp2[j] + n - i + 1, dp2[i]); n         else if (s[i] == s[j]) { n           if (s[i + dp[j][i]] > s[j + dp[j][i]]) { n             dp2[i] = max(dp2[i], dp2[j] + n - (i + dp[j][i]) + 1); n           } n         } n       } n       ans = max(ans, dp2[i]); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n double mod(double a, double b) { n   long long int val = a / b; n   return a - val * b; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   double a, b, m, vx, vy, vz; n   cin >> a >> b >> m >> vx >> vy >> vz; n   double sx, sy, sz, t, x0, y0; n   t = -m / vy; n   sx = abs(vx * t); n   sz = vz * t; n   long long int val; n   if (sx > (3 * a) / 2) { n     sx -= (3 * a) / 2; n     val = sx / (a); n     if (val % 2 == 0) n       x0 = mod(sx, a); n     else n       x0 = a - mod(sx, a); n   } else if (sx <= a / 2) n     x0 = a / 2 + sx; n   else n     x0 = a - (sx - a / 2); n   if (vx < 0) x0 = a - x0; n   val = sz / (b); n   if (val % 2 == 0) n     y0 = mod(sz, b); n   else n     y0 = b - mod(sz, b); n   cout << fixed << setprecision(10) << x0 <<     << y0; n } n


#include <bits/stdc++.h> n using namespace std; n char F1[2000000]; n char F2[2000000]; n void computeLPSArray(string pat, int M, int* lps); n void KMPSearch(string pat, string txt, vector<int>& st, vector<int>& end) { n   int M = pat.size(); n   int N = txt.size(); n   int lps[M]; n   computeLPSArray(pat, M, lps); n   int i = 0; n   int j = 0; n   while (i < N) { n     if (pat[j] == txt[i]) { n       j++; n       i++; n     } n     if (j == M) { n       end.push_back(i - 1); n       st.push_back(i - M); n       j = lps[j - 1]; n     } else if (i < N && pat[j] != txt[i]) { n       if (j != 0) n         j = lps[j - 1]; n       else n         i = i + 1; n     } n   } n } n void computeLPSArray(string pat, int M, int* lps) { n   int len = 0; n   lps[0] = 0; n   int i = 1; n   while (i < M) { n     if (pat[i] == pat[len]) { n       len++; n       lps[i] = len; n       i++; n     } else { n       if (len != 0) { n         len = lps[len - 1]; n       } else { n         lps[i] = 0; n         i++; n       } n     } n   } n } n long long int Stoi(string s) { n   long long int ans = 0; n   for (int i = 0; i < s.size(); i++) ans = ans * 10 + s[i] -  0 ; n   return ans; n } n string itos(long long int num) { n   if (num == 0) return  0 ; n   string ans =   ; n   while (num) { n     int digit = num % 10; n     char ch =  0  + digit; n     ans = ch + ans; n     num = num / 10; n   } n   return ans; n } n long long int numBefore(int i, string& s) { n   int indx = i - 1; n   while (s[indx] >=  0  && s[indx] <=  9  && indx >= 0) indx--; n   indx++; n   int len = i - indx; n   long long int num = Stoi(s.substr(indx, len)); n   return num; n } n int charAfter(int i, string& s) { n   if (i == s.size() - 1) return -1; n   int indx = i + 1; n   while (s[indx] >=  0  && s[indx] <=  9  && indx >= 0) indx++; n   return indx; n } n int main() { n   int m, n; n   cin >> n >> m; n   long long int prevFreq = 0; n   char prevCh =  Q ; n   string Final =   ; n   int ptr1 = 0, ptr2 = 0; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     int size = s.size(); n     int indx = size - 2; n     ; n     string num1 = s.substr(0, indx); n     long long int frq = Stoi(num1); n     char Chr = s[indx + 1]; n     if (Chr == prevCh) n       prevFreq += frq; n     else { n       if (prevCh !=  Q ) { n         string s1 = itos(prevFreq) + prevCh; n         for (int i = 0; i < s1.size(); i++) { n           F1[ptr1] = s1[i]; n           ptr1++; n         } n       } n       prevFreq = frq; n       prevCh = Chr; n     } n   } n   string s1 = itos(prevFreq) + prevCh; n   for (int i = 0; i < s1.size(); i++) { n     F1[ptr1] = s1[i]; n     ptr1++; n   } n   F1[ptr1] = 0; n   Final = F1; n   prevFreq = 0; n   prevCh =  Q ; n   string Final2 =   ; n   for (int i = 0; i < m; i++) { n     string s; n     cin >> s; n     int indx = s.find( - ); n     string num1 = s.substr(0, indx); n     long long int frq = Stoi(num1); n     char Chr = s[indx + 1]; n     if (Chr == prevCh) n       prevFreq += frq; n     else { n       if (prevCh !=  Q ) { n         string s2 = itos(prevFreq) + prevCh; n         for (int i = 0; i < s2.size(); i++) { n           F2[ptr2] = s2[i]; n           ptr2++; n         } n       } n       prevFreq = frq; n       prevCh = Chr; n     } n   } n   string s2 = itos(prevFreq) + prevCh; n   for (int i = 0; i < s2.size(); i++) { n     F2[ptr2] = s2[i]; n     ptr2++; n   } n   Final2 = F2; n   vector<int> st, end; n   int indx = 0; n   int indx2 = Final2.size() - 2; n   while (Final2[indx] >=  0  && Final2[indx] <=  9 ) indx++; n   while (indx2 >= 0 && Final2[indx2] >=  0  && Final2[indx2] <=  9 ) indx2--; n   long long int ans = 0; n   if (indx2 >= 0) { n     string toSrch = Final2.substr(indx, indx2 - indx + 1); n     KMPSearch(toSrch, Final, st, end); n     for (int i = 0; i < st.size(); i++) { n       long long int Aval = numBefore(st[i], Final); n       long long int Req = numBefore(indx, Final2); n       int i2 = charAfter(end[i], Final); n       int i3 = charAfter(indx2, Final2); n       if (i2 >= 0 && i3 >= 0 && Final2[i3] == Final[i2]) { n         long long int Aval2 = numBefore(i2, Final); n         long long int Req2 = numBefore(i3, Final2); n         if (Aval >= Req && Aval2 >= Req2) ans++; n       } n     } n   } else { n     char ch = Final2[Final2.size() - 1]; n     for (int i = 0; i < Final.size(); i++) { n       if (Final[i] == ch) { n         long long int Aval = numBefore(i, Final); n         long long int Req = numBefore(Final2.size() - 1, Final2); n         if (Aval >= Req) ans = ans + (Aval - Req + 1); n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void Fast() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n inline int RD() { n   int i; n   cin >> i; n   return i; n } n inline float RF() { n   float i; n   cin >> i; n   return i; n } n inline double RDO() { n   double i; n   cin >> i; n   return i; n } n inline string RS() { n   string i; n   cin >> i; n   return i; n } n inline long long Rll() { n   long long i; n   cin >> i; n   return i; n } n inline bool super(long long n) { n   int x4 = 0, x7 = 0; n   while (n != 0) { n     int x = n % 10; n     if (x == 7) n       x7++; n     else n       x4++; n     n /= 10; n   } n   return (x4 == x7) ? true : false; n } n int A1[1000]; n int arr[200004]; n int main() { n   Fast(); n   int n = RD(), k = RD(); n   string t = RS(); n   int x = 0; n   for (int i = 1; i < t.size(); i++) { n     if (t.substr(i) == t.substr(0, t.size() - i)) { n       x = n - i; n       break; n     } n   } n   cout << t; n   for (int i = 0; i < k - 1; i++) cout << t.substr(x); n } n


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


#include <bits/stdc++.h> n using namespace std; n double t, k, d, start = 0, sum = 0; n int main() { n   scanf( %lf%lf%lf , &k, &d, &t); n   if ((long long)k % (long long)d == 0) n     printf( %.1f n , t); n   else if (k >= t) n     printf( %.1f n , t); n   else { n     if (k > d) { n       long long a = k / d; n       d *= a + 1; n     } n     long long x = (long long)t / (k + (d - k) / 2); n     start = (double)x * d; n     sum = (double)x * (k + (d - k) / 2); n     sum = t - sum; n     if (sum > k) n       start += k + (sum - k) * 2; n     else n       start += sum; n     printf( %.9f n , start); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, i, dx, dy, y; n int main() { n   scanf( %d %d , &N, &M); n   if ((N == 5 || N == 6) && M == 3) { n     printf( -1 n ); n     return 0; n   } n   dx = 9; n   dy = 5; n   y = 0; n   for (i = 0; i < M; i++) { n     printf( %d %d n , dx * i, y); n     y += dy * (i + 1); n   } n   y = 0; n   for (i = 0; i < N - M; i++) { n     printf( %d %d n , 10000000 - dx * i, y); n     y += dy * (i + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pos[11], neg[11], n, x, zero; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (x == 0) zero++; n     if (x > 0) pos[x]++; n     if (x < 0) neg[abs(x)]++; n   } n   long long cnt = 0; n   cnt += zero * (zero - 1) / 2; n   for (int i = 1; i <= 10; i++) cnt += (pos[i] * neg[i]); n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(const pair<int, pair<int, int>> a, const pair<int, pair<int, int>> b) { n   if (a.first == b.first) { n     return a.second.first > b.second.first; n   } else { n     return a.first < b.first; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   vector<int> be(n); n   vector<int> en(n); n   for (int i = 0; i < n; i++) { n     cin >> be[i] >> en[i]; n   } n   int L = 0; n   int R = 1e9 + 1e9 + 5; n   while (R - L > 1) { n     int mid = L + (R - L) / 2; n     vector<pair<int, pair<int, int>>> even; n     for (int i = 0; i < n; i++) { n       long long nooow = (long long)en[i] - mid + 1; n       if (be[i] <= nooow) { n         even.push_back({be[i], {1, 0}}); n         even.push_back({nooow, {-1, 0}}); n       } n     } n     sort(even.begin(), even.end(), cmp); n     int bal = 0; n     bool good = false; n     for (int i = 0; i < even.size(); i++) { n       bal += even[i].second.first; n       if (bal >= k) { n         good = true; n       } n     } n     if (good) { n       L = mid; n     } else { n       R = mid; n     } n   } n   vector<pair<int, pair<int, int>>> even; n   for (int i = 0; i < n; i++) { n     long long nooow = (long long)en[i] - L + 1; n     if (be[i] <= nooow) { n       even.push_back({be[i], {1, i}}); n       even.push_back({nooow, {-1, i}}); n     } n   } n   sort(even.begin(), even.end(), cmp); n   vector<int> ans; n   ans.push_back(1); n   int ind = 0; n   for (int i = 1; i < even.size(); i++) { n     if (even[i].second.first == 1) { n       ans.push_back(ans[i - 1] + 1); n     } else { n       ans.push_back(ans[i - 1] - 1); n     } n     if (ans[i] == k) { n       ind = i; n       break; n     } n   } n   if (L == 0) { n     cout << 0 << endl; n     for (int i = 0; i < k; i++) { n       cout << i + 1 <<    ; n     } n   } else { n     cout << L << endl; n     set<int> answer; n     for (int i = 0; i <= ind; i++) { n       if (even[i].second.first == 1) { n         answer.insert(even[i].second.second); n       } else { n         answer.erase(even[i].second.second); n       } n     } n     for (set<int>::iterator it = answer.begin(); it != answer.end(); it++) { n       cout << *it + 1 <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, k, i, st = 0, cnt = 0; n   scanf( %d %d , &n, &k); n   int a[n]; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 0; i < n && k > 0; i++) { n     if (a[i] <= 8) { n       k -= a[i], cnt++; n       if (st > 0 && st <= (8 - a[i])) n         k -= st, st = 0; n       else if (st > 0 && st > (8 - a[i])) n         k -= (8 - a[i]), st -= (8 - a[i]); n     } else { n       k -= 8; n       st += (a[i] - 8); n       cnt++; n     } n   } n   if (k > 0) n     printf( -1 ); n   else n     printf( %d , cnt); n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int id; n   int u, v, w; n } edges[100005]; n int n, m; n int d[100005], cost[100005]; n bool path[100005]; n vector<Edge> G[100005], ans; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     edges[i].u = u, edges[i].v = v, edges[i].w = w, edges[i].id = i; n     G[u].push_back(edges[i]); n     G[v].push_back(edges[i]); n   } n   d[1] = 0; n   cost[1] = 0; n   queue<int> que; n   que.push(1); n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (size_t i = 0; i < G[u].size(); i++) { n       Edge e = G[u][i]; n       int v = e.u; n       if (v == u) v = e.v; n       if (v != 1 && d[v] == 0) { n         d[v] = d[u] + 1; n         que.push(v); n       } n       if (d[v] == d[u] + 1) cost[v] = max(cost[v], cost[u] + e.w); n     } n   } n   int u = n; n   while (d[u] != 0) { n     for (size_t i = 0; i < G[u].size(); i++) { n       Edge e = G[u][i]; n       int v = e.u; n       if (v == u) v = e.v; n       if (d[v] != d[u] - 1) continue; n       if ((e.w == 1 && cost[v] == cost[u] - 1) || n           (e.w == 0 && cost[v] == cost[u])) { n         path[e.id] = true; n         u = v; n         break; n       } n     } n   } n   for (int ind = 0; ind < m; ind++) { n     if (path[ind] && edges[ind].w == 0) { n       ans.push_back(edges[ind]); n     } else if (!path[ind] && edges[ind].w == 1) { n       ans.push_back(edges[ind]); n     } n   } n   cout << ans.size() << endl; n   for (vector<Edge>::iterator it = ans.begin(); it != ans.end(); ++it) { n     cout << it->u <<     << it->v <<     << (it->w ^ 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9, MOD = INF + 7; n long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); } n long long power(long long a, long long b) { n   return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); n } n long long mod(long long a) { return (a % MOD + MOD) % MOD; } n const long long N = 1e6 + 20; n vector<long long> g[N]; n long long mark[N]; n vector<pair<long long, pair<long long, long long> > > ans; n bool dfs(long long v, long long par = 0) { n   mark[v] = 1; n   long long tmp = 0; n   for (long long u : g[v]) { n     if (u == par || mark[u] == 2) continue; n     if (mark[u] == 0 && dfs(u, v)) continue; n     if (tmp == 0) n       tmp = u; n     else n       ans.push_back(make_pair(v, make_pair(u, tmp))), tmp = 0; n   } n   mark[v] = 2; n   if (tmp != 0 && par != 0) ans.push_back(make_pair(v, make_pair(tmp, par))); n   return tmp; n } n int32_t main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long n, m; n   cin >> n >> m; n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (long long i = 1; i <= n; i++) n     if (mark[i] == 0) dfs(i); n   cout << ans.size() <<   n ; n   for (auto p : ans) n     cout << p.second.first <<     << p.first <<     << p.second.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long n, m; n   scanf( %ld %ld , &n, &m); n   std::vector<long> a(n + 2, 0); n   a[n + 1] = m; n   for (long p = 1; p <= n; p++) { n     scanf( %ld , &a[p]); n   } n   long orig(0), off(0), mx(0); n   for (long p = n; p >= 0; p--) { n     if (p % 2) { n       off += a[p + 1] - a[p]; n     } else { n       orig += a[p + 1] - a[p]; n     } n     mx = (mx > off - orig) ? mx : (off - orig); n   } n   printf( %ld n , orig + (mx > 0) * (mx - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int k = (n + 1) / 2; n   vector<int> A(k); n   for (int& a : A) scanf( %d , &a); n   int x; n   scanf( %d , &x); n   A.resize(n, x); n   long long sum = accumulate(begin(A), begin(A) + k, 0LL); n   long long min_sum = sum; n   int res = -1; n   for (long long i = k, s = 1LL * x * (n - k); i < n; ++i, s -= x) { n     if (min_sum + s > 0) { n       res = n + k - i; n       break; n     } n     sum += A[i] - A[i - k]; n     min_sum = min(min_sum, sum); n   } n   if (res == -1 && min_sum > 0) res = k; n   printf( %d n , res); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void smn(T &a, const T &b) { n   if (b < a) a = b; n } n template <class T> n inline void smx(T &a, const T &b) { n   if (b > a) a = b; n } n template <class T> n inline T rev(const T &a) { n   T _ = a; n   reverse(_.begin(), _.end()); n   return _; n } n const double eps = 1e-9; n const long double leps = 1e-14; n const int MN = 5000 + 100, MOD = 1000 * 1000 * 1000 + 7; n vector<int> dis; n int n; n int dt[MN][MN]; n pair<int, int> point[MN]; n int mk = 1, now; n int mark[MN]; n int v[MN]; n int d(pair<int, int> a, pair<int, int> b) { n   return abs(a.first - b.first) + abs(a.second - b.second); n } n void dfs(int a) { n   mark[a] = mk; n   for (int i = 0; i < n; i++) n     if (dt[a][i] > now && mark[i] != mk) v[i] = 1 - v[a], dfs(i); n } n bool av(int a) { n   now = a; n   for (int i = 0; i < n; i++) n     if (mark[i] != mk) v[i] = 0, dfs(i); n   mk++; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (dt[i][j] > now && v[i] == v[j]) return 0; n   return 1; n } n int main(int argc, char *argv[]) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> point[i].first >> point[i].second; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) dt[i][j] = d(point[i], point[j]); n   int s = 0, e = 10000; n   int res = 10000; n   while (s <= e) { n     int m = (s + e) / 2; n     if (av(m)) n       smn(res, m), e = m - 1; n     else n       s = m + 1; n   } n   now = res; n   cout << now <<   n ; n   int rn = 1; n   for (int i = 0; i < n; i++) n     if (mark[i] != mk) dfs(i), rn = (2LL * rn) % MOD; n   cout << rn <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e5 + 10, md = 1e9 + 7; n vector<long long> child[MAXN]; n long long dp[2][MAXN], dp1[2][MAXN], dp2[2][2][MAXN]; n void dfs(long long v) { n   long long s = child[v].size(); n   for (long long i = 0; i < s; ++i) { n     long long now = child[v][i]; n     dfs(now); n     if (!i) { n       dp1[0][now] = dp[0][now] + 1; n       dp1[1][now] = dp[1][now]; n       dp2[1][0][now] = dp2[0][0][now] = 1; n       dp2[0][0][now] += dp[0][now]; n       dp2[1][1][now] = dp[1][now]; n       continue; n     } n     long long p = child[v][i - 1]; n     dp1[0][now] = (dp1[0][p] * (dp[0][now] + 1) + dp1[1][p] * dp[1][now]) % md; n     dp1[1][now] = (dp1[0][p] * dp[1][now] + dp1[1][p] * (dp[0][now] + 1)) % md; n     dp2[0][0][now] = dp2[0][0][p] * (1 + dp[0][now]) % md; n     dp2[1][0][now] = (dp2[1][1][p] * dp[1][now] + dp2[1][0][p]) % md; n     dp2[1][1][now] = (dp2[1][0][p] * dp[1][now] + dp2[1][1][p]) % md; n   } n   if (child[v].empty()) { n     dp[1][v] = 1; n     return; n   } n   long long k = child[v].back(); n   dp[1][v] = 2 * dp1[0][k] - dp2[0][0][k]; n   dp[1][v] = (dp[1][v] + md * 10) % md; n   dp[0][v] = 2 * dp1[1][k] - dp2[1][1][k]; n   dp[0][v] = (dp[0][v] + md * 10) % md; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n, a1; n   cin >> n; n   for (long long i = 2; i <= n; ++i) { n     cin >> a1; n     child[a1].push_back(i); n   } n   dfs(1); n   cout << (dp[0][1] + dp[1][1]) % md; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long t, a, b, x, y, n, z, z2; n   cin >> t; n   while (t--) { n     cin >> a >> b >> x >> y >> n; n     if (abs(a - x) + abs(b - y) < n) { n       n = abs(a - x) + abs(b - y); n     } n     long long a2 = a, b2 = b, x2 = x, y2 = y, n2 = n; n     if (n2 > abs(a2 - x2)) { n       n2 -= abs(a2 - x2); n       a2 = x2; n       b2 -= n2; n     } else { n       a2 -= n2; n     } n     if (n > abs(b - y)) { n       n -= abs(b - y); n       b = y; n       a -= n; n     } else { n       b -= n; n     } n     cout << min(a2 * b2, a * b) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1e9 + 7; n void solve() { n   long long n, r; n   cin >> n >> r; n   long long ans = 0; n   if (r >= n) ans++; n   r = min(r, n - 1); n   if (r % 2) n     ans += r * ((r + 1) / 2); n   else n     ans += (r / 2) * (r + 1); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n void read() { scanf( %d%d , &n, &q); } n void solve() { n   int p0 = 0, p1 = 0, l = 0; n   while (q--) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int x; n       scanf( %d , &x); n       p1 = (p1 + x) % n; n       p0 = (p0 + x) % n; n       l ^= ((x % 2) + 2) % 2; n     } else { n       if (!l) { n         p0 = (p0 + 1) % n; n         p1 = (p1 - 1) % n; n       } else { n         p0 = (p0 - 1) % n; n         p1 = (p1 + 1) % n; n       } n       l ^= 1; n     } n   } n   if (l == 1) swap(p0, p1); n   for (int i = 0; i < n; i++) { n     int x; n     x = (i - p0 + n) % n; n     printf( %d  , x + 1); n     swap(p0, p1); n   } n } n int main() { n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool o[30]; n int main() { n   int m, n, i, x, mid; n   cin >> m >> n; n   for (i = 0; i < n; i++) { n     cout << m << endl; n     cin >> x; n     if (!x) return printf( %d n , m), 0; n     o[i] = x == -1; n   } n   i = -1; n   int l = 1, r = m - 1; n   while (l <= r) { n     mid = (l + r) >> 1; n     cout << mid << endl; n     cin >> x; n     if (!x) return printf( %d n , mid), 0; n     if ((x == -1) ^ o[(++i) %= n]) n       l = mid + 1; n     else n       r = mid - 1; n   } n   return printf( %d n , l), 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ans, h, r; n   double tmp; n   scanf( %d%d , &r, &h); n   ans = h / r * 2; n   tmp = h % r; n   if (r / 2.0 - tmp > 1e-8) n     ans++; n   else if (sqrt(3) / 2 * r - tmp > 1e-8) n     ans += 2; n   else n     ans += 3; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 5; n vector<long long> adj[N]; n vector<pair<long long, long long> > lol[N]; n long long x[N], y[N], z[N], vis[N], tin[N], low[N], bridge[N], comp[N], n     artificat[N], depth[N], par[N], path[N], timer, cur; n void dfs1(long long node, long long prvId) { n   vis[node] = 1; n   tin[node] = low[node] = ++timer; n   for (auto &id : adj[node]) { n     if (id == prvId) continue; n     long long v = x[id] ^ y[id] ^ node; n     if (!vis[v]) n       dfs1(v, id), low[node] = min(low[node], low[v]); n     else n       low[node] = min(low[node], tin[v]); n     if (low[v] > tin[node]) bridge[id] = 1; n   } n } n void dfs2(long long node) { n   comp[node] = cur; n   vis[node] = 1; n   for (auto &id : adj[node]) { n     if (bridge[id]) continue; n     if (z[id]) artificat[cur] = 1; n     long long v = x[id] ^ y[id] ^ node; n     if (!vis[v]) dfs2(v); n   } n } n void dfs3(long long node, long long pr) { n   depth[node] = depth[pr] + 1; n   par[node] = pr; n   for (auto &ele : lol[node]) n     if (ele.first != pr) path[ele.first] = ele.second, dfs3(ele.first, node); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, m; n   cin >> n >> m; n   for (long long i = 1; i <= m; i++) { n     cin >> x[i] >> y[i] >> z[i]; n     adj[x[i]].push_back(i); n     adj[y[i]].push_back(i); n   } n   dfs1(1, 0); n   for (long long i = 1; i <= n; i++) vis[i] = 0; n   for (long long i = 1; i <= n; i++) n     if (!vis[i]) cur++, dfs2(i); n   for (long long i = 1; i <= m; i++) { n     if (bridge[i]) { n       lol[comp[x[i]]].push_back({comp[y[i]], z[i]}); n       lol[comp[y[i]]].push_back({comp[x[i]], z[i]}); n     } n   } n   dfs3(1, 0); n   long long s, t; n   cin >> s >> t; n   s = comp[s], t = comp[t]; n   while (s != t) { n     if (depth[s] < depth[t]) swap(s, t); n     if (artificat[s] || path[s]) return cout <<  YES , 0; n     s = par[s]; n   } n   cout << (artificat[s] ?  YES  :  NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500000; n const int M = 70; n const int C = 300; n const int MOD = 1e9 + 7; n struct Point { n   int x[5]; n   Point() { n     for (int i = 0; i < 5; i++) x[i] = 0; n   } n }; n int n; n Point a[N]; n vector<int> res; n Point diff(const Point &a, const Point &b) { n   Point res = Point(); n   for (int i = 0; i < 5; i++) res.x[i] = a.x[i] - b.x[i]; n   return res; n } n bool check(const Point &a, const Point &b) { n   int val = 0; n   for (int i = 0; i < 5; i++) val += a.x[i] * b.x[i]; n   return (val > 0); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 5; j++) scanf( %d , &a[i].x[j]); n   } n   int ans = 0; n   if (n <= C) { n     for (int i = 0; i < n; i++) { n       bool flag = true; n       for (int j = 0; j < n; j++) { n         for (int k = j + 1; k < n; k++) { n           if (j == i || k == i) continue; n           if (check(diff(a[j], a[i]), diff(a[k], a[i]))) { n             flag = false; n             break; n           } n         } n       } n       if (flag) { n         ans++; n         res.push_back(i + 1); n       } n     } n   } n   cout << ans << endl; n   for (int i = 0; i < res.size(); i++) cout << res[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> eg[400005]; n long long dep[400005]; n int dfn[400005], sz[400005]; n int a[400005]; n int p[400005], w[400005]; n int dfcnt = 0; n int fa[400005][20]; n void dfs(int a) { n   sz[a] = 1, dfn[a] = ++dfcnt; n   for (auto v : eg[a]) { n     if (v == p[a]) continue; n     fa[v][0] = a; n     for (int i = 1; i < 20; i++) fa[v][i] = fa[fa[v][i - 1]][i - 1]; n     dep[v] = dep[a] + w[v]; n     dfs(v); n     sz[a] += sz[v]; n   } n } n long long ud[400005]; n vector<int> qs[400005]; n int d[400005]; n int lb(int x) { return x & -x; } n void upd(int pl, int x) { n   while (pl < 400005) d[pl] += x, pl += lb(pl); n } n int q(int pl) { n   int ans = 0; n   while (pl) ans += d[pl], pl -= lb(pl); n   return ans; n } n int ans[400005]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 2; i <= n; i++) { n     scanf( %d%d , &p[i], &w[i]); n     eg[p[i]].push_back(i); n   } n   dfs(1); n   dep[0] = -1e18; n   for (int i = 1; i <= n; i++) { n     int v = i; n     for (int j = 19; j >= 0; j--) { n       int t = fa[v][j]; n       if (dep[t] >= dep[i] - a[i]) v = t; n     } n     if (p[v]) upd(dfn[p[v]], -1); n     upd(dfn[i], 1); n   } n   for (int i = 1; i <= n; i++) ans[i] = q(dfn[i] + sz[i] - 1) - q(dfn[i] - 1); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i] - 1); n   return 0; n } n


#include <bits/stdc++.h> n int n, k, a, b; n int ask(int x, int y) { n   if (x == n) return 1; n   fflush(stdout); n   printf( 1 %d %d n , x, y); n   fflush(stdout); n   char s[5]; n   scanf( %s , s); n   fflush(stdout); n   return s[0] ==  T ; n } n int xxx(int l, int r) { n   int mid, res = 0; n   while (l <= r) { n     mid = (l + r) >> 1; n     if (ask(mid, mid + 1)) n       res = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return res; n } n int main() { n   scanf( %d%d , &n, &k); n   fflush(stdout); n   a = xxx(1, n); n   b = xxx(1, a - 1); n   if (!b) b = xxx(a + 1, n); n   fflush(stdout); n   printf( 2 %d %d , a, b); n   fflush(stdout); n } n


#include <bits/stdc++.h> n int main() { n   int n; n   int x, y; n   int k; n   int l; n   scanf( %d , &n); n   for (x = 4; 2 * x < n; x++) { n     y = n - x; n     k = 0; n     l = 0; n     for (int i = 2; i < x; i++) { n       if (x % i == 0) k = 1; n     } n     for (int j = 2; j < y; j++) { n       if (y % j == 0) l = 1; n     } n     if (k && l) { n       printf( %d %d , x, y); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n using ii = pair<int, int>; n using ll = long long; n const int N = 2005; n const int mod = 1e9 + 7; n ll a[2005], b[2005]; n ll lena[2005], lenb[2005]; n int n, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   ll x; n   cin >> x; n   fill(lena, lena + n + 1, 1e9); n   fill(lenb, lenb + m + 1, 1e9); n   for (int i = 0; i < n; i++) { n     ll cur = 0; n     for (int j = i; j < n; j++) { n       cur += a[j]; n       lena[j - i + 1] = min(lena[j - i + 1], cur); n     } n   } n   for (int i = 0; i < m; i++) { n     ll cur = 0; n     for (int j = i; j < m; j++) { n       cur += b[j]; n       lenb[j - i + 1] = min(lenb[j - i + 1], cur); n     } n   } n   int out = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (lena[i] * lenb[j] <= x) out = max(out, i * j); n   cout << out <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const int nax = 1e6 + 10; n long long fac[nax], ifac[nax], inv[nax]; n long long ncr(int n, int k) { n   if (n < 0 || k < 0 || k > n) return 0; n   return fac[n] * ifac[k] % mod * ifac[n - k] % mod; n } n int main() { n   fac[0] = ifac[0] = 1; n   for (int i = 1; i < nax; i++) { n     inv[i] = i == 1 ? 1 : mod - mod / i * inv[mod % i] % mod; n     fac[i] = fac[i - 1] * i % mod; n     ifac[i] = ifac[i - 1] * inv[i] % mod; n     assert(fac[i] * ifac[i] % mod == 1); n   } n   ios::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   int n = s.size(); n   int lp = 0, rp = count(s.begin(), s.end(),  ) ); n   int lq = 0, rq = count(s.begin(), s.end(),  ? ); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     (ans += ncr(lq + rq, rq - lp + rp) * lp + n             ncr(lq + rq - 1, rq - 1 - lp + rp) * lq) %= mod; n     if (s[i] ==  ( ) n       lp++; n     else if (s[i] ==  ) ) n       rp--; n     else if (s[i] ==  ? ) n       lq++, rq--; n     else n       assert(0); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long T, i, j, n; n   char c[2], ca[4] = { v ,  < ,  ^ ,  > }, a, b; n   cin >> a >> b; n   map<char, long long> m; n   m[ca[0]] = 1; n   m[ca[1]] = 2; n   m[ca[2]] = 3; n   m[ca[3]] = 4; n   cin >> n; n   n = n % 4; n   if (n == 0) n     cout <<  undefined  << endl; n   else if (m[a] <= m[b]) { n     if (m[b] - m[a] == 2) n       cout <<  undefined  << endl; n     else if (m[b] - m[a] == n) n       cout <<  cw  << endl; n     else if (4 - m[b] + m[a] == n) n       cout <<  ccw  << endl; n     else n       cout <<  undefined  << endl; n   } else { n     if (m[a] - m[b] == 2) n       cout <<  undefined  << endl; n     else if (4 - m[a] + m[b] == n) n       cout <<  cw  << endl; n     else if (m[a] - m[b] == n) n       cout <<  ccw  << endl; n     else n       cout <<  undefined  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double PI = acos(-1); n const int oo = 1e9, bpr = 1e9 + 7, N = 0; n long long f[110]; n int a[110]; n long long d[110][4][4]; n int n; n inline long long calc(int ps, int v1, int v2) { n   if (ps == n) return v1 == 0 && v2 == 0; n   if (d[ps][v1][v2] != -1) return d[ps][v1][v2]; n   long long res = 0; n   for (int i = 0; i < 2; ++i) { n     int x = min(v1, v2 + i); n     for (int j = 0; j <= x; ++j) { n       if (v1 - j == a[ps]) { n         res += calc(ps + 1, v2 + i - j, j); n       } n     } n   } n   return d[ps][v1][v2] = res; n } n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   f[0] = f[1] = 1; n   for (n = 2; f[n - 1] <= 1e18; ++n) f[n] = f[n - 1] + f[n - 2]; n   --n; n   int t; n   cin >> t; n   while (t--) { n     long long x; n     cin >> x; n     int cnt = 0; n     for (int i = n; i >= 1; --i) { n       a[i] = (f[i] <= x); n       if (a[i]) x -= f[i]; n     } n     memset(d, -1, sizeof(d)); n     cout << calc(0, 0, 0) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int level[26]; n   for (int i = 0; i < 26; i++) cin >> level[i]; n   string s; n   cin >> s; n   long long ans = 0; n   for (char ch =  a ; ch <=  z ; ch++) { n     map<long long, long long> m; n     long long sum = 0; n     for (int i = 0; i < s.length(); i++) { n       sum += level[s[i] -  a ]; n       if (s[i] == ch) ans += m[sum - level[ch -  a ]], m[sum]++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n void stderr_printf(const char *fmt, ...) { n   va_list ap; n   va_start(ap, fmt); n   vfprintf(stderr, fmt, ap); n   va_end(ap); n } n using namespace std; n struct flist { n   int val; n   int pos; n }; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int i, j, k; n   int n; n   cin >> n; n   ; n   int stage = 0; n   bool ans = true; n   cin >> j; n   ; n   for (i = 0; i < n - 1; i++) { n     int cur; n     cin >> cur; n     ; n     if (stage == 0) { n       if (cur == j) { n         stage = 1; n       } else if (cur < j) { n         stage = 2; n       } else if (cur > j) { n         stage = 0; n       } n     } else if (stage == 1) { n       if (cur == j) { n         stage = 1; n       } else if (cur < j) { n         stage = 2; n       } else if (cur > j) { n         ans = false; n       } n     } else { n       if (cur >= j) { n         ans = false; n       } n     } n     j = cur; n   } n   if (ans) { n     printf( YES n ); n   } else { n     printf( NO n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<pair<long long, int>, vector<pair<long long, int> >, n                greater<pair<long long, int> > > n     q; n struct node { n   int left, right, num[3]; n } tree[4 * 100010]; n struct NODE { n   int begin, end, value, next; n } edge[50 * 100010 + 10]; n int cnt, Head[2 * 4 * 100010 + 10], lcc[3], SIZE, cc[3][100010]; n long long dis[2 * 4 * 100010 + 10]; n int read() { n   int s = 0, fh = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) fh = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     s = s * 10 + (ch -  0 ); n     ch = getchar(); n   } n   return s * fh; n } n void addedge(int bb, int ee, int vv) { n   edge[++cnt].begin = bb; n   edge[cnt].end = ee; n   edge[cnt].value = vv; n   edge[cnt].next = Head[bb]; n   Head[bb] = cnt; n } n void addedge1(int bb, int ee, int vv) { n   addedge(bb, ee, vv); n   addedge(ee, bb, vv); n } n void Build(int k, int l, int r) { n   tree[k].left = l; n   tree[k].right = r; n   tree[k].num[1] = ++SIZE; n   tree[k].num[2] = ++SIZE; n   if (l == r) { n     addedge(tree[k].num[1], tree[k].num[2], 0); n     return; n   } n   int mid = (l + r) / 2; n   Build(k * 2, l, mid); n   Build(k * 2 + 1, mid + 1, r); n   addedge(tree[k].num[1], tree[k * 2].num[1], 0); n   addedge(tree[k].num[1], tree[k * 2 + 1].num[1], 0); n   addedge(tree[k * 2].num[2], tree[k].num[2], 0); n   addedge(tree[k * 2 + 1].num[2], tree[k].num[2], 0); n } n void Find(int k, int ql, int qr, int F) { n   if (ql <= tree[k].left && tree[k].right <= qr) { n     cc[F][++lcc[F]] = tree[k].num[F]; n     return; n   } n   int mid = (tree[k].left + tree[k].right) / 2; n   if (qr <= mid) n     Find(k * 2, ql, qr, F); n   else if (ql > mid) n     Find(k * 2 + 1, ql, qr, F); n   else { n     Find(k * 2, ql, mid, F); n     Find(k * 2 + 1, mid + 1, qr, F); n   } n } n void dijkstra(int start) { n   int i, u, v; n   for (i = 1; i <= SIZE; i++) dis[i] = 1LL << 60; n   dis[start] = 0LL; n   q.push(make_pair(dis[start], start)); n   while (!q.empty()) { n     u = q.top().second; n     q.pop(); n     for (i = Head[u]; i != -1; i = edge[i].next) { n       v = edge[i].end; n       if (dis[v] > dis[u] + (long long)edge[i].value) { n         dis[v] = dis[u] + (long long)edge[i].value; n         q.push(make_pair(dis[v], v)); n       } n     } n   } n } n int main() { n   int N, Q, S, i, zs, s1, s2, s3, s4, j; n   N = read(); n   Q = read(); n   S = read(); n   memset(Head, -1, sizeof(Head)); n   cnt = 1; n   SIZE = 0; n   Build(1, 1, N); n   for (i = 1; i <= Q; i++) { n     zs = read(); n     if (zs == 1) { n       s1 = read(); n       s2 = read(); n       s3 = read(); n       lcc[1] = lcc[2] = 0; n       Find(1, s1, s1, 2); n       Find(1, s2, s2, 1); n       addedge(cc[2][1], cc[1][1], s3); n     } else if (zs == 2) { n       s1 = read(); n       s2 = read(); n       s3 = read(); n       s4 = read(); n       lcc[1] = lcc[2] = 0; n       Find(1, s1, s1, 2); n       Find(1, s2, s3, 1); n       for (j = 1; j <= lcc[1]; j++) addedge(cc[2][1], cc[1][j], s4); n     } else { n       s1 = read(); n       s2 = read(); n       s3 = read(); n       s4 = read(); n       lcc[1] = lcc[2] = 0; n       Find(1, s2, s3, 2); n       Find(1, s1, s1, 1); n       for (j = 1; j <= lcc[2]; j++) addedge(cc[2][j], cc[1][1], s4); n     } n   } n   lcc[2] = 0; n   Find(1, S, S, 2); n   dijkstra(cc[2][1]); n   for (i = 1; i <= N; i++) { n     lcc[2] = 0; n     Find(1, i, i, 2); n     printf( %lld  , dis[cc[2][1]] == 1LL << 60 ? -1LL : dis[cc[2][1]]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct lex_compare { n   bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) const { n     return lhs.second > rhs.second; n   } n }; n void solve() { n   int n; n   cin >> n; n   vector<long long> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   sort(v.begin(), v.end()); n   if (n >= 60) { n     long long ans = 0; n     for (int i = 0; i < n; i++) { n       ans += abs(v[i] - 1ll); n     } n     cout << ans <<   n ; n   } else { n     int k = 1; n     while (true) { n       if ((long long)pow(k, n - 1) > v[n - 1]) { n         break; n       } n       k += 1; n     } n     long long ans1 = 0, ans2 = 0; n     for (int i = 0; i < n; i++) { n       ans1 += abs(v[i] - (long long)pow(k, i)); n       ans2 += abs(v[i] - (long long)pow(k - 1, i)); n     } n     cout << min(ans1, ans2) <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n = 1; n   for (int i = 0; i < n; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void write(long long x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n long long n, A, B, x, y; n long long ans; n string a, b; n bool flag = 0; n void DOIT() { n   n = read(); n   A = read(); n   B = read(); n   A++; n   B++; n   x = 0; n   y = 0; n   cin >> a >> b; n   if (A > B) { n     if (a ==  left ) n       A--; n     else n       A++; n     if (A == 0) A = 2; n     if (A == n + 1) A = n - 1; n     swap(A, B); n     swap(a, b); n   } n   if (A == 1 && B == 1) { n     if (1) n       cout << n - 1 <<   n ; n     else n       cout << 0 <<   n ; n     return; n   } n   if (A == 1 && B == 2) { n     if (0) n       cout << n - 1 <<   n ; n     else n       cout << 0 <<   n ; n     return; n   } n   if (A == n) { n     if (0) n       cout << n - 1 <<   n ; n     else n       cout << 0 <<   n ; n     return; n   } n   if (A == n - 1) { n     if (0) n       cout << n - 1 <<   n ; n     else n       cout << 0 <<   n ; n     return; n   } n   if (A < B) { n     if (a ==  right  && b ==  left ) { n       if ((A + B + 1) % 2) n         cout << n - 1 <<   n ; n       else n         cout << 0 <<   n ; n       return; n     } n     if (a ==  left  && b ==  left ) { n       B -= A - 1; n       A = 1; n       if (A == 1 && B == 1) { n         if (1) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       if (A == 1 && B == 2) { n         if (0) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       { n         if ((A + B + 1) % 2) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n     } n     if (a ==  right  && b ==  right ) { n       A += n - B; n       B = n; n       if (A == n) { n         if (0) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       if (A == n - 1) { n         if (0) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       { n         if ((A + B + 1) % 2) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n     } n     if (a ==  left  && b ==  right ) { n       long long t = max(A - 1, n - B); n       A -= t; n       if (A < 1) A = 2 - A; n       B += t; n       if (B > n) B = 2 * n - B; n       if (A == 1 && B == 1) { n         if (1) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       if (A == 1 && B == 2) { n         if (0) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       if (B == n && A == n) { n         if (0) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       if (B == n && A == n - 1) { n         if (1) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n       { n         if ((A + B + 1) % 2) n           cout << n - 1 <<   n ; n         else n           cout << 0 <<   n ; n         return; n       } n     } n   } else if (A == B) { n     x = A - 1; n     y = n - x - 1; n     if (a ==  left  && b ==  right ) { n       if (0) n         cout << n - 1 <<   n ; n       else n         cout << 0 <<   n ; n       return; n     } n     if (a ==  left  && b ==  left ) { n       if (1) n         cout << n - 1 <<   n ; n       else n         cout << 0 <<   n ; n       return; n     } n     if (a ==  right  && b ==  right ) { n       if (0) n         cout << n - 1 <<   n ; n       else n         cout << 0 <<   n ; n       return; n     } n     if (a ==  right  && b ==  left ) { n       if (1) n         cout << n - 1 <<   n ; n       else n         cout << 0 <<   n ; n       return; n     } n   } n } n signed main() { n   long long JYZ; n   JYZ = read(); n   while (JYZ--) DOIT(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int main() { n   ios::sync_with_stdio(false); n   int n; n   long long m, x; n   set<long long> v1; n   set<long long> v2; n   v1.insert(0); n   v2.insert(0); n   cin >> n >> m; n   long long ans = 0; n   for (int i = 0; i < n / 2; i++) { n     cin >> x; n     set<long long> tmp; n     for (auto it : v1) tmp.insert((it + x) % m), ans = max(ans, it); n     for (auto it : tmp) v1.insert(it), ans = max(ans, it); n   } n   for (int i = n / 2; i < n; i++) { n     cin >> x; n     set<long long> tmp; n     for (auto it : v2) tmp.insert((it + x) % m), ans = max(ans, it); n     for (auto it : tmp) v2.insert(it), ans = max(ans, it); n   } n   for (auto it : v1) { n     int precisa = (m - 1) - it; n     auto ok = v2.lower_bound(precisa); n     if (ok == v2.end()) ok--; n     while (ok != v2.begin() and it + *ok >= m) ok--; n     ans = max(ans, (it + *ok) % m); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n vector<vector<int> > v; n bool transponer; n void escribe() { n   if (transponer) { n     vector<vector<int> > nextv(m + 2, vector<int>(n + 2, 0)); n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) nextv[j][i] = v[i][j]; n     swap(n, m); n     v = nextv; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (v[i][j]) n         cout <<  * ; n       else n         cout <<  . ; n     cout << endl; n   } n } n int valor(int i, int j) { n   if (i == 1) return 0; n   if (j == 1) return 1; n   if (j == m) return 3; n   return 4; n } n void genera() { n   int act = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (act + valor(i, j) > k) { n         int resta = k - act; n         if (resta == 1) { n           if (m > j) n             v[i][m] = 1; n           else n             v[i + 1][1] = 1; n         } else if (resta == 2) { n           if (m - j + 1 >= 3) n             v[i][m - 1] = 1; n           else if (m - j + 1 == 2) n             v[i][m] = v[i + 1][m] = v[i + 1][m - 1] = 1; n           else n             v[i + 1][2] = 1; n         } else { n           if (m - j + 1 >= 4) n             v[i][m] = v[i][m - 2] = 1; n           else if (j == 2) { n             if (i < n) n               v[i][m] = v[i + 1][m] = v[i + 1][m - 1] = v[i + 1][1] = n                   v[i + 1][2] = 1; n             else { n               v[i][1] = 0; n               v[i][2] = v[i][4] = 1; n             } n           } else n             v[i][m] = v[i + 1][m] = v[i + 1][m - 1] = v[i + 1][1] = 1; n         } n         escribe(); n         return; n       } n       v[i][j] = 1; n       act += valor(i, j); n       if (act == k) { n         escribe(); n         return; n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   int casos; n   cin >> casos; n   for (int cas = 0; cas < casos; cas++) { n     if (cas > 0) cout << endl; n     cin >> n >> m >> k; n     transponer = false; n     if (n > m) { n       swap(n, m); n       transponer = true; n     } n     v = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)); n     int total = (n - 1) + (n - 1) * (m - 2) * 4 + (n - 1) * 3; n     if (k > total or k == total - 1 or k == total - 2 or k == total - 4 or n         k == total - 5) { n       cout << -1 << endl; n       continue; n     } n     if (k == total - 8) { n       if (n > 3) { n         cout << -1 << endl; n         continue; n       } n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= m - 1; j++) v[i][j] = 1; n       escribe(); n       continue; n     } n     if (m == 3 and k == 7) { n       for (int i = 1; i <= 3; i++) n         for (int j = 1; j <= 3; j++) v[i][j] = 1; n       v[1][1] = v[3][1] = v[1][3] = 0; n       escribe(); n       continue; n     } n     genera(); n   } n } n


#include <bits/stdc++.h> n int main() { n   int a, i; n   char b, c, x; n   scanf( %d  , &a); n   scanf( %c , &b); n   for (i = 1; i <= a - 2; i++) scanf( %c , &x); n   scanf( %c , &c); n   if (b ==  S  && c ==  F ) n     printf( YES ); n   else n     printf( NO ); n } n


/*              Jai Maa Saraswati!!           */ n #include<bits/stdc++.h> n #include<iostream> n #include<algorithm> n #include<string.h> n #include<math.h> n #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); n #define ll long long  n #define pb push_back n #define mod 1000000007 n #define F first n #define S second n #define mp make_pair n #define vi vector<int> n #define vll vector<long long> n #define all(x) x.begin(),x.end() n #define dbg(x) cout<<   << #x <<  =  << x <<   ; //for debugging n   n using namespace std; n bool isprime(ll n) n { n     //if(n<2) n     //return false; n     if(n==1) n     return true; n     if(n==2 || n==3) n     return true; n     if(n%2==0)return false; n     for(ll i=3;i*i<=n;i+=2) n     { n         if(n%i==0) n         return false; n          n     } n     return true; n } n bool checkpalindrome(ll c) n {  n     string p=to_string(c);  n        int j = p.size() - 1; n   n     for (int i = 0; i < j; i++, j--) n     { n         if (p[i] != p[j]) n         { n             return false; n         } n     } n   n     return true; n } n ll gcd(ll a,ll b) n { n     if(a==0) n     return b; n     return gcd(b%a,a); n } n ll lcm(ll a,ll b) n { n     return a*(b/gcd(a,b)); n } n  set<ll> fac; n void allFactors(ll n) n { n    // set<ll> fac; n     for(ll i=1;i<=sqrt(n);i++) n     { n         if(n%i==0) n         { n             fac.insert(i); n             if(i!=n/i) n             { n                 fac.insert(n/i); n             } n         } n     } n     //return fac.size(); n } n bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no. n { n     ll p=sqrt(n); n     if(p*p==n) n     { n         if(isprime(p)) n         return 1; n         else n         return 0; n     } n     else n     return 0; n } n unsigned int countSetBits(unsigned int n) //no. of 1 s in a binary representation of a number n {  n     unsigned int count = 0;  n     while (n) {  n         count += n & 1;  n         n >>= 1;  n     }  n     return count;  n }  n int computeXOR(int n) n { n   if(n%4==0) n   return n;                        //TO CALCULATE XOR FROM 1 TO N n   if(n%4==1) n   return 1; n   if(n%4==2) n   return n+1; n   else n   return 0; n } n ll largest_power(ll N) n     {                                              //LARGEST POWER OF 2 JUST LESS THAN OR EQUAL TO A GIVEN 16 BIT NUMBER n         //changing all right side bits to 1. n         N = N| (N>>1); n         N = N| (N>>2); n         N = N| (N>>4); n         N = N| (N>>8); n         N = N| (N>>16);   n   n     //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by n                 return (N+1)>>1; n   n     } n ll fibo(ll n) n { n     long double him=(1+sqrt(5))/2; n   return round(pow(him,n)/sqrt(5)); n }  n //pair(weight,pair(u,v)); n void kruskal(vector<pair<ll,pair<int,int>>> v) n { n      sort(v.begin(),v.end()); n     set<int> s; n     ll ans=0; n     for(int i=0;i<v.size() && s.size()<8;i++) n     { n         if(s.count(v[i].S.F) && s.count(v[i].S.S)) n         { n              n         } n         else n         { n             ans+=v[i].F; n             s.insert(v[i].S.F); n             s.insert(v[i].S.S); n         } n     } n     cout<<ans; n } n /*                      Jai Shree Krishna!! n                         Jai Shree Ram!! n                      Jai Shiv Shambhu Sai Ram!!                      */   n  n void solve() n { n     ll n,x,t; n     cin>>n>>x>>t; n     ll a=0,b=1,cnt; n      a=t/x; n      if(a<=n) n      { n      cnt=a*(n-1); n      a--; n      cnt-=(a*(a+1))/2; n      } n      else n      { n          n--; n          cnt=(n*(n+1))/2; n      } n      cout<<max(0LL,cnt)<<endl; n      n      n      n } n int main() n { n      #ifndef ONLINE_JUDGE n         freopen( input.txt ,  r , stdin); n         freopen( output.txt ,  w , stdout); n      #endif n      IOS n      int test_cases=1;  n      cin>>test_cases; n      while(test_cases--) n      { n          solve(); n      } n      return 0; n }  n //ascii of a=97 n //ascii of A=65 n //ascii of 0=48 n // priority_queue<ll,vector<ll>,greater<ll>>pq; ascending queue n //lower_bound and upper_bound n /*   for erasing in vector n     1.you MUST declare a vector with its size or fill values using push_back n     2.v[]={0,1,2,3,4,5,6}; n     3.v.erase(v.begin()+2);=>0 1 3 4 5 6 n     4.Again v[]={0,1,2,3,4,5,6}; n     5.v.erase(v.begin()+2,v.begin()+4);=>0 1 4 5 6 n */ n /*              Har Har Mahadev!!               */


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n inline void write(long long a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n inline void writeln(long long a) { n   write(a); n   puts(  ); n } n inline void wri(long long a) { n   write(a); n   putchar(   ); n } n inline unsigned long long rnd() { n   return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4; n } n const int N = 50005, K = 16; n int n; n char ch[N], q[N]; n struct data { n   int m, tong[N], SA[N], y[N], x[N], rk[N], h[N], height[N], logn[N]; n   char ch[N]; n   int dp[N][K]; n   inline int ask(int a, int b) { n     if (a == b) return n - a + 1; n     a = rk[a]; n     b = rk[b]; n     if (a > b) swap(a, b); n     b--; n     int zs = logn[b - a + 1]; n     return min(dp[b][zs], dp[a + (1 << zs) - 1][zs]); n   } n   void init() { n     int m = 150; n     memset(SA, 0, sizeof(SA)); n     memset(rk, 0, sizeof(rk)); n     memset(h, 0, sizeof(h)); n     memset(height, 0, sizeof(height)); n     memset(dp, 0, sizeof(dp)); n     memset(tong, 0, sizeof(tong)); n     memset(x, 0, sizeof(x)); n     memset(y, 0, sizeof(y)); n     for (int i = 1; i <= n; i++) tong[x[i] = ch[i]]++; n     for (int i = 1; i <= m; i++) tong[i] += tong[i - 1]; n     for (int i = n; i; i--) SA[tong[x[i]]--] = i; n     logn[0] = -1; n     for (int k = 1; k <= n; k <<= 1) { n       int p = 0; n       for (int i = n - k + 1; i <= n; i++) y[++p] = i; n       for (int i = 1; i <= n; i++) n         if (SA[i] > k) y[++p] = SA[i] - k; n       memset(tong, 0, sizeof(tong)); n       for (int i = 1; i <= n; i++) tong[x[y[i]]]++; n       for (int i = 1; i <= m; i++) tong[i] += tong[i - 1]; n       for (int i = n; i; i--) SA[tong[x[y[i]]]--] = y[i]; n       swap(x, y); n       x[SA[1]] = p = 1; n       for (int i = 2; i <= n; i++) n         x[SA[i]] = y[SA[i]] == y[SA[i - 1]] && y[SA[i] + k] == y[SA[i - 1] + k] n                        ? p n                        : ++p; n       if (p >= n) break; n       m = p; n     } n     for (int i = 1; i <= n; i++) rk[SA[i]] = i; n     for (int i = 1; i <= n; i++) { n       int t = SA[rk[i] + 1]; n       for (h[i] = max(0, h[i - 1] - 1); ch[i + h[i]] == ch[t + h[i]]; h[i]++) n         ; n       height[rk[i]] = h[i]; n     } n     for (int i = 1; i <= n; i <<= 1) logn[i] = logn[i >> 1] + 1; n     for (int i = 1; i <= n; i++) { n       dp[i][0] = height[i]; n       if (i > 1 && !logn[i]) logn[i] = logn[i - 1]; n     } n     for (int j = 1; j < K; j++) n       for (int i = 1 << j; i <= n; i++) n         dp[i][j] = min(dp[i][j - 1], dp[i - (1 << (j - 1))][j - 1]); n   } n } S1, S2; n bool check(int x) { n   for (int i = x; i + x <= n; i += x) { n     if (S1.ask(i, i + x) + S2.ask(n - i + 1, n - i - x + 1) >= x) return 1; n   } n   return 0; n } n void build() { n   memset(S1.ch, 0, sizeof(S1.ch)); n   memset(S2.ch, 0, sizeof(S2.ch)); n   for (int i = 1; i <= n; i++) S1.ch[i] = S2.ch[n - i + 1] = ch[i]; n   S1.init(); n   S2.init(); n } n int main() { n   scanf( %s , ch + 1); n   n = strlen(ch + 1); n   build(); n   for (int i = 1; i <= n; i++) n     if (check(i)) { n       int tot = 0; n       for (int j = 1; j <= i; j++) q[++tot] = ch[j]; n       for (int j = i + 1; j <= n; j++) { n         q[++tot] = ch[j]; n         if (S1.ask(j - i, j) >= i) { n           tot -= i; n           for (int k = j + 1; k < j + i && k <= n; k++) q[++tot] = ch[k]; n           j = j + i - 1; n           continue; n         } n       } n       n = tot; n       for (int j = 1; j <= n; j++) ch[j] = q[j]; n       build(); n     } n   ch[n + 1] = 0; n   puts(ch + 1); n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int f = 1, x = 0; n   char c = getchar(); n   while (c <  0  ||  9  < c) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while ( 0  <= c && c <=  9 ) n     x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); n   return f * x; n } n const int MAXN = 100000; n const int INF = 0x3f3f3f3f; n int ans; n void Query(int L, int R, int l1, int r1, int l2, int r2) { n   if (l1 > r1 || l2 > r2) return; n   int le = max(l1, l2), ri = min(r1, r2); n   ans = max(ans, ri - le + 1); n   if ((l1 <= l2 && r2 <= r1) || (l2 <= l1 && r1 <= r2)) return; n   int Mid = (L + R) >> 1; n   Query(L, Mid - 1, l1, min(r1, Mid - 1), l2, min(r2, Mid - 1)); n   Query(L, Mid - 1, l1, min(r1, Mid - 1), max(l2, Mid + 1) - Mid, r2 - Mid); n   Query(L, Mid - 1, max(l1, Mid + 1) - Mid, r1 - Mid, l2, min(r2, Mid - 1)); n   Query(L, Mid - 1, max(l1, Mid + 1) - Mid, r1 - Mid, max(l2, Mid + 1) - Mid, n         r2 - Mid); n   return; n } n int main() { n   int l1 = read(), r1 = read(), l2 = read(), r2 = read(); n   Query(1, 1073741823, l1, r1, l2, r2); n   printf( %d n , ans); n   return 0; n } n