#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005, mod = 998244353; n inline int gi() { n   char c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   int sum = 0; n   while ( 0  <= c && c <=  9 ) sum = sum * 10 + c - 48, c = getchar(); n   return sum; n } n inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } n inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; } n inline int fpow(int x, int k) { n   int res = 1; n   while (k) { n     if (k & 1) res = (long long)res * x % mod; n     k >>= 1; n     x = (long long)x * x % mod; n   } n   return res; n } n int n, k, ans, s1, s2, fac[maxn], ifac[maxn]; n struct edge { n   int to, next; n } e[maxn * 2]; n int h[maxn], siz[maxn], tot; n int f[maxn], fs[maxn]; n vector<pair<int, int> > vec; n vector<int> _F[maxn], _G[maxn]; n int N, L, R[maxn << 2], w[maxn << 2], F[maxn << 2], Fl[maxn << 2], n     Fr[maxn << 2], G[maxn << 2], Gl[maxn << 2], Gr[maxn << 2]; n inline void adde(int u, int v) { n   e[++tot] = (edge){v, h[u]}; n   h[u] = tot; n   e[++tot] = (edge){u, h[v]}; n   h[v] = tot; n } n void init(int n) { n   for (N = 1, L = -1; N <= n; N <<= 1) ++L; n   for (int i = 0; i < N; ++i) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L); n   w[N >> 1] = 1; n   int wn = fpow(3, (mod - 1) / N); n   for (int i = (N >> 1) + 1; i < N; ++i) w[i] = (long long)w[i - 1] * wn % mod; n   for (int i = (N >> 1) - 1; i; --i) w[i] = w[i << 1]; n } n void dft(int *a) { n   for (int i = 0; i < N; ++i) n     if (i < R[i]) swap(a[i], a[R[i]]); n   for (int d = 1; d < N; d <<= 1) n     for (int i = 0; i < N; i += d << 1) n       for (int j = 0; j < d; ++j) { n         int t = (long long)w[d + j] * a[i + d + j] % mod; n         a[i + d + j] = sub(a[i + j], t); n         a[i + j] = add(a[i + j], t); n       } n } n void idft(int *a) { n   dft(a); n   reverse(a + 1, a + N); n   int inv = fpow(N, mod - 2); n   for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * inv % mod; n } n void solve(int l, int r, int u) { n   if (l == r) { n     vector<int> &F = _F[l], &G = _G[l]; n     F.resize(2); n     G.resize(2); n     F[0] = 1; n     F[1] = vec[l].second; n     G[0] = add(f[vec[l].first], fs[vec[l].first]); n     G[1] = n         (long long)add(f[vec[l].first], fs[vec[l].first]) * (n - siz[u]) % mod; n     return; n   } n   int mid = (l + r) >> 1, l1 = mid - l + 1, l2 = r - mid; n   solve(l, mid, u); n   solve(mid + 1, r, u); n   init(r - l + 1); n   for (int i = 0; i <= l1; ++i) Fl[i] = _F[l][i], Gl[i] = _G[l][i]; n   memset(Fl + l1 + 1, 0, sizeof(int) * (N - l1)); n   memset(Gl + l1 + 1, 0, sizeof(int) * (N - l1)); n   for (int i = 0; i <= l2; ++i) Fr[i] = _F[mid + 1][i], Gr[i] = _G[mid + 1][i]; n   memset(Fr + l2 + 1, 0, sizeof(int) * (N - l2)); n   memset(Gr + l2 + 1, 0, sizeof(int) * (N - l2)); n   dft(Fl); n   dft(Gl); n   dft(Fr); n   dft(Gr); n   for (int i = 0; i < N; ++i) F[i] = (long long)Fl[i] * Fr[i] % mod; n   for (int i = 0; i < N; ++i) n     G[i] = ((long long)Fl[i] * Gr[i] + (long long)Fr[i] * Gl[i]) % mod; n   idft(F); n   idft(G); n   _F[l].resize(r - l + 2); n   _G[l].resize(r - l + 2); n   for (int i = 0; i <= r - l + 1; ++i) _F[l][i] = F[i], _G[l][i] = G[i]; n } n void dfs(int u, int fa) { n   siz[u] = 1; n   for (int i = h[u], v; v = e[i].to, i; i = e[i].next) n     if (v != fa) dfs(v, u); n   vec.clear(); n   for (int i = h[u], v; v = e[i].to, i; i = e[i].next) n     if (v != fa) { n       fs[u] = add(fs[u], add(f[v], fs[v])); n       siz[u] += siz[v]; n       vec.emplace_back(v, siz[v]); n     } n   if (vec.empty()) n     return f[u] = 1, s1 = add(s1, f[u]), s2 = add(s2, f[u]), void(); n   solve(0, vec.size() - 1, u); n   vector<int> &F = _F[0], &G = _G[0]; n   int s = F.size() - 1; n   for (int i = 0; i <= s; ++i) n     f[u] = (f[u] + (long long)fac[k] * ifac[k - i] % mod * F[i]) % mod; n   s1 = add(s1, f[u]); n   s2 = (s2 + (long long)f[u] * f[u]) % mod; n   for (int i = 0; i <= s; ++i) n     ans = (ans + (long long)fac[k] * ifac[k - i] % mod * G[i]) % mod; n   ans = (ans + (long long)(mod - f[u]) * fs[u]) % mod; n } n int main() { n   n = gi(); n   k = gi(); n   if (k == 1) return printf( %lld n , (long long)n * (n - 1) / 2 % mod), 0; n   fac[0] = 1; n   for (int i = 1; i <= k; ++i) fac[i] = (long long)fac[i - 1] * i % mod; n   ifac[k] = fpow(fac[k], mod - 2); n   for (int i = k - 1; ~i; --i) ifac[i] = (long long)ifac[i + 1] * (i + 1) % mod; n   for (int i = 1; i < n; ++i) adde(gi(), gi()); n   dfs(1, 0); n   printf( %d n , add(ans, (long long)sub((long long)s1 * s1 % mod, s2) * n                               (mod + 1) / 2 % mod)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m[100][100]; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(0); n   long n, suma = 0; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       m[i][j] = 1; n     } n   } n   for (int i = 1; i < n; ++i) { n     for (int j = 1; j < n; ++j) { n       int x = m[i - 1][j], y = m[i][j - 1]; n       m[i][j] = x + y; n     } n   } n   cout << m[n - 1][n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   scanf( %i %i %i %i , &a, &b, &c, &d); n   int sum1 = max(3 * a / 10, a - a / 250 * c); n   int sum2 = max(3 * b / 10, b - b / 250 * d); n   if (sum1 > sum2) { n     printf( Misha n ); n   } else if (sum1 == sum2) { n     printf( Tie n ); n   } else { n     printf( Vasya n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n const long long INF = 1e18 + 10; n struct node { n   int next, v; n } edge[maxn * 2 + 10]; n int cnt, head[maxn], vis[maxn], pa[maxn]; n long long sum[maxn], cost[maxn], a[maxn], ss[maxn]; n queue<int> q; n int find(int x) { n   if (x == pa[x]) return x; n   return pa[x] = find(pa[x]); n } n void add2(int x, int y) { n   x = find(x); n   y = find(y); n   pa[x] = y; n   ss[y] += ss[x]; n } n void dfs(int u, int fa) { n   int i, v; n   sum[u] = a[u]; n   for (i = head[u]; i != -1; i = edge[i].next) { n     v = edge[i].v; n     if (v == fa) continue; n     dfs(v, u); n     if (sum[v] > 0) sum[u] += sum[v]; n   } n } n void dfs2(int u, int fa) { n   int i, v; n   if (u == 1) { n     cost[u] = sum[u]; n     for (i = head[1]; i != -1; i = edge[i].next) { n       v = edge[i].v; n       dfs2(v, u); n     } n     return; n   } n   if (sum[u] <= 0) { n     cost[u] = max(sum[u], sum[u] + cost[fa]); n   } else { n     long long tmp = cost[fa] - sum[u]; n     if (tmp > 0) { n       cost[u] = sum[u] + tmp; n       add2(u, fa); n     } else { n       cost[u] = sum[u]; n     } n   } n   for (i = head[u]; i != -1; i = edge[i].next) { n     v = edge[i].v; n     if (fa == v) continue; n     dfs2(v, u); n   } n } n void add(int x, int y) { n   edge[cnt].next = head[x]; n   edge[cnt].v = y; n   head[x] = cnt++; n } n int main() { n   int i, n; n   long long ans, ret, s, u, v; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %I64d , &a[i]); n   } n   cnt = 0; n   memset(head, -1, sizeof(head)); n   for (i = 1; i <= n - 1; i++) { n     scanf( %d%d , &u, &v); n     add(u, v); n     add(v, u); n   } n   for (i = 1; i <= n; i++) { n     pa[i] = i; n     ss[i] = a[i]; n   } n   dfs(1, -1); n   dfs2(1, -1); n   ans = -INF; n   for (i = 1; i <= n; i++) ans = max(ans, cost[i]); n   if (ans <= 0) { n     ret = 0; n     s = 0; n     for (i = 1; i <= n; i++) { n       if (ans == cost[i]) { n         ret++; n         s += ans; n       } n     } n     printf( %I64d %I64d n , s, ret); n   } else { n     ret = 0; n     s = 0; n     memset(vis, 0, sizeof(vis)); n     for (i = 1; i <= n; i++) { n       if (ans == cost[i]) { n         int tt = find(i); n         if (!vis[tt] && ss[tt] == ans) { n           ret++; n           s += ans; n           vis[tt] = 1; n         } n       } n     } n     printf( %I64d %I64d n , s, ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 10; n const char character[] =  ./  ; n int n, a[N], tag[N], type[N][N]; n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   int o = 0, r = 0; n   for (register int i = 1; i <= n; ++i) { n     if (tag[i] || a[i] == i) { n       continue; n     } n     vector<int> cycle; n     for (int j = i; !tag[j]; j = a[j]) { n       cycle.push_back(j), tag[j] = 1; n     } n     cycle.push_back(i); n     if (!o) { n       o = i; n       for (register int j = 1; j + 1 < cycle.size(); ++j) { n         int a = cycle[j], b = cycle[j + 1]; n         ++r; n         type[r][a] = type[r][b] = 2 - (a < b); n       } n     } else { n       ++r; n       type[r][o] = type[r][cycle[1]] = 1; n       for (register int j = 1; j + 1 < cycle.size(); ++j) { n         int a = cycle[j], b = cycle[j + 1]; n         ++r; n         type[r][a] = type[r][b] = 2 - (a < b); n       } n       type[r][o] = 2; n     } n   } n   printf( %d n , o ? n - 1 : n); n   for (register int i = 1; i <= n; ++i) { n     for (register int j = 1; j <= n; ++j) { n       printf( %c , character[type[i][j]]); n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, r; n int x[105], y[105]; n vector<pair<int, int> > pos, neg; n bool cmp(pair<int, int> p1, pair<int, int> p2) { n   return p1.first + p1.second > p2.first + p2.second; n } n int main() { n   cin >> n >> r; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x[i], &y[i]); n     if (y[i] >= 0) n       pos.push_back(pair<int, int>(x[i], y[i])); n     else n       neg.push_back(pair<int, int>(x[i], y[i])); n   } n   sort(pos.begin(), pos.end()); n   sort(neg.begin(), neg.end(), cmp); n   for (int i = 0; i < pos.size(); i++) { n     if (pos[i].first <= r) n       r += pos[i].second; n     else { n       printf( NO n ); n       return 0; n     } n   } n   for (int i = 0; i < neg.size(); i++) { n     if (neg[i].first <= r) n       r += neg[i].second; n     else { n       printf( NO n ); n       return 0; n     } n     if (r < 0) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long p; n map<long long, int> m[123]; n int main() { n   int characters_value[26]; n   long long i; n   for (i = 0; i < 26; i++) cin >> characters_value[i]; n   string s; n   cin >> s; n   long long ans = 0; n   for (i = 0; i < s.size(); i++) { n     ans += m[s[i]][p]; n     p += characters_value[s[i] -  a ]; n     m[s[i]][p]++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 811287553; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int n, m, s, t, a, b, d; n vector<long long> dist, dist1; n vector<pair<int, int> > grh[2][100000]; n vector<pair<pair<int, int>, int> > queries; n set<pair<int, int> > absEdges; n map<pair<int, int>, int> minEdges; n long long reachableCnt[2][100000]; n const long long INF = 1000000000000; n void dijkstra(int src, vector<long long>& d, int mode) { n   d.resize(n, INF); n   d[src] = 0; n   priority_queue<pair<long long, int> > pq; n   pq.push(make_pair(0, src)); n   while (!pq.empty()) { n     long long topD = -pq.top().first; n     int topIdx = pq.top().second; n     pq.pop(); n     if (d[topIdx] < topD) continue; n     int sz = grh[mode][topIdx].size(); n     for (int i = 0; i < (int)sz; i++) { n       int nIdx = grh[mode][topIdx][i].first; n       int nD = grh[mode][topIdx][i].second; n       long long nD1 = topD + nD; n       if (d[nIdx] > nD1) { n         d[nIdx] = nD1; n         pq.push(make_pair(-nD1, nIdx)); n       } n     } n   } n } n int calReachable(int idx, vector<long long>& d, bool rev) { n   if (rev && idx == s) { n     reachableCnt[!rev][idx] = 1; n     return 1; n   } n   if (!rev && idx == t) { n     reachableCnt[!rev][idx] = 1; n     return 1; n   } n   long long& ret = reachableCnt[!rev][idx]; n   if (ret != -1) return ret; n   int ret1 = 0; n   int sz = grh[rev][idx].size(); n   for (int i = 0; i < (int)sz; i++) { n     int nIdx = grh[rev][idx][i].first; n     int nD = grh[rev][idx][i].second; n     if (d[nIdx] == d[idx] + nD) { n       ret1 += calReachable(nIdx, d, rev); n       ret1 %= mod; n     } n   } n   return ret = (ret1 % mod); n } n int main() { n   cin >> n >> m >> s >> t; n   s--, t--; n   for (int i = 0; i < (int)m; i++) { n     cin >> a >> b >> d; n     a--, b--; n     grh[0][a].push_back(make_pair(b, d)); n     grh[1][b].push_back(make_pair(a, d)); n     queries.push_back(make_pair(make_pair(a, b), d)); n     if (minEdges.count(make_pair(a, b))) n       minEdges[make_pair(a, b)] = min(minEdges[make_pair(a, b)], d); n     else n       minEdges[make_pair(a, b)] = d; n   } n   memset(reachableCnt, -1, sizeof(reachableCnt)); n   dijkstra(s, dist, 0); n   dijkstra(t, dist1, 1); n   calReachable(t, dist1, 1); n   calReachable(s, dist, 0); n   for (int i = 0; i < (int)m; i++) { n     int x = queries[i].first.first, y = queries[i].first.second, n         d = queries[i].second; n     if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) == n          reachableCnt[0][t]) && n         minEdges[make_pair(x, y)] < d) { n       if (minEdges[make_pair(x, y)] == 1) n         cout <<  NO  << endl; n       else n         cout <<  CAN   << d - minEdges[make_pair(x, y)] + 1 << endl; n     } else { n       long long d1 = dist[x] + dist1[y]; n       if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) == n            reachableCnt[0][t])) { n         if (d1 + d == dist[t]) n           cout <<  YES  << endl; n         else { n           if (d > 1 && d1 + 1 < dist[t]) n             cout <<  CAN   << d + d1 - (dist[t] - 1) << endl; n           else n             cout <<  NO  << endl; n         } n       } else { n         if (d > 1 && d1 + 1 < dist[t]) n           cout <<  CAN   << d + d1 - (dist[t] - 1) << endl; n         else n           cout <<  NO  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { n   return {l.first + r.first, l.second + r.second}; n } n typedef void (*callback_function)(void); n const long long ZERO = 0LL; n const long long INF64 = 1e18; n const long long INF32 = 1e9; n const long long MOD = 1e9 + 7; n const long double PI = acos(-1.0L); n const long double EPS = static_cast<long double>(1e-9); n long long inv(long long a, long long b) { n   if (a != 1) { n     return b - (inv(b % a, a) * b) / a; n   } n   return 1; n } n inline long long Pow(long long a, long long k) { n   long long s = 1; n   for (; k; k >>= 1) { n     k& 1 ? s = 1LL * s * a % MOD : 0; n     a = 1LL * a * a % MOD; n   } n   return s; n } n const long long N = 1e6 + 7; n void input() {} n void output() {} n void preprocess() {} n void debug() { n   if (true) { n   } n } n void solve() { n   preprocess(); n   long long n; n   cin >> n; n   pair<long long, long long> a[n]; n   for (long long i = (0); i < (n); i++) { n     long long m; n     cin >> m; n     long long b[m]; n     for (long long i = (0); i < (m); i++) { n       cin >> b[i]; n     } n     a[i] = pair<long long, long long>(*max_element(b, b + m), m); n   } n   long long mx = (*max_element(a, a + n)).first; n   long long res = 0; n   for (long long i = (0); i < (n); i++) { n     res += (mx - a[i].first) * a[i].second; n   } n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   { n     input(); n     solve(); n     output(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } n int main() { n   int n, k; n   cin >> n >> k; n   pair<int, int> power[n]; n   for (int i = 0; i < n; ++i) { n     pair<int, int> a; n     int p; n     cin >> p; n     a.first = p; n     if (p % 10 == 0) n       a.second = 0; n     else n       a.second = 10 - p % 10; n     power[i] = a; n   } n   sort(power, power + n, compare); n   for (int i = 0; i < n; ++i) { n     if (power[i].first != 100) { n       k = k - power[i].second; n       if (k < 0) break; n       power[i].first = power[i].first + power[i].second; n     } n   } n   if (k > 0) { n     for (int i = 0; i < n; ++i) { n       while (power[i].first < 100 && k >= 10) { n         k = k - 10; n         power[i].first += 10; n       } n       if (k < 10) break; n     } n   } n   int res = 0; n   for (int i = 0; i < n; ++i) { n     res += power[i].first / 10; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[200005]; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   int flag = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] >= 2) a[i] %= 2; n     if (a[i] == 0) continue; n     if (i == n - 1) { n       flag = 1; n       break; n     } else { n       if (a[i + 1] > 0) n         a[i + 1] -= 1; n       else n         flag = 1; n     } n   } n   if (flag == 1) n     printf( NO n ); n   else n     printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (1 << 18); n struct segment { n  private: n   static const int maxn = (1 << 18); n   int arr[2 * maxn]; n   int private_sum(int node, int first, int last, int a, int b) { n     if (first >= a && last <= b) return arr[node]; n     if (a >= last || b <= first) return 0; n     int mid = (first + last) / 2; n     return private_sum(2 * node, first, mid, a, b) + n            private_sum(2 * node + 1, mid, last, a, b); n   } n  n  public: n   void add(int ja, int megh) { n     ja += maxn; n     while (ja > 0) { n       arr[ja] += megh; n       ja /= 2; n     } n   } n   int sum(int first, int last) { n     return private_sum(1, maxn, 2 * maxn, maxn + first, maxn + last); n   } n   int nth(int n) { n     int node = 1, zir = maxn; n     while (zir > 1) { n       if (n < zir / 2 - arr[2 * node]) { n         node *= 2; n       } else { n         n -= zir / 2 - arr[2 * node]; n         node = 2 * node + 1; n       } n       zir /= 2; n     } n     return node - maxn; n   } n } p_fir, p_sec, s; n int a[maxn], b[maxn], out[maxn]; n void find_ab(int x, int n) { n   int fir = a[x], sec = b[x]; n   p_fir.add(fir, 1); n   p_sec.add(sec, 1); n   a[x] -= p_fir.sum(0, fir); n   b[x] -= p_sec.sum(0, sec); n } n void find_out(int n) { n   for (int i = 0; i < n; i++) { n     find_ab(i, n); n   } n   int bgh = 0; n   for (int i = n - 1; i >= 0; i--) { n     out[i] = bgh + a[i] + b[i]; n     if (out[i] >= n - i) { n       bgh = 1; n       out[i] -= (n - i); n     } else n       bgh = 0; n   } n   for (int i = 0; i < n; i++) { n     out[i] = s.nth(out[i]); n     s.add(out[i], 1); n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   find_out(n); n   for (int i = 0; i < n; i++) cout << out[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void FastIO() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n } n long long int mod = 2e9 + 10; n class SegmentTree { n  public: n   vector<int> st; n   vector<int> lazy; n   vector<int> A; n   int n; n   int left(int p) { return (p << 1) + 1; } n   int right(int p) { return (p << 1) + 2; } n   void build(int p, int l, int r) { n     if (l == r) n       st[p] = A[l]; n     else { n       build(left(p), l, (l + r) / 2); n       build(right(p), (l + r) / 2 + 1, r); n       st[p] = st[left(p)] + st[right(p)]; n     } n   } n   SegmentTree(vector<int> a) { n     A = a; n     n = (int)A.size(); n     st.assign(4 * n, 0); n     lazy.assign(4 * n, 0); n     build(0, 0, n - 1); n   } n   void lazyUpdate(int pos, int l, int r) { n     st[pos] += lazy[pos] * (r - l + 1); n     if (l != r) { n       lazy[left(pos)] += lazy[pos]; n       lazy[right(pos)] += lazy[pos]; n     } n     lazy[pos] = 0; n   } n   int query(int pos, int l, int r, int i, int j) { n     lazyUpdate(pos, l, r); n     if (i > r || j < l || l > r) return 0; n     if (i <= l && r <= j) { n       return st[pos]; n     } n     long long int q1 = query(left(pos), l, (l + r) / 2, i, j); n     long long int q2 = query(right(pos), (l + r) / 2 + 1, r, i, j); n     return (q1 + q2) % mod; n   } n   void update(int pos, int l, int r, int i, int j, int val) { n     lazyUpdate(pos, l, r); n     if (i > r || j < l || l > r) return; n     if (i <= l && r <= j) { n       st[pos] += val * (r - l + 1); n       if (l != r) { n         lazy[left(pos)] += val; n         lazy[right(pos)] += val; n       } n       return; n     } n     update(left(pos), l, (l + r) / 2, i, j, val); n     update(right(pos), (l + r) / 2 + 1, r, i, j, val); n     st[pos] = (st[left(pos)] + st[right(pos)]); n   } n }; n int main() { n   FastIO(); n   int n, k, a, b, q, d, x, p, type; n   cin >> n >> k >> a >> b >> q; n   vector<int> V1(n, 0), V2(n, 0), V3(n, 0); n   SegmentTree ST2(V2); n   SegmentTree ST3(V3); n   while (q--) { n     cin >> type; n     if (type == 1) { n       cin >> d >> x; n       d--; n       V1[d] += x; n       ST2.update(0, 0, n - 1, d, d, min(b, V1[d]) - V2[d]); n       V2[d] = min(b, V1[d]); n       ST3.update(0, 0, n - 1, n - d - 1, n - d - 1, n                  min(a, V1[d]) - V3[n - d - 1]); n       V3[n - d - 1] = min(a, V1[d]); n     } else { n       cin >> p; n       p--; n       int temp1 = 0, temp2 = 0; n       if (p) { n         temp1 = ST2.query(0, 0, n - 1, 0, p - 1); n       } n       p += k - 1; n       p = n - p - 1; n       if (p) { n         temp2 = ST3.query(0, 0, n - 1, 0, p - 1); n       } n       cout << temp1 + temp2 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const double eps = 1e-8; n const int mod = 1e9 + 7; n int jia[N], jian[N], x[N], yes[N]; n int out[N][3]; n int abbs(int x) { n   if (x > 0) n     return x; n   else n     return -x; n } n int main() { n   int n, m, t; n   scanf( %d%d , &n, &m); n   memset(out, 0, sizeof(out)); n   memset(yes, 0, sizeof(yes)); n   memset(jia, 0, sizeof(jia)); n   memset(jian, 0, sizeof(jian)); n   int alljia = 0, alljian = 0, all = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x[i]); n     if (x[i] > 0) n       jia[x[i]]++, alljia++; n     else n       jian[-x[i]]++, alljian++; n   } n   for (int i = 1; i <= n; i++) { n     int numzhen = jia[i] + alljian - jian[i]; n     if (numzhen == m) { n       yes[i] = 1; n       all++; n     } n   } n   for (int i = 1; i <= n; i++) { n     int xx = abbs(x[i]); n     if (yes[xx]) { n       if (all == 1) { n         if (x[i] > 0) n           out[i][0] = 1; n         else n           out[i][1] = 1; n       } else { n         out[i][2] = 1; n       } n     } else { n       if (x[i] > 0) n         out[i][1] = 1; n       else n         out[i][0] = 1; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (out[i][2]) n       printf( Not defined n ); n     else if (out[i][0]) n       printf( Truth n ); n     else if (out[i][1]) n       printf( Lie n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n bool prime(long long c) { n   for (long long i = 2; i * i <= c; i++) { n     if (c % i == 0) return 0; n   } n   return 1; n } n int32_t main() { n   c_p_c(); n   long long n; n   cin >> n; n   while (n--) { n     long long a, b, s = 0; n     cin >> a >> b; n     while (a > 0 && b > 0) { n       if (a > b) { n         s += (a / b); n         a -= (a / b) * b; n       } else { n         s += (b / a); n         b -= (b / a) * a; n       } n     } n     cout << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int m, n, i, j, k, p, l; n   scanf( %d %d , &m, &n); n   p = m + n; n   int a[m], b[n], c[p]; n   for (i = 0; i < m; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 0; i < n; i++) { n     scanf( %d , &b[i]); n   } n   k = 0; n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       if (a[i] == b[j]) { n         c[k] = a[i]; n         k++; n       } n     } n   } n   l = k; n   for (k = 0; k < l; k++) { n     printf( %d  , c[k]); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O1 ) n #pragma GCC optimize( O2 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n void input() { return; } n template <typename T1, typename... T2> n void input(T1 &x, T2 &...args) { n   ((cin >> x), input(args...)); n } n void wrt() { n   cout <<   n ; n   return; n } n template <typename T1, typename... T2> n void wrt(T1 x, T2... args) { n   ((cout << x <<    ), wrt(args...)); n } n template <typename T> n void inputlst(T &lst, int x, int y) { n   for (int i = x; i < y; i++) cin >> lst[i]; n } n template <typename T> n void printlst(T &lst, int x, int y) { n   for (int i = x; i < y; i++) cout << lst[i] <<    ; n   wrt(); n } n const long long inf = INT64_MAX, MOD = 1e9 + 7, N = 10; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   int test; n   cin >> test; n   while (test--) { n     int n, k, ans; n     input(n, k); n     vector<int> lst(n + 1); n     inputlst(lst, 1, n + 1); n     vector<vector<int> > dp(n + 1, vector<int>(n + 1, 0)); n     ans = n; n     for (long long move = 0; move < n + 1; ++move) { n       for (long long i = 1; i < n + 1; ++i) { n         dp[i][move] = n             max(dp[i][move], dp[i - 1][move] + (lst[i] == (i - move))); n         dp[i][move + 1] = max(dp[i - 1][move], dp[i][move + 1]); n         if (i == n) { n           if (dp[i][move] >= k) ans = min(ans, (int)move); n           if (dp[i][move + 1] >= k) ans = min(ans, (int)move + 1); n         } n       } n     } n     wrt(ans == n ? -1 : ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug() { cout << endl; } n template <class T, class... R> n void debug(T f, R... r) { n   cout <<  [  << f <<  ] ; n   debug(r...); n } n template <class T> n T mmin(T a, T b) { n   return min(a, b); n } n template <class T, class... R> n T mmin(T a, R... b) { n   return min(a, mmin(b...)); n } n template <class T> n T mmax(T a, T b) { n   return max(a, b); n } n template <class T, class... R> n T mmax(T a, R... b) { n   return max(a, mmax(b...)); n } n template <class T> n T mgcd(T a, T b) { n   return __gcd(a, b); n } n template <class T, class... R> n T mgcd(T a, R... b) { n   return __gcd(a, mgcd(b...)); n } n void myin() { n   freopen( 1.in ,  r , stdin); n   freopen( 1.out ,  w , stdout); n } n namespace IO { n const int MX = 4e7; n char buf[MX]; n int c, sz; n void begin() { n   c = 0; n   sz = fread(buf, 1, MX, stdin); n } n inline bool read(int &t) { n   while (c < sz && buf[c] !=  -  && (buf[c] <  0  || buf[c] >  9 )) c++; n   if (c >= sz) return false; n   bool flag = 0; n   if (buf[c] ==  - ) flag = 1, c++; n   for (t = 0; c < sz &&  0  <= buf[c] && buf[c] <=  9 ; c++) n     t = t * 10 + buf[c] -  0 ; n   if (flag) t = -t; n   return true; n } n }  // namespace IO n const int N = 1e5 + 5; n const int M = 1e5 + 5; n long long a[100005], e[200][200]; n vector<long long> v, sz[100]; n int main() { n   long long n; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; ++i) { n     long long tmp; n     scanf( %lld , &a[i]); n     if (a[i]) v.push_back(a[i]); n     for (long long j = 0; j < 63; ++j) { n       if ((1ll << j) & a[i]) sz[j].push_back(a[i]); n     } n   } n   for (long long i = 0; i < 63; ++i) n     if (sz[i].size() > 2) { n       return !printf( 3 ); n     } n   memset(e, 0x3f, sizeof(e)); n   long long ans = 0x3f3f3f3f3f3f3f3f; n   for (long long i = 0; i < v.size(); ++i) { n     for (long long j = 0; j < v.size(); ++j) { n       if (i != j && (v[i] & v[j])) e[i][j] = 1; n     } n   } n   for (long long k = 0; k < v.size(); ++k) { n     for (long long i = 0; i < v.size(); ++i) { n       for (long long j = 0; j < v.size(); ++j) { n         if (i == j || i == k || j == k) continue; n         if ((v[i] & v[k] && v[k] & v[j])) ans = min(ans, e[i][j] + 2); n       } n     } n     for (long long i = 0; i < v.size(); ++i) { n       for (long long j = 0; j < v.size(); ++j) { n         e[i][j] = min(e[i][j], e[i][k] + e[k][j]); n       } n     } n   } n   if (ans == 0x3f3f3f3f3f3f3f3f) ans = -1; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const long double PI = acos(-1.0); n using namespace std; n int n, m; n long long dp[505][505]; n int a[505]; n long long cal(int l, int r) { n   if (l >= r) return 1; n   long long &ret = dp[l][r]; n   if (ret != -1) return ret; n   ret = 0; n   int mn = n + 1, idx = 0; n   for (int i = l; i <= r; i++) { n     if (a[i] < mn) { n       mn = a[i]; n       idx = i; n     } n   } n   long long lft = cal(l, idx - 1); n   long long rgh = cal(idx + 1, r); n   for (int i = l; i < idx; i++) { n     lft += cal(l, i) * cal(i + 1, idx - 1); n     lft %= 998244353; n   } n   for (int i = idx + 1; i <= r; i++) { n     rgh += cal(idx + 1, i) * cal(i + 1, r); n     rgh %= 998244353; n   } n   lft %= 998244353; n   rgh %= 998244353; n   ret = rgh * lft; n   ret %= 998244353; n   return ret; n } n void init() { memset(dp, -1, sizeof dp); } n void read_input() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n } n void solve() { n   init(); n   cal(0, n - 1); n } n void print_ans() { cout << cal(0, n - 1) <<   n ; } n int main() { n   int t = 1; n   while (t--) { n     read_input(); n     solve(); n     print_ans(); n     if (t) init(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, k, l, m[1100]; n   char s[1100][34]; n   scanf( %d , &n); n   map<string, int> mp, mp2; n   for (i = 0; i < n; i++) { n     scanf( %s%d , s[i], &m[i]); n     mp[s[i]] += m[i]; n   } n   string name; n   int max = 0; n   for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) { n     if (it->second > max) max = it->second; n   } n   for (i = 0; i < n; i++) { n     mp2[s[i]] += m[i]; n     if (mp[s[i]] >= max && mp2[s[i]] >= max) break; n   } n   puts(s[i]); n   scanf( %*d ); n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int st, ed; n } ch[100010]; n bool cmp(node a, node b) { return a.st < b.st; } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, l, a; n   cin >> n >> l >> a; n   for (int i = 0; i < n; i++) { n     cin >> ch[i].st >> ch[i].ed; n     ch[i].ed += ch[i].st; n   } n   sort(ch, ch + n, cmp); n   int num = 0; n   num += (ch[0].st) / a; n   for (int i = 0; i < n - 1; i++) { n     if (ch[i + 1].st - ch[i].ed >= a) { n       num += (ch[i + 1].st - ch[i].ed) / a; n     } n   } n   if (ch[n - 1].ed < l) { n     num += (l - ch[n - 1].ed) / a; n   } n   cout << num << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int x2, y2, x3, y3; n bool check(long long int x, long long int y) { n   long long int xx = x3 * x3 + y3 * y3, tx = x2 + x, ty = y2 + y; n   if (xx == 0) return x == x2 && y == y2; n   long long int ret1 = tx * x3 + ty * y3, ret2 = tx * y3 - ty * x3; n   if (ret1 % xx != 0 || ret2 % xx != 0) return false; n   return true; n } n int main() { n   long long int x1, y1; n   cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; n   if (check(x1, y1) || check(-x1, -y1) || check(-y1, x1) || check(y1, -x1)) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n vector<int> aa(200); n vector<int> bb(200); n int n, k; n int count(int i, int j) { n   for (int h = i; h < n; h++) { n     bb[h - i] = aa[h]; n   } n   for (int h = 0; h < i; h++) { n     bb[n - i + h] = aa[h]; n   } n   int m = j - i; n   sort(bb.begin(), bb.begin() + m); n   sort(bb.begin() + m, bb.begin() + n); n   int sum = 0; n   for (int h = 0; h < m; h++) { n     sum += bb[h]; n   } n   for (int s = 0; s < k; s++) { n     int p = s; n     int q = n - 1 - s; n     if (p >= m || q < m || bb[p] >= bb[q]) { n       break; n     } n     sum += bb[q] - bb[p]; n   } n   return sum; n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     aa[i] = a; n   } n   int maxVal = INT_MIN; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j <= n; j++) { n       int cnt = count(i, j); n       maxVal = max(maxVal, cnt); n     } n   } n   cout << maxVal << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n; n   cin >> t; n   for (int l = 0; l < t; l++) { n     cin >> n; n     int k; n     k = 0; n     int c; n     c = 0; n     char arr[n][5]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < 5; j++) { n         cin >> arr[i][j]; n       } n     } n     for (int j = 0; j < 5; j++) { n       k = 0; n       for (int m = j + 1; m < 5; m++) { n         int first = 0; n         int second = 0; n         int tie = 0; n         for (int n1 = 0; n1 < n; n1++) { n           if (arr[n1][j] ==  1  && arr[n1][m] ==  1 ) { n             tie++; n           } else { n             if (arr[n1][j] ==  1 ) { n               second++; n             } n             if (arr[n1][m] ==  1 ) { n               first++; n             } n           } n         } n         if (first + second + tie == n && second + tie >= n / 2 && n             first + tie >= n / 2) { n           c = 1; n         } n       } n     } n     if (c == 0) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse2 ) n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   std::cerr << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long max(long long a, long long b) { return (a > b) ? a : b; } n long long min(long long a, long long b) { return (a < b) ? a : b; } n void amax(long long& a, long long b) { a = max(a, b) % 1000000007; } n void amin(long long& a, long long b) { a = min(a, b) % 1000000007; } n void inc(long long& a, long long b) { a = (a + b) % 1000000007; } n void dec(long long& a, long long b) { a = (a - b + 1000000007) % 1000000007; } n long long n, a, b; n long long ans = 1e9; n void find(long long la, long long lb, long long level = 0) { n   if (la == 0 && lb == 0) { n     amin(ans, level); n     return; n   } n   for (long long i = 0; i <= la; i++) { n     long long n2 = n - i * a; n     if (n2 < 0) break; n     long long usedb = min(n2 / b, lb); n     n2 -= usedb * b; n     long long ii = i; n     ii += n2 / a; n     long long temp = n2 / a; n     n2 -= temp * a; n     ii = min(la, ii); n     if (usedb == 0 && ii == 0) continue; n     find(la - ii, lb - usedb, level + 1); n   } n } n long long solve() { n   cin >> n >> a >> b; n   find(4, 2); n   cout << ans; n   return 0; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int *arr = new int[2 * n + 1]; n   cin >> arr[0]; n   for (int i = 1; i < 2 * n + 1; i += 2) { n     cin >> arr[i] >> arr[i + 1]; n     if (k > 0 && arr[i] > arr[i - 1] + 1 && arr[i] > arr[i + 1] + 1) { n       k -= 1; n       arr[i] -= 1; n     } n   } n   for (int i = 0; i < 2 * n + 1; i++) cout << arr[i] <<      ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 105; n int no[maxn][maxn][15], sum[maxn][maxn][15]; n int main() { n   int n, q, c, ans, i, j, k, x, y, s, ss, t, x1, x2, y1, y2, tt, num; n   while (scanf( %d%d%d , &n, &q, &c) != EOF) { n     memset(no, 0, sizeof(no)); n     memset(sum, 0, sizeof(sum)); n     for (i = 1; i <= n; i++) { n       scanf( %d%d%d , &x, &y, &s); n       no[x][y][s]++; n     } n     for (j = 1; j <= 100; j++) { n       for (i = 1; i <= 100; i++) { n         for (k = 0; k <= c; k++) { n           sum[i][j][k] = sum[i - 1][j][k] + no[i][j][k]; n         } n       } n     } n     while (q--) { n       ans = 0; n       scanf( %d%d%d%d%d , &t, &x1, &y1, &x2, &y2); n       for (j = y1; j <= y2; j++) { n         for (k = 0; k <= c; k++) { n           num = sum[x2][j][k] - sum[x1][j][k] + no[x1][j][k]; n           if (num > 0) { n             if (t <= c - k) n               ss = k + t; n             else { n               x = t - (c - k); n               tt = x % (c + 1); n               if (tt) n                 ss = tt - 1; n               else n                 ss = c; n             } n             ans += num * ss; n           } n         } n       } n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MaxN = 52, mod_v = 1000000007; n long long f[MaxN][MaxN >> 1][2], C[MaxN][MaxN]; n void init_comb(int n) { n   for (int i = 0; i <= n; ++i) { n     C[i][i] = C[i][0] = 1; n     for (int j = 1; j < i; ++j) { n       C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; n       if (C[i][j] >= mod_v) C[i][j] -= mod_v; n     } n   } n } n int main() { n   int n0, k0; n   std::cin >> n0 >> k0; n   if (k0 << 1 > n0) { n     std::cout <<  0 n ; n     return 0; n   } n   init_comb(n0); n   f[1][0][0] = 1; n   f[0][0][1] = 1; n   for (int n = 2; n <= n0; ++n) { n     for (int k = 1; k <= std::min(k0, n >> 1); ++k) { n       for (int g = 0; g <= 1; ++g) { n         long long& val = f[n][k][g]; n         for (int n1 = 0, n2 = n - 1; n1 <= n2; ++n1, --n2) { n           long long ways; n           if (n1 != n2) n             ways = C[n - 1][n1]; n           else n             ways = C[n - 2][n1 - 1]; n           if (n1) n             ways = ways * n1 * n2 % mod_v; n           else n             ways = ways * n2 % mod_v; n           for (int k1 = 0; k1 + g <= k; ++k1) { n             int k2 = k - k1 - g; n             if (g == 0) { n               val += f[n1][k1][1] * f[n2][k2][1] % mod_v * ways % mod_v; n             } else { n               val += n                   (f[n1][k1][1] * f[n2][k2][0] + f[n1][k1][0] * f[n2][k2][1] + n                    f[n1][k1][0] * f[n2][k2][0]) % n                   mod_v * ways % mod_v; n             } n           } n           val %= mod_v; n         } n       } n     } n   } n   std::cout << (f[n0][k0][0] + f[n0][k0][1]) % mod_v << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v1; n int status[(100000007 / 32) + 10]; n bool check1(int n, int pos) { return (bool)(n & (1 << pos)); } n int set1(int n, int pos) { return n = n | (1 << pos); } n void sieve() { n   int i, j, k; n   k = int(sqrt(100000007)); n   for (i = 3; i <= k; i += 2) { n     if (check1(status[i / 32], i % 32) == 0) { n       for (j = i * i; j <= 100000007; j += 2 * i) { n         status[j / 32] = set1(status[j / 32], j % 32); n       } n     } n   } n   v1.push_back(2); n   for (i = 3; i < 100000007; i += 2) { n     if (check1(status[i / 32], i % 32) == 0) v1.push_back(i); n   } n } n vector<long long int> v2; n void factor(long long int k) { n   long long int i, a; n   v2.clear(); n   for (i = 0; i < v1.size(); i++) { n     if (k == 1) break; n     a = v1[i]; n     while (k % a == 0) { n       if (k == 1) break; n       v2.push_back(a); n       k /= a; n     } n   } n   if (k != 1) v2.push_back(k); n } n int main() { n   sieve(); n   long long int a, b, c, d, i, j, k, l, m, n; n   cin >> n; n   factor(n); n   if (v2.size() == 1 || v2.size() == 0) { n     cout <<  1  << endl; n     cout <<  0  << endl; n     return 0; n   } n   if (v2.size() == 2) { n     cout <<  2  << endl; n     return 0; n   } n   cout <<  1  << endl; n   cout << v2[0] * v2[1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100 + 5; n const int inf = 1e9 + 7; n int n, m; n int num[MAXN]; n map<int, int> q; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &num[i]); n   for (int i = 2; i <= n; ++i) { n     q[num[i] - num[i - 1]]++; n   } n   if (q.size() == 1) n     printf( %d n , num[n] + num[2] - num[1]); n   else n     printf( %d n , num[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string ulaz, jed =  1 , dva =  14 , tri =  144 ; n bool je[10]; n int main() { n   cin >> ulaz; n   int l = ulaz.size(); n   for (int i = 0; i < l; i++) je[i] = false; n   for (int i = 0; i < l; i++) { n     if (je[i] == true) continue; n     if (i + 2 < l) { n       string nov; n       nov = ulaz[i]; n       nov += ulaz[i + 1]; n       nov += ulaz[i + 2]; n       if (nov == tri) { n         je[i] = true; n         je[i + 1] = true; n         je[i + 2] = true; n         i += 2; n         continue; n       } n     } n     if (i + 1 < l) { n       string nov; n       nov = ulaz[i]; n       nov += ulaz[i + 1]; n       if (nov == dva) { n         je[i] = true; n         je[i + 1] = true; n         i += 1; n         continue; n       } n     } n     if (ulaz[i] == jed[0]) { n       je[i] = true; n       continue; n     } n   } n   for (int i = 0; i < l; i++) n     if (je[i] == false) { n       cout <<  NO  << endl; n       return 0; n     } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll P = 1e9 + 7; n ll N, M, K, R, C; n ll Dx, Dy; n ll mult(ll a, ll b) { return (a * b) % P; } n ll exp(ll num_classes) { n   if (num_classes == 0) { n     return 1; n   } n   ll temp = exp(num_classes / 2); n   return (num_classes % 2) ? mult(K, mult(temp, temp)) : mult(temp, temp); n } n void input() { n   ll Ax, Ay, Bx, By; n   cin >> N >> M >> K >> R >> C; n   cin >> Ax >> Ay >> Bx >> By; n   Dx = (Ax > Bx) ? Ax - Bx : Bx - Ax; n   Dy = (Ay > By) ? Ay - By : By - Ay; n } n ll count_classes() { n   ll overlap = ((R > Dx) ? R - Dx : 0) * ((C > Dy) ? C - Dy : 0); n   ll classes = N * M - (2 * R * C - overlap); n   if (overlap == 0) { n     return classes + R * C; n   } n   if (Dx == 0 && Dy == 0) { n     return classes + R * C; n   } n   return classes + (R * Dy) + (C * Dx) - Dx * Dy; n } n int main() { n   input(); n   cout << exp(count_classes()) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num; n   scanf( %d  , &num); n   printf( %d , num + 1); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = (1e9 + 7); n const long long inf = (1e18 + 3); n const long long N = 1e7 + 5; n void no() { n   cout <<  -1 ; n   exit(0); n } n void yes() { n   cout <<  YES ; n   exit(0); n } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long inv(long long a) { return powmod(a, mod - 2); } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long mul(long long a, long long b) { return a * b % mod; } n long long add(long long a, long long b) { return (a + b) % mod; } n long long sub(long long a, long long b) { return (a - b + mod) % mod; } n int main() { n   string s; n   cin >> s; n   long long cnt = 1, res = 0; n   for (auto i : s) { n     if (i ==  a ) n       cnt <<= 1, cnt %= mod; n     else n       res = add(res, cnt - 1); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool checkC(int n) { n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) return 1; n   } n   return 0; n } n void per(string s, int i, int &num, string &ans) { n   if (i == s.length()) { n     if (num != 0 && checkC(num)) { n       int x = num; n       int d = 0; n       while (x != 0) { n         x /= 10; n         d++; n       } n       if (d > 0) { n         if (d < ans.length() || ans.length() == 0) ans = to_string(num); n       } n     } n   } else { n     int k = num; n     num = num * 10 + (s[i] -  0 ); n     per(s, i + 1, num, ans); n     num = k; n     per(s, i + 1, num, ans); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int test; n   cin >> test; n   while (test--) { n     int k; n     cin >> k; n     string s; n     cin >> s; n     vector<int> c(10, 0); n     int ans = -1; n     for (int i = 0; i < k; i++) { n       int vl = s[i] -  0 ; n       if (vl == 1 || vl == 4 || vl == 6 || vl == 8 || vl == 9) { n         ans = vl; n         break; n       } n       c[vl]++; n     } n     if (ans != -1) { n       cout <<  1 n ; n       cout << ans <<   n ; n     } else { n       if (c[2] >= 2) { n         cout <<  2 n ; n         cout <<  22 n ; n       } else if (c[3] >= 2) { n         cout <<  2 n ; n         cout <<  33 n ; n       } else if (c[5] >= 2) { n         cout <<  2 n ; n         cout <<  55 n ; n       } else if (c[7] >= 2) { n         cout <<  2 n ; n         cout <<  77 n ; n       } else { n         string pa =   ; n         int num = 0; n         per(s, 0, num, pa); n         cout << pa.length() <<   n ; n         cout << pa <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 500010; n const int inf = 2147483647; n const double pi = acos(-1.0); n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int n, m, k, a[Maxn]; n long long ans, rest; n bool del[Maxn]; n struct Edge { n   int x, y; n } e[Maxn]; n int fa[Maxn << 1], dep[Maxn << 1]; n int findfa(int x) { return ((fa[x] == x) ? x : findfa(fa[x])); } n int top = 0, sta[Maxn << 1], o, fa1[Maxn << 1], dep1[Maxn << 1]; n void merge(int x, int y) { n   int fx = findfa(x), fy = findfa(y); n   if (dep[fx] < dep[fy]) swap(fx, fy); n   sta[++top] = fy; n   fa1[top] = fa[fy], dep1[top] = dep[fx]; n   fa[fy] = fx; n   dep[fx] = max(dep[fx], dep[fy] + 1); n } n void resume() { n   while (top > o) { n     int fy = sta[top]; n     dep[fa[fy]] = dep1[top]; n     fa[fy] = fa1[top]; n     --top; n   } n } n vector<pair<int, int> > g[Maxn]; n int tot = 0; n map<int, map<int, int> > mp; n int main() { n   memset(dep, 0, sizeof(dep)); n   memset(del, false, sizeof(del)); n   n = read(), m = read(), k = read(); n   ans = (long long)k * (k - 1ll) / 2ll; n   rest = k - 1; n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= m; i++) e[i].x = read(), e[i].y = read(); n   for (int i = 1; i <= n * 2; i++) fa[i] = i; n   for (int i = 1; i <= m; i++) n     if (!del[a[e[i].x]] && a[e[i].x] == a[e[i].y]) { n       int fx = findfa(e[i].x), fy = findfa(e[i].y); n       if (fx == fy) n         del[a[e[i].x]] = true, ans -= rest, rest--; n       else n         merge(e[i].x, e[i].y + n), merge(e[i].y, e[i].x + n); n     } n   o = top; n   for (int i = 1; i <= m; i++) n     if (a[e[i].x] != a[e[i].y] && !del[a[e[i].x]] && !del[a[e[i].y]]) { n       int cx = a[e[i].x], cy = a[e[i].y]; n       if (cx > cy) swap(cx, cy); n       if (!mp[cx][cy]) mp[cx][cy] = ++tot; n       g[mp[cx][cy]].push_back(make_pair(e[i].x, e[i].y)); n     } n   for (int i = 1; i <= tot; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       int x = g[i][j].first, y = g[i][j].second; n       int fx = findfa(x), fy = findfa(y); n       if (fx == fy) { n         ans--; n         break; n       } n       merge(x, y + n); n       merge(y, x + n); n     } n     resume(); n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c, l; n   cin >> a >> b >> c >> l; n   long long cnt = (l + 1) * (l + 2) * (l + 3) / 6; n   for (int i = 0; i <= l; i++) { n     long long x = min(l - i, c + i - a - b); n     if (x < 0) continue; n     cnt -= (x + 1) * (x + 2) / 2; n   } n   for (int i = 0; i <= l; i++) { n     long long x = min(l - i, b + i - a - c); n     if (x < 0) continue; n     cnt -= (x + 1) * (x + 2) / 2; n   } n   for (int i = 0; i <= l; i++) { n     long long x = min(l - i, a + i - b - c); n     if (x < 0) continue; n     cnt -= (x + 1) * (x + 2) / 2; n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000007; n const long long INFLL = 1000000000000000007; n const long long MOD = 998244353; n bool comp(long long a, long long b) { return a > b; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, k; n   cin >> n >> k; n   vector<long long> v; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     v.push_back(x); n   } n   long long ans = 0, ans1 = 1, licz = -INFLL; n   for (int i = 0; i < n; i++) { n     if (v[i] <= n - k) n       licz++; n     else { n       if (licz > 0) ans1 *= (licz + 1); n       ans1 %= MOD; n       ans += v[i]; n       licz = 0; n     } n   } n   cout << ans <<     << ans1; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n const int MOD = 1e9 + 7; n const long long INF = 1e18; n long long add(long long a, long long b) { n   a = a % MOD; n   b = b % MOD; n   return (a + b) % MOD; n } n long long sub(long long a, long long b) { n   a = a % MOD; n   b = b % MOD; n   return (a - b + MOD) % MOD; n } n long long mul(long long a, long long b) { n   a = a % MOD; n   b = b % MOD; n   return ((a * b) % MOD + MOD) % MOD; n } n long long mod_pow(long long n, long long x) { n   int res = 1; n   while (x > 0) { n     if (x % 2 == 1) res = (res * n) % MOD; n     n = (n * n) % MOD; n     x /= 2; n   } n   return res; n } n void solve() { n   string t, order =   ; n   cin >> t; n   map<char, int> m; n   int n = 0; n   for (int i = t.size() - 1; i >= 0; i--) { n     if (m[t[i]] == 0) { n       order = t[i] + order; n     } n     m[t[i]]++; n   } n   for (int i = 0; i < order.size(); i++) { n     m[order[i]] /= (i + 1); n     n += m[order[i]]; n   } n   string s = t.substr(0, n); n   string sc = s; n   bool temp = true; n   int ind = n; n   for (int i = 0; i < order.size(); i++) { n     string temp =   ; n     for (int j = 0; j < s.size(); j++) { n       if (s[j] == order[i]) continue; n       temp += s[j]; n     } n     s = temp; n     for (int j = 0; j < s.size(); j++) { n       if (ind == t.size() || t[ind] != s[j]) { n         cout <<  -1 n ; n         return; n       } n       ind++; n     } n   } n   if (ind != t.size()) temp = false; n   if (temp) { n     cout << sc <<     << order <<   n ; n   } else { n     cout <<  -1 n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tc = 1; n   cin >> tc; n   while (tc--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() {} n int main(int argc, char const *argv[]) { n   c_p_c(); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   string arr; n   cin >> n >> arr; n   int cnt = 0; n   if (n == 1) { n     cout << cnt << endl; n     cout << arr << endl; n     return 0; n   } n   for (int i = 1; i < n; i++) { n     if (arr[i] == arr[i - 1] && arr[i] == arr[i + 1]) { n       cnt++; n       if (arr[i] ==  R ) n         arr[i] =  G ; n       else if (arr[i] ==  G ) n         arr[i] =  R ; n       else { n         arr[i] =  G ; n       } n       i++; n     } else if (arr[i] == arr[i - 1]) { n       cnt++; n       if (arr[i] ==  R  && arr[i + 1] ==  B ) { n         arr[i] =  G ; n         i++; n       } else if (arr[i] ==  R  && arr[i + 1] ==  G ) { n         arr[i] =  B ; n         i++; n       } else if (arr[i] ==  G  && arr[i + 1] ==  R ) { n         arr[i] =  B ; n         i++; n       } else if (arr[i] ==  G  && arr[i + 1] ==  B ) { n         arr[i] =  R ; n         i++; n       } else if (arr[i] ==  B  && arr[i + 1] ==  G ) { n         arr[i] =  R ; n         i++; n       } else if (arr[i] ==  B  && arr[i + 1] ==  R ) { n         arr[i] =  G ; n         i++; n       } else { n         if (arr[i - 1] ==  R ) n           arr[i] =  G ; n         else if (arr[i - 1] ==  G ) n           arr[i] =  R ; n         else n           arr[i] =  R ; n       } n     } n   } n   cout << cnt << endl; n   cout << arr << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long infll = powl(2, 62) - 1; n const long long mod = pow(10, 9) + 7; n int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) { n   if (!a) { n     x = 0; n     y = 1; n     return b; n   } n   int64_t x1, y1; n   int64_t d = extGcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n inline long long addMod(long long a, long long b, long long m = mod) { n   return ((int64_t)a + b) % m; n } n inline long long mulMod(long long a, long long b, long long m = mod) { n   return ((int64_t)a * b) % m; n } n inline long long divMod(long long a, long long b, long long m = mod) { n   int64_t x, y; n   int64_t g = extGcd(b, m, x, y); n   if (g != 1) { n     cerr <<  Bad gcd!  << endl; n     for (;;) n       ; n   } n   x = (x % m + m) % m; n   return mulMod(a, x, m); n } n const long long factRange = 1000000; n long long fact[factRange]; n inline void precalcFactorials() { n   fact[0] = 1; n   for (long long i = 1; i < factRange; i++) { n     fact[i] = mulMod(fact[i - 1], i); n   } n } n inline long long F(long long n) { return (n < 0) ? 0 : fact[n]; } n inline long long C(long long n, long long k) { n   return divMod(F(n), mulMod(F(n - k), F(k))); n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   precalcFactorials(); n   string bracket; n   cin >> bracket; n   vector<long long> open(bracket.size()), close(bracket.size()); n   long long count = 0; n   for (long long i = 0; i < (long long)(bracket.size()); ++i) { n     if (bracket[i] ==  ( ) count++; n     open[i] = count; n   } n   count = 0; n   for (long long i = (long long)(bracket.size()) - 1; i >= 0; --i) { n     if (bracket[i] ==  ) ) count++; n     close[i] = count; n   } n   long long ans = 0; n   for (long long i = 0; i < (long long)(bracket.size()); ++i) { n     if (bracket[i] !=  (  || close[i] == 0) continue; n     if (bracket[i] ==  ( ) { n       ans += C(open[i] + close[i] - 1, open[i]); n       ans %= mod; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Input_Preparing() {} n void Processing() { n   int a, b; n   cin >> a >> b; n   cout << min(a, b) <<     << (max(a, b) - min(a, b)) / 2; n } n int main() { n   std::cin.tie(0)->sync_with_stdio(0); n   ; n   Processing(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[(100000 + 10)], size = 0; n int fa[(100000 + 10)], son[(100000 + 10)], n, x, spec, specp; n bool b[(100000 + 10)] = {0}, f[(100000 + 10)] = {0}; n int main() { n   scanf( %d%d , &n, &x); n   for (int i = 1; i <= n; i++) scanf( %d , &fa[i]); n   for (int i = 1; i <= n; i++) n     if (fa[i]) son[fa[i]] = i; n   for (int i = 1; i <= n; i++) n     if (fa[i] == 0) { n       int tot = 1, j = i; n       bool flag = b[x]; n       b[i] = 1; n       j = i; n       if (i == x) spec = 1; n       while (son[j]) { n         b[son[j]] = 1, tot++, j = son[j]; n         if (j == x) spec = tot; n       } n       if (b[x] == flag) n         l[++size] = tot; n       else n         specp = spec; n     } n   f[0] = 1; n   for (int i = 1; i <= size; i++) { n     for (int j = n; j >= 0; j--) { n       if (f[j]) f[j + l[i]] = 1; n     } n   } n   for (int j = 0; j < n + 1; j++) n     if (f[j]) cout << j + specp << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string to_string(string s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const long double eps = 1e-12; n const int N = 2e6 + 9; n long long ans[N]; n pair<pair<int, int>, int> a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first.first; n     a[i].second = i; n   } n   for (int i = 0; i < n; i++) { n     cin >> a[i].first.second; n     a[i].first.second *= -1; n   } n   sort(a, a + n); n   multiset<int> ss; n   for (int i = 0; i < n; i++) { n     42; n     int j = 0; n     auto it = ss.begin(); n     ans[a[i].second] = a[i].first.second; n     while (j < m && it != ss.end()) { n       ans[a[i].second] += (*it); n       it++; n       j++; n     } n     ss.insert(a[i].first.second); n   } n   for (int i = 0; i < n; i++) cout << -ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200001]; n int main() { n   int n, w; n   cin >> n >> w; n   for (int i = 0; i < 2 * n; i++) { n     cin >> a[i]; n   } n   sort(a, a + 2 * n); n   double x = min((double)a[0], (double)a[n] / 2); n   double ans = min((double)w, (double)3 * n * x); n   cout.precision(10); n   cout << fixed; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int mod = 1e9 + 7; n void solve() { n   long long v1, v2, t, d; n   cin >> v1 >> v2 >> t >> d; n   long long ans = 0; n   for (int i = 0; i < t; i++) ans += min(v1 + d * i, v2 + (t - i - 1) * d); n   cout << ans << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < n; j++) { n       if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1) n         cout <<  W ; n       else n         cout <<  B ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > v(3000); n int main() { n   std::ios::sync_with_stdio(false); n   long long n, x1, y1, x2, y2, x, y; n   cin >> n; n   cin >> x1 >> y1 >> x2 >> y2; n   long long d1, d2; n   for (long long i = (long long)(0); i <= (long long)(n - 1); i++) { n     cin >> x >> y; n     v[i].first = abs(x - x1) * abs(x - x1) + abs(y - y1) * abs(y - y1); n     v[i].second = abs(x - x2) * abs(x - x2) + abs(y - y2) * abs(y - y2); n   } n   v.push_back(make_pair(0, 0)); n   long long ans = LLONG_MAX; n   for (long long i = (long long)(0); i <= (long long)(n); i++) { n     long long d1 = v[i].first; n     long long d2 = 0; n     for (long long j = (long long)(0); j <= (long long)(n); j++) { n       if (v[j].first > d1) d2 = max(v[j].second, d2); n     } n     ans = min(ans, d1 + d2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int rbq[505][505]; n int score[505]; n int main() { n   int n, m, q; n   while (~scanf( %d%d%d , &n, &m, &q)) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         scanf( %d , &rbq[i][j]); n       } n     } n     for (int i = 1; i <= n; i++) { n       int max = 0; n       for (int j = 1; j <= m; j++) { n         int count = 0; n         while (j <= m && rbq[i][j] == 1) { n           j++; n           count++; n         } n         if (count > max) max = count; n       } n       score[i] = max; n     } n     for (int i = 0; i < q; i++) { n       int r, l; n       scanf( %d%d , &r, &l); n       if (rbq[r][l] == 0) n         rbq[r][l] = 1; n       else n         rbq[r][l] = 0; n       int max = 0; n       for (int j = 1; j <= m; j++) { n         int count = 0; n         while (j <= m && rbq[r][j] == 1) { n           j++; n           count++; n         } n         if (count > max) max = count; n       } n       score[r] = max; n       int max_score = 0; n       for (int j = 1; j <= n; j++) { n         if (score[j] > max_score) max_score = score[j]; n       } n       printf( %d n , max_score); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #define f(c,a,b) for(int c=a; c<=b; c++) n #define N 5000010 n #define pii pair<int,int> n #define mp make_pair n #define fi first n #define se second n #define sl (u<<1) n #define sr ((u<<1)+1) n #define pb push_back n  n using namespace std; n typedef double db; n typedef long long ll; n struct node{ n  int u,v,x; n  bool operator < (const node& a) const{ return x<a.x; } n }b[N]; n int k[N]; n  n bool ask(int i,int j){ n  cout<< ?  <<i<<   <<j<<endl; n  string ans; n  cin>>ans; n  if(ans== Yes ) return true; else return false; n } n  n int main(){ n  // freopen( owo.in , r ,stdin); n  // ios::sync_with_stdio(false); n  // cin.tie(nullptr); n  int n; n  cin >> n; n  f(i,1,n) cin>>k[i]; n  int id=0; n  f(i,1,n){ n   f(j,i+1,n){ n    b[++id] = (node){ i,j,abs(k[i]-k[j]) }; n   } n  } n  sort(b+1,b+id+1); n  for(int i=id; i>=1; i--) { n   int ti=b[i].u, tj=b[i].v; n   if(k[ti]>k[tj]) { n    if(ask(ti,tj)){ n     cout<< !  <<ti<<   <<tj<<endl; n     return 0; n    } n   }else{ n    if(ask(tj,ti)){ n     cout<< !  <<ti<<   <<tj<<endl; n     return 0; n    }  n   } n  } n  cout<< !  <<0<<   <<0<<endl; n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 512345, lgN = 20, rootN = 1123; n const double eps = 1e-11; n vector<int> cities; n int root = -1; n int dp[N]; n bool visited[N], rem[N]; n vector<int> adj[N]; n void dfsTree(int v) { n   int sum = 0; n   auto it = lower_bound(cities.begin(), cities.end(), v); n   if (it < cities.end() && *it == v) ++sum; n   for (int i = 0; i < adj[v].size(); ++i) { n     int u = adj[v][i]; n     if (visited[u]) continue; n     visited[u] = true; n     dfsTree(u); n     sum += dp[u]; n   } n   if (sum == 0) n     rem[v] = true; n   else if (sum == cities.size() && root == -1) n     root = v; n   else if (sum == cities.size()) n     rem[v] = true; n   dp[v] = sum; n } n pair<int, int> bfsDistance(int src) { n   memset(visited, false, sizeof visited); n   queue<pair<int, int> > q; n   q.push(make_pair(src, 0)); n   visited[src] = true; n   pair<int, int> ret = make_pair(src, 0); n   while (!q.empty()) { n     int v = q.front().first, dist = q.front().second; n     q.pop(); n     if (dist > ret.second || (dist == ret.second && v < ret.first)) n       ret = make_pair(v, dist); n     for (int i = 0; i < adj[v].size(); ++i) { n       int u = adj[v][i]; n       if (visited[u] || rem[u]) continue; n       visited[u] = true; n       q.push(make_pair(u, dist + 1)); n     } n   } n   return ret; n } n int main() { n   int n, c; n   scanf( %d %d , &n, &c); n   int u, v; n   for (int i = 1; i < n; ++i) { n     scanf( %d %d , &u, &v); n     adj[u].push_back(v), adj[v].push_back(u); n   } n   cities.resize(c); n   for (int i = 0; i < cities.size(); ++i) scanf( %d , &cities[i]); n   sort(cities.begin(), cities.end()); n   visited[1] = true; n   dfsTree(1); n   pair<int, int> x = bfsDistance(root); n   pair<int, int> y = bfsDistance(x.first); n   printf( %d n , min(x.first, y.first)); n   int ct = 0; n   for (int i = 1; i <= n; ++i) n     if (!rem[i]) ++ct; n   int ans = 2 * (ct - 1) - y.second; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[200010], fi[200010]; n const int MOD = 1e9 + 7; n int add(long long a, long long b) { return (a + b) % MOD; } n int mul(long long a, long long b) { return (a * b) % MOD; } n int fp(long long a, int b) { n   if (b == 0) return 1; n   int tp = fp(a, b >> 1); n   tp = mul(tp, tp); n   if (b & 1) n     return mul(tp, a); n   else n     return tp; n } n int comb(int n, int k) { n   if (k > n) return 0; n   return mul(f[n], mul(fi[n - k], fi[k])); n } n int h, w, n, dp[2010]; n vector<pair<int, int> > v; n int main() { n   f[0] = fi[0] = 1; n   for (int i = 1; i <= 200002; i++) { n     f[i] = mul(i, f[i - 1]); n     fi[i] = fp(f[i], MOD - 2); n   } n   scanf( %d%d%d , &h, &w, &n); n   v.resize(n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &v[i].first, &v[i].second); n   } n   sort(v.begin(), v.end()); n   v.emplace_back(h, w); n   for (int i = 0; i <= n; i++) { n     dp[i] = comb(v[i].first + v[i].second - 2, v[i].first - 1); n     for (int j = 0; j < i; j++) { n       if (v[j].first <= v[i].first && v[j].second <= v[i].second) { n         dp[i] = n             add(dp[i], n                 -mul(comb(v[i].first + v[i].second - (v[j].first + v[j].second), n                           v[i].first - v[j].first), n                      dp[j])); n         if (dp[i] < 0) dp[i] += MOD; n       } n     } n   } n   printf( %d n , dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> grid; n int main() { n   int n; n   cin >> n; n   string line =   ; n   for (int i = 0; i < n; i++) { n     cin >> line; n     grid.push_back(line); n   } n   bool rowblock = false; n   bool colblock = false; n   for (int i = 0; i < n; i++) { n     bool found = false; n     for (int j = 0; j < n; j++) { n       if (grid[i][j] ==  . ) { n         found = true; n       } n     } n     if (!found) { n       rowblock = true; n     } n   } n   for (int j = 0; j < n; j++) { n     bool found = false; n     for (int i = 0; i < n; i++) { n       if (grid[i][j] ==  . ) { n         found = true; n       } n     } n     if (!found) { n       colblock = true; n     } n   } n   if (rowblock && colblock) { n     cout << -1 << endl; n     return 0; n   } n   if (rowblock == false) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (grid[i][j] ==  . ) { n           cout << i + 1 <<     << j + 1 << endl; n           break; n         } n       } n     } n   } else { n     for (int j = 0; j < n; j++) { n       for (int i = 0; i < n; i++) { n         if (grid[i][j] ==  . ) { n           cout << i + 1 <<     << j + 1 << endl; n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n const long long MOD = 1e9 + 7; n long long n, a[55]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   if (a[0] == a[n / 2]) n     cout <<  Bob ; n   else n     cout <<  Alice ; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[1005]; n int main() { n   cin >> n; n   int x; n   int ans = 0; n   if (n == 1) { n     cin >> x; n     if (x) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     cin >> x; n     ans += x; n   } n   if (ans == n - 1) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double ex = 1e-6; n double pow(double x, int n) { n   double ret = 1; n   while (n) { n     if (n % 2) ret *= x; n     n >>= 1; n     x *= x; n   } n   return ret; n } n int main() { n   double n; n   int m; n   while (scanf( %lf %d , &n, &m) != EOF) { n     double ans = n; n     double i = n - 1; n     double k; n     for (i; i >= 1; i -= 1) { n       k = pow(i / n, m); n       if (k < ex) break; n       ans -= k; n     } n     printf( %0.4lf n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct coord { n   int c, f, v; n }; n coord var, pos; n int n, m, i, x, cont, h; n int pasos[1001][1001]; n bool ya[1001][1001], e; n char mapa[1001][1001]; n queue<coord> cola; n stack<coord> pila; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %s , mapa[i]); n   } n   for (i = 0; i < n; i++) { n     for (x = 0; x < m; x++) { n       if (mapa[i][x] ==  T ) n         ya[i][x] = true; n       else if (mapa[i][x] ==  E ) { n         ya[i][x] = true; n         var.c = i; n         var.f = x; n         var.v = 0; n         cola.push(var); n       } n     } n   } n   while (!cola.empty()) { n     pos = cola.front(); n     cola.pop(); n     if (pos.c - 1 >= 0 && ya[pos.c - 1][pos.f] == false) { n       pos.c--; n       cola.push(pos); n       ya[pos.c][pos.f] = true; n       pasos[pos.c][pos.f] = pasos[pos.c + 1][pos.f] + 1; n       if (mapa[pos.c][pos.f] ==  S ) { n         h = pasos[pos.c][pos.f]; n       } n       pos.c++; n     } n     if (pos.c + 1 < n && ya[pos.c + 1][pos.f] == false) { n       pos.c++; n       cola.push(pos); n       ya[pos.c][pos.f] = true; n       pasos[pos.c][pos.f] = pasos[pos.c - 1][pos.f] + 1; n       if (mapa[pos.c][pos.f] ==  S ) { n         h = pasos[pos.c][pos.f]; n       } n       pos.c--; n     } n     if (pos.f - 1 >= 0 && ya[pos.c][pos.f - 1] == false) { n       pos.f--; n       cola.push(pos); n       ya[pos.c][pos.f] = true; n       pasos[pos.c][pos.f] = pasos[pos.c][pos.f + 1] + 1; n       if (mapa[pos.c][pos.f] ==  S ) { n         h = pasos[pos.c][pos.f]; n       } n       pos.f++; n     } n     if (pos.f + 1 < m && ya[pos.c][pos.f + 1] == false) { n       pos.f++; n       cola.push(pos); n       ya[pos.c][pos.f] = true; n       pasos[pos.c][pos.f] = pasos[pos.c][pos.f - 1] + 1; n       if (mapa[pos.c][pos.f] ==  S ) { n         h = pasos[pos.c][pos.f]; n       } n       pos.f--; n     } n   } n   for (i = 0; i < n; i++) { n     for (x = 0; x < m; x++) { n       if (mapa[i][x] -  0  > 0 && mapa[i][x] -  0  < 10) { n         if (pasos[i][x] <= h && ya[i][x] == true) cont += mapa[i][x] -  0 ; n       } n     } n   } n   printf( %d , cont); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, t; n   while (cin >> n >> t) { n     int x, y; n     vector<pair<int, int> > a; n     vector<pair<int, int> > v; n     for (int i = 0; i < n; i++) { n       cin >> x >> y; n       a.push_back(make_pair(x, y)); n     } n     for (int i = 0; i < n; i++) { n       while (a[i].first < t) a[i].first += a[i].second; n       v.push_back(make_pair(a[i].first, i)); n     } n     sort(v.begin(), v.end()); n     cout << (v[0].second) + 1 << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int y, stat; n }; n struct query { n   int curNode; n   int curLength; n   int curGood; n }; n vector<edge> vec[100005]; n pair<long long, long long> best[100005]; n long long path[100005], pathStatus[100005]; n int n, m; n queue<query> q; n set<pair<int, int> > badRoads; n map<pair<int, int>, int> goodRoads; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int x, y, z; n     scanf( %d %d %d , &x, &y, &z); n     if (z == 1) goodRoads[make_pair(min(x, y), max(x, y))]++; n     x--, y--; n     vec[x].push_back({y, z}); n     vec[y].push_back({x, z}); n   } n   for (int i = 0; i < n; i++) best[i].first = 1e10; n   q.push({0, 0, 0}); n   while (!q.empty()) { n     query ab = q.front(); n     q.pop(); n     if (best[ab.curNode].first < ab.curLength || n         (best[ab.curNode].first == ab.curLength && n          best[ab.curNode].second > ab.curGood)) n       continue; n     int vSize = vec[ab.curNode].size(); n     for (int i = 0; i < vSize; i++) { n       int nextNode = vec[ab.curNode][i].y; n       int nextGood = vec[ab.curNode][i].stat + ab.curGood; n       if (ab.curLength + 1 < best[nextNode].first || n           (best[nextNode].first == ab.curLength + 1 && n            nextGood > best[nextNode].second)) { n         best[nextNode].first = ab.curLength + 1; n         best[nextNode].second = nextGood; n         q.push({nextNode, ab.curLength + 1, nextGood}); n         path[nextNode] = ab.curNode; n         pathStatus[nextNode] = vec[ab.curNode][i].stat; n       } n     } n   } n   int myNode = n - 1; n   while (myNode) { n     if (pathStatus[myNode]) { n       int minVal = min(path[myNode] + 1, myNode + 1LL); n       int maxVal = max(path[myNode] + 1, myNode + 1LL); n       goodRoads[make_pair(minVal, maxVal)]--; n     } else n       badRoads.insert({path[myNode] + 1, myNode + 1}); n     myNode = path[myNode]; n   } n   vector<pair<pair<int, int>, int> > ans; n   for (auto it : badRoads) n     ans.push_back(make_pair(make_pair(it.first, it.second), 1)); n   for (auto it : goodRoads) { n     if (it.second == 0) continue; n     for (int i = 0; i < it.second; i++) n       ans.push_back(make_pair(make_pair(it.first.first, it.first.second), 0)); n   } n   int curSize = ans.size(); n   printf( %d n , curSize); n   for (int i = 0; i < curSize; i++) n     printf( %d %d %d n , ans[i].first.first, ans[i].first.second, n            ans[i].second); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, m; n   cin >> n >> m; n   long long int n1, m1; n   cin >> n1 >> m1; n   long long int a[n], b[m]; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   for (long long int i = 0; i < m; i++) cin >> b[i]; n   if (a[n1 - 1] < b[m - m1]) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n int32_t main() { n   ios_base ::sync_with_stdio(false), cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n const int INF_INT = 0x3f3f3f3f; n const long long INF_LL = 0x7f7f7f7f; n const int MOD = 1e9 + 7; n const double eps = 1e-10; n const double pi = acos(-1); n using namespace std; n vector<int> g[100010]; n int n; n double ans; n void dfs(int fa, int u, int cnt) { n   ans += 1.0 / cnt; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == fa) continue; n     dfs(u, v, cnt + 1); n   } n } n int main(int argc, char const *argv[]) { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   ans = 0.0; n   dfs(0, 1, 1); n   printf( %.12f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int MAXN = 100100; n inline void add(int &a, int b) { n   a += b; n   if (a >= MOD) { n     a -= MOD; n   } n } n inline int mul(int a, int b) { return (a * 1LL * b) % MOD; } n inline int fastPow(int a, int b) { n   int r = 1; n   while (b) { n     if (b & 1) { n       r = mul(r, a); n     } n     a = mul(a, a); n     b >>= 1; n   } n   return r; n } n inline int inverse(int a) { return fastPow(a, MOD - 2); } n int f[MAXN]; n int invf[MAXN]; n int ten[MAXN]; n inline int c(int n, int k) { n   if (k < 0) { n     return 0; n   } n   if (n < k) { n     return 0; n   } n   return mul(mul(f[n], invf[k]), invf[n - k]); n } n int main() { n   clock_t start_time = clock(); n   f[0] = invf[0] = 1; n   ten[0] = 1; n   for (int i = 1; i < MAXN; i++) { n     ten[i] = mul(ten[i - 1], 10); n     f[i] = mul(f[i - 1], i); n     invf[i] = inverse(f[i]); n   } n   int n, k; n   while (scanf( %d%d , &n, &k) == 2) { n     char ss[n + 1]; n     scanf( %s , ss); n     vector<int> s(n, 0); n     for (int i = 0; i < n; i++) { n       s[i] = ss[i] -  0 ; n       if (i > 0) { n         add(s[i], s[i - 1]); n       } n     } n     int ans = 0; n     for (int d = 0; d <= n - 2; d++) { n       int val = mul(ten[d], c(n - d - 2, k - 1)); n       val = mul(val, s[n - d - 2]); n       add(ans, val); n     } n     for (int i = 0; i < n; i++) { n       int val = mul(ten[n - i - 1], ss[i] -  0 ); n       val = mul(val, c(i, k)); n       add(ans, val); n     } n     printf( %d n , ans); n   } n   (void)42; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   long long n, R = 0, L = 0; n   cin >> n; n   long long l[n], r[n]; n   for (int x = 0; x < n; x++) { n     cin >> l[x] >> r[x]; n     L += l[x]; n     R += r[x]; n   } n   int val = abs(R - L); n   int ans = 0; n   for (int x = 0; x < n; x++) { n     int tL = L - (l[x] - r[x]); n     int tR = R - (r[x] - l[x]); n     int i = abs(tL - tR); n     if (i > val) { n       ans = x + 1; n       val = i; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x %= p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int modInverse(long long int n, long long int p) { n   return power(n, p - 2, p); n } n long long int nCrModPFermat(long long int n, long long int r, long long int p) { n   if (r == 0) return 1; n   long long int fac[n + 1]; n   fac[0] = 1; n   for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n void SieveOfEratosthenes(long long int n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (long long int p = 2; p * p <= n; p++) { n     if (prime[p] == true) n       for (long long int i = p * p; i <= n; i += p) prime[i] = false; n   } n   for (long long int p = 2; p <= n; p++) n     if (prime[p]) cout << p <<    ; n } n int main() { n   fast(); n   int t = 1; n   while (t--) { n     int n, k; n     cin >> n >> k; n     int v[n]; n     vector<int> a; n     map<int, int> m; n     for (int i = 0; i < n; ++i) cin >> v[i]; n     a.push_back(v[0]); n     for (int i = 1; i < n; ++i) { n       if (v[i] != a[a.size() - 1]) a.push_back(v[i]); n     } n     n = a.size(); n     m[a[0]]++; n     for (int i = 1; i < n; ++i) { n       if (i < n - 1 && a[i - 1] == a[i + 1]) n         m[a[i]] += 2; n       else n         m[a[i]]++; n     } n     int maxi = 0, ans; n     for (auto x : m) { n       if (maxi < x.second) { n         maxi = x.second; n         ans = x.first; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int B = 27397, MOD = 1e9 + 7; n const int B1 = 33941, MOD1 = 1e9 + 9; n int n, q; n struct Node { n   int nxt[11]; n   long long sum[11]; n   Node() { n     for (int i = 0; i < 10; ++i) nxt[i] = i; n     memset(sum, 0, sizeof sum); n   } n }; n class Tournament { n  private: n   int offset, lo, hi, x, y; n   int nxt_left[11], nxt_right[11]; n   long long new_sum[11]; n   vector<Node> tree; n   void merge(int node) { n     for (int i = 0; i < 10; ++i) n       tree[node].sum[i] = tree[2 * node].sum[i] + tree[2 * node + 1].sum[i]; n   } n   void propagate(int node) { n     if (node < offset) { n       for (int i = 0; i < 10; ++i) { n         nxt_left[i] = tree[node].nxt[tree[2 * node].nxt[i]]; n         nxt_right[i] = tree[node].nxt[tree[2 * node + 1].nxt[i]]; n       } n       for (int i = 0; i < 10; ++i) { n         tree[2 * node].nxt[i] = nxt_left[i]; n         tree[2 * node + 1].nxt[i] = nxt_right[i]; n       } n     } n     memset(new_sum, 0, sizeof new_sum); n     for (int i = 0; i < 10; ++i) n       new_sum[tree[node].nxt[i]] += tree[node].sum[i]; n     for (int i = 0; i < 10; ++i) { n       tree[node].sum[i] = new_sum[i]; n       tree[node].nxt[i] = i; n     } n   } n   void update(int node, int from, int to) { n     propagate(node); n     if (to <= lo || hi <= from) return; n     if (from >= lo && to <= hi) { n       tree[node].nxt[x] = y; n       propagate(node); n       return; n     } n     update(2 * node, from, (from + to) / 2); n     update(2 * node + 1, (from + to) / 2, to); n     merge(node); n   } n   long long query(int node, int from, int to) { n     propagate(node); n     if (to <= lo || hi <= from) return 0; n     if (from >= lo && to <= hi) { n       long long ret = 0; n       for (int i = 0; i < 10; ++i) ret += (long long)i * tree[node].sum[i]; n       return ret; n     } n     long long left = query(2 * node, from, (from + to) / 2); n     long long right = query(2 * node + 1, (from + to) / 2, to); n     return left + right; n   } n  n  public: n   Tournament(int n) { n     for (offset = 1; offset <= n; offset <<= 1) n       ; n     tree.resize(2 * offset); n   } n   void insert(int i, int val) { n     i += offset; n     int coef = 1; n     while (val > 0) { n       tree[i].sum[val % 10] += (long long)coef; n       coef *= 10; n       val /= 10; n     } n     for (i >>= 1; i > 0; i >>= 1) merge(i); n   } n   void update(int l, int r, int _x, int _y) { n     lo = l; n     hi = r; n     x = _x; n     y = _y; n     update(1, 0, offset); n   } n   long long query(int l, int r) { n     lo = l; n     hi = r; n     return query(1, 0, offset); n   } n }; n int main(void) { n   scanf( %d%d , &n, &q); n   Tournament T(n); n   for (int i = 0; i < n; ++i) { n     int x; n     scanf( %d , &x); n     T.insert(i, x); n   } n   for (int i = 0; i < q; ++i) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int l, r, x, y; n       scanf( %d%d%d%d , &l, &r, &x, &y); n       --l; n       if (x == y) continue; n       T.update(l, r, x, y); n       continue; n     } n     int l, r; n     scanf( %d%d , &l, &r); n     --l; n     printf( %lld n , T.query(l, r)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > adj[100100]; n long long under[100100]; n long long n; n long long dfs(long long u, long long p) { n   under[u] = 0; n   long long next, edge; n   for (long long i = 0; i < adj[u].size(); i++) { n     next = adj[u][i].first; n     edge = adj[u][i].second; n     if (next != p) { n       under[u] += edge + dfs(next, u); n     } n   } n   return under[u]; n } n long long f(long long u, long long p) { n   long long sum = 0; n   long long edge, next; n   for (long long i = 0; i < adj[u].size(); i++) { n     next = adj[u][i].first; n     edge = adj[u][i].second; n     if (next != p) sum += edge + under[next]; n   } n   if (sum == 0) return 0; n   long long best = 100000000ll * 100000000ll; n   long long now; n   for (long long i = 0; i < adj[u].size(); i++) { n     next = adj[u][i].first; n     edge = adj[u][i].second; n     if (next != p) { n       now = (sum - (edge + under[next])) * 2 + edge + f(next, u); n       best = min(best, now); n     } n   } n   return best; n } n int main() { n   cin >> n; n   long long x, y, edge; n   for (long long i = 1; i < n; i++) { n     cin >> x >> y >> edge; n     adj[x].push_back(pair<long long, long long>(y, edge)); n     adj[y].push_back(pair<long long, long long>(x, edge)); n   } n   dfs(1, -1); n   cout << f(1, -1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n pair<int, int> answer[404]; n set<pair<int, int> > S; n set<pair<int, int> >::iterator it, ii; n bool check(pair<int, int> c) { n   ii = S.lower_bound(make_pair(c.first, 0)); n   if (ii != S.end()) { n     if (c.first + c.second > (*ii).first) return false; n   } n   if (ii != S.begin()) { n     ii--; n     if (c.first < (*ii).first + (*ii).second) return false; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   S.insert(make_pair(0, 1)); n   for (int i = 0; i < n; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     pair<int, int> c = make_pair(x, y); n     if (check(c)) { n       answer[i] = c; n       S.insert(c); n       continue; n     } n     for (it = S.begin(); it != S.end(); it++) { n       c = make_pair((*it).first + (*it).second, y); n       if (check(c)) { n         S.insert(c); n         answer[i] = c; n         break; n       } n     } n   } n   for (int i = 0; i < n; ++i) n     printf( %d %d n , answer[i].first, answer[i].second + answer[i].first - 1); n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> g, rv; n int ds[3030][3030]; n vector<int> md[3030]; n int rd[3030][3030]; n vector<int> mr[3030]; n int main() { n   int n, m; n   scanf( %d %d  , &n, &m); n   g.assign(n, vector<int>()); n   rv.assign(n, vector<int>()); n   while (m--) { n     int a, b; n     scanf( %d %d  , &a, &b); n     a--; n     b--; n     if (a == b) continue; n     g[a].push_back(b); n     rv[b].push_back(a); n   } n   memset(ds, -1, sizeof(ds)); n   memset(rd, -1, sizeof(rd)); n   for (int i = 0; i < n; i++) { n     ds[i][i] = rd[i][i] = 0; n     queue<int> q; n     priority_queue<pair<int, int>, vector<pair<int, int>>, n                    greater<pair<int, int>>> n         pq; n     q.push(i); n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       if (i != u) pq.push({ds[i][u], u}); n       while (pq.size() > 3) { n         pq.pop(); n       } n       for (int j = 0; j < g[u].size(); j++) { n         int v = g[u][j]; n         if (ds[i][v] >= 0) { n           continue; n         } n         ds[i][v] = ds[i][u] + 1; n         q.push(v); n       } n     } n     while (!pq.empty()) { n       int u = pq.top().second; n       pq.pop(); n       md[i].push_back(u); n     } n     q = queue<int>(); n     q.push(i); n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       if (i != u) pq.push({rd[i][u], u}); n       while (pq.size() > 3) { n         pq.pop(); n       } n       for (int j = 0; j < rv[u].size(); j++) { n         int v = rv[u][j]; n         if (rd[i][v] >= 0) continue; n         rd[i][v] = rd[i][u] + 1; n         q.push(v); n       } n     } n     while (!pq.empty()) { n       int u = pq.top().second; n       pq.pop(); n       mr[i].push_back(u); n     } n   } n   int ma = 0; n   int mi[4]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       if (ds[i][j] < 0) continue; n       for (int k = 0; k < mr[i].size(); k++) { n         for (int l = 0; l < md[j].size(); l++) { n           int a = mr[i][k], b = md[j][l]; n           if (a == b || a == j) continue; n           if (b == i) continue; n           int dist = ds[a][i] + ds[i][j] + ds[j][b]; n           if (dist > ma) { n             ma = dist; n             mi[0] = a; n             mi[1] = i; n             mi[2] = j; n             mi[3] = b; n           } n         } n       } n     } n   } n   printf( %d %d %d %d n , mi[0] + 1, mi[1] + 1, mi[2] + 1, mi[3] + 1); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000006; n const long long int M = 935172938408392767LL; n vector<long long int> kub[N]; n long long int kra[N]; n long long int maska[N]; n int deg[N]; n int main() { n   int n, m, a, b; n   long long int wynik = 0; n   scanf( %d%d , &n, &m); n   kra[1] = 1; n   for (int i = 2; i <= n; i++) kra[i] = (kra[i - 1] * 2) % M; n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &a, &b); n     maska[a] += kra[b]; n     maska[b] += kra[a]; n     maska[a] %= M; n     maska[b] %= M; n     deg[a]++; n     deg[b]++; n   } n   for (int i = 1; i <= n; i++) { n     kub[deg[i]].push_back(maska[i]); n     kub[deg[i]].push_back((maska[i] + kra[i]) % M); n   } n   for (int i = 0; i <= n; i++) { n     sort(kub[i].begin(), kub[i].end()); n     a = 1; n     for (int j = 1; j < kub[i].size(); j++) { n       if (kub[i][j - 1] == kub[i][j]) n         a++; n       else { n         wynik += ((a - 1) * (long long)a) / 2; n         a = 1; n       } n     } n     wynik += ((a - 1) * (long long)a) / 2; n   } n   printf( %I64d n , wynik); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (long long)4e18 + 7; n inline void minimize(long long &x, const long long &y) { n   if (x > y) x = y; n } n struct help { n   int x, s, r; n   help() { x = s = r = 0; } n   void input(void) { n     x = s = r = 0; n     int k; n     scanf( %d%d%d , &x, &r, &k); n     for (int zz = 0; zz < (k); zz = zz + 1) { n       int v; n       scanf( %d , &v); n       v--; n       s |= (1 << (v)); n     } n   } n   bool operator<(const help &a) const { return (r < a.r); } n }; n long long f[(1 << (20)) + 7]; n help a[111]; n int n, m, b; n void init(void) { n   scanf( %d%d%d , &n, &m, &b); n   for (int i = (1); i <= (n); i = i + 1) a[i].input(); n   sort(a + 1, a + n + 1); n } n void process(void) { n   for (int i = 0; i < ((1 << (m))); i = i + 1) f[i] = INF; n   f[0] = 0; n   long long res = INF; n   for (int i = (1); i <= (n); i = i + 1) { n     long long cost = 1LL * b * a[i].r; n     for (int j = 0; j < ((1 << (m))); j = j + 1) n       if (f[j] < INF) minimize(f[j | a[i].s], f[j] + a[i].x); n     minimize(res, f[(1 << (m)) - 1] + cost); n   } n   if (res < INF) n     cout << res; n   else n     cout << -1; n } n int main(void) { n   init(); n   process(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n int n; n bool init[MAXN], goal[MAXN]; n vector<int> e[MAXN]; n bool mark[MAXN]; n bool even = true; n bool eo[2]; n queue<int> ans; n void dfs(int v) { n   if (mark[v]) return; n   mark[v] = true; n   bool change = false; n   if ((init[v] != goal[v]) ^ eo[even]) { n     ans.push(v + 1); n     eo[even] = !eo[even]; n     change = true; n   } n   for (int i = 0; i < e[v].size(); i++) { n     int u = e[v][i]; n     even = !even; n     dfs(u); n     even = !even; n   } n   if (change) eo[even] = !eo[even]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     e[u].push_back(v); n     e[v].push_back(u); n   } n   for (int i = 0; i < n; i++) cin >> init[i]; n   for (int i = 0; i < n; i++) cin >> goal[i]; n   dfs(0); n   cout << ans.size() << endl; n   while (ans.size() > 0) { n     cout << ans.front() << endl; n     ans.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n using ll = long long int; n using ld = long double; n using pi = pair<int, int>; n const double PI = acos(-1.0); n const double eps = 1e-9; n const ll mod = 1e9 + 7; n const int inf = 1e7; n const int MAXN = 1e5 + 5; n void cp() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int &x : arr) cin >> x; n   int mn = *min_element(arr.begin(), arr.end()); n   for (int &x : arr) x -= mn, x++; n   int one = count(arr.begin(), arr.end(), 1); n   if (one > n / 2) n     cout <<  Bob n ; n   else n     cout <<  Alice n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t; n   t = 1; n   while (t--) { n     cp(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int Find(string x) { n   if (x ==  rock ) return 1; n   if (x ==  scissors ) return 2; n   if (x ==  paper ) return 3; n } n int main() { n   string a, b, c; n   int sa, sb, sc; n   cin >> a >> b >> c; n   sa = Find(a), sb = Find(b), sc = Find(c); n   if (sa == 1 && sb == 2 && sc == 2) n     printf( F ); n   else if (sa == 2 && sb == 3 && sc == 3) n     printf( F ); n   else if (sa == 3 && sb == 1 && sc == 1) n     printf( F ); n   else if (sa == 2 && sb == 1 && sc == 2) n     printf( M ); n   else if (sa == 3 && sb == 2 && sc == 3) n     printf( M ); n   else if (sa == 1 && sb == 3 && sc == 1) n     printf( M ); n   else if (sa == 2 && sb == 2 && sc == 1) n     printf( S ); n   else if (sa == 3 && sb == 3 && sc == 2) n     printf( S ); n   else if (sa == 1 && sb == 1 && sc == 3) n     printf( S ); n   else n     printf( ? ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long head[100005]; n long long memory[100005]; n int n, m; n bool possible(long long t) { n   int curr = 1; n   for (int i = 1; i <= n; i++) { n     long long headloc = head[i]; n     if (headloc <= memory[curr]) { n       headloc += t; n       while (headloc >= memory[curr] && curr <= m) curr++; n     } else { n       if (headloc - t > memory[curr]) return false; n       long long d = headloc - memory[curr]; n       long long next = max(headloc + (t - d) / 2, headloc + (t - 2 * d)); n       headloc = next; n       while (headloc >= memory[curr] && curr <= m) curr++; n     } n     if (curr == m + 1) return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> head[i]; n   for (int i = 1; i <= m; i++) cin >> memory[i]; n   long long start = 0; n   long long endi = 20000000000; n   while (start < endi) { n     long long mid = (start + endi) / 2; n     if (possible(mid)) n       endi = mid; n     else n       start = mid + 1; n   } n   cout << endi; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n const int base = 31337; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const int logo = 20; n const int off = 1 << logo; n const int treesiz = off << 1; n int n, m, k; n vector<int> graph[maxn]; n int a[maxn], ss[maxn], cs[maxn]; n bool bio[maxn]; n int cnt = 0; n int dfs(int x) { n   bio[x] = true; n   cnt += graph[x].size(); n   int out = 1; n   for (int i = 0; i < graph[x].size(); i++) { n     int tren = graph[x][i]; n     if (!bio[tren]) out += dfs(tren); n   } n   return out; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < k; i++) scanf( %d , a + i); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   memset(bio, false, sizeof bio); n   int maxi = 0; n   for (int i = 0; i < k; i++) { n     ss[i] = dfs(a[i]); n     maxi = max(maxi, ss[i]); n     cs[i] = cnt / 2, cnt = 0; n   } n   int ax = 0; n   for (int i = 1; i <= n; i++) { n     if (!bio[i]) ax += dfs(i); n   } n   long long tren = 0; n   long long sol = 0; n   for (int i = 0; i < k; i++) { n     tren += ss[i] * (ss[i] - 1) / 2 - cs[i]; n   } n   cnt /= 2; n   for (int i = 0; i < k; i++) { n     int pt = a[i]; n     int ts = ss[i] + ax; n     sol = max(sol, tren - (ss[i] * (ss[i] - 1) / 2 - cs[i]) + n                        (ts * (ts - 1) / 2 - cnt - cs[i])); n   } n   printf( %lld n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n struct Point { n   int x, y; n   Point(int _x = 0, int _y = 0) { n     x = _x; n     y = _y; n   } n   Point operator-(const Point &R) const { return Point(x - R.x, y - R.y); } n   long long operator^(const Point &R) const { n     return (long long)x * R.y - (long long)y * R.x; n   } n   long long operator%(const Point &R) const { n     return (long long)x * R.x + (long long)y * R.y; n   } n   bool operator<(const Point &R) const { n     if (x != R.x) return x < R.x; n     return y < R.y; n   } n }; n int n, m, p; n Point W[N], K[N]; n map<Point, int> Hash; n long long res[N], ans[N]; n int a[N]; n bool cmpP(const int &A, const int &B) { return W[A] < W[B]; } n bool cmpQ(const int &A, const int &B) { n   return (long long)K[A].x * K[B].y < (long long)K[B].x * K[A].y; n } n void update(vector<int> &P, vector<int> &Q) { n   if (P.empty() || Q.empty()) return; n   sort(P.begin(), P.end(), cmpP); n   vector<int> A, B; n   for (int i = 0; i < Q.size(); ++i) n     if (K[Q[i]].y >= 0) { n       A.push_back(Q[i]); n     } n   sort(A.begin(), A.end(), cmpQ); n   vector<Point> s(P.size() + 1); n   int t = 0; n   for (int i = 0; i < P.size(); ++i) { n     Point D = W[P[i]]; n     while (t > 1 && ((D - s[t - 2]) ^ (s[t - 1] - s[t - 2])) <= 0) --t; n     s[t++] = D; n   } n   for (int i = 0, j = 0; i < A.size(); ++i) { n     while (j + 1 < t && (K[A[i]] % s[j + 1]) >= (K[A[i]] % s[j])) ++j; n     res[A[i]] = max(res[A[i]], K[A[i]] % s[j]); n   } n   t = 0; n   for (int i = 0; i < P.size(); ++i) { n     Point D = W[P[i]]; n     while (t > 1 && ((D - s[t - 2]) ^ (s[t - 1] - s[t - 2])) >= 0) --t; n     s[t++] = D; n   } n } n int del[N]; n void divide(const vector<int> &A) { n   if (A.size() <= 1) return; n   vector<int> P, Q; n   int r = A.size(), mid = r / 2; n   for (int i = 0; i < mid; ++i) P.push_back(A[i]); n   divide(P); n   P.clear(); n   for (int i = 0; i < r; ++i) n     if (A[i] > 0 && (A[i] & 1)) del[A[i] >> 1] = 1; n   for (int i = 0; i < mid; ++i) n     if (A[i] > 0 && (~A[i] & 1)) { n       if (!del[A[i] >> 1]) n         P.push_back(A[i] >> 1); n       else n         del[A[i] >> 1] = 2; n     } n   for (int i = mid; i < r; ++i) n     if (A[i] < 0) Q.push_back(-A[i]); n   update(P, Q); n   Q.clear(); n   int c1 = 0, c2 = 0; n   for (int i = r - 1; i >= mid; --i) { n     if (A[i] > 0 && (A[i] & 1) && del[A[i] >> 1] == 2) { n       Q.push_back(A[i] ^ 1); n       ++c1; n     } else if (A[i] < 0) { n       Q.push_back(A[i]); n       ++c2; n     } n   } n   for (int i = 0; i < r; ++i) n     if (A[i] > 0 && (A[i] & 1)) del[A[i] >> 1] = 0; n   if (c1 && c2) divide(Q); n   P.clear(); n   for (int i = mid; i < r; ++i) P.push_back(A[i]); n   divide(P); n } n int iid[N]; n void work() { n   scanf( %d , &n); n   vector<int> A; n   for (int i = 0; i < n; ++i) { n     Point S; n     scanf( %d , &a[i]); n     if (a[i] == 3) { n       scanf( %d , &S.x); n       S.y = 1; n       ++m; n       res[m] = -1LL << 60; n       K[m] = S; n       a[i] = -m; n     } else { n       if (a[i] == 1) { n         scanf( %d%d , &S.x, &S.y); n         W[++p] = S; n         iid[i] = p; n         a[i] = p << 1; n       } else { n         int j; n         scanf( %d , &j); n         a[i] = iid[j - 1] << 1 | 1; n       } n     } n     A.push_back(a[i]); n   } n   divide(A); n   for (int i = 1; i <= m; ++i) { n     if (res[i] == -1LL << 60) { n       puts( EMPTY SET ); n     } else { n       printf( %lld n , res[i]); n     } n   } n } n int main() { n   work(); n   return 0; n } n