#include <bits/stdc++.h> n using namespace std; n int A[55], ctos, lleno; n long long D[52][52][52][52]; n double res = 0, suma; n int main() { n   scanf( %d , &ctos); n   for (int i = 1; i <= ctos; i++) { n     scanf( %d , &A[i]); n     suma += A[i]; n   } n   scanf( %d , &lleno); n   for (int quien = 1; quien <= ctos; quien++) { n     for (int dnde = ctos + 1; dnde > 0; dnde--) { n       for (int lleva = 0; lleva <= 50; lleva++) { n         for (int lugares = 0; lugares <= ctos; lugares++) { n           if (dnde == quien) { n             D[dnde][lleva][lugares][quien] = D[dnde + 1][lleva][lugares][quien]; n           } else if (dnde > ctos) { n             if (lleva == 0 and lugares == 0) { n               D[dnde][lleva][lugares][quien] = 1; n             } else { n               D[dnde][lleva][lugares][quien] = 0; n             } n           } else if (lleva == 0 or lugares == 0) { n             if (lleva == 0 and lugares == 0) { n               D[dnde][lleva][lugares][quien] = 1; n             } else { n               D[dnde][lleva][lugares][quien] = 0; n             } n           } else { n             D[dnde][lleva][lugares][quien] = D[dnde + 1][lleva][lugares][quien]; n             if (lleva >= A[dnde]) { n               D[dnde][lleva][lugares][quien] += n                   D[dnde + 1][lleva - A[dnde]][lugares - 1][quien]; n             } n           } n         } n       } n     } n   } n   if (suma <= lleno) { n     res = ctos; n   } else { n     for (int i = ctos - 1; i > 0; i--) { n       for (int eleg = 1; eleg <= ctos; eleg++) { n         suma = 0; n         for (int es = lleno - A[eleg] + 1; es <= lleno; es++) { n           suma += D[1][es][i][eleg]; n         } n         suma *= i; n         for (double e = ctos; e > i; e--) { n           suma /= e; n         } n         for (int e = 2; e <= ctos - i - 1; e++) { n           suma *= e; n         } n         res += suma; n       } n     } n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long a, b; n   while (scanf( %ld%ld , &a, &b) != EOF) { n     if (a == b) { n       if (a % 2 == 0) n         printf( 2 n ); n       else if (a % 3 == 0) n         printf( 3 n ); n       else if (a % 5 == 0) n         printf( 5 n ); n       else if (a % 7 == 0) n         printf( 7 n ); n       else n         printf( %ld , a); n     } else n       printf( 2 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double eps = 1e-8; n char ans[1024]; n int K, X, N, M; n char st[64], ed[64]; n long long num[64]; n void printAns(char from, char to, int all, int len) { n   int pos = 1; n   if (from ==  A ) pos = 0; n   for (int i = 0; i < len; i++) ans[i] =  B ; n   for (int i = 0; i < all; i++) n     ans[pos + 2 * i] =  A , ans[pos + 2 * i + 1] =  C ; n   ans[0] = from; n   ans[len - 1] = to; n   ans[len] =   0 ; n   printf( %s n , ans); n } n int main() { n   scanf( %d%d%d%d , &K, &X, &N, &M); n   for (char s1 =  A ; s1 <=  C ; s1++) { n     for (char e1 =  A ; e1 <=  C ; e1++) { n       if (N == 1 && s1 != e1) continue; n       for (char s2 =  A ; s2 <=  C ; s2++) { n         for (char e2 =  A ; e2 <=  C ; e2++) { n           if (M == 1 && s2 != e2) continue; n           long long tn = N - (s1 !=  A ) - (e1 !=  C ); n           long long tm = M - (s2 !=  A ) - (e2 !=  C ); n           long long inN = tn / 2; n           long long inM = tm / 2; n           st[1] = s1, ed[1] = e1; n           st[2] = s2, ed[2] = e2; n           for (long long i = 0; i <= inN; i++) { n             for (long long k = 0; k <= inM; k++) { n               if (N == 2 && s1 ==  A  && e1 ==  C  && i == 0) continue; n               if (M == 2 && s2 ==  A  && e2 ==  C  && k == 0) continue; n               num[1] = i; n               num[2] = k; n               for (int g = 3; g <= K; g++) { n                 st[g] = st[g - 2], ed[g] = ed[g - 1]; n                 num[g] = num[g - 1] + num[g - 2] + n                          (ed[g - 2] ==  A  && st[g - 1] ==  C ); n               } n               if (num[K] == X) { n                 printAns(s1, e1, i, N); n                 printAns(s2, e2, k, M); n                 return 0; n               } n             } n           } n         } n       } n     } n   } n   printf( Happy new year! n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string last_w =   ; n set<string> reserved; n void change_last_w() { n   do { n     int j(last_w.size() - 1); n     while (j >= 0 && last_w[j] ==  z ) --j; n     if (j == -1) n       last_w.assign(last_w.size() + 1,  a ); n     else { n       ++last_w[j]; n       for (int i(j + 1); i < last_w.size(); ++i) last_w[i] =  a ; n     } n   } while (reserved.count(last_w)); n } n bool valid_char(char c) { n   return isdigit(c) || isalpha(c) || c ==  _  || c ==  $ ; n } n int parse_word(const string& s) { n   if (s.empty()) return 0; n   if (isdigit(s[0])) return false; n   int ans(0); n   while (ans < s.size() && valid_char(s[ans])) ++ans; n   return ans; n } n int parse_num(const string& s) { n   if (s.empty()) return 0; n   int ans(0); n   while (ans < s.size() && isdigit(s[ans])) ++ans; n   return ans; n } n int parse_reserved(const string& s) { n   if (s.empty()) return 0; n   int best(0); n   string t; n   for (int i(0); i < min<size_t>(20UL, s.size()) && s[i] !=  # ; ++i) { n     t += s[i]; n     if (reserved.count(t)) best = i + 1; n   } n   return best; n } n int parse_all(const string& s) { n   return max({parse_num(s), parse_reserved(s), parse_word(s)}); n } n vector<string> parse(string s) { n   vector<string> ans; n   while (!s.empty() && s[0] !=  # ) { n     int cnt(0); n     while (cnt < s.size() && s[cnt] ==    ) ++cnt; n     if (cnt) { n       s = s.substr(cnt, s.size() - cnt); n       continue; n     } n     int cur(parse_all(s)); n     ans.push_back(s.substr(0, cur)); n     s = s.substr(cur, s.size() - cur); n   } n   return ans; n } n vector<int> parse_len(string s) { n   vector<int> ans; n   while (!s.empty()) { n     int cnt(0); n     while (cnt < s.size() && s[cnt] ==    ) ++cnt; n     if (cnt) { n       s = s.substr(cnt, s.size() - cnt); n       continue; n     } n     int cur(parse_all(s)); n     ans.push_back(cur); n     s = s.substr(cur, s.size() - cur); n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   string s__; n   for (int i(0); i < n; ++i) { n     cin >> s__; n     reserved.insert(s__); n   } n   cin >> n; n   getline(cin, s__); n   vector<string> tokens; n   while (n--) { n     getline(cin, s__); n     auto add = parse(s__); n     copy(begin(add), end(add), back_inserter(tokens)); n   } n   map<string, string> was; n   for (string& s : tokens) n     if (!reserved.count(s) && !isdigit(s[0])) { n       if (!was.count(s)) { n         change_last_w(); n         was[s] = last_w; n       } n       s = was[s]; n     } n   string ans; n   int next_space(tokens.size()); n   for (int i(0); i < tokens.size(); ++i) { n     string s(tokens[i]); n     int j(i + 1); n     while (true) { n       if (j == tokens.size()) break; n       s += tokens[j]; n       if (parse_all(s) != tokens[i].size()) { n         next_space = min(next_space, j - 1); n         break; n       } n       if (s.size() > 20) break; n       ++j; n     } n     ans += tokens[i]; n     if (next_space == i) { n       next_space = tokens.size(); n       ans +=    ; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK: 1024000000,1024000000 ) n using namespace std; n inline int getint() { n   int _x = 0; n   char _tc = getchar(); n   while (_tc <  0  || _tc >  9 ) _tc = getchar(); n   while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar(); n   return _x; n } n const int N = 1010, M = 1e5 + 15, INF = 1e7; n bool vis[N]; n int dis[N]; n struct Edge { n   int u, v, c, w; n   int nxt; n   Edge() {} n   Edge(int t2, int t3, int t4, int t5, int t6) n       : u(t2), v(t3), c(t4), w(t5), nxt(t6) {} n }; n Edge e[M]; n int h[N], ect; n int mom[N], id[N]; n int n, m, A[N], D[N], X[N], ca, cd; n char s[10]; n int S, T; n void init() { n   memset(vis, false, sizeof(vis)); n   ect = 0; n   memset(h, -1, sizeof(h)); n   ca = cd = 0; n } n void _add(int u, int v, int c, int w) { n   e[ect] = Edge(u, v, c, w, h[u]); n   h[u] = ect++; n   e[ect] = Edge(v, u, 0, -w, h[v]); n   h[v] = ect++; n } n int spfa() { n   queue<int> Q; n   for (int i = S + 1; i <= T; i++) dis[i] = 10 * INF; n   Q.push(S); n   vis[S] = true; n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     vis[u] = false; n     for (int i = h[u]; i + 1; i = e[i].nxt) { n       int v = e[i].v; n       if (e[i].c && dis[v] > dis[u] + e[i].w) { n         dis[v] = dis[u] + e[i].w; n         if (!vis[v]) vis[v] = true, Q.push(v); n         id[v] = i; n       } n     } n   } n   return dis[T]; n } n void aug() { n   int p = T; n   while (p != S) { n     e[id[p]].c -= 1; n     e[id[p] ^ 1].c += 1; n     p = e[id[p] ^ 1].v; n   } n } n int MFMC() { n   int ret = 0, d, tmp = 0; n   for (int i = 1; i <= n; i++) { n     d = spfa(); n     if (d == 10 * INF) return -ret; n     tmp += d, ret = min(ret, tmp), aug(); n   } n   for (int i = n + 1; i <= m; i++) { n     d = spfa(); n     if (d == 10 * INF) return -ret; n     tmp += d - 2 * INF, ret = min(ret, tmp), aug(); n   } n   return -ret; n } n int main() { n   init(); n   scanf( %d%d , &n, &m); n   S = 0, T = n + m + 1; n   dis[S] = 0; n   for (int i = 1, x; i <= n; i++) { n     scanf( %s %d , s, &x); n     if (s[0] ==  A ) n       A[++ca] = x; n     else n       D[++cd] = x; n   } n   for (int i = 1; i <= n; i++) _add(i + m, T, 1, 0); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &X[i]); n     _add(S, i, 1, 0); n     _add(i, T, 1, 2 * INF - X[i]); n     for (int j = 1; j <= ca; j++) n       if (X[i] >= A[j]) _add(i, j + m, 1, A[j] - X[i]); n     for (int j = 1; j <= cd; j++) n       if (X[i] > D[j]) _add(i, j + m + ca, 1, 0); n   } n   printf( %d n , MFMC()); 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   long long n; n   cin >> n; n   long long a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   long long ans = 0; n   for (long long i = n - 1; i >= 0; i--) { n     if (i == n - 1) n       ans += a[i]; n     else if (a[i] < a[i + 1]) n       ans += a[i]; n     else if (a[i] >= a[i + 1]) { n       if (a[i + 1] == 0) n         a[i] = 0; n       else { n         ans += a[i + 1] - 1; n         a[i] = a[i + 1] - 1; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n long long mod = 1000000007; n long long mod2 = 998244353; n long long OO = 1e18; n long long david_villa_pow(long long x, long long n) { n   if (n == 0) return 1; n   long long u = david_villa_pow(x, n / 2); n   u = ((u) * (u)); n   if (n % 2 == 1) u = ((u) * (x)); n   return u; n } n long long up(long long x, long long y) { n   if (x % y == 0) return x / y; n   return x / y + 1; n } n using namespace std; n long long a[200200]; n int main() { n   long long i, j; n   ; n   long long T; n   cin >> T; n   while (T--) { n     long long n, k, mn = OO; n     cin >> n >> k; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       mn = min(mn, a[i]); n     } n     long long indx = 0; n     for (i = 0; i < n; i++) { n       if (a[i] == mn) { n         indx = i; n         break; n       } n     } n     long long res = 0; n     for (i = 0; i < n; i++) { n       if (i != indx) { n         res += (k - a[i]) / mn; n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (1 << 30) - 1; n const long long linf = (1ll << 62) - 1; n int main() { n   int n; n   cin >> n; n   vector<int> is_prime(n + 1, true), primes; n   is_prime[0] = is_prime[1] = 0; n   for (int i = 2; i * i <= n; i++) { n     if (is_prime[i]) { n       for (int j = i * i; j <= n; j += i) { n         is_prime[j] = false; n       } n     } n   } n   vector<int> ans; n   for (int i = 1; i <= n; i++) { n     if (is_prime[i]) { n       int q = i; n       while (q <= n) { n         ans.push_back(q); n         q *= i; n       } n     } n   } n   cout << ((int)(ans).size()) << endl; n   for (int i : ans) { n     printf( %d  , i); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, n, k, r; n   cin >> n >> k; n   long long int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long int *m = min_element(a, a + n); n   r = 0; n   for (i = 0; i < n; i++) { n     if ((a[i] - *m) % k == 0) { n       r += (a[i] - *m) / k; n     } else { n       cout << -1; n       return 0; n     } n   } n   cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 * 100 + 10; n int n, d[N], par[N]; n pair<int, int> tr[N * 4]; n pair<long long, int> a[N], b[N]; n void add(int val, int p, int b = 0, int e = n, int ind = 1) { n   tr[ind] = max(tr[ind], make_pair(val, p)); n   if (b + 1 == e) return; n   int mid = (b + e) / 2; n   if (p < mid) n     add(val, p, b, mid, ind * 2); n   else n     add(val, p, mid, e, ind * 2 + 1); n   return; n } n pair<int, int> get(int l, int r, int b = 0, int e = n, int ind = 1) { n   if (l <= b && e <= r) return tr[ind]; n   int mid = (b + e) / 2; n   pair<int, int> ret = make_pair(0, 0); n   if (l < mid) ret = get(l, r, b, mid, ind * 2); n   if (r > mid) ret = max(get(l, r, mid, e, ind * 2 + 1), ret); n   return ret; n } n void pp(int v) { n   if (d[v] == 1) { n     cout << v + 1 <<    ; n     return; n   } n   pp(par[v]); n   cout << v + 1 <<    ; n   return; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first; n     b[i].first = a[i].first; n     b[i].second = i; n   } n   sort(b, b + n); n   for (int i = 0; i < n; i++) a[b[i].second].second = i; n   d[0] = 1; n   add(1, a[0].second); n   for (int i = 1; i < n; i++) { n     int l = upper_bound(b, b + n, make_pair(a[i].first - k, n)) - b; n     int r = lower_bound(b, b + n, make_pair(a[i].first + k, 0)) - b; n     if (l) { n       pair<int, int> temp = get(0, l); n       d[i] = temp.first + 1; n       par[i] = b[temp.second].second; n     } n     if (r < n) { n       pair<int, int> temp = get(r, n); n       if (temp.first >= d[i]) { n         d[i] = temp.first + 1; n         par[i] = b[temp.second].second; n       } n     } n     add(d[i], a[i].second); n   } n   long long maxx = 0, maxind; n   for (int i = 0; i < n; i++) { n     if (d[i] > maxx) { n       maxx = d[i]; n       maxind = i; n     } n   } n   cout << maxx << endl; n   pp(maxind); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:267386880 ) n using namespace std; n int n; n char g[72][72]; n struct pos { n   int data[3]; n }; n const int MAXQ = 400000; n bool used[72][72][72]; n pos prv[72][72][72]; n pos q[MAXQ]; n int head, tail; n pair<int, int> getDiff(pos &a, pos &b) { n   int diffA(-1); n   for (int i(0); i <= ((long long)(3) - 1); ++i) { n     bool ok(true); n     for (int j(0); j <= ((long long)(3) - 1); ++j) n       if (b.data[j] == a.data[i]) ok = false; n     if (ok) { n       diffA = a.data[i]; n       break; n     } n   } n   int sm1(accumulate(a.data, a.data + 3, 0)); n   int sm2(accumulate(b.data, b.data + 3, 0)); n   int diffB = -(sm1 - sm2 - diffA); n   return make_pair(diffA, diffB); n } n void printAns() { n   pos tmp = {{0, 1, 2}}; n   pos &now = tmp; n   pos &from = prv[0][1][2]; n   vector<pair<int, int> > ans; n   while (from.data[0] != -1) { n     pair<int, int> rs(getDiff(from, now)); n     ans.push_back(rs); n     now = from; n     from = prv[now.data[0]][now.data[1]][now.data[2]]; n   } n   reverse((ans).begin(), (ans).end()); n   printf( %d n , ((int)ans.size())); n   for (int i(0); i <= ((long long)(((int)ans.size())) - 1); ++i) n     printf( %d %d n , ans[i].first + 1, ans[i].second + 1); n   exit(0); n } n void addPos(int a, int b, int c, pos from) { n   pos p = {{a, b, c}}; n   sort(p.data, p.data + 3); n   if (used[p.data[0]][p.data[1]][p.data[2]]) return; n   used[p.data[0]][p.data[1]][p.data[2]] = true; n   prv[p.data[0]][p.data[1]][p.data[2]] = from; n   q[tail++] = p; n   if (tail == MAXQ) tail = 0; n   if (p.data[0] == 0 && p.data[1] == 1 && p.data[2] == 2) printAns(); n } n bool can(int from, int to, int a, int b) { return g[a][b] == g[from][to]; } n void process() { n   pos &cur = q[head++]; n   if (head == MAXQ) head = 0; n   for (int i(0); i <= ((long long)(3) - 1); ++i) { n     int from(cur.data[i]); n     int a(cur.data[(i + 1) % 3]), b(cur.data[(i + 2) % 3]); n     for (int to(0); to <= ((long long)(n)-1); ++to) { n       if (to == a || to == b || to == from) continue; n       if (can(from, to, a, b)) addPos(to, a, b, cur); n     } n   } n } n void solve() { n   scanf( %d , &n); n   int a, b, c; n   scanf( %d%d%d n , &a, &b, &c); n   for (int i(0); i <= ((long long)(n)-1); ++i) gets(g[i]); n   pos fict = {{-1, -1, -1}}; n   addPos(--a, --b, --c, fict); n   while (head != tail) process(); n   printf( -1 n ); n } n void bruteforce() {} n int main() { n   solve(); n   bruteforce(); 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   int t; n   cin >> t; n   while (t--) { n     int n, q; n     cin >> n >> q; n     string s; n     cin >> s; n     int pref[n + 1]; n     memset(pref, 0, sizeof(pref)); n     set<int> arr[2 * n + 5]; n     for (int i = 0; i < 2 * n + 5; i++) { n       set<int> ss; n       arr[i] = ss; n     } n     for (int i = 1; i <= n; i++) { n       if (s[i - 1] ==  + ) { n         if (i % 2 == 1) { n           pref[i] = pref[i - 1] + 1; n         } else { n           pref[i] = pref[i - 1] - 1; n         } n       } else { n         if (i % 2 == 1) { n           pref[i] = pref[i - 1] - 1; n         } else { n           pref[i] = pref[i - 1] + 1; n         } n       } n       arr[pref[i] + n].insert(i); n     } n     for (int i = 0; i < q; i++) { n       int l, r; n       cin >> l >> r; n       int val = pref[r] - pref[l - 1]; n       if (val == 0) { n         cout << 0 << endl; n       } else { n         if (abs(val) % 2 == 1) { n           if (val < 0) { n             val--; n           } else { n             val++; n           } n           int half = pref[l - 1] + val / 2; n           half += n; n           auto it = arr[half].lower_bound(l); n           int res = *it; n           cout << 1 << endl; n           cout << res << endl; n         } else { n           int diff = pref[r] - pref[r - 1]; n           val -= diff; n           if (val < 0) { n             val--; n           } else { n             val++; n           } n           int half = pref[l - 1] + val / 2; n           half += n; n           auto it = arr[half].lower_bound(l); n           int res = *it; n           cout << 2 << endl; n           cout << res <<     << r << endl; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int him(long long int a, long long int n) { n   long long int ans = 1; n   while (n) { n     if (n % 2 != 0) { n       ans = ((ans) * (a)); n     } n     a = ((a) * (a)); n     n = n / 2; n   } n   return ans; n } n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     if (n == 1 || n == 2) n       cout << 0 << endl; n     else n       cout << n - 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int Max = 1e6 + 5; n int lst[Max]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     long long sum = 0; n     while (n > 0) { n       if (n % k == 0) { n         n /= k; n         sum++; n       } else { n         sum += n % k; n         n -= n % k; n       } n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> split_string(string); n bool isDiverse(string &s) { n   int len = s.length(); n   sort(s.begin(), s.end()); n   for (int i = 0; i < len - 1; i++) { n     if (s[i] == s[i + 1]) { n       return false; n     } else if (s[i + 1] != s[i] + 1) { n       return false; n     } n   } n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   int N; n   string s; n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> s; n     if (isDiverse(s)) { n       cout <<  Yes n ; n     } else { n       cout <<  No n ; n     } n   } n } n vector<string> split_string(string input_string) { n   vector<string> splits; n   stringstream ss(input_string); n   string item; n   while (getline(ss, item,    )) { n     splits.push_back(item); n   } n   return splits; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 405; n const int oo = 10005; n int N, M, T, K, Q; n vector<pair<int, int> > G[MAXN]; n int dp[MAXN][MAXN][MAXN]; n int par[MAXN]; n int indPar[MAXN]; n void DFS(int u, int p) { n   par[u] = p; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i].first; n     if (v != p) { n       indPar[v] = G[u][i].second; n       DFS(v, u); n     } n   } n   return; n } n int solve(int i, int cnt, int curK) { n   if (curK == 0) return 0; n   if (G[i].size() == 1 && i != 1) return (curK == 1) ? 0 : oo; n   if (cnt >= G[i].size()) return (curK == 1) ? 0 : oo; n   if (dp[i][cnt][curK] != -1) return dp[i][cnt][curK]; n   int res = oo; n   int v = G[i][cnt].first; n   if (v == par[i]) return dp[i][cnt][curK] = solve(i, cnt + 1, curK); n   res = min(res, solve(i, cnt + 1, curK) + 1); n   for (int k = 1; k < curK; k++) n     res = min(res, solve(v, 0, k) + solve(i, cnt + 1, curK - k)); n   return dp[i][cnt][curK] = res; n } n void TRACE(int i, int cnt, int curK) { n   if (curK == 0) return; n   if (G[i].size() == 1 && i != 1) return; n   if (cnt >= G[i].size()) return; n   int res = solve(i, cnt, curK); n   int v = G[i][cnt].first; n   if (v == par[i]) { n     TRACE(i, cnt + 1, curK); n     return; n   } n   if (res == solve(i, cnt + 1, curK) + 1) { n     cout << G[i][cnt].second <<    ; n     TRACE(i, cnt + 1, curK); n     return; n   } n   for (int k = 1; k < curK; k++) n     if (res == solve(v, 0, k) + solve(i, cnt + 1, curK - k)) { n       TRACE(v, 0, k); n       TRACE(i, cnt + 1, curK - k); n       return; n     } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( 440D  n              .inp , n              r )) { n     freopen( n          440D  n          .inp , n          r , stdin); n     freopen( n          440D  n          .out , n          w , stdout); n   } n   cin >> N >> K; n   int u, v; n   for (int i = 1; i <= N - 1; i++) { n     cin >> u >> v; n     G[u].push_back({v, i}); n     G[v].push_back({u, i}); n   } n   DFS(1, 0); n   memset(dp, -1, sizeof(dp)); n   int ANS = solve(1, 0, K); n   int Root = 1; n   for (int i = 2; i <= N; i++) { n     if (ANS > solve(i, 0, K) + 1) { n       ANS = solve(i, 0, K) + 1; n       Root = i; n     } n   } n   if (Root == 1) { n     cout << solve(1, 0, K) <<   n ; n     TRACE(1, 0, K); n     return 0; n   } n   cout << solve(Root, 0, K) + 1 <<   n ; n   cout << indPar[Root] <<   n ; n   TRACE(Root, 0, K); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n; n   string s = to_string(n); n   k = s.size() - 1; n   if (k > 0) { n     long long a = rint(pow(10, k)); n     long long z = rint(n / a); n     long long m = (z + 1) * a; n     cout << m - n; n   } else n     cout << 1; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n ll gcd(ll a, ll b){ n  return b?gcd(b,a%b):a; n } n ll a[200005],b[200005],c,d; n int main(){ n  ll n,m; n  scanf( %lld%lld ,&n,&m); n  ll d=0; n  cin>>a[1]; n  for(ll i=2;i<=n;i++){      //从a[2]-a[1]开始  n   scanf( %lld ,&a[i]); n   d=gcd(d,a[i]-a[i-1]);  //gcd(0,a)=a n  } n  for(ll i=1;i<=m;i++){ n   scanf( %lld ,&b[i]); n   ll dd=abs(gcd(d,a[1]+b[i])); n   printf( %lld  ,dd); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, a[10005], sum1 = 0, sum2 = 0; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] < 0) n       sum2++; n     else { n       if (a[i] == 0) n         sum1++; n       else n         cout << a[i] <<    ; n     } n   } n   sort(a + 1, a + n + 1); n   if (sum2 % 2 == 0) { n     for (int i = 1; i <= sum2; i++) { n       cout << a[i] <<    ; n     } n   } else { n     for (int i = 1; i <= sum2 - 1; i++) { n       cout << a[i] <<    ; n     } n   } n   if (n == 1 && a[1] <= 0) { n     cout << a[1]; n     return 0; n   } n   if (sum1 == n) cout << 0; n   if (sum1 + sum2 == n && sum2 == 1) cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2147483647; n const long long LLINF = 9223372036854775807LL; n const int maxn = 30010; n int a[maxn] = {}; n int used[maxn] = {}; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   vector<int> ans1, ans2; n   if (n == 2) { n     ans1.push_back(a[0]); n     ans2.push_back(a[1]); n     goto ooo; n   } n   if (n == 3) { n     ans1.push_back(a[0]); n     ans1.push_back(a[1]); n     ans2.push_back(a[2]); n     goto ooo; n   } n   if (n == 4) { n     ans1.push_back(a[0]); n     ans1.push_back(a[1]); n     ans2.push_back(a[2]); n     ans2.push_back(a[3]); n     goto ooo; n   } n   for (int i = 0; i < 5; ++i) n     for (int j = i + 1; j < 5; ++j) n       for (int k = j + 1; k < 5; ++k) { n         if (a[j] - a[i] == a[k] - a[j]) { n           memset(used, 0, sizeof(used)); n           used[i] = 1; n           used[j] = 1; n           used[k] = 1; n           int d = a[j] - a[i]; n           int cur = a[k] + d; n           int cused = 3; n           int lused = k; n           for (int t = k + 1; t < n; ++t) { n             if (a[t] == cur) { n               used[t] = 1; n               lused = t; n               cused++; n               cur += d; n             } n           } n           int pppp = 2; n           while (pppp--) { n             if (pppp == 0) used[lused] = 0; n             bool ok = true; n             int p1 = -1; n             int p2 = -1; n             int curd = 0; n             for (int t = 0; t < n; ++t) { n               if (used[t]) continue; n               int ccc = a[i]; n               if (curd == 0) { n                 if (p2 == -1) { n                   p2 = p1; n                   p1 = t; n                   if (p2 != -1) { n                     curd = a[p1] - a[p2]; n                   } n                 } n               } else { n                 if (a[t] - a[p1] != curd) { n                   ok = false; n                   break; n                 } else { n                   p1 = t; n                 } n               } n             } n             if (ok) { n               if (cused == n) used[0] = 0; n               for (int t = 0; t < n; ++t) { n                 if (used[t]) n                   ans1.push_back(a[t]); n                 else n                   ans2.push_back(a[t]); n               } n               goto ooo; n             } n           } n         } n       } n   printf( No solution ); n   return 0; n ooo: n   for (int i = 0; i < ans1.size(); ++i) printf( %d  , ans1[i]); n   printf(  n ); n   for (int i = 0; i < ans2.size(); ++i) printf( %d  , ans2[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( unroll-loops ) n #pragma GCC optimize( O2 ) n constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; n constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; n constexpr long long INF = 1999999999999999997; n constexpr int inf = INT_MAX; n constexpr int MAXSIZE = int(1e6) + 5; n constexpr auto PI = 3.14159265358979323846L; n constexpr auto oo = numeric_limits<int>::max() / 2 - 2; n constexpr auto eps = 1e-6; n constexpr auto mod = 1000000007; n constexpr auto MOD = 1000000007; n constexpr auto MOD9 = 1000000009; n constexpr auto maxn = 100006; n void fastio() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int n, m, k; n int fre; n char a[502][502]; n int x = -1, y = -1; n bool visited[502][502]; n int l; n void dfs(int x, int y) { n   if (l == 0) return; n   if (x + 1 < n && a[x + 1][y] ==  .  && !visited[x + 1][y] && l > 0) { n     visited[x + 1][y] = 1; n     l--; n     dfs(x + 1, y); n   } n   if (l == 0) return; n   if (y + 1 < m && a[x][y + 1] ==  .  && !visited[x][y + 1] && l > 0) { n     visited[x][y + 1] = 1; n     l--; n     dfs(x, y + 1); n   } n   if (l == 0) return; n   if (x - 1 >= 0 && a[x - 1][y] ==  .  && !visited[x - 1][y] && l > 0) { n     visited[x - 1][y] = 1; n     l--; n     dfs(x - 1, y); n   } n   if (l == 0) return; n   if (y - 1 < n && a[x][y - 1] ==  .  && !visited[x][y - 1] && l > 0) { n     visited[x][y - 1] = 1; n     l--; n     dfs(x, y - 1); n   } n   if (l == 0) return; n } n int main() { n   fastio(); n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  . ) { n         fre++; n         if (x == -1) { n           x = i, y = j; n         } n       } n     } n   } n   l = fre - k; n   int c = k; n   dfs(x, y); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  .  && !visited[i][j] && c > 0) { n         a[i][j] =  X ; n         c--; n       } n       cout << a[i][j]; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n  n #define fi first n #define se second n #define db double n #define U unsigned n #define P std::pair<int,int> n #define LL long long n #define pb push_back n #define MP std::make_pair n #define all(x) x.begin(),x.end() n #define CLR(i,a) memset(i,a,sizeof(i)) n #define FOR(i,a,b) for(int i = a;i <= b;++i) n #define ROF(i,a,b) for(int i = a;i >= b;--i) n #define DEBUG(x) std::cerr << #x <<  =  << x << std::endl n  n const int MAXN = 500+5; n int n,k; n int mn[26]; n std::string f[MAXN],str; n  n inline std::string ctos(char x){ n     return std::string(1,x); n } n  n inline void Solve(){ n     std::cin >> n >> k >> str;str =  0 +str; n     mn[0] = 0;FOR(i,1,k-2) mn[i] = i-1;mn[k-1] = 0; n     f[0].clear();FOR(i,1,n) f[i] =  { ; n     FOR(i,0,n-1){ n         f[i+1] = std::min(f[i+1],f[i]+ctos( a +mn[str[i+1]- a ])); n         if(i) f[i+1] = std::min(f[i+1],f[i].substr(0,i-1)+ctos(str[i+1])+f[i].back()); n         if(i != n-1) f[i+2] = std::min(f[i+2],f[i]+ctos( a +mn[str[i+2]- a ])+ctos(str[i+1])); n         if(i && i != n-1) f[i+2] = std::min(f[i+2],f[i].substr(0,i-1)+ctos(str[i+2])+f[i].back()+ctos(str[i+1])); n     } n     std::cout << f[n] << std::endl; n } n  n int main(){ n     std::ios::sync_with_stdio(false); n     int T;std::cin >> T; n     while(T--) Solve(); n     return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimization( O3 ) n using namespace std; n template <typename T> n inline void Cin(T& first) { n   char c; n   T sign = 1; n   first = 0; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ; n   first *= sign; n } n template <typename T> n inline void Out(T first) { n   if (first > 9) Out(first / 10); n   putchar(first % 10 +  0 ); n } n template <typename T> n inline void Cout(T first, char c) { n   if (first < 0) putchar( - ); n   first = abs(first); n   Out(first); n   putchar(c); n } n template <typename T, typename... Args> n inline void Cin(T& a, Args&... args) { n   Cin(a); n   Cin(args...); n } n template <typename T, typename... Args> n inline void Cout(T a, char c, Args... args) { n   Cout(a, c); n   Cout(args...); n } n const int mod = int(1e9) + 7; n const int N = 2050; n int f[N][N], a[N], n, k, nState; n void Enter() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n } n void add(int& first, int second) { n   if ((first += second) >= mod) first -= mod; n } n void Solve() { n   nState = 1 << k, f[0][0] = 1; n   for (int i = 1; i <= n; ++i) { n     for (int bit = 0; bit <= nState; ++bit) { n       if (!f[i - 1][bit]) continue; n       if (a[i] == 2 || a[i] == 0) { n         if (bit + 2 >= nState) n           add(f[i][nState], f[i - 1][bit]); n         else n           add(f[i][bit + 2], f[i - 1][bit]); n       } n       if (a[i] == 4 || a[i] == 0) { n         if ((bit >> 1) & 1) n           add(f[i][4], f[i - 1][bit]); n         else { n           if (bit + 4 >= nState) n             add(f[i][nState], f[i - 1][bit]); n           else n             add(f[i][bit + 4], f[i - 1][bit]); n         } n       } n     } n   } n   cout << f[n][nState]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( test  n              .inp , n              r )) { n     freopen( n          test  n          .inp , n          r , stdin); n     freopen( n          test  n          .out , n          w , stdout); n   } n   Enter(), Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1.0); n int a[32][101111], n, m, d[32][111111], b[111111], t[400111]; n pair<pair<int, int>, int> p[111111]; n int bit(int mask, int i) { return (mask & (1 << i)) > 0; } n void build(int v, int tl, int tr) { n   if (tl == tr) n     t[v] = b[tl]; n   else { n     int tm = (tl + tr) / 2; n     build(v * 2, tl, tm); n     build(v * 2 + 1, tm + 1, tr); n     t[v] = (t[v * 2] & t[v * 2 + 1]); n   } n } n int get(int v, int tl, int tr, int l, int r) { n   if (l > r) return (1 << 30) - 1; n   if (l == tl && r == tr) return t[v]; n   int tm = (tl + tr) / 2; n   return get(v * 2, tl, tm, l, min(r, tm)) & n          get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r); n } n int main() { n   scanf( %d%d , &n, &m); n   int len = (int)sqrt(n + .0) + 1; n   for (int cs = 0; cs < m; ++cs) { n     int l, r, q; n     scanf( %d%d%d , &l, &r, &q); n     p[cs] = make_pair(make_pair(l, r), q); n     for (int j = 0; j < 30; ++j) { n       int w = bit(q, j); n       if (w == 0) continue; n       a[j][l]++; n       a[j][r + 1]--; n     } n   } n   for (int i = 0; i < 30; ++i) { n     int second = 0; n     for (int j = 1; j <= n; ++j) { n       second += a[i][j]; n       a[i][j] = a[i][j - 1] + second; n     } n   } n   for (int i = 1; i <= n; ++i) { n     int ans = 0; n     for (int j = 0; j < 30; ++j) ans += (1 << j) * (a[j][i] - a[j][i - 1] > 0); n     b[i] = ans; n   } n   build(1, 1, n); n   for (int i = 0; i < m; ++i) { n     int l = p[i].first.first, r = p[i].first.second, q = p[i].second; n     if (get(1, 1, n, l, r) != q) { n       puts( NO ); n       return 0; n     } n   } n   puts( YES ); n   for (int i = 1; i <= n; ++i) printf( %d  , b[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n map<int, int> memo; n int solve(int mask) { n   if (!mask) return 0; n   if (memo.find(mask) != memo.end()) return memo[mask]; n   map<int, bool> canreach; n   for (int i = 0; i < 32; i++) { n     int aux = ((1 << i) - 1) & mask; n     int ns = aux | ((mask - aux) >> (i + 1)); n     if (ns == mask) continue; n     canreach[solve(ns)] = true; n   } n   int mex = 0; n   for (int i = 0; i < 100; i++) n     if (!canreach[i]) { n       mex = i; n       break; n     } n   return memo[mask] = mex; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   map<int, int> mps; n   for (int j = 0; j < n; j++) { n     int val, aux; n     cin >> val; n     aux = val; n     for (int i = 2; i * i <= val; i++) { n       int cnt = 0; n       while (aux % i == 0) { n         aux /= i; n         cnt++; n       } n       if (cnt) mps[i] |= (1 << (cnt - 1)); n     } n     if (aux != 1) mps[aux] |= 1; n   } n   int grundy = 0; n   for (auto u : mps) grundy ^= solve(u.second); n   cout << (grundy ?  Mojtaba  :  Arpa ) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n int a[1000005]; n vector<int> x; n void solve() { n   int sum = 0, ans; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   int l = 1, r = 1e7; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (mid * n >= sum) { n       r = mid - 1; n       ans = mid; n     } else { n       l = mid + 1; n     } n   } n   x.push_back(ans); n } n int main() { n   cin >> t; n   while (t--) solve(); n   for (int i = 0; i < x.size(); i++) { n     cout << x[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     long long a, b, n; n     cin >> a >> b >> n; n     if (a < b) swap(a, b); n     int ans = 0; n     while (a <= n) { n       b += a; n       if (a < b) swap(a, b); n       ans++; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, jump[100005]; n   bool visited[100005]; n   string s; n   cin >> n; n   cin >> s; n   for (int i = 0; i < n; i++) cin >> jump[i]; n   int pos = 0; n   fill(visited, visited + n, false); n   while (!visited[pos]) { n     visited[pos] = true; n     if (s[pos] ==  > ) n       pos += jump[pos]; n     else if (s[pos] ==  < ) n       pos -= jump[pos]; n     if (pos < 0 || pos >= n) { n       cout <<  FINITE  << endl; n       return 0; n     } n   } n   cout <<  INFINITE  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n double PI = 3.141592653589793238462643383279; n const double EPS = 1e-9; n const long long MOD = 1000000007; n const int inf = 1 << 30; n const long long linf = 1LL << 60; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n namespace LCA { n vector<vector<int>> G; n int root; n int MAX_LOG_N; n vector<vector<int>> parent; n vector<int> depth; n void dfs(int v, int p, int d) { n   parent[0][v] = p; n   depth[v] = d; n   for (int i = 0; i < (int)G[v].size(); i++) { n     if (G[v][i] != p) dfs(G[v][i], v, d + 1); n   } n } n void init(int V, vector<vector<int>> _G, int root) { n   { n     int tmp = 1; n     MAX_LOG_N = 1; n     while (tmp <= V) { n       tmp *= 2; n       MAX_LOG_N++; n     } n   } n   parent.resize(MAX_LOG_N, vector<int>(V)); n   depth.resize(V); n   G = _G; n   dfs(root, -1, 0); n   for (int k = 0; k + 1 < MAX_LOG_N; k++) { n     for (int v = 0; v < V; v++) { n       if (parent[k][v] < 0) n         parent[k + 1][v] = -1; n       else n         parent[k + 1][v] = parent[k][parent[k][v]]; n     } n   } n } n int get_kth_parent(int v, int k) { n   for (int i = MAX_LOG_N - 1; i >= 0; i--) { n     if ((1 << i) > k) continue; n     v = parent[i][v]; n     k -= (1 << i); n   } n   return v; n } n int lca(int u, int v) { n   if (depth[u] > depth[v]) swap(u, v); n   for (int k = 0; k < MAX_LOG_N; k++) { n     if ((depth[v] - depth[u]) >> k & 1) { n       v = parent[k][v]; n     } n   } n   if (u == v) return u; n   for (int k = MAX_LOG_N - 1; k >= 0; k--) { n     if (parent[k][u] != parent[k][v]) { n       u = parent[k][u]; n       v = parent[k][v]; n     } n   } n   return parent[0][u]; n } n }  // namespace LCA n int n; n vector<vector<int>> e; n vector<pair<int, int>> e2[200000]; n int ord[200000]; n int v[200000], s[200000], u[200000]; n int rv[200000], ru[200000]; n long long dist[200000]; n int infe[200000]; n void dfs(int v, int p, int& pos) { n   ord[v] = pos++; n   for (int to : e[v]) { n     if (to == p) continue; n     dfs(to, v, pos); n   } n } n int main() { n   scanf( %d , &n); n   e.resize(n); n   for (int i = 0; i < (int)n - 1; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--; n     y--; n     e[x].push_back(y); n     e[y].push_back(x); n   } n   int tmp = 0; n   dfs(0, -1, tmp); n   LCA::init(n, e, 0); n   int q; n   scanf( %d , &q); n   memset(rv, -1, sizeof(rv)); n   memset(ru, -1, sizeof(ru)); n   for (int i = 0; i < (int)q; i++) { n     int k, m; n     scanf( %d%d , &k, &m); n     vector<int> vers(k + m); n     for (int j = 0; j < (int)k; j++) { n       scanf( %d%d , v + j, s + j); n       v[j]--; n       vers[j] = v[j]; n       rv[v[j]] = j; n     } n     for (int j = 0; j < (int)m; j++) { n       scanf( %d , u + j); n       u[j]--; n       vers[j + k] = u[j]; n       ru[u[j]] = j; n     } n     sort(vers.begin(), vers.end(), n          [&](const int& l, const int& r) { return ord[l] < ord[r]; }); n     for (int j = 1; j < k + m; j++) { n       int com = LCA::lca(vers[j - 1], vers[j]); n       vers.push_back(com); n     } n     sort(vers.begin(), vers.end()); n     vers.erase(unique(vers.begin(), vers.end()), vers.end()); n     int N = vers.size(); n     sort(vers.begin(), vers.end(), n          [&](const int& l, const int& r) { return ord[l] < ord[r]; }); n     vector<int> sta; n     sta.push_back(vers[0]); n     for (int j = 1; j < N; j++) { n       while (true) { n         if (LCA::lca(sta.back(), vers[j]) == sta.back()) break; n         sta.pop_back(); n       } n       e2[sta.back()].push_back(pair<int, int>( n           vers[j], LCA::depth[vers[j]] - LCA::depth[sta.back()])); n       e2[vers[j]].push_back(pair<int, int>( n           sta.back(), LCA::depth[vers[j]] - LCA::depth[sta.back()])); n       sta.push_back(vers[j]); n     } n     priority_queue<pair<pair<long long, long long>, int>, n                    vector<pair<pair<long long, long long>, int>>, n                    greater<pair<pair<long long, long long>, int>>> n         que; n     for (int ve : vers) { n       dist[ve] = linf; n       infe[ve] = -1; n       if (rv[ve] != -1) { n         dist[ve] = 0; n         infe[ve] = rv[ve]; n         que.push(pair<pair<long long, long long>, int>( n             pair<long long, long long>( n                 (dist[ve] + s[infe[ve]] - 1) / s[infe[ve]], infe[ve]), n             ve)); n       } n     } n     while (!que.empty()) { n       pair<pair<long long, long long>, int> q = que.top(); n       que.pop(); n       for (pair<int, int> E : e2[q.second]) { n         int to = E.first, cost = E.second; n         if (infe[to] == -1) { n           dist[to] = dist[q.second] + cost; n           infe[to] = infe[q.second]; n           que.push(pair<pair<long long, long long>, int>( n               pair<long long, long long>( n                   (dist[to] + s[infe[to]] - 1) / s[infe[to]], infe[to]), n               to)); n           continue; n         } n         long long ti = (dist[to] + s[infe[to]] - 1) / s[infe[to]]; n         if (pair<long long, long long>(ti, infe[to]) > n             pair<long long, long long>( n                 (dist[q.second] + cost + s[infe[q.second]] - 1) / n                     s[infe[q.second]], n                 infe[q.second])) { n           dist[to] = dist[q.second] + cost; n           infe[to] = infe[q.second]; n           que.push(pair<pair<long long, long long>, int>( n               pair<long long, long long>( n                   (dist[to] + s[infe[to]] - 1) / s[infe[to]], infe[to]), n               to)); n         } n       } n     } n     vector<int> out(m); n     for (int ve : vers) { n       if (ru[ve] == -1) continue; n       out[ru[ve]] = infe[ve] + 1; n     } n     for (int o : out) printf( %d  , o); n     puts(  ); n     for (int ve : vers) e2[ve].clear(); n     for (int j = 0; j < (int)k; j++) { n       rv[v[j]] = -1; n     } n     for (int j = 0; j < (int)m; j++) { n       ru[u[j]] = -1; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[105][105], b, c, d, e, f, g, h, i, j, k, l, m, n; n inline bool pd(int x, int y, int s) { n   return a[x - 1][y] == s || a[x + 1][y] == s || a[x][y - 1] == s || n          a[x][y + 1] == s; n } n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) n       if (!a[i][j]) { n         if (i == 3 && j == 21) { n           k = 1; n         } n         for (k = 1; k <= 26; k++) n           if (!pd(i, j, k)) { n             for (l = 1; l <= n; l++) { n               if (i + l > n || j + l > m) break; n               d = 0; n               for (g = j; g <= j + l; g++) n                 if (a[i + l][g] || pd(i + l, g, k)) { n                   d = 1; n                   break; n                 } n               if (d) break; n               for (g = i; g <= i + l; g++) n                 if (a[g][j + l] || pd(g, j + l, k)) { n                   d = 1; n                   break; n                 } n               if (d) break; n               for (g = 1; g < k; g++) n                 if (!pd(i, j + l, g)) d = 1; n               if (d) break; n             } n             l--; n             for (d = i; d <= i + l; d++) n               for (e = j; e <= j + l; e++) a[d][e] = k; n             break; n           } n       } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) putchar(a[i][j] +  A  - 1); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h, q, v, e; n string s; n map<int, int> xx; n inline double dfs(int x, int mx) { n   if (xx[x] <= mx) return mx; n   return 0.5 * (dfs(x << 1, max(mx, xx[x] - xx[x << 1])) + n                 dfs(x << 1 | 1, max(mx, xx[x] - xx[x << 1 | 1]))); n } n int main() { n   scanf( %d%d , &h, &q); n   while (q--) { n     cin >> s; n     if (s[0] ==  a ) { n       scanf( %d%d , &v, &e); n       while (v) xx[v] += e, v >>= 1; n     } else n       printf( %.8lf n , dfs(1, 0)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[200000]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int odd = 0, even = 0; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] & 1) n         odd++; n       else n         even++; n     } n     if (odd == 0 or (even == 0 and n % 2 == 0)) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, j, n, m, a, b, s = 0, e1, e2, o1, o2; n   long long t; n   cin >> t; n   while (t--) { n     e1 = e2 = o1 = o2 = 0; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a; n       if (a & 1) n         o1++; n       else n         e1++; n     } n     cin >> m; n     for (int i = 0; i < m; i++) { n       cin >> b; n       if (b & 1) n         o2++; n       else n         e2++; n     } n     cout << o1 * o2 + e1 * e2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 400050; n int n, x; n long long w; n vector<long long> val[4]; n int Abs(int a) { return a < 0 ? -a : a; } n int main() { n   scanf( %d , &n); n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d%I64d , &x, &w); n     if (x == 11) n       val[0].push_back(w), sum += w; n     else if (x == 1) n       val[1].push_back(w), sum += w; n     else if (x == 10) n       val[2].push_back(w), sum += w; n     else n       val[3].push_back(w); n   } n   int len = val[3].size(); n   int cnt = n - len; n   int num = min(val[1].size(), val[2].size()); n   num += val[0].size(); n   for (int i = 0; i < 4; i++) sort(val[i].begin(), val[i].end()); n   long long ans = sum; n   int now1 = 0, now2 = 0; n   if (num * 2 < cnt) { n     ans = 0; n     int no = Abs(val[1].size() - val[2].size()); n     if (val[2].size() < val[1].size()) { n       for (int i = 0; i < no; i++) { n         if (num * 2 >= cnt) break; n         sum -= val[1][i]; n         cnt--; n         now1++; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } else { n       for (int i = 0; i < no; i++) { n         if (num * 2 >= cnt) break; n         sum -= val[2][i]; n         cnt--; n         now2++; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } n     if (num * 2 >= cnt) ans = max(ans, sum); n   } n   if (num * 2 > cnt) { n     ans = sum; n     int pos = 1; n     while (num * 2 >= cnt) { n       if (pos > len) break; n       if (num * 2 >= (cnt + 1)) { n         sum += val[3][len - pos]; n         ans = max(ans, sum); n         cnt++; n       } else n         break; n       pos++; n     } n     if (num * 2 >= cnt) ans = max(ans, sum); n     int no = Abs(val[2].size() - val[1].size()); n     if (val[2].size() > val[1].size()) { n       for (int i = now2; i < no; i++) { n         if (pos + i - now2 > len) break; n         sum -= val[2][i]; n         sum += val[3][len - i + now2 - pos]; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } else { n       for (int i = now1; i < no; i++) { n         if (pos + i - now1 > len) break; n         sum -= val[1][i]; n         sum += val[3][len - i + now1 - pos]; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } n   } else if (num * 2 == cnt) { n     int no = Abs(val[2].size() - val[1].size()); n     if (val[2].size() > val[1].size()) { n       for (int i = now2; i < no; i++) { n         if (i - now2 >= len) break; n         sum -= val[2][i]; n         sum += val[3][len - i + now2 - 1]; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } else { n       for (int i = now1; i < no; i++) { n         if (i - now1 >= len) break; n         sum -= val[1][i]; n         sum += val[3][len - i + now1 - 1]; n         if (num * 2 >= cnt) ans = max(ans, sum); n       } n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, c; n   cin >> r; n   cin >> c; n   vector<vector<bool> > a(r); n   for (int i = 0; i < r; i++) a[i].resize(c); n   char t_c; n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       cin >> t_c; n       if (t_c ==  . ) n         a[i][j] = true; n       else n         a[i][j] = false; n     } n   } n   vector<vector<bool> > b(r); n   vector<vector<bool> > d(r); n   b = a; n   d = a; n   b[0][0] = true; n   d[r - 1][c - 1] = true; n   for (int i = 1; i <= r + c - 2; i++) { n     for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) { n       b[j][i - j] = false; n       if (a[j][i - j] == true) { n         if (j != 0) n           if (b[j - 1][i - j] == true) b[j][i - j] = true; n         if (i - j != 0) n           if (b[j][i - j - 1] == true) b[j][i - j] = true; n       } n     } n   } n   for (int i = r + c - 3; i >= 0; i--) { n     for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) { n       d[j][i - j] = false; n       if (a[j][i - j] == true) { n         if (j != r - 1) n           if (d[j + 1][i - j] == true) d[j][i - j] = true; n         if (i - j != c - 1) n           if (d[j][i - j + 1] == true) d[j][i - j] = true; n       } n     } n   } n   bool weak = false; n   for (int i = 1; i <= r + c - 3; i++) { n     int cnt1 = 0; n     for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) { n       if (b[j][i - j] && d[j][i - j]) cnt1++; n     } n     if (cnt1 < 2) weak = true; n   } n   if (!d[0][0]) n     cout <<  0 ; n   else if (weak) n     cout <<  1 ; n   else n     cout <<  2 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100 + 5; n const long long MOD = 1000000007; n long long pow2[MAXN]; n char x[MAXN]; n int main() { n   scanf( %s , x); n   int n = strlen(x); n   pow2[0] = 1; n   for (int i = 1; i < n; i++) pow2[i] = (pow2[i - 1] * 2) % MOD; n   long long d = pow2[n - 1], ans = 0; n   for (int i = 0; i < n; i++) n     if (x[i] ==  1 ) ans = (ans + pow2[n - i - 1] * d) % MOD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1000000 + 20; n int pos[MAX_N], mark[MAX_N]; n int inter[MAX_N]; n set<int> D; n long long ans; n int n, k; n void add(int x) { n   for (; x <= n; x += x & (-x)) ++inter[x]; n } n int get(int x) { n   if (x < 1) return 0; n   int res = 0; n   for (; x > 0; x -= x & (-x)) res += inter[x]; n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     pos[x] = i + 1; n   } n   for (int i = 0; i < k; ++i) { n     int x; n     cin >> x; n     mark[x] = 1; n   } n   D.insert(0); n   D.insert(n + 1); n   for (int i = 1; i <= n; ++i) { n     if (mark[i]) n       D.insert(pos[i]); n     else { n       int l, r; n       set<int>::iterator it = D.lower_bound(pos[i]); n       r = *it - 1; n       --it; n       l = *it + 1; n       ans += r - l + 1 - get(r) + get(l - 1); n       add(pos[i]); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long inf = 1e18 + 9; n const long long MAX_SIZE = 1e7 + 1; n long long _t = 1, _T, csn; n long long max(long long a, long long b) { n   if (a < b) return b; n   return a; n } n long long min(long long a, long long b) { n   if (a > b) return b; n   return a; n } n long long mmi(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long nxor(long long n) { n   if (n % 4 == 0) return n; n   if (n % 4 == 1) return 1; n   if (n % 4 == 2) return n + 1; n   return 0; n } n long long sum(long long n) { return ((n * (n + 1)) / 2); } n long long modsum(long long n, long long m) { n   long long ans = n % m; n   ans *= (n + 1) % m; n   ans %= m; n   ans *= mmi(2, m); n   return ans % m; n } n long long leap(long long y) { n   if (y % 400 == 0) n     return 1; n   else if (y % 100 == 0) n     return 0; n   else if (y % 4 == 0) n     return 1; n   else n     return 0; n } n void solve(); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   bool multicases = 0; n   if (multicases) cin >> _t; n   _T = _t; n   while (_t--) solve(); n   return 0; n } n void solve() { n   csn = _T - _t; n   long long n; n   cin >> n; n   ; n   map<string, long long> m; n   string s, ts; n   vector<vector<pair<long long, string>>> ans; n   for (long long i = 0; i < n; i += 1) { n     cin >> s; n     vector<pair<long long, string>> tv; n     for (long long j = 0; j < 9; j += 1) { n       for (long long k = 1; k < 9 - j + 1; k += 1) { n         ts = s.substr(j, k); n         m[ts]++; n         tv.emplace_back(make_pair(k, ts)); n       } n     } n     sort(tv.begin(), tv.end()); n     for (long long j = 1; j < tv.size(); j += 1) n       if (tv[j].second == tv[j - 1].second) m[tv[j].second]--; n     ans.emplace_back(tv); n   } n   for (long long i = 0; i < n; i += 1) { n     for (long long j = 0; j < ans[i].size(); j += 1) n       if (m[ans[i][j].second] == 1) { n         cout << ans[i][j].second <<   n ; n         ; n         break; n       } n   } n   return; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 9; n const int L = 20; n int par[N][L]; n int up[N][L]; n int h[N]; n int to[N]; n int s[N], t[N]; n pair<int, int> edge[N]; n vector<pair<int, int> > al[N]; n int find(int v) { n   if (to[v] == v) return v; n   return to[v] = find(to[v]); n } n int unite(int u, int v) { n   u = find(u), v = find(v); n   to[u] = v; n   return (u != v); n } n void dfs(int v, int p = -1) { n   h[v] = (p + 1 ? h[p] + 1 : 0); n   par[v][0] = p; n   for (int i = 1; i < L; i++) { n     if (par[v][i - 1] + 1) { n       par[v][i] = par[par[v][i - 1]][i - 1]; n       up[v][i] = max(up[v][i - 1], up[par[v][i - 1]][i - 1]); n     } n   } n   for (int i = 0; i < al[v].size(); i++) { n     int u = al[v][i].first; n     if (u == p) continue; n     up[u][0] = al[v][i].second; n     dfs(u, v); n   } n   return; n } n pair<int, int> go_up(int v, int x) { n   int mx = 0; n   for (int b = 0; b < L; b++) n     if (x >> b & 1) mx = max(mx, up[v][b]), v = par[v][b]; n   return {v, mx}; n } n int lca(int u, int v) { n   if (h[u] < h[v]) swap(u, v); n   u = go_up(u, h[u] - h[v]).first; n   if (u == v) return v; n   for (int b = L - 1; ~b; --b) n     if (par[v][b] != par[u][b]) v = par[v][b], u = par[u][b]; n   return par[v][0]; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) to[i] = i; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     --u, --v; n     s[i] = u, t[i] = v; n     edge[i] = {w, i}; n   } n   sort(edge, edge + m); n   long long ans = 0; n   int p = 0; n   for (int i = 0; i < m; i++) { n     long long w = edge[i].first, id = edge[i].second; n     int u = s[id], v = t[id]; n     if (unite(u, v)) { n       ans += w, p++; n       al[u].push_back({v, w}); n       al[v].push_back({u, w}); n     } n   } n   dfs(0); n   int q; n   cin >> q; n   while (q--) { n     int u, v; n     cin >> u >> v; n     --u, --v; n     int pu = find(u), pv = find(v); n     if ((p == n - 2 && pu == pv) || p < n - 2) { n       cout << -1 <<   n ; n       continue; n     } n     if (p == n - 2) { n       cout << ans <<   n ; n       continue; n     } n     int lc = lca(u, v); n     cout << ans - max(go_up(u, h[u] - h[lc]).second, n                       go_up(v, h[v] - h[lc]).second) n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1999999999; n const double pi = acos(-1.0); n const double eps = 1e-10; n char gc() { n   char c; n   while (isspace(c = getchar())) n     ; n   return c; n } n int gs(char* s) { n   gets(s); n   int l = strlen(s); n   while (l && isspace(s[l - 1])) s[--l] = 0; n   return l; n } n int n; n double p[101]; n double isok(double a) { n   double tmn = 1e20, tmx = -1e20; n   for (int i = 0; i <= n; i++) { n     if (i * 2 > n) tmx = max(tmx, (p[i] - a) / (i - n / 2.)); n     if (i * 2 < n) tmn = min(tmn, (a - p[i]) / (n / 2. - i)); n   } n   return tmn < tmx; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) scanf( %lf , &p[i]); n   double low = -0.001, mid, high = 1.001; n   if ((n % 2) == 0) low = p[n / 2]; n   for (int i = 0; i < 60; i++) { n     mid = (low + high) / 2; n     if (isok(mid)) n       low = mid; n     else n       high = mid; n   } n   printf( %.10f n , (low + high) / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<vector<string> > tab(9); n   int emp[3][3]; n   memset(emp, 0, sizeof emp); n   for (int i = 0; i < 9; i++) { n     tab[i].resize(3); n     for (int j = 0; j < 3; j++) { n       string a; n       cin >> a; n       for (int k = 0; k < a.size(); k++) { n         if (a[k] ==  . ) emp[i / 3][j]++; n       } n       tab[i][j] = a; n     } n   } n   int n, m; n   cin >> n >> m; n   n--; n   m--; n   char ne; n   int ln = n, lm = (m + 1) % 3; n   if (tab[ln][lm][m % 3] ==  x ) n     ne =  o ; n   else n     ne =  x ; n   n = n % 3; n   m = m % 3; n   if (emp[n][m] == 0) { n     for (int i = 0; i < 9; i++) { n       for (int j = 0; j < 3; j++) { n         string a = tab[i][j]; n         for (int k = 0; k < 3; k++) { n           if (a[k] ==  . ) tab[i][j][k] =  ! ; n         } n       } n     } n   } else { n     for (int i = n * 3; i < (n + 1) * 3; i++) { n       string a = tab[i][m]; n       for (int j = 0; j < 3; j++) { n         if (a[j] ==  . ) tab[i][m][j] =  ! ; n       } n     } n   } n   for (int i = 0; i < 9; i++) { n     if (i != 0 && i % 3 == 0) cout << endl; n     for (int j = 0; j < 3; j++) { n       cout << tab[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e6 + 10; n const long long INF = 8e18; n const long long MOD = 1e9 + 7; n inline long long poww(long long a, long long b) { n   a %= MOD; n   long long ans = 1; n   while (b > 0) { n     if (b & 1) ans = ans * a % MOD; n     b >>= 1; n     a = a * a % MOD; n   } n   return ans; n } n long long fact[MAXN], inv[MAXN], n, k, ans, F[MAXN]; n inline long long C(int k, int n) { n   return fact[n] * inv[k] % MOD * inv[n - k] % MOD; n } n inline void mkey(long long& a) { n   if (a >= MOD) a -= MOD; n   if (a < 0) a += MOD; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   fact[0] = inv[0] = 1; n   for (int i = 1; i < MAXN; i++) n     fact[i] = fact[i - 1] * i % MOD, inv[i] = poww(fact[i], MOD - 2); n   F[0] = 1; n   for (int i = 1; i <= n; i++) { n     F[i] = i * F[i - 1] % MOD; n     if (i > k) mkey(F[i] -= C(k, i - 1) * fact[k] % MOD * F[i - k - 1] % MOD); n   } n   for (int i = 1; i <= n; i++) n     mkey(ans += C(i - 1, n - 1) * F[i - 1] % MOD * fact[n - i] % MOD); n   cout << (fact[n] - ans + MOD) % MOD <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[105], c[105]; n int findz(int n) { return a[n] == n ? a[n] : a[n] = findz(a[n]); } n void un(int x, int y) { a[findz(x)] = findz(y); } n int main() { n   int n, l, f; n   cin >> n >> l; n   int count = 0; n   int wei = 0; n   memset(c, 0, sizeof(c)); n   for (int i = 1; i <= l; i++) a[i] = i; n   for (int i = 0; i < n; i++) { n     int z; n     cin >> z; n     if (z >= 1) { n       cin >> f; n       c[f]++; n     } else n       count++; n     for (int j = 1; j < z; j++) { n       int b; n       cin >> b; n       c[b]++; n       un(f, b); n     } n   } n   set<int> s; n   for (int i = 1; i <= l; i++) { n     s.insert(findz(i)); n     if (c[i] == 0) wei++; n   } n   if (s.size() - wei == 0) { n     cout << count; n   } else { n     cout << count + s.size() - wei - 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long mod(long long n) { return (n % 1000000007); } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n; n   vector<long long> v(n); n   map<long long, long long> has, cnt; n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n   } n   cin >> m; n   for (long long i = 0; i < m; i++) { n     long long x; n     cin >> x; n     has[v[x - 1]]++; n   } n   long long sz = has.size(); n   while (v.size() < n + 5 * m) { n     for (long long i = n - 2; i >= 0; i--) v.push_back(v[i]); n     for (long long i = 1; i < n; i++) v.push_back(v[i]); n   } n   set<long long> possible; n   long long cur = 0; n   long long match = 0; n   for (long long i = 0; i < m; i++) { n     if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--; n     cnt[v[i]]++; n     if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++; n     cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0)); n     if (i == 0) cur -= v[i]; n     if (match == sz) possible.insert(cur); n   } n   for (long long i = m; i < n + 5 * m; i++) { n     if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match--; n     cnt[v[i - m]]--; n     if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match++; n     if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--; n     cnt[v[i]]++; n     if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++; n     cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0)); n     cur -= abs(v[i - m + 1] - (i - m >= 0 ? v[i - m] : 0)); n     if (match == sz) possible.insert(cur); n   } n   if (possible.size() > 1) n     cout << -1 <<   n ; n   else if (possible.size() == 0) n     cout << -1 <<   n ; n   else n     cout << *possible.begin() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int invertir(int n) { n   int r = 0; n   while (n > 0) { n     r = r * 10 + (n % 10); n     n = n / 10; n   } n   return r; n } n int main() { n   int a, b; n   cin >> a >> b; n   cout << (a + invertir(b)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n int m; n const long long mod = 1e9 + 7; n struct Mat { n   long long mat[111][111]; n } st, ed; n long long stt[111][111]; n void init() { n   memset(stt, 0, sizeof(stt)); n   stt[0][0] = stt[0][m - 1] = 1; n   for (int i = 1; i < m; ++i) stt[i][i - 1] = 1; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < m; ++j) st.mat[i][j] = stt[i][j]; n } n Mat mul(Mat a, Mat b) { n   Mat ret; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < m; ++j) { n       ret.mat[i][j] = 0; n       for (int k = 0; k < m; ++k) n         (ret.mat[i][j] += a.mat[i][k] * b.mat[k][j] % mod) %= mod; n     } n   return ret; n } n Mat pow(Mat a, long long b) { n   Mat ret; n   memset(ret.mat, 0, sizeof(ret.mat)); n   for (int i = 0; i < m; ++i) ret.mat[i][i] = 1; n   while (b) { n     if (b & 1) ret = mul(ret, a); n     a = mul(a, a); n     b >>= 1; n   } n   return ret; n } n int main() { n   cin >> n >> m; n   if (n < m) return 0 * puts( 1 ); n   init(); n   ed = pow(st, n - m + 1); n   long long ans = 0; n   for (int i = 0; i < m; ++i) (ans += ed.mat[0][i]) %= mod; n   cout << ans << (  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n long long a_na_b_mod_c(long long a, long long b, long long c) { n   if (b == 0) return 1; n   long long t = a_na_b_mod_c(a, (b / 2), c) % c; n   if (b % 2 == 0) n     return (t * t) % c; n   else n     return (((t * t) % c) * (a % c)) % c; n } n long long ip(long long a) { return a_na_b_mod_c(a, mod - 2, mod); } n vector<long long> f(1, 1), fi; n long long nCk(long long n, long long k) { n   return (((f[n] * fi[k]) % mod) * fi[n - k]) % mod; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   long long k; n   cin >> n >> k; n   if (!k) { n     cout <<  0 n ; n     return 0; n   } n   for (int i = 1; i < n + 79; i++) f.push_back((f.back() * i) % mod); n   fi.resize(n + 79); n   for (int i = 0; i < n + 79; i++) fi[i] = ip(f[i]); n   vector<int> h(n); n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n   } n   h.push_back(h[0]); n   long long eq = 0; n   for (int i = 1; i <= n; i++) { n     if (h[i] == h[i - 1]) eq++; n   } n   long long dif = n - eq; n   if (!dif) { n     cout <<  0 n ; n     return 0; n   } n   long long all = 0; n   long long i2 = ip(2); n   long long p2 = a_na_b_mod_c(2, dif, mod); n   long long kp2 = 1; n   for (long long z = 0; z < dif; z++) { n     long long non_zero = dif - z; n     long long good = p2; n     long long zero = non_zero % 2 == 1 ? 0 : nCk(non_zero, non_zero >> 1); n     good = ((good - zero + mod) * i2) % mod; n     all += (((good * nCk(dif, z)) % mod) * kp2) % mod; n     all %= mod; n     p2 = (p2 * i2) % mod; n     kp2 = (kp2 * (k - 2)) % mod; n   } n   cout << (all * a_na_b_mod_c(k, eq, mod)) % mod <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   set<int> s; n   s.insert(0); n   int a; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     if (s.find(a) != s.end()) { n       s.erase(a); n     } n     s.insert(i); n   } n   cout << s.size(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100050; n struct node { n   int sa, ea, sb, eb; n } a[N]; n int t[N << 1], rt1[N << 1], rt2[N << 1], lc[N * 80], rc[N * 80], tot, n, m1, m2; n bool cnt[N * 80], addv[N * 80]; n inline bool cmp1(const node &a, const node &b) { return a.ea < b.ea; } n inline bool cmp2(const node &a, const node &b) { return a.sa < b.sa; } n int add(int pre, int L, int R, int x, int y) { n   if (addv[pre]) return pre; n   int o = ++tot; n   cnt[o] = 1; n   if (x <= L && y >= R) { n     addv[o] = 1; n     lc[o] = lc[pre]; n     rc[o] = rc[pre]; n   } else { n     int M = L + R >> 1; n     addv[o] = 0; n     if (x <= M) n       lc[o] = add(lc[pre], L, M, x, y); n     else n       lc[o] = lc[pre]; n     if (y > M) n       rc[o] = add(rc[pre], M + 1, R, x, y); n     else n       rc[o] = rc[pre]; n   } n   return o; n } n bool ask(int o, int L, int R, int x, int y) { n   if (addv[o]) return 0; n   if (x <= L && y >= R) return !cnt[o]; n   int M = L + R >> 1; n   return (x > M || ask(lc[o], L, M, x, y)) && n          (y <= M || ask(rc[o], M + 1, R, x, y)); n } n inline bool check() { n   int i, k = 1; n   memset(rt1, 0, sizeof(rt1)); n   memset(rt2, 0, sizeof(rt2)); n   tot = 0; n   sort(a + 1, a + n + 1, cmp1); n   for (i = 1; i <= (m1); ++i) { n     rt1[i] = rt1[i - 1]; n     for (; k <= n && a[k].ea == i; ++k) n       rt1[i] = add(rt1[i], 1, m2, a[k].sb, a[k].eb); n   } n   sort(a + 1, a + n + 1, cmp2); n   k = n; n   for (i = m1; i >= (1); --i) { n     rt2[i] = rt2[i + 1]; n     for (; k && a[k].sa == i; --k) n       rt2[i] = add(rt2[i], 1, m2, a[k].sb, a[k].eb); n   } n   for (i = 1; i <= (n); ++i) n     if (!ask(rt1[a[i].sa - 1], 1, m2, a[i].sb, a[i].eb) || n         !ask(rt2[a[i].ea + 1], 1, m2, a[i].sb, a[i].eb)) { n       puts( NO ); n       return 0; n     } n   return 1; n } n int main() { n   int i; n   scanf( %d , &n); n   for (i = 1; i <= (n); ++i) { n     scanf( %d%d%d%d , &a[i].sa, &a[i].ea, &a[i].sb, &a[i].eb); n     t[(i << 1) - 1] = a[i].sa; n     t[i << 1] = a[i].ea; n   } n   sort(t + 1, t + (n << 1) + 1); n   m1 = unique(t + 1, t + (n << 1) + 1) - t - 1; n   for (i = 1; i <= (n); ++i) { n     a[i].sa = lower_bound(t + 1, t + m1 + 1, a[i].sa) - t; n     a[i].ea = lower_bound(t + 1, t + m1 + 1, a[i].ea) - t; n   } n   for (i = 1; i <= (n); ++i) { n     t[(i << 1) - 1] = a[i].sb; n     t[i << 1] = a[i].eb; n   } n   sort(t + 1, t + (n << 1) + 1); n   m2 = unique(t + 1, t + (n << 1) + 1) - t - 1; n   for (i = 1; i <= (n); ++i) { n     a[i].sb = lower_bound(t + 1, t + m2 + 1, a[i].sb) - t; n     a[i].eb = lower_bound(t + 1, t + m2 + 1, a[i].eb) - t; n   } n   if (!check()) return 0; n   for (i = 1; i <= (n); ++i) { n     swap(a[i].sa, a[i].sb); n     swap(a[i].ea, a[i].eb); n   } n   swap(m1, m2); n   if (check()) puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); } n long long oo = 1e18; n long long const M = 1e9 + 7, N = 3e5 + 9; n int n, m, d; n string s =   ; n int ans = 0; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> d; n   vector<int> v; n   set<int> s; n   map<int, int> mb; n   int x; n   for (int i = 0; i < n; i++) { n     cin >> x; n     s.insert(x); n     v.push_back(x); n   } n   int day = 1, cofe = 0; n   while (s.size()) { n     if (s.lower_bound(cofe) != s.end()) { n       cofe = *s.lower_bound(cofe); n       s.erase(s.lower_bound(cofe)); n       mb[cofe] = day; n       cofe += d + 1; n     } else { n       cofe = 0; n       day++; n     } n   } n   cout << day << endl; n   for (int i = 0; i < n; i++) { n     cout << mb[v[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const int maxn = 1005; n int c[10], n, s; n int main() { n   scanf( %d%d , &n, &s); n   for (int i = 1, x; i <= n; i++) scanf( %d , &x), c[x]++; n   int ans = INF, I, K, J, t; n   for (int i = s / n; i >= 0; i--) n     for (int j = (s - c[3] * i) / (n - c[3]); j >= i; j--) { n       int k = (s - c[3] * i - c[4] * j) / c[5]; n       if (k * c[5] - j * c[4] >= ans) break; n       if (i * c[3] + j * c[4] + k * c[5] == s && n           ans > (t = abs(i * c[3] - j * c[4]) + abs(j * c[4] - k * c[5]))) n         ans = t, I = i, J = j, K = k; n     } n   if (ans != INF) n     printf( %d %d %d n , I, J, K); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > data; n vector<bool> parallel; n vector<int> father; n vector<int> spec; n vector<int> opt; n vector<long long> ans; n void dfs(int vertex) { n   if (parallel[vertex]) { n     int tot = 0; n     for (int i = 0; i < data[vertex].size(); ++i) { n       int to = data[vertex][i]; n       dfs(to); n       tot += opt[to]; n     } n     opt[vertex] = tot; n   } else { n     if (spec[vertex] != -1) { n       opt[vertex] = 1; n       return; n     } n     int mn = 1e9; n     for (int i = 0; i < data[vertex].size(); ++i) { n       int to = data[vertex][i]; n       dfs(to); n       mn = min(mn, opt[to]); n     } n     opt[vertex] = mn; n   } n } n void dfs2(int vertex, long long need) { n   if (parallel[vertex]) { n     for (int i = 0; i < data[vertex].size(); ++i) { n       int to = data[vertex][i]; n       dfs2(to, need); n     } n   } else { n     if (spec[vertex] != -1) { n       ans[spec[vertex]] = need; n       return; n     } n     for (int i = 0; i < data[vertex].size(); ++i) { n       int to = data[vertex][i]; n       if (opt[to] == opt[vertex]) { n         dfs2(to, need); n         return; n       } n     } n   } n } n void solve() { n   int first; n   cin >> first; n   data = {{}}, father = {-1}, spec = {-1}, parallel = {false}; n   int cur = 0, u = 0; n   while (true) { n     char ch =    ; n     while (ch ==    ) cin >> ch; n     if (ch ==  ( ) { n       data.push_back({}); n       father.push_back(cur), parallel.push_back(false), spec.push_back(-1); n       int index = data.size() - 1; n       data[cur].push_back(index); n       cur = index; n     } n     if (ch ==  * ) { n       data.push_back({}); n       father.push_back(cur), parallel.push_back(false), spec.push_back(u++); n       int index = data.size() - 1; n       data[cur].push_back(index); n     } n     if (ch ==  P ) parallel[cur] = true; n     if (ch ==  ) ) { n       cur = father[cur]; n     } n     if (cur == 0) break; n   } n   ans.assign(u, 0); n   opt.assign(data.size(), -1); n   dfs(1); n   long long need = (long long)first * opt[1]; n   dfs2(1, need); n   cout <<  REVOLTING  ; n   for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long int c[2020][2020]; n int main() { n   long long int n, k, sum = 0; n   cin >> n >> k; n   for (int i = 0; i < ((int)(n)); i++) { n     c[i][i] = -1; n   } n   if (k >= 3) { n     long long int tmp; n     for (int i = 0; i < ((int)(n - 1)); i++) { n       for (int j = (int)(i + 1); j < ((int)(n)); j++) { n         scanf( %I64d , &tmp); n         sum += tmp; n       } n     } n   } else { n     for (int i = 0; i < ((int)(n - 1)); i++) { n       for (int j = (int)(i + 1); j < ((int)(n)); j++) { n         cin >> c[i][j]; n         c[j][i] = c[i][j]; n         if (c[i][j] > -1) { n           sum += c[i][j]; n         } n       } n     } n   } n   if (k != 2) { n     double ress = (double)(sum * 2) / (double)n; n     cout << (long long int)(floor(ress)) << endl; n   } else { n     long long int res = 0; n     for (int i = 0; i < ((int)(n)); i++) { n       vector<long long int> pl; n       for (int j = 0; j < ((int)(n)); j++) { n         if (c[i][j] > -1) pl.push_back(c[i][j]); n       } n       for (int j = 0; j < ((int)(((long long int)(pl).size()))); j++) { n         res += pl[j] * (((long long int)(pl).size()) - 1); n       } n     } n     double ress = (double)(res) / (double)(n * (n - 1) / 2); n     cout << (int)(floor(ress)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int i, t; n   vector<int> a; n   for (i = 0; i < n; i++) { n     cin >> t; n     a.push_back(t); n   } n   for (i = 0; i < n - 1; i++) { n     if (a[i] % 2 != 0) { n       a[i] %= 2; n       a[i + 1]--; n       if (a[i + 1] < 0) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   if (a[i] & 1) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long Q = 1e9 + 7; n long long poww(long long a, long long b) { n   long long x = 1, y = a; n   while (b > 0) { n     if (b % 2 == 1) { n       x = (x * y); n       if (x > Q) x %= Q; n     } n     y = (y * y); n     if (y > Q) y %= Q; n     b /= 2; n   } n   return x; n } n long long C[52][52]; n void binomialCoeff() { n   long long i, j; n   for (i = 0; i <= 50; i++) { n     for (j = 0; j <= 50; j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; n     } n   } n } n int main() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long ans = 0; n   if (m == 1) { n     ans = 1; n   } else if (k == 1 || k > n) { n     ans = poww(m, n); n   } else if (n == k) { n     ans = poww(m, (k + 1) / 2); n     ans %= Q; n   } else if (k % 2 != 0) { n     ans = m * m; n     ans %= Q; n   } else { n     ans = m; n     ans %= Q; n   } n   ans %= Q; n   cout << ans <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   string s; n   for (int i = 1; i <= n; i++) { n     string str; n     ostringstream temp; n     temp << i; n     s += temp.str(); n   } n   cout << s[n - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char i = getchar(); n   long long f = 1, res = 0; n   while (i <  0  || i >  9 ) { n     if (i ==  - ) f = -1; n     i = getchar(); n   } n   while (i >=  0  && i <=  9 ) { n     res = res * 10 + i -  0 ; n     i = getchar(); n   } n   return res * f; n } n const int N = 1e5 + 50; n long long h[N], a[N], n, m, k, p; n struct bamboo { n   long long time, id; n   bool operator<(const bamboo& A) const { return time > A.time; } n   bamboo(long long T, long long ID) : time(T), id(ID) {} n }; n priority_queue<bamboo> q; n long long cnt[N]; n bool pd(long long mid) { n   while (!q.empty()) { n     q.pop(); n   } n   memset(cnt, 0, sizeof(cnt)); n   for (register int i = 1; i <= n; ++i) { n     if (mid - a[i] * m < h[i]) { n       q.push(bamboo(mid / a[i], i)); n     } n   } n   for (register int i = 1; i <= m; ++i) { n     if (q.empty()) { n       break; n     } n     for (register int j = 1; j <= k; ++j) { n       if (q.empty()) { n         break; n       } n       bamboo now = q.top(); n       q.pop(); n       if (now.time < i) { n         return false; n       } n       cnt[now.id]++; n       if (mid + cnt[now.id] * p - a[now.id] * m < h[now.id]) { n         q.push(bamboo((mid + cnt[now.id] * p) / a[now.id], now.id)); n       } n     } n   } n   return q.empty(); n } n int main() { n   n = read(); n   m = read(); n   k = read(); n   p = read(); n   long long l = 0, r = -10, ans = -1, mid; n   for (register int i = 1; i <= n; ++i) { n     h[i] = read(); n     a[i] = read(); n     r = max(r, h[i] + a[i] * m); n   } n   while (l <= r) { n     mid = (l + r) >> 1; n     if (pd(mid)) { n       r = mid - 1; n       ans = mid; n     } else n       l = mid + 1; n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n string tostr(const T& t) { n   ostringstream os; n   os << t; n   return os.str(); n } n int adj[110][110]; n int adj2[110][110]; n int N, M; n set<int> emp[110]; n bool are_connected2(int a, int b) { n   set<int>::iterator it; n   for (it = emp[a].begin(); it != emp[a].end(); ++it) { n     int x = *it; n     if (emp[b].count(x)) return true; n   } n   return false; n } n void floyd() { n   for (int k = (int)(0); k <= (int)(N - 1); ++k) n     for (int i = (int)(0); i <= (int)(N - 1); ++i) n       for (int j = (int)(0); j <= (int)(N - 1); ++j) { n         if (adj[i][k] == 9999999 || adj[k][j] == 9999999) continue; n         adj[i][j] = 1; n       } n } n bool are_connected(vector<int>& comp1, vector<int>& comp2) { n   for (int i = (int)(0); i <= (int)(comp1.size() - 1); ++i) { n     for (int j = (int)(0); j <= (int)(comp2.size() - 1); ++j) { n       if (adj[comp1[i]][comp2[j]] != 9999999) return true; n     } n   } n   return false; n } n vector<vector<int> > find_scc() { n   floyd(); n   vector<int> colors = vector<int>(N, -1); n   int cur_color = -1; n   for (int i = (int)(0); i <= (int)(N - 1); ++i) { n     for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) { n       if (adj[i][j] != 9999999 && adj[j][i] != 9999999) { n         if (colors[i] != -1) n           colors[j] = colors[i]; n         else { n           ++cur_color; n           colors[i] = colors[j] = cur_color; n         } n       } n     } n   } n   for (int i = (int)(0); i <= (int)(colors.size() - 1); ++i) n     if (colors[i] == -1) colors[i] = ++cur_color; n   int ncolors = cur_color + 1; n   for (int i = (int)(0); i <= (int)(N - 1); ++i) n     for (int j = (int)(0); j <= (int)(N - 1); ++j) adj2[i][j] = 9999999; n   vector<vector<int> > comp_list = vector<vector<int> >(ncolors); n   for (int i = (int)(0); i <= (int)(ncolors - 1); ++i) { n     for (int j = (int)(0); j <= (int)(N - 1); ++j) { n       if (colors[j] == i) comp_list[i].push_back(j); n     } n   } n   for (int i = (int)(0); i <= (int)(comp_list.size() - 1); ++i) { n     for (int j = (int)(0); j <= (int)(comp_list.size() - 1); ++j) { n       if (are_connected(comp_list[i], comp_list[j])) { n         adj2[i][j] = 1; n       } n     } n   } n   return comp_list; n } n int main() { n   cin >> N >> M; n   bool nonZero = false; n   for (int i = (int)(0); i <= (int)(N - 1); ++i) { n     int k; n     cin >> k; n     for (int j = (int)(0); j <= (int)(k - 1); ++j) { n       int a; n       cin >> a; n       --a; n       emp[i].insert(a); n       if (a != 0) nonZero = true; n     } n   } n   if (!nonZero) { n     cout << N << endl; n     return 0; n   } n   for (int i = (int)(0); i <= (int)(N - 1); ++i) n     for (int j = (int)(0); j <= (int)(N - 1); ++j) adj[i][j] = 9999999; n   for (int i = (int)(0); i <= (int)(N - 1); ++i) { n     for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) { n       if (are_connected2(i, j)) { n         adj[i][j] = 1; n         adj[j][i] = 1; n       } n     } n   } n   vector<vector<int> > scc = find_scc(); n   int ans = (int)scc.size() - 1; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; n int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; n template <class T> n inline T biton(T n, T pos) { n   return n | ((T)1 << pos); n } n template <class T> n inline T bitoff(T n, T pos) { n   return n & ~((T)1 << pos); n } n template <class T> n inline T ison(T n, T pos) { n   return (bool)(n & ((T)1 << pos)); n } n template <class T> n inline T gcd(T a, T b) { n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n template <class T> n inline T bigmod(T p, T e, T m) { n   T ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % m; n     p = (p * p) % m; n   } n   return (T)ret; n } n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> items; n   for (int i = 0; i < n; i++) { n     int item; n     cin >> item; n     items.push_back(item); n   } n   sort(items.rbegin(), items.rend()); n   set<long long> st; n   long long cnt = 0; n   for (int i = n - 1; i >= 0; i--) { n     while (items[i]) { n       if (st.count(items[i]) == 0) { n         cnt += items[i]; n         st.insert(items[i]); n         break; n       } n       items[i]--; n     } n   } n   cout << cnt << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.setf(ios::fixed); n   cout.precision(10); n   cout.tie(nullptr); n   cin.tie(nullptr); n   int t = 1; n   while (t--) { n     solve(); n   } n   int pause; n   cin >> pause; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1000000007, BIG = 0x3f3f3f3f; n int n; n vector<int> a; n vector<int> Process() { n   vector<int> ans = {0}; n   int x = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] < 0 && ++x > 2) { n       x = 1; n       ans.push_back(0); n     } n     ans.back()++; n   } n   return ans; n } n void Output() { n   const vector<int> ans = Process(); n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   while (cin >> n) { n     a.resize(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     Output(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int i, t; n   char str[25]; n   while (~scanf( %s , str)) { n     int len = strlen(str); n     t = 0; n     for (int i = 0; i < len; i++) { n       if (str[i] ==  4  || str[i] ==  7 ) { n         t++; n       } n     } n     if (t == 4 || t == 7) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int n, a[200001], mp[200001], x, y; n vector<int> to[200001], t2[200001]; n int fa[200001], d[200001], sz[200001], son[200001]; n int top[200001], dfn[200001], cnt; n int f[200001], v[200001], p[200001], g[200001]; n int st[200001], tp, s, sum, ans; n bool in[200001]; n inline int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; } n inline int sub(int x, int y) { return x < y ? x + mod - y : x - y; } n inline int power(int a, int n) { n   int tp = 1; n   while (n) { n     if (n & 1) tp = 1ll * tp * a % mod; n     a = 1ll * a * a % mod, n >>= 1; n   } n   return tp; n } n inline bool cmp(int i, int j) { return dfn[i] < dfn[j]; } n inline void dfs1(int i) { n   sz[i] = 1; n   dfn[i] = ++cnt; n   for (int j : to[i]) { n     if (j == fa[i]) continue; n     fa[j] = i, d[j] = d[i] + 1; n     dfs1(j); n     sz[i] += sz[j]; n     if (sz[son[i]] < sz[j]) son[i] = j; n   } n } n inline void dfs2(int i) { n   if (son[i]) top[son[i]] = top[i], dfs2(son[i]); n   for (int j : to[i]) n     if (j != fa[i] && j != son[i]) top[j] = j, dfs2(j); n } n inline int lca(int x, int y) { n   while (top[x] != top[y]) { n     if (d[top[x]] < d[top[y]]) swap(x, y); n     x = fa[top[x]]; n   } n   return d[x] < d[y] ? x : y; n } n inline int dfs(int i) { n   g[i] = 0; n   if (in[i]) g[i] = v[i]; n   int ans = 0; n   for (int j : t2[i]) { n     ans = add(ans, dfs(j)), g[i] = add(g[i], g[j]); n     ans = (ans + 1ll * (d[j] - d[i]) * g[j] % mod * sub(sum, g[j])) % mod; n   } n   return ans; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , a + i), mp[a[i]] = i; n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &x, &y); n     to[x].push_back(y), to[y].push_back(x); n   } n   dfs1(1), top[1] = 1, dfs2(1); n   f[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (f[i]) continue; n     f[i] = i - 1; n     for (int j = 2 * i; j <= n; j += i) { n       if ((j / i) % i) n         f[j] = f[i] * f[j / i]; n       else n         f[j] = i * f[j / i]; n     } n   } n   for (int i = 1; i <= n; i++) v[i] = f[a[i]]; n   for (int i = 1; i <= n; i++) f[i] = 1ll * i * power(f[i], mod - 2) % mod; n   for (int i = 1; i <= n; i++) n     for (int j = 2 * i; j <= n; j += i) f[j] = sub(f[j], f[i]); n   for (int t = 1; t <= n; t++) { n     sum = s = 0; n     for (int i = t; i <= n; i += t) n       p[++s] = mp[i], sum = add(sum, v[mp[i]]), in[mp[i]] = 1; n     sort(p + 1, p + s + 1, cmp); n     st[tp = 1] = p[1], t2[p[1]].clear(); n     for (int i = 2; i <= s; i++) { n       int x = lca(p[i], st[tp]), lt = 0; n       while (d[st[tp]] > d[x]) { n         if (lt) t2[st[tp]].push_back(lt); n         lt = st[tp--]; n       } n       if (st[tp] != x) st[++tp] = x, t2[x].clear(); n       if (lt) t2[x].push_back(lt); n       st[++tp] = p[i], t2[p[i]].clear(); n     } n     while (tp > 1) t2[st[tp - 1]].push_back(st[tp]), tp--; n     ans = (ans + 1ll * dfs(st[1]) * f[t]) % mod; n     for (int i = 1; i <= s; i++) in[p[i]] = 0; n   } n   cout << 2ll * ans * power(1ll * n * (n - 1) % mod, mod - 2) % mod; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char *argv[]) { n   int n; n   string str; n   string ans =   ; n   while (cin >> n) { n     cin >> str; n     int now = 0; n     int vis[26]; n     ans =   ; n     while (now < str.length()) { n       char tmp = str[now]; n       int diff = 0; n       memset(vis, 0, sizeof vis); n       int flag = 0; n       for (int i = now + 1; i < str.length(); i++) { n         if (str[i] != tmp) { n           flag = 1; n           ans.push_back(tmp); n           ans.push_back(str[i]); n           now = i + 1; n           break; n         } n         if (!vis[str[i] -  a ]) { n           diff++; n           if (diff > 2) { n             flag = 1; n             now = now + 1; n             break; n           } n         } n       } n       if (flag == 0) { n         break; n       } n     } n     cout << str.length() - ans.length() << endl; n     cout << ans << endl; n   } 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   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     n = 4 * n; n     for (long long i = 0; i < (n / 4); i++) { n       cout << n - (2 * i) <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100020, mo = 1e9 + 7; n int n, second[N], x, y, cnt, dfn[N], vis[N]; n int dot[N], size; n int l[N], r[N]; n long long ans = 1; n set<pair<int, int> > L[N], R[N]; n struct Dot { n   int x, y; n } s[N]; n inline void read(int &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = 10 * x + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n inline int LS() { n   sort(second + 1, second + n + 1); n   int l = 0; n   for (int i = 1; i <= n; i++) n     if (i == 1 || second[i] != second[i - 1]) second[++l] = second[i]; n   return l; n } n inline void dfs(int u) { n   if (u > n || u < 1) return; n   vis[u] = cnt; n   dot[++size] = u; n   set<pair<int, int> >::iterator it = L[s[u].x].find(pair<int, int>(s[u].y, u)); n   it++; n   if (!vis[(*it).second]) dfs((*it).second); n   it--; n   it--; n   if (!vis[(*it).second]) dfs((*it).second); n   it = R[s[u].y].find(pair<int, int>(s[u].x, u)); n   it++; n   if (!vis[(*it).second]) dfs((*it).second); n   it--; n   it--; n   if (!vis[(*it).second]) dfs((*it).second); n } n inline int power(long long a, int n) { n   long long ans = 1; n   while (n) { n     if (n & 1) ans = (ans * a % mo); n     a = (a * a % mo); n     n >>= 1; n   } n   return ans; n } n int main() { n   read(n); n   for (int i = 1; i <= n; i++) read(s[i].x), read(s[i].y); n   for (int i = 1; i <= n; i++) second[i] = s[i].x; n   int X = LS(); n   for (int i = 1; i <= n; i++) n     s[i].x = lower_bound(second + 1, second + X + 1, s[i].x) - second; n   for (int i = 1; i <= n; i++) second[i] = s[i].y; n   int Y = LS(); n   for (int i = 1; i <= n; i++) n     s[i].y = lower_bound(second + 1, second + Y + 1, s[i].y) - second; n   vis[n + 1] = 1e9; n   for (int i = 1; i <= n; i++) n     L[i].insert(pair<int, int>(0, n + 1)), n         L[i].insert(pair<int, int>(n + 1, n + 1)); n   for (int i = 1; i <= n; i++) n     R[i].insert(pair<int, int>(0, n + 1)), n         R[i].insert(pair<int, int>(n + 1, n + 1)); n   for (int i = 1; i <= n; i++) { n     L[s[i].x].insert(pair<int, int>(s[i].y, i)); n     R[s[i].y].insert(pair<int, int>(s[i].x, i)); n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) { n       size = 0; n       cnt++; n       dfs(i); n       int num = 0; n       bool flag = 0; n       for (int j = 1; j <= size; j++) { n         if (l[s[dot[j]].x] || r[s[dot[j]].y]) flag = 1; n         num += (!l[s[dot[j]].x]) + (!r[s[dot[j]].y]); n         l[s[dot[j]].x] = 1; n         r[s[dot[j]].y] = 1; n       } n       int x = power(2, num); n       if (size < num) x--; n       if (x < 0) x += mo; n       ans = ans * x % mo; n     } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool notprime[1000010]; n int sumprime[1000010]; n void fun() { n   for (int i = 2; i <= 1000000; i++) { n     if (notprime[i] == 0) { n       for (int j = i * 2; j <= 1000000; j += i) { n         notprime[j] = 1; n       } n     } n   } n } n void sum() { n   sumprime[1] = 0; n   for (int i = 2; i <= 1000000; i++) { n     sumprime[i] = sumprime[i - 1] + (!notprime[i]); n   } n } n int main() { n   int n, x; n   scanf( %d , &n); n   fun(); n   sum(); n   while (n--) { n     scanf( %d , &x); n     int sum = sumprime[x] - sumprime[(int)sqrt(x)] + 1; n     printf( %d n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, j; n string s[103]; n bool ktra1() { n   if (n % 3 == 0) { n     static int chk[1000]; n     fill_n(chk, 1000, 0); n     for (int i = 1; i <= n / 3; ++i) { n       for (int j = 1; j <= m; ++j) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[1][1]] != m * n / 3) return false; n     for (int i = n / 3 + 1; i <= 2 * n / 3; ++i) { n       for (int j = 1; j <= m; ++j) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[n / 3 + 1][1]] != m * n / 3) return false; n     for (int i = 2 * n / 3 + 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[n][1]] != m * n / 3) return false; n   } else n     return false; n   return true; n } n bool ktra2() { n   if (m % 3 == 0) { n     static int chk[1000]; n     fill_n(chk, 1000, 0); n     for (int j = 1; j <= m / 3; ++j) { n       for (int i = 1; i <= n; ++i) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[1][1]] != m * n / 3) return false; n     for (int j = m / 3 + 1; j <= 2 * m / 3; ++j) { n       for (int i = 1; i <= n; ++i) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[1][m / 3 + 1]] != m * n / 3) return false; n     for (int j = 2 * m / 3 + 1; j <= m; ++j) { n       for (int i = 1; i <= n; ++i) { n         chk[s[i][j]]++; n       } n     } n     if (chk[s[1][m]] != m * n / 3) return false; n   } else n     return false; n   return true; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> s[i], s[i] =     + s[i]; n   if (ktra1() || ktra2()) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n int main() { n   { n     long long n, m, k, p, s, k1, p1; n     cin >> n >> m >> s; n     if (s == 1) { n       cout << n * m; n       return 0; n     } n     k = (n - 1) % s + 1; n     k1 = n / s; n     if (n % s != 0) k1++; n     k = k1 * k; n     p = (m - 1) % s + 1; n     p1 = m / s; n     if (m % s != 0) p1++; n     p = p1 * p; n     cout << p * k; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y, idx; n   long double at; n   bool operator<(const point &other) const { return at < other.at; } n }; n point p[123123]; n int main() { n   int n; n   scanf( %d n , &n); n   for (auto(i) = (0); (i) < (n); (i)++) { n     int a, b; n     scanf( %d %d n , &a, &b); n     p[i].x = a; n     p[i].y = b; n     p[i].idx = i; n     p[i].at = atan2(b, a); n   } n   sort(p, p + n); n   long double kek = 123123; n   int good1, good2; n   for (auto(i) = (1); (i) < (n); (i)++) { n     if (kek - p[i].at + p[i - 1].at > 1e-21) { n       kek = p[i].at - p[i - 1].at; n       good1 = p[i - 1].idx; n       good2 = p[i].idx; n     } n   } n   p[0].at += 2 * 3.1415926535897932384; n   if (kek - p[0].at + p[n - 1].at > 1e-21) { n     good1 = p[0].idx; n     good2 = p[n - 1].idx; n   } n   printf( %d %d n , good1 + 1, good2 + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool primeFactor(int n) { n   if (n == 2 || n == 3) return true; n   int sum = 1, two = 0, cnt; n   while (!(n % 2)) { n     return false; n   } n   for (int i = 3; i <= sqrt(n); i += 2) { n     while (!(n % i)) { n       return false; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   ; n   int n, i, j, k, m, x, y, z; n   int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41, n                  43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; n   cin >> n; n   if (n == 3) { n     cout << 1 << endl << 3 << endl; n     exit(0); n   } else if (n == 5) { n     cout << 2 << endl << 2 <<     << 3 << endl; n     exit(0); n   } n   m = n - 4; n   for (i = m; i >= 0; i -= 2) { n     if (primeFactor(i)) { n       z = i; n       break; n     } n   } n   int zz = z; n   y = n - z; n   for (i = y; i >= 0; i--) { n     if (n - zz - i > 1 && primeFactor(i)) { n       z = i; n       if (binary_search(prime, prime + 25, n - zz - z)) { n         y = i; n         x = n - zz - z; n         break; n       } n     } n   } n   cout << 3 << endl; n   cout << x <<     << y <<     << zz << endl; n   return 0; n } n