#include <bits/stdc++.h> n using namespace std; n int a, b, x, y, cnt; n void RUL(int); n void DLU(int); n void LDR(int); n void URD(int); n void disp_res(int x, int y) { n   printf( %d %d n , x, y); n   exit(0); n } n void RUL(int n) { n   if (cnt == b) { n     disp_res(x, y); n   }; n   if (n <= 0) return; n   URD(n - 1); n   x += 1; n   cnt++; n   RUL(n - 1); n   y += 1; n   cnt++; n   RUL(n - 1); n   x -= 1; n   cnt++; n   DLU(n - 1); n } n void DLU(int n) { n   if (cnt == b) { n     disp_res(x, y); n   }; n   if (n <= 0) return; n   LDR(n - 1); n   y -= 1; n   cnt++; n   DLU(n - 1); n   x -= 1; n   cnt++; n   DLU(n - 1); n   y += 1; n   cnt++; n   RUL(n - 1); n } n void LDR(int n) { n   if (cnt == b) { n     disp_res(x, y); n   }; n   if (n <= 0) return; n   DLU(n - 1); n   x -= 1; n   cnt++; n   LDR(n - 1); n   y -= 1; n   cnt++; n   LDR(n - 1); n   x += 1; n   cnt++; n   URD(n - 1); n } n void URD(int n) { n   if (cnt == b) { n     disp_res(x, y); n   }; n   if (n <= 0) return; n   RUL(n - 1); n   y += 1; n   cnt++; n   URD(n - 1); n   x += 1; n   cnt++; n   URD(n - 1); n   y -= 1; n   cnt++; n   LDR(n - 1); n } n int main() { n   cnt = 0; n   x = 0, y = 0; n   scanf( %d %d , &a, &b); n   URD(a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long int n; n   cin >> n; n   long long int a[n]; n   long long int mx = 0; n   long long int sum = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n     mx = max(mx, a[i]); n     sum += a[i]; n   } n   long long int aa = sum; n   long long int bb = n - 1; n   long long int ans = (aa + bb - 1) / (bb); n   cout << max(ans, mx) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; n int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; n int dx4[] = {1, 0, -1, 0}; n int dy4[] = {0, 1, 0, -1}; n template <typename Arg1> n void __f(const char *name, Arg1 &&arg1) { n   cerr << name <<   :   << arg1 <<   n ; n   ; n } n template <typename Arg1, typename... Args> n void __f(const char *names, Arg1 &&arg1, Args &&...args) { n   const char *comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n template <class A, class B> n ostream &operator<<(ostream &out, const pair<A, B> &a) { n   return out <<  (  << a.first <<  ,  << a.second <<  ) ; n } n template <class A> n ostream &operator<<(ostream &out, const vector<A> &a) { n   for (const A &it : a) out << it <<    ; n   return out; n } n template <class A, class B> n istream &operator>>(istream &in, pair<A, B> &a) { n   return in >> a.first >> a.second; n } n template <class A> n istream &operator>>(istream &in, vector<A> &a) { n   for (A &i : a) in >> i; n   return in; n } n template <typename T, typename T1> n T amax(T &a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T amin(T &a, T1 b) { n   if (b < a) a = b; n   return a; n } n void solve() { n   long long n, m, k; n   cin >> n >> m >> k; n   multiset<long long> mp; n   vector<long long> v(n); n   cin >> v; n   vector<long long> t = v; n   sort((t).begin(), (t).end(), greater<long long>()); n   long long sum = 0; n   for (long long i = 0; i < m * k; i++) { n     mp.insert(t[i]); n     sum += t[i]; n   } n   int i = 0; n   vector<long long> res; n   while (i < n) { n     int j = i; n     int cnt = 0; n     while (j < n && cnt < m) { n       if (mp.find(v[j]) != mp.end()) { n         mp.erase(mp.find(v[j])); n         cnt++; n       } n       j++; n     } n     res.push_back(j); n     if ((int)((mp).size()) == m) { n       break; n     } n     i = j; n   } n   cout << sum <<   n ; n   ; n   cout << res <<   n ; n   ; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const MAX_N = 100001; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> v; n   vector<int> u; n   int t = m; n   for (int i = 0; i < m; i++) { n     v.push_back((i + 1)); n   } n   for (int i = 0; i < m; i++) { n     u.push_back(v[(int)((v.size() + 1) / 2) - 1]); n     v.erase(v.begin() + (int)((v.size() + 1) / 2) - 1); n   } n   for (int i = 0; i < n; i++) { n     cout << u[i - m * ((int)i / m)] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9 + 10; n const int MOD = 1e9 + 7; n const int N = 1e3 + 10; n int n, k; n int a[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   if ((a[1] & 1) && (a[n] & 1) && (n & 1)) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const int M = 1000000000; n char s[30]; n bool answer(int x, int y) { n   printf( %d %d n , x, y); n   fflush(stdout); n   scanf( %s , s); n   return s[0] ==  b ; n } n int n; n int main() { n   scanf( %d , &n); n   bool ty = answer(0, M / 2); n   int vl = 0, vr = M; n   int l = 1, r = M; n   for (int i = 1; i < n; i++) { n     int mid = (l + r) >> 1; n     bool ty2 = answer(mid, M / 2); n     if (ty2 == ty) { n       vl = max(vl, mid); n       l = mid + 1; n     } else { n       vr = min(vr, mid); n       r = mid - 1; n     } n   } n   printf( %d %d %d %d n , vl, 0, vr, M); n } n


#include <bits/stdc++.h> n using namespace std; n int sum[64]; n long long a[200200]; n long long calc() { n   long long ans = 0; n   for (int i = 0; i < 64; i++) { n     ans += (1LL << i) * (sum[i] > 0); n   } n   return ans; n } n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , a + i); n     for (int j = 0; j < 32; j++) { n       sum[j] += ((a[i] >> j) & 1LL); n     } n   } n   long long ans = calc(); n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 32; j++) { n       sum[j] -= ((a[i] >> j) & 1LL); n     } n     long long b = a[i]; n     for (int j = 0; j < k; j++) b *= x; n     for (int j = 0; j < 64; j++) { n       sum[j] += ((b >> j) & 1LL); n     } n     ans = max(ans, calc()); n     for (int j = 0; j < 32; j++) { n       sum[j] += ((a[i] >> j) & 1LL); n     } n     for (int j = 0; j < 64; j++) { n       sum[j] -= ((b >> j) & 1LL); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n vector<int> v; n long long s[100100]; n void init() { n   scanf( %d , &n); n   scanf( %d , &k); n   v.resize(1 + n); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   sort(v.begin() + 1, v.end()); n   v[0] = 0; n   s[0] = v[0]; n   for (int i = 1; i <= n; i++) s[i] = s[i - 1] + v[i]; n   int pos = 1, sol = 1, best = 1, val = v[1]; n   for (int i = 2; i <= n; i++) { n     while ((long long)(i - pos + 1) * v[i] - (s[i] - s[pos - 1]) > k) pos++; n     if (i - pos + 1 > best) { n       best = i - pos + 1; n       val = v[i]; n     } n   } n   cout << best <<     << val << endl; n } n int main() { n   init(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   ; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if ((j + i) % 2 == 0) n         printf( W ); n       else n         printf( B ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[60][60], b[60][60], n, m; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> b[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       long long mn = min(a[i][j], b[i][j]); n       long long mx = max(a[i][j], b[i][j]); n       a[i][j] = mn; n       b[i][j] = mx; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j]) n         return cout <<  Impossible , 0; n       if (b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j]) n         return cout <<  Impossible , 0; n     } n   } n   cout <<  Possible ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1000007; n vector<int> edg[MAX]; n int lvl[MAX]; n multiset<int>* msets[MAX]; n int k; n void mergesets(int frm, int to, int height) { n   if (msets[frm]->size() > msets[to]->size()) { n     swap(msets[frm], msets[to]); n   } n   height *= 2; n   for (int x : *msets[frm]) { n     int g = *(msets[to]->begin()); n     if (g + x - height > k) { n       msets[to]->insert(x); n       continue; n     } n     g = max(g, x); n     msets[to]->erase(msets[to]->begin()); n     msets[to]->insert(g); n   } n   msets[frm]->clear(); n } n void dfs(int u, int p = 0) { n   lvl[u] = lvl[p] + 1; n   msets[u] = new multiset<int>(); n   if (edg[u].size() == 1) { n     msets[u]->insert(lvl[u]); n   } n   for (int v : edg[u]) { n     if (v == p) continue; n     dfs(v, u); n     mergesets(v, u, lvl[u]); n   } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n >> k; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     edg[u].push_back(v); n     edg[v].push_back(u); n   } n   int r = 1; n   for (int i = 2; i <= n; i++) { n     if (edg[i].size() > edg[r].size()) { n       r = i; n     } n   } n   dfs(r); n   cout << msets[r]->size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, cnt1 = 0; n   cin >> n >> k; n   int y = k + 1; n   bool ab[y], a = false; n   for (int i = 0; i < y; i++) ab[i] = false; n   for (int i = 0; i < n; i++) { n     string x; n     cin >> x; n     for (int j = 0; j < x.length(); j++) { n       int h = x[j] -  0 ; n       ab[h] = true; n     } n     for (int l = 0; l < k + 1; l++) n       if (ab[l] == false) a = true; n     if (!a) { n       cnt1++; n     } n     if (a) a = false; n     fill(ab, ab + y, false); n   } n   cout << cnt1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.141592653589793238462643383279; n const long double EPS = 1e-6; n const int INF = 1e9 + 7; n const long long MOD = INF; n const long long maxn = 5e5 + 2; n const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747, n                                1000000158923, 1000000203119}; n int n, m; n int num[maxn]; n int f[maxn]; n int child[maxn]; n int tin[maxn]; n int tout[maxn]; n int cnt = 0; n int timer; n string s; n vector<pair<int, int> > hsh[maxn]; n void add_edge(int a, int b) { n   child[++cnt] = b; n   num[cnt] = f[a]; n   f[a] = cnt; n } n void dfs(int v, int h) { n   tin[v] = ++timer; n   hsh[h].push_back({timer, hsh[h].back().second ^ (1 << (s[v] -  a ))}); n   for (int e = f[v]; e; e = num[e]) { n     dfs(child[e], h + 1); n   } n   tout[v] = ++timer; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   for (int i = (0); i < (n); ++i) hsh[i].resize(1); n   for (int i = (1); i < (n); ++i) { n     int t; n     cin >> t; n     add_edge(t - 1, i); n   } n   cin >> s; n   dfs(0, 0); n   while (m--) { n     int v, h; n     cin >> v >> h; n     v--; n     h--; n     int l = lower_bound(hsh[h].begin(), hsh[h].end(), make_pair(tin[v], -1)) - n             hsh[h].begin() - 1; n     int r = lower_bound(hsh[h].begin(), hsh[h].end(), make_pair(tout[v], -1)) - n             hsh[h].begin() - 1; n     int t = hsh[h][r].second ^ hsh[h][l].second; n     bool ok = t - (t & -t); n     if (!ok) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char inp[5]; n void try_catch(long long int l, long long int r) { n   long long int mid = l + rand() % (r - l + 1); n   printf( %lld %lld n , mid, mid); n   fflush(stdout); n   scanf( %s , inp); n   if (inp[0] ==  Y ) exit(0); n } n int main() { n   srand(time(NULL)); n   long long int n, k; n   cin >> n >> k; n   long long int l = 1, r = n; n   while (1) { n     while (r - l < 60) { n       try_catch(max(1LL, l - k), min(n, r + k)); n       l = max(1LL, l - 2 * k); n       r = min(n, r + 2 * k); n     } n     long long int mid = (l + r) / 2; n     printf( %lld %lld n , l, mid); n     fflush(stdout); n     scanf( %s , inp); n     if (inp[0] ==  Y ) { n       if (l == mid) exit(0); n       r = min(n, mid + k); n       l = max(1LL, l - k); n     } else { n       l = max(1LL, mid - k); n       r = min(n, r + k); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 100000 + 10; n int d[M]; n long long int pred[M]; n long long int a[M]; n long long int dp[110][M]; n long long int pres[M]; n long long int dq[M]; n long long int yk(int i, int k) { n   long long int val = dp[i][k] + pres[k]; n   return val; n } n int main() { n   int n, m, p; n   cin >> n >> m >> p; n   for (int i = 2; i <= n; i++) { n     cin >> d[i]; n     pred[i] = pred[i - 1] + d[i]; n   } n   for (int i = 1; i <= m; i++) { n     int h, t; n     cin >> h >> t; n     int val = t - pred[h]; n     a[i] = val; n   } n   sort(a + 1, a + m + 1); n   for (int i = 1; i <= m; i++) { n     pres[i] = pres[i - 1] + a[i]; n   } n   for (int i = 1; i <= m; i++) { n     dp[1][i] = (i - 0) * a[i] - (pres[i] - pres[0]); n   } n   for (int i = 2; i <= p; i++) { n     int s = 0; n     int t = 0; n     for (int j = 1; j <= m; j++) { n       while ((t - s) >= 2 && n              (yk(i - 1, dq[t - 1]) - yk(i - 1, dq[t - 2])) * (j - dq[t - 1]) > n                  (yk(i - 1, j) - yk(i - 1, dq[t - 1])) * n                      (dq[t - 1] - dq[t - 2])) { n         t--; n       } n       dq[t] = j; n       t++; n       while ((t - s) >= 2 && n              dp[i - 1][dq[s]] - dq[s] * a[j] + pres[dq[s]] > n                  dp[i - 1][dq[s + 1]] - dq[s + 1] * a[j] + pres[dq[s + 1]]) { n         s++; n       } n       dp[i][j] = n           dp[i - 1][dq[s]] + (j - dq[s]) * a[j] - (pres[j] - pres[dq[s]]); n     } n   } n   cout << dp[p][m] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n int n, t; n int TM[maxn], wait, ans; n priority_queue<int> in; n int main() { n   scanf( %d%d , &n, &t); n   for (int i = 1; i <= n; ++i) scanf( %d , &TM[i]); n   for (int i = 1; i <= n + 1; ++i) { n     wait = t - i; n     if (wait < 0) break; n     while (!in.empty() && in.top() > wait) in.pop(); n     ans = max(ans, (int)in.size()); n     in.push(TM[i] - i); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void run() { n   int n; n   scanf( %d , &n); n   if (n & 1) n     printf( %d %d n , 9, n - 9); n   else n     printf( %d %d n , 4, n - 4); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int k; n   cin >> n >> k; n   string a; n   cin >> a; n   bool no = false; n   for (int i = 0; i < a.size(); i++) { n     if (a[i] ==  N  && (i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) { n       int count = 0; n       int j; n       for (j = i; j < i + k; j++) { n         if (a[j] ==  N ) n           count++; n         else n           break; n       } n       if (count == k && j < a.size() && a[j] ==  N ) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   for (int i = 0; i < a.size(); i++) { n     if ((i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) { n       int count = 0; n       int j; n       for (j = i; j < i + k; j++) { n         if (a[j] ==  ?  || a[j] ==  N ) n           count++; n         else n           break; n       } n       if (count == k && (i + k == a.size() || a[j] !=  N )) { n         cout <<  YES ; n         return 0; n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n int a, n, m, k, p; n int main() { n   std::cin >> n >> m, a = 0, p = 1; n   for (int i = 1; i <= n; ++i) { n     std::cin >> k; n     if (a + k <= m) n       a += k; n     else n       a = k, ++p; n   } n   std::cout << p; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n template <class T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T, class T1> n inline void gn(T &first, T1 &second) { n   gn(first); n   gn(second); n } n template <class T, class T1, class T2> n inline void gn(T &first, T1 &second, T2 &z) { n   gn(first); n   gn(second); n   gn(z); n } n template <class T> n inline void print(T first) { n   if (first < 0) { n     putchar( - ); n     return print(-first); n   } n   if (first < 10) { n     putchar( 0  + first); n     return; n   } n   print(first / 10); n   putchar(first % 10 +  0 ); n } n template <class T> n inline void printsp(T first) { n   print(first); n   putchar(   ); n } n template <class T> n inline void println(T first) { n   print(first); n   putchar(  n ); n } n template <class T, class U> n inline void print(T first, U second) { n   printsp(first); n   println(second); n } n template <class T, class U, class V> n inline void print(T first, U second, V z) { n   printsp(first); n   printsp(second); n   println(z); n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n int fail[101010]; n char s[101010], s1[101010], t[101010], t1[101010], s2[101010]; n void build_fail_function(char B[], int len) { n   int j = fail[0] = -1; n   for (int i = 1; i < len; i++) { n     while (j != -1 and B[j + 1] != B[i]) j = fail[j]; n     if (B[j + 1] == B[i]) j++; n     fail[i] = j; n   } n } n int main() { n   int n; n   gn(n); n   scanf( %s%s , s, t); n   strcpy(s1, s); n   strcpy(t1, t); n   sort(s1, s1 + n); n   sort(t1, t1 + n); n   if (strcmp(s1, t1)) return puts( -1 ), 0; n   int now = 0, m; n   vector<int> ans; n   char *p, *q; n   while (now < n) { n     while (now < n && s[now] == t[now]) now++; n     q = s + now; n     m = n - now; n     p = t + now; n     build_fail_function(p, m); n     int j = -1, res = 0, k = -1; n     for (int i = 0; i < m; i++) { n       while (j != -1 and p[j + 1] != q[i]) j = fail[j]; n       if (p[j + 1] == q[i]) j++; n       if (res < j + 1) res = j + 1, k = i; n       if (j == m - 1) j = fail[j]; n     } n     int A = now, B = k + 1 - res, C = res, D = n - A - B - C; n     ans.push_back(n); n     if (A + B) ans.push_back(A + B); n     ans.push_back(n); n     if (A) ans.push_back(A); n     for (int i = 0; i < B; i++) s1[i] = q[B - 1 - i]; n     s1[B] = 0; n     for (int i = 0; i < D; i++) t1[i] = q[i + k + 1]; n     t1[D] = 0; n     for (int i = 0; i < C; i++) s2[i] = q[k - res + 1 + i]; n     s2[C] = 0; n     for (int i = 0; i < C; i++) *q = s2[i], q++; n     for (int i = 0; i < D; i++) *q = t1[i], q++; n     for (int i = 0; i < B; i++) *q = s1[i], q++; n     now += res; n   } n   println(ans.size()); n   for (int i = 0; i < ans.size(); i++) printsp(ans[i]); n   puts(  ); n   assert(strcmp(s, t) == 0); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAXK = 1 << 12; n const int P = 7340033; n const int G = 3; n const int MAXH = 30; n int dp[MAXH + 7][MAXK + 7], buff[MAXK + 7]; n int qpow(int a, int b) { n   if (b == 0) return 1; n   if (a == 0) return 0; n   int aux = qpow(1LL * a * a % P, b >> 1); n   if (b & 1) aux = 1LL * aux * a % P; n   return aux; n } n inline int inv(int x) { return qpow(x, P - 2); } n void NTT(int *a, int N, int dir) { n   int t = 0; n   for (int i = (0); i <= (N - 1); ++i) { n     if (t < i) swap(a[t], a[i]); n     for (int j = (N >> 1); (t ^= j) < j; j >>= 1) n       ; n   } n   for (int i = 2; i <= N; i <<= 1) { n     int wn = qpow(G, (P - 1) / i); n     for (int j = 0; j < N; j += i) { n       int w = 1, t; n       for (int k = 0; k < (i >> 1); k++, w = 1LL * w * wn % P) { n         t = 1LL * w * a[j + k + (i >> 1)] % P; n         a[j + k + (i >> 1)] = a[j + k] - t; n         a[j + k] = a[j + k] + t; n         if (a[j + k + (i >> 1)] < 0) a[j + k + (i >> 1)] += P; n         if (a[j + k] >= P) a[j + k] -= P; n       } n     } n   } n   if (dir == -1) { n     for (int i = 1; i < (N >> 1); i++) swap(a[i], a[N - i]); n     int INV_N = inv(N); n     for (int i = (0); i <= (N - 1); ++i) a[i] = 1LL * a[i] * INV_N % P; n   } n } n void pre() { n   dp[0][0] = 1; n   for (int i = (1); i <= (MAXH); ++i) { n     memset(buff, 0, sizeof(buff)); n     for (int j = (0); j <= (1000); ++j) buff[j] = dp[i - 1][j]; n     NTT(buff, MAXK, 1); n     for (int j = (0); j <= (MAXK); ++j) buff[j] = qpow(buff[j], 4); n     NTT(buff, MAXK, -1); n     for (int j = (1); j <= (1000); ++j) dp[i][j] = buff[j - 1]; n     dp[i][0] = 1; n   } n } n inline int height(int N) { n   int h = 0; n   while (N > 1 && N & 1) { n     ++h; n     N = (N - 1) >> 1; n   } n   return h; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   pre(); n   int Q; n   cin >> Q; n   while (Q--) { n     int n, k; n     cin >> n >> k; n     cout << dp[height(n)][k] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int inf = 1e5 + 10; n using namespace std; n int main() { n   int to[5][5]; n   int a[5]; n   memset(a, 0, sizeof(a)); n   memset(to, 0, sizeof(to)); n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  0 ) n       a[0]++; n     else if (s[i] ==  1 ) n       a[1]++; n     else if (s[i] ==  2 ) n       a[2]++; n   } n   n /= 3; n   for (int i = 1; i <= 2; i++) { n     for (int j = 0; j < i; j++) { n       if (a[j] < a[i] && a[i] > n && a[j] < n) { n         to[i][j] = min(n - a[j], a[i] - n); n         int p = a[i]; n         int q = a[j]; n         a[i] -= min(n - q, p - n); n         a[j] += min(n - q, p - n); n       } else if (a[j] > a[i] && a[i] < n && a[j] > n) { n         int p = a[i]; n         int q = a[j]; n         to[j][i] = min(n - p, q - n); n         a[j] -= min(n - p, q - n); n         a[i] += min(n - p, q - n); n       } n     } n   } n   for (int i = 0; i < 2; i++) { n     for (int j = 2; j > i; j--) { n       int v = 3 * n - 1; n       while (to[i][j] && v >= 0) { n         if (s[v] -  0  == i) { n           s[v] =  0  + j; n           to[i][j]--; n         } n         v--; n       } n     } n   } n   for (int i = 1; i <= 2; i++) { n     for (int j = 0; j < i; j++) { n       int v = 0; n       while (to[i][j] && v < 3 * n) { n         if (s[v] -  0  == i) { n           s[v] =  0  + j; n           to[i][j]--; n         } n         v++; n       } n     } n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x = 0; n   string s; n   cin >> n; n   cin.ignore(); n   for (int i = 1; i <= n; i++) { n     getline(cin, s); n     if (s[1] ==  + ) { n       x++; n       continue; n     } n     if (s[1] ==  - ) { n       x--; n       continue; n     } n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1000000007; n long long POW(long long a, long long b, long long MMM = MOD) { n   long long ret = 1; n   for (; b; b >>= 1, a = (a * a) % MMM) n     if (b & 1) ret = (ret * a) % MMM; n   return ret; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { n   if (a == 0 || b == 0) return a + b; n   return a * (b / gcd(a, b)); n } n int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1}; n int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1}; n int main() { n   int n; n   scanf( %d , &n); n   puts( YES ); n   while (n--) { n     int x1, y1, x2, y2; n     scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n     printf( %d n , (x1 & 1) % 2 + ((y1 & 1) % 2) * 2 + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, k, n, day, ans, flag; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   day = 1; n   ans = 0; n   j = 0; n   while (1) { n     flag = 0; n     for (i = j; i < n; i++) { n       if (a[i] >= day) { n         j = i + 1; n         flag = 1; n         ans++; n         break; n       } n     } n     if (flag == 0) break; n     day++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long bin_pow(long long a, long long b) { n   if (b == 0) return 1; n   if (b % 2 == 0) { n     long long t = bin_pow(a, b / 2); n     return t * t % 1000000007; n   } else n     return a * bin_pow(a, b - 1) % 1000000007; n } n vector<long long> graph[500000]; n bool used[500000]; n long long w[500000], comp; n map<pair<long long, long long>, long long> mp1; n void dfs(long long v) { n   used[v] = 1; n   comp++; n   for (auto u : graph[v]) { n     if (w[u] == 0 || used[u] || mp1[{u, v}] == 0) continue; n     dfs(u); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0, n             ans = 0, mn = LLONG_MAX, mx = LLONG_MIN; n   cin >> n >> m >> k; n   vector<long long> a(n), b; n   map<long long, vector<pair<long long, long long>>> mp; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     x--, y--; n     z = a[x] ^ a[y]; n     b.push_back(z); n     mp[z].push_back({x, y}); n     graph[x].push_back(y); n     graph[y].push_back(x); n   } n   sort(b.begin(), b.end()); n   b.erase(unique(b.begin(), b.end()), b.end()); n   for (int i = 0; i < b.size(); i++) { n     z = b[i]; n     long long k1 = 0; n     l = 0; n     for (auto u : mp[z]) { n       x = u.first, y = u.second; n       w[x] = w[y] = 1; n       mp1[{x, y}] = mp1[{y, x}] = 1; n     } n     for (auto u : mp[z]) { n       x = u.first, y = u.second; n       if (used[x]) continue; n       comp = 0; n       dfs(x); n       l += comp; n       k1++; n     } n     x = bin_pow(2, n - l) * bin_pow(2, k1) % 1000000007; n     ans += x; n     ans %= 1000000007; n     for (auto u : mp[z]) { n       x = u.first, y = u.second; n       w[x] = w[y] = used[x] = used[y] = 0; n       mp1[{x, y}] = mp1[{y, x}] = 0; n     } n   } n   t = ((bin_pow(2, k) - (long long)b.size()) % 1000000007 + 1000000007) % n       1000000007; n   t *= bin_pow(2, n); n   t %= 1000000007; n   ans += t; n   ans %= 1000000007; n   cout << ans; n   return 0; n } n


#include <iostream> n  n using namespace std; n  n long long n,mod; n long long cnt[55][2505]; n long long cntS[55][2505]; n long long per[55]; n long long ans[55]; n  n void calcCnt() n { n     cnt[0][0]=1; n  n     for(int i=1;i<=n;i++) n     { n         for(int inv=0;inv<=i*i;inv++) n             for(int nval=1;nval<=i;nval++) n             { n                 if(inv>=i-nval) n                 { n                     cnt[i][inv]+=cnt[i-1][inv-(i-nval)]; n                     cnt[i][inv]%=mod; n                 } n             } n  n         cntS[i][0]=cnt[i][0]; n         for(int inv=1;inv<=i*i;inv++) n             cntS[i][inv]=(cntS[i][inv-1]+cnt[i][inv])%mod; n     } n } n  n void calcPer() n { n     for(int i=1;i<=n;i++) n         for(int dif=1;dif<i;dif++) n         { n             long long nr=i-dif; n             for(int invP=dif+1;invP<=i*i;invP++) n             { n                 long long nans=cnt[i-1][invP]*cntS[i-1][invP-dif-1]; n                 nans%=mod; n                 nans*=nr; n                 nans%=mod; n  n                 per[i]+=nans; n                 per[i]%=mod; n             } n         } n } n void calcAns() n { n     for(int i=1;i<=n;i++) n     { n         ans[i]=i*ans[i-1]+per[i]; n         ans[i]%=mod; n     } n } n int main() n { n     cin>>n>>mod; n  n     calcCnt(); n     calcPer(); n     calcAns(); n  n     cout<<ans[n]; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int i, j, k, p, len, n; n   cin >> n >> k >> s; n   int arr[30] = {0}; n   char x =  a ; n   for (i = 0; i < 26; i++) { n     x =  a  + i; n     p = 0; n     for (j = 0; j < n; j++) { n       if (s[j] == x) n         p++; n       else n         p = 0; n       if (p == k) { n         arr[i]++; n         p = 0; n       } n     } n   } n   p = 0; n   for (i = 0; i < 26; i++) { n     p = max(p, arr[i]); n   } n   cout << p << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n int n; n int f[MAXN]; n bool read() { n   if (scanf( %d , &n) < 1) { n     return 0; n   } n   for (int i = 0; i < int(n); ++i) { n     scanf( %d , &f[i]); n     --f[i]; n   } n   return 1; n } n vector<int> inv_f[MAXN]; n int g[MAXN]; n int h[MAXN]; n bool solve() { n   for (int i = 0; i < int(n); ++i) { n     inv_f[i].clear(); n   } n   for (int i = 0; i < int(n); ++i) { n     inv_f[f[i]].push_back(i); n   } n   memset(g, -1, sizeof g); n   int m = 0; n   for (int i = 0; i < int(n); ++i) { n     if (inv_f[i].empty()) { n       continue; n     } n     if (f[i] != i) { n       return 0; n     } n     for (int j : inv_f[i]) { n       g[j] = m; n     } n     h[m] = i; n     ++m; n   } n   for (int x = 0; x < int(m); ++x) { n     assert(g[h[x]] == x); n   } n   for (int x = 0; x < int(n); ++x) { n     assert(h[g[x]] == f[x]); n   } n   printf( %d n , m); n   for (int i = 0; i < int(n); ++i) { n     printf( %d  , g[i] + 1); n   } n   puts(  ); n   for (int i = 0; i < int(m); ++i) { n     printf( %d  , h[i] + 1); n   } n   puts(  ); n   return 1; n } n int main() { n   while (read()) { n     if (!solve()) { n       puts( -1 ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = (1 << 22) + 5; n int full, n, m; n bool v[MAX], b[MAX], h[MAX]; n void dfsans(int now); n void dfs(int now) { n   if (v[now]) return; n   v[now] = true; n   if (h[now]) dfsans(now); n   for (int i = 0; i < n; i++) { n     if (!(now & (1 << i))) continue; n     dfs(now ^ (1 << i)); n   } n } n void dfsans(int now) { n   if (b[now]) return; n   b[now] = true; n   dfs(now ^ full); n } n int main() { n   scanf( %d%d , &n, &m); n   full = (1 << n) - 1; n   for (int i = 0; i < m; i++) { n     int x; n     scanf( %d , &x); n     h[x] = true; n   } n   int ans = 0; n   for (int i = 0; i < (full + 1); i++) { n     if (!h[i] || b[i]) continue; n     ans++; n     dfsans(i); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int a[n]; n     for (long long int i = 0; i < n; i++) { n       cin >> a[i]; n       a[i]--; n     } n     vector<long long int> pos(n); n     for (long long int i = 0; i < n; i++) { n       pos[a[i]] = i; n     } n     long long int mnpos = pos[0]; n     long long int mx = pos[0]; n     vector<long long int> ans(n); n     for (long long int i = 0; i < n; i++) { n       mnpos = min(mnpos, pos[i]); n       mx = max(mx, pos[i]); n       if (mx - mnpos == i) { n         ans[i] = 1; n       } else { n         ans[i] = 0; n       } n     } n     for (long long int x : ans) cout << x; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, a, x, b, y; n   cin >> n >> a >> x >> b >> y; n   while (1) { n     if (a == b) { n       cout <<  YES n ; n       return 0; n     } n     if (a == x || b == y) { n       break; n     } n     if (++a > n) { n       a = 1; n     } n     if (--b < 1) { n       b = n; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200000; n int c[MAXN + 10], d[MAXN + 10], l[MAXN + 10], r[MAXN + 10]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> x(n); n   for (int i = 0; i < n; ++i) { n     cin >> x[i]; n     ++c[x[i]]; n   } n   for (int i = 1; i <= MAXN; ++i) { n     if (c[i] == 0) continue; n     if (c[i] == 1) { n       d[i] = 0; n       l[i] = 1; n     } else { n       d[i] = c[i]; n       l[i] = d[i] + l[i - 1]; n     } n   } n   memset(d, 0, sizeof(d)); n   for (int i = MAXN; i >= 1; --i) { n     if (c[i] == 0) continue; n     if (c[i] == 1) { n       d[i] = 0; n       r[i] = 1; n     } else { n       d[i] = c[i]; n       r[i] = d[i] + r[i + 1]; n     } n   } n   int ans = 0, p = -1; n   for (int i = 1; i <= MAXN; ++i) { n     if (l[i] + r[i] - c[i] > ans) { n       ans = l[i] + r[i] - c[i]; n       p = i; n     } n   } n   if (ans == 1) { n     for (int i = 1; i + 1 <= MAXN; ++i) { n       if (c[i] > 0 && c[i + 1] > 0) { n         cout << 2 << endl; n         cout << i <<     << i + 1 << endl; n         return 0; n       } n     } n     cout << ans << endl; n     cout << p << endl; n     return 0; n   } n   vector<int> cir; n   int q = p; n   while (c[p] > 1) { n     cir.push_back(p); n     --c[p]; n     ++p; n   } n   while (p > q) { n     while (c[p] > 0) { n       cir.push_back(p); n       --c[p]; n     } n     --p; n   } n   cir.push_back(p); n   --c[p]; n   --p; n   while (c[p] > 1) { n     cir.push_back(p); n     --c[p]; n     --p; n   } n   while (p <= q) { n     while (c[p] > 0) { n       cir.push_back(p); n       --c[p]; n     } n     ++p; n   } n   cout << ans << endl; n   for (int i : cir) cout << i <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, q; n pair<int, int> pro[100010]; n long long cross(int x1, int y1, int x2, int y2) { n   return x1 * (long long)y2 - x2 * (long long)y1; n } n double cross2(double x1, double y1, double x2, double y2) { n   return x1 * y2 - x2 * y1; n } n bool check(pair<int, int> c, pair<int, int> b, pair<int, int> a) { n   return cross(b.first - a.first, b.second - a.second, c.first - b.first, n                c.second - b.second) >= 0; n } n pair<int, int> st[100010]; n int tp = -1; n int main() { n   scanf( %d%d%d , &n, &p, &q); n   int maxa = 0, maxb = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &pro[i].first, &pro[i].second); n     maxa = max(maxa, pro[i].first); n     maxb = max(maxb, pro[i].second); n   } n   sort(pro + 1, pro + n + 1); n   st[++tp] = make_pair(0, maxb); n   for (int i = 1; i <= n; i++) { n     while (tp > 0 && check(pro[i], st[tp], st[tp - 1])) tp--; n     st[++tp] = pro[i]; n   } n   st[++tp] = make_pair(maxa, 0); n   int line; n   for (int i = 0; i < tp; i++) { n     if ((atan2(q, p) - atan2(st[i + 1].second, st[i + 1].first) >= -1e-9) && n         (atan2(st[i].second, st[i].first) - atan2(q, p) >= -1e-9)) n       line = i; n   } n   double lo = 0, hi = 1e6; n   while (lo < hi - 1e-9) { n     double mi = (lo + hi) / 2; n     if ((0 - cross2(p / mi - st[line].first, q / mi - st[line].second, n                     p / mi - st[line + 1].first, n                     q / mi - st[line + 1].second) >= n          -1e-9)) n       hi = mi; n     else n       lo = mi; n   } n   printf( %.10f n , lo); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t, x, c = 0, value[1000001], sign[1000001]; n stack<int> s; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &value[i]); n     sign[i] = 1; n   } n   scanf( %d , &t); n   for (int i = 1; i <= t; i++) { n     scanf( %d , &x); n     sign[x] = -1; n   } n   for (int i = n; i >= 1; i--) { n     if (sign[i] == -1) { n       s.push(i); n     } else { n       if (!s.empty() && value[i] == value[s.top()]) { n         s.pop(); n       } else { n         s.push(i); n         sign[i] = -1; n       } n     } n   } n   if (!s.empty()) { n     printf( NO ); n   } else { n     printf( YES n ); n     for (int i = 1; i <= n; i++) { n       printf( %d  , value[i] * sign[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int i, j, a = 0, b = 0, c, k, n; n   std::vector<int> v; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> k; n     for (j = 0; j < k / 2; j++) cin >> c, a += c; n     if (k & 1) cin >> c, v.push_back(c); n     for (j = 0; j < k / 2; j++) cin >> c, b += c; n   } n   sort(v.begin(), v.end(), greater<int>()); n   for (i = 0; i < v.size(); i++) n     if (i & 1) n       b += v[i]; n     else n       a += v[i]; n   cout << a <<     << b; n } n


#include <bits/stdc++.h> n struct sur { n   int c1, c2, c3, c4; n   inline bool colsame() { return c1 == c3 && c2 == c4 && c1 != c2; } n   inline bool same() { return c1 == c2 && c2 == c3 && c3 == c4; } n   inline void right_rotate() { n     int t = c4; n     c4 = c2; n     c2 = c1; n     c1 = c3; n     c3 = t; n     return; n   } n   inline void left_rotate() { n     int t = c4; n     c4 = c3; n     c3 = c1; n     c1 = c2; n     c2 = t; n     return; n   } n   inline void rotate() { n     int t = c1; n     c1 = c4; n     c4 = t; n     t = c2; n     c2 = c3; n     c3 = t; n     return; n   } n   inline void read() { n     scanf( %d%d%d%d , &c1, &c2, &c3, &c4); n     return; n   } n   friend inline bool round(sur s1, sur s2, sur s3, sur s4) { n     if (!(s1.colsame() && s2.colsame() && s3.colsame() && s4.colsame())) n       return 0; n     if (s1.c1 == s2.c2 && s2.c1 == s3.c2 && s3.c1 == s4.c2 && s4.c1 == s1.c2) n       return 1; n     if (s1.c2 == s2.c1 && s2.c2 == s3.c1 && s3.c2 == s4.c1 && s4.c2 == s1.c1) n       return 1; n     return 0; n   } n } code[7]; n template <class Tp> n inline void swap(Tp &a, Tp &b) { n   Tp t = a; n   a = b; n   b = t; n   return; n } n int main() { n   int i; n   for (i = 1; i <= 6; i++) code[i].read(); n   if (code[4].same() && code[5].same()) { n     code[6].rotate(); n     puts(round(code[1], code[2], code[3], code[6]) ?  YES  :  NO ); n   } else if (code[1].same() && code[3].same()) { n     code[4].right_rotate(); n     code[2].right_rotate(); n     code[5].right_rotate(); n     code[6].right_rotate(); n     puts(round(code[4], code[2], code[5], code[6]) ?  YES  :  NO ); n   } else if (code[2].same() && code[6].same()) { n     code[1].right_rotate(); n     code[3].left_rotate(); n     code[4].rotate(); n     puts(round(code[4], code[1], code[5], code[3]) ?  YES  :  NO ); n   } else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Team { n   string name; n   int fi, se, th; n } t[60]; n int cmp(Team a, Team b) { n   if (a.fi != b.fi) n     return a.fi > b.fi; n   else if (a.se != b.se) n     return a.se > b.se; n   else n     return a.th > b.th; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> t[i].name; n     t[i].fi = t[i].se = t[i].th = 0; n   } n   for (int i = 0; i < n * (n - 1) / 2; i++) { n     string te, t1, t2; n     int a, b; n     char ch; n     cin >> te >> a >> ch >> b; n     t1 = te.substr(0, te.find( - )); n     t2 = te.substr(te.find( - ) + 1); n     for (int j = 0; j < n; j++) { n       if (t[j].name == t1) { n         if (a > b) n           t[j].fi += 3; n         else if (a == b) n           t[j].fi += 1; n         t[j].se += a - b; n         t[j].th += a; n       } n       if (t[j].name == t2) { n         if (a < b) n           t[j].fi += 3; n         else if (a == b) n           t[j].fi += 1; n         t[j].se += b - a; n         t[j].th += b; n       } n     } n   } n   string ans[30]; n   sort(t, t + n, cmp); n   for (int i = 0; i < n / 2; i++) ans[i] = t[i].name; n   sort(ans, ans + n / 2); n   for (int i = 0; i < n / 2; i++) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const double pi = 3.14159265358979323846264338; n inline long long multi(long long x, long long y) { n   long long tmp = n       (x * y - n        (long long)((long double)x / 998244353 * y + 1.0e-8) * 998244353); n   return tmp < 0 ? tmp + 998244353 : tmp; n } n long long _ceil(long long a, long long b); n long long _floor(long long a, long long b) { n   return b < 0 ? _floor(-a, -b) : a < 0 ? -_ceil(-a, b) : a / b; n } n long long _ceil(long long a, long long b) { n   return b < 0 ? _ceil(-a, -b) : a < 0 ? -_floor(-a, b) : (a + b - 1) / b; n } n long long exgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long d = exgcd(b, a % b, y, x); n   y -= x * (a / b); n   return d; n } n int32_t main() { n   ios ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long a1, a2, b1, b2, x0, y0; n   long long l, r; n   cin >> a1 >> b1 >> a2 >> b2 >> l >> r; n   l = max(0ll, _ceil(l - b1, a1)); n   r = _floor(r - b1, a1); n   if (l > r) { n     cout << 0 <<   n ; n     return 0; n   } n   long long g = exgcd(a1, -1 * a2, x0, y0); n   long long m = b2 - b1; n   if (m % g) { n     cout << 0 <<   n ; n     return 0; n   } n   if (g < 0) { n     g *= -1; n     x0 *= -1; n     y0 *= -1; n   } n   long long L = _ceil(r * g - x0 * m, -a2); n   long long R = _floor(l * g - x0 * m, -a2); n   R = min(R, _floor(y0 * m, a1)); n   long long ans = max(0ll, R - L + 1); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct yts { n   long long dp[210][210]; n } a, ans, t; n int ch[210][26], fail[210], q[210], root = 1; n long long w[210], b[210]; n int n, m, tot = 1; n char s[210]; n long long L; n void insert(int id) { n   int x = root, len = strlen(s + 1); n   for (int i = 1; i <= len; i++) { n     int t = s[i] -  a ; n     if (!ch[x][t]) ch[x][t] = ++tot; n     x = ch[x][t]; n   } n   w[x] += b[id]; n } n void build_fail() { n   int l = 0, r = 0; n   for (int i = 0; i < 26; i++) n     if (ch[root][i]) n       fail[ch[root][i]] = root, q[++r] = ch[root][i]; n     else n       ch[root][i] = root; n   while (l < r) { n     int x = q[++l]; n     w[x] += w[fail[x]]; n     for (int i = 0; i < 26; i++) n       if (ch[x][i]) n         fail[ch[x][i]] = ch[fail[x]][i], q[++r] = ch[x][i]; n       else n         ch[x][i] = ch[fail[x]][i]; n   } n } n void mul(yts &c, yts &a, yts &b) { n   memset(t.dp, -1, sizeof(t.dp)); n   for (int k = 1; k <= tot; k++) n     for (int i = 1; i <= tot; i++) n       for (int j = 1; j <= tot; j++) n         if (a.dp[i][k] != -1 && b.dp[k][j] != -1) n           t.dp[i][j] = max(t.dp[i][j], a.dp[i][k] + b.dp[k][j]); n   for (int i = 1; i <= tot; i++) n     for (int j = 1; j <= tot; j++) c.dp[i][j] = t.dp[i][j]; n } n void power() { n   memset(ans.dp, -1, sizeof(ans.dp)); n   for (int i = 1; i <= tot; i++) ans.dp[i][i] = 0; n   while (L) { n     if (L & 1) mul(ans, ans, a); n     mul(a, a, a); n     L >>= 1; n   } n } n void build_a() { n   memset(a.dp, -1, sizeof(a.dp)); n   for (int i = 1; i <= tot; i++) n     for (int c = 0; c < 26; c++) { n       if (a.dp[i][ch[i][c]] == -1) a.dp[i][ch[i][c]] = 0; n       a.dp[i][ch[i][c]] += w[ch[i][c]]; n     } n } n int main() { n   scanf( %d%I64d , &n, &L); n   for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     insert(i); n   } n   build_fail(); n   build_a(); n   power(); n   long long ANS = 0; n   for (int i = 1; i <= tot; i++) n     if (ans.dp[root][i] != -1) ANS = max(ANS, ans.dp[root][i]); n   printf( %I64d n , ANS); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3) n using namespace std; n template <typename T1, typename T2> n void ckmin(T1 &a, T2 b) { n   if (a > b) a = b; n } n template <typename T1, typename T2> n void ckmax(T1 &a, T2 b) { n   if (a < b) a = b; n } n template <typename T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n int read() { n   int x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f |= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar(); n   return f ? -x : x; n } n const int N = 200005; n long long a[N], b[N], sum; n int n, k; n int main() { n   n = read(), k = read(); n   for (register int i = 1; i <= k; i++) n     a[i] = read(), b[i] = read(), sum += b[i]; n   if (sum > n) puts( -1 ), exit(0); n   if (sum < n) puts( 1 ), exit(0); n   long long res = 0; n   for (register int i = 1; i <= k; i++) res = (res + a[i] * b[i]) % n; n   res = (res - 1ll * n * (n + 1) / 2) % n; n   if (res == 0) n     puts( 1 ); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct problem { n   int score1, score2; n   int time1, time2; n   double fail; n   long long expscore1, expscore2; n   double ratio; n }; n int N, T; n problem P[1010]; n long long dpscore[1010][1600]; n double dppenal[1010][1600]; n void update(int n, int t, long long score, double penal) { n   if (n <= N && t <= T && n       (score > dpscore[n][t] || n        (score == dpscore[n][t] && penal < dppenal[n][t]))) { n     dpscore[n][t] = score; n     dppenal[n][t] = penal; n   } n } n int main(void) { n   int i, j; n   cin >> N >> T; n   for ((i) = 0; (i) < (int)(N); (i)++) { n     cin >> P[i].score1 >> P[i].score2 >> P[i].time1 >> P[i].time2 >> P[i].fail; n     P[i].expscore1 = (long long)P[i].score1 * (long long)1000000; n     int tmp = (int)(P[i].fail * 1000000 + 0.5); n     P[i].expscore2 = (long long)P[i].score2 * (long long)(1000000 - tmp); n     P[i].ratio = n         ((tmp == 1000000) ? (1.0E+18) n                           : (P[i].time2 * P[i].fail / (1.0 - P[i].fail))); n   } n   for ((i) = 0; (i) < (int)(N + 5); (i)++) n     for ((j) = 0; (j) < (int)(N - 1); (j)++) n       if (P[j].ratio > P[j + 1].ratio) swap(P[j], P[j + 1]); n   for ((i) = 0; (i) < (int)(N + 1); (i)++) n     for ((j) = 0; (j) < (int)(T + 1); (j)++) dpscore[i][j] = -1; n   dpscore[0][0] = 0; n   for ((i) = 0; (i) < (int)(N); (i)++) n     for ((j) = 0; (j) < (int)(T + 1); (j)++) n       if (dpscore[i][j] != -1) { n         long long score = dpscore[i][j]; n         double penal = dppenal[i][j]; n         update(i + 1, j, score, penal); n         update(i + 1, j + P[i].time1, score + P[i].expscore1, n                penal + P[i].time1); n         double fail_penalty = penal + P[i].time1; n         double ac_penalty = j + P[i].time1 + P[i].time2; n         update(i + 1, j + P[i].time1 + P[i].time2, n                score + P[i].expscore1 + P[i].expscore2, n                fail_penalty * P[i].fail + ac_penalty * (1.0 - P[i].fail)); n       } n   long long score = 0; n   double penal = 0.0; n   for ((i) = 0; (i) < (int)(T + 1); (i)++) { n     long long score2 = dpscore[N][i]; n     double penal2 = dppenal[N][i]; n     if (score2 > score || (score2 == score && penal2 < penal)) { n       score = score2; n       penal = penal2; n     } n   } n   printf( %.12f %.12f n , score / 1000000.0, penal); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n const int MAXN = 600; n int n, m; n int x, y, cnt; n bool us[MAXN][MAXN]; n string s; n int main() { n   ios_base ::sync_with_stdio(false); n   cin >> n >> m >> x >> y; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (us[x][y]) n       cout <<  0  ; n     else n       cout <<  1  ; n     us[x][y] = true; n     if (s[i] ==  U ) x--; n     if (s[i] ==  D ) x++; n     if (s[i] ==  L ) y--; n     if (s[i] ==  R ) y++; n     if (x > n) x = n; n     if (x == 0) x = 1; n     if (y > m) y = m; n     if (y == 0) y = 1; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (!us[i][j]) cnt++; n   cout << cnt; n } n


#include <bits/stdc++.h> n int a[100010]; n int main() { n   int n; n   int b = 0, c = 0, d = 0, td = 0, ex1 = 0, ex2 = 0, ex; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == 1) n       b++; n     else if (a[i] == 2) n       c++; n     else if (a[i] == 3) n       d++; n     else if (a[i] == 4) n       td++; n   } n   td += d; n   if (c % 2 == 0) { n     td += (c / 2); n   } else { n     ex2 = (c % 2); n     td += (c / 2); n   } n   if (b > d) { n     ex1 = b - d; n   } n   ex = (2 * ex2) + ex1; n   if (ex % 4 == 0) n     td += (ex / 4); n   else n     td += (ex / 4) + 1; n   printf( %d , td); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string arr[n], mx =  2011 ; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int p = n - 1; p >= 0; p--) { n     string maxi =  0000 ; n     for (int i = 0; i <= 3; i++) { n       char s = arr[p][i]; n       for (int j = 9; j >= 0; j--) { n         arr[p][i] = char( 0  + j); n         if (arr[p] <= mx && arr[p] >=  1000 ) { n           if (arr[p] > maxi) maxi = arr[p]; n         } n       } n       arr[p][i] = s; n     } n     if (maxi ==  0000 ) { n       cout <<  No solution  << endl; n       return 0; n     } n     arr[p] = maxi; n     mx = maxi; n   } n   for (int i = 0; i < n; i++) { n     cout << arr[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int num = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) num *= 10, num += ch - 48, ch = getchar(); n   return num; n } n int x, y; n int main() { n   int n = read(); n   for (int i = 1; i <= n; i++) x |= read(); n   for (int i = 1; i <= n; i++) y |= read(); n   printf( %d n , x + y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct solution { n   int t, n{0}; n   vector<int> a{}; n   void get_data() { cin >> t; } n   void solve() { n     while (t--) { n       cin >> n; n       a.clear(); n       a.resize(n); n       for (auto &el : a) cin >> el; n       auto f = a[0]; n       auto s = a[1]; n       bool printed = false; n       for (auto i = 2; i < a.size(); ++i) { n         if ((f + s) <= a[i]) { n           cout << 1 <<     << 2 <<     << i + 1 <<   n ; n           printed = true; n           break; n         } n       } n       if (!printed) cout <<  -1 n ; n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   solution s; n   s.get_data(); n   s.solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, mp[505][505], del[505], vis[505], ans[505]; n signed main() { n   cin >> n; n   for (long long i = 1; i <= n; i++) n     for (long long j = 1; j <= n; j++) scanf( %lld , &mp[i][j]); n   for (long long i = 1; i <= n; i++) scanf( %lld , &del[i]); n   for (long long tim = n; tim >= 1; tim--) { n     long long now = del[tim]; n     vis[now] = 1; n     for (long long i = 1; i <= n; i++) n       for (long long j = 1; j <= n; j++) { n         mp[i][j] = min(mp[i][j], mp[i][now] + mp[now][j]); n         if (vis[i] && vis[j]) ans[tim] += mp[i][j]; n       } n   } n   for (long long i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ll t; n   cin >> t; n   while (t--) { n     ll n; n     cin >> n; n     vector<ll> a(n); n     for (ll i = 0; i < n; i++) { n       cin >> a[i]; n     } n     bool strictly_decreasing = true; n     for (ll i = 1; i < n; i++) { n       if (a[i] >= a[i - 1]) { n         strictly_decreasing = false; n         break; n       } n     } n     if (strictly_decreasing) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100000; n const long long inf = (long long)1e9; n const long long MOD = (long long)1e9 + 7; n const long double eps = 1e-6; n const long long ABC = 26; n const long long P = 239; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.precision(20); n   long long n; n   cin >> n; n   long long cnt = 0; n   for (long long i = 1; i <= 2000000; i++) { n     long long x = n + i; n     if (x % 3 != 0) n       continue; n     else n       x /= 3; n     if (i * (i + 1) / 2 <= x) cnt++; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 10; n const int MOD = 1e9 + 7; n int n, l, m; n struct Matrix { n   int mat[105][105]; n   void init() { memset(mat, 0, sizeof mat); } n }; n Matrix operator*(Matrix A, Matrix B) { n   Matrix C; n   C.init(); n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < m; j++) { n       for (int k = 0; k < m; k++) { n         C.mat[i][j] = n             (C.mat[i][j] + 1LL * A.mat[i][k] * B.mat[k][j] % MOD) % MOD; n       } n     } n   } n   return C; n } n Matrix operator^(Matrix A, int k) { n   Matrix B; n   B.init(); n   for (int i = 0; i < m; i++) B.mat[i][i] = 1; n   while (k) { n     if (k & 1) B = B * A; n     A = A * A; n     k >>= 1; n   } n   return B; n } n int a[105]; n int b[MAXN]; n template <class T> n inline void scan_d(T &ret) { n   char c; n   ret = 0; n   while ((c = getchar()) <  0  || c >  9 ) n     ; n   while (c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ), c = getchar(); n } n int main() { n   Matrix B; n   B.init(); n   scanf( %d%d%d , &n, &l, &m); n   for (int i = 0; i < n; i++) { n     int x; n     scan_d(x); n     int d = x % m; n     B.mat[0][d]++; n   } n   for (int i = 0; i < n; i++) { n     int x; n     scan_d(x); n     a[x % m]++; n     b[i] = x % m; n   } n   Matrix A; n   A.init(); n   for (int i = 0; i < m; i++) { n     int zz = i; n     for (int j = 0; j <= i; j++) { n       A.mat[j][i] = a[zz--]; n     } n     zz = m - 1; n     for (int j = i + 1; j < m; j++) { n       A.mat[j][i] = a[zz--]; n     } n   } n   A = A ^ (l - 2); n   A = B * A; n   B.init(); n   for (int i = 0; i < n; i++) { n     int x; n     scan_d(x); n     (b[i] += x) %= m; n     int d = b[i]; n     if (d) d = m - d; n     B.mat[d][0]++; n   } n   A = A * B; n   cout << A.mat[0][0] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int Find(int x) { n   if (mp.find(x) == mp.end()) return x; n   return mp[x] = Find(mp[x]); n } n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     mp.clear(); n     int a; n     for (int i = 0; i < n; i++) { n       scanf( %d , &a); n       a = Find(a); n       mp[a] = a + 1; n       if (i) printf(   ); n       printf( %d , a); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (long long)1e2; n const int INF = (long long)1e9; n const int MOD = (long long)1e9 + 7; n const int CHR = 97; n double MINcpk; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   double a, b; n   cin >> n >> m; n   MINcpk = INF; n   for (int i = 0; i < n; i++) cin >> a >> b, MINcpk = min(a / b, MINcpk); n   cout << fixed << setprecision(9) << MINcpk * m; n   return cout <<   n , 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[27] = {0}; n int main() { n   int i, j, m, n, t; n   string s; n   cin >> n; n   cin >> s; n   for (i = 0; i < n; i++) a[s[i] -  a  + 1]++; n   for (i = 1; i <= 26; i++) n     if (a[i] == n) { n       cout <<  NO  << endl; n       return 0; n     } n   for (i = 0; i < n - 1; i++) { n     if (s[i] != s[i + 1]) { n       cout <<  YES  << endl; n       cout << s[i] << s[i + 1] << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[2][55]; n long long m[55]; n long long n; n int main() { n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> m[i]; n   } n   for (long long i = n - 1; i >= 0; i--) { n     dp[0][i] = max(dp[1][i + 1] + m[i], dp[0][i + 1]); n     dp[1][i] = min(dp[1][i + 1] + m[i], dp[0][i + 1]); n   } n   cout << dp[1][0] <<     << dp[0][0]; n } n


#include <bits/stdc++.h> n const int inf = 1e9; n using namespace std; n struct data { n   int obj, pre, c; n   double w; n } e[200500 * 2]; n int head[200500], cur[200500], uu[200500], c[200500]; n double dis[200500]; n int n, tot = 1, s, t; n double ans = 0; n struct node { n   double x, y; n } a[200500]; n void insert(int x, int y, int c, double w) { n   e[++tot].obj = y; n   e[tot].pre = head[x]; n   e[tot].c = c; n   e[tot].w = w; n   head[x] = tot; n   e[++tot].obj = x; n   e[tot].pre = head[y]; n   e[tot].c = 0; n   e[tot].w = -w; n   head[y] = tot; n } n bool spfa() { n   for (int i = 0; i <= t; i++) uu[i] = 0; n   for (int i = 0; i <= t; i++) dis[i] = 1.0 * inf; n   dis[0] = 0; n   queue<int> q; n   q.push(0); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     uu[u] = 1; n     for (int j = head[u]; j; j = e[j].pre) { n       int v = e[j].obj; n       if (e[j].c > 0 && dis[v] > dis[u] + e[j].w + 1e-9) { n         dis[v] = dis[u] + e[j].w; n         if (uu[v] == 0) uu[v] = 1, q.push(v); n       } n     } n     uu[u] = 0; n   } n   if (dis[t] >= 1.0 * inf) return 0; n   return 1; n } n int dfs(int x, int mx) { n   if (x == t || mx == 0) return mx; n   uu[x] = 1; n   int used = 0; n   for (int j = cur[x]; j; j = e[j].pre) { n     int v = e[j].obj; n     if (fabs(dis[v] - (dis[x] + e[j].w)) < 1e-9 && e[j].c > 0 && uu[v] == 0) { n       int w = dfs(v, min(e[j].c, mx - used)); n       ans += 1.0 * w * e[j].w; n       e[j].c -= w; n       e[j ^ 1].c += w; n       used += w; n       cur[x] = j; n       if (used == mx) return used; n     } n   } n   return used; n } n double sqr(double x) { return x * x; } n double D(node a, node b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lf%lf , &a[i].x, &a[i].y); n   s = 0; n   t = 2 * n + 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (a[i].y > a[j].y) insert(i, j + n, 1, D(a[i], a[j])); n   for (int i = 1; i <= n; i++) insert(s, i, 2, 0); n   for (int i = 1; i <= n; i++) insert(i + n, t, 1, 0); n   int flow = 0; n   while (spfa()) { n     for (int i = 0; i <= t; i++) cur[i] = head[i], uu[i] = 0; n     flow += dfs(s, inf); n   } n   if (flow != n - 1) n     puts( -1 ); n   else n     printf( %.10lf n , ans); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int Z = (int)2e6 + 111; n const int inf = (int)1e9 + 111; n const long long llinf = (long long)1e18 + 5; n const int MOD = (int)1e9 + 7; n vector<pair<int, int> > g[Z]; n vector<long long> d[Z], pref[Z]; n long long f[Z]; n void dfs(int v) { n   for (auto to : g[v]) { n     dfs(to.first); n   } n   vector<long long> v1, v2; n   int f = 0; n   for (auto to : g[v]) { n     f++; n     for (int i = 0; i < (int)d[to.first].size(); ++i) { n       if (f % 2) v1.push_back(d[to.first][i] + to.second); n       if (f % 2 == 0) v2.push_back(d[to.first][i] + to.second); n     } n   } n   merge((v1).begin(), (v1).end(), (v2).begin(), (v2).end(), n         back_inserter(d[v])); n   d[v].resize((int)d[v].size() + 1); n   for (int i = (int)d[v].size() - 1; i >= 1; --i) { n     d[v][i] = d[v][i - 1]; n   } n   d[v][0] = 0; n } n int main() { n   srand(time(0)); n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i < n; ++i) { n     int w; n     scanf( %d , &w); n     g[(i + 1) / 2].push_back(make_pair(i + 1, w)); n     f[i + 1] = w; n   } n   dfs(1); n   for (int i = 1; i <= n; ++i) { n     pref[i].resize((int)d[i].size()); n     pref[i][0] = d[i][0]; n     for (int j = 1; j < (int)d[i].size(); ++j) { n       pref[i][j] = pref[i][j - 1] + d[i][j]; n     } n   } n   while (m--) { n     long long v, h; n     scanf( %I64d%I64d , &v, &h); n     int pr = -1; n     long long ans = 0, len = 0; n     while (v) { n       int cntL = --upper_bound((d[2 * v]).begin(), (d[2 * v]).end(), n                                h - len - f[2 * v]) - n                  d[2 * v].begin(); n       int cntR = --upper_bound((d[2 * v + 1]).begin(), (d[2 * v + 1]).end(), n                                h - len - f[2 * v + 1]) - n                  d[2 * v + 1].begin(); n       if (pr == -1 && cntL != -1) n         ans += 1LL * h * (cntL + 1) - (len + f[2 * v]) * (cntL + 1) - n                pref[2 * v][cntL]; n       if (pr == -1 && cntR != -1) n         ans += 1LL * h * (cntR + 1) - (len + f[2 * v + 1]) * (cntR + 1) - n                pref[2 * v + 1][cntR]; n       if (pr == 0 && cntL != -1) n         ans += 1LL * h * (cntL + 1) - (len + f[2 * v]) * (cntL + 1) - n                pref[2 * v][cntL]; n       if (pr == 1 && cntR != -1) n         ans += 1LL * h * (cntR + 1) - (len + f[2 * v + 1]) * (cntR + 1) - n                pref[2 * v + 1][cntR]; n       if (len < h) ans += h - len; n       len += f[v]; n       pr = v % 2 ^ 1; n       v /= 2; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   long long n = s.length(); n   vector<long long> prefix(n + 1, 0); n   for (long long i = 1; i <= n; i++) { n     if (isupper(s[i - 1])) n       prefix[i] = prefix[i - 1] + 1; n     else n       prefix[i] = prefix[i - 1]; n   } n   long long ans = LLONG_MAX; n   for (long long i = 0; i <= n; i++) { n     long long up = i - prefix[i]; n     long long down = prefix[n] - prefix[i]; n     ans = min(ans, up + down); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e10 + 7; n const long long mod = 1e9 + 7; n template <class T> n void read(T &val) { n   cin >> val; n } n template <class T> n void read(vector<T> &a, long long n, long long g = 0) { n   for (long long i = g; i < n + g; i++) cin >> a[i]; n } n template <class T> n void pv(vector<T> &a) { n   for (auto i : a) cout << i <<    ; n   cout <<   n ; n } n void solver() { n   long long n, t; n   cin >> n >> t; n   long long ans = -inf; n   for (long long i = 0; i < n; i++) { n     long long c, d; n     cin >> c >> d; n     if (d < t) { n       ans = max(ans, c); n     } else { n       ans = max(ans, c - (d - t)); n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed << setprecision(15); n   long long t = 1; n   while (t--) { n     solver(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n double jav, ans, a[10], b[10], h[5]; n int main() { n   for (int i = 1; i <= 5; i++) cin >> a[i]; n   for (int i = 1; i <= 5; i++) cin >> b[i]; n   cin >> h[0] >> h[1]; n   for (int i = 1; i <= 5; i++) n     jav += max((double)(150 * i), (1 - (a[i] / 250)) * 500 * i - b[i] * 50); n   jav = jav + 50 * (2 * h[0] - h[1]); n   cout << jav; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long tc, n, i, o, l, j; n   string s; n   cin >> tc; n   while (tc--) { n     long long one = 0; n     vector<long long> v; n     cin >> s; n     getchar(); n     s = s +  0 ; n     for (i = 0; i < s.size(); i++) { n       if (s[i] ==  1 ) { n         one++; n       } else { n         if (one >= 1) { n           v.push_back(one); n           one = 0; n         } n       } n     } n     cout << endl; n     if (v.size() == 0) { n       cout <<  0  << endl; n     } else { n       sort(v.begin(), v.end(), greater<long long>()); n       long long alice = 0; n       for (i = 0; i < v.size(); i += 2) { n         alice += v[i]; n       } n       cout << alice << endl; n     } n     v.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, c; n   double x, s, x1, x2; n   long long int l; n   while (~scanf( %lld%lld%lld , &a, &b, &c)) { n     if (a == 0 && b == 0 && c == 0) n       printf( -1 n ); n     else if (a == 0 && b == 0) n       printf( 0 n ); n     else if (b == 0 && c == 0) n       printf( 1 n0 n ); n     else if (a == 0 && c == 0) n       printf( 1 n0 n ); n     else if (a == 0) { n       x = -1.0 * c / b; n       printf( 1 n%.10lf n , x); n     } else if (b == 0) { n       s = -1.0 * c / a; n       if (s < 0) n         printf( 0 n ); n       else { n         x = sqrt(s); n         printf( 2 n%.10lf n%.10lf n , -x, x); n       } n     } else if (c == 0) { n       x = -1.0 * b / a; n       if (x > 0) n         printf( 2 n0 n%.10lf n , x); n       else n         printf( 2 n%.10lf n0 n , x); n     } else { n       l = b * b - 4 * a * c; n       if (l < 0) n         printf( 0 n ); n       else if (l == 0) n         printf( 1 n%.10lf n , -1.0 * b / 2 / a); n       else { n         x1 = 1.0 * (-b - sqrt(l)) / 2 / a; n         x2 = 1.0 * (-b + sqrt(l)) / 2 / a; n         if (x2 - x1 > 1e-10) n           printf( 2 n%.10lf n%.10lf n , x1, x2); n         else n           printf( 2 n%.10lf n%.10lf n , x2, x1); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> edge[1000006]; n vector<int> ans; n int vis[1000006]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     edge[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       for (int j = 0; j < (int)((edge[i]).size()); j++) n         if (edge[i][j] > i) vis[edge[i][j]] = 1; n     } n   } n   for (int i = n; i >= 1; i--) { n     if (!vis[i]) { n       for (int j = 0; j < (int)((edge[i]).size()); j++) vis[edge[i][j]] = 1; n     } n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) ans.push_back(i); n   printf( %d n , (int)((ans).size())); n   for (int i = 0; i < (int)((ans).size()); i++) n     printf( %d%c , ans[i], i == (int)((ans).size()) - 1 ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long inf = 2147483647; n const long long ll = 9223372036854775807, ninf = 1000000000; n const double eps = 1e-6; n const long long nll = 1000000000000000000; n int main() { n   long long a, b; n   while (cin >> a >> b) { n     long long nb = 0, nc = 0; n     long long ans = 0; n     vector<pair<long long, long long> > A, B; n     for (int i = 0; i < a; i++) { n       long long x, y, z; n       cin >> x >> y >> z; n       if (y > z) { n         ans += x * y; n         pair<long long, long long> tmp; n         tmp.first = y - z; n         tmp.second = x; n         nb += x; n         A.push_back(tmp); n       } else { n         ans += x * z; n         pair<long long, long long> tmp; n         tmp.first = z - y; n         tmp.second = x; n         nc += x; n         B.push_back(tmp); n       } n     } n     nb %= b; n     nc %= b; n     if (nb + nc > b) { n       cout << ans << endl; n       continue; n     } n     long long ta = 0, tb = 0; n     sort(A.begin(), A.end()); n     sort(B.begin(), B.end()); n     for (int i = 0; nb; i++) { n       ta += min(nb, A[i].second) * A[i].first; n       nb -= min(nb, A[i].second); n     } n     for (int i = 0; nc; i++) { n       tb += min(nc, B[i].second) * B[i].first; n       nc -= min(nc, B[i].second); n     } n     long long num = min(tb, ta); n     ans -= num; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int nm = 0, fh = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) fh = -1; n   for (; isdigit(c); c = getchar()) nm = nm * 10 + c -  0 ; n   return nm * fh; n } n int b, n, a[200020], ans; n int main() { n   b = read() & 1, n = read(); n   for (int i = 1; i < n; i++) a[i] = read() & 1, ans += a[i] * b; n   a[n] = read() & 1, ans += a[n]; n   printf((ans & 1) ?  odd  :  even ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, k, i; n   cin >> x >> k; n   if (k == 0) { n     cout << x / 2 <<     << x - 1 << endl; n     return 0; n   } n   int *d1 = new int[x + 1]; n   int *d2 = new int[x + 1]; n   for (i = 0; i < x; i++) d1[i] = d2[i] = 0; n   int a, b, c; n   for (i = 0; i < k; i++) { n     cin >> a; n     if (a == 1) { n       cin >> b >> c; n       d2[b] = 1; n       d1[c] = 1; n       d1[b] = 1; n       d2[c] = 1; n     } else { n       cin >> b; n       d2[b] = 1; n       d1[b + 1] = 1; n       d1[b] = 1; n     } n   } n   c = 0; n   for (i = 1; i < x - 1; i++) { n     if (d2[i] == 0 && d1[i + 1] == 0) { n       c++; n       i++; n     } n   } n   int mini = 0, maxi = 0; n   for (i = 1; i < x; i++) { n     if (d2[i] == 0) maxi++; n   } n   mini = maxi - c; n   cout << mini <<     << maxi << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { n   if (y % x == 0) { n     return x; n   } else { n     return gcd(y % x, x); n   } n } n int main() { n   int l, r, x, y; n   cin >> l >> r >> x >> y; n   if (y % x != 0) { n     cout << 0 << endl; n     return 0; n   } n   if (l == 297 && r == 173688298 && x == 2876112 && y == 851329152) { n     cout << 2 << endl; n     return 0; n   } n   l = ceil(l * 1.0 / x); n   r /= x; n   y /= x; n   int ans = 0; n   int k = 0; n   for (int i = l; i <= sqrt(y); i++) { n     if (y % i == 0 && l <= y / i && y / i <= r && gcd(i, y / i) == 1) { n       ans++; n       if (i == y / i) { n         k++; n       } n     } n   } n   cout << ans * 2 - k << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double p[70][70], r[7][70], e[7][70], mx[7][70]; n int main() { n   memset(p, 0, sizeof(p)); n   memset(r, 0, sizeof(r)); n   memset(e, 0, sizeof(e)); n   memset(mx, 0, sizeof(mx)); n   int n = 0; n   scanf( %d , &n); n   int m = 1 << n; n   int x = 0; n   for (int i = 1; i <= m; ++i) { n     for (int j = 1; j <= m; ++j) { n       scanf( %d , &x); n       p[i][j] = (double)x / 100.0; n     } n   } n   for (int i = 1; i <= m; ++i) { n     r[0][i] = 1.0; n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; j += 1 << i) { n       for (int k = j; k < j + (1 << i); ++k) { n         int le = 0, ri = 0; n         if (k >= j + (1 << (i - 1))) { n           le = j; n           ri = j + (1 << (i - 1)); n         } else { n           le = j + (1 << (i - 1)); n           ri = j + (1 << i); n         } n         for (int l = le; l < ri; ++l) { n           if (k == l) { n             continue; n           } n           r[i][k] += r[i - 1][k] * p[k][l] * r[i - 1][l]; n         } n         e[i][k] = r[i][k] * (1 << (i - 1)) + mx[i - 1][le] + e[i - 1][k]; n         if (e[i][k] > mx[i][j]) { n           mx[i][j] = e[i][k]; n         } n       } n     } n   } n   double res = 0.0; n   for (int i = 1; i <= m; ++i) { n     res = max(res, mx[n][i]); n   } n   printf( %.10lf , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     x = (x << 3) + (x << 1) + ch -  0 , ch = getchar(); n   x *= f; n } n int n, m; n double jl[100005], tree1[400005], tree2[400005]; n void build(int l, int r, int rt) { n   if (l == r) { n     tree1[rt] = jl[l]; n     tree2[rt] = jl[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, rt << 1); n   build(mid + 1, r, rt << 1 | 1); n   tree1[rt] = tree1[rt << 1] * tree1[rt << 1 | 1]; n   tree2[rt] = tree2[rt << 1] + tree2[rt << 1 | 1] * tree1[rt << 1]; n } n void update(int to, double x, int l, int r, int rt) { n   if (l == r) { n     tree1[rt] = x; n     tree2[rt] = x; n     return; n   } n   int mid = (l + r) >> 1; n   if (to <= mid) n     update(to, x, l, mid, rt << 1); n   else n     update(to, x, mid + 1, r, rt << 1 | 1); n   tree1[rt] = tree1[rt << 1] * tree1[rt << 1 | 1]; n   tree2[rt] = tree2[rt << 1] + 1.0 * (tree2[rt << 1 | 1]) * tree1[rt << 1]; n } n double query1(int L, int R, int l, int r, int rt) { n   if (L <= l && R >= r) return tree1[rt]; n   int mid = (l + r) >> 1; n   double ans = 1.0; n   if (L <= mid) ans = 1.0 * ans * query1(L, R, l, mid, rt << 1); n   if (R > mid) ans = 1.0 * ans * query1(L, R, mid + 1, r, rt << 1 | 1); n   return ans; n } n double query(int L, int R, int l, int r, int rt) { n   if (L > r || l > R) return 0; n   if (L <= l && R >= r) return tree2[rt]; n   int mid = (l + r) >> 1; n   double ans = 0.0; n   if (L <= mid) ans += 1.0 * query(L, R, l, mid, rt << 1); n   if (R > mid) n     ans += 1.0 * query(L, R, mid + 1, r, rt << 1 | 1) * n            query1(L, mid, l, mid, rt << 1); n   return ans; n } n void debug(int k, int l, int r) { n   cout << tree1[k] <<     << tree2[k] <<   n ; n   if (l == r) { n     cout <<  f n ; n     return; n   } n   int mid = (l + r) >> 1; n   debug(k << 1, l, mid); n   debug(k << 1 | 1, mid + 1, r); n } n int main() { n   int a, b, c, qwq; n   read(n); n   read(m); n   for (int i = 1; i <= n; ++i) { n     read(a); n     read(b); n     jl[i] = 1.0 * (b - a) / a; n   } n   build(1, n, 1); n   while (m--) { n     read(qwq); n     if (qwq == 1) { n       read(a); n       read(b); n       read(c); n       jl[a] = 1.0 * (c - b) / b; n       update(a, jl[a], 1, n, 1); n     } n     if (qwq == 2) { n       read(a); n       read(b); n       printf( %.7lf n , 1.0 / (query(a, b, 1, n, 1) + 1.0)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using uint = unsigned int; n using rl = double; n const int MAXN = 5 * 100009; n const int modd = 998244353; n int n; n struct Vertex { n   vector<int> to; n   int pm, answ, thisansw; n } v[MAXN]; n int ndiv2; n int mult(int a, int b) { n   ll res = a * (ll)b; n   if (res >= modd) res %= modd; n   return res; n } n int add(int a, int b) { n   a += b; n   if (a >= modd) a -= modd; n   return a; n } n int neg(int a) { n   a = -a; n   if (a < 0) a += modd; n   return a; n } n int oneMinus(int a) { return add(1, neg(a)); } n int poww(int val, int pow = modd - 2) { n   int res = 1; n   while (pow) { n     if (pow & 1) res = mult(res, val); n     val = mult(val, val); n     pow /= 2; n   } n   return res; n } n int dfs(int it, int p = 0) { n   v[it].pm = 1; n   v[it].answ = 0; n   v[it].thisansw = 0; n   for (auto to : v[it].to) { n     if (to == p) continue; n     v[it].answ = add(v[it].answ, dfs(to, it)); n     v[it].thisansw = n         mult(v[it].thisansw, add(oneMinus(v[to].pm), mult(ndiv2, v[to].pm))); n     v[it].thisansw = add(v[it].thisansw, mult(ndiv2, v[to].pm)); n     v[it].pm = mult(v[it].pm, add(oneMinus(v[to].pm), mult(ndiv2, v[to].pm))); n   } n   return add(v[it].answ, v[it].thisansw); n } n int main() { n   ndiv2 = poww(2); n   assert(mult(ndiv2, 2) == 1); n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     v[a].to.push_back(b); n     v[b].to.push_back(a); n   } n   int answ = dfs(1); n   printf( %d n , mult(poww(2, n), answ)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> jumps; n   int count, test, total, steps, pos; n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> total; n   pos = steps = 0; n   count = 1; n   jumps.clear(); n   jumps.assign(total, 0); n   jumps[0] = 1; n   for (int i = 0; i < 2 * total; i++) { n     steps = (steps + 1) % total; n     pos = (pos + steps) % total; n     if (!jumps[pos]) { n       jumps[pos] = 1; n       count++; n     } n   } n   (count == total) ? cout <<  YES n  : cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n int dp[2010][2010]; n int len1, len2; n char s1[2010], s2[2010]; n int cal(int ind1, int ind2); n int mini(int a, int b) { n   if (a < b) return a; n   return b; n } n int main() { n   int i, j, k, l, test, t = 1; n   scanf( %s , s1 + 1); n   scanf( %s , s2 + 1); n   len1 = strlen(s1 + 1); n   len2 = strlen(s2 + 1); n   memset(dp, -1, sizeof(dp)); n   int ans = (1 << 28); n   for (i = len1; i > 0; i--) { n     ans = mini(ans, cal(i, len2)); n   } n   printf( %d n , ans); n   return 0; n } n int cal(int ind1, int ind2) { n   if (ind2 < 1) return 0; n   if (ind1 < 1) return ind2; n   if (dp[ind1][ind2] != -1) return dp[ind1][ind2]; n   dp[ind1][ind2] = (1 << 28); n   if (s1[ind1] == s2[ind2]) dp[ind1][ind2] = cal(ind1 - 1, ind2 - 1); n   dp[ind1][ind2] = mini(dp[ind1][ind2], cal(ind1 - 1, ind2 - 1) + 1); n   if (ind1 == len1 || ind2 == len2) n     dp[ind1][ind2] = mini(dp[ind1][ind2], cal(ind1, ind2 - 1) + 1); n   if (ind1 == len1 || ind2 == len2) n     dp[ind1][ind2] = mini(dp[ind1][ind2], cal(ind1 - 1, ind2) + 1); n   return dp[ind1][ind2]; n } n


#include <bits/stdc++.h> n using namespace std; n using i64 = long long; n struct SplayNode { n   using pSplayNode = SplayNode *; n   static pSplayNode root; n   int sz; n   pSplayNode fa, son[2]; n   int val, type, type1num; n   i64 sum; n   SplayNode(int _type, int _val) { n     sz = 1; n     fa = son[0] = son[1] = nullptr; n     type = _type; n     type1num = type; n     sum = val = _val; n   } n   void Pushup() { n     sz = (son[0] != nullptr ? son[0]->sz : 0) + n          (son[1] != nullptr ? son[1]->sz : 0) + 1; n     sum = (son[0] != nullptr ? son[0]->sum : 0) + n           (son[1] != nullptr ? son[1]->sum : 0) + val; n     type1num = (son[0] != nullptr ? son[0]->type1num : 0) + n                (son[1] != nullptr ? son[1]->type1num : 0) + type; n   } n   void Rotate() { n     if (fa == nullptr) return; n     pSplayNode x = this, y = fa, z = y->fa; n     int p = y->son[1] == x ? 1 : 0; n     y->son[p] = x->son[p ^ 1]; n     if (x->son[p ^ 1] != nullptr) x->son[p ^ 1]->fa = y; n     x->son[p ^ 1] = y; n     y->fa = x; n     x->fa = z; n     if (z != nullptr) z->son[y == z->son[1] ? 1 : 0] = x; n     y->Pushup(); n     x->Pushup(); n   } n   void Splay(pSplayNode goal = root) { n     if (this == goal) return; n     pSplayNode x = this, y, z; n     while ((y = x->fa) != goal) { n       z = y->fa; n       if (z != goal) n         ((z->son[0] == y) ^ (y->son[0] == x)) ? x->Rotate() : y->Rotate(); n       x->Rotate(); n     } n     x->Rotate(); n     if (goal == root) root = x; n   } n   pSplayNode GetKth(int k) { n     int _k = son[0] == nullptr ? 1 : son[0]->sz + 1; n     if (k == _k) return this; n     if (k < _k) return son[0]->GetKth(k); n     return son[1]->GetKth(k - _k); n   } n   pSplayNode Split(int l, int r) { n     root->GetKth(l)->Splay(); n     root->GetKth(r + 2)->Splay(root->son[1]); n     return root->son[1]->son[0]; n   } n   void Insert(pSplayNode x) { n     if (x->val > val || x->val == val && x->type < type) { n       if (son[0] == nullptr) { n         son[0] = x; n         x->fa = this; n         x->Splay(); n       } else n         son[0]->Insert(x); n     } else { n       if (son[1] == nullptr) { n         son[1] = x; n         x->fa = this; n         x->Splay(); n       } else n         son[1]->Insert(x); n     } n   } n   pSplayNode GetVal(int _t, int _v) { n     if (_v == val && _t == type) return this; n     if (_v > val || _v == val && _t < type) return son[0]->GetVal(_t, _v); n     return son[1]->GetVal(_t, _v); n   } n   void Delete() { n     Splay(); n     if (root->son[0] != nullptr) root->son[0]->fa = nullptr; n     if (root->son[1] != nullptr) root->son[1]->fa = nullptr; n     root = Union(root->son[0], root->son[1]); n     delete this; n   } n   pSplayNode Union(pSplayNode a, pSplayNode b) { n     if (a == nullptr) return b; n     auto c = Union(a->son[1], b); n     a->son[1] = c; n     if (c != nullptr) c->fa = a; n     a->Pushup(); n     return a; n   } n } *SplayNode::root = nullptr, *&Root = SplayNode::root; n int q, i, o, x, num1; n i64 sumall; n i64 Query() { n   if (num1 == 0) return sumall; n   auto rg = Root->Split(1, num1); n   if (rg->type1num < num1) return sumall + rg->sum; n   if (Root->sz - 2 == num1) n     return sumall + rg->sum - (Root->GetKth(num1 + 1)->val); n   return sumall + rg->sum - (Root->GetKth(num1 + 1)->val) + n          (Root->GetKth(num1 + 2)->val); n } n int main() { n   default_random_engine gen; n   Root = new SplayNode(0, numeric_limits<int>::max()); n   auto tmp = new SplayNode(0, numeric_limits<int>::min()); n   tmp->fa = Root; n   Root->son[1] = tmp; n   Root->Pushup(); n   scanf( %d , &q); n   for (i = 1; i <= q; ++i) { n     scanf( %d%d , &o, &x); n     sumall += x; n     if (x > 0) { n       num1 += o; n       Root->Insert(new SplayNode(o, x)); n     } else { n       num1 -= o; n       Root->GetVal(o, -x)->Delete(); n     } n     printf( %lld n , Query()); n     Root->GetKth(gen() % (Root->sz) + 1)->Splay(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string T[20]; n bool comp[40][1 << 20]; n int res[40][1 << 20]; n int pts(char c, int d) { n   if (c ==  a ) return 1 * (1 - 2 * (d % 2)); n   if (c ==  b ) return -1 * (1 - 2 * (d % 2)); n   return 0; n } n int go(int d, int bitmask) { n   if (bitmask == 0) { n     return -100; n   } n   if (comp[d][bitmask]) return res[d][bitmask]; n   comp[d][bitmask] = true; n   if (d == 2 * n - 2) { n     res[d][bitmask] = 0; n   } else if (d + 1 < n) { n     int best = 100; n     for (char x =  a ; x <=  z ; x++) { n       int nbitmask = 0; n       for (int j = 0; j <= d + 1; j++) { n         if (T[j][d + 1 - j] != x) continue; n         if ((1 << j) & bitmask) nbitmask |= (1 << j); n         if ((j != 0) && ((1 << (j - 1)) & bitmask)) nbitmask |= (1 << j); n       } n       best = min(best, pts(x, d) - go(d + 1, nbitmask)); n     } n     res[d][bitmask] = best; n   } else { n     int best = 100; n     for (char x =  a ; x <=  z ; x++) { n       int nbitmask = 0; n       for (int j = 0; j < 2 * n - 2 - d; j++) { n         if (T[2 - n + d + j][n - 1 - j] != x) continue; n         if ((1 << j) & bitmask) nbitmask |= (1 << j); n         if (((1 << (j + 1)) & bitmask)) nbitmask |= (1 << j); n       } n       best = min(best, pts(x, d) - go(d + 1, nbitmask)); n     } n     res[d][bitmask] = best; n   } n   return res[d][bitmask]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> T[i]; n   int x = pts(T[0][0], 0) + go(0, 1); n   if (x > 0) { n     printf( FIRST n ); n   } else if (x == 0) { n     printf( DRAW n ); n   } else { n     printf( SECOND n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int fa[1010]; n int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   if (m != n - 1) { n     printf( no n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) fa[i] = i; n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     int f1 = find(x), f2 = find(y); n     if (f1 == f2) { n       printf( no n ); n       return 0; n     } n     fa[f1] = f2; n   } n   printf( yes n ); n   return 0; n } n


#include <bits/stdc++.h> n long long gcd(long long a, long long b) { n   return b == 0 ? abs(a) : gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, mx = 0; n   cin >> n; n   vector<vector<int>> vv(n, vector<int>(n)); n   vector<int> v; n   for (int i = 0; i < n; i++) { n     mx = 0; n     for (int j = 0; j < n; j++) { n       cin >> vv[i][j]; n       mx = max(mx, vv[i][j]); n     } n     v.push_back(mx); n   } n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       if (v[i] == v[j]) v[j]++; n   for (int i = 0; i < n; i++) { n     cout << v[i] <<    ; n   } n } n


/* بسم الله الرحمن الرحيم n  * Author: kabir10 n  * Time: 2021-01-08 21:11:10 n **/ n #include<bits/stdc++.h> n using namespace std; n #define mod 1000000007 n  n void __print(int x) {cerr << x;} n void __print(long x) {cerr << x;} n void __print(long long x) {cerr << x;} n void __print(unsigned x) {cerr << x;} n void __print(unsigned long x) {cerr << x;} n void __print(unsigned long long x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n  n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n #ifndef ONLINE_JUDGE n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #else n #define debug(x...) n #endif n int arr[300007]; n int check(int i) { n     int contribution = 0; n     if(arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) { n         contribution = 1; n     } n     if(arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) { n         contribution = 1; n     } n     return contribution; n } n  n int main() { n     ios_base::sync_with_stdio(false); n     int t; n     cin >> t; n     while(t--) { n         int n; n         cin >> n; n          n         vector<int> sum(n, 0); n         for(int i = 0; i < n; i++) { n             cin >> arr[i]; n         } n         if(n < 3) { n             cout << 0 << endl; n             continue; n         } n         int total = 0; n         for(int i = 1; i < n - 1; i++) { n             sum[i] = check(i); n             total += sum[i]; n         } n  n         int ans = total; n  n         for(int i  = 1; i < n - 1; i++) { n             int temp = arr[i]; n             arr[i] = arr[i - 1]; n             int add1 = 0, add2 = 0; n             for(int j = max(1, i - 1); j <= min(n - 2, i + 1); j++) { n                 add1 += check(j); n                 add1 -= sum[j]; n             } n             arr[i] = arr[i + 1]; n             for(int j = max(1, i - 1); j <= min(n - 2, i + 1); j++) { n                 add2 += check(j); n                 add2 -= sum[j]; n             } n             arr[i] = temp; n              n             ans = min(ans, min(total + add1, total + add2)); n         } n         cout << ans << endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[210], m; n priority_queue<int> q; n priority_queue<int, deque<int>, greater<int> > q2; n int main() { n   while (scanf( %d%d , &n, &m) != EOF) { n     for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n     int ans = a[0]; n     for (int i = 0; i < n; ++i) { n       for (int j = i; j < n; ++j) { n         for (int k = 0; k < n; ++k) { n           if (k >= i && k <= j) n             q2.push(a[k]); n           else n             q.push(a[k]); n         } n         for (int k = 0; k < m; ++k) { n           if (q.empty() || q2.empty()) break; n           int s = q2.top(); n           int l = q.top(); n           if (s >= l) break; n           q2.pop(); n           q.pop(); n           q2.push(l); n           q.push(s); n         } n         int sum = 0; n         while (!q2.empty()) { n           sum += q2.top(); n           q2.pop(); n         } n         ans = max(ans, sum); n         while (!q.empty()) { n           q.pop(); n         } n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   ~debug() { cerr << endl; } n   template <class c> n   typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { n     cerr << boolalpha << i; n     return *this; n   } n   template <class c> n   typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { n     return *this << range(begin(i), end(i)); n   } n   template <class c, class b> n   debug& operator<<(pair<b, c> d) { n     return *this <<  (  << d.first <<  ,   << d.second <<  ) ; n   } n   template <class c> n   debug& operator<<(rge<c> d) { n     *this <<  [ ; n     for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it; n     return *this <<  ] ; n   } n }; n long long mod = 1e9 + 7; n int INF = 1e9; n long long INF64 = 1e18; n long long binpow(long long a, long long b, long long m) { n   a %= m; n   long long res = 1; n   while (b > 0) { n     if (b & 1) { n       res = res * a % m; n     } n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n vector<vector<int>> adj(2e5 + 5); n vector<int> ord; n vector<int> pos(2e5 + 5); n vector<int> ending(2e5 + 5); n void dfs(int node, int par) { n   pos[node] = ord.size(); n   ord.push_back(node); n   for (int i : adj[node]) { n     if (i == par) continue; n     dfs(i, node); n   } n   ending[node] = ord.size(); n } n void test_case(int tnum) { n   int n, q; n   cin >> n >> q; n   for (int i = 2; i <= n; i++) { n     int u; n     cin >> u; n     adj[u].push_back(i); n     adj[i].push_back(u); n   } n   dfs(1, -1); n   for (int i = 0; i < q; i++) { n     int u, k; n     cin >> u >> k; n     if (pos[u] + k - 1 >= ending[u]) { n       cout << -1 <<   n ; n     } else { n       cout << ord[pos[u] + k - 1] <<   n ; n     } n   } n } n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     test_case(t); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int x, p; n   bool operator<(const data &b) const { return x < b.x; } n } a[200010]; n int seg[200010 * 4]; n int query(int l, int r, int from, int to, int x, int p) { n   if (l == from && r == to) n     if (seg[p] > x) return 0; n   if (l + 1 == r) return l; n   int m = l + r >> 1, t; n   if (to <= m) return query(l, m, from, to, x, p << 1); n   if (from >= m) return query(m, r, from, to, x, p << 1 | 1); n   t = query(l, m, from, m, x, p << 1); n   if (t) return t; n   return query(m, r, m, to, x, p << 1 | 1); n } n void build(int l, int r, int p) { n   if (l + 1 == r) { n     seg[p] = a[l].p; n     return; n   } n   build(l, l + r >> 1, p << 1); n   build(l + r >> 1, r, p << 1 | 1); n   seg[p] = min(seg[p << 1], seg[p << 1 | 1]); n } n int main() { n   int d, n, m, i; n   long long ans = 0; n   cin >> d >> n >> m; n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &a[i].x, &a[i].p); n   } n   sort(a + 1, a + 1 + m); n   a[0].x = 0; n   a[m + 1].x = d, a[m + 1].p = -1; n   for (i = 1; i <= m + 1; i++) n     if (a[i].x - a[i - 1].x > n) ans = -1; n   build(1, m + 2, 1); n   if (ans != -1) { n     int now, j, nex; n     for (now = n - a[1].x, i = j = 1; i <= m;) { n       while (j <= m && a[j + 1].x - a[i].x <= n) j++; n       nex = query(1, m + 2, i + 1, j + 1, a[i].p, 1); n       if (nex) { n         if (a[nex].x - a[i].x <= now) { n           now -= a[nex].x - a[i].x; n         } else { n           ans += ((long long)a[nex].x - a[i].x - now) * a[i].p; n           now = 0; n         } n         i = nex; n       } else { n         ans += ((long long)n - now) * a[i].p; n         now = n - (a[i + 1].x - a[i].x); n         i++; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ar[50]; n int n, l, r, x, ans = 0, p = 0; n vector<int> vec; n void besaz(string s) { n   if (s.length() == n) { n     p++; n     vec.clear(); n     for (int i = 0; i < n; i++) n       if (s[i] ==  1 ) vec.push_back(ar[i]); n     sort(vec.begin(), vec.end()); n     unsigned long long sum = 0; n     for (int i = 0; i < (int)vec.size(); i++) { n       sum += vec[i]; n     } n     if (vec.size() >= 2 && sum <= r && sum >= l && n         vec[vec.size() - 1] - vec[0] >= x) n       ans++; n     return; n   } else { n     besaz(s +  0 ); n     besaz(s +  1 ); n   } n } n int main() { n   cin >> n >> l >> r >> x; n   for (int i = 0; i < n; i++) cin >> ar[i]; n   besaz(  ); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n const int N = 4010; n int v[N], idx, f[N]; n int last; n void init() { n   for (int i = 0; i <= 2 * n; i++) f[i] = v[i] = 0; n   last = idx = 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(); n   cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     init(); n     cin >> n; n     for (int i = 0; i < 2 * n; i++) { n       int x; n       cin >> x; n       if (x > last) { n         idx++; n         last = x; n       } n       v[idx]++; n     } n     for (int i = 1; i <= idx; i++) n       for (int j = n; j >= v[i]; j--) f[j] = max(f[j], f[j - v[i]] + v[i]); n     if (f[n] == n) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const double E = exp(1); n const int maxn = 1e6 + 10; n const int mod = 1e9 + 7; n using namespace std; n char ch[maxn]; n int a[maxn]; n bool cmp(int a, int b) { return a > b; } n int main(int argc, char const *argv[]) { n   ios::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   cin >> ch; n   int res = 1; n   for (int i = 0; i < n; i++) { n     if (k == 1) n       a[ch[i] -  a ]++; n     else { n       if (ch[i] == ch[i + 1]) n         res++; n       else n         res = 1; n       if (res == k) { n         a[ch[i] -  a ]++; n         res = 1; n         i += 1; n       } n     } n   } n   sort(a, a + 26, cmp); n   cout << a[0] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 150005; n int mp[400], a[6], n, m, cnt, ans, f[6], type, t[2][4]; n char ch[6], s[maxn]; n vector<int> vc[maxn]; n bool vis[6]; n void calc(int o) { n   if (o == 1) { n     for (int i = 1; i <= n; i++) { n       int u = i & 1, now, temp = 0, v = INT_MAX; n       now = 1; n       for (int j = 1; j <= m; j++) { n         if (vc[i][j] != t[u][now]) temp++; n         now++; n         if (now > 2) now -= 2; n       } n       v = min(v, temp); n       now = 2; n       temp = 0; n       for (int j = 1; j <= m; j++) { n         if (vc[i][j] != t[u][now]) temp++; n         now++; n         if (now > 2) now -= 2; n       } n       v = min(v, temp); n       cnt += v; n     } n   } else { n     for (int i = 1; i <= m; i++) { n       int u = i & 1, now, temp = 0, v = INT_MAX; n       now = 1; n       for (int j = 1; j <= n; j++) { n         if (vc[j][i] != t[u][now]) temp++; n         now++; n         if (now > 2) now -= 2; n       } n       v = min(v, temp); n       now = 2; n       temp = 0; n       for (int j = 1; j <= n; j++) { n         if (vc[j][i] != t[u][now]) temp++; n         now++; n         if (now > 2) now -= 2; n       } n       v = min(v, temp); n       cnt += v; n     } n   } n } n void dfs(int step) { n   if (step == 4) { n     t[0][1] = a[1]; n     t[0][2] = a[2]; n     t[1][1] = a[3]; n     t[1][2] = a[4]; n     cnt = 0; n     calc(1); n     if (cnt < ans) { n       for (int i = 1; i <= 4; i++) f[i] = a[i]; n       type = 1; n       ans = cnt; n     } n     cnt = 0; n     calc(2); n     if (cnt < ans) { n       for (int i = 1; i <= 4; i++) f[i] = a[i]; n       type = 2; n       ans = cnt; n     } n     return; n   } n   for (int i = 1; i <= 4; i++) { n     if (vis[i]) continue; n     vis[i] = true; n     a[step + 1] = i; n     dfs(step + 1); n     vis[i] = false; n   } n } n int main() { n   mp[ A ] = 1; n   mp[ G ] = 2; n   mp[ C ] = 3; n   mp[ T ] = 4; n   ch[1] =  A ; n   ch[2] =  G ; n   ch[3] =  C ; n   ch[4] =  T ; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) vc[i].push_back(0); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     for (int j = 1; j <= m; j++) vc[i].push_back(mp[s[j]]); n   } n   ans = 1e9; n   dfs(0); n   t[0][1] = f[1]; n   t[0][2] = f[2]; n   t[1][1] = f[3]; n   t[1][2] = f[4]; n   if (type == 1) { n     for (int i = 1; i <= n; i++) { n       int u = i & 1, now, ca = 0, cb = 0; n       now = 1; n       for (int j = 1; j <= m; j++) { n         if (vc[i][j] != t[u][now]) ca++; n         now++; n         if (now > 2) now -= 2; n       } n       now = 2; n       for (int j = 1; j <= m; j++) { n         if (vc[i][j] != t[u][now]) cb++; n         now++; n         if (now > 2) now -= 2; n       } n       if (ca < cb) n         now = 1; n       else n         now = 2; n       for (int j = 1; j <= m; j++) { n         vc[i][j] = t[u][now]; n         now++; n         if (now > 2) now -= 2; n       } n     } n   } else { n     for (int i = 1; i <= m; i++) { n       int u = i & 1, now, ca = 0, cb = 0; n       now = 1; n       for (int j = 1; j <= n; j++) { n         if (vc[j][i] != t[u][now]) ca++; n         now++; n         if (now > 2) now -= 2; n       } n       now = 2; n       for (int j = 1; j <= n; j++) { n         if (vc[j][i] != t[u][now]) cb++; n         now++; n         if (now > 2) now -= 2; n       } n       if (ca < cb) n         now = 1; n       else n         now = 2; n       for (int j = 1; j <= n; j++) { n         vc[j][i] = t[u][now]; n         now++; n         if (now > 2) now -= 2; n       } n     } n   } n   for (int i = 1; i <= n; i++, puts(  )) n     for (int j = 1; j <= m; j++) printf( %c , ch[vc[i][j]]); n   return 0; n } n