#include <bits/stdc++.h> n using namespace std; n const int maxN = (int)1e6 + 10; n int mod = (int)1e9 + 7; n int sum(int a, int b) { n   int s = a + b; n   if (s >= mod) s -= mod; n   return s; n } n int n; n int mult(int a, int b) { return (1LL * a * b) % mod; } n int a[maxN]; n int inv[maxN]; n int fact; n void calc() { n   inv[1] = 1; n   for (int i = 2; i < maxN; i++) { n     inv[i] = mult((mod - (mod / i)), inv[mod % i]); n   } n   fact = 1; n   for (int i = 2; i <= n; i++) fact = mult(fact, i); n } n int main() { n   ios_base::sync_with_stdio(false); n   srand(time(0)); n   srand(time(0)); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   calc(); n   sort(a + 1, a + n + 1); n   int mx = a[n]; n   int ans = 0; n   int x = 0; n   int prv = 0; n   int sz = 1; n   for (int i = 1; i <= n; i++) { n     if (a[i] == mx) break; n     if (i > 1) { n       if (a[i] == a[i - 1]) n         sz++; n       else { n         prv = prv + sz; n         sz = 1; n       } n     } n     ans = sum(ans, mult(mult(a[i], fact), inv[n - prv])); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n clock_t timeStart, timeFinish; n void timeBegin() { timeStart = clock(); } n void timeEnd() { timeFinish = clock(); } n void timeDuration() { n   timeEnd(); n   double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); n   cout <<  Time taken by program is :   << fixed << time_taken n        << setprecision(5); n   cout <<   sec   << endl; n } n class InputReader { n  public: n   InputReader() { n     input_file = stdin; n     cursor = 0; n     fread(buffer, SIZE, 1, input_file); n   } n   InputReader(const char *file_name) { n     input_file = fopen(file_name,  r ); n     cursor = 0; n     fread(buffer, SIZE, 1, input_file); n   } n   inline InputReader &operator>>(int &n) { n     while ((buffer[cursor] <  0  || buffer[cursor] >  9 ) && n            buffer[cursor] !=  - ) { n       advance(); n     } n     int sign = 1; n     if (buffer[cursor] ==  - ) { n       sign = -1; n       advance(); n     } n     n = 0; n     while ( 0  <= buffer[cursor] && buffer[cursor] <=  9 ) { n       n = n * 10 + buffer[cursor] -  0 ; n       advance(); n     } n     n *= sign; n     return *this; n   } n  n  private: n   FILE *input_file; n   static const int SIZE = 1 << 17; n   int cursor; n   char buffer[SIZE]; n   inline void advance() { n     ++cursor; n     if (cursor == SIZE) { n       cursor = 0; n       fread(buffer, SIZE, 1, input_file); n     } n   } n }; n const int MAXN = 200000; n const int MAXLOG = 18; n const int INF = 1000000000; n vector<int> g[1 + MAXN]; n vector<pair<int, int> > t[1 + MAXN]; n int dad[1 + MAXLOG][1 + MAXN], answer[1 + MAXN], virusId[1 + MAXN]; n int counter = 0, start[1 + MAXN], finish[1 + MAXN], depth[1 + MAXN]; n int speed[1 + MAXN], id[1 + MAXN], virus[1 + MAXN], city[1 + MAXN], n     st[1 + MAXN]; n void DFS(int node, int father) { n   dad[0][node] = father; n   depth[node] = depth[father] + 1; n   for (int i = 1; (1 << i) < depth[node]; i++) { n     dad[i][node] = dad[i - 1][dad[i - 1][node]]; n   } n   start[node] = ++counter; n   for (auto son : g[node]) { n     if (son != father) { n       DFS(son, node); n     } n   } n   finish[node] = counter; n } n int raise(int node, int delta) { n   for (int i = 0; i < MAXLOG; i++) { n     if ((delta >> i) & 1) { n       node = dad[i][node]; n     } n   } n   return node; n } n bool isParent(int a, int b) { n   return start[a] <= start[b] && finish[b] <= finish[a]; n } n int lca(int a, int b) { n   if (depth[a] < depth[b]) { n     swap(a, b); n   } n   a = raise(a, depth[a] - depth[b]); n   for (int i = MAXLOG - 1; i >= 0; i--) { n     if (dad[i][a] != dad[i][b]) { n       a = dad[i][a]; n       b = dad[i][b]; n     } n   } n   if (a != b) { n     a = dad[0][a]; n     b = dad[0][b]; n   } n   return a; n } n inline bool compareStart(const int &a, const int &b) { n   return start[a] < start[b]; n } n void sortUnique(vector<int> &v) { n   sort(v.begin(), v.end(), compareStart); n   v.resize(unique(v.begin(), v.end()) - v.begin()); n } n pair<int, int> d[1 + MAXN]; n bool isSmaller(int c1, int s1, int c2, int s2) { n   int t1 = (c1 == 0 ? 0 : (c1 - 1) / speed[s1] + 1); n   int t2 = (c2 == 0 ? 0 : (c2 - 1) / speed[s2] + 1); n   return make_pair(t1, virusId[s1]) < make_pair(t2, virusId[s2]); n } n bool seen[1 + MAXN]; n void dijkstra(vector<int> &v) { n   priority_queue<pair<pair<int, int>, pair<int, int> >, n                  vector<pair<pair<int, int>, pair<int, int> > >, n                  greater<pair<pair<int, int>, pair<int, int> > > > n       h; n   for (auto node : v) { n     if (virusId[node] != 0) { n       d[node] = {0, virusId[node]}; n       h.push({{0, virusId[node]}, {node, 0}}); n     } else { n       d[node] = {INF, 0}; n     } n   } n   while (!h.empty()) { n     int r = h.top().first.first, s = h.top().first.second, n         node = h.top().second.first, c = h.top().second.second; n     h.pop(); n     if (seen[node]) { n       continue; n     } n     seen[node] = true; n     for (auto it : t[node]) { n       int other = it.first, l = it.second; n       int r0 = (c + l - 1) / speed[s] + 1, s0 = s; n       if (make_pair(r0, s0) < d[other]) { n         d[other] = {r0, s0}; n         h.push({{r0, s0}, {other, c + l}}); n       } n     } n   } n } n void solve(int k, int m) { n   vector<int> v; n   for (int i = 1; i <= k; i++) { n     v.push_back(virus[i]); n   } n   for (int i = 1; i <= m; i++) { n     v.push_back(city[i]); n   } n   sortUnique(v); n   int x = v.size(); n   for (int i = 0; i + 1 < x; i++) { n     v.push_back(lca(v[i], v[i + 1])); n   } n   sortUnique(v); n   int top = 1; n   st[top] = v[0]; n   for (int i = 1; i < v.size(); i++) { n     int node = v[i]; n     while (!isParent(st[top], node)) { n       top--; n     } n     int l = depth[node] - depth[st[top]]; n     t[st[top]].push_back({node, l}); n     t[node].push_back({st[top], l}); n     top++; n     st[top] = node; n   } n   dijkstra(v); n   for (auto node : v) { n     seen[node] = false; n     t[node].clear(); n     if (id[node] != 0) { n       answer[id[node]] = d[node].second; n     } n   } n } n int main() { n   timeBegin(); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   speed[0] = 1; n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   DFS(1, 0); n   int q; n   cin >> q; n   for (int i = 1; i <= q; i++) { n     int k, m; n     cin >> k >> m; n     for (int i = 1; i <= k; i++) { n       cin >> virus[i] >> speed[i]; n       virusId[virus[i]] = i; n     } n     for (int i = 1; i <= m; i++) { n       cin >> city[i]; n       id[city[i]] = i; n     } n     solve(k, m); n     for (int i = 1; i <= m; i++) { n       cout << answer[i] <<    ; n     } n     cout <<   n ; n     for (int i = 1; i <= k; i++) { n       virusId[virus[i]] = 0; n     } n     for (int i = 1; i <= m; i++) { n       id[city[i]] = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n int main(void) { n   lint Q, N; n   cin >> Q; n   vector<lint> ans(Q); n   for (int i = 0; i < Q; i++) { n     cin >> N; n     lint sum = 0; n     for (int k = 0; k < N; k++) { n       int x; n       cin >> x; n       sum += x; n     } n     ans[i] = ceil(sum / (double)N); n   } n   for (int i = 0; i < Q; i++) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int MAX_N = 1e3 + 9; n int par[MAX_N], rankv[MAX_N]; n vector<pair<int, int>> cycles; n vector<array<int, 4>> ans; n void init(int n) { n   for (int i = 1; i <= n; i++) par[i] = i, rankv[i] = 1; n } n int find_set(int u) { n   if (par[u] == u) return u; n   return par[u] = find_set(par[u]); n } n void link(int x, int y) { n   if (rankv[x] > rankv[y]) swap(x, y); n   par[x] = y; n   rankv[y] += (rankv[y] == rankv[x]); n } n bool union_set(int x, int y) { n   x = find_set(x), y = find_set(y); n   if (x != y) link(x, y); n   return x != y; n } n int32_t main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, u, v; n   cin >> n; n   init(n); n   for (int i = 0; i < n - 1; i++) { n     cin >> u >> v; n     if (!union_set(u, v)) cycles.push_back({u, v}); n   } n   for (int i = 0; i < cycles.size(); i++) { n     auto cur = cycles[i]; n     for (int j = 1; j <= n; j++) { n       if (union_set(cur.first, j)) { n         ans.push_back({cur.first, cur.second, cur.first, j}); n         break; n       } n     } n   } n   if (ans.empty()) cout << 0, exit(0); n   cout << ans.size() <<   n ; n   for (auto i : ans) { n     for (int j = 0; j < 4; j++) cout << i[j] <<    [j == 3]; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N; n long long arr[100020]; n long long prefix[100020]; n multiset<long long> s; n set<int> ded; n long long range(int i, int j) { n   if (i == 0) { n     return prefix[j]; n   } else { n     return prefix[j] - prefix[i - 1]; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   if (fopen( cf722c.in ,  r )) { n     freopen( cf722c.in ,  r , stdin); n     freopen( cf722c.out ,  w , stdout); n   } n   cin >> N; n   arr[0] = 0; n   for (int i = 1; i <= N; i++) { n     cin >> arr[i]; n   } n   prefix[0] = arr[0]; n   for (int i = 1; i <= N + 1; i++) { n     prefix[i] = prefix[i - 1] + arr[i]; n   } n   s.insert(0); n   s.insert(prefix[N + 1]); n   ded.insert(0); n   ded.insert(N + 1); n   for (int i = 0; i < N; i++) { n     int x; n     cin >> x; n     ded.insert(x); n     int l = 0, r = 0; n     auto lt = ded.lower_bound(x); n     if (lt == ded.begin()) { n       l = 0; n     } else { n       lt--; n       l = *lt; n       l++; n     } n     auto rt = ded.upper_bound(x); n     if (rt == ded.end()) { n       r = N + 1; n     } else { n       r = *rt; n       r--; n     } n     s.erase(s.find(range(l, r))); n     s.insert(range(l, x - 1)); n     s.insert(range(x + 1, r)); n     cout << *(s.rbegin()) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n string s; n int main() { n   cin >> n >> m >> s; n   if (m - 1 < n - m) { n     while (m > 1) { n       cout <<  LEFT n ; n       --m; n     } n     for (int i = 0; i < (int)(n); i++) { n       cout <<  PRINT   << s[i] <<   n ; n       if (i != n - 1) cout <<  RIGHT n ; n     } n   } else { n     while (m < n) { n       cout <<  RIGHT n ; n       ++m; n     } n     for (int i = 0; i < (int)(n); i++) { n       cout <<  PRINT   << s[n - 1 - i] <<   n ; n       if (i != n - 1) cout <<  LEFT n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int cnt = 0; n   bool flag = true; n   int low = -2000000000, high = 2000000000; n   bool lset = false; n   bool hset = false; n   cin >> cnt; n   for (int i = 1; i <= cnt; i++) { n     string str1, str2, str3; n     cin >> str1 >> str2 >> str3; n     stringstream stream(str2); n     int num; n     stream >> num; n     if (((str1 ==  > ) && (str3 ==  Y )) || ((str1 ==  <= ) && (str3 ==  N ))) { n       if (low <= num) { n         low = num + 1; n         lset = true; n       } n       if (lset && hset && (high < low || low > 2000000000)) { n         flag = false; n         break; n       } n     } n     if (((str1 ==  >= ) && (str3 ==  Y )) || ((str1 ==  < ) && (str3 ==  N ))) { n       if (low < num) { n         low = num; n         lset = true; n       } n       if (lset && hset && (high < low || low > 2000000000)) { n         flag = false; n         break; n       } n     } n     if (((str1 ==  <= ) && (str3 ==  Y )) || ((str1 ==  > ) && (str3 ==  N ))) { n       if (high > num) { n         high = num; n         hset = true; n       } n       if (lset && hset && (high < low || high < -2000000000)) { n         flag = false; n         break; n       } n     } n     if (((str1 ==  < ) && (str3 ==  Y )) || ((str1 ==  >= ) && (str3 ==  N ))) { n       if (high >= num) { n         high = num - 1; n         hset = true; n       } n       if (lset && hset && (high < low || high < -2000000000)) { n         flag = false; n         break; n       } n     } n   } n   if (flag && (!hset) && lset) cout << low << endl; n   if (flag && (!lset) && hset) cout << high << endl; n   if (flag && !lset && !hset) cout <<  0  << endl; n   if (flag && lset && hset) cout << low << endl; n   if (!flag) cout <<  Impossible  << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n long long n, x, y, nr; n long long cx, cy; n int ans[2000002]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> x >> y; n   int xx = 0; n   while (xx <= x + y) { n     long long pa = (cx + 1) * y; n     long long pb = (cy + 1) * x; n     if (pa == pb) n       ++cx, ++cy, xx += 2; n     else if (pa < pb) n       ans[xx] = 1, ++cx, ++xx; n     else n       ans[xx] = 2, ++cy, ++xx; n   } n   for (int i = 1; i <= n; ++i) { n     cin >> nr; n     --nr; n     nr %= (x + y); n     if (ans[nr] == 1) cout <<  Vanya  <<   n ; n     if (ans[nr] == 2) cout <<  Vova  <<   n ; n     if (ans[nr] == 0) cout <<  Both  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n const int MAX = 1e9 + 5; n int i, j, w1, w2, k, n, m, a[N], b[N], calca[N], calcb[N], temp; n vector<pair<int, int> > ans, adasd; n bool ctr(int s) { n   int set = 0; n   int p1 = 0; n   int p2 = 0; n   int last1 = 0; n   int last2 = 0; n   int lastt = 0; n   while (1) { n     if (w1 == last1 && w2 == last2) n       if (((p1 > p2 && lastt == 1) || (p2 > p1 && lastt == 2)) && p1 != p2) { n         temp = max(p1, p2); n         return true; n       } else n         return false; n     if (last2 + s <= w2 && b[last2 + s] < a[last1 + s]) { n       p2++; n       lastt = 2; n       last2 += s; n       last1 = lower_bound(a + 1, a + w1 + 1, b[last2]) - a - 1; n     } else if (last1 + s <= w1 && a[last1 + s] < b[last2 + s]) { n       p1++; n       lastt = 1; n       last1 += s; n       last2 = lower_bound(b + 1, b + w2 + 1, a[last1]) - b - 1; n     } else n       return false; n   } n } n int main() { n   cin >> n; n   int asdasdasda; n   for (int i = 1; i <= 200001; i++) a[i] = b[i] = 100000000; n   int x; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     if (x == 1) n       a[++w1] = i; n     else n       b[++w2] = i; n   } n   for (int i = 1; i <= n; i++) n     if (ctr(i)) ans.push_back(make_pair(temp, i)); n   sort(ans.begin(), ans.end()); n   cout << ans.size() <<   n ; n   for (int i = 0; i <= (int)ans.size() - 1; i++) n     cout << ans[i].first <<     << ans[i].second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, j, k, l, maxx, minn, c = 1, c2 = 0, cnt = 0, a1 = 0, a2 = 0; n   cin >> n; n   long long a[n], b[n]; n   cnt = n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   maxx = b[n - 1]; n   minn = b[0]; n   for (i = 0; i < n; i++) { n     if (a[i] == a[i + 1]) n       ++c; n     else { n       a1 = a1 + ((c - 1) * c) / 2; n       c = 1; n     } n   } n   a1 = a1 + ((c - 1) * c) / 2; n   cnt = cnt + a1; n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int q[N]; n int n; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> q[i]; n   if (n & 1) { n     cout <<  YES  <<   n ; n     cout << n - 1 <<   n ; n     for (int i = 1; i < n; i += 2) { n       cout << i <<     << i + 1 <<     << i + 2 <<   n ; n     } n     for (int i = 1; i < n; i += 2) { n       cout << i <<     << i + 1 <<     << n <<   n ; n     } n   } else { n     int tmp = 0; n     for (int i = 1; i <= n; i++) tmp ^= q[i]; n     if (tmp != 0) { n       cout <<  NO  <<   n ; n     } else { n       cout <<  YES  <<   n ; n       cout << n - 2 <<   n ; n       for (int i = 1; i < n - 1; i += 2) { n         cout << i <<     << i + 1 <<     << i + 2 <<   n ; n       } n       for (int i = 1; i < n - 1; i += 2) { n         cout << i <<     << i + 1 <<     << n - 1 <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool mayorigual(const string &s, int i, int ifin, int j, int jfin) { n   if (ifin - i > jfin - j) return true; n   if (ifin - i < jfin - j) return false; n   int len = ifin - i; n   for (int k = 0; k < len; k++) { n     if (s[k + i] > s[k + j]) n       return true; n     else if (s[k + i] < s[k + j]) n       return false; n   } n   return true; n } n int main() { n   int ret = 0; n   string s; n   cin >> s; n   int j = s.size(); n   int i = j - 1; n   while (i >= 0 && j > 0) { n     if (s[i] ==  0 ) n       i--; n     else if (mayorigual(s, 0, i, i, j)) { n       ret++; n       j = i; n       i = j - 1; n     } else { n       ret++; n       break; n     } n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 131072, P = 998244353, inv2 = (P + 1) / 2; n int n, m, ans, a[maxn], b[maxn], fact[maxn], finv[maxn]; n int lim, l, r[maxn], w[maxn]; n vector<int> V; n vector<int> f[maxn << 2][2][2]; n int qp(int x, int y) { n   int z = 1; n   for (; y; y >>= 1, x = 1LL * x * x % P) { n     if (y & 1) z = 1LL * z * x % P; n   } n   return z; n } n void init() { n   for (int i = 0; i < lim; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1)); n   w[lim >> 1] = 1; n   int t = qp(3, (P - 1) / lim); n   for (int i = (lim >> 1) + 1; i < lim; i++) w[i] = 1LL * t * w[i - 1] % P; n   for (int i = (lim >> 1) - 1; i > 0; i--) w[i] = w[i << 1]; n } n void DFT(int *a, int type) { n   static unsigned long long c[maxn]; n   copy(a, a + lim, c); n   for (int i = 0; i < lim; i++) n     if (i < r[i]) swap(c[i], c[r[i]]); n   for (int i = 1; i < lim; i <<= 1) { n     for (int j = 0; j < lim; j += i << 1) { n       for (int k = 0; k < i; k++) { n         unsigned long long t = c[i + j + k] * w[i + k] % P; n         c[i + j + k] = c[j + k] + P - t, c[j + k] += t; n       } n     } n   } n   if (!~type) { n     reverse(c + 1, c + lim); n     for (int i = 0, t = qp(lim, P - 2); i < lim; i++) c[i] = c[i] % P * t % P; n   } n   for (int i = 0; i < lim; i++) a[i] = c[i] % P; n } n vector<int> operator*(vector<int> A, vector<int> B) { n   int len = A.size() + B.size() - 1; n   for (lim = 1, l = 0; lim < len; lim <<= 1) l++; n   A.resize(lim), B.resize(lim); n   init(), DFT(A.data(), 1), DFT(B.data(), 1); n   for (int i = 0; i < lim; i++) A[i] = 1LL * A[i] * B[i] % P; n   DFT(A.data(), -1), A.resize(len); n   return A; n } n int main() { n   scanf( %d , &n); n   for (int i = fact[0] = finv[0] = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     fact[i] = 1LL * i * fact[i - 1] % P; n     finv[i] = qp(fact[i], P - 2); n   } n   for (int i = 1; i <= n; i += a[i]) { n     b[++m] = a[i]; n     for (int j = i; j < i + a[i]; j++) { n       if (a[i] ^ a[j]) puts( 0 ), exit(0); n     } n   } n   function<void(int, int, int)> solve = [&](int k, int l, int r) { n     if (l == r) { n       f[k][0][0] = {0, b[l] == 1 ? inv2 : 1}; n       f[k][0][1] = f[k][1][0] = f[k][1][1] = {0, 1}; n       return; n     } n     int mid = (l + r) / 2, ls = k << 1, rs = k << 1 | 1; n     solve(ls, l, mid), solve(rs, mid + 1, r); n     for (int p : {0, 1}) n       for (int q : {0, 1}) { n         f[k][p][q].resize(r - l + 2); n       } n     for (int a : {0, 1}) n       for (int b : {0, 1}) n         for (int c : {0, 1}) { n           vector<int> g = f[ls][a][b] * f[rs][b][c]; n           for (int i = b; i < g.size(); i++) (f[k][a][c][i - b] += g[i]) %= P; n         } n   }; n   solve(1, 1, m); n   for (int i = 1; i <= m; i++) { n     ans = (ans + 1LL * fact[i] * f[1][0][0][i] % P * qp(2, i) % P * n                      ((m - i) & 1 ? P - 1 : 1)) % n           P; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int arr[200005]; n int brr[200005]; n priority_queue<int, vector<int>, greater<int> > q; n stack<int> s; n int vis[200005]; n int main() { n   while (cin >> n >> k) { n     while (!q.empty()) q.pop(); n     while (!s.empty()) s.pop(); n     memset(vis, 0, sizeof(vis)); n     int kmax = 0; n     for (int i = 0; i < k; i++) { n       scanf( %d , &arr[i]); n       vis[arr[i]] = 1; n       kmax = max(kmax, arr[i]); n     } n     for (int i = 1; i <= kmax; i++) { n       if (vis[i] == 0) { n         q.push(i); n       } n     } n     int indexb = 0; n     for (int i = 0; i < k; i++) { n       if (s.empty()) { n         s.push(arr[i]); n       } else if (arr[i] > s.top()) { n         while (!s.empty() && arr[i] > s.top()) { n           brr[indexb++] = s.top(); n           s.pop(); n         } n         s.push(arr[i]); n       } else { n         s.push(arr[i]); n       } n     } n     bool flag = true; n     for (int i = 0; i < indexb; i++) { n       if (brr[i] != i + 1) flag = false; n     } n     if (flag == false) { n       cout << -1 << endl; n       continue; n     } n     stack<int> choosing; n     for (int i = 0; i < k; i++) printf( %d%c , arr[i], i == k - 1 ?     :    ); n     int cnt = 0; n     while (!s.empty()) { n       while (!q.empty() && q.top() < s.top()) { n         choosing.push(q.top()); n         q.pop(); n       } n       s.pop(); n       while (!choosing.empty()) { n         printf( %d , choosing.top()); n         cnt++; n         if (cnt == kmax - k && kmax == n) n           printf(  n ); n         else n           printf(   ); n         choosing.pop(); n       } n     } n     for (int i = n; i >= kmax + 1; i--) { n       printf( %d%c , i, i == kmax + 1 ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[50]; n int main() { n   int n; n   cin >> f[0] >> f[1] >> n; n   for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2]; n   cout << f[n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n char zh[125], ch, sw; n int n, m; n int main() { n   cin >> n >> m >> s; n   for (int i = 97; i <= 122; i += 1) { n     zh[i] = i; n   } n   for (int i = 1; i <= m; i += 1) { n     cin >> ch >> sw; n     for (int j = 97; j <= 122; j += 1) { n       if (zh[j] == ch) { n         zh[j] = sw; n       } else { n         if (zh[j] == sw) { n           zh[j] = ch; n         } n       } n     } n   } n   for (int i = 0; i <= n - 1; i += 1) { n     cout << zh[s[i]]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, res, dpa[4005][4005], s[4005], c[4005][4005]; n long long combo(long long x, long long y) { n   if (c[x][y] != 0) return c[x][y]; n   if (y == 0 || x == y) return c[x][y] = 1; n   if (x == 0 || x < y) return 0; n   return c[x][y] = (combo(x - 1, y - 1) + combo(x - 1, y)) % 1000000007; n } n int main() { n   cin >> n; n   dpa[0][0] = s[0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       dpa[i][j] = dpa[i - 1][j - 1] + dpa[i - 1][j] * j; n       dpa[i][j] %= 1000000007; n       s[i] += dpa[i][j]; n       s[i] %= 1000000007; n     } n   } n   for (int i = 0; i < n; i++) { n     res += combo(n, n - i) * s[i]; n     res %= 1000000007; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<string, long long> > Name(1010); n long long n; n vector<vector<pair<string, long long> > > a(1010); n map<string, long long> already; n map<string, long long>::iterator ii; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   long long i, j; n   for (i = 1; i <= n; i++) { n     string w; n     long long version; n     cin >> w >> version; n     if (i == 1) { n       already[w] = version; n     } n     Name[i] = make_pair(w, version); n     long long m; n     cin >> m; n     for (j = 0; j < m; j++) { n       cin >> w >> version; n       a[i].push_back(make_pair(w, version)); n     } n   } n   vector<pair<string, long long> > q; n   map<string, long long> pretendent; n   q.push_back(Name[1]); n   while (q.size() > 0) { n     long long qs = 0, qf = q.size(); n     vector<pair<string, long long> > temp; n     temp.clear(); n     pretendent.clear(); n     while (qs < qf) { n       long long cur; n       for (i = 1; i <= n; i++) { n         if (Name[i].first == q[qs].first && Name[i].second == q[qs].second) n           cur = i; n       } n       for (i = 0; i < a[cur].size(); i++) { n         string task = a[cur][i].first; n         long long version = a[cur][i].second; n         if (already[task] == 0) n           pretendent[task] = max(pretendent[task], version); n       } n       qs++; n     } n     q.clear(); n     for (ii = pretendent.begin(); ii != pretendent.end(); ii++) { n       string task = ii->first; n       long long version = ii->second; n       already[task] = version; n       q.push_back(make_pair(task, version)); n     } n   } n   if (already[Name[1].first] == Name[1].second) already.erase(Name[1].first); n   cout << already.size() << endl; n   for (ii = already.begin(); ii != already.end(); ii++) { n     cout << ii->first <<     << ii->second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int dat[100000 + 10]; n int vis[100000 + 10]; n int dfs(int x) { n   vis[x] = 1; n   if (vis[dat[x]] == 0) return dfs(dat[x]) + 1; n   return 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> dat[i + 1]; n   } n   vector<long long> g; n   for (int i = 1; i <= n; i++) { n     if (vis[i] == 0) { n       g.push_back(dfs(i)); n     } n   } n   sort(g.begin(), g.end()); n   reverse(g.begin(), g.end()); n   if (g.size() == 0) { n     cout <<  0  << endl; n   } else if (g.size() == 1) { n     cout << g[0] * g[0] << endl; n   } else { n     long long total = (g[0] + g[1]) * (g[0] + g[1]); n     for (int i = 2; i < g.size(); i++) { n       total += g[i] * g[i]; n     } n     cout << total << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxx = (int)1e7; n long long SOD(long long n) { n   long long ans = 0; n   while (n) { n     ans += (n % 10); n     n /= 10; n   } n   return ans; n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     vector<int> num; n     long long n, s, nnn; n     cin >> n >> s; n     nnn = n; n     if (SOD(n) <= s) { n       cout << 0 << endl; n       continue; n     } n     while (n) { n       num.push_back(n % 10); n       n /= 10; n     } n     reverse(num.begin(), num.end()); n     int sum = 0; n     int start = 0; n     for (int i = 0; i < num.size(); i++) { n       sum += num[i]; n       if (sum >= s) { n         if (i != 0 && num[i - 1] != 9) { n           num[i - 1]++; n           start = i; n           break; n         } n         if (i == 0) { n           num.insert(num.begin(), 1); n           start = 1; n           break; n         } else if (num[i - 1] == 9) { n           while (i != 0 && num[i - 1] == 9) { n             i--; n           } n           i--; n         } n       } n     } n     for (int i = start; i < num.size(); i++) { n       num[i] = 0; n     } n     int p = num.size() - 1; n     long long nn = 0; n     for (int i = 0; i < num.size(); i++) { n       nn += num[i] * round(pow(10, p)); n       p--; n     } n     cout << (nn - nnn) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 100100; n int n, m, k; n int a[mx]; n int pos[mx]; n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> m >> k; n   long long ans = 0; n   for (int i = 1; i <= k; i++) { n     cin >> a[i]; n     pos[a[i]] = i; n   } n   while (n--) { n     for (int i = 0, x; i < m; i++) { n       cin >> x; n       ans += pos[x]; n       for (int j = pos[x]; j > 1; j--) { n         swap(a[j], a[j - 1]); n         pos[a[j]]++; n       } n       pos[x] = 1; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, t; n   cin >> n >> t; n   long long int i, a, c, ans, k = 0, f = 0; n   for (i = 0; i < n; i++) { n     cin >> a; n     c = 86400 - a; n     if (a == 0) { n       c = 86400; n     } n     k += c; n     if (k >= t && f == 0) { n       ans = i + 1; n       f = 100; n     } n   } n   if (n == 1) { n     cout << 1 << endl; n     return 0; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e6; n int st[MX * 4], la[MX * 4], tin[MX], tout[MX], t, n; n vector<int> chd[MX]; n void dfs(int u) { n   tin[u] = ++t; n   for (auto c : chd[u]) { n     dfs(c); n   } n   tout[u] = t; n } n void push(int v) { n   st[v * 2] += la[v]; n   la[v * 2] += la[v]; n   st[v * 2 + 1] += la[v]; n   la[v * 2 + 1] += la[v]; n   la[v] = 0; n } n void upd(int a, int b, int val, int v = 1, int l = 1, int r = n) { n   if (b < l || r < a) return; n   if (a <= l && r <= b) { n     st[v] += val; n     la[v] += val; n   } else { n     push(v); n     int m = (l + r) / 2; n     upd(a, b, val, v * 2, l, m); n     upd(a, b, val, v * 2 + 1, m + 1, r); n     st[v] = max(st[v * 2], st[v * 2 + 1]); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int k; n   cin >> n >> k; n   vector<pair<int, int>> stk; n   for (int i = 0; i < n; ++i) { n     int a; n     cin >> a; n     while (!stk.empty() && stk.back().first < a) { n       chd[i].push_back(stk.back().second); n       stk.pop_back(); n     } n     stk.emplace_back(a, i); n   } n   for (auto [a, i] : stk) { n     dfs(i); n   } n   for (int i = 0; i < n; ++i) { n     upd(tin[i], tout[i], 1); n     if (i >= k - 1) { n       if (i >= k) { n         upd(tin[i - k], tout[i - k], -1); n       } n       cout << st[1] <<    ; n     } n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int maxPrime[10000005]; n long long cnt_prime[10000005]; n int primes[10000005]; n int cnt_p; n void init() { n   for (int i = 2; i < 10000005; i += 2) maxPrime[i] = 2; n   for (int i = 3; i * i < 10000005; i += 2) { n     if (maxPrime[i] == i || maxPrime[i] == 0) { n       maxPrime[i] = i; n       for (int j = i * 2; j < 10000005; j += i) { n         maxPrime[j] = i; n       } n     } n   } n   for (int i = 2; i < 10000005; i++) { n     if (maxPrime[i] == 0) maxPrime[i] = i; n     if (maxPrime[i] == i) { n       primes[cnt_p++] = i; n     } n   } n } n bool good(long long x) { n   for (int i = 0; i < cnt_p; i++) { n     long long temp = x; n     long long res = 0; n     while (temp) { n       temp /= primes[i]; n       res += temp; n     } n     if (res < cnt_prime[primes[i]]) return false; n   } n   return true; n } n int main() { n   long long sum = 0; n   int n; n   int maxx = 0; n   init(); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int a; n     scanf( %d , &a); n     maxx = max(maxx, a); n     sum += a; n     cnt_prime[a]++; n   } n   for (int i = maxx; i >= 2; i--) { n     cnt_prime[i] += cnt_prime[i + 1]; n   } n   for (int i = maxx; i >= 2; i--) { n     cnt_prime[i / maxPrime[i]] += cnt_prime[i]; n     if (maxPrime[i] != i) { n       cnt_prime[maxPrime[i]] += cnt_prime[i]; n     } n   } n   long long left = maxx, right = sum; n   while (left <= right) { n     long long mid = (left + right) / 2; n     if (good(mid)) { n       right = mid - 1; n     } else { n       left = mid + 1; n     } n   } n   cout << left << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long DP[1000000]; n long long counter[1000000]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     counter[x]++; n   } n   DP[0] = 0; n   DP[1] = counter[1]; n   for (int i = 0; i < 1000000; i++) { n     DP[i] = max(DP[i - 1], DP[i - 2] + counter[i] * i); n   } n   cout << DP[1000000 - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n const long long maxn = 100; n long long mas[maxn], mas2[maxn]; n vector<pair<long long, long long> > cur; n vector<pair<long long, long long> > ans[maxn]; n void split(long long n) { n   cur.clear(); n   long long a, b; n   a = 1, b = 1; n   for (long long i = 2; i <= n; i++) { n     if (mas[i] == mas[i - 1] + 1) { n       b = i; n     } else { n       cur.push_back({a, b}); n       a = i, b = i; n     } n   } n   cur.push_back({a, b}); n } n signed main() { n   fast(); n   long long n, i, j, p, k, a, b; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> mas[i]; n   } n   long long x; n   p = 0; n   while (true) { n     split(n); n     long long sz = cur.size(); n     if (sz == 1) { n       break; n     } n     p++; n     x = mas[n]; n     if (x == n) { n       x = mas[cur[sz - 2].second]; n       for (i = 1; i <= n; i++) { n         if (mas[i] == x + 1) { n           if (i != 1) { n             ans[p].push_back({1, i - 1}); n           } n           ans[p].push_back({i, cur[sz - 2].first - 1}); n           ans[p].push_back(cur[sz - 2]); n           ans[p].push_back(cur[sz - 1]); n           k = 1; n           for (j = cur[sz - 1].first; j <= cur[sz - 1].second; j++) { n             mas2[k] = mas[j]; n             k++; n           } n           for (j = cur[sz - 2].first; j <= cur[sz - 2].second; j++) { n             mas2[k] = mas[j]; n             k++; n           } n           for (j = i; j <= cur[sz - 2].first - 1; j++) { n             mas2[k] = mas[j]; n             k++; n           } n           if (i != 1) { n             for (j = 1; j <= i - 1; j++) { n               mas2[k] = mas[j]; n               k++; n             } n           } n           for (k = 1; k <= n; k++) { n             mas[k] = mas2[k]; n           } n           break; n         } n       } n     } else { n       for (i = 1; i <= n; i++) { n         if (mas[i] == x + 1) { n           if (i != 1) { n             ans[p].push_back({1, i - 1}); n           } n           ans[p].push_back({i, cur[sz - 1].first - 1}); n           ans[p].push_back(cur[sz - 1]); n           k = 1; n           for (j = cur[sz - 1].first; j <= cur[sz - 1].second; j++) { n             mas2[k] = mas[j]; n             k++; n           } n           for (j = i; j <= cur[sz - 1].first - 1; j++) { n             mas2[k] = mas[j]; n             k++; n           } n           if (i != 1) { n             for (j = 1; j <= i - 1; j++) { n               mas2[k] = mas[j]; n               k++; n             } n           } n           for (k = 1; k <= n; k++) { n             mas[k] = mas2[k]; n           } n           break; n         } n       } n     } n   } n   cout << p << endl; n   for (i = 1; i <= p; i++) { n     cout << ans[i].size() <<    ; n     for (j = 0; j < ans[i].size(); j++) { n       cout << ans[i][j].second - ans[i][j].first + 1 <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _fill_int(int* p, int val, int rep) { n   int i; n   for (i = 0; i < rep; i++) p[i] = val; n } n signed long long GETi() { n   signed long long i; n   scanf( %lld , &i); n   return i; n } n int N, A[100001]; n void solve() { n   int f, i, j, k, l, x, y; n   cin >> N; n   for (i = 0; i < N; i++) cin >> A[i]; n   sort(A, A + N); n   if (N == 1) return (void)printf( -1 n ); n   if (A[0] == A[N - 1]) return (void)printf( 1 n%d n , A[0]); n   if (N == 2 && (A[1] - A[0]) % 2 == 0) n     return (void)printf( 3 n%d %d %d n , A[0] - (A[1] - A[0]), n                         A[0] + (A[1] - A[0]) / 2, A[1] + (A[1] - A[0])); n   int mi = A[1] - A[0]; n   for (i = 0; i < N - 1; i++) mi = min(mi, A[i + 1] - A[i]); n   x = -1; n   for (i = 0; i < N - 1; i++) { n     if (A[i + 1] - A[i] == mi) n       continue; n     else if (A[i + 1] - A[i] == 2 * mi && x == -1) n       x = i; n     else n       return (void)printf( 0 n ); n   } n   if (x == -1) n     (void)printf( 2 n%d %d n , A[0] - mi, A[N - 1] + mi); n   else n     (void)printf( 1 n%d n , A[x] + mi); n } n int main(int argc, char** argv) { n   string s; n   if (argc == 1) ios::sync_with_stdio(false); n   for (int i = 1; i < argc; i++) s += argv[i], s +=   n ; n   for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> g; n vector<int> vis, d; n void dfs(int v, int c) { n   d[v] = c; n   vis[v] = true; n   for (int u : g[v]) { n     if (!vis[u]) dfs(u, c + 1); n   } n } n void solve() { n   int n, m; n   cin >> n >> m; n   g.resize(n + 1, vector<int>()); n   vis.resize(n + 1, false); n   d.resize(n + 1, -1); n   while (m--) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   dfs(1, 0); n   int u = max_element(d.begin(), d.end()) - d.begin(); n   vis.clear(); n   vis.resize(n + 1, false); n   dfs(u, 0); n   cout << (*max_element(d.begin(), d.end())) <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int T = 1; n   while (T--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000 ) n using namespace std; n int n, m; n pair<int, pair<int, int> > a[100010]; n pair<int, int> g[100010]; n int r[100010]; n void solve() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a[i].first >> a[i].second.first; n     a[i].second.first *= -1; n     a[i].second.second = i; n   } n   for (int i = 0; i < n; i++) r[i] = i + 1; n   sort(a, a + m); n   int cur = 0; n   int lst = 0; n   for (int i = 0; i < m; i++) { n     if (a[i].second.first == -1) { n       cur = 1; n       lst++; n       g[a[i].second.second] = pair<int, int>(0, lst); n     } else { n       while (cur < lst && r[cur] > lst) cur++; n       if (cur >= lst) { n         cout << -1; n         return; n       } n       g[a[i].second.second] = pair<int, int>(cur, r[cur]); n       r[cur]++; n     } n   } n   for (int i = 0; i < m; i++) { n     cout << g[i].first + 1 <<     << g[i].second + 1 << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   srand(88); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n  n #define endl   n  n #define fi first n #define se second n #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) n #define forn(i,n) for (int i = 0; i < int(n); i++) n #define forr(i,a,b) for (int i = a; i <= b; i++) n #define all(v) v.begin(), v.end() n #define pb push_back n  n using namespace std; n  n typedef long long ll; n typedef long double ld; n typedef pair<int, int> ii; n typedef vector<int> vi; n typedef vector<vi> vvi; n typedef vector<ii> vii; n  n const int MX = 405, mod = 998244353; n int n, c[26]; n ll dp[2][MX][MX][2][2][2][2], res; n  n int main () { n  ios_base::sync_with_stdio(0); cin.tie(0); n   n  cin >> n; n  forn (i, 26) n   cin >> c[i]; n   n  int x = 0, y = 1 - x; n   n  forn (a, 2) forn (b, 2) forn (c, 2) forn (d, 2) n   dp[x][n + 1][n + 1][a][b][c][d] = 1;  n    n  for (int t = n - 1; t >= 0; t--) { n   forn (i, n + 2) forn (j, n + 2) forn (a, 2) forn (b, 2) forn (c, 2) forn (d, 2) { n    ll &res = dp[y][i][j][a][b][c][d]; n    res = (24 - (!a && !c && t >= 2)) * dp[x][i][j][b][0][d][0]; n     n    if (!a) n     res += dp[x][i == n + 1 ? i : i + 1][j][b][1][d][0]; n     n    if (!c) n     res += dp[x][i][j == n + 1 ? j : j + 1][b][0][d][1]; n     n    res %= mod; n   } n    n   swap(x, y); n  } n   n  res = dp[x][n + 1][n + 1][0][0][0][0]; n   n  forn (i, 26) n   res -= dp[x][n - c[i]][n + 1][0][0][0][0]; n   n  forn (i, 26) forn (j, i) n   res += dp[x][n - c[i]][n - c[j]][0][0][0][0]; n   n  cout << MOD(res, mod) << endl; n    n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long l; n long long calc(long long a, long long b, long long c) { n   long long sum = b + c; n   long long t = max(a, sum); n   long long ret = 0; n   while (t - a + sum - (b + c) <= l) { n     long long rem = l - (t - a + sum - (b + c)); n     ret += (rem + 1) * (sum - (b + c) + 1); n     sum++; n     t = max(a, sum); n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long a, b, c; n   cin >> a >> b >> c >> l; n   long long ans = 0; n   for (int i = 0; i <= l; i++) ans += (i + 2) * 1ll * (i + 1) / 2; n   ans -= calc(a, b, c); n   ans -= calc(b, a, c); n   ans -= calc(c, a, b); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   string s1; n   cin >> s >> s1; n   map<char, int> m; n   m.insert(make_pair( a , 1)); n   m.insert(make_pair( b , 2)); n   m.insert(make_pair( c , 3)); n   m.insert(make_pair( d , 4)); n   m.insert(make_pair( e , 5)); n   m.insert(make_pair( f , 6)); n   m.insert(make_pair( g , 7)); n   m.insert(make_pair( h , 8)); n   m.insert(make_pair( i , 9)); n   m.insert(make_pair( j , 10)); n   m.insert(make_pair( k , 11)); n   m.insert(make_pair( l , 12)); n   m.insert(make_pair( m , 13)); n   m.insert(make_pair( n , 14)); n   m.insert(make_pair( o , 15)); n   m.insert(make_pair( p , 16)); n   m.insert(make_pair( q , 17)); n   m.insert(make_pair( r , 18)); n   m.insert(make_pair( s , 19)); n   m.insert(make_pair( t , 20)); n   m.insert(make_pair( u , 21)); n   m.insert(make_pair( v , 22)); n   m.insert(make_pair( w , 23)); n   m.insert(make_pair( x , 24)); n   m.insert(make_pair( y , 25)); n   m.insert(make_pair( z , 26)); n   int cnt1[27]; n   memset(cnt1, 0, sizeof(cnt1)); n   for (int i = 0; i < s.length(); i++) { n     cnt1[m.find(s[i])->second]++; n   } n   int count1 = 0; n   int cnt2[27]; n   memset(cnt2, 0, sizeof(cnt2)); n   for (int i = 0; i < s1.length(); i++) { n     if (cnt1[m.find(s1[i])->second] == 0) { n       cout << -1 << endl; n       return 0; n     } n     cnt2[m.find(s1[i])->second]++; n   } n   for (int i = 1; i <= 26; i++) { n     if (cnt2[i] > cnt1[i]) n       count1 += cnt1[i]; n     else if (cnt2[i] <= cnt1[i]) n       count1 += cnt2[i]; n   } n   cout << count1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const long double EPS = 1e-11; n const long long INFL = 1e16; n const int INF = 2e9 + 7; n mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count()); n void add(long long& a, long long b) { n   a += b; n   while (a >= MOD) { n     a -= MOD; n   } n } n void sub(long long& a, long long b) { add(a, MOD - b); } n void mul(long long& a, long long b) { a = (a * b) % MOD; } n long long todeg(long long x, long long d) { n   if (d < 0) { n     d += MOD - 1; n   } n   if (d == 0) { n     return 1; n   } n   long long ans = todeg(x, d / 2); n   mul(ans, ans); n   if (d % 2 == 1) { n     mul(ans, x); n   } n   return ans; n } n vector<long long> fact, rfact; n void prep(long long high) { n   fact.assign(high + 1, 1); n   rfact.resize(high + 1); n   for (int i = 1; i <= high; ++i) { n     fact[i] = i; n     mul(fact[i], fact[i - 1]); n   } n   rfact[high] = todeg(fact[high], -1); n   for (int i = high; i > 0; --i) { n     rfact[i - 1] = rfact[i]; n     mul(rfact[i - 1], i); n   } n } n long long C(int n, int k) { n   long long ans = fact[n]; n   mul(ans, rfact[k]); n   mul(ans, rfact[n - k]); n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long n, k; n   cin >> n >> k; n   prep(n + 5); n   vector<long long> sposs(n, 1); n   for (int i = 1; i < n; ++i) { n     if (i <= k) { n       sposs[i] = fact[i]; n       continue; n     } n     sposs[i] = sposs[i - 1]; n     mul(sposs[i], i); n     long long del = sposs[i - k - 1]; n     mul(del, fact[i - 1]); n     mul(del, rfact[i - k - 1]); n     sub(sposs[i], del); n   } n   long long ans = fact[n]; n   for (int i = 0; i < n; ++i) { n     long long cv = C(n - 1, i); n     mul(cv, sposs[i]); n     mul(cv, fact[n - i - 1]); n     sub(ans, cv); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long rev_6 = 166666668ll; n const long long rev_2 = 500000004ll; n const long long MOD = 1000000007ll; n long long pow(long long A, long long n) { n   long long r = 1ll; n   while (n) { n     if (n & 1ll) r = r * A % MOD; n     A = A * A % MOD; n     n >>= 1; n   } n   return r; n } n int main() { n   bool odd = true, one = true; n   int k; n   long long ans = 2, temp; n   cin >> k; n   while (k--) { n     cin >> temp; n     if (temp > 1ll) one = false; n     if (temp % 2ll == 0ll) odd = false; n     ans = pow(ans, temp); n   } n   if (one) n     cout <<  0/1 n ; n   else { n     long long q = ans * rev_2 % MOD; n     if (odd) n       ans -= 2; n     else n       ans += 2; n     if (ans < 0) ans += MOD; n     ans = ans * rev_6 % MOD; n     cout << ans <<  /  << q << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 998244353; n const int M = 1e6 + 10; n const int N = 3e5 + 10; n inline long long read() { n   long long b = 1, sum = 0; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) b = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     sum = sum * 10 + c -  0 ; n     c = getchar(); n   } n   return b * sum; n } n long long T, n, m; n int main() { n   int i, j, k; n   T = read(); n   while (T--) { n     bool f = 0; n     n = read(); n     long long x = 1, sum = 1; n     vector<long long> ans; n     while (1) { n       if (n - sum >= 4 * x) { n         ans.push_back(x); n         x *= 2; n         sum += x; n       } else if (n - sum >= 3 * x) { n         int x1 = n - sum - 2 * x; n         x1 = x1 / 2; n         int x2 = n - sum - 2 * x - 2 * x1; n         ans.push_back(x1); n         ans.push_back(x2); n         break; n       } else if (n - sum > 2 * x) { n         ans.push_back(0); n         ans.push_back(n - sum - 2 * x); n         break; n       } else if (n - sum >= x) { n         ans.push_back(n - sum - x); n         break; n       } else { n         f = 1; n         break; n       } n     } n     if (f) { n       printf( -1 n ); n       continue; n     } n     printf( %d n , ans.size()); n     for (i = 0; i < ans.size(); i++) { n       printf( %lld  , ans[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 5; n const int MAXT = 2e5 + 10; n long long a[MAXN]; n long long cnt[MAXN]; n long long ans[MAXT]; n int L, R; n long long res; n struct node { n   int l, r, bid, id; n   bool operator<(const node &other) const { n     if (other.bid == bid) return r < other.r; n     return bid < other.bid; n   } n } q[MAXT]; n void query(int l, int r, int is) { n   if (is) { n     for (int i = l; i < L; i++) { n       res += ((cnt[a[i]] << 1) + 1) * a[i]; n       cnt[a[i]]++; n     } n     for (int i = L; i < l; i++) { n       cnt[a[i]]--; n       res -= ((cnt[a[i]] << 1) + 1) * a[i]; n     } n     for (int i = R + 1; i <= r; i++) { n       res += ((cnt[a[i]] << 1) + 1) * a[i]; n       cnt[a[i]]++; n     } n     for (int i = r + 1; i <= R; i++) { n       cnt[a[i]]--; n       res -= ((cnt[a[i]] << 1) + 1) * a[i]; n     } n   } else { n     for (int i = l; i <= r; i++) { n       res += ((cnt[a[i]] << 1) + 1) * a[i]; n       cnt[a[i]]++; n     } n   } n   L = l; n   R = r; n   ans[q[is].id] = res; n } n int main() { n   int n, t; n   scanf( %d%d , &n, &t); n   int bsize = sqrt(n + 1); n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   for (int i = 0; i < t; i++) { n     scanf( %I64d%I64d , &q[i].l, &q[i].r); n     q[i].bid = q[i].l / bsize; n     q[i].id = i; n   } n   sort(q, q + t); n   for (int i = 0; i < t; i++) query(q[i].l, q[i].r, i); n   for (int i = 0; i < t; i++) printf( %I64d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double E = 2.71828182845904523536; n const long double pi = acos(-1); n const double eps = 1e-9; n const long long mod = 1e9 + 7; n const long long inf = 1LL << 30; n long long a[400], b[400], n, x; n map<long long, long long> mem[301]; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long dp(int i, long long g) { n   if (g == 1) return 0; n   if (i >= n) return inf; n   if (g == 0) return min(dp(i + 1, a[i]) + b[i], dp(i + 1, 0)); n   long long &ret = mem[i][g]; n   if (ret != 0) return ret; n   long long gc = gcd(a[i], g); n   return ret = min(dp(i + 1, gc) + b[i], dp(i + 1, g)); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   long long ans = dp(0, 0); n   if (ans == inf) n     cout << -1 <<   n ; n   else n     cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[100100]; n char b[100100]; n int na, nb; n int main() { n   cin >> a >> b; n   na = 0; n   nb = 0; n   for (int i = 0; a[i]; i++) n     if (a[i] ==  1 ) na++; n   for (int i = 0; b[i]; i++) n     if (b[i] ==  1 ) nb++; n   if (na % 2) na++; n   if (na >= nb) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n, m, k; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     cin >> n >> m >> k; n     if (m < n - 1 || m > n * (n - 1) / 2) { n       puts( No ); n       continue; n     } n     if (n == 1) { n       if (k > 1) n         puts( Yes ); n       else n         puts( No ); n       continue; n     } n     if (m == n * (n - 1) / 2) { n       if (k > 2) n         puts( Yes ); n       else n         puts( No ); n       continue; n     } n     if (k > 3) n       puts( Yes ); n     else n       puts( No ); n   } n } n


#include <bits/stdc++.h> n uint32_t readu32() { n   int c; n   while ((c = getchar()) <  0 ) n     ; n   uint32_t n = c & 15U; n   while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U); n   return n; n } n uint64_t readu64() { n   int c; n   while ((c = getchar()) <  0 ) n     ; n   uint64_t n = c & 15U; n   while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U); n   return n; n } n int32_t read32() { n   int c; n   while ((c = getchar()) <  - ) n     ; n   bool neg = c ==  - ; n   if (neg) c = getchar(); n   uint32_t n = c & 15U; n   while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U); n   return neg ? -(int32_t)n : n; n } n int64_t read64() { n   int c; n   while ((c = getchar()) <  - ) n     ; n   bool neg = c ==  - ; n   if (neg) c = getchar(); n   uint64_t n = c & 15; n   while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U); n   return neg ? -(int64_t)n : n; n } n using namespace std; n bool v[100005]; n int p[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   int n = readu32(); n   for (int i = 1; i <= n; i++) p[i] = readu32(); n   int hub = 0, two = 0; n   bool hasodd = 0; n   for (int i = 1; i <= n; i++) { n     if (v[i]) continue; n     if (p[i] == i) n       hub = i; n     else if (p[p[i]] == i) n       two = i; n     else { n       int j = i; n       int cl = 0; n       for (;;) { n         v[j] = 1; n         j = p[j]; n         cl++; n         if (j == i) break; n       } n       if (cl & 1) hasodd = true; n     } n   } n   if (!hub && (hasodd || !two)) { n     cout <<  NO ; n     return 0; n   } n   printf( YES n ); n   if (hub) { n     for (int i = 1; i <= n; i++) n       if (i != hub) printf( %d %d n , i, hub); n   } else { n     memset(v, 0, sizeof(v)); n     int par[] = {two, p[two]}; n     v[par[0]] = v[par[1]] = 1; n     printf( %d %d n , par[0], par[1]); n     for (int i = 1; i <= n; i++) { n       if (v[i]) continue; n       int j = i, pa = 0; n       for (;; pa ^= 1) { n         v[j] = 1; n         printf( %d %d n , j, par[pa]); n         j = p[j]; n         if (j == i) break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, dp[300][300]; n long long s; n vector<pair<long long, long long> > v; n long long r, tr; n long long gs(long long a, long long b, long long c) { n   long long s = 0; n   s = (v[b].first - v[a].first) * (v[c].second - v[a].second) - n       (v[b].second - v[a].second) * (v[c].first - v[a].first); n   return s; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     v.push_back(make_pair(a, b)); n   } n   for (int i = 0; i < n; i++) n     s += n         v[(i + 1) % n].first * v[i].second - v[(i + 1) % n].second * v[i].first; n   if (s < 0) reverse(v.begin(), v.end()); n   for (int i = 0; i < n; i++) dp[i][(i + 1) % n] = 1; n   for (int span = 2; span < n; span++) { n     for (int l = 0; l < n; l++) { n       r = l + span; n       r %= n; n       for (int q = l + 1; q < l + span; q++) { n         tr = q % n; n         if (gs(l, r, tr) > 0) n           dp[l][r] = (dp[l][r] + dp[l][tr] * dp[tr][r]) % 1000000007; n       } n     } n   } n   cout << dp[0][n - 1] << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % 998244353; n     y = y / 2; n     if (y != 0) x = (x * x) % 998244353; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t, n, i, j, o, e, ans = 0, num, ans1, ans2, sz, x = 0, chk; n   cin >> n; n   long long a; n   vector<long long> v; n   for (i = 0; i < n; i++) { n     cin >> a; n     v.push_back(a); n   } n   queue<vector<long long> > q; n   q.push(v); n   long long bit = 30; n   while (bit >= 0) { n     sz = q.size(); n     chk = 1ll << bit; n     ans1 = ans2 = 0; n     for (i = 0; i < sz; i++) { n       v = q.front(); n       q.pop(); n       vector<long long> one, zero; n       o = e = 0; n       for (j = 0; j < v.size(); j++) { n         num = v[j]; n         if (num & chk) { n           one.push_back(v[j]); n           o++; n           ans2 += e; n         } else { n           zero.push_back(v[j]); n           e++; n           ans1 += o; n         } n       } n       if (!one.empty()) q.push(one); n       if (!zero.empty()) q.push(zero); n     } n     ans += min(ans1, ans2); n     if (ans1 > ans2) x += chk; n     bit--; n   } n   cout << ans <<     << x <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 100 * 1000 + 10, Max = 17; n int n, m, k, moal[Maxn], st[Maxn], par[Maxn], stt = 1, lca[Max][Maxn], h[Maxn], n                                               cnt; n vector<int> adj[Maxn], ind[Maxn], adj2[Maxn]; n struct edge { n   int u, v; n } e[Maxn]; n bool markE[Maxn], mark[Maxn]; n void dfs3(int v) { n   mark[v] = false; n   for (int i = 0; i < (int)adj2[v].size(); i++) n     if (mark[adj2[v][i]]) { n       lca[0][adj2[v][i]] = v; n       h[adj2[v][i]] = h[v] + 1; n       dfs3(adj2[v][i]); n     } n   return; n } n int dfs(int v) { n   st[v] = stt; n   stt++; n   int ans = INT_MAX, indd; n   for (int i = 0; i < (int)adj[v].size(); i++) { n     if (st[adj[v][i]] == 0) { n       par[adj[v][i]] = v; n       ans = min(ans, dfs(adj[v][i])); n     } else { n       if (adj[v][i] != par[v]) n         ans = min(ans, st[adj[v][i]]); n       else n         indd = i; n     } n   } n   if (v != 0 && ans >= st[v]) markE[ind[v][indd]] = true; n   return ans; n } n void dfs2(int v, int a) { n   mark[v] = true; n   moal[v] = a; n   for (int i = 0; i < (int)adj[v].size(); i++) { n     if (!markE[ind[v][i]] && !mark[adj[v][i]]) dfs2(adj[v][i], a); n   } n   return; n } n void dfsAll() { n   for (int i = 0; i < n; i++) n     if (!mark[i]) { n       dfs2(i, cnt); n       cnt++; n     } n   return; n } n void fillLca() { n   for (int i = 1; i < Max; i++) { n     for (int j = 0; j < cnt; j++) { n       if (lca[i - 1][j] != -1) lca[i][j] = lca[i - 1][lca[i - 1][j]]; n     } n   } n   return; n } n int fath(int a, int b) { n   for (int i = Max - 1; i >= 0; i--) { n     if ((b >> i) & 1) a = lca[i][a]; n   } n   return a; n } n int LCA(int u, int v) { n   if (h[u] > h[v]) swap(u, v); n   v = fath(v, h[v] - h[u]); n   if (v == u) return u; n   for (int i = Max - 1; i >= 0; i--) { n     if (lca[i][u] != lca[i][v]) { n       u = lca[i][u]; n       v = lca[i][v]; n     } n   } n   return lca[0][u]; n } n int main() { n   scanf( %d%d , &n, &m); n   int u, v; n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &u, &v); n     u--; n     v--; n     adj[u].push_back(v); n     ind[u].push_back(i); n     adj[v].push_back(u); n     ind[v].push_back(i); n     e[i].u = u, e[i].v = v; n   } n   int a = dfs(0); n   dfsAll(); n   for (int i = 0; i < m; i++) n     if (markE[i]) { n       adj2[moal[e[i].u]].push_back(moal[e[i].v]); n       adj2[moal[e[i].v]].push_back(moal[e[i].u]); n     } n   for (int i = 0; i < Max; i++) n     for (int j = 0; j < n; j++) lca[i][j] = -1; n   dfs3(0); n   fillLca(); n   scanf( %d , &k); n   for (int i = 0; i < k; i++) { n     scanf( %d%d , &u, &v); n     u--; n     v--; n     int a = LCA(moal[u], moal[v]); n     printf( %d n , h[moal[u]] + h[moal[v]] - 2 * h[a]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l, k, a[200], p[200]; n double memo[200][201][201]; n bool seen[200][201][201]; n double solve(int idx, int kk, int ll) { n   if (kk < 0) { n     return 0; n   } n   if (idx == n) { n     return ll >= l; n   } n   if (seen[idx][kk][ll]) { n     return memo[idx][kk][ll]; n   } n   double prob = p[idx]; n   prob /= 100; n   double ans = solve(idx + 1, kk, ll) * (1 - prob); n   if (a[idx] > 0) { n     ans += solve(idx + 1, min(a[idx] + kk, 200), ll + 1) * prob; n   } n   if (a[idx] == -1 && kk) { n     ans += solve(idx + 1, kk - 1, ll + 1) * prob; n   } n   seen[idx][kk][ll] = 1; n   return memo[idx][kk][ll] = ans; n } n int main() { n   scanf( %d%d%d , &n, &l, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &p[i]); n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (a[i] < a[j]) { n         swap(a[i], a[j]); n         swap(p[i], p[j]); n       } n     } n   } n   printf( %.6lf n , solve(0, k, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   string s; n   cin >> s; n   bool ok = true; n   set<char> vowel; n   vowel.insert( a ); n   vowel.insert( e ); n   vowel.insert( i ); n   vowel.insert( o ); n   vowel.insert( u ); n   for (int i = 0; i < s.size(); i++) { n     char c = s[i]; n     if (!vowel.count(c) && c !=  n ) { n       if (i == s.size() - 1 || !vowel.count(s[i + 1])) { n         ok = false; n       } n     } n   } n   if (ok) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v, v1; n   char a[8][8]; n   for (int i = 0; i < 8; i++) n     for (int j = 0; j < 8; j++) cin >> a[i][j]; n   for (int i = 0; i < 8; i++) n     for (int j = 0; j < 8; j++) { n       if (a[i][j] ==  B ) { n         int b = 0; n         bool t = true; n         for (int k = i + 1; k < 8; k++) { n           b++; n           if (a[k][j] ==  B  || a[k][j] ==  W ) { n             t = false; n             break; n           } n         } n         if (t == true) v.push_back(b); n       } n       if (a[i][j] ==  W ) { n         int z = 0; n         bool t = true; n         for (int k = i - 1; k >= 0; k--) { n           z++; n           if (a[k][j] ==  B  || a[k][j] ==  W ) { n             t = false; n             break; n           } n         } n         if (t == true) { n           v1.push_back(z); n         } n       } n     } n   int m = 999, m1 = 999; n   for (int i = 0; i < v.size(); i++) { n     m = min(m, v[i]); n   } n   for (int i = 0; i < v1.size(); i++) { n     m1 = min(m1, v1[i]); n   } n   if (m >= m1) n     cout <<  A ; n   else n     cout <<  B ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long int LINF = 0x3f3f3f3f3f3f3f3fll; n const long double pi = acos(-1); n const int MOD = 1e9 + 7; n int v[250]; n void calc() { n   double media = 0; n   for (int i = 0; i < 250; i++) media += v[i]; n   media /= 250.0; n   double dp = 0; n   for (int i = 0; i < 250; i++) dp += (v[i] - media) * (v[i] - media); n   dp /= 250.0; n   if (media * 2 > dp) { n     printf( %d n , (int)media); n   } else { n     int x = 0; n     for (int i = 0; i < 250; i++) x = max(x, v[i]); n     printf( %d n , x / 2); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   while (n--) { n     for (int i = 0; i < 250; i++) scanf( %d , &v[i]); n     calc(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct greater { n   template <class T> n   bool operator()(T const &a, T const &b) const { n     return a > b; n   } n }; n unsigned long long subV(unsigned long long a, unsigned long long b, n                         unsigned long long c, unsigned long long l) { n   if (a < b + c) { n     return 0; n   } n   unsigned long long sum = (l + 2) * (l + 1) / 2; n   unsigned long long df = a - b - c; n   if (df >= 0) { n     unsigned long long sub = (df + 2) * (df + 1) / 2; n     return min(sub, sum); n   } n   return 0; n } n int main() { n   int a, b, c, l; n   scanf( %d %d %d %d , &a, &b, &c, &l); n   unsigned long long total = 0; n   for (unsigned long long i = 0; i <= l; i++) { n     total += (i + 2) * (i + 1) / 2; n   } n   for (unsigned long long i = 0; i <= l; i++) { n     total -= subV(a + i, b, c, l - i); n     total -= subV(b + i, a, c, l - i); n     total -= subV(c + i, a, b, l - i); n   } n   printf( %I64d , total); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f, mod = 998244353; n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n const double pi = acosl(-1.), eps = 1e-9; n inline void sum(int &a, int b) { n   a += b; n   if (a >= mod) a -= mod; n } n const int NN = 1000100; n char A[NN], L[NN], R[NN]; n int n, ln, rn, B[NN]; n void zval(const char *s, int len, int *z) { n   z[0] = 0; n   for (int b = 0, i = 1; i < len; i++) { n     z[i] = max(min(z[i - b], z[b] + b - i), 0); n     while (s[i + z[i]] == s[z[i]]) z[i]++; n     if (i + z[i] > b + z[b]) b = i; n   } n   z[0] = len; n } n char zl[NN << 1], zr[NN << 1]; n int zL[NN << 1], zR[NN << 1]; n int main() { n   scanf( %s %s %s , A + 1, L, R); n   n = strlen(A + 1); n   ln = strlen(L); n   rn = strlen(R); n   for (int i = 0; i < ln; i++) zl[i] = L[i]; n   zl[ln] =  * ; n   for (int i = ln + 1; i <= ln + n; i++) zl[i] = A[i - ln]; n   zval(zl, ln + n + 1, zL); n   for (int i = 0; i < rn; i++) zr[i] = R[i]; n   zr[rn] =  * ; n   for (int i = rn + 1; i <= rn + n; i++) zr[i] = A[i - rn]; n   zval(zr, rn + n + 1, zR); n   B[n + 1] = 1; n   for (int i = n, st, ed; i; i--) { n     B[i] = B[i + 1]; n     if (A[i] ==  0 ) { n       if (ln == 1 && L[0] ==  0 ) { n         st = ed = i + 1; n       } else n         continue; n     } else { n       st = i + ln; n       if (st > n + 1) continue; n       int p = zL[ln + i]; n       if (p < ln) { n         if (A[i + p] < L[p]) st++; n       } n       if (st > n + 1) continue; n       ed = i + rn; n       if (ed <= n + 1) { n         p = zR[rn + i]; n         if (p < rn) { n           if (A[i + p] > R[p]) ed--; n         } n       } else n         ed = n + 1; n       if (ed < st) continue; n     } n     int d = B[st] - B[ed + 1]; n     if (d < 0) d += mod; n     sum(B[i], d); n     if (i == 1) { n       cout << d << endl; n       return 0; n     } n   } n   puts( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-8; n const long double PI = 3.1415926535897932384626433832795; n const long double E = 2.7182818284; n const int INF = 1000000000; n const int inf = 100000; n int main(void) { n   int n, m, i, j; n   char c; n   scanf( %d%d , &n, &m); n   char a[n + 2][m + 2]; n   c = getchar(); n   for (int i = 0; i < int(n); i++) { n     for (int j = 0; j < int(m); j++) { n       scanf( %c , &a[i][j]); n     } n     c = getchar(); n   } n   int tab[n + 2][m + 2]; n   for (int i = 0; i < int(n); i++) { n     int t = inf; n     for (int j = 0; j < int(2 * m); j++) { n       if (a[i][j % m] ==  1 ) { n         tab[i][j % m] = 0; n         t = 1; n       } else { n         tab[i][j % m] = t; n         if (t != inf) t++; n       } n     } n   } n   for (int i = 0; i < int(n); i++) { n     int t = inf; n     for (j = 2 * m - 1; j >= 0; j--) { n       if (a[i][j % m] ==  1 ) { n         tab[i][j % m] = 0; n         t = 1; n       } else { n         tab[i][j % m] = min(tab[i][j % m], t); n         if (t != inf) t++; n       } n     } n   } n   int res = -1; n   for (int i = 0; i < int(m); i++) { n     int sum = 0; n     for (int j = 0; j < int(n); j++) { n       if (tab[j][i] == inf) { n         printf( -1 n ); n         return 0; n       } n       sum += tab[j][i]; n     } n     if (sum < res || res == -1) res = sum; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200000 + 5; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long n, ma, sum, gc, a[N]; n signed main() { n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     ma = max(ma, a[i]); n   } n   for (long long i = 1; i <= n; i++) a[i] = ma - a[i]; n   gc = sum = a[1]; n   for (long long i = 2; i <= n; i++) { n     gc = gcd(gc, a[i]); n     sum += a[i]; n   } n   printf( %lld %lld n , sum / gc, gc); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long int, vector<pair<long long int, long long int> > > mapp; n bool cmp(pair<long long int, long long int> &p1, n          pair<long long int, long long int> &p2) { n   if (p1.second != p2.second) return p1.second < p2.second; n   return p1.first < p2.first; n } n int main() { n   long long int n, i, j, k; n   cin >> n; n   vector<long long int> a(n); n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) { n     long long int s = 0; n     for (j = i; j < n; j++) s += a[j], mapp[s].push_back({i, j}); n   } n   long long int ans = 0, f = 0; n   for (auto j : mapp) { n     sort(mapp[j.first].begin(), mapp[j.first].end(), cmp); n     long long int bound = -1, cnt = 0; n     for (auto k : mapp[j.first]) { n       if (k.first > bound) cnt++, bound = k.second; n     } n     if (ans < cnt) ans = cnt, f = j.first; n   } n   cout << ans <<   n ; n   long long int bound = -1, cnt = 0; n   for (auto j : mapp[f]) { n     if (j.first > bound) n       cout << j.first + 1 <<     << j.second + 1 <<   n , bound = j.second; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, h, k, i, j, a[100100], pkp = 0, tmp, p, ans = 0; n   double d; n   scanf( %lld %lld %lld , &n, &h, &k); n   for (i = 0; i < n; i++) scanf( %lld , &a[i]); n   for (i = 0; i < n; i++) { n     if (pkp + a[i] <= h) { n       pkp += a[i]; n     } else { n       tmp = h - a[i]; n       p = pkp - tmp; n       d = ceil((double)p / (double)k); n       ans += (long long)d; n       pkp -= d * k; n       if (pkp < 0) pkp = 0; n       pkp += a[i]; n     } n   } n   d = ceil((double)pkp / (double)k); n   ans += (long long)d; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, k, num, count = 0, i, j; n   cin >> n >> k; n   bitset<32> b[6]; n   for (i = 1; i < 3; i++) { n     for (j = i + 1; j <= 3; j++) { n       cout <<  or   << i <<     << j <<   n  << flush; n       cin >> num; n       b[count] = num; n       count++; n       cout <<  and   << i <<     << j <<   n  << flush; n       cin >> num; n       b[count] = num; n       count++; n     } n   } n   bitset<32> b1, b2; n   for (i = 0; i < 32; i++) { n     if (b[0][i] == b[1][i]) { n       b1[i] = b[0][i]; n       b2[i] = b[0][i]; n     } else { n       if (b[2][i] != b[4][i]) { n         b1[i] = b[2][i]; n         b2[i] = b[4][i]; n       } else { n         b1[i] = b[3][i]; n         b2[i] = b[5][i]; n       } n     } n   } n   bitset<32> r, ans; n   r = b1; n   vector<int> vec; n   vec.push_back(b1.to_ulong()); n   vec.push_back(b2.to_ulong()); n   b1 = b[2]; n   b2 = b[3]; n   for (i = 3; i <= n; i++) { n     if (i > 3) { n       cout <<  or   << 1 <<     << i <<   n  << flush; n       cin >> num; n       b1 = num; n       cout <<  and   << 1 <<     << i <<   n  << flush; n       cin >> num; n       b2 = num; n     } n     for (j = 0; j < 32; j++) { n       if (r[j] == 0 && b1[j] == 0) n         ans[j] = 0; n       else if (r[j] == 0 && b1[j] == 1) n         ans[j] = 1; n     } n     for (j = 0; j < 32; j++) { n       if (r[j] == 1 && b2[j] == 0) n         ans[j] = 0; n       else if (r[j] == 1 && b2[j] == 1) n         ans[j] = 1; n     } n     vec.push_back(ans.to_ulong()); n   } n   sort(vec.begin(), vec.end()); n   cout <<  finish   << vec[k - 1] <<   n  << flush; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxk = 999 + 5; n int a[maxk]; n vector<int> vec; n int main() { n   int n, k, p, x, y; n   scanf( %d%d%d%d%d , &n, &k, &p, &x, &y); n   for (int i = 0; i < k; i++) scanf( %d , a + i); n   if (y > p) { n     printf( -1 n ); n     return 0; n   } n   sort(a, a + k); n   for (int one = 0, now = 0; one <= n - k; one++) { n     now = 0; n     vec.clear(); n     for (int i = 0; i < one; i++) { n       now++; n       vec.push_back(1); n     } n     for (int i = 0; i < k; i++) { n       now += a[i]; n       vec.push_back(a[i]); n     } n     for (; vec.size() < n;) { n       vec.push_back(y); n       now += y; n     } n     if (now > x) continue; n     sort(vec.begin(), vec.end()); n     if (vec[(n + 1) / 2 - 1] >= y) { n       vector<int> ans; n       for (int i = 0; i < one; i++) ans.push_back(1); n       for (int i = 0; i < n - (one + k); i++) ans.push_back(y); n       for (int i = 0; i < ans.size(); i++) n         printf( %d%c , ans[i], i == ans.size() - 1 ?   n  :    ); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   point() : x(0), y(0){}; n   point(long long x, long long y) : x(x), y(y){}; n   long long x; n   long long y; n }; n point operator+(point a, point b) { return point(a.x + b.x, a.y + b.y); } n point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); } n long long dotProduct(point a, point b) { return a.x * b.x + a.y * b.y; } n long long crossProduct(point a, point b) { return a.x * b.y - a.y * b.x; } n int f(point a, point b) { n   if ((double)a.x / a.y > (double)b.x / b.y) return 1; n   return -1; n } n int main() { n   int n; n   cin >> n; n   vector<long long> a(n), b(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   vector<long long> dp(n); n   dp[0] = 0; n   vector<point> hull(n); n   hull[0] = point(b[0], dp[0]); n   int k = 1; n   for (int i = 1; i < n; i++) { n     int l = 0, r = k; n     point q(a[i], 1); n     while (r - l > 2) { n       int m1 = (r + 2 * l) / 3; n       int m2 = (2 * r + l) / 3; n       long long u = dotProduct(q, hull[m1]); n       long long v = dotProduct(q, hull[m2]); n       if (u < v) n         r = m2; n       else n         l = m1; n     } n     if (l + 1 < r && dotProduct(q, hull[l]) > dotProduct(q, hull[l + 1])) l++; n     dp[i] = a[i] * hull[l].x + hull[l].y; n     point p(b[i], dp[i]); n     while (k > 1 && f(hull[k - 1] - hull[k - 2], p - hull[k - 1]) > 0) k--; n     hull[k++] = p; n   } n   cout << dp[n - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long linf = 1e18 + 5; n const int mod = (int)1e9 + 7; n const int logN = 17; n const int inf = 1e9; n const int N = 2e5 + 5; n int main() { n   int n, t; n   vector<pair<int, int> > ans; n   scanf( %d , &n); n   queue<int> q; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &t); n     while (q.size() > t) { n       ans.push_back(make_pair(q.front(), i - 1)); n       q.pop(); n     } n     while (q.size() < t) q.push(i); n   } n   while (q.size()) { n     ans.push_back(make_pair(q.front(), n)); n     q.pop(); n   } n   cout << ans.size() <<   n ; n   for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++) n     cout << it->first <<     << it->second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 10; n int n, q, a[maxn], bit[maxn][22] = {0}, pos[maxn][22] = {0}; n int main() { n   int i, j, l, r; n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     l = i, r = a[i]; n     for (j = 20; j >= 0; j--) n       bit[i][j] = bit[i - 1][j], pos[i][j] = pos[i - 1][j]; n     for (j = 20; j >= 0; j--) n       if (r & (1 << j)) { n         if (bit[i][j] == 0) { n           bit[i][j] = r, pos[i][j] = l; n           break; n         } n         if (l > pos[i][j]) { n           swap(l, pos[i][j]); n           swap(r, bit[i][j]); n         } n         r ^= bit[i][j]; n       } n   } n   cin >> q; n   while (q--) { n     cin >> l >> r; n     int num = 0; n     for (i = 20; i >= 0; i--) n       if ((num ^ bit[r][i]) > num && pos[r][i] >= l) num ^= bit[r][i]; n     cout << num << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n template <class T> n inline void RST(T &A) { n   memset(A, 0, sizeof(A)); n } n template <class T> n inline void FLC(T &A, int x) { n   memset(A, x, sizeof(A)); n } n template <class T> n inline void CLR(T &A) { n   A.clear(); n } n const int dx4[] = {-1, 0, 1, 0}; n const int dy4[] = {0, 1, 0, -1}; n const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1}; n const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; n const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; n const int mod = 1000000007; n const int inf = 0x3f3f3f3f; n const long long inff = 1LL << 60; n const double eps = 1e-9; n const double oo = 1e25; n const double pi = acos(-1.0); n template <class T> n inline void checkMin(T &a, const T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkMax(T &a, const T b) { n   if (a < b) a = b; n } n template <class T> n inline void checkMin(T &a, T &b, const T x) { n   checkMin(a, x), checkMin(b, x); n } n template <class T> n inline void checkMax(T &a, T &b, const T x) { n   checkMax(a, x), checkMax(b, x); n } n template <class T, class C> n inline void checkMin(T &a, const T b, C c) { n   if (c(b, a)) a = b; n } n template <class T, class C> n inline void checkMax(T &a, const T b, C c) { n   if (c(a, b)) a = b; n } n template <class T> n inline T min(T a, T b, T c) { n   return min(min(a, b), c); n } n template <class T> n inline T max(T a, T b, T c) { n   return max(max(a, b), c); n } n template <class T> n inline T min(T a, T b, T c, T d) { n   return min(min(a, b), min(c, d)); n } n template <class T> n inline T max(T a, T b, T c, T d) { n   return max(max(a, b), max(c, d)); n } n template <class T> n inline T sqr(T a) { n   return a * a; n } n template <class T> n inline T cub(T a) { n   return a * a * a; n } n template <class T> n inline T ceil(T x, T y) { n   return (x - 1 + y) / y; n } n inline int sgn(double x) { return x < -eps ? -1 : x > eps; } n inline int sgn(double x, double y) { return sgn(x - y); } n inline double cot(double x) { return 1. / tan(x); }; n inline double sec(double x) { return 1. / cos(x); }; n inline double csc(double x) { return 1. / sin(x); }; n namespace BO { n inline bool _1(int x, int i) { return bool(x & 1 << i); } n inline bool _1(long long x, int i) { return bool(x & 1LL << i); } n inline long long _1(int i) { return 1LL << i; } n inline long long _U(int i) { return _1(i) - 1; }; n inline int reverse_bits(int x) { n   x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); n   x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); n   x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); n   x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); n   x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000); n   return x; n } n inline long long reverse_bits(long long x) { n   x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); n   x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); n   x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); n   x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); n   x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL); n   x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL); n   return x; n } n template <class T> n inline bool odd(T x) { n   return x & 1; n } n template <class T> n inline bool even(T x) { n   return !odd(x); n } n template <class T> n inline T low_bit(T x) { n   return x & -x; n } n template <class T> n inline T high_bit(T x) { n   T p = low_bit(x); n   while (p != x) x -= p, p = low_bit(x); n   return p; n } n template <class T> n inline T cover_bit(T x) { n   T p = 1; n   while (p < x) p <<= 1; n   return p; n } n template <class T> n inline int cover_idx(T x) { n   int p = 0; n   while (_1(p) < x) ++p; n   return p; n } n inline int clz(int x) { return __builtin_clz(x); } n inline int clz(long long x) { return __builtin_clzll(x); } n inline int ctz(int x) { return __builtin_ctz(x); } n inline int ctz(long long x) { return __builtin_ctzll(x); } n inline int lg2(int x) { return !x ? -1 : 31 - clz(x); } n inline int lg2(long long x) { return !x ? -1 : 63 - clz(x); } n inline int low_idx(int x) { return !x ? -1 : ctz(x); } n inline int low_idx(long long x) { return !x ? -1 : ctz(x); } n inline int high_idx(int x) { return lg2(x); } n inline int high_idx(long long x) { return lg2(x); } n inline int parity(int x) { return __builtin_parity(x); } n inline int parity(long long x) { return __builtin_parityll(x); } n inline int count_bits(int x) { return __builtin_popcount(x); } n inline int count_bits(long long x) { return __builtin_popcountll(x); } n }  // namespace BO n using namespace BO; n namespace NT { n template <class T> n inline T lowbit(T x) { n   return x & -x; n } n template <class T> n inline T GCD(T A, T B) { n   T C; n   while (B != 0) C = B, B = A % B, A = C; n   return A; n } n template <class T> n inline T LCM(T A, T B) { n   return A * (B / GCD(A, B)); n } n template <class T> n inline T Mod(T a, T b) { n   a %= b; n   return a < 0 ? a + b : a; n } n template <class T> n inline T MulMod(T a, T b, T c) { n   if (c == 1) return 0; n   if (c <= 0) return -1; n   T ret = 0, tmp; n   tmp = a = Mod(a, c); n   b = Mod(b, c); n   while (b) { n     if (b & 0x1) n       if ((ret += tmp) >= c) ret -= c; n     if ((tmp <<= 1) >= c) tmp -= c; n     b >>= 1; n   } n   return ret; n } n template <class T, class Tb> n inline T PowMod(Tb a, T b, T c) { n   if (c == 1) return 0; n   if (c <= 0) return -1; n   a = Mod(a, (Tb)c); n   Tb ret(1L % c); n   while (b) { n     if (b & 0x1) ret = ret * a % c; n     a = a * a % c; n     b >>= 1; n   } n   return (T)ret; n } n template <class T> n inline T HPowMod(T a, T b, T c) { n   if (c == 1) return 0; n   if (c <= 0) return -1; n   a = Mod(a, c); n   T ret(1L % c); n   while (b) { n     if (b & 0x1) ret = MulMod(ret, a, c); n     a = MulMod(a, a, c); n     b >>= 1; n   } n   return ret; n } n template <class T, class Tb> n inline T Pow(T a, Tb b) { n   T c(1); n   while (b) { n     if (b & 1) c *= a; n     a *= a, b >>= 1; n   } n   return c; n } n template <class T> n inline T EXT_GCD(T a, T b, T &x, T &y) { n   T t, ret; n   if (!b) { n     x = 1, y = 0; n     return a; n   } n   ret = EXT_GCD(b, a % b, x, y); n   t = x, x = y, y = t - a / b * y; n   return ret; n } n template <class T> n inline T Inv(T a, T n) { n   if (n <= 0) return -1; n   T d, x, y; n   d = EXT_GCD(a, n, x, y); n   if (d != 1) return -1; n   return Mod(x, n); n } n template <class T, int MAXN, T MOD = -1> n class Matrix { n  public: n   T m[MAXN][MAXN]; n   Matrix() {} n   void init(T num[MAXN][MAXN]) { n     for (int i = 0; i < MAXN; i++) { n       for (int j = 0; j < MAXN; j++) { n         m[i][j] = num[i][j]; n         if (MOD != -1) m[i][j] %= MOD; n       } n     } n   } n   friend Matrix operator*(const Matrix &m1, const Matrix &m2) { n     int i, j, k; n     Matrix ret; n     memset(ret.m, 0, sizeof(ret.m)); n     for (i = 0; i < MAXN; i++) { n       for (j = 0; j < MAXN; j++) n         if (m1.m[i][j]) { n           for (k = 0; k < MAXN; k++) { n             ret.m[i][k] += m1.m[i][j] * m2.m[j][k]; n             if (MOD != -1) ret.m[i][k] %= MOD; n           } n         } n     } n     return ret; n   } n   friend Matrix operator+(const Matrix &m1, const Matrix &m2) { n     int i, j; n     Matrix ret; n     for (i = 0; i < MAXN; i++) { n       for (j = 0; j < MAXN; j++) { n         ret.m[i][j] = 0; n         ret.m[i][j] = m1.m[i][j] + m2.m[i][j]; n         if (MOD != -1) ret.m[i][j] %= MOD; n       } n     } n     return ret; n   } n   friend Matrix operator^(const Matrix &_M, long long nx) { n     Matrix ret, M(_M); n     for (int i = 0; i < MAXN; i++) { n       for (int j = 0; j < MAXN; j++) { n         if (i == j) n           ret.m[i][j] = 1; n         else n           ret.m[i][j] = 0; n       } n     } n     while (nx) { n       if (nx & 1) ret = ret * M; n       nx = nx >> 1; n       M = M * M; n     } n     return ret; n   } n }; n }  // namespace NT n using namespace NT; n namespace Date { n int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n struct date { n   int year, month, day; n }; n inline int leap(int year) { n   return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; n } n inline int legal(date a) { n   if (a.month < 0 || a.month > 12) return 0; n   if (a.month == 2) return a.day > 0 && a.day <= 28 + leap(a.year); n   return a.day > 0 && a.day <= days[a.month - 1]; n } n inline int datecmp(date a, date b) { n   if (a.year != b.year) return a.year - b.year; n   if (a.month != b.month) return a.month - b.month; n   return a.day - b.day; n } n int weekday(date a) { n   int tm = a.month >= 3 ? (a.month - 2) : (a.month + 10); n   int ty = a.month >= 3 ? a.year : (a.year - 1); n   return (ty + ty / 4 - ty / 100 + ty / 400 + (int)(2.6 * tm - 0.2) + a.day) % n          7; n } n int date2int(date a) { n   int ret = a.year * 365 + (a.year - 1) / 4 - (a.year - 1) / 100 + n             (a.year - 1) / 400, n       i; n   days[1] += leap(a.year); n   for (i = 0; i < a.month - 1; ret += days[i++]) n     ; n   days[1] = 28; n   return ret + a.day; n } n date int2date(int a) { n   date ret; n   ret.year = a / 146097 * 400; n   for (a %= 146097; a >= 365 + leap(ret.year); n        a -= 365 + leap(ret.year), ret.year++) n     ; n   days[1] += leap(ret.year); n   for (ret.month = 1; a >= days[ret.month - 1]; n        a -= days[ret.month - 1], ret.month++) n     ; n   days[1] = 28; n   ret.day = a + 1; n   return ret; n } n }  // namespace Date n namespace IO { n template <class T> n inline T RD(T &x) { n   char c; n   for (c = getchar(); c <  - ; c = getchar()) n     ; n   if (c ==  - ) { n     x =  0  - getchar(); n     for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) n       x = x * 10 +  0  - c; n   } else { n     x = c -  0 ; n     for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) n       x = x * 10 + c -  0 ; n   } n   return x; n } n inline long long RD() { n   long long x; n   return RD(x); n } n }  // namespace IO n using namespace IO; n const int N = 3e5 + 7; n int a[N], b[N], d[N], e[N]; n struct pii { n   int fi, se; n   pii(int fi = 0, int se = 0) : fi(fi), se(se) {} n   bool operator<(const pii &t) const { n     if (fi != t.fi) n       return fi < t.fi; n     else n       return se < t.se; n   } n   bool operator==(const pii &t) const { return (fi == t.fi) && (se == t.se); } n }; n pii q[N], qq[N]; n int main() { n   int n, p; n   n = RD(), p = RD(); n   for (int i = 0; i < n; i++) { n     int a, b; n     a = RD(), b = RD(); n     if (a > b) swap(a, b); n     d[a]++, d[b]++; n     e[a]++, e[b]++; n     q[i] = pii(a, b); n     qq[i] = pii(a, b); n   } n   sort(e + 1, e + 1 + n); n   long long sum = 0; n   for (int i = 1; i <= n; i++) { n     int u = d[i], v = p - d[i]; n     sum += e + n + 1 - lower_bound(e + 1, e + 1 + n, v); n     if (u + u >= p) sum--; n   } n   assert(even(sum)); n   sum /= 2LL; n   sort(q, q + n); n   sort(qq, qq + n); n   int m = unique(qq, qq + n) - qq; n   for (int i = 0; i < m; i++) { n     int a = qq[i].fi, b = qq[i].se; n     assert(a != b); n     int cnt = n         upper_bound(q, q + n, pii(a, b)) - lower_bound(q, q + n, pii(a, b)); n     if (d[a] + d[b] >= p && d[a] + d[b] - cnt < p) sum--; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline string itos(T n) { n   return (n) < 0    ?  -  + itos(-(n)) n          : (n) < 10 ? (string)(  ) + (char)( 0  + (n)) n                     : itos((n) / 10) + itos((n) % 10); n } n string name[60]; n map<string, int> mp; n int point[60], _plus[60], _minus[60]; n vector<pair<pair<int, pair<int, int> >, string> > v; n int main(void) { n   int N, i, j; n   string s; n   cin >> N; n   for ((i) = 0; (i) < (int)(N); (i)++) { n     cin >> name[i]; n     mp[name[i]] = i; n   } n   for ((i) = 0; (i) < (int)(N * (N - 1) / 2); (i)++) { n     cin >> s; n     for (j = 0;; j++) { n       if (s[j] ==  - ) break; n     } n     int a = mp[s.substr(0, j)]; n     int b = mp[s.substr(j + 1)]; n     int x, y; n     cin >> s; n     for ((j) = 0; (j) < (int)(s.length()); (j)++) { n       if (s[j] ==  : ) { n         s[j] =    ; n       } n     } n     istringstream ss(s); n     ss >> x >> y; n     if (x > y) n       point[a] += 3; n     else if (x < y) n       point[b] += 3; n     else { n       point[a]++; n       point[b]++; n     } n     _plus[a] += x; n     _plus[b] += y; n     _minus[a] += y; n     _minus[b] += x; n   } n   for ((i) = 0; (i) < (int)(N); (i)++) { n     v.push_back(make_pair( n         make_pair(-point[i], make_pair(_minus[i] - _plus[i], -_plus[i])), n         name[i])); n   } n   sort(v.begin(), v.end()); n   vector<string> ans; n   for ((i) = 0; (i) < (int)(N / 2); (i)++) { n     ans.push_back(v[i].second); n   } n   sort(ans.begin(), ans.end()); n   for ((i) = 0; (i) < (int)(N / 2); (i)++) { n     cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ar[105] = {0}; n   int n; n   int r; n   cin >> n; n   int tc = n, a; n   while (tc--) { n     cin >> r; n     for (int i = 0; i < r; i++) { n       cin >> a; n       ar[a]++; n     } n   } n   for (int i = 1; i <= 100; i++) n     if (ar[i] == n) cout << i <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int T; n   cin >> T; n   while (T--) { n     int n; n     int number[200005], dis[10] = {0}; n     char c; n     cin >> n; n     for (int a = 1; a <= n; a++) { n       cin >> c; n       number[a] = c -  0 ; n       dis[number[a]] = 1; n     } n     int f = 0; n     for (int a = 0; a <= 9; a++) { n       int vis[200005]; n       for (int j = 1; j <= n; j++) vis[j] = 2; n       int t = 1; n       for (int i = 0; i <= a; i++) { n         if (dis[i] == 0) continue; n         for (int b = t; b <= n; b++) n           if (number[b] == i) { n             vis[b] = 1; n             t = b + 1; n           } n         if (t == n + 1) break; n       } n       int flag = 0; n       int maxx = 0; n       for (int i = 1; i <= n; i++) { n         if (vis[i] == 1) continue; n         if (number[i] >= a && number[i] >= maxx) n           maxx = number[i]; n         else { n           flag = 1; n           break; n         } n       } n       if (flag == 1) n         continue; n       else { n         for (int i = 1; i <= n; i++) cout << vis[i]; n         cout << endl; n         f = 1; n         break; n       } n     } n     if (f == 0) cout <<  -  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, -1, 1}; n int dy[] = {1, -1, 0, 0}; n int px[105], py[105]; n int main() { n   int x, y, Sz, d, z; n   bool f = 0; n   string s; n   cin >> x >> y >> s; n   Sz = s.size(); n   px[0] = py[0] = 0; n   for (int i = 0; i < Sz; i++) { n     if (s[i] ==  U ) n       d = 0; n     else if (s[i] ==  D ) n       d = 1; n     else if (s[i] ==  L ) n       d = 2; n     else n       d = 3; n     px[i + 1] = px[i] + dx[d]; n     py[i + 1] = py[i] + dy[d]; n   } n   for (int i = 0; i <= Sz; i++) { n     if (px[Sz] != 0) z = (x - px[i]) / px[Sz]; n     if (py[Sz] != 0) z = (y - py[i]) / py[Sz]; n     if (z < 0) continue; n     if (z * px[Sz] == (x - px[i]) && z * py[Sz] == (y - py[i])) f = 1; n   } n   if (f) n     printf( Yes n ); n   else n     printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void hehe() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   sort(arr.rbegin(), arr.rend()); n   vector<long long int> rem; n   for (int i = 0; i < n - 1; i++) { n     if (arr[i] - arr[i + 1] < 2) { n       i++; n       rem.push_back(arr[i]); n     } n   } n   long long int ans = 0; n   for (int i = 0; i + 1 < rem.size(); i += 2) { n     ans += (long long int)(rem[i] * rem[i + 1]); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     hehe(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, cnt; n int A[10]; n long long FE(long long n, long long m) { n   if (!m) return 1; n   long long t = FE(n, m >> 1); n   t = (t * t) % (1000000007); n   if (m & 1) t = (t * n) % (1000000007); n   return t % (1000000007); n } n bool ctrl() { n   bool H[10] = {0}; n   int s = k - 1; n   if (!s) return true; n   for (int i = 2; i <= k; i++) { n     if (A[i] == 1) { n       H[i] = 1; n       s--; n       if (!s) return true; n     } n   } n   bool flag; n   while (1) { n     flag = 0; n     for (int i = 2; i <= k; i++) { n       if (!H[i] && H[A[i]]) { n         H[i] = 1; n         s--; n         flag = 1; n         if (!s) return true; n       } n     } n     if (!flag) return false; n   } n } n void solve(int x) { n   if (x == k + 1) { n     if (ctrl()) { n       cnt++; n       cnt %= (1000000007); n     } n     return; n   } n   for (int i = 1; i <= k; i++) { n     A[x] = i; n     solve(x + 1); n   } n } n int main() { n   scanf( %lld %lld , &n, &k); n   solve(2); n   long long res = 1; n   if (n - k > 0) res *= FE(n - k, n - k); n   cout << ((cnt * k) % (1000000007) * res) % (1000000007) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int i, t = 1, j, temp; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   while (t--) { n     long long int n, k = 0; n     cin >> n; n     long long int a[n]; n     map<int, long long int> m; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       m[a[i]]++; n     } n     map<int, long long int>::iterator itr; n     for (itr = m.begin(); itr != m.end(); itr++) { n       if (k < (itr->second)) { n         k = itr->second; n       } n     } n     if (n % 2) { n       (k <= ((n + 1) / 2)) ? cout <<  YES  : cout <<  NO ; n     } else { n       (k <= (n / 2)) ? cout <<  YES  : cout <<  NO ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string transo(int n) { n   switch (n) { n     case 0: n       return  zero ; n       break; n     case 1: n       return  one ; n       break; n     case 2: n       return  two ; n       break; n     case 3: n       return  three ; n       break; n     case 4: n       return  four ; n       break; n     case 5: n       return  five ; n       break; n     case 6: n       return  six ; n       break; n     case 7: n       return  seven ; n       break; n     case 8: n       return  eight ; n       break; n     case 9: n       return  nine ; n       break; n   } n } n string transp(int n) { n   switch (n) { n     case 10: n       return  ten ; n       break; n     case 11: n       return  eleven ; n       break; n     case 12: n       return  twelve ; n       break; n     case 13: n       return  thirteen ; n       break; n     case 14: n       return  fourteen ; n       break; n     case 15: n       return  fifteen ; n       break; n     case 16: n       return  sixteen ; n       break; n     case 17: n       return  seventeen ; n       break; n     case 18: n       return  eighteen ; n       break; n     case 19: n       return  nineteen ; n       break; n   } n } n string transd(int n) { n   switch (n) { n     case 2: n       return  twenty ; n       break; n     case 3: n       return  thirty ; n       break; n     case 4: n       return  forty ; n       break; n     case 5: n       return  fifty ; n       break; n     case 6: n       return  sixty ; n       break; n     case 7: n       return  seventy ; n       break; n     case 8: n       return  eighty ; n       break; n     case 9: n       return  ninety ; n       break; n   } n } n int main() { n   cin >> n; n   if (n < 10) cout << transo(n); n   if (n >= 10 && n <= 19) cout << transp(n); n   if (n > 19 && n % 10 != 0) cout << transd(n / 10) <<  -  << transo(n % 10); n   if (n > 19 && n % 10 == 0) cout << transd(n / 10); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ts, tf, t, n, x, ans, lim = 1000000000007; n int main() { n   cin >> ts >> tf >> t; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (x <= tf - t) { n       if (max(ts, x - 1) <= tf - t && ts - (x - 1) < lim) { n         lim = ts - (x - 1); n         ans = min(ts, x - 1); n       } n       ts = max(ts, x) + t; n     } n   } n   if (ts <= tf - t) ans = ts; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     if (n == 1 || n == 2 || n == 4) { n       printf( -1 n ); n       continue; n     } n     if (!(n % 3)) n       printf( %d %d %d n , (n / 3), 0, 0); n     else if (n % 3 == 1) n       printf( %d %d %d n , (n - 7) / 3, 0, 1); n     else n       printf( %d %d %d n , (n - 5) / 3, 1, 0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   long long n, h, a, b, k; n   cin >> n >> k >> a >> b >> k; n   while (k--) { n     long long tower1, tower2, source, destination; n     cin >> tower1 >> source >> tower2 >> destination; n     long long ans = 0; n     if (tower1 == tower2) { n       cout << abs(source - destination) << endl; n     } else if (source > b) { n       ans += abs(source - b); n       ans += abs(tower2 - tower1); n       ans += abs(b - destination); n       cout << ans << endl; n     } else if (source < a) { n       ans += abs(a - source); n       ans += abs(tower2 - tower1); n       ans += abs(a - destination); n       cout << ans << endl; n     } else { n       ans += abs(tower2 - tower1); n       ans += abs(source - destination); n       cout << ans << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int connected; n int par[N], sz[N]; n struct DSU { n   void init(int n) { n     for (int i = 1; i <= n; i++) { n       par[i] = i; n       sz[i] = 1; n     } n     connected = n; n   } n   int getPar(int k) { n     while (k != par[k]) { n       par[k] = par[par[k]]; n       k = par[k]; n     } n     return k; n   } n   int getSize(int k) { return sz[getPar(k)]; } n   void unite(int u, int v) { n     int par1 = getPar(u), par2 = getPar(v); n     if (par1 == par2) return; n     connected--; n     if (sz[par1] > sz[par2]) swap(par1, par2); n     sz[par2] += sz[par1]; n     sz[par1] = 0; n     par[par1] = par[par2]; n   } n }; n DSU dsu; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long powermod(long long x, long long y) { n   if (y == 0) return 1; n   if (y % 2 == 0) n     return (powermod(x, y / 2) * powermod(x, y / 2)) % 1000000007; n   else n     return (((powermod(x, y / 2) * powermod(x, y / 2)) % 1000000007) * x) % n            1000000007; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   map<int, int> m1, m2; n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = 0; i < 2 * n; i++) { n     int x; n     cin >> x; n     if (m1.find(x) == m1.end()) n       m1[x] = i + 1; n     else n       m2[x] = i + 1; n   } n   int y = 1; n   for (auto x : m1) { n     ans += abs(y - x.second); n     y = x.second; n   } n   y = 1; n   for (auto x : m2) { n     ans += abs(y - x.second); n     y = x.second; n   } n   cout << ans; n } n