#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.sync_with_stdio(false), cin.tie(nullptr); n   int tests; n   cin >> tests; n   while (tests--) { n     int n, k; n     string s; n     cin >> n >> k >> s; n     const int need = n / k; n     vector<vector<int>> counts(k, vector<int>(26, 0)); n     for (int i = 0; i < n; i++) { n       counts[i % k][s[i] -  a ]++; n     } n     int ans = 0; n     for (int i = 0, j = k - 1; i <= j; i++, j--) { n       int cost = need * 2 - counts[i][0] - counts[j][0]; n       for (int c = 1; c < 26; c++) { n         cost = min(cost, need * 2 - counts[i][c] - counts[j][c]); n       } n       ans += (i == j ? cost / 2 : cost); n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> solve(vector<int> a) { n   int n = (int)a.size(); n   vector<int> dp(n + 1, 1e9); n   dp[0] = -1e9; n   vector<int> ret(n); n   for (int i = 0; i < n; i++) { n     int x = (int)(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin()); n     ret[i] = x; n     dp[x] = a[i]; n   } n   return ret; n } n int main() { n   int n, m; n   cin >> m >> n; n   vector<int> a(n); n   vector<int> delta(n + 1); n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     delta[x]++; n     delta[y]--; n   } n   int temp = 0; n   for (int i = 0; i < n; i++) { n     temp += delta[i]; n     a[i] = temp; n   } n   auto l = solve(a); n   reverse(a.begin(), a.end()); n   auto r = solve(a); n   reverse(r.begin(), r.end()); n   int ans = 0; n   for (int i = 0; i < n; i++) { n     ans = max(ans, l[i] + r[i] - 1); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long N = 1e9 + 7; n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   long long b[n]; n   long long sum = 0; n   for (int i = 0; i < n; i++) sum += v[i]; n   long long x = (n * (n + 1)) / 2; n   long long tot = sum / x; n   if (sum % x != 0) { n     cout <<  NO ; n     return; n   } n   b[0] = v[n - 1] - v[0]; n   for (int i = 1; i < n; i++) { n     b[i] = v[i - 1] - v[i]; n   } n   long long ans = 0; n   vector<long long> an; n   for (int i = 0; i < n; i++) { n     ans = (b[i] + tot) / (n); n     an.push_back(ans); n   } n   if ((b[0] + tot) % n != 0) an[0] = -1; n   int f = 1; n   for (int i = 0; i < n; i++) { n     if (an[i] <= 0) f = 0; n   } n   if (f) { n     cout <<  YES n ; n     for (auto y : an) cout << y <<    ; n   } else { n     cout <<  NO ; n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   map<char, long long> m; n   for (long long i = 0; i < 26; i++) { n     char ch; n     cin >> ch; n     m[ch] = i; n   } n   string str; n   cin >> str; n   long long ans = 0, sum = 0; n   for (long long i = 0; i < str.length() - 1; i++) { n     sum = abs(m[str[i]] - m[str[i + 1]]); n     ans += sum; n   } n   cout << ans <<   n ; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   long long t = 1; n   cin >> t; n   for (long long i = 0; i < t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 3; n char ch; n bool flag = 0; n void read(int &x) { n   for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1); n        ch = getchar()) n     ; n   for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar()) n     ; n   x *= 1 - 2 * flag; n } n string ans =   ; n bool h = 0; n string s; n void fu() { n   if (cin >> s) { n     ans += s; n     if (s ==  pair ) { n       ans +=  < ; n       fu(); n       ans +=  , ; n       fu(); n       ans +=  > ; n     } n   } else { n     h = 1; n   } n   if (h) return; n } n int main() { n   int n; n   read(n); n   fu(); n   if (h || (cin >> s)) n     cout <<  Error occurred  << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n long long mod = 1000000007LL; n long long mod2 = 998244353LL; n int n; n int t, q; n long long a[100005], b[100005]; n long long pre[100005]; n struct node { n   int l, r; n   long long mx, mn; n } tree[100005 << 2]; n void build(int id, int l, int r) { n   tree[id].l = l; n   tree[id].r = r; n   if (l == r) { n     tree[id].mx = pre[l]; n     tree[id].mn = pre[l]; n     return; n   } n   int mid = (l + r) / 2; n   build(id * 2, l, mid); n   build(id * 2 + 1, mid + 1, r); n   tree[id].mx = max(tree[id * 2].mx, tree[id * 2 + 1].mx); n   tree[id].mn = min(tree[id * 2].mn, tree[id * 2 + 1].mn); n } n long long query(int id, int l, int r, bool mx) { n   if (tree[id].l == l && tree[id].r == r) { n     return (mx ? tree[id].mx : tree[id].mn); n   } n   int mid = (tree[id].l + tree[id].r) / 2; n   if (r <= mid) n     return query(id * 2, l, r, mx); n   else if (l > mid) n     return query(id * 2 + 1, l, r, mx); n   else { n     long long r1 = query(id * 2, l, mid, mx); n     long long r2 = query(id * 2 + 1, mid + 1, r, mx); n     return (mx ? max(r1, r2) : min(r1, r2)); n   } n } n int main() { n   cin >> n >> q; n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &a[i]); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &b[i]); n   } n   pre[0] = 0LL; n   for (int i = 1; i <= n; ++i) { n     pre[i] = pre[i - 1] + b[i] - a[i]; n   } n   build(1, 1, n); n   while (q-- > 0) { n     int l, r; n     scanf( %d%d , &l, &r); n     if (pre[r] - pre[l - 1] != 0 || query(1, l, r, false) < pre[l - 1]) { n       puts( -1 ); n     } else { n       printf( %lld n , query(1, l, r, true) - pre[l - 1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x, y; n vector<long long> cnt; n vector<char> sol; n bool ok; n void solve(long long x, long long y) { n   if (!x) { n     if (y == 1) ok = 1; n     return; n   } n   if (!y) { n     if (x == 1) ok = 1; n     return; n   } n   if (x == y) { n     if (x == 1) ok = 1; n     return; n   } n   if (x > y) { n     sol.push_back( A ); n     if (x % y == 0) { n       cnt.push_back(x / y - 1); n     } else { n       cnt.push_back(x / y); n     } n     solve(x % y, y); n   } else { n     sol.push_back( B ); n     if (y % x == 0) { n       cnt.push_back(y / x - 1); n     } else { n       cnt.push_back(y / x); n     } n     solve(x, y % x); n   } n } n int main() { n   cin >> x >> y; n   solve(x, y); n   if (ok) { n     for (int i = 0; i < sol.size(); ++i) { n       cout << cnt[i] << sol[i]; n     } n   } else { n     cout <<  Impossible ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[100003], b[100003]; n int ggg[100003]; n string a; n long long d, e, f, g, ming, oo, ksa, lxy; n bool nn, o; n int main() { n   gets(c); n   c[strlen(c)] =    ; n   a = c; n   for (int i = 0; i <= a.length(); i++) { n     if (a.substr(i, 1) ==    ) { n       if (o == 0) { n         if (i >= 5 && a.substr(i - 5, 5) ==  liala ) n           nn = 1; n         else if (i >= 4 && a.substr(i - 4, 4) ==  etra ) n           nn = 1; n         else if (i >= 6 && a.substr(i - 6, 6) ==  inites ) n           nn = 1; n         o = 1; n       } n       if (!nn) { n         if (i >= 3 && a.substr(i - 3, 3) ==  etr ) { n           ming += 1; n           g++; n           ggg[g] = 2; n         } else if (i >= 6 && a.substr(i - 6, 6) ==  initis ) { n           g++; n           ggg[g] = 3; n         } else if (i >= 4 && a.substr(i - 4, 4) ==  lios ) { n           g++; n           ggg[g] = 1; n         } else { n           cout <<  NO  << endl; n           return 0; n         } n       } n       if (nn) { n         if (i >= 4 && a.substr(i - 4, 4) ==  etra ) { n           g++; n           ggg[g] = 2; n           ming += 1; n         } else if (i >= 6 && a.substr(i - 6, 6) ==  inites ) { n           g++; n           ggg[g] = 3; n         } else if (i >= 5 && a.substr(i - 5, 5) ==  liala ) { n           g++; n           ggg[g] = 1; n         } else { n           cout <<  NO  << endl; n           return 0; n         } n       } n       oo++; n     } n   } n   if (oo == 1) { n     if (a.length() >= 5 && a.substr(a.length() - 5, 4) ==  lios ) ming = 1; n     if (a.length() >= 4 && a.substr(a.length() - 4, 3) ==  etr ) ming = 1; n     if (a.length() >= 7 && a.substr(a.length() - 7, 6) ==  inites ) ming = 1; n     if (a.length() >= 7 && a.substr(a.length() - 7, 6) ==  initis ) ming = 1; n     if (a.length() >= 6 && a.substr(a.length() - 6, 5) ==  liala ) ming = 1; n     if (a.length() >= 5 && a.substr(a.length() - 5, 4) ==  etra ) ming = 1; n   } n   for (int i = 1; i <= 100002; i++) { n     if (ggg[i] == 0) { n       ksa = 1; n       break; n     } n     if (ggg[i] < ggg[i - 1]) break; n   } n   if (ming == 1 && oo == 1) { n     cout <<  YES  << endl; n     return 0; n   } else if (oo == 1) { n     cout <<  NO  << endl; n     return 0; n   } n   if (ming == 1 && ksa == 1) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y; n }; n Point points[100000]; n int gcd(int a, int b) { n   if (b) return gcd(b, a % b); n   return a; n } n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     long double A = 0.0; n     long double b = 0.0; n     for (int i = int(0); i < int(n); i++) { n       scanf( %lf %lf , &points[i].x, &points[i].y); n     } n     long double totProb = 1.0; n     if (n < 60) { n       totProb = pow(2., n) - n * (n - 1) / 2. - n - 1; n       for (int i = int(0); i < int(n); i++) { n         for (int j = int(1); j < int(n); j++) { n           int k = (i + j) % n; n           long double prob = pow(2, n - j - 1) - 1.; n           A += prob * (points[i].x * points[k].y - points[k].x * points[i].y); n           b += prob * gcd(abs(points[i].x - points[k].x), n                           abs(points[i].y - points[k].y)); n         } n       } n     } else { n       for (int i = int(0); i < int(n); i++) { n         for (int j = int(1); j < int(60); j++) { n           int k = (i + j) % n; n           long double prob = pow(2, -j - 1); n           A += prob * (points[i].x * points[k].y - points[k].x * points[i].y); n           b += prob * gcd(abs(points[i].x - points[k].x), n                           abs(points[i].y - points[k].y)); n         } n       } n     } n     double ans = (A - b) / totProb / 2. + 1.; n     printf( %.12lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const long long MAX = 6e6 + 10; n int w[1000]; n int a[1000]; n void solve() { n   int n; n   cin >> n; n   memset(a, 0, sizeof(a)); n   for (int i = 0; i < n; i++) { n     cin >> w[i]; n     a[w[i]]++; n   } n   int ans = 0; n   for (int i = 2; i <= n * 2; i++) { n     int sum = 0; n     for (int j = 0; j <= i; j++) { n       sum += min(a[j], a[i - j]); n     } n     ans = max(ans, sum / 2); n   } n   cout << ans << endl; n } n int main() { n   int _ = 1; n   cin >> _; n   while (_--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, i, a[200], s1, s2, j = 2; n string can =  YES ; n int main() { n   cin >> n; n   cin >> x; n   x = 7 - x; n   for (i = 0; i < n * 2; i++) { n     cin >> a[i]; n   } n   for (i = 1; i < n; i++) { n     s1 = a[j]; n     s2 = a[j + 1]; n     if (x == s1 || x == s2 || x == 7 - s2 || x == 7 - s1) { n       can =  NO ; n       break; n     } n     j += 2; n   } n   cout << can; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 502; n long long c[maxN][maxN]; n long long a[maxN]; n int n, m, b, md; n int main() { n   cin >> n >> m >> b >> md; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   c[0][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < m; j++) n       for (int t = 0; t <= b - a[i]; t++) n         if (c[j][t] > 0) { n           c[j + 1][t + a[i]] = (c[j + 1][t + a[i]] + c[j][t]) % md; n         } n   long long ans = 0; n   for (int i = 0; i <= b; i++) ans = (ans + c[m][i]) % md; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void print(vector<long long> v) { n   long long n = v.size(); n   for (long long i = 0; i < n; i++) { n     cout << v[i] <<    ; n   } n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b != 0) { n     if (b & 1) { n       res *= a; n     } n     a = (a * a); n     b = (b / 2); n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n; n   cin >> n; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n   } n   if (n <= 3) { n     cout << 1; n     return 0; n   } n   vector<long long> v1 = v; n   sort(v1.begin(), v1.end()); n   vector<long long> diff; n   map<long long, vector<long long> > mp; n   for (long long i = 1; i < n; i++) { n     diff.push_back(v1[i] - v1[i - 1]); n     mp[diff[i - 1]].push_back(i); n   } n   if (mp.size() > 3) { n     cout << -1; n     return 0; n   } n   if (mp.size() == 1) { n     for (long long i = 0; i < n; i++) { n       if (v[i] == v1[0]) { n         cout << i + 1; n         return 0; n       } n     } n   } n   if (mp.size() == 2) { n     auto it = mp.begin(); n     vector<long long> v2 = it->second; n     if (v2.size() == 1) { n       long long x = v2[0], y; n       if (x == 1) y = v1[0]; n       if (x == n - 1) y = v1[x]; n       if (x == 1 || x == n - 1) { n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n       if (it->first == 0) { n         long long y = v1[v2[0]]; n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n     } n     if (v2.size() == 2) { n       auto it2 = it; n       it2++; n       if (v2[1] - v2[0] == 1 && it->first * 2 == it2->first) { n         long long x = v2[0], y; n         y = v1[x]; n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n     } n     it++; n     v2 = it->second; n     if (v2.size() == 1) { n       long long x = v2[0], y; n       if (x == 1) y = v1[0]; n       if (x == n - 1) y = v1[x]; n       if (x == 1 || x == n - 1) { n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n     } n     if (v2.size() == 2) { n       auto it2 = it; n       it2++; n       if (v2[1] - v2[0] == 1 && it->first * 2 == it2->first) { n         long long x = v2[0], y; n         y = v1[x]; n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n     } n   } n   if (mp.size() == 3) { n     auto it = mp.begin(); n     auto it1 = it; n     it1++; n     auto it2 = it1; n     it2++; n     if (it->first + it1->first == it2->first) { n       if (abs(it->second[0] - it1->second[0]) == 1) { n         long long x1 = it->second[0], x2 = it1->second[0]; n         long long x = min(x1, x2); n         long long y = v1[x]; n         for (long long i = 0; i < n; i++) { n           if (v[i] == y) { n             cout << i + 1; n             return 0; n           } n         } n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long x, d; n   int cntDist = 0; n   string inp; n   cin >> n >> x; n   getline(cin, inp); n   for (int i = 0; i < n; i++) { n     getline(cin, inp); n     stringstream ss(inp.substr(2)); n     ss >> d; n     if (inp[0] ==  + ) { n       x += d; n     } else { n       if (x < d) n         cntDist++; n       else n         x -= d; n     } n   } n   cout << x <<     << cntDist; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> a >> b >> c; n   a = a % b; n   d[a]++; n   int t; n   for (int i = 1; i <= 100005; ++i) { n     t = a * 10 / b; n     if (t == c) { n       cout << i; n       exit(0); n     } n     a = ((a * 10) % b); n     d[a]++; n     if (d[a] == 2) { n       cout <<  -1 ; n       exit(0); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void _fill_int(int* p, int val, int rep) { n   int i; n   for (i = 0; i < rep; i++) p[i] = val; n } n signed long long GETi() { n   signed long long i; n   scanf( %lld , &i); n   return i; n } n int N; n map<vector<int>, double> M[64]; n int st[64], num[64]; n double dodo(int top, vector<int> V) { n   int otop, i, x, y, z, ng = 0; n   otop = top = st[top]; n   sort(V.begin(), V.end()); n   vector<int> VV = V; n   if (M[top].find(V) != M[top].end()) return M[top][V]; n   if (num[top] == 3) V.push_back(top), top = 0, ng = 1; n   double ma[4] = {0, 1e15, 1e15, 1e15}; n   int pre = -1; n   for (i = 0; i < V.size() - ng; i++) { n     if (pre == V[i]) continue; n     pre = V[i]; n     x = V[i] % 4; n     y = V[i] / 4 % 4; n     z = V[i] / 16; n     vector<int> V2 = V; n     V2.erase(V2.begin() + i); n     if (x && y && z) { n       if (top % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 1, V2)); n       if (top / 4 % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 4, V2)); n       if (top / 16 == 0 && top % 4) ma[y] = min(ma[y], dodo(top + y * 16, V2)); n     } n     if (z && y) { n       if (x) { n         V[i] = 4 + x; n         if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V)); n         if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V)); n         if (top / 16 == 0 && top % 4) ma[z] = min(ma[z], dodo(top + z * 16, V)); n       } else { n         if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V2)); n         if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V2)); n         if (top / 16 == 0 && top % 4) n           ma[z] = min(ma[z], dodo(top + z * 16, V2)); n       } n     } n     if (y && x) { n       if (z) { n         V[i] = z + 4; n         if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V)); n         if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V)); n         if (top / 16 == 0 && top % 4) ma[x] = min(ma[x], dodo(top + x * 16, V)); n       } else { n         if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V2)); n         if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V2)); n         if (top / 16 == 0 && top % 4) n           ma[x] = min(ma[x], dodo(top + x * 16, V2)); n       } n     } n     V[i] = pre; n   } n   int sum = 1; n   if (ma[1] >= 1e15) ma[1] = 0, sum += 1; n   if (ma[2] >= 1e15) ma[2] = 0, sum += 2; n   if (ma[3] >= 1e15) ma[3] = 0, sum += 2; n   if (sum == 6) return M[otop][VV] = 0; n   M[otop][VV] = (1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0); n   return M[otop][VV] = n              (1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0); n } n void solve() { n   int f, i, j, k, l, x, y, x2, y2, z; n   cin >> N; n   string S; n   for (i = 0; i < 64; i++) { n     x = i % 4; n     y = i / 4 % 4; n     z = i / 16; n     st[i] = (z > x) ? (x * 16 + y * 4 + z) : i; n     num[i] = (x > 0) + (y > 0) + (z > 0); n   } n   vector<int> V; n   for (i = 0; i < N; i++) { n     cin >> S; n     x = 0; n     for (y = 0; y < 3; y++) { n       if (S[y] ==  R ) x += 1 << (y * 2); n       if (S[y] ==  G ) x += 2 << (y * 2); n       if (S[y] ==  B ) x += 3 << (y * 2); n     } n     if (i < N - 1) V.push_back(st[x]); n   } n   (void)printf( %.12lf n , dodo(st[x], V)); n } n int main(int argc, char** argv) { n   string s; n   if (argc == 1) ios::sync_with_stdio(false); n   for (int i = 1; i < argc; i++) s += argv[i], s +=   n ; n   for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, r, k, tot; n int dx[] = {0, -1, 0, 1}; n int dy[] = {-1, 0, 1, 0}; n struct Cell { n   long long c, x, y; n   bool operator<(const Cell &oth) const { return c < oth.c; } n }; n class Map { n  private: n   set<long long> vis; n  n  public: n   bool isVisit(long long x, long long y) { n     return vis.count((x - 1) * m + y - 1); n   } n   void setVisit(long long x, long long y) { vis.insert((x - 1) * m + y - 1); } n } mp; n long long calc(long long x, long long y) { n   return min(r, min(n - r + 1, min(x, n - x + 1))) * n          min(r, min(m - r + 1, min(y, m - y + 1))); n } n priority_queue<Cell> pq; n void solve() { n   scanf( %lld%lld%lld%lld , &n, &m, &r, &k); n   pq.push({calc(r, r), r, r}); n   mp.setVisit(r, r); n   while (!pq.empty() && k) { n     Cell cur = pq.top(); n     pq.pop(); n     k--; n     tot += cur.c; n     for (int i = 0; i < 4; i++) { n       int nx = cur.x + dx[i], ny = cur.y + dy[i]; n       if (0 < nx && nx <= n && 0 < ny && ny <= m && !mp.isVisit(nx, ny)) { n         pq.push({calc(nx, ny), nx, ny}); n         mp.setVisit(nx, ny); n       } n     } n   } n   printf( %.10f n , 1.0 * tot / (1.0 * (n - r + 1) * (m - r + 1))); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pw(int a, int b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long rep = pw(a, b / 2), M = 1e9 + 7; n   if (b % 2 == 0) return (rep * rep) % M; n   return (((rep * rep) % M) * a) % M; n } n int main() { n   int n, k, m; n   cin >> n >> m >> k; n   if (k == 1 || k > n) { n     cout << pw(m, n); n     return 0; n   } n   if (k == n) { n     cout << pw(m, (n + 1) / 2); n     return 0; n   } n   long long answer = m; n   if (k % 2 == 1) { n     answer += m * (m - 1); n   } n   cout << answer << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j; n   string ss; n   cin >> n >> m >> ss; n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       if (ss[j] ==  B  && ss[j + 1] ==  G ) { n         ss[j] =  G ; n         ss[j + 1] =  B ; n         j++; n       } n     } n   } n   cout << ss << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 4010; n double num1[Maxn]; n int num2[Maxn]; n double dif[Maxn]; n int main() { n   int n = 0, N = 0; n   int cnt = 0, cnt1 = 0, cnt2 = 0; n   double sum = 0; n   double ans = 100000000.0; n   scanf( %d , &n); n   N = 2 * n; n   for (int i = 0; i < N; i++) { n     scanf( %lf , &num1[i]); n     num2[i] = num1[i]; n     dif[i] = (double)num1[i] - (double)num2[i]; n   } n   for (int i = 0; i < N; i++) { n     if (dif[i] != 0) { n       cnt1++; n       sum += dif[i]; n     } else { n       cnt2++; n     } n   } n   cnt = min(cnt1, n); n   for (int i = 0; i <= cnt; i++) { n     if (i + cnt2 >= n) { n       ans = min(ans, fabs(sum - i * 1.0)); n     } n   } n   printf( %.3f , ans); n   return 0; n } n


/* Author:- Neel_Patel */ n #include <bits/stdc++.h> n #define ff first n #define ss second n #define pb push_back n #define all(c) (c).begin(),(c).end() n #define vi vector<int> n #define pii pair<int,int> n #define pll pair<long long,long long>   n #define vll vector<long long> n #define priq priority_queue n #define sp fixed<<setprecision n #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) n using namespace std; n typedef long long ll; n typedef unsigned long long int llu; n const long double pi=3.14159265358979323846;         n const int inf=INT_MAX; n const ll inff=LLONG_MAX; n const long long int mod=1000000007; n  n ///////////////// debug n #define deb(...) print1(#__VA_ARGS__,__VA_ARGS__) n void print() n {cout<<endl;} n template <typename T, typename... Types>  void print(T var1, Types... var2) {cout << var1 <<  ,   ;print(var2...) ;} n template<typename ...Args> void print1(string vars, Args&&... values) {cout<<vars<<  =  ;print(values...);} n //////////////////// n  n // ostream operator overloading n template<typename T> n ostream& operator<< (ostream& out, const vector<T>& v) { n     out <<  { ;size_t last = v.size() - 1;for(size_t i = 0; i < v.size(); ++i) { out << v[i];  if (i != last)  out <<  ,  ;}out <<  } ;return out; n } n template<typename T1,typename T2>  n ostream & operator << (ostream &out,pair<T1,T2> x) { out<< ( <<x.ff<< , <<x.ss<< ) ;return out; }  n ///////////////////////// functions  n template<typename T> n T gcd(T a,T b,T& x,T& y)    // extended gcd:- x and y such that xa+yb=gcd(a,b); n { n     if(b==0) { x=1;y=0;return a;} n     T x1,y1;  T d=gcd(b,a%b,x1,y1);  x=y1;  y=x1-y1*(a/b);  return d; n } n template<typename T> n T pow(T a,T b,T M) n { n     // if M is prime # then we can take //  b=b%(M-1);  // using fermat s littel theorem  n     // b=b%(M-1); n     T res = 1; n     while(b) n     { n         if(b&1) res=(res*a)%M; n         a=(a*a)%M; n         b>>=1; n     } n     return res; n } n  n template<typename T> n T modular_inverse(T n, T mod)    { return pow(n, mod-2, mod); } n  n  n ////////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n // check value of t(#of test case -- in main function) n /////////////global variable/////////////////////// n // #define int ll n #define ld long double n const ld eps=1e-10; n ld fun(ld c,ld m,ld p,ld v) n { n     ld ans=0; n      // deb(c,m,p,v); n     if(c>eps) n     { n         ld diff=min(c,v); n         ld nm=m,nc=c-diff,np=p; n         if(m>eps) n         { n             nm+=diff/2.0; n             np+=diff/2.0; n         } n         else n         { n             np+=diff; n         } n         //  deb(nc,nm,np,v); n         ans+=c*(1.0+fun(nc,nm,np,v)); n     } n     if(m>eps) n     { n         ld diff=min(m,v); n         ld nm=m-diff,nc=c,np=p; n         if(c>eps) n         { n             nc+=diff/2.0; n             np+=diff/2.0; n         } n         else n         { n             np+=diff; n         } n         ans+=m*(1.0+fun(nc,nm,np,v)); n     } n     return ans+p; n  n } n ll ask(ll n) n { n     cout<<n<<endl; n     cin>>n; n     return n; n } n void solve() n { n     ld c,m,p,v; n     cin>>c>>m>>p>>v; n     cout<<sp(20)<<fun(c,m,p,v)<<endl; n  n      n } n // priority_queue <int, vector<int>, greater<int>> g = gq; // for small value on top n //////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n ////////////////////////////////////////////////////////////////////////////////////// n signed main()  // signed int n { n     // snippet = https://snippet-generator.app/ n     #ifndef ONLINE_JUDGE n     cout<< hi!! ; n    //  cout<< Code is running.... n ; n     freopen( input.txt ,  r , stdin); n      freopen( output.txt ,  w , stdout); n     //  chrono::time_point<std::chrono::system_clock> start, end; n     //  start = chrono::system_clock::now();  n     #endif // ONLINE_JUDGE n     fast; n      // cout<< hi n ; n     int t=1; n     cin>>t; n     while(t--)   n     { n          n         solve(); n     } n  n     /* #ifndef ONLINE_JUDGE n         end = chrono::system_clock::now(); n         chrono::duration<double> elapsed_seconds = end - start; n         cout<<elapsed_seconds.count()<<endl; n     #endif // ONLINE_JUDGE  */ n  n }


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long a[200010]; n const long long inf_int = 1e9; n pair<long long, long long> S[200010]; n long long st[400010]; n long long st_[400010]; n long long lazy[400010]; n void construct_st(int l = 1, int r = n, int i = 0) { n   if (l == r) { n     st[i] = a[l]; n     st_[i] = a[l]; n     return; n   } n   int mid = (l + r) >> 1; n   construct_st(l, mid, i * 2 + 1); n   construct_st(mid + 1, r, i * 2 + 2); n   st[i] = max(st[i * 2 + 1], st[i * 2 + 2]); n   st_[i] = min(st_[i * 2 + 1], st_[i * 2 + 2]); n } n void update(int s, int e, int value, int l = 1, int r = n, int i = 0) { n   if (lazy[i]) { n     st[i] += lazy[i]; n     st_[i] += lazy[i]; n     if (l != r) { n       lazy[i * 2 + 1] += lazy[i]; n       lazy[i * 2 + 2] += lazy[i]; n     } n     lazy[i] = 0; n   } n   if (e < l || s > r) return; n   if (s <= l && r <= e) { n     st[i] += value; n     st_[i] += value; n     if (l != r) { n       lazy[i * 2 + 1] += value; n       lazy[i * 2 + 2] += value; n     } n     return; n   } n   int mid = (l + r) >> 1; n   update(s, e, value, l, mid, i * 2 + 1); n   update(s, e, value, mid + 1, r, i * 2 + 2); n   st[i] = max(st[i * 2 + 1], st[i * 2 + 2]); n   st_[i] = min(st_[i * 2 + 1], st_[i * 2 + 2]); n } n int rmq(int s, int e, int l = 1, int r = n, int i = 0) { n   if (lazy[i]) { n     st[i] += lazy[i]; n     st_[i] += lazy[i]; n     if (l != r) { n       lazy[i * 2 + 1] += lazy[i]; n       lazy[i * 2 + 2] += lazy[i]; n     } n     lazy[i] = 0; n   } n   if (e < l || s > r) return inf_int; n   if (s <= l && r <= e) return st_[i]; n   int mid = (l + r) >> 1; n   long long L = rmq(s, e, l, mid, i * 2 + 1); n   long long R = rmq(s, e, mid + 1, r, i * 2 + 2); n   return min(L, R); n } n int rMq(int s, int e, int l = 1, int r = n, int i = 0) { n   if (lazy[i]) { n     st[i] += lazy[i]; n     st_[i] += lazy[i]; n     if (l != r) { n       lazy[i * 2 + 1] += lazy[i]; n       lazy[i * 2 + 2] += lazy[i]; n     } n     lazy[i] = 0; n   } n   if (e < l || s > r) return -inf_int; n   if (s <= l && r <= e) return st[i]; n   int mid = (l + r) >> 1; n   long long L = rMq(s, e, l, mid, i * 2 + 1); n   long long R = rMq(s, e, mid + 1, r, i * 2 + 2); n   return max(L, R); n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> S[i].first; n     cin >> S[i].second; n   } n   construct_st(); n   long long maxi = rMq(1, n); n   long long mini = rmq(1, n); n   long long answer = maxi - mini; n   long long answer_index = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int L = S[j].first; n       int R = S[j].second; n       if (i < L || i > R) { n         update(L, R, -1); n       } n     } n     maxi = rMq(1, n); n     mini = rmq(1, n); n     long long possible_answer = maxi - mini; n     if (possible_answer > answer) { n       answer = possible_answer; n       answer_index = i; n     } n     for (int j = 1; j <= m; j++) { n       int L = S[j].first; n       int R = S[j].second; n       if (i < L || i > R) { n         update(L, R, 1); n       } n     } n   } n   cout << answer <<   n ; n   if (answer_index != -1) { n     vector<int> changes; n     for (int j = 1; j <= m; j++) { n       int L = S[j].first; n       int R = S[j].second; n       if (answer_index < L || answer_index > R) { n         changes.push_back(j); n       } n     } n     cout << changes.size() <<   n ; n     for (auto t : changes) { n       cout << t <<    ; n     } n     cout <<   n ; n   } else { n     cout << 0 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n double res, a, b; n int main() { n   int n, k; n   cin >> n >> k; n   vector<double> x(n), y(n); n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     if (i) { n       a = x[i] - x[i - 1]; n       b = y[i] - y[i - 1]; n       res += sqrt((a * a) + (b * b)); n     } n   } n   res /= 50; n   cout << setprecision(10) << res * k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int mass[n]; n   for (int i = 0; i < n; i++) cin >> mass[i]; n   list<int> lis; n   int ans = 0; n   for (int i = 0; i < m; i++) { n     int temp; n     cin >> temp; n     temp--; n     if (lis.empty()) n       lis.push_front(temp); n     else { n       int sum = 0; n       list<int>::iterator i; n       for (i = lis.begin(); i != lis.end(); i++) { n         if (*i == temp) n           break; n         else n           sum += mass[*i]; n       } n       if (i != lis.end()) lis.erase(i); n       lis.push_front(temp); n       ans += sum; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int sst(string g) { n   int f; n   stringstream ss; n   ss << g; n   ss >> f; n   return f; n } n int main() { n   string s, s1, s2, s3; n   cin >> s; n   int max = -1, h = 0; n   int t = s.size(), x, y, z; n   if (t < 3) { n     cout <<  -1  << endl; n     return 0; n   } n   for (int i = 0; i < t - 1; i++) { n     for (int j = i + 1; j < t - 1; j++) { n       s1 = s.substr(0, i + 1); n       s2 = s.substr(i + 1, j - i); n       s3 = s.substr(j + 1, t - j - 1); n       x = sst(s1); n       y = sst(s2); n       z = sst(s3); n       if (s1.size() == 0 || s2.size() == 0 || s3.size() == 0) continue; n       if (s1[0] ==  0  && s1.size() > 1) continue; n       if (s2[0] ==  0  && s2.size() > 1) continue; n       if (s3[0] ==  0  && s3.size() > 1) continue; n       if (x <= 1000000 && y <= 1000000 && z <= 1000000 && x + y + z > max) { n         max = x + y + z; n         h = 1; n       } n     } n   } n   if (h = 1) n     cout << max; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string binary(long long n) { n   string result; n   do result +=  0  + (n & 1); n   while (n >>= 1); n   reverse(result.begin(), result.end()); n   return result; n } n int countSubstr(const string& str, const string& sub) { n   if (sub.length() == 0) return 0; n   int count = 0; n   for (size_t offset = str.find(sub); offset != string::npos; n        offset = str.find(sub, offset + sub.length())) { n     ++count; n   } n   return count; n } n vector<bool> primes; n vector<int> primesCnt; n void seive(int a, int b) { n   primes = vector<bool>(b + 1, true); n   primesCnt = vector<int>(b, true); n   primes[0] = primes[1] = false; n   for (int i = 2; i * i <= b; i++) { n     for (int j = i; j * i <= b; j++) { n       primes[i * j] = false; n     } n   } n   primesCnt[0] = 0; n   for (decltype(b + 1)(i) = (1); (i) < (b + 1); (i)++) { n     primesCnt[i] = primesCnt[i - 1] + primes[i]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int a, b, k, ans = -1; n   cin >> a >> b >> k; n   seive(a, b); n   if (primesCnt[b] - primesCnt[a - 1] < k) { n     cout << ans; n     return 0; n   } n   int left = 0, right = b - a + 1, med; n   while (right > left + 1) { n     med = (right + left) / 2; n     bool can = true; n     int j = a + med - 1; n     while (j <= b) { n       if (primesCnt[j] - primesCnt[j - med] < k) { n         can = false; n         break; n       } n       j++; n     } n     if (can) n       right = med; n     else n       left = med; n   } n   cout << right; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(const pair<int, int>& i, const pair<int, int>& j) { n   return i.first < j.first; n } n int ncr(int n, int k) { n   if (n < k) return 0; n   int C[n + 1][k + 1]; n   int i, j; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= min(i, k); j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; n     } n   } n   return C[n][k]; n } n long long modpowIter(long long a, long long b, long long c) { n   long long ans = 1; n   while (b != 0) { n     if (b % 2 == 1) ans = (ans * a) % LLONG_MAX; n     a = (a * a) % LLONG_MAX; n     b /= 2; n   } n   return ans; n } n string intobin(int n) { n   string s =   ; n   if (n == 0) s =  0 ; n   while (n) { n     if (n % 2) n       s =  1  + s; n     else n       s =  0  + s; n     n /= 2; n   } n   return s; n } n int bintoin(string s) { n   long long n = 0; n   vector<long long> v; n   v.push_back(1); n   for (int i = 0; i < 400; i++) { n     v.push_back((v[v.size() - 1] * 2) % 1000003); n   } n   for (int i = s.length() - 1; i > -1; i--) { n     n = (n + (s[i] -  0 ) * v[s.length() - i - 1]) % 1000003; n   } n   return n; n } n long long nc2(long long n, long long k) { n   if (n < k) return 0; n   return (n * (n - 1)) / 2; n } n bool prime[1000001]; n void SieveOfEratosthenes(int n) { n   memset(prime, true, sizeof(prime)); n   for (int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n int main() { n   int n; n   cin >> n; n   int m; n   cin >> m; n   int arr[n]; n   double b[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i] >> b[i]; n   } n   int dp[n]; n   dp[0] = 1; n   for (int i = 1; i <= n - 1; i++) { n     dp[i] = 1; n     for (int j = 0; j < i; j++) { n       if (arr[i] >= arr[j] && dp[i] < dp[j] + 1) dp[i] = dp[j] + 1; n     } n   } n   cout << n - (*max_element(dp, dp + n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2000 + 20; n int a[maxn]; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   int ans = 0; n   for (int i = n - 1; i >= 0; i -= k) { n     ans += 2 * (a[i] - 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2000; n int n, k; n int a, b, c, d; n int num[MAXN], num_cnt = 0; n int rank[MAXN]; n set<int> s; n vector<int> v; n int main() { n   cin >> n >> k; n   cin >> a >> b >> c >> d; n   if (k <= n) { n     cout << -1 << endl; n   } else { n     if (n >= 5) { n       for (int i = 1; i <= n; ++i) { n         if (i != a && i != b && i != c && i != d) { n           s.insert(i); n         } n       } n       v.push_back(a); n       v.push_back(c); n       while (!s.empty()) { n         v.push_back(*s.begin()); n         s.erase(s.begin()); n       } n       v.push_back(d); n       v.push_back(b); n       for (int i = 0; i < v.size(); ++i) { n         cout << v[i] <<    ; n       } n       cout << endl; n       cout << c <<     << a <<    ; n       for (int i = (int)v.size() - 3; i >= 2; --i) { n         cout << v[i] <<    ; n       } n       cout << b <<     << d << endl; n     } else if (n == 4) { n       cout << -1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[1234]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   int mx = 0; n   for (int i = 0; i < n; i++) n     if (a[i] > mx) mx = a[i]; n   for (int u = 1; u <= mx; u++) { n     for (int i = 0; i < n; i++) { n       if (a[i] >= u) putchar( P ); n       if (i < n - 1) n         putchar( R ); n       else { n         for (int j = 0; j < n - 1; j++) putchar( L ); n       } n     } n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char mp[444][444]; n struct node { n   int num[8]; n } np[444][444]; n int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n long long ans; n bool in(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } n void cal(int x, int y) { n   for (int i = 0; i < 8; i++) { n     int xx = x; n     int yy = y; n     while (in(xx, yy) && mp[xx][yy] ==  0 ) { n       np[x][y].num[i]++; n       xx += dx[i]; n       yy += dy[i]; n     } n     np[x][y].num[i]--; n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (mp[i][j] ==  0 ) cal(i, j); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (mp[i][j] ==  0 ) { n         long long cur = 0LL; n         node &now = np[i][j]; n         for (int k = 0; k < 8; k++) { n           if (k % 2 == 0) { n             for (int l = 1; l <= now.num[k]; l++) { n               node &then = np[i + l * dx[k]][j + l * dy[k]]; n               if (then.num[(k + 2) % 8] >= l && now.num[(k + 1) % 8] / 2 >= l) n                 cur++; n               if (then.num[(k + 3) % 8] >= l && now.num[(k + 1) % 8] >= l) n                 cur++; n               if (then.num[(k + 3) % 8] / 2 >= l && now.num[(k + 2) % 8] >= l) n                 cur++; n             } n           } else { n             for (int l = 1; l <= now.num[k]; l++) { n               node &then = np[i + l * dx[k]][j + l * dy[k]]; n               if (l % 2 == 0 && then.num[(k + 3) % 8] >= l / 2 && n                   now.num[(k + 1) % 8] >= l / 2) n                 cur++; n               if (then.num[(k + 2) % 8] >= l && now.num[(k + 1) % 8] >= l) n                 cur++; n               if (then.num[(k + 3) % 8] >= l && now.num[(k + 2) % 8] >= l) n                 cur++; n             } n           } n         } n         ans += cur; n       } n     } n   } n   printf( %I64d n , ans / 3); n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 2e5 + 5; n int x[MXN]; n int y[MXN]; n int d[MXN]; n int xr[MXN]; n int par[MXN]; n int siz[MXN]; n int sol[MXN]; n int type[MXN]; n int basis[30]; n stack<pair<int *, int>> stk; n vector<array<int, 3>> st[2 << 18]; n void change(int &ref, int val) { n   stk.push({&ref, ref}); n   ref = val; n } n array<int, 2> get(int x) { n   int len = 0; n   while (par[x]) { n     len ^= xr[x]; n     x = par[x]; n   } n   return {x, len}; n } n void join(int x, int y, int d) { n   auto [px, xrx] = get(x); n   auto [py, xry] = get(y); n   if (px == py) { n     int cycle = xrx ^ d ^ xry; n     for (int i = 29; i >= 0; --i) { n       if (cycle >> i & 1) { n         if (basis[i]) { n           cycle ^= basis[i]; n         } else { n           change(basis[i], cycle); n           break; n         } n       } n     } n   } else { n     if (siz[px] < siz[py]) { n       swap(px, py); n     } n     change(siz[px], siz[px] + siz[py]); n     change(xr[py], xrx ^ d ^ xry); n     change(par[py], px); n   } n } n void dfs(int lo, int hi, int nd = 0) { n   int sz = stk.size(); n   for (auto [x, y, d] : st[nd]) { n     join(x, y, d); n   } n   if (lo + 1 == hi) { n     sol[lo] ^= get(x[lo])[1]; n     sol[lo] ^= get(y[lo])[1]; n     for (int i = 29; i >= 0; --i) { n       sol[lo] = min(sol[lo], sol[lo] ^ basis[i]); n     } n   } else { n     int mid = (lo + hi) / 2; n     dfs(lo, mid, 2 * nd + 1); n     dfs(mid, hi, 2 * nd + 2); n   } n   while (sz < (int)stk.size()) { n     auto [ptr, val] = stk.top(); n     *ptr = val; n     stk.pop(); n   } n } n void add(int l, int r, array<int, 3> e, int lo, int hi, int nd = 0) { n   if (l <= lo && hi <= r) return st[nd].push_back(e); n   int mid = (lo + hi) / 2; n   if (l < mid) add(l, r, e, lo, mid, 2 * nd + 1); n   if (mid < r) add(l, r, e, mid, hi, 2 * nd + 2); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   map<array<int, 2>, array<int, 2>> mp; n   for (int i = 0; i < m; ++i) { n     int x, y, d; n     cin >> x >> y >> d; n     mp[{x, y}] = {0, d}; n   } n   int q; n   cin >> q; n   int sz = 0; n   for (int i = 0; i < q; ++i) { n     cin >> type[i] >> x[i] >> y[i]; n     if (type[i] == 1) cin >> d[i]; n     sz += type[i] == 3; n   } n   int cq = 0; n   for (int i = 0; i < q; ++i) { n     if (type[i] == 1) { n       mp[{x[i], y[i]}] = {cq, d[i]}; n     } else if (type[i] == 2) { n       auto [pq, d] = mp[{x[i], y[i]}]; n       mp.erase({x[i], y[i]}); n       if (pq < cq) add(pq, cq, {x[i], y[i], d}, 0, sz); n     } else { n       x[cq] = x[i]; n       y[cq] = y[i]; n       cq++; n     } n   } n   for (auto [a, b] : mp) { n     if (b[0] < sz) add(b[0], sz, {a[0], a[1], b[1]}, 0, sz); n   } n   for (int i = 1; i <= n; ++i) { n     siz[i] = 1; n   } n   dfs(0, sz); n   for (int i = 0; i < sz; ++i) { n     cout << sol[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int ans = 0; n   while (n--) { n     string t; n     cin >> t; n     int c = k; n     for (char x : t) n       if (x ==  4  || x ==  7 ) c--; n     if (c >= 0) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, neg, zero; n   cin >> x; n   int arr[x]; n   for (int i = 0; i < x; i++) cin >> arr[i]; n   sort(arr, arr + x); n   if (arr[x - 1] <= 0) { n     cout <<  1  n          <<     << arr[0] << endl; n     cout <<  2  n          <<     << arr[1] <<     << arr[2] << endl; n     for (int i = 3; i < x; i++) { n       if (i == 3) n         cout << x - i <<     << arr[3]; n       else n         cout <<     << arr[i]; n     } n   } else { n     for (int i = 0; i < x; i++) { n       if (arr[i] < 0) n         neg = i; n       else if (arr[i] == 0) n         zero = i; n     } n     cout <<  1   << arr[0] << endl; n     cout << x - zero - 1 <<    ; n     for (int i = zero + 1; i < x; i++) cout << arr[i] <<    ; n     cout << endl; n     cout << zero; n     for (int i = 1; i <= zero; i++) cout <<     << arr[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const char c[3][4] = { RGB ,  GBR ,  BRG }; n int sum[3][N]; n char s[N]; n int main() { n   int n, k, T; n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d , &n, &k); n     sum[0][0] = sum[1][0] = sum[2][0] = 0; n     scanf( %s , s); n     if (k == 1) { n       printf( 0 n ); n       continue; n     } n     for (int i = 0; i < 3; i++) { n       for (int j = 0; j < n; j++) { n         if (s[j] != c[i][j % 3]) { n           sum[i][j + 1] = sum[i][j] + 1; n         } else { n           sum[i][j + 1] = sum[i][j]; n         } n       } n     } n     int ans = N; n     for (int p = 0; p < 3; p++) { n       for (int i = 1; i + k - 1 <= n; i++) { n         int j = i + k - 1; n         ans = min(ans, sum[p][j] - sum[p][i - 1]); n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n char s[N]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, k; n     scanf( %d%d , &n, &k); n     scanf( %s , s); n     getchar(); n     vector<int> cnt(27, 0); n     for (int i = 0; i < n; ++i) ++cnt[s[i] -  a ]; n     for (int len = n; len >= 1; --len) { n       vector<int> circ, c_cnt, used(len, 0); n       for (int i = 0; i < len; ++i) { n         if (used[i]) continue; n         used[i] = 1; n         int j = (i + k) % len; n         circ.push_back(1); n         while (!used[j]) { n           used[j] = 1; n           circ.back()++; n           j = (j + k) % len; n         } n       } n       c_cnt = cnt; n       sort(circ.begin(), circ.end()); n       sort(c_cnt.begin(), c_cnt.end()); n       int ok = 1; n       while (!circ.empty()) { n         if (circ.back() > c_cnt.back()) { n           ok = 0; n           break; n         } else { n           c_cnt.back() -= circ.back(); n           circ.pop_back(); n           sort(c_cnt.begin(), c_cnt.end()); n         } n       } n       if (ok) { n         printf( %d n , len); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 90000000000000000; n inline bool checkBit(long long n, int i) { return n & (1LL << i); } n inline long long setBit(long long n, int i) { n   return n | (1LL << i); n   ; n } n inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); } n int dx[] = {0, 0, +1, -1}; n int dy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline void normal(long long &a) { n   a %= 1000000007; n   (a < 0) && (a += 1000000007); n } n inline long long modMul(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a * b) % 1000000007; n } n inline long long modAdd(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a + b) % 1000000007; n } n inline long long modSub(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n const int MX = 101000; n int tree[21][4 * MX], lazy[21][4 * MX], a[MX]; n long long arr[21]; n void build(int node, int l, int r, int val) { n   if (l == r) { n     if (checkBit(a[l], val)) tree[val][node] = 1; n     return; n   } n   int mid = (l + r) / 2; n   build(node * 2, l, mid, val); n   build(node * 2 + 1, mid + 1, r, val); n   tree[val][node] = tree[val][node * 2] + tree[val][node * 2 + 1]; n   ; n } n void update(int node, int l, int r, int b, int e, int val) { n   if (lazy[val][node]) { n     tree[val][node] = (r - l + 1) - tree[val][node]; n     if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1; n     lazy[val][node] = 0; n   } n   if (l > e || r < b) return; n   if (l >= b && r <= e) { n     tree[val][node] = (r - l + 1) - tree[val][node]; n     if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1; n     return; n   } n   int mid = (l + r) / 2; n   update(node * 2, l, mid, b, e, val); n   update(node * 2 + 1, mid + 1, r, b, e, val); n   tree[val][node] = tree[val][node * 2] + tree[val][node * 2 + 1]; n } n int query(int node, int l, int r, int b, int e, int val) { n   if (lazy[val][node]) { n     tree[val][node] = (r - l + 1) - tree[val][node]; n     if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1; n     lazy[val][node] = 0; n   } n   if (l > e || r < b) return 0; n   if (l >= b && r <= e) return tree[val][node]; n   int mid = (l + r) / 2; n   return query(node * 2, l, mid, b, e, val) + n          query(node * 2 + 1, mid + 1, r, b, e, val); n } n int main() { n   for (int i = 1, j = 0; j < 21; ++j, i *= 2) arr[j] = i; n   int n; n   scanf( %d , &n); n   ; n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < 21; ++i) build(1, 0, n - 1, i); n   int m; n   scanf( %d , &m); n   ; n   while (m--) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int l, r; n       scanf( %d%d , &l, &r); n       long long ans = 0LL; n       for (int i = 0; i < 21; ++i) n         ans += arr[i] * query(1, 0, n - 1, l - 1, r - 1, i); n       printf( %lld n , ans); n     } else { n       int l, r, x; n       scanf( %d%d%d , &l, &r, &x); n       for (int i = 0; i < 21; ++i) n         if (checkBit(x, i)) update(1, 0, n - 1, l - 1, r - 1, i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, x, y, res; n vector<int> g[200200], o[200200]; n bool u[3][200200], w[200200], ok = true; n char r[200200]; n void dfs(int i, int z) { n   u[z][i] = true; n   w[i] = true; n   for (int j = 0; j < g[i].size(); j++) { n     int k = g[i][j]; n     if (w[k]) ok = false; n     if (!u[z][k]) dfs(k, z); n   } n   w[i] = false; n } n void ofs(int i, int z) { n   u[z][i] = true; n   for (int j = 0; j < o[i].size(); j++) { n     int k = o[i][j]; n     if (!u[z][k]) ofs(k, z); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (i = 0; i < m; i++) { n     scanf( %d%d , &x, &y); n     g[x].push_back(y); n     o[y].push_back(x); n   } n   for (i = 1; ok && i <= n; i++) n     if (!u[0][i]) dfs(i, 0); n   if (!ok) { n     puts( -1 ); n     return 0; n   } n   memset(u, 0, sizeof(u)); n   for (i = 1; i <= n; i++) n     if (!u[0][i] && !u[1][i] && !u[2][i]) { n       dfs(i, 0); n       ofs(i, 0); n       r[i - 1] =  A ; n       res++; n     } else { n       r[i - 1] =  E ; n       if (!u[1][i]) dfs(i, 1); n       if (!u[2][i]) ofs(i, 2); n     } n   printf( %d n , res); n   puts(r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, lim = 1e7 + 10, key = 1010; n int v[lim], r[lim], d[lim]; n int main() { n   int n, m, q; n   scanf( %d%d%d , &n, &m, &q); n   for (long long i = 1, _b = (n); i <= _b; i++) n     for (long long j = 1, _b = (m); j <= _b; j++) scanf( %d , v + key * i + j); n   for (long long i = 0, _b = (n); i <= _b; i++) n     for (long long j = 0, _b = (m); j <= _b; j++) { n       r[key * i + j] = key * i + (j + 1); n       d[key * i + j] = key * (i + 1) + j; n     } n   int _a, _b, _c, _d, h, w; n   int x, y, x0, y0; n   for (long long i = 0, _n = (q); i < _n; i++) { n     scanf( %d%d%d%d%d%d , &_a, &_b, &_c, &_d, &h, &w); n     x0 = 0; n     while (--_a) x0 = d[x0]; n     while (--_b) x0 = r[x0]; n     y0 = 0; n     while (--_c) y0 = d[y0]; n     while (--_d) y0 = r[y0]; n     x = x0, y = y0; n     for (long long j = 0, _n = (h); j < _n; j++) n       x = d[x], y = d[y], swap(r[x], r[y]); n     for (long long j = 0, _n = (w); j < _n; j++) n       x = r[x], y = r[y], swap(d[x], d[y]); n     x = x0, y = y0; n     for (long long j = 0, _n = (w); j < _n; j++) n       x = r[x], y = r[y], swap(d[x], d[y]); n     for (long long j = 0, _n = (h); j < _n; j++) n       x = d[x], y = d[y], swap(r[x], r[y]); n   } n   x0 = 0; n   for (long long i = 0, _n = (n); i < _n; i++) { n     x0 = d[x0]; n     x = x0; n     for (long long j = 0, _n = (m); j < _n; j++) x = r[x], printf( %d  , v[x]); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int a, b, c, d, i, j, n, m, k, ans; n char mas2[2001][2001]; n bitset<2000> mas[2001], ver[2001]; n int si[2001]; n int main() { n   gets(mas2[0]); n   sscanf(mas2[0],  %d , &n); n   for (int _n((n)-1), i(0); i <= _n; i++) gets(mas2[i]); n   for (int _n((n)-1), i(0); i <= _n; i++) n     for (int _n(n - 1), j(i); j <= _n; j++) n       if (mas2[i][j] ==  1 ) { n         mas[i].set(j); n       } n   for (int _n((n)-1), i(0); i <= _n; i++) { n     for (int j = n - 1; j > i; --j) { n       if (mas[i].test(j) ^ ver[j].test(i)) { n         ++ans; n         si[i] ^= 1; n         si[j] ^= 1; n         mas[i].flip(); n         ver[j].flip(); n       } n     } n   } n   for (int _n((n)-1), i(0); i <= _n; i++) mas[i].reset(), ver[i].reset(); n   for (int _n((n)-1), i(0); i <= _n; i++) n     for (int _n(n - 1), j(i); j <= _n; j++) n       if (mas2[j][i] ==  1 ) { n         mas[i].set(j); n       } n   for (int _n((n)-1), i(0); i <= _n; i++) { n     for (int j = n - 1; j > i; --j) { n       if (mas[i].test(j) ^ ver[j].test(i)) { n         ++ans; n         si[i] ^= 1; n         si[j] ^= 1; n         mas[i].flip(); n         ver[j].flip(); n       } n     } n     if (si[i]) mas2[i][i] ^= 1; n     if (mas2[i][i] ==  1 ) { n       ++ans; n       mas[i].flip(i); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n const int N = 200200; n using namespace std; n int n, k, s, t; n int c[N]; n int v[N]; n vector<int> g; n bool f(int x) { n   long long cnt = s + s; n   for (int i = 0; i + 1 < g.size(); i++) { n     if (g[i + 1] - g[i] > x) return false; n     int l = x - (g[i + 1] - g[i]); n     cnt -= min(g[i + 1] - g[i], l); n   } n   return cnt <= t; n } n int main() { n   ios_base::sync_with_stdio(0); n   scanf( %d%d%d%d , &n, &k, &s, &t); n   for (int i = 1; i <= n; i++) scanf( %d%d , &c[i], &v[i]); n   g.push_back(0); n   g.push_back(s); n   for (int i = 1; i <= k; i++) { n     int x; n     scanf( %d , &x); n     g.push_back(x); n   } n   sort(g.begin(), g.end()); n   int l = 0, r = 1e9 + 1; n   while (l < r) { n     int m = (l + r) / 2; n     if (f(m)) n       r = m; n     else n       l = m + 1; n   } n   int ans = 1e9 + 1; n   for (int i = 1; i <= n; i++) n     if (v[i] >= l) ans = min(ans, c[i]); n   if (ans == 1e9 + 1) ans = -1; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n, t, k, ret; n int a[N]; n int sum[N]; n int main() { n   scanf( %d%d%d , &n, &t, &k); n   int all = 0; n   sum[0] = 1; n   a[0] = 1; n   for (int i = 1; i <= t; i++) { n     scanf( %d , &a[i]); n     sum[i] = sum[i - 1] + a[i]; n     if (a[i] < a[i - 1]) ret += a[i - 1] - a[i]; n   } n   if (ret + a[t] > k || n - t < k) { n     printf( -1 n ); n     return 0; n   } n   printf( %d n , n); n   int fa = 1, now = 2; n   int need = n - t - k; n   for (int i = 1; i <= t; i++) { n     while (now <= sum[i]) { n       printf( %d %d n , fa, now); n       if (fa != sum[i - 1] && now != sum[i] && need > 0) { n         fa++; n         need--; n       } n       now++; n     } n     fa = sum[i - 1] + 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, m, r0; n   cin >> a >> b >> m >> r0; n   int step = 0; n   map<int, int> smap; n   smap[r0] = 0; n   while (true) { n     r0 = r0 * a + b; n     r0 %= m; n     step++; n     if (smap.find(r0) != smap.end()) { n       cout << step - smap[r0]; n       break; n     } n     smap[r0] = step; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int maxn = 100000 + 10; n struct Point { n   double x, y; n   Point() {} n   Point(double x, double y) : x(x), y(y) {} n } inter; n struct Line { n   int a, b, c, id; n   Line() {} n   Line(int a, int b, int c, int id) : a(a), b(b), c(c), id(id) {} n } e[maxn]; n struct Node { n   int x, y; n   Node() {} n   Node(int x, int y) : x(x), y(y) {} n } ans[10]; n int n, k, cnt, tot, pos; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline int dcmp(double x) { n   if (fabs(x) < eps) return 0; n   return x < 0 ? -1 : 1; n } n bool judge(int l, int r) { n   if (dcmp((double)e[l].a * e[r].b - (double)e[r].a * e[l].b) == 0) return 0; n   inter = Point(((double)e[l].b * e[r].c - (double)e[l].c * e[r].b) / n                     ((double)e[l].a * e[r].b - (double)e[r].a * e[l].b), n                 ((double)e[l].a * e[r].c - (double)e[l].c * e[r].a) / n                     ((double)e[l].b * e[r].a - (double)e[l].a * e[r].b)); n   return 1; n } n int main() { n   n = read(), k = read(); n   for (int i = 1, a, b, c; i <= n; i++) { n     a = read(), b = read(), c = read(); n     e[i] = Line(a, b, c, i); n   } n   cnt = n; n   bool exis = 1; n   while (cnt) { n     if (k >= cnt) { n       ans[++tot] = Node(e[cnt].id, -1); n       cnt--; n       continue; n     } n     for (pos = 1; pos <= 100; pos++) { n       int a = rand() % cnt + 1, b = rand() % cnt + 1, sz = 0; n       if (!judge(a, b)) continue; n       for (int i = 1; i <= cnt; i++) n         if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y + n                  e[i].c) == 0) n           sz++; n       if (sz * k >= cnt) { n         ans[++tot] = Node(e[a].id, e[b].id); n         break; n       } n     } n     if (pos > 100) { n       exis = 0; n       break; n     } n     for (int i = cnt; i >= 1; i--) n       if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y + n                (double)e[i].c) == 0) { n         swap(e[i], e[cnt]); n         cnt--; n       } n     k--; n   } n   if (!exis) n     puts( NO ); n   else { n     puts( YES ); n     printf( %d n , tot); n     for (int i = 1; i <= tot; i++) printf( %d %d n , ans[i].x, ans[i].y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.14159265389793238462643383279502884197169; n const long long MOD = 1e9 + 7; n const int MAXN = 1e6 + 5; n const int oo = 1e9; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t, p; n   cin >> t; n   while (t--) { n     cin >> p; n     cout << 2 <<     << p - 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = 2 * acos(0.0); n long long infinity = std::numeric_limits<long long>::max(); n long long binary_search(long long dp[], long long n, long long p) { n   long long l, r, mid; n   l = 0; n   r = n - 1; n   sort(dp, dp + n); n   while (l <= r && l >= 0 && l <= n - 1 && r >= 0 && r <= n - 1) { n     mid = (l + r) / 2; n     if (dp[mid] >= p) { n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   return l; n } n struct order { n   long long l, r; n }; n bool compare(order o1, order o2) { n   if (o1.l == o2.l) n     return (o1.r < o2.r); n   else n     return (o1.l < o2.l); n } n bool check(order o1, order o2) { return (o1.r < o2.l); } n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long r, c, k, num_R = 0, i, j; n     cin >> r >> c >> k; n     char A[r][c]; n     for (i = 0; i < r; ++i) n       for (j = 0; j < c; ++j) { n         cin >> A[i][j]; n         num_R += (A[i][j] ==  R ); n       } n     long long x = ceil((double)num_R / (double)k), a, b, c1 = 0, x_count = 0, n               y_count = 0; n     char req = 48; n     b = x * k - num_R; n     a = k - b; n     long long a1 = a, b1 = b, l = 0, f = 0; n     for (i = 0; i < r; ++i) { n       if (i % 2 == 0) n         j = 0; n       else n         j = c - 1; n       while ((i % 2 == 0 && j < c) || (i % 2 == 1 && j >= 0)) { n         if (A[i][j] !=  R ) n           A[i][j] = req; n         else { n           A[i][j] = req; n           ++c1; n           if (c1 == x * a) { n             c1 = 0; n             x = x - 1; n             a = b; n             if (l == 1 || a == 0) { n               f = 1; n               break; n             } n             if (a != 0) ++req; n             ++l; n           } else if (c1 % x == 0) { n             ++req; n           } n         } n         if (i % 2 == 0) n           ++j; n         else n           --j; n         if (req == 58) n           req = 65; n         else if (req == 91) n           req = 97; n       } n       if (f == 1) { n         break; n       } n     } n     for (i = 0; i < r; ++i) { n       for (j = 0; j < c; ++j) { n         if (A[i][j] !=  . ) n           cout << A[i][j]; n         else n           cout << req; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double x, y, a, b, t; n   while (cin >> a >> b) { n     int n; n     cin >> n; n     double p = 1e18; n     for (int i = 0; i < n; i++) { n       cin >> x >> y >> t; n       p = min(p, hypot((x - a), (y - b)) / t); n     } n     printf( %.20lf , p); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long a, b[100100], p[100100]; n bool check(int num) { n   long long gongfei = 0LL; n   for (int i = n - num + 1; i <= n; i++) { n     int j = i - (n - num); n     if (b[i] < p[j]) { n       gongfei += p[j] - b[i]; n     } n   } n   if (gongfei > a) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m >> a; n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> p[i]; n   } n   sort(b + 1, b + n + 1); n   sort(p + 1, p + m + 1); n   int le = -1, ri = min(n, m) + 1; n   int res = 0; n   while (le + 1 < ri) { n     int mi = (le + ri) / 2; n     if (check(mi)) { n       le = mi; n     } else { n       ri = mi; n     } n   } n   long long tot = 0; n   for (int i = 1; i <= le; i++) tot += p[i]; n   cout << le <<     << max(tot - a, 0LL) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10, P = 1e9 + 7; n int qpow(int a, int n) { n   int ans = 1; n   for (; n; a = a * (int64_t)a % P, n >>= 1) n     if (n & 1) ans = ans * (int64_t)a % P; n   return ans; n } n int fac[N], ifac[N], f[N]; n int C(int n, int m) { n   if (m > n) return 0; n   return fac[n] * (int64_t)ifac[m] % P * ifac[n - m] % P; n } n int main() { n   fac[0] = 1; n   for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * (int64_t)i % P; n   ifac[N - 1] = qpow(fac[N - 1], P - 2); n   for (int i = N - 2; i >= 0; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % P; n   int n, m, k; n   cin >> n >> m >> k; n   if (m == 1) return cout << qpow(k, n) << endl, 0; n   for (int i = 1; i <= min(n, k); ++i) { n     for (int j = i; j >= 0; --j) { n       int ret = (int64_t)C(i, j) * qpow(j, n) % P; n       if (j % 2 == i % 2) n         f[i] = (f[i] + ret) % P; n       else n         f[i] = (f[i] - ret) % P; n     } n   } n   int ans = 0; n   if (m == 2) { n     for (int i = 1; i <= n; ++i) { n       ans = (ans + C(k, i) * (int64_t)C(k, i) % P * f[i] % P * f[i]) % P; n     } n   } else { n     for (int i = 1; i <= min(n, k); ++i) { n       for (int j = 1; j <= i; ++j) { n         ans = (ans + C(k, i) * (int64_t)C(i, j) % P * C(k - i, i - j) % P * n                          f[i] % P * f[i] % P * qpow(j, n * (m - 2))) % n               P; n       } n     } n   } n   if (ans < 0) ans += P; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, m, x, y; n     cin >> n >> m >> x >> y; n     string s[n]; n     for (int a = 0; a < n; a++) cin >> s[a]; n     if (y > (2 * x)) y = 2 * x; n     long long int xx, yy, zz, ans = 0; n     for (int a = 0; a < n; a++) { n       for (int b = 0; b < m; b++) { n         if (s[a][b] ==  . ) { n           if (b == m - 1) n             ans += x; n           else if (s[a][b + 1] ==  . ) { n             ans += y; n             b++; n           } else n             ans += x; n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long x[1005], y[1005]; n set<pair<pair<long long, long long>, pair<long long, long long> > > S; n map<pair<long long, long long>, long long> mp; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i >= j) continue; n       int s = i, t = j; n       pair<pair<long long, long long>, pair<long long, long long> > l; n       if (x[s] == x[t]) { n         l = make_pair(make_pair(1, 0), make_pair(x[s], 1)); n       } else { n         if (x[s] > x[t]) swap(s, t); n         long long dx = x[t] - x[s], dy = y[t] - y[s]; n         long long d = gcd(abs(dx), abs(dy)); n         dx /= d, dy /= d; n         l.first = make_pair(dy, dx); n         long long bunsi = (dx * y[s] - dy * x[s]), bunbo = dx; n         d = gcd(abs(bunsi), abs(bunbo)); n         bunsi /= d, bunbo /= d; n         l.second = make_pair(bunsi, bunbo); n       } n       S.insert(l); n     } n   } n   long long lnum = S.size(); n   for (auto it = S.begin(); it != S.end(); it++) mp[it->first]++; n   long long ans = 0; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     ans += it->second * (it->second - 1) / 2; n   } n   cout << lnum * (lnum - 1) / 2 - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const long double ACOSPI = (acosl(-1.0)); n using namespace std; n int main() { n   int n = 0; n   int i = 0; n   int x = 0; n   long long ans = 0; n   map<int, long long> m; n   int a = 0; n   cin >> n >> x; n   for (i = 0; i < n; i++) { n     cin >> a; n     ans += m[a]; n     m[x ^ a]++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } n int toInt(char xx) { return xx -  0 ; } n char toChar(int xx) { return xx +  0 ; } n int isDigit(char xx) { return ( 0  <= xx && xx <=  9 ); } n bool isCharacter(char xx) { n   return (( a  <= xx && xx <=  z ) || ( A  <= xx && xx <=  Z )); n } n void swapInt(int &x, int &y) { n   x = x ^ y; n   y = x ^ y; n   x = x ^ y; n } n const int dx[4] = {-1, 1, 0, 0}; n const int dy[4] = {0, 0, -1, 1}; n const int Mod = 9901; n const int maxn = 1e5 + 10; n int exitInput = 0; n int n; n int a[maxn], b[maxn], p[maxn]; n void read() { n   cin >> n; n   int i; n   for (i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   for (i = 1; i <= n; ++i) { n     cin >> b[i]; n   } n   for (i = 1; i <= n; ++i) { n     p[a[i]] = b[i]; n   } n } n void init() {} n void solve() { n   cout << p[1]; n   int i; n   for (i = 2; i <= n; ++i) { n     cout <<     << p[i]; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   int ntest = 1; n   int itest = 1; n   for (itest = 1; itest <= ntest; ++itest) { n     read(); n     if (exitInput) { n       break; n     } n     init(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Dev { n   int p; n   int e; n   long double t; n } d[100000]; n int n, p; n bool fun(long double midTime) { n   long double energy = 0, t; n   for (int i = 0; i < n; i++) { n     t = midTime - d[i].t; n     if (t > 0) energy += t * d[i].p; n   } n   return midTime * p >= energy; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> p; n   long long sumPow = 0; n   for (int i = 0; i < n; i++) { n     cin >> d[i].p >> d[i].e; n     d[i].t = (double)d[i].e / d[i].p; n     sumPow += d[i].p; n   } n   if (sumPow <= p) { n     cout << -1 << endl; n     return 0; n   } n   long double minTime = 0; n   long double maxTime = 1e18; n   long double midTime; n   for (int i = 0; i < 80; i++) { n     midTime = (minTime + maxTime) / 2; n     if (fun(midTime)) n       minTime = midTime; n     else n       maxTime = midTime; n   } n   if (midTime > 1e18 - 100) n     cout << -1 << endl; n   else n     cout << midTime << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> build_z(const vector<int>& a) { n   int n = (int)(a).size(); n   vector<int> z(n); n   int l = 0, r = 0; n   for (int i = 1; i < n; i++) { n     z[i] = max(0, min(z[i - l], r - i)); n     while (i + z[i] < n && a[z[i]] == a[z[i] + i]) z[i]++; n     if (i + z[i] > r) l = i, r = i + z[i]; n   } n   return z; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   vector<int> a(n), b(m); n   for (int i = 0; i < (int)(n); i++) cin >> a[i]; n   for (int i = 0; i < (int)(m); i++) cin >> b[i]; n   auto get_diff = [&](vector<int> a) { n     vector<int> ret; n     for (int i = 1; i < (int)(a).size(); i++) ret.push_back(a[i] - a[i - 1]); n     return ret; n   }; n   auto da = get_diff(a), db = get_diff(b); n   vector<int> com = db; n   com.push_back(1e9 + 7); n   for (int i : da) com.push_back(i); n   auto z = build_z(com); n   int cnt = 0; n   for (int i = m - 1; i < (int)(z).size(); i++) cnt += (z[i] == m - 1); n   cout << cnt <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = 1e9 + 10; n int n, D[2020][2020]; n int add(int& x, int y) { return x = (x + y) % MOD; } n int main() { n   scanf( %d , &n); n   int ans = 0; n   D[0][0] = 1; n   for (int i = 1; i <= 2 * n; i++) { n     for (int j = 0; j <= i; j++) { n       if (j > 0) add(D[i][j], D[i - 1][j - 1]); n       add(D[i][j], D[i - 1][j + 1]); n       if (i % 2 && 2 * n - i >= j) add(ans, D[i][j]); n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class abio { n   static const unsigned BUF_SZ = 65536; n   FILE *istream, *ostream; n   char ibuf[BUF_SZ], obuf[BUF_SZ]; n   bool reached_eof; n   size_t ip, isz; n   size_t op, osz; n   inline void clear_ibuf(void) { ip = isz = 0u; } n   inline void clear_obuf(void) { op = osz = 0u; } n   inline void clear_buffer(void) { n     reached_eof = false; n     clear_ibuf(); n     clear_obuf(); n   } n   inline size_t read_buffer(void) { n     isz = fread(ibuf, sizeof(char), BUF_SZ, istream); n     ip = 0; n     return isz; n   } n   inline size_t write_buffer(void) { n     if (osz) { n       size_t ret = fwrite(obuf + op, sizeof(char), osz - op, ostream); n       op += ret; n       if (op == osz) clear_obuf(); n       return ret; n     } n     return 0; n   } n   inline abio &reach_eof(void) { n     reached_eof = true; n     return (*this); n   } n  n  public: n   static const char endl =   n ; n   abio(FILE *input = stdin, FILE *output = stdout) { n     this->istream = input; n     this->ostream = output; n     clear_buffer(); n   } n   abio(const char *input, const char *output) { n     this->istream = fopen(input,  r ); n     this->istream = fopen(output,  w+ ); n     clear_buffer(); n   } n   ~abio(void) { n     write_buffer(); n     fclose(istream); n     fclose(ostream); n   } n   operator bool() const { return (!reached_eof); } n   inline int getchar(void) { n     if (0 == isz || isz == ip) read_buffer(); n     if (0 == isz || isz == ip) return EOF; n     return ibuf[ip++]; n   } n   inline int putchar(int ch) { n     if (osz == BUF_SZ) write_buffer(); n     if (osz == BUF_SZ) return EOF; n     return (obuf[osz++] = ch); n   } n   abio &read_int(int &x) { n     int flag = 0, ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     x = 0; n     while ((EOF != ch) && (( -  != ch) && ((ch <  0 ) || (ch >  9 )))) n       ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     if ( -  == ch) { n       flag = 1; n       ch = getchar(); n     } n     for (; (((ch >=  0 ) && (ch <=  9 ))); ch = getchar()) { n       x *= 10; n       x += (ch -  0 ); n     } n     if (flag) x *= (-1); n     return (*this); n   } n   abio &read_ll(long long int &x) { n     int flag = 0, ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     x = 0ll; n     while ((EOF != ch) && (( -  != ch) && ((ch <  0 ) || (ch >  9 )))) n       ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     if ( -  == ch) { n       flag = 1; n       ch = getchar(); n     } n     for (; (((ch >=  0 ) && (ch <=  9 ))); ch = getchar()) { n       x *= (10ll); n       x += (ch -  0 ); n     } n     if (flag) x *= (-1); n     return (*this); n   } n   abio &read_s(char *s, const char interrupt =    ) { n     int ch = getchar(); n     while ((EOF != ch) && (ch <  !  || ch >  ~ )) ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     for (; (EOF != ch) && (interrupt != ch) && (ch >=     && ch <=  ~ ); n          ch = getchar()) n       (*s++) = ch; n     (*s) = 0; n     return (*this); n   } n   abio &write_int(int x, char append = 0) { n     int d[20], nd = 0; n     if (0 == x) putchar( 0 ); n     if (x < 0) { n       putchar( - ); n       x = -x; n     } n     while (x) { n       d[nd++] = x % 10; n       x /= 10; n     } n     while (nd--) putchar( 0  + d[nd]); n     if (append) putchar(append); n     return (*this); n   } n   abio &write_ll(long long int x, char append = 0) { n     int d[20], nd = 0; n     if (0 == x) putchar( 0 ); n     if (x < 0) { n       putchar( - ); n       x = -x; n     } n     while (x) { n       d[nd++] = x % 10; n       x /= 10; n     } n     while (nd--) putchar( 0  + d[nd]); n     if (append) putchar(append); n     return (*this); n   } n   abio &write_s(const char *s, char append = 0) { n     while (*s) putchar(*s++); n     if (append) putchar(append); n     return (*this); n   } n   abio &operator>>(char &ch) { n     ch = getchar(); n     if (EOF == ch) return (this->reach_eof()); n     return (*this); n   } n   abio &operator>>(int &x) { return read_int(x); } n   abio &operator>>(long long int &x) { return read_ll(x); } n   abio &operator>>(char *s) { return read_s(s); } n   abio &operator<<(const char ch) { n     putchar(ch); n     return (*this); n   } n   abio &operator<<(const int x) { return write_int(x); } n   abio &operator<<(const long long int x) { return write_ll(x); } n   abio &operator<<(const char *s) { return write_s(s); } n } io; n int n, s[100005]; n int main() { n   io >> n; n   if (n > 26 || n < 2) { n     io <<  Yes n  << io.endl; n     return 0; n   } n   while (n--) { n     char c; n     io >> c; n     s[c -  a ]++; n     if (s[c -  a ] > 1) { n       io <<  Yes n  << io.endl; n       return 0; n     } n   } n   io <<  No n  << io.endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int f[300000]; n int a[40]; n int add(int a, int b) { return (a + b >= m) ? a + b - m : a + b; } n void inc(int& a, int b) { a = (a + b >= m) ? a + b - m : a + b; } n int main(void) { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]), a[i] %= m; n   for (int i = 0, len = n / 2; i < (1 << len); i++) { n     int t = 0; n     for (int j = 0; j < len; j++) n       if (i & (1 << j)) inc(t, a[j]); n     f[i] = t; n   } n   sort(f, f + (1 << n / 2)); n   int cnt = unique(f, f + (1 << n / 2)) - f; n   int ans = f[cnt - 1]; n   for (int i = 0, len = n - n / 2; i < (1 << len); i++) { n     int t = 0; n     for (int j = 0; j < len; j++) n       if (i & (1 << j)) inc(t, a[j + n / 2]); n     ans = max(ans, t); n     int pos = lower_bound(f, f + cnt, m - 1 - t) - f; n     for (int j = max(0, pos - 1); j <= pos + 1; j++) { n       ans = max(ans, add(t, f[j])); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q; n   cin >> q; n   for (int d = 0; d < q; d++) { n     string s, t; n     cin >> s >> t; n     int n = s.size(); n     int m = t.size(); n     n = n % 2; n     m = m % 2; n     int y = abs(n - m); n     int j = 0; n     for (int i = y; i < s.size(); i++) { n       if (s[i] == t[j]) { n         j++; n       } else { n         i++; n       } n       if (j == t.size()) { n         break; n       } n     } n     if (j == t.size()) { n       cout <<  YES  <<   n ; n       ; n     } else { n       cout <<  NO  <<   n ; n       ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n int a[N], b[N]; n int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 0; i <= m; i++) scanf( %d , &b[i]); n   if (n > m) { n     if (a[0] * b[0] > 0) n       puts( Infinity ); n     else n       puts( -Infinity ); n   } else if (n < m) { n     printf( 0/1 n ); n   } else { n     if (a[0] > 0 && b[0] > 0 || a[0] < 0 && b[0] < 0) { n       a[0] = abs(a[0]); n       b[0] = abs(b[0]); n       int t = gcd(a[0], b[0]); n       a[0] /= t; n       b[0] /= t; n       printf( %d/%d n , a[0], b[0]); n     } else { n       a[0] = abs(a[0]); n       b[0] = abs(b[0]); n       int t = gcd(a[0], b[0]); n       a[0] /= t; n       b[0] /= t; n       printf( -%d/%d n , a[0], b[0]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n void read(T &a) { n   a = 0; n   char x = getchar(); n   bool f = 0; n   for (; x <  0  || x >  9 ; x = getchar()) f |= x ==  - ; n   for (; x >=  0  && x <=  9 ; x = getchar()) a = (a << 3) + (a << 1) + x -  0 ; n   if (f) a = -a; n } n template <class T, class... Args> n void read(T &a, Args &...args) { n   read(a); n   read(args...); n } n using namespace std; n const int N = 2e5 + 5; n int n; n int f[N], lim; n pair<int, int> d[N]; n bool cmp(pair<int, int> a, pair<int, int> b) { n   if (a.first ^ b.first) { n     return a.first < b.first; n   } n   return a.second > b.second; n } n int main() { n   read(n); n   for (int i = 1; i <= n; ++i) { n     read(d[i].first); n     d[i].second = i; n   } n   sort(d + 1, d + n + 1, cmp); n   int lim = 0; n   for (int i = 1; i <= n; ++i) { n     int c = d[i].second - d[i].first; n     if (c < 0) continue; n     if (lim == 0) { n       f[++lim] = c; n       continue; n     } n     if (c >= f[lim]) { n       f[++lim] = c; n       continue; n     } n     int l = 1, r = lim + 1; n     while (l < r - 1) { n       int mid = l + r >> 1; n       if (f[mid] <= c) { n         l = mid; n       } else { n         r = mid; n       } n     } n     if (f[l] > c) { n       f[l] = c; n     } else if (l != lim) { n       f[l + 1] = c; n     } n   } n   printf( %d n , lim); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mo = 998244353; n long long bin_fun(long long chto, long long vkak) { n   if (vkak == 0) return 1; n   if (vkak == 1) return chto; n   if (vkak % 2 == 0) n     return bin_fun(chto * chto % mo, vkak / 2); n   else n     return (bin_fun(chto * chto % mo, vkak / 2) * chto) % mo; n } n int main() { n   long long a, s, d, i, j, k; n   cin >> a; n   vector<long long> v1; n   for (i = 0; i < a * 2; i++) { n     cin >> s; n     v1.push_back(s); n   } n   sort(v1.begin(), v1.end()); n   long long sum = 0; n   for (i = 0; i < a; i++) sum = (sum + abs(v1[a * 2 - i - 1] - v1[i])) % mo; n   long long ch1 = 1, ch2 = 1; n   for (i = a + 1; i <= a * 2; i++) { n     ch1 = (ch1 * i) % mo; n   } n   for (i = 1; i <= a; i++) { n     long long t = bin_fun(i, mo - 2); n     ch2 = (ch2 * t) % mo; n   } n   long long otv = (ch1 * ch2) % mo; n   cout << (otv * sum) % mo; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, z, X, Y, Z, A, B, C, D, E, F; n int main() { n   cin >> X >> Y >> Z >> x >> y >> z >> A >> B >> C >> D >> E >> F; n   cout << A * (Y < 0) + B * (Y > y) + C * (Z < 0) + D * (Z > z) + E * (X < 0) + n               F * (X > x) n        <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline char gc() { return getchar(); } n template <class T> n int read(T &ans) { n   ans = 0; n   char ch = gc(); n   T f = 1; n   while (!isdigit(ch)) { n     if (ch == EOF) return -1; n     if (ch ==  - ) f = -1; n     ch = gc(); n   } n   while (isdigit(ch)) ans = ans * 10 + ch -  0 , ch = gc(); n   ans *= f; n   return 1; n } n template <class T1, class T2> n int read(T1 &a, T2 &b) { n   return read(a) != EOF && read(b) != EOF ? 2 : EOF; n } n template <class T1, class T2, class T3> n int read(T1 &a, T2 &b, T3 &c) { n   return read(a, b) != EOF && read(c) != EOF ? 3 : EOF; n } n const int Maxn = 1100000; n const int inf = 0x3f3f3f3f; n int n, m, D, to[Maxn], nxt[Maxn], first[Maxn], tot = 1; n int vis[Maxn], d[Maxn], u, v, cnt; n queue<int> q; n vector<int> vi[Maxn]; n inline void add(int u, int v) { n   to[tot] = v; n   nxt[tot] = first[u]; n   first[u] = tot++; n   to[tot] = u; n   nxt[tot] = first[v]; n   first[v] = tot++; n } n void dfs(int root) { n   vis[root] = cnt; n   for (int i = first[root]; i; i = nxt[i]) n     if (!vis[to[i]]) dfs(to[i]); n } n signed main() { n   read(n, m, D); n   for (int i = 1; i <= m; i++) { n     read(u, v); n     add(u, v); n     d[u]++; n     d[v]++; n   } n   if (d[1] >= D && D) { n     vis[1] = ++cnt; n     for (int i = first[1]; i; i = nxt[i]) n       if (vis[to[i]]) n         vi[vis[to[i]]].push_back(to[i]); n       else n         cnt++, dfs(to[i]), vi[cnt].push_back(to[i]); n     if (cnt - 1 > D) n       puts( NO ); n     else { n       memset(vis, 0, sizeof(vis)); n       vis[1] = 1; n       puts( YES ); n       for (int i = 2; i <= cnt; i++) n         printf( 1 %d n , vi[i][0]), vis[vi[i][0]] = 1, q.push(vi[i][0]); n       D -= cnt - 1; n       for (int i = 2; i <= cnt; i++) { n         for (int j = 1; j < vi[i].size(); j++) { n           if (!D) break; n           D--; n           printf( 1 %d n , vi[i][j]); n           vis[vi[i][j]] = 1; n           q.push(vi[i][j]); n         } n       } n       while (!q.empty()) { n         int now = q.front(); n         q.pop(); n         for (int i = first[now]; i; i = nxt[i]) n           if (!vis[to[i]]) { n             vis[to[i]] = 1; n             printf( %d %d n , now, to[i]); n             q.push(to[i]); n           } n       } n     } n   } else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct note { n   int a, b, x; n } a[100005 * 2]; n long long ansa, ansb; n int n; n int tot; n bool cmp(note i, note j) { return i.x > j.x; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     long long a1, b, c, d; n     scanf( %I64d%I64d%I64d%I64d , &a1, &b, &c, &d); n     if (a1 <= d && b <= c) continue; n     if (a1 + b > c + d) { n       a[++tot].a = a1; n       a[tot].b = b; n       a[tot].x = a1 + b; n       a[++tot].a = c; n       a[tot].b = d; n       a[tot].x = c + d; n     } else { n       if (a1 > d) { n         ansa += a1; n         ansb += d; n       } else { n         ansa += c; n         ansb += b; n       } n     } n   } n   sort(a + 1, a + tot + 1, cmp); n   for (int i = 1; i <= tot; i++) { n     if (i % 2 == 1) n       ansa += a[i].a; n     else n       ansb += a[i].b; n   } n   printf( %I64d , ansa - ansb); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, ans = 0; n   cin >> n; n   pair<int, int> p[n]; n   int ab, be, le, ri; n   for (i = 0; i < n; i++) { n     int r, s; n     cin >> r >> s; n     p[i] = make_pair(r, s); n   } n   for (i = 0; i < n; i++) { n     ab = 0, be = 0, le = 0, ri = 0; n     for (j = 0; j < n; j++) { n       if (i == j) { n         continue; n       } n       if (p[i].first == p[j].first) { n         if (p[i].second < p[j].second) { n           ab++; n         } else { n           be++; n         } n       } n       if (p[i].second == p[j].second) { n         if (p[i].first < p[j].first) { n           ri++; n         } else { n           le++; n         } n       } n       if (ab > 0 && be > 0 && le > 0 && ri > 0) { n         ans++; n         break; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n   n using namespace std; n   n #define endl   n  n #define ll long long n #define fr(i,s,e) for(ll i=s;i<=e;i++) n #define rfr(i,s,e) for(ll i=s;i>=e;i--) n #define f(x,m) for(auto x : m) n #define ff first n #define ss second n #define pb push_back n #define pp pop_back n #define pf push_front n #define ppf pop_front n #define m_p make_pair n #define mod 1000000007 n #define TIME cerr<< Time Taken: <<(float)clock()/CLOCKS_PER_SEC*1000<< ms <<endl n   n const ll INF = (1LL << 60) - 1; n   n int main() n { n   n #ifndef ONLINE_JUDGE n  freopen( ../input-output/input.txt ,  r , stdin); n  freopen( ../input-output/output.txt ,  w , stdout); n #endif n  ios_base::sync_with_stdio(false); n     cin.tie(NULL); n   n  int t; n  cin>>t; n  while(t--){ n   ll r,b,d; n   cin>>r>>b>>d; n   int noPackets=min(r,b); n   r=max(r,b)-min(r,b); n   // cout<<r<<   ; n   if(noPackets==0){ n    cout<< NO n ; n    continue; n   } n   ll maxdiff=r/noPackets; n   if(r%noPackets) maxdiff++; n   // cout<<maxdiff<<endl; n   if(maxdiff<=d) cout<< YES n ; n   else cout<< NO n ; n  } n   n  TIME; n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int N, i, j, r[55]; n long long m, f[55]; n void solve(int n, int p, long long m) { n   if (n == 0) return; n   for (int i = 1; i <= n && i <= 2; i++) { n     if (m <= f[n - i]) { n       solve(n - i, p + i, m); n       for (int j = p + i; j <= N; j++) r[j] += i; n       for (int j = p + i - 1, k = 1; j >= p; j--, k++) r[j] = k; n       break; n     } else n       m -= f[n - i]; n   } n } n int main() { n   cin >> N >> m; n   for (f[0] = i = 1; i <= N; i++) n     for (j = 1; j <= i && j <= 2; j++) f[i] = min(m + 1, f[i] + f[i - j]); n   solve(N, 1, m); n   for (i = 1; i <= N; i++) printf( %d%c , r[i], i == N ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7, N = 1e5 + 10; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ll a[3]; n   cin >> a[0] >> a[1] >> a[2]; n   cout <<  First  << endl; n   vector<ll> b(3); n   iota(b.begin(), b.end(), 0); n   sort(b.begin(), b.end(), [&](ll u, ll v) { return a[u] < a[v]; }); n   sort(a, a + 3); n   cout << 2 * a[2] - a[1] - a[0] << endl; n   ll x; n   cin >> x; n   --x; n   if (x == -1) return 0; n   if (x == b[0]) { n     cout << a[2] - a[1] << endl; n     cin >> x; n     return 0; n   } else if (x == b[1]) { n     cout << a[2] - a[0] << endl; n     cin >> x; n     return 0; n   } n   cout << 6 * a[2] - 3 * a[1] - 3 * a[0] << endl; n   cin >> x; n   --x; n   if (x == -1) return 0; n   if (x == b[0]) { n     cout << 3 * a[2] - a[0] - a[1] - a[1] << endl; n     cin >> x; n     return 0; n   } n   cout << 3 * a[2] - a[0] - a[1] - a[0] << endl; n   cin >> x; n   return 0; n } n


#include <bits/stdc++.h> n const long long RXD = 1e9 + 7; n const long long N = 1e5 + 1000; n using namespace std; n long long C[N][110], a[N], s[N][110], n, m, l, r, K; n long long read() { n   long long x = 0, f = 1, c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return x * f; n } n int main() { n   C[0][0] = 1; n   for (long long i = 1; i <= 100100; i++) n     for (long long j = 0; j <= i && j <= 105; j++) n       C[i][j] = (j == 0) ? 1 : (C[i - 1][j] + C[i - 1][j - 1]) % RXD; n   n = read(); n   m = read(); n   for (long long i = 1; i <= n; i++) a[i] = read(); n   for (long long i = 1; i <= m; i++) { n     l = read(); n     r = read(); n     K = read(); n     for (long long i = 0; i <= K; i++) s[l][i] = (s[l][i] + C[K][K - i]) % RXD; n     for (long long i = 0; i <= K; i++) n       s[r + 1][i] = (s[r + 1][i] - C[K + r + 1 - l][K - i] + RXD) % RXD; n   } n   for (long long i = 1; i <= n; i++) n     for (long long j = 101; j; j--) n       s[i + 1][j - 1] = ((s[i + 1][j - 1] + s[i][j]) % RXD + s[i][j - 1]) % RXD; n   for (long long i = 1; i <= n; i++) n     printf( %d  , ((a[i] + s[i][0]) % RXD + RXD) % RXD); n } n


#include <bits/stdc++.h> n using namespace std; n void readi(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readll(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readc(char &x) { n   char c; n   while ((c = getchar()) ==    ) n     ; n   x = c; n } n void writes(string s) { puts(s.c_str()); } n void writeln() { writes(  ); } n void writei(int x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n void writell(long long x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n int fa[100005], n, m, i, j, x; n set<int> s; n int find(int x) { n   if (fa[x] == x) return x; n   return fa[x] = find(fa[x]); n } n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) fa[i] = i; n   for (i = 1; i <= n; i++) { n     cin >> x; n     fa[find(x)] = find(i); n   } n   for (i = 1; i <= n; i++) s.insert(find(i)); n   cout << s.size(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int toInt(string s) { n   int v; n   istringstream sin(s); n   sin >> v; n   return v; n } n template <class T> n string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n vector<string> form(string a, char s) { n   a += s; n   vector<string> v; n   string b; n   for (int i = (0); i < (int)(a.size()); ++i) { n     if (a[i] == s) { n       v.push_back(b); n       b =   ; n     } else n       b += a[i]; n   } n   return v; n } n vector<int> formint(string a, char s) { n   vector<int> v; n   vector<string> w = form(a, s); n   for (int i = (0); i < (int)(w.size()); ++i) v.push_back(toInt(w[i])); n   return v; n } n const int mod = 1000000007; n int aa[2048]; n int bb[2048]; n int pows(int a, int b) { n   if (b == 0) return 1; n   int k = pows(a, b / 2); n   k = ((long long)k * k) % mod; n   if (b % 2 == 1) k = ((long long)k * a) % mod; n   return k; n } n int divs(int a, int b) { return (((long long)a) * pows(b, mod - 2)) % mod; } n int combi(int a, int b) { n   int res = 1; n   if (a / 2 < b) b = a - b; n   for (int i = a, j = 0; j < b; i--, j++) res = (((long long)res) * i) % mod; n   for (int i = 2; i <= b; i++) res = divs(res, i); n   return res; n } n int main(void) { n   int n, k; n   cin >> n >> k; n   for (int i = (0); i < (int)(n); ++i) cin >> aa[i]; n   if (k == 0) { n     for (int i = (0); i < (int)(n); ++i) { n       if (i > 0) cout <<    ; n       cout << aa[i]; n     } n     cout << endl; n     return 0; n   } n   for (int i = (0); i < (int)(n); ++i) bb[i] = combi(k + i - 1, i); n   for (int i = (0); i < (int)(n); ++i) { n     if (i != 0) cout <<    ; n     int res = 0; n     for (int j = (0); j < (int)(i + 1); ++j) { n       res = (res + ((long long)aa[j] * bb[i - j]) % mod) % mod; n     } n     cout << res; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n void setmax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n void setmin(T &a, T b) { n   if (b < a) a = b; n } n using namespace std; n void read(long long &x) { scanf( %lld , &x); } n void read(long long &x, long long &y) { scanf( %lld %lld , &x, &y); } n void read(long long &x, long long &y, long long &z) { n   scanf( %lld %lld %lld , &x, &y, &z); n } n void read(long long &x, long long &y, long long &z, long long &w) { n   scanf( %lld %lld %lld %lld , &x, &y, &z, &w); n } n void read(vector<long long> &oneD) { n   for (long long i = 0; i < oneD.size(); i++) { n     read(oneD[i]); n   } n } n void read(vector<vector<long long> > &twoD) { n   for (long long i = 0; i < twoD.size(); i++) { n     read(twoD[i]); n   } n } n void write(vector<long long> &oneD) { n   for (long long i = 0; i < oneD.size(); i++) { n     printf( %lld  , oneD[i]); n   } n   printf(  n ); n } n void write(vector<vector<long long> > &twoD) { n   for (long long i = 0; i < twoD.size(); i++) { n     write(twoD[i]); n   } n } n void write(vector<pair<long long, long long> > &oneDP) { n   for (long long(i) = 0; (i) < (oneDP.size()); ++(i)) { n     printf( %lld %lld n , oneDP[i].first, oneDP[i].second); n   } n   cout <<   n ; n } n void write(map<long long, long long> &mpp) { n   for (map<long long, long long>::iterator it = mpp.begin(); it != mpp.end(); n        it++) { n     cout << it->first <<   :   << it->second <<   n ; n   } n   cout <<   n ; n } n bool cmp(const pair<long long, long long> &a, n          const pair<long long, long long> &b) { n   if (a.first == b.first) return (a.second >= b.second); n   return (a.first < b.first); n } n long long A[100005]; n vector<long long> seive; n vector<long long> primes; n void Seive() { n   const long long maxn = 100005; n   seive.resize(maxn); n   for (long long(i) = 0; (i) < (maxn); ++(i)) seive[i] = 1; n   for (long long i = 2; i * i < maxn; i++) { n     if (seive[i] == 1) { n       for (long long j = i * i; j < maxn; j += i) { n         seive[j] = 0; n       } n     } n   } n   primes.push_back(2); n   for (long long i = 3; i < maxn; i += 2) { n     if (seive[i]) primes.push_back(i); n   } n } n void printprime(long long l, long long r) { n   if (l < 2) l = 2; n   bool isprime[r - l + 1]; n   for (long long(i) = 0; (i) < (r - l + 1); ++(i)) isprime[i] = true; n   for (int i = 0; primes[i] * primes[i] <= r; i++) { n     long long base = (l / primes[i]) * primes[i]; n     if (base < l) { n       base = base + primes[i]; n     } n     for (long long j = base; j <= r; j += primes[i]) { n       isprime[j - l] = false; n     } n     if (base == primes[i]) isprime[base - l] = true; n   } n   for (int i = 0; i < r - l + 1; i++) { n     if (isprime[i] == true) cout << i + l <<   n ; n   } n } n long long isprime(long long N) { n   if (N < 2 || (!(N & 1) && N != 2)) return 0; n   for (long long i = 3; i * i <= N; i += 2) { n     if (!(N % i)) return 0; n   } n   return 1; n } n long long mulmod(long long a, long long b, long long mod) { n   long long res = 0; n   a = a % mod; n   while (b > 0) { n     if (b % 2 == 1) res = (res + a) % mod; n     a = (a * 2) % mod; n     b /= 2; n   } n   return res % mod; n } n long long power(long long x, long long y, long long m) { n   long long int res = 1; n   x = x % m; n   while (y > 0) { n     if (y & 1) res = mulmod(res, x, m); n     y = y >> 1; n     x = mulmod(x, x, m); n   } n   return res; n } n long long modinv(long long x, long long mod = 1000000007) { n   return power(x, mod - 2, mod); n } n long long B[100001]; n long long C[100001]; n long long D[100001]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long a, b, c, d; n   long long k, l, m, n, p, q, r, s, t, x, y; n   cin >> n; n   vector<pair<long long, long long> > v(n); n   long long mx1 = 0, mx2 = 0; n   long long s1 = 0, s2 = 0; n   for (long long(i) = 0; (i) < (n); ++(i)) { n     cin >> A[i] >> B[i]; n   } n   sort(A, A + n); n   sort(B, B + n); n   for (long long(i) = 0; (i) < (n); ++(i)) { n     mx1 += max(A[i], B[i]); n   } n   mx1 += n; n   cout << mx1 <<   n ; n } n