#include <bits/stdc++.h> n using namespace std; n struct vec { n   long long x, y; n }; n bool operator==(const vec& a, const vec& b) { n   return a.x == b.x and a.y == b.y; n } n bool operator!=(const vec& a, const vec& b) { return not(a == b); } n bool operator<(const vec& a, const vec& b) { n   return make_pair(a.x, a.y) < make_pair(b.x, b.y); n } n vec operator+(const vec& a, const vec& b) { n   return (vec){a.x + b.x, a.y + b.y}; n } n int main() { n   ios_base::sync_with_stdio(false); n   long long n, m; n   vec d; n   cin >> n >> m >> d.x >> d.y; n   vector<vec> apple(m); n   for (int i = 0; i < (m); ++i) cin >> apple[i].x >> apple[i].y; n   sort(apple.begin(), apple.end()); n   vector<int> x2y(n); n   { n     vec p = d; n     while (p != (vec){0, 0}) { n       x2y[p.x] = p.y; n       p = p + d; n       p.x %= n; n       p.y %= n; n     } n   } n   vector<int> bucket(n); n   { n     int i = 0; n     for (int x = 0; x < (n); ++x) { n       for (; i < m and apple[i].x <= x; ++i) { n         bucket[(apple[i].y - x2y[x] + n) % n] += 1; n       } n     } n   } n   { n     int ix; n     int sz = -1; n     for (int i = 0; i < (n); ++i) n       if (sz < bucket[i]) { n         sz = bucket[i]; n         ix = i; n       } n     cout << 0 <<     << ix << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const double pi = acos(-1.0), eps = 1e-9; n const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; n const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; n const int MO = (int)(1e9 + 7); n using namespace std; n struct Tcmp { n   bool operator()(const pair<int, int>& A, const pair<int, int>& B) { n     int lenA = A.second - A.first + 1, lenB = B.second - B.first + 1; n     lenA = lenA + 1 >> 1; n     lenB = lenB + 1 >> 1; n     if (lenA == lenB) n       return A.first < B.first; n     else n       return lenA > lenB; n   } n }; n set<int> s; n set<pair<int, int>, Tcmp> heap; n int n, m; n int where[2000001]; n int findnext(int t) { n   set<int>::iterator sit = s.upper_bound(t); n   if (sit == s.end()) return -1; n   return *sit; n } n int findpre(int t) { n   set<int>::iterator sit = s.lower_bound(t); n   if (sit == s.begin()) return -1; n   --sit; n   return *sit; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     if (i == 8) { n       int t = 1; n       ++t; n     } n     int kind, id; n     scanf( %d%d , &kind, &id); n     if (kind == 1) { n       pair<int, int> ans = make_pair(0, 0); n       if (s.size() == 0) { n         s.insert(1); n         puts( 1 ); n         where[id] = 1; n         continue; n       } n       if (s.count(1) == 0) { n         pair<int, int> temp = make_pair(-(findnext(1) - 1), 1); n         if (temp < ans) ans = temp; n       } n       if (s.count(n) == 0) { n         pair<int, int> temp = make_pair(-(n - findpre(n)), n); n         if (temp < ans) ans = temp; n       } n       if (heap.size()) { n         pair<int, int> now = *heap.begin(); n         pair<int, int> temp = make_pair(-(now.second - now.first + 2 >> 1), 0); n         temp.second = now.first - 1 - temp.first; n         if (temp < ans) { n           ans = temp; n           heap.erase(heap.begin()); n         } n       } n       s.insert(ans.second); n       int t = findpre(ans.second); n       if (t != -1 && t != ans.second - 1) n         heap.insert(make_pair(t + 1, ans.second - 1)); n       t = findnext(ans.second); n       if (t != -1 && t != ans.second + 1) n         heap.insert(make_pair(ans.second + 1, t - 1)); n       where[id] = ans.second; n       printf( %d n , ans.second); n     } else { n       s.erase(where[id]); n       int l = findpre(where[id]), r = findnext(where[id]); n       if (l != -1) heap.erase(make_pair(l + 1, where[id] - 1)); n       if (r != -1) heap.erase(make_pair(where[id] + 1, r - 1)); n       if (l != -1 && r != -1) heap.insert(make_pair(l + 1, r - 1)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct segtree { n   vector<long long> t; n   segtree(long long _n) { t.resize(4 * _n); } n   void update(long long id, long long l, long long r, long long pos, n               long long val) { n     if (l == r) { n       t[id] = val; n       return; n     } n     long long mid = (l + r) / 2; n     if (pos <= mid) { n       update(2 * id, l, mid, pos, val); n     } else { n       update(2 * id + 1, mid + 1, r, pos, val); n     } n     t[id] = t[2 * id] + t[2 * id + 1]; n   } n   long long query(long long id, long long l, long long r, long long lq, n                   long long rq) { n     if (lq > r || l > rq) return 0; n     if (lq <= l && r <= rq) return t[id]; n     long long mid = (l + r) / 2; n     long long L = query(2 * id, l, mid, lq, rq); n     long long R = query(2 * id + 1, mid + 1, r, lq, rq); n     return L + R; n   } n }; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long N; n   cin >> N; n   vector<long long> A(N); n   for (auto& a : A) cin >> a; n   segtree t1(N), t2(N); n   for (long long i = 0; i < N; i++) { n     if (i % 2) { n       t1.update(1, 0, N - 1, i, A[i]); n     } else { n       t2.update(1, 0, N - 1, i, A[i]); n     } n   } n   long long best = A[0]; n   for (long long i = 0; i + 1 < N; i++) { n     long long foo = A[i] + A[i + 1]; n     long long from = i + 3, to = N - 1; n     if (to >= from) { n       if (i % 2) { n         foo += t2.query(1, 0, N - 1, from, to); n       } else { n         foo += t1.query(1, 0, N - 1, from, to); n       } n     } n     from = 0; n     to = i - 2; n     if (to >= from) { n       long long z = to - from + 1; n       if (z % 2) { n         foo += t2.query(1, 0, N - 1, from, to); n       } else { n         foo += t1.query(1, 0, N - 1, from, to); n       } n     } n     best = max(best, foo); n   } n   long long foo = 0; n   if (N > 1) { n     foo = A[0] + A[N - 1]; n     for (long long i = 2; i <= N - 3; i += 2) foo += A[i]; n   } n   cout << max(best, foo) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long N, P; n long long L[100001]; n long long R[100001]; n long long getAc(long long l, long long r, long long p) { n   if ((l + p - 1) / p * p > r) return 0; n   return (r - (l + p - 1) / p * p) / p + 1; n } n int main() { n   scanf( %lld%lld , &N, &P); n   for (int i = 0; i < N; i++) scanf( %lld%lld , &L[i], &R[i]); n   double ans = 0; n   for (int i = 0; i < N; i++) { n     long long a = getAc(L[i], R[i], P); n     long long b = getAc(L[(i + 1) % N], R[(i + 1) % N], P); n     long long cur = (R[i] - L[i] + 1) * b; n     cur += (R[(i + 1) % N] - L[(i + 1) % N] + 1) * a; n     cur -= a * b; n     ans += (double)cur * 2000 / (R[i] - L[i] + 1) / n            (R[(i + 1) % N] - L[(i + 1) % N] + 1); n   } n   printf( %.8f , (double)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[200010], w[200010], f[3010][3010], g[3010][3010], inv[3010 * 2], n     sum[3]; n const int mod = 998244353; n int getInverse(int x, int y) { n   int ret = 1; n   while (y) { n     if (y & 1) ret = (long long)ret * x % mod; n     x = (long long)x * x % mod; n     y >>= 1; n   } n   return ret; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 1; i <= n; ++i) { n     cin >> w[i]; n     sum[a[i]] += w[i]; n     sum[2] += w[i]; n   } n   for (int i = max(0, m - sum[0]); i <= 2 * m; ++i) n     inv[i] = getInverse(sum[2] + i - m, mod - 2); n   for (int i = m; i >= 0; --i) { n     f[i][m - i] = g[i][m - i] = 1; n     for (int j = min(m - i - 1, sum[0]); j >= 0; --j) { n       f[i][j] = ((long long)(sum[1] + i + 1) * f[i + 1][j] + n                  (long long)(sum[0] - j) * f[i][j + 1]) % n                 mod * inv[i - j + m] % mod; n       g[i][j] = ((long long)(sum[1] + i) * g[i + 1][j] + n                  (long long)(sum[0] - j - 1) * g[i][j + 1]) % n                 mod * inv[i - j + m] % mod; n     } n   } n   for (int i = 1; i <= n; ++i) n     cout << ((long long)w[i] * (a[i] ? f[0][0] : g[0][0])) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a; n int main() { n   cin >> a; n   if (a == string(a.size(),  a )) { n     cout << string(a.size() - 1,  a ) <<  z  << endl; n   } else { n     for (int i = 0; i < a.size(); i++) { n       if (a[i] !=  a ) { n         int x = i; n         while (x < a.size() && a[x] !=  a ) { n           a[x++]--; n         } n         break; n       } n     } n     cout << a << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n int n, m; n long long minb[100010]; n long long maxg[100010]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     scanf( %lld , minb + i); n   } n   sort(minb, minb + n); n   for (int i = 0; i < m; i++) { n     scanf( %lld , maxg + i); n   } n   sort(maxg, maxg + m); n   long long ans = 0; n   if (minb[n - 1] > maxg[0]) { n     cout << -1 << endl; n     return 0; n   } n   if (m == 1) { n     if (minb[n - 1] != maxg[0]) { n       cout << -1 << endl; n       return 0; n     } else { n       for (int i = 0; i < n; i++) { n         ans += minb[i]; n       } n       cout << ans << endl; n       return 0; n     } n   } n   for (int i = 0; i < n - 1; i++) { n     ans += minb[i] * m; n   } n   for (int i = 1; i < m; i++) { n     ans += maxg[i]; n   } n   if (minb[n - 1] == maxg[0]) { n     ans += minb[n - 1]; n   } else { n     if (n == 1) { n       cout << -1 << endl; n       return 0; n     } else { n       ans += minb[n - 1] + maxg[0] - minb[n - 2]; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return !b ? a : gcd(b, a % b); n } n template <typename T> n T lcm(T a, T b) { n   return a * (b / gcd(a, b)); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n template <typename T> n T cube(T a) { n   return a * a * a; n } n template <typename T> n inline void smin(T &a, T b) { n   a = a < b ? a : b; n } n template <typename T> n inline void smax(T &a, T b) { n   a = a > b ? a : b; n } n template <typename T> n void fill(T a[], T n, T b) { n   for (int i = 0; i <= n; i++) a[i] = b; n } n int in() { n   int n; n   scanf( %d , &n); n   return n; n } n long long Lin() { n   long long n; n   scanf( %lld , &n); n   return n; n } n double Din() { n   double n; n   scanf( %lf , &n); n   return n; n } n const long long inf = (long long)1e17; n const long long mod = (long long)1e9 + 7; n const int N = 2e5 + 5; n int n, q, a[N]; n set<pair<int, pair<int, int> > > s; n int tree[4 * N], prop[4 * N]; n void propagate(int pos, int left, int right) { n   int mid = (left + right) >> 1; n   prop[pos] = 0; n   tree[pos * 2] = mid - left + 1; n   tree[pos * 2 + 1] = right - mid; n   prop[pos * 2] = 1; n   prop[pos * 2 + 1] = 1; n } n void update(int pos, int left, int right, int x, int y) { n   if (left > y || right < x) return; n   if (left >= x && right <= y) { n     tree[pos] = right - left + 1; n     prop[pos] = 1; n     return; n   } n   if (prop[pos] > 0) propagate(pos, left, right); n   int mid = (left + right) >> 1; n   update(pos * 2, left, mid, x, y); n   update(pos * 2 + 1, mid + 1, right, x, y); n   tree[pos] = tree[pos * 2] + tree[pos * 2 + 1]; n } n int query(int pos, int left, int right, int x, int y) { n   if (left > y || right < x) return 0; n   if (left >= x && right <= y) return tree[pos]; n   if (prop[pos] > 0) propagate(pos, left, right); n   int mid = (left + right) >> 1; n   int n = query(pos * 2, left, mid, x, y); n   int m = query(pos * 2 + 1, mid + 1, right, x, y); n   return m + n; n } n int root[N], Rank[N], lp[N], rp[N]; n void init(int n) { n   for (int i = 1; i <= n; i++) { n     root[i] = i, Rank[i] = 1, lp[i] = i, rp[i] = i; n   } n } n int Find(int u) { return root[u] == u ? u : root[u] = Find(root[u]); } n void Union(int u, int v) { n   u = Find(u), v = Find(v); n   if (u != v) { n     root[v] = u; n     Rank[u] += Rank[v]; n     rp[u] = rp[v]; n   } n } n int bs1(int l, int r) { n   int ans = -1; n   while (l <= r) { n     int m = (l + r) >> 1; n     if (query(1, 1, n, m, r) != (r - m + 1)) n       ans = m, l = m + 1; n     else n       r = m - 1; n   } n   return ans; n } n int bs2(int l, int r) { n   int ans = n + 1; n   while (l <= r) { n     int m = (l + r) >> 1; n     if (query(1, 1, n, l, m) != (m - l + 1)) n       ans = m, r = m - 1; n     else n       l = m + 1; n   } n   return ans; n } n int solve() { n   n = in(); n   for (int i = 1; i <= n; i++) { n     a[i] = in(); n   } n   init(n); n   int l = 1, cur = 1; n   for (int i = 2; i <= n; i++) { n     if (a[i] != a[i - 1]) { n       s.insert({-cur, {l, i - 1}}); n       cur = 1, l = i; n     } else { n       Union(i - 1, i); n       cur++; n     } n   } n   s.insert({-cur, {l, n}}); n   int ans = 0; n   while (!s.empty()) { n     auto it = s.begin(); n     int u = (*it).second.first, v = (*it).second.second; n     s.erase(it); n     if (query(1, 1, n, u, v) != (v - u + 1)) { n       ans++; n       update(1, 1, n, u, v); n       int x = bs1(1, u - 1); n       int y = bs2(u + 1, n); n       if (x >= 1 && y <= n && a[x] == a[y]) { n         Union(x, y); n         int par = Find(x); n         s.insert({-Rank[par], {lp[par], rp[par]}}); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n int main() { n   int test = 1, tc = 0; n   while (test--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 550; n struct DDF { n   int n; n   int v[maxn]; n   int dp[maxn][maxn]; n   int dfs(int l, int r) { n     if (l >= r) return dp[l][r] = 1; n     if (~dp[l][r]) return dp[l][r]; n     long long ans = dfs(l + 1, r); n     for (int i = l + 1; i <= r; i++) { n       if (v[l + 1] < v[i + 1]) { n         ans += 1LL * dfs(l + 1, i - 1) * (dfs(i, r)); n         ans %= mod; n       } n     } n     return dp[l][r] = ans; n   } n   void solve() { n     memset(dp, -1, sizeof dp); n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n     printf( %d n , dfs(1, n)); n   } n } solver; n int main() { n   solver.solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int ac = 1e6 + 5; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     cout << n <<   n ; n     string s; n     cin >> s; n     int p = 0; n     for (int i = 0; i < n / 2 - k + 1; i++) { n       int j = p; n       while (s[j] !=  ( ) j++; n       cout << p + 1 <<     << j + 1 <<   n ; n       reverse(s.begin() + p, s.begin() + j + 1); n       p++; n     } n     for (int i = 0; i < n / 2 - k + 1; i++) { n       int j = p; n       while (s[j] !=  ) ) j++; n       cout << p + 1 <<     << j + 1 <<   n ; n       reverse(s.begin() + p, s.begin() + j + 1); n       p++; n     } n     for (int i = 0; i < (k - 1) * 2; i++) { n       if (i % 2 == 0) { n         int j = p; n         while (s[j] !=  ( ) j++; n         cout << p + 1 <<     << j + 1 <<   n ; n         reverse(s.begin() + p, s.begin() + j + 1); n         p++; n       } else { n         int j = p; n         while (s[j] !=  ) ) j++; n         cout << p + 1 <<     << j + 1 <<   n ; n         reverse(s.begin() + p, s.begin() + j + 1); n         p++; n       } n     } n   } n } n


#include <bits/stdc++.h> n const int N = 50; n int i, j, tot, n; n bool left[N][N], down[N][N]; n int main() { n   long long T; n   scanf( %I64d , &T); n   for (i = 0; T; T /= 3, i++) { n     int x = T % 3; n     if (i) { n       tot += 2; n       down[i][i + 3] = left[i + 3][i] = 1; n       if (T >= 3) tot += 2, left[i][i + 4] = down[i + 4][i] = 1; n     } n     if (x < 2) tot++, left[i + 1][i + 3] = 1; n     if (x < 1) tot++, down[i + 3][i + 1] = 1; n   } n   left[i + 1][i + 2] = left[i + 2][i + 2] = 1; n   down[i + 2][i + 1] = down[i + 2][i + 2] = 1; n   n = i + 3; n   printf( %d %d n%d n , n, n, tot + 4); n   for (i = 1; i < n; i++) n     for (j = 1; j < n; j++) { n       if (left[i][j]) printf( %d %d %d %d n , i, j, i, j + 1); n       if (down[i][j]) printf( %d %d %d %d n , i, j, i + 1, j); n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n pair<int, int> a[N]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i + 1; n   sort(a + 1, a + n); n   int Sum1 = a[0].first; n   int Sum2 = 0; n   for (int i = 1; i < n; i++) Sum2 += a[i].first; n   vector<int> Ans({1}); n   for (int i = 1; i < n && Sum1 <= Sum2 && 2 * a[i].first <= a[0].first; i++) { n     Sum1 += a[i].first; n     Sum2 -= a[i].first; n     Ans.push_back(a[i].second); n   } n   if (Sum1 <= Sum2) return 0 * puts( 0 ); n   sort(Ans.begin(), Ans.end()); n   cout << Ans.size() << endl; n   for (int x : Ans) printf( %d  , x); n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 18; n const long long MOD = 1000000007; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1); n const double ERR = 1e-10; n int ans[100050]; n void aa1(int x) { n   if (x == 2) { n     ans[1] = 2; n     ans[2] = 1; n     return; n   } n   int i; n   for (i = 2; i <= 30; i++) n     if ((1 << i) > x + 2) break; n   int v = i - 1; n   if (x + 2 == (1 << v)) { n     for (int i = 1; i <= x; i++) ans[i] = x + 1 - i; n     return; n   } n   int nx; n   for (i = (1 << v); i <= x; i++) { n     int t = (1 << (v + 1)) - 1 - i; n     ans[i] = t; n     ans[t] = i; n     nx = t; n   } n   aa1(nx - 1); n } n void aa2(int N) { n   int v = 1; n   while (v * 2 <= N) v *= 2; n   int i; n   for (i = 2; i < v; i += 2) { n     ans[i] = i + 1; n     ans[i + 1] = i; n   } n   vector<int> Vu; n   for (i = v; i <= N; i++) Vu.push_back(i); n   if (Vu.back() % 2 == 0) swap(Vu[Vu.size() - 2], Vu.back()); n   ans[Vu.back()] = 1; n   ans[1] = Vu.back(); n   Vu.pop_back(); n   for (i = 0; i < Vu.size(); i++) ans[Vu[i]] = Vu[(i + 1) % Vu.size()]; n } n int main() { n   int N; n   scanf( %d , &N); n   if (N % 2 == 1) n     printf( NO n ); n   else { n     printf( YES n ); n     aa1(N); n     for (int i = 1; i <= N; i++) printf( %d  , ans[i]); n     printf(  n ); n   } n   if (N <= 5) n     printf( NO n ); n   else { n     int t = 1; n     while (t * 2 <= N) t *= 2; n     if (t == N) return !printf( NO n ); n     if (t + 1 == N) { n       ans[N - 1] = N; n       ans[N] = N - 1; n       aa2(N - 2); n     } else n       aa2(N); n     printf( YES n ); n     for (int i = 1; i <= N; i++) printf( %d  , ans[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[50100]; n int tmp[50100]; n int ans[50100]; n map<int, bool> vis; n int n; n bool Check(int mid) { n   vis.clear(); n   for (int i = 1; i <= n; ++i) { n     tmp[i] = arr[i]; n     while (tmp[i] > mid) tmp[i] >>= 1; n     if (tmp[i] == 0) return false; n     while (tmp[i] && vis[tmp[i]] == true) tmp[i] >>= 1; n     if (tmp[i] == 0) return false; n     vis[tmp[i]] = true; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &arr[i]); n   int l, r; n   l = 1, r = 2000000000; n   while (l < r) { n     int mid = l + ((r - l) >> 1); n     if (Check(mid)) { n       r = mid; n       for (int i = 1; i <= n; ++i) ans[i] = tmp[i]; n     } else n       l = mid + 1; n   } n   for (int i = 1; i <= n; ++i) { n     if (i == 1) n       printf( %d , ans[i]); n     else n       printf(  %d , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, x, y, i, j, l, pos1, pos2, A; n long long m, tmp1, tmp2, tmp3, ans; n struct node { n   int x, y; n } a[N]; n int cmp1(const node& a, const node& b) { return a.x > b.x; } n int cmp2(const node& a, const node& b) { return a.y < b.y; } n int main() { n   scanf( %d%d%d%d%I64d , &n, &A, &x, &y, &m); n   for (i = 1; i <= n; i++) scanf( %d , &a[i].x), a[i].y = i; n   sort(a + 1, a + n + 1, cmp1); n   for (tmp1 = 0, i = 1; i <= n && tmp1 + A - a[i].x <= m; i++) n     tmp1 += A - a[i].x; n   ans = 0; n   j = n, tmp1 = m - tmp1 - A + a[i].x; n   for (i--; i >= 0; i--) { n     tmp1 = tmp1 + A - a[i + 1].x; n     while (j > i + 1) { n       tmp2 = (long long)(n - j + 1) * (a[j - 1].x - a[j].x); n       if (tmp1 < tmp2) n         break; n       else n         tmp1 -= tmp2, j--; n     } n     if (i < j) n       tmp3 = min(tmp1 / (n - j + 1) + a[j].x, (long long)A); n     else n       tmp3 = A; n     tmp2 = (long long)i * x + tmp3 * y; n     if (tmp2 >= ans) ans = tmp2, pos1 = i, pos2 = j, l = tmp3; n   } n   for (i = 1; i <= pos1; i++) a[i].x = A; n   for (i = pos2; i <= n; i++) a[i].x = l; n   sort(a + 1, a + n + 1, cmp2); n   for (printf( %I64d n , ans), i = 1; i < n; i++) printf( %d  , a[i].x); n   return printf( %d n , a[n].x), 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[100001]; n string s; n long long dp2[100001]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   dp2[1] = 1; n   dp2[2] = 2; n   dp2[3] = 3; n   dp2[4] = 5; n   for (int i = 5; i <= 100000; i++) { n     dp2[i] = dp2[i - 1] + dp2[i - 2]; n     dp2[i] %= (1000000007); n   } n   long long res = 1; n   int cnt = 0, lastn = -1, lastu = -1; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  w  || s[i] ==  m ) { n       cout << 0 << endl; n       return 0; n     } n     if (s[i] ==  u ) { n       if (lastu == -1) { n         lastu = i; n       } n       if (lastn != -1) { n         res *= dp2[i - lastn]; n         res %= (1000000007); n         lastn = -1; n       } n     } else if (s[i] ==  n ) { n       if (lastn == -1) { n         lastn = i; n       } n       if (lastu != -1) { n         res *= dp2[i - lastu]; n         res %= (1000000007); n         lastu = -1; n       } n     } else { n       if (lastu != -1) { n         res *= dp2[i - lastu]; n         res %= (1000000007); n         lastu = -1; n       } else if (lastn != -1) { n         res *= dp2[i - lastn]; n         res %= (1000000007); n         lastn = -1; n       } n     } n   } n   if (lastu != -1) { n     res *= dp2[s.length() - lastu]; n     res %= (1000000007); n     lastu = -1; n   } else if (lastn != -1) { n     res *= dp2[s.length() - lastn]; n     res %= (1000000007); n     lastn = -1; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000100; n struct seg { n   seg *fe, *fd; n   int meio, l, r, xo; n   seg(int x, int y) { n     l = x, r = y; n     meio = (x + y) / 2; n     xo = 0; n     if (l == r) return; n     fe = new seg(x, meio); n     fd = new seg(meio + 1, y); n   } n   void up(int pos, int novo) { n     if (l == r) { n       xo = novo; n       return; n     } n     if (pos <= meio) n       fe->up(pos, novo); n     else n       fd->up(pos, novo); n     xo = (fe->xo ^ fd->xo); n   } n   int get(int a, int b) { n     if (l >= a && r <= b) return xo; n     if (l > b || r < a) return 0; n     return (fe->get(a, b) ^ fd->get(a, b)); n   } n }; n seg st(1, MAXN); n seg ss(1, MAXN); n struct query { n   int l, r, id; n }; n query q[MAXN]; n int resp[MAXN]; n int v[MAXN]; n bool comp1(query a, query b) { return a.r < b.r; } n int main() { n   int n; n   scanf( %d , &n); n   map<int, int> mapa; n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]), ss.up(i, v[i]); n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &q[i].l, &q[i].r); n     q[i].id = i; n   } n   sort(q + 1, q + m + 1, comp1); n   int p = 1; n   for (int i = 1; i <= n; i++) { n     int h = mapa[v[i]]; n     if (mapa[v[i]] != 0) st.up(h, 0); n     mapa[v[i]] = i; n     st.up(i, v[i]); n     while (p <= m && q[p].r <= i) { n       int r1 = ss.get(q[p].l, q[p].r); n       int r2 = st.get(q[p].l, q[p].r); n       resp[q[p].id] = (r1 ^ r2); n       p++; n     } n   } n   for (int i = 1; i <= m; i++) printf( %d n , resp[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n const double eps = 1e-8; n int n, T, cnt1, cnt2; n long double sum1; n double sum2; n struct water { n   int a, t; n } A[N], B[N], Tmp[N]; n bool cmp1(const water &a, const water &b) { return a.t < b.t; } n bool cmp2(const water &a, const water &b) { return a.t > b.t; } n int dcmp(long double x) { return (fabs(x) < eps) ? 0 : x < 0 ? -1 : 1; } n int main() { n   scanf( %d%d , &n, &T); n   for (int i = 1; i <= n; i++) scanf( %d , &Tmp[i].a); n   for (int i = 1; i <= n; i++) scanf( %d , &Tmp[i].t); n   for (int i = 1; i <= n; i++) { n     if (Tmp[i].t <= T) n       A[++cnt1] = Tmp[i]; n     else n       B[++cnt2] = Tmp[i]; n     sum1 += 1ll * Tmp[i].a * Tmp[i].t; n     sum2 += Tmp[i].a; n   } n   sort(A + 1, A + cnt1 + 1, cmp1); n   sort(B + 1, B + cnt2 + 1, cmp2); n   if (!dcmp(sum1 / sum2 - T)) printf( %.8lf , sum2), exit(0); n   int flag = 0; n   if (dcmp(sum1 / sum2 - T) < 0) { n     for (int i = 1; i <= cnt1; i++) { n       long double del = (sum1 - T * sum2) / (A[i].t - T); n       if (dcmp(del - A[i].a) <= 0) { n         sum1 -= del * A[i].t; n         sum2 -= del; n         flag = 1; n         break; n       } else n         sum1 -= 1ll * A[i].a * A[i].t, sum2 -= A[i].a; n     } n   } else { n     for (int i = 1; i <= cnt2; i++) { n       long double del = (sum1 - T * sum2) / (B[i].t - T); n       if (dcmp(del - B[i].a) <= 0) { n         sum1 -= del * B[i].t; n         sum2 -= del; n         flag = 1; n         break; n       } else n         sum1 -= 1ll * B[i].a * B[i].t, sum2 -= B[i].a; n     } n   } n   if (flag) n     printf( %.8lf n , sum2); n   else n     puts( 0.000000 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c *x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug &operator<<(const c &) { n     return *this; n   } n }; n void solve() { n   int n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   vector<int> res; n   for (int i = 0; i < a.length(); ++i) { n     if (a[i] != b[i]) { n       if (i > 0) res.push_back(i + 1); n       res.push_back(1); n       if (i > 0) res.push_back(i + 1); n     } n   } n   cout << (int)res.size() <<    ; n   for (long long i = 0; i < int((int)res.size()); i++) cout << res[i] <<    ; n   cout <<   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   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300005; n const int SIGMA_SIZE = 26; n int SZ = 0; n struct Node { n   int sz, ch[SIGMA_SIZE]; n   Node() { memset(ch, 0, sizeof(ch)); } n } nd[maxn << 1]; n int newNode() { n   ++SZ; n   memset(nd[SZ].ch, 0, sizeof(nd[SZ].ch)); n   return SZ; n } n void maintain(int u) { n   nd[u].sz = 1; n   for (int i = 0; i < SIGMA_SIZE; i++) n     if (nd[u].ch[i]) nd[u].sz += nd[nd[u].ch[i]].sz; n } n void merge(int &a, int b) { n   if (a == 0) { n     a = b; n   } else { n     for (int i = 0; i < SIGMA_SIZE; i++) { n       if (nd[b].ch[i]) merge(nd[a].ch[i], nd[b].ch[i]); n     } n   } n   maintain(a); n } n int N; n long long C[maxn]; n char S[maxn]; n vector<int> G[maxn]; n void init() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) { n     G[i].clear(); n     scanf( %lld , &C[i]); n   } n   scanf( %s , S + 1); n   int u, v; n   for (int i = 1; i < N; i++) { n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n } n int dfs(int u, int f) { n   int p = newNode(); n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i]; n     if (v == f) continue; n     merge(p, dfs(v, u)); n   } n   maintain(p); n   int r = newNode(); n   nd[r].ch[S[u] -  a ] = p; n   maintain(r); n   C[u] += nd[r].sz - 1; n   return r; n } n int main() { n   init(); n   dfs(1, 0); n   long long ans = 0, cnt; n   for (int i = 1; i <= N; i++) { n     if (C[i] > ans) { n       ans = C[i]; n       cnt = 0; n     } n     if (C[i] == ans) { n       cnt++; n     } n   } n   printf( %I64d n%I64d n , ans, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 998244353, inv2 = 499122177; n inline void XOR(int *a, int lim, int type) { n   for (register int mid = 1; mid < lim; mid <<= 1) { n     for (register int i = mid << 1, j = 0; j < lim; j += i) { n       for (register int k = 0; k < mid; k++) { n         a[j + k] += a[j + k + mid]; n         if (a[j + k] >= p) a[j + k] -= p; n         a[j + k + mid] = a[j + k] - a[j + k + mid] - a[j + k + mid]; n         if (a[j + k + mid] >= p) n           a[j + k + mid] -= p; n         else n           while (a[j + k + mid] < 0) a[j + k + mid] += p; n         if (type == -1) n           a[j + k] = 1ll * a[j + k] * inv2 % p, n                 a[j + k + mid] = 1ll * a[j + k + mid] * inv2 % p; n       } n     } n   } n } n int n, m, lim; n char s[25][2000086]; n int a[2000086], b[2000086]; n int ans = 0x3f3f3f3f; n int main() { n   scanf( %d%d , &n, &m), lim = 1 << n; n   for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   for (int i = 1; i <= m; i++) { n     int sum = 0; n     for (int j = 1, k = 1; j <= n; j++, k <<= 1) n       if (s[j][i] ==  1 ) sum += k; n     ++a[sum]; n   } n   for (int i = 1; i <= lim; i++) { n     for (int j = i; j; j >>= 1) n       if (j & 1) ++b[i]; n     b[i] = min(b[i], n - b[i]); n   } n   XOR(a, lim, 1), XOR(b, lim, 1); n   for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * b[i] % p; n   XOR(a, lim, -1); n   for (int i = 0; i < lim; i++) ans = min(ans, a[i]); n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int ans = (n / 2) + (n & 1); n   for (int i = ans; i <= n; ++i) { n     if (i % m == 0) { n       cout << i <<   n ; n       return 0; n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char ch = getchar(); n   int w = 1, c = 0; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) w = -1; n   for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); n   return w * c; n } n const int mod = 1e9 + 7, M = 1e6 + 10; n struct node { n   long long x, y, z; n   node(long long _ = 1, long long __ = 0, long long ___ = 0) { n     x = _; n     y = __; n     z = ___; n   } n } a[M]; n long long b[M]; n node operator+(node A, node B) { n   return node(A.x * B.x % mod, (A.y * B.x + B.y * A.x) % mod, n               (A.x * B.z + A.z * B.x + 2ll * A.y * B.y) % mod); n } n int n; n int main() { n   n = read(); n   for (int i = (1); i <= (n); ++i) { n     int x = read(); n     a[x] = a[x] + node(2, x, 1ll * x * x % mod); n   } n   for (int len = 1; len <= 100000; len *= 10) { n     for (int j = (999999); j >= (0); --j) { n       if ((j / len) % 10) { n         a[j - len] = a[j - len] + a[j]; n       } n     } n   } n   for (int i = (0); i <= (999999); ++i) b[i] = a[i].z; n   for (int len = 1; len <= 100000; len *= 10) { n     for (int j = (0); j <= (999999); ++j) { n       if ((j / len) % 10) { n         b[j - len] += mod - b[j]; n         b[j - len] %= mod; n       } n     } n   } n   long long ans = 0; n   for (int i = (0); i <= (999999); ++i) { n     ans ^= b[i] * i; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int m = 1000000007; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 0; i <= 25; i++) { n     for (int j = 0; j < n and k > 0; j++) { n       if (s[j] ==  a  + i) { n         k--; n         s[j] =  0 ; n       } n     } n   } n   for (auto &x : s) { n     if (x !=  0 ) { n       cout << x; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s, s1; n   cin >> s; n   int count = 0; n   sort(s.begin(), s.end()); n   for (int i = 0; i < s.length(); ++i) { n     if (s[i] ==  + ) count++; n   } n   std::vector<string> v(s.length()); n   for (int i = count; i < s.length(); ++i) { n     v[i] = s[i]; n   } n   if (count != 0) n     for (int i = count; i < v.size() - 1; ++i) { n       cout << v[i] <<  + ; n     } n   cout << v[v.size() - 1]; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n int ans0[1000001]; n int tail = 1; n int a[1001]; n int n, m; n int ans = 0; n int main() { n   int i, j, k; n   int id; n   int xx, yy; n   int temp; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       scanf( %d , &temp); n       if (i == j) { n         a[i] = temp; n         if (temp == 1) { n           ans = 1 - ans; n         } n       } n     } n   } n   scanf( %d , &m); n   for (i = 1; i <= m; i++) { n     scanf( %d , &id); n     if (id == 1 || id == 2) { n       scanf( %d , &temp); n       ans = 1 - ans; n       a[temp] = 1 - a[temp]; n     } else { n       ans0[tail] = ans; n       tail++; n     } n   } n   for (i = 1; i <= tail - 1; i++) { n     printf( %d , ans0[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool b[1000050]; n vector<int> v; n vector<int> v1; n int main() { n   int n; n   cin >> n; n   int u = sqrt(n); n   if (n == 1) { n     cout << 1; n     return 0; n   } n   for (int i = 2; i <= u; i++) { n     if (!b[i]) { n       for (int j = i * i; j <= n; j += i) b[j] = 1; n     } n   } n   for (int i = 2; i <= n; i++) n     if (!b[i]) { n       v.push_back(i); n     } n   v1.push_back(n); n   int j = 0; n   while (1) { n     while (n % v[j] != 0) j++; n     while (n % v[j] == 0) { n       n /= v[j]; n       v1.push_back(n); n     } n     if (j == v.size() - 1 || n == 1) break; n   } n   for (int i = 0; i < v1.size(); i++) cout << v1[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> lk; n void make(int num, int len) { n   if (len == 10) return; n   if (num != 0) lk.push_back(num); n   make(num * 10 + 4, len + 1); n   make(num * 10 + 7, len + 1); n } n double gao(int l1, int l2, int r1, int r2) { n   double l = max(l1, r1), r = min(l2, r2); n   return max(0.0, r - l + 1); n } n int main() { n   make(0, 0); n   sort(lk.begin(), lk.end()); n   int p1, p2, v1, v2, k; n   while (cin >> p1 >> p2 >> v1 >> v2 >> k) { n     int c1 = max(p1, v1), c2 = min(c2, v2); n     double tot = (p2 - p1 + 1.0) * (v2 - v1 + 1.0), sum = 0; n     int sz = lk.size(); n     for (int i = 0; i + k - 1 < sz; i++) { n       int l1, l2 = lk[i], r1 = lk[i + k - 1], r2; n       if (i == 0) n         l1 = 0; n       else n         l1 = lk[i - 1] + 1; n       if (i + k == sz) n         r2 = 1000000000; n       else n         r2 = lk[i + k] - 1; n       sum += gao(l1, l2, p1, p2) * gao(r1, r2, v1, v2); n       sum += gao(l1, l2, v1, v2) * gao(r1, r2, p1, p2); n       sum -= gao(c1, c2, max(l1, r1), min(l2, r2)); n     } n     printf( %.12f n , sum / tot); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pnt { n   int x, y; n   pnt(int x = 0, int y = 0) : x(x), y(y) {} n   bool operator<(const pnt &p) const { return x == p.x ? y < p.y : x < p.x; } n   bool operator==(const pnt &p) const { return x == p.x && y == p.y; } n }; n const int inf = 1e9; n int ans; n pnt p[4], rlt[4]; n void check(pnt *q) { n   sort(q, q + 4); n   while (1) { n     bool flag = 0; n     int cur = -1; n     for (int i = 0; i < 4; i++) { n       if (q[i].x != p[i].x && q[i].y != p[i].y) { n         flag = 1; n         break; n       } n       cur = max(cur, abs(p[i].x - q[i].x) + abs(p[i].y - q[i].y)); n     } n     if (!flag) { n       if (cur < ans) { n         ans = cur; n         for (int i = 0; i < 4; i++) rlt[i] = q[i]; n       } n     } n     if (!next_permutation(q, q + 4)) break; n   } n } n int dx[4] = {1, 0, -1, 0}; n int dy[4] = {0, 1, 0, -1}; n void solve() { n   for (int i = 0; i < 4; i++) cin >> p[i].x >> p[i].y; n   vector<pnt> u; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) { n       u.push_back(pnt(p[i].x, p[j].y)); n     } n   sort(u.begin(), u.end()); n   u.erase(unique(u.begin(), u.end()), u.end()); n   vector<int> a; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) { n       a.push_back(abs(p[i].x - p[j].x)); n       a.push_back(abs(p[i].y - p[j].y)); n     } n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n   vector<pnt> v; n   vector<int> dist; n   for (int i = 0; i < a.size(); i++) n     for (int j = i; j < a.size(); j++) { n       int d = a[j] - a[i]; n       dist.push_back(d >> 1); n       dist.push_back(d + 1 >> 1); n     } n   sort(dist.begin(), dist.end()); n   dist.erase(unique(dist.begin(), dist.end()), dist.end()); n   for (int k = 0; k < u.size(); k++) { n     for (int h = 0; h < 4; h++) { n       for (int r = 0; r < dist.size(); r++) n         v.push_back(pnt(u[k].x + dist[r] * dx[h], u[k].y + dist[r] * dy[h])); n     } n   } n   ans = inf; n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   for (int i = 0; i < v.size(); i++) { n     for (int j = 1; j < a.size(); j++) { n       pnt q0[4] = {pnt(v[i].x, v[i].y), pnt(v[i].x, v[i].y + a[j]), n                    pnt(v[i].x + a[j], v[i].y), n                    pnt(v[i].x + a[j], v[i].y + a[j])}; n       check(q0); n       pnt q1[4] = {pnt(v[i].x, v[i].y), pnt(v[i].x, v[i].y - a[j]), n                    pnt(v[i].x + a[j], v[i].y), n                    pnt(v[i].x + a[j], v[i].y - a[j])}; n       check(q1); n       pnt q2[4] = {pnt(v[i].x, v[i].y), pnt(v[i].x, v[i].y + a[j]), n                    pnt(v[i].x - a[j], v[i].y), n                    pnt(v[i].x - a[j], v[i].y + a[j])}; n       check(q2); n       pnt q3[4] = {pnt(v[i].x, v[i].y), pnt(v[i].x, v[i].y - a[j]), n                    pnt(v[i].x - a[j], v[i].y), n                    pnt(v[i].x - a[j], v[i].y - a[j])}; n       check(q3); n     } n   } n   if (ans == inf) { n     puts( -1 ); n   } else { n     printf( %d n , ans); n     for (int i = 0; i < 4; i++) printf( %d %d n , rlt[i].x, rlt[i].y); n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), n       cout.tie(0); n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (j != i) { n         for (int k = 0; k < n; k++) { n           if (k != j) { n             if (arr[i] + arr[j] == arr[k]) { n               cout << k + 1 <<     << j + 1 <<     << i + 1; n               return 0; n             } n           } n         } n       } n     } n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 2e5 + 10; n const int MOD = 1e9 + 7; n const int INF = 2e9; n using namespace std; n vector<int> a; n int f[N], d[N]; n int c, n; n int main() { n   ios::sync_with_stdio(false); n   cin >> c >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     a.push_back(x); n   } n   sort(a.begin(), a.end()); n   for (int i = 1; i <= N; i++) d[i] = -1; n   for (int i = 0; i < n; i++) n     if (d[a[i]] == -1) d[a[i]] = i; n   vector<int>::iterator it; n   for (int i = 1; i <= c; i++) { n     it = lower_bound(a.begin(), a.end(), i); n     if (*it == i) n       f[i] = it - a.begin(); n     else if (it > a.begin()) n       f[i] = it - a.begin() - 1; n     else n       f[i] = -1; n   } n   for (int i = 1; i < c; i++) { n     int tmp = c, prev = n + 1; n     bool ok = true; n     while (1) { n       int y = f[tmp]; n       if (y >= prev) y = prev - 1; n       if (y < 0) { n         cout << i; n         return 0; n       } n       if (y == -1) { n         cout << i; n         return 0; n       } else if (ok && a[y] <= i && i <= tmp) { n         tmp -= i; n         ok = false; n       } else { n         int x = a[y]; n         int pos = d[x]; n         int t1 = y - pos + 1; n         int t2 = tmp / x; n         if (t1 > t2) { n           tmp -= t2 * x; n           prev = y - t2 + 1; n         } else { n           tmp -= t1 * x; n           prev = pos; n         } n       } n       if (tmp == 0) break; n     } n   } n   cout <<  Greed is good ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n char A[N]; n char B[N]; n int buck[128]; n int ans[128]; n bool ok() { n   for (int i =  a ; i <=  z ; ++i) n     if (buck[i] > ans[i]) return false; n   return true; n } n int main() { n   scanf( %s , A); n   scanf( %s , B); n   int aa = strlen(A); n   int bb = strlen(B); n   for (int i = 0; i < bb; ++i) { n     buck[A[i]]++; n     ans[B[i]]++; n   } n   int cnt = 0; n   for (int i = bb - 1; i < aa; ++i) { n     if (ok()) cnt++; n     buck[A[i - bb + 1]]--; n     buck[A[i + 1]]++; n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2, left, line; n   cin >> line; n   bool first = true; n   for (int i = 0; i < line.size(); i++) { n     if (line[i] ==  | ) n       first = false; n     else if (first) n       s1 += line[i]; n     else n       s2 += line[i]; n   } n   cin >> left; n   int l1 = s1.size(); n   int l2 = s2.size(); n   int l3 = left.size(); n   int m = (l1 + l2 + l3) / 2; n   if ((l1 + l2 + l3) % 2 == 1 || l1 > m || l2 > m) n     cout <<  Impossible  << endl; n   else { n     cout << s1; n     int p = m - l1; n     for (int i = 0; i < p; i++) cout << left[i]; n     cout <<  | ; n     cout << s2; n     for (int i = p; i < l3; i++) cout << left[i]; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   char tmp[11]; n   deque<string> dq; n   set<string> st; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %s , &tmp); n     dq.push_front(tmp); n   } n   for (deque<string>::iterator i = dq.begin(); i != dq.end(); i++) { n     if (st.count(*i) == 0) { n       printf( %s n , (*i).c_str()); n       st.insert(*i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4010; n int n, a, b; n vector<pair<int, int>> ans; n deque<int> s[3]; n inline void print() { n   if (n == 1248) n     for (pair<int, int> p : ans) printf( %d %d n , p.first, p.second); n } n inline void move(int tp, int c) { n   if (!c) return; n   if (tp == 0 && c > a) print(), puts( NO ), exit(0); n   if (tp == 1 && c > b) print(), puts( NO ), exit(0); n   if (c > s[tp].size()) print(), puts( NO ), exit(0); n   if (c + s[tp + 1].size() > n) print(), puts( NO ), exit(0); n   ans.push_back(make_pair(tp + 1, c)); n   for (int i = c - 1; i >= 0; --i) s[tp + 1].push_front(s[tp][i]); n   for (int i = c - 1; i >= 0; --i) s[tp].pop_front(); n } n inline bool judge(int tp, int c) { n   if (tp == 0 && c > a) return false; n   if (tp == 1 && c > b) return false; n   return true; n } n int main() { n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 1, x; i <= n; ++i) scanf( %d , &x), s[0].push_back(x); n   while (s[2].size() != n) { n     if (!s[0].size() && !s[1].size()) print(), puts( NO ), exit(0); n     for (int i = 1; i < s[1].size(); ++i) n       if (s[1][i - 1] < s[1][i] - 1) print(), puts( NO ), exit(0); n     int flag = 0; n     for (int i = 0; i < s[0].size(); ++i) { n       if (s[0][i] == (n - s[2].size())) { n         for (int j = 0; j <= i; ++j) move(0, 1); n         flag = 1; n       } n       if (i < s[0].size() && s[0][i] + 1 < s[0][i + 1]) break; n     } n     if (flag) continue; n     for (int i = 0; i < s[1].size(); ++i) { n       if (s[1][i] == (n - s[2].size())) { n         move(1, i + 1); n         flag = 1; n       } n     } n     if (flag) continue; n     int l = 0, cnt = 1, r = s[0].size() - 1; n     vector<int> st; n     st.push_back(l); n     for (int i = 1; i < s[0].size(); ++i) { n       if (s[0][i - 1] + 1 < s[0][i]) { n         r = i - 1; n         break; n       } n       if (s[0][i] < s[0][i - 1]) ++cnt, st.push_back(i); n     } n     int mn = s[0][0], mx = s[0][0]; n     for (int i = l; i <= r; ++i) mn = min(mn, s[0][i]), mx = max(mx, s[0][i]); n     if (mx - mn + 1 > r - l + 1) n       move(0, r - l + 1); n     else { n       int mxlen = 0; n       for (int i = 0; i < st.size(); ++i) n         mxlen = max(mxlen, (i < st.size() - 1 ? st[i + 1] : r + 1) - st[i]); n       if (mxlen <= a && r - l + 1 <= b) { n         for (int i = 0; i < st.size(); ++i) n           move(0, (i < st.size() - 1 ? st[i + 1] : r + 1) - st[i]); n       } else { n         if (r - l + 1 > b) { n           if (cnt == 1) n             for (int i = 1; i <= r - l + 1; ++i) move(0, 1); n           else if (cnt > 2) n             move(0, r - l + 1); n           else { n             for (int i = l; i <= r; ++i) { n               if (judge(0, i - l + 1) && judge(0, r - i)) { n                 if (i == st[1] - 1) continue; n                 if (i != r) { n                   if (i < st[1] - 1 && n                       max(st[1] - i, r - l + 1 - (st[1] - i)) > b) n                     continue; n                   if (i >= st[1] && n                       max(i - st[1] + 1, r - l + 1 - (i - st[1] + 1)) > b) n                     continue; n                 } n                 if (i == r) { n                   if (mxlen > a) continue; n                 } n                 move(0, i - l + 1); n                 move(0, r - i); n                 flag = 1; n                 break; n               } n             } n             if (!flag) print(), puts( NO ), exit(0); n           } n         } else { n           if (cnt == 1) n             for (int i = 1; i <= r - l + 1; ++i) move(0, 1); n           else if (cnt > 2) n             print(), puts( NO ), exit(0); n           else { n             for (int i = l; i <= r; ++i) { n               if (judge(0, i - l + 1) && judge(0, r - i)) { n                 move(0, i - l + 1); n                 move(0, r - i); n                 flag = 1; n                 break; n               } n             } n             if (!flag) print(), puts( NO ), exit(0); n           } n         } n       } n     } n   } n   puts( YES ); n   printf( %d n , ans.size()); n   for (pair<int, int> p : ans) printf( %d %d n , p.first, p.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a, b, c, d, k; n   cin >> t; n   while (t--) { n     cin >> a >> b >> c >> d >> k; n     int pen = (a + c - 1) / c; n     int penc = (b + d - 1) / d; n     if (pen + penc <= k) n       cout << pen <<     << penc << endl; n     else n       cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 105; n int n, a[maxn], vis[maxn]; n int gcd(int a, int b) { n   while (b) { n     int c = a % b; n     a = b; n     b = c; n   } n   return a; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int flag = 0; n   vector<int> ans; n   for (int i = 1; i <= n; i++) { n     if (vis[i]) continue; n     int now = i; n     int cnt = 0; n     while (!vis[now]) { n       vis[now] = i; n       now = a[now]; n       cnt++; n     } n     if (now != i) return puts( -1 ), 0; n     if (cnt % 2 == 0) cnt /= 2; n     ans.push_back(cnt); n   } n   long long A = ans[0]; n   for (int i = 1; i < ans.size(); i++) A = A * ans[i] / gcd(A, ans[i]); n   cout << A << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n const int INF = 0x3f3f3f3f; n const double PI = acos(-1.0); n const double EPS = 1e-9; n inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; } n struct node { n   long long v; n   int id; n   int date; n   node(long long a = 0, int b = 0, int c = 0) { n     v = a; n     id = b; n     date = c; n   } n }; n bool cmp(node x, node y) { return x.v < y.v; } n int n, m, k; n long long s; n long long a[maxn]; n long long b[maxn]; n int t[maxn]; n long long c[maxn]; n int p1[maxn]; n int p2[maxn]; n vector<node> ans; n bool judge(int x) { n   ans.clear(); n   for (int i = 1; i <= m; i++) { n     if (t[i] == 1) { n       node xx = node((long long)(a[p1[x]] * c[i]), i, p1[x]); n       ans.push_back(xx); n     } else { n       node xx = node((long long)(b[p2[x]] * c[i]), i, p2[x]); n       ans.push_back(xx); n     } n   } n   sort(ans.begin(), ans.end(), cmp); n   long long sum = 0; n   for (int i = 0; i < k; i++) { n     sum += ans[i].v; n   } n   return sum <= s; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k >> s; n   p1[0] = 1; n   p2[0] = 1; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] < a[p1[i - 1]]) { n       p1[i] = i; n     } else n       p1[i] = p1[i - 1]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n     if (b[i] < b[p2[i - 1]]) n       p2[i] = i; n     else n       p2[i] = p2[i - 1]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> t[i] >> c[i]; n   } n   int l = 0; n   int r = n + 1; n   int mid; n   while (l + 1 < r) { n     mid = (l + r) >> 1; n     if (judge(mid)) { n       r = mid; n     } else n       l = mid; n   } n   if (r == n + 1) { n     cout << -1 <<   n ; n     return 0; n   } n   judge(r); n   int tt = 0; n   for (int i = 0; i < k; i++) { n     tt = max(tt, ans[i].date); n   } n   cout << tt <<   n ; n   for (int i = 0; i < k; i++) { n     cout << ans[i].id <<     << ans[i].date <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10, M = (1 << 18); n int n, a[N], fa[N], cnt; n long long ans; n pair<int, int> mx[M][2], cur[M]; n int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } n bool merge(int x, int y) { n   x = getfa(x), y = getfa(y); n   if (x == y) return 0; n   fa[x] = y; n   return 1; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]), fa[i] = i; n     ans -= a[i]; n   } n   cnt = n + 1; n   while (cnt > 1) { n     for (int i = 0; i <= M - 1; i++) n       for (int j = 0; j <= 1; j++) mx[i][j] = make_pair(-1, -1); n     for (int i = 0; i <= n; i++) { n       pair<int, int> t = make_pair(a[i], getfa(i)); n       if (mx[a[i]][0] < t) { n         if (mx[a[i]][0].second != t.second) mx[a[i]][1] = mx[a[i]][0]; n         mx[a[i]][0] = t; n       } else if (mx[a[i]][1] < t) { n         if (mx[a[i]][0].second != t.second) mx[a[i]][1] = t; n       } n     } n     for (int i = 0; i <= M - 1; i++) { n       for (int j = 0; j <= 18; j++) { n         if (i & (1 << j)) { n           for (int k = 0; k <= 1; k++) { n             if (mx[i][0] < mx[i ^ (1 << j)][k]) { n               if (mx[i][0].second != mx[i ^ (1 << j)][k].second) n                 mx[i][1] = mx[i][0]; n               mx[i][0] = mx[i ^ (1 << j)][k]; n             } else if (mx[i][1] < mx[i ^ (1 << j)][k]) { n               if (mx[i][0].second != mx[i ^ (1 << j)][k].second) n                 mx[i][1] = mx[i ^ (1 << j)][k]; n             } n           } n         } n       } n     } n     for (int i = 0; i <= n; i++) cur[i] = make_pair(-1, -1); n     for (int i = 0; i <= n; i++) { n       int f = getfa(i); n       int t = ((M - 1) ^ a[i]); n       if (mx[t][0].second != -1 && mx[t][0].second != f) { n         cur[f] = max(cur[f], make_pair(mx[t][0].first + a[i], mx[t][0].second)); n       } else if (mx[t][1].second != -1 && mx[t][1].second != f) { n         cur[f] = max(cur[f], make_pair(mx[t][1].first + a[i], mx[t][1].second)); n       } n     } n     for (int i = 0; i <= n; i++) { n       if (fa[i] == i && merge(i, cur[i].second)) { n         cnt--, ans += cur[i].first; n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int LG = 21; n const int N = 1000005; n const long long MOD = 1e9 + 7; n const long long INF = 1e9; n const long long INFLL = 1e18; n using namespace std; n int cx[4] = {-1, 0, 1, 0}; n int cy[4] = {0, -1, 0, 1}; n string Yes[2] = { No ,  Yes }; n string YES[2] = { NO ,  YES }; n long long inq(long long x, long long y) { n   if (!y) return 1 % MOD; n   long long l = inq(x, y / 2); n   if (y % 2) return l * l % MOD * x % MOD; n   return l * l % MOD; n } n long long rev(long long x) { return inq(x, MOD - 2); } n bool __precomputed_combinatorics = 0; n vector<long long> __fact, __ufact, __rev; n void __precompute_combinatorics() { n   __precomputed_combinatorics = 1; n   __fact.resize(N); n   __ufact.resize(N); n   __rev.resize(N); n   __rev[1] = 1; n   for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD; n   __fact[0] = 1, __ufact[0] = 1; n   for (int i = 1; i < N; i++) n     __fact[i] = __fact[i - 1] * i % MOD, n     __ufact[i] = __ufact[i - 1] * __rev[i] % MOD; n } n long long fact(int x) { n   if (!__precomputed_combinatorics) __precompute_combinatorics(); n   return __fact[x]; n } n long long cnk(int n, int k) { n   if (k < 0 || k > n) return 0; n   if (!__precomputed_combinatorics) __precompute_combinatorics(); n   return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD; n } n int Root(int x, vector<int> &root) { n   if (x == root[x]) return x; n   return root[x] = Root(root[x], root); n } n void Merge(int v, int u, vector<int> &root, vector<int> &sz) { n   v = Root(v, root), u = Root(u, root); n   if (v == u) return; n   if (sz[v] < sz[u]) { n     sz[u] += sz[v]; n     root[v] = u; n   } else { n     sz[v] += sz[u]; n     root[u] = v; n   } n } n int ok(int x, int n) { return 0 <= x && x < n; } n void bfs(int v, vector<int> &dist, vector<vector<int> > &graph) { n   fill((dist).begin(), (dist).end(), -1); n   dist[v] = 0; n   vector<int> q = {v}; n   for (int i = 0; i < q.size(); i++) { n     for (auto u : graph[q[i]]) { n       if (dist[u] == -1) { n         dist[u] = dist[q[i]] + 1; n         q.push_back(u); n       } n     } n   } n } n vector<int> z_func(string &s) { n   vector<int> z(s.size()); n   z[0] = s.size(); n   int L = 0, R = 0; n   for (int i = 1; i < s.size(); i++) { n     z[i] = max(0, min(z[i - L], R - i)); n     while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]]) z[i]++; n     if (i + z[i] > R) { n       R = i + z[i]; n       L = i; n     } n   } n   return z; n } n vector<int> p_func(string &s) { n   vector<int> p(s.size()); n   for (int i = 1; i < s.size(); i++) { n     int j = p[i - 1]; n     while (j > 0 && s[i] != s[j]) j = p[j - 1]; n     if (s[i] == s[j]) j++; n     p[i] = j; n   } n   return p; n } n vector<int> d1_func(string &s) { n   vector<int> d1(s.size()); n   int L = 0, R = -1; n   for (int i = 0; i < s.size(); i++) { n     int k = 0; n     if (i <= R) k = min(R - i + 1, d1[R - i + L]); n     while (i + k < s.size() && i - k >= 0 && s[i - k] == s[i + k]) k++; n     d1[i] = k--; n     if (i + k > R) { n       L = i - k; n       R = i + k; n     } n   } n   return d1; n } n vector<int> d2_func(string &s) { n   vector<int> d2(s.size()); n   int L = 0, R = -1; n   for (int i = 1; i < s.size(); i++) { n     int k = 0; n     if (i <= R) k = min(R - i + 1, d2[R - i + L + 1]); n     while (i + k < s.size() && i - k - 1 >= 0 && s[i - k - 1] == s[i + k]) k++; n     d2[i] = k--; n     if (i + k > R) { n       L = i - k - 1; n       R = i + k; n     } n   } n   return d2; n } n long long log10(long long x) { n   if (x < 10) return 1; n   return 1 + log10(x / 10); n } n long long ds(long long x) { n   if (x < 10) return x; n   return x % 10 + ds(x / 10); n } n double sqr(double x) { return x * x; } n bool in(int bit, int mask) { return (mask & (1 << bit)) > 0; } n void Del(vector<int> &v, int pos) { n   swap(v[pos], v[v.size() - 1]); n   v.pop_back(); n } n long long g(vector<long long> &p, int pos) { n   if (ok(pos, p.size())) return p[pos]; n   if (pos < 0 || p.size() == 0) return 0; n   return p.back(); n } n int g(vector<int> &p, int pos) { n   if (ok(pos, p.size())) return p[pos]; n   if (pos < 0 || p.size() == 0) return 0; n   return p.back(); n } n bool comp(pair<int, int> a, pair<int, int> b) { n   if (abs(a.first - a.second) == abs(b.first - b.second)) return a > b; n   return abs(a.first - a.second) > abs(b.first - b.second); n } n signed main() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   int s = max(1, k / 2); n   vector<int> a(n, 1); n   for (int i = 0; i < n; i++) { n     int k = 1; n     int x = i; n     while (0 <= x && x < n / s) { n       for (int j = x * s; j < x * s + s; j++) { n         if (a[j]) { n           cout <<  ?   << j + 1 << endl; n           string s; n           cin >> s; n           if (s ==  Y ) { n             a[j] = 0; n           } n         } n       } n       if (k % 2 == 1) n         x += k; n       else n         x -= k; n       k++; n     } n     cout <<  R  << endl; n   } n   cout <<  !   << accumulate((a).begin(), (a).end(), 0) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T sqr(T x) { n   return x * x; n } n const double EPS = 1e-6; n const int INF = 0x3fffffff; n const long long LINF = INF * 1ll * INF; n const double PI = acos(-1.0); n using namespace std; n bool vis[205][205]; n int main(void) { n   int a, b; n   cin >> a >> b; n   string s; n   cin >> s; n   int x = 0, y = 0; n   vis[100][100] = 1; n   for (int i = 0; s[i]; i++) { n     if (s[i] ==  R ) n       x++; n     else if (s[i] ==  L ) n       x--; n     else if (s[i] ==  D ) n       y--; n     else n       y++; n     vis[100 + x][100 + y] = true; n   } n   for (int i = 0; i <= 200; i++) n     for (int j = 0; j <= 200; j++) { n       if (vis[i][j]) { n         long long dx = i - 100, dy = j - 100; n         dx = a - dx, dy = b - dy; n         if (x == 0) { n           if (y == 0) { n             if (dx == dy && dx == 0) { n               cout <<  Yes  << endl; n               return 0; n             } n           } else if (dx == 0 && dy % y == 0 && 1ll * dy * y >= 0) { n             cout <<  Yes  << endl; n             return 0; n           } n         } else if (1ll * dx * y == 1ll * dy * x && dx % x == 0 && n                    1ll * dx * x >= 0) { n           cout <<  Yes  << endl; n           return 0; n         } n       } n     } n   cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, d, m, l, i, j, x; n   cin >> n >> d >> m >> l; n   for (i = 0; i < n - 1; i++) { n     if ((i * m + l) / d * d + d < (i + 1) * m) break; n   } n   cout << (i * m + l) / d * d + d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m >> k; n   vector<vector<int> > dp(1 << n, vector<int>(1 << n, 0)); n   vector<int> G[n]; n   int all = (1 << n) - 1; n   for (int i = 1; i <= m; ++i) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     G[u].emplace_back(v); n     G[v].emplace_back(u); n     dp[(1 << u) | (1 << v)][(1 << u) | (1 << v)]++; n   } n   for (int m1 = 0; m1 < (1 << n); m1++) { n     for (int m2 = 0; m2 < (1 << n); m2++) { n       if (!dp[m1][m2]) continue; n       for (int i = 0; i < n; i++) { n         if (!(m1 >> i & 1)) continue; n         for (auto v : G[i]) { n           if (m1 >> v & 1) continue; n           int m3 = (m2 | (1 << v)) & (all ^ (1 << i)); n           if (!((m3 >> v) ^ 1)) dp[m1 | (1 << v)][m3] += dp[m1][m2]; n         } n       } n     } n   } n   long long res = 0; n   for (int i = 0; i <= all; i++) { n     if (__builtin_popcount(i) == k) res += dp[all][i]; n   } n   cout << res <<   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   int n, m; n   cin >> n >> m; n   vector<int> cnt(n + 1, false), idx(n + 1), ans(m + 1), b(m + 1); n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     cnt[x]++; n     idx[x] = i; n   } n   for (int i = 1; i <= m; i++) { n     cin >> b[i]; n     if (!cnt[b[i]]) { n       cout <<  Impossible  << endl; n       return 0; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (cnt[b[i]] > 1) { n       cout <<  Ambiguity  << endl; n       return 0; n     } n     ans[i] = idx[b[i]]; n   } n   cout <<  Possible  << endl; n   for (int i = 1; i <= m; i++) cout << ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10] = {4, 8, 15, 16, 23, 42}; n int q[5]; n int main() { n   for (int i = 1; i <= 4; i++) { n     printf( ? %d %d n , i, i + 1); n     fflush(stdout); n     cin >> q[i]; n   } n   do { n     if (a[1] * a[0] == q[1] && a[2] * a[1] == q[2] && a[3] * a[2] == q[3] && n         a[4] * a[3] == q[4]) n       break; n   } while (next_permutation(a, a + 6)); n   printf( ! ); n   for (int i = 0; i < 6; i++) printf(  %d , a[i]); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int first[maxn]; n int n; n int main() { n   int num, i; n   while (scanf( %d , &n) != EOF) { n     memset(first, 0, sizeof(first)); n     for (i = 1; i <= n; i++) { n       scanf( %d , &num); n       if (i <= n / 2) { n         if (num - (i - 1) > 0) first[num - (i - 1)]++; n       } else { n         if (num - (n - i) > 0) first[num - (n - i)]++; n       } n     } n     int Max = 0; n     for (i = 1; i < maxn; i++) n       if (first[i] > Max) Max = first[i]; n     printf( %d n , n - Max); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long inf = 1000000000009; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long l{}, r{}, x{}, y{}, k{}, f{}; n   cin >> l >> r >> x >> y >> k; n   for (int i = x, sz = (int)y + 1; i < sz; i++) { n     if (l <= i * k && i * k <= r) { n       f = 1; n       break; n     } n   } n   (f) ? cout <<  YES  n              <<   n  n       : cout <<  NO  n              <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     cin >> a; n     for (int i = 0; i < a.length(); i += 2) cout << a[i]; n     cout << endl; n   } n   return 0; n } n


/* n python3 ../../CompetitionHelpers/run_codeforces.py --problem A --test 0 n g++ -ggdb -fsanitize=address -std=c++17 A.cpp && ./a.out <<<  1 n 4 n 0 3 5 6  n */ n  n #include <bits/stdc++.h> n using namespace std; n  n #define rep(i, a, b) for (int i = a; i < (b); i++) n #define trav(a, x) for (auto& a : x) n #define all(x) begin(x), end(x) n #define sz(x) (int)(x).size() n typedef long long ll; n typedef pair<int, int> pii; n typedef vector<int> vi; n  n string to_string(pii p) { return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ; } n template <typename A> n string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res +=    ; res += to_string(x); } return  [  + res +  ] ; } n string to_string(const string& s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string) s); } n  n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { cerr <<     << to_string(H); debug_out(T...); } n #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__) n  n template<typename T> n void output_vector(const vector<T> &v, int start = 0, int end = -1) { n     if (end < 0) end = int(v.size()); n     for (int i = start; i < end; i++) n         cout << v[i] << (i < end - 1 ?     :   n ); n } n  n int main() { n     cin.sync_with_stdio(0); cin.tie(0); n     cin.exceptions(cin.failbit); n  n     int T; cin >> T; while (T--) { n         ll n; cin >> n; n         vector<ll> Arr(n); rep(i, 0, n) cin >> Arr[i]; n  n         sort(all(Arr)); n  n         ll ans = Arr.back(); n         for (ll i = 1; i < n; i++) { n             ans -= (Arr[i] - Arr[i - 1]) * i * (n - i); n         } n  n         cout << ans <<   n ; n     } n }


#include <bits/stdc++.h> n using namespace std; n void ECHO(string _s) { n   cout << endl; n   (void)_s; n } n template <typename T, typename... Args> n void ECHO(string _s, T x, Args... args) { n   unsigned _i; n   string _s2 =   ; n   for (_i = 0; _i < _s.length(); ++_i) { n     if (_s[_i] ==  , ) break; n     if (_s[_i] !=    ) _s2 += _s[_i]; n   } n   if (_i == _s.length()) { n     --_i; n   } n   cout <<    (  << _s2 <<  ):  << x; n   ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...); n } n template <typename T0, typename T1> n inline ostream& operator<<(ostream& os, pair<T0, T1>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& v) { n   for (unsigned i = 0; i < v.size(); ++i) { n     cout << v[i] <<  _ ; n   } n   cout << endl; n   return os; n } n template <typename T> n inline T _min(T x1, T x2, T x3) { n   return min(x1, min(x2, x3)); n } n template <typename T> n inline T _min(T x1, T x2, T x3, T x4) { n   return min(min(x1, x2), min(x2, x3)); n } n inline long long _gcd(long long a, long long b) { n   while (b) b %= a ^= b ^= a ^= b; n   return a; n } n int main() { n   ios::sync_with_stdio(false); n   int q; n   cin >> q; n   while (q--) { n     long long n, n5, n3, n2, contador; n     cin >> n; n     contador = 0; n     n5 = (n % 5); n     while ((n5) == 0) { n       n = 4 * n; n       n = n / 5; n       n5 = (n % 5); n       contador = contador + 1; n     } n     n3 = (n % 3); n     while ((n3) == 0) { n       n = (2) * n; n       n = n / 3; n       n3 = (n % 3); n       contador = contador + 1; n     } n     n2 = (n % 2); n     while ((n2) == 0) { n       n = n / 2; n       n2 = (n % 2); n       contador = contador + 1; n     } n     if (n == 1) { n       cout << contador <<   n ; n     } else { n       cout << -1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T read(T& x) { n   x = 0; n   int f = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x = f ? -x : x; n } n int q, t, l, r, x, last; n map<int, int> fa; n map<int, int> val; n int Find(int x) { n   if (fa.find(x) == fa.end()) return fa[x] = x; n   if (fa[x] == x) return x; n   int root = Find(fa[x]); n   val[x] ^= val[fa[x]]; n   return fa[x] = root; n } n int main() { n   for (read(q); q--;) { n     read(t); n     if (t == 1) { n       read(l), read(r), read(x); n       l ^= last, r ^= last, x ^= last; n       if (l > r) swap(l, r); n       l--; n       int p = Find(l), q = Find(r); n       if (p ^ q) { n         if (p < q) swap(p, q); n         fa[p] = q; n         val[p] = val[l] ^ val[r] ^ x; n       } n     } else { n       read(l), read(r); n       l ^= last, r ^= last; n       if (l > r) swap(l, r); n       l--; n       int p = Find(l), q = Find(r); n       if (p == q) { n         printf( %d n , val[p] ^ val[l] ^ val[r]); n         last = val[p] ^ val[l] ^ val[r]; n       } else { n         puts( -1 ); n         last = 1; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1); n const int M = 3e5 + 10; n const int inf = 2e9 + 10; n const int mod = 1e9 + 7; n int n, stk[M], le[M], ri[M], f[M], cnt[M]; n char s[M], s1[M]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> s + 1; n   int num = 0, min = 0, id = 0; n   for (int i = 1; i <= n; ++i) { n     if (s[i] ==  ( ) n       ++num; n     else n       --num; n     if (num < min) { n       min = num; n       id = i; n     } n   } n   if (num) { n     cout <<  0 n1 1 n ; n     return 0; n   } n   for (int i = 1; i <= id; ++i) s1[n + i - id] = s[i]; n   for (int i = id + 1; i <= n; ++i) s1[i - id] = s[i]; n   int top = 0; n   num = 0; n   for (int i = 1; i <= n; ++i) { n     if (s1[i] ==  ( ) { n       stk[++top] = ++num; n       le[num] = i; n     } else { n       int t1 = stk[top]; n       ri[t1] = i; n       f[t1] = stk[--top]; n       ++cnt[stk[top]]; n     } n   } n   int ans = cnt[0], lans = 1, rans = 1; n   for (int i = 1; i <= num; ++i) { n     if (cnt[i] + 1 > ans && !f[i]) { n       ans = cnt[i] + 1; n       lans = le[i]; n       rans = ri[i]; n     } n     if (cnt[i] + 1 + cnt[0] > ans && f[i] && !f[f[i]]) { n       ans = cnt[i] + 1 + cnt[0]; n       lans = le[i]; n       rans = ri[i]; n     } n   } n   lans = (lans + id - 1) % n + 1; n   rans = (rans + id - 1) % n + 1; n   cout << ans <<   n  << lans <<     << rans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 2e5 + 6; n const long long inf = 1e15; n long long ex, ey, ez, bx, by, bz, a[7]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   if (fopen( inp.txt ,  r )) { n     freopen( inp.txt ,  r , stdin); n     freopen( outp.txt ,  w , stdout); n   } n   cin >> ex >> ey >> ez; n   cin >> bx >> by >> bz; n   long long i, ans = 0; n   for (i = 1; i <= 7; i++) cin >> a[i]; n   if (ex > bx) n     ans += a[6]; n   else if (ex < 0) n     ans += a[5]; n   if (ey > by) n     ans += a[2]; n   else if (ey < 0) n     ans += a[1]; n   if (ez > bz) n     ans += a[4]; n   else if (ez < 0) n     ans += a[3]; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2055, mod = (int)1e9 + 7; n template <class o> n void qr(o &x) { n   char c = getchar(); n   x = 0; n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n } n int n, m, L, last[N], ys[N], tot, vis[N], col[N]; n struct P { n   int x, y, c, i; n } a[N]; n bool cmpx(P a, P b) { return a.x < b.x; } n bool cmpy(P a, P b) { return a.y < b.y; } n struct Q { n   int l[N], r[N]; n   void del(int x) { n     l[r[x]] = l[x]; n     r[l[x]] = r[x]; n   } n } q, nq; n struct node { n   int mn, mx, s, tag; n   node(int a = 0, int b = 0, int c = 0, int d = 0) { n     mn = a; n     mx = b; n     s = c; n     tag = d; n   } n   node operator+(node b) const { n     return node(min(mn, b.mn), max(mx, b.mx), (s + b.s) % mod, 0); n   } n } tr[N * 2]; n int f[N]; n void bt(int x, int l, int r) { n   if (l == r) { n     tr[x] = node(f[l], f[l], 1LL * (ys[r] - ys[l - 1]) * f[l] % mod, 0); n     return; n   } n   int mid = (l + r) / 2; n   bt((x << 1), l, mid); n   bt((x << 1 | 1), mid + 1, r); n   tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)]; n } n void upd(int x, int l, int r, long long t) { n   tr[x] = node(t, t, t * (ys[r] - ys[l - 1]) % mod, t); n } n void change(int x, int l, int r, int L, long long t) { n   if (tr[x].mn >= t) return; n   if (tr[x].mx <= t && l == L) { n     upd(x, l, r, t); n     return; n   } n   int mid = (l + r) / 2; n   if (tr[x].tag) { n     upd((x << 1), l, mid, tr[x].tag); n     upd((x << 1 | 1), mid + 1, r, tr[x].tag); n     tr[x].tag = 0; n   } n   if (L <= mid) change((x << 1), l, mid, L, t); n   change((x << 1 | 1), mid + 1, r, max(mid + 1, L), t); n   tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)]; n } n int main() { n   qr(n); n   qr(m); n   qr(L); n   for (int i = 1; i <= n; i++) qr(a[i].x), qr(a[i].y), qr(a[i].c); n   sort(a + 1, a + n + 1, cmpy); n   a[0].x = a[0].y = -1; n   a[n + 1].x = a[n + 1].y = L; n   for (int i = 0; i <= n + 1; i++) ys[i] = a[i].y, a[i].i = i; n   for (int i = 1; i <= n; i++) { n     int l = nq.l[i] = last[a[i].c]; n     last[a[i].c] = i; n     nq.r[i] = n + 1; n     nq.r[l] = i; n   } n   sort(a + 1, a + n + 1, cmpx); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i].x ^ a[i - 1].x) { n       q = nq; n       for (int j = 1; j < i; j++) col[a[j].i] = 0; n       for (int j = i; j <= n; j++) col[a[j].i] = a[j].c; n       for (int l = 1, r = 1; l <= n; l++) { n         for (; r <= n && tot < m; r++) n           if (col[r] && !vis[col[r]]++) tot++; n         f[l] = (tot < m) ? L : ys[r - 1]; n         if (col[l] && !--vis[col[l]]) tot--; n       } n       bt(1, 1, n); n       for (int j = n; j >= i; j--) { n         ans += (1LL * (ys[n] + 1) * L - tr[1].s) % mod * (a[i].x - a[i - 1].x) % n                mod * (a[j + 1].x - a[j].x) % mod; n         int id = a[j].i, L = q.l[id], R = q.r[id]; n         change(1, 1, n, L + 1, ys[R]); n         q.del(id); n       } n       ans %= mod; n     } n     nq.del(a[i].i); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 10; n int arr[MAX]; n int n; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   set<array<int, 4> > vis; n   pair<int, int> p; n   for (int tc = 1; tc <= t; ++tc) { n     vis.clear(); n     cin >> s; n     array<int, 4> a; n     int ans = 0; n     int x = 0, y = 0; n     for (int i = 0; i < s.size(); ++i) { n       a[0] = x; n       a[1] = y; n       if (s[i] ==  N ) y++; n       if (s[i] ==  S ) y--; n       if (s[i] ==  E ) x++; n       if (s[i] ==  W ) x--; n       a[2] = x; n       a[3] = y; n       if (vis.count(a)) n         ans++; n       else n         ans += 5; n       vis.insert(a); n       swap(a[0], a[2]); n       swap(a[1], a[3]); n       vis.insert(a); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a1, b1, c1, ma = 0, maa = 0, x1, y1; n     cin >> a1 >> b1 >> c1; n     for (int i = 0; i < b1; i++) { n       cin >> x1; n       ma = max(x1, ma); n     } n     for (int i = 0; i < c1; i++) { n       cin >> y1; n       maa = max(y1, maa); n     } n     if (ma > maa) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1}; n int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1}; n int t; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> vec; n     for (int i = 0; i < n; i++) { n       int a; n       cin >> a; n       vec.push_back(a); n     } n     bool at = false; n     for (int i = 0; i < int(vec.size()); i++) { n       for (int j = i + 2; j < int(vec.size()); j++) { n         if (vec[j] == vec[i]) at = true; n       } n     } n     if (!at) n       cout <<  NO  n            <<   n ; n     else n       cout <<  YES  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void processTest(int n, int64_t m, int64_t k) { n   vector<int64_t> path(n); n   int64_t bag = m; n   for (auto &v : path) { n     cin >> v; n   } n   for (int i = 1; i < path.size(); ++i) { n     auto toEq = max(path[i] - k, int64_t(0)); n     bag += path[i - 1] - toEq; n     if (bag < 0) { n       cout <<  NO  << endl; n       return; n     } n   } n   cout <<  YES  << endl; n } n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) { n     int64_t n, m, k; n     cin >> n >> m >> k; n     processTest(n, m, k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long s = 0, w = 1; n   char ch = getchar(); n   while (ch < 48 || ch > 57) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch >= 48 && ch <= 57) n     s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); n   return s * w; n } n const long long N = 1e5 + 5, P = 1e9 + 7; n struct ChthollyTree { n   map<long long, long long> s; n   inline long long find(long long p) { return s.lower_bound(p)->second; } n   inline void split(long long p) { n     long long pos = find(p); n     s[p] = pos; n   } n   inline pair<map<long long, long long>::iterator, n               map<long long, long long>::iterator> n   range(long long l, long long r) { n     split(l - 1), split(r); n     return make_pair(s.find(l - 1), s.find(r)); n   } n } T; n long long n, m, seed, vmax, a[N], sum[N], len; n struct Node { n   long long val, cnt; n } A[N]; n inline bool cmp(Node x, Node y) { return x.val < y.val; } n inline long long rnd() { n   long long res = seed; n   seed = (seed * 7ll + 13ll) % P; n   return res; n } n inline long long qpow(long long x, long long y, long long p) { n   long long ans = 1, res = x % p; n   while (y) { n     if (y & 1) ans = (ans * res) % p; n     y >>= 1; n     res = (res * res) % p; n   } n   return ans % p; n } n signed main() { n   n = read(), m = read(), seed = read(), vmax = read(); n   for (register long long i = 1; i <= n; ++i) { n     a[i] = (rnd() % vmax) + 1; n     T.s[i] = a[i]; n   } n   while (m--) { n     long long op = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1, x, n               y; n     if (l > r) swap(l, r); n     if (op == 3) n       x = (rnd() % (r - l + 1)) + 1; n     else n       x = (rnd() % vmax) + 1; n     if (op == 4) y = (rnd() % vmax) + 1; n     map<long long, long long>::iterator st, ed; n     if (op == 1) { n       pair<map<long long, long long>::iterator, n            map<long long, long long>::iterator> n           border = T.range(l, r); n       st = border.first, ed = border.second; n       while (st != ed) ed->second += x, ed--; n     } else if (op == 2) { n       pair<map<long long, long long>::iterator, n            map<long long, long long>::iterator> n           border = T.range(l, r); n       st = border.first, ed = border.second; n       while (st != ed) T.s.erase(ed--); n       T.s[r] = x; n     } else if (op == 3) { n       long long nxt; n       len = 0; n       for (register long long i = l; i <= r; i = nxt + 1) { n         map<long long, long long>::iterator now = T.s.lower_bound(i); n         nxt = min(r, now->first); n         A[++len] = (Node){now->second, nxt - i + 1}; n       } n       sort(A + 1, A + len + 1, cmp); n       for (register long long i = 1; i <= len; ++i) n         sum[i] = sum[i - 1] + A[i].cnt; n       long long L = 1, R = len, res = -1; n       while (L <= R) { n         long long mid = (L + R) >> 1; n         if (sum[mid] >= x) n           res = mid, R = mid - 1; n         else n           L = mid + 1; n       } n       printf( %lld n , A[res].val); n     } else { n       long long Ans = 0; n       long long nxt; n       for (register long long i = l; i <= r; i = nxt + 1) { n         map<long long, long long>::iterator now = T.s.lower_bound(i); n         nxt = min(r, now->first); n         Ans = (Ans + qpow(now->second, x, y) * (nxt - i + 1) % y) % y; n       } n       printf( %lld n , Ans % y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[25]; n char times[6] = {4, 5, 6, 3, 2, 1}; n int main() { n   scanf( %s , str); n   int len = strlen(str); n   char seat = str[len - 1]; n   long long rows = 0; n   for (int i = 0; i < len - 1; i++) { n     rows = rows * 10; n     rows += str[i] -  0 ; n   } n   long long sec; n   if (rows % 4 != 0) n     sec = rows / 4 * 16; n   else n     sec = (rows - 1) / 4 * 16; n   int tmp = rows % 4; n   if (!tmp) tmp = 4; n   if (tmp > 2) tmp -= 2; n   sec += (tmp - 1) * 7; n   sec += times[seat -  a ]; n   printf( %I64d n , sec); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(int n, int m, vector<int> a) { n   for (int i = int(0); i < int(m); i++) a[i] = min(a[i], n / 2); n   int sum = accumulate((a).begin(), (a).end(), 0); n   if (sum < n) { n     cout << -1 << endl; n     return; n   } n   vector<pair<int, int> > b(m); n   for (int i = int(0); i < int(m); i++) b[i] = make_pair(a[i], i); n   sort((b).begin(), (b).end(), greater<pair<int, int> >()); n   vector<int> res(n); n   for (int i = int(0); i < int(n); i++) { n     int j = -1; n     if (i == 0) n       j = 0; n     else if (i == n - 1) { n       for (int k = int(0); k < int(m); k++) n         if (b[k].second != res[i - 1] && b[k].second != res[0] && n             (j == -1 || b[k].first > b[j].first)) n           j = k; n     } else { n       for (int k = int(0); k < int(m); k++) n         if (b[k].second != res[i - 1] && (j == -1 || b[k].first > b[j].first)) n           j = k; n     } n     res[i] = b[j].second; n     b[j].first--; n   } n   for (int i = int(0); i < int(n); i++) n     cout << res[i] + 1 << (i == n - 1 ?   n  :    ); n } n int main() { n   for (int n, m; cin >> n >> m, n | m;) { n     vector<int> a(m); n     for (int i = int(0); i < int(m); i++) cin >> a[i]; n     solve(n, m, a); n     break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string decToBin(int n) { n   string toret; n   while (n) { n     toret += char((n % 2) +  0 ); n     n /= 2; n   } n   while (toret.size() != 8) toret +=  0 ; n   return toret; n } n int binToDec(string res) { n   int t = 0; n   int pow = 1; n   for (int i = res.size() - 1; i >= 0; i--) { n     t += (res[i] -  0 ) * pow; n     pow *= 2; n   } n   return t; n } n int main() { n   string in; n   getline(cin, in); n   int tmp = 0; n   for (int i = 0; i < in.size(); i++) { n     int code = (int)in[i]; n     string p = decToBin(code); n     int t = binToDec(p); n     int m = tmp - t; n     while (m < 0) m += 256; n     tmp = t; n     cout << m % 256 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void BFS(map<int, int> &m1, int t) { n   queue<pair<int, int>> q1; n   set<int> set_help; n   set<int>::iterator p; n   q1.push(make_pair(t, 0)); n   m1[t] = 0; n   set_help.insert(t); n   int Value, step; n   while (q1.empty() == 0) { n     Value = q1.front().first; n     step = q1.front().second; n     if (Value % 2 == 0) { n       p = set_help.find(Value / 2); n       if (p == set_help.end()) { n         m1[Value / 2] = step + 1; n         q1.push(make_pair(Value / 2, step + 1)); n         set_help.insert(Value / 2); n       } n     } n     if (Value % 3 == 0) { n       p = set_help.find(Value / 3); n       if (p == set_help.end()) { n         m1[Value / 3] = step + 1; n         q1.push(make_pair(Value / 3, step + 1)); n         set_help.insert(Value / 3); n       } n     } n     if (Value % 5 == 0) { n       p = set_help.find(Value / 5); n       if (p == set_help.end()) { n         m1[Value / 5] = step + 1; n         q1.push(make_pair(Value / 5, step + 1)); n         set_help.insert(Value / 5); n       } n     } n     q1.pop(); n   } n } n int main() { n   int a, b; n   ifstream ff( file.txt ); n   cin >> a >> b; n   if (a == b) { n     cout << 0 << endl; n     return 0; n   } n   map<int, int> ma, mb; n   BFS(ma, a); n   BFS(mb, b); n   map<int, int>::iterator p = ma.begin(), p1; n   int Stap_Min = INT_MAX, Step; n   for (p; p != ma.end(); p++) { n     p1 = mb.find(p->first); n     if (p1 != mb.end()) { n       Step = p->second + p1->second; n       if (Step < Stap_Min) { n         Stap_Min = Step; n       } n     } n   } n   if (Stap_Min == INT_MAX) { n     cout << -1 << endl; n   } else { n     cout << Stap_Min << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int func(int a) { n   int cnt = 0; n   while (a) { n     cnt++; n     a /= 10; n   } n   return cnt; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   vector<long long> v(n); n   map<int, int> m[11]; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n     long long c = 10; n     for (int j = 1; j <= 10; j++) { n       m[j][((v[i] % k) * (c % k)) % k]++; n       c *= 10; n     } n   } n   for (int i = 0; i < n; i++) { n     int a = (k - v[i] % k) % k; n     int b = func(v[i]); n     ans += m[b][a]; n     long long c = 1; n     for (int j = 0; j < b; j++) { n       c *= 10; n     } n     ans -= a == (v[i] % k * c % k) % k; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int p[300]; n int main() { n   int i, k, j, l; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (i = 0; i < 2 * n; i++) { n     cin >> p[i]; n   } n   n *= 2; n   int result = 200000000; n   for (i = 0; i < n; i++) { n     for (j = i + 1; j < n; j++) { n       vector<int> V; n       for (k = 0; k < n; k++) { n         if (k != i && k != j) { n           V.push_back(p[k]); n         } n       } n       sort(V.begin(), V.end()); n       int sum = 0; n       for (l = 0; l < V.size(); l = l + 2) { n         sum += (V[l + 1] - V[l]); n       } n       result = min(result, sum); n     } n   } n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x, y, z; n   scanf( %d %d %d , &x, &y, &z); n   if (x > y + z) { n     printf( + n ); n   } else if (y > x + z) { n     printf( - n ); n   } else if (x == y && z == 0) { n     printf( 0 n ); n   } else { n     printf( ? n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, cnt; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   if (4 * n * m - 2 * n - 2 * m < k) { n     puts( NO ); n     return 0; n   } n   puts( YES ); n   if (m == 1) { n     if (k <= n - 1) { n       puts( 1 ); n       printf( %d D n , k); n     } else { n       puts( 2 ); n       printf( %d D n , n - 1); n       printf( %d U n , k - n + 1); n     } n     return 0; n   } n   int kk = k, x = 1; n   while (k && x < n) { n     cnt++; n     if (k <= 3 * (m - 1)) { n       if (k % 3 && k > 3) cnt++; n       break; n     } n     k -= 3 * (m - 1); n     cnt++; n     if (k <= m - 1) break; n     k -= m - 1; n     cnt++; n     if (k <= 1) break; n     k--; n     x++; n   } n   if (k && x == n) { n     cnt++; n     if (k > m - 1) cnt++; n     if (k > 2 * (m - 1)) cnt++; n   } n   printf( %d n , cnt); n   k = kk, x = 1; n   while (k && x < n) { n     if (k <= 3 * (m - 1)) { n       if (k >= 3) printf( %d RDU n , k / 3); n       if (k % 3 >= 1) printf( 1 R ); n       if (k % 3 >= 2) printf( D ); n       puts(  ); n       break; n     } n     printf( %d RDU n , m - 1); n     k -= 3 * (m - 1); n     if (k <= m - 1) { n       printf( %d L n , k); n       break; n     } n     printf( %d L n , m - 1); n     k -= m - 1; n     if (k <= 1) { n       printf( 1 D n ); n       break; n     } n     printf( 1 D n ); n     k--; n     x++; n   } n   if (k && x == n) { n     if (k <= m - 1) n       printf( %d R n , k); n     else { n       printf( %d R n , m - 1); n       k -= m - 1; n       if (k <= m - 1) n         printf( %d L n , k); n       else { n         printf( %d L n , m - 1); n         k -= m - 1; n         printf( %d U n , k); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ar[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; n int main() { n   int n, a, sum = 1; n   cin >> n; n   for (int i = 0; i < 2; i++) { n     a = n % 10; n     sum *= ar[a]; n     n /= 10; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.setf(ios::fixed); n   cout.precision(0); n   long long n; n   cin >> n; n   string s; n   char y =  a ; n   while (n != 0) { n     s.push_back(y); n     int t = 1; n     while (t <= n) { n       s.push_back(y); n       n -= t; n       t++; n     } n     y++; n   } n   if (s.size() == 0) s.push_back( a ); n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; } n inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; } n char s[500100], t[500100]; n int n, m, wt, p[500100], sta[500100], pre[500100], nex[500100], top; n int main() { n   scanf( %d%d%d , &n, &m, &wt); n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   for (int i = 1; i <= n; ++i) { n     if (s[i] ==  ( ) n       sta[++top] = i; n     else { n       p[i] = sta[top]; n       p[sta[top--]] = i; n     } n     pre[i] = i - 1; n     nex[i] = i + 1; n   } n   nex[0] = 1; n   pre[n + 1] = n; n   for (int i = 1; i <= m; ++i) { n     if (t[i] ==  L ) n       wt = pre[wt]; n     else if (t[i] ==  R ) n       wt = nex[wt]; n     else { n       int ww = p[wt]; n       if (ww > wt) swap(ww, wt); n       nex[pre[ww]] = nex[wt]; n       pre[nex[wt]] = pre[ww]; n       if (nex[wt] <= n) n         wt = nex[wt]; n       else n         wt = pre[ww]; n     } n   } n   int w = nex[0]; n   while (w <= n) { n     printf( %c , s[w]); n     w = nex[w]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     map<int, int> mp; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       mp[a[i]]++; n     } n     int mx = 0, p = 0; n     for (auto it = mp.begin(); it != mp.end(); it++) { n       mx = max(mx, it->second); n       p++; n     } n     cout << max(min(mx, p - 1), min(mx - 1, p)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   deque<int> dq; n   map<int, int> freq; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     if (freq[x] == 0) { n       if ((int)dq.size() < k) n         dq.push_front(x); n       else { n         dq.push_front(x); n         freq[dq.back()] = 0; n         dq.pop_back(); n       } n       freq[x] = 1; n     } n   } n   cout << (int)dq.size() <<   n ; n   for (auto i : dq) cout << i <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = unsigned long long; n using pii = pair<int, int>; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n template <class Ty> n Ty randint(Ty a, Ty b) { n   return uniform_int_distribution<Ty>(a, b)(rng); n } n template <class T> n void DBG(T&& x) { n   cerr << x <<    ; n } n template <class T, class... Args> n void DBG(T&& x, Args&&... args) { n   DBG(x); n   DBG(args...); n } n template <class num> n inline void rd(num& x) { n   cin >> x; n } n template <class Ty, class... Args> n inline void rd(Ty& x, Args&... args) { n   rd(x); n   rd(args...); n } n template <class num> n inline void print(num&& x) { n   cout << x; n } n template <class Ty, class... Args> n inline void print(Ty&& x, Args&&... args) { n   print(x); n   print(   ); n   print(args...); n } n const int MOD = 1e9 + 7; n struct mint { n   int v; n   mint() : v{} {} n   mint(int v) : v(v) { go(); } n   inline void go() { n     if (abs(v) >= MOD) v %= MOD; n     if (v < 0) v += MOD; n   } n   inline static mint fpow(mint x, long long y) { n     mint r = 1; n     for (; y > 0; y /= 2, x *= x) n       if (y % 2 != 0) r *= x; n     return r; n   } n   mint inv() const { return fpow(*this, MOD - 2); } n   mint operator+(mint const& m) const { n     return v + m.v >= MOD ? v + m.v - MOD : v + m.v; n   } n   mint operator-(mint const& m) const { n     return v - m.v < 0 ? v - m.v + MOD : v - m.v; n   } n   mint operator*(mint const& m) const { return (long long)v * m.v % MOD; } n   mint operator/(mint const& m) const { return (*this) * m.inv(); } n   mint operator^(long long m) const { return fpow(*this, m); } n   mint& operator+=(mint const& m) { return (*this) = (*this) + m; } n   mint& operator-=(mint const& m) { return (*this) = (*this) - m; } n   mint& operator*=(mint const& m) { return (*this) = (*this) * m; } n   mint& operator/=(mint const& m) { return (*this) = (*this) / m; } n }; n int cant[6][6]; n mint memo[61][6]; n mint mem2[2006 * 60][6]; n int k; n int find_level(ll u) { n   int ans = 0; n   while (u >= 1) { n     ans++; n     u /= 2; n   } n   return k - ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cant[0][0] = cant[0][1] = 1; n   cant[1][0] = cant[1][1] = 1; n   cant[2][2] = cant[2][3] = 1; n   cant[3][3] = cant[3][2] = 1; n   cant[4][4] = cant[4][5] = 1; n   cant[5][5] = cant[5][4] = 1; n   rd(k); n   int n; n   rd(n); n   map<ll, int> mp; n   for (int i = 0; i < n; i++) { n     ll u; n     rd(u); n     string c; n     rd(c); n     int cur; n     if (c[0] ==  o ) cur = 5; n     if (c[0] ==  w ) cur = 0; n     if (c[0] ==  y ) cur = 1; n     if (c[0] ==  g ) cur = 2; n     if (c[0] ==  b ) cur = 3; n     if (c[0] ==  r ) cur = 4; n     mp[u] = cur; n   } n   vector<ll> special; n   for (auto [cc, c] : mp) { n     ll cur = cc; n     while (cur >= 1) { n       special.emplace_back(cur); n       cur /= 2; n     } n   } n   sort(special.begin(), special.end()); n   special.erase(unique(special.begin(), special.end()), special.end()); n   for (int i = 0; i < 6; i++) memo[0][i] = 1; n   for (int i = 1; i < k; i++) { n     for (int c = 0; c < 6; c++) { n       mint& ans = memo[i][c]; n       for (int c1 = 0; c1 < 6; c1++) n         if (!cant[c][c1]) { n           for (int c2 = 0; c2 < 6; c2++) n             if (!cant[c][c2]) { n               ans += memo[i - 1][c1] * memo[i - 1][c2]; n             } n         } n     } n   } n   const int N = special.size(); n   for (int i = N - 1; i >= 0; i--) { n     ll u = special[i]; n     int l = find_level(u); n     if (l == 0) { n       mem2[i][mp[u]] = 1; n       continue; n     } n     for (int c = 0; c < 6; c++) n       if (!mp.count(u) || mp[u] == c) { n         mint& ans = mem2[i][c]; n         for (int c1 = 0; c1 < 6; c1++) n           if (!cant[c][c1]) { n             for (int c2 = 0; c2 < 6; c2++) n               if (!cant[c][c2]) { n                 mint ans1 = memo[l - 1][c1]; n                 if (binary_search(special.begin(), special.end(), 2 * u)) { n                   int id = lower_bound(special.begin(), special.end(), 2 * u) - n                            special.begin(); n                   ans1 = mem2[id][c1]; n                 } n                 mint ans2 = memo[l - 1][c2]; n                 if (binary_search(special.begin(), special.end(), 2 * u + 1)) { n                   int id = n                       lower_bound(special.begin(), special.end(), 2 * u + 1) - n                       special.begin(); n                   ans2 = mem2[id][c2]; n                 } n                 ans += ans1 * ans2; n               } n           } n       } n   } n   mint ans = 0; n   for (int i = 0; i < 6; i++) ans += mem2[0][i]; n   print(ans.v), print(  n ); n } n