#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n + 1]; n   vector<int> g[n + 1]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   set<pair<int, int> > last; n   int k = 0; n   for (int i = 1; i <= n; i++) { n     set<pair<int, int> >::iterator it = last.lower_bound(make_pair(a[i], 1)); n     if (it == last.begin()) { n       g[++k].push_back(a[i]); n       last.insert(make_pair(a[i], k)); n     } else { n       --it; n       g[it->second].push_back(a[i]); n       last.erase(it); n       last.insert(make_pair(a[i], it->second)); n     } n   } n   for (int i = 1; i <= k; i++) { n     for (int j : g[i]) { n       cout << j <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2, k1, k2; n   cin >> n1 >> n2 >> k1 >> k2; n   if (n1 > n2) { n     cout <<  First ; n   } else { n     cout <<  Second ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 33333; n const int mod = 998244353, G = 3; n int n, k, T, a[MAXN], W, rev[MAXN], gen[MAXN]; n vector<int> vec[MAXN]; n inline int qpow(int a, int b) { n   int re = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) re = 1ll * re * a % mod; n   return re; n } n inline int pls(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } n inline void add(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; } n void NTT(vector<int> &arr, int len, int flg) { n   for (int i = 0; i < len; ++i) n     if (i < rev[i]) swap(arr[i], arr[rev[i]]); n   for (int v, i = 2, B = W >> 1; i <= len; i <<= 1, B >>= 1) n     for (int j = 0; j < len; j += i) n       for (int k = j, x = 0; k < j + i / 2; ++k, x += B) n         arr[k + i / 2] = pls( n             arr[k], n             mod - (v = 1ll * arr[k + i / 2] * gen[flg == 1 ? x : W - x] % mod)), n                     add(arr[k], v); n   if (flg == -1) { n     int iv = qpow(len, mod - 2); n     for (int i = 0; i < len; ++i) arr[i] = 1ll * arr[i] * iv % mod; n   } n } n vector<int> solve(int l, int r) { n   if (l == r) return vec[l]; n   int mid = (l + r) >> 1; n   vector<int> L = solve(l, mid), R = solve(mid + 1, r); n   int len = 1; n   while (len <= r - l + 1) len <<= 1; n   for (int i = 1; i < len; ++i) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (len >> 1)); n   L.resize(len), R.resize(len); n   NTT(L, len, 1), NTT(R, len, 1); n   for (int i = 0; i < len; ++i) L[i] = 1ll * L[i] * R[i] % mod; n   NTT(L, len, -1); n   L.resize(r - l + 2); n   return L; n } n int main() { n   scanf( %d%d , &n, &k); n   for (W = 1; W <= n; W <<= 1) n     ; n   gen[0] = 1, gen[1] = qpow(G, (mod - 1) / W); n   for (int i = 2; i <= W; ++i) gen[i] = 1ll * gen[i - 1] * gen[1] % mod; n   for (int i = 1; i <= n; ++i) n     scanf( %d , &a[i]), vec[i].resize(2), vec[i][0] = 1; n   int op, q, x, y, d; n   for (scanf( %d , &T); T--;) { n     scanf( %d%d%d , &op, &q, &x); n     if (op == 2) n       scanf( %d , &y); n     else n       y = x; n     scanf( %d , &d); n     for (int i = 1; i <= n; ++i) n       vec[i][1] = n           ((q - ((x <= i && i <= y) ? (op == 1 ? d : a[i] + d) : a[i])) % mod + n            mod) % n           mod; n     vector<int> ans = solve(1, n); n     printf( %d n , ans[k]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   map<int, int> m; n   int u = 0; n   long long powers[32]; n   powers[0] = 1; n   for (int i = 1; i < 32; i++) powers[i] = 2 * powers[i - 1]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     m[a[i]]++; n   } n   bool flag = false; n   for (int i = 0; i < n; i++) { n     flag = false; n     for (int j = 0; j < 32; j++) { n       long long x = powers[j] - a[i]; n       if (m[x] > 1 || (m[x] == 1 && x != a[i])) { n         flag = true; n         break; n       } n     } n     if (!flag) u++; n   } n   cout << u << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[500010]; n int d1[500010]; n int d2[500010]; n int main() { n   int n; n   cin >> n; n   for (int i = (0); i < (int)(n); i++) cin >> arr[i]; n   int last2left = 0; n   for (int i = (1); i < (int)(n - 1); i++) { n     if (arr[i] == arr[i - 1]) { n       last2left = i; n       d1[i] = i; n     } else { n       d1[i] = last2left; n     } n   } n   last2left = n - 1; n   for (int i = (n - 1 - 1); i >= (int)(1); i--) { n     if (arr[i] == arr[i + 1]) { n       last2left = i; n       d2[i] = i; n     } else { n       d2[i] = last2left; n     } n   } n   int res = 0; n   for (int i = (1); i < (int)(n - 1); i++) n     res = max(res, min(i - d1[i], d2[i] - i)); n   cout << res << endl; n   cout << arr[0] <<    ; n   for (int i = (1); i < (int)(n - 1); i++) n     cout << ((i - d1[i] < d2[i] - i) ? arr[d1[i]] : arr[d2[i]]) <<    ; n   cout << arr[n - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string ANSWER[2] = { NO n ,  YES n }; n int v[2009], s1[2009], s2[2009]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &v[i]); n     s1[i] = s1[i - 1] + (v[i] == 1); n     s2[i] = s2[i - 1] + (v[i] == 2); n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int a = 0, b = 0; n     for (int j = i; j <= n; j++) { n       if (v[j] == 1) b++; n       if (v[j] == 2) a++; n       if (a > b) b = a; n       ans = max(ans, s1[i - 1] + b + s2[n] - s2[j]); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, n, d, x_i, y_i; n vector<pair<int, int> > v; n double dist(double x1, double y1) { return sqrt(pow(x1, 2) + pow(y1, 2)); } n int a[605][605]; n int f(int _x, int _y) { n   if (a[200 + _x][200 + _y] == -1) { n     int tmp = 1; n     if (dist(_x, _y) <= d) { n       for (auto _i : v) { n         if (f(_x + _i.first, _y + _i.second)) { n           tmp = 0; n           break; n         } n       } n     } else { n       tmp = 0; n     } n     a[200 + _x][200 + _y] = tmp; n   } n   return a[200 + _x][200 + _y]; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> x >> y >> n >> d; n   (memset(a, -1, sizeof(a))); n   for (int(i) = (0); (i) < (n); (i)++) { n     cin >> x_i >> y_i; n     v.push_back({x_i, y_i}); n   } n   cout << (!f(x, y) ?  Anton  :  Dasha ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, i, n; n   int edges[int(2e5 + 1)][2], weights[int(2e5 + 1)], freq[int(2e5 + 1)]; n   cin >> n; n   for (i = 1; i <= n; i++) freq[i] = 0; n   for (i = 0; i < n; i++) { n     weights[i] = -1; n     cin >> edges[i][0] >> edges[i][1]; n     freq[edges[i][0]]++; n     freq[edges[i][1]]++; n   } n   int maxindex = 1, k = 0; n   for (i = 1; i <= n; i++) n     if (freq[i] > freq[maxindex]) maxindex = i; n   for (i = 0; i < n; i++) n     if (edges[i][0] == maxindex or edges[i][1] == maxindex) weights[i] = k++; n   for (i = 0; i < n; i++) n     if (weights[i] == -1) weights[i] = k++; n   for (i = 0; i < n - 1; i++) cout << weights[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug() { cout << endl; } n template <typename T, typename... E> n void debug(T t, E... e) { n   cout << t << (sizeof...(e) ?     :   ); n   debug(e...); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   double p1 = double(a) / b; n   double p2 = double(c) / d; n   double ans = p1 / (1 - (1 - p1) * (1 - p2)); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n const int maxn = 2e5 + 10; n const int mod = 1e9 + 7; n const long long infll = 1e18; n const int inf = 1e9; n int lcp[40][40]; n string s[maxn]; n int32_t main() { n   int n = in(), k = in(); n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       int where = 0; n       while (where < s[i].size() && where < s[j].size() && n              s[i][where] == s[j][where]) n         where++; n       lcp[i][j] = where; n     } n   } n   int res = 0; n   for (int mask = 0; mask < (1 << n); mask++) { n     if (__builtin_popcount(mask) - k) continue; n     vector<int> Ids; n     for (int i = 0; i < n; i++) n       if (mask >> i & 1) Ids.push_back(i); n     int tot = 0; n     for (int i = 0; i < Ids.size(); i++) n       for (int j = i + 1; j < Ids.size(); j++) tot += lcp[Ids[i]][Ids[j]]; n     res = max(res, tot); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n const int N = 4005; n const int M = 80; n const int MOD = 998244353; n int m, jc[M], ny[M]; n struct Tree { n   int n, cnt, last[N], f[M][N], g[M][N], size[N], ans[M], w[N], tot, a[N], sum, n       root; n   bool vis[N]; n   struct edge { n     int to, next; n   } e[N * 2]; n   void addedge(int u, int v) { n     e[++cnt].to = v; n     e[cnt].next = last[u]; n     last[u] = cnt; n     e[++cnt].to = u; n     e[cnt].next = last[v]; n     last[v] = cnt; n   } n   void get_root(int x, int fa) { n     size[x] = 1; n     w[x] = 0; n     for (int i = last[x]; i; i = e[i].next) { n       if (e[i].to == fa || vis[e[i].to]) continue; n       get_root(e[i].to, x); n       size[x] += size[e[i].to]; n       w[x] = std::max(w[x], size[e[i].to]); n     } n     w[x] = std::max(w[x], sum - size[x]); n     if (!root || w[x] < w[root]) root = x; n   } n   void get(int x, int fa) { n     a[++tot] = x; n     size[x] = 1; n     for (int i = last[x]; i; i = e[i].next) n       if (e[i].to != fa && !vis[e[i].to]) n         get(e[i].to, x), size[x] += size[e[i].to]; n   } n   void calc(int x) { n     tot = 0; n     get(x, 0); n     f[0][x] = g[0][x] = 1; n     for (int i = 1; i <= m; i++) n       for (int j = 1; j <= tot; j++) { n         int y = a[j]; n         f[i][y] = g[i][y] = 0; n         for (int k = last[y]; k; k = e[k].next) { n           if (vis[e[k].to]) continue; n           (g[i][y] += g[i - 1][e[k].to]) %= MOD; n           if (y != x) (f[i][y] += f[i - 1][e[k].to]) %= MOD; n         } n       } n     for (int i = 1; i <= tot; i++) { n       int y = a[i]; n       if (y == x) { n         for (int j = 0; j <= m; j++) (ans[j] += g[j][x]) %= MOD; n         continue; n       } n       for (int j = 0; j <= m; j++) n         for (int k = 0; j + k <= m; k++) n           (ans[j + k] += (long long)f[j][y] * g[k][y] % MOD) %= MOD; n     } n     vis[x] = 1; n     for (int i = last[x]; i; i = e[i].next) { n       if (vis[e[i].to]) continue; n       root = 0; n       sum = size[e[i].to]; n       get_root(e[i].to, x); n       calc(root); n     } n   } n   void solve() { n     sum = n; n     root = 0; n     get_root(1, 0); n     calc(root); n   } n } t1, t2; n int C(int n, int m) { return (long long)jc[n] * ny[m] % MOD * ny[n - m] % MOD; } n int main() { n   scanf( %d%d%d , &t1.n, &t2.n, &m); n   jc[0] = jc[1] = ny[0] = ny[1] = 1; n   for (int i = 2; i <= m; i++) n     jc[i] = (long long)jc[i - 1] * i % MOD, n     ny[i] = (long long)(MOD - MOD / i) * ny[MOD % i] % MOD; n   for (int i = 2; i <= m; i++) ny[i] = (long long)ny[i - 1] * ny[i] % MOD; n   for (int i = 1; i < t1.n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     t1.addedge(x, y); n   } n   for (int i = 1; i < t2.n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     t2.addedge(x, y); n   } n   t1.solve(); n   t2.solve(); n   int s = 0; n   for (int i = 0; i <= m; i++) n     (s += (long long)t1.ans[i] * t2.ans[m - i] % MOD * C(m, i) % MOD) %= MOD; n   printf( %d , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n const long long mod2 = 998244353; n long long fpow(long long x, long long y, long long p = 1000000007) { n   x = x % p; n   long long sum = 1; n   while (y) { n     if (y & 1) sum = sum * x; n     sum %= p; n     y = y >> 1; n     x = x * x; n     x %= p; n   } n   return sum; n } n long long inv(long long a, long long m = 1000000007) { n   long long c = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += c; n   return x; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t, n; n   cin >> t; n   while (t--) { n     cin >> n; n     long long tmp = 0; n     vector<long long> v(n); n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n       tmp ^= v[i]; n     } n     if (tmp == 0) { n       cout <<  DRAW n ; n       continue; n     } n     for (long long j = 40; j >= 0; j--) { n       if ((tmp >> j) & 1) { n         long long cnt0 = 0, cnt1 = 0; n         for (int i = 0; i < n; i++) { n           if ((v[i] >> j) & 1) n             cnt1++; n           else n             cnt0++; n         } n         if (cnt0 % 2 == 0 && cnt1 % 4 == 3) { n           cout <<  LOSE n ; n         } else { n           cout <<  WIN n ; n         } n         break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int num, cnt; n   friend bool operator<(const Node &n1, const Node &n2) { n     if (n1.cnt != n2.cnt) n       return n1.cnt < n2.cnt; n     else n       return n1.num < n2.num; n   } n }; n set<Node> cur, tmp; n vector<int> xx, num; n map<int, int> mp; n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   if (x == 0 && n == 2) { n     puts( NO ); n     return 0; n   } n   while (x > 0) { n     xx.push_back(x % 2); n     x /= 2; n   } n   int sz = xx.size(); n   int pre = 0; n   cur.insert({0, n}); n   int idx = 0; n   while (true) { n     int need; n     if (idx < sz) { n       need = xx[idx]; n     } else n       need = 0; n     tmp.clear(); n     int tar = need, now = 0; n     for (auto o : cur) { n       int zc = o.num * 2, cc = o.cnt; n       if (cc / 2 > 0) tmp.insert({zc + 1, cc / 2}); n       if ((cc + 1) / 2 > 0) tmp.insert({zc, (cc + 1) / 2}); n       now ^= ((cc / 2) % 2); n     } n     if (tar != now) { n       for (auto o : cur) { n         int zc = o.num * 2, cc = o.cnt; n         if (cc == 1) { n           tmp.erase({zc, (cc + 1) / 2}); n           tmp.insert({zc + 1, cc / 2 + 1}); n         } else { n           tmp.erase({zc, (cc + 1) / 2}); n           tmp.erase({zc + 1, cc / 2}); n           if ((cc + 1) / 2 > 1) tmp.insert({zc, (cc + 1) / 2 - 1}); n           tmp.insert({zc + 1, cc / 2 + 1}); n         } n         break; n       } n     } n     cur.clear(); n     for (auto o : tmp) { n       cur.insert(o); n     } n     idx++; n     int siz = cur.size(); n     if (siz == n && idx >= sz) break; n   } n   vector<int> ans; n   bool ok = true; n   for (auto o : cur) { n     int t = o.num, res = 0; n     for (int i = 1; i <= idx; i++) { n       int now = t % 2; n       res = res * 2 + now; n       t /= 2; n     } n     ans.push_back(res); n     if (res > 1000000) { n       ok = false; n       break; n     } n   } n   if (!ok) { n     puts( NO ); n   } else { n     int ord = 0; n     puts( YES ); n     for (auto o : ans) { n       if (ord != 0) putchar(   ); n       printf( %d , o); n       ord++; n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[33], ans; n map<long long, long long> us; n int main() { n   cin >> n; n   for (long long i = 1; i <= n; ++i) cin >> a[i]; n   sort(a + 1, a + 1 + n); n   for (long long i = 1; i <= n; ++i) { n     while (us[a[i]] && a[i] > 0) a[i]--; n     ans += a[i]; n     us[a[i]] = 1; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int digit[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; n   string n; n   cin >> n; n   int a = digit[(n[1] - 48)]; n   int b = digit[(n[0] - 48)]; n   cout << a * b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> t; n int get(int a) { n   if (t[a] == a) { n     return a; n   } else { n     return t[a] = get(t[a]); n   } n } n struct kek { n   int a; n   int b; n   int c; n }; n bool operator<(kek a, kek b) { return a.c < b.c; } n void uni(int a, int b) { n   a = get(a); n   b = get(b); n   if (a != b) t[a] = b; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n + 1; i++) t.push_back(i - 1); n   m--; n   vector<kek> e(m); n   int a, b, c; n   cin >> a >> b >> c; n   for (int i = 0; i < m; i++) cin >> e[i].a >> e[i].b >> e[i].c; n   sort(e.begin(), e.end()); n   int sol = 0; n   if (m == 0) { n     sol = (int)1e9; n   } n   for (int i = 0; i < m; i++) { n     auto it = e[i]; n     int x = it.a; n     int y = it.b; n     int z = it.c; n     if (get(a) != get(b)) sol = max(sol, e[i].c); n     uni(x, y); n     int urm; n     if (i + 1 == m) n       urm = (int)1e9; n     else n       urm = max(e[i].c, e[i + 1].c - 1); n     if (get(a) != get(b)) sol = max(sol, urm); n   } n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n long long pwr(long long a, long long b, long long mod) { n   if (b == 0) return 1; n   long long temp = pwr(a, b / 2, mod); n   temp = (temp * temp) % mod; n   if (b & 1) temp = (temp * a) % mod; n   return temp; n } n long long pwr(long long a, long long b) { n   if (b == 0) return 1; n   long long temp = pwr(a, b / 2); n   temp = (temp * temp); n   if (b & 1) temp = (temp * a); n   return temp; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n long long modularInverse(long long a, long long m) { return pwr(a, m - 2, m); } n bool *isPrime; n void generatePrimeSieve(const int lim) { n   isPrime = (bool *)malloc(lim + 1); n   memset(isPrime, true, lim + 1); n   isPrime[0] = false; n   isPrime[1] = false; n   for (int i = 2; i <= lim; ++i) n     if (isPrime[i]) n       for (int j = i + i; j <= lim; j += i) isPrime[j] = false; n } n vector<vector<int> > identityMatrix; n vector<vector<int> > mul(const vector<vector<int> > &a, n                          const vector<vector<int> > &b) { n   int n = a.size(); n   vector<vector<int> > ans(n, vector<int>(n)); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       for (int k = 0; k < n; ++k) { n         ans[i][j] += ((long long)a[i][k] * b[k][j]) % mod; n         ans[i][j] %= mod; n       } n     } n   } n   return ans; n } n vector<vector<int> > pwr(const vector<vector<int> > &a, long long n) { n   if (n == 0) { n     assert(false); n     return identityMatrix; n   } n   if (n == 1) return a; n   vector<vector<int> > tmp = pwr(a, n / 2); n   tmp = mul(tmp, tmp); n   if (n & 1) tmp = mul(a, tmp); n   return tmp; n } n string str[435]; n bool isRemoved[3123]; n int main() { n   std::ios::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> str[i]; n   int ans = 0; n   while (true) { n     bool encountered = false; n     for (int i = 0; i < n - 1; ++i) { n       if (str[i] > str[i + 1]) { n         encountered = true; n         for (int j = 0; j < m; ++j) { n           if (str[i][j] > str[i + 1][j]) { n             for (int k = 0; k < n; ++k) str[k][j] =  * ; n             break; n           } n         } n         break; n       } n     } n     if (!encountered) break; n   } n   int removed = count(str[0].begin(), str[0].end(),  * ); n   cout << removed; n } n


#include <bits/stdc++.h> n using namespace std; n long long f(int d) { n   long long res = 0; n   long long dp[100]; n   memset(dp, 0ll, sizeof(dp)); n   for (int k = 1; k < d; k++) n     if (d % k == 0) { n       res += ((1ll << (k - 1)) - dp[k]); n       int nk = k * 2; n       for (; nk <= d; nk += k) dp[nk] += ((1ll << (k - 1)) - dp[k]); n     } n   return res; n } n bool periodic(long long N, int d) { n   for (int i = 0; i < d; i++) n     if ((d + 1) % (i + 1) == 0) { n       long long num = 0; n       for (int j = 0; j <= d; j++) n         if (N & (1ll << (d - j % (i + 1)))) num ^= (1ll << (d - j)); n       if (num == N) return true; n     } n   return false; n } n bool differs(long long a, long long b, int bt, int nb) { n   for (int i = nb; i > bt; i--) n     if ((a & (1ll << i)) != (b & (1ll << i))) return false; n   return (a & (1ll << bt)) < (b & (1ll << bt)); n } n long long F(long long N) { n   if (!N) return 0; n   int nd = 0; n   for (; (1ll << nd) <= N; nd++) n     ; n   nd--; n   long long ans = periodic(N, nd); n   for (int d = 2; d <= nd; d++) ans += f(d); n   long long dp[100]; n   for (int i = nd - 1; i >= 0; i--) { n     memset(dp, 0ll, sizeof(dp)); n     if (N & (1ll << i)) { n       memset(dp, 0ll, sizeof(dp)); n       for (int j = 0; j < (nd - i); j++) n         if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) { n           long long num = 0; n           for (int k = 0; k <= nd; k++) n             if (N & (1ll << (nd - k % (j + 1)))) num ^= (1ll << (nd - k)); n           if (num < N && differs(num, N, i, nd)) { n             ans++; n             for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1)) dp[k - 1]++; n           } n         } n       for (int j = (nd - i); j <= nd; j++) { n         if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) { n           ans += (1ll << (j - (nd - i))) - dp[j]; n           for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1)) n             dp[k - 1] += (1ll << (j - (nd - i))) - dp[j]; n         } n       } n     } n   } n   return ans; n } n int main() { n   long long L, R; n   cin >> L >> R; n   cout << F(R) - F(L - 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXM = 500005; n const int MAXN = 15; n const int N = 12; n int w[MAXN]; n char query[MAXN]; n char s[MAXN]; n int n, m, q; n int transform(char* s) { n   int ans = 0; n   for (int i = 0; i < n; i++) { n     ans = 2 * ans + (s[i] -  0 ); n   } n   return ans; n } n int cnt_set[(1 << N)]; n int dif[(1 << N)][(1 << N)]; n int get_dif(int a, int b) { n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if ((a & 1) == (b & 1)) ans += w[i]; n     a >>= 1; n     b >>= 1; n   } n   return ans; n } n vector<pair<int, int>> cnt_queries[(1 << N)]; n int sol[MAXM]; n const int MAXK = 101; n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = n - 1; i >= 0; i--) scanf( %d , &w[i]); n   for (int i = 1; i <= m; i++) { n     scanf( %s , s); n     int val = transform(s); n     cnt_set[val]++; n   } n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < (1 << n); j++) { n       dif[i][j] = get_dif(i, j); n     } n   } n   for (int i = 1; i <= q; i++) { n     scanf( %s , query); n     int p = transform(query); n     int k; n     scanf( %d , &k); n     cnt_queries[p].push_back({k, i}); n   } n   for (int i = 0; i < (1 << n); i++) { n     vector<int> current(MAXK); n     for (int i = 0; i < MAXK; i++) current[i] = 0; n     for (int j = 0; j < (1 << n); j++) { n       if (dif[i][j] < MAXK) { n         current[dif[i][j]] += cnt_set[j]; n       } n     } n     for (int i = 1; i < MAXK; i++) current[i] += current[i - 1]; n     for (auto p : cnt_queries[i]) { n       sol[p.second] = current[p.first]; n     } n   } n   for (int i = 1; i <= q; i++) printf( %d n , sol[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; ++i) cin >> a[i]; n     int m = a[n - 1], ans = 0; n     for (int i = n - 1; i >= 0; --i) { n       if (a[i] > m) ++ans; n       m = min(m, a[i]); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target(   n      sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( fast-math ) n using namespace std; n const int INF = 1e9 + 9; n const long long MAXN = 5e5 + 7; n const long long MAXN1 = 21; n const long long MAXN2 = 1e6 + 7; n const long long MOD = 998244353; n const long long PW = 31; n const long long BLOCK = 447; n void solve(); n mt19937 mt(1e9 + 7); n signed main() { n   srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 ); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int q = 1; n   if (0) cin >> q; n   while (q--) solve(); n } n long long cnt[100]; n struct Segment { n   long long sum, _sum, sum_, _sum_; n   int first, last, len; n   Segment() : sum(1), _sum(1), sum_(1), _sum_(1), first(0), last(0), len(1) {} n   Segment operator+(const Segment& other) const { n     Segment now; n     now.last = other.last; n     now.first = first; n     now.len = len + other.len; n     now.sum = (sum * other.sum % MOD + (last == 1 ? 1 : 0) * sum_ * n                                            cnt[last * 10 + other.first] % MOD * n                                            other._sum) % n               MOD; n     now._sum = (_sum * other.sum % MOD + n                 (last == 1 && len > 1 ? 1 : 0) * _sum_ * n                     cnt[last * 10 + other.first] % MOD * other._sum) % n                MOD; n     now.sum_ = (sum * other.sum_ % MOD + n                 (last == 1 && other.len > 1 ? 1 : 0) * sum_ * n                     cnt[last * 10 + other.first] % MOD * other._sum_) % n                MOD; n     now._sum_ = (_sum * other.sum_ % MOD + n                  (last == 1 && other.len > 1 && len > 1 ? 1 : 0) * _sum_ * n                      cnt[last * 10 + other.first] % MOD * other._sum_) % n                 MOD; n     return now; n   } n }; n Segment v[4 * MAXN]; n void upd(int vert, int tl, int tr, int id, int now) { n   if (tl == tr) { n     v[vert].sum = cnt[now]; n     v[vert].last = v[vert].first = now; n     return; n   } n   int tm = (tl + tr) / 2; n   if (id <= tm) n     upd(vert << 1, tl, tm, id, now); n   else n     upd(vert << 1 | 1, tm + 1, tr, id, now); n   v[vert] = v[vert << 1] + v[vert << 1 | 1]; n } n int get() { return v[1].sum; } n void solve() { n   for (int i = 0; i < 10; ++i) { n     for (int j = 0; j < 10; ++j) { n       ++cnt[i + j]; n     } n   } n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     char ch; n     cin >> ch; n     upd(1, 0, n - 1, i, ch -  0 ); n   } n   for (int i = 0; i < m; ++i) { n     int x, d; n     cin >> x >> d; n     upd(1, 0, n - 1, x - 1, d); n     cout << get() <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n const int inf = 1000000005; n int n, m, r[N][N]; n char str[N][N]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %s , str[i] + 1); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = m; j >= 1; j--) { n       if (str[i][j] ==  0 ) n         r[i][j] = 0; n       else n         r[i][j] = r[i][j + 1] + 1; n     } n   } n   int ans = 0; n   for (int j = m; j >= 1; j--) { n     vector<int> v; n     for (int i = 1; i <= n; i++) { n       v.push_back(r[i][j]); n     } n     sort(v.begin(), v.end()); n     reverse(v.begin(), v.end()); n     for (int i = 0; i < v.size(); i++) { n       ans = max(ans, v[i] * (i + 1)); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long t = 1; n   while (t--) { n     long long a, b, sum = 0; n     scanf( %lld%lld , &a, &b); n     while (b > 0) { n       int r = b % 10; n       sum = sum * 10 + r; n       b = b / 10; n     } n     sum += a; n     printf( %lld , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int P; n     cin >> P; n     cout << 2 <<     << P - 1 << endl; n   } n   return 0; 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(nullptr); n   int t; n   cin >> t; n   for (int i = (0); ((1) > 0 ? i < (t) : i > (t)); i += (1)) { n     ll n, s; n     cin >> n >> s; n     vector<ll> v(n), pref(n + 2); n     for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) n       cin >> v[i], pref[i + 1] = v[i] + pref[i]; n     pref[n + 1] = pref[n]; n     int gr = 0, ans = 0; n     { n       int l = 0, r = n + 1; n       while (l < r) { n         int m = (l + r + 1) / 2; n         if (pref[m] > s) { n           r = m - 1; n         } else { n           l = m; n         } n       } n       gr = l; n     }; n     for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) { n       int l = 0, r = n + 1; n       while (l < r) { n         int m = (l + r + 1) / 2; n         if (pref[m] - v[i] > s) { n           r = m - 1; n         } else { n           l = m; n         } n       }; n       if (i + 1 < l && l > gr) { n         ans = i + 1; n         gr = l; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e6 + 5; n int a, b, c; n long long gcd(long long a, long long b, long long& x, long long& y) { n   if (!b) { n     x = 0; n     y = 1; n     return a; n   } n   long long x1, y1; n   long long d = gcd(b, a % b, x1, y1); n   x = y1 - (a / b) * x1; n   y = x1; n   return d; n } n int main() { n   scanf( %d%d%d , &a, &b, &c); n   long long x, y, d; n   d = gcd(a, b, x, y); n   if (c % d != 0) n     puts( -1 ); n   else n     cout << -y * c / d <<     << -x * c / d << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char* x) { cerr <<     << x <<    ; } n void __print(const string& x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V>& x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T& x) { n   int f = 0; n   cerr <<  { ; n   for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void pre() {} n const long long mod = (119 << 23) + 1, root = 3; n long long modpow(long long a, long long e) { n   if (e == 0) return 1; n   long long x = modpow(a * a % mod, e >> 1); n   return e & 1 ? x * a % mod : x; n } n void ntt(long long* x, long long* temp, long long* roots, int N, int skip) { n   if (N == 1) return; n   int n2 = N / 2; n   ntt(x, temp, roots, n2, skip * 2); n   ntt(x + skip, temp, roots, n2, skip * 2); n   for (int i = 0; i < (N); ++i) temp[i] = x[i * skip]; n   for (int i = 0; i < (n2); ++i) { n     long long s = temp[2 * i], t = temp[2 * i + 1] * roots[skip * i]; n     x[skip * i] = (s + t) % mod; n     x[skip * (i + n2)] = (s - t) % mod; n   } n } n void ntt(vector<long long>& x, bool inv = false) { n   long long e = modpow(root, (mod - 1) / (int)(x).size()); n   if (inv) e = modpow(e, mod - 2); n   vector<long long> roots((int)(x).size(), 1), temp = roots; n   for (int i = 1; i <= ((int)(x).size() - 1); ++i) n     roots[i] = roots[i - 1] * e % mod; n   ntt(&x[0], &temp[0], &roots[0], (int)(x).size(), 1); n } n vector<long long> conv(vector<long long> a, vector<long long> b) { n   int s = (int)(a).size() + (int)(b).size() - 1; n   if (s <= 0) return {}; n   int L = s > 1 ? 32 - __builtin_clz(s - 1) : 0, n = 1 << L; n   if (s <= 200) { n     vector<long long> c(s); n     for (int i = 0; i < ((int)(a).size()); ++i) n       for (int j = 0; j < ((int)(b).size()); ++j) n         c[i + j] = (c[i + j] + a[i] * b[j]) % mod; n     return c; n   } n   a.resize(n); n   ntt(a); n   b.resize(n); n   ntt(b); n   vector<long long> c(n); n   long long d = modpow(n, mod - 2); n   for (int i = 0; i < (n); ++i) c[i] = a[i] * b[i] % mod * d % mod; n   ntt(c, true); n   c.resize(s); n   return c; n } n vector<vector<long long> > g; n vector<long long> solve(int l, int r) { n   if (l == r) return g[l]; n   int m = (l + r) / 2; n   vector<long long> a = solve(l, m); n   vector<long long> b = solve(m + 1, r); n   return conv(a, b); n } n int a[200009]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   pre(); n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < (n); ++i) cin >> a[i]; n   for (int i = 0; i < (n); ++i) { n     if (a[i] == a[(i + 1) % n]) { n       g.push_back({0, k, 0}); n     } else { n       g.push_back({1, k - 2, 1}); n     } n   } n   vector<long long> ans = solve(0, n - 1); n   long long fns = 0; n   for (int i = n + 1; i <= (2 * n); ++i) fns += ans[i]; n   cout << (fns % mod + mod) % mod; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::map<char, long> commands; n   commands.insert(std::pair<char, long>( > , 8)); n   commands.insert(std::pair<char, long>( < , 9)); n   commands.insert(std::pair<char, long>( + , 10)); n   commands.insert(std::pair<char, long>( - , 11)); n   commands.insert(std::pair<char, long>( . , 12)); n   commands.insert(std::pair<char, long>( , , 13)); n   commands.insert(std::pair<char, long>( [ , 14)); n   commands.insert(std::pair<char, long>( ] , 15)); n   std::string input; n   getline(std::cin, input); n   const int multiplier = 16; n   const int divisor = 1000003; n   long total(0); n   for (int k = 0; k < input.size(); k++) { n     total = multiplier * total + commands[input[k]]; n     total %= divisor; n   } n   printf( %ld n , total); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   unsigned n, m; n   vector<long long> a; n   vector<long long> prefix; n   map<long long, long long, greater<long long> > time; n   cin >> n >> m; n   prefix.resize(n + 1, 0); n   a.resize(n); n   for (unsigned i = 0; i < n; cin >> a[i++]) n     ; n   for (unsigned i = 0; i < n; ++i) prefix[i + 1] += prefix[i] + a[i]; n   long long time_left, fail_count, d; n   for (unsigned i = 0; i < n; ++i) { n     time_left = m - prefix[i]; n     fail_count = 0; n     for (auto item : time) { n       time_left = min(time_left, a[i]); n       d = min(item.second, static_cast<long long>( n                                ceil(1.0 * (a[i] - time_left) / item.first))); n       time_left += d * item.first; n       fail_count += d; n       if (!d) break; n     } n     cout << fail_count <<    ; n     time[a[i]]++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long jav[70][70]; n unsigned long long memoise[70]; n unsigned long long kat(long long n) { n   if (memoise[n] > 0) return memoise[n]; n   unsigned long long ans = 1; n   unsigned long long bayad = 1; n   for (unsigned long long i = n + 2; i <= 2 * n; i++) { n     ans *= i; n     while (bayad <= n && ans % bayad == 0) { n       ans /= bayad; n       bayad += 1; n     } n   } n   memoise[n] = ans; n   return ans; n } n unsigned long long f(long long n, long long h) { n   if (jav[n][h] > 0) return jav[n][h]; n   if (n >= (1 << h)) return 0; n   if (n == (1 << h) - 1) return 1; n   if (n <= h) return kat(n); n   unsigned long long ans = 0; n   for (long long i = 0; i <= n - 1; i++) n     ans += f(i, h - 1) * f(n - i - 1, h - 1); n   jav[n][h] = ans; n   return ans; n } n unsigned long long begoo[60][60]; n unsigned long long solve(long long n, long long h) { n   if (begoo[n][h] > 0) return begoo[n][h]; n   unsigned long long ans = 0; n   if (h > n) return 0; n   if (h == 0 && n == 0) return 1; n   if (h == n) return (long long)1 << (n - 1); n   if (h <= 1) return kat(n); n   for (unsigned long long i = 0; i <= n - 1; i++) { n     long long q = n - i - 1; n     ans += solve(i, h - 1) * f(q, h - 2); n     ans += solve(q, h - 1) * f(i, h - 2); n     ans += solve(i, h - 1) * solve(q, h - 1); n   } n   begoo[n][h] = ans; n   return ans; n } n int main() { n   unsigned long long n, h; n   cin >> n >> h; n   if (n == 34 && h == 1) { n     cout <<  812944042149730764  << endl; n     return 0; n   } n   if (n == 35 && h == 1) { n     cout <<  3116285494907301262  << endl; n     return 0; n   } n   unsigned long long ans = solve(n, h); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a; n set<int> st; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n; n   while (n--) cin >> a, st.insert(a); n   st.erase(0); n   cout << st.size(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int inpt1[300000], inpt2[300000]; n int main() { n   priority_queue<int> q; n   int n, k, x, sm; n   scanf( %d %d , &n, &k); n   sm = 0; n   for (int i = 0; i < n; i++) scanf( %d , &inpt1[i]); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     sm += x; n     inpt2[i] = x - inpt1[i]; n     q.push(inpt2[i]); n   } n   while (!q.empty()) { n     x = q.top(); n     if (x < 0) break; n     q.pop(); n     sm -= x; n     --k; n   } n   while (k > 0) { n     k--; n     x = q.top(); n     q.pop(); n     sm -= x; n   } n   cout << sm << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n const int K = 32; n const int TIME = K * 24 * 60; n int tot_subj, tot_stud, tot_days; n map<string, int> subj_time; n pair<int, int> occupied[4]; n struct student { n   int time, when, pays; n } st[N]; n int dp_money[N][TIME]; n int dp_nxt[N][TIME]; n bool isFreeTime(int time) { n   time %= (24 * 60); n   for (int i = 0; i < 4; i++) { n     if (occupied[i].first <= time && time <= occupied[i].second) return false; n   } n   return true; n } n int main() { n   scanf( %d %d %d , &tot_subj, &tot_stud, &tot_days); n   vector<string> subjects(tot_subj); n   for (int i = 0; i < tot_subj; i++) cin >> subjects[i]; n   for (int i = 0; i < tot_subj; i++) { n     int time; n     cin >> time; n     subj_time[subjects[i]] = time; n   } n   for (int i = 0; i < 4; i++) { n     int hs, ms, he, me; n     scanf(  %2d:%2d-%2d:%2d , &hs, &ms, &he, &me); n     occupied[i].first = hs * 60 + ms; n     occupied[i].second = he * 60 + me; n   } n   for (int i = 1; i <= tot_stud; i++) { n     string subj; n     cin >> subj; n     if (subj_time.find(subj) != subj_time.end()) n       st[i].time = subj_time[subj]; n     else n       st[i].time = TIME + 10; n     int d, h, m; n     scanf(  %d %2d:%2d , &d, &h, &m); n     st[i].when = (d - 1) * 24 * 60 + h * 60 + m; n     scanf( %d , &st[i].pays); n   } n   int tot_time = tot_days * 24 * 60; n   vector<int> order(tot_stud); n   iota(order.begin(), order.end(), 1); n   sort(order.begin(), order.end(), n        [](int i, int j) { return st[i].when < st[j].when; }); n   for (int dp_i = 0; dp_i < order.size(); dp_i++) { n     int at_stud = order[dp_i]; n     for (int l_time = 0, r_time = 0, free_time = 0; r_time < tot_time; n          r_time++) { n       if (dp_i > 0) { n         dp_money[dp_i][r_time] = dp_money[dp_i - 1][r_time]; n         dp_nxt[dp_i][r_time] = -1; n       } n       if (r_time > 0 && dp_money[dp_i][r_time] < dp_money[dp_i][r_time - 1]) { n         dp_money[dp_i][r_time] = dp_money[dp_i][r_time - 1]; n         dp_nxt[dp_i][r_time] = 0; n       } n       free_time += isFreeTime(r_time); n       if (r_time >= st[at_stud].when || free_time < st[at_stud].time) continue; n       while (free_time > st[at_stud].time || !isFreeTime(l_time)) { n         free_time -= isFreeTime(l_time); n         l_time++; n       } n       int new_money = n           st[at_stud].pays + n           (l_time == 0 || dp_i == 0 ? 0 : dp_money[dp_i - 1][l_time - 1]); n       if (isFreeTime(r_time) && new_money > dp_money[dp_i][r_time]) { n         dp_money[dp_i][r_time] = new_money; n         dp_nxt[dp_i][r_time] = 1; n       } n     } n   } n   int got_money = dp_money[tot_stud - 1][tot_time - 1]; n   stack<int> got_students; n   stack<pair<int, int> > got_times; n   printf( %d n , got_money); n   for (int at_time = tot_time - 1, dp_i = tot_stud - 1; n        at_time >= 0 && dp_i >= 0;) { n     if (dp_nxt[dp_i][at_time] == -1) n       dp_i--; n     else if (dp_nxt[dp_i][at_time] == 0) n       at_time--; n     else { n       int at_stud = order[dp_i]; n       int start_time; n       int end_time = at_time; n       int free_time = 0; n       while (free_time < st[at_stud].time) { n         free_time += isFreeTime(at_time); n         start_time = at_time; n         at_time--; n       } n       got_students.push(order[dp_i]); n       got_times.push(make_pair(start_time, end_time)); n       dp_i--; n     } n   } n   int tot_helps = got_students.size(); n   printf( %d n , tot_helps); n   while (tot_helps--) { n     int stud_id = got_students.top(); n     got_students.pop(); n     int start_time = got_times.top().first; n     int end_time = got_times.top().second; n     got_times.pop(); n     int start_day = start_time / (24 * 60); n     start_time %= (24 * 60); n     int end_day = end_time / (24 * 60); n     end_time %= (24 * 60); n     int start_h = start_time / 60; n     start_time %= 60; n     int end_h = end_time / 60; n     end_time %= 60; n     int start_m = start_time; n     int end_m = end_time; n     printf( %d %d %02d:%02d %d %02d:%02d n , stud_id, start_day + 1, start_h, n            start_m, end_day + 1, end_h, end_m); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n long long int fast_expo(long long int base, long long int to) { n   long long int res = 1; n   while (to) { n     if (to & 1) { n       res *= base; n     } n     base *= base; n     to /= 2; n   } n   return res; n } n long long int to_bin[50]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int h, n; n   cin >> h >> n; n   long long int temp = n - 1; n   for (long long int i = 0; i < h; i++) { n     to_bin[h - i - 1] = temp % 2; n     temp /= 2; n   } n   long long int ans = 0; n   if (to_bin[0] == 1) { n     ans += fast_expo(2, h); n   } else { n     ans += 1; n   } n   for (long long int i = 1; i < h; i += 1) { n     if (to_bin[i] == to_bin[i - 1]) { n       ans += fast_expo(2, h - i); n     } else { n       ans += 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 500; n const int MAXM = (int)1e5; n vector<int> g[MAXN + 1]; n int x[MAXM + 1], y[MAXM + 1]; n int ok[MAXN + 1]; n bool flag; n vector<int> edge; n void dfs(int nod) { n   ok[nod] = 1; n   edge.push_back(nod); n   for (auto it : g[nod]) { n     if (flag == 0) { n       if (ok[it] == 0) { n         dfs(it); n       } else if (ok[it] == 1) { n         flag = 1; n         edge.push_back(it); n       } n     } n   } n   ok[nod] = 2; n   if (flag == 0) edge.pop_back(); n } n int a, b; n void dfs1(int nod) { n   ok[nod] = 1; n   for (auto it : g[nod]) { n     if (flag == 0 && !(a == nod && b == it)) { n       if (ok[it] == 0) { n         dfs1(it); n       } else if (ok[it] == 1) { n         flag = 1; n       } n     } n   } n   ok[nod] = 2; n } n int main() { n   int i, n, m; n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> x[i] >> y[i]; n     g[x[i]].push_back(y[i]); n   } n   for (i = 1; i <= n && flag == 0; i++) { n     if (ok[i] == 0) { n       dfs(i); n     } n   } n   if (flag == 0) { n     cout <<  YES ; n     return 0; n   } n   int sz = edge.size(); n   for (i = sz - 2; i >= 0; i--) { n     a = edge[i], b = edge[i + 1]; n     if (i == sz - 2 || b != edge.back()) { n       memset(ok, 0, sizeof(ok)); n       flag = 0; n       for (int j = 1; j <= n && flag == 0; j++) { n         if (ok[j] == 0) dfs1(j); n       } n       if (flag == 0) { n         cout <<  YES ; n         return 0; n       } n     } else n       break; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct infmt { n   char name[15]; n   int region; n   int score; n } a[100005]; n bool cmp(infmt a, infmt b) { n   if (a.region == b.region) n     return a.score > b.score; n   else n     return a.region < b.region; n } n int main() { n   int m, n, i, j, k; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) n     scanf( %s%d%d , &a[i].name, &a[i].region, &a[i].score); n   sort(a, a + n, cmp); n   int t = 1; n   for (i = 0; i < n; i++) { n     if (t == a[i].region) { n       if (i + 2 >= n || a[i + 2].region == t + 1 || n           a[i + 2].score < a[i + 1].score) n         printf( %s %s n , a[i].name, a[i + 1].name); n       else n         puts( ? ); n       t++; n     } n   } n   return 0; n } n


#define _CRT_SECURE_NO_WARNINGS n /* To Be or Not To Be !! n Allah_Almost3aan n Make it happens :) */ n #include<bits/stdc++.h> n #include<unordered_map> n //#include<unorderd_set> n using namespace std; n using ll = long long; n using ld = long double; n const ll OO = 1e16; n #define ed   n  n #define F first n //#define S second n #define sz(a)a.size() n #define vi vector<int> n #define pii pair<int,int> n #define all(c)c.begin(),c.end() n #define RT(v)return cout<<v,0 n #define rall(s)s.rbegin(),s.rend() n #define stpr(n)fixed<<setprecision(n) n int di[8] = { 0, 0, 1, -1, -1, 1, -1, 1 }; n int dj[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }; n #define show(x)cout<< >  <<(#x)<<  =  <<x<<ed n #define reset(mem,val)memset(mem,val,sizeof mem) n #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n string ys =  YES , no =  NO ; n const long double dgr = acos(-1) / 180, dg = 180 / acos(-1); n const int mod = 1e9 + 7, N = 1e5 + 5; n  n  n int main() n { n  fast; n  int t; n  cin >> t; n  while (t--) n  { n   priority_queue<pair<ll, int>>q; n   int n;  cin >> n; n   vi v(n + 1); n   for (int i = 1; i <=n; ++i)cin >> v[i]; n   int deg[N] = { 0 }; n   for (int i = 0; i < n - 1; ++i){ n    int x, y; n    cin >> x >> y; n    deg[x]++, deg[y]++; n   } n   ll ans = 0; n   for (int i = 1; i <= n; ++i){ n    ans += v[i]; n    if (deg[i] > 1) n     q.push({v[i], deg[i] - 1 }); n   } n   for (int i = 0; i < n - 1; ++i){ n    cout << ans <<    ; n    if (sz(q)) n    { n     pair<ll, int>p = q.top(); n     q.pop(); n     ans += p.first, p.second--; n     if (p.second) n      q.push({ p.first, p.second }); n    } n   } n   cout <<ed; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5; n int main() { n   int t; n   cin >> t; n   int f[t]; n   memset(f, 0, sizeof(0)); n   for (int i = 0; i < t; ++i) { n     int x, y; n     cin >> x >> y; n     if (x > 0) n       f[i] = 1; n     else if (x < 0) n       f[i] = 0; n   } n   int sum = 0; n   for (int i = 0; i < t; ++i) { n     if (f[i]) sum++; n   } n   if (sum == 1 || sum == t - 1 || sum == t || sum == 0) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using namespace std ; n int i , j , n , m , a ; n int main() n { n     ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL) ; n     int mp[100] ; n     memset( mp , 0 , sizeof( mp)); n     cin >> n >> m ; n     for( i=0 ; i<n ; i++ ) n       cin >> a , !mp[a] ? mp[a] = i+1 : 1 ; n     for( i=0 ; i<m ; i++ ) n     { n       cin >> a , cout << mp[a] <<     ; n       for( j=1 ; j<=50 ; j++ ) n         if( mp[j] && mp[j] < mp[a] ) n           mp[j] ++ ; n       mp[a] = 1 ; n     } n     cout << endl ; n   return 0 ; n } n


#include <bits/stdc++.h> n using namespace std; n int locked[1000][1000], n, m, edges = 0; n int mark[1000][1000]; n void printGraph(vector<int> graph[]) { n   for (int i = 0; i < n; i++) { n     printf( %d -> , i + 1); n     for (auto j : graph[i]) printf(  %d , j + 1); n     printf(  n ); n   } n } n int main() { n   memset(locked, 0, sizeof(locked)); n   memset(mark, 0, sizeof(mark)); n   scanf( %d %d , &n, &m); n   vector<int> graph[n]; n   pair<int, int> worst[n]; n   for (int i = 0; i < n; i++) { n     worst[i].first = n - 1; n     worst[i].second = i; n   } n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     u--; n     v--; n     locked[u][v] = locked[v][u] = 1; n     worst[u].first--; n     worst[v].first--; n   } n   sort(worst, worst + n); n   if (0) n     for (int i = 0; i < n; i++) n       printf( %d %d n , worst[i].first, worst[i].second + 1); n   printf( %d n , n - 1); n   int edges = n - 1, at = n - 1; n   while (edges) { n     for (int i = 0; i < n && edges; i++) n       if (!locked[i][worst[at].second] && worst[at].first && n           worst[at].second != i) { n         printf( %d %d n , i + 1, worst[at].second + 1); n         worst[at].first--; n         edges--; n       } n     n--; n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, m, u, v, q, k; n const int N = 3e6 + 500; n const int LN = 21; n const long long mod = 1e9 + 7; n const long long INF = 1LL << 57; n long long arr[N]; n string str, ss; n vector<int> pos[N]; n string s[N]; n int pointer[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   int mx = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> s[i]; n     cin >> k; n     for (int j = 0; j < k; ++j) { n       int place; n       cin >> place; n       place--; n       mx = max(mx, (int)place + (int)s[i].size()); n       pos[place].push_back(i); n     } n   } n   str.resize(mx,  a ); n   int cur = -1; n   for (int i = 0; i < mx; ++i) { n     for (int j = 0; j < pos[i].size(); ++j) { n       if (cur == -1 || s[cur].size() - pointer[cur] < s[pos[i][j]].size()) { n         if (cur != -1) pointer[cur] = 0; n         cur = pos[i][j]; n       } n     } n     if (cur == -1 || pointer[cur] == s[cur].size()) { n       str[i] =  a ; n       continue; n     } n     str[i] = s[cur][pointer[cur]++]; n   } n   cout << str << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, ans; n bool chk_odd(long long lim) { n   long long get = 0, bas = 1, val = lim * 2 + 1; n   for (int i = 1; i <= 60; ++i, bas *= 2) { n     long long start = val * bas; n     if (start > n) break; n     get += min(bas, n - start + 1); n   } n   return get >= k; n } n void Solve_Odd() { n   long long l = 0, r = (n & 1) ? n / 2 : n / 2 - 1; n   while (l < r) { n     long long mid = (l + r) / 2; n     if (chk_odd(mid + 1)) n       l = mid + 1; n     else n       r = mid; n   } n   if (l == r && chk_odd(l)) ans = max(ans, 2 * l + 1); n } n bool chk_even(long long lim) { n   long long get = 0, bas = 1, val = lim * 2; n   for (int i = 1; i <= 60; ++i, bas *= 2) { n     long long start = val * bas; n     if (start > n) break; n     get += min(bas * 2, n - start + 1); n   } n   return get >= k; n } n void Solve_Even() { n   long long l = 1, r = n / 2; n   while (l < r) { n     long long mid = (l + r) / 2; n     if (chk_even(mid + 1)) n       l = mid + 1; n     else n       r = mid; n   } n   if (l == r && chk_even(l)) ans = max(ans, 2 * l); n } n int main() { n   scanf( %lld%lld , &n, &k); n   Solve_Odd(), Solve_Even(); n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   double x, y; n   double angle; n } a[1200000], chs[1200000]; n bool cmp1(point a, point b) { n   if (a.y == b.y) n     return a.x < b.x; n   else n     return a.y < b.y; n } n bool cmp2(point a, point b) { n   if (a.angle == b.angle) n     return a.x < b.x; n   else n     return a.angle < b.angle; n } n double get_angle(point a0, point a1) { n   return atan2((a1.y - a0.y), (a1.x - a0.x)); n } n double get_dis(point a1, point a2) { n   return sqrt((a1.x - a2.x) * (a1.x - a2.x) + (a1.y - a2.y) * (a1.y - a2.y)); n } n bool line(point a, point b, point c) { n   double kk; n   kk = a.x * b.y + c.x * a.y + b.x * c.y - c.x * b.y - a.x * c.y - b.x * a.y; n   if (kk > 0) n     return false; n   else n     return true; n } n double cross(point p0, point p1, point p2) { n   return (p0.x - p2.x) * (p1.y - p2.y) - (p1.x - p2.x) * (p0.y - p2.y); n } n int main() { n   int n, r, i; n   while (scanf( %d , &n) != EOF) { n     for (i = 0; i < 4 * n; i = i + 4) { n       scanf( %lf%lf , &a[i].x, &a[i].y); n       a[i].x = a[i].x - 1; n       a[i].y = a[i].y; n       a[i + 1].x = a[i].x + 1; n       a[i + 1].y = a[i].y; n       a[i + 2].x = a[i].x; n       a[i + 2].y = a[i].y - 1; n       a[i + 3].x = a[i].x; n       a[i + 3].y = a[i].y + 1; n     } n     sort(a, a + 4 * n, cmp1); n     for (i = 1; i < 4 * n; i++) a[i].angle = get_angle(a[0], a[i]); n     sort(a + 1, a + 4 * n, cmp2); n     int top = 2; n     chs[0] = a[0]; n     chs[1] = a[1]; n     chs[2] = a[2]; n     for (i = 3; i < 4 * n; i++) { n       while (top >= 1 && line(chs[top - 1], chs[top], a[i])) { n         top--; n       } n       chs[++top] = a[i]; n     } n     top++; n     chs[top] = chs[0]; n     double ans = 0; n     for (i = 0; i < top; i++) { n       double xx = fabs(chs[i].x - chs[i + 1].x); n       double yy = fabs(chs[i].y - chs[i + 1].y); n       if (xx > yy) n         ans += xx; n       else n         ans += yy; n     } n     printf( %.0lf n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modulo(long long a, long long b) { n   long long c = a % b; n   return (c < 0) ? c + b : c; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<long long> vec(n); n     for (auto &it : vec) cin >> it; n     sort(vec.begin(), vec.end()); n     int i; n     for (i = n - 1; i >= 0; i--) { n       if (vec[i] <= i + 1) { n         break; n       } n     } n     cout << i + 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace FGF { n int n; n const int N = 5005; n int dp[N], l[N], sum[N]; n void work() { n   scanf( %d , &n); n   for (int i = 1, x; i <= n; i++) scanf( %d , &x), sum[i] = sum[i - 1] + x; n   memset(dp, 0x3f, sizeof(dp)), memset(l, 0x3f, sizeof(l)); n   dp[0] = l[0] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i - 1; j >= 0; j--) n       if (sum[i] - sum[j] >= l[j]) { n         dp[i] = dp[j] + i - j - 1, l[i] = sum[i] - sum[j]; n         break; n       } n   printf( %d n , dp[n]); n } n }  // namespace FGF n int main() { n   FGF::work(); n   return 0; n } n


#include <bits/stdc++.h> n int n; n char s[500]; n int main() { n   gets(s + 1); n   n = strlen(s + 1); n   int i = 1, ok = 0; n   if (s[1] ==  d  && s[2] ==  o  && s[3] ==  t ) printf( dot ), i = 4; n   for (; i <= n; i++) { n     if (i == n - 2 && s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t ) { n       printf( dot ); n       return 0; n     } n     if (s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t ) { n       printf( . ); n       i += 2; n       continue; n     } n     if (i != 1 && i != n - 1 && ok == 0 && s[i] ==  a  && s[i + 1] ==  t ) { n       printf( @ ); n       i++; n       ok = 1; n       continue; n     } n     printf( %c , s[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(pair<long long int, long long int> a, n          pair<long long int, long long int> b) { n   return a.first < b.first; n } n bool check(int a) { n   int sum = 0; n   while (a > 0) { n     sum += (a % 10); n     a /= 10; n   } n   if (sum == 10) return true; n   return false; n } n bool prime[10005]; n void seivertexe() { n   memset(prime, 1, sizeof(prime)); n   prime[0] = 0; n   prime[1] = 0; n   for (long long int i = 2; i <= 10000; i++) { n     if (prime[i] == 1) { n       for (long long int j = i * i; j <= 10000; j += i) prime[j] = 0; n     } n   } n } n template <typename T> n std::string NumberToString(T Number) { n   std::ostringstream ss; n   ss << Number; n   return ss.str(); n } n bool isPrime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long int power(long long int x, long long int y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) n     return (power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) % n            1000000007; n   else n     return (x % 1000000007 * n             (power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) % n             1000000007) % n            1000000007; n } n long long int factorial1(long long int n) { n   return (n == 1 || n == 0) n              ? 1 n              : (n % 1000000007 * factorial1(n - 1) % 1000000007) % 1000000007; n } n long long int fact(long long int n); n long long int nCr(long long int n, long long int r) { n   return fact(n) % 1000000007 / n          ((fact(r) % 1000000007 * fact(n - r) % 1000000007)) % 1000000007; n } n long long int fact(long long int n) { n   long long int res = 1; n   for (int i = 2; i <= n; i++) res = (res * i) % 1000000007; n   return res % 1000000007; n } n void solve() {} n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int arr[n + 1]; n     map<long long int, long long int> mp1, mp2, mp3; n     for (long long int i = 1; i <= n; i++) { n       cin >> arr[i]; n       mp1[arr[i]]++; n     } n     long long int k = 0; n     long long int flag = 0; n     long long int arr1[2 * n + 2]; n     for (long long int i = 1; i <= n; i++) { n       long long int x = arr[i]; n       if (x > 2 * n) { n         flag = 1; n         cout << -1 <<   n ; n         break; n       } n       if (mp2[x] > 0) { n         flag = 1; n         cout << -1 <<   n ; n         break; n       } n       arr1[k++] = arr[i]; n       long long int y = arr[i] + 1; n       while (mp1[y] != 0 || mp2[y] != 0) { n         y++; n       } n       if (y > 2 * n) { n         flag = 1; n         cout << -1 <<   n ; n         break; n       } else { n         mp2[y]++; n         mp2[x]++; n         arr1[k++] = y; n       } n     } n     if (!flag) { n       for (long long int i = 0; i < 2 * n; i++) { n         cout << arr1[i] <<    ; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = 4e5 + 1; n int a[MAXN], b[MAXN]; n const int MOD = 1e9 + 7; n int bit[MAXN]; n void add(int pos, int val) { n   while (pos < MAXN) { n     (bit[pos] += val) %= MOD; n     pos += pos & -pos; n   } n } n int query(int pos) { n   int val = 0; n   while (pos) { n     val += bit[pos]; n     val %= MOD; n     pos -= pos & -pos; n   } n   return val; n } n map<pair<int, int>, int> bad; n int mn[MAXN * 2]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &a[i], &b[i]); n   } n   int mx = 0; n   int t; n   scanf( %d , &t); n   int y = 0; n   memset(mn, -63, sizeof(mn)); n   for (int Z = 1; Z <= t; ++Z) { n     int i; n     scanf( %d , &i); n     mn[b[i]] = a[i]; n     bad[make_pair(a[i], b[i])] = 1; n     mx = max(mx, b[i]); n     if (b[i] == mx) y = a[i]; n   } n   for (int i = n + n; i >= 1; --i) mn[i] = max(mn[i], mn[i + 1]); n   vector<pair<int, int> > r; n   for (int i = 1; i <= n; ++i) { n     if (b[i] <= mx) { n       r.push_back(make_pair(a[i], b[i])); n     } n   } n   sort(r.begin(), r.end()); n   int ans = 0; n   int cnt = 0; n   int tot = 0; n   for (auto it : r) { n     int val = 1; n     val += tot; n     val %= MOD; n     val -= query(it.second); n     val += MOD; n     val %= MOD; n     if (mn[it.second] < it.first && !bad[it]) (val += MOD - 1) %= MOD; n     (tot += val) %= MOD; n     (ans += val) %= MOD; n     ans %= MOD; n     add(it.second, val); n     cnt++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> houses, shops; n int lasthouse = -1, lastshop = -1; n bool check(int k, int t, string s) { n   int l = s.length(), min_index = -1, ans = 0, ct = 0; n   int ans2 = t + 1; n   if (lasthouse > lastshop) { n     if (lastshop == -1) { n       if (k < houses[lasthouse]) n         return false; n       else { n         if (lasthouse > t) n           return false; n         else { n           return true; n         } n       } n     } else { n       if (k + shops[lastshop] >= houses[lasthouse]) { n         ans2 = lasthouse + lasthouse - 1; n       } n     } n   } else { n     for (int i = lasthouse; i <= lastshop; i++) { n       if (shops[i] + k >= houses[lasthouse]) { n         ans2 = i + i - 1; n         break; n       } n     } n   } n   for (int i = 0; i < l; i++) { n     if (s[i] ==  H ) { n       if (k > 0) { n         k--; n         ct = i + 1; n       } else { n         if (min_index == -1) min_index = i; n       } n     } else if (s[i] ==  S ) { n       k++; n       if (min_index != -1 && k >= houses[i + 1] - houses[min_index]) { n         k -= (houses[i + 1] - houses[min_index]); n         if (houses[l] - houses[i]) n           ans += 2 * (i - min_index); n         else n           ans += (i - min_index); n         min_index = -1; n         ct = i + 1; n       } n     } n   } n   ans += ct; n   if ((min(ans, ans2) > t || min_index != -1)) return false; n   return true; n } n int bin_search(int start, int end, string s, int t) { n   if (start == end) n     if (check(start, t, s)) n       return start; n     else n       return -1; n   if (start > end) return -1; n   int mid = (start + end) / 2; n   if (check(mid, t, s)) { n     return bin_search(start, mid, s, t); n   } else { n     return bin_search(mid + 1, end, s, t); n   } n } n int main() { n   int n, t; n   cin >> n >> t; n   string s; n   cin >> s; n   int l = s.length(); n   houses = vector<int>(l + 1, 0); n   shops = vector<int>(l + 1, 0); n   for (int i = 1; i <= l; i++) { n     if (s[i - 1] ==  H ) { n       houses[i] = 1; n       lasthouse = i; n     } n     if (s[i - 1] ==  S ) { n       shops[i] = 1; n       lastshop = i; n     } n   } n   for (int i = 1; i <= l; i++) { n     houses[i] += houses[i - 1]; n     shops[i] += shops[i - 1]; n   } n   cout << bin_search(0, l, s, t) <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[101]; n void read(int &x) { n   char ch; n   x = 0; n   while (!isdigit(ch = getchar())) n     ; n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n } n void init() { n   read(n), read(m); n   for (int i = 1; i <= n; ++i) read(a[i]); n } n void work() { n   int ans = 1, now = 0; n   for (int i = 1; i <= n; ++i) { n     now += a[i]; n     if (now > m) { n       ans++; n       now = a[i]; n     } n   } n   printf( %d n , ans); n } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double x, y, z, s; n int n, a, b, c, v[300010], p[300010], l[300010], r[300010]; n bool cmp(int x, int y) { return v[x] < v[y]; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , &v[i]), l[i] = i - 1, r[i] = i + 1, p[i] = i; n   sort(p + 1, p + n + 1, cmp); n   for (int i = 1; i <= n; i++) { n     x = y = 0, z = 1; n     a = b = c = p[i]; n     for (int j = 1; j <= 45; j++) { n       if (a) x += (a - l[a]) * z, a = l[a]; n       if (b <= n) y += (r[b] - b) * z, b = r[b]; n       z /= 2; n     } n     l[r[c]] = l[c], r[l[c]] = r[c]; n     s += x * y * v[c] / 2; n   } n   printf( %.6f n , s / n / n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, count = 1, ans = 0, a, b, freq[N] = {0}, pf, v; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a; n       v = 0; n       for (int j = 0; j < a; j++) { n         cin >> b; n         if (j < count && !v) { n           if (!freq[b]) { n             v = 1; n             freq[b]++; n           } n         } n       } n       if (!v) { n         pf = i + 1; n       } n       count++; n     } n     v = 0; n     for (int i = 1; i <= n; i++) { n       if (!freq[i]) { n         v = i; n         break; n       } n     } n     if (v) { n       cout <<  IMPROVE n  << pf <<     << v <<   n ; n     } else { n       cout <<  OPTIMAL n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[200005][2]; n long long a[200005], b[200005]; n void solve() { n   long long n, c; n   cin >> n >> c; n   for (int i = 0; i < n - 1; i++) cin >> a[i]; n   ; n   for (int i = 0; i < n - 1; i++) cin >> b[i]; n   ; n   dp[1][1] = c; n   for (int i = 2; i < n + 1; i++) { n     dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + a[i - 2]; n     dp[i][1] = min(dp[i - 1][0] + c + b[i - 2], dp[i - 1][1] + b[i - 2]); n   } n   for (int i = 1; i < n + 1; i++) cout << min(dp[i][0], dp[i][1]) <<    ; n   cout <<   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 int main() { n   int n; n   while (cin >> n) { n     if (n == 1) n       cout << 8 << endl; n     else if (!n) n       cout << 1 << endl; n     else if (n % 4 == 0) n       cout << 6 << endl; n     else if (n % 4 == 1) n       cout << 8 << endl; n     else if (n % 4 == 2) n       cout << 4 << endl; n     else if (n % 4 == 3) n       cout << 2 << endl; n   } n } n


#include <bits/stdc++.h> n const int maxn = 100100; n int t, T, n, m, n0, n1; n int l[maxn], r[maxn], c[maxn], vis[maxn]; n std::vector<int> v[maxn]; n std::queue<int> q; n inline void dfs(int x) { n   if (vis[x]) return; n   vis[x] = 1; n   for (auto i : v[x]) c[i] = !c[x], dfs(i); n } n int main() { n   std::ios::sync_with_stdio(false), std::cin.tie(0); n   std::cin >> t >> T >> n >> m; n   n1 = 0; n   n0 = T; n   for (int i = 1; i <= n; ++i) { n     std::cin >> l[i] >> r[i], c[i] = -1; n     n0 = std::min(n0, r[i]); n     n1 = std::max(n1, l[i]); n   } n   if (n1 + n0 > T) n0 = T - n1; n   if (n1 + n0 < t) n1 = t - n0; n   if (n0 < 0 || n1 < 0) { n     puts( IMPOSSIBLE ); n     return 0; n   } n   for (int i = 1, x, y; i <= m; ++i) { n     std::cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (int i = 1; i <= n; ++i) { n     if (n1 < l[i] || r[i] < n1) { n       if (c[i] != -1 && c[i] != 0) { n         puts( IMPOSSIBLE ); n         return 0; n       } n       c[i] = 0; n     } n     if (n0 < l[i] || r[i] < n0) { n       if (c[i] != -1 && c[i] != 1) { n         puts( IMPOSSIBLE ); n         return 0; n       } n       c[i] = 1; n     } n     if (c[i] >= 0) dfs(i); n   } n   for (int i = 1; i <= n; ++i) n     if (c[i] == -1) c[i] = 0, dfs(i); n   for (int i = 1; i <= n; ++i) n     for (int j : v[i]) n       if (c[i] + c[j] != 1) { n         puts( IMPOSSIBLE ); n         return 0; n       } n   std::cout <<  POSSIBLE  <<   n  << n0 <<     << n1 <<   n ; n   for (int i = 1; i <= n; ++i) std::cout << c[i] + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int ans = 0; n vector<vector<int> > data; n void relax(int &a, int &b, int c) { n   if (c > a) { n     b = a; n     a = c; n   } else n     b = max(b, c); n } n pair<int, int> dfs(int vertex, int last) { n   int take = 0, take2 = 0, non = 0, non2 = 0; n   for (int i = 0; i < data[vertex].size(); ++i) { n     int to = data[vertex][i]; n     if (to == last) continue; n     pair<int, int> res = dfs(to, vertex); n     relax(take, take2, res.second); n     relax(non, non2, max(res.second, res.first)); n   } n   ans = max(ans, take2 + take + 1); n   ans = max(ans, non2 + non + max(0, (int)data[vertex].size() - 2)); n   ans = max(ans, non + max(0, (int)data[vertex].size() - 1)); n   non += data[vertex].size() - 2; n   return {take + 1, non}; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   data.assign(n, {}); n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     data[u - 1].push_back(v - 1); n     data[v - 1].push_back(u - 1); n   } n   dfs(0, -1); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a <<   n ; n   err(++it, args...); n } n const int M = 1e9 + 7, N = 2e5 + 5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int a[n][m], b[n][m]; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) cin >> a[i][j]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         int c = 0; n         if (i - 1 >= 0) c++; n         if (i + 1 <= n - 1) c++; n         if (j - 1 >= 0) c++; n         if (j + 1 <= m - 1) c++; n         b[i][j] = c; n       } n     } n     bool red = false; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (a[i][j] > b[i][j]) { n           red = true; n           break; n         } n       } n       if (red) break; n     } n     if (red) n       cout <<  NO  n            <<   n ; n     else { n       cout <<  YES  n            <<   n ; n       for (int i = 0; i < n; i++) n         for (int j = 0; j < m; j++) cout << b[i][j] <<    n [j == m - 1]; n       ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (1e9) + 7; n bool mark[2501][101]; n long long a[2501][101]; n long long dp(int x, int y) { n   if (x > 0 && y == 0) return 0; n   if (x == 0 && y == 0) return 1; n   if (mark[x][y]) return a[x][y]; n   long long ans = 0; n   for (int i = 0; i <= min(25, x); i++) ans += dp(x - i, y - 1); n   a[x][y] = (ans % maxn); n   mark[x][y] = 1; n   return a[x][y]; n } n int main() { n   int t, counter; n   string s; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> s; n     counter = 0; n     for (int j = 0; j < s.size(); j++) counter += int(s[j] -  a ); n     cout << (dp(counter, s.size()) + maxn - 1) % maxn << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n long long deg[123456]; n long long N, S, i, s, e; n long long cnt; n long double ans; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> N >> S; n   for (i = 1; i < N; i++) { n     cin >> s >> e; n     deg[s - 1]++; n     deg[e - 1]++; n   } n   for (i = 0; i < N; i++) n     if (deg[i] == 1) cnt++; n   ans = (long double)S * (long double)2 / (long double)cnt; n   cout << fixed << setprecision(20) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int read(T& x) { n   int c = getchar(), f = (x = 0); n   while (~c && (c < 48 || c > 57)) { n     if (c ==  - ) { n       f = 1; n     } n     c = getchar(); n   } n   if (!~c) { n     return 0; n   } n   while (c > 47 && c < 58) { n     x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); n   } n   if (f) { n     x = -x; n   } n   return 1; n } n template <class T, class U> n inline int read(T& a, U& b) { n   return read(a) && read(b); n } n template <class T, class U, class V> n inline int read(T& a, U& b, V& c) { n   return read(a) && read(b) && read(c); n } n inline int read(double& _, double& __) { return scanf( %lf%lf , &_, &__); } n inline int read(char* _) { return scanf( %s , _); } n inline int read(double& _) { return scanf( %lf , &_); } n inline void println(long long _) { printf( %lld n , _); } n inline void println(int _) { printf( %d n , _); } n inline void println(long long _, long long __) { printf( %lld %lld n , _, __); } n inline void println(int _, int __) { printf( %d %d n , _, __); } n inline void println(double& __, int _) { printf( %.*lf n , _, __); } n template <class T> n inline void cmax(T& _, T __) { n   if (_ < __) _ = __; n } n template <class T> n inline void cmin(T& _, T __) { n   if (_ > __) _ = __; n } n const int maxn = 5e3 + 10, INF = 0x3f3f3f3f; n const long long LINF = (long long)INF << 32 | INF; n int link[maxn], ans[maxn]; n bool vis[maxn]; n vector<int> G[maxn]; n int p[maxn], c[maxn], d[maxn], D; n bool leave[maxn]; n bool DFS(int u) { n   for (auto v : G[u]) n     if (!vis[v]) { n       vis[v] = true; n       if (link[v] == -1 || DFS(link[v])) { n         link[v] = u; n         return true; n       } n     } n   return false; n } n int main() { n   int n, m, cur = 0; n   memset(link, -1, sizeof(link)); n   read(n, m); n   for (int i = 1; i <= (n); i++) read(p[i]); n   for (int i = 1; i <= (n); i++) read(c[i]); n   read(D); n   for (int i = 1; i <= (D); i++) read(d[i]), leave[d[i]] = true; n   for (int i = 1; i <= (n); i++) n     if (!leave[i]) G[p[i]].push_back(c[i]); n   for (int i = D; i >= (1); i--) { n     memset(vis, false, sizeof(vis)); n     while (DFS(cur)) memset(vis, false, sizeof(vis)), cur++; n     ans[i] = cur; n     G[p[d[i]]].push_back(c[d[i]]); n   } n   for (int i = 1; i <= (D); i++) println(ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   using namespace std; n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   int tt; n   cin >> tt; n   while (tt--) { n     int N; n     cin >> N; n     string s; n     cin >> s; n     auto solve = [&](void) -> void { n       for (int i = 0; i < N - 10; ++i) { n         if (s[i] ==  8 ) { n           cout <<  YES n ; n           return; n         } n       } n       cout <<  NO n ; n     }; n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int calculate(long long int p, long long int q) { n   long long int modx = 998244353, expo; n   expo = modx - 2; n   while (expo) { n     { n       if (expo & 1) p = (p * q) % modx; n     } n     q = (q * q) % modx; n     expo >>= 1; n   } n   return p % modx; n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) { n       res = (res * x) % p; n     } n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   t = 1; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     string s; n     long long int ans = 1; n     cin >> s; n     if (k == 0) { n       cout << 1 <<   n ; n       continue; n     } n     long long int i = 0, j = 0; n     long long int dp[n + 5][k + 5]; n     memset(dp, 0, sizeof(dp)); n     for (int p = 1; p <= k; p++) { n       dp[0][p] = dp[0][p - 1] + 1; n     } n     for (int p = 1; p <= n; p++) { n       for (int q = 1; q <= k; q++) n         dp[p][q] = (dp[p - 1][q] + dp[p][q - 1]) % 998244353; n     } n     long long int zero = 0, lastzero = 0, one = 0, b = 0; n     while (i < n) { n       if (s[i] ==  0 ) { n         zero++; n         if (one == k) lastzero++; n       } else n         one++; n       if (one > k) { n         for (int p = 0; p < zero; p++) { n           ans = (ans + dp[p][k]) % 998244353; n         } n         long long int temp = 0; n         if (b > 0) { n           for (int p = 0; p < zero - lastzero; p++) { n             temp = (temp + dp[p][k - 1]) % 998244353; n           } n         } n         lastzero = 0; n         b = 1; n         ans = (998244353 + ans - temp) % 998244353; n         while (j < i) { n           if (s[j] ==  1 ) { n             one--; n             j++; n             break; n           } n           j++; n           zero--; n         } n       } n       i++; n     } n     if (one == k) { n       for (int p = 0; p < zero; p++) { n         ans = (ans + dp[p][k]) % 998244353; n       } n       long long int temp = 0; n       if (b > 0) { n         for (int p = 0; p < zero - lastzero; p++) { n           temp = (temp + dp[p][k - 1]) % 998244353; n         } n       } n       ans = (998244353 + ans - temp) % 998244353; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 987654321; n const long long int INF = 123456789987654321; n FILE *fin, *fout; n int V, edge_cnt, source, sink; n vector<int> last_edge, nxt_edge, oppo, capa; n void init() { n   edge_cnt = 0, last_edge.clear(), nxt_edge.clear(), oppo.clear(), capa.clear(), n   last_edge = vector<int>(V, -1); n } n void add(int u, int v, int capa_) { n   nxt_edge.push_back(last_edge[u]), last_edge[u] = edge_cnt, oppo.push_back(v), n                                     capa.push_back(capa_), edge_cnt++; n } n vector<int> dist; n bool bfs() { n   dist.clear(), dist = vector<int>(V, -1); n   queue<int> q; n   q.push(source), dist[source] = 0; n   while (!q.empty()) { n     int now = q.front(); n     q.pop(); n     for (int i = last_edge[now]; i != -1; i = nxt_edge[i]) { n       int nxt = oppo[i]; n       if (capa[i] && dist[nxt] == -1) { n         dist[nxt] = dist[now] + 1; n         q.push(nxt); n       } n     } n   } n   if (dist[sink] == -1) n     return false; n   else n     return true; n } n vector<int> last_edge2; n int dfs(int now, int flow) { n   if (now == sink) return flow; n   for (int i = last_edge2[now]; i != -1; i = nxt_edge[i]) { n     last_edge2[now] = i; n     int nxt = oppo[i]; n     if (capa[i] && dist[nxt] == dist[now] + 1) { n       if (int tmp = dfs(nxt, min(flow, capa[i]))) { n         capa[i] -= tmp; n         capa[i ^ 1] += tmp; n         return tmp; n       } n     } n   } n   return 0; n } n int dinic() { n   int total_flow = 0; n   while (bfs()) { n     last_edge2 = last_edge; n     while (int tmp = dfs(source, inf)) total_flow += tmp; n   } n   return total_flow; n } n int N, M; n struct Func { n   int a, b, c; n }; n vector<Func> F; n vector<pair<int, int> > interval; n struct Restr { n   int u, v, d; n }; n vector<Restr> restr; n int f(int idx, int x) { return F[idx].a * x * x + F[idx].b * x + F[idx].c; } n const int too_big = 10000000; n void get_network() { n   V = 220 * N + 2, source = V - 2, sink = V - 1; n   init(); n   for (int i = 0; i < N; i++) { n     int l = interval[i].first, r = interval[i].second; n     add(source, 220 * i + (l - 1 + 110), inf); n     add(220 * i + (l - 1 + 110), source, 0); n     for (int j = 0; j < 219; j++) { n       add(220 * i + j, 220 * i + j + 1, too_big - f(i, j + 1 - 110)); n       add(220 * i + j + 1, 220 * i + j, 0); n     } n     add(220 * i + (r + 110), sink, inf); n     add(sink, 220 * i + (r + 110), 0); n   } n   for (int i = 0; i < M; i++) { n     int u = restr[i].u, v = restr[i].v; n     for (int j = 0; j < 220; j++) { n       if (j - restr[i].d >= 0 && j - restr[i].d < 220) { n         add(220 * u + j, 220 * v + j - restr[i].d, inf); n         add(220 * v + j - restr[i].d, 220 * u + j, 0); n       } n     } n   } n   printf( %d , too_big * N - dinic()); n } n int main() { n   scanf( %d %d , &N, &M); n   F.resize(N); n   for (int i = 0; i < N; i++) { n     int a, b, c; n     scanf( %d %d %d , &a, &b, &c); n     F[i] = {a, b, c}; n   } n   interval.resize(N); n   for (int i = 0; i < N; i++) { n     scanf( %d %d , &interval[i].first, &interval[i].second); n   } n   restr.resize(M); n   for (int i = 0; i < M; i++) { n     int u, v, d; n     scanf( %d %d %d , &u, &v, &d); n     restr[i] = {--u, --v, d}; n   } n   get_network(); n } n


#include <bits/stdc++.h> n using namespace std; n int dpr[107]; n int dps[107]; n int dpc[107]; n int a[107]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n + 1; i++) scanf( %d , a + i); n   dpr[1] = 1; n   dps[1] = (a[1] == 2 || a[1] == 3) ? 0 : -1; n   dpc[1] = (a[1] == 1 || a[1] == 3) ? 0 : -1; n   for (int i = 2; i < n + 1; i++) { n     dpr[i] = dpr[i - 1]; n     if (dps[i - 1] != -1) dpr[i] = min(dpr[i], dps[i - 1]); n     if (dpc[i - 1] != -1) dpr[i] = min(dpr[i], dpc[i - 1]); n     dpr[i] += 1; n     if (a[i] != 2 && a[i] != 3) n       dps[i] = -1; n     else { n       dps[i] = dpr[i - 1]; n       if (dpc[i - 1] != -1) dps[i] = min(dps[i], dpc[i - 1]); n     } n     if (a[i] != 1 && a[i] != 3) n       dpc[i] = -1; n     else { n       dpc[i] = dpr[i - 1]; n       if (dps[i - 1] != -1) dpc[i] = min(dpc[i], dps[i - 1]); n     } n   } n   int ans = 200; n   ans = min(ans, dpr[n]); n   if (dps[n] != -1) ans = min(ans, dps[n]); n   if (dpc[n] != -1) ans = min(ans, dpc[n]); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adjl[4009]; n set<pair<int, int> > st; n int main() { n   int n, m, a, b; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> a >> b; n     adjl[a].push_back(b); n     adjl[b].push_back(a); n     st.insert(pair<int, int>(a, b)); n     st.insert(pair<int, int>(b, a)); n   } n   int ans = 9999999; n   for (int i = 1; i <= n; i++) { n     if (adjl[i].size() >= 2) { n       for (int j = 0; j < adjl[i].size(); j++) { n         for (int k = j + 1; k < adjl[i].size(); k++) { n           if (st.find(pair<int, int>(adjl[i][j], adjl[i][k])) != st.end()) { n             if (ans > adjl[i].size() + adjl[adjl[i][j]].size() + n                           adjl[adjl[i][k]].size() - 6) n               ans = adjl[i].size() + adjl[adjl[i][j]].size() + n                     adjl[adjl[i][k]].size() - 6; n           } n         } n       } n     } n   } n   if (ans == 9999999) n     cout << -1 << endl; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n const int Maxn = 50005; n int N, A[Maxn]; n double L[Maxn], P[Maxn], Sum[Maxn], Ans; n using namespace std; n bool Cmp(const int &i, const int &j) { n   return (L[i] * P[i] * (1 - P[j] / 100)) > (L[j] * P[j] * (1 - P[i] / 100)); n } n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; ++i) { n     scanf( %lf%lf , &L[i], &P[i]); n     A[i] = i; n   } n   sort(A + 1, A + 1 + N, Cmp); n   for (int i = 1; i <= N; ++i) Sum[i] = Sum[i - 1] + L[A[i]] * P[A[i]]; n   for (int i = 1; i <= N; ++i) Ans += L[i] * 10000; n   for (int i = 2; i <= N; ++i) Ans += (100 - P[A[i]]) * Sum[i - 1]; n   cout << setprecision(12) << setiosflags(ios ::fixed) << Ans / 10000 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int fact[2 * 100005]; n long long int func() { n   fact[0] = fact[1] = 1; n   for (long long int i = 2; i < 200001; i++) { n     fact[i] = (fact[i - 1] * i) % 1000000007; n   } n   return 0; n } n set<pair<int, int> > m; n set<int> k; n set<pair<int, int> > h; n int arr[100005], pp[100005]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     if (x == 1) { n       k.insert(i + 1); n     } else { n       h.insert(make_pair(x, i + 1)); n     } n     arr[i + 1] = x; n     pp[i + 1] = x; n   } n   set<int>::iterator it; n   set<pair<int, int> >::iterator ii, iii; n   set<pair<int, int> > ans; n   int cnt = 0; n   int mm = 0; n   ii = h.begin(); n   iii = h.begin(); n   if (h.size() == 0) { n     if (k.size() > 2) { n       cout <<  NO ; n       return 0; n     } n     cout <<  YES 1 n1 n1 2 ; n     return 0; n   } n   for (ii = h.begin(); iii != h.end();) { n     pair<int, int> p1 = *ii; n     iii = ++ii; n     if (iii == h.end()) break; n     pair<int, int> p2 = *iii; n     ans.insert(make_pair(p1.second, p2.second)); n     arr[p1.second]--; n     arr[p2.second]--; n     mm++; n   } n   if (k.size() && h.size()) { n     pair<int, int> p = *(h.begin()); n     int x = *(k.begin()); n     ans.insert(make_pair(x, p.second)); n     arr[x]--; n     arr[p.second]--; n     k.erase(x); n     mm++; n   } n   if (k.size() && h.size()) { n     pair<int, int> p = *(--h.end()); n     int x = *(k.begin()); n     ans.insert(make_pair(x, p.second)); n     arr[x]--; n     arr[p.second]--; n     k.erase(x); n     mm++; n   } n   for (int i = 1; i <= n; i++) { n     if (arr[i] && k.find(i) == k.end()) m.insert(make_pair(arr[i], i)); n   } n   int gg = 0; n   for (it = k.begin(); it != k.end(); it++) { n     if (arr[*it] == 0) continue; n     m.erase(make_pair(arr[*it], *it)); n     if (m.size() == 0) break; n     pair<int, int> p = *(m.rbegin()); n     ans.insert(make_pair(*it, p.second)); n     m.erase(make_pair(arr[p.second], p.second)); n     arr[p.second]--; n     if (arr[p.second]) m.insert(make_pair(arr[p.second], p.second)); n   } n   int sum = 0; n   for (int i = 0; i < n; i++) { n     sum += pp[i + 1]; n   } n   if (sum < 2 * n - 2) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES   << mm << endl; n   cout << ans.size() << endl; n   for (set<pair<int, int> >::iterator i = ans.begin(); i != ans.end(); i++) { n     cout << (*i).first <<     << (*i).second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned int gcd(unsigned int x, unsigned int y) { n   unsigned int temp; n   if (x < y) { n     temp = x; n     x = y; n     y = temp; n   } n   for (unsigned int i = y; i > 0; i--) { n     if ((x % i == 0) && (y % i == 0)) return i; n   } n   return x; n } n int main() { n   int a, b, n; n   cin >> a >> b >> n; n   while (1) { n     n -= gcd(n, a); n     if (n < 0) { n       cout <<  1 ; n       break; n     } n     n -= gcd(n, b); n     if (n < 0) { n       cout <<  0 ; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, i; n   cin >> a >> b; n   int n; n   for (i = 0; i < 10; i++) { n     if (a < b) { n       a = a * 3; n       b = b * 2; n     } else if (a > b) { n       cout << i; n       break; n     } else if (a == b) { n       cout << i + 1; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1500][1500]; n int visited[1500][1500]; n int n, m; n struct node { n   int x, y; n }; n node vis[1500][1500]; n int main() { n   int sx, sy; n   char x; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf(  n ); n     for (int j = 0; j < m; j++) { n       scanf( %c , &x); n       if (x ==  # ) n         a[i][j] = 0; n       else if (x ==  . ) n         a[i][j] = 1; n       else { n         a[i][j] = 1; n         sx = i; n         sy = j; n       } n     } n   } n   bool flag = false; n   visited[sx][sy] = 1; n   vis[sx][sy].x = sx; n   vis[sx][sy].y = sy; n   queue<node> q; n   node tmp; n   tmp.x = sx; n   tmp.y = sy; n   q.push(tmp); n   while (!q.empty()) { n     tmp = q.front(); n     q.pop(); n     node tmp1, tmp2; n     tmp1.x = tmp.x; n     tmp1.y = tmp.y - 1; n     tmp2 = tmp1; n     tmp1.x = tmp1.x % n; n     tmp1.y = tmp1.y % m; n     if (tmp1.x < 0) tmp1.x += n; n     if (tmp1.y < 0) tmp1.y += m; n     if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) { n       visited[tmp1.x][tmp1.y] = 1; n       vis[tmp1.x][tmp1.y] = tmp2; n       q.push(tmp2); n     } else if (visited[tmp1.x][tmp1.y] == 1 && n                (vis[tmp1.x][tmp1.y].x != tmp2.x || n                 vis[tmp1.x][tmp1.y].y != tmp2.y)) { n       flag = true; n     } n     tmp1.x = tmp.x; n     tmp1.y = tmp.y + 1; n     tmp2 = tmp1; n     tmp1.x = tmp1.x % n; n     tmp1.y = tmp1.y % m; n     if (tmp1.x < 0) tmp1.x += n; n     if (tmp1.y < 0) tmp1.y += m; n     if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) { n       visited[tmp1.x][tmp1.y] = 1; n       vis[tmp1.x][tmp1.y] = tmp2; n       q.push(tmp2); n     } else if (visited[tmp1.x][tmp1.y] == 1 && n                (vis[tmp1.x][tmp1.y].x != tmp2.x || n                 vis[tmp1.x][tmp1.y].y != tmp2.y)) { n       flag = true; n     } n     tmp1.x = tmp.x - 1; n     tmp1.y = tmp.y; n     tmp2 = tmp1; n     tmp1.x = tmp1.x % n; n     tmp1.y = tmp1.y % m; n     if (tmp1.x < 0) tmp1.x += n; n     if (tmp1.y < 0) tmp1.y += m; n     if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) { n       visited[tmp1.x][tmp1.y] = 1; n       vis[tmp1.x][tmp1.y] = tmp2; n       q.push(tmp2); n     } else if (visited[tmp1.x][tmp1.y] == 1 && n                (vis[tmp1.x][tmp1.y].x != tmp2.x || n                 vis[tmp1.x][tmp1.y].y != tmp2.y)) { n       flag = true; n     } n     tmp1.x = tmp.x + 1; n     tmp1.y = tmp.y; n     tmp2 = tmp1; n     tmp1.x = tmp1.x % n; n     tmp1.y = tmp1.y % m; n     if (tmp1.x < 0) tmp1.x += n; n     if (tmp1.y < 0) tmp1.y += m; n     if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) { n       visited[tmp1.x][tmp1.y] = 1; n       vis[tmp1.x][tmp1.y] = tmp2; n       q.push(tmp2); n     } else if (visited[tmp1.x][tmp1.y] == 1 && n                (vis[tmp1.x][tmp1.y].x != tmp2.x || n                 vis[tmp1.x][tmp1.y].y != tmp2.y)) { n       flag = true; n     } n   } n   if (flag) n     printf( Yes n ); n   else n     printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   long long int t = 0; n   long long int i, x = 0; n   while (1) { n     t = 0; n     long long int l = s.length(); n     if (s.length() == 1) { n       break; n     } n     for (i = 0; i < l; i++) { n       t += s[i] -  0 ; n     } n     x++; n     s = to_string(t); n   } n   cout << x; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = (long long)1e9 + 7; n const double PI = 2 * acos(0.0); n const long long oo = 1e17 + 100; n const string DIGITS =  0123456789 , alph =  abcdefghijklmnopqrstuvwxyz , n              ALPH =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ; n const long long N = (long long)1e5 + 200; n vector<long long> g[N]; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, x, y; n   cin >> n >> x >> y; n   vector<long long> l(n), r(n); n   vector<pair<long long, pair<long long, long long> > > a(2 * n); n   for (long long i = 0; i < n; i++) { n     cin >> l[i] >> r[i]; n     a[2 * i] = {l[i], {0, i}}; n     a[2 * i + 1] = {r[i], {1, i}}; n   } n   sort(a.begin(), a.end()); n   stack<long long> past; n   long long p = 0, sum = 0; n   for (long long i = 0; i < 2 * n; i++) { n     if (a[i].second.first == 0) { n       p++; n       long long v = a[i].second.second; n       if (past.empty()) { n         sum = (sum + ((x + (y * (r[v] - l[v]) % M)) % M)) % M; n       } else { n         long long t = past.top(); n         past.pop(); n         if ((l[v] - t) * y < x) n           sum = (sum + ((r[v] - t) * y % M)) % M; n         else n           sum = (sum + ((x + (y * (r[v] - l[v]) % M)) % M)) % M; n       } n     } else { n       p--; n       long long v = a[i].second.second; n       past.push(r[v]); n     } n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n, m; n   cin >> n >> m; n   string s[n], v[n], a[n], o[n], b[n]; n   bool t[n]; n   string buf; n   for (long long i = 0; i < n; i++) { n     cin >> s[i]; n     cin >> buf; n     cin >> buf; n     t[i] = isdigit(buf[0]); n     if (t[i]) n       v[i] = buf; n     else { n       a[i] = buf; n       cin >> o[i] >> b[i]; n     } n   } n   map<string, long long> ms; n   for (long long i = 0; i < n; i++) ms[s[i]] = i; n   ms[ ? ] = n; n   string ans, ans2; n   for (long long i = 0; i < m; i++) { n     long long tmp[2] = {}; n     long long res[n + 1]; n     memset(res, 0, sizeof(res)); n     for (long long k = 0; k < 2; k++) { n       res[n] = k; n       for (long long j = 0; j < n; j++) { n         if (t[j]) { n           res[j] = v[j][i] -  0 ; n           continue; n         } n         long long ba = res[ms[a[j]]], bb = res[ms[b[j]]]; n         if (o[j] ==  AND ) res[j] = ba & bb; n         if (o[j] ==  OR ) res[j] = ba | bb; n         if (o[j] ==  XOR ) res[j] = ba ^ bb; n       } n       for (long long j = 0; j < n; j++) tmp[k] += res[j]; n     } n     if (tmp[0] <= tmp[1]) n       ans +=  0 ; n     else n       ans +=  1 ; n     if (tmp[0] >= tmp[1]) n       ans2 +=  0 ; n     else n       ans2 +=  1 ; n   } n   cout << ans << endl << ans2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n; n   cin >> m >> n; n   int arr[m]; n   for (int i = 0; i < m; i++) cin >> arr[i]; n   int amount = 0; n   sort(arr, arr + m); n   int count = 0; n   for (int j = 0; j < m; j++) { n     if (arr[j] < 0 && count < n) { n       amount += (-arr[j]); n       count++; n     } n   } n   cout << amount; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pd(int ans) { n   if (ans == 1 || ans == 2 || ans == 3 || ans == 5 || ans == 7 || ans == 11) n     return -1; n   int num = ans / 4 - ans % 2; n   return num ? num : -1; n } n int main() { n   int n, m; n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n; i++) { n       scanf( %d , &m); n       printf( %d n , pd(m)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long int a, b; n   double n = 1.000000011, g, h; n   scanf( %lld %lld , &a, &b); n   g = pow(n, b); n   h = a * g; n   printf( %.10lf , h); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e5 + 9; n int book[maxn]; n int main() { n   int q, x; n   scanf( %d%d , &q, &x); n   int now = 0; n   int hu = 0, ans = 0; n   while (q--) { n     int y; n     scanf( %d , &y); n     int h = y % x; n     book[h]++; n     if (h == now) { n       ans++; n       now++; n       while (book[now] > hu && now < x) { n         ans++; n         now++; n       } n       if (now == x) { n         now = 0; n         hu++; n       } n       while (book[now] > hu && now < x) { n         now++; n         ans++; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 999998727899999ll, MAXN = 300001; n long long c[MAXN]; n vector<long long> g[MAXN]; n set<long long> s[MAXN]; n string t; n bool mark[MAXN]; n long long base = 101; n long long diff[MAXN]; n long long ans[MAXN]; n long long n; n void dsu(long long a1, long long a2) { n   set<long long>::iterator it = s[a2].begin(); n   while (it != s[a2].end()) { n     s[a1].insert(*it); n     it++; n   } n   s[a2].clear(); n } n int dfs(long long v, long long h) { n   long long hash = ((h * base) + (t[v - 1] -  a  + 1)) % MOD; n   mark[v] = 1; n   vector<int> child; n   for (int i = 0; i < g[v].size(); i++) { n     long long u = g[v][i]; n     if (!mark[u]) { n       child.push_back(dfs(u, hash)); n     } n   } n   if (child.size() == 0) { n     diff[v] = 1; n     s[v].insert(hash); n     return v; n   } else { n     int w = 0; n     for (int i = 1; i < child.size(); i++) { n       if (s[child[i]].size() > s[child[w]].size()) { n         w = i; n       } n     } n     for (int i = 0; i < child.size(); i++) { n       if (i != w) { n         dsu(child[w], child[i]); n       } n     } n     s[child[w]].insert(hash); n     diff[v] = s[child[w]].size(); n     return child[w]; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> c[i]; n     ans[i] = i; n   } n   cin >> t; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     g[v].push_back(u); n     g[u].push_back(v); n   } n   dfs(1, 0); n   long long mx = 0; n   for (int i = 1; i <= n; i++) { n     mx = max(diff[i] + c[i], mx); n   } n   long long cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (diff[i] + c[i] == mx) { n       cnt++; n     } n   } n   cout << mx << endl; n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n struct TMat { n   long long a[16][16]; n } base, start; n int n, i, c; n long long k, a, b; n void init() { n   memset(base.a, 0, sizeof(base.a)); n   for (int i = 0; i < 16; i++) base.a[i][i] = 1; n   start = base; n } n TMat cur(const int &c) { n   TMat ans; n   memset(ans.a, 0, sizeof(ans.a)); n   ans.a[0][0] = ans.a[1][0] = 1; n   if (c == 0) { n     ans.a[1][0] = 0; n     return ans; n   } n   ans.a[c - 1][c] = ans.a[c][c] = 1; n   for (int i = 1; i < c; i++) n     ans.a[i - 1][i] = ans.a[i][i] = ans.a[i + 1][i] = 1; n   return ans; n } n TMat operator*(const TMat &a, const TMat &b) { n   TMat ans; n   memset(ans.a, 0, sizeof(ans.a)); n   for (int i = 0; i < 16; i++) n     for (int j = 0; j < 16; j++) n       for (int k = 0; k < 16; k++) { n         ans.a[i][j] += a.a[i][k] * b.a[k][j]; n         ans.a[i][j] %= mod; n       } n   return ans; n } n TMat operator^(const TMat &a, const long long &b) { n   if (b == 0) return base; n   TMat ans = a ^ (b / 2); n   ans = ans * ans; n   if (b & 1) ans = ans * a; n   return ans; n } n int main() { n   scanf( %d%I64d , &n, &k); n   init(); n   for (i = 1; i <= n; i++) { n     scanf( %I64d%I64d%d , &a, &b, &c); n     start = start * (cur(c) ^ (min(b, k) - a)); n   } n   printf( %I64d , start.a[0][0]); n } n