#include <bits/stdc++.h> n using namespace std; n struct Tree { n   static const int MAXN = 500010; n   struct Edge { n     int son, dis; n     Edge *pre; n     void add(int _s, int _d, Edge *_p) { son = _s, dis = _d, pre = _p; } n   } edge[MAXN << 1], *pos[MAXN]; n   int sum; n   void clear() { n     sum = 0; n     memset(pos, 0, sizeof(pos)); n   } n   void add(int a, int b, int c) { n     edge[++sum].add(b, c, pos[a]); n     pos[a] = edge + sum; n   } n } T; n const int MAXN = 500010, MAXK = 500010, MAXM = 500010; n struct Edge { n   int from, to, price; n } E[MAXK + MAXM]; n int n, m, k; n void init() { n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 1; i <= k + m; ++i) { n     int u, v, w; n     scanf( %d%d , &u, &v); n     if (i <= k) n       w = -1; n     else n       scanf( %d , &w); n     E[i] = (Edge){u, v, w}; n   } n } n struct DisjointSet { n   static const int MAXN = 500010; n   int fa[MAXN], n; n   void clear(int _n) { n     n = _n; n     for (int i = 1; i <= n; ++i) fa[i] = i; n   } n   int find(int x) { n     if (fa[x] == x) return x; n     return fa[x] = find(fa[x]); n   } n   bool merge(int u, int v) { n     int fx = find(u), fy = find(v); n     if (fx == fy) return false; n     fa[fx] = fy; n     return true; n   } n } DS; n void buildTree() { n   DS.clear(n); n   T.clear(); n   for (int i = 1; i <= k + m; ++i) n     if (DS.merge(E[i].from, E[i].to)) { n       T.add(E[i].from, E[i].to, E[i].price); n       T.add(E[i].to, E[i].from, E[i].price); n     } n } n const int MAXL = 20; n int fa[MAXN][MAXL], l2[MAXN], dep[MAXN]; n void dfs(int x, int f) { n   for (int l = 1; l <= l2[dep[x]]; ++l) fa[x][l] = fa[fa[x][l - 1]][l - 1]; n   for (Tree::Edge *i = T.pos[x]; i; i = i->pre) n     if (i->son != f) { n       fa[i->son][0] = x; n       dep[i->son] = dep[x] + 1; n       dfs(i->son, x); n     } n } n void preset() { n   l2[0] = -1, l2[1] = 0; n   for (int i = 2; i <= n; ++i) l2[i] = l2[i >> 1] + 1; n   memset(fa, 0, sizeof(fa)), dep[1] = 1; n   dfs(1, 0); n } n int lca(int u, int v) { n   if (dep[u] > dep[v]) swap(u, v); n   for (int l = l2[dep[v] - dep[u]]; l >= 0; --l) n     if (dep[v] - (1 << l) >= dep[u]) v = fa[v][l]; n   if (u == v) return u; n   for (int l = l2[dep[u]]; l >= 0; --l) n     if (fa[u][l] != fa[v][l]) u = fa[u][l], v = fa[v][l]; n   return fa[u][0]; n } n const long long INF = ~0ull >> 3; n multiset<int> F[MAXN]; n vector<int> ins[MAXN]; n long long solve(int x, int f, bool mask) { n   long long ans = 0; n   for (Tree::Edge *i = T.pos[x]; i; i = i->pre) n     if (i->son != f) { n       long long ret = solve(i->son, x, (i->dis == -1)); n       if (ret == INF) return INF; n       ans += ret; n       if (F[x].size() < F[i->son].size()) F[x].swap(F[i->son]); n       F[x].insert(F[i->son].begin(), F[i->son].end()); n     } n   for (int val : ins[x]) n     if (val > 0) n       F[x].insert(val); n     else n       F[x].erase(F[x].find(-val)); n   if (!mask) return ans; n   if (x > 1 && F[x].empty()) return INF; n   ans += *F[x].begin(); n   return ans; n } n int main() { n   init(); n   buildTree(); n   preset(); n   for (int i = k + 1; i <= k + m; ++i) { n     int u = E[i].from, v = E[i].to, w = E[i].price; n     int z = lca(u, v); n     if (u != z) ins[u].push_back(w), ins[z].push_back(-w); n     if (v != z) ins[v].push_back(w), ins[z].push_back(-w); n   } n   long long ans = solve(1, 0, false); n   if (ans == INF) n     cout << -1 << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1073741824; n const int N = 200005; n const double PI = 4 * atan(1); n set<char> vowel = { A ,  O ,  Y ,  E ,  U ,  I ,  a ,  o ,  e ,  u ,  y ,  i }; n int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; n int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; 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 * (b / gcd(a, b)); } n bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; } n bool isprime(long long u) { n   for (long long i = 2; i <= (int)sqrt(u); i++) { n     if (u % i == 0) return 0; n   } n   return 1; n } n long long mod(long long to_mod) { n   to_mod %= MOD; n   while (to_mod < 0) to_mod += MOD; n   return to_mod % MOD; n } n long long moduloMultiplication(long long a, long long b, long long mod) { n   long long res = 0; n   a %= mod; n   while (b) { n     if (b & 1) res = (res + a) % mod; n     a = (2 * a) % mod; n     b >>= 1; n   } n   return res; n } n long long power(long long x, long long y) { n   long long res = 1; n   x = x; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n long long n, m, k, q, res, x, y, ans; n string ch, sh, d; n bool ok(string ss, long long len) { n   string second =   ; n   for (int i = 1; i <= max(n / len, m / len); i++) { n     second += ss; n     if (i == n / len) { n       if (ch != second) return 0; n     } n     if (i == m / len) { n       if (sh != second) return 0; n     } n   } n   return 1; n } n int main() { n   cin >> ch; n   cin >> sh; n   n = ch.size(); n   m = sh.size(); n   k = min(n, m); n   long long i = 0; n   d =   ; n   ans = 0; n   x = 0; n   while (i < k && ch[i] == sh[i]) { n     d += ch[i]; n     x++; n     if (n % x == 0 && m % x == 0) { n       if (ok(d, x)) ans++; n     } n     i++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long r = 0, mod = 1e9 + 7, a, b, i, z, x, y; n   cin >> a >> b; n   for (i = 1; i < b; ++i) { n     r += i * a + b * i % mod * (a * (a + 1) / 2 % mod); n     r %= mod; n   } n   cout << r << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int x = 0, y = 0, i, j, count = 0, n; n   cin >> n; n   string s1; n   cin >> s1; n   for (i = 0; i < n - 1; i++) { n     x = 0; n     y = 0; n     for (j = i; j < s1.size(); j++) { n       switch (s1[j]) { n         case  U : n           ++y; n           break; n         case  D : n           --y; n           break; n         case  L : n           --x; n           break; n         case  R : n           ++x; n           break; n       } n       if (x == 0 && y == 0) ++count; n     } n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   int m; n   cin >> m; n   vector<int> b(m); n   for (int i = 0; i < m; ++i) { n     cin >> b[i]; n   } n   int M = -1, cur = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (b[j] % a[i]) continue; n       int x = b[j] / a[i]; n       if (x > M) { n         M = x; n         cur = 1; n       } else if (x == M) n         ++cur; n     } n   } n   cout << cur; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   if (m == 3 && n > 4) return puts( -1 ), 0; n   for (int i = 1; i <= m; i++) printf( %d %d n , i, i * i + 300000); n   for (int i = 1; i <= n - m; i++) printf( %d %d n , i, -i * i - 300000); n } n


#include <bits/stdc++.h> n using namespace std; n int R; n vector<int> hv, use; n vector<char> ans; n int req[1000005]; n int fr[1000005]; n int main() { n   int n; n   scanf( %d , &n); n   if (n >= 1389) n     R = 4; n   else if (n >= 232) n     R = 3; n   else if (n >= 199) n     R = 2; n   else if (n >= 2) n     R = 1; n   else { n     printf( a a n ); n     return 0; n   } n   for (int i = 0; i < R; i++) hv.push_back(0); n   hv.push_back(1); n   for (int i = R + 1;; i++) { n     hv.push_back(hv.back() * i / (i - R)); n     if (hv.back() > n) break; n   } n   for (int &u : hv) u--; n   for (int i = 0; i < 2 * R; i++) hv[i] = 0; n   for (int i = 1; i <= n; i++) req[i] = 10000005; n   for (int i = 0; i <= n; i++) fr[i] = -1; n   for (int i = 1; i <= n; i++) n     for (unsigned j = 0; j < hv.size(); j++) n       if (hv[j] <= i) { n         if (req[i - hv[j]] + j < req[i]) { n           req[i] = req[i - hv[j]] + j; n           fr[i] = j; n         } n       } else n         break; n   n--; n   for (int i = n; i; i -= hv[fr[i]]) use.push_back(fr[i]); n   for (unsigned i = 0; i < use.size(); i++) n     for (int j = 0; j < R; j++) printf( %c ,  a  + i); n   for (int i = use.size() - 1; i >= 0; i--) n     for (int j = 2 * R; j < use[i]; j++) printf( %c ,  a  + i); n   for (unsigned i = 0; i < use.size(); i++) n     for (int j = 0; j < R; j++) printf( %c ,  a  + i); n   printf(   ); n   for (unsigned i = 0; i < use.size(); i++) n     for (int j = 0; j < R; j++) printf( %c ,  a  + i); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000; n long long cost[N][10], step[N][10], n; n int getMax(int x) { n   int ret = 0; n   while (x) { n     ret = max(ret, int(x % 10)); n     x /= 10; n   } n   return ret; n } n void init() { n   for (int i = 0; i < N; i++) { n     int c = getMax(i); n     for (int j = 0; j < 10; j++) { n       int v = max(j, c); n       if (i < v) { n         step[i][j] = 1; n         cost[i][j] = v; n       } else { n         step[i][j] = step[i - v][j] + 1; n         cost[i][j] = cost[i - v][j] + v; n       } n     } n   } n } n int main() { n   init(); n   scanf( %lld , &n); n   long long ans = 0; n   while (n >= N) { n     int j = getMax(n / N); n     ans += step[n % N][j]; n     n -= cost[n % N][j]; n   } n   while (n > 0) { n     int j = getMax(n); n     ans += 1; n     n -= j; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > v; n vector<vector<int> > vv; n vector<vector<long long int> > dp; n void merg(int x) { n   if (v[x].size() == 1) return; n   if (v[x].size() == 2) { n     vector<int> v1; n     v1.push_back(0); n     for (int i = 0; i < v[x * 2].size(); i++) { n       v1.push_back(v[x * 2][i] + v[x][1]); n     } n     v[x] = v1; n     return; n   } n   vector<int> v1 = v[x * 2]; n   vector<int> v2 = v[x * 2 + 1]; n   for (int i = 0; i < v1.size(); i++) v1[i] += v[x][1]; n   for (int i = 0; i < v2.size(); i++) v2[i] += v[x][2]; n   v[x].resize(1); n   int idx1 = 0; n   int idx2 = 0; n   while (idx1 < v1.size() && idx2 < v2.size()) { n     if (v1[idx1] < v2[idx2]) { n       v[x].push_back(v1[idx1]); n       idx1++; n     } else { n       v[x].push_back(v2[idx2]); n       idx2++; n     } n   } n   while (idx1 != v1.size()) v[x].push_back(v1[idx1++]); n   while (idx2 != v2.size()) v[x].push_back(v2[idx2++]); n } n int bs(int a, int h, int l, int r) { n   if (l == r) return l; n   int mid = (l + r) / 2; n   if (v[a][mid] > h) return bs(a, h, l, mid); n   if (v[a][mid + 1] > h) return mid; n   return bs(a, h, mid + 1, r); n } n long long int cal(int a, long long int h) { n   if (h < 0) return 0; n   long long int ans = 0; n   int x = bs(a, h, 0, v[a].size() - 1); n   ans = h * ((long long int)(x + 1)) - dp[a][x]; n   return ans; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int n, m; n   cin >> n >> m; n   v.resize(n + 3); n   vv.resize(n + 3); n   dp.resize(n + 3); n   for (int i = 1; i <= n; i++) v[i].push_back(0); n   int x; n   for (int i = 1; i <= n - 1; i++) { n     cin >> x; n     v[(i + 1) / 2].push_back(x); n     vv[(i + 1) / 2].push_back(x); n   } n   for (int i = n; i >= 1; i--) merg(i); n   for (int i = 1; i <= n; i++) { n     dp[i].push_back(v[i][0]); n     for (int j = 1; j < v[i].size(); j++) { n       dp[i].push_back(((long long int)(v[i][j])) + dp[i][j - 1]); n     } n   } n   for (int i = 0; i < m; i++) { n     int a, h; n     cin >> a >> h; n     long long int ans = 0; n     ans += cal(a, h); n     while (a != 1) { n       if (a % 2 == 0) { n         a /= 2; n         if (h - vv[a][0] <= 0) break; n         ans += h - vv[a][0]; n         if (vv[a].size() == 2) { n           h = h - vv[a][0] - vv[a][1]; n           a = a * 2 + 1; n           ans += cal(a, h); n           a /= 2; n           h += vv[a][1]; n         } else { n           h -= vv[a][0]; n         } n       } else { n         a /= 2; n         if (h - vv[a][1] <= 0) break; n         ans += h - vv[a][1]; n         h = h - vv[a][0] - vv[a][1]; n         a = a * 2; n         ans += cal(a, h); n         a /= 2; n         h += vv[a][0]; n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m, rb, cb, rd, cd; n     int count = 0; n     cin >> n >> m >> rb >> cb >> rd >> cd; n     if (rb <= rd && cb <= cd) n       cout << min(rd - rb, cd - cb) << endl; n     else if (rb <= rd && cb > cd) n       cout << min(rd - rb, 2 * m - cb - cd) << endl; n     else if (cb <= cd && rb > rd) n       cout << min(cd - cb, 2 * n - rb - rd) << endl; n     else n       cout << min(2 * n - rb - rd, 2 * m - cb - cd) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, q, a[3000000 + 5], m[3000000 + 5], dp[3000000 + 5]; n inline long long read() { n   long long q = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = 0; n     ch = getchar(); n   } n   while (isdigit(ch)) q = (q << 3) + (q << 1) + (ch ^ 48), ch = getchar(); n   return f ? q : -q; n } n inline void print(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) print(x / 10); n   putchar(x % 10 + 48); n } n signed main() { n   n = read(); n   for (register long long i = 1; i <= n; ++i) a[i] = read(), ++m[a[i]]; n   for (register long long i = 1; i <= 3000000; ++i) n     if (m[i]) n       for (register long long j = i; j <= 3000000; j += i) n         dp[j] += m[i] * ((i ^ (j / i)) ? m[j / i] : m[i] - 1); n   for (register long long i = 1; i <= 3000000; ++i) dp[i] += dp[i - 1]; n   q = read(); n   while (q--) { n     long long x = read(); n     print(n * (n - 1) - dp[x - 1]), putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long s = 0, w = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) w = -1; n   for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); n   return s * w; n } n inline void print(long long x, int op = 10) { n   if (!x) { n     putchar( 0 ); n     if (op) putchar(op); n     return; n   } n   char F[40]; n   long long tmp = x > 0 ? x : -x; n   if (x < 0) putchar( - ); n   int cnt = 0; n   while (tmp > 0) { n     F[cnt++] = tmp % 10 +  0 ; n     tmp /= 10; n   } n   while (cnt > 0) putchar(F[--cnt]); n   if (op) putchar(op); n } n inline long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans *= a; n     b >>= 1; n     a *= a; n   } n   return ans; n } n long long qpow(long long a, long long b, long long mod) { n   long long ans = 1; n   while (b) { n     if (b & 1) (ans *= a) %= mod; n     b >>= 1; n     (a *= a) %= mod; n   } n   return ans % mod; n } n const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0}, n                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; n const int MOD = 1e9 + 7; n const int INF = 0x3f3f3f3f; n const long long INF64 = 0x3f3f3f3f3f3f3f3f; n const int N = 1e6 + 7; n struct Node { n   long long val; n   int id; n   bool operator<(const Node& opt) const { return val < opt.val; } n }; n long long n, m; n set<int> st; n int p[20]; n int solve() { n   n = read(); n   int cnt = 0; n   for (int i = 1; i <= n; ++i) p[i] = read(), cnt += p[i] == 0; n   st.clear(); n   st.insert(0); n   for (int i = 1; i <= n; ++i) { n     set<int> tmp = st; n     for (auto& it : st) { n       int x1 = it - p[i]; n       int x2 = it + p[i]; n       cnt += x1 == 0; n       cnt += x2 == 0; n       tmp.insert(x1), tmp.insert(x2); n     } n     st = tmp; n   } n   return cnt; n } n int main() { n   int T = read(); n   for (int _ = 1; _ <= T; ++_) { n     cout << (solve() ?  YES  :  NO ) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream& operator<<(ostream& _s, vector<T> _t) { n   for (int i = 0; i < (int)(_t.size()); i++) _s << (i ?     :   ) << _t[i]; n   return _s; n } n template <typename T> n istream& operator>>(istream& _s, vector<T>& _t) { n   for (int i = 0; i < (int)(_t.size()); i++) _s >> _t[i]; n   return _s; n } n template <typename T, typename U> n ostream& operator<<(ostream& _s, pair<T, U> _t) { n   _s <<  (  << _t.first <<  ,  << _t.second <<  ) ; n   return _s; n } n template <typename T, typename U> n istream& operator>>(istream& _s, pair<T, U>& _t) { n   _s >> _t.first >> _t.second; n   return _s; n } n int find(const vector<int>& v, int value, int fr, int to) { n   for (int i = fr; i < (int)(to + 1); i++) { n     if (v[i] == value) { n       return i; n     } n   } n   assert(false); n } n vector<int> invert(const vector<int>& v) { n   vector<int> res(v.size()); n   for (int i = 0; i < (int)(v.size()); i++) { n     res[v[i]] = i; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> p(n); n   cin >> p; n   for (int i = 0; i < (int)(n); i++) p[i]--; n   bool is_id = true; n   for (int i = 0; i < (int)(n); i++) { n     if (p[i] != i) is_id = false; n   } n   string base_s; n   for (int j = 0; j < (int)(n); j++) base_s +=  . ; n   vector<string> res(n); n   for (int i = 0; i < (int)(n); i++) res[i] = base_s; n   if (is_id) { n     cout << n << endl; n     for (int i = 0; i < (int)(n); i++) { n       cout << base_s << endl; n     } n     return 0; n   } n   p = invert(p); n   int fr = 0, to = n - 1; n   for (int row = 0; row < (int)(n); row++) { n     if (row == 0) { n       int mid = n / 2; n       int pos = find(p, mid, fr, to); n       for (int i = fr; i < (int)(pos + 1); i++) { n         res[row][i] =     ; n       } n       for (int i = (pos)-1; i >= (int)(fr); i--) { n         p[i + 1] = p[i]; n       } n       p[fr] = -1; n     } else { n       bool left = row % 2 == 1; n       int free_pos = left ? fr : to; n       assert(p[free_pos] == -1); n       int pos = find(p, free_pos, fr, to); n       if (left) { n         res[row][fr] =  / ; n         for (int i = pos; i < (int)(to + 1); i++) { n           res[row][i] =  / ; n         } n         for (int i = pos; i < (int)(to); i++) { n           p[i] = p[i + 1]; n         } n         p[to] = -1; n         fr++; n       } else { n         res[row][to] =     ; n         for (int i = fr; i < (int)(pos + 1); i++) { n           res[row][i] =     ; n         } n         for (int i = (pos)-1; i >= (int)(fr); i--) { n           p[i + 1] = p[i]; n         } n         p[fr] = -1; n         to--; n       } n     } n   } n   cout << (n - 1) << endl; n   for (int i = 0; i < (int)(n); i++) { n     cout << res[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:16777216 ) n const int inf = 0x3f3f3f3f; n const long double pi = acos(-1.0); n const string debug_line =  yolo ; n const double PI = 4 * atan(1); n long long dp[81][81]; n bool visited[81][81]; n vector<pair<int, int> > Adj[81]; n int n; n vector<pair<pair<int, int>, string> > edge; n bool check(int l, int r, int l1, int r1, int index1, int index2) { n   for (auto &(t1) : (Adj[index1])) { n     int op = t1.first; n     if (op == 0) { n       if (t1.second != index2 && t1.second != index1) { n         return false; n       } n     } else if (op == 2) { n       if (t1.second <= l1 || t1.second >= r1) { n         return false; n       } n     } else if (op == 1) { n       if (t1.second > l && t1.second < r) { n         return false; n       } n     } else if (op == 3) { n       if (!(t1.second > l && t1.second < r)) { n         return false; n       } n     } else if (op == 4) { n       if (!(t1.second <= l1 || t1.second >= r1)) { n         return false; n       } n     } n   } n   for (auto &(t1) : (Adj[index2])) { n     int op = t1.first; n     if (op == 0) { n       if (t1.second != index1 && t1.second != index2) { n         return false; n       } n     } else if (op == 2) { n       if (t1.second <= l1 || t1.second >= r1) { n         return false; n       } n     } else if (op == 1) { n       if (t1.second > l && t1.second < r) { n         return false; n       } n     } else if (op == 3) { n       if (!(t1.second > l && t1.second < r)) { n         return false; n       } n     } else if (op == 4) { n       if (!(t1.second <= l1 || t1.second >= r1)) { n         return false; n       } n     } n   } n   return true; n } n int main() { n   int k; n   scanf( %d%d , &n, &k); n   for (int(i) = (0); (i) < (k); ++(i)) { n     int a, b; n     string c; n     cin >> a >> c >> b; n     edge.push_back(make_pair(make_pair(a, b), c)); n     if (c ==  = ) { n       Adj[a].push_back(make_pair(0, b)); n       Adj[b].push_back(make_pair(0, a)); n     } else if (c ==  > ) { n       Adj[a].push_back(make_pair(1, b)); n       Adj[b].push_back(make_pair(2, a)); n     } else if (c ==  < ) { n       Adj[a].push_back(make_pair(2, b)); n       Adj[b].push_back(make_pair(1, a)); n     } else if (c ==  <= ) { n       Adj[a].push_back(make_pair(3, b)); n       Adj[b].push_back(make_pair(4, a)); n     } else if (c ==  >= ) { n       Adj[a].push_back(make_pair(4, b)); n       Adj[b].push_back(make_pair(3, a)); n     } n   } n   dp[0][2 * n + 1] = 1LL; n   priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >, n                  greater<pair<pair<int, int>, int> > > n       Q1; n   Q1.push(make_pair(make_pair(0, 0), 2 * n + 1)); n   while (!Q1.empty()) { n     pair<pair<int, int>, int> t1 = Q1.top(); n     Q1.pop(); n     int l = t1.first.second; n     int r = t1.second; n     int d = t1.first.first; n     visited[l][r] = true; n     int valueNext = (l + 2 * n + 1 - r) / 2; n     if (l + 3 == r) { n       if (check(l, r, l + 1, r - 1, l + 1, r - 1)) { n         dp[l + 1][r - 1] = (dp[l + 1][r - 1] + dp[l][r]); n       } else { n       } n       continue; n     } else { n       if (check(l, r, l + 2, r, l + 1, l + 2)) { n         dp[l + 2][r] = (dp[l + 2][r] + dp[l][r]); n         if (!visited[l + 2][r]) { n           Q1.push(make_pair(make_pair(d + 1, l + 2), r)); n           visited[l + 2][r] = true; n         } n       } else { n       } n       if (check(l, r, l + 1, r - 1, l + 1, r - 1)) { n         dp[l + 1][r - 1] = (dp[l + 1][r - 1] + dp[l][r]); n         if (!visited[l + 1][r - 1]) { n           Q1.push(make_pair(make_pair(d + 1, l + 1), r - 1)); n           visited[l + 1][r - 1] = true; n         } n       } else { n       } n       if (check(l, r, l, r - 2, r - 1, r - 2)) { n         dp[l][r - 2] = (dp[l][r - 2] + dp[l][r]); n         if (!visited[l][r - 2]) { n           Q1.push(make_pair(make_pair(d + 1, l), r - 2)); n           visited[l][r - 2] = true; n         } n       } else { n       } n     } n   } n   long long answer1 = 0; n   for (int(i) = (0); (i) < (2 * n + 1); ++(i)) { n     answer1 = (answer1 + dp[i][i + 1]); n   } n   printf( %lld n , answer1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, k, q, w, x, y, flag = 0, sum = 0; n   char c; n   while (true) { n     c = getchar(); n     if (c ==   n ) break; n     sum = sum * 10 + int(c -  0 ); n     q = sum / 2; n     sum = sum % 2; n   } n   if (sum == 1 || q % 2 == 1) n     cout <<  0 n ; n   else n     cout <<  4 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 5; n int deg[N]; n vector<int> adj[N]; n int e[N][3]; n int seen[N]; n int dfs(int u) { n   seen[u] = true; n   if (deg[u] == 1) return u; n   for (int i = 0; i < adj[u].size(); i++) n     if (!seen[adj[u][i]]) return dfs(adj[u][i]); n } n int main() { n   int n; n   cin >> n; n   if (n == 2) { n     int x; n     cin >> x >> x >> x; n     cout <<  YES n ; n     cout << 2 <<   n ; n     cout <<  1 2 13 n ; n     cout <<  1 2   << x - 13; n     return 0; n   } n   if (n == 3) { n     cout <<  NO n ; n     return 0; n   } n   for (int i = 0; i < n - 1; i++) { n     int u, v, val; n     cin >> u >> v >> val; n     u--, v--; n     deg[u]++; n     deg[v]++; n     adj[u].push_back(v); n     adj[v].push_back(u); n     e[i][0] = u; n     e[i][1] = v; n     e[i][2] = val; n   } n   for (int i = 0; i < n; i++) n     if (deg[i] == 2) { n       cout <<  NO n ; n       return 0; n     } n   vector<pair<int, pair<int, int>>> ans; n   for (int i = 0; i < n - 1; i++) { n     int u, v, val; n     u = e[i][0]; n     v = e[i][1]; n     val = e[i][2]; n     if (deg[u] == 1 || deg[v] == 1) { n       if (deg[v] == 1) swap(u, v); n       int w, z; n       memset(seen, 0, sizeof seen); n       seen[v] = true; n       vector<int> adj_temp; n       for (int i = 0; adj_temp.size() < 2; i++) n         if (adj[v][i] != u) adj_temp.push_back(adj[v][i]); n       w = dfs(adj_temp[0]); n       z = dfs(adj_temp[1]); n       u++, w++, z++; n       ans.push_back({u, {w, val / 2}}); n       ans.push_back({w, {z, -val / 2}}); n       ans.push_back({u, {z, val / 2}}); n     } else { n       int x, y, w, z; n       vector<int> u_adj, v_adj; n       for (int i = 0; u_adj.size() < 2; i++) n         if (adj[u][i] != v) u_adj.push_back(adj[u][i]); n       for (int i = 0; v_adj.size() < 2; i++) n         if (adj[v][i] != u) v_adj.push_back(adj[v][i]); n       memset(seen, 0, sizeof seen); n       seen[v] = seen[u] = true; n       x = dfs(u_adj[0]); n       y = dfs(u_adj[1]); n       w = dfs(v_adj[0]); n       z = dfs(v_adj[1]); n       x++, y++, w++, z++; n       ans.push_back({x, {w, val / 2}}); n       ans.push_back({x, {y, -val / 2}}); n       ans.push_back({w, {z, -val / 2}}); n       ans.push_back({y, {z, val / 2}}); n     } n   } n   cout <<  YES n ; n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); i++) n     cout << ans[i].first <<     << ans[i].second.first <<     n          << ans[i].second.second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   if (b == 0) return a; n   return gcd(b % a, a); n } n long long int my_pow(long long int a, long long int b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long int half = my_pow(a, b / 2); n   long long int ans = (half * half); n   if (b % 2) { n     ans = (ans * a); n   } n   return ans; n } n long long int my_pow_mod_p(long long int a, long long int b, long long int p) { n   if (b == 0) return 1; n   if (b == 1) return a % p; n   long long int half = my_pow(a, b / 2); n   long long int ans = (half * half) % p; n   if (b % 2) { n     ans = (ans * a) % p; n   } n   return ans; n } n class combinatorics { n   long long int N; n   long long int p; n   vector<long long int> fact; n   void cal() { n     fact[0] = 1; n     fact[1] = 1; n     for (long long int i = 2; i < N; i++) { n       fact[i] = (i * fact[i - 1]) % 1000000007; n     } n   } n  n  public: n   combinatorics(long long int n1, long long int p1) { n     p = p1; n     N = max(n1, 2LL); n     fact.resize(N); n     cal(); n   } n   long long int nPr(long long int n, long long int r) { n     if (n < r) { n       return 0; n     } n     long long int val = (fact[n] * my_pow_mod_p(fact[n - r], p - 2, p)) % p; n     return val; n   } n   long long int nCr(long long int n, long long int r) { n     if (n < r) { n       return 0; n     } n     long long int val = nPr(n, r); n     val = (val * my_pow_mod_p(fact[r], p - 2, p)) % p; n     return val; n   } n   long long int get_fact(long long int n) { return fact[n]; } n }; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   string str1, str2; n   cin >> str1; n   cin >> str2; n   long long int len1 = str1.length(); n   long long int len2 = str2.length(); n   vector<vector<long long int> > V(len2, vector<long long int>()); n   map<char, vector<long long int> > M; n   for (long long int i = 0; i < len2; i++) { n     char curr_char = str2[i]; n     if (M.find(curr_char) == M.end()) { n       M[curr_char] = vector<long long int>(); n     } n     M[curr_char].push_back(i); n   } n   for (long long int i = 0; i < len1; i++) { n     char curr_char = str1[i]; n     if (M.find(curr_char) != M.end()) { n       long long int len = M[curr_char].size(); n       for (long long int j = 0; j < len; j++) { n         V[M[curr_char][j]].push_back(i); n       } n     } n   } n   for (int i = len2 - 2; i >= 0; --i) { n     while (1) { n       long long int last_len = V[i + 1].size(); n       long long int len = V[i].size(); n       if (V[i][len - 1] >= V[i + 1][last_len - 1]) { n         V[i].pop_back(); n       } else { n         break; n       } n     } n   } n   vector<long long int> min_A; n   long long int last_val = V[0][0]; n   min_A.push_back(V[0][0]); n   for (long long int i = 1; i < len2; i++) { n     long long int next_idx = n         upper_bound(V[i].begin(), V[i].end(), last_val) - V[i].begin(); n     long long int next_val = V[i][next_idx]; n     min_A.push_back(next_val); n     last_val = next_val; n   } n   long long int ans = V[0][V[0].size() - 1]; n   for (long long int i = 0; i < len2 - 1; i++) { n     long long int next_s = V[i + 1].size(); n     ans = max(ans, V[i + 1][next_s - 1] - min_A[i] - 1); n   } n   ans = max(ans, len1 - min_A[len2 - 1] - 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<ll, ll>; n const ll MOD = 1e9 + 7, N = 2e5 + 10; n vector<ll> g[N]; n ll vis[N]; n ll n, m, k; n void bfs(ll s, vector<ll> &dist) { n   for (ll i = 1; i < n + 1; i++) { n     vis[i] = 0; n   } n   dist[s] = 0; n   queue<pii> q; n   q.push({s, 0}); n   while (!q.empty()) { n     ll nd = q.front().first, st = q.front().second; n     q.pop(); n     if (vis[nd]) continue; n     vis[nd] = 1; n     dist[nd] = min(dist[nd], st); n     for (auto &v : g[nd]) { n       q.push({v, st + 1}); n     } n   } n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> k; n   vector<ll> spec; n   spec.assign(k, 0); n   for (ll i = 0; i < k; i++) { n     cin >> spec[i]; n   } n   ll u, v; n   for (ll i = 0; i < m; i++) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   vector<ll> dist_src(n + 2, INT_MAX), dist_dest(n + 2, INT_MAX); n   bfs(1, dist_src); n   bfs(n, dist_dest); n   vector<pii> tmp; n   for (auto &i : spec) { n     tmp.push_back({dist_dest[i] - dist_src[i], i}); n   } n   sort(tmp.begin(), tmp.end()); n   ll ans = 0; n   for (ll i = 1; i < k; i++) { n     ll a = tmp[i - 1].second, b = tmp[i].second; n     ll path = n         min(dist_src[a] + dist_dest[b] + 1, dist_src[b] + dist_dest[a] + 1); n     if (path >= dist_src[n]) { n       cout << dist_src[n] <<   n ; n       return 0; n     } n     ans = max(ans, path); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int str2int(string s) { n   istringstream ss(s); n   int t; n   ss >> t; n   return t; n } n int main() { n   string s; n   cin >> s; n   int ans = -1; n   for (int i = 1; i < s.length(); i++) { n     string s1 = s.substr(0, i); n     if (s1.length() > 1 && s1[0] ==  0 ) continue; n     int t1 = str2int(s1); n     if (t1 > 1000000) continue; n     for (int j = 1; j < s.length(); j++) { n       if (i + j >= s.length()) continue; n       string s2 = s.substr(i, j); n       string s3 = s.substr(i + j); n       if (s2.length() > 1 && s2[0] ==  0 ) continue; n       if (s3.length() > 1 && s3[0] ==  0 ) continue; n       int t2 = str2int(s2); n       int t3 = str2int(s3); n       if (t2 > 1000000) continue; n       if (t3 > 1000000) continue; n       int temp = t1 + t2 + t3; n       if (temp > ans) ans = temp; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n inline int calc(int x, int y, char c) { n   if (c ==  & ) return x & y; n   if (c ==  | ) return x | y; n   return x ^ y; n } n int work() { n   char c; n   scanf( %c , &c); n   if (c ==  ( ) { n     int l = work(); n     char op; n     scanf( %c , &op); n     int r = work(), res = 0; n     scanf( %*c ); n     for (int i = 0; i < 4; i++) { n       if (!(l & (1 << i))) continue; n       for (int j = 0; j < 4; j++) { n         if (!(r & (1 << j))) continue; n         res |= 1 << calc(i, j, op); n       } n     } n     return res; n   } n   if (c ==  ? ) return 6; n   return c ==  0  ? 1 : 8; n } n int main() { n   scanf( %*d n ); n   puts(work() & 6 ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n const long double pi = acos(-1.0); n const long double eps = 1e-5; n const int INF = 0x3f3f3f3f; n const long long INFLL = 0x3f3f3f3f3f3f3f3f; n int a[300010]; n int main() { n   ios::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     map<int, int> l; n     map<int, int> r; n     for (int i = (1); i <= (n); i++) { n       cin >> a[i]; n       if (!l[a[i]]) l[a[i]] = i; n       r[a[i]] = i; n     } n     int ans = l.size(); n     int p = 0; n     int cnt = 0; n     int res = 0; n     for (auto it : l) { n       if (p < it.second) n         cnt++; n       else n         cnt = 1; n       p = r[it.first]; n       res = max(res, cnt); n     } n     cout << ans - res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007LL; n long long large = 2000000000000000000LL; n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<int> > adj(n, vector<int>()); n   set<pair<int, int> > s; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     if (x > y) swap(x, y); n     s.insert(pair<int, int>(x, y)); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   int u = -1, v = -1; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (s.find(pair<int, int>(i, j)) == s.end()) { n         u = i; n         v = j; n         break; n       } n     } n   } n   if (u == -1) { n     cout <<  NO  << endl; n     return 0; n   } n   cout <<  YES  << endl; n   vector<vector<int> > adjt(n, vector<int>()); n   for (int i = 0; i < n; i++) { n     int f = i; n     if (f == v) f = u; n     for (int j = 0; j < (int)adj[i].size(); j++) { n       int to = adj[i][j]; n       if (to == v) to = u; n       adjt[f].push_back(to); n     } n   } n   queue<int> q; n   q.push(u); n   vector<int> dis(n, -1); n   dis[u] = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int j = 0; j < (int)adjt[u].size(); j++) { n       int v = adjt[u][j]; n       if (dis[v] == -1) { n         dis[v] = dis[u] + 1; n         q.push(v); n       } n     } n   } n   vector<pair<int, int> > e; n   for (int i = 0; i < n; i++) { n     if (i != v) e.push_back(pair<int, int>(dis[i], i)); n   } n   sort(e.begin(), e.end()); n   vector<int> a(n, -1); n   for (int i = 0; i < (int)e.size(); i++) a[e[i].second] = n - 2 - i; n   a[v] = n - 1; n   for (int i = 0; i < n; i++) printf( %d  , a[i] + 1); n   printf(  n ); n   a[v] = n - 2; n   for (int i = 0; i < n; i++) printf( %d  , a[i] + 1); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long arr64[200020]; n int n, tn, tS, qS = 1; n pair<int, long long> pr[200020]; n arr64 pX, pY, K, B; n int main() { n   long long s; n   scanf( %d%I64d , &n, &s); n   for (int i = 1; i <= n; i++) scanf( %d%d , &pr[i].first, &pr[i].second); n   sort(pr + 1, pr + n + 1); n   pr[++n] = make_pair((int)1e9, s); n   for (int i = 1; i <= n; i++) n     if (i == 1 || pr[i].first > pr[i - 1].first) { n       while (tn > 0 && pr[i].second <= pr[tn].second) tn--; n       pr[++tn] = pr[i]; n     } n   K[tS = 1] = pr[1].first; n   for (int i = 2; i <= tn; i++) { n     qS = min(qS, tS); n     while (qS < tS && n            (((pr[i].second - B[qS + 1]) / (K[qS + 1]) + n              ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) < n                 ((pr[i].second - B[qS]) / (K[qS]) + n                  ((pr[i].second - B[qS]) % (K[qS]) != 0)) || n             ((pr[i].second - B[qS + 1]) / (K[qS + 1]) + n              ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) == n                     ((pr[i].second - B[qS]) / (K[qS]) + n                      ((pr[i].second - B[qS]) % (K[qS]) != 0)) && n                 (K[qS + 1] * ((pr[i].second - B[qS + 1]) / (K[qS + 1]) + n                               ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) + n                  B[qS + 1] - pr[i].second) >= n                     (K[qS] * ((pr[i].second - B[qS]) / (K[qS]) + n                               ((pr[i].second - B[qS]) % (K[qS]) != 0)) + n                      B[qS] - pr[i].second))) n       qS++; n     long long cX = ((pr[i].second - B[qS]) / (K[qS]) + n                     ((pr[i].second - B[qS]) % (K[qS]) != 0)), n               cK = pr[i].first; n     long long cY = (K[qS] * ((pr[i].second - B[qS]) / (K[qS]) + n                              ((pr[i].second - B[qS]) % (K[qS]) != 0)) + n                     B[qS] - pr[i].second), n               cB = cY - cK * cX; n     if (i == tn) printf( %I64d n , cX); n     while (tS > 1 && cK * pX[tS - 1] + cB >= pY[tS - 1]) tS--; n     K[++tS] = cK, B[tS] = cB; n     pX[tS - 1] = (((B[tS - 1] - B[tS])) / ((K[tS] - K[tS - 1])) + n                   (((B[tS - 1] - B[tS])) % ((K[tS] - K[tS - 1])) != 0)); n     pY[tS - 1] = cK * pX[tS - 1] + cB; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 200010; n const long long mod = 1000000007; n const long long inf = 1000000000000000000; n const long double pi = 3.14159265358979323846264338; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort((a).begin(), (a).end()); n   long long int ans = 0, cnt = 1; n   for (long long int i = 0; i < n; i++) { n     if (a[i] >= cnt) ans++, cnt++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n T abs(T x) { n   return x < 0 ? -x : x; n } n template <typename T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n const int MOD = (int)1e+9 + 7; n int n; n vector<pair<int, int> > a; n vector<int> f; n int powmod(const int a, const int b) { n   if (b == 0) { n     return 1; n   } n   long long r = powmod(a, b >> 1); n   (r *= r) %= MOD; n   return b & 1 ? r * a % MOD : r; n } n int divmod(const int a, const int b) { n   return a * (long long)powmod(b, MOD - 2) % MOD; n } n int C(int n, int m) { return divmod(divmod(f[n], f[m]), f[n - m]); } n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   f.resize(n + 1); n   f[0] = 1; n   for (int i = 1; i <= n; ++i) { n     f[i] = f[i - 1] * (long long)i % MOD; n   } n   for (int i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     if (x) { n       a.push_back(make_pair(x, i)); n     } n   } n   sort(a.begin(), a.end()); n   if (a.size() == 0) { n     cout << powmod(2, n - 1) << endl; n     return 0; n   } n   int ans = 0; n   for (int d = -1; d <= 1; d += 2) { n     int l = a[0].second + d * (a[0].first - 1), r = a[0].second; n     if (l > r) { n       swap(l, r); n     } n     if (l < 1 || n < r || (l == r && d == 1)) { n       continue; n     } n     long long res = 1; n     for (size_t i = 1; i < a.size(); ++i) { n       bool f = false; n       for (int j = -1; j <= 1; j += 2) { n         int L = a[i].second + j * (a[i].first - 1), R = a[i].second + j; n         if (L > R) { n           swap(L, R); n         } n         if (L < 1 || n < R || R < r || l < L) { n           continue; n         } n         (res *= C(l - L + R - r, l - L)) %= MOD; n         f = true; n         l = L; n         r = R; n         if (r < a[i].second) { n           ++r; n         } else { n           --l; n         } n         break; n       } n       if (!f) { n         res = 0; n         break; n       } n     } n     if (res) { n       int L = 1, R = n; n       (res *= C(l - L + R - r, l - L)) %= MOD; n     } n     (ans += res) %= MOD; n   } n   if (a[0].first > 1) { n     ans = ans * (long long)powmod(2, a[0].first - 2) % MOD; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const int N = 110; n struct T { n   int bits; n   int x; n   int k; n }; n bool cmp(const T& a, const T& b) { return a.k < b.k; } n T a[N]; n long long dp[(1 << 20) + 4]; n int n, m; n long long b; n long long Ans() { n   const long long INF = 1LL << 60; n   long long res = 0; n   long long ans = INF; n   int top = 1 << m; n   for (int i = 0; i < top; ++i) dp[i] = 1LL << 60; n   dp[0] = 0; n   res = a[0].k * b; n   dp[a[0].bits] = a[0].x; n   ans = min(ans, dp[top - 1] + res); n   for (int i = 1; i < n; ++i) { n     res = a[i].k * b; n     int& bits = a[i].bits; n     for (int j = top - 1; j >= 0; --j) n       if (dp[j] != INF) { n         dp[j | bits] = min(dp[j | bits], dp[j] + a[i].x); n       } n     ans = min(ans, dp[top - 1] + res); n   } n   if (ans == INF) ans = -1; n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> b; n   int s, t; n   for (int i = 0; i < n; ++i) { n     cin >> a[i].x >> a[i].k >> s; n     a[i].bits = 0; n     for (int j = 0; j < s; ++j) { n       cin >> t; n       a[i].bits |= 1 << (t - 1); n     } n   } n   sort(a, a + n, cmp); n   cout << Ans() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b; n int main() { n   cin >> n >> a >> b; n   for (long long tx = 0; tx <= n; tx += a) { n     if ((n - tx) % b == 0) { n       cout <<  YES  << endl << tx / a <<     << (n - tx) / b << endl; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[100010]; n int dp[26][100010]; n int maxP[260][260][260]; n int len[3]; n int idx[3]; n char desc[3][260]; n int get(int rel) { n   int m = maxP[idx[0] - (rel == 0)][idx[1] - (rel == 1)][idx[2] - (rel == 2)]; n   if (m == 100010) return 100010; n   return dp[desc[rel][idx[rel] - 1] -  a ][m]; n } n int main(void) { n   setbuf(stdout, 0); n   int N, Q; n   cin >> N >> Q; n   cin >> str; n   for (int i = 0; i < 26; i++) dp[i][N] = 100010; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < 26; j++) { n       if (str[N - 1 - i] ==  a  + j) n         dp[j][N - 1 - i] = N - i; n       else n         dp[j][N - 1 - i] = dp[j][N - i]; n     } n   } n   for (int q = 0; q < Q; q++) { n     char o, c; n     int i; n     cin >> o >> i; n     i--; n     if (o ==  + ) { n       cin >> c; n       desc[i][len[i]++] = c; n       idx[i] = len[i]; n       if (i == 0) { n         for (int j = 0; j <= len[1]; j++) { n           idx[1] = j; n           for (int k = 0; k <= len[2]; k++) { n             idx[2] = k; n             maxP[len[0]][j][k] = get(i); n             if (j) maxP[len[0]][j][k] = min(maxP[len[0]][j][k], get(1)); n             if (k) maxP[len[0]][j][k] = min(maxP[len[0]][j][k], get(2)); n           } n         } n       } n       if (i == 1) { n         for (int j = 0; j <= len[0]; j++) { n           idx[0] = j; n           for (int k = 0; k <= len[2]; k++) { n             idx[2] = k; n             maxP[j][len[1]][k] = get(i); n             if (j) maxP[j][len[1]][k] = min(maxP[j][len[1]][k], get(0)); n             if (k) maxP[j][len[1]][k] = min(maxP[j][len[1]][k], get(2)); n           } n         } n       } n       if (i == 2) { n         for (int j = 0; j <= len[0]; j++) { n           idx[0] = j; n           for (int k = 0; k <= len[1]; k++) { n             idx[1] = k; n             maxP[j][k][len[2]] = get(i); n             if (j) maxP[j][k][len[2]] = min(maxP[j][k][len[2]], get(0)); n             if (k) maxP[j][k][len[2]] = min(maxP[j][k][len[2]], get(1)); n           } n         } n       } n     } else n       len[i]--; n     cout << (maxP[len[0]][len[1]][len[2]] < 100010 ?  YES n  :  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void task(); n int main() { n   task(); n   return 0; n } n const int N = (int)1e5 + 10; n const int MODULO = (int)1e9 + 3; n const long long int INF = (long long int)1e18; n const int BUF_SIZE = (int)1e5 + 10; n bool used[110]; n int n, k; n int a[110], b[110]; n long long int cat[110][110]; n void comp_cat() { n   cat[0][0] = 0; n   for (int i = 1; i < 101; ++i) { n     cat[i][0] = cat[i][i] = 1; n     for (int j = 1; j < i; ++j) { n       cat[i][j] = cat[i - 1][j - 1] + cat[i - 1][j]; n     } n   } n } n void task() { n   scanf( %d %d , &n, &k); n   int cnt = n / k; n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   double ansmin = 100500, ansmax = -1; n   int q; n   scanf( %d , &q); n   while (q--) { n     for (int i = 0; i < cnt; ++i) scanf( %d , &b[i]); n     int sum = 0; n     if (used[b[0]]) { n       continue; n     } n     for (int i = 0; i < cnt; ++i) { n       sum += a[b[i]]; n       used[b[i]] = 1; n     } n     ansmin = min(ansmin, (double)sum / cnt); n     ansmax = max(ansmax, (double)sum / cnt); n   } n   vector<int> v; n   for (int i = 1; i <= n; ++i) n     if (!used[i]) v.push_back(a[i]); n   sort(v.begin(), v.end()); n   int sz = v.size(); n   (void(1)); n   if (sz > n % k) { n     int sum = 0; n     for (int i = 0; i < cnt; ++i) { n       sum += v[i]; n     } n     ansmin = min(ansmin, (double)sum / cnt); n     sum = 0; n     for (int i = sz - 1; i >= sz - cnt; --i) { n       sum += v[i]; n     } n     ansmax = max(ansmax, (double)sum / cnt); n   } n   printf( %.10f %.10f , ansmin, ansmax); n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = INT_MAX, df = 3e5 + 7; n long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, dp[df], pos[df], n     a[df]; n inline long long read() { n   long long x = 0, y = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) y = (ch ==  - ) ? -1 : 1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) n     x = (x << 3) + (x << 1) + ch -  0 , ch = getchar(); n   return x * y; n } n bool chk(long long x) { n   dp[1] = 0; n   for (long long i = (2); i <= (n); ++i) { n     dp[i] = dp[i - 1]; n     if (dp[i - 1] >= pos[i] - 1) dp[i] = max(dp[i], pos[i] + x); n     if (dp[i - 1] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i]); n     if (dp[i - 2] >= pos[i] - x - 1 && i > 2) n       dp[i] = max(dp[i], pos[i - 1] + x); n   } n   if (dp[n] >= m - x - 1) return 1; n   dp[2] = max(pos[2], x); n   for (long long i = (3); i <= (n); ++i) { n     dp[i] = dp[i - 1]; n     if (dp[i - 1] >= pos[i] - 1) dp[i] = max(dp[i], pos[i] + x); n     if (dp[i - 1] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i]); n     if (dp[i - 2] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i - 1] + x); n   } n   if (dp[n] >= min(m - 1, m + pos[2] - x - 1)) return 1; n   return 0; n } n int main() { n   m = read(); n   n = read(); n   long long now = 1; n   for (long long i = (1); i <= (n); ++i) a[i] = read(), a[i + n] = a[i] + m; n   if (n == 1) { n     return printf( %lld n , m - 1), 0; n   } n   for (long long i = (2); i <= (n); ++i) n     if (a[now + 1] - a[now] < a[i + 1] - a[i]) now = i; n   long long le = 0, rig = a[now + 1] - a[now] - 1, mid = 0, ans = 0; n   for (long long i = (1); i <= (n); ++i) pos[i] = a[i + now]; n   long long cur = pos[1]; n   for (long long i = (1); i <= (n); ++i) pos[i] -= cur; n   while (le <= rig) { n     mid = (le + rig) >> 1; n     if (chk(mid)) n       ans = mid, rig = mid - 1; n     else n       le = mid + 1; n   } n   return printf( %lld n , ans), 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chmin(T& a, const T& b) { n   return a > b ? a = b, true : false; n } n template <class T> n bool chmax(T& a, const T& b) { n   return a < b ? a = b, true : false; n } n const long long mod = 1e9 + 7, N = 2e5 + 5; n inline long long msb(long long val) { n   return sizeof(long long) * 8 - __builtin_clzll(val) - 1; n } n long long a[N], n, m, k; n vector<pair<long long, long long> > edges[N]; n bool check(long long a) { n   while (a > 0) { n     if (a % 10 != 4 && a % 10 != 7) return false; n     a /= 10; n   } n   return true; n } n struct des { n   vector<long long> p, rnk, sz; n   void init() { n     p.assign(n + 1, 0); n     rnk.assign(n + 1, 0); n     sz.assign(n + 1, 1); n     for (long long i = 0; i < n; i++) p[i] = i; n   } n   long long par(long long u) { n     if (p[u] == u) n       return u; n     else n       return p[u] = par(p[u]); n   } n   bool issame(long long u, long long v) { return (par(u) == par(v)); } n   void merge(long long u, long long v) { n     u = par(u); n     v = par(v); n     if (u == v) return; n     if (rnk[u] > rnk[v]) { n       p[v] = u; n       sz[u] += sz[v]; n       rnk[u]++; n     } else { n       p[u] = v; n       sz[v] += sz[u]; n       rnk[v]++; n     } n   } n   long long get_size(long long u) { return sz[par(u)]; } n } d; n void solve(long long test_case) { n   long long i, j; n   cin >> n; n   d.init(); n   for (i = 1; i < n; i++) { n     long long u, v, w; n     cin >> u >> v >> w; n     if (!check(w)) d.merge(u, v); n   } n   long long ans = 0; n   for (i = 1; i <= n; i++) { n     long long t = n - d.get_size(i); n     ans += t * (t - 1); n   } n   cout << ans <<   n ; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   solve(1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 123456; n int n, d[N], h[N]; n bool vis[N]; n vector<int> G[N]; n struct Node { n   int u, h; n   bool operator<(const Node& rhs) const { return h < rhs.h; } n   Node(int u, int h) : u(u), h(h) {} n }; n priority_queue<Node> pq; n int bfs() { n   memset(d, -1, sizeof(d)); n   d[1] = 0; n   queue<int> q; n   q.push(1); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int v : G[u]) n       if (d[v] == -1) { n         d[v] = d[u] + 1; n         q.push(v); n       } n   } n   int ans = 1, maxm = 0; n   for (int i = 2; i <= n; i++) n     if (d[i] > maxm) { n       maxm = d[i]; n       ans = i; n     } n   return ans; n } n int dfs(int u, int fa) { n   for (int v : G[u]) n     if (v != fa) h[u] = max(h[u], dfs(v, u) + 1); n   if (fa) pq.push(Node(u, h[u])); n   return h[u]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   int root = bfs(); n   dfs(root, 0); n   cout << 1; n   int cnt = 1; n   for (int i = 2; i <= n; i++) { n     if (cnt == n) { n       cout <<     << n; n       continue; n     } n     int cur = 0; n     while (!pq.empty()) { n       Node u = pq.top(); n       pq.pop(); n       if (!vis[u.u]) { n         cur = u.u; n         break; n       } n     } n     for (;;) { n       cnt++; n       vis[cur] = true; n       if (!h[cur]) break; n       for (int v : G[cur]) n         if (h[v] == h[cur] - 1) { n           cur = v; n           break; n         } n     } n     cout <<     << cnt; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> f; n long long fib[100] = {0}; n int solve(long long n) { n   int what[100] = {0}; n   int ind = -1; n   for (int i = 90; i >= 0; i--) { n     if (n >= fib[i]) { n       n -= fib[i], what[i] = true; n       if (ind == -1) ind = i; n     } n   } n   vector<int> x, y; n   x.push_back(1); n   y.push_back(0); n   int zero = 0, f = 1; n   for (int i = 0; i <= ind; i++) { n     if (what[i] == 0) n       zero++; n     else { n       int z1 = (zero / 2) * (x.back() + y.back()); n       if (zero & 1 && !f) z1 += x.back(); n       int z2 = x.back() + y.back(); n       x.push_back(z1); n       y.push_back(z2); n       zero = 0; n       f = false; n     } n   } n   return x.back() + y.back(); n } n int main() { n   fib[0] = 1; n   fib[1] = 2; n   for (int i = 2; i <= 90; i++) fib[i] = fib[i - 1] + fib[i - 2]; n   int T; n   long long n; n   cin >> T; n   while (T--) { n     cin >> n; n     cout << solve(n) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9 + 1e8; n const long long INF = 2e18 + 1e17; n const int mod = 998244353; n const int MOD = 1e9 + 7; n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n bool is_prime(int x) { n   if (x <= 1 || (x % 2 == 0 && x > 2)) return false; n   for (int i = 3; i * i <= x; i += 2) { n     if (!(x % i)) { n       return false; n     } n   } n   return true; n } n const int MAXN = 40010; n int N; n string str; n vector<int> arr; n int ans; n int main() { n   cin >> N >> str; n   arr.resize(N); n   int sum = 0; n   for (int i = 0; i < str.length(); i++) { n     arr[i] = (str[i] ==  )  ? -1 : 1); n     sum += arr[i]; n   } n   if (sum != 0) { n     cout <<  -1  << endl; n     return 0; n   } n   int cur = 0, last = 0; n   bool bad = false; n   for (int i = 0; i < N; i++) { n     cur += arr[i]; n     if (!bad && cur < 0) { n       bad = true; n       last = i; n     } else if (cur == 0 && bad) { n       ans += (i - last + 1); n       bad = false; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s1, s2; n   cin >> s1 >> s2; n   int n = s1.size(); n   int m = s2.size(); n   pair<pair<int, int>, pair<int, char> > parent[n + 1][m + 1][205]; n   int dp[n + 5][m + 5][205]; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       for (int bal = 0; bal <= 200; bal++) { n         dp[i][j][bal] = 600; n       } n     } n   } n   dp[0][0][0] = 0; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       for (int bal = 0; bal <= 200; bal++) { n         if (dp[i][j][bal] == 600) continue; n         int newI = i + (i < n && s1[i] ==  ( ); n         int newJ = j + (j < m && s2[j] ==  ( ); n         if (bal + 1 < 205 && dp[newI][newJ][bal + 1] > dp[i][j][bal] + 1) { n           dp[newI][newJ][bal + 1] = dp[i][j][bal] + 1; n           parent[newI][newJ][bal + 1] = n               make_pair(make_pair(i, j), make_pair(bal,  ( )); n         } n         newI = i + (i < n && s1[i] ==  ) ); n         newJ = j + (j < m && s2[j] ==  ) ); n         if (bal > 0 && dp[newI][newJ][bal - 1] > dp[i][j][bal] + 1) { n           dp[newI][newJ][bal - 1] = dp[i][j][bal] + 1; n           parent[newI][newJ][bal - 1] = n               make_pair(make_pair(i, j), make_pair(bal,  ) )); n         } n       } n     } n   } n   int cBal = 0; n   for (int bal = 0; bal <= 200; bal++) { n     if (dp[n][m][bal] + bal < dp[n][m][cBal] + cBal) { n       cBal = bal; n     } n   } n   int ci = n, cj = m; n   string res = string(cBal,  ) ); n   while (ci > 0 || cj > 0 || cBal != 0) { n     int nci = parent[ci][cj][cBal].first.first; n     int ncj = parent[ci][cj][cBal].first.second; n     int ncBal = parent[ci][cj][cBal].second.first; n     res += parent[ci][cj][cBal].second.second; n     ci = nci; n     cj = ncj; n     cBal = ncBal; n   } n   reverse(res.begin(), res.end()); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int DEBUG = 0; n double Min(double a, double b) { return (a < b ? a : b); } n double Max(double a, double b) { return (a > b ? a : b); } n double Abs(double a) { return (a >= 0 ? a : -a); } n void print1d(int *vec, int M, const char *str = NULL) { n   if (str != NULL) printf( %s  , str); n   for (int i = 0; i < M; i++) { n     if (i > 0) printf(   ); n     printf( %d , vec[i]); n   } n   printf(  n ); n } n struct NODE { n   double t, v; n }; n int compare_NODE_inc(const void *a_, const void *b_) { n   NODE *a = (NODE *)a_; n   NODE *b = (NODE *)b_; n   if (a->t > b->t) n     return 1; n   else if (a->t < b->t) n     return -1; n   else n     return 0; n } n int main(int argc, char **argv) { n   DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; n   int n; n   double a, d; n   cin >> n >> a >> d; n   NODE bus[n]; n   for (int i = 0; i < n; i++) { n     cin >> bus[i].t >> bus[i].v; n   } n   qsort(bus, n, sizeof(NODE), compare_NODE_inc); n   double prevt = 0; n   double tim; n   for (int i = 0; i < n; i++) { n     double t = bus[i].t; n     double v = bus[i].v; n     if (v * v >= 2.0 * a * d) { n       tim = t + sqrt(2.0 * d / a); n     } else { n       tim = t + (1.0 * d / v + 1.0 * v / 2.0 / a); n     } n     prevt = Max(tim, prevt); n     printf( %.10f n , prevt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:8000000 ) n int main() { n   int n; n   scanf( %d , &n); n   if (n % 2 == 1) { n     printf( -1 ); n     return 0; n   } n   for (int k = 0; k != n; ++k) n     for (int i = 0; i != n; ++i) { n       for (int j = 0; j != n; ++j) n         if ((j % 4 < 2) ^ (k % 2 == 0) ^ (i % 4 < 2)) n           printf( b ); n         else n           printf( w ); n       printf(  n ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   double l, v1, v2; n   scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k); n   int num = n / k; n   if (num * k < n) { n     num++; n   } n   double w = (v1 + v2) * v2 / (2 * v1 * v2 * num + v2 * v2 - v1 * v2) * l; n   double t = w / v2 + (l - w) / v1; n   printf( %.10lf n , t); n } n


#include <bits/stdc++.h> n using namespace std; n void SOLVE(int, int); n int main() { n   int A, B; n   cin >> A >> B; n   SOLVE(A, B); n   return 0; n } n void SOLVE(int A, int B) { n   int T1 = min(A, B); n   int T2 = (A + B) / 2; n   cout << T1 <<     << abs(T2 - T1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int Hash = 743; n const int Mod = 51123987; n int powh[2000005], N, h1[2000005], h2[2000005], start[2000005], finish[2000005], n     a[2000005], b[2000005]; n char s[2000005]; n int getsub1(int lo, int hi) { n   return lo == 0 ? h1[hi] : h1[hi] - h1[lo - 1] * powh[hi - lo + 1]; n } n int getsub2(int lo, int hi) { n   return hi == N - 1 ? h2[lo] : h2[lo] - h2[hi + 1] * powh[hi - lo + 1]; n } n int main(void) { n   powh[0] = 1; n   for (int i = 1; i < 2000005; ++i) powh[i] = powh[i - 1] * Hash; n   scanf( %d %s , &N, s); n   int ch = 0; n   for (int i = 0; i < N; ++i) { n     ch = ch * Hash + s[i]; n     h1[i] = ch; n   } n   ch = 0; n   for (int i = N - 1; i >= 0; --i) { n     ch = ch * Hash + s[i]; n     h2[i] = ch; n   } n   long long tot = 0; n   for (int i = 0; i < N; ++i) { n     int lo = 1, hi = min(i + 1, N - i), mid, ans = 1; n     while (lo <= hi) { n       mid = (lo + hi) / 2; n       int s1 = getsub1(i, i + mid - 1); n       int s2 = getsub2(i - mid + 1, i); n       if (s1 == s2) { n         lo = mid + 1; n         ans = mid; n       } else n         hi = mid - 1; n     } n     tot += ans; n     tot %= Mod; n     a[i - ans + 1] += 1; n     a[i + 1] -= 1; n     b[i] += 1; n     b[i + ans] -= 1; n   } n   for (int i = 0; i + 1 < N; ++i) { n     if (s[i] != s[i + 1]) continue; n     int lo = 1, hi = min(i + 1, N - (i + 1)), mid, ans = 1; n     while (lo <= hi) { n       mid = (lo + hi) / 2; n       int s1 = getsub1(i + 1, i + mid); n       int s2 = getsub2(i - mid + 1, i); n       if (s1 == s2) { n         lo = mid + 1; n         ans = mid; n       } else n         hi = mid - 1; n     } n     tot += ans; n     tot %= Mod; n     a[i - ans + 1] += 1; n     a[i + 1] -= 1; n     b[i + 1] += 1; n     b[i + 1 + ans] -= 1; n   } n   for (int i = 0; i < N; ++i) { n     a[i] %= Mod; n     b[i] %= Mod; n     a[i] += Mod; n     b[i] += Mod; n     start[i] = (i == 0) ? a[i] : start[i - 1] + a[i]; n     finish[i] = (i == 0) ? b[i] : finish[i - 1] + b[i]; n     start[i] %= Mod; n     finish[i] %= Mod; n   } n   int sf = 0, sol = 0; n   for (int i = 0; i < N; ++i) { n     sol = (sol + (long long)(start[i]) * (long long)(sf) % Mod) % Mod; n     sf = (sf + finish[i]) % Mod; n   } n   cout << ((long long)(tot) * (tot - 1) / 2 - sol + Mod) % Mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v[100000 + 1]; n long long n, m; n long long taken[100000 + 1]; n map<int, int> v2; n int check = 0, sum; n void bfs() { n   queue<long long> q; n   long long j, x, y; n   for (int i = 1; i <= n; i++) { n     if (taken[i] == 0) { n       q.push(i); n       check = 0; n       while (!q.empty()) { n         x = q.front(); n         q.pop(); n         v2[x] = 1; n         for (j = 0; j < v[x].size(); j++) { n           y = v[x][j]; n           if (taken[y] == 0) { n             q.push(y); n             taken[y] = 1; n           } else if (taken[y] == 1 && v2[y] == 0) { n             check = 1; n           } n         } n       } n       if (check == 0) { n         sum = sum + 1; n       } n     } n   } n } n int main() { n   long long i, x, y; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   sum = 0; n   bfs(); n   cout << sum <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     int a, b, c, d; n     cin >> a >> b >> c; n     d = (a + b + c) / 3; n     int ans = min(a, b); n     ans = min(d, ans); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool chkmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <class T> n inline bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n inline long long Max(long long x, long long y) { return x > y ? x : y; } n inline long long Min(long long x, long long y) { return x < y ? x : y; } n int n, m; n long long fac[1002], inv[1002]; n long long dp[47][1002], ans[1002][47]; n void Add(long long &x, long long y) { n   x += y; n   if (x >= 1000000007) x -= 1000000007; n } n long long C(int n, int m) { n   if (n < 0 || m > n) return 0; n   return fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007; n } n void Init() { n   fac[0] = fac[1] = 1; n   for (int i = (2), i_end_ = (1002); i < i_end_; i++) n     fac[i] = fac[i - 1] * i % 1000000007; n   inv[0] = inv[1] = 1; n   for (int i = (2), i_end_ = (1002); i < i_end_; i++) n     inv[i] = (1000000007 - (1000000007 / i)) * inv[1000000007 % i] % 1000000007; n   for (int i = (2), i_end_ = (1002); i < i_end_; i++) n     inv[i] = inv[i] * inv[i - 1] % 1000000007; n   dp[0][0] = 1; n   for (int i = (1), i_end_ = (47); i < i_end_; i++) n     for (int j = (i * (i + 1) / 2), j_end_ = (1002); j < j_end_; j++) n       Add(dp[i][j] = dp[i][j - i], dp[i - 1][j - i]); n   for (int i = (1), i_end_ = (1002); i < i_end_; i++) { n     for (int k = (1), k_end_ = (47); k < k_end_; k++) { n       for (int j = (k * (k + 1) / 2), j_end_ = (i); j <= j_end_; j++) n         Add(ans[i][k], C(i - j + k, k) * dp[k][j] % 1000000007); n       ans[i][k] = ans[i][k] * fac[k] % 1000000007; n     } n   } n } n int main() { n   Init(); n   int cas; n   cin >> cas; n   while (cas--) { n     scanf( %d%d , &n, &m); n     printf( %I64d n , m >= 45 ? 0 : ans[n][m]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100 * 1000 + 19; n const int MASK = 20; n const int inf = 2e9 + 19; n long long n, m, dp[1 << MASK][MASK + 1]; n string s[MAX_N]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < m; i++) { n     long long tmp = 0; n     for (int j = 0; j < n; j++) tmp += ((1 << j) * (s[j][i] ==  1 )); n     dp[tmp][0]++; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i; j >= 1; j--) { n       for (int mask = 0; mask < (1 << n); mask++) n         dp[mask][j] += dp[mask ^ (1 << (i - 1))][j - 1]; n     } n   } n   long long ans = inf; n   for (int mask = 0; mask < (1 << n); mask++) { n     long long sum = 0; n     for (long long j = 0; j <= n; j++) sum += dp[mask][j] * min(j, n - j); n     ans = min(ans, sum); n   } n   cout << ans; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100100; n int n, m; n long long h[MAX], t[MAX]; n bool can(int cur, int last, int nxt, long long val) { n   if (t[last] >= h[cur]) return val >= t[nxt] - h[cur]; n   if (t[nxt] <= h[cur]) return val >= h[cur] - t[last]; n   return val >= min((h[cur] - t[last]) + (t[nxt] - t[last]), n                     (t[nxt] - h[cur]) + (t[nxt] - t[last])); n } n bool check(long long val) { n   int last = 1; n   for (int i = 1; i <= n; ++i) { n     int j = last; n     while (j <= m && can(i, last, j, val)) ++j; n     last = j; n   } n   return last == m + 1; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %I64d , h + i); n   for (int i = 1; i <= m; ++i) scanf( %I64d , t + i); n   long long low = 0, high = 20000000000LL, mid; n   while (low <= high) { n     mid = (low + high) >> 1; n     if (check(mid)) n       high = mid - 1; n     else n       low = mid + 1; n   } n   printf( %I64d n , high + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double a[1 << 19]; n double ans; n int n, r, w; n int main() { n   scanf( %d%d , &n, &r); n   w = 1 << n; n   for (register int i = 0; i < w; i++) { n     scanf( %lf , &a[i]); n     ans += a[i]; n   } n   printf( %.6lf n , ans / w); n   while (r--) { n     int pos; n     double x; n     scanf( %d%lf , &pos, &x); n     ans -= a[pos]; n     a[pos] = x; n     ans += a[pos]; n     printf( %.6lf n , ans / w); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n void DBG() { cerr <<  ]  << endl; } n template <class H, class... T> n void DBG(H h, T... t) { n   cerr << to_string(h); n   if (sizeof...(t)) cerr <<  ,  ; n   DBG(t...); n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.tie(nullptr); n   int n; n   cin >> n; n   vector<vector<long long>> a(n, vector<long long>(3)); n   for (int i = 0; i < n; ++i) { n     cin >> a[i][0] >> a[i][1] >> a[i][2]; n   } n   vector<bool> vis(n); n   for (int i = 0; i < n; ++i) { n     long long bonus = 0, cnt = 0; n     if (vis[i]) continue; n     for (int j = i + 1; j < n; ++j) { n       if (vis[j]) continue; n       a[j][2] -= max(0LL, (a[i][0] - cnt)); n       ++cnt; n       a[j][2] -= bonus; n       if (a[j][2] < 0) { n         vis[j] = true; n         bonus += a[j][1]; n       } n     } n   } n   vector<int> ans; n   for (int i = 0; i < n; ++i) { n     if (!vis[i]) { n       ans.push_back(i + 1); n     } n   } n   cout << ((int)(ans).size()) <<   n ; n   for (auto &A : ans) cout << A <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int t, l, r, m; n } op[5010]; n int a[5010], b[5010], n, m; n bool solve() { n   int p, i, k; n   for (i = 1; i <= n; i++) { n     a[i] = 1000000000; n   } n   memset(b, 0, sizeof(b)); n   for (p = 1; p <= m; p++) { n     if (op[p].t == 1) n       for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m; n     else n       for (i = op[p].l; i <= op[p].r; i++) a[i] = min(a[i], op[p].m - b[i]); n   } n   memset(b, 0, sizeof(b)); n   for (p = 1; p <= m; p++) { n     if (op[p].t == 1) n       for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m; n     else { n       k = -1000000007; n       for (i = op[p].l; i <= op[p].r; i++) k = max(k, a[i] + b[i]); n       if (k != op[p].m) return false; n     } n   } n   return true; n } n int main() { n   int i; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d%d , &op[i].t, &op[i].l, &op[i].r, &op[i].m); n   } n   if (!solve()) { n     printf( NO n ); n   } else { n     printf( YES n ); n     for (i = 1; i <= n; i++) printf( %d  , a[i]); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int n; n   int value; n   vector<int> next; n } p[100010]; n queue<struct point> q; n int main() { n   int n, m, x, y, flag = 1, t; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &x, &y); n     p[x].next.push_back(y); n     p[x].n++; n     p[y].next.push_back(x); n     p[y].n++; n   } n   for (int i = 1; i <= n; i++) { n     if (!flag) break; n     if (p[i].n && !p[i].value) { n       p[i].value = 1; n       q.push(p[i]); n       while (!q.empty()) { n         for (int j = 0; j < q.front().n; j++) { n           if (!p[q.front().next[j]].value) { n             p[q.front().next[j]].value = q.front().value % 2 + 1; n             q.push(p[q.front().next[j]]); n           } else { n             if (p[q.front().next[j]].value != q.front().value % 2 + 1) { n               flag = 0; n               break; n             } n           } n         } n         q.pop(); n       } n     } n   } n   if (flag) { n     int ans = 0; n     for (int i = 1; i <= n; i++) { n       if (p[i].value == 1) ans++; n     } n     printf( %d n , ans); n     for (int i = 1; i <= n; i++) { n       if (p[i].value == 1) { n         printf( %d  , i); n       } n     } n     printf(  n ); n     ans = 0; n     for (int i = 1; i <= n; i++) { n       if (p[i].value == 2) ans++; n     } n     printf( %d n , ans); n     for (int i = 1; i <= n; i++) { n       if (p[i].value == 2) { n         printf( %d  , i); n       } n     } n   } else { n     printf( -1 ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 16, K = 225; n struct HASH { n   size_t operator()(const pair<long long, long long> &x) const { n     return hash<long long>()((x.first) ^ ((x.second) << 32)); n   } n }; n int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0}; n int n, m; n int len = 0; n long long pw[N]; n string str[N]; n unordered_map<pair<long long, long long>, int, HASH> dis; n bool good(pair<long long, long long> p, int i, int j) { n   int cur = (i * m + j); n   for (int k = 0; k < len - 1 - 5; k++) n     if (p.first / pw[k] % K == cur) return false; n   for (int k = 0; k < min(len - 1, 5); k++) n     if (p.second / pw[k] % K == cur) return false; n   return true; n } n bool in_bound(int i, int j) { n   return i >= 0 && i < n && j >= 0 && j < m && str[i][j] !=  # ; n } n pair<long long, long long> getnxt(pair<long long, long long> p, int i, int j) { n   p.first *= K; n   p.first += p.second / pw[4]; n   p.first %= pw[max(len - 5, 0)]; n   p.second *= K; n   p.second += (i * m + j); n   p.second %= pw[min(len, 5)]; n   return p; n } n int main() { n   pw[0] = 1; n   for (int i = 1; i < 6; i++) pw[i] = pw[i - 1] * K; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> str[i]; n   pair<long long, long long> ori; n   queue<pair<long long, long long> > que; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       char c = str[i][j]; n       if (c >=  1  && c <=  9 ) { n         int x = c -  0 ; n         len = max(len, x); n         x--; n         if (x >= 5) n           ori.first += (i * m + j) * pw[x - 5]; n         else n           ori.second += (i * m + j) * pw[x]; n       } n     } n   } n   que.push(ori); n   dis[ori] = 0; n   while (!que.empty()) { n     pair<long long, long long> p = que.front(); n     que.pop(); n     int curdis = dis[p]; n     int ci = (int)(p.second % K / m), cj = (int)(p.second % K % m); n     for (int d = 0; d < 4; d++) { n       int ni = ci + dx[d], nj = cj + dy[d]; n       if (in_bound(ni, nj) && good(p, ni, nj)) { n         if (str[ni][nj] ==  @ ) { n           return cout << curdis + 1 << endl, 0; n         } n         pair<long long, long long> nxt = getnxt(p, ni, nj); n         if (!dis.count(nxt)) { n           que.push(nxt); n           dis[nxt] = curdis + 1; n         } n       } n     } n   } n   cout <<  -1  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 5e10 + 5; n int main() { n   bool flag = 0; n   int n, ans = 0, k; n   cin >> n; n   int arr[n + 5]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   sort(arr, arr + n); n   k = n / 2; n   for (int i = 0; i < n / 2; i++) { n     for (int j = k; j < n; j++) { n       if (arr[i] * 2 <= arr[j]) { n         ans++; n         k = j + 1; n         break; n       } n       if (j == n - 1) { n         flag = 1; n       } n     } n     if (flag) break; n   } n   cout << n - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int val{0}; n struct Triplet { n   char letter; n   int onePosn; n   int otherPosn; n }; n int findContinuous(string s) { n   int j{0}; n   for (auto i = 0; i < s.length() - 2; i++) { n     if (s[i] ==  Q  && s[i + 1] ==  A  && s[i + 2] ==  Q ) { n       j++; n     } n   } n   return j; n } n int findLastQ(string s) { n   int j{0}; n   for (auto i = 0; i < s.length() - 1; i++) { n     if (s[i] ==  Q  && s[i + 1] ==  A ) { n       for (int k = i + 2; k < s.length(); k++) { n         if (s[k] ==  Q ) { n           j++; n         } n       } n     } n   } n   return j; n } n int findFirstQ(string s) { n   int j{0}; n   for (auto i = 0; i < s.length() - 1; i++) { n     if (s[i] ==  A  && s[i + 1] ==  Q ) { n       for (int k = 0; k < i; k++) { n         if (s[k] ==  Q ) { n           j++; n         } n       } n     } n   } n   return j; n } n int findDisjoint(string s) { n   int j{0}; n   for (auto i = 0; i < s.length(); i++) { n     int before{0}; n     int after{0}; n     if (s[i] ==  A ) { n       for (int k = 0; k < i; k++) { n         if (s[k] ==  Q ) { n           before++; n         } n       } n       for (int k = i + 1; k < s.length(); k++) { n         if (s[k] ==  Q ) { n           after++; n         } n       } n       j += before * after; n     } n   } n   return j; n } n int main() { n   string s; n   cin >> s; n   int n = findDisjoint(s); n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class L> n bool smax(T& x, L y) { n   return x < y ? (x = y, 1) : 0; n } n template <class T, class L> n bool smin(T& x, L y) { n   return x > y ? (x = y, 1) : 0; n } n const int maxn = 2e5 + 17, mod = 1e9 + 7; n struct Seg { n   int lazy[maxn << 2], s[maxn << 2]; n   void build(int l = 0, int r = maxn, int id = 1) { n     s[id] = r - l; n     if (r - l < 2) return; n     int mid = l + r >> 1; n     build(l, mid, id << 1), build(mid, r, id << 1 | 1); n   } n   Seg() { fill(lazy, lazy + (maxn << 2), 1), build(); } n   void shift(int id) { n     lazy[id << 1] = (long long)lazy[id << 1] * lazy[id] % mod, n                lazy[id << 1 | 1] = n                    (long long)lazy[id << 1 | 1] * lazy[id] % mod; n     s[id << 1] = (long long)s[id << 1] * lazy[id] % mod, n             s[id << 1 | 1] = (long long)s[id << 1 | 1] * lazy[id] % mod; n     lazy[id] = 1; n   } n   void add(int st, int en, int v, int l = 0, int r = maxn, int id = 1) { n     if (st <= l && r <= en) { n       s[id] = (long long)s[id] * v % mod, n       lazy[id] = (long long)lazy[id] * v % mod; n       return; n     } n     if (en <= l || r <= st) return; n     shift(id); n     int mid = l + r >> 1; n     add(st, en, v, l, mid, id << 1), add(st, en, v, mid, r, id << 1 | 1); n     s[id] = (s[id << 1] + s[id << 1 | 1]) % mod; n   } n   int get(int st, int en, int l = 0, int r = maxn, int id = 1) { n     if (st <= l && r <= en) return s[id]; n     if (en <= l || r <= st) return 0; n     shift(id); n     int mid = l + r >> 1; n     return (get(st, en, l, mid, id << 1) + get(st, en, mid, r, id << 1 | 1)) % n            mod; n   } n   void add(int l, int v) { add(l, l + 1, v); } n   int get(int l) { return get(l, l + 1); } n } d, po, bad; n struct Q { n   int t, p, v; n } q[maxn]; n int rev(int a) { n   int b = mod - 2, ans = 1; n   for (; b; b >>= 1) { n     if (b & 1) ans = (long long)ans * a % mod; n     a = (long long)a * a % mod; n   } n   return ans; n } n int tim, st[maxn], en[maxn], nq, deg[maxn], cnt = 1; n vector<int> g[maxn]; n void dfs(int v = 0) { n   st[v] = tim++; n   for (auto u : g[v]) dfs(u); n   en[v] = tim; n } n void DeemoLovesInit() { n   int tmp; n   cin >> tmp >> nq; n   po.add(0, tmp); n   bad.add(0, 0); n   fill(deg, deg + maxn, 1); n   for (int i = 0; i < nq && cin >> q[i].t; i++) n     if (q[i].t == 1) n       cin >> q[i].p >> q[i].v, g[--q[i].p].push_back(cnt++); n     else n       cin >> q[i].v, q[i].v--; n   dfs(); n   cnt = 1; n } n int main() { n   DeemoLovesInit(); n   for (int i = 0, t = q[i].t, v = q[i].v, p = q[i].p; i < nq; n        i++, t = q[i].t, v = q[i].v, p = q[i].p) n     if (t == 1) { n       po.add(st[cnt], n              (long long)rev(po.get(st[cnt])) * v % mod * d.get(st[p]) % mod); n       bad.add(st[cnt], 0); n       deg[p]++; n       d.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod); n       po.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod); n       bad.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod); n       cnt++; n     } else { n       cout << (long long)(po.get(st[v], en[v]) - bad.get(st[v], en[v]) + mod) % n                   mod * rev(d.get(st[v])) % mod * deg[v] % mod n            <<   n ; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int iL = 666666; n char *iS, *iT, ibuf[iL]; n inline char gc() { n   if (iS == iT) { n     iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin); n     return iS == iT ? EOF : *iS++; n   } n   return *iS++; n } n template <class I> n void gi(I &x) { n   static char c; n   static int f; n   for (f = 1, c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (x = 0; c <=  9  && c >=  0 ; c = getchar()) x = x * 10 + (c & 15); n   x *= f; n } n const int N = 200050; n int Ttag[N * 4], Tval[N * 4], T[N * 4][31]; n int n, q, sig, d, l, r; n int cnt(int x) { n   int ans = 0; n   for (int i = 0; i <= 30; i++) n     if (T[x][i]) ans++; n   return ans; n } n void clear(int x) { n   for (int i = 0; i <= 30; i++) T[x][i] = 0; n   Tval[x] = Ttag[x] = 0; n } n void add(int d, int x) { n   for (int i = 30; i >= 0; i--) n     if ((d >> i) & 1) { n       if (T[x][i]) n         d ^= T[x][i]; n       else { n         T[x][i] = d; n         break; n       } n     } n } n void Complex(int x, int lc, int rc) { n   clear(x); n   for (int i = 0; i <= 30; i++) add(T[lc][i], x), add(T[rc][i], x); n   add(Tval[lc] ^ Tval[rc], x); n   Tval[x] = Tval[lc]; n } n void Complex2(int x, int rc) { n   clear(N * 4 - 1); n   for (int i = 0; i <= 30; i++) n     add(T[x][i], N * 4 - 1), add(T[rc][i], N * 4 - 1); n   add(Tval[x] ^ Tval[rc], N * 4 - 1); n   Tval[N * 4 - 1] = Tval[x]; n   for (int i = 0; i <= 30; i++) T[x][i] = T[N * 4 - 1][i]; n   Tval[x] = Tval[N * 4 - 1]; n } n void build(int x, int l, int r) { n   clear(x); n   if (l == r) { n     gi(Tval[x]); n     return; n   } n   int mid = (l + r) >> 1; n   build(x << 1, l, mid); n   build(x << 1 | 1, mid + 1, r); n   Complex(x, x << 1, x << 1 | 1); n } n void push_down(int x) { n   int lc = x << 1, rc = x << 1 | 1; n   if (Ttag[x]) { n     Ttag[lc] ^= Ttag[x]; n     Ttag[rc] ^= Ttag[x]; n     Tval[lc] ^= Ttag[x]; n     Tval[rc] ^= Ttag[x]; n     Ttag[x] = 0; n   } n } n void change(int x, int l, int r, int lb, int rb, int d) { n   if (lb <= l && r <= rb) { n     Tval[x] ^= d; n     Ttag[x] ^= d; n     return; n   } n   push_down(x); n   int mid = (l + r) >> 1; n   if (lb <= mid) change(x << 1, l, mid, lb, rb, d); n   if (rb > mid) change(x << 1 | 1, mid + 1, r, lb, rb, d); n   Complex(x, x << 1, x << 1 | 1); n } n void query(int x, int l, int r, int lb, int rb) { n   if (lb <= l && r <= rb) { n     Complex2(0, x); n     return; n   } n   push_down(x); n   int mid = (l + r) >> 1; n   if (lb <= mid) query(x << 1, l, mid, lb, rb); n   if (rb > mid) query(x << 1 | 1, mid + 1, r, lb, rb); n   Complex(x, x << 1, x << 1 | 1); n } n int main() { n   gi(n); n   gi(q); n   build(1, 1, n); n   while (q--) { n     gi(sig); n     if (sig == 1) { n       gi(l); n       gi(r); n       gi(d); n       change(1, 1, n, l, r, d); n     } else { n       gi(l); n       gi(r); n       clear(0); n       query(1, 1, n, l, r); n       printf( %d n , (1 << cnt(0))); n     } n   } n   return 0; n } n


#pragma comment(linker,  /stack:200000000 ) n     #pragma GCC optimize( Ofast ) n     #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n       n     #define _CRT_SECURE_NO_WARNINGS n     # include <iostream> n     # include <cmath> n     # include <algorithm> n     # include <stdio.h> n     # include <cstdint> n     # include <cstring> n     # include <string> n     # include <cstdlib> n     # include <vector> n     # include <bitset> n     # include <map> n     # include <queue> n     # include <ctime> n     # include <stack> n     # include <set> n     # include <list> n     # include <random> n     # include <deque> n     # include <functional> n     # include <iomanip> n     # include <sstream> n     # include <fstream> n     # include <complex> n     # include <numeric> n     # include <immintrin.h> n     # include <cassert> n     # include <array> n     # include <tuple> n       n     #ifdef LOCAL n     # include <opencv2/core/core.hpp> n     # include <opencv2/highgui/highgui.hpp> n     # include <opencv2/imgproc/imgproc.hpp> n     #endif n       n     using namespace std; n       n     // Let s define unordered map n     # ifdef __GNUC__ n     # if __cplusplus > 199711L n     # include <unordered_set> n     # include <unordered_map> n     # else n     # include <tr1/unordered_map> n     # include <tr1/unordered_set> n     using namespace tr1; n     # endif n     # else n     # include <unordered_map> n     # include <unordered_set> n     # endif n       n     #define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1)) n     #define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple n     #define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N n     #define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__)) n     #define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs) n     #define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs) n     #define macro_dispatcher___(macro, nargs) macro ## nargs n     #define DBN1(a)           cerr<<#a<< = <<(a)<<  n  n     #define DBN2(a,b)         cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<<  n  n     #define DBN3(a,b,c)       cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<<  n  n     #define DBN4(a,b,c,d)     cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<<  n  n     #define DBN5(a,b,c,d,e)   cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<< ,  <<#e<< = <<(e)<<  n  n     #define DBN6(a,b,c,d,e,f) cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<< ,  <<#e<< = <<(e)<< ,  <<#f<< = <<(f)<<  n  n     #define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__) n     #define DA(a,n) cerr<<#a<< =[ ; printarray(a,n); cerr<< ] n  n     #define DAR(a,n,s) cerr<<#a<< [ <<s<< - <<n-1<< ]=[ ; printarray(a,n,s); cerr<< ] n  n       n     #ifdef _MSC_VER n     #define PREFETCH(ptr, rw, level) ((void)0) n     #else n     #define PREFETCH(ptr, rw, level) __builtin_prefetch(ptr, rw, level) n     #endif n       n     #ifdef LOCAL n     #define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl n     #else n     #define CURTIME() n     #endif n       n     #define mp make_pair n     typedef long long ll; n     typedef unsigned int uint; n     typedef unsigned long long ull; n     typedef pair<int, int> pii; n     typedef pair<long long, long long> pll; n     typedef vector<int> vi; n     typedef vector<long long> vll; n     typedef int itn; n       n     template<class T1, class T2, class T3> n     struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} }; n     template<class T1, class T2, class T3> n     bool operator<(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a<t2.a;else if(t1.b!=t2.b)return t1.b<t2.b;else return t1.c<t2.c;} n     template<class T1, class T2, class T3> n     bool operator>(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a>t2.a;else if(t1.b!=t2.b)return t1.b>t2.b;else return t1.c>t2.c;} n     #define tri triple<int,int,int> n     #define trll triple<ll,ll,ll> n       n     #define FI(n) for(int i=0;i<(n);++i) n     #define FJ(n) for(int j=0;j<(n);++j) n     #define FK(n) for(int k=0;k<(n);++k) n     #define FL(n) for(int l=0;l<(n);++l) n     #define FQ(n) for(int q=0;q<(n);++q) n     #define FOR(i,a,b) for(int i = (a), __e = (int) (b); i < __e; ++i) n     #define all(a) std::begin(a), std::end(a) n     #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) n       n     #define sqr(x) ((x) * (x)) n     #define sqrt(x) sqrt(1.0 * (x)) n     #define pow(x, n) pow(1.0 * (x), n) n       n     #define COMPARE(obj) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b) n     #define COMPARE_BY(obj, field) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b) { return a.field < b.field; } n       n     #define checkbit(n, b) (((n) >> (b)) & 1) n     #define setbit(n, b) ((n) | (static_cast<std::decay_t<decltype(n)>>(1) << (b))) n     #define removebit(n, b) ((n) & ~(static_cast<std::decay_t<decltype(n)>>(1) << (b))) n     #define flipbit(n, b) ((n) ^ (static_cast<std::decay_t<decltype(n)>>(1) << (b))) n     inline int countBits(uint v){v=v-((v>>1)&0x55555555);v=(v&0x33333333)+((v>>2)&0x33333333);return((v+(v>>4)&0xF0F0F0F)*0x1010101)>>24;} n     inline int countBits(ull v){uint t=v>>32;uint p=(v & ((1ULL << 32) - 1)); return countBits(t) + countBits(p); } n     inline int countBits(ll v){return countBits((ull)v); } n     inline int countBits(int v){return countBits((uint)v); } n     unsigned int reverseBits(uint x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); } n     template<class T> inline int sign(T x){ return x > 0 ? 1 : x < 0 ? -1 : 0; } n     inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); } n     constexpr ll power(ll x, int p) { return p == 0 ? 1 : (x * power(x, p - 1)); } n     template<class T1, class T2, class T3> T1 inline clamp(T1 x, const T2& a, const T3& b) { if (x < a) return a; else if (x > b) return b; else return x; } n     unsigned long long rdtsc() { unsigned long long ret = 0; n     #ifdef __clang__ n         return __builtin_readcyclecounter(); n     #endif n     #ifndef _MSC_VER n         asm volatile( rdtsc  :  =A  (ret) : :); n     #endif n         return ret; } n     // Fast IO ******************************************************************************************************** n     const int __BS = 4096; n     static char __bur[__BS + 16], *__er = __bur + __BS, *__ir = __er; n     template<class T = int> T readInt() { n         auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; }; n         c(); while (*__ir && (*__ir <  0  || *__ir >  9 ) && *__ir !=  - ) ++__ir; c(); n         bool m = false; if (*__ir ==  - ) ++__ir, c(), m = true; n         T r = 0; while (*__ir >=  0  && *__ir <=  9 ) r = r * 10 + *__ir -  0 , ++__ir, c(); n         ++__ir; return m ? -r : r; n     } n     static char __buw[__BS + 20], *__iw = __buw, *__ew = __buw + __BS; n     template<class T> n     void writeInt(T x, char endc =   n ) { n         if (x < 0) *__iw++ =  - , x = -x; if (x == 0) *__iw++ =  0 ; n         char* s = __iw; n         while (x) { T t = x / 10; char c = x - 10 * t +  0 ; *__iw++ = c; x = t; } n         char* f = __iw - 1; while (s < f) swap(*s, *f), ++s, --f; n         if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw; n         *__iw++ = endc; n     } n     template<class T> n     void writeStr(const T& str) { n         int i = 0; while (str[i]) { *__iw++ = str[i++]; if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw; } n     } n     struct __FL__ { ~__FL__() { if (__iw != __buw) cout.write(__buw, __iw - __buw); } }; n     static __FL__ __flushVar__; n       n     //STL output ***************************************************************************************************** n     #define TT1 template<class T> n     #define TT1T2 template<class T1, class T2> n     #define TT1T2T3 template<class T1, class T2, class T3> n     TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p); n     TT1 ostream& operator << (ostream& os, const vector<T>& v); n     TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v); n     TT1T2 ostream& operator << (ostream& os, const multiset<T1, T2>&v); n     TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v); n     TT1T2T3 ostream& operator << (ostream& os, const map<T1, T2, T3>& v); n     TT1T2T3 ostream& operator << (ostream& os, const multimap<T1, T2, T3>& v); n     TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t); n     template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v); n     TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os << ( <<p.first<< ,  << p.second<< ) ; } n     TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; } n     template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; } n     TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; } n     TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; } n     TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os <<  [ ; for (auto& ii : v) { if (!f)os <<  ,  ; os <<  (  << ii.first <<   ->   << ii.second <<  )  ; f = 0; }return os <<  ] ; } n     TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os <<  [ ; for (auto& ii : v) { if (!f)os <<  ,  ; os <<  (  << ii.first <<   ->   << ii.second <<  )  ; f = 0; }return os <<  ] ; } n     TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os <<  [ ; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os <<  ,  ; f = 0; os << x; } return os <<  ] ; } n     TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t){ return os <<  (  << t.a <<  ,   << t.b <<  ,   << t.c <<  ) ; } n     TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] <<    ; cout << endl; } n       n     //STL input ***************************************************************************************************** n     TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t); n     TT1T2 inline istream& operator >> (istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; } n     TT1 inline istream& operator >> (istream& os, vector<T>& v) { n         if (v.size()) for (T& t : v) os >> t; else { n             string s; T obj; while (s.empty()) {getline(os, s); if (!os) return os;} n             stringstream ss(s); while (ss >> obj) v.push_back(obj); n         } n         return os; n     } n     TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t) { return os >> t.a >> t.b >> t.c; } n       n     //Pair magic ***************************************************************************************************** n     #define PT1T2 pair<T1, T2> n     TT1T2 inline PT1T2 operator+(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first + p2.first, p1.second + p2.second); } n     TT1T2 inline PT1T2& operator+=(PT1T2 &p1 , const PT1T2 &p2) { p1.first += p2.first, p1.second += p2.second; return p1; } n     TT1T2 inline PT1T2 operator-(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first - p2.first, p1.second - p2.second); } n     TT1T2 inline PT1T2& operator-=(PT1T2 &p1 , const PT1T2 &p2) { p1.first -= p2.first, p1.second -= p2.second; return p1; } n       n     #undef TT1 n     #undef TT1T2 n     #undef TT1T2T3 n       n     #define FREIN(FILE) freopen(FILE,  rt , stdin) n     #define FREOUT(FILE) freopen(FILE,  wt , stdout) n     #ifdef LOCAL n     #define BEGIN_PROFILE(idx, name) int profileIdx = idx; profileName[profileIdx] = name; totalTime[profileIdx] -= rdtsc() / 1e3; n     #define END_PROFILE totalTime[profileIdx] += rdtsc() / 1e3; totalCount[profileIdx]++; n     #else n     #define BEGIN_PROFILE(idx, name) n     #define END_PROFILE n     #endif n       n     template<class T> inline void normmod(T &x, T m) { x %= m; if (x < 0) x += m; } n     template<class T1, class T2> inline T2 summodfast(T1 x, T1 y, T2 m) { T2 res = x + y; if (res >= m) res -= m; return res; } n     template<class T1, class T2, class T3> inline void addmodfast(T1 &x, T2 y, T3 m) { x += y; if (x >= m) x -= m; } n     template<class T1, class T2, class T3> inline void submodfast(T1 &x, T2 y, T3 m) { x -= y; if (x < 0) x += m; } n     #if INTPTR_MAX == INT32_MAX or !defined(__SIZEOF_INT128__) n     inline ll mulmod(ll x, ll n, ll m){ ll r = 0; normmod(x, m); normmod(n, m); while (n) { if (n & 1) r += x; x += x; if (r >= m) r -= m; if (x >= m) x -= m; n /= 2; } return r; } n     #else n     using int128 = __int128; n     inline ll mulmod(ll x, ll n, ll m){ return __int128(x) * n % m; } n     #endif n     inline ll powmod(ll x, ll n, ll m){ ll r = 1; normmod(x, m); while (n){ if (n & 1)r = (r*x) % m; x = (x*x) % m; n /= 2; }return r; } n     inline ll powmulmod(ll x, ll n, ll m) { ll res = 1; normmod(x, m); while (n){ if (n & 1)res = mulmod(res, x, m); x = mulmod(x, x, m); n /= 2; } return res; } n     template<class T> inline T gcd(T a, T b) { while (b) { a %= b; T t = a; a = b; b = t; } return a; } n     inline ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } n     template<class T> inline T gcd(T a, T b, T c){ return gcd(gcd(a, b), c); } n     ll gcdex(ll a, ll b, ll& x, ll& y) { n         if (!a) { x = 0; y = 1; return b; } n         ll y1; ll d = gcdex(b % a, a, y, y1); x = y1 - (b / a) * y; n         return d; n     } n     template<class T> bool isPrime(T x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; n         for (T i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; } n     bool millerRabin(long long n) { n         if (n <= 1000) return isPrime(n); n         long long s = n - 1; int t = 0; while (s % 2 == 0) s /= 2, ++t; n         for (int a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if (!(a %= n)) return true; n             long long f = powmulmod(a, s, n); if (f == 1 || f == n - 1) continue; n             for (int i = 1; i < t; ++i) if ((f = mulmod(f, f, n)) == n - 1) goto nextp; n             return false; nextp:; n         } return true; n     } n       n     // Useful constants n       n     //int some_primes[7] = {24443, 100271, 1000003, 1000333, 5000321, 98765431, 1000000123}; n     #define T9          1000000000 n     #define T18         1000000000000000000LL n     #define INF         1011111111 n     #define LLINF       1000111000111000111LL n     #define mod         1000000007 n     #define EPS         (double)1e-10 n     #define PI          3.14159265358979323846264 n     #define link        asaxlajrewqwe n     #define rank        wahayawehasdakw n     //************************************************************************************* n       n     int32_t solve(); n     int32_t main(int argc, char** argv) { n         ios_base::sync_with_stdio(0);cin.tie(0); n     #ifdef LOCAL n         //    FREIN( input.txt ); n         //            FREOUT( out.txt ); n     #endif n         return solve(); n     } n     int a[10101]; n     int solve() { n         int n, m, c; n         cin >> n >> m >> c; n         FI(n) { n             a[i] = INF; n         } n         int b = 0, e = 0; n         while (m--) { n     //        printarray(a, n); n             int x; n             cin >> x; n             int pos; n             if (x <= c / 2) { n                 pos = int(upper_bound(a, a + b, x) - a); n                 if (pos == b) { n                     ++b; n                 } n             } else { n                 pos = int(lower_bound(a + n - e, a + n, x) - a - 1); n                 if (pos == n - 1 - e) { n                     ++e; n                 } n             } n     //        DBN(b, e); n             a[pos] = x; n             cout << pos + 1 << endl; n             if (b + e == n) return 0; n         } n          n         return 0; n     } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int main() { n   string a; n   cin >> a; n   int sz = int(a.size()); n   for (__typeof(sz) i = 0; i < sz; i++) n     for (__typeof(sz) j = 0; j < sz; j++) n       if (a.substr(0, i) + a.substr(j + 1) ==  CODEFORCES ) { n         cout <<  YES n ; n         return 0; n       } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double EPS = 1e-10; n const int OO = 2147483647; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, -1, 1}; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   map<pair<long long, long long>, long long> st; n   map<long long, long long> xs, ys; n   long long ans = 0; n   long long cnt = 0; n   while (n--) { n     int x, y; n     cin >> x >> y; n     ans += xs[x]++ + ys[y]++ - st[{x, y}]++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 1; n const int MOD = 1e9 + 7; n long long a[MAXN], b[MAXN]; n bool used[MAXN]; n vector<int> g[MAXN]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   long long n, m, cnt = 0, ans = 0; n   bool y = 0; n   cin >> n; n   a[1] = 1; n   for (int i = 2; i <= n; i++) { n     cin >> a[i]; n   } n   cnt = n; n   while (cnt != 1) { n     ans++; n     b[ans] = cnt; n     cnt = a[cnt]; n   } n   reverse(b + 1, b + ans + 1); n   cout << 1 <<    ; n   for (int i = 1; i <= ans; i++) { n     cout << b[i] <<    ; n   } n   return 0; n } n