#include <bits/stdc++.h> n using namespace std; n inline long long in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n inline string get() { n   char ch[2000010]; n   scanf( %s , ch); n   return ch; n } n inline void read(long long *a, long long n) { n   for (long long i = 0; i < n; i++) a[i] = in(); n } n template <class blank> n inline void out(blank x) { n   cout << x <<   n ; n   exit(0); n } n const long long maxn = 1e5 + 10; n const long long maxm = 1e6 + 10; n const long long maxlg = 21; n const long long base = 29; n const long long mod = 1e9 + 7; n const long long INF = 1e18 + 10; n const long long SQ = 317 + 5; n vector<long long> g[maxn]; n long long h[maxn], st[maxn], root[maxn][maxlg], cur; n struct cmp { n   inline bool operator()(const long long &a, const long long &b) const { n     return st[a] < st[b]; n   } n }; n set<long long, cmp> SET; n inline void dfs(long long node, long long fa = 0) { n   h[node] = fa == 0 ? 0 : h[fa] + 1; n   root[node][0] = fa; n   st[node] = cur++; n   for (long long i = 1; i < maxlg; i++) n     root[node][i] = root[root[node][i - 1]][i - 1]; n   for (auto u : g[node]) n     if (u - fa) dfs(u, node); n } n inline long long lca(long long p, long long q) { n   if (h[p] < h[q]) swap(p, q); n   for (long long i = maxlg - 1; i >= 0; i--) n     if (h[p] - (1 << i) >= h[q]) p = root[p][i]; n   if (p == q) return p; n   for (long long i = maxlg - 1; i >= 0; i--) n     if (root[p][i] != root[q][i]) p = root[p][i], q = root[q][i]; n   return root[p][0]; n } n inline long long dis(long long v, long long u) { n   return h[v] + h[u] - 2 * h[lca(v, u)]; n } n inline long long add(long long x, long long fl = 0, long long tp = 0) { n   if (SET.empty() || (SET.size() == 1 && tp == 1)) { n     if (fl) { n       if (tp == 0) n         SET.insert(x); n       else n         SET.erase(x); n     } n     return 1 * (tp == 0 ? 1 : -1); n   } n   long long pre, nxt; n   set<long long>::iterator it, it2; n   it = it2 = SET.upper_bound(x); n   if (it == SET.end()) it = SET.begin(); n   if (it2 == SET.begin()) it2 = SET.end(); n   it2--; n   if (*it2 == x) { n     if (it2 == SET.begin()) it2 = SET.end(); n     it2--; n   } n   pre = *it2, nxt = *it; n   if (fl) { n     if (tp == 0) n       SET.insert(x); n     else n       SET.erase(x); n   } n   return (dis(x, pre) + dis(x, nxt) - dis(pre, nxt)) / 2 * (tp == 0 ? 1 : -1); n } n long long tot; n long long res; n int32_t main() { n   long long n = in(), k = in(); n   for (long long i = 0; i < n - 1; i++) { n     long long v = in(), u = in(); n     g[v].push_back(u); n     g[u].push_back(v); n   } n   dfs(1); n   long long r = 1; n   for (long long i = 1; i <= n; i++) { n     while (r <= n && add(r) + tot <= k) tot += add(r++, 1); n     res = max(res, r - i); n     if (r == i) r++; n     tot += add(i, 1, 1); n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n FILE *outt, *inn; n const int N = 3e5 + 10; n int n, a[N], res[N], ans, c, l, r; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   ans = -1; n   for (int i = 0; i < n; i++) { n     l = r = i; n     while (l > 0 && a[l - 1] % a[i] == 0) l--; n     while (r < n - 1 && a[r + 1] % a[i] == 0) r++; n     if ((r - l) > ans) ans = r - l, c = 0; n     if ((r - l) == ans) res[c++] = l; n     i = r; n   } n   printf( %d %d n , c, ans); n   for (int i = 0; i < c; i++) { n     printf( %d  , res[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int test, i, j, count, flag = 0, n, o1 = 0, o2 = 0, b1, x, y, m, l, n                                    z, max1, x1, y1, x2, y2, z1, k, sum, f, r, n                                    ans1, min1; n   cin >> n; n   long long int a[n]; n   if (n == 1) { n     cin >> x; n     cout <<  1  n  << x; n     return 0; n   } n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   vector<long long int> a1; n   vector<long long int> a2; n   flag = 0; n   for (i = 0; i < n; i++) { n     if (a1.size() == 0) { n       a1.push_back(a[i]); n     } else { n       if (a2.size() == 0) { n         a2.push_back(a[i]); n       } else { n         if (a2.back() != a[i]) { n           a2.push_back(a[i]); n         } else { n           if (a1.back() != a[i]) { n             a1.push_back(a[i]); n           } n         } n       } n     } n   } n   if (a1.size() >= 1 && a2.size() >= 1) { n     if (a1.back() == a2.back()) { n       a1.pop_back(); n     } n   } n   cout << a1.size() + a2.size() <<   n ; n   for (i = 0; i < a1.size(); i++) { n     cout << a1[i] <<    ; n   } n   for (i = a2.size() - 1; i >= 0; i--) { n     cout << a2[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n, h, p[N], q[N], bit[N]; n void update(int x, int v) { n   for (; x < n; x += (x + 1) & -(x + 1)) bit[x] += v; n } n int sum(int x) { n   int res = 0; n   for (; x >= 0; x -= (x + 1) & -(x + 1)) res += bit[x]; n   return res; n } n void solve() { n   fill(bit, bit + n, 0); n   for (int i = n - 1; i >= 0; i--) { n     int x = sum(p[i] - 1); n     update(p[i], 1); n     p[i] = x; n   } n   fill(bit, bit + n, 0); n   for (int i = n - 1; i >= 0; i--) { n     int x = sum(q[i] - 1); n     update(q[i], 1); n     q[i] = x; n   } n   for (int i = n - 1; i >= 0; i--) { n     int c = (p[i] + q[i]) / (n - i); n     p[i] = (p[i] + q[i]) % (n - i); n     if (i > 0) { n       p[i - 1] += c; n     } n   } n   fill(bit, bit + n, 0); n   for (int i = 0; i < n; i++) update(i, 1); n   for (int i = 0; i < n; i++) { n     if (i) printf(   ); n     int lo = 0, hi = n; n     while (lo < hi) { n       int m = lo + (hi - lo) / 2; n       if (p[i] + 1 <= sum(m)) n         hi = m; n       else n         lo = m + 1; n     } n     printf( %d , lo); n     update(lo, -1); n   } n   printf(  n ); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , p + i); n   for (int i = 0; i < n; i++) scanf( %d , q + i); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ara[400005], csum1[400005], csum2[400005]; n int main() { n   int n; n   scanf( %d , &n); n   long long sum = 0; n   for (int i = 0; i < n; i++) n     scanf( %lld , &ara[i]), sum += ara[i], csum1[ara[i]] += ara[i], n         csum2[ara[i]]++; n   for (int i = 1; i <= 400000; i++) n     csum1[i] += csum1[i - 1], csum2[i] += csum2[i - 1]; n   sort(ara, ara + n); n   long long res = 0, lft = 0; n   for (int i = 0; i < n; i++) { n     long long s = 0; n     int x = ara[i]; n     while (i < n && ara[i] == x) s += ara[i], i++; n     i--; n     long long temp = 0; n     for (int j = x; j <= 200000; j += x) n       temp += (csum1[j + x - 1] - csum1[j]) - (csum2[j + x - 1] - csum2[j]) * j; n     res = max(res, sum - temp - lft); n     lft += s; n   } n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using db = double; n int mod = 1000000007; n db pie = 3.1415926535; n int spf[5000005]; n int mm = 5000000; n int pre[5000005]; n void help() { n   int i; n   for (i = 1; i <= mm; i++) { n     spf[i] = i; n   } n   for (i = 2; i <= mm; i += 2) { n     spf[i] = 2; n   } n   int j; n   for (i = 3; i * i <= mm; i += 2) { n     if (spf[i] == i) { n       for (j = i * i; j <= mm; j += i) { n         if (spf[j] == j) spf[j] = i; n       } n     } n   } n   pre[0] = 0; n   pre[1] = 0; n   for (i = 2; i <= mm; i++) { n     int m = i; n     int cnt = 0; n     while (m > 1) { n       cnt++; n       m = m / spf[m]; n     } n     pre[i] = cnt; n     pre[i] += pre[i - 1]; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   help(); n   while (t--) { n     int a, b; n     cin >> a >> b; n     int ans = pre[a] - pre[b]; n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Query { n   int left; n   int right; n   int index; n   bool operator<(const Query &other) const { return right < other.right; } n }; n const int N = 1e6 + 100; n int a[N]; n int xorSum[N]; n Query q[N]; n int ans[N]; n struct FenwickTree { n   FenwickTree() { fill(array, array + N, 0); } n   int lowbit(int a) { return a & -a; } n   void update(int i, int value) { n     while (i <= n) { n       array[i] ^= value; n       i += lowbit(i); n     } n   } n   int query(int i) { n     int res = 0; n     while (i > 0) { n       res ^= array[i]; n       i -= lowbit(i); n     } n     return res; n   } n   int n; n   int array[N]; n } tr; n int main() { n   int n, m, i, j; n   scanf( %d , &n); n   tr.n = n; n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   scanf( %d , &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &q[i].left, &q[i].right); n     q[i].index = i; n   } n   sort(q + 1, q + 1 + m); n   map<int, int> last; n   for (i = 1, j = 1; i <= n; i++) { n     int &lastTmp = last[a[i]]; n     if (lastTmp > 0) { n       tr.update(lastTmp, a[i]); n     } n     lastTmp = i; n     tr.update(i, a[i]); n     xorSum[i] = xorSum[i - 1] ^ a[i]; n     for (; j <= m && q[j].right == i; j++) { n       ans[q[j].index] = xorSum[i] ^ xorSum[q[j].left - 1] ^ n                         tr.query(q[j].right) ^ tr.query(q[j].left - 1); n     } n   } n   for (i = 1; i <= m; i++) { n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long expr(long long n, long long e) { n   if (e == 0) return 1; n   if (e & 1) { n     return n * expr(n, e ^ 1); n   } else n     return expr(n, e >> 1) * expr(n, e >> 1); n } n int main() { n   long long n, l, r; n   scanf( %lld %lld %lld , &n, &l, &r); n   long long count = 0; n   long long root = 0.000001 + pow((double)r, 1.0 / ((double)n - 1.0)); n   if (n == 1) { n     printf( %lld n , r - l + 1); n     return 0; n   } n   if (n == 2) { n     printf( %lld n , (r - l + 1) * (r - l)); n     return 0; n   }; n   for (long long i = 1; i <= root; i++) { n     for (long long j = i + 1; j <= root; j++) { n       if (gcd(i, j) == 1) { n         long long maxb = r / expr(j, n - 1); n         long long minb = ceil((double)l / (double)expr(i, n - 1)); n         ; n         count += max(0ll, maxb - minb + 1); n       } n     } n   } n   printf( %lld n , 2 * count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100009; n const long long MOD = 1e9 + 7; n int dX[] = {0, 0, 1, -1}; n int dY[] = {1, -1, 0, 0}; n long long GCD(long long num, long long ones) { n   return !ones ? num : GCD(ones, num % ones); n } n string s; n map<int, int> mp; n long long ans, sum; n int arr[4040]; n int main() { n   scanf( %lld , &sum); n   cin >> s; n   int n = (s.size()); n   for (int i = 0; i < n; ++i) arr[i + 1] = s[i] -  0 , arr[i + 1] += arr[i]; n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       mp[arr[j] - arr[i]]++; n     } n   } n   if (sum == 0) { n     if (mp.count(0)) n       cout << mp[0] * (n * 1LL * n - mp[0] + n); n     else n       puts( 0 ); n     return 0; n   } n   for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) { n     if (!it->first) continue; n     if (sum % it->first == 0 && mp.count(sum / it->first)) n       ans += mp[sum / it->first] * 1LL * it->second; n   } n   cout << ans; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n #define int ll n typedef pair<int, int> P; n ll gcd(ll a, ll b){return b? gcd(b, a % b): a;} n ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;} n // head n  n const int N = 2e3 + 5, inf = 1e18; n int n, m, w, mat[N][N]; n int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; n  n void bfs(int x0, int y0, vector<vector<int>> &d) { n  d.resize(n + 1, vector<int> (m + 1, inf)); n  queue<pair<int, int>> quu; n  quu.push(make_pair(x0, y0)); n  d[x0][y0] = 0; n  while (!quu.empty()) { n   int px = quu.front().first, py = quu.front().second; n   quu.pop(); n   for (int i = 0; i < 4; i++) { n    int nx = px + dx[i], ny = py + dy[i]; n    if (1 <= nx && nx <= n && 1 <= ny && ny <= m && mat[nx][ny] != -1 && d[nx][ny] == inf) { n     d[nx][ny] = d[px][py] + w; n     quu.push(make_pair(nx, ny)); n    } n   } n  } n } n  n void show(vector<vector<int>> &vt) { n  for (int i = 1; i <= n; i++) { n   for (int j = 1; j <= m; j++) { n    cout << vt[i][j] <<    ; n   } n   cout << endl; n  } n } n  n signed main(void){ n  ios::sync_with_stdio(false); n  cin.tie(0); n  cin >> n >> m >> w; n  for (int i = 1; i <= n; i++) { n   for (int j = 1; j <= m; j++) { n    cin >> mat[i][j]; n   } n  } n  vector<vector<int>> d1, d2; n  bfs(1, 1, d1); n  bfs(n, m, d2); n  int ans = d1[n][m]; n  int mn1 = inf; n  for (int i = 1; i <= n; i++) { n   for (int j = 1; j <= m; j++) { n    if (mat[i][j] <= 0) continue; n    mn1 = min(mn1, d1[i][j] + mat[i][j]); n   } n  } n  int mn2 = inf; n  for (int i = 1; i <= n; i++) { n   for (int j = 1; j <= m; j++) { n    if (mat[i][j] <= 0) continue; n    mn2 = min(mn2, d2[i][j] + mat[i][j]); n   } n  } n  ans = min(ans, mn1 + mn2); n  if (ans == inf) { n   cout << -1 << endl; n  } n  else { n   cout << ans << endl; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int BUFFER_SIZE = 1 << 20; n char rb[BUFFER_SIZE], *rp = rb, *rt = rb; n inline char read_char() { n   return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp++) n                   : *rp++; n } n inline int read_int() { n   int x = 0; n   char ch = read_char(), flag = 0; n   while (ch !=  -  && (ch <  0  || ch >  9 )) { n     ch = read_char(); n   } n   if (ch ==  - ) { n     flag = 1; n     ch = read_char(); n   } n   for (x = 0; ch >=  0  && ch <=  9 ; ch = read_char()) { n     x = x * 10 + (ch -  0 ); n   } n   return flag ? -x : x; n } n const int MAX_N = 200000 + 5; n int N, n[2], siz[MAX_N]; n int ey[MAX_N << 1], enext[MAX_N << 1], elast[MAX_N]; n void dp(int u, int fa, int dep) { n   n[dep & 1]++; n   siz[u] = 1; n   for (int j = elast[u]; j; j = enext[j]) { n     int v = ey[j]; n     if (v != fa) { n       dp(v, u, dep ^ 1); n       siz[u] += siz[v]; n     } n   } n } n int main() { n   N = read_int(); n   for (int i = 1, j = 1; i < N; i++) { n     int x = read_int(); n     int y = read_int(); n     ey[j] = y; n     enext[j] = elast[x]; n     elast[x] = j++; n     ey[j] = x; n     enext[j] = elast[y]; n     elast[y] = j++; n   } n   dp(1, 0, 0); n   long long ans = 0; n   for (int i = 1; i <= N; i++) { n     ans += 1ll * siz[i] * (N - siz[i]); n   } n   ans += 1ll * n[0] * n[1]; n   printf( %lld n , ans >> 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   string s; n   cin >> s; n   int x = -1, y = -1; n   for (int i = 0; i < s.size(); ++i) { n     for (int j = 0; j < i; ++j) { n       if (s[i] == s[j]) { n         x = j, y = i; n       } n     } n   } n   if (abs(y - x) == 1) { n     cout <<  Impossible  << endl; n     return 0; n   } n   int len = y - x; n   char ans[2][13]; n   for (int i = 0; i < 13; ++i) { n     ans[0][i] = ans[1][i] =  * ; n   } n   for (int i = (len + 1) / 2 - 1; i >= 0; i--) { n     ans[0][i] = s[x + ((len + 1) / 2 - 1 - i)]; n   } n   for (int i = 0; i < len - (len + 1) / 2; ++i) { n     ans[1][i] = s[x + (len + 1) / 2 + i]; n   } n   int pos0 = (len + 1) / 2, pos1 = len - (len + 1) / 2; n   if (13 - pos0 > x) { n     for (int i = 0; i < x; ++i) { n       ans[0][pos0 + i] = s[x - 1 - i]; n     } n     for (int i = pos1; i < 13; ++i) { n       ans[1][i] = s[y + 1 + (i - pos1)]; n     } n     for (int i = pos0 + x; i < 13; ++i) { n       ans[0][i] = s[27 - (i - pos0 - x) - 1]; n     } n   } else { n     for (int i = 0; i < 13 - pos0; ++i) { n       ans[0][pos0 + i] = s[x - 1 - i]; n     } n     for (int i = pos1; i < pos1 + (26 - y); ++i) { n       ans[1][i] = s[y + 1 + (i - pos1)]; n     } n     pos1 += 26 - y; n     for (int i = 0; i + pos1 < 13; ++i) { n       ans[1][i + pos1] = s[i]; n     } n   } n   for (int i = 0; i < 13; ++i) { n     cout << ans[0][i]; n   } n   cout << endl; n   for (int i = 0; i < 13; ++i) { n     cout << ans[1][i]; n   } n   cout << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int m = 1e9 + 7; n const int N = 3e5 + 15; n const int64_t INF = 100000000000000018LL; n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, n                greater<pair<long long, long long>>> n     pq; n vector<vector<long long>> graph(N); n vector<long long> collect; n map<long long, long long> mpp; n set<pair<long long, long long>> s; n set<long long> second; n long long odd = 0, even = 0; n long long pow(long long a, long long b, long long m) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % m; n     b /= 2; n     a = (a * a) % m; n   } n   return ans; n } n long long inv(long long a) { return pow(a, m - 2, m); } n void dfs(long long ind, vector<bool>& visited) { n   visited[ind] = true; n   for (auto it : graph[ind]) { n     { n       if (!visited[it]) dfs(it, visited); n     } n   } n } n bool isPowerOfTwo(long long n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n void solve() { n   long long a, b, n, x; n   cin >> a >> b >> n >> x; n   long long ans = pow(a, n, m); n   n = n % m; n   long long aa = ans * x; n   if (aa < 0) aa += m; n   aa = aa % m; n   long long aa1 = 1; n   if (a == 1) { n     long long z1 = b * n; n     z1 = z1 % m; n     cout << (x + z1) % m; n     return; n   } n   aa1 = ((ans - 1 + m) % m) * inv(a - 1); n   aa1 = aa1 % m; n   if (aa1 < 0) aa1 += m; n   aa1 = aa1 * b; n   cout << (aa + aa1 + m) % m <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string str; n   cin >> n >> str; n   int sum = 0; n   bool flag = false; n   for (int i = 0; i < n - 1; i++) { n     sum += str[i] - 48; n     int ts = 0, ti = i + 1; n     while (ti < n && ts <= sum) { n       if (ts == sum && str[ti] != 48) { n         ts = 0; n       } n       ts += str[ti] - 48; n       ti++; n     } n     if (ti == n && ts == sum) { n       flag = true; n       break; n     } n   } n   if (flag) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, st; n int tmp, tmp2; n vector<int> adj[200005]; n int memo[200005][5]; n bool vis[200005][5]; n int stc, stn; n pair<int, int> par[200005][5]; n int dp(int node, int cur) { n   if (adj[node].size() == 0) { n     if (cur == 2) { n       stc = cur; n       stn = node; n       return 1; n     } n     if (cur == 1) { n       stc = cur; n       stn = node; n     } n     return cur; n   } n   if (memo[node][cur] != -1) return memo[node][cur]; n   int ret = 0; n   pair<int, int> cp; n   cp.first = node; n   cp.second = cur; n   for (int i = 0; i < adj[node].size(); i++) { n     if (cur == 2) { n       if (vis[adj[node][i]][cur]) { n         if (ret == 0) ret = 2; n         continue; n       } n       vis[adj[node][i]][cur] = 1; n       par[adj[node][i]][cur] = cp; n       int now = dp(adj[node][i], cur); n       if (now == 1) ret = 1; n       vis[adj[node][i]][cur] = 0; n     } else { n       if (vis[adj[node][i]][(cur + 1) % 2]) { n         if (ret == 0) ret = 2; n         continue; n       } n       vis[adj[node][i]][(cur + 1) % 2] = 1; n       par[adj[node][i]][(cur + 1) % 2] = cp; n       int now = dp(adj[node][i], (cur + 1) % 2); n       if (now == 1) n         ret = 1; n       else if (now == 2 && ret == 0) n         ret = 2; n       vis[adj[node][i]][(cur + 1) % 2] = 0; n     } n   } n   return memo[node][cur] = ret; n } n void dfs(int node, int cur) { n   if (node == st && cur == 0) { n     printf( %d , node); n     return; n   } n   dfs(par[node][cur].first, par[node][cur].second); n   printf(  %d , node); n   return; n } n int main() { n   memset(memo, -1, sizeof(memo)); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &tmp); n     for (int j = 1; j <= tmp; j++) { n       scanf( %d , &tmp2); n       adj[i].push_back(tmp2); n     } n   } n   scanf( %d , &st); n   int ans = dp(st, 0); n   if (ans == 0) { n     printf( Lose n ); n   } else if (ans == 2) { n     printf( Draw n ); n   } else { n     printf( Win n ); n     dfs(stn, stc); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n char ch[111111]; n int main() { n   scanf( %d%d , &n, &k); n   scanf( %s , ch); n   int pos = 0; n   for (int act = 0; act <= 1000000 && act < k && pos < n - 1; ++act) { n     if (act >= 1000000 && act % 2 == k % 2) break; n     while (pos < n - 1 && !(ch[pos] ==  4  && ch[pos + 1] ==  7 )) pos++; n     if (pos == n - 1) break; n     if (pos % 2 == 0) n       ch[pos] = ch[pos + 1] =  4 ; n     else n       ch[pos] = ch[pos + 1] =  7 ; n     --pos; n     if (pos < 0) pos = 0; n   } n   printf( %s n , ch); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100000; n const int MAXV = 100; n double prob[MAXN + 5][MAXV + 5]; n int sz[MAXN + 5]; n double temp[MAXV + 5]; n int n; n double ncr(int r, int n) { n   if (r > n) return 0; n   double ret = 1; n   for (int c = 0; c < r; c++) ret *= n - c; n   for (int c = 0; c < r; c++) ret /= c + 1; n   return ret; n } n double probabilityToTaketakeFromVuntasted(int take, int k, int untasted, n                                           int from) { n   int tasted = sz[from] - untasted; n   return ncr(take, untasted) * ncr(k - take, tasted) / ncr(k, sz[from]); n } n int main() { n   int c, c2; n   memset(prob, 0, sizeof(prob)); n   double ret = 0; n   scanf( %d , &n); n   for (c = 0; c < n; c++) { n     scanf( %d , &sz[c]); n     prob[c][sz[c]] = 1.0; n   } n   for (c = 0; c < n; c++) ret += prob[c][0]; n   int qs; n   for (scanf( %d , &qs); qs; qs--) { n     int from, to, k; n     scanf( %d%d%d , &from, &to, &k); n     from--; n     to--; n     memset(temp, 0, sizeof(temp)); n     double denominator = ncr(k, sz[from]); n     for (int untasted = 0; untasted <= MAXV; untasted++) { n       int newk = min(k, untasted); n       int tasted = sz[from] - untasted; n       double n1 = 1, n2 = 1; n       double d1 = 1, d2 = 1; n       for (int i = 0; i < min(tasted, k); i++) { n         d2 *= i + 1; n         n2 *= tasted - i; n       } n       for (int take = 0; take <= k; take++) { n         if (take > 0) { n           d1 *= take; n           if (take <= untasted) n             n1 *= untasted - take + 1; n           else n             n1 = 0; n         } n         if (k - take > tasted) continue; n         temp[untasted - take] += n             prob[from][untasted] * (n1 / d1) * (n2 / d2) / denominator; n         if (k - take > 0) { n           d2 /= k - take; n           n2 /= tasted - (k - take) + 1; n         } n       } n     } n     ret += temp[0] - prob[from][0]; n     for (int i = 0; i <= MAXV; i++) prob[from][i] = temp[i]; n     sz[from] -= k; n     sz[to] += k; n     printf( %.10lf n , ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:500000000 ) n using namespace std; n vector<int> A[2]; n int main() { n   int n, i, j, t, w; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> t >> w; n     A[t - 1].push_back(w); n   } n   for (i = 0; i < 2; i++) sort(A[i].begin(), A[i].end(), greater<int>()); n   int res = 0x3F3F3F3F; n   for (int x = -1; x < (int)A[0].size(); x++) { n     for (int y = -1; y < (int)A[1].size(); y++) { n       w = (x + 1) + 2 * (y + 1); n       int s = 0; n       for (i = x + 1; i < A[0].size(); i++) s += A[0][i]; n       for (i = y + 1; i < A[1].size(); i++) s += A[1][i]; n       if (s <= w) res = min(res, w); n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int a, b, k; n   cin >> a >> b >> k; n   long long int total = 0; n   if (k % 2 != 0) { n     total -= b * (k / 2); n     total += a * (k / 2 + 1); n   } else { n     total -= b * (k / 2); n     total += a * (k / 2); n   } n   cout << total << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int a[503][503]; n int max_row[503]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, q, i, j, mxi, cnt, x, y; n   cin >> n >> m >> q; n   for (i = 1; i <= n; i++) { n     mxi = 0, cnt = 0; n     for (j = 1; j <= m; j++) { n       cin >> a[i][j]; n       if (a[i][j]) n         cnt++; n       else n         cnt = 0; n       mxi = ((mxi > cnt) ? mxi : cnt); n     } n     max_row[i] = mxi; n   } n   for (i = 0; i < q; i++) { n     cin >> x >> y; n     a[x][y] ^= 1; n     cnt = 0, mxi = 0; n     for (j = 1; j <= m; j++) { n       if (a[x][j]) n         cnt++; n       else n         cnt = 0; n       mxi = ((mxi > cnt) ? mxi : cnt); n     } n     max_row[x] = mxi; n     mxi = 0; n     for (j = 1; j <= n; j++) mxi = ((mxi > max_row[j]) ? mxi : max_row[j]); n     cout << mxi << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char A[200006]; n int S[200006], T[200006]; n void solve() { n   cin >> n >> m; n   scanf( %s , A + 1); n   long long re = 0; n   for (int i = (1), iend = (n); i <= iend; ++i) { n     S[i] = (A[i] != A[i + 1]) + S[i - 1]; n     if (i >= 2 && A[i] == A[i - 2]) n       T[i] = T[i - 1] + 1; n     else if (i >= 2) n       T[i] = 2; n     else n       T[i] = 1; n   } n   for (int r = (1), rend = (n); r <= rend; ++r) { n     if (A[r] != A[r - 1]) re += (m - 1) * 1ll * (r - 1); n     re += m - 1; n     re += S[r - 1] * 1ll * (m - 1); n     if (A[r] != A[r - 1]) re -= T[r] - 1; n   } n   cout << re << endl; n } n signed main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, k, m, n, x, y; n   cin >> n; n   if (n == 1) { n     x = 9; n     y = 8; n   } n   if (n == 2) { n     x = 6; n     y = 4; n   } n   if (n == 3) { n     x = 9; n     y = 6; n   } n   if ((n != 2) && (n != 1) && (n != 3)) { n     if (n % 2 == 0) { n       x = 2 * n; n       y = n; n     } else { n       x = n + 9; n       y = 9; n     } n   } n   cout << x <<     << y <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long A, B, D; n int a[70], b[70], len1, len2; n int main() { n   cin >> A >> B; n   D = A - B; n   unsigned long long temp = A; n   if (A < B) { n     cout << -1 << endl; n     return 0; n   } n   while (A) { n     a[len1++] = A % 2; n     A /= 2; n   } n   while (B) { n     b[len2++] = B % 2; n     B /= 2; n   } n   unsigned long long res = 0; n   for (int i = len1 - 1; i >= 0; --i) { n     if (!b[i]) { n       unsigned long long n = (1ULL << i); n       if (n <= D / 2.0) { n         D -= 2 * n; n         res += n; n       } n     } n   } n   if (D) { n     cout << -1 << endl; n     return 0; n   } n   cout << res <<     << temp - res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, d; n   while (~scanf( %lld%lld , &x, &d)) { n     vector<pair<long long, int> > counts; n     long long sum = 0; n     long long num = 1; n     while (x > 0) { n       long long two = 1; n       int count = 0; n       while (two - 1 <= x) two *= 2, count++; n       two /= 2, count--; n       sum += count; n       counts.emplace_back(num, count); n       x -= two - 1; n       num += d; n     } n     printf( %lld n , sum); n     for (int i = 0; i < counts.size(); i++) n       for (int j = 0; j < counts[i].second; j++) n         printf( %lld  , counts[i].first); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int long long x, y, l, r, k, i, j, ans; n vector<int long long> mex, mey, my; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> x >> y >> l >> r; n   for (k = 1; k <= 1e18 / x; k *= x) mex.push_back(k); n   if (k <= 1e18) mex.push_back(k); n   for (k = 1; k <= 1e18 / y; k *= y) mey.push_back(k); n   if (k <= 1e18) mey.push_back(k); n   for (i = 0; i < mex.size(); i++) { n     for (j = 0; j < mey.size(); j++) { n       if (mex[i] + mey[j] > r) break; n       if (mex[i] + mey[j] >= l) { n         my.push_back(mex[i] + mey[j]); n       } n     } n   } n   my.push_back(l - 1); n   x = l; n   sort(my.begin(), my.end()); n   my.push_back(r + 1); n   for (i = 1; i < my.size(); i++) { n     ans = max(ans, my[i] - my[i - 1] - 1); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int N, P; n bool can = false; n string word; n int main() { n   scanf( %d%d , &N, &P); n   cin >> word; n   if (P == 1) { n     cout <<  NO n ; n     return 0; n   } else if (P == 2) { n     if (N == 1) { n       if (word ==  a ) n         cout <<  b n ; n       else n         cout <<  NO n ; n     } else if (N == 2) { n       if (word ==  ab ) n         cout <<  ba n ; n       else n         cout <<  NO n ; n     } else if (N > 2) n       cout <<  NO n ; n     return 0; n   } n   for (int i = N - 1; i >= 0; --i) { n     ++word[i]; n     while ((i >= 1 && word[i] == word[i - 1]) || n            (i >= 2 && word[i] == word[i - 2])) n       ++word[i]; n     if ((word[i] -  a ) + 1 <= P) { n       can = true; n       for (int j = i + 1; j < N; ++j) { n         word[j] =  a ; n         while ((j >= 1 && word[j] == word[j - 1]) || n                (j >= 2 && word[j] == word[j - 2])) n           ++word[j]; n       } n       break; n     } n   } n   if (can) n     cout << word; n   else n     cout <<  NO 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   ; n   int ts; n   cin >> ts; n   while (ts--) { n     long long n, i, vis[500] = {0}, a; n     cin >> n; n     for (i = 1; i <= 2 * n; i++) { n       cin >> a; n       if (vis[a] == 0) { n         cout << a <<    ; n       } n       vis[a] = 1; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n int a[1003][1003], p[maxn], num[maxn], n, m, vis[1003][1003]; n long long k; n int dx[4] = {1, -1, 0, 0}; n int dy[4] = {0, 0, 1, -1}; n int fi(int x) { return p[x] == x ? x : p[x] = fi(p[x]); } n void uni(int x, int y) { n   int p1 = fi(x), p2 = fi(y); n   if (p1 == p2) return; n   p[p1] = p2; n   num[p2] += num[p1]; n   num[p1] = 0; n } n struct node { n   int x, y, z; n   node(int x1, int y1, int z1) { x = x1, y = y1, z = z1; } n }; n bool cmp(node a, node b) { return a.x > b.x; } n vector<node> Q; n void solve(int x, int y, int z, int v) { n   queue<node> Q; n   Q.push(node(x, y, 0)); n   vis[x][y] = 1; n   z--; n   while (!Q.empty()) { n     node now = Q.front(); n     Q.pop(); n     for (int i = 0; i < 4; i++) { n       int xx = now.x + dx[i]; n       int yy = now.y + dy[i]; n       if (z == 0) continue; n       if (xx <= 0 || xx > n) continue; n       if (yy <= 0 || yy > m) continue; n       if (vis[xx][yy]) continue; n       if (a[xx][yy] < v) continue; n       vis[xx][yy] = 1, z--; n       Q.push(node(xx, yy, 0)); n     } n   } n   for (int i = 1; i <= n; i++, cout << endl) n     for (int j = 1; j <= m; j++) n       if (vis[i][j]) n         printf( %d  , v); n       else n         printf( 0  ); n } n int main() { n   scanf( %d%d%lld , &n, &m, &k); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       scanf( %d , &a[i][j]), Q.push_back(node(a[i][j], i, j)); n   for (int i = 0; i < maxn; i++) p[i] = i, num[i] = 1; n   sort(Q.begin(), Q.end(), cmp); n   for (int i = 0; i < Q.size(); i++) { n     int v = Q[i].x; n     if (v == 0) break; n     int x = Q[i].y; n     int y = Q[i].z; n     for (int j = 0; j < 4; j++) { n       int xx = x + dx[j]; n       int yy = y + dy[j]; n       if (a[xx][yy] >= v) uni((xx - 1) * m + yy, (x - 1) * m + y); n     } n     long long Num = k / v; n     if (k % v) continue; n     int fa = fi((x - 1) * m + y); n     if (Num <= num[fa]) { n       printf( YES n ); n       solve(x, y, Num, v); n       return 0; n     } n   } n   printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 2e6 + 14; n int n, a[Maxn], b[Maxn], ans, m; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = a[i], m = max(m, a[i]); n   sort(a, a + n); n   for (int i = 1; i <= 2 * m; i++) { n     if (b[i] == 0) b[i] = b[i - 1]; n   } n   for (int i = m - 1; i > ans; i--) { n     if (b[i] == i) n       for (int j = i * 2 - 1; j < 2 * m; j += i) { n         ans = max(ans, b[j] % i); n       } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 1e9; n const int MX = 1e6 + 5; n const int MD = 1e9 + 7; n int next(vector<int> &a, int pos, long long p) { n   long long cnt = 2; n   int l = pos, r = pos; n   while (r < ((int)a.size())) { n     while (r < ((int)a.size()) && cnt > 0 && a[r] == a[l]) r++, cnt--; n     if (cnt == 0) return r; n     if (r == ((int)a.size())) return -1; n     for (int i = 0; cnt <= ((int)a.size()) && i < a[l] - a[r]; i++) cnt *= p; n     if (cnt > ((int)a.size())) return -1; n     l = r; n   } n   return -1; n } n long long pt(long long b, long long e) { n   long long ans = 1; n   while (e > 0) { n     if (e & 1) ans = (ans * b) % MD; n     b = (b * b) % MD; n     e >>= 1; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, p; n     cin >> n >> p; n     vector<int> a(n); n     for (int &x : a) cin >> x; n     if (p == 1) { n       cout << n % 2 <<   n ; n       continue; n     } n     sort(a.begin(), a.end()); n     reverse(a.begin(), a.end()); n     int last = -1; n     for (int l = 0, r = 0; l < n; l = r) { n       r = next(a, l, p); n       if (r == -1) { n         last = l; n         break; n       } n     } n     if (last == -1) { n       cout << 0 <<   n ; n       continue; n     } n     long long ans = pt(p, a[last]); n     for (int i = last + 1; i < n; i++) ans = (ans - pt(p, a[i]) + MD) % MD; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   char a[15], b[15], c[15]; n   scanf( %s%s , a, b); n   scanf( %d , &n); n   printf( %s %s n , a, b); n   for (int i = 1; i <= n; i++) { n     scanf( %s , c); n     int l = strlen(c); n     int la = strlen(a); n     int lb = strlen(b); n     if (memcmp(a, c, l) == 0 && l == la) { n       scanf( %s , a); n       printf( %s %s n , a, b); n     } n     if (memcmp(b, c, l) == 0 && l == lb) { n       scanf( %s , b); n       printf( %s %s n , a, b); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 1; n const long long nol = 0; n long long n, k, a, cnt, ans, j, mx; n deque<long long> v, vc; n void vkoshp() { n   cin >> n >> k; n   for (long long i = 0; i < n; i++) { n     cin >> a; n     v.push_back(a); n   } n   for (long long i = 0; i < n; i++) { n     cin >> a; n     if (a == 1) n       cnt += v[i], vc.push_back(0); n     else n       ans += v[i], vc.push_back(v[i]); n     mx = max(mx, ans); n     if (vc.size() == k) { n       ans -= vc[0]; n       vc.pop_front(); n     } n   } n   cout << cnt + mx << endl; n } n int main() { n   cout.tie(NULL); n   cin.tie(NULL); n   ios_base::sync_with_stdio(0); n   long long t = 1; n   while (t--) vkoshp(); n } n


#include <bits/stdc++.h> n using namespace std; n int f[10000001]; n int main() { n   int n, m, l, r; n   scanf( %d%d , &n, &m); n   long long ans = 0; n   int Max0 = max(n * 2, m); n   for (long long b = 1; b <= n; ++b) { n     ans += 2 * min(b * b, (long long)m); n     l = max(0, int(ceil(sqrt(b * b - m)))); n     r = int(floor(sqrt(b * b - 1))); n     ++f[-b - r + Max0], --f[-b - l + 1 + Max0], ++f[-b + l + Max0], n         --f[-b + r + 1 + Max0]; n   } n   int s = 0; n   for (int i = 0; i < Max0; ++i) { n     s += f[i]; n     if (s > 1) ans -= s - 1; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t = 0; n int ans = 1; n long long int prime(long long int n) { n   while (n % 2 == 0) { n     if (t == 2) break; n     n = n / 2; n     t++; n     ans *= 2; n   } n   for (int i = 3; i <= sqrt(n); i += 2) { n     while (n % i == 0) { n       if (t == 2) break; n       n = n / i; n       t++; n       ans *= i; n     } n     if (t == 2) break; n   } n   if (n > 2 && t != 2) { n     ans *= n; n     t++; n     n = 1; n   } n   return n; n } n int main() { n   cin.tie(NULL); n   cout.tie(NULL); n   ios_base::sync_with_stdio(false); n   long long int n; n   cin >> n; n   if (n == 1) n     cout << 1 <<   n  << 0; n   else { n     long long int final = prime(n); n     if (final == 1 && t == 1) n       cout << 1 << endl << 0; n     else if (final == 1 && t == 2) n       cout << 2; n     else if (t == 2) n       cout << 1 <<   n  << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &a) { n   return os <<  (  << a.first <<  ,   << a.second <<  ) ; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &a) { n   os <<  [ ; n   for (unsigned long long i = 0; i < a.size(); i++) n     os << a[i] << (i < a.size() - 1 ?  ,   :   ); n   os <<  ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &a) { n   os <<  { ; n   for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) { n     typename set<T>::iterator jt = it; n     os << *it << (++jt != a.end() ?  ,   :   ); n   } n   os <<  } ; n   return os; n } n template <class T1, class T2> n ostream &operator<<(ostream &os, map<T1, T2> &a) { n   os <<  { n ; n   for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) { n     typename map<T1, T2>::iterator jt = it; n     os <<      << it->first <<  :   << it->second n        << (++jt != a.end() ?  , n  :   n ); n   } n   os <<  } ; n   return os; n } n long long n, m; n long long a[2005]; n long long dp[2005][2]; n bool check(long long lim) { n   memset(dp, 127, sizeof(dp)); n   dp[0][0] = dp[0][1] = 0; n   for (long long i = 1; i <= n; i++) { n     dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + 1; n     dp[i][1] = min(dp[i][1], i - 1); n     for (long long j = 1; j < i; j++) { n       long long diff = abs(a[i] - a[j]); n       if (diff > lim * (i - j)) continue; n       dp[i][1] = min(dp[i][1], dp[j][1] + (i - j - 1)); n     } n   } n   if (min(dp[n][0], dp[n][1]) <= m) return true; n   return false; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   long long l = 0, r = 2e9; n   while (l != r) { n     long long mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   cout << l <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX - 10000000; n const double eps = 1e-8; n long long t1, t2, x1, x2, t0; n int main() { n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   if (t1 == t2) { n     cout << x1 <<     << x2 << endl; n     return 0; n   } n   long long minp = 12345678, minq = 1; n   long long y2, ans = 0; n   for (long long y1 = 0; y1 <= x1; y1++) { n     long long Left = 0, Right = x2, Mid; n     if (y1) n       while (Left <= Right) { n         Mid = Left + Right >> 1; n         if ((t2 - t1) * Mid < (t0 - t1) * (Mid + y1)) n           Left = Mid + 1; n         else n           Right = Mid - 1; n       } n     else n       Left = x2; n     if ((t2 - t1) * Left < (t0 - t1) * (Left + y1) || Left > x2) continue; n     if (Left * (t2 - t1) * minq - minq * (t0 - t1) * (Left + y1) < n         minp * (Left + y1)) { n       y2 = Left; n       ans = y1 + y2; n       minp = Left * (t2 - t1) - (t0 - t1) * (Left + y1); n       minq = Left + y1; n     } else if (Left * (t2 - t1) * minq - minq * (t0 - t1) * (Left + y1) == n                minp * (Left + y1)) { n       if (Left + y1 > ans) { n         y2 = Left; n         ans = y1 + y2; n       } n     } n   } n   cout << ans - y2 <<     << y2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long powmod(long long n, long long q) { n   long long ans = 1; n   n %= 1000000007; n   while (q > 0) { n     if (q & 1) ans = (ans * n) % 1000000007; n     n = (n * n) % 1000000007; n     q >>= 1; n   } n   return ans % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int tc = 1; n   while (tc--) { n     int n, ans = 0; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       for (int j = i + 1; j <= n; j++) { n         int k = i ^ j; n         if (k < i + j) { n           if (i < k + j) { n             if (j < i + k) { n               if (k >= 1 && k <= n) ans++; n             } n           } n         } n       } n     } n     cout << ans / 3 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int reverseChar(char input) { n   const int N = 8; n   int output(0); n   for (int p = 0; p < N; p++) { n     output = 2 * output + (input % 2); n     input /= 2; n   } n   return output; n } n int main() { n   const int N = 256; n   std::string line; n   getline(std::cin, line); n   int previous = 0; n   for (int p = 0; p < line.size(); p++) { n     int current = reverseChar(line[p]); n     printf( %d n , (N + previous - current) % N); n     previous = current; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct box { n   long long int x1, x2, y1, y2; n   box() : x1(0), x2(0), y1(0), y2(0) {} n   box(int x1, int x2, int y1, int y2) : x1(x1), x2(x2), y1(y1), y2(y2) {} n }; n struct edge { n   long long int to, c, f; n   edge() : to(0), c(0), f(0) {} n   edge(int to, long long int c, int f) : to(to), c(c), f(f) {} n }; n bool ins(box a, box b) { n   if (a.x1 >= b.x1 && a.x2 <= b.x2 && a.y1 >= b.y1 && a.y2 <= b.y2) { n     return 1; n   } n   return 0; n } n const int M = 5000000; n edge edges[M]; n vector<int> g[M]; n int cnt = 0; n int nxt[M]; n int d[M]; n int oy[40000]; n int ox[40000]; n int lasty[10000]; n vector<int> how; n int n1; n void addedge(int v, int u, long long int c) { n   edges[cnt] = edge(u, c, 0); n   g[v].push_back(cnt++); n   edges[cnt] = edge(v, 0, 0); n   g[u].push_back(cnt++); n } n void buildy(int v, int l, int r) { n   if (l == r) { n     addedge(100000, v, 1); n     return; n   } n   int m = (l + r) / 2; n   buildy(2 * v, l, m); n   buildy(2 * v + 1, m + 1, r); n   addedge(2 * v, v, 1000000); n   addedge(2 * v + 1, v, 1000000); n   return; n } n void buildx(int v, int l, int r) { n   if (l == r) { n     addedge(v + 40000, 100001, 1); n     return; n   } n   int m = (l + r) / 2; n   buildx(2 * v, l, m); n   buildx(2 * v + 1, m + 1, r); n   addedge(v + 40000, 2 * v + 40000, 1000000); n   addedge(v + 40000, 2 * v + 1 + 40000, 1000000); n   return; n } n void gety(int v, int l, int r, int l1, int r1) { n   if (l >= l1 && r <= r1) { n     how.push_back(v); n     return; n   } n   if (l > r1 || l1 > r) return; n   int m = (l + r) / 2; n   gety(2 * v, l, m, l1, r1); n   gety(2 * v + 1, m + 1, r, l1, r1); n } n void getx(int v, int l, int r, int l1, int r1) { n   if (l >= l1 && r <= r1) { n     for (auto c : how) { n       addedge(c, 40000 + v, 1000000000); n     } n     return; n   } n   if (l > r1 || l1 > r) return; n   int m = (l + r) / 2; n   getx(2 * v, l, m, l1, r1); n   getx(2 * v + 1, m + 1, r, l1, r1); n } n void makepr(int x1, int x2, int y1, int y2) { n   how.clear(); n   gety(1, 0, n1 - 1, x1, x2); n   getx(1, 0, n1 - 1, y1, y2); n } n bool bfs(int s, int t, int n) { n   for (int i = 0; i < n; i++) d[i] = 1000000; n   d[s] = 0; n   queue<int> q; n   q.push(s); n   while (q.size()) { n     int v = q.front(); n     q.pop(); n     for (auto c : g[v]) { n       int to = edges[c].to; n       if (d[to] <= d[v] + 1 || edges[c].c == edges[c].f) continue; n       d[to] = d[v] + 1; n       q.push(to); n     } n   } n   if (d[t] == 1000000) return 0; n   return 1; n } n long long int dfs(int v, int t, long long int f) { n   if (v == t) return f; n   if (f == 0) return 0; n   long long int sum = 0; n   for (; nxt[v] < g[v].size(); nxt[v]++) { n     int id = g[v][nxt[v]]; n     int to = edges[id].to; n     if (d[to] != d[v] + 1 || edges[id].c == edges[id].f) continue; n     long long int del = dfs(to, t, min(edges[id].c - edges[id].f, f - sum)); n     sum += del; n     edges[id].f += del; n     edges[id ^ 1].f -= del; n     if (sum == f) break; n   } n   return sum; n } n long long int dinic(int s, int t, int n) { n   long long int mf = 0; n   while (bfs(s, t, n)) { n     for (int i = 0; i < n; i++) nxt[i] = 0; n     mf += dfs(s, t, 1e9); n   } n   return mf; n } n bool cmp(box a, box b) { return (a.y1 < b.y1); } n void solve() { n   cin >> n1; n   int m; n   cin >> m; n   vector<box> all(m); n   for (int i = 0; i < m; i++) { n     cin >> all[i].x1 >> all[i].y1 >> all[i].x2 >> all[i].y2; n     all[i].x1--; n     all[i].x2--; n     all[i].y1--; n     all[i].y2--; n   } n   sort(begin(all), end(all), cmp); n   buildy(1, 0, n1 - 1); n   buildx(1, 0, n1 - 1); n   for (auto c : all) { n     int x1, x2, y1, y2; n     y1 = c.x1; n     y2 = c.x2; n     x1 = c.y1; n     x2 = c.y2; n     int cur = 0; n     for (int i = 0; i < n1; i++) { n       if (lasty[cur] != lasty[i]) { n         if (cur >= y1 && i - 1 <= y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, cur, i - 1); n           for (int y = cur; y <= i - 1; y++) lasty[y] = x2 + 1; n         } n         if (cur < y1 && i - 1 > y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, y1, y2); n           for (int y = y1; y <= y2; y++) lasty[y] = x2 + 1; n           cur = i; n         } n         if (cur < y1 && i - 1 <= y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, y1, i - 1); n           for (int y = y1; y <= i - 1; y++) lasty[y] = x2 + 1; n         } n         if (cur >= y1 && i - 1 > y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, cur, y2); n           for (int y = cur; y <= y2; y++) lasty[y] = x2 + 1; n         } n         cur = i; n       } n       if (i == n1 - 1) { n         i++; n         if (cur >= y1 && i - 1 <= y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, cur, i - 1); n           for (int y = cur; y <= i - 1; y++) lasty[y] = x2 + 1; n         } n         if (cur < y1 && i - 1 > y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, y1, y2); n           for (int y = y1; y <= y2; y++) lasty[y] = x2 + 1; n         } n         if (cur < y1 && i - 1 <= y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, y1, i - 1); n           for (int y = y1; y <= i - 1; y++) lasty[y] = x2 + 1; n         } n         if (cur >= y1 && i - 1 > y2) { n           if (lasty[cur] != x1) makepr(lasty[cur], x1 - 1, cur, y2); n           for (int y = cur; y <= y2; y++) lasty[y] = x2 + 1; n         } n       } n     } n   } n   int cur = 0; n   for (int i = 0; i < n1; i++) { n     if (lasty[cur] != lasty[i]) { n       if (lasty[cur] <= n1 - 1) makepr(lasty[cur], n1 - 1, cur, i - 1); n       cur = i; n     } n     if (i == n1 - 1) { n       i++; n       if (lasty[cur] <= n1 - 1) makepr(lasty[cur], n1 - 1, cur, i - 1); n       cur = i; n     } n   } n   cout << dinic(100000, 100001, 100002); n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   int t; n   t = 1; n   while (t) { n     t--; n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5010; n const int MOD = 1000000007; n int n, x[N], y[N], w[N][N], vis[N]; n inline void dfs(int v, int val) { n   for (int u = 0; u < n; u++) { n     if (w[v][u] > val) { n       if (vis[u] == vis[v]) throw 0; n       if (vis[u] != -1) continue; n       vis[u] = !vis[v]; n       dfs(u, val); n     } n   } n } n inline int check(int val) { n   memset(vis, -1, sizeof vis); n   int ans = 1; n   for (int i = 0; i < n; i++) n     if (vis[i] == -1) { n       try { n         vis[i] = 0; n         dfs(i, val); n       } catch (...) { n         return 0; n       } n       ans += ans; n       if (ans >= MOD) ans -= MOD; n     } n   return ans; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d%d , x + i, y + i); n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       w[i][j] = w[j][i] = abs(x[i] - x[j]) + abs(y[i] - y[j]); n   int lo = 0, hi = 10050, mid; n   while (lo < hi) { n     mid = lo + hi >> 1; n     if (check(mid)) n       hi = mid; n     else n       lo = mid + 1; n   } n   cout << hi <<   n  << check(hi) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int rowblk[200005]; n long long int colblk[200005]; n long long int col[200005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int l, n, i, j, k, m; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> k >> l; n     rowblk[k] = 1; n     colblk[l] = 1; n   } n   long long int cnt = 0; n   for (i = 2; i < n; i++) { n     if (colblk[i] == 0) { n       cnt++; n       col[i] = 1; n     } n   } n   for (i = 2; i < n; i++) { n     if (rowblk[i] == 0) { n       if (n % 2 != 0 && i == n / 2 + 1) { n         if (col[i] == 0) cnt++; n       } else { n         cnt++; n       } n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[200001]; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   sort(arr, arr + n, greater<int>()); n   long long gcf = 0, total = 0; n   for (int i = 0; i < n; ++i) { n     gcf = gcd(arr[0] - arr[i], gcf); n     total += (arr[0] - arr[i]); n   } n   cout << total / gcf <<     << gcf << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout <<  ?  <<    ; n   fflush(stdout); n   for (int i = 0; i < 100; i++) { n     cout << i <<    ; n     fflush(stdout); n   } n   cout << endl; n   int n; n   cin >> n; n   cout <<  ?  <<    ; n   fflush(stdout); n   long long a = 0; n   for (int i = 0; i < 100; i++) { n     a += (1 << 7); n     cout << a <<    ; n     fflush(stdout); n   } n   cout << endl; n   int b; n   cin >> b; n   bitset<14> x(n), y(b), z; n   for (int i = 0; i < 14; i++) { n     if (i < 7) n       z[i] = y[i]; n     else n       z[i] = x[i]; n   } n   cout <<  !   << z.to_ulong(); n } n


#include <bits/stdc++.h> n using namespace std; n struct Pair { n   int a, b, c; n }; n int a1[200009], a2[200009]; n vector<Pair> arr; n bool rules(Pair x, Pair y) { return ((x.a - x.b) < (y.a - y.b)); } n int main() { n   int n, k, sum = 0; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , &a1[i]); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a2[i]); n     Pair p; n     p.a = a1[i], p.b = a2[i]; n     arr.push_back(p); n   } n   sort(arr.begin(), arr.end(), rules); n   for (int i = 0; i < k; i++) sum += arr[i].a; n   for (int i = k; i < n; i++) sum += min(arr[i].a, arr[i].b); n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void umax(T &x, T y) { n   if (y > x) x = y; n } n template <class T> n inline void umin(T &x, T y) { n   if (y < x) x = y; n } n const int N = 2e5 + 5, B = 0x7fffffff; n map<int, int> comp; n set<int> s; n vector<int> ans; n int a[N]; n int st[4 * N]; n int n; n int nn; n void upd(int l, int r, int id, int u, int v) { n   if (l == r) { n     umax(st[id], v); n     return; n   } n   int mid = (l + r) >> 1; n   if (u <= mid) n     upd(l, mid, id << 1, u, v); n   else n     upd(mid + 1, r, id << 1 | 1, u, v); n   st[id] = max(st[id << 1], st[id << 1 | 1]); n } n int get(int l, int r, int id, int ql, int qr) { n   if (r < ql || l > qr) return 0; n   if (l >= ql && r <= qr) return st[id]; n   int mid = (l + r) >> 1; n   return max(get(l, mid, id << 1, ql, qr), n              get(mid + 1, r, id << 1 | 1, ql, qr)); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , &a[i]), s.insert(a[i]), s.insert(a[i] - 1); n   for (int x : s) comp[x] = ++nn; n   for (int i = n; i >= 1; i--) { n     int ppq = (get(1, nn, 1, 1, comp[a[i] - 1])); n     ans.push_back(ppq == 0 ? -1 : ppq - i - 1); n     upd(1, nn, 1, comp[a[i]], i); n   } n   for (int i = (int)ans.size() - 1; i >= 0; i--) printf( %d  , ans[i]); n   return !1; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const long long int MOD = 1000000007; n int main() { n   int t, a, b; n   scanf( %lld , &t); n   while (t--) { n     scanf( %d %d , &a, &b); n     if (b >= a) n       printf( 1 ); n     else { n       vector<int> v; n       bool k = false; n       int c; n       for (int i = 1; i * i <= a; i++) { n         if (a % i == 0) { n           v.push_back(i); n           v.push_back(a / i); n           k = true; n         } n       } n       if (!k) n         printf( %d , a); n       else { n         sort(v.begin(), v.end(), greater<int>()); n         for (int i = 0; i < (int)v.size(); i++) { n           if (v[i] <= b) { n             printf( %d , a / v[i]); n             break; n           } n         } n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void __p(T a) { n   cout << a; n } n template <typename T, typename U> n void __p(pair<T, U> a) { n   cout <<  { ; n   __p(a.first); n   cout <<  , ; n   __p(a.second); n   cout <<  } ; n } n template <typename T> n void __p(std::vector<T> a) { n   cout <<  { ; n   for (auto it = a.begin(); it < a.end(); it++) n     __p(*it), cout <<  ,} [it + 1 == a.end()]; n } n void solve() { n   long long n, k; n   cin >> n >> k; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   if (n == 2) { n     cout << 2 - k * (a[0] | a[1]) << endl; n     return; n   } n   long long ans = 2 - k * (a[0] | a[1]); n   for (long long i = n - 2; i > n - 300 && i >= 0; i--) { n     for (long long j = n - 1; j > i; j--) { n       ans = max(ans, (i + 1) * (j + 1) - k * (a[i] | a[j])); n     } n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc = 1; n   cin >> tc; n   for (int t = 1; t <= tc; t++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, x; n bool X[26]; n int mat[6][6]; n int niz[26]; n int sum; n bool check() { n   sum = 0; n   for (int i = 0; i < n; i++) sum += mat[i][0]; n   for (int j = 1; j < n; j++) { n     int st = 0; n     for (int i = 0; i < n; i++) st += mat[i][j]; n     if (st != sum) return false; n   } n   for (int i = 0; i < n; i++) { n     int st = 0; n     for (int j = 0; j < n; j++) st += mat[i][j]; n     if (st != sum) return false; n   } n   int sz = 0; n   for (int i = 0; i < n; i++) { n     sz += mat[i][i]; n   } n   if (sz != sum) return false; n   sz = 0; n   for (int i = 0; i < n; i++) { n     sz += mat[i][n - i - 1]; n   } n   if (sz != sum) return false; n   return true; n } n vector<pair<int, int> > pos; n vector<int> vals; n int empty_cnt = 0; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n * n; i++) { n     scanf( %d , &niz[i]); n     vals.push_back(i); n     pos.push_back(make_pair(i / n, i % n)); n   } n   do { n     for (int i = 0; i < pos.size(); i++) { n       mat[pos[i].first][pos[i].second] = niz[vals[i]]; n     } n     if (check()) { n       break; n     } n   } while (next_permutation(vals.begin(), vals.end())); n   printf( %d n , sum); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       printf( %d  , mat[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[200001], b[200001], m; n int main() { n   cin >> n >> m; n   n = n + m; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   vector<int> vec; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &b[i]); n     if (b[i] == 1) { n       vec.push_back(a[i]); n     } n   } n   vec.push_back(2e9 + 1); n   int l = 0, cnt = 0, r = 1, c = 0; n   while (l < vec.size() - 1 && r <= n) { n     if (b[r] == 0) { n       while (abs(a[r] - vec[l]) > abs(a[r] - vec[l + 1])) { n         cout << cnt <<    ; n         c++; n         l++; n         cnt = 0; n       } n       cnt++; n     } n     r++; n   } n   cout << cnt <<    ; n   for (int i = 0; i < vec.size() - 2 - c; i++) { n     cout <<  0  ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<1000> mask[1010]; n long long sqr(int x) { return 1LL * x * x; } n int n, m, k; n int px[10010], py[10010], x[10010], y[10010], r[10010]; n int main() { n   int i, j; n   scanf( %d%d%d , &n, &m, &k); n   for (i = 0; i < n; ++i) { n     scanf( %d%d , &px[i], &py[i]); n   } n   for (i = 0; i < m; ++i) { n     scanf( %d%d%d , &r[i], &x[i], &y[i]); n   } n   for (i = 0; i < n; ++i) { n     for (j = 0; j < m; ++j) n       if (sqr(px[i] - x[j]) + sqr(py[i] - y[j]) <= sqr(r[j])) mask[i][j] = 1; n   } n   while (k--) { n     int a, b; n     scanf( %d%d , &a, &b); n     printf( %d n , (mask[a - 1] ^ mask[b - 1]).count()); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int n; n int head[N], Next[N << 1], ver[N << 1], size[N], edge[N << 1], w[N]; n int tot; n long long ans; n void add(int x, int y, int z) { n   ver[++tot] = y; n   edge[tot] = z; n   Next[tot] = head[x]; n   head[x] = tot; n } n void dfs(int x, int fa) { n   size[x] = 1; n   for (int i = head[x]; i; i = Next[i]) { n     int y = ver[i]; n     if (y == fa) continue; n     dfs(y, x); n     size[x] += size[y]; n   } n } n void solve(int x, int fa, long long s) { n   for (int i = head[x]; i; i = Next[i]) { n     int y = ver[i], z = edge[i]; n     if (y == fa) continue; n     if (s + (long long)z > (long long)w[y]) n       ans += (long long)size[y]; n     else n       solve(y, x, max(0ll, s + (long long)z)); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &w[i]); n   for (int i = 2; i <= n; i++) { n     int p, c; n     scanf( %d%d , &p, &c); n     add(p, i, c); n     add(i, p, c); n   } n   dfs(1, 0); n   solve(1, 0, 0ll); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 50; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n long long n, k; n long long a[maxn]; n int vis[maxn]; n long long ans = 0; n bool Overflow(long long x, long long y) { n   if (x > LLONG_MAX / y) n     return false; n   else n     return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   memset(vis, 0, sizeof(vis)); n   memset(a, 0, sizeof(a)); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   vis[n + 1] = -1; n   for (int i = n; i >= 1; i--) { n     if (a[i] > 1) n       vis[i] = i; n     else n       vis[i] = vis[i + 1]; n   } n   long long p = 1; n   long long s = 0; n   for (int i = 1; i <= n; i++) { n     int j = i; n     p = a[i]; n     s = a[i]; n     if (p == s * k) ans++; n     while (1) { n       int z = vis[j + 1]; n       if (z == -1) z = n + 1; n       int ones = z - j - 1; n       if (p % k == 0 && p / k - s >= 1 && p / k - s <= ones) { n         ans++; n       } n       if (z == n + 1) break; n       if (Overflow(p, a[z])) { n         p = p * a[z]; n         j = z; n         s = s + a[z] + ones; n         if (p == s * k) ans++; n       } else n         break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e5 + 5; n long long N, K; n long long v[MAXN]; n int main() { n   cin >> N >> K; n   for (int i = 0; i < N; i++) cin >> v[i]; n   sort(v, v + N); n   long long resp = N; n   for (int i = 0; i < N; i++) { n     long long value = v[i] * K; n     int l = i + 1, r = N - 1; n     while (l <= r) { n       int mid = (l + r) / 2; n       if (v[mid] == value) { n         resp--; n         v[mid] = -1; n         break; n       } n       if (v[mid] < value) n         l = mid + 1; n       else n         r = mid - 1; n     } n   } n   cout << resp << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, k, n, c = 0, p = 0, al, bl, l = 0; n   string s; n   cin >> s; n   for (i = 0; i < s.length(); i++) { n     l++; n     c += (s[i] -  0 ); n     if (c % 3 == 0 || (s[i] -  0 ) % 3 == 0 || l >= 3) { n       p++; n       c = 0; n       l = 0; n     } n   } n   if (s[0] ==  0 ) p--; n   cout << p; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMX = 5007; n const int MMX = 20007; n long long a[NMX][NMX]; n long long mi[NMX]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int k, l; n     scanf( %d %d , &k, &l); n     a[k % n][l % n] += 1; n   } n   for (int i = 0; i < n; i++) { n     bool first = false; n     for (int j = i; j < (n + i); j++) { n       if (first == false && a[i][j % n] >= 1) { n         mi[i] += abs(j - i); n         first = true; n         a[i][j % n] -= 1; n       } n       mi[i] += a[i][j % n] * n; n     } n   } n   for (int i = 1; i <= n; i++) { n     long long ans = 0; n     for (int j = 1; j <= n; j++) { n       if (mi[j % n] >= 1) n         ans = max(ans, mi[j % n] + ((i > j) ? n - i + j : j - i)); n     } n     cout << ans <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int h[n]; n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n   } n   int wys[n][2]; n   int rosnpr = 0; n   int rosnlw = 0; n   for (int i = 0; i < n; i++) { n     if (h[i] > rosnpr) { n       rosnpr++; n       wys[i][0] = rosnpr; n     } else { n       rosnpr = h[i]; n       wys[i][0] = rosnpr; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     if (h[i] > rosnlw) { n       rosnlw++; n       wys[i][1] = rosnlw; n     } else { n       rosnlw = h[i]; n       wys[i][1] = rosnlw; n     } n   } n   int maxi = 0; n   for (int i = 0; i < n; i++) { n     if (min(wys[i][0], wys[i][1]) > maxi) { n       maxi = min(wys[i][0], wys[i][1]); n     } n   } n   cout << maxi; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename S, typename T> n ostream& operator<<(ostream& out, pair<S, T> const& p) { n   out <<  (  << p.first <<  ,   << p.second <<  ) ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T> const& v) { n   int l = v.size(); n   for (int i = 0; i < l - 1; i++) out << v[i] <<    ; n   if (l > 0) out << v[l - 1]; n   return out; n } n template <typename T> n void trace(const char* name, T&& arg1) { n   cout << name <<   :   << arg1 << endl; n } n template <typename T, typename... Args> n void trace(const char* names, T&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   trace(comma + 1, args...); n } n vector<int> htov(string s) { n   vector<int> ret; n   for (char c : s) { n     if (c <=  9 ) n       ret.push_back(c -  0 ); n     else n       ret.push_back(10 + c -  a ); n   } n   reverse(ret.begin(), ret.end()); n   return ret; n } n void sub(vector<int>& v) { n   int n = v.size(); n   if (n == 1 and v[0] == 0) return; n   int i = 0; n   while (i < n and v[i] == 0) i++; n   v[i]--; n   if (i > 0) { n     for (int j = 0; j < i; j++) v[j] = 15; n     if (v[i] == 0 and (i + 1) == v.size()) v.resize(i); n   } n   return; n } n const int N = 17; n long long dp[N][2][2]; n long long get(vector<int> v) { n   reverse(v.begin(), v.end()); n   int n = v.size(); n   long long res = 0; n   for (int d = 1; d < 16; d++) { n     if ((d / 4) + 1 > n) break; n     memset(dp, 0, sizeof dp); n     dp[0][1][0] = 1; n     for (int i = 0; i < n; i++) { n       for (int eq = 0; eq < 2; eq++) { n         for (int flag = 0; flag < 2; flag++) { n           long long val = dp[i][eq][flag]; n           if (!val) continue; n           int max_nd = min(d, (eq == 0) ? 15 : v[i]); n           for (int nd = 0; nd <= max_nd; nd++) { n             if (n - i - 1 == d / 4 and (nd & (1 << (d % 4))) == 0) continue; n             int neq = (eq and nd == v[i]); n             int nflag = (flag or nd == d); n             dp[i + 1][neq][nflag] += val; n           } n         } n       } n     } n     for (int eq = 0; eq < 2; eq++) { n       res += dp[n][eq][1]; n     } n   } n   return res; n } n void solve() { n   string l, r; n   cin >> l >> r; n   vector<int> R = htov(r); n   vector<int> L = htov(l); n   sub(L); n   cout << get(R) - get(L) << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int q; n   cin >> q; n   while (q--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct fenwick_tree_t { n   vector<int> t; n   void init(int n) { t.assign(n, 0); } n   void inc(int pos, int x = 1) { n     while (pos < (int)t.size()) { n       t[pos] += x; n       pos = pos | (pos + 1); n     } n   } n   int get(int pos) const { n     int ret = 0; n     while (pos >= 0) { n       ret += t[pos]; n       pos = (pos & (pos + 1)) - 1; n     } n     return ret; n   } n }; n vector<int> ord(vector<int> const &a) { n   fenwick_tree_t tree; n   tree.init(a.size() + 1); n   vector<int> ret(a.size(), 0); n   for (int i = (int)ret.size() - 1; i >= 0; --i) { n     ret[i] = tree.get(a[i]); n     tree.inc(a[i]); n   } n   return ret; n } n ostream &operator<<(ostream &out, vector<int> const &a) { n   for (int x : a) out << x <<    ; n   return out; n } n vector<int> solve(vector<int> const &a, vector<int> const &b) { n   vector<int> ord_a = ord(a); n   vector<int> ord_b = ord(b); n   vector<int> ord_ans(ord_a.size(), 0); n   for (int i = 0; i < (int)ord_ans.size(); ++i) n     ord_ans[i] = ord_a[i] + ord_b[i]; n   reverse(ord_ans.begin(), ord_ans.end()); n   for (int i = 0; i < (int)ord_ans.size(); ++i) { n     if (ord_ans[i] >= i + 1) { n       if (i + 1 < (int)ord_ans.size()) ++ord_ans[i + 1]; n       ord_ans[i] -= i + 1; n     } n   } n   reverse(ord_ans.begin(), ord_ans.end()); n   vector<int> ans(ord_ans.size(), 0); n   fenwick_tree_t t; n   t.init(ord_ans.size() + 1); n   for (int i = 0; i < (int)ans.size(); ++i) t.inc(i); n   for (int i = 0; i < (int)ans.size(); ++i) { n     int l = -1, r = ans.size() - 1; n     while (r - l > 1) { n       int m = (l + r) / 2; n       if (t.get(m) < ord_ans[i] + 1) { n         l = m; n       } else { n         r = m; n       } n     } n     t.inc(r, -1); n     ans[i] = r; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> a(n), b(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> b[i]; n   cout << solve(a, b) << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n bool sortbysec(const pair<char, int> &a, const pair<char, int> &b) { n   return (a.second < b.second); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string ip, hh, mm; n   cin >> ip; n   hh = ip.substr(0, 2); n   string hr = hh; n   reverse(hr.begin(), hr.end()); n   mm = ip.substr(3, 4); n   if (hh ==  23  && (stoi(mm) >= stoi(hr))) n     cout <<  00:00 ; n   else if (hh ==  06  || hh ==  07  || hh ==  08  || hh ==  09 ) n     cout <<  10:01 ; n   else if (hh ==  15  && stoi(mm) >= 51 || hh ==  16  || hh ==  17  || n            hh ==  18  || hh ==  19 ) n     cout <<  20:02 ; n   else if (stoi(mm) < stoi(hr)) n     cout << hh <<  :  << hr; n   else { n     int x = (stoi(hh) + 1) % 10 * 10 + stoi(hh) / 10; n     int y = stoi(hh) + 1; n     if (y >= 10) n       cout << y <<  :  << x; n     else n       cout <<  0  << y <<  :  << x; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int N = 1e5 + 10; n char a[N], b[N]; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     scanf( %s%s , a, b); n     int t = 0; n     int t1 = 0, t2 = 0; n     for (int i = 0; i < n; i++) { n       if (a[i] != b[i]) { n         t++; n         if (t == 1) n           t1 = i; n         else if (t == 2) n           t2 = i; n       } n       if (t == 3) break; n     } n     if (t != 2) n       printf( No n ); n     else { n       if (t == 0 || (a[t1] == a[t2] && b[t1] == b[t2])) n         printf( Yes n ); n       else n         printf( No n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q; n int par[26][100005], depth[100005]; n vector<int> st[400005]; n vector<int> G[100005]; n vector<int> SS[26][100005]; n int cnt, chaincnt; n void get10(vector<int> &res, const vector<int> &fir, const vector<int> sec) { n   int c1 = 0, c2 = 0; n   res = vector<int>(min((int)fir.size() + (int)sec.size(), 10)); n   for (int i = 0; i < (int)res.size(); i++) { n     if (c1 != fir.size() && c2 != sec.size()) { n       if (fir[c1] < sec[c2]) { n         res[i] = fir[c1++]; n       } else { n         res[i] = sec[c2++]; n       } n     } else if (c1 == fir.size()) { n       res[i] = sec[c2++]; n     } else { n       res[i] = fir[c1++]; n     } n   } n   return; n } n set<int> ret1, ret2; n int LCA(int u, int v) { n   ret1.clear(), ret2.clear(); n   if (depth[u] < depth[v]) swap(u, v); n   int dif = depth[u] - depth[v]; n   for (int i = 0; i <= 24; i++) { n     if (dif & (1 << i)) { n       u = par[i][u]; n     } n   } n   if (u == v) return u; n   for (int i = 24; i >= 0; i--) { n     if (par[i][u] != par[i][v]) { n       u = par[i][u], v = par[i][v]; n     } n   } n   return par[0][u]; n } n vector<int> solve(int u, int v) { n   int lca = LCA(u, v); n   int d1 = depth[u] - depth[lca] + 1; n   int d2 = depth[v] - depth[lca] + 1; n   int lvl = 26; n   set<int> ret1; n   while (d1 > 0) { n     if ((1 << lvl) <= d1) { n       d1 -= (1 << lvl); n       for (int i = 0; i < (int)SS[lvl][u].size() && i < 10; i++) { n         ret1.insert(SS[lvl][u][i]); n       } n       while (ret1.size() > 10) { n         ret1.erase(--ret1.end()); n       } n       u = par[lvl][u]; n     } n     lvl--; n     if (lvl < 0) lvl = 0; n   } n   lvl = 26; n   set<int> ret2; n   while (d2 > 0) { n     if ((1 << lvl) <= d2) { n       d2 -= (1 << lvl); n       for (int i = 0; i < (int)SS[lvl][v].size() && i < 10; i++) { n         ret2.insert(SS[lvl][v][i]); n       } n       while (ret2.size() > 10) { n         ret2.erase(--ret2.end()); n       } n       v = par[lvl][v]; n     } n     lvl--; n     if (lvl < 0) lvl = 0; n   } n   ret1.insert(ret2.begin(), ret2.end()); n   while (ret1.size() > 10) { n     ret1.erase(--ret1.end()); n   } n   vector<int> ret(ret1.begin(), ret1.end()); n   return ret; n } n void dfs(int u, int p, int dep) { n   depth[u] = dep; n   par[0][u] = p; n   for (int i = 0; i < (int)G[u].size(); i++) { n     int v = G[u][i]; n     if (v == p) continue; n     dfs(v, u, dep + 1); n   } n } n int main() { n   int from, to; n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i < n; i++) { n     scanf( %d %d , &from, &to); n     G[from].push_back(to); n     G[to].push_back(from); n   } n   int cur; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &cur); n     SS[0][cur].push_back(i); n   } n   memset(par, -1, sizeof par); n   chaincnt = cnt = 1; n   dfs(1, -1, 0); n   for (int i = 1; i <= 24; i++) n     for (int j = 1; j <= n; j++) n       if (par[i - 1][j] != -1) { n         par[i][j] = par[i - 1][par[i - 1][j]]; n         get10(SS[i][j], SS[i - 1][par[i - 1][j]], SS[i - 1][j]); n       } n   int how; n   vector<int> ans; n   while (q--) { n     scanf( %d %d %d , &from, &to, &how); n     ans = solve(from, to); n     printf( %d , min((int)ans.size(), how)); n     for (int i = 0; i < ans.size() && how; i++, how--) { n       printf(  %d , ans[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, c; n   cin >> n >> c; n   int a[n], t[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int j = 0; j < n; j++) cin >> t[j]; n   int b = 0, e = 0, e1 = 0; n   for (int i = 0; i < n; i++) { n     b += t[i]; n     e += max(0, a[i] - c * b); n   } n   b = 0; n   for (int i = n - 1; i >= 0; i--) { n     b += t[i]; n     e1 += max(0, a[i] - c * b); n   } n   if (e > e1) n     cout <<  Limak ; n   else if (e == e1) n     cout <<  Tie ; n   else n     cout <<  Radewoosh ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n void vrikodara(long long n = 12) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << setprecision(n) << fixed; n } n long long lb = 100000; n void solve() { n   long long n; n   cin >> n; n   set<long long> s, so, se; n   for (long long i = 1; i <= n; i++) s.insert(i); n   vector<long long> p(n + 2); n   for (long long i = 1; i <= n; i++) { n     cin >> p[i]; n     if (p[i]) s.erase(p[i]); n   } n   if (n == 1) { n     cout <<  0 ; n     return; n   } n   for (auto i : s) n     if (i & 1) n       so.insert(i); n     else n       se.insert(i); n   set<pair<long long, long long> > sso, sse; n   for (long long i = 1; i <= n; i++) { n     if (!p[i]) { n       if (!p[i - 1]) continue; n       long long x = i, y = i; n       while (y <= n && !p[y]) y++; n       if (y > n) break; n       if (p[x - 1] & 1 && p[y] & 1) { n         sso.insert({y - x, x}); n       } else if (p[x - 1] % 2 == 0 && p[y] % 2 == 0) { n         sse.insert({y - x, x}); n       } n       i = y; n     } n   } n   if (s.size() >= n - 1) { n     cout <<  1 ; n     return; n   } n   while (!sso.empty() && !so.empty()) { n     auto q = *sso.begin(); n     long long x = q.second; n     long long y = q.first + q.second; n     if (q.first > so.size()) break; n     sso.erase(q); n     while (x < y && !so.empty()) { n       long long j = *so.begin(); n       so.erase(j); n       p[x] = j; n       x++; n     } n     if (x < y) { n       sso.insert({y - x, x}); n       break; n     } n   } n   while (!sse.empty() && !se.empty()) { n     auto q = *sse.begin(); n     long long x = q.second, y = q.first + q.second; n     if (q.first > se.size()) break; n     sse.erase(q); n     while (x < y && !se.empty()) { n       long long j = *se.begin(); n       se.erase(j); n       p[x] = j; n       x++; n     } n     if (x < y) { n       sse.insert({y - x, x}); n       break; n     } n   } n   long long d1 = 1; n   while (d1 <= n && !p[d1]) d1++; n   d1--; n   long long d2 = n; n   while (d2 > 0 && !p[d2]) d2--; n   if (d1 && d2 < n) { n     if (d1 > n - d2) { n       d2++; n       if (p[d2 - 1] & 1) { n         while (!so.empty() && d2 <= n) { n           long long j = *so.begin(); n           so.erase(j); n           p[d2] = j; n           d2++; n         } n       } else { n         while (!se.empty() && d2 <= n) { n           long long j = *se.begin(); n           se.erase(j); n           p[d2] = j; n           d2++; n         } n       } n     } else { n       if (p[d1 + 1] & 1) { n         while (!so.empty() && d1 > 0) { n           long long j = *so.begin(); n           so.erase(j); n           p[d1] = j; n           d1--; n         } n       } else { n         while (!se.empty() && d1 > 0) { n           long long j = *se.begin(); n           se.erase(j); n           p[d1] = j; n           d1--; n         } n       } n     } n   } n   d1 = 1; n   while (d1 <= n && !p[d1]) d1++; n   d1--; n   d2 = n; n   while (d2 > 0 && !p[d2]) d2--; n   d2++; n   if (p[1] == 0) { n     if (p[d1 + 1] & 1) { n       while (!so.empty() && d1 > 0) { n         long long j = *so.begin(); n         so.erase(j); n         p[d1] = j; n         d1--; n       } n     } else { n       while (!se.empty() && d1 > 0) { n         long long j = *se.begin(); n         se.erase(j); n         p[d1] = j; n         d1--; n       } n     } n   } n   if (p[n] == 0) { n     if (p[d2 - 1] & 1) { n       while (!so.empty() && d2 <= n) { n         long long j = *so.begin(); n         so.erase(j); n         p[d2] = j; n         d2++; n       } n     } else { n       while (!se.empty() && d2 <= n) { n         long long j = *se.begin(); n         se.erase(j); n         p[d2] = j; n         d2++; n       } n     } n   } n   for (long long i = 1; i <= n && !so.empty() && !se.empty(); i++) { n     if (!p[i]) { n       if (p[i - 1] & 1) { n         long long j = *so.begin(); n         so.erase(j); n         p[i] = j; n       } else { n         long long j = *se.begin(); n         se.erase(j); n         p[i] = j; n       } n     } n   } n   long long i = 1; n   for (auto j : se) { n     while (p[i] && i <= n) i++; n     p[i] = j; n   } n   for (auto j : so) { n     while (p[i] && i <= n) i++; n     p[i] = j; n   } n   long long ans = 0; n   for (long long i = 2; i <= n; i++) { n     if (p[i] % 2 != p[i - 1] % 2) ans++; n   } n   cout << ans; n } n int32_t main() { n   vrikodara(); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long vis[1009]; n vector<long long> v[1000]; n long long th, n; n void dfs(long long s) { n   if (vis[s]) return; n   vis[s] = 1; n   for (long long i = 0; i < v[s].size(); i++) { n     if (s <= n) th++; n     dfs(v[s][i]); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long i, j, k, m, l, a, prothom = 1, kake, ans = 0; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     cin >> k; n     while (k--) { n       cin >> a; n       v[a + n].push_back(i); n       v[i].push_back(a + n); n     } n   } n   for (i = 1; i <= n; i++) { n     if (vis[i] == 0) { n       ans++; n       dfs(i); n     } n   } n   if (ans == n && th == 0) n     cout << n << endl; n   else n     cout << ans - 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[7]; n   while (scanf( %d , &a[0]) != EOF) { n     int maxx = a[0]; n     int minn = a[0]; n     int ans = 0; n     for (int i = 1; i < 6; i++) { n       cin >> a[i]; n     } n     ans = (a[0] + a[1] + a[2]) * (a[0] + a[2] + a[1]) - a[0] * a[0] - n           a[2] * a[2] - a[4] * a[4]; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( -O3 ) n using ld = long double; n const long long int mod = 1000000007; n const long long int inf = 1000000000000000000; n const long long int rk = 256; n const ld PI = 3.141592653589793; n ostream& operator<<(ostream& os, pair<long long int, long long int> const& x) { n   os << x.first <<  ,  << x.second; n   return os; n } n template <class T> n ostream& operator<<(ostream& os, vector<T> const& x) { n   os <<  {  ; n   for (auto& y : x) os << y <<    ; n   return os <<  } ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> const& x) { n   os <<  {  ; n   for (auto& y : x) os << y <<    ; n   return os <<  } ; n } n template <class Ch, class Tr, class Container> n basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, n                                   Container const& x) { n   os <<  {  ; n   for (auto& y : x) os << y <<    ; n   return os <<  } ; n } n template <class X, class Y> n ostream& operator<<(ostream& os, pair<X, Y> const& p) { n   return os <<  [   << p.first <<  ,   << p.second <<  ] ; n } n const int tot = 1e6 + 5; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   vector<long long int> a(2 * tot, 0); n   for (int i = 1; i <= n; i++) cin >> a[i]; n   long long int q; n   vector<long long int> pos(2 * tot, 0); n   vector<long long int> ans(2 * tot, 0); n   cin >> q; n   for (int time = 1; time <= q; time++) { n     long long int operation, p, x; n     cin >> operation; n     if (operation == 1) { n       cin >> p >> x; n       a[p] = x; n       pos[p] = time; n     } else { n       cin >> ans[time]; n     } n   } n   for (int i = q; i >= 1; i--) { n     ans[i] = max(ans[i], ans[i + 1]); n   } n   for (int i = 1; i <= n; i++) cout << max(a[i], ans[pos[i] + 1]) <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005, val1 = 20, val2 = 50, val3 = 120; n long long in[N], sum[N]; n int n; n long long Sum(int pos) { n   if (pos < 0) return 0LL; n   return sum[pos]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> in[i]; n   for (int i = 0; i < n; i++) { n     int t1 = in[i], t2 = in[i] - 90 + 1, t3 = in[i] - 1440 + 1; n     int pos2 = lower_bound(in, in + n, t2) - in - 1; n     int pos3 = lower_bound(in, in + n, t3) - in - 1; n     int pos1 = i - 1; n     long long Min = val1 + Sum(pos1); n     Min = min(Min, Sum(pos2) + val2); n     Min = min(Min, Sum(pos3) + val3); n     sum[i] = Min; n     cout << Min - sum[i - 1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200005; n int n; n int a[MAXN]; n int inc[MAXN], p; n int de[MAXN], q; n bool flag; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   for (int i = 3; i <= n; ++i) n     if (a[i] == a[i - 1] && a[i - 1] == a[i - 2]) { n       flag = true; n       break; n     } n   if (flag) { n     printf( NO n ); n   } else { n     printf( YES n ); n     a[0] = -0x3f3f3f3f; n     for (int i = 1; i <= n; ++i) { n       if (a[i - 1] == a[i]) { n         de[++q] = a[i]; n       } else n         inc[++p] = a[i]; n     } n     printf( %d n , p); n     for (int i = 1; i <= p; ++i) printf( %d  , inc[i]); n     printf(  n%d n , q); n     for (int i = q; i >= 1; --i) printf( %d  , de[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p, n, m, x[10005], ans; n char c[10005], *s; n void Init() { n   scanf( %d , &p); n   scanf( %s , c + 1); n   if (c[1] ==  - ) n     s = c + 1; n   else { n     c[0] =  + ; n     s = c; n   } n   n = strlen(s); n   int d, t; n   for (int i = 0; i <= n - 1; ++i) { n     if (s[i] ==  + ) n       d = 1; n     else n       d = -1; n     ++i; n     if (s[i] ==  + ) n       ans += d, x[++m] = d; n     else if (s[i] ==  a ) n       x[++m] = d; n     else { n       t = 0; n       while (s[i] !=  * ) { n         t = t * 10 + (s[i] - 48) * d; n         ++i; n       } n       ++i; n       if (s[i] ==  + ) n         ans += t, x[++m] = t; n       else if (s[i] ==  a ) n         x[++m] = t; n     } n     i += 2; n   } n } n void Work() { n   sort(x + 1, x + 1 + m); n   for (int i = 1; i <= m; ++i) { n     ans += x[i] * p; n     ++p; n   } n   printf( %d n , ans); n } n int main() { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } n inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); } n inline long long int bigmod(long long int a, long long int b, long long int m) { n   if (b == 0) return 1 % m; n   long long int x = bigmod(a, b / 2, m); n   x = (x * x) % m; n   if (b % 2 == 1) { n     x = (x * a) % m; n   } n   return x; n } n inline long long int phi(long long int n) { n   long long int ret = n; n   for (long long int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n     } n     ret -= ret / i; n   } n   if (n > 1) { n     ret -= ret / n; n   } n   return ret; n } n long long int missing_number(long long int A[], long long int n) { n   long long int x1 = A[0], x2 = 1; n   for (int i = 1; i < n; i++) x1 ^= A[i]; n   for (int i = 2; i <= n + 1; i++) x2 ^= i; n   return (x1 ^ x2); n } n bool isFibo(long long int n) { n   long long int A = (5 * n * n + 4); n   long long int B = (5 * n * n - 4); n   long long int C = sqrt(A); n   long long int D = sqrt(B); n   return (A == (C * C) || B == (D * D)); n } n long long int classini(long long int n) { return (n & 1) ? -1 : 1; } n long long int factorial(int n) { n   return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; n } n long long int catanal(long long int n) { n   return (factorial(2 * n) / ((factorial(n + 1) * factorial(n)))); n } n string orientation_3_ordered_point(vector<pair<int, int> > V) { n   long long int value = n       (V[1].second - V[0].second) * (V[2].first - V[1].first) - n       (V[1].first * V[0].first) * (V[2].second - V[1].second); n   string res; n   if (value == 0) res =  colinear ; n   value == 1 ? res =  clockwise  : res =  counterclockwise ; n   return res; n } n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1}; n int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; n string make_string(long long int num) { n   stringstream ss; n   ss << num; n   string s; n   ss >> s; n   return s; n } n long long int make_num(string s) { n   stringstream ss; n   long long int tmp; n   ss << s; n   ss >> tmp; n   return tmp; n } n int SET(int mask, int pos) { return (mask | (1 << pos)); } n int check(int mask, int pos) { return (mask & (1 << pos)); } n vector<int> G[100], win[100]; n int V[100], tmp[100]; n bool found = false; n void dfs(int u, int des) { n   tmp[u] = 1; n   if (u == des) { n     found = true; n     return; n   } n   for (auto x : win[u]) { n     if (!tmp[x]) { n       dfs(x, des); n     } n   } n } n int main() { n   int n; n   cin >> n; n   int tot = (n * (n - 1) / 2); n   for (int i = 1; i < tot; i++) { n     int u, v; n     scanf( %d , &u), scanf( %d , &v); n     G[u].push_back(v); n     win[u].push_back(v); n     G[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) { n     int sz = G[i].size(); n     memset(V, 0, sizeof(V)); n     memset(tmp, 0, sizeof(tmp)); n     for (int j = 0; j < sz; j++) { n       V[G[i][j]] = 1; n     } n     for (int k = 1; k <= n; k++) { n       found = false; n       if (!V[k] && k != i) { n         dfs(i, k); n         if (found == true) { n           i = i; n           k = k; n         } else { n           swap(i, k); n         } n         printf( %d , i); n         printf(   ); n         ; n         printf( %d , k); n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 5, mod = 1e9 + 7; n long long n, k, pre[N], suf[N], fac[N], qx[N], qy[N]; n long long mul(long long x, long long n, long long mod) { n   long long ans = mod != 1; n   for (x %= mod; n; n >>= 1, x = x * x % mod) n     if (n & 1) ans = ans * x % mod; n   return ans; n } n long long calc(long long n, long long k, long long qx[N], long long qy[N]) { n   fac[0] = pre[0] = suf[n + 2] = 1; n   for (long long i = 1; i <= n + 1; i++) n     pre[i] = pre[i - 1] * (k - qx[i] + mod) % mod, n     fac[i] = fac[i - 1] * i % mod; n   for (long long i = n + 1; i >= 1; i--) n     suf[i] = suf[i + 1] * (k - qx[i] + mod) % mod; n   long long ans = 0; n   for (long long i = 1; i <= n + 1; i++) { n     long long s = fac[i - 1] * ((n + 1 - i) & 1 ? mod - 1 : 1) % mod * n                   fac[n + 1 - i] % mod; n     ans = (ans + qy[i] * (pre[i - 1] * suf[i + 1] % mod) % mod * n                      mul(s, mod - 2, mod) % mod) % n           mod; n   } n   return ans; n } n signed main() { n   scanf( %lld%lld , &n, &k); n   for (long long i = 1; i <= k + 2; i++) n     qx[i] = i, qy[i] = (qy[i - 1] + mul(i, k, mod)) % mod; n   printf( %lld n , calc(k + 1, n, qx, qy)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, r, s, range = 0; n   scanf( %d%d , &n, &m); n   vector<int> sub[m + 1]; n   set<int> st; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &s, &r); n     sub[s].push_back(r); n     st.insert(s); n   } n   for (auto it : st) { n     int sz = sub[it].size(); n     range = max(range, sz); n     sort(sub[it].begin(), sub[it].end(), greater<int>()); n     for (int i = 1; i < sz; i++) { n       sub[it][i] += sub[it][i - 1]; n     } n   } n   int ans = 0; n   for (int i = 1; i <= range; i++) { n     set<int> t = st; n     int sum = 0; n     for (auto it : t) { n       if ((int)sub[it].size() < i) { n         st.erase(it); n       } else if (sub[it][i - 1] < 0) { n         st.erase(it); n       } else n         sum += sub[it][i - 1]; n     } n     ans = max(ans, sum); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n long long po[1000006]; n long long sr[1000006]; n long long a[1000006]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   po[0] = 1; n   sr[0] = 1; n   for (int i = 1; i <= 1000002; i++) { n     po[i] = po[i - 1] * 2; n     po[i] %= mod; n   } n   sr[1] = 3; n   for (int i = 2; i <= 1000002; i++) { n     sr[i] = ((i + 2) * po[i - 1]) % mod; n   } n   long long n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int pos = 0; n   long long ret = 0; n   for (int i = n - 1; i >= 0; i--) { n     long long co = sr[pos++]; n     long long temp = (co * a[i]) % mod; n     ret += temp; n     ret %= mod; n   } n   cout << ret << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n int vis[100005], tick = 0; n vector<int> G[100005]; n int a[200001], b[200005]; n int main() { n   int n, m, h, t; n   scanf( %d%d%d%d , &n, &m, &h, &t); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n     a[i * 2 - 1] = u; n     b[i * 2 - 1] = v; n     a[i * 2] = v; n     b[i * 2] = u; n   } n   for (int i = 1; i <= n; ++i) sort(G[i].begin(), G[i].end()); n   bool flag = 0; n   for (int i = 1; i <= 2 * m; ++i) { n     int u = a[i], v = b[i]; n     if (G[u].size() - 1 < h || G[v].size() - 1 < t) continue; n     bool done = 0; n     if (G[u].size() > G[v].size()) { n       swap(u, v); n       done = 1; n     } n     int acnt = 0, bcnt = 0, bothcnt = 0; n     for (int j = 0; j < G[u].size(); ++j) { n       if (G[u][j] == v) continue; n       if (binary_search(G[v].begin(), G[v].end(), G[u][j])) { n         bothcnt++; n       } else { n         acnt++; n       } n     } n     bcnt = G[v].size() - 1 - bothcnt; n     if (done) { n       swap(acnt, bcnt); n       swap(u, v); n     } n     if (max(0, h - acnt) + max(0, t - bcnt) > bothcnt) continue; n     tick++; n     for (int j = 0; j < G[u].size(); ++j) n       if (G[u][j] != v) { n         vis[G[u][j]] = tick; n       } n     vector<int> A, B, BOTH; n     tick++; n     for (int j = 0; j < G[v].size(); ++j) n       if (G[v][j] != u) { n         if (vis[G[v][j]] == tick - 1) { n           BOTH.push_back(G[v][j]); n         } else { n           B.push_back(G[v][j]); n         } n         vis[G[v][j]] = tick; n       } n     for (int j = 0; j < G[u].size(); ++j) n       if (G[u][j] != v) { n         if (vis[G[u][j]] != tick) { n           A.push_back(G[u][j]); n         } n       } n     if (max(0, h - (int)A.size()) + max(0, t - (int)B.size()) <= n         (int)BOTH.size()) { n       flag = 1; n       puts( YES ); n       printf( %d %d n , u, v); n       int k = 0; n       while (A.size() < h) A.push_back(BOTH[k++]); n       while (B.size() < t) B.push_back(BOTH[k++]); n       for (int i = 0; i < h; ++i) printf( %d%c , A[i],    n [i == h - 1]); n       for (int i = 0; i < t; ++i) printf( %d%c , B[i],    n [i == t - 1]); n       break; n     } n   } n   if (!flag) puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e3 + 5; n char a[maxn], b[maxn]; n int dp[maxn][maxn]; n int main() { n   int n, m; n   cin >> n >> m; n   scanf( %s%s , a + 1, b + 1); n   int max_ = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2); n       dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1); n       dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1); n       max_ = max(max_, dp[i][j]); n     } n   } n   cout << max_ << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = int(1e9) + 7; n const long long int MOD64 = (long long int)(1e18) + 7; n const int INF = 0x7fffffff; n const long long int INF64 = 0x7fffffffffffffff; n const int N = 2e4 + 200; n int a[60][N]; n int sum[60][N]; n int dp[60][N]; n int t[4 * N], lazy[4 * N]; n void update_lazy(int i, int lo, int hi) { n   if (lazy[i]) { n     t[i] += lazy[i]; n     if (lo != hi) { n       lazy[i * 2] += lazy[i]; n       lazy[i * 2 + 1] += lazy[i]; n     } n     lazy[i] = 0; n   } n } n int update(int i, int lo, int hi, int l, int r, int val) { n   update_lazy(i, lo, hi); n   if (lo > r || hi < l) return t[i]; n   if (l <= lo && hi <= r) { n     t[i] += val; n     if (lo != hi) { n       lazy[i * 2] += val; n       lazy[i * 2 + 1] += val; n     } n     return t[i]; n   } n   int mid = (lo + hi) / 2; n   return t[i] = max(update(i * 2, lo, mid, l, r, val), n                     update(i * 2 + 1, mid + 1, hi, l, r, val)); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = int(1); i < int(n + 1); i++) { n     for (int j = int(1); j < int(m + 1); j++) { n       cin >> a[i][j]; n       sum[i][j] = sum[i][j - 1] + a[i][j]; n     } n   } n   int mm = m - k + 1; n   for (int i = int(1); i < int(mm + 1); i++) n     dp[1][i] = n         sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1]; n   for (int i = int(2); i < int(n + 1); i++) { n     memset(t, 0, sizeof(t)); n     memset(lazy, 0, sizeof(lazy)); n     for (int j = int(1); j < int(mm + 1); j++) n       update(1, 1, mm, j, j, dp[i - 1][j]); n     for (int j = int(1); j < int(k + 1); j++) update(1, 1, mm, 1, j, -a[i][j]); n     for (int j = int(1); j < int(mm + 1); j++) { n       dp[i][j] = t[1] + sum[i][j + k - 1] - sum[i][j - 1] + n                  sum[i + 1][j + k - 1] - sum[i + 1][j - 1]; n       if (j != mm) { n         update(1, 1, mm, max(1, j - k + 1), j, a[i][j]); n         update(1, 1, mm, j + 1, j + k, -a[i][j + k]); n       } n     } n   } n   cout << *max_element(dp[n] + 1, dp[n] + mm + 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long v[200005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tc; n   cin >> tc; n   while (tc--) { n     long long n; n     cin >> n; n     for (long long int i = 0; i < n; i++) { n       cin >> v[i]; n     } n     long long i = n - 1, prev = 0; n     while (v[i] >= prev && i >= 0) { n       prev = v[i]; n       i--; n     } n     while (v[i] <= prev && i >= 0) { n       prev = v[i]; n       i--; n     } n     cout << i + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int n, m, c[N], s[N]; n bool cmp(int a, int b) { return a > b; } n int main() { n   int cnt = 0, p = 0, q = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &m); n     int tmp = m / 2; n     for (int j = 0; j < m; j++) { n       scanf( %d , &c[j]); n       if (j < tmp) n         p += c[j]; n       else n         q += c[j]; n     } n     if (m & 1) { n       q -= c[tmp]; n       s[cnt++] = c[tmp]; n     } n   } n   sort(s, s + cnt, cmp); n   for (int i = 0; i < cnt; i++) { n     if (i & 1) n       q += s[i]; n     else n       p += s[i]; n   } n   printf( %d %d n , p, q); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1200; n int n; n const double eps = 1e-9; n double c, t; n double dp[110][110][1110]; n double skill[110]; n pair<int, int> a[N]; n inline bool cmp(pair<int, int> a, pair<int, int> b) { n   return a.first > b.first; n } n inline long long get() { n   int ss = 0; n   for (int i = 1; i <= n; ++i) ss += a[i].second; n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= n; ++j) n       for (int b = 0; b <= ss; ++b) dp[i][j][b] = 1e9; n   double s = 1; n   skill[0] = s; n   dp[0][0][0] = 0; n   for (int k = 1; k <= n; ++k) skill[k] = skill[k - 1] * 0.9; n   for (int i = 1; i <= n; ++i) { n     for (int k = 0; k <= n; ++k) n       for (int b = 0; b <= ss; ++b) { n         dp[i][k][b] = min(dp[i][k][b], dp[i - 1][k][b]); n         if (k > 0 && b >= a[i].second) { n           double was = dp[i - 1][k - 1][b - a[i].second]; n           was += a[i].first / skill[k]; n           dp[i][k][b] = min(dp[i][k][b], was); n         } n       } n   } n   int ans = 0; n   for (int i = 0; i <= n; ++i) { n     if (i * 10 > t) continue; n     for (int b = 0; b <= ss; ++b) { n       double timer = dp[n][i][b]; n       if (timer + 10 * i - eps <= t) n         ans = max(ans, b); n       else { n         double l = 1, r = t * c + 1; n         for (int it = 1; it <= 100; ++it) { n           double m1 = l + (r - l) / 3.0; n           double m2 = r - (r - l) / 3.0; n           if (timer / m1 + (m1 - 1) / c <= timer / m2 + (m2 - 1) / c) n             r = m2; n           else n             l = m1; n         } n         double ti = timer / l + (l - 1) / c; n         if (ti - eps + i * 10 <= t) ans = max(ans, b); n       } n     } n   } n   return ans; n } n inline void solve() { n   cin >> n >> c >> t; n   for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second; n   sort(a + 1, a + n + 1, cmp); n   cout << get() <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int tc; n   cin >> tc; n   while (tc--) { n     solve(); n   } n   return 0; n } n