#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000; n const long long LINF = (long long)INF * INF; n const int MAX = 2e5; n const double EPS = 1e-9; n const double PI = acos(-1.); n int n, m, k; n vector<pair<int, long long> > g[300005]; n set<pair<pair<int, int>, int> > elist; n set<int> ans; n int siz[300005]; n namespace D { n vector<long long> d; n vector<pair<long long, long long> > p; n void go() { n   d.resize(n, LINF); n   p.resize(n); n   d[0] = 0; n   priority_queue<pair<long long, long long> > q; n   q.push(make_pair(0LL, 0LL)); n   while (!q.empty()) { n     long long v = q.top().second, cur_d = -q.top().first; n     q.pop(); n     if (cur_d > d[v]) continue; n     for (size_t j = 0; j < g[v].size(); ++j) { n       long long to = g[v][j].first, len = g[v][j].second; n       if (d[v] + len < d[to]) { n         d[to] = d[v] + len; n         p[to] = make_pair(v, len); n         q.push(make_pair(-d[to], to)); n       } n     } n   } n } n }  // namespace D n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m >> k; n   for (int i = (0); i < (m); ++i) { n     int x, y, z; n     cin >> x >> y >> z; n     x--; n     y--; n     g[x].push_back(make_pair(y, z)); n     g[y].push_back(make_pair(x, z)); n     if (x > y) swap(x, y); n     elist.insert(make_pair(make_pair(x, y), i + 1)); n   } n   D::go(); n   for (int i = (0); i < (n); ++i) { n     g[i].clear(); n   } n   for (int i = (1); i < (n); ++i) { n     int u = D::p[i].first; n     int v = i; n     int w = D::p[i].second; n     g[u].push_back(make_pair(v, w)); n     g[v].push_back(make_pair(u, w)); n     if (u > v) swap(u, v); n     int id = elist.lower_bound(make_pair(make_pair(u, v), -1))->second; n     ans.insert(id); n   } n   if (k == 0) { n     cout << 0; n     return 0; n   } n   set<int> foo; n   for (int i = (0); i < (n); ++i) { n     siz[i] = (int)g[i].size(); n     if ((int)g[i].size() == 1) { n       foo.insert(i); n     } n   } n   int cur = n - 1; n   while (cur > k) { n     int u = *foo.begin(); n     foo.erase(foo.begin()); n     if (u == 0) continue; n     siz[u] = -1; n     for (int i = (0); i < ((int)g[u].size()); ++i) { n       int v = g[u][i].first; n       if (siz[v] == 2) { n         if (v) foo.insert(v); n       } n       if (siz[v] != -1) { n         siz[v]--; n         int x = u; n         int y = v; n         if (x > y) swap(x, y); n         int id = elist.lower_bound(make_pair(make_pair(x, y), -1))->second; n         ans.erase(id); n       } n     } n     cur--; n   } n   cout << ans.size() << endl; n   for (auto& iter : ans) { n     cout << iter <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char ch = getchar(); n   long long p = 1, data = 0; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) p = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     data = data * 10 + (ch ^ 48); n     ch = getchar(); n   } n   return p * data; n } n inline long long qpow(long long a, long long b) { n   long long r = 1; n   while (b) { n     if (b & 1) r = a * r; n     a = a * a; n     b >>= 1; n   } n   return r; n } n inline long long gcd(long long a, long long b) { n   if (!a || !b) return (!a) ? b : a; n   while (b ^= a ^= b ^= a %= b) n     ; n   return a; n } n inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n void exgcd(long long a, long long b, long long &x, long long &y) { n   if (!b) n     x = 1, y = 0; n   else { n     exgcd(b, a % b, y, x); n     y -= x * (a / b); n   } n } n const int mod = 1e9 + 7; n int main() { n   int n = read(); n   long long a[2] = {0, 0}; n   for (int i = 1; i <= n; i++) { n     long long x = read(); n     a[i & 1] += x / 2 + x % 2; n     a[1 - i & 1] += x / 2; n   } n   printf( %lld n , min(a[0], a[1])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int to, next, v; n } e[2005 * 105]; n int head[2005], tot, n; n void add(int x, int y, int v) { n   e[++tot] = (edge){y, head[x], v}; n   head[x] = tot; n } n struct Graph { n   int S, sz; n   bool vis[2005]; n   long long dis[2005], b[2005]; n   void work() { n     for (int i = 1; i <= n; i++) n       if (i != S) dis[i] = (1ll << 62); n     for (int i = 1; i <= n; i++) { n       int k = 0; n       for (int j = 1; j <= n; j++) n         if (!vis[j] && (!k || dis[j] < dis[k])) k = j; n       vis[k] = 1; n       for (int j = head[k]; j; j = e[j].next) n         dis[e[j].to] = min(dis[e[j].to], dis[k] + e[j].v); n     } n     memcpy(b, dis, sizeof(b)); n     sort(b + 1, b + n + 1); n     sz = unique(b + 1, b + n + 1) - b - 1; n     for (int i = 1; i <= n; i++) n       dis[i] = lower_bound(b + 1, b + sz + 1, dis[i]) - b; n   } n } G[2]; n int sz[2005][2005]; n long long sum[2005][2005]; n long long f[2005][2005][2][2]; n bool vis[2005][2005][2][2]; n int SZ(int x, int y, int X, int Y) { return sz[x][y] - sz[X][Y]; } n long long SUM(int x, int y, int X, int Y) { return sum[x][y] - sum[X][Y]; } n long long DP(int x, int y, int who, int can) { n   if (x > G[0].sz || y > G[1].sz) return 0; n   if (vis[x][y][who][can]) return f[x][y][who][can]; n   vis[x][y][who][can] = 1; n   long long ans; n   if (who) n     ans = DP(x, y + 1, who, can || SZ(x, y, x, y + 1)) + SUM(x, y, x, y + 1); n   else n     ans = DP(x + 1, y, who, can || SZ(x, y, x + 1, y)) + SUM(x, y, x + 1, y); n   if (can) ans = max(ans, -DP(x, y, who ^ 1, 0)); n   return f[x][y][who][can] = ans; n } n int m, v[2005]; n int main() { n   scanf( %d%d%d%d , &n, &m, &G[0].S, &G[1].S); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   for (int i = 1; i <= m; i++) { n     int x, y, v; n     scanf( %d%d%d , &x, &y, &v); n     add(x, y, v); n     add(y, x, v); n   } n   G[0].work(); n   G[1].work(); n   for (int i = 1; i <= n; i++) { n     sz[G[0].dis[i]][G[1].dis[i]]++; n     sum[G[0].dis[i]][G[1].dis[i]] += v[i]; n   } n   for (int i = G[0].sz; i; i--) n     for (int j = G[1].sz; j; j--) { n       sz[i][j] += sz[i][j + 1] + sz[i + 1][j] - sz[i + 1][j + 1]; n       sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1]; n     } n   long long ans = DP(1, 1, 0, 0); n   if (ans == 0) n     puts( Flowers ); n   else if (ans < 0) n     puts( Cry ); n   else n     puts( Break a heart ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int a, b, i, cnt, x; n   cin >> a >> b; n   if (a < b) { n     cout <<  0 n ; n     return 0; n   } n   if (a == b) { n     cout <<  infinity n ; n     return 0; n   } n   a = a - b; n   cnt = 0; n   for (i = 1; i <= sqrt(a); i++) { n     if (a % i == 0) { n       x = a / i; n       if (x == i) { n         if (i > b) cnt++; n       } else { n         if (i > b) cnt++; n         if (x > b) cnt++; n       } n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ansp[200001]; n int main() { n   long long k; n   memset(ansp, 0, sizeof(ansp)); n   scanf( %lld , &k); n   char s[200001], t[200001], ans[200001]; n   scanf( %s %s , s, t); n   long long add = 0, dec = 0, again = 0; n   long long i, j; n   for (i = 0; i < k; i++) { n     long long x = s[i] -  a , y = t[i] -  a  + add; n     add = 0; n     if ((x + y) % 2 != 0) { n       add = 26; n       y--; n     } n     long long now = (x + y) / 2; n     ansp[i] = now; n   } n   for (i = k - 1; i >= 0; i--) { n     ansp[i - 1] += ansp[i] / 26; n     ansp[i] %= 26; n   } n   for (i = 0; i < k; i++) printf( %c , (char)(ansp[i] +  a )); n } n


#include <bits/stdc++.h> n using namespace std; n int bit(int mask, int n) { return mask & (1 << n) ? 1 : 0; } n int rev(int a) { n   int res = 0; n   for (int i = 0; i < 8; ++i) res = res | ((1 << (7 - i)) * bit(a, i)); n   return res; n } n int main() { n   string s; n   int prev = 0; n   getline(cin, s); n   for (int i = 0; i < s.length(); ++i) { n     int cur = (256 + prev - rev(s[i])) % 256; n     cout << cur << endl; n     prev = rev(s[i]); n   } n   cin >> s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long a[100010], ans; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n inline long long cal(long long a) { n   if (a % 2 == 0) return 0; n   long long tmp = 0; n   for (int i = 0; (a << i) < m; i++) { n     tmp += m - (a << i); n   } n   return tmp; n } n int main() { n   scanf( %d%d , &n, &m); n   long long d = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (i) n       d = gcd(d, a[i] - 1); n     else n       d = a[i] - 1; n   } n   for (int i = 1; i * i <= d; i++) { n     if (d % i == 0) { n       ans += cal(i); n       if (i * i != d) ans += cal(d / i); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2000000000; n struct Edge { n   int from, to, cap, flow, index; n   Edge(int from, int to, int cap, int flow, int index) n       : from(from), to(to), cap(cap), flow(flow), index(index) {} n }; n struct Dinic { n   int N; n   vector<vector<Edge> > G; n   vector<Edge *> dad; n   vector<int> Q; n   Dinic(int N) : N(N), G(N), dad(N), Q(N) {} n   void AddEdge(int from, int to, int cap) { n     G[from].push_back(Edge(from, to, cap, 0, G[to].size())); n     if (from == to) G[from].back().index++; n     G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1)); n   } n   long long BlockingFlow(int s, int t) { n     fill(dad.begin(), dad.end(), (Edge *)NULL); n     dad[s] = &G[0][0] - 1; n     int head = 0, tail = 0; n     Q[tail++] = s; n     while (head < tail) { n       int x = Q[head++]; n       for (int i = 0; i < G[x].size(); i++) { n         Edge &e = G[x][i]; n         if (!dad[e.to] && e.cap - e.flow > 0) { n           dad[e.to] = &G[x][i]; n           Q[tail++] = e.to; n         } n       } n     } n     if (!dad[t]) return 0; n     long long totflow = 0; n     for (int i = 0; i < G[t].size(); i++) { n       Edge *start = &G[G[t][i].to][G[t][i].index]; n       int amt = INF; n       for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) { n         if (!e) { n           amt = 0; n           break; n         } n         amt = min(amt, e->cap - e->flow); n       } n       if (amt == 0) continue; n       for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) { n         e->flow += amt; n         G[e->to][e->index].flow -= amt; n       } n       totflow += amt; n     } n     return totflow; n   } n   long long GetMaxFlow(int s, int t) { n     long long totflow = 0; n     while (long long flow = BlockingFlow(s, t)) totflow += flow; n     return totflow; n   } n }; n bool prime[20010]; n void sieve() { n   int k = sqrt(20010); n   for (int i = 3; i <= k; i++) { n     if (!prime[i]) { n       for (int j = i * i; j < 20001; j += i + i) { n         prime[j] = 1; n       } n     } n   } n   return; n } n int a[210]; n vector<int> adj[210]; n vector<vector<int> > ans; n vector<int> tmp; n bool vis[210]; n void dfs(int u) { n   vis[u] = 1; n   tmp.push_back(u); n   for (int i = 0; i < (int)adj[u].size(); i++) { n     int v = adj[u][i]; n     if (!vis[v]) { n       dfs(v); n       return; n     } n   } n   return; n } n inline bool chk(int x, int n) { return (x >= 1 && x <= n); } n int main() { n   sieve(); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   Dinic din(n + 2); n   for (int i = 1; i <= n; i++) { n     if (a[i] & 1) { n       din.AddEdge(0, i, 2); n     } else { n       din.AddEdge(i, n + 1, 2); n     } n     for (int j = 1; j <= n; j++) { n       if (a[i] % 2 == 1 && a[j] % 2 == 0 && !prime[a[i] + a[j]]) { n         din.AddEdge(i, j, 1); n       } n     } n   } n   if (din.GetMaxFlow(0, n + 1) != n) { n     cout <<  Impossible n ; n   } else { n     for (int i = 0; i < (int)din.G.size(); i++) { n       for (int j = 0; j < (int)din.G[i].size(); j++) { n         if (din.G[i][j].flow && chk(din.G[i][j].from, n) && n             chk(din.G[i][j].to, n)) { n           adj[din.G[i][j].from].push_back(din.G[i][j].to); n         } n       } n     } n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         (tmp.clear()); n         dfs(i); n         ans.push_back(tmp); n       } n     } n     cout << (int)ans.size() <<   n ; n     for (int i = 0; i < (int)ans.size(); i++) { n       cout << (int)ans[i].size(); n       for (int j = 0; j < (int)ans[i].size(); j++) { n         cout <<     << ans[i][j]; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(int x, int y) { return x > y; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t = 1; n   cin >> t; n   long long m, n, k; n   string a, b; n   while (t--) { n     cin >> n; n     vector<long long> vec(n); n     for (long long i = 0; i < n; i++) cin >> vec[i]; n     map<long long, long long> mp; n     for (long long i = 0; i < n; i++) { n       long long k = (long long)(log2(vec[i])); n       mp[k] += 1; n     } n     map<long long, long long>::iterator it = mp.begin(); n     long long ans = 0; n     while (it != mp.end()) { n       ans += ((it->second) * (it->second - 1)) / 2; n       ++it; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b, c, d; n   cin >> a >> b >> c >> d; n   long long ans = 0, fl = 0; n   if (a != c && b != d) n     ans = abs(a - c) + abs(b - d) + 2; n   else n     ans = abs(a - c) + abs(b - d); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) solve(); n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void rd(T &ret) { n   ret = 0; n   bool ok = 0, u = 0; n   for (;;) { n     int c = getchar(); n     if (c >=  0  && c <=  9 ) n       ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1; n     else if (c ==  - ) n       u = 1; n     else if (ok) { n       if (u) ret *= -1; n       return; n     } n   } n } n long long powmod(long long p, long long n, long long mod) { n   long long ret = 1; n   for (; n; n >>= 1) { n     if (n & 1) ret = ret * p % mod; n     p = p * p % mod; n   } n   return ret; n } n template <class T> n bool chmin(T &a, const T &b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool chmax(T &a, const T &b) { n   return b > a ? a = b, 1 : 0; n } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n const long long mod = 998244353; n const int N = (int)2e5 + 9; n template <int sz> n struct combo { n   const long long mod = ::mod; n   long long *fac, *ifac; n   long long mem_fac[sz + 5], mem_ifac[sz + 5]; n   combo(long long *fa = 0, long long *ifa = 0) { n     fac = fa ? fa : mem_fac; n     ifac = ifa ? ifa : mem_ifac; n     fac[0] = ifac[0] = 1; n     for (int i = 1; i <= sz; ++i) { n       fac[i] = i * fac[i - 1] % mod; n       ifac[i] = powmod(fac[i], mod - 2, mod); n     } n   } n   long long comb(long long n, long long m) { n     if (n < m) return 0; n     return (fac[n] * ifac[m] % mod) * ifac[n - m] % mod; n   } n }; n namespace ntt { n const int N = ::N; n const long long mod = ::mod, rt = 3; n long long G[55], iG[55], itwo[55]; n void add(int &a, int b) { n   a += b; n   if (a >= mod) a -= mod; n } n void init() { n   int now = (mod - 1) / 2, len = 1, irt = powmod(rt, mod - 2, mod); n   while (now % 2 == 0) { n     G[len] = powmod(rt, now, mod); n     iG[len] = powmod(irt, now, mod); n     itwo[len] = powmod(1 << len, mod - 2, mod); n     now >>= 1; n     len++; n   } n } n void dft(long long *first, int n, int fg = 1) { n   for (int i = (n >> 1), j = 1, k; j < n; ++j) { n     if (i < j) swap(first[i], first[j]); n     for (k = (n >> 1); k & i; i ^= k, k >>= 1) n       ; n     i ^= k; n   } n   long long r, tr, u, v; n   for (int m = 2, now = 1; m <= n; m <<= 1, now++) { n     r = fg > 0 ? G[now] : iG[now]; n     for (int i = 0, j; i < n; i += m) { n       tr = 1, u, v; n       for (j = i; j < i + (m >> 1); ++j) { n         u = first[j]; n         v = first[j + (m >> 1)] * tr % mod; n         first[j] = (u + v) % mod; n         first[j + (m >> 1)] = (u + mod - v) % mod; n         tr = tr * r % mod; n       } n     } n   } n } n void brute(long long *a, long long *b, int n, int m) { n   static long long c[N]; n   for (int k = 0, t; k < n + m - 1; ++k) { n     t = 0; n     for (int i = max(k - m + 1, 0); i < n && i <= k; ++i) { n       add(t, a[i] * b[k - i] % mod); n     } n     c[k] = t; n   } n   for (int k = 0; k < n + m - 1; ++k) a[k] = c[k]; n } n void mul(long long *a, long long *b, int n, int m) { n   if (n + m <= 200) { n     brute(a, b, n, m); n     return; n   } n   int nn = n + m - 1; n   if (n == 0 || m == 0) { n     memset(a, 0, nn * sizeof(a[0])); n     return; n   } n   int L, len; n   for (L = 1, len = 0; L < nn; ++len, L <<= 1) n     ; n   if (n < L) memset(a + n, 0, (L - n) * sizeof(a[0])); n   if (m < L) memset(b + m, 0, (L - m) * sizeof(b[0])); n   dft(a, L, 1); n   dft(b, L, 1); n   for (int i = 0; i < L; ++i) a[i] = a[i] * b[i] % mod; n   dft(a, L, -1); n   for (int i = 0; i < L; ++i) a[i] = a[i] * itwo[len] % mod; n } n }  // namespace ntt n long long a[N], b[N], fac[N], fnv[N], u[N], v[N], pw[N], ct[N], c[N]; n combo<100005> C(fac, fnv); n void solve(int n) { n   if (n == 1) { n     c[0] = 0; n     c[1] = 1; n   } else if (n & 1) { n     solve(n - 1); n     for (int i = (n + 1) - 1; i >= (1); i--) n       c[i] = (c[i - 1] + (long long)(n - 1) * c[i]) % mod; n     c[0] = 0; n   } else { n     solve(n / 2); n     int t = n / 2; n     pw[0] = 1; n     for (int i = (1); i < (t + 1); i++) pw[i] = pw[i - 1] * t % mod; n     for (int i = (0); i < (t + 1); i++) u[i] = c[i] * fac[i] % mod; n     for (int i = (0); i < (t + 1); i++) v[i] = pw[i] * fnv[i] % mod; n     reverse(v, v + t + 1); n     ntt::mul(u, v, t + 1, t + 1); n     for (int i = (0); i < (t + 1); i++) ct[i] = u[i + t] * fnv[i] % mod; n     ntt::mul(c, ct, t + 1, t + 1); n   } n } n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   --a; n   --b; n   if (a < 0 || b < 0) { n     puts( 0 ); n     return 0; n   } n   if (n == 1) { n     puts(a == 0 && b == 0 ?  1  :  0 ); n     return 0; n   } n   if (a + b >= n) { n     puts( 0 ); n     return 0; n   } n   ntt::init(); n   solve(n - 1); n   cout << C.comb(a + b, a) * c[a + b] % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int N; n   cin >> N; n   int arr[N], grr[100006] = {0}, fre[100005] = {0}, x, ma = 0, ans = 0; n   for (int i = 0; i < N; i++) { n     bool ok = false; n     cin >> x; n     grr[fre[x]]--; n     fre[x]++; n     grr[fre[x]]++; n     ma = max(ma, fre[x]); n     if (grr[1] == i + 1) n       ok = true; n     else if (grr[i + 1] == 1) n       ok = true; n     else if (grr[ma - 1] * (ma - 1) == i + 1 - ma && grr[ma] == 1) n       ok = true; n     else if (grr[1] == 1 && grr[ma] * (ma) == i) n       ok = true; n     if (ok) ans = i + 1; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int SIZE = 2e6 + 10; n int a[SIZE]; n int num[SIZE], nxt[SIZE]; n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   long long sum = 0; n   for (int i = 0; i < (n); ++i) { n     scanf( %d , &(a[i])); n     sum += a[i]; n     a[i + n] = a[i]; n   } n   for (int tt = 1; tt <= q; tt++) { n     long long b; n     scanf( %I64d , &b); n     if (b >= sum) { n       puts( 1 ); n       continue; n     } n     { n       int rr = -1; n       long long now = 0; n       for (int i = 0; i < (n); ++i) { n         while (now + a[rr + 1] <= b) now += a[++rr]; n         nxt[i] = rr + 1; n         nxt[i + n] = rr + 1 + n; n         num[i] = 1; n         now -= a[i]; n       } n     } n     int an = n; n     for (int i = n - 1; i >= 0; i--) { n       if (nxt[i] < n) { n         num[i] += num[nxt[i]]; n         nxt[i] = nxt[nxt[i]]; n       } n       if (nxt[i] >= i + n) an = min(an, num[i]); n     } n     printf( %d n , an); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mul(long long a, long long b) { n   return ((a % 1000000007) * (b % 1000000007)) % 1000000007; n } n long long power(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long temp = power(a, b / 2); n   if (b % 2 == 0) n     return mul(temp, temp); n   else n     return mul(mul(temp, temp), a); n } n vector<long long> g[100005]; n long long color[100005]; n long long curr_color, ok; n void dfs(long long node, long long par) { n   ok = ok && (color[node] == curr_color); n   for (long long i = 0; i < g[node].size(); i++) { n     if (g[node][i] != par) { n       dfs(g[node][i], node); n     } n   } n } n long long solve(long long node) { n   long long ans = 1; n   ok = 1; n   for (long long i = 0; i < g[node].size(); i++) { n     curr_color = color[g[node][i]]; n     dfs(g[node][i], node); n     ans = ans && ok; n   } n   return ans; n } n int main() { n   long long n, i, x, a, b; n   cin >> n; n   for (i = 0; i < n - 1; i++) { n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   for (i = 0; i < n; i++) cin >> color[i + 1]; n   long long root1 = -1, root2 = -1; n   for (i = 1; i <= n; i++) { n     for (long long j = 0; j < g[i].size(); j++) { n       if (color[i] != color[g[i][j]]) { n         root1 = i; n         root2 = g[i][j]; n       } n     } n   } n   if (root1 == -1) { n     cout <<  YES  << endl; n     cout << 1 << endl; n     return 0; n   } n   if (solve(root1)) { n     cout <<  YES  << endl; n     cout << root1 << endl; n     return 0; n   } n   if (solve(root2)) { n     cout <<  YES  << endl; n     cout << root2 << endl; n     return 0; n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[105]; n int dp[105][55]; n int f[55]; n int n, k; n void dfs(int u, int fa) { n   dp[u][0] = 1; n   dp[u][k + 1] = 1; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == fa) continue; n     dfs(v, u); n     memset(f, 0, sizeof(f)); n     for (int j = 0; j <= 2 * k; j++) n       for (int p = 0; p <= 2 * k; p++) { n         if (j + p <= 2 * k) { n           f[min(p + 1, j)] += (1LL * dp[u][j] * dp[v][p]) % 1000000007; n           f[min(p + 1, j)] %= 1000000007; n         } else { n           f[max(p + 1, j)] += (1LL * dp[u][j] * dp[v][p]) % 1000000007; n           f[max(p + 1, j)] %= 1000000007; n         } n       } n     for (int j = 0; j <= 2 * k; j++) dp[u][j] = f[j]; n   } n } n int main() { n   cin >> n >> k; n   for (int i = 1; i < n; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(1, 1); n   int ans = 0; n   for (int i = 0; i <= k; i++) { n     ans = (ans + dp[1][i]) % 1000000007; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt; n char c[11]; n int main() { n   scanf( %d %s , &n, c + 1); n   if (n == 6) n     printf( espeon n ); n   else if (n == 8) n     printf( vaporeon n ); n   else if (c[1] ==  j  || c[2] ==  o  || c[4] ==  t ) n     printf( jolteon n ); n   else if (c[1] ==  u  || c[2] ==  m  || c[3] ==  b ) n     printf( umbreon n ); n   else if (c[1] ==  l  || c[2] ==  e  || c[4] ==  f ) n     printf( leafeon n ); n   else if (c[1] ==  s  || c[2] ==  y  || c[4] ==  v ) n     printf( sylveon n ); n   else if (c[1] ==  f  || c[4] ==  r ) n     printf( flareon n ); n   else n     printf( glaceon n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   const int n = s.length() + 5; n   int arr[n]; n   memset(arr, 0, sizeof arr); n   int m, l, r; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] == s[i + 1]) { n       arr[i + 2]++; n     } n     arr[i + 1] += arr[i]; n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> l >> r; n     cout << arr[r] - arr[l] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int dp[110][10100]; n bool f[110][10100] = {false}; n int main() { n   int m, n, x, y, i, j, k, a[1111]; n   pair<int, int> pii[101]; n   cin >> n; n   for (i = 0; i < n; i++) cin >> pii[i].second >> pii[i].first; n   sort(pii, pii + n); n   for (i = 0; i <= n; i++) n     for (j = 0; j <= 10000; j++) dp[i][j] = 555555; n   reverse(pii, pii + n); n   f[0][0] = true; n   dp[0][0] = 0; n   int t = 0; n   for (i = 0; i < n; i++) { n     x = pii[i].first; n     y = pii[i].second; n     for (j = t; j >= 0; j--) { n       dp[i + 1][j + y] = min(dp[i + 1][j + y], dp[i][j] + y); n       if (dp[i][j] >= x) { n         f[i + 1][j - x] = true; n         dp[i + 1][j - x] = min(dp[i + 1][j - x], dp[i][j]); n       } n     } n     t += y; n   } n   int ans = 5555555; n   for (i = 0; i <= t; i++) ans = min(ans, dp[n][i]); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxl = 2 * 1000 * 100 + 5; n const int maxlg = 22; n vector<pair<int, int> > adj[maxl]; n vector<int> tree[maxl]; n int n, m, q; n int mark[maxl], depth[maxl]; n bool cut[maxl]; n int dsu[maxl]; n int arr[maxl]; n int lca[maxl][maxlg]; n int psum1[maxl], psum2[maxl]; n bool flag = true; n int par(int index) { n   if (dsu[index] < 0) return index; n   return dsu[index] = par(dsu[index]); n } n inline void merge(int a, int b) { n   a = par(a); n   b = par(b); n   if (a == b) return; n   if (dsu[a] < dsu[b]) swap(a, b); n   dsu[b] += dsu[a]; n   dsu[a] = b; n   return; n } n inline int getPar(int index, int x) { n   int ind = 0; n   while (x) { n     if (x & 1) index = lca[index][ind]; n     ind++; n     x /= 2; n   } n   return index; n } n inline int Lca(int a, int b) { n   if (depth[a] < depth[b]) swap(a, b); n   a = getPar(a, depth[a] - depth[b]); n   if (a == b) return a; n   for (int i = maxlg - 1; i >= 0; i--) n     if (lca[a][i] != lca[b][i]) { n       a = lca[a][i]; n       b = lca[b][i]; n     } n   return lca[a][0]; n } n int dfs_cut(int index, int par = -1) { n   mark[index] = 1; n   int mn = depth[index]; n   for (int i = 0; i < adj[index].size(); i++) { n     int node = adj[index][i].first, edge = adj[index][i].second; n     if (mark[node] == 1 && edge != par) mn = min(mn, depth[node]); n     if (!mark[node]) { n       depth[node] = depth[index] + 1; n       int tmp = dfs_cut(node, edge); n       mn = min(mn, tmp); n       cut[edge] = (tmp >= depth[node]); n     } n   } n   mark[index] = 2; n   return mn; n } n void dfs(int index, int par = -1) { n   lca[index][0] = par; n   if (par == -1) lca[index][0] = index; n   for (int i = 0; i < tree[index].size(); i++) { n     int node = tree[index][i]; n     if (node != par) { n       depth[node] = depth[index] + 1; n       dfs(node, index); n       psum1[index] += psum1[node]; n       psum2[index] += psum2[node]; n       if (psum1[node] && psum2[node]) flag = false; n     } n   } n } n int main() { n   memset(dsu, -1, sizeof dsu); n   memset(lca, -1, sizeof lca); n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     a--; n     b--; n     adj[a].push_back(make_pair(b, i)); n     adj[b].push_back(make_pair(a, i)); n   } n   for (int i = 0; i < n; i++) n     if (!mark[i]) dfs_cut(i); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < adj[i].size(); j++) { n       int node = adj[i][j].first, edge = adj[i][j].second; n       if (!cut[edge]) merge(i, node); n     } n   for (int i = 0; i < n; i++) arr[i] = par(i); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < adj[i].size(); j++) { n       int node = adj[i][j].first, edge = adj[i][j].second; n       merge(i, node); n       int x = arr[i], y = arr[node]; n       if (x == y) continue; n       tree[x].push_back(y); n     } n   memset(depth, 0, sizeof depth); n   for (int i = 0; i < n; i++) n     if (arr[i] == i && lca[i][0] == -1) dfs(i); n   for (int j = 1; j < maxlg; j++) n     for (int i = 0; i < n; i++) n       if (arr[i] == i) lca[i][j] = lca[lca[i][j - 1]][j - 1]; n   for (int i = 0; i < q; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     y--; n     x = arr[x]; n     y = arr[y]; n     if (par(x) != par(y)) { n       flag = false; n       continue; n     } n     int node = Lca(x, y); n     psum1[x]++; n     psum1[node]--; n     psum2[y]++; n     psum2[node]--; n   } n   for (int i = 0; i < n; i++) n     if (arr[i] == i && lca[i][0] == i) dfs(i); n   if (flag) n     printf( Yes n ); n   else n     printf( No n ); n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n long long add(long long a, long long b) { n   long long ret = a + b; n   if (ret >= 1000000007) ret -= 1000000007; n   return ret; n } n long long subtract(long long a, long long b) { n   long long ret = a - b; n   if (ret < 0) ret += 1000000007; n   return ret; n } n long long mult(long long a, long long b) { n   long long ret = a * b; n   if (ret >= 1000000007) ret %= 1000000007; n   return ret; n } n long long bigmod(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = mult(ret, a); n     b >>= 1; n     a = mult(a, a); n   } n   return ret; n } n long long inverse(long long n) { return bigmod(n, 1000000007 - 2); } n bool base[1000010]; n vector<int> primes; n void sieve(int mx) { n   mx += 10; n   int x = sqrt(mx); n   for (int i = 3; i <= x; i += 2) n     if (base[i] == 0) n       for (int j = i * i, k = i << 1; j < mx; j += k) base[j] = 1; n   primes.push_back(2); n   for (int i = 3; i < mx; i += 2) n     if (base[i] == 0) primes.push_back(i); n } n bool checkBit(int n, int i) { return (n & (1 << i)); } n int setBit(int n, int i) { return (n | (1 << i)); } n int resetBit(int n, int i) { return (n & (~(1 << i))); } n char a[22], b[22]; n int c[22]; n struct node { n   int end; n   node *next[2]; n   node() { n     end = 0; n     next[0] = next[1] = NULL; n   } n } * root; n void insert(int val) { n   node *curr = root; n   for (int i = 0; i < 18; ++i) { n     int id = c[i]; n     if (curr->next[id] == NULL) curr->next[id] = new node; n     curr = curr->next[id]; n   } n   curr->end += val; n } n int query() { n   node *curr = root; n   for (int i = 0; i < 18; ++i) { n     int id = c[i]; n     if (curr->next[id] == NULL) return 0; n     curr = curr->next[id]; n   } n   return curr->end; n } n int main() { n   int q; n   scanf( %d , &q); n   root = new node; n   while (q--) { n     scanf( %s , a); n     scanf( %s , b); n     int n = strlen(b); n     for (int i = 0; i < 18 - n; ++i) c[i] = 0; n     for (int i = 0; i < n; ++i) c[18 - n + i] = ((b[i] -  0 ) & 1); n     if (a[0] ==  + ) n       insert(1); n     else if (a[0] ==  - ) n       insert(-1); n     else { n       printf( %d n , query()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t dp[2004], nx[2004]; n struct pt { n   int64_t v, c; n }; n int main() { n   ios::sync_with_stdio(false); n   int n, m, q; n   cin >> n >> m >> q; n   vector<vector<pair<int, int>>> G(n + 1); n   vector<int> val(n + 1, 0); n   vector<int64_t> cost(n + 1, 0); n   for (int i = 0; i < m; ++i) { n     int a, b, c; n     cin >> a >> b >> c; n     G[a].push_back({b, c}); n     G[b].push_back({a, c}); n     val[a] = max(val[a], c); n     val[b] = max(val[b], c); n   } n   int64_t ans = 0, md = 1000000007; n   for (int j = 2; j <= n; ++j) dp[j] = -1e12; n   for (int i = 0; i < m; ++i) { n     int64_t tm = 0; n     for (int j = 1; j <= n; ++j) { n       nx[j] = -1e12; n       for (auto to : G[j]) { n         nx[j] = max(nx[j], dp[to.first] + to.second); n       } n       tm = max(tm, nx[j]); n     } n     ans = (ans + tm) % md; n     swap(dp, nx); n   } n   for (int i = 1; i <= n; ++i) { n     cost[i] = val[i] * 1ll * m - dp[i]; n   } n   vector<pt> v; n   for (int i = 1; i <= n; ++i) { n     v.push_back({val[i], cost[i]}); n   } n   int64_t nowq = m + 1; n   int64_t mx = 0; n   int mxi = 0; n   for (int i = 0; i < v.size(); ++i) { n     if (nowq * v[i].v - v[i].c > mx) { n       mx = nowq * v[i].v - v[i].c; n       mxi = i; n     } n   } n   while (nowq <= q) { n     int64_t nxq = q + 1; n     for (int i = 0; i < v.size(); ++i) { n       if (v[i].v > v[mxi].v) { n         nxq = min(nxq, 1 + (v[i].c - v[mxi].c) / (v[i].v - v[mxi].v)); n       } n     } n     int64_t q2 = (nxq - nowq) * (nxq - nowq - 1) / 2; n     q2 %= md; n     ans += (nxq - nowq) * (mx % md) + (v[mxi].v * q2) % md; n     ans %= md; n     mx = 0; n     for (int i = 0; i < v.size(); ++i) { n       if (nxq * v[i].v - v[i].c > mx) { n         mx = nxq * v[i].v - v[i].c; n         mxi = i; n       } n     } n     nowq = nxq; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int A[3] = {0}; n   int num; n   cin >> num; n   long ip; n   while (num--) { n     cin >> ip; n     if (ip % 3 == 0) n       A[0]++; n     else if (ip % 3 == 1) n       A[1]++; n     else if (ip % 3 == 2) n       A[2]++; n   } n   cout << A[0] / 2 + min(A[1], A[2]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ret, f[26]; n vector<pair<pair<int, int>, int> > ss; n int call(char c) { return int(c) - int( a ); } n int main() { n   cin >> n; n   string s; n   for (int i = 1; i <= n; i++) { n     cin >> s; n     ss.push_back(make_pair(make_pair(call(s[0]), call(s[long(s.length()) - 1])), n                            long(s.length()))); n   } n   ret = 0; n   for (int c = 0; c < 26; c++) { n     fill(f + 0, f + 26, 0); n     for (int i = 0; i < n; i++) { n       if ((ss[i].first.first == c) || (f[ss[i].first.first] > 0)) { n         f[ss[i].first.second] = n             max(f[ss[i].first.second], f[ss[i].first.first] + ss[i].second); n       } n     } n     ret = max(ret, f[c]); n   } n   printf( %d , ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, m, t, cnt, r[105]; n int main() { n   scanf( %d , &n); n   for (int i = (0); i <= (n); i++) { n     ++cnt; n     if (i < n) scanf( %d , &x); n     if (x < 0) ++t; n     if (t == 3 || i == n) { n       r[m++] = cnt - 1; n       cnt = t = 1; n     } n   } n   printf( %d n , m); n   for (int i = (0); i < (m); i++) printf( %d  , r[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i = 0; n   string a, b; n   vector<pair<string, string> > vec; n   cin >> n; n   while (n--) { n     cin >> a >> b; n     vec.push_back(make_pair(a, b)); n   } n   n = 0; n   sort(vec.begin(), vec.end()); n   while (i < vec.size()) { n     n++; n     while (i < vec.size() - 1 && vec[i].first == vec[i + 1].first && n            vec[i].second == vec[i + 1].second) n       i++; n     i++; n   } n   cout << n << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n int vowel(char a) { n   if (a ==  a  || a ==  i  || a ==  e  || a ==  u  || a ==  o ) { n     return 1; n   } n   return 0; n } n int main() { n   char s[1005]; n   char t[1005]; n   int i; n   scanf( %s , s); n   scanf( %s , t); n   if (strlen(s) != strlen(t)) { n     printf( NO n ); n     return 0; n   } n   for (i = 0; i < strlen(s); i++) { n     if (vowel(s[i]) != vowel(t[i])) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[50][50]; n int main() { n   long long int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     for (int i = 0; i < n; i++) { n       string s; n       cin >> s; n       for (int j = 0; j < n; j++) { n         A[i][j] = s[j] -  0 ; n       } n     } n     bool f = true; n     for (int i = 0; i < n - 1; i++) { n       for (int j = 0; j < n - 1; j++) { n         if (A[i][j] && !A[i + 1][j] && !A[i][j + 1]) { n           f = false; n           i = n; n           break; n         } n       } n     } n     cout << ((f) ?  YES  :  NO ) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, p[500500], pp[500500], t = 1; n vector<long long> s, f; n int fd(long long x) { n   if (x == pp[x]) { n     return x; n   } n   return pp[x] = fd(pp[x]); n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     p[i] = i; n     pp[i] = i; n   } n   for (int i = 1; i <= m; i++) { n     long long x; n     cin >> x; n     if (x == 1) { n       long long l, r; n       cin >> l >> r; n       p[l] = r; n       pp[l] = r; n     } n     if (x == 2) { n       long long r; n       cin >> r; n       s.push_back(r); n       f.push_back(fd(r)); n     } n     if (x == 3) { n       long long r, y; n       cin >> r >> y; n       int st = s[y - 1], fn = f[y - 1]; n       while (st != fn) { n         if (st == r) { n           break; n         } n         st = p[st]; n       } n       if (st == r) { n         cout <<  YES  << endl; n         continue; n       } n       cout <<  NO  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, a[100010], b[100010], c[100], w, e; n long long ans = 0; n void init() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= 90; i++) c[i] = 0; n   sort(a + 1, a + n + 1); n   w = 1; n   for (int i = 1; i <= n; i++) { n     while (a[i] > ((1 << w) - 1)) w++; n     b[i] = w; n     c[w]++; n   } n   ans = 0; n   for (int i = 1; i <= w; i++) ans = ans + (c[i] - 1) * c[i] / 2; n   cout << ans << endl; n } n int main() { n   cin >> t; n   for (int q = 1; q <= t; q++) init(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int N=10,M=405,mod=998244353; n int n,m,k,t,v[M],id[M][M],ch[M][30],l[N]; n char s[N][N]; n struct mat{int a[M][M];}; n mat operator*(mat x,mat y) n { n  mat z; n  for(int i=1;i<=t;i++) n  { n   for(int j=1;j<=t;j++) n   { n    z.a[i][j]=0; n    for(int k=1;k<=t;k++) n     z.a[i][j]=(z.a[i][j]+1ll*x.a[i][k]*y.a[k][j]%mod)%mod; n   } n  } n  return z; n } n mat qp(mat a,int b) n { n  mat ans=a; n  b--; n  while(b) n  { n   if(b&1) n    ans=ans*a; n   a=a*a; n   b>>=1; n  } n  return ans; n } n mat tr; n int sol(int x,int y) n { n  if(x>y) n   swap(x,y); n  if(id[x][y]) n   return id[x][y]; n  int u=++t; n  id[x][y]=u; n  for(int i=0;i<26;i++) n  { n   if(ch[x][i]&&ch[y][i]) n   { n    int nx1=ch[x][i],nx2=ch[y][i]; n    tr.a[u][sol(nx1,nx2)]++; n    if(v[nx1]) n     tr.a[u][sol(1,nx2)]++; n    if(v[nx2]) n     tr.a[u][sol(nx1,1)]++; n    if(v[nx1]&&v[nx2]) n     tr.a[u][sol(1,1)]++; n   } n  } n  return u; n } n int main() n { n  scanf( %d%d ,&n,&m); n  k=1; n  for(int i=1;i<=n;i++) n  { n   scanf( %s ,s[i]+1),l[i]=strlen(s[i]+1); n   int u=1; n   for(int j=1;j<=l[i];j++) n   { n    int x=s[i][j]- a ; n    if(!ch[u][x]) n     ch[u][x]=++k; n    u=ch[u][x]; n   } n   v[u]=1; n  } n  memset(tr.a,0,sizeof(tr.a)); n  int b=sol(1,1); n  tr=qp(tr,m); n  printf( %d n ,tr.a[b][b]); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long int a[4005]; n long long int dp[4005][4005]; n int m; n int dfs(int l, int r) { n   if (l > r) return 0; n   long long int mi = 1e18; n   long long int root = -1; n   for (int i = l; i <= r; i++) { n     if (a[i] < mi) { n       mi = a[i]; n       root = i; n     } n   } n   int root_l = dfs(l, root - 1); n   int root_r = dfs(root + 1, r); n   int sz = r - l + 1; n   for (int i = 0; i <= sz; i++) { n     int sz_l = root - l; n     int sz_r = r - root; n     dp[root][i] = -1e18; n     for (int j = max(0, i - sz_r - 1); j <= min(sz_l, i); j++) { n       dp[root][i] = max(dp[root][i], dp[root_l][j] + dp[root_r][i - j] - n                                          2ll * j * (i - j) * a[root]); n       if (i - 1 - j >= 0) n         dp[root][i] = max(dp[root][i], dp[root_l][j] + dp[root_r][i - 1 - j] - n                                            2ll * (j + 1) * (i - j) * a[root] + n                                            a[root] + 1ll * m * a[root]); n     } n   } n   return root; n } n int main(void) { n   int n; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 0; i <= n; i++) { n     dp[0][i] = -1e18; n   } n   dp[0][0] = 0; n   int root = dfs(1, n); n   printf( %lld n , dp[root][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5010; n const int mod = 1e9 + 7; n const int INF = 0x3f3f3f3f; n const double pi = acos(-1.0); n const double eps = 1e-4; n int main() { n   double d, l, v1, v2; n   cin >> d >> l >> v1 >> v2; n   printf( %.6lf n , (l - d) / (v1 + v2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class S, class T> n ostream& operator<<(ostream& o, const pair<S, T>& p) { n   return o <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& o, const vector<T>& vc) { n   o <<  sz =   << vc.size() << endl <<  [ ; n   for (const T& v : vc) o << v <<  , ; n   o <<  ] ; n   return o; n } n int cnt; n vector<int> ask(int v) { n   cout <<  ?   << v << endl; n   int K; n   cin >> K; n   vector<int> ret; n   for (int i = 0; i < (int)(K); i++) { n     int x; n     cin >> x; n     ret.push_back(x); n   } n   cnt++; n   assert(cnt <= 16); n   return ret; n } n void ans(int v) { cout <<  !   << v << endl; } n bool ToLeaf(int v, int p, vector<int>& vs, vector<vector<int> >& vis) { n   while (true) { n     vector<int> vi = ask(v); n     if (vi.size() == 2) { n       ans(v); n       return 1; n     } n     vs.push_back(v); n     vis.push_back(vi); n     if (vi.size() == 1) break; n     int nv = -1; n     for (int i = 0; i < (int)(3); i++) n       if (vi[i] != p) nv = vi[i]; n     p = v, v = nv; n   } n   return 0; n } n bool Leaf2Leaf(vector<int>& vs, vector<vector<int> >& vis) { n   int s = 1; n   if (ToLeaf(s, -1, vs, vis)) return 1; n   if (vs.size() == 1) return 0; n   int nxt = -1; n   for (int nv : vis[0]) n     if (nv != vs[1]) nxt = nv; n   reverse(vs.begin(), vs.end()); n   reverse(vis.begin(), vis.end()); n   if (ToLeaf(nxt, s, vs, vis)) return 1; n   return 0; n } n bool dfs(int v, int p, int d = 0) { n   vector<int> vi = ask(v); n   if (vi.size() == 2) { n     ans(v); n     return 1; n   } n   if (d == 2) { n     return 0; n   } n   for (int u : vi) n     if (u != p) { n       if (cnt < 16) { n         if (dfs(u, v, d + 1)) return 1; n       } else { n         ans(u); n         return 1; n       } n     } n   return 0; n } n void solve() { n   cnt = 0; n   int H; n   cin >> H; n   vector<int> vs; n   vector<vector<int> > vis; n   if (Leaf2Leaf(vs, vis)) { n     return; n   } n   int K = vs.size(); n   while (K <= 5) { n     int top = vs[K / 2]; n     int nxt = -1; n     if (vis[K / 2].size() == 1) n       nxt = vis[K / 2][0]; n     else n       nxt = vis[K / 2][0] ^ vis[K / 2][1] ^ vis[K / 2][2] ^ vs[K / 2 - 1] ^ n             vs[K / 2 + 1]; n     for (int i = 0; i < (int)(K / 2); i++) vs.pop_back(), vis.pop_back(); n     if (ToLeaf(nxt, top, vs, vis)) { n       return; n     } n     K = vs.size(); n   } n   int top = vs[K / 2]; n   int nxt = vis[K / 2][0] ^ vis[K / 2][1] ^ vis[K / 2][2] ^ vs[K / 2 - 1] ^ n             vs[K / 2 + 1]; n   assert(dfs(nxt, top)); n } n int main() { n   int T; n   cin >> T; n   for (int t = 0; t < (int)(T); t++) solve(); 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   ; n   long long n; n   cin >> n; n   long long d = 0; n   vector<long long> v; n   vector<long long> a; n   long long val = 0; n   map<long long, long long> m; n   long long start = 0, end = -1, count = 0; n   for (long long i = 0; i < (long long)n; i++) { n     cin >> val; n     if (i == 0) { n       if (val < 0) { n         count++; n         break; n       } else { n         v.push_back(val); n         m[val]++; n       } n     } else { n       if (val > 0) { n         if (m[val] >= m[-val] && m[val] == 0) { n           v.push_back(val); n           m[val]++; n         } else { n           count++; n           break; n         } n       } else { n         if (v.size() == 0 && start != end) { n           d++; n           end = i; n           a.push_back(end - start + 1); n           start = i + 1; n           m.clear(); n         } n         if (m[val] >= m[-val]) { n           count++; n           break; n         } else { n           m[val]++; n           for (long long j = 0; j < v.size(); j++) { n             if (v[j] == (-val)) { n               v.erase(v.begin() + j); n               break; n             } n           } n         } n         if (v.size() == 0 && start != end) { n           d++; n           end = i; n           a.push_back(end - start + 1); n           start = i + 1; n           m.clear(); n         } n       } n     } n   } n   if (v.size() != 0 || count > 0) { n     cout << -1 <<   n ; n   } else { n     cout << d <<   n ; n     for (long long i = 0; i < a.size(); i++) { n       cout << a[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   long long ar[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   ar[0] = 0; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     long long x = ar[i]; n     long long y = ar[i + 1]; n     if (x > y) { n       ans += y * (x - y); n     } n     if (x < y) { n       ans += (y - x) * (n - y + 1); n     } n   } n   cout << ans; n } n


#include <iostream> n #include <vector> n #include <algorithm> n #include <math.h> n  n using namespace std; n  n #define fi first n #define se second n #define all(x) x.begin(), x.end() n #define sz(x) x.size() n #define pb push_back n #define mk make_pair n #define tests int t; cin >> t; while(t--) n #define forn(i, a, b) for (int i = a; i < b; i++) n  n typedef long long ll; n typedef long double ld; n  n const int Z = (int)1e5 + 123; n const int inf = (int)2e9 + 123; n const ll llinf = (ll)9e18 + 123; n  n int main() { n     tests { n         int n; n         cin >> n; n         ll a = 0, b = n % 10; n         bool flag = false; n         while ((b * 2021) + (a * 2020) <= n) { n             if ((n - (b * 2021)) % 2020 > 0) { n                 b += 10; n                 continue; n             } else { n                 flag = true; n                 break; n             } n         } n         cout << (flag ?  YES n  :  NO n ); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y >= 1) { n     if (y % 2) res = (res * x) % p; n     x = ((x % p) * (x % p)) % p; n     y /= 2; n   } n   return res; n } n void solve() { n   long long int n, m; n   cin >> n >> m; n   cout << power(power(2, m, 1000000007) - 1, n, 1000000007) <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   int m = max(3 * a / 10, a - a / 250 * c); n   int v = max(3 * b / 10, b - b / 250 * d); n   if (m == v) n     cout <<  Tie ; n   else if (m > v) n     cout <<  Misha ; n   else n     cout <<  Vasya ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6 + 6; n long long int arr[2000005], brr[2000005], crr[2000005]; n void solve(int n, long long int arr[]) { n   int cnt = n + arr[0]; n   for (int i = 1; i < n; i++) { n     cnt += abs(arr[i] - arr[i - 1]) + 1; n   } n   cout << cnt; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   solve(n, arr); n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFTY = 20000000; n const int MAX = 500100; n const int MOD = 10000000; n void coutTab(int* tab, int n) { n   for (int i = 0; i < n; i++) { n     cout << tab[i] <<    ; n   } n   cout <<   n ; n } n string create(int a, int b, int x, int start) { n   if (start == 0) n     a--; n   else n     b--; n   string s; n   s.push_back(start +  0 ); n   char l; n   for (int i = 0; i < x - 1; i++) { n     l = s[s.size() - 1]; n     if (l ==  1 ) { n       s.push_back( 0 ); n       a--; n     } else { n       s.push_back( 1 ); n       b--; n     } n   } n   l = s[s.size() - 1]; n   if (l ==  0 ) { n     while (a--) s.push_back( 0 ); n     while (b--) s.push_back( 1 ); n   } else { n     while (b--) s.push_back( 1 ); n     while (a--) s.push_back( 0 ); n   } n   return s; n } n bool check(string s, int x) { n   int j = 0; n   for (int i = 1; i < s.size(); i++) { n     if (s[i - 1] != s[i]) j++; n   } n   return x == j; n } n int main() { n   ios_base::sync_with_stdio(0); n   int a, b, x; n   cin >> a >> b >> x; n   string res = create(a, b, x, 0); n   if (!check(res, x)) res = create(a, b, x, 1); n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct NODE { n   int to, next; n } node[200000 + 10]; n long long dp[100000 + 10], k[100000 + 10]; n int n, tol; n int head[100000 + 10]; n void addedge(int from, int to) { n   node[tol].to = to; n   node[tol].next = head[from]; n   head[from] = tol++; n } n void tree_dp(int now, int fa) { n   priority_queue<long long, vector<long long>, less<long long> > que; n   while (!que.empty()) que.pop(); n   for (int i = head[now]; i != -1; i = node[i].next) { n     int v = node[i].to; n     if (v != fa) { n       k[v]--; n       tree_dp(v, now); n       que.push(dp[v]); n     } n   } n   while (k[now] && !que.empty()) { n     k[now]--; n     int p = que.top(); n     dp[now] += que.top() + 2; n     que.pop(); n   } n   for (int i = head[now]; i != -1; i = node[i].next) { n     if (k[now] == 0) break; n     int v = node[i].to; n     if (v != fa) { n       long long t = min(k[now], k[v]); n       dp[now] += t * 2; n       k[now] -= t; n     } n   } n } n int main() { n   while (scanf( %d , &n) != EOF) { n     memset(head, -1, sizeof(head)); n     tol = 0; n     for (int i = 1; i <= n; i++) scanf( %I64d , &k[i]); n     for (int i = 1; i <= n - 1; i++) { n       int u, v; n       scanf( %d %d , &u, &v); n       addedge(u, v); n       addedge(v, u); n     } n     int root; n     scanf( %d , &root); n     memset(dp, 0, sizeof(dp)); n     tree_dp(root, 0); n     printf( %I64d n , dp[root]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200004, M = 19; n vector<int> g[N]; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int d[N], fa[N][M], n; n long long w[N][M], a[N], mod = 1000000007; n void bfs() { n   d[1] = 1; n   for (int i = 0; i < M; i++) w[1][i] = a[1]; 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]) continue; n       d[v] = d[u] + 1; n       fa[v][0] = u; n       w[v][0] = a[v]; n       for (int i = 1; i < M; i++) { n         fa[v][i] = fa[fa[v][i - 1]][i - 1]; n         w[v][i] = gcd(w[v][i - 1], w[fa[v][i - 1]][i - 1]); n       } n       q.push(v); n     } n   } n } n int main() { n   int x, y; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 1; i < n; i++) { n     scanf( %d %d , &x, &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   bfs(); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     long long nw = a[i]; n     int pre = d[i]; n     for (;;) { n       int v = i; n       for (int j = M - 1; j >= 0; j--) n         if (w[v][j] == 0) v = fa[v][j]; n       for (int j = M - 1; j >= 0; j--) n         if (gcd(nw, w[v][j]) == nw) v = fa[v][j]; n       ans = (ans + nw * (pre - d[v])) % mod; n       if (v == 0) break; n       nw = gcd(nw, a[v]); n       pre = d[v]; n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int mera[100001]; n   int snct[100001]; n   string s; n   cin >> s; n   int len = s.length(); n   stack<int> st; n   if (s[0] ==  [ ) { n     snct[0] = 1; n   } else { n     snct[0] = 0; n   } n   for (int i = 1; i < len; i++) { n     snct[i] = snct[i - 1]; n     if (s[i] ==  [ ) { n       snct[i]++; n     } n   } n   for (int i = 0; i < len; i++) { n     mera[i] = -1; n     if (s[i] ==  (  || s[i] ==  [ ) { n       st.push(i); n     } else if (s[i] ==  ) ) { n       if (!st.empty()) { n         int h = st.top(); n         if (h != -1 && s[h] ==  ( ) { n           mera[i] = h; n           st.pop(); n         } else { n           st.push(-1); n         } n       } n     } else { n       if (!st.empty()) { n         int h = st.top(); n         if (h != -1 && s[h] ==  [ ) { n           mera[i] = h; n           st.pop(); n         } else { n           st.push(-1); n         } n       } n     } n   } n   for (int i = 0; i < len; i++) { n     if (mera[i] != -1 && mera[i] > 0 && mera[mera[i] - 1] != -1) { n       mera[i] = mera[mera[i] - 1]; n     } n   } n   int max = 0; n   int x = -1; n   for (int i = 0; i < len; i++) { n     if (mera[i] != -1) { n       int c = snct[i]; n       if (mera[i] > 0) c -= snct[mera[i] - 1]; n       if (c > max) { n         x = i; n         max = c; n       } n     } n   } n   cout << max << endl; n   if (max > 0) cout << s.substr(mera[x], x - mera[x] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   int a[n], g[n]; n   int sa = 0, sg = 0; n   char ans[n]; n   for (int i = 0; i < n; ++i) { n     cin >> a[i] >> g[i]; n   } n   for (int i = 0; i < n; ++i) { n     sa += a[i]; n     if (sa <= 500) { n       ans[i] =  A ; n     } else if (sa > 500) { n       sa -= 1000; n       ans[i] =  G ; n     } else { n       cout <<  -1 ; n       return 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     cout << ans[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int INF = MOD; n vector<int> a[200]; n int cnt = 0; n bool used[200]; n void dfs(int v) { n   used[v] = true; n   for (int i = 0; i < a[v].size(); i++) n     if (!used[a[v][i]]) dfs(a[v][i]); n } n bool flag = false; n vector<pair<int, int> > ans; n int main() { n   std::ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   if (m == 3 && (n == 5 || n == 6)) { n     cout << -1 << endl; n     return 0; n   } n   if (m == 3 && n == 4) { n     cout << -1 <<     << 0 << endl; n     cout << 0 <<     << 0 << endl; n     cout << 1 <<     << 1 << endl; n     cout << 1 <<     << -1 << endl; n     return 0; n   } n   int cnt = n; n   for (int i = 0; i < m; i++, cnt--) cout << i <<     << i * i << endl; n   for (int i = 0, x = 4 * m * m; cnt > 0; i++, cnt--, x--) n     cout << x <<     << m * m - i * i << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   cin >> s; n   vector<long long> cnt(26); n   long long posl = 1e9, posr = 0; n   for (auto c : s) { n     cnt[c -  a ]++; n     posl = min(posl, (long long)(c -  a )); n     posr = max(posr, (long long)(c -  a )); n   } n   for (long long i = posl; i <= posr; i++) { n     if (cnt[i] != 1) { n       cout <<  No n ; n       return; n     } n   } n   cout <<  Yes n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout << fixed; n   cout.precision(30); n   long long t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long N = 1e6 + 5; n long long solve() { n   long long n; n   cin >> n; n   map<long long, long long> mp; n   vector<long long> v(n); n   for (long long &x : v) { n     cin >> x; n     mp[x]++; n   } n   long long ans = 0; n   for (auto it : mp) { n     long long usable = (long long)mp.size() - 1; n     long long use = min(usable, it.second); n     if (it.second > usable + 1) { n       ++use; n     } n     ans = max(ans, use); n   } n   cout << ans <<   n ; n   return 0; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long T = 1; n   cin >> T; n   for (long long i = 1; i <= T; ++i) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const double EPS = 1e-9; n int n, m, t[210][210], d[210][210]; n bool active[210]; n vector<pair<int, int> > x_sorted; n double calc(int x, int y) { n   double ans = INF; n   vector<pair<int, int> > s; n   multiset<int> up; n   int down = -INF; n   for (int i = 1; i <= n; i++) { n     int tmp = t[x][y] + d[y][i] - d[x][i]; n     active[i] = false; n     if (tmp < 0) n       down = max(down, t[x][y] + d[y][i]); n     else if (tmp > 2 * t[x][y]) { n       active[i] = true; n     } else { n       s.push_back(make_pair(tmp, i)); n       active[i] = true; n     } n   } n   active[0] = true; n   s.push_back(make_pair(0, -1)); n   s.push_back(make_pair(2 * t[x][y], -1)); n   sort(s.begin(), s.end()); n   int _x_sorted = 0; n   for (int i = 0; i + 1 < s.size(); i++) { n     if (s[i].second > -1) { n       active[s[i].second] = false; n       down = max(down, t[x][y] + d[y][s[i].second]); n     } n     while (!active[x_sorted[_x_sorted].second]) ++_x_sorted; n     int up_best = x_sorted[_x_sorted].first; n     int z = down - up_best; n     z = max(s[i].first, z); n     z = min(s[i + 1].first, z); n     ans = min(ans, max(up_best + 0.5 * z, down - 0.5 * z)); n   } n   return ans; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) t[i][j] = INF; n   while (m--) { n     int x, y, z; n     scanf( %d %d %d , &x, &y, &z); n     t[x][y] = t[y][x] = z; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) d[i][j] = i == j ? 0 : t[i][j]; n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); n   double ans = INF; n   for (int i = 1; i <= n; i++) { n     x_sorted.clear(); n     for (int j = 1; j <= n; j++) x_sorted.push_back(make_pair(d[i][j], j)); n     x_sorted.push_back(make_pair(-1, 0)); n     sort(x_sorted.begin(), x_sorted.end()); n     reverse(x_sorted.begin(), x_sorted.end()); n     for (int j = 1; j < i; j++) ans = min(ans, calc(i, j)); n   } n   printf( %.9lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i < n + 1; i++) { n     for (int j = 1; j < m + 1; j++) { n       if (i % 4 == 2) { n         if (j == m) { n           cout <<  # ; n         } else { n           cout <<  . ; n         } n       } else if (i % 4 == 0) { n         if (j == 1) { n           cout <<  # ; n         } else { n           cout <<  . ; n         } n       } else { n         cout <<  # ; n       } n     } n     cout <<   n ; n   } n   return 0; n } n


/** try <3 **/ n  n #include<bits/stdc++.h> n  n using namespace std; n  n #define task  sol  n #define lb lower_bound n #define ub upper_bound n #define fi first n #define se second n #define pb push_back n #define mp make_pair n #define zs(v) ((int)(v).size()) n #define BIT(x, i) (((x) >> (i)) & 1) n #define CNTBIT __builtin_popcountll n #define ALL(v) (v).begin(),(v).end() n #define endl   n  n  n typedef long double ld; n typedef long long ll; n typedef pair<int,int> pii; n  n void gogo() n { n     int x; n     cin>>x; n  n     ll s=0, ans=0; n  n     for(int i=1;i<=x;++i) n     { n         s+=i; n         ans=i; n         if(s>=x) break; n     } n  n     if(!(s==x||s>x+1)) ++ans; n     cout<<ans<<  n ; n } n int main() n { n     ios_base::sync_with_stdio(0); cin.tie(0); n     if(fopen(task .inp , r )) n     { n         freopen(task .inp , r ,stdin); n         freopen(task .out , w ,stdout); n     } n     int t; n     cin>>t; n     while(t--) gogo(); n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a[60], b[60]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   cin >> m; n   for (int i = 0; i < m; i++) cin >> b[i]; n   int BG = -1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (!(b[j] % a[i])) { n         if (b[j] / a[i] > BG) { n           BG = b[j] / a[i]; n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (!(b[j] % a[i]) && b[j] / a[i] == BG) { n         ans++; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int t, h, m; n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d , &h, &m); n     printf( %d n , (23 - h) * 60 + (60 - m)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Max = 1000000100; n vector<long long> s; n void dfs(long long temp) { n   if (temp > Max) { n     return; n   } n   long long x = temp * 10 + 4; n   if (temp > Max) { n     return; n   } n   s.push_back(x); n   dfs(x); n   long long y = temp * 10 + 7; n   if (temp > Max) { n     return; n   } n   s.push_back(y); n   dfs(y); n } n int main() { n   dfs(0); n   s.push_back(0); n   sort(s.begin(), s.end()); n   long long l, r, x, y; n   int n; n   cin >> l >> r >> x >> y >> n; n   long long temp = l > x ? x : l; n   int i = lower_bound(s.begin(), s.end(), temp) - s.begin(); n   double sum = 0; n   while (true) { n     long long a = s[i - 1] + 1; n     long long b = s[i]; n     long long c = s[i + n - 1]; n     long long d = s[i + n] - 1; n     if (a > r && a > y) break; n     if (c > r && c > y) break; n     long long A = a > l ? a : l; n     long long B = b < r ? b : r; n     long long C = c > x ? c : x; n     long long D = d < y ? d : y; n     int shabi; n     int z = 0; n     if (n == 1 && B == C) { n       int o = lower_bound(s.begin(), s.end(), B) - s.begin(); n       if (s[o] == B) z = 1; n     } n     if (z) shabi = D; n     if (A <= B && C <= D) { n       if (z) n         sum += (double)(B - A) / (double)(r - l + 1) * (double)(D - C + 1) / n                (double)(y - x + 1); n       else n         sum += (double)(B - A + 1) / (double)(r - l + 1) * (double)(D - C + 1) / n                (double)(y - x + 1); n     } n     A = a > x ? a : x; n     B = b < y ? b : y; n     C = c > l ? c : l; n     D = d < r ? d : r; n     if (A <= B && C <= D) { n       if (z) n         sum += (double)(B - A + 1) / (double)(y - x + 1) * (double)(D - C) / n                (double)(r - l + 1); n       else n         sum += (double)(B - A + 1) / (double)(y - x + 1) * (double)(D - C + 1) / n                (double)(r - l + 1); n     } n     if (z) { n       sum += (double)(shabi - A + 1) / (double)(y - x + 1) * (double)(1) / n              (double)(r - l + 1); n     } n     i++; n   } n   printf( %.12lf , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fact[1000001], power[1000001]; n long long powerr(long long x, long long y); n long long mpower(long long x, long long y, long long p); n long long gcdExtended(long long a, long long b); n bool isPrime(long long n); n long long func(long long n) { n   long long x = sqrt(n); n   if (n % x == 0) x = x + 1; n   long long i; n   for (i = 2; i < n / 2; i++) { n     if (n % i == 0 && isPrime(i) == true) { n       return i; n     } n   } n   return n; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t, j, k, l, h, p, q, r, x, i, y, z, a, b, c, d, f, n, m, n       M = 1000000007; n   char ch, ch2, ch3; n   string s1, s2, s3; n   vector<long long> v, w; n   set<long long> S; n   t = 1; n   while (t--) { n     cin >> n >> m >> x >> y; n     cout << x <<     << y; n     cout <<   n ; n     z = 0; n     for (j = x - 1; j < n; j++) { n       if (z == 0) { n         for (k = z; k < m; k++) { n           if (j == x - 1 && k == y - 1) n             continue; n           else { n             cout << j + 1 <<     << k + 1; n             cout <<   n ; n           } n         } n         z = m - 1; n       } else { n         for (k = m - 1; k >= 0; k--) { n           if (j == x - 1 && k == y - 1) n             continue; n           else { n             cout << j + 1 <<     << k + 1; n             cout <<   n ; n           } n         } n         z = 0; n       } n     } n     for (j = x - 2; j >= 0; j--) { n       if (z == 0) { n         for (k = z; k < m; k++) { n           if (j == x - 1 && k == y - 1) n             continue; n           else { n             cout << j + 1 <<     << k + 1; n             cout <<   n ; n           } n         } n         z = m - 1; n       } else { n         for (k = m - 1; k >= 0; k--) { n           if (j == x - 1 && k == y - 1) n             continue; n           else { n             cout << j + 1 <<     << k + 1; n             cout <<   n ; n           } n         } n         z = 0; n       } n     } n   } n } n long long gcdExtended(long long a, long long b) { n   if (b == 0) { n     return a; n   } else n     return gcdExtended(b, a % b); n } n long long mpower(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long powerr(long long x, long long y) { n   long long res = 1; 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 bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   long long p = sqrt(n); n   for (int i = 5; i <= p; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5 + 5; n const long long int M = 1e3; n const long long int mod = 1e7 + 7; n const long long int m1 = 1e9 + 7; n const long long int m2 = 1e9 + 9; n const long long int p1 = 402653189; n const long long int p2 = 1610612741; n const int LN = 32; n long long int powermodm(long long int x, long long int n, long long int M) { n   long long int result = 1; n   while (n > 0) { n     if (n % 2 == 1) result = (result * x) % M; n     x = (x * x) % M; n     n = n / 2; n   } n   return result; n } n long long int power(long long int _a, long long int _b) { n   long long int _r = 1; n   while (_b) { n     if (_b % 2 == 1) _r = (_r * _a); n     _b /= 2; n     _a = (_a * _a); n   } n   return _r; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   return (max(a, b) / gcd(a, b)) * min(a, b); n } n long long int dx[4] = {-1, 1, 0, 0}; n long long int dy[4] = {0, 0, 1, -1}; n long long int pw[LN], fact[N], invfact[N]; n void pre() { n   fact[0] = 1; n   for (int i = 0; i < LN; i++) pw[i] = power(2, i); n   for (int i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod; n   for (int i = 0; i < N; i++) invfact[i] = powermodm(fact[i], mod - 2, mod); n } n long long int n, m, a[N], st[N], en[N], tme[N], curr, lazy[4 * N]; n vector<long long int> adj[N]; n bitset<M> B[4 * N], fin, bset; n void dfs(long long int node, long long int par) { n   st[node] = ++curr; n   tme[curr] = node; n   for (auto it : adj[node]) { n     if (it == par) continue; n     dfs(it, node); n   } n   en[node] = curr; n } n void build(long long int pos, long long int left, long long int right) { n   if (left == right) { n     B[pos].set(a[tme[left]] % m); n     return; n   } n   long long int mid = (left + right) >> 1; n   build(2 * pos + 1, left, mid); n   build(2 * pos + 2, mid + 1, right); n   B[pos] = B[2 * pos + 1] | B[2 * pos + 2]; n } n void apply(bitset<M> &tmp, long long int shift) { n   tmp = (tmp << shift) | (tmp >> (m - shift)); n } n void update(long long int pos, long long int left, long long int right, n             long long int start, long long int end, long long int val) { n   if (lazy[pos] != 0) { n     apply(B[pos], lazy[pos]); n     if (left != right) { n       lazy[2 * pos + 1] = (lazy[2 * pos + 1] + lazy[pos]) % m; n       lazy[2 * pos + 2] = (lazy[2 * pos + 2] + lazy[pos]) % m; n     } n     lazy[pos] = 0; n   } n   if (left > end || right < start) n     return; n   else if (start <= left && right <= end) { n     apply(B[pos], val); n     if (left != right) { n       lazy[2 * pos + 1] = (lazy[2 * pos + 1] + val) % m; n       lazy[2 * pos + 2] = (lazy[2 * pos + 2] + val) % m; n     } n     return; n   } n   long long int mid = (left + right) >> 1; n   update(2 * pos + 1, left, mid, start, end, val); n   update(2 * pos + 2, mid + 1, right, start, end, val); n   B[pos] = B[2 * pos + 1] | B[2 * pos + 2]; n } n void query(long long int pos, long long int left, long long int right, n            long long int start, long long int end) { n   if (lazy[pos] != 0) { n     apply(B[pos], lazy[pos]); n     if (left != right) { n       lazy[2 * pos + 1] = (lazy[2 * pos + 1] + lazy[pos]) % m; n       lazy[2 * pos + 2] = (lazy[2 * pos + 2] + lazy[pos]) % m; n     } n     lazy[pos] = 0; n   } n   if (left > end || right < start) n     return; n   else if (start <= left && right <= end) { n     bset |= B[pos]; n     return; n   } n   long long int mid = (left + right) >> 1; n   query(2 * pos + 1, left, mid, start, end); n   query(2 * pos + 2, mid + 1, right, start, end); n } n bool pri[1005]; n vector<long long int> prm; n void fun() { n   for (long long int i = 2; i < m; i++) pri[i] = true; n   for (long long int i = 2; i < m; i++) { n     if (pri[i]) { n       prm.push_back(i); n       for (long long int j = 2 * i; j < m; j += i) pri[j] = false; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int i, j; n   fin.set(); n   cin >> n >> m; n   fun(); n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i < n; i++) { n     long long int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1, 0); n   build(0, 1, n); n   long long int q; n   cin >> q; n   while (q--) { n     long long int x; n     cin >> x; n     if (x == 1) { n       long long int node, val; n       cin >> node >> val; n       update(0, 1, n, st[node], en[node], val % m); n     } else { n       bset.reset(); n       long long int node; n       cin >> node; n       query(0, 1, n, st[node], en[node]); n       long long int ans = 0; n       for (i = 0; i < prm.size(); i++) { n         if (bset[prm[i]]) ans++; n       } n       printf( %lld n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a < b) { n     int temp; n     temp = a; n     a = b; n     b = temp; n   } n   while (a % b) { n     int r = a % b; n     a = b; n     b = r; n     r = a % b; n   } n   return b; n } n int fun(int a, int n) { n   int sum = 0; n   for (;;) { n     sum = sum + a % n; n     a = a / n; n     if (a == 0) break; n   } n   return sum; n } n int main() { n   int i, j, m, n, a, qum = 0; n   while (scanf( %d , &a) != EOF) { n     for (i = 2; i <= (a - 1); i++) { n       qum += fun(a, i); n     } n     m = gcd(qum, a - 2); n     qum = qum / m; n     a = (a - 2) / m + 2; n     printf( %d/%d n , qum, a - 2); n     qum = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Point { n  public: n   int x; n   int y; n   Point(int x = 0, int y = 0) : x(x), y(y) {} n   friend Point operator-(Point a, Point b) { n     return Point(b.x - a.x, b.y - a.y); n   } n }; n int getBit(int mask, int num) { return ((mask & (1 << num)) ? 1 : 0); } n int innerProduct(Point a, Point b) { return a.x * b.x + a.y * b.y; } n int sqr(int x) { return x * x; } n int squareDist(Point a, Point b) { return sqr(a.x - b.x) + sqr(b.y - a.y); } n bool checkEdges(vector<Point> figure) { n   figure.push_back(figure.front()); n   figure.push_back(*(figure.begin() + 1)); n   for (int i = 0; i + 2 < figure.size(); ++i) n     if (innerProduct(figure[i + 1] - figure[i], n                      figure[i + 2] - figure[i + 1]) != 0) n       return false; n   return true; n } n bool checkEdgesEquality(vector<Point> figure) { n   figure.push_back(figure.front()); n   for (int i = 0; i + 2 < figure.size(); ++i) n     if (squareDist(figure[i], figure[i + 1]) != n         squareDist(figure[i + 1], figure[i + 2])) n       return false; n   return true; n } n bool checkRectangleEdges(vector<Point> figure) { n   figure.push_back(figure.front()); n   if (squareDist(figure[0], figure[1]) == squareDist(figure[2], figure[3]) && n       squareDist(figure[1], figure[2]) == squareDist(figure[3], figure[4])) n     return true; n   else n     return false; n } n bool checkSquare(vector<Point> square) { n   vector<int> sm; n   sm.push_back(0); n   sm.push_back(1); n   sm.push_back(2); n   sm.push_back(3); n   do { n     vector<Point> sq; n     for (int i = 0; i < 4; ++i) sq.push_back(square[sm[i]]); n     if (checkEdges(sq) && checkEdgesEquality(sq)) return true; n   } while (next_permutation(sm.begin(), sm.end())); n   return false; n } n bool checkRectangle(vector<Point> rectangle) { n   vector<int> sm; n   sm.push_back(0); n   sm.push_back(1); n   sm.push_back(2); n   sm.push_back(3); n   do { n     vector<Point> sq; n     for (int i = 0; i < 4; ++i) sq.push_back(rectangle[sm[i]]); n     if (checkEdges(sq) && checkRectangleEdges(sq)) return true; n   } while (next_permutation(sm.begin(), sm.end())); n   return false; n } n bool check(vector<Point> square, vector<Point> rectangle) { n   if (checkSquare(square) && checkRectangle(rectangle)) return true; n   return false; n } n int main() { n   vector<Point> v; n   int a, b; n   for (int i = 0; i < 8; ++i) { n     cin >> a >> b; n     v.push_back(Point(a, b)); n   } n   int i = 0; n   while (i < 1 << 8) { n     vector<Point> square, rectangle; n     vector<int> resSquare, resRectangle; n     for (int j = 0; j < 8; ++j) { n       if (getBit(i, j)) n         square.push_back(v[j]); n       else n         rectangle.push_back(v[j]); n     } n     if (square.size() == 4 && rectangle.size() == 4 && n         check(square, rectangle)) { n       for (int j = 0; j < 8; ++j) { n         if (getBit(i, j)) n           resSquare.push_back(j); n         else n           resRectangle.push_back(j); n       } n       cout <<  YES  << endl; n       for (int j = 0; j < 4; ++j) cout << resSquare[j] + 1 <<    ; n       cout << endl; n       for (int j = 0; j < 4; ++j) cout << resRectangle[j] + 1 <<    ; n       return 0; n     } n     ++i; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   while (cin >> n >> m) { n     vector<int> f(n); n     vector<int> v[100005]; n     vector<int> b(m); n     vector<int> a(m); n     vector<int> used(100005, 0); n     for (int i = 0; i < n; i++) { n       cin >> f[i]; n       v[f[i]].push_back(i + 1); n     } n     for (int i = 0; i < m; i++) cin >> b[i]; n     int sizeA = 0; n     int state = -1; n     for (int i = 0; i < m; i++) { n       if (v[b[i]].size()) { n         a[sizeA++] = v[b[i]][0]; n         used[b[i]]++; n       } else { n         sizeA = 0; n         break; n       } n     } n     if (sizeA < m) { n       cout <<  Impossible  << endl; n       continue; n     } n     for (int i = 0; i < 100005 && state == -1; i++) { n       if (used[i] && v[i].size() > 1) { n         state = 1; n       } n     } n     if (state == 1 || sizeA > m) { n       cout <<  Ambiguity  << endl; n     } else { n       cout <<  Possible  << endl; n       for (int i = 0; i < m; i++) { n         if (i) cout <<    ; n         cout << a[i]; n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   string A, B; n   cin >> A >> B; n   int ans = 0; n   for (int x = 0; x < N - 1 - x; x++) { n     vector<char> v; n     v = {A[x], A[N - 1 - x], B[x], B[N - 1 - x]}; n     sort(v.begin(), v.end()); n     if (v[0] == v[1] && v[2] == v[3]) continue; n     if ((v[0] == v[1] && v[1] == v[2]) || (v[1] == v[2] && v[2] == v[3])) { n       ans++; n       continue; n     } n     bool flag = true; n     for (int y = 1; y < 4; y++) n       if (v[y] == v[y - 1] && A[x] != A[N - 1 - x]) { n         cerr << v[y] <<     << v[y - 1] << endl; n         ans++; n         flag = false; n         break; n       } n     if (flag) ans += 2; n   } n   if (N % 2 && A[N / 2] != B[N / 2]) ans++; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int n, c1, c2; n int a[10]; n long long f[501]; n long long c[501][501]; n long long dp[501][501]; n long long gao(int a, int b) { n   if (a == 0 && b == 0) { n     return 1; n   } n   if (dp[a][b] == -1) { n     long long& cur = dp[a][b] = 0; n     if (a > 0) { n       if (a >= 1) { n         for (int i = 0; i <= b; ++i) { n           cur = (cur + gao(a - 1, b - i) * c[b][i] % MOD * f[i]) % MOD; n         } n       } n       if (a >= 2) { n         for (int i = 0; i <= b; ++i) { n           cur = (cur + n                  gao(a - 2, b - i) * c[b][i] % MOD * (a - 1) % MOD * f[i + 1]) % n                 MOD; n         } n       } n     } else { n       for (int i = 0; i < b; ++i) { n         cur = (cur + gao(a, b - i - 1) * c[b - 1][i] % MOD * f[i]) % MOD; n       } n     } n   } n   return dp[a][b]; n } n int main() { n   for (int i = f[0] = 1; i <= 500; ++i) { n     f[i] = f[i - 1] * i % MOD; n   } n   for (int i = 0; i <= 500; ++i) { n     c[i][0] = c[i][i] = 1; n     for (int j = 1; j < i; ++j) { n       c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD; n     } n   } n   c1 = c2 = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     ++(a[i] == 1 ? c1 : c2); n   } n   memset(dp, -1, sizeof(dp)); n   int res = gao(c1, c2) % MOD; n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int N = 10e6 + 6; n int p[N]; n int nx[N]; n int n; n priority_queue<int> r; n bool vis[N]; n int main(void) { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> p[i]; n     nx[p[i] - 1] = i; n   } n   r.push(1); n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       vis[i] = true; n       if (nx[p[i]] > i and nx[p[i]] > 0 and nx[p[i]] <= n) { n         int j = nx[p[i]]; n         int ct = 2; n         while (nx[p[j]] > j and nx[p[j]] > 0 and nx[p[j]] <= n) { n           vis[j] = true; n           j = nx[p[j]]; n           ct++; n         } n         r.push(ct); n       } n     } n   } n   memset(vis, false, sizeof(vis)); n   cout << n - r.top() << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int S = 103; n int n, m, a[S], b[S]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     if (2 * n + 2 * (i - 1) + 1 <= m) printf( %d  , 2 * n + 2 * (i - 1) + 1); n     if (2 * i - 1 <= m) printf( %d  , 2 * i - 1); n     if (2 * (n + i) <= m) printf( %d  , 2 * (n + i)); n     if (2 * i <= m) printf( %d  , 2 * i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long Getint() { n   char ch = getchar(); n   long long x = 0, fh = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) fh = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     (x *= 10) += ch ^ 48; n     ch = getchar(); n   } n   return x * fh; n } n const long long mod = 998244353; n const int N = 400005; n inline long long Inc(long long x, long long y) { n   return (x += y) >= mod ? x - mod : x; n } n inline long long Dec(long long x, long long y) { n   return (x -= y) < 0 ? x + mod : x; n } n inline long long Ksm(long long x, long long y) { n   long long tmp = 1; n   while (y) { n     if (y & 1) tmp = tmp * x % mod; n     y >>= 1; n     if (y) x = x * x % mod; n   } n   return tmp; n } n long long K, n, fc[N], fiv[N], inv[N]; n vector<int> G[N]; n int lst, rev[N]; n long long pwi[2][25], wn[N]; n inline void initpw() { n   for (int i = 1, k = 0; i < N; i <<= 1, k++) { n     pwi[0][k] = Ksm(3, (mod - 1) / (i << 1)); n     pwi[1][k] = Ksm(3, -(mod - 1) / (i << 1) + mod - 1); n   } n } n inline int Make(int len) { return 1 << int(ceil(log2(len))); } n inline int Trans(int len) { n   int l = ceil(log2(len)); n   len = 1 << l; n   for (int i = 0; i <= len - 1; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1); n   return lst = len; n } n inline void NTT(vector<long long> &F, int fir, int len, int f) { n   if (lst != len) Trans(len); n   if (f == 1) F.resize(len); n   for (int i = 0; i <= len - 1; i++) n     if (rev[i] < i) swap(F[rev[i]], F[i]); n   for (int i = 1, k = 0; i < len; i <<= 1, k++) { n     long long wi = f == 1 ? pwi[0][k] : pwi[1][k]; n     wn[0] = 1; n     for (int j = 1; j <= i - 1; j++) wn[j] = wn[j - 1] * wi % mod; n     for (int j = 0; j < len; j += i << 1) { n       for (int k = 0; k < i; k++) { n         long long x = F[j + k], y = F[i + j + k] * wn[k] % mod; n         F[j + k] = Inc(x, y); n         F[i + j + k] = Dec(x, y); n       } n     } n   } n   if (f == 1) return; n   long long iv = inv[len]; n   for (int i = 0; i <= fir - 1; i++) F[i] = F[i] * iv % mod; n   F.resize(fir); n } n inline vector<long long> operator*(vector<long long> A, vector<long long> B) { n   if (A.size() == 0) return A; n   if (B.size() == 0) return B; n   int len = A.size() + B.size() - 1, l = Make(len); n   NTT(A, A.size(), l, 1); n   NTT(B, B.size(), l, 1); n   for (int i = 0; i <= l - 1; i++) A[i] = A[i] * B[i] % mod; n   NTT(A, len, l, -1); n   return A; n } n vector<long long> F[N], Lt; n map<int, long long> mp[N]; n inline long long Div(int u, int sz) { n   if (mp[u].count(sz)) return mp[u][sz]; n   vector<long long> A = F[u]; n   vector<long long> C(A.size() - 1); n   long long iv = inv[sz]; n   for (int i = int(A.size()) - 1; i >= 1; i--) { n     C[i - 1] = A[i] * iv % mod; n     A[i - 1] = Dec(A[i - 1], C[i - 1]); n   } n   long long tmp = 0; n   for (int i = 0; i <= int(C.size()) - 1; i++) { n     if (i > K) break; n     (tmp += C[i] * fiv[K - i]) %= mod; n   } n   return mp[u][sz] = tmp; n } n inline vector<long long> CDQ1(int l = 0, int r = int(Lt.size()) - 1) { n   if (r < l) { n     vector<long long> t(1); n     t[0] = 1; n     return t; n   } else if (l == r) { n     vector<long long> t(2); n     t[1] = Lt[l]; n     t[0] = 1; n     return t; n   } n   int mid = l + r >> 1; n   return CDQ1(l, mid) * CDQ1(mid + 1, r); n } n int sz[N]; n long long dp[N]; n void Dfs1(int u, int fa) { n   sz[u] = 1; n   dp[u] = 0; n   for (int v : G[u]) { n     if (v == fa) continue; n     Dfs1(v, u); n     sz[u] += sz[v]; n     dp[u] = Inc(dp[u], dp[v]); n   } n   Lt.clear(); n   for (int v : G[u]) { n     if (v == fa) continue; n     Lt.push_back(sz[v]); n   } n   if (fa) Lt.push_back(n - sz[u]); n   F[u] = CDQ1(); n   if (fa) { n     dp[u] = Inc(dp[u], Div(u, n - sz[u])); n   } else { n     for (int i = 0; i <= int(F[u].size()) - 1; i++) { n       if (i > K) break; n       (dp[u] += F[u][i] * fiv[K - i]) %= mod; n     } n   } n } n long long Ans = 0; n void Dfs2(int u, int fa) { n   long long su = 0; n   for (int v : G[u]) { n     if (v == fa) continue; n     Dfs2(v, u); n     (Ans += su * dp[v]) %= mod; n     su = Inc(su, dp[v]); n   } n   for (int v : G[u]) { n     if (v == fa) continue; n     long long val = Div(u, sz[v]); n     (Ans += val * dp[v]) %= mod; n   } n } n int main() { n   int x, y, z; n   fc[0] = fc[1] = inv[0] = inv[1] = fiv[0] = fiv[1] = 1; n   for (int i = 2; i <= N - 1; i++) { n     fc[i] = fc[i - 1] * i % mod; n     inv[i] = (mod - mod / i) * inv[mod % i] % mod; n     fiv[i] = fiv[i - 1] * inv[i] % mod; n   } n   initpw(); n   n = Getint(); n   K = Getint(); n   for (int i = 2; i <= n; i++) { n     x = Getint(); n     y = Getint(); n     G[x].push_back(y); n     G[y].push_back(x); n   } n   if (K == 1) { n     cout << n * (n - 1) / 2 % mod <<   n ; n     return 0; n   } n   Dfs1(1, 0); n   Dfs2(1, 0); n   Ans = Ans % mod * Ksm(fc[K], 2) % mod; n   cout << (Ans % mod + mod) % mod <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n #pragma warning(disable : 4786) n using namespace std; n int MIN(int a, int b) { return a < b ? a : b; } n int MAX(int a, int b) { return a > b ? a : b; } n int GCD(int a, int b) { n   while (b) b ^= a ^= b ^= a %= b; n   return a; n } n int LCM(int a, int b) { return a * (b / GCD(a, b)); } n void SWAP(int &a, int &b) { n   a = a ^ b; n   b = a ^ b; n   a = a ^ b; n } n const double PI = acos(-1); n const double ESP = 1e-11; n int arr[100100], brr[100010], crr[100010]; n int main() { n   int ind, i, j, N, T, result, cnt, counter, temp, temp1, idx, index, a, b, c, n       d, e, f, g, h, n, m, k; n   memset(crr, -1, sizeof(crr)); n   while (scanf( %d , &n) != EOF) { n     for (i = 0; i < n; i++) { n       counter = 0; n       scanf( %d%d , &a, &e); n       b = a; n       c = sqrt(b); n       memset(brr, NULL, sizeof(brr)); n       cnt = 0; n       { n         for (j = 1; j <= c; j++) { n           f = j; n           g = b / j; n           if (b % f == 0) { n             if (crr[f] == -1 || crr[f] < i - e) { n               counter += 1; n             } n             if (f != g && (crr[g] == -1 || crr[g] < i - e)) { n               counter += 1; n             } n             crr[f] = i; n             if (b % g == 0) { n               crr[g] = i; n             } n           } n         } n         f = b; n         if (crr[f] == -1 || crr[f] < i - e) { n           crr[f] = i; n           counter += 1; n         } n         printf( %d n , counter); n       } n     } n     memset(arr, NULL, sizeof(arr)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 555; n int n, m; n int a[maxn], b[maxn]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= m; i++) scanf( %d , b + i); n   int i1 = 1, i2 = 1; n   int res = 0; n   while (i1 <= n && i2 <= m) { n     if (a[i1] <= b[i2]) n       i1++, i2++, res++; n     else n       i1++; n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int q, r, g, b, w; n   cin >> q; n   while (q--) { n     vector<int> a(4); n     int odd = 0, even = 0; n     for (int i = 0; i < 4; i++) { n       cin >> a[i]; n       if (a[i] % 2) n         odd += 1; n       else n         even += 1; n     } n     if (odd <= 1) n       cout <<  YES n ; n     else { n       if (min(a[0], min(a[1], a[2])) >= 1) { n         odd = 0, even = 0; n         for (int i = 0; i < 3; i++) { n           a[i] -= 1; n           if (a[i] % 2) n             odd += 1; n           else n             even += 1; n         } n         a[3] += 1; n         if (a[3] % 2) n           odd += 1; n         else n           even += 1; n         if (odd <= 1) n           cout <<  YES n ; n         else n           cout <<  NO n ; n       } else { n         cout <<  NO n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, etime, cnt[2], f[2]; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d%d%d , &n, &etime, f, f + 1); n     vector<int> v = {etime}; n     vector<pair<int, bool> > p(n); n     cnt[0] = cnt[1] = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &p[i].second); n       cnt[p[i].second]++; n     } n     for (int i = 0; i < n; i++) { n       scanf( %d , &p[i].first); n       v.push_back(p[i].first - 1); n     } n     sort(p.begin(), p.end()); n     sort(v.begin(), v.end()); n     v.resize(unique(v.begin(), v.end()) - v.begin()); n     int mx = 0, must_cnt = 0, i = 0; n     long long must = 0; n     for (int x : v) { n       while (i < p.size() && p[i].first <= x) { n         cnt[p[i].second]--; n         must_cnt++; n         must += f[p[i].second]; n         i++; n       } n       if (x >= must) { n         int max_points = must_cnt, rem = x - must; n         for (int j = 0; j < 2; j++) { n           int take = min(cnt[j], rem / f[j]); n           rem -= take * f[j]; n           max_points += take; n         } n         mx = max(mx, max_points); n       } n     } n     printf( %d n , mx); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n = 0; n   long long k = 0; n   long long wynik = 0; n   long long wynik2 = 0; n   long long wynik3 = 0; n   cin >> n >> k; n   if (k == 1) { n     cout <<  1 ; n     return 0; n   } n   if (k == 2) { n     wynik = n * (n - 1) / 2 + 1; n     cout << wynik; n     return 0; n   } n   if (k == 3) { n     wynik = n * (n - 1) / 2; n     wynik2 = n * (n - 1) * (n - 2) / 3 + 1; n     cout << wynik2 + wynik; n     return 0; n   } n   if (k == 4) { n     wynik = n * (n - 1) / 2; n     wynik2 = n * (n - 1) * (n - 2) / 3 + 1; n     wynik3 = (n * (n - 1) * (n - 2) * (n - 3) / 24) * 9; n     cout << wynik + wynik2 + wynik3; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD_EXPO(long long b, long long p, long long m) { n   if (p == 0) return 1; n   long long ret = MOD_EXPO(b, p / 2, m) % m; n   ret = (ret * ret) % m; n   return ((p & 1) ? (ret * b) % m : ret % m); n } n long long POWER(long long N, long long K) { n   long long i, ans = 1; n   for (i = 1; i <= K; i++) ans *= N; n   return ans; n } n int SET(int N, int pos) { return (N | (1 << pos)); } n int RESET(int N, int pos) { return (N & !(1 << pos)); } n bool CHECK(int N, int pos) { return (N & (1 << pos)); } n int dx4[] = {1, -1, 0, 0}; n int dy4[] = {0, 0, 1, -1}; n int dx6[] = {0, 0, 1, -1, 0, 0}; n int dy6[] = {1, -1, 0, 0, 0, 0}; n int dz6[] = {0, 0, 0, 0, 1, -1}; n int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1}; n int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1}; n int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2}; n int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1}; n int tc = 1; n const double eps = 1e-9; n const double pi = acos(-1.0); n const long long int mx = 1e3; n const long long int mod = 1e9 + 7; n int dp[5][mx + 5]; n int n, arr[mx + 5]; n string str; n int rec(int i, int prev) { n   if (i > n) return 0; n   int &ret = dp[prev][i]; n   if (ret != -1) return ret; n   ret = INT_MAX; n   if (prev != 0) ret = min(ret, rec(i + 1, 0) + (arr[i] != 0)); n   if (prev != 1) ret = min(ret, rec(i + 1, 1) + (arr[i] != 1)); n   return ret; n } n int main() { n   int i; n   while (cin >> n >> str) { n     for (i = 1; i <= n; i++) arr[i] = (str[i - 1] -  0 ); n     memset(dp, -1, sizeof(dp)); n     cout << rec(1, 2) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, k = 0; n   cin >> x; n   while (x) { n     k += x % 2; n     x /= 2; n   } n   cout << k; n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 1005; n char a[MaxN]; n int b[MaxN]; n bool prime(int x) { n   for (int i = 2; i < x / 2; i++) { n     if (x % 2 == 0) { n       return false; n     } n   } n   return true; n } n int main() { n   string s; n   int i, n, Max, j; n   char v; n   Max = 0; n   for (i = 0; i < MaxN; i++) { n     a[i] =    ; n     b[i] = 0; n   } n   cin >> s; n   for (i = 0; i < s.length(); i++) { n     b[s[i]]++; n     if (b[s[i]] > Max) { n       Max = b[s[i]]; n       v = s[i]; n     } n   } n   for (i = 2; i <= s.length(); i++) { n     if (prime(i)) { n       if (i == 2) { n         int ind = 1; n         while (ind * i <= s.length()) { n           if (a[ind * i] ==    ) { n             a[ind * i] = (char)v; n             b[v]--; n             if (b[v] < 0) { n               cout <<  NO  << endl; n               return 0; n             } n           } n           ind++; n         } n       } else { n         if (i * 2 <= s.length()) { n           int ind = 1; n           while (ind * i <= s.length()) { n             if (a[ind * i] ==    ) { n               a[ind * i] = (char)v; n               b[v]--; n               if (b[v] < 0) { n                 cout <<  NO  << endl; n                 return 0; n               } n             } n             ind++; n           } n         } n       } n     } n   } n   cout <<  YES  << endl; n   for (i = 1; i <= s.length(); i++) { n     if (a[i] ==    ) { n       for (j = 0; j < MaxN; j++) { n         if (b[j]) { n           a[i] = (char)j; n           b[j]--; n           break; n         } n       } n     } n     cout << a[i]; n   } n   cin.get(); n   cin.get(); n } n


#include <bits/stdc++.h> n using namespace std; n int t, i; n int c[32650]; n void ciu(); n unsigned long long int p, q; n unsigned long long int minim = 0xffffffffffffffff; n vector<unsigned long long int> v; n int main() { n   cin >> t; n   ciu(); n   while (t--) { n     minim = 0xffffffffffffffff; n     cin >> p >> q; n     if (p % q != 0) n       cout << p <<   n ; n     else { n       for (i = 0; i < v.size() && v[i] * v[i] <= q; i++) n         if (q % v[i] == 0) { n           unsigned long long int exp = 0, rez = 1; n           while (q % v[i] == 0) { n             q /= v[i]; n             exp++; n             rez *= v[i]; n           } n           if (rez != 1) { n             unsigned long long int expx = 0, rezx = 1; n             unsigned long long int cp = p; n             cp /= rez; n             while (cp % v[i] == 0) { n               cp /= v[i]; n               expx++; n               rezx *= v[i]; n             } n             rezx *= v[i]; n             if (rezx < minim) minim = rezx; n           } n         } n       if (q != 1) { n         unsigned long long int expq = 0, rezq = 1; n         unsigned long long int cp = p; n         cp /= q; n         while (cp % q == 0) { n           cp /= q; n           expq++; n           rezq *= q; n         } n         rezq *= q; n         if (rezq < minim) minim = rezq; n       } n       cout << p / minim <<   n ; n     } n   } n   return 0; n } n void ciu() { n   int i, j; n   for (i = 2; i * i < 32650; i++) n     if (!c[i]) n       for (j = i * i; j < 32650; j += i) c[j] = 1; n   for (i = 2; i < 32650; i++) n     if (!c[i]) v.push_back(i); n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return (a.second < b.second); n } n inline long long mx(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long solve(long long x, long long n) { n   long long r; n   if (x <= n) n     r = (x - 1) / 2; n   else n     r = (n - (x - n) + 1) / 2; n   if (r > 0) n     return r; n   else n     return 0; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   cin >> n; n   long long i; n   for (i = 9; i <= n + n - 1; i = i * 10 + 9) n     ; n   long long k = i / 10; n   long long ans = 0; n   for (long long i = 0; i <= 9; i++) { n     if (i * (k + 1) + k <= n + n - 1) n       ans += solve(i * (k + 1) + k, n); n     else n       break; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   long long a = n, b = m; n   while (1) { n     if (a <= 0 || b <= 0) break; n     if (a >= 2 * b) { n       a %= 2 * b; n       continue; n     } n     if (b >= 2 * a) { n       b %= 2 * a; n       continue; n     } n     break; n   } n   cout << a <<     << b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r, k; n   cin >> l >> r >> k; n   if (k == 1 || l == r || (r - l == 1 && l % 2 && (l ^ r) >= l)) { n     cout << l <<   n1 n  << l << endl; n     return 0; n   } n   long long int num = 1, ind; n   for (int i = 0;; i++) { n     if (num > l) { n       ind = i; n       break; n     } n     num *= 2; n   } n   if (num + num / 2 <= r && k >= 3) { n     cout <<  0 n3 n  n          << num - 1 <<     << num + num / 2 <<     << num + num / 2 - 1 << endl; n     return 0; n   } n   if (r - l == 1) { n     cout << (l ^ (l + 1)) <<   n2 n  << l <<     << l + 1 << endl; n     return 0; n   } n   if (l % 2) l++; n   if (l + 3 <= r && k >= 4) { n     cout <<  0 n4 n  n          << l <<     << l + 1 <<     << l + 2 <<     << l + 3 << endl; n   } else { n     cout <<  1 n2 n  << l <<     << l + 1 << endl; n   } n   return 0; n } n