#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n template <typename T> n void chmin(T &a, T b) { n   if (a > b) a = b; n } n template <typename T> n void chmax(T &a, T b) { n   if (a < b) a = b; n } n template <typename T> n void add(T &a, T b) { n   a += b; n   if (a < 0) a += MOD; n   if (a >= MOD) a -= MOD; n } n void FastIn(int &T) { n   char C; n   bool F = 0; n   for (; C = getchar(), C <  0  || C >  9 ;) n     if (C ==  - ) F = 1; n   for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 ) n     ; n   F && (T = -T); n } n int in() { n   int x; n   scanf( %d , &x); n   return x; n } n long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n double din() { n   double x; n   scanf( %lf , &x); n   return x; n } n long long p2[63]; n void initP2() { n   p2[0] = 1; n   for (int i = (1); i <= (62); ++i) { n     p2[i] = p2[i - 1] * 2; n   } n } n int countBitsBaseB(long long n, long long b) { n   if (n == 0) return 1; n   int ret = 0; n   while (n) { n     ret++; n     n /= b; n   } n   return ret; n } n int count1(long long n) { n   int ret = 0; n   while (n) { n     ret += n & 1; n     n >>= 1; n   } n   return ret; n } n long long c[1024][1024] = {0}; n void initC() { n   for (int i = 0; i < (1024); ++i) { n     for (int j = 0; j < (i + 1); ++j) { n       if (j == 0 || j == i) { n         c[i][j] = 1; n       } else { n         c[i][j] = c[i - 1][j - 1]; n         add(c[i][j], c[i - 1][j]); n       } n     } n   } n } n bool IsPrime(int n) { n   if (n < 2) return false; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n void init() { n   initP2(); n   initC(); n } n const unsigned INVALID = 2000000001; n struct CMD { n   int cmd, x, y; n } q[(int)(2e5 + 10)]; n struct DSU { n   int f[(int)(2e5 + 10)]; n   int h[(int)(2e5 + 10)]; n   int *addr[(int)(2e5 + 10) << 2]; n   int val[(int)(2e5 + 10) << 2]; n   int stkSize = 0; n   void init(int n) { n     for (int i = (1); i <= (n); ++i) { n       f[i] = i; n       h[i] = 1; n     } n     stkSize = 0; n   } n   int find(int x) { return x == f[x] ? x : find(f[x]); } n   void merge(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) { n       return; n     } n     if (h[x] > h[y]) swap(x, y); n     addr[stkSize] = &f[x]; n     val[stkSize++] = f[x]; n     f[x] = y; n     if (h[x] == h[y]) { n       addr[stkSize] = &h[y]; n       val[stkSize++] = h[y]; n       h[y]++; n     } n   } n   void mergeFast(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) { n       return; n     } n     if (h[x] > h[y]) swap(x, y); n     f[x] = y; n     if (h[x] == h[y]) { n       h[y]++; n     } n   } n   void undo(int size) { n     while (stkSize > size) { n       stkSize--; n       *addr[stkSize] = val[stkSize]; n     } n   } n  n  private: n } dsu; n const int BLOCK = 5000; n int last[(int)(2e5 + 10)]; n pair<int, int> GetEdge(int x, int y, int der, int n) { n   x += der - 1; n   if (x >= n) x -= n; n   y += der - 1; n   if (y >= n) y -= n; n   if (x > y) swap(x, y); n   return make_pair(x + 1, y + 1); n } n void Switch(const pair<int, int> &edge, set<pair<int, int>> &edges) { n   if (edges.find(edge) != edges.end()) { n     edges.erase(edge); n   } else { n     edges.insert(edge); n   } n } n int main() { n   init(); n   int n = in(), m = in(); n   for (int i = (1); i <= (m); ++i) { n     q[i].cmd = in(); n     q[i].x = in(); n     q[i].y = in(); n   } n   last[0] = 0; n   for (int start = 1; start <= m; start += BLOCK) { n     int end = start + BLOCK - 1; n     if (end > m) { n       end = m; n     } n     set<pair<int, int>> nowEdges; n     nowEdges.clear(); n     for (int i0 = (start); i0 <= (end); ++i0) { n       nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 0, n)); n       nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 1, n)); n     } n     set<pair<int, int>> possible; n     possible.clear(); n     set<pair<int, int>> impossible; n     impossible.clear(); n     for (int i1 = (1); i1 <= (start - 1); ++i1) { n       if (q[i1].cmd == 2) { n         continue; n       } n       auto edge0 = GetEdge(q[i1].x, q[i1].y, last[i1 - 1], n); n       if (nowEdges.find(edge0) == nowEdges.end()) { n         Switch(edge0, impossible); n       } else { n         Switch(edge0, possible); n       } n     } n     dsu.init(n); n     for (auto edge1 : impossible) { n       dsu.mergeFast(edge1.first, edge1.second); n     } n     for (int i2 = (start); i2 <= (end); ++i2) { n       if (q[i2].cmd == 1) { n         last[i2] = last[i2 - 1]; n         Switch(GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n), possible); n         continue; n       } else { n         const int top = dsu.stkSize; n         for (auto edge1 : possible) { n           dsu.merge(edge1.first, edge1.second); n         } n         auto queryEdge = GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n); n         last[i2] = dsu.find(queryEdge.first) == dsu.find(queryEdge.second); n         putchar( 0  + last[i2]); n         dsu.undo(top); n       } n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n const bool debug = false; n int triple[1 << 12][3]; n int use[1 << 12]; n int cost[1 << 12]; n std::vector<int> gen_masks(int L) { n   std::vector<int> masks; n   masks.push_back(0); n   for (int i = 0; i < L; i++) { n     for (int j = 1; j < L; j++) { n       if (i + j * 2 >= L) continue; n       masks.push_back((1 << i) | (1 << (i + j)) | (1 << (i + 2 * j))); n     } n   } n   return masks; n } n int as[100005]; n int main() { n   std::vector<int> masks = gen_masks(12); n   for (int u : masks) { n     for (int v : masks) { n       for (int w : masks) { n         int res = (u ^ v ^ w) & ((1 << 9) - 1); n         triple[res][0] = u; n         triple[res][1] = v; n         triple[res][2] = w; n       } n     } n   } n   std::vector<std::array<int, 3> > moves; n   int NN; n   scanf( %d , &NN); n   int N = NN; n   for (int i = 1; i <= N; i++) { n     scanf( %d , &as[i]); n   } n   while (N >= 12) { n     int M = 0; n     for (int i = 0; i < 9; i++) { n       M |= (as[N - i] << i); n     } n     for (int t = 0; t < 3; t++) { n       std::array<int, 3> move; n       int index = 0; n       for (int i = 0; i < 12; i++) { n         if (triple[M][t] & (1 << i)) { n           as[N - i] ^= 1; n           move[index++] = N - i; n         } n       } n       if (index) { n         assert(index == 3); n         moves.push_back(move); n       } n     } n     N -= 9; n   } n   N = std::min(NN, 12); n   masks = gen_masks(N); n   for (int i = 1; i < (1 << N); i++) { n     cost[i] = 1e9; n   } n   for (int mask : masks) { n     for (int i = 0; i < (1 << N); i++) { n       if (cost[i ^ mask] > cost[i] + 1) { n         cost[i ^ mask] = cost[i] + 1; n         use[i ^ mask] = mask; n       } n     } n   } n   if (debug) { n     int worst = 0; n     for (int i = 0; i < (1 << N); i++) { n       if (cost[i] < 1e9) worst = std::max(worst, cost[i]); n       printf( %d:  , i); n       for (int k = 0; k < N; k++) { n         printf( %d , (use[i] >> k) & 1); n       } n       printf(  n ); n     } n     printf( WORST: %d n , worst); n   } n   while (true) { n     int M = 0; n     for (int i = 0; i < N; i++) { n       M |= (as[N - i] << i); n     } n     if (M == 0) break; n     std::array<int, 3> move; n     int index = 0; n     for (int i = 0; i < 12; i++) { n       if (use[M] & (1 << i)) { n         as[N - i] ^= 1; n         move[index++] = N - i; n       } n     } n     if (index == 0) { n       printf( NO n ); n       return 0; n     } n     assert(index == 3); n     moves.push_back(move); n   } n   for (int i = 0; i < N; i++) { n     assert(as[i] == 0); n   } n   printf( YES n ); n   printf( %d n , (int)moves.size()); n   for (auto move : moves) { n     printf( %d %d %d n , move[0], move[1], move[2]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[100010], b[100010], c[100010]; n void nhap() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   int dem = 1; n   a[1] = c[1]; n   for (int i = 2; i <= n; i++) n     if (c[i] != a[dem]) { n       dem++; n       a[dem] = c[i]; n     } n   n = dem; n } n void xuli() { n   a[0] = 0; n   a[n + 1] = 0; n   memset(b, 0, sizeof b); n   for (int i = 1; i <= n; i++) n     if (a[i - 1] == a[i + 1]) n       b[a[i]] += 2; n     else n       b[a[i]]++; n   int dem = 0, kq; n   for (int i = 1; i <= k; i++) n     if (dem < b[i]) dem = b[i], kq = i; n   cout << kq; n } n int main() { n   if (0) { n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n   }; n   nhap(); n   xuli(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   long n, m, l, r; n   vector<long> a(100005); n   map<long, vector<long> >::iterator mi; n   vector<long>::iterator vi1, vi2; n   map<long, vector<long> > hash; n   scanf( %ld %ld , &n, &m); n   for (long i = 0; i < n; i++) { n     scanf( %ld , &a[i]); n     if (hash.find(a[i]) != hash.end()) n       hash[a[i]].push_back(i); n     else { n       vector<long> v; n       v.push_back(i); n       hash[a[i]] = v; n     } n   } n   mi = hash.begin(); n   while (mi != hash.end()) { n     if (mi->first > mi->second.size()) { n       long temp = mi->first; n       mi++; n       hash.erase(hash.find(temp)); n     } else n       mi++; n   } n   long diff = r - l + 1, count = 0; n   long first, last; n   for (long i = 0; i < m; i++) { n     scanf( %ld %ld , &l, &r); n     diff = r - l + 1, count = 0; n     mi = hash.begin(); n     while (mi->first <= diff && mi != hash.end()) { n       vi1 = upper_bound(mi->second.begin(), mi->second.end(), r - 1); n       vi2 = lower_bound( n           mi->second.begin(), n           mi->second.end() - ((mi->first - 3 > 0) ? (mi->first - 3) : 0), n           l - 1); n       last = vi1 - mi->second.begin(), first = vi2 - mi->second.begin(); n       if (last - first == mi->first) count++; n       mi++; n     } n     printf( %ld n , count); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int __SIZE = 1 << 18; n char ibuf[__SIZE], *iS, *iT; n template <typename T> n inline void read(T &x) { n   char ch, t = 0; n   x = 0; n   while (!isdigit(ch = (iS == iT n                             ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                                (iS == iT ? EOF : *iS++)) n                             : *iS++))) n     t |= ch ==  - ; n   while (isdigit(ch)) n     x = x * 10 + (ch ^ 48), n     ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                       (iS == iT ? EOF : *iS++)) n                    : *iS++); n   x = t ? -x : x; n } n inline int read_int() { n   int x; n   return read(x), x; n } n inline long long read_ll() { n   long long x; n   return read(x), x; n } n template <typename T> n inline void chkmin(T &a, T b) { n   a = a < b ? a : b; n } n template <typename T> n inline void chkmax(T &a, T b) { n   a = a > b ? a : b; n } n const int MAXN = 150010; n const int mod = 998244353; n inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; } n inline int Mod(int x) { return x >= mod ? x - mod : x; } n inline int fsp(int x, int k = mod - 2) { n   int s = 1; n   while (k) { n     if (k & 1) s = 1LL * s * x % mod; n     x = 1LL * x * x % mod, k >>= 1; n   } n   return s; n } n inline long long S(long long x, long long k) { return (x + x + k - 1) * k / 2; } n inline long long find(long long x, long long k) { n   if (!x) return k * (k + 1) >> 1; n   long long p = find(x / k, k), rest = x % k; n   long long st = (x / k) * (k * k + 1) + rest * k + 1; n   if (st + k <= p) n     return S(st, k); n   else n     return S(st, k) + min(k, st + k - p); n } n inline void Solve() { n   long long n = read_ll(), k = read_int(), bel = (n - 1) / (k * k + 1); n   long long p = find(bel, k); n   if (p == n) n     cout << (bel + 1) * (k + 1) << endl; n   else { n     long long pos = n - bel - 1 + (n < p); n     long long t = (n - 1) % (k * k + 1) + 1; n     long long cnt = bel * k + (t - 1 - (n >= p)) / k; n     cout << pos + cnt << endl; n   } n } n int main() { n   int Case = read_int(); n   while (Case--) Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n; n   int mx = 0; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     mx = max(mx, (x + y)); n   } n   cout << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int arr[n]; n   int unos = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &arr[i]); n     if (arr[i]) unos++; n   } n   int fin = 0; n   for (int i = 0; i < n; i++) { n     int total = unos; n     for (int j = i; j < n; j++) { n       if (arr[j]) n         total--; n       else n         total++; n       fin = max(fin, total); n     } n   } n   printf( %d , fin); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned int n, i, f, p, s, rez; n int main() { n   cin >> n; n   f = 1; n   for (i = 1; i <= n; i++) f = ((unsigned long long)f * i) % 998244353; n   f = ((unsigned long long)f * n) % 998244353; n   p = 1; n   s = 0; n   for (i = n; i >= 2; i--) { n     p = ((unsigned long long)p * i) % 998244353; n     s = (s + p) % 998244353; n   } n   rez = (f - s + 998244353) % 998244353; n   cout << rez; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long calc_2(int s) { n   if (s < 0) return 0; n   return 1LL * (s + 1) * (s + 2) / 2; n } n long long calc_3(int s) { n   if (s < 0) return 0; n   long long ans = 0; n   for (int i = 0; i <= s; i++) ans += calc_2(s - i); n   return ans; n } n int val[5]; n int main() { n   int a, b, c, L; n   scanf( %d%d%d%d , &a, &b, &c, &L); n   val[1] = a - b - c, val[2] = b - a - c, val[3] = c - a - b; n   long long ans = calc_3(L); n   for (int i = 1; i <= 3; i++) { n     for (int z = 0; z <= L; z++) { n       int ed = min(L - z, val[i] + z); n       ans -= calc_2(ed); n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 26; n int cost[nmax][3]; n const int l = 0, m = 1, w = 2; n map<pair<int, int>, pair<string, int> > myMap; n pair<string, long long> global; n bool ok = 0; n void firstHalf(int a, int b, int c, string s) { n   if (myMap.count({a - b, b - c}) == 0 || myMap[{a - b, b - c}].second < a) { n     myMap[{a - b, b - c}] = {s, a}; n   } n } n void findMatch(int a, int b, int c, string s) { n   if (myMap.count({b - a, c - b}) != 0) { n     int ans = myMap[{b - a, c - b}].second + a; n     string fin = myMap[{b - a, c - b}].first + s; n     if (ans > global.second) { n       ok = 1; n       global = {fin, ans}; n     } n   } n } n void solve(int i, const int stop, void (*op)(int, int, int, string), int a, n            int b, int c, string s) { n   if (i == stop + 1) { n     op(a, b, c, s); n     return; n   } n   solve(i + 1, stop, op, a + cost[i][l], b + cost[i][m], c, s +  LM n ); n   solve(i + 1, stop, op, a + cost[i][l], b, c + cost[i][w], s +  LW n ); n   solve(i + 1, stop, op, a, b + cost[i][m], c + cost[i][w], s +  MW n ); n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> cost[i][l] >> cost[i][m] >> cost[i][w]; n   global.second = -26 * 10e7; n   string pl; n   solve(1, n / 2, &firstHalf, 0, 0, 0, pl); n   solve(n / 2 + 1, n, &findMatch, 0, 0, 0, pl); n   if (ok) n     cout << global.first; n   else n     cout <<  Impossible ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n; n     cin >> n; n     long long mn = 1e9, mx = -1e9; n     long long a[n]; n     for (int j = 0; j < n; j++) { n       cin >> a[j]; n       mn = min(a[j], mn); n       mx = max(a[j], mx); n     } n     long long x = mn * mx; n     int ans = 1; n     set<long long> s; n     for (int j = 2; j <= sqrt(x); j++) { n       if (x % j == 0) { n         s.insert(j); n         s.insert(x / j); n       } n     } n     int cnt = 0; n     for (int j = 0; j < n; j++) { n       if (x % a[j] == 0) { n         cnt++; n       } else { n         cnt = -1; n         break; n       } n     } n     if (cnt != s.size()) { n       cout << -1 << endl; n     } else n       cout << x << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n class IntTree { n  public: n   IntTree(int size) : nodes_(4 * size + 10, 0), size_(size) {} n   void Set(int pos, char ch) { Set(0, 1, size_, pos, ch); } n   int Count(int left, int right) { n     int mask = Mask(0, 1, size_, left, right); n     return CountBits(mask); n   } n  n  private: n   static int Left(int node) { return 2 * node + 1; } n   static int Right(int node) { return 2 * node + 2; } n   static int CountBits(int num); n   void Set(int node, int left, int right, int pos, char ch); n   int Mask(int node, int left, int right, int x, int y); n   vector<int> nodes_; n   int size_; n }; n int IntTree::CountBits(int num) { n   int count = 0; n   while (num > 0) { n     count += 1; n     num -= (num & -num); n   } n   return count; n } n void IntTree::Set(int node, int left, int right, int pos, char ch) { n   if (left == right) { n     nodes_[node] = (1 << (ch -  a )); n     return; n   } n   int mid = left + (right - left) / 2; n   if (pos <= mid) { n     Set(Left(node), left, mid, pos, ch); n   } else { n     Set(Right(node), mid + 1, right, pos, ch); n   } n   nodes_[node] = (nodes_[Left(node)] | nodes_[Right(node)]); n } n int IntTree::Mask(int node, int left, int right, int x, int y) { n   if (x <= left && right <= y) { n     return nodes_[node]; n   } n   int mask = 0; n   int mid = left + (right - left) / 2; n   if (x <= mid) { n     mask |= Mask(Left(node), left, mid, x, y); n   } n   if (mid < y) { n     mask |= Mask(Right(node), mid + 1, right, x, y); n   } n   return mask; n } n int main() { n   string str; n   getline(cin, str); n   IntTree tree(str.size()); n   for (size_t i = 0; i < str.size(); i += 1) { n     tree.Set(i + 1, str[i]); n   } n   int queries; n   cin >> queries; n   for (int i = 0; i < queries; i += 1) { n     int type, x, y; n     char ch; n     cin >> type; n     if (type == 1) { n       cin >> x >> ch; n       tree.Set(x, ch); n     } else { n       cin >> x >> y; n       cout << tree.Count(x, y) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n constexpr int N = 155; n int in[N][N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cin >> in[i][j]; n     } n   } n   vector<int> ans(N); n   for (int v = 1; v < n; v++) { n     for (int i = 1; i <= n; i++) { n       bool f1 = false; n       bool f2 = true; n       for (int j = 1; j <= n; j++) { n         if (in[i][j] == v) n           f1 = true; n         else { n           if (in[i][j] != -1 and in[i][j] != 0) f2 = false; n         } n       } n       if (f1 && f2) { n         ans[i] = v; n         for (int j = 1; j <= n; j++) in[i][j] = in[j][i] = -1; n         break; n       } n     } n   } n   for (int i = 1; i <= n; i++) cout << (ans[i] == 0 ? n : ans[i]) <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e5 + 9; n int n; n int mp[9]; n bool done[109]; n vector<pair<long long, pair<long long, long long> > > v[109]; n void dfs(int node) { n   done[node] = 1; n   for (int i = 0; i < v[node].size(); i++) { n     int u = v[node][i].first; n     int e = v[node][i].second.first; n     int f = v[node][i].second.second; n     if (done[u]) continue; n     mp[f] += e, dfs(u); n   } n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cin >> n; n   for (int i = 0; i < n; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     a--; n     b--; n     v[a].push_back({b, {c, 1}}); n     v[b].push_back({a, {c, 0}}); n   } n   dfs(0); n   mp[1 - v[0][1].second.second] += v[0][1].second.first; n   cout << min(mp[1], mp[0]) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000 + 10; n const long long INF = 1e18; n int n, q; n struct Edge { n   int u, v; n   long long w; n   Edge(int _u = 0, int _v = 0, long long _w = 0) : u(_u), v(_v), w(_w) {} n }; n vector<Edge> E; n int E_size; n vector<int> G[N]; n int ptr[2 * N]; n void adjListInit(int l, int r) { n   E.clear(); n   E_size = 0; n   for (int i = l; i <= r; i++) G[i].clear(); n } n void addEdge(int u, int v, long long w, int i) { n   E.push_back(Edge(u, v, w)); n   E_size++; n   ptr[i] = E_size - 1; n   G[u].push_back(E_size - 1); n } n vector<Edge> Eback; n int Gback[N]; n int Eback_size; n long long dist[N]; n int in[N], out[N]; n int peg[N]; n int dfs_clock; n inline void dfsInit() { n   dist[1] = 0; n   dfs_clock = 0; n } n void dfs(int u, int pre) { n   in[u] = ++dfs_clock; n   peg[in[u]] = u; n   for (int i = 0; i < G[u].size(); i++) { n     Edge e = E[G[u][i]]; n     int v = e.v; n     if (v == pre) continue; n     dist[v] = dist[u] + e.w; n     dfs(v, u); n   } n   out[u] = dfs_clock; n } n struct Node { n   int l, r; n   long long val, lazy; n   void update(long long x) { val += x, lazy += x; } n } node[N << 2]; n inline void pushdown(int rt) { n   if (node[rt].lazy) { n     node[rt << 1].update(node[rt].lazy); n     node[rt << 1 | 1].update(node[rt].lazy); n     node[rt].lazy = 0; n   } n } n inline void pushup(int rt) { n   node[rt].val = min(node[rt << 1].val, node[rt << 1 | 1].val); n } n void build(int root, int l, int r) { n   node[root].l = l; n   node[root].r = r; n   node[root].val = 0; n   node[root].lazy = 0; n   if (l == r) { n     int p = peg[l]; n     node[root].val = dist[p] + Eback[Gback[p]].w; n   } else { n     int mid = l + (r - l) / 2; n     build(root * 2, l, mid); n     build(root * 2 + 1, mid + 1, r); n     pushup(root); n   } n } n void update(int root, int st, int ed, int val) { n   if (st > node[root].r || ed < node[root].l) return; n   if (st <= node[root].l && node[root].r <= ed) n     node[root].update(val); n   else { n     pushdown(root); n     update(root * 2, st, ed, val); n     update(root * 2 + 1, st, ed, val); n     pushup(root); n   } n } n long long query(int root, int st, int ed) { n   if (ed < node[root].l || node[root].r < st) return INF; n   if (st <= node[root].l && node[root].r <= ed) n     return node[root].val; n   else { n     pushdown(root); n     long long lson = query(root * 2, st, ed); n     long long rson = query(root * 2 + 1, st, ed); n     pushup(root); n     return min(lson, rson); n   } n } n int main() { n   cin >> n >> q; n   adjListInit(1, n); n   for (int i = 1; i <= n - 1; i++) { n     int a, b; n     long long c; n     scanf( %d%d%I64d , &a, &b, &c); n     addEdge(a, b, c, i); n   } n   dfsInit(); n   dfs(1, -1); n   Eback.clear(); n   Eback_size = 0; n   for (int i = n, a, b, c; i <= 2 * n - 2; i++) { n     scanf( %d%d%d , &a, &b, &c); n     Eback.push_back(Edge(a, b, c)); n     Eback_size++; n     ptr[i] = Eback_size - 1; n     Gback[a] = Eback_size - 1; n   } n   Eback.push_back(Edge(1, 1, 0)); n   Eback_size++; n   Gback[1] = Eback_size - 1; n   build(1, 1, n); n   for (int i = 1, type; i <= q; i++) { n     scanf( %d , &type); n     if (type == 1) { n       int id; n       long long w; n       scanf( %d%I64d , &id, &w); n       if (id < n) { n         Edge &e = E[ptr[id]]; n         update(1, in[e.v], out[e.v], w - e.w); n         e.w = w; n       } else { n         Edge &e = Eback[ptr[id]]; n         update(1, in[e.u], in[e.u], w - e.w); n         e.w = w; n       } n     } n     if (type == 2) { n       int u, v; n       scanf( %d%d , &u, &v); n       if (in[u] <= in[v] && in[v] <= out[u]) { n         long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w; n         long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w; n         printf( %I64d n , dv - du); n       } else { n         long long ans = query(1, in[u], out[u]); n         long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w; n         long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w; n         ans -= du; n         ans += dv; n         printf( %I64d n , ans); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> a[100004]; n int p[100004]; n int v[100004]; n long long int c[100004]; n struct sajal { n   long long int add, sub, d; n }; n sajal d[100004]; n int main() { n   long n; n   cin >> n; n   long x, y; n   for (long i = 1; i < n; i++) { n     cin >> x >> y; n     a[x].push_back(y); n     a[y].push_back(x); n   } n   queue<long> q; n   q.push(1); n   p[1] = 1; n   while (!q.empty()) { n     long f = q.front(); n     q.pop(); n     v[f] = 1; n     for (long i = 0; i < a[f].size(); i++) { n       if (v[a[f][i]] == 0) { n         v[a[f][i]] = 1; n         q.push(a[f][i]); n         p[a[f][i]] = f; n       } n     } n   } n   for (long i = 1; i <= n; i++) { n     cin >> c[i]; n     d[i].add = 0; n     d[i].sub = 0; n     d[i].d = a[i].size(); n     if (a[i].size() == 1 && i != 1) { n       q.push(i); n     } n   } n   long long int add = 0; n   long long int sub = 0; n   long cur = 1; n   while (!q.empty()) { n     long f = q.front(); n     q.pop(); n     long long int e = d[f].add - d[f].sub; n     long long int h = -c[f] - e; n     long long int w = p[f]; n     if (h >= 0) { n       d[f].add = d[f].add + h; n     } else { n       h = -h; n       d[f].sub = h + d[f].sub; n     } n     if (d[f].sub > sub) sub = d[f].sub; n     if (d[f].add > add) add = d[f].add; n     if (d[w].sub < d[f].sub) d[w].sub = d[f].sub; n     if (d[w].add < d[f].add) d[w].add = d[f].add; n     d[w].d--; n     if (d[w].d == 1 && w != 1) { n       q.push(w); n     } n   } n   c[1] = c[1] + d[1].add - d[1].sub; n   c[1] = -c[1]; n   if (c[1] >= 0) { n     d[1].add = d[1].add + c[1]; n   } else { n     c[1] = -c[1]; n     d[1].sub = d[1].sub + c[1]; n   } n   if (add < d[1].add) add = d[1].add; n   if (sub < d[1].sub) sub = d[1].sub; n   cout << add + sub << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, l, r, x; n string s; n int main() { n   cin >> n >> m; n   r = 0; n   l = n + 1; n   for (int i = 0; i < m; ++i) { n     cin >> s; n     cin >> s; n     cin >> s; n     if (s ==  left ) { n       cin >> s >> x; n       l = min(l, x); n     } else { n       cin >> s >> x; n       r = max(r, x); n     } n   } n   if (l - r - 1 <= 0) n     cout << -1 << endl; n   else n     cout << l - r - 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string intial, code; n   cin >> intial >> code; n   int res = 0; n   for (int i = 0; i < n; i++) { n     int a = (((intial[i] -  0 ) - (code[i] -  0 )) + 10) % 10; n     int b = (((code[i] -  0 ) - (intial[i] -  0 )) + 10) % 10; n     res += min(a, b); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int e[100010]; n int main() { n   int n, u, i, j = 3; n   double ans = 0; n   scanf( %d%d , &n, &u); n   for (i = 1; i <= n; i++) scanf( %d , &e[i]); n   for (i = 1; i <= n; i++) { n     while (j <= n && e[j] - e[i] <= u) j++; n     j--; n     if (j > i + 1) ans = max(ans, (e[j] - e[i + 1] + 0.0) / (e[j] - e[i])); n   } n   if (ans == 0) n     cout << -1 << endl; n   else { n     cout.precision(19); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int temperature; n     long long int a12, b11; n     long long int solution; n     cin >> a12 >> b11; n     if (b11 == a12) { n       solution = 0; n     } else if (b11 > a12) { n       temperature = b11 - a12; n       if (temperature & 1) { n         solution = 1; n       } else { n         solution = 2; n       } n     } else { n       temperature = a12 - b11; n       if (temperature & 1) { n         solution = 2; n       } else { n         solution = 1; n       } n     } n     cout << solution <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[26]; n int w[256]; n int n; n int LIMIT = 1; n int su[26], sv[26], sk[26]; n int go(int lev) { n   if (a[lev] == n) { n     printf( %d n , lev); n     for (int i = 0; i < lev; i++) n       if (su[i] == -1) { n         printf( lea e%cx, [%d*e%cx] n ,  a  + i + 1, 1 << sk[i],  a  + sv[i]); n       } else if (sk[i] == 0) n         printf( lea e%cx, [e%cx + e%cx] n ,  a  + i + 1,  a  + su[i], n                 a  + sv[i]); n       else n         printf( lea e%cx, [e%cx + %d*e%cx] n ,  a  + i + 1,  a  + su[i], n                1 << sk[i],  a  + sv[i]); n     return 1; n   } n   if (lev >= LIMIT) return 0; n   int &i = su[lev], &j = sv[lev], &k = sk[lev]; n   i = -1; n   for (j = 0; j <= lev; j++) n     for (k = 0; k <= 3; k++) { n       int v = (a[j] << k); n       if (v > a[lev] && v <= n) { n         a[lev + 1] = v; n         if (go(lev + 1)) return 1; n         a[lev + 1] = 0; n       } n     } n   for (i = 0; i <= lev; i++) n     for (j = 0; j <= lev; j++) { n       for (k = 0; k <= 3; k++) { n         int v = a[i] + (a[j] << k); n         if (v > a[lev] && v <= n) { n           a[lev + 1] = v; n           if (go(lev + 1)) return 1; n           a[lev + 1] = 0; n         } n       } n     } n   return 0; n } n int main(void) { n   scanf( %d , &n); n   if (n == 1) { n     printf( 0 n ); n     return 0; n   } n   a[0] = 1; n   w[1] = 1; n   for (LIMIT = 1;; LIMIT++) { n     if (go(0)) { n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   long long ans = 0; n   for (int i = 2; i <= n; i++) n     for (int j = i + i; j <= n; j += i) ans += j / i; n   cout << ans * 4 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int64_t INF = INT64_MAX / 4; n const int64_t NINF = -INF; n map<pair<int64_t, uint32_t>, int64_t> dp; n int64_t grundy(int64_t pile, uint32_t pattern) { n   if (pile == 0) { n     return 0; n   } n   pair<int64_t, uint32_t> key = {pile, pattern}; n   auto fd = dp.find(key); n   if (fd != dp.end()) { n     return fd->second; n   } n   bitset<32> bs(pattern); n   set<int64_t> res; n   for (int64_t i = 0; i < pile; i++) { n     if (!bs[i]) { n       bs[i] = true; n       res.insert(grundy(pile - (i + 1), bs.to_ulong())); n       bs[i] = false; n     } n   } n   int64_t ans = 0; n   while (res.find(ans) != res.end()) { n     ans++; n   } n   dp.insert({key, ans}); n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int64_t n; n   cin >> n; n   int64_t ans = 0; n   for (int64_t i = 0; i < n; i++) { n     int64_t pile; n     cin >> pile; n     ans ^= grundy(pile, 0); n   }; n   if (ans == 0) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long p, q, b, t, g; n long long gcd(long long a, long long b) { n   if (a < b) swap(a, b); n   while (b != 0) { n     a %= b; n     swap(a, b); n   } n   return a; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> p >> q >> b; n     g = gcd(p, q); n     q /= g; n     while (true) { n       g = gcd(b, q); n       if (g == 1) break; n       while (q % g == 0) q /= g; n     } n     if (q == 1) n       cout <<  Finite ; n     else n       cout <<  Infinite ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n int dx[4] = {1, 0, -1, 0}; n int dy[4] = {0, 1, 0, -1}; n int main() { n   long long A, B, C, D, E, F, N, K, M, Z, sum = 0, num = 0, flag = 0; n   string S, T; n   cin >> Z; n   queue<long long> que; n   while (Z--) { n     cin >> S; n     vector<long long> P(0, 0); n     num = 0; n     S +=  0 ; n     for (long long int i = 0; i < S.size(); i++) { n       if (S[i] ==  1 ) n         num++; n       else { n         P.push_back(num); n         num = 0; n       } n     } n     sort(P.begin(), P.end()); n     reverse(P.begin(), P.end()); n     sum = 0; n     for (long long int i = 0; i < P.size(); i++) { n       sum += P[i]; n       i++; n     } n     que.push(sum); n   } n   while (!que.empty()) { n     cout << que.front() << endl; n     que.pop(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int k, n; n   cin >> n >> k; n   int x[n]; n   for (int i = 0; i < n; i++) { n     cin >> x[i]; n   } n   double m = -1, sum = 0; n   int c = 0; n   for (int i = 0; i < n; i++) { n     for (int j = i; j < n; j++) { n       c++; n       sum += x[j]; n       if (c >= k && (sum / c) > m) { n         m = sum / c; n       } n     } n     c = 0; n     sum = 0; n   } n   cout << setprecision(15) << fixed << m << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long powm(long long base, long long exp, long long mod = 1000000009) { n   long long ans = 1; n   while (exp) { n     if (exp & 1) ans = (ans * base) % mod; n     exp >>= 1, base = (base * base) % mod; n   } n   return ans; n } n long long ctl(char x, char an =  a ) { return (long long)(x - an); } n char ltc(long long x, char an =  a ) { return (char)(x + an); } n long long first[300005], pref[300005], pref_fib[300005], a[300005]; n long long get_fibo_sum(long long l, long long r) { n   return (pref_fib[r] - (l ? pref_fib[l - 1] : 0) + 1000000009) % 1000000009; n } n long long get_fibo(long long st1, long long st2, long long i) { n   if (i == 0) n     return st1; n   else if (i == 1) n     return st2; n   else { n     long long ret = ((first[i - 1] * st2) % 1000000009 + n                      (first[i - 2] * st1) % 1000000009) % n                     1000000009; n     return ret; n   } n } n long long get_fibo_sum(long long st1, long long st2, long long i) { n   if (i == 0) n     return st1; n   else if (i == 1) n     return (st1 + st2) % 1000000009; n   else { n     long long ans = (st2 * get_fibo_sum(1, i - 1)) % 1000000009; n     ans = (ans + (st1 * get_fibo_sum(0, i - 2)) % 1000000009) % 1000000009; n     ans = (ans + st1) % 1000000009; n     ans = (ans + st2) % 1000000009; n     return ans; n   } n } n const pair<long long, long long> khali = make_pair(0LL, 0LL); n struct lazySegTree { n   long long tree[4 * 300005], x, y, val; n   pair<long long, long long> lazy[4 * 300005]; n   void push(long long low, long long high, long long pos) { n     if (lazy[pos] != khali) { n       tree[pos] += n           get_fibo_sum(lazy[pos].first, lazy[pos].second, (high - low)); n       if (low != high) { n         pair<long long, long long> tmp; n         tmp = lazy[pos]; n         lazy[2 * pos + 1].first = n             (lazy[2 * pos + 1].first + tmp.first) % 1000000009; n         lazy[2 * pos + 1].second = n             (lazy[2 * pos + 1].second + tmp.second) % 1000000009; n         tmp.first = get_fibo(lazy[pos].first, lazy[pos].second, n                              (low + high) / 2 - low + 1); n         tmp.second = get_fibo(lazy[pos].first, lazy[pos].second, n                               (low + high) / 2 - low + 2); n         lazy[2 * pos + 2].first = n             (lazy[2 * pos + 2].first + tmp.first) % 1000000009; n         lazy[2 * pos + 2].second = n             (lazy[2 * pos + 2].second + tmp.second) % 1000000009; n       } n       lazy[pos] = khali; n     } n   } n   long long query(long long low, long long high, long long pos) { n     push(low, high, pos); n     if (x <= low and y >= high) return tree[pos]; n     if (x > high || y < low) return 0; n     long long mid = (high + low) / 2; n     return (query(low, mid, 2 * pos + 1) + query(mid + 1, high, 2 * pos + 2)) % n            1000000009; n   } n   void update(long long low, long long high, long long pos) { n     push(low, high, pos); n     if (x > high || y < low) return; n     if (x <= low and y >= high) { n       lazy[pos].first = first[low - x]; n       lazy[pos].second = first[low - x + 1]; n       push(low, high, pos); n       return; n     } n     long long mid = (low + high) / 2; n     update(low, mid, 2 * pos + 1), update(mid + 1, high, 2 * pos + 2); n     tree[pos] = (tree[2 * pos + 1] + tree[2 * pos + 2]) % 1000000009; n   } n } lst; n int main() { n   first[0] = 1, first[1] = 1; n   for (long long i = 2; i < 300005; i++) n     first[i] = (first[i - 1] + first[i - 2]) % 1000000009; n   for (long long i = 0; i < 4 * 300005; i++) lst.lazy[i] = khali; n   long long type, l, r, n, q; n   cin >> n >> q; n   for (long long i = 1; i < n + 1; i++) cin >> a[i]; n   pref_fib[0] = 1; n   for (long long i = 1; i < 300005; i++) n     pref_fib[i] = (pref_fib[i - 1] + first[i]) % 1000000009; n   pref[1] = a[1]; n   for (long long i = 1; i < 300005; i++) n     pref[i] = (pref[i - 1] + a[i]) % 1000000009; n   while (q--) { n     cin >> type >> l >> r; n     lst.x = l, lst.y = r; n     if (type == 1) { n       lst.update(1, n, 0); n     } else { n       long long ans = lst.query(1, n, 0); n       ans = (ans + pref[r]) % 1000000009; n       ans = (ans - pref[l - 1] + 1000000009) % 1000000009; n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n void solve() { n   int n; n   std::cin >> n; n   std::stack<int> q; n   int a = 0; n   int cur = 1; n   n += n; n   while (n--) { n     std::string s; n     std::cin >> s; n     if (s[0] ==  r ) { n       if (!q.empty() && q.top() != cur) { n         while (!q.empty()) q.pop(); n         ++a; n       } n       if (!q.empty()) q.pop(); n       ++cur; n     } else { n       int x; n       std::cin >> x; n       q.push(x); n     } n   } n   std::cout << a; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool smin(T &a, const T &b) { n   return b < a ? a = b, 1 : 0; n } n template <typename T> n inline bool smax(T &a, const T &b) { n   return a < b ? a = b, 1 : 0; n } n const long long N = 1e5 + 100, lg = 22; n long long n, k, add[N], h[N]; n vector<pair<long long, long long> > adj[N]; n long long par[N][lg]; n void dfs(long long v = 1, long long p = -1, long long dep = 0) { n   if (v != 1) { n     par[v][0] = p; n     for (long long i = 1; i < lg; i++) par[v][i] = par[par[v][i - 1]][i - 1]; n   } else { n     for (long long i = 0; i < lg; i++) par[v][i] = v; n   } n   h[v] = dep; n   for (auto u : adj[v]) n     if (u.first != p) dfs(u.first, v, dep + 1); n } n long long getPar(long long v, long long k) { n   for (long long i = lg - 1; i >= 0; i--) n     if (k >> i & 1) v = par[v][i]; n   return v; n } n long long lca(long long u, long long v) { n   if (h[u] > h[v]) swap(u, v); n   v = getPar(v, h[v] - h[u]); n   if (u == v) return v; n   for (long long i = lg - 1; i >= 0; i--) { n     if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; n   } n   return par[v][0]; n } n long long ans[N]; n long long calc(long long v = 1, long long p = -1, long long want = -1) { n   long long res = add[v]; n   for (auto u : adj[v]) { n     if (u.first == p) continue; n     res += calc(u.first, v, u.second); n   } n   if (want != -1) ans[want] = res; n   return res; n } n int32_t main() { n   cin >> n; n   for (long long i = 0; i < n - 1; i++) { n     long long u, v; n     cin >> u >> v; n     adj[v].push_back({u, i}), adj[u].push_back({v, i}); n   } n   dfs(); n   cin >> k; n   while (k--) { n     long long u, v; n     cin >> u >> v; n     long long l = lca(u, v); n     add[u]++, add[v]++, add[l] -= 2; n   }; n   calc(); n   for (long long i = 0; i < n - 1; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int arr[n][4]; n   multiset<int> s[4]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 4; j++) { n       cin >> arr[i][j]; n       s[j].insert(arr[i][j]); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 4; j++) { n       auto temp = s[j].find(arr[i][j]); n       s[j].erase(temp); n     } n     if (*s[0].rbegin() <= *s[2].begin() && *s[1].rbegin() <= *s[3].begin()) { n       cout << *s[0].rbegin() <<     << *s[1].rbegin() << endl; n       break; n     } n     for (int j = 0; j < 4; j++) s[j].insert(arr[i][j]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long p[m]; n   for (long long int i = 0; i < m; i++) cin >> p[i]; n   sort(p, p + m); n   long long an = 0, x = 0, c = 0, cp = 1; n   while (1) { n     long long y = x, pg = ceil((long double)(p[x] - x) / (k)); n     while (y < m && ceil((long double)(p[y] - x) / (k)) == pg) y++; n     if (y == m) { n       cout << an + 1; n       return; n     } n     an++; n     x = y; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long TESTS = 1; n   while (TESTS--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int requestNum; n   cin >> requestNum; n   vector<pair<int, pair<int, int>>> vect(requestNum); n   for (int i = 0; i < requestNum; i++) { n     int num, money; n     cin >> num >> money; n     vect.push_back(make_pair(money, make_pair(num, i + 1))); n   } n   sort(vect.rbegin(), vect.rend()); n   int tablesNum; n   cin >> tablesNum; n   vector<pair<int, int>> maxPeople(tablesNum); n   for (int i = 0; i < tablesNum; i++) { n     cin >> maxPeople[i].first; n     maxPeople[i].second = i + 1; n   } n   sort(maxPeople.begin(), maxPeople.end()); n   vector<bool> tablesFull(tablesNum, false); n   long long int totalMoney = 0; n   vector<pair<long, long>> result; n   for (int i = 0; i < requestNum; i++) { n     for (int j = 0; j < tablesNum; j++) { n       if (vect[i].second.first <= maxPeople[j].first && !tablesFull[j]) { n         result.push_back(make_pair(vect[i].second.second, maxPeople[j].second)); n         totalMoney += vect[i].first; n         tablesFull[j] = true; n         break; n       } n     } n   } n   cout << result.size() <<     << totalMoney << endl; n   for (int i = 0; i < result.size(); i++) { n     cout << result[i].first <<     << result[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7; n const double PI = 3.1415926536; n int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n bool is_prime(long long n) { n   for (long long i = 2; i * i <= n; ++i) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n inline long long getPow(long long a, long long b) { n   long long res = 1ll, tp = a; n   while (b) { n     if (b & 1ll) { n       res *= tp; n     } n     tp *= tp; n     b >>= 1ll; n   } n   return res; n } n long long vec_mult(const pair<long long, long long> &t1, n                    const pair<long long, long long> &t2, n                    const pair<long long, long long> &t3) { n   const long long &x1 = t1.first, y1 = t1.second; n   const long long &x2 = t2.first, y2 = t2.second; n   const long long &x3 = t3.first, y3 = t3.second; n   return ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)); n } n void ok() { n   cout <<  YES  << endl; n   exit(0); n } n void no() { n   cout <<  NO  << endl; n   exit(0); n } n inline long long nxt() { n   long long x; n   cin >> x; n   return x; n } n long long otr(long long num) { n   long long cur = 0; n   long long ct = 1; n   while (num) { n     cur += ct * (9 - num % 10); n     num /= 10; n     ct *= 10; n   } n   return cur; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   long long l = nxt(), r = nxt(); n   long long t = 1ll; n   long long ans = -1; n   while (t <= r) { n     long long left = max(l, t); n     long long right = min(r, 10ll * t - 1); n     while (right - left > 2) { n       long long len = (right - left + 1) / 3; n       long long t1 = left + len; n       long long t2 = right - len; n       if (t1 * otr(t1) >= t2 * otr(t2)) { n         right = t2; n       } else { n         left = t1; n       } n     } n     while (left <= right) { n       ans = max(ans, left * otr(left)); n       left++; n     } n     t *= 10ll; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void faster() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n string s, x, t, ans; n long long q, n, a[456789], b[456789], sum, prefa[456789], prefb[456789], k, l, n     r, mx; n bool ok; n void dii() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   k = 1; n   for (int i = 1; i <= n; i++) { n     if (a[i] <= 2 * a[i - 1]) { n       k++; n     } else { n       k = 1; n     } n     if (k > mx) { n       mx = k; n     } n   } n   cout << mx; n } n int main() { n   faster(); n   q = 1; n   while (q--) { n     dii(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 1 << 29; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(NULL); n   ; n   int n; n   std::cin >> n; n   std::vector<int> v(n); n   for (int &it : v) std::cin >> it; n   int alice = v[0]; n   int sum = std::accumulate(v.begin(), v.end(), 0); n   int target = sum / 2 + 1; n   std::vector<int> ans; n   ans.push_back(1); n   int cur = alice; n   for (int i = 0; i < n; i++) { n     if (alice < v[i] * 2) continue; n     cur += v[i]; n     ans.push_back(i + 1); n     if (cur >= target) break; n   } n   if (cur < target) { n     std::cout << 0; n     exit(0); n   } else { n     std::cout << ans.size() <<   n ; n     for (int it : ans) std::cout << it <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n void dfs(int64_t node, int64_t from, n          const std::vector<std::vector<int64_t> > &g, n          std::vector<bool> &visited, int64_t &count, bool &cycle, bool &self) { n   if (visited[node]) { n     return; n   } n   visited[node] = 1; n   ++count; n   for (int64_t p = 0; p < g[node].size(); p++) { n     int64_t u = g[node][p]; n     if (u == from) { n       continue; n     } else if (u == node) { n       self = true; n     } else if (visited[u]) { n       cycle = true; n     } else { n       dfs(u, node, g, visited, count, cycle, self); n     } n   } n   return; n } n int main() { n   const int64_t MOD = 1000000007; n   int64_t n; n   scanf( %lld , &n); n   std::vector<std::vector<int64_t> > g(2 * n); n   for (int64_t p = 0; p < n; p++) { n     int64_t x, y; n     scanf( %lld %lld , &x, &y); n     --x; n     --y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   std::vector<bool> visited(2 * n, false); n   int64_t total(1); n   for (int64_t p = 0; p < 2 * n; p++) { n     if (visited[p]) { n       continue; n     } n     int64_t count(0); n     bool cycle(false), self(false); n     dfs(p, -1, g, visited, count, cycle, self); n     if (self) { n       count = 1; n     } else if (cycle) { n       count = 2; n     } n     total *= count; n     total %= MOD; n   } n   printf( %lld n , total); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1010, M = 2010; n int las[M], nxt[M], to[M], cnt; n int l[M], r[M], siz[M], mx[N][N], f[N]; n inline void add(int u, int v) { n   cnt++; n   to[cnt] = v; n   nxt[cnt] = las[u]; n   las[u] = cnt; n } n int n, m; n inline void fmin(int &a, int b) { n   if (a > b) a = b; n } n inline void fmax(int &a, int b) { n   if (a < b) a = b; n } n void dfs(int now) { n   int i; n   siz[now] = now != 1; n   if (las[now]) l[now] = n, r[now] = 0; n   for (i = las[now]; i; i = nxt[i]) n     dfs(to[i]), siz[now] += siz[to[i]], fmin(l[now], l[to[i]]), n         fmax(r[now], r[to[i]]); n   fmax(mx[l[now]][r[now]], siz[now]); n } n int main() { n   int i, j, x; n   scanf( %d , &n); n   scanf( %d , &m); n   for (i = 2; i <= m; i++) scanf( %d , &x), add(x, i); n   for (i = 1; i <= n; i++) scanf( %d , &x), l[x] = r[x] = i; n   dfs(1); n   cnt = 0; n   memset(las, 0, sizeof las); n   scanf( %d , &m); n   for (i = 2; i <= m; i++) scanf( %d , &x), add(x, i); n   for (i = 1; i <= n; i++) scanf( %d , &x), l[x] = r[x] = i; n   dfs(1); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= i; j++) n       if (mx[j][i]) fmax(f[i], f[j - 1] + mx[j][i]); n   printf( %d n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, ans[N], an; n struct edge { n   int to, nx, id, dl; n } ee[N]; n int eq[N], en = 1; n void dfs(int d) { n   for (int j = eq[d], k; k = ee[j].to, j; j = ee[j].nx) n     if (!ee[j].dl) { n       ee[j].dl = 1; n       dfs(k); n       ans[--an] = ee[j].id; n     } n } n int main() { n   scanf( %d , &n); n   if (n & 1) { n     printf( -1 n ); n     return 0; n   } n   for (int x = 0, t1, t2; x < n; x++) { n     t1 = (x * 2 + 0) % n; n     t2 = (x * 2 + 1) % n; n     ee[++en] = (edge){((t1) / 2 + 1), eq[((x) / 2 + 1)], x, 0}, n     eq[((x) / 2 + 1)] = en; n   } n   an = n; n   dfs(1); n   for (int s = 0; s < n; s++) n     if (ans[s] == 0) { n       for (int i = 0; i < n; i++) printf( %d  , ans[(s + i) % n]); n       printf( 0 n ); n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n void _print(long long t) { cerr << t; } n void _print(int t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(unordered_map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(list<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc = 0, T; n   cin >> T; n   while (++tc <= T) { n     int N; n     cin >> N; n     cout << (int)sqrt(N) + (int)cbrt(N) - (int)sqrt((int)cbrt(N)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const double pi = acos(-1); n const double EPS = 1e-9; n long long binpowmod(long long a, long long b) { n   a %= MOD; n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return ret % MOD; n } n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n const int N = 1 << 18; n const int E = N * 2; n bool good(long long n) { n   long long t = n; n   int sumofdigits = 0; n   while (n) { n     sumofdigits += n % 10; n     n /= 10; n   } n   return (gcd(t, sumofdigits) > 1); n } n int n, m, ans; n vector<vector<int> > a; n bool good(int i, int j) { n   for (int k = 0; k < m; ++k) { n     if (a[i][k] != a[j][k]) return false; n   } n   return true; n } n void solveit(int l = 0, int r = n - 1, int c = 1) { n   int len = r - l + 1; n   if (len % 2) return; n   int i = l, j = r; n   while (i < j) { n     if (!good(i, j)) return; n     i++; n     j--; n   } n   ans = min(ans, n / (1 << c)); n   int mid = (l + r) / 2; n   solveit(l, mid, c + 1); n   solveit(mid + 1, r, c + 1); n } n void solve() { n   cin >> n >> m; n   ans = n; n   a.assign(n, vector<int>(m)); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> a[i][j]; n   solveit(); n   cout << ans <<   n ; n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc = 1; n   while (tc--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   long long ans1 = 1, ans2 = 1; n   for (int i = 1; i <= k - 1; i++) ans1 = ans1 * k % 1000000007; n   for (int i = 1; i <= n - k; i++) ans2 = ans2 * (n - k) % 1000000007; n   printf( %I64d n , ans1 * ans2 % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 25, mod = 1e9 + 7; n int a[N][N], used[N][N], cur, first, n, m, k; n long long ans; n int count(int x) { n   int ans = 0; n   for (; x; x -= x & -x) ans++; n   return ans; n } n void dfs(int x, int y) { n   if (x == n) { n     int p = count(cur & ~first), q = count(((1 << k) - 1) & ~first); n     long long curans = 1; n     while (p--) { n       curans = (curans * q) % mod; n       q--; n     } n     ans = (ans + curans) % mod; n     return; n   } n   int nx = x, ny = y + 1; n   if (ny == m) { n     nx++; n     ny = 0; n   } n   if (a[x][y]) { n     dfs(nx, ny); n     return; n   } else { n     bool flag = true; n     int can = (1 << k) - 1; n     can &= ~used[x][y]; n     for (int i = 0; (1 << i) <= can; i++) { n       if (!((can >> i) & 1)) continue; n       bool preused[N][N], preusedcur; n       preusedcur = true; n       memset(preused, false, sizeof(preused)); n       if (!((cur >> i) & 1)) { n         if (flag) n           flag = false; n         else n           continue; n         preusedcur = false; n       } n       cur |= 1 << i; n       for (int px = x; px < n; px++) n         for (int py = y; py < m; py++) { n           if ((used[px][py] >> i) & 1) n             preused[px][py] = true; n           else n             used[px][py] |= 1 << i; n         } n       dfs(nx, ny); n       if (!preusedcur) cur &= ~(1 << i); n       for (int px = x; px < n; px++) n         for (int py = y; py < m; py++) { n           if (!preused[px][py]) used[px][py] &= ~(1 << i); n         } n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   if (n + m - 1 > k) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       scanf( %d , &a[i][j]); n       if (a[i][j]) { n         first |= 1 << a[i][j] - 1; n         if ((used[i][j] >> a[i][j] - 1) & 1) { n           printf( 0 n ); n           return 0; n         } n         for (int r = 0; r < n; r++) n           for (int c = 0; c < m; c++) { n             if (r <= i && c <= j || r >= i && c >= j) n               used[r][c] |= 1 << a[i][j] - 1; n           } n       } n     } n   cur = first; n   dfs(0, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int p1, p2, p3, p4, a, b; n   cin >> p1 >> p2 >> p3 >> p4 >> a >> b; n   int m = min(min(min(p1, p2), p3), p4); n   cout << max(0, min(b + 1, m) - a) << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int inf = (1 << 30) - 1; n const double eps = 1e-9; n using namespace std; n int a[111111], n, k, mx = 0, aa; n long long s[111111]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; n   for (int i = 1; i <= n; i++) { n     int l = 1, r = i; n     while (r > l) { n       int m = (l + r) / 2; n       long long ss = s[i] - s[m - 1]; n       if (1ll * a[i] * (i - m + 1) - ss > k) n         l = m + 1; n       else n         r = m; n     } n     if (i - r + 1 > mx) { n       mx = i - r + 1; n       aa = a[i]; n     } n   } n   cout << (mx) <<    ; n   cout << (aa) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double dp[(1 << 20)]; n double a[20][20]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> a[i][j]; n     } n   } n   dp[(1 << n) - 1] = 1.0; n   for (int st = (1 << n) - 1; st >= 0; st--) { n     for (int i = 0; i < n; i++) { n       if (st & (1 << i)) { n         for (int j = 0; j < n; j++) { n           if ((st & (1 << j)) && (i != j)) { n             int q = __builtin_popcount(st); n             dp[st ^ (1 << j)] += dp[st] * a[i][j] * (1.0 / (q * (q - 1) / 2)); n           } n         } n       } n     } n   } n   for (int i = 1; i < (1 << n); i = (i << 1)) { n     printf( %.6f  , dp[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int pr[] = {2, 3, 5, 7, 11, 13, 17, 19}; n int big[50000005]; n int c[10]; n int ans[10100]; n int main() { n   int k; n   scanf( %d , &k); n   big[1] = 0; n   for (int i = 0; i < 7; i++) big[pr[i]] = i + 1; n   for (int i = 2; i <= 2 * k * k; i++) { n     if (big[i] == 0) continue; n     for (int j = 0; j < 7; j++) { n       if (i * pr[j] <= 2 * k * k) { n         big[i * pr[j]] = max(big[i], j + 1); n       } n     } n     for (int j = big[i] - 1; j < 7; j++) c[j]++; n   } n   for (int j = 0; j < 7; j++) n     if (c[j] >= k) { n       int sz = 0; n       for (int i = 2 * k * k; i >= 0; i--) n         if (big[i] != 0 && big[i] - 1 <= j && n             big[i / pr[big[i] - 1]] - 1 < big[i] - 1) { n           ans[sz++] = i; n           if (sz == k) break; n         } n       if (sz < k) continue; n       for (int i = sz - 1; i >= 0; i--) printf( %d  , ans[i]); n       printf(  n ); n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e7 + 5; n int s[maxn]; n int a[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &s[i]); n   } n   sort(s + 1, s + n + 1); n   for (int i = 1; i <= n / 2; i++) { n     a[i] = s[i] + s[n + 1 - i]; n     ans += a[i] * a[i]; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9; n long long Power(long long a, long long b) { n   if (b == 0) return 1; n   long long p = Power(a, b / 2); n   p = (p * p); n   if (b & 1) { n     p = (p * a); n   } n   return p; n } n long long Gcd(long long a, long long b) { n   if (b == 0) return a; n   if (a < b) return Gcd(b, a); n   return Gcd(b, a % b); n } n void Solve() { n   int n, m; n   long long l; n   cin >> n >> m >> l; n   vector<long long> arr(n), seg(n, -1); n   for (int i = 0; i < n; i++) cin >> arr[i]; n   int curr = 0, prev = -1; n   for (int i = 0; i < n; i++) { n     if (arr[i] > l) { n       seg[i] = 0; n       if (prev == -1) { n         curr++; n       } n       prev = 0; n     } else { n       prev = -1; n       seg[i] = -1; n     } n   } n   while (m--) { n     int t; n     cin >> t; n     if (t == 0) { n       cout << curr <<   n ; n     } else { n       int p; n       long long d; n       cin >> p >> d; n       p--; n       arr[p] += d; n       if (seg[p] == -1 && arr[p] > l) { n         seg[p] = 0; n         if (p == 0) { n           if (p + 1 < n && seg[p + 1] == -1) { n             curr++; n           } else if (n == 1) { n             curr++; n           } n         } else if (p == n - 1) { n           if (p - 1 >= 0 && seg[p - 1] == -1) { n             curr++; n           } else if (n == 1) { n             curr++; n           } n         } else { n           if (seg[p - 1] == 0 && seg[p + 1] == 0) { n             curr--; n           } else if (seg[p - 1] == -1 && seg[p + 1] == -1) { n             curr++; n           } n         } n       } n     } n   } n } n int main() { n   int t = 1; n   while (t--) { n     Solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e4 + 5; n char s[N]; n int dp[10][N]; n int ans[N]; n int len; n int dfs(int num, int idx) { n   if (~dp[num][idx]) return dp[num][idx]; n   if (idx == len) n     return 1; n   else if (idx > len) n     return 0; n   int &ret = dp[num][idx]; n   ret = dfs(num ^ 1, idx + num); n   bool flag = false; n   for (int i = idx; i < idx + num; ++i) { n     if (s[i] != s[i + num]) { n       flag = true; n       break; n     } n   } n   if (flag) { n     ret = max(ret, dfs(num, idx + num)); n   } n   return ret; n } n const int B = 333; n int cal(char a, char b, char c) { return a * B * B + b * B + c; } n int cal(char a, char b) { return a * B * B + b * B; } n void prt(int x) { n   printf( %c , x / (B * B)); n   printf( %c , x % (B * B) / B); n   if (x % B) { n     printf( %c , x % B); n   } n   puts(  ); n } n int main() { n   while (~scanf( %s , s)) { n     memset(dp, -1, sizeof(dp)); n     int cnt = 0; n     len = strlen(s); n     for (int i = len - 2; i >= 5; --i) { n       if (dfs(2, i) == 1) { n         ans[cnt++] = (cal(s[i], s[i + 1])); n       } n       if (dfs(3, i) == 1) { n         ans[cnt++] = (cal(s[i], s[i + 1], s[i + 2])); n       } n     } n     sort(ans, ans + cnt); n     cnt = unique(ans, ans + cnt) - ans; n     printf( %d n , cnt); n     for (int i = 0; i < cnt; ++i) { n       prt(ans[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int mod = 1e9 + 7; n const int N = 100 + 10; n inline int add(int x, int y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline int mul(int x, int y) { n   x = (1LL * x * y) % mod; n   return x; n } n vector<pair<int, int> > G[N]; n int dp[N][N][30][2]; n int f(int i, int j, int last, int turn) { n   int &ret = dp[i][j][last][turn]; n   if (~ret) return ret; n   ret = 0; n   if (turn == 1) { n     for (auto it : G[i]) { n       int nxt = it.first; n       int ed = it.second; n       if (ed >= last) { n         int x = f(nxt, j, ed, 0); n         if (x == 0) return ret = 1; n       } n     } n   } else { n     for (auto it : G[j]) { n       int nxt = it.first; n       int ed = it.second; n       if (ed >= last) { n         int x = f(i, nxt, ed, 1); n         if (x == 0) return ret = 1; n       } n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   memset(dp, -1, sizeof(dp)); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i <= m - 1; ++i) { n     int u, v; n     cin >> u >> v; n     char c; n     cin >> c; n     int x = c -  a ; n     G[u].push_back({v, x}); n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       int curr = f(i, j, 0, 1); n       if (curr == 0) n         cout <<  B ; n       else n         cout <<  A ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n const int N = 1e5 + 5; n  n struct query { n  int i, type, l, r, k, p, x; n }; n  n int n, m; n vector<int> a, _a; n query q[N]; n int queryCnt; n int block_size; n int ans[N]; n int freqA[N]; n int freqL[N], freqR[N], freqV[N]; n  n void increaseFreq(int f) { n  freqR[f]++, freqL[f - 1]++, freqV[freqR[f] - 1] = f; n } n  n void decreaseFreq(int f) { n  freqR[f]--, freqL[f - 1]--, freqV[freqR[f]] = f - 1; n } n  n void include(int i) { n  increaseFreq(++freqA[a[i]]); n } n  n void remove(int i) { n  decreaseFreq(freqA[a[i]]--); n } n  n void go(int& fromL, int& fromR, int toL, int toR) { n  // debug() << name(fromL) name(fromR) name(toL) name(toR); n  while (fromL > toL) include(--fromL); n  while (fromR < toR) include(fromR++); n  while (fromL < toL) remove(fromL++); n  while (fromR > toR) remove(--fromR); n } n  n void update(int qi, int L, int R) { n  if (L <= q[qi].p && q[qi].p < R) remove(q[qi].p); n  a[q[qi].p] = q[qi].x; n  if (L <= q[qi].p && q[qi].p < R) include(q[qi].p); n } n  n int answer(int k) { n  vector<pair<int, int>> v; n  for (int at = freqV[1]; at != 0; ) { n   v.push_back({at, freqR[at] - freqL[at]}); n   at = freqV[freqR[at]]; n  } n  reverse(v.begin(), v.end()); n   n  int ret = -1; n  for (int l = 0, r = 0, cnt = 0; l < v.size(); cnt -= v[l++].second) { n   r = max(l, r); n   while (r < v.size() && cnt < k) cnt += v[r++].second; n   if (cnt >= k) { n    int _ret = v[r - 1].first - v[l].first; n    ret = ret == -1 ? _ret : min(ret, _ret); n   } n  } n     // debug() << name(k) name(v) name(ret); n   n  return ret; n } n  n int main() { n  scanf( %d %d , &n, &m); n  _a.resize(n + 1); n  for (int i = 1; i <= n; i++) scanf( %d , &_a[i]); a = _a; n  for (int i = 1; i <= m; i++) { n   q[i].i = i; n   scanf( %d , &q[i].type); n   if (q[i].type == 1) scanf( %d %d %d , &q[i].l, &q[i].r, &q[i].k); n   else scanf( %d %d , &q[i].p, &q[i].x); n   queryCnt += q[i].type == 1; n  } n   n  block_size = ceil(cbrt((long double)2 * n * n)); n   n  sort(q + 1, q + m + 1, [](const query& q1,const query& q2) { n   int l1 = (q1.l - 1) / block_size, r1 = (q1.r - 1) / block_size; n   int l2 = (q2.l - 1) / block_size, r2 = (q2.r - 1) / block_size; n   auto p1 = make_pair(l1, r1); n   auto p2 = make_pair(l2, r2); n    n   if (q1.type == 1) { n    if (q2.type == 1) return make_pair(p1, q1.i) < make_pair(p2, q2.i); n    else return true; n   } else { n    if (q2.type == 1) return false; n    else return q1.i < q2.i; n   } n  }); n   n  // for (int i = 1; i <= m; i++) debug() << name(i) name(q[i].type) name(q[i].i); n   n  fill(ans, ans + N, -2); n  fill(freqL, freqL + N, 1); n  fill(freqR, freqR + N, 1); n  freqR[0] = N; n   n  pair<int, int> qp = {-1, -1}; n  int qAt; n  int L = 1, R = 1; n  for (int i = 1; i <= m && q[i].type == 1; i++) { n   int ql = (q[i].l - 1) / block_size, qr = (q[i].r - 1) / block_size; n   pair<int, int> _qp = {ql, qr}; n   if (qp != _qp) { n    go(L, R, block_size * ql + 1, block_size * ql + 1); n    a = _a; n    qAt = queryCnt + 1; n    qp = _qp; n   } n    n   while (qAt <= m && q[qAt].i < q[i].i) { n    update(qAt, L, R); n    qAt++; n   } n    n   go(L, R, q[i].l, q[i].r + 1); n    n   // debug() << name(q[i].i); n   ans[q[i].i] = answer(q[i].k); n  } n   n  for (int i = 1; i <= m; i++) if (ans[i] >= -1) printf( %d n , ans[i]); n   n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n pair<long long, pair<long long, long long> > stree[4000005]; n char sa[1000005]; n void build(long long node, long long start, long long end) { n   if (start == end) { n     stree[node].first = 0; n     stree[node].second.first = 0; n     stree[node].second.second = 0; n     if (sa[start] ==  ( ) n       stree[node].second.first = 1; n     else if (sa[start] ==  ) ) n       stree[node].second.second = 1; n   } else { n     long long mid = (start + end) / 2; n     build(2 * node, start, mid); n     build(2 * node + 1, mid + 1, end); n     long long com = n         min(stree[2 * node].second.first, stree[2 * node + 1].second.second); n     long long left = n         stree[2 * node].second.first + stree[2 * node + 1].second.first - com; n     long long right = n         stree[2 * node].second.second + stree[2 * node + 1].second.second - com; n     stree[node].first = stree[2 * node].first + stree[2 * node + 1].first + com; n     stree[node].second.first = left; n     stree[node].second.second = right; n   } n } n pair<long long, pair<long long, long long> > query(long long node, n                                                    long long start, n                                                    long long end, long long l, n                                                    long long r) { n   if (l > end || start > r) return make_pair(0, make_pair(0, 0)); n   if (l <= start && r >= end) return stree[node]; n   long long mid = (start + end) / 2; n   pair<long long, pair<long long, long long> > p1 = n       query(2 * node, start, mid, l, r); n   pair<long long, pair<long long, long long> > p2 = n       query(2 * node + 1, mid + 1, end, l, r); n   long long a = min(p1.second.first, p2.second.second); n   long long b = p1.second.first + p2.second.first - a; n   long long c = p1.second.second + p2.second.second - a; n   return make_pair(p1.first + p2.first + a, make_pair(b, c)); n } n int main() { n   string str; n   cin >> str; n   long long n, q; n   n = str.length(); n   cin >> q; n   for (long long i = 1; i <= n; i++) sa[i] = str[i - 1]; n   build(1, 1, n); n   while (q-- != 0) { n     long long x, y; n     cin >> x >> y; n     long long ans = 2 * query(1, 1, n, x, y).first; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t, ss, tt; n   int bc; n   vector<int> res; n   cin >> bc >> s >> t; n   ss = s; n   tt = t; n   sort(ss.begin(), ss.end()); n   sort(tt.begin(), tt.end()); n   if (ss != tt) { n     cout << -1; n     return 0; n   } n   if (!is_permutation(s.begin(), s.end(), t.begin())) return cout << -1, 0; n   for (int i = 0; i < t.size(); ++i) { n     for (int j = i; j < s.size(); ++j) n       if (t[t.size() - i - 1] == s[j]) { n         res.insert(res.end(), {(int)s.size(), j, 1}); n         reverse(s.begin() + j, s.end()); n         rotate(s.begin(), s.begin() + s.size() - 1, s.end()); n         break; n       } n   } n   cout << res.size() <<   n ; n   for (int i = 0; i < res.size(); i++) { n     cout << res[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n typename T::value_type arr_sum(const T& v, int n) { n   typename T::value_type sum = 0; n   for (int i = 0; i < n; ++i) sum += v[i]; n   return sum; n } n struct Sync_stdio { n   Sync_stdio() { n     cin.tie(NULL); n     ios_base::sync_with_stdio(false); n   } n } _sync_stdio; n int n, m; n vector<string> w(n); n void print_square(int x1, int x2, int y1, int y2) { n   for (int i = x1; i < x2 + 1; ++i) { n     if (w[i][y1] !=  w ) { n       w[i][y1] =  + ; n     } n     if (w[i][y2] !=  w ) { n       w[i][y2] =  + ; n     } n   } n   for (int i = y1; i < y2 + 1; ++i) { n     if (w[x1][i] !=  w ) { n       w[x1][i] =  + ; n     } n     if (w[x2][i] !=  w ) { n       w[x2][i] =  + ; n     } n   } n   for (auto i : w) { n     cout << i <<   n ; n   } n   exit(0); n } n void check1(vector<pair<int, int> >& v) { n   int max1 = -1, min1 = 100001; n   int max2 = -1, min2 = 100001; n   for (int i = 0; i < v.size(); ++i) { n     max1 = max(max1, v[i].first); n     min1 = min(min1, v[i].first); n     max2 = max(max2, v[i].second); n     min2 = min(min2, v[i].second); n   } n   int left = 0, up = 0, right = 0, down = 0; n   for (int i = 0; i < v.size(); ++i) { n     if (v[i].first == min1 && min2 < v[i].second && v[i].second < max2) { n       up = 1; n     } n     if (v[i].first == max1 && min2 < v[i].second && v[i].second < max2) { n       down = 1; n     } n     if (v[i].second == min2 && min1 < v[i].first && v[i].first < max1) { n       left = 1; n     } n     if (v[i].second == max2 && min1 < v[i].first && v[i].first < max1) { n       right = 1; n     } n     if (min1 < v[i].first && v[i].first < max1 && min2 < v[i].second && n         v[i].second < max2) { n       cout << -1; n       exit(0); n     } n   } n   if (max1 == min1) { n     up = 0; n     down = 0; n   } n   if (min2 == max2) { n     left = 0; n     right = 0; n   } n   if (max1 - min1 == max2 - min2) { n     print_square(min1, max1, min2, max2); n   } n   if (up && down && left && right) { n     cout << -1; n     exit(0); n   } n   int diff = (max1 - min1) - (max2 - min2); n   if (diff > 0) { n     if (!left && max2 + (min1 - max1) >= 0) { n       print_square(min1, max1, max2 + (min1 - max1), max2); n     } n     if (!right && min2 + (max1 - min1) < m) { n       print_square(min1, max1, min2, min2 + (max1 - min1)); n     } n     if (!left && !right && max1 - min1 < m) { n       print_square(min1, max1, 0, max1 - min1); n     } n   } n   if (diff < 0) { n     if (!up && max1 + (min2 - max2) >= 0) { n       print_square(max1 + (min2 - max2), max1, min2, max2); n     } n     if (!down && min1 + (max2 - min2) < n) { n       print_square(min1, min1 + (max2 - min2), min2, max2); n     } n     if (!up && !down && max2 - min2 < n) { n       print_square(0, max2 - min2, min2, max2); n     } n   } n   cout << -1; n   exit(0); n } n int main() { n   cin >> n >> m; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; ++i) { n     string t; n     cin >> t; n     w.push_back(t); n     for (int j = 0; j < m; ++j) { n       if (t[j] ==  w ) { n         v.push_back({i, j}); n       } n     } n   } n   check1(v); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int q; n   cin >> q; n   while (q--) { n     ll a, b, m; n     cin >> a >> b >> m; n     if (a == b) { n       cout << 1 <<     << a <<   n ; n       continue; n     } n     bool f = false; n     for (int k = 1; k <= 49 && (1ll << (k - 1)) <= b / a; k++) { n       ll t = (1ll << (k - 1)) * a; n       ll b_tmp = b - t; n       vector<ll> rs(k + 1); n       rs[0] = a; n       for (int cur = 1; cur <= k; cur++) { n         ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1)); n         rs[cur] = 1; n         b_tmp -= pw * rs[cur]; n       } n       if (b_tmp < 0) { n         continue; n       } n       for (int cur = 1; cur <= k; cur++) { n         ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1)); n         ll now = min(m - 1, b_tmp / pw); n         b_tmp -= pw * now; n         rs[cur] += now; n       } n       if (b_tmp == 0) { n         f = true; n         cout << k + 1 <<    ; n         vector<ll> ans; n         for (int i = 0; i <= k; i++) { n           ll cur = rs[i]; n           for (int j = i - 1; j >= 0; j--) { n             cur += ans[j]; n           } n           ans.push_back(cur); n           cout << cur <<    ; n         } n         cout <<   n ; n         break; n       } n     } n     if (!f) cout << -1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string s) { n   string t = s; n   reverse(t.begin(), t.end()); n   return (s == t); n } n int main() { n   string s; n   cin >> s; n   int l = 0, r = ((int)s.length()) - 1; n   set<char> all; n   while (l < r) { n     all.insert(s[l]); n     all.insert(s[r]); n     l++; n     r--; n   } n   if (all.size() <= 1) { n     cout <<  Impossible  << endl; n     return 0; n   } n   for (int i = 0; i < ((int)s.length()) - 1; i++) { n     string fi =   , se =   ; n     for (int j = 0; j <= i; j++) fi += s[j]; n     for (int j = i + 1; j < (int)s.length(); j++) se += s[j]; n     if (check(se + fi) && (se + fi != s)) { n       cout << 1 << endl; n       return 0; n     } n   } n   cout << 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T MAX(T a, T b) { n   if (a > b) return a; n   return b; n } n template <class T> n inline T MIN(T a, T b) { n   if (a < b) return a; n   return b; n } n template <class T> n inline T ABS(T x) { n   if (x < 0) return -x; n   return x; n } n inline void OPEN(const string &s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n const static int inf = 1000000000; n int n, m, x, y, z, p; n int a, b; n vector<pair<int, int> > cek; n void rotate90(int &a, int &b, int &r, int &c) { n   int tempa = a; n   int tempb = b; n   a = tempb; n   b = r - tempa + 1; n   swap(r, c); n } n void flipH(int &a, int &b, int &r, int &c) { b = c - b + 1; } n void rotate(int &a, int &b, int &r, int &c) { n   int tempa = a; n   int tempb = b; n   a = c - tempb + 1; n   b = tempa; n   swap(r, c); n } n int main() { n   scanf( %d%d%d%d%d%d , &n, &m, &x, &y, &z, &p); n   for (int(i) = (0); (i) < (p); ++(i)) { n     scanf( %d%d , &a, &b); n     cek.push_back(make_pair(a, b)); n   } n   x %= 4; n   z %= 4; n   y %= 2; n   for (int(i) = (0); (i) < (cek.size()); ++(i)) { n     a = cek[i].first; n     b = cek[i].second; n     int r = n, c = m; n     for (int(j) = (0); (j) < (x); ++(j)) rotate90(a, b, r, c); n     for (int(j) = (0); (j) < (y); ++(j)) flipH(a, b, r, c); n     for (int(j) = (0); (j) < (z); ++(j)) rotate(a, b, r, c); n     printf( %d %d n , a, b); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}; n const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; n int n, pre = 0; n int a[1005], b[1005], p[1005]; n vector<int> num; n bool vis[1005]; n bool valid() { n   int na = 0; n   set<int> st; n   for (int j = 0; j < n; ++j) { n     if (a[j] == p[j]) ++na; n     st.insert(p[j]); n   } n   return ((st.size()) == n && na == n - 1); n } n int main() { n   int v; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &b[i]); n     p[i] = b[i]; n     if (vis[p[i]]) v = p[i]; n     vis[p[i]] = 1; n   } n   vis[v] = 0; n   for (int i = 0; i < n; ++i) n     if (b[i] == v) num.push_back(i); n   int tmp1 = p[num[0]], tmp2 = p[num[1]]; n   for (int j = 1; j <= n; ++j) { n     if (!vis[j]) { n       vis[j] = 1; n       p[num[0]] = j; n       for (int k = 1; k <= n; ++k) { n         if (!vis[k]) { n           vis[k] = 1; n           p[num[1]] = k; n           break; n         } n       } n       if (valid()) n         break; n       else { n         vis[p[num[0]]] = vis[p[num[1]]] = 0; n         p[num[0]] = tmp1; n         p[num[1]] = tmp2; n       } n     } n   } n   for (int i = 0; i < n; ++i) printf( %d  , p[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   if (n % 2 == 0) { n     for (int i = 0; i < n - 2; i++) { n       cout << s[i]; n       if (i % 2) { n         cout <<  - ; n       } n     } n     cout << s[n - 2] << s[n - 1]; n   } n   if (n % 2) { n     for (int i = 0; i < n - 3; i++) { n       cout << s[i]; n       if (i % 2) { n         cout <<  - ; n       } n     } n     cout << s[n - 3] << s[n - 2] << s[n - 1]; n   } n } n


#include <bits/stdc++.h> n int C[100005], D[505][505], L[100005], R[100005], Par[100005]; n int N, K, M; n using namespace std; n int find(int n) { n   if (Par[n] == n) n     return n; n   else n     return Par[n] = find(Par[n]); n } n void join(int a, int b) { Par[find(a)] = find(b); } n int main() { n   cin >> N >> M >> K; n   for (int i = 1; i <= K; i++) { n     int x; n     cin >> x; n     L[i] = R[i - 1] + 1; n     R[i] = L[i] + x - 1; n     for (int p = L[i]; p <= R[i]; p++) C[p] = i; n   } n   for (int i = 1; i <= N; i++) Par[i] = i; n   for (int i = 1; i <= K; i++) { n     for (int j = 1; j <= K; j++) D[i][j] = 1000000005; n     D[i][i] = 0; n   } n   while (M--) { n     int a, b, d; n     cin >> a >> b >> d; n     if (d == 0) join(a, b); n     D[C[a]][C[b]] = min(D[C[a]][C[b]], d); n     D[C[b]][C[a]] = min(D[C[b]][C[a]], d); n   } n   for (int i = 1; i <= K; i++) n     for (int p = L[i]; p <= R[i]; p++) n       if (find(p) != find(L[i])) { n         cout <<  No ; n         return 0; n       } n   for (int k = 1; k <= K; k++) n     for (int i = 1; i <= K; i++) n       for (int j = 1; j <= K; j++) D[i][j] = min(D[i][j], D[i][k] + D[k][j]); n   cout <<  Yes n ; n   for (int i = 1; i <= K; i++) { n     for (int j = 1; j <= K; j++) { n       if (D[i][j] < 1000000005) n         cout << D[i][j] <<    ; n       else n         cout <<  -1  ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> g[100001], vc; n int judge(int x) { n   vc.clear(); n   int need = x - g[0].size(), ans = 0; n   for (int i = 1; i < 100001; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       if (g[i].size() - j >= x) { n         need--; n         ans += g[i][j]; n       } else n         vc.push_back(g[i][j]); n     } n   } n   sort(vc.begin(), vc.end()); n   for (int i = 0; i < need; i++) ans += vc[i]; n   return ans; n } n int main() { n   scanf( %d , &n); n   int a, b; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &a, &b); n     g[a].push_back(b); n   } n   for (int i = 1; i < 100001; i++) { n     sort(g[i].begin(), g[i].end()); n   } n   int l = g[0].size(), r = n; n   while (l < r) { n     int mid = (l + l + r) / 3, mmid = (l + r + r) / 3; n     if (judge(mid) > judge(mmid)) { n       if (l == mid) n         break; n       else n         l = mid; n     } else { n       if (r == mmid) n         break; n       else n         r = mmid; n     } n   } n   int ans = 0x3f3f3f3f; n   for (int i = l; i <= r; i++) ans = min(ans, judge(i)); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y, z; n   int sum1 = 0, sum2 = 0, sum3 = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y >> z; n     sum1 += x; n     sum2 += y; n     sum3 += z; n   } n   if ((sum1 == 0) && (sum2 == 0) && (sum3 == 0)) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, n; n void solve() { n   int n; n   long long l; n   cin >> n >> l; n   long long a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   ; n   sort(a, a + n); n   long long m = 2 * max(a[0], l - a[n - 1]); n   for (i = 0; i < n - 1; i++) { n     m = max(m, a[i + 1] - a[i]); n   } n   long double d = 1.0 * m / 2; n   cout << setprecision(9) << d; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n const int maxd = 205; n struct Node { n   int l, d; n } leg[maxn]; n bool operator<(const Node &a, const Node &b) { return a.l > b.l; } n int n, tot[maxd], td = 0, md = 0; n int Solve(int st, int ed) { n   int cnt = ed - st; n   int res = td; n   for (int i = md; i >= 0 && cnt > 0; i--) { n     res -= min(cnt, tot[i]) * i; n     cnt -= min(cnt, tot[i]); n   } n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> leg[i].l; n   for (int i = 0; i < n; i++) cin >> leg[i].d; n   for (int i = 0; i < n; i++) md = max(md, leg[i].d); n   sort(leg, leg + n); n   for (int i = 0; i < n; i++) { n     tot[leg[i].d]++; n     td += leg[i].d; n   } n   int p = 0; n   int res = INT_MAX, tot_d = 0; n   while (p < n) { n     int p1 = p + 1; n     while (p1 < n && leg[p1].l == leg[p].l) p1++; n     p1--; n     for (int i = p; i <= p1; i++) { n       tot[leg[i].d]--; n       td -= leg[i].d; n     } n     int tmp = tot_d + Solve(p, p1); n     res = min(tmp, res); n     for (int i = p; i <= p1; i++) tot_d += leg[i].d; n     p = p1 + 1; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   register long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n const long long N = 1e5 + 10; n long long n, m, k, p; n long long h[N], a[N]; n long long c[N]; n struct node { n   long long t, id; n   bool operator<(const node& x) const { return t > x.t; } n }; n priority_queue<node> q; n bool check(long long x) { n   while (!q.empty()) q.pop(); n   memset(c, 0, sizeof c); n   for (long long i = 1; i <= n; i++) n     if (x - a[i] * m < h[i]) q.push((node){x / a[i], i}); n   for (long long i = 1; !q.empty() && i <= m; i++) n     for (long long j = 1; !q.empty() && j <= k; j++) { n       node u = q.top(); n       q.pop(); n       if (u.t < i) return 0; n       ++c[u.id]; n       if (x + c[u.id] * p - a[u.id] * m < h[u.id]) n         q.push((node){(x + c[u.id] * p) / a[u.id], u.id}); n     } n   return q.empty(); n } n signed main() { n   n = read(), m = read(), k = read(), p = read(); n   for (long long i = 1; i <= n; i++) h[i] = read(), a[i] = read(); n   long long l = 0, r = 1e15, ans; n   while (l <= r) { n     long long mid = l + r >> 1; n     if (check(mid)) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int idx, val; n   bool operator<(const data &a1) const { n     if (a1.val == val) { n       return a1.idx < idx; n     } n     return val > a1.val; n   } n   data(int t, int w) : idx(t), val(w) {} n }; n set<data> coastline; n set<data>::iterator it, it2; n int main() { n   int N; n   scanf( %d , &N); n   string ans[N]; n   int a; n   for (int i = 0; i < N; i++) { n     scanf( %d , &a); n     if (a == 0) { n       int sz = coastline.size(); n       if (sz == 0) { n         ans[i] =  0 ; n       } else if (sz == 1) { n         ans[i] =  1 popStack ; n         it = coastline.begin(); n         ans[it->idx] =  pushStack ; n       } else if (sz == 2) { n         ans[i] =  2 popStack popQueue ; n         it = coastline.begin(); n         ans[it->idx] =  pushQueue ; n         it++; n         ans[it->idx] =  pushStack ; n         it++; n       } else { n         ans[i] =  3 popStack popQueue popFront ; n         it = coastline.begin(); n         ans[it->idx] =  pushFront ; n         it++; n         ans[it->idx] =  pushQueue ; n         it++; n         ans[it->idx] =  pushStack ; n         it++; n       } n       coastline.clear(); n     } else { n       coastline.insert(data(i, a)); n     } n   } n   for (int i = 0; i < N; i++) { n     if (ans[i].size() == 0) { n       cout <<  pushBack  << endl; n     } else n       cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n #define mod 1000000007 n using namespace std; n  n ll dp[10][200001]; n string s =  abcdefghijklmnopqrstuvwxyz ; n ll findgcd(ll a, ll b) { n     if (b == 0) { n         return a; n     } n     return findgcd(b, a % b); n } n  n bool ispalindrome(string s) { n     int n = s.length(); n     bool flag = true; n     for (int i = 0; i < n / 2; i++) { n         if (s[i] != s[n - 1 - i]) { n             flag = false; n             break; n         } n     } n     return flag; n } n  n ll factorial(ll n) { n     vector<ll> v(n + 1); n     for (ll i = 0; i <= n; i++) { n         if (i == 0 || i == 1) { n             v[i] = 1; n         } n         else { n             v[i] = (i * v[i - 1]) % mod; n         } n     } n     return v[n]; n } n  n void calculatedp() { n     for (ll i = 0; i <= 9; i++) { n         ll temp = 10 - i; n         for (ll j = 0; j <= 200000; j++) { n             if (j < temp) { n                 dp[i][j] = 1; n             } n             else if (j == temp) { n                 dp[i][j] = 2; n             } n             else { n                 break; n             } n         } n     } n     dp[1][10] = 2; n     for (ll i = 11; i <= 200000; i++) { n         int temp1 = i - 10; n         int temp2 = i - 9; n         dp[0][i] = (dp[0][temp1] + dp[1][temp1]) % mod; n         dp[1][i] = (dp[0][temp2] + dp[1][temp2]) % mod; n     } n     for (ll i = 2; i <= 9; i++) { n         ll temp = 10 - i; n         for (ll j = temp + 1; j <= 200000; j++) { n             dp[i][j] = (dp[0][j - temp] + dp[1][j - temp]) % mod; n         } n     } n } n  n void solve() { n     // ll m; n     // cin >> s; n     // cin >> m; n     // ll ans = 0; n     // for (int i = 0; i < s.length(); i++) { n     //     ans = (ans + (dp[s[i] -  0 ][m])) % mod; n     // } n     // cout << ans <<   n ; n     int n, k; n     cin >> n >> k; n  n     string ans =   ; n  n     for (int i = 0 ; i < k ; i++) { n         ans += s[i]; n         for (int j = i + 1 ; j < k ; j++) { n             ans += s[i]; n             ans += s[j]; n         } n     } n  n     if (n < ans.size()) { n         cout << ans.substr(0, n) << endl; n     } n     else { n         int j = ans.length(); n         int i = 0; n         while (j < n) { n             ans += ans[i]; n             i++; n             j++; n         } n  n         cout << ans << endl; n     } n } n int main() { n #ifndef ONLINE_JUDGE n     //for getting input from input.txt n     freopen( input.txt ,  r , stdin); n     //for writing output to output.txt n     freopen( output.txt ,  w , stdout); n #endif n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n     // calculatedp(); n     // for (int i = 0; i <= 10; i++) { n     //     for (int j = 0; j <= 10; j++) { n     //         cout << dp[i][j] <<    ; n     //     } n     //     cout <<   n ; n     // } n     int t; n     t = 1; n     // cin >> t; n     while (t--) { n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline int popcount(T t) { n   if (std::numeric_limits<T>::digits <= n       std::numeric_limits<unsigned int>::digits) { n     return __builtin_popcount(t); n   } else { n     return __builtin_popcountll(t); n   } n } n const long double EPS = 1e-8; n const long double PI = acosl(0.0) * 2; n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < int(n); ++i) cin >> a[i]; n   for (int i = 30; i >= 0; --i) { n     vector<int> b; n     int mask = (1 << i) - 1; n     for (int x : a) { n       if ((x >> i) & 1) { n         b.push_back(x); n         mask &= x; n       } n     } n     if (!mask) { n       cout << b.size() << endl; n       for (int x : b) { n         cout << x <<    ; n       } n       cout << endl; n       return; n     } n   } n   assert(false); n } n int main() { n   ios_base::sync_with_stdio(false); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2, n3, n4; n   long long ans; n   unordered_map<char, int> m; n   string s; n   while (cin >> n1 >> n2 >> n3 >> n4) { n     ans = 0; n     m[ 1 ] = n1; n     m[ 2 ] = n2; n     m[ 3 ] = n3; n     m[ 4 ] = n4; n     cin >> s; n     for (int i = 0; i < s.size(); i++) { n       ans += m[s[i]]; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(double a, double b) { return a > b; } n int n; n double a[110], x, sum, ans; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %lf , &a[i]); n   sort(a, a + n, cmp); n   ans = 0; n   for (int i = 1; i <= n; i++) { n     sum = 0; n     for (int j = 0; j < i; j++) { n       x = a[j]; n       for (int k = 0; k < i; k++) { n         if (j != k) x *= 1 - a[k]; n       } n       sum += x; n     } n     ans = max(sum, ans); n   } n   printf( %.12lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[200][3]; n int main() { n   ios ::sync_with_stdio(false); n   cin.tie(0); n   ; n   long long int i, k, l, n, j; n   cin >> n; n   for (i = 0; i <= n - 1; i++) cin >> a[i][0] >> a[i][1]; n   cin >> j; n   for (i = 0; i <= n - 1; i++) n     if (j >= a[i][0] && j <= a[i][1]) { n       cout << n - i << endl; n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n string S; n int vis[5050][5050]; n vector<pair<int, int>> nex[26]; n void dfs(int cur, int mask) { n   if (vis[cur][mask] || cur + 1 + mask > N) return; n   vis[cur][mask] = 1; n   int i; n   nex[S[cur] -  a ].push_back({cur + 1, mask}); n   for (i = 0; i < (K); i++) n     if (mask & (1 << i)) dfs(cur + (1 << i), mask ^ (1 << i)); n } n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> S; n   N = S.size(); n   while (1 << (K + 1) <= N) K++; n   vector<pair<int, int>> now; n   now.push_back({0, (1 << K) - 1}); n   while (now.size()) { n     for (i = 0; i < (26); i++) nex[i].clear(); n     for (auto& n : now) dfs(n.first, n.second); n     char c =  z  + 1; n     for (i = 25; i >= 0; i--) n       if (nex[i].size()) c =  a  + i; n     if (c ==  z  + 1) break; n     cout << c; n     swap(now, nex[c -  a ]); n   } n   cout << endl; n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<double, double> get_vec_rotate(pair<double, double> nv, double fi) { n   return make_pair(nv.first * cos(fi) - nv.second * sin(fi), n                    nv.second * cos(fi) + nv.first * sin(fi)); n } n pair<double, double> get_normal(pair<double, double> vec) { n   double len = sqrt(vec.first * vec.first + vec.second * vec.second); n   vec.first /= len; n   vec.second /= len; n   return vec; n } n pair<double, double> end_p(pair<double, double> start_p, n                            pair<double, double> nv, double len) { n   nv.first *= len; n   nv.second *= len; n   return make_pair(nv.first + start_p.first, nv.second + start_p.second); n } n double a, b, c, d; n pair<double, double> p, v, ToWrite; n pair<double, double> len_fi[7]; n int main() { n   cin >> p.first >> p.second >> v.first >> v.second >> a >> b >> c >> d; n   v = get_normal(v); n   len_fi[0].first = b; n   len_fi[0].second = 0; n   len_fi[1].first = a / 2; n   len_fi[1].second = M_PI / 2; n   len_fi[2].first = c / 2; n   len_fi[2].second = M_PI / 2; n   len_fi[3].first = sqrt(c * c + 4 * d * d) / 2; n   len_fi[3].second = M_PI / 2 + atan(2 * d / c); n   len_fi[4].first = sqrt(c * c + 4 * d * d) / 2; n   len_fi[4].second = 3 * M_PI / 2 - atan(2 * d / c); n   len_fi[5].first = c / 2; n   len_fi[5].second = 3 * M_PI / 2; n   len_fi[6].first = a / 2; n   len_fi[6].second = 3 * M_PI / 2; n   cout.precision(10); n   for (int i = 0; i < 7; i++) { n     ToWrite = end_p(p, get_vec_rotate(v, len_fi[i].second), len_fi[i].first); n     cout << fixed << ToWrite.first <<     << ToWrite.second << endl; n   } n   return 0; n } n