#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 15; n struct tree { n   int l, r, sum; n   tree *left, *right; n   tree(int L, int R, int val) { n     l = L, r = R, sum = val; n     left = right = NULL; n   } n }; n tree *pq[N], *db[N]; n tree *update(tree *cur, int l, int r, int ind, int add) { n   tree *ret = new tree(l, r, 0); n   ret->sum += cur->sum + add; n   if (l == r) { n     ret->sum = cur->sum; n     ret->sum += add; n     return ret; n   } n   int mid = (l + r) / 2; n   if (ind <= mid) { n     if (!cur->left) { n       cur->left = new tree(l, mid, 0); n     } n     ret->right = cur->right; n     ret->left = update(cur->left, l, mid, ind, add); n   } else { n     if (!cur->right) { n       cur->right = new tree(mid + 1, r, 0); n     } n     ret->right = update(cur->right, mid + 1, r, ind, add); n     ret->left = cur->left; n   } n   return ret; n } n int getval(tree *cur, int l, int r, int ind) { n   if (l == r) { n     return cur->sum; n   } n   int mid = (l + r) / 2; n   if (ind <= mid) { n     if (!cur->left) return 0; n     return getval(cur->left, l, mid, ind); n   } else { n     if (!cur->right) return 0; n     return getval(cur->right, mid + 1, r, ind); n   } n } n int count(tree *cur, int l, int r, int ind) { n   if (cur == NULL) return 0; n   if (ind < l) { n     return 0; n   } n   if (r <= ind) { n     return cur->sum; n   } n   int mid = (l + r) / 2; n   int ret = 0; n   if (cur->left) ret = count(cur->left, l, mid, ind); n   if (cur->right) ret += count(cur->right, mid + 1, r, ind); n   return ret; n } n map<string, int> Hash; n int main() { n   int q, i; n   string s, name; n   int pos = 1; n   int x; n   cin >> q; n   int n = 1e5; n   int m = 1e9; n   int C = 0, v; n   pq[C] = new tree(1, n, -1); n   db[C] = new tree(1, m, 0); n   while (q--) { n     cin >> s; n     if (s[0] ==  u ) { n       scanf( %d , &x); n       pq[C + 1] = pq[C - x]; n       db[C + 1] = db[C - x]; n     } else { n       cin >> name; n       if (!Hash.count(name)) { n         Hash[name] = pos++; n       } n       int id = Hash[name]; n       if (s[0] ==  s ) { n         scanf( %d , &x); n         v = getval(pq[C], 1, n, id); n         if (v != 0) { n           pq[C + 1] = update(pq[C], 1, n, id, -v + x); n           db[C + 1] = update(db[C], 1, m, v, -1); n           db[C + 1] = update(db[C + 1], 1, m, x, 1); n         } else { n           pq[C + 1] = pq[C], db[C + 1] = db[C]; n           pq[C + 1] = update(pq[C + 1], 1, n, id, x); n           db[C + 1] = update(db[C + 1], 1, m, x, 1); n         } n       } else if (s[0] ==  q ) { n         pq[C + 1] = pq[C]; n         db[C + 1] = db[C]; n         v = getval(pq[C + 1], 1, n, id); n         if (v != 0) { n           printf( %d n , count(db[C + 1], 1, m, v - 1)); n         } else n           printf( -1 n ); n       } else { n         pq[C + 1] = pq[C]; n         db[C + 1] = db[C]; n         v = getval(pq[C + 1], 1, n, id); n         if (v != 0) { n           pq[C + 1] = update(pq[C + 1], 1, n, id, -v); n           db[C + 1] = update(db[C + 1], 1, m, v, -1); n         } n       } n     } n     ++C; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int a, b; n   cin >> a >> b; n   vector<long long int> m; n   vector<long long int> n; n   set<long long int> s; n   m.push_back(1); n   n.push_back(1); n   if (a == 1) s.insert(1); n   for (long long int i = 1; i <= b;) { n     i = i * 2; n     m.push_back(i); n     if (i >= a && i <= b) s.insert(i); n   } n   for (long long int i = 1; i <= b;) { n     i = i * 3; n     n.push_back(i); n     if (i >= a && i <= b) s.insert(i); n   } n   for (int i = 0; i < m.size(); i++) { n     for (int j = 0; j < n.size(); j++) { n       long long int x = m[i] * n[j]; n       if (x >= a && x <= b) { n         s.insert(x); n       } n     } n   } n   cout << s.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void rd(int &x) { n   x = 0; n   int f = 1; n   char ch = (getchar()); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = (getchar()); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = (getchar()); n   x *= f; n } n const int N = 5e5 + 5; n int n, m; n int a[N], c[N], tmp[N]; n priority_queue<int, vector<int>, greater<int> > Q; n int main() { n   rd(n); n   long long ans = 0; n   for (int i = 1; i <= n; ++i) rd(a[i]), ans += a[i]; n   sort(a + 1, a + n + 1, greater<int>()); n   for (int i = 1; i <= n; ++i) { n     int j = i; n     a[++m] = a[i]; n     while (j <= n && a[j + 1] == a[i]) ++j; n     c[m] = j - i + 1, i = j; n   } n   n = m; n   int cnt = 0, tmp0 = 0; n   for (int i = 1; i <= n; ++i) { n     int res = min(cnt - 2 * (int)Q.size(), c[i]), n         ok = min(c[i] - res, cnt - res); n     tmp0 = 0; n     for (int j = 1; j <= res; ++j) tmp[++tmp0] = a[i]; n     for (int j = 1; j <= ok; j += 2) { n       int val = Q.top(); n       Q.pop(); n       if (val < a[i]) { n         tmp[++tmp0] = a[i]; n         if (ok - j) tmp[++tmp0] = a[i]; n       } else { n         tmp[++tmp0] = val; n         if (ok - j && 2 * a[i] - val > 0) tmp[++tmp0] = 2 * a[i] - val; n       } n     } n     for (int j = 1; j <= tmp0; ++j) Q.push(tmp[j]); n     cnt += c[i]; n   } n   while (!Q.empty()) ans -= Q.top(), Q.pop(); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, A[105], B[105], w, ans, tmp; n int main() { n   scanf( %d , &n); n   n *= 2; n   for (int i = (0); i < (n); i++) scanf( %d , &A[i]); n   sort(A, A + n); n   ans = 123412345; n   for (int i = (0); i < (n); i++) n     for (int j = (i + 1); j < (n); j++) { n       w = 0; n       for (int k = (0); k < (n); k++) { n         if (k == i || k == j) continue; n         B[w++] = A[k]; n       } n       tmp = 0; n       for (int k = 0; k < w; k += 2) tmp += B[k + 1] - B[k]; n       ans = min(ans, tmp); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 100; n vector<int> g[maxn]; n int father[maxn]; n int a[maxn]; n int findfather(int x) { n   int a = x; n   while (x != father[x]) x = father[x]; n   while (a != father[a]) { n     int z = a; n     a = father[a]; n     father[z] = x; n   } n   return x; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     g[a[i]].push_back(i); n   } n   int wjm = n; n   for (int i = 1; i <= m; i++) father[i] = i; n   for (int i = 2; i <= n; i++) n     if (a[i - 1] == a[i]) wjm--; n   printf( %d n , wjm - 1); n   for (int i = 1; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     int faX = findfather(x); n     int faY = findfather(y); n     if (g[faX].size() > g[faY].size()) swap(faX, faY); n     for (int j : g[faX]) { n       if (j + 1 <= n && a[j + 1] == faY) wjm--; n       if (j - 1 >= 1 && a[j - 1] == faY) wjm--; n       g[faY].push_back(j); n     } n     for (int j : g[faX]) a[j] = faY; n     father[faX] = faY; n     printf( %d n , wjm - 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5, INF = 0x3f3f3f3f; n int a[maxn]; n int last[maxn]; n int main() { n   int n; n   while (cin >> n) { n     memset(last, INF, sizeof(last)); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       last[a[i]] = i; n     } n     sort(last, last + maxn); n     cout << a[last[0]] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char seat[10][1005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int mark = 2000; n   int flag; n   for (int i = 0; i < n; i++) { n     cin >> seat[0][i] >> seat[1][i] >> seat[2][i] >> seat[3][i] >> seat[4][i]; n     if (seat[0][i] ==  O  && seat[1][i] ==  O ) { n       mark = i; n       flag = 0; n     } n     if (seat[3][i] ==  O  && seat[4][i] ==  O ) { n       mark = i; n       flag = 3; n     } n   } n   if (mark == 2000) n     cout <<  NO  << endl; n   else { n     seat[flag][mark] =  + ; n     seat[flag + 1][mark] =  + ; n     cout <<  YES  << endl; n     for (int i = 0; i < n; i++) { n       cout << seat[0][i] << seat[1][i] << seat[2][i] << seat[3][i] << seat[4][i] n            << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> dp[2001][26]; n int q[2000]; n pair<int, int> ans[2001][2001]; n int nxt[2001][26]; n pair<int, int> jump(pair<int, int> p, char c) { n   if (p.first < m) { n     p.second = dp[q[p.first]][c -  a ][p.second]; n     if (p.second == -1) { n       p.first = nxt[p.first + 1][c -  a ]; n       if (p.first < m) p.second = dp[q[p.first]][c -  a ][0]; n     } n   } n   return p; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     for (int j = 0; j < 26; ++j) { n       dp[i][j].resize(s.size() + 1); n       dp[i][j][s.size()] = -1; n       for (int k = s.size() - 1; k >= 0; --k) n         dp[i][j][k] = s[k] == j +  a  ? k + 1 : dp[i][j][k + 1]; n     } n   } n   cin >> m; n   for (int i = 0; i < m; ++i) cin >> q[i], q[i]--; n   for (int i = 0; i < 26; ++i) { n     nxt[m][i] = m; n     for (int j = m - 1; j >= 0; --j) n       nxt[j][i] = dp[q[j]][i][0] == -1 ? nxt[j + 1][i] : j; n   } n   string s; n   cin >> s; n   for (int i = 0; i <= s.size(); ++i) n     for (int j = 0; j <= s.size(); ++j) ans[i][j] = make_pair(1e9, 1e9); n   ans[0][0] = make_pair(0, 0); n   for (int i = 1; i <= s.size(); ++i) n     for (int j = 0; j <= i; ++j) { n       ans[i][j] = min(ans[i][j], ans[i - 1][j]); n       if (j) ans[i][j] = min(ans[i][j], jump(ans[i - 1][j - 1], s[i - 1])); n     } n   for (int i = s.size(); i >= 0; --i) n     if (ans[s.size()][i].first < m) { n       cout << i <<   n ; n       break; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, a, ans, i, b[10000000]; n string s, s1; n int main() { n   cin >> n >> s; n   s1 =  0 ; n   s1 += s; n   s1 +=  0 ; n   s = s1; n   a = s.find( 11 ); n   if (a < 10000) return cout <<  No , 0; n   a = s.find( 000 ); n   if (a < 10000) return cout <<  No , 0; n   cout <<  Yes ; n } n


#include <bits/stdc++.h> n const long double eps = 1e-9; n const double pi = acos(-1.0); n const long long inf = 1e18; n using namespace std; n int a[33], b[33], p[33], k[33], n, r, u, tt[33], z[33], back[33]; n int cnt = 0; n long long ans = -inf; n void update(int step) { n   int left = (u - step) % 2; n   long long now = 0; n   if (left == 0) n     for (int i = 1; i <= n; i++) now += 1ll * k[i] * a[i]; n   if (left == 1) n     for (int i = 1; i <= n; i++) now += 1ll * k[i] * (a[i] ^ b[i]); n   ans = max(ans, now); n } n void rec(int pos) { n   if (pos == u + 1) return; n   for (int i = ((z[pos - 1] + 1) & 1); i < 2; i++) { n     z[pos] = i; n     if (i == 0) { n       for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i]; n     } n     if (i == 1) { n       for (int i = 1; i <= n; i++) tt[i] = a[p[i]]; n       for (int i = 1; i <= n; i++) a[i] = tt[i] + r; n     } n     update(pos); n     rec(pos + 1); n     if (i == 0) { n       for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i]; n     } n     if (i == 1) { n       for (int i = 1; i <= n; i++) tt[i] = a[back[i]]; n       for (int i = 1; i <= n; i++) a[i] = tt[i] - r; n     } n   } n } n int main(int argc, const char* argv[]) { n   cin >> n >> u >> r; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   for (int i = 1; i <= n; i++) cin >> k[i]; n   for (int i = 1; i <= n; i++) cin >> p[i]; n   for (int i = 1; i <= n; i++) back[p[i]] = i; n   z[0] = 1; n   rec(1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 0x3f3f3f3f; n using namespace std; n void file(bool opt) { n   if (opt && fopen( in.txt ,  r )) n     freopen( in.txt ,  r , stdin), freopen( out.txt ,  w , stdout); n } n struct node { n   double x, y; n } point[100000 + 5], tu[100000 + 5]; n int tot = 0; n int n; n double multi(node p0, node p1, node p2) { n   return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y); n } n double dis(node a, node b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n bool cmp(node a, node b) { n   double x = multi(a, b, point[1]); n   if (x > 0 || (x == 0 && dis(a, point[1]) < dis(b, point[1]))) return 1; n   return 0; n } n void Graham() { n   int k = 1; n   for (int i = 1; i <= n; i++) n     if (point[i].y < point[k].y || n         (point[i].y == point[k].y && point[i].x < point[k].x)) n       k = i; n   swap(point[1], point[k]); n   sort(point + 2, point + 1 + n, cmp); n   tot = 2, tu[1] = point[1], tu[2] = point[2]; n   for (int i = 3; i <= n; i++) { n     while (tot >= 1 && multi(tu[tot], tu[tot - 1], point[i]) >= 0) tot--; n     tu[++tot] = point[i]; n   } n } n int main() { n   file(1); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %lf%lf , &point[i].x, &point[i].y); n     point[i].y = point[i].y - point[i].x * point[i].x; n   } n   if (n == 1) { n     puts( 0 ); n     return 0; n   } n   Graham(); n   int ans = 0; n   for (int i = 1; i <= tot; i++) { n     node a = tu[i], b = tu[(i + 1) > tot ? 1 : (i + 1)], n          c = {0, (long long)1e15}; n     if (a.x != b.x) { n       double x = multi(a, b, c); n       if (x < 0) ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace Work { n const int kMaxN = 100010; n multiset<int> set; n int n; n int a[kMaxN], b[kMaxN]; n int pos[kMaxN]; n void solve(FILE* fin, FILE* fout) { n   fscanf(fin,  %d , &n); n   for (int i = 1; i <= n; i++) { n     fscanf(fin,  %d , a + i); n     pos[a[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     fscanf(fin,  %d , b + i); n     set.insert(i - pos[b[i]]); n   } n   multiset<int>::iterator it = set.lower_bound(0); n   int x = *it, y = x; n   if (it != set.begin()) { n     it--; n     y = *it; n   } n   fprintf(fout,  %d n , min(abs(x), abs(y))); n   for (int dt = 1; dt < n; dt++) { n     set.erase(set.find(dt - pos[b[dt]])); n     set.insert(n - pos[b[dt]] + dt); n     it = set.lower_bound(dt); n     x = *it, y = x; n     if (it != set.begin()) { n       it--; n       y = *it; n     } n     fprintf(fout,  %d n , min(abs(x - dt), abs(y - dt))); n   } n   return; n } n }  // namespace Work n int main() { n   Work::solve(stdin, stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string x, y; n   cin >> x >> y; n   int sum = atoi(x.c_str()) + atoi(y.c_str()); n   int p = 0, now = 1; n   for (; sum; sum /= 10) { n     if (sum % 10 != 0) { n       p += (sum % 10) * now; n       now *= 10; n     } n   } n   x.erase(remove(x.begin(), x.end(),  0 ), x.end()); n   y.erase(remove(y.begin(), y.end(),  0 ), y.end()); n   int X = atoi(x.c_str()), Y = atoi(y.c_str()); n   if (X + Y == p) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > vec(n); n   vector<int> x(n); n   vector<int> y(n); n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     vec[i].first = x[i]; n     vec[i].second = y[i]; n   } n   long long ans = 0; n   sort(x.begin(), x.end()); n   long long count = 1; n   for (int i = 1; i < n; i++) { n     if (x[i] != x[i - 1]) { n       ans += (count * (count - 1)) / 2; n       count = 0; n     } n     count++; n   } n   ans += (count * (count - 1)) / 2; n   sort(y.begin(), y.end()); n   count = 1; n   for (int i = 1; i < n; i++) { n     if (y[i] != y[i - 1]) { n       ans += (count * (count - 1)) / 2; n       count = 0; n     } n     count++; n   } n   ans += (count * (count - 1)) / 2; n   sort(vec.begin(), vec.end()); n   count = 1; n   for (int i = 1; i < n; i++) { n     if (vec[i].first != vec[i - 1].first || n         vec[i].second != vec[i - 1].second) { n       ans -= (count * (count - 1)) / 2; n       count = 0; n     } n     count++; n   } n   ans -= (count * (count - 1)) / 2; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   cin >> n; n   int ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       int a; n       cin >> a; n       if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += a; n     } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n == 1) n     cout << -1 <<   n ; n   else n     cout << n <<     << n + 1 <<     << n * 1LL * (n + 1) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> split(const string& s, char c) { n   vector<string> v; n   stringstream ss(s); n   string x; n   while (getline(ss, x, c)) v.emplace_back(x); n   return move(v); n } n void err(vector<string>::iterator it) {} n template <typename T, typename... Args> n void err(vector<string>::iterator it, T a, Args... args) { n   cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ; n   err(++it, args...); n } n int check(int x, int l) { return x >= 0 && x < l; } n int solve(vector<string> board, string per, string comm) { n   int startx, starty, endx, endy; n   int r, c; n   r = board.size(); n   c = board[0].size(); n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       if (board[i][j] ==  S ) { n         startx = i; n         starty = j; n       } else if (board[i][j] ==  E ) { n         endx = i; n         endy = j; n       } n     } n   } n   int cx, cy; n   cx = startx; n   cy = starty; n   int i = 0; n   while (check(cx, r) && check(cy, c)) { n     int t = comm[i] -  0 ; n     i++; n     if (i > comm.length()) return 0; n     if (per[t] ==  U ) n       cy--; n     else if (per[t] ==  D ) n       cy++; n     else if (per[t] ==  L ) n       cx--; n     else if (per[t] ==  R ) n       cx++; n     if (!check(cx, r) || !check(cy, c)) return 0; n     if (board[cx][cy] ==  E ) return 1; n     if (board[cx][cy] ==  # ) return 0; n   } n   return 0; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<string> board; n   string comm; n   for (int i = 0; i < n; i++) { n     string temp; n     cin >> temp; n     board.push_back(temp); n   } n   cin >> comm; n   string per =  DLRU ; n   int ans = 0; n   while (1) { n     ans += solve(board, per, comm); n     bool x = next_permutation(per.begin(), per.end()); n     if (!x) break; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long oo = 1e16; n template <class P> n P gcd(P a, P b) { n   return b ? gcd(b, a % b) : a; n }; n long long read() { n   char c = getchar(); n   long long d = 0, f = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (; c >=  0  && c <=  9 ; d = d * 10 + c - 48, c = getchar()) n     ; n   return d * f; n } n const int N = 100001; n const int M = 400001; n const int mod = 1e9 + 7; n int n, m, cnt, cyc_amount, head[N]; n long long cyc_tot, ans, qz[N], _m2[201], record[62], f[62][2]; n bool exist[N]; n struct xint { n   int to, next; n   long long s; n } e[M]; n inline void addedge(int x, int y, long long s) { n   e[++cnt].to = y; n   e[cnt].next = head[x]; n   e[cnt].s = s; n   head[x] = cnt; n } n inline void dfs(int fa, int x, long long s) { n   exist[x] = 1; n   for (int i = 0; i <= 61; i++) f[i][s >> i & 1]++; n   qz[x] = s; n   for (int i = head[x]; i; i = e[i].next) { n     int y = e[i].to; n     if (y == fa) continue; n     if (!exist[y]) n       dfs(x, y, s ^ e[i].s); n     else { n       long long t = qz[x] ^ qz[y] ^ e[i].s; n       cyc_tot |= t; n       for (int i = 61; i >= 0; i--) { n         if ((t & (1LL << i)) && !record[i]) { n           record[i] = t; n           cyc_amount++; n           break; n         } n         t = min(t, t ^ record[i]); n       } n     } n   } n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= n; i++) exist[i] = 1; n   for (int i = 1; i <= m; i++) { n     int x = read(), y = read(); n     long long s = read(); n     exist[x] = exist[y] = 0; n     addedge(x, y, s); n     addedge(y, x, s); n   } n   _m2[0] = 1; n   for (int i = 1; i <= 200; i++) _m2[i] = _m2[i - 1] * 2 % mod; n   for (int i = 1; i <= n; i++) n     if (!exist[i]) { n       cyc_amount = cyc_tot = 0; n       for (int j = 0; j <= 61; j++) f[j][0] = f[j][1] = record[j] = 0; n       memset(qz, 0, sizeof qz); n       dfs(0, i, 0); n       for (int j = 0; j <= 61; j++) n         if (cyc_tot & (1LL << j)) n           ans = (ans + (f[j][0] + f[j][1]) * (f[j][0] + f[j][1] - 1) / 2 % mod * n                            _m2[j + cyc_amount - 1] % mod) % n                 mod; n         else n           ans = n               (ans + f[j][0] * f[j][1] % mod * _m2[j + cyc_amount] % mod) % mod; n     } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxRounds = 200000; n double p[110], ans, pw[110][maxRounds + 10]; n int times[110], n; n int main() { n   cin >> n; n   if (n == 1) { n     cout << 1; n     return 0; n   } n   for (int i = 1; i <= n; ++i) { n     int first; n     cin >> first; n     p[i] = first / 100.0; n   } n   double initProd = 1; n   for (int i = 1; i <= n; ++i) { n     initProd *= p[i]; n     pw[i][0] = 1; n     times[i] = 1; n     for (int j = 1; j <= maxRounds; ++j) { n       pw[i][j] = pw[i][j - 1] * (1 - p[i]); n     } n   } n   ans += initProd * n; n   for (int round = n + 1; round <= maxRounds; ++round) { n     double best = 0; n     int besti = 1; n     double prod = 1; n     for (int j = 1; j <= n; ++j) prod *= (1 - pw[j][times[j]]); n     for (int j = 1; j <= n; ++j) { n       double current = prod / (1 - pw[j][times[j]]) * pw[j][times[j]] * p[j]; n       if (current > best) { n         besti = j; n         best = current; n       } n     } n     ans += best * round; n     times[besti]++; n   } n   cout << fixed << setprecision(8) << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, maxx = 2, s = 1, k = 1; n   cin >> n; n   vector<int> a(n); n   for (i = 0; i < n; i++) cin >> a[i]; n   a.push_back(0); n   for (i = 0; i < n; i++) { n     if (i > 0 && s > 1 && a[i] == 1 && a[i - 1] == 2) s = 1; n     if (i > 0 && k > 1 && a[i] == 2 && a[i - 1] == 1) k = 1; n     if (a[i] == 1 && a[i + 1] == 1) n       s += 1; n     else if (min(k, s) * 2 > maxx) n       maxx = min(k, s) * 2; n     if (a[i] == 2 && a[i + 1] == 2) n       k += 1; n     else if (min(k, s) * 2 > maxx) n       maxx = min(k, s) * 2; n   } n   cout << maxx; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, f, k; n   scanf( %lld %lld %lld %lld , &a, &b, &f, &k); n   long long ans = 0; n   long long cfuel = b; n   for (int i = 0; i < k - 1; i++) { n     if (i % 2 == 0) { n       if (cfuel >= 2 * a - f) { n         cfuel -= a; n       } else if (cfuel >= f && b >= a - f) { n         ans++; n         cfuel = b - (a - f); n       } else { n         printf( -1 n ); n         return 0; n       } n     } else { n       if (cfuel >= a + f) { n         cfuel -= a; n       } else if (cfuel >= a - f && b >= f) { n         ans++; n         cfuel = b - f; n       } else { n         printf( -1 n ); n         return 0; n       } n     } n   } n   if (k % 2) { n     if (cfuel >= a) { n     } else if (cfuel >= f && b >= a - f) { n       ans++; n     } else { n       printf( -1 n ); n       return 0; n     } n   } else { n     if (cfuel >= a) { n     } else if (cfuel >= a - f && b >= f) { n       ans++; n     } else { n       printf( -1 n ); n       return 0; n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n void rs(int &x) { scanf( %d , &x); } n void rsl(long long &x) { scanf( %I64d , &x); } n void rsd(double &x) { scanf( %lf , &x); } n void rss(char *str) { scanf( %s , str); } n void ws(int &x) { printf( %d  , x); } n void wsl(long long &x) { printf( %I64d  , x); } n void wsd(double &x) { printf( %lf  , x); } n void wss(char *str) { printf( %s  , str); } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int const N = (2e5) + 5; n int const mod = (1e9) + 7; n int a[N], t[N], suma[N], sumt[N]; n priority_queue<int> que; n set<pair<int, int>> ms, mns; n map<int, int> mm; n int ins[N], inns[N]; n int main() { n   int n, w, k; n   cin >> n >> w >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     suma[i] = suma[i - 1] + a[i]; n   } n   for (int i = 1; i <= n; ++i) { n     cin >> t[i]; n     mm[t[i]] = i; n     sumt[i] = sumt[i - 1] + t[i]; n   } n   int ans = 0; n   int r = 1; n   int ct = 0; n   int cp = 0; n   for (int i = 1; i <= n; ++i) { n     r = max(r, i); n     while (r <= n) { n       int dt = 0; n       if (ms.size() < w) { n         dt = t[r] / 2 + t[r] % 2; n         if (ct + dt <= k) { n           ms.insert(make_pair(t[r], r)); n           ins[r] = 1; n           ct += dt; n         } else { n           break; n         } n       } else { n         int var = ms.begin()->first; n         if (t[r] > var) { n           int dt = t[r] / 2 + t[r] % 2; n           int ddt = (var / 2); n           if (ct + dt + ddt <= k) { n             ins[ms.begin()->second] = 0; n             ins[r] = 1; n             mns.insert(*ms.begin()); n             ms.erase(ms.begin()); n             ms.insert(make_pair(t[r], r)); n             ct += dt + ddt; n           } else { n             break; n           } n         } else { n           int dt = t[r]; n           if (ct + dt <= k) { n             ct += dt; n             mns.insert(make_pair(t[r], r)); n           } else { n             break; n           } n         } n       } n       r++; n     } n     ans = max(suma[r - 1] - suma[i - 1], ans); n     if (ins[i] == 0) { n       ct -= t[i]; n     } else { n       ct -= (t[i] / 2 + t[i] % 2); n       ins[i] = 0; n       set<pair<int, int>>::iterator it = ms.find(make_pair(t[i], i)); n       if (it != ms.end()) { n         ms.erase(it); n       } n       while (mns.size() > 0 && ((--mns.end())->second <= i)) { n         mns.erase(--mns.end()); n       } n       if (mns.size() > 0) { n         it = --mns.end(); n         ct -= ((it->first) / 2); n         ins[it->second] = 1; n         ms.insert(*(--mns.end())); n         mns.erase((--mns.end())); n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int generateb(int a, long int nos[], long int noa[], long int nob[]) { n   int i, minb = 100002; n   for (i = 0; i < 26; i++) { n     nos[i] = nos[i] - (noa[i] * a); n   } n   for (i = 0; i < 26; i++) { n     if (nob[i] != 0) { n       if (nos[i] / nob[i] < minb) { n         minb = nos[i] / nob[i]; n       } n     } n   } n   return minb; n } n int generatea(int b, long int nos[], long int noa[], long int nob[]) { n   int i, mina = 100002; n   for (i = 0; i < 26; i++) { n     nos[i] = nos[i] - (nob[i] * b); n   } n   for (i = 0; i < 26; i++) { n     if (noa[i] != 0) { n       if (nos[i] / noa[i] < mina) { n         mina = nos[i] / noa[i]; n       } n     } n   } n   return mina; n } n int main() { n   char s[100010], a[100010], b[100010]; n   long int nos[26] = {0}, i, lens = 0, noa[26] = {0}, nob[26] = {0}, lena = 0, n            lenb = 0, j, nos1[26] = {0}, mina = 100002, counta, countb, max = -1, n            maxa, maxb, minb = 100002, r; n   cin >> s >> a >> b; n   for (i = 0; s[i] !=   0 ; i++) { n     nos[s[i] -  a ]++; n     lens++; n   } n   for (j = 0; j < 26; j++) { n     nos1[j] = nos[j]; n   } n   for (i = 0; a[i] !=   0 ; i++) { n     noa[a[i] -  a ]++; n     lena++; n   } n   for (i = 0; b[i] !=   0 ; i++) { n     nob[b[i] -  a ]++; n     lenb++; n   } n   for (i = 0; i < 26; i++) { n     if (noa[i] != 0) { n       if (nos[i] / noa[i] < mina) { n         mina = nos[i] / noa[i]; n       } n     } n   } n   for (i = 0; i <= mina; i++) { n     countb = generateb(i, nos, noa, nob); n     for (j = 0; j < 26; j++) { n       nos[j] = nos1[j]; n     } n     if (i + countb > max) { n       max = i + countb; n       maxa = i; n       maxb = countb; n     } n   } n   for (i = 0; i < 26; i++) { n     if (nob[i] != 0) { n       if (nos[i] / nob[i] < minb) { n         minb = nos[i] / nob[i]; n       } n     } n   } n   for (i = 0; i <= minb; i++) { n     counta = generatea(i, nos, noa, nob); n     for (j = 0; j < 26; j++) { n       nos[j] = nos1[j]; n     } n     if (i + counta > max) { n       max = i + counta; n       maxb = i; n       maxa = counta; n     } n   } n   for (i = 0; i < maxa; i++) { n     cout << a; n   } n   for (i = 0; i < maxb; i++) { n     cout << b; n   } n   for (i = 0; i < 26; i++) { n     nos[i] = nos[i] - (maxa * noa[i]) - (maxb * nob[i]); n   } n   for (i = 0; i < 26; i++) { n     for (j = 0; j < nos[i]; j++) { n       cout << char(i +  a ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define F first n #define S second n #define rep(i, a, b) for(int i = a; i < (b); ++i) n #define per(i, a, b) for(int i = b-1; i>=a ; i--) n #define trav(a, x) for(auto& a : x) n #define allin(a , x) for(auto a : x) n #define all(x) begin(x), end(x) n #define sz(x) (int)(x).size() n typedef long long ll; n typedef pair<int, int> pii; n typedef vector<ll> vl; n typedef vector<pii> vpi; n typedef pair<ll,ll> pll; n typedef vector<string> vs; n typedef vector<pll> vpl; n typedef vector<int> vi; n std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); n  n int ask(int x , int i , vi v){ n  cout << 2 <<    << x  <<    << i <<    ; n  for(int j = 0 ; j < i ; j ++){ n   cout << v[j]  <<   ; n  } n  cout << endl; n  int ans; n  cin >> ans; n  return ans; n } n  n  n  n  n  n int32_t main(){ n  int t; n  cin >> t; n  while(t--){ n   int n; n   cin >> n; n   vector<int> v; n   for(int i = 0 ; i < n; i ++) n    v.push_back(i); n   stable_sort(all(v) , [&](int a , int b){ n    cout << 1 <<    << a <<    << b << endl; n    int ans; n    cin >> ans; n    return ans; n   }); n   vector< vector<char> > ans(n, vector<char>(n, 0 )); n   for(int i = 0 ; i < n ; i ++){ n    for(int j = i ; j < n; j ++){ n     ans[v[i]][v[j]] =  1 ; n    } n   } n   int pr = n-1; n   vector< vector<int> > g(n); n   for(int i = 0 ; i < n - 1; i ++) n    g[v[i]].push_back(v[i+1]); n   for(int i = n - 1 ; i >= 0 ; i --){ n    pr = min(pr, i); n    while(pr > 0 && ask(v[i] , pr , v)){ n     pr -- ; n    } n    g[v[i]].push_back(v[pr]); n   } n   vector< vector<bool> > vis(n , vector<bool> (n)); n   for(int i = 0 ; i< n; i ++){ n    queue<int> q; n    q.push(i); n    while(sz(q)){ n     auto u = q.front(); n     q.pop(); n     if(vis[i][u]) n      continue; n     vis[i][u] = true; n     for(auto w : g[u]) n      if(!vis[i][w]) n       q.push(w); n    } n   } n   cout << 3 << endl; n   for(int i = 0; i < n; i ++){ n    for(int j = 0; j < n; j ++) n     cout << (vis[i][j] ? 1 : 0); n    cout << endl; n   } n   int ansx; n   cin >> ansx; n   assert(ansx != -1); n  } n  exit(0); n }


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int maxn = 100086; n const double PI = atan(1.0) * 4.0; n const double eps = 1e-9; n const long long mod = 1000000007; n const int maxe = 10086 * 2; n long long quick_pow(long long a, long long n) { n   long long ret = 1; n   while (n) { n     if (n & 1) ret = ret * a % mod; n     a = a * a % mod; n     n >>= 1; n   } n   return ret; n } n char s[maxn]; n int n, num[5]; n int main() { n   scanf( %d%s , &n, s); n   memset(num, 0, sizeof num); n   for (int i = 0; i < n; i++) { n     if (s[i] ==  A ) n       num[0]++; n     else if (s[i] ==  G ) n       num[1]++; n     else if (s[i] ==  T ) n       num[2]++; n     else n       num[3]++; n   } n   int maxx = -1; n   for (int i = 0; i < 4; i++) maxx = max(maxx, num[i]); n   int a = 0; n   for (int i = 0; i < 4; i++) n     if (maxx == num[i]) a++; n   cout << quick_pow(a, n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 1e9 + 7; n struct node { n   int mat[210][210]; n } qwq; n int n, k, m; n inline int ha(int x, int y) { return x * (1 << m) + y; } n node ksm(int l) { n   if (l == 1) return qwq; n   node op = ksm(l / 2), op2; n   memset(op2.mat, 0, sizeof(op2.mat)); n   for (int i = 0; i < (k + 1) * (1 << m); i++) n     for (int j = 0; j < (k + 1) * (1 << m); j++) n       for (int h = 0; h < (k + 1) * (1 << m); h++) n         op2.mat[i][j] = n             (op2.mat[i][j] + 1ll * op.mat[i][h] * op.mat[h][j]) % mo; n   if (l % 2 == 0) return op2; n   node op3; n   memset(op3.mat, 0, sizeof(op3.mat)); n   for (int i = 0; i < (k + 1) * (1 << m); i++) n     for (int j = 0; j < (k + 1) * (1 << m); j++) n       for (int h = 0; h < (k + 1) * (1 << m); h++) n         op3.mat[i][j] = n             (op3.mat[i][j] + 1ll * qwq.mat[i][h] * op2.mat[h][j]) % mo; n   return op3; n } n int main() { n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 0; i <= k; i++) n     for (int j = 0; j < (1 << m); j++) { n       int ovo = (j << 1) % (1 << m); n       qwq.mat[ha(i, ovo)][ha(i, j)]++; n       if (i > 0) { n         int way_to_here = 1; n         for (int r = 0; r < m; r++) n           if ((1 << r) & j) way_to_here++; n         qwq.mat[ha(i, ovo | 1)][ha(i - 1, j)] += way_to_here; n       } n     } n   node uoj = ksm(n); n   int ans = 0; n   for (int i = 0; i < (1 << m); i++) n     ans = (ans + 1ll * uoj.mat[ha(k, i)][0]) % mo; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 2011; n int n, a[MN]; n vector<int> ls[MN]; n void solve1(int u) { n   cout <<  YES  << endl; n   for (int turn = 0, _a = (3); turn < _a; turn++) { n     for (int i = (1), _b = (2000); i <= _b; i++) { n       if (i != u) { n         for (int x = 0, _a = (ls[i].size()); x < _a; x++) n           cout << ls[i][x] <<    ; n       } else { n         if (turn == 0) n           cout << ls[i][0] <<     << ls[i][1] <<     << ls[i][2] <<    ; n         else if (turn == 1) n           cout << ls[i][0] <<     << ls[i][2] <<     << ls[i][1] <<    ; n         else n           cout << ls[i][1] <<     << ls[i][0] <<     << ls[i][2] <<    ; n         for (int x = (3), _b = (ls[i].size() - 1); x <= _b; x++) n           cout << ls[i][x] <<    ; n       } n     } n     cout << endl; n   } n } n void solve2(int u, int v) { n   cout <<  YES  << endl; n   for (int turn = 0, _a = (3); turn < _a; turn++) { n     for (int i = (1), _b = (2000); i <= _b; i++) { n       if (i != u && i != v) { n         for (int x = 0, _a = (ls[i].size()); x < _a; x++) n           cout << ls[i][x] <<    ; n       } else if (i == u) { n         if (turn == 0) n           cout << ls[i][0] <<     << ls[i][1] <<    ; n         else if (turn == 1) n           cout << ls[i][0] <<     << ls[i][1] <<    ; n         else n           cout << ls[i][1] <<     << ls[i][0] <<    ; n         for (int x = (2), _b = (ls[i].size() - 1); x <= _b; x++) n           cout << ls[i][x] <<    ; n       } else if (i == v) { n         if (turn == 0) n           cout << ls[i][0] <<     << ls[i][1] <<    ; n         else if (turn == 1) n           cout << ls[i][1] <<     << ls[i][0] <<    ; n         else n           cout << ls[i][1] <<     << ls[i][0] <<    ; n         for (int x = (2), _b = (ls[i].size() - 1); x <= _b; x++) n           cout << ls[i][x] <<    ; n       } n     } n     cout << endl; n   } n } n int main() { n   ios ::sync_with_stdio(false); n   while (cin >> n) { n     for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i]; n     for (int i = (0), _b = (2000); i <= _b; i++) ls[i].clear(); n     for (int i = (1), _b = (n); i <= _b; i++) { n       ls[a[i]].push_back(i); n     } n     bool ok = false; n     for (int i = (0), _b = (2000); i <= _b; i++) n       if (ls[i].size() >= 3) { n         solve1(i); n         ok = true; n         break; n       } n     if (ok) continue; n     for (int i = (1), _b = (2000); i <= _b; i++) { n       for (int j = (i + 1), _b = (2000); j <= _b; j++) n         if (ls[i].size() >= 2 && ls[j].size() >= 2) { n           solve2(i, j); n           ok = true; n           break; n         } n       if (ok) break; n     } n     if (!ok) cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n const int sqrtN = 320; n int countA[sqrtN], countP[sqrtN]; n map<int, int> dm[sqrtN]; n void recomp(int ind) { n   int a, p; n   a = p = 0; n   for (auto& x : dm[ind]) { n     if (x.second != -1) { n       if (p != 0) n         p--; n       else n         (a++); n     } else { n       p++; n     } n   } n   countA[ind] = a; n   countP[ind] = p; n } n int getTop(int ind, int p) { n   for (auto& x : dm[ind]) { n     if (x.second != -1) { n       if (p != 0) n         p--; n       else n         return x.second; n     } else { n       p++; n     } n   } n } n int top() { n   int p = 0; n   for (int i = 0; i < sqrtN; ++i) { n     if (p - countA[i] < 0) return getTop(i, p); n     p += countP[i] - countA[i]; n   } n   return -1; n } n const long long mod = 1e9 + 7; n long long sums(long long a, long long b) { n   long long ans = a + b; n   if (ans >= mod) ans -= mod; n   return ans; n } n long long mins(long long a, long long b) { n   long long ans = a - b; n   if (ans < 0) ans += mod; n   return ans; n } n int p = 31; n long long nextH(long long h, char a) { return h * p + (a -  a ) + 1; } n int last[26], sum[5010] = {0}, f[5010] = {0}; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   string str; n   cin >> str; n   f[0] = 1; n   for (int step = 0; step < n; ++step) { n     for (int i = 0; i < 26; ++i) last[i] = -1; n     sum[0] = 0; n     for (int i = 0; i < n; ++i) sum[i + 1] = sums(sum[i], f[i]); n     for (int i = 0; i < n; ++i) { n       f[i] = mins(sum[i + 1], sum[last[str[i] -  a ] + 1]); n       last[str[i] -  a ] = i; n     } n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) ans = sums(ans, f[i]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n int ah = 911382323; n int bh = 972663749; n template <typename F, typename S> n ostream &operator<<(ostream &os, const pair<F, S> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   typename vector<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  } ; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &v) { n   os <<  [ ; n   typename set<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename F, typename S> n ostream &operator<<(ostream &os, const map<F, S> &v) { n   os <<  [ ; n   typename map<F, S>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n long long dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; n long long dy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long(t); n   cin >> (t); n   while ((t)--) { n     long long n; n     cin >> n; n     vector<long long> v(n); n     for (long long i = 0; i < n; i++) cin >> v[i]; n     long long ind = 0; n     while (ind < n && v[ind] == 1) ind++; n     if (ind == n) { n       if (n % 2) n         cout << ( First ) <<   n ; n       else n         cout << ( Second ) <<   n ; n     } else { n       if (ind % 2 == 0) n         cout << ( First ) <<   n ; n       else n         cout << ( Second ) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6; n int cost[N], n, a, b, T; n string s; n long long l[N], r[N]; n bool check(int d) { n   --d; n   long long bst = min(l[d], r[d]); n   for (int i = 1; i < d; ++i) { n     bst = min(bst, l[i] + r[d - i] + a * i); n     bst = min(bst, r[i] + l[d - i] + a * i); n   } n   return bst + d + 1 + cost[0] <= T; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> a >> b >> T; n   cin >> s; n   for (int i = 0; i < s.size(); ++i) { n     cost[i] = (s[i] ==  w  ? b : 0); n   } n   for (int i = 1; i < n; ++i) { n     r[i] = r[i - 1] + cost[i] + a; n   } n   for (int i = 1; i < n; ++i) { n     l[i] = l[i - 1] + cost[n - i] + a; n   } n   int L = 0, R = n + 1; n   while (R - L > 1) { n     int m = (L + R) >> 1; n     if (check(m)) n       L = m; n     else n       R = m; n   } n   cout << L; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   long long a(-1), b(-1), ans(INT_MAX), tempA, tempB; n   for (int i = 0;; i++) { n     if (i * 7 > n) { n       break; n     } n     if ((n - i * 7) % 4 == 0) { n       tempA = (n - i * 7) / 4; n       tempB = i; n       if (tempA + tempB < ans) { n         a = tempA; n         b = tempB; n         ans = a + b; n       } n     } n   } n   if (a == -1 && b == -1) { n     cout << -1 << endl; n   } else { n     for (int i = 0; i < a; i++) { n       cout << 4; n     } n     for (int i = 0; i < b; i++) { n       cout << 7; n     } n     cout <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.precision(8); n   long long t(1); n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans; n int n, a, b; n vector<pair<int, int> > v; n int main() { n   ans = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d %d , &a, &b); n     v.push_back(make_pair(b, a)); n   } n   sort(v.begin(), v.end()); n   for (int i = 0, j = 0; i < v.size(); ++i) { n     if (v[i].second > j) { n       j = v[i].first; n       ++ans; n     } n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using cd = complex<double>; n const double PI = acos(-1); n int reverse(int num, int lg_n) { n   int res = 0; n   for (int i = 0; i < lg_n; i++) { n     if (num & (1 << i)) res |= 1 << (lg_n - 1 - i); n   } n   return res; n } n void fft(vector<cd> &a, bool invert) { n   int n = a.size(); n   int lg_n = 0; n   while ((1 << lg_n) < n) lg_n++; n   for (int i = 0; i < n; i++) { n     if (i < reverse(i, lg_n)) swap(a[i], a[reverse(i, lg_n)]); n   } n   for (int len = 2; len <= n; len <<= 1) { n     double ang = 2 * PI / len * (invert ? -1 : 1); n     cd wlen(cos(ang), sin(ang)); n     for (int i = 0; i < n; i += len) { n       cd w(1); n       for (int j = 0; j < len / 2; j++) { n         cd u = a[i + j], v = a[i + j + len / 2] * w; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n         w *= wlen; n       } n     } n   } n   if (invert) { n     for (cd &x : a) x /= n; n   } n } n vector<int> mult(vector<cd> &a, vector<cd> &b) { n   vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end()); n   int n = 1; n   while (n < a.size() + b.size()) n <<= 1; n   fa.resize(n); n   fb.resize(n); n   fft(fa, false); n   fft(fb, false); n   for (int i = 0; i < n; i++) fa[i] *= fb[i]; n   fft(fa, true); n   vector<int> result(n); n   for (int i = 0; i < n; i++) { n     result[i] = round(fa[i].real()); n   } n   return result; n } n long long mdp[1000010]; n void crive() { n   for (long long i = 2; i <= 1000000; i++) { n     if (mdp[i] == 0) { n       mdp[i] = i; n       for (long long j = i * i; j <= 1000000; j += i) { n         if (mdp[j] == 0) mdp[j] = i; n       } n     } n   } n } n vector<long long> div(int l) { n   vector<long long> ans = {1}; n   int sz = 1; n   while (l > 1) { n     long long p = mdp[l]; n     long long it = p; n     while (l % it == 0) { n       for (int j = 0; j < sz; j++) ans.push_back(it * ans[j]); n       it *= p; n     } n     it /= p; n     sz = ans.size(); n     l /= it; n   } n   sort(ans.begin(), ans.end()); n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   crive(); n   long long n, x, y; n   cin >> n >> x >> y; n   vector<cd> a(x + 1), b(x + 1); n   for (int i = 0; i < n + 1; i++) { n     int num; n     cin >> num; n     a[x - num] = 1; n     b[num] = 1; n   } n   vector<int> c = mult(a, b); n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int l; n     cin >> l; n     vector<long long> d = div(l); n     long long resp = -1; n     for (int i = d.size() - 1; i >= 0 && d[i] > 2 * y; i--) { n       long long u = d[i]; n       if (u & 1) continue; n       if ((u - 2 * y) / 2 + x < c.size() && c[(u - 2 * y) / 2 + x]) n         resp = u, i = -1; n     } n     cout << resp <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct segtree { n   int n; n   vector<long long> tree; n   void init(int s) { n     n = s; n     tree.resize(4 * s); n   } n   long long qry(int i, int j) { return qry(i, j, 1, 0, n - 1); } n   void upd(int i, long long v) { upd(i, v, 1, 0, n - 1); } n   long long qry(int i, int j, int x, int nowi, int nowj) { n     if (i <= nowi && nowj <= j) return tree[x]; n     if (nowi > j || nowj < i) return 0; n     int m = (nowi + nowj) / 2; n     return qry(i, j, 2 * x, nowi, m) + qry(i, j, 2 * x + 1, m + 1, nowj); n   } n   void upd(int i, long long v, int x, int nowi, int nowj) { n     if (nowi == i && nowj == i) { n       tree[x] = v; n       return; n     } n     if (nowi > i || nowj < i) return; n     int m = (nowi + nowj) / 2; n     upd(i, v, 2 * x, nowi, m); n     upd(i, v, 2 * x + 1, m + 1, nowj); n     tree[x] = tree[2 * x] + tree[2 * x + 1]; n   } n }; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, ans = 0; n   cin >> n; n   n *= 2; n   vector<int> a(n), p(n + 1, -1), v(n + 1); n   for (auto &i : a) cin >> i; n   for (int i = 0; i < n; ++i) { n     if (p[a[i]] == -1) p[a[i]] = i; n     v[i] = p[a[i]]; n   } n   segtree s; n   s.init(n); n   for (int i = n - 1; ~i; --i) { n     s.upd(v[i], 1); n     if (v[i]) ans += s.qry(0, v[i] - 1); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n vector<int> arr; n struct Query { n   int l, r, p, q; n }; n vector<Query> query, tmp; n vector<vector<long long> > dp; n vector<int> cnt; n int lpos, rpos; n long long cost; n void solve(int k) { n   query.push_back({0, N - 1, 0, N - 1}); n   while (query.size()) { n     cnt = vector<int>(N, 0); n     lpos = rpos = cost = 0; n     tmp.clear(); n     for (int i = 0; i < query.size(); i++) { n       int l = query[i].l; n       int r = query[i].r; n       int p = query[i].p; n       int q = query[i].q; n       if (l > r) continue; n       int m = (l + r) >> 1; n       int a = q; n       dp[k][m] = 1e18; n       while (rpos < max(m + 1, p)) { n         cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n         cnt[arr[rpos]]++; n         cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n         rpos++; n       } n       while (rpos > max(m + 1, p)) { n         rpos--; n         cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n         cnt[arr[rpos]]--; n         cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n       } n       while (lpos < m) { n         cost -= 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2; n         cnt[arr[lpos]]--; n         cost += 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2; n         lpos++; n       } n       for (int i = max(m + 1, p); i <= q; i++) { n         if (dp[k][m] > dp[k - 1][i] + cost) { n           dp[k][m] = dp[k - 1][i] + cost; n           a = i; n         } n         cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n         cnt[arr[rpos]]++; n         cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2; n         rpos++; n       } n       tmp.push_back({l, m - 1, p, a}); n       tmp.push_back({m + 1, r, a, q}); n     } n     query = tmp; n   } n } n int main() { n   scanf( %d %d , &N, &K); n   arr.resize(N); n   for (int i = 0; i < N; i++) { n     scanf( %d , &arr[i]); n     arr[i]--; n   } n   dp = vector<vector<long long> >(K + 1, vector<long long>(N)); n   cnt = vector<int>(N, 0); n   cost = 0; n   for (int i = N - 1; i >= 0; i--) { n     cost -= 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2; n     cnt[arr[i]]++; n     cost += 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2; n     dp[1][i] = cost; n   } n   for (int i = 2; i <= K; i++) { n     solve(i); n   } n   printf( %lld , dp[K][0]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double d, h, v, e; n   while (~scanf( %lf%lf%lf%lf , &d, &h, &v, &e)) { n     double v1, v2; n     v1 = (d / 2) * (d / 2) * 3.1415927 * e; n     v2 = (d / 2) * (d / 2) * 3.1415927 * h; n     if (v1 >= v) n       printf( NO n ); n     else { n       double time = v2 / (v - v1); n       printf( YES n ); n       printf( %lf n , time); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int tot = 1; n int b[200005], e[200005], h[200005], p[200005], u[200005]; n vector<int> ans[200005]; n void add(int x, int y) { n   b[++tot] = y; n   e[tot] = h[x]; n   h[x] = tot; n } n void dfs(int k, int fa_edge) { n   p[k] = 1; n   for (int go = h[k]; go; go = e[go]) n     if (b[go] != b[fa_edge]) { n       if (p[b[go]] == 0) dfs(b[go], go ^ 1); n       if (u[go] == 0) ans[k].push_back(b[go]), u[go] = u[go ^ 1] = 1; n     } n   int sum = ans[k].size(); n   if (sum & 1) n     sum++, ans[k].push_back(b[fa_edge]), u[fa_edge] = u[fa_edge ^ 1] = 1; n   for (int i = 0; i < sum; i += 2) n     printf( %d %d %d n , ans[k][i] + 1, k + 1, ans[k][i + 1] + 1); n } n int main() { n   scanf( %d%d , &n, &m); n   if (m % 2) { n     printf( No solution ); n     return 0; n   } n   int x, y; n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &x, &y); n     add(--x, --y); n     add(y, x); n   } n   dfs(0, -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n int n; n int neg = 0; n string s[N + 5]; n inline long long pars(int x) { n   long long ret = 0LL; n   for (int i = 0; i < s[x].size(); i++) { n     if (s[x][i] ==  - ) continue; n     if (s[x][i] ==  . ) break; n     ret *= 10; n     ret += s[x][i] -  0 ; n   } n   if (s[x][0] ==  - ) ret *= -1; n   return ret; n } n bool bisa(int x) { n   for (int i = s[x].size() - 1; i >= 0; i--) { n     if (s[x][i] ==  . ) break; n     if (s[x][i] !=  0 ) return 1; n   } n   return 0; n } n int main() { n   cin >> n; n   long long ct = 0LL; n   for (int i = 1; i <= n; i++) { n     cin >> s[i]; n     if (s[i][0] ==  - ) neg++; n     ct += pars(i); n   } n   for (int i = 1; i <= n; i++) { n     long long tmp = pars(i); n     if (bisa(i)) { n       if (ct > 0) { n         if (s[i][0] ==  - ) { n           tmp--; n           ct--; n         } n       } else if (ct < 0) { n         if (s[i][0] !=  - ) { n           tmp++; n           ct++; n         } n       } n     } n     cout << tmp << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int sum; n int l, r; n int ans = 360; n int a[360]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   while (r < n) { n     sum += a[r]; n     while (sum >= 180) { n       ans = min(ans, 2 * abs(180 - sum)); n       sum -= a[l]; n       l++; n     } n     ans = min(ans, 2 * abs(180 - sum)); n     r++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, f, d; n int main() { n   cin >> n; n   if (n % 3 != 2) n     d = n / 3; n   else n     d = n / 3 + 1; n   f = d / 12; n   d %= 12; n   cout << f <<     << d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000001; n const long long int LLINF = 1000000000000000001LL; n struct ITree { n   vector<long long int> T; n   int p = 1; n   ITree(int n) { n     while (p < n) p *= 2; n     T.resize(2 * p - 1, 0); n   } n   int par(int x) { return (x - 1) / 2; } n   void Set(int l, long long int v) { n     l += p - 1; n     T[l] = v; n     while (l > 0) { n       l = par(l); n       T[l] = T[2 * l + 1] + T[2 * l + 2]; n     } n   } n   long long int Query(int l, int r) { n     l += p - 1; n     r += p - 1; n     long long int ans = T[l]; n     if (l < r) ans += T[r]; n     while (par(l) != par(r)) { n       if (l % 2 == 1) ans += T[l + 1]; n       if (r % 2 == 0) ans += T[r - 1]; n       l = par(l); n       r = par(r); n     } n     return ans; n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   int n, k, a, b, q; n   cin >> n >> k >> a >> b >> q; n   ITree treeA(n), treeB(n); n   vector<long long int> A(n, 0); n   while (q--) { n     int type; n     cin >> type; n     if (type == 1) { n       int day, add; n       cin >> day >> add; n       day--; n       A[day] += add; n       treeB.Set(day, min((long long int)b, A[day])); n       treeA.Set(day, min((long long int)a, A[day])); n     } else { n       int l; n       cin >> l; n       l--; n       int r = l + k - 1; n       long long int ans = 0; n       if (l > 0) ans += treeB.Query(0, l - 1); n       if (r < n - 1) ans += treeA.Query(r + 1, n - 1); n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n constexpr int N = 1e5 + 5; n void solve() { n   int a, b; n   cin >> a >> b; n   if (a * 2 <= b) n     cout << a <<     << a * 2 <<   n ; n   else n     cout <<  -1 -1 n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const int S = 40; n const unsigned long long mod = 998244353; n struct poly { n   int a[S + 10]; n   inline int& operator[](const int& x) { return a[x]; } n   poly() { n     for (int i = 0; i < S; i++) a[i] = 0; n   } n   friend poly operator*(poly a, poly b) { n     poly c; n     for (int i = 0; i < S; i++) n       for (int j = 0; j < S && i + j < S; j++) c[i + j] += a[i] * b[j]; n     return c; n   } n   friend poly operator+(poly a, poly b) { n     poly c; n     for (int i = 0; i < S; i++) c[i] = a[i] + b[i]; n     return c; n   } n   friend poly operator-(poly a, poly b) { n     poly c; n     for (int i = 0; i < S; i++) c[i] = a[i] - b[i]; n     return c; n   } n   poly operator<<(const int& x) { n     poly c; n     for (int i = S - 1; i >= x; i--) c[i] = a[i - x]; n     return c; n   } n } a, b, c, q, fz, fm, fz1, fm1; n int n; n unsigned long long f0[N]; n unsigned long long c0[N]; n unsigned long long f1[N]; n unsigned long long c1[N]; n unsigned long long f2[N]; n unsigned long long c2[N]; n unsigned long long g[N]; n unsigned long long sqr[N]; n inline void calc(poly& fz, poly& fm, unsigned long long* f, n                  unsigned long long* c) { n   for (int i = 0; i < S; i++) f[i] = (mod + fz[i]) % mod; n   for (int i = 0; i < S; i++) c[i] = (mod - fm[i]) % mod; n   (c[0] += 1) %= mod; n   for (int i = 0; i <= n; i++) n     for (int j = 1; j < S && j <= i; j++) (f[i] += f[i - j] * c[j]) %= mod; n } n int main() { n   a[8] = 16; n   a[6] = 12; n   a[4] = 20; n   a[2] = 4; n   b[8] = 9; n   b[6] = 2; n   b[4] = 23; n   b[2] = 6; n   b[0] = 1; n   c[8] = 4; n   c[6] = -4; n   c[4] = 24; n   c[2] = 4; n   c[0] = 4; n   q[12] = -1; n   q[10] = -3; n   q[6] = +5; n   q[2] = -3; n   q[0] = +1; n   scanf( %d , &n); n   fz = ((b * b) << 3) - a * ((c << 3) - q); n   fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4); n   calc(fz, fm, f0, c0); n   fz = b * q; n   fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4); n   calc(fz, fm, f1, c1); n   fz1 = c * fm + ((b * fz) << 1); n   fm1 = fm * (q - (c << 3)); n   calc(fz1, fm1, f2, c2); n   g[0] = 1; n   g[2] = 1; n   for (int i = 4; i <= n; i++) g[i] = (g[i - 2] + g[i - 4]) % mod; n   for (int i = 1; i <= n; i++) sqr[i] = (unsigned long long)i * i % mod; n   unsigned long long ans = (g[n - 1] + g[n - 3]) * sqr[n - 1] % mod * n % mod; n   for (int i = 2; i <= n - 2; i++) { n     unsigned long long ret = 0; n     (ret += g[i - 1] * f0[n - i - 1]) %= mod; n     (ret += g[i - 2] * f1[n - i - 2] * 2) %= mod; n     if (3 <= i && i <= n - 3) (ret += g[i - 3] * f2[n - i - 3]) %= mod; n     (ans += ret * sqr[i - 1] % mod * i) %= mod; n   } n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, k, m, x, ans = 0; n   cin >> n >> k >> m; n   vector<pair<long long, long long> > v; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (v.empty() || (v.back().first != x)) { n       v.push_back({x, 1}); n     } else if (v.back().first == x) { n       v.back().second = (v.back().second + 1) % k; n       if (v.back().second == 0) v.pop_back(); n     } n   } n   if (v.size() == 0) return cout << 0, 0; n   if (v.size() == 1) { n     return cout << ((v[0].second * m) % k), 0; n   } n   for (auto &i : v) { n     ans += m * i.second; n   } n   if (m == 1) return cout << ans, 0; n   long long rem = 0; n   int back = v.size() - 1, front = 0; n   while (back > front) { n     if ((v[front].first != v[back].first)) { n       break; n     } else { n       rem += ((v[front].second + v[back].second) - n               ((v[front].second + v[back].second) % k)) * n              (m - 1); n       if ((v[front].second + v[back].second) % k) break; n     } n     back--; n     front++; n   } n   if (back == front) { n     rem += ((v[back].second) * m) - ((v[back].second) * m) % k; n     if (((v[back].second) * m) % k == 0) { n       back--; n       front++; n     } n   } n   if (back < front) n     while (back >= 0) { n       if ((v[front].first != v[back].first)) { n         break; n       } else { n         rem += ((v[front].second + v[back].second) - n                 ((v[front].second + v[back].second) % k)); n         if ((v[front].second + v[back].second) % k) break; n       } n       back--; n       front++; n     } n   cout << (ans - rem); n   return 0; n } n


#include <bits/stdc++.h> n #pragma optimize( avx ) n #pragma optimize( no-stack-protector ) n namespace io { n inline char gnc() { return (char)getchar(); } n template <typename T> n inline void gi(T &dx) { n   dx = 0; n   int yc = gnc(); n   bool nega = false; n   while (yc <  0  || yc >  9 ) { n     nega = (yc ==  -  ? true : nega); n     yc = gnc(); n   } n   while (yc >=  0  && yc <=  9 ) { n     dx = (T)(dx * 10 + yc -  0 ); n     yc = gnc(); n   } n   if (nega) { n     dx = -dx; n   } n } n void gc(char &a) { n   do a = gnc(); n   while (!isgraph(a)); n } n void gss(char *c) { n   *c = gnc(); n   while (!isgraph(*c)) *c = gnc(); n   while (isgraph(*c)) *++c = gnc(); n   *c = 0; n } n template <typename t1, typename t2> n inline void gi(t1 &a, t2 &b) { n   gi(a); n   gi(b); n } n template <typename t1, typename t2, typename t3> n inline void gi(t1 &a, t2 &b, t3 &c) { n   gi(a); n   gi(b); n   gi(c); n } n template <typename t1, typename t2, typename t3, typename t4> n inline void gi(t1 &a, t2 &b, t3 &c, t4 &d) { n   gi(a); n   gi(b); n   gi(c); n   gi(d); n } n template <typename t1, typename t2, typename t3, typename t4, typename t5> n inline void gi(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) { n   gi(a); n   gi(b); n   gi(c); n   gi(d); n   gi(e); n } n }  // namespace io n using namespace io; n using namespace std; n inline int gcd(int x, int y) { n   return y > x ? gcd(y, x) : y ? gcd(y, x % y) : x; n } n inline void exgcd(int a, int b, int &x, int &y) { n   if (!b) { n     x = 1; n     y = 0; n     return; n   } n   exgcd(b, a % b, x, y); n   int t = x; n   x = y; n   y = t - (a / b) * y; n } n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n const int Rev = (MOD + 1) >> 1; n template <typename T> n inline void Sol(T &x) { n   if (x >= MOD) x -= MOD; n } n template <typename t1, typename t2> n inline int inc(t1 x, t2 y) { n   x += y; n   if (x >= MOD) x -= MOD; n   return x; n } n template <typename t1, typename t2> n inline int dec(t1 x, t2 y) { n   x += MOD - y; n   if (x >= MOD) x -= MOD; n   return x; n } n template <typename t1, typename t2> n inline long long mul(t1 x, t2 y) { n   long long res = (long long)x * y; n   return res >= MOD ? res % MOD : res; n } n template <typename t1, typename t2, typename t3> n inline long long mul(t1 x, t2 y, t3 z) { n   return mul(mul(x, y), z); n } n template <typename t1, typename t2, typename t3, typename t4> n inline long long mul(t1 a, t2 b, t3 c, t4 d) { n   return mul(mul(a, b), mul(c, d)); n } n inline long long qpow(long long x, int y) { n   long long res = 1; n   for (; y; y >>= 1, x = x * x % MOD) n     if (y & 1) res = res * x % MOD; n   return res; n } n inline long long read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n template <typename T1, typename T2> n inline void Getmin(T1 &x, T2 y) { n   if (x > y) x = y; n } n template <typename T1, typename T2> n inline void Getmax(T1 &x, T2 y) { n   if (x < y) x = y; n } n const int MAXN = 52; n int n, d[MAXN], f[2][MAXN][MAXN][MAXN][MAXN]; n inline long long binom(long long x) { return 1LL * x * (x - 1) / 2ll % MOD; } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) d[i] = read(); n   int np = 0; n   f[np][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1; n   for (int i = 3; i <= n; i++) { n     int p = np, op = d[i] & 1; n     np ^= 1; n     memset(f[np], 0, sizeof f[np]); n     for (int pre1 = 0; pre1 < i; pre1++) n       for (int pre2 = 0; pre2 < i - pre1; pre2++) { n         int now1up = i - pre1 - pre2, now2up; n         for (int now1 = 0; now1 < now1up; now1++) { n           now2up = now1up - now1; n           for (int now2 = 0; now2 < now2up; now2++) n             if (f[p][pre1][pre2][now1][now2]) { n               if (!(now1 || now2 || pre1 || pre2)) continue; n               int val = f[p][pre1][pre2][now1][now2]; n               if (!pre1 && !pre2) { n                 if (now1) n                   f[np][now1 - 1][now2][op ^ 1][op] = n                       inc(f[np][now1 - 1][now2][op ^ 1][op], mul(val, now1)); n                 if (now2) n                   f[np][now1 + 1][now2 - 1][op ^ 1][op] = inc( n                       f[np][now1 + 1][now2 - 1][op ^ 1][op], mul(val, now2)); n               } else { n                 if (pre1) { n                   int newnow1 = now1 + (op ^ 1), newnow2 = now2 + op; n                   long long v = mul(val, pre1); n                   int newpre1 = pre1 - 1; n                   f[np][newpre1][pre2][newnow1][newnow2] = n                       inc(f[np][newpre1][pre2][newnow1][newnow2], v); n                   if (now1) { n                     f[np][newpre1][pre2][now1 - 1 + op][now2] = n                         inc(f[np][newpre1][pre2][now1 - 1 + op][now2], n                             mul(v, now1)); n                     if (op && now1 > 1) n                       f[np][newpre1][pre2][now1 - 2][now2] = n                           inc(f[np][newpre1][pre2][now1 - 2][now2], n                               mul(v, binom(now1))); n                   } n                   if (now2) { n                     f[np][newpre1][pre2][now1 + op + 1][now2 - 1] = n                         inc(f[np][newpre1][pre2][now1 + op + 1][now2 - 1], n                             mul(v, now2)); n                     if (op && now2 > 1) n                       f[np][newpre1][pre2][now1 + 2][now2 - 2] = n                           inc(f[np][newpre1][pre2][now1 + 2][now2 - 2], n                               mul(v, binom(now2))); n                   } n                   if (now1 && now2 && op) n                     f[np][newpre1][pre2][now1][now2 - 1] = n                         inc(f[np][newpre1][pre2][now1][now2 - 1], n                             mul(mul(v, now1), now2)); n                 } n                 if (pre2) { n                   int newnow1 = now1 + (op ^ 1), newnow2 = now2 + op; n                   long long v = mul(val, pre2); n                   int newpre1 = pre1 + 1, newpre2 = pre2 - 1; n                   f[np][newpre1][newpre2][newnow1][newnow2] = n                       inc(f[np][newpre1][newpre2][newnow1][newnow2], v); n                   if (now1) { n                     f[np][newpre1][newpre2][now1 - 1 + op][now2] = n                         inc(f[np][newpre1][newpre2][now1 - 1 + op][now2], n                             mul(v, now1)); n                     if (op && now1 > 1) n                       f[np][newpre1][newpre2][now1 - 2][now2] = n                           inc(f[np][newpre1][newpre2][now1 - 2][now2], n                               mul(v, binom(now1))); n                   } n                   if (now2) { n                     f[np][newpre1][newpre2][now1 + op + 1][now2 - 1] = n                         inc(f[np][newpre1][newpre2][now1 + op + 1][now2 - 1], n                             mul(v, now2)); n                     if (op && now2 > 1) n                       f[np][newpre1][newpre2][now1 + 2][now2 - 2] = n                           inc(f[np][newpre1][newpre2][now1 + 2][now2 - 2], n                               mul(v, binom(now2))); n                   } n                   if (now1 && now2 && op) n                     f[np][newpre1][newpre2][now1][now2 - 1] = n                         inc(f[np][newpre1][newpre2][now1][now2 - 1], n                             mul(v, now1, now2)); n                 } n               } n             } n         } n       } n   } n   int ans = f[n & 1][0][0][0][0]; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long A = 100000000000000LL, N = 300005; n long long p, d, limit; n long long cal(long long p) { n   int x = 0; n   if (p % 10 != 9) return 0; n   while (p % 10 == 9) { n     x++; n     p /= 10; n   } n   return x; n } n int main() { n   cin >> p >> d; n   limit = p - d; n   long long j = p; n   long long length = log10(p) + 1; n   long long initial = cal(p); n   int i = 0; n   long long powerr = 10; n   while (true) { n     j = p - p % powerr - 1; n     if (j == -1) break; n     if (j < limit) break; n     powerr *= 10; n   } n   powerr /= 10; n   j = p - p % powerr - 1; n   if (j < limit) j = p; n   if (j >= limit and powerr == 1) j = p; n   if (initial >= (log10(powerr))) j = p; n   cout << j; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int data[100]; n   int n, x, y; n   cin >> n >> x >> y; n   int c = 0; n   for (int i = 0; i < n; i++) { n     cin >> data[i]; n     if (data[i] <= x) c++; n   } n   if (x > y) { n     cout << n; n   } else { n     if (c % 2 == 0) { n       cout << c / 2; n     } else n       cout << (c / 2) + 1; n   } n   char a; n   cin >> a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<long long unsigned, long long unsigned>, n     pair<long long unsigned, long long unsigned> > n     dp; n long long unsigned n; n void read() { n   cin >> n; n   return; n } n pair<long long unsigned, long long unsigned> find(long long unsigned s, n                                                   long long unsigned mx) { n   if (s <= 9) return make_pair(0, s); n   if (dp.find(make_pair(s, mx)) != dp.end()) return dp[make_pair(s, mx)]; n   long long unsigned t, r, m; n   pair<long long unsigned, long long unsigned> &ans = dp[make_pair(s, mx)]; n   t = 1; n   while (t * 10 <= s) t *= 10; n   r = s % t; n   s = s / t; n   while (1) { n     m = max(mx, s); n     pair<long long unsigned, long long unsigned> f = find(r, m); n     ans.first += f.first; n     if (s == 0) { n       ans.second = f.second; n       break; n     } n     if (f.second >= m) { n       ans.first += 2; n       r = t - m; n     } else { n       ans.first++; n       r = t - (m - f.second); n     } n     s--; n   } n   return ans; n } n void solve() { n   read(); n   pair<long long unsigned, long long unsigned> cvp = find(n, 0); n   cout << cvp.first + !!cvp.second << endl; n   return; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10001001; n int min_div[MAXN]; n vector<long long> primes; n void criba() { n   for (int i = (int)0; i < (int)MAXN; i++) min_div[i] = i; n   for (int i = (int)2; i < (int)MAXN; i++) { n     if (min_div[i] != i) continue; n     primes.push_back(i); n     for (int j = i + i; j < MAXN; j += i) { n       min_div[j] = i; n     } n   } n } n void solve(long long* acum) { n   long long now = acum[MAXN - 1]; n   for (int i = MAXN - 2; i > 1; i--) { n     now += acum[i]; n     acum[i] = now; n   } n   for (int i = MAXN - 1; i > 1; i--) n     if (acum[i]) { n       if (min_div[i] == i) continue; n       int a = min_div[i]; n       int b = i / min_div[i]; n       acum[a] += acum[i]; n       acum[b] += acum[i]; n       acum[i] = 0; n     } n } n long long acum_a[MAXN]; n bool test(long long n) { n   for (int i = (int)0; i < (int)primes.size(); i++) { n     long long e = 0; n     long long n_t = n; n     while (n_t) { n       e += (n_t /= (long long)primes[i]); n     } n     if (e < acum_a[primes[i]]) return false; n   } n   return true; n } n int main() { n   criba(); n   int k; n   scanf( %d , &k); n   long long lo = 1, hi = 0; n   for (int i = (int)0; i < (int)k; i++) { n     int n = 1000101; n     scanf( %d , &n); n     acum_a[n]++; n     hi += n; n   } n   solve(acum_a); n   while (lo < hi) { n     long long mid = (lo + hi) / 2LL; n     if (test(mid)) { n       hi = mid; n     } else { n       lo = mid + 1; n     } n   } n   cout << lo << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 5; n int n; n char c[N]; n int main() { n   int T = 1; n   scanf( %d , &T); n   while (T--) { n     scanf( %s , c + 1); n     n = strlen(c + 1); n     printf( %d n , 4); n     printf( L 2 n ); n     printf( L 2 n ); n     printf( R 2 n ); n     n += 2; n     n += n - 2; n     printf( R %d n , n - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char grid[1005][1005]; n int lewo[1005][1005], prawo[1005][1005], gora[1005][1005], dol[1005][1005]; n bool odwiedzony[1005][1005]; n vector<pair<int, int> > przedzialy_x[1005], przedzialy_y[1005]; n vector<pair<pair<int, int>, int> > wynik; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int y, x, xd = 0, wszystkie = 0; n   cin >> y >> x; n   for (int i = 1; i <= y; i++) { n     for (int j = 1; j <= x; j++) { n       cin >> grid[i][j]; n       if (grid[i][j] ==  * ) wszystkie++; n       if (grid[i][j] ==  . ) n         lewo[i][j] = j; n       else n         lewo[i][j] = lewo[i][j - 1]; n     } n     prawo[i][x + 1] = x + 1; n     for (int j = x; j > 0; j--) { n       if (grid[i][j] ==  . ) n         prawo[i][j] = j; n       else n         prawo[i][j] = prawo[i][j + 1]; n     } n   } n   for (int i = 1; i <= x; i++) { n     for (int j = 1; j <= y; j++) { n       if (grid[j][i] ==  . ) n         gora[j][i] = j; n       else n         gora[j][i] = gora[j - 1][i]; n     } n     dol[y + 1][i] = y + 1; n     for (int j = y; j > 0; j--) { n       if (grid[j][i] ==  . ) n         dol[j][i] = j; n       else n         dol[j][i] = dol[j + 1][i]; n     } n   } n   for (int i = 2; i < y; i++) n     for (int j = 2; j < x; j++) { n       int pom = min(min(j - lewo[i][j] - 1, prawo[i][j] - j - 1), n                     min(i - gora[i][j] - 1, dol[i][j] - i - 1)); n       if (pom && grid[i][j] ==  * ) { n         przedzialy_x[i].push_back({j - pom, j + pom}); n         przedzialy_y[j].push_back({i - pom, i + pom}); n         wynik.emplace_back(make_pair(make_pair(i, j), pom)); n       } n     } n   for (int i = 1; i <= y; i++) { n     przedzialy_x[i].push_back({1e9, 1e9}); n     sort(przedzialy_x[i].begin(), przedzialy_x[i].end()); n     int indeks = 0; n     for (int j = 1; j <= x; j++) { n       while (przedzialy_x[i][indeks].second < j) indeks++; n       if (grid[i][j] ==  *  && przedzialy_x[i][indeks].first <= j) { n         xd++; n         odwiedzony[i][j] = true; n       } n     } n   } n   for (int i = 1; i <= x; i++) { n     przedzialy_y[i].push_back({1e9, 1e9}); n     sort(przedzialy_y[i].begin(), przedzialy_y[i].end()); n     int indeks = 0; n     for (int j = 1; j <= y; j++) { n       while (przedzialy_y[i][indeks].second < j) indeks++; n       if (grid[j][i] ==  *  && przedzialy_y[i][indeks].first <= j && n           !odwiedzony[j][i]) n         xd++; n     } n   } n   if (xd == wszystkie) { n     int aha = wynik.size(); n     cout << aha <<   n ; n     for (int i = 0; i < aha; i++) n       cout << wynik[i].first.first <<     << wynik[i].first.second <<     n            << wynik[i].second <<   n ; n   } else n     cout <<  -1 n ; n } n


#include <bits/stdc++.h> n using std::bitset; n using std::cin; n using std::cout; n using std::endl; n using std::make_pair; n using std::map; n using std::pair; n using std::priority_queue; n using std::queue; n using std::set; n using std::string; n using std::stringstream; n using std::vector; n class MyTimer { n  public: n   void reset() {} n   void report() {} n } myTimer; n template <typename A, typename B> n std::ostream &operator<<(std::ostream &cout, const pair<A, B> &x) { n   return cout <<  (  << x.first <<  ,   << x.second <<  ) ; n } n template <typename T1, typename T2> n inline bool chmin(T1 &a, const T2 &b) { n   return a > b ? a = b, true : false; n } n template <typename T1, typename T2> n inline bool chmax(T1 &a, const T2 &b) { n   return a < b ? a = b, true : false; n } n const int maxN = 100000 + 233; n int n, m; n int a[maxN], b[maxN], c[maxN], d[maxN], e[maxN]; n int ans[maxN]; n struct Q { n   int t; n   int x, y, L, R; n   Q(int t, int x, int y, int L, int R) : t(t), x(x), y(y), L(L), R(R) {} n   bool operator<(const Q &rhs) const { n     return x != rhs.x ? x < rhs.x : y != rhs.y ? y < rhs.y : t > rhs.t; n   } n }; n vector<Q> q, tmp; n void initialize() { n   std::ios::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 1; i <= n; ++i) cin >> b[i]; n   for (int i = 1; i <= n; ++i) cin >> c[i]; n   for (int i = 1; i <= m; ++i) cin >> d[i]; n   for (int i = 1; i <= m; ++i) cin >> e[i]; n   for (int i = 1; i <= n; ++i) { n     q.emplace_back(i, -c[i] + a[i], c[i] + a[i], a[i], b[i]); n   } n   for (int i = 1; i <= m; ++i) { n     q.emplace_back(-i, -e[i] + d[i], d[i] + e[i], d[i], d[i]); n   } n   vector<int> t; n   for (auto &p : q) t.push_back(p.L), t.push_back(p.R); n   std::sort(t.begin(), t.end()); n   t.erase(std::unique(t.begin(), t.end()), t.end()); n   for (auto &p : q) n     p.L = std::lower_bound(t.begin(), t.end(), p.L) - t.begin() + 1, n     p.R = std::lower_bound(t.begin(), t.end(), p.R) - t.begin() + 1; n   std::sort(q.begin(), q.end()); n   tmp.resize(q.size(), Q(0, 0, 0, 0, 0)); n } n int C[maxN * 3]; n void add(int p, int x) { n   p += 2; n   for (int i = p; i <= n * 2 + m + 5; i += i & -i) C[i] += x; n } n int sum(int p) { n   p += 2; n   int r = 0; n   for (int i = p; i > 0; i -= i & -i) r += C[i]; n   return r; n } n void solve(int L, int R) { n   if (L >= R) return; n   int M = (L + R) >> 1; n   solve(L, M); n   solve(M + 1, R); n   int i = L, j = M + 1, qwq = L; n   const auto left = [&](const Q &p) { n     tmp[qwq++] = p; n     if (p.t > 0) add(p.L, 1), add(p.R + 1, -1); n   }; n   const auto right = [&](const Q &p) { n     tmp[qwq++] = p; n     if (p.t < 0) ans[-p.t] += sum(p.L); n   }; n   while (i <= M && j <= R) { n     if (q[i].y < q[j].y || (q[i].y == q[j].y && q[i].t > 0)) n       left(q[i++]); n     else n       right(q[j++]); n   } n   while (i <= M) left(q[i++]); n   while (j <= R) right(q[j++]); n   for (int k = L; k <= M; ++k) n     if (q[k].t > 0) add(q[k].L, -1), add(q[k].R + 1, 1); n   for (int k = L; k <= R; ++k) q[k] = tmp[k]; n } n int main() { n   initialize(); n   solve(0, (int)q.size() - 1); n   for (int i = 1; i <= m; ++i) printf( %d%c , ans[i],    n [i == m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n void qr(int &x) { scanf( %d , &x); } n int n, sz[N], f[N], root, c[N]; n long long k, mn, mx; n struct edge { n   int y, next; n } a[N * 2]; n int len, last[N]; n void ins(int x, int y) { n   a[++len] = (edge){y, last[x]}; n   last[x] = len; n } n void dfs1(int x, int fa) { n   sz[x] = f[x] = 1; n   for (int k = last[x], y; k; k = a[k].next) { n     y = a[k].y; n     if (y ^ fa) { n       dfs1(y, x); n       sz[x] += sz[y]; n       mn += sz[y] & 1; n       mx += min(sz[y], n - sz[y]); n       f[x] = max(f[x], sz[y]); n     } n   } n   f[x] = max(f[x], n - sz[x]); n } n void dfs2(int x, int fa) { n   sz[x] = 1; n   for (int k = last[x], y; k; k = a[k].next) { n     y = a[k].y; n     if (y ^ fa) { n       dfs2(y, x); n       sz[x] += sz[y]; n     } n   } n   c[sz[x]]++; n } n vector<int> d[N]; n int son[N], tot, A[N], B[N]; n void dfs3(int x, int fa) { n   sz[x] = 1; n   for (int k = last[x], y; k; k = a[k].next) n     if ((y = a[k].y) ^ fa) dfs3(y, x), sz[x] += c[y]; n   int C = (sz[x] - c[x]) >> 1, st = 1, ed; n   son[tot = 1] = x; n   d[x].push_back(x); n   for (int k = last[x], y; k; k = a[k].next) n     if ((y = a[k].y) ^ fa) son[++tot] = y; n   ed = tot; n   for (int i = 1; i <= C; i++) { n     while (d[son[st]].empty()) st++; n     A[i] = d[son[st]].back(); n     d[son[st]].pop_back(); n     while (d[son[ed]].empty()) ed--; n     B[i] = d[son[ed]].back(); n     d[son[ed]].pop_back(); n   } n   for (int i = 1; i <= C; i++) printf( %d %d n , A[i], B[C - i + 1]); n   for (int i = 2; i <= tot; i++) { n     if (d[son[i]].size() > d[x].size()) swap(d[x], d[son[i]]); n     for (int j : d[son[i]]) d[x].push_back(j); n   } n } n int main() { n   qr(n); n   scanf( %lld , &k); n   for (int i = 1, x, y; i < n; i++) qr(x), qr(y), ins(x, y), ins(y, x); n   dfs1(1, 0); n   if (!(mn <= k && k <= mx) || (k - mn) % 2 == 1) puts( NO ), exit(0); n   root = 1; n   for (int i = 2; i <= n; i++) n     if (f[i] < f[root]) root = i; n   dfs2(root, 0); n   int p = n - 1; n   for (; p > 1; p--) n     if (mx - c[p] * 2 >= k) { n       mx -= c[p] * 2; n       c[p - 2] += c[p]; n     } else n       break; n   for (int i = 1; i <= n; i++) c[i] = min(sz[i], p - (p + sz[i]) % 2); n   c[root] = 0; n   for (int i = 1; i <= n; i++) n     if (c[i] == p && mx > k) { n       mx -= 2; n       c[i] -= 2; n     } n   puts( YES ); n   dfs3(root, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 111111; n const int INF = 0x3f3f3f3f; n int vis[maxn]; n bool selected[maxn]; n int n, m; n vector<int> adj[maxn]; n bool test[maxn]; n double elapsed() { return clock() / (double)CLOCKS_PER_SEC; } n bool dfs(int v) { n   if (selected[v] == true) return false; n   vis[v] = -1; n   for (auto w : adj[v]) { n     if (vis[w] == 0) { n       if (dfs(w)) return true; n     } else if (vis[w] == -1) { n       for (int i = 1; i <= n; i++) { n         if (vis[i] != -1) test[i] = true; n       } n       return true; n     } n   } n   vis[v] = 1; n   return false; n } n bool check() { n   memset(vis, 0, sizeof vis); n   for (int i = 1; i <= n; i++) { n     if (!vis[i] && dfs(i)) return false; n   } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n   } n   vector<int> emp; n   for (int i = 0; i < n; ++i) emp.push_back(i + 1); n   random_shuffle(emp.begin(), emp.end()); n   for (int i = 0; elapsed() <= 0.95 and i < emp.size(); i++) { n     selected[emp[i]] = true; n     if (!test[emp[i]] && check()) { n       printf( %d n , emp[i]); n       return 0; n     } n     selected[emp[i]] = false; n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n inline int gi() { n   char c; n   int num = 0, flg = 1; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) flg = -1; n   while (c >=  0  && c <=  9 ) { n     num = num * 10 + c - 48; n     c = getchar(); n   } n   return num * flg; n } n int n, m; n int fir[200005], cur[200005], to[5000005], nxt[5000005], cap[5000005], n     id[2 * 200005], cnt; n void adde(int a, int b, int c, int d = 0) { n   to[++cnt] = b; n   nxt[cnt] = fir[a]; n   fir[a] = cnt; n   cap[cnt] = c; n   if (d) id[cnt] = d; n   to[++cnt] = a; n   nxt[cnt] = fir[b]; n   fir[b] = cnt; n   cap[cnt] = 0; n   if (d) id[cnt] = d; n } n int fa[200005], son[200005], sonp[200005], siz[200005], top[200005], n     dep[200005]; n void dfs1(int u) { n   dep[u] = dep[fa[u]] + 1; n   siz[u] = 1; n   for (int v, p = fir[u]; p; p = nxt[p]) { n     if ((v = to[p]) != fa[u]) { n       fa[v] = u; n       dfs1(v); n       siz[u] += siz[v]; n       if (siz[son[u]] < siz[v]) son[u] = v, sonp[u] = p; n     } n   } n } n int pos[200005], dc, dfn[200005]; n void dfs2(int u, int fro) { n   pos[u] = ++dc; n   dfn[dc] = id[fro]; n   if (son[u]) top[son[u]] = top[u], dfs2(son[u], sonp[u]); n   for (int v, p = fir[u]; p; p = nxt[p]) n     if ((v = to[p]) != fa[u] && v != son[u]) top[v] = v, dfs2(v, p); n } n int S, T, sz; n const int INF = 0x3f3f3f3f; n struct node { n   int l, r; n } a[200005]; n int rt; n void build(int &i, int l, int r) { n   if (l == r) { n     i = dfn[l]; n     return; n   } n   i = ++sz; n   int mid = (l + r) >> 1; n   build(a[i].l, l, mid); n   build(a[i].r, mid + 1, r); n   adde(i, a[i].l, INF); n   adde(i, a[i].r, INF); n } n void insert(int i, int l, int r, int ql, int qr, int p) { n   if (l > qr || r < ql) return; n   if (ql <= l && r <= qr) { n     adde(p, i, INF); n     return; n   } n   int mid = (l + r) >> 1; n   insert(a[i].l, l, mid, ql, qr, p); n   insert(a[i].r, mid + 1, r, ql, qr, p); n } n void QP(int x, int y, int p) { n   while (top[x] != top[y]) { n     if (dep[top[x]] < dep[top[y]]) swap(x, y); n     insert(rt, 1, n, pos[top[x]], pos[x], p); n     x = fa[top[x]]; n   } n   if (dep[x] > dep[y]) swap(x, y); n   insert(rt, 1, n, pos[x] + 1, pos[y], p); n } n queue<int> q; n int dis[200005]; n bool bfs() { n   for (int i = 1; i <= sz; i++) dis[i] = -1; n   q.push(T); n   dis[T] = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int v, p = fir[u]; p; p = nxt[p]) { n       v = to[p]; n       if (cap[p ^ 1] > 0 && dis[v] == -1) { n         dis[v] = dis[u] + 1; n         q.push(v); n       } n     } n   } n   return dis[S] != -1; n } n int sap(int u, int aug) { n   if (u == T) return aug; n   int tmp, ret = 0; n   for (int v, &p = cur[u]; p; p = nxt[p]) { n     v = to[p]; n     if (cap[p] > 0 && dis[u] == dis[v] + 1) { n       tmp = sap(v, min(cap[p], aug)); n       cap[p] -= tmp; n       aug -= tmp; n       cap[p ^ 1] += tmp; n       ret += tmp; n       if (!aug) break; n     } n   } n   return ret; n } n int flow; n void maxflow() { n   flow = 0; n   while (bfs()) { n     for (int i = 1; i <= sz; i++) cur[i] = fir[i]; n     flow += sap(S, INF); n   } n } n int main() { n   int i, u, v; n   n = gi(); n   m = gi(); n   for (i = 1; i < n; i++) { n     u = gi(); n     v = gi(); n     adde(u, v, 0, i); n   } n   dfs1(1); n   top[1] = 1; n   dfs2(1, 0); n   memset(fir, 0, sizeof(fir)); n   cnt = 1; n   sz = n; n   build(rt, 1, n); n   for (i = 1; i <= m; i++) { n     u = gi(); n     v = gi(); n     QP(u, v, sz + i); n   } n   S = sz + m + 1; n   T = sz + m + 2; n   int tot = sz; n   for (i = 1; i < n; i++) adde(i, T, 1); n   for (i = 1; i <= m; i++) adde(S, sz + i, 1); n   sz = T; n   maxflow(); n   printf( %d n , flow); n   int cnt1 = 0, cnt2 = 0; n   for (i = 1; i <= m; i++) n     if (dis[tot + i] != -1) cnt1++; n   for (i = 1; i < n; i++) n     if (dis[i] == -1) cnt2++; n   printf( %d , cnt1); n   for (i = 1; i <= m; i++) n     if (dis[tot + i] != -1) printf(  %d , i); n   printf(  n ); n   printf( %d , cnt2); n   for (i = 1; i < n; i++) n     if (dis[i] == -1) printf(  %d , i); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long a[212345], sumi, wow, i; n int main() { n   std::ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     sumi += a[i]; n   } n   wow = 0; n   for (i = 0; i < n; i++) { n     wow += a[i]; n     if (2 * wow >= sumi) break; n   } n   cout << i + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9, maxn = (int)1e5 + 1; n const double eps = (double)1e-8; n const int mod = (int)1000000009; n int n, a[1001], x, y, xx, yy, z, my, mx; n vector<pair<int, bool> > b[3000]; n string c, st; n int main() { n   my = 1500; n   z = 1500; n   cin >> n; n   x = 0; n   y = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     xx = x; n     yy = y; n     x += a[i]; n     if (i & 1) { n       y += a[i]; n       for (int j = yy; j < y; j++) n         b[z + j].push_back(make_pair(xx + j - yy, 1)); n     } else { n       y -= a[i]; n       for (int j = yy - 1; j >= y; j--) n         b[z + j].push_back(make_pair(xx + (yy - j - 1), 0)); n     } n     my = max(my, y + z); n   } n   st =   ; n   for (int i = 0; i < x; i++) st +=    ; n   mx = x; n   for (int i = my - 1;; i--) { n     c = st; n     if (b[i].size() == 0) break; n     for (int j = 0; j < b[i].size(); j++) { n       if (b[i][j].second) n         c[b[i][j].first] =  / ; n       else n         c[b[i][j].first] = char(92); n     } n     cout << c << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int H, M, N; n set<int> a[200005]; n int p[200005], seq[200005], r = 0; n int u[200005]; n map<int, pair<int, int> > history; n void release(pair<int, int> P) { a[P.first].insert(P.second); } n int main(void) { n   scanf( %d%d%d , &H, &M, &N); n   for (int i = 0; i < H; i++) { n     if (!u[i]) { n       for (int c = 0, j = i; !u[j]; j = (j + M) % H, ++c) { n         p[j] = r; n         seq[j] = c; n         a[r].insert(c); n         u[j] = 1; n       } n       ++r; n     } n   } n   long long ans = 0; n   while (N--) { n     char x[10]; n     int id, hash; n     scanf( %s%d , x, &id); n     if (x[0] ==  - ) n       release(history[id]); n     else { n       scanf( %d , &hash); n       hash %= H; n       int A = p[hash], B = seq[hash]; n       set<int>::iterator it = a[A].lower_bound(B); n       if (it == a[A].end()) { n         it = a[A].begin(); n         ans += *it + H / r - B; n       } else { n         ans += *it - B; n       } n       history[id] = make_pair(A, *it); n       a[A].erase(it); n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n int main() { n   int n; n   cin >> n; n   int graph[n][n]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       graph[i][j] = INF; n     } n   } n   for (int i = 0; i < n - 1; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     graph[a][b] = graph[b][a] = c; n   } n   for (int k = 0; k < n; k++) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (graph[i][j] >= graph[i][k] + graph[k][j]) { n           graph[i][j] = graph[i][k] + graph[k][j]; n         } n       } n     } n   } n   int ans = 0; n   for (int i = 1; i < n; i++) { n     if (graph[0][i] != INF) ans = max(ans, graph[0][i]); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 300333, inf = 1011111111; n int n, m, a[max_n], used[max_n], pos, lb[max_n]; n vector<int> g2[max_n], num2[max_n], g[max_n], num[max_n], k, ans; n void dfs(int v) { n   used[v] = 1; n   for (int i = 0; i < g2[v].size(); ++i) { n     if (used[g2[v][i]] == 0) { n       g[v].push_back(g2[v][i]); n       num[v].push_back(num2[v][i]); n       dfs(g2[v][i]); n     } n   } n } n void dfs2(int v) { n   for (int i = 0; i < g[v].size(); ++i) { n     dfs2(g[v][i]); n     lb[v] ^= lb[g[v][i]]; n     if (lb[g[v][i]]) { n       ans.push_back(num[v][i]); n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   pos = -1; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     if (a[i] == -1) { n       pos = i; n     } n     if (a[i] == 1) { n       k.push_back(i); n     } n   } n   if (pos == -1 && k.size() % 2 != 0) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     g2[u].push_back(v); n     g2[v].push_back(u); n     num2[u].push_back(i); n     num2[v].push_back(i); n   } n   dfs(1); n   for (int i = 0; i + 1 < k.size(); i += 2) { n     lb[k[i]] = 1; n     lb[k[i + 1]] = 1; n   } n   if (k.size() % 2) { n     lb[pos] = 1; n     lb[k.back()] = 1; n   } n   dfs2(1); n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); ++i) { n     printf( %d n , ans[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   int ans; n   scanf( %d%d%d , &a, &b, &c); n   ans = (a - b) * c; n   if (!(ans % b)) n     ans /= b; n   else { n     ans /= b; n     ans += 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005, INF = 1e18; n void solve() { n   long long n, ans = 0, max = 0; n   cin >> n; n   ans = n / 2; n   cout << ans <<   n ; n   for (long long i = (long long)0; i < ans - 1; i++) { n     cout <<  2  ; n   } n   if (n % 2 == 0) n     cout << 2 <<   n ; n   else n     cout << 3 <<   n ; n } n int32_t main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010, maxp = 1000010; n int x[maxn], dp[maxp][20], can[maxp], f[maxp]; n int n, a, b; n inline void chkmax(int& a, int b) { n   if (a < b) a = b; n } n inline void chkmin(int& a, int b) { n   if (a > b) a = b; n } n int getmin(int l, int r) { n   int b; n   for (b = 0; l + (1 << b) < r - (1 << b) + 1; b++) n     ; n   return min(dp[l][b], dp[r - (1 << b) + 1][b]); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &x[i]); n   sort(x, x + n); n   n = unique(x, x + n) - x; n   scanf( %d %d , &a, &b); n   swap(a, b); n   for (int i = 0; i < n; i++) { n     int st = a - a % x[i]; n     if (st != a) st += x[i]; n     while (st <= b) { n       chkmax(can[st - a], x[i]); n       st += x[i]; n     } n   } n   int length = b - a + 1; n   memset(f, 0x3f, sizeof f); n   dp[length - 1][0] = 0; n   f[length - 1] = 0; n   for (int i = length - 2; i >= 0; i--) { n     int pos = min(length - 1, i + can[i] - 1); n     if (can[i] > 1) chkmin(f[i], getmin(i + 1, pos) + 1); n     chkmin(f[i], f[i + 1] + 1); n     dp[i][0] = f[i]; n     for (int j = 1; i + (1 << j) <= length; j++) n       dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]); n   } n   printf( %d n , f[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> g[100000]; n vector<int> rev_g[100000]; n vector<int> post_order; n vector<bool> visited; n vector<int> scc; n void dfs1(int x) { n   if (visited[x]) return; n   visited[x] = true; n   for (auto y : g[x]) dfs1(y); n   post_order.push_back(x); n } n void dfs2(int x, int cc) { n   if (visited[x]) return; n   visited[x] = true; n   scc[x] = cc; n   for (auto y : rev_g[x]) dfs2(y, cc); n } n int Kosaraju() { n   visited = vector<bool>(n, false); n   for (int i = 0; i < n; i++) dfs1(i); n   scc = vector<int>(n, -1); n   visited = vector<bool>(n, false); n   int cc = 0; n   assert(post_order.size() == n); n   reverse(post_order.begin(), post_order.end()); n   for (auto x : post_order) n     if (scc[x] == -1) dfs2(x, cc++); n   return cc; n } n set<int> par_scc[100000]; n set<int> chi_scc[100000]; n vector<int> scc_list[100000]; n stack<int> source_scc; n int q = 0; n int pos = 0; n bool get_dir(int a, int b) { n   q++; n   printf( ? %d %d n , a + 1, b + 1); n   fflush(stdout); n   int res; n   scanf( %d , &res); n   if (res == 1) pos++; n   return (res == 1); n } n int main() { n   scanf( %d%d , &n, &m); n   int v = -1, w; n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     g[a].push_back(b); n     rev_g[b].push_back(a); n   } n   int ncc = Kosaraju(); n   for (int i = 0; i < n; i++) n     for (auto j : g[i]) n       if (scc[i] != scc[j]) { n         assert(scc[i] >= 0 && scc[j] >= 0 && scc[i] < n && scc[j] < n); n         par_scc[scc[j]].insert(scc[i]); n         chi_scc[scc[i]].insert(scc[j]); n       } n   for (int i = 0; i < n; i++) scc_list[scc[i]].push_back(i); n   for (int i = 0; i < ncc; i++) n     if (par_scc[i].empty()) source_scc.push(i); n   int cur_scc = source_scc.top(); n   int cur_i = 0; n   int cur_size = scc_list[cur_scc].size(); n   source_scc.pop(); n   int nxt_scc, nxt_i, nxt_size; n   while (!source_scc.empty()) { n     nxt_scc = source_scc.top(); n     nxt_i = 0; n     nxt_size = scc_list[nxt_scc].size(); n     source_scc.pop(); n     while (cur_i < cur_size && nxt_i < nxt_size) { n       if (!get_dir(scc_list[cur_scc][cur_i], scc_list[nxt_scc][nxt_i])) { n         swap(cur_scc, nxt_scc); n         swap(cur_i, nxt_i); n         swap(cur_size, nxt_size); n       } n       nxt_i++; n     } n     assert(nxt_i == nxt_size); n     for (auto x : chi_scc[nxt_scc]) { n       par_scc[x].erase(nxt_scc); n       if (par_scc[x].empty()) source_scc.push(x); n     } n   } n   printf( ! %d n , scc_list[cur_scc][cur_i] + 1); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int query(int x, int y) { n   cout <<  1   << x <<     << y << endl; n   string ans; n   cin >> ans; n   if (ans ==  TAK ) return 1; n   return 0; n } n int find(int l, int r) { n   if (l > r) return -1; n   int L = l; n   int R = r; n   while (L < R) { n     int mid = (L + R) / 2; n     if (query(mid, mid + 1)) n       R = mid; n     else n       L = mid + 1; n   } n   return L; n } n int main() { n   cin >> n >> k; n   int x = find(1, n); n   int y = find(1, x - 1); n   if (x == 1 || !query(y, x)) y = find(x + 1, n); n   cout <<  2   << x <<     << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, s, t; n int read() { n   int x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n int n1, n2, n3, p1, p2, p3, m1, m2, m3, st; n long long m, n, ans; n int st2[1010000], sta[1010000]; n struct data { n   int p, q; n }; n bool cmp(const data &a, const data &b) { return a.p < b.p; } n struct da { n   data a[50]; n   int n; n } a, b; n long long qpow(long long x, int y) { n   long long ans = 1; n   while (y) { n     if (y & 1) ans *= x; n     x *= x; n     y >>= 1; n   } n   return ans; n } n void solve1(int x, long long y) { n   if (y > n) return; n   if (x == b.n + 1) { n     ans++; n     return; n   } n   solve1(x + 1, y); n   for (int i = 1; i <= b.a[x].q; i++) y *= b.a[x].p, solve1(x + 1, y); n } n void solve2(int x, long long y, int f) { n   if (!y) return; n   if (x == st + 1) { n     ans += y * f; n     return; n   } n   solve2(x + 1, y, f); n   for (int i = 1; i <= st2[x]; i++) y /= sta[x]; n   solve2(x + 1, y, -f); n } n void pre(da &a, int x) { n   int i, j, k; n   for (i = 1; i <= a.n; i++) n     while (x % a.a[i].p == 0) x /= a.a[i].p, a.a[i].q++; n   for (i = 2; i * i <= x; i++) n     if (x % i == 0) { n       a.n++; n       a.a[a.n].p = i; n       a.a[a.n].q = 0; n       while (x % i == 0) x /= i, a.a[a.n].q++; n     } n   if (x > 1) { n     a.n++; n     a.a[a.n].p = x; n     a.a[a.n].q = 1; n   } n } n int main() { n   int T = read(); n   while (T--) { n     n1 = read(); n     n2 = read(); n     n3 = read(); n     n = (long long)n1 * n2 * n3; n     m1 = read(); n     m2 = read(); n     m3 = read(); n     m = (long long)m1 * m2 * m3; n     p1 = read(); n     p2 = read(); n     p3 = read(); n     a.n = 0; n     b.n = 0; n     ans = 0; n     pre(a, n1); n     pre(a, n2); n     pre(a, n3); n     pre(b, p1); n     pre(b, p2); n     pre(b, p3); n     pre(b, 2); n     sort(a.a + 1, a.a + a.n + 1, cmp); n     sort(b.a + 1, b.a + b.n + 1, cmp); n     solve1(1, 1); n     j = 1; n     st = 0; n     for (i = 1; i <= a.n; i++) { n       while (b.a[j].p < a.a[i].p && j <= b.n) j++; n       if (j == b.n + 1) break; n       if (b.a[j].p == a.a[i].p && a.a[i].q > b.a[j].q) { n         sta[++st] = a.a[i].p; n         st2[st] = b.a[j].q + 1; n       } n       if (b.a[j].p > a.a[i].p) { n         sta[++st] = a.a[i].p; n         st2[st] = 1; n       } n     } n     for (; i <= a.n; i++) { n       sta[++st] = a.a[i].p; n       st2[st] = 1; n     } n     solve2(1, m, 1); n     cout << ans << endl; n   } n } n